code wiki / _hdl_build / nx_ws_discover_gate.nx

nx_ws_discover_gate.nx source

↩ module page · 117 lines · 5372 B

1import "nx_gate_gn.nx" 2// nx_ws_discover_gate.nx -- the S-class AUTO-DISCOVERY completeness gate (rung 1 of the 3// discover->research->spec->build pipeline). Proves the registry SEES every arc on disk and -- the 4// capability the old markdown loss-detector LACKED -- DETECTS exactly WHICH arc dropped, on the 5// machine SSOT the orchestrator dispatches from (not a doc). The exceed is measured by T2: a 6// deliberately-omitted real arc must come back ABSENT with coverage == disk-1 (a count-only 7// detector would miss which one; a fabricated-green gate would pass it silently). 8// 9// T1 POS full ingest into scratch A -> coverage == disk_count (nothing dropped). 10// T2 EXCEED ingest all-but-one into scratch B -> the omitted arc is ABSENT and coverage == disk-1 11// (the detector fires on a real drop -- the load-bearing negative control). 12// T3 HONEST a fabricated never-on-disk id is ABSENT in A (no invented hits). 13// GREEN iff T1 && T2 && T3. Sovereign; imports the keystone + stores. license_tier: ORIGINAL 14import "nx_ws_ingest.nx" 15import "nx_ws_index_lib.nx" 16import "nx_workstream_store.nx" 17import "nx_seg_store.nx" 18import "nx_framed_append.nx" 19import "nx_syscalls.nx" 20 21const GMEMDIR: *u8 = "/mnt/c/Users/elder/.claude/projects/C--Users-elder/memory" 22const GSCR_A: *u8 = "knowledge/store/wsdisc_a-" 23const GSCR_B: *u8 = "knowledge/store/wsdisc_b-" 24const GLOG: *u8 = "knowledge/status/ws_discover_gate.log" 25// a STABLE real arc used as the T2 drop fixture (B is only ever ingested WITH this omitted, so it 26// is never present in B across re-runs -> the detector test is deterministic). 27const GOMIT: *u8 = "pets-game-sfx-2026-06-13" 28const GCAP: i64 = 8192 29 30func gp(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 31 32// count how many project-*.md ids on disk are retrievable in the registry under `prefix`. 33func g_coverage(prefix: *u8, memdir: *u8, disk_out: *i64) -> i64 { 34 let names: *i64 = sys_mmap(8 * GCAP) as *i64 35 let mtimes: *i64 = sys_mmap(8 * GCAP) as *i64 36 let cnt: i64 = wme_scan(memdir, names, mtimes, GCAP) 37 disk_out[0] = cnt 38 if cnt < 0 { return 0 - 1 } 39 let h: *i64 = ss_open(prefix) 40 let keybuf: *u8 = sys_mmap(512) 41 let idb: *u8 = sys_mmap(256) 42 let rq: *i64 = sys_mmap(16) as *i64 43 let rl: *i64 = sys_mmap(16) as *i64 44 var covered: i64 = 0 45 var i: i64 = 0 46 while i < cnt { 47 wsi_id_from_name(names[i] as *u8, idb) 48 wsi_build_key(idb, keybuf) 49 if ss_hget(h, keybuf, rq, rl) == 1 { covered = covered + 1 } 50 i = i + 1 51 } 52 return covered 53} 54 55// 1 iff `id` is ABSENT under `prefix` (the detector / honesty primitive). 56func g_absent(prefix: *u8, id: *u8) -> i64 { 57 let h: *i64 = ss_open(prefix) 58 let keybuf: *u8 = sys_mmap(512) 59 wsi_build_key(id, keybuf) 60 let rq: *i64 = sys_mmap(16) as *i64 61 let rl: *i64 = sys_mmap(16) as *i64 62 if ss_hget(h, keybuf, rq, rl) == 1 { return 0 } 63 return 1 64} 65 66func main(argc: i64, argv: *i64) -> i64 { 67 let out4: *i64 = sys_mmap(64) as *i64 68 69 // T1: full ingest into scratch A, assert complete coverage. 70 wsi_ingest_omit_p(GSCR_A, GMEMDIR, 0 as *u8, out4) 71 let dA: *i64 = sys_mmap(16) as *i64 72 let covA: i64 = g_coverage(GSCR_A, GMEMDIR, dA) 73 let disk: i64 = dA[0] 74 var pass1: i64 = 0 75 if covA == disk { if disk > 0 { pass1 = 1 } } 76 77 // T2 (EXCEED / load-bearing neg-control): ingest all-but-GOMIT into B; the detector must 78 // report GOMIT ABSENT and coverage == disk-1. 79 wsi_ingest_omit_p(GSCR_B, GMEMDIR, GOMIT, out4) 80 let dB: *i64 = sys_mmap(16) as *i64 81 let covB: i64 = g_coverage(GSCR_B, GMEMDIR, dB) 82 let absOmit: i64 = g_absent(GSCR_B, GOMIT) 83 var pass2: i64 = 0 84 if absOmit == 1 { if covB == disk - 1 { pass2 = 1 } } 85 86 // T3 (HONEST): a fabricated never-on-disk id must be ABSENT in A. 87 let absFake: i64 = g_absent(GSCR_A, "ZZZ-not-a-real-arc-neg-control" as *u8) 88 var pass3: i64 = 0 89 if absFake == 1 { pass3 = 1 } 90 91 var green: i64 = 0 92 if pass1 == 1 { if pass2 == 1 { if pass3 == 1 { green = 1 } } } 93 94 gp("WS-DISCOVER-GATE disk=" as *u8); gn(disk) 95 gp(" covA=" as *u8); gn(covA) 96 gp(" covB=" as *u8); gn(covB) 97 gp(" omit=" as *u8); gp(GOMIT) 98 gp(" absent_omit=" as *u8); gn(absOmit) 99 gp(" absent_fake=" as *u8); gn(absFake) 100 gp(" T1=" as *u8); gn(pass1); gp(" T2=" as *u8); gn(pass2); gp(" T3=" as *u8); gn(pass3) 101 102 let buf: *u8 = sys_mmap(512) 103 var o: i64 = 0 104 o = fa_cat(buf, o, "WS-DISCOVER-GATE ts=\x00" as *u8); o = fa_catn(buf, o, sys_now_realtime_sec()) 105 o = fa_cat(buf, o, " disk=\x00" as *u8); o = fa_catn(buf, o, disk) 106 o = fa_cat(buf, o, " covA=\x00" as *u8); o = fa_catn(buf, o, covA) 107 o = fa_cat(buf, o, " covB=\x00" as *u8); o = fa_catn(buf, o, covB) 108 o = fa_cat(buf, o, " absent_omit=\x00" as *u8); o = fa_catn(buf, o, absOmit) 109 o = fa_cat(buf, o, " T1=\x00" as *u8); o = fa_catn(buf, o, pass1) 110 o = fa_cat(buf, o, " T2=\x00" as *u8); o = fa_catn(buf, o, pass2) 111 o = fa_cat(buf, o, " T3=\x00" as *u8); o = fa_catn(buf, o, pass3) 112 if green == 1 { o = fa_cat(buf, o, " verdict=GREEN\x00" as *u8) } else { o = fa_cat(buf, o, " verdict=RED\x00" as *u8) } 113 fa_appendz(GLOG, buf, 512) 114 115 if green == 1 { gp(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 } 116 gp(" verdict=RED\n" as *u8); sys_exit(1); return 1 117}