# Invar Pre-commit Hooks
# Install: pip install pre-commit && pre-commit install
#
# Smart Guard: Detects rule-affecting file changes and runs full guard when needed.
# This prevents "works locally, fails in CI" issues when rule severity is upgraded.
#
# Structure Protection (DX-11): Warns if INVAR.md is modified directly.

repos:
  - repo: local
    hooks:
      # DX-11: Warn if INVAR.md is modified directly
      - id: invar-md-protected
        name: INVAR.md Protection
        entry: bash -c 'if git diff --cached --name-only | grep -q "^INVAR.md$"; then echo "Warning - INVAR.md was modified directly. Use git commit --no-verify if intentional."; exit 1; fi'
        language: system
        pass_filenames: false
        stages: [pre-commit]

      # Ruff - Fast Python linter (catches import sorting, code style issues)
      - id: ruff-check
        name: Ruff Check
        entry: bash -c 'source .venv/bin/activate && ruff check src/invar/'
        language: system
        pass_filenames: false
        stages: [pre-commit]
        types: [python]

      # Mypy - Static type checker (checks critical modules only)
      - id: mypy
        name: Type Check (mypy)
        entry: bash -c 'source .venv/bin/activate && mypy src/invar/mcp/handlers.py src/invar/core/doc_parser.py src/invar/core/doc_edit.py src/invar/shell/doc_tools.py --ignore-missing-imports --follow-imports=silent'
        language: system
        pass_filenames: false
        stages: [pre-commit]
        types: [python]

      # Smart Invar Guard - Full verification (static + doctests)
      # Runs full guard when rule files are modified, --changed otherwise
      # Note: invar guard already includes doctests, no separate pytest needed
      - id: invar-guard
        name: Invar Guard
        entry: bash scripts/smart-guard.sh
        language: system
        pass_filenames: false
        stages: [pre-commit]
        types: [python]
