code wiki / _hdl_build / nx_capsearch.nx
nx_capsearch.nx
buildroot/runtime/_hdl_build/nx_capsearch.nx
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
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
structs
| none |
consts
| 38 | const CS_MAGIC_1024: i64 = 1024 |
| 40 | const CS_SCHEMAS: *u8 = "knowledge/tool_schemas.conf" as *u8 |
| 41 | const CS_GRAMMAR: *u8 = "knowledge/tool_grammar.conf" as *u8 |
| 47 | const CS_LIBIDX: *u8 = "knowledge/store/libindex-" as *u8 |
| 49 | const CS_FCAP: i64 = 1 << 21 |
| 54 | const CS_MAXTOOLS: i64 = 8192 |
| 56 | const CS_MAXTOK: i64 = 12 |
| 58 | const CS_TOKCAP: i64 = 64 |
| 60 | const CS_TOPN: i64 = 8 |
| 62 | const CS_SCALE: i64 = 1000000 |
| 64 | const CS_MORPH: i64 = 4 |
| 66 | const CS_MINTOK: i64 = 3 |
| 68 | const CS_SURF_TOOL: i64 = 0 |
| 69 | const CS_SURF_LIB: i64 = 1 |
functions
| 71 | func csw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 72 | func csn(v: i64) -> i64 |
| 82 | func csj(buf: *u8, off: i64, n: i64) -> i64 |
| 96 | func cs_lower(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c } |
| 98 | func cs_isw(c: i64) -> i64 |
| 106 | func cs_field(buf: *u8, ls: i64, le: i64, idx: i64, out2: *i64) -> i64 called by 1: main |
| 123 | func cs_morph(buf: *u8, a: i64, alen: i64, tok: *u8, tlen: i64) -> i64 |
| 138 | func cs_namehit(buf: *u8, off: i64, len: i64, tok: *u8, tlen: i64) -> i64 |
| 159 | func cs_texthit(buf: *u8, off: i64, len: i64, tok: *u8, tlen: i64) -> i64 |
| 182 | func cs_buf(surf: i64, sb: *u8, lb: *u8) -> *u8 { if surf == CS_SURF_LIB { return lb } return sb } called by 1: main |
| 184 | func main(argc: i64, argv: *i64) -> i64 |