code wiki / _hdl_build / nx_pm_dashboard.nx
nx_pm_dashboard.nx source
↩ module page · 901 lines · 46694 B
1// nx_pm_dashboard.nx -- the PM OVERSIGHT + ROI organ (operator 2026-07-18: "the pm to give us based
2// on my executive, management, and operations layer a dashboard and feedback... return on investment
3// with non fake numbers but real estimates in time and money and energy and other savings").
4//
5// THREE LAYERS, one artifact-derived truth:
6// EXECUTIVE -- ROI ledger + portfolio rollup + research-opps (the invest/return view)
7// MANAGEMENT -- feedback: gating debts, stalest lanes, debt burn, phase mix (the decide/unblock view)
8// OPERATIONS -- live in-progress table with ACTIVE/STALE liveness (the standup / right-now view)
9//
10// ROI HONESTY BY CONSTRUCTION (operator: "not fake numbers... bad form leads to bad gains and injuries"):
11// every figure = a MEASURED event count (frontier D-rows, cron/daemon/tool rows, journal frames, debt
12// rows) x a DECLARED rate that lives as a CONFIG row in the roi- store (rule 11, no magic numbers).
13// The arithmetic (count x rate) is shown inline so any figure is auditable; nothing is hardcoded.
14// Rates absent/unseeded -> the ROI block says "unseeded (run seedroi)" and emits NO numbers (fail-closed).
15// Scale-law: journal read is TAIL-windowed with journal_bytes vs window_bytes DECLARED in every output.
16//
17// nx_pm_dashboard seedroi [roiprefix] (idempotent: 16 rate CONFIG + 4 RESEARCH rows)
18// nx_pm_dashboard roi [roiprefix] [frontier] [journal] [debtprefix] (JSON: the ROI ledger, tagged)
19// nx_pm_dashboard exec [journal] [debtprefix] [frontier] [roiprefix] (JSON: portfolio + roi + attention)
20// nx_pm_dashboard page [outpath] [journal] [debtprefix] [frontier] [roiprefix] [cycleprefix] (HTML, 3 layers)
21// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
22// NOTE (DRY debt, filed): the journal/debt/store scan helpers are shared in spirit with nx_ws_cycle;
23// extract a common nx_loop_lib.nx and import from both (avoided a mid-flight refactor of a contended organ).
24import "nx_store_seed_lib.nx"
25import "nx_seg_store.nx"
26import "nx_syscalls.nx"
27const PD_MAGIC_2880: i64 = 2880
28const PD_MAGIC_30000: i64 = 30000
29const PD_MAGIC_7200: i64 = 7200
30
31const PD_CAP: i64 = 1048576
32const PD_JCAP: i64 = 1048576
33const PD_SEEK_SET: i64 = 0
34const PD_SEEK_END: i64 = 2
35const PD_TAB: i64 = 9
36const PD_NL: i64 = 10
37const PD_HASH: i64 = 35
38const PD_STDERR: i64 = 2
39const PD_MODE: i64 = 420
40const PD_SPAN: i64 = 16
41const PD_EXIT_USAGE: i64 = 2
42
43func pd_werr(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(PD_STDERR, s, n); return 0 }
44func pd_vlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
45func pd_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { d[o] = s[i]; o = o + 1; i = i + 1 } return o }
46func pd_catn(d: *u8, o: i64, v: i64) -> i64 { let t: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 } var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 } while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } var i: i64 = 0; while i < k { d[o] = t[k-1-i]; o = o + 1; i = i + 1 } return o }
47// two-digit cents (00..99) for USD.cc display
48func pd_cat_cc(d: *u8, o: i64, c: i64) -> i64 { var cc: i64 = c; if cc < 0 { cc = 0 } cc = cc % 100; d[o] = (48 + (cc / 10)) as u8; d[o+1] = (48 + (cc % 10)) as u8; return o + 2 }
49func pd_cat_esc(d: *u8, o: i64, q: *u8, s: i64, e: i64) -> i64 {
50 var i: i64 = s
51 while i < e { var c: i64 = q[i] as i64; if c == 34 { c = 39 } if c == 92 { c = 47 } if c < 32 { c = 32 } d[o] = c as u8; o = o + 1; i = i + 1 }
52 return o
53}
54// HTML-SINK ESCAPER (seq677 sweep, 2026-07-23). pd_cat_esc above is a JSON-STRING escaper and does NOT
55// neutralise markup -- it was feeding the /pm HTML page the SAME journal callout text that produced a live
56// stored-injection on /standup (fixed in nx_ws_cycle). Context-correct: JSON sink keeps pd_cat_esc
57// (rule 19), HTML sink uses this. Bounded write.
58func pd_cat_esc_html(d: *u8, o: i64, q: *u8, s: i64, e: i64) -> i64 {
59 var i: i64 = s
60 var w: i64 = o
61 while i < e {
62 if w > PD_CAP - 16 { i = e } else {
63 let c: i64 = q[i] as i64
64 if c == 38 { w = pd_cat(d, w, "&" as *u8) } else { if c == 60 { w = pd_cat(d, w, "<" as *u8) } else { if c == 62 { w = pd_cat(d, w, ">" as *u8) } else { if c == 34 { w = pd_cat(d, w, """ as *u8) } else { if c < 32 { d[w] = 32 as u8; w = w + 1 } else { d[w] = c as u8; w = w + 1 } } } } }
65 i = i + 1
66 }
67 }
68 return w
69}
70// SCALE-LAW tail-window read: lseek END, keep the last cap bytes, drop the partial first line so every
71// framed row in the window is whole. sizep[0] = the file's TRUE size (caller declares window vs total).
72func pd_read(path: *u8, buf: *u8, cap: i64, sizep: *i64) -> i64 {
73 sizep[0] = 0
74 let fd: i64 = sys_openat_rd(path)
75 if fd < 0 { return 0 }
76 var size: i64 = sys_lseek(fd, 0, PD_SEEK_END)
77 if size < 0 { size = 0 }
78 sizep[0] = size
79 var off: i64 = 0
80 if size > cap { off = size - cap }
81 sys_lseek(fd, off, PD_SEEK_SET)
82 var n: i64 = 0
83 var go: i64 = 1
84 while go == 1 { let r: i64 = sys_read(fd, ((buf as i64) + n) as *u8, cap - n); if r <= 0 { go = 0 } else { n = n + r } if n >= cap { go = 0 } }
85 sys_close(fd)
86 if off > 0 {
87 var fnl: i64 = 0
88 var s: i64 = 1
89 while s == 1 { if fnl >= n { s = 0 } else { if buf[fnl] == (PD_NL as u8) { s = 0 } else { fnl = fnl + 1 } } }
90 if fnl < n { var t: i64 = 0; let sk: i64 = fnl + 1; while sk + t < n { buf[t] = buf[sk + t]; t = t + 1 } n = t }
91 }
92 return n
93}
94func pd_le(q: *u8, i: i64, n: i64) -> i64 { var e: i64 = i; var s: i64 = 1; while s == 1 { if e >= n { s = 0 } else { if q[e] == (PD_NL as u8) { s = 0 } else { e = e + 1 } } } return e }
95func pd_col(q: *u8, ls: i64, le: i64, c: i64, out: *i64) -> i64 {
96 var col: i64 = 0
97 var p: i64 = ls
98 while col < c {
99 var s: i64 = 1
100 while s == 1 { if p >= le { return 0 } if q[p] == (PD_TAB as u8) { s = 0 } else { p = p + 1 } }
101 p = p + 1
102 col = col + 1
103 }
104 var e: i64 = p
105 var s2: i64 = 1
106 while s2 == 1 { if e >= le { s2 = 0 } else { if q[e] == (PD_TAB as u8) { s2 = 0 } else { e = e + 1 } } }
107 out[0] = p
108 out[1] = e
109 return 1
110}
111func pd_lit_eq(q: *u8, s: i64, e: i64, lit: *u8) -> i64 {
112 var i: i64 = 0
113 while s + i < e { if lit[i] == (0 as u8) { return 0 } if q[s+i] != lit[i] { return 0 } i = i + 1 }
114 if lit[i] != (0 as u8) { return 0 }
115 return 1
116}
117func pd_span_eq(q: *u8, s1: i64, e1: i64, s2: i64, e2: i64) -> i64 {
118 if e1 - s1 != e2 - s2 { return 0 }
119 var i: i64 = 0
120 while s1 + i < e1 { if q[s1+i] != q[s2+i] { return 0 } i = i + 1 }
121 return 1
122}
123func pd_atoi_span(q: *u8, s: i64, e: i64) -> i64 { var v: i64 = 0; var i: i64 = s; while i < e { let c: i64 = q[i] as i64; if c >= 48 { if c <= 57 { v = v * 10 + (c - 48) } } i = i + 1 } return v }
124// data-driven CONFIG lookup, key-aware (rule 11). absent store/key -> defv. Also used to detect seeding.
125func pd_cfg(cprefix: *u8, key: *u8, defv: i64) -> i64 {
126 let b: *u8 = sys_mmap(PD_CAP)
127 let n: i64 = sts_load(cprefix, b, PD_CAP)
128 if n <= 0 { return defv }
129 let c1: *i64 = sys_mmap(PD_SPAN) as *i64
130 let c2: *i64 = sys_mmap(PD_SPAN) as *i64
131 let c3: *i64 = sys_mmap(PD_SPAN) as *i64
132 var i: i64 = 0
133 while i < n {
134 let le: i64 = pd_le(b, i, n)
135 if pd_col(b, i, le, 1, c1) == 1 { if pd_lit_eq(b, c1[0], c1[1], "CONFIG" as *u8) == 1 {
136 if pd_col(b, i, le, 2, c2) == 1 { if pd_lit_eq(b, c2[0], c2[1], key) == 1 {
137 if pd_col(b, i, le, 3, c3) == 1 { return pd_atoi_span(b, c3[0], c3[1]) }
138 } }
139 } }
140 i = le + 1
141 }
142 return defv
143}
144func pd_store_seeded(cprefix: *u8) -> i64 { let b: *u8 = sys_mmap(PD_CAP); let n: i64 = sts_load(cprefix, b, PD_CAP); if n > 0 { return 1 } return 0 }
145// does buf start with the NUL-terminated literal? (for a gate-log VERDICT check)
146func pd_starts(buf: *u8, n: i64, lit: *u8) -> i64 { var i: i64 = 0; while lit[i] != (0 as u8) { if i >= n { return 0 } if buf[i] != lit[i] { return 0 } i = i + 1 } return 1 }
147// count non-empty, non-comment ('#') lines of a CWD-relative file (cron.reg / daemons.reg / tool_allowlist.conf)
148func pd_count_noncomment(path: *u8) -> i64 {
149 let b: *u8 = sys_mmap(PD_CAP)
150 let szp: *i64 = sys_mmap(PD_SPAN) as *i64
151 let n: i64 = pd_read(path, b, PD_CAP - 4, szp)
152 var cnt: i64 = 0
153 var i: i64 = 0
154 while i < n {
155 let le: i64 = pd_le(b, i, n)
156 if le > i { if (b[i] as i64) != PD_HASH {
157 // treat a whitespace-only line as empty
158 var np: i64 = 0
159 var j: i64 = i
160 while j < le { let c: i64 = b[j] as i64; if c != 32 { if c != PD_TAB { np = 1; j = le } else { j = j + 1 } } else { j = j + 1 } }
161 if np == 1 { cnt = cnt + 1 }
162 } }
163 i = le + 1
164 }
165 return cnt
166}
167// frontier scan: count rows whose status col5 == ch; totp[0] = data-row count (non-comment).
168func pd_scan_frontier(path: *u8, ch: i64, totp: *i64) -> i64 {
169 let b: *u8 = sys_mmap(PD_CAP)
170 let szp: *i64 = sys_mmap(PD_SPAN) as *i64
171 let n: i64 = pd_read(path, b, PD_CAP - 4, szp)
172 let c5: *i64 = sys_mmap(PD_SPAN) as *i64
173 var cnt: i64 = 0
174 var tot: i64 = 0
175 var i: i64 = 0
176 while i < n {
177 let le: i64 = pd_le(b, i, n)
178 if le > i { if (b[i] as i64) != PD_HASH {
179 tot = tot + 1
180 if pd_col(b, i, le, 5, c5) == 1 { if c5[1] - c5[0] == 1 { if (b[c5[0]] as i64) == ch { cnt = cnt + 1 } } }
181 } }
182 i = le + 1
183 }
184 totp[0] = tot
185 return cnt
186}
187// debt store: count rows whose status col3 == lit (open|eaten). status@3 in BOTH debt families.
188func pd_count_debt(dprefix: *u8, lit: *u8) -> i64 {
189 let b: *u8 = sys_mmap(PD_CAP)
190 let n: i64 = sts_load(dprefix, b, PD_CAP)
191 let c3: *i64 = sys_mmap(PD_SPAN) as *i64
192 var cnt: i64 = 0
193 var i: i64 = 0
194 while i < n {
195 let le: i64 = pd_le(b, i, n)
196 if pd_col(b, i, le, 3, c3) == 1 { if pd_lit_eq(b, c3[0], c3[1], lit) == 1 { cnt = cnt + 1 } }
197 i = le + 1
198 }
199 return cnt
200}
201// journal: count frames whose verb col1 == verb
202func pd_count_verb(q: *u8, n: i64, verb: *u8) -> i64 {
203 let cv: *i64 = sys_mmap(PD_SPAN) as *i64
204 var cnt: i64 = 0
205 var i: i64 = 0
206 while i < n {
207 let le: i64 = pd_le(q, i, n)
208 if pd_col(q, i, le, 1, cv) == 1 { if pd_lit_eq(q, cv[0], cv[1], verb) == 1 { cnt = cnt + 1 } }
209 i = le + 1
210 }
211 return cnt
212}
213func pd_first_kick(q: *u8, upto: i64, ws_s: i64, ws_e: i64) -> i64 {
214 let cv: *i64 = sys_mmap(PD_SPAN) as *i64
215 let cw: *i64 = sys_mmap(PD_SPAN) as *i64
216 var i: i64 = 0
217 while i < upto {
218 let le: i64 = pd_le(q, i, upto)
219 if pd_col(q, i, le, 1, cv) == 1 { if pd_lit_eq(q, cv[0], cv[1], "KICKOFF" as *u8) == 1 {
220 if pd_col(q, i, le, 2, cw) == 1 { if pd_span_eq(q, cw[0], cw[1], ws_s, ws_e) == 1 { return 0 } }
221 } }
222 i = le + 1
223 }
224 return 1
225}
226func pd_has_span(q: *u8, n: i64, verb: *u8, ws_s: i64, ws_e: i64) -> i64 {
227 let cv: *i64 = sys_mmap(PD_SPAN) as *i64
228 let cw: *i64 = sys_mmap(PD_SPAN) as *i64
229 var i: i64 = 0
230 while i < n {
231 let le: i64 = pd_le(q, i, n)
232 if pd_col(q, i, le, 1, cv) == 1 { if pd_lit_eq(q, cv[0], cv[1], verb) == 1 {
233 if pd_col(q, i, le, 2, cw) == 1 { if pd_span_eq(q, cw[0], cw[1], ws_s, ws_e) == 1 { return 1 } }
234 } }
235 i = le + 1
236 }
237 return 0
238}
239func pd_last(q: *u8, n: i64, ws_s: i64, ws_e: i64, ons: *i64) -> i64 {
240 let cw: *i64 = sys_mmap(PD_SPAN) as *i64
241 let c0: *i64 = sys_mmap(PD_SPAN) as *i64
242 let cn: *i64 = sys_mmap(PD_SPAN) as *i64
243 var last: i64 = 0 - 1
244 var i: i64 = 0
245 while i < n {
246 let le: i64 = pd_le(q, i, n)
247 if pd_col(q, i, le, 2, cw) == 1 { if pd_span_eq(q, cw[0], cw[1], ws_s, ws_e) == 1 {
248 if pd_col(q, i, le, 0, c0) == 1 { last = pd_atoi_span(q, c0[0], c0[1]) }
249 if pd_col(q, i, le, 4, cn) == 1 { ons[0] = cn[0]; ons[1] = cn[1] }
250 } }
251 i = le + 1
252 }
253 return last
254}
255// scoped-debt gate (R2a semantics): open debts gating ws = sev >= sevmin (global floor) OR scope-hits-ws.
256// schema-aware: legacy(col0 all-digits len>=8) sev@1 scope@2; v2 sev@2 scope@5; status@3 in both.
257func pd_row_legacy(q: *u8, ls: i64, le: i64, c0: *i64) -> i64 {
258 if pd_col(q, ls, le, 0, c0) == 0 { return 0 }
259 if c0[1] - c0[0] < 8 { return 0 }
260 var i: i64 = c0[0]
261 while i < c0[1] { let c: i64 = q[i] as i64; if c < 48 { return 0 } if c > 57 { return 0 } i = i + 1 }
262 return 1
263}
264func pd_scope_hits_ws(q: *u8, s: i64, e: i64, ws: *u8) -> i64 {
265 if pd_lit_eq(q, s, e, "global" as *u8) == 1 { return 1 }
266 if pd_lit_eq(q, s, e, ws) == 1 { return 1 }
267 var wl: i64 = 0
268 while ws[wl] != (0 as u8) { wl = wl + 1 }
269 let sl: i64 = e - s
270 if sl > 0 { if sl <= wl {
271 var i: i64 = 0
272 while i + sl <= wl { var j: i64 = 0; var ok: i64 = 1; while j < sl { if ws[i+j] != q[s+j] { ok = 0; j = sl } else { j = j + 1 } } if ok == 1 { return 1 } i = i + 1 }
273 } }
274 if wl > 0 { if wl <= sl {
275 var i2: i64 = s
276 while i2 + wl <= e { var j2: i64 = 0; var ok2: i64 = 1; while j2 < wl { if q[i2+j2] != ws[j2] { ok2 = 0; j2 = wl } else { j2 = j2 + 1 } } if ok2 == 1 { return 1 } i2 = i2 + 1 }
277 } }
278 return 0
279}
280func pd_debts_scoped_ws(dbuf: *u8, dn: i64, ws: *u8, sevmin: i64) -> i64 {
281 let c1: *i64 = sys_mmap(PD_SPAN) as *i64
282 let c2: *i64 = sys_mmap(PD_SPAN) as *i64
283 let c3: *i64 = sys_mmap(PD_SPAN) as *i64
284 var k: i64 = 0
285 var i: i64 = 0
286 while i < dn {
287 let le: i64 = pd_le(dbuf, i, dn)
288 if pd_col(dbuf, i, le, 3, c3) == 1 { if pd_lit_eq(dbuf, c3[0], c3[1], "open" as *u8) == 1 {
289 var gates: i64 = 0
290 var sevcol: i64 = 2
291 var scopecol: i64 = 5
292 if pd_row_legacy(dbuf, i, le, c1) == 1 { sevcol = 1; scopecol = 2 }
293 if pd_col(dbuf, i, le, sevcol, c1) == 1 { if pd_atoi_span(dbuf, c1[0], c1[1]) >= sevmin { gates = 1 } }
294 if gates == 0 { if pd_col(dbuf, i, le, scopecol, c2) == 1 { if pd_scope_hits_ws(dbuf, c2[0], c2[1], ws) == 1 { gates = 1 } } }
295 if gates == 1 { k = k + 1 }
296 } }
297 i = le + 1
298 }
299 return k
300}
301// lane tally across first-kickoff lanes: out[0]=lanes out[1]=done out[2]=active(work) out[3]=gated
302// out[4]=stalest-age(sec, among non-done) out[5]=stalest-ws-start out[6]=stalest-ws-end (into q)
303func pd_lane_tally(q: *u8, n: i64, dbuf: *u8, dn: i64, sevmin: i64, now: i64, wsb: *u8, out: *i64) -> i64 {
304 let cv: *i64 = sys_mmap(PD_SPAN) as *i64
305 let cw: *i64 = sys_mmap(PD_SPAN) as *i64
306 let ons: *i64 = sys_mmap(PD_SPAN) as *i64
307 var lanes: i64 = 0
308 var done: i64 = 0
309 var active: i64 = 0
310 var gated: i64 = 0
311 var stalest: i64 = 0 - 1
312 var sst: i64 = 0 - 1
313 var sen: i64 = 0 - 1
314 var i: i64 = 0
315 while i < n {
316 let le: i64 = pd_le(q, i, n)
317 if pd_col(q, i, le, 1, cv) == 1 { if pd_lit_eq(q, cv[0], cv[1], "KICKOFF" as *u8) == 1 {
318 if pd_col(q, i, le, 2, cw) == 1 { if pd_first_kick(q, i, cw[0], cw[1]) == 1 {
319 lanes = lanes + 1
320 if pd_has_span(q, n, "DONE" as *u8, cw[0], cw[1]) == 1 { done = done + 1 } else {
321 var wl: i64 = cw[1] - cw[0]
322 if wl > PD_SPAN * 16 - 2 { wl = PD_SPAN * 16 - 2 }
323 var wi: i64 = 0
324 while wi < wl { wsb[wi] = q[cw[0]+wi]; wi = wi + 1 }
325 wsb[wl] = 0 as u8
326 let kws: i64 = pd_debts_scoped_ws(dbuf, dn, wsb, sevmin)
327 if kws > 0 { gated = gated + 1 } else { active = active + 1 }
328 ons[0] = 0 - 1
329 let lt: i64 = pd_last(q, n, cw[0], cw[1], ons)
330 var age: i64 = now - lt
331 if age < 0 { age = 0 }
332 if age > stalest { stalest = age; sst = cw[0]; sen = cw[1] }
333 }
334 } }
335 } }
336 i = le + 1
337 }
338 out[0] = lanes
339 out[1] = done
340 out[2] = active
341 out[3] = gated
342 out[4] = stalest
343 out[5] = sst
344 out[6] = sen
345 return 0
346}
347// R indices filled by pd_compute
348const R_TOOLS: i64 = 0
349const R_CAPDONE: i64 = 1
350const R_CAPTOT: i64 = 2
351const R_RUNGS: i64 = 3
352const R_CRONS: i64 = 4
353const R_DAEMONS: i64 = 5
354const R_DOPEN: i64 = 6
355const R_DEATEN: i64 = 7
356const R_GATELOGS: i64 = 8
357const R_BUILDH: i64 = 9
358const R_OPSH: i64 = 10
359const R_RESILH: i64 = 11
360const R_TOTH: i64 = 12
361const R_VLOW: i64 = 13
362const R_VHIGH: i64 = 14
363const R_ENERGYCC: i64 = 15
364const R_TOKENS: i64 = 16
365const R_LANES: i64 = 17
366const R_LDONE: i64 = 18
367const R_LACTIVE: i64 = 19
368const R_LGATED: i64 = 20
369const R_STALEST: i64 = 21
370const R_UPH: i64 = 22
371const R_USDHR: i64 = 23
372const R_USDMKT: i64 = 24
373const R_SEVMIN: i64 = 25
374// fills R (32 slots). roiok[0]=1 if roi store seeded. returns 0.
375func pd_compute(jr: *u8, dp: *u8, fr: *u8, rp: *u8, R: *i64, roiok: *i64) -> i64 {
376 roiok[0] = pd_store_seeded(rp)
377 let hpt: i64 = pd_cfg(rp, "hours-per-tool" as *u8, 4)
378 let hpc: i64 = pd_cfg(rp, "hours-per-cron-month" as *u8, 2)
379 let hpd: i64 = pd_cfg(rp, "hours-per-daemon-month" as *u8, 1)
380 let mo: i64 = pd_cfg(rp, "months-operating" as *u8, 4)
381 let uhr: i64 = pd_cfg(rp, "usd-per-hour" as *u8, 75)
382 let umk: i64 = pd_cfg(rp, "usd-per-hour-market" as *u8, 150)
383 let nw: i64 = pd_cfg(rp, "nas-watts" as *u8, 40)
384 let lw: i64 = pd_cfg(rp, "laptop-watts" as *u8, 65)
385 let uph: i64 = pd_cfg(rp, "uptime-hours" as *u8, PD_MAGIC_2880)
386 let kcc: i64 = pd_cfg(rp, "kwh-cost-cents" as *u8, 12)
387 let tpb: i64 = pd_cfg(rp, "tokens-saved-per-boot" as *u8, PD_MAGIC_30000)
388 let boots: i64 = pd_cfg(rp, "boots" as *u8, 20)
389 let gl: i64 = pd_cfg(rp, "gate-logs" as *u8, 0)
390 let hpg: i64 = pd_cfg(rp, "hours-per-gate" as *u8, 1)
391 let rec: i64 = pd_cfg(rp, "recoveries" as *u8, 0)
392 let hpr: i64 = pd_cfg(rp, "hours-per-recovery" as *u8, 8)
393 let sevmin: i64 = pd_cfg(rp, "global-sev-min" as *u8, 6)
394 // MEASURED counts
395 let tools: i64 = pd_count_noncomment("tool_allowlist.conf" as *u8)
396 let crons: i64 = pd_count_noncomment("cron.reg" as *u8)
397 let daemons: i64 = pd_count_noncomment("daemons.reg" as *u8)
398 let totp: *i64 = sys_mmap(PD_SPAN) as *i64
399 let capdone: i64 = pd_scan_frontier(fr, 68, totp)
400 let captot: i64 = totp[0]
401 let dopen: i64 = pd_count_debt(dp, "open" as *u8)
402 let deaten: i64 = pd_count_debt(dp, "eaten" as *u8)
403 let q: *u8 = sys_mmap(PD_JCAP)
404 let jsz: *i64 = sys_mmap(PD_SPAN) as *i64
405 let jn: i64 = pd_read(jr, q, PD_JCAP - 4, jsz)
406 let rungs: i64 = pd_count_verb(q, jn, "DONE" as *u8)
407 let dbuf: *u8 = sys_mmap(PD_CAP)
408 let dn: i64 = sts_load(dp, dbuf, PD_CAP)
409 let now: i64 = sys_now_realtime_sec()
410 let wsb: *u8 = sys_mmap(PD_SPAN * 16)
411 let lt: *i64 = sys_mmap(PD_SPAN * 2) as *i64
412 pd_lane_tally(q, jn, dbuf, dn, sevmin, now, wsb, lt)
413 // DERIVED (count x declared rate)
414 let buildh: i64 = tools * hpt
415 let opsh: i64 = crons * hpc * mo + daemons * hpd * mo
416 let resilh: i64 = rec * hpr + gl * hpg
417 let toth: i64 = buildh + opsh + resilh
418 let vlow: i64 = toth * uhr
419 let vhigh: i64 = toth * umk
420 let energycc: i64 = (nw + lw) * uph * kcc / 1000
421 let tokens: i64 = tpb * boots
422 R[R_TOOLS] = tools
423 R[R_CAPDONE] = capdone
424 R[R_CAPTOT] = captot
425 R[R_RUNGS] = rungs
426 R[R_CRONS] = crons
427 R[R_DAEMONS] = daemons
428 R[R_DOPEN] = dopen
429 R[R_DEATEN] = deaten
430 R[R_GATELOGS] = gl
431 R[R_BUILDH] = buildh
432 R[R_OPSH] = opsh
433 R[R_RESILH] = resilh
434 R[R_TOTH] = toth
435 R[R_VLOW] = vlow
436 R[R_VHIGH] = vhigh
437 R[R_ENERGYCC] = energycc
438 R[R_TOKENS] = tokens
439 R[R_LANES] = lt[0]
440 R[R_LDONE] = lt[1]
441 R[R_LACTIVE] = lt[2]
442 R[R_LGATED] = lt[3]
443 R[R_STALEST] = lt[4]
444 R[R_UPH] = uph
445 R[R_USDHR] = uhr
446 R[R_USDMKT] = umk
447 R[R_SEVMIN] = sevmin
448 return 0
449}
450// emit the ROI JSON block into out at o; returns new o. roiok gates fabricated numbers (fail-closed).
451func pd_emit_roi(out: *u8, o: i64, R: *i64, roiok: i64) -> i64 {
452 o = pd_cat(out, o, "\"roi\":" as *u8)
453 if roiok == 0 { o = pd_cat(out, o, "{\"status\":\"unseeded\",\"hint\":\"run nx_pm_dashboard seedroi -- no figures emitted without declared rates\"}" as *u8); return o }
454 o = pd_cat(out, o, "{\"disclaimer\":\"estimates = MEASURED counts x declared CONFIG rates (edit via seedroi); no figure without a real count and a stated rate\",\"measured\":{\"mcp_tools\":" as *u8)
455 o = pd_catn(out, o, R[R_TOOLS])
456 o = pd_cat(out, o, ",\"capabilities_done\":" as *u8)
457 o = pd_catn(out, o, R[R_CAPDONE])
458 o = pd_cat(out, o, ",\"capabilities_total\":" as *u8)
459 o = pd_catn(out, o, R[R_CAPTOT])
460 o = pd_cat(out, o, ",\"rungs_done\":" as *u8)
461 o = pd_catn(out, o, R[R_RUNGS])
462 o = pd_cat(out, o, ",\"crons\":" as *u8)
463 o = pd_catn(out, o, R[R_CRONS])
464 o = pd_cat(out, o, ",\"daemons\":" as *u8)
465 o = pd_catn(out, o, R[R_DAEMONS])
466 o = pd_cat(out, o, ",\"gate_logs\":" as *u8)
467 o = pd_catn(out, o, R[R_GATELOGS])
468 o = pd_cat(out, o, ",\"debts_open\":" as *u8)
469 o = pd_catn(out, o, R[R_DOPEN])
470 o = pd_cat(out, o, ",\"debts_eaten\":" as *u8)
471 o = pd_catn(out, o, R[R_DEATEN])
472 o = pd_cat(out, o, "},\"lines\":[" as *u8)
473 o = pd_cat(out, o, "{\"bucket\":\"build\",\"basis\":\"mcp_tools x hours-per-tool\",\"hours\":" as *u8)
474 o = pd_catn(out, o, R[R_BUILDH])
475 o = pd_cat(out, o, ",\"tag\":\"ESTIMATE\"},{\"bucket\":\"operate\",\"basis\":\"(crons x hpc + daemons x hpd) x months\",\"hours\":" as *u8)
476 o = pd_catn(out, o, R[R_OPSH])
477 o = pd_cat(out, o, ",\"tag\":\"ESTIMATE\"},{\"bucket\":\"resilience\",\"basis\":\"recoveries x hpr + gates x hpg\",\"hours\":" as *u8)
478 o = pd_catn(out, o, R[R_RESILH])
479 o = pd_cat(out, o, ",\"tag\":\"ESTIMATE-soft\"}],\"totals\":{\"engineer_hours\":" as *u8)
480 o = pd_catn(out, o, R[R_TOTH])
481 o = pd_cat(out, o, ",\"value_usd_low\":" as *u8)
482 o = pd_catn(out, o, R[R_VLOW])
483 o = pd_cat(out, o, ",\"value_usd_high\":" as *u8)
484 o = pd_catn(out, o, R[R_VHIGH])
485 o = pd_cat(out, o, ",\"energy_cost_usd\":" as *u8)
486 o = pd_catn(out, o, R[R_ENERGYCC] / 100)
487 o = pd_cat(out, o, "." as *u8)
488 o = pd_cat_cc(out, o, R[R_ENERGYCC])
489 o = pd_cat(out, o, ",\"tokens_saved\":" as *u8)
490 o = pd_catn(out, o, R[R_TOKENS])
491 o = pd_cat(out, o, ",\"net_usd_low\":" as *u8)
492 o = pd_catn(out, o, R[R_VLOW] - R[R_ENERGYCC] / 100)
493 o = pd_cat(out, o, "},\"confidence\":\"rates conservative + editable; energy MEASURED-basis (watts x uptime); tokens ASSUMPTION (token_efficiency.log absent -- seat metering S3)\"}" as *u8)
494 return o
495}
496func pd_seedroi(prefix: *u8) -> i64 {
497 let b: *u8 = sys_mmap(PD_CAP)
498 var o: i64 = 0
499 o = pd_cat(b, o, "0\tCONFIG\thours-per-tool\t4\teng-hours-to-design-build-gate-expose-one-mcp-tool\n" as *u8)
500 o = pd_cat(b, o, "0\tCONFIG\thours-per-cron-month\t2\tmanual-ops-hours-per-month-each-cron-eliminates\n" as *u8)
501 o = pd_cat(b, o, "0\tCONFIG\thours-per-daemon-month\t1\tmanual-ops-hours-per-month-each-daemon-eliminates\n" as *u8)
502 o = pd_cat(b, o, "0\tCONFIG\tmonths-operating\t4\tmonths-savings-accrued-conservative\n" as *u8)
503 o = pd_cat(b, o, "0\tCONFIG\tusd-per-hour\t75\tloaded-eng-rate-conservative\n" as *u8)
504 o = pd_cat(b, o, "0\tCONFIG\tusd-per-hour-market\t150\tmarket-eng-rate-high-estimate\n" as *u8)
505 o = pd_cat(b, o, "0\tCONFIG\tnas-watts\t40\tnas-draw-w\n" as *u8)
506 o = pd_cat(b, o, "0\tCONFIG\tlaptop-watts\t65\tlaptop-draw-w\n" as *u8)
507 o = pd_cat(b, o, "0\tCONFIG\tuptime-hours\t2880\t4mo-x-720h\n" as *u8)
508 o = pd_cat(b, o, "0\tCONFIG\tkwh-cost-cents\t12\tusd-0-12-per-kwh\n" as *u8)
509 o = pd_cat(b, o, "0\tCONFIG\ttokens-saved-per-boot\t30000\tseat-boot-delta-ASSUMPTION-token-log-absent\n" as *u8)
510 o = pd_cat(b, o, "0\tCONFIG\tboots\t20\tsessions-conservative\n" as *u8)
511 o = pd_cat(b, o, "0\tCONFIG\tgate-logs\t39\tquality-gate-logs-measured-2026-07-18\n" as *u8)
512 o = pd_cat(b, o, "0\tCONFIG\thours-per-gate\t1\trework-hours-a-gate-prevents-soft\n" as *u8)
513 o = pd_cat(b, o, "0\tCONFIG\trecoveries\t4\tzero-loss-crash-recoveries-this-program\n" as *u8)
514 o = pd_cat(b, o, "0\tCONFIG\thours-per-recovery\t8\trebuild-hours-a-clean-recovery-avoids\n" as *u8)
515 o = pd_cat(b, o, "0\tCONFIG\tglobal-sev-min\t6\tscoped-debt-gate-floor-mirror\n" as *u8)
516 o = pd_cat(b, o, "0\tRESEARCH\tdora-space-dxcore4\t0\tbenchmark ROI derivation vs DORA plus SPACE plus DX-Core-4 dev-productivity frameworks\n" as *u8)
517 o = pd_cat(b, o, "0\tRESEARCH\tvsm-platforms\t0\tValue-Stream-Mgmt (Jellyfish, Faros AI, Swarmia, LinearB) engineering-to-business ROI mapping\n" as *u8)
518 o = pd_cat(b, o, "0\tRESEARCH\tsoftware-carbon-intensity\t0\tGreen-Software SCI spec plus FinOps: real per-workload energy and CO2 (replace flat watt estimate)\n" as *u8)
519 o = pd_cat(b, o, "0\tRESEARCH\tevidence-based-scheduling\t0\tMonte-Carlo velocity: replace point ROI estimates with distributions and confidence bands\n" as *u8)
520 let cnt: i64 = sts_seed(prefix, b, o)
521 if cnt < 0 { pd_werr("PD-FAIL seedroi commit error\n" as *u8); return 1 }
522 let m: *u8 = sys_mmap(64)
523 var mo: i64 = pd_cat(m, 0, "ROI-SEEDED rows=" as *u8)
524 mo = pd_catn(m, mo, cnt)
525 m[mo] = PD_NL as u8
526 mo = mo + 1
527 sys_write(1, m, mo)
528 return 0
529}
530// print the RESEARCH rows (slug + text) as JSON array items into out at o
531func pd_emit_research(out: *u8, o: i64, rp: *u8) -> i64 {
532 let b: *u8 = sys_mmap(PD_CAP)
533 let n: i64 = sts_load(rp, b, PD_CAP)
534 let c1: *i64 = sys_mmap(PD_SPAN) as *i64
535 let c2: *i64 = sys_mmap(PD_SPAN) as *i64
536 let c4: *i64 = sys_mmap(PD_SPAN) as *i64
537 var first: i64 = 1
538 var i: i64 = 0
539 while i < n {
540 let le: i64 = pd_le(b, i, n)
541 if pd_col(b, i, le, 1, c1) == 1 { if pd_lit_eq(b, c1[0], c1[1], "RESEARCH" as *u8) == 1 {
542 if first == 0 { o = pd_cat(out, o, "," as *u8) }
543 first = 0
544 o = pd_cat(out, o, "{\"slug\":\"" as *u8)
545 if pd_col(b, i, le, 2, c2) == 1 { o = pd_cat_esc(out, o, b, c2[0], c2[1]) }
546 o = pd_cat(out, o, "\",\"opp\":\"" as *u8)
547 if pd_col(b, i, le, 4, c4) == 1 { o = pd_cat_esc(out, o, b, c4[0], c4[1]) }
548 o = pd_cat(out, o, "\"}" as *u8)
549 } }
550 i = le + 1
551 }
552 return o
553}
554func main(argc: i64, argv: *i64) -> i64 {
555 if argc < 2 { pd_werr("usage: nx_pm_dashboard {seedroi [roiprefix] | roi [roiprefix] [frontier] [journal] [debtprefix] | exec [journal] [debtprefix] [frontier] [roiprefix] | page [outpath] [journal] [debtprefix] [frontier] [roiprefix] [cycleprefix]}\n" as *u8); sys_exit(PD_EXIT_USAGE); return PD_EXIT_USAGE }
556 let verb: *u8 = argv[1] as *u8
557 let vl: i64 = pd_vlen(verb)
558 if pd_lit_eq(verb, 0, vl, "seedroi" as *u8) == 1 {
559 var rp: *u8 = "knowledge/store/roi-" as *u8
560 if argc > 2 { rp = argv[2] as *u8 }
561 let rc: i64 = pd_seedroi(rp)
562 sys_exit(rc)
563 return rc
564 }
565 if pd_lit_eq(verb, 0, vl, "roi" as *u8) == 1 {
566 var rp2: *u8 = "knowledge/store/roi-" as *u8
567 var fr: *u8 = "knowledge/registry/frontier_queue.tsv" as *u8
568 var jr: *u8 = "knowledge/status/ws_sync.jrnl" as *u8
569 var dp: *u8 = "knowledge/store/debt-" as *u8
570 if argc > 2 { rp2 = argv[2] as *u8 }
571 if argc > 3 { fr = argv[3] as *u8 }
572 if argc > 4 { jr = argv[4] as *u8 }
573 if argc > 5 { dp = argv[5] as *u8 }
574 let R: *i64 = sys_mmap(PD_SPAN * 4) as *i64
575 let roiok: *i64 = sys_mmap(PD_SPAN) as *i64
576 pd_compute(jr, dp, fr, rp2, R, roiok)
577 let out: *u8 = sys_mmap(PD_CAP)
578 var o: i64 = 0
579 o = pd_cat(out, o, "{" as *u8)
580 o = pd_emit_roi(out, o, R, roiok[0])
581 o = pd_cat(out, o, "}" as *u8)
582 out[o] = PD_NL as u8
583 o = o + 1
584 sys_write(1, out, o)
585 sys_exit(0)
586 return 0
587 }
588 if pd_lit_eq(verb, 0, vl, "exec" as *u8) == 1 {
589 var jr2: *u8 = "knowledge/status/ws_sync.jrnl" as *u8
590 var dp2: *u8 = "knowledge/store/debt-" as *u8
591 var fr2: *u8 = "knowledge/registry/frontier_queue.tsv" as *u8
592 var rp3: *u8 = "knowledge/store/roi-" as *u8
593 if argc > 2 { jr2 = argv[2] as *u8 }
594 if argc > 3 { dp2 = argv[3] as *u8 }
595 if argc > 4 { fr2 = argv[4] as *u8 }
596 if argc > 5 { rp3 = argv[5] as *u8 }
597 let R: *i64 = sys_mmap(PD_SPAN * 4) as *i64
598 let roiok: *i64 = sys_mmap(PD_SPAN) as *i64
599 pd_compute(jr2, dp2, fr2, rp3, R, roiok)
600 let now: i64 = sys_now_realtime_sec()
601 let out: *u8 = sys_mmap(PD_CAP)
602 var o: i64 = 0
603 o = pd_cat(out, o, "{\"exec\":{\"epoch\":" as *u8)
604 o = pd_catn(out, o, now)
605 o = pd_cat(out, o, ",\"derivation\":\"artifacts-only: journal+debt+frontier+roi-config\",\"portfolio\":{\"lanes\":" as *u8)
606 o = pd_catn(out, o, R[R_LANES])
607 o = pd_cat(out, o, ",\"done\":" as *u8)
608 o = pd_catn(out, o, R[R_LDONE])
609 o = pd_cat(out, o, ",\"active\":" as *u8)
610 o = pd_catn(out, o, R[R_LACTIVE])
611 o = pd_cat(out, o, ",\"debt_gated\":" as *u8)
612 o = pd_catn(out, o, R[R_LGATED])
613 o = pd_cat(out, o, ",\"roadmap_done\":" as *u8)
614 o = pd_catn(out, o, R[R_CAPDONE])
615 o = pd_cat(out, o, ",\"roadmap_total\":" as *u8)
616 o = pd_catn(out, o, R[R_CAPTOT])
617 o = pd_cat(out, o, "},\"attention\":{\"sev_min\":" as *u8)
618 o = pd_catn(out, o, R[R_SEVMIN])
619 o = pd_cat(out, o, ",\"debts_open\":" as *u8)
620 o = pd_catn(out, o, R[R_DOPEN])
621 o = pd_cat(out, o, ",\"debts_eaten\":" as *u8)
622 o = pd_catn(out, o, R[R_DEATEN])
623 o = pd_cat(out, o, ",\"stalest_active_age_min\":" as *u8)
624 var sm: i64 = R[R_STALEST]
625 if sm < 0 { sm = 0 }
626 o = pd_catn(out, o, sm / 60)
627 o = pd_cat(out, o, "},\"research_opps\":[" as *u8)
628 o = pd_emit_research(out, o, rp3)
629 o = pd_cat(out, o, "]," as *u8)
630 o = pd_emit_roi(out, o, R, roiok[0])
631 o = pd_cat(out, o, "}}" as *u8)
632 out[o] = PD_NL as u8
633 o = o + 1
634 sys_write(1, out, o)
635 sys_exit(0)
636 return 0
637 }
638 if pd_lit_eq(verb, 0, vl, "page" as *u8) == 1 {
639 var op: *u8 = 0 as *u8
640 var jr3: *u8 = "knowledge/status/ws_sync.jrnl" as *u8
641 var dp3: *u8 = "knowledge/store/debt-" as *u8
642 var fr3: *u8 = "knowledge/registry/frontier_queue.tsv" as *u8
643 var rp4: *u8 = "knowledge/store/roi-" as *u8
644 if argc > 2 { let a2: *u8 = argv[2] as *u8; if a2[0] != (45 as u8) { op = a2 } }
645 if argc > 3 { jr3 = argv[3] as *u8 }
646 if argc > 4 { dp3 = argv[4] as *u8 }
647 if argc > 5 { fr3 = argv[5] as *u8 }
648 if argc > 6 { rp4 = argv[6] as *u8 }
649 let R: *i64 = sys_mmap(PD_SPAN * 4) as *i64
650 let roiok: *i64 = sys_mmap(PD_SPAN) as *i64
651 pd_compute(jr3, dp3, fr3, rp4, R, roiok)
652 let now: i64 = sys_now_realtime_sec()
653 let q: *u8 = sys_mmap(PD_JCAP)
654 let jsz: *i64 = sys_mmap(PD_SPAN) as *i64
655 let jn: i64 = pd_read(jr3, q, PD_JCAP - 4, jsz)
656 let sev: i64 = R[R_SEVMIN]
657 let act: i64 = pd_cfg(rp4, "standup-active-secs" as *u8, PD_MAGIC_7200)
658 let dbuf: *u8 = sys_mmap(PD_CAP)
659 let dn: i64 = sts_load(dp3, dbuf, PD_CAP)
660 let out: *u8 = sys_mmap(PD_CAP)
661 var o: i64 = 0
662 o = pd_cat(out, o, "<html><head><title>Nishi PM Dashboard</title><style>body{background:black;color:gainsboro;font:15px sans-serif;margin:24px;max-width:1100px}h1{color:white}h2{color:deepskyblue;border-bottom:1px solid dimgray;margin-top:28px}table{border-collapse:collapse;width:100%}td,th{border-bottom:1px solid dimgray;padding:5px 9px;text-align:left}th{color:gray}.a{color:springgreen}.s{color:orange}.d{color:gray}.g{color:tomato}.big{font-size:30px;color:white;margin:8px 0}.note{color:gray;font-size:12px}</style></head><body><h1>Nishi PM Dashboard</h1><p class=d>epoch " as *u8)
663 o = pd_catn(out, o, now)
664 o = pd_cat(out, o, " · journal " as *u8)
665 o = pd_catn(out, o, jsz[0])
666 o = pd_cat(out, o, "B window " as *u8)
667 o = pd_catn(out, o, jn)
668 o = pd_cat(out, o, "B · derivation artifacts-only</p>" as *u8)
669 // EXECUTIVE
670 o = pd_cat(out, o, "<h2>EXECUTIVE — return on investment</h2>" as *u8)
671 if roiok[0] == 0 { o = pd_cat(out, o, "<p class=g>ROI unseeded — run nx_pm_dashboard seedroi (no figures without declared rates)</p>" as *u8) } else {
672 o = pd_cat(out, o, "<div class=big>USD " as *u8)
673 o = pd_catn(out, o, R[R_VLOW])
674 o = pd_cat(out, o, " – " as *u8)
675 o = pd_catn(out, o, R[R_VHIGH])
676 o = pd_cat(out, o, "</div><p>labor-equivalent value delivered = " as *u8)
677 o = pd_catn(out, o, R[R_TOTH])
678 o = pd_cat(out, o, " engineer-hours (at USD " as *u8)
679 o = pd_catn(out, o, R[R_USDHR])
680 o = pd_cat(out, o, "–" as *u8)
681 o = pd_catn(out, o, R[R_USDMKT])
682 o = pd_cat(out, o, "/h) · against USD " as *u8)
683 o = pd_catn(out, o, R[R_ENERGYCC] / 100)
684 o = pd_cat(out, o, "." as *u8)
685 o = pd_cat_cc(out, o, R[R_ENERGYCC])
686 o = pd_cat(out, o, " energy invested</p>" as *u8)
687 o = pd_cat(out, o, "<table><tr><th>bucket</th><th>basis (count x rate)</th><th>engineer-hours</th><th>tag</th></tr>" as *u8)
688 o = pd_cat(out, o, "<tr><td>build</td><td>" as *u8)
689 o = pd_catn(out, o, R[R_TOOLS])
690 o = pd_cat(out, o, " mcp-tools x hours-per-tool</td><td>" as *u8)
691 o = pd_catn(out, o, R[R_BUILDH])
692 o = pd_cat(out, o, "</td><td class=a>ESTIMATE</td></tr>" as *u8)
693 o = pd_cat(out, o, "<tr><td>operate</td><td>" as *u8)
694 o = pd_catn(out, o, R[R_CRONS])
695 o = pd_cat(out, o, " crons + " as *u8)
696 o = pd_catn(out, o, R[R_DAEMONS])
697 o = pd_cat(out, o, " daemons x months</td><td>" as *u8)
698 o = pd_catn(out, o, R[R_OPSH])
699 o = pd_cat(out, o, "</td><td class=a>ESTIMATE</td></tr>" as *u8)
700 o = pd_cat(out, o, "<tr><td>resilience</td><td>recoveries + " as *u8)
701 o = pd_catn(out, o, R[R_GATELOGS])
702 o = pd_cat(out, o, " gates</td><td>" as *u8)
703 o = pd_catn(out, o, R[R_RESILH])
704 o = pd_cat(out, o, "</td><td class=s>ESTIMATE-soft</td></tr>" as *u8)
705 o = pd_cat(out, o, "<tr><td><b>total</b></td><td>tokens saved " as *u8)
706 o = pd_catn(out, o, R[R_TOKENS])
707 o = pd_cat(out, o, " (context)</td><td><b>" as *u8)
708 o = pd_catn(out, o, R[R_TOTH])
709 o = pd_cat(out, o, "</b></td><td></td></tr></table>" as *u8)
710 o = pd_cat(out, o, "<p class=note>DISCLAIMER: estimates = MEASURED counts x declared CONFIG rates (edit via seedroi). Energy is MEASURED-basis (watts x uptime); tokens ASSUMPTION (token metering lands in seat-system S3). No figure exists without a real count and a stated rate.</p>" as *u8)
711 }
712 o = pd_cat(out, o, "<p>portfolio: " as *u8)
713 o = pd_catn(out, o, R[R_LANES])
714 o = pd_cat(out, o, " lanes (" as *u8)
715 o = pd_catn(out, o, R[R_LDONE])
716 o = pd_cat(out, o, " done / " as *u8)
717 o = pd_catn(out, o, R[R_LACTIVE])
718 o = pd_cat(out, o, " active / " as *u8)
719 o = pd_catn(out, o, R[R_LGATED])
720 o = pd_cat(out, o, " debt-gated) · roadmap " as *u8)
721 o = pd_catn(out, o, R[R_CAPDONE])
722 o = pd_cat(out, o, "/" as *u8)
723 o = pd_catn(out, o, R[R_CAPTOT])
724 o = pd_cat(out, o, " · " as *u8)
725 o = pd_catn(out, o, R[R_TOOLS])
726 o = pd_cat(out, o, " mcp-tools · " as *u8)
727 o = pd_catn(out, o, R[R_DAEMONS])
728 o = pd_cat(out, o, " daemons · " as *u8)
729 o = pd_catn(out, o, R[R_CRONS])
730 o = pd_cat(out, o, " crons</p>" as *u8)
731 // MANAGEMENT
732 o = pd_cat(out, o, "<h2>MANAGEMENT — feedback & decisions</h2><ul>" as *u8)
733 o = pd_cat(out, o, "<li>debt burn: <b>" as *u8)
734 o = pd_catn(out, o, R[R_DOPEN])
735 o = pd_cat(out, o, "</b> open / " as *u8)
736 o = pd_catn(out, o, R[R_DEATEN])
737 o = pd_cat(out, o, " eaten · gate floor sev " as *u8)
738 o = pd_catn(out, o, sev)
739 o = pd_cat(out, o, "</li><li>phase mix: " as *u8)
740 o = pd_catn(out, o, R[R_LDONE])
741 o = pd_cat(out, o, " done / " as *u8)
742 o = pd_catn(out, o, R[R_LACTIVE])
743 o = pd_cat(out, o, " active / <span class=g>" as *u8)
744 o = pd_catn(out, o, R[R_LGATED])
745 o = pd_cat(out, o, " debt-gated</span></li></ul>" as *u8)
746 o = pd_cat(out, o, "<p class=note>top open debts at or above gate floor:</p><table><tr><th>sev</th><th>scope</th><th>debt</th></tr>" as *u8)
747 // list up to 4 gating debt rows (sev>=sevmin)
748 let c1: *i64 = sys_mmap(PD_SPAN) as *i64
749 let c2: *i64 = sys_mmap(PD_SPAN) as *i64
750 let c3: *i64 = sys_mmap(PD_SPAN) as *i64
751 let c4: *i64 = sys_mmap(PD_SPAN) as *i64
752 var shown: i64 = 0
753 var di: i64 = 0
754 while di < dn {
755 let le: i64 = pd_le(dbuf, di, dn)
756 if shown < 4 { if pd_col(dbuf, di, le, 3, c3) == 1 { if pd_lit_eq(dbuf, c3[0], c3[1], "open" as *u8) == 1 {
757 var sevcol: i64 = 2
758 var scopecol: i64 = 5
759 var notecol: i64 = 6
760 if pd_row_legacy(dbuf, di, le, c1) == 1 { sevcol = 1; scopecol = 2; notecol = 4 }
761 var sv: i64 = 0
762 if pd_col(dbuf, di, le, sevcol, c1) == 1 { sv = pd_atoi_span(dbuf, c1[0], c1[1]) }
763 if sv >= sev {
764 o = pd_cat(out, o, "<tr><td class=g>" as *u8)
765 o = pd_catn(out, o, sv)
766 o = pd_cat(out, o, "</td><td>" as *u8)
767 if pd_col(dbuf, di, le, scopecol, c2) == 1 { o = pd_cat_esc_html(out, o, dbuf, c2[0], c2[1]) }
768 o = pd_cat(out, o, "</td><td>" as *u8)
769 if pd_col(dbuf, di, le, notecol, c4) == 1 {
770 var ne: i64 = c4[1]
771 if ne - c4[0] > 90 { ne = c4[0] + 90 }
772 o = pd_cat_esc_html(out, o, dbuf, c4[0], ne)
773 }
774 o = pd_cat(out, o, "</td></tr>" as *u8)
775 shown = shown + 1
776 }
777 } } }
778 di = le + 1
779 }
780 o = pd_cat(out, o, "</table>" as *u8)
781 // OPERATIONS -- live in-progress table (like standup)
782 o = pd_cat(out, o, "<h2>OPERATIONS — in progress now</h2><table><tr><th>workstream</th><th>phase</th><th>live</th><th>age-min</th><th>last callout</th></tr>" as *u8)
783 let cv: *i64 = sys_mmap(PD_SPAN) as *i64
784 let cw: *i64 = sys_mmap(PD_SPAN) as *i64
785 let ons: *i64 = sys_mmap(PD_SPAN) as *i64
786 let wsb: *u8 = sys_mmap(PD_SPAN * 16)
787 var i4: i64 = 0
788 while i4 < jn {
789 let le: i64 = pd_le(q, i4, jn)
790 if pd_col(q, i4, le, 1, cv) == 1 { if pd_lit_eq(q, cv[0], cv[1], "KICKOFF" as *u8) == 1 {
791 if pd_col(q, i4, le, 2, cw) == 1 { if pd_first_kick(q, i4, cw[0], cw[1]) == 1 {
792 if pd_has_span(q, jn, "DONE" as *u8, cw[0], cw[1]) == 0 {
793 ons[0] = 0 - 1
794 let lt2: i64 = pd_last(q, jn, cw[0], cw[1], ons)
795 var wl: i64 = cw[1] - cw[0]
796 if wl > PD_SPAN * 16 - 2 { wl = PD_SPAN * 16 - 2 }
797 var wi: i64 = 0
798 while wi < wl { wsb[wi] = q[cw[0]+wi]; wi = wi + 1 }
799 wsb[wl] = 0 as u8
800 let kws: i64 = pd_debts_scoped_ws(dbuf, dn, wsb, sev)
801 var age: i64 = now - lt2
802 if age < 0 { age = 0 }
803 o = pd_cat(out, o, "<tr><td><b>" as *u8)
804 o = pd_cat_esc_html(out, o, q, cw[0], cw[1])
805 o = pd_cat(out, o, "</b></td><td>" as *u8)
806 if kws > 0 { o = pd_cat(out, o, "<span class=g>DEBT-GATED</span>" as *u8) } else { o = pd_cat(out, o, "WORK" as *u8) }
807 o = pd_cat(out, o, "</td><td>" as *u8)
808 if age <= act { o = pd_cat(out, o, "<span class=a>ACTIVE</span>" as *u8) } else { o = pd_cat(out, o, "<span class=s>STALE</span>" as *u8) }
809 o = pd_cat(out, o, "</td><td>" as *u8)
810 o = pd_catn(out, o, age / 60)
811 o = pd_cat(out, o, "</td><td>" as *u8)
812 if ons[0] >= 0 { o = pd_cat_esc_html(out, o, q, ons[0], ons[1]) }
813 o = pd_cat(out, o, "</td></tr>" as *u8)
814 }
815 } }
816 } }
817 i4 = le + 1
818 }
819 o = pd_cat(out, o, "</table>" as *u8)
820 // RESEARCH -- beyond-SOTA opps
821 o = pd_cat(out, o, "<h2>RESEARCH — beyond SOTA (fetch targets)</h2><ul>" as *u8)
822 let rb: *u8 = sys_mmap(PD_CAP)
823 let rn: i64 = sts_load(rp4, rb, PD_CAP)
824 let rc1: *i64 = sys_mmap(PD_SPAN) as *i64
825 let rc4: *i64 = sys_mmap(PD_SPAN) as *i64
826 var ri: i64 = 0
827 while ri < rn {
828 let le: i64 = pd_le(rb, ri, rn)
829 if pd_col(rb, ri, le, 1, rc1) == 1 { if pd_lit_eq(rb, rc1[0], rc1[1], "RESEARCH" as *u8) == 1 {
830 o = pd_cat(out, o, "<li>" as *u8)
831 if pd_col(rb, ri, le, 4, rc4) == 1 { o = pd_cat_esc_html(out, o, rb, rc4[0], rc4[1]) }
832 o = pd_cat(out, o, "</li>" as *u8)
833 } }
834 ri = le + 1
835 }
836 o = pd_cat(out, o, "</ul>" as *u8)
837 // GOVERNANCE -- clear RACI (live from the registry) + maturity + organized nav (not random)
838 o = pd_cat(out, o, "<h2>GOVERNANCE — RACI & maturity</h2><table><tr><th>role</th><th>RACI (A=accountable R=responsible C=consulted I=informed)</th></tr>" as *u8)
839 let rt: *u8 = sys_mmap(PD_CAP)
840 let rtsz: *i64 = sys_mmap(PD_SPAN) as *i64
841 let rtn: i64 = pd_read("knowledge/registry/nishi_raci.tsv" as *u8, rt, PD_CAP - 4, rtsz)
842 let rrole: *i64 = sys_mmap(PD_SPAN) as *i64
843 let ract: *i64 = sys_mmap(PD_SPAN) as *i64
844 let rlet: *i64 = sys_mmap(PD_SPAN) as *i64
845 var rti: i64 = 0
846 var racishown: i64 = 0
847 while rti < rtn {
848 let le: i64 = pd_le(rt, rti, rtn)
849 if le > rti { if (rt[rti] as i64) != PD_HASH {
850 if pd_col(rt, rti, le, 1, ract) == 1 { if pd_lit_eq(rt, ract[0], ract[1], "pm-oversight" as *u8) == 1 {
851 o = pd_cat(out, o, "<tr><td><b>" as *u8)
852 if pd_col(rt, rti, le, 0, rrole) == 1 { o = pd_cat_esc_html(out, o, rt, rrole[0], rrole[1]) }
853 o = pd_cat(out, o, "</b></td><td>" as *u8)
854 if pd_col(rt, rti, le, 2, rlet) == 1 { o = pd_cat_esc_html(out, o, rt, rlet[0], rlet[1]) }
855 o = pd_cat(out, o, "</td></tr>" as *u8)
856 racishown = racishown + 1
857 } }
858 } }
859 rti = le + 1
860 }
861 if racishown == 0 { o = pd_cat(out, o, "<tr><td colspan=2 class=s>no pm-oversight RACI rows found in nishi_raci.tsv</td></tr>" as *u8) }
862 o = pd_cat(out, o, "</table>" as *u8)
863 o = pd_cat(out, o, "<p>maturity: <b>pm-oversight</b> on the live rollup (FUNCTIONAL → EXCEED, single-src) · ship gate: " as *u8)
864 let glb: *u8 = sys_mmap(PD_CAP)
865 let glsz: *i64 = sys_mmap(PD_SPAN) as *i64
866 let gln: i64 = pd_read("knowledge/status/pm_dashboard_gate.log" as *u8, glb, PD_CAP - 4, glsz)
867 if pd_starts(glb, gln, "VERDICT=GREEN" as *u8) == 1 { o = pd_cat(out, o, "<span class=a>GREEN</span>" as *u8) } else { o = pd_cat(out, o, "<span class=s>unverified</span>" as *u8) }
868 // SUPERVISED deploy-reliability: read the buildroot-guard self-heal verdict (published every 5min by cron)
869 o = pd_cat(out, o, " · deploy-reliability: " as *u8)
870 let dgb: *u8 = sys_mmap(PD_CAP)
871 let dgsz: *i64 = sys_mmap(PD_SPAN) as *i64
872 let dgn: i64 = pd_read("knowledge/status/buildroot_guard.log" as *u8, dgb, PD_CAP - 4, dgsz)
873 if pd_starts(dgb, dgn, "VERDICT=GREEN" as *u8) == 1 { o = pd_cat(out, o, "<span class=a>GREEN</span> buildroot self-heal + fail-loud build" as *u8) } else { if dgn > 0 { o = pd_cat(out, o, "<span class=s>HEALING</span>" as *u8) } else { o = pd_cat(out, o, "<span class=d>unmonitored</span>" as *u8) } }
874 // SUPERVISED api-contract (rule-19): read the contract-guard verdict (cron-probed) -- flags a dropped route
875 o = pd_cat(out, o, " · api-contract: " as *u8)
876 let acb: *u8 = sys_mmap(PD_CAP)
877 let acsz: *i64 = sys_mmap(PD_SPAN) as *i64
878 let acn: i64 = pd_read("knowledge/status/api_contract.log" as *u8, acb, PD_CAP - 4, acsz)
879 if pd_starts(acb, acn, "VERDICT=GREEN" as *u8) == 1 { o = pd_cat(out, o, "<span class=a>GREEN</span>" as *u8) } else { if acn > 0 { o = pd_cat(out, o, "<span class=g>REGRESSION (see api_contract.log)</span>" as *u8) } else { o = pd_cat(out, o, "<span class=d>unmonitored</span>" as *u8) } }
880 o = pd_cat(out, o, "</p><p class=note>views: <a href=/standup>standup</a> · <a href=/frontier>frontier board</a> · <a href=/compare/maturity>maturity</a> · <a href=/compare/atlas/card/nx_pm_dashboard.nx.html>atlas card</a> · <a href=/pmdash>pm-cockpit search</a> · <a href=/pmroi>ROI (mirror)</a></p>" as *u8)
881 o = pd_cat(out, o, "</body></html>" as *u8)
882 out[o] = PD_NL as u8
883 o = o + 1
884 if (op as i64) != 0 {
885 let fd: i64 = sys_openat_wr(op, PD_MODE)
886 if fd < 0 { pd_werr("PD-FAIL cannot open outpath\n" as *u8); sys_exit(1); return 1 }
887 sys_write(fd, out, o)
888 sys_close(fd)
889 let m: *u8 = sys_mmap(128)
890 var mo: i64 = pd_cat(m, 0, "PD PAGE bytes=" as *u8)
891 mo = pd_catn(m, mo, o)
892 mo = pd_cat(m, mo, "\n" as *u8)
893 sys_write(1, m, mo)
894 } else { sys_write(1, out, o) }
895 sys_exit(0)
896 return 0
897 }
898 pd_werr("usage: nx_pm_dashboard {seedroi | roi | exec | page}\n" as *u8)
899 sys_exit(PD_EXIT_USAGE)
900 return PD_EXIT_USAGE
901}