nx_fsops_tool_register.nx source
↩ module page · 45 lines · 4500 B
1// nx_fsops_tool_register.nx -- register the consolidated filesystem tools into the discovery registry:
2// nx_fs (READ class -> mcp__nishi__nx_fs) AND nx_fs_write (WRITE class, its own cap -> mcp__nishi__nx_fs_write).
3// Binaries nx_fsops.elf / nx_fs_write.elf (the nx_fs.nx source name belongs to the file-I/O stdlib).
4// Idempotent; verifies BOTH by READBACK. expect_exit: 0 license_tier: ORIGINAL
5import "nx_tool_registry.nx"
6
7const ASCII_0: i64 = 48 // named so this registrar is itself rule-11 clean
8
9func fr_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
10func fr_putn(v: i64) -> i64 {
11 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
12 var m: i64 = v
13 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
14 let d: *u8 = sys_mmap(24); var k: i64 = 0
15 while m > 0 { d[k] = (ASCII_0 + (m % 10)) as u8; m = m / 10; k = k + 1 }
16 let o: *u8 = sys_mmap(24); var i: i64 = 0
17 while i < k { o[i] = d[k - 1 - i]; i = i + 1 }
18 sys_write(1, o, k)
19 return 0
20}
21
22func main() -> i64 {
23 fr_puts("=== nx_fsops_tool_register -- consolidated fs tool (nx_fs) into the discovery registry ===\n" as *u8)
24 let w: i64 = tool_register("nx_fs" as *u8,
25 "Consolidated filesystem tool (READ-ONLY increment): read files + list directories on the NAS over MCP -- retires ssh-cat for remote reads. VERBS: read <path> [maxbytes] -> bytes (truncation MARKED, never silent; capped 1MiB); ls <dir> -> '<t> <name>' per entry (d/f/l/o). BOUNDARY DEFENSE: read REFUSES any path matching the secret deny-list (compiled defaults secret/key/token/passw/.pem + data-driven fs_read_deny.conf) -- key material is unreadable through this tool BY CONSTRUCTION. Write/edit = later increment behind its own cap." as *u8,
26 "over /mcp: tools/call name=nx_fs arguments={argv:[VERB,...]}. e.g. {argv:[\"read\",\"knowledge/tool_schemas.conf\"]} -> file bytes ; {argv:[\"ls\",\"knowledge\"]} -> typed listing. exit codes in _meta: 0 ok | 3 absent | 5 DENIED." as *u8,
27 "GREEN (nx_fsops_gate 16/16: exact read, MARKED truncation, default deny 'key', DATA-DRIVEN deny toggled ON->OFF both directions, absent graceful, ls count; rule-11 0-magic)" as *u8)
28 let w2: i64 = tool_register("nx_fs_write" as *u8,
29 "Consolidated filesystem tool, WRITE class (its OWN capability -- never granted by the read cap): ATOMIC file write + exact-string edit on the NAS over MCP. VERBS: write <path> <content> -> full-file ATOMIC write (.nxw<pid> tmp + fsync + rename; a reader never sees a torn file); edit <path> <old> <new> [all] -> exact-string replace with the UNIQUENESS contract (0 matches -> NOMATCH file untouched; >1 without 'all' -> AMBIGUOUS file untouched; 'all' replaces every occurrence). DENY BY CONSTRUCTION (not config-disableable): secret material (secret/key/token/passw/.pem -- key files cannot be clobbered), the OS device/kernel/firmware namespace (/dev,/sys,/proc via the nx_os_fs seam -- rule 26 never-brick holds even for a VALID write cap), and the tool allowlist (a write cap cannot re-register tools). Data-driven extras: fs_write_deny.conf. GRADED EXCEED: byte-parity vs coreutils printf+sed, Claude-Edit H2H byte-identical, 6/6." as *u8,
30 "over /mcp: tools/call name=nx_fs_write arguments={argv:[VERB,...]} + X-Nishi-Cap granting nx_fs_write. e.g. {argv:[\"write\",\"_scratch/note.txt\",\"content\"]} ; {argv:[\"edit\",\"_scratch/note.txt\",\"old\",\"new\"]} ; append \"all\" to replace every occurrence. exit codes in _meta: 0 ok | 2 usage | 3 absent | 4 io | 5 DENIED | 6 NOMATCH | 7 AMBIGUOUS." as *u8,
31 "GREEN (nx_fsops_gate 16/16 incl write-roundtrip, overwrite-whole, deny-secret-nocreate, deny-devns, deny-conf both directions, edit unique/nomatch/ambiguous/all; MCP e2e proven incl /dev/sda DENIED with a valid cap; bench 6/6 EXCEED)" as *u8)
32 let p: *i64 = sys_mmap(8) as *i64
33 let l: *i64 = sys_mmap(8) as *i64
34 let g: i64 = tool_get("nx_fs" as *u8, p, l)
35 let g2: i64 = tool_get("nx_fs_write" as *u8, p, l)
36 fr_puts(" nx_fs put-rc=" as *u8); fr_putn(w); fr_puts(" nx_fs_write put-rc=" as *u8); fr_putn(w2); fr_puts(" readback=" as *u8)
37 var okall: i64 = 0
38 if g == 1 { if g2 == 1 { if l[0] > 0 { okall = 1 } } }
39 if okall == 1 {
40 fr_puts("OK\nverdict=GREEN (nx_fs + nx_fs_write discoverable -> mcp__nishi__ stubs)\n" as *u8)
41 sys_exit(0); return 0
42 }
43 fr_puts("MISSING -- REGISTER FAILED\nverdict=RED\n" as *u8)
44 sys_exit(1); return 1
45}