code wiki / (root) / nx_chat_demo_api.nx

nx_chat_demo_api.nx

buildroot/runtime/nx_chat_demo_api.nx

18372 B430 linesdepth 5pulls 7 transitivereach 1 importersview sourcekind sketch/demotopic chat
docsdependenciesstructsconstsfunctions

about

nx_chat_demo_api.nx -- the SAFE public front for a testable persistent-chat UI backed by C1's store. v2 (2026-08-16): does the append/fetch IN-PROCESS on the seg-store, NOT by forking nx_chat_store. WHY: MEASURED via curl to /mcp -- a list (read) returned in 44ms, but a post that FORKED nx_chat_store to write hung to the tools-daemon exec deadline (~14s) and returned empty (exit -5), because the write-path grandchild orphaned under the daemon's capture. A read fork was fine; a write fork was not. In-process removes the fork entirely: this organ takes the plane lock, appends, and releases in its own process -- the exact code path nx_chat_store's gate proves, just linked instead of exec'd. Fast + no orphan. SECURITY BOUNDARY unchanged: only post/list, rooms forced into demo_, inputs sanitized + capped, budgets from C1's conf refuse loudly. Destructive verbs do not exist here. REFEREE: nx_chat_demo_api_gate. DEBT (named, not a silent twin): the append/fetch logic is duplicated from nx_chat_store; the consolidation is to extract nx_chat_store_lib that BOTH this front and the CLI import (comms.plan chatstore-lib-extract). license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 4 imports · 1 importers

nx_syscalls.nx nx_itoa_lib.nx nx_store_seed_lib.nx nx_seg_store.nx nx_chat_demo_api.nx nx_chat_unicode_probe_t58.nx

imports: nx_syscalls.nxnx_itoa_lib.nxnx_store_seed_lib.nxnx_seg_store.nx

imported by: nx_chat_unicode_probe_t58.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main cda_usage cda_w sys_write sys_exit cda_eq cda_post sts_mm sys_mmap nxa_die sys_write ↻ sys_exit ↻ nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sts_werr sys_write ↻ sys_exit ↻ cda_ident cda_w ↻ cda_text cda_demoroom csa_append cda_confn sts_mm ↻ cda_confs sts_mm ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read

structs

none

consts

18const CDA_EXIT_OK: i64 = 0
19const CDA_EXIT_USAGE: i64 = 2
20const CDA_EXIT_REFUSED: i64 = 3
21const CDA_ROOM_MAX: i64 = 24
22const CDA_NAME_MAX: i64 = 24
23const CDA_TEXT_MAX: i64 = 280
24const CDA_FETCH_MAX: i64 = 200
25const CDA_PFX_CAP: i64 = 256
26const CDA_ROW_OVH: i64 = 128
27const CDA_WSLACK: i64 = 65536
28const CDA_CONF_CAP: i64 = 192
29const CDA_OUTCAP: i64 = 262144
30const CDA_NL: i64 = 10
31const CDA_PIPE: i64 = 124
32const CDA_KIND_TEXT: i64 = 1
33const CDA_KIND_SYS: i64 = 4
34const CHATCONF: *u8 = "knowledge/comms/chatstore.conf"
35const CSA_ERR_CONF: i64 = 0 - 3
36const CSA_ERR_BODY: i64 = 0 - 10
37const CSA_ERR_LOCK: i64 = 0 - 4
38const CSA_ERR_MSGS: i64 = 0 - 11
39const CSA_ERR_BYTES: i64 = 0 - 12
40const CSA_ERR_CORRUPT: i64 = 0 - 5

functions

42func cda_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 3: cda_postcda_listcda_usage calls 1: sys_write
43func cda_wn(s: *u8, n: i64) -> i64 { sys_write(1, s, n); return 0 }
called by 2: cda_postcda_list calls 1: sys_write
44func cda_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
45func cda_eq(a: *u8, b: *u8) -> i64
called by 2: mainmain
51func cda_ident(src: *u8, dst: *u8, cap: i64) -> i64
called by 2: cda_postcda_list
66func cda_text(src: *u8, dst: *u8, cap: i64) -> i64
called by 2: cda_postmain
78func cda_demoroom(clean: *u8, out: *u8) -> i64
called by 2: cda_postcda_list
87func cda_jesc(out: *u8, o: i64, s: *u8, n: i64) -> i64
called by 1: cda_list
100func cda_hexe(src: *u8, n: i64, dst: *u8) -> i64
called by 1: cda_rowbuild
112func cda_hexv(c: i64) -> i64
called by 1: cda_list
117func cda_catn(d: *u8, o: i64, v: i64) -> i64
called by 2: cda_postcda_list calls 1: sys_mmap
127func cda_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { d[o] = s[i]; o = o + 1; i = i + 1 } return o }
called by 2: cda_postcda_list
128func cda_confs(key: *u8, out: *u8, cap: i64) -> i64
157func cda_confn(key: *u8) -> i64
called by 1: csa_append calls 3: sts_mmcda_confssts_atoi
163func cda_prefix(room: *u8, out: *u8) -> i64
called by 2: csa_appendcsa_fetch calls 2: cda_confsss_cat
173func cda_rowbuild(seq: i64, kind: i64, sender: *u8, body: *u8, blen: i64, out: *u8) -> i64
187func cda_delkey(seq: i64, out: *u8) -> i64
called by 1: csa_fetch calls 2: ss_catss_catn
193func cda_put_key(prefix: *u8, key: *u8, val: *u8, vlen: i64) -> i64
199func csa_append(room: *u8, sender: *u8, body: *u8, blen: i64) -> i64
264func csa_fetch(room: *u8, since: i64, maxn: i64, outbuf: *u8, outcap: i64) -> i64
300func cda_post(room_in: *u8, name_in: *u8, text_in: *u8) -> i64
328func cda_atoi(b: *u8, n: i64) -> i64 { var v: i64 = 0; var i: i64 = 0; while i < n { let c: i64 = b[i] as i64; if c < 48 { break } if c > 57 { break } v = v * 10 + (c - 48); i = i + 1 } return v }
called by 1: cda_list
329func cda_list(room_in: *u8, since_in: *u8) -> i64
406func cda_usage() -> i64
called by 1: main calls 1: cda_w
410func main(argc: i64, argv: *i64) -> i64