code wiki / (root) / nx_tool_registry.nx

nx_tool_registry.nx source

↩ module page · 29 lines · 2051 B

1// nx_tool_registry.nx -- MCP Tools-primitive parity, sovereign: every Nishi organ/capability registers itself 2// (name / description / how-to-invoke / gate-status) and is DISCOVERABLE. Backed by the canonical nx_registry on 3// seg_store (additive, history kept). The registry IS the capability list the census measures -> one source of truth. 4// Record (tab-separated): name <TAB> description <TAB> invoke <TAB> status. license_tier: ORIGINAL 5import "nx_registry.nx" 6import "nx_tabrec.nx" 7const TOOL_MAGIC_2048: i64 = 2048 8 9const TOOL_KP: *u8 = "tool:" as *u8 10const TOOL_IDX: *u8 = "__toolidx__" as *u8 11const TOOL_PREFIX: *u8 = "knowledge/toolreg-" as *u8 12 13func tool_register_pfx(prefix: *u8, name: *u8, desc: *u8, invoke: *u8, status: *u8) -> i64 { 14 let rec: *u8 = sys_mmap(TOOL_MAGIC_2048); var o: i64=0 15 o=tr_cat(rec,o,name); o=tr_tab(rec,o); o=tr_cat(rec,o,desc); o=tr_tab(rec,o); o=tr_cat(rec,o,invoke); o=tr_tab(rec,o); o=tr_cat(rec,o,status) 16 return reg_put(prefix, TOOL_KP, TOOL_IDX, name, rec, o) 17} 18func tool_get_pfx(prefix: *u8, name: *u8, ptrout: *i64, lenout: *i64) -> i64 { return reg_get(prefix, TOOL_KP, name, ptrout, lenout) } 19// SIZE-TO-NEED: the caller receives a buffer sized to the index instead of stating 20// a capacity. The 64 KiB ceiling this replaces guarded the LIVE "what tools exist" 21// surface -- past it reg_index returns -1, and nx_tools_api fed that straight into 22// a walk, so the tool list would have rendered EMPTY rather than failing loudly. 23// bufout[0] receives the buffer; the return value is its byte length. 24func tool_list_pfx(prefix: *u8, bufout: *i64) -> i64 { return reg_index_read(prefix, TOOL_IDX, bufout) } 25 26// production-prefix convenience wrappers 27func tool_register(name: *u8, desc: *u8, invoke: *u8, status: *u8) -> i64 { return tool_register_pfx(TOOL_PREFIX, name, desc, invoke, status) } 28func tool_get(name: *u8, ptrout: *i64, lenout: *i64) -> i64 { return tool_get_pfx(TOOL_PREFIX, name, ptrout, lenout) } 29func tool_list(bufout: *i64) -> i64 { return tool_list_pfx(TOOL_PREFIX, bufout) }