code wiki / _hdl_build / nx_dedup_migrate.nx
nx_dedup_migrate.nx
buildroot/runtime/_hdl_build/nx_dedup_migrate.nx
about
nx_dedup_migrate.nx -- D001-FAMILY ORGAN-DEDUP MIGRATION VERIFIER (2026-07-23, dedupq-/TS03 lane).
THE DEBT (measured): 245 organs in _hdl_build re-implement the same ~10 span/JSON helpers inline
(~2400 duplicated funcs, D001-family; queue = knowledge/store/dedupq-). The canonical base is
nx_sovjson_lib.nx (proven consumers: nx_seat/nx_clawf_route/nx_actlog/nx_tokroi/nx_ctxcost).
The EDIT (delegate local helpers to sj_*) is mechanical -- an author lane or the local maker
produces a .migrated source; THIS organ is the unfailable judge that makes committing it safe,
which is what lets the migration run AUTONOMOUSLY (a tool that cannot do the wrong thing beats
a session that must remember).
THE SOUND ORACLE = BEHAVIOR-EQUIVALENCE (source-byte equivalence is the WRONG oracle -- param
names/registers differ across organs; the exact lesson that unblocked the D001 gate campaign
via judge-equivalence):
(a) exit code identical (original argless probe vs migrated argless probe)
(b) stdout byte-identical -- or, when the original is not self-deterministic (two baseline
runs differ, e.g. epoch stamps), digit-normalized-identical; the MODE is DECLARED in the
report, never silently weakened
(c) non-vacuity: the migrated source imports nx_sovjson_lib AND calls sj_* AND differs from
the original (an unchanged "migration" is a lie -> REFUSE)
commit-or-restore: on ANY refusal/build-failure/harness error the ORIGINAL source is restored
AND rebuilt (so /tmp + staged artifacts match reality); the pre-migration copy is kept as
<src>.premigrate, FIRST-TOUCH preserved (rule 13 additive -- a second run never clobbers the
true original). never-brick: touches ONLY buildroot sources + /tmp build artifacts; live elf
promotion stays a separate deliberate /api step. No hw writes (Rule 26).
nx_dedup_migrate stage <organ> -- copy <src> -> <src>.migrated (edit substrate)
nx_dedup_migrate verify <organ> <migrated-src> -- judge + commit-or-restore
nx_dedup_migrate selftest -- hermetic oracle teeth (gv lib)
license_tier: ORIGINAL expect_exit: 0
dependencies 6 imports · 0 importers
imports: nx_syscalls.nxnx_gate_verdict.nxnx_tool_run.nxnx_sovjson_lib.nxnx_store_seed_lib.nxnx_seg_store.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 36 | const DD_MAGIC_4096: i64 = 4096 |
| 37 | const DD_MAGIC_1024: i64 = 1024 |
| 38 | const DD_MAGIC_65536: i64 = 65536 |
| 40 | const DD_CAP: i64 = 262144 |
| 41 | const DD_PATH: i64 = 512 |
| 42 | const DD_MODE: i64 = 420 |
| 43 | const DD_XMODE: i64 = 493 |
| 44 | const DD_ELF_MAG0: i64 = 127 |
| 45 | const DD_SLOT: i64 = 16 |
| 46 | const DD_ARGV: i64 = 40 |
| 47 | const DD_RES_BYTES: i64 = 64 |
| 48 | const DD_SRC: i64 = 524288 |
| 49 | const DD_PLANE: i64 = 1048576 |
| 50 | const DD_USAGE: i64 = 2 |
| 51 | const DD_REFUSE: i64 = 3 |
| 52 | const DD_HARNESS: i64 = 4 |
| 54 | const DD_R_EXIT: i64 = 0 |
| 55 | const DD_R_OUT: i64 = 1 |
| 56 | const DD_R_NORM: i64 = 2 |
| 57 | const DD_R_IMPORT: i64 = 3 |
| 58 | const DD_R_CALLS: i64 = 4 |
| 59 | const DD_R_CHANGED: i64 = 5 |
| 60 | const DD_R_RAN: i64 = 6 |
| 61 | const DD_RESN: i64 = 7 |
| 62 | const DD_UNMEASURED: i64 = 0 - 1 |
| 309 | const DE_N: i64 = 9 |
functions
| 64 | func dd_eqz(a: *u8, b: *u8) -> i64 called by 1: main |
| 71 | func dd_read(path: *u8, lenp: *i64) -> *u8 |
| 79 | func dd_write_file(path: *u8, buf: *u8, n: i64) -> i64 { return dd_write_file_m(path, buf, n, DD_MODE) } |
| 81 | func dd_write_file_m(path: *u8, buf: *u8, n: i64, mode: i64) -> i64 |
| 97 | func dd_byteeq(a: *u8, na: i64, b: *u8, nb: i64) -> i64 |
| 106 | func dd_normeq(a: *u8, na: i64, b: *u8, nb: i64) -> i64 |
| 126 | func dd_oracle(rcA: i64, rcB: i64, outA: *u8, nA: i64, outB: *u8, nB: i64, selfdet: i64, imp: i64, calls: i64, changed: i64, res: *i64) -> i64 |
| 143 | func dd_path_src(organ: *u8, out: *u8) -> i64 |
| 151 | func dd_path_art(organ: *u8, out: *u8) -> i64 |
| 161 | func dd_build(organ: *u8) -> i64 |
| 189 | func dd_run(organ: *u8, out: *u8, ol: *i64) -> i64 |
| 202 | func dd_report(organ: *u8, verdict: *u8, res: *i64, rcA: i64, rcB: i64, nA: i64, nB: i64, srcA: i64, srcB: i64, reason: *u8) -> i64 |
| 253 | func de_isws(c: i64) -> i64 { if c == 32 { return 1 } if c == 9 { return 1 } return 0 } called by 1: de_try |
| 255 | func de_at(q: *u8, n: i64, i: i64, lit: *u8) -> i64 |
| 265 | func de_linestart(q: *u8, i: i64) -> i64 |
| 272 | func de_close(q: *u8, n: i64, open: i64) -> i64 called by 1: de_try |
| 299 | func de_endswith(q: *u8, s: i64, e: i64, lit: *u8) -> i64 |
| 310 | func de_suffix(k: i64) -> *u8 called by 1: de_try |
| 322 | func de_sig(k: i64) -> *u8 called by 1: de_try |
| 334 | func de_target(k: i64) -> *u8 called by 1: de_try |
| 348 | func de_nulterm(q: *u8, ob: i64, cb: i64) -> i64 |
| 356 | func de_try(q: *u8, n: i64, i: i64, out: *u8, o: i64, res2: *i64) -> i64 |
| 444 | func dd_edit(q: *u8, n: i64, out: *u8, lenp: *i64) -> i64 |
| 478 | func dd_insert_import(q: *u8, n: i64, out: *u8, lenp: *i64) -> i64 |
| 498 | func dd_qparse(q: *u8, ls: i64, le: i64, res: *i64) -> i64 |
| 518 | func main(argc: i64, argv: *i64) -> i64 |