# Pre-commit Configuration for Multi-Agent Projects
# Save as: .pre-commit-config.yaml (update existing or create new)
#
# Install: pre-commit install
# Run all: pre-commit run --all-files

repos:
  # Standard pre-commit hooks
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.5.0
    hooks:
      - id: trailing-whitespace
        exclude: ^\.agent-state/
      - id: end-of-file-fixer
        exclude: ^\.agent-state/
      - id: check-yaml
        args: [--unsafe]  # Allow custom tags in YAML
      - id: check-json
      - id: check-toml
      - id: check-merge-conflict
      - id: check-added-large-files
        args: ['--maxkb=500']
      - id: detect-private-key
      - id: no-commit-to-branch
        args: ['--branch', 'main']

  # Python code formatting (if using Python)
  - repo: https://github.com/psf/black
    rev: 24.1.1
    hooks:
      - id: black
        args: ['--line-length=100']
        language_version: python3

  # Import sorting (if using Python)
  - repo: https://github.com/pycqa/isort
    rev: 5.13.2
    hooks:
      - id: isort
        args: ['--profile=black', '--line-length=100']

  # Linting (if using Python)
  - repo: https://github.com/pycqa/flake8
    rev: 7.0.0
    hooks:
      - id: flake8
        args: ['--max-line-length=100', '--extend-ignore=E203,W503']

  # Custom multi-agent hooks
  - repo: local
    hooks:
      # Ownership verification hook
      - id: check-ownership
        name: Check Agent Ownership
        description: Verify file ownership and locks for multi-agent workflow
        entry: python tools/check-ownership.py
        language: python
        always_run: true
        pass_filenames: true
        additional_dependencies:
          - pyyaml
        # Only runs when SEO_AGENT_AUTHOR is set
        # If not set, hook will warn but not block

      # Commit message format hook
      - id: check-commit-message
        name: Check Commit Message Format
        description: Verify commit message follows [Agent] type(scope) format
        entry: python tools/check-ownership.py --check-commit-msg
        language: python
        stages: [commit-msg]
        additional_dependencies:
          - pyyaml

# CI Configuration
# These settings are used when running in CI environment
ci:
  autofix_commit_msg: |
    [CI] auto fixes from pre-commit hooks

    for more information, see https://pre-commit.ci
  autofix_prs: true
  autoupdate_branch: ''
  autoupdate_commit_msg: '[CI] pre-commit autoupdate'
  autoupdate_schedule: weekly
  skip: [check-ownership, check-commit-message]  # Skip custom hooks in CI
  submodules: false

# Default stages - hooks run at these stages unless otherwise specified
default_stages: [commit]
