nx_restage_tool_register.nx source
↩ module page · 39 lines · 3431 B
1// nx_restage_tool_register.nx -- register nx_restage into the discovery registry so it appears in
2// nishifamily.com/api/tools + /mcp tools/list, i.e. so agents (and Claude) get a first-class
3// mcp__nishi__nx_restage STUB (not just cap-executable via raw tools/call). EXECUTION is already live
4// (tool_allowlist.conf row + cap 72130; proven on NAS -- restaged nx_swcompare_sota 35291B -> /compare/llm
5// @verdict source-derived). This adds the DISCOVERY half. Mirrors nx_shelltool_tool_register. Writes the
6// CWD registry (knowledge/toolreg-); run on the NAS (CWD nishihost) to flip the LIVE registry. Idempotent;
7// verifies by READBACK. expect_exit: 0 license_tier: ORIGINAL
8import "nx_tool_registry.nx"
9
10func 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 }
11func sr_putn(v: i64) -> i64 {
12 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
13 var m: i64 = v
14 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
15 let d: *u8 = sys_mmap(24); var k: i64 = 0
16 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
17 let o: *u8 = sys_mmap(24); var i: i64 = 0
18 while i < k { o[i] = d[k - 1 - i]; i = i + 1 }
19 sys_write(1, o, k)
20 return 0
21}
22
23func main() -> i64 {
24 sr_puts("=== nx_restage_tool_register -- buildroot/_offc restager into the discovery registry ===\n" as *u8)
25 let w: i64 = tool_register("nx_restage" as *u8,
26 "Restage a freshly-built ELF into a build tree's _offc/ -- the NAS-side primitive that keeps buildroot generators from going STALE vs runtime source (the F-004 stale-binary class; e.g. an @verdict directive that lived in source but not the staged generator elf). Rebuilds <target> via nx_sov_build_run --build-only then binary-safe ATOMICALLY copies /tmp/<target>.sov.elf -> _offc/<target>.elf with ELF-magic + nonzero-size verification; target sanitized to [A-Za-z0-9_]. Closes the gap left open by nx_fs_write (text + refuses _offc), nx_shelltool (read-only), and /api/build (stages to nishihost not buildroot/_offc)." as *u8,
27 "over /mcp: tools/call name=nx_restage arguments={argv:[TARGET, BROOT?]}. e.g. {argv:[\"nx_swcompare_sota\"]} rebuilds + restages buildroot/_offc/nx_swcompare_sota.elf (BROOT defaults to \"buildroot\"). Emits {\"action\":\"RESTAGED\",\"target\":...,\"path\":...,\"bytes\":N}. Then re-run the consumer (e.g. nishi_compare_regen) to pick up the fresh generator. Fail-closed: bad target, non-ELF output, or copy failure -> exit 1/2, _offc untouched." as *u8,
28 "GREEN (nx_restage_gate 8/8: target-sanitizer safety KATs -- path-escape/slash/dot/space/empty/overlong all REJECTED; copy + ELF-magic verify + atomic rename proven LIVE -- self-staged 17236B locally + restaged nx_swcompare_sota 35291B on the NAS, making /compare/llm's verdict source-derived from @verdict). Cap 72130 least-authority, revocable via cap_revoked.list." as *u8)
29 let p: *i64 = sys_mmap(8) as *i64
30 let l: *i64 = sys_mmap(8) as *i64
31 let g: i64 = tool_get("nx_restage" as *u8, p, l)
32 sr_puts(" nx_restage put-rc=" as *u8); sr_putn(w); sr_puts(" readback=" as *u8)
33 if g == 1 { if l[0] > 0 {
34 sr_puts("OK len=" as *u8); sr_putn(l[0]); sr_puts("\nverdict=GREEN (nx_restage discoverable -> mcp__nishi__nx_restage stub)\n" as *u8)
35 sys_exit(0); return 0
36 } }
37 sr_puts("MISSING -- REGISTER FAILED\nverdict=RED\n" as *u8)
38 sys_exit(1); return 1
39}