code wiki / _hdl_build / nx_codewiki_lib.nx

nx_codewiki_lib.nx source

↩ module page · 4797 lines · 262144 B

1// nx_codewiki_lib.nx -- THE CODE WIKI: an always-regenerable wiki OF the source tree. 2// 3// ===== WHY THIS EXISTS ============================================ 4// 5// The ecosystem has a charter wiki (runtime/wiki/, ~100 curated pages) and a 6// corpus search (nishi_search), but NOTHING that answers, for a given module: 7// what does it do, what does it import, WHO IMPORTS IT, what functions does 8// it export, and where do I look next. That is the Google-Code-Wiki class of 9// artifact: generated FROM the code, never hand-maintained, stale-proof 10// because regeneration is one command and the output is deterministic. 11// 12// It is deliberately a STATIC generator, not a daemon: 13// - the charter wiki daemon is sized for ~100 docs (docs_cap) and serves 14// public charter sites; 17k code pages do not belong in its pools 15// - static bytes are gateable (byte-identical re-run), diffable, and 16// servable by any route -- or browsable as local files with zero infra 17// 18// ===== WHAT IS REUSED (the dupfunc law: the tool must not duplicate) ====== 19// 20// gl_walk / gl_read (nx_gatelib) -- the ONE tree walk + file read 21// nis_scan (nx_import_scan) -- the ONE accurate import scanner 22// EcoGraph (nx_eco_graph) -- intern + CSR fan-in/fan-out 23// 24// gl_walk's edge mode is NOT used: it interns import paths verbatim, so a 25// subdir import ("wiki/nx_foo.nx") would become a node DISTINCT from the 26// basename node of the actual file and every such link would dangle. We 27// intern the BASENAME of each import ourselves -- same convention as file 28// nodes -- so links resolve, and what still cannot resolve is reported as 29// an honest unresolved count instead of a dead href. 30// 31// ===== ENVELOPES (declared, per the scale law) ===================== 32// CW_MAXNODE 24000 nodes | CW_EDGECAP 262144 edges | file cap GL_FILECAP 33// CW_PAGECAP 4 MiB/page -- overflow appends a LOUD PAGE-TRUNCATED banner 34// CW_MAXDIRS 256 | desc arena 2 MiB | per-file import dedup window 128 35// 36// license_tier: ORIGINAL 37import "nx_syscalls.nx" 38import "nx_eco_graph.nx" 39import "nx_gatelib.nx" 40import "nx_import_scan.nx" 41const CW_MAGIC_2166136261: i64 = 2166136261 42const CW_MAGIC_16777619: i64 = 16777619 43const CW_MAGIC_1024: i64 = 1024 44const CW_MAGIC_65536: i64 = 65536 45const CW_MAGIC_262144: i64 = 262144 46const CW_MAGIC_86400: i64 = 86400 47const CW_MAGIC_131072: i64 = 131072 48const CW_MAGIC_4096: i64 = 4096 49const CW_MAGIC_1469598103934665603: i64 = 1469598103934665603 50const CW_MAGIC_1099511628211: i64 = 1099511628211 51 52const CW_MAXNODE: i64 = 24000 // units=modules; tree measured 17,491 today (2026-07-29 census) = 37% headroom 53const CW_ARENA: i64 = 4194304 54const CW_HASH: i64 = 65536 55const CW_PATHARENA: i64 = 8388608 56const CW_EDGECAP: i64 = 262144 // units=import edges; measured 44,399 (2026-07-27) = 5.9x headroom 57// 4 MiB: the root-directory listing alone is ~2.1 MiB (10702 rows); a module 58// page tops out near ~1 MiB worst-case (256 KiB source fully escaped). 59const CW_PAGECAP: i64 = 4194304 // units=bytes; == the measured 4MB edge serving cap (a bigger page cannot ship); overflow -> loud banner (T8) 60const CW_PAGERESERVE: i64 = 192 61const CW_MAXDIRS: i64 = 256 // units=dirs; tree measured 13 today -- headroom visible on purpose 62const CW_DESCARENA: i64 = 2097152 63const CW_DESCMAX: i64 = 160 64const CW_TOPK: i64 = 20 65const CW_IMPDEDUP: i64 = 128 66const CW_SHOWIN: i64 = 100 67// function index (search): every top-level func across the tree, DECLARED cap 68const CW_MAXFN: i64 = 131072 // units=funcs; measured 91,067 today (2026-07-29 regen) = 1.4x headroom; cap declared on the search page 69const CW_FNARENA: i64 = 4194304 70// architecture SVG: hubs plotted, DECLARED cap 71const CW_SVGN: i64 = 36 72// topic families: derived from the tree's own naming discipline (nx_<fam>_*) 73const CW_MAXFAM: i64 = 4096 // units=families; measured ~750 today (threshold-4 rule) = 5x headroom 74const CW_FAMARENA: i64 = 131072 75const CW_FAMMIN: i64 = 4 76const CW_SBFAM: i64 = 16 77// call graph: defs share CW_MAXFN; sites/edges DECLARED caps 78const CW_MAXSITE: i64 = 2097152 79const CW_SITEARENA: i64 = 33554432 80const CW_DEFHASH: i64 = 262144 81const CW_CALLSHOW: i64 = 6 82const CW_CALLDEDUP: i64 = 64 83// module KINDS -- what each file IS, by measurable rule (precedence declared 84// on the census page; first match wins; "generated fixture" needs either the 85// literal marker in its own header or family-scale + tiny size, both measured) 86const CW_NKIND: i64 = 11 87const CW_K_ARCHIVED: i64 = 0 88const CW_K_GATE: i64 = 1 89const CW_K_BENCH: i64 = 2 90const CW_K_PROBE: i64 = 3 91const CW_K_SMOKE: i64 = 4 92const CW_K_SKETCH: i64 = 5 93const CW_K_GENFIX: i64 = 6 94const CW_K_SERVICE: i64 = 7 95const CW_K_TOOL: i64 = 8 96const CW_K_LIB: i64 = 9 97const CW_K_ORPHAN: i64 = 10 98const CW_GENFIX_FAM: i64 = 200 99const CW_GENFIX_LOC: i64 = 40 100const CW_KINDSHOW: i64 = 24 101// findings: detectors -> the WORK BACKLOG. Each finding is one line in the 102// exact nx_debt grammar (sev<TAB>scope<TAB>desc) with a STABLE description -- 103// no counts, no dates -- so the filing bridge is idempotent by construction 104// (nx_debt dedups on exact desc). Live numbers stay on the wiki pages the 105// descs cite; the debt row is the pointer, the wiki is the gauge. 106const CW_FINDCAP: i64 = 65536 // units=bytes; findings feed measured ~30 rows x ~200B today = 10x headroom 107const CW_SPRAWLMAX: i64 = 12 108// DEBT TAXONOMY -- the categories the operator named. Each is detected by 109// markers a module carries in its OWN comments (the tree already documents its 110// hazards; the wiki just makes them countable + backlog-fed). One bit per 111// category in a per-module mask; a marker-scan in pass 1 sets the bits. 112const CW_NCAT: i64 = 8 113const CW_CAT_LANDMINE: i64 = 0 114const CW_CAT_WORKAROUND: i64 = 1 115const CW_CAT_GOTCHA: i64 = 2 116const CW_CAT_TODO: i64 = 3 117const CW_CAT_THIRDPARTY: i64 = 4 118const CW_CAT_SECURITY: i64 = 5 119const CW_CAT_PERF: i64 = 6 120const CW_CAT_DEPRECATED: i64 = 7 121const CW_CATSHOW: i64 = 20 122const CW_LANGSHOW: i64 = 24 123// TARGETED findings: for the severe categories, name INDIVIDUAL modules so each 124// is a pickable work item, ranked by fan-in (blast radius). Capped so the board 125// gets actionable rows, not a flood; the aggregate finding still covers the tail. 126const CW_TGTCAP: i64 = 8 127const CW_TGTSEV: i64 = 7 128// exposure join (where MCP/APIs are needed): input caps DECLARED 129const CW_EXPCONF: i64 = 1048576 130const CW_EXPELFS: i64 = 4096 // units=elfs; deployed set measured ~700 (496 exposed + 211 dark) = 5x headroom 131const CW_EXPARENA: i64 = 262144 132const CW_EXPSHOW: i64 = 40 133// retrieval (ask): index read cap, hit cap, question-token cap -- all DECLARED 134// searchable header text per module (the doc block, not just line 1): the 135// difference between "the first sentence mentions it" and "the file explains 136// itself". Display still uses the short desc; retrieval reads this. 137const CW_SDOCMAX: i64 = 1400 138const CW_SDOCARENA: i64 = 41943040 139const CW_ASKDESCMAX: i64 = 150 140const CW_ASKCAP: i64 = 41943040 141// ★The ask index is a DATA FILE, not a page: it must never share the page 142// buffer's 4 MiB envelope. It silently held 10% of the corpus for a whole 143// evening because it did -- the truncation banner fired into the TSV and the 144// count sat in a line of output nobody read. Own buffer, own cap, and a 145// LOUD REFUSAL if it ever overflows again. 146const CW_ASKIDXCAP: i64 = 67108864 // units=bytes; sized for the measured 108.9k-record corpus w/ headroom; truncation REFUSES loudly (T33 + rc=4) 147const CW_ASKTOP: i64 = 10 148const CW_ASKQTOK: i64 = 16 149const CW_ASKMINTOK: i64 = 3 150// RARITY WEIGHTING, in permil of the corpus (relative, so the bands hold for a 151// 16-record fixture and a 103k-record tree alike). A token in 0.5% of records 152// carries far more signal than one in 30% -- flat scoring let "function" drown 153// "duplicate" on a real question, which is how this was found. 154const CW_IDF_P1: i64 = 5 155const CW_IDF_W1: i64 = 12 156const CW_IDF_P2: i64 = 30 157const CW_IDF_W2: i64 = 8 158const CW_IDF_P3: i64 = 100 159const CW_IDF_W3: i64 = 5 160const CW_IDF_P4: i64 = 300 161const CW_IDF_W4: i64 = 3 162const CW_IDF_W5: i64 = 1 163const CW_ASKNAMEX: i64 = 2 164 165// ---------- tiny string/number helpers (ordered before use) ---------- 166 167func cw_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 168 169// bounded append; pos[0]=len, pos[1]=overflow flag. Reserve keeps room for the banner. 170func cw_app(buf: *u8, pos: *i64, cap: i64, s: *u8, n: i64) -> i64 { 171 if pos[0] + n >= cap - CW_PAGERESERVE { pos[1] = 1; return 0 } 172 var i: i64 = 0 173 while i < n { buf[pos[0] + i] = s[i]; i = i + 1 } 174 pos[0] = pos[0] + n 175 return 0 176} 177 178func cw_apps(buf: *u8, pos: *i64, cap: i64, s: *u8) -> i64 { return cw_app(buf, pos, cap, s, cw_slen(s)) } 179 180// append a decimal number, in place (digits written then reversed -- zero allocation). 181func cw_appn(buf: *u8, pos: *i64, cap: i64, v: i64) -> i64 { 182 if pos[0] + 24 >= cap - CW_PAGERESERVE { pos[1] = 1; return 0 } 183 var m: i64 = v 184 if m < 0 { buf[pos[0]] = 45 as u8; pos[0] = pos[0] + 1; m = 0 - m } 185 let start: i64 = pos[0] 186 if m == 0 { buf[pos[0]] = 48 as u8; pos[0] = pos[0] + 1; return 0 } 187 while m > 0 { buf[pos[0]] = (48 + (m % 10)) as u8; pos[0] = pos[0] + 1; m = m / 10 } 188 var a: i64 = start 189 var b: i64 = pos[0] - 1 190 while a < b { 191 let t: u8 = buf[a]; buf[a] = buf[b]; buf[b] = t 192 a = a + 1; b = b - 1 193 } 194 return 0 195} 196 197// HTML-escaped append of raw source-derived bytes. 198func cw_appe(buf: *u8, pos: *i64, cap: i64, s: *u8, n: i64) -> i64 { 199 var i: i64 = 0 200 while i < n { 201 let c: i64 = s[i] as i64 202 if c == 38 { cw_app(buf, pos, cap, "&amp;" as *u8, 5) } 203 if c == 60 { cw_app(buf, pos, cap, "&lt;" as *u8, 4) } 204 if c == 62 { cw_app(buf, pos, cap, "&gt;" as *u8, 4) } 205 if c != 38 { if c != 60 { if c != 62 { 206 if pos[0] + 1 >= cap - CW_PAGERESERVE { pos[1] = 1 } else { buf[pos[0]] = s[i]; pos[0] = pos[0] + 1 } 207 } } } 208 i = i + 1 209 } 210 return 0 211} 212 213// write buf to path; if the overflow flag is set, append the LOUD banner first. 214// A silently clipped page is indistinguishable from a complete one -- the 215// banner is the honesty device, and the gate has a tooth for it. 216func cw_flush(path: *u8, buf: *u8, pos: *i64, cap: i64) -> i64 { 217 if pos[1] == 1 { 218 let bn: *u8 = "\n<p class='trunc'>PAGE-TRUNCATED at declared cap</p><!-- PAGE-TRUNCATED -->\n" as *u8 219 let bl: i64 = cw_slen(bn) 220 var i: i64 = 0 221 while i < bl { buf[pos[0] + i] = bn[i]; i = i + 1 } 222 pos[0] = pos[0] + bl 223 } 224 let fd: i64 = sys_openat_wr(path, 420) 225 if fd < 0 { return 0 - 1 } 226 var off: i64 = 0 227 while off < pos[0] { 228 let w: i64 = sys_write(fd, ((buf as i64) + off) as *u8, pos[0] - off) 229 if w <= 0 { sys_close(fd); return 0 - 1 } 230 off = off + w 231 } 232 sys_close(fd) 233 return 0 234} 235 236// basename start offset within a nul-terminated path 237func cw_base(path: *u8) -> i64 { 238 var i: i64 = 0 239 var last: i64 = 0 240 while path[i] != (0 as u8) { 241 if path[i] == (47 as u8) { last = i + 1 } 242 i = i + 1 243 } 244 return last 245} 246 247// stem length of a basename (minus trailing .nx) 248func cw_stemlen(nm: *u8) -> i64 { 249 let n: i64 = cw_slen(nm) 250 if gl_is_nx(nm, n) == 1 { return n - 3 } 251 return n 252} 253 254func cw_rawcpy(dst: *u8, at: i64, s: *u8) -> i64 { 255 var i: i64 = 0 256 while s[i] != (0 as u8) { dst[at + i] = s[i]; i = i + 1 } 257 return i 258} 259 260// build outdir/<stem>.html into dst; a module literally named index.nx would 261// clobber the wiki index, so it gets index.mod.html (guard, declared). 262func cw_pagepath(dst: *u8, outdir: *u8, nm: *u8) -> i64 { 263 var w: i64 = 0 264 var i: i64 = 0 265 while outdir[i] != (0 as u8) { dst[w] = outdir[i]; w = w + 1; i = i + 1 } 266 dst[w] = 47 as u8; w = w + 1 267 let sl: i64 = cw_stemlen(nm) 268 var guard: i64 = 0 269 if sl == 5 { 270 if nm[0] == (105 as u8) { if nm[1] == (110 as u8) { if nm[2] == (100 as u8) { if nm[3] == (101 as u8) { if nm[4] == (120 as u8) { guard = 1 } } } } } 271 } 272 var j: i64 = 0 273 while j < sl { dst[w] = nm[j]; w = w + 1; j = j + 1 } 274 if guard == 1 { cw_rawcpy(dst, w, ".mod" as *u8); w = w + 4 } 275 cw_rawcpy(dst, w, ".html" as *u8) 276 w = w + 5 277 dst[w] = 0 as u8 278 return w 279} 280 281// append <a href='stem[.html]'>name</a> for a node known to have a page. 282// noext=1 emits extensionless hrefs (the edge's canonical form -- kills the 283// per-click 301); files on disk are ALWAYS <stem>.html either way. 284func cw_applink2(buf: *u8, pos: *i64, cap: i64, nm: *u8, noext: i64) -> i64 { 285 cw_apps(buf, pos, cap, "<a href='" as *u8) 286 let sl: i64 = cw_stemlen(nm) 287 cw_app(buf, pos, cap, nm, sl) 288 var guard: i64 = 0 289 if sl == 5 { 290 if nm[0] == (105 as u8) { if nm[1] == (110 as u8) { if nm[2] == (100 as u8) { if nm[3] == (101 as u8) { if nm[4] == (120 as u8) { guard = 1 } } } } } 291 } 292 if guard == 1 { cw_apps(buf, pos, cap, ".mod" as *u8) } 293 if noext == 0 { cw_apps(buf, pos, cap, ".html" as *u8) } 294 cw_apps(buf, pos, cap, "'>" as *u8) 295 cw_appe(buf, pos, cap, nm, cw_slen(nm)) 296 cw_apps(buf, pos, cap, "</a>" as *u8) 297 return 0 298} 299 300func cw_applink(buf: *u8, pos: *i64, cap: i64, nm: *u8) -> i64 { 301 return cw_applink2(buf, pos, cap, nm, 0) 302} 303 304// href suffix for generated non-module pages (search/arch/dir/index) 305func cw_appext(buf: *u8, pos: *i64, cap: i64, noext: i64) -> i64 { 306 if noext == 0 { cw_apps(buf, pos, cap, ".html" as *u8) } 307 return 0 308} 309 310// JS-string-escaped append (into generated .js index files): \ and " escaped, 311// CR dropped, < emitted as \x3c so a desc can never close the script context. 312func cw_appjse(buf: *u8, pos: *i64, cap: i64, s: *u8, n: i64) -> i64 { 313 var i: i64 = 0 314 while i < n { 315 let c: i64 = s[i] as i64 316 var done: i64 = 0 317 if c == 92 { cw_app(buf, pos, cap, "\\\\" as *u8, 2); done = 1 } 318 if c == 34 { cw_app(buf, pos, cap, "\\\"" as *u8, 2); done = 1 } 319 if c == 60 { cw_app(buf, pos, cap, "\\x3c" as *u8, 4); done = 1 } 320 if c == 13 { done = 1 } 321 if c == 10 { done = 1 } 322 if done == 0 { 323 if pos[0] + 1 >= cap - CW_PAGERESERVE { pos[1] = 1 } else { buf[pos[0]] = s[i]; pos[0] = pos[0] + 1 } 324 } 325 i = i + 1 326 } 327 return 0 328} 329 330// ---------- shared page chrome (literals kept well under the nx_cc ceiling) ---------- 331 332// The app shell: a fixed sidebar + main column, tokenized dark design. 333// CSS split into small literals (nx_cc literal ceiling). 334func cw_css(buf: *u8, pos: *i64, cap: i64) -> i64 { 335 // docs-grade light theme first; dark honored via prefers-color-scheme. 336 cw_apps(buf, pos, cap, ":root{--bg:#ffffff;--sf:#f6f8fb;--sf2:#eef1f6;--br:#dfe4ec;--ink:#232936;--mut:#68748a;--acc:#1a5dc8;--acc2:#2e8555;--hd:#111726;--hov:#f0f4fa;--hl:#fff3c4;--svgb:#eef2f8;--svgs:#b9c4d8;--svgt:#28406b;--svgc:#dbe4f2}\n" as *u8) 337 cw_apps(buf, pos, cap, "@media(prefers-color-scheme:dark){:root{--bg:#0d1017;--sf:#131826;--sf2:#1a2132;--br:#252d40;--ink:#dbe2ec;--mut:#8a94a8;--acc:#5aa7f0;--acc2:#86c793;--hd:#eef2f8;--hov:#141a28;--hl:#22304d;--svgb:#1a2132;--svgs:#33405c;--svgt:#9fc0e8;--svgc:#20304a}}\n" as *u8) 338 cw_apps(buf, pos, cap, "*{box-sizing:border-box}body{font-family:system-ui,'Segoe UI',sans-serif;margin:0;background:var(--bg);color:var(--ink);display:grid;grid-template-columns:252px minmax(0,1fr);min-height:100vh}\n" as *u8) 339 cw_apps(buf, pos, cap, "a{color:var(--acc);text-decoration:none}a:hover{text-decoration:underline}\n" as *u8) 340 cw_apps(buf, pos, cap, "nav.sb{background:var(--sf);border-right:1px solid var(--br);padding:14px 12px;position:sticky;top:0;height:100vh;overflow-y:auto;font-size:.9em}\n" as *u8) 341 cw_apps(buf, pos, cap, ".sb .brand{display:block;font-weight:700;color:var(--hd);font-size:1.02em;margin:2px 6px 12px}\n" as *u8) 342 cw_apps(buf, pos, cap, ".sb a.it{display:block;padding:4px 8px;border-radius:6px;color:var(--ink)}.sb a.it:hover{background:var(--sf2);text-decoration:none;color:var(--hd)}\n" as *u8) 343 cw_apps(buf, pos, cap, ".sb .sec{margin:14px 6px 4px;font-size:.74em;letter-spacing:.09em;text-transform:uppercase;color:var(--mut)}\n" as *u8) 344 cw_apps(buf, pos, cap, ".sb .ct{float:right;color:var(--mut);font-size:.85em;font-variant-numeric:tabular-nums}\n" as *u8) 345 cw_apps(buf, pos, cap, "main{padding:22px 30px 40px;max-width:1080px;min-width:0}\n" as *u8) 346 cw_apps(buf, pos, cap, ".crumb{font-size:.85em;color:var(--mut);margin-bottom:10px}.crumb a{color:var(--mut)}.crumb a:hover{color:var(--acc)}\n" as *u8) 347 cw_apps(buf, pos, cap, "h1{font-size:1.55em;color:var(--hd);margin:2px 0 6px;letter-spacing:-.01em}\n" as *u8) 348 cw_apps(buf, pos, cap, "h2{font-size:1.02em;color:var(--hd);margin:26px 0 8px;padding-bottom:5px;border-bottom:1px solid var(--br)}h2 .cnt{color:var(--mut);font-weight:400;font-size:.85em}\n" as *u8) 349 cw_apps(buf, pos, cap, "code,pre,.sig{font-family:ui-monospace,'Cascadia Code',Consolas,monospace;font-size:.86em}\n" as *u8) 350 cw_apps(buf, pos, cap, ".meta{display:flex;flex-wrap:wrap;gap:6px;margin:10px 0 4px}.chip{background:var(--sf);border:1px solid var(--br);border-radius:20px;padding:2px 11px;font-size:.8em;color:var(--ink)}.chip b{color:var(--hd);font-weight:600}\n" as *u8) 351 cw_apps(buf, pos, cap, ".toc{display:flex;flex-wrap:wrap;gap:6px;margin:8px 0 2px}.toc a{background:var(--sf2);border-radius:6px;padding:2px 10px;font-size:.8em}\n" as *u8) 352 cw_apps(buf, pos, cap, ".fnc{margin-top:4px;font-size:.86em}.fnc .lab{color:var(--mut);font-size:.85em}\n" as *u8) 353 cw_apps(buf, pos, cap, ".cta{display:inline-block;background:var(--acc);color:#fff !important;border-radius:8px;padding:9px 20px;margin:8px 8px 8px 0;font-size:.95em}.cta:hover{text-decoration:none;filter:brightness(1.1)}\n" as *u8) 354 cw_apps(buf, pos, cap, ".doc{background:var(--sf);border:1px solid var(--br);border-left:3px solid var(--acc);border-radius:8px;padding:12px 16px;white-space:pre-wrap;font-size:.88em;color:var(--ink);line-height:1.55;overflow-x:auto}\n" as *u8) 355 cw_apps(buf, pos, cap, ".nar{background:var(--sf);border:1px solid var(--br);border-left:3px solid var(--acc2);border-radius:8px;padding:12px 16px;font-size:.92em;line-height:1.6}\n" as *u8) 356 cw_apps(buf, pos, cap, ".tiles{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:10px;margin:14px 0}.tile{background:var(--sf);border:1px solid var(--br);border-radius:10px;padding:12px 14px}.tile .v{font-size:1.5em;color:var(--hd);font-variant-numeric:tabular-nums}.tile .k{font-size:.78em;color:var(--mut);margin-top:2px}\n" as *u8) 357 cw_apps(buf, pos, cap, "table{border-collapse:collapse;width:100%}td,th{padding:4px 10px;border-bottom:1px solid var(--br);text-align:left;vertical-align:top}th{color:var(--mut);font-size:.85em}\n" as *u8) 358 cw_apps(buf, pos, cap, "tr:hover td{background:var(--hov)}.n{text-align:right;color:var(--mut);font-variant-numeric:tabular-nums}.muted{color:var(--mut)}.ext{color:#a89a6e}\n" as *u8) 359 cw_apps(buf, pos, cap, ".trunc{background:#4a1f1f;color:#ffb0b0;padding:6px 10px;font-weight:bold}\n" as *u8) 360 cw_apps(buf, pos, cap, ".pill{display:inline-block;background:var(--sf2);border:1px solid var(--br);border-radius:14px;padding:1px 10px;margin:2px 4px 2px 0;font-size:.83em}\n" as *u8) 361 cw_apps(buf, pos, cap, "input{background:var(--sf);color:var(--ink);border:1px solid var(--br);border-radius:8px;padding:7px 12px;margin:8px 0;width:340px;font-size:.95em}input:focus{outline:1px solid var(--acc)}\n" as *u8) 362 cw_apps(buf, pos, cap, ".svgwrap{overflow-x:auto;background:var(--sf);border:1px solid var(--br);border-radius:10px;padding:8px;margin:8px 0}\n" as *u8) 363 cw_apps(buf, pos, cap, ".srcv{background:var(--sf);border:1px solid var(--br);border-radius:8px;padding:8px 0;overflow-x:auto;font-family:ui-monospace,Consolas,monospace;font-size:.84em;line-height:1.5}\n" as *u8) 364 cw_apps(buf, pos, cap, ".srcv .l{display:block;padding:0 14px;white-space:pre}.srcv .l:target{background:var(--hl)}.srcv .ln{display:inline-block;min-width:52px;text-align:right;padding-right:16px;color:var(--mut)}\n" as *u8) 365 cw_apps(buf, pos, cap, "footer{margin-top:36px;padding-top:10px;border-top:1px solid var(--br);font-size:.8em;color:var(--mut)}\n" as *u8) 366 cw_apps(buf, pos, cap, ".vd{background:linear-gradient(135deg,var(--sf),var(--sf2));border:1px solid var(--br);border-radius:14px;padding:22px 26px;margin:14px 0}.vd .big{font-size:1.7em;font-weight:700;color:var(--hd);letter-spacing:-.01em}.vd .sub{color:var(--mut);margin-top:6px;line-height:1.55;max-width:70ch}\n" as *u8) 367 cw_apps(buf, pos, cap, ".kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(215px,1fr));gap:12px;margin:14px 0}.pk{background:var(--sf);border:1px solid var(--br);border-radius:12px;padding:16px 18px}.pk .lab{font-size:.76em;letter-spacing:.06em;text-transform:uppercase;color:var(--mut)}.pk .val{font-size:2.1em;font-weight:700;color:var(--hd);font-variant-numeric:tabular-nums;margin:2px 0}\n" as *u8) 368 cw_apps(buf, pos, cap, ".pk .d{display:inline-block;border-radius:12px;padding:1px 9px;font-size:.8em;font-weight:600}.pk .dg{background:color-mix(in srgb,var(--acc2) 16%,transparent);color:var(--acc2)}.pk .db{background:color-mix(in srgb,#c0392b 14%,transparent);color:#c0392b}.pk .goal{font-size:.75em;color:var(--mut);margin-top:5px}\n" as *u8) 369 cw_apps(buf, pos, cap, "@media(max-width:880px){body{grid-template-columns:1fr}nav.sb{position:static;height:auto;border-right:0;border-bottom:1px solid var(--br)}}\n" as *u8) 370 return 0 371} 372 373// head3: doctype + css + sidebar (sb = prebuilt nul-terminated html) + <main> 374func cw_head3(buf: *u8, pos: *i64, cap: i64, title: *u8, tn: i64, sb: *u8) -> i64 { 375 cw_apps(buf, pos, cap, "<!doctype html>\n<html lang='en'><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'>\n<title>" as *u8) 376 cw_appe(buf, pos, cap, title, tn) 377 cw_apps(buf, pos, cap, " - nishi code wiki</title>\n<style>\n" as *u8) 378 cw_css(buf, pos, cap) 379 cw_apps(buf, pos, cap, "</style></head><body>\n" as *u8) 380 cw_apps(buf, pos, cap, sb) 381 // AD ANCHOR (2026-07-31). The edge injects the labeled ad slot at this marker; with NO marker it 382 // falls back to just before the closing body tag -- the absolute bottom of the page, where a 383 // reference page of tables means essentially nobody scrolls. MRC viewability needs 50% of the 384 // creative in view for one CONTINUOUS second, so footer placement made viewable impressions 385 // structurally near-zero: we measured honestly and still sold a position nobody sees. 386 // TOP-OF-CONTENT IS THE FORMAT-APPROPRIATE POSITION, not a preference: the creative is 728x90, 387 // the IAB leaderboard, which exists for exactly this slot. The size dictates the convention. 388 // TO MOVE OR REMOVE: delete this one emit line (pages regenerate with no marker and the edge 389 // reverts to the old footer behaviour), or emit the marker from a later block instead. 390 cw_apps(buf, pos, cap, "<main>\n" as *u8) 391 cw_apps(buf, pos, cap, "<!--nx-ad-slot-->\n" as *u8) 392 return 0 393} 394 395// breadcrumb row: code wiki / <dir> / <self> 396func cw_crumb(buf: *u8, pos: *i64, cap: i64, noext: i64, dlabel: *u8, dslug: *u8, self: *u8, sn: i64) -> i64 { 397 cw_apps(buf, pos, cap, "<div class='crumb'><a href='index" as *u8) 398 cw_appext(buf, pos, cap, noext) 399 cw_apps(buf, pos, cap, "'>code wiki</a>" as *u8) 400 if (dslug as i64) != 0 { 401 cw_apps(buf, pos, cap, " / <a href='" as *u8) 402 cw_apps(buf, pos, cap, dslug) 403 cw_appext(buf, pos, cap, noext) 404 cw_apps(buf, pos, cap, "'>" as *u8) 405 if cw_slen(dlabel) == 0 { cw_apps(buf, pos, cap, "(root)" as *u8) } else { cw_appe(buf, pos, cap, dlabel, cw_slen(dlabel)) } 406 cw_apps(buf, pos, cap, "</a>" as *u8) 407 } 408 if sn > 0 { 409 cw_apps(buf, pos, cap, " / " as *u8) 410 cw_appe(buf, pos, cap, self, sn) 411 } 412 cw_apps(buf, pos, cap, "</div>\n" as *u8) 413 return 0 414} 415 416func cw_foot(buf: *u8, pos: *i64, cap: i64) -> i64 { 417 cw_apps(buf, pos, cap, "\n<footer>generated by nx_codewiki from the source tree -- every number measured, nothing hand-edited. regenerate any time.</footer>\n</main></body></html>\n" as *u8) 418 return 0 419} 420 421// the tiny client-side filter used on listing pages (plain JS -- the CSP 422// doctrine allows plain script, and locally it is just a file). 423func cw_filterjs(buf: *u8, pos: *i64, cap: i64) -> i64 { 424 cw_apps(buf, pos, cap, "<input id='q' placeholder='filter...' oninput='f()'>\n<script>\n" as *u8) 425 cw_apps(buf, pos, cap, "function f(){var q=document.getElementById('q').value.toLowerCase();var r=document.querySelectorAll('tr[data-m]');for(var i=0;i<r.length;i++){var m=r[i].getAttribute('data-m');r[i].style.display=(m.indexOf(q)>=0)?'':'none';}}\n" as *u8) 426 cw_apps(buf, pos, cap, "</script>\n" as *u8) 427 return 0 428} 429 430// ---------- per-file line classification ---------- 431 432func cw_line_starts(buf: *u8, ls: i64, le: i64, kw: *u8) -> i64 { 433 let kl: i64 = cw_slen(kw) 434 if ls + kl > le { return 0 } 435 var i: i64 = 0 436 while i < kl { if buf[ls + i] != kw[i] { return 0 } i = i + 1 } 437 return 1 438} 439 440// signature end: trim trailing spaces and a trailing '{' 441func cw_sigend(buf: *u8, ls: i64, le: i64) -> i64 { 442 var e: i64 = le 443 var go: i64 = 1 444 while go == 1 { 445 if e <= ls { go = 0 } else { 446 let c: i64 = buf[e - 1] as i64 447 if c == 123 { e = e - 1 } else { 448 if c == 32 { e = e - 1 } else { 449 if c == 9 { e = e - 1 } else { go = 0 } 450 } 451 } 452 } 453 } 454 return e 455} 456 457// extract quoted path range on an import line; returns start, writes len to out[0]; -1 if none 458func cw_impquote(buf: *u8, ls: i64, le: i64, out: *i64) -> i64 { 459 var q: i64 = ls 460 var s: i64 = 0 - 1 461 while q < le { 462 if buf[q] == (34 as u8) { 463 if s < 0 { s = q + 1 } else { 464 out[0] = q - s 465 return s 466 } 467 } 468 q = q + 1 469 } 470 return 0 - 1 471} 472 473// basename range within a quoted import path buf[s..s+n) 474func cw_impbase(buf: *u8, s: i64, n: i64, out: *i64) -> i64 { 475 var last: i64 = s 476 var i: i64 = s 477 while i < s + n { 478 if buf[i] == (47 as u8) { last = i + 1 } 479 i = i + 1 480 } 481 out[0] = (s + n) - last 482 return last 483} 484 485// ---------- graph analysis (transitive impact + layering) ---------- 486// 487// Reach counting uses EPOCH STAMPS, not a per-node memset: clearing a 17k 488// visited array 17k times is ~580M byte-writes for ~800k useful steps. A 489// stamp array + monotonically increasing epoch makes each closure O(reachable). 490// Iterative explicit stack -- a 14k-node cone must not become 14k stack frames. 491// dirn 0 = out-closure (transitive imports), 1 = in-closure (transitive importers). 492// NEWEST SOURCE ANYWHERE IN A MODULE'S IMPORT CLOSURE (seq1721). 493// 494// The shipped-drift gauge first compared a deployed elf against its module's 495// OWN source, which under-reports badly: a binary is equally stale when a 496// DEPENDENCY changed and it was never rebuilt -- and that is the common case, 497// since a fix usually lands in a shared lib. Same epoch-stamped walk as 498// cw_reach_count (no per-node memset, explicit stack, O(reachable)); returns 499// max(srcmt) over {start} + everything start transitively imports. 500// dirn is fixed at 0 (out-closure = what this module depends on) because that 501// is the only direction that can invalidate a build. 502func cw_reach_maxmt(g: *EcoGraph, start: i64, stampv: *i64, epoch: i64, stack: *i64, srcmt: *i64) -> i64 { 503 var best: i64 = srcmt[start] 504 var sp: i64 = 0 505 stampv[start] = epoch 506 stack[sp] = start 507 sp = sp + 1 508 while sp > 0 { 509 sp = sp - 1 510 let u: i64 = stack[sp] 511 if srcmt[u] > best { best = srcmt[u] } 512 var p: i64 = g.out_head[u] 513 let e: i64 = g.out_head[u + 1] 514 while p < e { 515 let v: i64 = g.out_list[p] 516 if stampv[v] != epoch { 517 stampv[v] = epoch 518 stack[sp] = v 519 sp = sp + 1 520 } 521 p = p + 1 522 } 523 } 524 return best 525} 526 527func cw_reach_count(g: *EcoGraph, start: i64, dirn: i64, stampv: *i64, epoch: i64, stack: *i64) -> i64 { 528 var cnt: i64 = 0 529 var sp: i64 = 0 530 stampv[start] = epoch 531 stack[sp] = start 532 sp = sp + 1 533 while sp > 0 { 534 sp = sp - 1 535 let u: i64 = stack[sp] 536 var p: i64 = 0 537 var e: i64 = 0 538 if dirn == 0 { p = g.out_head[u]; e = g.out_head[u + 1] } else { p = g.in_head[u]; e = g.in_head[u + 1] } 539 while p < e { 540 var v: i64 = 0 541 if dirn == 0 { v = g.out_list[p] } else { v = g.in_list[p] } 542 if stampv[v] != epoch { 543 stampv[v] = epoch 544 cnt = cnt + 1 545 stack[sp] = v 546 sp = sp + 1 547 } 548 p = p + 1 549 } 550 } 551 return cnt 552} 553 554// longest-path depth over the import DAG: leaves (no imports) = 0, else 555// 1 + max(depth of imports). Memoized; recursion depth = longest chain (~tens). 556func cw_depth_of(g: *EcoGraph, u: i64, memo: *i64) -> i64 { 557 if memo[u] >= 0 { return memo[u] } 558 memo[u] = 0 559 var best: i64 = 0 560 var p: i64 = g.out_head[u] 561 let e: i64 = g.out_head[u + 1] 562 while p < e { 563 let d: i64 = cw_depth_of(g, g.out_list[p], memo) + 1 564 if d > best { best = d } 565 p = p + 1 566 } 567 memo[u] = best 568 return best 569} 570 571// ---------- deterministic ordering ---------- 572// 573// getdents enumeration order is filesystem- and mount-state-dependent (a 9p 574// remount reordered it mid-session and silently changed the tree stamp with 575// zero content change). Every listing and the stamp therefore iterate a 576// NAME-SORTED index of file nodes, so identical tree content -> identical 577// bytes, on any filesystem. (Residual: for duplicate basenames the walk's 578// first-path-wins registration is still enumeration-order-dependent -- declared.) 579 580func cw_namecmp(g: *EcoGraph, a: i64, b: i64) -> i64 { 581 let sa: *u8 = ((g.arena as i64) + g.node_off[a]) as *u8 582 let sb: *u8 = ((g.arena as i64) + g.node_off[b]) as *u8 583 var i: i64 = 0 584 var r: i64 = 0 585 var go: i64 = 1 586 while go == 1 { 587 let ca: i64 = sa[i] as i64 588 let cb: i64 = sb[i] as i64 589 if ca < cb { r = 0 - 1; go = 0 } 590 if go == 1 { if ca > cb { r = 1; go = 0 } } 591 if go == 1 { if ca == 0 { go = 0 } } 592 i = i + 1 593 } 594 return r 595} 596 597// bottom-up merge sort of idx[0..n) by node name 598func cw_sortnodes(g: *EcoGraph, idx: *i64, tmp: *i64, n: i64) -> i64 { 599 var width: i64 = 1 600 while width < n { 601 var lo: i64 = 0 602 while lo < n { 603 var mid: i64 = lo + width 604 if mid > n { mid = n } 605 var hi: i64 = lo + width + width 606 if hi > n { hi = n } 607 var a: i64 = lo 608 var b: i64 = mid 609 var w: i64 = lo 610 while w < hi { 611 var takea: i64 = 0 612 if a < mid { 613 if b >= hi { takea = 1 } else { 614 if cw_namecmp(g, idx[a], idx[b]) <= 0 { takea = 1 } 615 } 616 } 617 if takea == 1 { tmp[w] = idx[a]; a = a + 1 } else { tmp[w] = idx[b]; b = b + 1 } 618 w = w + 1 619 } 620 lo = hi 621 } 622 var c: i64 = 0 623 while c < n { idx[c] = tmp[c]; c = c + 1 } 624 width = width + width 625 } 626 return 0 627} 628 629// stem (page basename without .html) for JS index rows -- same index.nx guard 630// as cw_applink2 so JS-built hrefs and real page names can never disagree. 631func cw_appstem(buf: *u8, pos: *i64, cap: i64, nm: *u8) -> i64 { 632 let sl: i64 = cw_stemlen(nm) 633 cw_app(buf, pos, cap, nm, sl) 634 var guard: i64 = 0 635 if sl == 5 { 636 if nm[0] == (105 as u8) { if nm[1] == (110 as u8) { if nm[2] == (100 as u8) { if nm[3] == (101 as u8) { if nm[4] == (120 as u8) { guard = 1 } } } } } 637 } 638 if guard == 1 { cw_apps(buf, pos, cap, ".mod" as *u8) } 639 return 0 640} 641 642// build outdir/<name> into dst (for the non-module emissions) 643func cw_outpath(dst: *u8, outdir: *u8, name: *u8) -> i64 { 644 var w: i64 = 0 645 var i: i64 = 0 646 while outdir[i] != (0 as u8) { dst[w] = outdir[i]; w = w + 1; i = i + 1 } 647 dst[w] = 47 as u8 648 w = w + 1 649 w = w + cw_rawcpy(dst, w, name) 650 dst[w] = 0 as u8 651 return w 652} 653 654// FNV bucket for the function-def name hash 655func cwc_hash(s: *u8, n: i64) -> i64 { 656 var h: i64 = CW_MAGIC_2166136261 657 var i: i64 = 0 658 while i < n { h = (h ^ (s[i] as i64)) * CW_MAGIC_16777619; h = h & 0x7fffffff; i = i + 1 } 659 return h % CW_DEFHASH 660} 661 662// scan a comment-STRIPPED buffer for defs AND call sites in ONE walk. 663// A def = line-start `func <name>`; a call site = identifier immediately 664// followed by '('. String literals are skipped so quoted code cannot fake a 665// call; comments are already gone (gl_strip_comments preserves line numbers). 666// Sites are attributed to the ENCLOSING function (the def just seen) and 667// stored UNRESOLVED (name text); resolution happens later against the 668// complete def table. Everything is appended to caller-owned tables. 669func cwc_scan(strip: *u8, sn: i64, mod: i64, 670 dnames: *u8, dnoff: *i64, dnlen: *i64, dmod: *i64, dline: *i64, dhead: *i64, dnext: *i64, dn: *i64, du: *i64, 671 snames: *u8, snoff: *i64, snlen: *i64, smod: *i64, scaller: *i64, ns: *i64, su: *i64) -> i64 { 672 var i: i64 = 0 673 var ln: i64 = 1 674 var atline: i64 = 1 675 var curdef: i64 = 0 - 1 676 while i < sn { 677 let c: i64 = strip[i] as i64 678 if c == 34 { 679 var j: i64 = i + 1 680 var go: i64 = 1 681 while go == 1 { 682 if j >= sn { go = 0 } else { 683 if strip[j] == (92 as u8) { j = j + 2 } else { 684 if strip[j] == (34 as u8) { go = 0 } else { j = j + 1 } 685 } 686 } 687 } 688 i = j + 1 689 atline = 0 690 } else { 691 if gl_is_ident(c) == 1 { 692 let st0: i64 = i 693 var e1: i64 = i 694 var ge: i64 = 1 695 while ge == 1 { if e1 >= sn { ge = 0 } else { if gl_is_ident(strip[e1] as i64) == 1 { e1 = e1 + 1 } else { ge = 0 } } } 696 let idl: i64 = e1 - st0 697 var isfunc: i64 = 0 698 if atline == 1 { if idl == 4 { 699 if strip[st0] == (102 as u8) { if strip[st0+1] == (117 as u8) { if strip[st0+2] == (110 as u8) { if strip[st0+3] == (99 as u8) { isfunc = 1 } } } } 700 } } 701 if isfunc == 1 { 702 var p1: i64 = e1 703 var gp: i64 = 1 704 while gp == 1 { if p1 >= sn { gp = 0 } else { if strip[p1] == (32 as u8) { p1 = p1 + 1 } else { gp = 0 } } } 705 var q1: i64 = p1 706 var gq: i64 = 1 707 while gq == 1 { if q1 >= sn { gq = 0 } else { if gl_is_ident(strip[q1] as i64) == 1 { q1 = q1 + 1 } else { gq = 0 } } } 708 let nl2: i64 = q1 - p1 709 if nl2 > 0 { if nl2 < 96 { if dn[0] < CW_MAXFN { if du[0] + nl2 + 1 < CW_FNARENA { 710 var cc0: i64 = 0 711 while cc0 < nl2 { dnames[du[0] + cc0] = strip[p1 + cc0]; cc0 = cc0 + 1 } 712 dnoff[dn[0]] = du[0] 713 dnlen[dn[0]] = nl2 714 dmod[dn[0]] = mod 715 dline[dn[0]] = ln 716 let b: i64 = cwc_hash(((strip as i64) + p1) as *u8, nl2) 717 dnext[dn[0]] = dhead[b] 718 dhead[b] = dn[0] + 1 719 du[0] = du[0] + nl2 720 dn[0] = dn[0] + 1 721 curdef = dn[0] - 1 722 } } } } 723 i = q1 724 atline = 0 725 } else { 726 if e1 < sn { if strip[e1] == (40 as u8) { if curdef >= 0 { 727 if ns[0] < CW_MAXSITE { if su[0] + idl + 1 < CW_SITEARENA { if idl < 96 { 728 var cc1: i64 = 0 729 while cc1 < idl { snames[su[0] + cc1] = strip[st0 + cc1]; cc1 = cc1 + 1 } 730 snoff[ns[0]] = su[0] 731 snlen[ns[0]] = idl 732 smod[ns[0]] = mod 733 scaller[ns[0]] = curdef 734 su[0] = su[0] + idl 735 ns[0] = ns[0] + 1 736 } } } 737 } } } 738 i = e1 739 atline = 0 740 } 741 } else { 742 if c == 10 { atline = 1; ln = ln + 1 } else { if c != 32 { if c != 9 { atline = 0 } } } 743 i = i + 1 744 } 745 } 746 } 747 return 0 748} 749 750// topic-family key of a module name: skip a leading "nx_", take the next 751// name segment (the tree's prefix discipline IS its concept map). 752func cw_famkey(nm: *u8, out: *u8) -> i64 { 753 var s: i64 = 0 754 if nm[0] == (110 as u8) { if nm[1] == (120 as u8) { if nm[2] == (95 as u8) { s = 3 } } } 755 // leading underscores are convention noise (_a2a_* is the a2a family) 756 while nm[s] == (95 as u8) { s = s + 1 } 757 var i: i64 = s 758 var w: i64 = 0 759 var go: i64 = 1 760 while go == 1 { 761 let c: i64 = nm[i] as i64 762 if c == 0 { go = 0 } else { 763 if c == 95 { go = 0 } else { 764 if c == 46 { go = 0 } else { 765 if w < 24 { out[w] = nm[i]; w = w + 1; i = i + 1 } else { go = 0 } 766 } 767 } 768 } 769 } 770 return w 771} 772 773// pill-link to a function definition: <modstem>[.html]#fn_<name> 774func cw_appdeflink(buf: *u8, pos: *i64, cap: i64, g: *EcoGraph, dmodv: *i64, dnamesv: *u8, dnoffv: *i64, dnlenv: *i64, dx: i64, noext: i64) -> i64 { 775 let mn: *u8 = ((g.arena as i64) + g.node_off[dmodv[dx]]) as *u8 776 cw_apps(buf, pos, cap, "<a class='pill' href='" as *u8) 777 cw_appstem(buf, pos, cap, mn) 778 cw_appext(buf, pos, cap, noext) 779 cw_apps(buf, pos, cap, "#fn_" as *u8) 780 cw_app(buf, pos, cap, ((dnamesv as i64) + dnoffv[dx]) as *u8, dnlenv[dx]) 781 cw_apps(buf, pos, cap, "'>" as *u8) 782 cw_appe(buf, pos, cap, ((dnamesv as i64) + dnoffv[dx]) as *u8, dnlenv[dx]) 783 cw_apps(buf, pos, cap, "</a>" as *u8) 784 return 0 785} 786 787// call-flow tree from an entry def: pre-order walk over the call CSR, 788// caps DECLARED (40 nodes, depth 6); a def already in the tree is recorded 789// once more with a cycle mark and not re-expanded. Emitted as a linked SVG. 790func cw_callflow(buf: *u8, pos: *i64, cap: i64, g: *EcoGraph, dmodv: *i64, dnamesv: *u8, dnoffv: *i64, dnlenv: *i64, 791 cfoh: *i64, cfol: *i64, start: i64, noext: i64) -> i64 { 792 let nd: *i64 = sys_mmap(48 * 8) as *i64 793 let ndep: *i64 = sys_mmap(48 * 8) as *i64 794 let npar: *i64 = sys_mmap(48 * 8) as *i64 795 let ncyc: *i64 = sys_mmap(48 * 8) as *i64 796 let stk: *i64 = sys_mmap(CW_MAGIC_1024 * 8) as *i64 797 var nn: i64 = 0 798 var sp: i64 = 0 799 stk[0] = start 800 stk[1] = 0 801 stk[2] = 0 - 1 802 sp = 1 803 while sp > 0 { 804 if nn >= 40 { sp = 0 } else { 805 sp = sp - 1 806 let cd: i64 = stk[sp * 3] 807 let cdep: i64 = stk[sp * 3 + 1] 808 let cpar: i64 = stk[sp * 3 + 2] 809 var seen: i64 = 0 810 var sj: i64 = 0 811 while sj < nn { if nd[sj] == cd { seen = 1 } sj = sj + 1 } 812 nd[nn] = cd 813 ndep[nn] = cdep 814 npar[nn] = cpar 815 ncyc[nn] = seen 816 let myrow: i64 = nn 817 nn = nn + 1 818 if seen == 0 { if cdep < 6 { 819 // push children in REVERSE so the LIFO pops them in CSR order 820 var cc: i64 = cfoh[cd + 1] - 1 821 while cc >= cfoh[cd] { 822 if sp < 340 { 823 stk[sp * 3] = cfol[cc] 824 stk[sp * 3 + 1] = cdep + 1 825 stk[sp * 3 + 2] = myrow 826 sp = sp + 1 827 } 828 cc = cc - 1 829 } 830 } } 831 } 832 } 833 if nn <= 1 { return 0 } 834 cw_apps(buf, pos, cap, "<div class='svgwrap'><svg class='cflow' width='1160' height='" as *u8) 835 cw_appn(buf, pos, cap, nn * 38 + 14) 836 cw_apps(buf, pos, cap, "' xmlns='http://www.w3.org/2000/svg'>\n" as *u8) 837 var r0: i64 = 0 838 while r0 < nn { 839 if npar[r0] >= 0 { 840 let px: i64 = 20 + ndep[npar[r0]] * 150 + 12 841 let py: i64 = npar[r0] * 38 + 34 842 let cy2: i64 = r0 * 38 + 20 843 cw_apps(buf, pos, cap, "<path d='M " as *u8) 844 cw_appn(buf, pos, cap, px) 845 cw_apps(buf, pos, cap, " " as *u8) 846 cw_appn(buf, pos, cap, py) 847 cw_apps(buf, pos, cap, " V " as *u8) 848 cw_appn(buf, pos, cap, cy2) 849 cw_apps(buf, pos, cap, " H " as *u8) 850 cw_appn(buf, pos, cap, 20 + ndep[r0] * 150 - 6) 851 cw_apps(buf, pos, cap, "' fill='none' style='stroke:var(--svgs)'/>\n" as *u8) 852 } 853 r0 = r0 + 1 854 } 855 var r1: i64 = 0 856 while r1 < nn { 857 let dd: i64 = nd[r1] 858 cw_apps(buf, pos, cap, "<a href='" as *u8) 859 let mn2: *u8 = ((g.arena as i64) + g.node_off[dmodv[dd]]) as *u8 860 cw_appstem(buf, pos, cap, mn2) 861 cw_appext(buf, pos, cap, noext) 862 cw_apps(buf, pos, cap, "#fn_" as *u8) 863 cw_app(buf, pos, cap, ((dnamesv as i64) + dnoffv[dd]) as *u8, dnlenv[dd]) 864 cw_apps(buf, pos, cap, "'><rect x='" as *u8) 865 cw_appn(buf, pos, cap, 20 + ndep[r1] * 150) 866 cw_apps(buf, pos, cap, "' y='" as *u8) 867 cw_appn(buf, pos, cap, r1 * 38 + 8) 868 cw_apps(buf, pos, cap, "' width='240' height='26' rx='6' style='fill:var(--svgb);stroke:var(--svgs)'/><text x='" as *u8) 869 cw_appn(buf, pos, cap, 20 + ndep[r1] * 150 + 9) 870 cw_apps(buf, pos, cap, "' y='" as *u8) 871 cw_appn(buf, pos, cap, r1 * 38 + 25) 872 cw_apps(buf, pos, cap, "' style='fill:var(--svgt)' font-size='11' font-family='monospace'>" as *u8) 873 var tl: i64 = dnlenv[dd] 874 if tl > 26 { tl = 26 } 875 cw_appe(buf, pos, cap, ((dnamesv as i64) + dnoffv[dd]) as *u8, tl) 876 if ncyc[r1] == 1 { cw_apps(buf, pos, cap, " &#8635;" as *u8) } 877 cw_apps(buf, pos, cap, "</text></a>\n" as *u8) 878 r1 = r1 + 1 879 } 880 cw_apps(buf, pos, cap, "</svg></div>\n" as *u8) 881 return nn 882} 883 884// include <outdir>/_narrative/<name>.html verbatim (the LLM/analyst-written 885// overview sidecar). The generator only SHOWS it; the narration beat owns it. 886func cw_nar_include(page: *u8, pos: *i64, cap: i64, outdir: *u8, opath: *u8, name: *u8) -> i64 { 887 var w: i64 = 0 888 var i: i64 = 0 889 while outdir[i] != (0 as u8) { opath[w] = outdir[i]; w = w + 1; i = i + 1 } 890 opath[w] = 47 as u8 891 w = w + 1 892 w = w + cw_rawcpy(opath, w, "_narrative/" as *u8) 893 var j: i64 = 0 894 while name[j] != (0 as u8) { opath[w] = name[j]; w = w + 1; j = j + 1 } 895 w = w + cw_rawcpy(opath, w, ".html" as *u8) 896 opath[w] = 0 as u8 897 let narbuf: *u8 = sys_mmap(CW_MAGIC_65536) 898 let narn: i64 = gl_read(opath, narbuf, CW_MAGIC_65536) 899 if narn > 0 { 900 cw_apps(page, pos, cap, "<div class='nar'>" as *u8) 901 cw_app(page, pos, cap, narbuf, narn) 902 cw_apps(page, pos, cap, "</div>\n<p class='muted'>narrated overview -- maintained by the narration lane, module links verified against this wiki.</p>\n" as *u8) 903 } 904 return narn 905} 906 907// line-number link into the module's source page: src_<stem>[.html]#L<n> 908func cw_appsrclink(buf: *u8, pos: *i64, cap: i64, nm: *u8, ln: i64, noext: i64) -> i64 { 909 cw_apps(buf, pos, cap, "<a href='src_" as *u8) 910 cw_app(buf, pos, cap, nm, cw_stemlen(nm)) 911 cw_appext(buf, pos, cap, noext) 912 cw_apps(buf, pos, cap, "#L" as *u8) 913 cw_appn(buf, pos, cap, ln) 914 cw_apps(buf, pos, cap, "'>" as *u8) 915 cw_appn(buf, pos, cap, ln) 916 cw_apps(buf, pos, cap, "</a>" as *u8) 917 return 0 918} 919 920// per-module neighborhood diagram: imports (left, cap 10) -> module -> importers 921// (right, cap 10), every box a link. The pill lists below it stay COMPLETE -- 922// the SVG is a view, the pills are the record. 923func cw_nbr(buf: *u8, pos: *i64, cap: i64, g: *EcoGraph, v: i64, pathoff: *i64, noext: i64) -> i64 { 924 let oh: i64 = g.out_head[v] 925 let oe: i64 = g.out_head[v + 1] 926 let ih: i64 = g.in_head[v] 927 let ie: i64 = g.in_head[v + 1] 928 var nl: i64 = oe - oh 929 var nr: i64 = ie - ih 930 if nl + nr <= 0 { return 0 } 931 var xl: i64 = 0 932 if nl > 10 { xl = nl - 10; nl = 10 } 933 var xr: i64 = 0 934 if nr > 10 { xr = nr - 10; nr = 10 } 935 var rows: i64 = nl 936 if nr > rows { rows = nr } 937 let hh: i64 = rows * 42 + 26 938 cw_apps(buf, pos, cap, "<div class='svgwrap'><svg class='nbr' width='990' height='" as *u8) 939 cw_appn(buf, pos, cap, hh) 940 cw_apps(buf, pos, cap, "' xmlns='http://www.w3.org/2000/svg'>\n" as *u8) 941 let cy: i64 = hh / 2 - 14 942 // edges 943 var e0: i64 = 0 944 while e0 < nl { 945 cw_apps(buf, pos, cap, "<line x1='262' y1='" as *u8) 946 cw_appn(buf, pos, cap, 14 + e0 * 42 + 13) 947 cw_apps(buf, pos, cap, "' x2='372' y2='" as *u8) 948 cw_appn(buf, pos, cap, cy + 13) 949 cw_apps(buf, pos, cap, "' style='stroke:var(--svgs);stroke-opacity:.8'/>\n" as *u8) 950 e0 = e0 + 1 951 } 952 var e1: i64 = 0 953 while e1 < nr { 954 cw_apps(buf, pos, cap, "<line x1='618' y1='" as *u8) 955 cw_appn(buf, pos, cap, cy + 13) 956 cw_apps(buf, pos, cap, "' x2='728' y2='" as *u8) 957 cw_appn(buf, pos, cap, 14 + e1 * 42 + 13) 958 cw_apps(buf, pos, cap, "' style='stroke:var(--svgs);stroke-opacity:.8'/>\n" as *u8) 959 e1 = e1 + 1 960 } 961 // left: imports 962 var l0: i64 = 0 963 while l0 < nl { 964 let dep: i64 = g.out_list[oh + l0] 965 let dnm: *u8 = ((g.arena as i64) + g.node_off[dep]) as *u8 966 cw_apps(buf, pos, cap, "<a href='" as *u8) 967 if pathoff[dep] > 0 { cw_appstem(buf, pos, cap, dnm); cw_appext(buf, pos, cap, noext) } else { cw_apps(buf, pos, cap, "#deps" as *u8) } 968 cw_apps(buf, pos, cap, "'><rect x='10' y='" as *u8) 969 cw_appn(buf, pos, cap, 14 + l0 * 42) 970 cw_apps(buf, pos, cap, "' width='252' height='26' rx='6' style='fill:var(--svgb);stroke:var(--svgs)'/><text x='20' y='" as *u8) 971 cw_appn(buf, pos, cap, 14 + l0 * 42 + 17) 972 cw_apps(buf, pos, cap, "' style='fill:var(--svgt)' font-size='11' font-family='monospace'>" as *u8) 973 var dl: i64 = cw_slen(dnm) 974 if dl > 34 { dl = 34 } 975 cw_appe(buf, pos, cap, dnm, dl) 976 cw_apps(buf, pos, cap, "</text></a>\n" as *u8) 977 l0 = l0 + 1 978 } 979 // center: this module 980 let snm: *u8 = ((g.arena as i64) + g.node_off[v]) as *u8 981 cw_apps(buf, pos, cap, "<rect x='372' y='" as *u8) 982 cw_appn(buf, pos, cap, cy) 983 cw_apps(buf, pos, cap, "' width='246' height='28' rx='7' style='fill:var(--svgc);stroke:var(--acc)'/><text x='382' y='" as *u8) 984 cw_appn(buf, pos, cap, cy + 18) 985 cw_apps(buf, pos, cap, "' style='fill:var(--svgt)' font-size='12' font-family='monospace' font-weight='bold'>" as *u8) 986 var sl: i64 = cw_slen(snm) 987 if sl > 30 { sl = 30 } 988 cw_appe(buf, pos, cap, snm, sl) 989 cw_apps(buf, pos, cap, "</text>\n" as *u8) 990 // right: importers 991 var r0: i64 = 0 992 while r0 < nr { 993 let who: i64 = g.in_list[ih + r0] 994 let wnm: *u8 = ((g.arena as i64) + g.node_off[who]) as *u8 995 cw_apps(buf, pos, cap, "<a href='" as *u8) 996 cw_appstem(buf, pos, cap, wnm) 997 cw_appext(buf, pos, cap, noext) 998 cw_apps(buf, pos, cap, "'><rect x='728' y='" as *u8) 999 cw_appn(buf, pos, cap, 14 + r0 * 42) 1000 cw_apps(buf, pos, cap, "' width='252' height='26' rx='6' style='fill:var(--svgb);stroke:var(--svgs)'/><text x='738' y='" as *u8) 1001 cw_appn(buf, pos, cap, 14 + r0 * 42 + 17) 1002 cw_apps(buf, pos, cap, "' style='fill:var(--svgt)' font-size='11' font-family='monospace'>" as *u8) 1003 var wl: i64 = cw_slen(wnm) 1004 if wl > 34 { wl = 34 } 1005 cw_appe(buf, pos, cap, wnm, wl) 1006 cw_apps(buf, pos, cap, "</text></a>\n" as *u8) 1007 r0 = r0 + 1 1008 } 1009 cw_apps(buf, pos, cap, "</svg></div>" as *u8) 1010 if xl + xr > 0 { 1011 cw_apps(buf, pos, cap, "<p class='muted'>diagram shows first 10 each side; +" as *u8) 1012 cw_appn(buf, pos, cap, xl) 1013 cw_apps(buf, pos, cap, " more imports, +" as *u8) 1014 cw_appn(buf, pos, cap, xr) 1015 cw_apps(buf, pos, cap, " more importers in the complete lists below.</p>" as *u8) 1016 } 1017 cw_apps(buf, pos, cap, "\n" as *u8) 1018 return 0 1019} 1020 1021// display name for a module kind 1022func cw_kindname(k: i64) -> *u8 { 1023 if k == CW_K_ARCHIVED { return "archived" as *u8 } 1024 if k == CW_K_GATE { return "gate/proof" as *u8 } 1025 if k == CW_K_BENCH { return "bench" as *u8 } 1026 if k == CW_K_PROBE { return "probe" as *u8 } 1027 if k == CW_K_SMOKE { return "smoke" as *u8 } 1028 if k == CW_K_SKETCH { return "sketch/demo" as *u8 } 1029 if k == CW_K_GENFIX { return "generated fixture" as *u8 } 1030 if k == CW_K_SERVICE { return "service" as *u8 } 1031 if k == CW_K_TOOL { return "tool" as *u8 } 1032 if k == CW_K_LIB { return "library" as *u8 } 1033 return "orphan library" as *u8 1034} 1035 1036// bare substring (case-sensitive) over a nul-terminated name 1037func cw_namehas(nm: *u8, sub: *u8) -> i64 { 1038 let n: i64 = cw_slen(nm) 1039 let sl: i64 = cw_slen(sub) 1040 if sl <= 0 { return 0 } 1041 var i: i64 = 0 1042 while i + sl <= n { 1043 var m: i64 = 0 1044 var ok: i64 = 1 1045 while m < sl { if nm[i + m] != sub[m] { ok = 0; m = sl } else { m = m + 1 } } 1046 if ok == 1 { return 1 } 1047 i = i + 1 1048 } 1049 return 0 1050} 1051 1052// debt-category display name + the severity a finding for it carries 1053func cw_catname(k: i64) -> *u8 { 1054 if k == CW_CAT_LANDMINE { return "landmine" as *u8 } 1055 if k == CW_CAT_WORKAROUND { return "workaround / hack" as *u8 } 1056 if k == CW_CAT_GOTCHA { return "gotcha / trap" as *u8 } 1057 if k == CW_CAT_TODO { return "todo / unfinished" as *u8 } 1058 if k == CW_CAT_THIRDPARTY { return "third-party / foreign dependency" as *u8 } 1059 if k == CW_CAT_SECURITY { return "security note" as *u8 } 1060 if k == CW_CAT_PERF { return "performance debt" as *u8 } 1061 return "deprecated / retire" as *u8 1062} 1063// STABLE, count-free finding description per category (idempotent filing) 1064func cw_catdesc(k: i64) -> *u8 { 1065 if k == CW_CAT_LANDMINE { return "Landmine markers present (dual-copy / stale-tree / footgun hazards documented in source). https://nishifamily.com/code/debt -- these are the traps that silently regress; review + neutralize each." as *u8 } 1066 if k == CW_CAT_WORKAROUND { return "Workaround/hack markers present (code that works around a defect rather than fixing it). https://nishifamily.com/code/debt -- replace each with a real fix where the root cause now allows it." as *u8 } 1067 if k == CW_CAT_GOTCHA { return "Gotcha/trap/caveat markers present (documented traps future work must not step on). https://nishifamily.com/code/debt -- consider a gate tooth so the trap cannot recur silently." as *u8 } 1068 if k == CW_CAT_TODO { return "TODO/FIXME/unfinished markers present (declared-incomplete work). https://nishifamily.com/code/debt -- convert each to a tracked backlog item or finish it." as *u8 } 1069 if k == CW_CAT_THIRDPARTY { return "Third-party/foreign-dependency markers present (the sovereignty tax). https://nishifamily.com/code/debt and /code/sovereignty -- plan the first-byte-up replacement per dependency." as *u8 } 1070 if k == CW_CAT_SECURITY { return "Security markers present (CWE/vuln/exploit notes in source). https://nishifamily.com/code/debt -- verify each is closed and gated, not merely noted." as *u8 } 1071 if k == CW_CAT_PERF { return "Performance-debt markers present (quadratic/O(n^2)/slow-path notes). https://nishifamily.com/code/debt -- measure before optimizing; the note is a lead, the ruler decides." as *u8 } 1072 return "Deprecated/retire markers present (code flagged for removal still in the tree). https://nishifamily.com/code/debt -- migrate consumers then soft-delete (rule 13)." as *u8 1073} 1074func cw_catsev(k: i64) -> i64 { 1075 if k == CW_CAT_LANDMINE { return 7 } 1076 if k == CW_CAT_SECURITY { return 7 } 1077 if k == CW_CAT_GOTCHA { return 5 } 1078 if k == CW_CAT_WORKAROUND { return 5 } 1079 if k == CW_CAT_THIRDPARTY { return 5 } 1080 if k == CW_CAT_DEPRECATED { return 5 } 1081 if k == CW_CAT_PERF { return 4 } 1082 return 4 1083} 1084 1085// Does the byte range [s,e) describe a hazard that is ALREADY HANDLED -- 1086// a defence, or a defect that was resolved -- rather than one still live? 1087// 1088// ★THE DISCRIMINATOR IS GRAMMATICAL TENSE, and it is declared on purpose: 1089// only PAST-TENSE / accomplished forms count ("avoided", "fixed", "sealed", 1090// "prevents"). The imperative is deliberately EXCLUDED -- "fix this landmine" 1091// and "avoid X" are work OWED, and a rule that swallowed those would let the 1092// gauge hide exactly the rows it exists to surface. This one function serves 1093// every hazard category (rule 15: one copy, not one per marker family). 1094func cw_resolved(src: *u8, s: i64, e: i64) -> i64 { 1095 if cw_hastok(src, s, e, "prevent" as *u8, 7) == 1 { return 1 } 1096 if cw_hastok(src, s, e, "mitigat" as *u8, 7) == 1 { return 1 } 1097 if cw_hastok(src, s, e, "harden" as *u8, 6) == 1 { return 1 } 1098 if cw_hastok(src, s, e, "structural" as *u8, 10) == 1 { return 1 } 1099 if cw_hastok(src, s, e, "defen" as *u8, 5) == 1 { return 1 } 1100 if cw_hastok(src, s, e, "closes" as *u8, 6) == 1 { return 1 } 1101 if cw_hastok(src, s, e, "closed" as *u8, 6) == 1 { return 1 } 1102 if cw_hastok(src, s, e, "sealed" as *u8, 6) == 1 { return 1 } 1103 if cw_hastok(src, s, e, "refuses" as *u8, 7) == 1 { return 1 } 1104 if cw_hastok(src, s, e, "avoided" as *u8, 7) == 1 { return 1 } 1105 if cw_hastok(src, s, e, "fixed" as *u8, 5) == 1 { return 1 } 1106 if cw_hastok(src, s, e, "killed" as *u8, 6) == 1 { return 1 } 1107 if cw_hastok(src, s, e, "retired" as *u8, 7) == 1 { return 1 } 1108 if cw_hastok(src, s, e, "resolved" as *u8, 8) == 1 { return 1 } 1109 if cw_hastok(src, s, e, "eaten" as *u8, 5) == 1 { return 1 } 1110 return 0 1111} 1112 1113// kept as the security-specific name the security tooth drives; the behaviour 1114// now lives in the shared scanner below. 1115func cw_secmit(src: *u8, s: i64, e: i64) -> i64 { return cw_resolved(src, s, e) } 1116 1117// Line-scoped hazard scan shared by every marker family. Returns 1 iff SOME 1118// line carries one of the (up to 4) markers AND neither it nor the line above 1119// says the hazard is handled. Pass length 0 to skip an unused marker slot. 1120func cw_markscan(src: *u8, n: i64, m1: *u8, l1: i64, m2: *u8, l2: i64, m3: *u8, l3: i64, m4: *u8, l4: i64) -> i64 { 1121 var ls: i64 = 0 1122 var ps: i64 = 0 1123 var pe: i64 = 0 1124 while ls < n { 1125 var le: i64 = ls 1126 var g: i64 = 1 1127 while g == 1 { if le >= n { g = 0 } else { if src[le] == (10 as u8) { g = 0 } else { le = le + 1 } } } 1128 var hit: i64 = 0 1129 if l1 > 0 { if cw_hastok(src, ls, le, m1, l1) == 1 { hit = 1 } } 1130 if hit == 0 { if l2 > 0 { if cw_hastok(src, ls, le, m2, l2) == 1 { hit = 1 } } } 1131 if hit == 0 { if l3 > 0 { if cw_hastok(src, ls, le, m3, l3) == 1 { hit = 1 } } } 1132 if hit == 0 { if l4 > 0 { if cw_hastok(src, ls, le, m4, l4) == 1 { hit = 1 } } } 1133 if hit == 1 { 1134 var done: i64 = 0 1135 if cw_resolved(src, ls, le) == 1 { done = 1 } 1136 if done == 0 { if pe > ps { if cw_resolved(src, ps, pe) == 1 { done = 1 } } } 1137 if done == 0 { return 1 } 1138 } 1139 ps = ls 1140 pe = le 1141 ls = le + 1 1142 } 1143 return 0 1144} 1145 1146// Security markers: HAZARD, or a DECLARED MITIGATION? 1147// 1148// A whole-file substring hit on cwe-/vuln/exploit cannot tell "this module HAS 1149// a vulnerability" from "this module PREVENTS one" -- and the tree is full of 1150// the latter. nx_http_server's header documents CWE-352 CSRF *structural 1151// prevention* three times; the old rule filed it as a sev-7 hazard telling the 1152// reader to go neutralize it. **A gauge that reports a defence as a defect 1153// teaches its reader to ignore the rows that are real.** 1154// 1155// Rule (DECLARED, and the same "own line or the line ABOVE" convention the 1156// bounds scanner already uses): a security-marker LINE counts as a hazard 1157// unless that line -- or the one above it -- carries mitigation vocabulary. 1158// ONE unmitigated line marks the module, so a file that prevents one CWE and 1159// still notes a real hazard is reported, correctly, as carrying a hazard. 1160func cw_secscan(src: *u8, n: i64) -> i64 { 1161 return cw_markscan(src, n, "cwe-" as *u8, 4, "vuln" as *u8, 4, "exploit" as *u8, 7, "" as *u8, 0) 1162} 1163 1164// landmine family, same rule: "sys_mkdir landmine avoided" and a dated 1165// citation of a historical repro are NOT live hazards in this file. 1166func cw_lmscan(src: *u8, n: i64) -> i64 { 1167 return cw_markscan(src, n, "landmine" as *u8, 8, "footgun" as *u8, 7, "dual-copy" as *u8, 9, "stale-tree" as *u8, 10) 1168} 1169 1170// set category bits for a module by scanning its raw source for markers. 1171// Case-insensitive; each marker maps to one category. Returns the mask. 1172func cw_catscan(src: *u8, n: i64) -> i64 { 1173 var mask: i64 = 0 1174 // landmine: the tree's own hazard vocabulary, LINE-SCOPED and 1175 // resolution-aware (see cw_markscan) -- "landmine avoided" and a dated 1176 // citation of a past repro describe handled hazards, not live ones. 1177 if cw_lmscan(src, n) == 1 { mask = mask | 1 } 1178 // workaround / hack 1179 if cw_hastok(src, 0, n, "workaround" as *u8, 10) == 1 { mask = mask | 2 } 1180 if cw_hastok(src, 0, n, "hack" as *u8, 4) == 1 { mask = mask | 2 } 1181 if cw_hastok(src, 0, n, "kludge" as *u8, 6) == 1 { mask = mask | 2 } 1182 // gotcha / trap 1183 if cw_hastok(src, 0, n, "gotcha" as *u8, 6) == 1 { mask = mask | 4 } 1184 if cw_hastok(src, 0, n, "trap" as *u8, 4) == 1 { mask = mask | 4 } 1185 if cw_hastok(src, 0, n, "caveat" as *u8, 6) == 1 { mask = mask | 4 } 1186 // todo / unfinished 1187 if cw_hastok(src, 0, n, "todo" as *u8, 4) == 1 { mask = mask | 8 } 1188 if cw_hastok(src, 0, n, "fixme" as *u8, 5) == 1 { mask = mask | 8 } 1189 if cw_hastok(src, 0, n, "unfinished" as *u8, 10) == 1 { mask = mask | 8 } 1190 // third-party / foreign dependency (sovereignty-relevant) 1191 if cw_hastok(src, 0, n, "third-party" as *u8, 11) == 1 { mask = mask | 16 } 1192 if cw_hastok(src, 0, n, "3rd-party" as *u8, 9) == 1 { mask = mask | 16 } 1193 if cw_hastok(src, 0, n, "foreign" as *u8, 7) == 1 { mask = mask | 16 } 1194 if cw_hastok(src, 0, n, "non-sovereign" as *u8, 13) == 1 { mask = mask | 16 } 1195 // security note -- LINE-SCOPED and mitigation-aware (see cw_secscan): 1196 // a documented DEFENCE is not a defect, so "CWE-352 structural prevention" 1197 // no longer files a sev-7 telling the reader to go neutralize it. 1198 if cw_secscan(src, n) == 1 { mask = mask | 32 } 1199 // performance debt 1200 if cw_hastok(src, 0, n, "quadratic" as *u8, 9) == 1 { mask = mask | 64 } 1201 if cw_hastok(src, 0, n, "o(n^2)" as *u8, 6) == 1 { mask = mask | 64 } 1202 if cw_hastok(src, 0, n, "slow path" as *u8, 9) == 1 { mask = mask | 64 } 1203 // deprecated / retire 1204 if cw_hastok(src, 0, n, "deprecated" as *u8, 10) == 1 { mask = mask | 128 } 1205 if cw_hastok(src, 0, n, "retire" as *u8, 6) == 1 { mask = mask | 128 } 1206 if cw_hastok(src, 0, n, "obsolete" as *u8, 8) == 1 { mask = mask | 128 } 1207 return mask 1208} 1209 1210// ---------- SHIPPED-DRIFT: is what RUNS what the tree SAYS? (2026-07-30) ---------- 1211// 1212// ★★★THE DOMINANT SYSTEMIC CLASS ON THE BOARD. Of the open sev-9 rows, whole 1213// scopes are named for it: `eaten-but-fix-not-in-any-tree`, 1214// `breaker-exists-in-source-NOT-in-running-supervisor`, `source-loss`. I hit it 1215// FIVE times in one day -- the torrent reaper, the mgmt api, the tools daemon, 1216// nx_fsops_write and the edge -- each time rediscovered by hand, one binary at 1217// a time, because **nothing in the ecosystem answers "is the deployed artefact 1218// newer than its source?"** A fix that lives only in source is not shipped; a 1219// feature that lives only in a deployed binary is not in the tree. Both are 1220// invisible without this comparison. 1221// 1222// MEASURE: for a deployed <stem>.elf, compare its mtime against its module 1223// source mtime. elf OLDER than source => DRIFT (a source change never shipped). 1224// Declared honestly: this is the MODULE'S OWN source, not its full import 1225// closure, so it UNDER-reports (a change in a dependency will not show until 1226// the closure walk lands) -- an under-reporting gauge is safe; it never invents 1227// drift, and the rows it does show are real. mtime lives at offset 88 of the 1228// x86-64 struct stat (sys_fstatat). 1229// Returns mtime seconds, or -1 when the path is absent/unreadable. 1230func cw_mtime(path: *u8) -> i64 { 1231 let sb: *u8 = sys_mmap(256) 1232 if sys_fstatat(path, sb) != 0 { return 0 - 1 } 1233 let p: *i64 = ((sb as i64) + 88) as *i64 1234 return p[0] 1235} 1236 1237// ---------- substring-classifier scan (2026-07-30) ---------- 1238// 1239// ★★★THE DEFECT CLASS THIS MEASURES cost FOUR separate bugs in ONE day, at 1240// sev 5 through 9, in four unrelated subsystems: 1241// * hazard markers -- `contains(src,"cwe-")` filed nx_http_server's CWE-352 1242// *structural prevention* as a hazard to neutralize 1243// * promote-sprawl -- `contains(name,"_v2")` flagged the edge SSOT, whose 1244// version IS its identity, as a stale-promote copy 1245// * organ role -- `contains(name,"torrent")` classified the one-shot 1246// worker nx_torrent_get as a daemon, leaving it 1247// unshippable by ANY sanctioned verb 1248// * HTTP structure -- route matching scanned the whole buffer, so BODY 1249// bytes reading `POST /route?` hijacked the request 1250// 1251// Every one is the same mistake: **A SUBSTRING STANDING IN FOR A PROPERTY.** 1252// The needle is cheap to write and reads as a rule, but it cannot distinguish 1253// a thing from a mention of a thing -- a defect from its documented cure, an 1254// identity from a copy, a role from a name, a request line from its payload. 1255// 1256// WHAT IS COUNTED (declared, deliberately narrow so the gauge stays honest): 1257// a SINGLE LINE that both tests a substring AND decides on it -- a 1258// `contains(`/`hastok(`/`streq(`-family call, a quoted literal, and a verdict 1259// on the same line (`return 0`/`return 1`/`= 1`). That is the exact shape of 1260// all four defects. A search that merely FINDS text and hands the offset 1261// onward is not counted: locating a substring is legitimate; CLASSIFYING by 1262// one is the smell. The honest fix is to read the structure (parse the field, 1263// declare the role in data, bound the scan to the header) -- so this gauge 1264// falls as classifiers become declarative. 1265// Plain substring test over [s,e) with NO word-boundary requirement. 1266// 1267// ⚠cw_hastok deliberately demands a LEFT WORD BOUNDARY (that rule is what stops 1268// "organ" matching inside nx_chem_mORGANn). Here it is exactly wrong: the call 1269// sites we are hunting are named `md_contains(`, `sd2_contains(`, `cw_hastok(`, 1270// so the needle is always preceded by an identifier character. The detector for 1271// substring classifiers was itself defeated by a substring rule -- which is the 1272// class it exists to measure. 1273func cw_hasraw(src: *u8, s: i64, e: i64, needle: *u8, nl: i64) -> i64 { 1274 if nl <= 0 { return 0 } 1275 var i: i64 = s 1276 while i + nl <= e { 1277 var k: i64 = 0 1278 var ok: i64 = 1 1279 // ⚠SELF-CONTAINED lowercase ON PURPOSE. This function sits at line ~1200, 1280 // far ABOVE cw_lc (~2298), and nx_cc forward references are unproven -- 1281 // calling cw_lc here compiled clean and then returned garbage, which is 1282 // exactly why the first build of this scanner failed its own gate tooth 1283 // and the second CRASHED the generator after its header line. Depend on 1284 // nothing defined below you. 1285 while k < nl { 1286 var ch: i64 = src[i + k] as i64 1287 if ch >= 65 { if ch <= 90 { ch = ch + 32 } } 1288 if ch != (needle[k] as i64) { ok = 0; k = nl } else { k = k + 1 } 1289 } 1290 if ok == 1 { return 1 } 1291 i = i + 1 1292 } 1293 return 0 1294} 1295 1296func cw_substrclass(src: *u8, n: i64) -> i64 { 1297 var hits: i64 = 0 1298 var ls: i64 = 0 1299 while ls < n { 1300 var le: i64 = ls 1301 var g: i64 = 1 1302 while g == 1 { if le >= n { g = 0 } else { if src[le] == (10 as u8) { g = 0 } else { le = le + 1 } } } 1303 if le > ls { if src[ls] != (47 as u8) { 1304 var isc: i64 = 0 1305 if cw_hasraw(src, ls, le, "contains(" as *u8, 9) == 1 { isc = 1 } 1306 if isc == 0 { if cw_hasraw(src, ls, le, "hastok(" as *u8, 7) == 1 { isc = 1 } } 1307 if isc == 1 { 1308 var hasq: i64 = 0 1309 var q: i64 = ls 1310 while q < le { if src[q] == (34 as u8) { hasq = 1; q = le } else { q = q + 1 } } 1311 if hasq == 1 { 1312 var dec: i64 = 0 1313 if cw_hasraw(src, ls, le, "return 1" as *u8, 8) == 1 { dec = 1 } 1314 if dec == 0 { if cw_hasraw(src, ls, le, "return 0" as *u8, 8) == 1 { dec = 1 } } 1315 if dec == 0 { if cw_hasraw(src, ls, le, "= 1 " as *u8, 4) == 1 { dec = 1 } } 1316 if dec == 1 { hits = hits + 1 } 1317 } 1318 } 1319 } } 1320 ls = le + 1 1321 } 1322 return hits 1323} 1324 1325// ---------- taste-bound scan (bounds law 2026-07-29, seq1242) ---------- 1326// Counts `const ..._CAP/_MAX... = N` (N >= 16) declarations whose own line or 1327// the line ABOVE carries no measurement-provenance marker. Lexical, declared; 1328// the 07-29 audit found the tree inverted (naked bounds the majority) -- this 1329// makes the law a STANDING GAUGE that falls as bounds gain derivations. 1330func cw_bs_prov(src: *u8, s: i64, e: i64) -> i64 { 1331 if cw_submatch(src, s, e, "measured" as *u8) == 1 { return 1 } 1332 if cw_submatch(src, s, e, "derived" as *u8) == 1 { return 1 } 1333 if cw_submatch(src, s, e, "sized" as *u8) == 1 { return 1 } 1334 if cw_submatch(src, s, e, "budget" as *u8) == 1 { return 1 } 1335 if cw_submatch(src, s, e, "today" as *u8) == 1 { return 1 } 1336 if cw_submatch(src, s, e, "RFC" as *u8) == 1 { return 1 } 1337 if cw_submatch(src, s, e, "rfc" as *u8) == 1 { return 1 } 1338 if cw_submatch(src, s, e, "JPL" as *u8) == 1 { return 1 } 1339 if cw_submatch(src, s, e, "== " as *u8) == 1 { return 1 } 1340 return 0 1341} 1342 1343func cw_boundscan(src: *u8, n: i64) -> i64 { 1344 var cnt: i64 = 0 1345 var ls: i64 = 0 1346 var prevs: i64 = 0 1347 var preve: i64 = 0 1348 while ls < n { 1349 var le: i64 = ls 1350 var g1: i64 = 1 1351 while g1 == 1 { if le >= n { g1 = 0 } else { if src[le] == (10 as u8) { g1 = 0 } else { le = le + 1 } } } 1352 var cand: i64 = 0 1353 if le > ls + 8 { if src[ls] != (47 as u8) { 1354 if cw_submatch(src, ls, le, "const " as *u8) == 1 { 1355 // "CAP:"/"MAX:" (name-fused OR underscored -- the first rule 1356 // used "_CAP/_MAX" and let PAGECAP-style names dodge; widened 1357 // 07-29 after the gauge's own first eat exposed the blind spot) 1358 if cw_submatch(src, ls, le, "CAP:" as *u8) == 1 { cand = 1 } else { 1359 if cw_submatch(src, ls, le, "MAX:" as *u8) == 1 { cand = 1 } } 1360 } 1361 } } 1362 if cand == 1 { 1363 var veq: i64 = 0 - 1 1364 var eq: i64 = ls 1365 while eq < le { if src[eq] == (61 as u8) { if veq < 0 { veq = eq } } eq = eq + 1 } 1366 var val: i64 = 0 1367 var seen: i64 = 0 1368 if veq >= 0 { 1369 var vp: i64 = veq + 1 1370 var run: i64 = 1 1371 while run == 1 { 1372 if vp >= le { run = 0 } else { 1373 let c2: i64 = src[vp] as i64 1374 if c2 >= 48 { if c2 <= 57 { val = val * 10 + (c2 - 48); seen = 1; vp = vp + 1 } else { if seen == 1 { run = 0 } else { vp = vp + 1 } } } else { if seen == 1 { run = 0 } else { vp = vp + 1 } } 1375 } 1376 } 1377 } 1378 if seen == 1 { if val >= 16 { 1379 var prov: i64 = cw_bs_prov(src, ls, le) 1380 if prov == 0 { if preve > prevs { prov = cw_bs_prov(src, prevs, preve) } } 1381 if prov == 0 { cnt = cnt + 1 } 1382 } } 1383 } 1384 prevs = ls 1385 preve = le 1386 ls = le + 1 1387 } 1388 return cnt 1389} 1390 1391// ---------- language-adoption scan (rung 16: the nishilang lane's axes) ---------- 1392// Lexical, comment-INCLUSIVE, rule declared on /code/lang: bit1 = declares a 1393// fixed array `: [<digit>` (the bounds-checked [N]T form, lane r1); bit2 = 1394// uses the slice form (`: []` or `__slice(`, heap spatial safety, lane r2). 1395// A comment mentioning the syntax counts -- the rule is stated in-band and 1396// applied identically every regen, so the TREND is honest even where a stray 1397// comment inflates a count by one. 1398func cw_langscan(src: *u8, n: i64) -> i64 { 1399 var mask: i64 = 0 1400 var i: i64 = 0 1401 while i + 8 < n { 1402 if src[i] == (58 as u8) { if src[i + 1] == (32 as u8) { if src[i + 2] == (91 as u8) { 1403 if src[i + 3] >= (48 as u8) { if src[i + 3] <= (57 as u8) { mask = mask | 1 } } 1404 if src[i + 3] == (93 as u8) { mask = mask | 2 } 1405 } } } 1406 if src[i] == (95 as u8) { if src[i + 1] == (95 as u8) { if src[i + 2] == (115 as u8) { 1407 if src[i + 3] == (108 as u8) { if src[i + 4] == (105 as u8) { if src[i + 5] == (99 as u8) { 1408 if src[i + 6] == (101 as u8) { if src[i + 7] == (40 as u8) { mask = mask | 2 } } 1409 } } } 1410 } } } 1411 if mask == 3 { return 3 } 1412 i = i + 1 1413 } 1414 return mask 1415} 1416 1417// append a TARGETED finding naming one module: the desc stays stable (module 1418// name + category + citation, no counts/dates) so re-filing is idempotent, and 1419// each row is a discrete work item a maker can pick up and close. 1420func cw_fnd_mod(fbuf: *u8, fpos: *i64, sev: i64, cat: *u8, mstem: *u8, mstem_n: i64) -> i64 { 1421 // ⚠NO COUNTS IN THE DESC. Fan-in decides the RANKING (which modules get a 1422 // targeted row) but must never appear in the text: a number that drifts 1423 // makes every regen file a "new" debt and the board becomes noise. 1424 cw_appn(fbuf, fpos, CW_FINDCAP, sev) 1425 cw_apps(fbuf, fpos, CW_FINDCAP, "\tcodewiki-debt\t" as *u8) 1426 cw_apps(fbuf, fpos, CW_FINDCAP, cat) 1427 cw_apps(fbuf, fpos, CW_FINDCAP, " in " as *u8) 1428 cw_app(fbuf, fpos, CW_FINDCAP, mstem, mstem_n) 1429 cw_apps(fbuf, fpos, CW_FINDCAP, " (high blast radius -- widely imported). Review and neutralize the hazard, then add a gate tooth so it cannot recur. https://nishifamily.com/code/" as *u8) 1430 cw_app(fbuf, fpos, CW_FINDCAP, mstem, mstem_n) 1431 cw_apps(fbuf, fpos, CW_FINDCAP, "\n" as *u8) 1432 return 0 1433} 1434 1435// append one finding line: <sev>\t<scope>\t<desc>\n (the nx_debt add grammar) 1436func cw_fnd(fbuf: *u8, fpos: *i64, sev: i64, scope: *u8, desc: *u8) -> i64 { 1437 cw_appn(fbuf, fpos, CW_FINDCAP, sev) 1438 cw_apps(fbuf, fpos, CW_FINDCAP, "\t" as *u8) 1439 cw_apps(fbuf, fpos, CW_FINDCAP, scope) 1440 cw_apps(fbuf, fpos, CW_FINDCAP, "\t" as *u8) 1441 cw_apps(fbuf, fpos, CW_FINDCAP, desc) 1442 cw_apps(fbuf, fpos, CW_FINDCAP, "\n" as *u8) 1443 return 0 1444} 1445 1446// ---------- pulse: the self-sufficiency trend instrument (rung 20) ---------- 1447// The gauges the engine-shift is steered by, drawn NATIVE (first-byte-up 1448// doctrine 07-29) from the machine-fed logs at every regen: DONE frames/day, 1449// non-Claude DONE frames/day (the making-plane self-sufficiency gauge), the 1450// foreign-vs-sovereign tool-mention split, and the token meter as a TABLE -- 1451// a bar chart would render a missing meter day as zero, and missing is not 1452// zero. Day buckets are RELATIVE (d-0 = newest journal day): the chart is 1453// about the trend, so no calendar math is needed or pretended. 1454func cw_atoi(b: *u8, s: i64, e: i64) -> i64 { 1455 var v: i64 = 0 1456 var i: i64 = s 1457 while i < e { 1458 let c: i64 = b[i] as i64 1459 if c >= 48 { if c <= 57 { v = v * 10 + (c - 48) } else { i = e } } else { i = e } 1460 i = i + 1 1461 } 1462 return v 1463} 1464 1465func cw_submatch(hay: *u8, hs: i64, he: i64, needle: *u8) -> i64 { 1466 var nl: i64 = 0 1467 while needle[nl] != (0 as u8) { nl = nl + 1 } 1468 if nl == 0 { return 0 } 1469 var i: i64 = hs 1470 while i + nl <= he { 1471 var m: i64 = 0 1472 var ok: i64 = 1 1473 while m < nl { if hay[i + m] != needle[m] { ok = 0; m = nl } else { m = m + 1 } } 1474 if ok == 1 { return 1 } 1475 i = i + 1 1476 } 1477 return 0 1478} 1479 1480// series points "x,y x,y ..." for a 14-day series into a fixed plot box, 1481// d-13 at the left edge, d-0 at the right (the reading direction of time) 1482func cw_plpts(page: *u8, pos: *i64, cap: i64, vals: *i64, mx: i64, x0: i64, y0: i64, w: i64, h: i64) -> i64 { 1483 var d: i64 = 13 1484 while d >= 0 { 1485 let x: i64 = x0 + ((13 - d) * w) / 13 1486 let y: i64 = (y0 + h) - (vals[d] * h) / mx 1487 if d < 13 { cw_apps(page, pos, cap, " " as *u8) } 1488 cw_appn(page, pos, cap, x) 1489 cw_apps(page, pos, cap, "," as *u8) 1490 cw_appn(page, pos, cap, y) 1491 d = d - 1 1492 } 1493 return 0 1494} 1495 1496// tiny sparkline for a KPI card (last 14 days, no axes -- shape only) 1497func cw_spark(page: *u8, pos: *i64, cap: i64, vals: *i64) -> i64 { 1498 var mx: i64 = 1 1499 var i: i64 = 0 1500 while i < 14 { if vals[i] > mx { mx = vals[i] } i = i + 1 } 1501 cw_apps(page, pos, cap, "<svg width='130' height='30' viewBox='0 0 130 30'><polyline fill='none' stroke='var(--acc)' stroke-width='2' stroke-linejoin='round' stroke-linecap='round' points='" as *u8) 1502 cw_plpts(page, pos, cap, vals, mx, 3, 3, 122, 22) 1503 cw_apps(page, pos, cap, "'/><circle cx='125' cy='" as *u8) 1504 cw_appn(page, pos, cap, 25 - (vals[0] * 22) / mx) 1505 cw_apps(page, pos, cap, "' r='2.6' fill='var(--acc)'/></svg>" as *u8) 1506 return 0 1507} 1508 1509// delta pill: direction arrow + signed value + wk/wk; good direction = green 1510func cw_dpill(page: *u8, pos: *i64, cap: i64, dv: i64, goodup: i64, unit: *u8) -> i64 { 1511 var good: i64 = 0 1512 if dv > 0 { if goodup == 1 { good = 1 } } 1513 if dv < 0 { if goodup == 0 { good = 1 } } 1514 if dv == 0 { good = 1 } 1515 if good == 1 { cw_apps(page, pos, cap, "<span class='d dg'>" as *u8) } else { cw_apps(page, pos, cap, "<span class='d db'>" as *u8) } 1516 if dv > 0 { cw_apps(page, pos, cap, "&#9650; +" as *u8); cw_appn(page, pos, cap, dv) } 1517 if dv < 0 { cw_apps(page, pos, cap, "&#9660; " as *u8); cw_appn(page, pos, cap, dv) } 1518 if dv == 0 { cw_apps(page, pos, cap, "&#8722; 0" as *u8) } 1519 cw_apps(page, pos, cap, unit) 1520 cw_apps(page, pos, cap, " wk/wk</span>" as *u8) 1521 return 0 1522} 1523 1524func cw_pulse(page: *u8, pos: *i64, cap: i64, jrnlpath: *u8, meterpath: *u8, noext2: i64) -> i64 { 1525 let jb: *u8 = sys_mmap(CW_EXPCONF) 1526 let jn: i64 = gl_read(jrnlpath, jb, CW_EXPCONF) 1527 let mb: *u8 = sys_mmap(CW_MAGIC_262144) 1528 let mn: i64 = gl_read(meterpath, mb, CW_MAGIC_262144) 1529 if jn <= 0 { 1530 cw_apps(page, pos, cap, "<p class='muted'>journal not present in this build environment -- the NAS regeneration carries the real gauges; absence of the INPUT is not an empty ANSWER.</p>\n" as *u8) 1531 return 0 1532 } 1533 let done: *i64 = sys_mmap(16 * 8) as *i64 1534 let noncl: *i64 = sys_mmap(16 * 8) as *i64 1535 var z: i64 = 0 1536 while z < 16 { done[z] = 0; noncl[z] = 0; z = z + 1 } 1537 var maxep: i64 = 0 1538 var pass: i64 = 0 1539 var foreignc: i64 = 0 1540 var sovc: i64 = 0 1541 var donetot: i64 = 0 1542 var noncltot: i64 = 0 1543 var done7: i64 = 0 1544 var donep: i64 = 0 1545 var nc7: i64 = 0 1546 var ncp: i64 = 0 1547 var for7: i64 = 0 1548 var forp: i64 = 0 1549 var sov7: i64 = 0 1550 var sovp: i64 = 0 1551 while pass < 2 { 1552 var ls: i64 = 0 1553 while ls < jn { 1554 var le: i64 = ls 1555 var g1: i64 = 1 1556 while g1 == 1 { if le >= jn { g1 = 0 } else { if jb[le] == (10 as u8) { g1 = 0 } else { le = le + 1 } } } 1557 let f1e: i64 = cw_fld(jb, ls, le) 1558 if f1e < le { 1559 let ep: i64 = cw_atoi(jb, ls, f1e) 1560 if pass == 0 { if ep > maxep { maxep = ep } } else { 1561 let f2s: i64 = f1e + 1 1562 let f2e: i64 = cw_fld(jb, f2s, le) 1563 // TYPE == DONE (4 bytes) 1564 var isdone: i64 = 0 1565 if f2e - f2s == 4 { if jb[f2s] == (68 as u8) { if jb[f2s+1] == (79 as u8) { if jb[f2s+2] == (78 as u8) { if jb[f2s+3] == (69 as u8) { isdone = 1 } } } } } 1566 if isdone == 1 { 1567 donetot = donetot + 1 1568 let dd: i64 = (maxep / CW_MAGIC_86400) - (ep / CW_MAGIC_86400) 1569 let f3s: i64 = f2e + 1 1570 let f3e: i64 = cw_fld(jb, f3s, le) 1571 let f4s: i64 = f3e + 1 1572 let f4e: i64 = cw_fld(jb, f4s, le) 1573 // actor class: claude* prefix = seat; else local/other 1574 var iscl: i64 = 0 1575 if f4e - f4s >= 6 { if jb[f4s] == (99 as u8) { if jb[f4s+1] == (108 as u8) { if jb[f4s+2] == (97 as u8) { if jb[f4s+3] == (117 as u8) { if jb[f4s+4] == (100 as u8) { if jb[f4s+5] == (101 as u8) { iscl = 1 } } } } } } } 1576 if iscl == 0 { noncltot = noncltot + 1 } 1577 var wk: i64 = 2 1578 if dd >= 0 { if dd < 7 { wk = 0 } } 1579 if dd >= 7 { if dd < 14 { wk = 1 } } 1580 if dd >= 0 { if dd < 14 { 1581 done[dd] = done[dd] + 1 1582 if iscl == 0 { noncl[dd] = noncl[dd] + 1 } 1583 } } 1584 if wk == 0 { done7 = done7 + 1; if iscl == 0 { nc7 = nc7 + 1 } } 1585 if wk == 1 { donep = donep + 1; if iscl == 0 { ncp = ncp + 1 } } 1586 let f5s: i64 = f4e + 1 1587 var isfor: i64 = 0 1588 var issov: i64 = 0 1589 if cw_submatch(jb, f5s, le, "ssh " as *u8) == 1 { isfor = 1 } else { 1590 if cw_submatch(jb, f5s, le, "scp " as *u8) == 1 { isfor = 1 } else { 1591 if cw_submatch(jb, f5s, le, "curl" as *u8) == 1 { isfor = 1 } else { 1592 if cw_submatch(jb, f5s, le, "chrome" as *u8) == 1 { isfor = 1 } else { 1593 if cw_submatch(jb, f5s, le, "powershell" as *u8) == 1 { isfor = 1 } else { 1594 if cw_submatch(jb, f5s, le, "wsl " as *u8) == 1 { isfor = 1 } } } } } } 1595 if cw_submatch(jb, f5s, le, "nx_" as *u8) == 1 { issov = 1 } else { 1596 if cw_submatch(jb, f5s, le, "tools/call" as *u8) == 1 { issov = 1 } else { 1597 if cw_submatch(jb, f5s, le, "/api/" as *u8) == 1 { issov = 1 } } } 1598 if isfor == 1 { foreignc = foreignc + 1 1599 if wk == 0 { for7 = for7 + 1 } 1600 if wk == 1 { forp = forp + 1 } } 1601 if issov == 1 { sovc = sovc + 1 1602 if wk == 0 { sov7 = sov7 + 1 } 1603 if wk == 1 { sovp = sovp + 1 } } 1604 } 1605 } 1606 } 1607 ls = le + 1 1608 } 1609 pass = pass + 1 1610 } 1611 // week-over-week deltas of the two GOAL gauges drive the verdict (rule 1612 // declared in the envelope; permil math guards div-by-zero via max(x,1)) 1613 var d7g: i64 = done7 1614 if d7g < 1 { d7g = 1 } 1615 var dpg: i64 = donep 1616 if dpg < 1 { dpg = 1 } 1617 let nc7p: i64 = (nc7 * 1000) / d7g 1618 let ncpp: i64 = (ncp * 1000) / dpg 1619 var fs7: i64 = for7 + sov7 1620 if fs7 < 1 { fs7 = 1 } 1621 var fsp: i64 = forp + sovp 1622 if fsp < 1 { fsp = 1 } 1623 let fo7p: i64 = (for7 * 1000) / fs7 1624 let fopp: i64 = (forp * 1000) / fsp 1625 let dnc: i64 = nc7p - ncpp 1626 let dfo: i64 = fo7p - fopp 1627 let ddn: i64 = done7 - donep 1628 var goods: i64 = 0 1629 if dnc > 0 { goods = goods + 1 } 1630 if dfo < 0 { goods = goods + 1 } 1631 cw_apps(page, pos, cap, "<div class='vd'><div class='big'>" as *u8) 1632 if goods == 2 { cw_apps(page, pos, cap, "The shift is moving." as *u8) } 1633 if goods == 1 { cw_apps(page, pos, cap, "Mixed signals this week." as *u8) } 1634 if goods == 0 { cw_apps(page, pos, cap, "The seat still carries the making plane." as *u8) } 1635 cw_apps(page, pos, cap, "</div><div class='sub'>" as *u8) 1636 cw_appn(page, pos, cap, done7) 1637 cw_apps(page, pos, cap, " closures in the last 7 journal days (" as *u8) 1638 cw_appn(page, pos, cap, donep) 1639 cw_apps(page, pos, cap, " the week before). Non-Claude actors closed " as *u8) 1640 cw_appn(page, pos, cap, nc7p) 1641 cw_apps(page, pos, cap, "&permil; of them &mdash; this number should RISE as makers and beats take the mechanical middle. Foreign plumbing appears in " as *u8) 1642 cw_appn(page, pos, cap, fo7p) 1643 cw_apps(page, pos, cap, "&permil; of tool mentions &mdash; it should FALL as sovereign verbs land. What moves both is ranked below.</div></div>\n" as *u8) 1644 // KPI band -- the data-* attributes are the GATE CONTRACT; markup may evolve 1645 cw_apps(page, pos, cap, "<div class='kpis'><div class='pk'><div class='lab'>non-Claude closures (7d)</div><div class='val' data-nc='" as *u8) 1646 cw_appn(page, pos, cap, nc7p) 1647 cw_apps(page, pos, cap, "'>" as *u8) 1648 cw_appn(page, pos, cap, nc7p) 1649 cw_apps(page, pos, cap, "&permil;</div>" as *u8) 1650 cw_dpill(page, pos, cap, dnc, 1, "&permil;" as *u8) 1651 cw_apps(page, pos, cap, "<div class='goal'>goal: rising &middot; who FINISHES the work</div>" as *u8) 1652 cw_spark(page, pos, cap, noncl) 1653 cw_apps(page, pos, cap, "</div><div class='pk'><div class='lab'>foreign-tool mentions (7d)</div><div class='val' data-fo='" as *u8) 1654 cw_appn(page, pos, cap, fo7p) 1655 cw_apps(page, pos, cap, "'>" as *u8) 1656 cw_appn(page, pos, cap, fo7p) 1657 cw_apps(page, pos, cap, "&permil;</div>" as *u8) 1658 cw_dpill(page, pos, cap, dfo, 0, "&permil;" as *u8) 1659 cw_apps(page, pos, cap, "<div class='goal'>goal: falling &middot; ssh/scp/curl/chrome vs sovereign verbs</div></div><div class='pk'><div class='lab'>closures this week</div><div class='val' data-done='" as *u8) 1660 cw_appn(page, pos, cap, done7) 1661 cw_apps(page, pos, cap, "'>" as *u8) 1662 cw_appn(page, pos, cap, done7) 1663 cw_apps(page, pos, cap, "</div>" as *u8) 1664 cw_dpill(page, pos, cap, ddn, 1, "" as *u8) 1665 cw_apps(page, pos, cap, "<div class='goal'>velocity &middot; all actors &middot; all-time " as *u8) 1666 cw_appn(page, pos, cap, donetot) 1667 cw_apps(page, pos, cap, "</div>" as *u8) 1668 cw_spark(page, pos, cap, done) 1669 cw_apps(page, pos, cap, "</div></div>\n" as *u8) 1670 // ONE story chart: all closures (area) + non-Claude (line), direct-labeled 1671 // at the right edge -- no legend to decode, time reads left to right 1672 var mx: i64 = 1 1673 var mi2: i64 = 0 1674 while mi2 < 14 { if done[mi2] > mx { mx = done[mi2] } mi2 = mi2 + 1 } 1675 cw_apps(page, pos, cap, "<h2>the last 14 journal days</h2>\n<div class='svgwrap'><svg width='660' height='230' viewBox='0 0 660 230'><defs><linearGradient id='gA' x1='0' y1='0' x2='0' y2='1'><stop offset='0' stop-color='var(--acc)' stop-opacity='.25'/><stop offset='1' stop-color='var(--acc)' stop-opacity='0'/></linearGradient></defs>" as *u8) 1676 cw_apps(page, pos, cap, "<line x1='44' y1='178' x2='580' y2='178' stroke='var(--br)'/><line x1='44' y1='98' x2='580' y2='98' stroke='var(--br)' stroke-dasharray='3 4'/><line x1='44' y1='18' x2='580' y2='18' stroke='var(--br)' stroke-dasharray='3 4'/>" as *u8) 1677 cw_apps(page, pos, cap, "<text x='40' y='182' font-size='10' text-anchor='end' fill='var(--svgt)'>0</text><text x='40' y='102' font-size='10' text-anchor='end' fill='var(--svgt)'>" as *u8) 1678 cw_appn(page, pos, cap, mx / 2) 1679 cw_apps(page, pos, cap, "</text><text x='40' y='22' font-size='10' text-anchor='end' fill='var(--svgt)'>" as *u8) 1680 cw_appn(page, pos, cap, mx) 1681 cw_apps(page, pos, cap, "</text>" as *u8) 1682 cw_apps(page, pos, cap, "<path fill='url(#gA)' stroke='none' d='M44,178 L" as *u8) 1683 cw_plpts(page, pos, cap, done, mx, 44, 18, 536, 160) 1684 cw_apps(page, pos, cap, " L580,178 Z'/><polyline fill='none' stroke='var(--acc)' stroke-width='2.5' stroke-linejoin='round' stroke-linecap='round' points='" as *u8) 1685 cw_plpts(page, pos, cap, done, mx, 44, 18, 536, 160) 1686 cw_apps(page, pos, cap, "'/><polyline fill='none' stroke='var(--acc2)' stroke-width='2' stroke-linejoin='round' points='" as *u8) 1687 cw_plpts(page, pos, cap, noncl, mx, 44, 18, 536, 160) 1688 cw_apps(page, pos, cap, "'/>" as *u8) 1689 cw_apps(page, pos, cap, "<text x='588' y='" as *u8) 1690 cw_appn(page, pos, cap, 182 - (done[0] * 160) / mx) 1691 cw_apps(page, pos, cap, "' font-size='11' fill='var(--acc)'>all " as *u8) 1692 cw_appn(page, pos, cap, done[0]) 1693 cw_apps(page, pos, cap, "</text><text x='588' y='" as *u8) 1694 cw_appn(page, pos, cap, 196 - (noncl[0] * 160) / mx) 1695 cw_apps(page, pos, cap, "' font-size='11' fill='var(--acc2)'>non-Claude " as *u8) 1696 cw_appn(page, pos, cap, noncl[0]) 1697 cw_apps(page, pos, cap, "</text><text x='44' y='212' font-size='9' fill='var(--svgt)'>14 days ago</text><text x='580' y='212' font-size='9' text-anchor='end' fill='var(--svgt)'>today</text></svg></div>\n" as *u8) 1698 // the decision rail: where to act on what the gauges say 1699 cw_apps(page, pos, cap, "<h2>what moves these numbers</h2>\n<div class='tiles'><div class='tile'><div class='v'>&#128295;</div><div class='k'><a href='tools" as *u8) 1700 cw_appext(page, pos, cap, noext2) 1701 cw_apps(page, pos, cap, "'>use the capability catalog</a> &mdash; a shell lane usually means the verb existed and was not found</div></div><div class='tile'><div class='v'>&#128203;</div><div class='k'>the ranked build order: knowledge/status/self_sufficiency_map_20260729.md (seq1231 transfer verbs &middot; seq1126 async-job &middot; TS03 maker dispatch)</div></div><div class='tile'><div class='v'>&#129302;</div><div class='k'><a href='findings" as *u8) 1702 cw_appext(page, pos, cap, noext2) 1703 cw_apps(page, pos, cap, "'>the findings backlog</a> &mdash; work the maker beats can take next</div></div></div>\n" as *u8) 1704 // the token meter: a TABLE, because a missing meter day is ABSENT, not zero 1705 cw_apps(page, pos, cap, "<h2>seat token meter <span class='cnt'>(daily harvest rows; missing days are absent, never zero)</span></h2>\n" as *u8) 1706 if mn <= 0 { 1707 cw_apps(page, pos, cap, "<p class='muted'>meter log not present in this build environment.</p>\n" as *u8) 1708 } else { 1709 cw_apps(page, pos, cap, "<table><tr><th class='n'>day (relative)</th><th>seat</th><th class='n'>sessions</th><th class='n'>output tok</th><th class='n'>cache-read tok</th></tr>\n" as *u8) 1710 var ms: i64 = 0 1711 while ms < mn { 1712 var me: i64 = ms 1713 var g2: i64 = 1 1714 while g2 == 1 { if me >= mn { g2 = 0 } else { if mb[me] == (10 as u8) { g2 = 0 } else { me = me + 1 } } } 1715 let m1e: i64 = cw_fld(mb, ms, me) 1716 if m1e < me { 1717 let mep: i64 = cw_atoi(mb, ms, m1e) 1718 let m2s: i64 = m1e + 1 1719 let m2e: i64 = cw_fld(mb, m2s, me) 1720 let m3s: i64 = m2e + 1 1721 let m3e: i64 = cw_fld(mb, m3s, me) 1722 let m4s: i64 = m3e + 1 1723 let m4e: i64 = cw_fld(mb, m4s, me) 1724 let m5s: i64 = m4e + 1 1725 let m5e: i64 = cw_fld(mb, m5s, me) 1726 cw_apps(page, pos, cap, "<tr><td class='n'>d-" as *u8) 1727 var mdd: i64 = 0 1728 if maxep > 0 { mdd = (maxep / CW_MAGIC_86400) - (mep / CW_MAGIC_86400) } 1729 cw_appn(page, pos, cap, mdd) 1730 cw_apps(page, pos, cap, "</td><td><code>" as *u8) 1731 cw_appe(page, pos, cap, ((mb as i64) + m2s) as *u8, m2e - m2s) 1732 cw_apps(page, pos, cap, "</code></td><td class='n'>" as *u8) 1733 cw_appe(page, pos, cap, ((mb as i64) + m3s) as *u8, m3e - m3s) 1734 cw_apps(page, pos, cap, "</td><td class='n'>" as *u8) 1735 cw_appe(page, pos, cap, ((mb as i64) + m4s) as *u8, m4e - m4s) 1736 cw_apps(page, pos, cap, "</td><td class='n'>" as *u8) 1737 cw_appe(page, pos, cap, ((mb as i64) + m5s) as *u8, m5e - m5s) 1738 cw_apps(page, pos, cap, "</td></tr>\n" as *u8) 1739 } 1740 ms = me + 1 1741 } 1742 cw_apps(page, pos, cap, "</table>\n" as *u8) 1743 } 1744 cw_apps(page, pos, cap, "<p class='muted'>envelope: journal read whole (declared cap), newest epoch " as *u8) 1745 cw_appn(page, pos, cap, maxep) 1746 cw_apps(page, pos, cap, "; actor class = name prefix 'claude'; foreign/sovereign = declared substring lists over DONE notes (one mention per note per side); verdict = week-over-week deltas of the two goal gauges (both good = moving, one = mixed, none = stalled). The full build order: knowledge/status/self_sufficiency_map_20260729.md</p>\n" as *u8) 1747 return donetot 1748} 1749 1750// ---------- the capability catalog: SOTA discoverability (rung 19) ---------- 1751// One row per REGISTERED tool -- name, what it does (schema title), the argv 1752// grammar (schema col 8), an anchor -- plus toolindex.js so client search and 1753// /code/ask retrieve CAPABILITIES exactly like modules. The discovery failure 1754// this eats is documented and personal: nx_page_verify existed all evening 1755// while its own consumer hand-rolled page verification. Inputs are parameters 1756// (the gate fixtures them); an absent input SAYS so, never renders as "none". 1757// schema-row resolver shared by the capability catalog and the askindex 1758// T-rows: find name's row (name = conf[ns..ne)) in the schema conf. box gets 1759// [title_s, title_e, grammar_s, grammar_e] as byte offsets into sch (-1 = 1760// absent). First match wins, exactly as the catalog always behaved. One copy 1761// so the page, toolindex.js and the retrieval corpus cannot drift apart. 1762func cw_schemarow(sch: *u8, schn: i64, conf: *u8, ns: i64, ne: i64, box: *i64) -> i64 { 1763 box[0] = 0 - 1 1764 box[1] = 0 - 1 1765 box[2] = 0 - 1 1766 box[3] = 0 - 1 1767 var found: i64 = 0 1768 var sls: i64 = 0 1769 while sls < schn { 1770 var sle: i64 = sls 1771 var sg: i64 = 1 1772 while sg == 1 { if sle >= schn { sg = 0 } else { if sch[sle] == (10 as u8) { sg = 0 } else { sle = sle + 1 } } } 1773 if found == 0 { if sle > sls { if sch[sls] != (35 as u8) { 1774 let sn1: i64 = cw_fld(sch, sls, sle) 1775 if sn1 - sls == ne - ns { 1776 var seq2: i64 = 1 1777 var sc2: i64 = 0 1778 while sc2 < sn1 - sls { if sch[sls + sc2] != conf[ns + sc2] { seq2 = 0; sc2 = sn1 - sls } else { sc2 = sc2 + 1 } } 1779 if seq2 == 1 { 1780 found = 1 1781 var fs2: i64 = sn1 + 1 1782 var fe2: i64 = cw_fld(sch, fs2, sle) 1783 box[0] = fs2 1784 box[1] = fe2 1785 var fk: i64 = 2 1786 var fks: i64 = fs2 1787 var fke: i64 = fe2 1788 while fk < 8 { if fke < sle { fks = fke + 1; fke = cw_fld(sch, fks, sle); fk = fk + 1 } else { fk = 8 } } 1789 if fk == 8 { if fke > fks { box[2] = fks; box[3] = fke } } 1790 } 1791 } 1792 } } } 1793 sls = sle + 1 1794 } 1795 return found 1796} 1797 1798// Emits catalog rows into page and JS rows into tix; returns row count. 1799func cw_tools(page: *u8, pos: *i64, cap: i64, tix: *u8, tpos: *i64, 1800 allowpath: *u8, schemapath: *u8) -> i64 { 1801 let conf: *u8 = sys_mmap(CW_EXPCONF) 1802 let confn: i64 = gl_read(allowpath, conf, CW_EXPCONF) 1803 let sch: *u8 = sys_mmap(CW_EXPCONF) 1804 let schn: i64 = gl_read(schemapath, sch, CW_EXPCONF) 1805 let sbox: *i64 = sys_mmap(64) as *i64 1806 cw_apps(tix, tpos, CW_PAGECAP, "var TOOLS=[" as *u8) 1807 var nrows: i64 = 0 1808 if confn <= 0 { 1809 cw_apps(page, pos, cap, "<p class='muted'>allowlist not present in this build environment -- the NAS regeneration carries the real catalog; absence of the INPUT is not an empty ANSWER.</p>\n" as *u8) 1810 } else { 1811 cw_apps(page, pos, cap, "<table><tr><th>capability</th><th>what it does</th><th>call grammar (argv)</th></tr>\n" as *u8) 1812 var ls: i64 = 0 1813 while ls < confn { 1814 var le: i64 = ls 1815 var g1: i64 = 1 1816 while g1 == 1 { if le >= confn { g1 = 0 } else { if conf[le] == (10 as u8) { g1 = 0 } else { le = le + 1 } } } 1817 if le > ls + 2 { if conf[ls] != (35 as u8) { 1818 let f1e: i64 = cw_fld(conf, ls, le) 1819 if f1e < le { 1820 nrows = nrows + 1 1821 // locate this tool's schema row via the shared resolver 1822 // (title = field 2, grammar = field 8): one copy feeds the 1823 // catalog page, toolindex.js AND the askindex T-rows. 1824 cw_schemarow(sch, schn, conf, ls, f1e, sbox) 1825 let tts: i64 = sbox[0] 1826 let tte: i64 = sbox[1] 1827 let tgs: i64 = sbox[2] 1828 let tge: i64 = sbox[3] 1829 cw_apps(page, pos, cap, "<tr data-m='" as *u8) 1830 cw_appe(page, pos, cap, ((conf as i64) + ls) as *u8, f1e - ls) 1831 cw_apps(page, pos, cap, "'><td id='t_" as *u8) 1832 cw_appe(page, pos, cap, ((conf as i64) + ls) as *u8, f1e - ls) 1833 cw_apps(page, pos, cap, "'><code>" as *u8) 1834 cw_appe(page, pos, cap, ((conf as i64) + ls) as *u8, f1e - ls) 1835 cw_apps(page, pos, cap, "</code></td><td class='muted'>" as *u8) 1836 if tte > tts { cw_appe(page, pos, cap, ((sch as i64) + tts) as *u8, tte - tts) } else { cw_apps(page, pos, cap, "(capability undocumented -- the schema-less finding covers it)" as *u8) } 1837 cw_apps(page, pos, cap, "</td><td class='sig'>" as *u8) 1838 if tge > tgs { cw_appe(page, pos, cap, ((sch as i64) + tgs) as *u8, tge - tgs) } 1839 cw_apps(page, pos, cap, "</td></tr>\n" as *u8) 1840 cw_apps(tix, tpos, CW_PAGECAP, "[\"" as *u8) 1841 cw_appjse(tix, tpos, CW_PAGECAP, ((conf as i64) + ls) as *u8, f1e - ls) 1842 cw_apps(tix, tpos, CW_PAGECAP, "\",\"" as *u8) 1843 if tte > tts { cw_appjse(tix, tpos, CW_PAGECAP, ((sch as i64) + tts) as *u8, tte - tts) } 1844 cw_apps(tix, tpos, CW_PAGECAP, "\",\"" as *u8) 1845 if tge > tgs { cw_appjse(tix, tpos, CW_PAGECAP, ((sch as i64) + tgs) as *u8, tge - tgs) } 1846 cw_apps(tix, tpos, CW_PAGECAP, "\"],\n" as *u8) 1847 } 1848 } } 1849 ls = le + 1 1850 } 1851 cw_apps(page, pos, cap, "</table>\n" as *u8) 1852 } 1853 cw_apps(tix, tpos, CW_PAGECAP, "];\n" as *u8) 1854 return nrows 1855} 1856 1857// askindex T-rows: capabilities as RETRIEVAL RECORDS (rung 23 -- the organ 1858// side of rung 19's discoverability law: nx_codewiki_ask and the answer beat 1859// must retrieve capabilities exactly like modules; the browser side already 1860// does via toolindex.js). Emits T<TAB>name<TAB>title<TAB>grammar per 1861// allowlist row (TSV-safe), returns the row count. Inputs are parameters so 1862// the gate fixtures the join without touching the prod CWD. 1863func cw_asktools(abuf: *u8, apos: *i64, acap: i64, allowpath: *u8, schemapath: *u8) -> i64 { 1864 let conf: *u8 = sys_mmap(CW_EXPCONF) 1865 let confn: i64 = gl_read(allowpath, conf, CW_EXPCONF) 1866 if confn <= 0 { return 0 } 1867 let sch: *u8 = sys_mmap(CW_EXPCONF) 1868 let schn: i64 = gl_read(schemapath, sch, CW_EXPCONF) 1869 let sbox: *i64 = sys_mmap(64) as *i64 1870 var nrows: i64 = 0 1871 var ls: i64 = 0 1872 while ls < confn { 1873 var le: i64 = ls 1874 var g1: i64 = 1 1875 while g1 == 1 { if le >= confn { g1 = 0 } else { if conf[le] == (10 as u8) { g1 = 0 } else { le = le + 1 } } } 1876 if le > ls + 2 { if conf[ls] != (35 as u8) { 1877 let f1e: i64 = cw_fld(conf, ls, le) 1878 if f1e < le { 1879 nrows = nrows + 1 1880 cw_schemarow(sch, schn, conf, ls, f1e, sbox) 1881 cw_apps(abuf, apos, acap, "T\t" as *u8) 1882 cw_apptsv(abuf, apos, acap, ((conf as i64) + ls) as *u8, f1e - ls) 1883 cw_apps(abuf, apos, acap, "\t" as *u8) 1884 if sbox[1] > sbox[0] { cw_apptsv(abuf, apos, acap, ((sch as i64) + sbox[0]) as *u8, sbox[1] - sbox[0]) } 1885 cw_apps(abuf, apos, acap, "\t" as *u8) 1886 if sbox[3] > sbox[2] { cw_apptsv(abuf, apos, acap, ((sch as i64) + sbox[2]) as *u8, sbox[3] - sbox[2]) } 1887 cw_apps(abuf, apos, acap, "\n" as *u8) 1888 } 1889 } } 1890 ls = le + 1 1891 } 1892 return nrows 1893} 1894 1895// ---------- atlas: the family -> domain conformance ruler (seq1220) ---------- 1896// 1897// The ecosystem's domain taxonomy is DECLARED data (the atlas conf: rows 1898// family<TAB>domain, # comments) joined against the tree's MEASURED families. 1899// Renders: conformance permil by LOC (goal RISING, data-conf contract attr), 1900// the mapped domain table, the unmapped work list biggest-LOC-first, and 1901// stale conf rows (a mapping naming no current family) -- declared, never 1902// silently dropped. Files one aggregate finding while unmapped families 1903// exist. Inputs are parameters so the gate fixtures the join. 1904func cw_atlas(page: *u8, pos: *i64, cap: i64, 1905 famarena: *u8, famoff: *i64, famlen: *i64, famcnt: *i64, 1906 famloc: *i64, nfam: i64, atlaspath: *u8, noext: i64, 1907 fbuf: *u8, fpos: *i64) -> i64 { 1908 let conf: *u8 = sys_mmap(CW_EXPCONF) 1909 let confn: i64 = gl_read(atlaspath, conf, CW_EXPCONF) 1910 if confn <= 0 { 1911 cw_apps(page, pos, cap, "<p class='muted'>atlas conf not present in this build environment -- the NAS regeneration carries the real mapping; absence of the INPUT is not an empty ANSWER. Every eligible family below is UNMAPPED by definition of this run.</p>\n" as *u8) 1912 } 1913 let famdom: *i64 = sys_mmap(CW_MAXFAM * 8) as *i64 1914 let famdle: *i64 = sys_mmap(CW_MAXFAM * 8) as *i64 1915 var fz: i64 = 0 1916 while fz < nfam { famdom[fz] = 0 - 1; famdle[fz] = 0 - 1; fz = fz + 1 } 1917 var stale: i64 = 0 1918 let stbuf: *u8 = sys_mmap(CW_MAGIC_4096) 1919 let stpos: *i64 = sys_mmap(32) as *i64 1920 stpos[0] = 0 1921 stpos[1] = 0 1922 var ls: i64 = 0 1923 while ls < confn { 1924 var le: i64 = ls 1925 var g1: i64 = 1 1926 while g1 == 1 { if le >= confn { g1 = 0 } else { if conf[le] == (10 as u8) { g1 = 0 } else { le = le + 1 } } } 1927 if le > ls + 2 { if conf[ls] != (35 as u8) { 1928 let f1e: i64 = cw_fld(conf, ls, le) 1929 if f1e < le { 1930 let d2s: i64 = f1e + 1 1931 let d2e: i64 = cw_fld(conf, d2s, le) 1932 var fidx: i64 = 0 - 1 1933 var ff: i64 = 0 1934 while ff < nfam { 1935 if fidx < 0 { if famlen[ff] == f1e - ls { 1936 var eq: i64 = 1 1937 var fc: i64 = 0 1938 while fc < famlen[ff] { if famarena[famoff[ff] + fc] != conf[ls + fc] { eq = 0; fc = famlen[ff] } else { fc = fc + 1 } } 1939 if eq == 1 { fidx = ff } 1940 } } 1941 ff = ff + 1 1942 } 1943 if fidx >= 0 { famdom[fidx] = d2s; famdle[fidx] = d2e } else { 1944 stale = stale + 1 1945 cw_apps(stbuf, stpos, CW_MAGIC_4096, "<code>" as *u8) 1946 cw_appe(stbuf, stpos, CW_MAGIC_4096, ((conf as i64) + ls) as *u8, f1e - ls) 1947 cw_apps(stbuf, stpos, CW_MAGIC_4096, "</code> " as *u8) 1948 } 1949 } 1950 } } 1951 ls = le + 1 1952 } 1953 var elig: i64 = 0 1954 var mapped: i64 = 0 1955 var tloc: i64 = 0 1956 var mloc: i64 = 0 1957 var fe: i64 = 0 1958 while fe < nfam { 1959 if famcnt[fe] >= CW_FAMMIN { 1960 elig = elig + 1 1961 tloc = tloc + famloc[fe] 1962 if famdom[fe] >= 0 { mapped = mapped + 1; mloc = mloc + famloc[fe] } 1963 } 1964 fe = fe + 1 1965 } 1966 var permil: i64 = 0 1967 if tloc > 0 { permil = (mloc * 1000) / tloc } 1968 cw_apps(page, pos, cap, "<p>conformance: <b data-conf='" as *u8) 1969 cw_appn(page, pos, cap, permil) 1970 cw_apps(page, pos, cap, "'>" as *u8) 1971 cw_appn(page, pos, cap, permil) 1972 cw_apps(page, pos, cap, "&permil;</b> of eligible-family LOC is atlas-mapped (goal RISING) &middot; " as *u8) 1973 cw_appn(page, pos, cap, mapped) 1974 cw_apps(page, pos, cap, " of " as *u8) 1975 cw_appn(page, pos, cap, elig) 1976 cw_apps(page, pos, cap, " eligible families mapped</p>\n" as *u8) 1977 cw_apps(page, pos, cap, "<h2>domains</h2>\n<table><tr><th>domain</th><th>family</th><th>modules</th><th>loc</th></tr>\n" as *u8) 1978 var fm: i64 = 0 1979 while fm < nfam { 1980 if famcnt[fm] >= CW_FAMMIN { if famdom[fm] >= 0 { 1981 cw_apps(page, pos, cap, "<tr><td>" as *u8) 1982 cw_appe(page, pos, cap, ((conf as i64) + famdom[fm]) as *u8, famdle[fm] - famdom[fm]) 1983 cw_apps(page, pos, cap, "</td><td><a href='t_" as *u8) 1984 cw_appe(page, pos, cap, ((famarena as i64) + famoff[fm]) as *u8, famlen[fm]) 1985 cw_appext(page, pos, cap, noext) 1986 cw_apps(page, pos, cap, "'>" as *u8) 1987 cw_appe(page, pos, cap, ((famarena as i64) + famoff[fm]) as *u8, famlen[fm]) 1988 cw_apps(page, pos, cap, "</a></td><td class='n'>" as *u8) 1989 cw_appn(page, pos, cap, famcnt[fm]) 1990 cw_apps(page, pos, cap, "</td><td class='n'>" as *u8) 1991 cw_appn(page, pos, cap, famloc[fm]) 1992 cw_apps(page, pos, cap, "</td></tr>\n" as *u8) 1993 } } 1994 fm = fm + 1 1995 } 1996 cw_apps(page, pos, cap, "</table>\n<h2>unmapped families (biggest LOC first -- the work list)</h2>\n<table><tr><th>family</th><th>modules</th><th>loc</th></tr>\n" as *u8) 1997 // selection-emit by descending LOC; famloc entries are negated as a 1998 // visited mark and RESTORED after (the table is a view, not a mutation) 1999 var guard: i64 = 0 2000 while guard < nfam { 2001 var best: i64 = 0 - 1 2002 var bl: i64 = 0 - 1 2003 var fu: i64 = 0 2004 while fu < nfam { 2005 if famcnt[fu] >= CW_FAMMIN { if famdom[fu] < 0 { if famloc[fu] > bl { 2006 best = fu 2007 bl = famloc[fu] 2008 } } } 2009 fu = fu + 1 2010 } 2011 if best < 0 { guard = nfam } else { 2012 cw_apps(page, pos, cap, "<tr><td><a href='t_" as *u8) 2013 cw_appe(page, pos, cap, ((famarena as i64) + famoff[best]) as *u8, famlen[best]) 2014 cw_appext(page, pos, cap, noext) 2015 cw_apps(page, pos, cap, "'>" as *u8) 2016 cw_appe(page, pos, cap, ((famarena as i64) + famoff[best]) as *u8, famlen[best]) 2017 cw_apps(page, pos, cap, "</a></td><td class='n'>" as *u8) 2018 cw_appn(page, pos, cap, famcnt[best]) 2019 cw_apps(page, pos, cap, "</td><td class='n'>" as *u8) 2020 cw_appn(page, pos, cap, famloc[best]) 2021 cw_apps(page, pos, cap, "</td></tr>\n" as *u8) 2022 famloc[best] = 0 - famloc[best] - 1 2023 guard = guard + 1 2024 } 2025 } 2026 var fr: i64 = 0 2027 while fr < nfam { if famloc[fr] < 0 { famloc[fr] = 0 - (famloc[fr] + 1) } fr = fr + 1 } 2028 cw_apps(page, pos, cap, "</table>\n" as *u8) 2029 if stale > 0 { 2030 cw_apps(page, pos, cap, "<h2>stale mapping rows (conf names no current family)</h2>\n<p class='muted'>" as *u8) 2031 cw_app(page, pos, cap, stbuf, stpos[0]) 2032 cw_apps(page, pos, cap, "</p>\n" as *u8) 2033 } 2034 if elig - mapped > 0 { 2035 cw_fnd(fbuf, fpos, 5, "codewiki-atlas" as *u8, "Atlas-unmapped families present: eligible families carry no domain row in the atlas conf. https://nishifamily.com/code/atlas -- add the family-to-domain row (rule 11: extend the conf); conformance rises at the next regen." as *u8) 2036 } 2037 return elig 2038} 2039 2040// Index of `needle` in NUL-terminated `name`, or -1. cw_namehas answers 2041// "is it there"; the sprawl rule needs WHERE, to derive the base name. 2042func cw_nameidx(name: *u8, needle: *u8) -> i64 { 2043 let n: i64 = gl_len(name) 2044 let m: i64 = gl_len(needle) 2045 if m <= 0 { return 0 - 1 } 2046 var i: i64 = 0 2047 while i + m <= n { 2048 var k: i64 = 0 2049 var ok: i64 = 1 2050 while k < m { if name[i + k] != needle[k] { ok = 0; k = m } else { k = k + 1 } } 2051 if ok == 1 { return i } 2052 i = i + 1 2053 } 2054 return 0 - 1 2055} 2056 2057// Is `<base>.elf` -- the name truncated at its version marker -- ALSO in the 2058// deployed set? That is the WHOLE difference between a stale-promote hazard 2059// and an organ whose NAME merely carries a version. 2060// 2061// `sites_new2.elf` beside `sites.elf` is genuinely ambiguous: a promote could 2062// pick either, which is what the finding warns about. `nx_signaling_v2.elf` 2063// with NO `nx_signaling.elf` is simply an organ called v2 -- and the edge SSOT 2064// itself is `nx_sites_daemon_v2`. Flagging those is a false alarm, and a gauge 2065// that cries wolf teaches its reader to ignore the real rows. 2066func cw_has_base_sibling(earena: *u8, eoff: *i64, nelf: i64, cut: i64, snm: *u8) -> i64 { 2067 if cut <= 0 { return 0 } 2068 let bb: *u8 = sys_mmap(CW_MAGIC_4096) 2069 var b: i64 = 0 2070 while b < cut { bb[b] = snm[b]; b = b + 1 } 2071 bb[b] = 46 as u8 2072 bb[b + 1] = 101 as u8 2073 bb[b + 2] = 108 as u8 2074 bb[b + 3] = 102 as u8 2075 bb[b + 4] = 0 as u8 2076 let bl: i64 = b + 4 2077 var e: i64 = 0 2078 while e < nelf { 2079 let o: *u8 = ((earena as i64) + eoff[e]) as *u8 2080 if gl_len(o) == bl { 2081 var q: i64 = 0 2082 var same: i64 = 1 2083 while q < bl { if o[q] != bb[q] { same = 0; q = bl } else { q = q + 1 } } 2084 if same == 1 { return 1 } 2085 } 2086 e = e + 1 2087 } 2088 return 0 2089} 2090 2091// ---------- exposure: where MCP / API coverage is and is not ---------- 2092// 2093// Joins three ground truths the ecosystem already maintains -- the MCP 2094// allowlist (name<TAB>elf<TAB>GREEN[<TAB>args]), the deployed *.elf set in the 2095// host dir, and this wiki's own module+kind table -- into the map the operator 2096// asked for: what is EXPOSED, what is DEPLOYED BUT DARK (no MCP row), and how 2097// long the local-only tail is. Inputs are parameters so the gate can fixture 2098// them; when an input is absent (laptop build) the page SAYS so instead of 2099// rendering an empty section as if the answer were "none". 2100// Returns exposed-row count; writes dark count to darkbox[0]. 2101func cw_exposure(page: *u8, pos: *i64, cap: i64, g: *EcoGraph, pathoff: *i64, 2102 kindv: *i64, sidx: *i64, nsorted: i64, noext: i64, 2103 confpath: *u8, elfdir: *u8, darkbox: *i64, fbuf: *u8, fpos: *i64, 2104 srcmt: *i64) -> i64 { 2105 let conf: *u8 = sys_mmap(CW_EXPCONF) 2106 let confn: i64 = gl_read(confpath, conf, CW_EXPCONF) 2107 2108 // deployed *.elf basenames (one directory, non-recursive, cap declared) 2109 let earena: *u8 = sys_mmap(CW_EXPARENA) 2110 let eoff: *i64 = sys_mmap(CW_EXPELFS * 8) as *i64 2111 var nelf: i64 = 0 2112 var eu: i64 = 0 2113 let dfd: i64 = sys_openat_rd(elfdir) 2114 if dfd >= 0 { 2115 let dbuf: *u8 = sys_mmap(CW_MAGIC_131072) 2116 var go: i64 = 1 2117 while go == 1 { 2118 let nr: i64 = sys_getdents64(dfd, dbuf, CW_MAGIC_131072) 2119 if nr <= 0 { go = 0 } else { 2120 var off: i64 = 0 2121 while off < nr { 2122 let rec: *u8 = ((dbuf as i64) + off) as *u8 2123 let nm: *u8 = dirent_name(rec) 2124 let nl: i64 = gl_len(nm) 2125 if gl_ends(nm, nl, ".elf" as *u8) == 1 { if nelf < CW_EXPELFS { if eu + nl + 1 < CW_EXPARENA { 2126 eoff[nelf] = eu 2127 var c0: i64 = 0 2128 while c0 <= nl { earena[eu + c0] = nm[c0]; c0 = c0 + 1 } 2129 eu = eu + nl + 1 2130 nelf = nelf + 1 2131 } } } 2132 off = off + dirent_reclen(rec) 2133 } 2134 } 2135 } 2136 sys_close(dfd) 2137 } 2138 2139 // the CAPABILITY layer: tool_schemas.conf carries what each tool DOES 2140 // (title) + its MCP safety annotations. Joining it here turns the exposure 2141 // page from a list of names into the team's living capability catalog. 2142 let sch: *u8 = sys_mmap(CW_EXPCONF) 2143 let schn: i64 = gl_read("knowledge/tool_schemas.conf" as *u8, sch, CW_EXPCONF) 2144 2145 cw_apps(page, pos, cap, "<h2 id='exposure'>exposure: MCP + API coverage</h2>\n" as *u8) 2146 if confn <= 0 { 2147 cw_apps(page, pos, cap, "<p class='muted'>allowlist not present in this build environment -- the NAS regeneration carries the real join; absence of the INPUT is not an empty ANSWER.</p>\n" as *u8) 2148 } 2149 2150 // pass 1 over the allowlist: emit exposed rows, remember exposed elf names 2151 let xoff: *i64 = sys_mmap(CW_EXPELFS * 8) as *i64 2152 var nexp: i64 = 0 2153 var nundoc: i64 = 0 2154 if confn > 0 { 2155 cw_apps(page, pos, cap, "<h2>MCP-exposed capabilities <span class='cnt'>what the team can DO -- title + safety annotations from the live schema registry, joined to the code</span></h2>\n<table><tr><th>capability</th><th>what it does</th><th>module</th></tr>\n" as *u8) 2156 var ls: i64 = 0 2157 while ls < confn { 2158 var le: i64 = ls 2159 var g1: i64 = 1 2160 while g1 == 1 { if le >= confn { g1 = 0 } else { if conf[le] == (10 as u8) { g1 = 0 } else { le = le + 1 } } } 2161 if le > ls + 2 { if conf[ls] != (35 as u8) { 2162 let f1e: i64 = cw_fld(conf, ls, le) 2163 if f1e < le { 2164 let f2s: i64 = f1e + 1 2165 let f2e: i64 = cw_fld(conf, f2s, le) 2166 // elf basename 2167 var bs: i64 = f2s 2168 var bi: i64 = f2s 2169 while bi < f2e { if conf[bi] == (47 as u8) { bs = bi + 1 } bi = bi + 1 } 2170 if nexp < CW_EXPELFS { xoff[nexp] = bs } 2171 nexp = nexp + 1 2172 cw_apps(page, pos, cap, "<tr><td><code>" as *u8) 2173 cw_appe(page, pos, cap, ((conf as i64) + ls) as *u8, f1e - ls) 2174 cw_apps(page, pos, cap, "</code></td><td class='muted'>" as *u8) 2175 // capability title: find this tool's row in tool_schemas.conf 2176 var tfound: i64 = 0 2177 if schn > 0 { 2178 var sls: i64 = 0 2179 while sls < schn { 2180 var sle: i64 = sls 2181 var sg: i64 = 1 2182 while sg == 1 { if sle >= schn { sg = 0 } else { if sch[sle] == (10 as u8) { sg = 0 } else { sle = sle + 1 } } } 2183 if tfound == 0 { if sle > sls { if sch[sls] != (35 as u8) { 2184 let sn1: i64 = cw_fld(sch, sls, sle) 2185 if sn1 - sls == f1e - ls { 2186 var seq2: i64 = 1 2187 var sc2: i64 = 0 2188 while sc2 < sn1 - sls { if sch[sls + sc2] != conf[ls + sc2] { seq2 = 0; sc2 = sn1 - sls } else { sc2 = sc2 + 1 } } 2189 if seq2 == 1 { 2190 let st1: i64 = sn1 + 1 2191 let st2: i64 = cw_fld(sch, st1, sle) 2192 if st2 > st1 { cw_appe(page, pos, cap, ((sch as i64) + st1) as *u8, st2 - st1); tfound = 1 } 2193 } 2194 } 2195 } } } 2196 sls = sle + 1 2197 } 2198 } 2199 if tfound == 0 { cw_apps(page, pos, cap, "<i>no schema row -- capability undocumented</i>" as *u8); nundoc = nundoc + 1 } 2200 cw_apps(page, pos, cap, "</td><td>" as *u8) 2201 // elf basename minus .elf + ".nx" -> module? 2202 let stl: i64 = f2e - bs - 4 2203 var found: i64 = 0 - 1 2204 if stl > 0 { if stl < 90 { 2205 let nmb: *u8 = sys_mmap(128) 2206 var c1: i64 = 0 2207 while c1 < stl { nmb[c1] = conf[bs + c1]; c1 = c1 + 1 } 2208 cw_rawcpy(nmb, stl, ".nx" as *u8) 2209 nmb[stl + 3] = 0 as u8 2210 found = eg_find(g, nmb, stl + 3) 2211 if found >= 0 { if pathoff[found] == 0 { found = 0 - 1 } } 2212 if found >= 0 { cw_applink2(page, pos, cap, nmb, noext) } 2213 } } 2214 if found < 0 { cw_apps(page, pos, cap, "<span class='muted'>no module in this tree</span>" as *u8) } 2215 cw_apps(page, pos, cap, "</td></tr>\n" as *u8) 2216 } 2217 } } 2218 ls = le + 1 2219 } 2220 cw_apps(page, pos, cap, "</table>\n" as *u8) 2221 if nundoc > 0 { 2222 cw_apps(page, pos, cap, "<p class='muted'>capabilities exposed but carrying no schema row (callable, undocumented): " as *u8) 2223 cw_appn(page, pos, cap, nundoc) 2224 cw_apps(page, pos, cap, " -- an agent can invoke them but cannot learn what they do.</p>\n" as *u8) 2225 cw_fnd(fbuf, fpos, 5, "capabilities" as *u8, 2226 "MCP capabilities are exposed without a schema row (callable but undocumented -- an agent can invoke them without learning what they do). https://nishifamily.com/code/exposure -- add a title via /api/tools/register (title creates the schema row) per capability." as *u8) 2227 } 2228 } 2229 2230 // deployed elfs with NO allowlist row = the dark-capability list 2231 var ndark: i64 = 0 2232 if nelf > 0 { 2233 cw_apps(page, pos, cap, "<h2>deployed but NOT MCP-exposed <span class='cnt'>the dark-capability list -- where an MCP row is likely needed</span></h2>\n<p>" as *u8) 2234 var e1: i64 = 0 2235 while e1 < nelf { 2236 let enm: *u8 = ((earena as i64) + eoff[e1]) as *u8 2237 let enl: i64 = gl_len(enm) 2238 var isexp: i64 = 0 2239 var x1: i64 = 0 2240 while x1 < nexp { if x1 < CW_EXPELFS { 2241 let xs: i64 = xoff[x1] 2242 var eq: i64 = 1 2243 var c2: i64 = 0 2244 while c2 < enl { if conf[xs + c2] != enm[c2] { eq = 0; c2 = enl } else { c2 = c2 + 1 } } 2245 if eq == 1 { isexp = 1 } 2246 } x1 = x1 + 1 } 2247 if isexp == 0 { 2248 ndark = ndark + 1 2249 if ndark <= CW_EXPSHOW { 2250 cw_apps(page, pos, cap, "<span class='pill'>" as *u8) 2251 // module link when the stem matches 2252 let stl2: i64 = enl - 4 2253 var f2: i64 = 0 - 1 2254 if stl2 > 0 { if stl2 < 90 { 2255 let nmb2: *u8 = sys_mmap(128) 2256 var c3: i64 = 0 2257 while c3 < stl2 { nmb2[c3] = enm[c3]; c3 = c3 + 1 } 2258 cw_rawcpy(nmb2, stl2, ".nx" as *u8) 2259 nmb2[stl2 + 3] = 0 as u8 2260 f2 = eg_find(g, nmb2, stl2 + 3) 2261 if f2 >= 0 { if pathoff[f2] == 0 { f2 = 0 - 1 } } 2262 if f2 >= 0 { cw_applink2(page, pos, cap, nmb2, noext) } 2263 } } 2264 if f2 < 0 { cw_appe(page, pos, cap, enm, enl) } 2265 cw_apps(page, pos, cap, "</span>" as *u8) 2266 } 2267 } 2268 e1 = e1 + 1 2269 } 2270 if ndark > CW_EXPSHOW { 2271 cw_apps(page, pos, cap, " <span class='muted'>+" as *u8) 2272 cw_appn(page, pos, cap, ndark - CW_EXPSHOW) 2273 cw_apps(page, pos, cap, " more (cap " as *u8) 2274 cw_appn(page, pos, cap, CW_EXPSHOW) 2275 cw_apps(page, pos, cap, " declared)</span>" as *u8) 2276 } 2277 if ndark == 0 { cw_apps(page, pos, cap, "<span class='muted'>none -- every deployed elf has an MCP row</span>" as *u8) } 2278 cw_apps(page, pos, cap, "</p>\n" as *u8) 2279 if ndark > 0 { 2280 cw_fnd(fbuf, fpos, 5, "exposure" as *u8, 2281 "Deployed elfs without MCP allowlist rows exist (dark capabilities). Live list: https://nishifamily.com/code/exposure -- decide expose vs retire per capability." as *u8) 2282 } 2283 } 2284 2285 // promote-sprawl: deployed binaries whose name carries a "_new" or "_v<n>" 2286 // version suffix = the sites_new2..8 class. These are stale-promote hazards 2287 // (a restart could pick the wrong one) AND naming noise. Listed + FILED. 2288 var nsp: i64 = 0 2289 if nelf > 0 { 2290 cw_apps(page, pos, cap, "<h2>versioned deployed binaries <span class='cnt'>_new / _v&lt;n&gt; names -- stale-promote hazard + naming noise</span></h2>\n<p>" as *u8) 2291 var sp0: i64 = 0 2292 while sp0 < nelf { 2293 let snm: *u8 = ((earena as i64) + eoff[sp0]) as *u8 2294 var isspr: i64 = 0 2295 var cut: i64 = 0 - 1 2296 let vi1: i64 = cw_nameidx(snm, "_new" as *u8) 2297 if vi1 >= 0 { isspr = 1; cut = vi1 } 2298 if isspr == 0 { let vi2: i64 = cw_nameidx(snm, "_v2" as *u8); if vi2 >= 0 { isspr = 1; cut = vi2 } } 2299 if isspr == 0 { let vi3: i64 = cw_nameidx(snm, "_v3" as *u8); if vi3 >= 0 { isspr = 1; cut = vi3 } } 2300 // A versioned NAME is only a promote hazard when the BASE binary is 2301 // deployed too -- otherwise the version is the organ's identity. 2302 if isspr == 1 { if cw_has_base_sibling(earena, eoff, nelf, cut, snm) == 0 { isspr = 0 } } 2303 if isspr == 1 { 2304 nsp = nsp + 1 2305 if nsp <= CW_SPRAWLMAX { cw_apps(page, pos, cap, "<span class='pill'>" as *u8); cw_appe(page, pos, cap, snm, gl_len(snm)); cw_apps(page, pos, cap, "</span>" as *u8) } 2306 } 2307 sp0 = sp0 + 1 2308 } 2309 if nsp == 0 { cw_apps(page, pos, cap, "<span class='muted'>none</span>" as *u8) } 2310 if nsp > CW_SPRAWLMAX { cw_apps(page, pos, cap, " <span class='muted'>+more</span>" as *u8) } 2311 // CONTRACT ATTRIBUTE, not prose: the flagged COUNT, so a tooth can pin 2312 // an exact number. Absence-of-a-name is a broken discriminator here -- 2313 // the dark-capability list on this same page prints every elf basename, 2314 // so "solo_v2.elf is not on the page" can never be true. Same law the 2315 // taste-bound gauge learned: pin exact counts or data attributes. 2316 cw_apps(page, pos, cap, " <span class='cnt' data-sprawl='" as *u8) 2317 cw_appn(page, pos, cap, nsp) 2318 cw_apps(page, pos, cap, "'>" as *u8) 2319 cw_appn(page, pos, cap, nsp) 2320 cw_apps(page, pos, cap, " flagged (base binary also deployed)</span>" as *u8) 2321 cw_apps(page, pos, cap, "</p>\n" as *u8) 2322 if nsp > 1 { 2323 cw_fnd(fbuf, fpos, 5, "nishihost" as *u8, 2324 "Versioned deployed binaries (_new/_v<n> names) exist in the host dir = stale-promote hazard: a restart could pick the wrong one. https://nishifamily.com/code/exposure -- identify the live one, archive the rest (rule 13), adopt the .prev convention." as *u8) 2325 } 2326 } 2327 2328 // the local-only tail: tools in the tree with no deployed elf at all 2329 var nlocal: i64 = 0 2330 var t0: i64 = 0 2331 while t0 < nsorted { 2332 let tv: i64 = sidx[t0] 2333 if kindv[tv] == CW_K_TOOL { 2334 let tnm: *u8 = ((g.arena as i64) + g.node_off[tv]) as *u8 2335 let tsl: i64 = cw_stemlen(tnm) 2336 var dep: i64 = 0 2337 var e2: i64 = 0 2338 while e2 < nelf { 2339 let dnm2: *u8 = ((earena as i64) + eoff[e2]) as *u8 2340 if gl_len(dnm2) == tsl + 4 { 2341 var eq2: i64 = 1 2342 var c4: i64 = 0 2343 while c4 < tsl { if dnm2[c4] != tnm[c4] { eq2 = 0; c4 = tsl } else { c4 = c4 + 1 } } 2344 if eq2 == 1 { dep = 1 } 2345 } 2346 e2 = e2 + 1 2347 } 2348 if dep == 0 { nlocal = nlocal + 1 } 2349 } 2350 t0 = t0 + 1 2351 } 2352 cw_apps(page, pos, cap, "<p class='muted'>tools in the tree with no deployed elf here: " as *u8) 2353 cw_appn(page, pos, cap, nlocal) 2354 cw_apps(page, pos, cap, " -- the long tail; deploy+expose is a per-capability decision, and this number is its honest size.</p>\n" as *u8) 2355 2356 // ---- SHIPPED DRIFT: deployed binary OLDER than its own source ---- 2357 // The dominant sev-9 class made visible. For every deployed <stem>.elf whose 2358 // module we know, compare mtimes: elf older than source => a source change 2359 // that was never shipped. UNDER-reports by design (module source only, not 2360 // its import closure) -- it can miss drift, never invent it. 2361 cw_apps(page, pos, cap, "<h2>shipped drift <span class='cnt' data-drift='" as *u8) 2362 let dbuf2: *u8 = sys_mmap(CW_MAGIC_4096) 2363 let dpos2: *i64 = sys_mmap(32) as *i64 2364 dpos2[0] = 0 2365 dpos2[1] = 0 2366 var ndrift: i64 = 0 2367 var dchk: i64 = 0 2368 // closure scratch: epoch stamps + explicit stack, same pattern as the 2369 // impact section (no per-node memset; one allocation for the whole sweep) 2370 let dstamp: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2371 let dstack: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2372 var dz: i64 = 0 2373 while dz < CW_MAXNODE { dstamp[dz] = 0; dz = dz + 1 } 2374 var depoch: i64 = 0 2375 var d0: i64 = 0 2376 while d0 < nsorted { 2377 let dv: i64 = sidx[d0] 2378 let dnm3: *u8 = ((g.arena as i64) + g.node_off[dv]) as *u8 2379 let dsl: i64 = cw_stemlen(dnm3) 2380 var e3: i64 = 0 2381 while e3 < nelf { 2382 let enm3: *u8 = ((earena as i64) + eoff[e3]) as *u8 2383 if gl_len(enm3) == dsl + 4 { 2384 var eq3: i64 = 1 2385 var c5: i64 = 0 2386 while c5 < dsl { if enm3[c5] != dnm3[c5] { eq3 = 0; c5 = dsl } else { c5 = c5 + 1 } } 2387 if eq3 == 1 { 2388 let ep: *u8 = sys_mmap(CW_MAGIC_4096) 2389 var eo: i64 = 0 2390 var c7: i64 = 0 2391 while elfdir[c7] != (0 as u8) { ep[eo] = elfdir[c7]; eo = eo + 1; c7 = c7 + 1 } 2392 ep[eo] = 47 as u8 2393 eo = eo + 1 2394 var c6: i64 = 0 2395 while c6 < gl_len(enm3) { ep[eo] = enm3[c6]; eo = eo + 1; c6 = c6 + 1 } 2396 ep[eo] = 0 as u8 2397 let emt: i64 = cw_mtime(ep) 2398 depoch = depoch + 1 2399 let smt: i64 = cw_reach_maxmt(g, dv, dstamp, depoch, dstack, srcmt) 2400 if emt > 0 { if smt > 0 { 2401 dchk = dchk + 1 2402 if emt < smt { 2403 ndrift = ndrift + 1 2404 if ndrift <= CW_CATSHOW { 2405 cw_apps(dbuf2, dpos2, CW_MAGIC_4096, "<span class='pill'>" as *u8) 2406 cw_appe(dbuf2, dpos2, CW_MAGIC_4096, dnm3, dsl) 2407 cw_apps(dbuf2, dpos2, CW_MAGIC_4096, "</span>" as *u8) 2408 } 2409 } 2410 } } 2411 e3 = nelf 2412 } 2413 } 2414 e3 = e3 + 1 2415 } 2416 d0 = d0 + 1 2417 } 2418 cw_appn(page, pos, cap, ndrift) 2419 cw_apps(page, pos, cap, "'>" as *u8) 2420 cw_appn(page, pos, cap, ndrift) 2421 cw_apps(page, pos, cap, " of " as *u8) 2422 cw_appn(page, pos, cap, dchk) 2423 cw_apps(page, pos, cap, " comparable &middot; goal ZERO</span></h2>\n<p class='muted'>a deployed binary whose mtime is OLDER than its own source: <b>a fix that lives only in the tree is not shipped</b>. Whole sev-9 scopes are named for this class (<code>eaten-but-fix-not-in-any-tree</code>, <code>breaker-exists-in-source-NOT-in-running-supervisor</code>), and it was rediscovered five separate times by hand on 2026-07-30. compares the elf against the NEWEST source anywhere in the module's transitive IMPORT CLOSURE, not merely its own file: a binary is equally stale when a shared dependency changed and nobody rebuilt it, which is the common case since fixes usually land in a lib &mdash; and an mtime delta is a HYPOTHESIS about shipped state, so confirm with a reproduction before redeploying anything.</p>\n<p>" as *u8) 2424 if ndrift == 0 { cw_apps(page, pos, cap, "<span class='muted'>none detected</span>" as *u8) } else { cw_app(page, pos, cap, dbuf2, dpos2[0]) } 2425 if ndrift > CW_CATSHOW { cw_apps(page, pos, cap, " <span class='muted'>+" as *u8); cw_appn(page, pos, cap, ndrift - CW_CATSHOW); cw_apps(page, pos, cap, " more</span>" as *u8) } 2426 cw_apps(page, pos, cap, "</p>\n" as *u8) 2427 if ndrift > 0 { 2428 cw_fnd(fbuf, fpos, 6, "shipped-drift" as *u8, "Deployed binaries are OLDER than their own source: a fix that lives only in the tree is not shipped, and nothing else in the ecosystem answers that question -- it was rediscovered five separate times by hand in one day. Rebuild and redeploy each, or explain the divergence. Confirm with a REPRODUCTION first: an mtime delta is a hypothesis about shipped state, not proof. Standing gauge: https://nishifamily.com/code/exposure" as *u8) 2429 } 2430 2431 darkbox[0] = ndark 2432 return nexp 2433} 2434 2435// ---------- retrieval: ask the wiki, with citations ---------- 2436// 2437// Exact-token retrieval over askindex.tsv (DECLARED: this is lexical, not 2438// semantic -- a question sharing no token with the corpus returns NO-MATCH 2439// rather than the least-bad guess, because a confident wrong answer is worse 2440// than an honest miss). It is the GROUNDING half of chat: every hit carries 2441// its citation, so an answer can be checked without trusting the answerer. 2442 2443// TSV-safe append: tabs/newlines/control bytes become spaces so source text 2444// can never break the record format. 2445func cw_apptsv(buf: *u8, pos: *i64, cap: i64, s: *u8, n: i64) -> i64 { 2446 var i: i64 = 0 2447 while i < n { 2448 var c: i64 = s[i] as i64 2449 if c < 32 { c = 32 } 2450 if pos[0] + 1 >= cap - CW_PAGERESERVE { pos[1] = 1 } else { buf[pos[0]] = c as u8; pos[0] = pos[0] + 1 } 2451 i = i + 1 2452 } 2453 return 0 2454} 2455 2456func cw_lc(c: i64) -> i64 { 2457 if c >= 65 { if c <= 90 { return c + 32 } } 2458 return c 2459} 2460 2461// Case-insensitive match at a LEFT WORD BOUNDARY over hay[hs..he). 2462// 2463// ★The boundary is the whole point. Unbounded substring matching made a 2464// question about "which organ ..." rank nx_chem_m-ORGAN-_test first: the query 2465// word appeared inside an unrelated word. Requiring the match to begin at the 2466// start of a word (or after a non-identifier byte such as _ / . space) kills 2467// that class entirely, while still letting "func" match nx_dup_FUNC and "gate" 2468// match GATElib -- prefix-of-a-segment is real signal in an identifier corpus, 2469// suffix-of-a-word is noise. 2470func cw_hastok(hay: *u8, hs: i64, he: i64, tok: *u8, tl: i64) -> i64 { 2471 if tl <= 0 { return 0 } 2472 var i: i64 = hs 2473 while i + tl <= he { 2474 var lb: i64 = 1 2475 if i > hs { if gl_is_ident(cw_lc(hay[i - 1] as i64)) == 1 { lb = 0 } } 2476 if lb == 1 { 2477 var m: i64 = 0 2478 var ok: i64 = 1 2479 while m < tl { if cw_lc(hay[i + m] as i64) != (tok[m] as i64) { ok = 0; m = tl } else { m = m + 1 } } 2480 if ok == 1 { return 1 } 2481 } 2482 i = i + 1 2483 } 2484 return 0 2485} 2486 2487// field end: index of the next TAB (or line end) 2488func cw_fld(buf: *u8, s: i64, e: i64) -> i64 { 2489 var i: i64 = s 2490 var r: i64 = e 2491 var go: i64 = 1 2492 while go == 1 { 2493 if i >= e { go = 0 } else { 2494 if buf[i] == (9 as u8) { r = i; go = 0 } else { i = i + 1 } 2495 } 2496 } 2497 return r 2498} 2499 2500// tokenize a question (argv words) into lowercase tokens >= CW_ASKMINTOK. 2501// Shared by every ask front-end so one grammar cannot drift into two. 2502func cw_qtok(words: *i64, wn: i64, first: i64, toks: *u8, toff: *i64, tlen: *i64) -> i64 { 2503 var nt: i64 = 0 2504 var u: i64 = 0 2505 var w: i64 = first 2506 while w < wn { 2507 let s: *u8 = words[w] as *u8 2508 var i: i64 = 0 2509 var go: i64 = 1 2510 while go == 1 { 2511 let c: i64 = s[i] as i64 2512 if c == 0 { go = 0 } else { 2513 if gl_is_ident(c) == 1 { 2514 var e: i64 = i 2515 var g2: i64 = 1 2516 while g2 == 1 { if gl_is_ident(s[e] as i64) == 1 { e = e + 1 } else { g2 = 0 } } 2517 let l: i64 = e - i 2518 if l >= CW_ASKMINTOK { if nt < CW_ASKQTOK { if u + l + 1 < CW_MAGIC_1024 { 2519 toff[nt] = u 2520 tlen[nt] = l 2521 var k: i64 = 0 2522 while k < l { toks[u + k] = cw_lc(s[i + k] as i64) as u8; k = k + 1 } 2523 u = u + l 2524 nt = nt + 1 2525 } } } 2526 i = e 2527 } else { i = i + 1 } 2528 } 2529 } 2530 w = w + 1 2531 } 2532 return nt 2533} 2534 2535// ask: score every record against the question tokens, print the top hits 2536// WITH citations. Returns the number of hits shown (0 = honest NO-MATCH). 2537func cw_ask(idxpath: *u8, qtoks: *u8, qoff: *i64, qlen: *i64, nq: i64, urlbase: *u8, topname: *u8) -> i64 { 2538 let buf: *u8 = sys_mmap(CW_ASKCAP) 2539 let n: i64 = gl_read(idxpath, buf, CW_ASKCAP) 2540 let out: *u8 = sys_mmap(CW_MAGIC_65536) 2541 let opos: *i64 = sys_mmap(32) as *i64 2542 opos[0] = 0 2543 opos[1] = 0 2544 if n <= 0 { 2545 cw_apps(out, opos, CW_MAGIC_65536, "ASK-INDEX-MISSING: " as *u8) 2546 cw_apps(out, opos, CW_MAGIC_65536, idxpath) 2547 cw_apps(out, opos, CW_MAGIC_65536, " (run the generator first)\n" as *u8) 2548 sys_write(1, out, opos[0]) 2549 return 0 - 1 2550 } 2551 let bsc: *i64 = sys_mmap((CW_ASKTOP + 2) * 8) as *i64 2552 let bst: *i64 = sys_mmap((CW_ASKTOP + 2) * 8) as *i64 2553 let ben: *i64 = sys_mmap((CW_ASKTOP + 2) * 8) as *i64 2554 var nb: i64 = 0 2555 var scanned: i64 = 0 2556 // ★TIE ACCOUNTING (debt seq1328, measured 2026-07-30). A WIDE TIE AT A LOW SCORE IS NOT A RANKING. 2557 // The top-K below keeps the FIRST K records that clear score>0 and only displaces on STRICTLY 2558 // greater, so thousands of equally-scoring records render as ten alphabetical 'hits' and the tie is 2559 // invisible. A caller then cannot tell 'no such capability exists' from 'here are your top hits' -- 2560 // on the DISCOVERY path, which is the measured bottleneck. Count the tie so it can be declared. 2561 var best: i64 = 0 2562 var nbest: i64 = 0 2563 var nmatch: i64 = 0 2564 2565 // ---- pass A: document frequency per token -> rarity weight ---- 2566 let qdf: *i64 = sys_mmap(CW_ASKQTOK * 8) as *i64 2567 let qw: *i64 = sys_mmap(CW_ASKQTOK * 8) as *i64 2568 var z0: i64 = 0 2569 while z0 < nq { qdf[z0] = 0; z0 = z0 + 1 } 2570 var nrec: i64 = 0 2571 var pls: i64 = 0 2572 while pls < n { 2573 var ple: i64 = pls 2574 var pg: i64 = 1 2575 while pg == 1 { if ple >= n { pg = 0 } else { if buf[ple] == (10 as u8) { pg = 0 } else { ple = ple + 1 } } } 2576 if ple > pls + 2 { 2577 nrec = nrec + 1 2578 var pk: i64 = 0 2579 while pk < nq { 2580 let ptk: *u8 = ((qtoks as i64) + qoff[pk]) as *u8 2581 if cw_hastok(buf, pls, ple, ptk, qlen[pk]) == 1 { qdf[pk] = qdf[pk] + 1 } 2582 pk = pk + 1 2583 } 2584 } 2585 pls = ple + 1 2586 } 2587 var z1: i64 = 0 2588 while z1 < nq { 2589 var permil: i64 = 1000 2590 if nrec > 0 { permil = (qdf[z1] * 1000) / nrec } 2591 var w: i64 = CW_IDF_W5 2592 if permil <= CW_IDF_P4 { w = CW_IDF_W4 } 2593 if permil <= CW_IDF_P3 { w = CW_IDF_W3 } 2594 if permil <= CW_IDF_P2 { w = CW_IDF_W2 } 2595 if permil <= CW_IDF_P1 { w = CW_IDF_W1 } 2596 if qdf[z1] == 0 { w = 0 } 2597 qw[z1] = w 2598 z1 = z1 + 1 2599 } 2600 2601 // ---- pass B: score ---- 2602 var ls: i64 = 0 2603 while ls < n { 2604 var le: i64 = ls 2605 var g0: i64 = 1 2606 while g0 == 1 { if le >= n { g0 = 0 } else { if buf[le] == (10 as u8) { g0 = 0 } else { le = le + 1 } } } 2607 if le > ls + 2 { 2608 scanned = scanned + 1 2609 let isM: i64 = buf[ls] as i64 2610 // field 1 = name (both record kinds), field 2..: kind-specific 2611 let f1s: i64 = ls + 2 2612 let f1e: i64 = cw_fld(buf, f1s, le) 2613 var score: i64 = 0 2614 var k: i64 = 0 2615 while k < nq { 2616 let tk: *u8 = ((qtoks as i64) + qoff[k]) as *u8 2617 if cw_hastok(buf, f1s, f1e, tk, qlen[k]) == 1 { score = score + qw[k] * CW_ASKNAMEX } 2618 // module records: the description field is the last one 2619 if isM == 77 { 2620 // fields: name | dir | loc | funcs | desc -- walk to the END 2621 // of `funcs` (3 hops), then +1 is the START of desc. Walking 2622 // 4 hops lands on the line end and silently scores nothing. 2623 var ds: i64 = f1e 2624 var fc: i64 = 0 2625 while fc < 3 { ds = cw_fld(buf, ds + 1, le); fc = fc + 1 } 2626 ds = ds + 1 2627 // desc = field 5, searchable header doc = field 6 (to EOL). 2628 // A token counts ONCE even though desc is a prefix of doc. 2629 if ds < le { if cw_hastok(buf, ds, le, tk, qlen[k]) == 1 { score = score + qw[k] } } 2630 } 2631 // capability records: the title+grammar tail (fields 2..EOL) 2632 // carries the question's words ("verify a live page" names no 2633 // tool), so it scores like a module description does. 2634 if isM == 84 { 2635 let cts: i64 = f1e + 1 2636 if cts < le { if cw_hastok(buf, cts, le, tk, qlen[k]) == 1 { score = score + qw[k] } } 2637 } 2638 k = k + 1 2639 } 2640 if score > 0 { 2641 nmatch = nmatch + 1 2642 if score > best { best = score; nbest = 1 } else { if score == best { nbest = nbest + 1 } } 2643 var ins: i64 = 0 - 1 2644 if nb < CW_ASKTOP { ins = nb; bsc[nb] = score; bst[nb] = ls; ben[nb] = le; nb = nb + 1 } 2645 if ins < 0 { if score > bsc[CW_ASKTOP - 1] { ins = CW_ASKTOP - 1; bsc[ins] = score; bst[ins] = ls; ben[ins] = le } } 2646 var q2: i64 = ins 2647 while q2 > 0 { 2648 if bsc[q2 - 1] < bsc[q2] { 2649 let t1: i64 = bsc[q2-1]; bsc[q2-1] = bsc[q2]; bsc[q2] = t1 2650 let t2: i64 = bst[q2-1]; bst[q2-1] = bst[q2]; bst[q2] = t2 2651 let t3: i64 = ben[q2-1]; ben[q2-1] = ben[q2]; ben[q2] = t3 2652 q2 = q2 - 1 2653 } else { q2 = 0 } 2654 } 2655 } 2656 } 2657 ls = le + 1 2658 } 2659 cw_apps(out, opos, CW_MAGIC_65536, "=== ASK THE CODE WIKI (lexical retrieval; every hit cited) ===\nrecords scanned: " as *u8) 2660 cw_appn(out, opos, CW_MAGIC_65536, scanned) 2661 cw_apps(out, opos, CW_MAGIC_65536, " hits shown: " as *u8) 2662 cw_appn(out, opos, CW_MAGIC_65536, nb) 2663 cw_apps(out, opos, CW_MAGIC_65536, " (cap " as *u8) 2664 cw_appn(out, opos, CW_MAGIC_65536, CW_ASKTOP) 2665 cw_apps(out, opos, CW_MAGIC_65536, " DECLARED)\n" as *u8) 2666 // ★WHY THESE HITS (seq1328): per-token document frequency, so a caller can SEE whether the question 2667 // carried any discriminating word. A token in 0 records contributes nothing; a token in nearly every 2668 // record contributes nothing USEFUL. Hiding this is what let a uniform tie read as a ranking. 2669 cw_apps(out, opos, CW_MAGIC_65536, "token signal (df of " as *u8) 2670 cw_appn(out, opos, CW_MAGIC_65536, nrec) 2671 cw_apps(out, opos, CW_MAGIC_65536, " records):" as *u8) 2672 var zt: i64 = 0 2673 while zt < nq { 2674 cw_apps(out, opos, CW_MAGIC_65536, " " as *u8) 2675 cw_app(out, opos, CW_MAGIC_65536, ((qtoks as i64) + qoff[zt]) as *u8, qlen[zt]) 2676 cw_apps(out, opos, CW_MAGIC_65536, "=" as *u8) 2677 cw_appn(out, opos, CW_MAGIC_65536, qdf[zt]) 2678 zt = zt + 1 2679 } 2680 cw_apps(out, opos, CW_MAGIC_65536, "\nmatched: " as *u8) 2681 cw_appn(out, opos, CW_MAGIC_65536, nmatch) 2682 cw_apps(out, opos, CW_MAGIC_65536, " top score: " as *u8) 2683 cw_appn(out, opos, CW_MAGIC_65536, best) 2684 cw_apps(out, opos, CW_MAGIC_65536, " records tied at it: " as *u8) 2685 cw_appn(out, opos, CW_MAGIC_65536, nbest) 2686 cw_apps(out, opos, CW_MAGIC_65536, "\n" as *u8) 2687 // ★★THE REFUSAL. If more records tie at the top score than can be shown, the order below is INDEX 2688 // ORDER and nothing more. Say so in the caller's own terms rather than letting ten arbitrary rows 2689 // impersonate an answer. This LOOSENS NOTHING -- the hits are still printed, they are just no longer 2690 // allowed to pretend they were ranked. 2691 if nbest > CW_ASKTOP { 2692 cw_apps(out, opos, CW_MAGIC_65536, "AMBIGUOUS: the top score is a TIE WIDER THAN THE DISPLAY CAP, so the rows below are in INDEX ORDER, NOT RELEVANCE ORDER. The question carried no discriminating token (see df above). Treat this as NO USABLE ANSWER and re-ask with a rarer term.\n" as *u8) 2693 } 2694 if nb == 0 { 2695 cw_apps(out, opos, CW_MAGIC_65536, "NO-MATCH: no record shares a token with the question. Not guessing.\n" as *u8) 2696 sys_write(1, out, opos[0]) 2697 return 0 2698 } 2699 var r: i64 = 0 2700 while r < nb { 2701 let rs: i64 = bst[r] 2702 let re: i64 = ben[r] 2703 let kind: i64 = buf[rs] as i64 2704 let f1s: i64 = rs + 2 2705 let f1e: i64 = cw_fld(buf, f1s, re) 2706 // hand the top hit's name back to the caller (gates rank-check on it) 2707 if r == 0 { if (topname as i64) != 0 { 2708 var tc: i64 = 0 2709 while tc < f1e - f1s { if tc < 90 { topname[tc] = buf[f1s + tc]; tc = tc + 1 } else { tc = f1e - f1s } } 2710 var tl2: i64 = f1e - f1s 2711 if tl2 > 90 { tl2 = 90 } 2712 topname[tl2] = 0 as u8 2713 } } 2714 cw_apps(out, opos, CW_MAGIC_65536, "\n[" as *u8) 2715 cw_appn(out, opos, CW_MAGIC_65536, r + 1) 2716 cw_apps(out, opos, CW_MAGIC_65536, "] score=" as *u8) 2717 cw_appn(out, opos, CW_MAGIC_65536, bsc[r]) 2718 if kind == 77 { 2719 cw_apps(out, opos, CW_MAGIC_65536, " MODULE " as *u8) 2720 cw_app(out, opos, CW_MAGIC_65536, ((buf as i64) + f1s) as *u8, f1e - f1s) 2721 // dir, loc, funcs, desc 2722 let d2s: i64 = f1e + 1 2723 let d2e: i64 = cw_fld(buf, d2s, re) 2724 let l3s: i64 = d2e + 1 2725 let l3e: i64 = cw_fld(buf, l3s, re) 2726 let n4s: i64 = l3e + 1 2727 let n4e: i64 = cw_fld(buf, n4s, re) 2728 cw_apps(out, opos, CW_MAGIC_65536, " (" as *u8) 2729 cw_app(out, opos, CW_MAGIC_65536, ((buf as i64) + l3s) as *u8, l3e - l3s) 2730 cw_apps(out, opos, CW_MAGIC_65536, " lines, " as *u8) 2731 cw_app(out, opos, CW_MAGIC_65536, ((buf as i64) + n4s) as *u8, n4e - n4s) 2732 cw_apps(out, opos, CW_MAGIC_65536, " funcs)\n cite: " as *u8) 2733 cw_apps(out, opos, CW_MAGIC_65536, urlbase) 2734 cw_app(out, opos, CW_MAGIC_65536, ((buf as i64) + f1s) as *u8, f1e - f1s) 2735 cw_apps(out, opos, CW_MAGIC_65536, "\n " as *u8) 2736 // print the DESC field only (field 5) -- field 6 is the searchable 2737 // header text and is for scoring, not for reading. 2738 let d5s: i64 = n4e + 1 2739 let d5e: i64 = cw_fld(buf, d5s, re) 2740 var dshow: i64 = d5e - d5s 2741 if dshow > CW_ASKDESCMAX { dshow = CW_ASKDESCMAX } 2742 if dshow > 0 { cw_app(out, opos, CW_MAGIC_65536, ((buf as i64) + d5s) as *u8, dshow) } 2743 cw_apps(out, opos, CW_MAGIC_65536, "\n" as *u8) 2744 } else { if kind == 84 { 2745 // capability record: label it as one, cite the catalog anchor, 2746 // and show title + argv grammar (rung 23). 2747 cw_apps(out, opos, CW_MAGIC_65536, " CAPABILITY " as *u8) 2748 cw_app(out, opos, CW_MAGIC_65536, ((buf as i64) + f1s) as *u8, f1e - f1s) 2749 cw_apps(out, opos, CW_MAGIC_65536, "\n cite: " as *u8) 2750 cw_apps(out, opos, CW_MAGIC_65536, urlbase) 2751 cw_apps(out, opos, CW_MAGIC_65536, "tools#t_" as *u8) 2752 cw_app(out, opos, CW_MAGIC_65536, ((buf as i64) + f1s) as *u8, f1e - f1s) 2753 cw_apps(out, opos, CW_MAGIC_65536, "\n " as *u8) 2754 let c2s: i64 = f1e + 1 2755 let c2e: i64 = cw_fld(buf, c2s, re) 2756 var cshow: i64 = c2e - c2s 2757 if cshow > CW_ASKDESCMAX { cshow = CW_ASKDESCMAX } 2758 if cshow > 0 { cw_app(out, opos, CW_MAGIC_65536, ((buf as i64) + c2s) as *u8, cshow) } 2759 let c3s: i64 = c2e + 1 2760 if c3s < re { 2761 cw_apps(out, opos, CW_MAGIC_65536, " -- argv: " as *u8) 2762 let c3e: i64 = cw_fld(buf, c3s, re) 2763 cw_app(out, opos, CW_MAGIC_65536, ((buf as i64) + c3s) as *u8, c3e - c3s) 2764 } 2765 cw_apps(out, opos, CW_MAGIC_65536, "\n" as *u8) 2766 } else { 2767 cw_apps(out, opos, CW_MAGIC_65536, " FUNCTION " as *u8) 2768 cw_app(out, opos, CW_MAGIC_65536, ((buf as i64) + f1s) as *u8, f1e - f1s) 2769 let m2s: i64 = f1e + 1 2770 let m2e: i64 = cw_fld(buf, m2s, re) 2771 cw_apps(out, opos, CW_MAGIC_65536, " in " as *u8) 2772 cw_app(out, opos, CW_MAGIC_65536, ((buf as i64) + m2s) as *u8, m2e - m2s) 2773 cw_apps(out, opos, CW_MAGIC_65536, " line " as *u8) 2774 if m2e + 1 < re { cw_app(out, opos, CW_MAGIC_65536, ((buf as i64) + m2e + 1) as *u8, re - m2e - 1) } 2775 cw_apps(out, opos, CW_MAGIC_65536, "\n cite: " as *u8) 2776 cw_apps(out, opos, CW_MAGIC_65536, urlbase) 2777 cw_app(out, opos, CW_MAGIC_65536, ((buf as i64) + m2s) as *u8, m2e - m2s) 2778 cw_apps(out, opos, CW_MAGIC_65536, "#fn_" as *u8) 2779 cw_app(out, opos, CW_MAGIC_65536, ((buf as i64) + f1s) as *u8, f1e - f1s) 2780 cw_apps(out, opos, CW_MAGIC_65536, "\n" as *u8) 2781 } } 2782 r = r + 1 2783 } 2784 sys_write(1, out, opos[0]) 2785 return nb 2786} 2787 2788// ---------- the generator ---------- 2789// 2790// st[] result slots (DECLARED): 2791// 0 files 1 nodes 2 edges 3 funcs 4 structs 5 consts 2792// 6 unresolved-import targets 7 pages written 8 tree stamp 2793// 9 cycle(0=DAG) 10 dirs 11 truncated pages 2794// noext: 0 = hrefs carry .html (local file browsing), 1 = extensionless hrefs 2795// (the edge's canonical form). Disk filenames always carry .html. 2796// rc: 0 ok · 1 io-fail · 2 EMPTY ROOT (refused loudly -- a generator pointed 2797// at a wrong root must never report a green nothing; debt seq1107). 2798// allowpath/schemapath: the capability-join inputs (allowlist x schema 2799// registry). PARAMETERS, not CWD literals, so the gate's fixture runs are 2800// deterministic -- a prod conf leaking into a fixture corpus warps df 2801// ranking and the on-disk record counts (the rung-23 RED taught this). 2802func cw_generate2(root: *u8, outdir: *u8, noext: i64, st: *i64, allowpath: *u8, schemapath: *u8, atlaspath: *u8) -> i64 { 2803 sys_mkdir(outdir, 493) 2804 2805 let g: *EcoGraph = eg_new(CW_MAXNODE, CW_EDGECAP, CW_ARENA, CW_HASH) 2806 let patharena: *u8 = sys_mmap(CW_PATHARENA) 2807 let pathoff: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2808 let used: *i64 = sys_mmap(16) 2809 let wst: *i64 = sys_mmap(16) 2810 used[0] = 0 2811 wst[0] = 0 2812 var z: i64 = 0 2813 while z < CW_MAXNODE { pathoff[z] = 0; z = z + 1 } 2814 let path: *u8 = sys_mmap(CW_MAGIC_4096) 2815 var rn: i64 = 0 2816 while root[rn] != (0 as u8) { path[rn] = root[rn]; rn = rn + 1 } 2817 gl_walk(g, path, rn, 0 as *u8, 0 as *i64, 0 as *i64, wst, 0, patharena, pathoff, used, CW_PATHARENA) 2818 st[0] = wst[0] 2819 if st[0] == 0 { return 2 } 2820 2821 // per-node stores 2822 let fbytes: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2823 let floc: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2824 let catmask: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2825 let langv: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2826 let boundv: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2827 let subclv: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2828 let srcmt: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2829 let fnfn: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2830 let fdir: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2831 let doff: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2832 let dlen: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2833 let descarena: *u8 = sys_mmap(CW_DESCARENA) 2834 let dused: *i64 = sys_mmap(16) 2835 dused[0] = 0 2836 // searchable header-doc text (retrieval corpus, see CW_SDOCMAX) 2837 let sdocarena: *u8 = sys_mmap(CW_SDOCARENA) 2838 let sdoff: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2839 let sdlen: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2840 let sdused: *i64 = sys_mmap(16) 2841 sdused[0] = 0 2842 2843 // dir table 2844 let dirarena: *u8 = sys_mmap(CW_MAGIC_262144) 2845 let dirnoff: *i64 = sys_mmap(CW_MAXDIRS * 8) as *i64 2846 let dirslug: *i64 = sys_mmap(CW_MAXDIRS * 8) as *i64 2847 let dircnt: *i64 = sys_mmap(CW_MAXDIRS * 8) as *i64 2848 let dau: *i64 = sys_mmap(16) 2849 dau[0] = 0 2850 var ndirs: i64 = 0 2851 2852 let src: *u8 = sys_mmap(GL_FILECAP) 2853 let aoff: *i64 = sys_mmap(CW_MAGIC_1024 * 8) as *i64 2854 let alen: *i64 = sys_mmap(CW_MAGIC_1024 * 8) as *i64 2855 let seen: *i64 = sys_mmap(CW_IMPDEDUP * 8) as *i64 2856 let tbox: *i64 = sys_mmap(16) 2857 2858 var stamp: i64 = CW_MAGIC_1469598103934665603 2859 let nfilenodes: i64 = g.node_count 2860 2861 // name-sorted file-node index (see cw_sortnodes header) 2862 let sidx: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2863 let stmp: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 2864 var nsorted: i64 = 0 2865 var sv: i64 = 0 2866 while sv < nfilenodes { 2867 if pathoff[sv] > 0 { sidx[nsorted] = sv; nsorted = nsorted + 1 } 2868 sv = sv + 1 2869 } 2870 cw_sortnodes(g, sidx, stmp, nsorted) 2871 2872 // ===== pass 1: edges + stats + desc + dir + stamp ===== 2873 var s1i: i64 = 0 2874 while s1i < nsorted { 2875 let v: i64 = sidx[s1i] 2876 if pathoff[v] > 0 { 2877 let fp: *u8 = ((patharena as i64) + pathoff[v] - 1) as *u8 2878 // stamp: path bytes then size 2879 var pi: i64 = 0 2880 while fp[pi] != (0 as u8) { stamp = (stamp ^ (fp[pi] as i64)) * CW_MAGIC_1099511628211; pi = pi + 1 } 2881 let n: i64 = gl_read(fp, src, GL_FILECAP) 2882 stamp = (stamp ^ n) * CW_MAGIC_1099511628211 2883 fbytes[v] = n 2884 catmask[v] = cw_catscan(src, n) 2885 langv[v] = cw_langscan(src, n) 2886 boundv[v] = cw_boundscan(src, n) 2887 subclv[v] = cw_substrclass(src, n) 2888 srcmt[v] = cw_mtime(fp) 2889 var nl: i64 = 0 2890 var q: i64 = 0 2891 while q < n { if src[q] == (10 as u8) { nl = nl + 1 } q = q + 1 } 2892 floc[v] = nl 2893 2894 // imports -> basename-interned edges, deduped per file 2895 let ic: i64 = nis_scan(src, n, aoff, alen, CW_MAGIC_1024) 2896 var nseen: i64 = 0 2897 var k: i64 = 0 2898 while k < ic { 2899 let bs: i64 = cw_impbase(src, aoff[k], alen[k], tbox) 2900 let bl: i64 = tbox[0] 2901 let dep: i64 = eg_intern(g, ((src as i64) + bs) as *u8, bl) 2902 if dep >= 0 { if dep != v { 2903 var dup: i64 = 0 2904 var s2: i64 = 0 2905 while s2 < nseen { if seen[s2] == dep { dup = 1 } s2 = s2 + 1 } 2906 if dup == 0 { 2907 if nseen < CW_IMPDEDUP { seen[nseen] = dep; nseen = nseen + 1 } 2908 eg_add_edge(g, v, dep) 2909 } 2910 } } 2911 k = k + 1 2912 } 2913 2914 // desc: first line, text after "-- " (or after "// ") 2915 var e1: i64 = 0 2916 var g1: i64 = 1 2917 while g1 == 1 { if e1 >= n { g1 = 0 } else { if src[e1] == (10 as u8) { g1 = 0 } else { e1 = e1 + 1 } } } 2918 doff[v] = 0 2919 dlen[v] = 0 2920 if e1 > 2 { if src[0] == (47 as u8) { if src[1] == (47 as u8) { 2921 var ds: i64 = 0 - 1 2922 var p3: i64 = 2 2923 while p3 + 3 <= e1 { 2924 if ds < 0 { if src[p3] == (45 as u8) { if src[p3+1] == (45 as u8) { if src[p3+2] == (32 as u8) { ds = p3 + 3 } } } } 2925 p3 = p3 + 1 2926 } 2927 if ds < 0 { if e1 > 3 { ds = 3 } } 2928 if ds > 0 { if ds < e1 { 2929 var dl: i64 = e1 - ds 2930 if dl > CW_DESCMAX { dl = CW_DESCMAX } 2931 if dused[0] + dl + 1 < CW_DESCARENA { 2932 var c2: i64 = 0 2933 while c2 < dl { descarena[dused[0] + c2] = src[ds + c2]; c2 = c2 + 1 } 2934 doff[v] = dused[0] 2935 dlen[v] = dl 2936 dused[0] = dused[0] + dl 2937 } 2938 } } 2939 } } } 2940 2941 // searchable header text: the LEADING comment block, comment 2942 // markers stripped, control bytes flattened, capped + declared. 2943 sdoff[v] = sdused[0] 2944 sdlen[v] = 0 2945 var hls: i64 = 0 2946 var hgo: i64 = 1 2947 var hw: i64 = 0 2948 while hgo == 1 { 2949 if hls >= n { hgo = 0 } else { 2950 var hle: i64 = hls 2951 var hg2: i64 = 1 2952 while hg2 == 1 { if hle >= n { hg2 = 0 } else { if src[hle] == (10 as u8) { hg2 = 0 } else { hle = hle + 1 } } } 2953 var iscm: i64 = 0 2954 if hls + 1 < hle { if src[hls] == (47 as u8) { if src[hls + 1] == (47 as u8) { iscm = 1 } } } 2955 if iscm == 0 { hgo = 0 } else { 2956 var hc: i64 = hls + 2 2957 while hc < hle { 2958 if hw < CW_SDOCMAX { if sdused[0] + hw + 2 < CW_SDOCARENA { 2959 var ch: i64 = src[hc] as i64 2960 if ch < 32 { ch = 32 } 2961 if ch == 9 { ch = 32 } 2962 sdocarena[sdused[0] + hw] = ch as u8 2963 hw = hw + 1 2964 } } 2965 hc = hc + 1 2966 } 2967 if hw < CW_SDOCMAX { if sdused[0] + hw + 2 < CW_SDOCARENA { sdocarena[sdused[0] + hw] = 32 as u8; hw = hw + 1 } } 2968 hls = hle + 1 2969 if hw >= CW_SDOCMAX { hgo = 0 } 2970 } 2971 } 2972 } 2973 sdlen[v] = hw 2974 sdused[0] = sdused[0] + hw 2975 2976 // dir: relative dir of fp under root 2977 let bo: i64 = cw_base(fp) 2978 var rs: i64 = rn + 1 2979 if bo < rs { rs = bo } 2980 var dn2: i64 = bo - rs - 1 2981 if dn2 < 0 { dn2 = 0 } 2982 // find-or-add in dir table (linear; dirs are few) 2983 var di: i64 = 0 - 1 2984 var t2: i64 = 0 2985 while t2 < ndirs { 2986 if di < 0 { 2987 let off2: i64 = dirnoff[t2] 2988 var eq: i64 = 1 2989 var c3: i64 = 0 2990 while c3 < dn2 { if dirarena[off2 + c3] != fp[rs + c3] { eq = 0; c3 = dn2 } else { c3 = c3 + 1 } } 2991 if eq == 1 { if dirarena[off2 + dn2] == (0 as u8) { di = t2 } } 2992 } 2993 t2 = t2 + 1 2994 } 2995 if di < 0 { 2996 if ndirs < CW_MAXDIRS { 2997 di = ndirs 2998 dirnoff[di] = dau[0] 2999 var c4: i64 = 0 3000 while c4 < dn2 { dirarena[dau[0] + c4] = fp[rs + c4]; c4 = c4 + 1 } 3001 dirarena[dau[0] + dn2] = 0 as u8 3002 dau[0] = dau[0] + dn2 + 1 3003 // slug: "d_" + dir with '/'->'_' (empty dir -> "d_root") 3004 dirslug[di] = dau[0] 3005 dirarena[dau[0]] = 100 as u8 3006 dirarena[dau[0] + 1] = 95 as u8 3007 var sw: i64 = dau[0] + 2 3008 if dn2 == 0 { 3009 dirarena[sw] = 114 as u8; dirarena[sw+1] = 111 as u8; dirarena[sw+2] = 111 as u8; dirarena[sw+3] = 116 as u8 3010 sw = sw + 4 3011 } 3012 var c5: i64 = 0 3013 while c5 < dn2 { 3014 var ch: i64 = fp[rs + c5] as i64 3015 if ch == 47 { ch = 95 } 3016 if ch == 46 { ch = 95 } 3017 dirarena[sw] = ch as u8 3018 sw = sw + 1 3019 c5 = c5 + 1 3020 } 3021 dirarena[sw] = 0 as u8 3022 dau[0] = sw + 1 3023 dircnt[di] = 0 3024 ndirs = ndirs + 1 3025 } else { di = 0 } 3026 } 3027 fdir[v] = di 3028 dircnt[di] = dircnt[di] + 1 3029 } 3030 s1i = s1i + 1 3031 } 3032 3033 st[1] = g.node_count 3034 st[2] = g.edge_count 3035 st[8] = stamp & 0x7fffffffffffffff 3036 st[10] = ndirs 3037 eg_finalize(g) 3038 st[9] = eg_has_cycle(g) 3039 3040 var unres: i64 = 0 3041 var u0: i64 = 0 3042 while u0 < g.node_count { if pathoff[u0] == 0 { unres = unres + 1 } u0 = u0 + 1 } 3043 st[6] = unres 3044 3045 // transitive impact + DAG depth per file node (epoch-stamped, iterative) 3046 let stampv: *i64 = sys_mmap((g.node_count + 2) * 8) as *i64 3047 let rstack: *i64 = sys_mmap((g.node_count + 2) * 8) as *i64 3048 let tri_out: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 3049 let tri_in: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 3050 let depthv: *i64 = sys_mmap((g.node_count + 2) * 8) as *i64 3051 var z2a: i64 = 0 3052 while z2a < g.node_count { stampv[z2a] = 0; depthv[z2a] = 0 - 1; z2a = z2a + 1 } 3053 var epoch: i64 = 0 3054 var s1b: i64 = 0 3055 while s1b < nsorted { 3056 let vv: i64 = sidx[s1b] 3057 epoch = epoch + 1 3058 tri_out[vv] = cw_reach_count(g, vv, 0, stampv, epoch, rstack) 3059 epoch = epoch + 1 3060 tri_in[vv] = cw_reach_count(g, vv, 1, stampv, epoch, rstack) 3061 cw_depth_of(g, vv, depthv) 3062 s1b = s1b + 1 3063 } 3064 3065 // function index arenas (search): DECLARED caps CW_MAXFN / CW_FNARENA 3066 let fnarena: *u8 = sys_mmap(CW_FNARENA) 3067 let fnoff: *i64 = sys_mmap(CW_MAXFN * 8) as *i64 3068 let fnlen: *i64 = sys_mmap(CW_MAXFN * 8) as *i64 3069 let fnmod: *i64 = sys_mmap(CW_MAXFN * 8) as *i64 3070 let fnline: *i64 = sys_mmap(CW_MAXFN * 8) as *i64 3071 let fnu: *i64 = sys_mmap(16) 3072 fnu[0] = 0 3073 var nfns: i64 = 0 3074 3075 // ===== topic families (derived from name prefixes, threshold DECLARED) ===== 3076 let famarena: *u8 = sys_mmap(CW_FAMARENA) 3077 let famoff: *i64 = sys_mmap(CW_MAXFAM * 8) as *i64 3078 let famlen: *i64 = sys_mmap(CW_MAXFAM * 8) as *i64 3079 let famcnt: *i64 = sys_mmap(CW_MAXFAM * 8) as *i64 3080 let modfam: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 3081 var famu: i64 = 0 3082 var nfam: i64 = 0 3083 let fkey: *u8 = sys_mmap(32) 3084 var sf0: i64 = 0 3085 while sf0 < nsorted { 3086 let fv: i64 = sidx[sf0] 3087 let fnm2: *u8 = ((g.arena as i64) + g.node_off[fv]) as *u8 3088 let fkl: i64 = cw_famkey(fnm2, fkey) 3089 var fidx: i64 = 0 - 1 3090 var ff0: i64 = 0 3091 while ff0 < nfam { 3092 if fidx < 0 { if famlen[ff0] == fkl { 3093 var feq: i64 = 1 3094 var fc0: i64 = 0 3095 while fc0 < fkl { if famarena[famoff[ff0] + fc0] != fkey[fc0] { feq = 0; fc0 = fkl } else { fc0 = fc0 + 1 } } 3096 if feq == 1 { fidx = ff0 } 3097 } } 3098 ff0 = ff0 + 1 3099 } 3100 if fidx < 0 { if fkl > 0 { if nfam < CW_MAXFAM { if famu + fkl + 1 < CW_FAMARENA { 3101 fidx = nfam 3102 famoff[fidx] = famu 3103 famlen[fidx] = fkl 3104 famcnt[fidx] = 0 3105 var fc1: i64 = 0 3106 while fc1 < fkl { famarena[famu + fc1] = fkey[fc1]; fc1 = fc1 + 1 } 3107 famarena[famu + fkl] = 0 as u8 3108 famu = famu + fkl + 1 3109 nfam = nfam + 1 3110 } } } } 3111 if fidx >= 0 { modfam[fv] = fidx; famcnt[fidx] = famcnt[fidx] + 1 } else { modfam[fv] = 0 - 1 } 3112 sf0 = sf0 + 1 3113 } 3114 // rank families by TOTAL LOC, not member count: a 2000-stub test corpus 3115 // must not outrank a 78-module subsystem (measured curation, no name lists) 3116 let famloc: *i64 = sys_mmap(CW_MAXFAM * 8) as *i64 3117 var fl0: i64 = 0 3118 while fl0 < nfam { famloc[fl0] = 0; fl0 = fl0 + 1 } 3119 var fl1: i64 = 0 3120 while fl1 < nsorted { 3121 let flv: i64 = sidx[fl1] 3122 if modfam[flv] >= 0 { famloc[modfam[flv]] = famloc[modfam[flv]] + floc[flv] } 3123 fl1 = fl1 + 1 3124 } 3125 var nfamE: i64 = 0 3126 var fe0: i64 = 0 3127 while fe0 < nfam { if famcnt[fe0] >= CW_FAMMIN { nfamE = nfamE + 1 } fe0 = fe0 + 1 } 3128 st[15] = nfamE + 1 3129 3130 // ===== the shared sidebar (built once, appended to every page) ===== 3131 let sbbuf: *u8 = sys_mmap(CW_MAGIC_65536) 3132 let sbpos: *i64 = sys_mmap(32) as *i64 3133 sbpos[0] = 0 3134 sbpos[1] = 0 3135 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "<nav class='sb'><span class='brand'>&#9670; nishi code wiki</span>\n<a class='it' href='index" as *u8) 3136 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3137 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>Overview</a>\n<a class='it' href='search" as *u8) 3138 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3139 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#128269; Search</a>\n<a class='it' href='ask" as *u8) 3140 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3141 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#128172; Ask (local AI)</a>\n<a class='it' href='lang" as *u8) 3142 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3143 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#128220; Language</a>\n<a class='it' href='tools" as *u8) 3144 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3145 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#128295; Tools (capabilities)</a>\n<a class='it' href='pulse" as *u8) 3146 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3147 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#128200; Pulse (shift gauges)</a>\n<a class='it' href='arch" as *u8) 3148 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3149 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#127959; Architecture</a>\n<a class='it' href='kinds" as *u8) 3150 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3151 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#128203; Inventory</a>\n<a class='it' href='exposure" as *u8) 3152 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3153 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#128268; Exposure (MCP/API)</a>\n<a class='it' href='findings" as *u8) 3154 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3155 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#9888; Findings (backlog)</a>\n<a class='it' href='debt" as *u8) 3156 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3157 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#128296; Debt taxonomy</a>\n<a class='it' href='families" as *u8) 3158 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3159 // Work families -- GENERATED BY nx_debtcluster, not by this tool. Linked here for exactly the reason 3160 // given for the SOTA rung plan below: a page the nav does not mention is unreachable. It groups the 3161 // debt ledger's rows into families that share an anchor, ranks them by max_sev x open, and publishes 3162 // its own measured B-cubed precision/recall so the page states its own accuracy. 3163 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#129513; Work families</a>\n<a class='it' href='sovereignty" as *u8) 3164 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3165 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#127963; Sovereignty ladder</a>\n<a class='it' href='sotaplan" as *u8) 3166 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3167 // SOTA rung plan. HAND-AUTHORED page, not generated by this tool -- linked here because a page the 3168 // nav does not mention is unreachable, and DISCOVERABILITY IS THE CAPABILITY: a document nobody can 3169 // find has the same value as one nobody wrote, and costs more. The generator must therefore know 3170 // about the non-generated pages it sits beside, or publishing one silently produces nothing. 3171 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#129517; SOTA rung plan</a>\n<a class='it' href='sota" as *u8) 3172 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3173 // SOTA by generation + Research briefs. HAND-AUTHORED pages, same class as the SOTA rung plan above 3174 // and linked for the same reason: a page the nav does not mention is unreachable. sota scores each 3175 // family-tree generation on its own bar and carries the 7-cluster work order; research is the briefs 3176 // library whose entries declare a Forks-off lineage so future research forks off it. 3177 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#127795; SOTA by generation</a>\n<a class='it' href='research" as *u8) 3178 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3179 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#128218; Research briefs</a>\n<a class='it' href='atlas" as *u8) 3180 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3181 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>&#128506; Atlas (domains)</a>\n<div class='sec'>topics</div>\n" as *u8) 3182 // top families by member count (threshold + cap declared on the topics page) 3183 let sbf: *i64 = sys_mmap((CW_SBFAM + 2) * 8) as *i64 3184 var nsbf: i64 = 0 3185 var tf0: i64 = 0 3186 while tf0 < CW_SBFAM { 3187 var tbest: i64 = 0 - 1 3188 var tf1: i64 = 0 3189 while tf1 < nfam { 3190 var ttk: i64 = 0 3191 var tf2: i64 = 0 3192 while tf2 < nsbf { if sbf[tf2] == tf1 { ttk = 1 } tf2 = tf2 + 1 } 3193 if ttk == 0 { if famcnt[tf1] >= CW_FAMMIN { if tbest < 0 { tbest = tf1 } else { if famloc[tf1] > famloc[tbest] { tbest = tf1 } } } } 3194 tf1 = tf1 + 1 3195 } 3196 if tbest >= 0 { 3197 sbf[nsbf] = tbest 3198 nsbf = nsbf + 1 3199 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "<a class='it' href='t_" as *u8) 3200 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, ((famarena as i64) + famoff[tbest]) as *u8) 3201 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3202 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>" as *u8) 3203 cw_appe(sbbuf, sbpos, CW_MAGIC_65536, ((famarena as i64) + famoff[tbest]) as *u8, famlen[tbest]) 3204 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "<span class='ct'>" as *u8) 3205 cw_appn(sbbuf, sbpos, CW_MAGIC_65536, famcnt[tbest]) 3206 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "</span></a>\n" as *u8) 3207 } 3208 tf0 = tf0 + 1 3209 } 3210 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "<a class='it' href='topics" as *u8) 3211 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3212 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>all topics &#8594;</a>\n<div class='sec'>directories</div>\n" as *u8) 3213 var sb0: i64 = 0 3214 while sb0 < ndirs { 3215 let sdl: *u8 = ((dirarena as i64) + dirnoff[sb0]) as *u8 3216 let sds: *u8 = ((dirarena as i64) + dirslug[sb0]) as *u8 3217 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "<a class='it' href='" as *u8) 3218 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, sds) 3219 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3220 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'>" as *u8) 3221 if cw_slen(sdl) == 0 { cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "(root)" as *u8) } else { cw_appe(sbbuf, sbpos, CW_MAGIC_65536, sdl, cw_slen(sdl)) } 3222 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "<span class='ct'>" as *u8) 3223 cw_appn(sbbuf, sbpos, CW_MAGIC_65536, dircnt[sb0]) 3224 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "</span></a>\n" as *u8) 3225 sb0 = sb0 + 1 3226 } 3227 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "<div class='sec'>load-bearing</div>\n" as *u8) 3228 // top 8 by fan-in, bounded selection 3229 let sbk: *i64 = sys_mmap(16 * 8) as *i64 3230 var nsb: i64 = 0 3231 var sb1: i64 = 0 3232 while sb1 < nsorted { 3233 if nsb < 8 { 3234 var bb: i64 = 0 - 1 3235 var sb2: i64 = 0 3236 while sb2 < nsorted { 3237 let cnd3: i64 = sidx[sb2] 3238 var tk: i64 = 0 3239 var t3: i64 = 0 3240 while t3 < nsb { if sbk[t3] == cnd3 { tk = 1 } t3 = t3 + 1 } 3241 if tk == 0 { if bb < 0 { bb = cnd3 } else { if g.ca_arr[cnd3] > g.ca_arr[bb] { bb = cnd3 } } } 3242 sb2 = sb2 + 1 3243 } 3244 if bb >= 0 { if g.ca_arr[bb] > 0 { 3245 sbk[nsb] = bb 3246 nsb = nsb + 1 3247 let bnm2: *u8 = ((g.arena as i64) + g.node_off[bb]) as *u8 3248 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "<a class='it' href='" as *u8) 3249 cw_appstem(sbbuf, sbpos, CW_MAGIC_65536, bnm2) 3250 cw_appext(sbbuf, sbpos, CW_MAGIC_65536, noext) 3251 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "'><code>" as *u8) 3252 var bl2: i64 = cw_stemlen(bnm2) 3253 if bl2 > 24 { bl2 = 24 } 3254 cw_appe(sbbuf, sbpos, CW_MAGIC_65536, bnm2, bl2) 3255 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "</code></a>\n" as *u8) 3256 } } 3257 } 3258 sb1 = sb1 + 1 3259 } 3260 cw_apps(sbbuf, sbpos, CW_MAGIC_65536, "</nav>\n" as *u8) 3261 sbbuf[sbpos[0]] = 0 as u8 3262 3263 // ===== pass 1.5: THE CALL GRAPH ===== 3264 // One extra read per file: comment-strip, collect defs + unresolved call 3265 // sites (cwc_scan), then resolve in memory. Resolution order: same module 3266 // -> a DIRECT import -> globally unique name; anything else is COUNTED as 3267 // ambiguous/unknown, never guessed (the honest-number rule). 3268 let dnames: *u8 = sys_mmap(CW_FNARENA) 3269 let dnoff: *i64 = sys_mmap(CW_MAXFN * 8) as *i64 3270 let dnlen: *i64 = sys_mmap(CW_MAXFN * 8) as *i64 3271 let dmod: *i64 = sys_mmap(CW_MAXFN * 8) as *i64 3272 let dline: *i64 = sys_mmap(CW_MAXFN * 8) as *i64 3273 let dhead: *i64 = sys_mmap(CW_DEFHASH * 8) as *i64 3274 let dnext: *i64 = sys_mmap(CW_MAXFN * 8) as *i64 3275 let dnbox: *i64 = sys_mmap(16) 3276 let dubox: *i64 = sys_mmap(16) 3277 dnbox[0] = 0 3278 dubox[0] = 0 3279 var zc0: i64 = 0 3280 while zc0 < CW_DEFHASH { dhead[zc0] = 0; zc0 = zc0 + 1 } 3281 let snames: *u8 = sys_mmap(CW_SITEARENA) 3282 let snoff: *i64 = sys_mmap(CW_MAXSITE * 8) as *i64 3283 let snlen: *i64 = sys_mmap(CW_MAXSITE * 8) as *i64 3284 let smod: *i64 = sys_mmap(CW_MAXSITE * 8) as *i64 3285 let scaller: *i64 = sys_mmap(CW_MAXSITE * 8) as *i64 3286 let nsbox: *i64 = sys_mmap(16) 3287 let subox: *i64 = sys_mmap(16) 3288 nsbox[0] = 0 3289 subox[0] = 0 3290 let stripbuf: *u8 = sys_mmap(GL_FILECAP) 3291 let mdefh: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 3292 let mdefc: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 3293 var s15: i64 = 0 3294 while s15 < nsorted { 3295 let vc: i64 = sidx[s15] 3296 let fpc: *u8 = ((patharena as i64) + pathoff[vc] - 1) as *u8 3297 let nc: i64 = gl_read(fpc, src, GL_FILECAP) 3298 let sn2: i64 = gl_strip_comments(src, nc, stripbuf) 3299 mdefh[vc] = dnbox[0] 3300 cwc_scan(stripbuf, sn2, vc, dnames, dnoff, dnlen, dmod, dline, dhead, dnext, dnbox, dubox, 3301 snames, snoff, snlen, smod, scaller, nsbox, subox) 3302 mdefc[vc] = dnbox[0] - mdefh[vc] 3303 s15 = s15 + 1 3304 } 3305 let ndefs: i64 = dnbox[0] 3306 let nsites: i64 = nsbox[0] 3307 3308 // resolve sites -> def-level edges (deduped per caller within a window) 3309 let cesrc: *i64 = sys_mmap(CW_MAXSITE * 8) as *i64 3310 let cedst: *i64 = sys_mmap(CW_MAXSITE * 8) as *i64 3311 var ncedge: i64 = 0 3312 var namb: i64 = 0 3313 var nunk: i64 = 0 3314 let dwin: *i64 = sys_mmap(CW_CALLDEDUP * 8) as *i64 3315 var ndwin: i64 = 0 3316 var lastcaller: i64 = 0 - 2 3317 var k5: i64 = 0 3318 while k5 < nsites { 3319 let snm2: *u8 = ((snames as i64) + snoff[k5]) as *u8 3320 let snl2: i64 = snlen[k5] 3321 var inmod: i64 = 0 - 1 3322 var inimp: i64 = 0 - 1 3323 var glob: i64 = 0 - 1 3324 var gcount: i64 = 0 3325 var cur: i64 = dhead[cwc_hash(snm2, snl2)] 3326 while cur != 0 { 3327 let di: i64 = cur - 1 3328 if dnlen[di] == snl2 { 3329 var eq2: i64 = 1 3330 var cb: i64 = 0 3331 while cb < snl2 { if dnames[dnoff[di] + cb] != snm2[cb] { eq2 = 0; cb = snl2 } else { cb = cb + 1 } } 3332 if eq2 == 1 { 3333 gcount = gcount + 1 3334 glob = di 3335 if dmod[di] == smod[k5] { inmod = di } else { 3336 if inimp < 0 { 3337 var p7: i64 = g.out_head[smod[k5]] 3338 let e7: i64 = g.out_head[smod[k5] + 1] 3339 while p7 < e7 { if g.out_list[p7] == dmod[di] { inimp = di; p7 = e7 } else { p7 = p7 + 1 } } 3340 } 3341 } 3342 } 3343 } 3344 cur = dnext[di] 3345 } 3346 var pick: i64 = inmod 3347 if pick < 0 { pick = inimp } 3348 if pick < 0 { if gcount == 1 { pick = glob } } 3349 if pick < 0 { 3350 if gcount > 1 { namb = namb + 1 } else { nunk = nunk + 1 } 3351 } else { 3352 if scaller[k5] != lastcaller { ndwin = 0; lastcaller = scaller[k5] } 3353 var dup2: i64 = 0 3354 var w5: i64 = 0 3355 while w5 < ndwin { if dwin[w5] == pick { dup2 = 1 } w5 = w5 + 1 } 3356 if dup2 == 0 { 3357 if ndwin < CW_CALLDEDUP { dwin[ndwin] = pick; ndwin = ndwin + 1 } 3358 if ncedge < CW_MAXSITE { 3359 cesrc[ncedge] = scaller[k5] 3360 cedst[ncedge] = pick 3361 ncedge = ncedge + 1 3362 } 3363 } 3364 } 3365 k5 = k5 + 1 3366 } 3367 3368 // def-level CSR both directions (the eg_finalize pattern) 3369 let cf_oh: *i64 = sys_mmap((ndefs + 2) * 8) as *i64 3370 let cf_ih: *i64 = sys_mmap((ndefs + 2) * 8) as *i64 3371 let cf_oc: *i64 = sys_mmap((ndefs + 2) * 8) as *i64 3372 let cf_ic: *i64 = sys_mmap((ndefs + 2) * 8) as *i64 3373 let cf_ol: *i64 = sys_mmap((ncedge + 1) * 8) as *i64 3374 let cf_il: *i64 = sys_mmap((ncedge + 1) * 8) as *i64 3375 var z6: i64 = 0 3376 while z6 <= ndefs { cf_oc[z6] = 0; cf_ic[z6] = 0; z6 = z6 + 1 } 3377 var z7: i64 = 0 3378 while z7 < ncedge { cf_oc[cesrc[z7]] = cf_oc[cesrc[z7]] + 1; cf_ic[cedst[z7]] = cf_ic[cedst[z7]] + 1; z7 = z7 + 1 } 3379 cf_oh[0] = 0 3380 cf_ih[0] = 0 3381 var z8: i64 = 0 3382 while z8 < ndefs { cf_oh[z8 + 1] = cf_oh[z8] + cf_oc[z8]; cf_ih[z8 + 1] = cf_ih[z8] + cf_ic[z8]; z8 = z8 + 1 } 3383 let cur_o2: *i64 = sys_mmap((ndefs + 2) * 8) as *i64 3384 let cur_i2: *i64 = sys_mmap((ndefs + 2) * 8) as *i64 3385 var z9: i64 = 0 3386 while z9 < ndefs { cur_o2[z9] = cf_oh[z9]; cur_i2[z9] = cf_ih[z9]; z9 = z9 + 1 } 3387 var za: i64 = 0 3388 while za < ncedge { 3389 cf_ol[cur_o2[cesrc[za]]] = cedst[za] 3390 cur_o2[cesrc[za]] = cur_o2[cesrc[za]] + 1 3391 cf_il[cur_i2[cedst[za]]] = cesrc[za] 3392 cur_i2[cedst[za]] = cur_i2[cedst[za]] + 1 3393 za = za + 1 3394 } 3395 st[12] = ndefs 3396 st[13] = ncedge 3397 st[14] = namb + nunk 3398 3399 // ===== module KINDS: what each file IS, by measured rule ===== 3400 let hasmain: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 3401 var hm0: i64 = 0 3402 while hm0 < nsorted { hasmain[sidx[hm0]] = 0; hm0 = hm0 + 1 } 3403 var hm1: i64 = 0 3404 while hm1 < ndefs { 3405 if dnlen[hm1] == 4 { 3406 if dnames[dnoff[hm1]] == (109 as u8) { if dnames[dnoff[hm1]+1] == (97 as u8) { if dnames[dnoff[hm1]+2] == (105 as u8) { if dnames[dnoff[hm1]+3] == (110 as u8) { 3407 hasmain[dmod[hm1]] = 1 3408 } } } } 3409 } 3410 hm1 = hm1 + 1 3411 } 3412 let kindv: *i64 = sys_mmap(CW_MAXNODE * 8) as *i64 3413 let kindcnt: *i64 = sys_mmap(CW_NKIND * 8) as *i64 3414 let kindloc: *i64 = sys_mmap(CW_NKIND * 8) as *i64 3415 var kz: i64 = 0 3416 while kz < CW_NKIND { kindcnt[kz] = 0; kindloc[kz] = 0; kz = kz + 1 } 3417 var kk: i64 = 0 3418 while kk < nsorted { 3419 let kv: i64 = sidx[kk] 3420 let knm: *u8 = ((g.arena as i64) + g.node_off[kv]) as *u8 3421 let kdl: *u8 = ((dirarena as i64) + dirnoff[fdir[kv]]) as *u8 3422 var kind: i64 = 0 - 1 3423 // 1. archived: lives in a _retired* / _attic dir 3424 if cw_namehas(kdl, "_retired" as *u8) == 1 { kind = CW_K_ARCHIVED } 3425 if kind < 0 { if cw_namehas(kdl, "_attic" as *u8) == 1 { kind = CW_K_ARCHIVED } } 3426 // 2. gate/proof (both live conventions, per nx_gatelib) 3427 if kind < 0 { if gl_is_gate_name(knm, cw_slen(knm)) == 1 { kind = CW_K_GATE } } 3428 // 3-6. bench / probe / smoke / sketch-demo, by naming convention 3429 if kind < 0 { if cw_namehas(knm, "bench" as *u8) == 1 { kind = CW_K_BENCH } } 3430 if kind < 0 { if cw_namehas(knm, "_probe" as *u8) == 1 { kind = CW_K_PROBE } } 3431 if kind < 0 { if cw_namehas(knm, "smoke" as *u8) == 1 { kind = CW_K_SMOKE } } 3432 if kind < 0 { if cw_namehas(knm, "_demo" as *u8) == 1 { kind = CW_K_SKETCH } } 3433 if kind < 0 { if cw_namehas(knm, "sketch_" as *u8) == 1 { kind = CW_K_SKETCH } } 3434 // 7. generated fixture: says so in its own header, or family-scale + tiny 3435 if kind < 0 { if dlen[kv] > 0 { 3436 if cw_hastok(descarena, doff[kv], doff[kv] + dlen[kv], "auto-generated" as *u8, 14) == 1 { kind = CW_K_GENFIX } 3437 } } 3438 if kind < 0 { if modfam[kv] >= 0 { if famcnt[modfam[kv]] >= CW_GENFIX_FAM { if floc[kv] < CW_GENFIX_LOC { kind = CW_K_GENFIX } } } } 3439 // 8. service: owns main and carries a serving suffix 3440 if kind < 0 { if hasmain[kv] == 1 { 3441 if gl_ends(knm, cw_slen(knm), "_daemon.nx" as *u8) == 1 { kind = CW_K_SERVICE } 3442 if kind < 0 { if gl_ends(knm, cw_slen(knm), "_serve.nx" as *u8) == 1 { kind = CW_K_SERVICE } } 3443 if kind < 0 { if gl_ends(knm, cw_slen(knm), "_server.nx" as *u8) == 1 { kind = CW_K_SERVICE } } 3444 if kind < 0 { if gl_ends(knm, cw_slen(knm), "_gw.nx" as *u8) == 1 { kind = CW_K_SERVICE } } 3445 if kind < 0 { if gl_ends(knm, cw_slen(knm), "_api.nx" as *u8) == 1 { kind = CW_K_SERVICE } } 3446 } } 3447 // 9-11. tool (owns main) / library (imported) / orphan library 3448 if kind < 0 { if hasmain[kv] == 1 { kind = CW_K_TOOL } } 3449 if kind < 0 { if g.ca_arr[kv] > 0 { kind = CW_K_LIB } } 3450 if kind < 0 { kind = CW_K_ORPHAN } 3451 kindv[kv] = kind 3452 kindcnt[kind] = kindcnt[kind] + 1 3453 kindloc[kind] = kindloc[kind] + floc[kv] 3454 kk = kk + 1 3455 } 3456 st[18] = kindcnt[CW_K_ORPHAN] 3457 3458 // ===== pass 2: emit one page per file node ===== 3459 let page: *u8 = sys_mmap(CW_PAGECAP) 3460 let pos: *i64 = sys_mmap(32) as *i64 3461 let opath: *u8 = sys_mmap(CW_MAGIC_4096) 3462 var tfuncs: i64 = 0 3463 var tstructs: i64 = 0 3464 var tconsts: i64 = 0 3465 var pages: i64 = 0 3466 var truncs: i64 = 0 3467 3468 var s2i: i64 = 0 3469 while s2i < nsorted { 3470 let v2: i64 = sidx[s2i] 3471 if pathoff[v2] > 0 { 3472 let fp2: *u8 = ((patharena as i64) + pathoff[v2] - 1) as *u8 3473 let nm: *u8 = ((g.arena as i64) + g.node_off[v2]) as *u8 3474 let n2: i64 = gl_read(fp2, src, GL_FILECAP) 3475 pos[0] = 0 3476 pos[1] = 0 3477 cw_head3(page, pos, CW_PAGECAP, nm, cw_slen(nm), sbbuf) 3478 let dslug: *u8 = ((dirarena as i64) + dirslug[fdir[v2]]) as *u8 3479 let dlab2: *u8 = ((dirarena as i64) + dirnoff[fdir[v2]]) as *u8 3480 cw_crumb(page, pos, CW_PAGECAP, noext, dlab2, dslug, nm, cw_slen(nm)) 3481 cw_apps(page, pos, CW_PAGECAP, "<h1>" as *u8) 3482 cw_appe(page, pos, CW_PAGECAP, nm, cw_slen(nm)) 3483 cw_apps(page, pos, CW_PAGECAP, "</h1>\n<p class='muted'><code>" as *u8) 3484 cw_appe(page, pos, CW_PAGECAP, fp2, cw_slen(fp2)) 3485 cw_apps(page, pos, CW_PAGECAP, "</code></p>\n<div class='meta'><span class='chip'><b>" as *u8) 3486 cw_appn(page, pos, CW_PAGECAP, fbytes[v2]) 3487 cw_apps(page, pos, CW_PAGECAP, "</b> B</span><span class='chip'><b>" as *u8) 3488 cw_appn(page, pos, CW_PAGECAP, floc[v2]) 3489 cw_apps(page, pos, CW_PAGECAP, "</b> lines</span><span class='chip'>depth <b>" as *u8) 3490 cw_appn(page, pos, CW_PAGECAP, depthv[v2]) 3491 cw_apps(page, pos, CW_PAGECAP, "</b></span><span class='chip'>pulls <b>" as *u8) 3492 cw_appn(page, pos, CW_PAGECAP, tri_out[v2]) 3493 cw_apps(page, pos, CW_PAGECAP, "</b> transitive</span><span class='chip'>reach <b>" as *u8) 3494 cw_appn(page, pos, CW_PAGECAP, tri_in[v2]) 3495 cw_apps(page, pos, CW_PAGECAP, "</b> importers</span><span class='chip'><a href='src_" as *u8) 3496 cw_app(page, pos, CW_PAGECAP, nm, cw_stemlen(nm)) 3497 cw_appext(page, pos, CW_PAGECAP, noext) 3498 cw_apps(page, pos, CW_PAGECAP, "#L1'>view source</a></span><span class='chip'>kind <a href='kinds" as *u8) 3499 cw_appext(page, pos, CW_PAGECAP, noext) 3500 cw_apps(page, pos, CW_PAGECAP, "'><b>" as *u8) 3501 cw_apps(page, pos, CW_PAGECAP, cw_kindname(kindv[v2])) 3502 cw_apps(page, pos, CW_PAGECAP, "</b></a></span>" as *u8) 3503 if modfam[v2] >= 0 { if famcnt[modfam[v2]] >= CW_FAMMIN { 3504 cw_apps(page, pos, CW_PAGECAP, "<span class='chip'>topic <a href='t_" as *u8) 3505 cw_apps(page, pos, CW_PAGECAP, ((famarena as i64) + famoff[modfam[v2]]) as *u8) 3506 cw_appext(page, pos, CW_PAGECAP, noext) 3507 cw_apps(page, pos, CW_PAGECAP, "'><b>" as *u8) 3508 cw_appe(page, pos, CW_PAGECAP, ((famarena as i64) + famoff[modfam[v2]]) as *u8, famlen[modfam[v2]]) 3509 cw_apps(page, pos, CW_PAGECAP, "</b></a></span>" as *u8) 3510 } } 3511 cw_apps(page, pos, CW_PAGECAP, "</div>\n<div class='toc'><a href='#docs'>docs</a><a href='#deps'>dependencies</a><a href='#structs'>structs</a><a href='#consts'>consts</a><a href='#functions'>functions</a></div>\n" as *u8) 3512 3513 // header doc block: leading // lines (cap 40) 3514 var hl: i64 = 0 3515 var ls: i64 = 0 3516 var started: i64 = 0 3517 var stop: i64 = 0 3518 while stop == 0 { 3519 if ls >= n2 { stop = 1 } else { 3520 var le2: i64 = ls 3521 var g2: i64 = 1 3522 while g2 == 1 { if le2 >= n2 { g2 = 0 } else { if src[le2] == (10 as u8) { g2 = 0 } else { le2 = le2 + 1 } } } 3523 var iscmt: i64 = 0 3524 if ls + 1 < le2 { if src[ls] == (47 as u8) { if src[ls+1] == (47 as u8) { iscmt = 1 } } } 3525 if iscmt == 1 { 3526 if started == 0 { cw_apps(page, pos, CW_PAGECAP, "<h2 id='docs'>about</h2>\n<div class='doc'>" as *u8); started = 1 } 3527 var cs: i64 = ls + 2 3528 if cs < le2 { if src[cs] == (32 as u8) { cs = cs + 1 } } 3529 cw_appe(page, pos, CW_PAGECAP, ((src as i64) + cs) as *u8, le2 - cs) 3530 cw_apps(page, pos, CW_PAGECAP, "\n" as *u8) 3531 hl = hl + 1 3532 if hl >= 40 { stop = 1 } 3533 ls = le2 + 1 3534 } else { stop = 1 } 3535 } 3536 } 3537 if started == 1 { cw_apps(page, pos, CW_PAGECAP, "</div>\n" as *u8) } 3538 3539 // dependencies: neighborhood diagram + the COMPLETE pill lists 3540 cw_apps(page, pos, CW_PAGECAP, "<h2 id='deps'>dependencies <span class='cnt'>" as *u8) 3541 cw_appn(page, pos, CW_PAGECAP, g.ce_arr[v2]) 3542 cw_apps(page, pos, CW_PAGECAP, " imports &middot; " as *u8) 3543 cw_appn(page, pos, CW_PAGECAP, g.ca_arr[v2]) 3544 cw_apps(page, pos, CW_PAGECAP, " importers</span></h2>\n" as *u8) 3545 cw_nbr(page, pos, CW_PAGECAP, g, v2, pathoff, noext) 3546 cw_apps(page, pos, CW_PAGECAP, "<p><b class='muted'>imports:</b> " as *u8) 3547 var op: i64 = g.out_head[v2] 3548 let oe: i64 = g.out_head[v2 + 1] 3549 if op >= oe { cw_apps(page, pos, CW_PAGECAP, "<span class='muted'>none</span>" as *u8) } 3550 while op < oe { 3551 let dep2: i64 = g.out_list[op] 3552 let dnm: *u8 = ((g.arena as i64) + g.node_off[dep2]) as *u8 3553 if pathoff[dep2] > 0 { 3554 cw_apps(page, pos, CW_PAGECAP, "<span class='pill'>" as *u8) 3555 cw_applink2(page, pos, CW_PAGECAP, dnm, noext) 3556 cw_apps(page, pos, CW_PAGECAP, "</span>" as *u8) 3557 } else { 3558 cw_apps(page, pos, CW_PAGECAP, "<span class='pill ext'>" as *u8) 3559 cw_appe(page, pos, CW_PAGECAP, dnm, cw_slen(dnm)) 3560 cw_apps(page, pos, CW_PAGECAP, " (unresolved)</span>" as *u8) 3561 } 3562 op = op + 1 3563 } 3564 cw_apps(page, pos, CW_PAGECAP, "</p>\n" as *u8) 3565 3566 // imported-by (in CSR), shown cap declared 3567 cw_apps(page, pos, CW_PAGECAP, "<p><b class='muted'>imported by:</b> " as *u8) 3568 var ip: i64 = g.in_head[v2] 3569 let ie: i64 = g.in_head[v2 + 1] 3570 let intotal: i64 = ie - ip 3571 if intotal <= 0 { cw_apps(page, pos, CW_PAGECAP, "<span class='muted'>nobody (leaf or entry point)</span>" as *u8) } 3572 var shown: i64 = 0 3573 while ip < ie { 3574 if shown < CW_SHOWIN { 3575 let who: i64 = g.in_list[ip] 3576 let wnm: *u8 = ((g.arena as i64) + g.node_off[who]) as *u8 3577 cw_apps(page, pos, CW_PAGECAP, "<span class='pill'>" as *u8) 3578 cw_applink2(page, pos, CW_PAGECAP, wnm, noext) 3579 cw_apps(page, pos, CW_PAGECAP, "</span>" as *u8) 3580 shown = shown + 1 3581 } 3582 ip = ip + 1 3583 } 3584 if intotal > CW_SHOWIN { 3585 cw_apps(page, pos, CW_PAGECAP, " <span class='muted'>+" as *u8) 3586 cw_appn(page, pos, CW_PAGECAP, intotal - CW_SHOWIN) 3587 cw_apps(page, pos, CW_PAGECAP, " more (shown cap " as *u8) 3588 cw_appn(page, pos, CW_PAGECAP, CW_SHOWIN) 3589 cw_apps(page, pos, CW_PAGECAP, " declared)</span>" as *u8) 3590 } 3591 cw_apps(page, pos, CW_PAGECAP, "</p>\n" as *u8) 3592 3593 // call flow from main, when this module has one (the entry-point story) 3594 var maind: i64 = 0 - 1 3595 var ms0: i64 = mdefh[v2] 3596 let msE: i64 = mdefh[v2] + mdefc[v2] 3597 while ms0 < msE { 3598 if dnlen[ms0] == 4 { if dnames[dnoff[ms0]] == (109 as u8) { if dnames[dnoff[ms0]+1] == (97 as u8) { if dnames[dnoff[ms0]+2] == (105 as u8) { if dnames[dnoff[ms0]+3] == (110 as u8) { maind = ms0 } } } } } 3599 ms0 = ms0 + 1 3600 } 3601 if maind >= 0 { if cf_oh[maind + 1] - cf_oh[maind] > 0 { 3602 cw_apps(page, pos, CW_PAGECAP, "<h2>call flow from main <span class='cnt'>pre-order; caps 40 nodes / depth 6 declared; &#8635; = already shown</span></h2>\n" as *u8) 3603 cw_callflow(page, pos, CW_PAGECAP, g, dmod, dnames, dnoff, dnlen, cf_oh, cf_ol, maind, noext) 3604 } } 3605 3606 // structs / consts / functions -- one line pass, three tables built as we go 3607 // (functions into the page directly; structs+consts buffered would need 3608 // arenas, so instead: three passes over lines, each cheap and clear) 3609 var nfn2: i64 = 0 3610 3611 cw_apps(page, pos, CW_PAGECAP, "<h2 id='structs'>structs</h2>\n<table>" as *u8) 3612 var any1: i64 = 0 3613 var ls2: i64 = 0 3614 var ln: i64 = 1 3615 while ls2 < n2 { 3616 var le3: i64 = ls2 3617 var g3: i64 = 1 3618 while g3 == 1 { if le3 >= n2 { g3 = 0 } else { if src[le3] == (10 as u8) { g3 = 0 } else { le3 = le3 + 1 } } } 3619 if cw_line_starts(src, ls2, le3, "struct " as *u8) == 1 { 3620 any1 = 1 3621 tstructs = tstructs + 1 3622 cw_apps(page, pos, CW_PAGECAP, "<tr><td class='n'>" as *u8) 3623 cw_appsrclink(page, pos, CW_PAGECAP, nm, ln, noext) 3624 cw_apps(page, pos, CW_PAGECAP, "</td><td class='sig'>" as *u8) 3625 cw_appe(page, pos, CW_PAGECAP, ((src as i64) + ls2) as *u8, cw_sigend(src, ls2, le3) - ls2) 3626 cw_apps(page, pos, CW_PAGECAP, "</td></tr>\n" as *u8) 3627 } 3628 ln = ln + 1 3629 ls2 = le3 + 1 3630 } 3631 if any1 == 0 { cw_apps(page, pos, CW_PAGECAP, "<tr><td class='muted'>none</td></tr>" as *u8) } 3632 cw_apps(page, pos, CW_PAGECAP, "</table>\n" as *u8) 3633 3634 cw_apps(page, pos, CW_PAGECAP, "<h2 id='consts'>consts</h2>\n<table>" as *u8) 3635 var any2: i64 = 0 3636 var ls3: i64 = 0 3637 var ln2: i64 = 1 3638 while ls3 < n2 { 3639 var le4: i64 = ls3 3640 var g4: i64 = 1 3641 while g4 == 1 { if le4 >= n2 { g4 = 0 } else { if src[le4] == (10 as u8) { g4 = 0 } else { le4 = le4 + 1 } } } 3642 if cw_line_starts(src, ls3, le4, "const " as *u8) == 1 { 3643 any2 = 1 3644 tconsts = tconsts + 1 3645 cw_apps(page, pos, CW_PAGECAP, "<tr><td class='n'>" as *u8) 3646 cw_appsrclink(page, pos, CW_PAGECAP, nm, ln2, noext) 3647 cw_apps(page, pos, CW_PAGECAP, "</td><td class='sig'>" as *u8) 3648 cw_appe(page, pos, CW_PAGECAP, ((src as i64) + ls3) as *u8, cw_sigend(src, ls3, le4) - ls3) 3649 cw_apps(page, pos, CW_PAGECAP, "</td></tr>\n" as *u8) 3650 } 3651 ln2 = ln2 + 1 3652 ls3 = le4 + 1 3653 } 3654 if any2 == 0 { cw_apps(page, pos, CW_PAGECAP, "<tr><td class='muted'>none</td></tr>" as *u8) } 3655 cw_apps(page, pos, CW_PAGECAP, "</table>\n" as *u8) 3656 3657 cw_apps(page, pos, CW_PAGECAP, "<h2 id='functions'>functions</h2>\n<table>" as *u8) 3658 var any3: i64 = 0 3659 var ls4: i64 = 0 3660 var ln3: i64 = 1 3661 while ls4 < n2 { 3662 var le5: i64 = ls4 3663 var g5: i64 = 1 3664 while g5 == 1 { if le5 >= n2 { g5 = 0 } else { if src[le5] == (10 as u8) { g5 = 0 } else { le5 = le5 + 1 } } } 3665 if cw_line_starts(src, ls4, le5, "func " as *u8) == 1 { 3666 any3 = 1 3667 nfn2 = nfn2 + 1 3668 tfuncs = tfuncs + 1 3669 // function name span (for the anchor + the search index) 3670 let fs0: i64 = ls4 + 5 3671 var fe0: i64 = fs0 3672 var gnm: i64 = 1 3673 while gnm == 1 { 3674 if fe0 < le5 { if gl_is_ident(src[fe0] as i64) == 1 { fe0 = fe0 + 1 } else { gnm = 0 } } else { gnm = 0 } 3675 } 3676 let fnl: i64 = fe0 - fs0 3677 cw_apps(page, pos, CW_PAGECAP, "<tr id='fn_" as *u8) 3678 if fnl > 0 { cw_app(page, pos, CW_PAGECAP, ((src as i64) + fs0) as *u8, fnl) } 3679 cw_apps(page, pos, CW_PAGECAP, "'><td class='n'>" as *u8) 3680 cw_appsrclink(page, pos, CW_PAGECAP, nm, ln3, noext) 3681 if fnl > 0 { if fnl < 96 { if nfns < CW_MAXFN { if fnu[0] + fnl + 1 < CW_FNARENA { 3682 var fc0: i64 = 0 3683 while fc0 < fnl { fnarena[fnu[0] + fc0] = src[fs0 + fc0]; fc0 = fc0 + 1 } 3684 fnoff[nfns] = fnu[0] 3685 fnlen[nfns] = fnl 3686 fnmod[nfns] = v2 3687 fnline[nfns] = ln3 3688 fnu[0] = fnu[0] + fnl 3689 nfns = nfns + 1 3690 } } } } 3691 cw_apps(page, pos, CW_PAGECAP, "</td><td class='sig'>" as *u8) 3692 cw_appe(page, pos, CW_PAGECAP, ((src as i64) + ls4) as *u8, cw_sigend(src, ls4, le5) - ls4) 3693 // call-graph annotation: callers/callees of THIS def (matched by line) 3694 var dfx: i64 = 0 - 1 3695 var dscan: i64 = mdefh[v2] 3696 let dend: i64 = mdefh[v2] + mdefc[v2] 3697 while dscan < dend { if dline[dscan] == ln3 { dfx = dscan; dscan = dend } else { dscan = dscan + 1 } } 3698 if dfx >= 0 { 3699 let ncal: i64 = cf_ih[dfx + 1] - cf_ih[dfx] 3700 let ncee: i64 = cf_oh[dfx + 1] - cf_oh[dfx] 3701 if ncal + ncee > 0 { 3702 cw_apps(page, pos, CW_PAGECAP, "<div class='fnc'>" as *u8) 3703 if ncal > 0 { 3704 cw_apps(page, pos, CW_PAGECAP, "<span class='lab'>called by " as *u8) 3705 cw_appn(page, pos, CW_PAGECAP, ncal) 3706 cw_apps(page, pos, CW_PAGECAP, ":</span> " as *u8) 3707 var cp0: i64 = cf_ih[dfx] 3708 var csh0: i64 = 0 3709 while cp0 < cf_ih[dfx + 1] { 3710 if csh0 < CW_CALLSHOW { cw_appdeflink(page, pos, CW_PAGECAP, g, dmod, dnames, dnoff, dnlen, cf_il[cp0], noext); csh0 = csh0 + 1 } 3711 cp0 = cp0 + 1 3712 } 3713 if ncal > CW_CALLSHOW { cw_apps(page, pos, CW_PAGECAP, "<span class='muted'>+" as *u8); cw_appn(page, pos, CW_PAGECAP, ncal - CW_CALLSHOW); cw_apps(page, pos, CW_PAGECAP, "</span>" as *u8) } 3714 } 3715 if ncee > 0 { 3716 cw_apps(page, pos, CW_PAGECAP, " <span class='lab'>calls " as *u8) 3717 cw_appn(page, pos, CW_PAGECAP, ncee) 3718 cw_apps(page, pos, CW_PAGECAP, ":</span> " as *u8) 3719 var cp1: i64 = cf_oh[dfx] 3720 var csh1: i64 = 0 3721 while cp1 < cf_oh[dfx + 1] { 3722 if csh1 < CW_CALLSHOW { cw_appdeflink(page, pos, CW_PAGECAP, g, dmod, dnames, dnoff, dnlen, cf_ol[cp1], noext); csh1 = csh1 + 1 } 3723 cp1 = cp1 + 1 3724 } 3725 if ncee > CW_CALLSHOW { cw_apps(page, pos, CW_PAGECAP, "<span class='muted'>+" as *u8); cw_appn(page, pos, CW_PAGECAP, ncee - CW_CALLSHOW); cw_apps(page, pos, CW_PAGECAP, "</span>" as *u8) } 3726 } 3727 cw_apps(page, pos, CW_PAGECAP, "</div>" as *u8) 3728 } 3729 } 3730 cw_apps(page, pos, CW_PAGECAP, "</td></tr>\n" as *u8) 3731 } 3732 ln3 = ln3 + 1 3733 ls4 = le5 + 1 3734 } 3735 if any3 == 0 { cw_apps(page, pos, CW_PAGECAP, "<tr><td class='muted'>none</td></tr>" as *u8) } 3736 cw_apps(page, pos, CW_PAGECAP, "</table>\n" as *u8) 3737 3738 fnfn[v2] = nfn2 3739 cw_foot(page, pos, CW_PAGECAP) 3740 cw_pagepath(opath, outdir, nm) 3741 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 3742 if pos[1] == 1 { truncs = truncs + 1 } 3743 3744 // ----- the SOURCE PAGE: line-anchored, escaped, cross-linked ----- 3745 pos[0] = 0 3746 pos[1] = 0 3747 cw_head3(page, pos, CW_PAGECAP, nm, cw_slen(nm), sbbuf) 3748 cw_crumb(page, pos, CW_PAGECAP, noext, dlab2, dslug, nm, cw_slen(nm)) 3749 cw_apps(page, pos, CW_PAGECAP, "<h1><code>" as *u8) 3750 cw_appe(page, pos, CW_PAGECAP, nm, cw_slen(nm)) 3751 cw_apps(page, pos, CW_PAGECAP, "</code> source</h1>\n<p class='muted'><a href='" as *u8) 3752 cw_appstem(page, pos, CW_PAGECAP, nm) 3753 cw_appext(page, pos, CW_PAGECAP, noext) 3754 cw_apps(page, pos, CW_PAGECAP, "'>&#8617; module page</a> &middot; " as *u8) 3755 cw_appn(page, pos, CW_PAGECAP, floc[v2]) 3756 cw_apps(page, pos, CW_PAGECAP, " lines &middot; " as *u8) 3757 cw_appn(page, pos, CW_PAGECAP, fbytes[v2]) 3758 cw_apps(page, pos, CW_PAGECAP, " B</p>\n<div class='srcv'>" as *u8) 3759 var sls: i64 = 0 3760 var sln: i64 = 1 3761 while sls < n2 { 3762 var sle: i64 = sls 3763 var sg: i64 = 1 3764 while sg == 1 { if sle >= n2 { sg = 0 } else { if src[sle] == (10 as u8) { sg = 0 } else { sle = sle + 1 } } } 3765 cw_apps(page, pos, CW_PAGECAP, "<span class='l' id='L" as *u8) 3766 cw_appn(page, pos, CW_PAGECAP, sln) 3767 cw_apps(page, pos, CW_PAGECAP, "'><span class='ln'>" as *u8) 3768 cw_appn(page, pos, CW_PAGECAP, sln) 3769 cw_apps(page, pos, CW_PAGECAP, "</span>" as *u8) 3770 var sve: i64 = sle 3771 if sve > sls { if src[sve - 1] == (13 as u8) { sve = sve - 1 } } 3772 cw_appe(page, pos, CW_PAGECAP, ((src as i64) + sls) as *u8, sve - sls) 3773 cw_apps(page, pos, CW_PAGECAP, "</span>\n" as *u8) 3774 sln = sln + 1 3775 sls = sle + 1 3776 } 3777 cw_apps(page, pos, CW_PAGECAP, "</div>\n" as *u8) 3778 cw_foot(page, pos, CW_PAGECAP) 3779 var sw0: i64 = 0 3780 var si0: i64 = 0 3781 while outdir[si0] != (0 as u8) { opath[sw0] = outdir[si0]; sw0 = sw0 + 1; si0 = si0 + 1 } 3782 opath[sw0] = 47 as u8 3783 sw0 = sw0 + 1 3784 sw0 = sw0 + cw_rawcpy(opath, sw0, "src_" as *u8) 3785 var si1: i64 = 0 3786 let stl: i64 = cw_stemlen(nm) 3787 while si1 < stl { opath[sw0] = nm[si1]; sw0 = sw0 + 1; si1 = si1 + 1 } 3788 sw0 = sw0 + cw_rawcpy(opath, sw0, ".html" as *u8) 3789 opath[sw0] = 0 as u8 3790 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 3791 if pos[1] == 1 { truncs = truncs + 1 } 3792 } 3793 s2i = s2i + 1 3794 } 3795 st[3] = tfuncs 3796 st[4] = tstructs 3797 st[5] = tconsts 3798 st[11] = truncs 3799 3800 // ===== pass 3a: directory pages ===== 3801 var d3: i64 = 0 3802 while d3 < ndirs { 3803 pos[0] = 0 3804 pos[1] = 0 3805 let dlabel: *u8 = ((dirarena as i64) + dirnoff[d3]) as *u8 3806 var dll: i64 = cw_slen(dlabel) 3807 cw_head3(page, pos, CW_PAGECAP, dlabel, dll, sbbuf) 3808 cw_crumb(page, pos, CW_PAGECAP, noext, dlabel, 0 as *u8, dlabel, dll) 3809 cw_apps(page, pos, CW_PAGECAP, "<h1>" as *u8) 3810 if dll == 0 { cw_apps(page, pos, CW_PAGECAP, "(root)" as *u8) } else { cw_appe(page, pos, CW_PAGECAP, dlabel, dll) } 3811 cw_apps(page, pos, CW_PAGECAP, "</h1>\n<p class='muted'>" as *u8) 3812 cw_appn(page, pos, CW_PAGECAP, dircnt[d3]) 3813 cw_apps(page, pos, CW_PAGECAP, " modules</p>\n" as *u8) 3814 // narrative sidecar (see cw_nar_include) 3815 let nslug: *u8 = ((dirarena as i64) + dirslug[d3]) as *u8 3816 cw_nar_include(page, pos, CW_PAGECAP, outdir, opath, nslug) 3817 cw_filterjs(page, pos, CW_PAGECAP) 3818 cw_apps(page, pos, CW_PAGECAP, "<table><tr><th>module</th><th>description</th><th class='n'>lines</th><th class='n'>funcs</th></tr>\n" as *u8) 3819 var s3i: i64 = 0 3820 while s3i < nsorted { 3821 let v3: i64 = sidx[s3i] 3822 if pathoff[v3] > 0 { if fdir[v3] == d3 { 3823 let nm3: *u8 = ((g.arena as i64) + g.node_off[v3]) as *u8 3824 cw_apps(page, pos, CW_PAGECAP, "<tr data-m='" as *u8) 3825 cw_appe(page, pos, CW_PAGECAP, nm3, cw_slen(nm3)) 3826 cw_apps(page, pos, CW_PAGECAP, "'><td>" as *u8) 3827 cw_applink2(page, pos, CW_PAGECAP, nm3, noext) 3828 cw_apps(page, pos, CW_PAGECAP, "</td><td class='muted'>" as *u8) 3829 if dlen[v3] > 0 { cw_appe(page, pos, CW_PAGECAP, ((descarena as i64) + doff[v3]) as *u8, dlen[v3]) } 3830 cw_apps(page, pos, CW_PAGECAP, "</td><td class='n'>" as *u8) 3831 cw_appn(page, pos, CW_PAGECAP, floc[v3]) 3832 cw_apps(page, pos, CW_PAGECAP, "</td><td class='n'>" as *u8) 3833 cw_appn(page, pos, CW_PAGECAP, fnfn[v3]) 3834 cw_apps(page, pos, CW_PAGECAP, "</td></tr>\n" as *u8) 3835 } } 3836 s3i = s3i + 1 3837 } 3838 cw_apps(page, pos, CW_PAGECAP, "</table>\n" as *u8) 3839 cw_foot(page, pos, CW_PAGECAP) 3840 var w2: i64 = 0 3841 var i4: i64 = 0 3842 while outdir[i4] != (0 as u8) { opath[w2] = outdir[i4]; w2 = w2 + 1; i4 = i4 + 1 } 3843 opath[w2] = 47 as u8; w2 = w2 + 1 3844 let slg: *u8 = ((dirarena as i64) + dirslug[d3]) as *u8 3845 var i5: i64 = 0 3846 while slg[i5] != (0 as u8) { opath[w2] = slg[i5]; w2 = w2 + 1; i5 = i5 + 1 } 3847 cw_rawcpy(opath, w2, ".html" as *u8) 3848 w2 = w2 + 5 3849 opath[w2] = 0 as u8 3850 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 3851 if pos[1] == 1 { truncs = truncs + 1 } 3852 d3 = d3 + 1 3853 } 3854 3855 // ===== pass 3f: topic pages (families >= CW_FAMMIN members) + topics index ===== 3856 let tnmb: *u8 = sys_mmap(64) 3857 var tp0: i64 = 0 3858 while tp0 < nfam { 3859 if famcnt[tp0] >= CW_FAMMIN { 3860 let fmn2: *u8 = ((famarena as i64) + famoff[tp0]) as *u8 3861 pos[0] = 0 3862 pos[1] = 0 3863 cw_head3(page, pos, CW_PAGECAP, fmn2, famlen[tp0], sbbuf) 3864 cw_crumb(page, pos, CW_PAGECAP, noext, 0 as *u8, 0 as *u8, fmn2, famlen[tp0]) 3865 cw_apps(page, pos, CW_PAGECAP, "<h1>topic: " as *u8) 3866 cw_appe(page, pos, CW_PAGECAP, fmn2, famlen[tp0]) 3867 cw_apps(page, pos, CW_PAGECAP, "</h1>\n<p class='muted'>" as *u8) 3868 cw_appn(page, pos, CW_PAGECAP, famcnt[tp0]) 3869 cw_apps(page, pos, CW_PAGECAP, " modules sharing the <code>" as *u8) 3870 cw_appe(page, pos, CW_PAGECAP, fmn2, famlen[tp0]) 3871 cw_apps(page, pos, CW_PAGECAP, "</code> name family (derived from the tree's prefix discipline).</p>\n" as *u8) 3872 var tw0: i64 = 0 3873 tw0 = tw0 + cw_rawcpy(tnmb, 0, "t_" as *u8) 3874 var tw1: i64 = 0 3875 while tw1 < famlen[tp0] { tnmb[tw0] = famarena[famoff[tp0] + tw1]; tw0 = tw0 + 1; tw1 = tw1 + 1 } 3876 tnmb[tw0] = 0 as u8 3877 cw_nar_include(page, pos, CW_PAGECAP, outdir, opath, tnmb) 3878 cw_filterjs(page, pos, CW_PAGECAP) 3879 cw_apps(page, pos, CW_PAGECAP, "<table><tr><th>module</th><th>description</th><th class='n'>lines</th><th class='n'>funcs</th></tr>\n" as *u8) 3880 var tm0: i64 = 0 3881 while tm0 < nsorted { 3882 let tmv: i64 = sidx[tm0] 3883 if modfam[tmv] == tp0 { 3884 let tmn: *u8 = ((g.arena as i64) + g.node_off[tmv]) as *u8 3885 cw_apps(page, pos, CW_PAGECAP, "<tr data-m='" as *u8) 3886 cw_appe(page, pos, CW_PAGECAP, tmn, cw_slen(tmn)) 3887 cw_apps(page, pos, CW_PAGECAP, "'><td>" as *u8) 3888 cw_applink2(page, pos, CW_PAGECAP, tmn, noext) 3889 cw_apps(page, pos, CW_PAGECAP, "</td><td class='muted'>" as *u8) 3890 if dlen[tmv] > 0 { cw_appe(page, pos, CW_PAGECAP, ((descarena as i64) + doff[tmv]) as *u8, dlen[tmv]) } 3891 cw_apps(page, pos, CW_PAGECAP, "</td><td class='n'>" as *u8) 3892 cw_appn(page, pos, CW_PAGECAP, floc[tmv]) 3893 cw_apps(page, pos, CW_PAGECAP, "</td><td class='n'>" as *u8) 3894 cw_appn(page, pos, CW_PAGECAP, fnfn[tmv]) 3895 cw_apps(page, pos, CW_PAGECAP, "</td></tr>\n" as *u8) 3896 } 3897 tm0 = tm0 + 1 3898 } 3899 cw_apps(page, pos, CW_PAGECAP, "</table>\n" as *u8) 3900 cw_foot(page, pos, CW_PAGECAP) 3901 cw_outpath(opath, outdir, tnmb) 3902 var tw2: i64 = cw_slen(opath) 3903 cw_rawcpy(opath, tw2, ".html" as *u8) 3904 opath[tw2 + 5] = 0 as u8 3905 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 3906 if pos[1] == 1 { truncs = truncs + 1 } 3907 } 3908 tp0 = tp0 + 1 3909 } 3910 // the topics index 3911 pos[0] = 0 3912 pos[1] = 0 3913 cw_head3(page, pos, CW_PAGECAP, "topics" as *u8, 6, sbbuf) 3914 cw_crumb(page, pos, CW_PAGECAP, noext, 0 as *u8, 0 as *u8, "topics" as *u8, 6) 3915 cw_apps(page, pos, CW_PAGECAP, "<h1>topics</h1>\n<p class='muted'>every name family with at least " as *u8) 3916 cw_appn(page, pos, CW_PAGECAP, CW_FAMMIN) 3917 cw_apps(page, pos, CW_PAGECAP, " member modules (threshold declared); ordered by total lines of code.</p>\n<table><tr><th>topic</th><th class='n'>modules</th><th class='n'>lines</th></tr>\n" as *u8) 3918 let tix: *i64 = sys_mmap((nfam + 2) * 8) as *i64 3919 var ntix: i64 = 0 3920 var ti0: i64 = 0 3921 while ti0 < nfam { 3922 var tibest: i64 = 0 - 1 3923 var ti1: i64 = 0 3924 while ti1 < nfam { 3925 var titk: i64 = 0 3926 var ti2: i64 = 0 3927 while ti2 < ntix { if tix[ti2] == ti1 { titk = 1 } ti2 = ti2 + 1 } 3928 if titk == 0 { if famcnt[ti1] >= CW_FAMMIN { if tibest < 0 { tibest = ti1 } else { if famloc[ti1] > famloc[tibest] { tibest = ti1 } } } } 3929 ti1 = ti1 + 1 3930 } 3931 if tibest >= 0 { 3932 tix[ntix] = tibest 3933 ntix = ntix + 1 3934 cw_apps(page, pos, CW_PAGECAP, "<tr><td><a href='t_" as *u8) 3935 cw_apps(page, pos, CW_PAGECAP, ((famarena as i64) + famoff[tibest]) as *u8) 3936 cw_appext(page, pos, CW_PAGECAP, noext) 3937 cw_apps(page, pos, CW_PAGECAP, "'>" as *u8) 3938 cw_appe(page, pos, CW_PAGECAP, ((famarena as i64) + famoff[tibest]) as *u8, famlen[tibest]) 3939 cw_apps(page, pos, CW_PAGECAP, "</a></td><td class='n'>" as *u8) 3940 cw_appn(page, pos, CW_PAGECAP, famcnt[tibest]) 3941 cw_apps(page, pos, CW_PAGECAP, "</td><td class='n'>" as *u8) 3942 cw_appn(page, pos, CW_PAGECAP, famloc[tibest]) 3943 cw_apps(page, pos, CW_PAGECAP, "</td></tr>\n" as *u8) 3944 } 3945 ti0 = ti0 + 1 3946 } 3947 cw_apps(page, pos, CW_PAGECAP, "</table>\n" as *u8) 3948 cw_foot(page, pos, CW_PAGECAP) 3949 cw_outpath(opath, outdir, "topics.html" as *u8) 3950 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 3951 if pos[1] == 1 { truncs = truncs + 1 } 3952 3953 // ===== pass 3g: the KIND CENSUS (what everything IS, by measured rule) ===== 3954 pos[0] = 0 3955 pos[1] = 0 3956 cw_head3(page, pos, CW_PAGECAP, "inventory" as *u8, 9, sbbuf) 3957 cw_crumb(page, pos, CW_PAGECAP, noext, 0 as *u8, 0 as *u8, "inventory" as *u8, 9) 3958 cw_apps(page, pos, CW_PAGECAP, "<h1>inventory: what every module IS</h1>\n<p class='muted'>classified by measurable rule, first match wins: archived dir &rarr; gate/test name &rarr; bench &rarr; probe &rarr; smoke &rarr; sketch/demo &rarr; generated fixture (self-declared, or family &ge; " as *u8) 3959 cw_appn(page, pos, CW_PAGECAP, CW_GENFIX_FAM) 3960 cw_apps(page, pos, CW_PAGECAP, " members and &lt; " as *u8) 3961 cw_appn(page, pos, CW_PAGECAP, CW_GENFIX_LOC) 3962 cw_apps(page, pos, CW_PAGECAP, " lines) &rarr; service (main + serving suffix) &rarr; tool (owns main) &rarr; library (imported) &rarr; orphan library (no main, no importers &mdash; candidate dead code). Nothing is guessed; a rule either fires or the next one is tried.</p>\n" as *u8) 3963 var kc0: i64 = 0 3964 while kc0 < CW_NKIND { 3965 cw_apps(page, pos, CW_PAGECAP, "<h2>" as *u8) 3966 cw_apps(page, pos, CW_PAGECAP, cw_kindname(kc0)) 3967 cw_apps(page, pos, CW_PAGECAP, " <span class='cnt'>" as *u8) 3968 cw_appn(page, pos, CW_PAGECAP, kindcnt[kc0]) 3969 cw_apps(page, pos, CW_PAGECAP, " modules &middot; " as *u8) 3970 cw_appn(page, pos, CW_PAGECAP, kindloc[kc0]) 3971 cw_apps(page, pos, CW_PAGECAP, " lines &middot; first " as *u8) 3972 cw_appn(page, pos, CW_PAGECAP, CW_KINDSHOW) 3973 cw_apps(page, pos, CW_PAGECAP, " shown (declared)</span></h2>\n<p>" as *u8) 3974 var ks0: i64 = 0 3975 var ksh: i64 = 0 3976 while ks0 < nsorted { 3977 let ksv: i64 = sidx[ks0] 3978 if kindv[ksv] == kc0 { if ksh < CW_KINDSHOW { 3979 cw_apps(page, pos, CW_PAGECAP, "<span class='pill'>" as *u8) 3980 cw_applink2(page, pos, CW_PAGECAP, ((g.arena as i64) + g.node_off[ksv]) as *u8, noext) 3981 cw_apps(page, pos, CW_PAGECAP, "</span>" as *u8) 3982 ksh = ksh + 1 3983 } } 3984 ks0 = ks0 + 1 3985 } 3986 if kindcnt[kc0] > CW_KINDSHOW { 3987 cw_apps(page, pos, CW_PAGECAP, " <span class='muted'>+" as *u8) 3988 cw_appn(page, pos, CW_PAGECAP, kindcnt[kc0] - CW_KINDSHOW) 3989 cw_apps(page, pos, CW_PAGECAP, " more (search filters by kind)</span>" as *u8) 3990 } 3991 cw_apps(page, pos, CW_PAGECAP, "</p>\n" as *u8) 3992 kc0 = kc0 + 1 3993 } 3994 cw_foot(page, pos, CW_PAGECAP) 3995 cw_outpath(opath, outdir, "kinds.html" as *u8) 3996 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 3997 if pos[1] == 1 { truncs = truncs + 1 } 3998 3999 // ===== THE FINDINGS ENGINE: detectors -> the work backlog ===== 4000 // Findings accumulate into fbuf as nx_debt-grammar rows with STABLE descs; 4001 // the exposure page + census contribute theirs; the beat bridge files them 4002 // idempotently. This is what closes the loop: regen surfaces work, the 4003 // wiki page is the gauge, the debt row is the durable pointer. 4004 let fbuf: *u8 = sys_mmap(CW_FINDCAP) 4005 let fpos: *i64 = sys_mmap(32) as *i64 4006 fpos[0] = 0 4007 fpos[1] = 0 4008 4009 // census-derived findings (thresholds declared; descs count-free) 4010 if st[18] > 0 { 4011 cw_fnd(fbuf, fpos, 4, "codewiki" as *u8, 4012 "Orphan libraries exist (modules with no main and zero importers = dead-code candidates). Live list: https://nishifamily.com/code/kinds -- triage each: wire a caller, or retire (rule 13)." as *u8) 4013 } 4014 // import graph should be a DAG; a cycle is an architecture tangle 4015 if st[9] != 0 { 4016 cw_fnd(fbuf, fpos, 6, "codewiki" as *u8, 4017 "The import graph has a CYCLE (should be a DAG). https://nishifamily.com/code/arch -- break the tangle; sovereign layering flows one way toward nx_syscalls.") 4018 } 4019 // unresolved imports = a module names an import not present in this tree 4020 if st[6] > 0 { 4021 cw_fnd(fbuf, fpos, 4, "codewiki" as *u8, 4022 "Unresolved import targets exist (a module imports a name not found under this root -- generated, drifted, or dead imports). https://nishifamily.com/code/index -- reconcile or remove." as *u8) 4023 } 4024 4025 // ===== pass 3h: exposure page (MCP/API coverage join) ===== 4026 pos[0] = 0 4027 pos[1] = 0 4028 cw_head3(page, pos, CW_PAGECAP, "exposure" as *u8, 8, sbbuf) 4029 cw_crumb(page, pos, CW_PAGECAP, noext, 0 as *u8, 0 as *u8, "exposure" as *u8, 8) 4030 cw_apps(page, pos, CW_PAGECAP, "<h1>exposure: where MCP and APIs are (and are not)</h1>\n<p class='muted'>the wiki's module+kind table joined with the live allowlist and the deployed elf set. The dark-capability section IS the where-we-need-MCP list, and it feeds the work backlog automatically.</p>\n" as *u8) 4031 let darkbox: *i64 = sys_mmap(16) 4032 darkbox[0] = 0 4033 let nexp2: i64 = cw_exposure(page, pos, CW_PAGECAP, g, pathoff, kindv, sidx, nsorted, noext, 4034 "tool_allowlist.conf" as *u8, "." as *u8, darkbox, fbuf, fpos, srcmt) 4035 st[19] = nexp2 4036 st[20] = darkbox[0] 4037 cw_foot(page, pos, CW_PAGECAP) 4038 cw_outpath(opath, outdir, "exposure.html" as *u8) 4039 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 4040 if pos[1] == 1 { truncs = truncs + 1 } 4041 4042 // ===== pass 3dbt: the DEBT TAXONOMY -- every category, module-cited ===== 4043 // Counts modules carrying each category's markers (from the pass-1 scan), 4044 // lists examples, and files ONE finding per non-empty category. This is the 4045 // "cover all the categories" surface: landmines, workarounds, gotchas, 4046 // todos, third-party, security, perf, deprecated -- each a backlog row. 4047 pos[0] = 0 4048 pos[1] = 0 4049 cw_head3(page, pos, CW_PAGECAP, "debt" as *u8, 4, sbbuf) 4050 cw_crumb(page, pos, CW_PAGECAP, noext, 0 as *u8, 0 as *u8, "debt" as *u8, 4) 4051 cw_apps(page, pos, CW_PAGECAP, "<h1>debt taxonomy</h1>\n<p class='muted'>every module is scanned for the debt-category markers it carries in its own comments -- the tree already documents its hazards; this makes them countable and backlog-fed. Each non-empty category files one finding.</p>\n" as *u8) 4052 var cat0: i64 = 0 4053 while cat0 < CW_NCAT { 4054 let bit: i64 = 1 4055 var shift: i64 = 0 4056 var bmask: i64 = 1 4057 while shift < cat0 { bmask = bmask * 2; shift = shift + 1 } 4058 var ccnt: i64 = 0 4059 var cq: i64 = 0 4060 while cq < nsorted { let cvv: i64 = sidx[cq]; if (catmask[cvv] & bmask) != 0 { ccnt = ccnt + 1 } cq = cq + 1 } 4061 cw_apps(page, pos, CW_PAGECAP, "<h2>" as *u8) 4062 cw_apps(page, pos, CW_PAGECAP, cw_catname(cat0)) 4063 cw_apps(page, pos, CW_PAGECAP, " <span class='cnt'>" as *u8) 4064 cw_appn(page, pos, CW_PAGECAP, ccnt) 4065 cw_apps(page, pos, CW_PAGECAP, " modules &middot; sev " as *u8) 4066 cw_appn(page, pos, CW_PAGECAP, cw_catsev(cat0)) 4067 cw_apps(page, pos, CW_PAGECAP, " &middot; first " as *u8) 4068 cw_appn(page, pos, CW_PAGECAP, CW_CATSHOW) 4069 cw_apps(page, pos, CW_PAGECAP, " shown</span></h2>\n<p>" as *u8) 4070 var csh: i64 = 0 4071 var cq2: i64 = 0 4072 while cq2 < nsorted { 4073 let cvv2: i64 = sidx[cq2] 4074 if (catmask[cvv2] & bmask) != 0 { if csh < CW_CATSHOW { 4075 cw_apps(page, pos, CW_PAGECAP, "<span class='pill'>" as *u8) 4076 cw_applink2(page, pos, CW_PAGECAP, ((g.arena as i64) + g.node_off[cvv2]) as *u8, noext) 4077 cw_apps(page, pos, CW_PAGECAP, "</span>" as *u8) 4078 csh = csh + 1 4079 } } 4080 cq2 = cq2 + 1 4081 } 4082 if ccnt == 0 { cw_apps(page, pos, CW_PAGECAP, "<span class='muted'>none detected</span>" as *u8) } 4083 if ccnt > CW_CATSHOW { cw_apps(page, pos, CW_PAGECAP, " <span class='muted'>+" as *u8); cw_appn(page, pos, CW_PAGECAP, ccnt - CW_CATSHOW); cw_apps(page, pos, CW_PAGECAP, " more</span>" as *u8) } 4084 cw_apps(page, pos, CW_PAGECAP, "</p>\n" as *u8) 4085 // one aggregate finding per non-empty category (count-free desc) 4086 if ccnt > 0 { 4087 cw_fnd(fbuf, fpos, cw_catsev(cat0), "codewiki-debt" as *u8, cw_catdesc(cat0)) 4088 } 4089 // TARGETED rows for the SEVERE categories: name the individual modules 4090 // with the largest blast radius so each is a pickable work item. The 4091 // aggregate row above still covers the tail; these are the ones to do 4092 // first, chosen by measurement (fan-in), not by taste. 4093 if cw_catsev(cat0) >= CW_TGTSEV { if ccnt > 0 { 4094 cw_apps(page, pos, CW_PAGECAP, "<p class='muted'>filed individually (top " as *u8) 4095 cw_appn(page, pos, CW_PAGECAP, CW_TGTCAP) 4096 cw_apps(page, pos, CW_PAGECAP, " by blast radius): " as *u8) 4097 let tgk: *i64 = sys_mmap((CW_TGTCAP + 2) * 8) as *i64 4098 var ntg: i64 = 0 4099 var tg0: i64 = 0 4100 while tg0 < CW_TGTCAP { 4101 var tbest: i64 = 0 - 1 4102 var tg1: i64 = 0 4103 while tg1 < nsorted { 4104 let tvv: i64 = sidx[tg1] 4105 if (catmask[tvv] & bmask) != 0 { 4106 var taken: i64 = 0 4107 var tg2: i64 = 0 4108 while tg2 < ntg { if tgk[tg2] == tvv { taken = 1 } tg2 = tg2 + 1 } 4109 if taken == 0 { if tbest < 0 { tbest = tvv } else { if g.ca_arr[tvv] > g.ca_arr[tbest] { tbest = tvv } } } 4110 } 4111 tg1 = tg1 + 1 4112 } 4113 if tbest >= 0 { if g.ca_arr[tbest] > 0 { 4114 tgk[ntg] = tbest 4115 ntg = ntg + 1 4116 let tnm2: *u8 = ((g.arena as i64) + g.node_off[tbest]) as *u8 4117 cw_fnd_mod(fbuf, fpos, cw_catsev(cat0), cw_catname(cat0), tnm2, cw_stemlen(tnm2)) 4118 cw_apps(page, pos, CW_PAGECAP, "<span class='pill'>" as *u8) 4119 cw_applink2(page, pos, CW_PAGECAP, tnm2, noext) 4120 cw_apps(page, pos, CW_PAGECAP, "</span>" as *u8) 4121 } } 4122 tg0 = tg0 + 1 4123 } 4124 if ntg == 0 { cw_apps(page, pos, CW_PAGECAP, "<span class='muted'>none with importers</span>" as *u8) } 4125 cw_apps(page, pos, CW_PAGECAP, "</p>\n" as *u8) 4126 } } 4127 cat0 = cat0 + 1 4128 } 4129 // taste-bound gauge (bounds law 2026-07-29, seq1242): the 07-29 audit 4130 // found naked bounds the MAJORITY tree-wide; this section re-measures at 4131 // every regen so the law has a standing gauge, not a one-off sweep. 4132 var tbcnt: i64 = 0 4133 var tbmods: i64 = 0 4134 var tb0: i64 = 0 4135 while tb0 < nsorted { 4136 let tbv: i64 = sidx[tb0] 4137 if boundv[tbv] > 0 { tbmods = tbmods + 1; tbcnt = tbcnt + boundv[tbv] } 4138 tb0 = tb0 + 1 4139 } 4140 cw_apps(page, pos, CW_PAGECAP, "<h2>taste-bound consts <span class='cnt'>" as *u8) 4141 cw_appn(page, pos, CW_PAGECAP, tbcnt) 4142 cw_apps(page, pos, CW_PAGECAP, " caps in " as *u8) 4143 cw_appn(page, pos, CW_PAGECAP, tbmods) 4144 cw_apps(page, pos, CW_PAGECAP, " modules &middot; goal FALLING &middot; first " as *u8) 4145 cw_appn(page, pos, CW_PAGECAP, CW_CATSHOW) 4146 cw_apps(page, pos, CW_PAGECAP, " shown</span></h2>\n<p class='muted'>consts named *CAP/*MAX (value &gt;= 16) whose own line or the line above carries NO measurement provenance (markers: measured / derived / sized / budget / today / RFC / JPL / ==). The bounds law: derived and adaptive, never taste &mdash; and when a bound bites, the fix is architecture, not a different number.</p>\n<p>" as *u8) 4147 var tbs: i64 = 0 4148 var tb1: i64 = 0 4149 while tb1 < nsorted { 4150 let tbw: i64 = sidx[tb1] 4151 if boundv[tbw] > 0 { if tbs < CW_CATSHOW { 4152 cw_apps(page, pos, CW_PAGECAP, "<span class='pill'>" as *u8) 4153 cw_applink2(page, pos, CW_PAGECAP, ((g.arena as i64) + g.node_off[tbw]) as *u8, noext) 4154 cw_apps(page, pos, CW_PAGECAP, "</span>" as *u8) 4155 tbs = tbs + 1 4156 } } 4157 tb1 = tb1 + 1 4158 } 4159 if tbmods == 0 { cw_apps(page, pos, CW_PAGECAP, "<span class='muted'>none detected</span>" as *u8) } 4160 if tbmods > CW_CATSHOW { cw_apps(page, pos, CW_PAGECAP, " <span class='muted'>+" as *u8); cw_appn(page, pos, CW_PAGECAP, tbmods - CW_CATSHOW); cw_apps(page, pos, CW_PAGECAP, " more</span>" as *u8) } 4161 cw_apps(page, pos, CW_PAGECAP, "</p>\n" as *u8) 4162 if tbmods > 0 { 4163 cw_fnd(fbuf, fpos, 5, "bounds-law/tree" as *u8, "Taste-bound consts present: cap/max constants lack measurement provenance in the adjacent comment; apply the bounds law (derive from a measured table or scale with the input; when a bound bites the fix is architecture, never a different number). Standing gauge: https://nishifamily.com/code/debt" as *u8) 4164 } 4165 // substring-classifier gauge (2026-07-30): the class that produced four 4166 // separate defects in one day, now a standing measurement instead of a 4167 // lesson somebody has to remember. 4168 var sccnt: i64 = 0 4169 var scmods: i64 = 0 4170 var sc0: i64 = 0 4171 while sc0 < nsorted { 4172 let scv: i64 = sidx[sc0] 4173 if subclv[scv] > 0 { scmods = scmods + 1; sccnt = sccnt + subclv[scv] } 4174 sc0 = sc0 + 1 4175 } 4176 cw_apps(page, pos, CW_PAGECAP, "<h2>substring classifiers <span class='cnt' data-subcl='" as *u8) 4177 cw_appn(page, pos, CW_PAGECAP, sccnt) 4178 cw_apps(page, pos, CW_PAGECAP, "'>" as *u8) 4179 cw_appn(page, pos, CW_PAGECAP, sccnt) 4180 cw_apps(page, pos, CW_PAGECAP, " decisions in " as *u8) 4181 cw_appn(page, pos, CW_PAGECAP, scmods) 4182 cw_apps(page, pos, CW_PAGECAP, " modules &middot; goal FALLING &middot; first " as *u8) 4183 cw_appn(page, pos, CW_PAGECAP, CW_CATSHOW) 4184 cw_apps(page, pos, CW_PAGECAP, " shown</span></h2>\n<p class='muted'>lines that both TEST a substring and DECIDE on it (a contains/hastok call, a quoted literal, and a verdict on the same line). <b>A substring standing in for a property</b> cost four separate defects on 2026-07-30 alone, sev 5 to 9: a documented CWE <i>prevention</i> filed as a hazard; the edge SSOT <code>nx_sites_daemon_v2</code> flagged as a stale copy because its name carries <code>_v2</code>; the one-shot worker <code>nx_torrent_get</code> classified a daemon by the substring <code>torrent</code>, leaving it unshippable by any sanctioned verb; and route matching reading BODY bytes as a request line. A needle cannot tell a thing from a MENTION of a thing. Locating a substring is fine &mdash; classifying by one is the smell; read the structure instead (parse the field, declare the role in data, bound the scan).</p>\n<p>" as *u8) 4185 var scs: i64 = 0 4186 var sc1: i64 = 0 4187 while sc1 < nsorted { 4188 let scw: i64 = sidx[sc1] 4189 if subclv[scw] > 0 { if scs < CW_CATSHOW { 4190 cw_apps(page, pos, CW_PAGECAP, "<span class='pill'>" as *u8) 4191 cw_applink2(page, pos, CW_PAGECAP, ((g.arena as i64) + g.node_off[scw]) as *u8, noext) 4192 cw_apps(page, pos, CW_PAGECAP, "</span>" as *u8) 4193 scs = scs + 1 4194 } } 4195 sc1 = sc1 + 1 4196 } 4197 if scmods == 0 { cw_apps(page, pos, CW_PAGECAP, "<span class='muted'>none detected</span>" as *u8) } 4198 if scmods > CW_CATSHOW { cw_apps(page, pos, CW_PAGECAP, " <span class='muted'>+" as *u8); cw_appn(page, pos, CW_PAGECAP, scmods - CW_CATSHOW); cw_apps(page, pos, CW_PAGECAP, " more</span>" as *u8) } 4199 cw_apps(page, pos, CW_PAGECAP, "</p>\n" as *u8) 4200 if scmods > 0 { 4201 cw_fnd(fbuf, fpos, 5, "substring-classifier/tree" as *u8, "Substring classifiers present: a line that tests a substring AND decides on it. A needle cannot distinguish a thing from a mention of a thing -- this exact shape produced four defects (sev 5-9) on 2026-07-30: a documented CWE prevention filed as a hazard, the edge SSOT flagged as a stale copy for carrying _v2, a one-shot worker classified a daemon by name and left unshippable, and route matching reading body bytes as a request line. Read the structure instead: parse the field, declare the role in data, bound the scan. Standing gauge: https://nishifamily.com/code/debt" as *u8) 4202 } 4203 cw_apps(page, pos, CW_PAGECAP, "<p class='muted'>markers are conservative substrings (landmine/footgun/dual-copy, workaround/hack/kludge, gotcha/trap/caveat, todo/fixme, third-party/foreign, cwe-/vuln/exploit, quadratic/O(n^2), deprecated/retire). A module can appear under several categories.</p>\n" as *u8) 4204 cw_foot(page, pos, CW_PAGECAP) 4205 cw_outpath(opath, outdir, "debt.html" as *u8) 4206 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 4207 if pos[1] == 1 { truncs = truncs + 1 } 4208 4209 // ===== pass 3k: sovereignty ladder -- from the first byte up ===== 4210 // Each rung is a layer of the stack; "sovereign" = built first-byte-up in 4211 // NishiLang with no foreign dependency. We MEASURE the tree's coverage of 4212 // each rung (modules whose family/name matches the rung's markers) and 4213 // FILE a finding for any rung that is a known gap -- the ladder itself 4214 // becomes backlog. HARDWARE is the lowest rung by doctrine (rule 26). 4215 pos[0] = 0 4216 pos[1] = 0 4217 cw_head3(page, pos, CW_PAGECAP, "sovereignty" as *u8, 11, sbbuf) 4218 cw_crumb(page, pos, CW_PAGECAP, noext, 0 as *u8, 0 as *u8, "sovereignty" as *u8, 11) 4219 cw_apps(page, pos, CW_PAGECAP, "<h1>the sovereignty ladder</h1>\n<p class='muted'>from the first byte up. Sovereign = built in NishiLang with no foreign dependency. Each rung shows the modules in this tree that implement it; a thin rung is where sovereignty is still owed, and it feeds the backlog.</p>\n<table><tr><th>rung</th><th class='n'>modules here</th><th>representative</th><th>status</th></tr>\n" as *u8) 4220 // rung markers: name-substring that identifies a rung's modules 4221 let RUNGN: i64 = 10 4222 let rname: *i64 = sys_mmap(RUNGN * 8) as *i64 4223 let rmark: *i64 = sys_mmap(RUNGN * 8) as *i64 4224 rname[0] = "hardware / firmware (CMOS, POST, never-brick)" as *u8 as i64; rmark[0] = "firmware" as *u8 as i64 4225 rname[1] = "boot / kernel / syscalls" as *u8 as i64; rmark[1] = "syscall" as *u8 as i64 4226 rname[2] = "compiler / assembler (nx_cc, nxasm)" as *u8 as i64; rmark[2] = "nxasm" as *u8 as i64 4227 rname[3] = "TLS / crypto" as *u8 as i64; rmark[3] = "tls" as *u8 as i64 4228 rname[4] = "HTTP / web edge" as *u8 as i64; rmark[4] = "http" as *u8 as i64 4229 rname[5] = "storage / data plane" as *u8 as i64; rmark[5] = "store" as *u8 as i64 4230 rname[6] = "model / inference" as *u8 as i64; rmark[6] = "llm" as *u8 as i64 4231 rname[7] = "graphics / video" as *u8 as i64; rmark[7] = "vcodec" as *u8 as i64 4232 rname[8] = "browser" as *u8 as i64; rmark[8] = "browser" as *u8 as i64 4233 rname[9] = "management / deploy" as *u8 as i64; rmark[9] = "mgmt" as *u8 as i64 4234 var ru: i64 = 0 4235 while ru < RUNGN { 4236 let mk: *u8 = rmark[ru] as *u8 4237 var cnt: i64 = 0 4238 var rep: i64 = 0 - 1 4239 var rq: i64 = 0 4240 while rq < nsorted { 4241 let rvv: i64 = sidx[rq] 4242 let rnm: *u8 = ((g.arena as i64) + g.node_off[rvv]) as *u8 4243 if cw_namehas(rnm, mk) == 1 { 4244 cnt = cnt + 1 4245 if rep < 0 { rep = rvv } else { if g.ca_arr[rvv] > g.ca_arr[rep] { rep = rvv } } 4246 } 4247 rq = rq + 1 4248 } 4249 cw_apps(page, pos, CW_PAGECAP, "<tr><td>" as *u8) 4250 cw_apps(page, pos, CW_PAGECAP, rname[ru] as *u8) 4251 cw_apps(page, pos, CW_PAGECAP, "</td><td class='n'>" as *u8) 4252 cw_appn(page, pos, CW_PAGECAP, cnt) 4253 cw_apps(page, pos, CW_PAGECAP, "</td><td>" as *u8) 4254 if rep >= 0 { cw_applink2(page, pos, CW_PAGECAP, ((g.arena as i64) + g.node_off[rep]) as *u8, noext) } else { cw_apps(page, pos, CW_PAGECAP, "<span class='muted'>none</span>" as *u8) } 4255 cw_apps(page, pos, CW_PAGECAP, "</td><td>" as *u8) 4256 if cnt == 0 { 4257 cw_apps(page, pos, CW_PAGECAP, "<b style='color:var(--acc2)'>gap &mdash; sovereignty owed</b>" as *u8) 4258 } else { 4259 cw_apps(page, pos, CW_PAGECAP, "sovereign (" as *u8) 4260 cw_appn(page, pos, CW_PAGECAP, cnt) 4261 cw_apps(page, pos, CW_PAGECAP, " modules)" as *u8) 4262 } 4263 cw_apps(page, pos, CW_PAGECAP, "</td></tr>\n" as *u8) 4264 // the hardware rung is doctrine-critical: file it if thin 4265 if ru == 0 { if cnt == 0 { 4266 cw_fnd(fbuf, fpos, 7, "sovereignty" as *u8, 4267 "The hardware/firmware rung shows no modules in the tree -- the first-byte-up hardware sovereignty (rule 26, CMOS/POST/never-brick) is not yet represented as measurable organs. https://nishifamily.com/code/sovereignty" as *u8) 4268 } } 4269 ru = ru + 1 4270 } 4271 cw_apps(page, pos, CW_PAGECAP, "</table>\n<p class='muted'>the goal is every rung sovereign from the first byte up; a gap here is a program, not a bug -- but it is TRACKED here so it is never invisible.</p>\n" as *u8) 4272 cw_foot(page, pos, CW_PAGECAP) 4273 cw_outpath(opath, outdir, "sovereignty.html" as *u8) 4274 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 4275 if pos[1] == 1 { truncs = truncs + 1 } 4276 4277 // ===== sotaplan.html: the SOTA ladder -- KEEPS THE SIDEBAR PROMISE ===== 4278 // The sidebar has linked 'sotaplan' since rung 23 with NO emission behind 4279 // it, so every generated page carried a dead link. A SIDEBAR LINK IS A 4280 // PROMISE THE GENERATOR MUST KEEP; a link without an emission is a 404 4281 // multiplied by the page count. Content is deliberately POINTER-ONLY: the 4282 // measured inputs already live on findings/debt/atlas/sovereignty/exposure, 4283 // and restating a number here would create a second source of truth that 4284 // drifts (the publishing-plane law). 4285 pos[0] = 0 4286 pos[1] = 0 4287 cw_head3(page, pos, CW_PAGECAP, "sotaplan" as *u8, 8, sbbuf) 4288 cw_crumb(page, pos, CW_PAGECAP, noext, 0 as *u8, 0 as *u8, "sotaplan" as *u8, 8) 4289 cw_apps(page, pos, CW_PAGECAP, "<h1>the SOTA plan</h1>\n<p class='muted'>What state of the art means here, and where the ecosystem measurably is not there yet. Every input below is measured elsewhere in this wiki and LINKED, never restated -- a number copied here would be a second source of truth that drifts.</p>\n<table><tr><th>rung</th><th>the measured input</th></tr>\n<tr><td>Open work, ranked</td><td><a href='findings'>findings</a> -- the backlog the generator files against itself</td></tr>\n<tr><td>Debt by category</td><td><a href='debt'>debt taxonomy</a> -- landmines, workarounds, gotchas, third-party, security, perf</td></tr>\n<tr><td>Organisation</td><td><a href='atlas'>atlas</a> -- family to domain conformance; extend the conf, never the generator</td></tr>\n<tr><td>First-byte-up sovereignty</td><td><a href='sovereignty'>sovereignty ladder</a> -- a thin rung is sovereignty owed</td></tr>\n<tr><td>Reach</td><td><a href='exposure'>exposure</a> -- what is callable over MCP/API versus deployed but dark</td></tr>\n<tr><td>External frontier</td><td><a href='research'>research briefs</a> -- sourced, dated SOTA censuses with declared gaps</td></tr>\n</table>\n<p class='muted'>The plan is the join of those six: what is broken (findings, debt), what is disorganised (atlas), what is not ours yet (sovereignty), what nobody can reach (exposure), and where the outside world actually is (research).</p>\n" as *u8) 4290 cw_foot(page, pos, CW_PAGECAP) 4291 cw_outpath(opath, outdir, "sotaplan.html" as *u8) 4292 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 4293 if pos[1] == 1 { truncs = truncs + 1 } 4294 4295 // ===== atlas.html: the family -> domain conformance ruler (seq1220) ===== 4296 pos[0] = 0 4297 pos[1] = 0 4298 cw_head3(page, pos, CW_PAGECAP, "atlas" as *u8, 5, sbbuf) 4299 cw_crumb(page, pos, CW_PAGECAP, noext, 0 as *u8, 0 as *u8, "atlas" as *u8, 5) 4300 cw_apps(page, pos, CW_PAGECAP, "<h1>atlas: families mapped to ecosystem domains</h1>\n<p class='muted'>the tree's naming discipline (nx_&lt;family&gt;_*) joined to the DECLARED family-to-domain mapping conf (knowledge/codewiki_atlas.conf). Extend the conf to raise conformance -- never rebuild the generator (rule 11). Unmapped families are the work list, biggest LOC first; stale rows are declared, never dropped silently.</p>\n" as *u8) 4301 cw_atlas(page, pos, CW_PAGECAP, famarena, famoff, famlen, famcnt, famloc, nfam, atlaspath, noext, fbuf, fpos) 4302 cw_foot(page, pos, CW_PAGECAP) 4303 cw_outpath(opath, outdir, "atlas.html" as *u8) 4304 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 4305 if pos[1] == 1 { truncs = truncs + 1 } 4306 4307 // ===== findings.tsv + findings.html: emitted LAST so every detector (census, 4308 // exposure, sovereignty) has contributed. findings.tsv IS the backlog feed 4309 // (exactly the rows the debt bridge files); findings.html is its human view. 4310 var nfind: i64 = 0 4311 var nfi: i64 = 0 4312 while nfi < fpos[0] { if fbuf[nfi] == (10 as u8) { nfind = nfind + 1 } nfi = nfi + 1 } 4313 st[21] = nfind 4314 cw_outpath(opath, outdir, "findings.tsv" as *u8) 4315 if cw_flush(opath, fbuf, fpos, CW_FINDCAP) == 0 { pages = pages + 1 } 4316 4317 pos[0] = 0 4318 pos[1] = 0 4319 cw_head3(page, pos, CW_PAGECAP, "findings" as *u8, 8, sbbuf) 4320 cw_crumb(page, pos, CW_PAGECAP, noext, 0 as *u8, 0 as *u8, "findings" as *u8, 8) 4321 cw_apps(page, pos, CW_PAGECAP, "<h1>findings: the wiki's own work backlog</h1>\n<p class='muted'>each regeneration runs the detectors; every finding is filed into the debt board with a stable description (idempotent -- refiling the same finding is a no-op). Fix the issue and the next regen drops the finding. This is the loop: code &rarr; wiki &rarr; findings &rarr; backlog &rarr; work &rarr; code.</p>\n<table><tr><th class='n'>sev</th><th>scope</th><th>finding</th></tr>\n" as *u8) 4322 var fls: i64 = 0 4323 while fls < fpos[0] { 4324 var fle: i64 = fls 4325 var fg: i64 = 1 4326 while fg == 1 { if fle >= fpos[0] { fg = 0 } else { if fbuf[fle] == (10 as u8) { fg = 0 } else { fle = fle + 1 } } } 4327 if fle > fls { 4328 let s1: i64 = cw_fld(fbuf, fls, fle) 4329 let s2s: i64 = s1 + 1 4330 let s2e: i64 = cw_fld(fbuf, s2s, fle) 4331 cw_apps(page, pos, CW_PAGECAP, "<tr><td class='n'>" as *u8) 4332 cw_appe(page, pos, CW_PAGECAP, ((fbuf as i64) + fls) as *u8, s1 - fls) 4333 cw_apps(page, pos, CW_PAGECAP, "</td><td class='muted'>" as *u8) 4334 cw_appe(page, pos, CW_PAGECAP, ((fbuf as i64) + s2s) as *u8, s2e - s2s) 4335 cw_apps(page, pos, CW_PAGECAP, "</td><td>" as *u8) 4336 if s2e + 1 < fle { cw_appe(page, pos, CW_PAGECAP, ((fbuf as i64) + s2e + 1) as *u8, fle - s2e - 1) } 4337 cw_apps(page, pos, CW_PAGECAP, "</td></tr>\n" as *u8) 4338 } 4339 fls = fle + 1 4340 } 4341 if nfind == 0 { cw_apps(page, pos, CW_PAGECAP, "<tr><td colspan='3' class='muted'>no open findings -- the detectors are all green</td></tr>" as *u8) } 4342 cw_apps(page, pos, CW_PAGECAP, "</table>\n" as *u8) 4343 cw_foot(page, pos, CW_PAGECAP) 4344 cw_outpath(opath, outdir, "findings.html" as *u8) 4345 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 4346 if pos[1] == 1 { truncs = truncs + 1 } 4347 4348 // ===== pass 3b: index ===== 4349 pos[0] = 0 4350 pos[1] = 0 4351 cw_head3(page, pos, CW_PAGECAP, "index" as *u8, 5, sbbuf) 4352 cw_apps(page, pos, CW_PAGECAP, "<h1>nishi code wiki</h1>\n<p class='muted'>generated from the source tree; every number below is measured, not asserted.</p>\n<p><a class='cta' href='search" as *u8) 4353 cw_appext(page, pos, CW_PAGECAP, noext) 4354 cw_apps(page, pos, CW_PAGECAP, "'>&#128269; Search " as *u8) 4355 cw_appn(page, pos, CW_PAGECAP, st[12]) 4356 cw_apps(page, pos, CW_PAGECAP, " functions</a> <a class='cta' style='background:var(--acc2)' href='topics" as *u8) 4357 cw_appext(page, pos, CW_PAGECAP, noext) 4358 cw_apps(page, pos, CW_PAGECAP, "'>&#128218; Browse topics</a> <a class='cta' href='ask" as *u8) 4359 cw_appext(page, pos, CW_PAGECAP, noext) 4360 cw_apps(page, pos, CW_PAGECAP, "'>&#128172; Ask (local AI)</a></p>\n<div class='tiles'>" as *u8) 4361 cw_apps(page, pos, CW_PAGECAP, "<div class='tile'><div class='v'>" as *u8) 4362 cw_appn(page, pos, CW_PAGECAP, st[0]) 4363 cw_apps(page, pos, CW_PAGECAP, "</div><div class='k'>modules</div></div><div class='tile'><div class='v'>" as *u8) 4364 cw_appn(page, pos, CW_PAGECAP, st[2]) 4365 cw_apps(page, pos, CW_PAGECAP, "</div><div class='k'>import edges</div></div><div class='tile'><div class='v'>" as *u8) 4366 cw_appn(page, pos, CW_PAGECAP, st[3]) 4367 cw_apps(page, pos, CW_PAGECAP, "</div><div class='k'>functions</div></div><div class='tile'><div class='v'>" as *u8) 4368 cw_appn(page, pos, CW_PAGECAP, st[4]) 4369 cw_apps(page, pos, CW_PAGECAP, "</div><div class='k'>structs</div></div><div class='tile'><div class='v'>" as *u8) 4370 cw_appn(page, pos, CW_PAGECAP, st[5]) 4371 cw_apps(page, pos, CW_PAGECAP, "</div><div class='k'>consts</div></div><div class='tile'><div class='v'>" as *u8) 4372 if st[9] == 0 { cw_apps(page, pos, CW_PAGECAP, "DAG" as *u8) } else { cw_apps(page, pos, CW_PAGECAP, "CYCLE" as *u8) } 4373 cw_apps(page, pos, CW_PAGECAP, "</div><div class='k'>import graph</div></div></div>\n<p class='muted'>unresolved import targets: " as *u8) 4374 cw_appn(page, pos, CW_PAGECAP, st[6]) 4375 cw_apps(page, pos, CW_PAGECAP, " &middot; tree stamp (content-derived): " as *u8) 4376 cw_appn(page, pos, CW_PAGECAP, st[8]) 4377 cw_apps(page, pos, CW_PAGECAP, "</p>\n" as *u8) 4378 cw_nar_include(page, pos, CW_PAGECAP, outdir, opath, "index" as *u8) 4379 4380 cw_apps(page, pos, CW_PAGECAP, "<h2>directories</h2>\n<table>" as *u8) 4381 var d4: i64 = 0 4382 while d4 < ndirs { 4383 let dl2: *u8 = ((dirarena as i64) + dirnoff[d4]) as *u8 4384 let sl2: *u8 = ((dirarena as i64) + dirslug[d4]) as *u8 4385 cw_apps(page, pos, CW_PAGECAP, "<tr><td><a href='" as *u8) 4386 cw_apps(page, pos, CW_PAGECAP, sl2) 4387 cw_appext(page, pos, CW_PAGECAP, noext) 4388 cw_apps(page, pos, CW_PAGECAP, "'>" as *u8) 4389 if cw_slen(dl2) == 0 { cw_apps(page, pos, CW_PAGECAP, "(root)" as *u8) } else { cw_appe(page, pos, CW_PAGECAP, dl2, cw_slen(dl2)) } 4390 cw_apps(page, pos, CW_PAGECAP, "</a></td><td class='n'>" as *u8) 4391 cw_appn(page, pos, CW_PAGECAP, dircnt[d4]) 4392 cw_apps(page, pos, CW_PAGECAP, "</td></tr>\n" as *u8) 4393 d4 = d4 + 1 4394 } 4395 cw_apps(page, pos, CW_PAGECAP, "</table>\n" as *u8) 4396 4397 // hubs: top-K by fan-in among file nodes, then top-K by fan-out 4398 let hk: *i64 = sys_mmap((CW_TOPK + 2) * 8) as *i64 4399 let hv: *i64 = sys_mmap((CW_TOPK + 2) * 8) as *i64 4400 var hn: i64 = 0 4401 var s4i: i64 = 0 4402 while s4i < nsorted { 4403 let v4: i64 = sidx[s4i] 4404 if pathoff[v4] > 0 { 4405 let ca: i64 = g.ca_arr[v4] 4406 var ins: i64 = 0 - 1 4407 if hn < CW_TOPK { ins = hn; hk[hn] = v4; hv[hn] = ca; hn = hn + 1 } 4408 if ins < 0 { if ca > hv[CW_TOPK - 1] { ins = CW_TOPK - 1; hk[ins] = v4; hv[ins] = ca } } 4409 var q3: i64 = ins 4410 while q3 > 0 { 4411 if hv[q3 - 1] < hv[q3] { 4412 let t5: i64 = hv[q3-1]; hv[q3-1] = hv[q3]; hv[q3] = t5 4413 let t6: i64 = hk[q3-1]; hk[q3-1] = hk[q3]; hk[q3] = t6 4414 q3 = q3 - 1 4415 } else { q3 = 0 } 4416 } 4417 } 4418 s4i = s4i + 1 4419 } 4420 cw_apps(page, pos, CW_PAGECAP, "<h2>most imported (load-bearing modules, top " as *u8) 4421 cw_appn(page, pos, CW_PAGECAP, CW_TOPK) 4422 cw_apps(page, pos, CW_PAGECAP, " declared)</h2>\n<table><tr><th>module</th><th class='n'>importers</th></tr>\n" as *u8) 4423 var r1: i64 = 0 4424 while r1 < hn { 4425 if hv[r1] > 0 { 4426 let hnm: *u8 = ((g.arena as i64) + g.node_off[hk[r1]]) as *u8 4427 cw_apps(page, pos, CW_PAGECAP, "<tr><td>" as *u8) 4428 cw_applink2(page, pos, CW_PAGECAP, hnm, noext) 4429 cw_apps(page, pos, CW_PAGECAP, "</td><td class='n'>" as *u8) 4430 cw_appn(page, pos, CW_PAGECAP, hv[r1]) 4431 cw_apps(page, pos, CW_PAGECAP, "</td></tr>\n" as *u8) 4432 } 4433 r1 = r1 + 1 4434 } 4435 cw_apps(page, pos, CW_PAGECAP, "</table>\n" as *u8) 4436 4437 var hn2: i64 = 0 4438 var s5i: i64 = 0 4439 while s5i < nsorted { 4440 let v5: i64 = sidx[s5i] 4441 if pathoff[v5] > 0 { 4442 let ce: i64 = g.ce_arr[v5] 4443 var ins2: i64 = 0 - 1 4444 if hn2 < CW_TOPK { ins2 = hn2; hk[hn2] = v5; hv[hn2] = ce; hn2 = hn2 + 1 } 4445 if ins2 < 0 { if ce > hv[CW_TOPK - 1] { ins2 = CW_TOPK - 1; hk[ins2] = v5; hv[ins2] = ce } } 4446 var q4: i64 = ins2 4447 while q4 > 0 { 4448 if hv[q4 - 1] < hv[q4] { 4449 let t7: i64 = hv[q4-1]; hv[q4-1] = hv[q4]; hv[q4] = t7 4450 let t8: i64 = hk[q4-1]; hk[q4-1] = hk[q4]; hk[q4] = t8 4451 q4 = q4 - 1 4452 } else { q4 = 0 } 4453 } 4454 } 4455 s5i = s5i + 1 4456 } 4457 cw_apps(page, pos, CW_PAGECAP, "<h2>widest importers (composition roots, top " as *u8) 4458 cw_appn(page, pos, CW_PAGECAP, CW_TOPK) 4459 cw_apps(page, pos, CW_PAGECAP, " declared)</h2>\n<table><tr><th>module</th><th class='n'>imports</th></tr>\n" as *u8) 4460 var r2: i64 = 0 4461 while r2 < hn2 { 4462 if hv[r2] > 0 { 4463 let hnm2: *u8 = ((g.arena as i64) + g.node_off[hk[r2]]) as *u8 4464 cw_apps(page, pos, CW_PAGECAP, "<tr><td>" as *u8) 4465 cw_applink2(page, pos, CW_PAGECAP, hnm2, noext) 4466 cw_apps(page, pos, CW_PAGECAP, "</td><td class='n'>" as *u8) 4467 cw_appn(page, pos, CW_PAGECAP, hv[r2]) 4468 cw_apps(page, pos, CW_PAGECAP, "</td></tr>\n" as *u8) 4469 } 4470 r2 = r2 + 1 4471 } 4472 cw_apps(page, pos, CW_PAGECAP, "</table>\n" as *u8) 4473 4474 // unresolved import targets (honesty section) 4475 if st[6] > 0 { 4476 cw_apps(page, pos, CW_PAGECAP, "<h2>unresolved import targets (first 20)</h2>\n<p class='muted'>imported by modules in this tree but not found under this root -- generated files, other trees, or genuine dead imports.</p>\n<table><tr><th>name</th><th class='n'>importers</th></tr>\n" as *u8) 4477 var shown2: i64 = 0 4478 var u1: i64 = 0 4479 while u1 < g.node_count { 4480 if pathoff[u1] == 0 { if shown2 < 20 { 4481 let unm: *u8 = ((g.arena as i64) + g.node_off[u1]) as *u8 4482 cw_apps(page, pos, CW_PAGECAP, "<tr><td class='ext'>" as *u8) 4483 cw_appe(page, pos, CW_PAGECAP, unm, cw_slen(unm)) 4484 cw_apps(page, pos, CW_PAGECAP, "</td><td class='n'>" as *u8) 4485 cw_appn(page, pos, CW_PAGECAP, g.ca_arr[u1]) 4486 cw_apps(page, pos, CW_PAGECAP, "</td></tr>\n" as *u8) 4487 shown2 = shown2 + 1 4488 } } 4489 u1 = u1 + 1 4490 } 4491 cw_apps(page, pos, CW_PAGECAP, "</table>\n" as *u8) 4492 } 4493 4494 cw_foot(page, pos, CW_PAGECAP) 4495 var w3: i64 = 0 4496 var i6: i64 = 0 4497 while outdir[i6] != (0 as u8) { opath[w3] = outdir[i6]; w3 = w3 + 1; i6 = i6 + 1 } 4498 opath[w3] = 47 as u8; w3 = w3 + 1 4499 cw_rawcpy(opath, w3, "index.html" as *u8) 4500 w3 = w3 + 10 4501 opath[w3] = 0 as u8 4502 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 4503 if pos[1] == 1 { truncs = truncs + 1 } 4504 4505 // ===== pass 3c: search indexes (modindex.js + fnindex.js) ===== 4506 // Client-side symbol search: no daemon, no third-party lib -- two generated 4507 // JS arrays a plain page filters. Sizes declared on the search page. 4508 pos[0] = 0 4509 pos[1] = 0 4510 cw_apps(page, pos, CW_PAGECAP, "var MODS=[" as *u8) 4511 var m1: i64 = 0 4512 while m1 < nsorted { 4513 let mv: i64 = sidx[m1] 4514 let mnm: *u8 = ((g.arena as i64) + g.node_off[mv]) as *u8 4515 cw_apps(page, pos, CW_PAGECAP, "[\"" as *u8) 4516 cw_appstem(page, pos, CW_PAGECAP, mnm) 4517 cw_apps(page, pos, CW_PAGECAP, "\",\"" as *u8) 4518 let mdl: *u8 = ((dirarena as i64) + dirnoff[fdir[mv]]) as *u8 4519 cw_appjse(page, pos, CW_PAGECAP, mdl, cw_slen(mdl)) 4520 cw_apps(page, pos, CW_PAGECAP, "\",\"" as *u8) 4521 if dlen[mv] > 0 { cw_appjse(page, pos, CW_PAGECAP, ((descarena as i64) + doff[mv]) as *u8, dlen[mv]) } 4522 cw_apps(page, pos, CW_PAGECAP, "\"," as *u8) 4523 cw_appn(page, pos, CW_PAGECAP, floc[mv]) 4524 cw_apps(page, pos, CW_PAGECAP, "," as *u8) 4525 cw_appn(page, pos, CW_PAGECAP, fnfn[mv]) 4526 cw_apps(page, pos, CW_PAGECAP, ",\"" as *u8) 4527 cw_apps(page, pos, CW_PAGECAP, cw_kindname(kindv[mv])) 4528 cw_apps(page, pos, CW_PAGECAP, "\"],\n" as *u8) 4529 m1 = m1 + 1 4530 } 4531 cw_apps(page, pos, CW_PAGECAP, "];\n" as *u8) 4532 cw_outpath(opath, outdir, "modindex.js" as *u8) 4533 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 4534 if pos[1] == 1 { truncs = truncs + 1 } 4535 4536 pos[0] = 0 4537 pos[1] = 0 4538 cw_apps(page, pos, CW_PAGECAP, "var FNS=[" as *u8) 4539 var f1: i64 = 0 4540 while f1 < nfns { 4541 cw_apps(page, pos, CW_PAGECAP, "[\"" as *u8) 4542 cw_app(page, pos, CW_PAGECAP, ((fnarena as i64) + fnoff[f1]) as *u8, fnlen[f1]) 4543 cw_apps(page, pos, CW_PAGECAP, "\",\"" as *u8) 4544 let fmn: *u8 = ((g.arena as i64) + g.node_off[fnmod[f1]]) as *u8 4545 cw_appstem(page, pos, CW_PAGECAP, fmn) 4546 cw_apps(page, pos, CW_PAGECAP, "\"," as *u8) 4547 cw_appn(page, pos, CW_PAGECAP, fnline[f1]) 4548 cw_apps(page, pos, CW_PAGECAP, "],\n" as *u8) 4549 f1 = f1 + 1 4550 } 4551 cw_apps(page, pos, CW_PAGECAP, "];\n" as *u8) 4552 cw_outpath(opath, outdir, "fnindex.js" as *u8) 4553 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 4554 if pos[1] == 1 { truncs = truncs + 1 } 4555 4556 // askindex.tsv -- the RETRIEVAL corpus (one flat file, one read): 4557 // M <TAB> stem <TAB> dir <TAB> loc <TAB> funcs <TAB> desc 4558 // F <TAB> fname <TAB> modstem <TAB> line 4559 // T <TAB> tool <TAB> schema-title <TAB> argv-grammar (capabilities -- 4560 // rung 23, the organ-side half of the discoverability law) 4561 // Tabs/newlines inside a desc are mapped to spaces so the format cannot 4562 // be broken by source text (cw_apptsv). 4563 let abuf: *u8 = sys_mmap(CW_ASKIDXCAP) 4564 let apos: *i64 = sys_mmap(32) as *i64 4565 apos[0] = 0 4566 apos[1] = 0 4567 var arecs: i64 = 0 4568 var a1: i64 = 0 4569 while a1 < nsorted { 4570 let av: i64 = sidx[a1] 4571 let anm: *u8 = ((g.arena as i64) + g.node_off[av]) as *u8 4572 cw_apps(abuf, apos, CW_ASKIDXCAP, "M\t" as *u8) 4573 cw_appstem(abuf, apos, CW_ASKIDXCAP, anm) 4574 cw_apps(abuf, apos, CW_ASKIDXCAP, "\t" as *u8) 4575 let adl: *u8 = ((dirarena as i64) + dirnoff[fdir[av]]) as *u8 4576 cw_apptsv(abuf, apos, CW_ASKIDXCAP, adl, cw_slen(adl)) 4577 cw_apps(abuf, apos, CW_ASKIDXCAP, "\t" as *u8) 4578 cw_appn(abuf, apos, CW_ASKIDXCAP, floc[av]) 4579 cw_apps(abuf, apos, CW_ASKIDXCAP, "\t" as *u8) 4580 cw_appn(abuf, apos, CW_ASKIDXCAP, fnfn[av]) 4581 cw_apps(abuf, apos, CW_ASKIDXCAP, "\t" as *u8) 4582 if dlen[av] > 0 { cw_apptsv(abuf, apos, CW_ASKIDXCAP, ((descarena as i64) + doff[av]) as *u8, dlen[av]) } 4583 cw_apps(abuf, apos, CW_ASKIDXCAP, "\t" as *u8) 4584 if sdlen[av] > 0 { cw_apptsv(abuf, apos, CW_ASKIDXCAP, ((sdocarena as i64) + sdoff[av]) as *u8, sdlen[av]) } 4585 cw_apps(abuf, apos, CW_ASKIDXCAP, "\n" as *u8) 4586 arecs = arecs + 1 4587 a1 = a1 + 1 4588 } 4589 var a2: i64 = 0 4590 while a2 < nfns { 4591 cw_apps(abuf, apos, CW_ASKIDXCAP, "F\t" as *u8) 4592 cw_app(abuf, apos, CW_ASKIDXCAP, ((fnarena as i64) + fnoff[a2]) as *u8, fnlen[a2]) 4593 cw_apps(abuf, apos, CW_ASKIDXCAP, "\t" as *u8) 4594 let afm: *u8 = ((g.arena as i64) + g.node_off[fnmod[a2]]) as *u8 4595 cw_appstem(abuf, apos, CW_ASKIDXCAP, afm) 4596 cw_apps(abuf, apos, CW_ASKIDXCAP, "\t" as *u8) 4597 cw_appn(abuf, apos, CW_ASKIDXCAP, fnline[a2]) 4598 cw_apps(abuf, apos, CW_ASKIDXCAP, "\n" as *u8) 4599 arecs = arecs + 1 4600 a2 = a2 + 1 4601 } 4602 // T-rows: every registered capability joins the retrieval corpus, so the 4603 // organ-side ask can serve "which tool does X" (rung 23). Same live confs 4604 // the catalog page reads; a missing conf just contributes zero rows. 4605 let atr: i64 = cw_asktools(abuf, apos, CW_ASKIDXCAP, allowpath, schemapath) 4606 arecs = arecs + atr 4607 cw_outpath(opath, outdir, "askindex.tsv" as *u8) 4608 if cw_flush(opath, abuf, apos, CW_ASKIDXCAP) == 0 { pages = pages + 1 } 4609 st[16] = arecs 4610 st[17] = apos[1] 4611 if apos[1] == 1 { truncs = truncs + 1 } 4612 4613 // ===== pass 3d: search.html ===== 4614 pos[0] = 0 4615 pos[1] = 0 4616 cw_head3(page, pos, CW_PAGECAP, "search" as *u8, 6, sbbuf) 4617 cw_crumb(page, pos, CW_PAGECAP, noext, 0 as *u8, 0 as *u8, "search" as *u8, 6) 4618 cw_apps(page, pos, CW_PAGECAP, "<h1>search the code wiki</h1>\n<p class='muted'>" as *u8) 4619 cw_appn(page, pos, CW_PAGECAP, nsorted) 4620 cw_apps(page, pos, CW_PAGECAP, " modules and " as *u8) 4621 cw_appn(page, pos, CW_PAGECAP, nfns) 4622 cw_apps(page, pos, CW_PAGECAP, " functions, filtered in your browser (no server round-trip).</p>\n" as *u8) 4623 cw_apps(page, pos, CW_PAGECAP, "<input id='q' placeholder='module, function, or capability...' oninput='go()' autofocus style='width:420px'>\n<div id='out'></div>\n<script src='modindex.js'></script><script src='fnindex.js'></script><script src='toolindex.js'></script>\n<script>\n" as *u8) 4624 if noext == 0 { cw_apps(page, pos, CW_PAGECAP, "var EXT=\".html\";\n" as *u8) } else { cw_apps(page, pos, CW_PAGECAP, "var EXT=\"\";\n" as *u8) } 4625 cw_apps(page, pos, CW_PAGECAP, "function row(h){return \"<tr>\"+h+\"</tr>\"}\n" as *u8) 4626 cw_apps(page, pos, CW_PAGECAP, "function go(){var q=document.getElementById(\"q\").value.toLowerCase();var o=document.getElementById(\"out\");if(q.length<2){o.innerHTML=\"\";return}\n" as *u8) 4627 cw_apps(page, pos, CW_PAGECAP, "var mh=\"\";var mc=0;for(var i=0;i<MODS.length&&mc<40;i++){var r=MODS[i];if(r[0].indexOf(q)>=0||r[2].toLowerCase().indexOf(q)>=0){mc++;mh+=row(\"<td><a href='\"+r[0]+EXT+\"'>\"+r[0]+\"</a> <span class='muted'>[\"+(r[5]||\"\")+\"]</span></td><td class='muted'>\"+r[2]+\"</td><td class='n'>\"+r[3]+\" loc</td>\")}}\n" as *u8) 4628 cw_apps(page, pos, CW_PAGECAP, "var fh=\"\";var fc=0;for(var j=0;j<FNS.length&&fc<60;j++){var s=FNS[j];if(s[0].toLowerCase().indexOf(q)>=0){fc++;fh+=row(\"<td><a href='\"+s[1]+EXT+\"#fn_\"+s[0]+\"'>\"+s[0]+\"</a></td><td class='muted'>\"+s[1]+\"</td><td class='n'>line \"+s[2]+\"</td>\")}}\n" as *u8) 4629 cw_apps(page, pos, CW_PAGECAP, "var th2=\"\";var tc=0;if(typeof TOOLS!==\"undefined\"){for(var k=0;k<TOOLS.length&&tc<30;k++){var t=TOOLS[k];if(t[0].indexOf(q)>=0||t[1].toLowerCase().indexOf(q)>=0){tc++;th2+=row(\"<td><a href='tools\"+EXT+\"#t_\"+t[0]+\"'>\"+t[0]+\"</a></td><td class='muted'>\"+t[1]+\"</td><td class='sig'>\"+t[2]+\"</td>\")}}}\n" as *u8) 4630 cw_apps(page, pos, CW_PAGECAP, "o.innerHTML=\"<h2>capabilities (\"+tc+\" shown, cap 30)</h2><table>\"+th2+\"</table><h2>modules (\"+mc+\" shown, cap 40)</h2><table>\"+mh+\"</table><h2>functions (\"+fc+\" shown, cap 60)</h2><table>\"+fh+\"</table>\"}\n</script>\n" as *u8) 4631 cw_foot(page, pos, CW_PAGECAP) 4632 cw_outpath(opath, outdir, "search.html" as *u8) 4633 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 4634 if pos[1] == 1 { truncs = truncs + 1 } 4635 4636 // ===== pass 3d2: ask.html -- grounded chat over the wiki (rung 15) ===== 4637 // The rung-14 answer pipeline (_ops/codewiki_answer.ps1) as an in-wiki 4638 // surface, its four disciplines enforced IN THE PAGE: 1. no evidence, no 4639 // answer (NO-MATCH never invokes the model); 2. the prompt carries only 4640 // retrieved records; 3. every identifier in the answer is mechanically 4641 // verified against the retrieved set -- one unverified name REJECTS the 4642 // whole answer; 4. all local -- retrieval is client-side over the wiki's 4643 // own indexes, generation is the operator's loopback llama-server (CORS 4644 // origin-echo verified live 2026-07-28). Engine absent => cited evidence 4645 // only, declared -- an honest degrade, never a dead page. 4646 pos[0] = 0 4647 pos[1] = 0 4648 cw_head3(page, pos, CW_PAGECAP, "ask" as *u8, 3, sbbuf) 4649 cw_crumb(page, pos, CW_PAGECAP, noext, 0 as *u8, 0 as *u8, "ask" as *u8, 3) 4650 cw_apps(page, pos, CW_PAGECAP, "<h1>ask the code wiki</h1>\n<p class='muted'>grounded Q&amp;A: retrieval over " as *u8) 4651 cw_appn(page, pos, CW_PAGECAP, nsorted) 4652 cw_apps(page, pos, CW_PAGECAP, " modules and " as *u8) 4653 cw_appn(page, pos, CW_PAGECAP, nfns) 4654 cw_apps(page, pos, CW_PAGECAP, " functions runs in your browser; prose comes from a local engine at <code>http://127.0.0.1:7862</code>. The question never leaves your machine -- not even to this site.</p>\n" as *u8) 4655 cw_apps(page, pos, CW_PAGECAP, "<div id='eng'><span class='pill'>engine: checking...</span></div>\n<input id='q' style='width:520px' placeholder='e.g. which organ detects duplicate function bodies' onkeydown='if(event.key==\"Enter\")ask()'>\n<a class='cta' href='#' onclick='ask();return false'>ask</a>\n<div id='out'></div>\n" as *u8) 4656 cw_apps(page, pos, CW_PAGECAP, "<h2>the discipline</h2>\n<p class='muted'>1. no evidence, no answer -- NO-MATCH never invokes the model. 2. the prompt carries only retrieved records. 3. every identifier in the answer is mechanically verified against the evidence; one unverified name rejects the whole answer. 4. everything is local; your browser may ask permission to reach a local device. Engine recipe: _ops/codewiki_answer.ps1 (llama-server, port 7862).</p>\n" as *u8) 4657 cw_apps(page, pos, CW_PAGECAP, "<script src='modindex.js'></script><script src='fnindex.js'></script><script src='toolindex.js'></script>\n<script>\n" as *u8) 4658 if noext == 0 { cw_apps(page, pos, CW_PAGECAP, "var EXT=\".html\";\n" as *u8) } else { cw_apps(page, pos, CW_PAGECAP, "var EXT=\"\";\n" as *u8) } 4659 cw_apps(page, pos, CW_PAGECAP, "var ENG=\"http://127.0.0.1:7862\";var eng=0;\n" as *u8) 4660 cw_apps(page, pos, CW_PAGECAP, "function esc(s){return s.replace(/&/g,\"&amp;\").replace(/</g,\"&lt;\").replace(/>/g,\"&gt;\")}\n" as *u8) 4661 cw_apps(page, pos, CW_PAGECAP, "function pill(t,c){document.getElementById(\"eng\").innerHTML=\"<span class='pill'>engine: \"+t+\"</span>\"+(c?\" <span class='muted'>\"+c+\"</span>\":\"\")}\n" as *u8) 4662 cw_apps(page, pos, CW_PAGECAP, "function detect(){return fetch(ENG+\"/health\").then(function(r){eng=r.ok?1:0;pill(eng?\"LIVE (local model, 127.0.0.1:7862)\":\"not detected\",\"\")}).catch(function(){eng=0;pill(\"not detected\",\"evidence retrieval still works; start the local engine for prose\")})}\n" as *u8) 4663 cw_apps(page, pos, CW_PAGECAP, "var qp=new URLSearchParams(location.search).get(\"q\");if(qp)document.getElementById(\"q\").value=qp;\n" as *u8) 4664 cw_apps(page, pos, CW_PAGECAP, "detect().then(function(){if(qp)ask()});\n" as *u8) 4665 cw_apps(page, pos, CW_PAGECAP, "var STOP={the:1,and:1,for:1,what:1,which:1,how:1,does:1,that:1,this:1,with:1,are:1,was:1,not:1,you:1,can:1,use:1,used:1,uses:1,our:1,any:1,all:1,one:1,has:1,have:1,its:1,into:1,from:1,when:1,where:1,who:1,why:1,there:1,they:1};\n" as *u8) 4666 cw_apps(page, pos, CW_PAGECAP, "function toks(q){var raw=q.toLowerCase().split(/[^a-z0-9_]+/);var out=[];for(var i=0;i<raw.length;i++){var t=raw[i];if(t.length>=3&&!STOP[t]&&out.indexOf(t)<0)out.push(t)}return out}\n" as *u8) 4667 cw_apps(page, pos, CW_PAGECAP, "function wb(hay,t){return new RegExp(\"(^|[^a-z0-9_])\"+t+\"($|[^a-z0-9_])\").test(hay)}\n" as *u8) 4668 cw_apps(page, pos, CW_PAGECAP, "function stemhit(stem,t){if(stem===t)return 3;return stem.replace(/\\.nx$/,\"\").split(\"_\").indexOf(t)>=0?2:0}\n" as *u8) 4669 cw_apps(page, pos, CW_PAGECAP, "function rank(ts){var df=[],i,j;for(j=0;j<ts.length;j++){var d=0;for(i=0;i<MODS.length;i++){if(stemhit(MODS[i][0],ts[j])>0||wb(MODS[i][2].toLowerCase(),ts[j]))d++}df.push(d)}\n" as *u8) 4670 cw_apps(page, pos, CW_PAGECAP, "var sc=[];for(i=0;i<MODS.length;i++){var r=MODS[i],s=0;for(j=0;j<ts.length;j++){var w=1000/(3+df[j]);var h=stemhit(r[0],ts[j]);if(h)s+=h*2*w;if(wb(r[2].toLowerCase(),ts[j]))s+=w}if(s>0)sc.push([s,i])}sc.sort(function(a,b){return b[0]-a[0]});return sc.slice(0,8)}\n" as *u8) 4671 cw_apps(page, pos, CW_PAGECAP, "function fnhits(ts){var out=[];for(var i=0;i<FNS.length&&out.length<8;i++){var nm=FNS[i][0].toLowerCase();for(var j=0;j<ts.length;j++){if(nm===ts[j]||nm.split(\"_\").indexOf(ts[j])>=0){out.push(FNS[i]);break}}}return out}\n" as *u8) 4672 cw_apps(page, pos, CW_PAGECAP, "function tooltop(ts){if(typeof TOOLS===\"undefined\")return[];var sc=[];for(var i=0;i<TOOLS.length;i++){var s=0,nm=TOOLS[i][0],tt=TOOLS[i][1].toLowerCase();for(var j=0;j<ts.length;j++){var h=stemhit(nm,ts[j]);if(h)s+=h*3;if(wb(tt,ts[j]))s+=2}if(s>0)sc.push([s,i])}sc.sort(function(a,b){return b[0]-a[0]});return sc.slice(0,4)}\n" as *u8) 4673 cw_apps(page, pos, CW_PAGECAP, "function evhtml(top,fns,tls){var h=\"<h2>retrieved evidence</h2><table>\";for(var w=0;w<tls.length;w++){var tv=TOOLS[tls[w][1]];h+=\"<tr><td><a href='tools\"+EXT+\"#t_\"+tv[0]+\"'>\"+tv[0]+\"</a> <span class='muted'>[capability]</span></td><td class='muted'>\"+esc(tv[1])+\"</td></tr>\"}\n" as *u8) 4674 cw_apps(page, pos, CW_PAGECAP, "for(var i=0;i<top.length;i++){var r=MODS[top[i][1]];h+=\"<tr><td><a href='\"+r[0]+EXT+\"'>\"+r[0]+\"</a> <span class='muted'>[\"+(r[5]||\"\")+\"]</span></td><td class='muted'>\"+esc(r[2])+\"</td></tr>\"}\n" as *u8) 4675 cw_apps(page, pos, CW_PAGECAP, "for(i=0;i<fns.length;i++){h+=\"<tr><td><a href='\"+fns[i][1]+EXT+\"#fn_\"+fns[i][0]+\"'>\"+fns[i][0]+\"()</a></td><td class='muted'>in \"+fns[i][1]+\" line \"+fns[i][2]+\"</td></tr>\"}return h+\"</table>\"}\n" as *u8) 4676 cw_apps(page, pos, CW_PAGECAP, "function ask(){var q=document.getElementById(\"q\").value.trim();var o=document.getElementById(\"out\");if(q.length<4)return;var ts=toks(q);\n" as *u8) 4677 cw_apps(page, pos, CW_PAGECAP, "if(ts.length===0){o.innerHTML=\"<p class='doc'>NO EVIDENCE IN THE WIKI -- the question has no usable terms. Not guessing.</p>\";return}\n" as *u8) 4678 cw_apps(page, pos, CW_PAGECAP, "var top=rank(ts),fns=fnhits(ts),tls=tooltop(ts);\n" as *u8) 4679 cw_apps(page, pos, CW_PAGECAP, "if(top.length===0&&fns.length===0&&tls.length===0){o.innerHTML=\"<p class='doc'>NO EVIDENCE IN THE WIKI for: \"+esc(q)+\"<br>No module, function, or capability record shares a token with this question. Not guessing -- the model was not invoked.</p>\";return}\n" as *u8) 4680 cw_apps(page, pos, CW_PAGECAP, "var ev=evhtml(top,fns,tls);\n" as *u8) 4681 cw_apps(page, pos, CW_PAGECAP, "if(!eng){o.innerHTML=\"<p class='muted'>local engine not detected -- cited evidence only; nothing was generated, nothing left this machine.</p>\"+ev;return}\n" as *u8) 4682 cw_apps(page, pos, CW_PAGECAP, "o.innerHTML=\"<p class='muted'>reading cited pages + asking the local model...</p>\";\n" as *u8) 4683 cw_apps(page, pos, CW_PAGECAP, "var picks=top.slice(0,4);\n" as *u8) 4684 cw_apps(page, pos, CW_PAGECAP, "var proms=picks.map(function(p){return fetch(MODS[p[1]][0]+EXT).then(function(r){return r.text()}).then(function(h){var b=new DOMParser().parseFromString(h,\"text/html\").querySelector(\".doc\");return b?b.textContent.slice(0,1100):\"\"}).catch(function(){return \"\"})});\n" as *u8) 4685 cw_apps(page, pos, CW_PAGECAP, "Promise.all(proms).then(function(docs){var allowed={},recs=\"\",i;\n" as *u8) 4686 cw_apps(page, pos, CW_PAGECAP, "for(i=0;i<top.length;i++){var r=MODS[top[i][1]];allowed[r[0]]=1;recs+=\"MODULE \"+r[0]+\" (dir \"+r[1]+\", \"+r[3]+\" loc, kind \"+r[5]+\"): \"+r[2]+\"\\n\"}\n" as *u8) 4687 cw_apps(page, pos, CW_PAGECAP, "for(i=0;i<picks.length;i++){if(docs[i])recs+=\"HEADER-DOC of \"+MODS[picks[i][1]][0]+\": \"+docs[i]+\"\\n\"}\n" as *u8) 4688 cw_apps(page, pos, CW_PAGECAP, "for(i=0;i<fns.length;i++){allowed[fns[i][0]]=1;allowed[fns[i][1]]=1;recs+=\"FUNCTION \"+fns[i][0]+\" in \"+fns[i][1]+\" line \"+fns[i][2]+\"\\n\"}\n" as *u8) 4689 cw_apps(page, pos, CW_PAGECAP, "for(i=0;i<tls.length;i++){var tz=TOOLS[tls[i][1]];allowed[tz[0]]=1;recs+=\"CAPABILITY \"+tz[0]+\": \"+tz[1]+(tz[2]?\" -- call: \"+tz[2]:\"\")+\"\\n\"}\n" as *u8) 4690 cw_apps(page, pos, CW_PAGECAP, "var names=Object.keys(allowed).sort().join(\", \");\n" as *u8) 4691 cw_apps(page, pos, CW_PAGECAP, "var prompt=\"You answer questions about the Nishi sovereign ecosystem codebase (all NishiLang, one binary per organ) using ONLY the retrieved records below.\\n\\nRETRIEVED RECORDS:\\n\"+recs+\"\\nQUESTION: \"+q+\"\\n\\n\";\n" as *u8) 4692 cw_apps(page, pos, CW_PAGECAP, "prompt+=\"Rules: answer in 2-4 sentences using only the records above. You may name ONLY these identifiers: \"+names+\". If the records do not answer the question, say exactly \\\"The retrieved records do not answer this.\\\" Do not speculate, do not invent module names, no bullet points. /no_think\";\n" as *u8) 4693 cw_apps(page, pos, CW_PAGECAP, "return fetch(ENG+\"/v1/chat/completions\",{method:\"POST\",headers:{\"Content-Type\":\"application/json\"},body:JSON.stringify({model:\"local\",max_tokens:400,temperature:0.2,messages:[{role:\"user\",content:prompt}]})}).then(function(r){return r.json()}).then(function(j){\n" as *u8) 4694 cw_apps(page, pos, CW_PAGECAP, "var ans=(j.choices&&j.choices[0]&&j.choices[0].message)?j.choices[0].message.content:\"\";ans=ans.split(/<\\/?think>/).pop().trim();\n" as *u8) 4695 cw_apps(page, pos, CW_PAGECAP, "var un=[],m,re=/\\b(nx_[A-Za-z0-9_]+|[a-z]{2,}_[a-z0-9_]{3,})\\b/g;\n" as *u8) 4696 cw_apps(page, pos, CW_PAGECAP, "while((m=re.exec(ans)))if(!allowed[m[1]]&&un.indexOf(m[1])<0)un.push(m[1]);\n" as *u8) 4697 cw_apps(page, pos, CW_PAGECAP, "if(!ans){o.innerHTML=\"<p class='doc'>the engine returned nothing -- evidence below.</p>\"+ev;return}\n" as *u8) 4698 cw_apps(page, pos, CW_PAGECAP, "if(un.length){o.innerHTML=\"<p class='doc'>ANSWER REJECTED -- the model named identifiers retrieval never returned: \"+esc(un.join(\", \"))+\". Refusing to show an answer whose citations cannot be checked. The evidence:</p>\"+ev;return}\n" as *u8) 4699 cw_apps(page, pos, CW_PAGECAP, "var src=\"\";for(var s=0;s<picks.length;s++){var r2=MODS[picks[s][1]];src+=\"<a class='pill' href='\"+r2[0]+EXT+\"'>\"+r2[0]+\"</a> \"}\n" as *u8) 4700 cw_apps(page, pos, CW_PAGECAP, "o.innerHTML=\"<div class='nar'>\"+esc(ans)+\"</div><p class='muted'>every identifier verified present in the retrieved evidence; the question never left this machine.</p><p>sources: \"+src+\"</p>\"+ev\n" as *u8) 4701 cw_apps(page, pos, CW_PAGECAP, "})\n}).catch(function(e){o.innerHTML=\"<p class='doc'>engine call failed (\"+esc(String(e))+\") -- evidence below.</p>\"+ev})\n}\n</script>\n" as *u8) 4702 cw_foot(page, pos, CW_PAGECAP) 4703 cw_outpath(opath, outdir, "ask.html" as *u8) 4704 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 4705 if pos[1] == 1 { truncs = truncs + 1 } 4706 4707 // ===== pass 3d3: lang.html -- the NishiLang adoption instrument (rung 16) ===== 4708 // The language lane's coverage/adoption axes measured over the WHOLE tree 4709 // at every regen: [N]T fixed arrays (bounds-checked spatial safety, lane 4710 // r1) and []T slices (heap spatial safety, lane r2). The lane's one-off 4711 // hand counts become a live instrument; the measured cross-language 4712 // rankings + the SOTA plan live at /nishilang. 4713 var lgfix: i64 = 0 4714 var lgsli: i64 = 0 4715 var lg0: i64 = 0 4716 while lg0 < nsorted { 4717 let lgv: i64 = sidx[lg0] 4718 if (langv[lgv] & 1) != 0 { lgfix = lgfix + 1 } 4719 if (langv[lgv] & 2) != 0 { lgsli = lgsli + 1 } 4720 lg0 = lg0 + 1 4721 } 4722 var lgfp: i64 = 0 4723 var lgsp: i64 = 0 4724 if nsorted > 0 { lgfp = (lgfix * 1000) / nsorted; lgsp = (lgsli * 1000) / nsorted } 4725 pos[0] = 0 4726 pos[1] = 0 4727 cw_head3(page, pos, CW_PAGECAP, "language" as *u8, 8, sbbuf) 4728 cw_crumb(page, pos, CW_PAGECAP, noext, 0 as *u8, 0 as *u8, "language" as *u8, 8) 4729 cw_apps(page, pos, CW_PAGECAP, "<h1>the language: NishiLang</h1>\n<p class='muted'>every module in this tree is NishiLang, compiled by the sovereign nx_cc (no gcc, no llvm). The measured cross-language rankings, safety head-to-heads, and the SOTA plan live at <a href='/nishilang'>/nishilang</a>; this page is the tree-side instrument: the language lane's adoption axes, re-measured on every regeneration.</p>\n" as *u8) 4730 cw_apps(page, pos, CW_PAGECAP, "<div class='tiles'><div class='tile'><div class='v'>" as *u8) 4731 cw_appn(page, pos, CW_PAGECAP, nsorted) 4732 cw_apps(page, pos, CW_PAGECAP, "</div><div class='k'>NishiLang modules</div></div><div class='tile'><div class='v'>" as *u8) 4733 cw_appn(page, pos, CW_PAGECAP, lgfix) 4734 cw_apps(page, pos, CW_PAGECAP, "</div><div class='k'>[N]T fixed-array modules (" as *u8) 4735 cw_appn(page, pos, CW_PAGECAP, lgfp) 4736 cw_apps(page, pos, CW_PAGECAP, " permil)</div></div><div class='tile'><div class='v'>" as *u8) 4737 cw_appn(page, pos, CW_PAGECAP, lgsli) 4738 cw_apps(page, pos, CW_PAGECAP, "</div><div class='k'>[]T slice modules (" as *u8) 4739 cw_appn(page, pos, CW_PAGECAP, lgsp) 4740 cw_apps(page, pos, CW_PAGECAP, " permil)</div></div></div>\n" as *u8) 4741 cw_apps(page, pos, CW_PAGECAP, "<h2>spatial-safety adoption (measured at every regen)</h2>\n<p>[N]T carries its length in the TYPE, so indexing is bounds-checked with zero annotations (lane r1; OOB refused at runtime, parity with Rust, ahead of C). []T carries {ptr,len}, extending the same guarantee to HEAP memory (lane r2). Coverage vs adoption are SEPARATE axes on purpose: 100 percent of modules are addressable; adoption is what this page counts.</p>\n" as *u8) 4742 cw_apps(page, pos, CW_PAGECAP, "<p class='muted'>DECLARED GATE: []T corpus migration is deliberately parked until the phi/mem2reg codegen rung lands -- migrating today would ship a measured 3.7x slowdown tree-wide (G9 header reloads). Expect the slice number to sit near zero until that rung; this page will show it move the regen it moves.</p>\n" as *u8) 4743 cw_apps(page, pos, CW_PAGECAP, "<h2>[N]T adopters <span class='cnt'>(alphabetical, cap 24 declared)</span></h2>\n<p>" as *u8) 4744 var lg1: i64 = 0 4745 var lgc1: i64 = 0 4746 while lg1 < nsorted { 4747 let lw1: i64 = sidx[lg1] 4748 if (langv[lw1] & 1) != 0 { if lgc1 < CW_LANGSHOW { 4749 cw_apps(page, pos, CW_PAGECAP, "<span class='pill'>" as *u8) 4750 cw_applink2(page, pos, CW_PAGECAP, ((g.arena as i64) + g.node_off[lw1]) as *u8, noext) 4751 cw_apps(page, pos, CW_PAGECAP, "</span> " as *u8) 4752 lgc1 = lgc1 + 1 4753 } } 4754 lg1 = lg1 + 1 4755 } 4756 cw_apps(page, pos, CW_PAGECAP, "</p>\n<h2>[]T / __slice adopters <span class='cnt'>(alphabetical, cap 24 declared)</span></h2>\n<p>" as *u8) 4757 var lg2: i64 = 0 4758 var lgc2: i64 = 0 4759 while lg2 < nsorted { 4760 let lw2: i64 = sidx[lg2] 4761 if (langv[lw2] & 2) != 0 { if lgc2 < CW_LANGSHOW { 4762 cw_apps(page, pos, CW_PAGECAP, "<span class='pill'>" as *u8) 4763 cw_applink2(page, pos, CW_PAGECAP, ((g.arena as i64) + g.node_off[lw2]) as *u8, noext) 4764 cw_apps(page, pos, CW_PAGECAP, "</span> " as *u8) 4765 lgc2 = lgc2 + 1 4766 } } 4767 lg2 = lg2 + 1 4768 } 4769 cw_apps(page, pos, CW_PAGECAP, "</p>\n<h2>the scan rule (declared)</h2>\n<p class='muted'>lexical and comment-INCLUSIVE: a module counts as [N]T if it contains ': [' followed by a digit, and as []T if it contains ': []' or '__slice('. A stray comment can inflate a count by one (this generator counts itself via its own emission strings); the rule is applied identically every regen, so the TREND is honest. The compiler family starts at " as *u8) 4770 cw_applink2(page, pos, CW_PAGECAP, "nx_parse.nx" as *u8, noext) 4771 cw_apps(page, pos, CW_PAGECAP, ".</p>\n" as *u8) 4772 cw_foot(page, pos, CW_PAGECAP) 4773 cw_outpath(opath, outdir, "lang.html" as *u8) 4774 if cw_flush(opath, page, pos, CW_PAGECAP) == 0 { pages = pages + 1 } 4775 if pos[1] == 1 { truncs = truncs + 1 } 4776 4777 // ===== pass 3d4: tools.html + toolindex.js -- the capability catalog ===== 4778 // (rung 19: SOTA discoverability -- capabilities are first-class records, 4779 // browsable here, filterable, and retrievable in search + ask.) 4780 let tix: *u8 = sys_mmap(CW_PAGECAP) 4781 let tixp: *i64 = sys_mmap(32) as *i64 4782 tixp[0] = 0 4783 tixp[1] = 0 4784 pos[0] = 0 4785 pos[1] = 0 4786 cw_head3(page, pos, CW_PAGECAP, "tools" as *u8, 5, sbbuf) 4787 cw_crumb(page, pos, CW_PAGECAP, noext, 0 as *u8, 0 as *u8, "tools" as *u8, 5) 4788 cw_apps(page, pos, CW_PAGECAP, "<h1>capability catalog</h1>\n<p class='muted'>every REGISTERED tool: what it does (schema title) and how to call it (argv grammar), generated from the live allowlist joined to the schema registry. Capabilities are also retrievable in <a href='search" as *u8) 4789 cw_appext(page, pos, CW_PAGECAP, noext) 4790 cw_apps(page, pos, CW_PAGECAP, "'>search</a> and <a href='ask" as *u8) 4791 cw_appext(page, pos, CW_PAGECAP, noext) 4792 cw_apps(page, pos, CW_PAGECAP, "'>ask</a> -- a capability nobody can find at the moment of need is a capability the ecosystem does not have.</p>\n" as *u8) 4793 cw_filterjs(page, pos, CW_PAGECAP) 4794 let ntools: i64 = cw_tools(page, pos, CW_PAGECAP, tix, tixp, allowpath, schemapath) 4795 cw_apps(page, pos, CW_PAGECAP, "<p class='muted'>rows: " as *u8) 4796 cw_appn(page, pos, CW_PAGECAP, ntools) 4797 cw_apps(page, pos, CW_PAGECAP, " (filter box matches the capability name)</p>\n" as *u8) 4798 cw