code wiki / _hdl_build / nx_ws_coach.nx

nx_ws_coach.nx source

↩ module page · 184 lines · 9785 B

1// nx_ws_coach.nx -- THE WORKSTREAM COACH (operator 2026-07-09: "assists the workstreams so they dont drift and 2// claim state of the art when they are still toy level -- a liar killer AND a coach actively checking with 3// searchers and censuses as it climbs, with our sovereign tooling so we dont have massive token eating from 4// your deep researcher"). 5// 6// PROTOCOL (every workstream rung): build gate GREEN -> census re-run -> `nx_ws_coach <census.nx>` -> only a 7// COACH-OK rung may be CLAIMED. Research questions go to SOVEREIGN organs FIRST (nx_swcompare_research product 8// mode / nx_fetch / nx_qabench research -- ledger: deep-research cost 0 vs 107 LLM agents/query); Claude-token 9// deep research only when the sovereign tools return empty. 10// 11// v1 CHECKS (source-level, per census): 12// C1 U-AXES : product-surface census must carry the U1-U4 block (visual/interaction/info-design/polish) 13// C2 NAMED BARS : evidence must cite named competitor bars/dates (dateless claims = drift) 14// C3 CLAIM/PROOF: AHEAD/EXCEED/parity claims need gate-citations (gate/GREEN/n-of-m) nearby in the source -- 15// claims without proof = the liar-kill 16// C4 STALENESS : most recent evidence date must be current-quarter (2026-07/06) else STALE 17// VERDICT: COACH-OK / DRIFT (with the exact fixes + the sovereign research command to run next). 18// usage: nx_ws_coach [census-file.nx] (no arg = self-test teeth on known healthy + known drifted) 19// expect_exit: 0 license_tier: ORIGINAL 20import "nx_syscalls.nx" 21import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 22const K_MAGIC_4096: i64 = 4096 23const K_MAGIC_1048576: i64 = 1048576 24 25func wc_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 26// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 27// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 28// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 29// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 30func wc_n(v: i64) -> i64 { nxi_out(v); return 0 } 31func wc_find(buf: *u8, n: i64, pat: *u8) -> i64 { 32 var pl: i64 = 0 33 while pat[pl] != (0 as u8) { pl = pl + 1 } 34 if pl == 0 { return 0 - 1 } 35 var i: i64 = 0 36 while i + pl <= n { 37 var j: i64 = 0 38 var ok: i64 = 1 39 while j < pl { 40 if buf[i + j] != pat[j] { ok = 0; j = pl } else { j = j + 1 } 41 } 42 if ok == 1 { return i } 43 i = i + 1 44 } 45 return 0 - 1 46} 47func wc_count(buf: *u8, n: i64, pat: *u8) -> i64 { 48 var pl: i64 = 0 49 while pat[pl] != (0 as u8) { pl = pl + 1 } 50 var c: i64 = 0 51 var i: i64 = 0 52 while i + pl <= n { 53 var j: i64 = 0 54 var ok: i64 = 1 55 while j < pl { 56 if buf[i + j] != pat[j] { ok = 0; j = pl } else { j = j + 1 } 57 } 58 if ok == 1 { c = c + 1; i = i + pl } else { i = i + 1 } 59 } 60 return c 61} 62func wc_surface(buf: *u8, n: i64) -> i64 { 63 var h: i64 = n 64 if h > K_MAGIC_4096 { h = K_MAGIC_4096 } 65 if wc_find(buf, h, "game" as *u8) >= 0 { return 1 } 66 if wc_find(buf, h, "viewer" as *u8) >= 0 { return 1 } 67 if wc_find(buf, h, "UI" as *u8) >= 0 { return 1 } 68 if wc_find(buf, h, "office" as *u8) >= 0 { return 1 } 69 if wc_find(buf, h, "browser" as *u8) >= 0 { return 1 } 70 if wc_find(buf, h, "hub" as *u8) >= 0 { return 1 } 71 if wc_find(buf, h, "site" as *u8) >= 0 { return 1 } 72 if wc_find(buf, h, "video" as *u8) >= 0 { return 1 } 73 if wc_find(buf, h, "interactive" as *u8) >= 0 { return 1 } 74 return 0 75} 76// small read helper 77func sp2_read(path: *u8, buf: *u8) -> i64 { 78 let fd: i64 = sys_openat_rd(path) 79 if fd < 0 { return 0 - 1 } 80 let n: i64 = sys_read(fd, buf, K_MAGIC_1048576) 81 sys_close(fd) 82 return n 83} 84// coach one census file; returns 1 = COACH-OK, 0 = DRIFT. verbose board printed. 85func wc_coach(path: *u8, buf: *u8) -> i64 { 86 let n: i64 = sp2_read(path, buf) 87 if n <= 0 { wc_w(" cannot read " as *u8); wc_w(path); wc_w("\n" as *u8); return 0 } 88 wc_w("COACH " as *u8); wc_w(path); wc_w("\n" as *u8) 89 var drift: i64 = 0 90 // C1: TYPED subject declaration wins (structural > keyword heuristic -- the audit's own liar-kill rule); 91 // fallback = the surface keyword heuristic. 92 var surf: i64 = 0 - 1 93 if wc_find(buf, n, "census-subject: instrument" as *u8) >= 0 { surf = 0 } 94 if wc_find(buf, n, "census-subject: backend" as *u8) >= 0 { surf = 0 } 95 if wc_find(buf, n, "census-subject: product-surface" as *u8) >= 0 { surf = 1 } 96 if surf < 0 { surf = wc_surface(buf, n) } 97 var hasu: i64 = 0 98 if wc_find(buf, n, "UI/PRODUCT AXES" as *u8) >= 0 { hasu = 1 } 99 if wc_find(buf, n, "visual fidelity" as *u8) >= 0 { hasu = 1 } 100 if surf == 1 { 101 if hasu == 1 { wc_w(" C1 U-axes: PRESENT\n" as *u8) } else { 102 wc_w(" C1 U-axes: MISSING (product surface) -> ADD U1 visual/U2 interaction/U3 info-design/U4 polish vs a NAMED product\n" as *u8) 103 drift = drift + 1 104 } 105 } else { wc_w(" C1 U-axes: n/a (declared/backend census)\n" as *u8) } 106 // C2 named bars + dates 107 let d26: i64 = wc_count(buf, n, "2026-" as *u8) 108 let d25: i64 = wc_count(buf, n, "2025" as *u8) 109 if d26 + d25 >= 2 { wc_w(" C2 dated bars: OK (" as *u8); wc_n(d26 + d25); wc_w(" dated citations)\n" as *u8) } else { 110 wc_w(" C2 dated bars: WEAK -> cite competitor bars WITH dates (bank via the sovereign researcher)\n" as *u8) 111 drift = drift + 1 112 } 113 // C3 claim/proof. ★STRUCTURED MODE (census-v2, R3 2026-07-10): if the census carries "@claim" tokens, 114 // count MECHANICALLY -- every @claim row must carry an @ev evidence token (paired at the row). This kills 115 // the v1 vocabulary-count false-drifts (grade-LEGEND words like "PARITY < AHEAD" inflated claim counts on 116 // honest censuses -- mcbench was the driver). Fallback for unstructured censuses = the v1 heuristic. 117 var claims: i64 = wc_count(buf, n, "@claim" as *u8) 118 var proofs: i64 = wc_count(buf, n, "@ev" as *u8) 119 var structured: i64 = 0 120 if claims > 0 { structured = 1 } 121 if structured == 0 { 122 claims = wc_count(buf, n, "EXCEED" as *u8) + wc_count(buf, n, "AHEAD" as *u8) + wc_count(buf, n, "parity" as *u8) + wc_count(buf, n, "PARITY" as *u8) 123 proofs = wc_count(buf, n, "gate" as *u8) + wc_count(buf, n, "GREEN" as *u8) + wc_count(buf, n, "LIVE" as *u8) + wc_count(buf, n, "nx_" as *u8) / 2 124 } 125 wc_w(" C3 claims=" as *u8); wc_n(claims); wc_w(" proofs=" as *u8); wc_n(proofs) 126 if structured == 1 { 127 wc_w(" [STRUCTURED]" as *u8) 128 if proofs < claims { 129 wc_w(" -> UNPAIRED @claim (a claim row lacks its @ev evidence token)" as *u8) 130 drift = drift + 1 131 } 132 } else { 133 if claims > 0 { if proofs < claims / 2 { 134 wc_w(" -> UNDER-PROVEN (liar-kill risk): every AHEAD/EXCEED/parity needs a gate/GREEN/LIVE citation" as *u8) 135 drift = drift + 1 136 } } 137 } 138 wc_w("\n" as *u8) 139 // C4 staleness: current-quarter evidence 140 var fresh: i64 = 0 141 if wc_find(buf, n, "2026-07" as *u8) >= 0 { fresh = 1 } 142 if wc_find(buf, n, "2026-06" as *u8) >= 0 { fresh = 1 } 143 if fresh == 1 { wc_w(" C4 freshness: OK (current-quarter evidence)\n" as *u8) } else { 144 wc_w(" C4 freshness: STALE -> re-run the census + re-fetch bars (living-compare doctrine)\n" as *u8) 145 drift = drift + 1 146 } 147 if drift == 0 { 148 wc_w(" VERDICT: COACH-OK -- rung may be claimed\n" as *u8) 149 return 1 150 } 151 wc_w(" VERDICT: DRIFT (" as *u8); wc_n(drift) 152 wc_w(" findings) -- rung may NOT be claimed as SOTA/parity.\n NEXT (SOVEREIGN, near-zero token): 1) fix findings above; 2) bank bars: nx_swcompare_research product <oss-repo>; 3) re-run census; 4) re-coach.\n" as *u8) 153 return 0 154} 155func main(argc: i64, argv: *i64) -> i64 { 156 wc_w("=== nx_ws_coach -- anti-drift coach: liar-killer + prescriptions, sovereign-first research ===\n" as *u8) 157 let buf: *u8 = sys_mmap(K_MAGIC_1048576) 158 if argc >= 2 { 159 let ok: i64 = wc_coach(argv[1] as *u8, buf) 160 if ok == 1 { return 0 } 161 return 1 162 } 163 // self-test teeth: healthy (upgraded cadtwin) vs drifted (a flagged game census) 164 let fails: *i64 = sys_mmap(8) as *i64 165 fails[0] = 0 166 let ok1: i64 = wc_coach("runtime/_hdl_build/nx_cadtwin_census.nx" as *u8, buf) 167 wc_w("\n" as *u8) 168 // T2 target: a STILL-unconverted product-surface census (game_sclass was CONVERTED 2026-07-10 -> now OK) 169 let ok2: i64 = wc_coach("runtime/_hdl_build/nx_replika_census.nx" as *u8, buf) 170 wc_w("\n T1 upgraded cadtwin census -> COACH-OK -> " as *u8) 171 if ok1 == 1 { wc_w("PASS\n" as *u8) } else { wc_w("FAIL\n" as *u8); fails[0] = fails[0] + 1 } 172 wc_w(" T2 flagged unconverted census -> DRIFT detected -> " as *u8) 173 if ok2 == 0 { wc_w("PASS\n" as *u8) } else { wc_w("FAIL\n" as *u8); fails[0] = fails[0] + 1 } 174 let buf2: *u8 = sys_mmap(K_MAGIC_1048576) 175 let ok3: i64 = wc_coach("runtime/_hdl_build/nx_cadtwin_census.nx" as *u8, buf2) 176 wc_w(" T3 deterministic -> " as *u8) 177 if ok3 == ok1 { wc_w("PASS\n" as *u8) } else { wc_w("FAIL\n" as *u8); fails[0] = fails[0] + 1 } 178 wc_w("\nPROTOCOL: every rung = gate GREEN -> census re-run -> nx_ws_coach -> only COACH-OK claims the rung.\n" as *u8) 179 wc_w("Research = sovereign organs FIRST (0 tokens; ledger floor 0-vs-107-agents); Claude deep-research LAST.\n" as *u8) 180 wc_w("\nfails=" as *u8); wc_n(fails[0]); wc_w("\n" as *u8) 181 if fails[0] == 0 { wc_w("GREEN -- the coach is live (liar-killer + prescription + sovereign-first)\n" as *u8); return 0 } 182 wc_w("RED\n" as *u8) 183 return 1 184}