feat: grove hook edit and grove config edit#26
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
补齐 CLI 编辑入口:
grove hook edit— 在 $EDITOR 里只编辑 hooks 部分([[hooks.<event>]]),存回时合并进完整的 repo configgrove 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]`。重试时编辑器打开的是用户改了一半的版本,不是原模板 — 不会丢工作。
设计权衡
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
🤖 Generated with Claude Code