code wiki / _hdl_build / nx_asset_page.nx

nx_asset_page.nx source

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