code wiki / (root) / nx_swarm_maturity.nx

nx_swarm_maturity.nx source

↩ module page · 321 lines · 15364 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" 19const MT_MAGIC_262144: i64 = 262144 20const MT_MAGIC_65536: i64 = 65536 21 22const MT_ROOT: *u8 = "knowledge/compare/" 23 24func mt_puts(s: *u8) -> i64 { sys_write(1, s, fa_len(s)); return 0 } 25func mt_putn(v: i64) -> i64 { 26 let b: *u8 = sys_mmap(28) 27 var m: i64 = v 28 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 29 let t: *u8 = sys_mmap(28) 30 var k: i64 = 0 31 if m == 0 { t[0] = 48 as u8; k = 1 } 32 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 33 var i: i64 = 0 34 while i < k { b[i] = t[k-1-i]; i = i + 1 } 35 sys_write(1, b, k) 36 return 0 37} 38 39// does the organ file at <path> contain <needle>? (L1 evidence — gate must exist on disk) 40func mt_file_has(path: *u8, needle: *u8) -> i64 { 41 let buf: *u8 = sys_mmap(MT_MAGIC_262144) 42 let n: i64 = sb_read(path, buf, MT_MAGIC_262144) 43 if n <= 0 { return 0 } 44 return sb_has(buf, n, needle) 45} 46func mt_exists(path: *u8) -> i64 { 47 let fd: i64 = sys_openat_rd(path) 48 if fd < 0 { return 0 } 49 sys_close(fd) 50 return 1 51} 52 53// extract field #idx (0-based, '|'-delimited) from line[0..ln) into out (NUL-term). returns length. 54func mt_field(line: *u8, ln: i64, idx: i64, out: *u8) -> i64 { 55 var f: i64 = 0 56 var o: i64 = 0 57 var i: i64 = 0 58 while i < ln { 59 let c: i64 = line[i] as i64 60 if c == 124 { f = f + 1 } else { 61 if f == idx { out[o] = line[i]; o = o + 1 } 62 } 63 i = i + 1 64 } 65 out[o] = 0 as u8 66 return o 67} 68 69func mt_streq(a: *u8, b: *u8) -> i64 { 70 var i: i64 = 0 71 while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } 72 if b[i] != (0 as u8) { return 0 } 73 return 1 74} 75func mt_starts(s: *u8, pfx: *u8) -> i64 { 76 var i: i64 = 0 77 while pfx[i] != (0 as u8) { if s[i] != pfx[i] { return 0 } i = i + 1 } 78 return 1 79} 80 81// grade the production-dimensions file; returns sum of levels, fills *rowsb + *secminb (weakest-link security). 82func mt_grade_dims(dimp: *u8, rowsb: *i64, secminb: *i64) -> i64 { 83 let dbuf: *u8 = sys_mmap(MT_MAGIC_65536) 84 let dn: i64 = sb_read(dimp, dbuf, MT_MAGIC_65536) 85 if dn <= 0 { rowsb[0] = 0; secminb[0] = 0; return 0 } 86 let dim: *u8 = sys_mmap(512) 87 let lvl: *u8 = sys_mmap(32) 88 let organ: *u8 = sys_mmap(512) 89 let sym: *u8 = sys_mmap(256) 90 let vout: *i64 = sys_mmap(16) as *i64 91 let pend: *i64 = sys_mmap(16) as *i64 92 var sum: i64 = 0 93 var rows: i64 = 0 94 var sec_min: i64 = 5 95 var sec_any: i64 = 0 96 var i: i64 = 0 97 while i < dn { 98 var e: i64 = i 99 var g: i64 = 1 100 while g == 1 { if e >= dn { g = 0 } else { if (dbuf[e] as i64) == 10 { g = 0 } else { e = e + 1 } } } 101 if e > i { if (dbuf[i] as i64) != 35 { 102 let line: *u8 = (dbuf as i64 + i) as *u8 103 let ln: i64 = e - i 104 mt_field(line, ln, 0, dim) 105 mt_field(line, ln, 1, lvl) 106 mt_field(line, ln, 2, organ) 107 mt_field(line, ln, 3, sym) 108 if fa_len(dim) > 0 { if fa_len(lvl) > 0 { 109 sb_pint(lvl, fa_len(lvl), 0, vout, pend); let claimed: i64 = vout[0] 110 var verified: i64 = 0 111 if mt_streq(sym, "_ABSENT_" as *u8) == 0 { if mt_file_has(organ, sym) == 1 { verified = 1 } } 112 var L: i64 = 0 113 if verified == 1 { L = claimed; if L > 3 { L = 3 } } // evidence-verified, capped at L3 114 if mt_starts(dim, "Security" as *u8) == 1 { sec_any = 1; if L < sec_min { sec_min = L } } 115 sum = sum + L 116 rows = rows + 1 117 mt_puts(" " as *u8); mt_bar(L); mt_puts(" " as *u8); mt_puts(dim); mt_puts("\n" as *u8) 118 } } 119 } } 120 i = e + 1 121 } 122 if sec_any == 0 { sec_min = 0 } 123 rowsb[0] = rows 124 secminb[0] = sec_min 125 return sum 126} 127 128// evidence-capped maturity level. 129func mt_grade(gate_ok: i64, live: i64, mcp: i64, mn_proof: i64, hard_proof: i64, ext_proof: i64) -> i64 { 130 var L: i64 = 0 131 if gate_ok == 1 { L = 1 } 132 if live == 1 { if L >= 1 { L = 2 } } 133 if mcp == 1 { if L >= 2 { L = 3 } } 134 if mn_proof == 1 { if L >= 3 { L = 4 } } 135 if hard_proof == 1 { if ext_proof == 1 { if L >= 4 { L = 5 } } } 136 return L 137} 138 139func mt_bar(L: i64) -> i64 { 140 mt_puts("[" as *u8) 141 var i: i64 = 0 142 while i < 5 { if i < L { mt_puts("#" as *u8) } else { mt_puts("-" as *u8) } i = i + 1 } 143 mt_puts("] L" as *u8); mt_putn(L) 144 return 0 145} 146 147// AUTO-DERIVE maturity from an existing <domain>.matrix (the ecosystem default, zero per-domain authoring): 148// grade L1 iff the row's symbol (field 2) verifies on disk, L0 if _ABSENT_. Capped at L1 -- a domain claims 149// L2+ (live/mcp) ONLY via a hand-authored <domain>.maturity. This is the anti-navel-gazing FLOOR: a feature 150// matrix scoring 950 with all-gate-only symbols honestly grades ~200 maturity. Returns sum; fills rows/l1/l0. 151func mt_auto_matrix(matrixp: *u8, rowsb: *i64, l1b: *i64, l0b: *i64) -> i64 { 152 let buf: *u8 = sys_mmap(MT_MAGIC_262144) 153 let n: i64 = sb_read(matrixp, buf, MT_MAGIC_262144) 154 if n <= 0 { rowsb[0] = 0; l1b[0] = 0; l0b[0] = 0; return 0 } 155 let organ: *u8 = sys_mmap(512) 156 let sym: *u8 = sys_mmap(256) 157 var sum: i64 = 0 158 var rows: i64 = 0 159 var l1: i64 = 0 160 var l0: i64 = 0 161 var i: i64 = 0 162 while i < n { 163 var e: i64 = i 164 var g: i64 = 1 165 while g == 1 { if e >= n { g = 0 } else { if (buf[e] as i64) == 10 { g = 0 } else { e = e + 1 } } } 166 if e > i { if (buf[i] as i64) != 35 { if (buf[i] as i64) != 64 { // skip '#' and '@' header lines 167 let line: *u8 = (buf as i64 + i) as *u8 168 let ln: i64 = e - i 169 mt_field(line, ln, 1, organ) 170 mt_field(line, ln, 2, sym) 171 if fa_len(sym) > 0 { 172 var L: i64 = 0 173 if mt_streq(sym, "_ABSENT_" as *u8) == 0 { if mt_file_has(organ, sym) == 1 { L = 1 } } 174 sum = sum + L 175 rows = rows + 1 176 if L == 1 { l1 = l1 + 1 } else { l0 = l0 + 1 } 177 } 178 } } } 179 i = e + 1 180 } 181 rowsb[0] = rows; l1b[0] = l1; l0b[0] = l0 182 return sum 183} 184 185func main(argc: i64, argv: *i64) -> i64 { 186 // DOMAIN-PARAMETERIZED (ecosystem-wide ruler). arg = domain (default swarm). 187 var domain: *u8 = "swarm" as *u8 188 if argc >= 2 { domain = argv[1] as *u8 } 189 let matp: *u8 = sys_mmap(512) 190 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 191 192 // AUTO-DERIVE path: no hand-authored .maturity -> grade the FLOOR from <domain>.matrix symbols on disk. 193 if mt_exists(matp) == 0 { 194 let mxp: *u8 = sys_mmap(512) 195 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 196 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 } 197 let rb: *i64 = sys_mmap(16) as *i64 198 let l1b: *i64 = sys_mmap(16) as *i64 199 let l0b: *i64 = sys_mmap(16) as *i64 200 let s: i64 = mt_auto_matrix(mxp, rb, l1b, l0b) 201 var dd: i64 = rb[0] * 5 202 if dd < 1 { dd = 1 } 203 let sc: i64 = s * 1000 / dd 204 mt_puts("=== MATURITY (AUTO-FLOOR from " as *u8); mt_puts(domain); mt_puts(".matrix -- no live/mcp evidence declared) ===\n" as *u8) 205 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]) 206 mt_puts(" -> honest maturity FLOOR = " as *u8); mt_putn(sc) 207 mt_puts("/1000 (gate-only unless a .maturity file declares live/MCP evidence)\n" as *u8) 208 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) 209 return 0 210 } 211 212 // proof files for L4/L5 (absent -> mechanical cap at L3) 213 let mn_proof: i64 = mt_exists("knowledge/compare/swarm_multinode.proof" as *u8) 214 let hard_proof: i64 = mt_exists("knowledge/compare/swarm_hardened.proof" as *u8) 215 let ext_proof: i64 = mt_exists("knowledge/compare/swarm_extbench.proof" as *u8) 216 217 let buf: *u8 = sys_mmap(MT_MAGIC_65536) 218 let n: i64 = sb_read(matp, buf, MT_MAGIC_65536) 219 if n <= 0 { mt_puts("SWARMMATURITY no-data\n" as *u8); return 1 } 220 221 let label: *u8 = sys_mmap(512) 222 let organ: *u8 = sys_mmap(512) 223 let gate: *u8 = sys_mmap(256) 224 let mcps: *u8 = sys_mmap(32) 225 let lives: *u8 = sys_mmap(32) 226 let vout: *i64 = sys_mmap(16) as *i64 227 let pend: *i64 = sys_mmap(16) as *i64 228 229 mt_puts("=== SWARM FABRIC MATURITY (evidence-capped; L4+ mechanically locked -- no multinode/hardened/bench proof) ===\n" as *u8) 230 var sum: i64 = 0 231 var rows: i64 = 0 232 var at_l3: i64 = 0 233 var at_l1: i64 = 0 234 var at_l0: i64 = 0 235 // liar-kill accumulators 236 var lk_capped: i64 = 1 // no row exceeds L3 (proofs absent) 237 var lk_gate_verified: i64 = 1 // a present gate that ISN'T on disk would be L0 (tested below via _ABSENT_ rows) 238 239 var i: i64 = 0 240 while i < n { 241 var e: i64 = i 242 var g: i64 = 1 243 while g == 1 { if e >= n { g = 0 } else { if (buf[e] as i64) == 10 { g = 0 } else { e = e + 1 } } } 244 if e > i { if (buf[i] as i64) != 35 { // skip '#' comments 245 let line: *u8 = (buf as i64 + i) as *u8 246 let ln: i64 = e - i 247 mt_field(line, ln, 0, label) 248 mt_field(line, ln, 1, organ) 249 mt_field(line, ln, 2, gate) 250 mt_field(line, ln, 3, mcps) 251 mt_field(line, ln, 4, lives) 252 if fa_len(label) > 0 { if fa_len(gate) > 0 { 253 // L1 evidence: gate symbol must be non-_ABSENT_ AND verified on disk 254 var gate_ok: i64 = 0 255 if mt_streq(gate, "_ABSENT_" as *u8) == 0 { if mt_file_has(organ, gate) == 1 { gate_ok = 1 } } 256 sb_pint(mcps, fa_len(mcps), 0, vout, pend); let mcp: i64 = vout[0] 257 sb_pint(lives, fa_len(lives), 0, vout, pend); let live: i64 = vout[0] 258 let L: i64 = mt_grade(gate_ok, live, mcp, mn_proof, hard_proof, ext_proof) 259 if L > 3 { lk_capped = 0 } 260 sum = sum + L 261 rows = rows + 1 262 if L >= 3 { at_l3 = at_l3 + 1 } 263 if L == 1 { at_l1 = at_l1 + 1 } 264 if L == 0 { at_l0 = at_l0 + 1 } 265 mt_puts(" " as *u8); mt_bar(L); mt_puts(" " as *u8); mt_puts(label); mt_puts("\n" as *u8) 266 } } 267 } } 268 i = e + 1 269 } 270 271 // honest maturity score: sum of levels / (rows * 5) permille 272 var denom: i64 = rows * 5 273 if denom < 1 { denom = 1 } 274 let score: i64 = sum * 1000 / denom 275 mt_puts("--- honest maturity: " as *u8); mt_putn(score) 276 mt_puts("/1000 (sum L=" as *u8); mt_putn(sum); mt_puts(" of max " as *u8); mt_putn(denom) 277 mt_puts(") · at-L3(ceiling)=" as *u8); mt_putn(at_l3); mt_puts(" gate-only-L1=" as *u8); mt_putn(at_l1) 278 mt_puts(" not-built-L0=" as *u8); mt_putn(at_l0); mt_puts("\n" as *u8) 279 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) 280 281 // ===== production DIMENSIONS ("the other stuff": security, reliability, observability, ...) ===== 282 mt_puts("=== production DIMENSIONS (evidence-verified; Security = WEAKEST-LINK) ===\n" as *u8) 283 let drowsb: *i64 = sys_mmap(16) as *i64 284 let dsecb: *i64 = sys_mmap(16) as *i64 285 // DOMAIN-PARAMETERIZED dimensions (2026-07-16: was hardcoded swarm.dimensions -- supervisor's census 286 // printed SWARM's 309/1000 + its 0.0.0.0 note verbatim; the second domain to author .dimensions 287 // exposed it). Path = knowledge/compare/<domain>.dimensions; the note names the weakest level only. 288 let dimp: *u8 = sys_mmap(512) 289 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 290 let dsum: i64 = mt_grade_dims(dimp, drowsb, dsecb) 291 let drows: i64 = drowsb[0] 292 var ddenom: i64 = drows * 5 293 if ddenom < 1 { ddenom = 1 } 294 let dscore: i64 = dsum * 1000 / ddenom 295 mt_puts("--- dimensions maturity: " as *u8); mt_putn(dscore) 296 mt_puts("/1000 · ★SECURITY (weakest-link)=L" as *u8); mt_putn(dsecb[0]) 297 mt_puts(" (security is capped by its weakest row -- see the .dimensions file's noted gap)\n" as *u8) 298 299 // combined honest maturity (capabilities + dimensions) 300 let comb_sum: i64 = sum + dsum 301 var comb_denom: i64 = (rows + drows) * 5 302 if comb_denom < 1 { comb_denom = 1 } 303 let comb: i64 = comb_sum * 1000 / comb_denom 304 mt_puts("=== COMBINED HONEST MATURITY = " as *u8); mt_putn(comb) 305 mt_puts("/1000 (vs this domain's FEATURE-presence score -- the gap IS the navel-gazing) ===\n" as *u8) 306 307 // liar-kills 308 mt_puts("LIAR-KILL: capped-at-L3(no-fabricated-maturity)=" as *u8); mt_putn(lk_capped) 309 // neg-control: a bogus gate on a real file must grade L0 (proves gate-verified-on-disk) 310 var neg: i64 = 0 311 if mt_file_has("runtime/nx_swarm_beat.nx" as *u8, "NOSUCHGATE_XYZ" as *u8) == 0 { neg = 1 } 312 mt_puts(" neg-control-bogus-gate-L0=" as *u8); mt_putn(neg) 313 // proof-ratchet control: a fake proof path must read absent (0) so the cap holds 314 var pr: i64 = 0 315 if mt_exists("knowledge/compare/swarm_multinode.proof" as *u8) == 0 { pr = 1 } 316 mt_puts(" multinode-proof-absent=" as *u8); mt_putn(pr); mt_puts("\n" as *u8) 317 318 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 } } } 319 mt_puts("SWARMMATURITY verdict=RED (liar-kill failed)\n" as *u8) 320 return 1 321}