code wiki / _hdl_build / nx_vizsla_contact_gate.nx

nx_vizsla_contact_gate.nx source

↩ module page · 213 lines · 9782 B

1// nx_vizsla_contact_gate.nx -- VIZSLA rich-contact gate: arbitrary key->value fields per contact, latest-per-key 2// wins, profile view + search-by-field, all on the sovereign CID/seg_store plane. Construction-known oracle. 3// 4// fields: mom company Acme-Retired@06-01 then Self-Employed@06-10 (LATEST wins) + city Dallas ; alex company 5// Globex + role CTO + city Dallas. profile mom => company=Self-Employed,city=Dallas (fields=2). 6// find city Dallas => mom AND alex (matches=2). find company Self-Employed => mom (1). find company X => 0. 7// 8// Rows: 9// 1 load 6 FIELD -> new=6 seg-9901 10// 2 idempotent new=0 dup_instore=6 (law 10) 11// 3 profile-latest profile mom: company=Self-Employed (NOT Acme-Retired) + fields=2 12// 4 profile-multikey profile alex: role=CTO + fields=3 13// 5 find-single find company Self-Employed -> contact=mom + matches=1 14// 6 find-multi find city Dallas -> mom AND alex + matches=2 (search/segment foundation) 15// 7 find-nomatch find company Nope -> matches=0 16// 8 neg-no-file load missing file -> exit 1 17// Evidence: VIZSLA-CONTACT-GATE -> stdout + knowledge/status/vizsla_gate.log; exit 0 iff 8/8. 18// license_tier: ORIGINAL 19import "nx_syscalls.nx" 20import "nx_gate_verdict.nx" 21 22func og_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 23func og_p(s: *u8) -> i64 { sys_write(1, s, og_slen(s)); return 0 } 24 25func og_cat(dst: *u8, off: i64, s: *u8) -> i64 { 26 var i: i64 = 0 27 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 28 return off + i 29} 30 31func og_catn(dst: *u8, off: i64, v: i64) -> i64 { 32 var o: i64 = off 33 var m: i64 = v 34 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m } 35 let t: *u8 = sys_mmap(28) 36 var k: i64 = 0 37 if m == 0 { t[0] = 48 as u8; k = 1 } 38 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 39 var i: i64 = 0 40 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } 41 return o + k 42} 43 44func og_write(path: *u8, content: *u8) -> i64 { 45 let fd: i64 = sys_openat_wr(path, 0x1a4) 46 if fd < 0 { return 0 - 1 } 47 sys_write(fd, content, og_slen(content)) 48 sys_close(fd) 49 return 0 50} 51 52func og_readall(path: *u8, szout: *i64) -> *u8 { 53 let fd: i64 = sys_openat_rd(path) 54 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 } 55 let sz: i64 = sys_lseek(fd, 0, 2) 56 sys_lseek(fd, 0, 0) 57 let buf: *u8 = sys_mmap(sz + 64) 58 var got: i64 = 0 59 var n: i64 = 1 60 while n > 0 { n = sys_read(fd, (buf as i64 + got) as *u8, 65536); if n > 0 { got = got + n } } 61 sys_close(fd) 62 szout[0] = got 63 return buf 64} 65 66func og_runv(elf: *u8, args: *i64, outpath: *u8) -> i64 { 67 let pid: i64 = sys_fork() 68 if pid == 0 { 69 if (outpath as i64) != 0 { 70 let ofd: i64 = sys_openat_wr(outpath, 0x1a4) 71 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) } 72 } 73 let argv: *i64 = sys_mmap(128) as *i64 74 argv[0] = elf as i64 75 var i: i64 = 0 76 var go: i64 = 1 77 while go == 1 { if args[i] == 0 { go = 0 } else { argv[i + 1] = args[i]; i = i + 1 } } 78 argv[i + 1] = 0 79 let envp: *i64 = sys_mmap(16) as *i64 80 envp[0] = 0 81 sys_execve(elf, argv, envp) 82 sys_exit(127) 83 } 84 let st: *i64 = sys_mmap(16) as *i64 85 sys_wait4(pid, st, 0) 86 let sig: i64 = st[0] & 0x7f 87 if sig != 0 { return 128 + sig } 88 return (st[0] >> 8) & 0xff 89} 90 91func og_has(path: *u8, needle: *u8) -> i64 { 92 let szp: *i64 = sys_mmap(16) as *i64 93 let b: *u8 = og_readall(path, szp) 94 let sz: i64 = szp[0] 95 let n: i64 = og_slen(needle) 96 if sz < n { return 0 } 97 var i: i64 = 0 98 while i + n <= sz { 99 var ok: i64 = 1 100 var j: i64 = 0 101 while j < n { if b[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 } } 102 if ok == 1 { return 1 } 103 i = i + 1 104 } 105 return 0 106} 107 108func og_row(name: *u8, pass: i64) -> i64 { 109 og_p("ROW " as *u8); og_p(name) 110 if pass == 1 { og_p(" PASS\n" as *u8) } else { og_p(" FAIL\n" as *u8) } 111 return pass 112} 113 114func og_args(a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8) -> *i64 { 115 let a: *i64 = sys_mmap(64) as *i64 116 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 117 return a 118} 119 120func main(argc: i64, argv: *i64) -> i64 { 121 og_p("=== VIZSLA CONTACT GATE: rich fields (latest-per-key) + profile + search-by-field ===\n" as *u8) 122 var ob: *u8 = "buildroot/_build/nx_vizsla_contact.sov.elf" as *u8 123 if argc > 1 { ob = argv[1] as *u8 } 124 let pr: i64 = sys_openat_rd(ob) 125 if pr >= 0 { sys_close(pr) } 126 else { 127 og_p(" instrument missing -> rebuilding via durable runner\n" as *u8) 128 og_runv("_offc/nx_sov_build_run.elf" as *u8, og_args("nx_vizsla_contact" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8), "/tmp/vkc_rebuild.out" as *u8) 129 } 130 131 let pfx: *u8 = sys_mmap(128) 132 var po: i64 = 0 133 po = og_cat(pfx, po, "/tmp/vkcG" as *u8); po = og_catn(pfx, po, sys_now_us()); po = og_cat(pfx, po, "-" as *u8) 134 pfx[po] = 0 as u8 135 136 og_write("/tmp/vkc_fields.txt" as *u8, "FIELD 2026-06-01 mom company Acme-Retired\nFIELD 2026-06-10 mom company Self-Employed\nFIELD 2026-06-01 mom city Dallas\nFIELD 2026-06-01 alex company Globex\nFIELD 2026-06-01 alex role CTO\nFIELD 2026-06-01 alex city Dallas\n" as *u8) 137 138 var pass: i64 = 0 139 var r: i64 = 0 140 141 let rc1: i64 = og_runv(ob, og_args("load" as *u8, "/tmp/vkc_fields.txt" as *u8, pfx, "9901" as *u8, 0 as *u8), "/tmp/vkc_l1.txt" as *u8) 142 r = 0 143 if rc1 == 0 { if og_has("/tmp/vkc_l1.txt" as *u8, "VIZSLA-CONTACT-LOAD scanned=6 new=6 dup_infile=0 dup_instore=0 segment=seg-9901" as *u8) == 1 { r = 1 } } 144 pass = pass + og_row("load" as *u8, r) 145 146 let rc2: i64 = og_runv(ob, og_args("load" as *u8, "/tmp/vkc_fields.txt" as *u8, pfx, "9909" as *u8, 0 as *u8), "/tmp/vkc_l2.txt" as *u8) 147 r = 0 148 if rc2 == 0 { if og_has("/tmp/vkc_l2.txt" as *u8, "VIZSLA-CONTACT-LOAD scanned=6 new=0 dup_infile=0 dup_instore=6 segment=none" as *u8) == 1 { r = 1 } } 149 pass = pass + og_row("idempotent-reload" as *u8, r) 150 151 og_runv(ob, og_args("profile" as *u8, pfx, "mom" as *u8, 0 as *u8, 0 as *u8), "/tmp/vkc_pm.txt" as *u8) 152 r = 0 153 if og_has("/tmp/vkc_pm.txt" as *u8, "VIZSLA-CONTACT-FIELD contact=mom key=company value=Self-Employed" as *u8) == 1 { if og_has("/tmp/vkc_pm.txt" as *u8, "VIZSLA-CONTACT-PROFILE contact=mom fields=2" as *u8) == 1 { r = 1 } } 154 pass = pass + og_row("profile-latest-wins" as *u8, r) 155 156 og_runv(ob, og_args("profile" as *u8, pfx, "alex" as *u8, 0 as *u8, 0 as *u8), "/tmp/vkc_pa.txt" as *u8) 157 r = 0 158 if og_has("/tmp/vkc_pa.txt" as *u8, "VIZSLA-CONTACT-FIELD contact=alex key=role value=CTO" as *u8) == 1 { if og_has("/tmp/vkc_pa.txt" as *u8, "VIZSLA-CONTACT-PROFILE contact=alex fields=3" as *u8) == 1 { r = 1 } } 159 pass = pass + og_row("profile-multikey" as *u8, r) 160 161 og_runv(ob, og_args("find" as *u8, pfx, "company" as *u8, "Self-Employed" as *u8, 0 as *u8), "/tmp/vkc_f1.txt" as *u8) 162 r = 0 163 if og_has("/tmp/vkc_f1.txt" as *u8, "VIZSLA-CONTACT-MATCH contact=mom key=company value=Self-Employed" as *u8) == 1 { if og_has("/tmp/vkc_f1.txt" as *u8, "matches=1" as *u8) == 1 { r = 1 } } 164 pass = pass + og_row("find-single" as *u8, r) 165 166 og_runv(ob, og_args("find" as *u8, pfx, "city" as *u8, "Dallas" as *u8, 0 as *u8), "/tmp/vkc_f2.txt" as *u8) 167 var m1: i64 = og_has("/tmp/vkc_f2.txt" as *u8, "VIZSLA-CONTACT-MATCH contact=mom key=city value=Dallas" as *u8) 168 var m2: i64 = og_has("/tmp/vkc_f2.txt" as *u8, "VIZSLA-CONTACT-MATCH contact=alex key=city value=Dallas" as *u8) 169 var m3: i64 = og_has("/tmp/vkc_f2.txt" as *u8, "matches=2" as *u8) 170 r = 0 171 if m1 == 1 { if m2 == 1 { if m3 == 1 { r = 1 } } } 172 pass = pass + og_row("find-multi" as *u8, r) 173 174 og_runv(ob, og_args("find" as *u8, pfx, "company" as *u8, "Nonexistent" as *u8, 0 as *u8), "/tmp/vkc_f3.txt" as *u8) 175 r = og_has("/tmp/vkc_f3.txt" as *u8, "VIZSLA-CONTACT-FIND key=company value=Nonexistent matches=0" as *u8) 176 pass = pass + og_row("find-nomatch" as *u8, r) 177 178 let rc8: i64 = og_runv(ob, og_args("load" as *u8, "/tmp/vkc_NOPE.txt" as *u8, "/tmp/vkcNx-" as *u8, "1" as *u8, 0 as *u8), "/tmp/vkc_8.txt" as *u8) 179 r = 0 180 if rc8 == 1 { r = 1 } 181 pass = pass + og_row("neg-no-file" as *u8, r) 182 183 let permil: i64 = (pass * 1000) / 8 184 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4) 185 var fdi: i64 = 0 186 while fdi < 2 { 187 var fd: i64 = 1 188 if fdi == 1 { fd = logfd } 189 if fd > 0 { 190 let line: *u8 = sys_mmap(256) 191 var o: i64 = 0 192 o = og_cat(line, o, "VIZSLA-CONTACT-GATE epoch=" as *u8) 193 o = og_catn(line, o, sys_now_realtime_sec()) 194 o = og_cat(line, o, " rows=8 pass=" as *u8) 195 o = og_catn(line, o, pass) 196 o = og_cat(line, o, " permil=" as *u8) 197 o = og_catn(line, o, permil) 198 if pass == 8 { o = og_cat(line, o, " verdict=GREEN\n" as *u8) } else { o = og_cat(line, o, " verdict=RED\n" as *u8) } 199 sys_write(fd, line, o) 200 } 201 fdi = fdi + 1 202 } 203 if logfd > 0 { sys_close(logfd) } 204 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 205 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 206 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 207 let ctr__dry: *i64 = gv_ctr() 208 ctr__dry[0] = pass 209 ctr__dry[1] = 8 210 let rc__dry: i64 = gv_verdict("VIZSLA-CONTACT-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 211 sys_exit(rc__dry) 212 return rc__dry 213}