# ============================================================================== # Pre-commit Configuration - Multi-language Linting & Formatting # ============================================================================== # Install: pre-commit install && pre-commit install --hook-type pre-push # Fast lint: pre-commit run --all-files (linters only, ~10 s) # Full suite: pre-commit run --all-files --hook-stage pre-push (+ tests) # Update hooks: pre-commit autoupdate # ============================================================================== # Global settings default_language_version: python: python3 # By default every hook runs ONLY at commit-time. Pre-push runs only the # hooks that explicitly opt in via `stages: [pre-push]` (currently # pytest-coverage + prettier). This keeps `git push` cheap; commit-time # already enforces the full lint suite. default_stages: [pre-commit] # Fail fast on first error (set to false to see all errors) fail_fast: false # Configuration ci: autofix_commit_msg: "style: auto-fix by pre-commit hooks" autoupdate_commit_msg: "chore: update pre-commit hooks" repos: # =========================================================================== # GENERAL HOOKS - File formatting and validation # =========================================================================== - 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 args: [--unsafe] - id: check-json # Exclude JSONC files (VS Code configs, TypeScript configs) exclude: ^(\.vscode/|.*/\.vscode/|.*tsconfig.*\.json) - id: check-toml - id: check-xml - id: check-added-large-files args: [--maxkb=2000] - id: check-merge-conflict - id: check-case-conflict - id: check-symlinks - id: check-executables-have-shebangs - id: check-shebang-scripts-are-executable - id: detect-private-key - id: debug-statements - id: check-ast - id: check-builtin-literals - id: fix-byte-order-marker - id: mixed-line-ending args: [--fix=lf] - id: requirements-txt-fixer # =========================================================================== # BINARY BLOCKER - Prevent binary/image files from being committed # =========================================================================== - repo: local hooks: - id: no-binaries name: Block binary/image files entry: meta/scripts/check_no_binaries.sh language: script always_run: false - id: directory-depth-cap name: Enforce the directory-depth cap # Repo-wide and ENFORCING. It ran --warn while the 46 paths under # periodic_background/{hosts,digital_wellbeing} were over the cap; # both units are now their own repos (kuhyx/hosts-blocker, # kuhyx/digital-wellbeing) and the count is 0, so the cap is real. # Re-adding --warn would silently re-open the hole it was there to # close: put the offending path somewhere legal instead. entry: bash meta/scripts/check_directory_depth.sh --all language: system pass_filenames: false always_run: true - id: repo-size-cap name: Enforce the source-file ceiling # Counts tracked files only, excluding vendored and hook-generated # trees. Prints the count on every run so the ceiling is auditable. entry: bash meta/scripts/check_repo_size.sh language: system pass_filenames: false always_run: true - id: ci-baseline-green name: Refuse to build on a red CI baseline # Checks the last COMPLETED run of each required workflow on main. # Fails closed on a definitively red baseline; warns and passes on # anything it cannot determine (offline, no gh, no runs yet), because # the real per-change guarantee is the pre-push ci-mirror hook and # blocking every commit on network reachability is not worth it. # Bypass a deliberate fix-forward commit with CI_GREEN_SKIP=1. entry: bash meta/scripts/check_ci_green.sh language: system pass_filenames: false always_run: true - id: ai-evidence-contract name: Require AI evidence artifacts for code changes entry: meta/scripts/check_ai_evidence.sh language: script pass_filenames: false always_run: true - id: ai-multifile-contract name: Require workflow contract for multi-file code changes entry: meta/scripts/check_agent_contract.sh language: script pass_filenames: false always_run: true - id: append-only-sessions name: Enforce append-only session logs entry: meta/scripts/check_append_only_sessions.sh language: script pass_filenames: false always_run: true # =========================================================================== # POLLING SCRIPT LINTER - Detect fork-storm anti-patterns in shell scripts # =========================================================================== - repo: local hooks: - id: no-inline-python name: Block Python logic embedded in shell scripts entry: meta/scripts/check_no_inline_python.sh language: script types_or: [shell, zsh] - id: no-polling-antipatterns name: Block polling script anti-patterns entry: meta/scripts/check_polling_antipatterns.sh language: script types: [shell] require_serial: true exclude: ^(\.git/|tests/) # =========================================================================== # NOQA BLOCKER - Zero tolerance for noqa/type:ignore suppression comments # =========================================================================== - 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] # =========================================================================== # RUFF - Fast Python linter and formatter (replaces black, isort, flake8, etc.) # =========================================================================== - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.15.2 hooks: # Formatter - run after linting - id: ruff-format types_or: [python, pyi] # =========================================================================== # PYTEST + COVERAGE - Run tests and enforce 100% code coverage # Only tests for subpackages with changed files are run (see script). # Uses pytest-xdist (-n auto) to parallelize across all CPUs. # =========================================================================== - repo: local hooks: - id: requirements-sync name: requirements.txt covers all python_pkg imports entry: python3 meta/scripts/check_requirements_sync.py --package python_pkg language: system pass_filenames: false files: ^(python_pkg/.*\.py|requirements\.txt)$ - id: requirements-test-sync name: requirements-test.txt covers every import the CI pytest run makes # python-tests.yml installs this SUBSET rather than the full list, so # it needs the same completeness guarantee. --testpaths walks the # import closure of pyproject's testpaths, tests included: a test-only # import (hypothesis) or a dependency of a linux_configuration script # the tests load (jeepney) otherwise passed here and failed CI with a # bare ModuleNotFoundError. entry: python3 meta/scripts/check_requirements_sync.py --testpaths python_pkg linux_configuration/tests --requirements meta/requirements-test.txt language: system pass_filenames: false files: ^(python_pkg/.*|linux_configuration/.*|meta/scripts/.*)\.py$|^meta/requirements-test\.txt$ - id: session-autopsy-hook-mutations name: session_autopsy hook tests are non-vacuous (mutation) entry: python3 meta/scripts/mutate_session_autopsy_hooks.py language: system pass_filenames: false require_serial: true # Scoped to the two files that can invalidate the proof: the suite # itself and the mutation definitions. Takes ~40s, so it must not run # on unrelated commits. Skips itself where ~/.claude is absent (CI). files: ^(linux_configuration/tests/test_session_autopsy_hooks\.py|meta/scripts/mutate_session_autopsy_hooks\.py)$ - id: ci-mirror name: CI mirror (background; a failed verdict blocks the next push) entry: bash meta/scripts/ci_mirror.sh language: system pass_filenames: false always_run: true require_serial: 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)$ # =========================================================================== # VULTURE - Dead code detection (disabled - doesn't work well with pre-commit) # =========================================================================== # - repo: https://github.com/jendrikseipp/vulture # rev: v2.13 # hooks: # - id: vulture # args: # - --min-confidence=80 # - --exclude=.venv,Bash,__pycache__ # exclude: ^(Bash/|\.venv/) # =========================================================================== # PYUPGRADE - Upgrade Python syntax (disabled - incompatible with Python 3.14) # =========================================================================== # - repo: https://github.com/asottile/pyupgrade # rev: v3.19.0 # hooks: # - id: pyupgrade # args: # - --py310-plus # =========================================================================== # DOCFORMATTER - Format docstrings (disabled - causes recursion errors) # =========================================================================== # - repo: local # hooks: # - id: docformatter # name: docformatter # entry: docformatter # language: system # types: [python] # args: # - --in-place # - --wrap-summaries=88 # - --wrap-descriptions=88 # =========================================================================== # INTERROGATE - Docstring coverage (disabled - causes recursion on large files) # =========================================================================== # - repo: https://github.com/econchick/interrogate # rev: 1.7.0 # hooks: # - id: interrogate # args: # - --fail-under=0 # - --verbose # - --ignore-init-method # - --ignore-init-module # - --ignore-magic # - --ignore-private # - --ignore-semiprivate # - --exclude=Bash,.venv,__pycache__ # pass_filenames: false # =========================================================================== # AUTOFLAKE - Remove unused imports/variables # Disabled: fully redundant with ruff (F401, F841, F811) + --fix # =========================================================================== # - repo: https://github.com/PyCQA/autoflake # rev: v2.3.1 # hooks: # - id: autoflake # args: # - --in-place # - --remove-all-unused-imports # - --remove-unused-variables # - --remove-duplicate-keys # - --expand-star-imports # =========================================================================== # SAFETY - Check for security vulnerabilities in dependencies # =========================================================================== # Note: Safety requires API key for full functionality, disabled by default # - repo: https://github.com/Lucas-C/pre-commit-hooks-safety # rev: v1.3.2 # hooks: # - id: python-safety-dependencies-check # files: requirements.*\.txt$ # =========================================================================== # PYRIGHT - Microsoft's type checker (very strict, optional) # =========================================================================== # Uncomment to enable - can be slow and very strict # - repo: https://github.com/RobertCraiworthy/pyright-action # rev: v1.1.350 # hooks: # - id: pyright # =========================================================================== # CHECK JSON/YAML/TOML formatting (runs on push only — slow Node.js startup) # =========================================================================== - repo: local hooks: - id: prettier name: prettier (capped scope) # Wrapper runs prettier inside its own systemd-run scope so its # memory budget is independent of the outer pre-push cgroup that # has already accumulated page cache from pytest/mypy/pylint. entry: meta/scripts/run_prettier_capped.sh language: system types_or: [yaml, json, markdown] exclude: >- (?x)^( Bash/.*| \.venv/.*| third_party/.*| \.github/skills/.*| docs/superpowers/(plans|specs)/.*| linux_configuration/report/.*| .*\.lock )$ stages: [pre-push] # =========================================================================== # ZSH SYNTAX - zsh -n parse check (shellcheck has no zsh mode) # =========================================================================== - repo: local hooks: - id: zsh-syntax name: zsh syntax check entry: bash -c 'for f in "$@"; do zsh -n "$f" || exit 1; done' -- language: system types: [zsh] # =========================================================================== # CHECK PYTHON LOCATION - All Python files must be under python_pkg/ # =========================================================================== - repo: local hooks: - id: check-python-location name: check Python files are under python_pkg/ entry: meta/scripts/check_python_location.sh language: script types: [python] # =========================================================================== # REMOVE EMPTY DIRECTORIES - Clean up empty folders in the repo # =========================================================================== - repo: local hooks: - id: remove-empty-dirs name: remove empty directories entry: find . -type d -empty -not -path './.git/*' -delete -print language: system pass_filenames: false always_run: true # =========================================================================== # SECRET PATTERNS - Block commits containing sensitive data # =========================================================================== - repo: local hooks: - id: check-no-secrets name: check for leaked secrets entry: meta/scripts/check_no_secrets.sh language: script exclude: ^(\.secret-patterns|\.pre-commit-config\.yaml|.*\.geojson)$ - id: check-no-dufs-conf name: block dufs secret config (.dufs_cloud.conf) entry: meta/scripts/check_no_dufs_conf.sh language: script always_run: true pass_filenames: false # =========================================================================== # COMMITIZEN - Conventional commits (optional) # =========================================================================== # - repo: https://github.com/commitizen-tools/commitizen # rev: v3.13.0 # hooks: # - id: commitizen # - id: commitizen-branch # stages: [push] # 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)$ # 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. Local only: GitHub Actions does not run this gate # (see .dep-freshness-no-workflow); `--all --strict` is the manual sweep. - 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)$