Files
agentic-dev-template/.claude/hooks/library-policy-nudge.sh
Danijel Martinek b0191a7cbe feat(scripts): add library-policy-nudge hook + smoke tests
Registers .claude/hooks/library-policy-nudge.sh under PreToolUse/Bash
and PostToolUse/Edit|Write|MultiEdit. The hook emits a non-blocking
system-reminder pointing at /evaluate-library before runtime deps are
added via pnpm add or via direct package.json edits, so policy
evaluation happens before the pre-commit gate fires.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 05:34:29 +00:00

48 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Advisory — nudges the agent to run /evaluate-library before adding runtime
# dependencies. Non-blocking (exit 0). Stdout is injected as system-reminder
# context by the harness.
#
# Dispatches on payload shape:
# .tool_input.command → PreToolUse / Bash (pnpm add / pnpm i <pkg>)
# .tool_input.file_path → PostToolUse / Edit|Write (**/package.json edits)
set -euo pipefail
input=$(cat)
# --- PreToolUse / Bash path ---
cmd=$(printf '%s' "$input" | jq -r '.tool_input.command // ""')
if [[ -n "$cmd" ]]; then
# Match: pnpm add <...> or pnpm i <pkg> — must have a space after keyword
if [[ "$cmd" =~ (^|[[:space:]])pnpm[[:space:]]+(add[[:space:]]|i[[:space:]]) ]]; then
# Skip dev-dependency installs — no policy evaluation needed for devDeps
if [[ ! "$cmd" =~ (^|[[:space:]])(-D|--save-dev)([[:space:]]|$) ]]; then
cat <<'EOF'
[library-policy-nudge] Runtime dependency detected — evaluate before adding.
Run the evaluate-library skill first:
/evaluate-library <name> --tier <feature|core|app> --target <package-path>
This ensures the dependency is logged in docs/decisions/ before the pre-commit gate fires.
EOF
fi
fi
exit 0
fi
# --- PostToolUse / Edit|Write path ---
file_path=$(printf '%s' "$input" | jq -r '.tool_input.file_path // ""')
if [[ "$file_path" == */package.json ]]; then
cat <<'EOF'
[library-policy-nudge] package.json edited — verify any new runtime dependencies are evaluated.
If you added a runtime dependency, run the evaluate-library skill:
/evaluate-library <name> --tier <feature|core|app> --target <package-path>
This ensures the dependency is logged in docs/decisions/ before the pre-commit gate fires.
EOF
fi
exit 0