#!/usr/bin/env bash # The commit-msg hook encodes the Human Voice policy (AI_POLICY.md §"What agents must not do"). # If the hook silently stops rejecting, nothing else will notice. set -uo pipefail cd "$(dirname "$0")/../.." || exit 1 HOOK="./scripts/hooks/commit-msg" [ -x "$HOOK" ] || { printf 'FAIL: %s missing or not executable\n' "$HOOK"; exit 1; } tmp=$(mktemp); trap 'rm -f "$tmp"' EXIT fail=0 case_() { # name, message, expected exit printf '%s\n' "$2" > "$tmp" "$HOOK" "$tmp" >/dev/null 2>&1 got=$? if [ "$got" -ne "$3" ]; then printf ' %-28s expected exit %s, got %s\n' "$1" "$3" "$got"; fail=1 fi } SIGN='Signed-off-by: A Human ' case_ "own words + DCO" "feat(hal): replay traces Why it matters, briefly. $SIGN" 0 case_ "human co-author" "fix(ui): dock overflow Body. $SIGN Co-Authored-By: Jane Doe " 0 case_ "AI co-author" "feat: gauges Co-Authored-By: Claude $SIGN" 1 case_ "tool footer" "feat: gauges Generated with Claude Code $SIGN" 1 case_ "robot signature" "feat: gauges 🤖 Generated $SIGN" 1 case_ "missing DCO" "feat: gauges Body only." 1 case_ "merge commit exempt" "Merge branch 'feat/hal'" 0 [ "$fail" -eq 0 ] || { printf 'FAIL: commit-msg hook behaviour regressed\n'; exit 1; } printf 'OK: commit-msg hook rejects AI attribution, requires DCO\n'