Blind, two-layer structural homology and stylometry for codebases, built on GitGalaxy scans.
structural-fingerprint-scanner (sfs) compares repositories without reading function names, comments, or file paths. It pairs two complementary layers:
- Layer 1 — Macro-Topology (FGW + Seed-and-Extend): Fused Gromov–Wasserstein (
FGW) optimal transport over function geometry + hop-distance call graphs, followed by 3-hop call-graph extension. Recovers vertical source ports, cross-language translations, and horizontally borrowed modules. - Layer 2 — Micro-Idiomatic Texture (32-Keyword-Family Lattice +
delta_lang): Distributional and per-matched-pair comparison across 32 structural signal families (branching, bitwise ops, pointer/state flux, encapsulation, I/O, etc.), with additive language-translation centering (LanguageDeltaModel) and linear style attribution (StyleAxis).
Real scans, real output: linuxdoom (C, 777 functions) against gore, its Go port (996 functions). Names are hidden until the last step.
- Read: each function becomes a shape (size, arguments, 32 keyword families) at a place in its call graph.
- Match: FGW optimal transport pairs functions whose shape and call-graph position agree. 439 pairs pick each other; only the strongest 15% are kept as anchors (66).
- Extend: the C → Go offset is measured on the anchors. Then, for 3 hops, a caller or callee of a matched function is paired with its partner's unclaimed neighbour that is closest in shape. 66 → 276 → 482 → 598 matched (77%).
- Fingerprint check (evidence quality): extend finds partners even in unrelated code, so every pair's keyword fingerprint and shape are checked against decoys. A pair passes with sufficient evidence or is held back. gore: 121 of 598 pairs pass. rust-doom, a from-scratch rewrite: 0 of 123. Random pairing: 0 of 777 right.
- Answer key: names, never used to match, grade it. Without the check, 364 of 598 matches are the same function. With it, 108 of 121 (89%) are; the zoom-out shows all 777 functions with their verdict.
Details, caveats and how to regenerate: docs/media/README.md ·
MP4
It also provides cohort fingerprinting, target–decoy structural twins, descent & profile trees, subsystem subway maps, git-history drift timelines, and scan-quality verification (ctags / tree-sitter + LLM triage + PII-stripped GitGalaxy Epic issue reporting).
Featured Case Study — DOOM's DNA: What Survives Translation, Porting, and Rewriting: Validated blind across 44+ DOOM ports (~20 languages), 9 controls, and 5 held-out repos. Explore the Interactive 16-Track DNA Gene Map or the Interactive Function & Tree Explorer on GitHub Pages.
# Core (Python 3.10+, numpy, scipy — works on pre-scanned *_galaxy_master.db or .sfp.json files)
pip install .
# With GitGalaxy auto-scanning for raw source repositories
pip install '.[scan]'
# With Tree-sitter quality verification (also auto-uses Universal Ctags if on PATH)
pip install '.[verify]'
# Development / tests
pip install '.[test]'
sfs --versionNote:
pip install '.[scan]'requiresgitgalaxyto be reachable (via PyPI orpip install git+https://github.com/squid-protocol/gitgalaxy.git).
Compare two pre-scanned DBs or raw source repositories (with [scan] installed):
sfs lattice-compare repo_a/ repo_b/ --lens portable --json
sfs lattice-compare repo_a/ repo_b/ --lens portable --matches --verify --issue-out epic.mdEvery matched pair also gets an evidence verdict (sufficient in --matches output, a count in the summary). The
threshold is calibrated on decoys at a 2% false-pass rate (--evidence-fdr, 0 to skip). The rate is against random
functions of the same kind; near-identical siblings are not covered by it
(see docs/media/README.md).
Guard against under-tuned language regexes or slicers before trusting downstream numbers:
# Check internal yield + optional ctags / tree-sitter recall
sfs quality repo_or_scan --source ./repo --verify
# Emit a disagreement cell list + LLM validation prompt (separates real gaps from parser noise)
sfs quality repo_or_scan --source ./repo --verify --triage-out triage.md
# Emit a copy-pasteable GitGalaxy Epic issue (standard or PII-stripped paranoid mode)
sfs quality repo_or_scan --source ./repo --verify --epic-issue --privacy paranoid --issue-out epic.md# Fingerprint scans (writes <name>.sfp.json + <name>.sfp.npz)
sfs fingerprint scans/ -o fingerprints/
# Compare a cohort: distances, twins, descent & profile trees, report.html
sfs compare fingerprints/ -o report/ --declared-lineage lineage.csv
sfs compare fingerprints/ -o report-portable/ --lens portable --no-twins
# Function-level structural twins (CSV)
sfs twins fingerprints/A.sfp.json fingerprints/B.sfp.json -o twins/
# Subsystem subway maps & cross-check
sfs subway fingerprints/ -o subway/ --reference A --taxonomy subsystems.json [--declared-lineage lineage.csv]
# Git-history drift timeline
sfs timeline --repo A=path/to/A --repo B=path/to/B --reference fingerprints/R.sfp.json \
--engine /path/to/gitgalaxy --python /path/to/engine-venv/bin/python --every 1y -o timeline/
# Explain what separates two repositories & inspect the 37D reference frame
sfs explain fingerprints/A.sfp.json fingerprints/B.sfp.json
sfs spec [--lens portable] [--json]A persistent ID for every function across snapshots of one repository, so renames and moves are not counted as a death plus a birth. Structure proposes a link; body text or comments verify it; each link records the stage that made it. On four repositories, path-and-name identity overcounted deaths by 40–78%; lineage identity recovers 70–96% of unambiguous renames and 97–100% of moves (discovery measurements, not a registered result).
from pathlib import Path
from structural_fingerprint.ledger import Snapshot, build_ledger, classify_unlinked
snaps = [Snapshot(Path("scans/q1.db"), "<commit sha>", "2024Q1"), ...] # oldest first, one scan per commit
led = build_ledger(Path("path/to/git/checkout"), snaps) # reads git objects only
led.ids[s] # lineage id of every function in snapshot s
led.links[s] # old index -> Link(new, stage, score, ambiguous, body, doc)
led.span() # lineage id -> (first, last) snapshot
dead, born = classify_unlinked(led, s) # cause of each unlinked death/birth (split, merged, file_removed, ...)Needs start_line and docstring in the scan database for text verification; without them only the certain
stages (identity, same name in the git-mapped file) link.
The two-layer pipeline has been validated across three benchmark programs (all blind to identifiers and file paths):
Article: DOOM's DNA (Text Edition) · Interactive: 16-Track DNA Gene Map · Function & Tree Explorer · Study repo: squid-protocol/doom-dna
Click the preview above to open the Interactive 16-Track DNA Gene Map across all 49 measured targets (C01–C16 call-graph communities discovered directly from linuxdoom, zero filename rules). Above: doom-wasm exposes multi-donor horizontal borrowing (42.4% linuxdoom core in red, 12.3% chocolate-doom in blue, 2.0% doomgeneric in purple, 1.7% woof in cyan), while gore recovers 47.1% of Go LOC (75.9% 1-to-1 functions) from C without reading a single identifier.
- Within-language structural twins (
sfs twins): Achieves 93% precision (65% recall) across27,778function-by-port pairs against source-text diffs (Spearmanρ = 0.83–0.84), while unrelated C controls (lua,quake,quake2) sit at0.0%–0.6%. - Clean port vs. scratch/unrelated separation (44+ ports, 9 controls, 66 cross-pairs):
- Unrelated controls (
lua0.0%,quake/quake20.6%, Gogoom3d/bubbletea, Rustmacroquad, C raycasters, business COBOLcarddemo-cobol-ctrl) and from-scratch reimplementations (room4doom,rust-doom,helionall0.0%) sit at the noise floor, with 0–1 accidental name hits across 66 cross-pair permutations. - Layout-stripped and translated ports are recovered 1-to-1 by unsupervised Seed-and-Extend (
compositionmode + FGW +deltaoffset + 3-hop extension):mood(95.3%,687/721), single-headerpuredoom(89.0%,590/663),doomgeneric(84.9%,547/644), flat-directory Go portgore(75.9%,426/561, despite0.2%filename-taxonomy match), andchocolate-doom(65.0%,433/666).
- Unrelated controls (
- Horizontal gene transfer: Subtracting
linuxdoomisolates Chocolate Doom'stextscreenUI library insideodamex(178/212=84.0%Tier-1),eternity(210/276=76.1%Tier-1),doom-wasm(220/271=81.2%Tier-1), and directly betweeneternity ↔ odamex(190/228=83.3%Tier-1) across distinct DOOM branches. - Architectural clustering vs. syntax: Three COBOL raycasters cluster at
FGW 0.670–0.706vs. same-size enterprise business COBOL (carddemo-cobol-ctrl) at0.748–0.775. - Preregistered
DOOM-E5held-out predictions: Confirmedcydoomgeneric(FGW=0.313,100.0%=156/156Tier-1 vs.doomgeneric),DOOM-style-Game(0.0%), anddoome(0.0%); falsifications oniron-doom(0.0%,0/147) anddoomarkable(0.0%) pinpointed the paradigm boundary (below).
- Same-model runs resemble source forks (56
confirmruns): Independent Sonnet runs (FGW = 0.154–0.489,78.7%Tier-1 /68.1%SE) match or exceed true C DOOM ports even with zero shared codebase ancestry. - 32-keyword-family lattice (
-kw_JSD): Achieves0.944ROC AUC for same-model vs. different-model attribution within(task, lang), outperforming FGW Seed-and-Extend (0.874AUC) and 14-archetype JSD (0.655AUC). - Additive language-translation centering (
delta_lang): Pure 32D translation matches or beats 32×32 Orthogonal Procrustes (0.698vs.0.645on held-outchess), and a language-centeredClaude Code vs. Codex CLIvector transfers zero-shot to 16 held-outexplore/scans at0.730ROC AUC (6/7within-(task, lang)pairs orderedcc > codex).
- Using 24-language centroids from
keyword-rosetta(language-cruciblev4.3.1 DB), predicting a port's 32-keyword-family profile aslinuxdoom + (rosetta[lang] - rosetta["c"])reduces JSD across all 5 tested cross-language DOOM translations:mochadoom(java):0.358 → 0.193(-0.165)doomf77(fortran):0.353 → 0.253(-0.100)managed-doom(csharp):0.332 → 0.273(-0.059)gore(go):0.329 → 0.273(-0.056)dartdoom(dart):0.350 → 0.302(-0.048)
- Conversely, general-purpose Rosetta centroids do not improve subtle cross-language model attribution on
chess/sat(0.660 → 0.601), showing that coarse translation shifts transfer universally while fine model-style residuals need domain-matcheddelta_lang.
- Paradigm shifts:
C → Go(gore,75.9%) preserves imperative call-graph DNA, whereasC → Bevy ECS(iron-doom,0.0%) replaces the call graph with decoupled ECS systems and drops to the from-scratch floor. - Externalized wrappers: Thin platform wrappers around external crates (
doomarkable, 41 functions) lack the vendored engine call graph (0.0%). - Uncentered cross-domain attribution: Comparing
kw_JSDdirectly across unrelated domains (e.g.raycastervs.chess/satCOBOL) is confounded by task structure unless language/domain offsets are centered.
Controlled ablations against linuxdoom (doomgeneric, gore, rust-doom) show that Layer 1 and Layer 2 fail in opposite ways:
| Failure Mode | Layer 1 (FGW Seed-and-Extend) |
Layer 2 (32-Keyword Lattice) |
|---|---|---|
| Missing functions | Same-lang C holds >80% T1 through 50% loss (cliff at 75% drop); cross-lang Go drops below 50% T1 at 50% loss |
Resilient (kw_JSD flat 0.101–0.109 up to 90% drop) |
| Missing call edges | Same-lang C holds >70% T1 through 75% loss; cross-lang Go drops below 50% T1 at 50% loss |
Resilient |
| Missing keyword signals | Resilient (98.7% C / 91.5% Go T1 even with 90% signal columns zeroed) |
Sensitive (doomgeneric kw_JSD jumps 0.104 → 0.392 at 25% loss and 0.748 at 50% loss) |
This asymmetry is why sfs quality --verify gates on both parser function recall (ctags / tree-sitter, protecting Layer 1) and zero-signal rate (protecting Layer 2).
| Reviewer Lens | What Stands Out | Caveat / Boundary Noted |
|---|---|---|
| Clean-Room & IP Forensics | 93% twin precision on stripped code (puredoom 89.0%, gore 75.9%) and exact isolation of horizontally vendored modules (textscreen in eternity/odamex/doom-wasm) while keeping 0–1 false hits across 66 non-DOOM cross-pairs and 9 controls. |
Structural homology flags candidate ancestry; as agent-habits proves (0.154–0.489 FGW across independent Sonnet runs), shared model/idiom habits can mimic fork-level topology without copying. |
| Compiler & Static Analysis | True two-layer orthogonality: ablating 50% of functions/edges drops Layer 1 below 50% on Go while Layer 2 kw_JSD stays flat (0.101–0.109 up to 90% drop); zeroing keyword signals breaks Layer 2 (0.104 → 0.748) while Layer 1 holds (98.7% C / 91.5% Go). |
Tiny-function OOP splitting (34% of mochadoom and 43% of kocoa-doom <= 3 LOC) distorts unsmoothed hits/loc, requiring composition mode and sfs quality --verify. |
| Legacy Modernization & Architecture | Imperative cross-language translations (C → Go gore, +0.50 cross-subsystem wiring) preserve call-graph DNA, and COBOL raycasters separate cleanly from business COBOL (FGW 0.670–0.706 vs. 0.748–0.775). |
Paradigm shifts (C → Bevy ECS in iron-doom, 0.0%) and thin external-crate wrappers (doomarkable, 0.0%) erase the call-graph signature even when ported from a known ancestor. |
| Empirical Methodology / Skeptic | Preregistered held-out predictions (DOOM-E5), explicit negative controls (9 controls + 66 cross-pairs), and documented non-separators (raw graph-shape distance 0.30–3.25 vs. 1.04–2.30 fails without nulls). |
Uncentered kw_JSD confounds task domain with author style unless offset by delta_lang, and blind wiring must be evaluated by placement agreement rather than imposed post-hoc. |
action.yml provides a composite GitHub Action that installs structural-fingerprint-scanner[scan], runs sfs lattice-compare on two repositories or scan directories, and emits fgw-cost, se-coverage, kw-jsd, and json outputs plus a step summary:
- uses: squid-protocol/structural-fingerprint-scanner@v0.1.0
with:
repo-a: ./baseline
repo-b: ./candidate
lens: portable- docs/METHOD.md specifies formulas, calibration, and limits; examples/doom/ contains the 44-port DOOM reference dataset.
- The vendored reference model (
src/structural_fingerprint/data/) records the GitGalaxy commit (spec_hash) used to normalize the 37D feature frame.
pytest
# Engine parity on real scans:
SFS_REAL_SCANS=/path/to/scans pytestLicensed under the PolyForm Noncommercial License 1.0.0.

