Skip to content

fix: pass hook event name to speckit.git.commit so AI agents read config#2724

Open
mnriem wants to merge 3 commits into
github:mainfrom
mnriem:fix/git-hook-event-name-in-commit-command
Open

fix: pass hook event name to speckit.git.commit so AI agents read config#2724
mnriem wants to merge 3 commits into
github:mainfrom
mnriem:fix/git-hook-event-name-in-commit-command

Conversation

@mnriem
Copy link
Copy Markdown
Collaborator

@mnriem mnriem commented May 27, 2026

Problem

When speckit.git.commit fires as a hook (e.g., after speckit.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:

The after_tasks git hook is disabled in configuration, so no auto-commit occurred.

This happens even when the user has set after_tasks.enabled: true and default: true in 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

  1. speckit.git.commit.md — The old template had a descriptive "Behavior" section that AI agents interpreted without actually reading the config file
  2. format_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 commit
  • src/specify_cli/extensions.py — Added Hook event: {event_name} to format_hook_message() output and appended event name to EXECUTE_COMMAND_INVOCATION for both optional and mandatory hooks
  • Tests — Updated assertions in test_extensions.py and test_integration_claude.py to match the new hook message format

Testing

Full test suite: 2999 passed, 1 skipped, 0 failures

Fixes #2279
Fixes #2702

Copilot AI review requested due to automatic review settings May 27, 2026 12:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread extensions/git/commands/speckit.git.commit.md Outdated
Comment thread extensions/git/commands/speckit.git.commit.md Outdated
Comment thread src/specify_cli/extensions.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 2

Comment thread src/specify_cli/extensions.py Outdated
Comment thread extensions/git/commands/speckit.git.commit.md
mnriem added 3 commits May 27, 2026 17:21
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.
@mnriem mnriem force-pushed the fix/git-hook-event-name-in-commit-command branch from 5b78459 to 7281217 Compare May 27, 2026 22:23
@mnriem mnriem requested a review from Copilot May 27, 2026 22:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

Comment on lines +22 to 25
**You MUST read** the file `.specify/extensions/git/git-config.yml` before deciding whether to commit. Do NOT assume its contents — the user may have changed the defaults.

Replace `<event_name>` with the actual hook event (e.g., `after_specify`, `before_plan`, `after_implement`).
If the file does not exist, auto-commit is disabled. Exit silently.

Comment on lines +15 to +18
Identify the hook event name to use:
- If the invocation includes an explicit event name argument (e.g., `/speckit.git.commit after_tasks`), use it.
- Otherwise infer it from the surrounding hook context (e.g., `after_tasks`, `before_plan`), matching `hooks.<event>` in `.specify/extensions.yml`.
- If invoked manually with no hook context and no event argument, ask the user which event to use.
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.

[Bug]: git hooks are not being triggered. ((possible) FIX mentioned in "Additional Context") [Bug]: git hooks are not triggered

2 participants