code wiki / _hdl_build / nx_cms_wp_scorecard.nx

nx_cms_wp_scorecard.nx source

↩ module page · 186 lines · 8382 B

1// nx_cms_wp_scorecard.nx -- W0: the EXCEED-WORDPRESS scorecard (mechanical, evidence-derived). 2// Reads the capability matrix (knowledge/cms/wp_matrix.txt -- the top WP plugin buckets as DATA; 3// adding a bucket = editing the FILE, never this code) and derives each bucket's status from the 4// durable gate log: COVERED (latest evidence row passes), OPEN (no evidence yet -- the honest 5// backlog the ladder climbs), FAILING (evidence row present but not passing = a REGRESSION). 6// Coverage permil climbs ONLY by landing gated rungs. Verdict: EXCEED-WP iff permil=1000 with the 7// matrix's standing-exceed column intact; ON-LADDER otherwise. Appends to 8// knowledge/status/cms_wp_scorecard.log. Exit 0 iff NO bucket is FAILING (OPEN is allowed -- this 9// is a ladder instrument; regressions are not). Spec: 2026-06-10-cms-exceed-wordpress-ladder.md. 10// license_tier: ORIGINAL 11import "nx_syscalls.nx" 12import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 13const K_MAGIC_65536: i64 = 65536 14const K_MAGIC_65535: i64 = 65535 15const K_MAGIC_262144: i64 = 262144 16const K_MAGIC_262143: i64 = 262143 17 18func ws_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 19// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 20// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 21// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 22// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 23func ws_wn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 } 24func ws_fput(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } 25func ws_fputn(fd: i64, s: *u8, n: i64) -> i64 { sys_write(fd, s, n); return 0 } 26 27func ws_read(path: *u8, out: *u8, cap: i64) -> i64 { 28 let fd: i64 = sys_openat_rd(path) 29 if fd < 0 { return 0 - 1 } 30 var total: i64 = 0 31 var go: i64 = 1 32 while go == 1 { 33 let r: i64 = sys_read(fd, (out + total) as *u8, cap - total) 34 go = 0 35 if r > 0 { total = total + r; if total < cap { go = 1 } } 36 } 37 sys_close(fd) 38 return total 39} 40 41// last occurrence of pat (len pl) in buf[0..len); -1 absent 42func ws_find_last(buf: *u8, len: i64, pat: *u8, pl: i64) -> i64 { 43 if pl == 0 { return 0 - 1 } 44 var best: i64 = 0 - 1 45 var i: i64 = 0 46 while i + pl <= len { 47 var j: i64 = 0 48 var ok: i64 = 1 49 while j < pl { 50 if buf[i + j] != pat[j] { ok = 0; j = pl } 51 if ok == 1 { j = j + 1 } 52 } 53 if ok == 1 { best = i } 54 i = i + 1 55 } 56 return best 57} 58 59// status of evidence (rowpat,len rl) vs (passpat,len ql) in log: 1 COVERED, 0 FAILING, -1 OPEN 60func ws_status(log: *u8, ln: i64, rowpat: *u8, rl: i64, passpat: *u8, ql: i64) -> i64 { 61 let at: i64 = ws_find_last(log, ln, rowpat, rl) 62 if at < 0 { return 0 - 1 } 63 var e: i64 = at 64 var scanning: i64 = 1 65 while scanning == 1 { 66 if e >= ln { scanning = 0 } 67 if scanning == 1 { if log[e] == (10 as u8) { scanning = 0 } } 68 if scanning == 1 { e = e + 1 } 69 } 70 let sub: *u8 = ((log as i64) + at) as *u8 71 if ws_find_last(sub, e - at, passpat, ql) >= 0 { return 1 } 72 return 0 73} 74 75// parse the unsigned int immediately after the LAST occurrence of key in buf; -1 if key absent. 76func ws_parse_after(buf: *u8, len: i64, key: *u8, kl: i64) -> i64 { 77 let at: i64 = ws_find_last(buf, len, key, kl) 78 if at < 0 { return 0 - 1 } 79 var p: i64 = at + kl 80 var v: i64 = 0 81 var go: i64 = 1 82 while go == 1 { 83 if p >= len { go = 0 } 84 else { 85 let c: i64 = buf[p] as i64 86 if c < 48 { go = 0 } 87 else { if c > 57 { go = 0 } else { v = v * 10 + (c - 48); p = p + 1 } } 88 } 89 } 90 return v 91} 92 93func main() -> i64 { 94 let mx: *u8 = sys_mmap(K_MAGIC_65536) 95 let mn: i64 = ws_read("knowledge/cms/wp_matrix.txt" as *u8, mx, K_MAGIC_65535) 96 if mn <= 0 { ws_w("WPSCORE NO-MATRIX\n" as *u8); sys_exit(1); return 1 } 97 let log: *u8 = sys_mmap(K_MAGIC_262144) 98 var ln: i64 = ws_read("knowledge/status/cms_gate.log" as *u8, log, K_MAGIC_262143) 99 if ln < 0 { ln = 0 } 100 101 // W-RE-001: reach = the MEASURED census reach (per-feature PRESENT/ABSENT), NOT binary gate-pass. 102 let clog: *u8 = sys_mmap(K_MAGIC_262144) 103 var cln: i64 = ws_read("knowledge/status/cms_census.log" as *u8, clog, K_MAGIC_262143) 104 if cln < 0 { cln = 0 } 105 var census_reach: i64 = ws_parse_after(clog, cln, "our_coverage_permil=" as *u8, 20) 106 if census_reach < 0 { census_reach = 0 } 107 108 let lf: i64 = sys_openat_append("knowledge/status/cms_wp_scorecard.log" as *u8, 0x1a4) 109 var total: i64 = 0 110 var covered: i64 = 0 111 var openn: i64 = 0 112 var failing: i64 = 0 113 var won: i64 = 0 114 115 // walk matrix lines: bucket|wp_equiv|rowpat|passpat|exceed_note 116 var i: i64 = 0 117 while i < mn { 118 // line span 119 var e: i64 = i 120 while e < mn { if mx[e] == (10 as u8) { break } e = e + 1 } 121 if e > i + 4 { 122 // field offsets: 4 pipes 123 var p1: i64 = 0 - 1 124 var p2: i64 = 0 - 1 125 var p3: i64 = 0 - 1 126 var p4: i64 = 0 - 1 127 var q: i64 = i 128 while q < e { 129 if mx[q] == (124 as u8) { 130 var done2: i64 = 0 131 if p1 < 0 { p1 = q; done2 = 1 } 132 if done2 == 0 { if p2 < 0 { p2 = q; done2 = 1 } } 133 if done2 == 0 { if p3 < 0 { p3 = q; done2 = 1 } } 134 if done2 == 0 { if p4 < 0 { p4 = q } } 135 } 136 q = q + 1 137 } 138 if p4 > 0 { 139 total = total + 1 140 // a bucket is WON only with an explicit head-to-head win marker (no-wave law: a win 141 // MUST be measured head-to-head vs the incumbent; an unmarked bucket is ABSENT, never assumed). 142 if ws_find_last(((mx as i64) + i) as *u8, e - i, "won=1" as *u8, 5) >= 0 { won = won + 1 } 143 let st: i64 = ws_status(log, ln, ((mx as i64) + p2 + 1) as *u8, p3 - p2 - 1, ((mx as i64) + p3 + 1) as *u8, p4 - p3 - 1) 144 var tag: *u8 = "OPEN " as *u8 145 if st == 1 { covered = covered + 1; tag = "COVERED" as *u8 } 146 if st == 0 { failing = failing + 1; tag = "FAILING" as *u8 } 147 if st < 0 { openn = openn + 1 } 148 ws_w("WPSCORE " as *u8); ws_w(tag); ws_w(" " as *u8) 149 ws_fputn(1, ((mx as i64) + i) as *u8, p1 - i) 150 ws_w(" (vs " as *u8) 151 ws_fputn(1, ((mx as i64) + p1 + 1) as *u8, p2 - p1 - 1) 152 ws_w(")\n" as *u8) 153 } 154 } 155 i = e + 1 156 } 157 // W-RE-001 no-overclaim re-instrument: report MEASURED reach (census) + MEASURED won (head-to-head) 158 // separately; RETIRE the binary EXCEED-WP verdict -- the old permil=covered/total counted a bucket 159 // "covered" on ONE gate-PASS, which is REACH not a WIN (the 2026-06-13 overclaim). verdict=MEASURED 160 // always; REGRESSION on a failing gate. won_permil rises ONLY when a bucket carries a real won=1 marker. 161 let won_permil: i64 = won * 1000 / total 162 var verdict: *u8 = "MEASURED" as *u8 163 if failing > 0 { verdict = "REGRESSION" as *u8 } 164 ws_w("WPSCORE buckets=" as *u8); ws_wn(1, total) 165 ws_w(" covered=" as *u8); ws_wn(1, covered) 166 ws_w(" open=" as *u8); ws_wn(1, openn) 167 ws_w(" failing=" as *u8); ws_wn(1, failing) 168 ws_w(" census_reach_permil=" as *u8); ws_wn(1, census_reach) 169 ws_w(" won_permil=" as *u8); ws_wn(1, won_permil) 170 ws_w(" verdict=" as *u8); ws_w(verdict); ws_w("\n" as *u8) 171 if lf >= 0 { 172 ws_fput(lf, "WPSCORE buckets=" as *u8); ws_wn(lf, total) 173 ws_fput(lf, " covered=" as *u8); ws_wn(lf, covered) 174 ws_fput(lf, " open=" as *u8); ws_wn(lf, openn) 175 ws_fput(lf, " failing=" as *u8); ws_wn(lf, failing) 176 ws_fput(lf, " census_reach_permil=" as *u8); ws_wn(lf, census_reach) 177 ws_fput(lf, " won_permil=" as *u8); ws_wn(lf, won_permil) 178 ws_fput(lf, " verdict=" as *u8); ws_fput(lf, verdict) 179 ws_fput(lf, " epoch=" as *u8); ws_wn(lf, sys_now_realtime_sec()) 180 ws_fput(lf, "\n" as *u8) 181 sys_close(lf) 182 } 183 if failing == 0 { sys_exit(0) } 184 sys_exit(1) 185 return 1 186}