nx_compare_rank.nx source
↩ module page · 1404 lines · 96689 B
1// nx_compare_rank.nx -- THE ROADMAP RANKER: priority computed from the boards, never chosen by a seat.
2//
3// Operator 2026-08-18: "we need sota best of breed prioritization and ranking from the foundation first
4// bit up in our compares to drive our roadmaps ... it needs to push back on your random doing of low
5// priorities" and "we cant keep having you do random shit and say its effective". A seat picking rungs
6// by whatever is cheapest with parts in-tree is the defect; this organ makes the compare COMPUTE the
7// order from data the boards already carry and PUBLISH it where every seat, MCP caller and RACI row
8// reads it. It decides nothing itself: the math is nx_dr_ocm (DR-6 opportunity-cost ranker,
9// Priority=(V*M)/C, integer deterministic -- REGISTERED-DARK until today, adopted here) and the plane
10// write is nx_store_put; this organ only DERIVES the three inputs per open rung, all from data:
11//
12// THE MATHEMATICS (v5, 2026-08-18 -- operator: "a full mathematical system on opportunity cost,
13// clustering, foundation-up capabilities, best-of-breed research as of August 2026", not a seat's
14// coefficients). Every term is COUNTED or a RATIO of board data; the only chosen constant left is
15// RANK_COST_UNKNOWN and it fires only on a plan row that declared no cost (a labeled data defect).
16// value v = deficit + CoD + option + enables (all from matrix codes + dep rows)
17// deficit = sum of rival codes on the rung's row (2 leads, 1 present, 0 absent): value at stake
18// CoD = deficit x (rivals LEADING / rivals total): WSJF cost-of-delay -- the fraction of the
19// field already ahead is the time-criticality; every unit open, that many rivals widen it
20// option = 1, ONLY when every rival is absent: the lead itself, held by nobody -- its unlocking
21// value is already the enables leg below (one leg each; a v5 draft double-charged it)
22// enables = number of OTHER open rungs whose transitive dependency closure contains this rung:
23// the foundation-first / opportunity-enablement leg (WSJF) and the compound-option leg
24// (real-options portfolio theory), counted from dep rows
25// momentum m = 1 + declared dependencies already MEASURED present (substrate landed; never 0 because
26// nx_dr_ocm multiplies and a zero would hide the rung)
27// cost c = the plan's own est u in tenths, DIVIDED by the rung's cluster size (open rungs sharing
28// the same organ file share substrate: read once, one build lane, one gate to extend --
29// graph clustering on the organ column, measured never labelled); unestimated -> labeled
30// sponsor = the operator's sponsor- plane coefficient (PR6), applied to value, every firing row named
31// priority = nx_dr_ocm( v x sponsor, m, c ) = (V x M x 1000)/C with forgone-best-alternative and
32// budget-aware greedy selection (DR-6, integer deterministic)
33// critical path: the FIRST unmet product version's milestone rungs + transitive open deps rank
34// before everything else (ver| rows) -- staged delivery 0.1 -> 1.0 -> 2.0.
35// Provenance: WSJF/cost-of-delay (SAFe LPM), real-options R&D portfolio valuation with project
36// interdependencies (Blau et al.; OptFolio-class DSS), integer-programming portfolio selection under
37// budget (knapsack form -- dr_ocm's greedy is the bounded-effort stand-in), dependency-graph enablement.
38// pmdash.refs carries the citations. What is NOT here, honestly: uncertainty distributions (PTRS-style
39// success probabilities per rung) -- the estate has no measured per-rung success rate yet; PR7's
40// actuals-write-back is the data that makes that term possible, and it will be added when the data
41// exists rather than invented now.
42//
43// The output is the PRINTED TABLE (every rung's full derivation, v/m/c and where each came from, so the
44// number can be argued from its inputs) plus ONE PLANE ROW per domain in comparerank-<domain>:
45// id=<domain>, title=the #1 rung, status=its priority, scope=the #1 rung id, note=the ordered queue.
46// One row = one segment commit; a per-rung row was measured stalling the fleet in D-state on
47// 2026-08-18 (syscalls per unit of output, §F). Whole population per domain, no sampling.
48//
49// usage: nx_compare_rank <domain> [budget_tenths] (runs from nishihost cwd; reads
50// buildroot/knowledge/compare/<domain>.plan + .matrix; forks ./nx_dr_ocm_cli.elf and ./nx_store_put.elf)
51// exit: 0 ranked+published | 2 usage | 3 plan/matrix unreadable | 4 ranker fork failed | 5 BAR-STALE (a declared bar
52// older than the current month with no this-month barscan attestation: the board refuses to hand out work) or
53// BAR-DUPLICATE / SCAN-DUPLICATE (a sotabar id or a same-day barscan for one ref declared twice; the printed
54// RANK REFUSED line carries rule=<the rule from nx_barfresh_lib.bf_refusal_rule>, never a paraphrase)
55// | 6 LADDER-PARTIAL (a declared ladder to SOTA left half-declared: an undated target or a rung with no role) or
56// TARGET-DUPLICATE / ROLE-DUPLICATE (a target id or a rung's role declared twice; rule=<from ld_refusal_rule>)
57// | 7 malformed authored graph | 8 TREATMENT-PARTIAL (ecosystem EC49: a treat| row declared and left unmet -- a field a dash,
58// an MCP row absent from tool_allowlist.conf or not GREEN, a primitive with no source, a workflow with no plan_run manifest,
59// an agent on neither the clock plane nor the gate roster, or a row short of its seven fields; every offending row printed)
60// license_tier: ORIGINAL No hw writes (Rule 26).
61import "nx_syscalls.nx"
62import "nx_tool_run.nx"
63// CE2 (2026-08-23): the estate's adoption ladder -- ONE classifier shared with nx_catalog and the page
64import "nx_catalog_lib.nx"
65import "nx_symdecl_lib.nx"
66// ES28 (2026-09-14, operator: the estate answers a rung's contract itself, no treasure hunting): the incumbents and
67// the record's rejections for every open rung, from nx_incumbent_lib's stamped index. Loaded once per run after the
68// bar and ladder rulers; printed under each ranked rung line; the coverage envelope printed once. An absent or stale
69// index is ANNOUNCED per rung (INDEX-ABSENT / INDEX-STALE with the remedy), never guessed around.
70import "nx_incumbent_lib.nx"
71const RK_INC_OUT: i64 = 16384
72static rk_inc_g: i64
73static rk_inc_c: i64
74func rk_incumbents(rid: *u8, title: *u8, sym: *u8, note: *u8, excl: *u8) -> i64 {
75 let g: *i64 = rk_inc_g as *i64
76 let c: *i64 = rk_inc_c as *i64
77 rk_puts(" INCUMBENTS(" as *u8)
78 if g[INC_G_STATE] != INC_S_FRESH {
79 rk_puts(rid); rk_puts("): INDEX-" as *u8); rk_puts(inc_state_name(g[INC_G_STATE])); rk_puts(" (no answer is given from an index in this state; run nx_incumbents index)\n" as *u8)
80 return 0
81 }
82 let out: *u8 = sys_mmap(RK_INC_OUT) as *u8
83 let r: *i64 = inc_match(g, c, title, sym, note, excl)
84 inc_render(g, c, r, rid, out, RK_INC_OUT)
85 // inc_render already opens with INCUMBENTS(<rid>): -- skip that prefix, we printed our own indent
86 rk_puts((out as i64 + 11) as *u8); rk_puts("\n" as *u8)
87 return 0
88}
89// BAR FRESHNESS (2026-09-06): the one ruler for bar age, composed here so a stale bar refuses the work queue
90import "nx_barfresh_lib.nx"
91// LADDER TO SOTA (2026-09-06): the one ruler for dated best-in-class and frontier targets and a role on every rung
92import "nx_ladder_lib.nx"
93import "nx_swcompare_lib.nx" // reuse source identities and declared graph validation
94const RANK_EXIT_BAR_STALE: i64 = 5 // a declared bar older than the current month with no this-month attestation: the board hands out no work
95const RANK_EXIT_LADDER_PARTIAL: i64 = 6 // a declared ladder to SOTA left half-declared (an undated target, a rung with no role): refused the same way
96// THREE-STEP TREATMENT (ecosystem EC49, operator 2026-09-16: "make sure its mandatory that they get mcp and api and composable
97// primitives and workflows and agent treatment in our 1 2 3 step process"): nx_treatment_lib is the one ruler; the ranker composes
98// it after the ladder ruler so a rung declared without its MCP row, API route, primitive, workflow or agent is refused work.
99import "nx_treatment_lib.nx"
100const RANK_EXIT_TREATMENT_PARTIAL: i64 = 8 // a declared treatment left unmet on some rung: refused the same way (7 is the graph refusal)
101const RK_TRT_ALLOW: *u8 = "tool_allowlist.conf" // the MCP surface: name TAB elf TAB GREEN [TAB pinned args]; the API route is the same row
102const RK_TRT_ROSTER: *u8 = "knowledge/gateroster.conf" // the gate roster: one agent per line
103const RK_TRT_CLOCK_PLANE: *u8 = "knowledge/store/clockjobs-" // the clock DESIRED plane: name TAB secs TAB elf args
104const RK_TRT_CLOCK_CAP: i64 = 1048576 // captured stdout of the clock DESIRED plane load (a fork, size unknowable): 11,897 B for
105 // 188 rows on 2026-09-16, so this reserve is 88x the measured plane; a fill is ANNOUNCED
106 // and the plane treated as UNOBSERVED, never read as a prefix
107const RK_TRT_WF_PFX: *u8 = "knowledge/store/plan-" // a workflow is a plan_run plane: its manifest is <pfx><id><sfx>
108const RK_TRT_WF_SFX: *u8 = "-manifest.txt"
109const RK_TRT_PATH_CAP: i64 = 1024 // one composed estate path, the reserve every ep_* probe in this estate writes into
110const RK_TRT_MISS_CAP: i64 = 256 // one missing-list line: five fields of name:state from the ruler's own vocabulary (under 80 B)
111
112// POPULATION CAPS REMOVED 2026-08-23 (lane F): the former RANK_MAX_RUNGS=64 / RANK_MAX_ROWS=64 /
113// RANK_FIELD_MAX=24 / RANK_FILE_CAP=262144 / RANK_SRC_CAP=524288 / RANK_QUEUE_CAP=8192 were SILENT
114// caps -- browser.matrix carries 76 rows, so every row past 64 was invisible and its rung read
115// UNMAPPED (measured: BR20 bpd_download, whose watch row exists). Every population bound is now
116// DERIVED from the data it bounds: files are read whole by sys_read_file (sized from the file, cannot
117// short-read), row/rung/field arrays are sized from the line and pipe census of the loaded bytes, and
118// every buffer that holds a composed string is sized from the lengths of what it composes. The only
119// bounds that remain are fork CAPTURES (a pipe has no knowable size): each is named for its one
120// purpose, sized from the population that produces it, and ANNOUNCES when it fills.
121const RK_DEC_MAX: i64 = 20 // max decimal digits of an i64 (19) plus a sign: the width of one
122 // rk_catn/rk_pn number, the unit every composed-string bound counts in
123const RK_NUMBUF: i64 = RK_DEC_MAX + 4 // one number rendered to text + NUL + slack for the '-' and terminator
124// (RANK_EXCEED_BONUS retired 2026-08-18: the exceed lane is now valued as a REAL OPTION -- one plus the
125// downstream rungs it enables -- derived from the dependency graph instead of a chosen constant.)
126const RANK_COST_UNKNOWN: i64 = 100 // 10.0 u: an unestimated rung is treated as EXPENSIVE, labeled --
127 // the ONE remaining chosen constant, and it only ever affects rungs
128 // whose plan row failed to declare a cost (a labeled data defect)
129const RANK_DEFAULT_BUDGET: i64 = 300 // 30.0 u -- above every plan's full-parity figure, so the greedy
130 // selection reports the whole ordering (budget filtering is the
131 // caller's lever via argv[2])
132const RANK_STORE_FIELDS: i64 = 8
133// ONE RUNG NOTE is literals + numbers + plane-sourced text. The constants below are COUNTED from this
134// source (scratchpad count_lits.py over every `rk_cat(nb, ...)` / `rk_catn(nb, ...)` site, 2026-08-23):
135// RK_NOTE_LITERALS = 531 the summed source length of the 26 literal appends (a source-length bound)
136// RK_NOTE_NUMS = 13 rk_catn sites on the note path, each at most RK_DEC_MAX bytes
137// RK_SPONSOR_ROW_LITERALS = 11 the literal bytes ONE applying sponsor row adds (" sponsor[" ":" "]"); the
138// row's own id and weight come from the plane, so the plane's length bounds them
139// The caller sizes a note as literals + nums*RK_DEC_MAX + splen + rows*RK_SPONSOR_ROW_LITERALS + the
140// dom/id/sym/organ strings it echoes. Re-count when a note literal is added; the count is the contract.
141// 2026-09-16: +120 for the DARK-CONTRACT literal (landed 2026-09-06 without a re-count) and +102 for the
142// TREATMENT-UNDECLARED literal (EC49) -- both counted from their source lines, the bound stays a source-length bound
143const RK_NOTE_LITERALS: i64 = 531 + 120 + 102
144const RK_NOTE_NUMS: i64 = 13
145const RK_SPONSOR_ROW_LITERALS: i64 = 11
146const RANK_FORK_CAP: i64 = 4096 // captured stdout of one nx_store_put / nx_pm_intake fork: their
147 // receipts are one line; a fill is ANNOUNCED (CAPTURE-FULL) not dropped
148// the ranker's JSON: one object per open rung -- 8 keys (89 literal bytes incl. braces and the separating
149// comma) plus 8 numbers -- and a fixed header/footer (195 literal bytes plus 5 numbers); COUNTED from
150// nx_dr_ocm_cli's emitter (scratchpad count_ocm.py, 2026-08-23). The capture is sized from nopen, and a
151// fill is REFUSED loudly (a ranking read as a prefix is worse than no ranking).
152const RK_OCM_OBJ_BYTES: i64 = 89 + 8 * RK_DEC_MAX
153const RK_OCM_HDR_BYTES: i64 = 195 + 5 * RK_DEC_MAX + 16
154// CE2/CE6 (2026-08-23): a rung whose symbol is PRESENT but whose organ is short of full adoption (built and
155// never promoted, promoted and never registered, a lib imported only by its gate) used to count DONE here --
156// the board could not see a partial deploy at all. Such rungs now also print as FINISH rows (state + remedy)
157// ahead of the ranked queue, land in the plane note as F[state]ID, and in the stamped artefact
158// buildroot/knowledge/compare/<dom>.rank that the page renders as "Do this next". NO coefficient changed:
159// v/m/c, the critical path and the order of open rungs are untouched; FINISH is a separate, cheaper class.
160const RANK_FIX_PER_RUNG: i64 = 64 + 10 * RK_DEC_MAX // row skeleton: kind, pipes, numbers, newline
161// One persisted `unmapped|<id>|<sym>|<reason>` row: the literal bytes only. The two VARIABLE parts,
162// id and sym, are added as measured rk_slen terms at the cap loop rather than being guessed here --
163// the same shape the rest of that loop already uses, so this cannot under-size on a long symbol.
164// Measured literal: "unmapped|" 9 + "|" 1 + "|" 1 + "no-matrix-row-carries-this-symbol" 33 + LF 1 = 45.
165const RANK_UNMAPPED_ROW: i64 = 48
166// RAISED 256 -> 512 (2026-09-01) to carry the one-line unmapped COUNT header that now precedes the
167// stamp. The tail is fixed-size text, so this is arithmetic, not a guess: the count line is ~110 bytes
168// plus a rendered integer, and 256 had no room for it beside the stamp it was sized for.
169const RANK_FIX_TAIL: i64 = 512 // the stamped last line + the unmapped count line
170const RANK_PM_TOP: i64 = 3 // critical rungs filed into pm intake per run: enough to drive
171 // the next sessions, few enough that intake stays a queue not a dump
172
173func rk_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
174func rk_puts(s: *u8) -> i64 { sys_write(1, s, rk_slen(s)); return 0 }
175func rk_pn(v: i64) -> i64 {
176 let t: *u8 = sys_mmap(RK_NUMBUF) as *u8
177 var m: i64 = v; var w: i64 = 0
178 if m < 0 { t[w] = 45 as u8; w = w + 1; m = 0 - m }
179 if m == 0 { t[w] = 48 as u8; sys_write(1, t, w + 1); return 0 }
180 let d: *u8 = sys_mmap(RK_NUMBUF) as *u8
181 var k: i64 = 0
182 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
183 var j: i64 = 0
184 while j < k { t[w] = d[k-1-j]; w = w + 1; j = j + 1 }
185 sys_write(1, t, w); return 0
186}
187func rk_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; var oo: i64 = o; while s[i] != (0 as u8) { d[oo] = s[i]; oo = oo + 1; i = i + 1 } d[oo] = 0 as u8; return oo }
188func rk_catn(d: *u8, o: i64, v: i64) -> i64 {
189 let t: *u8 = sys_mmap(RK_NUMBUF) as *u8
190 var m: i64 = v; var k: i64 = 0; var oo: i64 = o
191 if m < 0 { d[oo] = 45 as u8; oo = oo + 1; m = 0 - m }
192 if m == 0 { d[oo] = 48 as u8; oo = oo + 1; d[oo] = 0 as u8; return oo }
193 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
194 while k > 0 { k = k - 1; d[oo] = t[k]; oo = oo + 1 }
195 d[oo] = 0 as u8
196 return oo
197}
198func rk_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] == b[i] { if a[i] == (0 as u8) { return 1 } i = i + 1 } return 0 }
199func rk_starts(s: *u8, p: *u8) -> i64 { var i: i64 = 0; while p[i] != (0 as u8) { if s[i] != p[i] { return 0 } i = i + 1 } return 1 }
200// WHOLE-FILE READ, sized from the file (sys_read_file: lseek END, cannot short-read; +16 slack so the
201// in-place NUL-splitting below may write one past the last byte). Returns the byte count, -1 if
202// unreadable, and hands the buffer back through outb. The former rk_read took a caller CAP and
203// stopped there in silence -- a 262144-byte plan or a 524288-byte organ source read as a PREFIX.
204func rk_read_all(path: *u8, outb: *i64) -> i64 {
205 let lenp: *i64 = sys_mmap(16) as *i64
206 let b: *u8 = sys_read_file(path, lenp)
207 outb[0] = b as i64
208 if (b as i64) == 0 { return 0 - 1 }
209 return lenp[0]
210}
211// EC49: a whole-file read of an estate artifact resolved through THE ONE probe order (nx_estate_path), so the ranker at
212// CWD=nishihost reads the same tool_allowlist.conf and gateroster.conf that nx_treatment reads at CWD=buildroot. 0 = absent.
213func rk_trt_read(rel: *u8, outb: *i64) -> i64 {
214 let path: *u8 = sys_mmap(RK_TRT_PATH_CAP)
215 if ep_artifact_path(path, rel) == 0 { outb[0] = 0; return 0 }
216 let n: i64 = rk_read_all(path, outb)
217 if n < 0 { outb[0] = 0; return 0 }
218 return n
219}
220// a NUL-terminated copy of one span of a loaded buffer (a treat row's field, handed to the path probes as a name)
221func rk_span_copy(buf: *u8, off: i64, len: i64) -> *u8 {
222 var l: i64 = len
223 if l < 0 { l = 0 }
224 let s: *u8 = sys_mmap(l + 1)
225 var i: i64 = 0
226 while i < l { s[i] = buf[off + i]; i = i + 1 }
227 s[l] = 0 as u8
228 return s
229}
230// line census of a loaded buffer: newlines + 1 -- an upper bound on rows/rungs/ms/ver rows, DERIVED
231func rk_lines(b: *u8, n: i64) -> i64 {
232 var c: i64 = 1
233 var i: i64 = 0
234 while i < n { if b[i] == (10 as u8) { c = c + 1 } i = i + 1 }
235 return c
236}
237// pipe census: the most '|' on any one line + 2 -- the field-slot bound for rk_split, DERIVED
238func rk_max_pipes(b: *u8, n: i64) -> i64 {
239 var best: i64 = 0
240 var cur: i64 = 0
241 var i: i64 = 0
242 while i < n {
243 if b[i] == (10 as u8) { if cur > best { best = cur } cur = 0 } else { if b[i] == (124 as u8) { cur = cur + 1 } }
244 i = i + 1
245 }
246 if cur > best { best = cur }
247 return best + 2
248}
249// split a NUL-terminated line on '|' IN PLACE (same contract as the compare generator's splitpipe)
250func rk_split(s: *u8, fld: *i64, maxf: i64) -> i64 {
251 var c: i64 = 1; fld[0] = s as i64; var i: i64 = 0
252 while s[i] != (0 as u8) { if s[i] == (124 as u8) { s[i] = 0 as u8; if c < maxf { fld[c] = (s as i64) + i + 1; c = c + 1 } } i = i + 1 }
253 return c
254}
255// "1.5" -> 15, "2" -> 20, "-" -> -1 (tenths of a unit; one decimal is all the plans use)
256func rk_tenths(s: *u8) -> i64 {
257 if s[0] == (45 as u8) { return 0 - 1 }
258 var v: i64 = 0; var i: i64 = 0; var any: i64 = 0; var frac: i64 = 0 - 1
259 while s[i] != (0 as u8) {
260 let c: i64 = s[i] as i64
261 if c >= 48 { if c <= 57 { if frac < 0 { v = v * 10 + (c - 48) } else { if frac == 0 { v = v * 10 + (c - 48); frac = 1 } } any = 1 } }
262 if c == 46 { frac = 0 }
263 i = i + 1
264 }
265 if any == 0 { return 0 - 1 }
266 if frac < 0 { v = v * 10 }
267 if frac == 0 { v = v * 10 }
268 return v
269}
270func rk_int(s: *u8) -> i64 { var v: i64 = 0; var i: i64 = 0; while s[i] != (0 as u8) { let c: i64 = s[i] as i64; if c >= 48 { if c <= 57 { v = v * 10 + (c - 48) } } i = i + 1 } return v }
271// symbol match: the matrix row's symbol is either "<sym>" (present) or "_ABSENT_:<sym>" (watched)
272func rk_sym_is(rowsym: *u8, sym: *u8) -> i64 {
273 if rk_streq(rowsym, sym) == 1 { return 1 }
274 if rk_starts(rowsym, "_ABSENT_:" as *u8) == 1 { if rk_streq((rowsym as i64 + 9) as *u8, sym) == 1 { return 1 } }
275 return 0
276}
277
278// presence measured EXACTLY as the emitter measures it: the symbol exists as a top-level function
279// declaration in the organ's source. The matrix DATA keeps its _ABSENT_ watch spelling forever --
280// the flip is a MEASUREMENT at emit -- so a ranker that reads the data state calls every landed rung
281// open (measured on first run: done=0 of 22 with ig_room_solve, gp_collect2 and ntb_bake_pbr all
282// live). Re-measure, never trust the spelling.
283func rk_measure(org: *u8, sym: *u8) -> i64 {
284 let pb: *u8 = sys_mmap(rk_slen(org) + 16) // "buildroot/" (10) + org + NUL
285 var o: i64 = rk_cat(pb, 0, "buildroot/" as *u8)
286 o = rk_cat(pb, o, org)
287 // ONE RULER (2026-08-23, lane L): the declaration test lives in nx_symdecl_lib and is the SAME
288 // function the matrix generator, the sota watch section and the regen's comparewatch plane call.
289 // The claim above ("EXACTLY as the emitter measures it") was measured FALSE on lang LN8 -- the
290 // emitter used a substring -- and is now true by construction rather than by assertion.
291 let rl: *i64 = sys_mmap(16) as *i64
292 if sd_present(pb, sym, rl) == 1 { return 1 }
293 return 0
294}
295// DARK CONTRACT (2026-09-06, operator: a permanent fix, we do not build and lose capability to darkness): the organ
296// the row names EXISTS and was read, but does not declare the symbol under a rule that can judge -- something shipped
297// there under another name. The SAME arithmetic the matrix generator (cell state dk) and the regen's comparewatch
298// plane (state DARK) use: sd_present returns -1 unreadable / 0 read-and-absent / 1 present, and the JS rule's
299// abstention is folded to 0, so a JSDECL rule is excluded -- a rung the ruler cannot judge is open, never dark.
300func rk_dark(org: *u8, sym: *u8) -> i64 {
301 let pb: *u8 = sys_mmap(rk_slen(org) + 16)
302 var o: i64 = rk_cat(pb, 0, "buildroot/" as *u8)
303 o = rk_cat(pb, o, org)
304 let rl: *i64 = sys_mmap(16) as *i64
305 let st: i64 = sd_present(pb, sym, rl)
306 if st != 0 { return 0 }
307 if rl[0] == SD_RULE_JSDECL { return 0 }
308 return 1
309}
310// rk_sponsor_term -- PR6: the operator's SPONSORSHIP as a ranker coefficient (feedback law
311// 2026-08-18: a verdict that is not a row is a verdict the next ranking ignores). Reads the sponsor-
312// plane through nx_store_put load (the CLI lane; the MCP load verb reads planes empty), each row
313// id<TAB>title<TAB>sev<TAB>weight<TAB>actor<TAB>scope<TAB>note. A row APPLIES to a rung when its scope
314// is this domain or "all" AND (its note or title names the rung's id, its symbol, or its domain).
315// Weights are the coarse vocabulary plus2/plus1/minus1/minus2 (a coefficient, not a science; a fine
316// scale would invite tuning theater). Multiplier = SPONSOR_BASE + sum(weights) in units of
317// SPONSOR_BASE, floored at 1 so a minus can demote but never zero a value (a zeroed value hides the
318// rung from the ranker -- demotion must stay visible). Returns the multiplier x SPONSOR_BASE; the
319// caller applies v = v * m / SPONSOR_BASE and prints m so the coefficient is arguable from its rows.
320const SPONSOR_BASE: i64 = 4 // plus2 = +50%, plus1 = +25%, minus1 = -25%, minus2 = -50%
321const SPONSOR_PLANE_CAP: i64 = 262144
322func rk_has(hay: *u8, needle: *u8) -> i64 {
323 let nl: i64 = rk_slen(needle)
324 if nl == 0 { return 0 }
325 var i: i64 = 0
326 while hay[i] != (0 as u8) {
327 var k: i64 = 0
328 var same: i64 = 1
329 while k < nl { if hay[i+k] != needle[k] { same = 0; k = nl } else { if hay[i+k] == (0 as u8) { same = 0; k = nl } } k = k + 1 }
330 if same == 1 { return 1 }
331 i = i + 1
332 }
333 return 0
334}
335func rk_sponsor_term(plane: *u8, plen: i64, dom: *u8, rid1: *u8, sym: *u8, nb: *u8, no0: i64, noOut: *i64) -> i64 {
336 var mult: i64 = SPONSOR_BASE
337 var no: i64 = no0
338 var applied: i64 = 0
339 var p: i64 = 0
340 while p < plen {
341 var e: i64 = p
342 while e < plen { if plane[e] == (10 as u8) { break } e = e + 1 }
343 plane[e] = 0 as u8
344 let ln: *u8 = (plane as i64 + p) as *u8
345 p = e + 1
346 if ln[0] != (0 as u8) {
347 // split on TAB
348 let f: *i64 = sys_mmap(16 * 8) as *i64
349 var c: i64 = 1; f[0] = ln as i64; var i: i64 = 0
350 while ln[i] != (0 as u8) { if ln[i] == (9 as u8) { ln[i] = 0 as u8; if c < 16 { f[c] = (ln as i64) + i + 1; c = c + 1 } } i = i + 1 }
351 if c >= 7 {
352 let scope: *u8 = f[5] as *u8
353 var inscope: i64 = 0
354 if rk_streq(scope, dom) == 1 { inscope = 1 }
355 if rk_streq(scope, "all" as *u8) == 1 { inscope = 1 }
356 if inscope == 1 {
357 var names: i64 = 0
358 if rk_has(f[6] as *u8, rid1) == 1 { names = 1 }
359 if rk_has(f[6] as *u8, sym) == 1 { names = 1 }
360 if rk_has(f[1] as *u8, sym) == 1 { names = 1 }
361 // a domain-scoped row with no rung name applies to the whole domain
362 if rk_streq(scope, dom) == 1 { names = 1 }
363 if names == 1 {
364 var w: i64 = 0
365 let ws: *u8 = f[3] as *u8
366 if rk_streq(ws, "plus2" as *u8) == 1 { w = 2 }
367 if rk_streq(ws, "plus1" as *u8) == 1 { w = 1 }
368 if rk_streq(ws, "minus1" as *u8) == 1 { w = 0 - 1 }
369 if rk_streq(ws, "minus2" as *u8) == 1 { w = 0 - 2 }
370 mult = mult + w
371 applied = applied + 1
372 no = rk_cat(nb, no, " sponsor[" as *u8); no = rk_cat(nb, no, f[0] as *u8); no = rk_cat(nb, no, ":" as *u8); no = rk_cat(nb, no, ws); no = rk_cat(nb, no, "]" as *u8)
373 }
374 }
375 }
376 }
377 }
378 if mult < 1 { mult = 1 }
379 if applied == 0 { no = rk_cat(nb, no, " sponsor=none" as *u8) } else { no = rk_cat(nb, no, " sponsor_mult_x4=" as *u8); no = rk_catn(nb, no, mult) }
380 noOut[0] = no
381 return mult
382}
383// ---- PR11: THE SELF-SUFFICIENCY TERM ------------------------------------------------------------
384// Operator 2026-08-20: "where would be the best investment that drives the most self sufficiency
385// down". Recorded interpretation (feedback-foundation-and-autonomous-frontier-2026-08-20): drive
386// outside DEPENDENCY down / sovereignty UP. A rung whose organ stands on outside dependency delivers
387// a capability that does not survive the internet going away, or that only exists while a seat drives
388// it -- and rule 1 of that same memo says such a rung is MISPRICED, not merely noted. So the price
389// changes here, in the ranker, rather than on a separate board nobody consults.
390//
391// Input: nx_selfsuff's ledger (knowledge/status/selfsuff.ledger, or argv[3]), rows
392// dep|domain|organ|outside_dep|seat_only|seat_freq|claude_loop|hosts
393// Only TWO of those columns feed the coefficient, and the exclusion is measured, not stylistic:
394// outside_dep -- distinct non-sovereign hosts the organ dials in string literals, plus distinct
395// carriers it touches at ONE HOP. Sparse, RE-MEASURED 2026-08-20 against the fixed
396// census (the 90-of-556 figure this line used to carry came from a build that no
397// longer exists): 33 of 560 with-source organs carry ANY measured dependency --
398// 26 outside_dep units + 18 claude_loop organs = 44 dependency units.
399// ⚠ The ledger also now carries a TRANSITIVE net_dep column (0 none / 1 direct /
400// 2 via-helper). It is DELIBERATELY NOT read here: it answers "what breaks with no
401// internet", which is a different question from "how much outside dependency does
402// this rung stand on", and folding it in would re-price every rung in the estate
403// off the back of a measurement change rather than a decision.
404// claude_loop -- seat_only AND a WITNESS frame in the action record. Evidence-positive.
405// seat_only -- DELIBERATELY NOT USED. Measured at 92% of subjects, and A SIGNAL THAT FIRES ON
406// EVERYTHING DISCRIMINATES NOTHING; as a penalty it would demote nearly every rung
407// by the same amount, which is a no-op on ordering wearing the costume of rigour.
408//
409// THERE ARE NO CHOSEN WEIGHTS, on purpose -- there is no number here for a later seat to tune toward
410// a nicer answer:
411// SELFSUFF_BASE = SPONSOR_BASE's quarter vocabulary. ONE coefficient scale in this organ, not two.
412// SELFSUFF_FLOOR = the sponsor term's floor, for the sponsor term's reason: a zeroed value HIDES a
413// rung from the ranking, and a demotion must stay VISIBLE.
414// SELFSUFF_PEN_CAP = SELFSUFF_BASE - SELFSUFF_FLOOR. Not a knob: any larger value is unreachable
415// because the floor clamps first, and any smaller one would make the floor
416// unreachable, silently capping the term below its own vocabulary.
417//
418// d == 0 => multiplier == SELFSUFF_BASE => the value is UNCHANGED. That is the POSITIVE CONTROL, and
419// it is the tooth that matters: A TERM THAT PENALISES EVERYTHING PASSES EVERY NEGATIVE TEST.
420const SELFSUFF_BASE: i64 = 4
421const SELFSUFF_FLOOR: i64 = 1
422const SELFSUFF_PEN_CAP: i64 = SELFSUFF_BASE - SELFSUFF_FLOOR
423// (SELFSUFF_LEDGER_CAP=4194304 retired 2026-08-23: the ledger is a FILE and is read whole by rk_read_all)
424// compare b[s..e) against a NUL-terminated literal WITHOUT writing into the buffer -- the ledger is
425// read once and shared by every rung, so a parser that NUL-splits in place would corrupt the next
426// lookup (the sponsor term hands out copies for exactly this reason; not needing copies is cheaper).
427func rk_ss_eqf(b: *u8, s: i64, e: i64, lit: *u8) -> i64 {
428 var i: i64 = 0
429 var p: i64 = s
430 while p < e {
431 if lit[i] == (0 as u8) { return 0 }
432 if b[p] != lit[i] { return 0 }
433 p = p + 1
434 i = i + 1
435 }
436 if lit[i] == (0 as u8) { return 1 }
437 return 0
438}
439func rk_ss_atoi(b: *u8, s: i64, e: i64) -> i64 {
440 var v: i64 = 0
441 var neg: i64 = 0
442 var p: i64 = s
443 while p < e {
444 let c: i64 = b[p] as i64
445 if c == 45 { neg = 1 } else { if c >= 48 { if c <= 57 { v = v * 10 + (c - 48) } } }
446 p = p + 1
447 }
448 if neg == 1 { return 0 - v }
449 return v
450}
451// Returns the multiplier in units of SELFSUFF_BASE; the caller applies v = v * m / SELFSUFF_BASE.
452// Every row that fired is printed BY ID (domain/organ) beside the number, so the coefficient is
453// arguable from its evidence rather than taken on trust -- the sponsor term's contract, kept.
454func rk_selfsuff_term(led: *u8, ln: i64, dom: *u8, org: *u8, nb: *u8, no0: i64, noOut: *i64) -> i64 {
455 var no: i64 = no0
456 if ln <= 0 {
457 no = rk_cat(nb, no, " selfsuff=UNOBSERVED(no ledger -- run nx_selfsuff census)" as *u8)
458 noOut[0] = no
459 return SELFSUFF_BASE
460 }
461 let fs: *i64 = sys_mmap(16 * 8) as *i64
462 var found: i64 = 0
463 var outd: i64 = 0
464 var loopd: i64 = 0
465 var p: i64 = 0
466 while p < ln {
467 var e: i64 = p
468 var fnd: i64 = 0
469 while fnd == 0 { if e >= ln { fnd = 1 } else { if led[e] == (10 as u8) { fnd = 1 } else { e = e + 1 } } }
470 if found == 0 { if rk_starts((led as i64 + p) as *u8, "dep|" as *u8) == 1 {
471 var nf: i64 = 1
472 fs[0] = p
473 var q: i64 = p
474 while q < e { if led[q] == (124 as u8) { if nf < 16 { fs[nf] = q + 1; nf = nf + 1 } } q = q + 1 }
475 if nf >= 8 {
476 if rk_ss_eqf(led, fs[1], fs[2] - 1, dom) == 1 { if rk_ss_eqf(led, fs[2], fs[3] - 1, org) == 1 {
477 outd = rk_ss_atoi(led, fs[3], fs[4] - 1)
478 loopd = rk_ss_atoi(led, fs[6], fs[7] - 1)
479 found = 1
480 } }
481 }
482 } }
483 p = e + 1
484 }
485 if found == 0 {
486 // NOT the same state as a missing ledger, and NOT the same as zero dependency: this organ was
487 // never in the census population. Say which, and do not price what was not measured.
488 no = rk_cat(nb, no, " selfsuff=NO-LEDGER-ROW(organ absent from the census population)" as *u8)
489 noOut[0] = no
490 return SELFSUFF_BASE
491 }
492 var dep: i64 = outd + loopd
493 if dep < 0 { dep = 0 }
494 var pen: i64 = dep
495 if pen > SELFSUFF_PEN_CAP { pen = SELFSUFF_PEN_CAP }
496 var mult: i64 = SELFSUFF_BASE - pen
497 if mult < SELFSUFF_FLOOR { mult = SELFSUFF_FLOOR }
498 no = rk_cat(nb, no, " selfsuff[row=" as *u8); no = rk_cat(nb, no, dom); no = rk_cat(nb, no, "/" as *u8); no = rk_cat(nb, no, org)
499 no = rk_cat(nb, no, " outside_dep=" as *u8); no = rk_catn(nb, no, outd)
500 no = rk_cat(nb, no, " claude_loop=" as *u8); no = rk_catn(nb, no, loopd)
501 no = rk_cat(nb, no, " pen=min(dep,base-floor)=" as *u8); no = rk_catn(nb, no, pen)
502 no = rk_cat(nb, no, " mult_x4=" as *u8); no = rk_catn(nb, no, mult)
503 if dep == 0 { no = rk_cat(nb, no, " SOVEREIGN-NO-PENALTY" as *u8) }
504 no = rk_cat(nb, no, "]" as *u8)
505 noOut[0] = no
506 return mult
507}
508// walk one comma-separated rung-id token: resolve to a rung index; return 1 if that rung is OPEN
509// (not measured present); mode 1 additionally marks it on the critical path.
510func rk_list_one(idstr: *u8, mode: i64, rid: *i64, nr: i64, rdone: *i64, crit: *i64) -> i64 {
511 if idstr[0] == (0 as u8) { return 0 }
512 if idstr[0] == (45 as u8) { return 0 }
513 var r: i64 = 0
514 while r < nr {
515 if rk_streq(rid[r] as *u8, idstr) == 1 {
516 if rdone[r] == 0 { if mode == 1 { crit[r] = 1 } return 1 }
517 return 0
518 }
519 r = r + 1
520 }
521 return 0
522}
523// walk a whole comma list; returns how many listed rungs are OPEN (mode 1 also marks them critical)
524func rk_list_scan(ls: *u8, mode: i64, rid: *i64, nr: i64, rdone: *i64, crit: *i64) -> i64 {
525 let tmp: *u8 = sys_mmap(rk_slen(ls) + 2) // one token is never longer than the whole list
526 var di: i64 = 0
527 var dj: i64 = 0
528 var any: i64 = 0
529 var go: i64 = 1
530 while go == 1 {
531 let c: i64 = ls[di] as i64
532 if c == 44 { tmp[dj] = 0 as u8; any = any + rk_list_one(tmp, mode, rid, nr, rdone, crit); dj = 0 }
533 else { if c == 0 { tmp[dj] = 0 as u8; any = any + rk_list_one(tmp, mode, rid, nr, rdone, crit); go = 0 }
534 else { if c != 32 { tmp[dj] = ls[di]; dj = dj + 1 } } }
535 di = di + 1
536 }
537 return any
538}
539
540// the longest ver| label: the stage text one queue entry can carry ("later" is 5; a label may be longer)
541// ---- CE6: THE ORDER, AS AN ARTEFACT A PAGE CAN READ (2026-08-23) ----
542// One truncate-write per run (tmp + fsync + rename: a reader never sees a half file), canonical last line
543// = the stamp, so a consumer anchors by POSITION and never greps an append-only journal (the
544// nx_deploy_ready lesson). Path is the generator's tree: buildroot/knowledge/compare/<dom>.rank.
545func rk_write_rank(dom: *u8, buf: *u8, n0: i64, nr: i64, ndone: i64, nopen: i64, nfinish: i64, tgt: i64, vlab: *i64) -> i64 {
546 var n: i64 = n0
547 n = rk_cat(buf, n, "# asof=" as *u8); n = rk_catn(buf, n, sys_now_realtime_sec())
548 n = rk_cat(buf, n, " domain=" as *u8); n = rk_cat(buf, n, dom)
549 n = rk_cat(buf, n, " target_version=" as *u8)
550 if tgt >= 0 { n = rk_cat(buf, n, vlab[tgt] as *u8) } else { n = rk_cat(buf, n, "-" as *u8) }
551 n = rk_cat(buf, n, " rungs=" as *u8); n = rk_catn(buf, n, nr)
552 n = rk_cat(buf, n, " done=" as *u8); n = rk_catn(buf, n, ndone)
553 n = rk_cat(buf, n, " open=" as *u8); n = rk_catn(buf, n, nopen)
554 n = rk_cat(buf, n, " finish=" as *u8); n = rk_catn(buf, n, nfinish)
555 n = rk_cat(buf, n, " ranker=nx_dr_ocm\n" as *u8)
556 let dl: i64 = rk_slen(dom)
557 let outp: *u8 = sys_mmap(dl + 48)
558 var oo: i64 = rk_cat(outp, 0, "buildroot/knowledge/compare/" as *u8); oo = rk_cat(outp, oo, dom); oo = rk_cat(outp, oo, ".rank" as *u8)
559 let tmp: *u8 = sys_mmap(dl + 56)
560 var to: i64 = rk_cat(tmp, 0, outp); to = rk_cat(tmp, to, ".tmp" as *u8)
561 let fd: i64 = sys_openat_wr(tmp, MODE_0644)
562 if fd < 0 { rk_puts("RANK ARTEFACT WRITE-FAILED: cannot open " as *u8); rk_puts(tmp); rk_puts("\n" as *u8); return 0 - 1 }
563 var w: i64 = 0
564 while w < n {
565 let r: i64 = sys_write(fd, ((buf as i64) + w) as *u8, n - w)
566 if r <= 0 { sys_close(fd); rk_puts("RANK ARTEFACT WRITE-FAILED: short write\n" as *u8); return 0 - 1 }
567 w = w + r
568 }
569 sys_fsync(fd)
570 sys_close(fd)
571 if sys_renameat(tmp, outp) != 0 { rk_puts("RANK ARTEFACT WRITE-FAILED: rename\n" as *u8); return 0 - 1 }
572 rk_puts("RANK artefact wrote=" as *u8); rk_pn(n); rk_puts(" of=" as *u8); rk_puts(outp); rk_puts(" finish=" as *u8); rk_pn(nfinish); rk_puts("\n" as *u8)
573 return 0
574}
575func qcap_stage_max(vlab: *i64, nver: i64) -> i64 {
576 var best: i64 = 5
577 var k: i64 = 0
578 while k < nver { let l: i64 = rk_slen(vlab[k] as *u8); if l > best { best = l } k = k + 1 }
579 return best
580}
581
582func main(argc: i64, argv: *i64) -> i64 {
583 if argc < 2 { rk_puts("usage: nx_compare_rank <domain> [budget_tenths] [selfsuff_ledger] [--artifact-only]\n" as *u8); return 2 }
584 let dom: *u8 = argv[1] as *u8
585 if sg_id(dom,rk_slen(dom)) == 0 { rk_puts("RANK REFUSED: invalid domain identifier\n" as *u8);return 2 }
586 var budget: i64 = RANK_DEFAULT_BUDGET
587 var ssledp: *u8 = "knowledge/status/selfsuff.ledger" as *u8
588 var artifact_only: i64 = 0;var positional: i64 = 0;var argi: i64 = 2
589 while argi < argc {
590 let arg: *u8 = argv[argi] as *u8
591 if rk_streq(arg,"--artifact-only" as *u8)==1 { artifact_only=1 } else {
592 if positional==0 { budget=rk_int(arg) } else { if positional==1 { ssledp=arg } else { rk_puts("RANK REFUSED: unexpected argument\n" as *u8);return 2 } }
593 positional=positional+1
594 }
595 argi=argi+1
596 }
597 if artifact_only==1 { rk_puts("RANK mode=artifact-only task_queue_writes=0 readiness=UNVERIFIED; ranking is prioritization, not execution authorization\n" as *u8) }
598 // ---- read the plan ----
599 let dlen: i64 = rk_slen(dom)
600 let pp: *u8 = sys_mmap(dlen + 48) // "buildroot/knowledge/compare/" (28) + dom + ".matrix" (7) + NUL
601 var po: i64 = rk_cat(pp, 0, "buildroot/knowledge/compare/" as *u8); po = rk_cat(pp, po, dom); po = rk_cat(pp, po, ".plan" as *u8)
602 let pbp: *i64 = sys_mmap(16) as *i64
603 let pn: i64 = rk_read_all(pp, pbp)
604 let pbuf: *u8 = pbp[0] as *u8
605 if pn <= 0 { rk_puts("RANK REFUSED: no plan at " as *u8); rk_puts(pp); rk_puts("\n" as *u8); return 3 }
606 // ---- read the matrix ----
607 let mp: *u8 = sys_mmap(dlen + 48)
608 var mo: i64 = rk_cat(mp, 0, "buildroot/knowledge/compare/" as *u8); mo = rk_cat(mp, mo, dom); mo = rk_cat(mp, mo, ".matrix" as *u8)
609 let mbp: *i64 = sys_mmap(16) as *i64
610 let mn: i64 = rk_read_all(mp, mbp)
611 let mbuf: *u8 = mbp[0] as *u8
612 if mn <= 0 { rk_puts("RANK REFUSED: no matrix at " as *u8); rk_puts(mp); rk_puts("\n" as *u8); return 3 }
613 let captured: *SgPlan = sg_parse(pbuf,pn,0 as *u8,0,mbuf,mn)
614 if (captured as i64)==0 { rk_puts("RANK REFUSED: input capture unavailable\n" as *u8);return 7 }
615 if sg_valid(captured)!=1 {
616 // THE REFUSAL NAMES ITS OFFENDERS. The first line is UNCHANGED by design -- existing consumers
617 // match on it -- and the counters plus the per-row worklist follow it, because a verdict with
618 // no rows costs the next reader the whole investigation. Counters print first, rows after.
619 rk_puts("RANK REFUSED: malformed, missing, duplicate or cyclic authored graph\n" as *u8)
620 sg_graph_text(captured,1)
621 return 7
622 }
623 // A board that DECLARES cross-board references says so on every run. Printed only when there is
624 // at least one, so a board with none emits exactly the bytes this organ emitted before today.
625 if captured.external_deps > 0 { sg_graph_text(captured,1) }
626 // ---- DERIVED population bounds: rows <= lines of the matrix, rungs/ms/ver <= lines of the plan,
627 // fields per row <= pipes on the widest line -- counted from the loaded bytes, never a constant ----
628 let max_rows: i64 = rk_lines(mbuf, mn)
629 let max_rungs: i64 = rk_lines(pbuf, pn)
630 var max_fields: i64 = rk_max_pipes(mbuf, mn)
631 let pf: i64 = rk_max_pipes(pbuf, pn)
632 if pf > max_fields { max_fields = pf }
633 // ---- index matrix rows: symbol -> (present, sum of rival codes, all-absent) ----
634 let msym: *i64 = sys_mmap(max_rows * 8) as *i64
635 let morg: *i64 = sys_mmap(max_rows * 8) as *i64
636 let mdef: *i64 = sys_mmap(max_rows * 8) as *i64
637 let mall0: *i64 = sys_mmap(max_rows * 8) as *i64
638 let mlead: *i64 = sys_mmap(max_rows * 8) as *i64
639 let mpres: *i64 = sys_mmap(max_rows * 8) as *i64
640 var mrows: i64 = 0
641 var ncol: i64 = 0
642 let fld: *i64 = sys_mmap(max_fields * 8) as *i64
643 var p: i64 = 0
644 while p < mn {
645 var e: i64 = p
646 while e < mn { if mbuf[e] == (10 as u8) { break } e = e + 1 }
647 mbuf[e] = 0 as u8
648 let line: *u8 = (mbuf as i64 + p) as *u8
649 p = e + 1
650 if line[0] == (64 as u8) { if rk_starts(line, "@cols " as *u8) == 1 { let cf: *i64 = sys_mmap(max_fields * 8) as *i64; ncol = rk_split((line as i64 + 6) as *u8, cf, max_fields) } }
651 else { if line[0] != (0 as u8) { if line[0] != (35 as u8) {
652 let cnt: i64 = rk_split(line, fld, max_fields)
653 if cnt >= 5 + ncol { if mrows < max_rows {
654 msym[mrows] = fld[2]
655 morg[mrows] = fld[1]
656 var dsum: i64 = 0
657 var allz: i64 = 1
658 var nlead: i64 = 0
659 var cj: i64 = 0
660 while cj < ncol { let cv: i64 = rk_int(fld[4 + cj] as *u8); dsum = dsum + cv; if cv > 0 { allz = 0 } if cv >= 2 { nlead = nlead + 1 } cj = cj + 1 }
661 mdef[mrows] = dsum
662 mall0[mrows] = allz
663 mlead[mrows] = nlead
664 mpres[mrows] = 1
665 if rk_starts(fld[2] as *u8, "_ABSENT_" as *u8) == 1 { mpres[mrows] = 0 }
666 mrows = mrows + 1
667 } }
668 } } }
669 }
670 // ---- walk plan rungs: collect id/title/sym/exec/est/deps ----
671 let vlab: *i64 = sys_mmap(max_rungs * 8) as *i64
672 let vms: *i64 = sys_mmap(max_rungs * 8) as *i64
673 var nver: i64 = 0
674 let msid: *i64 = sys_mmap(max_rungs * 8) as *i64
675 let msrungs: *i64 = sys_mmap(max_rungs * 8) as *i64
676 var nms: i64 = 0
677 let rid: *i64 = sys_mmap(max_rungs * 8) as *i64
678 let rtitle: *i64 = sys_mmap(max_rungs * 8) as *i64
679 let rsym: *i64 = sys_mmap(max_rungs * 8) as *i64
680 let rexec: *i64 = sys_mmap(max_rungs * 8) as *i64
681 let rest: *i64 = sys_mmap(max_rungs * 8) as *i64
682 let rdeps: *i64 = sys_mmap(max_rungs * 8) as *i64
683 let rnote: *i64 = sys_mmap(max_rungs * 8) as *i64
684 var nr: i64 = 0
685 // THE BAR AND LADDER RULERS READ A PRISTINE COPY. rk_split in the rung walk below NUL-terminates every FIELD of every
686 // rung| row in place, so once that loop has run pbuf no longer spells "rung|" anywhere: a ruler handed pbuf counts zero
687 // rungs and reports every rungrole| row as an orphan. MEASURED live 2026-09-06 on a fully declared board: targets=3
688 // rungs=0 orphans=34 verdict=PARTIAL, a false refusal from the hook that exists to refuse half-declared ladders. The copy
689 // is taken BEFORE the walk; sotabar|, sotatarget| and rungrole| rows were never mutated, which is why the bar hook
690 // happened to read correctly and the ladder hook did not -- the same buffer, two answers, decided by which rows the
691 // ranker itself parses.
692 let prist: *u8 = sys_mmap(pn + 1)
693 var pci: i64 = 0
694 while pci < pn { prist[pci] = pbuf[pci]; pci = pci + 1 }
695 prist[pn] = 0 as u8
696 p = 0
697 while p < pn {
698 var e2: i64 = p
699 while e2 < pn { if pbuf[e2] == (10 as u8) { break } e2 = e2 + 1 }
700 pbuf[e2] = 0 as u8
701 let ln: *u8 = (pbuf as i64 + p) as *u8
702 p = e2 + 1
703 if rk_starts(ln, "rung|" as *u8) == 1 { if nr < max_rungs {
704 let c2: i64 = rk_split(ln, fld, max_fields)
705 if c2 >= 8 {
706 rid[nr] = fld[1]; rtitle[nr] = fld[2]; rsym[nr] = fld[3]; rexec[nr] = fld[5]
707 rnote[nr] = fld[4]
708 rest[nr] = rk_tenths(fld[6] as *u8)
709 rdeps[nr] = fld[7]
710 nr = nr + 1
711 }
712 } }
713 // ver|<label>|<ms-id>: the PRODUCT VERSION ladder (operator 2026-08-18: critical paths to 0.1
714 // then 1.0 then 2.0 drive delivery, digital and physical). Order in the file IS the ladder.
715 if rk_starts(ln, "ver|" as *u8) == 1 { if nver < max_rungs {
716 let c3: i64 = rk_split(ln, fld, max_fields)
717 if c3 >= 3 { vlab[nver] = fld[1]; vms[nver] = fld[2]; nver = nver + 1 }
718 } }
719 // ms|<id>|<label>|<cum>|<rung,rung,...>
720 if rk_starts(ln, "ms|" as *u8) == 1 { if nms < max_rungs {
721 let c4: i64 = rk_split(ln, fld, max_fields)
722 if c4 >= 5 { msid[nms] = fld[1]; msrungs[nms] = fld[4]; nms = nms + 1 }
723 } }
724 }
725 if nr == 0 { rk_puts("RANK REFUSED: plan has no rung rows\n" as *u8); return 3 }
726 // BAR FRESHNESS -- THE HARD FAIL (operator 2026-09-06: "make sure its a hard fail to use anything less than current
727 // month unless there is nothing current month" and "this needs to become the way that the logic forces you from the
728 // /compare domain"). The plan's sotabar| rows carry their source month and its barscan| rows attest what THIS month's
729 // listing returned; nx_barfresh_lib is the one ruler. A domain that declared bars and let them go stale gets NO ranking
730 // and NO pm filing: the board refuses to hand out work until the bar is the current month's or its fallback is attested
731 // this month. A domain with no bar rows is LABELED, never refused -- it opts in by declaring its first bar (a fleet-wide
732 // refusal on day one would be the permanently-red detector everyone learns to ignore). prist is the pristine copy taken
733 // before the rung walk (rk_split NUL-terminates every field in place); the ruler reads both line endings.
734 let bfc: *i64 = sys_mmap(BF_C_N * 8) as *i64
735 let bfnb: i64 = bf_count_rows(prist, pn, BF_BAR_TAG)
736 let bfoff: *i64 = sys_mmap((bfnb + 1) * 8) as *i64
737 let bfym: *i64 = sys_mmap((bfnb + 1) * 8) as *i64
738 let bfst: *i64 = sys_mmap((bfnb + 1) * 8) as *i64
739 let bfseen: *i64 = sys_mmap((bfnb + 1) * 8) as *i64
740 let bfcur: i64 = bf_now_ym()
741 bf_classify(prist, pn, bfcur, bfoff, bfym, bfst, bfseen, bfc)
742 let bfv: i64 = bf_verdict(bfc)
743 rk_puts("BARFRESH bars=" as *u8); rk_pn(bfc[BF_C_BARS]); rk_puts(" fresh=" as *u8); rk_pn(bfc[BF_C_FRESH]); rk_puts(" attested=" as *u8); rk_pn(bfc[BF_C_ATTESTED]); rk_puts(" stale=" as *u8); rk_pn(bfc[BF_C_STALE]); rk_puts(" unattested=" as *u8); rk_pn(bfc[BF_C_UNATTESTED]); rk_puts(" malformed=" as *u8); rk_pn(bfc[BF_C_MALFORMED]); rk_puts(" duplicate=" as *u8); rk_pn(bfc[BF_C_DUPLICATE]); rk_puts(" sum=" as *u8); rk_pn(bf_partition_sum(bfc)); rk_puts(" scans_this_month=" as *u8); rk_pn(bfc[BF_C_SCANS_CUR]); rk_puts(" scans_dup=" as *u8); rk_pn(bfc[BF_C_SCANS_DUP]); rk_puts(" verdict=" as *u8); rk_puts(bf_verdict_name(bfv)); rk_puts("\n" as *u8)
744 if bfv == BF_EXIT_NOBAR { rk_puts("BARFRESH NO-BAR: this plan declares no sotabar| row, so its bars are UNMEASURED -- LABELED, ranking proceeds; declare the field's current-month bar (sotabar|<id>|<YYYY-MM>|<subject>|<what it says>|<ref>|<note>) to opt into the hard fail\n" as *u8) }
745 if bfv == BF_EXIT_STALE {
746 rk_puts("RANK REFUSED: BAR-STALE rule=" as *u8); rk_puts(bf_refusal_rule(bfc)); rk_puts(" -- " as *u8)
747 if bfc[BF_C_DUPLICATE] + bfc[BF_C_SCANS_DUP] > 0 {
748 rk_puts("a sotabar id or a same-day barscan for one ref is declared TWICE on this board (duplicate bars=" as *u8); rk_pn(bfc[BF_C_DUPLICATE]); rk_puts(" duplicate scans=" as *u8); rk_pn(bfc[BF_C_SCANS_DUP]); rk_puts("); two rows for one declaration hand every reader a coin flip, so the board hands out no work until one row remains: run nx_barfresh " as *u8); rk_puts(dom); rk_puts(" for the per-bar states (the later row reads DUPLICATE) and remove the repeated row\n" as *u8)
749 } else {
750 rk_puts("a bar on this board is older than the current month and no barscan| row dated this month attests that the current month has nothing newer for its listing. The board hands out no work on a stale bar: run nx_barfresh " as *u8); rk_puts(dom); rk_puts(" for the per-bar states, fetch and READ the current month's listing (nx_research_fetch, pinned as a .refs row), then land a current sotabar| row or a barscan|<today>|<ref>|newest=<month> attestation\n" as *u8)
751 }
752 return RANK_EXIT_BAR_STALE
753 }
754 // LADDER TO SOTA (operator 2026-09-06: "how you framed it here is how all the /compare domains should be emitting with
755 // clarity on what dependencies from the first byte up all grow us each rung up to sota with a clear target on what is
756 // best in class and what is frontier"). sotatarget| rows name the dated targets and rungrole| rows give every rung its
757 // role toward one; nx_ladder_lib is the one ruler. A board that declared its ladder and left it half-declared (an
758 // undated target, a rung with no role, a role or class outside the vocabulary) is refused like a stale bar; a board with
759 // no ladder is LABELED and ranked -- it opts in by declaring its first target.
760 let ldnt: i64 = bf_count_rows(prist, pn, LD_TARGET_TAG)
761 let ldnr: i64 = bf_count_rows(prist, pn, LD_RUNG_TAG)
762 let ldc: *i64 = sys_mmap(LD_N_COUNT * 8) as *i64
763 let ldtoff: *i64 = sys_mmap((ldnt + 1) * 8) as *i64
764 let ldtcls: *i64 = sys_mmap((ldnt + 1) * 8) as *i64
765 let ldtst: *i64 = sys_mmap((ldnt + 1) * 8) as *i64
766 let ldroff: *i64 = sys_mmap((ldnr + 1) * 8) as *i64
767 let ldrrole: *i64 = sys_mmap((ldnr + 1) * 8) as *i64
768 let ldrtgt: *i64 = sys_mmap((ldnr + 1) * 8) as *i64
769 let ldrst: *i64 = sys_mmap((ldnr + 1) * 8) as *i64
770 ld_classify(prist, pn, ldtoff, ldtcls, ldtst, ldroff, ldrrole, ldrtgt, ldrst, ldc)
771 let ldv: i64 = ld_verdict(ldc)
772 rk_puts("LADDER targets=" as *u8); rk_pn(ldc[LD_N_TARGETS]); rk_puts(" best_in_class=" as *u8); rk_pn(ldc[LD_N_BIC]); rk_puts(" frontier=" as *u8); rk_pn(ldc[LD_N_FRONTIER]); rk_puts(" undated=" as *u8); rk_pn(ldc[LD_N_UNDATED]); rk_puts(" badclass=" as *u8); rk_pn(ldc[LD_N_BADCLASS]); rk_puts(" rungs=" as *u8); rk_pn(ldc[LD_N_RUNGS]); rk_puts(" placed=" as *u8); rk_pn(ldc[LD_N_PLACED]); rk_puts(" unplaced=" as *u8); rk_pn(ldc[LD_N_UNPLACED]); rk_puts(" badrole=" as *u8); rk_pn(ldc[LD_N_BADROLE]); rk_puts(" badtarget=" as *u8); rk_pn(ldc[LD_N_BADTARGET]); rk_puts(" sum=" as *u8); rk_pn(ld_partition_sum(ldc)); rk_puts(" substrate=" as *u8); rk_pn(ldc[LD_N_SUBSTRATE]); rk_puts(" arm=" as *u8); rk_pn(ldc[LD_N_ARM]); rk_puts(" contender=" as *u8); rk_pn(ldc[LD_N_CONTENDER]); rk_puts(" superseded=" as *u8); rk_pn(ldc[LD_N_SUPERSEDED]); rk_puts(" orphans=" as *u8); rk_pn(ldc[LD_N_ORPHANS]); rk_puts(" duptarget=" as *u8); rk_pn(ldc[LD_N_DUPTARGET]); rk_puts(" duprole=" as *u8); rk_pn(ldc[LD_N_DUPROLE]); rk_puts(" verdict=" as *u8); rk_puts(ld_verdict_name(ldv)); rk_puts("\n" as *u8)
773 if ldv == LD_EXIT_NOLADDER { rk_puts("LADDER NO-LADDER: this plan names no sotatarget| row, so what best-in-class and the frontier ARE is UNDECLARED -- LABELED, ranking proceeds; declare a dated best-in-class and a dated frontier target (sotatarget|<id>|<class>|<sotabar id>|<statement>|<ref>) and a rungrole|<rung>|<role>|<target>|<why> row per rung to opt into the hard fail\n" as *u8) }
774 if ldv == LD_EXIT_PARTIAL {
775 rk_puts("RANK REFUSED: LADDER-PARTIAL rule=" as *u8); rk_puts(ld_refusal_rule(ldc)); rk_puts(" -- " as *u8)
776 if ldc[LD_N_DUPTARGET] + ldc[LD_N_DUPROLE] > 0 {
777 rk_puts("a sotatarget id or a rung's rungrole is declared TWICE on this board (duplicate targets=" as *u8); rk_pn(ldc[LD_N_DUPTARGET]); rk_puts(" duplicate roles=" as *u8); rk_pn(ldc[LD_N_DUPROLE]); rk_puts("); two rows for one declaration hand every reader a coin flip, so the board hands out no work until one row remains: run nx_ladder " as *u8); rk_puts(dom); rk_puts(" for the per-target and per-rung states (the later target row reads DUPLICATE) and remove the repeated row\n" as *u8)
778 } else {
779 rk_puts("this board declared its ladder to SOTA and left it half-declared: a target without a sotabar row, a class or role outside the vocabulary, a rung with no rungrole row, or a rungrole row naming no rung or no target. The board hands out no work on a half-declared ladder: run nx_ladder " as *u8); rk_puts(dom); rk_puts(" for the per-target and per-rung states and complete the declaration\n" as *u8)
780 }
781 return RANK_EXIT_LADDER_PARTIAL
782 }
783 // THREE-STEP TREATMENT (ecosystem EC49, operator 2026-09-16: "make sure its mandatory that they get mcp and api and
784 // composable primitives and workflows and agent treatment in our 1 2 3 step process"). A treat|<rung>|mcp=|api=|prim=|wf=|agent=
785 // row is judged by nx_treatment_lib, the one ruler, against evidence the estate already keeps: tool_allowlist.conf (the MCP
786 // row, GREEN, and with it the API route), the source tree through ep_src_path (the primitive), the plan_run plane manifest
787 // knowledge/store/plan-<id>-manifest.txt (the workflow), the clock DESIRED plane and knowledge/gateroster.conf (the agent).
788 // A board that declared treat rows and left one unmet is refused like a stale bar; a board with none is LABELED and ranked
789 // (it opts in by declaring its first row); a rung with no treat row prints TREATMENT-UNDECLARED on its line below.
790 let trcap: i64 = trt_cap(pn)
791 let trtab: *i64 = sys_mmap(trcap * TRT_STRIDE * 8) as *i64
792 let trrows: i64 = trt_scan(prist, pn, trtab, trcap)
793 let trc: *i64 = sys_mmap(TRT_C_SLOTS * 8) as *i64
794 if trrows > 0 {
795 let trap: *i64 = sys_mmap(16) as *i64
796 let tran: i64 = rk_trt_read(RK_TRT_ALLOW, trap)
797 let trrp: *i64 = sys_mmap(16) as *i64
798 let trrn: i64 = rk_trt_read(RK_TRT_ROSTER, trrp)
799 // the clock DESIRED plane through the CLI lane, exactly as the sponsor plane below: ONE fork per run, never per rung
800 let trcav: *i64 = sys_mmap(8 * 8) as *i64
801 trcav[0] = "./nx_store_put.elf" as *u8 as i64
802 trcav[1] = RK_TRT_CLOCK_PLANE as i64
803 trcav[2] = "load" as *u8 as i64
804 trcav[3] = 0
805 let trclock: *u8 = sys_mmap(RK_TRT_CLOCK_CAP)
806 let trcl: *i64 = sys_mmap(16) as *i64
807 trcl[0] = 0
808 tr_run_capture("./nx_store_put.elf" as *u8, trcav, trclock, RK_TRT_CLOCK_CAP - 1, trcl)
809 var trcn: i64 = trcl[0]
810 if trcn < 0 { trcn = 0 }
811 // a capture that fills its reserve is a PREFIX: an agent judged against a prefix could read ABSENT for a row past the
812 // cut, so the plane is treated as UNOBSERVED (DECLARED stays DECLARED, the row reads PARTIAL and names the field)
813 if trcn >= RK_TRT_CLOCK_CAP - 1 { rk_puts("TREATMENT clock plane CAPTURE-FULL at RK_TRT_CLOCK_CAP -- treated as UNOBSERVED, agent fields stay DECLARED\n" as *u8); trcn = 0 }
814 rk_puts("TREATMENT-EVIDENCE allowlist_bytes=" as *u8); rk_pn(tran); rk_puts(" roster_bytes=" as *u8); rk_pn(trrn); rk_puts(" clock_plane_bytes=" as *u8); rk_pn(trcn); rk_puts("\n" as *u8)
815 let trsp: *u8 = sys_mmap(RK_TRT_PATH_CAP)
816 let trwf: *u8 = sys_mmap(RK_TRT_PATH_CAP)
817 let trwp: *u8 = sys_mmap(RK_TRT_PATH_CAP)
818 var trr: i64 = 0
819 while trr < trrows {
820 let trb: i64 = trr * TRT_STRIDE
821 var trprim: i64 = 0 - 1
822 var trwfok: i64 = 0 - 1
823 if trtab[trb + TRT_ST_PRIM] == TRT_F_DECLARED {
824 let trpn: *u8 = rk_span_copy(prist, trtab[trb + TRT_PRIM_O], trtab[trb + TRT_PRIM_L])
825 trprim = ep_src_path(trsp, trpn)
826 }
827 if trtab[trb + TRT_ST_WF] == TRT_F_DECLARED {
828 var trwo: i64 = rk_cat(trwf, 0, RK_TRT_WF_PFX)
829 let trwn: *u8 = rk_span_copy(prist, trtab[trb + TRT_WF_O], trtab[trb + TRT_WF_L])
830 trwo = rk_cat(trwf, trwo, trwn)
831 trwo = rk_cat(trwf, trwo, RK_TRT_WF_SFX)
832 trwfok = ep_artifact_path(trwp, trwf)
833 }
834 trt_judge_row(trtab, trr, prist, trap[0] as *u8, tran, trrp[0] as *u8, trrn, trclock, trcn, trprim, trwfok)
835 trr = trr + 1
836 }
837 }
838 trt_census(trtab, trrows, prist, pn, trc)
839 let trv: i64 = trt_verdict(trc)
840 rk_puts("TREATMENT rows=" as *u8); rk_pn(trc[TRT_C_ROWS]); rk_puts(" complete=" as *u8); rk_pn(trc[TRT_C_COMPLETE]); rk_puts(" partial=" as *u8); rk_pn(trc[TRT_C_PARTIAL]); rk_puts(" fields=" as *u8); rk_pn(trc[TRT_C_FIELDS]); rk_puts(" sum=" as *u8); rk_pn(trt_partition_sum(trc)); rk_puts(" rungs=" as *u8); rk_pn(trc[TRT_C_RUNGS]); rk_puts(" undeclared=" as *u8); rk_pn(trc[TRT_C_UNDECLARED]); rk_puts(" verdict=" as *u8); rk_puts(trt_exit_name(trv)); rk_puts("\n" as *u8)
841 if trv == TRT_EXIT_NONE { rk_puts("TREATMENT NO-TREATMENT: this plan declares no treat| row, so whether its rungs get the MCP, API, primitive, workflow and agent treatment is UNDECLARED -- LABELED, ranking proceeds; declare treat|<rung>|mcp=<allowlist row>|api=<route>|prim=<lib>|wf=<plan_run id>|agent=<clock or roster row> per rung to opt into the hard fail\n" as *u8) }
842 if trv == TRT_EXIT_PARTIAL {
843 rk_puts("RANK REFUSED: TREATMENT-PARTIAL -- a declared treat| row on this board is unmet: a field left as a dash, an MCP row absent from tool_allowlist.conf or not GREEN (its API route follows it), a primitive with no source in the tree, a workflow with no plan_run plane manifest, an agent on neither the clock DESIRED plane nor the gate roster, or a row short of its seven fields. The board hands out no work on a half-treated rung:\n" as *u8)
844 let trmb: *u8 = sys_mmap(RK_TRT_MISS_CAP)
845 var trq: i64 = 0
846 while trq < trrows {
847 let trqb: i64 = trq * TRT_STRIDE
848 let trqv: i64 = trtab[trqb + TRT_VERDICT]
849 if trqv != TRT_V_COMPLETE {
850 rk_puts(" TREAT rung=" as *u8); sys_write(1, (prist as i64 + trtab[trqb + TRT_RUNG_O]) as *u8, trtab[trqb + TRT_RUNG_L]); rk_puts(" verdict=" as *u8); rk_puts(trt_verdict_name(trqv))
851 if trqv == TRT_V_PARTIAL { trt_missing(trtab, trq, trmb, 0); rk_puts(" missing=" as *u8); rk_puts(trmb) }
852 rk_puts("\n" as *u8)
853 }
854 trq = trq + 1
855 }
856 rk_puts(" run nx_treatment " as *u8); rk_puts(dom); rk_puts(" for the per-row states and complete the treatment\n" as *u8)
857 return RANK_EXIT_TREATMENT_PARTIAL
858 }
859 // ES28: the incumbents index, loaded once per run; its coverage envelope printed here, its answer printed under
860 // every ranked rung (the estate answers the contract, the seat reads the answer)
861 rk_inc_c = inc_conf_load() as i64
862 rk_inc_g = inc_load(rk_inc_c as *i64) as i64
863 let incout: *u8 = sys_mmap(RK_INC_OUT) as *u8
864 inc_envelope(rk_inc_g as *i64, incout, RK_INC_OUT)
865 rk_puts(incout); rk_puts("\n" as *u8)
866 // ---- derive v/m/c per OPEN rung (a rung whose symbol is measured PRESENT is done: skipped, counted) ----
867 let ov: *i64 = sys_mmap(nr * 8) as *i64
868 let om: *i64 = sys_mmap(nr * 8) as *i64
869 let oc: *i64 = sys_mmap(nr * 8) as *i64
870 let oidx: *i64 = sys_mmap(nr * 8) as *i64
871 let onote: *i64 = sys_mmap(nr * 8) as *i64
872 let rdone: *i64 = sys_mmap(nr * 8) as *i64
873 let rmi: *i64 = sys_mmap(nr * 8) as *i64
874 // DARK CONTRACT per rung (2026-09-06, operator: a permanent fix, we do not build and lose capability to darkness):
875 // 1 when the rung's matrix row names an organ that EXISTS and was read but does not declare the contracted
876 // symbol -- something shipped under another name; printed on the rung line so the repoint is priced as work.
877 let rdark_r: *i64 = sys_mmap(nr * 8) as *i64
878 var nopen: i64 = 0
879 var ndone: i64 = 0
880 // PASS A: measure every rung's presence first, so the momentum pass can read ANY dependency's
881 // state regardless of declaration order.
882 var i: i64 = 0
883 while i < nr {
884 var mi: i64 = 0 - 1
885 var q: i64 = 0
886 while q < mrows { if rk_sym_is(msym[q] as *u8, rsym[i] as *u8) == 1 { mi = q; q = mrows } q = q + 1 }
887 var done: i64 = 0
888 if mi >= 0 {
889 if mpres[mi] == 1 { done = 1 }
890 else {
891 var symp: *u8 = msym[mi] as *u8
892 if rk_starts(symp, "_ABSENT_:" as *u8) == 1 { symp = (symp as i64 + 9) as *u8 }
893 done = rk_measure(morg[mi] as *u8, symp)
894 if done == 0 { rdark_r[i] = rk_dark(morg[mi] as *u8, symp) }
895 }
896 }
897 rdone[i] = done
898 rmi[i] = mi
899 if done == 1 { ndone = ndone + 1 }
900 i = i + 1
901 }
902 // ---- CE2: ADOPTION of every DONE rung (present by symbol) -- FULL or PARTIAL, judged by the shared
903 // classifier (program ladder / library importer reach / gate execution surfaces), memoised per organ ----
904 let ads: *i64 = sys_mmap(CLB_N * 8) as *i64
905 clb_load(ads)
906 let rfin: *i64 = sys_mmap(nr * 8) as *i64
907 let rtok: *i64 = sys_mmap(nr * 8) as *i64
908 let rrem: *i64 = sys_mmap(nr * 8) as *i64
909 let mname: *i64 = sys_mmap(nr * 8) as *i64
910 let mtok: *i64 = sys_mmap(nr * 8) as *i64
911 let mful: *i64 = sys_mmap(nr * 8) as *i64
912 let mrem: *i64 = sys_mmap(nr * 8) as *i64
913 var mc: i64 = 0
914 var nfinish: i64 = 0
915 var fi: i64 = 0
916 while fi < nr {
917 rfin[fi] = 0
918 rtok[fi] = "" as *u8 as i64
919 rrem[fi] = "" as *u8 as i64
920 if rdone[fi] == 1 { if rmi[fi] >= 0 {
921 let oname: *u8 = sys_mmap(CLB_TOK_CAP)
922 cl_name_of_path(morg[rmi[fi]] as *u8, oname, CLB_TOK_CAP)
923 var hit: i64 = 0 - 1
924 var mk: i64 = 0
925 while mk < mc { if rk_streq(mname[mk] as *u8, oname) == 1 { hit = mk; mk = mc } mk = mk + 1 }
926 if hit < 0 {
927 let tokb: *u8 = sys_mmap(CLB_TOK_CAP)
928 let remp: *i64 = sys_mmap(8) as *i64
929 let ful: i64 = clb_classify(oname, ads, tokb, remp)
930 mname[mc] = oname as i64; mtok[mc] = tokb as i64; mful[mc] = ful; mrem[mc] = remp[0]
931 hit = mc
932 mc = mc + 1
933 }
934 rtok[fi] = mtok[hit]
935 rrem[fi] = mrem[hit]
936 if mful[hit] != CLB_FULL { rfin[fi] = 1; nfinish = nfinish + 1 }
937 } }
938 fi = fi + 1
939 }
940 // the stamped artefact: sized from the rows it will hold, never a cap
941 let binding_cap: i64 = rk_slen("# inputs_v=1 plan_sha256= plan_bytes= matrix_sha256= matrix_bytes=\n") + sg_len(captured.plan_sha) + sg_len(captured.matrix_sha) + RK_DEC_MAX*2
942 var rkcap: i64 = RANK_FIX_TAIL + rk_slen(dom) + 64 + binding_cap
943 var rkz: i64 = 0
944 // + RANK_UNMAPPED_ROW and a SECOND id/sym pair per rung (2026-09-01): every rung can now also emit
945 // an `unmapped|<id>|<sym>|...` row, and id and sym appear in BOTH that row and its rank| row. Budget
946 // for the worst case -- every rung unmapped -- because a cap that assumes some rungs are carried
947 // would under-size exactly on the board that most needs this row.
948 while rkz < nr { rkcap = rkcap + RANK_FIX_PER_RUNG + RANK_UNMAPPED_ROW + rk_slen(rid[rkz] as *u8) + rk_slen(rid[rkz] as *u8) + rk_slen(rtitle[rkz] as *u8) + rk_slen(rsym[rkz] as *u8) + rk_slen(rsym[rkz] as *u8) + rk_slen(rtok[rkz] as *u8) + rk_slen(rrem[rkz] as *u8); rkz = rkz + 1 }
949 let rkbuf: *u8 = sys_mmap(rkcap)
950 var rko: i64 = rk_cat(rkbuf, 0, "# " as *u8); rko = rk_cat(rkbuf, rko, dom); rko = rk_cat(rkbuf, rko, ".rank -- NX-DERIVED: regenerated artefact, not authored memory (nx_compare_rank). rows: finish|id|title|sym|state|remedy . rank|n|stage|id|priority|v|m|c|title|sym . unmapped-count|n|why . unmapped|id|sym|reason (a rung NO matrix row carries: priced at zero, so the dimension is invisible to every consumer -- the count is emitted even when it is 0, because a declared zero proves the check ran and silence does not) . last line = stamp\n" as *u8)
951 rko=rk_cat(rkbuf,rko,"# inputs_v=1 plan_sha256=" as *u8);rko=rk_cat(rkbuf,rko,captured.plan_sha)
952 rko=rk_cat(rkbuf,rko," plan_bytes=" as *u8);rko=rk_catn(rkbuf,rko,pn)
953 rko=rk_cat(rkbuf,rko," matrix_sha256=" as *u8);rko=rk_cat(rkbuf,rko,captured.matrix_sha)
954 rko=rk_cat(rkbuf,rko," matrix_bytes=" as *u8);rko=rk_catn(rkbuf,rko,mn);rko=rk_cat(rkbuf,rko,"\n" as *u8)
955 var fp: i64 = 0
956 while fp < nr {
957 if rfin[fp] == 1 {
958 rk_puts(" F [FINISH] " as *u8); rk_puts(rid[fp] as *u8); rk_puts(" state=" as *u8); rk_puts(rtok[fp] as *u8); rk_puts(" | " as *u8); rk_puts(rtitle[fp] as *u8); rk_puts(" [" as *u8); rk_puts(rsym[fp] as *u8); rk_puts("] " as *u8); rk_puts(rrem[fp] as *u8); rk_puts("\n" as *u8)
959 rko = rk_cat(rkbuf, rko, "finish|" as *u8); rko = rk_cat(rkbuf, rko, rid[fp] as *u8); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, rtitle[fp] as *u8); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, rsym[fp] as *u8)
960 rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, rtok[fp] as *u8); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, rrem[fp] as *u8); rko = rk_cat(rkbuf, rko, "\n" as *u8)
961 }
962 fp = fp + 1
963 }
964 // sponsor plane, loaded ONCE through the CLI lane (a fork per rung would be N forks for one read)
965 let spav: *i64 = sys_mmap(8 * 8) as *i64
966 spav[0] = "./nx_store_put.elf" as *u8 as i64
967 spav[1] = "sponsor-" as *u8 as i64
968 spav[2] = "load" as *u8 as i64
969 spav[3] = 0
970 let splane: *u8 = sys_mmap(SPONSOR_PLANE_CAP)
971 let splen: *i64 = sys_mmap(16) as *i64
972 splen[0] = 0
973 tr_run_capture("./nx_store_put.elf" as *u8, spav, splane, SPONSOR_PLANE_CAP - 1, splen)
974 let splines: i64 = rk_lines(splane, splen[0]) // the most rows any note could name: every row of the plane
975 // a capture that fills its pipe budget is a PREFIX: say so (the plane is a fork, its size unknowable)
976 if splen[0] >= SPONSOR_PLANE_CAP - 1 { rk_puts("SPONSOR plane CAPTURE-FULL at SPONSOR_PLANE_CAP -- rows past the cap are NOT applied, LABELED\n" as *u8) }
977 // a plane that failed to load is UNOBSERVED, not empty: say so once, rank without the term
978 if splen[0] <= 0 { rk_puts("SPONSOR plane UNOBSERVED (load returned nothing) -- ranking without the sponsorship term, LABELED\n" as *u8) }
979 // PR11: the self-sufficiency ledger, read ONCE. A plain file read, not a plane fork: the ledger is
980 // a derived artefact with ONE writer (nx_selfsuff census), so it needs neither a segment commit nor
981 // a fork per rung, and under the load this estate actually runs at that difference is the whole
982 // cost of the term.
983 let ssbp: *i64 = sys_mmap(16) as *i64
984 var ssn: i64 = rk_read_all(ssledp, ssbp) // the WHOLE ledger (a file, sized from itself)
985 let ssbuf: *u8 = ssbp[0] as *u8
986 if ssn < 0 { ssn = 0 }
987 if ssn <= 0 { rk_puts("SELFSUFF ledger UNOBSERVED (nothing at " as *u8); rk_puts(ssledp); rk_puts(") -- ranking without the self-sufficiency term, LABELED per rung\n" as *u8) }
988 else { rk_puts("SELFSUFF ledger " as *u8); rk_puts(ssledp); rk_puts(" bytes=" as *u8); rk_pn(ssn); rk_puts("\n" as *u8) }
989 // ---- ENABLEMENT (foundation-first, from the dependency graph): for each open rung, how many OTHER
990 // open rungs have it in their transitive dependency closure. A rung that unblocks five others is
991 // worth five downstream deliveries -- this is the WSJF "opportunity enablement" leg and the real-
992 // options "compound option" value, both COUNTED from dep rows, never chosen. O(n^2) closure walk
993 // over nr rungs (nr is the plan's own count; the former "<=64" was the cap this lane removed).
994 let enab: *i64 = sys_mmap(nr * 8) as *i64
995 var ez: i64 = 0
996 while ez < nr { enab[ez] = 0; ez = ez + 1 }
997 var a6: i64 = 0
998 while a6 < nr {
999 if rdone[a6] == 0 {
1000 // closure of a6's deps: mark reachable open rungs
1001 let reach: *i64 = sys_mmap(nr * 8) as *i64
1002 var z6: i64 = 0
1003 while z6 < nr { reach[z6] = 0; z6 = z6 + 1 }
1004 rk_list_scan(rdeps[a6] as *u8, 1, rid, nr, rdone, reach)
1005 var it6: i64 = 0
1006 while it6 < nr {
1007 var grew: i64 = 0
1008 var b6: i64 = 0
1009 while b6 < nr {
1010 if reach[b6] == 1 {
1011 var pre6: i64 = 0; var q6: i64 = 0
1012 while q6 < nr { pre6 = pre6 + reach[q6]; q6 = q6 + 1 }
1013 rk_list_scan(rdeps[b6] as *u8, 1, rid, nr, rdone, reach)
1014 var post6: i64 = 0; q6 = 0
1015 while q6 < nr { post6 = post6 + reach[q6]; q6 = q6 + 1 }
1016 if post6 > pre6 { grew = 1 }
1017 }
1018 b6 = b6 + 1
1019 }
1020 if grew == 0 { it6 = nr }
1021 it6 = it6 + 1
1022 }
1023 // every rung in a6's closure enables a6: credit each
1024 var c6: i64 = 0
1025 while c6 < nr { if reach[c6] == 1 { enab[c6] = enab[c6] + 1 } c6 = c6 + 1 }
1026 }
1027 a6 = a6 + 1
1028 }
1029 // ---- rival total for the cost-of-delay ratio (from @cols) ----
1030 var nriv: i64 = ncol
1031 if nriv < 1 { nriv = 1 }
1032 // PASS B: derive v/m/c for the open rungs
1033 i = 0
1034 while i < nr {
1035 let mi: i64 = rmi[i]
1036 if rdone[i] == 1 { } else {
1037 var v: i64 = 0
1038 // the note is literals + numbers + (sponsor rows named verbatim, bounded by the plane's own
1039 // length) + (the organ path the selfsuff term echoes): sized from those parts, never a cap
1040 var nbcap: i64 = RK_NOTE_LITERALS + RK_NOTE_NUMS * RK_DEC_MAX + splen[0] + splines * RK_SPONSOR_ROW_LITERALS + rk_slen(dom) + rk_slen(rid[i] as *u8) + rk_slen(rsym[i] as *u8) + 16
1041 if mi >= 0 { nbcap = nbcap + rk_slen(morg[mi] as *u8) }
1042 let nb: *u8 = sys_mmap(nbcap)
1043 var no: i64 = 0
1044 // EC49: a rung with no treat| row on a board that declares treatment is NAMED on its line, never refused -- the
1045 // refusal above is for a row declared and left unmet; an undeclared rung is a labeled gap the seat prices as work
1046 if trrows > 0 { if trt_find(trtab, trrows, prist, rid[i] as *u8) < 0 { no = rk_cat(nb, no, "TREATMENT-UNDECLARED(no treat row for this rung: declare its mcp, api, primitive, workflow and agent) " as *u8) } }
1047 if mi >= 0 {
1048 // COST OF DELAY (WSJF): the deficit is the value at stake; the fraction of rivals already
1049 // LEADING (code 2) on this row is the time-criticality -- every day open, that many rivals
1050 // widen the gap. CoD = deficit x leading / rivals, in the same integer units as deficit,
1051 // plus the deficit itself as the base value. Both from the matrix codes.
1052 let lead: i64 = mlead[mi]
1053 let cod: i64 = mdef[mi] * lead / nriv
1054 v = mdef[mi] + cod
1055 if rdark_r[i] == 1 { no = rk_cat(nb, no, "DARK-CONTRACT(organ exists, symbol undeclared: repoint the rung AND its row to the real entry point, or rename the function) " as *u8) }
1056 no = rk_cat(nb, no, "deficit=" as *u8); no = rk_catn(nb, no, mdef[mi])
1057 no = rk_cat(nb, no, " cod=deficit*leading/rivals=" as *u8); no = rk_catn(nb, no, cod)
1058 // REAL-OPTION VALUE (exceed lane): a row NO rival has is an option on a lead; its value
1059 // is what it unlocks -- the enablement count in deficit units, plus one for the lead
1060 // itself. DERIVED, replacing the former constant bonus.
1061 // the option is the LEAD itself (1) on top of the enablement every rung already carries
1062 // below -- counting enables inside the option AND as its own leg double-charged exceed
1063 // rows (measured 2026-08-18: R14 printed option=1+enables=8 AND +enables=7). One leg each.
1064 if mall0[mi] == 1 { v = v + 1; no = rk_cat(nb, no, " +option(all rivals absent: a lead nobody holds)=1" as *u8) }
1065 } else { no = rk_cat(nb, no, "UNMAPPED(no matrix row carries this symbol) value=0" as *u8) }
1066 // ENABLEMENT: downstream open rungs this one unblocks (foundation-first, from dep rows)
1067 v = v + enab[i]
1068 no = rk_cat(nb, no, " +enables=" as *u8); no = rk_catn(nb, no, enab[i])
1069 // momentum: 1 + deps measured present
1070 var mom: i64 = 1
1071 let ds: *u8 = rdeps[i] as *u8
1072 if ds[0] != (45 as u8) {
1073 // deps are comma-separated rung ids; resolve each to its symbol, then to matrix presence
1074 let dtmp: *u8 = sys_mmap(rk_slen(ds) + 2)
1075 var di: i64 = 0; var dj: i64 = 0
1076 var run: i64 = 1
1077 while run == 1 {
1078 if ds[di] == (44 as u8) { dtmp[dj] = 0 as u8; dj = 0
1079 var r2: i64 = 0; while r2 < nr { if rk_streq(rid[r2] as *u8, dtmp) == 1 { if rdone[r2] == 1 { mom = mom + 1 } r2 = nr } r2 = r2 + 1 }
1080 } else { if ds[di] == (0 as u8) { dtmp[dj] = 0 as u8; run = 0
1081 var r3: i64 = 0; while r3 < nr { if rk_streq(rid[r3] as *u8, dtmp) == 1 { if rdone[r3] == 1 { mom = mom + 1 } r3 = nr } r3 = r3 + 1 }
1082 } else { dtmp[dj] = ds[di]; dj = dj + 1 } }
1083 di = di + 1
1084 }
1085 }
1086 no = rk_cat(nb, no, " momentum=1+deps-present=" as *u8); no = rk_catn(nb, no, mom)
1087 var cst: i64 = rest[i]
1088 if cst <= 0 { cst = RANK_COST_UNKNOWN; no = rk_cat(nb, no, " cost=UNESTIMATED->" as *u8); no = rk_catn(nb, no, RANK_COST_UNKNOWN) } else { no = rk_cat(nb, no, " cost_tenths=" as *u8); no = rk_catn(nb, no, cst) }
1089 // CLUSTER COHERENCE: open rungs whose matrix rows name the SAME organ file share substrate
1090 // (one read of the code, one build lane, one gate to extend). Cost is divided by the cluster
1091 // size for every member -- adjacent scheduling pays the shared setup once. Measured from the
1092 // organ column, never labelled by hand; a singleton cluster divides by 1.
1093 if mi >= 0 {
1094 var clu: i64 = 0
1095 var k7: i64 = 0
1096 while k7 < nr { if rdone[k7] == 0 { if rmi[k7] >= 0 { if rk_streq(morg[rmi[k7]] as *u8, morg[mi] as *u8) == 1 { clu = clu + 1 } } } k7 = k7 + 1 }
1097 if clu > 1 { cst = cst / clu; if cst < 1 { cst = 1 } no = rk_cat(nb, no, " cluster=" as *u8); no = rk_catn(nb, no, clu); no = rk_cat(nb, no, "->cost/cluster=" as *u8); no = rk_catn(nb, no, cst) }
1098 }
1099 if v <= 0 { v = 0 }
1100 // PR6: sponsorship coefficient (x4 fixed-point), applied to VALUE so a standing order moves
1101 // the ordering the way the operator meant, and every row that fired is printed by id
1102 if splen[0] > 0 {
1103 let noo: *i64 = sys_mmap(16) as *i64
1104 // the term NUL-splits its buffer in place: hand it a COPY so the plane stays intact for
1105 // the next rung (one load, N cheap copies -- never N forks, never a corrupted re-read)
1106 let scopy: *u8 = sys_mmap(splen[0] + 16)
1107 var cz: i64 = 0
1108 while cz < splen[0] { scopy[cz] = splane[cz]; cz = cz + 1 }
1109 scopy[splen[0]] = 0 as u8
1110 let sm: i64 = rk_sponsor_term(scopy, splen[0], dom, rid[i] as *u8, rsym[i] as *u8, nb, no, noo)
1111 no = noo[0]
1112 v = v * sm / SPONSOR_BASE
1113 }
1114 // PR11: the self-sufficiency coefficient (x4 fixed-point), applied to VALUE so a rung that
1115 // ships a capability standing on outside dependency is priced for what it actually
1116 // delivers. Floored at SELFSUFF_FLOOR: it DEMOTES, it never hides. A rung whose organ has
1117 // zero measured dependency comes back at SELFSUFF_BASE and its value is untouched.
1118 if mi >= 0 {
1119 let noo2: *i64 = sys_mmap(16) as *i64
1120 let ssm: i64 = rk_selfsuff_term(ssbuf, ssn, dom, morg[mi] as *u8, nb, no, noo2)
1121 no = noo2[0]
1122 v = v * ssm / SELFSUFF_BASE
1123 } else { no = rk_cat(nb, no, " selfsuff=NO-MATRIX-ROW(no organ to look up)" as *u8) }
1124 ov[nopen] = v; om[nopen] = mom; oc[nopen] = cst; oidx[nopen] = i; onote[nopen] = nb as i64
1125 nopen = nopen + 1
1126 }
1127 i = i + 1
1128 }
1129 // ---- CRITICAL PATH: the first version whose milestone rungs are not all measured present is the
1130 // TARGET; its open rungs plus their transitive open dependencies are the path. Everything else is
1131 // real work for a LATER version and ranks after -- the version ladder, not a seat's taste, decides.
1132 let crit: *i64 = sys_mmap(nr * 8) as *i64
1133 var cz: i64 = 0
1134 while cz < nr { crit[cz] = 0; cz = cz + 1 }
1135 var tgt: i64 = 0 - 1
1136 var vv: i64 = 0
1137 while vv < nver {
1138 var mm: i64 = 0 - 1
1139 var s5: i64 = 0
1140 while s5 < nms { if rk_streq(msid[s5] as *u8, vms[vv] as *u8) == 1 { mm = s5; s5 = nms } s5 = s5 + 1 }
1141 if mm >= 0 { if tgt < 0 {
1142 let unmet: i64 = rk_list_scan(msrungs[mm] as *u8, 0, rid, nr, rdone, crit)
1143 if unmet > 0 { tgt = vv; rk_list_scan(msrungs[mm] as *u8, 1, rid, nr, rdone, crit) }
1144 } }
1145 vv = vv + 1
1146 }
1147 // transitive closure over declared deps (only OPEN deps join the path)
1148 var itc: i64 = 0
1149 while itc < nr {
1150 var ch: i64 = 0
1151 var a5: i64 = 0
1152 while a5 < nr {
1153 if crit[a5] == 1 {
1154 let before: i64 = rk_list_scan(rdeps[a5] as *u8, 0, rid, nr, rdone, crit)
1155 if before > 0 {
1156 // count marks added by mode 1: re-scan marking; ch set if any newly marked
1157 var b5: i64 = 0
1158 var pre: i64 = 0
1159 while b5 < nr { pre = pre + crit[b5]; b5 = b5 + 1 }
1160 rk_list_scan(rdeps[a5] as *u8, 1, rid, nr, rdone, crit)
1161 var post: i64 = 0
1162 b5 = 0
1163 while b5 < nr { post = post + crit[b5]; b5 = b5 + 1 }
1164 if post > pre { ch = 1 }
1165 }
1166 }
1167 a5 = a5 + 1
1168 }
1169 if ch == 0 { itc = nr }
1170 itc = itc + 1
1171 }
1172 rk_puts("=== NX-COMPARE-RANK domain=" as *u8); rk_puts(dom); rk_puts(" rungs=" as *u8); rk_pn(nr); rk_puts(" done=" as *u8); rk_pn(ndone); rk_puts(" open=" as *u8); rk_pn(nopen); rk_puts(" finish(done-but-partially-adopted)=" as *u8); rk_pn(nfinish); rk_puts(" (partition sums: done+open=rungs; finish is a subset of done) matrix_rows=" as *u8); rk_pn(mrows); rk_puts(" fields_max=" as *u8); rk_pn(max_fields); rk_puts(" (derived bounds: rows<=matrix lines, rungs<=plan lines -- no cap)\n" as *u8)
1173 if tgt >= 0 { rk_puts("TARGET VERSION " as *u8); rk_puts(vlab[tgt] as *u8); rk_puts(" (milestone " as *u8); rk_puts(vms[tgt] as *u8); rk_puts(") -- critical-path rungs rank FIRST; the rest are staged later\n" as *u8) }
1174 else { if nver > 0 { rk_puts("ALL DECLARED VERSIONS MET -- ranking by value alone\n" as *u8) } else { rk_puts("NO ver| ladder in the plan -- add ver rows to stage the roadmap; ranking by value alone (LABELED)\n" as *u8) } }
1175 if nopen == 0 {
1176 rk_puts("RANK: nothing open -- every rung's symbol is measured present\n" as *u8)
1177 if rk_write_rank(dom, rkbuf, rko, nr, ndone, nopen, nfinish, tgt, vlab)!=0 { return 8 }
1178 return 0
1179 }
1180 // ---- fork nx_dr_ocm with the triples ----
1181 let av: *i64 = sys_mmap(8 * (4 + 3 * nopen + 2)) as *i64 // argv0, budget, 3 per open rung, NULL
1182 av[0] = "./nx_dr_ocm_cli.elf" as *u8 as i64
1183 let bs: *u8 = sys_mmap(RK_NUMBUF); rk_catn(bs, 0, budget)
1184 av[1] = bs as i64
1185 var ai: i64 = 2
1186 var k: i64 = 0
1187 while k < nopen {
1188 let sv: *u8 = sys_mmap(RK_NUMBUF); rk_catn(sv, 0, ov[k]); av[ai] = sv as i64; ai = ai + 1
1189 let sm: *u8 = sys_mmap(RK_NUMBUF); rk_catn(sm, 0, om[k]); av[ai] = sm as i64; ai = ai + 1
1190 let sc: *u8 = sys_mmap(RK_NUMBUF); rk_catn(sc, 0, oc[k]); av[ai] = sc as i64; ai = ai + 1
1191 k = k + 1
1192 }
1193 av[ai] = 0
1194 // capture sized from the population: one JSON object per open rung + header/footer (see the consts)
1195 let out_cap: i64 = RK_OCM_HDR_BYTES + nopen * RK_OCM_OBJ_BYTES
1196 let out: *u8 = sys_mmap(out_cap)
1197 let olen: *i64 = sys_mmap(16) as *i64
1198 let rank_rc: i64=tr_run_capture("./nx_dr_ocm_cli.elf" as *u8, av, out, out_cap - 1, olen)
1199 if rank_rc!=0 { rk_puts("RANK REFUSED: prioritization child failed\n" as *u8);return 4 }
1200 if olen[0] <= 0 { rk_puts("RANK REFUSED: nx_dr_ocm returned nothing\n" as *u8); return 4 }
1201 if olen[0] >= out_cap - 1 { rk_puts("RANK REFUSED: nx_dr_ocm output FILLED its derived capture (RK_OCM_OBJ_BYTES/HDR undersized for this emitter -- the ranking would be a prefix)\n" as *u8); return 4 }
1202 // ---- parse the ranking: sequence of {"rank":R,"id":I,...,"priority":P,...} objects, in rank order ----
1203 // walk "\"id\":" occurrences; the object's rank and priority follow/precede in a fixed field order
1204 let rank_of: *i64 = sys_mmap(nopen * 8) as *i64
1205 let pri_of: *i64 = sys_mmap(nopen * 8) as *i64
1206 var z: i64 = 0
1207 while z < nopen { rank_of[z] = 0; pri_of[z] = 0; z = z + 1 }
1208 var oi: i64 = 0
1209 var currank: i64 = 0
1210 while oi + 8 < olen[0] {
1211 if out[oi] == (34 as u8) { if out[oi+1] == (114 as u8) { if out[oi+2] == (97 as u8) { if out[oi+3] == (110 as u8) { if out[oi+4] == (107 as u8) { if out[oi+5] == (34 as u8) { if out[oi+6] == (58 as u8) {
1212 var jj: i64 = oi + 7; var rv: i64 = 0
1213 var gj: i64 = 1
1214 while gj == 1 { if jj < olen[0] { if out[jj] >= (48 as u8) { if out[jj] <= (57 as u8) { rv = rv * 10 + ((out[jj] as i64) - 48); jj = jj + 1 } else { gj = 0 } } else { gj = 0 } } else { gj = 0 } }
1215 currank = rv
1216 } } } } } } }
1217 if out[oi] == (34 as u8) { if out[oi+1] == (105 as u8) { if out[oi+2] == (100 as u8) { if out[oi+3] == (34 as u8) { if out[oi+4] == (58 as u8) {
1218 var jj2: i64 = oi + 5; var idv: i64 = 0
1219 var gj2: i64 = 1
1220 while gj2 == 1 { if jj2 < olen[0] { if out[jj2] >= (48 as u8) { if out[jj2] <= (57 as u8) { idv = idv * 10 + ((out[jj2] as i64) - 48); jj2 = jj2 + 1 } else { gj2 = 0 } } else { gj2 = 0 } } else { gj2 = 0 } }
1221 if idv < nopen { rank_of[idv] = currank }
1222 } } } } }
1223 if out[oi] == (34 as u8) { if rk_starts((out as i64 + oi) as *u8, "\"priority\":" as *u8) == 1 {
1224 var jj3: i64 = oi + 11; var pv: i64 = 0
1225 var gj3: i64 = 1
1226 while gj3 == 1 { if jj3 < olen[0] { if out[jj3] >= (48 as u8) { if out[jj3] <= (57 as u8) { pv = pv * 10 + ((out[jj3] as i64) - 48); jj3 = jj3 + 1 } else { gj3 = 0 } } else { gj3 = 0 } } else { gj3 = 0 } }
1227 // the id for this object was the last id seen: attribute priority to it
1228 var lastid: i64 = 0 - 1
1229 var back: i64 = oi
1230 while back > 0 { if out[back] == (34 as u8) { if rk_starts((out as i64 + back) as *u8, "\"id\":" as *u8) == 1 { var jb: i64 = back + 5; var iv: i64 = 0; var gb: i64 = 1; while gb == 1 { if jb < olen[0] { if out[jb] >= (48 as u8) { if out[jb] <= (57 as u8) { iv = iv * 10 + ((out[jb] as i64) - 48); jb = jb + 1 } else { gb = 0 } } else { gb = 0 } } else { gb = 0 } } lastid = iv; back = 0 } } back = back - 1 }
1231 if lastid >= 0 { if lastid < nopen { pri_of[lastid] = pv } }
1232 } }
1233 oi = oi + 1
1234 }
1235 // ---- print in rank order + publish the plane ----
1236 // THE PREFIX IS A PATH AND MUST BE SPELLED IN FULL. Measured 2026-08-23: the bare "comparerank-<dom>"
1237 // resolved against the CWD, so every published order landed at the nishihost ROOT (segments beside the
1238 // binaries), knowledge/store/comparerank-* read EMPTY, and a seat concluded the ranker committed nothing.
1239 let pfx: *u8 = sys_mmap(dlen + 48) // "knowledge/store/comparerank-" (28) + dom + NUL
1240 var pfo: i64 = rk_cat(pfx, 0, "knowledge/store/comparerank-" as *u8); pfo = rk_cat(pfx, pfo, dom)
1241 // ---- two-pass order: critical-path rungs first (in ranker order), then the rest ----
1242 let ord: *i64 = sys_mmap(nopen * 8) as *i64
1243 var no2: i64 = 0
1244 var pass2: i64 = 0
1245 while pass2 < 2 {
1246 var rr2: i64 = 1
1247 while rr2 <= nopen {
1248 var f2: i64 = 0
1249 while f2 < nopen {
1250 if rank_of[f2] == rr2 {
1251 var isc: i64 = crit[oidx[f2]]
1252 if pass2 == 0 { if isc == 1 { ord[no2] = f2; no2 = no2 + 1 } }
1253 else { if isc == 0 { ord[no2] = f2; no2 = no2 + 1 } }
1254 f2 = nopen
1255 }
1256 f2 = f2 + 1
1257 }
1258 rr2 = rr2 + 1
1259 }
1260 pass2 = pass2 + 1
1261 }
1262 var r: i64 = 1
1263 var published: i64 = 0
1264 var pmfiled: i64 = 0
1265 // the queue note holds one entry per open rung: "#" r "[" stage "]" id "=" pri " " -- sized from the
1266 // ids and stage labels it will actually hold (RK_DEC_MAX per number), so it cannot fill and the
1267 // former ...TRUNCATED-AT-CAP suffix has no path to fire: the row IS the whole order now
1268 var qcap: i64 = 16
1269 var qk: i64 = 0
1270 while qk < nver { qcap = qcap + rk_slen(vlab[qk] as *u8); qk = qk + 1 } // the longest stage label <= sum of labels
1271 var qk2: i64 = 0
1272 while qk2 < nopen { qcap = qcap + 8 + 2 * RK_DEC_MAX + rk_slen(rid[oidx[qk2]] as *u8) + qcap_stage_max(vlab, nver); qk2 = qk2 + 1 }
1273 var qk3: i64 = 0
1274 while qk3 < nr { if rfin[qk3] == 1 { qcap = qcap + 4 + rk_slen(rid[qk3] as *u8) + rk_slen(rtok[qk3] as *u8) } qk3 = qk3 + 1 }
1275 let qbuf: *u8 = sys_mmap(qcap)
1276 var qlen: i64 = 0
1277 var qf: i64 = 0
1278 while qf < nr { if rfin[qf] == 1 { qlen = rk_cat(qbuf, qlen, "F[" as *u8); qlen = rk_cat(qbuf, qlen, rtok[qf] as *u8); qlen = rk_cat(qbuf, qlen, "]" as *u8); qlen = rk_cat(qbuf, qlen, rid[qf] as *u8); qlen = rk_cat(qbuf, qlen, " " as *u8) } qf = qf + 1 }
1279 var qtop: i64 = "-" as *u8 as i64
1280 var qtoptitle: i64 = "-" as *u8 as i64
1281 var qtoppri: i64 = 0
1282 while r <= no2 {
1283 let found: i64 = ord[r - 1]
1284 if found >= 0 {
1285 let ri: i64 = oidx[found]
1286 var stg: *u8 = "later" as *u8
1287 if crit[ri] == 1 { if tgt >= 0 { stg = vlab[tgt] as *u8 } }
1288 rk_puts(" #" as *u8); rk_pn(r); rk_puts(" [" as *u8); rk_puts(stg); rk_puts("] " as *u8); rk_puts(rid[ri] as *u8); rk_puts(" priority=" as *u8); rk_pn(pri_of[found])
1289 rk_puts(" v=" as *u8); rk_pn(ov[found]); rk_puts(" m=" as *u8); rk_pn(om[found]); rk_puts(" c=" as *u8); rk_pn(oc[found])
1290 rk_puts(" | " as *u8); rk_puts(rtitle[ri] as *u8); rk_puts(" [" as *u8); rk_puts(rsym[ri] as *u8); rk_puts("] " as *u8); rk_puts(onote[found] as *u8); rk_puts("\n" as *u8)
1291 // ES28: the estate's answer to this rung's contract, printed under its line (its own organ excluded)
1292 let incexcl: *u8 = sys_mmap(INC_NAME_CAP) as *u8
1293 incexcl[0] = 0 as u8
1294 if rmi[ri] >= 0 { inc_organ_name(morg[rmi[ri]] as *u8, incexcl) }
1295 rk_incumbents(rid[ri] as *u8, rtitle[ri] as *u8, rsym[ri] as *u8, rnote[ri] as *u8, incexcl)
1296 rko = rk_cat(rkbuf, rko, "rank|" as *u8); rko = rk_catn(rkbuf, rko, r); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, stg); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, rid[ri] as *u8)
1297 rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_catn(rkbuf, rko, pri_of[found]); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_catn(rkbuf, rko, ov[found]); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_catn(rkbuf, rko, om[found]); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_catn(rkbuf, rko, oc[found])
1298 rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, rtitle[ri] as *u8); rko = rk_cat(rkbuf, rko, "|" as *u8); rko = rk_cat(rkbuf, rko, rsym[ri] as *u8); rko = rk_cat(rkbuf, rko, "\n" as *u8)
1299 // ONE PLANE ROW PER DOMAIN, accumulated here and committed ONCE after the loop. The v5 draft
1300 // committed one row PER RUNG -- 19 fsync'd segment commits per domain, x7 domains, x the gate's
1301 // fixture -- and on 2026-08-18 that serialised into D-state store puts (wait_on_page_bit) that
1302 // stalled the fleet, the gate and the ship loop for an hour on a saturated array. Count the
1303 // syscalls per unit of output (§F): the printed table already carries every derivation, pm
1304 // intake carries the top rows; the plane needs the ORDER, and the order is one row.
1305 let qo0: i64 = qlen
1306 qlen = rk_cat(qbuf, qlen, "#" as *u8); qlen = rk_catn(qbuf, qlen, r); qlen = rk_cat(qbuf, qlen, "[" as *u8); qlen = rk_cat(qbuf, qlen, stg); qlen = rk_cat(qbuf, qlen, "]" as *u8); qlen = rk_cat(qbuf, qlen, rid[ri] as *u8); qlen = rk_cat(qbuf, qlen, "=" as *u8); qlen = rk_catn(qbuf, qlen, pri_of[found]); qlen = rk_cat(qbuf, qlen, " " as *u8)
1307 if r == 1 { qtop = rid[ri]; qtoptitle = rtitle[ri]; qtoppri = pri_of[found] }
1308 // NISHI PM DRIVES (operator 2026-08-18): the top RANK_PM_TOP critical-path rungs are FILED
1309 // into the pm intake journal, so the work queue every seat reads starts from the ranking,
1310 // not from a seat's taste. Idempotence is the journal's triage lane's problem by design --
1311 // re-ranking re-asserts the same ask, which is a re-prioritisation signal, not noise.
1312 if artifact_only==0 { if r <= RANK_PM_TOP { if crit[ri] == 1 {
1313 let pav: *i64 = sys_mmap(8 * 8) as *i64
1314 // dom + " rank#" r + " stage=" stg + " " id + " " title + " priority=" pri + " sym=" sym
1315 let pt: *u8 = sys_mmap(rk_slen(dom) + rk_slen(stg) + rk_slen(rid[ri] as *u8) + rk_slen(rtitle[ri] as *u8) + rk_slen(rsym[ri] as *u8) + 2 * RK_DEC_MAX + 48)
1316 var pto: i64 = rk_cat(pt, 0, dom); pto = rk_cat(pt, pto, " rank#" as *u8); pto = rk_catn(pt, pto, r)
1317 pto = rk_cat(pt, pto, " stage=" as *u8); pto = rk_cat(pt, pto, stg)
1318 pto = rk_cat(pt, pto, " " as *u8); pto = rk_cat(pt, pto, rid[ri] as *u8)
1319 pto = rk_cat(pt, pto, " " as *u8); pto = rk_cat(pt, pto, rtitle[ri] as *u8)
1320 pto = rk_cat(pt, pto, " priority=" as *u8); pto = rk_catn(pt, pto, pri_of[found])
1321 pto = rk_cat(pt, pto, " sym=" as *u8); pto = rk_cat(pt, pto, rsym[ri] as *u8)
1322 pav[0] = "./nx_pm_intake.elf" as *u8 as i64
1323 pav[1] = "ask" as *u8 as i64
1324 pav[2] = "knowledge/status/pm_intake.jrnl" as *u8 as i64
1325 pav[3] = "nx_compare_rank" as *u8 as i64
1326 pav[4] = pt as i64
1327 pav[5] = 0
1328 let pout: *u8 = sys_mmap(RANK_FORK_CAP)
1329 let polen: *i64 = sys_mmap(16) as *i64
1330 tr_run_capture("./nx_pm_intake.elf" as *u8, pav, pout, RANK_FORK_CAP - 1, polen)
1331 if polen[0] >= RANK_FORK_CAP - 1 { rk_puts("PM intake receipt CAPTURE-FULL at RANK_FORK_CAP (receipt truncated, filing counted)\n" as *u8) }
1332 if polen[0] > 0 { pmfiled = pmfiled + 1 }
1333 } } }
1334 }
1335 r = r + 1
1336 }
1337 rk_puts("PM filed=" as *u8); rk_pn(pmfiled); rk_puts(" of top " as *u8); rk_pn(RANK_PM_TOP); rk_puts(" critical rungs into knowledge/status/pm_intake.jrnl\n" as *u8)
1338 // the ONE plane commit: id=<domain>, title=the #1 rung, sev=1, status=its priority, note=the ordered
1339 // queue "#r[stage]RUNG=priority ..." -- the whole order in one row, one segment commit
1340 if artifact_only==0 { if no2 > 0 {
1341 let sav: *i64 = sys_mmap(8 * 16) as *i64
1342 let spr: *u8 = sys_mmap(RK_NUMBUF); rk_catn(spr, 0, qtoppri)
1343 var sncap: i64 = 6 + qlen + 16 + 2 // "queue=" + the queue + " target_version=" + NUL
1344 if tgt >= 0 { sncap = sncap + rk_slen(vlab[tgt] as *u8) }
1345 let sn: *u8 = sys_mmap(sncap)
1346 var sno: i64 = rk_cat(sn, 0, "queue=" as *u8); sno = rk_cat(sn, sno, qbuf)
1347 if tgt >= 0 { sno = rk_cat(sn, sno, " target_version=" as *u8); sno = rk_cat(sn, sno, vlab[tgt] as *u8) }
1348 sav[0] = "./nx_store_put.elf" as *u8 as i64
1349 sav[1] = pfx as i64
1350 sav[2] = "put" as *u8 as i64
1351 sav[3] = "nx_compare_rank" as *u8 as i64
1352 sav[4] = dom as i64
1353 sav[5] = qtoptitle
1354 sav[6] = "1" as *u8 as i64
1355 sav[7] = spr as i64
1356 sav[8] = "pm" as *u8 as i64
1357 sav[9] = qtop
1358 sav[10] = sn as i64
1359 sav[11] = 0
1360 let sout: *u8 = sys_mmap(RANK_FORK_CAP)
1361 let solen: *i64 = sys_mmap(16) as *i64
1362 tr_run_capture("./nx_store_put.elf" as *u8, sav, sout, RANK_FORK_CAP - 1, solen)
1363 if solen[0] >= RANK_FORK_CAP - 1 { rk_puts("plane receipt CAPTURE-FULL at RANK_FORK_CAP (receipt truncated, publish counted)\n" as *u8) }
1364 if solen[0] > 0 { published = 1 }
1365 } }
1366 // PERSIST THE UNCARRIED-DIMENSION FINDING (2026-09-01) -- the ranker already KNEW this and threw it away.
1367 // A rung whose symbol no matrix row carries takes the UNMAPPED branch above and is priced at ZERO, but
1368 // it said so only on stdout: the .rank ARTIFACT had no field for it. So the one signal that names the
1369 // "measured, but carried by no column" defect died with whatever terminal ran the ranker -- for all 96
1370 // domains, on every run.
1371 // WHY THIS OUTRANKS THE ROWS IT PRINTS: that defect is exactly how /compare/search carried NO latency
1372 // row at all while its own declared 3000ms consumer bar (knowledge/uat_journeys.conf: search-query)
1373 // FAILED 41 consecutive hourly runs. The published critical path was computed on input that omitted
1374 // the only axis that was failing, and a seat had to NOTICE. Persisting it makes the artifact say so.
1375 // ★AN INSTRUMENT THAT PRINTS A FINDING BUT DOES NOT PERSIST IT HAS NOT PUBLISHED IT.
1376 // THE COUNT IS EMITTED EVEN WHEN ZERO: a declared zero is evidence the check RAN, while silence is
1377 // indistinguishable from the check being absent -- the estate's own abstain-never-acquit law. And the
1378 // count carries a NAMED WORKLIST, one row per offender, because a count without a worklist is not
1379 // actionable.
1380 // STRICTLY ADDITIVE, AND THE STAMP STAYS LAST: these rows are appended BEFORE rk_write_rank writes the
1381 // stamp, so every positional reader that takes the final line is unaffected, and no rank| row changes,
1382 // so a consumer parsing only rank| rows cannot even notice this.
1383 var unm: i64 = 0
1384 var uq: i64 = 0
1385 while uq < nr { if rmi[uq] < 0 { unm = unm + 1 } uq = uq + 1 }
1386 rko = rk_cat(rkbuf, rko, "unmapped-count|" as *u8)
1387 rko = rk_catn(rkbuf, rko, unm)
1388 rko = rk_cat(rkbuf, rko, "|rungs whose symbol NO matrix row carries: priced at zero, invisible to consumers\n" as *u8)
1389 uq = 0
1390 while uq < nr {
1391 if rmi[uq] < 0 {
1392 rko = rk_cat(rkbuf, rko, "unmapped|" as *u8)
1393 rko = rk_cat(rkbuf, rko, rid[uq] as *u8)
1394 rko = rk_cat(rkbuf, rko, "|" as *u8)
1395 rko = rk_cat(rkbuf, rko, rsym[uq] as *u8)
1396 rko = rk_cat(rkbuf, rko, "|no-matrix-row-carries-this-symbol\n" as *u8)
1397 }
1398 uq = uq + 1
1399 }
1400 rk_puts("RANK unmapped=" as *u8); rk_pn(unm); rk_puts(" rung(s) no matrix row carries -- now PERSISTED in the artifact, not merely printed\n" as *u8)
1401 if rk_write_rank(dom, rkbuf, rko, nr, ndone, nopen, nfinish, tgt, vlab)!=0 { return 8 }
1402 rk_puts("RANK published=" as *u8); rk_pn(published); rk_puts(" row(s) (one per domain, the whole order in its note) plane=" as *u8); rk_puts(pfx); rk_puts(" ranker=nx_dr_ocm rule=(deficit+CoD+option+enables)*sponsor*selfsuff*(1+deps-landed)/(est_tenths/cluster) provenance=WSJF+real-options+dep-graph+sovereignty-ledger (header + pmdash.refs)\n" as *u8)
1403 return 0
1404}