# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
# CodeRabbit Configuration
# https://docs.coderabbit.ai/guides/configure-coderabbit

language: en-US

# Tone instructions for reviews
tone_instructions: |
  Be concise and direct. Focus on actionable feedback.
  Python project using modern tooling (uv, ruff, mypy).
  Integrates with FreeCAD CAD software via MCP protocol.

early_access: false

# Enable or disable reviews
reviews:
  # Enable automated code reviews
  auto_review:
    enabled: true
    # Don't review drafts until ready
    drafts: false
    # Review base branches (PRs to main)
    base_branches:
      - main
      - master

  # Review profile - assertive catches more issues
  profile: assertive

  # Request changes when issues found
  request_changes_workflow: true

  # High-level summary in PR comments
  high_level_summary: true
  high_level_summary_placeholder: "@coderabbitai summary"

  # Add poem to review (disabled - keep it professional)
  poem: false

  # Collapse walkthrough in large PRs
  collapse_walkthrough: true

  # Review labeling
  labeling_instructions:
    - label: "security"
      instructions: "Apply when security vulnerabilities are found"
    - label: "breaking-change"
      instructions: "Apply when changes break backward compatibility"
    - label: "documentation"
      instructions: "Apply when documentation changes are needed"

  # Paths to always review carefully
  path_instructions:
    - path: "src/freecad_mcp/**/*.py"
      instructions: >
        This is the core MCP server code. Pay attention to:
        - Async/await patterns
        - Error handling for FreeCAD operations
        - Type hints and Pydantic models
        - Security of execute_python functionality
    - path: "src/freecad_mcp/tools/**/*.py"
      instructions: >
        These are MCP tool implementations. Ensure:
        - Proper docstrings for tool discovery
        - Consistent error handling patterns
        - GUI-safe checks (FreeCAD.GuiUp) for view operations
    - path: "addon/FreecadRobustMCP/**/*.py"
      instructions: >
        This code runs inside FreeCAD's Python environment as a workbench addon.
        It cannot import packages from the project's virtualenv (mcp, pydantic).
        Watch for accidental imports of project dependencies.
    - path: "macros/**/*.FCMacro"
      instructions: >
        FreeCAD macro files. These are standalone Python scripts.
        They run in FreeCAD's environment with access to FreeCAD, Part, etc.
    - path: "tests/**/*.py"
      instructions: >
        Test files. Ensure good test coverage and clear assertions.
        Integration tests require FreeCAD MCP bridge to be running.
    - path: ".github/workflows/**/*.yaml"
      instructions: >
        GitHub Actions workflows. Check for:
        - Proper caching configuration
        - Security of secrets handling
        - Correct job dependencies

        INTENTIONAL PATTERNS (do not flag as issues):
        - continue-on-error: true on test steps is intentional during stabilization
        - upload-artifact@v6 and download-artifact@v7 work on GitHub-hosted runners
        - Actions version jumps (v4 to v6/v7) are intentional Dependabot updates
    - path: "pyproject.toml"
      instructions: >
        Project configuration. Watch for:
        - Dependency version constraints
        - Tool configuration consistency (ruff, mypy, pytest)

        CRITICAL: Python 3.11 is required - FreeCAD bundles libpython3.11.
        Using a different Python version causes ABI incompatibility crashes.

        INTENTIONAL PATTERN - Dependency version ranges:
        - Dependencies use '>=' minimum version constraints (e.g., pydantic>=2.0)
        - This is correct for Python libraries per PEP 440 best practices
        - Exact versions are pinned in uv.lock for reproducible builds
        - Do NOT suggest changing '>=' to '==' - this would break library usability
        - The combination of '>=' in pyproject.toml + uv.lock is the modern standard
    - path: "README.md"
      instructions: >
        INTENTIONAL NAMING: The repo is "freecad-robust-mcp-and-more" but Docker
        image and PyPI package are "freecad-robust-mcp". This is documented and
        intentional - do NOT flag as a naming mismatch or inconsistency.
    - path: "Dockerfile"
      instructions: >
        INTENTIONAL NAMING: Image name "freecad-robust-mcp" differs from repo name
        "freecad-robust-mcp-and-more". This is intentional and documented in README.
        Do NOT flag as a naming mismatch.
    - path: ".mise.toml"
      instructions: >
        Tool version management via mise. All versions use fuzzy matching:
        - "0.9" means "0.9.x" (allows patch updates)
        - "1.43" means "1.43.x" (allows patch updates)
        This is consistent and intentional. Do not flag as inconsistent pinning.

        CRITICAL: Python must stay at 3.11 to match FreeCAD's bundled Python.
    - path: "justfile"
      instructions: >
        Main task runner configuration using just (https://just.systems/).
        Imports modules from the just/ directory.
    - path: "just/*.just"
      instructions: >
        Just module files for task automation.

        INTENTIONAL PATTERN - Heredoc indentation:
        - Heredoc content inside recipes IS indented with 4 spaces (matching recipe body)
        - This is CORRECT - just automatically strips leading indentation from heredocs
        - Do NOT suggest adding more indentation to heredoc content
        - Do NOT suggest removing indentation from heredoc content
        - The 4-space indent prevents just from parsing embedded code as justfile syntax
        - Example: Python code in heredocs uses 4-space indent, just outputs it unindented

        INTENTIONAL PATTERN - Module paths:
        - Modules use `project_root := justfile_directory()` to get project root
        - Do NOT suggest using $(pwd) - it returns the wrong directory in modules

  # Tools to use for analysis
  tools:
    # Python-specific tools
    ruff:
      enabled: true
    # General tools
    shellcheck:
      enabled: true
    markdownlint:
      enabled: true
    yamllint:
      enabled: true
    hadolint:
      enabled: true

  # Files and paths to ignore in reviews (! prefix = exclude)
  path_filters:
    # Lock files - auto-generated
    - "!uv.lock"
    - "!poetry.lock"
    - "!package-lock.json"
    # Generated/cached files
    - "!**/.mypy_cache/**"
    - "!**/.pytest_cache/**"
    - "!**/.ruff_cache/**"
    - "!**/__pycache__/**"
    - "!**/*.pyc"
    # Virtual environments
    - "!.venv/**"
    - "!venv/**"
    # IDE settings (except shared configs)
    - "!.idea/**"
    # Build artifacts
    - "!dist/**"
    - "!build/**"
    - "!*.egg-info/**"
    # Documentation build output
    - "!site/**"
    # Secrets baseline (reviewed separately)
    - "!.secrets.baseline"

# Chat configuration
chat:
  auto_reply: true

# Knowledge base for context
knowledge_base:
  opt_out: false
  learnings:
    scope: auto
  issues:
    scope: auto
  jira:
    project_keys: []
  pull_requests:
    scope: auto
