code wiki / _hdl_build / nx_vizsla_coord_gate.nx

nx_vizsla_coord_gate.nx source

↩ module page · 290 lines · 12118 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" 17 18func cg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 19func cg_p(s: *u8) -> i64 { sys_write(1, s, cg_slen(s)); return 0 } 20 21func cg_cat(dst: *u8, off: i64, s: *u8) -> i64 { 22 var i: i64 = 0 23 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 24 return off + i 25} 26 27func cg_catn(dst: *u8, off: i64, v: i64) -> i64 { 28 var o: i64 = off 29 var m: i64 = v 30 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m } 31 let t: *u8 = sys_mmap(28) 32 var k: i64 = 0 33 if m == 0 { t[0] = 48 as u8; k = 1 } 34 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 35 var i: i64 = 0 36 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } 37 return o + k 38} 39 40func cg_write(path: *u8, content: *u8) -> i64 { 41 let fd: i64 = sys_openat_wr(path, 0x1a4) 42 if fd < 0 { return 0 - 1 } 43 sys_write(fd, content, cg_slen(content)) 44 sys_close(fd) 45 return 0 46} 47 48func cg_readall(path: *u8, szout: *i64) -> *u8 { 49 let fd: i64 = sys_openat_rd(path) 50 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 } 51 let sz: i64 = sys_lseek(fd, 0, 2) 52 sys_lseek(fd, 0, 0) 53 let buf: *u8 = sys_mmap(sz + 64) 54 var got: i64 = 0 55 var n: i64 = 1 56 while n > 0 { 57 n = sys_read(fd, (buf as i64 + got) as *u8, 65536) 58 if n > 0 { got = got + n } 59 } 60 sys_close(fd) 61 szout[0] = got 62 return buf 63} 64 65func cg_runv(elf: *u8, args: *i64, outpath: *u8) -> i64 { 66 let pid: i64 = sys_fork() 67 if pid == 0 { 68 if (outpath as i64) != 0 { 69 let ofd: i64 = sys_openat_wr(outpath, 0x1a4) 70 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) } 71 } 72 let argv: *i64 = sys_mmap(128) as *i64 73 argv[0] = elf as i64 74 var i: i64 = 0 75 var go: i64 = 1 76 while go == 1 { 77 if args[i] == 0 { go = 0 } else { 78 argv[i + 1] = args[i] 79 i = i + 1 80 } 81 } 82 argv[i + 1] = 0 83 let envp: *i64 = sys_mmap(16) as *i64 84 envp[0] = 0 85 sys_execve(elf, argv, envp) 86 sys_exit(127) 87 } 88 let st: *i64 = sys_mmap(16) as *i64 89 sys_wait4(pid, st, 0) 90 let sig: i64 = st[0] & 0x7f 91 if sig != 0 { return 128 + sig } 92 return (st[0] >> 8) & 0xff 93} 94 95func cg_has(path: *u8, needle: *u8) -> i64 { 96 let szp: *i64 = sys_mmap(16) as *i64 97 let b: *u8 = cg_readall(path, szp) 98 let sz: i64 = szp[0] 99 let n: i64 = cg_slen(needle) 100 if sz < n { return 0 } 101 var i: i64 = 0 102 while i + n <= sz { 103 var ok: i64 = 1 104 var j: i64 = 0 105 while j < n { 106 if b[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 } 107 } 108 if ok == 1 { return 1 } 109 i = i + 1 110 } 111 return 0 112} 113 114func cg_fileeq(p1: *u8, p2: *u8) -> i64 { 115 let s1: *i64 = sys_mmap(16) as *i64 116 let s2: *i64 = sys_mmap(16) as *i64 117 let b1: *u8 = cg_readall(p1, s1) 118 let b2: *u8 = cg_readall(p2, s2) 119 if s1[0] != s2[0] { return 0 } 120 if s1[0] <= 0 { return 0 } 121 var i: i64 = 0 122 while i < s1[0] { 123 if b1[i] != b2[i] { return 0 } 124 i = i + 1 125 } 126 return 1 127} 128 129func cg_row(name: *u8, pass: i64) -> i64 { 130 cg_p("ROW " as *u8) 131 cg_p(name) 132 if pass == 1 { cg_p(" PASS\n" as *u8) } else { cg_p(" FAIL\n" as *u8) } 133 return pass 134} 135 136func cg_args(a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8) -> *i64 { 137 let a: *i64 = sys_mmap(64) as *i64 138 a[0] = a1 as i64 139 a[1] = a2 as i64 140 a[2] = a3 as i64 141 a[3] = a4 as i64 142 a[4] = a5 as i64 143 a[5] = 0 144 return a 145} 146 147func cg_ensure(elf: *u8, organ: *u8) -> i64 { 148 let pr: i64 = sys_openat_rd(elf) 149 if pr >= 0 { sys_close(pr); return 0 } 150 cg_p(" instrument missing -> rebuilding via durable runner\n" as *u8) 151 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) 152 return 0 153} 154 155func cg_mkpfx(tag: *u8, us: i64) -> *u8 { 156 let pfx: *u8 = sys_mmap(128) 157 var po: i64 = 0 158 po = cg_cat(pfx, po, tag) 159 po = cg_catn(pfx, po, us) 160 po = cg_cat(pfx, po, "-" as *u8) 161 pfx[po] = 0 as u8 162 return pfx 163} 164 165func main(argc: i64, argv: *i64) -> i64 { 166 cg_p("=== VIZSLA COORD GATE: engagement digest -> sovereign 0-JS coordination page ===\n" as *u8) 167 let ren: *u8 = "/tmp/nx_vizsla_render.sov.elf" as *u8 168 cg_ensure(ren, "nx_vizsla_render" as *u8) 169 170 let us: i64 = sys_now_us() 171 let rpfx: *u8 = cg_mkpfx("/tmp/vzcoR" as *u8, us) 172 let npfx: *u8 = cg_mkpfx("/tmp/vzcoN" as *u8, us) 173 let cpfx: *u8 = cg_mkpfx("/tmp/vzcoC" as *u8, us) 174 let ppfx: *u8 = cg_mkpfx("/tmp/vzcoP" as *u8, us) 175 let vpfx: *u8 = cg_mkpfx("/tmp/vzcoV" as *u8, us) 176 177 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) 178 cg_write("/tmp/vzco_relog.txt" as *u8, "TOUCH 2026-06-10 mom weekly-call\nTOUCH 2026-02-01 alex lunch\n" as *u8) 179 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) 180 cg_write("/tmp/vzco_nconf.txt" as *u8, "CONF window_days 3\nOCCASION birthday BEFORE 3 7 arrive-by-the-day\n" as *u8) 181 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) 182 cg_write("/tmp/vzco_cal.txt" as *u8, "EVENT mtg 2026-06-14 600 60 standup-mtg\n" as *u8) 183 cg_write("/tmp/vzco_plan.txt" as *u8, "TASK dg venue2 jason 2026-06-16 60 5 - book-venue2\n" as *u8) 184 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) 185 186 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) 187 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) 188 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) 189 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) 190 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) 191 192 let conf: *u8 = sys_mmap(4096) 193 var co: i64 = 0 194 co = cg_cat(conf, co, "RELATE_PREFIX " as *u8); co = cg_cat(conf, co, rpfx); co = cg_cat(conf, co, "\n" as *u8) 195 co = cg_cat(conf, co, "RELATE_CONTACTS /tmp/vzco_contacts.txt\n" as *u8) 196 co = cg_cat(conf, co, "NOTES_PREFIX " as *u8); co = cg_cat(conf, co, npfx); co = cg_cat(conf, co, "\n" as *u8) 197 co = cg_cat(conf, co, "NOTES_CONF /tmp/vzco_nconf.txt\n" as *u8) 198 co = cg_cat(conf, co, "NOTES_TEMPLATES /tmp/vzco_ntmpl.txt\n" as *u8) 199 co = cg_cat(conf, co, "CAL_PREFIX " as *u8); co = cg_cat(conf, co, cpfx); co = cg_cat(conf, co, "\n" as *u8) 200 co = cg_cat(conf, co, "REMIND_CONTACTS /tmp/vzco_contacts.txt\n" as *u8) 201 co = cg_cat(conf, co, "REMIND_LEADS 6,0\n" as *u8) 202 co = cg_cat(conf, co, "PLAN_PREFIX " as *u8); co = cg_cat(conf, co, ppfx); co = cg_cat(conf, co, "\n" as *u8) 203 co = cg_cat(conf, co, "PLAN_NAME dg\n" as *u8) 204 co = cg_cat(conf, co, "VENUE_PREFIX " as *u8); co = cg_cat(conf, co, vpfx); co = cg_cat(conf, co, "\n" as *u8) 205 co = cg_cat(conf, co, "VENUE_EVENT dgparty\n" as *u8) 206 conf[co] = 0 as u8 207 cg_write("/tmp/vzco.conf" as *u8, conf) 208 209 var pass: i64 = 0 210 var r: i64 = 0 211 212 // row 1: coord renders with the expected counters 213 let outp: *u8 = "/tmp/vzco_page.html" as *u8 214 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) 215 r = 0 216 if rc1 == 0 { 217 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 { 218 if cg_has("/tmp/vzco_r1.txt" as *u8, "sovereign=1" as *u8) == 1 { r = 1 } 219 } 220 } 221 pass = pass + cg_row("coord-renders" as *u8, r) 222 223 // row 2: the page carries the coordination items 224 r = 0 225 if cg_has(outp, "id=mom" as *u8) == 1 { 226 if cg_has(outp, "id=mtg" as *u8) == 1 { 227 if cg_has(outp, "id=venue2" as *u8) == 1 { 228 if cg_has(outp, "id=spot-x" as *u8) == 1 { r = 1 } 229 } 230 } 231 } 232 pass = pass + cg_row("coord-page-items" as *u8, r) 233 234 // row 3: the consolidated summary is on the page 235 r = 0 236 if cg_has(outp, "VIZSLA-DIGEST-VERDICT followups=" as *u8) == 1 { 237 if cg_has(outp, "cal_events=1" as *u8) == 1 { r = 1 } 238 } 239 pass = pass + cg_row("coord-summary" as *u8, r) 240 241 // row 4: fail-closed sovereignty held (no script, no external loads) 242 r = 0 243 if cg_has(outp, "<script" as *u8) == 0 { 244 if cg_has(outp, "http" as *u8) == 0 { 245 if cg_has(outp, "<!DOCTYPE html>" as *u8) == 1 { 246 if cg_has(outp, "loaded <b>zero</b> third-party code" as *u8) == 1 { r = 1 } 247 } 248 } 249 } 250 pass = pass + cg_row("coord-sovereign" as *u8, r) 251 252 // row 5: determinism 253 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) 254 r = cg_fileeq(outp, "/tmp/vzco_page2.html" as *u8) 255 pass = pass + cg_row("coord-determinism" as *u8, r) 256 257 // row 6: missing conf -> loud fail (negative control) 258 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) 259 r = 0 260 if rc6 == 1 { r = 1 } 261 pass = pass + cg_row("loud-fail-missing-conf" as *u8, r) 262 263 let permil: i64 = (pass * 1000) / 6 264 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4) 265 var fdi: i64 = 0 266 while fdi < 2 { 267 var fd: i64 = 1 268 if fdi == 1 { fd = logfd } 269 if fd > 0 { 270 let line: *u8 = sys_mmap(256) 271 var o: i64 = 0 272 o = cg_cat(line, o, "VIZSLA-COORD-GATE epoch=" as *u8) 273 o = cg_catn(line, o, sys_now_realtime_sec()) 274 o = cg_cat(line, o, " rows=6 pass=" as *u8) 275 o = cg_catn(line, o, pass) 276 o = cg_cat(line, o, " permil=" as *u8) 277 o = cg_catn(line, o, permil) 278 if pass == 6 { 279 o = cg_cat(line, o, " verdict=GREEN\n" as *u8) 280 } else { 281 o = cg_cat(line, o, " verdict=RED\n" as *u8) 282 } 283 sys_write(fd, line, o) 284 } 285 fdi = fdi + 1 286 } 287 if logfd > 0 { sys_close(logfd) } 288 if pass == 6 { return 0 } 289 return 1 290}