code wiki / _hdl_build / nx_vn_living_gate.nx

nx_vn_living_gate.nx source

↩ module page · 72 lines · 5169 B

1// nx_vn_living_gate.nx -- proves the "living but it tracks" limit. LIVING: a provider yields varied interaction 2// lines across seeds. TRACKS: the validator keeps every FINAL line on-canon (has the fact, never the forbidden) -- 3// and a ROGUE provider (an unbounded/hallucinating LLM that omits the fact or injects a plot-breaking claim) is 4// REJECTED, falling back to the authored canon line, so the story CANNOT be derailed. Provider-agnostic: the same 5// limit will bound a sovereign no-float LLM when it plugs in. Prints sample living lines so the result is visible. 6// license_tier: ORIGINAL expect_exit: 0 7import "nx_vn_living.nx" 8import "nx_syscalls.nx" 9 10func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11func wn(v: i64) -> i64 { var m: i64=v; if m<0{w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 } 12func streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 } 13 14func main(argc: i64, argv: *i64) -> i64 { 15 w("=== nx_vn_living_gate -- interactions LIVING (vary) but the story TRACKS (canon enforced vs any provider) ===\n" as *u8) 16 let fact: *u8 = "Mara" as *u8 17 let forbidden: *u8 = "ghost" as *u8 18 let authored: *u8 = "Mara, the keeper, meets your eyes. 'You came at last.'" as *u8 19 let acc: *i64 = sys_mmap(16) as *i64 20 let lines: *u8 = sys_mmap(8*512) 21 var pass: i64 = 0; var tot: i64 = 0 22 23 // T1 LIVING: good provider varies + every final line is on-canon + accepted 24 var distinct: i64 = 0; var oncanon: i64 = 0; var accepted: i64 = 0 25 var i: i64 = 0 26 while i < 8 { 27 let cur: *u8 = ((lines as i64) + i*512) as *u8 28 vl_interact(i, 1, fact, forbidden, authored, cur, acc) 29 if acc[0] == 1 { accepted = accepted + 1 } 30 if vl_ok(cur, fact, forbidden) == 1 { oncanon = oncanon + 1 } 31 var seenbefore: i64 = 0; var j: i64 = 0 32 while j < i { if streq(((lines as i64)+j*512) as *u8, cur) == 1 { seenbefore = 1 } j = j + 1 } 33 if seenbefore == 0 { distinct = distinct + 1 } 34 i = i + 1 35 } 36 w(" sample LIVING lines (good provider):\n" as *u8) 37 w(" - "); w(((lines as i64)+0*512) as *u8); w("\n" as *u8) 38 w(" - "); w(((lines as i64)+1*512) as *u8); w("\n" as *u8) 39 w(" - "); w(((lines as i64)+3*512) as *u8); w("\n" as *u8) 40 tot = tot + 1 41 if distinct >= 3 { if oncanon == 8 { if accepted == 8 { pass = pass + 1; w("PASS T1 LIVING: "); wn(distinct); w(" distinct lines, all 8 on-canon + accepted\n" as *u8) } else { w("FAIL T1 accepted="); wn(accepted); w("\n" as *u8) } } else { w("FAIL T1 oncanon="); wn(oncanon); w("\n" as *u8) } } else { w("FAIL T1 distinct="); wn(distinct); w("\n" as *u8) } 42 43 // T2 ROGUE REJECTED -> TRACKS: an unbounded provider that derails is caught; final lines stay on-canon 44 var rejected: i64 = 0; var finalcanon: i64 = 0 45 i = 0 46 while i < 8 { 47 let cur: *u8 = ((lines as i64) + i*512) as *u8 48 vl_interact(i, 2, fact, forbidden, authored, cur, acc) 49 if acc[0] == 0 { rejected = rejected + 1 } 50 if vl_ok(cur, fact, forbidden) == 1 { finalcanon = finalcanon + 1 } 51 i = i + 1 52 } 53 tot = tot + 1 54 if rejected >= 1 { if finalcanon == 8 { pass = pass + 1; w("PASS T2 TRACKS: rogue provider derailed "); wn(rejected); w("/8 -> rejected + fell back; ALL 8 final lines still on-canon (story unbreakable)\n" as *u8) } else { w("FAIL T2 finalcanon="); wn(finalcanon); w(" (a derail leaked through!)\n" as *u8) } } else { w("FAIL T2 rogue never rejected (validator not enforcing)\n" as *u8) } 55 56 // T3 the unconditional invariant: the validator itself rejects off-canon, accepts on-canon (anti-rubber-stamp) 57 tot = tot + 1; var ok3: i64 = 1 58 if vl_ok("Mara welcomes you warmly." as *u8, fact, forbidden) != 1 { ok3 = 0 } // on-canon -> accept 59 if vl_ok("A stranger welcomes you." as *u8, fact, forbidden) != 0 { ok3 = 0 } // missing fact -> reject 60 if vl_ok("Mara is secretly a ghost." as *u8, fact, forbidden) != 0 { ok3 = 0 } // forbidden -> reject 61 if ok3 == 1 { pass = pass + 1; w("PASS T3 the LIMIT is real: accepts on-canon, rejects missing-fact AND forbidden (not a rubber stamp)\n" as *u8) } else { w("FAIL T3\n" as *u8) } 62 63 // T4 sovereignty: living lines are plain text, no injected markup 64 tot = tot + 1; var ok4: i64 = 1 65 if vl_has(authored, "<script" as *u8) == 1 { ok4 = 0 } 66 if vl_has(((lines as i64)+0*512) as *u8, "src=" as *u8) == 1 { ok4 = 0 } 67 if ok4 == 1 { pass = pass + 1; w("PASS T4 sovereign: interaction lines are plain text, 0 third-party markup\n" as *u8) } else { w("FAIL T4\n" as *u8) } 68 69 w("nx_vn_living_gate pass="); wn(pass); w("/"); wn(tot) 70 if pass == tot { w(" verdict=GREEN (living interactions, bounded -- the story tracks vs ANY provider incl. a future sovereign LLM)\n" as *u8); sys_exit(0); return 0 } 71 w(" verdict=RED\n" as *u8); sys_exit(1); return 1 72}