[Bug]: Removing Vibe event hooks deletes user comments that follow a Spec Kit hook block

Ouverte Adaptée aux débutants
#5,079 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
78/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
python
Domaine
cli

Piste de recherche

Lisez src/specify_cli/integrations/vibe/__init__.py, en particulier les lignes 440–490 concernant la détection des blocs gérés et _without_managed_hooks, puis examinez remove_vibe_event_hooks et les tests associés dans tests/integrations/test_integration_vibe.py. Exécutez les tests d’intégration Vibe qui couvrent la conservation des commentaires et la suppression ; le travail est terminé lorsque les commentaires et les hooks de l’utilisateur survivent à la suppression et qu’un fichier contenant du contenu utilisateur est conservé.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug-assess invalid triage-must-have
Bug Description

VibeIntegration finds the [[hooks]] blocks that Spec Kit owns (marked speckit_marker = true) and treats each one as running until the next table header or the end of the file (src/specify_cli/integrations/vibe/__init__.py:440-470). Comment and blank lines after a managed block therefore count as part of it. When the hooks are removed, those user comments are deleted. If a comment is the only user content left, remove_vibe_event_hooks deletes the whole .vibe/hooks.toml file. _merge_managed_hooks, used when hooks are written again, uses the same block detection and drops the comments as well.

Steps to Reproduce

From the root of a fresh clone, after uv sync, save the script below as repro.py and run it with uv run python repro.py.

import tempfile
from pathlib import Path
from specify_cli.integrations import get_integration

vibe = get_integration("vibe")
managed = (
    '[[hooks]]\nname = "speckit-pre_tool-validate"\ntype = "pre_tool"\n'
    'command = "c"\ntimeout = 65\nspeckit_marker = true\n'
)
cases = {
    "comment before a user hook": managed
    + '\n# NOTE: keep guard-bash first\n[[hooks]]\nname = "user-hook"\n'
    'type = "pre_tool"\ncommand = "guard-bash"\n',
    "trailing user comment only": managed + "\n# my notes about vibe hooks\n",
}
for label, text in cases.items():
    root = Path(tempfile.mkdtemp())
    path = root / ".vibe" / "hooks.toml"
    path.parent.mkdir()
    path.write_text(text)
    vibe.remove_vibe_event_hooks(root, ensure_safe_destination=lambda p: None)
    print(f"[{label}]")
    print("  file exists after removal:", path.exists())
    print("  content:", repr(path.read_text()) if path.exists() else None)

The script writes a .vibe/hooks.toml containing a Spec Kit managed hook followed by user content, then calls remove_vibe_event_hooks, the method used when Vibe event hooks are removed.

Expected Behavior

Only the Spec Kit managed hook is removed. The user's comment and the user's hook stay, and a file that still holds a user comment is kept. The _without_managed_hooks docstring says it preserves "every other source slice verbatim" (src/specify_cli/integrations/vibe/__init__.py:477-490), and the remove_vibe_event_hooks docstring says it removes "only Specify-owned Vibe hooks and delete[s] an owned-only file" (vibe/__init__.py:553-590). The tests test_empty_events_preserve_comments_only_file and test_removal_preserves_user_comment_with_marker_text (tests/integrations/test_integration_vibe.py:496-528) treat user comments as content to keep.

Actual Behavior
[comment before a user hook]
  file exists after removal: True
  content: '[[hooks]]\nname = "user-hook"\ntype = "pre_tool"\ncommand = "guard-bash"\n'
[trailing user comment only]
  file exists after removal: False
  content: None

In the first case the line # NOTE: keep guard-bash first is gone. In the second case the file is deleted together with the user's comment.

Specify CLI Version

1.2.4.dev0 (main at 27d14e2)

AI Agent

Mistral Vibe

Operating System

Linux 6.18 (Ubuntu container)

Python Version

Python 3.12.3

Additional Context

A comment placed after a managed block is likely to describe the user content that follows it, as in the first case, so attaching it to the managed block loses user content.

Related: #4646 (merged) added this removal path. A review comment on that pull request flagged the comment loss, and no later commit addressed it.

Also reproduced on macOS (Darwin 25.6, arm64) with Python 3.14.4 and uv run python -I repro.py against 27d14e2; the output matches the above.

AI Disclosure

Found and reproduced with Claude Code (model: Claude Opus 4.8), run autonomously under human supervision. The human reporter re-ran every reproduction above before filing.

Langage dominant
Python
Étoiles
149k
Forks
13.4k
Merge moyen
1 j 5 h
PR mergées (30 j)
223

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de github/spec-kit

Toutes les issues de github/spec-kit

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.