code wiki / _hdl_build / nx_vizsla_capture_gate.nx

nx_vizsla_capture_gate.nx source

↩ module page · 183 lines · 8260 B

1// nx_vizsla_capture_gate.nx -- VIZSLA capture gate: the opt-in page->person extractor pulls a contact from a 2// loaded page's structured data (JSON-LD Person > og:title > <title>), strips the site suffix, and emits an 3// action-ready suggestion -- NEVER auto-adding. 100% sovereign: writes synthetic page fixtures, runs the 4// extractor, greps the suggestion. (The realm choice + confirm happen downstream; this is just the extractor.) 5// 6// Rows: 7// 1 jsonld-person JSON-LD {"@type":"Person","name":"Ada Lovelace"} -> id=ada-lovelace name=Ada-Lovelace source=jsonld 8// 2 og-title <meta og:title "Grace Hopper - Rear Admiral | LinkedIn"> -> id=grace-hopper source=og (suffix stripped) 9// 3 title-fallback <title>Alan Turing | LinkedIn</title> -> id=alan-turing source=title (suffix stripped) 10// 4 priority-jsonld JSON-LD + og both present -> JSON-LD wins (source=jsonld, NOT the og "Wrong Name") 11// 5 form-output emits VIZSLA-CAPTURE-FORM id=ada-lovelace&name=Ada-Lovelace (action-ready body) 12// 6 neg-no-person a page with no Person/og/title -> exit 1 13// Evidence: VIZSLA-CAPTURE-GATE -> stdout + knowledge/status/vizsla_gate.log; exit 0 iff 6/6. 14// license_tier: ORIGINAL 15import "nx_syscalls.nx" 16 17func og_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 18func og_p(s: *u8) -> i64 { sys_write(1, s, og_slen(s)); return 0 } 19 20func og_cat(dst: *u8, off: i64, s: *u8) -> i64 { 21 var i: i64 = 0 22 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 23 return off + i 24} 25 26func og_catn(dst: *u8, off: i64, v: i64) -> i64 { 27 var o: i64 = off 28 var m: i64 = v 29 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m } 30 let t: *u8 = sys_mmap(28) 31 var k: i64 = 0 32 if m == 0 { t[0] = 48 as u8; k = 1 } 33 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 34 var i: i64 = 0 35 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } 36 return o + k 37} 38 39func og_write(path: *u8, content: *u8) -> i64 { 40 let fd: i64 = sys_openat_wr(path, 0x1a4) 41 if fd < 0 { return 0 - 1 } 42 sys_write(fd, content, og_slen(content)) 43 sys_close(fd) 44 return 0 45} 46 47func og_readall(path: *u8, szout: *i64) -> *u8 { 48 let fd: i64 = sys_openat_rd(path) 49 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 } 50 let sz: i64 = sys_lseek(fd, 0, 2) 51 sys_lseek(fd, 0, 0) 52 let buf: *u8 = sys_mmap(sz + 64) 53 var got: i64 = 0 54 var n: i64 = 1 55 while n > 0 { n = sys_read(fd, (buf as i64 + got) as *u8, 65536); if n > 0 { got = got + n } } 56 sys_close(fd) 57 szout[0] = got 58 return buf 59} 60 61func og_runv(elf: *u8, args: *i64, outpath: *u8) -> i64 { 62 let pid: i64 = sys_fork() 63 if pid == 0 { 64 if (outpath as i64) != 0 { 65 let ofd: i64 = sys_openat_wr(outpath, 0x1a4) 66 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) } 67 } 68 let argv: *i64 = sys_mmap(128) as *i64 69 argv[0] = elf as i64 70 var i: i64 = 0 71 var go: i64 = 1 72 while go == 1 { if args[i] == 0 { go = 0 } else { argv[i + 1] = args[i]; i = i + 1 } } 73 argv[i + 1] = 0 74 let envp: *i64 = sys_mmap(16) as *i64 75 envp[0] = 0 76 sys_execve(elf, argv, envp) 77 sys_exit(127) 78 } 79 let st: *i64 = sys_mmap(16) as *i64 80 sys_wait4(pid, st, 0) 81 let sig: i64 = st[0] & 0x7f 82 if sig != 0 { return 128 + sig } 83 return (st[0] >> 8) & 0xff 84} 85 86func og_has(path: *u8, needle: *u8) -> i64 { 87 let szp: *i64 = sys_mmap(16) as *i64 88 let b: *u8 = og_readall(path, szp) 89 let sz: i64 = szp[0] 90 let n: i64 = og_slen(needle) 91 if sz < n { return 0 } 92 var i: i64 = 0 93 while i + n <= sz { 94 var ok: i64 = 1 95 var j: i64 = 0 96 while j < n { if b[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 } } 97 if ok == 1 { return 1 } 98 i = i + 1 99 } 100 return 0 101} 102 103func og_row(name: *u8, pass: i64) -> i64 { 104 og_p("ROW " as *u8); og_p(name) 105 if pass == 1 { og_p(" PASS\n" as *u8) } else { og_p(" FAIL\n" as *u8) } 106 return pass 107} 108 109func og_args(a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8) -> *i64 { 110 let a: *i64 = sys_mmap(64) as *i64 111 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 112 return a 113} 114 115func main(argc: i64, argv: *i64) -> i64 { 116 og_p("=== VIZSLA CAPTURE GATE: opt-in page->person extractor (JSON-LD/og/title) ===\n" as *u8) 117 var ob: *u8 = "/tmp/nx_vizsla_capture.sov.elf" as *u8 118 if argc > 1 { ob = argv[1] as *u8 } 119 let pr: i64 = sys_openat_rd(ob) 120 if pr >= 0 { sys_close(pr) } 121 else { 122 og_p(" instrument missing -> rebuilding via durable runner\n" as *u8) 123 og_runv("_offc/nx_sov_build_run.elf" as *u8, og_args("nx_vizsla_capture" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8), "/tmp/vzcap_rebuild.out" as *u8) 124 } 125 126 og_write("/tmp/cap_jsonld.html" as *u8, "<html><head><script type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"Person\",\"name\":\"Ada Lovelace\",\"jobTitle\":\"Mathematician\"}</script></head><body>x</body></html>" as *u8) 127 og_write("/tmp/cap_og.html" as *u8, "<html><head><meta property=\"og:title\" content=\"Grace Hopper - Rear Admiral | LinkedIn\"></head><body></body></html>" as *u8) 128 og_write("/tmp/cap_title.html" as *u8, "<html><head><title>Alan Turing | LinkedIn</title></head><body></body></html>" as *u8) 129 og_write("/tmp/cap_pri.html" as *u8, "<html><head><script type=\"application/ld+json\">{\"@type\":\"Person\",\"name\":\"Ada Lovelace\"}</script><meta property=\"og:title\" content=\"Wrong Name\"></head></html>" as *u8) 130 og_write("/tmp/cap_none.html" as *u8, "<html><head></head><body>just some text, nobody here</body></html>" as *u8) 131 132 var pass: i64 = 0 133 var r: i64 = 0 134 135 og_runv(ob, og_args("extract" as *u8, "/tmp/cap_jsonld.html" as *u8, 0 as *u8, 0 as *u8, 0 as *u8), "/tmp/cap_r1.txt" as *u8) 136 r = og_has("/tmp/cap_r1.txt" as *u8, "VIZSLA-CAPTURE id=ada-lovelace name=Ada-Lovelace source=jsonld" as *u8) 137 pass = pass + og_row("jsonld-person" as *u8, r) 138 139 og_runv(ob, og_args("extract" as *u8, "/tmp/cap_og.html" as *u8, 0 as *u8, 0 as *u8, 0 as *u8), "/tmp/cap_r2.txt" as *u8) 140 r = og_has("/tmp/cap_r2.txt" as *u8, "id=grace-hopper name=Grace-Hopper source=og" as *u8) 141 pass = pass + og_row("og-title" as *u8, r) 142 143 og_runv(ob, og_args("extract" as *u8, "/tmp/cap_title.html" as *u8, 0 as *u8, 0 as *u8, 0 as *u8), "/tmp/cap_r3.txt" as *u8) 144 r = og_has("/tmp/cap_r3.txt" as *u8, "id=alan-turing name=Alan-Turing source=title" as *u8) 145 pass = pass + og_row("title-fallback" as *u8, r) 146 147 og_runv(ob, og_args("extract" as *u8, "/tmp/cap_pri.html" as *u8, 0 as *u8, 0 as *u8, 0 as *u8), "/tmp/cap_r4.txt" as *u8) 148 r = 0 149 if og_has("/tmp/cap_r4.txt" as *u8, "source=jsonld" as *u8) == 1 { if og_has("/tmp/cap_r4.txt" as *u8, "Wrong" as *u8) == 0 { r = 1 } } 150 pass = pass + og_row("priority-jsonld-wins" as *u8, r) 151 152 r = og_has("/tmp/cap_r1.txt" as *u8, "VIZSLA-CAPTURE-FORM id=ada-lovelace&name=Ada-Lovelace" as *u8) 153 pass = pass + og_row("form-output" as *u8, r) 154 155 let rc6: i64 = og_runv(ob, og_args("extract" as *u8, "/tmp/cap_none.html" as *u8, 0 as *u8, 0 as *u8, 0 as *u8), "/tmp/cap_r6.txt" as *u8) 156 r = 0 157 if rc6 == 1 { r = 1 } 158 pass = pass + og_row("neg-no-person" as *u8, r) 159 160 let permil: i64 = (pass * 1000) / 6 161 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4) 162 var fdi: i64 = 0 163 while fdi < 2 { 164 var fd: i64 = 1 165 if fdi == 1 { fd = logfd } 166 if fd > 0 { 167 let line: *u8 = sys_mmap(256) 168 var o: i64 = 0 169 o = og_cat(line, o, "VIZSLA-CAPTURE-GATE epoch=" as *u8) 170 o = og_catn(line, o, sys_now_realtime_sec()) 171 o = og_cat(line, o, " rows=6 pass=" as *u8) 172 o = og_catn(line, o, pass) 173 o = og_cat(line, o, " permil=" as *u8) 174 o = og_catn(line, o, permil) 175 if pass == 6 { o = og_cat(line, o, " verdict=GREEN\n" as *u8) } else { o = og_cat(line, o, " verdict=RED\n" as *u8) } 176 sys_write(fd, line, o) 177 } 178 fdi = fdi + 1 179 } 180 if logfd > 0 { sys_close(logfd) } 181 if pass == 6 { return 0 } 182 return 1 183}