Research-Stack/.pre-commit-config.yaml
Devin AI c946319be1 Add math-first tooling: receipt schema, claims registry, pre-commit, CI, MCP
Adds automated guardrails so mathematical rigor is enforced by tooling
instead of by convention. See docs/math-first-tooling.md for the full
contract.

Schemas + registry:
- shared-data/schemas/deepseek-review-receipt.schema.json
  Draft 2020-12 schema for the existing ollama_deepseek_review_receipt_v1
  and ollama_deepseek_review_continuation_receipt_v1 receipt formats. Pins
  sha256:<hex> hashes, non-negative token counts, repo-relative POSIX
  paths, and rejects additional fields.
- shared-data/schemas/claims-registry.schema.json
  Schema for claims.yaml. Requires review_receipts when status is
  verified-by-ai and a lean source when status is formally-proven.
- claims.yaml
  Initial registry entry: prime-gap-entropy-collapse (verified-by-ai)
  linked to the two existing receipts under
  shared-data/artifacts/deepseek_review/.

Validators (scripts/math-first/):
- validate_deepseek_receipts.py: validates tracked or passed receipts
  against the JSON Schema; shared by pre-commit and CI.
- test_validate_deepseek_receipts.py: positive + 7 negative fixtures
  asserting exit-code behaviour.
- validate_claims_registry.py: schema check + unique id check + on-disk
  existence check for every referenced repo-relative path.
- require_math_evidence.py: gate that requires a DeepSeek receipt, a
  Lean change, or a claims.yaml update alongside edits to math-track
  surfaces (Lean Semantics kernels, ArithmeticSpec docs, stack
  solidification receipts).

Pre-commit (.pre-commit-config.yaml):
- check-json, check-yaml, end-of-file-fixer, trim trailing whitespace,
  detect-private-key (scoped to math-first files only per AGENTS.md
  Do Not Sweep).
- Local hooks wiring all three math-first validators above.

CI (.github/workflows/math-check.yml):
- validate-schemas: compiles every schema, runs both validators, runs
  the validator self-tests, then re-invokes the canonical Ollama
  emitter in --verify-only mode against every tracked receipt to
  re-check answer_sha256 against the answer-file bytes on disk.
- require-evidence: enforces the math-track evidence rule at PR scope.
- pre-commit: runs all pre-commit hooks against the PR diff so the
  contract holds even for contributors who skip installing hooks
  locally.

MCP (.mcp.json):
- filesystem, sympy, wolfram-alpha, lean, deepseek-review entries
  pointing at off-the-shelf upstream servers and at the canonical
  ollama_deepseek_review_emitter.py. Secrets stay in the runtime env
  (WOLFRAM_ALPHA_APPID, OLLAMA_API_KEY) and are never embedded.

Docs (docs/math-first-tooling.md):
- Philosophy, surfaces, schema reference, registry workflow, hook
  catalogue, CI catalogue, MCP catalogue, end-to-end verify command.

shared-data/schemas/*.schema.json and claims.yaml live under paths the
top-level .gitignore would normally exclude; they are force-added via
git add -f the same way existing promoted receipts under
shared-data/artifacts/deepseek_review/ are tracked (per AGENTS.md).

Co-Authored-By: Allaun Silverfox <bigdataiscoming+9i37y6j2@protonmail.com>
2026-05-12 04:25:52 +00:00

88 lines
3.9 KiB
YAML

# Research Stack pre-commit configuration
# -----------------------------------------------------------------------------
# Math-first guardrails that run on every commit. See docs/math-first-tooling.md
# for the contract and rationale.
#
# Install once per clone:
# uv tool install pre-commit
# pre-commit install
#
# Run against the full tree:
# pre-commit run --all-files
# -----------------------------------------------------------------------------
default_install_hook_types: [pre-commit]
fail_fast: false
repos:
# --- Generic hygiene -------------------------------------------------------
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-json
# Schemas, MCP config, package.json, VS Code config, and JSON receipts.
files: '\.json$'
# Skip Lean editor metadata and Lake-managed lockfiles.
exclude: '\.(lean\.pist\.meta|lake)/'
- id: check-yaml
# Validate YAML at the syntactic level. The claims registry gets a
# stronger semantic check below.
files: '\.(ya?ml)$'
- id: end-of-file-fixer
# Force a trailing newline only on text files the math-first scripts
# actually own. Avoid sweeping the rest of the tree (see AGENTS.md).
files: '^(scripts/math-first/|shared-data/schemas/|claims\.yaml$|docs/math-first-tooling\.md$|\.mcp\.json$|\.pre-commit-config\.yaml$|\.github/workflows/math-check\.yml$)'
- id: trailing-whitespace
files: '^(scripts/math-first/|shared-data/schemas/|claims\.yaml$|docs/math-first-tooling\.md$|\.mcp\.json$|\.pre-commit-config\.yaml$|\.github/workflows/math-check\.yml$)'
- id: detect-private-key
# --- Math-first guardrails -------------------------------------------------
- repo: local
hooks:
- id: deepseek-receipt-schema
name: Validate DeepSeek review receipts
description: >-
Validates every tracked *.receipt.json under
shared-data/artifacts/deepseek_review/ against
shared-data/schemas/deepseek-review-receipt.schema.json.
entry: scripts/math-first/validate_deepseek_receipts.py
language: python
additional_dependencies:
- "jsonschema>=4.21"
- "rfc3339-validator"
files: '^shared-data/artifacts/deepseek_review/.*\.receipt\.json$'
# Pass matched files explicitly so partial commits still get a check
# but stay scoped to the changed receipts.
require_serial: true
types_or: [file]
- id: claims-registry-schema
name: Validate claims.yaml registry
description: >-
Validates claims.yaml against
shared-data/schemas/claims-registry.schema.json and asserts every
referenced repo-relative path exists on disk.
entry: scripts/math-first/validate_claims_registry.py
language: python
additional_dependencies:
- "jsonschema>=4.21"
- "PyYAML"
files: '^claims\.yaml$'
pass_filenames: false
require_serial: true
- id: receipt-required-for-math-content
name: Require a DeepSeek receipt or Lean proof for math-track content
description: >-
If a commit touches a file under one of the math-track surfaces
(Lean Semantics kernels, ArithmeticSpec docs, stack solidification
receipts), require that at least one file under
shared-data/artifacts/deepseek_review/ or
0-Core-Formalism/lean/Semantics/ is also part of the commit. This
enforces the math-first contract at commit time; the same check
runs in CI for PR-scope coverage.
entry: scripts/math-first/require_math_evidence.py
language: python
files: '^(0-Core-Formalism/lean/Semantics/|6-Documentation/docs/distilled/|shared-data/data/stack_solidification/).*$'
pass_filenames: true
require_serial: true