code wiki / (root) / nx_lorebook.nx

nx_lorebook.nx

buildroot/runtime/nx_lorebook.nx

10327 B202 linesdepth 2pulls 2 transitivereach 10 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_lorebook.nx -- THE LOREBOOK PLANE (companionchat CC3): keyed world entries as DATA, injected into the chat turn ONLY when the turn touches one of an entry's trigger terms, under an insertion budget that REFUSES LOUDLY instead of truncating. Rows (knowledge/lorebook.conf -- daemon cwd first, then the nishihost tree, the gen_chat_budget.conf idiom): key|trigger1, trigger2, ...|entry text (# comments and blank lines skipped) @budget N (total bytes the [WORLD] block may carry, header included) A row with fewer than three fields is skipped and COUNTED as malformed, never guessed at. Matching is an ASCII case-insensitive substring of a trimmed trigger inside the user turn (non-ASCII case folding is deliberately not done -- a documented imprecision, not an accident); an entry fires at most once per turn however many of its triggers match; a turn that touches no trigger writes ZERO bytes (the neg-control). When the fired entries would exceed the budget, NOTHING is injected partially: out carries one refusal line naming the bytes wanted and the budget, and stats[LB_ST_REFUSED]=1, so the persona is never silently cut and the caller can log the refusal rather than the model reading half a fact. Contract symbol: em_lorebook (the companionchat.matrix CC3 watch). Composed by nx_companion_mind into the chat turn. stats[]: LB_ST_ROWS parsed rows, LB_ST_MALFORMED, LB_ST_FIRED, LB_ST_WANTED bytes, LB_ST_BUDGET effective, LB_ST_REFUSED 0/1. Gate: nx_lorebook_gate (fixture confs under /tmp/<gate>/, written at run time). license_tier: ORIGINAL

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_lorebook.nx nx_companion_mind.nx nx_lorebook_gate.nx

imports: nx_syscalls.nx

imported by: nx_companion_mind.nxnx_lorebook_gate.nx

structs

none

consts

17const LB_CONF_REL: *u8 = "knowledge/lorebook.conf" as *u8
18const LB_CONF_ABS: *u8 = "/volume1/homes/elderwesto/nishihost/knowledge/lorebook.conf" as *u8
21const LB_BUDGET_DEFAULT: i64 = 4096
22const LB_STATS_N: i64 = 8
23const LB_ST_ROWS: i64 = 0
24const LB_ST_MALFORMED: i64 = 1
25const LB_ST_FIRED: i64 = 2
26const LB_ST_WANTED: i64 = 3
27const LB_ST_BUDGET: i64 = 4
28const LB_ST_REFUSED: i64 = 5
30const LB_REFUSE_MIN_CAP: i64 = 256
31const LB_ACC_HEADROOM: i64 = 4096
32const LB_NUM_CAP: i64 = 24
33const LB_DEC_BASE: i64 = 10
34const LB_CH_NL: i64 = 10
35const LB_CH_CR: i64 = 13
36const LB_CH_SPACE: i64 = 32
37const LB_CH_HASH: i64 = 35
38const LB_CH_AT: i64 = 64
39const LB_CH_PIPE: i64 = 124
40const LB_CH_COMMA: i64 = 44
41const LB_CH_0: i64 = 48
42const LB_CH_9: i64 = 57
43const LB_CH_A_UP: i64 = 65
44const LB_CH_Z_UP: i64 = 90
45const LB_CASE_DELTA: i64 = 32
46const LB_BUDGET_KEY: *u8 = "@budget" as *u8
47const LB_HEAD: *u8 = "[WORLD -- facts about the world this conversation just touched; treat them as true and use the exact detail]\n" as *u8
48const LB_ITEM: *u8 = "- " as *u8
49const LB_SEP: *u8 = ": " as *u8
50const LB_REFUSE_HEAD: *u8 = "[WORLD refused: the entries this turn touched need " as *u8
51const LB_REFUSE_MID: *u8 = " bytes against a lorebook budget of " as *u8
52const LB_REFUSE_TAIL: *u8 = " -- raise @budget in lorebook.conf or split the entries; nothing was injected partially]\n" as *u8

functions

54func lb_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 1: em_lorebook_from
55func lb_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64 = off; var i: i64 = 0; while s[i] != (0 as u8) { dst[o] = s[i]; o = o + 1; i = i + 1 } return o }
called by 1: em_lorebook_from
56func lb_catn(dst: *u8, off: i64, src: *u8, n: i64) -> i64 { var o: i64 = off; var i: i64 = 0; while i < n { dst[o] = src[i]; o = o + 1; i = i + 1 } return o }
called by 1: em_lorebook_from
57func lb_itoa(dst: *u8, off: i64, v: i64) -> i64
called by 1: em_lorebook_from calls 1: sys_mmap
65func lb_lower(c: i64) -> i64 { if c >= LB_CH_A_UP { if c <= LB_CH_Z_UP { return c + LB_CASE_DELTA } } return c }
called by 1: lb_ci_find
68func lb_ci_find(hay: *u8, hn: i64, needle: *u8, nn: i64) -> i64
87func lb_triggers_hit(trig: *u8, tn: i64, umsg: *u8, umlen: i64) -> i64
called by 1: em_lorebook_from calls 1: lb_ci_find
110func em_lorebook_from(path: *u8, umsg: *u8, umlen: i64, out: *u8, cap: i64, stats: *i64) -> i64
196func em_lorebook(umsg: *u8, umlen: i64, out: *u8, cap: i64, stats: *i64) -> i64