code wiki / _hdl_build / nx_growth_series.nx

nx_growth_series.nx source

↩ module page · 1159 lines · 53376 B

1// nx_growth_series.nx -- THE TIME SPINE for the exec/managerial/operational wedding cake. 2// 3// nx_pm_board emits the three tiers correctly. What the estate had NOWHERE was TIME: measured 4// 2026-08-15, ecomat hist EMPTY, frontier hist EMPTY, comparewatch unseeded, token_efficiency.log 5// 1417B -- so no board could answer "how did this change since last week". 6// A LEVEL CANNOT EXPRESS GROWTH: growth is a DERIVATIVE and needs two samples in time. 7// 8// This organ adds ONLY that dimension. Every number it records is COMPOSED from nx_pm_board through 9// tr_run_capture and every historical number is READ from journals already on disk. Zero measurement 10// logic is duplicated: one ruler per figure. 11// 12// nx_growth_series beat [log] [board-elf] -> append ONE dated row; a BEAT-FAIL is ALSO a row 13// nx_growth_series report [log] -> d/w/m deltas + the per-axis HORIZON 14// nx_growth_series mine [journal] -> retro-computed workstream history, FULL population 15// nx_growth_series selftest [scratchlog] -> gate teeth incl. named negative controls 16// 17// ROW SHAPE -- the ECOMAT shape already proven in knowledge/status/ecosystem_maturity.log, so reader 18// idiom transfers. Line-anchored, each field name appears EXACTLY ONCE, canonical verdict LAST so a 19// positional reader can anchor on it. 20// 21// A FIELD THAT COULD NOT BE READ IS -1, NEVER 0. "Could not look" and "measured zero" are different 22// facts, and a series that confuses them reports a collapse that never happened. 23// 24// NO GUESSED CEILINGS. Every buffer here is sized from the thing that fills it -- needles from the 25// key, emit lines from the field count, the mine day-grid from the journal's own epoch span. The one 26// remaining bound (GS_BOARDCAP) guards a SUBPROCESS's output, whose size is genuinely unknowable in 27// advance; it is named for that single purpose and its truncation ANNOUNCES as a RED row rather than 28// being absorbed. A ceiling that has to be guessed is a defect generator in both directions. 29// 30// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 31import "nx_sovjson_lib.nx" 32import "nx_syscalls.nx" 33import "nx_tool_run.nx" 34 35// The ONLY legitimate bound in this file: a forked child's stdout length cannot be known before it 36// runs. mmap faults pages on demand so the headroom costs address space, not resident memory. AT the 37// cap the capture is a FLOOR, not a reading -> BEAT-FAIL. 38const GS_BOARDCAP: i64 = 4194304 39const GS_MODE: i64 = 420 40// byte values, not tunables 41const GS_TAB: i64 = 9 42const GS_NL: i64 = 10 43const GS_SPACE: i64 = 32 44const GS_QUOTE: i64 = 34 45const GS_MINUS: i64 = 45 46const GS_SLASH: i64 = 47 47const GS_D0: i64 = 48 48const GS_D9: i64 = 57 49const GS_COLON: i64 = 58 50const GS_EQ: i64 = 61 51const GS_LBRACK: i64 = 91 52const GS_RBRACK: i64 = 93 53// time. GS_MONTH is 30 days BY CHOICE -- calendar months are unequal and a 30-day window is the 54// honest approximation. Stated here so the next reader does not mistake it for exactness. 55const GS_DAY: i64 = 86400 56const GS_WEEK: i64 = 604800 57const GS_MONTH: i64 = 2592000 58const GS_ABSENT: i64 = 0 - 1 59// the axis schema. ONE table feeds emitter AND parser, so a field cannot be written under one name 60// and read under another. 61// 11 axes. adoption_permil was added 2026-08-15 on EXTERNAL ground truth, not taste: the published 62// platform-engineering consensus of 2026 makes ADOPTION the leading metric -- the share of capability 63// actually on the paved path -- with roughly 70pc of platform initiatives failing to reach meaningful 64// adoption. The estate's own census reads 506 permil, and nx_adopt was itself REGISTERED-DARK when 65// this axis was written: the organ that measures adoption had never been adopted. 66// 15 axes. The four finance axes were added 2026-08-15 because an executive tier without money is a 67// status report, not a sponsor report. They are COMPOSED from nx_eff_board, whose cost side is REAL 68// (per-model attributed against rates fetched from the vendor price list) and whose value side is an 69// explicitly conservative floor. BOTH are carried, deliberately: monthly_cost_cents next to 70// monthly_value_cents is the only honest way to show that the return is currently UNMEASURABLE rather 71// than negative -- the value plane holds avoided subscription spend only, while the cost is a monthly 72// flow, and the labor-equivalent value STOCK is never amortized against it. nx_eff_board names that 73// time-base mismatch itself and nothing has ever reconciled it. 74// NO INVENTED NUMBER IS ADDED HERE. Every one of the four is read from a field that organ publishes. 75// 18 axes. The three governance axes were added 2026-08-15 from nx_law_warden, the estate's own 76// mechanical law-breach detector -- 11 written laws, every one joined to a RACI owner, laws_unowned=0. 77// It was on NO BEAT: the governance instrument the 2026 bar asks for existed, was ownership-complete, 78// and ran only when a human remembered. Composing it into a beat that already runs AND is already 79// watched adopts it without a second clock row and without a second ruler. 80// RESOURCE ENVELOPE, stated because a beat is a recurring cost: the warden walks ~18,670 files and 81// nx_adopt another ~18,669, so a beat is ~37k file reads, four times a day. The estate already 82// hashes ~18k files hourly, so this sits inside the established norm rather than above it. 83// 20 axes. The two ownership axes complete the 2026 governance triad on the dated series -- adoption, 84// law breaches, and now the percentage of work with a real accountable owner, which the published bar 85// names as a leading metric. Composed from nx_registrymine over the frontier plane (706 rungs), and 86// BOTH readings are carried: owned_permil_strict answers "has an owner a human could be held to" while 87// placeholder_owned is the gap between that and the nominal figure. MEASURED 2026-08-15: nominal 1000, 88// strict 936, 45 rows carrying a placeholder owner -- and 9 of those 45 sat among the 54 owners the 89// top-20 table never emits, so the number was NOT derivable downstream. The ruler had to compute it. 90const GS_NF: i64 = 20 91// workstream verb buckets. GS_VO is the UNKNOWN bucket and is never folded into a known one. 92const GS_VK: i64 = 0 93const GS_VB: i64 = 1 94const GS_VD: i64 = 2 95const GS_VR: i64 = 3 96const GS_VO: i64 = 4 97const GS_NV: i64 = 5 98 99func gs_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 100func gs_puts(s: *u8) -> i64 { sys_write(1, s, gs_strlen(s)); return 0 } 101func gs_werr(s: *u8) -> i64 { sys_write(2, s, gs_strlen(s)); return 0 } 102 103// emit-line width DERIVED from the schema: each field is a name (<64) plus a signed 64-bit decimal 104// (<24) plus separators, so GS_NF fields can never overrun this. No guessed 8192. 105func gs_linecap() -> i64 { return GS_NF * 128 + 1024 } 106 107func gs_names(t: *i64) -> i64 { 108 t[0] = ("frontier_done" as *u8) as i64 109 t[1] = ("frontier_total" as *u8) as i64 110 t[2] = ("debts_open" as *u8) as i64 111 t[3] = ("debts_closed" as *u8) as i64 112 t[4] = ("maturity_permil" as *u8) as i64 113 t[5] = ("incidents_sev7" as *u8) as i64 114 t[6] = ("work_open" as *u8) as i64 115 t[7] = ("work_closed" as *u8) as i64 116 t[8] = ("debt_mutations" as *u8) as i64 117 t[9] = ("work_mutations" as *u8) as i64 118 t[10] = ("adoption_permil" as *u8) as i64 119 t[11] = ("cost_per_action_cents" as *u8) as i64 120 t[12] = ("cache_hit_pct" as *u8) as i64 121 t[13] = ("monthly_cost_cents" as *u8) as i64 122 t[14] = ("monthly_value_cents" as *u8) as i64 123 t[15] = ("laws_breached" as *u8) as i64 124 t[16] = ("breach_weight_permil" as *u8) as i64 125 t[17] = ("unregistered_organs" as *u8) as i64 126 t[18] = ("owned_permil_strict" as *u8) as i64 127 t[19] = ("placeholder_owned" as *u8) as i64 128 return GS_NF 129} 130 131func gs_streq(a: *u8, b: *u8) -> i64 { 132 var i: i64 = 0 133 var r: i64 = 1 134 var go: i64 = 1 135 while go == 1 { 136 if a[i] != b[i] { r = 0; go = 0 } 137 else { if a[i] == (0 as u8) { go = 0 } else { i = i + 1 } } 138 } 139 return r 140} 141 142func gs_append(path: *u8, buf: *u8, n: i64) -> i64 { 143 let fd: i64 = sys_openat_append(path, GS_MODE) 144 if fd < 0 { return 0 - 1 } 145 sys_write(fd, buf, n) 146 sys_fsync(fd) 147 sys_close(fd) 148 return 0 149} 150 151// substring search bounded to [from,to). Separate cursor + explicit flag: a loop that exits by 152// clobbering its own cursor cannot also report where it stopped. 153func gs_find(buf: *u8, from: i64, to: i64, pat: *u8, pl: i64) -> i64 { 154 if pl <= 0 { return GS_ABSENT } 155 var i: i64 = from 156 var found: i64 = GS_ABSENT 157 var go: i64 = 1 158 while go == 1 { 159 if i + pl > to { go = 0 } 160 else { 161 var j: i64 = 0 162 var hit: i64 = 1 163 while j < pl { if buf[i+j] != pat[j] { hit = 0; j = pl } else { j = j + 1 } } 164 if hit == 1 { found = i; go = 0 } else { i = i + 1 } 165 } 166 } 167 return found 168} 169// THE CALLEE IS THE ONLY THING THAT KNOWS ITS OWN WIDTH: never hand-count a literal's length at the 170// call site. A hand-counted 13 silently stops matching the day someone rewords the string. 171func gs_findz(buf: *u8, from: i64, to: i64, pat: *u8) -> i64 { return gs_find(buf, from, to, pat, gs_strlen(pat)) } 172 173func gs_all_digits(buf: *u8, s: i64, e: i64) -> i64 { 174 if e <= s { return 0 } 175 var i: i64 = s 176 var r: i64 = 1 177 var go: i64 = 1 178 while go == 1 { 179 if i >= e { go = 0 } 180 else { 181 let c: i64 = buf[i] as i64 182 if c < GS_D0 { r = 0; go = 0 } 183 else { if c > GS_D9 { r = 0; go = 0 } else { i = i + 1 } } 184 } 185 } 186 return r 187} 188 189// needle buffers are sized FROM THE KEY, so there is no cap to clamp against and no truncated needle 190// that could match the wrong field. 191func gs_needle_json(key: *u8, outlen: *i64) -> *u8 { 192 let kl: i64 = gs_strlen(key) 193 let dst: *u8 = sys_mmap(kl + 8) 194 var p: i64 = 0 195 dst[p] = GS_QUOTE as u8; p = p + 1 196 var k: i64 = 0 197 while k < kl { dst[p] = key[k]; p = p + 1; k = k + 1 } 198 dst[p] = GS_QUOTE as u8; p = p + 1 199 dst[p] = GS_COLON as u8; p = p + 1 200 dst[p] = 0 as u8 201 outlen[0] = p 202 return dst 203} 204 205func gs_needle_row(key: *u8, outlen: *i64) -> *u8 { 206 let kl: i64 = gs_strlen(key) 207 let dst: *u8 = sys_mmap(kl + 8) 208 var p: i64 = 0 209 var k: i64 = 0 210 while k < kl { dst[p] = key[k]; p = p + 1; k = k + 1 } 211 dst[p] = GS_EQ as u8; p = p + 1 212 dst[p] = 0 as u8 213 outlen[0] = p 214 return dst 215} 216 217// GS_ABSENT when there is no digit at all, so "key present but unparseable" abstains rather than 218// silently reading as zero. 219func gs_num_at(buf: *u8, to: i64, start: i64) -> i64 { 220 var i: i64 = start 221 var go: i64 = 1 222 while go == 1 { 223 if i >= to { go = 0 } else { if buf[i] == (GS_SPACE as u8) { i = i + 1 } else { go = 0 } } 224 } 225 var neg: i64 = 0 226 if i < to { if buf[i] == (GS_MINUS as u8) { neg = 1; i = i + 1 } } 227 var have: i64 = 0 228 var v: i64 = 0 229 go = 1 230 while go == 1 { 231 if i >= to { go = 0 } 232 else { 233 let c: i64 = buf[i] as i64 234 if c < GS_D0 { go = 0 } 235 else { if c > GS_D9 { go = 0 } else { v = v * 10 + (c - GS_D0); have = 1; i = i + 1 } } 236 } 237 } 238 if have == 0 { return GS_ABSENT } 239 if neg == 1 { return 0 - v } 240 return v 241} 242 243// the REGION is the anchor. nx_pm_board repeats debts_open in the executive object AND in all 24 244// management lane rows; an unregioned search takes whichever comes first and calls it the exec figure. 245func gs_json_int(buf: *u8, from: i64, to: i64, key: *u8) -> i64 { 246 let pl: *i64 = sys_mmap(8) as *i64 247 let nd: *u8 = gs_needle_json(key, pl) 248 let at: i64 = gs_find(buf, from, to, nd, pl[0]) 249 if at < 0 { return GS_ABSENT } 250 return gs_num_at(buf, to, at + pl[0]) 251} 252 253// COUNT array members. nx_pm_board emits every sev>=7 incident id inline; an executive tier that 254// hands a sponsor 936 ids has reported nothing. The ids stay available to the operational tier. 255func gs_json_count(buf: *u8, from: i64, to: i64, key: *u8) -> i64 { 256 let pl: *i64 = sys_mmap(8) as *i64 257 let nd: *u8 = gs_needle_json(key, pl) 258 let at: i64 = gs_find(buf, from, to, nd, pl[0]) 259 if at < 0 { return GS_ABSENT } 260 var i: i64 = at + pl[0] 261 var go: i64 = 1 262 while go == 1 { if i >= to { go = 0 } else { if buf[i] == (GS_SPACE as u8) { i = i + 1 } else { go = 0 } } } 263 if i >= to { return GS_ABSENT } 264 if buf[i] != (GS_LBRACK as u8) { return GS_ABSENT } 265 i = i + 1 266 var q: i64 = 0 267 go = 1 268 while go == 1 { 269 if i >= to { go = 0 } 270 else { 271 if buf[i] == (GS_RBRACK as u8) { go = 0 } 272 else { if buf[i] == (GS_QUOTE as u8) { q = q + 1 } i = i + 1 } 273 } 274 } 275 return q / 2 276} 277 278func gs_region(buf: *u8, to: i64, key: *u8, nextkey: *u8, out: *i64) -> i64 { 279 let pl: *i64 = sys_mmap(8) as *i64 280 let nd: *u8 = gs_needle_json(key, pl) 281 let a: i64 = gs_find(buf, 0, to, nd, pl[0]) 282 if a < 0 { out[0] = 0; out[1] = 0; return 0 } 283 let pl2: *i64 = sys_mmap(8) as *i64 284 let nd2: *u8 = gs_needle_json(nextkey, pl2) 285 let b: i64 = gs_find(buf, a + pl[0], to, nd2, pl2[0]) 286 out[0] = a 287 if b < 0 { out[1] = to } else { out[1] = b } 288 return 1 289} 290 291// THE ADOPTION AXIS. Composed from nx_adopt, the estate's own adoption census, which walks the 292// corpus and publishes ADOPTION_PERMIL = externally-called defs / total defs. Zero measurement logic 293// is duplicated here -- this reads the number that census already publishes. 294// ANCHORED ON THE PUBLISHED FIELD NAME, and gs_findz computes the needle's own width so a reworded 295// label can never be silently mismatched by a hand-counted length. 296// UNOBSERVABLE ON EVERY FAILURE PATH, never 0: a census that could not run, returned nothing, filled 297// the capture, or did not publish the field yields -1. An adoption number of zero and an adoption 298// number nobody could take are opposite facts, and only one of them is an emergency. 299// RESOURCE ENVELOPE, stated because a beat is a recurring cost: nx_adopt scanned 18,669 files on the 300// run that motivated this axis. At the 6h growthbeat cadence that is 4 corpus walks a day, the same 301// order as the hourly tree-hash beat this estate already carries. 302func gs_axis_adoption(elf: *u8) -> i64 { 303 // REAL ARGV, NOT A BARE FORK. nx_adopt is a PINNED registry row and the REGISTRY supplies its 304 // three arguments; forking the binary bare makes it print usage and exit non-zero, which this 305 // function then faithfully reports as UNOBSERVABLE -- a true answer to the wrong question. 306 // MEASURED 2026-08-15: the first live beat with this axis carried adoption_permil=-1 for exactly 307 // that reason, and the abstain is what made the mistake visible instead of publishing a zero. 308 let av: *i64 = sys_mmap(8*5) as *i64 309 av[0] = elf as i64 310 av[1] = ("buildroot/runtime" as *u8) as i64 311 av[2] = ("buildroot/runtime/_hdl_build" as *u8) as i64 312 av[3] = ("knowledge/status/adopt_census.txt" as *u8) as i64 313 av[4] = 0 314 let out: *u8 = sys_mmap(GS_BOARDCAP) 315 let ol: *i64 = sys_mmap(8) as *i64 316 let rc: i64 = tr_run_capture(elf, av, out, GS_BOARDCAP, ol) 317 let n: i64 = ol[0] 318 if rc != 0 { return GS_ABSENT } 319 if n <= 0 { return GS_ABSENT } 320 if n >= GS_BOARDCAP - 1 { return GS_ABSENT } 321 let key: *u8 = "ADOPTION_PERMIL=" as *u8 322 let at: i64 = gs_findz(out, 0, n, key) 323 if at < 0 { return GS_ABSENT } 324 return gs_num_at(out, n, at + gs_strlen(key)) 325} 326 327// THE FINANCE AXES. Composed from nx_eff_board (the honest ROI board: every row tagged MEASURED or 328// ESTIMATE, SET-ME rows surfaced as needs_decision rather than invented). Fills v[11..14]. 329// REGION-ANCHORED for a reason that bites here: `monthly_cost_cents` appears in BOTH the 330// spend_estimate object AND the roi object of that same JSON, so an unregioned search takes whichever 331// comes first and would silently bind the executive tier to the wrong one. 332// Every field is UNOBSERVABLE (-1) on any failure path. A cost of zero and a cost nobody could take 333// are opposite facts, and reporting the second as the first is how a board starts lying about money. 334func gs_axis_finance(elf: *u8, v: *i64) -> i64 { 335 let av: *i64 = sys_mmap(8*2) as *i64 336 av[0] = elf as i64 337 av[1] = 0 338 let out: *u8 = sys_mmap(GS_BOARDCAP) 339 let ol: *i64 = sys_mmap(8) as *i64 340 let rc: i64 = tr_run_capture(elf, av, out, GS_BOARDCAP, ol) 341 let n: i64 = ol[0] 342 if rc != 0 { return 0 } 343 if n <= 0 { return 0 } 344 if n >= GS_BOARDCAP - 1 { return 0 } 345 let ek: *i64 = sys_mmap(8*2) as *i64 346 let se: *i64 = sys_mmap(8*2) as *i64 347 let ro: *i64 = sys_mmap(8*2) as *i64 348 gs_region(out, n, "efficiency_kpi" as *u8, "spend_estimate" as *u8, ek) 349 gs_region(out, n, "spend_estimate" as *u8, "roi" as *u8, se) 350 gs_region(out, n, "roi" as *u8, "feedback" as *u8, ro) 351 v[11] = gs_json_int(out, ek[0], ek[1], "cost_per_action_cents" as *u8) 352 v[12] = gs_json_int(out, ek[0], ek[1], "cache_hit_ratio_pct" as *u8) 353 v[13] = gs_json_int(out, se[0], se[1], "monthly_cost_cents" as *u8) 354 v[14] = gs_json_int(out, ro[0], ro[1], "monthly_value_cents" as *u8) 355 return 1 356} 357 358// THE GOVERNANCE AXES. Composed from nx_law_warden, which measures 11 written laws and joins every 359// one to a RACI owner. Fills v[15..17]. 360// The warden's own honesty note is the reason this is worth trending: VERDICT=GREEN there means THE 361// WARDEN MEASURED, not that the estate is clean -- laws_breached is the number that says that. And a 362// law with no row is UNENFORCED and therefore invisible, so ADDING a law RAISES the breach count. 363// A RISING breach_weight can therefore mean the governance surface got WIDER, not that the estate got 364// worse; the two are separated by reading laws_total, which is why the count is trended and not judged. 365// L003 IS THE MCP ADOPTION GAP: shipped .elf organs whose basename is absent from the tool allowlist -- 366// a capability that exists and that nobody can call. `measured` appears in EVERY law object, so this 367// read is bounded to the L003 row explicitly rather than taking whichever came first. 368func gs_axis_laws(elf: *u8, v: *i64) -> i64 { 369 let av: *i64 = sys_mmap(8*3) as *i64 370 av[0] = elf as i64 371 av[1] = ("scan" as *u8) as i64 372 av[2] = 0 373 let out: *u8 = sys_mmap(GS_BOARDCAP) 374 let ol: *i64 = sys_mmap(8) as *i64 375 let rc: i64 = tr_run_capture(elf, av, out, GS_BOARDCAP, ol) 376 let n: i64 = ol[0] 377 if rc != 0 { return 0 } 378 if n <= 0 { return 0 } 379 if n >= GS_BOARDCAP - 1 { return 0 } 380 v[15] = gs_json_int(out, 0, n, "laws_breached" as *u8) 381 v[16] = gs_json_int(out, 0, n, "breach_weight_permil" as *u8) 382 let a: i64 = gs_findz(out, 0, n, "L003" as *u8) 383 if a < 0 { v[17] = GS_ABSENT } else { 384 var e2: i64 = n 385 let b: i64 = gs_findz(out, a, n, "L004" as *u8) 386 if b > a { e2 = b } 387 v[17] = gs_json_int(out, a, e2, "measured" as *u8) 388 } 389 return 1 390} 391 392// THE OWNERSHIP AXES. Composed from nx_registrymine over the frontier plane. Fills v[18..19]. 393// Both fields are top-level and unambiguous in that JSON, so no region anchor is needed here -- unlike 394// the finance axes, where monthly_cost_cents genuinely appears twice. Saying WHY a guard is absent is 395// part of the guard: an unexplained missing anchor reads as an oversight to the next reader. 396func gs_axis_owner(elf: *u8, v: *i64) -> i64 { 397 let av: *i64 = sys_mmap(8*4) as *i64 398 av[0] = elf as i64 399 av[1] = ("mine" as *u8) as i64 400 av[2] = ("knowledge/store/frontier-" as *u8) as i64 401 av[3] = 0 402 let out: *u8 = sys_mmap(GS_BOARDCAP) 403 let ol: *i64 = sys_mmap(8) as *i64 404 let rc: i64 = tr_run_capture(elf, av, out, GS_BOARDCAP, ol) 405 let n: i64 = ol[0] 406 if rc != 0 { return 0 } 407 if n <= 0 { return 0 } 408 if n >= GS_BOARDCAP - 1 { return 0 } 409 v[18] = gs_json_int(out, 0, n, "owned_permil_strict" as *u8) 410 v[19] = gs_json_int(out, 0, n, "placeholder_owned" as *u8) 411 return 1 412} 413 414func gs_beat(logp: *u8, boardelf: *u8, adoptelf: *u8, effelf: *u8, lawelf: *u8, ownelf: *u8) -> i64 { 415 let av: *i64 = sys_mmap(8*2) as *i64 416 av[0] = boardelf as i64 417 av[1] = 0 418 let out: *u8 = sys_mmap(GS_BOARDCAP) 419 let ol: *i64 = sys_mmap(8) as *i64 420 let rc: i64 = tr_run_capture(boardelf, av, out, GS_BOARDCAP, ol) 421 let n: i64 = ol[0] 422 423 var ok: i64 = 1 424 var why: *u8 = "none" as *u8 425 if rc != 0 { ok = 0; why = "board-rc-nonzero" as *u8 } 426 if n <= 0 { ok = 0; why = "board-empty-capture" as *u8 } 427 if n >= GS_BOARDCAP - 1 { ok = 0; why = "board-output-hit-cap" as *u8 } 428 if ok == 1 { if gs_findz(out, 0, n, "pm_board" as *u8) < 0 { ok = 0; why = "board-identity-absent" as *u8 } } 429 430 let t: *i64 = sys_mmap(8*GS_NF) as *i64 431 gs_names(t) 432 let v: *i64 = sys_mmap(8*GS_NF) as *i64 433 var f: i64 = 0 434 while f < GS_NF { v[f] = GS_ABSENT; f = f + 1 } 435 436 if ok == 1 { 437 let ex: *i64 = sys_mmap(8*2) as *i64 438 let op: *i64 = sys_mmap(8*2) as *i64 439 gs_region(out, n, "executive" as *u8, "management" as *u8, ex) 440 gs_region(out, n, "operations" as *u8, "roi" as *u8, op) 441 v[0] = gs_json_int(out, ex[0], ex[1], "frontier_done" as *u8) 442 v[1] = gs_json_int(out, ex[0], ex[1], "frontier_total" as *u8) 443 v[2] = gs_json_int(out, ex[0], ex[1], "debts_open" as *u8) 444 v[3] = gs_json_int(out, ex[0], ex[1], "debts_closed" as *u8) 445 v[4] = gs_json_int(out, ex[0], ex[1], "maturity_permil" as *u8) 446 v[5] = gs_json_count(out, ex[0], ex[1], "incidents_sev7plus" as *u8) 447 v[6] = gs_json_int(out, op[0], op[1], "work_open" as *u8) 448 v[7] = gs_json_int(out, op[0], op[1], "work_closed" as *u8) 449 v[8] = gs_json_int(out, op[0], op[1], "debt_mutations" as *u8) 450 v[9] = gs_json_int(out, op[0], op[1], "work_mutations" as *u8) 451 } 452 // taken whether or not the board read cleanly: the two censuses are independent subjects and a 453 // failure of one must not blank the other. 454 v[10] = gs_axis_adoption(adoptelf) 455 // independent subject, taken on its own terms: a board failure must not blank the money. 456 gs_axis_finance(effelf, v) 457 gs_axis_laws(lawelf, v) 458 gs_axis_owner(ownelf, v) 459 460 let ln: *u8 = sys_mmap(gs_linecap()) 461 var o: i64 = sj_cat(ln, 0, "GROWTH epoch=" as *u8) 462 o = sj_catn(ln, o, sys_now_realtime_sec()) 463 f = 0 464 while f < GS_NF { 465 ln[o] = GS_SPACE as u8; o = o + 1 466 o = sj_cat(ln, o, t[f] as *u8) 467 ln[o] = GS_EQ as u8; o = o + 1 468 o = sj_catn(ln, o, v[f]) 469 f = f + 1 470 } 471 o = sj_cat(ln, o, " board_rc=" as *u8) 472 o = sj_catn(ln, o, rc) 473 o = sj_cat(ln, o, " board_bytes=" as *u8) 474 o = sj_catn(ln, o, n) 475 o = sj_cat(ln, o, " src=beat reason=" as *u8) 476 o = sj_cat(ln, o, why) 477 if ok == 1 { o = sj_cat(ln, o, " verdict=GREEN" as *u8) } else { o = sj_cat(ln, o, " verdict=RED" as *u8) } 478 ln[o] = GS_NL as u8; o = o + 1 479 480 if gs_append(logp, ln, o) != 0 { gs_werr("GROWTH-BEAT FAIL cannot append series log\n" as *u8); return 1 } 481 if ok == 1 { gs_puts("GROWTH-BEAT OK appended dated row\n" as *u8); return 0 } 482 gs_werr("GROWTH-BEAT FAIL (RED row appended as evidence)\n" as *u8) 483 return 1 484} 485 486func gs_row_field(buf: *u8, s: i64, e: i64, key: *u8) -> i64 { 487 let pl: *i64 = sys_mmap(8) as *i64 488 let nd: *u8 = gs_needle_row(key, pl) 489 let at: i64 = gs_find(buf, s, e, nd, pl[0]) 490 if at < 0 { return GS_ABSENT } 491 return gs_num_at(buf, e, at + pl[0]) 492} 493 494// A BASELINE THAT IS THE SAME SAMPLE AS THE CURRENT READING IS NOT A BASELINE. With one row in the 495// window the delta is that row minus itself: exactly zero, and flagged observed -- a self-referential 496// zero that reads as "measured no change" when it means "measured once". 497func gs_observed(be: i64, ecur: i64) -> i64 { 498 if be <= 0 { return 0 } 499 if be == ecur { return 0 } 500 return 1 501} 502 503func gs_report(logp: *u8) -> i64 { 504 let nlp: *i64 = sys_mmap(8) as *i64 505 let buf: *u8 = sys_read_file(logp, nlp) 506 if (buf as i64) == 0 { gs_puts("GROWTH-REPORT horizon_rows=0 reason=series-absent verdict=RED\n" as *u8); return 1 } 507 let n: i64 = nlp[0] 508 if n <= 0 { gs_puts("GROWTH-REPORT horizon_rows=0 reason=series-empty verdict=RED\n" as *u8); return 1 } 509 510 let t: *i64 = sys_mmap(8*GS_NF) as *i64 511 gs_names(t) 512 let now: i64 = sys_now_realtime_sec() 513 514 let cur: *i64 = sys_mmap(8*GS_NF) as *i64 515 let b1: *i64 = sys_mmap(8*GS_NF) as *i64 516 let b7: *i64 = sys_mmap(8*GS_NF) as *i64 517 let b30: *i64 = sys_mmap(8*GS_NF) as *i64 518 var f: i64 = 0 519 while f < GS_NF { cur[f] = GS_ABSENT; b1[f] = GS_ABSENT; b7[f] = GS_ABSENT; b30[f] = GS_ABSENT; f = f + 1 } 520 var e1: i64 = 0 521 var e7: i64 = 0 522 var e30: i64 = 0 523 var ecur: i64 = 0 524 var eold: i64 = 0 525 var rows: i64 = 0 526 var green: i64 = 0 527 528 var s: i64 = 0 529 var go: i64 = 1 530 while go == 1 { 531 if s >= n { go = 0 } 532 else { 533 var e: i64 = s 534 var g2: i64 = 1 535 while g2 == 1 { if e >= n { g2 = 0 } else { if buf[e] == (GS_NL as u8) { g2 = 0 } else { e = e + 1 } } } 536 if e > s { 537 let ep: i64 = gs_row_field(buf, s, e, "epoch" as *u8) 538 if ep > 0 { 539 rows = rows + 1 540 if eold == 0 { eold = ep } 541 if ep < eold { eold = ep } 542 if gs_findz(buf, s, e, "verdict=GREEN" as *u8) >= 0 { green = green + 1 } 543 if ep >= ecur { 544 ecur = ep 545 f = 0 546 while f < GS_NF { cur[f] = gs_row_field(buf, s, e, t[f] as *u8); f = f + 1 } 547 } 548 if ep <= now - GS_DAY { if ep >= e1 { e1 = ep 549 f = 0 550 while f < GS_NF { b1[f] = gs_row_field(buf, s, e, t[f] as *u8); f = f + 1 } } } 551 if ep <= now - GS_WEEK { if ep >= e7 { e7 = ep 552 f = 0 553 while f < GS_NF { b7[f] = gs_row_field(buf, s, e, t[f] as *u8); f = f + 1 } } } 554 if ep <= now - GS_MONTH { if ep >= e30 { e30 = ep 555 f = 0 556 while f < GS_NF { b30[f] = gs_row_field(buf, s, e, t[f] as *u8); f = f + 1 } } } 557 } 558 } 559 s = e + 1 560 } 561 } 562 563 let ln: *u8 = sys_mmap(gs_linecap()) 564 var o: i64 = sj_cat(ln, 0, "GROWTH-REPORT epoch=" as *u8) 565 o = sj_catn(ln, o, now) 566 o = sj_cat(ln, o, " horizon_rows=" as *u8) 567 o = sj_catn(ln, o, rows) 568 o = sj_cat(ln, o, " horizon_oldest=" as *u8) 569 o = sj_catn(ln, o, eold) 570 o = sj_cat(ln, o, " horizon_span_s=" as *u8) 571 if ecur > eold { o = sj_catn(ln, o, ecur - eold) } else { o = sj_catn(ln, o, 0) } 572 o = sj_cat(ln, o, " green_rows=" as *u8) 573 o = sj_catn(ln, o, green) 574 ln[o] = GS_NL as u8; o = o + 1 575 sys_write(1, ln, o) 576 577 o = sj_cat(ln, 0, "GROWTH-LEVEL epoch=" as *u8) 578 o = sj_catn(ln, o, ecur) 579 f = 0 580 while f < GS_NF { 581 ln[o] = GS_SPACE as u8; o = o + 1 582 o = sj_cat(ln, o, t[f] as *u8) 583 ln[o] = GS_EQ as u8; o = o + 1 584 o = sj_catn(ln, o, cur[f]) 585 f = f + 1 586 } 587 ln[o] = GS_NL as u8; o = o + 1 588 sys_write(1, ln, o) 589 590 var w: i64 = 0 591 while w < 3 { 592 var wname: *u8 = "1d" as *u8 593 var base: *i64 = b1 594 var be: i64 = e1 595 if w == 1 { wname = "7d" as *u8; base = b7; be = e7 } 596 if w == 2 { wname = "30d" as *u8; base = b30; be = e30 } 597 o = sj_cat(ln, 0, "GROWTH-DELTA window=" as *u8) 598 o = sj_cat(ln, o, wname) 599 o = sj_cat(ln, o, " base_epoch=" as *u8) 600 o = sj_catn(ln, o, be) 601 o = sj_cat(ln, o, " observed=" as *u8) 602 let obs: i64 = gs_observed(be, ecur) 603 o = sj_catn(ln, o, obs) 604 f = 0 605 while f < GS_NF { 606 ln[o] = GS_SPACE as u8; o = o + 1 607 o = sj_cat(ln, o, t[f] as *u8) 608 ln[o] = GS_EQ as u8; o = o + 1 609 var d: i64 = GS_ABSENT 610 if obs == 1 { if cur[f] != GS_ABSENT { if base[f] != GS_ABSENT { d = cur[f] - base[f] } } } 611 o = sj_catn(ln, o, d) 612 f = f + 1 613 } 614 ln[o] = GS_NL as u8; o = o + 1 615 sys_write(1, ln, o) 616 w = w + 1 617 } 618 619 o = sj_cat(ln, 0, "GROWTH-REPORT-END rows=" as *u8) 620 o = sj_catn(ln, o, rows) 621 if rows >= 2 { o = sj_cat(ln, o, " verdict=GREEN" as *u8) } 622 else { o = sj_cat(ln, o, " reason=series-too-short-for-a-derivative verdict=AMBER" as *u8) } 623 ln[o] = GS_NL as u8; o = o + 1 624 sys_write(1, ln, o) 625 if rows >= 2 { return 0 } 626 return 2 627} 628 629func gs_prefix_at(buf: *u8, s: i64, e: i64, pat: *u8) -> i64 { 630 var i: i64 = 0 631 var r: i64 = 1 632 var go: i64 = 1 633 while go == 1 { 634 if pat[i] == (0 as u8) { go = 0 } 635 else { 636 if s + i >= e { r = 0; go = 0 } 637 else { if buf[s+i] != pat[i] { r = 0; go = 0 } else { i = i + 1 } } 638 } 639 } 640 return r 641} 642 643// A FRAME IS STRUCTURAL, NOT A THRESHOLD: a line whose first field is a NON-EMPTY RUN OF DIGITS 644// terminated by a TAB. No magic epoch floor to tune, and no future date at which the test silently 645// changes meaning. Journal notes are free prose and DO wrap, so every other line is a CONTINUATION -- 646// counted in its own bucket, never dropped and never miscounted as a frame. 647// out[0]=epoch out[1]=verb-bucket 648func gs_frame(buf: *u8, s: i64, e: i64, out: *i64) -> i64 { 649 var tb: i64 = s 650 var g: i64 = 1 651 while g == 1 { if tb >= e { g = 0 } else { if buf[tb] == (GS_TAB as u8) { g = 0 } else { tb = tb + 1 } } } 652 if tb >= e { return 0 } 653 if gs_all_digits(buf, s, tb) == 0 { return 0 } 654 out[0] = gs_num_at(buf, tb, s) 655 let vs: i64 = tb + 1 656 var ve: i64 = vs 657 g = 1 658 while g == 1 { if ve >= e { g = 0 } else { if buf[ve] == (GS_TAB as u8) { g = 0 } else { ve = ve + 1 } } } 659 var vi: i64 = GS_VO 660 if gs_prefix_at(buf, vs, ve, "KICKOFF" as *u8) == 1 { vi = GS_VK } 661 if gs_prefix_at(buf, vs, ve, "BEAT" as *u8) == 1 { vi = GS_VB } 662 if gs_prefix_at(buf, vs, ve, "DONE" as *u8) == 1 { vi = GS_VD } 663 if gs_prefix_at(buf, vs, ve, "REAPED" as *u8) == 1 { vi = GS_VR } 664 if gs_prefix_at(buf, vs, ve, "ORPHAN-REAPED" as *u8) == 1 { vi = GS_VR } 665 out[1] = vi 666 return 1 667} 668 669// pure scan over the WHOLE buffer. meta[0]=frames meta[1]=cont meta[2]=oldest meta[3]=newest 670func gs_mine_scan(buf: *u8, n: i64, tot: *i64, meta: *i64) -> i64 { 671 var z: i64 = 0 672 while z < GS_NV { tot[z] = 0; z = z + 1 } 673 meta[0] = 0; meta[1] = 0; meta[2] = 0; meta[3] = 0 674 let fr: *i64 = sys_mmap(8*2) as *i64 675 var s: i64 = 0 676 var go: i64 = 1 677 while go == 1 { 678 if s >= n { go = 0 } 679 else { 680 var e: i64 = s 681 var g2: i64 = 1 682 while g2 == 1 { if e >= n { g2 = 0 } else { if buf[e] == (GS_NL as u8) { g2 = 0 } else { e = e + 1 } } } 683 if e > s { 684 if gs_frame(buf, s, e, fr) == 1 { 685 let ep: i64 = fr[0] 686 tot[fr[1]] = tot[fr[1]] + 1 687 meta[0] = meta[0] + 1 688 if meta[2] == 0 { meta[2] = ep } 689 if ep < meta[2] { meta[2] = ep } 690 if ep > meta[3] { meta[3] = ep } 691 } else { meta[1] = meta[1] + 1 } 692 } 693 s = e + 1 694 } 695 } 696 return meta[0] 697} 698 699func gs_mine(jrnl: *u8) -> i64 { 700 let nlp: *i64 = sys_mmap(8) as *i64 701 let buf: *u8 = sys_read_file(jrnl, nlp) 702 if (buf as i64) == 0 { gs_puts("MINE-END frames=0 reason=journal-absent verdict=RED\n" as *u8); return 1 } 703 let n: i64 = nlp[0] 704 if n <= 0 { gs_puts("MINE-END frames=0 reason=journal-empty verdict=RED\n" as *u8); return 1 } 705 706 let tot: *i64 = sys_mmap(8*GS_NV) as *i64 707 let meta: *i64 = sys_mmap(8*4) as *i64 708 gs_mine_scan(buf, n, tot, meta) 709 let frames: i64 = meta[0] 710 let cont: i64 = meta[1] 711 let oldest: i64 = meta[2] 712 let newest: i64 = meta[3] 713 if frames <= 0 { gs_puts("MINE-END frames=0 reason=no-anchored-frames verdict=RED\n" as *u8); return 1 } 714 715 // THE GRID IS SIZED FROM THE JOURNAL'S OWN SPAN. No guessed ceiling, so no bucket can overflow 716 // and no row can land outside the array by construction. 717 let d0: i64 = oldest / GS_DAY 718 let d1: i64 = newest / GS_DAY 719 let days: i64 = d1 - d0 + 1 720 let grid: *i64 = sys_mmap(8 * days * GS_NV) as *i64 721 var z: i64 = 0 722 while z < days * GS_NV { grid[z] = 0; z = z + 1 } 723 724 let fr: *i64 = sys_mmap(8*2) as *i64 725 var s: i64 = 0 726 var go: i64 = 1 727 while go == 1 { 728 if s >= n { go = 0 } 729 else { 730 var e: i64 = s 731 var g2: i64 = 1 732 while g2 == 1 { if e >= n { g2 = 0 } else { if buf[e] == (GS_NL as u8) { g2 = 0 } else { e = e + 1 } } } 733 if e > s { if gs_frame(buf, s, e, fr) == 1 { 734 let di: i64 = (fr[0] / GS_DAY) - d0 735 grid[di*GS_NV + fr[1]] = grid[di*GS_NV + fr[1]] + 1 736 } } 737 s = e + 1 738 } 739 } 740 741 let ln: *u8 = sys_mmap(gs_linecap()) 742 let now: i64 = sys_now_realtime_sec() 743 var o: i64 = sj_cat(ln, 0, "MINE-HORIZON bytes=" as *u8) 744 o = sj_catn(ln, o, n) 745 o = sj_cat(ln, o, " frames=" as *u8) 746 o = sj_catn(ln, o, frames) 747 o = sj_cat(ln, o, " cont_lines=" as *u8) 748 o = sj_catn(ln, o, cont) 749 o = sj_cat(ln, o, " oldest=" as *u8) 750 o = sj_catn(ln, o, oldest) 751 o = sj_cat(ln, o, " newest=" as *u8) 752 o = sj_catn(ln, o, newest) 753 o = sj_cat(ln, o, " span_days=" as *u8) 754 o = sj_catn(ln, o, days) 755 o = sj_cat(ln, o, " now=" as *u8) 756 o = sj_catn(ln, o, now) 757 o = sj_cat(ln, o, " coverage_complete=1\n" as *u8) 758 sys_write(1, ln, o) 759 760 // A PARTITION IS A CLAIM: CHECK THE PARTS SUM, AND PRINT THE SUM. 761 let sum: i64 = tot[GS_VK] + tot[GS_VB] + tot[GS_VD] + tot[GS_VR] + tot[GS_VO] 762 o = sj_cat(ln, 0, "MINE-PARTITION kickoff=" as *u8) 763 o = sj_catn(ln, o, tot[GS_VK]) 764 o = sj_cat(ln, o, " beat=" as *u8) 765 o = sj_catn(ln, o, tot[GS_VB]) 766 o = sj_cat(ln, o, " done=" as *u8) 767 o = sj_catn(ln, o, tot[GS_VD]) 768 o = sj_cat(ln, o, " reaped=" as *u8) 769 o = sj_catn(ln, o, tot[GS_VR]) 770 o = sj_cat(ln, o, " other=" as *u8) 771 o = sj_catn(ln, o, tot[GS_VO]) 772 o = sj_cat(ln, o, " sum=" as *u8) 773 o = sj_catn(ln, o, sum) 774 o = sj_cat(ln, o, " frames=" as *u8) 775 o = sj_catn(ln, o, frames) 776 o = sj_cat(ln, o, " reconciles=" as *u8) 777 if sum == frames { o = sj_catn(ln, o, 1) } else { o = sj_catn(ln, o, 0) } 778 ln[o] = GS_NL as u8; o = o + 1 779 sys_write(1, ln, o) 780 781 // FULL POPULATION, NOT A WINDOW: every day in the span that carries a frame is emitted, and the 782 // days that carry none are counted so emitted + empty == span. No 30-day slice standing in for 783 // the corpus. 784 var emitted: i64 = 0 785 var empty: i64 = 0 786 var di: i64 = 0 787 while di < days { 788 let k: i64 = grid[di*GS_NV + GS_VK] 789 let b: i64 = grid[di*GS_NV + GS_VB] 790 let dn: i64 = grid[di*GS_NV + GS_VD] 791 let r: i64 = grid[di*GS_NV + GS_VR] 792 let ot: i64 = grid[di*GS_NV + GS_VO] 793 if k + b + dn + r + ot == 0 { empty = empty + 1 } 794 else { 795 emitted = emitted + 1 796 o = sj_cat(ln, 0, "MINE-DAY day_epoch=" as *u8) 797 o = sj_catn(ln, o, (d0 + di) * GS_DAY) 798 o = sj_cat(ln, o, " ago_days=" as *u8) 799 o = sj_catn(ln, o, (now / GS_DAY) - (d0 + di)) 800 o = sj_cat(ln, o, " kickoff=" as *u8) 801 o = sj_catn(ln, o, k) 802 o = sj_cat(ln, o, " beat=" as *u8) 803 o = sj_catn(ln, o, b) 804 o = sj_cat(ln, o, " done=" as *u8) 805 o = sj_catn(ln, o, dn) 806 o = sj_cat(ln, o, " reaped=" as *u8) 807 o = sj_catn(ln, o, r) 808 o = sj_cat(ln, o, " other=" as *u8) 809 o = sj_catn(ln, o, ot) 810 ln[o] = GS_NL as u8; o = o + 1 811 sys_write(1, ln, o) 812 } 813 di = di + 1 814 } 815 816 // windows DERIVED from the single time definitions above, never re-typed as 1/7/30 817 var w: i64 = 0 818 while w < 3 { 819 var wd: i64 = GS_DAY / GS_DAY 820 if w == 1 { wd = GS_WEEK / GS_DAY } 821 if w == 2 { wd = GS_MONTH / GS_DAY } 822 var ak: i64 = 0 823 var ab: i64 = 0 824 var ad: i64 = 0 825 var ar: i64 = 0 826 var ao: i64 = 0 827 var covered: i64 = 0 828 var i: i64 = 0 829 while i < wd { 830 let dd: i64 = (now / GS_DAY) - i - d0 831 if dd >= 0 { if dd < days { 832 covered = covered + 1 833 ak = ak + grid[dd*GS_NV + GS_VK] 834 ab = ab + grid[dd*GS_NV + GS_VB] 835 ad = ad + grid[dd*GS_NV + GS_VD] 836 ar = ar + grid[dd*GS_NV + GS_VR] 837 ao = ao + grid[dd*GS_NV + GS_VO] 838 } } 839 i = i + 1 840 } 841 o = sj_cat(ln, 0, "MINE-WINDOW days=" as *u8) 842 o = sj_catn(ln, o, wd) 843 o = sj_cat(ln, o, " days_covered_by_journal=" as *u8) 844 o = sj_catn(ln, o, covered) 845 o = sj_cat(ln, o, " kickoff=" as *u8) 846 o = sj_catn(ln, o, ak) 847 o = sj_cat(ln, o, " beat=" as *u8) 848 o = sj_catn(ln, o, ab) 849 o = sj_cat(ln, o, " done=" as *u8) 850 o = sj_catn(ln, o, ad) 851 o = sj_cat(ln, o, " reaped=" as *u8) 852 o = sj_catn(ln, o, ar) 853 o = sj_cat(ln, o, " other=" as *u8) 854 o = sj_catn(ln, o, ao) 855 ln[o] = GS_NL as u8; o = o + 1 856 sys_write(1, ln, o) 857 w = w + 1 858 } 859 860 o = sj_cat(ln, 0, "MINE-DAYS-PARTITION emitted=" as *u8) 861 o = sj_catn(ln, o, emitted) 862 o = sj_cat(ln, o, " empty=" as *u8) 863 o = sj_catn(ln, o, empty) 864 o = sj_cat(ln, o, " span_days=" as *u8) 865 o = sj_catn(ln, o, days) 866 o = sj_cat(ln, o, " reconciles=" as *u8) 867 if emitted + empty == days { o = sj_catn(ln, o, 1) } else { o = sj_catn(ln, o, 0) } 868 ln[o] = GS_NL as u8; o = o + 1 869 sys_write(1, ln, o) 870 871 o = sj_cat(ln, 0, "MINE-END frames=" as *u8) 872 o = sj_catn(ln, o, frames) 873 var okall: i64 = 0 874 if sum == frames { if emitted + empty == days { okall = 1 } } 875 if okall == 1 { o = sj_cat(ln, o, " verdict=GREEN" as *u8) } 876 else { o = sj_cat(ln, o, " reason=partition-does-not-reconcile verdict=RED" as *u8) } 877 ln[o] = GS_NL as u8; o = o + 1 878 sys_write(1, ln, o) 879 if okall == 1 { return 0 } 880 return 1 881} 882 883func gs_t(nm: *u8, got: i64, want: i64, ctr: *i64) -> i64 { 884 ctr[1] = ctr[1] + 1 885 gs_puts(" " as *u8) 886 if got == want { ctr[0] = ctr[0] + 1; gs_puts("PASS " as *u8) } else { gs_puts("FAIL " as *u8) } 887 gs_puts(nm) 888 let ln: *u8 = sys_mmap(gs_linecap()) 889 var o: i64 = sj_cat(ln, 0, " got=" as *u8) 890 o = sj_catn(ln, o, got) 891 o = sj_cat(ln, o, " want=" as *u8) 892 o = sj_catn(ln, o, want) 893 ln[o] = GS_NL as u8; o = o + 1 894 sys_write(1, ln, o) 895 return 0 896} 897 898// fixtures are ASSEMBLED AT RUNTIME from bytes: a detector that scans source finds its own fixture, 899// and prose is source bytes too. 900func gs_q(d: *u8, p: i64) -> i64 { d[p] = GS_QUOTE as u8; return p + 1 } 901 902func gs_fixture(d: *u8) -> i64 { 903 var p: i64 = sj_cat(d, 0, "{" as *u8) 904 p = gs_q(d, p); p = sj_cat(d, p, "pm_board" as *u8); p = gs_q(d, p) 905 p = sj_cat(d, p, ":1," as *u8) 906 p = gs_q(d, p); p = sj_cat(d, p, "executive" as *u8); p = gs_q(d, p) 907 p = sj_cat(d, p, ":{" as *u8) 908 p = gs_q(d, p); p = sj_cat(d, p, "frontier_done" as *u8); p = gs_q(d, p) 909 p = sj_cat(d, p, ":252," as *u8) 910 p = gs_q(d, p); p = sj_cat(d, p, "debts_open" as *u8); p = gs_q(d, p) 911 p = sj_cat(d, p, ":2599," as *u8) 912 p = gs_q(d, p); p = sj_cat(d, p, "incidents_sev7plus" as *u8); p = gs_q(d, p) 913 p = sj_cat(d, p, ":[" as *u8) 914 p = gs_q(d, p); p = sj_cat(d, p, "a" as *u8); p = gs_q(d, p) 915 p = sj_cat(d, p, "," as *u8) 916 p = gs_q(d, p); p = sj_cat(d, p, "b" as *u8); p = gs_q(d, p) 917 p = sj_cat(d, p, "," as *u8) 918 p = gs_q(d, p); p = sj_cat(d, p, "c" as *u8); p = gs_q(d, p) 919 p = sj_cat(d, p, "]}," as *u8) 920 p = gs_q(d, p); p = sj_cat(d, p, "management" as *u8); p = gs_q(d, p) 921 p = sj_cat(d, p, ":[{" as *u8) 922 p = gs_q(d, p); p = sj_cat(d, p, "debts_open" as *u8); p = gs_q(d, p) 923 p = sj_cat(d, p, ":3}]," as *u8) 924 p = gs_q(d, p); p = sj_cat(d, p, "operations" as *u8); p = gs_q(d, p) 925 p = sj_cat(d, p, ":{" as *u8) 926 p = gs_q(d, p); p = sj_cat(d, p, "work_open" as *u8); p = gs_q(d, p) 927 p = sj_cat(d, p, ":22}," as *u8) 928 p = gs_q(d, p); p = sj_cat(d, p, "roi" as *u8); p = gs_q(d, p) 929 p = sj_cat(d, p, ":{}}" as *u8) 930 d[p] = 0 as u8 931 return p 932} 933 934// journal fixture: 3 anchored frames (one carrying an UNKNOWN verb) + 1 wrapped continuation line. 935// Days are two apart so the derived grid must span exactly 3 days. 936func gs_jfixture(d: *u8) -> i64 { 937 var p: i64 = sj_cat(d, 0, "1700000000" as *u8) 938 d[p] = GS_TAB as u8; p = p + 1 939 p = sj_cat(d, p, "KICKOFF" as *u8) 940 d[p] = GS_TAB as u8; p = p + 1 941 p = sj_cat(d, p, "ws-a" as *u8) 942 d[p] = GS_NL as u8; p = p + 1 943 p = sj_cat(d, p, "a wrapped note line that carries no leading epoch at all" as *u8) 944 d[p] = GS_NL as u8; p = p + 1 945 p = sj_cat(d, p, "1700086400" as *u8) 946 d[p] = GS_TAB as u8; p = p + 1 947 p = sj_cat(d, p, "DONE" as *u8) 948 d[p] = GS_TAB as u8; p = p + 1 949 p = sj_cat(d, p, "ws-a" as *u8) 950 d[p] = GS_NL as u8; p = p + 1 951 p = sj_cat(d, p, "1700172800" as *u8) 952 d[p] = GS_TAB as u8; p = p + 1 953 p = sj_cat(d, p, "NOTAREALVERB" as *u8) 954 d[p] = GS_TAB as u8; p = p + 1 955 p = sj_cat(d, p, "ws-b" as *u8) 956 d[p] = GS_NL as u8; p = p + 1 957 d[p] = 0 as u8 958 return p 959} 960 961// finance fixture: monthly_cost_cents DELIBERATELY appears twice with different values, once in 962// spend_estimate and once in roi, exactly as nx_eff_board emits it. 963func gs_ffixture(d: *u8) -> i64 { 964 var p: i64 = sj_cat(d, 0, "{" as *u8) 965 p = gs_q(d, p); p = sj_cat(d, p, "efficiency_kpi" as *u8); p = gs_q(d, p) 966 p = sj_cat(d, p, ":{" as *u8) 967 p = gs_q(d, p); p = sj_cat(d, p, "cost_per_action_cents" as *u8); p = gs_q(d, p) 968 p = sj_cat(d, p, ":214}," as *u8) 969 p = gs_q(d, p); p = sj_cat(d, p, "spend_estimate" as *u8); p = gs_q(d, p) 970 p = sj_cat(d, p, ":{" as *u8) 971 p = gs_q(d, p); p = sj_cat(d, p, "monthly_cost_cents" as *u8); p = gs_q(d, p) 972 p = sj_cat(d, p, ":24747471}," as *u8) 973 p = gs_q(d, p); p = sj_cat(d, p, "roi" as *u8); p = gs_q(d, p) 974 p = sj_cat(d, p, ":{" as *u8) 975 p = gs_q(d, p); p = sj_cat(d, p, "monthly_value_cents" as *u8); p = gs_q(d, p) 976 p = sj_cat(d, p, ":21800," as *u8) 977 p = gs_q(d, p); p = sj_cat(d, p, "monthly_cost_cents" as *u8); p = gs_q(d, p) 978 p = sj_cat(d, p, ":99999999}," as *u8) 979 p = gs_q(d, p); p = sj_cat(d, p, "feedback" as *u8); p = gs_q(d, p) 980 p = sj_cat(d, p, ":[]}" as *u8) 981 d[p] = 0 as u8 982 return p 983} 984 985// law fixture: `measured` appears in BOTH law objects with different values, exactly as the warden 986// emits it across its eleven laws. 987func gs_lfixture(d: *u8) -> i64 { 988 var p: i64 = sj_cat(d, 0, "{" as *u8) 989 p = gs_q(d, p); p = sj_cat(d, p, "laws" as *u8); p = gs_q(d, p) 990 p = sj_cat(d, p, ":[{" as *u8) 991 p = gs_q(d, p); p = sj_cat(d, p, "law" as *u8); p = gs_q(d, p) 992 p = sj_cat(d, p, ":" as *u8) 993 p = gs_q(d, p); p = sj_cat(d, p, "L003" as *u8); p = gs_q(d, p) 994 p = sj_cat(d, p, "," as *u8) 995 p = gs_q(d, p); p = sj_cat(d, p, "measured" as *u8); p = gs_q(d, p) 996 p = sj_cat(d, p, ":977},{" as *u8) 997 p = gs_q(d, p); p = sj_cat(d, p, "law" as *u8); p = gs_q(d, p) 998 p = sj_cat(d, p, ":" as *u8) 999 p = gs_q(d, p); p = sj_cat(d, p, "L004" as *u8); p = gs_q(d, p) 1000 p = sj_cat(d, p, "," as *u8) 1001 p = gs_q(d, p); p = sj_cat(d, p, "measured" as *u8); p = gs_q(d, p) 1002 p = sj_cat(d, p, ":5}]," as *u8) 1003 p = gs_q(d, p); p = sj_cat(d, p, "laws_breached" as *u8); p = gs_q(d, p) 1004 p = sj_cat(d, p, ":9," as *u8) 1005 p = gs_q(d, p); p = sj_cat(d, p, "breach_weight_permil" as *u8); p = gs_q(d, p) 1006 p = sj_cat(d, p, ":807}" as *u8) 1007 d[p] = 0 as u8 1008 return p 1009} 1010 1011func gs_selftest(scratch: *u8) -> i64 { 1012 let ctr: *i64 = sys_mmap(8*2) as *i64 1013 ctr[0] = 0 1014 ctr[1] = 0 1015 gs_puts("nx_growth_series selftest\n" as *u8) 1016 1017 let j: *u8 = sys_mmap(gs_linecap()) 1018 let jn: i64 = gs_fixture(j) 1019 let ex: *i64 = sys_mmap(8*2) as *i64 1020 let op: *i64 = sys_mmap(8*2) as *i64 1021 gs_region(j, jn, "executive" as *u8, "management" as *u8, ex) 1022 gs_region(j, jn, "operations" as *u8, "roi" as *u8, op) 1023 // ASSERT THE FIXTURE REACHED THE CONDITION BEFORE ASSERTING THE OUTCOME. 1024 gs_t("fixture-exec-region-nonempty" as *u8, ex[1] > ex[0], 1, ctr) 1025 gs_t("fixture-ops-region-nonempty" as *u8, op[1] > op[0], 1, ctr) 1026 gs_t("exec-frontier-done" as *u8, gs_json_int(j, ex[0], ex[1], "frontier_done" as *u8), 252, ctr) 1027 gs_t("neg-control-region-anchor-exec-debts" as *u8, gs_json_int(j, ex[0], ex[1], "debts_open" as *u8), 2599, ctr) 1028 gs_t("neg-control-region-anchor-mgmt-debts" as *u8, gs_json_int(j, ex[1], jn, "debts_open" as *u8), 3, ctr) 1029 gs_t("incident-count-not-list" as *u8, gs_json_count(j, ex[0], ex[1], "incidents_sev7plus" as *u8), 3, ctr) 1030 gs_t("ops-work-open" as *u8, gs_json_int(j, op[0], op[1], "work_open" as *u8), 22, ctr) 1031 gs_t("neg-control-absent-field-is-minus-one" as *u8, gs_json_int(j, ex[0], ex[1], "no_such_key" as *u8), GS_ABSENT, ctr) 1032 gs_t("neg-control-absent-array-is-minus-one" as *u8, gs_json_count(j, ex[0], ex[1], "no_such_arr" as *u8), GS_ABSENT, ctr) 1033 1034 gs_t("neg-control-self-referential-delta-abstains" as *u8, gs_observed(1700000000, 1700000000), 0, ctr) 1035 gs_t("neg-control-no-baseline-abstains" as *u8, gs_observed(0, 1700000000), 0, ctr) 1036 gs_t("observed-requires-two-distinct-samples" as *u8, gs_observed(1700000000, 1700086400), 1, ctr) 1037 1038 let row: *u8 = "GROWTH epoch=1700000000 frontier_done=100 debts_open=-1 verdict=GREEN" as *u8 1039 let rn: i64 = gs_strlen(row) 1040 gs_t("row-roundtrip-epoch" as *u8, gs_row_field(row, 0, rn, "epoch" as *u8), 1700000000, ctr) 1041 gs_t("row-roundtrip-mid-field" as *u8, gs_row_field(row, 0, rn, "frontier_done" as *u8), 100, ctr) 1042 gs_t("row-roundtrip-negative-preserved" as *u8, gs_row_field(row, 0, rn, "debts_open" as *u8), GS_ABSENT, ctr) 1043 // the length-free search must find a literal the caller never measured 1044 gs_t("findz-computes-its-own-width" as *u8, gs_findz(row, 0, rn, "verdict=GREEN" as *u8) > 0, 1, ctr) 1045 1046 // ---- mine teeth: exact counts on a runtime-built journal fixture ---- 1047 let jf: *u8 = sys_mmap(gs_linecap()) 1048 let jfn: i64 = gs_jfixture(jf) 1049 let tot: *i64 = sys_mmap(8*GS_NV) as *i64 1050 let meta: *i64 = sys_mmap(8*4) as *i64 1051 gs_mine_scan(jf, jfn, tot, meta) 1052 gs_t("mine-frames-counted" as *u8, meta[0], 3, ctr) 1053 // A WRAPPED NOTE IS NOT A FRAME and must not inflate the delivery count. 1054 gs_t("neg-control-continuation-not-a-frame" as *u8, meta[1], 1, ctr) 1055 gs_t("mine-kickoff" as *u8, tot[GS_VK], 1, ctr) 1056 gs_t("mine-done" as *u8, tot[GS_VD], 1, ctr) 1057 // UNKNOWN IS ITS OWN BUCKET: an unrecognised verb must never land in a known one, because the 1058 // bucket it lands in becomes the number somebody plans against. 1059 gs_t("neg-control-unknown-verb-own-bucket" as *u8, tot[GS_VO], 1, ctr) 1060 gs_t("neg-control-unknown-verb-not-in-done" as *u8, tot[GS_VD], 1, ctr) 1061 gs_t("mine-partition-sums" as *u8, tot[GS_VK]+tot[GS_VB]+tot[GS_VD]+tot[GS_VR]+tot[GS_VO], meta[0], ctr) 1062 gs_t("mine-span-is-derived-from-data" as *u8, (meta[3]/GS_DAY) - (meta[2]/GS_DAY) + 1, 3, ctr) 1063 gs_t("neg-control-absent-journal-refuses" as *u8, gs_mine("knowledge/status/__nx_growth_no_such_journal" as *u8), 1, ctr) 1064 1065 // A CENSUS THAT CANNOT RUN MUST ABSTAIN, NOT REPORT ZERO ADOPTION. Reporting 0 here would be an 1066 // estate with no adopted capability at all -- an emergency -- manufactured out of a missing binary. 1067 gs_t("neg-control-adoption-census-absent-abstains" as *u8, gs_axis_adoption("/tmp/__nx_no_such_adopt_census_elf" as *u8), GS_ABSENT, ctr) 1068 // AN OWNERSHIP CENSUS THAT CANNOT RUN MUST ABSTAIN, NOT REPORT ZERO OWNERSHIP. Reporting 0 here 1069 // would be an estate where nothing has an owner -- a governance emergency -- manufactured out of a 1070 // missing binary. The axis returns 0 (did not fill) and the fields stay at their -1 sentinel. 1071 let ov: *i64 = sys_mmap(8*GS_NF) as *i64 1072 var oz: i64 = 0 1073 while oz < GS_NF { ov[oz] = GS_ABSENT; oz = oz + 1 } 1074 gs_t("neg-control-owner-census-absent-does-not-fill" as *u8, gs_axis_owner("/tmp/__nx_no_such_registrymine_elf" as *u8, ov), 0, ctr) 1075 gs_t("neg-control-owner-census-absent-leaves-sentinel" as *u8, ov[18], GS_ABSENT, ctr) 1076 1077 // ---- finance teeth ---- 1078 let ff: *u8 = sys_mmap(gs_linecap()) 1079 let ffn: i64 = gs_ffixture(ff) 1080 let ek: *i64 = sys_mmap(8*2) as *i64 1081 let se: *i64 = sys_mmap(8*2) as *i64 1082 let ro: *i64 = sys_mmap(8*2) as *i64 1083 gs_region(ff, ffn, "efficiency_kpi" as *u8, "spend_estimate" as *u8, ek) 1084 gs_region(ff, ffn, "spend_estimate" as *u8, "roi" as *u8, se) 1085 gs_region(ff, ffn, "roi" as *u8, "feedback" as *u8, ro) 1086 gs_t("finance-cost-per-action" as *u8, gs_json_int(ff, ek[0], ek[1], "cost_per_action_cents" as *u8), 214, ctr) 1087 // THE MONEY REGION TOOTH. monthly_cost_cents exists in BOTH spend_estimate and roi with DIFFERENT 1088 // values; an unregioned parse binds the executive tier to whichever appears first in the byte 1089 // stream. These two teeth assert each region returns ITS OWN number, so the failure is impossible 1090 // rather than merely unlikely. 1091 gs_t("neg-control-money-region-is-not-the-roi-copy" as *u8, gs_json_int(ff, se[0], se[1], "monthly_cost_cents" as *u8), 24747471, ctr) 1092 gs_t("neg-control-roi-region-holds-the-other-copy" as *u8, gs_json_int(ff, ro[0], ro[1], "monthly_cost_cents" as *u8), 99999999, ctr) 1093 gs_t("finance-value-floor-read" as *u8, gs_json_int(ff, ro[0], ro[1], "monthly_value_cents" as *u8), 21800, ctr) 1094 1095 // ---- governance teeth ---- 1096 let lf: *u8 = sys_mmap(gs_linecap()) 1097 let lfn: i64 = gs_lfixture(lf) 1098 gs_t("laws-breached-toplevel" as *u8, gs_json_int(lf, 0, lfn, "laws_breached" as *u8), 9, ctr) 1099 gs_t("breach-weight-toplevel" as *u8, gs_json_int(lf, 0, lfn, "breach_weight_permil" as *u8), 807, ctr) 1100 // THE LAW-ROW BOUNDING TOOTH. `measured` exists in EVERY law object; an unbounded read returns the 1101 // FIRST one regardless of which law was asked for. These assert the L003 window returns 977 and 1102 // that the very next law's own value is a different number, so a silent bleed is impossible. 1103 let la: i64 = gs_findz(lf, 0, lfn, "L003" as *u8) 1104 let lb: i64 = gs_findz(lf, la, lfn, "L004" as *u8) 1105 gs_t("fixture-law-rows-both-found" as *u8, lb > la, 1, ctr) 1106 gs_t("neg-control-L003-measured-is-bounded" as *u8, gs_json_int(lf, la, lb, "measured" as *u8), 977, ctr) 1107 gs_t("neg-control-L004-holds-its-own" as *u8, gs_json_int(lf, lb, lfn, "measured" as *u8), 5, ctr) 1108 1109 gs_t("neg-control-empty-series-refuses" as *u8, gs_report("knowledge/status/__nx_growth_no_such_file" as *u8), 1, ctr) 1110 1111 let one: *u8 = "GROWTH epoch=1700000000 frontier_done=1 verdict=GREEN\n" as *u8 1112 gs_append(scratch, one, gs_strlen(one)) 1113 gs_t("neg-control-one-row-is-not-a-trend" as *u8, gs_report(scratch), 2, ctr) 1114 1115 let ln: *u8 = sys_mmap(gs_linecap()) 1116 var o: i64 = sj_cat(ln, 0, "passed " as *u8) 1117 o = sj_catn(ln, o, ctr[0]) 1118 ln[o] = GS_SLASH as u8; o = o + 1 1119 o = sj_catn(ln, o, ctr[1]) 1120 if ctr[0] == ctr[1] { o = sj_cat(ln, o, " verdict=GREEN" as *u8) } else { o = sj_cat(ln, o, " verdict=RED" as *u8) } 1121 ln[o] = GS_NL as u8; o = o + 1 1122 sys_write(1, ln, o) 1123 if ctr[0] == ctr[1] { return 0 } 1124 return 1 1125} 1126 1127func main(argc: i64, argv: *i64) -> i64 { 1128 var mode: *u8 = "beat" as *u8 1129 if argc > 1 { mode = argv[1] as *u8 } 1130 var logp: *u8 = "knowledge/status/growth_series.log" as *u8 1131 if argc > 2 { logp = argv[2] as *u8 } 1132 var boardelf: *u8 = "/volume1/homes/elderwesto/nishihost/nx_pm_board.elf" as *u8 1133 if argc > 3 { boardelf = argv[3] as *u8 } 1134 1135 var adoptelf: *u8 = "/volume1/homes/elderwesto/nishihost/nx_adopt.elf" as *u8 1136 if argc > 4 { adoptelf = argv[4] as *u8 } 1137 var effelf: *u8 = "/volume1/homes/elderwesto/nishihost/nx_eff_board.elf" as *u8 1138 if argc > 5 { effelf = argv[5] as *u8 } 1139 var lawelf: *u8 = "/volume1/homes/elderwesto/nishihost/nx_law_warden.elf" as *u8 1140 if argc > 6 { lawelf = argv[6] as *u8 } 1141 var ownelf: *u8 = "/volume1/homes/elderwesto/nishihost/nx_registrymine.elf" as *u8 1142 if argc > 7 { ownelf = argv[7] as *u8 } 1143 if gs_streq(mode, "beat" as *u8) == 1 { let r: i64 = gs_beat(logp, boardelf, adoptelf, effelf, lawelf, ownelf); sys_exit(r); return r } 1144 if gs_streq(mode, "report" as *u8) == 1 { let r: i64 = gs_report(logp); sys_exit(r); return r } 1145 if gs_streq(mode, "mine" as *u8) == 1 { 1146 var jr: *u8 = "knowledge/status/ws_sync.jrnl" as *u8 1147 if argc > 2 { jr = argv[2] as *u8 } 1148 let r: i64 = gs_mine(jr); sys_exit(r); return r 1149 } 1150 if gs_streq(mode, "selftest" as *u8) == 1 { 1151 var sc: *u8 = "/tmp/nx_growth_series_selftest.log" as *u8 1152 if argc > 2 { sc = argv[2] as *u8 } 1153 let r: i64 = gs_selftest(sc); sys_exit(r); return r 1154 } 1155 // A FLAG THAT ACCEPTS ANY SPELLING CANNOT REPORT A TYPO: unknown verbs REFUSE with the list. 1156 gs_werr("nx_growth_series: unknown verb. usage: beat [log] [board-elf] | report [log] | mine [journal] | selftest [scratchlog]\n" as *u8) 1157 sys_exit(3) 1158 return 3 1159}