# .pre-commit-config.yaml
#
# Install: pip install pre-commit && pre-commit install
# Run manually: pre-commit run --all-files
# Update hooks: pre-commit autoupdate

# A plain `pre-commit install` installs both hook types (needs pre-commit 2.18.0+).
# The AI commit audit below runs at the commit-msg stage.
default_install_hook_types: [pre-commit, commit-msg]

repos:
  # ─── General file hygiene ───────────────────────────────────────────
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.6.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-json
      - id: check-merge-conflict
      - id: check-added-large-files
        args: ['--maxkb=500']
      - id: no-commit-to-branch
        args: ['--branch', 'main', '--branch', 'staging', '--branch', 'master']

  # ─── Secret scanning ────────────────────────────────────────────────
  # Detects accidentally committed secrets and credentials
  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.18.4
    hooks:
      - id: gitleaks

  # ─── AI commit audit ────────────────────────────────────────────────
  # Warns when an AI-generated commit is detected (via attribution in commit message)
  # so the team can ensure human review happened before merge
  - repo: local
    hooks:
      - id: ai-commit-review-reminder
        name: AI commit — verify human review
        # commit-msg hooks receive the message file as $1 (`--` fills $0);
        # `git log -1` would read the previous commit.
        entry: >-
          bash -c 'grep -qiE "^Co-authored-by: Claude" "$1" && echo "⚠️  AI-assisted commit detected. Ensure a human has reviewed the changes before merging." || true' --
        language: system
        stages: [commit-msg]
        # pre-commit hides the output of a passing hook unless verbose is set.
        verbose: true

  # ─── Add your language-specific hooks below ─────────────────────────
  # JavaScript / TypeScript example:
  # - repo: local
  #   hooks:
  #     - id: typecheck
  #       name: TypeScript type check
  #       entry: npx tsc --noEmit
  #       language: system
  #       pass_filenames: false
  #     - id: lint
  #       name: ESLint
  #       entry: npx eslint --fix
  #       language: system
  #       types: [javascript, ts]

  # Python example:
  # - repo: https://github.com/astral-sh/ruff-pre-commit
  #   rev: v0.4.4
  #   hooks:
  #     - id: ruff
  #       args: [--fix]
  #     - id: ruff-format
