nx_swarm_maturity.nx source
↩ module page · 358 lines · 17998 B
1// nx_swarm_maturity.nx -- SWARM FABRIC MATURITY census (SF-MAT): the HONEST measurement the operator
2// demanded -- "maturity is the real feedback", NOT feature-presence (944/1000 was inflatable: 'do we have
3// a form of X'). This grades every capability on a PRODUCTION-MATURITY ladder, EVIDENCE-CAPPED so it cannot
4// overclaim:
5// L0 not-built · L1 GATED (liar-killed synthetic/single-machine) · L2 LIVE (real data/telemetry) ·
6// L3 MCP (operationally callable) · L4 MULTI-NODE (live across >=2 real remote participants) ·
7// L5 MATURE (hardened + externally PERF-benchmarked vs the actual tool, not feature-presence).
8//
9// ★★THE ANTI-OVERCLAIM LIAR-KILLER (mechanical): L1 requires the gate symbol to VERIFY ON DISK (a claimed
10// gate that isn't in the organ file -> L0, never fabricated). L4 requires knowledge/compare/swarm_multinode
11// .proof; L5 requires swarm_hardened.proof + swarm_extbench.proof. Those files do NOT exist -> EVERY
12// capability is mechanically CAPPED at L3. So the maturity score reflects what's PROVEN, not claimed; it
13// RATCHETS up only when a real multi-node/hardened/benchmark proof is produced (create the proof file).
14//
15// Reads knowledge/compare/swarm.maturity (label|organ|gate|mcp|live). Score = sum(level)/(n*5) permille.
16// nx_swarm_maturity [maturity-file] -- grade + honest score + the maturity roadmap + self-liar-kills
17// license_tier: ORIGINAL expect_exit:0
18import "nx_swarm_lib.nx"
19import "nx_matrix_sym_lib.nx"
20import "nx_estate_path.nx"
21const MT_MAGIC_262144: i64 = 262144
22const MT_MAGIC_65536: i64 = 65536
23
24const MT_ROOT: *u8 = "knowledge/compare/"
25
26func mt_puts(s: *u8) -> i64 { sys_write(1, s, fa_len(s)); return 0 }
27func mt_putn(v: i64) -> i64 {
28 let b: *u8 = sys_mmap(28)
29 var m: i64 = v
30 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
31 let t: *u8 = sys_mmap(28)
32 var k: i64 = 0
33 if m == 0 { t[0] = 48 as u8; k = 1 }
34 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
35 var i: i64 = 0
36 while i < k { b[i] = t[k-1-i]; i = i + 1 }
37 sys_write(1, b, k)
38 return 0
39}
40
41// does the organ file at <path> contain <needle>? (L1 evidence — gate must exist on disk)
42// PATH RESOLUTION IS NOT OPTIONAL, AND ITS ABSENCE HERE FABRICATED A ZERO.
43// Maturity rows declare their organ BUILDROOT-relative ("runtime/nx_swarm_beat.nx"), but this read was
44// BARE, so from the serving root EVERY row failed to open and scored L0 -- and the organ published
45// "COMBINED HONEST MATURITY = 0/1000 ... verdict=MEASURED-HONEST". That zero was not a measurement of
46// the fabric, it was "I could not open anything", wearing the costume of a rigorous evidence-capped
47// grade. MEASURED 2026-08-16: SWARMBEATGATE IS present in runtime/nx_swarm_beat.nx --
48// nx_swcompare_evidence grounds that exact symbol in that exact file -- while this organ scored the
49// same row not-built. ★TWO INSTRUMENTS THAT DISAGREE LOCATE A DEFECT NEITHER COULD FIND ALONE.
50// Composes nx_estate_path's ep_open_rd, the estate's ONE resolver (CWD -> ../ -> root -> buildroot),
51// rather than adding a fourth private probe order. Its own header already states the law this broke:
52// A VERDICT THAT CHANGES WITH THE CALLER'S WORKING DIRECTORY IS NOT A MEASUREMENT.
53// RETURNS 1 present · 0 absent-from-a-READABLE-organ · -1 ORGAN UNREADABLE. The third state is the
54// point: "I read the organ and the symbol is not there" and "I could not read the organ" are OPPOSITE
55// facts, and collapsing them into 0 is exactly what let a resolution bug masquerade as a fleet of
56// honestly-not-built capabilities. Unreadable ANNOUNCES, because a silent one is how this survived.
57func mt_file_has(path: *u8, needle: *u8) -> i64 {
58 let fd: i64 = ep_open_rd(path)
59 if fd < 0 {
60 mt_puts(" [WARN] organ UNREADABLE (not scored as absent): " as *u8); mt_puts(path); mt_puts("\n" as *u8)
61 return 0 - 1
62 }
63 let buf: *u8 = sys_mmap(MT_MAGIC_262144)
64 var tot: i64 = 0
65 var go: i64 = 1
66 while go == 1 {
67 let r: i64 = sys_read(fd, ((buf as i64) + tot) as *u8, MT_MAGIC_262144 - tot)
68 if r <= 0 { go = 0 } else { tot = tot + r; if tot >= MT_MAGIC_262144 { go = 0 } }
69 }
70 sys_close(fd)
71 if tot <= 0 {
72 mt_puts(" [WARN] organ EMPTY (not scored as absent): " as *u8); mt_puts(path); mt_puts("\n" as *u8)
73 return 0 - 1
74 }
75 return sb_has(buf, tot, needle)
76}
77func mt_exists(path: *u8) -> i64 {
78 let fd: i64 = sys_openat_rd(path)
79 if fd < 0 { return 0 }
80 sys_close(fd)
81 return 1
82}
83
84// extract field #idx (0-based, '|'-delimited) from line[0..ln) into out (NUL-term). returns length.
85func mt_field(line: *u8, ln: i64, idx: i64, out: *u8) -> i64 {
86 var f: i64 = 0
87 var o: i64 = 0
88 var i: i64 = 0
89 while i < ln {
90 let c: i64 = line[i] as i64
91 if c == 124 { f = f + 1 } else {
92 if f == idx { out[o] = line[i]; o = o + 1 }
93 }
94 i = i + 1
95 }
96 out[o] = 0 as u8
97 return o
98}
99
100func mt_streq(a: *u8, b: *u8) -> i64 {
101 var i: i64 = 0
102 while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 }
103 if b[i] != (0 as u8) { return 0 }
104 return 1
105}
106func mt_starts(s: *u8, pfx: *u8) -> i64 {
107 var i: i64 = 0
108 while pfx[i] != (0 as u8) { if s[i] != pfx[i] { return 0 } i = i + 1 }
109 return 1
110}
111
112// grade the production-dimensions file; returns sum of levels, fills *rowsb + *secminb (weakest-link security).
113func mt_grade_dims(dimp: *u8, rowsb: *i64, secminb: *i64) -> i64 {
114 let dbuf: *u8 = sys_mmap(MT_MAGIC_65536)
115 let dn: i64 = sb_read(dimp, dbuf, MT_MAGIC_65536)
116 if dn <= 0 { rowsb[0] = 0; secminb[0] = 0; return 0 }
117 let dim: *u8 = sys_mmap(512)
118 let lvl: *u8 = sys_mmap(32)
119 let organ: *u8 = sys_mmap(512)
120 let sym: *u8 = sys_mmap(256)
121 let vout: *i64 = sys_mmap(16) as *i64
122 let pend: *i64 = sys_mmap(16) as *i64
123 var sum: i64 = 0
124 var rows: i64 = 0
125 var sec_min: i64 = 5
126 var sec_any: i64 = 0
127 var i: i64 = 0
128 while i < dn {
129 var e: i64 = i
130 var g: i64 = 1
131 while g == 1 { if e >= dn { g = 0 } else { if (dbuf[e] as i64) == 10 { g = 0 } else { e = e + 1 } } }
132 if e > i { if (dbuf[i] as i64) != 35 {
133 let line: *u8 = (dbuf as i64 + i) as *u8
134 let ln: i64 = e - i
135 mt_field(line, ln, 0, dim)
136 mt_field(line, ln, 1, lvl)
137 mt_field(line, ln, 2, organ)
138 mt_field(line, ln, 3, sym)
139 if fa_len(dim) > 0 { if fa_len(lvl) > 0 {
140 sb_pint(lvl, fa_len(lvl), 0, vout, pend); let claimed: i64 = vout[0]
141 var verified: i64 = 0
142 // ONE reader of the symbol format (nx_matrix_sym_lib): a WATCH contract
143 // "_ABSENT_:<future_symbol>" is not equal to the bare form, so the old test handed the
144 // WHOLE literal to mt_file_has -- a string that can never occur inside an organ -- and a
145 // contract that had ALREADY LANDED scored L0, exactly like one never started.
146 // THE LADDER MUST NOT PUNISH SHIPPING: search the REAL symbol, so a landed contract
147 // verifies while an undelivered one still does not.
148 if msym_is_bare_absent_z(sym) == 0 { if mt_file_has(organ, msym_real_z(sym)) == 1 { verified = 1 } }
149 var L: i64 = 0
150 if verified == 1 { L = claimed; if L > 3 { L = 3 } } // evidence-verified, capped at L3
151 if mt_starts(dim, "Security" as *u8) == 1 { sec_any = 1; if L < sec_min { sec_min = L } }
152 sum = sum + L
153 rows = rows + 1
154 mt_puts(" " as *u8); mt_bar(L); mt_puts(" " as *u8); mt_puts(dim); mt_puts("\n" as *u8)
155 } }
156 } }
157 i = e + 1
158 }
159 if sec_any == 0 { sec_min = 0 }
160 rowsb[0] = rows
161 secminb[0] = sec_min
162 return sum
163}
164
165// evidence-capped maturity level.
166func mt_grade(gate_ok: i64, live: i64, mcp: i64, mn_proof: i64, hard_proof: i64, ext_proof: i64) -> i64 {
167 var L: i64 = 0
168 if gate_ok == 1 { L = 1 }
169 if live == 1 { if L >= 1 { L = 2 } }
170 if mcp == 1 { if L >= 2 { L = 3 } }
171 if mn_proof == 1 { if L >= 3 { L = 4 } }
172 if hard_proof == 1 { if ext_proof == 1 { if L >= 4 { L = 5 } } }
173 return L
174}
175
176func mt_bar(L: i64) -> i64 {
177 mt_puts("[" as *u8)
178 var i: i64 = 0
179 while i < 5 { if i < L { mt_puts("#" as *u8) } else { mt_puts("-" as *u8) } i = i + 1 }
180 mt_puts("] L" as *u8); mt_putn(L)
181 return 0
182}
183
184// AUTO-DERIVE maturity from an existing <domain>.matrix (the ecosystem default, zero per-domain authoring):
185// grade L1 iff the row's symbol (field 2) verifies on disk, L0 if _ABSENT_. Capped at L1 -- a domain claims
186// L2+ (live/mcp) ONLY via a hand-authored <domain>.maturity. This is the anti-navel-gazing FLOOR: a feature
187// matrix scoring 950 with all-gate-only symbols honestly grades ~200 maturity. Returns sum; fills rows/l1/l0.
188func mt_auto_matrix(matrixp: *u8, rowsb: *i64, l1b: *i64, l0b: *i64) -> i64 {
189 let buf: *u8 = sys_mmap(MT_MAGIC_262144)
190 let n: i64 = sb_read(matrixp, buf, MT_MAGIC_262144)
191 if n <= 0 { rowsb[0] = 0; l1b[0] = 0; l0b[0] = 0; return 0 }
192 let organ: *u8 = sys_mmap(512)
193 let sym: *u8 = sys_mmap(256)
194 var sum: i64 = 0
195 var rows: i64 = 0
196 var l1: i64 = 0
197 var l0: i64 = 0
198 var i: i64 = 0
199 while i < n {
200 var e: i64 = i
201 var g: i64 = 1
202 while g == 1 { if e >= n { g = 0 } else { if (buf[e] as i64) == 10 { g = 0 } else { e = e + 1 } } }
203 if e > i { if (buf[i] as i64) != 35 { if (buf[i] as i64) != 64 { // skip '#' and '@' header lines
204 let line: *u8 = (buf as i64 + i) as *u8
205 let ln: i64 = e - i
206 mt_field(line, ln, 1, organ)
207 mt_field(line, ln, 2, sym)
208 if fa_len(sym) > 0 {
209 var L: i64 = 0
210 if msym_is_bare_absent_z(sym) == 0 { if mt_file_has(organ, msym_real_z(sym)) == 1 { L = 1 } }
211 sum = sum + L
212 rows = rows + 1
213 if L == 1 { l1 = l1 + 1 } else { l0 = l0 + 1 }
214 }
215 } } }
216 i = e + 1
217 }
218 rowsb[0] = rows; l1b[0] = l1; l0b[0] = l0
219 return sum
220}
221
222func main(argc: i64, argv: *i64) -> i64 {
223 // DOMAIN-PARAMETERIZED (ecosystem-wide ruler). arg = domain (default swarm).
224 var domain: *u8 = "swarm" as *u8
225 if argc >= 2 { domain = argv[1] as *u8 }
226 let matp: *u8 = sys_mmap(512)
227 var mo: i64 = fa_cat(matp, 0, "knowledge/compare/" as *u8); mo = fa_cat(matp, mo, domain); mo = fa_cat(matp, mo, ".maturity" as *u8); matp[mo] = 0 as u8
228
229 // AUTO-DERIVE path: no hand-authored .maturity -> grade the FLOOR from <domain>.matrix symbols on disk.
230 if mt_exists(matp) == 0 {
231 let mxp: *u8 = sys_mmap(512)
232 var xo: i64 = fa_cat(mxp, 0, "knowledge/compare/" as *u8); xo = fa_cat(mxp, xo, domain); xo = fa_cat(mxp, xo, ".matrix" as *u8); mxp[xo] = 0 as u8
233 if mt_exists(mxp) == 0 { mt_puts("SWARMMATURITY no .maturity and no .matrix for domain=" as *u8); mt_puts(domain); mt_puts("\n" as *u8); return 1 }
234 let rb: *i64 = sys_mmap(16) as *i64
235 let l1b: *i64 = sys_mmap(16) as *i64
236 let l0b: *i64 = sys_mmap(16) as *i64
237 let s: i64 = mt_auto_matrix(mxp, rb, l1b, l0b)
238 var dd: i64 = rb[0] * 5
239 if dd < 1 { dd = 1 }
240 let sc: i64 = s * 1000 / dd
241 mt_puts("=== MATURITY (AUTO-FLOOR from " as *u8); mt_puts(domain); mt_puts(".matrix -- no live/mcp evidence declared) ===\n" as *u8)
242 mt_puts(" axes=" as *u8); mt_putn(rb[0]); mt_puts(" gated-L1=" as *u8); mt_putn(l1b[0]); mt_puts(" absent-L0=" as *u8); mt_putn(l0b[0])
243 mt_puts(" -> honest maturity FLOOR = " as *u8); mt_putn(sc)
244 mt_puts("/1000 (gate-only unless a .maturity file declares live/MCP evidence)\n" as *u8)
245 mt_puts("SWARMMATURITY domain=" as *u8); mt_puts(domain); mt_puts(" verdict=MEASURED-HONEST (auto-floor; the gap vs its feature-matrix score = navel-gazing)\n" as *u8)
246 return 0
247 }
248
249 // proof files for L4/L5 (absent -> mechanical cap at L3)
250 let mn_proof: i64 = mt_exists("knowledge/compare/swarm_multinode.proof" as *u8)
251 let hard_proof: i64 = mt_exists("knowledge/compare/swarm_hardened.proof" as *u8)
252 let ext_proof: i64 = mt_exists("knowledge/compare/swarm_extbench.proof" as *u8)
253
254 let buf: *u8 = sys_mmap(MT_MAGIC_65536)
255 let n: i64 = sb_read(matp, buf, MT_MAGIC_65536)
256 if n <= 0 { mt_puts("SWARMMATURITY no-data\n" as *u8); return 1 }
257
258 let label: *u8 = sys_mmap(512)
259 let organ: *u8 = sys_mmap(512)
260 let gate: *u8 = sys_mmap(256)
261 let mcps: *u8 = sys_mmap(32)
262 let lives: *u8 = sys_mmap(32)
263 let vout: *i64 = sys_mmap(16) as *i64
264 let pend: *i64 = sys_mmap(16) as *i64
265
266 mt_puts("=== SWARM FABRIC MATURITY (evidence-capped; L4+ mechanically locked -- no multinode/hardened/bench proof) ===\n" as *u8)
267 var sum: i64 = 0
268 var rows: i64 = 0
269 var at_l3: i64 = 0
270 var at_l1: i64 = 0
271 var at_l0: i64 = 0
272 // liar-kill accumulators
273 var lk_capped: i64 = 1 // no row exceeds L3 (proofs absent)
274 var lk_gate_verified: i64 = 1 // a present gate that ISN'T on disk would be L0 (tested below via _ABSENT_ rows)
275
276 var i: i64 = 0
277 while i < n {
278 var e: i64 = i
279 var g: i64 = 1
280 while g == 1 { if e >= n { g = 0 } else { if (buf[e] as i64) == 10 { g = 0 } else { e = e + 1 } } }
281 if e > i { if (buf[i] as i64) != 35 { // skip '#' comments
282 let line: *u8 = (buf as i64 + i) as *u8
283 let ln: i64 = e - i
284 mt_field(line, ln, 0, label)
285 mt_field(line, ln, 1, organ)
286 mt_field(line, ln, 2, gate)
287 mt_field(line, ln, 3, mcps)
288 mt_field(line, ln, 4, lives)
289 if fa_len(label) > 0 { if fa_len(gate) > 0 {
290 // L1 evidence: gate symbol must be non-_ABSENT_ AND verified on disk
291 var gate_ok: i64 = 0
292 if msym_is_bare_absent_z(gate) == 0 { if mt_file_has(organ, msym_real_z(gate)) == 1 { gate_ok = 1 } }
293 sb_pint(mcps, fa_len(mcps), 0, vout, pend); let mcp: i64 = vout[0]
294 sb_pint(lives, fa_len(lives), 0, vout, pend); let live: i64 = vout[0]
295 let L: i64 = mt_grade(gate_ok, live, mcp, mn_proof, hard_proof, ext_proof)
296 if L > 3 { lk_capped = 0 }
297 sum = sum + L
298 rows = rows + 1
299 if L >= 3 { at_l3 = at_l3 + 1 }
300 if L == 1 { at_l1 = at_l1 + 1 }
301 if L == 0 { at_l0 = at_l0 + 1 }
302 mt_puts(" " as *u8); mt_bar(L); mt_puts(" " as *u8); mt_puts(label); mt_puts("\n" as *u8)
303 } }
304 } }
305 i = e + 1
306 }
307
308 // honest maturity score: sum of levels / (rows * 5) permille
309 var denom: i64 = rows * 5
310 if denom < 1 { denom = 1 }
311 let score: i64 = sum * 1000 / denom
312 mt_puts("--- honest maturity: " as *u8); mt_putn(score)
313 mt_puts("/1000 (sum L=" as *u8); mt_putn(sum); mt_puts(" of max " as *u8); mt_putn(denom)
314 mt_puts(") · at-L3(ceiling)=" as *u8); mt_putn(at_l3); mt_puts(" gate-only-L1=" as *u8); mt_putn(at_l1)
315 mt_puts(" not-built-L0=" as *u8); mt_putn(at_l0); mt_puts("\n" as *u8)
316 mt_puts("--- CEILING: every capability capped at L3 -- to climb: L4 needs swarm_multinode.proof (live >=2 remote nodes), L5 needs swarm_hardened.proof + swarm_extbench.proof (real perf vs K3s/Ray).\n" as *u8)
317
318 // ===== production DIMENSIONS ("the other stuff": security, reliability, observability, ...) =====
319 mt_puts("=== production DIMENSIONS (evidence-verified; Security = WEAKEST-LINK) ===\n" as *u8)
320 let drowsb: *i64 = sys_mmap(16) as *i64
321 let dsecb: *i64 = sys_mmap(16) as *i64
322 // DOMAIN-PARAMETERIZED dimensions (2026-07-16: was hardcoded swarm.dimensions -- supervisor's census
323 // printed SWARM's 309/1000 + its 0.0.0.0 note verbatim; the second domain to author .dimensions
324 // exposed it). Path = knowledge/compare/<domain>.dimensions; the note names the weakest level only.
325 let dimp: *u8 = sys_mmap(512)
326 var dpo: i64 = fa_cat(dimp, 0, "knowledge/compare/" as *u8); dpo = fa_cat(dimp, dpo, domain); dpo = fa_cat(dimp, dpo, ".dimensions" as *u8); dimp[dpo] = 0 as u8
327 let dsum: i64 = mt_grade_dims(dimp, drowsb, dsecb)
328 let drows: i64 = drowsb[0]
329 var ddenom: i64 = drows * 5
330 if ddenom < 1 { ddenom = 1 }
331 let dscore: i64 = dsum * 1000 / ddenom
332 mt_puts("--- dimensions maturity: " as *u8); mt_putn(dscore)
333 mt_puts("/1000 · ★SECURITY (weakest-link)=L" as *u8); mt_putn(dsecb[0])
334 mt_puts(" (security is capped by its weakest row -- see the .dimensions file's noted gap)\n" as *u8)
335
336 // combined honest maturity (capabilities + dimensions)
337 let comb_sum: i64 = sum + dsum
338 var comb_denom: i64 = (rows + drows) * 5
339 if comb_denom < 1 { comb_denom = 1 }
340 let comb: i64 = comb_sum * 1000 / comb_denom
341 mt_puts("=== COMBINED HONEST MATURITY = " as *u8); mt_putn(comb)
342 mt_puts("/1000 (vs this domain's FEATURE-presence score -- the gap IS the navel-gazing) ===\n" as *u8)
343
344 // liar-kills
345 mt_puts("LIAR-KILL: capped-at-L3(no-fabricated-maturity)=" as *u8); mt_putn(lk_capped)
346 // neg-control: a bogus gate on a real file must grade L0 (proves gate-verified-on-disk)
347 var neg: i64 = 0
348 if mt_file_has("runtime/nx_swarm_beat.nx" as *u8, "NOSUCHGATE_XYZ" as *u8) == 0 { neg = 1 }
349 mt_puts(" neg-control-bogus-gate-L0=" as *u8); mt_putn(neg)
350 // proof-ratchet control: a fake proof path must read absent (0) so the cap holds
351 var pr: i64 = 0
352 if mt_exists("knowledge/compare/swarm_multinode.proof" as *u8) == 0 { pr = 1 }
353 mt_puts(" multinode-proof-absent=" as *u8); mt_putn(pr); mt_puts("\n" as *u8)
354
355 if lk_capped == 1 { if neg == 1 { if pr == 1 { mt_puts("SWARMMATURITY verdict=MEASURED-HONEST (evidence-capped, un-gameable)\n" as *u8); return 0 } } }
356 mt_puts("SWARMMATURITY verdict=RED (liar-kill failed)\n" as *u8)
357 return 1
358}