nx_explore_census.nx source
↩ module page · 112 lines · 7576 B
1// nx_explore_census.nx -- THE NISHI EXPLORE TEAM: capability census + living map (operator 2026-06-23:
2// "build a nishi explore team capability from the hardware rung up each rung to be s class exceed").
3//
4// WHY THIS EXISTS (the dogfood): this session the third-party Explore *agent* hit a spend wall AND
5// ripgrep-backed Glob TIMED OUT FOUR TIMES at 20s on this very tree. The sovereign explore capability
6// is justified by DIRECT MEASUREMENT, not assertion -- the incumbents demonstrably fail here.
7//
8// This organ is the ladder's RUNG-0 keystone: it does NOT re-implement anything. It PROBES the real
9// on-disk organs that already provide each explore rung and grades them HAVE/MISSING by reading the
10// file for its DEFINING SYMBOL (so it cannot lie -- drop the symbol and the rung flips MISSING). It is
11// SELF-GATING: baked neg-controls (a bogus-symbol liar-kill + an absent-file open-fail control) must
12// hold or it exits RED. Composes nx_codegrep's proven read+substring idiom. license_tier: ORIGINAL
13//
14// THE LADDER (each rung: incumbent / sovereign exceed axis / proving organ):
15// R0 WALK recursive fs-walk via getdents64 vs find/os.walk nx_dir.nx::nx_dir_list (JPL-bounded,
16// verdict-sealed, no libc -- bounded where find recurses unbounded)
17// R1 GLOB name/suffix match vs find -name nx_dir.nx::nx_dir_name_ends_with
18// R2 GREP recursive content search vs ripgrep nx_codegrep.nx::cg_scan_dir (COMPLETES
19// where rg TIMED OUT on runtime/ -- measured live, 4x this session)
20// R3 INDEX durable inverted index + BM25 rank vs Sourcegraph nx_library_harvest_v2.nx::lh2_query
21// R4 MAP query -> conclusion map (paths+role+hits+rank) = the EXPLORE-AGENT REPLACEMENT, the GAP
22// R5 GROW self-discovers its own coverage gaps and grows the GAP
23//
24// HAVE rungs are proven on-disk; MISSING rungs are the HONEST backlog (the gap IS the roadmap).
25// Build/run: ./_offc/nx_sov_build_run.elf nx_explore_census (run-exit=0 => map correct + neg-controls held)
26import "nx_syscalls.nx"
27import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
28
29const EC_FBUF: i64 = 4194304 // 4 MB per-probe read buffer (reused); every probed organ is far under this
30
31func ec_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
32func ec_puts(s: *u8) -> i64 { sys_write(1, s, ec_strlen(s)); return 0 }
33// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
34// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
35// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
36// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
37func ec_putn(v: i64) -> i64 { nxi_out(v); return 0 }
38
39// substring search of pat[0..pl] within buf[lo..hi]; 1 if found (reuses nx_codegrep's proven idiom).
40func ec_find(buf: *u8, lo: i64, hi: i64, pat: *u8, pl: i64) -> i64 {
41 if pl == 0 { return 0 }
42 var i: i64 = lo
43 while i + pl <= hi {
44 var j: i64 = 0
45 while j < pl { if buf[i + j] != pat[j] { j = pl + 1 } else { j = j + 1 } }
46 if j == pl { return 1 }
47 i = i + 1
48 }
49 return 0
50}
51
52// PROBE: 1 iff the file at `path` opens AND contains the literal `sym`. open-fail or absent => 0.
53// This reads REAL on-disk bytes -- a hardcoded verdict cannot survive the baked liar-kill below.
54func ec_probe(path: *u8, sym: *u8, fbuf: *u8) -> i64 {
55 let fd: i64 = sys_openat_rd(path)
56 if fd < 0 { return 0 }
57 let n: i64 = sys_read(fd, fbuf, EC_FBUF)
58 sys_close(fd)
59 if n <= 0 { return 0 }
60 return ec_find(fbuf, 0, n, sym, ec_strlen(sym))
61}
62
63func ec_verd(have: i64) -> i64 { if have == 1 { ec_puts(" HAVE " as *u8) } else { ec_puts(" MISSING " as *u8) } return 0 }
64
65func main() -> i64 {
66 let fbuf: *u8 = sys_mmap(EC_FBUF + 16)
67 ec_puts("=== NISHI EXPLORE TEAM -- CAPABILITY CENSUS (hardware-rung-up, sovereign) ===\n" as *u8)
68 ec_puts(" (justified live: 3rd-party Explore agent spend-walled + ripgrep Glob timed out 4x @20s this tree)\n" as *u8)
69
70 // --- probe each rung against the REAL organ that provides it ---
71 let r0: i64 = ec_probe("runtime/nx_dir.nx" as *u8, "func nx_dir_list" as *u8, fbuf)
72 let r1: i64 = ec_probe("runtime/nx_dir.nx" as *u8, "func nx_dir_name_ends_with" as *u8, fbuf)
73 let r2: i64 = ec_probe("runtime/nx_codegrep.nx" as *u8, "func cg_scan_dir" as *u8, fbuf)
74 let r3: i64 = ec_probe("runtime/_hdl_build/nx_library_harvest_v2.nx" as *u8, "func lh2_query" as *u8, fbuf)
75 let r4: i64 = ec_probe("runtime/nx_explore.nx" as *u8, "func ex_map" as *u8, fbuf)
76 let r5: i64 = ec_probe("runtime/nx_explore_grow.nx" as *u8, "func exg_step" as *u8, fbuf)
77
78 ec_puts("R0 WALK fs-walk(getdents64) " as *u8); ec_verd(r0); ec_puts("nx_dir.nx::nx_dir_list | vs find/os.walk: JPL-bounded, verdict-sealed, no libc\n" as *u8)
79 ec_puts("R1 GLOB name/suffix match " as *u8); ec_verd(r1); ec_puts("nx_dir.nx::nx_dir_name_ends_with | vs find -name: sovereign predicate\n" as *u8)
80 ec_puts("R2 GREP recursive content scan " as *u8); ec_verd(r2); ec_puts("nx_codegrep.nx::cg_scan_dir | vs ripgrep: COMPLETES where rg timed out @20s\n" as *u8)
81 ec_puts("R3 INDEX inverted index + BM25 " as *u8); ec_verd(r3); ec_puts("nx_library_harvest_v2.nx::lh2_query | vs Sourcegraph: durable on-disk, zero egress\n" as *u8)
82 ec_puts("R4 MAP query->conclusion map " as *u8); ec_verd(r4); ec_puts("nx_explore.nx::ex_map | R4 LIVE: sovereign Explore-agent replacement (gated)\n" as *u8)
83 ec_puts("R5 GROW self-discovers gaps " as *u8); ec_verd(r5); ec_puts("nx_explore_grow.nx::exg_step | R5 LIVE: discovers gaps + emits build-target (auto-author routes to team)\n" as *u8)
84
85 let have: i64 = r0 + r1 + r2 + r3 + r4 + r5
86 let missing: i64 = 6 - have
87 let cov: i64 = (have * 1000) / 6
88 ec_puts("EXPLORE-CENSUS have=" as *u8); ec_putn(have)
89 ec_puts(" missing=" as *u8); ec_putn(missing)
90 ec_puts(" cov=" as *u8); ec_putn(cov); ec_puts(" /1000 (of 6 rungs)\n" as *u8)
91
92 // --- baked NEG-CONTROLS: the map cannot lie ---
93 let liar: i64 = ec_probe("runtime/nx_dir.nx" as *u8, "func zzq_nonexistent_symbol_qqx" as *u8, fbuf) // present file, absent symbol -> MUST be 0
94 let nofile: i64 = ec_probe("runtime/nx_zzz_does_not_exist_qqx.nx" as *u8, "func nx_dir_list" as *u8, fbuf) // absent file -> MUST be 0
95
96 var ok: i64 = 1
97 if r0 != 1 { ok = 0; ec_puts("FAIL inv R0 (walk) expected HAVE\n" as *u8) }
98 if r1 != 1 { ok = 0; ec_puts("FAIL inv R1 (glob) expected HAVE\n" as *u8) }
99 if r2 != 1 { ok = 0; ec_puts("FAIL inv R2 (grep) expected HAVE\n" as *u8) }
100 if r3 != 1 { ok = 0; ec_puts("FAIL inv R3 (index) expected HAVE\n" as *u8) }
101 if r4 != 1 { ok = 0; ec_puts("FAIL inv R4 (map front-door) expected HAVE\n" as *u8) }
102 if r5 != 1 { ok = 0; ec_puts("FAIL inv R5 (self-grow) expected HAVE\n" as *u8) }
103 if liar != 0 { ok = 0; ec_puts("FAIL liar-kill: bogus symbol probed HAVE -- not reading file content!\n" as *u8) }
104 if nofile != 0 { ok = 0; ec_puts("FAIL neg-control: absent file probed HAVE -- open-fail not handled!\n" as *u8) }
105
106 if ok == 1 {
107 ec_puts("EXPLORE-CENSUS-GATE GREEN -- 6/6 rungs proven on-disk, INITIAL LADDER COMPLETE (cov=1000), neg-controls held\n" as *u8)
108 sys_exit(0); return 0
109 }
110 ec_puts("EXPLORE-CENSUS-GATE RED\n" as *u8)
111 sys_exit(1); return 1
112}