code wiki / (root) / nx_research_report_gate.nx

nx_research_report_gate.nx source

↩ module page · 116 lines · 8495 B

1// nx_research_report_gate.nx -- liar-kill gate for S3 the GROUNDED REPORT WRITER. 2// TIER-1 (deterministic, $0, no model): assemble a sectioned, referenced Markdown report; then the report-level 3// grounding guarantee ACCEPTS a fully-cited body and REJECTS one with an uncited sentence or a dangling [5] 4// citation (nsrc=2). TIER-2 (marker knowledge/index/rp_model.on): synthesize each section with real Qwen and 5// emit the full report. license_tier: ORIGINAL 6import "nx_research_report.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 } 12 13func main() -> i64 { 14 var pass: i64 = 0 15 var total: i64 = 0 16 let out: *i64 = sys_mmap(64) as *i64 17 let out2: *i64 = sys_mmap(64) as *i64 18 let buf: *u8 = sys_mmap(8192) 19 20 let heads: *i64 = sys_mmap(8*8) as *i64 21 let bodies: *i64 = sys_mmap(8*8) as *i64 22 let srcs: *i64 = sys_mmap(8*8) as *i64 23 heads[0] = ("Location" as *u8) as i64 24 heads[1] = ("History" as *u8) as i64 25 bodies[0] = ("It stands in Paris [1]." as *u8) as i64 26 bodies[1] = ("It was completed in 1889 [2]." as *u8) as i64 27 srcs[0] = ("Wikipedia Eiffel Tower" as *u8) as i64 28 srcs[1] = ("Britannica Eiffel Tower" as *u8) as i64 29 30 // T1: assemble a structured, referenced Markdown report 31 total = total + 1 32 let n: i64 = rp_assemble("Eiffel Tower Report" as *u8, heads, bodies, 2, srcs, 2, buf, 8192) 33 var t1: i64 = 1 34 if rp_contains(buf, n, "# Eiffel Tower Report" as *u8) != 1 { t1 = 0 } 35 if rp_contains(buf, n, "## Location" as *u8) != 1 { t1 = 0 } 36 if rp_contains(buf, n, "## History" as *u8) != 1 { t1 = 0 } 37 if rp_contains(buf, n, "## References" as *u8) != 1 { t1 = 0 } 38 if rp_contains(buf, n, "[1] Wikipedia Eiffel Tower" as *u8) != 1 { t1 = 0 } 39 if rp_contains(buf, n, "[2] Britannica Eiffel Tower" as *u8) != 1 { t1 = 0 } 40 st_puts("T1 assemble: bytes=" as *u8); st_putn(n); st_puts(" ok=" as *u8); st_putn(t1); st_puts("\n" as *u8) 41 if t1 == 1 { pass = pass + 1 } else { st_puts("T1 FAIL assemble\n" as *u8) } 42 43 // T2: a fully-grounded body -- every sentence cited, all cites resolve -> grounded 44 total = total + 1 45 let bg: *u8 = "It stands in Paris [1]. It opened in 1889 [2]." as *u8 46 let g2: i64 = rp_report_grounded(bg, st_len(bg), 2, out) 47 st_puts("T2 grounded-good: sentences=" as *u8); st_putn(out[0]); st_puts(" uncited=" as *u8); st_putn(out[1]); st_puts(" dangling=" as *u8); st_putn(out[2]); st_puts(" grounded=" as *u8); st_putn(g2); st_puts("\n" as *u8) 48 if g2 == 1 { if out[0] == 2 { pass = pass + 1 } else { st_puts("T2 FAIL sentence-count\n" as *u8) } } else { st_puts("T2 FAIL not-grounded\n" as *u8) } 49 50 // T3 LIAR-KILL: an UNCITED sentence must make the report NOT grounded 51 total = total + 1 52 let bu: *u8 = "It stands in Paris [1]. It is very tall." as *u8 53 let g3: i64 = rp_report_grounded(bu, st_len(bu), 2, out) 54 st_puts("T3 uncited-caught: uncited=" as *u8); st_putn(out[1]); st_puts(" grounded=" as *u8); st_putn(g3); st_puts("\n" as *u8) 55 if g3 == 0 { if out[1] == 1 { pass = pass + 1 } else { st_puts("T3 FAIL uncited-count\n" as *u8) } } else { st_puts("T3 FAIL uncited-not-caught\n" as *u8) } 56 57 // T4 LIAR-KILL: a DANGLING citation [5] with only 2 sources must make the report NOT grounded 58 total = total + 1 59 let bd: *u8 = "It stands in Paris [5]." as *u8 60 let g4: i64 = rp_report_grounded(bd, st_len(bd), 2, out) 61 st_puts("T4 dangling-caught: dangling=" as *u8); st_putn(out[2]); st_puts(" grounded=" as *u8); st_putn(g4); st_puts("\n" as *u8) 62 if g4 == 0 { if out[2] == 1 { pass = pass + 1 } else { st_puts("T4 FAIL dangling-count\n" as *u8) } } else { st_puts("T4 FAIL dangling-not-caught\n" as *u8) } 63 64 // T5: determinism 65 total = total + 1 66 rp_report_grounded(bg, st_len(bg), 2, out) 67 rp_report_grounded(bg, st_len(bg), 2, out2) 68 var t5: i64 = 1 69 if out[0] != out2[0] { t5 = 0 } 70 if out[1] != out2[1] { t5 = 0 } 71 if out[2] != out2[2] { t5 = 0 } 72 if t5 == 1 { pass = pass + 1 } else { st_puts("T5 FAIL not-deterministic\n" as *u8) } 73 74 // T6: the 0.5B's ACTUAL "## History" output this session (citation-spam [1]..[14) -> cleanup makes it GROUNDED. 75 total = total + 1 76 let jhist: *u8 = "The Eiffel Tower was completed in 1889 for the World Fair. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14" as *u8 77 let jhl: i64 = st_len(jhist) 78 rp_report_grounded(jhist, jhl, 2, out) // BEFORE cleanup 79 let cbuf: *u8 = sys_mmap(2048) 80 let chl: i64 = rp_clean_body(jhist, jhl, 2, cbuf, 2048) 81 let g6: i64 = rp_report_grounded(cbuf, chl, 2, out2) // AFTER cleanup 82 st_puts("T6 real-junk History: BEFORE dangling=" as *u8); st_putn(out[2]); st_puts(" -> cleaned=[" as *u8); sys_write(1, cbuf, chl); st_puts("] AFTER grounded=" as *u8); st_putn(g6); st_puts(" dangling=" as *u8); st_putn(out2[2]); st_puts("\n" as *u8) 83 if out[2] >= 1 { if g6 == 1 { if out2[2] == 0 { pass = pass + 1 } else { st_puts("T6 FAIL still-dangling\n" as *u8) } } else { st_puts("T6 FAIL not-grounded-after\n" as *u8) } } else { st_puts("T6 FAIL junk-not-dangling\n" as *u8) } 84 85 // T7: the 0.5B's ACTUAL "## Location" output. Cleanup strips the spam AND a FABRICATED [3] (only 2 sources); 86 // the claim that cited [3] is then correctly flagged UNGROUNDED -- the system REFUSES to launder a fake citation. 87 total = total + 1 88 let jloc: *u8 = "[1] The Eiffel Tower stands in Paris, the capital of France. [2] The Eiffel Tower was completed in 1889 for the World Fair. [3] The Eiffel Tower is located in Paris, the capital of France. [4] The Eiffel Tower" as *u8 89 let jll: i64 = st_len(jloc) 90 let cbuf2: *u8 = sys_mmap(2048) 91 let cll: i64 = rp_clean_body(jloc, jll, 2, cbuf2, 2048) 92 let g7: i64 = rp_report_grounded(cbuf2, cll, 2, out) 93 st_puts("T7 real-junk Location: cleaned=[" as *u8); sys_write(1, cbuf2, cll); st_puts("] grounded=" as *u8); st_putn(g7); st_puts(" uncited=" as *u8); st_putn(out[1]); st_puts(" dangling=" as *u8); st_putn(out[2]); st_puts(" (HONEST: fake [3] stripped -> its claim left uncited -> NOT certified)\n" as *u8) 94 if out[2] == 0 { if g7 == 0 { if out[1] == 1 { pass = pass + 1 } else { st_puts("T7 FAIL uncited-count\n" as *u8) } } else { st_puts("T7 FAIL should-be-ungrounded\n" as *u8) } } else { st_puts("T7 FAIL cleanup-left-dangling\n" as *u8) } 95 96 // T8 (marker-gated): REAL multi-section report via Qwen -- HONEST criterion: the emitted report must be GROUNDED. 97 let mk: i64 = sys_openat_rd("knowledge/index/rp_model.on" as *u8) 98 if mk >= 0 { 99 sys_close(mk) 100 total = total + 1 101 let qs: *i64 = sys_mmap(8*8) as *i64 102 qs[0] = ("In what city is the Eiffel Tower?" as *u8) as i64 103 qs[1] = ("When was the Eiffel Tower completed?" as *u8) as i64 104 let rsrcs: *i64 = sys_mmap(8*8) as *i64 105 rsrcs[0] = ("The Eiffel Tower stands in Paris, the capital of France." as *u8) as i64 106 rsrcs[1] = ("The Eiffel Tower was completed in 1889 for the World Fair." as *u8) as i64 107 let rn: i64 = rp_report("Eiffel Tower" as *u8, heads, qs, 2, rsrcs, 2, buf, 8192, out) 108 st_puts("T8 MODEL report bytes=" as *u8); st_putn(rn); st_puts(" sentences=" as *u8); st_putn(out[0]); st_puts(" uncited=" as *u8); st_putn(out[1]); st_puts(" dangling=" as *u8); st_putn(out[2]); st_puts("\n---REPORT---\n" as *u8); if rn > 0 { sys_write(1, buf, rn) } st_puts("\n---END---\n" as *u8) 109 if rn > 0 { if out[1] == 0 { if out[2] == 0 { pass = pass + 1 } else { st_puts("T8 FAIL report-has-dangling\n" as *u8) } } else { st_puts("T8 FAIL report-has-uncited\n" as *u8) } } else { st_puts("T8 FAIL empty\n" as *u8) } 110 } else { st_puts("T8 SKIP (no rp_model.on; assembly+grounding+cleanup proven on REAL junk in T6/T7; model path honest-gated)\n" as *u8) } 111 112 st_puts("RESEARCH-REPORT " as *u8); st_putn(pass); st_puts("/" as *u8); st_putn(total); st_puts("\n" as *u8) 113 if pass == total { st_puts("RESEARCH-REPORT ALL-PASS\n" as *u8); sys_exit(0) } 114 sys_exit(1) 115 return 1 116}