code wiki / _hdl_build / nx_vizsla_coord_gate.nx
nx_vizsla_coord_gate.nx source
↩ module page · 298 lines · 12668 B
1// nx_vizsla_coord_gate.nx -- VIZSLA COORD-PAGE gate: the engagement-partner digest renders to a
2// sovereign 0-JS first-party page (nx_vizsla_render coord). FULL-STACK COMPOSITION: fixtures load
3// through the blessed relate/notes/calendar/plan/venue organs -> the blessed digest composes them
4// -> the render organ builds the page -> the page carries the coordination items and passes the
5// fail-closed sovereignty scan.
6//
7// fixtures (today=2026-06-14): relate mom(06-20 bday, touched 06-10) et al; notes birthday card;
8// calendar mtg 10:00-11:00; plan dg/venue2 due 06-16; venue dgparty/spot-x fits.
9// digest conf: REMIND_LEADS 6,0 -> due = mtg(in=0 event) + mom(in=6 birthday) = 2.
10// coord page counters: cal=1 rem=2 plan=2 (TASK + CRITICAL) venue=1.
11//
12// Rows: 1 coord-renders 2 coord-page-items 3 coord-summary 4 coord-sovereign
13// 5 coord-determinism 6 loud-fail-missing-conf[neg]
14// Evidence: VIZSLA-COORD-GATE -> stdout + knowledge/status/vizsla_gate.log; exit 0 iff 6/6.
15// spec: knowledge/research/2026-06-22-vizsla-sclass-roadmap.md license_tier: ORIGINAL
16import "nx_syscalls.nx"
17import "nx_gate_verdict.nx"
18
19func cg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
20func cg_p(s: *u8) -> i64 { sys_write(1, s, cg_slen(s)); return 0 }
21
22func cg_cat(dst: *u8, off: i64, s: *u8) -> i64 {
23 var i: i64 = 0
24 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 }
25 return off + i
26}
27
28func cg_catn(dst: *u8, off: i64, v: i64) -> i64 {
29 var o: i64 = off
30 var m: i64 = v
31 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m }
32 let t: *u8 = sys_mmap(28)
33 var k: i64 = 0
34 if m == 0 { t[0] = 48 as u8; k = 1 }
35 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
36 var i: i64 = 0
37 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 }
38 return o + k
39}
40
41func cg_write(path: *u8, content: *u8) -> i64 {
42 let fd: i64 = sys_openat_wr(path, 0x1a4)
43 if fd < 0 { return 0 - 1 }
44 sys_write(fd, content, cg_slen(content))
45 sys_close(fd)
46 return 0
47}
48
49func cg_readall(path: *u8, szout: *i64) -> *u8 {
50 let fd: i64 = sys_openat_rd(path)
51 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 }
52 let sz: i64 = sys_lseek(fd, 0, 2)
53 sys_lseek(fd, 0, 0)
54 let buf: *u8 = sys_mmap(sz + 64)
55 var got: i64 = 0
56 var n: i64 = 1
57 while n > 0 {
58 n = sys_read(fd, (buf as i64 + got) as *u8, 65536)
59 if n > 0 { got = got + n }
60 }
61 sys_close(fd)
62 szout[0] = got
63 return buf
64}
65
66func cg_runv(elf: *u8, args: *i64, outpath: *u8) -> i64 {
67 let pid: i64 = sys_fork()
68 if pid == 0 {
69 if (outpath as i64) != 0 {
70 let ofd: i64 = sys_openat_wr(outpath, 0x1a4)
71 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) }
72 }
73 let argv: *i64 = sys_mmap(128) as *i64
74 argv[0] = elf as i64
75 var i: i64 = 0
76 var go: i64 = 1
77 while go == 1 {
78 if args[i] == 0 { go = 0 } else {
79 argv[i + 1] = args[i]
80 i = i + 1
81 }
82 }
83 argv[i + 1] = 0
84 let envp: *i64 = sys_mmap(16) as *i64
85 envp[0] = 0
86 sys_execve(elf, argv, envp)
87 sys_exit(127)
88 }
89 let st: *i64 = sys_mmap(16) as *i64
90 sys_wait4(pid, st, 0)
91 let sig: i64 = st[0] & 0x7f
92 if sig != 0 { return 128 + sig }
93 return (st[0] >> 8) & 0xff
94}
95
96func cg_has(path: *u8, needle: *u8) -> i64 {
97 let szp: *i64 = sys_mmap(16) as *i64
98 let b: *u8 = cg_readall(path, szp)
99 let sz: i64 = szp[0]
100 let n: i64 = cg_slen(needle)
101 if sz < n { return 0 }
102 var i: i64 = 0
103 while i + n <= sz {
104 var ok: i64 = 1
105 var j: i64 = 0
106 while j < n {
107 if b[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 }
108 }
109 if ok == 1 { return 1 }
110 i = i + 1
111 }
112 return 0
113}
114
115func cg_fileeq(p1: *u8, p2: *u8) -> i64 {
116 let s1: *i64 = sys_mmap(16) as *i64
117 let s2: *i64 = sys_mmap(16) as *i64
118 let b1: *u8 = cg_readall(p1, s1)
119 let b2: *u8 = cg_readall(p2, s2)
120 if s1[0] != s2[0] { return 0 }
121 if s1[0] <= 0 { return 0 }
122 var i: i64 = 0
123 while i < s1[0] {
124 if b1[i] != b2[i] { return 0 }
125 i = i + 1
126 }
127 return 1
128}
129
130func cg_row(name: *u8, pass: i64) -> i64 {
131 cg_p("ROW " as *u8)
132 cg_p(name)
133 if pass == 1 { cg_p(" PASS\n" as *u8) } else { cg_p(" FAIL\n" as *u8) }
134 return pass
135}
136
137func cg_args(a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8) -> *i64 {
138 let a: *i64 = sys_mmap(64) as *i64
139 a[0] = a1 as i64
140 a[1] = a2 as i64
141 a[2] = a3 as i64
142 a[3] = a4 as i64
143 a[4] = a5 as i64
144 a[5] = 0
145 return a
146}
147
148func cg_ensure(elf: *u8, organ: *u8) -> i64 {
149 let pr: i64 = sys_openat_rd(elf)
150 if pr >= 0 { sys_close(pr); return 0 }
151 cg_p(" instrument missing -> rebuilding via durable runner\n" as *u8)
152 cg_runv("_offc/nx_sov_build_run.elf" as *u8, cg_args(organ, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8), "/tmp/vzco_rebuild.out" as *u8)
153 return 0
154}
155
156func cg_mkpfx(tag: *u8, us: i64) -> *u8 {
157 let pfx: *u8 = sys_mmap(128)
158 var po: i64 = 0
159 po = cg_cat(pfx, po, tag)
160 po = cg_catn(pfx, po, us)
161 po = cg_cat(pfx, po, "-" as *u8)
162 pfx[po] = 0 as u8
163 return pfx
164}
165
166func main(argc: i64, argv: *i64) -> i64 {
167 cg_p("=== VIZSLA COORD GATE: engagement digest -> sovereign 0-JS coordination page ===\n" as *u8)
168 let ren: *u8 = "buildroot/_build/nx_vizsla_render.sov.elf" as *u8
169 cg_ensure(ren, "nx_vizsla_render" as *u8)
170
171 let us: i64 = sys_now_us()
172 let rpfx: *u8 = cg_mkpfx("/tmp/vzcoR" as *u8, us)
173 let npfx: *u8 = cg_mkpfx("/tmp/vzcoN" as *u8, us)
174 let cpfx: *u8 = cg_mkpfx("/tmp/vzcoC" as *u8, us)
175 let ppfx: *u8 = cg_mkpfx("/tmp/vzcoP" as *u8, us)
176 let vpfx: *u8 = cg_mkpfx("/tmp/vzcoV" as *u8, us)
177
178 cg_write("/tmp/vzco_contacts.txt" as *u8, "CONF soon_days 14\nTIER inner 30\nTIER close 90\nTIER network 180\nCONTACT mom Mom inner 06-20\nCONTACT alex Alex-Mentor close 03-15\nCONTACT sam Sam-Colleague network 12-01\nCONTACT pat Pat-Friend close -\n" as *u8)
179 cg_write("/tmp/vzco_relog.txt" as *u8, "TOUCH 2026-06-10 mom weekly-call\nTOUCH 2026-02-01 alex lunch\n" as *u8)
180 cg_write("/tmp/vzco_nlog.txt" as *u8, "EVENT e1 2026-06-20 mom birthday card-gift\nNOTE n1 e1 BEFORE 7 card signature:img-mom\n" as *u8)
181 cg_write("/tmp/vzco_nconf.txt" as *u8, "CONF window_days 3\nOCCASION birthday BEFORE 3 7 arrive-by-the-day\n" as *u8)
182 cg_write("/tmp/vzco_ntmpl.txt" as *u8, "TMPL birthday BEFORE Happy early birthday, {contact}! Wishing you a wonderful day on {date}. Enclosed: {personal}\n" as *u8)
183 cg_write("/tmp/vzco_cal.txt" as *u8, "EVENT mtg 2026-06-14 600 60 standup-mtg\n" as *u8)
184 cg_write("/tmp/vzco_plan.txt" as *u8, "TASK dg venue2 jason 2026-06-16 60 5 - book-venue2\n" as *u8)
185 cg_write("/tmp/vzco_ven.txt" as *u8, "REQ dgparty 10 20000 2026-06-20 600 120\nVENUE dgparty spot-x 12 15000 555-9 corner-hall\n" as *u8)
186
187 cg_runv("_offc/nx_vizsla_relate.elf" as *u8, cg_args("load" as *u8, "/tmp/vzco_relog.txt" as *u8, rpfx, "7101" as *u8, 0 as *u8), "/tmp/vzco_l1.txt" as *u8)
188 cg_runv("_offc/nx_vizsla_notes.elf" as *u8, cg_args("load" as *u8, "/tmp/vzco_nlog.txt" as *u8, npfx, "7102" as *u8, 0 as *u8), "/tmp/vzco_l2.txt" as *u8)
189 cg_runv("_offc/nx_vizsla_calendar.elf" as *u8, cg_args("load" as *u8, "/tmp/vzco_cal.txt" as *u8, cpfx, "7103" as *u8, 0 as *u8), "/tmp/vzco_l3.txt" as *u8)
190 cg_runv("_offc/nx_vizsla_plan.elf" as *u8, cg_args("load" as *u8, "/tmp/vzco_plan.txt" as *u8, ppfx, "7104" as *u8, 0 as *u8), "/tmp/vzco_l4.txt" as *u8)
191 cg_runv("_offc/nx_vizsla_venue.elf" as *u8, cg_args("load" as *u8, "/tmp/vzco_ven.txt" as *u8, vpfx, "7105" as *u8, 0 as *u8), "/tmp/vzco_l5.txt" as *u8)
192
193 let conf: *u8 = sys_mmap(4096)
194 var co: i64 = 0
195 co = cg_cat(conf, co, "RELATE_PREFIX " as *u8); co = cg_cat(conf, co, rpfx); co = cg_cat(conf, co, "\n" as *u8)
196 co = cg_cat(conf, co, "RELATE_CONTACTS /tmp/vzco_contacts.txt\n" as *u8)
197 co = cg_cat(conf, co, "NOTES_PREFIX " as *u8); co = cg_cat(conf, co, npfx); co = cg_cat(conf, co, "\n" as *u8)
198 co = cg_cat(conf, co, "NOTES_CONF /tmp/vzco_nconf.txt\n" as *u8)
199 co = cg_cat(conf, co, "NOTES_TEMPLATES /tmp/vzco_ntmpl.txt\n" as *u8)
200 co = cg_cat(conf, co, "CAL_PREFIX " as *u8); co = cg_cat(conf, co, cpfx); co = cg_cat(conf, co, "\n" as *u8)
201 co = cg_cat(conf, co, "REMIND_CONTACTS /tmp/vzco_contacts.txt\n" as *u8)
202 co = cg_cat(conf, co, "REMIND_LEADS 6,0\n" as *u8)
203 co = cg_cat(conf, co, "PLAN_PREFIX " as *u8); co = cg_cat(conf, co, ppfx); co = cg_cat(conf, co, "\n" as *u8)
204 co = cg_cat(conf, co, "PLAN_NAME dg\n" as *u8)
205 co = cg_cat(conf, co, "VENUE_PREFIX " as *u8); co = cg_cat(conf, co, vpfx); co = cg_cat(conf, co, "\n" as *u8)
206 co = cg_cat(conf, co, "VENUE_EVENT dgparty\n" as *u8)
207 conf[co] = 0 as u8
208 cg_write("/tmp/vzco.conf" as *u8, conf)
209
210 var pass: i64 = 0
211 var r: i64 = 0
212
213 // row 1: coord renders with the expected counters
214 let outp: *u8 = "/tmp/vzco_page.html" as *u8
215 let rc1: i64 = cg_runv(ren, cg_args("coord" as *u8, "/tmp/vzco.conf" as *u8, "2026-06-14" as *u8, outp, 0 as *u8), "/tmp/vzco_r1.txt" as *u8)
216 r = 0
217 if rc1 == 0 {
218 if cg_has("/tmp/vzco_r1.txt" as *u8, "VIZSLA-RENDER-COORD today=2026-06-14 cal=1 rem=2 plan=2 venue=1" as *u8) == 1 {
219 if cg_has("/tmp/vzco_r1.txt" as *u8, "sovereign=1" as *u8) == 1 { r = 1 }
220 }
221 }
222 pass = pass + cg_row("coord-renders" as *u8, r)
223
224 // row 2: the page carries the coordination items
225 r = 0
226 if cg_has(outp, "id=mom" as *u8) == 1 {
227 if cg_has(outp, "id=mtg" as *u8) == 1 {
228 if cg_has(outp, "id=venue2" as *u8) == 1 {
229 if cg_has(outp, "id=spot-x" as *u8) == 1 { r = 1 }
230 }
231 }
232 }
233 pass = pass + cg_row("coord-page-items" as *u8, r)
234
235 // row 3: the consolidated summary is on the page
236 r = 0
237 if cg_has(outp, "VIZSLA-DIGEST-VERDICT followups=" as *u8) == 1 {
238 if cg_has(outp, "cal_events=1" as *u8) == 1 { r = 1 }
239 }
240 pass = pass + cg_row("coord-summary" as *u8, r)
241
242 // row 4: fail-closed sovereignty held (no script, no external loads)
243 r = 0
244 if cg_has(outp, "<script" as *u8) == 0 {
245 if cg_has(outp, "http" as *u8) == 0 {
246 if cg_has(outp, "<!DOCTYPE html>" as *u8) == 1 {
247 if cg_has(outp, "loaded <b>zero</b> third-party code" as *u8) == 1 { r = 1 }
248 }
249 }
250 }
251 pass = pass + cg_row("coord-sovereign" as *u8, r)
252
253 // row 5: determinism
254 cg_runv(ren, cg_args("coord" as *u8, "/tmp/vzco.conf" as *u8, "2026-06-14" as *u8, "/tmp/vzco_page2.html" as *u8, 0 as *u8), "/tmp/vzco_r5.txt" as *u8)
255 r = cg_fileeq(outp, "/tmp/vzco_page2.html" as *u8)
256 pass = pass + cg_row("coord-determinism" as *u8, r)
257
258 // row 6: missing conf -> loud fail (negative control)
259 let rc6: i64 = cg_runv(ren, cg_args("coord" as *u8, "/tmp/vzco_NOPE.conf" as *u8, "2026-06-14" as *u8, "/tmp/vzco_bad.html" as *u8, 0 as *u8), "/tmp/vzco_r6.txt" as *u8)
260 r = 0
261 if rc6 == 1 { r = 1 }
262 pass = pass + cg_row("loud-fail-missing-conf" as *u8, r)
263
264 let permil: i64 = (pass * 1000) / 6
265 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4)
266 var fdi: i64 = 0
267 while fdi < 2 {
268 var fd: i64 = 1
269 if fdi == 1 { fd = logfd }
270 if fd > 0 {
271 let line: *u8 = sys_mmap(256)
272 var o: i64 = 0
273 o = cg_cat(line, o, "VIZSLA-COORD-GATE epoch=" as *u8)
274 o = cg_catn(line, o, sys_now_realtime_sec())
275 o = cg_cat(line, o, " rows=6 pass=" as *u8)
276 o = cg_catn(line, o, pass)
277 o = cg_cat(line, o, " permil=" as *u8)
278 o = cg_catn(line, o, permil)
279 if pass == 6 {
280 o = cg_cat(line, o, " verdict=GREEN\n" as *u8)
281 } else {
282 o = cg_cat(line, o, " verdict=RED\n" as *u8)
283 }
284 sys_write(fd, line, o)
285 }
286 fdi = fdi + 1
287 }
288 if logfd > 0 { sys_close(logfd) }
289 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
290 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
291 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
292 let ctr__dry: *i64 = gv_ctr()
293 ctr__dry[0] = pass
294 ctr__dry[1] = 6
295 let rc__dry: i64 = gv_verdict("VIZSLA-COORD-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
296 sys_exit(rc__dry)
297 return rc__dry
298}