nx_swcompare_lib.nx source
↩ module page · 3731 lines · 262144 B
1// AUTO-EXTRACTED shared base (nx_oo_extract). license_tier: ORIGINAL No hw writes (Rule 26).
2// functions: w,wc,wn,wj,wq,kv_s,kv_n,c_read,streq,starts,scopy,splitpipe,wnote,rp_base,rp_publish,rp_json,refs_pass
3import "nx_syscalls.nx"
4import "nx_symdecl_lib.nx"
5import "nx_market_ladder_lib.nx"
6import "nx_brand_tokens.nx" // the estate's design-token SSOT -- sc_theme_pass composes it, never a second parser
7import "nx_lineconf_lib.nx" // line-anchored conf reader, ONE owner -- never a private key=value parser
8import "nx_estate_path.nx" // THE ONE probe order for a status artifact -- a stamp written from the serving root must resolve from CWD=buildroot (gauge_pass, gaps_pass)
9import "nx_imgattr_lib.nx" // the ONE definition of how an attribute value and an img tag are written
10import "nx_evprofile_lib.nx" // THE ONE READER of the /compare evidence stamp -- evj_pass below PROJECTS
11import "nx_bench_receipt_lib.nx" // THE ONE READER of a <dom>.bench benchmark receipt -- bench_pass below RENDERS it (2026-09-01)
12import "nx_barfresh_lib.nx" // THE ONE bar-age ruler (2026-09-06) -- plan_pass renders each sotatarget with its sotabar month and freshness state
13import "nx_cdmap_lib.nx" // THE ONE centrality/distinctiveness ruler (2026-09-15) -- cdmap_pass below RENDERS the four-quadrant position map and the day spine from the SAME cells the matrix grades
14import "nx_leaderboard_lib.nx" // THE ONE reader of <dom>.leaderboard (EC44, 2026-09-15) -- lbp_pass below RENDERS the public board with the estate's rank recomputed from the scores
15import "nx_cdmap_raster_lib.nx" // THE ONE position-map rasteriser (datavis DV6, 2026-09-15) -- cdp_export writes the SVG and PNG twins
16import "nx_chartlay_lib.nx" // THE ONE chart-layout ruler (datavis DV1, 2026-09-15) -- cdmap_pass fits its axes, seats its labels and grades its own readability through it
17import "nx_compare_growth_json.nx"
18import "nx_ladder_lib.nx" // THE ONE ladder ruler (2026-09-06) -- plan_pass renders the targets, the rung-role table and the NOT DECLARED notice
19import "nx_gauge_lib.nx" // THE ONE gauge-heartbeat ruler (codeeffectiveness CE9, 2026-09-06) -- gauge_pass below RENDERS a <dom>.gauge row with the SAME classifier the writing beat uses, so a stale gauge reads STALE and never zero
20import "nx_costest_lib.nx" // THE ONE cost estimator (2026-09-16) -- assets_pass below prices the lift to replace each foreign asset and converts u to hours through the calibration ledger nx_costcal writes
21import "nx_assets_lib.nx" // THE ONE reader of <dom>.assets (sovereignty SV13, 2026-09-16) -- assets_pass below RENDERS every foreign asset in the run path with its licence, bytes, replacement rung and lift
22import "nx_treatment_lib.nx" // THE ONE treatment ruler (ecosystem EC49, 2026-09-16) -- plan_pass judges every treat row against the same evidence the ranker reads and renders the Treatment verdict on every page
23import "nx_tool_run.nx" // the clock DESIRED plane is read through ONE nx_store_put fork per page, the lane the ranker already uses
24 // it into api.json. Its closure adds NOTHING new to this lib: nx_lineconf_lib
25 // above already imports nx_estate_path, and nx_swcompare_matrix already
26 // imports both this base AND nx_evprofile_lib and compiles, so the two
27 // symbol sets are proven compatible rather than assumed so.
28func w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 }
29func wc(fd: i64, code: i64) -> i64 { let t: *u8 = sys_mmap(2); t[0] = code as u8; sys_write(fd, t, 1); return 0 }
30func wn(fd: i64, v: i64) -> i64 {
31 var m: i64 = v; if m < 0 { w(fd, "-" as *u8); m = 0 - m }
32 let t: *u8 = sys_mmap(24); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 }
33 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
34 let o: *u8 = sys_mmap(24); var i: i64 = 0; while i < k { o[i] = t[k-1-i]; i = i + 1 } sys_write(fd, o, k); return 0
35}
36func wj(fd: i64, s: *u8) -> i64 {
37 var i: i64 = 0
38 while s[i] != (0 as u8) { let c: i64 = s[i] as i64
39 if c == 34 { wc(fd, 92); wc(fd, 34) } else { if c == 92 { wc(fd, 92); wc(fd, 92) } else { if c < 32 { wc(fd, 32) } else { wc(fd, c) } } }
40 i = i + 1 }
41 return 0
42}
43func wq(fd: i64) -> i64 { wc(fd, 34); return 0 }
44func kv_s(fd: i64, key: *u8, val: *u8) -> i64 { wq(fd); w(fd, key); wq(fd); wc(fd, 58); wq(fd); wj(fd, val); wq(fd); return 0 }
45func kv_n(fd: i64, key: *u8, v: i64) -> i64 { wq(fd); w(fd, key); wq(fd); wc(fd, 58); wn(fd, v); return 0 }
46func c_read(path: *u8, buf: *u8, cap: i64) -> i64 {
47 let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 - 1 }
48 var tot: i64 = 0
49 while tot < cap { let r: i64 = sys_read(fd, (buf as i64 + tot) as *u8, cap - tot); if r <= 0 { break } tot = tot + r }
50 sys_close(fd); return tot
51}
52func streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 }
53func starts(s: *u8, pfx: *u8) -> i64 { var i: i64 = 0; while pfx[i] != (0 as u8) { if s[i] != pfx[i] { return 0 } i = i + 1 } return 1 }
54func scopy(dst: *u8, doff: i64, src: *u8) -> i64 { var i: i64 = 0; while src[i] != (0 as u8) { dst[doff+i] = src[i]; i = i + 1 } return doff + i }
55func splitpipe(s: *u8, fld: *i64, maxf: i64) -> i64 {
56 var c: i64 = 1; fld[0] = s as i64; var i: i64 = 0
57 while s[i] != (0 as u8) { if s[i] == (124 as u8) { s[i] = 0 as u8; if c < maxf { fld[c] = (s as i64) + i + 1; c = c + 1 } } i = i + 1 }
58 return c
59}
60func wnote(fd: i64, s: *u8) -> i64 {
61 var i: i64 = 0
62 while s[i] != (0 as u8) {
63 var emitted: i64 = 0
64 if s[i] == (91 as u8) { if s[i+1] == (64 as u8) {
65 var kl: i64 = 0
66 while s[i+2+kl] != (0 as u8) { if s[i+2+kl] == (93 as u8) { break } kl = kl + 1 }
67 if s[i+2+kl] == (93 as u8) { if kl > 0 {
68 w(fd, "<a class='cite' href='" as *u8); wc(fd, 35); w(fd, "ref-" as *u8)
69 var q: i64 = 0
70 while q < kl { wc(fd, s[i+2+q] as i64); q = q + 1 }
71 w(fd, "'>[" as *u8)
72 q = 0
73 while q < kl { wc(fd, s[i+2+q] as i64); q = q + 1 }
74 w(fd, "]</a>" as *u8)
75 i = i + 2 + kl + 1
76 emitted = 1
77 } }
78 } }
79 // ESCAPE THE TAG DELIMITERS, AND DELIBERATELY NOT '&'. Note prose is PROSE, so a '<' in it must
80 // render as TEXT: emitted raw it injects a live element into the published page. MEASURED
81 // 2026-08-26 -- a browser note reading "an <img> is an INLINE_BLOCK" emitted a real empty <img>,
82 // which took that page to a11y-issues=1 and made its whole-page asset claim UNPROVABLE, because
83 // the verifier counted an img tag whose src it could never resolve. One funnel, so both
84 // generators and every domain are fixed at once.
85 // '&' IS LEFT ALONE ON PURPOSE: 48 notes across the fleet (corpus_complete=1) carry intentional
86 // entities such as —, and escaping it would publish those literally on all 48. That is the
87 // imprecision chosen here, named rather than left for the next reader to rediscover.
88 if emitted == 0 {
89 let c: i64 = s[i] as i64
90 if c == 60 { w(fd, "<" as *u8) } else { if c == 62 { w(fd, ">" as *u8) } else { wc(fd, c) } }
91 i = i + 1
92 }
93 }
94 return 0
95}
96// ---- RIVAL-CLAIM PROVENANCE (2026-09-05) ----------------------------------------------------------------
97// Every Yes, Best or Part code in a rival column is a CLAIM about someone else's product, and until this
98// pass those codes were feature-observation reads with nothing behind them: the refs gate proves every
99// declared reference is cited and every mark resolves, but nothing asked whether a row that grades a rival
100// cites anything at all. Measured while evaluating DanceXR against charsim: eleven rows of rival codes typed
101// from a vendor read, zero marks, indistinguishable on the page from a row backed by a pinned mirror.
102// ONE classifier here, read by both generators (the refs_pass precedent), so the split cannot drift:
103// RV_NONE every rival code is 0 -- the row claims nothing about a rival
104// RV_CITED at least one rival code is non-zero AND the note carries a reference mark ( [@key] )
105// RV_UNCITED at least one rival code is non-zero and the note carries no mark: an observation read
106// A mark proves a mirror exists and is pinned (the refs gate's job); it does not prove the mirror SUPPORTS
107// the code -- that residual is stated on the page, never hidden behind the badge.
108const RV_NONE: i64 = 0
109const RV_CITED: i64 = 1
110const RV_UNCITED: i64 = 2
111func rv_code(s: *u8) -> i64 {
112 var v: i64 = 0
113 var any: i64 = 0
114 var i: i64 = 0
115 while s[i] != (0 as u8) { let c: i64 = s[i] as i64; if c >= 48 { if c <= 57 { v = v * 10 + (c - 48); any = 1 } } i = i + 1 }
116 if any == 0 { return 0 }
117 return v
118}
119func rv_note_cited(note: *u8) -> i64 {
120 var i: i64 = 0
121 while note[i] != (0 as u8) { if note[i] == (91 as u8) { if note[i+1] == (64 as u8) { return 1 } } i = i + 1 }
122 return 0
123}
124func rv_class(note: *u8, rf: *i64, rr: i64, stride: i64, ncol: i64) -> i64 {
125 var claims: i64 = 0
126 var cj: i64 = 0
127 while cj < ncol { if rv_code(rf[rr*stride + 4 + cj] as *u8) != 0 { claims = claims + 1 } cj = cj + 1 }
128 if claims == 0 { return RV_NONE }
129 if rv_note_cited(note) == 1 { return RV_CITED }
130 return RV_UNCITED
131}
132// the SOTA dialect grades with letters: B = Best, Y = Yes, ~ = Part are positive claims about a rival; N and blank are not.
133// ONE claim rule per dialect, ONE note rule for both, so the two generators cannot split on what counts as a claim.
134func rv_grade_claims(g: *u8) -> i64 { if g[0] == (66 as u8) { return 1 } if g[0] == (89 as u8) { return 1 } if g[0] == (126 as u8) { return 1 } return 0 }
135func rv_class_grades(note: *u8, rf: *i64, rr: i64, stride: i64, first: i64, count: i64) -> i64 {
136 var claims: i64 = 0
137 var cj: i64 = 0
138 while cj < count { if rv_grade_claims(rf[rr*stride + first + cj] as *u8) == 1 { claims = claims + 1 } cj = cj + 1 }
139 if claims == 0 { return RV_NONE }
140 if rv_note_cited(note) == 1 { return RV_CITED }
141 return RV_UNCITED
142}
143func rv_name(c: i64) -> *u8 {
144 if c == RV_CITED { return "CITED" as *u8 }
145 if c == RV_UNCITED { return "UNCITED" as *u8 }
146 return "NONE" as *u8
147}
148
149func rp_base(p: *u8) -> *u8 {
150 var i: i64 = 0
151 var last: i64 = 0
152 while p[i] != (0 as u8) { if p[i] == (47 as u8) { last = i + 1 } i = i + 1 }
153 return ((p as i64) + last) as *u8
154}
155func rp_publish(mir: *u8, dom: *u8) -> i64 {
156 let src: *u8 = sys_mmap(700)
157 var so: i64 = scopy(src, 0, "../" as *u8)
158 so = scopy(src, so, mir); src[so] = 0 as u8
159 let ln: *i64 = sys_mmap(16) as *i64
160 let body: *u8 = sys_read_file(src, ln)
161 if (body as i64) == 0 { return 0 }
162 if ln[0] <= 0 { return 0 }
163 let dir: *u8 = sys_mmap(700)
164 var dd: i64 = scopy(dir, 0, "../sites/nishifamily/compare/" as *u8)
165 dd = scopy(dir, dd, dom); dd = scopy(dir, dd, "/refs" as *u8); dir[dd] = 0 as u8
166 sys_mkdir(dir, MODE_0755)
167 let fin: *u8 = sys_mmap(700)
168 var fo: i64 = scopy(fin, 0, dir); fo = scopy(fin, fo, "/" as *u8); fo = scopy(fin, fo, rp_base(mir)); fin[fo] = 0 as u8
169 let tmp: *u8 = sys_mmap(700)
170 var to2: i64 = scopy(tmp, 0, fin); to2 = scopy(tmp, to2, ".tmp" as *u8); tmp[to2] = 0 as u8
171 let fd: i64 = sys_openat_wr(tmp, MODE_0644)
172 if fd < 0 { sys_free_file(body, ln[0]); return 0 }
173 let wrote: i64 = sys_write(fd, body, ln[0])
174 sys_close(fd)
175 sys_free_file(body, ln[0])
176 if wrote != ln[0] { return 0 }
177 if sys_renameat(tmp, fin) < 0 { return 0 }
178 return 1
179}
180
181// ---- THE REDISTRIBUTION GATE, ADDED 2026-08-25 ----
182// rp_publish above copies a stored third-party mirror into the PUBLIC docroot, and rp_html then links
183// it as "read in our library". THAT IS REDISTRIBUTION OF SOMEONE ELSE'S WORK, and until today nothing
184// on that path asked whether the licence permits it -- on 80 of the 84 domains carrying a .refs file.
185// The .refs `class` field is a SOURCE-TYPE vocabulary (published-paper, vendor-doc, dataset...), never
186// a rights vocabulary, so it could not have answered the question even in principle.
187//
188// RIGHTS ARE DATA (knowledge/refs_redistribute.conf), never code: clearing a class costs a row edit
189// AFTER someone reads a licence, not a rebuild. The encoding matches nx_licgate_lib and nx_acquire_lib
190// (0 NO / 1 REVIEW / 2 YES) so the three rulers cannot disagree about direction.
191const RP_NO: i64 = 0
192const RP_REVIEW: i64 = 1
193const RP_YES: i64 = 2
194const RP_KEYCAP: i64 = 128
195
196// AN ABSENT ROW IS A REFUSAL, NOT A PERMISSION. lcf_int_of returns LCF_MISS (negative) for a missing
197// key, so a class nobody has adjudicated -- including a brand-new vocabulary word arriving in a future
198// .refs file -- can never show up as an accidental YES. Silence is never permission.
199func rp_may_republish(cls: *u8) -> i64 {
200 let key: *u8 = sys_mmap(RP_KEYCAP)
201 var k: i64 = scopy(key, 0, "class_" as *u8)
202 k = scopy(key, k, cls); key[k] = 0 as u8
203 let v: i64 = lcf_int_of("knowledge/refs_redistribute.conf" as *u8, key)
204 if v < 0 { return RP_NO }
205 if v > RP_YES { return RP_NO }
206 return v
207}
208
209// THE GATE IN FRONT OF THE COPIER.
210// arm=0 (today) is MEASURE-ONLY: behaviour is byte-identical to before, so no published page changes
211// and no link disappears. That is the ONLY way to land this without silently stripping a link from 80
212// domains in a single regen. arm=1 ENFORCES, and flipping it is an OPERATOR decision about a public
213// surface -- the conf says so in its own words.
214// A missing or non-numeric arm row reads LCF_MISS (negative), which is not 1, so a corrupted conf
215// fails toward TODAY'S behaviour rather than toward an unannounced fleet-wide link removal. That is
216// deliberately the opposite default from rp_may_republish: an unreadable POLICY must not silently
217// change a public surface, while an unadjudicated CLASS must never grant a right.
218func rp_publish_gated(mir: *u8, dom: *u8, cls: *u8) -> i64 {
219 let arm: i64 = lcf_int_of("knowledge/refs_redistribute.conf" as *u8, "arm" as *u8)
220 if arm == 1 {
221 if rp_may_republish(cls) != RP_YES { return 0 }
222 }
223 return rp_publish(mir, dom)
224}
225
226func rp_json(fld: *i64, count: i64) -> i64 {
227 if count == 0 { wc(1, 44); wq(1); w(1, "refs" as *u8); wq(1); wc(1, 58); wc(1, 91) } else { wc(1, 44) }
228 wc(1, 123)
229 kv_s(1, "key" as *u8, fld[1] as *u8); wc(1, 44)
230 kv_s(1, "cite" as *u8, fld[2] as *u8); wc(1, 44)
231 kv_s(1, "url" as *u8, fld[3] as *u8); wc(1, 44)
232 kv_s(1, "mirror" as *u8, fld[4] as *u8); wc(1, 44)
233 kv_s(1, "pin" as *u8, fld[5] as *u8); wc(1, 44)
234 kv_s(1, "accessed" as *u8, fld[6] as *u8); wc(1, 44)
235 kv_s(1, "class" as *u8, fld[7] as *u8); wc(1, 44)
236 kv_s(1, "grounds" as *u8, fld[8] as *u8)
237 wc(1, 125)
238 return 0
239}
240// ---- rp_html LIFTED INTO THE BASE 2026-08-23 (lane L). It was a byte-identical copy in BOTH generators
241// while refs_pass here called it as a dangling callback, so nothing else could import this lib (a gate
242// composing watch_pass failed to link on rp_html). One copy now; the only per-generator difference --
243// the section header prose -- travels as the hdr argument. ----
244func rp_html(fld: *i64, count: i64, dom: *u8, hdr: *u8) -> i64 {
245 if count == 0 { w(1, hdr) }
246 w(1, "<li id='ref-" as *u8); w(1, fld[1] as *u8); w(1, "'><span class='rkey'>[" as *u8); w(1, fld[1] as *u8); w(1, "]</span> " as *u8)
247 w(1, fld[2] as *u8)
248 w(1, " <span class='rlinks'><a href='" as *u8); w(1, fld[3] as *u8); w(1, "'>publisher</a>" as *u8)
249 if streq(fld[4] as *u8, "-" as *u8) == 0 {
250 if rp_publish_gated(fld[4] as *u8, dom, fld[7] as *u8) == 1 {
251 w(1, " · <a href='/compare/" as *u8); w(1, dom); w(1, "/refs/" as *u8); w(1, rp_base(fld[4] as *u8)); w(1, "'><b>read in our library</b></a> <code>" as *u8); w(1, fld[4] as *u8); w(1, "</code>" as *u8)
252 } else {
253 w(1, " · mirror <code>" as *u8); w(1, fld[4] as *u8); w(1, "</code>" as *u8)
254 }
255 }
256 if streq(fld[5] as *u8, "-" as *u8) == 0 { w(1, " · pin <code>" as *u8); w(1, fld[5] as *u8); w(1, "</code>" as *u8) }
257 if streq(fld[6] as *u8, "-" as *u8) == 0 { w(1, " · accessed " as *u8); w(1, fld[6] as *u8) }
258 w(1, " · <span class='rgrade'>" as *u8); w(1, fld[7] as *u8); w(1, "</span></span>" as *u8)
259 w(1, "<span class='rg'>Grounds: " as *u8); w(1, fld[8] as *u8); w(1, "</span></li>\n" as *u8)
260 return 0
261}
262func refs_pass(path: *u8, bufz: *u8, capz: i64, mode: i64, dom: *u8, hdr: *u8) -> i64 {
263 // SAME CAP, SAME REMOVAL (2026-08-28, debt 1787937117): the HTML refs render was called with the
264 // 20479-byte plan buffer while the api.json render got a larger one, so on any board whose .refs
265 // exceeds 20479 the page and the JSON disagreed about how many references exist -- 7 of them
266 // measured, aesthetictwin worst at 37446. Size from the file, never from the caller.
267 var fsz: i64 = 0
268 let szfd: i64 = sys_openat_rd(path)
269 if szfd < 0 { return 0 }
270 fsz = sys_lseek(szfd, 0, 2)
271 sys_close(szfd)
272 if fsz <= 0 { return 0 }
273 let buf: *u8 = sys_mmap(fsz + 1)
274 let n: i64 = c_read(path, buf, fsz)
275 if n <= 0 { return 0 }
276 buf[n] = 0 as u8
277 let fld: *i64 = sys_mmap(200) as *i64
278 var count: i64 = 0
279 var p: i64 = 0
280 while p < n {
281 var e: i64 = p
282 while e < n { if buf[e] == (10 as u8) { break } e = e + 1 }
283 buf[e] = 0 as u8
284 let line: *u8 = (buf as i64 + p) as *u8
285 p = e + 1
286 var skip: i64 = 0
287 if line[0] == (0 as u8) { skip = 1 }
288 if line[0] == (35 as u8) { skip = 1 }
289 if skip == 0 {
290 let nf: i64 = splitpipe(line, fld, 12)
291 if streq(fld[0] as *u8, "ref" as *u8) == 1 { if nf >= 9 {
292 if mode == 1 { rp_html(fld, count, dom, hdr) }
293 if mode == 2 { rp_json(fld, count) }
294 count = count + 1
295 } }
296 }
297 }
298 if count > 0 { if mode == 1 { w(1, "</ol>\n" as *u8) } else { if mode == 2 { wc(1, 93) } } }
299 return count
300}
301
302// ---- PLAN RENDERING, LIFTED INTO THE BASE 2026-08-22 (rung DG5) ------------------------------------
303// WHY THIS MOVED. plan_pass lived INSIDE nx_swcompare_matrix, so a domain whose page is emitted by the
304// SOTA generator had its .plan admitted as data and then NEVER RENDERED. Proven with full coverage
305// (matches=0, files=11, corpus_complete=1): the tool plane's own computed build order was invisible on
306// its own page, which is why nx_compare_rank looked like it had nothing to say there.
307// This follows the refs_pass precedent exactly -- ONE renderer in the base, BOTH generators call it --
308// so the two surfaces cannot drift into two different plan dialects. A second copy in the sota generator
309// would have been the duplicate-ruler defect, and it would have drifted on the first row kind either
310// generator added.
311// dstate and wlow come WITH it, not after it: NishiLang resolves identifiers in TEXTUAL ORDER, so a lib
312// function cannot call a helper defined later in the importing program. A partial lift does not compile.
313const SWL_DSTATE_CAP: i64 = 20480 // .debtstate sidecar read buffer. The NUL slot is DERIVED (CAP - 1)
314 // rather than a second hand-counted constant beside it: two numbers
315 // describing one buffer drift silently and the parser then reads the
316 // wrong window while still compiling.
317
318// Print what the DEBT PLANE says about an id: open, eaten, or not filed in this scope at all. The state
319// file is `id<TAB>state` per line, refreshed by the regen before any page is emitted.
320func dstate(fd: i64, id: *u8, ds: *u8, dn: i64) -> i64 {
321 if dn <= 0 { return 0 }
322 var i: i64 = 0
323 while i < dn {
324 var e: i64 = i
325 while e < dn { if ds[e] == (10 as u8) { break } e = e + 1 }
326 var k: i64 = 0
327 var ok: i64 = 1
328 var stop: i64 = 0
329 while stop == 0 {
330 if i + k >= e { stop = 1 } else {
331 let c: i64 = ds[i+k] as i64
332 if c == 9 { stop = 1 } else {
333 let ic: i64 = id[k] as i64
334 if ic == 0 { ok = 0; stop = 1 } else { if ic != c { ok = 0; stop = 1 } else { k = k + 1 } }
335 }
336 }
337 }
338 if ok == 1 { if (id[k] as i64) == 0 {
339 var s: i64 = i + k
340 if s < e { if ds[s] == (9 as u8) { s = s + 1 } }
341 w(fd, "<span class='pstate'>" as *u8)
342 var q: i64 = s
343 while q < e { wc(fd, ds[q] as i64); q = q + 1 }
344 w(fd, "</span>" as *u8)
345 return 1
346 } }
347 i = e + 1
348 }
349 // NOT "not filed". The lookup is scoped to THIS domain, so a debt filed under another scope is
350 // absent here while being perfectly real in the plane. Saying "not filed" publishes a false negative
351 // about a colleague's open work.
352 w(fd, "<span class='pstate note'>not in this scope</span>" as *u8)
353 return 0
354}
355// lowercase into a search-key attribute; single AND double quotes neutralised so they cannot close it.
356// wlow writes a lowercase SEARCH TOKEN into a single-quoted data- attribute. It already neutralised
357// both quote characters, which is why the gallery's data-t survived the caption apostrophe that
358// destroyed its sibling alt on the same tag -- HALF A LAW, APPLIED IN ONE ATTRIBUTE AND NOT THE OTHER.
359// It still passed the three markup-significant bytes through raw, so the same hole stood open for any
360// caption carrying an ampersand or an angle bracket. It now hands its result to the ONE attribute
361// escaper rather than carrying a second, weaker copy of that decision (2026-08-26).
362// The bare character codes are gone with it: they are the IA_ identities now.
363func wlow(fd: i64, s: *u8) -> i64 {
364 let n: i64 = ia_slen(s)
365 let low: *u8 = sys_mmap(n + 1)
366 var i: i64 = 0
367 while i < n {
368 var c: i64 = s[i] as i64
369 if c >= IA_UPPER_A { if c <= IA_UPPER_Z { c = c + IA_CASE_DELTA } }
370 if c == IA_SQ { c = IA_SP }
371 if c == IA_DQ { c = IA_SP }
372 low[i] = c as u8
373 i = i + 1
374 }
375 low[n] = 0 as u8
376 let need: i64 = n * IA_MAX_EXPANSION + IA_SEP_AND_NUL
377 let b: *u8 = sys_mmap(need)
378 let tr: *i64 = sys_mmap(IA_SLOT_BYTES) as *i64
379 ia_esc_attr(b, 0, low, need, tr)
380 w(fd, b)
381 return 0
382}
383// ---- LADDER TO SOTA helpers (2026-09-06), defined BEFORE plan_pass because NishiLang resolves in textual order ----
384// Both take SPANS precomputed before the walk: plan_pass's walk NUL-terminates lines and splitpipe zeroes pipes in place,
385// so a field re-parsed at render time on an already-walked line would read one truncated field. The bytes of the fields
386// themselves are untouched, so a span captured first is still readable when its consumer row arrives later in the file.
387// the month and freshness state of the sotabar row whose id is `id`, printed after the target's "dated by <id>"
388func swl_bar_state(fd: i64, buf: *u8, bidoff: *i64, bidlen: *i64, bym: *i64, bst: *i64, nb: i64, id: *u8) -> i64 {
389 var i: i64 = 0
390 while i < nb {
391 if ld_span_is(buf, bidoff[i], bidlen[i], id) == 1 {
392 w(fd, " = " as *u8)
393 if bym[i] == BF_NONE { w(fd, "MALFORMED MONTH" as *u8) } else {
394 let ymb: *u8 = sys_mmap(12)
395 bf_ym_write(ymb, 0, bym[i])
396 w(fd, ymb)
397 }
398 w(fd, " " as *u8); w(fd, bf_state_name(bst[i]))
399 return 1
400 }
401 i = i + 1
402 }
403 w(fd, " = NO SUCH SOTABAR ROW, UNDATED" as *u8)
404 return 0
405}
406// the deps field of the rung row whose id is `id` (what the rung stands on), or a dash
407func swl_rung_deps(fd: i64, buf: *u8, ridoff: *i64, ridlen: *i64, rdoff: *i64, rdlen: *i64, nr: i64, id: *u8) -> i64 {
408 var i: i64 = 0
409 while i < nr {
410 if ld_span_is(buf, ridoff[i], ridlen[i], id) == 1 {
411 if rdlen[i] > 0 { sys_write(fd, (buf as i64 + rdoff[i]) as *u8, rdlen[i]) } else { w(fd, "-" as *u8) }
412 return 1
413 }
414 i = i + 1
415 }
416 w(fd, "-" as *u8)
417 return 0
418}
419// A release date comes from a complete positive decimal epoch, never filtered digits.
420const SWL_RELEASE_I64_MAX: i64 = 9223372036854775807
421func swl_release_epoch(s: *u8) -> i64 {
422 if (s as i64) == 0 { return 0 }
423 if s[0] == (0 as u8) { return 0 }
424 var v: i64 = 0
425 var i: i64 = 0
426 while s[i] != (0 as u8) {
427 let c: i64 = s[i] as i64
428 if c < 48 { return 0 }
429 if c > 57 { return 0 }
430 let d: i64 = c - 48
431 if v > (SWL_RELEASE_I64_MAX - d) / 10 { return 0 }
432 v = v * 10 + d
433 i = i + 1
434 }
435 return v
436}
437// Equal timestamps preserve append-order corrections; older rows cannot replace newer ones.
438func swl_release_candidate(epoch: *u8, kind: *u8, entry: *u8, current: i64, now: i64) -> i64 {
439 if (kind as i64) == 0 { return 0 }
440 if (entry as i64) == 0 { return 0 }
441 if entry[0] == (0 as u8) { return 0 }
442 if streq(kind, "land" as *u8) != 1 { return 0 }
443 let candidate: i64 = swl_release_epoch(epoch)
444 if candidate <= 0 { return 0 }
445 if candidate < current { return 0 }
446 if candidate > now { return 0 }
447 return candidate
448}
449
450// Explicit heading ownership: old render APIs delegate level 2; grouped consumers select level 3.
451// attrs is a caller-owned static HTML attribute literal, never source data.
452func sc_heading_level(level: i64) -> i64 { if level<1 { return 2 }; if level>6 { return 2 }; return level }
453func sc_heading_open(fd: i64, level: i64, attrs: *u8) -> i64 {
454 w(fd, "<h" as *u8); wn(fd, sc_heading_level(level)); w(fd, attrs); w(fd, ">" as *u8); return 0
455}
456func sc_heading_close(fd: i64, level: i64) -> i64 {
457 w(fd, "</h" as *u8); wn(fd, sc_heading_level(level)); w(fd, ">" as *u8); return 0
458}
459
460// Shared plan tables retain their semantics inside a named keyboard-scroll region.
461func sc_plan_table_open(fd: i64, label: *u8) -> i64 {
462 w(fd, "<div class='table-scroll plan-table-scroll' role='region' tabindex='0' aria-label='" as *u8); w(fd, label); w(fd, "'><table class='pl'>" as *u8); return 0
463}
464func sc_plan_table_close(fd: i64) -> i64 { w(fd, "</tbody></table></div>" as *u8); return 0 }
465
466func plan_pass(path: *u8, bufz: *u8, capz: i64, phase: i64) -> i64 { return plan_pass_heading(path, bufz, capz, phase, 2) }
467// Only rendered rows change the active table; ignored metadata cannot split a table.
468func sc_plan_row_table(phase: i64, kind: *u8, fields: i64) -> i64 {
469 if phase == 1 {
470 if streq(kind, "biz" as *u8) == 1 { if fields >= 5 { return 3 } }
471 if streq(kind, "ladder" as *u8) == 1 { if fields >= 6 { return 4 } }
472 if streq(kind, "pos" as *u8) == 1 { if fields >= 2 { return 0 } }
473 if streq(kind, "goal" as *u8) == 1 { if fields >= 2 { return 0 } }
474 if streq(kind, "answer" as *u8) == 1 { if fields >= 4 { return 0 } }
475 if streq(kind, "evidence_snapshot" as *u8) == 1 { if fields == 5 { return 0 } }
476 if streq(kind, "bar" as *u8) == 1 { if fields >= 6 { return 0 } }
477 if streq(kind, "unit" as *u8) == 1 { if fields >= 2 { return 0 } }
478 }
479 if phase == 2 {
480 if streq(kind, "rung" as *u8) == 1 { if fields >= 8 { return 1 } }
481 if streq(kind, "ms" as *u8) == 1 { if fields >= 5 { return 2 } }
482 if streq(kind, "rungrole" as *u8) == 1 { if fields >= 5 { return 6 } }
483 if streq(kind, "sotatarget" as *u8) == 1 { if fields >= 6 { return 0 } }
484 }
485 if phase == 3 {
486 if streq(kind, "debt" as *u8) == 1 { if fields >= 5 { return 1 } }
487 if streq(kind, "risk" as *u8) == 1 { if fields >= 4 { return 2 } }
488 if streq(kind, "log" as *u8) == 1 { if fields >= 5 { return 5 } }
489 }
490 return 0 - 1
491}
492
493// ---- THREE-STEP TREATMENT ON THE PAGE (ecosystem EC49, 2026-09-16) ----
494// Operator: "make sure its mandatory that they get mcp and api and composable primitives and workflows and agent
495// treatment in our 1 2 3 step process". The page judges every treat row with THE ONE ruler (nx_treatment_lib) against
496// the SAME evidence the ranker reads -- tool_allowlist.conf (the MCP row, GREEN, and with it the API route), the source
497// tree through ep_src_path (the primitive), the plan_run plane manifest knowledge/store/plan-<id>-manifest.txt (the
498// workflow), the clock DESIRED plane through ONE nx_store_put fork per page and knowledge/gateroster.conf (the agent) --
499// so the page and the ranker cannot disagree by construction. Every path resolves through the estate probe: the regen
500// emits from CWD=buildroot and the ranker runs from CWD=nishihost, and both read the nishihost files.
501const SWL_TRT_ALLOW: *u8 = "tool_allowlist.conf"
502const SWL_TRT_ROSTER: *u8 = "knowledge/gateroster.conf"
503const SWL_TRT_STORE_PUT: *u8 = "./nx_store_put.elf"
504const SWL_TRT_CLOCK_MANIFEST: *u8 = "knowledge/store/clockjobs-manifest.txt" // a plane is a prefix, not a file: its manifest is what the probe can open, and the prefix is that path minus the manifest name
505const SWL_TRT_MANIFEST_TAIL: *u8 = "manifest.txt"
506const SWL_TRT_CLOCK_CAP: i64 = 1048576 // captured stdout of the clock DESIRED plane load (a fork, size unknowable): 11,935 B for 189 rows on 2026-09-16, 88x headroom; a fill is ANNOUNCED on the page and the plane treated as unobserved, never read as a prefix
507const SWL_TRT_WF_PFX: *u8 = "knowledge/store/plan-"
508const SWL_TRT_WF_SFX: *u8 = "-manifest.txt"
509const SWL_TRT_PATH_CAP: i64 = 1024 // one composed estate path, the reserve every ep_* probe writes into
510const SWL_TRT_EV_ALLOW: i64 = 0
511const SWL_TRT_EV_ROSTER: i64 = 1
512const SWL_TRT_EV_CLOCK: i64 = 2
513const SWL_TRT_EV_UNPROVEN: i64 = 3
514const SWL_TRT_EV_SLOTS: i64 = 4
515func swl_trt_read(rel: *u8, outb: *i64) -> i64 {
516 let path: *u8 = sys_mmap(SWL_TRT_PATH_CAP)
517 if ep_artifact_path(path, rel) == 0 { outb[0] = 0; return 0 }
518 let lenp: *i64 = sys_mmap(16) as *i64
519 lenp[0] = 0
520 let b: *u8 = sys_read_file(path, lenp)
521 if (b as i64) == 0 { outb[0] = 0; return 0 }
522 outb[0] = b as i64
523 return lenp[0]
524}
525// The tools daemon reads tool_allowlist.conf from ITS cwd, the estate root. buildroot carries a 177-byte twin of that name
526// which no surface executes, and the regen emits from CWD=buildroot, so the cwd-first probe judged the first published
527// Treatment verdict against the twin (MEASURED 2026-09-16: allowlist 177 B on the page, 165424 B in the ranker, two rows
528// PARTIAL on the page and COMPLETE in the ranker). The authority is resolved at the estate root FIRST; the probe is the
529// fallback for a hermetic tree, and the page prints the byte count it read so a twin can never hide again.
530func swl_trt_allow_read(outb: *i64) -> i64 {
531 let path: *u8 = sys_mmap(SWL_TRT_PATH_CAP)
532 ep_join(path, EP_ROOT, SWL_TRT_ALLOW)
533 let lenp: *i64 = sys_mmap(16) as *i64
534 lenp[0] = 0
535 let b: *u8 = sys_read_file(path, lenp)
536 if (b as i64) != 0 { if lenp[0] > 0 { outb[0] = b as i64; return lenp[0] } }
537 return swl_trt_read(SWL_TRT_ALLOW, outb)
538}
539func swl_trt_span(buf: *u8, off: i64, len: i64) -> *u8 {
540 var l: i64 = len
541 if l < 0 { l = 0 }
542 let s: *u8 = sys_mmap(l + 1)
543 var i: i64 = 0
544 while i < l { s[i] = buf[off + i]; i = i + 1 }
545 s[l] = 0 as u8
546 return s
547}
548// judge every treat row in tab; ev receives the evidence sizes (allowlist, roster, clock plane bytes, clock unproven)
549func swl_treat_judge(buf: *u8, tab: *i64, rows: i64, ev: *i64) -> i64 {
550 let ap: *i64 = sys_mmap(16) as *i64
551 let an: i64 = swl_trt_allow_read(ap)
552 let rp: *i64 = sys_mmap(16) as *i64
553 let rn: i64 = swl_trt_read(SWL_TRT_ROSTER, rp)
554 let clock: *u8 = sys_mmap(SWL_TRT_CLOCK_CAP)
555 var cn: i64 = 0
556 var unproven: i64 = 0
557 let spp: *u8 = sys_mmap(SWL_TRT_PATH_CAP)
558 let mfp: *u8 = sys_mmap(SWL_TRT_PATH_CAP)
559 if ep_artifact_path(spp, SWL_TRT_STORE_PUT) == 1 { if ep_artifact_path(mfp, SWL_TRT_CLOCK_MANIFEST) == 1 {
560 // the plane prefix in the SAME root the manifest resolved in: the path minus its manifest tail
561 var ml: i64 = 0
562 while mfp[ml] != (0 as u8) { ml = ml + 1 }
563 var tl: i64 = 0
564 while SWL_TRT_MANIFEST_TAIL[tl] != (0 as u8) { tl = tl + 1 }
565 if ml > tl { mfp[ml - tl] = 0 as u8 }
566 let av: *i64 = sys_mmap(8 * 8) as *i64
567 av[0] = spp as i64
568 av[1] = mfp as i64
569 av[2] = "load" as *u8 as i64
570 av[3] = 0
571 let cl: *i64 = sys_mmap(16) as *i64
572 cl[0] = 0
573 tr_run_capture(spp, av, clock, SWL_TRT_CLOCK_CAP - 1, cl)
574 cn = cl[0]
575 if cn < 0 { cn = 0 }
576 if cn >= SWL_TRT_CLOCK_CAP - 1 { unproven = 1; cn = 0 }
577 } }
578 ev[SWL_TRT_EV_ALLOW] = an; ev[SWL_TRT_EV_ROSTER] = rn; ev[SWL_TRT_EV_CLOCK] = cn; ev[SWL_TRT_EV_UNPROVEN] = unproven
579 let sp: *u8 = sys_mmap(SWL_TRT_PATH_CAP)
580 let wf: *u8 = sys_mmap(SWL_TRT_PATH_CAP)
581 let wp: *u8 = sys_mmap(SWL_TRT_PATH_CAP)
582 var r: i64 = 0
583 while r < rows {
584 let b: i64 = r * TRT_STRIDE
585 var prim_ok: i64 = 0 - 1
586 var wf_ok: i64 = 0 - 1
587 if tab[b + TRT_ST_PRIM] == TRT_F_DECLARED { prim_ok = ep_src_path(sp, swl_trt_span(buf, tab[b + TRT_PRIM_O], tab[b + TRT_PRIM_L])) }
588 if tab[b + TRT_ST_WF] == TRT_F_DECLARED {
589 var o: i64 = scopy(wf, 0, SWL_TRT_WF_PFX)
590 o = scopy(wf, o, swl_trt_span(buf, tab[b + TRT_WF_O], tab[b + TRT_WF_L]))
591 o = scopy(wf, o, SWL_TRT_WF_SFX)
592 wf[o] = 0 as u8
593 wf_ok = ep_artifact_path(wp, wf)
594 }
595 trt_judge_row(tab, r, buf, ap[0] as *u8, an, rp[0] as *u8, rn, clock, cn, prim_ok, wf_ok)
596 r = r + 1
597 }
598 return rows
599}
600// one value cell: the declared text (escaped through wnote) and its measured state
601func swl_trt_cell(fd: i64, buf: *u8, off: i64, len: i64, st: i64) -> i64 {
602 w(fd, "<td>" as *u8)
603 if len > 0 { wnote(fd, swl_trt_span(buf, off, len)) } else { w(fd, "-" as *u8) }
604 w(fd, " <span class='ct'>" as *u8); w(fd, trt_state_name(st)); w(fd, "</span></td>" as *u8)
605 return 0
606}
607
608func plan_pass_heading(path: *u8, bufz: *u8, capz: i64, phase: i64, heading_level: i64) -> i64 {
609 // THE 20479-BYTE CAP IS REMOVED, NOT RAISED (2026-08-28, debt 1787937117). The caller handed us a
610 // guessed buffer whose cap silently short-read every .plan over 20479 bytes -- 8 of 93 measured,
611 // browser worst at 63614 -- publishing a PREFIX whose lost rows are always the NEWEST, announced
612 // nowhere. A ceiling that has to be guessed is a defect generator in both directions, and for a FILE
613 // read there is no guess to make: size the buffer from the file itself (lseek END), like sys_read_file.
614 // bufz/capz are kept only so every existing call site still compiles; they are deliberately unused.
615 var fsz: i64 = 0
616 let szfd: i64 = sys_openat_rd(path)
617 if szfd < 0 { return 0 }
618 fsz = sys_lseek(szfd, 0, 2)
619 sys_close(szfd)
620 if fsz <= 0 { return 0 }
621 let buf: *u8 = sys_mmap(fsz + 1)
622 let n: i64 = c_read(path, buf, fsz)
623 if n <= 0 { return 0 }
624 buf[n] = 0 as u8
625 let fld: *i64 = sys_mmap(200) as *i64
626 // the plane's view of each debt id, refreshed by the regen before this page was emitted.
627 // Derived from the plan path so the two files cannot drift apart by name.
628 let dsbuf: *u8 = sys_mmap(SWL_DSTATE_CAP)
629 var dsn: i64 = 0
630 if phase == 3 {
631 let dsp: *u8 = sys_mmap(600)
632 var dq: i64 = 0
633 while path[dq] != (0 as u8) { dsp[dq] = path[dq]; dq = dq + 1 }
634 var cut: i64 = dq
635 while cut > 0 { if dsp[cut] == (46 as u8) { break } cut = cut - 1 }
636 if cut > 0 { dq = cut }
637 dq = scopy(dsp, dq, ".debtstate" as *u8)
638 dsp[dq] = 0 as u8
639 dsn = c_read(dsp, dsbuf, SWL_DSTATE_CAP - 1)
640 if dsn < 0 { dsn = 0 }
641 }
642 var active_table: i64 = 0
643 var log_heading_seen: i64 = 0
644 var in_rung: i64 = 0
645 var in_ms: i64 = 0
646 var in_biz: i64 = 0
647 var in_lad: i64 = 0
648 var in_log: i64 = 0
649 var release_epoch: i64 = 0
650 let release_now: i64 = sys_now_realtime_sec()
651 var release_entry: *u8 = 0 as *u8
652 var release_rung: *u8 = 0 as *u8
653 // LADDER TO SOTA (2026-09-06): classify the sotabar/barscan and sotatarget/rungrole rows ONCE, before the walk below
654 // NUL-terminates lines and zeroes pipes in place, and bank the spans the render helpers read (see swl_bar_state).
655 let bfnb: i64 = bf_count_rows(buf, n, BF_BAR_TAG)
656 let bfoff: *i64 = sys_mmap((bfnb + 1) * 8) as *i64
657 let bfym: *i64 = sys_mmap((bfnb + 1) * 8) as *i64
658 let bfst: *i64 = sys_mmap((bfnb + 1) * 8) as *i64
659 let bfseen: *i64 = sys_mmap((bfnb + 1) * 8) as *i64
660 let bfc: *i64 = sys_mmap(BF_C_N * 8) as *i64
661 let bfcur: i64 = bf_now_ym()
662 bf_classify(buf, n, bfcur, bfoff, bfym, bfst, bfseen, bfc)
663 let bidoff: *i64 = sys_mmap((bfnb + 1) * 8) as *i64
664 let bidlen: *i64 = sys_mmap((bfnb + 1) * 8) as *i64
665 let sfo: *i64 = sys_mmap(8) as *i64
666 var sbi: i64 = 0
667 while sbi < bfnb { let sbe: i64 = bf_line_end(buf, n, bfoff[sbi]); bidlen[sbi] = bf_field(buf, bfoff[sbi], sbe, BF_F_BAR_ID, sfo); bidoff[sbi] = sfo[0]; sbi = sbi + 1 }
668 let ldnt: i64 = bf_count_rows(buf, n, LD_TARGET_TAG)
669 let ldnr: i64 = bf_count_rows(buf, n, LD_RUNG_TAG)
670 let ldc: *i64 = sys_mmap(LD_N_COUNT * 8) as *i64
671 let ldtoff: *i64 = sys_mmap((ldnt + 1) * 8) as *i64
672 let ldtcls: *i64 = sys_mmap((ldnt + 1) * 8) as *i64
673 let ldtst: *i64 = sys_mmap((ldnt + 1) * 8) as *i64
674 let ldroff: *i64 = sys_mmap((ldnr + 1) * 8) as *i64
675 let ldrrole: *i64 = sys_mmap((ldnr + 1) * 8) as *i64
676 let ldrtgt: *i64 = sys_mmap((ldnr + 1) * 8) as *i64
677 let ldrst: *i64 = sys_mmap((ldnr + 1) * 8) as *i64
678 ld_classify(buf, n, ldtoff, ldtcls, ldtst, ldroff, ldrrole, ldrtgt, ldrst, ldc)
679 let ldv: i64 = ld_verdict(ldc)
680 // THREE-STEP TREATMENT (EC49): scanned and judged on the pristine buffer, before the walk below zeroes the pipes;
681 // judged only in the render phase so a page costs ONE clock-plane fork, not three
682 let trcap: i64 = trt_cap(n)
683 let trtab: *i64 = sys_mmap(trcap * TRT_STRIDE * 8) as *i64
684 let trrows: i64 = trt_scan(buf, n, trtab, trcap)
685 let trev: *i64 = sys_mmap(SWL_TRT_EV_SLOTS * 8) as *i64
686 var trz: i64 = 0
687 while trz < SWL_TRT_EV_SLOTS { trev[trz] = 0; trz = trz + 1 }
688 if phase == 2 { if trrows > 0 { swl_treat_judge(buf, trtab, trrows, trev) } }
689 let trc: *i64 = sys_mmap(TRT_C_SLOTS * 8) as *i64
690 trt_census(trtab, trrows, buf, n, trc)
691 let trv: i64 = trt_verdict(trc)
692 let ridoff: *i64 = sys_mmap((ldnr + 1) * 8) as *i64
693 let ridlen: *i64 = sys_mmap((ldnr + 1) * 8) as *i64
694 let rdoff: *i64 = sys_mmap((ldnr + 1) * 8) as *i64
695 let rdlen: *i64 = sys_mmap((ldnr + 1) * 8) as *i64
696 var sri: i64 = 0
697 while sri < ldnr { let sre: i64 = bf_line_end(buf, n, ldroff[sri]); ridlen[sri] = bf_field(buf, ldroff[sri], sre, LD_F_R_ID, sfo); ridoff[sri] = sfo[0]; rdlen[sri] = bf_field(buf, ldroff[sri], sre, LD_F_R_DEPS, sfo); rdoff[sri] = sfo[0]; sri = sri + 1 }
698 var in_tgt: i64 = 0
699 var in_role: i64 = 0
700 if phase == 1 { w(1, "<div class='exec-grid'>\n" as *u8) }
701 var p: i64 = 0
702 while p < n {
703 var e: i64 = p
704 while e < n { if buf[e] == (10 as u8) { break } e = e + 1 }
705 buf[e] = 0 as u8
706 let line: *u8 = (buf as i64 + p) as *u8
707 p = e + 1
708 var skip: i64 = 0
709 if line[0] == (0 as u8) { skip = 1 }
710 if line[0] == (35 as u8) { skip = 1 }
711 if skip == 0 {
712 let nf: i64 = splitpipe(line, fld, 20)
713 let kind: *u8 = fld[0] as *u8
714 let next_table: i64 = sc_plan_row_table(phase, kind, nf)
715 if next_table >= 0 { if next_table != active_table {
716 if active_table != 0 { sc_plan_table_close(1); w(1, "\n" as *u8) }
717 in_rung = 0; in_ms = 0; in_biz = 0; in_lad = 0; in_log = 0; in_role = 0
718 active_table = next_table
719 } }
720 if phase == 1 {
721 if streq(kind, "log" as *u8) == 1 { if nf == 5 {
722 let candidate: i64 = swl_release_candidate(fld[1] as *u8, fld[3] as *u8, fld[4] as *u8, release_epoch, release_now)
723 if candidate > 0 {
724 release_epoch = candidate
725 release_rung = fld[2] as *u8
726 release_entry = fld[4] as *u8
727 }
728 } }
729 if streq(kind, "pos" as *u8) == 1 { if nf >= 2 { w(1, "<p class='lead'><b>Where we are.</b> " as *u8); wnote(1, fld[1] as *u8); w(1, "</p>\n" as *u8) } }
730 if streq(kind, "goal" as *u8) == 1 { if nf >= 2 { w(1, "<p class='lead'><b>Where we need to go.</b> " as *u8); wnote(1, fld[1] as *u8); w(1, "</p>\n" as *u8) } }
731 if streq(kind, "evidence_snapshot" as *u8) == 1 { if nf == 5 {
732 if streq(fld[1] as *u8,"1" as *u8)==1 { efs_render(fld[3] as *u8,fld[4] as *u8,heading_level,1) } else { w(1,"<p>Evidence snapshot unavailable: unsupported row version.</p>" as *u8) }
733 } }
734 if streq(kind, "answer" as *u8) == 1 { if nf >= 4 {
735 w(1, "<div class='answer'><b>" as *u8); w(1, fld[1] as *u8); w(1, ": " as *u8); w(1, fld[2] as *u8); w(1, ".</b> " as *u8); wnote(1, fld[3] as *u8); w(1, "</div>\n" as *u8) } }
736 if streq(kind, "bar" as *u8) == 1 { if nf >= 6 {
737 w(1, "<p class='lead'><b>Research bar.</b> <a href='" as *u8); w(1, fld[2] as *u8); w(1, "'>" as *u8); w(1, fld[1] as *u8); w(1, "</a> is measured on " as *u8); w(1, fld[3] as *u8)
738 w(1, ". Theirs: <b>" as *u8); wnote(1, fld[4] as *u8); w(1, "</b>. Ours: " as *u8); wnote(1, fld[5] as *u8); w(1, ".</p>\n" as *u8) } }
739 if streq(kind, "unit" as *u8) == 1 { if nf >= 2 { w(1, "<div class='meth'><b>The unit.</b> " as *u8); w(1, fld[1] as *u8); w(1, "</div>\n" as *u8) } }
740 // biz|axis|position|figures|decision -- the BUSINESS CASE row kind (investment, opportunity
741 // cost, market, competitive position, go-to-market, buy-vs-build). Rendered as one table in
742 // the executive layer; biz rows belong LAST in a plan's phase-1 block so the table closes clean.
743 if streq(kind, "biz" as *u8) == 1 { if nf >= 5 {
744 if in_biz == 0 { sc_heading_open(1, heading_level, "" as *u8); w(1, "Business case" as *u8); sc_heading_close(1, heading_level); w(1, "\n" as *u8); sc_plan_table_open(1, "Business case" as *u8); w(1, "<thead><tr><th>Axis</th><th>Position</th><th>Figures</th><th>Decision</th></tr></thead><tbody>\n" as *u8); in_biz = 1 }
745 w(1, "<tr><td><b>" as *u8); w(1, fld[1] as *u8); w(1, "</b></td><td>" as *u8); wnote(1, fld[2] as *u8)
746 w(1, "</td><td class='ct'>" as *u8); wnote(1, fld[3] as *u8); w(1, "</td><td>" as *u8); wnote(1, fld[4] as *u8); w(1, "</td></tr>\n" as *u8) } }
747 // ladder|level|best_in_class|have|grow|verdict -- the MARKET-ENTRY LADDER row kind (2026-08-24): per level
748 // (hobbyist to research leader) what best-in-class looks like from the mirrored record, what the estate measures
749 // today, what must grow, and the ENTER or HOLD or GROW-FIRST verdict. Rendered as one table after the business
750 // case; ladder rows belong LAST in a plan's phase-1 block. The verdict is DATA here; ml_entry_verdict computes it.
751 if streq(kind, "ladder" as *u8) == 1 { if nf >= 6 {
752 if in_lad == 0 { sc_heading_open(1, heading_level, "" as *u8); w(1, "Market-entry ladder" as *u8); sc_heading_close(1, heading_level); w(1, "\n" as *u8); sc_plan_table_open(1, "Market-entry ladder" as *u8); w(1, "<thead><tr><th>Level</th><th>Best in class (Aug 2026)</th><th>What we have</th><th>What must grow</th><th>Verdict</th></tr></thead><tbody>\n" as *u8); in_lad = 1 }
753 w(1, "<tr><td><b>" as *u8); w(1, fld[1] as *u8); w(1, "</b></td><td>" as *u8); wnote(1, fld[2] as *u8)
754 w(1, "</td><td>" as *u8); wnote(1, fld[3] as *u8); w(1, "</td><td>" as *u8); wnote(1, fld[4] as *u8)
755 w(1, "</td><td class='ct'>" as *u8); wnote(1, fld[5] as *u8)
756 // the COMPUTED verdict beside the authored one (nx_market_ladder_lib, the one ruler the CLI uses)
757 if nf >= 7 { ml_render_computed_html(1, path, fld[6] as *u8) }
758 w(1, "</td></tr>\n" as *u8) } }
759 }
760 if phase == 3 {
761 if streq(kind, "debt" as *u8) == 1 { if nf >= 5 {
762 if in_rung == 0 { sc_heading_open(1, heading_level, "" as *u8); w(1, "Debt register" as *u8); sc_heading_close(1, heading_level); w(1, "\n" as *u8); sc_plan_table_open(1, "Debt register" as *u8); w(1, "<thead><tr><th>Id</th><th class='r'>Sev</th><th>What it is</th><th>Unblock</th></tr></thead><tbody>\n" as *u8); in_rung = 1 }
763 w(1, "<tr><td class='ct'>" as *u8); w(1, fld[1] as *u8)
764 // STATE COMES FROM THE PLANE, NEVER FROM THIS ROW. An id the plane does not know is a
765 // page-local note wearing the shape of a filed debt, and saying so is the honest move.
766 dstate(1, fld[1] as *u8, dsbuf, dsn)
767 w(1, "</td><td class='r'>" as *u8); w(1, fld[2] as *u8)
768 w(1, "</td><td>" as *u8); wnote(1, fld[3] as *u8); w(1, "</td><td>" as *u8); wnote(1, fld[4] as *u8); w(1, "</td></tr>\n" as *u8) } }
769 if streq(kind, "risk" as *u8) == 1 { if nf >= 4 {
770 if in_ms == 0 { sc_heading_open(1, heading_level, "" as *u8); w(1, "Risk register" as *u8); sc_heading_close(1, heading_level); w(1, "\n" as *u8); sc_plan_table_open(1, "Risk register" as *u8); w(1, "<thead><tr><th>Risk</th><th>Likelihood x impact</th><th>Mitigation</th></tr></thead><tbody>\n" as *u8); in_ms = 1 }
771 w(1, "<tr><td>" as *u8); wnote(1, fld[1] as *u8); w(1, "</td><td class='ct'>" as *u8); w(1, fld[2] as *u8)
772 w(1, "</td><td>" as *u8); wnote(1, fld[3] as *u8); w(1, "</td></tr>\n" as *u8) } }
773 // log|<epoch>|<rung>|<kind>|<text> -- THE WORKED PLAN ON THE BOARD (operator 2026-09-02: a crash must
774 // leave a ledger here, not a transcript to mine). Every leg appends what it measured, landed,
775 // retracted, learned and left queued, per rung; rendered newest-last, each row linking to its rung.
776 if streq(kind, "log" as *u8) == 1 { if nf >= 5 {
777 if in_log == 0 { if log_heading_seen == 0 { sc_heading_open(1, heading_level, " id='worklog'" as *u8); w(1, "Release history and work log" as *u8); sc_heading_close(1, heading_level); w(1, "\n<div class='meth'><b>The worked plan, on the board.</b> Every leg appends what it measured, landed, retracted, learned and left queued, per rung, so a crash leaves the next seat a ledger here rather than a transcript to mine. Kinds: measure, land, retract, lesson, queue. Newest last.</div>\n" as *u8); log_heading_seen = 1 } else { sc_heading_open(1, heading_level, "" as *u8); w(1, "Release history continued" as *u8); sc_heading_close(1, heading_level); w(1, "\n" as *u8) } sc_plan_table_open(1, "Release history and work log" as *u8); w(1, "<thead><tr><th>When</th><th>Rung</th><th>Kind</th><th>Entry</th></tr></thead><tbody>\n" as *u8); in_log = 1 }
778 let lep: *u8 = fld[1] as *u8
779 var lv: i64 = 0
780 var li: i64 = 0
781 while lep[li] != (0 as u8) { let lc: i64 = lep[li] as i64; if lc >= 48 { if lc <= 57 { lv = lv*10 + (lc-48) } } li = li + 1 }
782 let ldb: *u8 = sys_mmap(32)
783 let ldn: i64 = bd_ymd(lv, ldb, 0)
784 ldb[ldn] = 0 as u8
785 w(1, "<tr><td class='ct'>" as *u8); w(1, ldb); w(1, "</td><td class='ct'><a href='#" as *u8); wlow(1, fld[2] as *u8); w(1, "'>" as *u8); w(1, fld[2] as *u8)
786 w(1, "</a></td><td class='ct'>" as *u8); w(1, fld[3] as *u8); w(1, "</td><td>" as *u8); wnote(1, fld[4] as *u8); w(1, "</td></tr>\n" as *u8) } }
787 }
788 if phase == 2 {
789 if streq(kind, "rung" as *u8) == 1 { if nf >= 8 {
790 if in_rung == 0 { sc_plan_table_open(1, "Capability roadmap" as *u8); w(1, "<thead><tr><th>Rung</th><th>Closes with</th><th>Definition of done (pre-declared)</th><th>Executor</th><th class='r'>Est.</th></tr></thead><tbody>\n" as *u8); in_rung = 1 }
791 w(1, "<tr id='" as *u8); wlow(1, fld[1] as *u8); w(1, "'><td><b>" as *u8); w(1, fld[2] as *u8); w(1, "</b> (" as *u8); w(1, fld[1] as *u8); w(1, ")" as *u8)
792 if streq(fld[7] as *u8, "-" as *u8) == 0 { w(1, "<br><span class='ct'>after " as *u8); w(1, fld[7] as *u8); w(1, "</span>" as *u8) }
793 w(1, "</td><td class='ct'>" as *u8); w(1, fld[3] as *u8); w(1, "</td><td>" as *u8); wnote(1, fld[4] as *u8)
794 w(1, "</td><td><span class='ex'>" as *u8); w(1, fld[5] as *u8); w(1, "</span></td><td class='r'>" as *u8); w(1, fld[6] as *u8); w(1, " u</td></tr>\n" as *u8) } }
795 // LADDER TO SOTA (2026-09-06): the dated targets, judged by the bar-age ruler, then the rung-role table.
796 // sotatarget and rungrole rows belong AFTER the rung and ms rows in a plan so the ladder renders beneath them.
797 if streq(kind, "sotatarget" as *u8) == 1 { if nf >= 6 {
798 if in_tgt == 0 { sc_heading_open(1, heading_level, " id='ladder'" as *u8); w(1, "Ladder to SOTA" as *u8); sc_heading_close(1, heading_level); w(1, "\n<div class='meth'><b>Two dated targets, and every rung's role toward them.</b> Best in class is the proven, deployed leader today; the frontier is the research edge as of its month. Each target is dated by a sotabar row and judged against the current month by the bar-age ruler (FRESH, ATTESTED with the fallback month named, or refused). Each rung is substrate (what the target's own methods consume), an arm (a sovereign arm that triangulates without competing for the number), a contender (its done-rule is a number against the target) or superseded (kept as capability, retired as a claim), and carries the rungs it stands on.</div>\n" as *u8); in_tgt = 1 }
799 w(1, "<div class='answer'><b>" as *u8); w(1, fld[2] as *u8); w(1, " (" as *u8); w(1, fld[1] as *u8); w(1, "), dated by " as *u8); w(1, fld[3] as *u8)
800 swl_bar_state(1, buf, bidoff, bidlen, bfym, bfst, bfnb, fld[3] as *u8)
801 w(1, ".</b> " as *u8); wnote(1, fld[4] as *u8)
802 w(1, " <span class='ct'>ref " as *u8); w(1, fld[5] as *u8); w(1, "</span></div>\n" as *u8) } }
803 if streq(kind, "rungrole" as *u8) == 1 { if nf >= 5 {
804 if in_tgt == 0 { sc_heading_open(1, heading_level, " id='ladder'" as *u8); w(1, "Ladder to SOTA" as *u8); sc_heading_close(1, heading_level); w(1, "\n" as *u8); in_tgt = 1 }
805 if in_role == 0 { sc_plan_table_open(1, "Rung roles and prerequisites" as *u8); w(1, "<thead><tr><th>Rung</th><th>Role</th><th>Toward</th><th>Stands on</th><th>Why</th></tr></thead><tbody>\n" as *u8); in_role = 1 }
806 w(1, "<tr><td class='ct'><a href='#" as *u8); wlow(1, fld[1] as *u8); w(1, "'>" as *u8); w(1, fld[1] as *u8); w(1, "</a></td><td class='ct'>" as *u8); w(1, fld[2] as *u8); w(1, "</td><td class='ct'>" as *u8); w(1, fld[3] as *u8); w(1, "</td><td class='ct'>" as *u8)
807 swl_rung_deps(1, buf, ridoff, ridlen, rdoff, rdlen, ldnr, fld[1] as *u8)
808 w(1, "</td><td>" as *u8); wnote(1, fld[4] as *u8); w(1, "</td></tr>\n" as *u8) } }
809 if streq(kind, "ms" as *u8) == 1 { if nf >= 5 {
810 if in_ms == 0 { sc_heading_open(1, heading_level, "" as *u8); w(1, "Milestones" as *u8); sc_heading_close(1, heading_level); w(1, "\n" as *u8); sc_plan_table_open(1, "Milestones" as *u8); w(1, "<thead><tr><th>Milestone</th><th>Rungs</th><th class='r'>Cumulative</th></tr></thead><tbody>\n" as *u8); in_ms = 1 }
811 w(1, "<tr><td><b>" as *u8); w(1, fld[1] as *u8); w(1, "</b> · " as *u8); w(1, fld[2] as *u8); w(1, "</td><td class='ct'>" as *u8); w(1, fld[4] as *u8)
812 w(1, "</td><td class='r'>" as *u8); w(1, fld[3] as *u8); w(1, " u</td></tr>\n" as *u8) } }
813 }
814 }
815 }
816 if active_table != 0 { sc_plan_table_close(1); w(1, "\n" as *u8) }
817 if phase == 1 {
818 w(1, "<section class='meth' id='release-summary'>" as *u8); sc_heading_open(1, heading_level, "" as *u8); w(1, "Latest recorded release" as *u8); sc_heading_close(1, heading_level)
819 if release_epoch > 0 {
820 let date: *u8 = sys_mmap(32)
821 let date_len: i64 = bd_ymd(release_epoch, date, 0)
822 date[date_len] = 0 as u8
823 w(1, "<p><b>" as *u8); w(1, date); w(1, "</b> · " as *u8)
824 wnote(1, release_rung); w(1, "</p><p>" as *u8); wnote(1, release_entry)
825 w(1, "</p><p><a href='#worklog'>Release history and work log</a></p>" as *u8)
826 } else {
827 w(1, "<p>No valid dated release entry is recorded for this domain.</p>" as *u8)
828 }
829 w(1, "<p>Release entries describe recorded changes; they do not establish that every capability passed evaluation.</p></section>\n</div>\n" as *u8)
830 }
831 if phase == 2 {
832 // THE TWO VERDICTS, FROM THE RULERS, ON EVERY PAGE WITH A PLAN (2026-09-06). A board that has not declared its
833 // ladder is TOLD so on its own page: an undeclared target is exactly how a seat climbed toward a 2014 bar for a day.
834 w(1, "<div class='meth' id='ladderverdict'><b>Ladder verdict.</b> " as *u8)
835 if ldv == LD_EXIT_NOLADDER {
836 w(1, "<b>NOT DECLARED.</b> This board names no dated best-in-class or frontier target and no rung roles (sotatarget and rungrole rows on its plan); the ranker labels it NO-LADDER until it does, and until then its rungs climb toward a target nobody has written down." as *u8)
837 } else {
838 w(1, "targets " as *u8); wn(1, ldc[LD_N_TARGETS]); w(1, " (best in class " as *u8); wn(1, ldc[LD_N_BIC]); w(1, ", frontier " as *u8); wn(1, ldc[LD_N_FRONTIER]); w(1, ", undated " as *u8); wn(1, ldc[LD_N_UNDATED])
839 w(1, "); rungs " as *u8); wn(1, ldc[LD_N_RUNGS]); w(1, ", placed " as *u8); wn(1, ldc[LD_N_PLACED]); w(1, " (substrate " as *u8); wn(1, ldc[LD_N_SUBSTRATE]); w(1, ", arm " as *u8); wn(1, ldc[LD_N_ARM]); w(1, ", contender " as *u8); wn(1, ldc[LD_N_CONTENDER]); w(1, ", superseded " as *u8); wn(1, ldc[LD_N_SUPERSEDED]); w(1, "), unplaced " as *u8); wn(1, ldc[LD_N_UNPLACED]); w(1, "; verdict <b>" as *u8); w(1, ld_verdict_name(ldv)); w(1, "</b>" as *u8)
840 if ldv == LD_EXIT_PARTIAL { w(1, " -- half-declared: the ranker refuses this board until every target is dated and every rung has a role" as *u8) }
841 }
842 w(1, " Bars: " as *u8); wn(1, bfc[BF_C_BARS]); w(1, " (fresh " as *u8); wn(1, bfc[BF_C_FRESH]); w(1, ", attested " as *u8); wn(1, bfc[BF_C_ATTESTED]); w(1, ", stale " as *u8); wn(1, bfc[BF_C_STALE]); w(1, ", unattested " as *u8); wn(1, bfc[BF_C_UNATTESTED]); w(1, "), verdict <b>" as *u8); w(1, bf_verdict_name(bf_verdict(bfc))); w(1, "</b> against the current month " as *u8)
843 let cymb: *u8 = sys_mmap(12)
844 bf_ym_write(cymb, 0, bfcur)
845 w(1, cymb); w(1, ".</div>\n" as *u8)
846 // THREE-STEP TREATMENT VERDICT (ecosystem EC49, 2026-09-16): the same ruler and the same evidence the ranker composes,
847 // on every page with a plan -- a board that has declared no treatment is TOLD so on its own page.
848 w(1, "<div class='meth' id='treatmentverdict'><b>Treatment verdict.</b> " as *u8)
849 if trv == TRT_EXIT_NONE {
850 w(1, "<b>NOT DECLARED.</b> No rung on this board declares its three-step treatment (a treat row naming the MCP row, the API route, the primitive it composes, the workflow that composes it and the agent beat that runs it); the ranker labels every rung TREATMENT-UNDECLARED until it does." as *u8)
851 } else {
852 w(1, "rows " as *u8); wn(1, trc[TRT_C_ROWS]); w(1, " (complete " as *u8); wn(1, trc[TRT_C_COMPLETE]); w(1, ", partial " as *u8); wn(1, trc[TRT_C_PARTIAL]); w(1, ", malformed " as *u8); wn(1, trc[TRT_C_FIELDS]); w(1, "); rungs " as *u8); wn(1, trc[TRT_C_RUNGS]); w(1, ", undeclared " as *u8); wn(1, trc[TRT_C_UNDECLARED]); w(1, "; verdict <b>" as *u8); w(1, trt_exit_name(trv)); w(1, "</b>" as *u8)
853 if trv == TRT_EXIT_PARTIAL { w(1, " -- a declared row is unmet: the ranker refuses this board until every declared row verifies" as *u8) }
854 w(1, ". Evidence read: allowlist " as *u8); wn(1, trev[SWL_TRT_EV_ALLOW]); w(1, " B, roster " as *u8); wn(1, trev[SWL_TRT_EV_ROSTER]); w(1, " B, clock plane " as *u8); wn(1, trev[SWL_TRT_EV_CLOCK]); w(1, " B" as *u8)
855 if trev[SWL_TRT_EV_UNPROVEN] == 1 { w(1, " (the clock plane filled its reserve: agent reads are UNPROVEN)" as *u8) }
856 }
857 w(1, "</div>\n" as *u8)
858 if trrows > 0 {
859 sc_plan_table_open(1, "Three-step treatment" as *u8); w(1, "<thead><tr><th>Rung</th><th>MCP row</th><th>API route</th><th>Primitive</th><th>Workflow</th><th>Agent beat</th><th>Verdict</th></tr></thead><tbody>\n" as *u8)
860 var tq: i64 = 0
861 while tq < trrows {
862 let tb: i64 = tq * TRT_STRIDE
863 let trid: *u8 = swl_trt_span(buf, trtab[tb + TRT_RUNG_O], trtab[tb + TRT_RUNG_L])
864 w(1, "<tr><td class='ct'><a href='#" as *u8); wlow(1, trid); w(1, "'>" as *u8); w(1, trid); w(1, "</a></td>" as *u8)
865 swl_trt_cell(1, buf, trtab[tb + TRT_MCP_O], trtab[tb + TRT_MCP_L], trtab[tb + TRT_ST_MCP])
866 swl_trt_cell(1, buf, trtab[tb + TRT_API_O], trtab[tb + TRT_API_L], trtab[tb + TRT_ST_API])
867 swl_trt_cell(1, buf, trtab[tb + TRT_PRIM_O], trtab[tb + TRT_PRIM_L], trtab[tb + TRT_ST_PRIM])
868 swl_trt_cell(1, buf, trtab[tb + TRT_WF_O], trtab[tb + TRT_WF_L], trtab[tb + TRT_ST_WF])
869 swl_trt_cell(1, buf, trtab[tb + TRT_AGENT_O], trtab[tb + TRT_AGENT_L], trtab[tb + TRT_ST_AGENT])
870 w(1, "<td class='ct'>" as *u8); w(1, trt_verdict_name(trtab[tb + TRT_VERDICT])); w(1, "</td></tr>\n" as *u8)
871 tq = tq + 1
872 }
873 sc_plan_table_close(1); w(1, "\n" as *u8)
874 }
875 }
876 return 1
877}
878// ---- WATCH CONTRACTS, MEASURED, FOR EVERY PAGE KIND (2026-08-23, lane L) ----
879// A sota-class page renders <dom>.sota (hand-graded cells) while the ranker reads <dom>.matrix, so a
880// sota domain that also carries a .matrix NEVER FLIPPED on the page when a watch symbol landed
881// (measured on /compare/lang: LN2 landed, the regen republished the page at an IDENTICAL byte size).
882// watch_pass renders the .matrix's symbol rows with their status MEASURED by the one ruler
883// (nx_symdecl_lib sd_declared) -- the same function the matrix generator, the ranker and the regen's
884// comparewatch plane use -- so the page, the plane and the ranker cannot disagree by construction.
885// Writes to fd (a gate captures it through a file), mode 1 = HTML section, mode 2 = JSON array value.
886// An absent .matrix writes NOTHING and returns 0 (a byte-identical emit for every domain without one).
887// Returns the number of symbol rows rendered; the partition it prints must sum to that number.
888const WP_ST_LANDED: i64 = 1
889const WP_ST_WATCHING: i64 = 2
890const WP_ST_PRESENT: i64 = 3
891const WP_ST_MISSING: i64 = 4
892const WP_ST_ABSENT: i64 = 5
893func wp_status_text(st: i64) -> *u8 {
894 if st == WP_ST_LANDED { return "LANDED" as *u8 }
895 if st == WP_ST_WATCHING { return "WATCHING" as *u8 }
896 if st == WP_ST_PRESENT { return "PRESENT" as *u8 }
897 if st == WP_ST_MISSING { return "MISSING" as *u8 }
898 return "ABSENT" as *u8
899}
900func wp_status_class(st: i64) -> *u8 {
901 if st == WP_ST_LANDED { return "me" as *u8 }
902 if st == WP_ST_PRESENT { return "me" as *u8 }
903 if st == WP_ST_WATCHING { return "pa" as *u8 }
904 return "ab" as *u8
905}
906// classify ONE matrix row: organ + symbol field -> status. Measured, never read from the spelling.
907func wp_classify(organ: *u8, sym: *u8, rule_out: *i64) -> i64 {
908 rule_out[0] = 0
909 if streq(sym, "_ABSENT_" as *u8) == 1 { return WP_ST_ABSENT }
910 if starts(sym, "_ABSENT_:" as *u8) == 1 {
911 if sd_present(organ, (sym as i64 + 9) as *u8, rule_out) == 1 { return WP_ST_LANDED }
912 return WP_ST_WATCHING
913 }
914 if sd_present(organ, sym, rule_out) == 1 { return WP_ST_PRESENT }
915 return WP_ST_MISSING
916}
917func watch_pass(mpath: *u8, fd: i64, mode: i64) -> i64 {
918 let ln: *i64 = sys_mmap(16) as *i64
919 let b: *u8 = sys_read_file(mpath, ln)
920 if (b as i64) == 0 { return 0 }
921 let n: i64 = ln[0]
922 if n <= 0 { if mode == 2 { wc(fd, 91); wc(fd, 93) } return 0 }
923 // field capacity derived from the widest row (pipes + 1), never a fixed count
924 var maxf: i64 = 2
925 var pc: i64 = 0
926 var i: i64 = 0
927 while i < n { if b[i] == (124 as u8) { pc = pc + 1 } if b[i] == (10 as u8) { if pc + 1 > maxf { maxf = pc + 1 } pc = 0 } i = i + 1 }
928 if pc + 1 > maxf { maxf = pc + 1 }
929 let fld: *i64 = sys_mmap((maxf + 1) * 8) as *i64
930 let rl: *i64 = sys_mmap(16) as *i64
931 var rows: i64 = 0
932 var c_landed: i64 = 0
933 var c_watching: i64 = 0
934 var c_present: i64 = 0
935 var c_missing: i64 = 0
936 var c_absent: i64 = 0
937 var opened: i64 = 0
938 var p: i64 = 0
939 while p < n {
940 var e: i64 = p
941 while e < n { if b[e] == (10 as u8) { break } e = e + 1 }
942 b[e] = 0 as u8
943 let line: *u8 = (b as i64 + p) as *u8
944 p = e + 1
945 var skip: i64 = 0
946 if line[0] == (0 as u8) { skip = 1 }
947 if line[0] == (35 as u8) { skip = 1 }
948 if line[0] == (64 as u8) { skip = 1 }
949 if skip == 0 {
950 let nf: i64 = splitpipe(line, fld, maxf)
951 if nf >= 4 {
952 let label: *u8 = fld[0] as *u8
953 let organ: *u8 = fld[1] as *u8
954 let sym: *u8 = fld[2] as *u8
955 let note: *u8 = fld[nf - 1] as *u8
956 if sym[0] != (0 as u8) {
957 let st: i64 = wp_classify(organ, sym, rl)
958 if st == WP_ST_LANDED { c_landed = c_landed + 1 }
959 if st == WP_ST_WATCHING { c_watching = c_watching + 1 }
960 if st == WP_ST_PRESENT { c_present = c_present + 1 }
961 if st == WP_ST_MISSING { c_missing = c_missing + 1 }
962 if st == WP_ST_ABSENT { c_absent = c_absent + 1 }
963 var symtext: *u8 = sym
964 if starts(sym, "_ABSENT_:" as *u8) == 1 { symtext = (sym as i64 + 9) as *u8 }
965 if mode == 1 {
966 if opened == 0 {
967 w(fd, "<h2 class='ghead' id='watch'>Watch contracts (measured)</h2>\n<div class='meth'><b>Not a claim, a measurement.</b> Each row names an organ and a symbol; the status is re-measured on every publish by the one ruler the ranker and the hive plane use, and the rule it applied is printed beside it: <b>decl</b> a top-level declaration in a NishiLang organ (a comment or a call site does not count), <b>jsdecl</b> a JS declaration form, <b>exists</b> the organ itself (the symbol is its name), <b>marker</b> a literal the organ carries, <b>data</b> a token in a data file. LANDED / PRESENT = measured present, WATCHING = the named contract is still open, MISSING = the row names something its organ does not carry, ABSENT = no contract named.</div>\n" as *u8); sc_plan_table_open(fd, "Watch contracts" as *u8); w(fd, "<thead><tr><th>Axis</th><th>Organ</th><th>Symbol</th><th>Status</th><th>Note</th></tr></thead><tbody>\n" as *u8)
968 opened = 1
969 }
970 w(fd, "<tr><td><b>" as *u8); w(fd, label); w(fd, "</b></td><td class='ct'>" as *u8); w(fd, organ)
971 w(fd, "</td><td class='ct'>" as *u8); w(fd, symtext); w(fd, "</td><td><span class='st " as *u8); w(fd, wp_status_class(st)); w(fd, "'>" as *u8); w(fd, wp_status_text(st))
972 w(fd, "</span>" as *u8)
973 if rl[0] > 0 { w(fd, " <span class='ct'>" as *u8); w(fd, sd_rule_name(rl[0])); w(fd, "</span>" as *u8) }
974 w(fd, "</td><td>" as *u8); wnote(fd, note); w(fd, "</td></tr>\n" as *u8)
975 }
976 if mode == 2 {
977 if opened == 0 { wc(fd, 91); opened = 1 } else { wc(fd, 44) }
978 wc(fd, 123)
979 kv_s(fd, "label" as *u8, label); wc(fd, 44)
980 kv_s(fd, "organ" as *u8, organ); wc(fd, 44)
981 kv_s(fd, "symbol" as *u8, symtext); wc(fd, 44)
982 kv_s(fd, "status" as *u8, wp_status_text(st)); wc(fd, 44)
983 kv_s(fd, "rule" as *u8, sd_rule_name(rl[0])); wc(fd, 44)
984 kv_s(fd, "note" as *u8, note)
985 wc(fd, 125)
986 }
987 rows = rows + 1
988 }
989 }
990 }
991 }
992 if mode == 1 { if opened == 1 {
993 sc_plan_table_close(fd); w(fd, "\n<p class='foot'>watch rows=" as *u8); wn(fd, rows)
994 w(fd, " landed=" as *u8); wn(fd, c_landed); w(fd, " watching=" as *u8); wn(fd, c_watching)
995 w(fd, " present=" as *u8); wn(fd, c_present); w(fd, " missing=" as *u8); wn(fd, c_missing)
996 w(fd, " absent=" as *u8); wn(fd, c_absent); w(fd, " (partition sums)</p>\n" as *u8)
997 } }
998 if mode == 2 { if opened == 1 { wc(fd, 93) } else { wc(fd, 91); wc(fd, 93) } }
999 sys_free_file(b, n)
1000 return rows
1001}
1002
1003// ---- PERSON / PRODUCT / PLACE, MEASURED (operator 2026-08-24: "all our compares should have [UI analysis]
1004// and august 2026 researched sota ... to tell us how to build a better site than our competitors ... person
1005// via privacy and superior cx, product ... design and longevity and features, place ... ease of navigation
1006// and ability to accomplish the desired task"). ONE renderer in the base, both generators call it -- the
1007// refs_pass / watch_pass precedent. Reads knowledge/compare/<dom>.pppstate, the artefact nx_ppp_probe writes
1008// after running ONE ruler on OUR live surface AND on every rival's live front door named in <dom>.ppp:
1009// ppp|<col>|<label>|<url>|<json> last line = "# asof=... surfaces=N probed=K ruler=nx_ppp_probe"
1010// The page prints per-axis permil AND the raw counts beside it, so the derivation can be argued with, and the
1011// direction of the gap per rival is computed HERE from the numbers -- never typed by a seat. A domain with no
1012// .pppstate prints a NAMED absence (the worklist: every compare carries this layer; a page not yet measured
1013// says so in its own words). Self-contained scoped <style> so it renders in BOTH generators regardless of
1014// their page CSS; colours reference the page theme vars with rgb() fallbacks. -1 = unobserved (scores zero
1015// for that rule, never acquitted).
1016const PL_MAXROWS: i64 = 32
1017// first integer value of "<key>": at or after `from`; -999 = key absent (distinct from a real -1 unobserved)
1018func pl_jint(buf: *u8, n: i64, from: i64, key: *u8) -> i64 {
1019 var klen: i64 = 0
1020 while key[klen] != (0 as u8) { klen = klen + 1 }
1021 var i: i64 = from
1022 var at: i64 = 0 - 1
1023 while i + klen <= n {
1024 var k: i64 = 0
1025 var m: i64 = 1
1026 while k < klen { if buf[i + k] != key[k] { m = 0; k = klen } else { k = k + 1 } }
1027 if m == 1 { at = i; i = n } else { i = i + 1 }
1028 }
1029 if at < 0 { return 0 - 999 }
1030 var j: i64 = at + klen
1031 var neg: i64 = 0
1032 if j < n { if buf[j] == (45 as u8) { neg = 1; j = j + 1 } }
1033 var v: i64 = 0
1034 var got: i64 = 0
1035 while j < n {
1036 let c: i64 = buf[j] as i64
1037 if c >= 48 { if c <= 57 { v = v * 10 + (c - 48); got = 1; j = j + 1 } else { j = n } } else { j = n }
1038 }
1039 if got == 0 { return 0 - 999 }
1040 if neg == 1 { return 0 - v }
1041 return v
1042}
1043// offset of the literal `name` inside buf, or 0 (name is chosen to be unique in the row json)
1044func pl_off(buf: *u8, n: i64, name: *u8) -> i64 {
1045 var nl: i64 = 0
1046 while name[nl] != (0 as u8) { nl = nl + 1 }
1047 var i: i64 = 0
1048 while i + nl <= n {
1049 var k: i64 = 0
1050 var m: i64 = 1
1051 while k < nl { if buf[i + k] != name[k] { m = 0; k = nl } else { k = k + 1 } }
1052 if m == 1 { return i }
1053 i = i + 1
1054 }
1055 return 0
1056}
1057func pl_cell(fd: i64, v: i64) -> i64 {
1058 if v == 0 - 999 { w(fd, "<td class='ct'>-</td>" as *u8); return 0 }
1059 if v < 0 { w(fd, "<td class='ct'>unobs</td>" as *u8); return 0 }
1060 w(fd, "<td class='r'>" as *u8); wn(fd, v); w(fd, "</td>" as *u8)
1061 return 0
1062}
1063func ppp_pass(dom: *u8, fd: i64, mode: i64) -> i64 { return ppp_pass_heading(dom, fd, mode, 2) }
1064func ppp_pass_heading(dom: *u8, fd: i64, mode: i64, heading_level: i64) -> i64 {
1065 let sp: *u8 = sys_mmap(600)
1066 var o: i64 = scopy(sp, 0, "knowledge/compare/" as *u8)
1067 o = scopy(sp, o, dom); o = scopy(sp, o, ".pppstate" as *u8); sp[o] = 0 as u8
1068 let ln: *i64 = sys_mmap(16) as *i64
1069 let b: *u8 = sys_read_file(sp, ln)
1070 if (b as i64) == 0 {
1071 if mode == 2 { w(fd, "{\"measured\":false}" as *u8); return 0 }
1072 sc_heading_open(fd, heading_level, " class='ghead' id='ppp'" as *u8); w(fd, "Person · product · place — not yet measured for this domain" as *u8); sc_heading_close(fd, heading_level); w(fd, "\n<div class='meth'><b>Every compare carries this layer.</b> Declare <code>knowledge/compare/" as *u8); w(fd, dom)
1073 w(fd, ".ppp</code> (rows <code>surface|nishi or c1..c4|label|url|connect</code> naming OUR live surface and each rival's front door), run <code>nx_ppp_probe domain " as *u8); w(fd, dom)
1074 w(fd, "</code>, and this section fills itself on the next beat: the same ruler on both sides — privacy and CX (third-party hosts, tracker classes, cookies, security headers), design and longevity (design hygiene, computed WCAG contrast, render-blocking resources, unsized media, script weight, theme and motion queries), findability (landmarks, skip link, on-site search, breadcrumb, headings, internal links).</div>\n" as *u8)
1075 return 0
1076 }
1077 let n: i64 = ln[0]
1078 if n <= 0 { sys_free_file(b, n); if mode == 2 { w(fd, "{\"measured\":false}" as *u8) } return 0 }
1079 // the stamp is the LAST non-empty line; capture it BEFORE the parser NUL-splits anything
1080 var ls: i64 = n
1081 if ls > 0 { if b[ls - 1] == (10 as u8) { ls = ls - 1 } }
1082 while ls > 0 { if b[ls - 1] == (10 as u8) { break } ls = ls - 1 }
1083 let stamp: i64 = (b as i64) + ls
1084 var se: i64 = ls
1085 while se < n { if b[se] == (10 as u8) { break } se = se + 1 }
1086 b[se] = 0 as u8
1087 // collect data-row offsets (lines beginning 'p' = 'ppp|')
1088 let roff: *i64 = sys_mmap(PL_MAXROWS * 8) as *i64
1089 let rlen: *i64 = sys_mmap(PL_MAXROWS * 8) as *i64
1090 var rows: i64 = 0
1091 var p: i64 = 0
1092 while p < ls {
1093 var e: i64 = p
1094 while e < ls { if b[e] == (10 as u8) { break } e = e + 1 }
1095 if b[p] == (112 as u8) { if rows < PL_MAXROWS { roff[rows] = p; rlen[rows] = e - p; rows = rows + 1 } }
1096 p = e + 1
1097 }
1098 let fld: *i64 = sys_mmap(8 * 8) as *i64
1099 if mode == 2 {
1100 w(fd, "{\"stamp\":\"" as *u8); wj(fd, stamp as *u8); w(fd, "\",\"surfaces\":[" as *u8)
1101 var rj: i64 = 0
1102 var emitted: i64 = 0
1103 while rj < rows {
1104 b[roff[rj] + rlen[rj]] = 0 as u8
1105 let line: *u8 = (b as i64 + roff[rj]) as *u8
1106 let nf: i64 = splitpipe(line, fld, 5)
1107 if nf >= 5 {
1108 if emitted > 0 { wc(fd, 44) }
1109 w(fd, fld[4] as *u8)
1110 emitted = emitted + 1
1111 }
1112 rj = rj + 1
1113 }
1114 w(fd, "]}" as *u8)
1115 sys_free_file(b, n)
1116 return rows
1117 }
1118 // ---- mode 1: HTML ----
1119 w(fd, "<style>.pppsec{overflow-x:auto;margin:6px 0 2px}.pppt{border-collapse:collapse;width:100%;font-size:12.5px;min-width:760px}.pppt th{text-align:left;padding:8px 9px 8px 0;border-bottom:1px solid var(--fg,rgb(26,26,28));color:var(--mut,rgb(120,126,134));font-size:10px;letter-spacing:.06em;text-transform:uppercase;white-space:nowrap}.pppt td{border-bottom:1px solid var(--line,rgb(219,216,208));padding:9px 9px 9px 0;vertical-align:top;line-height:1.4}.pppt td.r{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}.pppt td.ct{font-family:var(--mono,ui-monospace,Consolas,monospace);font-size:11px;color:var(--mut,rgb(120,126,134))}.pppt tr.ours td{background:var(--tint,rgba(120,90,220,.06))}.pppt tr.ours td.ni b{color:var(--ac,rgb(88,64,180))}.pppt a{color:var(--ac,rgb(88,64,180));text-decoration:none}</style>\n" as *u8)
1120 sc_heading_open(fd, heading_level, " class='ghead' id='ppp'" as *u8); w(fd, "Person · product · place — the same ruler on our live surface and on theirs" as *u8); sc_heading_close(fd, heading_level); w(fd, "\n" as *u8)
1121 w(fd, "<div class='meth'><b>Measured on both sides, from the bytes a first visitor receives.</b> <code>nx_ppp_probe</code> fetched every surface below over the sovereign TLS stack and scored three axes by declared rules, each a count against a published Aug-2026 bar. <b>Person</b> (privacy + CX): third-party asset/script hosts, the tracker classes The Markup's Blacklight tests for, consent-banner markers, <code>Set-Cookie</code> on the first consent-less response (the CNIL bar), the OWASP secure headers. <b>Product</b> (design + longevity): design-system hygiene (/12), computed WCAG 2.2 contrast over the page's real colour tokens, the static Core-Web-Vitals predictors (render-blocking css/js, unsized media — the source-visible causes of poor LCP/CLS), script count, dark-mode and reduced-motion queries, canonical URL. <b>Place</b> (findability + task): nav/main/footer landmarks, a skip link, on-site search, breadcrumb, exactly one h1, internal links, lang, viewport, title. Envelope: static HTML plus response headers, no render, no script execution — a client-rendered app is graded on what a no-JS first visitor receives, which is the progressive-enhancement bar itself. <b>unobs</b> = the probe could not see that sub-measure and scored it zero rather than acquit. Stamp: <code>" as *u8)
1122 w(fd, stamp as *u8); w(fd, "</code></div>\n" as *u8)
1123 w(fd, "<div class='pppsec'><table class='pppt'><thead><tr><th>Surface</th><th class='r'>Person</th><th class='r'>Product</th><th class='r'>Place</th><th class='r'>3p script hosts</th><th class='r'>trackers</th><th class='r'>set-cookie</th><th class='r'>sec hdr /5</th><th class='r'>design /12</th><th class='r'>contrast fails</th><th class='r'>blocking css+js</th><th class='r'>unsized img</th><th class='r'>scripts</th><th class='r'>KB</th><th>nav main skip search crumb</th></tr></thead><tbody>\n" as *u8)
1124 var ours_pe: i64 = 0 - 1
1125 var ours_pr: i64 = 0 - 1
1126 var ours_pl: i64 = 0 - 1
1127 var best_pe: i64 = 0 - 1
1128 var best_pr: i64 = 0 - 1
1129 var best_pl: i64 = 0 - 1
1130 var rr: i64 = 0
1131 while rr < rows {
1132 b[roff[rr] + rlen[rr]] = 0 as u8
1133 let line: *u8 = (b as i64 + roff[rr]) as *u8
1134 let nf: i64 = splitpipe(line, fld, 5)
1135 if nf >= 5 {
1136 let col: *u8 = fld[1] as *u8
1137 let label: *u8 = fld[2] as *u8
1138 let url: *u8 = fld[3] as *u8
1139 let js: *u8 = fld[4] as *u8
1140 var jn: i64 = 0
1141 while js[jn] != (0 as u8) { jn = jn + 1 }
1142 var ours: i64 = 0
1143 if streq(col, "nishi" as *u8) == 1 { ours = 1 }
1144 if ours == 1 { w(fd, "<tr class='ours'><td class='ni'><b>" as *u8) } else { w(fd, "<tr><td><b>" as *u8) }
1145 w(fd, label); w(fd, "</b><br><a href='" as *u8); w(fd, url); w(fd, "' rel='nofollow'><span class='ct'>" as *u8); w(fd, url); w(fd, "</span></a></td>" as *u8)
1146 let unreach: i64 = pl_jint(js, jn, 0, "\"unreachable\":" as *u8)
1147 if unreach != 0 - 999 {
1148 w(fd, "<td colspan='13'>UNREACHABLE (probe code " as *u8); wn(fd, unreach); w(fd, ") — no measurement, no score; re-run the probe rather than infer a number</td></tr>\n" as *u8)
1149 } else {
1150 let sp_pe: i64 = pl_off(js, jn, "\"person\":{" as *u8)
1151 let sp_pr: i64 = pl_off(js, jn, "\"product\":{" as *u8)
1152 let sp_pl: i64 = pl_off(js, jn, "\"place\":{" as *u8)
1153 let pe: i64 = pl_jint(js, jn, sp_pe, "\"score_permil\":" as *u8)
1154 let pr: i64 = pl_jint(js, jn, sp_pr, "\"score_permil\":" as *u8)
1155 let pl: i64 = pl_jint(js, jn, sp_pl, "\"score_permil\":" as *u8)
1156 if ours == 1 {
1157 if pe > ours_pe { ours_pe = pe }
1158 if pr > ours_pr { ours_pr = pr }
1159 if pl > ours_pl { ours_pl = pl }
1160 } else {
1161 if pe > best_pe { best_pe = pe }
1162 if pr > best_pr { best_pr = pr }
1163 if pl > best_pl { best_pl = pl }
1164 }
1165 pl_cell(fd, pe); pl_cell(fd, pr); pl_cell(fd, pl)
1166 pl_cell(fd, pl_jint(js, jn, sp_pe, "\"third_party_script_hosts\":" as *u8))
1167 pl_cell(fd, pl_jint(js, jn, sp_pe, "\"tracker_hits\":" as *u8))
1168 pl_cell(fd, pl_jint(js, jn, sp_pe, "\"set_cookie\":" as *u8))
1169 pl_cell(fd, pl_jint(js, jn, sp_pe, "\"sec_headers\":" as *u8))
1170 pl_cell(fd, pl_jint(js, jn, sp_pr, "\"design_hygiene\":" as *u8))
1171 pl_cell(fd, pl_jint(js, jn, sp_pr, "\"contrast_fails\":" as *u8))
1172 let bc: i64 = pl_jint(js, jn, sp_pr, "\"blocking_css\":" as *u8)
1173 let bj: i64 = pl_jint(js, jn, sp_pr, "\"blocking_js\":" as *u8)
1174 if bc < 0 { pl_cell(fd, bc) } else { if bj < 0 { pl_cell(fd, bj) } else { pl_cell(fd, bc + bj) } }
1175 pl_cell(fd, pl_jint(js, jn, sp_pr, "\"unsized_media\":" as *u8))
1176 pl_cell(fd, pl_jint(js, jn, sp_pr, "\"script_tags\":" as *u8))
1177 let bytes: i64 = pl_jint(js, jn, 0, "\"bytes\":" as *u8)
1178 if bytes > 0 { w(fd, "<td class='r'>" as *u8); wn(fd, bytes / 1024); w(fd, "</td>" as *u8) } else { w(fd, "<td class='ct'>-</td>" as *u8) }
1179 w(fd, "<td class='r ct'>" as *u8)
1180 wn(fd, pl_jint(js, jn, sp_pl, "\"nav\":" as *u8)); wc(fd, 32); wn(fd, pl_jint(js, jn, sp_pl, "\"main\":" as *u8)); wc(fd, 32)
1181 wn(fd, pl_jint(js, jn, sp_pl, "\"skip_link\":" as *u8)); wc(fd, 32); wn(fd, pl_jint(js, jn, sp_pl, "\"site_search\":" as *u8)); wc(fd, 32)
1182 wn(fd, pl_jint(js, jn, sp_pl, "\"breadcrumb\":" as *u8)); w(fd, "</td></tr>\n" as *u8)
1183 }
1184 }
1185 rr = rr + 1
1186 }
1187 w(fd, "</tbody></table></div>\n" as *u8)
1188 // the direction of the gap, computed from the numbers above
1189 w(fd, "<div class='meth'><b>Where to beat them, from the numbers.</b> " as *u8)
1190 if ours_pe >= 0 { if best_pe >= 0 {
1191 w(fd, "PERSON ours " as *u8); wn(fd, ours_pe); w(fd, " vs best rival " as *u8); wn(fd, best_pe)
1192 if ours_pe > best_pe { w(fd, " — we lead; hold it (zero third-party hosts, zero trackers, headers 5/5 is the ceiling). " as *u8) } else { w(fd, " — behind: the higher-scoring rival shows which privacy rule we lose. " as *u8) }
1193 } }
1194 if ours_pr >= 0 { if best_pr >= 0 {
1195 w(fd, "PRODUCT ours " as *u8); wn(fd, ours_pr); w(fd, " vs best rival " as *u8); wn(fd, best_pr)
1196 if ours_pr > best_pr { w(fd, " — we lead on measurable hygiene; the perceptual premium is a judged rung, not this ruler. " as *u8) } else { w(fd, " — behind: design/12, contrast, blocking, unsized and scripts name the rule. " as *u8) }
1197 } }
1198 if ours_pl >= 0 { if best_pl >= 0 {
1199 w(fd, "PLACE ours " as *u8); wn(fd, ours_pl); w(fd, " vs best rival " as *u8); wn(fd, best_pl)
1200 if ours_pl > best_pl { w(fd, " — we lead on the findability floor; task completion by a real user is the next ruler. " as *u8) } else { w(fd, " — behind: nav main skip search crumb, in that order. " as *u8) }
1201 } }
1202 w(fd, "Re-measured by the beat; nothing here is typed by a seat.</div>\n" as *u8)
1203 sys_free_file(b, n)
1204 return rows
1205}
1206
1207// ============================================================================
1208// SC THEME PASS (2026-08-25) -- ONE palette, emitted from the estate's TOKEN SSOT
1209// (nx_brand_tokens), for BOTH domain generators. It is lifted HERE for the same
1210// reason plan_pass, dstate and wlow were lifted here: this module is the base class
1211// the two generators already share, so a palette that lives here CANNOT drift
1212// between them. Two hand-landed dark blocks in two files is the duplicate-ruler
1213// defect wearing a stylesheet.
1214//
1215// WHY IT EXISTS. Measured 2026-08-25 against the LIVE pages, not inherited:
1216// /compare/search scored theme-aware 0/2 and prefers-color-scheme occurred ZERO
1217// times in 79,499 bytes of matrix source. The dark PALETTE was already authored and
1218// already shipping as html[data-theme='dark'] -- it was simply unreachable from the
1219// operating system's own preference. ***A THEME THAT EXISTS BUT CANNOT BE REACHED
1220// WITHOUT HUNTING FOR A CHIP IS A CAPABILITY THE PAGE IS PAYING FOR AND NOT
1221// DELIVERING.*** Nothing here invents a palette, so no contrast pair moved: the dark
1222// values below are byte-identical to the literal they replace, which makes the dark
1223// rendering unchanged BY CONSTRUCTION rather than by inspection.
1224//
1225// ***THE DARK VALUES ARE DECLARED ONCE AND EMITTED TWICE.*** The same parsed rows go
1226// out under html[data-theme='dark'] (the chip) AND under the media query (the OS
1227// preference). Keeping two copies in step is exactly how a chip theme and an auto
1228// theme drift apart; here a drift is not merely unlikely, it is UNREPRESENTABLE --
1229// there is only one copy of the data, and it is re-SELECTED, never re-PARSED, so the
1230// SSOT keeps its 3-pipe field rule, its bt_ident_safe/bt_value_safe injection screens
1231// and its silent-skip semantics. A second brand parser here would be a second ruler.
1232//
1233// ***THE MEDIA BLOCK IS GUARDED :root:not([data-theme]) AND THAT GUARD IS LOAD-BEARING.***
1234// This page ships a three-way switcher (paper/ink/dark) whose sett() calls
1235// setAttribute('data-theme', n) for ALL THREE values -- paper INCLUDED -- and a boot
1236// script restores the stored choice before first paint. But PAPER IS THE BARE :root
1237// DEFAULT: there is no html[data-theme='paper'] rule to out-rank anything. So an
1238// UNGUARDED @media(prefers-color-scheme:dark){:root{...}} would carry EQUAL
1239// specificity to that default and sit LATER in the cascade, and would therefore
1240// repaint a user who had just explicitly chosen Paper on an OS-dark machine. Every
1241// explicit choice sets the attribute, so :not([data-theme]) makes all three chips win
1242// over the OS preference with ONE selector, while a visitor who has chosen nothing
1243// still gets their system preference. ***A DARK BLOCK ADDED WITHOUT FIRST ASKING
1244// WHETHER THE PAGE ALREADY HAS A THEME SWITCHER SILENTLY OVERRIDES AN EXPLICIT USER
1245// CHOICE -- AND FROM THE USER'S SIDE THAT IS INDISTINGUISHABLE FROM A BROKEN BUTTON.***
1246// nx_brand_tokens' bt_emit_dark_root_buf emits the UNGUARDED selector, which is
1247// CORRECT for a page with no switcher (nx_games_page). The difference is the switcher,
1248// not the SSOT, so the fix belongs at this call site and NOT in the shared emitter.
1249//
1250// BREAKPOINTS ARE THE ESTATE'S ONE LADDER, NOT A THIRD SET. 860/640 are taken from
1251// sites/nishifamily/nishi-ds.css section 5 RESPONSIVE -- the same two numbers
1252// nx_games_page adopted, for the same reason: a third ladder would be a duplicate
1253// ruler wearing a constant and nothing downstream could tell the two apart. They
1254// redefine TOKENS ONLY, never components: a token carries no paint, so a breakpoint
1255// cannot restyle anything the page did not already opt into by reading that token.
1256//
1257// MEMORY: the two scratch buffers are deliberately NOT munmap'd per call -- this is a
1258// one-shot page emitter that exits, and sc_theme_pass is called exactly once per page.
1259// Declared rather than left silent.
1260const SC_TOKCAP: i64 = 16384
1261const SC_BP_MD: i64 = 860
1262const SC_BP_SM: i64 = 640
1263
1264// The compare palette AS DATA. Light rows first, then the dark overrides. A token with
1265// NO dark row is theme-independent by construction -- that is why --nx-font-mono and
1266// the layout tokens carry none: a monospace stack and a wrap width are not chrome.
1267func sc_brand() -> *u8 {
1268 return "token|color|bg|rgb(243,241,236)\ntoken|color|fg|rgb(26,26,28)\ntoken|color|accent|rgb(88,64,180)\ntoken|color|panel|rgb(249,247,243)\ntoken|color|soft|rgb(236,233,226)\ntoken|color|tint|rgb(236,233,226)\ntoken|color|line|rgb(219,216,208)\ntoken|color|mut|rgb(92,96,104)\ntoken|color|faint|rgb(138,141,148)\ntoken|color|gk|rgb(60,64,72)\ntoken|color|goff|rgb(198,195,187)\ntoken|color|ghalf|rgb(122,126,134)\ntoken|color|codebg|rgb(229,226,218)\ntoken|color|ok|rgb(26,127,55)\ntoken|color|part|rgb(178,106,0)\ntoken|color|absent|rgb(179,38,30)\ntoken|color|exceed|rgb(130,80,223)\ntoken|font|mono|ui-monospace,Consolas,monospace\ntoken|layout|wrap|clamp(20rem,95vw,110rem)\ntoken|layout|gutter|clamp(14px,3vw,28px)\ntoken|layout|measure|66ch\ntoken|layout|capmin|27rem\ntoken|layout|capgap|clamp(10px,1.6vw,20px)\ntoken|layout|rail|13rem\ndark|color|bg|rgb(16,18,23)\ndark|color|fg|rgb(226,229,235)\ndark|color|accent|rgb(171,152,238)\ndark|color|panel|rgb(23,26,34)\ndark|color|soft|rgb(30,34,43)\ndark|color|tint|rgb(23,26,34)\ndark|color|line|rgb(43,47,56)\ndark|color|mut|rgb(139,146,158)\ndark|color|faint|rgb(100,107,119)\ndark|color|gk|rgb(168,175,186)\ndark|color|goff|rgb(58,63,73)\ndark|color|ghalf|rgb(120,127,138)\ndark|color|codebg|rgb(35,39,48)\ndark|color|ok|rgb(121,224,167)\ndark|color|part|rgb(255,166,120)\ndark|color|absent|rgb(118,130,154)\ndark|color|exceed|rgb(255,209,122)\n" as *u8
1269}
1270
1271// The SSOT's own dark wrapper, named once so its LENGTH is DERIVED and never
1272// hand-counted beside the literal -- a hand-counted length is a second copy of the
1273// string's shape and the two drift silently.
1274func sc_dark_open() -> *u8 { return "@media(prefers-color-scheme:dark){:root{\n" as *u8 }
1275func sc_dark_close() -> *u8 { return "}}\n" as *u8 }
1276
1277func sc_theme_pass(fd: i64) -> i64 {
1278 let bd: *u8 = sc_brand()
1279 let bn: i64 = bt_len(bd)
1280 let tb: *u8 = sys_mmap(SC_TOKCAP)
1281 // ---- light :root, straight from the SSOT ----
1282 let lw: i64 = bt_emit_root_buf(bd, bn, tb, SC_TOKCAP)
1283 if lw < 0 { w(2, "FATAL sc_theme_pass: brand parsed ZERO light tokens -- refusing to emit a page with no palette\n" as *u8); sys_exit(2); return 2 }
1284 // bt_app SATURATES at cap instead of failing, so an undersized buffer truncates the
1285 // palette mid-block and still returns a POSITIVE count. ***A CAP REACHED IN SILENCE
1286 // BECOMES A MEASUREMENT NOBODY KNOWS IS PARTIAL*** -- refuse at the boundary instead.
1287 if lw >= SC_TOKCAP - 1 { w(2, "FATAL sc_theme_pass: light block reached SC_TOKCAP -- this palette is TRUNCATED, not complete\n" as *u8); sys_exit(2); return 2 }
1288 sys_write(fd, tb, lw)
1289 // ---- page-local ALIASES over the SSOT names: one indirection, so a brand DATA edit
1290 // re-themes the whole page and every rule below keeps reading the short name it
1291 // always read. They are var() REFERENCES, not copies, so they resolve at use time --
1292 // which is why ONE alias block serves paper, ink, dark and the OS preference alike.
1293 w(fd, ":root{--bg:var(--nx-color-bg);--fg:var(--nx-color-fg);--ac:var(--nx-color-accent);--panel:var(--nx-color-panel);--soft:var(--nx-color-soft);--tint:var(--nx-color-tint);--line:var(--nx-color-line);--mut:var(--nx-color-mut);--faint:var(--nx-color-faint);--gk:var(--nx-color-gk);--goff:var(--nx-color-goff);--ghalf:var(--nx-color-ghalf);--codebg:var(--nx-color-codebg);--mono:var(--nx-font-mono);--y:var(--nx-color-ok);--p:var(--nx-color-part);--n:var(--nx-color-absent);--ex:var(--nx-color-exceed)}\n" as *u8)
1294 // ---- dark: ONE parse, TWO selectors ----
1295 let dw: i64 = bt_emit_dark_root_buf(bd, bn, tb, SC_TOKCAP)
1296 // bt_emit_dark_root_buf returns 0 (never negative) when the brand carries no dark
1297 // rows, so this guard is <= 0. A < 0 guard here would be a tooth that CANNOT FIRE.
1298 if dw <= 0 { w(2, "FATAL sc_theme_pass: brand carries NO dark override -- the page would ship theme-blind\n" as *u8); sys_exit(2); return 2 }
1299 if dw >= SC_TOKCAP - 1 { w(2, "FATAL sc_theme_pass: dark block reached SC_TOKCAP -- TRUNCATED, not complete\n" as *u8); sys_exit(2); return 2 }
1300 let op: *u8 = sc_dark_open()
1301 let ol: i64 = bt_len(op)
1302 let cl: i64 = bt_len(sc_dark_close())
1303 // The re-selection is only valid if the SSOT still emits the wrapper we expect. If it
1304 // ever changes, slicing past a stale prefix would emit a CORRUPT block that still
1305 // looks like CSS -- so verify the prefix and refuse loudly rather than guess.
1306 var gi: i64 = 0
1307 while gi < ol { if tb[gi] != op[gi] { w(2, "FATAL sc_theme_pass: nx_brand_tokens changed its dark wrapper -- re-selecting it would corrupt the block\n" as *u8); sys_exit(2); return 2 } gi = gi + 1 }
1308 let rs: i64 = ol
1309 let re: i64 = dw - cl
1310 if re <= rs { w(2, "FATAL sc_theme_pass: dark block carried no rows between its wrapper\n" as *u8); sys_exit(2); return 2 }
1311 let rb: *u8 = sys_mmap(SC_TOKCAP)
1312 var k: i64 = 0
1313 while rs + k < re { rb[k] = tb[rs + k]; k = k + 1 }
1314 w(fd, "html[data-theme='dark']{\n" as *u8)
1315 sys_write(fd, rb, k)
1316 w(fd, "}\n" as *u8)
1317 w(fd, "@media(prefers-color-scheme:dark){:root:not([data-theme]){\n" as *u8)
1318 sys_write(fd, rb, k)
1319 w(fd, "}}\n" as *u8)
1320 // ---- breakpoints: TOKENS ONLY, on the estate's one ladder ----
1321 w(fd, "@media (max-width:" as *u8); wn(fd, SC_BP_MD); w(fd, "px){:root{--nx-layout-gutter:clamp(12px,3.6vw,18px)}}\n" as *u8)
1322 w(fd, "@media (max-width:" as *u8); wn(fd, SC_BP_SM); w(fd, "px){:root{--nx-layout-wrap:100%;--nx-layout-gutter:12px}}\n" as *u8)
1323 return 0
1324}
1325
1326// ---- sc_print_css: THE ONE PRINT STYLESHEET FOR EVERY COMPARE PAGE (datavis DV7, 2026-09-15) ----
1327// WHY THIS EXISTS. A board is read on paper and as a PDF as often as on a screen, and until today every
1328// compare page printed exactly what it painted: the sticky filter bar over the first page, theme chips
1329// in the header, a position map sliced across a page break, evidence tables whose header row appeared
1330// once and never again. There was no print block anywhere in the family (measured 2026-09-15: zero
1331// print media rules over the emitted HTML), so "prints as pages" was true only by accident.
1332// ONE EMITTER, EVERY GENERATOR. Exactly the sc_theme_pass / sc_layout_pass shape: the block is written
1333// ONCE here and every generator calls it, so a board, a sota page and the hub cannot drift apart on
1334// paper any more than they can on screen.
1335// ORDER IS THE SPECIFICITY. Every generator calls this LAST, immediately before the style close. A print
1336// rule that has to beat a screen rule of equal specificity wins by ORDER, never by importance: the nx_cc
1337// lexer refuses the bang byte inside a string literal, and a print sheet that needs it is a sheet emitted
1338// in the wrong place. nx_print_css_gate pins the bytes; the call sites are one grep away.
1339// PAPER IS THE LIGHT REGISTER, MADE WHITE. The SSOT's light rows are re-selected under
1340// html,html[data-theme],:root:not([data-theme]) -- the last of those is the OS-preference selector's own
1341// specificity, so a dark chip, an OS-dark machine and the ink register all print as the light register;
1342// then the five grounds (bg, panel, soft, tint, codebg) go white, because browsers do not print
1343// background graphics by default and a tinted ground that is NOT printed would leave every text class
1344// (measured against its surface by DV3) sitting on a surface the paper never shows.
1345// WHAT IT DOES, in the rung's own words: figures unbroken (break-inside:avoid on every figure and card),
1346// tables paginated (thead repeats as the table-header-group, a row never splits), chips and filters
1347// hidden (the sticky filter bar, the filter and theme chips, the skip link, the header nav, the map's
1348// tooltip and selection line). A link prints its target once, except inside the refs list and the
1349// breadcrumb, which already carry their URLs as text.
1350const SC_PRINT_MARGIN_MM: i64 = 14
1351const SC_PRINT_BODY_PT: i64 = 11
1352// The SSOT's own light wrapper, named once so its LENGTH is DERIVED (the reason sc_dark_open exists).
1353func sc_light_open() -> *u8 { return ":root{\n" as *u8 }
1354func sc_light_close() -> *u8 { return "}\n" as *u8 }
1355// EC47 (2026-09-16): the daily /compare feed, advertised in the head of EVERY emitted page (the hub and the gateway's root
1356// index already carry it), so a feed reader subscribed from any board finds the one feed of positions and reviews.
1357const SC_FEED_LINK_TAG: *u8 = "<link rel='alternate' type='application/rss+xml' title='Nishi /compare daily positions and reviews' href='/compare/feed.xml'>
1358"
1359func sc_feed_link(fd: i64) -> i64 { w(fd, SC_FEED_LINK_TAG); return 0 }
1360
1361func sc_print_css(fd: i64) -> i64 {
1362 let bd: *u8 = sc_brand()
1363 let bn: i64 = bt_len(bd)
1364 let tb: *u8 = sys_mmap(SC_TOKCAP)
1365 let lw: i64 = bt_emit_root_buf(bd, bn, tb, SC_TOKCAP)
1366 if lw < 0 { w(2, "FATAL sc_print_css: brand parsed ZERO light tokens -- refusing to emit a print sheet with no palette\n" as *u8); sys_exit(2); return 2 }
1367 if lw >= SC_TOKCAP - 1 { w(2, "FATAL sc_print_css: light block reached SC_TOKCAP -- TRUNCATED, not complete\n" as *u8); sys_exit(2); return 2 }
1368 let op: *u8 = sc_light_open()
1369 let ol: i64 = bt_len(op)
1370 let cp: *u8 = sc_light_close()
1371 let cl: i64 = bt_len(cp)
1372 var gi: i64 = 0
1373 while gi < ol { if tb[gi] != op[gi] { w(2, "FATAL sc_print_css: nx_brand_tokens changed its light wrapper -- re-selecting it would corrupt the print block\n" as *u8); sys_exit(2); return 2 } gi = gi + 1 }
1374 gi = 0
1375 while gi < cl { if tb[lw - cl + gi] != cp[gi] { w(2, "FATAL sc_print_css: nx_brand_tokens changed its light closer -- re-selecting it would corrupt the print block\n" as *u8); sys_exit(2); return 2 } gi = gi + 1 }
1376 let re: i64 = lw - cl
1377 if re <= ol { w(2, "FATAL sc_print_css: light block carried no rows between its wrapper\n" as *u8); sys_exit(2); return 2 }
1378 w(fd, "@media print{\n" as *u8)
1379 w(fd, "html,html[data-theme],:root:not([data-theme]){\n" as *u8)
1380 sys_write(fd, tb + ol, re - ol)
1381 w(fd, "}\n" as *u8)
1382 w(fd, "html,html[data-theme],:root:not([data-theme]){--nx-color-bg:rgb(255,255,255);--nx-color-panel:rgb(255,255,255);--nx-color-soft:rgb(255,255,255);--nx-color-tint:rgb(255,255,255);--nx-color-codebg:rgb(255,255,255)}\n" as *u8)
1383 w(fd, "@page{margin:" as *u8); wn(fd, SC_PRINT_MARGIN_MM); w(fd, "mm}\n" as *u8)
1384 w(fd, "html{color-scheme:light}\n" as *u8)
1385 w(fd, "body{background:var(--nx-color-bg);color:var(--nx-color-fg);font-size:" as *u8); wn(fd, SC_PRINT_BODY_PT); w(fd, "pt;line-height:1.4}\n" as *u8)
1386 w(fd, "main>*{animation:none}\n" as *u8)
1387 w(fd, ".fbar,.fchip,.tchip,.tgroup,.cnt,.skip-link,.hd,.lnav,.cdtip,.cdsel,[data-print='hide']{display:none}\n" as *u8)
1388 w(fd, ".cdleg,.cdleg[aria-pressed='false']{opacity:1;text-decoration:none}\n" as *u8)
1389 w(fd, "figure,.cdfig,.galf,.cap,.verdict,.meth,.answer,.ev,.refs li{break-inside:avoid;page-break-inside:avoid}\n" as *u8)
1390 w(fd, "figure{max-width:100%}\n" as *u8)
1391 w(fd, "svg,img{max-width:100%;height:auto}\n" as *u8)
1392 w(fd, "table{break-inside:auto;page-break-inside:auto}\n" as *u8)
1393 w(fd, "thead{display:table-header-group}\n" as *u8)
1394 w(fd, "tfoot{display:table-footer-group}\n" as *u8)
1395 w(fd, "tr{break-inside:avoid;page-break-inside:avoid;break-after:auto}\n" as *u8)
1396 w(fd, "h1,h2,h3,.ghead,.layer,.eyebrow{break-after:avoid;page-break-after:avoid}\n" as *u8)
1397 w(fd, ".layer{color:var(--nx-color-fg);background:none;border:1px solid var(--nx-color-fg)}\n" as *u8)
1398 w(fd, "details summary::after,details[open] summary::after{content:none}\n" as *u8)
1399 w(fd, "a{color:inherit;text-decoration:none}\n" as *u8)
1400 w(fd, "a[href^='http']::after{content:' (' attr(href) ')';font-size:.8em;color:var(--nx-color-mut);overflow-wrap:anywhere}\n" as *u8)
1401 w(fd, ".refs a::after,.crumb a::after{content:none}\n" as *u8)
1402 w(fd, ".g,.dot,.st,.badge,.bst,.pstate,.watch{-webkit-print-color-adjust:exact;print-color-adjust:exact}\n" as *u8)
1403 w(fd, "}\n" as *u8)
1404 return 0
1405}
1406
1407// ---- sc_layout_pass: THE ONE LAYOUT EMITTER FOR EVERY COMPARE PAGE (2026-08-31) ----
1408// WHY THIS EXISTS. The body rule was hand-copied into SEVEN generators and had already drifted to
1409// SIX different page widths (960/980/1000/1040/1080/1180) -- the duplicate-ruler defect living in
1410// emitted CSS, where nothing compares the copies. Worse, the two layout TOKENS the SSOT publishes
1411// (--nx-layout-wrap/--nx-layout-gutter) were DEFINED on every page and REFERENCED by none of the
1412// sota-class ones: they hardcoded max-width:980px and a second clamp() straight over the top.
1413// ***A TOKEN DEFINED AND NEVER READ IS NOT A DESIGN SYSTEM, IT IS DEAD BYTES THAT LOOK LIKE ONE***
1414// -- and the page it governed rendered as one narrow column down the middle of a 1920px display.
1415//
1416// FULL CANVAS WITHOUT UNREADABLE PROSE. These are two different width budgets and the fix is to stop
1417// spending one on the other. The PAGE takes a fluid clamp (95vw, capped) so the LAYOUT uses the
1418// display; PROSE keeps its own measure cap (--nx-layout-measure, 66ch) applied to the text element
1419// itself, never to its container. Surplus width therefore cannot lengthen a line -- it has nowhere
1420// to go except into more capability cards side by side, which is more information on screen rather
1421// than a 200-character sentence.
1422//
1423// WHY SC_CAP_SPLIT IS A CONST AND NOT A TOKEN. Every other layout number here is a --nx-layout-*
1424// token, per rule 11. This one CANNOT be: a CSS container/media query CONDITION does not accept
1425// var(), so the threshold must reach the stylesheet as a literal. A named const emitted through wn()
1426// is the same guarantee by the only mechanism CSS allows -- it is not an exception to the rule, it is
1427// the rule honoured where var() is structurally unavailable. 496px is where a card can seat the
1428// 13rem rail beside a main column still wider than the rail; below it the card stacks.
1429//
1430// CONTAINER QUERY, NOT A BREAKPOINT, FOR THE CARD. The same .cap renders one-per-row on a phone and
1431// three-across on a desktop, so its reflow depends on ITS OWN width, not the window's. @container is
1432// Baseline Widely Available (2025-08-14). The container-name is declared explicitly and queried by
1433// name: an unresolvable container silently falls back to small-viewport units rather than erroring,
1434// so the anonymous form would fail as a confident wrong answer.
1435const SC_CAP_SPLIT: i64 = 496
1436// Shared production sections preserve all domain detail and existing deep links.
1437func sc_production_open(fd: i64, id: *u8, title: *u8, purpose: *u8) -> i64 {
1438 w(fd, "<section class='production-section' aria-labelledby='" as *u8); w(fd, id); w(fd, "'>\n<h2 class='production-title' id='" as *u8); w(fd, id); w(fd, "'>" as *u8); w(fd, title); w(fd, "</h2>\n<p class='production-purpose'>" as *u8); w(fd, purpose); w(fd, "</p>\n<div class='production-detail'>\n" as *u8)
1439 return 0
1440}
1441func sc_production_close(fd: i64) -> i64 { w(fd, "</div></section>\n" as *u8); return 0 }
1442
1443func sc_layout_pass(fd: i64) -> i64 {
1444 w(fd, ".production-section{margin-block:3em;border-top:1px solid var(--line);padding-top:1.5em}.production-title{font-size:clamp(1.6rem,3vw,2.5rem);line-height:1.15;letter-spacing:-.025em;margin:0 0 .5em;scroll-margin-top:1em}.production-purpose{max-width:var(--nx-layout-measure);color:var(--mut);margin:0 0 2em}.production-detail{min-width:0}.production-detail h3{font-size:1.25rem;margin-top:2em}.production-detail h4{font-size:1.1rem}.production-nav{display:flex;flex-wrap:wrap;gap:.5em;padding:1em 0;border-block:1px solid var(--line);margin:2em 0}.production-nav a{display:block;padding:.6em .9em;text-decoration:none;border:1px solid var(--line);border-radius:.4em}.production-nav a:hover,.production-nav a:focus-visible{background:var(--panel);text-decoration:underline}.production-detail>*{min-width:0;max-width:100%}\n" as *u8)
1445 // page shell -- reads the SSOT tokens, so a brand DATA edit re-widths every compare page at once
1446 w(fd, "*{box-sizing:border-box}html{scrollbar-gutter:stable}\n" as *u8)
1447 w(fd, "body{background:var(--bg);font-family:-apple-system,Segoe UI,Roboto,sans-serif;max-width:var(--nx-layout-wrap);margin:0 auto;padding:0 var(--nx-layout-gutter) 6vh;color:var(--fg);line-height:1.6;font-size:1rem}\n" as *u8)
1448 // min-width:0 defeats the min-content floor that grid/flex children carry by default. Without it a
1449 // single wide table forces every ancestor wider than its track and THE PAGE scrolls sideways --
1450 // the overflow lands on the document, which is the one place it must never land.
1451 w(fd, "main{min-width:0}main>*{min-width:0;max-width:100%}table{max-width:100%}\n" as *u8)
1452 // long unbroken identifiers (organ names, hashes, paths) are the only real width bombs on these
1453 // pages; break them where they occur instead of letting them set the table's minimum width
1454 w(fd, ".pl .ct,.ev code,.rlinks code,.watch{overflow-wrap:anywhere}\n" as *u8)
1455 // ---- PROSE MEASURE: ONE cap for the prose blocks BOTH archetypes emit ----
1456 // THE REGRESSION THIS FUNCTION CAUSED, AND WHY THE FIX LANDS HERE. Widening body from a fixed 980px
1457 // to a fluid clamp is right for the LAYOUT and wrong for PROSE unless the prose carries its own cap.
1458 // Matrix learned that on 2026-08-25 and capped .meth/.lead/.answer/.verdict at 72ch. Sota never
1459 // received it: measured over the whole corpus, 72ch occurs 5 times in the estate and ALL FIVE are in
1460 // nx_swcompare_matrix (coverage_complete=1 corpus_complete=1 over 23,407 files). So sota's .meth --
1461 // the ~1,100-character "How this is scored" block, the FIRST prose a reader meets -- went from
1462 // inheriting 980px (~130 characters a line) to inheriting up to 1760px (~240), roughly 3x the WCAG
1463 // 1.4.8 (AAA) 80-character ceiling. ***A FIX THAT LIVES IN ONE ORGAN AND NOT ITS SIBLING IS HALF A
1464 // FIX***, and widening the canvas converted this one from latent to acute.
1465 //
1466 // WHY THE TOKEN AND NOT A SECOND 72ch. --nx-layout-measure is already the SSOT's declared prose
1467 // measure and is already read by .cap-note. Hard-coding 72ch a second time -- in the SHARED lib, no
1468 // less -- is the duplicate-ruler defect this extraction exists to remove, and nothing downstream
1469 // could tell the two copies apart. It does NOT overrule matrix: matrix emits its own .meth/.verdict
1470 // rules AFTER this one at equal specificity, so matrix still renders at 72ch and its emitted bytes
1471 // are unchanged. Only sota, which carried NO cap at all, changes. .lead and .answer are deliberately
1472 // NOT here -- they are matrix-only classes already carrying their own 72ch, so listing them would
1473 // add a second ruler for a page that already has one.
1474 w(fd, ".lead,.answer,.meth,.verdict{max-width:var(--nx-layout-measure);text-wrap:pretty}\n" as *u8)
1475 w(fd, ".exec-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,var(--nx-layout-capmin)),1fr));gap:var(--nx-layout-capgap);align-items:start;margin:var(--nx-layout-capgap) 0}.exec-grid>*{min-width:0;overflow-wrap:anywhere}.exec-grid>.lead,.exec-grid>.answer,.exec-grid>.meth{max-width:min(100%,var(--nx-layout-measure));margin:0}.exec-grid>h2,.exec-grid>h3,.exec-grid>table{grid-column:1/-1}.table-scroll{max-width:100%;overflow-x:auto;overscroll-behavior-inline:contain}.table-scroll>table{max-width:none;min-width:100%;width:max-content}.table-scroll th,.table-scroll td{white-space:nowrap}.table-scroll th:first-child,.table-scroll td:first-child{white-space:normal;width:var(--nx-layout-capmin);min-width:min(100vw - 2 * var(--nx-layout-gutter),var(--nx-layout-capmin));max-width:var(--nx-layout-capmin)}.table-scroll:focus-visible{outline:3px solid var(--ac);outline-offset:2px}\n" as *u8)
1476 // ---- the capability board: a responsive multi-column grid ----
1477 // auto-FILL, never auto-fit: auto-fit collapses the empty tracks and stretches a lone card across
1478 // the whole canvas, which re-creates at component scale the exact single-wide-column defect this
1479 // function exists to remove. min(100%,...) inside minmax is load-bearing: the auto-repeat count is
1480 // computed from the track MINIMUM, so a bare minmax(27rem,1fr) overflows any container narrower
1481 // than 27rem instead of dropping to one column.
1482 w(fd, ".caps{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,var(--nx-layout-capmin)),1fr));gap:var(--nx-layout-capgap);align-items:start;margin:6px 0}\n" as *u8)
1483 // the category headings are emitted INSIDE .caps, so they are grid items too and must span the row
1484 w(fd, ".caps>.ghead{grid-column:1/-1}\n" as *u8)
1485 // THE CARD IS SCOPED .caps>.cap, NOT BARE .cap, FOR THE SAME REASON .ghead ABOVE IS. "cap" is an
1486 // overloaded name in this estate and a bare rule in a SHARED lib claims it globally. Measured over
1487 // the whole corpus (coverage_complete=1 corpus_complete=1, 23,407 files) there are four other
1488 // holders: nx_swcompare_crm:64 and nx_swcompare_sending:65 both emit <td class='cap'> inside a <tr>,
1489 // and _hdl_build/nx_rewards:175 emits <span class='cap'> -- none of them a child of .caps, so the
1490 // child combinator excludes all three BY CONSTRUCTION. That matters because the roadmap is to
1491 // convert those generators onto this emitter, and display:grid landing on a <td> overrides
1492 // display:table-cell and destroys the table. Scoping costs 6 bytes and removes the trap before
1493 // anyone can walk into it.
1494 //
1495 // ***THIS IS NOT A COMPLETE FENCE AND MUST NOT BE READ AS ONE.*** The same census found a FIFTH
1496 // holder that the child combinator does NOT exclude: nx_compare_unified:281 emits
1497 // <div class='caps'> with <span class='cap on'> as its DIRECT CHILDREN, so .caps>.cap matches its
1498 // chip row exactly. It is harmless today -- nx_compare_unified does not call sc_layout_pass (the
1499 // four callers, RE-CENSUSED 2026-08-31 at coverage_complete=1 corpus_complete=1 over 23,407 files,
1500 // are nx_swcompare_sota, nx_swcompare_matrix, nx_swcompare_hub and nx_swcompare_watch_gate -- an
1501 // earlier revision of this comment said THREE and omitted hub. LINE NUMBERS ARE DELIBERATELY NOT
1502 // CITED HERE: hub's call site moved 729 -> 863 while this comment was being written, so a line
1503 // citation would rot faster than the fact it carries -- re-derive it with a grep for the symbol.
1504 // That undercount is load-bearing, not cosmetic: this enumeration IS the whole basis for calling the
1505 // collision harmless, so a fence that miscounts its own callers asserts a gap it never measured) -- but
1506 // whoever converts nx_compare_unified inherits a live collision, and a chip is not a card. Naming
1507 // the residual here rather than in a report nobody re-reads: a count without a worklist is not
1508 // actionable, and a fence published as "done" is worse than one published with its gap.
1509 w(fd, ".caps>.cap{container-type:inline-size;container-name:nxcap;display:grid;grid-template-columns:minmax(0,1fr) minmax(0,var(--nx-layout-rail));gap:6px 18px;padding:14px 16px;border:1px solid var(--line);border-radius:14px;background:var(--panel);align-items:start;min-width:0}\n" as *u8)
1510 w(fd, ".caps>.cap>.capmain,.caps>.cap>.capside{grid-column:1/-1}.capmain{min-width:0}.cap-note{max-width:var(--nx-layout-measure);text-wrap:pretty}\n" as *u8)
1511 w(fd, ".capside{display:flex;flex-direction:row;flex-wrap:wrap;align-items:center;gap:8px}.rw{max-width:100%}\n" as *u8)
1512 w(fd, "@container nxcap (min-width:" as *u8); wn(fd, SC_CAP_SPLIT); w(fd, "px){.caps>.cap>.capmain{grid-column:1;grid-row:1}.caps>.cap>.capside{grid-column:2;grid-row:1;flex-direction:column;align-items:flex-end}.caps>.cap .rw{justify-content:flex-end;max-width:var(--nx-layout-rail)}}\n" as *u8)
1513 w(fd, ".production-detail{overflow-wrap:anywhere}.lead,.answer,.meth,.verdict{overflow-wrap:anywhere}.production-detail .legend .m{display:inline-block;max-width:100%;white-space:normal}.plan-table-scroll>table{width:100%;min-width:var(--nx-layout-measure);max-width:none}.plan-table-scroll th,.plan-table-scroll td{white-space:normal;overflow-wrap:anywhere}.plan-table-scroll th:first-child,.plan-table-scroll td:first-child{width:auto;min-width:0;max-width:none}.exec-grid>.plan-table-scroll{grid-column:1/-1}.plan-table-scroll th,.plan-table-scroll td.ct{overflow-wrap:normal}.plan-table-scroll th{white-space:nowrap}" as *u8)
1514 sg_css(fd)
1515 return 0
1516}
1517
1518// ---- THE EVIDENCE PROFILE AS MACHINE-READABLE DATA (2026-08-31, frontier F1208) -------------------
1519// ONE RENDERER IN THE BASE, BOTH GENERATORS CALL IT -- the refs_pass / plan_pass precedent exactly. The
1520// HTML band (ev_pass, in nx_swcompare_matrix) and this JSON projection read THE SAME stamp through THE
1521// SAME reader, nx_evprofile_lib, so a board page and its api.json cannot disagree about that domain's
1522// gaps: there is one artifact and one parser, and this function only PROJECTS what evp_parse already
1523// read. THE GENERATOR ADDS A READER, NEVER A MEASUREMENT -- every field below is already materialised
1524// verbatim on knowledge/status/evstamp_<domain>.verdict by nx_swcompare_evidence.
1525//
1526// ABSTAIN, NEVER ACQUIT -- AND HERE THE ABSTAIN PATH IS THE COMMON PATH. 92 of the 95 live stamps are
1527// v1 (measured 2026-08-31), so the branch that emits NO NUMBERS is the one nearly every board takes,
1528// and it is therefore the one that has to be right: a v1 stamp carries none of the profile keys,
1529// evp_parse leaves every slot -1, and writing a 0 there would publish a gapless board for a domain
1530// nobody ever measured. AN ALWAYS-ZERO FIELD READS AS EVIDENCE.
1531// The evidence key is emitted on EVERY path, including the abstentions. An ABSENT key is
1532// indistinguishable from an emitter that never shipped, so the abstention is published as a VALUE --
1533// status UNKNOWN / UNSTAMPED / AMBIGUOUS -- and never as a silence.
1534//
1535// NO SCALAR GRADE, DELIBERATELY. Counts WITH their denominators, the partition sums, and the list of
1536// gap classes that FIRE. A stored scalar is a field a seat can edit; a counted partition is not, and
1537// any consumer can recompute whatever ranking it wants from these numbers at read time.
1538//
1539// NO PATH IS BUILT HERE. evp_load composes ep_artifact_path, so this behaves identically whether the
1540// generator was launched from the estate root or -- as nx_compare_regen launches it -- from buildroot,
1541// whose knowledge/status holds ZERO evstamp files. A bare relative read there would confidently render
1542// no-evidence for all 96 domains.
1543func evj_class(fired: i64, name: *u8, n: *i64) -> i64 {
1544 if fired != 1 { return 0 }
1545 if n[0] > 0 { wc(1, 44) }
1546 wq(1); wj(1, name); wq(1)
1547 n[0] = n[0] + 1
1548 return 1
1549}
1550
1551func evj_pass(dom: *u8) -> i64 {
1552 let buf: *u8 = sys_mmap(EVP_STAMP_CAP)
1553 let pathout: *u8 = sys_mmap(EVP_PATH_CAP)
1554 let flags: *i64 = sys_mmap(8 * EVP_NFLAG) as *i64
1555 let n: i64 = evp_load(dom, buf, EVP_STAMP_CAP, pathout, flags)
1556 wc(1, 44); wq(1); w(1, "evidence" as *u8); wq(1); wc(1, 58); wc(1, 123)
1557 kv_s(1, "producer" as *u8, "nx_swcompare_evidence" as *u8); wc(1, 44)
1558 kv_s(1, "reader" as *u8, "nx_evprofile_lib" as *u8); wc(1, 44)
1559 // Two different files answering to one name is REFUSED, not silently decided: ep_open_rd probes the
1560 // caller CWD first on purpose, so a stray copy beside the generator would win, and win silently.
1561 if n == EVP_RC_AMBIGUOUS {
1562 kv_s(1, "evidence_status" as *u8, "AMBIGUOUS" as *u8); wc(1, 44)
1563 kv_s(1, "source" as *u8, pathout); wc(1, 44)
1564 kv_s(1, "note" as *u8, "two different files answer to one stamp name -- one under the generator working directory, one at the estate root, and their bytes differ. No reader may pick one, so no numbers are published." as *u8)
1565 wc(1, 125)
1566 return 0
1567 }
1568 if n < 0 {
1569 kv_s(1, "evidence_status" as *u8, "UNSTAMPED" as *u8); wc(1, 44)
1570 kv_s(1, "note" as *u8, "no evidence stamp exists for this domain yet: run nx_swcompare_evidence on it and this object fills itself on the next beat. Not one numeric field is emitted, deliberately -- a zero-filled profile reads as a board with no gaps, which is the one wrong answer nobody would question." as *u8)
1571 wc(1, 125)
1572 return 0
1573 }
1574 let f: *i64 = sys_mmap(8 * EVP_NF) as *i64
1575 evp_parse(buf, n, f)
1576 kv_s(1, "source" as *u8, pathout); wc(1, 44)
1577 kv_n(1, "stamp_version" as *u8, f[EVP_F_V]); wc(1, 44)
1578 kv_n(1, "stamp_read_capped" as *u8, flags[EVP_FL_BRIM]); wc(1, 44)
1579 // THE VERSION IS DERIVED FROM THE WIRE, NEVER DECLARED ON IT: a v1 stamp simply has no profile keys.
1580 if f[EVP_F_V] < 2 {
1581 kv_s(1, "evidence_status" as *u8, "UNKNOWN" as *u8); wc(1, 44)
1582 kv_s(1, "note" as *u8, "this stamp predates the gap profile and carries none of its keys, so the reader abstains rather than acquit. UNKNOWN IS NOT ZERO. Re-stamp with nx_swcompare_evidence on this domain and the counts below appear." as *u8)
1583 wc(1, 125)
1584 return 0
1585 }
1586 let now: i64 = sys_now_realtime_sec()
1587 let ttl: i64 = evp_ttl_sec()
1588 let stale: i64 = evp_stale(f, now, ttl)
1589 var age: i64 = now - f[EVP_F_EPOCH]
1590 if age < 0 { age = 0 }
1591 kv_s(1, "evidence_status" as *u8, "MEASURED" as *u8); wc(1, 44)
1592 kv_n(1, "ok" as *u8, f[EVP_F_OK]); wc(1, 44)
1593 kv_n(1, "epoch" as *u8, f[EVP_F_EPOCH]); wc(1, 44)
1594 kv_n(1, "age_sec" as *u8, age); wc(1, 44)
1595 kv_n(1, "ttl_sec" as *u8, ttl); wc(1, 44)
1596 kv_n(1, "stale" as *u8, stale); wc(1, 44)
1597 // EVERY COUNT CARRIES ITS DENOMINATOR: a bare grounded=14 is not a fact about a board.
1598 wq(1); w(1, "grounded" as *u8); wq(1); wc(1, 58); wc(1, 123)
1599 kv_n(1, "count" as *u8, f[EVP_F_GROUNDED]); wc(1, 44); kv_n(1, "of" as *u8, f[EVP_F_PRESENT])
1600 wc(1, 125); wc(1, 44)
1601 kv_n(1, "unsupported" as *u8, f[EVP_F_UNGROUND]); wc(1, 44)
1602 wq(1); w(1, "gates" as *u8); wq(1); wc(1, 58); wc(1, 123)
1603 kv_n(1, "green" as *u8, f[EVP_F_GREEN]); wc(1, 44)
1604 kv_n(1, "ran" as *u8, f[EVP_F_RAN]); wc(1, 44)
1605 kv_n(1, "declared" as *u8, f[EVP_F_DECLARED]); wc(1, 44)
1606 kv_n(1, "skipped" as *u8, f[EVP_F_SKIPPED]); wc(1, 44)
1607 kv_n(1, "hashed" as *u8, f[EVP_F_HASHED]); wc(1, 44)
1608 kv_n(1, "redseen" as *u8, f[EVP_F_REDSEEN]); wc(1, 44)
1609 kv_n(1, "vacuous" as *u8, f[EVP_F_VACUOUS])
1610 wc(1, 125); wc(1, 44)
1611 wq(1); w(1, "gaps" as *u8); wq(1); wc(1, 58); wc(1, 123)
1612 kv_n(1, "open" as *u8, f[EVP_F_ABSENT]); wc(1, 44)
1613 kv_n(1, "named" as *u8, f[EVP_F_ABSNAMED]); wc(1, 44)
1614 kv_n(1, "unnamed" as *u8, f[EVP_F_ABSBARE])
1615 wc(1, 125); wc(1, 44)
1616 kv_n(1, "flips_ready" as *u8, f[EVP_F_LANDED]); wc(1, 44)
1617 // A PARTITION IS A CLAIM: PUBLISH THE PARTS AND THE SUM SO A LEAK CANNOT HIDE BEHIND A TOTAL.
1618 // reconciles is THREE-STATE on purpose -- 1 sums, 0 LEAKS, -1 not measurable from this stamp --
1619 // because a partition we could not check and one that failed are different facts.
1620 wq(1); w(1, "partition" as *u8); wq(1); wc(1, 58); wc(1, 123)
1621 kv_n(1, "grounded_plus_unsupported" as *u8, f[EVP_F_GROUNDED] + f[EVP_F_UNGROUND]); wc(1, 44)
1622 kv_n(1, "present_axes" as *u8, f[EVP_F_PRESENT]); wc(1, 44)
1623 kv_n(1, "named_plus_unnamed" as *u8, f[EVP_F_ABSNAMED] + f[EVP_F_ABSBARE]); wc(1, 44)
1624 kv_n(1, "open" as *u8, f[EVP_F_ABSENT]); wc(1, 44)
1625 kv_n(1, "reconciles" as *u8, evp_reconciles(f))
1626 wc(1, 125); wc(1, 44)
1627 // THE FAILING CONJUNCT, NAMED. A bare verdict is a disjunction and the reader always guesses the
1628 // alarming third; GPqN and gPQN are the same word and opposite work. evp_conj_char is the WRITER's
1629 // own function, so these letters cannot drift from the letters the referee stamped.
1630 wq(1); w(1, "conj" as *u8); wq(1); wc(1, 58); wq(1)
1631 wc(1, evp_conj_char(f[EVP_F_CJ_G], 71, 103))
1632 wc(1, evp_conj_char(f[EVP_F_CJ_P], 80, 112))
1633 wc(1, evp_conj_char(f[EVP_F_CJ_Q], 81, 113))
1634 wc(1, evp_conj_char(f[EVP_F_CJ_N], 78, 110))
1635 wq(1); wc(1, 44)
1636 kv_s(1, "first_failing_conjunct" as *u8, evp_conj_name(evp_conj_fail(f))); wc(1, 44)
1637 // WHICH DOCUMENT WAS GRADED. There are two knowledge trees and their copies of a matrix differ, so a
1638 // verdict that cannot name its subject document is not a verdict about the published board.
1639 wq(1); w(1, "graded_document" as *u8); wq(1); wc(1, 58); wc(1, 123)
1640 kv_s(1, "tree" as *u8, evp_tree_name(f[EVP_F_MROOT])); wc(1, 44)
1641 kv_n(1, "bytes" as *u8, f[EVP_F_MBYTES]); wc(1, 44)
1642 kv_n(1, "read_capped" as *u8, f[EVP_F_MCAPPED])
1643 wc(1, 125); wc(1, 44)
1644 kv_s(1, "gates_map_tree" as *u8, evp_tree_name(f[EVP_F_GATESROOT])); wc(1, 44)
1645 // THE GAP CLASSES THAT FIRE -- the machine half of the worklist. SEPARATE, NEVER MERGED: CLAIM-ONLY
1646 // needs a gate WRITTEN and GATE-FAILING needs one FIXED, and a single blended number sends a seat at
1647 // the wrong work. The remedy prose lives on the board page and is deliberately NOT copied here: two
1648 // copies of one sentence is a duplicate ruler that drifts on the first edit.
1649 wq(1); w(1, "classes" as *u8); wq(1); wc(1, 58); wc(1, 91)
1650 let cn: *i64 = sys_mmap(16) as *i64
1651 cn[0] = 0
1652 evj_class(evp_claim_only(f), "CLAIM-ONLY" as *u8, cn)
1653 evj_class(evp_gate_failing(f), "GATE-FAILING" as *u8, cn)
1654 evj_class(evp_fabricated(f), "UNSUPPORTED-CLAIM" as *u8, cn)
1655 evj_class(evp_flip_ready(f), "FLIP-READY" as *u8, cn)
1656 evj_class(evp_unnamed_gap(f), "UNNAMED-GAP" as *u8, cn)
1657 evj_class(evp_vacuous_gate(f), "VACUOUS-GATE" as *u8, cn)
1658 evj_class(stale, "STALE" as *u8, cn)
1659 wc(1, 93); wc(1, 44)
1660 kv_n(1, "classes_fired" as *u8, cn[0])
1661 wc(1, 125)
1662 return cn[0]
1663}
1664
1665// ---- MEASURED HEAD-TO-HEAD RECEIPTS (2026-09-01, lang leg) ---------------------------------------------
1666// OPERATOR: "meet and exceed gcc and rust and all the other languages independently verified with evidence
1667// documented and our /compare properly storing and making the evidence reproducible and visible and have that
1668// be an ecosystem wide capability". A performance number typed into a note is a CLAIM; this section renders a
1669// RECEIPT. knowledge/compare/<dom>.bench is written by a measuring organ (nx_lang_h2h for lang) and carries
1670// the host, every toolchain version, every source and binary sha256, min and median microseconds per arm, the
1671// checksum every arm had to agree on, and the exact command that regenerates it. ONE reader
1672// (nx_bench_receipt_lib) is shared by the writer, this renderer and the gate, and the verdict on the page is
1673// RE-DERIVED from the rows here, never copied from the file's own @verdict line -- the two are printed side by
1674// side and an agreement flag says whether the writer and the reader concur.
1675// ONE renderer in the base, BOTH generators call it (the refs_pass / plan_pass / watch_pass precedent), so a
1676// matrix board and a sota board publish the same bench dialect. A domain with no .bench emits NOTHING in both
1677// modes: every board without a receipt is byte-identical by construction.
1678const BD_SECS_PER_DAY: i64 = 86400
1679const BD_DAYS_TO_CIVIL_SHIFT: i64 = 719468 // days from 0000-03-01 to 1970-01-01 (Hinnant, civil_from_days)
1680const BD_DAYS_PER_ERA: i64 = 146097
1681const BD_DAYS_PER_4Y: i64 = 1460
1682const BD_DAYS_PER_100Y: i64 = 36524
1683const BD_DAYS_PER_ERA_LESS1: i64 = 146096
1684const BD_DAYS_PER_YEAR: i64 = 365
1685const BD_YEARS_PER_ERA: i64 = 400
1686const BD_MONTH_NUM: i64 = 153
1687const BD_MONTH_SHIFT: i64 = 2
1688const BD_MONTH_SCALE: i64 = 5
1689const BD_MARCH: i64 = 3
1690const BD_JAN_FROM_MP: i64 = 9
1691const BD_MP_WRAP: i64 = 10
1692const BD_FEB: i64 = 2
1693const BD_TEN: i64 = 10
1694const BD_SHA_SHOWN: i64 = 12
1695// YYYY-MM-DD from unix seconds (proleptic Gregorian, UTC); a non-positive epoch prints a dash
1696func bd_ymd(epoch: i64, dst: *u8, off: i64) -> i64 {
1697 if epoch <= 0 { return br_cat(dst, off, "-" as *u8) }
1698 let z: i64 = epoch / BD_SECS_PER_DAY + BD_DAYS_TO_CIVIL_SHIFT
1699 let era: i64 = z / BD_DAYS_PER_ERA
1700 let doe: i64 = z - era * BD_DAYS_PER_ERA
1701 let yoe: i64 = (doe - doe / BD_DAYS_PER_4Y + doe / BD_DAYS_PER_100Y - doe / BD_DAYS_PER_ERA_LESS1) / BD_DAYS_PER_YEAR
1702 let doy: i64 = doe - (BD_DAYS_PER_YEAR * yoe + yoe / 4 - yoe / 100)
1703 let mp: i64 = (BD_MONTH_SCALE * doy + BD_MONTH_SHIFT) / BD_MONTH_NUM
1704 let d: i64 = doy - (BD_MONTH_NUM * mp + BD_MONTH_SHIFT) / BD_MONTH_SCALE + 1
1705 var m: i64 = mp + BD_MARCH
1706 if mp >= BD_MP_WRAP { m = mp - BD_JAN_FROM_MP }
1707 var y: i64 = yoe + era * BD_YEARS_PER_ERA
1708 if m <= BD_FEB { y = y + 1 }
1709 var o: i64 = br_catn(dst, off, y)
1710 o = br_put(dst, o, 45)
1711 if m < BD_TEN { o = br_put(dst, o, 48) }
1712 o = br_catn(dst, o, m)
1713 o = br_put(dst, o, 45)
1714 if d < BD_TEN { o = br_put(dst, o, 48) }
1715 o = br_catn(dst, o, d)
1716 return o
1717}
1718// the first BD_SHA_SHOWN hex digits of a digest, or the whole thing when shorter
1719func bd_sha_short(fd: i64, s: *u8) -> i64 {
1720 var i: i64 = 0
1721 while s[i] != (0 as u8) { if i < BD_SHA_SHOWN { wc(fd, s[i] as i64) } i = i + 1 }
1722 return 0
1723}
1724func bd_status_class(st: i64) -> *u8 {
1725 if st == BR_ST_VALID { return "ok" as *u8 }
1726 if st == BR_ST_VOID { return "void" as *u8 }
1727 if st == BR_ST_UNMEASURABLE { return "unm" as *u8 }
1728 return "fail" as *u8
1729}
1730// ---- IM3 (intelmine, 2026-09-05): MINED INTELLIGENCE ON THE BOARD -- knowledge/compare/<dom>.proposed, rendered by the base for both generators ----
1731// nx_intelmine_propose routes review and competitive signals (nx_reviewmine_lib over Steam reviews under the
1732// exceeds / meets / mixed / does-not-meet rubric, the installed-title census) through capability_map.conf and APPENDS
1733// prop|epoch|appid|name|signal|kind|term|domain|rung-title|evidence (PR_NF fields; the writer dedupes on appid+kind+term)
1734// The proposer writes DATA and never a page. This is the ONE renderer, so every domain inherits the band on its next
1735// beat and a one-off report can never be built beside it (the grow-the-emitter law). An ABSENT file emits NOTHING --
1736// no section, no JSON key: an empty band would read as "the field has nothing to say", the one wrong answer nobody
1737// questions. A malformed row is COUNTED beside the rendered ones, never dropped in silence. A proposal is a LEAD, never
1738// a rung: it closes only when a rung with a gate lands, and the page says so in its own words.
1739const PR_READ_CAP: i64 = 65536 // announces when it binds; a .proposed file is rows, not a corpus
1740const PR_PATH_CAP: i64 = 600 // knowledge/compare/<dom>.proposed -- the reserve its sibling passes use
1741const PR_I64_BYTES: i64 = 8
1742const PR_NF: i64 = 10 // fields per prop| row, from the writer's own emit order (ip_emit)
1743const PR_SPLIT: i64 = 16 // field table: PR_NF plus room, so an over-long row is read whole rather than clipped to fit
1744const PR_F_TAG: i64 = 0
1745const PR_F_EPOCH: i64 = 1
1746const PR_F_APPID: i64 = 2
1747const PR_F_NAME: i64 = 3
1748const PR_F_SIGNAL: i64 = 4
1749const PR_F_KIND: i64 = 5
1750const PR_F_TERM: i64 = 6
1751const PR_F_DOMAIN: i64 = 7
1752const PR_F_TITLE: i64 = 8
1753const PR_F_EVIDENCE: i64 = 9
1754const PR_CH_COMMENT: i64 = 35
1755const PR_CH_LF: i64 = 10
1756const PR_CH_COMMA: i64 = 44
1757const PR_CH_COLON: i64 = 58
1758const PR_CH_LBRACE: i64 = 123
1759const PR_CH_RBRACE: i64 = 125
1760const PR_CH_LBRACKET: i64 = 91
1761const PR_CH_RBRACKET: i64 = 93
1762// RENDER-TIME TITLE (intelmine IM23/IM27, 2026-09-05): a row whose name column is its appid was written before any
1763// census or platform-api name existed, and the writer dedupes rows so it never rewrites them. The banked name
1764// (nx_steam_reviews name <appid> -> <appid>.name, one line) is read HERE instead, from the estate root as the mgmt
1765// daemon sees it AND from one directory up as the regen sees it (CWD = buildroot) -- the two-root read, announced
1766// per row as name_src=banked, never a silent guess. Absent in both: the row prints its appid and says so.
1767const PR_NAME_CAP: i64 = 256
1768const PR_NAME_DIR: *u8 = "knowledge/reviews/steam/"
1769const PR_NAME_DIR_UP: *u8 = "../knowledge/reviews/steam/"
1770const PR_NAME_SUFFIX: *u8 = ".name"
1771func pr_name_read(dir: *u8, appid: *u8, out: *u8, cap: i64) -> i64 {
1772 let path: *u8 = sys_mmap(PR_PATH_CAP)
1773 var o: i64 = scopy(path, 0, dir)
1774 o = scopy(path, o, appid); o = scopy(path, o, PR_NAME_SUFFIX); path[o] = 0 as u8
1775 let n: i64 = c_read(path, out, cap - 1)
1776 if n <= 0 { return 0 - 1 }
1777 var e: i64 = 0
1778 while e < n { if out[e] == (PR_CH_LF as u8) { break } e = e + 1 }
1779 out[e] = 0 as u8
1780 if e <= 0 { return 0 - 1 }
1781 return e
1782}
1783func pr_name_lookup(appid: *u8, out: *u8, cap: i64) -> i64 {
1784 let n: i64 = pr_name_read(PR_NAME_DIR, appid, out, cap)
1785 if n > 0 { return n }
1786 return pr_name_read(PR_NAME_DIR_UP, appid, out, cap)
1787}
1788func prop_pass(dom: *u8, fd: i64, mode: i64) -> i64 { return prop_pass_heading(dom, fd, mode, 2) }
1789func prop_pass_heading(dom: *u8, fd: i64, mode: i64, heading_level: i64) -> i64 {
1790 let path: *u8 = sys_mmap(PR_PATH_CAP)
1791 var o: i64 = scopy(path, 0, "knowledge/compare/" as *u8)
1792 o = scopy(path, o, dom); o = scopy(path, o, ".proposed" as *u8); path[o] = 0 as u8
1793 let buf: *u8 = sys_mmap(PR_READ_CAP)
1794 let n: i64 = c_read(path, buf, PR_READ_CAP - 1)
1795 if n <= 0 { return 0 }
1796 var capped: i64 = 0
1797 if n >= PR_READ_CAP - 1 { capped = 1 }
1798 buf[n] = 0 as u8
1799 let fld: *i64 = sys_mmap(PR_SPLIT * PR_I64_BYTES) as *i64
1800 if mode == 2 {
1801 wc(fd, PR_CH_COMMA); wq(fd); w(fd, "proposed" as *u8); wq(fd); wc(fd, PR_CH_COLON); wc(fd, PR_CH_LBRACE)
1802 kv_s(fd, "file" as *u8, path); wc(fd, PR_CH_COMMA)
1803 kv_s(fd, "writer" as *u8, "nx_intelmine_propose" as *u8); wc(fd, PR_CH_COMMA)
1804 wq(fd); w(fd, "rows" as *u8); wq(fd); wc(fd, PR_CH_COLON); wc(fd, PR_CH_LBRACKET)
1805 }
1806 if mode == 1 {
1807 sc_heading_open(fd, heading_level, "" as *u8); w(fd, "Mined from the field — review and competitive intelligence proposed to this board" as *u8); sc_heading_close(fd, heading_level); w(fd, "\n" as *u8)
1808 if capped == 1 { w(fd, "<div class='meth'>proposed artefact READ-CAPPED at " as *u8); wn(fd, PR_READ_CAP); w(fd, " bytes — the rows below are a PREFIX of the file</div>\n" as *u8) }
1809 w(fd, "<p class='lead'>Rows written by <code>nx_intelmine_propose</code> from <code>nx_reviewmine_lib</code> signals (Steam reviews under the exceeds / meets / mixed / does-not-meet rubric, the installed-title census) and routed here by <code>capability_map.conf</code>. <b>DEFECT</b> names a rival failing that a rung here answers; <b>DEMANDED</b> a capability buyers ask for and do not get; <b>WE-DO-BETTER</b> an exceed the reviews corroborate; <b>THEY-DO-WELL</b> a bar this board must meet; <b>SHIPS</b> a rival capability to match. <b>A proposal is a lead, never a rung</b> — it closes only when a rung with a gate lands, and nothing in this band changes a measured cell.</p>\n" as *u8)
1810 sc_plan_table_open(fd, "Capability proposals" as *u8); w(fd, "<thead><tr><th>Signal</th><th>Kind</th><th>Term</th><th>Title</th><th>Proposed rung</th><th>Evidence</th></tr></thead><tbody>\n" as *u8)
1811 }
1812 var rows: i64 = 0
1813 var malformed: i64 = 0
1814 let nbuf: *u8 = sys_mmap(PR_NAME_CAP)
1815 var p: i64 = 0
1816 while p < n {
1817 var e: i64 = p
1818 while e < n { if buf[e] == (PR_CH_LF as u8) { break } e = e + 1 }
1819 buf[e] = 0 as u8
1820 let line: *u8 = (buf as i64 + p) as *u8
1821 p = e + 1
1822 if line[0] != (PR_CH_COMMENT as u8) { if line[0] != (0 as u8) {
1823 let nf: i64 = splitpipe(line, fld, PR_SPLIT)
1824 var ok: i64 = 0
1825 if nf >= PR_NF { if streq(fld[PR_F_TAG] as *u8, "prop" as *u8) == 1 { ok = 1 } }
1826 if ok == 0 { malformed = malformed + 1 } else {
1827 rows = rows + 1
1828 let name: *u8 = fld[PR_F_NAME] as *u8
1829 let appid: *u8 = fld[PR_F_APPID] as *u8
1830 // the proposer wrote the appid as the name when nothing named the title: try the banked name at render
1831 // time (name_src=banked), and only when that is absent too print the number AND say so (name_src=appid)
1832 var shown: *u8 = name
1833 var nsrc: *u8 = "row" as *u8
1834 if streq(name, appid) == 1 {
1835 nsrc = "appid" as *u8
1836 if pr_name_lookup(appid, nbuf, PR_NAME_CAP) > 0 { shown = nbuf; nsrc = "banked" as *u8 }
1837 }
1838 if mode == 1 {
1839 w(fd, "<tr><td><span class='ex'>" as *u8); wnote(fd, fld[PR_F_SIGNAL] as *u8); w(fd, "</span></td><td class='ct'>" as *u8); wnote(fd, fld[PR_F_KIND] as *u8)
1840 w(fd, "</td><td class='ct'>" as *u8); wnote(fd, fld[PR_F_TERM] as *u8); w(fd, "</td><td>" as *u8)
1841 if streq(nsrc, "appid" as *u8) == 1 { w(fd, "appid <span class='ct'>" as *u8); wnote(fd, appid); w(fd, "</span> (title unresolved: no census row and no banked name)" as *u8) } else { wnote(fd, shown); w(fd, " <span class='ct'>" as *u8); wnote(fd, appid); w(fd, "</span>" as *u8) }
1842 w(fd, "</td><td><b>" as *u8); wnote(fd, fld[PR_F_TITLE] as *u8); w(fd, "</b></td><td class='ct'>" as *u8); wnote(fd, fld[PR_F_EVIDENCE] as *u8); w(fd, "</td></tr>\n" as *u8)
1843 }
1844 if mode == 2 {
1845 if rows > 1 { wc(fd, PR_CH_COMMA) }
1846 wc(fd, PR_CH_LBRACE)
1847 kv_s(fd, "epoch" as *u8, fld[PR_F_EPOCH] as *u8); wc(fd, PR_CH_COMMA)
1848 kv_s(fd, "appid" as *u8, appid); wc(fd, PR_CH_COMMA)
1849 kv_s(fd, "name" as *u8, shown); wc(fd, PR_CH_COMMA)
1850 kv_s(fd, "name_src" as *u8, nsrc); wc(fd, PR_CH_COMMA)
1851 kv_s(fd, "signal" as *u8, fld[PR_F_SIGNAL] as *u8); wc(fd, PR_CH_COMMA)
1852 kv_s(fd, "kind" as *u8, fld[PR_F_KIND] as *u8); wc(fd, PR_CH_COMMA)
1853 kv_s(fd, "term" as *u8, fld[PR_F_TERM] as *u8); wc(fd, PR_CH_COMMA)
1854 kv_s(fd, "domain" as *u8, fld[PR_F_DOMAIN] as *u8); wc(fd, PR_CH_COMMA)
1855 kv_s(fd, "title" as *u8, fld[PR_F_TITLE] as *u8); wc(fd, PR_CH_COMMA)
1856 kv_s(fd, "evidence" as *u8, fld[PR_F_EVIDENCE] as *u8)
1857 wc(fd, PR_CH_RBRACE)
1858 }
1859 }
1860 } }
1861 }
1862 if mode == 1 {
1863 sc_plan_table_close(fd); w(fd, "\n<p class='stats'>proposals <b>" as *u8); wn(fd, rows); w(fd, "</b><span class='sep'>|</span>malformed rows <b>" as *u8); wn(fd, malformed)
1864 w(fd, "</b> (counted, never rendered: a row that is not <code>prop|</code> with " as *u8); wn(fd, PR_NF); w(fd, " fields)<span class='sep'>|</span>read-capped <b>" as *u8); wn(fd, capped); w(fd, "</b></p>\n" as *u8)
1865 }
1866 if mode == 2 {
1867 wc(fd, PR_CH_RBRACKET); wc(fd, PR_CH_COMMA)
1868 kv_n(fd, "count" as *u8, rows); wc(fd, PR_CH_COMMA)
1869 kv_n(fd, "malformed" as *u8, malformed); wc(fd, PR_CH_COMMA)
1870 kv_n(fd, "read_capped" as *u8, capped)
1871 wc(fd, PR_CH_RBRACE)
1872 }
1873 return rows
1874}
1875// THE DISCOVERED FIELD (fieldwatch FW1, 2026-09-05; operator: the six columns "arent a good sample of the industry").
1876// knowledge/compare/<dom>.field is WRITTEN by nx_field_discover from <dom>.seeds -- public lists (Wikipedia wikitext,
1877// GitHub topics, awesome lists) read mechanically -- and rendered here by the ONE reader for both generators. The page
1878// shows the field, then measures the matrix's own @cols as a SUBSET of it: columns_in_field of columns, and how many
1879// discovered rivals have no column at all. A seat's pick is thereby shown for what it is. Absent file = no section.
1880const FI_READ_CAP: i64 = 262144 // announces when it binds: a .field is rows, not a corpus
1881const FI_PATH_CAP: i64 = 600
1882const FI_I64_BYTES: i64 = 8
1883const FI_NF: i64 = 7 // rival|name|seeds_hit|mentions|first_seed|link|kind (nx_field_lib fl_emit)
1884const FI_SPLIT: i64 = 12
1885const FI_F_TAG: i64 = 0
1886const FI_F_NAME: i64 = 1
1887const FI_F_SEEDS: i64 = 2
1888const FI_F_MENTIONS: i64 = 3
1889const FI_F_FIRST: i64 = 4
1890const FI_F_LINK: i64 = 5
1891const FI_F_KIND: i64 = 6
1892const FI_SHOW: i64 = 60 // rows rendered; the rest are COUNTED and the stats line says shown of count
1893const FI_COLS_MAX: i64 = 16
1894const FI_CH_COMMENT: i64 = 35
1895const FI_CH_LF: i64 = 10
1896const FI_CH_PIPE: i64 = 124
1897const FI_CH_COMMA: i64 = 44
1898const FI_CH_COLON: i64 = 58
1899const FI_CH_LBRACE: i64 = 123
1900const FI_CH_RBRACE: i64 = 125
1901const FI_CH_LBRACKET: i64 = 91
1902const FI_CH_RBRACKET: i64 = 93
1903const FI_UPPER_A: i64 = 65
1904const FI_UPPER_Z: i64 = 90
1905const FI_CASE_DELTA: i64 = 32
1906func fi_lc(c: i64) -> i64 { if c >= FI_UPPER_A { if c <= FI_UPPER_Z { return c + FI_CASE_DELTA } } return c }
1907// case-insensitive: does hay contain needle (needle non-empty)?
1908func fi_ci_contains(hay: *u8, needle: *u8) -> i64 {
1909 var nl: i64 = 0
1910 while needle[nl] != (0 as u8) { nl = nl + 1 }
1911 if nl < 1 { return 0 }
1912 var hl: i64 = 0
1913 while hay[hl] != (0 as u8) { hl = hl + 1 }
1914 var i: i64 = 0
1915 while i + nl <= hl {
1916 var m: i64 = 0
1917 var j: i64 = 0
1918 while j < nl { if fi_lc(hay[i + j] as i64) == fi_lc(needle[j] as i64) { m = m + 1 } j = j + 1 }
1919 if m == nl { return 1 }
1920 i = i + 1
1921 }
1922 return 0
1923}
1924// the leading words of a column label (up to the first space) -- "Blender 4.5 plus addons" matches a rival named Blender
1925func fi_head_word(col: *u8, out: *u8, cap: i64) -> i64 {
1926 var i: i64 = 0
1927 while col[i] != (0 as u8) { if col[i] == (32 as u8) { break } if i < cap - 1 { out[i] = col[i] } i = i + 1 }
1928 if i > cap - 1 { i = cap - 1 }
1929 out[i] = 0 as u8
1930 return i
1931}
1932// colv/ncols: the matrix generator's ALREADY-SPLIT @cols vector (one owner of the split); the sota generator passes 0/0.
1933func field_pass(dom: *u8, fd: i64, mode: i64, colv: *i64, ncols_in: i64) -> i64 { return field_pass_heading(dom, fd, mode, colv, ncols_in, 2) }
1934func field_pass_heading(dom: *u8, fd: i64, mode: i64, colv: *i64, ncols_in: i64, heading_level: i64) -> i64 {
1935 let path: *u8 = sys_mmap(FI_PATH_CAP)
1936 var o: i64 = scopy(path, 0, "knowledge/compare/" as *u8)
1937 o = scopy(path, o, dom); o = scopy(path, o, ".field" as *u8); path[o] = 0 as u8
1938 let buf: *u8 = sys_mmap(FI_READ_CAP)
1939 let n: i64 = c_read(path, buf, FI_READ_CAP - 1)
1940 if n <= 0 { return 0 }
1941 var capped: i64 = 0
1942 if n >= FI_READ_CAP - 1 { capped = 1 }
1943 buf[n] = 0 as u8
1944 var ncols: i64 = ncols_in
1945 if ncols > FI_COLS_MAX { ncols = FI_COLS_MAX }
1946 if ncols < 0 { ncols = 0 }
1947 let colhit: *i64 = sys_mmap(FI_COLS_MAX * FI_I64_BYTES) as *i64
1948 let head: *u8 = sys_mmap(FI_PATH_CAP)
1949 let fld: *i64 = sys_mmap(FI_SPLIT * FI_I64_BYTES) as *i64
1950 var summary: *u8 = "" as *u8
1951 var rows: i64 = 0
1952 var shown: i64 = 0
1953 var malformed: i64 = 0
1954 var p: i64 = 0
1955 // pass 1: the summary row and the column coverage (every row, never a prefix)
1956 while p < n {
1957 var e: i64 = p
1958 while e < n { if buf[e] == (FI_CH_LF as u8) { break } e = e + 1 }
1959 buf[e] = 0 as u8
1960 let line: *u8 = (buf as i64 + p) as *u8
1961 p = e + 1
1962 if line[0] != (FI_CH_COMMENT as u8) { if line[0] != (0 as u8) {
1963 if starts(line, "field|" as *u8) == 1 { summary = line } else {
1964 let nf: i64 = splitpipe(line, fld, FI_SPLIT)
1965 var ok: i64 = 0
1966 if nf >= FI_NF { if streq(fld[FI_F_TAG] as *u8, "rival" as *u8) == 1 { ok = 1 } }
1967 if ok == 0 { malformed = malformed + 1 } else {
1968 rows = rows + 1
1969 var c: i64 = 0
1970 while c < ncols {
1971 if colhit[c] == 0 {
1972 fi_head_word(colv[c] as *u8, head, FI_PATH_CAP)
1973 if fi_ci_contains(fld[FI_F_NAME] as *u8, head) == 1 { colhit[c] = 1 }
1974 }
1975 c = c + 1
1976 }
1977 }
1978 }
1979 } }
1980 }
1981 var cols_in: i64 = 0
1982 var c2: i64 = 0
1983 while c2 < ncols { if colhit[c2] == 1 { cols_in = cols_in + 1 } c2 = c2 + 1 }
1984 // pass 2: render (re-read, because splitpipe NUL-terminates in place)
1985 let n2: i64 = c_read(path, buf, FI_READ_CAP - 1)
1986 buf[n2] = 0 as u8
1987 if mode == 2 {
1988 wc(fd, FI_CH_COMMA); wq(fd); w(fd, "field" as *u8); wq(fd); wc(fd, FI_CH_COLON); wc(fd, FI_CH_LBRACE)
1989 kv_s(fd, "file" as *u8, path); wc(fd, FI_CH_COMMA)
1990 kv_s(fd, "writer" as *u8, "nx_field_discover" as *u8); wc(fd, FI_CH_COMMA)
1991 kv_s(fd, "summary" as *u8, summary); wc(fd, FI_CH_COMMA)
1992 kv_n(fd, "columns" as *u8, ncols); wc(fd, FI_CH_COMMA)
1993 kv_n(fd, "columns_in_field" as *u8, cols_in); wc(fd, FI_CH_COMMA)
1994 wq(fd); w(fd, "rows" as *u8); wq(fd); wc(fd, FI_CH_COLON); wc(fd, FI_CH_LBRACKET)
1995 }
1996 if mode == 1 {
1997 sc_heading_open(fd, heading_level, " id='field'" as *u8); w(fd, "The field — discovered, not chosen" as *u8); sc_heading_close(fd, heading_level); w(fd, "\n" as *u8)
1998 if capped == 1 { w(fd, "<div class='meth'>field artefact READ-CAPPED at " as *u8); wn(fd, FI_READ_CAP); w(fd, " bytes — the rows below are a PREFIX of the file</div>\n" as *u8) }
1999 w(fd, "<p class='lead'>Rows written by <code>nx_field_discover</code> from <code>" as *u8); wnote(fd, dom); w(fd, ".seeds</code>: the industry's own lists (Wikipedia wikitext, GitHub topics, awesome lists) read mechanically, every candidate counted across seeds. The matrix columns above are a SEAT'S pick; this band is the population they were picked from, and the stats line measures one against the other. A rival here is a lead, never a verdict — it earns a column when its capabilities are read and pinned.</p>\n" as *u8)
2000 w(fd, "<div class='meth'><code>" as *u8); wnote(fd, summary); w(fd, "</code></div>\n" as *u8)
2001 sc_plan_table_open(fd, "Competitor field" as *u8); w(fd, "<thead><tr><th>Rank</th><th>Rival</th><th>Seeds</th><th>Mentions</th><th>First seed</th><th>Kind</th><th>Link</th></tr></thead><tbody>\n" as *u8)
2002 }
2003 var p2: i64 = 0
2004 var rank: i64 = 0
2005 while p2 < n2 {
2006 var e: i64 = p2
2007 while e < n2 { if buf[e] == (FI_CH_LF as u8) { break } e = e + 1 }
2008 buf[e] = 0 as u8
2009 let line: *u8 = (buf as i64 + p2) as *u8
2010 p2 = e + 1
2011 if line[0] != (FI_CH_COMMENT as u8) { if line[0] != (0 as u8) { if starts(line, "rival|" as *u8) == 1 {
2012 let nf: i64 = splitpipe(line, fld, FI_SPLIT)
2013 if nf >= FI_NF { if shown < FI_SHOW {
2014 rank = rank + 1
2015 shown = shown + 1
2016 if mode == 1 {
2017 w(fd, "<tr><td class='ct'>" as *u8); wn(fd, rank); w(fd, "</td><td><b>" as *u8); wnote(fd, fld[FI_F_NAME] as *u8)
2018 w(fd, "</b></td><td class='ct'>" as *u8); wnote(fd, fld[FI_F_SEEDS] as *u8); w(fd, "</td><td class='ct'>" as *u8); wnote(fd, fld[FI_F_MENTIONS] as *u8)
2019 w(fd, "</td><td class='ct'>" as *u8); wnote(fd, fld[FI_F_FIRST] as *u8); w(fd, "</td><td class='ct'>" as *u8); wnote(fd, fld[FI_F_KIND] as *u8)
2020 w(fd, "</td><td class='ct'>" as *u8); wnote(fd, fld[FI_F_LINK] as *u8); w(fd, "</td></tr>\n" as *u8)
2021 }
2022 if mode == 2 {
2023 if shown > 1 { wc(fd, FI_CH_COMMA) }
2024 wc(fd, FI_CH_LBRACE)
2025 kv_s(fd, "name" as *u8, fld[FI_F_NAME] as *u8); wc(fd, FI_CH_COMMA)
2026 kv_s(fd, "seeds" as *u8, fld[FI_F_SEEDS] as *u8); wc(fd, FI_CH_COMMA)
2027 kv_s(fd, "mentions" as *u8, fld[FI_F_MENTIONS] as *u8); wc(fd, FI_CH_COMMA)
2028 kv_s(fd, "first_seed" as *u8, fld[FI_F_FIRST] as *u8); wc(fd, FI_CH_COMMA)
2029 kv_s(fd, "link" as *u8, fld[FI_F_LINK] as *u8); wc(fd, FI_CH_COMMA)
2030 kv_s(fd, "kind" as *u8, fld[FI_F_KIND] as *u8)
2031 wc(fd, FI_CH_RBRACE)
2032 }
2033 } }
2034 } } }
2035 }
2036 if mode == 1 {
2037 sc_plan_table_close(fd); w(fd, "\n<p class='stats'>field candidates <b>" as *u8); wn(fd, rows); w(fd, "</b><span class='sep'>|</span>shown <b>" as *u8); wn(fd, shown)
2038 w(fd, "</b> of " as *u8); wn(fd, rows); w(fd, "<span class='sep'>|</span>matrix columns in the field <b>" as *u8); wn(fd, cols_in); w(fd, "</b> of " as *u8); wn(fd, ncols)
2039 w(fd, "<span class='sep'>|</span>discovered rivals with no column <b>" as *u8); wn(fd, rows - cols_in); w(fd, "</b><span class='sep'>|</span>malformed rows <b>" as *u8); wn(fd, malformed)
2040 w(fd, "</b> (counted, never rendered)<span class='sep'>|</span>read-capped <b>" as *u8); wn(fd, capped); w(fd, "</b></p>\n" as *u8)
2041 }
2042 if mode == 2 {
2043 wc(fd, FI_CH_RBRACKET); wc(fd, FI_CH_COMMA)
2044 kv_n(fd, "count" as *u8, rows); wc(fd, FI_CH_COMMA)
2045 kv_n(fd, "shown" as *u8, shown); wc(fd, FI_CH_COMMA)
2046 kv_n(fd, "no_column" as *u8, rows - cols_in); wc(fd, FI_CH_COMMA)
2047 kv_n(fd, "malformed" as *u8, malformed); wc(fd, FI_CH_COMMA)
2048 kv_n(fd, "read_capped" as *u8, capped)
2049 wc(fd, FI_CH_RBRACE)
2050 }
2051 return rows
2052}
2053// ---- GAUGE HEARTBEATS (codeeffectiveness CE9, 2026-09-06): A GAUGE CELL THAT READS STALE, NEVER ZERO ----
2054// <dom>.gauge rows: gauge|<label>|<stamp-path>|<cadence_s>|<note> (cadence_s 0 = take it from the stamp)
2055// WHY THIS IS IN THE BASE. The estate paid once for its effectiveness gauge going dark for 28 days and reading as
2056// "no movement": a number with no heartbeat is a claim with an expiry date nobody recorded. Every gauge row here is
2057// re-judged on every publish by THE ONE ruler the writing beat also uses (nx_gauge_lib.ga_judge), so the page and the
2058// beat cannot disagree: FRESH shows the value, STALE withholds it (age beyond two beats), BLIND withholds it (an axis
2059// abstained), ABSENT means nothing has measured. In api.json the "gauge" value key exists ONLY on a FRESH row -- a
2060// consumer that reads a missing key as zero is the defect this pass exists to make impossible on the page.
2061const GP_PATH_CAP: i64 = 600
2062const GP_READ_CAP: i64 = 65536
2063const GP_SPLIT: i64 = 8
2064const GP_NF: i64 = 5
2065const GP_F_LABEL: i64 = 1
2066const GP_F_PATH: i64 = 2
2067const GP_F_CAD: i64 = 3
2068const GP_F_NOTE: i64 = 4
2069const GP_ROW_CAP: i64 = 1024
2070const GP_CH_NL: i64 = 10
2071const GP_CH_HASH: i64 = 35
2072const GP_CH_COMMA: i64 = 44
2073const GP_CH_COLON: i64 = 58
2074const GP_CH_LBRACKET: i64 = 91
2075const GP_CH_RBRACKET: i64 = 93
2076const GP_CH_LBRACE: i64 = 123
2077const GP_CH_RBRACE: i64 = 125
2078func gauge_pass(dom: *u8, fd: i64, mode: i64) -> i64 { return gauge_pass_heading(dom, fd, mode, 2) }
2079func gauge_pass_heading(dom: *u8, fd: i64, mode: i64, heading_level: i64) -> i64 {
2080 let path: *u8 = sys_mmap(GP_PATH_CAP)
2081 var o: i64 = scopy(path, 0, "knowledge/compare/" as *u8)
2082 o = scopy(path, o, dom); o = scopy(path, o, ".gauge" as *u8); path[o] = 0 as u8
2083 let buf: *u8 = sys_mmap(GP_READ_CAP)
2084 let n: i64 = c_read(path, buf, GP_READ_CAP - 1)
2085 if n <= 0 { return 0 }
2086 var capped: i64 = 0
2087 if n >= GP_READ_CAP - 1 { capped = 1 }
2088 let now: i64 = sys_now_realtime_sec()
2089 let fld: *i64 = sys_mmap(GP_SPLIT * GA_WORD) as *i64
2090 let f: *i64 = sys_mmap(GA_F_SLOTS * GA_WORD) as *i64
2091 let rb: *u8 = sys_mmap(GP_ROW_CAP)
2092 var rows: i64 = 0
2093 var malformed: i64 = 0
2094 var c_fresh: i64 = 0
2095 var c_stale: i64 = 0
2096 var c_blind: i64 = 0
2097 var c_absent: i64 = 0
2098 if mode == 2 {
2099 wc(fd, GP_CH_COMMA); wq(fd); w(fd, "gauge" as *u8); wq(fd); wc(fd, GP_CH_COLON); wc(fd, GP_CH_LBRACE)
2100 kv_s(fd, "file" as *u8, path); wc(fd, GP_CH_COMMA)
2101 kv_s(fd, "reader" as *u8, "nx_gauge_lib" as *u8); wc(fd, GP_CH_COMMA)
2102 kv_n(fd, "now" as *u8, now); wc(fd, GP_CH_COMMA)
2103 wq(fd); w(fd, "rows" as *u8); wq(fd); wc(fd, GP_CH_COLON); wc(fd, GP_CH_LBRACKET)
2104 }
2105 if mode == 1 {
2106 sc_heading_open(fd, heading_level, " id='gauge'" as *u8); w(fd, "Gauges — a heartbeat, never a bare number" as *u8); sc_heading_close(fd, heading_level); w(fd, "\n" as *u8)
2107 if capped == 1 { w(fd, "<div class='meth'>gauge artefact READ-CAPPED at " as *u8); wn(fd, GP_READ_CAP); w(fd, " bytes — the rows below are a PREFIX of the file</div>\n" as *u8) }
2108 w(fd, "<p class='lead'>Each row names a gauge stamp written by its measuring beat. This page re-judges the stamp on every publish with the same ruler the beat uses (<code>nx_gauge_lib</code>): <b>FRESH</b> shows the value; <b>STALE</b> withholds it (older than two beats); <b>BLIND</b> withholds it (an axis abstained); <b>ABSENT</b> means nothing has measured. A stale gauge never reads as zero.</p>\n" as *u8)
2109 w(fd, "<table class='gauge-tab'><thead><tr><th>gauge</th><th>state</th><th>reading</th><th>note</th></tr></thead><tbody>\n" as *u8)
2110 }
2111 var p: i64 = 0
2112 while p < n {
2113 var e: i64 = p
2114 while e < n { if buf[e] == (GP_CH_NL as u8) { break } e = e + 1 }
2115 buf[e] = 0 as u8
2116 let line: *u8 = (buf as i64 + p) as *u8
2117 p = e + 1
2118 if line[0] != (GP_CH_HASH as u8) { if line[0] != (0 as u8) { if starts(line, "gauge|" as *u8) == 1 {
2119 let nf: i64 = splitpipe(line, fld, GP_SPLIT)
2120 if nf < GP_NF { malformed = malformed + 1 } else {
2121 let cs: *u8 = fld[GP_F_CAD] as *u8
2122 let cad: i64 = sj_atoi_span(cs, 0, sj_vlen(cs))
2123 // RESOLVE BEFORE JUDGING (2026-09-06): the regen runs with CWD=buildroot while every beat stamps from the serving root, so a
2124 // bare stamp path read ABSENT on the page for a stamp FRESH on disk (measured: knowledge/status/stepsolve.stamp 66 B at the
2125 // root, absent under buildroot). ep_artifact_path is the ONE probe order; an absent stamp still judges ABSENT through the same ruler.
2126 let gpath: *u8 = sys_mmap(GP_PATH_CAP)
2127 if ep_artifact_path(gpath, fld[GP_F_PATH] as *u8) == 0 { let go: i64 = scopy(gpath, 0, fld[GP_F_PATH] as *u8); gpath[go] = 0 as u8 }
2128 let st: i64 = ga_judge(gpath, now, cad, f)
2129 var age: i64 = 0 - 1
2130 if f[GA_F_TS] > 0 { age = now - f[GA_F_TS] }
2131 var mcad: i64 = cad
2132 if mcad <= 0 { mcad = f[GA_F_CADENCE] }
2133 let rl: i64 = ga_render(rb, 0, st, age, ga_max_age(mcad), f[GA_F_GAUGE], f[GA_F_KNOWN], f[GA_F_TOTAL])
2134 rb[rl] = 0 as u8
2135 if st == GA_FRESH { c_fresh = c_fresh + 1 }
2136 if st == GA_STALE { c_stale = c_stale + 1 }
2137 if st == GA_BLIND { c_blind = c_blind + 1 }
2138 if st == GA_ABSENT { c_absent = c_absent + 1 }
2139 if mode == 1 {
2140 w(fd, "<tr><td><b>" as *u8); wnote(fd, fld[GP_F_LABEL] as *u8); w(fd, "</b></td><td class='ct'>" as *u8); w(fd, ga_state_name(st))
2141 w(fd, "</td><td class='ct'>" as *u8); wnote(fd, rb); w(fd, "</td><td>" as *u8); wnote(fd, fld[GP_F_NOTE] as *u8); w(fd, "</td></tr>\n" as *u8)
2142 }
2143 if mode == 2 {
2144 if rows > 0 { wc(fd, GP_CH_COMMA) }
2145 wc(fd, GP_CH_LBRACE)
2146 kv_s(fd, "label" as *u8, fld[GP_F_LABEL] as *u8); wc(fd, GP_CH_COMMA)
2147 kv_s(fd, "stamp" as *u8, fld[GP_F_PATH] as *u8); wc(fd, GP_CH_COMMA)
2148 kv_s(fd, "state" as *u8, ga_state_name(st)); wc(fd, GP_CH_COMMA)
2149 kv_n(fd, "age_s" as *u8, age); wc(fd, GP_CH_COMMA)
2150 kv_n(fd, "max_age_s" as *u8, ga_max_age(mcad)); wc(fd, GP_CH_COMMA)
2151 kv_n(fd, "axes_known" as *u8, f[GA_F_KNOWN]); wc(fd, GP_CH_COMMA)
2152 kv_n(fd, "axes_total" as *u8, f[GA_F_TOTAL]); wc(fd, GP_CH_COMMA)
2153 if st == GA_FRESH { kv_n(fd, "gauge" as *u8, f[GA_F_GAUGE]); wc(fd, GP_CH_COMMA) }
2154 kv_s(fd, "reading" as *u8, rb); wc(fd, GP_CH_COMMA)
2155 kv_s(fd, "note" as *u8, fld[GP_F_NOTE] as *u8)
2156 wc(fd, GP_CH_RBRACE)
2157 }
2158 rows = rows + 1
2159 }
2160 } } }
2161 }
2162 if mode == 2 {
2163 wc(fd, GP_CH_RBRACKET); wc(fd, GP_CH_COMMA)
2164 kv_n(fd, "count" as *u8, rows); wc(fd, GP_CH_COMMA)
2165 kv_n(fd, "fresh" as *u8, c_fresh); wc(fd, GP_CH_COMMA)
2166 kv_n(fd, "stale" as *u8, c_stale); wc(fd, GP_CH_COMMA)
2167 kv_n(fd, "blind" as *u8, c_blind); wc(fd, GP_CH_COMMA)
2168 kv_n(fd, "absent" as *u8, c_absent); wc(fd, GP_CH_COMMA)
2169 kv_n(fd, "malformed" as *u8, malformed); wc(fd, GP_CH_COMMA)
2170 kv_n(fd, "read_capped" as *u8, capped)
2171 wc(fd, GP_CH_RBRACE)
2172 }
2173 if mode == 1 {
2174 w(fd, "</tbody></table>\n<p class='stats'>gauges <b>" as *u8); wn(fd, rows)
2175 w(fd, "</b><span class='sep'>|</span>fresh <b>" as *u8); wn(fd, c_fresh); w(fd, "</b><span class='sep'>|</span>stale <b>" as *u8); wn(fd, c_stale)
2176 w(fd, "</b><span class='sep'>|</span>blind <b>" as *u8); wn(fd, c_blind); w(fd, "</b><span class='sep'>|</span>absent <b>" as *u8); wn(fd, c_absent)
2177 w(fd, "</b> (partition sums)<span class='sep'>|</span>malformed rows <b>" as *u8); wn(fd, malformed); w(fd, "</b> (counted, never rendered)</p>\n" as *u8)
2178 }
2179 return rows
2180}
2181// ---- GAPS FROM THE RECORD (ecosystem EC38, 2026-09-06) ------------------------------------------------------
2182// Renders the record census (nx_goalmap record): organs the estate invokes and directives its own plan queue rows
2183// name that NO board row carries. The feed is the plane's own bytes written beside the conf by the same run
2184// (knowledge/recordgaps.conf.rows), resolved through ep_artifact_path like every status artifact, and its freshness
2185// is judged from the sibling stamp with the ONE gauge ruler: a stale census renders its rows under a STALE state
2186// and a BLIND one says how many declared sources are still unread; neither ever reads as "no gaps".
2187// Per board: this board's own directive rows (board == dom) always; the estate-wide UNASSIGNED organs in full on
2188// the ecosystem hub and as a COUNT everywhere else (hundreds of rows on every page would be the site saying one
2189// thing a hundred times). mode 1 = HTML section, mode 2 = api.json object. Absent feed = no section, returns 0.
2190const GX_FEED: *u8 = "knowledge/recordgaps.conf.rows"
2191const GX_STAMP: *u8 = "knowledge/recordgaps.conf.stamp"
2192const GX_READ_CAP: i64 = 4194304
2193const GX_NF: i64 = 5
2194const GX_F_KIND: i64 = 0
2195const GX_F_NAME: i64 = 1
2196const GX_F_BOARD: i64 = 2
2197const GX_F_SRC: i64 = 3
2198const GX_F_EV: i64 = 4
2199const GX_HUB: *u8 = "ecosystem"
2200const GX_UNASSIGNED: *u8 = "UNASSIGNED"
2201func gaps_pass(dom: *u8, fd: i64, mode: i64) -> i64 { return gaps_pass_heading(dom, fd, mode, 2) }
2202func gaps_pass_heading(dom: *u8, fd: i64, mode: i64, heading_level: i64) -> i64 {
2203 let path: *u8 = sys_mmap(GP_PATH_CAP)
2204 if ep_artifact_path(path, GX_FEED) == 0 { return 0 }
2205 let buf: *u8 = sys_mmap(GX_READ_CAP)
2206 let n: i64 = c_read(path, buf, GX_READ_CAP - 1)
2207 if n <= 0 { return 0 }
2208 var capped: i64 = 0
2209 if n >= GX_READ_CAP - 1 { capped = 1 }
2210 let now: i64 = sys_now_realtime_sec()
2211 let spath: *u8 = sys_mmap(GP_PATH_CAP)
2212 if ep_artifact_path(spath, GX_STAMP) == 0 { let so: i64 = scopy(spath, 0, GX_STAMP); spath[so] = 0 as u8 }
2213 let f: *i64 = sys_mmap(GA_F_SLOTS * GA_WORD) as *i64
2214 var st: i64 = ga_judge(spath, now, 0, f)
2215 if f[GA_F_CADENCE] > 0 { st = ga_judge(spath, now, f[GA_F_CADENCE], f) }
2216 var age: i64 = 0 - 1
2217 if f[GA_F_TS] > 0 { age = now - f[GA_F_TS] }
2218 let fld: *i64 = sys_mmap(GP_SPLIT * GA_WORD) as *i64
2219 var hub: i64 = 0
2220 if streq(dom, GX_HUB) == 1 { hub = 1 }
2221 var total: i64 = 0
2222 var own: i64 = 0
2223 var unassigned: i64 = 0
2224 var malformed: i64 = 0
2225 var shown: i64 = 0
2226 if mode == 2 {
2227 wc(fd, GP_CH_COMMA); wq(fd); w(fd, "gaps" as *u8); wq(fd); wc(fd, GP_CH_COLON); wc(fd, GP_CH_LBRACE)
2228 kv_s(fd, "feed" as *u8, path); wc(fd, GP_CH_COMMA)
2229 kv_s(fd, "stamp" as *u8, spath); wc(fd, GP_CH_COMMA)
2230 kv_s(fd, "state" as *u8, ga_state_name(st)); wc(fd, GP_CH_COMMA)
2231 kv_n(fd, "age_s" as *u8, age); wc(fd, GP_CH_COMMA)
2232 kv_n(fd, "sources_read" as *u8, f[GA_F_KNOWN]); wc(fd, GP_CH_COMMA)
2233 kv_n(fd, "sources_declared" as *u8, f[GA_F_TOTAL]); wc(fd, GP_CH_COMMA)
2234 kv_n(fd, "hub" as *u8, hub); wc(fd, GP_CH_COMMA)
2235 wq(fd); w(fd, "rows" as *u8); wq(fd); wc(fd, GP_CH_COLON); wc(fd, GP_CH_LBRACKET)
2236 }
2237 if mode == 1 {
2238 sc_heading_open(fd, heading_level, " id='gaps'" as *u8); w(fd, "Gaps from the record — what the estate does that no board carries" as *u8); sc_heading_close(fd, heading_level); w(fd, "\n" as *u8)
2239 w(fd, "<p class='lead'>The record census (<code>nx_goalmap record</code>) reads the invoked-tool population and every plan queue row and files each organ or directive that NO matrix, plan or gates row names. A row here is a callout the boards missed: adjudicate it onto a board or declare it infrastructure. Census state <b>" as *u8)
2240 w(fd, ga_state_name(st)); w(fd, "</b>" as *u8)
2241 if age >= 0 { w(fd, " (age " as *u8); wn(fd, age); w(fd, " s)" as *u8) }
2242 w(fd, ", sources read <b>" as *u8); wn(fd, f[GA_F_KNOWN]); w(fd, "</b> of <b>" as *u8); wn(fd, f[GA_F_TOTAL])
2243 w(fd, "</b> declared — a BLIND census is a FLOOR: unread sources can only add rows.</p>\n" as *u8)
2244 if capped == 1 { w(fd, "<div class='meth'>feed READ-CAPPED at " as *u8); wn(fd, GX_READ_CAP); w(fd, " bytes — the rows below are a PREFIX of the file</div>\n" as *u8) }
2245 w(fd, "<table class='gaps-tab'><thead><tr><th>kind</th><th>name</th><th>board</th><th>source</th><th>evidence</th></tr></thead><tbody>\n" as *u8)
2246 }
2247 var p: i64 = 0
2248 while p < n {
2249 var e: i64 = p
2250 while e < n { if buf[e] == (GP_CH_NL as u8) { break } e = e + 1 }
2251 buf[e] = 0 as u8
2252 let line: *u8 = (buf as i64 + p) as *u8
2253 p = e + 1
2254 if line[0] != (GP_CH_HASH as u8) { if line[0] != (0 as u8) {
2255 let nf: i64 = splitpipe(line, fld, GP_SPLIT)
2256 if nf < GX_NF { malformed = malformed + 1 } else {
2257 total = total + 1
2258 var render: i64 = 0
2259 if streq(fld[GX_F_BOARD] as *u8, dom) == 1 { own = own + 1; render = 1 }
2260 if streq(fld[GX_F_BOARD] as *u8, GX_UNASSIGNED) == 1 { unassigned = unassigned + 1; if hub == 1 { render = 1 } }
2261 if render == 1 {
2262 if mode == 1 {
2263 w(fd, "<tr><td class='ct'>" as *u8); wnote(fd, fld[GX_F_KIND] as *u8); w(fd, "</td><td><code>" as *u8); wnote(fd, fld[GX_F_NAME] as *u8)
2264 w(fd, "</code></td><td class='ct'>" as *u8); wnote(fd, fld[GX_F_BOARD] as *u8); w(fd, "</td><td class='ct'>" as *u8); wnote(fd, fld[GX_F_SRC] as *u8)
2265 w(fd, "</td><td>" as *u8); wnote(fd, fld[GX_F_EV] as *u8); w(fd, "</td></tr>\n" as *u8)
2266 }
2267 if mode == 2 {
2268 if shown > 0 { wc(fd, GP_CH_COMMA) }
2269 wc(fd, GP_CH_LBRACE)
2270 kv_s(fd, "kind" as *u8, fld[GX_F_KIND] as *u8); wc(fd, GP_CH_COMMA)
2271 kv_s(fd, "name" as *u8, fld[GX_F_NAME] as *u8); wc(fd, GP_CH_COMMA)
2272 kv_s(fd, "board" as *u8, fld[GX_F_BOARD] as *u8); wc(fd, GP_CH_COMMA)
2273 kv_s(fd, "source" as *u8, fld[GX_F_SRC] as *u8); wc(fd, GP_CH_COMMA)
2274 kv_s(fd, "evidence" as *u8, fld[GX_F_EV] as *u8)
2275 wc(fd, GP_CH_RBRACE)
2276 }
2277 shown = shown + 1
2278 }
2279 }
2280 } }
2281 }
2282 if mode == 2 {
2283 wc(fd, GP_CH_RBRACKET); wc(fd, GP_CH_COMMA)
2284 kv_n(fd, "shown" as *u8, shown); wc(fd, GP_CH_COMMA)
2285 kv_n(fd, "own" as *u8, own); wc(fd, GP_CH_COMMA)
2286 kv_n(fd, "estate_unassigned" as *u8, unassigned); wc(fd, GP_CH_COMMA)
2287 kv_n(fd, "total" as *u8, total); wc(fd, GP_CH_COMMA)
2288 kv_n(fd, "malformed" as *u8, malformed); wc(fd, GP_CH_COMMA)
2289 kv_n(fd, "read_capped" as *u8, capped)
2290 wc(fd, GP_CH_RBRACE)
2291 }
2292 if mode == 1 {
2293 w(fd, "</tbody></table>\n<p class='stats'>rows shown <b>" as *u8); wn(fd, shown)
2294 w(fd, "</b><span class='sep'>|</span>this board's directives <b>" as *u8); wn(fd, own)
2295 w(fd, "</b><span class='sep'>|</span>estate-wide un-boarded organs <b>" as *u8); wn(fd, unassigned)
2296 if hub == 0 { w(fd, "</b> (listed in full on <a href='/compare/ecosystem'>/compare/ecosystem</a>)<span class='sep'>|</span>census rows <b>" as *u8) } else { w(fd, "</b><span class='sep'>|</span>census rows <b>" as *u8) }
2297 wn(fd, total); w(fd, "</b><span class='sep'>|</span>malformed <b>" as *u8); wn(fd, malformed); w(fd, "</b> (counted, never rendered)</p>\n" as *u8)
2298 }
2299 return shown
2300}
2301func bench_pass(dom: *u8, fd: i64, mode: i64) -> i64 { return bench_pass_heading(dom, fd, mode, 2) }
2302func bench_pass_heading(dom: *u8, fd: i64, mode: i64, heading_level: i64) -> i64 {
2303 let path: *u8 = sys_mmap(600)
2304 var o: i64 = scopy(path, 0, "knowledge/compare/" as *u8)
2305 o = scopy(path, o, dom); o = scopy(path, o, ".bench" as *u8); path[o] = 0 as u8
2306 let hdr: *i64 = sys_mmap(BR_H_N * 8) as *i64
2307 let arms: *i64 = sys_mmap(BR_MAXARMS * BR_STRIDE * 8) as *i64
2308 let n: i64 = br_load(path, hdr, arms)
2309 if n < 0 { return 0 }
2310 let verdict: i64 = br_verdict(hdr, arms, n)
2311 let written: i64 = hdr[BR_H_WRITTEN_VERDICT]
2312 var agree: i64 = 0
2313 if written == verdict { agree = 1 }
2314 var c_valid: i64 = 0; var c_void: i64 = 0; var c_unm: i64 = 0; var c_bf: i64 = 0; var c_rf: i64 = 0; var c_unk: i64 = 0
2315 var i: i64 = 0
2316 while i < n {
2317 let st: i64 = arms[i * BR_STRIDE + BR_A_STATUS]
2318 if st == BR_ST_VALID { c_valid = c_valid + 1 } else { if st == BR_ST_VOID { c_void = c_void + 1 } else {
2319 if st == BR_ST_UNMEASURABLE { c_unm = c_unm + 1 } else { if st == BR_ST_BUILDFAIL { c_bf = c_bf + 1 } else {
2320 if st == BR_ST_RUNFAIL { c_rf = c_rf + 1 } else { c_unk = c_unk + 1 } } } } }
2321 i = i + 1
2322 }
2323 let ymd: *u8 = sys_mmap(32)
2324 bd_ymd(hdr[BR_H_ASOF], ymd, 0)
2325 let rt: *u8 = sys_mmap(32)
2326 if mode == 2 {
2327 wc(fd, 44); wq(fd); w(fd, "bench" as *u8); wq(fd); wc(fd, 58); wc(fd, 123)
2328 kv_s(fd, "file" as *u8, path); wc(fd, 44)
2329 kv_s(fd, "reader" as *u8, "nx_bench_receipt_lib" as *u8); wc(fd, 44)
2330 kv_s(fd, "writer" as *u8, hdr[BR_H_WRITER] as *u8); wc(fd, 44)
2331 kv_s(fd, "title" as *u8, hdr[BR_H_TITLE] as *u8); wc(fd, 44)
2332 kv_s(fd, "workload" as *u8, hdr[BR_H_WORKLOAD] as *u8); wc(fd, 44)
2333 kv_s(fd, "host" as *u8, hdr[BR_H_HOST] as *u8); wc(fd, 44)
2334 kv_n(fd, "runs" as *u8, hdr[BR_H_RUNS]); wc(fd, 44)
2335 kv_s(fd, "ref" as *u8, hdr[BR_H_REF] as *u8); wc(fd, 44)
2336 kv_n(fd, "asof" as *u8, hdr[BR_H_ASOF]); wc(fd, 44)
2337 kv_s(fd, "asof_ymd" as *u8, ymd); wc(fd, 44)
2338 kv_s(fd, "repro" as *u8, hdr[BR_H_REPRO] as *u8); wc(fd, 44)
2339 kv_s(fd, "verdict" as *u8, br_verdict_name(verdict)); wc(fd, 44)
2340 kv_s(fd, "written_verdict" as *u8, br_verdict_name(written)); wc(fd, 44)
2341 kv_n(fd, "writer_reader_agree" as *u8, agree); wc(fd, 44)
2342 kv_n(fd, "arms" as *u8, n); wc(fd, 44)
2343 kv_n(fd, "valid" as *u8, c_valid); wc(fd, 44); kv_n(fd, "void" as *u8, c_void); wc(fd, 44)
2344 kv_n(fd, "unmeasurable" as *u8, c_unm); wc(fd, 44); kv_n(fd, "build_fail" as *u8, c_bf); wc(fd, 44)
2345 kv_n(fd, "run_fail" as *u8, c_rf); wc(fd, 44); kv_n(fd, "unknown" as *u8, c_unk); wc(fd, 44)
2346 wq(fd); w(fd, "rows" as *u8); wq(fd); wc(fd, 58); wc(fd, 91)
2347 var j: i64 = 0
2348 while j < n {
2349 let b: i64 = j * BR_STRIDE
2350 if j > 0 { wc(fd, 44) }
2351 wc(fd, 123)
2352 kv_s(fd, "arm" as *u8, arms[b + BR_A_NAME] as *u8); wc(fd, 44)
2353 kv_s(fd, "toolchain" as *u8, arms[b + BR_A_TOOL] as *u8); wc(fd, 44)
2354 kv_s(fd, "version" as *u8, arms[b + BR_A_VER] as *u8); wc(fd, 44)
2355 kv_s(fd, "source" as *u8, arms[b + BR_A_SRC] as *u8); wc(fd, 44)
2356 kv_s(fd, "source_sha256" as *u8, arms[b + BR_A_SRCSHA] as *u8); wc(fd, 44)
2357 kv_n(fd, "bin_bytes" as *u8, arms[b + BR_A_BINBYTES]); wc(fd, 44)
2358 kv_s(fd, "bin_sha256" as *u8, arms[b + BR_A_BINSHA] as *u8); wc(fd, 44)
2359 kv_n(fd, "runs" as *u8, arms[b + BR_A_RUNS]); wc(fd, 44)
2360 kv_n(fd, "min_us" as *u8, arms[b + BR_A_MIN]); wc(fd, 44)
2361 kv_n(fd, "median_us" as *u8, arms[b + BR_A_MED]); wc(fd, 44)
2362 kv_n(fd, "checksum" as *u8, arms[b + BR_A_CHK]); wc(fd, 44)
2363 kv_s(fd, "status" as *u8, br_status_name(arms[b + BR_A_STATUS])); wc(fd, 44)
2364 kv_n(fd, "ratio_permil" as *u8, arms[b + BR_A_RATIO]); wc(fd, 44)
2365 kv_s(fd, "note" as *u8, arms[b + BR_A_NOTE] as *u8)
2366 wc(fd, 125)
2367 j = j + 1
2368 }
2369 wc(fd, 93)
2370 wc(fd, 125)
2371 return n
2372 }
2373 if mode == 1 {
2374 // scoped style so the section renders identically under both generators' sheets; theme vars with fallbacks
2375 w(fd, "<style>.bench-tab{width:100%;border-collapse:collapse;font-size:.84rem}.bench-tab th,.bench-tab td{text-align:left;padding:6px 8px;border-bottom:1px solid var(--line,rgb(60,64,72));vertical-align:top}.bench-tab th{font-size:.7rem;letter-spacing:.08em;text-transform:uppercase;color:var(--mut,rgb(150,162,186))}.bench-tab td.num{font-variant-numeric:tabular-nums;text-align:right;white-space:nowrap}.bench-tab code{font-family:ui-monospace,Consolas,monospace;font-size:.78rem}.bst{font-size:.66rem;letter-spacing:.08em;text-transform:uppercase;font-weight:650;padding:2px 8px;border-radius:8px;display:inline-block;white-space:nowrap;border:1px solid var(--line,rgb(60,64,72))}.bst.ok{color:var(--nx-color-ok,rgb(26,127,55))}.bst.void{color:var(--nx-color-absent,rgb(179,38,30))}.bst.unm{color:var(--mut,rgb(150,162,186))}.bst.fail{color:var(--nx-color-part,rgb(178,106,0))}.bench-repro{font-family:ui-monospace,Consolas,monospace;font-size:.78rem;background:var(--soft,rgb(40,46,64));padding:8px 10px;border-radius:8px;overflow-x:auto;white-space:pre}.bench-ref{font-weight:600}</style>\n" as *u8)
2376 sc_heading_open(fd, heading_level, " class='ghead' id='bench'" as *u8); w(fd, "Measured head-to-head — a receipt, not a claim" as *u8); sc_heading_close(fd, heading_level); w(fd, "\n<div class='meth'><b>" as *u8); wnote(fd, hdr[BR_H_TITLE] as *u8); w(fd, ".</b> " as *u8); wnote(fd, hdr[BR_H_WORKLOAD] as *u8)
2377 w(fd, " Measured on <code>" as *u8); wnote(fd, hdr[BR_H_HOST] as *u8); w(fd, "</code> on " as *u8); w(fd, ymd); w(fd, " (unix " as *u8); wn(fd, hdr[BR_H_ASOF]); w(fd, "), " as *u8); wn(fd, hdr[BR_H_RUNS]); w(fd, " runs per arm, reference arm <span class='bench-ref'>" as *u8); wnote(fd, hdr[BR_H_REF] as *u8)
2378 w(fd, "</span> = 1.00x. Every arm had to print the same checksum or its row is VOID and never ranked; an arm whose toolchain is not declared on the host is UNMEASURABLE, an absence rather than a loss. Written by <code>" as *u8); wnote(fd, hdr[BR_H_WRITER] as *u8); w(fd, "</code>, re-derived here by <code>nx_bench_receipt_lib</code>: reader verdict <span class='bst " as *u8)
2379 if verdict == BR_V_VALID { w(fd, "ok" as *u8) } else { if verdict == BR_V_VOID { w(fd, "void" as *u8) } else { w(fd, "unm" as *u8) } }
2380 w(fd, "'>" as *u8); w(fd, br_verdict_name(verdict)); w(fd, "</span>, writer wrote " as *u8); w(fd, br_verdict_name(written))
2381 if agree == 1 { w(fd, " (writer and reader agree)" as *u8) } else { w(fd, " (<b>WRITER AND READER DISAGREE</b> -- the rows were edited after the receipt was written)" as *u8) }
2382 w(fd, ".</div>\n<div style='overflow-x:auto'><table class='bench-tab'><thead><tr><th>Arm</th><th>Toolchain</th><th>Version</th><th>Median µs</th><th>Min µs</th><th>vs reference</th><th>Checksum</th><th>Status</th><th>Runs</th><th>Source sha256</th><th>Binary</th></tr></thead><tbody>\n" as *u8)
2383 var k: i64 = 0
2384 while k < n {
2385 let b: i64 = k * BR_STRIDE
2386 let st: i64 = arms[b + BR_A_STATUS]
2387 w(fd, "<tr><td><b>" as *u8); wnote(fd, arms[b + BR_A_NAME] as *u8); w(fd, "</b></td><td>" as *u8); wnote(fd, arms[b + BR_A_TOOL] as *u8)
2388 w(fd, "</td><td><code>" as *u8); wnote(fd, arms[b + BR_A_VER] as *u8); w(fd, "</code></td><td class='num'>" as *u8)
2389 if st == BR_ST_VALID { wn(fd, arms[b + BR_A_MED]) } else { w(fd, "-" as *u8) }
2390 w(fd, "</td><td class='num'>" as *u8)
2391 if st == BR_ST_VALID { wn(fd, arms[b + BR_A_MIN]) } else { w(fd, "-" as *u8) }
2392 w(fd, "</td><td class='num'>" as *u8)
2393 br_ratio_text(arms[b + BR_A_RATIO], rt, 0); w(fd, rt)
2394 w(fd, "</td><td class='num'>" as *u8)
2395 if st == BR_ST_VALID { wn(fd, arms[b + BR_A_CHK]) } else { if st == BR_ST_VOID { wn(fd, arms[b + BR_A_CHK]) } else { w(fd, "-" as *u8) } }
2396 w(fd, "</td><td><span class='bst " as *u8); w(fd, bd_status_class(st)); w(fd, "'>" as *u8); w(fd, br_status_name(st)); w(fd, "</span>" as *u8)
2397 if st != BR_ST_VALID { w(fd, "<br><span class='ct'>" as *u8); wnote(fd, arms[b + BR_A_NOTE] as *u8); w(fd, "</span>" as *u8) }
2398 w(fd, "</td><td class='num'>" as *u8); wn(fd, arms[b + BR_A_RUNS])
2399 w(fd, "</td><td><code title='" as *u8); wnote(fd, arms[b + BR_A_SRC] as *u8); w(fd, "'>" as *u8); bd_sha_short(fd, arms[b + BR_A_SRCSHA] as *u8); w(fd, "</code></td><td class='num'><code>" as *u8); bd_sha_short(fd, arms[b + BR_A_BINSHA] as *u8); w(fd, "</code> " as *u8); wn(fd, arms[b + BR_A_BINBYTES]); w(fd, " B</td></tr>\n" as *u8)
2400 k = k + 1
2401 }
2402 w(fd, "</tbody></table></div>\n<p class='foot'>bench arms=" as *u8); wn(fd, n); w(fd, " valid=" as *u8); wn(fd, c_valid); w(fd, " void=" as *u8); wn(fd, c_void); w(fd, " unmeasurable=" as *u8); wn(fd, c_unm); w(fd, " build_fail=" as *u8); wn(fd, c_bf); w(fd, " run_fail=" as *u8); wn(fd, c_rf); w(fd, " unknown=" as *u8); wn(fd, c_unk); w(fd, " (partition sums) verdict=" as *u8); w(fd, br_verdict_name(verdict)); w(fd, "</p>\n" as *u8)
2403 w(fd, "<p class='foot'>reproduce: </p><div class='bench-repro'>" as *u8); wnote(fd, hdr[BR_H_REPRO] as *u8); w(fd, "</div>\n<p class='foot'>receipt: knowledge/compare/" as *u8); w(fd, dom); w(fd, ".bench · a rerun on the same host that changes the ranking is a finding, not noise; a rerun on a different host is a different receipt and says so in its host line.</p>\n" as *u8)
2404 return n
2405 }
2406 return n
2407}
2408
2409// Additive shared dependency projection. Parsed declarations are not verified readiness.
2410// Owned by nx_swcompare_lib; no main, filesystem writes, publication or dispatch.
2411import "nx_sha256.nx"
2412const SGP_FIELDS: i64 = 8
2413const SGP_PATH_CAP: i64 = 600
2414const SGP_I64_MAX: i64 = 9223372036854775807
2415// WHY THE LEDGERS BELOW EXIST (2026-09-11): every counter in SgPlan was computed at parse time and
2416// the one consumer printed a single sentence -- malformed, missing, duplicate or cyclic -- and threw
2417// the rest away, so a refused board cost the next reader the whole investigation. The reason is in
2418// hand at the moment the defect is found; it is recorded there instead of being re-derived by hand.
2419// A COUNT WITHOUT A WORKLIST IS NOT ACTIONABLE.
2420const SGP_COLON: i64 = 58 // ':' -- the separator in a cross-board '<domain>:<rung>' ref
2421const SGP_NOTE_WORDS: i64 = 5 // one record: rule, rung-id ptr, name ptr, name len, number
2422const SGP_OFFENDER_MAX: i64 = 64 // offender rows RECORDED; offender_overflow carries the rest
2423const SGP_EXTERNAL_MAX: i64 = 64 // cross-board refs RECORDED; external_overflow carries the rest
2424const SGP_RULE_FIELDS: i64 = 1 // a rung row whose field count is not SGP_FIELDS
2425const SGP_RULE_BADID: i64 = 2 // a rung id outside the id grammar
2426const SGP_RULE_DUPID: i64 = 3 // a second declaration of one id
2427const SGP_RULE_BADDEP: i64 = 4 // a dependency token outside the id grammar
2428const SGP_RULE_MISSDEP: i64 = 5 // a dependency naming no rung on THIS plan
2429const SGP_RULE_DUPEDGE: i64 = 6 // the same dependency declared twice on one rung
2430const SGP_RULE_CYCLE: i64 = 7 // on a dependency cycle
2431const SGP_RULE_CYCLEDOWN: i64 = 8 // not on a cycle, but blocked by one
2432struct SgPlan {
2433 plan: *u8
2434 plan_bytes: i64
2435 plan_sha: *u8
2436 matrix_sha: *u8
2437 matrix_bytes: i64
2438 rank_sha: *u8
2439 rank_bytes: i64
2440 nodes: *i64
2441 count: i64
2442 declared: i64
2443 edges: *i64
2444 edge_count: i64
2445 malformed: i64
2446 duplicate_ids: i64
2447 duplicate_edges: i64
2448 missing_deps: i64
2449 cyclic_nodes: i64
2450 target_rows: i64
2451 role_rows: i64
2452 risk_rows: i64
2453 log_rows: i64
2454 rank_count: i64
2455 rank_mismatches: i64
2456 binding_rows: i64
2457 binding_ok: i64
2458 growth: *CgModel
2459 // ---- the offender and cross-board ledgers (2026-09-11). APPENDED, so every field above keeps
2460 // its place; sys_mmap zero-fills, so an unrecorded plan reads them as an empty ledger, not junk.
2461 external_deps: i64
2462 offenders: *i64
2463 offender_count: i64
2464 offender_overflow: i64
2465 externals: *i64
2466 external_count: i64
2467 external_overflow: i64
2468}
2469func sg_len(s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { i = i + 1 } return i }
2470func sg_id(s: *u8, n: i64) -> i64 {
2471 if n <= 0 { return 0 }
2472 var i: i64 = 0
2473 while i < n {
2474 let c: i64 = s[i] as i64
2475 var ok: i64 = 0
2476 if c >= 48 { if c <= 57 { ok = 1 } }
2477 if c >= 65 { if c <= 90 { ok = 1 } }
2478 if c >= 97 { if c <= 122 { ok = 1 } }
2479 if c == 95 { ok = 1 }; if c == 45 { ok = 1 }
2480 if ok == 0 { return 0 }; i = i + 1
2481 }
2482 return 1
2483}
2484// Unlike splitpipe, count every field even when the caller's pointer reserve is full.
2485func sg_split(s: *u8, f: *i64, capacity: i64, delimiter: i64) -> i64 {
2486 var count: i64 = 1; var i: i64 = 0; f[0] = s as i64
2487 while s[i] != (0 as u8) {
2488 if s[i] == (delimiter as u8) { s[i] = 0 as u8; if count < capacity { f[count] = s as i64 + i + 1 }; count = count + 1 }
2489 i = i + 1
2490 }
2491 return count
2492}
2493func sg_decimal(s: *u8) -> i64 {
2494 if s[0] == (0 as u8) { return 0 - 1 }
2495 var v: i64 = 0; var i: i64 = 0
2496 while s[i] != (0 as u8) {
2497 let c: i64 = s[i] as i64; if c < 48 { return 0 - 1 }; if c > 57 { return 0 - 1 }
2498 let d: i64 = c - 48; if v > (SGP_I64_MAX - d) / 10 { return 0 - 1 }
2499 v = v * 10 + d; i = i + 1
2500 }
2501 return v
2502}
2503func sg_sha(b: *u8, n: i64) -> *u8 {
2504 let raw: *u8 = sys_mmap(32); let text: *u8 = sys_mmap(65)
2505 if (raw as i64) <= 0 { return "" as *u8 }; if (text as i64) <= 0 { return "" as *u8 }
2506 sha256_digest(b, n, raw)
2507 let digits: *u8 = "0123456789abcdef" as *u8
2508 var i: i64 = 0
2509 while i < 32 { let c: i64 = raw[i] as i64; text[i*2] = digits[c / 16]; text[i*2+1] = digits[c % 16]; i = i + 1 }
2510 text[64] = 0 as u8; return text
2511}
2512func sg_find(m: *SgPlan, name: *u8, length: i64) -> i64 {
2513 var i: i64 = 0
2514 while i < m.count {
2515 let id: *u8 = m.nodes[i*SGP_FIELDS + 1] as *u8
2516 if sg_len(id) == length {
2517 var j: i64 = 0; var equal: i64 = 1
2518 while j < length { if id[j] != name[j] { equal = 0 }; j = j + 1 }
2519 if equal == 1 { return i }
2520 }
2521 i = i + 1
2522 }
2523 return 0 - 1
2524}
2525func sg_prefix_decimal(s: *u8, key: *u8) -> i64 {
2526 if starts(s, key) == 0 { return 0 - 1 }
2527 return sg_decimal((s as i64 + sg_len(key)) as *u8)
2528}
2529func sg_rank(m: *SgPlan, raw: *u8, n: i64) -> i64 {
2530 m.rank_count = 0 - 1
2531 if n <= 0 { return 0 }
2532 if n == SGP_I64_MAX { m.rank_mismatches = m.rank_mismatches + 1; return 0 }
2533 m.rank_sha = sg_sha(raw, n); m.rank_bytes = n
2534 if sg_len(m.rank_sha) != 64 { m.rank_mismatches = m.rank_mismatches + 1; return 0 }
2535 let b: *u8 = sys_mmap(n + 1); var c: i64 = 0
2536 if (b as i64) <= 0 { m.rank_mismatches = m.rank_mismatches + 1; return 0 }
2537 while c < n { if raw[c] == (0 as u8) { m.rank_mismatches = m.rank_mismatches + 1; return 0 }; b[c] = raw[c]; c = c + 1 }; b[n] = 0 as u8
2538 let f: *i64 = sys_mmap(12 * 8) as *i64
2539 if (f as i64) <= 0 { m.rank_mismatches = m.rank_mismatches + 1; return 0 }
2540 var pos: i64 = 0; var stamps: i64 = 0
2541 while pos < n {
2542 var end: i64 = pos; while end < n { if b[end] == (10 as u8) { break }; end = end + 1 }
2543 b[end] = 0 as u8; if end > pos { if b[end-1] == (13 as u8) { b[end-1] = 0 as u8 } }
2544 let line: *u8 = (b as i64 + pos) as *u8; pos = end + 1
2545 if starts(line, "# inputs_v=" as *u8) == 1 {
2546 m.binding_rows = m.binding_rows + 1
2547 let nf: i64 = sg_split(line, f, 12, 32)
2548 if nf == 6 {
2549 if streq(f[1] as *u8, "inputs_v=1" as *u8) == 1 {
2550 let ps: *u8 = f[2] as *u8; let ms: *u8 = f[4] as *u8
2551 if starts(ps, "plan_sha256=" as *u8) == 1 { if starts(ms, "matrix_sha256=" as *u8) == 1 {
2552 if streq((ps as i64 + 12) as *u8, m.plan_sha) == 1 { if streq((ms as i64 + 14) as *u8, m.matrix_sha) == 1 {
2553 if sg_prefix_decimal(f[3] as *u8, "plan_bytes=" as *u8) == m.plan_bytes {
2554 if sg_prefix_decimal(f[5] as *u8, "matrix_bytes=" as *u8) == m.matrix_bytes { m.binding_ok = 1 }
2555 }
2556 } }
2557 } }
2558 }
2559 }
2560 } else {
2561 if starts(line, "# asof=" as *u8) == 1 {
2562 stamps = stamps + 1
2563 let nf: i64 = sg_split(line, f, 12, 32)
2564 if nf > 12 { m.rank_mismatches = m.rank_mismatches + 1 } else {
2565 var z: i64 = 0; var found: i64 = 0
2566 while z < nf { if starts(f[z] as *u8, "rungs=" as *u8) == 1 { found = found + 1; m.rank_count = sg_prefix_decimal(f[z] as *u8, "rungs=" as *u8) }; z = z + 1 }
2567 if found != 1 { m.rank_mismatches = m.rank_mismatches + 1 }
2568 }
2569 } else {
2570 if starts(line, "rank|" as *u8) == 1 {
2571 let nf: i64 = sg_split(line, f, 12, 124)
2572 if nf != 10 { m.rank_mismatches = m.rank_mismatches + 1 } else {
2573 let id: *u8 = f[3] as *u8; let idx: i64 = sg_find(m, id, sg_len(id))
2574 if idx < 0 { m.rank_mismatches = m.rank_mismatches + 1 } else {
2575 if streq(f[9] as *u8, m.nodes[idx*SGP_FIELDS+3] as *u8) == 0 { m.rank_mismatches = m.rank_mismatches + 1 }
2576 }
2577 }
2578 }
2579 }
2580 }
2581 }
2582 if stamps != 1 { m.rank_mismatches = m.rank_mismatches + 1 }
2583 if m.binding_rows != 1 { m.binding_ok = 0 }
2584 if m.matrix_bytes <= 0 { m.binding_ok = 0 }
2585 return 0
2586}
2587// ---- THE OFFENDER AND CROSS-BOARD LEDGERS (2026-09-11) -----------------------------------------
2588// Both lists are BOUNDED and say so: the counters are the complete population, these are the
2589// worklist, and anything that does not fit is announced as an unlisted count, never dropped silently.
2590func sg_colon(s: *u8, n: i64) -> i64 {
2591 var i: i64 = 0
2592 while i < n { if s[i] == (SGP_COLON as u8) { return i }; i = i + 1 }
2593 return 0 - 1
2594}
2595func sg_rule_name(rule: i64) -> *u8 {
2596 if rule == SGP_RULE_FIELDS { return "field-count" as *u8 }
2597 if rule == SGP_RULE_BADID { return "bad-id" as *u8 }
2598 if rule == SGP_RULE_DUPID { return "duplicate-id" as *u8 }
2599 if rule == SGP_RULE_BADDEP { return "bad-dep-id" as *u8 }
2600 if rule == SGP_RULE_MISSDEP { return "missing-dep" as *u8 }
2601 if rule == SGP_RULE_DUPEDGE { return "duplicate-edge" as *u8 }
2602 if rule == SGP_RULE_CYCLE { return "cycle" as *u8 }
2603 if rule == SGP_RULE_CYCLEDOWN { return "cycle-downstream" as *u8 }
2604 return "unnamed-rule" as *u8
2605}
2606// A record is written ONLY when there is room; the caller counts the ones that did not fit.
2607func sg_note(list: *i64, count: i64, capacity: i64, rule: i64, rung: *u8, name: *u8, length: i64, number: i64) -> i64 {
2608 if (list as i64) <= 0 { return 0 }
2609 if count >= capacity { return 0 }
2610 let b: i64 = count * SGP_NOTE_WORDS
2611 list[b] = rule; list[b+1] = rung as i64; list[b+2] = name as i64; list[b+3] = length; list[b+4] = number
2612 return 1
2613}
2614func sg_offend(m: *SgPlan, rule: i64, rung: *u8, name: *u8, length: i64, number: i64) -> i64 {
2615 if sg_note(m.offenders, m.offender_count, SGP_OFFENDER_MAX, rule, rung, name, length, number) == 1 { m.offender_count = m.offender_count + 1; return 1 }
2616 m.offender_overflow = m.offender_overflow + 1
2617 return 0
2618}
2619func sg_extern(m: *SgPlan, rung: *u8, name: *u8, length: i64) -> i64 {
2620 if sg_note(m.externals, m.external_count, SGP_EXTERNAL_MAX, 0, rung, name, length, 0) == 1 { m.external_count = m.external_count + 1; return 1 }
2621 m.external_overflow = m.external_overflow + 1
2622 return 0
2623}
2624// ONE emitter, so no caller can print a count without its worklist. COUNTERS FIRST: a reader that
2625// truncates keeps the population line, and the per-row detail follows it.
2626func sg_graph_text(m: *SgPlan, fd: i64) -> i64 {
2627 if (m as i64) <= 0 { w(fd, "GRAPH capture=UNAVAILABLE\n" as *u8); return 0 }
2628 w(fd, "GRAPH declared=" as *u8); wn(fd, m.declared)
2629 w(fd, " nodes=" as *u8); wn(fd, m.count)
2630 w(fd, " edges=" as *u8); wn(fd, m.edge_count)
2631 w(fd, " malformed=" as *u8); wn(fd, m.malformed)
2632 w(fd, " duplicate_ids=" as *u8); wn(fd, m.duplicate_ids)
2633 w(fd, " duplicate_edges=" as *u8); wn(fd, m.duplicate_edges)
2634 w(fd, " missing_deps=" as *u8); wn(fd, m.missing_deps)
2635 w(fd, " cyclic_nodes=" as *u8); wn(fd, m.cyclic_nodes)
2636 w(fd, " external_deps=" as *u8); wn(fd, m.external_deps)
2637 w(fd, " offenders_listed=" as *u8); wn(fd, m.offender_count)
2638 w(fd, " offenders_unlisted=" as *u8); wn(fd, m.offender_overflow)
2639 w(fd, " offender_cap=" as *u8); wn(fd, SGP_OFFENDER_MAX)
2640 w(fd, " externals_listed=" as *u8); wn(fd, m.external_count)
2641 w(fd, " externals_unlisted=" as *u8); wn(fd, m.external_overflow)
2642 w(fd, " external_cap=" as *u8); wn(fd, SGP_EXTERNAL_MAX)
2643 w(fd, "\n" as *u8)
2644 var i: i64 = 0
2645 while i < m.offender_count {
2646 let ob: i64 = i * SGP_NOTE_WORDS
2647 w(fd, "GRAPH OFFENDER rung=" as *u8); w(fd, m.offenders[ob+1] as *u8)
2648 w(fd, " rule=" as *u8); w(fd, sg_rule_name(m.offenders[ob]))
2649 if m.offenders[ob+3] > 0 { w(fd, " dep=" as *u8); sys_write(fd, m.offenders[ob+2] as *u8, m.offenders[ob+3]) }
2650 if m.offenders[ob] == SGP_RULE_FIELDS { w(fd, " fields=" as *u8); wn(fd, m.offenders[ob+4]); w(fd, " expected=" as *u8); wn(fd, SGP_FIELDS) }
2651 w(fd, "\n" as *u8)
2652 i = i + 1
2653 }
2654 if m.offender_overflow > 0 { w(fd, "GRAPH OFFENDER-OVERFLOW unlisted=" as *u8); wn(fd, m.offender_overflow); w(fd, " -- the counters above are the whole population; this list stops at offender_cap\n" as *u8) }
2655 var e: i64 = 0
2656 while e < m.external_count {
2657 let xb: i64 = e * SGP_NOTE_WORDS
2658 w(fd, "GRAPH EXTERNAL rung=" as *u8); w(fd, m.externals[xb+1] as *u8)
2659 w(fd, " ref=" as *u8); sys_write(fd, m.externals[xb+2] as *u8, m.externals[xb+3])
2660 w(fd, " -- cross-board reference: recorded, NOT an edge on this plan and NOT a refusal\n" as *u8)
2661 e = e + 1
2662 }
2663 if m.external_overflow > 0 { w(fd, "GRAPH EXTERNAL-OVERFLOW unlisted=" as *u8); wn(fd, m.external_overflow); w(fd, "\n" as *u8) }
2664 return 0
2665}
2666func sg_parse(raw: *u8, n: i64, rank: *u8, rn: i64, matrix: *u8, mn: i64) -> *SgPlan {
2667 // SgPlan stores 33 pointer/i64 fields, each one native 64-bit word.
2668 let m: *SgPlan = sys_mmap(33 * 8) as *SgPlan
2669 if (m as i64) <= 0 { return 0 as *SgPlan }
2670 m.rank_count = 0 - 1; m.matrix_bytes = mn
2671 m.plan_sha = "" as *u8; m.matrix_sha = "" as *u8; m.rank_sha = "" as *u8
2672 if n <= 0 { m.malformed = 1; return m }
2673 if (raw as i64) <= 0 { m.malformed = 1; return m }
2674 // Reserve arithmetic is bounded by the input byte count, not a policy cutoff.
2675 if n > SGP_I64_MAX / (SGP_FIELDS * 8) - 1 { m.malformed = 1; return m }
2676 if rn < 0 { m.malformed = 1; return m }; if mn < 0 { m.malformed = 1; return m }
2677 if rn > 0 { if (rank as i64) <= 0 { m.malformed = 1; return m } }
2678 if mn > 0 { if (matrix as i64) <= 0 { m.malformed = 1; return m } }
2679 m.growth = cg_parse(raw, n)
2680 m.plan_bytes = n; m.plan_sha = sg_sha(raw, n)
2681 if sg_len(m.plan_sha) != 64 { m.malformed = 1; return m }
2682 if mn > 0 { m.matrix_sha = sg_sha(matrix, mn); if sg_len(m.matrix_sha) != 64 { m.malformed = 1; return m } }
2683 let b: *u8 = sys_mmap(n + 1); m.plan = b
2684 if (b as i64) <= 0 { m.malformed = 1; return m }
2685 var maxrows: i64 = 1; var maxedges: i64 = 1; var c: i64 = 0
2686 while c < n {
2687 if raw[c] == (0 as u8) { m.malformed = m.malformed + 1 }
2688 if raw[c] == (10 as u8) { maxrows = maxrows + 1; maxedges = maxedges + 1 }
2689 if raw[c] == (44 as u8) { maxedges = maxedges + 1 }
2690 b[c] = raw[c]; c = c + 1
2691 }
2692 b[n] = 0 as u8
2693 m.nodes = sys_mmap(maxrows * SGP_FIELDS * 8) as *i64
2694 m.edges = sys_mmap(maxedges * 2 * 8) as *i64
2695 // The two ledgers. A failed reserve is DELIBERATELY NOT a malformed board: sg_note refuses to
2696 // write and the unlisted counter carries it, so losing the worklist can never change a verdict.
2697 m.offenders = sys_mmap(SGP_OFFENDER_MAX * SGP_NOTE_WORDS * 8) as *i64
2698 m.externals = sys_mmap(SGP_EXTERNAL_MAX * SGP_NOTE_WORDS * 8) as *i64
2699 let f: *i64 = sys_mmap(SGP_FIELDS * 8) as *i64
2700 if (m.nodes as i64) <= 0 { m.malformed = 1; return m }
2701 if (m.edges as i64) <= 0 { m.malformed = 1; return m }
2702 if (f as i64) <= 0 { m.malformed = 1; return m }
2703 var pos: i64 = 0
2704 while pos < n {
2705 var end: i64 = pos; while end < n { if b[end] == (10 as u8) { break }; end = end + 1 }
2706 b[end] = 0 as u8; if end > pos { if b[end-1] == (13 as u8) { b[end-1] = 0 as u8 } }
2707 let line: *u8 = (b as i64 + pos) as *u8; pos = end + 1
2708 if starts(line, "sotatarget|" as *u8) == 1 { m.target_rows = m.target_rows + 1 }
2709 if starts(line, "rungrole|" as *u8) == 1 { m.role_rows = m.role_rows + 1 }
2710 if starts(line, "risk|" as *u8) == 1 { m.risk_rows = m.risk_rows + 1 }
2711 if starts(line, "log|" as *u8) == 1 { m.log_rows = m.log_rows + 1 }
2712 if starts(line, "rung|" as *u8) == 1 {
2713 m.declared = m.declared + 1
2714 let nf: i64 = sg_split(line, f, SGP_FIELDS, 124)
2715 // f[1] is the id field. The line began with "rung|", so the split produced at least two
2716 // fields and f[1] is set even on a row whose field COUNT is wrong -- which is exactly the
2717 // row a reader most needs named.
2718 if nf != SGP_FIELDS { m.malformed = m.malformed + 1; sg_offend(m, SGP_RULE_FIELDS, f[1] as *u8, "" as *u8, 0, nf) } else {
2719 let id: *u8 = f[1] as *u8
2720 if sg_id(id, sg_len(id)) == 0 { m.malformed = m.malformed + 1; sg_offend(m, SGP_RULE_BADID, id, "" as *u8, 0, 0) } else {
2721 if sg_find(m, id, sg_len(id)) >= 0 { m.duplicate_ids = m.duplicate_ids + 1; sg_offend(m, SGP_RULE_DUPID, id, "" as *u8, 0, 0) } else {
2722 var j: i64 = 0; while j < SGP_FIELDS { m.nodes[m.count*SGP_FIELDS+j] = f[j]; j = j + 1 }
2723 m.count = m.count + 1
2724 }
2725 }
2726 }
2727 }
2728 }
2729 var node: i64 = 0
2730 while node < m.count {
2731 let deps: *u8 = m.nodes[node*SGP_FIELDS+7] as *u8
2732 if streq(deps, "-" as *u8) == 0 {
2733 var start: i64 = 0; var at: i64 = 0; var more: i64 = 1
2734 while more == 1 {
2735 var delimiter: i64 = 0
2736 if deps[at] == (0 as u8) { more = 0; delimiter = 1 }
2737 if deps[at] == (44 as u8) { delimiter = 1 }
2738 if delimiter == 1 {
2739 let length: i64 = at - start
2740 let name: *u8 = (deps as i64 + start) as *u8
2741 let rid: *u8 = m.nodes[node*SGP_FIELDS+1] as *u8
2742 // '<domain>:<rung>' is a DECLARED cross-board reference. The other board is not loaded
2743 // here, so it is RECORDED and COUNTED -- never an edge on this graph, and never a
2744 // refusal. A BARE unknown id still refuses, so the syntax IS the declaration and this
2745 // cannot launder a typo: 'gen:' or ':G16' or 'a:b:c' fail the id grammar below and
2746 // stay malformed, named as bad-dep-id.
2747 var ext: i64 = 0
2748 let colon: i64 = sg_colon(name, length)
2749 if colon > 0 { if sg_id(name, colon) == 1 { if sg_id((name as i64 + colon + 1) as *u8, length - colon - 1) == 1 { ext = 1 } } }
2750 if ext == 1 { m.external_deps = m.external_deps + 1; sg_extern(m, rid, name, length) } else {
2751 if sg_id(name, length) == 0 { m.malformed = m.malformed + 1; sg_offend(m, SGP_RULE_BADDEP, rid, name, length, 0) } else {
2752 let dep: i64 = sg_find(m, name, length)
2753 if dep < 0 { m.missing_deps = m.missing_deps + 1; sg_offend(m, SGP_RULE_MISSDEP, rid, name, length, 0) } else {
2754 var duplicate: i64 = 0; var e: i64 = 0
2755 while e < m.edge_count { if m.edges[e*2] == dep { if m.edges[e*2+1] == node { duplicate = 1 } }; e = e + 1 }
2756 if duplicate == 1 { m.duplicate_edges = m.duplicate_edges + 1; sg_offend(m, SGP_RULE_DUPEDGE, rid, name, length, 0) } else {
2757 m.edges[m.edge_count*2] = dep; m.edges[m.edge_count*2+1] = node; m.edge_count = m.edge_count + 1
2758 }
2759 }
2760 }
2761 }
2762 start = at + 1
2763 }
2764 at = at + 1
2765 }
2766 }
2767 node = node + 1
2768 }
2769 let degree: *i64 = sys_mmap((m.count+1)*8) as *i64
2770 let visited: *i64 = sys_mmap((m.count+1)*8) as *i64
2771 if (degree as i64) <= 0 { m.malformed = 1; return m }
2772 if (visited as i64) <= 0 { m.malformed = 1; return m }
2773 var e: i64 = 0; while e < m.edge_count { let to: i64 = m.edges[e*2+1]; degree[to] = degree[to] + 1; e = e + 1 }
2774 var removed: i64 = 0; var progress: i64 = 1
2775 while progress == 1 {
2776 progress = 0; var i: i64 = 0
2777 while i < m.count {
2778 if visited[i] == 0 { if degree[i] == 0 {
2779 visited[i] = 1; removed = removed + 1; progress = 1
2780 var j: i64 = 0; while j < m.edge_count { if m.edges[j*2] == i { let to: i64 = m.edges[j*2+1]; degree[to] = degree[to] - 1 }; j = j + 1 }
2781 } }
2782 i = i + 1
2783 }
2784 }
2785 m.cyclic_nodes = m.count - removed
2786 // Kahn's residue is ON a cycle OR BLOCKED BY one, and those two need OPPOSITE edits, so the
2787 // ledger names which. Reverse trim: a residual node that no residual node depends on cannot be on
2788 // a cycle. What survives the trim is the cycle core. Runs ONLY when there is a residue, so a valid
2789 // board pays nothing for it.
2790 if m.cyclic_nodes > 0 {
2791 let core: *i64 = sys_mmap((m.count+1)*8) as *i64
2792 if (core as i64) > 0 {
2793 var ci: i64 = 0
2794 while ci < m.count { if visited[ci] == 0 { core[ci] = 1 }; ci = ci + 1 }
2795 var trimming: i64 = 1
2796 while trimming == 1 {
2797 trimming = 0
2798 var t: i64 = 0
2799 while t < m.count {
2800 if core[t] == 1 {
2801 var out: i64 = 0
2802 var te: i64 = 0
2803 while te < m.edge_count { if m.edges[te*2] == t { if core[m.edges[te*2+1]] == 1 { out = out + 1 } }; te = te + 1 }
2804 if out == 0 { core[t] = 0; trimming = 1 }
2805 }
2806 t = t + 1
2807 }
2808 }
2809 var cz: i64 = 0
2810 while cz < m.count {
2811 if visited[cz] == 0 {
2812 var rule: i64 = SGP_RULE_CYCLEDOWN
2813 if core[cz] == 1 { rule = SGP_RULE_CYCLE }
2814 sg_offend(m, rule, m.nodes[cz*SGP_FIELDS+1] as *u8, "" as *u8, 0, 0)
2815 }
2816 cz = cz + 1
2817 }
2818 }
2819 }
2820 sg_rank(m, rank, rn)
2821 return m
2822}
2823func sg_valid(m: *SgPlan) -> i64 {
2824 if (m as i64) <= 0 { return 0 }
2825 if m.malformed + m.duplicate_ids + m.duplicate_edges + m.missing_deps + m.cyclic_nodes != 0 { return 0 }
2826 return 1
2827}
2828func sg_rank_state(m: *SgPlan) -> *u8 {
2829 if m.rank_bytes <= 0 { return "UNAVAILABLE" as *u8 }
2830 if m.rank_count != m.declared { return "STALE_INCONSISTENT" as *u8 }
2831 if m.rank_mismatches > 0 { return "STALE_INCONSISTENT" as *u8 }
2832 if m.binding_rows > 1 { return "INVALID_BINDING" as *u8 }
2833 if m.binding_rows == 1 { if m.binding_ok == 0 { return "STALE_OR_INVALID_BINDING" as *u8 } }
2834 if m.binding_ok == 1 { return "PLAN_MATRIX_BOUND_ONLY" as *u8 }
2835 return "UNBOUND" as *u8
2836}
2837func sg_load(domain: *u8) -> *SgPlan {
2838 let path: *u8 = sys_mmap(SGP_PATH_CAP)
2839 if (path as i64) <= 0 { return 0 as *SgPlan }
2840 let prefix: *u8 = "knowledge/compare/" as *u8
2841 let dn: i64 = sg_len(domain)
2842 if dn + sg_len(prefix) + sg_len(".matrix") + 1 > SGP_PATH_CAP { return 0 as *SgPlan }
2843 if sg_id(domain, dn) == 0 { return 0 as *SgPlan }
2844 let base: i64 = scopy(path, 0, prefix)
2845 let tail: i64 = scopy(path, base, domain)
2846 let plen: *i64 = sys_mmap(16) as *i64; let rlen: *i64 = sys_mmap(16) as *i64; let mlen: *i64 = sys_mmap(16) as *i64
2847 if (plen as i64) <= 0 { return 0 as *SgPlan }; if (rlen as i64) <= 0 { return 0 as *SgPlan }; if (mlen as i64) <= 0 { return 0 as *SgPlan }
2848 var end: i64 = scopy(path, tail, ".plan" as *u8); path[end] = 0 as u8
2849 let p: *u8 = sys_read_file(path, plen)
2850 if (p as i64) == 0 { return 0 as *SgPlan }
2851 end = scopy(path, tail, ".rank" as *u8); path[end] = 0 as u8
2852 let r: *u8 = sys_read_file(path, rlen)
2853 if (r as i64) == 0 { rlen[0] = 0 }
2854 end = scopy(path, tail, ".matrix" as *u8); path[end] = 0 as u8
2855 let x: *u8 = sys_read_file(path, mlen)
2856 if (x as i64) == 0 { mlen[0] = 0 }
2857 return sg_parse(p, plen[0], r, rlen[0], x, mlen[0])
2858}
2859
2860// Growth projects the same borrowed plan capture; eligibility remains a separate unverified axis.
2861func sg_growth_json(g: *CgModel,fd: i64) -> i64 {
2862 if (g as i64)<=0 { w(fd,"null" as *u8); return 0 }
2863 // Six bytes is JSON's maximum one-input-byte escape (\\u00xx).
2864 // Fixed overhead is derived from the projection's complete literal inventory, once per possible row.
2865 let inventory: *u8="\"nx_compare_growth_lib_20260910.nx\",:{}[]\"json_emit.nx\",:{}[]\"id\",:{}[]\"rung_id\",:{}[]\"entry_basis\",:{}[]\"target_id\",:{}[]\"research_refs_authored\",:{}[]\"learned_model_authored\",:{}[]\"questions_authored\",:{}[]\"path_id\",:{}[]\"prerequisite_exercises_authored\",:{}[]\"contract_symbol_authored\",:{}[]\"tool_or_api_ref_authored\",:{}[]\"workload_ref_authored\",:{}[]\"resource_ref_authored\",:{}[]\"acceptance_ref_authored\",:{}[]\"failure_next_authored\",:{}[]\"path_id\",:{}[]\"scope_authored\",:{}[]\"asserted_stage\",:{}[]\"evidence_refs_authored\",:{}[]\"assessed_unix_text\",:{}[]\"assessor_ref_authored\",:{}[]\"supersedes_assessment_id_authored\",:{}[]\"evidence_validated_stage\",:{}[]\"evidence_verified\",:{}[]\"evidence_age_seconds\",:{}[]\"investment_observed\",:{}[]\"investment_uncertainty\",:{}[]\"reference_resolution\",:{}[]\"local_graph_only_external_refs_unresolved\",:{}[]\"v\",:{}[]\"status\",:{}[]\"invalid_authored_growth\",:{}[]\"not_declared\",:{}[]\"authored_graph_valid\",:{}[]\"code\",:{}[]\"error_growth_row\",:{}[]\"scope\",:{}[]\"authored_growth_graph_not_behavior_or_mastery\",:{}[]\"paths\",:{}[]\"exercises\",:{}[]\"assessments\",:{}[]" as *u8
2866 let fixed: i64=bf_slen(inventory)
2867 if g.count>=SGP_I64_MAX/fixed-1 { w(fd,"{\"v\":1,\"status\":\"projection_unavailable\",\"code\":-2}" as *u8); return 0 }
2868 let structural: i64=(g.count+1)*fixed
2869 if g.n>(SGP_I64_MAX-structural-1)/6 { w(fd,"{\"v\":1,\"status\":\"projection_unavailable\",\"code\":-2}" as *u8); return 0 }
2870 let capacity: i64=g.n*6+structural
2871 let out: *u8=sys_mmap(capacity+1)
2872 if (out as i64)<=0 { w(fd,"{\"v\":1,\"status\":\"projection_unavailable\",\"code\":-2}" as *u8); return 0 }
2873 let n: i64=cg_json_into(g,out,capacity)
2874 if n<0 { w(fd,"{\"v\":1,\"status\":\"projection_unavailable\",\"code\":-2}" as *u8) } else { out[n]=0 as u8; w(fd,out) }
2875 sys_munmap(out,capacity+1); return n
2876}
2877func sg_growth_text(g: *CgModel,row: i64,col: i64,fd: i64) -> i64 {
2878 var offset: i64=0; let n: i64=cg_field(g,row,col,&offset)
2879 if n<0 { w(fd,"[field unavailable]" as *u8); return 0 }
2880 let text: *u8=sys_mmap(n+1)
2881 if (text as i64)<=0 { w(fd,"[field unavailable]" as *u8); return 0 }
2882 var i: i64=0; while i<n { text[i]=g.plan[offset+i]; i=i+1 }; text[n]=0 as u8
2883 sg_text(fd,text); sys_munmap(text,n+1); return n
2884}
2885func sg_growth_detail(g: *CgModel,row: i64,col: i64,label: *u8,fd: i64) -> i64 {
2886 w(fd,"<dt>" as *u8); w(fd,label); w(fd,"</dt><dd>" as *u8); sg_growth_text(g,row,col,fd); w(fd,"</dd>" as *u8); return 0
2887}
2888func sg_growth_html(g: *CgModel,fd: i64,heading: i64) -> i64 {
2889 w(fd,"<section class='capability-growth' aria-label='Learning and practice paths'>" as *u8)
2890 sc_heading_open(fd,heading,"" as *u8); w(fd,"Learning and practice paths" as *u8); sc_heading_close(fd,heading)
2891 if (g as i64)<=0 { w(fd,"<p>Growth capture unavailable.</p></section>" as *u8); return 0 }
2892 if g.error!=0 {
2893 w(fd,"<p>Invalid authored growth data. Error " as *u8); wn(fd,g.error); w(fd," at growth row " as *u8); wn(fd,g.error_row)
2894 w(fd,". Path details withheld; existing capability evidence retains its own scope.</p></section>" as *u8); return 0
2895 }
2896 if g.count==0 { w(fd,"<p>No structured learning path is declared for this plan. Existing research, roadmap and worklog remain available above.</p></section>" as *u8); return 0 }
2897 w(fd,"<p>Paths can begin with proactive research, an observed failure or an operator target. Prerequisites below are authored and structurally checked; execution readiness, evidence validity and investment remain unknown. An asserted stage does not establish mastery or innovation.</p>" as *u8)
2898 var p: i64=0
2899 while p<g.count {
2900 if g.rows[p*CG_ROW_WORDS]==CG_PATH {
2901 w(fd,"<details><summary>Path " as *u8); sg_growth_text(g,p,2,fd); w(fd," for rung " as *u8); sg_growth_text(g,p,3,fd); w(fd,"</summary><dl>" as *u8)
2902 sg_growth_detail(g,p,4,"Entry",fd); sg_growth_detail(g,p,5,"Target",fd); sg_growth_detail(g,p,6,"Research references (unresolved)",fd)
2903 sg_growth_detail(g,p,7,"Learned model (authored)",fd); sg_growth_detail(g,p,8,"Open questions",fd); w(fd,"</dl>" as *u8)
2904 w(fd,"<p><b>Practice exercises</b></p><ul>" as *u8)
2905 var e: i64=0; var exercises: i64=0
2906 while e<g.count {
2907 if g.rows[e*CG_ROW_WORDS]==CG_EXERCISE { if cg_same(g,e,3,p,2)==1 {
2908 exercises=exercises+1
2909 w(fd,"<li><details><summary>Exercise " as *u8); sg_growth_text(g,e,2,fd); w(fd," — readiness unverified</summary><dl>" as *u8)
2910 sg_growth_detail(g,e,4,"Declared prerequisites",fd); sg_growth_detail(g,e,5,"Capability contract",fd)
2911 sg_growth_detail(g,e,6,"Tool or API reference (unresolved)",fd); sg_growth_detail(g,e,7,"Workload reference",fd)
2912 sg_growth_detail(g,e,8,"Resource envelope reference",fd); sg_growth_detail(g,e,9,"Acceptance reference",fd)
2913 sg_growth_detail(g,e,10,"If practice fails",fd); w(fd,"</dl></details></li>" as *u8)
2914 } }
2915 e=e+1
2916 }
2917 w(fd,"</ul>" as *u8); if exercises==0 { w(fd,"<p>No practice exercise declared.</p>" as *u8) }
2918 w(fd,"<p><b>Assessment history</b></p><ul>" as *u8)
2919 var a: i64=0; var assessments: i64=0
2920 while a<g.count {
2921 if g.rows[a*CG_ROW_WORDS]==CG_ASSESSMENT { if cg_same(g,a,3,p,2)==1 {
2922 assessments=assessments+1
2923 w(fd,"<li><details><summary>Assessment " as *u8); sg_growth_text(g,a,2,fd); w(fd," — asserted " as *u8); sg_growth_text(g,a,5,fd)
2924 w(fd,"; evidence not validated</summary><dl>" as *u8)
2925 sg_growth_detail(g,a,4,"Scope",fd); sg_growth_detail(g,a,6,"Evidence references (unresolved)",fd)
2926 sg_growth_detail(g,a,7,"Authored assessment epoch",fd); sg_growth_detail(g,a,8,"Assessor reference",fd)
2927 sg_growth_detail(g,a,9,"Supersedes assessment",fd); w(fd,"</dl></details></li>" as *u8)
2928 } }
2929 a=a+1
2930 }
2931 w(fd,"</ul>" as *u8); if assessments==0 { w(fd,"<p>No assessment declared.</p>" as *u8) }
2932 w(fd,"<p>Verified stage: unknown. Observed investment and uncertainty: unknown. No dispatch recommendation is made.</p></details>" as *u8)
2933 }
2934 p=p+1
2935 }
2936 w(fd,"</section>" as *u8); return 0
2937}
2938
2939func sg_json(m: *SgPlan, fd: i64) -> i64 {
2940 w(fd, ",\"ladder\":{\"v\":1,\"availability\":" as *u8)
2941 if (m as i64) == 0 { w(fd, "\"UNAVAILABLE\"}" as *u8); return 0 }
2942 w(fd, "\"CAPTURED\"," as *u8); kv_s(fd, "plan_sha256" as *u8, m.plan_sha); wc(fd, 44); kv_n(fd, "plan_bytes" as *u8, m.plan_bytes)
2943 wc(fd, 44); kv_s(fd, "matrix_sha256" as *u8, m.matrix_sha); wc(fd, 44); kv_n(fd, "matrix_bytes" as *u8, m.matrix_bytes)
2944 wc(fd, 44); kv_s(fd, "rank_sha256" as *u8, m.rank_sha); wc(fd, 44); kv_n(fd, "rank_bytes" as *u8, m.rank_bytes)
2945 wc(fd, 44); kv_s(fd, "rank_binding" as *u8, sg_rank_state(m)); wc(fd, 44); kv_n(fd, "rank_declared_nodes" as *u8, m.rank_count)
2946 wc(fd, 44); kv_n(fd, "rank_symbol_or_shape_errors" as *u8, m.rank_mismatches)
2947 wc(fd, 44); kv_n(fd, "declared_nodes" as *u8, m.declared); wc(fd, 44); kv_n(fd, "parsed_nodes" as *u8, m.count)
2948 wc(fd, 44); kv_n(fd, "declared_graph_valid" as *u8, sg_valid(m))
2949 wc(fd, 44); kv_n(fd, "malformed" as *u8, m.malformed); wc(fd, 44); kv_n(fd, "duplicate_ids" as *u8, m.duplicate_ids)
2950 wc(fd, 44); kv_n(fd, "duplicate_dependencies" as *u8, m.duplicate_edges); wc(fd, 44); kv_n(fd, "missing_dependencies" as *u8, m.missing_deps)
2951 wc(fd, 44); kv_n(fd, "cyclic_or_cycle_dependent_nodes" as *u8, m.cyclic_nodes)
2952 wc(fd, 44); kv_n(fd, "target_rows" as *u8, m.target_rows); wc(fd, 44); kv_n(fd, "role_rows" as *u8, m.role_rows)
2953 wc(fd, 44); kv_n(fd, "unprojected_risk_rows" as *u8, m.risk_rows); wc(fd, 44); kv_n(fd, "worklog_rows" as *u8, m.log_rows)
2954 w(fd, ",\"defaults\":{\"implementation\":\"UNKNOWN\",\"verification\":\"UNVERIFIED\",\"eligibility\":\"UNVERIFIED\",\"target_binding\":\"UNVERIFIED\",\"responsible\":null,\"accountable\":null,\"verifier\":null},\"eligible_now\":[],\"eligible_set_complete\":false,\"recommended\":[],\"recommendation_state\":\"WITHHELD\",\"changed_since_supported\":false,\"next_cursor\":null,\"nodes\":[" as *u8)
2955 if sg_valid(m) == 1 {
2956 var i: i64 = 0
2957 while i < m.count {
2958 if i > 0 { wc(fd, 44) }; wc(fd, 123)
2959 kv_s(fd, "id" as *u8, m.nodes[i*SGP_FIELDS+1] as *u8); wc(fd, 44); kv_s(fd, "title" as *u8, m.nodes[i*SGP_FIELDS+2] as *u8)
2960 wc(fd, 44); kv_s(fd, "contract_symbol" as *u8, m.nodes[i*SGP_FIELDS+3] as *u8)
2961 wc(fd, 44); kv_s(fd, "acceptance_authored" as *u8, m.nodes[i*SGP_FIELDS+4] as *u8)
2962 wc(fd, 44); kv_s(fd, "executor_kind_authored" as *u8, m.nodes[i*SGP_FIELDS+5] as *u8)
2963 wc(fd, 44); kv_s(fd, "effort_authored" as *u8, m.nodes[i*SGP_FIELDS+6] as *u8)
2964 w(fd, ",\"forecast\":false,\"prerequisites\":[" as *u8)
2965 var e: i64 = 0; var shown: i64 = 0
2966 while e < m.edge_count {
2967 if m.edges[e*2+1] == i { if shown > 0 { wc(fd, 44) }; let from: i64 = m.edges[e*2]; wq(fd); wj(fd, m.nodes[from*SGP_FIELDS+1] as *u8); wq(fd); shown = shown + 1 }
2968 e = e + 1
2969 }
2970 w(fd, "]}" as *u8); i = i + 1
2971 }
2972 }
2973 w(fd, "],\"capability_growth\":" as *u8); sg_growth_json(m.growth, fd)
2974 w(fd, "}" as *u8); return 0
2975}
2976// Literal authored fields use the existing text escaper; citation expansion is not needed here.
2977func sg_text(fd: i64, s: *u8) -> i64 {
2978 let n: i64 = sg_len(s)
2979 if n > (SGP_I64_MAX - IA_SEP_AND_NUL) / IA_MAX_EXPANSION - 1 { w(fd, "[text unavailable]" as *u8); return 0 }
2980 let cap: i64 = (n + 1) * IA_MAX_EXPANSION + IA_SEP_AND_NUL
2981 let out: *u8 = sys_mmap(cap); let cut: *i64 = sys_mmap(8) as *i64
2982 if (out as i64) <= 0 { w(fd, "[text unavailable]" as *u8); return 0 }
2983 if (cut as i64) <= 0 { w(fd, "[text unavailable]" as *u8); return 0 }
2984 let written: i64 = ia_esc_text(out, 0, s, cap, cut)
2985 if cut[0] != 0 { w(fd, "[text unavailable]" as *u8); return 0 }
2986 w(fd, out); return written
2987}
2988func sg_html(m: *SgPlan, fd: i64) -> i64 { return sg_html_heading(m, fd, 2) }
2989func sg_html_heading(m: *SgPlan, fd: i64, heading_level: i64) -> i64 {
2990 w(fd, "<section class='ladder-model' aria-label='Declared prerequisite paths'>" as *u8); sc_heading_open(fd, heading_level, "" as *u8); w(fd, "Inspect a rung and its prerequisites" as *u8); sc_heading_close(fd, heading_level)
2991 if (m as i64) == 0 { w(fd, "<p>Plan unavailable; no path or eligibility can be established.</p></section>" as *u8); return 0 }
2992 w(fd, "<p>Declared nodes " as *u8); wn(fd, m.declared); w(fd, ". Rank input binding: <b>" as *u8); w(fd, sg_rank_state(m))
2993 w(fd, "</b>. Dependency order is authored. Implementation, acceptance evidence, authority and resource readiness are unverified. No action is recommended or dispatched here.</p><p>Plan SHA-256 <code>" as *u8); w(fd, m.plan_sha); w(fd, "</code>. Target rows " as *u8); wn(fd, m.target_rows)
2994 w(fd, "; role rows " as *u8); wn(fd, m.role_rows); w(fd, ". Existing risks and release worklog retain their own scope; no node completion is inferred.</p>" as *u8)
2995 if sg_valid(m) == 0 {
2996 w(fd, "<p><b>Invalid declared graph.</b> Malformed rows or IDs " as *u8); wn(fd, m.malformed); w(fd, "; duplicate IDs " as *u8); wn(fd, m.duplicate_ids)
2997 w(fd, "; duplicate prerequisites " as *u8); wn(fd, m.duplicate_edges); w(fd, "; missing prerequisites " as *u8); wn(fd, m.missing_deps)
2998 w(fd, "; cyclic or cycle-dependent nodes " as *u8); wn(fd, m.cyclic_nodes); w(fd, ". Node paths withheld.</p></section>" as *u8)
2999 sg_growth_html(m.growth, fd, heading_level)
3000 return 0
3001 }
3002 w(fd, "<p>Use Enter or Space on a rung to inspect its contract. Prerequisite links locate another rung in this list; open its summary to inspect it. Estimates are authored effort, not forecasts.</p><ol class='ladder-nodes'>" as *u8)
3003 var i: i64 = 0
3004 while i < m.count {
3005 let id: *u8 = m.nodes[i*SGP_FIELDS+1] as *u8
3006 w(fd, "<li><details id='ladder-node-" as *u8); w(fd, id); w(fd, "'><summary>" as *u8); w(fd, id); w(fd, " — " as *u8); sg_text(fd, m.nodes[i*SGP_FIELDS+2] as *u8)
3007 w(fd, "</summary><p><b>Prerequisites:</b> " as *u8)
3008 var e: i64 = 0; var shown: i64 = 0
3009 while e < m.edge_count {
3010 if m.edges[e*2+1] == i {
3011 let from: i64 = m.edges[e*2]; let dep: *u8 = m.nodes[from*SGP_FIELDS+1] as *u8
3012 if shown > 0 { w(fd, ", " as *u8) }; w(fd, "<a href='#ladder-node-" as *u8); w(fd, dep); w(fd, "'>" as *u8); w(fd, dep); w(fd, "</a> (acceptance unverified)" as *u8); shown = shown + 1
3013 }; e = e + 1
3014 }
3015 if shown == 0 { w(fd, "None declared; this does not establish execution eligibility." as *u8) }
3016 w(fd, "</p><p><b>Contract:</b> <code>" as *u8); sg_text(fd, m.nodes[i*SGP_FIELDS+3] as *u8); w(fd, "</code></p><p><b>Acceptance:</b> " as *u8); sg_text(fd, m.nodes[i*SGP_FIELDS+4] as *u8)
3017 w(fd, "</p><p><b>Authored effort:</b> " as *u8); sg_text(fd, m.nodes[i*SGP_FIELDS+6] as *u8); w(fd, ". <b>Executor kind:</b> " as *u8); sg_text(fd, m.nodes[i*SGP_FIELDS+5] as *u8)
3018 w(fd, ". Responsible, accountable and verifier not established. <a href='#worklog'>Inspect retained worklog</a>.</p></details></li>" as *u8); i = i + 1
3019 }
3020 w(fd, "</ol></section>" as *u8)
3021 sg_growth_html(m.growth, fd, heading_level)
3022 return 0
3023}
3024func sg_css(fd: i64) -> i64 {
3025 w(fd, ".capability-growth{min-width:0}.capability-growth details{display:block}.capability-growth summary{display:list-item;cursor:pointer;list-style:revert;font-size:1rem;line-height:1.5}.capability-growth details summary::after,.capability-growth details[open] summary::after{content:none}.capability-growth summary:focus-visible{outline:3px solid var(--ac);outline-offset:2px}.capability-growth p{max-width:var(--nx-layout-measure)}.capability-growth dd{margin-inline-start:0;overflow-wrap:anywhere}.capability-growth dt{font-weight:600}.capability-growth dl{display:grid;grid-template-columns:minmax(0,1fr);gap:var(--nx-layout-capgap)}.capability-growth ul{padding-inline-start:1.5em}" as *u8)
3026 w(fd, ".ladder-model{min-width:0}.ladder-model p{max-width:var(--nx-layout-measure)}.ladder-model code{overflow-wrap:anywhere}.ladder-nodes{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,var(--nx-layout-capmin)),1fr));gap:var(--nx-layout-capgap);padding-inline-start:1.5em}.ladder-nodes li{min-width:0}.ladder-nodes details{display:block}.ladder-nodes summary{display:list-item;cursor:pointer;list-style:revert;font-size:1rem;line-height:1.5}.ladder-nodes summary::after{content:none}.ladder-nodes summary:focus-visible,.ladder-nodes a:focus-visible{outline:3px solid var(--ac);outline-offset:2px}.ladder-nodes details:target{outline:2px solid var(--ac);outline-offset:4px}\n" as *u8)
3027 return 0
3028}
3029
3030// Snapshot projection consumes the existing collector's summary; it never remeasures evidence.
3031// Token grammar is caller-owned as specified by nx_json.nx. Working storage derives from input bytes.
3032import "nx_json.nx"
3033import "nx_json_lib.nx"
3034struct EfsDoc { src: *u8, len: i64, tokens: *i64, count: i64, error: i64 }
3035const EFS_DOC_BYTES: i64=40
3036const EFS_TOKEN_WORDS: i64=4
3037const EFS_KEY: i64=14
3038func efs_free(d: *EfsDoc) -> i64 {
3039 if (d as i64)<=0 { return 0 }
3040 if (d.tokens as i64)>0 { sys_munmap(d.tokens as *u8,d.len*EFS_TOKEN_WORDS*8) }
3041 return sys_munmap(d as *u8,EFS_DOC_BYTES)
3042}
3043func efs_parse(src: *u8,n: i64) -> *EfsDoc {
3044 let d: *EfsDoc=sys_mmap(EFS_DOC_BYTES) as *EfsDoc
3045 if (d as i64)<=0 { return 0 as *EfsDoc }
3046 d.src=src;d.len=n;d.error=1
3047 if (src as i64)<=0 { return d };if n<=0 { return d };if n>SGP_I64_MAX/(EFS_TOKEN_WORDS*8) { return d }
3048 d.tokens=sys_mmap(n*EFS_TOKEN_WORDS*8) as *i64
3049 if (d.tokens as i64)<=0 { d.tokens=0 as *i64;return d }
3050 let stack: *i64=sys_mmap(n*16) as *i64
3051 if (stack as i64)<=0 { return d }
3052 let t: *NxJsonTok=nx_json_new(src,n)
3053 if (t as i64)<=0 { sys_munmap(stack as *u8,n*16);return d }
3054 var depth: i64=0;var started: i64=0;var bad: i64=0;var done: i64=0
3055 while done==0 {
3056 var k: i64=nx_json_next(t)
3057 if k==NX_JSON_ERROR { bad=1;break }
3058 if k==NX_JSON_EOF { if depth!=0 { bad=1 };if started==0 { bad=1 };break }
3059 var record: i64=0;var push: i64=0;var parent: i64=0-1
3060 if depth==0 {
3061 if started==1 { bad=1;break }
3062 if k!=NX_JSON_LBRACE { bad=1;break }
3063 started=1;record=1;push=1
3064 } else {
3065 let frame: i64=(depth-1)*2;let state: i64=stack[frame];parent=stack[frame+1]
3066 if state==0 || state==4 {
3067 if k==NX_JSON_RBRACE && state==0 { depth=depth-1 } else {
3068 if k!=NX_JSON_STRING { bad=1;break }
3069 k=EFS_KEY;record=1;stack[frame]=1
3070 }
3071 } else { if state==1 {
3072 if k!=NX_JSON_COLON { bad=1;break };stack[frame]=2
3073 } else { if state==3 || state==11 {
3074 var close: i64=NX_JSON_RBRACE;if state==11 { close=NX_JSON_RBRACKET }
3075 if k==close { depth=depth-1 } else {
3076 if k!=NX_JSON_COMMA { bad=1;break }
3077 if state==3 { stack[frame]=4 } else { stack[frame]=12 }
3078 }
3079 } else {
3080 if state==10 && k==NX_JSON_RBRACKET { depth=depth-1 } else {
3081 if k==NX_JSON_LBRACE { push=1 } else { if k==NX_JSON_LBRACKET { push=10 } else {
3082 if k!=NX_JSON_STRING && k!=NX_JSON_NUMBER && k!=NX_JSON_TRUE && k!=NX_JSON_FALSE && k!=NX_JSON_NULL { bad=1;break }
3083 } }
3084 record=1;if state==2 { stack[frame]=3 } else { stack[frame]=11 }
3085 }
3086 } } }
3087 }
3088 if record==1 {
3089 let at: i64=d.count*EFS_TOKEN_WORDS
3090 d.tokens[at]=k;d.tokens[at+1]=t.tok_off;d.tokens[at+2]=t.tok_len;d.tokens[at+3]=parent
3091 if push>0 {
3092 if depth>=n { bad=1;break }
3093 if push==1 { stack[depth*2]=0 } else { stack[depth*2]=10 }
3094 stack[depth*2+1]=d.count;depth=depth+1
3095 }
3096 d.count=d.count+1
3097 }
3098 }
3099 sys_munmap(t as *u8,NX_JSONTOK_BYTES);sys_munmap(stack as *u8,n*16)
3100 if bad==0 { d.error=0 };return d
3101}
3102func efs_equal(d: *EfsDoc,idx: i64,s: *u8) -> i64 {
3103 if idx<0 || idx>=d.count { return 0 }
3104 let b: i64=idx*EFS_TOKEN_WORDS;let cap: i64=d.tokens[b+2]+1
3105 let decoded: *u8=sys_mmap(cap);if (decoded as i64)<=0 { return 0 }
3106 let end: i64=jx_copy_str_argv(d.src,d.len,d.tokens[b+1]+1,decoded,cap)
3107 var equal: i64=0;if end>=0 { equal=streq(decoded,s) }
3108 sys_munmap(decoded,cap);return equal
3109}
3110// A duplicate required member refuses the projection instead of selecting a flattering copy.
3111func efs_get(d: *EfsDoc,parent: i64,key: *u8) -> i64 {
3112 var hit: i64=0-1;var i: i64=0
3113 while i<d.count {
3114 let b: i64=i*EFS_TOKEN_WORDS
3115 if d.tokens[b]==EFS_KEY && d.tokens[b+3]==parent { if efs_equal(d,i,key)==1 {
3116 if hit>=0 { return 0-2 };hit=i+1
3117 } };i=i+1
3118 };return hit
3119}
3120func efs_kind(d: *EfsDoc,i: i64) -> i64 { if i<0 || i>=d.count { return 0 };return d.tokens[i*EFS_TOKEN_WORDS] }
3121func efs_int(d: *EfsDoc,i: i64) -> i64 {
3122 if efs_kind(d,i)!=NX_JSON_NUMBER { return 0-1 }
3123 let b: i64=i*EFS_TOKEN_WORDS;let p: i64=d.tokens[b+1];let n: i64=d.tokens[b+2]
3124 var v: i64=0;var j: i64=0
3125 while j<n { let c: i64=d.src[p+j] as i64;if c<48 || c>57 { return 0-1 };let digit: i64=c-48
3126 if v>(SGP_I64_MAX-digit)/10 { return 0-1 };v=v*10+digit;j=j+1
3127 };return v
3128}
3129func efs_number(d: *EfsDoc,parent: i64,key: *u8) -> i64 { return efs_int(d,efs_get(d,parent,key)) }
3130func efs_string(d: *EfsDoc,i: i64) -> *u8 {
3131 if efs_kind(d,i)!=NX_JSON_STRING { return 0 as *u8 }
3132 let b: i64=i*EFS_TOKEN_WORDS;let cap: i64=d.tokens[b+2]+1
3133 let s: *u8=sys_mmap(cap);if (s as i64)<=0 { return 0 as *u8 }
3134 if jx_copy_str_argv(d.src,d.len,d.tokens[b+1]+1,s,cap)<0 { sys_munmap(s,cap);return 0 as *u8 };return s
3135}
3136func efs_print_string(d: *EfsDoc,i: i64,fd: i64) -> i64 {
3137 let s: *u8=efs_string(d,i);if (s as i64)<=0 { return 0-1 }
3138 sg_text(fd,s);return sys_munmap(s,d.tokens[i*EFS_TOKEN_WORDS+2]+1)
3139}
3140
3141func efs_validate(d: *EfsDoc) -> i64 {
3142 if (d as i64)<=0 { return 1 };if d.error!=0 { return 2 }
3143 let schema: i64=efs_get(d,0,"schema" as *u8)
3144 if efs_kind(d,schema)!=NX_JSON_STRING || efs_equal(d,schema,"estate-evidence-progression/v1" as *u8)==0 { return 3 }
3145 let summary: i64=efs_get(d,0,"summary" as *u8)
3146 if efs_kind(d,summary)!=NX_JSON_LBRACE { return 3 }
3147 if efs_kind(d,efs_get(d,0,"rows" as *u8))!=NX_JSON_LBRACKET { return 3 }
3148 if efs_kind(d,efs_get(d,0,"enumeration_complete" as *u8))!=NX_JSON_TRUE { return 4 }
3149 if efs_kind(d,efs_get(d,summary,"partition_reconciles" as *u8))!=NX_JSON_TRUE { return 4 }
3150 if efs_kind(d,efs_get(d,0,"freshness_policy" as *u8))!=NX_JSON_NULL { return 3 }
3151 if efs_kind(d,efs_get(d,0,"matrix_scope" as *u8))!=NX_JSON_STRING { return 3 }
3152 if efs_kind(d,efs_get(d,0,"gate_scope" as *u8))!=NX_JSON_STRING { return 3 }
3153 if efs_kind(d,efs_get(d,0,"stamp_scope" as *u8))!=NX_JSON_STRING { return 3 }
3154 if efs_kind(d,efs_get(d,0,"artifact_binding" as *u8))!=NX_JSON_STRING { return 3 }
3155 if efs_kind(d,efs_get(d,0,"served_acceptance" as *u8))!=NX_JSON_STRING { return 3 }
3156 let total: i64=efs_number(d,summary,"eligible_matrix_domains" as *u8)
3157 if total<0 { return 3 }
3158 if efs_number(d,summary,"eligible_matrix_domains" as *u8)<0 || efs_number(d,summary,"eligible_matrix_domains" as *u8)>total { return 4 }
3159 if efs_number(d,summary,"gate_declared_domains" as *u8)<0 || efs_number(d,summary,"gate_declared_domains" as *u8)>total { return 4 }
3160 if efs_number(d,summary,"gate_declaration_unknown" as *u8)<0 || efs_number(d,summary,"gate_declaration_unknown" as *u8)>total { return 4 }
3161 if efs_number(d,summary,"matrix_unknown" as *u8)<0 || efs_number(d,summary,"matrix_unknown" as *u8)>total { return 4 }
3162 if efs_number(d,summary,"retained_stamp_valid" as *u8)<0 || efs_number(d,summary,"retained_stamp_valid" as *u8)>total { return 4 }
3163 if efs_number(d,summary,"retained_stamp_missing" as *u8)<0 || efs_number(d,summary,"retained_stamp_missing" as *u8)>total { return 4 }
3164 if efs_number(d,summary,"retained_stamp_invalid" as *u8)<0 || efs_number(d,summary,"retained_stamp_invalid" as *u8)>total { return 4 }
3165 if efs_number(d,summary,"retained_stamp_unreadable" as *u8)<0 || efs_number(d,summary,"retained_stamp_unreadable" as *u8)>total { return 4 }
3166 if efs_number(d,summary,"recorded_execution_domains" as *u8)<0 || efs_number(d,summary,"recorded_execution_domains" as *u8)>total { return 4 }
3167 if efs_number(d,summary,"recorded_all_green_domains" as *u8)<0 || efs_number(d,summary,"recorded_all_green_domains" as *u8)>total { return 4 }
3168 if efs_number(d,summary,"current_artifact_binding_unknown" as *u8)<0 || efs_number(d,summary,"current_artifact_binding_unknown" as *u8)>total { return 4 }
3169
3170 var remainder: i64=total
3171 let valid: i64=efs_number(d,summary,"retained_stamp_valid" as *u8)
3172 remainder=remainder-valid
3173 remainder=remainder-efs_number(d,summary,"retained_stamp_missing" as *u8)
3174 if remainder<0 { return 4 }
3175 remainder=remainder-efs_number(d,summary,"retained_stamp_invalid" as *u8)
3176 if remainder<0 { return 4 }
3177 remainder=remainder-efs_number(d,summary,"retained_stamp_unreadable" as *u8)
3178 if remainder!=0 { return 4 }
3179 let runs: i64=efs_number(d,summary,"recorded_execution_domains" as *u8)
3180 if runs>valid || efs_number(d,summary,"recorded_all_green_domains" as *u8)>runs { return 4 }
3181 if efs_number(d,summary,"gate_declaration_unknown" as *u8)>total-efs_number(d,summary,"gate_declared_domains" as *u8) { return 4 }
3182 let first: i64=efs_number(d,0,"observed_start_epoch" as *u8)
3183 let last: i64=efs_number(d,0,"observed_end_epoch" as *u8)
3184 if first<0 || last<first { return 5 }
3185 let lo: i64=efs_get(d,summary,"age_min_seconds" as *u8);let hi: i64=efs_get(d,summary,"age_max_seconds" as *u8)
3186 if efs_kind(d,lo)==NX_JSON_NULL && efs_kind(d,hi)==NX_JSON_NULL { return 0 }
3187 if efs_int(d,lo)<0 || efs_int(d,hi)<efs_int(d,lo) { return 5 }
3188 return 0
3189}
3190func efs_metric(d: *EfsDoc,summary: i64,key: *u8,label: *u8,meaning: *u8,fd: i64) -> i64 {
3191 w(fd,"<tr><th scope='row'>" as *u8);sg_text(fd,label);w(fd,"</th><td>" as *u8)
3192 wn(fd,efs_number(d,summary,key));w(fd," / " as *u8);wn(fd,efs_number(d,summary,"eligible_matrix_domains" as *u8))
3193 w(fd," files</td><td>" as *u8);sg_text(fd,meaning);w(fd,"</td></tr>" as *u8);return 0
3194}
3195func efs_html(d: *EfsDoc,fd: i64,heading: i64,path: *u8,hash: *u8) -> i64 {
3196 let valid: i64=efs_validate(d)
3197 if valid!=0 { w(fd,"<p>Evidence snapshot unavailable: invalid document or schema, code " as *u8);wn(fd,valid);w(fd,". No measurements inferred.</p>" as *u8);return valid }
3198 let summary: i64=efs_get(d,0,"summary" as *u8)
3199 w(fd,"<section class='evidence-snapshot'><style>.exec-grid>.evidence-snapshot{grid-column:1/-1}.evidence-snapshot{min-width:0;overflow-wrap:anywhere}.evidence-snapshot .plan-table-scroll>table{min-width:0;width:100%;table-layout:fixed}.evidence-snapshot caption{text-align:left;font-weight:600;padding-block:.5em}.evidence-snapshot th,.evidence-snapshot td{white-space:normal;overflow-wrap:anywhere}.evidence-snapshot dd{margin-inline-start:0}.foot{overflow-wrap:anywhere}@media(max-width:" as *u8);wn(fd,SC_BP_SM)
3200 w(fd,"px){.evidence-snapshot .plan-table-scroll{overflow:visible}.evidence-snapshot table,.evidence-snapshot caption,.evidence-snapshot tbody,.evidence-snapshot tr,.evidence-snapshot th,.evidence-snapshot td{display:block;width:auto;max-width:100%;min-width:0}.evidence-snapshot thead{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}.evidence-snapshot tr{border:1px solid var(--line);border-radius:.5em;margin-block:.75em;padding:.75em}.evidence-snapshot th,.evidence-snapshot td{border:0;padding:.25em 0}.evidence-snapshot th{font-size:1rem;text-align:left}.evidence-snapshot td:nth-child(2)::before{content:'Count / eligible files: ';font-weight:600}.evidence-snapshot td:nth-child(3)::before{content:'Meaning: ';font-weight:600}}</style>" as *u8)
3201 sc_heading_open(fd,heading,"" as *u8);w(fd,"Estate evidence measurements" as *u8);sc_heading_close(fd,heading)
3202 w(fd,"<p>Scope: every matrix file in <code>" as *u8);efs_print_string(d,efs_get(d,0,"matrix_scope" as *u8),fd)
3203 w(fd,"</code>, including candidates and fixtures. This is a directory population, not a count of registered products.</p>" as *u8)
3204 sc_plan_table_open(fd,"Estate evidence measurements" as *u8)
3205 w(fd,"<caption>Estate evidence measurements</caption><thead><tr><th>Measure</th><th>Count / eligible files</th><th>Meaning and limits</th></tr></thead><tbody>" as *u8)
3206 efs_metric(d,summary,"gate_declared_domains" as *u8,"Gate declarations" as *u8,"Files with syntactic gate declarations; execution is not implied." as *u8,fd)
3207 efs_metric(d,summary,"retained_stamp_valid" as *u8,"Coherent retained records" as *u8,"Structurally valid historical verdict records; current artifacts are unbound." as *u8,fd)
3208 efs_metric(d,summary,"retained_stamp_missing" as *u8,"Missing records" as *u8,"No verdict file in the explicitly selected stamp directory." as *u8,fd)
3209 efs_metric(d,summary,"recorded_execution_domains" as *u8,"Recorded execution" as *u8,"Retained record reports one or more runs; not current acceptance." as *u8,fd)
3210 efs_metric(d,summary,"recorded_all_green_domains" as *u8,"Recorded all-green runs" as *u8,"Historical record only; not proof that the current artifact passes." as *u8,fd)
3211 efs_metric(d,summary,"current_artifact_binding_unknown" as *u8,"Current artifact binding unknown" as *u8,"No retained source/artifact binding in this collector schema." as *u8,fd)
3212 efs_metric(d,summary,"matrix_unknown" as *u8,"Matrix format unknown" as *u8,"Files with unrecognized matrix rows; not a product failure count." as *u8,fd)
3213
3214 sc_plan_table_close(fd)
3215 w(fd,"<dl><dt>Unknown gate declarations</dt><dd>" as *u8);wn(fd,efs_number(d,summary,"gate_declaration_unknown" as *u8))
3216 w(fd,"</dd><dt>Invalid / unreadable retained records</dt><dd>" as *u8);wn(fd,efs_number(d,summary,"retained_stamp_invalid" as *u8));w(fd," / " as *u8);wn(fd,efs_number(d,summary,"retained_stamp_unreadable" as *u8))
3217 w(fd,"</dd><dt>Evidence age at observation</dt><dd>" as *u8)
3218 let lo: i64=efs_get(d,summary,"age_min_seconds" as *u8)
3219 if efs_kind(d,lo)==NX_JSON_NULL { w(fd,"Unknown: no age range retained" as *u8) } else {
3220 wn(fd,efs_int(d,lo));w(fd," to " as *u8);wn(fd,efs_number(d,summary,"age_max_seconds" as *u8));w(fd," seconds" as *u8)
3221 }
3222 w(fd,". No freshness cutoff applied.</dd><dt>Observation window (Unix seconds)</dt><dd>" as *u8)
3223 wn(fd,efs_number(d,0,"observed_start_epoch" as *u8));w(fd," to " as *u8);wn(fd,efs_number(d,0,"observed_end_epoch" as *u8))
3224 w(fd,"</dd><dt>Gate / verdict scope</dt><dd><code>" as *u8);efs_print_string(d,efs_get(d,0,"gate_scope" as *u8),fd)
3225 w(fd,"</code> / <code>" as *u8);efs_print_string(d,efs_get(d,0,"stamp_scope" as *u8),fd)
3226 w(fd,"</code></dd><dt>Current artifact binding</dt><dd>" as *u8);efs_print_string(d,efs_get(d,0,"artifact_binding" as *u8),fd)
3227 w(fd,"</dd><dt>Served acceptance in this snapshot</dt><dd>" as *u8);efs_print_string(d,efs_get(d,0,"served_acceptance" as *u8),fd)
3228 w(fd,"</dd><dt>Retained evidence</dt><dd style='overflow-wrap:anywhere'><code>" as *u8);sg_text(fd,path)
3229 w(fd,"</code><br>SHA256 <code>" as *u8);sg_text(fd,hash);w(fd,"</code></dd></dl></section>" as *u8)
3230 return 0
3231}
3232
3233import "nx_fio.nx"
3234func efs_capture(path: *u8,expected: *u8,r: *NxFileReadRegion) -> *u8 {
3235 fio_region_init(r)
3236 if sg_len(expected)!=64 { r.code=FIO_EINVAL;return 0 as *u8 }
3237 if fio_region_open(path,r)!=0 { return 0 as *u8 }
3238 let n: i64=r.total
3239 if n<=0 || n>=SGP_I64_MAX { fio_region_fail(r,"extent",FIO_EINVAL);return 0 as *u8 }
3240 let body: *u8=sys_mmap(n+1)
3241 if (body as i64)<=0 { fio_region_fail(r,"allocation",0-12);return 0 as *u8 }
3242 var offset: i64=0
3243 while offset<n {
3244 let got: i64=fio_region_next(r,(body as i64+offset) as *u8,n-offset)
3245 if got<=0 { break };offset=offset+got
3246 }
3247 fio_region_close(r)
3248 if r.code!=0 || offset!=n { sys_munmap(body,n+1);if r.code==0 { r.code=FIO_EIO };return 0 as *u8 }
3249 let digest: *u8=sys_mmap(32)
3250 if (digest as i64)<=0 { sys_munmap(body,n+1);r.code=0-12;return 0 as *u8 }
3251 sha256_digest(body,n,digest)
3252 let hex: *u8="0123456789abcdef" as *u8;var i: i64=0;var same: i64=1
3253 while i<32 {
3254 let v: i64=digest[i] as i64
3255 if expected[i*2]!=hex[v/16] || expected[i*2+1]!=hex[v%16] { same=0 };i=i+1
3256 }
3257 sys_munmap(digest,32)
3258 if same==0 { sys_munmap(body,n+1);r.code=FIO_EBADMSG;return 0 as *u8 }
3259 body[n]=0 as u8;return body
3260}
3261func efs_render(path: *u8,expected: *u8,heading: i64,fd: i64) -> i64 {
3262 let r: *NxFileReadRegion=sys_mmap(72) as *NxFileReadRegion
3263 if (r as i64)<=0 { w(fd,"<p>Evidence snapshot unavailable: allocation failed.</p>" as *u8);return 1 }
3264 let body: *u8=efs_capture(path,expected,r)
3265 if (body as i64)<=0 {
3266 w(fd,"<p>Evidence snapshot unavailable: read or identity check failed, code " as *u8);wn(fd,r.code)
3267 w(fd,". No measurements inferred.</p>" as *u8);sys_munmap(r as *u8,72);return 1
3268 }
3269 let d: *EfsDoc=efs_parse(body,r.total)
3270 let rc: i64=efs_html(d,fd,heading,path,expected)
3271 efs_free(d);sys_munmap(body,r.total+1);sys_munmap(r as *u8,72);return rc
3272}
3273// ---- THE POSITION MAP (2026-09-15): centrality vs distinctiveness from the matrix cells, with a day spine ----
3274// Operator: "a multi variable four quadrant visual ... where we are and our competitors and where we are moving as
3275// time goes on daily" and, the same day, "extensible as we get more and more variables ... a 3 dimensional x y z axis
3276// cube with a 2d cut and a 3d view". The RULER is nx_cdmap_lib (one arithmetic, an axis registry, the view conf and
3277// the isometric projection, all gated on planted tables); this pass only PROJECTS it: the 2D cut (any two axes; the
3278// HBR quadrant names when the cut is centrality by distinctiveness), the 3D cube (any three axes, isometric, every
3279// bubble dropped to the floor so depth reads), the values table over EVERY registered axis (a picture is never the
3280// only copy of a number), and the review log of days so the review's own breadth is visible as the matrix grows.
3281// The matrix generator passes the cells it just measured, so the map and the table cannot disagree; a domain with
3282// no rows emits nothing here, byte-identically. Views are DATA: knowledge/compare/<dom>.cdmap.
3283const CDP_CELL0: i64 = 4 // a matrix row is label|organ|symbol|exceed|cells...: the first rival cell
3284const CDP_SYM: i64 = 2 // the row's symbol field (the plan join for the substrate mask)
3285const CDP_PLAN_EXT: *u8 = ".plan"
3286const CDP_SVG_W: i64 = 760
3287const CDP_SVG_H: i64 = 520
3288const CDP_PAD_L: i64 = 70
3289const CDP_PAD_R: i64 = 30
3290const CDP_PAD_T: i64 = 30
3291const CDP_PAD_B: i64 = 60
3292const CDP_R_MIN: i64 = 6 // bubble radius floor (px); radius = floor + isqrt(breadth points)
3293const CDP_LABEL_DX: i64 = 10
3294const CDP_LABEL_DY: i64 = 4
3295const CDP_QLABEL_IN: i64 = 8
3296const CDP_QLABEL_UP: i64 = 16
3297const CDP_AXIS_DROP: i64 = 40
3298const CDP_AXIS_LEFT: i64 = 22
3299const CDP_TICK_DROP: i64 = 16
3300const CDP_LOG_SHOW: i64 = 14 // review-log days rendered (newest); earlier days are COUNTED
3301const CDP_ISO_W: i64 = 760
3302const CDP_ISO_H: i64 = 560
3303const CDP_ISO_OX: i64 = 380 // the floor's near corner (0,0,0) sits here...
3304const CDP_ISO_OY: i64 = 290 // ...so x runs right-down, y left-down, z straight up (raised 2026-09-15 for the 250 px unit)
3305const CDP_ISO_UNIT: i64 = 250 // pixels per 1000 permil on every cube axis (220 left a third of the canvas empty)
3306const CDP_ISO_LABEL_GAP: i64 = 14
3307const CDP_NISHI: *u8 = "Nishi"
3308const CDP_CH_HASH: i64 = 35 // '#' cannot sit inside a string literal (lexer); written as a byte
3309const CDP_CH_COMMA: i64 = 44
3310const CDP_CH_SPACE: i64 = 32
3311const CDP_CH_QUOTE: i64 = 39
3312const CDP_CH_COLON: i64 = 58
3313const CDP_CH_GT: i64 = 62
3314const CDP_CH_PLUS: i64 = 43
3315const CDP_CH_LBRACE: i64 = 123
3316const CDP_CH_RBRACE: i64 = 125
3317const CDP_CH_LBRACKET: i64 = 91
3318const CDP_CH_RBRACKET: i64 = 93
3319const CDP_DATE_CAP: i64 = 32
3320const CDP_XYZ: i64 = 3
3321func cdp_x(v: i64, dom: *i64) -> i64 { return cl_scale_dom(v, dom, CDP_PAD_L, CDP_SVG_W - CDP_PAD_R) }
3322func cdp_y(v: i64, dom: *i64) -> i64 { return cl_scale_dom(v, dom, CDP_SVG_H - CDP_PAD_B, CDP_PAD_T) }
3323func cdp_an(fd: i64, name: *u8, v: i64) -> i64 { wc(fd, CDP_CH_SPACE); w(fd, name); w(fd, "='" as *u8); wn(fd, v); wc(fd, CDP_CH_QUOTE); return 0 }
3324func cdp_mom_stroke(known: i64, mom: i64) -> *u8 {
3325 if known == 0 { return "rgb(140,140,140)" as *u8 }
3326 if mom > 0 { return "rgb(40,160,90)" as *u8 }
3327 if mom < 0 { return "rgb(200,60,60)" as *u8 }
3328 return "rgb(140,140,140)" as *u8
3329}
3330const CDP_TWO: i64 = 2
3331const CDP_CH_RPAREN: i64 = 41
3332const CDP_FONT_LABEL: i64 = 13
3333const CDP_FONT_TICK: i64 = 11
3334const CDP_FONT_QUAD: i64 = 11
3335const CDP_QUAD_N: i64 = 4 // the four HBR quadrant words, seated by the placer AFTER every label and note (2026-09-15)
3336const CDP_QUAD_W_PERMIL: i64 = 1300 // a quadrant word is uppercase with .12em tracking: its box is 1.3x the plain text width
3337const CDP_QUAD_BASE: i64 = 10 // text baseline inside an 11 px quadrant-word box
3338const CDP_CANVAS_IN: i64 = 2 // labels keep this many px inside the plot frame
3339const CDP_TICK_TEXT_DY: i64 = 15 // x tick numerals sit this far under the frame
3340const CDP_TICK_TEXT_DX: i64 = 6 // y tick numerals end this far left of the frame
3341const CDP_TICK_BASE: i64 = 4 // a numeral's baseline offset so it centres on its gridline
3342const CDP_MEAN_LABEL_DY: i64 = 12
3343const CDP_MEAN_LABEL_DX: i64 = 4
3344const CDP_LABEL_BASE: i64 = 12 // text baseline inside a 16 px label box at 13 px
3345const CDP_STROKE_W: i64 = 2
3346const CDP_NOTES_CAP: i64 = 16 // notes a board may pin on one cut (datavis DV5); the parser counts the rest as refused
3347const CDP_NOTE_CH: i64 = 26 // wrap width in characters at CDP_FONT_NOTE (a box about a quarter of the plot wide)
3348const CDP_NOTE_LINES: i64 = 4 // a note is at most four lines; a longer one is refused by name, never truncated
3349const CDP_FONT_NOTE: i64 = 11
3350const CDP_NOTE_PAD: i64 = 5 // px between a note box's edge and its text
3351const CDP_NOTE_DOT_R: i64 = 3 // the anchor dot of a point-pinned note
3352const CDP_NOTE_BASE: i64 = 9 // text baseline inside a note line at 11 px
3353const CDP_NOTE_STROKE: *u8 = "stroke='var(--nx-color-mut)' stroke-dasharray='2 2'"
3354const CDP_CH_SEMI: i64 = 59
3355const CDP_ISO_TICK_DX: i64 = 8
3356const CDP_ISO_TICK_DY: i64 = 14
3357const CDP_ISO_ZTICK_DX: i64 = 6
3358const CDP_ISO_ZTICK_DY: i64 = 4
3359const CDP_ISO_AXIS_GAP: i64 = 30
3360const CDP_SHADOW_R: i64 = 3
3361const CDP_LEG_SW: i64 = 12
3362// ---- the layout helpers (nx_chartlay_lib underneath): three domain records for the cube, fitted xyz, the svg shell, ticks, marks, halo labels, leaders, swatches, the grade ----
3363func cdp_dom3(domc: *i64, k: i64) -> *i64 { return (domc as i64 + k * CL_DOM_W * CD_I64_BYTES) as *i64 }
3364func cdp_fit3(sfit: *i64, p: i64) -> *i64 { return (sfit as i64 + p * CDP_XYZ * CD_I64_BYTES) as *i64 }
3365func cdp_iso_fit(xyz: *i64, domc: *i64, s: *i64) -> i64 { var k: i64 = 0; while k < CDP_XYZ { s[k] = cl_scale_dom(xyz[k], cdp_dom3(domc, k), 0, CD_PERMIL); k = k + 1 } return 0 }
3366func cdp_fig_open(fd: i64, cls: *u8, wd: i64, ht: i64, title: *u8, desc: *u8) -> i64 {
3367 w(fd, "<figure class='cdfig' style='margin:1rem 0;max-width:" as *u8); wn(fd, wd); w(fd, "px'><svg class='" as *u8); w(fd, cls); w(fd, "' viewBox='0 0 " as *u8); wn(fd, wd); wc(fd, CDP_CH_SPACE); wn(fd, ht)
3368 w(fd, "' width='100%' style='height:auto;display:block' role='img' aria-labelledby='" as *u8); w(fd, cls); w(fd, "-title " as *u8); w(fd, cls); w(fd, "-desc' font-family='system-ui,-apple-system,Segoe UI,Roboto,sans-serif'>\n<title id='" as *u8); w(fd, cls); w(fd, "-title'>" as *u8); wnote(fd, title); w(fd, "</title><desc id='" as *u8); w(fd, cls); w(fd, "-desc'>" as *u8); wnote(fd, desc); w(fd, "</desc>\n" as *u8)
3369 return 0
3370}
3371func cdp_tick_text(fd: i64, x: i64, y: i64, extra: *u8, v: i64) -> i64 { w(fd, "<text" as *u8); cdp_an(fd, "x" as *u8, x); cdp_an(fd, "y" as *u8, y); w(fd, " fill='var(--nx-color-mut)' font-size='" as *u8); wn(fd, CDP_FONT_TICK); wc(fd, CDP_CH_QUOTE); w(fd, extra); wc(fd, CDP_CH_GT); wn(fd, v); w(fd, "</text>\n" as *u8); return 0 }
3372func cdp_mean_text(fd: i64, x: i64, y: i64, extra: *u8, v: i64) -> i64 { w(fd, "<text" as *u8); cdp_an(fd, "x" as *u8, x); cdp_an(fd, "y" as *u8, y); w(fd, " fill='var(--nx-color-mut)' font-size='" as *u8); wn(fd, CDP_FONT_TICK); wc(fd, CDP_CH_QUOTE); w(fd, extra); w(fd, ">mean " as *u8); wn(fd, v); w(fd, "</text>\n" as *u8); return 0 }
3373// the contrast refuse flags (datavis DV3): set by cdp_contrast before any text is drawn, read by the text emitters below;
3374// zero-initialised, so a view that never measures draws everything
3375static g_cdp_ct_refuse_labels: i64
3376static g_cdp_ct_refuse_notes: i64
3377static g_cdp_ct_refuse_quad: i64
3378func cdp_quad_word(i: i64) -> *u8 {
3379 if i == 0 { return "Unconventional" as *u8 }
3380 if i == 1 { return "Aspirational" as *u8 }
3381 if i == CDP_TWO { return "Peripheral" as *u8 }
3382 return "Mainstream" as *u8
3383}
3384// a quadrant word at a SEATED box (text-anchor start at the box's left edge): the placer chose the seat, not the centre
3385// full opacity since DV3: at three quarters the muted word over the panel measured 3.67:1, under the 4.5 small-text floor
3386func cdp_quad_at(fd: i64, x: i64, ybase: i64, s: *u8) -> i64 { if g_cdp_ct_refuse_quad == 1 { return 0 } w(fd, "<text" as *u8); cdp_an(fd, "x" as *u8, x); cdp_an(fd, "y" as *u8, ybase); w(fd, " fill='var(--nx-color-mut)' font-size='" as *u8); wn(fd, CDP_FONT_QUAD); w(fd, "' style='letter-spacing:.12em;text-transform:uppercase'>" as *u8); wnote(fd, s); w(fd, "</text>\n" as *u8); return 0 }
3387func cdp_mark(fd: i64, x: i64, y: i64, r: i64, p: i64, known: i64, mom: i64) -> i64 { w(fd, "<circle" as *u8); cdp_an(fd, "cx" as *u8, x); cdp_an(fd, "cy" as *u8, y); cdp_an(fd, "r" as *u8, r); cdp_an(fd, "data-p" as *u8, p); w(fd, " fill='" as *u8); w(fd, cl_palette(p)); w(fd, "' fill-opacity='0.82' stroke='" as *u8); w(fd, cdp_mom_stroke(known, mom)); w(fd, "' stroke-width='" as *u8); wn(fd, CDP_STROKE_W); w(fd, "'>" as *u8); return 0 }
3388func cdp_leader(fd: i64, mx: i64, my: i64, lx: i64, ly: i64, lw: i64, lh: i64) -> i64 { if g_cdp_ct_refuse_labels == 1 { return 0 } var tx: i64 = lx; if lx + lw < mx { tx = lx + lw } cdp_line(fd, mx, my, tx, ly + lh / CDP_TWO, "stroke='var(--nx-color-mut)'" as *u8); return 0 }
3389func cdp_label(fd: i64, x: i64, y: i64, bold: i64, s: *u8, p: i64) -> i64 {
3390 if g_cdp_ct_refuse_labels == 1 { return 0 }
3391 w(fd, "<text" as *u8); cdp_an(fd, "x" as *u8, x); cdp_an(fd, "y" as *u8, y + CDP_LABEL_BASE); cdp_an(fd, "data-p" as *u8, p)
3392 w(fd, " font-size='" as *u8); wn(fd, CDP_FONT_LABEL); w(fd, "' fill='var(--nx-color-fg)' style='paint-order:stroke;stroke:var(--nx-color-bg);stroke-width:3px;stroke-linejoin:round'" as *u8)
3393 if bold == 1 { w(fd, " font-weight='700'" as *u8) }
3394 wc(fd, CDP_CH_GT); wnote(fd, s); w(fd, "</text>\n" as *u8)
3395 return 0
3396}
3397// a slice of the notes buffer through the ONE escaper (wnote / wj want a NUL-terminated string)
3398func cdp_wnote_n(fd: i64, s: *u8, n: i64) -> i64 { let t: *u8 = sys_mmap(n + 1); var i: i64 = 0; while i < n { t[i] = s[i]; i = i + 1 } t[n] = 0 as u8; return wnote(fd, t) }
3399func cdp_wj_n(fd: i64, s: *u8, n: i64) -> i64 { let t: *u8 = sys_mmap(n + 1); var i: i64 = 0; while i < n { t[i] = s[i]; i = i + 1 } t[n] = 0 as u8; return wj(fd, t) }
3400// THE ANNOTATION LAYER (datavis DV5 cdp_annotate): a note's callout -- the box, its wrapped lines, and a <title> carrying the id.
3401// The box sits where the placer seated it (the same placer as the labels), so it never collides with a mark or a label.
3402func cdp_annotate(fd: i64, x: i64, y: i64, wd: i64, ht: i64, buf: *u8, rcn: *i64, loff: *i64, llen: *i64, nlines: i64) -> i64 {
3403 if g_cdp_ct_refuse_notes == 1 { return 0 }
3404 w(fd, "<g class='cdnote'><title>note " as *u8); cdp_wnote_n(fd, (buf as i64 + rcn[CD_N_IDOFF]) as *u8, rcn[CD_N_IDLEN]); w(fd, "</title><rect" as *u8)
3405 cdp_an(fd, "x" as *u8, x); cdp_an(fd, "y" as *u8, y); cdp_an(fd, "width" as *u8, wd); cdp_an(fd, "height" as *u8, ht)
3406 w(fd, " rx='4' fill='var(--nx-color-panel)' " as *u8); w(fd, CDP_NOTE_STROKE); w(fd, "/>\n" as *u8)
3407 var i: i64 = 0
3408 while i < nlines {
3409 w(fd, "<text" as *u8); cdp_an(fd, "x" as *u8, x + CDP_NOTE_PAD); cdp_an(fd, "y" as *u8, y + CDP_NOTE_PAD + CDP_NOTE_BASE + i * cl_text_h(CDP_FONT_NOTE))
3410 w(fd, " fill='var(--nx-color-fg)' font-size='" as *u8); wn(fd, CDP_FONT_NOTE); wc(fd, CDP_CH_QUOTE); wc(fd, CDP_CH_GT)
3411 cdp_wnote_n(fd, (buf as i64 + rcn[CD_N_TOFF] + loff[i]) as *u8, llen[i])
3412 w(fd, "</text>\n" as *u8)
3413 i = i + 1
3414 }
3415 w(fd, "</g>\n" as *u8)
3416 return 0
3417}
3418// THE INTERACTION DOOR (datavis DV8 cdp_interact): one inline script over the zero-JS floor. Without it the figure, its
3419// legend, the notes and the grade are complete; with it, hover (or focus) reveals a mark's values in a tooltip (the same
3420// <title> text the emitter already wrote), a legend button toggles a player's mark, label and path, and dragging on the
3421// plot brushes a region: the players inside are listed in an <output> and the region is written into the URL hash as
3422// cdsel=xlo,xhi,ylo,yhi in PERMIL on the cut axes, so the trace is shareable and re-applied on load -- the evidence a
3423// claim can be checked against. The lexer forbids '#' and '!' inside a literal, so the hash mark is built from its code
3424// and every negation is spelled as a comparison.
3425func cdp_interact(fd: i64, domx: *i64, domy: *i64) -> i64 {
3426 w(fd, "<style>.cdfig{position:relative}.cdleg{font:inherit;background:none;border:0;padding:0;margin:0;cursor:pointer;color:inherit}.cdleg[aria-pressed='false']{opacity:.45;text-decoration:line-through}.cdtip{position:absolute;pointer-events:none;background:var(--nx-color-panel);color:var(--nx-color-fg);border:1px solid var(--nx-color-line);border-radius:4px;padding:4px 8px;font-size:.8rem;max-width:26rem;z-index:2}.cdsel{display:block;font-size:.85rem;color:var(--nx-color-mut);margin-top:.35rem;min-height:1.2em}</style>\n" as *u8)
3427 w(fd, "<script>(function(){var fig=document.querySelector('figure.cdfig svg.cdmap');if(fig==null)return;var tip=fig.parentNode.querySelector('.cdtip');var out=fig.parentNode.querySelector('.cdsel');var F={x0:" as *u8); wn(fd, CDP_PAD_L); w(fd, ",y0:" as *u8); wn(fd, CDP_PAD_T); w(fd, ",x1:" as *u8); wn(fd, CDP_SVG_W - CDP_PAD_R); w(fd, ",y1:" as *u8); wn(fd, CDP_SVG_H - CDP_PAD_B)
3428 w(fd, ",xlo:" as *u8); wn(fd, domx[CL_D_LO]); w(fd, ",xhi:" as *u8); wn(fd, domx[CL_D_HI]); w(fd, ",ylo:" as *u8); wn(fd, domy[CL_D_LO]); w(fd, ",yhi:" as *u8); wn(fd, domy[CL_D_HI]); w(fd, "};var H=String.fromCharCode(35);\n" as *u8)
3429 w(fd, "fig.parentNode.querySelectorAll('.cdleg').forEach(function(b){b.addEventListener('click',function(){var p=b.getAttribute('data-p');var on=(b.getAttribute('aria-pressed')=='true');b.setAttribute('aria-pressed',on?'false':'true');fig.querySelectorAll(\"[data-p='\"+p+\"']\").forEach(function(e){e.style.display=on?'none':'';});});});\n" as *u8)
3430 w(fd, "fig.querySelectorAll('circle[data-p]').forEach(function(c){c.setAttribute('tabindex','0');function show(ev){var t=c.querySelector('title');if(t==null)return;tip.textContent=t.textContent;tip.hidden=false;var r=fig.getBoundingClientRect();tip.style.left=(ev.clientX-r.left+12)+'px';tip.style.top=(ev.clientY-r.top+12)+'px';}function hide(){tip.hidden=true;}c.addEventListener('pointerenter',show);c.addEventListener('pointermove',show);c.addEventListener('pointerleave',hide);c.addEventListener('focus',function(){var t=c.querySelector('title');if(t==null)return;tip.textContent=t.textContent;tip.hidden=false;tip.style.left='0px';tip.style.top='0px';});c.addEventListener('blur',hide);});\n" as *u8)
3431 w(fd, "var brush=document.createElementNS('http://www.w3.org/2000/svg','rect');brush.setAttribute('class','cdbrush');brush.setAttribute('fill','var(--nx-color-accent)');brush.setAttribute('fill-opacity','0.12');brush.setAttribute('stroke','var(--nx-color-accent)');brush.setAttribute('stroke-dasharray','3 2');brush.style.display='none';fig.appendChild(brush);\n" as *u8)
3432 w(fd, "function toSvg(ev){var pt=fig.createSVGPoint();pt.x=ev.clientX;pt.y=ev.clientY;var m=fig.getScreenCTM();if(m==null)return null;var q=pt.matrixTransform(m.inverse());return {x:q.x,y:q.y};}function px2x(px){return Math.round(F.xlo+(px-F.x0)*(F.xhi-F.xlo)/(F.x1-F.x0));}function px2y(py){return Math.round(F.ylo+(F.y1-py)*(F.yhi-F.ylo)/(F.y1-F.y0));}\n" as *u8)
3433 w(fd, "function apply(x0,y0,x1,y1){var lx=Math.min(x0,x1),rx=Math.max(x0,x1),ty=Math.min(y0,y1),by=Math.max(y0,y1);brush.setAttribute('x',lx);brush.setAttribute('y',ty);brush.setAttribute('width',rx-lx);brush.setAttribute('height',by-ty);brush.style.display='';var sel=[];var all=fig.querySelectorAll('circle[data-p]');all.forEach(function(c){var cx=Number(c.getAttribute('cx')),cy=Number(c.getAttribute('cy'));if(cx>=lx&&cx<=rx&&cy>=ty&&cy<=by){var t=c.querySelector('title');sel.push(t==null?c.getAttribute('data-p'):t.textContent);}});var dx0=px2x(lx),dx1=px2x(rx),dy0=px2y(by),dy1=px2y(ty);out.textContent='Selected '+sel.length+' of '+all.length+' players in x '+dx0+'..'+dx1+', y '+dy0+'..'+dy1+(sel.length>0?': '+sel.join('; '):'');try{history.replaceState(null,'',H+'cdsel='+dx0+','+dx1+','+dy0+','+dy1);}catch(e){}}\n" as *u8)
3434 w(fd, "var down=null;fig.addEventListener('pointerdown',function(ev){var p=toSvg(ev);if(p==null)return;if(p.x<F.x0||p.x>F.x1||p.y<F.y0||p.y>F.y1)return;down=p;try{fig.setPointerCapture(ev.pointerId);}catch(e){}});fig.addEventListener('pointermove',function(ev){if(down==null)return;var p=toSvg(ev);if(p==null)return;apply(down.x,down.y,p.x,p.y);});fig.addEventListener('pointerup',function(ev){if(down==null)return;var p=toSvg(ev);if(p==null){down=null;return;}apply(down.x,down.y,p.x,p.y);down=null;});\n" as *u8)
3435 w(fd, "var m=new RegExp(H+'cdsel=(-?[0-9]+),(-?[0-9]+),(-?[0-9]+),(-?[0-9]+)').exec(location.hash);if(m==null)return;function X(v){return F.x0+(v-F.xlo)*(F.x1-F.x0)/(F.xhi-F.xlo);}function Y(v){return F.y1-(v-F.ylo)*(F.y1-F.y0)/(F.yhi-F.ylo);}apply(X(Number(m[1])),Y(Number(m[3])),X(Number(m[2])),Y(Number(m[4])));})();</script>\n" as *u8)
3436 return 0
3437}
3438// the note's anchor as text: the player's name, or at <x>,<y>
3439// THE EXPORT (datavis DV6, 2026-09-15): the page's position map as a STANDALONE SVG and a PNG beside index.html, plus a
3440// receipt the page and api.json point at. Run by the regen as `nx_swcompare_matrix <dom> export <dir>` right after the
3441// page is published, from the page it just published, so the twins can never describe a different figure than the one
3442// on the page. The rasteriser is the estate's own (nx_cdmap_raster_lib over nx_ttf_fontlib and nx_png) -- no third party
3443// enters the publish path -- and every count it kept (elements drawn, constructs skipped by name, colours it could not
3444// resolve) is written into the receipt, so a partial render is legible as partial. A page with no position map is a
3445// NAMED absence (exit CDP_EXPORT_ABSENT), never a failure.
3446const CDP_EXPORT_SVG: *u8 = "cdmap.svg"
3447const CDP_EXPORT_PNG: *u8 = "cdmap.png"
3448const CDP_EXPORT_RECEIPT: *u8 = "cdmap.export.json"
3449const CDP_EXPORT_INDEX: *u8 = "index.html"
3450const CDP_EXPORT_SCALE: i64 = 2 // the PNG is twice the viewBox: crisp on a 2x display, 1520 x 1040 for the standard map
3451const CDP_EXPORT_OK: i64 = 0
3452const CDP_EXPORT_FAIL: i64 = 1
3453const CDP_EXPORT_ABSENT: i64 = 2
3454const CDP_EXPORT_PATH_CAP: i64 = 1024
3455const CDP_FONT_NAS: *u8 = "knowledge/fonts/LiberationSans-Regular.ttf"
3456const CDP_FONT_NAS_BOLD: *u8 = "knowledge/fonts/LiberationSans-Bold.ttf"
3457const CDP_FONT_UP: *u8 = "../knowledge/fonts/LiberationSans-Regular.ttf" // the regen runs the generators from buildroot
3458const CDP_FONT_UP_BOLD: *u8 = "../knowledge/fonts/LiberationSans-Bold.ttf"
3459const CDP_FONT_LAPTOP: *u8 = "web_assets/fonts/LiberationSans-Regular.ttf"
3460const CDP_FONT_LAPTOP_BOLD: *u8 = "web_assets/fonts/LiberationSans-Bold.ttf"
3461const CDP_CH_SLASH: i64 = 47
3462func cdp_font_probe(nas: *u8, up: *u8, laptop: *u8) -> *u8 {
3463 var fd: i64 = sys_openat_rd(nas)
3464 if fd >= 0 { sys_close(fd); return nas }
3465 fd = sys_openat_rd(up)
3466 if fd >= 0 { sys_close(fd); return up }
3467 return laptop
3468}
3469func cdp_export_path(dst: *u8, dir: *u8, leaf: *u8) -> i64 {
3470 var o: i64 = scopy(dst, 0, dir)
3471 if o > 0 { if (dst[o - 1] as i64) != CDP_CH_SLASH { dst[o] = CDP_CH_SLASH as u8; o = o + 1 } }
3472 o = scopy(dst, o, leaf)
3473 dst[o] = 0 as u8
3474 return o
3475}
3476func cdp_export_kv(fd: i64, key: *u8, v: i64) -> i64 { kv_n(fd, key, v); wc(fd, CDP_CH_COMMA); return 0 }
3477func cdp_export(dir: *u8) -> i64 {
3478 let page: *u8 = sys_mmap(CDP_EXPORT_PATH_CAP)
3479 let svgp: *u8 = sys_mmap(CDP_EXPORT_PATH_CAP)
3480 let pngp: *u8 = sys_mmap(CDP_EXPORT_PATH_CAP)
3481 let recp: *u8 = sys_mmap(CDP_EXPORT_PATH_CAP)
3482 cdp_export_path(page, dir, CDP_EXPORT_INDEX)
3483 cdp_export_path(svgp, dir, CDP_EXPORT_SVG)
3484 cdp_export_path(pngp, dir, CDP_EXPORT_PNG)
3485 cdp_export_path(recp, dir, CDP_EXPORT_RECEIPT)
3486 let freg: *u8 = cdp_font_probe(CDP_FONT_NAS, CDP_FONT_UP, CDP_FONT_LAPTOP)
3487 let fbold: *u8 = cdp_font_probe(CDP_FONT_NAS_BOLD, CDP_FONT_UP_BOLD, CDP_FONT_LAPTOP_BOLD)
3488 let stats: *i64 = rs_i64(RS_S_SLOTS)
3489 let out: *i64 = rs_i64(2)
3490 let rc: i64 = rs_export(page, svgp, pngp, freg, fbold, CDP_EXPORT_SCALE, stats, out)
3491 var verdict: i64 = CDP_EXPORT_OK
3492 if rc != RS_OK { verdict = CDP_EXPORT_FAIL }
3493 if rc == RS_E_NOSVG { verdict = CDP_EXPORT_ABSENT }
3494 // the receipt beside the twins (truncate-written; absent when the page has no map)
3495 if rc != RS_E_NOSVG {
3496 let fd: i64 = sys_openat_wr(recp, 420)
3497 if fd >= 0 {
3498 wc(fd, CDP_CH_LBRACE)
3499 kv_s(fd, "export" as *u8, "cdmap" as *u8); wc(fd, CDP_CH_COMMA)
3500 kv_s(fd, "verdict" as *u8, rs_rc_name(rc)); wc(fd, CDP_CH_COMMA)
3501 kv_s(fd, "svg" as *u8, CDP_EXPORT_SVG); wc(fd, CDP_CH_COMMA)
3502 cdp_export_kv(fd, "svg_bytes" as *u8, out[0])
3503 kv_s(fd, "png" as *u8, CDP_EXPORT_PNG); wc(fd, CDP_CH_COMMA)
3504 cdp_export_kv(fd, "png_bytes" as *u8, out[1])
3505 cdp_export_kv(fd, "scale" as *u8, CDP_EXPORT_SCALE)
3506 cdp_export_kv(fd, "png_width" as *u8, stats[RS_S_W])
3507 kv_s(fd, "font_regular" as *u8, freg); wc(fd, CDP_CH_COMMA)
3508 kv_s(fd, "font_bold" as *u8, fbold); wc(fd, CDP_CH_COMMA)
3509 cdp_export_kv(fd, "rect" as *u8, stats[RS_S_RECT]); cdp_export_kv(fd, "circle" as *u8, stats[RS_S_CIRCLE]); cdp_export_kv(fd, "line" as *u8, stats[RS_S_LINE])
3510 cdp_export_kv(fd, "polyline" as *u8, stats[RS_S_POLYLINE]); cdp_export_kv(fd, "polygon" as *u8, stats[RS_S_POLYGON]); cdp_export_kv(fd, "text" as *u8, stats[RS_S_TEXT])
3511 cdp_export_kv(fd, "notes" as *u8, stats[RS_S_NOTES]); cdp_export_kv(fd, "arrows" as *u8, stats[RS_S_ARROWS]); cdp_export_kv(fd, "rotated" as *u8, stats[RS_S_ROTATED])
3512 cdp_export_kv(fd, "rotated_skipped" as *u8, stats[RS_S_ROTSKIP]); cdp_export_kv(fd, "skipped" as *u8, stats[RS_S_SKIPPED]); cdp_export_kv(fd, "unresolved_colors" as *u8, stats[RS_S_UNRESOLVED])
3513 cdp_export_kv(fd, "glyphs" as *u8, stats[RS_S_GLYPHS]); cdp_export_kv(fd, "ink_px" as *u8, stats[RS_S_INK])
3514 kv_n(fd, "tokens" as *u8, stats[RS_S_TOKENS])
3515 wc(fd, CDP_CH_RBRACE); wc(fd, 10)
3516 sys_close(fd)
3517 }
3518 }
3519 w(1, "CDMAP-EXPORT dir=" as *u8); w(1, dir); w(1, " verdict=" as *u8); w(1, rs_rc_name(rc))
3520 w(1, " svg_bytes=" as *u8); wn(1, out[0]); w(1, " png_bytes=" as *u8); wn(1, out[1]); w(1, " png_width=" as *u8); wn(1, stats[RS_S_W])
3521 w(1, " circle=" as *u8); wn(1, stats[RS_S_CIRCLE]); w(1, " text=" as *u8); wn(1, stats[RS_S_TEXT]); w(1, " skipped=" as *u8); wn(1, stats[RS_S_SKIPPED])
3522 w(1, " unresolved_colors=" as *u8); wn(1, stats[RS_S_UNRESOLVED]); w(1, " font=" as *u8); w(1, freg); wc(1, 10)
3523 return verdict
3524}
3525func cdp_note_anchor(fd: i64, rcn: *i64, names: *i64) -> i64 {
3526 if rcn[CD_N_KIND] == CD_NK_PLAYER { wnote(fd, names[rcn[CD_N_PLAYER]] as *u8); return 0 }
3527 w(fd, "at " as *u8); wn(fd, rcn[CD_N_X]); wc(fd, CDP_CH_COMMA); wn(fd, rcn[CD_N_Y])
3528 return 0
3529}
3530func cdp_swatch(fd: i64, p: i64) -> i64 { w(fd, "<span style='display:inline-block;width:" as *u8); wn(fd, CDP_LEG_SW); w(fd, "px;height:" as *u8); wn(fd, CDP_LEG_SW); w(fd, "px;border-radius:50%;background:" as *u8); w(fd, cl_palette(p)); w(fd, ";margin:0 5px 0 10px;vertical-align:-1px' aria-hidden='true'></span>" as *u8); return 0 }
3531// THE CONTRAST MEASURE (datavis DV3, 2026-09-15): every text class the position map draws is measured against the surface
3532// it is drawn on, with the house tokens the page actually publishes (the brand SSOT rendered to its :root block and read
3533// back by the ONE token reader, rs_theme_load) and the ONE contrast ruler (cl_contrast, WCAG 2.x kernel; floors and tiers
3534// from knowledge/compare/contrast.conf, the row that moves when the WCAG 3 draft names its algorithm). The classes the
3535// placer seats -- player labels, note text, quadrant words -- are REFUSED when they fall under their floor (the emitters
3536// consult the refuse flags and draw nothing, and the count is printed); the structural classes -- tick numerals and axis
3537// titles -- are measured and printed but never hidden, because a chart without its scale is a worse defect than a faint
3538// one. Light theme only, announced: the page's dark variant carries its own tokens and is the next measure.
3539const CDP_CT_LABELS: i64 = 0
3540const CDP_CT_NOTES: i64 = 1
3541const CDP_CT_QUAD: i64 = 2
3542const CDP_CT_TICKS: i64 = 3
3543const CDP_CT_AXES: i64 = 4
3544const CDP_CT_REFUSED: i64 = 5
3545const CDP_CT_LOADED: i64 = 6
3546const CDP_CT_FLOOR_SMALL: i64 = 7
3547const CDP_CT_FLOOR_LARGE: i64 = 8
3548const CDP_CT_FLOOR_LABELS: i64 = 9
3549const CDP_CT_FLOOR_NOTES: i64 = 10
3550const CDP_CT_FLOOR_QUAD: i64 = 11
3551const CDP_CT_FLOOR_TICKS: i64 = 12
3552const CDP_CT_FLOOR_AXES: i64 = 13
3553const CDP_CT_TOKENS: i64 = 14
3554// the DARK register (DV3 extension, 2026-09-15): the same classes against the brand's dark rows, printed and counted
3555const CDP_CT_D_LABELS: i64 = 15
3556const CDP_CT_D_QUAD: i64 = 16
3557const CDP_CT_D_AXES: i64 = 17
3558const CDP_CT_D_UNDER: i64 = 18
3559const CDP_CT_D_TOKENS: i64 = 19
3560const CDP_CT_W: i64 = 20
3561const CDP_FONT_AXIS: i64 = 12 // the axis titles' font-size (cdp_text's literal)
3562const CDP_CONTRAST_CONF: *u8 = "knowledge/compare/contrast.conf" // CWD buildroot (the regen)
3563const CDP_CONTRAST_CONF_UP: *u8 = "buildroot/knowledge/compare/contrast.conf" // CWD nishihost (a probe)
3564const CDP_CT_X100: i64 = 100
3565func cdp_contrast(out: *i64) -> i64 {
3566 var k: i64 = 0
3567 while k < CDP_CT_W { out[k] = 0; k = k + 1 }
3568 let bd: *u8 = sc_brand()
3569 let tb: *u8 = sys_mmap(SC_TOKCAP)
3570 let tn: i64 = bt_emit_root_buf(bd, bt_len(bd), tb, SC_TOKCAP)
3571 let names: *u8 = sys_mmap(RS_TOK_MAX * RS_TOK_NAME_W)
3572 let recs: *i64 = sys_mmap(RS_TOK_MAX * RS_TOK_REC * CD_I64_BYTES) as *i64
3573 var ntok: i64 = 0
3574 if tn > 0 { ntok = rs_theme_load(tb, tn, names, recs) }
3575 out[CDP_CT_TOKENS] = ntok
3576 let fg: *i64 = sys_mmap(3 * CD_I64_BYTES) as *i64
3577 let mut: *i64 = sys_mmap(3 * CD_I64_BYTES) as *i64
3578 let panel: *i64 = sys_mmap(3 * CD_I64_BYTES) as *i64
3579 let bg: *i64 = sys_mmap(3 * CD_I64_BYTES) as *i64
3580 // an absent token measures as its own colour against itself (ratio 1.00) and REFUSES: a missing palette must not pass
3581 rs_tok_rgb(names, recs, ntok, "fg" as *u8, fg)
3582 rs_tok_rgb(names, recs, ntok, "mut" as *u8, mut)
3583 rs_tok_rgb(names, recs, ntok, "panel" as *u8, panel)
3584 rs_tok_rgb(names, recs, ntok, "bg" as *u8, bg)
3585 let ct: *i64 = sys_mmap(CL_CT_W * CD_I64_BYTES) as *i64
3586 var lc: i64 = cl_contrast_conf(CDP_CONTRAST_CONF, ct)
3587 if lc == 0 { lc = cl_contrast_conf(CDP_CONTRAST_CONF_UP, ct) }
3588 out[CDP_CT_LOADED] = ct[CL_CT_LOADED]
3589 out[CDP_CT_FLOOR_SMALL] = ct[CL_CT_SMALL]
3590 out[CDP_CT_FLOOR_LARGE] = ct[CL_CT_LARGE]
3591 out[CDP_CT_LABELS] = cl_contrast(fg[0], fg[1], fg[2], panel[0], panel[1], panel[2])
3592 out[CDP_CT_NOTES] = out[CDP_CT_LABELS]
3593 out[CDP_CT_QUAD] = cl_contrast(mut[0], mut[1], mut[2], panel[0], panel[1], panel[2])
3594 out[CDP_CT_TICKS] = out[CDP_CT_QUAD]
3595 out[CDP_CT_AXES] = cl_contrast(mut[0], mut[1], mut[2], bg[0], bg[1], bg[2])
3596 out[CDP_CT_FLOOR_LABELS] = cl_contrast_floor(CDP_FONT_LABEL, 0, ct) // the house label is bold at 13 px; below the bold tier that is the same floor
3597 out[CDP_CT_FLOOR_NOTES] = cl_contrast_floor(CDP_FONT_NOTE, 0, ct)
3598 out[CDP_CT_FLOOR_QUAD] = cl_contrast_floor(CDP_FONT_QUAD, 0, ct)
3599 out[CDP_CT_FLOOR_TICKS] = cl_contrast_floor(CDP_FONT_TICK, 0, ct)
3600 out[CDP_CT_FLOOR_AXES] = cl_contrast_floor(CDP_FONT_AXIS, 0, ct)
3601 g_cdp_ct_refuse_labels = 1 - cl_contrast_ok(out[CDP_CT_LABELS], out[CDP_CT_FLOOR_LABELS])
3602 g_cdp_ct_refuse_notes = 1 - cl_contrast_ok(out[CDP_CT_NOTES], out[CDP_CT_FLOOR_NOTES])
3603 g_cdp_ct_refuse_quad = 1 - cl_contrast_ok(out[CDP_CT_QUAD], out[CDP_CT_FLOOR_QUAD])
3604 out[CDP_CT_REFUSED] = g_cdp_ct_refuse_labels + g_cdp_ct_refuse_notes + g_cdp_ct_refuse_quad
3605 // DARK REGISTER (DV3 extension, 2026-09-15): the same classes measured against the brand's dark rows. ONE figure serves
3606 // both themes through var() tokens, so a dark class under its floor is PRINTED and counted, never hidden -- the remedy
3607 // is a token in the brand SSOT, and hiding a class in the light theme to satisfy the dark one would be the blank-chart
3608 // defect twice over. The refusal flags above belong to the light (paper, default) register.
3609 let td: *u8 = sys_mmap(SC_TOKCAP)
3610 let dn: i64 = bt_emit_dark_root_buf(bd, bt_len(bd), td, SC_TOKCAP)
3611 let dnames: *u8 = sys_mmap(RS_TOK_MAX * RS_TOK_NAME_W)
3612 let drecs: *i64 = sys_mmap(RS_TOK_MAX * RS_TOK_REC * CD_I64_BYTES) as *i64
3613 var dtok: i64 = 0
3614 if dn > 0 { dtok = rs_theme_load(td, dn, dnames, drecs) }
3615 out[CDP_CT_D_TOKENS] = dtok
3616 let dfg: *i64 = sys_mmap(3 * CD_I64_BYTES) as *i64
3617 let dmut: *i64 = sys_mmap(3 * CD_I64_BYTES) as *i64
3618 let dpanel: *i64 = sys_mmap(3 * CD_I64_BYTES) as *i64
3619 let dbg: *i64 = sys_mmap(3 * CD_I64_BYTES) as *i64
3620 rs_tok_rgb(dnames, drecs, dtok, "fg" as *u8, dfg)
3621 rs_tok_rgb(dnames, drecs, dtok, "mut" as *u8, dmut)
3622 rs_tok_rgb(dnames, drecs, dtok, "panel" as *u8, dpanel)
3623 rs_tok_rgb(dnames, drecs, dtok, "bg" as *u8, dbg)
3624 out[CDP_CT_D_LABELS] = cl_contrast(dfg[0], dfg[1], dfg[2], dpanel[0], dpanel[1], dpanel[2])
3625 out[CDP_CT_D_QUAD] = cl_contrast(dmut[0], dmut[1], dmut[2], dpanel[0], dpanel[1], dpanel[2])
3626 out[CDP_CT_D_AXES] = cl_contrast(dmut[0], dmut[1], dmut[2], dbg[0], dbg[1], dbg[2])
3627 var dunder: i64 = 0
3628 dunder = dunder + (1 - cl_contrast_ok(out[CDP_CT_D_LABELS], out[CDP_CT_FLOOR_LABELS]))
3629 dunder = dunder + (1 - cl_contrast_ok(out[CDP_CT_D_LABELS], out[CDP_CT_FLOOR_NOTES]))
3630 dunder = dunder + (1 - cl_contrast_ok(out[CDP_CT_D_QUAD], out[CDP_CT_FLOOR_QUAD]))
3631 dunder = dunder + (1 - cl_contrast_ok(out[CDP_CT_D_QUAD], out[CDP_CT_FLOOR_TICKS]))
3632 dunder = dunder + (1 - cl_contrast_ok(out[CDP_CT_D_AXES], out[CDP_CT_FLOOR_AXES]))
3633 out[CDP_CT_D_UNDER] = dunder
3634 return 0
3635}
3636// a ratio x100 as d.dd
3637func cdp_x100(fd: i64, v: i64) -> i64 { wn(fd, v / CDP_CT_X100); w(fd, "." as *u8); let f: i64 = v % CDP_CT_X100; if f < CDP_CT_X100 / 10 { wn(fd, 0) } wn(fd, f); return 0 }
3638func cdp_ct_pair(fd: i64, name: *u8, v: i64, floor: i64) -> i64 { w(fd, name); w(fd, " <b>" as *u8); cdp_x100(fd, v); w(fd, "</b> (floor " as *u8); cdp_x100(fd, floor); w(fd, ")" as *u8); return 0 }
3639func cdp_contrast_html(fd: i64, ct: *i64) -> i64 {
3640 w(fd, "<span class='cdcontrast'>text contrast, measured with " as *u8); w(fd, CL_CT_ALGORITHM)
3641 if ct[CDP_CT_LOADED] == 1 { w(fd, " (floors from contrast.conf)" as *u8) } else { if ct[CDP_CT_LOADED] == CL_CT_UNKNOWN_ALG { w(fd, " (contrast.conf names an algorithm this ruler does not implement: WCAG 2.x AA defaults)" as *u8) } else { w(fd, " (no contrast.conf: WCAG 2.x AA defaults)" as *u8) } }
3642 w(fd, ", light theme: " as *u8)
3643 cdp_ct_pair(fd, "labels" as *u8, ct[CDP_CT_LABELS], ct[CDP_CT_FLOOR_LABELS]); w(fd, " · " as *u8)
3644 cdp_ct_pair(fd, "notes" as *u8, ct[CDP_CT_NOTES], ct[CDP_CT_FLOOR_NOTES]); w(fd, " · " as *u8)
3645 cdp_ct_pair(fd, "quadrant words" as *u8, ct[CDP_CT_QUAD], ct[CDP_CT_FLOOR_QUAD]); w(fd, " · " as *u8)
3646 cdp_ct_pair(fd, "tick numerals" as *u8, ct[CDP_CT_TICKS], ct[CDP_CT_FLOOR_TICKS]); w(fd, " · " as *u8)
3647 cdp_ct_pair(fd, "axis titles" as *u8, ct[CDP_CT_AXES], ct[CDP_CT_FLOOR_AXES])
3648 w(fd, " · dark theme: " as *u8)
3649 cdp_ct_pair(fd, "labels" as *u8, ct[CDP_CT_D_LABELS], ct[CDP_CT_FLOOR_LABELS]); w(fd, " · " as *u8)
3650 cdp_ct_pair(fd, "quadrant words" as *u8, ct[CDP_CT_D_QUAD], ct[CDP_CT_FLOOR_QUAD]); w(fd, " · " as *u8)
3651 cdp_ct_pair(fd, "axis titles" as *u8, ct[CDP_CT_D_AXES], ct[CDP_CT_FLOOR_AXES])
3652 w(fd, " · dark classes under their floor <b>" as *u8); wn(fd, ct[CDP_CT_D_UNDER]); w(fd, "</b> (one figure serves both themes: a dark shortfall is a token to fix, never a class to hide)" as *u8)
3653 w(fd, " · classes refused under their floor <b>" as *u8); wn(fd, ct[CDP_CT_REFUSED]); w(fd, "</b> (a refused class is not drawn; the scale classes are measured, never hidden)</span>" as *u8)
3654 return 0
3655}
3656func cdp_contrast_json(fd: i64, ct: *i64) -> i64 {
3657 kv_s(fd, "contrast_algorithm" as *u8, CL_CT_ALGORITHM); wc(fd, CDP_CH_COMMA)
3658 kv_n(fd, "contrast_conf_loaded" as *u8, ct[CDP_CT_LOADED]); wc(fd, CDP_CH_COMMA)
3659 kv_n(fd, "contrast_floor_small_x100" as *u8, ct[CDP_CT_FLOOR_SMALL]); wc(fd, CDP_CH_COMMA)
3660 kv_n(fd, "contrast_floor_large_x100" as *u8, ct[CDP_CT_FLOOR_LARGE]); wc(fd, CDP_CH_COMMA)
3661 kv_n(fd, "contrast_labels_x100" as *u8, ct[CDP_CT_LABELS]); wc(fd, CDP_CH_COMMA)
3662 kv_n(fd, "contrast_notes_x100" as *u8, ct[CDP_CT_NOTES]); wc(fd, CDP_CH_COMMA)
3663 kv_n(fd, "contrast_quadrant_x100" as *u8, ct[CDP_CT_QUAD]); wc(fd, CDP_CH_COMMA)
3664 kv_n(fd, "contrast_ticks_x100" as *u8, ct[CDP_CT_TICKS]); wc(fd, CDP_CH_COMMA)
3665 kv_n(fd, "contrast_axes_x100" as *u8, ct[CDP_CT_AXES]); wc(fd, CDP_CH_COMMA)
3666 kv_n(fd, "contrast_tokens_read" as *u8, ct[CDP_CT_TOKENS]); wc(fd, CDP_CH_COMMA)
3667 kv_n(fd, "contrast_dark_labels_x100" as *u8, ct[CDP_CT_D_LABELS]); wc(fd, CDP_CH_COMMA)
3668 kv_n(fd, "contrast_dark_quadrant_x100" as *u8, ct[CDP_CT_D_QUAD]); wc(fd, CDP_CH_COMMA)
3669 kv_n(fd, "contrast_dark_axes_x100" as *u8, ct[CDP_CT_D_AXES]); wc(fd, CDP_CH_COMMA)
3670 kv_n(fd, "contrast_dark_under_floor" as *u8, ct[CDP_CT_D_UNDER]); wc(fd, CDP_CH_COMMA)
3671 kv_n(fd, "contrast_dark_tokens_read" as *u8, ct[CDP_CT_D_TOKENS]); wc(fd, CDP_CH_COMMA)
3672 kv_n(fd, "contrast_refused" as *u8, ct[CDP_CT_REFUSED])
3673 return 0
3674}
3675func cdp_grade(fd: i64, view: *u8, crit: *i64, unresolved: i64) -> i64 {
3676 w(fd, "<span class='cdgrade'>readability of the " as *u8); w(fd, view); w(fd, ", self-graded by the layout ruler: label overlaps <b>" as *u8); wn(fd, crit[CL_C_LL]); w(fd, "</b> · labels over marks <b>" as *u8); wn(fd, crit[CL_C_LM]); w(fd, "</b> · off-canvas <b>" as *u8); wn(fd, crit[CL_C_OFF]); w(fd, "</b> · unresolved labels <b>" as *u8); wn(fd, unresolved)
3677 w(fd, "</b> · mark overlaps <b>" as *u8); wn(fd, crit[CL_C_MM]); w(fd, "</b> (a fact of the data: two players that close are that close) · data spread <b>" as *u8); wn(fd, crit[CL_C_SPREAD]); w(fd, "</b> permil of the plot</span>" as *u8)
3678 return 0
3679}
3680func cdp_grade_json(fd: i64, key: *u8, crit: *i64, unresolved: i64) -> i64 {
3681 wq(fd); w(fd, key); wq(fd); wc(fd, CDP_CH_COLON); wc(fd, CDP_CH_LBRACE)
3682 kv_n(fd, "label_overlaps" as *u8, crit[CL_C_LL]); wc(fd, CDP_CH_COMMA); kv_n(fd, "labels_over_marks" as *u8, crit[CL_C_LM]); wc(fd, CDP_CH_COMMA); kv_n(fd, "off_canvas" as *u8, crit[CL_C_OFF]); wc(fd, CDP_CH_COMMA)
3683 kv_n(fd, "unresolved" as *u8, unresolved); wc(fd, CDP_CH_COMMA); kv_n(fd, "mark_overlaps" as *u8, crit[CL_C_MM]); wc(fd, CDP_CH_COMMA); kv_n(fd, "spread_permil" as *u8, crit[CL_C_SPREAD]); wc(fd, CDP_CH_COMMA); kv_n(fd, "defects" as *u8, crit[CL_C_DEFECTS])
3684 wc(fd, CDP_CH_RBRACE)
3685 return 0
3686}
3687func cdp_dom_json(fd: i64, key: *u8, dom: *i64) -> i64 { wq(fd); w(fd, key); wq(fd); wc(fd, CDP_CH_COLON); wc(fd, CDP_CH_LBRACKET); wn(fd, dom[CL_D_LO]); wc(fd, CDP_CH_COMMA); wn(fd, dom[CL_D_HI]); wc(fd, CDP_CH_COMMA); wn(fd, dom[CL_D_STEP]); wc(fd, CDP_CH_RBRACKET); return 0 }
3688func cdp_day_label(fd: i64, day: i64) -> i64 { let b: *u8 = sys_mmap(CDP_DATE_CAP); let o: i64 = bd_ymd(day * CD_SECS_PER_DAY, b, 0); sys_write(fd, b, o); return 0 }
3689func cdp_text(fd: i64, x: i64, y: i64, extra: *u8, s: *u8) -> i64 { w(fd, "<text" as *u8); cdp_an(fd, "x" as *u8, x); cdp_an(fd, "y" as *u8, y); w(fd, " fill='currentColor' font-size='12'" as *u8); w(fd, extra); wc(fd, CDP_CH_GT); wnote(fd, s); w(fd, "</text>\n" as *u8); return 0 }
3690func cdp_hist(hist: *i64, p: i64) -> *i64 { return (hist as i64 + p * CD_HIST_W * CD_I64_BYTES) as *i64 }
3691// player p's block of daily trail records (tcap records of CD_HIST_W words each)
3692func cdp_trail(trail: *i64, tcap: i64, p: i64) -> *i64 { return (trail as i64 + p * tcap * CD_HIST_W * CD_I64_BYTES) as *i64 }
3693func cdp_line(fd: i64, x1: i64, y1: i64, x2: i64, y2: i64, style: *u8) -> i64 { w(fd, "<line" as *u8); cdp_an(fd, "x1" as *u8, x1); cdp_an(fd, "y1" as *u8, y1); cdp_an(fd, "x2" as *u8, x2); cdp_an(fd, "y2" as *u8, y2); wc(fd, CDP_CH_SPACE); w(fd, style); w(fd, "/>\n" as *u8); return 0 }
3694func cdp_pt(fd: i64, x: i64, y: i64) -> i64 { wn(fd, x); wc(fd, CDP_CH_COMMA); wn(fd, y); return 0 }
3695// the 3D point of player p on the cube's axes: which = first or previous spine day, or -1 for today
3696func cdp_cube_xyz(out: *i64, p: i64, nr: i64, h: *i64, cube: *i64, which: i64, xyz: *i64) -> i64 {
3697 var k: i64 = 0
3698 while k < CD_CUBE_AXES {
3699 if which < 0 { xyz[k] = cd_axis_plot(out, p, nr, h, cube[k]) } else { xyz[k] = cd_hist_axis_plot(h, which, cube[k]) }
3700 k = k + 1
3701 }
3702 return 0
3703}
3704func cdp_iso_px(xyz: *i64) -> i64 { return cd_iso_x(CDP_ISO_OX, xyz[0], xyz[1], CDP_ISO_UNIT) }
3705func cdp_iso_py(xyz: *i64) -> i64 { return cd_iso_y(CDP_ISO_OY, xyz[0], xyz[1], xyz[2], CDP_ISO_UNIT) }
3706func cdp_iso_floor_py(xyz: *i64) -> i64 { return cd_iso_y(CDP_ISO_OY, xyz[0], xyz[1], 0, CDP_ISO_UNIT) }
3707func cdp_iso_at(fd: i64, x: i64, y: i64, z: i64) -> i64 { cdp_pt(fd, cd_iso_x(CDP_ISO_OX, x, y, CDP_ISO_UNIT), cd_iso_y(CDP_ISO_OY, x, y, z, CDP_ISO_UNIT)); return 0 }
3708func cdp_names(fd: i64, ids: *i64, n: i64) -> i64 { var k: i64 = 0; while k < n { if k > 0 { w(fd, ", " as *u8) } w(fd, cd_axis_name(ids[k])); k = k + 1 } return 0 }
3709func cdp_names_json(fd: i64, ids: *i64, n: i64) -> i64 { wc(fd, CDP_CH_LBRACKET); var k: i64 = 0; while k < n { if k > 0 { wc(fd, CDP_CH_COMMA) } wq(fd); w(fd, cd_axis_name(ids[k])); wq(fd); k = k + 1 } wc(fd, CDP_CH_RBRACKET); return 0 }
3710// ---- DV4 SMALL MULTIPLES (datavis DV4 cdp_splom, 2026-09-15): every registered axis pair as one small cut ----
3711// A five-axis registry reads as ten small pictures instead of one cube: each panel fits BOTH of its axes to the field
3712// of play through the ONE layout ruler (cl_domain / cl_scale_dom), draws the category means and the same momentum-
3713// ringed marks as the cut (radius halved, floor CDP_SM_R_MIN), and grades itself with the same critic. A small cut
3714// carries NO labels (the legend names the colours), so the critic is called with zero-size boxes and only its MARK
3715// terms are reported: MM (a data property, marks that overlap) and SPREAD (how much of the panel the players use).
3716// LL, LM and OFF are box terms with no boxes behind them here and are deliberately NOT published for a panel.
3717// The figure's grade line sums MM over the panels and carries the spread's minimum and mean; api.json carries every panel.
3718const CDP_SM_COLS: i64 = 3
3719const CDP_SM_CELL_W: i64 = 246
3720const CDP_SM_CELL_H: i64 = 190
3721const CDP_SM_PAD_L: i64 = 36
3722const CDP_SM_PAD_R: i64 = 10
3723const CDP_SM_PAD_T: i64 = 22
3724const CDP_SM_PAD_B: i64 = 26
3725const CDP_SM_R_MIN: i64 = 3
3726const CDP_SM_R_DIV: i64 = 2
3727const CDP_SM_FONT: i64 = 10
3728const CDP_SM_TITLE_DY: i64 = 14
3729const CDP_SM_TICK_DY: i64 = 12
3730const CDP_SM_TICK_DX: i64 = 4
3731const CDP_SM_TICK_BASE: i64 = 3
3732co