#!/usr/bin/env bash # commit-msg hook: enforce the Human Voice policy on commit messages. # # allow Signed-off-by: Jane Doe (required, DCO) # allow Co-Authored-By: Jane Doe (human pair) # reject Co-Authored-By: Claude # reject "Generated with Claude Code", "🤖 Generated", etc. # # See AI_POLICY.md and CONTRIBUTING.md#commits. # # Install: ln -sf ../../scripts/hooks/commit-msg .git/hooks/commit-msg set -uo pipefail MSG_FILE="${1:-}" [ -n "$MSG_FILE" ] && [ -f "$MSG_FILE" ] || exit 0 # Strip comment lines, as git does. BODY=$(grep -v '^#' "$MSG_FILE" | sed '/^[[:space:]]*$/d') # Nothing to check (e.g. an empty commit message that another hook will reject). [ -n "$BODY" ] || exit 0 # Merges and reverts carry their own generated shapes. case "$BODY" in Merge\ *|Revert\ *) exit 0 ;; esac AI_NAMES='claude|copilot|chatgpt|gpt-[0-9]|openai|anthropic|gemini|bard|cursor|windsurf|codeium|codex|devin|aider|tabnine|sourcegraph|continue\.dev|\[bot\]|noreply@anthropic|noreply@openai' fail=0 if echo "$BODY" | grep -qiE "^[[:space:]]*co-authored-by:.*($AI_NAMES)"; then printf 'commit-msg: AI co-author trailer is not allowed.\n' printf ' Your name on the commit is the whole attribution (AI_POLICY.md).\n' fail=1 fi if echo "$BODY" | grep -qiE "(generated (with|by)|written (with|by)|assisted by|powered by)[[:space:]:]+.*($AI_NAMES|claude|copilot)"; then printf 'commit-msg: tool attribution footer is not allowed (AI_POLICY.md).\n' fail=1 fi if echo "$BODY" | grep -q $'\xf0\x9f\xa4\x96'; then printf 'commit-msg: robot-emoji signature is not allowed (AI_POLICY.md).\n' fail=1 fi if ! echo "$BODY" | grep -qE "^[[:space:]]*Signed-off-by: .+ <.+@.+>"; then printf 'commit-msg: missing DCO sign-off.\n' printf ' Use: git commit -s (adds Signed-off-by: Your Name )\n' printf ' See LICENSING.md#contributing-the-dco.\n' fail=1 fi [ "$fail" -eq 0 ] || exit 1 exit 0