code wiki / _hdl_build / nx_dora.nx
nx_dora.nx source
↩ module page · 300 lines · 18391 B
1// nx_dora.nx -- DORA-analogue delivery metrics derived from SOVEREIGN event planes (F740).
2// Operator ask: beyond-SOTA, evidence-driven, no manual instrumentation. Incumbents (Jellyfish/LinearB/
3// Swarmia/DX) POLL git/Jira; we DERIVE the DORA keys from our own event stream -- the sovereign exceed
4// /compare/pmdash flagged as GAP F740:
5// - DEPLOY FREQUENCY = DONE frames in knowledge/status/ws_sync.jrnl (each shipped ws = a delivery event)
6// - LEAD TIME (cycle) = DONE_epoch - most-recent-prior KICKOFF_epoch of the same ws, median across pairs
7// - CHANGE-FAIL proxy = incident-class OPEN debts / deploys (debt- plane; declared heuristic, labeled)
8// - MTTR proxy = median debt filed->eaten span is NOT in the row (needs debthist join) -> declared PENDING
9// Honest by construction: 2 keys MEASURED, 2 PROXY/PENDING, each labeled; DORA elite/high/medium/low bands.
10// argv[1] = mode: json(default -> stdout) | html [argv[2]=out path, default sites/nishifamily/dora.html]
11// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
12import "nx_store_seed_lib.nx"
13import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
14import "nx_syscalls.nx"
15
16const DJPATH: *u8 = "knowledge/status/ws_sync.jrnl"
17const DEBTPFX: *u8 = "knowledge/store/debt-"
18const DNL: i64 = 10
19const DTAB: i64 = 9
20const DHASH: i64 = 35
21const DZERO: i64 = 48
22const DNINE: i64 = 57
23const DCAP: i64 = 1048576
24const DMAXEV: i64 = 6000
25const DSECDAY: i64 = 86400
26const DSECHR: i64 = 3600
27const DSECWK: i64 = 604800
28const DHTMLH: i64 = 104 // 'h'
29const DOUTCAP: i64 = 262144
30const DI64: i64 = 8
31
32func d_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
33func d_p(s: *u8) -> i64 { sys_write(1, s, d_len(s)); return 0 }
34func d_read(path: *u8, buf: *u8, cap: i64) -> i64 {
35 let fd: i64 = sys_openat_rd(path)
36 if fd < 0 { return 0 }
37 var n: i64 = 0
38 var go: i64 = 1
39 while go == 1 {
40 let base: i64 = buf as i64
41 let r: i64 = sys_read(fd, (base + n) as *u8, cap - n)
42 if r <= 0 { go = 0 } else { n = n + r }
43 if n >= cap { go = 0 }
44 }
45 sys_close(fd)
46 return n
47}
48// integer at [a,b)
49func d_int(buf: *u8, a: i64, b: i64) -> i64 {
50 var v: i64 = 0
51 var i: i64 = a
52 while i < b { let c: i64 = buf[i]; if c >= DZERO { if c <= DNINE { v = v*10 + (c-DZERO) } } i = i + 1 }
53 return v
54}
55// bytes [a,b) equal [c,d) ?
56func d_span_eq(buf: *u8, a: i64, b: i64, c: i64, d: i64) -> i64 {
57 if b - a != d - c { return 0 }
58 var i: i64 = 0
59 while a + i < b { if buf[a+i] != buf[c+i] { return 0 } i = i + 1 }
60 return 1
61}
62// does [a,b) start with lit?
63func d_starts(buf: *u8, a: i64, b: i64, lit: *u8) -> i64 {
64 let l: i64 = d_len(lit)
65 if b - a < l { return 0 }
66 var i: i64 = 0
67 while i < l { if buf[a+i] != lit[i] { return 0 } i = i + 1 }
68 return 1
69}
70// substring lit inside [a,b) (case-sensitive)
71func d_has(buf: *u8, a: i64, b: i64, lit: *u8) -> i64 {
72 let l: i64 = d_len(lit)
73 if l == 0 { return 0 }
74 var i: i64 = a
75 while i + l <= b { if d_starts(buf, i, b, lit) == 1 { return 1 } i = i + 1 }
76 return 0
77}
78// number -> decimal into fd via buffer
79// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
80// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
81// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
82// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
83func d_num(v: i64) -> i64 { nxi_out(v); return 0 }
84
85// DORA band codes: 4=ELITE 3=HIGH 2=MEDIUM 1=LOW
86func d_band_deploy(per_week: i64) -> i64 { // per_week*100 (fixed-point x100 to keep integer)
87 if per_week >= 700 { return 4 } // >=7/wk (~1+/day) = elite
88 if per_week >= 100 { return 3 } // >=1/wk = high
89 if per_week >= 23 { return 2 } // >=~1/mo = medium
90 return 1
91}
92func d_band_lead(hrs: i64) -> i64 {
93 if hrs < 24 { return 4 }
94 if hrs < 168 { return 3 }
95 if hrs < 720 { return 2 }
96 return 1
97}
98func d_band_cfr(pct: i64) -> i64 {
99 if pct <= 15 { return 4 }
100 if pct <= 30 { return 2 }
101 return 1
102}
103func d_band_label(b: i64) -> *u8 {
104 if b == 4 { return "ELITE" as *u8 }
105 if b == 3 { return "HIGH" as *u8 }
106 if b == 2 { return "MEDIUM" as *u8 }
107 return "LOW" as *u8
108}
109
110func main(argc: i64, argv: *i64) -> i64 {
111 var html: i64 = 0
112 var outp: *u8 = "sites/nishifamily/dora.html" as *u8
113 if argc >= 2 { let a1: *u8 = argv[1] as *u8; if a1[0] == (DHTMLH as u8) { html = 1 } }
114 if argc >= 3 { outp = argv[2] as *u8 }
115
116 let buf: *u8 = sys_mmap(DCAP)
117 let n: i64 = d_read(DJPATH, buf, DCAP - 16)
118
119 // parse frames into arrays
120 let ep: *i64 = sys_mmap(DMAXEV*DI64) as *i64
121 let vb: *i64 = sys_mmap(DMAXEV*DI64) as *i64 // 1=KICKOFF 2=DONE 0=other
122 let wa: *i64 = sys_mmap(DMAXEV*DI64) as *i64
123 let wbb: *i64 = sys_mmap(DMAXEV*DI64) as *i64
124 var nev: i64 = 0
125 var i: i64 = 0
126 while i < n {
127 var le: i64 = i
128 var s: i64 = 1
129 while s == 1 { if le >= n { s = 0 } else { if buf[le] == (DNL as u8) { s = 0 } else { le = le + 1 } } }
130 if le > i { if buf[i] != (DHASH as u8) {
131 // col0 = epoch [i, t0)
132 var t0: i64 = i
133 while t0 < le { if buf[t0] == (DTAB as u8) { t0 = le + 1 } else { t0 = t0 + 1 } }
134 // recover c0 end
135 var c0e: i64 = i
136 var f: i64 = 1
137 while f == 1 { if c0e >= le { f = 0 } else { if buf[c0e] == (DTAB as u8) { f = 0 } else { c0e = c0e + 1 } } }
138 if c0e < le {
139 let epoch: i64 = d_int(buf, i, c0e)
140 // col1 = verb
141 let v1a: i64 = c0e + 1
142 var v1b: i64 = v1a
143 var g: i64 = 1
144 while g == 1 { if v1b >= le { g = 0 } else { if buf[v1b] == (DTAB as u8) { g = 0 } else { v1b = v1b + 1 } } }
145 // col2 = ws
146 let w2a: i64 = v1b + 1
147 var w2b: i64 = w2a
148 var h: i64 = 1
149 while h == 1 { if w2b >= le { h = 0 } else { if buf[w2b] == (DTAB as u8) { h = 0 } else { w2b = w2b + 1 } } }
150 var verb: i64 = 0
151 if d_starts(buf, v1a, v1b, "KICKOFF" as *u8) == 1 { verb = 1 }
152 if d_starts(buf, v1a, v1b, "DONE" as *u8) == 1 { verb = 2 }
153 if nev < DMAXEV {
154 ep[nev] = epoch; vb[nev] = verb; wa[nev] = w2a; wbb[nev] = w2b
155 nev = nev + 1
156 }
157 }
158 } }
159 i = le + 1
160 }
161
162 // deploys = DONE count; window from min/max epoch
163 var deploys: i64 = 0
164 var mn: i64 = 0
165 var mx: i64 = 0
166 var have: i64 = 0
167 i = 0
168 while i < nev {
169 if have == 0 { mn = ep[i]; mx = ep[i]; have = 1 } else { if ep[i] < mn { mn = ep[i] } if ep[i] > mx { mx = ep[i] } }
170 if vb[i] == 2 { deploys = deploys + 1 }
171 i = i + 1
172 }
173 var window_s: i64 = mx - mn
174 if window_s < 1 { window_s = 1 }
175 // per_week x100 (fixed point)
176 let per_week: i64 = (deploys * DSECWK * 100) / window_s
177
178 // lead times: for each DONE, latest prior KICKOFF same ws
179 let leads: *i64 = sys_mmap(DMAXEV*DI64) as *i64
180 var nlead: i64 = 0
181 i = 0
182 while i < nev {
183 if vb[i] == 2 {
184 var best: i64 = 0 - 1
185 var j: i64 = 0
186 while j < i {
187 if vb[j] == 1 {
188 if d_span_eq(buf, wa[j], wbb[j], wa[i], wbb[i]) == 1 {
189 if ep[j] <= ep[i] { if best < 0 { best = ep[j] } else { if ep[j] > best { best = ep[j] } } }
190 }
191 }
192 j = j + 1
193 }
194 if best >= 0 { let cyc: i64 = ep[i] - best; if cyc >= 0 { leads[nlead] = cyc; nlead = nlead + 1 } }
195 }
196 i = i + 1
197 }
198 // median lead (insertion sort)
199 var a: i64 = 1
200 while a < nlead {
201 let key: i64 = leads[a]
202 var b: i64 = a - 1
203 var mv: i64 = 1
204 while mv == 1 { if b < 0 { mv = 0 } else { if leads[b] > key { leads[b+1] = leads[b]; b = b - 1 } else { mv = 0 } } }
205 leads[b+1] = key
206 a = a + 1
207 }
208 var lead_med_s: i64 = 0
209 if nlead > 0 { lead_med_s = leads[nlead/2] }
210 let lead_med_hr: i64 = lead_med_s / DSECHR
211
212 // change-fail proxy from debt- plane: incident-class open debts / deploys
213 let dbuf: *u8 = sys_mmap(DCAP)
214 let dn: i64 = sts_load(DEBTPFX, dbuf, DCAP - 16)
215 var incident: i64 = 0
216 var dtot: i64 = 0
217 var i2: i64 = 0
218 while i2 < dn {
219 var le2: i64 = i2
220 var s2: i64 = 1
221 while s2 == 1 { if le2 >= dn { s2 = 0 } else { if dbuf[le2] == (DNL as u8) { s2 = 0 } else { le2 = le2 + 1 } } }
222 if le2 > i2 { if dbuf[i2] != (DHASH as u8) {
223 dtot = dtot + 1
224 var isopen: i64 = 0
225 if d_has(dbuf, i2, le2, "open" as *u8) == 1 { isopen = 1 }
226 if isopen == 1 {
227 if d_has(dbuf, i2, le2, "regress" as *u8) == 1 { incident = incident + 1 }
228 else { if d_has(dbuf, i2, le2, "rollback" as *u8) == 1 { incident = incident + 1 }
229 else { if d_has(dbuf, i2, le2, "revert" as *u8) == 1 { incident = incident + 1 }
230 else { if d_has(dbuf, i2, le2, "outage" as *u8) == 1 { incident = incident + 1 }
231 else { if d_has(dbuf, i2, le2, "brick" as *u8) == 1 { incident = incident + 1 } } } } }
232 }
233 } }
234 i2 = le2 + 1
235 }
236 var cfr: i64 = 0
237 if deploys > 0 { cfr = (incident * 100) / deploys }
238 if cfr > 100 { cfr = 100 }
239
240 let bd: i64 = d_band_deploy(per_week)
241 let bl: i64 = d_band_lead(lead_med_hr)
242 let bc: i64 = d_band_cfr(cfr)
243
244 if html == 0 {
245 d_p("{\"tool\":\"nx_dora\",\"epoch\":" as *u8); d_num(sys_now_realtime_sec())
246 d_p(",\"source\":\"knowledge/status/ws_sync.jrnl (DONE=deploy, KICKOFF->DONE=lead) + debt- plane (change-fail proxy) -- sovereign, zero git-poll\"" as *u8)
247 d_p(",\"window_days\":" as *u8); d_num(window_s / DSECDAY)
248 d_p(",\"deploy_frequency\":{\"deploys\":" as *u8); d_num(deploys)
249 d_p(",\"per_week_x100\":" as *u8); d_num(per_week)
250 d_p(",\"band\":\"" as *u8); d_p(d_band_label(bd)); d_p("\",\"kind\":\"MEASURED\"}" as *u8)
251 d_p(",\"lead_time\":{\"matched_pairs\":" as *u8); d_num(nlead)
252 d_p(",\"median_hours\":" as *u8); d_num(lead_med_hr)
253 d_p(",\"median_seconds\":" as *u8); d_num(lead_med_s)
254 d_p(",\"band\":\"" as *u8); d_p(d_band_label(bl)); d_p("\",\"kind\":\"MEASURED\"}" as *u8)
255 d_p(",\"change_fail_rate\":{\"pct\":" as *u8); d_num(cfr)
256 d_p(",\"incident_open_debts\":" as *u8); d_num(incident)
257 d_p(",\"band\":\"" as *u8); d_p(d_band_label(bc)); d_p("\",\"kind\":\"PROXY\"}" as *u8)
258 d_p(",\"mttr\":{\"kind\":\"PENDING\",\"note\":\"filed->eaten span needs the debthist- join (F740b); not asserted\"}" as *u8)
259 d_p(",\"bands_legend\":\"ELITE/HIGH/MEDIUM/LOW per DORA 2023-24 thresholds; deploy elite>=1/day, lead elite<24h, CFR elite<=15pct\"" as *u8)
260 d_p(",\"caveat\":\"DORA-ANALOGUE from our delivery event stream (shipped work items), not git-commit-instrumented; a DONE frame = a delivered capability. Honest: 2 keys MEASURED, change-fail PROXY (incident-class open debts), MTTR PENDING.\"}" as *u8)
261 d_p("\n" as *u8)
262 sys_exit(0)
263 return 0
264 }
265
266 // ---- HTML /dora ----
267 let out: *u8 = sys_mmap(DOUTCAP)
268 var o: i64 = 0
269 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 DORA (sovereign)</title><style>body{margin:0;font:15px/1.5 -apple-system,Segoe UI,Roboto,sans-serif;background:#0e1116;color:#e6edf3}header{padding:28px 24px;background:linear-gradient(135deg,#161b22,#0e1116);border-bottom:1px solid #30363d}h1{margin:0 0 6px;font-size:22px}.sub{color:#8b949e;font-size:14px}h2{margin:24px 24px 8px;font-size:13px;text-transform:uppercase;letter-spacing:.08em;color:#8b949e}table{border-collapse:collapse;margin:0 24px 8px;max-width:1000px}td,th{padding:8px 10px;border-bottom:1px solid #21262d;text-align:left;font-size:14px}th{color:#8b949e;font-size:12px;text-transform:uppercase}.m{color:#8b949e;font-size:12px}.tile{display:inline-block;background:#161b22;border:1px solid #30363d;border-radius:10px;padding:14px 18px;margin:10px 8px 0 0;min-width:150px}.tile .n{font-size:24px;font-weight:700}.tile .l{color:#8b949e;font-size:12px}.e{color:#3fb950}.h{color:#58a6ff}.md{color:#d29922}.lo{color:#f85149}a{color:#58a6ff;text-decoration:none}footer{padding:18px 24px;color:#6e7681;font-size:12px;border-top:1px solid #21262d;margin-top:22px}</style></head><body><header><h1>Nishi DORA — sovereign delivery metrics (F740)</h1><div class=sub>the four keys DERIVED from our own event stream (ws_sync.jrnl + debt plane) — zero git-poll, zero manual entry · measured, never asserted</div></header>" as *u8)
270 o = ss_cat(out, o, "<div style='padding:0 16px'>" as *u8)
271 o = ss_cat(out, o, "<span class=tile><div class=n>" as *u8); o = ss_catn(out, o, deploys); o = ss_cat(out, o, "</div><div class=l>deploys (DONE frames) · <span class=" as *u8)
272 if bd == 4 { o = ss_cat(out, o, "e>ELITE" as *u8) } else { if bd == 3 { o = ss_cat(out, o, "h>HIGH" as *u8) } else { if bd == 2 { o = ss_cat(out, o, "md>MEDIUM" as *u8) } else { o = ss_cat(out, o, "lo>LOW" as *u8) } } }
273 o = ss_cat(out, o, "</span></div></span>" as *u8)
274 o = ss_cat(out, o, "<span class=tile><div class=n>" as *u8); o = ss_catn(out, o, lead_med_hr); o = ss_cat(out, o, "h</div><div class=l>median lead time · <span class=" as *u8)
275 if bl == 4 { o = ss_cat(out, o, "e>ELITE" as *u8) } else { if bl == 3 { o = ss_cat(out, o, "h>HIGH" as *u8) } else { if bl == 2 { o = ss_cat(out, o, "md>MEDIUM" as *u8) } else { o = ss_cat(out, o, "lo>LOW" as *u8) } } }
276 o = ss_cat(out, o, "</span></div></span>" as *u8)
277 o = ss_cat(out, o, "<span class=tile><div class=n>" as *u8); o = ss_catn(out, o, cfr); o = ss_cat(out, o, "%</div><div class=l>change-fail (proxy) · <span class=" as *u8)
278 if bc == 4 { o = ss_cat(out, o, "e>ELITE" as *u8) } else { if bc == 2 { o = ss_cat(out, o, "md>MEDIUM" as *u8) } else { o = ss_cat(out, o, "lo>LOW" as *u8) } }
279 o = ss_cat(out, o, "</span></div></span></div>" as *u8)
280 o = ss_cat(out, o, "<h2>The four keys — measured from sovereign planes</h2><table><tr><th>key</th><th>value</th><th>band</th><th>kind</th><th>how it is derived</th></tr>" as *u8)
281 o = ss_cat(out, o, "<tr><td>Deployment frequency</td><td>" as *u8); o = ss_catn(out, o, deploys); o = ss_cat(out, o, " over " as *u8); o = ss_catn(out, o, window_s/DSECDAY); o = ss_cat(out, o, "d (" as *u8); o = ss_catn(out, o, per_week/100); o = ss_cat(out, o, "/wk)</td><td>" as *u8); o = ss_cat(out, o, d_band_label(bd)); o = ss_cat(out, o, "</td><td class=m>MEASURED</td><td class=m>count of DONE frames in ws_sync.jrnl (each = a delivered capability)</td></tr>" as *u8)
282 o = ss_cat(out, o, "<tr><td>Lead time for changes</td><td>median " as *u8); o = ss_catn(out, o, lead_med_hr); o = ss_cat(out, o, "h (" as *u8); o = ss_catn(out, o, nlead); o = ss_cat(out, o, " matched pairs)</td><td>" as *u8); o = ss_cat(out, o, d_band_label(bl)); o = ss_cat(out, o, "</td><td class=m>MEASURED</td><td class=m>DONE_epoch - most-recent prior KICKOFF of the same workstream</td></tr>" as *u8)
283 o = ss_cat(out, o, "<tr><td>Change failure rate</td><td>" as *u8); o = ss_catn(out, o, cfr); o = ss_cat(out, o, "% (" as *u8); o = ss_catn(out, o, incident); o = ss_cat(out, o, " incident-class open debts)</td><td>" as *u8); o = ss_cat(out, o, d_band_label(bc)); o = ss_cat(out, o, "</td><td class=md>PROXY</td><td class=m>deploy-failure open debts (regression/rollback/revert/outage/brick) / deploys (declared coarse-upper-bound heuristic; broad coordination/stale debts EXCLUDED)</td></tr>" as *u8)
284 o = ss_cat(out, o, "<tr><td>Time to restore (MTTR)</td><td>—</td><td>—</td><td class=lo>PENDING</td><td class=m>filed→eaten span needs the debthist- join (F740b); NOT asserted rather than faked</td></tr></table>" as *u8)
285 o = ss_cat(out, o, "<h2>Why this is beyond SOTA</h2><table><tr><th>axis</th><th>Nishi</th><th>Jellyfish / LinearB / Swarmia / DX</th></tr>" as *u8)
286 o = ss_cat(out, o, "<tr><td>instrumentation</td><td class=e>ZERO manual + ZERO git-poll: derived from the native delivery event stream</td><td class=m>poll git/CI/Jira webhooks; batch ETL</td></tr>" as *u8)
287 o = ss_cat(out, o, "<tr><td>honesty</td><td class=e>each key tagged MEASURED / PROXY / PENDING; a key it cannot ground is shown PENDING, never faked</td><td class=m>single confident numbers</td></tr>" as *u8)
288 o = ss_cat(out, o, "<tr><td>agents as workers</td><td class=e>autonomous zero-Claude DONE frames counted as first-class deliveries</td><td class=m>humans-only</td></tr></table>" as *u8)
289 o = ss_cat(out, o, "<h2>Fetch spec (what to ingest to harden this)</h2><table><tr><th>target</th><th>why</th></tr>" as *u8)
290 o = ss_cat(out, o, "<tr><td>dora.dev 2024 State of DevOps</td><td class=m>the canonical thresholds + the AI-impact findings to re-band against</td></tr>" as *u8)
291 o = ss_cat(out, o, "<tr><td>DX Core 4 (getdx.com)</td><td class=m>unify DORA+SPACE+DevEx; the 4-dim model to extend these keys with effectiveness/quality</td></tr>" as *u8)
292 o = ss_cat(out, o, "<tr><td>debthist- join (F740b)</td><td class=m>filed→eaten timestamps to turn MTTR from PENDING into MEASURED</td></tr></table>" as *u8)
293 o = ss_cat(out, o, "<footer>source knowledge/status/ws_sync.jrnl + knowledge/store/debt- · DORA-analogue from the delivery event stream (a DONE = a shipped capability), not git-commit-instrumented · bands per DORA 2023-24 · generated epoch " as *u8)
294 o = ss_catn(out, o, sys_now_realtime_sec())
295 o = ss_cat(out, o, " · measured, never asserted · oversight: <a href=/pmcockpit>/pmcockpit</a> · bench: <a href=/compare/pmdash>/compare/pmdash</a> · hub: <a href=/compare>/compare</a></footer></body></html>\n" as *u8)
296 ss_writefile(outp, out, o)
297 d_p("wrote " as *u8); d_p(outp); d_p(" bytes=" as *u8); d_num(o); d_p("\n" as *u8)
298 sys_exit(0)
299 return 0
300}