code wiki / _hdl_build / nx_authorgen_gate.nx

nx_authorgen_gate.nx source

↩ module page · 127 lines · 7620 B

1// nx_authorgen_gate.nx -- ★THE ORCA PATTERN, GATED: describe -> build -> VALIDATE -> deploy, on the sovereign engine. 2// T1 "a rabbit with long ears" -> rabbit built, long ears MEASURED present. T2 "a four-armed monster with horns and 3// a tail" -> all four features MEASURED present. T3 SUBTRACTIVE causal: "a monster with two arms and no horns and no 4// tail" -> those parts MEASURED ABSENT (the words really drive the build). T4 "a person" -> canon human. T5 ★ANTI- 5// HALLUCINATION (the differentiator vs "AI writes code and hopes"): "a dragon with wings that breathes fire" builds 6// a body but HONESTLY reports unmet features; "a shiny spaceship" is REFUSED (no fake build). T6 determinism. T7 7// evidence render. license_tier: ORIGINAL expect_exit: 0 8import "nx_syscalls.nx" 9import "nx_png.nx" 10import "nx_bodyatlas.nx" 11import "nx_genome.nx" 12import "nx_authorgen.nx" 13 14func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 15func pn(v: i64) -> i64 { let b: *u8=sys_mmap(32) as *u8; var x: i64=v; var ng: i64=0; if x<0{ng=1;x=0-x} var i: i64=31; if x==0{b[i]=48 as u8;i=i-1} while x>0{b[i]=(48+x%10) as u8;x=x/10;i=i-1} if ng==1{b[i]=45 as u8;i=i-1} sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 } 16func inside(x: i64, y: i64, z: i64) -> i64 { if ba_sdf(x, y, z, 1) < 0 { return 1 } return 0 } 17func top_at(x: i64, z: i64, yhi: i64, ylo: i64) -> i64 { 18 var y: i64 = yhi 19 while y >= ylo { if ba_sdf(x, y, z, 1) < 0 { return y } y = y - 4 } 20 return 0-100000 21} 22func clearfb(fb: *i64, n: i64, c: i64) -> i64 { var i: i64=0; while i<n { fb[i]=c; i=i+1 } return 0 } 23 24func main() -> i64 { 25 hw("=== nx_authorgen_gate -- describe -> build -> validate -> deploy (the Orca pattern, sovereign) ===\n" as *u8) 26 var fails: i64 = 0 27 28 // ---- T1 "a rabbit with long ears" ---- 29 ag_parse("a rabbit with long ears" as *u8) 30 let n1: i64 = ag_build() 31 let headTop: i64 = top_at(0, 380, 700, 100) 32 let earTip: i64 = top_at(74, 268, 900, 200) 33 hw(" 'a rabbit with long ears' -> plan="); pn(ag_plan()); hw(" parts="); pn(n1); hw(" headTop="); pn(headTop); hw(" earTip="); pn(earTip); hw("\n" as *u8) 34 var t1: i64 = 0 35 if ag_plan() == 1 { if n1 > 10 { if earTip > headTop + 90 { t1 = 1 } } } 36 if t1 == 1 { hw("T1 PASS a rabbit was built with LONG EARS (the words drove the geometry -- ear tip well above the head)\n" as *u8) } 37 else { fails=fails+1; hw("T1 FAIL\n" as *u8) } 38 39 // ---- T2 "a four-armed monster with horns and a tail" ---- 40 ag_parse("a four-armed monster with horns and a tail" as *u8) 41 let n2: i64 = ag_build() 42 var arms: i64 = inside(330,500,40) + inside(0-330,500,40) + inside(330,0-180,90) + inside(0-330,0-180,90) 43 let horn: i64 = inside(90,1030,0-10) + inside(0-90,1030,0-10) 44 let tail: i64 = inside(0,0-270,0-289) 45 hw(" '...four-armed monster with horns and a tail' -> plan="); pn(ag_plan()); hw(" arms="); pn(arms); hw("/4 horns="); pn(horn); hw("/2 tail="); pn(tail); hw(" unmet="); pn(ag_unmet()); hw("\n" as *u8) 46 var t2: i64 = 0 47 if ag_plan() == 2 { if arms == 4 { if horn == 2 { if tail == 1 { t2 = 1 } } } } 48 if t2 == 1 { hw("T2 PASS every requested feature BUILT + MEASURED present (4 arms, horns, tail)\n" as *u8) } 49 else { fails=fails+1; hw("T2 FAIL\n" as *u8) } 50 51 // ---- T3 SUBTRACTIVE causal: features toggle OFF from the words ---- 52 ag_parse("a monster with two arms and no horns and no tail" as *u8) 53 ag_build() 54 let armsLo: i64 = inside(330,0-180,90) + inside(0-330,0-180,90) // ISOLATED lower arm (upper chain only reaches y~13) -> GONE 55 let armsUp: i64 = inside(330,500,40) + inside(0-330,500,40) // upper pair -> stays 56 let horn2: i64 = inside(90,1030,0-10) + inside(0-90,1030,0-10) 57 let tail2: i64 = inside(0,0-270,0-289) 58 hw(" '...two arms and no horns and no tail' -> lower-arms="); pn(armsLo); hw(" upper-arms="); pn(armsUp); hw(" horns="); pn(horn2); hw(" tail="); pn(tail2); hw("\n" as *u8) 59 var t3: i64 = 0 60 if armsLo == 0 { if armsUp == 2 { if horn2 == 0 { if tail2 == 0 { t3 = 1 } } } } 61 if t3 == 1 { hw("T3 PASS SUBTRACTIVE causal: 'two arms / no horns / no tail' removed exactly those parts (the parser truly drives the build)\n" as *u8) } 62 else { fails=fails+1; hw("T3 FAIL\n" as *u8) } 63 64 // ---- T4 "a person" ---- 65 ag_parse("please build a person" as *u8) 66 let n4: i64 = ag_build() 67 hw(" 'please build a person' -> plan="); pn(ag_plan()); hw(" parts="); pn(n4); hw("\n" as *u8) 68 var t4: i64 = 0 69 if ag_plan() == 0 { if n4 >= 119 { t4 = 1 } } 70 if t4 == 1 { hw("T4 PASS a canon human was built (119+ parts, the anthropometry-validated body)\n" as *u8) } 71 else { fails=fails+1; hw("T4 FAIL\n" as *u8) } 72 73 // ---- T5 ANTI-HALLUCINATION ---- 74 ag_parse("a dragon with wings that breathes fire" as *u8) 75 let n5: i64 = ag_build() 76 let unmet5: i64 = ag_unmet() 77 hw(" 'a dragon with wings that breathes fire' -> plan="); pn(ag_plan()); hw(" parts="); pn(n5); hw(" HONEST unmet="); pn(unmet5); hw(" (wings/fire/breathe)\n" as *u8) 78 ag_parse("a shiny spaceship" as *u8) 79 let n6: i64 = ag_build() 80 hw(" 'a shiny spaceship' -> plan="); pn(ag_plan()); hw(" build="); pn(n6); hw(" (REFUSED = 0, no fake build)\n" as *u8) 81 var t5: i64 = 0 82 if n5 > 10 { if unmet5 >= 3 { if ag_plan() == 0-1 { if n6 == 0 { t5 = 1 } } } } 83 if t5 == 1 { hw("T5 PASS ANTI-HALLUCINATION: the dragon body built + 3 unmet features HONESTLY reported; the spaceship was REFUSED (no fake build) -- we never claim what we did not make\n" as *u8) } 84 else { fails=fails+1; hw("T5 FAIL\n" as *u8) } 85 86 // ---- T6 determinism ---- 87 ag_parse("a rabbit with long ears" as *u8) 88 let da: i64 = ag_build() 89 let pa: i64 = ba_sdf(74, 400, 268, 1) 90 ag_parse("a rabbit with long ears" as *u8) 91 let db: i64 = ag_build() 92 let pb: i64 = ba_sdf(74, 400, 268, 1) 93 var t6: i64 = 0 94 if da == db { if pa == pb { t6 = 1 } } 95 if t6 == 1 { hw("T6 PASS deterministic (same words -> same creature)\n" as *u8) } else { fails=fails+1; hw("T6 FAIL\n" as *u8) } 96 97 // ---- T7 evidence: three described creatures ---- 98 let W: i64 = 250 99 let H: i64 = 380 100 let GW: i64 = W*3 101 let gal: *i64 = sys_mmap(GW*H*8) as *i64 102 var i: i64 = 0 103 while i < GW*H { gal[i] = 24 + 26*256 + 34*65536; i = i + 1 } 104 let fb: *i64 = sys_mmap(W*H*8) as *i64 105 var slot: i64 = 0 106 while slot < 3 { 107 if slot == 0 { ag_parse("a rabbit with long ears" as *u8) } 108 if slot == 1 { ag_parse("a four-armed monster with horns and a tail" as *u8) } 109 if slot == 2 { ag_parse("a person" as *u8) } 110 ag_build() 111 atlas_render(fb, W, H, 700, 1, 0-1) 112 var yy: i64 = 0 113 while yy < H { 114 var xx: i64 = 0 115 while xx < W { gal[yy*GW + slot*W + xx] = fb[yy*W + xx]; xx = xx + 1 } 116 yy = yy + 1 117 } 118 slot = slot + 1 119 } 120 write_png(gal, GW, H, "knowledge/nx_authorgen.png" as *u8) 121 hw("T7 evidence -> knowledge/nx_authorgen.png (three creatures, each from a sentence)\n" as *u8) 122 123 if fails == 0 { hw("AUTHORGEN-GATE GREEN -- the Orca pattern, sovereign: describe a creature in words -> the engine builds + VALIDATES + deploys it; features toggle causally; unbuildable requests are HONESTLY reported/refused (anti-hallucination). Residual: a trained-LLM front-end (our no-float Qwen) for open vocabulary, more content types (worlds/rules), edit-existing, AI ops (crash-log auto-fix).\n" as *u8); sys_exit(0); return 0 } 124 hw("AUTHORGEN-GATE RED fails="); pn(fails); hw("\n" as *u8) 125 sys_exit(1) 126 return 1 127}