code wiki / _hdl_build / nx_engineer_reproduce.nx

nx_engineer_reproduce.nx source

↩ module page · 168 lines · 10869 B

1// nx_engineer_reproduce.nx -- the ENGINEER autonomously REPRODUCES Claude's fresh methods on NEW targets, 2// closing the training loop with ZERO Claude authoring the content. For each of the 5 fresh engineer methods 3// it EMITS a real .nx organ that genuinely APPLIES the method, GOD-BUILDS it (fork rv64im->nx_cc->nxasm, no 4// gcc), and keys on the emitted gate's OWN exit code. Each GREEN reproduction is a real compiled+asserting 5// organ on disk => nx_team_train re-grades ENGINEER toward 5/5. Emit/build pattern = the proven nx_god_cycle. 6// E0 find-existing-first -> check existence BEFORE authoring (dup REFUSE / novel ALLOW) 7// E1 extend-not-copy -> a base verdict + a RAISED bar that rejects a case the base accepted 8// E2 gate-with-liar-kill -> a verdict that FLIPS when its data is corrupted 9// E3 measured-exceed -> margin = improvements - regressions on a labeled set, liar-killed 10// E4 never-brick(#26) -> a hardware op without a never-brick proof is REJECTED despite good quality 11// Sovereign. license_tier: ORIGINAL 12import "nx_syscalls.nx" 13const ER_MAGIC_4096: i64 = 4096 14const ER_MAGIC_8192: i64 = 8192 15 16const ER_RUNNER: *u8 = "_offc/nx_sov_build_run.elf" 17 18func ew(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 19func en(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let t: *u8=sys_mmap(24); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } let o: *u8=sys_mmap(24); var w: i64=0; var q: i64=k-1; while q>=0 { o[w]=t[q]; w=w+1; q=q-1 } sys_write(1,o,w); return 0 } 20func ecat(b: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var i: i64=0; while s[i]!=(0 as u8){ b[o]=s[i]; o=o+1; i=i+1 } return o } 21func er_flush(path: *u8, b: *u8, len: i64) -> i64 { let fd: i64=sys_openat_wr(path, 420); if fd<0 { return 0-1 } sys_write(fd, b, len); sys_close(fd); return 0 } 22 23// fork/exec the GOD-ROOTED sovereign toolchain to compile+run the emitted organ; return its exit code. 24func er_build(name: *u8) -> i64 { 25 let pid: i64 = sys_fork() 26 if pid == 0 { 27 let dn: i64 = sys_openat_wr("/dev/null\x00" as *u8, 420) 28 if dn >= 0 { sys_dup3(dn, 1, 0); sys_dup3(dn, 2, 0) } 29 let argv: *i64 = sys_mmap(64) as *i64 30 argv[0] = ER_RUNNER as i64; argv[1] = name as i64; argv[2] = 0 31 let envp: *i64 = sys_mmap(16) as *i64 32 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0 33 sys_execve(ER_RUNNER, argv, envp) 34 sys_exit(127) 35 } 36 let st: *i64 = sys_mmap(16) as *i64 37 sys_wait4(pid, st, 0) 38 return (st[0] >> 8) & 0xff 39} 40 41func er_emit_findfirst() -> i64 { 42 let b: *u8 = sys_mmap(ER_MAGIC_4096); var o: i64 = 0 43 o=ecat(b,o,"// EMITTED by nx_engineer_reproduce -- applies find-existing-first. license_tier: ORIGINAL\n" as *u8) 44 o=ecat(b,o,"import \"nx_syscalls.nx\"\n" as *u8) 45 o=ecat(b,o,"func ex(name: *u8) -> i64 { let fd: i64=sys_openat_rd(name); if fd>=0 { sys_close(fd); return 1 } return 0 }\n" as *u8) 46 o=ecat(b,o,"func main() -> i64 {\n" as *u8) 47 o=ecat(b,o," let dup: i64 = ex(\"runtime/_hdl_build/nx_cap_exists.nx\" as *u8)\n" as *u8) 48 o=ecat(b,o," let novel: i64 = ex(\"runtime/_hdl_build/nx_zzz_absent_xyz.nx\" as *u8)\n" as *u8) 49 o=ecat(b,o," if dup == 1 { if novel == 0 { sys_exit(0); return 0 } }\n" as *u8) 50 o=ecat(b,o," sys_exit(1); return 1\n" as *u8) 51 o=ecat(b,o,"}\n" as *u8) 52 return er_flush("runtime/_hdl_build/nx_eng_repro_findfirst_gate.nx" as *u8, b, o) 53} 54 55func er_emit_extend() -> i64 { 56 let b: *u8 = sys_mmap(ER_MAGIC_4096); var o: i64 = 0 57 o=ecat(b,o,"// EMITTED by nx_engineer_reproduce -- applies extend-not-copy (base + a raised bar). license_tier: ORIGINAL\n" as *u8) 58 o=ecat(b,o,"import \"nx_syscalls.nx\"\n" as *u8) 59 o=ecat(b,o,"func base_ok(score: i64) -> i64 { if score >= 2 { return 1 } return 0 }\n" as *u8) 60 o=ecat(b,o,"func ext_ok(score: i64, hw: i64, proven: i64) -> i64 { if base_ok(score) == 0 { return 0 } if hw == 1 { if proven == 0 { return 0 } } return 1 }\n" as *u8) 61 o=ecat(b,o,"func main() -> i64 {\n" as *u8) 62 o=ecat(b,o," let bb: i64 = base_ok(3)\n" as *u8) 63 o=ecat(b,o," let e1: i64 = ext_ok(3, 1, 0)\n" as *u8) 64 o=ecat(b,o," let e2: i64 = ext_ok(3, 0, 0)\n" as *u8) 65 o=ecat(b,o," if bb == 1 { if e1 == 0 { if e2 == 1 { sys_exit(0); return 0 } } }\n" as *u8) 66 o=ecat(b,o," sys_exit(1); return 1\n" as *u8) 67 o=ecat(b,o,"}\n" as *u8) 68 return er_flush("runtime/_hdl_build/nx_eng_repro_extend_gate.nx" as *u8, b, o) 69} 70 71func er_emit_liarkill() -> i64 { 72 let b: *u8 = sys_mmap(ER_MAGIC_4096); var o: i64 = 0 73 o=ecat(b,o,"// EMITTED by nx_engineer_reproduce -- applies gate-with-liar-kill. license_tier: ORIGINAL\n" as *u8) 74 o=ecat(b,o,"import \"nx_syscalls.nx\"\n" as *u8) 75 o=ecat(b,o,"func main() -> i64 {\n" as *u8) 76 o=ecat(b,o," let data: *i64 = sys_mmap(24) as *i64\n" as *u8) 77 o=ecat(b,o," data[0]=1; data[1]=1; data[2]=1\n" as *u8) 78 o=ecat(b,o," var v: i64 = 1; var i: i64 = 0\n" as *u8) 79 o=ecat(b,o," while i < 3 { if data[i] != 1 { v = 0 } i = i + 1 }\n" as *u8) 80 o=ecat(b,o," data[1] = 0\n" as *u8) 81 o=ecat(b,o," var v2: i64 = 1; i = 0\n" as *u8) 82 o=ecat(b,o," while i < 3 { if data[i] != 1 { v2 = 0 } i = i + 1 }\n" as *u8) 83 o=ecat(b,o," if v == 1 { if v2 == 0 { sys_exit(0); return 0 } }\n" as *u8) 84 o=ecat(b,o," sys_exit(1); return 1\n" as *u8) 85 o=ecat(b,o,"}\n" as *u8) 86 return er_flush("runtime/_hdl_build/nx_eng_repro_liarkill_gate.nx" as *u8, b, o) 87} 88 89func er_emit_measure() -> i64 { 90 let b: *u8 = sys_mmap(ER_MAGIC_8192); var o: i64 = 0 91 o=ecat(b,o,"// EMITTED by nx_engineer_reproduce -- applies measured-exceed (margin, liar-killed). license_tier: ORIGINAL\n" as *u8) 92 o=ecat(b,o,"import \"nx_syscalls.nx\"\n" as *u8) 93 o=ecat(b,o,"func main() -> i64 {\n" as *u8) 94 o=ecat(b,o," let oldc: *i64 = sys_mmap(24) as *i64\n" as *u8) 95 o=ecat(b,o," let newc: *i64 = sys_mmap(24) as *i64\n" as *u8) 96 o=ecat(b,o," let sc: *i64 = sys_mmap(72) as *i64\n" as *u8) 97 o=ecat(b,o," sc[0]=2; sc[1]=9; sc[2]=1; sc[3]=7; sc[4]=3; sc[5]=4; sc[6]=1; sc[7]=2; sc[8]=8\n" as *u8) 98 o=ecat(b,o," let gt: *i64 = sys_mmap(24) as *i64\n" as *u8) 99 o=ecat(b,o," gt[0]=1; gt[1]=0; gt[2]=2\n" as *u8) 100 o=ecat(b,o," var i: i64 = 0\n" as *u8) 101 o=ecat(b,o," while i < 3 {\n" as *u8) 102 o=ecat(b,o," var bi: i64 = 0; var bv: i64 = sc[i*3]; var j: i64 = 1\n" as *u8) 103 o=ecat(b,o," while j < 3 { if sc[i*3+j] > bv { bv = sc[i*3+j]; bi = j } j = j + 1 }\n" as *u8) 104 o=ecat(b,o," oldc[i] = 0\n" as *u8) 105 o=ecat(b,o," if gt[i] == 0 { oldc[i] = 1 }\n" as *u8) 106 o=ecat(b,o," newc[i] = 0\n" as *u8) 107 o=ecat(b,o," if bi == gt[i] { newc[i] = 1 }\n" as *u8) 108 o=ecat(b,o," i = i + 1\n" as *u8) 109 o=ecat(b,o," }\n" as *u8) 110 o=ecat(b,o," var impr: i64 = 0; var regr: i64 = 0\n" as *u8) 111 o=ecat(b,o," i = 0\n" as *u8) 112 o=ecat(b,o," while i < 3 {\n" as *u8) 113 o=ecat(b,o," if oldc[i] == 0 { if newc[i] == 1 { impr = impr + 1 } }\n" as *u8) 114 o=ecat(b,o," if oldc[i] == 1 { if newc[i] == 0 { regr = regr + 1 } }\n" as *u8) 115 o=ecat(b,o," i = i + 1\n" as *u8) 116 o=ecat(b,o," }\n" as *u8) 117 o=ecat(b,o," let margin: i64 = impr - regr\n" as *u8) 118 o=ecat(b,o," var im2: i64 = 0; var rg2: i64 = 0\n" as *u8) 119 o=ecat(b,o," i = 0\n" as *u8) 120 o=ecat(b,o," while i < 3 {\n" as *u8) 121 o=ecat(b,o," var nv: i64 = newc[i]\n" as *u8) 122 o=ecat(b,o," if i == 0 { nv = 0 }\n" as *u8) 123 o=ecat(b,o," if oldc[i] == 0 { if nv == 1 { im2 = im2 + 1 } }\n" as *u8) 124 o=ecat(b,o," if oldc[i] == 1 { if nv == 0 { rg2 = rg2 + 1 } }\n" as *u8) 125 o=ecat(b,o," i = i + 1\n" as *u8) 126 o=ecat(b,o," }\n" as *u8) 127 o=ecat(b,o," let margin2: i64 = im2 - rg2\n" as *u8) 128 o=ecat(b,o," if margin > 0 { if margin2 < margin { sys_exit(0); return 0 } }\n" as *u8) 129 o=ecat(b,o," sys_exit(1); return 1\n" as *u8) 130 o=ecat(b,o,"}\n" as *u8) 131 return er_flush("runtime/_hdl_build/nx_eng_repro_measure_gate.nx" as *u8, b, o) 132} 133 134func er_emit_neverbrick() -> i64 { 135 let b: *u8 = sys_mmap(ER_MAGIC_4096); var o: i64 = 0 136 o=ecat(b,o,"// EMITTED by nx_engineer_reproduce -- applies never-brick(#26): the safety bar dominates. license_tier: ORIGINAL\n" as *u8) 137 o=ecat(b,o,"import \"nx_syscalls.nx\"\n" as *u8) 138 o=ecat(b,o,"func certify(hw: i64, proven: i64, quality_ok: i64) -> i64 { if hw == 1 { if proven == 0 { return 0 } } return quality_ok }\n" as *u8) 139 o=ecat(b,o,"func main() -> i64 {\n" as *u8) 140 o=ecat(b,o," let unproven: i64 = certify(1, 0, 1)\n" as *u8) 141 o=ecat(b,o," let proven: i64 = certify(1, 1, 1)\n" as *u8) 142 o=ecat(b,o," let software: i64 = certify(0, 0, 1)\n" as *u8) 143 o=ecat(b,o," if unproven == 0 { if proven == 1 { if software == 1 { sys_exit(0); return 0 } } }\n" as *u8) 144 o=ecat(b,o," sys_exit(1); return 1\n" as *u8) 145 o=ecat(b,o,"}\n" as *u8) 146 return er_flush("runtime/_hdl_build/nx_eng_repro_neverbrick_gate.nx" as *u8, b, o) 147} 148 149// emit + god-build one reproduction; print the result; return 1 if GREEN. 150func er_one(label: *u8, name: *u8, emit_rc: i64) -> i64 { 151 if emit_rc != 0 { ew(" [emit FAIL] " as *u8); ew(label); ew("\n" as *u8); return 0 } 152 let ex: i64 = er_build(name) 153 if ex == 0 { ew(" [GREEN] " as *u8); ew(label); ew(" -> " as *u8); ew(name); ew(".nx compiled + asserts passed\n" as *u8); return 1 } 154 ew(" [RED] " as *u8); ew(label); ew(" (exit " as *u8); en(ex); ew(")\n" as *u8); return 0 155} 156 157func main() -> i64 { 158 ew("=== ENGINEER reproduces ALL 5 fresh methods on new targets (autonomous emit + god-build) ===\n" as *u8) 159 var green: i64 = 0 160 green = green + er_one("find-existing-first" as *u8, "nx_eng_repro_findfirst_gate" as *u8, er_emit_findfirst()) 161 green = green + er_one("extend-not-copy" as *u8, "nx_eng_repro_extend_gate" as *u8, er_emit_extend()) 162 green = green + er_one("gate-with-liar-kill" as *u8, "nx_eng_repro_liarkill_gate" as *u8, er_emit_liarkill()) 163 green = green + er_one("measured-exceed" as *u8, "nx_eng_repro_measure_gate" as *u8, er_emit_measure()) 164 green = green + er_one("never-brick(#26)" as *u8, "nx_eng_repro_neverbrick_gate" as *u8, er_emit_neverbrick()) 165 ew(" reproduced " as *u8); en(green); ew("/5 engineer methods (each a real compiled+passing organ).\n" as *u8) 166 if green == 5 { ew(" Re-run nx_team_train_gate: ENGINEER frontier 5/5 -- the team can now DO all 5, autonomously.\n" as *u8); sys_exit(0); return 0 } 167 ew(" (honest: only " as *u8); en(green); ew("/5 passed -- the rest stay un-owned)\n" as *u8); sys_exit(1); return 1 168}