nx_libindex.nx source
↩ module page · 54 lines · 3001 B
1// nx_libindex.nx -- CLI front door for the library discovery index (PG1, procgen.plan, 2026-08-24).
2//
3// Thin main only. Every function lives in nx_libindex_lib.nx so nx_libindex_gate can compose them IN-PROCESS
4// rather than forking a deployed binary: a gate that rebuilds the test but not the subject proves nothing,
5// and this way there is no subject to rebuild.
6//
7// WHY THIS ORGAN EXISTS: nx_capsearch ranks REGISTERED MCP TOOLS, and a library has no registration row by
8// design. So the one instrument CLAUDE.md orders run before building anything is structurally blind to every
9// library in the estate -- which is how eight duplicate isqrt copies came to be written beside each other.
10//
11// THE INDEX IS A SOVEREIGN ROW PLANE at knowledge/store/libindex- (never a .tsv file in the plane -- that
12// shape was retired 2026-08-13). The scratch descriptor the walker streams into is organ-owned and transient.
13// license_tier: ORIGINAL
14
15import "nx_libindex_lib.nx"
16
17func li_plane() -> *u8 { return "knowledge/store/libindex-" as *u8 }
18func li_scratch() -> *u8 { return "/tmp/nx_libindex.scratch" as *u8 }
19
20func li_usage() -> i64 {
21 li_out("usage: nx_libindex build | find <term> [term...]\n" as *u8)
22 li_out(" build scan buildroot/runtime and buildroot/runtime/_hdl_build, index every LIBRARY\n" as *u8)
23 li_out(" (cl_is_lib: no top-level main) with its title and every declared symbol,\n" as *u8)
24 li_out(" and seed the row plane knowledge/store/libindex- in ONE locked commit.\n" as *u8)
25 li_out(" find substring search over that plane. Prints the list, never a verdict --\n" as *u8)
26 li_out(" nx_capsearch owns ranking and a second scorer would be a duplicate ruler.\n" as *u8)
27 li_out(" WHY: nx_capsearch indexed REGISTERED TOOLS ONLY, so every library was invisible to it;\n" as *u8)
28 li_out(" it now joins this plane as its second corpus and tags each result with its surface.\n" as *u8)
29 return 2
30}
31
32func main(argc: i64, argv: *i64) -> i64 {
33 if argc < 2 { return li_usage() }
34 let op: *u8 = argv[1] as *u8
35 if clb_eq(op, "build" as *u8) == 1 {
36 let cen: *i64 = li_cen()
37 return li_build_to(li_scratch(), li_plane(), cen, 0)
38 }
39 if clb_eq(op, "find" as *u8) == 1 {
40 if argc < 3 { li_out("usage: nx_libindex find <term> [term...]\n" as *u8); return 2 }
41 // argv is indexed element-wise; `argv + 2` was BYTE arithmetic and read garbage pointers (SIGSEGV at
42 // 0x40276b on the first live find, 2026-08-24). Copy the terms into a vector the callee can index.
43 let nterms: i64 = argc - 2
44 let terms: *i64 = sys_mmap(nterms * 8) as *i64
45 var k: i64 = 0
46 while k < nterms { terms[k] = argv[2 + k]; k = k + 1 }
47 let h: i64 = li_find_in(li_plane(), terms, nterms, 0)
48 if h < 0 { return 2 }
49 if h == 0 { return 1 }
50 return 0
51 }
52 li_out("NX-LIBINDEX unknown verb -- expected build or find\n" as *u8)
53 return li_usage()
54}