code wiki / _hdl_build / nx_pm_board.nx

nx_pm_board.nx source

↩ module page · 380 lines · 16034 B

1// nx_pm_board.nx -- THE PM DASHBOARD (operator 2026-07-18: "the pm to give us based on my executive, 2// management, and operations layer a dashboard and feedback ... oversight into what work is happening 3// and the return on investment ... with non fake numbers but real estimates"). 4// THREE LAYERS, all DERIVED from the sovereign planes (never asserted): 5// executive : frontier done/total + open-debt posture + sev>=7 incidents + maturity permil 6// (read from the rollup's durable log; unreadable -> -1 flagged, never invented) 7// management: per RACI lane (raci- plane): open debts / open work / ready frontier rows owned by R 8// operations: mutation activity per plane (hist row counts = provenanced writes = the real work log) 9// roi : NON-FAKE BY CONSTRUCTION -- measured counts (debts closed, work closed, frontier done, 10// plane mutations) + assumption rows from the roi- plane {id metric value basis note}; 11// derived figures computed ONLY from rows whose basis != SET-ME; SET-ME rows are emitted 12// under needs_decision (feedback TO the executive) instead of being faked. 13// nx_pm_board [frontierpfx] [debtpfx] [workpfx] [racipfx] [roipfx] -> JSON on stdout 14// Debt rows are schema-aware per row (legacy epoch 5-col sev@1 vs v2 7-col sev@2/status@3/owner@4). 15// Fail-closed: unseeded frontier or debt plane -> error exit (no dashboard over missing data). 16// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 17import "nx_store_seed_lib.nx" 18import "nx_seg_store.nx" 19import "nx_deploy_lib.nx" 20import "nx_syscalls.nx" 21const PB_MAGIC_4096: i64 = 4096 22 23const PB_CAP: i64 = 1048576 24const PB_OUT: i64 = 262144 25const PB_NL: i64 = 10 26const PB_TAB: i64 = 9 27const PB_MAXCOL: i64 = 16 28const PB_PAIR: i64 = 2 29const PB_SPB: i64 = 256 30const PB_STDERR: i64 = 2 31const PB_EXIT_IO: i64 = 1 32const PB_ZERO: i64 = 48 33const PB_NINE: i64 = 57 34const PB_B10: i64 = 10 35const PB_MAXLANE: i64 = 24 36const PB_INCSEV: i64 = 7 37 38func pb_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 39func pb_werr(s: *u8) -> i64 { sys_write(PB_STDERR, s, pb_slen(s)); return 0 } 40func pb_cols(q: *u8, ls: i64, le: i64, sp: *i64) -> i64 { 41 var c: i64 = 0 42 var p: i64 = ls 43 while c < PB_MAXCOL { 44 var e: i64 = p 45 var s: i64 = 1 46 while s == 1 { if e >= le { s = 0 } else { if q[e] == (PB_TAB as u8) { s = 0 } else { e = e + 1 } } } 47 sp[c*PB_PAIR] = p 48 sp[c*PB_PAIR+1] = e 49 c = c + 1 50 if e >= le { return c } 51 p = e + 1 52 } 53 return c 54} 55func pb_int(q: *u8, a: i64, b: i64) -> i64 { 56 var v: i64 = 0 57 var i: i64 = a 58 while i < b { let c: i64 = q[i]; if c >= PB_ZERO { if c <= PB_NINE { v = v * PB_B10 + (c - PB_ZERO) } } i = i + 1 } 59 return v 60} 61func pb_sl_eq(q: *u8, a: i64, b: i64, s: *u8) -> i64 { 62 let sn: i64 = pb_slen(s) 63 if b - a != sn { return 0 } 64 var i: i64 = 0 65 while i < sn { if q[a+i] != s[i] { return 0 } i = i + 1 } 66 return 1 67} 68func pb_sl_eq2(q: *u8, a: i64, b: i64, r: *u8, c: i64, d: i64) -> i64 { 69 if b - a != d - c { return 0 } 70 var i: i64 = 0 71 while a + i < b { if q[a+i] != r[c+i] { return 0 } i = i + 1 } 72 return 1 73} 74func pb_legacy(q: *u8, ls: i64, le: i64, sp: *i64) -> i64 { 75 if pb_cols(q, ls, le, sp) < 1 { return 0 } 76 if sp[1] - sp[0] < 8 { return 0 } 77 var i: i64 = sp[0] 78 while i < sp[1] { let c: i64 = q[i]; if c < PB_ZERO { return 0 } if c > PB_NINE { return 0 } i = i + 1 } 79 return 1 80} 81func pb_lines(q: *u8, n: i64) -> i64 { var k: i64 = 0; var i: i64 = 0; while i < n { if q[i] == (PB_NL as u8) { k = k + 1 } i = i + 1 } return k } 82// raw verbatim copy (for pre-quoted lists built with literal '\x22' -- must NOT be re-escaped) 83func pb_raw(d: *u8, o: i64, q: *u8, a: i64, b: i64) -> i64 { 84 var oo: i64 = o 85 var i: i64 = a 86 while i < b { d[oo] = q[i]; oo = oo + 1; i = i + 1 } 87 return oo 88} 89func pb_esc(d: *u8, o: i64, q: *u8, a: i64, b: i64) -> i64 { 90 var oo: i64 = o 91 var i: i64 = a 92 while i < b { 93 var c: i64 = q[i] 94 if c == 34 { c = 39 } 95 if c == 92 { c = 47 } 96 if c < 32 { c = 32 } 97 d[oo] = c as u8 98 oo = oo + 1 99 i = i + 1 100 } 101 return oo 102} 103// scan the durable maturity log for " = NNN permil" -> NNN; -1 if unreadable/absent (flag, never invent) 104func pb_maturity() -> i64 { 105 let b: *u8 = sys_mmap(PB_CAP) 106 let n: i64 = dp_read("knowledge/status/ecosystem_maturity.log" as *u8, b, PB_CAP - 4) 107 if n <= 0 { return 0 - 1 } 108 let pat: *u8 = " permil" as *u8 109 var found: i64 = 0 - 1 110 var i: i64 = 0 111 while i + 7 <= n { 112 var hit: i64 = 1 113 var j: i64 = 0 114 while j < 7 { if b[i+j] != pat[j] { hit = 0; j = 7 } else { j = j + 1 } } 115 if hit == 1 { found = i } 116 i = i + 1 117 } 118 if found < 0 { return 0 - 1 } 119 var s: i64 = found 120 while s > 0 { let c: i64 = b[s-1]; if c >= PB_ZERO { if c <= PB_NINE { s = s - 1 } else { s = 0 - s } } else { s = 0 - s } } 121 if s < 0 { s = 0 - s } 122 if s == found { return 0 - 1 } 123 return pb_int(b, s, found) 124} 125 126func main(argc: i64, argv: *i64) -> i64 { 127 var fpx: *u8 = "knowledge/store/frontier-" as *u8 128 var dpx: *u8 = "knowledge/store/debt-" as *u8 129 var wpx: *u8 = "knowledge/store/work-" as *u8 130 var rpx: *u8 = "knowledge/store/raci-" as *u8 131 var opx: *u8 = "knowledge/store/roi-" as *u8 132 if argc > 1 { fpx = argv[1] as *u8 } 133 if argc > 2 { dpx = argv[2] as *u8 } 134 if argc > 3 { wpx = argv[3] as *u8 } 135 if argc > 4 { rpx = argv[4] as *u8 } 136 if argc > 5 { opx = argv[5] as *u8 } 137 138 let fb: *u8 = sys_mmap(PB_CAP) 139 let fn: i64 = sts_load(fpx, fb, PB_CAP) 140 if fn <= 0 { pb_werr("frontier plane unseeded (fail-closed)\n" as *u8); sys_exit(PB_EXIT_IO); return PB_EXIT_IO } 141 let db: *u8 = sys_mmap(PB_CAP) 142 let dn: i64 = sts_load(dpx, db, PB_CAP) 143 if dn <= 0 { pb_werr("debt plane unseeded (fail-closed)\n" as *u8); sys_exit(PB_EXIT_IO); return PB_EXIT_IO } 144 let wb: *u8 = sys_mmap(PB_CAP) 145 var wn: i64 = sts_load(wpx, wb, PB_CAP) 146 if wn < 0 { wn = 0 } 147 let rb: *u8 = sys_mmap(PB_CAP) 148 var rn: i64 = sts_load(rpx, rb, PB_CAP) 149 if rn < 0 { rn = 0 } 150 let ob: *u8 = sys_mmap(PB_CAP) 151 var on: i64 = sts_load(opx, ob, PB_CAP) 152 if on < 0 { on = 0 } 153 let sp: *i64 = sys_mmap(PB_SPB) as *i64 154 let out: *u8 = sys_mmap(PB_OUT) 155 156 // ---- frontier tallies (9-col: status col5, owner col4) 157 var ftot: i64 = 0 158 var fdone: i64 = 0 159 var i: i64 = 0 160 while i < fn { 161 var le: i64 = i 162 var s: i64 = 1 163 while s == 1 { if le >= fn { s = 0 } else { if fb[le] == (PB_NL as u8) { s = 0 } else { le = le + 1 } } } 164 if le > i { if pb_cols(fb, i, le, sp) >= 6 { 165 ftot = ftot + 1 166 if pb_sl_eq(fb, sp[10], sp[11], "D" as *u8) == 1 { fdone = fdone + 1 } 167 } } 168 i = le + 1 169 } 170 // ---- debt tallies (schema-aware) + incidents (open sev>=7) collected as id list 171 var dtot: i64 = 0 172 var dopen: i64 = 0 173 var dclosed: i64 = 0 174 var inc_o: i64 = 0 175 let incb: *u8 = sys_mmap(PB_MAGIC_4096) 176 var ninc: i64 = 0 177 i = 0 178 while i < dn { 179 var le2: i64 = i 180 var s2: i64 = 1 181 while s2 == 1 { if le2 >= dn { s2 = 0 } else { if db[le2] == (PB_NL as u8) { s2 = 0 } else { le2 = le2 + 1 } } } 182 if le2 > i { 183 let nc: i64 = pb_cols(db, i, le2, sp) 184 if nc >= 4 { 185 dtot = dtot + 1 186 var sevcol: i64 = 2 187 if pb_legacy(db, i, le2, sp) == 1 { sevcol = 1 } 188 pb_cols(db, i, le2, sp) 189 var isopen: i64 = 0 190 if pb_sl_eq(db, sp[6], sp[7], "open" as *u8) == 1 { isopen = 1 } 191 if isopen == 1 { dopen = dopen + 1 } else { dclosed = dclosed + 1 } 192 if isopen == 1 { 193 let sev: i64 = pb_int(db, sp[sevcol*PB_PAIR], sp[sevcol*PB_PAIR+1]) 194 if sev >= PB_INCSEV { 195 if ninc > 0 { incb[inc_o] = 44 as u8; inc_o = inc_o + 1 } 196 incb[inc_o] = 34 as u8 197 inc_o = inc_o + 1 198 inc_o = pb_esc(incb, inc_o, db, sp[0], sp[1]) 199 incb[inc_o] = 34 as u8 200 inc_o = inc_o + 1 201 ninc = ninc + 1 202 } 203 } 204 } 205 } 206 i = le2 + 1 207 } 208 // ---- work tallies (7-col: status col3) 209 var wtot: i64 = 0 210 var wopen: i64 = 0 211 var wclosed: i64 = 0 212 i = 0 213 while i < wn { 214 var le3: i64 = i 215 var s3: i64 = 1 216 while s3 == 1 { if le3 >= wn { s3 = 0 } else { if wb[le3] == (PB_NL as u8) { s3 = 0 } else { le3 = le3 + 1 } } } 217 if le3 > i { if pb_cols(wb, i, le3, sp) >= 4 { 218 wtot = wtot + 1 219 if pb_sl_eq(wb, sp[6], sp[7], "open" as *u8) == 1 { wopen = wopen + 1 } else { wclosed = wclosed + 1 } 220 } } 221 i = le3 + 1 222 } 223 // ---- hist activity (operations layer): line counts of the mutation ledgers 224 let hb: *u8 = sys_mmap(PB_CAP) 225 let hp: *u8 = sys_mmap(256) 226 var n0: i64 = pb_slen(dpx) 227 if n0 > 0 { if dpx[n0-1] == (45 as u8) { n0 = n0 - 1 } } 228 var hh: i64 = 0 229 var t: i64 = 0 230 while t < n0 { hp[t] = dpx[t]; t = t + 1 } 231 var ho: i64 = ss_cat(hp, n0, "hist-" as *u8) 232 hp[ho] = 0 as u8 233 var dhn: i64 = sts_load(hp, hb, PB_CAP) 234 if dhn < 0 { dhn = 0 } 235 let dmut: i64 = pb_lines(hb, dhn) 236 n0 = pb_slen(wpx) 237 if n0 > 0 { if wpx[n0-1] == (45 as u8) { n0 = n0 - 1 } } 238 t = 0 239 while t < n0 { hp[t] = wpx[t]; t = t + 1 } 240 ho = ss_cat(hp, n0, "hist-" as *u8) 241 hp[ho] = 0 as u8 242 var whn: i64 = sts_load(hp, hb, PB_CAP) 243 if whn < 0 { whn = 0 } 244 let wmut: i64 = pb_lines(hb, whn) 245 if hh == 0 { hh = 0 } 246 // ---- maturity from the durable instrument log (never invented) 247 let mat: i64 = pb_maturity() 248 249 // ---- emit 250 var o: i64 = 0 251 o = ss_cat(out, o, "{\x22pm_board\x22:\x22v1\x22,\x22executive\x22:{\x22frontier_done\x22:" as *u8) 252 o = ss_catn(out, o, fdone) 253 o = ss_cat(out, o, ",\x22frontier_total\x22:" as *u8) 254 o = ss_catn(out, o, ftot) 255 o = ss_cat(out, o, ",\x22debts_open\x22:" as *u8) 256 o = ss_catn(out, o, dopen) 257 o = ss_cat(out, o, ",\x22debts_closed\x22:" as *u8) 258 o = ss_catn(out, o, dclosed) 259 o = ss_cat(out, o, ",\x22maturity_permil\x22:" as *u8) 260 if mat < 0 { o = ss_cat(out, o, "-1,\x22maturity_note\x22:\x22instrument log unreadable here -- run nx_ecosystem_maturity_rollup\x22" as *u8) } else { o = ss_catn(out, o, mat) } 261 o = ss_cat(out, o, ",\x22incidents_sev7plus\x22:[" as *u8) 262 o = pb_raw(out, o, incb, 0, inc_o) 263 o = ss_cat(out, o, "]},\x22management\x22:[" as *u8) 264 // per raci lane: {lane,R,debts_open,work_open} 265 var nlane: i64 = 0 266 i = 0 267 while i < rn { 268 var le4: i64 = i 269 var s4: i64 = 1 270 while s4 == 1 { if le4 >= rn { s4 = 0 } else { if rb[le4] == (PB_NL as u8) { s4 = 0 } else { le4 = le4 + 1 } } } 271 if le4 > i { if nlane < PB_MAXLANE { if pb_cols(rb, i, le4, sp) >= 2 { 272 let la: i64 = sp[0] 273 let lb2: i64 = sp[1] 274 let ra: i64 = sp[2] 275 let rb2: i64 = sp[3] 276 // count open debts + open work owned by R (owner col4 both planes) 277 var cd: i64 = 0 278 var cw: i64 = 0 279 var j2: i64 = 0 280 let spd: *i64 = sys_mmap(PB_SPB) as *i64 281 while j2 < dn { 282 var led: i64 = j2 283 var sd: i64 = 1 284 while sd == 1 { if led >= dn { sd = 0 } else { if db[led] == (PB_NL as u8) { sd = 0 } else { led = led + 1 } } } 285 if led > j2 { if pb_cols(db, j2, led, spd) >= 5 { 286 if pb_sl_eq(db, spd[6], spd[7], "open" as *u8) == 1 { if pb_sl_eq2(db, spd[8], spd[9], rb, ra, rb2) == 1 { cd = cd + 1 } } 287 } } 288 j2 = led + 1 289 } 290 j2 = 0 291 while j2 < wn { 292 var lew: i64 = j2 293 var sw: i64 = 1 294 while sw == 1 { if lew >= wn { sw = 0 } else { if wb[lew] == (PB_NL as u8) { sw = 0 } else { lew = lew + 1 } } } 295 if lew > j2 { if pb_cols(wb, j2, lew, spd) >= 5 { 296 if pb_sl_eq(wb, spd[6], spd[7], "open" as *u8) == 1 { if pb_sl_eq2(wb, spd[8], spd[9], rb, ra, rb2) == 1 { cw = cw + 1 } } 297 } } 298 j2 = lew + 1 299 } 300 if nlane > 0 { out[o] = 44 as u8; o = o + 1 } 301 o = ss_cat(out, o, "{\x22lane\x22:\x22" as *u8) 302 o = pb_esc(out, o, rb, la, lb2) 303 o = ss_cat(out, o, "\x22,\x22r\x22:\x22" as *u8) 304 o = pb_esc(out, o, rb, ra, rb2) 305 o = ss_cat(out, o, "\x22,\x22debts_open\x22:" as *u8) 306 o = ss_catn(out, o, cd) 307 o = ss_cat(out, o, ",\x22work_open\x22:" as *u8) 308 o = ss_catn(out, o, cw) 309 o = ss_cat(out, o, "}" as *u8) 310 nlane = nlane + 1 311 } } } 312 i = le4 + 1 313 } 314 o = ss_cat(out, o, "],\x22operations\x22:{\x22debt_mutations\x22:" as *u8) 315 o = ss_catn(out, o, dmut) 316 o = ss_cat(out, o, ",\x22work_mutations\x22:" as *u8) 317 o = ss_catn(out, o, wmut) 318 o = ss_cat(out, o, ",\x22work_open\x22:" as *u8) 319 o = ss_catn(out, o, wopen) 320 o = ss_cat(out, o, ",\x22work_closed\x22:" as *u8) 321 o = ss_catn(out, o, wclosed) 322 o = ss_cat(out, o, "},\x22roi\x22:{\x22measured\x22:{\x22debts_closed\x22:" as *u8) 323 o = ss_catn(out, o, dclosed) 324 o = ss_cat(out, o, ",\x22work_closed\x22:" as *u8) 325 o = ss_catn(out, o, wclosed) 326 o = ss_cat(out, o, ",\x22frontier_done\x22:" as *u8) 327 o = ss_catn(out, o, fdone) 328 o = ss_cat(out, o, ",\x22plane_mutations\x22:" as *u8) 329 o = ss_catn(out, o, dmut + wmut) 330 o = ss_cat(out, o, "},\x22assumptions\x22:[" as *u8) 331 // roi- rows: id metric value basis note; derived only from basis != SET-ME 332 var na: i64 = 0 333 var derived_min: i64 = 0 - 1 334 var need_o: i64 = 0 335 let needb: *u8 = sys_mmap(PB_MAGIC_4096) 336 var nneed: i64 = 0 337 i = 0 338 while i < on { 339 var le5: i64 = i 340 var s5: i64 = 1 341 while s5 == 1 { if le5 >= on { s5 = 0 } else { if ob[le5] == (PB_NL as u8) { s5 = 0 } else { le5 = le5 + 1 } } } 342 if le5 > i { if pb_cols(ob, i, le5, sp) >= 4 { 343 if na > 0 { out[o] = 44 as u8; o = o + 1 } 344 o = ss_cat(out, o, "{\x22id\x22:\x22" as *u8) 345 o = pb_esc(out, o, ob, sp[0], sp[1]) 346 o = ss_cat(out, o, "\x22,\x22metric\x22:\x22" as *u8) 347 o = pb_esc(out, o, ob, sp[2], sp[3]) 348 o = ss_cat(out, o, "\x22,\x22value\x22:" as *u8) 349 o = ss_catn(out, o, pb_int(ob, sp[4], sp[5])) 350 o = ss_cat(out, o, ",\x22basis\x22:\x22" as *u8) 351 o = pb_esc(out, o, ob, sp[6], sp[7]) 352 o = ss_cat(out, o, "\x22}" as *u8) 353 na = na + 1 354 if pb_sl_eq(ob, sp[6], sp[7], "SET-ME" as *u8) == 1 { 355 if nneed > 0 { needb[need_o] = 44 as u8; need_o = need_o + 1 } 356 needb[need_o] = 34 as u8 357 need_o = need_o + 1 358 need_o = pb_esc(needb, need_o, ob, sp[0], sp[1]) 359 needb[need_o] = 34 as u8 360 need_o = need_o + 1 361 nneed = nneed + 1 362 } else { 363 if pb_sl_eq(ob, sp[2], sp[3], "manual_minutes_per_debt" as *u8) == 1 { 364 derived_min = dclosed * pb_int(ob, sp[4], sp[5]) 365 } 366 } 367 } } 368 i = le5 + 1 369 } 370 o = ss_cat(out, o, "],\x22derived\x22:{\x22est_minutes_saved_debt_eating\x22:" as *u8) 371 if derived_min < 0 { o = ss_cat(out, o, "\x22AWAITING-ASSUMPTION\x22" as *u8) } else { o = ss_catn(out, o, derived_min) } 372 o = ss_cat(out, o, "},\x22needs_decision\x22:[" as *u8) 373 o = pb_raw(out, o, needb, 0, need_o) 374 o = ss_cat(out, o, "]}}" as *u8) 375 out[o] = PB_NL as u8 376 o = o + 1 377 sys_write(1, out, o) 378 sys_exit(0) 379 return 0 380}