#!/bin/sh

# Enforce conventional commit format: type(scope?): description
# Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
commit_msg=$(cat "$1")
pattern='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?: .+'

if ! echo "$commit_msg" | head -1 | grep -qE "$pattern"; then
  echo "ERROR: Commit message does not follow Conventional Commits format."
  echo ""
  echo "  Format: <type>(<scope>): <description>"
  echo "  Types:  feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
  echo ""
  echo "  Examples:"
  echo "    feat(core): add Gemini provider support"
  echo "    fix(cli): correct exit code for help"
  echo "    docs: update API reference"
  echo ""
  exit 1
fi
