Skip to content

Incremental engine for long horizon agents 🌟 Star if you like it!

6.6 KB
Raw Blame
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
      - id: check-case-conflict
        # Check for files with names that would conflict on a case-insensitive
        # filesystem like MacOS HFS+ or Windows FAT.
      - id: check-merge-conflict
        # Check for files that contain merge conflict strings.
      - id: check-symlinks
        # Checks for symlinks which do not point to anything.
        exclude: ".*(.github.*)$"
      - id: detect-private-key
        # Checks for the existence of private keys.
        # gdrive.rs holds a throwaway test-only RSA key (RS256 JWT signing test);
        # oci_object_storage.rs only references the PEM key header in doc comments.
        # (This comment must avoid the literal key-header phrase, or the hook would
        # flag its own config file.)
        exclude: "^rust/sdk/cocoindex/src/connectors/(gdrive|oci_object_storage)\\.rs$"
      - id: end-of-file-fixer
        # Makes sure files end in a newline and only a newline.
        exclude: ".*(data.*|licenses.*|_static.*|\\.ya?ml|\\.jpe?g|\\.png|\\.svg|\\.webp)$"
      - id: trailing-whitespace
        # Trims trailing whitespace.
        exclude_types: [python]  # ruff-format handles Python; this line-based fixer would also edit string literals.
        exclude: ".*(data.*|licenses.*|_static.*|\\.ya?ml|\\.jpe?g|\\.png|\\.svg|\\.webp)$"

  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.30.1
    hooks:
      - id: gitleaks
        # Scans the staged diff for hardcoded secrets before each commit.

  - repo: local
    hooks:
      - id: cargo-fmt
        name: cargo fmt
        entry: cargo fmt
        language: system
        types: [rust]
        pass_filenames: false

  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.12.0
    hooks:
      # Lint before formatting, as Ruff recommends with `--fix`.
      - id: ruff-check
        args: [--fix]
      - id: ruff-format

  - repo: https://github.com/astral-sh/uv-pre-commit
    rev: 0.6.1
    hooks:
      - id: uv-lock
        # Ensures uv.lock is up to date with pyproject.toml

  - repo: local
    hooks:
        - id: mypy-check
          name: mypy type check
          entry: uv run mypy
          language: system
          files: ^(python/|examples/|benchmarks/|pyproject\.toml)
          pass_filenames: false

        - id: maturin-develop
          name: maturin develop
          entry: ./dev/run_maturin_develop.sh
          language: system
          # Every input of a hook that imports the extension (pytest,
          # generate-cli-docs): CI starts without a built extension and builds
          # it only when this hook runs.
          files: ^(rust/|python/|Cargo\.(toml|lock)$|pyproject\.toml$|uv\.lock$|dev/generate_cli_docs\.py$|docs/src/content/docs/cli\.mdx$)
          pass_filenames: false

        - id: cargo-test
          name: cargo test
          entry: ./dev/run_cargo_test.sh
          # The Rust SDK's crates, and the CLI that builds on it, are left to
          # cargo-test-sdk.
          args: [
            --workspace,
            --exclude, cocoindex,
            --exclude, cocoindex_macros,
            --exclude, cocoindex_cli,
            --exclude, cocoindex_cli_fixture_app,
          ]
          language: system
          files: ^(rust/|Cargo\.(toml|lock)$)
          pass_filenames: false

        # The Rust SDK isn't launched yet, so its hooks (cargo-test-sdk,
        # cargo-clippy-sdk, cargo-test-rust-externs) run only for changes to the
        # SDK itself, to the `cocoindex` CLI for Rust projects (rust/cli) and
        # to the Rust examples and benchmarks that build on the SDK.
        # A change to the code the SDK builds on (rust/core, Cargo.lock, ...)
        # skips them. CI runs them on no pull request and in no merge group,
        # so a local run is the check before a change lands; the daily Rust SDK
        # workflow runs them on all of main.
        - id: cargo-test-sdk
          name: cargo test (Rust SDK)
          entry: ./dev/run_cargo_test_sdk.sh
          language: system
          files: ^rust/(sdk|cli)/
          pass_filenames: false

        - id: cargo-clippy
          name: cargo clippy
          entry: ./dev/run_cargo_clippy.sh
          language: system
          files: ^(rust/|Cargo\.(toml|lock)$)
          pass_filenames: false

        - id: cargo-clippy-sdk
          name: cargo clippy (Rust SDK)
          entry: ./dev/run_cargo_clippy_sdk.sh
          language: system
          files: ^rust/(sdk|cli)/
          pass_filenames: false

        - id: update-rust-extern-locks
          name: update Cargo.lock (rust examples + benchmarks)
          entry: ./dev/update_rust_extern_locks.sh
          language: system
          # Any rust/ change can shift the cocoindex SDK's transitive deps and
          # stale these external lockfiles, so trigger on the whole rust tree.
          # Ordered before cargo-test-rust-externs so a refresh in the same run
          # satisfies its `--locked` check.
          files: ^(rust/|examples/rust/|benchmarks/.*/rust/|Cargo\.toml)
          pass_filenames: false

        - id: cargo-test-rust-externs
          name: cargo check (rust examples + benchmarks)
          entry: ./dev/run_cargo_test_rust_externs.sh
          language: system
          files: ^(rust/sdk/|examples/rust/|benchmarks/.*/rust/)
          pass_filenames: false

        - id: cargo-tree-sdk-no-pyo3
          name: cargo tree (cocoindex SDK must not depend on pyo3)
          entry: ./dev/check_sdk_no_pyo3.sh
          language: system
          files: ^(rust/sdk/|rust/core/|rust/utils/|Cargo\.toml)
          pass_filenames: false

        - id: pytest
          name: pytest
          entry: uv run pytest python/
          language: system
          # The suite's inputs: the package and its tests, the extension, and
          # the locked environment. A Rust-only change can change Python
          # behavior through the extension, so it runs the suite too.
          files: ^(rust/|python/|Cargo\.(toml|lock)$|pyproject\.toml$|uv\.lock$)
          pass_filenames: false
          always_run: false

        - id: generate-cli-docs
          name: generate CLI documentation
          entry: uv run python dev/generate_cli_docs.py
          language: system
          # Includes cli.mdx itself so a manual edit to the generated file
          # re-runs the generator and is caught on PR CI (which runs prek only
          # on changed files). Otherwise a hand-edit to cli.mdx slips through
          # every PR and only surfaces on the all-files run after merge to main.
          files: ^(python/cocoindex/cli\.py|dev/generate_cli_docs\.py|docs/src/content/docs/cli\.mdx)$
          pass_filenames: false