code wiki / _hdl_build / nx_asset_page.nx
nx_asset_page.nx source
↩ module page · 841 lines · 40341 B
1// nx_asset_page.nx -- THE /exceed ASSET-PAGE EMITTER (debt 1785877956, three-tier display doctrine).
2// Point at an asset MANIFEST (judged measurements as DATA) -> emit the per-asset three-tier page.
3// Operator 2026-08-04: "shown on nishifamily.com and not just asserted... point an asset and you can
4// publish a page with the judge and measurements and gaps and all that."
5//
6// nx_asset_page <manifest.tsv> <out.html> [pubprefix] [relpath]
7//
8// manifest rows (tab-separated, first col = row type; unknown types are IGNORED additively):
9// meta \t <slug> \t <format> \t <title>
10// tasset\t <1|2|3> \t <glb|img> \t <href> \t <label> (a tier's DISPLAYED artifact, site-relative)
11// lic \t <field> \t <value> (asset license meta, displayed verbatim)
12// tier \t <1|2|3> \t <state> \t <note> (state: LIVE|PARTIAL|OPEN -- badged honestly)
13// THE THREE SHOWINGS ARE SIDE BY SIDE, ALWAYS (operator 2026-08-04: "its three things to show and
14// we have to get them side by side"): every page renders exactly three panels in one grid row --
15// ORIGINAL / MIGRATED / IMPROVED. A tier without a tasset row renders a visible OPEN slot naming
16// its rung; absence is shown, never hidden in a footnote.
17// judge \t <organ> \t <axis> \t <value> \t <unit> \t <evidence>
18// gap \t <axis> \t <ours> \t <best> \t <holder>
19//
20// FAIL-CLOSED (the pub-house law: a page nothing judged is an ASSERTION, not a showcase):
21// exit 3 manifest unreadable/empty
22// exit 4 no meta row
23// exit 5 ZERO judge rows -- refuses to emit a judgeless page
24// exit 6 ZERO tier rows -- refuses a page that hides the tier ladder
25// With [pubprefix relpath] the emitted page SELF-REGISTERS on the pub plane (pl_register_asset,
26// idempotent) so it is never an orphan on the desk it was born on.
27// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
28import "nx_syscalls.nx"
29import "nx_itoa_lib.nx"
30import "nx_pub_lib.nx"
31import "nx_store_seed_lib.nx"
32import "nx_asset_page_lib.nx"
33import "nx_reveal_lib.nx"
34const AP_MAGIC_1160: i64 = 1160
35// pubsync provenance (publishing-partner lane): rows counted for the emitted slug, stamped into the
36// page so nx_pub_reconcile can compare plane-vs-page WITHOUT re-deriving anything.
37static AP_SLUGROWS: i64
38
39const AP_COLS: i64 = 6
40const AP_CAP: i64 = 262144
41const AP_OUT: i64 = 524288
42const AP_TAB: i64 = 9
43const AP_NL: i64 = 10
44const AP_PATHCAP: i64 = 1024
45
46func ap_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
47func ap_puts(s: *u8) -> i64 { sys_write(1, s, ap_len(s)); return 0 }
48func ap_num(v: i64) -> i64 { nxi_out(v); return 0 }
49func ap_read(path: *u8, buf: *u8, cap: i64) -> i64 {
50 let fd: i64 = sys_openat_rd(path)
51 if fd < 0 { return 0 - 1 }
52 var n: i64 = 0
53 var go: i64 = 1
54 while go == 1 {
55 let base: i64 = buf as i64
56 let r: i64 = sys_read(fd, (base + n) as *u8, cap - n)
57 if r <= 0 { go = 0 } else { n = n + r }
58 if n >= cap { go = 0 }
59 }
60 sys_close(fd)
61 return n
62}
63func ap_app(dst: *u8, off: i64, s: *u8) -> i64 {
64 var i: i64 = 0
65 var o: i64 = off
66 while s[i] != (0 as u8) { dst[o] = s[i]; o = o + 1; i = i + 1 }
67 return o
68}
69// append src[a..b) with minimal HTML escaping (& < >) -- manifest values land in markup.
70func ap_appesc(dst: *u8, off: i64, src: *u8, a: i64, b: i64) -> i64 {
71 var i: i64 = a
72 var o: i64 = off
73 while i < b {
74 let ch: i64 = src[i] as i64
75 if ch == 38 { o = ap_app(dst, o, "&" as *u8) }
76 if ch == 60 { o = ap_app(dst, o, "<" as *u8) }
77 if ch == 62 { o = ap_app(dst, o, ">" as *u8) }
78 if ch != 38 { if ch != 60 { if ch != 62 { dst[o] = src[i]; o = o + 1 } } }
79 i = i + 1
80 }
81 return o
82}
83func ap_eol(buf: *u8, n: i64, i: i64) -> i64 {
84 var e: i64 = i
85 var s: i64 = 1
86 while s == 1 {
87 if e >= n { s = 0 } else { if buf[e] == (AP_NL as u8) { s = 0 } else { e = e + 1 } }
88 }
89 return e
90}
91func ap_cols(buf: *u8, ls: i64, le: i64, col: *i64) -> i64 {
92 var c: i64 = 0
93 var p: i64 = ls
94 while c < AP_COLS {
95 var q: i64 = p
96 var s: i64 = 1
97 while s == 1 {
98 if q >= le { s = 0 } else { if buf[q] == (AP_TAB as u8) { s = 0 } else { q = q + 1 } }
99 }
100 col[c*2] = p
101 col[c*2+1] = q
102 if q >= le {
103 c = c + 1
104 while c < AP_COLS { col[c*2] = le; col[c*2+1] = le; c = c + 1 }
105 return c
106 }
107 p = q + 1
108 c = c + 1
109 }
110 return c
111}
112func ap_is(buf: *u8, a: i64, b: i64, lit: *u8) -> i64 {
113 let l: i64 = ap_len(lit)
114 if b - a != l { return 0 }
115 var i: i64 = 0
116 while i < l { if buf[a+i] != lit[i] { return 0 } i = i + 1 }
117 return 1
118}
119func ap_span_cstr(buf: *u8, a: i64, b: i64) -> *u8 {
120 let s: *u8 = sys_mmap(b - a + 1)
121 var i: i64 = 0
122 while a + i < b { s[i] = buf[a + i]; i = i + 1 }
123 s[b - a] = 0 as u8
124 return s
125}
126// PUBLIC-BOARD RULE (ecosystem EC64, operator 2026-09-17: nothing sensitive draws on load). The content class of a
127// displayed artifact is column 6 of its tasset row; a row that declares none is classed by KIND (a 3D model, or an image
128// its publisher did not class), which is click-to-open, so no tier's media is ever inline by default
129const AP_TASSET_CLASS_COL: i64 = 5
130func ap_reveal_class(buf: *u8, col: *i64) -> *u8 {
131 if col[AP_TASSET_CLASS_COL * 2 + 1] > col[AP_TASSET_CLASS_COL * 2] { return ap_span_cstr(buf, col[AP_TASSET_CLASS_COL * 2], col[AP_TASSET_CLASS_COL * 2 + 1]) }
132 if ap_is(buf, col[4], col[5], "glb" as *u8) == 1 { return "model-3d" as *u8 }
133 return "unclassified-image" as *u8
134}
135
136// LAST-WINS AT RENDER TIME (debt 1785901592): planes are append-only BY DESIGN, so a corrected row
137// coexists with the row it retires and the emitter used to show BOTH. The emitter, not the store,
138// resolves: a row is SUPERSEDED when a LATER row shares its rowtype + key (key = field 1; for judge
139// rows the AXIS, field 2 -- a re-measurement by ANY organ retires the old number). The plane keeps
140// the full correction trail for audit; only the page collapses it.
141func ap_sup(m: *u8, mn: i64, ls: i64, le: i64) -> i64 {
142 let ca: *i64 = sys_mmap(AP_COLS * 16) as *i64
143 let cb: *i64 = sys_mmap(AP_COLS * 16) as *i64
144 ap_cols(m, ls, le, ca)
145 var ka: i64 = 1
146 if ap_is(m, ca[0], ca[1], "judge" as *u8) == 1 { ka = 2 }
147 var j: i64 = le + 1
148 var sup: i64 = 0
149 while j < mn {
150 let je: i64 = ap_eol(m, mn, j)
151 if je > j {
152 ap_cols(m, j, je, cb)
153 var same: i64 = 0
154 if ca[1]-ca[0] == cb[1]-cb[0] { same = 1 }
155 var q: i64 = 0
156 while same == 1 { if q >= ca[1]-ca[0] { same = 2 } else { if m[ca[0]+q] != m[cb[0]+q] { same = 0 } else { q = q + 1 } } }
157 if same == 2 {
158 var keq: i64 = 0
159 if ca[ka*2+1]-ca[ka*2] == cb[ka*2+1]-cb[ka*2] { keq = 1 }
160 q = 0
161 while keq == 1 { if q >= ca[ka*2+1]-ca[ka*2] { keq = 2 } else { if m[ca[ka*2]+q] != m[cb[ka*2]+q] { keq = 0 } else { q = q + 1 } } }
162 if keq == 2 { sup = 1; j = mn }
163 }
164 }
165 if j < mn { j = je + 1 }
166 }
167 sys_munmap(ca as *u8, AP_COLS * 16)
168 sys_munmap(cb as *u8, AP_COLS * 16)
169 return sup
170}
171
172// one pass over the manifest emitting rows of ONE type via the given section writer state.
173// mode: 1=tier badges, 2=judge rows, 3=gap rows, 4=license rows. Returns rows emitted.
174func ap_pass(m: *u8, mn: i64, out: *u8, optr: *i64, mode: i64) -> i64 {
175 let col: *i64 = sys_mmap(AP_COLS * 16) as *i64
176 var cnt: i64 = 0
177 var i: i64 = 0
178 var o: i64 = optr[0]
179 while i < mn {
180 let le: i64 = ap_eol(m, mn, i)
181 if le > i {
182 ap_cols(m, i, le, col)
183 var hit: i64 = 0
184 if mode == 1 { if ap_is(m, col[0], col[1], "tier" as *u8) == 1 { hit = 1 } }
185 if mode == 2 { if ap_is(m, col[0], col[1], "judge" as *u8) == 1 { hit = 1 } }
186 if mode == 3 { if ap_is(m, col[0], col[1], "gap" as *u8) == 1 { hit = 1 } }
187 if mode == 4 { if ap_is(m, col[0], col[1], "lic" as *u8) == 1 { hit = 1 } }
188 if hit == 1 { if ap_sup(m, mn, i, le) == 1 { hit = 0 } }
189 if hit == 1 {
190 cnt = cnt + 1
191 if mode == 1 {
192 o = ap_app(out, o, "<span class=\"tier t" as *u8)
193 o = ap_appesc(out, o, m, col[2], col[3])
194 o = ap_app(out, o, "\">T" as *u8)
195 o = ap_appesc(out, o, m, col[2], col[3])
196 o = ap_app(out, o, " " as *u8)
197 o = ap_appesc(out, o, m, col[4], col[5])
198 o = ap_app(out, o, "</span> <span class=\"note\">" as *u8)
199 o = ap_appesc(out, o, m, col[6], col[7])
200 o = ap_app(out, o, "</span><br>\n" as *u8)
201 }
202 if mode == 2 {
203 o = ap_app(out, o, "<tr><td>" as *u8)
204 o = ap_appesc(out, o, m, col[2], col[3])
205 o = ap_app(out, o, "</td><td>" as *u8)
206 o = ap_appesc(out, o, m, col[4], col[5])
207 o = ap_app(out, o, "</td><td class=\"val\">" as *u8)
208 o = ap_appesc(out, o, m, col[6], col[7])
209 o = ap_app(out, o, "</td><td>" as *u8)
210 o = ap_appesc(out, o, m, col[8], col[9])
211 o = ap_app(out, o, "</td><td class=\"ev\">" as *u8)
212 o = ap_appesc(out, o, m, col[10], col[11])
213 o = ap_app(out, o, "</td></tr>\n" as *u8)
214 }
215 if mode == 3 {
216 o = ap_app(out, o, "<tr><td>" as *u8)
217 o = ap_appesc(out, o, m, col[2], col[3])
218 o = ap_app(out, o, "</td><td>" as *u8)
219 o = ap_appesc(out, o, m, col[4], col[5])
220 o = ap_app(out, o, "</td><td class=\"best\">" as *u8)
221 o = ap_appesc(out, o, m, col[6], col[7])
222 o = ap_app(out, o, "</td><td>" as *u8)
223 o = ap_appesc(out, o, m, col[8], col[9])
224 o = ap_app(out, o, "</td></tr>\n" as *u8)
225 }
226 if mode == 4 {
227 o = ap_app(out, o, "<tr><td>" as *u8)
228 o = ap_appesc(out, o, m, col[2], col[3])
229 o = ap_app(out, o, "</td><td>" as *u8)
230 o = ap_appesc(out, o, m, col[4], col[5])
231 o = ap_app(out, o, "</td></tr>\n" as *u8)
232 }
233 }
234 }
235 i = le + 1
236 }
237 optr[0] = o
238 sys_munmap(col as *u8, AP_COLS * 16)
239 return cnt
240}
241
242// append a non-negative decimal into dst at off; returns new off. (nxi_out writes stdout; SVG needs buffer.)
243func ap_dec(dst: *u8, off: i64, v: i64) -> i64 {
244 if v <= 0 { dst[off] = 48 as u8; return off + 1 }
245 let tmp: *u8 = sys_mmap(32)
246 var n: i64 = 0
247 var x: i64 = v
248 while x > 0 { tmp[n] = ((x - (x / 10) * 10) + 48) as u8; x = x / 10; n = n + 1 }
249 var o: i64 = off
250 while n > 0 { n = n - 1; dst[o] = tmp[n]; o = o + 1 }
251 sys_munmap(tmp, 32)
252 return o
253}
254// append a decimal that may be negative (SVG coordinates)
255func ap_deci(dst: *u8, off: i64, v: i64) -> i64 {
256 var o: i64 = off
257 var x: i64 = v
258 if x < 0 { dst[o] = 45 as u8; o = o + 1; x = 0 - x }
259 return ap_dec(dst, o, x)
260}
261// parse a non-negative int from m[a..b); non-digits end the parse. -1 if no digits.
262func ap_int(m: *u8, a: i64, b: i64) -> i64 {
263 var v: i64 = 0
264 var got: i64 = 0
265 var i: i64 = a
266 while i < b {
267 let c: i64 = m[i] as i64
268 if c >= 48 { if c <= 57 { v = v * 10 + (c - 48); got = 1; i = i + 1 } else { i = b } } else { i = b }
269 }
270 if got == 0 { return 0 - 1 }
271 return v
272}
273// dota-style 6-spoke compass, x1000 (SVG y grows DOWN; k=0 is straight up, clockwise)
274func ap_dirx(k: i64) -> i64 {
275 if k == 0 { return 0 }
276 if k == 1 { return 866 }
277 if k == 2 { return 866 }
278 if k == 3 { return 0 }
279 if k == 4 { return 0 - 866 }
280 return 0 - 866
281}
282func ap_diry(k: i64) -> i64 {
283 if k == 0 { return 0 - 1000 }
284 if k == 1 { return 0 - 500 }
285 if k == 2 { return 500 }
286 if k == 3 { return 1000 }
287 if k == 4 { return 500 }
288 return 0 - 500
289}
290// THE CAPABILITY RADAR (operator 2026-08-04: dota-2-style hero card; 'measurements feedback is
291// trash' -> the gap SHAPE at a glance). Sovereign inline SVG, zero JS, integer geometry only --
292// renders in the nishi browser by construction. Manifest rows: radar \t label \t ours \t best \t max
293// (max = the axis scale, DATA never a code constant). Up to 6 axes; needs >=3 to draw. OURS = filled
294// green polygon, BEST-OF-BREED = dashed blue outline; both clamped to the rim.
295func ap_radar(m: *u8, mn: i64, out: *u8, optr: *i64) -> i64 {
296 let col: *i64 = sys_mmap(AP_COLS * 16) as *i64
297 let rl: *i64 = sys_mmap(6 * 16) as *i64 // label spans
298 let rv: *i64 = sys_mmap(6 * 8) as *i64 // ours scaled x1000
299 let rb: *i64 = sys_mmap(6 * 8) as *i64 // best scaled x1000
300 let ro: *i64 = sys_mmap(6 * 8) as *i64 // ours raw
301 let rr: *i64 = sys_mmap(6 * 8) as *i64 // best raw
302 var n: i64 = 0
303 var i: i64 = 0
304 while i < mn {
305 let le: i64 = ap_eol(m, mn, i)
306 if le > i {
307 if n < 6 {
308 ap_cols(m, i, le, col)
309 if ap_is(m, col[0], col[1], "radar" as *u8) == 1 {
310 let vo: i64 = ap_int(m, col[4], col[5])
311 let vb: i64 = ap_int(m, col[6], col[7])
312 let vm: i64 = ap_int(m, col[8], col[9])
313 if vm > 0 { if vo >= 0 { if vb >= 0 {
314 rl[n*2] = col[2]; rl[n*2+1] = col[3]
315 var so: i64 = vo * 1000 / vm
316 var sb: i64 = vb * 1000 / vm
317 if so > 1000 { so = 1000 }
318 if sb > 1000 { sb = 1000 }
319 rv[n] = so; rb[n] = sb; ro[n] = vo; rr[n] = vb
320 n = n + 1
321 } } }
322 }
323 }
324 }
325 i = le + 1
326 }
327 if n < 3 { return 0 }
328 var o: i64 = optr[0]
329 o = ap_app(out, o, "<h2>Capability radar — <span class=\"lg-ours\">ours (filled)</span> vs <span class=\"lg-best\">best-of-breed (outline)</span></h2>\n<svg class=\"radar\" viewBox=\"-1400 -1400 2800 2800\" role=\"img\" aria-label=\"capability radar\">\n" as *u8)
330 // grid rings + spokes
331 var ring: i64 = 250
332 while ring <= 1000 {
333 o = ap_app(out, o, "<polygon fill=\"none\" stroke=\"#8884\" stroke-width=\"6\" points=\"" as *u8)
334 var k: i64 = 0
335 while k < n {
336 o = ap_deci(out, o, ap_dirx(k) * ring / 1000)
337 o = ap_app(out, o, "," as *u8)
338 o = ap_deci(out, o, ap_diry(k) * ring / 1000)
339 o = ap_app(out, o, " " as *u8)
340 k = k + 1
341 }
342 o = ap_app(out, o, "\"/>\n" as *u8)
343 ring = ring + 250
344 }
345 var s: i64 = 0
346 while s < n {
347 o = ap_app(out, o, "<line stroke=\"#8884\" stroke-width=\"6\" x1=\"0\" y1=\"0\" x2=\"" as *u8)
348 o = ap_deci(out, o, ap_dirx(s))
349 o = ap_app(out, o, "\" y2=\"" as *u8)
350 o = ap_deci(out, o, ap_diry(s))
351 o = ap_app(out, o, "\"/>\n" as *u8)
352 s = s + 1
353 }
354 // BEST polygon (dashed outline), then OURS (filled) on top
355 o = ap_app(out, o, "<polygon fill=\"none\" stroke=\"#5b8def\" stroke-width=\"14\" stroke-dasharray=\"40 24\" points=\"" as *u8)
356 var kb: i64 = 0
357 while kb < n {
358 o = ap_deci(out, o, ap_dirx(kb) * rb[kb] / 1000)
359 o = ap_app(out, o, "," as *u8)
360 o = ap_deci(out, o, ap_diry(kb) * rb[kb] / 1000)
361 o = ap_app(out, o, " " as *u8)
362 kb = kb + 1
363 }
364 o = ap_app(out, o, "\"/>\n<polygon fill=\"#2e9e44\" fill-opacity=\"0.35\" stroke=\"#2e9e44\" stroke-width=\"14\" points=\"" as *u8)
365 var ko: i64 = 0
366 while ko < n {
367 o = ap_deci(out, o, ap_dirx(ko) * rv[ko] / 1000)
368 o = ap_app(out, o, "," as *u8)
369 o = ap_deci(out, o, ap_diry(ko) * rv[ko] / 1000)
370 o = ap_app(out, o, " " as *u8)
371 ko = ko + 1
372 }
373 o = ap_app(out, o, "\"/>\n" as *u8)
374 // labels + ours/best values at the rim
375 var kl: i64 = 0
376 while kl < n {
377 let lx: i64 = ap_dirx(kl) * AP_MAGIC_1160 / 1000
378 var ly: i64 = ap_diry(kl) * AP_MAGIC_1160 / 1000
379 if ly > 1000 { ly = ly + 60 }
380 o = ap_app(out, o, "<text x=\"" as *u8)
381 o = ap_deci(out, o, lx)
382 o = ap_app(out, o, "\" y=\"" as *u8)
383 o = ap_deci(out, o, ly)
384 o = ap_app(out, o, "\" text-anchor=\"middle\" font-size=\"78\" fill=\"currentColor\" opacity=\"0.8\">" as *u8)
385 o = ap_appesc(out, o, m, rl[kl*2], rl[kl*2+1])
386 o = ap_app(out, o, "</text>\n<text x=\"" as *u8)
387 o = ap_deci(out, o, lx)
388 o = ap_app(out, o, "\" y=\"" as *u8)
389 o = ap_deci(out, o, ly + 88)
390 o = ap_app(out, o, "\" text-anchor=\"middle\" font-size=\"66\" opacity=\"0.55\" fill=\"currentColor\">" as *u8)
391 o = ap_dec(out, o, ro[kl])
392 o = ap_app(out, o, " vs " as *u8)
393 o = ap_dec(out, o, rr[kl])
394 o = ap_app(out, o, "</text>\n" as *u8)
395 kl = kl + 1
396 }
397 o = ap_app(out, o, "</svg>\n<p class=\"legend\">every axis scaled to its own stated max (manifest data, never a code constant); values clamp at the rim</p>\n" as *u8)
398 optr[0] = o
399 return n
400}
401
402// emit ONE tier panel: badge from the tier-row type trow (tier|tier2), artifact from the tasset-row
403// type tarow (tasset|tasset2) -- glb -> live viewer canvas, img -> image, no artifact -> a visible
404// OPEN slot. Two row types = the two DIRECTIONS (inbound: theirs into our ecosystem; outbound: ours
405// into their world) correlated on one page. Returns 1 if the tier row was found.
406func ap_panel(m: *u8, mn: i64, out: *u8, optr: *i64, trow: *u8, tarow: *u8, tlit: *u8, tname: *u8) -> i64 {
407 let col: *i64 = sys_mmap(AP_COLS * 16) as *i64
408 var tier_s: i64 = 0 - 1
409 var tier_e: i64 = 0
410 var ta_s: i64 = 0 - 1
411 var ta_e: i64 = 0
412 var i: i64 = 0
413 while i < mn {
414 let le: i64 = ap_eol(m, mn, i)
415 if le > i {
416 ap_cols(m, i, le, col)
417 // LAST-WINS per (rowtype, tier) -- the supersedence convention (debt 1785901592): planes are
418 // append-only by design, so a corrected tier badge or artifact is APPENDED, and the newest
419 // row is the one that renders while the whole correction trail survives in the plane for audit.
420 if ap_is(m, col[0], col[1], trow) == 1 {
421 if ap_is(m, col[2], col[3], tlit) == 1 { tier_s = i; tier_e = le }
422 }
423 if ap_is(m, col[0], col[1], tarow) == 1 {
424 if ap_is(m, col[2], col[3], tlit) == 1 { ta_s = i; ta_e = le }
425 }
426 }
427 i = le + 1
428 }
429 var o: i64 = optr[0]
430 o = ap_app(out, o, "<div class=\"panel\"><span class=\"tier t" as *u8)
431 o = ap_app(out, o, tlit)
432 o = ap_app(out, o, "\">T" as *u8)
433 o = ap_app(out, o, tlit)
434 o = ap_app(out, o, " " as *u8)
435 o = ap_app(out, o, tname)
436 var found: i64 = 0
437 if tier_s >= 0 {
438 found = 1
439 ap_cols(m, tier_s, tier_e, col)
440 o = ap_app(out, o, " · " as *u8)
441 o = ap_appesc(out, o, m, col[4], col[5])
442 }
443 o = ap_app(out, o, "</span>\n" as *u8)
444 if ta_s >= 0 {
445 ap_cols(m, ta_s, ta_e, col)
446 // the displayed artifact goes behind the estate's one click-to-open primitive: a class the policy withholds
447 // writes a named placeholder and NO media; an overflow writes nothing (wrong in the direction of showing less)
448 let rv_pl: *i64 = sys_mmap(16) as *i64
449 let rv_pw: *i64 = sys_mmap(16) as *i64
450 let rv_pol: *u8 = rvl_policy_load(rv_pl, rv_pw)
451 let rv_tally: *i64 = sys_mmap(RVL_T_N * RVL_I64) as *i64
452 rvl_tally_clear(rv_tally)
453 let rv_md: *i64 = sys_mmap(16) as *i64
454 let rv_cap: *u8 = ap_span_cstr(m, col[8], col[9])
455 let rv_o: i64 = rvl_block_open(out, o, AP_OUT, rv_pol, rv_pl[0], ap_reveal_class(m, col), rv_cap, rv_tally, rv_md)
456 if rv_o >= 0 {
457 o = rv_o
458 if rv_md[0] != RVL_MODE_GATED {
459 if ap_is(m, col[4], col[5], "glb" as *u8) == 1 {
460 o = ap_app(out, o, "<canvas id=\"tv" as *u8)
461 o = ap_app(out, o, trow)
462 o = ap_app(out, o, tlit)
463 o = ap_app(out, o, "\" data-glb=\"" as *u8)
464 o = ap_appesc(out, o, m, col[6], col[7])
465 o = ap_app(out, o, "\" data-mode=\"turn\" width=\"300\" height=\"400\"></canvas>\n" as *u8)
466 }
467 if ap_is(m, col[4], col[5], "img" as *u8) == 1 {
468 o = ap_app(out, o, "<img src=\"" as *u8)
469 o = ap_appesc(out, o, m, col[6], col[7])
470 o = ap_app(out, o, "\" alt=\"" as *u8)
471 o = ap_appesc(out, o, m, col[8], col[9])
472 o = ap_app(out, o, "\" loading=\"lazy\" decoding=\"async\">\n" as *u8)
473 }
474 let rv_c: i64 = rvl_block_close(out, o, AP_OUT, rv_md[0], rv_cap)
475 if rv_c >= 0 { o = rv_c } else { o = ap_app(out, o, "</figure></details>
476" as *u8) }
477 }
478 }
479 o = ap_app(out, o, "<p class=\"prov\">" as *u8)
480 o = ap_appesc(out, o, m, col[8], col[9])
481 o = ap_app(out, o, "</p>\n" as *u8)
482 }
483 if ta_s < 0 {
484 o = ap_app(out, o, "<div class=\"openslot\">" as *u8)
485 if tier_s >= 0 {
486 ap_cols(m, tier_s, tier_e, col)
487 o = ap_appesc(out, o, m, col[6], col[7])
488 }
489 if tier_s < 0 { o = ap_app(out, o, "no tier row in manifest" as *u8) }
490 o = ap_app(out, o, "</div>\n" as *u8)
491 }
492 if tier_s >= 0 {
493 if ta_s >= 0 {
494 ap_cols(m, tier_s, tier_e, col)
495 o = ap_app(out, o, "<p class=\"note\">" as *u8)
496 o = ap_appesc(out, o, m, col[6], col[7])
497 o = ap_app(out, o, "</p>\n" as *u8)
498 }
499 }
500 o = ap_app(out, o, "</div>\n" as *u8)
501 optr[0] = o
502 sys_munmap(col as *u8, AP_COLS * 16)
503 return found
504}
505
506func main(argc: i64, argv: *i64) -> i64 {
507 // register verb: one pub-plane row, no page emit -- the primitive the adopt-cap refusal exposed
508 // (67k-file docroots cannot bulk-adopt; single assets register one row at a time, honestly noted).
509 if argc >= 2 {
510 if ap_is(argv[1] as *u8, 0, ap_len(argv[1] as *u8), "register" as *u8) == 1 {
511 if argc < 5 {
512 ap_puts("usage: nx_asset_page register <pubprefix> <relpath> <note>\n" as *u8)
513 sys_exit(2); return 2
514 }
515 let rr: i64 = pl_register_asset(argv[2] as *u8, argv[3] as *u8, argv[4] as *u8)
516 ap_puts("ASSET-REGISTER " as *u8)
517 if rr == 1 { ap_puts("ADDED " as *u8) }
518 if rr == 0 { ap_puts("ALREADY " as *u8) }
519 if rr < 0 { ap_puts("FAILED " as *u8) }
520 ap_puts(argv[3] as *u8)
521 ap_puts("\n" as *u8)
522 if rr < 0 { sys_exit(1); return 1 }
523 sys_exit(0); return 0
524 }
525 }
526 let m: *u8 = sys_mmap(AP_CAP)
527 var mn: i64 = 0
528 var outp: *u8 = 0 as *u8
529 var pfx: *u8 = 0 as *u8
530 var rel: *u8 = 0 as *u8
531 var isplane: i64 = 0
532 if argc >= 2 { if ap_is(argv[1] as *u8, 0, ap_len(argv[1] as *u8), "emit" as *u8) == 1 { isplane = 1 } }
533 if isplane == 1 {
534 // THE PERMANENT PATH (operator 2026-08-04: tsv is not part of our permanent work): manifest
535 // rows live slug-keyed in the seg-store plane (SSOT, e.g. knowledge/store/assetcat-); the
536 // organ reads the PLANE via sts_load -- no file-shaped manifest exists anywhere in the loop.
537 if argc < 5 {
538 ap_puts("usage: nx_asset_page emit <plane-prefix> <slug> <out.html> [pubprefix relpath]\n" as *u8)
539 sys_exit(2); return 2
540 }
541 let pb: *u8 = sys_mmap(AP_CAP)
542 let pn: i64 = sts_load(argv[2] as *u8, pb, AP_CAP - 16)
543 if pn <= 0 {
544 ap_puts("ASSET-PAGE REFUSED: plane unreadable or empty -> " as *u8)
545 ap_puts(argv[2] as *u8)
546 ap_puts("\n" as *u8)
547 sys_exit(3); return 3
548 }
549 let slug: *u8 = argv[3] as *u8
550 let sl: i64 = ap_len(slug)
551 var pi: i64 = 0
552 while pi < pn {
553 let ple: i64 = ap_eol(pb, pn, pi)
554 if ple > pi + sl {
555 var hit: i64 = 1
556 var si: i64 = 0
557 while si < sl { if pb[pi + si] != slug[si] { hit = 0; si = sl } else { si = si + 1 } }
558 if hit == 1 { if pb[pi + sl] != (AP_TAB as u8) { hit = 0 } }
559 if hit == 1 {
560 var ci: i64 = pi + sl + 1
561 while ci < ple { m[mn] = pb[ci]; mn = mn + 1; ci = ci + 1 }
562 m[mn] = AP_NL as u8
563 mn = mn + 1
564 AP_SLUGROWS = AP_SLUGROWS + 1
565 }
566 }
567 pi = ple + 1
568 }
569 if mn <= 0 {
570 ap_puts("ASSET-PAGE REFUSED: no plane rows for slug -> " as *u8)
571 ap_puts(slug)
572 ap_puts("\n" as *u8)
573 sys_exit(3); return 3
574 }
575 outp = argv[4] as *u8
576 if argc >= 7 { pfx = argv[5] as *u8; rel = argv[6] as *u8 }
577 }
578 // index verb: THE /exceed FRONT DOOR, derived from the pub registry (the generated-index law:
579 // the registry is the SSOT of what exists on the surface -- never hand-listed).
580 // nx_asset_page index <pubprefix> <out.html> [regprefix relpath]
581 var isindex: i64 = 0
582 if isplane == 0 { if argc >= 2 { if ap_is(argv[1] as *u8, 0, ap_len(argv[1] as *u8), "index" as *u8) == 1 { isindex = 1 } } }
583 if isindex == 1 {
584 if argc < 4 {
585 ap_puts("usage: nx_asset_page index <pubprefix> <out.html> [regprefix relpath]\n" as *u8)
586 sys_exit(2); return 2
587 }
588 let rb: *u8 = sys_mmap(AP_CAP)
589 let rn: i64 = sts_load(argv[2] as *u8, rb, AP_CAP - 16)
590 if rn <= 0 {
591 ap_puts("ASSET-PAGE REFUSED: registry unreadable or empty -> " as *u8)
592 ap_puts(argv[2] as *u8)
593 ap_puts("\n" as *u8)
594 sys_exit(3); return 3
595 }
596 let iout: *u8 = sys_mmap(AP_OUT)
597 var oo: i64 = 0
598 oo = ap_app(iout, oo, "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n<title>/exceed - original, migrated, improved: every asset judged</title>\n<style>\nbody{font-family:system-ui,sans-serif;margin:0 auto;padding:24px;max-width:900px;line-height:1.5;color-scheme:light dark}\nh1{font-size:1.4rem}\n.card{border:1px solid #8884;border-radius:10px;padding:12px 16px;margin:10px 0}\n.card a{font-weight:600;font-size:1.02em}\n.fmt{display:inline-block;font-size:.7rem;padding:2px 10px;border-radius:10px;border:1px solid #5b8def;margin-right:8px;text-transform:uppercase}\n.prov{font-size:.72rem;opacity:.65}\n</style>\n</head>\n<body>\n<h1>/exceed — the asset showcase</h1>\n<p class=\"prov\">Every page shows ORIGINAL / MIGRATED / IMPROVED side by side, judged by organs, gaps as a capability radar; pages are emitted from the plane by nx_asset_page and enumerated here FROM THE PUB REGISTRY.</p>\n" as *u8)
599 let seen: *u8 = sys_mmap(AP_CAP)
600 var seenn: i64 = 0
601 var npages: i64 = 0
602 let icol: *i64 = sys_mmap(AP_COLS * 16) as *i64
603 var ri: i64 = 0
604 while ri < rn {
605 let rle: i64 = ap_eol(rb, rn, ri)
606 if rle > ri {
607 ap_cols(rb, ri, rle, icol)
608 var cx: i64 = 0
609 var taken: i64 = 0
610 while cx < AP_COLS {
611 if taken == 0 {
612 let pa: i64 = icol[cx*2]
613 let pb2: i64 = icol[cx*2+1]
614 var okp: i64 = 0
615 if pb2 - pa > 12 {
616 if ap_is(rb, pa, pa + 7, "exceed/" as *u8) == 1 {
617 if ap_is(rb, pb2 - 5, pb2, ".html" as *u8) == 1 { okp = 1 }
618 }
619 }
620 if okp == 1 {
621 taken = 1
622 var dup: i64 = 0
623 var sscan: i64 = 0
624 while sscan < seenn {
625 let sle: i64 = ap_eol(seen, seenn, sscan)
626 if sle - sscan == pb2 - pa {
627 var eq: i64 = 1
628 var q2: i64 = 0
629 while q2 < pb2 - pa { if seen[sscan + q2] != rb[pa + q2] { eq = 0; q2 = pb2 - pa } else { q2 = q2 + 1 } }
630 if eq == 1 { dup = 1 }
631 }
632 sscan = sle + 1
633 }
634 if dup == 0 {
635 var cpi: i64 = 0
636 while cpi < pb2 - pa { seen[seenn] = rb[pa + cpi]; seenn = seenn + 1; cpi = cpi + 1 }
637 seen[seenn] = AP_NL as u8
638 seenn = seenn + 1
639 if ap_is(rb, pa, pb2, "exceed/index.html" as *u8) == 0 {
640 npages = npages + 1
641 // format badge = the path segment between exceed/ and the next slash
642 var fs2: i64 = pa + 7
643 var fe2: i64 = fs2
644 var going: i64 = 1
645 while going == 1 {
646 if fe2 >= pb2 { going = 0 } else { if rb[fe2] == (47 as u8) { going = 0 } else { fe2 = fe2 + 1 } }
647 }
648 oo = ap_app(iout, oo, "<div class=\"card\"><span class=\"fmt\">" as *u8)
649 oo = ap_appesc(iout, oo, rb, fs2, fe2)
650 oo = ap_app(iout, oo, "</span><a href=\"/" as *u8)
651 oo = ap_appesc(iout, oo, rb, pa, pb2 - 5)
652 oo = ap_app(iout, oo, "\">" as *u8)
653 oo = ap_appesc(iout, oo, rb, pa, pb2 - 5)
654 oo = ap_app(iout, oo, "</a></div>\n" as *u8)
655 }
656 }
657 }
658 }
659 cx = cx + 1
660 }
661 }
662 ri = rle + 1
663 }
664 if npages == 0 {
665 ap_puts("ASSET-PAGE REFUSED: zero exceed pages in the registry -- an empty index is indistinguishable from a broken read\n" as *u8)
666 sys_exit(3); return 3
667 }
668 oo = ap_app(iout, oo, "<p class=\"prov\">Sibling surfaces: <a href=\"/compare\">/compare</a> (per-domain axes) · <a href=\"/papers\">/papers</a> (research corpus).</p>\n</body>\n</html>\n" as *u8)
669 let ifd: i64 = sys_openat_wr(argv[3] as *u8, 0x1a4)
670 if ifd < 0 { ap_puts("ASSET-PAGE REFUSED: cannot write index out\n" as *u8); sys_exit(7); return 7 }
671 sys_write(ifd, iout, oo)
672 sys_close(ifd)
673 var ireg: i64 = 0
674 if argc >= 6 { ireg = pl_register_asset(argv[4] as *u8, argv[5] as *u8, "exceed index derived from the pub registry by nx_asset_page" as *u8) }
675 ap_puts("ASSET-INDEX-EMITTED bytes=" as *u8)
676 ap_num(oo)
677 ap_puts(" pages=" as *u8)
678 ap_num(npages)
679 ap_puts(" registered=" as *u8)
680 ap_num(ireg)
681 ap_puts("\n" as *u8)
682 sys_exit(0); return 0
683 }
684 if isplane == 0 {
685 if argc < 3 {
686 ap_puts("usage: nx_asset_page emit <plane-prefix> <slug> <out.html> [pubprefix relpath] | index <pubprefix> <out.html> [regprefix relpath] | register <pubprefix> <relpath> <note>\n" as *u8)
687 sys_exit(2); return 2
688 }
689 mn = ap_read(argv[1] as *u8, m, AP_CAP - 16)
690 if mn <= 0 {
691 ap_puts("ASSET-PAGE REFUSED: manifest unreadable or empty -> " as *u8)
692 ap_puts(argv[1] as *u8)
693 ap_puts("\n" as *u8)
694 sys_exit(3); return 3
695 }
696 outp = argv[2] as *u8
697 if argc >= 5 { pfx = argv[3] as *u8; rel = argv[4] as *u8 }
698 }
699 // locate the meta row
700 let col: *i64 = sys_mmap(AP_COLS * 16) as *i64
701 var meta_s: i64 = 0 - 1
702 var i: i64 = 0
703 while i < mn {
704 let le: i64 = ap_eol(m, mn, i)
705 if le > i {
706 ap_cols(m, i, le, col)
707 if meta_s < 0 { if ap_is(m, col[0], col[1], "meta" as *u8) == 1 { meta_s = i } }
708 }
709 i = le + 1
710 }
711 if meta_s < 0 {
712 ap_puts("ASSET-PAGE REFUSED: no meta row (slug/format/title unknown)\n" as *u8)
713 sys_exit(4); return 4
714 }
715 let mle: i64 = ap_eol(m, mn, meta_s)
716 let mc: *i64 = sys_mmap(AP_COLS * 16) as *i64
717 ap_cols(m, meta_s, mle, mc)
718
719 let out: *u8 = sys_mmap(AP_OUT)
720 let op: *i64 = sys_mmap(16) as *i64
721 var o: i64 = 0
722 o = ap_app(out, o, "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n<title>" as *u8)
723 o = ap_appesc(out, o, m, mc[6], mc[7])
724 o = ap_app(out, o, "</title>\n<style>\nbody{font-family:system-ui,sans-serif;margin:0 auto;padding:24px;max-width:1100px;line-height:1.45;color-scheme:light dark}\nh1{font-size:1.4rem}h2{font-size:1.05rem;margin-top:1.6em}\n.tier{display:inline-block;font-size:.72rem;padding:2px 10px;border-radius:10px;border:1px solid #5b8def;margin:2px 6px 2px 0}\n.tier.t1{border-color:#2e9e44}.tier.t3{border-color:#c07a2b}\n.note{font-size:.8rem;opacity:.75}\ntable{border-collapse:collapse;width:100%;font-size:.85rem;margin:8px 0}\ntd,th{border-bottom:1px solid #8884;padding:4px 6px;text-align:left}\n.ev{font-size:.72rem;opacity:.6}.best{font-weight:600}\n.viewer{border:1px solid #8884;border-radius:10px;padding:12px;text-align:center;margin:14px 0}\n.prov{font-size:.72rem;opacity:.65}\n.cols3{display:grid;grid-template-columns:1fr 1fr 1fr;gap:14px;margin:14px 0}\n@media(max-width:950px){.cols3{grid-template-columns:1fr}}\n.panel{border:1px solid #8884;border-radius:10px;padding:12px;text-align:center}\n.panel img,.panel canvas{max-width:100%;height:auto;border-radius:6px;background:#17191e}\n.openslot{opacity:.55;padding:40px 10px;border:1px dashed #8886;border-radius:6px;font-size:.85rem}\n.radar{max-width:560px;margin:6px auto;display:block}\n.val{font-weight:700;font-size:1.02em}\n.legend{text-align:center;font-size:.78rem;opacity:.75}\n.lg-ours{color:#2e9e44;font-weight:700}.lg-best{color:#5b8def;font-weight:700}\n" as *u8)
725 let rv_css: i64 = rvl_css(out, o, AP_OUT)
726 if rv_css >= 0 { o = rv_css }
727 o = ap_app(out, o, "</style>\n</head>\n<body>\n<h1>" as *u8)
728 o = ap_appesc(out, o, m, mc[6], mc[7])
729 o = ap_app(out, o, "</h1>\n<p class=\"prov\">/exceed showcase · format=" as *u8)
730 o = ap_appesc(out, o, m, mc[4], mc[5])
731 o = ap_app(out, o, " · slug=" as *u8)
732 o = ap_appesc(out, o, m, mc[2], mc[3])
733 o = ap_app(out, o, " · every number re-derives from its evidence path; tiers per the three-tier display doctrine.</p>\n" as *u8)
734 // does an OUTBOUND row exist? (any tier2 line)
735 var has2: i64 = 0
736 var si: i64 = 0
737 while si < mn {
738 let sle: i64 = ap_eol(m, mn, si)
739 if sle > si {
740 ap_cols(m, si, sle, col)
741 if ap_is(m, col[0], col[1], "tier2" as *u8) == 1 { has2 = 1 }
742 }
743 si = sle + 1
744 }
745 if has2 == 1 {
746 o = ap_app(out, o, "<h2>INBOUND — their original, into the nishi ecosystem</h2>\n<div class=\"cols3\">\n" as *u8)
747 }
748 if has2 == 0 {
749 o = ap_app(out, o, "<h2>The three showings, side by side</h2>\n<div class=\"cols3\">\n" as *u8)
750 }
751 op[0] = o
752 var ntier: i64 = 0
753 ntier = ntier + ap_panel(m, mn, out, op, "tier" as *u8, "tasset" as *u8, "1" as *u8, "ORIGINAL" as *u8)
754 ntier = ntier + ap_panel(m, mn, out, op, "tier" as *u8, "tasset" as *u8, "2" as *u8, "MIGRATED" as *u8)
755 ntier = ntier + ap_panel(m, mn, out, op, "tier" as *u8, "tasset" as *u8, "3" as *u8, "IMPROVED" as *u8)
756 o = op[0]
757 o = ap_app(out, o, "</div>\n" as *u8)
758 if ntier < 3 {
759 ap_puts("ASSET-PAGE REFUSED: all three tiers must be declared (found " as *u8)
760 ap_num(ntier)
761 ap_puts(" of 3) -- the side-by-side may not be reduced\n" as *u8)
762 sys_exit(6); return 6
763 }
764 if has2 == 1 {
765 o = ap_app(out, o, "<h2>OUTBOUND — ours, into their world</h2>\n<div class=\"cols3\">\n" as *u8)
766 op[0] = o
767 var ntier2: i64 = 0
768 ntier2 = ntier2 + ap_panel(m, mn, out, op, "tier2" as *u8, "tasset2" as *u8, "1" as *u8, "ORIGINAL" as *u8)
769 ntier2 = ntier2 + ap_panel(m, mn, out, op, "tier2" as *u8, "tasset2" as *u8, "2" as *u8, "MIGRATED" as *u8)
770 ntier2 = ntier2 + ap_panel(m, mn, out, op, "tier2" as *u8, "tasset2" as *u8, "3" as *u8, "IMPROVED" as *u8)
771 o = op[0]
772 o = ap_app(out, o, "</div>\n" as *u8)
773 if ntier2 < 3 {
774 ap_puts("ASSET-PAGE REFUSED: outbound row present but incomplete (found " as *u8)
775 ap_num(ntier2)
776 ap_puts(" of 3 tiers) -- a direction may not be shown half-laddered\n" as *u8)
777 sys_exit(6); return 6
778 }
779 }
780 // the viewer script belongs to a page that shows a GLB canvas; an image-only page never used it, and a reference
781 // to a script a page does not use is a broken asset the verifier is right to name (nx_asset_page_lib, 2026-09-17)
782 if apl_has_glb(m, mn) == 1 { o = ap_app(out, o, "<script src=\"/compare/koikatsu/viewer11.js\"></script>\n" as *u8) }
783 op[0] = o
784 ap_radar(m, mn, out, op)
785 o = op[0]
786 o = ap_app(out, o, "<h2>Judge measurements</h2>\n<table>\n<tr><th>organ</th><th>axis</th><th>value</th><th>unit</th><th>evidence</th></tr>\n" as *u8)
787 op[0] = o
788 let njudge: i64 = ap_pass(m, mn, out, op, 2)
789 o = op[0]
790 o = ap_app(out, o, "</table>\n" as *u8)
791 if njudge == 0 {
792 ap_puts("ASSET-PAGE REFUSED: zero judge rows -- a judgeless page is an assertion\n" as *u8)
793 sys_exit(5); return 5
794 }
795 o = ap_app(out, o, "<h2>Gap table (ours vs best-of-breed)</h2>\n<table>\n<tr><th>axis</th><th>ours</th><th>best</th><th>holder</th></tr>\n" as *u8)
796 op[0] = o
797 let ngap: i64 = ap_pass(m, mn, out, op, 3)
798 o = op[0]
799 o = ap_app(out, o, "</table>\n<h2>Asset license (verbatim from the file's meta)</h2>\n<table>\n" as *u8)
800 op[0] = o
801 let nlic: i64 = ap_pass(m, mn, out, op, 4)
802 o = op[0]
803 o = ap_app(out, o, "</table>\n<p class=\"prov\">Emitted by nx_asset_page from a judged manifest; hand-editing this page violates the publishing-house standing order. Sibling surfaces: <a href=\"/compare\">/compare</a> (per-domain axes) · <a href=\"/papers\">/papers</a> (research corpus).</p>\n" as *u8)
804 o = ap_app(out, o, "<!--pubsync slug-rows=" as *u8)
805 o = ap_dec(out, o, AP_SLUGROWS)
806 o = ap_app(out, o, "-->\n</body>\n</html>\n" as *u8)
807
808 // write out
809 let fd: i64 = sys_openat_wr(outp, 0x1a4)
810 if fd < 0 {
811 ap_puts("ASSET-PAGE REFUSED: cannot write out -> " as *u8)
812 ap_puts(outp)
813 ap_puts("\n" as *u8)
814 sys_exit(7); return 7
815 }
816 sys_write(fd, out, o)
817 sys_close(fd)
818
819 // self-register on the pub plane (idempotent) when asked
820 var reg: i64 = 0
821 if (pfx as i64) != 0 {
822 reg = pl_register_asset(pfx, rel, "emitted by nx_asset_page from a judged manifest" as *u8)
823 }
824 ap_puts("ASSET-PAGE-EMITTED bytes=" as *u8)
825 ap_num(o)
826 ap_puts(" tiers=" as *u8)
827 ap_num(ntier)
828 ap_puts(" judges=" as *u8)
829 ap_num(njudge)
830 ap_puts(" gaps=" as *u8)
831 ap_num(ngap)
832 ap_puts(" lic=" as *u8)
833 ap_num(nlic)
834 ap_puts(" registered=" as *u8)
835 ap_num(reg)
836 ap_puts(" -> " as *u8)
837 ap_puts(outp)
838 ap_puts("\n" as *u8)
839 sys_exit(0)
840 return 0
841}