code wiki / (root) / nx_service.nx

nx_service.nx

buildroot/runtime/nx_service.nx

10559 B333 linesdepth 3pulls 3 transitivereach 6 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_service.nx -- SERVICE BASE rung. The shared harness every domain organ inherits to become an MCP tool + HTTP-drivable API endpoint: a JSON response-builder object, a versioned envelope, structured errors, and a verb dispatcher. This is the base class of the whole lab-science / go-to-market service family -- write it once, and every facade over the existing library modules is a thin skin on top. WHY A BASE AND NOT A COPY PER SERVICE. Seventeen library organs already exist as pure functions. Turning each into a standalone tool by hand would duplicate the envelope, the escaping, the error shape and the dispatch seventeen times -- the exact copy-paste this codebase forbids. Instead a facade composes: it owns a verb table and handlers, and delegates all of the wire format to NxJson + the nsvc_* envelope here. Rule 15 (DRY through a shared library), rule 6 (OOP: NxJson is an object with methods), rule 12 (structured errors at the boundary), rule 19 (a VERSIONED contract). AGENTIC + WORKFLOW READY BY CONSTRUCTION. Every reply is machine-readable JSON with a stable envelope, every handler is a PURE stateless function of its arguments, and every facade exposes a `describe` verb that emits its own verb catalog -- the service-level analog of MCP tools/list, so an agent can discover a facade's capabilities without a human in the loop. Stateless + structured + self-describing is exactly what a pipeline stage or an LLM tool call consumes. SCALES BY BEING STATELESS. No handler holds state between calls; the whole object is a per-request scratch buffer. N concurrent callers are N independent invocations, so horizontal scale is free -- fork more workers. TRUNCATION IS MARKED, NEVER SILENT. The response buffer is bounded; an overflow sets ov=1 and the envelope reports "truncated":true rather than emitting invalid JSON. A parser must never receive a lie. genealogy_id: service_infrastructure + nishi_sovereign_api

dependencies 2 imports · 6 importers

nx_syscalls.nx nx_grounding.nx nx_service.nx nx_finance_svc.nx nx_gtm_svc.nx nx_labsci_svc.nx nx_legal_svc.nx nx_plan_svc.nx nx_qc_svc.nx

imports: nx_syscalls.nxnx_grounding.nx

imported by: nx_finance_svc.nxnx_gtm_svc.nxnx_labsci_svc.nxnx_legal_svc.nxnx_plan_svc.nxnx_qc_svc.nx

structs

77struct NxJson

consts

37const NSVC_MAGIC_4096: i64 = 4096
41const NSVC_API_VERSION: i64 = 1
45const NSVC_OK: i64 = 0
46const NSVC_ERR_UNKNOWN_VERB: i64 = 1 // 404
47const NSVC_ERR_BAD_ARGS: i64 = 2 // 400
48const NSVC_ERR_NOT_FOUND: i64 = 3 // 404
49const NSVC_ERR_REFUSED: i64 = 4 // 422 (fail-closed domain refusal)
50const NSVC_ERR_INTERNAL: i64 = 5 // 500

functions

52func nsvc_err_status(code: i64) -> i64
called by 1: nsvc_error
61func nsvc_err_slug(code: i64) -> *u8
called by 1: nsvc_error
84func nx_json_new(cap: i64) -> *NxJson
called by 6: mainmainmainmainmainmain calls 1: sys_mmap
97func nj_putc(j: *NxJson, ch: i64) -> i64
109func nj_puts(j: *NxJson, s: *u8) -> i64
119func nj_puti(j: *NxJson, v: i64) -> i64
called by 2: qc_msmsnj_kv_int calls 2: nj_putcsys_mmap
147func nj_putstr(j: *NxJson, s: *u8) -> i64
called by 2: nj_keynj_kv_str calls 1: nj_putc
168func nj_key(j: *NxJson, k: *u8) -> i64
174func nj_comma(j: *NxJson) -> i64
180func nj_kv_int(j: *NxJson, k: *u8, v: i64) -> i64
186func nj_kv_str(j: *NxJson, k: *u8, v: *u8) -> i64
192func nj_kv_bool(j: *NxJson, k: *u8, v: i64) -> i64
199func nj_flush(j: *NxJson) -> i64
called by 6: mainmainmainmainmainmain calls 1: sys_write
205func nj_len(j: *NxJson) -> i64
221func nsvc_ok_open(j: *NxJson, svc: *u8, verb: *u8) -> i64
236func nsvc_ok_close(j: *NxJson) -> i64
251func nsvc_ground(j: *NxJson, tier: i64) -> i64
263func nsvc_ok_close_g(j: *NxJson, tier: i64) -> i64
270func nsvc_error(j: *NxJson, svc: *u8, verb: *u8, code: i64, detail: *u8) -> i64
296func nsvc_arg(argc: i64, argv: *i64, k: i64) -> *u8
302func nsvc_streq(a: *u8, b: *u8) -> i64
314func nsvc_atoi(s: *u8) -> i64
called by 1: nsvc_arg_int
330func nsvc_arg_int(argc: i64, argv: *i64, k: i64) -> i64