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 cc_advise sys_mmap ↻ sts_load ss_open_cached ssc_init sys_mmap ↻ ssc_sig_of ss_cat sys_fstatat ssc_streq ss_open ss_open2 sys_mmap ↻ ss_manifest_dyn ss_cat ↻ ss_loadfile ss_load_aux2 ssl_total_keys ssl_pow2 ssl_build ss_r32 ssl_lookup ss_manifest_free sys_munmap ssc_retire_handle sts_mm sys_mmap ↻ sts_werr sys_write ↻ sys_exit ↻ ss_hget sys_mmap ↻ ss_idx_find

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