# Pre-commit Configuration for diet-guard # Run `pre-commit install` after cloning: pre-commit hooks are not automatic. # Install: pre-commit install && pre-commit install --hook-type pre-push # Run: pre-commit run --all-files # Update: pre-commit autoupdate default_language_version: python: python3 default_stages: [pre-commit] fail_fast: false default_install_hook_types: [pre-commit, pre-push, post-commit, post-merge, post-rewrite] repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 hooks: - id: trailing-whitespace args: [--markdown-linebreak-ext=md] - id: end-of-file-fixer - id: check-yaml - id: check-json - id: check-toml - id: check-added-large-files args: [--maxkb=2000] - id: check-merge-conflict - id: detect-private-key - id: debug-statements - id: check-ast - id: mixed-line-ending args: [--fix=lf] - id: requirements-txt-fixer - repo: local hooks: - id: no-noqa name: Block noqa comments entry: '(?i)#\s*(noqa|type:\s*ignore)' language: pygrep types: [python] - id: no-ruff-noqa name: Block ruff noqa file-level comments entry: '(?i)#\s*ruff:\s*noqa' language: pygrep types: [python] - id: requirements-sync name: requirements.txt covers all package imports entry: python3 scripts/check_requirements_sync.py language: system pass_filenames: false files: ^(diet_guard/.*\.py|requirements\.txt)$ - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.15.2 hooks: - id: ruff-format types_or: [python, pyi] - repo: local hooks: # Split into <60 s steps (run in this order); no-arg ci_mirror.sh is the CI form. - id: ci-mirror-venv name: CI mirror 1 (clean venv) entry: bash scripts/ci_mirror.sh venv language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - id: ci-mirror-precommit name: CI mirror 2 (pre-commit --all-files) entry: bash scripts/ci_mirror.sh precommit language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - id: ci-mirror-pytest name: CI mirror 3 (pytest, xvfb, 100% cov) entry: bash scripts/ci_mirror.sh pytest language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - id: ci-mirror-flutter-test-1 name: CI mirror 5 (flutter test 1/12) entry: bash scripts/ci_mirror.sh flutter-test --shard 0/12 language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - id: ci-mirror-flutter-test-2 name: CI mirror 6 (flutter test 2/12) entry: bash scripts/ci_mirror.sh flutter-test --shard 1/12 language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - id: ci-mirror-flutter-test-3 name: CI mirror 7 (flutter test 3/12) entry: bash scripts/ci_mirror.sh flutter-test --shard 2/12 language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - id: ci-mirror-flutter-test-4 name: CI mirror 8 (flutter test 4/12) entry: bash scripts/ci_mirror.sh flutter-test --shard 3/12 language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - id: ci-mirror-flutter-test-5 name: CI mirror 9 (flutter test 5/12) entry: bash scripts/ci_mirror.sh flutter-test --shard 4/12 language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - id: ci-mirror-flutter-test-6 name: CI mirror 10 (flutter test 6/12) entry: bash scripts/ci_mirror.sh flutter-test --shard 5/12 language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - id: ci-mirror-flutter-test-7 name: CI mirror 11 (flutter test 7/12) entry: bash scripts/ci_mirror.sh flutter-test --shard 6/12 language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - id: ci-mirror-flutter-test-8 name: CI mirror 12 (flutter test 8/12) entry: bash scripts/ci_mirror.sh flutter-test --shard 7/12 language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - id: ci-mirror-flutter-test-9 name: CI mirror 13 (flutter test 9/12) entry: bash scripts/ci_mirror.sh flutter-test --shard 8/12 language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - id: ci-mirror-flutter-test-10 name: CI mirror 14 (flutter test 10/12) entry: bash scripts/ci_mirror.sh flutter-test --shard 9/12 language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - id: ci-mirror-flutter-test-11 name: CI mirror 15 (flutter test 11/12) entry: bash scripts/ci_mirror.sh flutter-test --shard 10/12 language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - id: ci-mirror-flutter-test-12 name: CI mirror 16 (flutter test 12/12) entry: bash scripts/ci_mirror.sh flutter-test --shard 11/12 language: system pass_filenames: false always_run: true require_serial: true stages: [manual] - repo: local hooks: # Fails a commit that still points crdt_sync at a local path. Local # tests would go green against a library CI has never seen, silently. - id: crdt-sync-override name: no local crdt_sync dependency_override entry: bash scripts/check_no_crdt_sync_override.sh app/pubspec.yaml language: system pass_filenames: false always_run: true # Every commit ships its own patch bump, so the release workflow's clean # vX.Y.Z tag tracks HEAD instead of whatever version was last hand-edited. # The Flutter app lives in app/, so point the script at its pubspec. - id: bump-patch-version name: Bump patch version in app/pubspec.yaml entry: bash scripts/bump_patch_version.sh --pubspec app/pubspec.yaml language: system pass_filenames: false always_run: true require_serial: true # unittest.mock.patch fails OPEN: once a refactor moves a name, a patch # target that still imports redirects nothing, the test passes, and the # suite writes to the real ~/.local/share/diet_guard. This resolves every # patch target statically so a stale path fails the commit instead. - id: patch-targets name: test patch targets resolve entry: python3 scripts/check_patch_targets.py diet_guard language: system pass_filenames: false files: ^diet_guard/ # Four markdown namespaces (README / CLAUDE* / DOCS* / TODO*), plus the # rule that a TODO carries "REMOVE ME AFTER FINISH" and nothing else may. # Shared gate in ~/src/utils owns the namespaces and the exemption list, so # one repo's idea of a valid name cannot drift from every other repo's. - id: md-naming name: markdown naming convention entry: scripts/check_md_naming.sh language: system files: \.(md|markdown)$ - id: todo-closer name: close Todo trailer tasks entry: scripts/todo_hooks.sh closer language: system stages: [post-commit] always_run: true pass_filenames: false - id: todo-import-pr-merge name: import PR Todo sections (pull) entry: scripts/todo_hooks.sh import-pr post-merge language: system stages: [post-merge] always_run: true pass_filenames: false - id: todo-import-pr-rewrite name: import PR Todo sections (pull --rebase) entry: scripts/todo_hooks.sh import-pr post-rewrite language: system stages: [post-rewrite] always_run: true pass_filenames: false # Every dependency on its ecosystem's newest STABLE release, exact-pinned # so the question is mechanically answerable at all. # # `files:` is what keeps this cheap: a commit touching only source makes # ZERO network requests, and manifest commits mostly hit a 6h disk cache. # # Runs WITHOUT --strict on purpose. Offline it degrades to the cached # answer and passes with a loud banner; `--no-verify` is banned here, so # a hook that hard-failed on a flaky connection would leave no way to # commit at all. CI, always online, is the strict authority. - id: dependency-freshness name: dependencies on newest stable entry: scripts/check_dependency_freshness.sh language: system pass_filenames: true files: >- (pubspec\.(yaml|lock)|pyproject\.toml|requirements.*\.txt|uv\.lock |package\.json|package-lock\.json|pnpm-lock\.yaml |Cargo\.(toml|lock)|go\.(mod|sum) |\.fvmrc|\.nvmrc|\.python-version |\.github/workflows/.*\.ya?ml)$ - repo: local hooks: # The only pre-push hook. Everything that used to run here is now # `stages: [manual]` -- run on demand with `scripts/check_gate_stamp.sh # full`, and by CI on every push. finish_auto.sh stamps HEAD after its # gate; a tree without that receipt cannot leave the machine. - id: gate-stamp name: pushed tree passed the local gate (stamp check) entry: scripts/check_gate_stamp.sh check language: system pass_filenames: false always_run: true stages: [pre-push] - id: repo-contract name: repo contract (CLAUDE.md Commands + test_changed) entry: scripts/check_repo_contract.sh language: system pass_filenames: false files: ^(CLAUDE\.md|AGENTS\.md|scripts/test_changed\.sh)$|(^|/)(AndroidManifest\.xml|build\.gradle(\.kts)?|strings\.xml|pubspec\.yaml|repo-contract\.toml|[^/]+\.desktop|assets/icon/[^/]+\.png)$