code wiki / _hdl_build / nx_ims_corpus_refresh.nx
nx_ims_corpus_refresh.nx source
↩ module page · 96 lines · 7298 B
1// nx_ims_corpus_refresh.nx -- rebuild the framed live-corpus snapshot
2// knowledge/status/ims_live_corpus.txt from the CURRENT web_assets/*.html bytes (the
3// exact bytes vpub publishes). Each page is framed "###PAGE /wiki/<slug>.html <blen>\n
4// <body>" -- the SAME transport nx_wiki_walk_metrics / nx_ims_monitor read. This is the
5// "refresh from live bytes before measuring" step the walkability rung requires; it must
6// run AFTER the page emitters and BEFORE the walk gate so the gate measures the new tree.
7// READ web_assets, WRITE the snapshot only (additive to the wiki; replaces the snapshot
8// cache). Driven by a slug->file map so adding a page is a one-line data change.
9// license_tier: ORIGINAL
10import "nx_syscalls.nx"
11import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
12
13const CR_OUT: *u8 = "knowledge/status/ims_live_corpus.txt"
14const CR_CAP: i64 = 4194304 // 4 MB (matches WM_MAX_BYTES)
15const CR_MODE: i64 = 0x1a4
16
17func cr_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
18// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
19// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
20// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
21// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
22func cr_num(v: i64) -> i64 { nxi_out(v); return 0 }
23func cr_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != 0 as u8 { dst[off + i] = s[i]; i = i + 1 } return off + i }
24func cr_catn(dst: *u8, off: i64, v: i64) -> i64 {
25 var o: i64 = off; let t: *u8 = sys_mmap(28); var m: i64 = v; var k: i64 = 0
26 if m == 0 { t[0] = 48 as u8; k = 1 }
27 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
28 var i: i64 = 0; while i < k { dst[o] = t[k - 1 - i]; o = o + 1; i = i + 1 }
29 return o
30}
31
32// append one framed page for (slug, file) into dst at off; returns new off, or -1 on read fail.
33func cr_frame(dst: *u8, off: i64, slug: *u8, file: *u8) -> i64 {
34 let nbox: *i64 = sys_mmap(16) as *i64
35 nbox[0] = 0
36 let body: *u8 = sys_read_file(file, nbox)
37 if (body as i64) == 0 { cr_w(" READ-FAIL "); cr_w(file); cr_w("\n"); return 0 - 1 }
38 let blen: i64 = nbox[0]
39 if blen < 1 { cr_w(" EMPTY "); cr_w(file); cr_w("\n"); return 0 - 1 }
40 var o: i64 = off
41 o = cr_cat(dst, o, "###PAGE /wiki/" as *u8)
42 o = cr_cat(dst, o, slug)
43 o = cr_cat(dst, o, ".html " as *u8)
44 o = cr_catn(dst, o, blen)
45 dst[o] = 0x0A as u8; o = o + 1
46 var b: i64 = 0
47 while b < blen { dst[o] = body[b]; o = o + 1; b = b + 1 }
48 cr_w(" framed "); cr_w(slug); cr_w(" blen="); cr_num(blen); cr_w("\n")
49 return o
50}
51
52func main() -> i64 {
53 let buf: *u8 = sys_mmap(CR_CAP)
54 var o: i64 = 0
55 var n: i64 = 0
56 cr_w("=== corpus refresh: framing live web_assets bytes -> snapshot ===\n")
57
58 // slug -> web_assets file. NOTE: slug "start" lives in ai_start.html (the AI front door).
59 let r1: i64 = cr_frame(buf, o, "start" as *u8, "web_assets/ai_start.html" as *u8); if r1 >= 0 { o = r1; n = n + 1 }
60 let r2: i64 = cr_frame(buf, o, "charter" as *u8, "web_assets/charter.html" as *u8); if r2 >= 0 { o = r2; n = n + 1 }
61 let r3: i64 = cr_frame(buf, o, "nist_stem" as *u8, "web_assets/nist_stem.html" as *u8); if r3 >= 0 { o = r3; n = n + 1 }
62 let r4: i64 = cr_frame(buf, o, "roadmap" as *u8, "web_assets/roadmap.html" as *u8); if r4 >= 0 { o = r4; n = n + 1 }
63 let r5: i64 = cr_frame(buf, o, "board" as *u8, "web_assets/board.html" as *u8); if r5 >= 0 { o = r5; n = n + 1 }
64 let r6: i64 = cr_frame(buf, o, "devlog" as *u8, "web_assets/devlog.html" as *u8); if r6 >= 0 { o = r6; n = n + 1 }
65 // NOTE: the WALKABLE wiki version of econsim is econsim_wiki.html (econsim.html is
66 // the game/product page served at /econsim, furniture-free). The /wiki/ slug uses the wiki one.
67 let r7: i64 = cr_frame(buf, o, "econsim" as *u8, "web_assets/econsim_wiki.html" as *u8); if r7 >= 0 { o = r7; n = n + 1 }
68 let r8: i64 = cr_frame(buf, o, "products" as *u8, "web_assets/products.html" as *u8); if r8 >= 0 { o = r8; n = n + 1 }
69 let r9: i64 = cr_frame(buf, o, "genesis_genealogy" as *u8, "web_assets/genesis_genealogy.html" as *u8); if r9 >= 0 { o = r9; n = n + 1 }
70 let r10: i64 = cr_frame(buf, o, "access_wall" as *u8, "web_assets/access_wall.html" as *u8); if r10 >= 0 { o = r10; n = n + 1 }
71 let r11: i64 = cr_frame(buf, o, "formats_uxf" as *u8, "web_assets/formats_uxf.html" as *u8); if r11 >= 0 { o = r11; n = n + 1 }
72 // IMS Thrust D rung 1: the sovereign LaTeX->MathML render demo page (slug == web_assets/<slug>.html).
73 let r11b: i64 = cr_frame(buf, o, "math_render" as *u8, "web_assets/math_render.html" as *u8); if r11b >= 0 { o = r11b; n = n + 1 }
74 let r12: i64 = cr_frame(buf, o, "media_studio" as *u8, "web_assets/media_studio.html" as *u8); if r12 >= 0 { o = r12; n = n + 1 }
75 let r13: i64 = cr_frame(buf, o, "search" as *u8, "web_assets/search.html" as *u8); if r13 >= 0 { o = r13; n = n + 1 }
76 // batch #2: substrate hub + 6 leaves (the real-tree deepening). slug == web_assets/<slug>.html.
77 let r14: i64 = cr_frame(buf, o, "substrate" as *u8, "web_assets/substrate.html" as *u8); if r14 >= 0 { o = r14; n = n + 1 }
78 let r15: i64 = cr_frame(buf, o, "nishi_os" as *u8, "web_assets/nishi_os.html" as *u8); if r15 >= 0 { o = r15; n = n + 1 }
79 let r16: i64 = cr_frame(buf, o, "sovereign_email" as *u8, "web_assets/sovereign_email.html" as *u8); if r16 >= 0 { o = r16; n = n + 1 }
80 let r17: i64 = cr_frame(buf, o, "simd_backend" as *u8, "web_assets/simd_backend.html" as *u8); if r17 >= 0 { o = r17; n = n + 1 }
81 let r18: i64 = cr_frame(buf, o, "neural_mt" as *u8, "web_assets/neural_mt.html" as *u8); if r18 >= 0 { o = r18; n = n + 1 }
82 let r19: i64 = cr_frame(buf, o, "vision_fr" as *u8, "web_assets/vision_fr.html" as *u8); if r19 >= 0 { o = r19; n = n + 1 }
83 let r20: i64 = cr_frame(buf, o, "voxelworld" as *u8, "web_assets/voxelworld.html" as *u8); if r20 >= 0 { o = r20; n = n + 1 }
84 // IMS Thrust D rung 2: native SVG charts + multi-format dataset export (slug == web_assets/<slug>.html).
85 let r21: i64 = cr_frame(buf, o, "figures" as *u8, "web_assets/figures.html" as *u8); if r21 >= 0 { o = r21; n = n + 1 }
86 // R5: the asset catalog + awareness dashboard (HAVE / TO-DO / GOING-ON). slug == web_assets/<slug>.html.
87 let r22: i64 = cr_frame(buf, o, "assets" as *u8, "web_assets/assets.html" as *u8); if r22 >= 0 { o = r22; n = n + 1 }
88
89 let fd: i64 = sys_openat_wr(CR_OUT, CR_MODE)
90 if fd < 0 { cr_w("FATAL: cannot open snapshot for write\n"); sys_exit(2); return 2 }
91 sys_write(fd, buf, o)
92 sys_close(fd)
93 cr_w("=== wrote snapshot pages="); cr_num(n); cr_w(" bytes="); cr_num(o); cr_w(" ===\n")
94 if n == 23 { sys_exit(0); return 0 }
95 sys_exit(1); return 1
96}