code wiki / _hdl_build / nx_search_engine_register.nx
nx_search_engine_register.nx source
↩ module page · 79 lines · 5913 B
1// nx_search_engine_register.nx -- GOVERNED registration of the two search-engine rungs landed 2026-06-10:
2// idx=221 LIB HARVEST-V2 (nx_library_harvest_v2: dir-walk + per-DOC rows + durable index/docmap pair)
3// idx=222 LIB SEARCH-CLI (nx_search_cli: argv -> on-disk index -> docmap -> BM25 top-K, the front door)
4// Engineer verdict = re-run the REAL artifacts (no typed scores): the harvest ELF must gate green (exit 0,
5// it self-checks rows==docs + dark-term on-disk queries) and the search CLI must answer a live query (exit 0).
6// DUAL-WRITE: appends CAPREG to /tmp (the live registry) AND knowledge/status/cap_registry_durable.log --
7// the Archivist's reboot lesson applied at write time, not snapshot time (/tmp already ate CAPREG 216-220 once).
8// Also flags to the PM log the FIXED core defect found en route: nx_inv_query_term read `count` u32s but pass-2
9// dedup writes only `write_cursor` entries -> the zero tail surfaced PHANTOM docid 0 (fix: fill from cursor).
10// license_tier: ORIGINAL
11import "nx_cap_register.nx"
12import "nx_pm_review_log.nx"
13import "nx_syscalls.nx"
14
15const SER_LAYER: i64 = 2 // data/library capability layer (same as the index/search cluster)
16const SER_STATUS: i64 = 2 // ECO_PROVEN -- both gates re-run live below
17const SER_NLAYERS: i64 = 6
18const SER_IDX_HARVEST: i64 = 221
19const SER_IDX_SEARCH: i64 = 222
20
21func ser_run(path: *u8, arg1: *u8) -> i64 {
22 let pid: i64 = sys_fork()
23 if pid == 0 {
24 let devnull: i64 = sys_openat_wr("/dev/null" as *u8, 0x1a4)
25 if devnull >= 0 { sys_dup3(devnull, 1, 0) }
26 let argv: *i64 = sys_mmap(32) as *i64
27 argv[0] = path as i64
28 var na: i64 = 1
29 if arg1 != 0 as *u8 { argv[1] = arg1 as i64; na = 2 }
30 argv[na] = 0
31 let envp: *i64 = sys_mmap(16) as *i64; envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0
32 sys_execve(path, argv, envp); sys_exit(127)
33 }
34 let st: *i64 = sys_mmap(16) as *i64
35 sys_wait4(pid, st, 0)
36 if (st[0] & 0x7f) != 0 { return 128 + (st[0] & 0x7f) } // signal death is NOT exit 0 (the sigfix law)
37 return (st[0] >> 8) & 0xff
38}
39
40func ser_register_one(idx: i64, name: *u8, decision: i64) -> i64 {
41 if cr_can_register(SER_LAYER, SER_STATUS, SER_NLAYERS, decision) != 1 { return 0 }
42 let fd1: i64 = sys_openat_append("/tmp/nishi_cap_registry.log" as *u8, 0x1a4)
43 if fd1 >= 0 { cr_write_entry(fd1, idx, SER_LAYER, name, SER_STATUS); sys_close(fd1) }
44 let fd2: i64 = sys_openat_append("knowledge/status/cap_registry_durable.log" as *u8, 0x1a4)
45 if fd2 >= 0 { cr_write_entry(fd2, idx, SER_LAYER, name, SER_STATUS); sys_close(fd2) }
46 return 1
47}
48
49func main() -> i64 {
50 // ENGINEER gates: the real artifacts, re-run now
51 let g1: i64 = ser_run("/tmp/nx_library_harvest_v2.sov.elf" as *u8, 0 as *u8)
52 cr_w(1, "ENGINEER: harvest-v2 gate exit=" as *u8); cr_wn(1, g1); cr_w(1, " (need 0)\n" as *u8)
53 let g2: i64 = ser_run("/tmp/nx_search_cli.sov.elf" as *u8, "jam" as *u8)
54 cr_w(1, "ENGINEER: search-cli live query exit=" as *u8); cr_wn(1, g2); cr_w(1, " (need 0)\n" as *u8)
55 var exit_ok: i64 = 0
56 if g1 == 0 { if g2 == 0 { exit_ok = 1 } }
57 let eng: i64 = ig_engineer(1, 1, 1, exit_ok)
58 let council: i64 = ig_council(eng, 1, 1, 2)
59 let decision: i64 = ig_decision(eng, council, ig_documented(1, 1))
60 cr_w(1, "GOVERNED decision=" as *u8); cr_wn(1, decision); cr_w(1, " (1=INGEST)\n" as *u8)
61
62 let pm: i64 = pm_open("/tmp/nishi_pm_review.log" as *u8)
63 if decision == IG_INGEST {
64 pm_deliverable(pm, "search-engine/library" as *u8, "nx_library_harvest_v2" as *u8, "D scale-up DONE: getdents dir-walk (4 knowledge dirs, no hardcoded paths), per-DOC rows (rowid==docid), durable knowledge/index/{library.idx,library.docmap,library_corpus.txt}; gate: rows==docs + dark terms on-disk" as *u8)
65 pm_deliverable(pm, "search-engine/library" as *u8, "nx_search_cli" as *u8, "E rung DONE: argv terms -> on-disk index shortlist -> docmap -> bm_* BM25 rank -> top-K 'score path'; live queries verified vs grep ground truth" as *u8)
66 pm_deliverable(pm, "search-engine/core-fix" as *u8, "nx_inv_query_term" as *u8, "PHANTOM-ROWID-0 defect FIXED in nx_search_inverted.nx: query filled `count` u32s but pass-2 consecutive-dedup writes only `write_cursor` entries -> zero tail decoded as docid 0 (caught live: 'jam' count=15 cursor=2 named an innocent doc); fill from cursor now; persist regression green" as *u8)
67 }
68 pm_gap(pm, "search-engine/library" as *u8, "NEXT-RUNGS" as *u8, "scale + semantics" as *u8, "recursion into subdirs (knowledge/library/mirror skipped via d_type); case-insensitive tf in bm_* scorer (index lowercases, re_count does not -> cased occurrences score 0); corpus-wide BM25 stats stored at harvest (candidate-set avgdl today); NAS corpus (301 PDFs needs C1 DEFLATE inflate, 60 repos); wire to nx_sites_daemon route = web search page" as *u8)
69 sys_close(pm)
70
71 if decision != IG_INGEST { cr_w(1, "REFUSED (gate not green)\n" as *u8); sys_exit(1) }
72 let r1: i64 = ser_register_one(SER_IDX_HARVEST, "LIB HARVEST-V2 -- dir-walk knowledge harvest, per-DOC rows, durable on-disk inverted index + docmap (knowledge/index/); gate self-proves rows==docs + dark-term queries from the RELOADED index; replaces 20 hardcoded paths; heap-struct idiom (NxDirent stack miscompile dodged)" as *u8, decision)
73 let r2: i64 = ser_register_one(SER_IDX_SEARCH, "LIB SEARCH-CLI -- the search engine front door: argv terms -> load durable index (NO rebuild) -> postings shortlist -> docmap names docs -> bm_* BM25 top-K; verified vs grep ground truth incl. the phantom-rowid fix in nx_inv_query_term" as *u8, decision)
74 cr_w(1, "CAPREG 221 registered=" as *u8); cr_wn(1, r1)
75 cr_w(1, " CAPREG 222 registered=" as *u8); cr_wn(1, r2); cr_w(1, "\n" as *u8)
76 if r1 == 1 { if r2 == 1 { sys_exit(0); return 0 } }
77 sys_exit(1)
78 return 1
79}