nx_memindex_emit.nx
buildroot/runtime/nx_memindex_emit.nx
about
nx_memindex_emit.nx -- splice the DERIVED index into a curated markdown file (the MEMORY.md
wiring of the conflict-free coindex rail). Sessions APPEND entries to the journal (nx_coindex
append -- never editing the shared file); THIS organ is the single writer that regenerates the
auto-derived section between whole-line markers:
<!-- COINDEX:BEGIN --> ...derived lines (last-write-wins per slug)... <!-- COINDEX:END -->
Everything OUTSIDE the markers is preserved BYTE-IDENTICAL (curated sections stay human).
FAIL-CLOSED: missing markers -> file untouched. ATOMIC: tmp + fsync + renameat. Serialized
under <journal>.lock.
EVICTION (2026-07-31, debt 1785558752): the budget gate has always specified a SPLIT -- newest
entries stay live in the md block, oldest move into an overflow file COINDEX-OVFL block, nothing
is ever lost -- but that capability WAS NEVER IMPLEMENTED. This organ contained zero references
to the overflow file, so 4 gate teeth were testing a feature that did not exist, and the whole
memindex family read as broken logic when it was in fact an ABSENT CAPABILITY. Built here rather
than deleting the teeth (rule 25: build intelligence, never strip features).
WHY EVICTION AND NOT REFUSAL: refusing protects the file but leaves the index stale forever, and
the harness drops everything past its hard load cliff SILENTLY and TAIL-FIRST. Moving the oldest
entries to an overflow file is NOT silent shrinking -- every entry still exists in exactly one of
the two blocks (additive, rule 13), and the budget is actually enforced instead of wished for.
usage: nx_memindex_emit <journal> <md> [ovfl] [budget] -- legacy: <journal> <md> [budget]
The 3rd arg is disambiguated BY CONTENT: all-digits => legacy budget, otherwise the overflow
path. That keeps the pre-existing 4th-arg-is-budget contract working (rule 19).
With an overflow file the budget measures the DERIVED SECTION; without one it measures the
WHOLE composed file and the organ REFUSES rather than write over budget (unchanged behaviour).
license_tier: ORIGINAL expect_exit: 0
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_coindex_core.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 31 | const MI_DEFAULT_BUDGET: i64 = 17100 |
| 32 | const K_1024: i64 = 1024 |
| 33 | const K_262144: i64 = 262144 |
| 34 | const K_262143: i64 = 262143 |
| 35 | const MI_NL: i64 = 10 |
| 36 | const MI_MODE: i64 = 420 |
functions
| 47 | func m_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 50 | func mi_atoi(s: *u8) -> i64 called by 1: main |
| 56 | func m_putn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 59 | func m_find(hay: *u8, n: i64, needle: *u8) -> i64 |
| 77 | func mi_splice() -> i64 |
| 122 | func mi_cut(d: *u8, dn: i64, budget: i64) -> i64 called by 1: main |
| 142 | func main(argc: i64, argv: *i64) -> i64 |