Skip to content

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

Open
mnriem wants to merge 2 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 2 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

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
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
…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
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 on lines 2809 to +2813
lines.append(f"\n**Automatic Hook**: {extension}")
lines.append(f"Executing: `{display_invocation}`")
lines.append(f"Hook event: {event_name}")
lines.append(f"Executing: `{display_invocation} {event_name}`")
lines.append(f"EXECUTE_COMMAND: {command_text}")
lines.append(f"EXECUTE_COMMAND_INVOCATION: {display_invocation}")
lines.append(f"EXECUTE_COMMAND_INVOCATION: {display_invocation} {event_name}")
Comment on lines +30 to +32
1. Find the key matching the event name (e.g., `after_tasks:`).
2. If the event key exists **and** has `enabled: true` → auto-commit is **enabled**. Use the `message` value from that key.
3. If the event key exists **and** has `enabled: false` → auto-commit is **disabled**. Exit silently.
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