code wiki / _hdl_build / nx_vizsla_report_gate.nx

nx_vizsla_report_gate.nx source

↩ module page · 231 lines · 9884 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" 26 27func og_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 28func og_p(s: *u8) -> i64 { sys_write(1, s, og_slen(s)); return 0 } 29 30func og_cat(dst: *u8, off: i64, s: *u8) -> i64 { 31 var i: i64 = 0 32 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 33 return off + i 34} 35 36func og_catn(dst: *u8, off: i64, v: i64) -> i64 { 37 var o: i64 = off 38 var m: i64 = v 39 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m } 40 let t: *u8 = sys_mmap(28) 41 var k: i64 = 0 42 if m == 0 { t[0] = 48 as u8; k = 1 } 43 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 44 var i: i64 = 0 45 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } 46 return o + k 47} 48 49func og_write(path: *u8, content: *u8) -> i64 { 50 let fd: i64 = sys_openat_wr(path, 0x1a4) 51 if fd < 0 { return 0 - 1 } 52 sys_write(fd, content, og_slen(content)) 53 sys_close(fd) 54 return 0 55} 56 57func og_readall(path: *u8, szout: *i64) -> *u8 { 58 let fd: i64 = sys_openat_rd(path) 59 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 } 60 let sz: i64 = sys_lseek(fd, 0, 2) 61 sys_lseek(fd, 0, 0) 62 let buf: *u8 = sys_mmap(sz + 64) 63 var got: i64 = 0 64 var n: i64 = 1 65 while n > 0 { n = sys_read(fd, (buf as i64 + got) as *u8, 65536); if n > 0 { got = got + n } } 66 sys_close(fd) 67 szout[0] = got 68 return buf 69} 70 71func og_runv(elf: *u8, args: *i64, outpath: *u8) -> i64 { 72 let pid: i64 = sys_fork() 73 if pid == 0 { 74 if (outpath as i64) != 0 { 75 let ofd: i64 = sys_openat_wr(outpath, 0x1a4) 76 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) } 77 } 78 let argv: *i64 = sys_mmap(128) as *i64 79 argv[0] = elf as i64 80 var i: i64 = 0 81 var go: i64 = 1 82 while go == 1 { if args[i] == 0 { go = 0 } else { argv[i + 1] = args[i]; i = i + 1 } } 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 og_idx(buf: *u8, sz: i64, needle: *u8) -> i64 { 97 let n: i64 = og_slen(needle) 98 if n == 0 { return 0 - 1 } 99 var i: i64 = 0 100 while i + n <= sz { 101 var ok: i64 = 1 102 var j: i64 = 0 103 while j < n { if buf[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 } } 104 if ok == 1 { return i } 105 i = i + 1 106 } 107 return 0 - 1 108} 109 110func og_has(path: *u8, needle: *u8) -> i64 { 111 let szp: *i64 = sys_mmap(16) as *i64 112 let b: *u8 = og_readall(path, szp) 113 if og_idx(b, szp[0], needle) >= 0 { return 1 } 114 return 0 115} 116 117// a appears strictly before b (both present) ? 118func og_before(path: *u8, a: *u8, b: *u8) -> i64 { 119 let szp: *i64 = sys_mmap(16) as *i64 120 let buf: *u8 = og_readall(path, szp) 121 let sz: i64 = szp[0] 122 let ia: i64 = og_idx(buf, sz, a) 123 let ib: i64 = og_idx(buf, sz, b) 124 if ia < 0 { return 0 } 125 if ib < 0 { return 0 } 126 if ia < ib { return 1 } 127 return 0 128} 129 130func og_row(name: *u8, pass: i64) -> i64 { 131 og_p("ROW " as *u8); og_p(name) 132 if pass == 1 { og_p(" PASS\n" as *u8) } else { og_p(" FAIL\n" as *u8) } 133 return pass 134} 135 136func og_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; a[1] = a2 as i64; a[2] = a3 as i64; a[3] = a4 as i64; a[4] = a5 as i64; a[5] = 0 139 return a 140} 141 142func main(argc: i64, argv: *i64) -> i64 { 143 og_p("=== VIZSLA REPORT GATE: activity analytics + log->report integration ===\n" as *u8) 144 var ob: *u8 = "/tmp/nx_vizsla_report.sov.elf" as *u8 145 if argc > 1 { ob = argv[1] as *u8 } 146 let pr: i64 = sys_openat_rd(ob) 147 if pr >= 0 { sys_close(pr) } 148 else { 149 og_p(" instrument missing -> rebuilding via durable runner\n" as *u8) 150 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) 151 } 152 153 let pfx: *u8 = sys_mmap(128) 154 var po: i64 = 0 155 po = og_cat(pfx, po, "/tmp/vrpG" as *u8); po = og_catn(pfx, po, sys_now_us()); po = og_cat(pfx, po, "-" as *u8) 156 pfx[po] = 0 as u8 157 let epx: *u8 = sys_mmap(128) 158 var eo: i64 = 0 159 eo = og_cat(epx, eo, "/tmp/vrpE" as *u8); eo = og_catn(epx, eo, sys_now_us()); eo = og_cat(epx, eo, "-" as *u8) 160 epx[eo] = 0 as u8 161 162 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) 163 164 var pass: i64 = 0 165 var r: i64 = 0 166 167 // 1 ingest via the blessed log organ 168 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) 169 r = 0 170 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 } } 171 pass = pass + og_row("ingest" as *u8, r) 172 173 // report (window 30) 174 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) 175 176 r = og_has("/tmp/vrp_r30.txt" as *u8, "VIZSLA-REPORT-VERDICT interactions=5 contacts=2 types=4" as *u8) 177 pass = pass + og_row("total-volume" as *u8, r) 178 179 r = 0 180 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 } } 181 pass = pass + og_row("by-type" as *u8, r) 182 183 r = 0 184 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 } } 185 pass = pass + og_row("by-contact" as *u8, r) 186 187 r = og_has("/tmp/vrp_r30.txt" as *u8, "VIZSLA-REPORT window=30d recent=3 older=2" as *u8) 188 pass = pass + og_row("recent-window" as *u8, r) 189 190 r = og_has("/tmp/vrp_r30.txt" as *u8, "span=2026-03-01..2026-06-15" as *u8) 191 pass = pass + og_row("span" as *u8, r) 192 193 r = 0 194 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 } } 195 pass = pass + og_row("liar-kill-absent" as *u8, r) 196 197 // 8 window sensitivity: window=14 -> recent=2 older=3 198 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) 199 r = og_has("/tmp/vrp_r14.txt" as *u8, "VIZSLA-REPORT window=14d recent=2 older=3" as *u8) 200 pass = pass + og_row("window-sensitive" as *u8, r) 201 202 // 9 neg-empty: empty prefix -> zero everything, exit 0 203 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) 204 r = 0 205 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 } } 206 pass = pass + og_row("neg-empty" as *u8, r) 207 208 let permil: i64 = (pass * 1000) / 9 209 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4) 210 var fdi: i64 = 0 211 while fdi < 2 { 212 var fd: i64 = 1 213 if fdi == 1 { fd = logfd } 214 if fd > 0 { 215 let line: *u8 = sys_mmap(256) 216 var o: i64 = 0 217 o = og_cat(line, o, "VIZSLA-REPORT-GATE epoch=" as *u8) 218 o = og_catn(line, o, sys_now_realtime_sec()) 219 o = og_cat(line, o, " rows=9 pass=" as *u8) 220 o = og_catn(line, o, pass) 221 o = og_cat(line, o, " permil=" as *u8) 222 o = og_catn(line, o, permil) 223 if pass == 9 { o = og_cat(line, o, " verdict=GREEN\n" as *u8) } else { o = og_cat(line, o, " verdict=RED\n" as *u8) } 224 sys_write(fd, line, o) 225 } 226 fdi = fdi + 1 227 } 228 if logfd > 0 { sys_close(logfd) } 229 if pass == 9 { return 0 } 230 return 1 231}