code wiki / _hdl_build / nx_capsearch.nx

nx_capsearch.nx

buildroot/runtime/_hdl_build/nx_capsearch.nx

19480 B431 linesdepth 5pulls 6 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_capsearch.nx -- CAPABILITY SEARCH (2026-08-06). "What tool does X?" answered from the estate's OWN registry, server-side, so an AGENT or a script can ask it. This is the organ the ecosystem was missing: grounded capability retrieval EXISTED at /code/ask but was browser-only client-side JS plus a local llama-server on the operator's laptop, so no agent and no headless caller could ever reach it, while /api/search has scopes site|web|trusted and NO capability scope -- querying it for `nx_page_verify`, the literal name of one of our own 869 tools, returns arxiv.org and kernel.org. THE RANKER IS NOT INVENTED. It is /code/ask's own `tooltop` (stem-hit on the name + word-boundary hit on the title) plus three GENERIC improvements, each measured against a HELD-OUT gold set before being kept: nx_common_tasks' 45 team-authored task->canonical-organ rows, which predate this organ. The task labels were deliberately NOT folded in as aliases -- that would score ~1000 and mean nothing. known good (/code/ask tooltop) : hit@1 400 hit@5 640 hit@10 720 MRR 482 (permil) + call-grammar field + idf : hit@1 400 hit@5 640 hit@10 720 MRR 507 + morphological prefix match : hit@1 520 hit@5 760 hit@10 800 MRR 620 <- shipped +120 permil hit@1 (+30% rel), +138 MRR (+29% rel) over the known good. CORPUS = knowledge/tool_schemas.conf (name + title) joined to knowledge/tool_grammar.conf (the derived argv contract from nx_toolgrammar) PLUS, since 2026-08-24, knowledge/status/libindex.tsv -- THE LIBRARY SURFACE. This organ ranked REGISTERED TOOLS ONLY, and a library has no registration row by design, so every library in the estate was invisible to the one instrument CLAUDE.md orders run before building anything. Measured cost the day it was fixed: two FALSE ABSENT rows on one compare board (a LIVE constraint solver and a complete Mei-2007 erosion pipeline that a sibling board had called "catalogue-proven absent" for a week), six private isqrt copies written beside each other, and a capsearch zero read as corroboration of absence. The lib corpus is emitted by nx_libindex (PG1) from cl_is_lib, the same classifier the adoption ladder uses, so this organ and the board cannot disagree about what a library is. Every result now carries its SURFACE ("tool" is MCP-callable, "lib" is import-only) so a lib hit is never mistaken for something a caller can invoke. Both corpora are read fresh per call, so a re-harvest is LIVE. INTEGER-ONLY scoring (no floats anywhere in this estate): weights are scaled by CS_SCALE. HONEST: a query whose tokens match nothing returns an EMPTY result list -- it never falls back to "here are some tools anyway". No evidence, no answer. And the corpus cap is ANNOUNCED: rows beyond it are COUNTED as dropped and corpus_complete flips to 0, never silently ranked as if they did not exist. nx_capsearch <query words...> -> JSON {query, considered, tools, libs, dropped, corpus_complete, results:[{tool,surface,score,what,call}]} license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_store_seed_lib.nx nx_capsearch.nx

imports: nx_syscalls.nxnx_store_seed_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main csw sys_write sys_exit sys_mmap nxa_die sys_write ↻ sys_exit ↻ nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap sys_close sts_load_fit sts_mm sys_mmap ↻ sts_werr sys_write ↻ sys_exit ↻ sts_load sts_gen_note sts_pfxhash ss_max_segid sys_mmap ↻ ss_cat ss_readall sys_openat_rd ↻

structs

none

consts

38const CS_MAGIC_1024: i64 = 1024
40const CS_SCHEMAS: *u8 = "knowledge/tool_schemas.conf" as *u8
41const CS_GRAMMAR: *u8 = "knowledge/tool_grammar.conf" as *u8
47const CS_LIBIDX: *u8 = "knowledge/store/libindex-" as *u8
49const CS_FCAP: i64 = 1 << 21
54const CS_MAXTOOLS: i64 = 8192
56const CS_MAXTOK: i64 = 12
58const CS_TOKCAP: i64 = 64
60const CS_TOPN: i64 = 8
62const CS_SCALE: i64 = 1000000
64const CS_MORPH: i64 = 4
66const CS_MINTOK: i64 = 3
68const CS_SURF_TOOL: i64 = 0
69const CS_SURF_LIB: i64 = 1

functions

71func csw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 2: csjmain calls 1: sys_write
72func csn(v: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
82func csj(buf: *u8, off: i64, n: i64) -> i64
called by 1: main calls 3: sys_mmapcswsys_write
96func cs_lower(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
called by 3: cs_iswcs_morphmain
98func cs_isw(c: i64) -> i64
called by 2: cs_texthitmain calls 1: cs_lower
106func cs_field(buf: *u8, ls: i64, le: i64, idx: i64, out2: *i64) -> i64
called by 1: main
123func cs_morph(buf: *u8, a: i64, alen: i64, tok: *u8, tlen: i64) -> i64
called by 2: cs_namehitcs_texthit calls 1: cs_lower
138func cs_namehit(buf: *u8, off: i64, len: i64, tok: *u8, tlen: i64) -> i64
called by 1: main calls 1: cs_morph
159func cs_texthit(buf: *u8, off: i64, len: i64, tok: *u8, tlen: i64) -> i64
called by 1: main calls 2: cs_iswcs_morph
182func cs_buf(surf: i64, sb: *u8, lb: *u8) -> *u8 { if surf == CS_SURF_LIB { return lb } return sb }
called by 1: main
184func main(argc: i64, argv: *i64) -> i64