AI Agent Harness Checkpointing
AI coding agents often reformat untouched lines, rename local variables, or accidentally change public function signatures during a refactor. Wrapping edit turns with canontra snap lets harnesses verify what actually changed and enforce strict API boundaries without touching Git history.
1. Full Agent Loop Workflow
Section titled “1. Full Agent Loop Workflow”# 1. Create .canontra/snaps/ + .canontra/.gitignore and record baseline snap_0canontra snap init --json
# 2. Agent applies edits, then checkpoints the turn (--skip-noop skips formatting-only turns)canontra snap mark --label "refactor-helper" --agent "coding-agent" --skip-noop --json
# 3. Verify public signatures (F2), dependencies (F3), and types (F_T) did not breakcanontra snap guard --against snap_0 --forbid F2,F3,F_T --allow-paths "tests/**" --json
# 4. If guard exits 1, inspect compact semantic diff or preview/run rollbackcanontra snap diff snap_0 HEAD --compact --jsoncanontra snap rewind snap_0 --dry-run --jsoncanontra snap rewind snap_0 --json
# 5. View checkpoint log or clean up old snapshotscanontra snap log -n 10 --jsoncanontra snap gc --keep-last 10 --json2. Claude Code PostToolUse Hook Configuration
Section titled “2. Claude Code PostToolUse Hook Configuration”Run canontra snap guard automatically after Edit or Write tool calls in .claude/settings.json:
{ "hooks": { "PostToolUse": [ { "matcher": "Edit|Write", "hooks": [ { "type": "command", "command": "canontra snap guard --against snap_0 --forbid F2,F3,F_T --allow-paths \"tests/**\" --json" } ] } ] }}3. Reading Compact Diffs (snap diff --compact --json)
Section titled “3. Reading Compact Diffs (snap diff --compact --json)”Instead of passing noisy line-by-line Git diffs back into an LLM context window, snap diff --compact --json returns the turn classification (no_change, semantic_noop, internal_logic, or contract_change), mutated tiers, symbol_changes, and CSR recommended_tests:
level1_trivia_count: Files with only formatting, comment, or local variable rename edits.level2_logic: Files where internal logic changed (F1,F_CF,F_DF) while public APIs stayed unchanged.level3_contract: Files where public declarations (F2), dependencies (F3), or structural types (F_T) changed.
4. Measured Harness Overhead (v0.4.0)
Section titled “4. Measured Harness Overhead (v0.4.0)”- In-memory
diffFileBundles:733.1 ns(RQ19) - 1,000-file delta check (1 dirty file):
1.73 ms(RQ19) - Warm CLI
canontra snap mark --skip-noop:143.61 msto477.16 msacross small, medium, and large repos (chalkthroughripgrep), and3,978.55 mson 994-fileprometheus.