Skip to content

Commit 551da47

Browse files
codejunkie99claude
andcommitted
Replace prompt-based PostToolUse hook with deterministic Python script
The prompt-based hook was unreliably blocking non-SV file writes (e.g. .ts files) because the LLM would generate explanatory text instead of returning a clean {}. The new deterministic script checks file extensions directly, guaranteeing silent pass-through for non-SV files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1c90b40 commit 551da47

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

plugins/gateflow/hooks/hooks.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
"matcher": "Write|Edit",
4040
"hooks": [
4141
{
42-
"type": "prompt",
43-
"prompt": "Check if the file just written/edited is a SystemVerilog or Verilog file (.sv, .svh, .v, .vh). Return ONLY a JSON object. If it IS an SV/V file: {\"systemMessage\": \"SV file modified. Run /gf-lint to check for issues, or continue if you plan to lint later.\"}. If it is NOT an SV file: {}.",
44-
"timeout": 10
42+
"type": "command",
43+
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/scripts/posttooluse-sv-lint-nudge.py",
44+
"timeout": 2
4545
}
4646
]
4747
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python3
2+
"""GateFlow PostToolUse hook for Write/Edit events.
3+
4+
Deterministic check: if the file just written/edited has a SystemVerilog or
5+
Verilog extension, remind the user to lint. For all other file types, silently
6+
pass through.
7+
"""
8+
9+
from __future__ import annotations
10+
11+
import json
12+
import sys
13+
from typing import Any, Dict
14+
15+
16+
SV_EXTENSIONS = (".sv", ".svh", ".v", ".vh")
17+
18+
19+
def main() -> int:
20+
try:
21+
payload: Dict[str, Any] = json.load(sys.stdin)
22+
except Exception:
23+
sys.stdout.write("{}")
24+
return 0
25+
26+
tool_input = payload.get("tool_input", {}) or {}
27+
file_path = tool_input.get("file_path", "") if isinstance(tool_input, dict) else ""
28+
29+
if isinstance(file_path, str) and file_path.lower().endswith(SV_EXTENSIONS):
30+
out = {
31+
"systemMessage": (
32+
"SV file modified. Run /gf-lint to check for issues, "
33+
"or continue if you plan to lint later."
34+
)
35+
}
36+
sys.stdout.write(json.dumps(out))
37+
else:
38+
sys.stdout.write("{}")
39+
40+
return 0
41+
42+
43+
if __name__ == "__main__":
44+
raise SystemExit(main())

0 commit comments

Comments
 (0)