code wiki / _hdl_build / nx_pm_roi_lib.nx
nx_pm_roi_lib.nx source
↩ module page · 819 lines · 46754 B
1// nx_pm_roi_lib.nx -- shared core for the PM COCKPIT (operator 2026-07-18: "the pm gives us, based on my
2// executive, management, and operations layer, a dashboard and feedback ... and the return on investment
3// that's being driven with non-fake numbers but real estimates").
4// DESIGN LAWS honored here:
5// - READER, never a second truth: every tier is measured from the SAME live artifact its owning organ
6// writes (ecomat seg-store via em_rollup_store, frontier- plane via sts_load, debt- plane via sts_load,
7// tool_allowlist.conf / cron.reg / daemons.reg registries). No forks (NAS OOM hygiene), no duplicated
8// rollup logic -> the cockpit can never disagree with /compare/maturity or /frontier.
9// - ROI IS AN ESTIMATE BY CONSTRUCTION: monthly value = COUNT (measured live from a named artifact)
10// x RATE (a data row in the knowledge/store/roi- plane, operator-editable, each row carrying its own
11// basis note). Missing roi- plane -> status UNSEEDED and ZERO dollar output -- fabrication is
12// structurally impossible. (rule 11: rates are data, never code.)
13// - SCALE LAW: every read is bounded by a NAMED cap and the envelope is DECLARED in the output;
14// truncation is marked, never silent.
15// license_tier: ORIGINAL No hw writes (Rule 26).
16import "nx_ecomat_lib.nx"
17import "nx_store_seed_lib.nx"
18
19// ---- envelope (declared in output; every read bounded) ----
20const PM_PLANE_CAP: i64 = 524288 // frontier-/debt-/roi- plane text cap (real planes ~15-60KB)
21const PM_CONF_CAP: i64 = 262144 // registry conf cap (tool_allowlist/cron.reg/daemons.reg)
22const PM_OUT_CAP: i64 = 262144 // emitted JSON/HTML cap
23const PM_MAXCOLS: i64 = 16 // per-row column pairs parsed
24const PM_TOP_ROCKS: i64 = 8 // top open frontier rocks listed
25const PM_TOP_DEBTS: i64 = 6 // top gating debts listed
26const PM_TOP_NEXT: i64 = 3 // maturity next-rung feedback lines
27const PM_NOTE_CAP: i64 = 140 // per-listed-row text slice cap (truncation visible by design)
28const PM_ROCK_W_MIN: i64 = 8 // "big rock" weight floor
29const PM_DEBT_GATE_SEV: i64 = 6 // gating severity floor (mirrors cycle store CONFIG global-sev-min)
30const PM_DEBT_HI_SEV: i64 = 7 // "top debt" listing floor
31const PM_TAB: i64 = 9
32const PM_NL: i64 = 10
33const PM_HASH: i64 = 35
34const PM_ZERO: i64 = 48
35const PM_NINE: i64 = 57
36const PM_B10: i64 = 10
37const PM_LEGACY_IDLEN: i64 = 8 // col0 all-digits len>=8 => legacy 5-col debt row (epoch id)
38// slot indices in the shared measurement array m[64]:
39const S_MAT: i64 = 0
40const S_DOM: i64 = 1
41const S_TRI: i64 = 2
42const S_CON: i64 = 3
43const S_SNG: i64 = 4
44const S_DNG: i64 = 5
45const S_AUT: i64 = 6
46const S_LIAR: i64 = 7
47const S_SCLASS: i64 = 8
48const S_FTOT: i64 = 10
49const S_FDONE: i64 = 11
50const S_FEXT: i64 = 12
51const S_FOPEN: i64 = 13
52const S_DTOT: i64 = 20
53const S_DOPEN: i64 = 21
54const S_DSEV: i64 = 22
55const S_D3P: i64 = 23
56const S_ROIAV: i64 = 30
57const S_ROICENTS: i64 = 31
58const S_ROILINES: i64 = 32
59const S_ROISUPER: i64 = 34
60const S_ROICFG: i64 = 35
61const S_ROIRES: i64 = 36
62const S_TOOLS: i64 = 40
63const S_CRONS: i64 = 41
64const S_FLEET: i64 = 42
65const S_JRNLB: i64 = 43
66const S_RACILANES: i64 = 44
67const PM_TOP_RACI: i64 = 40
68const RC_STRIDE: i64 = 12
69
70func pm_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
71
72// bounded whole-file read (fb_read idiom: no 4GB sys_read_file reservation; rule-21 fork hygiene)
73func pm_read(path: *u8, buf: *u8, cap: i64) -> i64 {
74 let fd: i64 = sys_openat_rd(path)
75 if fd < 0 { return 0 - 1 }
76 var n: i64 = 0
77 var go: i64 = 1
78 while go == 1 {
79 let base: i64 = buf as i64
80 let r: i64 = sys_read(fd, (base + n) as *u8, cap - n)
81 if r <= 0 { go = 0 } else { n = n + r }
82 if n >= cap { go = 0 }
83 }
84 sys_close(fd)
85 return n
86}
87
88// count non-comment non-blank lines (registry row count)
89func pm_count_rows(buf: *u8, n: i64) -> i64 {
90 var cnt: i64 = 0
91 var i: i64 = 0
92 while i < n {
93 var le: i64 = i
94 var s: i64 = 1
95 while s == 1 { if le >= n { s = 0 } else { if buf[le] == (PM_NL as u8) { s = 0 } else { le = le + 1 } } }
96 if le > i { if buf[i] != (PM_HASH as u8) { cnt = cnt + 1 } }
97 i = le + 1
98 }
99 return cnt
100}
101
102// split one line [ls,le) into up to PM_MAXCOLS tab columns; sp = (start,end) pairs; returns count
103func pm_cols(buf: *u8, ls: i64, le: i64, sp: *i64) -> i64 {
104 var c: i64 = 0
105 var p: i64 = ls
106 while c < PM_MAXCOLS {
107 var e: i64 = p
108 var s: i64 = 1
109 while s == 1 { if e >= le { s = 0 } else { if buf[e] == (PM_TAB as u8) { s = 0 } else { e = e + 1 } } }
110 sp[c*2] = p
111 sp[c*2+1] = e
112 c = c + 1
113 if e >= le { return c }
114 p = e + 1
115 }
116 return c
117}
118func pm_slice_int(buf: *u8, a: i64, b: i64) -> i64 {
119 var v: i64 = 0
120 var i: i64 = a
121 while i < b {
122 let c: i64 = buf[i]
123 if c >= PM_ZERO { if c <= PM_NINE { v = v * PM_B10 + (c - PM_ZERO) } }
124 i = i + 1
125 }
126 return v
127}
128func pm_slice_eq(buf: *u8, a: i64, b: i64, lit: *u8) -> i64 {
129 let l: i64 = pm_len(lit)
130 if b - a != l { return 0 }
131 var i: i64 = 0
132 while i < l { if buf[a+i] != lit[i] { return 0 } i = i + 1 }
133 return 1
134}
135// is col0 [a,b) an all-digit id of len>=PM_LEGACY_IDLEN (legacy epoch-keyed debt row)?
136func pm_is_legacy(buf: *u8, a: i64, b: i64) -> i64 {
137 if b - a < PM_LEGACY_IDLEN { return 0 }
138 var i: i64 = a
139 while i < b {
140 let c: i64 = buf[i]
141 if c < PM_ZERO { return 0 }
142 if c > PM_NINE { return 0 }
143 i = i + 1
144 }
145 return 1
146}
147// lowercase substring check of pat inside [a,b)
148func pm_has_lc(buf: *u8, a: i64, b: i64, pat: *u8) -> i64 {
149 let pl: i64 = pm_len(pat)
150 if pl == 0 { return 0 }
151 var i: i64 = a
152 while i + pl <= b {
153 var k: i64 = 0
154 var ok: i64 = 1
155 while k < pl {
156 var c: i64 = buf[i+k]
157 if c >= 65 { if c <= 90 { c = c + 32 } }
158 if c != (pat[k] as i64) { ok = 0; k = pl } else { k = k + 1 }
159 }
160 if ok == 1 { return 1 }
161 i = i + 1
162 }
163 return 0
164}
165// third-party debt classifier (declared heuristic; basis visible on the page). Patterns lowercase.
166func pm_is_3p(buf: *u8, a: i64, b: i64) -> i64 {
167 if pm_has_lc(buf, a, b, "/usr/bin/git" as *u8) == 1 { return 1 }
168 if pm_has_lc(buf, a, b, "stock git" as *u8) == 1 { return 1 }
169 if pm_has_lc(buf, a, b, "git origin" as *u8) == 1 { return 1 }
170 if pm_has_lc(buf, a, b, "gitea" as *u8) == 1 { return 1 }
171 if pm_has_lc(buf, a, b, "nginx" as *u8) == 1 { return 1 }
172 if pm_has_lc(buf, a, b, "dsm" as *u8) == 1 { return 1 }
173 if pm_has_lc(buf, a, b, "synology" as *u8) == 1 { return 1 }
174 if pm_has_lc(buf, a, b, "vendor" as *u8) == 1 { return 1 }
175 if pm_has_lc(buf, a, b, "third-party" as *u8) == 1 { return 1 }
176 if pm_has_lc(buf, a, b, "3rd party" as *u8) == 1 { return 1 }
177 return 0
178}
179
180// ---- DEBT tier: scan the merged debt plane (BOTH schemas: legacy 5-col ts/sev/scope/status/note,
181// v2 7-col id/title/sev/status/owner/scope/note -- status@col3 both by the convergence design;
182// sev@col1 legacy / col2 v2 per the schema-detect heuristic proven in the conductor W002 fix).
183// out: m[S_DTOT/S_DOPEN/S_DSEV/S_D3P]. topv: up to PM_TOP_DEBTS (sev, note_a, note_b) triples.
184func pm_debt_scan(buf: *u8, n: i64, m: *i64, topv: *i64) -> i64 {
185 let sp: *i64 = sys_mmap(PM_MAXCOLS*2*8) as *i64
186 var total: i64 = 0
187 var open: i64 = 0
188 var sev6: i64 = 0
189 var p3: i64 = 0
190 var ntop: i64 = 0
191 var i: i64 = 0
192 while i < n {
193 var le: i64 = i
194 var s: i64 = 1
195 while s == 1 { if le >= n { s = 0 } else { if buf[le] == (PM_NL as u8) { s = 0 } else { le = le + 1 } } }
196 if le > i { if buf[i] != (PM_HASH as u8) {
197 let nc: i64 = pm_cols(buf, i, le, sp)
198 if nc >= 5 {
199 total = total + 1
200 var sevcol: i64 = 2
201 if pm_is_legacy(buf, sp[0], sp[1]) == 1 { sevcol = 1 }
202 let sev: i64 = pm_slice_int(buf, sp[sevcol*2], sp[sevcol*2+1])
203 let is_open: i64 = pm_slice_eq(buf, sp[6], sp[7], "open" as *u8)
204 if is_open == 1 {
205 open = open + 1
206 if sev >= PM_DEBT_GATE_SEV { sev6 = sev6 + 1 }
207 if pm_is_3p(buf, i, le) == 1 { p3 = p3 + 1 }
208 if sev >= PM_DEBT_HI_SEV {
209 if ntop < PM_TOP_DEBTS {
210 // note = last parsed col
211 topv[ntop*3] = sev
212 topv[ntop*3+1] = sp[(nc-1)*2]
213 topv[ntop*3+2] = sp[(nc-1)*2+1]
214 ntop = ntop + 1
215 }
216 }
217 }
218 }
219 } }
220 i = le + 1
221 }
222 m[S_DTOT] = total
223 m[S_DOPEN] = open
224 m[S_DSEV] = sev6
225 m[S_D3P] = p3
226 return ntop
227}
228
229// ---- MGMT tier: frontier plane scan (9-col id title w dur owner status deps milestone lane;
230// status D=done X=external else open). topv: up to PM_TOP_ROCKS (w, id_a, id_b, ti_a, ti_b).
231func pm_frontier_scan(buf: *u8, n: i64, m: *i64, topv: *i64) -> i64 {
232 let sp: *i64 = sys_mmap(PM_MAXCOLS*2*8) as *i64
233 var total: i64 = 0
234 var done: i64 = 0
235 var ext: i64 = 0
236 var ntop: i64 = 0
237 var i: i64 = 0
238 while i < n {
239 var le: i64 = i
240 var s: i64 = 1
241 while s == 1 { if le >= n { s = 0 } else { if buf[le] == (PM_NL as u8) { s = 0 } else { le = le + 1 } } }
242 if le > i { if buf[i] != (PM_HASH as u8) {
243 let nc: i64 = pm_cols(buf, i, le, sp)
244 if nc >= 9 {
245 total = total + 1
246 let st: i64 = buf[sp[10]]
247 if st == 68 { done = done + 1 }
248 else { if st == 88 { ext = ext + 1 }
249 else {
250 let w: i64 = pm_slice_int(buf, sp[4], sp[5])
251 if w >= PM_ROCK_W_MIN {
252 if ntop < PM_TOP_ROCKS {
253 topv[ntop*5] = w
254 topv[ntop*5+1] = sp[0]
255 topv[ntop*5+2] = sp[1]
256 topv[ntop*5+3] = sp[2]
257 topv[ntop*5+4] = sp[3]
258 ntop = ntop + 1
259 }
260 }
261 } }
262 }
263 } }
264 i = le + 1
265 }
266 m[S_FTOT] = total
267 m[S_FDONE] = done
268 m[S_FEXT] = ext
269 m[S_FOPEN] = total - done - ext
270 return ntop
271}
272
273// ---- ROI tier: the sibling-owned knowledge/store/roi- plane is a qty*cents ledger (converged schema:
274// id label src qty cents basis). We COMPOSE it -- convergence, not a fork -- and honor the plane's own
275// ROI-CONVERGE discipline row: the CONSERVATIVE FLOOR ships (sum of VALUE rows), aspirational ceilings and
276// COORD flags are NEVER summed, and any SUPERSEDED/neutralized row is EXCLUDED BY CONSTRUCTION so a stale
277// value can never surface as a live number (the honesty core -- what would otherwise re-admit a false $).
278// bucket codes: 0 summable-VALUE (clean integer qty+cents) | 1 rate-config | 2 research | 3 skip (COORD/SUPERSEDED/narrative)
279// rrow[i*RR_STRIDE]: bucket qty cents subtotal id(a,b) label(a,b) src(a,b) basis(a,b)
280const RR_STRIDE: i64 = 12
281
282func pm_col_starts(buf: *u8, a: i64, b: i64, lit: *u8) -> i64 {
283 let l: i64 = pm_len(lit)
284 if b - a < l { return 0 }
285 var i: i64 = 0
286 while i < l { if buf[a+i] != lit[i] { return 0 } i = i + 1 }
287 return 1
288}
289func pm_all_digits(buf: *u8, a: i64, b: i64) -> i64 {
290 if b <= a { return 0 }
291 var i: i64 = a
292 while i < b { let c: i64 = buf[i]; if c < PM_ZERO { return 0 } if c > PM_NINE { return 0 } i = i + 1 }
293 return 1
294}
295func pm_row_superseded(buf: *u8, sp: *i64, nc: i64) -> i64 {
296 var c: i64 = 1
297 while c < nc { if pm_col_starts(buf, sp[c*2], sp[c*2+1], "SUPERSEDED" as *u8) == 1 { return 1 } c = c + 1 }
298 return 0
299}
300func pm_roi_bucket(buf: *u8, sp: *i64, nc: i64) -> i64 {
301 if pm_col_starts(buf, sp[2], sp[3], "CONFIG" as *u8) == 1 { return 1 }
302 if pm_col_starts(buf, sp[2], sp[3], "RESEARCH" as *u8) == 1 { return 2 }
303 if pm_col_starts(buf, sp[2], sp[3], "COORD" as *u8) == 1 { return 3 }
304 if pm_row_superseded(buf, sp, nc) == 1 { return 3 }
305 if nc >= 6 { if pm_all_digits(buf, sp[6], sp[7]) == 1 { if pm_all_digits(buf, sp[8], sp[9]) == 1 { return 0 } } }
306 return 3
307}
308func pm_roi_scan(buf: *u8, n: i64, m: *i64, rrow: *i64, maxrows: i64) -> i64 {
309 if n <= 0 { m[S_ROIAV] = 0; m[S_ROICENTS] = 0; m[S_ROILINES] = 0; return 0 }
310 m[S_ROIAV] = 1
311 let sp: *i64 = sys_mmap(PM_MAXCOLS*2*8) as *i64
312 var nr: i64 = 0
313 var totc: i64 = 0
314 var lines: i64 = 0
315 var sup: i64 = 0
316 var cfg: i64 = 0
317 var res: i64 = 0
318 var i: i64 = 0
319 while i < n {
320 var le: i64 = i
321 var s: i64 = 1
322 while s == 1 { if le >= n { s = 0 } else { if buf[le] == (PM_NL as u8) { s = 0 } else { le = le + 1 } } }
323 if le > i { if buf[i] != (PM_HASH as u8) {
324 let nc: i64 = pm_cols(buf, i, le, sp)
325 if nc >= 4 {
326 if pm_row_superseded(buf, sp, nc) == 1 { sup = sup + 1 }
327 let bkt: i64 = pm_roi_bucket(buf, sp, nc)
328 if bkt == 1 { cfg = cfg + 1 }
329 if bkt == 2 { res = res + 1 }
330 if bkt != 3 {
331 var qty: i64 = 0
332 var cents: i64 = 0
333 var sub: i64 = 0
334 var la: i64 = sp[4]
335 var lb: i64 = sp[5]
336 var sa: i64 = sp[6]
337 var sb: i64 = sp[7]
338 if bkt == 0 {
339 la = sp[2]; lb = sp[3]; sa = sp[4]; sb = sp[5]
340 qty = pm_slice_int(buf, sp[6], sp[7])
341 cents = pm_slice_int(buf, sp[8], sp[9])
342 sub = qty * cents
343 totc = totc + sub
344 lines = lines + 1
345 }
346 if nr < maxrows {
347 rrow[nr*RR_STRIDE] = bkt
348 rrow[nr*RR_STRIDE+1] = qty
349 rrow[nr*RR_STRIDE+2] = cents
350 rrow[nr*RR_STRIDE+3] = sub
351 rrow[nr*RR_STRIDE+4] = sp[0]
352 rrow[nr*RR_STRIDE+5] = sp[1]
353 rrow[nr*RR_STRIDE+6] = la
354 rrow[nr*RR_STRIDE+7] = lb
355 rrow[nr*RR_STRIDE+8] = sa
356 rrow[nr*RR_STRIDE+9] = sb
357 rrow[nr*RR_STRIDE+10] = sp[(nc-1)*2]
358 rrow[nr*RR_STRIDE+11] = sp[(nc-1)*2+1]
359 nr = nr + 1
360 }
361 }
362 }
363 } }
364 i = le + 1
365 }
366 m[S_ROICENTS] = totc
367 m[S_ROILINES] = lines
368 m[S_ROISUPER] = sup
369 m[S_ROICFG] = cfg
370 m[S_ROIRES] = res
371 return nr
372}
373
374// ---- maturity feedback: top-N below-bar domains by weight -> "domain -- next_rung" pairs.
375// nextv per entry: (weight, keyidx). Caller re-reads strings via ec_str on demand.
376func pm_maturity_next(prefix: *u8, nextv: *i64, maxn: i64) -> i64 {
377 let h: *i64 = ss_open(prefix)
378 if (h as i64) == 0 { return 0 }
379 let pq: *i64 = sys_mmap(16) as *i64
380 let lq: *i64 = sys_mmap(16) as *i64
381 var cnt: i64 = 0
382 var k: i64 = 0
383 var go: i64 = 1
384 while go == 1 {
385 let key: *u8 = sys_mmap(64)
386 ec_key(k, key)
387 if ss_hget(h, key, pq, lq) == 1 {
388 let v: *u8 = pq[0] as *u8
389 let cur: i64 = ec_cur(v)
390 let bar: i64 = ec_bar(v)
391 let w: i64 = ec_weight(v)
392 if cur < bar {
393 // insertion into a small max-list
394 if cnt < maxn {
395 nextv[cnt*2] = w
396 nextv[cnt*2+1] = k
397 cnt = cnt + 1
398 } else {
399 var mi: i64 = 0
400 var mv: i64 = nextv[0]
401 var t: i64 = 1
402 while t < cnt { if nextv[t*2] < mv { mv = nextv[t*2]; mi = t } t = t + 1 }
403 if w > mv { nextv[mi*2] = w; nextv[mi*2+1] = k }
404 }
405 }
406 k = k + 1
407 } else { go = 0 }
408 }
409 return cnt
410}
411
412// ---- RACI tier: the raci- plane (lane R A C I status note) = WHO owns each lane. Renders the ownership
413// matrix so the cockpit is oversight organized by clear RACI (operator: "organized impeccably, clear raci").
414// rrow[i*RC_STRIDE]: lane(a,b) R(a,b) A(a,b) C(a,b) I(a,b) status(a,b)
415func pm_raci_scan(buf: *u8, n: i64, m: *i64, rrow: *i64, maxrows: i64) -> i64 {
416 if n <= 0 { m[S_RACILANES] = 0; return 0 }
417 let sp: *i64 = sys_mmap(PM_MAXCOLS*2*8) as *i64
418 var nr: i64 = 0
419 var i: i64 = 0
420 while i < n {
421 var le: i64 = i
422 var s: i64 = 1
423 while s == 1 { if le >= n { s = 0 } else { if buf[le] == (PM_NL as u8) { s = 0 } else { le = le + 1 } } }
424 if le > i { if buf[i] != (PM_HASH as u8) {
425 let nc: i64 = pm_cols(buf, i, le, sp)
426 if nc >= 5 {
427 if nr < maxrows {
428 rrow[nr*RC_STRIDE] = sp[0]; rrow[nr*RC_STRIDE+1] = sp[1]
429 rrow[nr*RC_STRIDE+2] = sp[2]; rrow[nr*RC_STRIDE+3] = sp[3]
430 rrow[nr*RC_STRIDE+4] = sp[4]; rrow[nr*RC_STRIDE+5] = sp[5]
431 rrow[nr*RC_STRIDE+6] = sp[6]; rrow[nr*RC_STRIDE+7] = sp[7]
432 rrow[nr*RC_STRIDE+8] = sp[8]; rrow[nr*RC_STRIDE+9] = sp[9]
433 if nc >= 6 { rrow[nr*RC_STRIDE+10] = sp[10]; rrow[nr*RC_STRIDE+11] = sp[11] }
434 else { rrow[nr*RC_STRIDE+10] = le; rrow[nr*RC_STRIDE+11] = le }
435 nr = nr + 1
436 }
437 }
438 } }
439 i = le + 1
440 }
441 m[S_RACILANES] = nr
442 return nr
443}
444
445// ---- emit helpers ----
446func pm_jesc(dst: *u8, off: i64, src: *u8, a: i64, b: i64, maxb: i64) -> i64 {
447 var o: i64 = off
448 var i: i64 = a
449 var lim: i64 = b
450 if lim - a > maxb { lim = a + maxb }
451 while i < lim {
452 var c: i64 = src[i]
453 if c == 34 { dst[o] = 92 as u8; o = o + 1; dst[o] = 34 as u8; o = o + 1 }
454 else { if c == 92 { dst[o] = 92 as u8; o = o + 1; dst[o] = 92 as u8; o = o + 1 }
455 else { if c < 32 { dst[o] = 32 as u8; o = o + 1 }
456 else { dst[o] = c as u8; o = o + 1 } } }
457 i = i + 1
458 }
459 if lim < b { o = ss_cat(dst, o, "..." as *u8) }
460 return o
461}
462func pm_hesc(dst: *u8, off: i64, src: *u8, a: i64, b: i64, maxb: i64) -> i64 {
463 var o: i64 = off
464 var i: i64 = a
465 var lim: i64 = b
466 if lim - a > maxb { lim = a + maxb }
467 while i < lim {
468 let c: i64 = src[i]
469 if c == 60 { o = ss_cat(dst, o, "<" as *u8) }
470 else { if c == 38 { o = ss_cat(dst, o, "&" as *u8) }
471 else { dst[o] = c as u8; o = o + 1 } }
472 i = i + 1
473 }
474 if lim < b { o = ss_cat(dst, o, "…" as *u8) }
475 return o
476}
477// cents -> "$D.CC" (integer money, no float ever)
478func pm_money(dst: *u8, off: i64, cents: i64) -> i64 {
479 var o: i64 = ss_cat(dst, off, "$" as *u8)
480 o = ss_catn(dst, o, cents / 100)
481 o = ss_cat(dst, o, "." as *u8)
482 let r: i64 = cents % 100
483 if r < 10 { o = ss_cat(dst, o, "0" as *u8) }
484 o = ss_catn(dst, o, r)
485 return o
486}
487
488// append "dom -- next_rung" for a maturity-next entry (re-reads strings from the store handle)
489func pm_next_str(dst: *u8, off: i64, h: *i64, keyidx: i64, html: i64) -> i64 {
490 let pq: *i64 = sys_mmap(16) as *i64
491 let lq: *i64 = sys_mmap(16) as *i64
492 let key: *u8 = sys_mmap(64)
493 let dom: *u8 = sys_mmap(ECOMAT_DOM_CAP)
494 let nr: *u8 = sys_mmap(ECOMAT_NR_CAP)
495 ec_key(keyidx, key)
496 var o: i64 = off
497 if ss_hget(h, key, pq, lq) == 1 {
498 let v: *u8 = pq[0] as *u8
499 ec_str(v, 0, dom, ECOMAT_DOM_CAP)
500 ec_str(v, 2, nr, ECOMAT_NR_CAP)
501 if html == 1 { o = pm_hesc(dst, o, dom, 0, pm_len(dom), 64) } else { o = pm_jesc(dst, o, dom, 0, pm_len(dom), 64) }
502 o = ss_cat(dst, o, " -- " as *u8)
503 if html == 1 { o = pm_hesc(dst, o, nr, 0, pm_len(nr), PM_NOTE_CAP) } else { o = pm_jesc(dst, o, nr, 0, pm_len(nr), PM_NOTE_CAP) }
504 }
505 return o
506}
507
508// ---- the machine interchange: one JSON document, every number named to its live source ----
509func pm_emit_json(out: *u8, m: *i64, frbuf: *u8, frtop: *i64, nfr: i64, dbbuf: *u8, dbtop: *i64, ndb: i64, roibuf: *u8, roiline: *i64, nroi: i64, ecoprefix: *u8, nextv: *i64, nnext: i64, racibuf: *u8, raciline: *i64, nraci: i64) -> i64 {
510 var o: i64 = 0
511 o = ss_cat(out, o, "{\"tool\":\"nx_pm_cockpit\",\"epoch\":" as *u8)
512 o = ss_catn(out, o, sys_now_realtime_sec())
513 o = ss_cat(out, o, ",\"envelope\":{\"plane_cap\":" as *u8); o = ss_catn(out, o, PM_PLANE_CAP)
514 o = ss_cat(out, o, ",\"conf_cap\":" as *u8); o = ss_catn(out, o, PM_CONF_CAP)
515 o = ss_cat(out, o, ",\"top_rocks\":" as *u8); o = ss_catn(out, o, PM_TOP_ROCKS)
516 o = ss_cat(out, o, ",\"top_debts\":" as *u8); o = ss_catn(out, o, PM_TOP_DEBTS)
517 o = ss_cat(out, o, ",\"truncation\":\"marked\"}" as *u8)
518 // EXEC -- live em_rollup_store numbers (same call the maturity organ makes; cannot diverge)
519 o = ss_cat(out, o, ",\"exec\":{\"maturity_permil\":" as *u8); o = ss_catn(out, o, m[S_MAT])
520 o = ss_cat(out, o, ",\"domains\":" as *u8); o = ss_catn(out, o, m[S_DOM])
521 o = ss_cat(out, o, ",\"sclass\":" as *u8); o = ss_catn(out, o, m[S_SCLASS])
522 o = ss_cat(out, o, ",\"triangulated\":" as *u8); o = ss_catn(out, o, m[S_TRI])
523 o = ss_cat(out, o, ",\"single_src\":" as *u8); o = ss_catn(out, o, m[S_SNG])
524 o = ss_cat(out, o, ",\"dangling\":" as *u8); o = ss_catn(out, o, m[S_DNG])
525 o = ss_cat(out, o, ",\"conflicts\":" as *u8); o = ss_catn(out, o, m[S_CON])
526 o = ss_cat(out, o, ",\"autonomy_permil\":" as *u8); o = ss_catn(out, o, m[S_AUT])
527 o = ss_cat(out, o, ",\"liar_kill\":" as *u8); o = ss_catn(out, o, m[S_LIAR])
528 o = ss_cat(out, o, ",\"detail\":\"/compare/maturity\"}" as *u8)
529 // MGMT -- frontier plane counts + big rocks
530 o = ss_cat(out, o, ",\"mgmt\":{\"frontier_total\":" as *u8); o = ss_catn(out, o, m[S_FTOT])
531 o = ss_cat(out, o, ",\"done\":" as *u8); o = ss_catn(out, o, m[S_FDONE])
532 o = ss_cat(out, o, ",\"open\":" as *u8); o = ss_catn(out, o, m[S_FOPEN])
533 o = ss_cat(out, o, ",\"external\":" as *u8); o = ss_catn(out, o, m[S_FEXT])
534 o = ss_cat(out, o, ",\"detail\":\"/frontier\",\"top_rocks\":[" as *u8)
535 var i: i64 = 0
536 while i < nfr {
537 if i > 0 { o = ss_cat(out, o, "," as *u8) }
538 o = ss_cat(out, o, "{\"id\":\"" as *u8)
539 o = pm_jesc(out, o, frbuf, frtop[i*5+1], frtop[i*5+2], 24)
540 o = ss_cat(out, o, "\",\"w\":" as *u8); o = ss_catn(out, o, frtop[i*5])
541 o = ss_cat(out, o, ",\"title\":\"" as *u8)
542 o = pm_jesc(out, o, frbuf, frtop[i*5+3], frtop[i*5+4], 90)
543 o = ss_cat(out, o, "\"}" as *u8)
544 i = i + 1
545 }
546 o = ss_cat(out, o, "]}" as *u8)
547 // OPS -- registry counts + coordination pointer
548 o = ss_cat(out, o, ",\"ops\":{\"fleet_daemons\":" as *u8); o = ss_catn(out, o, m[S_FLEET])
549 o = ss_cat(out, o, ",\"mcp_tools_green\":" as *u8); o = ss_catn(out, o, m[S_TOOLS])
550 o = ss_cat(out, o, ",\"cron_jobs\":" as *u8); o = ss_catn(out, o, m[S_CRONS])
551 o = ss_cat(out, o, ",\"ws_journal_bytes\":" as *u8); o = ss_catn(out, o, m[S_JRNLB])
552 o = ss_cat(out, o, ",\"coordination\":\"/standup\"}" as *u8)
553 // RACI -- who owns each lane (the raci- plane); oversight organized by ownership
554 o = ss_cat(out, o, ",\"raci\":{\"lanes\":" as *u8); o = ss_catn(out, o, m[S_RACILANES])
555 o = ss_cat(out, o, ",\"rows\":[" as *u8)
556 var rcf: i64 = 1
557 i = 0
558 while i < nraci {
559 if rcf == 0 { o = ss_cat(out, o, "," as *u8) }
560 rcf = 0
561 o = ss_cat(out, o, "{\"lane\":\"" as *u8); o = pm_jesc(out, o, racibuf, raciline[i*RC_STRIDE], raciline[i*RC_STRIDE+1], 20)
562 o = ss_cat(out, o, "\",\"R\":\"" as *u8); o = pm_jesc(out, o, racibuf, raciline[i*RC_STRIDE+2], raciline[i*RC_STRIDE+3], 20)
563 o = ss_cat(out, o, "\",\"A\":\"" as *u8); o = pm_jesc(out, o, racibuf, raciline[i*RC_STRIDE+4], raciline[i*RC_STRIDE+5], 16)
564 o = ss_cat(out, o, "\",\"C\":\"" as *u8); o = pm_jesc(out, o, racibuf, raciline[i*RC_STRIDE+6], raciline[i*RC_STRIDE+7], 20)
565 o = ss_cat(out, o, "\",\"I\":\"" as *u8); o = pm_jesc(out, o, racibuf, raciline[i*RC_STRIDE+8], raciline[i*RC_STRIDE+9], 16)
566 o = ss_cat(out, o, "\",\"status\":\"" as *u8); o = pm_jesc(out, o, racibuf, raciline[i*RC_STRIDE+10], raciline[i*RC_STRIDE+11], 12)
567 o = ss_cat(out, o, "\"}" as *u8)
568 i = i + 1
569 }
570 o = ss_cat(out, o, "]}" as *u8)
571 // DEBT -- eat-first visibility, ours vs third-party split
572 o = ss_cat(out, o, ",\"debt\":{\"total\":" as *u8); o = ss_catn(out, o, m[S_DTOT])
573 o = ss_cat(out, o, ",\"open\":" as *u8); o = ss_catn(out, o, m[S_DOPEN])
574 o = ss_cat(out, o, ",\"gating_sev6plus\":" as *u8); o = ss_catn(out, o, m[S_DSEV])
575 o = ss_cat(out, o, ",\"third_party\":" as *u8); o = ss_catn(out, o, m[S_D3P])
576 o = ss_cat(out, o, ",\"top\":[" as *u8)
577 i = 0
578 while i < ndb {
579 if i > 0 { o = ss_cat(out, o, "," as *u8) }
580 o = ss_cat(out, o, "{\"sev\":" as *u8); o = ss_catn(out, o, dbtop[i*3])
581 o = ss_cat(out, o, ",\"note\":\"" as *u8)
582 o = pm_jesc(out, o, dbbuf, dbtop[i*3+1], dbtop[i*3+2], PM_NOTE_CAP)
583 o = ss_cat(out, o, "\"}" as *u8)
584 i = i + 1
585 }
586 o = ss_cat(out, o, "]}" as *u8)
587 // ROI -- CONSERVATIVE FLOOR from the sibling-owned roi- plane; superseded/coord excluded by construction
588 if m[S_ROIAV] == 1 {
589 o = ss_cat(out, o, ",\"roi\":{\"status\":\"ESTIMATE\",\"floor_monthly_cents\":" as *u8)
590 o = ss_catn(out, o, m[S_ROICENTS])
591 o = ss_cat(out, o, ",\"discipline\":\"CONSERVATIVE FLOOR = qty x rate over VALUE rows of the sibling-owned knowledge/store/roi- plane; SUPERSEDED + COORD rows EXCLUDED by construction; a modeled avoidance/estimate, NOT revenue and NOT a measurement -- aspirational ceilings are never summed here (honors the plane ROI-CONVERGE rule)\",\"counts\":{\"value_lines\":" as *u8)
592 o = ss_catn(out, o, m[S_ROILINES])
593 o = ss_cat(out, o, ",\"superseded_excluded\":" as *u8); o = ss_catn(out, o, m[S_ROISUPER])
594 o = ss_cat(out, o, ",\"rate_configs\":" as *u8); o = ss_catn(out, o, m[S_ROICFG])
595 o = ss_cat(out, o, ",\"research_targets\":" as *u8); o = ss_catn(out, o, m[S_ROIRES])
596 o = ss_cat(out, o, "},\"lines\":[" as *u8)
597 var rfirst: i64 = 1
598 i = 0
599 while i < nroi {
600 if roiline[i*RR_STRIDE] == 0 {
601 if rfirst == 0 { o = ss_cat(out, o, "," as *u8) }
602 rfirst = 0
603 o = ss_cat(out, o, "{\"id\":\"" as *u8)
604 o = pm_jesc(out, o, roibuf, roiline[i*RR_STRIDE+4], roiline[i*RR_STRIDE+5], 20)
605 o = ss_cat(out, o, "\",\"label\":\"" as *u8)
606 o = pm_jesc(out, o, roibuf, roiline[i*RR_STRIDE+6], roiline[i*RR_STRIDE+7], 60)
607 o = ss_cat(out, o, "\",\"src\":\"" as *u8)
608 o = pm_jesc(out, o, roibuf, roiline[i*RR_STRIDE+8], roiline[i*RR_STRIDE+9], 16)
609 o = ss_cat(out, o, "\",\"qty\":" as *u8); o = ss_catn(out, o, roiline[i*RR_STRIDE+1])
610 o = ss_cat(out, o, ",\"cents_per_mo\":" as *u8); o = ss_catn(out, o, roiline[i*RR_STRIDE+2])
611 o = ss_cat(out, o, ",\"subtotal_cents\":" as *u8); o = ss_catn(out, o, roiline[i*RR_STRIDE+3])
612 o = ss_cat(out, o, ",\"basis\":\"" as *u8)
613 o = pm_jesc(out, o, roibuf, roiline[i*RR_STRIDE+10], roiline[i*RR_STRIDE+11], PM_NOTE_CAP)
614 o = ss_cat(out, o, "\"}" as *u8)
615 }
616 i = i + 1
617 }
618 o = ss_cat(out, o, "],\"research_fetch_targets\":[" as *u8)
619 rfirst = 1
620 i = 0
621 while i < nroi {
622 if roiline[i*RR_STRIDE] == 2 {
623 if rfirst == 0 { o = ss_cat(out, o, "," as *u8) }
624 rfirst = 0
625 o = ss_cat(out, o, "{\"topic\":\"" as *u8)
626 o = pm_jesc(out, o, roibuf, roiline[i*RR_STRIDE+6], roiline[i*RR_STRIDE+7], 60)
627 o = ss_cat(out, o, "\",\"note\":\"" as *u8)
628 o = pm_jesc(out, o, roibuf, roiline[i*RR_STRIDE+10], roiline[i*RR_STRIDE+11], PM_NOTE_CAP)
629 o = ss_cat(out, o, "\"}" as *u8)
630 }
631 i = i + 1
632 }
633 o = ss_cat(out, o, "]}" as *u8)
634 } else {
635 o = ss_cat(out, o, ",\"roi\":{\"status\":\"UNSEEDED\",\"note\":\"knowledge/store/roi- ledger absent -- no numbers invented; the sibling PM-cockpit workstream seeds it via nx_store_put\"}" as *u8)
636 }
637 // FEEDBACK -- the PM's next actions, each derived from a live source above
638 o = ss_cat(out, o, ",\"feedback\":{\"maturity_next\":[" as *u8)
639 let h: *i64 = ss_open(ecoprefix)
640 if (h as i64) != 0 {
641 i = 0
642 while i < nnext {
643 if i > 0 { o = ss_cat(out, o, "," as *u8) }
644 o = ss_cat(out, o, "\"" as *u8)
645 o = pm_next_str(out, o, h, nextv[i*2+1], 0)
646 o = ss_cat(out, o, "\"" as *u8)
647 i = i + 1
648 }
649 }
650 o = ss_cat(out, o, "],\"order\":\"eat gating debts first (debt.top), then the biggest ready rocks (mgmt.top_rocks), then maturity next-rungs\"}}" as *u8)
651 o = ss_cat(out, o, "\n" as *u8)
652 return o
653}
654
655// ---- the /pm page: 0-JS organ-authored HTML, dark theme, every figure labeled to its source ----
656func pm_emit_html(out: *u8, m: *i64, frbuf: *u8, frtop: *i64, nfr: i64, dbbuf: *u8, dbtop: *i64, ndb: i64, roibuf: *u8, roiline: *i64, nroi: i64, ecoprefix: *u8, nextv: *i64, nnext: i64, racibuf: *u8, raciline: *i64, nraci: i64) -> i64 {
657 var o: i64 = 0
658 o = ss_cat(out, o, "<!doctype html><html lang=en><head><meta charset=utf-8><meta name=viewport content='width=device-width,initial-scale=1'><title>Nishi PM Cockpit</title><style>" as *u8)
659 o = ss_cat(out, o, "body{margin:0;font:15px/1.5 -apple-system,Segoe UI,Roboto,sans-serif;background:#0e1116;color:#e6edf3}" as *u8)
660 o = ss_cat(out, o, "header{padding:28px 24px;background:linear-gradient(135deg,#161b22,#0e1116);border-bottom:1px solid #30363d}" as *u8)
661 o = ss_cat(out, o, "h1{margin:0 0 6px;font-size:22px}.sub{color:#8b949e;font-size:14px}.big{font-size:44px;font-weight:800;color:#3fb950;line-height:1.1}" as *u8)
662 o = ss_cat(out, o, "h2{margin:26px 24px 8px;font-size:13px;text-transform:uppercase;letter-spacing:.08em;color:#8b949e}" as *u8)
663 o = ss_cat(out, o, "table{border-collapse:collapse;margin:0 24px 8px;max-width:1020px}td,th{padding:7px 10px;border-bottom:1px solid #21262d;text-align:left;font-size:14px}th{color:#8b949e;font-size:12px;text-transform:uppercase}" as *u8)
664 o = ss_cat(out, o, ".k{color:#8b949e}.g{color:#3fb950}.a{color:#d29922}.r{color:#f85149}.m{color:#8b949e;font-size:12px}a{color:#58a6ff;text-decoration:none}" as *u8)
665 o = ss_cat(out, o, ".tile{display:inline-block;background:#161b22;border:1px solid #30363d;border-radius:10px;padding:12px 18px;margin:10px 8px 0 0;min-width:130px}.tile .n{font-size:26px;font-weight:700}.tile .l{color:#8b949e;font-size:12px}" as *u8)
666 o = ss_cat(out, o, "footer{padding:18px 24px;color:#6e7681;font-size:12px;border-top:1px solid #21262d;margin-top:22px}" as *u8)
667 o = ss_cat(out, o, "</style></head><body><header><h1>Nishi PM Cockpit</h1><div class=sub>executive · management · operations — measured live from the sovereign planes, never asserted</div>" as *u8)
668 // headline tiles
669 o = ss_cat(out, o, "<div><span class=tile><div class=n>" as *u8); o = ss_catn(out, o, m[S_MAT])
670 o = ss_cat(out, o, "‰</div><div class=l>maturity toward S-class</div></span>" as *u8)
671 o = ss_cat(out, o, "<span class=tile><div class=n>" as *u8); o = ss_catn(out, o, m[S_FDONE]); o = ss_cat(out, o, "/" as *u8); o = ss_catn(out, o, m[S_FTOT])
672 o = ss_cat(out, o, "</div><div class=l>frontier rocks done</div></span>" as *u8)
673 o = ss_cat(out, o, "<span class=tile><div class=n>" as *u8); o = ss_catn(out, o, m[S_DOPEN])
674 o = ss_cat(out, o, "</div><div class=l>open debts (" as *u8); o = ss_catn(out, o, m[S_DSEV]); o = ss_cat(out, o, " gating)</div></span>" as *u8)
675 if m[S_ROIAV] == 1 {
676 o = ss_cat(out, o, "<span class=tile><div class=n>" as *u8); o = pm_money(out, o, m[S_ROICENTS])
677 o = ss_cat(out, o, "</div><div class=l>est. value / mo (FLOOR)</div></span>" as *u8)
678 }
679 o = ss_cat(out, o, "</div>" as *u8)
680 if m[S_LIAR] > 0 { o = ss_cat(out, o, "<p class=r><b>LIAR-KILL FIRED</b> in the maturity store -- an S-class claim lacks evidence; fix before trusting the exec tier.</p>" as *u8) }
681 o = ss_cat(out, o, "</header>" as *u8)
682 // EXEC
683 o = ss_cat(out, o, "<h2>Executive — ecosystem maturity (live rollup)</h2><table><tr><th>metric</th><th>value</th><th>source</th></tr>" as *u8)
684 o = ss_cat(out, o, "<tr><td>overall maturity</td><td>" as *u8); o = ss_catn(out, o, m[S_MAT]); o = ss_cat(out, o, "‰ across " as *u8); o = ss_catn(out, o, m[S_DOM]); o = ss_cat(out, o, " domains · " as *u8); o = ss_catn(out, o, m[S_SCLASS]); o = ss_cat(out, o, " at S-class</td><td class=m>knowledge/store/ecomat via em_rollup_store (same call as <a href=/compare/maturity>/compare/maturity</a>)</td></tr>" as *u8)
685 o = ss_cat(out, o, "<tr><td>validation</td><td>triangulated " as *u8); o = ss_catn(out, o, m[S_TRI]); o = ss_cat(out, o, " · single-src " as *u8); o = ss_catn(out, o, m[S_SNG]); o = ss_cat(out, o, " · dangling " as *u8); o = ss_catn(out, o, m[S_DNG]); o = ss_cat(out, o, " · conflicts " as *u8); o = ss_catn(out, o, m[S_CON]); o = ss_cat(out, o, "</td><td class=m>two independent witnesses per grade; conservative MIN consensus</td></tr>" as *u8)
686 o = ss_cat(out, o, "<tr><td>live autonomy</td><td>" as *u8); o = ss_catn(out, o, m[S_AUT]); o = ss_cat(out, o, "‰</td><td class=m>knowledge/status/autonomy_meter.log</td></tr></table>" as *u8)
687 // MGMT
688 o = ss_cat(out, o, "<h2>Management — frontier program</h2><table><tr><th>total</th><th>done</th><th>open</th><th>external</th><th>detail</th></tr><tr><td>" as *u8)
689 o = ss_catn(out, o, m[S_FTOT]); o = ss_cat(out, o, "</td><td class=g>" as *u8); o = ss_catn(out, o, m[S_FDONE])
690 o = ss_cat(out, o, "</td><td class=a>" as *u8); o = ss_catn(out, o, m[S_FOPEN]); o = ss_cat(out, o, "</td><td class=k>" as *u8); o = ss_catn(out, o, m[S_FEXT])
691 o = ss_cat(out, o, "</td><td><a href=/frontier>CPM board: critical path, float, ready/blocked</a></td></tr></table>" as *u8)
692 o = ss_cat(out, o, "<table><tr><th>w</th><th>open big rocks (weight ≥ " as *u8); o = ss_catn(out, o, PM_ROCK_W_MIN); o = ss_cat(out, o, ")</th></tr>" as *u8)
693 var i: i64 = 0
694 while i < nfr {
695 o = ss_cat(out, o, "<tr><td>" as *u8); o = ss_catn(out, o, frtop[i*5])
696 o = ss_cat(out, o, "</td><td><b>" as *u8)
697 o = pm_hesc(out, o, frbuf, frtop[i*5+1], frtop[i*5+2], 24)
698 o = ss_cat(out, o, "</b> · " as *u8)
699 o = pm_hesc(out, o, frbuf, frtop[i*5+3], frtop[i*5+4], 110)
700 o = ss_cat(out, o, "</td></tr>" as *u8)
701 i = i + 1
702 }
703 o = ss_cat(out, o, "</table>" as *u8)
704 // OPS
705 o = ss_cat(out, o, "<h2>Operations — live registries</h2><table><tr><th>meter</th><th>count</th><th>source</th></tr>" as *u8)
706 o = ss_cat(out, o, "<tr><td>supervised fleet daemons</td><td>" as *u8); o = ss_catn(out, o, m[S_FLEET]); o = ss_cat(out, o, "</td><td class=m>daemons.reg rows</td></tr>" as *u8)
707 o = ss_cat(out, o, "<tr><td>MCP tools GREEN</td><td>" as *u8); o = ss_catn(out, o, m[S_TOOLS]); o = ss_cat(out, o, "</td><td class=m>tool_allowlist.conf GREEN rows</td></tr>" as *u8)
708 o = ss_cat(out, o, "<tr><td>automation cron jobs</td><td>" as *u8); o = ss_catn(out, o, m[S_CRONS]); o = ss_cat(out, o, "</td><td class=m>cron.reg rows</td></tr>" as *u8)
709 o = ss_cat(out, o, "<tr><td>coordination journal</td><td>" as *u8); o = ss_catn(out, o, m[S_JRNLB]); o = ss_cat(out, o, " bytes</td><td class=m>knowledge/status/ws_sync.jrnl · liveness view: <a href=/standup>/standup</a></td></tr></table>" as *u8)
710 // RACI -- ownership matrix (organized impeccably per operator ask)
711 o = ss_cat(out, o, "<h2>Team & ownership — RACI (who runs each lane)</h2><table><tr><th>lane</th><th>R responsible</th><th>A accountable</th><th>C consulted</th><th>I informed</th><th>status</th></tr>" as *u8)
712 i = 0
713 while i < nraci {
714 o = ss_cat(out, o, "<tr><td><b>" as *u8); o = pm_hesc(out, o, racibuf, raciline[i*RC_STRIDE], raciline[i*RC_STRIDE+1], 20)
715 o = ss_cat(out, o, "</b></td><td>" as *u8); o = pm_hesc(out, o, racibuf, raciline[i*RC_STRIDE+2], raciline[i*RC_STRIDE+3], 20)
716 o = ss_cat(out, o, "</td><td class=g>" as *u8); o = pm_hesc(out, o, racibuf, raciline[i*RC_STRIDE+4], raciline[i*RC_STRIDE+5], 16)
717 o = ss_cat(out, o, "</td><td class=m>" as *u8); o = pm_hesc(out, o, racibuf, raciline[i*RC_STRIDE+6], raciline[i*RC_STRIDE+7], 24)
718 o = ss_cat(out, o, "</td><td class=m>" as *u8); o = pm_hesc(out, o, racibuf, raciline[i*RC_STRIDE+8], raciline[i*RC_STRIDE+9], 16)
719 o = ss_cat(out, o, "</td><td class=m>" as *u8); o = pm_hesc(out, o, racibuf, raciline[i*RC_STRIDE+10], raciline[i*RC_STRIDE+11], 12)
720 o = ss_cat(out, o, "</td></tr>" as *u8)
721 i = i + 1
722 }
723 o = ss_cat(out, o, "</table><p class=m style='margin:4px 24px'>R=responsible A=accountable C=consulted I=informed · source knowledge/store/raci- (" as *u8)
724 o = ss_catn(out, o, m[S_RACILANES]); o = ss_cat(out, o, " lanes; A=operator = the executive owns the portfolio)</p>" as *u8)
725 // DEBT
726 o = ss_cat(out, o, "<h2>Debt — eat first, then move (good form)</h2><table><tr><th>total</th><th>open</th><th>gating (sev≥" as *u8)
727 o = ss_catn(out, o, PM_DEBT_GATE_SEV)
728 o = ss_cat(out, o, ")</th><th>third-party</th></tr><tr><td>" as *u8)
729 o = ss_catn(out, o, m[S_DTOT]); o = ss_cat(out, o, "</td><td class=a>" as *u8); o = ss_catn(out, o, m[S_DOPEN])
730 o = ss_cat(out, o, "</td><td class=r>" as *u8); o = ss_catn(out, o, m[S_DSEV]); o = ss_cat(out, o, "</td><td>" as *u8); o = ss_catn(out, o, m[S_D3P])
731 o = ss_cat(out, o, "</td></tr></table><p class=m style='margin:4px 24px'>third-party = rows whose note names stock git / gitea / DSM nginx / Synology / vendor surfaces (declared heuristic). The work-refusing gate lives in nx_ws_cycle: no WORK action while an in-scope debt ≥ sev-floor is open.</p>" as *u8)
732 o = ss_cat(out, o, "<table><tr><th>sev</th><th>top gating debts (sev ≥ " as *u8); o = ss_catn(out, o, PM_DEBT_HI_SEV); o = ss_cat(out, o, ")</th></tr>" as *u8)
733 i = 0
734 while i < ndb {
735 o = ss_cat(out, o, "<tr><td class=r>" as *u8); o = ss_catn(out, o, dbtop[i*3])
736 o = ss_cat(out, o, "</td><td>" as *u8)
737 o = pm_hesc(out, o, dbbuf, dbtop[i*3+1], dbtop[i*3+2], PM_NOTE_CAP)
738 o = ss_cat(out, o, "</td></tr>" as *u8)
739 i = i + 1
740 }
741 o = ss_cat(out, o, "</table>" as *u8)
742 // ROI -- conservative FLOOR (qty x rate); superseded/coord excluded by construction
743 o = ss_cat(out, o, "<h2>Return on investment — conservative FLOOR, no fake numbers</h2>" as *u8)
744 if m[S_ROIAV] == 1 {
745 o = ss_cat(out, o, "<p class=m style='margin:4px 24px'>Composed from the sibling-owned <b>knowledge/store/roi-</b> plane (the convergence surface). Honors the plane ROI-CONVERGE rule: only the CONSERVATIVE FLOOR is summed; " as *u8)
746 o = ss_catn(out, o, m[S_ROISUPER]); o = ss_cat(out, o, " SUPERSEDED + all COORD rows are EXCLUDED by construction. A modeled SaaS/energy/time <b>avoidance estimate — not revenue, not a measurement</b>; aspirational ceilings are never summed here.</p>" as *u8)
747 o = ss_cat(out, o, "<table><tr><th>id</th><th>replaces / avoids</th><th>axis</th><th>qty</th><th>rate/mo</th><th>subtotal/mo</th><th>basis</th></tr>" as *u8)
748 i = 0
749 while i < nroi {
750 if roiline[i*RR_STRIDE] == 0 {
751 o = ss_cat(out, o, "<tr><td class=m>" as *u8)
752 o = pm_hesc(out, o, roibuf, roiline[i*RR_STRIDE+4], roiline[i*RR_STRIDE+5], 20)
753 o = ss_cat(out, o, "</td><td>" as *u8)
754 o = pm_hesc(out, o, roibuf, roiline[i*RR_STRIDE+6], roiline[i*RR_STRIDE+7], 52)
755 o = ss_cat(out, o, "</td><td class=m>" as *u8)
756 o = pm_hesc(out, o, roibuf, roiline[i*RR_STRIDE+8], roiline[i*RR_STRIDE+9], 12)
757 o = ss_cat(out, o, "</td><td>" as *u8); o = ss_catn(out, o, roiline[i*RR_STRIDE+1])
758 o = ss_cat(out, o, "</td><td>" as *u8); o = pm_money(out, o, roiline[i*RR_STRIDE+2])
759 o = ss_cat(out, o, "</td><td class=g>" as *u8); o = pm_money(out, o, roiline[i*RR_STRIDE+3])
760 o = ss_cat(out, o, "</td><td class=m>" as *u8)
761 o = pm_hesc(out, o, roibuf, roiline[i*RR_STRIDE+10], roiline[i*RR_STRIDE+11], PM_NOTE_CAP)
762 o = ss_cat(out, o, "</td></tr>" as *u8)
763 }
764 i = i + 1
765 }
766 o = ss_cat(out, o, "<tr><td colspan=5><b>TOTAL conservative floor / month</b></td><td class=g><b>" as *u8)
767 o = pm_money(out, o, m[S_ROICENTS])
768 o = ss_cat(out, o, "</b></td><td class=m>modeled avoidance; " as *u8); o = ss_catn(out, o, m[S_ROILINES]); o = ss_cat(out, o, " value lines; NOT revenue, NOT measured</td></tr></table>" as *u8)
769 } else {
770 o = ss_cat(out, o, "<p class=a style='margin:4px 24px'>UNSEEDED — the knowledge/store/roi- ledger is absent; no numbers are invented. The sibling PM-cockpit workstream seeds it via nx_store_put.</p>" as *u8)
771 }
772 // FEEDBACK
773 o = ss_cat(out, o, "<h2>Feedback — what the measurements say to do next</h2><table><tr><th>tier</th><th>next action</th></tr>" as *u8)
774 o = ss_cat(out, o, "<tr><td>order</td><td>eat gating debts first → biggest ready rocks → maturity next-rungs (the debt-gate in nx_ws_cycle enforces this; it is not advice)</td></tr>" as *u8)
775 let h: *i64 = ss_open(ecoprefix)
776 if (h as i64) != 0 {
777 i = 0
778 while i < nnext {
779 o = ss_cat(out, o, "<tr><td class=k>maturity</td><td>" as *u8)
780 o = pm_next_str(out, o, h, nextv[i*2+1], 1)
781 o = ss_cat(out, o, "</td></tr>" as *u8)
782 i = i + 1
783 }
784 }
785 o = ss_cat(out, o, "</table>" as *u8)
786 // SOTA H2H -- honest, measured-vs-unmeasured labeled
787 o = ss_cat(out, o, "<h2>vs state of the art — honest, no self-graded wins</h2><table><tr><th>axis</th><th>vs Jira Align / Asana Goals / Monday / Power BI-class exec dashboards</th></tr>" as *u8)
788 o = ss_cat(out, o, "<tr><td class=g>BEST (measured)</td><td>every figure machine-derived from live artifacts (stores/logs/registries) -- zero manual status entry; SOTA tools rely on humans updating fields</td></tr>" as *u8)
789 o = ss_cat(out, o, "<tr><td class=g>BEST (measured)</td><td>honesty gates: liar-kill on unevidenced claims + two-witness triangulation + fail-closed UNSEEDED ROI -- no SOTA PM dashboard refuses to show a number it cannot ground</td></tr>" as *u8)
790 o = ss_cat(out, o, "<tr><td class=g>BEST (measured)</td><td>debt-gated flow: the conductor refuses WORK while gating debt is open (mechanized stop-and-eat); SOTA has no equivalent tooth</td></tr>" as *u8)
791 o = ss_cat(out, o, "<tr><td class=a>PAR</td><td>CPM critical path / float (<a href=/frontier>/frontier</a>) vs MS-Project-class scheduling</td></tr>" as *u8)
792 o = ss_cat(out, o, "<tr><td class=r>GAP</td><td>resource leveling + capacity + EVM: nishi_project has the organs but its plane is UNSEEDED (gate 9/31 RED) -- honest gap, next rung</td></tr>" as *u8)
793 o = ss_cat(out, o, "<tr><td class=r>GAP</td><td>probabilistic forecasting (Monte-Carlo when-will-it-be-done), velocity/burn trends over history, telemetry-scored OKRs -- research opportunities below</td></tr></table>" as *u8)
794 o = ss_cat(out, o, "<h2>Research opportunities — beyond SOTA + what to look for in our fetches</h2><table><tr><th>opportunity</th><th>fetch targets</th></tr>" as *u8)
795 // LIVE from the sibling-curated roi- research plane (convergence: their fetch spec renders here)
796 i = 0
797 while i < nroi {
798 if roiline[i*RR_STRIDE] == 2 {
799 o = ss_cat(out, o, "<tr><td class=g>" as *u8)
800 o = pm_hesc(out, o, roibuf, roiline[i*RR_STRIDE+6], roiline[i*RR_STRIDE+7], 48)
801 o = ss_cat(out, o, " <span class=m>(roi- plane)</span></td><td class=m>" as *u8)
802 o = pm_hesc(out, o, roibuf, roiline[i*RR_STRIDE+10], roiline[i*RR_STRIDE+11], PM_NOTE_CAP)
803 o = ss_cat(out, o, "</td></tr>" as *u8)
804 }
805 i = i + 1
806 }
807 o = ss_cat(out, o, "<tr><td>DORA/flow metrics from our own event planes (deploy frequency, lead time -- raw events already in ws_sync.jrnl + promote logs)</td><td class=m>DORA 2024-25 State of DevOps; Flow Framework (Kersten); value-stream metrics literature</td></tr>" as *u8)
808 o = ss_cat(out, o, "<tr><td>Monte-Carlo schedule forecasting on the frontier DAG (probabilistic ES/EF instead of point CPM)</td><td class=m>Vacanti 'When Will It Be Done'; reference-class forecasting (Flyvbjerg); MCMC throughput models</td></tr>" as *u8)
809 o = ss_cat(out, o, "<tr><td>evidence-based portfolio ROI (replace declared rates with fetched market comparators, auto-refreshed)</td><td class=m>ANSI-748 EVM criteria; lean-portfolio ROI critiques; public SaaS price pages as rate oracles</td></tr>" as *u8)
810 o = ss_cat(out, o, "<tr><td>telemetry-scored OKRs (grade objectives from live meters, no self-report)</td><td class=m>OpenTelemetry-to-OKR pipelines; Google OKR grading practice</td></tr></table>" as *u8)
811 o = ss_cat(out, o, "<footer>sources: knowledge/store/ecomat · knowledge/store/frontier- · knowledge/store/debt- · knowledge/store/roi- · tool_allowlist.conf · cron.reg · daemons.reg · ws_sync.jrnl — envelope: plane reads ≤ " as *u8)
812 o = ss_catn(out, o, PM_PLANE_CAP)
813 o = ss_cat(out, o, "B, conf reads ≤ " as *u8)
814 o = ss_catn(out, o, PM_CONF_CAP)
815 o = ss_cat(out, o, "B, truncation marked · generated epoch " as *u8)
816 o = ss_catn(out, o, sys_now_realtime_sec())
817 o = ss_cat(out, o, " · measured, never asserted · hub: <a href=/compare>/compare</a> · atlas: <a href=/compare/atlas>/compare/atlas</a></footer></body></html>\n" as *u8)
818 return o
819}