From 16f17ad133f59eabdb4fa2c9785dadb8d96a8eb5 Mon Sep 17 00:00:00 2001 From: Mats Bosson Date: Sun, 29 Mar 2026 05:24:13 +0700 Subject: [PATCH] Update NagLint hooks --- .claude/hooks/naglint.sh | 8 ++------ .claude/settings.json | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.claude/hooks/naglint.sh b/.claude/hooks/naglint.sh index 3f316fa..dd0601e 100755 --- a/.claude/hooks/naglint.sh +++ b/.claude/hooks/naglint.sh @@ -1,6 +1,6 @@ #!/bin/bash # 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 @@ -27,7 +27,7 @@ if [ ! -f "$FILE" ]; then exit 0 fi -RAW=$("$NAG" "$FILE" --json 2>/dev/null) +RAW=$("$NAG" "$FILE" --agent-json 2>/dev/null) if [ "$RAW" = "{}" ] || [ -z "$RAW" ]; then echo "{}" @@ -48,22 +48,18 @@ except Exception: print(raw) sys.exit(0) -# If no decision:block, pass through as-is if d.get('decision') != 'block': print(raw) sys.exit(0) 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_reason = '\n'.join(filtered_lines).strip() if not filtered_reason: - # All violations were AI-08 — file is clean for our purposes print('{}') else: d['reason'] = filtered_reason - # Also update additionalContext ctx = d.get('hookSpecificOutput', {}).get('additionalContext', '') ctx_lines = [l for l in ctx.splitlines() if '[AI-08]' not in l] d['hookSpecificOutput']['additionalContext'] = '\n'.join(ctx_lines) diff --git a/.claude/settings.json b/.claude/settings.json index df12726..b80df20 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -1,12 +1,25 @@ { "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": [ { "matcher": "Write|Edit", "hooks": [ { "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..." } ] }