Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2.7 KiB
repo_contract
Shared gate: every repo tells an agent how to run and test it, so nobody has to
explore. Enforced like the other shared gates (real gate in ~/src/utils, a
thin shim per repo, pre-commit + CI).
The contract
CLAUDE.md (or AGENTS.md that CLAUDE.md symlinks to) has a ## Commands
section with one line per key, exactly - <key>: \``:
## Commands
- run: `<command>` | n/a: library
- test: `<full suite>`
- test-changed: `scripts/test_changed.sh`
- lint: `<command>`
- coverage: `<command writing a report>`
- coverage-gaps: `coverage-gaps <report>`
Rules (all machine-checked):
- All six keys present, once each. A value is a backticked command or
n/a: <reason>/n/a (<reason>). A baren/afails: n/a carries a reason. test-changedinvokes an existing, executablescripts/test_changed.sh-style script that runs only tests related to files changed vs HEAD, falls back to the full suite when it cannot map, and prints failures plus a one-line summary only.coverage-gapsruns the shared listercoverage-gaps <report>(~/src/utils/coverage_gaps).test,test-changed,lint,coverageare quiet: no-v/--verbose/ expanded reporter, in the command or in the script's runner lines.- No placeholders (
<FILL IN>,TODO,...). - If
testis n/a, thentest-changed,coverage,coverage-gapsare n/a too, and the repo must contain no tests (bounded scan).
Use
python3 ~/src/utils/repo_contract/check.py --repo <path> # 0 pass / 1 violations / 2 unreadable
python3 ~/src/utils/repo_contract/bootstrap.py --repo <path> # print proposal
python3 ~/src/utils/repo_contract/bootstrap.py --repo <path> --write
python3 ~/src/utils/repo_contract/sweep.py # ~/data/claude-scratch/repo-contract/SWEEP.md
Bootstrap never overwrites: it appends the section (or inserts missing lines at
the end of an existing ## Commands), creates CLAUDE.md -> AGENTS.md when
only AGENTS.md exists, and writes scripts/test_changed.sh only if absent.
Sources, in priority order: existing CLAUDE.md, scripts/<key>.sh, Makefile,
package.json (node only), CI workflows, stack defaults. Anything it cannot infer
is written as <FILL IN>, which the gate rejects until a human fills it.
Adding the gate to a repo
- Copy
templates/check_repo_contract.shim.shtoscripts/check_repo_contract.sh(never copyscripts/check_repo_contract.shfrom this repo). - Add
templates/pre-commit-snippet.yamlto.pre-commit-config.yaml. - Copy
templates/repo-contract.ymlto.github/workflows/.
Tests
PYTHONPATH=. python -m pytest repo_contract/tests -q --cov=repo_contract --cov-branch --cov-fail-under=100