nx_research_ocean.nx source
↩ module page · 281 lines · 15380 B
1// nx_research_ocean.nx -- THE OCEAN. Renders /wiki/research.html from the `resbrief-` information
2// plane, so every research river (/code/research, /product/research, and any area added later) flows
3// into ONE surface. Operator 2026-08-01: "both should like rivers to the ocean go into
4// nishifamily.com/wiki/research under sections for product and code and other research areas".
5//
6// The AREA LIST IS NOT HARDCODED: sections are the DISTINCT values of the area column, in first-seen
7// order, and a brief's URL is derived as /<area>/<slug>. A new research area therefore appears on this
8// page by adding ONE plane row -- no page surgery, no organ edit. That is the difference between this
9// and nx_wiki_products_page, whose families are string literals while its header claims a file source
10// it never reads (debt 1785625149).
11//
12// Reads with sts_load_honest, NOT sts_load: a stale/low q:n silently truncates the plain loader, and an
13// index that under-reports its own library is indistinguishable from a complete one. Declared vs loaded
14// vs reachable-beyond are printed on stdout AND rendered on the page, so partial coverage is visible to
15// a reader of the page, not just to whoever ran the organ.
16//
17// Plane row (8 col): id area slug title date status forks_off scope
18// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
19import "nx_store_seed_lib.nx"
20import "nx_seg_store.nx"
21import "nx_syscalls.nx"
22
23const RO_PLANE: *u8 = "knowledge/store/resbrief-"
24const RO_OUT: *u8 = "sites/nishifamily/wiki/research.html"
25const RO_RCAP: i64 = 262144
26const RO_HCAP: i64 = 524288
27const RO_NL: i64 = 10
28const RO_TAB: i64 = 9
29const RO_MAXCOL: i64 = 16
30const RO_PAIR: i64 = 2
31const RO_SPB: i64 = 256
32const RO_MAXAREA: i64 = 16
33const RO_AREAB: i64 = 256
34const RO_FLAGB: i64 = 64
35const RO_C_AREA: i64 = 1
36const RO_C_SLUG: i64 = 2
37const RO_C_TITLE: i64 = 3
38const RO_C_DATE: i64 = 4
39const RO_C_STATUS: i64 = 5
40const RO_C_FORKS: i64 = 6
41const RO_C_SCOPE: i64 = 7
42const RO_NCOL: i64 = 8
43const RO_MODE: i64 = 0x1a4
44const RO_ERRFD: i64 = 2
45const RO_EXIT_IO: i64 = 1
46const RO_EXIT_EMPTY: i64 = 3
47const RO_LT: i64 = 60
48const RO_GT: i64 = 62
49const RO_AMP: i64 = 38
50
51func ro_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
52func ro_werr(s: *u8) -> i64 { sys_write(RO_ERRFD, s, ro_slen(s)); return 0 }
53
54// slice [a,b) of q equals C-string s
55func ro_slice_eqs(q: *u8, a: i64, b: i64, s: *u8) -> i64 {
56 let sn: i64 = ro_slen(s)
57 if b - a != sn { return 0 }
58 var i: i64 = 0
59 while i < sn { if q[a+i] != s[i] { return 0 } i = i + 1 }
60 return 1
61}
62// slice [a,b) of q equals slice [c,d) of r
63func ro_slice_eq(q: *u8, a: i64, b: i64, r: *u8, c: i64, d: i64) -> i64 {
64 if b - a != d - c { return 0 }
65 var i: i64 = 0
66 while a + i < b { if q[a+i] != r[c+i] { return 0 } i = i + 1 }
67 return 1
68}
69// split line [ls,le) into up to RO_MAXCOL (start,end) pairs
70func ro_cols(q: *u8, ls: i64, le: i64, sp: *i64) -> i64 {
71 var c: i64 = 0
72 var p: i64 = ls
73 while c < RO_MAXCOL {
74 var e: i64 = p
75 var s: i64 = 1
76 while s == 1 { if e >= le { s = 0 } else { if q[e] == (RO_TAB as u8) { s = 0 } else { e = e + 1 } } }
77 sp[c*RO_PAIR] = p
78 sp[c*RO_PAIR+1] = e
79 c = c + 1
80 if e >= le { return c }
81 p = e + 1
82 }
83 return c
84}
85// copy slice verbatim
86func ro_cat_slice(d: *u8, o: i64, q: *u8, a: i64, b: i64) -> i64 {
87 var oo: i64 = o
88 var i: i64 = a
89 while i < b { d[oo] = q[i]; oo = oo + 1; i = i + 1 }
90 return oo
91}
92// copy slice HTML-escaped (plane text is authored data, not markup)
93func ro_cat_esc(d: *u8, o: i64, q: *u8, a: i64, b: i64) -> i64 {
94 var oo: i64 = o
95 var i: i64 = a
96 while i < b {
97 let c: i64 = q[i] as i64
98 if c == RO_LT { oo = ss_cat(d, oo, "<" as *u8) }
99 else { if c == RO_GT { oo = ss_cat(d, oo, ">" as *u8) }
100 else { if c == RO_AMP { oo = ss_cat(d, oo, "&" as *u8) }
101 else { d[oo] = q[i]; oo = oo + 1 } } }
102 i = i + 1
103 }
104 return oo
105}
106
107func main() -> i64 {
108 let buf: *u8 = sts_mm(RO_RCAP)
109 let flags: *i64 = sts_mm(RO_FLAGB) as *i64
110 let n: i64 = sts_load_honest(RO_PLANE, buf, RO_RCAP, flags)
111 if n <= 0 {
112 ro_werr("OCEAN-RED plane EMPTY / unseeded: knowledge/store/resbrief-\n" as *u8)
113 sys_exit(RO_EXIT_EMPTY)
114 return RO_EXIT_EMPTY
115 }
116 let h: *u8 = sts_mm(RO_HCAP)
117 let sp: *i64 = sts_mm(RO_SPB) as *i64
118 let sp2: *i64 = sts_mm(RO_SPB) as *i64
119 let ar: *i64 = sts_mm(RO_AREAB) as *i64
120 let now: i64 = sys_now_realtime_sec()
121
122 // ---- pass 1: distinct areas, first-seen order (this is what makes a new area free) ----
123 var nar: i64 = 0
124 var i: i64 = 0
125 while i < n {
126 var le: i64 = i
127 var s: i64 = 1
128 while s == 1 { if le >= n { s = 0 } else { if buf[le] == (RO_NL as u8) { s = 0 } else { le = le + 1 } } }
129 if le > i {
130 let nc: i64 = ro_cols(buf, i, le, sp)
131 if nc > RO_C_AREA {
132 let aa: i64 = sp[RO_C_AREA*RO_PAIR]
133 let ab: i64 = sp[RO_C_AREA*RO_PAIR+1]
134 var seen: i64 = 0
135 var k: i64 = 0
136 while k < nar {
137 if ro_slice_eq(buf, aa, ab, buf, ar[k*RO_PAIR], ar[k*RO_PAIR+1]) == 1 { seen = 1 }
138 k = k + 1
139 }
140 if seen == 0 { if nar < RO_MAXAREA {
141 ar[nar*RO_PAIR] = aa
142 ar[nar*RO_PAIR+1] = ab
143 nar = nar + 1
144 } }
145 }
146 }
147 i = le + 1
148 }
149
150 // ---- page head ----
151 var w: i64 = 0
152 w = ss_cat(h, w, "<!doctype html>\n<html lang='en'><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'>\n<title>research - the nishi ocean</title>\n<style>\n" as *u8)
153 w = ss_cat(h, w, ":root{--bg:#fff;--sf:#f6f8fb;--br:#dfe4ec;--ink:#232936;--mut:#68748a;--acc:#1a5dc8;--acc2:#2e8555;--hd:#111726;--hov:#f0f4fa}\n" as *u8)
154 w = ss_cat(h, w, "@media(prefers-color-scheme:dark){:root{--bg:#0d1017;--sf:#131826;--br:#252d40;--ink:#dbe2ec;--mut:#8a94a8;--acc:#5aa7f0;--acc2:#86c793;--hd:#eef2f8;--hov:#141a28}}\n" as *u8)
155 w = ss_cat(h, w, "*{box-sizing:border-box}body{font-family:system-ui,'Segoe UI',sans-serif;margin:0;background:var(--bg);color:var(--ink);padding:22px 30px 40px;line-height:1.55}\n" as *u8)
156 w = ss_cat(h, w, "main{max-width:1080px;margin:0 auto}a{color:var(--acc);text-decoration:none}a:hover{text-decoration:underline}\n" as *u8)
157 w = ss_cat(h, w, "h1{font-size:1.55em;color:var(--hd);margin:2px 0 6px;letter-spacing:-.01em}\n" as *u8)
158 w = ss_cat(h, w, "h2{font-size:1.05em;color:var(--hd);margin:26px 0 8px;padding-bottom:5px;border-bottom:1px solid var(--br)}\n" as *u8)
159 w = ss_cat(h, w, "table{border-collapse:collapse;width:100%;margin:8px 0}td,th{padding:6px 10px;border-bottom:1px solid var(--br);text-align:left;vertical-align:top;font-size:.9em}th{color:var(--mut);font-size:.85em}tr:hover td{background:var(--hov)}\n" as *u8)
160 w = ss_cat(h, w, ".muted{color:var(--mut)}.n{text-align:right;font-variant-numeric:tabular-nums}\n" as *u8)
161 w = ss_cat(h, w, ".nar{background:var(--sf);border:1px solid var(--br);border-left:3px solid var(--acc2);border-radius:8px;padding:12px 16px;font-size:.92em;margin:12px 0}\n" as *u8)
162 w = ss_cat(h, w, ".st{font-weight:600;font-size:.82em;white-space:nowrap}.pub{color:var(--acc2)}.wip{color:#a8792e}.stub{color:var(--mut)}\n" as *u8)
163 w = ss_cat(h, w, "code{font-family:ui-monospace,Consolas,monospace;font-size:.85em}\nfooter{margin-top:36px;padding-top:10px;border-top:1px solid var(--br);font-size:.8em;color:var(--mut)}\n" as *u8)
164 w = ss_cat(h, w, "</style></head><body><main>\n<p class='muted'><a href='/wiki/index.html'>nishi wiki</a> / research</p>\n<h1>Research — the ocean</h1>\n" as *u8)
165 w = ss_cat(h, w, "<p class='muted'>Every research river flows here. Each area keeps its own index — the river — and every brief published in any of them gets exactly one row on this page. Generated by <code>nx_research_ocean</code> from the <code>resbrief-</code> information plane at epoch=" as *u8)
166 w = ss_catn(h, w, now)
167 w = ss_cat(h, w, ".</p>\n" as *u8)
168 w = ss_cat(h, w, "<div class='nar'><b>How to use this page.</b> Before starting ANY research, read this index and search the corpus for your topic. If a brief already covers it, <b>append to it, supersede specific claims with newer sources, or add a sub-brief that forks off it</b> — never start a parallel brief. Re-deriving an existing brief is the redo-work failure this surface exists to end. Sections below are the distinct research areas in the plane; a new area appears here by adding a row, not by editing this page.</div>\n" as *u8)
169
170 // ---- one section per distinct area ----
171 var a: i64 = 0
172 var total: i64 = 0
173 while a < nar {
174 let aa: i64 = ar[a*RO_PAIR]
175 let ab: i64 = ar[a*RO_PAIR+1]
176 w = ss_cat(h, w, "<h2>" as *u8)
177 w = ro_cat_esc(h, w, buf, aa, ab)
178 w = ss_cat(h, w, " research — <a href='/" as *u8)
179 w = ro_cat_slice(h, w, buf, aa, ab)
180 w = ss_cat(h, w, "/research'>the river</a></h2>\n" as *u8)
181 w = ss_cat(h, w, "<table><tr><th>Brief</th><th>Compiled</th><th class='st'>Status</th><th>Forks off</th><th>Scope</th></tr>\n" as *u8)
182 var rows: i64 = 0
183 var j: i64 = 0
184 while j < n {
185 var le2: i64 = j
186 var s2: i64 = 1
187 while s2 == 1 { if le2 >= n { s2 = 0 } else { if buf[le2] == (RO_NL as u8) { s2 = 0 } else { le2 = le2 + 1 } } }
188 if le2 > j {
189 let nc2: i64 = ro_cols(buf, j, le2, sp2)
190 if nc2 >= RO_NCOL {
191 if ro_slice_eq(buf, sp2[RO_C_AREA*RO_PAIR], sp2[RO_C_AREA*RO_PAIR+1], buf, aa, ab) == 1 {
192 let sa: i64 = sp2[RO_C_STATUS*RO_PAIR]
193 let sb: i64 = sp2[RO_C_STATUS*RO_PAIR+1]
194 let isstub: i64 = ro_slice_eqs(buf, sa, sb, "STUB" as *u8)
195 w = ss_cat(h, w, "<tr><td>" as *u8)
196 // STUB rows are corpus-only: there is no served page to link, so do not fake one.
197 if isstub == 1 {
198 w = ss_cat(h, w, "<b>" as *u8)
199 w = ro_cat_esc(h, w, buf, sp2[RO_C_TITLE*RO_PAIR], sp2[RO_C_TITLE*RO_PAIR+1])
200 w = ss_cat(h, w, "</b><br><code class='muted'>" as *u8)
201 w = ro_cat_esc(h, w, buf, sp2[RO_C_SLUG*RO_PAIR], sp2[RO_C_SLUG*RO_PAIR+1])
202 w = ss_cat(h, w, "</code>" as *u8)
203 } else {
204 w = ss_cat(h, w, "<a href='/" as *u8)
205 w = ro_cat_slice(h, w, buf, aa, ab)
206 w = ss_cat(h, w, "/" as *u8)
207 w = ro_cat_slice(h, w, buf, sp2[RO_C_SLUG*RO_PAIR], sp2[RO_C_SLUG*RO_PAIR+1])
208 w = ss_cat(h, w, "'><b>" as *u8)
209 w = ro_cat_esc(h, w, buf, sp2[RO_C_TITLE*RO_PAIR], sp2[RO_C_TITLE*RO_PAIR+1])
210 w = ss_cat(h, w, "</b></a>" as *u8)
211 }
212 w = ss_cat(h, w, "</td><td class='muted'>" as *u8)
213 w = ro_cat_esc(h, w, buf, sp2[RO_C_DATE*RO_PAIR], sp2[RO_C_DATE*RO_PAIR+1])
214 w = ss_cat(h, w, "</td><td class='st " as *u8)
215 if isstub == 1 { w = ss_cat(h, w, "stub" as *u8) } else {
216 if ro_slice_eqs(buf, sa, sb, "PUBLISHED" as *u8) == 1 { w = ss_cat(h, w, "pub" as *u8) } else { w = ss_cat(h, w, "wip" as *u8) }
217 }
218 w = ss_cat(h, w, "'>" as *u8)
219 w = ro_cat_esc(h, w, buf, sa, sb)
220 w = ss_cat(h, w, "</td><td class='muted'>" as *u8)
221 w = ro_cat_esc(h, w, buf, sp2[RO_C_FORKS*RO_PAIR], sp2[RO_C_FORKS*RO_PAIR+1])
222 w = ss_cat(h, w, "</td><td>" as *u8)
223 w = ro_cat_esc(h, w, buf, sp2[RO_C_SCOPE*RO_PAIR], sp2[RO_C_SCOPE*RO_PAIR+1])
224 w = ss_cat(h, w, "</td></tr>\n" as *u8)
225 rows = rows + 1
226 total = total + 1
227 }
228 }
229 }
230 j = le2 + 1
231 }
232 w = ss_cat(h, w, "</table>\n<p class='muted'>" as *u8)
233 w = ss_catn(h, w, rows)
234 w = ss_cat(h, w, " briefs in this area.</p>\n" as *u8)
235 a = a + 1
236 }
237
238 // ---- coverage, rendered ON THE PAGE (a reader must be able to see under-reporting too) ----
239 w = ss_cat(h, w, "<h2>Coverage of this index</h2>\n<table><tr><th>Measure</th><th class='n'>Rows</th><th>Meaning</th></tr>\n" as *u8)
240 w = ss_cat(h, w, "<tr><td>Declared by the plane</td><td class='n'>" as *u8)
241 w = ss_catn(h, w, flags[0])
242 w = ss_cat(h, w, "</td><td class='muted'>the plane's own row count</td></tr>\n<tr><td>Loaded</td><td class='n'>" as *u8)
243 w = ss_catn(h, w, flags[1])
244 w = ss_cat(h, w, "</td><td class='muted'>rows actually read back</td></tr>\n<tr><td>Rendered</td><td class='n'>" as *u8)
245 w = ss_catn(h, w, total)
246 w = ss_cat(h, w, "</td><td class='muted'>rows on this page — must equal Loaded, else a row is malformed</td></tr>\n<tr><td>Reachable beyond the count</td><td class='n'>" as *u8)
247 w = ss_catn(h, w, flags[2])
248 w = ss_cat(h, w, "</td><td class='muted'>records past the declared count (older seeding generation); non-zero means reconcile</td></tr>\n</table>\n" as *u8)
249 if flags[1] != total { w = ss_cat(h, w, "<p class='nar'><b>WARNING:</b> loaded and rendered disagree — at least one plane row is malformed (wrong column count) and is missing from the sections above. This page is INCOMPLETE.</p>\n" as *u8) }
250 if flags[2] > 0 { w = ss_cat(h, w, "<p class='nar'><b>WARNING:</b> records exist past the declared count. This index may be under-reporting the library.</p>\n" as *u8) }
251
252 w = ss_cat(h, w, "<footer>Generated sovereignly by <code>nx_research_ocean</code> from <code>knowledge/store/resbrief-</code>. Rivers: <a href='/code/research'>/code/research</a> · <a href='/product/research'>/product/research</a>. Add a research area by adding a plane row — this page needs no edit. Nishi ecosystem.</footer>\n</main></body></html>\n" as *u8)
253
254 let fd: i64 = sys_openat_wr(RO_OUT, RO_MODE)
255 if fd < 0 {
256 ro_werr("OCEAN-RED cannot open sites/nishifamily/wiki/research.html for write\n" as *u8)
257 sys_exit(RO_EXIT_IO)
258 return RO_EXIT_IO
259 }
260 sys_write(fd, h, w)
261 sys_close(fd)
262
263 let m: *u8 = sts_mm(512)
264 var o: i64 = ss_cat(m, 0, "OCEAN-GREEN areas=" as *u8)
265 o = ss_catn(m, o, nar)
266 o = ss_cat(m, o, " rendered=" as *u8)
267 o = ss_catn(m, o, total)
268 o = ss_cat(m, o, " declared=" as *u8)
269 o = ss_catn(m, o, flags[0])
270 o = ss_cat(m, o, " loaded=" as *u8)
271 o = ss_catn(m, o, flags[1])
272 o = ss_cat(m, o, " beyond=" as *u8)
273 o = ss_catn(m, o, flags[2])
274 o = ss_cat(m, o, " bytes=" as *u8)
275 o = ss_catn(m, o, w)
276 m[o] = RO_NL as u8
277 o = o + 1
278 sys_write(1, m, o)
279 sys_exit(0)
280 return 0
281}