code wiki / _hdl_build / nx_eff_lib.nx

nx_eff_lib.nx

buildroot/runtime/_hdl_build/nx_eff_lib.nx

15970 B346 linesdepth 2pulls 3 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 2 imports · 1 importers

nx_syscalls.nx nx_eff_conv.nx nx_eff_lib.nx nx_eff_scan.nx

imports: nx_syscalls.nxnx_eff_conv.nx

imported by: nx_eff_scan.nx

structs

none

consts

18const ES_NF: i64 = 10 // fields per day slot
19const ES_F_ACT: i64 = 0 // actions
20const ES_F_MCP: i64 = 1 // mcp__ tool calls
21const ES_F_SH: i64 = 2 // shell (PowerShell/Bash)
22const ES_F_FILE: i64 = 3 // file ops (Read/Edit/Write/Grep/Glob)
23const ES_F_SEC: i64 = 4 // active seconds (gap300-strict)
24const ES_F_TIN: i64 = 5 // tokens input
25const ES_F_TOUT: i64 = 6 // tokens output
26const ES_F_TCR: i64 = 7 // cache-read tokens
27const ES_F_TCW: i64 = 8 // cache-write tokens
28const ES_F_TRF: i64 = 9 // transcript files touched this day
30const ES_ENV_SLOTS: i64 = 8
31const ES_E_TRUNC: i64 = 0 // transcripts that hit the per-file cap
32const ES_E_TRF: i64 = 1 // transcript files scanned
33const ES_E_TRB: i64 = 2 // transcript bytes read
34const ES_E_WLR: i64 = 3 // worklog rows parsed
35const ES_E_WLB: i64 = 4 // worklog bytes read
37const ES_WIN_MAX: i64 = 28
38const ES_WIN_DEF: i64 = 14
39const ES_CAP_WL: i64 = 33554432 // 32MiB worklog read cap
40const ES_CAP_TR: i64 = 33554432 // 32MiB per-transcript read cap
41const ES_GAP_CAP: i64 = 300 // active-time gap ceiling (s)
42const ES_DAYSEC: i64 = 86400
43const ES_TAB: i64 = 9
44const ES_NL: i64 = 10
45const ES_QUOTE: i64 = 34
46const ES_SPACE: i64 = 32
47const ES_ZERO: i64 = 48
48const ES_NINE: i64 = 57

functions

51func es_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
52func es_eq(a: *u8, b: *u8) -> i64
called by 1: main
58func es_atoi(s: *u8) -> i64
called by 1: main
66func es_read_bounded(path: *u8, buf: *u8, cap: i64, env: *i64) -> i64
85func es_num_at(b: *u8, n: i64, pos: i64) -> i64
97func es_slice_pfx(b: *u8, a: i64, e: i64, s: *u8) -> i64
108func es_slice_eq(b: *u8, a: i64, e: i64, s: *u8) -> i64
called by 1: es_wl_scan calls 2: es_slice_pfxes_len
114func es_match(b: *u8, n: i64, pos: i64, needle: *u8) -> i64
128func es_wl_maxepoch(b: *u8, n: i64) -> i64
called by 2: es_selftestmain calls 1: es_num_at
141func es_wl_scan(b: *u8, n: i64, dayw: *i64, nowday: i64, win: i64, env: *i64) -> i64
200func es_tr_tokens(b: *u8, n: i64, dayw: *i64, base: i64) -> i64
221func es_slice_has(b: *u8, a: i64, e: i64, s: *u8) -> i64
called by 1: es_classify_model calls 1: es_len
235func es_classify_model(b: *u8, a: i64, e: i64) -> i64
called by 1: es_tr_tokens_bymodel calls 1: es_slice_has
244func es_find_in(b: *u8, a: i64, e: i64, needle: *u8) -> i64
260func es_tr_tokens_bymodel(b: *u8, n: i64, modacc: *i64) -> i64
289func es_is_jsonl(name: *u8) -> i64
called by 1: es_tr_scan calls 1: es_len
298func es_tr_scan(dir: *u8, tbuf: *u8, dayw: *i64, nowday: i64, win: i64, env: *i64, modacc: *i64) -> i64