code wiki / (root) / nx_research_unified_gate.nx

nx_research_unified_gate.nx source

↩ module page · 146 lines · 9056 B

1// nx_research_unified_gate.nx -- liar-kill gate for the UNIFIED sovereign researcher (S1+S2+S3+S4 -> one verdict). 2// TIER-1 (deterministic, $0): nxr_assess grades fixture report bodies and shows the VERDICT: 3// PUBLISH (grounded + numbers confirmed), CONTINUE (a fabricated number / uncited claim -> investigate again), 4// STOP-INCOMPLETE (gaps remain but budget spent -> ship honestly). TIER-2 (marker knowledge/index/nxr_model.on): 5// the full nxr_research pipeline with real Qwen. license_tier: ORIGINAL 6import "nx_research_unified.nx" 7import "nx_syscalls.nx" 8 9func st_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 10func st_putn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); 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; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 } 11func st_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 12func st_verdict(v: i64) -> i64 { 13 if v == 0 { st_puts("PUBLISH" as *u8) } 14 if v == 1 { st_puts("CONTINUE" as *u8) } 15 if v == 2 { st_puts("STOP-INCOMPLETE" as *u8) } 16 return 0 17} 18func st_row(tag: *u8, out: *i64) -> i64 { 19 st_puts(tag) 20 st_puts(" grounded_sents=" as *u8); st_putn(out[0] - out[1]) 21 st_puts(" uncited=" as *u8); st_putn(out[1]) 22 st_puts(" dangling=" as *u8); st_putn(out[2]) 23 st_puts(" numeric=" as *u8); st_putn(out[3]) 24 st_puts(" confirmed=" as *u8); st_putn(out[4]) 25 st_puts(" discredited=" as *u8); st_putn(out[5]) 26 st_puts(" gaps=" as *u8); st_putn(out[6]) 27 st_puts(" -> VERDICT=" as *u8); st_verdict(out[8]) 28 st_puts("\n" as *u8) 29 return 0 30} 31 32func main() -> i64 { 33 var pass: i64 = 0 34 var total: i64 = 0 35 let out: *i64 = sys_mmap(128) as *i64 36 let out2: *i64 = sys_mmap(128) as *i64 37 38 let srcv: *i64 = sys_mmap(8*8) as *i64 39 srcv[0] = ("The Eiffel Tower stands in Paris, the capital of France." as *u8) as i64 40 srcv[1] = ("Human performance reaches an F1 of 86.8 percent." as *u8) as i64 41 42 // T1 PUBLISH: fully grounded, the numeric claim (86.8) confirmed against source 2 -> 0 gaps -> PUBLISH 43 total = total + 1 44 let b_pub: *u8 = "The tower stands in Paris [1]. Human performance is 86.8 [2]." as *u8 45 nxr_assess(b_pub, st_len(b_pub), srcv, 2, 0, 3, 1000000, out) 46 st_row("T1 PUBLISH " as *u8, out) 47 if out[8] == 0 { if out[6] == 0 { pass = pass + 1 } else { st_puts("T1 FAIL gaps\n" as *u8) } } else { st_puts("T1 FAIL verdict\n" as *u8) } 48 49 // T2 CONTINUE: a FABRICATED number (50.0 not in the cited source) -> discredited -> gaps=1, budget left -> CONTINUE 50 total = total + 1 51 let b_bad: *u8 = "The tower stands in Paris [1]. Human performance is 50.0 [2]." as *u8 52 nxr_assess(b_bad, st_len(b_bad), srcv, 2, 0, 3, 1000000, out) 53 st_row("T2 CONTINUE " as *u8, out) 54 if out[8] == 1 { if out[5] == 1 { pass = pass + 1 } else { st_puts("T2 FAIL discredited\n" as *u8) } } else { st_puts("T2 FAIL verdict\n" as *u8) } 55 56 // T3 STOP-INCOMPLETE: same fabricated-number report but the budget is spent (iter 2 of 3) -> ship honestly 57 total = total + 1 58 nxr_assess(b_bad, st_len(b_bad), srcv, 2, 2, 3, 3, out) 59 st_row("T3 STOP-INC " as *u8, out) 60 if out[8] == 2 { pass = pass + 1 } else { st_puts("T3 FAIL verdict\n" as *u8) } 61 62 // T4 CONTINUE (uncited claim): an uncited sentence -> gaps>=1 -> CONTINUE 63 total = total + 1 64 let b_unc: *u8 = "The tower stands in Paris [1]. It is very old today." as *u8 65 nxr_assess(b_unc, st_len(b_unc), srcv, 2, 0, 3, 1000000, out) 66 st_row("T4 CONTINUE " as *u8, out) 67 if out[1] >= 1 { if out[8] == 1 { pass = pass + 1 } else { st_puts("T4 FAIL verdict\n" as *u8) } } else { st_puts("T4 FAIL uncited\n" as *u8) } 68 69 // T5 determinism 70 total = total + 1 71 nxr_assess(b_pub, st_len(b_pub), srcv, 2, 0, 3, 1000000, out) 72 nxr_assess(b_pub, st_len(b_pub), srcv, 2, 0, 3, 1000000, out2) 73 var t5: i64 = 1 74 if out[6] != out2[6] { t5 = 0 } 75 if out[8] != out2[8] { t5 = 0 } 76 if t5 == 1 { pass = pass + 1 } else { st_puts("T5 FAIL not-deterministic\n" as *u8) } 77 78 // T6 CORROBORATION AXIS (nx_research_crossval integration): the same value carried by >=2 distinct-origin 79 // sources -> out[9]=1; carried only by its cited source -> out[9]=0 (single-source is honest, not inflated). 80 total = total + 1 81 let srcv3: *i64 = sys_mmap(8*8) as *i64 82 srcv3[0] = ("The Eiffel Tower stands in Paris, the capital of France." as *u8) as i64 83 srcv3[1] = ("Human performance reaches an F1 of 86.8 percent." as *u8) as i64 84 srcv3[2] = ("An independent replication also measured 86.8 for humans." as *u8) as i64 85 let b_cor: *u8 = "Human performance is 86.8 [2]." as *u8 86 nxr_assess(b_cor, st_len(b_cor), srcv3, 3, 0, 3, 1000000, out) // origins 2+3 both carry 86.8 87 nxr_assess(b_cor, st_len(b_cor), srcv, 2, 0, 3, 1000000, out2) // only the cited source carries it 88 st_puts("T6 corrob: 3src confirmed=" as *u8); st_putn(out[4]); st_puts(" corroborated=" as *u8); st_putn(out[9]); st_puts(" | 2src corroborated=" as *u8); st_putn(out2[9]); st_puts("\n" as *u8) 89 var t6: i64 = 1 90 if out[4] != 1 { t6 = 0 } 91 if out[9] != 1 { t6 = 0 } 92 if out2[9] != 0 { t6 = 0 } 93 if t6 == 1 { pass = pass + 1 } else { st_puts("T6 FAIL corroboration\n" as *u8) } 94 95 // T7 LIAR-KILL (citation laundering): claim cites [1] (which carries NO number) while 2 OTHER sources carry 96 // the value -> confirmed=0 AND corroborated=0. Corroboration must never launder a bad citation. 97 total = total + 1 98 let b_mis: *u8 = "Human performance is 86.8 [1]." as *u8 99 nxr_assess(b_mis, st_len(b_mis), srcv3, 3, 0, 3, 1000000, out) 100 st_puts("T7 mis-cite: confirmed=" as *u8); st_putn(out[4]); st_puts(" corroborated=" as *u8); st_putn(out[9]); st_puts(" (2 non-cited carriers give NO credit)\n" as *u8) 101 var t7: i64 = 1 102 if out[4] != 0 { t7 = 0 } 103 if out[9] != 0 { t7 = 0 } 104 if t7 == 1 { pass = pass + 1 } else { st_puts("T7 FAIL cite-laundering\n" as *u8) } 105 106 // T8 REGRESSION-GUARD (why host ids matter): a same-origin pair -- 2 sources carrying the value from the SAME 107 // real host. nxr_assess (index-as-host default) OVER-CREDITS corroborated=1; nxr_assess_hosts (real host ids, 108 // both = same id) correctly says corroborated=0. Locks the exact caveat cvx_host_id fixes (proves the BUG, 109 // complementing crossval T13 which proves the FIX). 110 total = total + 1 111 let svp: *i64 = sys_mmap(8*8) as *i64 112 svp[0] = ("Human performance reaches an F1 of 86.8 percent." as *u8) as i64 113 svp[1] = ("A mirror of the same page also lists 86.8 for humans." as *u8) as i64 114 let hs: *i64 = sys_mmap(8*8) as *i64 115 hs[0] = 777; hs[1] = 777 // SAME real origin (two paths, one host) 116 let b_pair: *u8 = "Human performance is 86.8 [1]." as *u8 117 nxr_assess(b_pair, st_len(b_pair), svp, 2, 0, 3, 1000000, out) // index-as-host default: over-credits 118 nxr_assess_hosts(b_pair, st_len(b_pair), svp, 2, hs, 0, 3, 1000000, out2) // host-TRUE: echo-suppressed 119 st_puts("T8 host-guard: index corroborated=" as *u8); st_putn(out[9]); st_puts(" (over-credit) vs host-TRUE corroborated=" as *u8); st_putn(out2[9]); st_puts("\n" as *u8) 120 var t8: i64 = 1 121 if out[9] != 1 { t8 = 0 } 122 if out2[9] != 0 { t8 = 0 } 123 if t8 == 1 { pass = pass + 1 } else { st_puts("T8 FAIL host-guard\n" as *u8) } 124 125 // T9 (marker-gated): the FULL pipeline with real Qwen (synthesize 2 sections -> grounded report -> verdict) 126 let mk: i64 = sys_openat_rd("knowledge/index/nxr_model.on" as *u8) 127 if mk >= 0 { 128 sys_close(mk) 129 total = total + 1 130 let heads: *i64 = sys_mmap(8*8) as *i64 131 heads[0] = ("Location" as *u8) as i64 132 heads[1] = ("Human performance" as *u8) as i64 133 let qs: *i64 = sys_mmap(8*8) as *i64 134 qs[0] = ("In what city is the Eiffel Tower?" as *u8) as i64 135 qs[1] = ("What F1 does human performance reach?" as *u8) as i64 136 let buf: *u8 = sys_mmap(8192) 137 let rn: i64 = nxr_research("Research Brief" as *u8, heads, qs, 2, srcv, 2, buf, 8192, out) 138 st_puts("T9 MODEL pipeline bytes=" as *u8); st_putn(rn); st_puts(" -> VERDICT=" as *u8); st_verdict(out[8]); st_puts(" (gaps=" as *u8); st_putn(out[6]); st_puts(" corroborated=" as *u8); st_putn(out[9]); st_puts(")\n---REPORT---\n" as *u8); if rn > 0 { sys_write(1, buf, rn) } st_puts("\n---END---\n" as *u8) 139 if rn > 0 { pass = pass + 1 } else { st_puts("T9 FAIL empty\n" as *u8) } 140 } else { st_puts("T9 SKIP (no nxr_model.on; unified assess+verdict+corroboration+host-guard proven $0 in T1-T8)\n" as *u8) } 141 142 st_puts("NX-RESEARCH-UNIFIED " as *u8); st_putn(pass); st_puts("/" as *u8); st_putn(total); st_puts("\n" as *u8) 143 if pass == total { st_puts("NX-RESEARCH-UNIFIED ALL-PASS\n" as *u8); sys_exit(0) } 144 sys_exit(1) 145 return 1 146}