snap (Alpha)
Synopsis
Section titled “Synopsis”canontra snap init [-d|--dir DIR] [--json]canontra snap mark [-l|--label LABEL] [-a|--agent AGENT] [--skip-noop] [-d|--dir DIR] [--json]canontra snap diff [FROM] [TO] [--compact] [-d|--dir DIR] [--json]canontra snap guard [--against SNAP_ID] --forbid <TIERS> [--allow-paths GLOB]... [-d|--dir DIR] [--json]canontra snap rewind <SNAP_ID> [-f|--file PATH | FILES...] [--dry-run] [-d|--dir DIR] [--json]canontra snap log [-n|--limit N] [-d|--dir DIR] [--json]canontra snap gc [--keep-last N] [-d|--dir DIR] [--json]Description
Section titled “Description”When AI coding tools edit code across several turns, creating temporary Git commits pollutes repository history. canontra snap records lightweight semantic checkpoints inside .canontra/snaps/ without touching .git/index or running a background service.
On-Disk Storage Layout (.canontra/snaps/)
Section titled “On-Disk Storage Layout (.canontra/snaps/)”canontra snap init automatically creates .canontra/.gitignore (*) so stored blobs and manifests never show up as untracked files in Git:
.canontra/├── .gitignore # Auto-created ("*")├── cache.bin # Shared CNTR\x07 incremental slab + FileGraphSummary cache└── snaps/ ├── HEAD # Active snap_id (atomic swap on write) ├── ledger.jsonl # Append-only chronological turn metadata log ├── objects/ │ └── <aa>/ │ └── <sha256> # Deduplicated raw source blobs keyed by F0 SHA-256 └── manifests/ ├── snap_0.json # Immutable initial baseline snapshot └── snap_<ts>_<hash>.jsonTurn Classifications & Severity Levels
Section titled “Turn Classifications & Severity Levels”| Classification | Condition | File Severity Tier |
|---|---|---|
no_change |
Identical F0 raw bytes across all tracked files |
None |
semantic_noop |
F0 changed, while F1..F4 and F_T stayed identical (formatting, comments, docstrings, local variable renames) |
Level1_Trivia |
internal_logic |
Function body behavior (F1, F_CG, F_CF, F_DF, F4) changed without altering public APIs or imports |
Level2_Logic |
contract_change |
Files added/deleted, or public declarations (F2), dependencies (F3), or structural types (F_T) changed |
Level3_Contract |
All subcommands accept -d, --dir DIR (repository root, default .) and --json before or after the subcommand name.
| Flag | Short | Applies To | Default | Description |
|---|---|---|---|---|
--label <LABEL> |
-l |
mark |
- |
Human-readable label for the checkpoint |
--agent <AGENT> |
-a |
mark |
- |
Name of the coding agent or harness |
--skip-noop |
- |
mark |
false |
Skip advancing HEAD on no_change or semantic_noop turns |
[FROM] [TO] |
- |
diff |
HEAD, WORKTREE |
Snapshot IDs or HEAD/WORKTREE endpoints to compare |
--compact |
- |
diff |
false |
Output compact symbol changes, severity counts, and test slices |
--against <SNAP_ID> |
- |
guard |
HEAD |
Baseline snapshot ID to check the current workspace against |
--forbid <TIERS> |
- |
guard |
required | Comma-separated tiers (F0, F1, F2, F3, F_CG/FCG, F_CF/FCF, F_DF/FDF, F_T/FT, F4) |
--allow-paths <GLOB> |
- |
guard |
- |
Repeatable glob exemption (e.g. "tests/**") |
--file <PATH> |
-f |
rewind |
all tracked | Restore only one or more specific relative file paths |
--dry-run |
- |
rewind |
false |
Run path and SHA-256 checks and print planned edits without touching disk |
--limit <N> |
-n |
log |
20 |
Maximum number of recent turns to show |
--keep-last <N> |
- |
gc |
50 |
Keep the last N manifests (always preserving snap_0 and HEAD) and delete unreferenced blobs |
Output Schema, Rollback Safety & Exit Codes
Section titled “Output Schema, Rollback Safety & Exit Codes”canontra snap guard --against snap_0 --forbid F2,F3,F_T --json (Exit Code 1)
Section titled “canontra snap guard --against snap_0 --forbid F2,F3,F_T --json (Exit Code 1)”{ "against_snap_id": "snap_0", "allow_paths": [], "allowed_skipped": [], "elapsed_ms": 5.3398, "forbidden_tiers": ["F2", "F3", "F_T"], "passed": false, "schema_version": "0.1-alpha", "stability": "alpha", "violations": [ { "mutated_tiers": ["F0", "F1", "F2", "F_CF", "F_DF", "F4"], "path": "app.py", "severity": "Level3_Contract", "status": "modified", "violated_tiers": ["F2"] } ]}canontra snap diff snap_0 HEAD --compact --json
Section titled “canontra snap diff snap_0 HEAD --compact --json”{ "classification": "contract_change", "compact": true, "elapsed_ms": 11.4, "from_snap": "snap_0", "level1_trivia_count": 0, "level2_logic": [], "level3_contract": [ { "invariant_tiers": ["F3", "F_CG", "F_T"], "mutated_tiers": ["F0", "F1", "F2", "F_CF", "F_DF", "F4"], "path": "app.py", "severity": "Level3_Contract", "status": "modified" } ], "recommended_tests": [], "schema_version": "0.1-alpha", "stability": "alpha", "symbol_changes": [ { "action": "signature_modified", "detail": "Function signature altered", "file": "app.py", "symbol": "Function: compute" } ], "to_snap": "snap_20261130T181733297Z_3809be13"}Preflight Rollback Safety (snap rewind)
Section titled “Preflight Rollback Safety (snap rewind)”- Snapshot ID and Path Containment:
isSafeSnapIdrejects traversal tokens (..,/,\) with Exit Code4; every file path passesisSafeRelativeFilePathandcanonicalizeSafePath. - Preflight SHA-256 Blob Verification:
readVerifiedBlobverifies every stored object against its manifestf0hash before any workspace file is modified or deleted. - Untracked File Preservation and Atomic Swap: Only files tracked in
HEADand absent from the target snapshot are deleted; restored files write to.tmp.<pid>and swap viaatomicSwapWithRetry_.
Exit Codes
Section titled “Exit Codes”0: Success, orsnap guardpassed with zero violations.1: Policy violation found bysnap guard.2: Invalid CLI flags or missing required option.4: Unsafe snapshot ID, path traversal, missing snapshot/blob, or SHA-256 mismatch.
Measured v0.4.0 Performance (RQ19 & 15-Repo Corpus)
Section titled “Measured v0.4.0 Performance (RQ19 & 15-Repo Corpus)”diffFileBundles:733.1 ns|computeFileDeltas(1,000 files, 1 dirty):1.73 ms|classifySnapDeltas:19.9 ns|parseGuardTiers:733.1 ns|matchesGlob:5.9 us.- End-to-end warm CLI
canontra snap mark --skip-noop:143.61 ms(chalk) to477.16 ms(ripgrep),1,352.99 ms(deno_core),3,978.55 ms(prometheus),5,022.56 ms(hugo).
Examples
Section titled “Examples”canontra snap init --jsoncanontra snap mark --label "refactor-helper" --agent "coding-agent" --skip-noop --jsoncanontra snap guard --against snap_0 --forbid F2,F3,F_T --allow-paths "tests/**" --jsoncanontra snap diff snap_0 HEAD --compact --jsoncanontra snap rewind snap_0 --dry-run --jsoncanontra snap log -n 10 --jsoncanontra snap gc --keep-last 10 --json