code wiki / _hdl_build / nx_eff_lib.nx

nx_eff_lib.nx

buildroot/runtime/_hdl_build/nx_eff_lib.nx

13505 B291 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind librarytopic eff
docsdependenciesstructsconstsfunctions

about

nx_eff_lib.nx -- THE efficiency-telemetry shared core (eff lane, 2026-07-18). Operator: "know from god how we are spending energy and time and tokens ... ROI driven with non-fake numbers but real estimates in time and money and energy and other savings." This lib is the ONE measurement+conversion core imported by nx_eff_scan (the CLI substrate) AND nx_eff_board (the ops/ROI dashboard) -- DRY (rule 15), so a spend number can never disagree between the two. It MEASURES (worklog gaps=time, transcript needles=tokens) and CONVERTS via DECLARED, operator-transparent coefficients (every rate emitted in the output; rule 11). - cost(money): weighted-token basis-points x cents/Mtok (Anthropic pricing SHAPE: out 5x, cache-read 0.1x, cache-write 1.25x vs uncached input 1x -- the multipliers are real; the base rate is declared). - energy: total tokens x Wh/Mtok (ESTIMATE, flagged as a research/fetch target for real per-node RAPL). - time: sum of inter-action gaps <= 300s (gap300-strict; idle beyond 5min is NOT counted as work). Every number traces to a real artifact (worklog.tsv rows, transcript usage fields); fabrication is structurally impossible (no artifact -> zero). license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 1 imports · 1 importers

nx_syscalls.nx nx_eff_lib.nx nx_eff_scan.nx

imports: nx_syscalls.nx

imported by: nx_eff_scan.nx

structs

none

consts

17const ES_NF: i64 = 10 // fields per day slot
18const ES_F_ACT: i64 = 0 // actions
19const ES_F_MCP: i64 = 1 // mcp__ tool calls
20const ES_F_SH: i64 = 2 // shell (PowerShell/Bash)
21const ES_F_FILE: i64 = 3 // file ops (Read/Edit/Write/Grep/Glob)
22const ES_F_SEC: i64 = 4 // active seconds (gap300-strict)
23const ES_F_TIN: i64 = 5 // tokens input
24const ES_F_TOUT: i64 = 6 // tokens output
25const ES_F_TCR: i64 = 7 // cache-read tokens
26const ES_F_TCW: i64 = 8 // cache-write tokens
27const ES_F_TRF: i64 = 9 // transcript files touched this day
29const ES_ENV_SLOTS: i64 = 8
30const ES_E_TRUNC: i64 = 0 // transcripts that hit the per-file cap
31const ES_E_TRF: i64 = 1 // transcript files scanned
32const ES_E_TRB: i64 = 2 // transcript bytes read
33const ES_E_WLR: i64 = 3 // worklog rows parsed
34const ES_E_WLB: i64 = 4 // worklog bytes read
36const ES_WIN_MAX: i64 = 28
37const ES_WIN_DEF: i64 = 14
38const ES_CAP_WL: i64 = 33554432 // 32MiB worklog read cap
39const ES_CAP_TR: i64 = 33554432 // 32MiB per-transcript read cap
40const ES_GAP_CAP: i64 = 300 // active-time gap ceiling (s)
41const ES_DAYSEC: i64 = 86400
42const ES_TAB: i64 = 9
43const ES_NL: i64 = 10
44const ES_QUOTE: i64 = 34
45const ES_SPACE: i64 = 32
46const ES_ZERO: i64 = 48
47const ES_NINE: i64 = 57
50const EFL_W_IN: i64 = 100
51const EFL_W_OUT: i64 = 500
52const EFL_W_CR: i64 = 10
53const EFL_W_CW: i64 = 125
54const EFL_CENTS_PER_MTOK_IN: i64 = 1500 // uncached input $15.00/Mtok (Opus-class default; declared, editable)
55const EFL_WH_PER_MTOK: i64 = 400 // ~0.4 Wh / 1k tok large-model inference (ESTIMATE; fetch-target)
56const EFL_MONEY_DIV: i64 = 100000000 // bp(x100) x per-Mtok(1e6) normalizer

functions

58func es_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
59func es_eq(a: *u8, b: *u8) -> i64
called by 1: main
65func es_atoi(s: *u8) -> i64
called by 1: main
73func es_read_bounded(path: *u8, buf: *u8, cap: i64, env: *i64) -> i64
92func es_num_at(b: *u8, n: i64, pos: i64) -> i64
104func es_slice_pfx(b: *u8, a: i64, e: i64, s: *u8) -> i64
115func es_slice_eq(b: *u8, a: i64, e: i64, s: *u8) -> i64
called by 1: es_wl_scan calls 2: es_slice_pfxes_len
121func es_match(b: *u8, n: i64, pos: i64, needle: *u8) -> i64
called by 1: es_tr_tokens
135func es_wl_maxepoch(b: *u8, n: i64) -> i64
called by 2: es_selftestmain calls 1: es_num_at
148func es_wl_scan(b: *u8, n: i64, dayw: *i64, nowday: i64, win: i64, env: *i64) -> i64
204func es_tr_tokens(b: *u8, n: i64, dayw: *i64, base: i64) -> i64
224func es_is_jsonl(name: *u8) -> i64
called by 1: es_tr_scan calls 1: es_len
233func es_tr_scan(dir: *u8, tbuf: *u8, dayw: *i64, nowday: i64, win: i64, env: *i64) -> i64
281func efl_weighted_bp(ti: i64, to_: i64, cr: i64, cw: i64) -> i64 { return ti*EFL_W_IN + to_*EFL_W_OUT + cr*EFL_W_CR + cw*EFL_W_CW }
called by 1: efl_cost_cents
283func efl_cost_cents(ti: i64, to_: i64, cr: i64, cw: i64) -> i64
called by 2: es_emites_selftest calls 1: efl_weighted_bp
288func efl_energy_wh(ti: i64, to_: i64, cr: i64, cw: i64) -> i64
called by 1: es_emit