nx_wiki_status.nx source
↩ module page · 271 lines · 16523 B
1// nx_wiki_status.nx -- /wiki/status : the LIVE "distance to S-class" scorecard.
2//
3// SOVEREIGNTY MANDATE (operator, 2026-05-29): this page must be Nishi,
4// bits-and-hardware-up -- NOT bash/sed/awk/TSV glue. The whole point of
5// the page is to prove the sovereign stack is real; if it were generated
6// by a shell pipeline parsing TSVs the medium would contradict the
7// message. So: the scorecard data is Nishi data (in nx_sc_emit_html
8// below), the aggregation/roll-up is computed in NishiLang, and the page
9// is rendered by the wiki's own render primitives + served live by the
10// Nishi wiki daemon at request time. Zero shell. Zero external lib.
11//
12// COMPOSES (per NISHI_SMALL_SHARP_COMPOSABLE_STANDARD; no new primitives):
13// wiki/nx_wiki_doc_render NxWikiDocCtx + ctx_init + write_header
14// (legacy header ships table CSS) +
15// write_z + write_byte + write_footer
16//
17// COMPOSED BY:
18// wiki/nx_wiki_routes dispatch GET /wiki/status
19//
20// FRESHNESS (honest): v1 embeds the latest 1:1-measured values (source:
21// NX_PITWALL_MEASURED_BOARD_2026_05_29 + the daily gates) as the Nishi
22// source of truth, replacing the prose board. v2 wires live reads from
23// each bench's Nishi-written results store (still no shell/TSV). The
24// page states its own provenance so freshness is never overclaimed.
25//
26// Hygiene per NISHI_CODE_HYGIENE_STANDARD: M2 every length checked vs
27// cap; M3 every while bounded; M7 named caps; M8 every write rc checked
28// + propagated (sealed verdict surface, no silent error).
29//
30// Status: V1. 2026-05-29.
31
32import "nx_syscalls.nx"
33import "wiki/nx_wiki_doc_render.nx"
34
35// ===== Sealed verdict surface =================================================
36const NX_SC_OK: i64 = 0
37const NX_SC_OVERFLOW: i64 = 2800
38
39// ===== Named sizing constants (M7) =================================================
40const NX_SC_RENDER_CAP: i64 = 262144 // 256 KB rendered HTML scratch
41const NX_SC_SCRATCH_CAP: i64 = 4096 // ctx scratch (>= 256 required)
42const NX_SC_STRLEN_CAP: i64 = 65536 // bounded strlen scan
43const NX_SC_PUTZ_CAP: i64 = 1048576 // bounded put_z scan
44
45// Class codes: 0=S(exceed) 1=A(parity) 2=B 3=C 4=D(behind) 5=pre(unmeasured)
46const NX_SC_CLASSES: i64 = 6
47
48// ===== Bounded strlen for NUL-terminated literals (M3) =================================================
49func nx_sc_strlen(s: *u8) -> i64 {
50 if (s as i64) == 0 { return 0 }
51 var n: i64 = 0
52 while n < NX_SC_STRLEN_CAP {
53 if s[n] == (0 as u8) { return n }
54 n = n + 1
55 }
56 return NX_SC_STRLEN_CAP
57}
58
59// ===== Append a NUL-terminated literal into a raw byte buffer (M2 + M3) =================================================
60// Used for the HTTP response framing (resp_buf is not an NxWikiDocCtx).
61func nx_sc_put_z(dst: *u8, off: *i64, cap: i64, s: *u8) -> i64 {
62 if (s as i64) == 0 { return 0 - NX_SC_OVERFLOW }
63 var n: i64 = 0
64 while n < NX_SC_PUTZ_CAP {
65 if s[n] == (0 as u8) {
66 if off[0] + n > cap { return 0 - NX_SC_OVERFLOW }
67 var i: i64 = 0
68 while i < n { dst[off[0] + i] = s[i]; i = i + 1 }
69 off[0] = off[0] + n
70 return NX_SC_OK
71 }
72 n = n + 1
73 }
74 return 0 - NX_SC_OVERFLOW
75}
76
77// ===== Emit a base-10 integer into the ctx output (M3) =================================================
78func nx_sc_emit_int(ctx: *NxWikiDocCtx, v: i64) -> i64 {
79 if v == 0 { return nx_wiki_doc_write_byte(ctx, 0x30) }
80 if v < 0 { return nx_wiki_doc_write_byte(ctx, 0x2D) } // '-' (not expected; defensive)
81 let tmp: *u8 = sys_mmap(32)
82 var n: i64 = v
83 var k: i64 = 0
84 while n > 0 {
85 if k >= 32 { return 0 - NX_SC_OVERFLOW }
86 tmp[k] = (0x30 + (n % 10)) as u8
87 n = n / 10
88 k = k + 1
89 }
90 var j: i64 = k - 1
91 var rc: i64 = 0
92 while j >= 0 {
93 rc = nx_wiki_doc_write_byte(ctx, tmp[j] as i64)
94 if rc != NX_WIKI_DOC_OK { return rc }
95 j = j - 1
96 }
97 return NX_SC_OK
98}
99
100// ===== Emit one car row (the data IS the source of truth; sovereign) =================================================
101// 10 args (< native 16-arg call cap). Tallies its class into counts[].
102func nx_sc_emit_row(ctx: *NxWikiDocCtx, counts: *i64,
103 name: *u8, layer: *u8, ours: *u8, incumbent: *u8,
104 sov: *u8, lever: *u8, k: i64, measured: i64) -> i64 {
105 var rc: i64 = 0
106 rc = nx_wiki_doc_write_z(ctx, "<tr><td>" as *u8); if rc != NX_WIKI_DOC_OK { return rc }
107 rc = nx_wiki_doc_write_z(ctx, name); if rc != NX_WIKI_DOC_OK { return rc }
108 rc = nx_wiki_doc_write_z(ctx, "</td><td>" as *u8); if rc != NX_WIKI_DOC_OK { return rc }
109 rc = nx_wiki_doc_write_z(ctx, layer); if rc != NX_WIKI_DOC_OK { return rc }
110 rc = nx_wiki_doc_write_z(ctx, "</td><td>" as *u8); if rc != NX_WIKI_DOC_OK { return rc }
111 rc = nx_wiki_doc_write_z(ctx, ours); if rc != NX_WIKI_DOC_OK { return rc }
112 rc = nx_wiki_doc_write_z(ctx, "</td><td>" as *u8); if rc != NX_WIKI_DOC_OK { return rc }
113 rc = nx_wiki_doc_write_z(ctx, incumbent); if rc != NX_WIKI_DOC_OK { return rc }
114 rc = nx_wiki_doc_write_z(ctx, "</td><td class=\"c\">" as *u8); if rc != NX_WIKI_DOC_OK { return rc }
115 // class cell (exactly one matches; rc holds that write)
116 if k == 0 { rc = nx_wiki_doc_write_z(ctx, "S" as *u8) }
117 if k == 1 { rc = nx_wiki_doc_write_z(ctx, "A" as *u8) }
118 if k == 2 { rc = nx_wiki_doc_write_z(ctx, "B" as *u8) }
119 if k == 3 { rc = nx_wiki_doc_write_z(ctx, "C" as *u8) }
120 if k == 4 { rc = nx_wiki_doc_write_z(ctx, "D" as *u8) }
121 if k == 5 { rc = nx_wiki_doc_write_z(ctx, "pre" as *u8) }
122 if rc != NX_WIKI_DOC_OK { return rc }
123 rc = nx_wiki_doc_write_z(ctx, "</td><td>" as *u8); if rc != NX_WIKI_DOC_OK { return rc }
124 rc = nx_wiki_doc_write_z(ctx, sov); if rc != NX_WIKI_DOC_OK { return rc }
125 rc = nx_wiki_doc_write_z(ctx, "</td><td>" as *u8); if rc != NX_WIKI_DOC_OK { return rc }
126 if measured == 1 { rc = nx_wiki_doc_write_z(ctx, "1:1" as *u8) }
127 if measured == 0 { rc = nx_wiki_doc_write_z(ctx, "floor/unmeasured" as *u8) }
128 if rc != NX_WIKI_DOC_OK { return rc }
129 rc = nx_wiki_doc_write_z(ctx, "</td><td>" as *u8); if rc != NX_WIKI_DOC_OK { return rc }
130 rc = nx_wiki_doc_write_z(ctx, lever); if rc != NX_WIKI_DOC_OK { return rc }
131 rc = nx_wiki_doc_write_z(ctx, "</td></tr>" as *u8); if rc != NX_WIKI_DOC_OK { return rc }
132 if k >= 0 { if k < NX_SC_CLASSES { counts[k] = counts[k] + 1 } }
133 return NX_SC_OK
134}
135
136// ===== Build the scorecard body (between <main> and </main>) =================================================
137func nx_sc_emit_html(ctx: *NxWikiDocCtx) -> i64 {
138 var rc: i64 = 0
139 let counts: *i64 = (sys_mmap(NX_SC_CLASSES * 8)) as *i64
140 var ci: i64 = 0
141 while ci < NX_SC_CLASSES { counts[ci] = 0; ci = ci + 1 }
142
143 rc = nx_wiki_doc_write_z(ctx, "<h1>Distance to S-Class: Nishi Stack, Lang and Ecosystem</h1>" as *u8)
144 if rc != NX_WIKI_DOC_OK { return rc }
145 rc = nx_wiki_doc_write_z(ctx, "<p class=\"status\">Live and sovereign. This page is generated from Nishi data and rendered by the Nishi wiki engine -- no shell, no TSV, no external library on the path. S=measured exceed, A=parity, B/C closing, D=measured behind, pre=unmeasured.</p><p><a href=\"/wiki/components\">▸ Browse component articles — each a researched, benchmarked, living repo + math + partnership worklog →</a> · <a href=\"/wiki/projects\">▸ Projects (all work, organized by the PM) →</a></p>" as *u8)
146 if rc != NX_WIKI_DOC_OK { return rc }
147
148 rc = nx_wiki_doc_write_z(ctx, "<table><thead><tr><th>Car</th><th>Layer</th><th>Ours (1:1)</th><th>Incumbent</th><th>Class</th><th>Sov</th><th>Proof</th><th>Next lever</th></tr></thead><tbody>" as *u8)
149 if rc != NX_WIKI_DOC_OK { return rc }
150
151 rc = nx_sc_emit_row(ctx, counts, "NishiLang self-host" as *u8, "lang" as *u8, "18/18 daily gates green; loud-fail guards" as *u8, "(structural wins)" as *u8, "A+" as *u8, "downstream of G1" as *u8, 1, 1); if rc != NX_SC_OK { return rc }
152 rc = nx_sc_emit_row(ctx, counts, "nxasm assembler" as *u8, "toolchain" as *u8, "2-6x faster .s->ELF, 13% smaller, deterministic" as *u8, "GNU as+ld" as *u8, "A+" as *u8, "single-pass backpatch" as *u8, 0, 1); if rc != NX_SC_OK { return rc }
153 rc = nx_sc_emit_row(ctx, counts, "Search / Diora ranking" as *u8, "search" as *u8, "MAP 0.959 vs 0.11 (8x), S-recall 1.0 vs 0.43" as *u8, "WebSearch/Mojeek/DDG/Brave" as *u8, "A+" as *u8, "live web crawl (corpus is 45-doc oracle pool)" as *u8, 0, 1); if rc != NX_SC_OK { return rc }
154 rc = nx_sc_emit_row(ctx, counts, "X25519 ECDH" as *u8, "crypto" as *u8, "~24x off (was 225x), 15x faster this push" as *u8, "OpenSSL" as *u8, "A+" as *u8, "G1 -> safegcd -> G2 5x51 limbs" as *u8, 4, 1); if rc != NX_SC_OK { return rc }
155 rc = nx_sc_emit_row(ctx, counts, "P-256 ECDSA" as *u8, "crypto" as *u8, "~488x off (was 3188x), 13.2x faster" as *u8, "OpenSSL" as *u8, "A+" as *u8, "G1-P2 -> G2 u128/MULX -> G3 ADX" as *u8, 4, 1); if rc != NX_SC_OK { return rc }
156 rc = nx_sc_emit_row(ctx, counts, "NX-EMU (RV64)" as *u8, "emu" as *u8, "~105x off; correct on 109 programs" as *u8, "qemu" as *u8, "A+" as *u8, "if-collapse -> predecode -> G4" as *u8, 4, 1); if rc != NX_SC_OK { return rc }
157 rc = nx_sc_emit_row(ctx, counts, "Sites daemon" as *u8, "sites" as *u8, "served-page 122-147ms, live on LAN" as *u8, "nginx/Caddy" as *u8, "A+" as *u8, "handshake rides crypto (G1+)" as *u8, 2, 1); if rc != NX_SC_OK { return rc }
158 rc = nx_sc_emit_row(ctx, counts, "Call / Voice" as *u8, "call" as *u8, "voice ~43dB @ 36kbps; 3-peer 0-loss" as *u8, "Zoom/Opus" as *u8, "A+ sov / D live" as *u8, "PESQ vs Opus; WAN latency bench" as *u8, 4, 1); if rc != NX_SC_OK { return rc }
159 rc = nx_sc_emit_row(ctx, counts, "Sovereign browser" as *u8, "browser" as *u8, "HTTP + JPEG->ASCII; no HTML layout yet" as *u8, "Chrome" as *u8, "A+" as *u8, "HTML block-layout engine" as *u8, 3, 0); if rc != NX_SC_OK { return rc }
160 rc = nx_sc_emit_row(ctx, counts, "Vision / captioner" as *u8, "vision" as *u8, "math + 3D-pose shipped; training loop designed" as *u8, "(pre-benchmark)" as *u8, "A+" as *u8, "label journal -> VLM distill -> 10K holdout" as *u8, 5, 0); if rc != NX_SC_OK { return rc }
161 rc = nx_sc_emit_row(ctx, counts, "GPU / sensors / print / game" as *u8, "hardware" as *u8, "4/5 UNMEASURED; BF x86 2.1-3.65x slower than gcc-O0" as *u8, "CUDA/llama.cpp/DirectX" as *u8, "mixed" as *u8, "x86 regalloc -> native-float codegen (GPU-M1)" as *u8, 4, 0); if rc != NX_SC_OK { return rc }
162
163 rc = nx_wiki_doc_write_z(ctx, "</tbody></table>" as *u8); if rc != NX_WIKI_DOC_OK { return rc }
164
165 // Roll-up: computed from the tally (not hardcoded).
166 rc = nx_wiki_doc_write_z(ctx, "<h2>Roll-up</h2><p>S (exceed): " as *u8); if rc != NX_WIKI_DOC_OK { return rc }
167 rc = nx_sc_emit_int(ctx, counts[0]); if rc != NX_SC_OK { return rc }
168 rc = nx_wiki_doc_write_z(ctx, " | A (parity): " as *u8); if rc != NX_WIKI_DOC_OK { return rc }
169 rc = nx_sc_emit_int(ctx, counts[1]); if rc != NX_SC_OK { return rc }
170 rc = nx_wiki_doc_write_z(ctx, " | B: " as *u8); if rc != NX_WIKI_DOC_OK { return rc }
171 rc = nx_sc_emit_int(ctx, counts[2]); if rc != NX_SC_OK { return rc }
172 rc = nx_wiki_doc_write_z(ctx, " | C: " as *u8); if rc != NX_WIKI_DOC_OK { return rc }
173 rc = nx_sc_emit_int(ctx, counts[3]); if rc != NX_SC_OK { return rc }
174 rc = nx_wiki_doc_write_z(ctx, " | D (behind): " as *u8); if rc != NX_WIKI_DOC_OK { return rc }
175 rc = nx_sc_emit_int(ctx, counts[4]); if rc != NX_SC_OK { return rc }
176 rc = nx_wiki_doc_write_z(ctx, " | pre (unmeasured): " as *u8); if rc != NX_WIKI_DOC_OK { return rc }
177 rc = nx_sc_emit_int(ctx, counts[5]); if rc != NX_SC_OK { return rc }
178 rc = nx_wiki_doc_write_z(ctx, "</p>" as *u8); if rc != NX_WIKI_DOC_OK { return rc }
179
180 // Keystone.
181 rc = nx_wiki_doc_write_z(ctx, "<h2>Keystone: G1 register allocation</h2><p>The raw-speed exceed across the D-class cars is gated by ONE substrate keystone: G1 register allocation. Phase-1 (rax-residency) is DEPLOYED and measured +8-13% on crypto, self-host byte-stable. Phase-2 (full linear-scan across loop bodies) is the next lever; it lifts every D-class crypto car. G2 (u128/MULX) and G3 (ADX) queue behind it.</p>" as *u8); if rc != NX_WIKI_DOC_OK { return rc }
182
183 // Honest caveats (1:1 discipline).
184 rc = nx_wiki_doc_write_z(ctx, "<h2>Honest caveats</h2><ul><li>Search S-class is on a 45-doc oracle pool, not a live web crawl: the ranking layer exceeds, the index is not yet sovereign-scraped.</li><li>Voice dB is synthetic-signal SNR, not PESQ-vs-Opus on real speech; sovereignty is A+, measured live-call quality is still D.</li><li>The 122-147ms page-load was the sites daemon served through a real browser; the sovereign browser itself is greenfield (no HTML render yet).</li><li>The hardware cars are mostly UNMEASURED (GPU tok/s=0, 0 real prints, 0 DirectX titles).</li></ul>" as *u8); if rc != NX_WIKI_DOC_OK { return rc }
185
186 rc = nx_wiki_doc_write_z(ctx, "<p class=\"status\">Source: 1:1 measured boards (NX_PITWALL 2026-05-29) + daily gates. v1 embeds the latest measured values as the Nishi source of truth; v2 wires live reads from each bench's Nishi-written results (still no shell/TSV).</p>" as *u8); if rc != NX_WIKI_DOC_OK { return rc }
187
188 return NX_SC_OK
189}
190
191// ===== Top-level handler: GET /wiki/status =================================================
192// Builds the page via the wiki render ctx (chrome + table CSS from the
193// legacy header), then HTTP-wraps. Returns NX_SC_OK (0) + resp byte count
194// via out_resp_n; negative verdict on overflow.
195func nx_wiki_status_handle(resp_buf: *u8, resp_cap: i64, out_resp_n: *i64) -> i64 {
196 if (resp_buf as i64) == 0 { return 0 - NX_SC_OVERFLOW }
197 if (out_resp_n as i64) == 0 { return 0 - NX_SC_OVERFLOW }
198 out_resp_n[0] = 0
199
200 let render_buf: *u8 = sys_mmap(NX_SC_RENDER_CAP)
201 let scratch: *u8 = sys_mmap(NX_SC_SCRATCH_CAP)
202 let ctx: *NxWikiDocCtx = (sys_mmap(512)) as *NxWikiDocCtx
203 let srcph: *u8 = "scorecard-status" as *u8
204 let srcl: i64 = nx_sc_strlen(srcph)
205
206 let rc_ci: i64 = nx_wiki_doc_ctx_init(ctx,
207 render_buf, NX_SC_RENDER_CAP,
208 srcph, srcl,
209 0 as *u8, 0, 0,
210 scratch, NX_SC_SCRATCH_CAP)
211 if rc_ci != NX_WIKI_DOC_OK { return rc_ci }
212
213 let title: *u8 = "Distance to S-Class" as *u8
214 let title_n: i64 = nx_sc_strlen(title)
215 let rc_h: i64 = nx_wiki_doc_write_header(ctx, title, title_n)
216 if rc_h != NX_WIKI_DOC_OK { return rc_h }
217
218 let rc_b: i64 = nx_sc_emit_html(ctx)
219 if rc_b != NX_SC_OK { return rc_b }
220
221 let rc_f: i64 = nx_wiki_doc_write_footer(ctx)
222 if rc_f != NX_WIKI_DOC_OK { return rc_f }
223
224 let body_len: i64 = ctx.out_off
225
226 // HTTP wrap: status line + headers + CRLFCRLF + body. Lengths scanned
227 // (no hand-counting) via nx_sc_put_z; Content-Length is itoa'd.
228 let off: *i64 = (sys_mmap(8)) as *i64
229 off[0] = 0
230 let rc_p1: i64 = nx_sc_put_z(resp_buf, off, resp_cap,
231 "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: " as *u8)
232 if rc_p1 != NX_SC_OK { return rc_p1 }
233
234 var bl: i64 = body_len
235 if bl == 0 {
236 if off[0] >= resp_cap { return 0 - NX_SC_OVERFLOW }
237 resp_buf[off[0]] = 0x30 as u8
238 off[0] = off[0] + 1
239 }
240 if bl > 0 {
241 let tmp: *u8 = sys_mmap(32)
242 var k: i64 = 0
243 while bl > 0 {
244 if k >= 32 { return 0 - NX_SC_OVERFLOW }
245 tmp[k] = (0x30 + (bl % 10)) as u8
246 bl = bl / 10
247 k = k + 1
248 }
249 var j: i64 = k - 1
250 while j >= 0 {
251 if off[0] >= resp_cap { return 0 - NX_SC_OVERFLOW }
252 resp_buf[off[0]] = tmp[j]
253 off[0] = off[0] + 1
254 j = j - 1
255 }
256 }
257
258 let rc_p2: i64 = nx_sc_put_z(resp_buf, off, resp_cap, "\r\n\r\n" as *u8)
259 if rc_p2 != NX_SC_OK { return rc_p2 }
260
261 if off[0] + body_len > resp_cap { return 0 - NX_SC_OVERFLOW }
262 var bi: i64 = 0
263 while bi < body_len {
264 resp_buf[off[0] + bi] = ctx.out_buf[bi]
265 bi = bi + 1
266 }
267 off[0] = off[0] + body_len
268
269 out_resp_n[0] = off[0]
270 return NX_SC_OK
271}