code wiki / _hdl_build / nx_work_wiki.nx

nx_work_wiki.nx source

↩ module page · 248 lines · 12613 B

1// nx_work_wiki.nx -- the COMPREHENSIVE Work Board on the shared design skin. Renders the WHOLE picture 2// from live on-disk sources (regenerated each pulse, never a hand-seed): 3// DELEGATION -- coordination.tsv (active streams, West Industrial owners, floating-supervision flags) 4// FULL BACKLOG-- EVERY workstream from the resume-manifest auto-index (~389, the real landscape) 5// PRESENT -- worklog.tsv newest actions (refreshed each generation) 6// FUTURE -- predict_next.txt adjacent-possible next-work 7// Sovereign (nx_syscalls + nx_wiki_skin_lib). Emits /tmp/nx_work_board.html + nx_aw_push specs. 8// license_tier: ORIGINAL 9import "nx_syscalls.nx" 10import "nx_wiki_skin_lib.nx" 11const WW_MAGIC_8192: i64 = 8192 12const WW_MAGIC_200000: i64 = 200000 13const WW_MAGIC_8388608: i64 = 8388608 14const WW_MAGIC_2097152: i64 = 2097152 15 16const WW_WORKLOG: *u8 = "/mnt/c/Users/elder/.claude/projects/C--Users-elder/memory/worklog/worklog.tsv" 17const WW_PREDICT: *u8 = "/mnt/c/Users/elder/.claude/projects/C--Users-elder/memory/worklog/predict_next.txt" 18const WW_COORD: *u8 = "/mnt/c/Users/elder/.claude/projects/C--Users-elder/memory/worklog/coordination.tsv" 19const WW_MANIFEST: *u8 = "/mnt/c/Users/elder/.claude/projects/C--Users-elder/memory/workstream-resume-manifest.md" 20const WW_OUT: *u8 = "/tmp/nx_work_board.html" 21const WW_SRC: *u8 = "/tmp/nx_work_board.src" 22const WW_DST: *u8 = "/tmp/nx_work_board.dst" 23const WW_SRCVAL: *u8 = "/tmp/nx_work_board.html\n" 24const WW_DSTVAL: *u8 = "cat > /volume1/homes/elderwesto/nishihost/sites/nishifamily/wiki/board.html\n" 25const WW_PRESENT_N: i64 = 30 26const WW_FUTURE_N: i64 = 30 27 28func ww_slurp(path: *u8, buf: *u8, cap: i64) -> i64 { 29 let fd: i64 = sys_openat_rd(path) 30 if fd < 0 { return 0 } 31 var total: i64 = 0 32 var nrd: i64 = sys_read(fd, buf, cap) 33 while nrd > 0 { total = total + nrd; if total >= cap { nrd = 0 } else { nrd = sys_read(fd, ((buf as i64) + total) as *u8, cap - total) } } 34 sys_close(fd) 35 return total 36} 37func ww_index_lines(buf: *u8, len: i64, starts: *i64, maxlines: i64) -> i64 { 38 if len <= 0 { return 0 } 39 var n: i64 = 1; starts[0] = 0; var i: i64 = 0 40 while i < len { if buf[i] == (10 as u8) { if i + 1 < len { if n < maxlines { starts[n] = i + 1; n = n + 1 } } } i = i + 1 } 41 return n 42} 43func ww_line_end(buf: *u8, len: i64, s: i64) -> i64 { var e: i64 = s; while e < len { if buf[e] == (10 as u8) { return e } e = e + 1 } return len } 44func ww_esc(dst: *u8, off: i64, buf: *u8, a: i64, b: i64) -> i64 { 45 var o: i64 = off; var i: i64 = a 46 while i < b { 47 let c: i64 = buf[i] as i64 48 if c == 60 { o = sk_cat(dst, o, "&lt;" as *u8) } 49 else { if c == 62 { o = sk_cat(dst, o, "&gt;" as *u8) } 50 else { if c == 38 { o = sk_cat(dst, o, "&amp;" as *u8) } 51 else { if c == 9 { o = sk_cat(dst, o, " &middot; " as *u8) } 52 else { dst[o] = c as u8; o = o + 1 } } } } 53 i = i + 1 54 } 55 return o 56} 57func ww_emit_field(dst: *u8, off: i64, buf: *u8, s: i64, e: i64, k: i64) -> i64 { 58 var o: i64 = off; var field: i64 = 0; var i: i64 = s 59 while i < e { 60 if buf[i] == (9 as u8) { field = field + 1; i = i + 1 } else { 61 if field == k { 62 let c: i64 = buf[i] as i64 63 if c == 60 { o = sk_cat(dst, o, "&lt;" as *u8) } 64 else { if c == 62 { o = sk_cat(dst, o, "&gt;" as *u8) } 65 else { if c == 38 { o = sk_cat(dst, o, "&amp;" as *u8) } 66 else { dst[o] = c as u8; o = o + 1 } } } 67 } 68 i = i + 1 69 } 70 } 71 return o 72} 73func ww_field_eq(buf: *u8, s: i64, e: i64, k: i64, lit: *u8) -> i64 { 74 var field: i64 = 0; var i: i64 = s; var li: i64 = 0; var matched: i64 = 1 75 while i < e { 76 if buf[i] == (9 as u8) { field = field + 1; i = i + 1 } else { 77 if field == k { if lit[li] == (0 as u8) { matched = 0 } else { if buf[i] != lit[li] { matched = 0 } } li = li + 1 } 78 i = i + 1 79 } 80 } 81 if lit[li] != (0 as u8) { matched = 0 } 82 if matched == 1 { return 1 } 83 return 0 84} 85func ww_find(buf: *u8, len: i64, pat: *u8) -> i64 { 86 var pl: i64 = 0; while pat[pl] != (0 as u8) { pl = pl + 1 } 87 if pl == 0 { return 0 - 1 } 88 var i: i64 = 0 89 while i + pl <= len { 90 var j: i64 = 0; var ok: i64 = 1 91 while j < pl { if buf[i + j] != pat[j] { ok = 0; j = pl } else { j = j + 1 } } 92 if ok == 1 { return i } 93 i = i + 1 94 } 95 return 0 - 1 96} 97 98// DELEGATION table from coordination.tsv; returns floating count. 99func ww_count_floating(buf: *u8, len: i64, starts: *i64) -> i64 { 100 let nl: i64 = ww_index_lines(buf, len, starts, WW_MAGIC_8192); var k: i64 = 0; var f: i64 = 0 101 while k < nl { let s: i64 = starts[k]; let e: i64 = ww_line_end(buf, len, s); if e > s { if ww_field_eq(buf, s, e, 1, "UNASSIGNED" as *u8) == 1 { f = f + 1 } } k = k + 1 } 102 return f 103} 104func ww_emit_coord(dst: *u8, off0: i64, buf: *u8, len: i64, starts: *i64) -> i64 { 105 var o: i64 = off0 106 let nl: i64 = ww_index_lines(buf, len, starts, WW_MAGIC_8192) 107 o = sk_cat(dst, o, "<table><thead><tr><th>Workstream</th><th>Owner</th><th>State</th><th>Next action</th></tr></thead><tbody>\n" as *u8) 108 var k: i64 = 0 109 while k < nl { 110 let s: i64 = starts[k]; let e: i64 = ww_line_end(buf, len, s) 111 if e > s { 112 let un: i64 = ww_field_eq(buf, s, e, 1, "UNASSIGNED" as *u8) 113 if un == 1 { o = sk_cat(dst, o, "<tr class=\"floating\">" as *u8) } else { o = sk_cat(dst, o, "<tr>" as *u8) } 114 o = sk_cat(dst, o, "<td><code>" as *u8); o = ww_emit_field(dst, o, buf, s, e, 0); o = sk_cat(dst, o, "</code></td><td>" as *u8) 115 if un == 1 { o = sk_cat(dst, o, "<span class=\"warn\">&#9888; assign</span>" as *u8) } else { o = ww_emit_field(dst, o, buf, s, e, 1) } 116 o = sk_cat(dst, o, "</td><td>" as *u8); o = ww_emit_field(dst, o, buf, s, e, 2) 117 o = sk_cat(dst, o, "</td><td>" as *u8); o = ww_emit_field(dst, o, buf, s, e, 3) 118 o = sk_cat(dst, o, "</td></tr>\n" as *u8) 119 } 120 k = k + 1 121 } 122 o = sk_cat(dst, o, "</tbody></table>\n" as *u8) 123 return o 124} 125 126// count [[workstream]] entries in the manifest auto-index (for the section header). 127func ww_count_backlog(buf: *u8, len: i64) -> i64 { 128 var b: i64 = ww_find(buf, len, "WS-AUTO-INDEX:BEGIN" as *u8) 129 var e: i64 = ww_find(buf, len, "WS-AUTO-INDEX:END" as *u8) 130 if b < 0 { b = 0 } 131 if e < 0 { e = len } 132 var i: i64 = b; var count: i64 = 0 133 while i + 1 < e { if buf[i] == (91 as u8) { if buf[i + 1] == (91 as u8) { count = count + 1; i = i + 2 } else { i = i + 1 } } else { i = i + 1 } } 134 return count 135} 136// FULL BACKLOG: every [[workstream]] in the resume-manifest auto-index. returns count via out_cnt[0]. 137func ww_emit_backlog(dst: *u8, off0: i64, buf: *u8, len: i64, out_cnt: *i64) -> i64 { 138 var o: i64 = off0 139 var b: i64 = ww_find(buf, len, "WS-AUTO-INDEX:BEGIN" as *u8) 140 var e: i64 = ww_find(buf, len, "WS-AUTO-INDEX:END" as *u8) 141 if b < 0 { b = 0 } 142 if e < 0 { e = len } 143 o = sk_cat(dst, o, "<ul class=\"feed\" style=\"max-height:460px;columns:2;column-gap:24px\">\n" as *u8) 144 var i: i64 = b; var count: i64 = 0 145 while i < e { 146 if buf[i] == (91 as u8) { // '[' 147 if i + 1 < e { if buf[i + 1] == (91 as u8) { // "[[" 148 var k: i64 = i + 2 149 o = sk_cat(dst, o, "<li>" as *u8) 150 var go: i64 = 1 151 while go == 1 { 152 if k + 1 >= e { go = 0 } else { 153 if buf[k] == (93 as u8) { if buf[k + 1] == (93 as u8) { go = 0 } } 154 } 155 if go == 1 { 156 let c: i64 = buf[k] as i64 157 if c == 60 { o = sk_cat(dst, o, "&lt;" as *u8) } else { if c == 62 { o = sk_cat(dst, o, "&gt;" as *u8) } else { if c == 38 { o = sk_cat(dst, o, "&amp;" as *u8) } else { dst[o] = c as u8; o = o + 1 } } } 158 k = k + 1 159 } 160 } 161 o = sk_cat(dst, o, "</li>\n" as *u8) 162 count = count + 1 163 i = k + 2 164 } else { i = i + 1 } } else { i = i + 1 } 165 } else { i = i + 1 } 166 } 167 o = sk_cat(dst, o, "</ul>\n" as *u8) 168 out_cnt[0] = count 169 return o 170} 171 172func ww_emit_present(dst: *u8, off0: i64, buf: *u8, len: i64, starts: *i64) -> i64 { 173 var o: i64 = off0 174 let nl: i64 = ww_index_lines(buf, len, starts, WW_MAGIC_200000) 175 o = sk_cat(dst, o, "<ul class=\"feed\">\n" as *u8) 176 var from: i64 = nl - WW_PRESENT_N; if from < 0 { from = 0 } 177 var k: i64 = nl - 1 178 while k >= from { 179 let s: i64 = starts[k]; let e: i64 = ww_line_end(buf, len, s) 180 if e > s { o = sk_cat(dst, o, "<li>" as *u8); o = ww_emit_field(dst, o, buf, s, e, 2); o = sk_cat(dst, o, " " as *u8); o = ww_emit_field(dst, o, buf, s, e, 3); o = sk_cat(dst, o, "</li>\n" as *u8) } 181 k = k - 1 182 } 183 o = sk_cat(dst, o, "</ul>\n" as *u8) 184 return o 185} 186func ww_emit_topn(dst: *u8, off0: i64, buf: *u8, len: i64, starts: *i64, n: i64) -> i64 { 187 var o: i64 = off0 188 let nl: i64 = ww_index_lines(buf, len, starts, WW_MAGIC_200000) 189 o = sk_cat(dst, o, "<ul class=\"feed\">\n" as *u8) 190 var k: i64 = 0 191 while k < nl { if k < n { let s: i64 = starts[k]; let e: i64 = ww_line_end(buf, len, s); if e > s { o = sk_cat(dst, o, "<li>" as *u8); o = ww_esc(dst, o, buf, s, e); o = sk_cat(dst, o, "</li>\n" as *u8) } } k = k + 1 } 192 o = sk_cat(dst, o, "</ul>\n" as *u8) 193 return o 194} 195func ww_write(path: *u8, content: *u8) -> i64 { 196 let fd: i64 = sys_openat_wr(path, 420) 197 if fd < 0 { return 0 - 1 } 198 var n: i64 = 0; while content[n] != (0 as u8) { n = n + 1 } 199 sys_write(fd, content, n); sys_close(fd); return 0 200} 201 202func main(argc: i64, argv: *i64) -> i64 { 203 let h: *u8 = sys_mmap(WW_MAGIC_8388608) 204 let fbuf: *u8 = sys_mmap(WW_MAGIC_8388608) 205 let starts: *i64 = sys_mmap(WW_MAGIC_2097152) as *i64 206 let cnt: *i64 = sys_mmap(8) as *i64 207 var w: i64 = 0 208 209 w = skin_open(h, w, "Work Board" as *u8, "board" as *u8) 210 w = sk_cat(h, w, "<h1>Work Board</h1>\n<p class=\"sub\">The live planning surface &mdash; operator, AI, and Nishi PM triangulate the next hardware-up rung. No floaters.</p>\n" as *u8) 211 212 // DELEGATION 213 let clen: i64 = ww_slurp(WW_COORD, fbuf, WW_MAGIC_8388608) 214 let floating: i64 = ww_count_floating(fbuf, clen, starts) 215 w = sk_cat(h, w, "<h2>Delegation &amp; coordination</h2>\n<p class=\"sub\">Who supervises what. Unassigned = " as *u8) 216 w = sk_catn(h, w, floating); w = sk_cat(h, w, " <span class=\"warn\">floating</span>.</p>\n" as *u8) 217 if clen > 0 { w = ww_emit_coord(h, w, fbuf, clen, starts) } 218 219 // FULL BACKLOG (every workstream) 220 let mlen: i64 = ww_slurp(WW_MANIFEST, fbuf, WW_MAGIC_8388608) 221 w = sk_cat(h, w, "<h2>Full backlog &mdash; every workstream</h2>\n" as *u8) 222 if mlen > 0 { 223 let bc: i64 = ww_count_backlog(fbuf, mlen) 224 w = sk_cat(h, w, "<p class=\"sub\">" as *u8); w = sk_catn(h, w, bc); w = sk_cat(h, w, " workstreams in the registry &mdash; the whole landscape.</p>\n" as *u8) 225 w = ww_emit_backlog(h, w, fbuf, mlen, cnt) 226 } else { w = sk_cat(h, w, "<p class=\"sub\">manifest not found</p>\n" as *u8) } 227 228 // PRESENT 229 let plen: i64 = ww_slurp(WW_WORKLOG, fbuf, WW_MAGIC_8388608) 230 w = sk_cat(h, w, "<h2>Present &mdash; work as it happens</h2>\n<p class=\"sub\">Newest captured actions (crash-proof journal; this page refreshes on each pulse).</p>\n" as *u8) 231 if plen > 0 { w = ww_emit_present(h, w, fbuf, plen, starts) } 232 233 // FUTURE 234 let flen: i64 = ww_slurp(WW_PREDICT, fbuf, WW_MAGIC_8388608) 235 w = sk_cat(h, w, "<h2>Future &mdash; predicted next-work</h2>\n<p class=\"sub\">Adjacent-possible rungs: prerequisites done, not yet started.</p>\n" as *u8) 236 if flen > 0 { w = ww_emit_topn(h, w, fbuf, flen, starts, WW_FUTURE_N) } 237 238 w = skin_close(h, w, sys_now_realtime_sec()) 239 240 let outfd: i64 = sys_openat_wr(WW_OUT, 420) 241 if outfd < 0 { sys_write(2, "WW-FAIL\n" as *u8, 8); sys_exit(1); return 1 } 242 sys_write(outfd, h, w); sys_close(outfd) 243 ww_write(WW_SRC, WW_SRCVAL); ww_write(WW_DST, WW_DSTVAL) 244 let r: *u8 = sys_mmap(128); var ro: i64 = 0 245 ro = sk_cat(r, ro, "WORK-WIKI-OK bytes=" as *u8); ro = sk_catn(r, ro, w); ro = sk_cat(r, ro, " backlog=" as *u8); ro = sk_catn(r, ro, cnt[0]); ro = sk_cat(r, ro, " floating=" as *u8); ro = sk_catn(r, ro, floating); ro = sk_cat(r, ro, "\n" as *u8) 246 sys_write(1, r, ro) 247 sys_exit(0); return 0 248}