#!/usr/bin/env bash

# Guard commit messages against explicit AI usage indicators.
# The script rejects messages containing phrases that suggest the text
# was generated by an AI assistant or tool (as defined in onboarding docs).

set -euo pipefail

MSG_FILE=${1:?}

# Patterns to block; all matches are case-insensitive (grep -i).
declare -a PATTERNS=(
  "generated by cursor"
  "cursor ai"
  "cursor wrote this"
  "cursor suggestion"
  "generated by claude"
  "claude wrote this"
  "claude ai"
  "claude opus"
  "claude sonnet"
  "claude haiku"
  "claude code"
  "generated with claude code"
  "generated with \\[claude code\\]"
  "co-authored-by: claude"
  "noreply@anthropic\\.com"
  "generated by gemini"
  "gemini wrote this"
  "google gemini"
  "gemini ultra"
  "gemini pro"
  "gemini nano"
  "generated by bard"
  "bard wrote this"
  "google bard"
  "as an ai assistant"
  "as an ai"
  "ai assistant"
  "ai suggestion"
  "ai suggestions"
  "ai-generated"
  "ai generated"
  "ai-assisted"
  "ai assisted"
  "ai-powered"
  "ai powered"
  "powered by ai"
  "with ai assistance"
  "with the help of ai"
  "assisted by ai"
  "written with ai"
  "written by ai"
  "generated with ai"
  "generated via ai"
  "created with ai"
  "created by ai"
  "authored by ai"
  "co-authored by ai"
  "ai help"
  "ai helped"
  "ai copilot"
  "ai co-pilot"
  "chatgpt"
  "gpt-4"
  "gpt4"
  "gpt-3"
  "gpt3"
  "openai"
  "anthropic"
  "google ai"
  "google deepmind"
  "deepmind"
  "perplexity"
  "perplexity ai"
  "tabnine"
  "tabnine ai"
  "replit ghostwriter"
  "ghostwriter ai"
  "aws codewhisperer"
  "amazon codewhisperer"
  "code whisperer"
  "codewhisperer"
  "github copilot"
  "copilot"
  "amazon q"
  "amazon q developer"
  "meta ai"
  "deepseek"
  "phind"
  "blackbox ai"
  "magic ai"
  "ai model"
  "llm"
  "large language model"
  "language model"
  "\\[ai\\]"
  "\\[ai-generated\\]"
  "\\[cursor\\]"
  "\\[claude\\]"
  "\\[gemini\\]"
  "\\[copilot\\]"
  "\\[chatgpt\\]"
  "\\[llm\\]"
)

for pattern in "${PATTERNS[@]}"; do
  if LC_ALL=C grep -qiE "$pattern" "$MSG_FILE"; then
    cat >&2 <<EOF
✖ Commit message blocked: found AI indicator "$pattern".

Please rewrite the message without explicitly referencing AI tools or prompts.
EOF
    exit 1
  fi
done

exit 0
