Canontra
Canontra is a deterministic code fingerprinting and dependency analysis tool written in pure Haskell. Instead of hashing raw file text (which changes whenever someone adds a comment or reformats a line), Canontra produces 9 separate SHA-256 fingerprints for Python, JavaScript/TypeScript, Go, and Rust files. Build caches, CI runners, and AI coding tools can tell immediately whether an edit is harmless formatting or a real behavior change.
Install
Section titled “Install”cabal update && cabal install canontracurl -fsSL https://raw.githubusercontent.com/symtrace/canontra/main/install.sh | bashirm https://raw.githubusercontent.com/symtrace/canontra/main/install.ps1 | iexgit clone https://github.com/symtrace/canontra.git && cd canontra && stack build --fast && stack install30-Second Proof: Formatting Churn vs. Logic Changes
Section titled “30-Second Proof: Formatting Churn vs. Logic Changes”Suppose a developer moves a helper function, adds a docstring, fixes spacing, and renames a local variable. Raw file hashes (F0) change completely, but Canontra sees that the program logic (F1 through F4) is unchanged:
# Calculate customer discountdef calculate_discount(price: float, discount: float = 0.1) -> float: net = price * (1.0 - discount) return net
def get_service_version() -> str: return "1.0.0"def get_service_version() -> str: return "1.0.0"
def calculate_discount( price: float, discount: float = 0.1 ) -> float: """Calculates customer discount for orders.""" discounted_amount = price * (1.0 - discount) return discounted_amountcanontra compare original.py modified.py================================================================================ CANONTRA SEMANTIC COMPARISON================================================================================ Target A: original.py Target B: modified.py................................................................................ Source Text (F0): DIFFERENT (raw formatting, docstrings, or locals modified) Structural AST (F1): IDENTICAL (executable logic is unchanged) Declarations (F2): IDENTICAL (public API signatures are unchanged) Dependencies (F3): IDENTICAL (imported packages are unchanged) Type Contract (F_T): IDENTICAL (interface contracts are unchanged) Composite (F4): IDENTICAL (overall semantic identity preserved)================================================================================ Verdict: SEMANTICALLY IDENTICAL (Exit Code: 0)================================================================================Now change * to - inside calculate_discount (buggy.py). Canontra flags F1 and F4 as DIFFERENT and returns exit code 1, while F2 confirms the public function signature did not change:
canontra compare original.py buggy.py================================================================================ CANONTRA SEMANTIC COMPARISON================================================================================ Structural AST (F1): DIFFERENT (arithmetic operator mutated) Declarations (F2): IDENTICAL (public signature unchanged) Composite (F4): DIFFERENT================================================================================ Verdict: SEMANTICALLY DIVERGENT (Exit Code: 1)================================================================================Reference Map
Section titled “Reference Map”| Area | What You Will Find | Entry Point |
|---|---|---|
| Fingerprint Tiers | Plain and formal guide to F0..F4 and repo-wide F_R, F_WCG, F_WDF, F_W4 |
9+4 Fingerprint Tiers |
| CLI Reference | Every command, flag, JSON output schema, and exit code (0 to 4) |
Overview & Exit Codes |
| PR Batch Impact | Minimal test selection across Pull Requests (canontra impact --pr-base) |
impact & slice |
| 15-Repo Benchmarks | Live v0.4.0 timings across 3,182 files and 1,026,521 LOC (4.07× cold / 9.07× warm vs. v0.3.0, 9.7× to 205.1× vs. CodeQL) |
Empirical Results |