feat: motif-basis fingerprint v2 — triad census, weighted TV drift, quotient k=1 (Part B)#144
Conversation
9 TDD tasks: triad census (no new deps), census vectors on PatternFingerprint, ideal/layers/triad_weights config, v2 TV scoring with empty-layer exclusion, quotient builder, patterns.yaml v2.1 with re-baselined tolerances, observe-only quotient self-test, CLI TV columns, spec §3.3 example amendment. Baseline measured live 2026-06-10 (networkx cross-check); all design deviations from spec documented with measurement. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… §3.2) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…spec §3.3-3.4) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…erm (spec §3.3) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ift, explicit None guards
Adds build_quotient() that collapses each domain to one MODULE node and aggregates cross-domain IMPORTS/CALLS edges by (src, dst, type) with weight = count. Relaxes Edge.weight upper bound (le=1.0 → unbounded) to allow aggregated counts > 1.0 in quotient edges. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…match, weight field description
…ces, project_level (spec §3.3-3.4) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ect-level loaders
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ot layering Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request implements the Motif-Basis Fingerprint v2 (Part B) design, replacing heuristic topological constraint scoring with a 13-triad census fingerprint and weighted total-variation distance to ideal points. It introduces a new triads module for census and TV distance calculations, adds census vectors to PatternFingerprint, implements a domain-quotient graph builder, and updates the DriftScorer with a v2 scoring path. The CLI is also updated to display TV columns and observe-only quotient drift. The reviewer feedback focuses on enhancing robustness by defensively clipping calculated ratio-based values (such as TV distance and drift scores) to the [0.0, 1.0] range, and validating that configuration blocks are dictionaries before parsing them to prevent runtime errors.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…s, census complexity - shared _validate_mapping helper; ideal layers / profile layers / triad_weights now fail loud (TypeError) on non-mapping YAML blocks (gemini; same precedent as Part A's _params_mapping) - layers and triad_weights validated non-negative at load time — addresses the clip-to-[0,1] concern at the config layer instead of silently mangling computed TV/drift outputs - triad_census split into _adjacency + _connected_triples (sonar cognitive complexity 21 -> below threshold) - float equality in tests replaced with pytest.approx (sonar reliability) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
/gemini review |
|
/guardian review |
|
LGTM — no defects found in this diff. I have performed a high-precision, line-by-line review of the Pull Request diff. The implementation is of exceptional quality and fully complies with all engineering standards, type discipline, and the project ontology. Verified Correctness & Components Audited:
|
There was a problem hiding this comment.
Code Review
This pull request implements the Motif-Basis Fingerprint v2 (Part B) architecture, replacing heuristic topological constraint scoring with a 13-triad census fingerprint and weighted total-variation distance to ideal points. It introduces a new triads.py module for triad census and TV distance calculations, updates PatternFingerprint with census vectors, and implements a v2 scoring path in DriftScorer. Additionally, it adds a quotient.py module to construct domain-quotient graphs, updates patterns.yaml to v2.1, and enhances the CLI to display TV columns and observe-only quotient drift. Review feedback suggests defensively clipping the calculated drift score to the [0.0, 1.0] range in drift.py and refactoring the manual edge aggregation loop in quotient.py to use a declarative Counter comprehension.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…ehension Review round 2 (gemini): declarative comprehension matches the style of the rest of build_quotient; behavior unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|



Implements Part B of the pattern-alphabet / motif-basis spec (
docs/specs/2026-06-09-pattern-alphabet-motif-basis-design.md§3.2–3.4, merged in #142). Plan:docs/specs/plans/2026-06-10-motif-basis-part-b.md.What's new
13-triad census (
query/triads.py)normalized_census(raw ratios, no null-model z-scores per spec §3.2) and weighted total-variation distancetv_distancewith per-triad contribution decomposition.Fingerprint v2 (
query/fingerprint.py)PatternFingerprintgainst_imports/t_callscensus vectors, computed per-layer over domain-internal edges.FingerprintExtractor.from_graph()preload path (used by quotient scoring) with defensive copies.Drift scoring v2 (
query/drift.py)drift = Σ eff_k·tv_k / Σ eff_kover layers {imports, calls, gates}; CALLS discounted byclip(1 − unresolved_ratio); empty layers are excluded and renormalized — no data ≠ maximally drifted.ideal:and the profile declareslayers:— legacy configs hit the untouched v1 path.drift_scoreis now uniformly unrounded on both paths.Quotient k=1 (
query/quotient.py)quotient.<name>MODULE nodes; cross-domain IMPORTS/CALLS aggregate withweight = count(thele=1.0bound onEdge.weightwas removed — verified no consumer reads the magnitude). Longest-prefix domain matching, fully deterministic edge ordering.enforce: false) for the burn-in milestone: reported, never flips the exit code.patterns.yaml v2.1 + CLI
layers:weights; all 5 templates gainideal:census points; per-domain tolerances re-baselined against measured v2 drifts (annotated# measured);project_level:bindingcgis-project → pipeline_stage, observe-only.cgis drifttable gains TV imp / TV calls columns; quotient line + JSON entries carry theenforceflag.Validation (plan Task 7)
Every hand-computed v2 prediction matched measurement within 0.003:
extraction 0.262/tol 0.30 · resolution 0.350/0.40 · pipeline 0.196/0.25 · storage 0.166/0.20 · query 0.141/0.18 · components 0.167/0.20 · layout 0.455/0.50 · hygiene-only 0.00. Quotient measures 0.700 vs
pipeline_stage(exact arithmetic: orchestrator reality, expected — rebind decision deferred to post-burn-in).Out of scope (deferred by design)
Quotient rebind to orchestrator, TS quotient binding, quotient
unresolved_ratioplumbing, removing v1 counting fields, Part C.Test plan
cgis ingest src && cgis drift— exit 0, quotient observe-only line rendered🤖 Generated with Claude Code