code wiki / _hdl_build / nx_vn_living_gate.nx
nx_vn_living_gate.nx source
↩ module page · 80 lines · 5546 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"
9import "nx_gate_verdict.nx"
10
11func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
12func 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 }
13func 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 }
14
15func main(argc: i64, argv: *i64) -> i64 {
16 w("=== nx_vn_living_gate -- interactions LIVING (vary) but the story TRACKS (canon enforced vs any provider) ===\n" as *u8)
17 let fact: *u8 = "Mara" as *u8
18 let forbidden: *u8 = "ghost" as *u8
19 let authored: *u8 = "Mara, the keeper, meets your eyes. 'You came at last.'" as *u8
20 let acc: *i64 = sys_mmap(16) as *i64
21 let lines: *u8 = sys_mmap(8*512)
22 var pass: i64 = 0; var tot: i64 = 0
23
24 // T1 LIVING: good provider varies + every final line is on-canon + accepted
25 var distinct: i64 = 0; var oncanon: i64 = 0; var accepted: i64 = 0
26 var i: i64 = 0
27 while i < 8 {
28 let cur: *u8 = ((lines as i64) + i*512) as *u8
29 vl_interact(i, 1, fact, forbidden, authored, cur, acc)
30 if acc[0] == 1 { accepted = accepted + 1 }
31 if vl_ok(cur, fact, forbidden) == 1 { oncanon = oncanon + 1 }
32 var seenbefore: i64 = 0; var j: i64 = 0
33 while j < i { if streq(((lines as i64)+j*512) as *u8, cur) == 1 { seenbefore = 1 } j = j + 1 }
34 if seenbefore == 0 { distinct = distinct + 1 }
35 i = i + 1
36 }
37 w(" sample LIVING lines (good provider):\n" as *u8)
38 w(" - "); w(((lines as i64)+0*512) as *u8); w("\n" as *u8)
39 w(" - "); w(((lines as i64)+1*512) as *u8); w("\n" as *u8)
40 w(" - "); w(((lines as i64)+3*512) as *u8); w("\n" as *u8)
41 tot = tot + 1
42 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) }
43
44 // T2 ROGUE REJECTED -> TRACKS: an unbounded provider that derails is caught; final lines stay on-canon
45 var rejected: i64 = 0; var finalcanon: i64 = 0
46 i = 0
47 while i < 8 {
48 let cur: *u8 = ((lines as i64) + i*512) as *u8
49 vl_interact(i, 2, fact, forbidden, authored, cur, acc)
50 if acc[0] == 0 { rejected = rejected + 1 }
51 if vl_ok(cur, fact, forbidden) == 1 { finalcanon = finalcanon + 1 }
52 i = i + 1
53 }
54 tot = tot + 1
55 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) }
56
57 // T3 the unconditional invariant: the validator itself rejects off-canon, accepts on-canon (anti-rubber-stamp)
58 tot = tot + 1; var ok3: i64 = 1
59 if vl_ok("Mara welcomes you warmly." as *u8, fact, forbidden) != 1 { ok3 = 0 } // on-canon -> accept
60 if vl_ok("A stranger welcomes you." as *u8, fact, forbidden) != 0 { ok3 = 0 } // missing fact -> reject
61 if vl_ok("Mara is secretly a ghost." as *u8, fact, forbidden) != 0 { ok3 = 0 } // forbidden -> reject
62 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) }
63
64 // T4 sovereignty: living lines are plain text, no injected markup
65 tot = tot + 1; var ok4: i64 = 1
66 if vl_has(authored, "<script" as *u8) == 1 { ok4 = 0 }
67 if vl_has(((lines as i64)+0*512) as *u8, "src=" as *u8) == 1 { ok4 = 0 }
68 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) }
69
70 w("nx_vn_living_gate pass="); wn(pass); w("/"); wn(tot)
71 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
72 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
73 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
74 let ctr__dry: *i64 = gv_ctr()
75 ctr__dry[0] = pass
76 ctr__dry[1] = tot
77 let rc__dry: i64 = gv_verdict("VN-LIVING-GATE" as *u8, ctr__dry, "living interactions, bounded -- the story tracks vs ANY provider incl. a future sovereign LLM)" as *u8)
78 sys_exit(rc__dry)
79 return rc__dry
80}