code wiki / _hdl_build / nx_vizsla_calendar_conflict_gate.nx

nx_vizsla_calendar_conflict_gate.nx source

↩ module page · 255 lines · 10168 B

1// nx_vizsla_calendar_conflict_gate.nx -- VIZSLA R-CAL.2 gate: conflict detection (overlap scan across the 2// expanded occurrences + single events) is gate-proven against construction-known fixtures with HAND-COMPUTED 3// overlaps (oracle in THIS header). 100% sovereign: self-writes fixtures via the organ's syscalls, forks the 4// organ, greps stdout. 5// 6// fixture (seg-7001), single EVENTs + one DAILY RRULE: 7// meeting 06-22 09:00 +60 -> [540,600) 8// call 06-22 09:30 +30 -> [570,600) 9// after 06-22 10:00 +30 -> [600,630) (back-to-back with meeting/call -- MUST NOT conflict) 10// lunch 06-22 12:00 +60 -> [720,780) 11// solo 06-23 09:00 +60 -> [540,600) (different day) 12// standup 06-22 09:15 +30 DAILY x1 -> [555,585) (a RECURRING occurrence that overlaps meeting AND call) 13// W1 conflicts 06-22..06-22 (sorted meeting/standup/call/after/lunch) => 14// meeting x standup [555,585)=09:15-09:45 ; meeting x call [570,600)=09:30-10:00 ; 15// standup x call [570,585)=09:30-09:45 (after is adjacent -> NO clash) => occurrences=5 conflicts=3 16// W2 conflicts 06-23..06-23 => only solo => occurrences=1 conflicts=0 (no false positive) 17// 18// Rows: 19// 1 conflict-load 6 records -> new=6 seg-7001 20// 2 conflict-overlap-events meeting x call line exact (two single events) 21// 3 conflict-recurring meeting x standup line exact (the RRULE occurrence participates) 22// 4 conflict-three-way standup x call line exact 23// 5 conflict-verdict occurrences=5 conflicts=3 (adjacency 'after' counted but NOT a clash) 24// 6 no-conflict-other-day W2 occurrences=1 conflicts=0 (day isolation, no false positive) 25// 7 conflict-determinism W1 byte-identical twice 26// 8 loud-fail-bad-date conflicts from=2026-13-99 => exit 1 [negative control] 27// Evidence: VIZSLA-CAL-CONFLICT-GATE -> stdout + knowledge/status/vizsla_gate.log; exit 0 iff 8/8. 28// spec: knowledge/research/2026-06-22-vizsla-sclass-roadmap.md license_tier: ORIGINAL 29import "nx_syscalls.nx" 30 31func og_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 32func og_p(s: *u8) -> i64 { sys_write(1, s, og_slen(s)); return 0 } 33 34func og_cat(dst: *u8, off: i64, s: *u8) -> i64 { 35 var i: i64 = 0 36 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 37 return off + i 38} 39 40func og_catn(dst: *u8, off: i64, v: i64) -> i64 { 41 var o: i64 = off 42 var m: i64 = v 43 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m } 44 let t: *u8 = sys_mmap(28) 45 var k: i64 = 0 46 if m == 0 { t[0] = 48 as u8; k = 1 } 47 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 48 var i: i64 = 0 49 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } 50 return o + k 51} 52 53func og_write(path: *u8, content: *u8) -> i64 { 54 let fd: i64 = sys_openat_wr(path, 0x1a4) 55 if fd < 0 { return 0 - 1 } 56 sys_write(fd, content, og_slen(content)) 57 sys_close(fd) 58 return 0 59} 60 61func og_readall(path: *u8, szout: *i64) -> *u8 { 62 let fd: i64 = sys_openat_rd(path) 63 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 } 64 let sz: i64 = sys_lseek(fd, 0, 2) 65 sys_lseek(fd, 0, 0) 66 let buf: *u8 = sys_mmap(sz + 64) 67 var got: i64 = 0 68 var n: i64 = 1 69 while n > 0 { 70 n = sys_read(fd, (buf as i64 + got) as *u8, 65536) 71 if n > 0 { got = got + n } 72 } 73 sys_close(fd) 74 szout[0] = got 75 return buf 76} 77 78func og_runv(elf: *u8, args: *i64, outpath: *u8) -> i64 { 79 let pid: i64 = sys_fork() 80 if pid == 0 { 81 if (outpath as i64) != 0 { 82 let ofd: i64 = sys_openat_wr(outpath, 0x1a4) 83 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) } 84 } 85 let argv: *i64 = sys_mmap(128) as *i64 86 argv[0] = elf as i64 87 var i: i64 = 0 88 var go: i64 = 1 89 while go == 1 { 90 if args[i] == 0 { go = 0 } else { 91 argv[i + 1] = args[i] 92 i = i + 1 93 } 94 } 95 argv[i + 1] = 0 96 let envp: *i64 = sys_mmap(16) as *i64 97 envp[0] = 0 98 sys_execve(elf, argv, envp) 99 sys_exit(127) 100 } 101 let st: *i64 = sys_mmap(16) as *i64 102 sys_wait4(pid, st, 0) 103 let sig: i64 = st[0] & 0x7f 104 if sig != 0 { return 128 + sig } 105 return (st[0] >> 8) & 0xff 106} 107 108func og_has(path: *u8, needle: *u8) -> i64 { 109 let szp: *i64 = sys_mmap(16) as *i64 110 let b: *u8 = og_readall(path, szp) 111 let sz: i64 = szp[0] 112 let n: i64 = og_slen(needle) 113 if sz < n { return 0 } 114 var i: i64 = 0 115 while i + n <= sz { 116 var ok: i64 = 1 117 var j: i64 = 0 118 while j < n { 119 if b[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 } 120 } 121 if ok == 1 { return 1 } 122 i = i + 1 123 } 124 return 0 125} 126 127func og_fileeq(p1: *u8, p2: *u8) -> i64 { 128 let s1: *i64 = sys_mmap(16) as *i64 129 let s2: *i64 = sys_mmap(16) as *i64 130 let b1: *u8 = og_readall(p1, s1) 131 let b2: *u8 = og_readall(p2, s2) 132 if s1[0] != s2[0] { return 0 } 133 if s1[0] <= 0 { return 0 } 134 var i: i64 = 0 135 while i < s1[0] { 136 if b1[i] != b2[i] { return 0 } 137 i = i + 1 138 } 139 return 1 140} 141 142func og_row(name: *u8, pass: i64) -> i64 { 143 og_p("ROW " as *u8) 144 og_p(name) 145 if pass == 1 { og_p(" PASS\n" as *u8) } else { og_p(" FAIL\n" as *u8) } 146 return pass 147} 148 149func og_args(a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8) -> *i64 { 150 let a: *i64 = sys_mmap(64) as *i64 151 a[0] = a1 as i64 152 a[1] = a2 as i64 153 a[2] = a3 as i64 154 a[3] = a4 as i64 155 a[4] = a5 as i64 156 a[5] = 0 157 return a 158} 159 160func main(argc: i64, argv: *i64) -> i64 { 161 og_p("=== VIZSLA CALENDAR CONFLICT GATE: overlap-scan KATs (hand-computed clashes) ===\n" as *u8) 162 var ob: *u8 = "/tmp/nx_vizsla_calendar.sov.elf" as *u8 163 if argc > 1 { ob = argv[1] as *u8 } 164 let pr: i64 = sys_openat_rd(ob) 165 if pr >= 0 { sys_close(pr) } 166 else { 167 og_p(" instrument missing -> rebuilding via durable runner\n" as *u8) 168 og_runv("_offc/nx_sov_build_run.elf" as *u8, og_args("nx_vizsla_calendar" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8), "/tmp/vzc_rebuild.out" as *u8) 169 } 170 171 let pfx: *u8 = sys_mmap(128) 172 var po: i64 = 0 173 po = og_cat(pfx, po, "/tmp/vzcC" as *u8) 174 po = og_catn(pfx, po, sys_now_us()) 175 po = og_cat(pfx, po, "-" as *u8) 176 pfx[po] = 0 as u8 177 178 let cf: *u8 = "EVENT meeting 2026-06-22 540 60 morning-meeting\nEVENT call 2026-06-22 570 30 client-call\nEVENT after 2026-06-22 600 30 right-after\nEVENT lunch 2026-06-22 720 60 lunch\nEVENT solo 2026-06-23 540 60 solo-day\nRRULE standup 2026-06-22 555 30 DAILY 1 1 daily-standup\n" as *u8 179 og_write("/tmp/vzc_cf.txt" as *u8, cf) 180 let fcf: *u8 = "/tmp/vzc_cf.txt" as *u8 181 var pass: i64 = 0 182 var r: i64 = 0 183 184 // row 1: load 6 records 185 let rc1: i64 = og_runv(ob, og_args("load" as *u8, fcf, pfx, "7001" as *u8, 0 as *u8), "/tmp/vzc_c1.txt" as *u8) 186 r = 0 187 if rc1 == 0 { 188 if og_has("/tmp/vzc_c1.txt" as *u8, "VIZSLA-CAL-LOAD scanned=6 new=6 dup_infile=0 dup_instore=0 segment=seg-7001" as *u8) == 1 { r = 1 } 189 } 190 pass = pass + og_row("conflict-load" as *u8, r) 191 192 // rows 2-5: W1 conflicts on 2026-06-22 193 let rc2: i64 = og_runv(ob, og_args("conflicts" as *u8, pfx, "2026-06-22" as *u8, "2026-06-22" as *u8, 0 as *u8), "/tmp/vzc_c2.txt" as *u8) 194 r = 0 195 if rc2 == 0 { 196 if og_has("/tmp/vzc_c2.txt" as *u8, "VIZSLA-CAL-CONFLICT date=2026-06-22 a=meeting@09:00-10:00 b=call@09:30-10:00 overlap=09:30-10:00" as *u8) == 1 { r = 1 } 197 } 198 pass = pass + og_row("conflict-overlap-events" as *u8, r) 199 200 r = og_has("/tmp/vzc_c2.txt" as *u8, "VIZSLA-CAL-CONFLICT date=2026-06-22 a=meeting@09:00-10:00 b=standup@09:15-09:45 overlap=09:15-09:45" as *u8) 201 pass = pass + og_row("conflict-recurring-participates" as *u8, r) 202 203 r = og_has("/tmp/vzc_c2.txt" as *u8, "VIZSLA-CAL-CONFLICT date=2026-06-22 a=standup@09:15-09:45 b=call@09:30-10:00 overlap=09:30-09:45" as *u8) 204 pass = pass + og_row("conflict-three-way" as *u8, r) 205 206 r = og_has("/tmp/vzc_c2.txt" as *u8, "VIZSLA-CAL-CONFLICT-VERDICT occurrences=5 conflicts=3" as *u8) 207 pass = pass + og_row("conflict-verdict" as *u8, r) 208 209 // row 6: a day with no overlap (single event) -> no false positive 210 let rc6: i64 = og_runv(ob, og_args("conflicts" as *u8, pfx, "2026-06-23" as *u8, "2026-06-23" as *u8, 0 as *u8), "/tmp/vzc_c6.txt" as *u8) 211 r = 0 212 if rc6 == 0 { 213 if og_has("/tmp/vzc_c6.txt" as *u8, "VIZSLA-CAL-CONFLICT-VERDICT occurrences=1 conflicts=0" as *u8) == 1 { r = 1 } 214 } 215 pass = pass + og_row("no-conflict-other-day" as *u8, r) 216 217 // row 7: determinism 218 og_runv(ob, og_args("conflicts" as *u8, pfx, "2026-06-22" as *u8, "2026-06-22" as *u8, 0 as *u8), "/tmp/vzc_c7.txt" as *u8) 219 r = og_fileeq("/tmp/vzc_c2.txt" as *u8, "/tmp/vzc_c7.txt" as *u8) 220 pass = pass + og_row("conflict-determinism" as *u8, r) 221 222 // row 8: loud-fail on bad date (negative control) 223 let rc8: i64 = og_runv(ob, og_args("conflicts" as *u8, pfx, "2026-13-99" as *u8, "2026-06-22" as *u8, 0 as *u8), "/tmp/vzc_c8.txt" as *u8) 224 r = 0 225 if rc8 == 1 { r = 1 } 226 pass = pass + og_row("loud-fail-bad-date" as *u8, r) 227 228 let permil: i64 = (pass * 1000) / 8 229 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4) 230 var fdi: i64 = 0 231 while fdi < 2 { 232 var fd: i64 = 1 233 if fdi == 1 { fd = logfd } 234 if fd > 0 { 235 let line: *u8 = sys_mmap(256) 236 var o: i64 = 0 237 o = og_cat(line, o, "VIZSLA-CAL-CONFLICT-GATE epoch=" as *u8) 238 o = og_catn(line, o, sys_now_realtime_sec()) 239 o = og_cat(line, o, " rows=8 pass=" as *u8) 240 o = og_catn(line, o, pass) 241 o = og_cat(line, o, " permil=" as *u8) 242 o = og_catn(line, o, permil) 243 if pass == 8 { 244 o = og_cat(line, o, " verdict=GREEN\n" as *u8) 245 } else { 246 o = og_cat(line, o, " verdict=RED\n" as *u8) 247 } 248 sys_write(fd, line, o) 249 } 250 fdi = fdi + 1 251 } 252 if logfd > 0 { sys_close(logfd) } 253 if pass == 8 { return 0 } 254 return 1 255}