code wiki / _hdl_build / nx_ctxcost.nx

nx_ctxcost.nx

buildroot/runtime/_hdl_build/nx_ctxcost.nx

6901 B147 linesdepth 5pulls 8 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_ctxcost.nx -- CONTEXT-COST ADVISOR (operator 2026-07-21: 'make nishi SEE the cost if it can, flag to you what we should do as you work a workstream'). MEASURED real usage 2026-07-21: 96pct of spend at >150k context; 71pct from nishi MCP results that STAY in context re-read every turn. So: given the current context_pct (relayed from the Claude Code usage banner -- nishi can't read live context, so the caller feeds the number it CAN see), advise CONTINUE / COMPACT-SOON / COMPACT-NOW from data-driven thresholds in ctxbudget- (rule-11, tune without code). Reminds of the cheap-reboot: /clear then nx_seat boot = ~1KB (state lives in planes). Composes nx_sovjson_lib (sj_*) = OO, 5th base consumer. advise <context_pct> [ws] [ctxbudgetprefix] -> verdict JSON | selftest [tmpbase] ctxbudget- row = id threshold_pct verdict action reason (5-col policy plane; pick highest thr <= pct). license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0

dependencies 5 imports · 0 importers

nx_sovjson_lib.nx nx_store_seed_lib.nx nx_seg_store.nx nx_gate_verdict.nx nx_syscalls.nx nx_ctxcost.nx

imports: nx_sovjson_lib.nxnx_store_seed_lib.nxnx_seg_store.nxnx_gate_verdict.nxnx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main sj_werr sys_write sys_exit sj_lit_eq sj_vlen 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 ↻ cc_advise sys_mmap ↻ sts_load sts_gen_note sts_pfxhash ss_max_segid sys_mmap ↻ ss_cat ss_readall sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close ss_segid_ok ss_open_cached ssc_init sys_mmap ↻ ssc_sig_of

structs

none

consts

17const CC_CAP: i64 = 1048576
18const CC_OUT: i64 = 8192
19const CC_SPAN: i64 = 16
20const CC_USAGE: i64 = 2

functions

22func cc_advise(pct: i64, ws: *u8, prefix: *u8, out: *u8) -> i64
73func cc_selftest(base: *u8) -> i64
115func main(argc: i64, argv: *i64) -> i64