compare & diff
Synopsis
Section titled “Synopsis”canontra compare <FILE1> <FILE2> [--diff] [--json]canontra diff <FILE1> <FILE2> [--json]Description
Section titled “Description”compare: Computes all 9 fingerprints (F0throughF4) for both files, marks each tier asIdenticalorDifferent, and exits0when compositeF4matches or1whenF4differs.diff: Parses both files into normalized IR and lists exact changes in declarations, imports, AST structure, call graph, control flow (CFG), and data flow (DFG). Passing--difftocompareprints the same detailed breakdown.
diff also accepts - to read one side from standard input.
| Flag | Short | Applies To | Default | Description |
|---|---|---|---|---|
--diff |
- |
compare |
false |
Show detailed function and graph changes alongside tier status |
--json |
- |
compare, diff |
false |
Print ComparisonResult or DiffResult as JSON |
Output Schema & Exit Codes
Section titled “Output Schema & Exit Codes”compare exits 0 when crComposite == Identical, and 1 when crComposite == Different. diff exits 0 only when crComposite == Identical and all six change lists (declaration, dependency, structural, call_graph, cfg, dfg) are empty; otherwise it exits 1.
{ "target_a": "original.py", "target_b": "modified.py", "source": "Different", "structural": "Identical", "declaration": "Identical", "dependency": "Identical", "call_graph": "Identical", "control_flow": "Identical", "data_flow": "Identical", "type_contract": "Identical", "composite": "Identical"}- Exit
0: Semantically identical. - Exit
1: Semantic difference found. - Exit
3: Parse error in either file. - Exit
4: Missing file or path outside the project root.
Examples
Section titled “Examples”# CI gate: fails only when program behavior changedcanontra compare v1/billing.py v2/billing.py
# Inspect exact functions and graphs that changedcanontra diff v1/billing.py v2/billing.py --json