nx_service.nx
buildroot/runtime/nx_service.nx
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
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
| 77 | struct NxJson |
consts
| 37 | const NSVC_MAGIC_4096: i64 = 4096 |
| 41 | const NSVC_API_VERSION: i64 = 1 |
| 45 | const NSVC_OK: i64 = 0 |
| 46 | const NSVC_ERR_UNKNOWN_VERB: i64 = 1 // 404 |
| 47 | const NSVC_ERR_BAD_ARGS: i64 = 2 // 400 |
| 48 | const NSVC_ERR_NOT_FOUND: i64 = 3 // 404 |
| 49 | const NSVC_ERR_REFUSED: i64 = 4 // 422 (fail-closed domain refusal) |
| 50 | const NSVC_ERR_INTERNAL: i64 = 5 // 500 |
functions
| 52 | func nsvc_err_status(code: i64) -> i64 called by 1: nsvc_error |
| 61 | func nsvc_err_slug(code: i64) -> *u8 called by 1: nsvc_error |
| 84 | func nx_json_new(cap: i64) -> *NxJson |
| 97 | func nj_putc(j: *NxJson, ch: i64) -> i64 |
| 109 | func nj_puts(j: *NxJson, s: *u8) -> i64 called by 8: fin_describegtm_describelab_describeleg_describeplan_describeqc_describe+2 calls 1: nj_putc |
| 119 | func nj_puti(j: *NxJson, v: i64) -> i64 |
| 147 | func nj_putstr(j: *NxJson, s: *u8) -> i64 |
| 168 | func nj_key(j: *NxJson, k: *u8) -> i64 called by 12: fin_describegtm_describelab_describeleg_describeplan_describeqc_describe+6 calls 2: nj_putstrnj_putc |
| 174 | func nj_comma(j: *NxJson) -> i64 called by 59: fin_describefin_dcf_verdictfin_bond_pricefin_bond_durationfin_taxlot_washfin_amort_schedule+53 calls 1: nj_putc |
| 180 | func nj_kv_int(j: *NxJson, k: *u8, v: i64) -> i64 called by 61: fin_describefin_dcf_verdictfin_dcf_terminalfin_bond_pricefin_bond_ytmfin_bond_duration+55 calls 2: nj_keynj_puti |
| 186 | func nj_kv_str(j: *NxJson, k: *u8, v: *u8) -> i64 called by 39: fin_describefin_dcf_verdictfin_bond_pricegtm_describegtm_ingredient_infogtm_claims_classify+33 calls 2: nj_keynj_putstr |
| 192 | func nj_kv_bool(j: *NxJson, k: *u8, v: i64) -> i64 |
| 199 | func nj_flush(j: *NxJson) -> i64 |
| 205 | func nj_len(j: *NxJson) -> i64 |
| 221 | func nsvc_ok_open(j: *NxJson, svc: *u8, verb: *u8) -> i64 |
| 236 | func nsvc_ok_close(j: *NxJson) -> i64 |
| 251 | func nsvc_ground(j: *NxJson, tier: i64) -> i64 |
| 263 | func nsvc_ok_close_g(j: *NxJson, tier: i64) -> i64 |
| 270 | func nsvc_error(j: *NxJson, svc: *u8, verb: *u8, code: i64, detail: *u8) -> i64 |
| 296 | func nsvc_arg(argc: i64, argv: *i64, k: i64) -> *u8 |
| 302 | func nsvc_streq(a: *u8, b: *u8) -> i64 |
| 314 | func nsvc_atoi(s: *u8) -> i64 called by 1: nsvc_arg_int |
| 330 | func nsvc_arg_int(argc: i64, argv: *i64, k: i64) -> i64 called by 10: maingtm_dispatchlab_stability_mktlab_stability_separatelab_dispatchmain+4 calls 2: nsvc_argnsvc_atoi |