code wiki / _hdl_build / nx_vizsla_report_gate.nx

nx_vizsla_report_gate.nx source

↩ module page · 239 lines · 10435 B

1// nx_vizsla_report_gate.nx -- VIZSLA activity-analytics gate. Construction-known oracle + log->report integration. 2// Ingest 5 typed interactions via the BLESSED nx_vizsla_log (proves report reads what log writes): 3// mom call 2026-06-10 "talked about her trip to Italy" 4// mom call 2026-06-15 "quick check-in" 5// mom meeting 2026-05-01 "lunch downtown" 6// mom email 2026-03-01 "sent vacation photos" 7// alex coffee 2026-06-05 "discussed the new role" 8// report activity <prefix> 2026-06-23 30 => 9// total=5 contacts=2(mom,alex) types=4(call=2,meeting,email,coffee) span=2026-03-01..2026-06-15 10// recent(30d from 06-23, i.e. >=05-24)= 06-15,06-10,06-05 = 3 ; older=2 11// sorted desc: call(2) before meeting ; mom(4) before alex 12// window=14 (>=06-09): 06-15,06-10 = recent=2 older=3 (proves window arg is real, not hardcoded) 13// Rows: 14// 1 ingest log load new=5 seg-2101 (integration precondition) 15// 2 total-volume verdict interactions=5 contacts=2 types=4 16// 3 by-type "type=call count=2" present AND sorted (call before meeting) 17// 4 by-contact "contact=mom interactions=4" present AND sorted (mom before alex) 18// 5 recent-window "window=30d recent=3 older=2" 19// 6 span "span=2026-03-01..2026-06-15" 20// 7 liar-kill absent type "text" + absent contact "pat" (no hallucinated rows) 21// 8 window-sensitive window=14 -> "window=14d recent=2 older=3" (param actually changes the result) 22// 9 neg-empty empty prefix -> interactions=0 contacts=0 types=0, exit 0 (no invented data) 23// Evidence: VIZSLA-REPORT-GATE -> stdout + knowledge/status/vizsla_gate.log; exit 0 iff 9/9. 24// license_tier: ORIGINAL 25import "nx_syscalls.nx" 26import "nx_gate_verdict.nx" 27 28func og_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 29func og_p(s: *u8) -> i64 { sys_write(1, s, og_slen(s)); return 0 } 30 31func og_cat(dst: *u8, off: i64, s: *u8) -> i64 { 32 var i: i64 = 0 33 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 34 return off + i 35} 36 37func og_catn(dst: *u8, off: i64, v: i64) -> i64 { 38 var o: i64 = off 39 var m: i64 = v 40 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m } 41 let t: *u8 = sys_mmap(28) 42 var k: i64 = 0 43 if m == 0 { t[0] = 48 as u8; k = 1 } 44 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 45 var i: i64 = 0 46 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } 47 return o + k 48} 49 50func og_write(path: *u8, content: *u8) -> i64 { 51 let fd: i64 = sys_openat_wr(path, 0x1a4) 52 if fd < 0 { return 0 - 1 } 53 sys_write(fd, content, og_slen(content)) 54 sys_close(fd) 55 return 0 56} 57 58func og_readall(path: *u8, szout: *i64) -> *u8 { 59 let fd: i64 = sys_openat_rd(path) 60 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 } 61 let sz: i64 = sys_lseek(fd, 0, 2) 62 sys_lseek(fd, 0, 0) 63 let buf: *u8 = sys_mmap(sz + 64) 64 var got: i64 = 0 65 var n: i64 = 1 66 while n > 0 { n = sys_read(fd, (buf as i64 + got) as *u8, 65536); if n > 0 { got = got + n } } 67 sys_close(fd) 68 szout[0] = got 69 return buf 70} 71 72func og_runv(elf: *u8, args: *i64, outpath: *u8) -> i64 { 73 let pid: i64 = sys_fork() 74 if pid == 0 { 75 if (outpath as i64) != 0 { 76 let ofd: i64 = sys_openat_wr(outpath, 0x1a4) 77 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) } 78 } 79 let argv: *i64 = sys_mmap(128) as *i64 80 argv[0] = elf as i64 81 var i: i64 = 0 82 var go: i64 = 1 83 while go == 1 { if args[i] == 0 { go = 0 } else { argv[i + 1] = args[i]; i = i + 1 } } 84 argv[i + 1] = 0 85 let envp: *i64 = sys_mmap(16) as *i64 86 envp[0] = 0 87 sys_execve(elf, argv, envp) 88 sys_exit(127) 89 } 90 let st: *i64 = sys_mmap(16) as *i64 91 sys_wait4(pid, st, 0) 92 let sig: i64 = st[0] & 0x7f 93 if sig != 0 { return 128 + sig } 94 return (st[0] >> 8) & 0xff 95} 96 97func og_idx(buf: *u8, sz: i64, needle: *u8) -> i64 { 98 let n: i64 = og_slen(needle) 99 if n == 0 { return 0 - 1 } 100 var i: i64 = 0 101 while i + n <= sz { 102 var ok: i64 = 1 103 var j: i64 = 0 104 while j < n { if buf[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 } } 105 if ok == 1 { return i } 106 i = i + 1 107 } 108 return 0 - 1 109} 110 111func og_has(path: *u8, needle: *u8) -> i64 { 112 let szp: *i64 = sys_mmap(16) as *i64 113 let b: *u8 = og_readall(path, szp) 114 if og_idx(b, szp[0], needle) >= 0 { return 1 } 115 return 0 116} 117 118// a appears strictly before b (both present) ? 119func og_before(path: *u8, a: *u8, b: *u8) -> i64 { 120 let szp: *i64 = sys_mmap(16) as *i64 121 let buf: *u8 = og_readall(path, szp) 122 let sz: i64 = szp[0] 123 let ia: i64 = og_idx(buf, sz, a) 124 let ib: i64 = og_idx(buf, sz, b) 125 if ia < 0 { return 0 } 126 if ib < 0 { return 0 } 127 if ia < ib { return 1 } 128 return 0 129} 130 131func og_row(name: *u8, pass: i64) -> i64 { 132 og_p("ROW " as *u8); og_p(name) 133 if pass == 1 { og_p(" PASS\n" as *u8) } else { og_p(" FAIL\n" as *u8) } 134 return pass 135} 136 137func og_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; a[1] = a2 as i64; a[2] = a3 as i64; a[3] = a4 as i64; a[4] = a5 as i64; a[5] = 0 140 return a 141} 142 143func main(argc: i64, argv: *i64) -> i64 { 144 og_p("=== VIZSLA REPORT GATE: activity analytics + log->report integration ===\n" as *u8) 145 var ob: *u8 = "buildroot/_build/nx_vizsla_report.sov.elf" as *u8 146 if argc > 1 { ob = argv[1] as *u8 } 147 let pr: i64 = sys_openat_rd(ob) 148 if pr >= 0 { sys_close(pr) } 149 else { 150 og_p(" instrument missing -> rebuilding via durable runner\n" as *u8) 151 og_runv("_offc/nx_sov_build_run.elf" as *u8, og_args("nx_vizsla_report" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8), "/tmp/vrp_rebuild.out" as *u8) 152 } 153 154 let pfx: *u8 = sys_mmap(128) 155 var po: i64 = 0 156 po = og_cat(pfx, po, "/tmp/vrpG" as *u8); po = og_catn(pfx, po, sys_now_us()); po = og_cat(pfx, po, "-" as *u8) 157 pfx[po] = 0 as u8 158 let epx: *u8 = sys_mmap(128) 159 var eo: i64 = 0 160 eo = og_cat(epx, eo, "/tmp/vrpE" as *u8); eo = og_catn(epx, eo, sys_now_us()); eo = og_cat(epx, eo, "-" as *u8) 161 epx[eo] = 0 as u8 162 163 og_write("/tmp/vrp_log.txt" as *u8, "INT 2026-06-10 mom call talked about her trip to Italy\nINT 2026-06-15 mom call quick check-in\nINT 2026-05-01 mom meeting lunch downtown\nINT 2026-03-01 mom email sent vacation photos\nINT 2026-06-05 alex coffee discussed the new role\n" as *u8) 164 165 var pass: i64 = 0 166 var r: i64 = 0 167 168 // 1 ingest via the blessed log organ 169 let rc1: i64 = og_runv("_offc/nx_vizsla_log.elf" as *u8, og_args("load" as *u8, "/tmp/vrp_log.txt" as *u8, pfx, "2101" as *u8, 0 as *u8), "/tmp/vrp_ing.txt" as *u8) 170 r = 0 171 if rc1 == 0 { if og_has("/tmp/vrp_ing.txt" as *u8, "VIZSLA-LOG-LOAD scanned=5 new=5 dup_infile=0 dup_instore=0 segment=seg-2101" as *u8) == 1 { r = 1 } } 172 pass = pass + og_row("ingest" as *u8, r) 173 174 // report (window 30) 175 og_runv(ob, og_args("activity" as *u8, pfx, "2026-06-23" as *u8, "30" as *u8, 0 as *u8), "/tmp/vrp_r30.txt" as *u8) 176 177 r = og_has("/tmp/vrp_r30.txt" as *u8, "VIZSLA-REPORT-VERDICT interactions=5 contacts=2 types=4" as *u8) 178 pass = pass + og_row("total-volume" as *u8, r) 179 180 r = 0 181 if og_has("/tmp/vrp_r30.txt" as *u8, "VIZSLA-REPORT type=call count=2" as *u8) == 1 { if og_before("/tmp/vrp_r30.txt" as *u8, "type=call" as *u8, "type=meeting" as *u8) == 1 { r = 1 } } 182 pass = pass + og_row("by-type" as *u8, r) 183 184 r = 0 185 if og_has("/tmp/vrp_r30.txt" as *u8, "VIZSLA-REPORT contact=mom interactions=4" as *u8) == 1 { if og_before("/tmp/vrp_r30.txt" as *u8, "contact=mom" as *u8, "contact=alex" as *u8) == 1 { r = 1 } } 186 pass = pass + og_row("by-contact" as *u8, r) 187 188 r = og_has("/tmp/vrp_r30.txt" as *u8, "VIZSLA-REPORT window=30d recent=3 older=2" as *u8) 189 pass = pass + og_row("recent-window" as *u8, r) 190 191 r = og_has("/tmp/vrp_r30.txt" as *u8, "span=2026-03-01..2026-06-15" as *u8) 192 pass = pass + og_row("span" as *u8, r) 193 194 r = 0 195 if og_has("/tmp/vrp_r30.txt" as *u8, "type=text" as *u8) == 0 { if og_has("/tmp/vrp_r30.txt" as *u8, "contact=pat" as *u8) == 0 { r = 1 } } 196 pass = pass + og_row("liar-kill-absent" as *u8, r) 197 198 // 8 window sensitivity: window=14 -> recent=2 older=3 199 og_runv(ob, og_args("activity" as *u8, pfx, "2026-06-23" as *u8, "14" as *u8, 0 as *u8), "/tmp/vrp_r14.txt" as *u8) 200 r = og_has("/tmp/vrp_r14.txt" as *u8, "VIZSLA-REPORT window=14d recent=2 older=3" as *u8) 201 pass = pass + og_row("window-sensitive" as *u8, r) 202 203 // 9 neg-empty: empty prefix -> zero everything, exit 0 204 let rc9: i64 = og_runv(ob, og_args("activity" as *u8, epx, "2026-06-23" as *u8, "30" as *u8, 0 as *u8), "/tmp/vrp_e.txt" as *u8) 205 r = 0 206 if rc9 == 0 { if og_has("/tmp/vrp_e.txt" as *u8, "VIZSLA-REPORT-VERDICT interactions=0 contacts=0 types=0" as *u8) == 1 { r = 1 } } 207 pass = pass + og_row("neg-empty" as *u8, r) 208 209 let permil: i64 = (pass * 1000) / 9 210 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4) 211 var fdi: i64 = 0 212 while fdi < 2 { 213 var fd: i64 = 1 214 if fdi == 1 { fd = logfd } 215 if fd > 0 { 216 let line: *u8 = sys_mmap(256) 217 var o: i64 = 0 218 o = og_cat(line, o, "VIZSLA-REPORT-GATE epoch=" as *u8) 219 o = og_catn(line, o, sys_now_realtime_sec()) 220 o = og_cat(line, o, " rows=9 pass=" as *u8) 221 o = og_catn(line, o, pass) 222 o = og_cat(line, o, " permil=" as *u8) 223 o = og_catn(line, o, permil) 224 if pass == 9 { o = og_cat(line, o, " verdict=GREEN\n" as *u8) } else { o = og_cat(line, o, " verdict=RED\n" as *u8) } 225 sys_write(fd, line, o) 226 } 227 fdi = fdi + 1 228 } 229 if logfd > 0 { sys_close(logfd) } 230 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 231 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 232 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 233 let ctr__dry: *i64 = gv_ctr() 234 ctr__dry[0] = pass 235 ctr__dry[1] = 9 236 let rc__dry: i64 = gv_verdict("VIZSLA-REPORT-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 237 sys_exit(rc__dry) 238 return rc__dry 239}