Update NagLint hooks

This commit is contained in:
Mats Bosson 2026-03-29 05:24:13 +07:00
parent 0268422c81
commit 16f17ad133
2 changed files with 16 additions and 7 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# NagLint PostToolUse hook — runs after Write/Edit on .ts/.tsx/.js/.jsx files # NagLint PostToolUse hook — runs after Write/Edit on .ts/.tsx/.js/.jsx files
# Reads tool_use JSON from stdin, extracts file_path, runs nag --json # Reads tool_use JSON from stdin, extracts file_path, runs nag --agent-json
NAG=/Users/matsbosson/Documents/StayThree/NagLint/target/release/nag NAG=/Users/matsbosson/Documents/StayThree/NagLint/target/release/nag
@ -27,7 +27,7 @@ if [ ! -f "$FILE" ]; then
exit 0 exit 0
fi fi
RAW=$("$NAG" "$FILE" --json 2>/dev/null) RAW=$("$NAG" "$FILE" --agent-json 2>/dev/null)
if [ "$RAW" = "{}" ] || [ -z "$RAW" ]; then if [ "$RAW" = "{}" ] || [ -z "$RAW" ]; then
echo "{}" echo "{}"
@ -48,22 +48,18 @@ except Exception:
print(raw) print(raw)
sys.exit(0) sys.exit(0)
# If no decision:block, pass through as-is
if d.get('decision') != 'block': if d.get('decision') != 'block':
print(raw) print(raw)
sys.exit(0) sys.exit(0)
reason = d.get('reason', '') reason = d.get('reason', '')
# Filter AI-08 lines from reason
filtered_lines = [l for l in reason.splitlines() if '[AI-08]' not in l] filtered_lines = [l for l in reason.splitlines() if '[AI-08]' not in l]
filtered_reason = '\n'.join(filtered_lines).strip() filtered_reason = '\n'.join(filtered_lines).strip()
if not filtered_reason: if not filtered_reason:
# All violations were AI-08 — file is clean for our purposes
print('{}') print('{}')
else: else:
d['reason'] = filtered_reason d['reason'] = filtered_reason
# Also update additionalContext
ctx = d.get('hookSpecificOutput', {}).get('additionalContext', '') ctx = d.get('hookSpecificOutput', {}).get('additionalContext', '')
ctx_lines = [l for l in ctx.splitlines() if '[AI-08]' not in l] ctx_lines = [l for l in ctx.splitlines() if '[AI-08]' not in l]
d['hookSpecificOutput']['additionalContext'] = '\n'.join(ctx_lines) d['hookSpecificOutput']['additionalContext'] = '\n'.join(ctx_lines)

View File

@ -1,12 +1,25 @@
{ {
"hooks": { "hooks": {
"PreToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "jq -r '.tool_input.file_path // \"\"' | { read -r f; case \"$f\" in *.rs|*.js|*.jsx|*.mjs|*.cjs|*.ts|*.tsx|*.mts|*.cts) /Users/matsbosson/Documents/StayThree/NagLint/target/release/nag --rules-summary | jq -Rs '{hookSpecificOutput: {hookEventName: \"PreToolUse\", additionalContext: .}}';; *) echo '{}';; esac; }",
"statusMessage": "NagLint rules..."
}
]
}
],
"PostToolUse": [ "PostToolUse": [
{ {
"matcher": "Write|Edit", "matcher": "Write|Edit",
"hooks": [ "hooks": [
{ {
"type": "command", "type": "command",
"command": "/Users/matsbosson/Documents/StayThree/PettyUI/.claude/hooks/naglint.sh" "command": "/Users/matsbosson/Documents/StayThree/PettyUI/.claude/hooks/naglint.sh",
"statusMessage": "NagLint checking..."
} }
] ]
} }