fix: pass hook event name to speckit.git.commit so AI agents read config#2724
fix: pass hook event name to speckit.git.commit so AI agents read config#2724mnriem wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves extension hook messaging and the git auto-commit command template so AI agents reliably know which hook event triggered /speckit.git.commit and are prompted to read the live git extension config before deciding whether to commit.
Changes:
- Add the hook event name to hook messages and append it to the suggested command invocation so agents don’t have to infer context.
- Rewrite
speckit.git.commit’s command template into explicit, step-by-step instructions emphasizing reading.specify/extensions/git/git-config.yml. - Update Claude + general hook rendering tests to match the new message format.
Show a summary per file
| File | Description |
|---|---|
| tests/test_extensions.py | Updates hook message assertions to expect “Hook event: …” and invocations including the event name. |
| tests/integrations/test_integration_claude.py | Updates Claude hook rendering assertion for the new event-aware invocation format. |
| src/specify_cli/extensions.py | Extends format_hook_message() output to include the hook event and append it to the invocation. |
| extensions/git/commands/speckit.git.commit.md | Replaces the old “Behavior” section with prescriptive instructions to read config and execute commits correctly. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 3
5b78459 to
7281217
Compare
The speckit.git.commit command template described script behavior in a 'Behavior' section that AI agents interpreted as instructions to follow without actually reading the config file. This caused agents to assume the default config (all events disabled) and fabricate 'disabled in configuration' messages even when the user had enabled auto-commit. Changes: - Rewrite speckit.git.commit.md with explicit step-by-step instructions that mandate reading .specify/extensions/git/git-config.yml before deciding whether to commit - Add 'Hook event: <event>' line to format_hook_message() output for both optional and mandatory hooks so agents know which event triggered the hook without guessing - Append event name to EXECUTE_COMMAND_INVOCATION so agents can pass it to the auto-commit script Fixes github#2279, fixes github#2702
…mat, add event to Executing line - Step 1: prefer explicit event name argument over context inference - Fix default commit message format to match script output: '[Spec Kit] Auto-commit <before|after> <command>' - Include event_name in the 'Executing:' line so agents see the full invocation immediately, not just on EXECUTE_COMMAND_INVOCATION
Address PR review: remove hook message changes from extensions.py (avoids changing $ARGUMENTS semantics for all hooks). The fix is now entirely in the speckit.git.commit.md command template which instructs agents to read the config file and documents the message fallback.
…it template - Step 1: reference 'Hooks available for event' line as primary event source - Step 2: instruct agent to ask user for file contents if it cannot access files
e9872df to
6db18fe
Compare
…name-in-commit-command
|
Closing this PR — the change addresses the right problem at the wrong layer. After review, I don't think this belongs in the default The commit decision is already deterministic. Customization is already covered. Custom commit messages are a config concern (the The original bug was narrower than the fix. #2279/#2702 weren't "config is hard to override" — they were "the agent read the template's descriptive prose, concluded 'hook disabled,' and never ran the script." The remedy for that is to make the template do less (just: determine event → run the script), not to add a four-step config-parsing routine that re-derives logic the script already owns. Net: the elaborate rewrite increases cost and the surface for the agent to get config interpretation wrong, while the real fix — if anything is needed — is a near-zero trim of the misleading prose. Closing in favor of that lighter approach; if the hallucination reports recur, a small follow-up scoped to just that trim would be the way to go. |
Problem
When
speckit.git.commitfires as a hook (e.g., afterspeckit.tasks), AI agents read the command template's "Behavior" section and treat it as manual instructions — but never actually read.specify/extensions/git/git-config.yml. They assume the default config (all events disabled) and fabricate messages like:This happens even when the user has set
after_tasks.enabled: trueanddefault: truein their config.The user's workaround in #2702 confirms this — explicitly attaching the config file with
@forces the AI to read it, and then it works.Root Cause
speckit.git.commit.md— The old template had a descriptive "Behavior" section that AI agents interpreted without actually reading the config fileformat_hook_message()— The hook event name (e.g.,after_tasks) was not passed through to the command invocation, so agents had to infer it from context (and often failed)Changes
extensions/git/commands/speckit.git.commit.md— Rewrote with explicit step-by-step instructions that mandate reading the config file (Step 2: "You MUST read the file") before deciding whether to commitsrc/specify_cli/extensions.py— AddedHook event: {event_name}toformat_hook_message()output and appended event name toEXECUTE_COMMAND_INVOCATIONfor both optional and mandatory hookstest_extensions.pyandtest_integration_claude.pyto match the new hook message formatTesting
Full test suite: 2999 passed, 1 skipped, 0 failures
Fixes #2279
Fixes #2702