code wiki / _hdl_build / nx_ws_discover_gate.nx
nx_ws_discover_gate.nx source
↩ module page · 125 lines · 5823 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"
20import "nx_gate_verdict.nx"
21
22const GMEMDIR: *u8 = "/mnt/c/Users/elder/.claude/projects/C--Users-elder/memory"
23const GSCR_A: *u8 = "knowledge/store/wsdisc_a-"
24const GSCR_B: *u8 = "knowledge/store/wsdisc_b-"
25const GLOG: *u8 = "knowledge/status/ws_discover_gate.log"
26// a STABLE real arc used as the T2 drop fixture (B is only ever ingested WITH this omitted, so it
27// is never present in B across re-runs -> the detector test is deterministic).
28const GOMIT: *u8 = "pets-game-sfx-2026-06-13"
29const GCAP: i64 = 8192
30
31func gp(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
32
33// count how many project-*.md ids on disk are retrievable in the registry under `prefix`.
34func g_coverage(prefix: *u8, memdir: *u8, disk_out: *i64) -> i64 {
35 let names: *i64 = sys_mmap(8 * GCAP) as *i64
36 let mtimes: *i64 = sys_mmap(8 * GCAP) as *i64
37 let cnt: i64 = wme_scan(memdir, names, mtimes, GCAP)
38 disk_out[0] = cnt
39 if cnt < 0 { return 0 - 1 }
40 let h: *i64 = ss_open(prefix)
41 let keybuf: *u8 = sys_mmap(512)
42 let idb: *u8 = sys_mmap(256)
43 let rq: *i64 = sys_mmap(16) as *i64
44 let rl: *i64 = sys_mmap(16) as *i64
45 var covered: i64 = 0
46 var i: i64 = 0
47 while i < cnt {
48 wsi_id_from_name(names[i] as *u8, idb)
49 wsi_build_key(idb, keybuf)
50 if ss_hget(h, keybuf, rq, rl) == 1 { covered = covered + 1 }
51 i = i + 1
52 }
53 return covered
54}
55
56// 1 iff `id` is ABSENT under `prefix` (the detector / honesty primitive).
57func g_absent(prefix: *u8, id: *u8) -> i64 {
58 let h: *i64 = ss_open(prefix)
59 let keybuf: *u8 = sys_mmap(512)
60 wsi_build_key(id, keybuf)
61 let rq: *i64 = sys_mmap(16) as *i64
62 let rl: *i64 = sys_mmap(16) as *i64
63 if ss_hget(h, keybuf, rq, rl) == 1 { return 0 }
64 return 1
65}
66
67func main(argc: i64, argv: *i64) -> i64 {
68 let out4: *i64 = sys_mmap(64) as *i64
69
70 // T1: full ingest into scratch A, assert complete coverage.
71 wsi_ingest_omit_p(GSCR_A, GMEMDIR, 0 as *u8, out4)
72 let dA: *i64 = sys_mmap(16) as *i64
73 let covA: i64 = g_coverage(GSCR_A, GMEMDIR, dA)
74 let disk: i64 = dA[0]
75 var pass1: i64 = 0
76 if covA == disk { if disk > 0 { pass1 = 1 } }
77
78 // T2 (EXCEED / load-bearing neg-control): ingest all-but-GOMIT into B; the detector must
79 // report GOMIT ABSENT and coverage == disk-1.
80 wsi_ingest_omit_p(GSCR_B, GMEMDIR, GOMIT, out4)
81 let dB: *i64 = sys_mmap(16) as *i64
82 let covB: i64 = g_coverage(GSCR_B, GMEMDIR, dB)
83 let absOmit: i64 = g_absent(GSCR_B, GOMIT)
84 var pass2: i64 = 0
85 if absOmit == 1 { if covB == disk - 1 { pass2 = 1 } }
86
87 // T3 (HONEST): a fabricated never-on-disk id must be ABSENT in A.
88 let absFake: i64 = g_absent(GSCR_A, "ZZZ-not-a-real-arc-neg-control" as *u8)
89 var pass3: i64 = 0
90 if absFake == 1 { pass3 = 1 }
91
92 var green: i64 = 0
93 if pass1 == 1 { if pass2 == 1 { if pass3 == 1 { green = 1 } } }
94
95 gp("WS-DISCOVER-GATE disk=" as *u8); gn(disk)
96 gp(" covA=" as *u8); gn(covA)
97 gp(" covB=" as *u8); gn(covB)
98 gp(" omit=" as *u8); gp(GOMIT)
99 gp(" absent_omit=" as *u8); gn(absOmit)
100 gp(" absent_fake=" as *u8); gn(absFake)
101 gp(" T1=" as *u8); gn(pass1); gp(" T2=" as *u8); gn(pass2); gp(" T3=" as *u8); gn(pass3)
102
103 let buf: *u8 = sys_mmap(512)
104 var o: i64 = 0
105 o = fa_cat(buf, o, "WS-DISCOVER-GATE ts=\x00" as *u8); o = fa_catn(buf, o, sys_now_realtime_sec())
106 o = fa_cat(buf, o, " disk=\x00" as *u8); o = fa_catn(buf, o, disk)
107 o = fa_cat(buf, o, " covA=\x00" as *u8); o = fa_catn(buf, o, covA)
108 o = fa_cat(buf, o, " covB=\x00" as *u8); o = fa_catn(buf, o, covB)
109 o = fa_cat(buf, o, " absent_omit=\x00" as *u8); o = fa_catn(buf, o, absOmit)
110 o = fa_cat(buf, o, " T1=\x00" as *u8); o = fa_catn(buf, o, pass1)
111 o = fa_cat(buf, o, " T2=\x00" as *u8); o = fa_catn(buf, o, pass2)
112 o = fa_cat(buf, o, " T3=\x00" as *u8); o = fa_catn(buf, o, pass3)
113 if green == 1 { o = fa_cat(buf, o, " verdict=GREEN\x00" as *u8) } else { o = fa_cat(buf, o, " verdict=RED\x00" as *u8) }
114 fa_appendz(GLOG, buf, 512)
115
116 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
117 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
118 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
119 let ctr__dry: *i64 = gv_ctr()
120 ctr__dry[0] = green
121 ctr__dry[1] = 1
122 let rc__dry: i64 = gv_verdict("WS-DISCOVER-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
123 sys_exit(rc__dry)
124 return rc__dry
125}