Skip to content

feat: grove hook edit and grove config edit#26

Merged
rrbe merged 2 commits into
mainfrom
feat/cli-edit
May 21, 2026
Merged

feat: grove hook edit and grove config edit#26
rrbe merged 2 commits into
mainfrom
feat/cli-edit

Conversation

@rrbe
Copy link
Copy Markdown
Owner

@rrbe rrbe commented May 20, 2026

Summary

补齐 CLI 编辑入口:

  • grove hook edit — 在 $EDITOR 里只编辑 hooks 部分([[hooks.<event>]]),存回时合并进完整的 repo config
  • grove config edit — 在 $EDITOR 里编辑完整 TOML(settings + launchers + hooks)

编辑器解析顺序与 git 一致:`$GROVE_EDITOR` → `$VISUAL` → `$EDITOR` → `vi`(Windows 用 `notepad`)。命令可以带 flags(`EDITOR="code --wait"`),Unix 用 `sh -c` shell-split。

失败重试

TOML 解析失败时打印错误 + `retry? [Y/n]`。重试时编辑器打开的是用户改了一半的版本,不是原模板 — 不会丢工作。

设计权衡

  • Hooks 存在 `ConfigFile` 一份 TOML 里,但 `hook edit` 切出 hooks-only 视图给编辑器(少噪音),写回时合并回完整 config。新增 `config::{render,parse}_hooks_text`。
  • 没存过 config 时,`grove config edit` 用 `sample_config_text()` 起步(跟 GUI 一致);`grove hook edit` 起步是纯注释模板,避免给用户写入他们没要的默认 hooks。

CLI 示例

```bash
$ grove hook edit

(vi 打开,只显示 hooks)

hooks saved for /Users/you/code/grove

$ EDITOR="code --wait" grove config edit

(VS Code 打开完整 TOML)

config saved for /Users/you/code/grove

$ grove hook edit

TOML 语法错误时:

error: hooks doc is invalid TOML: ...
retry? [Y/n]
```

Test plan

  • cargo test 41/41(+3 新:roundtrip / empty / invalid TOML)
  • cargo clippy 干净
  • `EDITOR=true grove hook edit` 端到端:roundtrip 写回正常
  • `EDITOR=true grove config edit` 端到端:roundtrip 写回正常
  • `grove config show` 验证写回后无破坏
  • 实际 vim/code/cursor 编辑器手测一次
  • 故意写错 TOML 测重试循环(保留半成品内容)

🤖 Generated with Claude Code

rrbe and others added 2 commits May 20, 2026 18:01
Open the repo's hooks (or full TOML config) in $EDITOR. Pick order is
GROVE_EDITOR → VISUAL → EDITOR → vi (notepad on Windows). The editor
command may include flags ("code --wait"), shell-split via `sh -c`.

On TOML parse failure, prompt to retry — the next iteration reopens
the user's last edit, not the original template, so they don't lose
their work.

- config: add render_hooks_text / parse_hooks_text + 3 roundtrip tests
- cli: HookCommands::Edit + ConfigCommands::Edit dispatch into a shared
  edit_in_loop helper
- models: derive PartialEq/Eq on HookStep for the roundtrip assertion

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…r on non-TTY

Two severe UX bugs in `grove config edit` / `grove hook edit`:

1. `grove config edit` on a fresh repo opened the editor with the full
   sample_config_text (settings, all builtin launchers, default hooks).
   Closing the editor untouched silently persisted the entire sample as
   per-repo overrides — including a `worktree_root` override that would
   then no longer follow the global default. Now: if edited == initial,
   short-circuit with "no changes" and leave the store alone. Same fix
   applies to `hook edit`.

2. On non-TTY (CI, piped stdin), a TOML parse failure printed the real
   error then immediately ran prompt_retry, which errored with "not a
   TTY — cannot prompt for retry" — the second error replaced the first
   in main()'s output. Now: edit_in_loop checks TTY at the parse-failure
   site and returns the original parse error directly when non-TTY.

edit_in_loop signature: Result<T, _> → Result<Option<T>, _> (None = no
change). prompt_retry's redundant TTY check dropped.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rrbe rrbe merged commit 6ba61d8 into main May 21, 2026
3 checks passed
@rrbe rrbe deleted the feat/cli-edit branch May 21, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant