code wiki / _hdl_build / nx_vizsla_import_gate.nx

nx_vizsla_import_gate.nx source

↩ module page · 222 lines · 9791 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" 24 25func og_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 26func og_p(s: *u8) -> i64 { sys_write(1, s, og_slen(s)); return 0 } 27 28func og_cat(dst: *u8, off: i64, s: *u8) -> i64 { 29 var i: i64 = 0 30 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 31 return off + i 32} 33 34func og_catn(dst: *u8, off: i64, v: i64) -> i64 { 35 var o: i64 = off 36 var m: i64 = v 37 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m } 38 let t: *u8 = sys_mmap(28) 39 var k: i64 = 0 40 if m == 0 { t[0] = 48 as u8; k = 1 } 41 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 42 var i: i64 = 0 43 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } 44 return o + k 45} 46 47func og_write(path: *u8, content: *u8) -> i64 { 48 let fd: i64 = sys_openat_wr(path, 0x1a4) 49 if fd < 0 { return 0 - 1 } 50 sys_write(fd, content, og_slen(content)) 51 sys_close(fd) 52 return 0 53} 54 55func og_readall(path: *u8, szout: *i64) -> *u8 { 56 let fd: i64 = sys_openat_rd(path) 57 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 } 58 let sz: i64 = sys_lseek(fd, 0, 2) 59 sys_lseek(fd, 0, 0) 60 let buf: *u8 = sys_mmap(sz + 64) 61 var got: i64 = 0 62 var n: i64 = 1 63 while n > 0 { n = sys_read(fd, (buf as i64 + got) as *u8, 65536); if n > 0 { got = got + n } } 64 sys_close(fd) 65 szout[0] = got 66 return buf 67} 68 69func og_runv(elf: *u8, args: *i64, outpath: *u8) -> i64 { 70 let pid: i64 = sys_fork() 71 if pid == 0 { 72 if (outpath as i64) != 0 { 73 let ofd: i64 = sys_openat_wr(outpath, 0x1a4) 74 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) } 75 } 76 let argv: *i64 = sys_mmap(128) as *i64 77 argv[0] = elf as i64 78 var i: i64 = 0 79 var go: i64 = 1 80 while go == 1 { if args[i] == 0 { go = 0 } else { argv[i + 1] = args[i]; i = i + 1 } } 81 argv[i + 1] = 0 82 let envp: *i64 = sys_mmap(16) as *i64 83 envp[0] = 0 84 sys_execve(elf, argv, envp) 85 sys_exit(127) 86 } 87 let st: *i64 = sys_mmap(16) as *i64 88 sys_wait4(pid, st, 0) 89 let sig: i64 = st[0] & 0x7f 90 if sig != 0 { return 128 + sig } 91 return (st[0] >> 8) & 0xff 92} 93 94func og_has(path: *u8, needle: *u8) -> i64 { 95 let szp: *i64 = sys_mmap(16) as *i64 96 let b: *u8 = og_readall(path, szp) 97 let sz: i64 = szp[0] 98 let n: i64 = og_slen(needle) 99 if sz < n { return 0 } 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 b[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 } } 105 if ok == 1 { return 1 } 106 i = i + 1 107 } 108 return 0 109} 110 111func og_row(name: *u8, pass: i64) -> i64 { 112 og_p("ROW " as *u8); og_p(name) 113 if pass == 1 { og_p(" PASS\n" as *u8) } else { og_p(" FAIL\n" as *u8) } 114 return pass 115} 116 117func og_args(a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8) -> *i64 { 118 let a: *i64 = sys_mmap(64) as *i64 119 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 120 return a 121} 122 123func og_join(base: *u8, name: *u8) -> *u8 { 124 let p: *u8 = sys_mmap(512) 125 var o: i64 = 0 126 o = og_cat(p, o, base); o = og_cat(p, o, name); p[o] = 0 as u8 127 return p 128} 129 130func main(argc: i64, argv: *i64) -> i64 { 131 og_p("=== VIZSLA IMPORT GATE: LinkedIn + vCard -> a tenant's people (sovereign parse) ===\n" as *u8) 132 var ob: *u8 = "/tmp/nx_vizsla_import.sov.elf" as *u8 133 if argc > 1 { ob = argv[1] as *u8 } 134 let pr: i64 = sys_openat_rd(ob) 135 if pr >= 0 { sys_close(pr) } 136 else { 137 og_p(" instrument missing -> rebuilding via durable runner\n" as *u8) 138 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) 139 } 140 141 let base: *u8 = sys_mmap(256) 142 var bo: i64 = 0 143 bo = og_cat(base, bo, "/tmp/vziG" as *u8); bo = og_catn(base, bo, sys_now_us()); bo = og_cat(base, bo, "_" as *u8) 144 base[bo] = 0 as u8 145 146 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) 147 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) 148 149 let impc: *u8 = og_join(base, "imp.contacts.txt" as *u8) 150 let impl: *u8 = og_join(base, "imp.relate_log.txt" as *u8) 151 let impp: *u8 = og_join(base, "imp.relate-" as *u8) 152 let today: *u8 = "2026-06-22" as *u8 153 var pass: i64 = 0 154 var r: i64 = 0 155 156 // row 1-3: vCard import 157 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) 158 r = 0 159 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 } } 160 pass = pass + og_row("vcard-import" as *u8, r) 161 162 r = og_has(impc, "CONTACT john-smith John-Smith network 07-03" as *u8) 163 pass = pass + og_row("vcard-contact-bday" as *u8, r) 164 165 r = og_has(impc, "CONTACT mary-jones Mary-Jones network -" as *u8) 166 pass = pass + og_row("vcard-nobday" as *u8, r) 167 168 // row 4: idempotent re-import 169 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) 170 r = og_has("/tmp/vzi_v2.txt" as *u8, "VIZSLA-IMPORT-VCARD tenant=imp imported=0 skipped=2" as *u8) 171 pass = pass + og_row("vcard-idempotent" as *u8, r) 172 173 // row 5-6: LinkedIn import (additive) 174 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) 175 r = 0 176 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 } } 177 pass = pass + og_row("linkedin-import" as *u8, r) 178 179 r = og_has(impl, "TOUCH 2026-06-15 bob-lee connected-on-linkedin" as *u8) 180 pass = pass + og_row("linkedin-touch-dateparse" as *u8, r) 181 182 // row 7-8: the resulting brief 183 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) 184 r = og_has("/tmp/vzi_brief.txt" as *u8, "BIRTHDAY contact=john-smith on=07-03 in=11d" as *u8) 185 pass = pass + og_row("brief-bday" as *u8, r) 186 187 var bobfollow: i64 = og_has("/tmp/vzi_brief.txt" as *u8, "FOLLOWUP contact=bob-lee" as *u8) 188 var johnfollow: i64 = og_has("/tmp/vzi_brief.txt" as *u8, "FOLLOWUP contact=john-smith" as *u8) 189 r = 0 190 if bobfollow == 0 { if johnfollow == 1 { r = 1 } } 191 pass = pass + og_row("fresh-vs-new" as *u8, r) 192 193 // row 9: neg-control -- linkedin import on a non-CSV (no First Name header) -> exit 1 194 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) 195 r = 0 196 if rc9 == 1 { r = 1 } 197 pass = pass + og_row("neg-control-not-a-csv" as *u8, r) 198 199 let permil: i64 = (pass * 1000) / 9 200 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4) 201 var fdi: i64 = 0 202 while fdi < 2 { 203 var fd: i64 = 1 204 if fdi == 1 { fd = logfd } 205 if fd > 0 { 206 let line: *u8 = sys_mmap(256) 207 var o: i64 = 0 208 o = og_cat(line, o, "VIZSLA-IMPORT-GATE epoch=" as *u8) 209 o = og_catn(line, o, sys_now_realtime_sec()) 210 o = og_cat(line, o, " rows=9 pass=" as *u8) 211 o = og_catn(line, o, pass) 212 o = og_cat(line, o, " permil=" as *u8) 213 o = og_catn(line, o, permil) 214 if pass == 9 { o = og_cat(line, o, " verdict=GREEN\n" as *u8) } else { o = og_cat(line, o, " verdict=RED\n" as *u8) } 215 sys_write(fd, line, o) 216 } 217 fdi = fdi + 1 218 } 219 if logfd > 0 { sys_close(logfd) } 220 if pass == 9 { return 0 } 221 return 1 222}