Skip to content

fix(vibe): keep user comments that follow a managed hook block - #5109

Open
kartsan03 wants to merge 1 commit into
github:mainfrom
kartsan03:fix/vibe-hooks-keep-user-comments
Open

kartsan03 wants to merge 1 commit into
github:mainfrom
kartsan03:fix/vibe-hooks-keep-user-comments

Conversation

@kartsan03

Copy link
Copy Markdown
Contributor

Description

VibeIntegration._managed_hook_spans treats a managed [[hooks]] block in .vibe/hooks.toml as running until the next table header or the end of the file, so cleanup removes any comments after the block along with it. Every events refresh and teardown goes through this code. A note a user writes above their own hook is deleted the next time an extension is added, enabled, disabled or removed, while the hook itself stays.

Copilot flagged this on #4646 ("Exclude trailing standalone comments from managed spans, while still including complete multiline values"), and #4646 merged without that change. The regex cleanup before #4646 stopped at speckit_marker = true and kept these comments.

With this PR, a managed block ends after its last line of TOML and the blank lines right after it. A standalone comment after that stays with whatever follows it. Lines inside a multiline string or array still belong to the value, so a managed hook whose value has comment-like lines is still removed whole.

Repro with the real CLI. ext-demo and ext-demo2 are minimal project extensions that each declare one event in extension.yml (events:, as in docs/reference/extensions.md):

specify init proj --integration vibe --ignore-agent-tools --non-interactive
cd proj
specify extension add ../ext-demo --dev     # writes the managed hook
cat >> .vibe/hooks.toml <<'EOF'

# NOTE: keep guard-bash first
[[hooks]]
name = "user-hook"
type = "pre_tool"
command = "guard-bash"
EOF
specify extension add ../ext-demo2 --dev    # refresh
specify extension disable demo              # removal (run on a fresh copy)
Command main (67e0f72) This PR
specify extension add ../ext-demo2 --dev note deleted, user hook kept both kept
specify extension disable demo note deleted, user hook kept both kept

The PR says Refs #5079 because it doesn't change the issue's second case: when removal leaves only comments, remove_vibe_event_hooks still deletes the file. The shared TOML cleanup does the same for Codex's config.toml (_remove_toml_entries, pinned by test_owned_only_config_still_deleted_on_teardown), and the rule predates #4646. Changing it only for Vibe would make the two integrations disagree.

Testing

  • Tested locally with uv run specify --help
  • Ran existing tests with uv sync && uv run pytest
  • Tested with a sample project (if applicable)

New tests in tests/integrations/test_integration_vibe.py:

  • test_refresh_and_teardown_keep_comments_after_a_managed_hook, through install_integration_events and remove_integration_events, with a comment above a user hook and with a comment at the end of the file.
  • test_removal_keeps_a_comment_that_follows_a_managed_hook checks the exact bytes: the blank line after the managed block goes with it, and the comment stays.
  • test_removal_still_takes_comment_like_lines_inside_managed_values is a control: a managed multiline string and array whose lines look like comments are still removed whole. It passes on main too.

With only vibe/__init__.py reverted to main, the first three fail. With the fix, all four pass.

Full suite on Linux, Python 3.13: 12805 passed, 435 skipped (uv sync --extra test, then pytest -n 3, 6 min). Ruff 0.15.0 (ruff check src tests) passes. I haven't run it on Windows.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

AI disclosure: Claude Code (model: claude-opus-5-5, autonomous) reproduced the issue on main with the real CLI, wrote the fix and the tests, ran them against main and the fix, ran the full suite and lint, and drafted this description. The commit carries an Assisted-by: trailer.

A managed [[hooks]] block ran until the next table header or the end
of the file, so the comments after it were removed with it on every
events refresh and teardown. A comment there usually introduces the
user hook that follows it.

End the block after its last line of TOML and the blank lines right
after it. Lines inside a multiline string or array still belong to the
value.

Refs github#5079

Assisted-by: Claude Code (model: claude-opus-5-5, autonomous)
@kartsan03
kartsan03 requested a review from mnriem as a code owner October 24, 2026 18:03
@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Oct 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants