code wiki / _hdl_build / nx_vizsla_import_gate.nx

nx_vizsla_import_gate.nx source

↩ module page · 230 lines · 10342 B

1// nx_vizsla_import_gate.nx -- VIZSLA import gate: parsing LinkedIn + vCard exports into a tenant's people is 2// gate-proven against construction-known fixtures (oracle in THIS header). 100% sovereign: self-writes the 3// .vcf + .csv fixtures, forks nx_vizsla_import, greps the tenant files + the resulting brief. 4// 5// vCard fixture: John Smith (BDAY 1985-07-03) + Mary Jones (no bday) -> CONTACT john-smith/mary-jones network. 6// LinkedIn fixture (preamble + header + 2 rows): Bob Lee (Connected 15 Jun 2026) + Sue Park (03 May 2026) 7// -> CONTACT bob-lee/sue-park network + TOUCH 2026-06-15/2026-05-03 (connection date). 8// brief @2026-06-22: john-smith+mary-jones = FOLLOWUP NEW (no touch); john-smith BIRTHDAY 07-03 in 11d; 9// bob-lee+sue-park = FRESH (their connect-date TOUCH anchors them) = the value of importing the date. 10// 11// Rows: 12// 1 vcard-import imported=2 skipped=0 13// 2 vcard-contact-bday CONTACT john-smith John-Smith network 07-03 (name sanitize + BDAY->MM-DD) 14// 3 vcard-nobday CONTACT mary-jones Mary-Jones network - 15// 4 vcard-idempotent re-import => imported=0 skipped=2 (dedup vs existing) 16// 5 linkedin-import imported=2 skipped=0 (additive to the vCard contacts) 17// 6 linkedin-touch TOUCH 2026-06-15 bob-lee connected-on-linkedin ("15 Jun 2026" month-name parse) 18// 7 brief-bday BIRTHDAY contact=john-smith in=11d (vCard bday flows into the brief) 19// 8 fresh-vs-new bob-lee NOT a FOLLOWUP (FRESH via connect-date) AND john-smith IS (no touch) 20// 9 neg-control import linkedin on a non-CSV (vcf) file => exit 1 21// Evidence: VIZSLA-IMPORT-GATE -> stdout + knowledge/status/vizsla_gate.log; exit 0 iff 9/9. 22// license_tier: ORIGINAL 23import "nx_syscalls.nx" 24import "nx_gate_verdict.nx" 25 26func og_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 27func og_p(s: *u8) -> i64 { sys_write(1, s, og_slen(s)); return 0 } 28 29func og_cat(dst: *u8, off: i64, s: *u8) -> i64 { 30 var i: i64 = 0 31 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 32 return off + i 33} 34 35func og_catn(dst: *u8, off: i64, v: i64) -> i64 { 36 var o: i64 = off 37 var m: i64 = v 38 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m } 39 let t: *u8 = sys_mmap(28) 40 var k: i64 = 0 41 if m == 0 { t[0] = 48 as u8; k = 1 } 42 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 43 var i: i64 = 0 44 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } 45 return o + k 46} 47 48func og_write(path: *u8, content: *u8) -> i64 { 49 let fd: i64 = sys_openat_wr(path, 0x1a4) 50 if fd < 0 { return 0 - 1 } 51 sys_write(fd, content, og_slen(content)) 52 sys_close(fd) 53 return 0 54} 55 56func og_readall(path: *u8, szout: *i64) -> *u8 { 57 let fd: i64 = sys_openat_rd(path) 58 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 } 59 let sz: i64 = sys_lseek(fd, 0, 2) 60 sys_lseek(fd, 0, 0) 61 let buf: *u8 = sys_mmap(sz + 64) 62 var got: i64 = 0 63 var n: i64 = 1 64 while n > 0 { n = sys_read(fd, (buf as i64 + got) as *u8, 65536); if n > 0 { got = got + n } } 65 sys_close(fd) 66 szout[0] = got 67 return buf 68} 69 70func og_runv(elf: *u8, args: *i64, outpath: *u8) -> i64 { 71 let pid: i64 = sys_fork() 72 if pid == 0 { 73 if (outpath as i64) != 0 { 74 let ofd: i64 = sys_openat_wr(outpath, 0x1a4) 75 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) } 76 } 77 let argv: *i64 = sys_mmap(128) as *i64 78 argv[0] = elf as i64 79 var i: i64 = 0 80 var go: i64 = 1 81 while go == 1 { if args[i] == 0 { go = 0 } else { argv[i + 1] = args[i]; i = i + 1 } } 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 og_has(path: *u8, needle: *u8) -> i64 { 96 let szp: *i64 = sys_mmap(16) as *i64 97 let b: *u8 = og_readall(path, szp) 98 let sz: i64 = szp[0] 99 let n: i64 = og_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 { if b[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 } } 106 if ok == 1 { return 1 } 107 i = i + 1 108 } 109 return 0 110} 111 112func og_row(name: *u8, pass: i64) -> i64 { 113 og_p("ROW " as *u8); og_p(name) 114 if pass == 1 { og_p(" PASS\n" as *u8) } else { og_p(" FAIL\n" as *u8) } 115 return pass 116} 117 118func og_args(a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8) -> *i64 { 119 let a: *i64 = sys_mmap(64) as *i64 120 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 121 return a 122} 123 124func og_join(base: *u8, name: *u8) -> *u8 { 125 let p: *u8 = sys_mmap(512) 126 var o: i64 = 0 127 o = og_cat(p, o, base); o = og_cat(p, o, name); p[o] = 0 as u8 128 return p 129} 130 131func main(argc: i64, argv: *i64) -> i64 { 132 og_p("=== VIZSLA IMPORT GATE: LinkedIn + vCard -> a tenant's people (sovereign parse) ===\n" as *u8) 133 var ob: *u8 = "buildroot/_build/nx_vizsla_import.sov.elf" as *u8 134 if argc > 1 { ob = argv[1] as *u8 } 135 let pr: i64 = sys_openat_rd(ob) 136 if pr >= 0 { sys_close(pr) } 137 else { 138 og_p(" instrument missing -> rebuilding via durable runner\n" as *u8) 139 og_runv("_offc/nx_sov_build_run.elf" as *u8, og_args("nx_vizsla_import" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8), "/tmp/vzi_rebuild.out" as *u8) 140 } 141 142 let base: *u8 = sys_mmap(256) 143 var bo: i64 = 0 144 bo = og_cat(base, bo, "/tmp/vziG" as *u8); bo = og_catn(base, bo, sys_now_us()); bo = og_cat(base, bo, "_" as *u8) 145 base[bo] = 0 as u8 146 147 og_write("/tmp/vzi_cards.vcf" as *u8, "BEGIN:VCARD\nVERSION:3.0\nFN:John Smith\nBDAY:1985-07-03\nEND:VCARD\nBEGIN:VCARD\nVERSION:3.0\nFN:Mary Jones\nEND:VCARD\n" as *u8) 148 og_write("/tmp/vzi_conn.csv" as *u8, "Notes:\n\nFirst Name,Last Name,URL,Email Address,Company,Position,Connected On\nBob,Lee,https://lnkd.in/bob,bob@x.com,Acme,Engineer,15 Jun 2026\nSue,Park,https://lnkd.in/sue,,Globex,Manager,03 May 2026\n" as *u8) 149 150 let impc: *u8 = og_join(base, "imp.contacts.txt" as *u8) 151 let impl: *u8 = og_join(base, "imp.relate_log.txt" as *u8) 152 let impp: *u8 = og_join(base, "imp.relate-" as *u8) 153 let today: *u8 = "2026-06-22" as *u8 154 var pass: i64 = 0 155 var r: i64 = 0 156 157 // row 1-3: vCard import 158 let rc1: i64 = og_runv(ob, og_args("vcard" as *u8, base, "imp" as *u8, "/tmp/vzi_cards.vcf" as *u8, 0 as *u8), "/tmp/vzi_v1.txt" as *u8) 159 r = 0 160 if rc1 == 0 { if og_has("/tmp/vzi_v1.txt" as *u8, "VIZSLA-IMPORT-VCARD tenant=imp imported=2 skipped=0" as *u8) == 1 { r = 1 } } 161 pass = pass + og_row("vcard-import" as *u8, r) 162 163 r = og_has(impc, "CONTACT john-smith John-Smith network 07-03" as *u8) 164 pass = pass + og_row("vcard-contact-bday" as *u8, r) 165 166 r = og_has(impc, "CONTACT mary-jones Mary-Jones network -" as *u8) 167 pass = pass + og_row("vcard-nobday" as *u8, r) 168 169 // row 4: idempotent re-import 170 og_runv(ob, og_args("vcard" as *u8, base, "imp" as *u8, "/tmp/vzi_cards.vcf" as *u8, 0 as *u8), "/tmp/vzi_v2.txt" as *u8) 171 r = og_has("/tmp/vzi_v2.txt" as *u8, "VIZSLA-IMPORT-VCARD tenant=imp imported=0 skipped=2" as *u8) 172 pass = pass + og_row("vcard-idempotent" as *u8, r) 173 174 // row 5-6: LinkedIn import (additive) 175 let rc5: i64 = og_runv(ob, og_args("linkedin" as *u8, base, "imp" as *u8, "/tmp/vzi_conn.csv" as *u8, 0 as *u8), "/tmp/vzi_l1.txt" as *u8) 176 r = 0 177 if rc5 == 0 { if og_has("/tmp/vzi_l1.txt" as *u8, "VIZSLA-IMPORT-LINKEDIN tenant=imp imported=2 skipped=0" as *u8) == 1 { r = 1 } } 178 pass = pass + og_row("linkedin-import" as *u8, r) 179 180 r = og_has(impl, "TOUCH 2026-06-15 bob-lee connected-on-linkedin" as *u8) 181 pass = pass + og_row("linkedin-touch-dateparse" as *u8, r) 182 183 // row 7-8: the resulting brief 184 og_runv("_offc/nx_vizsla_relate.elf" as *u8, og_args("brief" as *u8, impp, impc, today, 0 as *u8), "/tmp/vzi_brief.txt" as *u8) 185 r = og_has("/tmp/vzi_brief.txt" as *u8, "BIRTHDAY contact=john-smith on=07-03 in=11d" as *u8) 186 pass = pass + og_row("brief-bday" as *u8, r) 187 188 var bobfollow: i64 = og_has("/tmp/vzi_brief.txt" as *u8, "FOLLOWUP contact=bob-lee" as *u8) 189 var johnfollow: i64 = og_has("/tmp/vzi_brief.txt" as *u8, "FOLLOWUP contact=john-smith" as *u8) 190 r = 0 191 if bobfollow == 0 { if johnfollow == 1 { r = 1 } } 192 pass = pass + og_row("fresh-vs-new" as *u8, r) 193 194 // row 9: neg-control -- linkedin import on a non-CSV (no First Name header) -> exit 1 195 let rc9: i64 = og_runv(ob, og_args("linkedin" as *u8, base, "imp" as *u8, "/tmp/vzi_cards.vcf" as *u8, 0 as *u8), "/tmp/vzi_neg.txt" as *u8) 196 r = 0 197 if rc9 == 1 { r = 1 } 198 pass = pass + og_row("neg-control-not-a-csv" as *u8, r) 199 200 let permil: i64 = (pass * 1000) / 9 201 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4) 202 var fdi: i64 = 0 203 while fdi < 2 { 204 var fd: i64 = 1 205 if fdi == 1 { fd = logfd } 206 if fd > 0 { 207 let line: *u8 = sys_mmap(256) 208 var o: i64 = 0 209 o = og_cat(line, o, "VIZSLA-IMPORT-GATE epoch=" as *u8) 210 o = og_catn(line, o, sys_now_realtime_sec()) 211 o = og_cat(line, o, " rows=9 pass=" as *u8) 212 o = og_catn(line, o, pass) 213 o = og_cat(line, o, " permil=" as *u8) 214 o = og_catn(line, o, permil) 215 if pass == 9 { o = og_cat(line, o, " verdict=GREEN\n" as *u8) } else { o = og_cat(line, o, " verdict=RED\n" as *u8) } 216 sys_write(fd, line, o) 217 } 218 fdi = fdi + 1 219 } 220 if logfd > 0 { sys_close(logfd) } 221 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 222 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 223 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 224 let ctr__dry: *i64 = gv_ctr() 225 ctr__dry[0] = pass 226 ctr__dry[1] = 9 227 let rc__dry: i64 = gv_verdict("VIZSLA-IMPORT-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 228 sys_exit(rc__dry) 229 return rc__dry 230}