code wiki / _hdl_build / nx_beingctl.nx

nx_beingctl.nx source

↩ module page · 312 lines · 16146 B

1// nx_beingctl -- the end-to-end being driver (plan rung S8, first slice). 2// 3// ★THE FINDING THAT STARTED THIS PROGRAM: ~110KB of gated organs, connected to NOTHING. Every stage 4// below existed, was gated GREEN, and had never once been run in sequence. This organ is the sequence. 5// 6// build: nx_body_proc (params -> canon) -> nx_body_gen (canon -> mesh) -> nx_flexbody (pose flex) 7// -> nx_fascia (fascia/fat as soft body) 8// bench: nx_twinbench rms through its machine channel 9// 10// Composition, not reimplementation: this organ owns no canon rule, no mesh math, no metric. It forks 11// the organs that do and FAILS LOUD per stage with distinct exits, deleting its target first so a 12// failed run can never leave a stale artifact that reads as success. 13// 14// ✅RETRACTED 2026-08-03 (was: "fascia is NOT in this slice -- nx_fascia exists only on the NAS SSOT"). 15// The condition it named is satisfied: driver and organ are both on the NAS tree, nx_fascia is 7/7 GREEN 16// there, and the stage is wired as stage 4 behind an OPT-IN flag, so fascia=0 is bit-identical to the 17// pre-fascia chain. ⚠STILL NOT IN THIS CHAIN: nx_softtissue.nx, the 3D layered XPBD tet cage that is the 18// estate's most capable tissue model -- it is imported by its three gates and NOTHING else (debt 19// 1785766330). fascia here is nx_softdyn's spring-damper lattice, a strictly coarser tier. 20// 21// usage: nx_beingctl build <out.nxmesh> <sex> <build> <musc> [flex_deg] [fascia] 22// nx_beingctl bench <cand.nxmesh> <ref.nxmesh> [stature_mm] 23// nx_beingctl selftest 24import "nx_gate_verdict.nx" 25 26const BC_STATURE: i64 = 1750 27const BC_RADIAL: i64 = 10 28const BC_SUB: i64 = 1 29const BC_RELIEF: i64 = 0 30const BC_SAMPLES: i64 = 3000 31 32func bc_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 33func bc_pn(v: i64) -> i64 { 34 let b: *u8 = sys_mmap(32); var x: i64=v; var ng: i64=0 35 if x<0 { ng=1; x=0-x } 36 var i: i64=31 37 if x==0 { b[i]=48 as u8; i=i-1 } 38 while x>0 { b[i]=(48+x%10) as u8; x=x/10; i=i-1 } 39 if ng==1 { b[i]=45 as u8; i=i-1 } 40 sys_write(1,(b as i64 + i + 1) as *u8, 31-i); return 0 41} 42func bc_streq(a: *u8, b: *u8) -> i64 { 43 var i: i64=0; var go: i64=1; var eq: i64=1 44 while go==1 { if a[i]!=b[i] { eq=0; go=0 } else { if a[i]==(0 as u8) { go=0 } else { i=i+1 } } } 45 return eq 46} 47func bc_atoi(s: *u8) -> i64 { 48 var i: i64=0; var n: i64=0; var sg: i64=1 49 if s[0]==(45 as u8) { sg=0-1; i=1 } 50 while s[i]!=(0 as u8) { let c: i64=s[i] as i64; if c>=48 { if c<=57 { n=n*10+(c-48) } } i=i+1 } 51 return n*sg 52} 53func bc_itoa(v: i64, b: *u8) -> *u8 { 54 var x: i64 = v; var k: i64 = 0 55 let t: *u8 = sys_mmap(32) 56 if x == 0 { t[0] = 48 as u8; k = 1 } 57 var ng: i64 = 0 58 if x < 0 { ng = 1; x = 0-x } 59 while x > 0 { t[k] = (48+x%10) as u8; x = x/10; k = k+1 } 60 var p: i64 = 0 61 if ng == 1 { b[0] = 45 as u8; p = 1 } 62 var q: i64 = k-1 63 while q >= 0 { b[p] = t[q]; p = p+1; q = q-1 } 64 b[p] = 0 as u8 65 return b 66} 67// ★A DEFAULT THAT WORKS OFF THE AUTHOR'S MACHINE (wired 2026-08-03). Every stage below was exec'd as 68// "./nx_<stage>.elf", a name the build system NEVER produces -- it emits "_build/<stage>.sov.elf", and a 69// census found exactly ONE non-.sov .elf in the whole build tree. So every stage returned 127 = NOT FOUND, 70// which the driver could only report as a failed stage. That is why "the organs are connected to nothing" 71// survived a driver written specifically to connect them: the sequence existed and could never once run. 72// Same class, same remedy as nx_arousal_mesh_gate.nx:78 -- prefer the promoted name, fall back to the dev 73// path, so ONE file is correct on both machines. ⚠exit 127 is NOT-FOUND, never a failing assertion. 74func bc_exists(pth: *u8) -> i64 { 75 let fd: i64 = sys_openat_rd(pth) 76 if fd < 0 { return 0 } 77 sys_close(fd) 78 return 1 79} 80func bc_pick(promoted: *u8, devpath: *u8) -> *u8 { 81 if bc_exists(promoted) == 1 { return promoted } 82 return devpath 83} 84// fork+exec+wait -- the codebase's proven idiom, whole 85func bc_run(path: *u8, a: *i64, nargs: i64) -> i64 { 86 let pid: i64 = sys_fork() 87 if pid == 0 { 88 let av: *i64 = sys_mmap((nargs+2)*8) as *i64 89 av[0] = path as i64 90 var i: i64 = 0 91 while i < nargs { av[i+1] = a[i]; i = i+1 } 92 av[nargs+1] = 0 93 sys_execve(path, av as *i64, 0 as *i64) 94 sys_exit(127) 95 } 96 if pid < 0 { return 0-1 } 97 let stw: *i64 = sys_mmap(16) as *i64 98 stw[0] = 0 99 sys_wait4(pid, stw, 0) 100 return wait_exit_code(stw[0]) 101} 102// twinbench rms through a pipe. ★pipe2 fills int[2] -- TWO 32-BIT fds packed in 8 bytes; unpack or the 103// write end is never closed and the read never EOFs (nx_tool_run.nx:24; the creatorfit wedge). 104func bc_rms(cand: *u8, ref: *u8, stature: i64) -> i64 { 105 let pf: *i64 = sys_mmap(32) as *i64 106 if sys_pipe2(pf, 0) < 0 { return 0-3 } 107 let packed: i64 = pf[0] 108 let rfd: i64 = packed & 0xFFFFFFFF 109 let wfd: i64 = (packed >> 32) & 0xFFFFFFFF 110 let b1: *u8 = sys_mmap(64); let b2: *u8 = sys_mmap(64) 111 let tbp: *u8 = bc_pick("./nx_twinbench.elf" as *u8, "_build/nx_twinbench.sov.elf" as *u8) 112 let pid: i64 = sys_fork() 113 if pid == 0 { 114 sys_close(rfd) 115 sys_dup3(wfd, 1, 0) 116 let av: *i64 = sys_mmap(8*8) as *i64 117 av[0] = tbp as i64 118 av[1] = "rms" as i64 119 av[2] = cand as i64 120 av[3] = ref as i64 121 av[4] = bc_itoa(stature, b1) as i64 122 av[5] = bc_itoa(BC_SAMPLES, b2) as i64 123 av[6] = 0 124 sys_execve(tbp, av as *i64, 0 as *i64) 125 sys_exit(127) 126 } 127 if pid < 0 { return 0-4 } 128 sys_close(wfd) 129 let rb: *u8 = sys_mmap(256) 130 var got: i64 = 0 131 var run: i64 = 1 132 while run == 1 { 133 let n: i64 = sys_read(rfd, (rb as i64 + got) as *u8, 255-got) 134 if n <= 0 { run = 0 } else { got = got + n; if got >= 255 { run = 0 } } 135 } 136 sys_close(rfd) 137 let stw: *i64 = sys_mmap(16) as *i64 138 stw[0] = 0 139 sys_wait4(pid, stw, 0) 140 rb[got] = 0 as u8 141 return bc_atoi(rb) 142} 143// the chain. Returns 0, or the failing stage as a distinct negative. Deletes the target FIRST. 144func bc_build(outp: *u8, sex: i64, bld: i64, msc: i64, flex: i64, fasc: i64, tmpc: *u8, tmpraw: *u8, tmpfas: *u8) -> i64 { 145 sys_unlinkat(outp) 146 sys_unlinkat(tmpraw) 147 sys_unlinkat(tmpfas) 148 let a: *i64 = sys_mmap(16*8) as *i64 149 let b1: *u8 = sys_mmap(64); let b2: *u8 = sys_mmap(64); let b3: *u8 = sys_mmap(64) 150 let b4: *u8 = sys_mmap(64); let b5: *u8 = sys_mmap(64); let b6: *u8 = sys_mmap(64) 151 // stage 1: params -> canon 152 a[0] = tmpc as i64 153 a[1] = bc_itoa(sex, b1) as i64 154 a[2] = bc_itoa(bld, b2) as i64 155 a[3] = bc_itoa(msc, b3) as i64 156 a[4] = bc_itoa(0, b4) as i64 157 a[5] = bc_itoa(1, b5) as i64 158 a[6] = bc_itoa(0, b6) as i64 159 if bc_run(bc_pick("./nx_body_proc.elf" as *u8, "_build/nx_body_proc.sov.elf" as *u8), a, 7) != 0 { return 0-10 } 160 // stage 2: canon -> raw mesh 161 var meshout: *u8 = outp 162 if flex > 0 { meshout = tmpraw } 163 if flex == 0 { if fasc > 0 { meshout = tmpraw } } 164 a[0] = meshout as i64 165 a[1] = bc_itoa(BC_STATURE, b1) as i64 166 a[2] = bc_itoa(BC_RADIAL, b2) as i64 167 a[3] = bc_itoa(BC_SUB, b3) as i64 168 a[4] = bc_itoa(BC_RELIEF, b4) as i64 169 a[5] = tmpc as i64 170 if bc_run(bc_pick("./nx_body_gen.elf" as *u8, "_build/nx_body_gen.sov.elf" as *u8), a, 6) != 0 { return 0-20 } 171 // stage 3: pose flex (the first stranded organ wired into the chain) 172 var cur: *u8 = meshout 173 var fo: *u8 = outp 174 if fasc > 0 { fo = tmpfas } 175 if flex > 0 { 176 a[0] = tmpraw as i64 177 a[1] = fo as i64 178 a[2] = bc_itoa(flex, b1) as i64 179 if bc_run(bc_pick("./nx_flexbody.elf" as *u8, "_build/nx_flexbody.sov.elf" as *u8), a, 3) != 0 { return 0-30 } 180 cur = fo 181 } 182 // ★stage 4: FASCIA/FAT AS SOFT BODY -- the stage the first slice deliberately deferred, wired 183 // 2026-08-03. The original header refused it because nx_fascia lived only on the NAS SSOT and 184 // wiring it against a stale local copy would fork the source of truth. Both organ and driver are 185 // now on the NAS tree, so the reason to defer is gone. Order is the industry pipeline's own: 186 // skeleton -> muscle (flexbody) -> fascia/fat -> skin, so fascia consumes the FLEXED mesh. 187 // fasc=0 is bit-identical to the previous chain (Rule 19: additive only). 188 if fasc > 0 { 189 a[0] = cur as i64 190 a[1] = outp as i64 191 if bc_run(bc_pick("./nx_fascia.elf" as *u8, "_build/nx_fascia.sov.elf" as *u8), a, 2) != 0 { return 0-40 } 192 } 193 return 0 194} 195func bc_gate() -> i64 { 196 let ctr: *i64 = gv_ctr() 197 gv_head("nx_beingctl selftest -- the stranded organs, run in sequence for the first time" as *u8) 198 let tc: *u8 = "/tmp/bc_c.dat" as *u8 199 let traw: *u8 = "/tmp/bc_raw.nxmesh" as *u8 200 let m0: *u8 = "/tmp/bc_flat.nxmesh" as *u8 201 let m1: *u8 = "/tmp/bc_flex.nxmesh" as *u8 202 let m2: *u8 = "/tmp/bc_fascia.nxmesh" as *u8 203 let tfas: *u8 = "/tmp/bc_fas_tmp.nxmesh" as *u8 204 // ★★T1 THE CHAIN COMPOSES: params -> canon -> mesh, driver adds nothing of its own 205 var t1: i64 = 0 206 if bc_build(m0, 600, 400, 500, 0, 0, tc, traw, tfas) == 0 { 207 let szp: *i64 = sys_mmap(16) as *i64 208 let mb: *u8 = sys_read_file(m0, szp) 209 if (mb as i64) != 0 { if szp[0] > 1000 { t1 = 1 } } 210 } 211 gv_check("T1 THE CHAIN COMPOSES: parameters become a mesh through two forked organs, rc 0 at every stage" as *u8, t1, ctr) 212 // ★★★T2 THE STRANDED ORGAN DOES SOMETHING: flex=150 must produce a DIFFERENT mesh. This is the 213 // anti-vacuity tooth for the whole S8 idea -- wiring an organ into a chain that it does not move 214 // is cosmetic wiring, and the program has caught cosmetic gates twice before. 215 var t2: i64 = 0 216 if bc_build(m1, 600, 400, 500, 150, 0, tc, traw, tfas) == 0 { 217 let s0: *i64 = sys_mmap(16) as *i64 218 let s1: *i64 = sys_mmap(16) as *i64 219 let a0: *u8 = sys_read_file(m0, s0) 220 let a1: *u8 = sys_read_file(m1, s1) 221 if (a0 as i64) != 0 { if (a1 as i64) != 0 { 222 var diff: i64 = 0 223 if s0[0] != s1[0] { diff = 1 } else { 224 var i: i64 = 0 225 while i < s0[0] { if a0[i] != a1[i] { diff = 1; i = s0[0] } else { i = i + 1 } } 226 } 227 t2 = diff 228 } } 229 } 230 gv_check("T2 THE STRANDED ORGAN MOVES THE MESH: flex 150 produces a different body than flex 0 -- the wiring is real, not cosmetic" as *u8, t2, ctr) 231 // ★★T3 THE RULER SEES THE FLEX -- and the number is REPORTED, whatever it is. S8's declared tooth: 232 // if composed benches worse than raw, publish that; what is refused is silence. 233 let d: i64 = bc_rms(m1, m0, BC_STATURE) 234 var t3: i64 = 0 235 if d > 0 { t3 = 1 } 236 gv_check("T3 THE RULER SEES IT: rms(flexed, flat) is a positive measured distance, reported not hidden" as *u8, t3, ctr) 237 bc_puts(" [measured] rms(flex150, flat) um = " as *u8); bc_pn(d); bc_puts("\n" as *u8) 238 // ★T4 self-distance is exactly zero -- the bench channel through this driver is calibrated 239 var t4: i64 = 0 240 if bc_rms(m0, m0, BC_STATURE) == 0 { t4 = 1 } 241 gv_check("T4 CALIBRATED: rms(flat, flat) through the driver's own channel is exactly 0" as *u8, t4, ctr) 242 // ★T5 A FAILING STAGE FAILS LOUD AND LEAVES NO ARTIFACT: unreadable canon path -> stage-2 exit, 243 // and the target mesh must NOT exist afterwards (deleted up front, never re-created) 244 var t5: i64 = 0 245 let rc5: i64 = bc_build("/tmp/bc_never.nxmesh" as *u8, 600, 400, 500, 0, 0, "/tmp/bc_nodir_x/nope.dat" as *u8, traw, tfas) 246 if rc5 == 0-10 { 247 let s5: *i64 = sys_mmap(16) as *i64 248 if (sys_read_file("/tmp/bc_never.nxmesh" as *u8, s5) as i64) == 0 { t5 = 1 } 249 } 250 gv_check("T5 FAILS LOUD, LEAVES NOTHING: a broken stage returns its own distinct exit and the target mesh does not exist -- a failed build can never read as a stale success" as *u8, t5, ctr) 251 // ★★★T6 THE DEFERRED STAGE IS REAL: fascia=1 must produce a DIFFERENT body than fascia=0 at the SAME 252 // flex. The control is not a remembered number from another run -- it is m1, built in THIS gate with 253 // identical parameters and the stage switched off. A comparison tooth carries its own control or it is 254 // a voter with information content 0. 255 var t6: i64 = 0 256 if bc_build(m2, 600, 400, 500, 150, 1, tc, traw, tfas) == 0 { 257 let s1b: *i64 = sys_mmap(16) as *i64 258 let s2b: *i64 = sys_mmap(16) as *i64 259 let c1: *u8 = sys_read_file(m1, s1b) 260 let c2: *u8 = sys_read_file(m2, s2b) 261 if (c1 as i64) != 0 { if (c2 as i64) != 0 { 262 var dif2: i64 = 0 263 if s1b[0] != s2b[0] { dif2 = 1 } else { 264 var j: i64 = 0 265 while j < s1b[0] { if c1[j] != c2[j] { dif2 = 1; j = s1b[0] } else { j = j + 1 } } 266 } 267 t6 = dif2 268 } } 269 } 270 gv_check("T6 THE DEFERRED STAGE IS REAL: fascia=1 moves the mesh vs fascia=0 at identical flex -- control built in the same run, not recalled" as *u8, t6, ctr) 271 let df: i64 = bc_rms(m2, m1, BC_STATURE) 272 bc_puts(" [measured] rms(fascia_on, fascia_off) um = " as *u8); bc_pn(df); bc_puts("\n" as *u8) 273 return gv_verdict("BEINGCTL-GATE" as *u8, ctr, "proc->gen->flexbody->fascia->bench in one driver; per-stage loud failure; the stranded organs run as one chain" as *u8) 274} 275func main(argc: i64, argv: *i64) -> i64 { 276 if argc >= 2 { 277 if bc_streq(argv[1] as *u8, "selftest" as *u8) == 1 { return bc_gate() } 278 if bc_streq(argv[1] as *u8, "build" as *u8) == 1 { 279 if argc < 6 { bc_puts("{\x22error\x22:\x22usage: nx_beingctl build <out.nxmesh> <sex> <build> <musc> [flex_deg] [fascia]\x22}\n" as *u8); return 2 } 280 var flex: i64 = 0 281 if argc > 6 { flex = bc_atoi(argv[6] as *u8) } 282 var fasc: i64 = 0 283 if argc > 7 { fasc = bc_atoi(argv[7] as *u8) } 284 let rc: i64 = bc_build(argv[2] as *u8, bc_atoi(argv[3] as *u8), bc_atoi(argv[4] as *u8), bc_atoi(argv[5] as *u8), 285 flex, fasc, "/tmp/bc_cli_c.dat" as *u8, "/tmp/bc_cli_raw.nxmesh" as *u8, "/tmp/bc_cli_fas.nxmesh" as *u8) 286 if rc != 0 { 287 bc_puts("{\x22organ\x22:\x22nx_beingctl\x22,\x22verdict\x22:\x22STAGE-FAILED\x22,\x22rc\x22:" as *u8); bc_pn(rc) 288 bc_puts(",\x22stages\x22:\x22-10 body_proc, -20 body_gen, -30 flexbody, -40 fascia -- the failing organ's own output precedes this line\x22}\n" as *u8) 289 return 0-rc 290 } 291 bc_puts("{\x22organ\x22:\x22nx_beingctl\x22,\x22verb\x22:\x22build\x22,\x22flex_deg\x22:" as *u8); bc_pn(flex) 292 bc_puts(",\x22fascia\x22:" as *u8); bc_pn(fasc) 293 bc_puts(",\x22chain\x22:\x22body_proc -> body_gen" as *u8) 294 if flex > 0 { bc_puts(" -> flexbody" as *u8) } 295 if fasc > 0 { bc_puts(" -> fascia" as *u8) } 296 bc_puts("\x22,\x22reads\x22:\x22the stranded organs, run as one chain. This driver owns no canon rule, no mesh math, no metric -- composition only, loud per-stage failure.\x22}\n" as *u8) 297 return 0 298 } 299 if bc_streq(argv[1] as *u8, "bench" as *u8) == 1 { 300 if argc < 4 { bc_puts("{\x22error\x22:\x22usage: nx_beingctl bench <cand.nxmesh> <ref.nxmesh> [stature_mm]\x22}\n" as *u8); return 2 } 301 var st: i64 = BC_STATURE 302 if argc > 4 { st = bc_atoi(argv[4] as *u8) } 303 let r: i64 = bc_rms(argv[2] as *u8, argv[3] as *u8, st) 304 bc_puts("{\x22organ\x22:\x22nx_beingctl\x22,\x22verb\x22:\x22bench\x22,\x22rms_um\x22:" as *u8); bc_pn(r) 305 bc_puts(",\x22samples\x22:" as *u8); bc_pn(BC_SAMPLES) 306 bc_puts(",\x22reads\x22:\x22nx_twinbench's number through its machine channel -- one metric, one implementation.\x22}\n" as *u8) 307 return 0 308 } 309 } 310 bc_puts("{\x22organ\x22:\x22nx_beingctl\x22,\x22usage\x22:\x22nx_beingctl build <out> <sex> <build> <musc> [flex] | bench <cand> <ref> [stature] | selftest\x22}\n" as *u8) 311 return 0 312}