nx_shelltool_tool_register.nx source
↩ module page · 41 lines · 3149 B
1// nx_shelltool_tool_register.nx -- register nx_shelltool (sovereign grep/glob/find) into the
2// discovery registry so it appears in nishifamily.com/api/tools + /mcp tools/list, i.e. so a
3// workstream (and Claude itself) gets a first-class mcp__nishi__nx_shelltool STUB and PREFERS it
4// over the flaky WSL + limited built-in Grep/Glob (operator 07-15: "they should have primacy in
5// our iteration loops"). EXECUTION is already live (allowlist row + cap-minted, tools/call proven
6// over /mcp loopback: grep returned its own allowlist row, glob returned 11 confs). This adds the
7// DISCOVERY half. Mirrors nx_crew_tool_register. Writes the CWD registry (knowledge/toolreg-); run
8// on the NAS (CWD nishihost) to flip the LIVE registry. Idempotent; verifies by READBACK.
9// expect_exit: 0 license_tier: ORIGINAL
10import "nx_tool_registry.nx"
11
12func sr_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
13func sr_putn(v: i64) -> i64 {
14 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
15 var m: i64 = v
16 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
17 let d: *u8 = sys_mmap(24); var k: i64 = 0
18 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
19 let o: *u8 = sys_mmap(24); var i: i64 = 0
20 while i < k { o[i] = d[k - 1 - i]; i = i + 1 }
21 sys_write(1, o, k)
22 return 0
23}
24
25func main() -> i64 {
26 sr_puts("=== nx_shelltool_tool_register -- grep/glob/find into the discovery registry ===\n" as *u8)
27 let w: i64 = tool_register("nx_shelltool" as *u8,
28 "Sovereign filesystem grep/glob/find -- the bits-up replacement for the flaky WSL + built-in Grep/Glob. Recursive, composes the canonical nx_grep (Boyer-Moore/KMP lineage; regex is roadmap S2). Read-only, runs on the NAS over MCP -- no WSL, no Linux-brother dependency. Verbs: grep <pattern> <dir> [ext] -> path:line:match ; glob <*wildcard> <dir> -> matching paths ; find <substr> <dir> -> paths whose name contains substr." as *u8,
29 "over /mcp: tools/call name=nx_shelltool arguments={argv:[VERB, PATTERN, DIR, EXT?]}. e.g. {argv:[\"grep\",\"tool_register\",\"runtime\",\".nx\"]} -> path:line:match lines ; {argv:[\"glob\",\"*.conf\",\".\"]} -> paths ; {argv:[\"find\",\"census\",\"runtime\"]} -> paths. Read-only; results are newline-joined text." as *u8,
30 "GREEN (nx_shelltool_gate 6/6: recursive grep + ext-filter neg-control, glob * wildcard, find substr, liar-killed via fork+pipe capture; LIVE over /mcp loopback -- grep returned its own allowlist row, glob returned 11 confs, exit 0. Substring-only vs ripgrep regex = roadmap S2)" as *u8)
31 let p: *i64 = sys_mmap(8) as *i64
32 let l: *i64 = sys_mmap(8) as *i64
33 let g: i64 = tool_get("nx_shelltool" as *u8, p, l)
34 sr_puts(" nx_shelltool put-rc=" as *u8); sr_putn(w); sr_puts(" readback=" as *u8)
35 if g == 1 { if l[0] > 0 {
36 sr_puts("OK len=" as *u8); sr_putn(l[0]); sr_puts("\nverdict=GREEN (nx_shelltool discoverable -> mcp__nishi__nx_shelltool stub)\n" as *u8)
37 sys_exit(0); return 0
38 } }
39 sr_puts("MISSING -- REGISTER FAILED\nverdict=RED\n" as *u8)
40 sys_exit(1); return 1
41}