Sovereign OO/DRY Consolidation — Gate-Base Helper Library

Mechanized, behaviorally-verified extraction of copy-pasted gate helpers into one shared sovereign base — with the evidence standard, and the design law it produced.

nx_gate_base.nxrule-15 DRYbyte-identical proofbehavioral verification2026-07-21

The debt

nx_funcmine measured ~9,495 duplicate function bodies across the _hdl_build tree (~23% of the codebase). Corrected measurement shows it is dominated by one dominant byte-identical variant per helper — the copy-pasted gate test-harness family (gw stdout, g_slen strlen, gn int-print, grow PASS/FAIL emit).

What was consolidated — verified

HelperCopies → baseProofStatus
gw (stdout write)399 → 1exact-match remove-local (nothing to shadow) + build-verify + behavioral spot-checkCONSOLIDATED
g_slen (strlen)33 → 1single logic-variant ⇒ canonical behaviorally identical to every copyCONSOLIDATED
gn (int-print)432 → 1behavioral-verify-every-importer: each adopter proven output-byte-identical before/after; 72 variants rejected, 22 non-deterministic skippedCONSOLIDATED
grow (PASS/FAIL)10 → 1compiler else-desync fixed (plain-if); only 10 output-identical — grow's PASS/FAIL formats genuinely vary per gate, so 419 were correctly rejectedCONSOLIDATED (partial)

874 copy-pasted helper bodies collapsed to canonical sources (gw 399 + g_slen 33 + gn 432 + grow 10), each provably behavior-preserving. Full-scale, not sampled — the un-consolidatable variants were rejected, not force-fit.

The gn consolidation used the behavioral applier (nx_behav_consolidate.sh) — the correct oracle for multi-variant helpers, where build-success is invalid: it runs each gate's self-test before and after and keeps only the output-byte-identical adopters, rejecting any variant a canonical would change. A separate per-helper lib avoids the cross-helper import shadow.

The evidence standard (why this is not optimism)

The design law (found by testing, kept in the ecosystem)

Import shadows a same-signature local function. Adding a helper to a shared base that importers already pull in retroactively replaces any importer's same-signature local variant with the canonical — and a build still succeeds, so build-success cannot detect the behavior change. Therefore the only safe shared-base consolidator is exact-match-remove-local (the gw pass) or behavioral-verify-every-importer — never build-success alone. gn/grow were reverted to a provably-original state rather than shipped unverified.

The mechanized tools (reusable)

Sovereign Nishi ecosystem · built and verified on the NAS build tree · no external toolchain.