code wiki / _hdl_build / nx_eff_lib.nx
nx_eff_lib.nx
buildroot/runtime/_hdl_build/nx_eff_lib.nx
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
imports: nx_syscalls.nx
imported by: nx_eff_scan.nx
structs
| none |
consts
| 17 | const ES_NF: i64 = 10 // fields per day slot |
| 18 | const ES_F_ACT: i64 = 0 // actions |
| 19 | const ES_F_MCP: i64 = 1 // mcp__ tool calls |
| 20 | const ES_F_SH: i64 = 2 // shell (PowerShell/Bash) |
| 21 | const ES_F_FILE: i64 = 3 // file ops (Read/Edit/Write/Grep/Glob) |
| 22 | const ES_F_SEC: i64 = 4 // active seconds (gap300-strict) |
| 23 | const ES_F_TIN: i64 = 5 // tokens input |
| 24 | const ES_F_TOUT: i64 = 6 // tokens output |
| 25 | const ES_F_TCR: i64 = 7 // cache-read tokens |
| 26 | const ES_F_TCW: i64 = 8 // cache-write tokens |
| 27 | const ES_F_TRF: i64 = 9 // transcript files touched this day |
| 29 | const ES_ENV_SLOTS: i64 = 8 |
| 30 | const ES_E_TRUNC: i64 = 0 // transcripts that hit the per-file cap |
| 31 | const ES_E_TRF: i64 = 1 // transcript files scanned |
| 32 | const ES_E_TRB: i64 = 2 // transcript bytes read |
| 33 | const ES_E_WLR: i64 = 3 // worklog rows parsed |
| 34 | const ES_E_WLB: i64 = 4 // worklog bytes read |
| 36 | const ES_WIN_MAX: i64 = 28 |
| 37 | const ES_WIN_DEF: i64 = 14 |
| 38 | const ES_CAP_WL: i64 = 33554432 // 32MiB worklog read cap |
| 39 | const ES_CAP_TR: i64 = 33554432 // 32MiB per-transcript read cap |
| 40 | const ES_GAP_CAP: i64 = 300 // active-time gap ceiling (s) |
| 41 | const ES_DAYSEC: i64 = 86400 |
| 42 | const ES_TAB: i64 = 9 |
| 43 | const ES_NL: i64 = 10 |
| 44 | const ES_QUOTE: i64 = 34 |
| 45 | const ES_SPACE: i64 = 32 |
| 46 | const ES_ZERO: i64 = 48 |
| 47 | const ES_NINE: i64 = 57 |
| 50 | const EFL_W_IN: i64 = 100 |
| 51 | const EFL_W_OUT: i64 = 500 |
| 52 | const EFL_W_CR: i64 = 10 |
| 53 | const EFL_W_CW: i64 = 125 |
| 54 | const EFL_CENTS_PER_MTOK_IN: i64 = 1500 // uncached input $15.00/Mtok (Opus-class default; declared, editable) |
| 55 | const EFL_WH_PER_MTOK: i64 = 400 // ~0.4 Wh / 1k tok large-model inference (ESTIMATE; fetch-target) |
| 56 | const EFL_MONEY_DIV: i64 = 100000000 // bp(x100) x per-Mtok(1e6) normalizer |
functions
| 58 | func es_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 59 | func es_eq(a: *u8, b: *u8) -> i64 called by 1: main |
| 65 | func es_atoi(s: *u8) -> i64 called by 1: main |
| 73 | func es_read_bounded(path: *u8, buf: *u8, cap: i64, env: *i64) -> i64 |
| 92 | func es_num_at(b: *u8, n: i64, pos: i64) -> i64 |
| 104 | func es_slice_pfx(b: *u8, a: i64, e: i64, s: *u8) -> i64 |
| 115 | func es_slice_eq(b: *u8, a: i64, e: i64, s: *u8) -> i64 |
| 121 | func es_match(b: *u8, n: i64, pos: i64, needle: *u8) -> i64 called by 1: es_tr_tokens |
| 135 | func es_wl_maxepoch(b: *u8, n: i64) -> i64 |
| 148 | func es_wl_scan(b: *u8, n: i64, dayw: *i64, nowday: i64, win: i64, env: *i64) -> i64 |
| 204 | func es_tr_tokens(b: *u8, n: i64, dayw: *i64, base: i64) -> i64 |
| 224 | func es_is_jsonl(name: *u8) -> i64 |
| 233 | func es_tr_scan(dir: *u8, tbuf: *u8, dayw: *i64, nowday: i64, win: i64, env: *i64) -> i64 called by 2: es_selftestmain calls 7: sys_openat_rdsys_mmapes_is_jsonlsys_fstatates_read_boundedes_tr_tokens+1 |
| 281 | func 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 |
| 283 | func efl_cost_cents(ti: i64, to_: i64, cr: i64, cw: i64) -> i64 |
| 288 | func efl_energy_wh(ti: i64, to_: i64, cr: i64, cw: i64) -> i64 called by 1: es_emit |