code wiki / (root) / nx_stale_check_tool_register.nx

nx_stale_check_tool_register.nx source

↩ module page · 34 lines · 3021 B

1// nx_stale_check_tool_register.nx -- register nx_stale_check into the discovery registry so it appears 2// in /api/tools + /mcp tools/list (mcp__nishi__nx_stale_check stub). Mirrors nx_restage_tool_register. 3// Run on the NAS (CWD nishihost) to flip the LIVE registry. Idempotent; verifies by READBACK. 4// expect_exit: 0 license_tier: ORIGINAL 5import "nx_tool_registry.nx" 6 7func 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 } 8func sr_putn(v: i64) -> i64 { 9 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 10 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 11 let d: *u8 = sys_mmap(24); var k: i64 = 0 12 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 13 let o: *u8 = sys_mmap(24); var i: i64 = 0 14 while i < k { o[i] = d[k - 1 - i]; i = i + 1 } 15 sys_write(1, o, k); return 0 16} 17 18func main() -> i64 { 19 sr_puts("=== nx_stale_check_tool_register -- deploy-drift detector into the discovery registry ===\n" as *u8) 20 let w: i64 = tool_register("nx_stale_check" as *u8, 21 "SAFE (detect-only, never writes) deploy-drift detector -- the companion to nx_restage. Rebuilds a build tree's <target> from source and byte-compares to the DEPLOYED _offc/<target>.elf to answer 'is this generator current vs its source?'. Guards the stub-source trap that a naive byte-diff falls into (a same-basename .nx can be a do-nothing SMOKE stub while the real tool was built from <target>_cli.nx): reports AMBIGUOUS (wrong source, do NOT restage) when the fresh elf is far smaller than the deployed one. Cannot break a tool -- it only reads + rebuilds to /tmp." as *u8, 22 "over /mcp: tools/call name=nx_stale_check arguments={argv:[TARGET, BROOT?]}. e.g. {argv:[\"nx_swcompare_sota\"]} (BROOT defaults to \"buildroot\"). Emits one line: CURRENT <t> (NB match) | STALE <t> (fresh!=deployed; fix via nx_restage then VERIFY) | AMBIGUOUS <t> (stub source -- do not restage) | NOSOURCE | BUILDFAIL | NOELF. Exit 0=CURRENT 1=STALE 2=AMBIGUOUS/error." as *u8, 23 "GREEN (validated LIVE on NAS: nx_swcompare_sota + nx_maturity_board -> CURRENT with byte-exact size match; tools not in buildroot/_offc -> NOELF honest-scope; deterministic-compiler byte-compare core proven via nx_restage CURRENT). Detect-only = cannot break a tool. Born from the 2026-07-17 bulk-restage incident whose stub-source trap this tool's AMBIGUOUS guard exists to catch. Cap 72131, revocable." as *u8) 24 let p: *i64 = sys_mmap(8) as *i64 25 let l: *i64 = sys_mmap(8) as *i64 26 let g: i64 = tool_get("nx_stale_check" as *u8, p, l) 27 sr_puts(" nx_stale_check put-rc=" as *u8); sr_putn(w); sr_puts(" readback=" as *u8) 28 if g == 1 { if l[0] > 0 { 29 sr_puts("OK len=" as *u8); sr_putn(l[0]); sr_puts("\nverdict=GREEN (nx_stale_check discoverable -> mcp__nishi__nx_stale_check stub)\n" as *u8) 30 sys_exit(0); return 0 31 } } 32 sr_puts("MISSING -- REGISTER FAILED\nverdict=RED\n" as *u8) 33 sys_exit(1); return 1 34}