Skip to content

feat(cli): /hooks preview <event> lists hooks that would fire#216

Merged
emal-avala merged 1 commit intomainfrom
feat/hooks-preview-subcommand
Apr 23, 2026
Merged

feat(cli): /hooks preview <event> lists hooks that would fire#216
emal-avala merged 1 commit intomainfrom
feat/hooks-preview-subcommand

Conversation

@emal-avala
Copy link
Copy Markdown
Member

Summary

A misspelled event in `settings.toml` (e.g. `pre-tool-used` instead of `pre_tool_use`) silently deserializes as a hook that never matches anything at runtime. Users only notice when the hook seems not to run — often hours of debugging later. And even with correctly-spelled events, there's no way to audit which of my configured hooks would actually fire for `user_prompt_submit` without tracing the code.

This PR adds a `/hooks preview ` subcommand:

```

/hooks preview pre_tool_use
Hooks that would fire for 'pre_tool_use' (2):

  1. shell: ./check-bash.sh (tool=Bash)
  2. http: POST https://my-audit.internal/event
    ```
  • Shows "No configured hooks match event ''" when nothing matches.
  • Rejects unknown event names with a hint pointing at `/hooks events`.
  • Accepts both canonical `snake_case` and the hyphen / mixed-case forms users tend to type (`pre-tool-use`, `Pre-Tool-Use`).

Also adds a round-trip test that pins the new `parse_hook_event` helper to `HOOK_EVENT_CATALOG` — adding a new event to the catalog without teaching the parser will now fail the build instead of silently rejecting that event name from preview.

Test plan

  • `cargo clippy -p agent-code --tests --no-deps -- -D warnings` — clean
  • `cargo test -p agent-code --bin agent commands::tests::` — 85 pass (80 prior + 5 new)
  • 5 new tests: canonical snake_case parsing, hyphen/case tolerance, whitespace trimming, unknown-name rejection, catalog round-trip

A misspelled event in settings.toml (e.g. \`pre-tool-used\` instead of
\`pre_tool_use\`) silently deserializes as a hook that never matches
anything at runtime. Users only notice when the hook seems not to run
— often hours of debugging later. And even with correctly-spelled
events, there was no way to audit "which of my configured hooks would
actually fire for user_prompt_submit?" without tracing the code.

Adds a \`/hooks preview <event>\` subcommand that prints every
configured hook matching the given event, along with its action line
and optional tool_name filter. Shows "No configured hooks match
event '<name>'" when empty, and rejects unknown event names with a
hint pointing at \`/hooks events\`.

Also adds \`parse_hook_event\`, which accepts both canonical
\`snake_case\` and the hyphenated / mixed-case forms users tend to type.
A round-trip test pins it to HOOK_EVENT_CATALOG — adding a new event
to the catalog without teaching the parser will now fail the build
instead of silently rejecting the new name.

5 new tests cover canonical parsing, hyphen/case tolerance, whitespace
trimming, rejection of unknown names, and catalog round-trip.
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@emal-avala emal-avala merged commit 52d1db0 into main Apr 23, 2026
14 checks passed
@emal-avala emal-avala deleted the feat/hooks-preview-subcommand branch April 23, 2026 18:55
@emal-avala emal-avala mentioned this pull request Apr 23, 2026
5 tasks
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