code wiki / _hdl_build / nx_vizsla_contact_gate.nx

nx_vizsla_contact_gate.nx source

↩ module page · 205 lines · 9230 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" 20 21func og_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 22func og_p(s: *u8) -> i64 { sys_write(1, s, og_slen(s)); return 0 } 23 24func og_cat(dst: *u8, off: i64, s: *u8) -> i64 { 25 var i: i64 = 0 26 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 27 return off + i 28} 29 30func og_catn(dst: *u8, off: i64, v: i64) -> i64 { 31 var o: i64 = off 32 var m: i64 = v 33 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m } 34 let t: *u8 = sys_mmap(28) 35 var k: i64 = 0 36 if m == 0 { t[0] = 48 as u8; k = 1 } 37 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 38 var i: i64 = 0 39 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } 40 return o + k 41} 42 43func og_write(path: *u8, content: *u8) -> i64 { 44 let fd: i64 = sys_openat_wr(path, 0x1a4) 45 if fd < 0 { return 0 - 1 } 46 sys_write(fd, content, og_slen(content)) 47 sys_close(fd) 48 return 0 49} 50 51func og_readall(path: *u8, szout: *i64) -> *u8 { 52 let fd: i64 = sys_openat_rd(path) 53 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 } 54 let sz: i64 = sys_lseek(fd, 0, 2) 55 sys_lseek(fd, 0, 0) 56 let buf: *u8 = sys_mmap(sz + 64) 57 var got: i64 = 0 58 var n: i64 = 1 59 while n > 0 { n = sys_read(fd, (buf as i64 + got) as *u8, 65536); if n > 0 { got = got + n } } 60 sys_close(fd) 61 szout[0] = got 62 return buf 63} 64 65func og_runv(elf: *u8, args: *i64, outpath: *u8) -> i64 { 66 let pid: i64 = sys_fork() 67 if pid == 0 { 68 if (outpath as i64) != 0 { 69 let ofd: i64 = sys_openat_wr(outpath, 0x1a4) 70 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) } 71 } 72 let argv: *i64 = sys_mmap(128) as *i64 73 argv[0] = elf as i64 74 var i: i64 = 0 75 var go: i64 = 1 76 while go == 1 { if args[i] == 0 { go = 0 } else { argv[i + 1] = args[i]; i = i + 1 } } 77 argv[i + 1] = 0 78 let envp: *i64 = sys_mmap(16) as *i64 79 envp[0] = 0 80 sys_execve(elf, argv, envp) 81 sys_exit(127) 82 } 83 let st: *i64 = sys_mmap(16) as *i64 84 sys_wait4(pid, st, 0) 85 let sig: i64 = st[0] & 0x7f 86 if sig != 0 { return 128 + sig } 87 return (st[0] >> 8) & 0xff 88} 89 90func og_has(path: *u8, needle: *u8) -> i64 { 91 let szp: *i64 = sys_mmap(16) as *i64 92 let b: *u8 = og_readall(path, szp) 93 let sz: i64 = szp[0] 94 let n: i64 = og_slen(needle) 95 if sz < n { return 0 } 96 var i: i64 = 0 97 while i + n <= sz { 98 var ok: i64 = 1 99 var j: i64 = 0 100 while j < n { if b[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 } } 101 if ok == 1 { return 1 } 102 i = i + 1 103 } 104 return 0 105} 106 107func og_row(name: *u8, pass: i64) -> i64 { 108 og_p("ROW " as *u8); og_p(name) 109 if pass == 1 { og_p(" PASS\n" as *u8) } else { og_p(" FAIL\n" as *u8) } 110 return pass 111} 112 113func og_args(a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8) -> *i64 { 114 let a: *i64 = sys_mmap(64) as *i64 115 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 116 return a 117} 118 119func main(argc: i64, argv: *i64) -> i64 { 120 og_p("=== VIZSLA CONTACT GATE: rich fields (latest-per-key) + profile + search-by-field ===\n" as *u8) 121 var ob: *u8 = "/tmp/nx_vizsla_contact.sov.elf" as *u8 122 if argc > 1 { ob = argv[1] as *u8 } 123 let pr: i64 = sys_openat_rd(ob) 124 if pr >= 0 { sys_close(pr) } 125 else { 126 og_p(" instrument missing -> rebuilding via durable runner\n" as *u8) 127 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) 128 } 129 130 let pfx: *u8 = sys_mmap(128) 131 var po: i64 = 0 132 po = og_cat(pfx, po, "/tmp/vkcG" as *u8); po = og_catn(pfx, po, sys_now_us()); po = og_cat(pfx, po, "-" as *u8) 133 pfx[po] = 0 as u8 134 135 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) 136 137 var pass: i64 = 0 138 var r: i64 = 0 139 140 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) 141 r = 0 142 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 } } 143 pass = pass + og_row("load" as *u8, r) 144 145 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) 146 r = 0 147 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 } } 148 pass = pass + og_row("idempotent-reload" as *u8, r) 149 150 og_runv(ob, og_args("profile" as *u8, pfx, "mom" as *u8, 0 as *u8, 0 as *u8), "/tmp/vkc_pm.txt" as *u8) 151 r = 0 152 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 } } 153 pass = pass + og_row("profile-latest-wins" as *u8, r) 154 155 og_runv(ob, og_args("profile" as *u8, pfx, "alex" as *u8, 0 as *u8, 0 as *u8), "/tmp/vkc_pa.txt" as *u8) 156 r = 0 157 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 } } 158 pass = pass + og_row("profile-multikey" as *u8, r) 159 160 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) 161 r = 0 162 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 } } 163 pass = pass + og_row("find-single" as *u8, r) 164 165 og_runv(ob, og_args("find" as *u8, pfx, "city" as *u8, "Dallas" as *u8, 0 as *u8), "/tmp/vkc_f2.txt" as *u8) 166 var m1: i64 = og_has("/tmp/vkc_f2.txt" as *u8, "VIZSLA-CONTACT-MATCH contact=mom key=city value=Dallas" as *u8) 167 var m2: i64 = og_has("/tmp/vkc_f2.txt" as *u8, "VIZSLA-CONTACT-MATCH contact=alex key=city value=Dallas" as *u8) 168 var m3: i64 = og_has("/tmp/vkc_f2.txt" as *u8, "matches=2" as *u8) 169 r = 0 170 if m1 == 1 { if m2 == 1 { if m3 == 1 { r = 1 } } } 171 pass = pass + og_row("find-multi" as *u8, r) 172 173 og_runv(ob, og_args("find" as *u8, pfx, "company" as *u8, "Nonexistent" as *u8, 0 as *u8), "/tmp/vkc_f3.txt" as *u8) 174 r = og_has("/tmp/vkc_f3.txt" as *u8, "VIZSLA-CONTACT-FIND key=company value=Nonexistent matches=0" as *u8) 175 pass = pass + og_row("find-nomatch" as *u8, r) 176 177 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) 178 r = 0 179 if rc8 == 1 { r = 1 } 180 pass = pass + og_row("neg-no-file" as *u8, r) 181 182 let permil: i64 = (pass * 1000) / 8 183 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4) 184 var fdi: i64 = 0 185 while fdi < 2 { 186 var fd: i64 = 1 187 if fdi == 1 { fd = logfd } 188 if fd > 0 { 189 let line: *u8 = sys_mmap(256) 190 var o: i64 = 0 191 o = og_cat(line, o, "VIZSLA-CONTACT-GATE epoch=" as *u8) 192 o = og_catn(line, o, sys_now_realtime_sec()) 193 o = og_cat(line, o, " rows=8 pass=" as *u8) 194 o = og_catn(line, o, pass) 195 o = og_cat(line, o, " permil=" as *u8) 196 o = og_catn(line, o, permil) 197 if pass == 8 { o = og_cat(line, o, " verdict=GREEN\n" as *u8) } else { o = og_cat(line, o, " verdict=RED\n" as *u8) } 198 sys_write(fd, line, o) 199 } 200 fdi = fdi + 1 201 } 202 if logfd > 0 { sys_close(logfd) } 203 if pass == 8 { return 0 } 204 return 1 205}