code wiki / _hdl_build / nx_common_tasks.nx
nx_common_tasks.nx source
↩ module page · 212 lines · 11964 B
1// nx_common_tasks.nx -- THE COMMON-TASK CANONICAL REGISTRY (operator 2026-07-17: "arent thing like
2// api and cron a workstream ... we need logical reviews of all these common tasks that should be unified").
3// A sovereign seg-store catalog (knowledge/store/commontask-) of the recurring ecosystem "verbs": for each,
4// the ONE canonical organ, its RACI owner, exposure state, and the CONSOLIDATION DEBT (how many bespoke
5// duplicates bypass the canonical). This is the logical review made DURABLE + STORE-LAW (no flat .tsv) +
6// OWNED -- the SSOT future sessions consult so nobody re-hand-rolls publish/cron/gate/seed again.
7// Reuses frs_seed/frs_load (the generic tsv-buffer<->seg-store codec) -- dogfooding the very "one store-seed,
8// not 30 bespoke" unification this registry records as debt.
9// verbs: seed | list (default -> JSON, the api/mcp/agent interchange) | html (-> argv[2] or stdout)
10// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
11import "nx_frontier_store.nx"
12import "nx_seg_store.nx"
13import "nx_syscalls.nx"
14import "nx_html_head.nx" // seq702: the ONE accessible head; migrate-on-touch
15
16const CT_PREFIX: *u8 = "knowledge/store/commontask-"
17const CT_NREC: i64 = 10 // number of catalog records
18const CT_NFLD: i64 = 7 // fields per record
19const CT_TAB: i64 = 9
20const CT_NL: i64 = 10
21const CT_ZERO: i64 = 48
22const CT_HTMLH: i64 = 104 // 'h' -- html verb selector
23const CT_SEEDS: i64 = 115 // 's' -- seed verb selector
24const CT_QCAP: i64 = 262144
25const CT_OUTCAP: i64 = 262144
26const CT_SPWORDS: i64 = 16 // 7 fields * 2 (start,end) + slack, in i64
27const CT_STDERR: i64 = 2
28const CT_ARGC_OUT: i64 = 3
29const CT_IDX_OUT: i64 = 2
30const CT_PAIR: i64 = 2 // ct_cols stores each field as a (start,end) pair
31const CT_DQUOTE: i64 = 34 // '"' -- JSON escape
32const CT_BSLASH: i64 = 92 // '\' -- JSON escape
33const CT_MODE: i64 = 0x1a4 // 0644 html out perms
34const CT_I64: i64 = 8 // sizeof(i64) -- sp pair-array stride
35const CT_VHTML: i64 = 2 // verb selector: emit HTML board
36// field (start,end) offsets into the ct_cols pair array -- the commontask record schema:
37const CTF_TASK_A: i64 = 0
38const CTF_TASK_B: i64 = 1
39const CTF_ORGAN_A: i64 = 2
40const CTF_ORGAN_B: i64 = 3
41const CTF_OWNER_A: i64 = 4
42const CTF_OWNER_B: i64 = 5
43const CTF_EXP_A: i64 = 6
44const CTF_EXP_B: i64 = 7
45const CTF_STATE_A: i64 = 8
46const CTF_STATE_B: i64 = 9
47const CTF_DUPS_A: i64 = 10
48const CTF_DUPS_B: i64 = 11
49const CTF_NOTE_A: i64 = 12
50const CTF_NOTE_B: i64 = 13
51
52func ct_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
53func ct_werr(s: *u8) -> i64 { sys_write(CT_STDERR, s, ct_slen(s)); return 0 }
54func ct_puts(buf: *u8, off: i64, s: *u8) -> i64 {
55 var o: i64 = off
56 var j: i64 = 0
57 while s[j] != (0 as u8) { buf[o] = s[j]; o = o + 1; j = j + 1 }
58 return o
59}
60func ct_putsl(buf: *u8, off: i64, q: *u8, a: i64, b: i64) -> i64 {
61 var o: i64 = off
62 var i: i64 = a
63 while i < b { buf[o] = q[i]; o = o + 1; i = i + 1 }
64 return o
65}
66// JSON-escape a slice (", \, control) into buf
67func ct_putj(buf: *u8, off: i64, q: *u8, a: i64, b: i64) -> i64 {
68 var o: i64 = off
69 var i: i64 = a
70 while i < b {
71 let c: i64 = q[i] as i64
72 if c == CT_DQUOTE { buf[o] = CT_BSLASH as u8; o = o + 1; buf[o] = CT_DQUOTE as u8; o = o + 1 }
73 else { if c == CT_BSLASH { buf[o] = CT_BSLASH as u8; o = o + 1; buf[o] = CT_BSLASH as u8; o = o + 1 }
74 else { buf[o] = q[i]; o = o + 1 } }
75 i = i + 1
76 }
77 return o
78}
79// split line [ls,le) into up to CT_NFLD (start,end) pairs in sp; returns field count
80func ct_cols(q: *u8, ls: i64, le: i64, sp: *i64) -> i64 {
81 var c: i64 = 0
82 var p: i64 = ls
83 while c < CT_NFLD {
84 var e: i64 = p
85 var s: i64 = 1
86 while s == 1 { if e >= le { s = 0 } else { if q[e] == (CT_TAB as u8) { s = 0 } else { e = e + 1 } } }
87 sp[c*CT_PAIR] = p
88 sp[c*CT_PAIR+1] = e
89 c = c + 1
90 if e >= le { return c }
91 p = e + 1
92 }
93 return c
94}
95
96// append one catalog record + newline; returns new offset
97func ct_row(buf: *u8, o: i64, rec: *u8) -> i64 {
98 let n: i64 = ct_puts(buf, o, rec)
99 buf[n] = CT_NL as u8
100 return n + 1
101}
102// the catalog: task \t canonical-organ \t raci-owner \t exposure \t state \t dup-count \t note
103func ct_seed() -> i64 {
104 let buf: *u8 = sys_mmap(CT_QCAP)
105 var o: i64 = 0
106 o = ct_row(buf, o, "publish\tnx_site_publish\tsites\tmcp-live\tLIVE\t35\t~35 domain *_publish.nx bypass it + wiki forks ssh-cat aw_push -- consolidate onto site_publish_lib" as *u8)
107 o = ct_row(buf, o, "deploy\tnx_mgmt_api\tsupervisor\tmcp-live\tLIVE\t0\t/api/build+/api/promote canonical; nx_ship + nx_content_ship COMPOSE it (not dupes)" as *u8)
108 o = ct_row(buf, o, "cron\tnx_cron\tconductor\tinternal\tWIRE\t6\tbuilt PARTIAL (in-mem table, no durability) AND not mcp-exposed -- add durability + expose" as *u8)
109 o = ct_row(buf, o, "api-route\tnx_mgmt_api+proxy_routes\tengineer\tflat\tWIRE\t0\tapp routes = flat proxy_routes.conf (store-law); ctrl-plane verbs hardcoded in ma_handle" as *u8)
110 o = ct_row(buf, o, "mcp-register\tnx_tool_registry\twarden\tmcp-live\tLIVE\t18\t18 thin *_tool_register wrappers compose the lib; allowlist+schemas flat; F-210 register-half open" as *u8)
111 o = ct_row(buf, o, "ws-register\tnx_workstream_store\tpm\tinternal\tWIRE\t7\tseg-store SSOT but NO ws_put symbol + not mcp-exposed; 7 bespoke *_ws_register wrappers" as *u8)
112 o = ct_row(buf, o, "gate\tnx_gate_green\treferee\tinternal\tGAP\t2555\t2555 gate organs, 0 import the DRY verdict lib -- the worst hand-roll; consolidate" as *u8)
113 o = ct_row(buf, o, "store-seed\tnx_seg_store\tjanitor\tinternal\tWIRE\t30\tno generic migrate-any-plane tool; bespoke per plane (frs_* is already generic -- promote to nx_store_seed)" as *u8)
114 o = ct_row(buf, o, "bank-memory\tnx_coindex\tlibrarian\tinternal\tLIVE\t0\tcanonical 2-rail (coindex append + memindex_emit); not mcp-exposed" as *u8)
115 o = ct_row(buf, o, "verify-url\tnx_https_get\tracing\tmcp-partial\tWIRE\t0\thttps_get mcp-live; nx_page_verify (browser-grade) NOT exposed" as *u8)
116 // PLANE LOCK (seq1559). frs_seed -> sts_seed REPLACES the whole plane, so this overwrite must not
117 // interleave with another writer's read-modify-write on the same prefix -- that is the lost-update
118 // path: the other writer loads, we replace, it commits its stale buffer and our rows are gone.
119 // FAIL-CLOSED: a lock we could not take is a REFUSAL, never a licence to proceed unlocked.
120 let lk: i64 = sts_lock(CT_PREFIX)
121 if lk <= 0 { return 0 - 1 }
122 let rc: i64 = frs_seed(CT_PREFIX, buf, o)
123 sts_unlock(lk)
124 return rc
125}
126
127func main(argc: i64, argv: *i64) -> i64 {
128 // verb: default = list(JSON); "seed" -> populate store; "html" -> board page
129 var verb: i64 = 0 // 0 list, 1 seed, 2 html
130 if argc > 1 {
131 let a1: *u8 = argv[1] as *u8
132 if a1[0] == (CT_SEEDS as u8) { verb = 1 }
133 if a1[0] == (CT_HTMLH as u8) { verb = CT_VHTML }
134 }
135 if verb == 1 {
136 let cnt: i64 = ct_seed()
137 if cnt < 0 { ct_werr("SEED-FAIL\n" as *u8); sys_exit(1); return 1 }
138 let mb: *u8 = sys_mmap(CT_SPWORDS * CT_NFLD)
139 var mo: i64 = ct_puts(mb, 0, "SEEDED knowledge/store/commontask- rows=" as *u8)
140 mo = ss_catn(mb, mo, cnt)
141 mb[mo] = CT_NL as u8; mo = mo + 1
142 sys_write(1, mb, mo)
143 sys_exit(0)
144 return 0
145 }
146
147 // read the store
148 let q: *u8 = sys_mmap(CT_QCAP)
149 let qn: i64 = frs_load(CT_PREFIX, q, CT_QCAP)
150 if qn <= 0 { ct_werr("commontask store EMPTY -- run: nx_common_tasks seed\n" as *u8); sys_exit(1); return 1 }
151 let out: *u8 = sys_mmap(CT_OUTCAP)
152 let sp: *i64 = sys_mmap(CT_SPWORDS * CT_I64) as *i64
153 var o: i64 = 0
154
155 if verb == CT_VHTML {
156 o = nxh_head_open(out, o, "Common Tasks" as *u8)
157 o = ct_puts(out, o, "<style>body{background:#0b0f14;color:#d4dae3;font:15px/1.5 system-ui,sans-serif;margin:0;padding:24px}h1{font-size:22px}.m{color:#8a93a3}table{border-collapse:collapse;width:100%;font-size:13px;margin-top:12px}td,th{border-bottom:1px solid #232833;padding:5px 9px;text-align:left;vertical-align:top}th{color:#8a93a3}.L{color:#3fb950}.W{color:#d29922}.G{color:#f85149}</style>" as *u8)
158 o = nxh_body_open(out, o)
159 o = ct_puts(out, o, "<h1>Nishi Common-Task Registry</h1><p class=\"m\">The canonical way to do each recurring ecosystem task -- sovereign seg-store (store-law), RACI-owned. `dups` = bespoke variants bypassing the canonical = the consolidation backlog.</p><table><tr><th>task</th><th>canonical organ</th><th>owner</th><th>exposure</th><th>state</th><th>dups</th><th>note</th></tr>" as *u8)
160 } else {
161 o = ct_puts(out, o, "{\"registry\":\"common-tasks\",\"store\":\"knowledge/store/commontask-\",\"tasks\":[" as *u8)
162 }
163
164 var first: i64 = 1
165 var i: i64 = 0
166 while i < qn {
167 var le: i64 = i
168 var s: i64 = 1
169 while s == 1 { if le >= qn { s = 0 } else { if q[le] == (CT_NL as u8) { s = 0 } else { le = le + 1 } } }
170 if le > i {
171 let nc: i64 = ct_cols(q, i, le, sp)
172 if nc == CT_NFLD {
173 if verb == CT_VHTML {
174 o = ct_puts(out, o, "<tr><td>" as *u8); o = ct_putsl(out, o, q, sp[CTF_TASK_A], sp[CTF_TASK_B])
175 o = ct_puts(out, o, "</td><td><code>" as *u8); o = ct_putsl(out, o, q, sp[CTF_ORGAN_A], sp[CTF_ORGAN_B])
176 o = ct_puts(out, o, "</code></td><td>" as *u8); o = ct_putsl(out, o, q, sp[CTF_OWNER_A], sp[CTF_OWNER_B])
177 o = ct_puts(out, o, "</td><td>" as *u8); o = ct_putsl(out, o, q, sp[CTF_EXP_A], sp[CTF_EXP_B])
178 o = ct_puts(out, o, "</td><td class=\"" as *u8)
179 o = ct_putsl(out, o, q, sp[CTF_STATE_A], sp[CTF_STATE_A]+1) // first letter of state -> class L/W/G
180 o = ct_puts(out, o, "\">" as *u8); o = ct_putsl(out, o, q, sp[CTF_STATE_A], sp[CTF_STATE_B])
181 o = ct_puts(out, o, "</td><td>" as *u8); o = ct_putsl(out, o, q, sp[CTF_DUPS_A], sp[CTF_DUPS_B])
182 o = ct_puts(out, o, "</td><td>" as *u8); o = ct_putsl(out, o, q, sp[CTF_NOTE_A], sp[CTF_NOTE_B])
183 o = ct_puts(out, o, "</td></tr>" as *u8)
184 } else {
185 if first == 0 { o = ct_puts(out, o, "," as *u8) }
186 first = 0
187 o = ct_puts(out, o, "{\"task\":\"" as *u8); o = ct_putj(out, o, q, sp[CTF_TASK_A], sp[CTF_TASK_B])
188 o = ct_puts(out, o, "\",\"organ\":\"" as *u8); o = ct_putj(out, o, q, sp[CTF_ORGAN_A], sp[CTF_ORGAN_B])
189 o = ct_puts(out, o, "\",\"owner\":\"" as *u8); o = ct_putj(out, o, q, sp[CTF_OWNER_A], sp[CTF_OWNER_B])
190 o = ct_puts(out, o, "\",\"exposure\":\"" as *u8); o = ct_putj(out, o, q, sp[CTF_EXP_A], sp[CTF_EXP_B])
191 o = ct_puts(out, o, "\",\"state\":\"" as *u8); o = ct_putj(out, o, q, sp[CTF_STATE_A], sp[CTF_STATE_B])
192 o = ct_puts(out, o, "\",\"dups\":" as *u8); o = ct_putsl(out, o, q, sp[CTF_DUPS_A], sp[CTF_DUPS_B])
193 o = ct_puts(out, o, ",\"note\":\"" as *u8); o = ct_putj(out, o, q, sp[CTF_NOTE_A], sp[CTF_NOTE_B])
194 o = ct_puts(out, o, "\"}" as *u8)
195 }
196 }
197 }
198 i = le + 1
199 }
200
201 if verb == CT_VHTML { o = ct_puts(out, o, "</table></main></body></html>\n" as *u8) }
202 else { o = ct_puts(out, o, "]}\n" as *u8) }
203
204 if verb == CT_VHTML { if argc >= CT_ARGC_OUT {
205 let op: *u8 = argv[CT_IDX_OUT] as *u8
206 let fd: i64 = sys_openat_wr(op, CT_MODE)
207 if fd >= 0 { sys_write(fd, out, o); sys_close(fd); ct_werr("wrote html\n" as *u8); sys_exit(0); return 0 }
208 } }
209 sys_write(1, out, o)
210 sys_exit(0)
211 return 0
212}