code wiki / _hdl_build / nx_scilib_page.nx
nx_scilib_page.nx source
↩ module page · 127 lines · 8295 B
1// nx_scilib_page.nx -- DATA-DRIVEN UI for the sovereign Nishi KNOWLEDGE library (the foundationed research
2// corpus: papers / wiki mirrors / research artifacts). Distinct from the sibling nx_library_page.nx, which is
3// the MEDIA library (video/photos/games). Operator law: every capability needs a live UI we iterate on. Emits
4// web_assets/library.html STRAIGHT FROM the library model -- iterates lib_list, pulls lib_meta(title/source/
5// bytes) + a lib_get snippet per doc, renders a browsable instant-filter catalog. CX differentiator = the
6// provenance: every doc is CID-signed + lineage-traced to god + in the no-link-rot corpus. Read-only +
7// public-safe (no controls, no secrets). Honest scope: browse + client-side keyword filter; the sovereign
8// BM25 ranked-search endpoint (ls_best_bm25 server-side) is the next rung. license_tier: ORIGINAL
9import "nx_syscalls.nx"
10import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
11import "nx_library.nx"
12
13const SP_OUT: *u8 = "web_assets/library.html"
14
15func sp_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
16func sp_we(fd: i64, p: *u8, n: i64) -> i64 { if n>0 { sys_write(fd,p,n) } return 0 }
17// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
18// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
19// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
20// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
21func sp_num(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
22
23// write n bytes HTML-escaped (& < > " and control chars -> space) to fd.
24func sp_esc(fd: i64, p: *u8, n: i64) -> i64 {
25 var i: i64 = 0
26 while i < n {
27 let c: i64 = p[i] as i64
28 if c == 38 { sp_w(fd, "&" as *u8) } else {
29 if c == 60 { sp_w(fd, "<" as *u8) } else {
30 if c == 62 { sp_w(fd, ">" as *u8) } else {
31 if c == 34 { sp_w(fd, """ as *u8) } else {
32 if c < 32 { sp_w(fd, " " as *u8) } else {
33 let one: *u8 = sys_mmap(2); one[0] = p[i]; sys_write(fd, one, 1)
34 } } } } }
35 i = i + 1
36 }
37 return 0
38}
39
40// snippet: first `cap` bytes of the doc, skipping leading whitespace. returns length into out.
41func sp_snip(body: *u8, blen: i64, out: *u8, cap: i64) -> i64 {
42 var i: i64 = 0; var done: i64 = 0
43 while done == 0 {
44 if i >= blen { done = 1 } else {
45 let c: i64 = body[i] as i64
46 if c==32 { i=i+1 } else { if c==10 { i=i+1 } else { if c==13 { i=i+1 } else { if c==9 { i=i+1 } else { done = 1 } } } }
47 }
48 }
49 var o: i64 = 0
50 while o < cap { if i >= blen { o = cap } else { out[o] = body[i]; o = o + 1; i = i + 1 } }
51 if i >= blen { return o }
52 return cap
53}
54
55func main() -> i64 {
56 let fd: i64 = sys_openat_wr(SP_OUT, 0x1a4)
57 if fd < 0 { return 1 }
58
59 let n: i64 = lib_count()
60 sp_w(fd, "<!DOCTYPE html>\n<html lang=\"en\"><head><meta charset=\"utf-8\">\n")
61 sp_w(fd, "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n")
62 sp_w(fd, "<title>Nishi Library \xe2\x80\x94 sovereign knowledge, no link rot</title>\n<style>\n")
63 sp_w(fd, ":root{--bg:#0d1117;--panel:#161b22;--line:#30363d;--ink:#e6edf3;--mut:#9da7b3;--grn:#3fb950;--acc:#58a6ff;--amb:#d29922}\n")
64 sp_w(fd, "*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.6 -apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif}\n")
65 sp_w(fd, ".wrap{max-width:920px;margin:0 auto;padding:30px 20px 90px}h1{font-size:26px;margin:0 0 4px}.sub{color:var(--mut);margin:0 0 18px}\n")
66 sp_w(fd, ".stats{display:flex;gap:18px;flex-wrap:wrap;margin:0 0 16px;color:var(--mut);font-size:13px}.stats b{color:var(--grn)}\n")
67 sp_w(fd, "#q{width:100%;padding:12px 14px;background:var(--panel);border:1px solid var(--line);border-radius:9px;color:var(--ink);font-size:15px;outline:none}#q:focus{border-color:var(--acc)}\n")
68 sp_w(fd, ".doc{background:var(--panel);border:1px solid var(--line);border-radius:9px;padding:14px 16px;margin:11px 0}\n")
69 sp_w(fd, ".t{font-size:16px;font-weight:600;margin:0 0 6px;color:#fff}\n")
70 sp_w(fd, ".m{display:flex;gap:10px;flex-wrap:wrap;align-items:center;font-size:12px;color:var(--mut);margin-bottom:7px}\n")
71 sp_w(fd, ".badge{padding:2px 8px;border-radius:20px;border:1px solid var(--line);color:var(--acc)}\n")
72 sp_w(fd, ".found{color:var(--grn);border:1px solid rgba(63,185,80,.4);padding:2px 8px;border-radius:20px}\n")
73 sp_w(fd, ".cid{font-family:ui-monospace,Menlo,Consolas,monospace;color:var(--amb)}\n")
74 sp_w(fd, ".sn{color:var(--mut);font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n")
75 sp_w(fd, ".foot{color:var(--mut);font-size:13px;margin-top:26px}.empty{color:var(--mut);padding:20px 0;display:none}\n</style></head>\n<body><div class=\"wrap\">\n")
76
77 sp_w(fd, "<h1>Nishi Library</h1>\n<p class=\"sub\">A sovereign knowledge corpus that <strong>cannot link-rot</strong> \xe2\x80\x94 we own every byte, and every source is traceable to god.</p>\n")
78 sp_w(fd, "<div class=\"stats\"><span><b>"); sp_num(fd, n); sp_w(fd, "</b> foundationed documents</span><span><b>0</b> non-foundationed</span><span>every doc CID-signed + lineage\xe2\x86\x92god</span><span>showing <b id=\"cnt\">"); sp_num(fd, n); sp_w(fd, "</b></span></div>\n")
79 sp_w(fd, "<input id=\"q\" type=\"search\" placeholder=\"Filter the library \xe2\x80\x94 title, source, or keyword\xe2\x80\xa6\" oninput=\"filt()\" autocomplete=\"off\">\n")
80 sp_w(fd, "<div id=\"docs\">\n")
81
82 let cids: *i64 = sys_mmap(8 * 256) as *i64
83 let cnt: i64 = lib_list(cids, 256)
84 let title: *u8 = sys_mmap(512)
85 let source: *u8 = sys_mmap(256)
86 let bytes: *u8 = sys_mmap(64)
87 let snip: *u8 = sys_mmap(256)
88 let pp: *i64 = sys_mmap(8) as *i64
89 let ll: *i64 = sys_mmap(8) as *i64
90
91 var d: i64 = 0
92 while d < cnt {
93 let cid: *u8 = cids[d] as *u8
94 var z: i64=0; while z<512 { title[z]=0 as u8; z=z+1 } z=0; while z<256 { source[z]=0 as u8; z=z+1 } z=0; while z<64 { bytes[z]=0 as u8; z=z+1 }
95 lib_meta(cid, "title" as *u8, title, 500)
96 lib_meta(cid, "source" as *u8, source, 250)
97 lib_meta(cid, "bytes" as *u8, bytes, 60)
98 var sl: i64 = 0
99 if lib_get(cid, pp, ll) == 1 { sl = sp_snip(pp[0] as *u8, ll[0], snip, 150) }
100
101 var tl: i64 = 0; while title[tl]!=(0 as u8){tl=tl+1}
102 if tl >= 4 { if title[tl-4]==(46 as u8){ if title[tl-3]==(116 as u8){ if title[tl-2]==(120 as u8){ if title[tl-1]==(116 as u8){ tl = tl - 4 } } } } }
103 var srcl: i64 = 0; while source[srcl]!=(0 as u8){srcl=srcl+1}
104
105 sp_w(fd, "<article class=\"doc\" data-s=\"")
106 sp_esc(fd, title, tl); sp_w(fd, " "); sp_esc(fd, source, srcl); sp_w(fd, " "); sp_esc(fd, snip, sl)
107 sp_w(fd, "\">\n <div class=\"t\">")
108 sp_esc(fd, title, tl)
109 sp_w(fd, "</div>\n <div class=\"m\"><span class=\"badge\">")
110 sp_esc(fd, source, srcl)
111 sp_w(fd, "</span><span class=\"cid\">")
112 sp_we(fd, cid, 21)
113 sp_w(fd, "\xe2\x80\xa6</span><span class=\"found\">\xe2\x9c\x93 foundationed \xc2\xb7 lineage\xe2\x86\x92god</span></div>\n <div class=\"sn\">")
114 sp_esc(fd, snip, sl)
115 sp_w(fd, "\xe2\x80\xa6</div>\n</article>\n")
116 d = d + 1
117 }
118
119 sp_w(fd, "</div>\n<p class=\"empty\" id=\"empty\">No documents match your filter.</p>\n")
120 sp_w(fd, "<p class=\"foot\">Nishi \xe2\x80\x94 sovereign from the hardware rung up. Each document foundationed: CID + ed25519 provenance + lineage to god. No link rot, by construction.</p>\n")
121 sp_w(fd, "<script>\nfunction filt(){var q=document.getElementById('q').value.toLowerCase();var ds=document.querySelectorAll('.doc');var s=0;for(var i=0;i<ds.length;i++){var m=ds[i].getAttribute('data-s').toLowerCase().indexOf(q)>=0;ds[i].style.display=m?'':'none';if(m)s++;}document.getElementById('cnt').textContent=s;document.getElementById('empty').style.display=s?'none':'block';}\n</script>\n")
122 sp_w(fd, "</div></body></html>\n")
123 sys_close(fd)
124
125 sp_w(1, "[scilib_page] wrote web_assets/library.html docs="); sp_num(1, cnt); sp_w(1, "\n")
126 sys_exit(0); return 0
127}