code wiki / (root) / nx_chat_demo_unicode_t59.nx

nx_chat_demo_unicode_t59.nx

buildroot/runtime/nx_chat_demo_unicode_t59.nx

19797 B458 linesdepth 5pulls 8 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 5 imports · 1 importers

nx_syscalls.nx nx_itoa_lib.nx nx_store_seed_lib.nx nx_seg_store.nx nx_utf8.nx nx_chat_demo_unicode_t59.nx nx_chat_unicode_gate_t59.nx

imports: nx_syscalls.nxnx_itoa_lib.nxnx_store_seed_lib.nxnx_seg_store.nxnx_utf8.nx

imported by: nx_chat_unicode_gate_t59.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_v2 cda_post_mode 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 nxa_dump_sizes sts_werr sys_write ↻ sys_exit ↻ cda_ident cda_w ↻ cda_text utf8_validate cda_text_legacy cda_demoroom csa_append cda_confn sts_mm ↻ cda_confs sts_mm ↻ sys_read_file cda_len sts_atoi sts_mm ↻

structs

none

consts

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

functions

46func 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 }
47func cda_wn(s: *u8, n: i64) -> i64 { sys_write(1, s, n); return 0 }
called by 2: cda_post_modecda_list calls 1: sys_write
48func cda_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
49func cda_eq(a: *u8, b: *u8) -> i64
called by 2: mainmain
55func cda_ident(src: *u8, dst: *u8, cap: i64) -> i64
71func cda_text_legacy(src: *u8, dst: *u8, cap: i64) -> i64
called by 1: cda_post_mode
83func cda_text(src: *u8, dst: *u8, cap: i64) -> i64
called by 2: cda_post_modemain calls 1: utf8_validate
97func cda_demoroom(clean: *u8, out: *u8) -> i64
106func cda_jesc(out: *u8, o: i64, s: *u8, n: i64) -> i64
called by 2: cda_listmain calls 1: cda_hexe
119func cda_hexe(src: *u8, n: i64, dst: *u8) -> i64
131func cda_hexv(c: i64) -> i64
called by 1: cda_list
136func cda_catn(d: *u8, o: i64, v: i64) -> i64
called by 2: cda_post_modecda_list calls 1: sys_mmap
146func 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 }
147func cda_confs(key: *u8, out: *u8, cap: i64) -> i64
176func cda_confn(key: *u8) -> i64
called by 1: csa_append calls 3: sts_mmcda_confssts_atoi
182func cda_prefix(room: *u8, out: *u8) -> i64
called by 2: csa_appendcsa_fetch calls 2: cda_confsss_cat
192func cda_rowbuild(seq: i64, kind: i64, sender: *u8, body: *u8, blen: i64, out: *u8) -> i64
206func cda_delkey(seq: i64, out: *u8) -> i64
called by 1: csa_fetch calls 2: ss_catss_catn
212func cda_put_key(prefix: *u8, key: *u8, val: *u8, vlen: i64) -> i64
218func csa_append(room: *u8, sender: *u8, body: *u8, blen: i64) -> i64
283func csa_fetch(room: *u8, since: i64, maxn: i64, outbuf: *u8, outcap: i64) -> i64
319func cda_post_mode(room_in: *u8, name_in: *u8, text_in: *u8, version:i64) -> i64
350func cda_post(room_in:*u8,name_in:*u8,text_in:*u8)->i64 {return cda_post_mode(room_in,name_in,text_in,1)}
called by 1: main calls 1: cda_post_mode
351func cda_post_v2(room_in:*u8,name_in:*u8,text_in:*u8)->i64 {return cda_post_mode(room_in,name_in,text_in,2)}
called by 1: main calls 1: cda_post_mode
352func 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
353func cda_list(room_in: *u8, since_in: *u8) -> i64
430func cda_usage() -> i64
called by 1: main calls 1: cda_w
434func main(argc: i64, argv: *i64) -> i64