code wiki / _hdl_build / nx_wfcost_outcomes_t144.nx
nx_wfcost_outcomes_t144.nx
buildroot/runtime/_hdl_build/nx_wfcost_outcomes_t144.nx
about
nx_wfcost.nx -- WORKFLOW-EPISODE TOKEN COST (Lane I, common-task hardening loop, 2026-08-20).
Operator: "grow our capabilities into repeatable high value little to no token capabilities".
Ranking hardening candidates needs the REAL cost of what we already do repeatedly. The estate had
the three halves and never joined them: nx_actlog mines recurring tool:verb support, nx_eff_lib
measures transcript tokens PER DAY, and nx_tokroi's uses_per_day is a DECLARED assumption. This
organ joins them: per-INVOCATION-PAIR measured token cost over the FULL transcript population.
THE CORRECTION THIS ORGAN CARRIES (measured 2026-08-20, and it is why the join could not be trusted
before): one assistant MESSAGE is written to the transcript as SEVERAL JSONL LINES -- one per content
block (thinking, tool_use, text) -- and EVERY one of those lines repeats the SAME usage object
verbatim. nx_eff_lib::es_tr_tokens dedups the two usage copies WITHIN a line (message.usage and the
iterations[] echo -- that half is correct and gated by its T20) but counts once PER LINE, so a
message with N content blocks is counted N times. Measured over the 12 largest transcripts:
43,372 assistant lines carry only 22,234 distinct message ids => the per-line method overstates by
~1.95x. This organ dedups by message.id through a real hash set and PRINTS BOTH TOTALS side by side
so the correction is proven by the run, never asserted (two counters of one population = free audit).
Dedup is a SET, not a previous-id compare: 12 of 22,234 ids reappear NON-consecutively, so the cheap
compare would silently overcount those.
gauge [trdir] -> corrected(msgid-deduped) vs perline totals + overcount permil + envelope
mine [trdir] [minsup] -> recurring invocation PAIRS >= minsup with exact total measured tokens
selftest -> gv_verdict gate, named neg-controls, runtime fixtures
RANKING QUANTITY IS THE EXACT TOTAL, NOT A MEDIAN: total = the sum of every episode's measured cost,
carried exactly. A median would need a second pass plus per-episode retention; mean and max are
printed and LABELLED as such, and no median is claimed. license_tier: ORIGINAL No hw writes (Rule 26).
dependencies 5 imports · 1 importers
imports: nx_syscalls.nxnx_gate_verdict.nxnx_claude_harvest.nxnx_comparestale_lib.nxnx_store_seed_lib.nx
imported by: nx_wfcost_outcomes_gate_t144.nx
structs
| none |
consts
| 30 | const WF_TR_DEF: *u8 = "/mnt/c/Users/elder/.claude/projects/C--Users-elder" |
| 32 | const WF_NL: i64 = 10 |
| 33 | const WF_QUOTE: i64 = 34 |
| 34 | const WF_SLASH: i64 = 47 |
| 35 | const WF_ZERO: i64 = 48 |
| 36 | const WF_NINE: i64 = 57 |
| 40 | const WF_W_IN: i64 = 10 |
| 41 | const WF_W_OUT: i64 = 50 |
| 42 | const WF_W_CR: i64 = 1 |
| 43 | const WF_W_CW: i64 = 12 |
| 44 | const WF_W_DIV: i64 = 10 |
| 46 | const WF_MID_SLOTS: i64 = 4194304 |
| 47 | const WF_MID_MASK: i64 = 4194303 |
| 49 | const WF_ID_SLOTS: i64 = 262144 |
| 50 | const WF_ID_MASK: i64 = 262143 |
| 51 | const WF_IDS_MAX: i64 = 32768 |
| 52 | const WF_ARENA: i64 = 8388608 |
| 53 | const WF_LABEL_MAX: i64 = 96 |
| 55 | const WF_BG_SLOTS: i64 = 1048576 |
| 56 | const WF_BG_MASK: i64 = 1048575 |
| 58 | const WF_MSG_MAX: i64 = 262144 |
| 59 | const WF_INV_MAX: i64 = 262144 |
| 61 | const WF_E_FILES: i64 = 0 |
| 62 | const WF_E_BYTES: i64 = 1 |
| 63 | const WF_E_LINES: i64 = 2 |
| 64 | const WF_E_MSGS: i64 = 3 |
| 65 | const WF_E_DUPLINES: i64 = 4 |
| 66 | const WF_E_INVS: i64 = 5 |
| 67 | const WF_E_UNREAD: i64 = 6 |
| 68 | const WF_E_MSGCAP: i64 = 7 |
| 69 | const WF_E_INVCAP: i64 = 8 |
| 70 | const WF_E_IDCAP: i64 = 9 |
| 71 | const WF_E_BGCAP: i64 = 10 |
| 72 | const WF_E_PAIRS: i64 = 11 |
| 73 | const WF_E_SLOTS: i64 = 16 |
| 75 | const WF_T_IN: i64 = 0 |
| 76 | const WF_T_OUT: i64 = 1 |
| 77 | const WF_T_CR: i64 = 2 |
| 78 | const WF_T_CW: i64 = 3 |
| 79 | const WF_T_PIN: i64 = 4 |
| 80 | const WF_T_POUT: i64 = 5 |
| 81 | const WF_T_PCR: i64 = 6 |
| 82 | const WF_T_PCW: i64 = 7 |
| 83 | const WF_T_SLOTS: i64 = 8 |
| 84 | const WF_STAT_BUF: i64 = 256 |
| 85 | const WF_DIRENT_BUF: i64 = 65536 |
| 86 | const WF_PATH_BUF: i64 = 4096 |
| 87 | const WF_GETDENTS: i64 = 217 |
| 88 | const WF_RECLEN_OFF: i64 = 16 |
| 89 | const WF_NAME_OFF: i64 = 19 |
| 90 | const WF_TOP_DEF: i64 = 40 |
| 91 | const WF_PERMIL: i64 = 1000 |
| 92 | const WF_MODE_755: i64 = 493 |
| 93 | const WF_MODE_644: i64 = 420 |
| 94 | const WF_TSV_TAB: i64 = 9 |
| 95 | const WF_DAYSEC: i64 = 86400 |
| 96 | const WF_E_MINTS: i64 = 12 |
| 97 | const WF_E_MAXTS: i64 = 13 |
| 98 | const WF_E_FRAMES: i64 = 14 |
| 99 | const WF_CHBEAT_DEF: *u8 = "knowledge/status/chbeat" |
| 860 | const WFJ_COLS:i64=16 |
| 861 | const WFJ_STATS:i64=25 |
| 1194 | const WFJ_CONFIG_COLS:i64=7 |
| 1195 | const WFJ_CONFIG_PREFIX:*u8="knowledge/store/wfcost-evaluations-" |
functions
| 101 | func wf_len(s: *u8) -> i64 |
| 106 | func wf_eq(a: *u8, b: *u8) -> i64 |
| 117 | func wf_atoi(s: *u8) -> i64 |
| 128 | func wf_find_in(b: *u8, a: i64, e: i64, needle: *u8) -> i64 |
| 142 | func wf_num_at(b: *u8, e: i64, p: i64) -> i64 |
| 157 | func wf_hash(b: *u8, a: i64, e: i64) -> i64 |
| 171 | func wf_set_add(tab: *i64, h: i64) -> i64 |
| 184 | func wf_intern(tab: *i64, offs: *i64, arena: *u8, st: *i64, b: *u8, a: i64, e: i64) -> i64 |
| 215 | func wf_pair_add(bg: *i64, key: i64, tok: i64, env: *i64) -> i64 |
| 242 | func wf_is_jsonl(name: *u8) -> i64 |
| 254 | func wf_scan_file(path: *u8, mids: *i64, idtab: *i64, idoffs: *i64, arena: *u8, ist: *i64, bg: *i64, msgtok: *i64, invid: *i64, invmsg: *i64, env: *i64, tok: *i64) -> i64 |
| 372 | func wf_walk(dir: *u8, mids: *i64, idtab: *i64, idoffs: *i64, arena: *u8, ist: *i64, bg: *i64, msgtok: *i64, invid: *i64, invmsg: *i64, env: *i64, tok: *i64) -> i64 |
| 403 | func wf_emit_env(env: *i64, tok: *i64) -> i64 |
| 431 | func wf_gauge(dir: *u8) -> i64 |
| 473 | func wf_mine(dir: *u8, minsup: i64, top: i64) -> i64 |
| 557 | func wf_is_jrnl(name: *u8) -> i64 |
| 567 | func wf_frames_file(path: *u8, idtab: *i64, idoffs: *i64, arena: *u8, ist: *i64, bg: *i64, env: *i64) -> i64 |
| 626 | func wf_frames(dir: *u8, minsup: i64, top: i64) -> i64 |
| 724 | func wf_selftest() -> i64 |
| 803 | func main(argc: i64, argv: *i64) -> i64 |
| 867 | func wfj_span_eq(a:*u8,s:i64,n:i64,b:*u8,t:i64,m:i64)->i64 |
| 870 | func wfj_lit(q:*u8,f:*i64,col:i64,s:*u8)->i64{return wfj_span_eq(q,f[col*2],f[col*2+1],s,0,cd_len(s))} |
| 871 | func wfj_fields_n(q:*u8,s:i64,e:i64,f:*i64,cols:i64)->i64 |
| 884 | func wfj_fields(q:*u8,s:i64,e:i64,f:*i64)->i64{return wfj_fields_n(q,s,e,f,WFJ_COLS)} |
| 885 | func wfj_hash(q:*u8,f:*i64,col:i64)->i64 |
| 889 | func wfj_copy(q:*u8,f:*i64,col:i64,out:*u8)->i64 |
| 892 | func wfj_role(q:*u8,f:*i64)->i64 |
| 897 | func wfj_validate(q:*u8,f:*i64)->i64 |
| 912 | func wfj_evidence(q:*u8,f:*i64)->i64 |
| 931 | func wfj_join(raw:*u8,table:*i64,count:i64,from:i64,to:i64,digest:*u8,bindings:*u8,n:i64,stats:*i64,usage:*i64)->i64 |
| 1002 | func wfj_read(path:*u8,limit:i64,result:*i64)->*u8 |
| 1020 | func wfj_digest(raw:*u8,n:i64,hex:*u8)->i64 |
| 1031 | func wfj_plane_range(prefix:*u8,cols:i64,extra:i64,meta:*i64)->*u8 |
| 1078 | func wfj_plane(prefix:*u8,cols:i64,meta:*i64)->*u8{return wfj_plane_range(prefix,cols,0,meta)} |
| 1082 | func wfj_retain_bindings(path:*u8,rows:*u8,n:i64)->i64 |
| 1096 | func wfj_null(j:*JsonWriter,key:*u8)->i64 {let rc:i64=json_emit_key(j,key,cd_len(key));return rc|json_emit_null(j)} |
| 1097 | func wfj_report(stage:*u8,code:i64,digest:*u8,from:i64,to:i64,plane:*u8,pm:*i64,s:*i64,u:*i64,c:*i64,config_id:*u8,config_sha:*u8,binding_sha:*u8,snapshot:*u8,snapshot_rc:i64)->i64 |
| 1153 | func wfj_command_context(argc:i64,argv:*i64,config_id:*u8,config_sha:*u8)->i64 |
| 1189 | func wfj_command(argc:i64,argv:*i64)->i64{return wfj_command_context(argc,argv,0 as *u8,0 as *u8)} |
| 1196 | func wfj_config_command(argc:i64,argv:*i64)->i64 |