code wiki / (root) / nx_genui_tool_register.nx

nx_genui_tool_register.nx source

↩ module page · 73 lines · 4836 B

1// nx_genui_tool_register.nx -- register the GEN capabilities (image + 3D + companion) into the sovereign tool 2// registry (operator 2026-07-05: "add these capabilities into our synthetic human workstream as APIs ... so 3// Elara can have a wide range of behavior"). The registry IS what /api/tools + /mcp tools/list serve, so 4// registration = discoverability for any orchestrating agent (Elara's agency loop included). DISCOVERY only: 5// runnable-over-/mcp stays a SEPARATE fail-closed step (tool_allowlist.conf + cap token, operator-gated). 6// Idempotent (reg_put is additive, history kept -- safe to run twice). Verifies by READBACK, not by claim. 7// expect_exit: 0 license_tier: ORIGINAL 8import "nx_tool_registry.nx" 9 10func gr_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 gr_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 // write-once: buffer HOISTED (was a per-char sys_mmap(1) inside the loop = mmap-in-loop leak-by-construction) 18 let o: *u8 = sys_mmap(24); var i: i64 = 0 19 while i < k { o[i] = d[k - 1 - i]; i = i + 1 } 20 sys_write(1, o, k) 21 return 0 22} 23 24func gr_reg1(name: *u8, desc: *u8, invoke: *u8, status: *u8) -> i64 { 25 let w: i64 = tool_register(name, desc, invoke, status) 26 let p: *i64 = sys_mmap(8) as *i64 27 let l: *i64 = sys_mmap(8) as *i64 28 let g: i64 = tool_get(name, p, l) 29 gr_puts(" "); gr_puts(name); gr_puts(" put-rc="); gr_putn(w); gr_puts(" readback=") 30 if g == 1 { if l[0] > 0 { 31 gr_puts("OK len="); gr_putn(l[0]); gr_puts("\n") 32 return 1 33 } } 34 gr_puts("MISSING -- REGISTER FAILED\n") 35 return 0 36} 37 38func main() -> i64 { 39 gr_puts("=== nx_genui_tool_register -- gen capabilities into the discovery registry (knowledge/toolreg-) ===\n") 40 var ok: i64 = 0 41 ok = ok + gr_reg1("gen_image" as *u8, 42 "text->image batch via the NAS gen orchestrator into the CID gallery (Z-Image on the 5080 worker)" as *u8, 43 "POST /gen/api/generate {prompt,negative,width,height,steps,cfg,seed,count,sampler} (OPAQUE-gated); results GET /gen/img/<cid> + /gen/api/recent" as *u8, 44 "GREEN (nx_gen_orchestrator_gate 3/3 + realpipe; LIVE nishifamily.com/gen)" as *u8) 45 ok = ok + gr_reg1("gen_upscale" as *u8, 46 "sovereign 2x-4x image upscale (bilinear Q16.16, CID-addressed) of stored gens" as *u8, 47 "GET /upscale/<CID>?s=<n> (gallery daemon, fork-per-request); organ nx_galx_upscale one <src.png> <out.png> [scale]" as *u8, 48 "GREEN (sovereign codecs compose; AI super-res = future GPU rung)" as *u8) 49 ok = ok + gr_reg1("t2mesh" as *u8, 50 "text -> watertight 3D mesh, parametric SDF templates v0 (8+ objects, vocabulary grows as data)" as *u8, 51 "organ nx_t2mesh: prompt keywords -> template -> field -> surface-nets -> knowledge/t2m_<obj>.stl" as *u8, 52 "GREEN (nx_t2mesh_gate: 8 distinct closed meshes; the CF-studio capability, UI surfacing = rung G2)" as *u8) 53 ok = ok + gr_reg1("i2mesh" as *u8, 54 "image/mask -> 3D mesh v0 by silhouette inflation (mask -> chamfer DT -> field -> surface-nets)" as *u8, 55 "organ nx_i2mesh: mask -> knowledge/i2m_<name>.stl; real Z-Image PNG->mask wire = rung G3" as *u8, 56 "GREEN v0 (nx_i2mesh_gate; synthetic-mask proven, single-view honest ceiling)" as *u8) 57 ok = ok + gr_reg1("sdf2mesh" as *u8, 58 "any signed-distance field -> watertight tri-mesh (surface nets) + STL export" as *u8, 59 "lib nx_meshgen: field -> verts/tris -> STL (the bridge t2mesh/i2mesh feed)" as *u8, 60 "GREEN (nx_meshgen_gate 6/6 incl closed-manifold Euler check)" as *u8) 61 ok = ok + gr_reg1("companion_photo" as *u8, 62 "Elara shares a grounded self-photo: visual arc advances (outfit/scene/pose), memory records the exact look" as *u8, 63 "companion_share_photo (nx_companion_photo: nx_visual_arc advance -> POST /gen/api/generate -> mem_append)" as *u8, 64 "GREEN (nx_companion_photo_gate 3/3; what she shares == what she recalls)" as *u8) 65 66 gr_puts("registered+readback "); gr_putn(ok); gr_puts(" / 6\n") 67 gr_puts("NOTE: this is the LOCAL SSOT registry (knowledge/toolreg-). The LIVE NAS registry behind\n") 68 gr_puts(" nishifamily.com/api/tools is a separate store -- flipping it live = a deploy step (operator-gated),\n") 69 gr_puts(" as is any tool_allowlist.conf row that would make these RUNNABLE over /mcp (fail-closed today).\n") 70 if ok == 6 { gr_puts("verdict=GREEN (6 capabilities discoverable; Elara-facing behavior surface widened)\n"); sys_exit(0); return 0 } 71 gr_puts("verdict=RED\n") 72 sys_exit(1); return 1 73}