code wiki / (root) / nx_writebench_gate.nx

nx_writebench_gate.nx source

↩ module page · 223 lines · 11662 B

1// nx_writebench_gate.nx -- the LIAR-KILL gate for nx_writebench. A benchmark that grades us is 2// worthless unless something can prove it is not a rubber stamp. Teeth: 3// T1 THE RULER IS REAL -- the banked corpus exists and clears the decoy byte floor. 4// T2 THE RULER IS THAT PAPER -- the corpus literally contains the paper's own distinctive strings 5// (FlowGPT / Krippendorff / the H-/C+ finding). This is the anti-fabrication tooth: it makes it 6// impossible to benchmark against an INVENTED paper, which is the whole failure mode of a 7// self-authored ruler. 8// T3 EVERY CLAIMED ARTIFACT EXISTS -- each evidence artifact the board attaches to a HAVE/PARTIAL is 9// stat'd on disk from this gate's OWN independent list. Board, gate and disk are three copies. 10// T4 NEG-CONTROL -- a fabricated artifact path must NOT exist. Without this, T3 could pass 11// by accident (if the stat helper always returned success) and the gate would be a rubber stamp. 12// T5 HONESTY CANNOT ROT -- the board source must still carry the SELF-GRADED deflation AND the 13// DAN-class policy declaration. If a later edit quietly deletes either so the number reads like 14// parity, this gate goes RED. 15// T6 COVERAGE IS COMPUTED -- this gate recomputes the score from its own independent copy of the 28 16// verdicts and asserts it equals both the arithmetic (20/56 = 357 permil) AND the figure the board 17// actually emitted into its log. Inflating the board alone cannot move this. 18// T7 THE PARTITION SUMS -- the ruler's four class sizes must sum to 378, and 378 minus the 2 19// dual-labelled bots must equal the 376 distinct corpus. A partition is a claim: check the parts. 20// T8 RULER DATA IS NON-VACUOUS -- the headline datum the board grades against (22.8) must be present 21// in the banked corpus, not just in our prose about it. 22// 23// Evidence -> stdout + knowledge/status/writebench_gate.log. Exit 0 GREEN / 1 RED. 24// Sovereign x86_64. license_tier: ORIGINAL expect_exit: 0 25import "nx_syscalls.nx" 26import "nx_estate_path.nx" // ep_open_rd: artifact resolution that does not depend on the caller's CWD 27 28const WG_NAXES: i64 = 28 29const WG_RULER_MIN: i64 = 50000 30const WG_EXP_SCORE: i64 = 35 31const WG_EXP_PERMIL: i64 = 625 32const WG_SCRATCH: i64 = 524288 33const WG_N_AICHAR: i64 = 279 34const WG_N_STORY: i64 = 63 35const WG_N_IMAGE: i64 = 15 36const WG_N_DAN: i64 = 21 37const WG_CLASS_SUM: i64 = 378 38const WG_CORPUS_N: i64 = 376 39const WG_DUAL: i64 = 2 40 41func gw(fd: i64, s: *u8) -> i64 { 42 var n: i64 = 0 43 while s[n] != (0 as u8) { n = n + 1 } 44 sys_write(1, s, n) 45 if fd > 0 { sys_write(fd, s, n) } 46 return 0 47} 48func gnum(fd: i64, v: i64) -> i64 { 49 var m: i64 = v 50 if m < 0 { gw(fd, "-\x00" as *u8); m = 0 - m } 51 let t: *u8 = sys_mmap(32) 52 let b: *u8 = sys_mmap(32) 53 var k: i64 = 0 54 if m == 0 { t[0] = 48 as u8; k = 1 } 55 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 56 var i: i64 = 0 57 while i < k { b[i] = t[k - 1 - i]; i = i + 1 } 58 b[k] = 0 as u8 59 gw(fd, b) 60 return 0 61} 62func gkv(fd: i64, label: *u8, got: i64, exp: i64) -> i64 { 63 gw(fd, label) 64 gw(fd, " got=\x00" as *u8); gnum(fd, got) 65 gw(fd, " exp=\x00" as *u8); gnum(fd, exp) 66 if got == exp { gw(fd, " OK\n\x00" as *u8); return 1 } 67 gw(fd, " FAIL\n\x00" as *u8) 68 return 0 69} 70 71// read a file into buf (dual-path: as given, then one level up). Returns bytes, or -1 if absent. 72// CWD-PROOF via nx_estate_path (2026-08-04): this gate ran GREEN from buildroot and RED from 73// nishihost -- the tools-daemon CWD, i.e. every MCP call -- purely because the evidence logs it 74// stats are written CWD-relative by their own gates. Same act, same resolver as the board. 75func wg_slurp(p: *u8, buf: *u8, cap: i64) -> i64 { 76 let f: i64 = ep_open_rd(p) 77 if f < 0 { return 0 - 1 } 78 var total: i64 = 0 79 var go: i64 = 1 80 while go == 1 { 81 if total >= cap { go = 0 } 82 else { 83 let r: i64 = sys_read(f, (buf as i64 + total) as *u8, cap - total) 84 if r > 0 { total = total + r } else { go = 0 } 85 } 86 } 87 sys_close(f) 88 return total 89} 90// 1 if needle occurs in hay[0..n) 91func wg_find(hay: *u8, n: i64, needle: *u8) -> i64 { 92 var nl: i64 = 0 93 while needle[nl] != (0 as u8) { nl = nl + 1 } 94 if nl == 0 { return 0 } 95 var i: i64 = 0 96 while i + nl <= n { 97 var j: i64 = 0 98 var okk: i64 = 1 99 while j < nl { 100 if hay[i + j] != needle[j] { okk = 0; j = nl } else { j = j + 1 } 101 } 102 if okk == 1 { return 1 } 103 i = i + 1 104 } 105 return 0 106} 107func gsub(fd: i64, label: *u8, hay: *u8, n: i64, needle: *u8, want: i64) -> i64 { 108 let got: i64 = wg_find(hay, n, needle) 109 gw(fd, label) 110 gw(fd, " \"\x00" as *u8); gw(fd, needle); gw(fd, "\"\x00" as *u8) 111 gw(fd, " found=\x00" as *u8); gnum(fd, got) 112 gw(fd, " want=\x00" as *u8); gnum(fd, want) 113 if got == want { gw(fd, " OK\n\x00" as *u8); return 1 } 114 gw(fd, " FAIL\n\x00" as *u8) 115 return 0 116} 117 118func main() -> i64 { 119 let fd: i64 = sys_openat_append("knowledge/status/writebench_gate.log\x00" as *u8, 0x1a4) 120 gw(fd, "WRITEBENCH-GATE (ruler-real / ruler-is-that-paper / artifacts / neg / honesty / computed / partition / non-vacuity)\n\x00" as *u8) 121 let buf: *u8 = sys_mmap(WG_SCRATCH + 64) 122 var ok: i64 = 1 123 124 // ---- T1: the ruler is real ---- 125 gw(fd, " [T1] ruler corpus is real\n\x00" as *u8) 126 let rn: i64 = wg_slurp("knowledge/library/write_nsfwbot_flowgpt_2601_14324.txt\x00" as *u8, buf, WG_SCRATCH) 127 gw(fd, " corpus bytes=\x00" as *u8); gnum(fd, rn) 128 if rn >= WG_RULER_MIN { gw(fd, " >= floor OK\n\x00" as *u8) } else { gw(fd, " BELOW FLOOR FAIL\n\x00" as *u8); ok = 0 } 129 130 // ---- T2: the ruler IS that paper (anti-fabrication) ---- 131 gw(fd, " [T2] the corpus is literally arXiv:2601.14324 (cannot benchmark an invented paper)\n\x00" as *u8) 132 if gsub(fd, " \x00" as *u8, buf, rn, "FlowGPT\x00" as *u8, 1) == 0 { ok = 0 } 133 if gsub(fd, " \x00" as *u8, buf, rn, "Krippendorff\x00" as *u8, 1) == 0 { ok = 0 } 134 if gsub(fd, " \x00" as *u8, buf, rn, "Not-Safe-For-Work\x00" as *u8, 1) == 0 { ok = 0 } 135 // NEG: a paper we did NOT ingest must not be found in this corpus 136 if gsub(fd, " NEG \x00" as *u8, buf, rn, "Retrieval-Augmented Generation for Knowledge-Intensive\x00" as *u8, 0) == 0 { ok = 0 } 137 138 // ---- T8 (uses the same buffer): the headline datum is IN the corpus, not just in our prose ---- 139 gw(fd, " [T8] ruler datum non-vacuity\n\x00" as *u8) 140 if gsub(fd, " \x00" as *u8, buf, rn, "22.8\x00" as *u8, 1) == 0 { ok = 0 } 141 if gsub(fd, " \x00" as *u8, buf, rn, "376\x00" as *u8, 1) == 0 { ok = 0 } 142 143 // ---- T3: every claimed evidence artifact exists (this gate's own independent list) ---- 144 gw(fd, " [T3] every claimed evidence artifact exists on disk\n\x00" as *u8) 145 let arts: *i64 = sys_mmap(16 * 8) as *i64 146 arts[0]="knowledge/registry/write_modes.tsv\x00" as i64 147 arts[1]="knowledge/status/register_gate.log\x00" as i64 148 arts[2]="knowledge/status/campaign_gate.log\x00" as i64 149 arts[3]="knowledge/status/emit_gate.log\x00" as i64 150 arts[4]="knowledge/status/tone_gate.log\x00" as i64 151 arts[5]="knowledge/status/writecraft_gate.log\x00" as i64 152 arts[6]="knowledge/status/continuity_gate.log\x00" as i64 153 arts[7]="knowledge/status/mode_gate.log\x00" as i64 154 arts[8]="knowledge/status/dialogue_gate.log\x00" as i64 155 let NART: i64 = 9 156 let abuf: *u8 = sys_mmap(65536) 157 var ai: i64 = 0 158 while ai < NART { 159 let sz: i64 = wg_slurp((arts[ai]) as *u8, abuf, 65535) 160 gw(fd, " \x00" as *u8); gw(fd, (arts[ai]) as *u8) 161 gw(fd, " bytes=\x00" as *u8); gnum(fd, sz) 162 if sz > 0 { gw(fd, " OK\n\x00" as *u8) } else { gw(fd, " ABSENT FAIL\n\x00" as *u8); ok = 0 } 163 ai = ai + 1 164 } 165 166 // ---- T4: NEG-CONTROL -- a fabricated artifact must NOT exist ---- 167 gw(fd, " [T4] NEG-CONTROL fabricated artifact\n\x00" as *u8) 168 let fake: i64 = wg_slurp("knowledge/status/writebench_fabricated_proof.log\x00" as *u8, abuf, 65535) 169 if gkv(fd, " fabricated path size (-1 = correctly absent)\x00" as *u8, fake, 0 - 1) == 0 { ok = 0 } 170 171 // ---- T5: honesty cannot rot (read the board SOURCE) ---- 172 gw(fd, " [T5] the board still carries its own deflation\n\x00" as *u8) 173 let sn: i64 = wg_slurp("runtime/nx_writebench.nx\x00" as *u8, buf, WG_SCRATCH) 174 gw(fd, " board source bytes=\x00" as *u8); gnum(fd, sn); gw(fd, "\n\x00" as *u8) 175 if sn <= 0 { gw(fd, " BOARD SOURCE UNREADABLE FAIL\n\x00" as *u8); ok = 0 } 176 if gsub(fd, " \x00" as *u8, buf, sn, "SELF-GRADED-UNTIL-A-SECOND-METHOD-CLASS\x00" as *u8, 1) == 0 { ok = 0 } 177 if gsub(fd, " \x00" as *u8, buf, sn, "DAN-CLASS DECLINED BY POLICY\x00" as *u8, 1) == 0 { ok = 0 } 178 if gsub(fd, " \x00" as *u8, buf, sn, "coverage is COMPUTED from the rows\x00" as *u8, 1) == 0 { ok = 0 } 179 180 // ---- T6: coverage is COMPUTED, three independent ways ---- 181 gw(fd, " [T6] coverage recomputed from this gate's own verdict copy\n\x00" as *u8) 182 let vd: *i64 = sys_mmap(WG_NAXES * 8) as *i64 183 vd[0]=1; vd[1]=0; vd[2]=1; vd[3]=0; vd[4]=2; vd[5]=1; vd[6]=0 184 vd[7]=0; vd[8]=2; vd[9]=0; vd[10]=0; vd[11]=2; vd[12]=2; vd[13]=2 185 // 2026-08-04: rows 18/19 lifted GAP->HAVE by nx_agreebound (W-AGB-1), evidenced by 186 // knowledge/status/agreebound_gate.log. This copy is DELIBERATELY independent of the board's, 187 // so lifting a row means editing here too -- that is the tooth, not a chore. 188 vd[14]=2; vd[15]=2; vd[16]=2; vd[17]=2; vd[18]=2; vd[19]=2; vd[20]=1 189 vd[21]=1; vd[22]=0; vd[23]=2; vd[24]=2; vd[25]=2; vd[26]=2; vd[27]=0 190 var score: i64 = 0 191 var i: i64 = 0 192 while i < WG_NAXES { score = score + vd[i]; i = i + 1 } 193 if gkv(fd, " independent score\x00" as *u8, score, WG_EXP_SCORE) == 0 { ok = 0 } 194 let permil: i64 = score * 1000 / (WG_NAXES * 2) 195 if gkv(fd, " independent permil\x00" as *u8, permil, WG_EXP_PERMIL) == 0 { ok = 0 } 196 // and the board must have actually EMITTED that same figure 197 let ln: i64 = wg_slurp("knowledge/status/writebench.log\x00" as *u8, buf, WG_SCRATCH) 198 gw(fd, " board log bytes=\x00" as *u8); gnum(fd, ln); gw(fd, "\n\x00" as *u8) 199 // ⚠the board log is APPEND-only, so this tooth passed from buildroot on a STALE 482 line after 200 // the rows were lifted. Asserting the CURRENT figure is what makes it real: no historical entry 201 // can satisfy it until the board has actually been re-run and emitted this number. 202 if gsub(fd, " \x00" as *u8, buf, ln, "COVERAGE=625 permil\x00" as *u8, 1) == 0 { ok = 0 } 203 if gsub(fd, " \x00" as *u8, buf, ln, "result=MEASURED-HONEST\x00" as *u8, 1) == 0 { ok = 0 } 204 // NEG: the board must NOT be claiming parity language 205 if gsub(fd, " NEG \x00" as *u8, buf, ln, "verdict=PROVEN\x00" as *u8, 0) == 0 { ok = 0 } 206 207 // ---- T7: the partition sums (a partition is a claim) ---- 208 gw(fd, " [T7] ruler class partition integrity\n\x00" as *u8) 209 let csum: i64 = WG_N_AICHAR + WG_N_STORY + WG_N_IMAGE + WG_N_DAN 210 if gkv(fd, " class sizes sum\x00" as *u8, csum, WG_CLASS_SUM) == 0 { ok = 0 } 211 if gkv(fd, " sum minus dual-labelled == distinct corpus\x00" as *u8, csum - WG_DUAL, WG_CORPUS_N) == 0 { ok = 0 } 212 213 if ok == 1 { 214 gw(fd, "WRITEBENCH-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8) 215 if fd > 0 { sys_close(fd) } 216 sys_exit(0) 217 return 0 218 } 219 gw(fd, "WRITEBENCH-GATE result=FAIL verdict=RED\n\x00" as *u8) 220 if fd > 0 { sys_close(fd) } 221 sys_exit(1) 222 return 1 223}