code wiki / _hdl_build / nx_vizsla_health_gate.nx

nx_vizsla_health_gate.nx source

↩ module page · 203 lines · 8750 B

1// nx_vizsla_health_gate.nx -- VIZSLA relationship-intelligence gate: the health score is gate-proven against a 2// construction-known interaction history with HAND-COMPUTED scores (oracle in THIS header). 100% sovereign. 3// 4// today 2026-06-23. contacts: mom inner(30) alex close(90) pat close(90) sam network(180). 5// store: mom touched 06-10,05-01,03-01 (3) ; alex 02-01 (1) ; pat 2025-06-01 (1) ; sam never. 6// open OWE alex book ; open OWE pat dinner. 7// model: recency [<=cad 100, <=2x 70, <=4x 40, else 10] ; freq min(touch*25,100) ; balance 100-owe*25 ; 8// health = (rec*50 + freq*30 + bal*20)/100. 9// mom: rec100 freq75 bal100 -> (5000+2250+2000)/100 = 92 THRIVING 10// alex:dsince142<=180 rec70 freq25 owe1 bal75 -> (3500+750+1500)/100 = 57 STEADY 11// pat: dsince387>360 rec10 freq25 owe1 bal75 -> (500+750+1500)/100 = 27 AT-RISK (the quietly-dying one) 12// sam: never -> rec0 freq0 bal100 -> 20 NEW 13// => contacts=4 thriving=1 steady=1 cooling=0 at_risk=1 new=1 14// 15// Rows: 16// 1 mom-thriving health=92 status=THRIVING recency=100 freq=75 balance=100 touches=3 17// 2 alex-steady health=57 status=STEADY recency=70 freq=25 balance=75 touches=1 18// 3 pat-at-risk health=27 status=AT-RISK recency=10 freq=25 balance=75 touches=1 (recent obligation+stale = at risk) 19// 4 sam-new health=20 status=NEW recency=0 freq=0 balance=100 touches=0 20// 5 verdict contacts=4 thriving=1 steady=1 cooling=0 at_risk=1 new=1 21// 6 neg-no-contacts missing contacts -> exit 1 22// Evidence: VIZSLA-HEALTH-GATE -> stdout + knowledge/status/vizsla_gate.log; exit 0 iff 6/6. 23// license_tier: ORIGINAL 24import "nx_syscalls.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 HEALTH GATE: relationship intelligence (recency+frequency+reciprocity -> health) ===\n" as *u8) 133 var ob: *u8 = "/tmp/nx_vizsla_health.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_health" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8), "/tmp/vzh_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/vzhG" 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(og_join(base, "h.contacts.txt" as *u8), "CONF soon_days 14\nTIER inner 30\nTIER close 90\nTIER network 180\nCONTACT mom Mom inner 06-30\nCONTACT alex Alex close -\nCONTACT pat Pat close -\nCONTACT sam Sam network -\n" as *u8) 148 og_write(og_join(base, "h.relate_log.txt" as *u8), "TOUCH 2026-06-10 mom call\nTOUCH 2026-05-01 mom call\nTOUCH 2026-03-01 mom call\nTOUCH 2026-02-01 alex lunch\nTOUCH 2025-06-01 pat old\nOBLIGATION 2026-06-01 OWE alex book 0 owe-book\nOBLIGATION 2026-06-01 OWE pat dinner 0 owe-dinner\n" as *u8) 149 150 let logp: *u8 = og_join(base, "h.relate_log.txt" as *u8) 151 let pfx: *u8 = og_join(base, "h.relate-" as *u8) 152 let cpath: *u8 = og_join(base, "h.contacts.txt" as *u8) 153 og_runv("_offc/nx_vizsla_relate.elf" as *u8, og_args("load" as *u8, logp, pfx, "8801" as *u8, 0 as *u8), "/tmp/vzh_load.txt" as *u8) 154 155 var pass: i64 = 0 156 var r: i64 = 0 157 158 og_runv(ob, og_args("score" as *u8, pfx, cpath, "2026-06-23" as *u8, 0 as *u8), "/tmp/vzh_s.txt" as *u8) 159 160 r = og_has("/tmp/vzh_s.txt" as *u8, "VIZSLA-HEALTH contact=mom health=92 status=THRIVING recency=100 freq=75 balance=100 touches=3" as *u8) 161 pass = pass + og_row("mom-thriving" as *u8, r) 162 163 r = og_has("/tmp/vzh_s.txt" as *u8, "VIZSLA-HEALTH contact=alex health=57 status=STEADY recency=70 freq=25 balance=75 touches=1" as *u8) 164 pass = pass + og_row("alex-steady" as *u8, r) 165 166 r = og_has("/tmp/vzh_s.txt" as *u8, "VIZSLA-HEALTH contact=pat health=27 status=AT-RISK recency=10 freq=25 balance=75 touches=1" as *u8) 167 pass = pass + og_row("pat-at-risk" as *u8, r) 168 169 r = og_has("/tmp/vzh_s.txt" as *u8, "VIZSLA-HEALTH contact=sam health=20 status=NEW recency=0 freq=0 balance=100 touches=0" as *u8) 170 pass = pass + og_row("sam-new" as *u8, r) 171 172 r = og_has("/tmp/vzh_s.txt" as *u8, "VIZSLA-HEALTH-VERDICT contacts=4 thriving=1 steady=1 cooling=0 at_risk=1 new=1" as *u8) 173 pass = pass + og_row("verdict" as *u8, r) 174 175 let rc6: i64 = og_runv(ob, og_args("score" as *u8, pfx, "/tmp/vzh_NOPE.txt" as *u8, "2026-06-23" as *u8, 0 as *u8), "/tmp/vzh_neg.txt" as *u8) 176 r = 0 177 if rc6 == 1 { r = 1 } 178 pass = pass + og_row("neg-no-contacts" as *u8, r) 179 180 let permil: i64 = (pass * 1000) / 6 181 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4) 182 var fdi: i64 = 0 183 while fdi < 2 { 184 var fd: i64 = 1 185 if fdi == 1 { fd = logfd } 186 if fd > 0 { 187 let line: *u8 = sys_mmap(256) 188 var o: i64 = 0 189 o = og_cat(line, o, "VIZSLA-HEALTH-GATE epoch=" as *u8) 190 o = og_catn(line, o, sys_now_realtime_sec()) 191 o = og_cat(line, o, " rows=6 pass=" as *u8) 192 o = og_catn(line, o, pass) 193 o = og_cat(line, o, " permil=" as *u8) 194 o = og_catn(line, o, permil) 195 if pass == 6 { o = og_cat(line, o, " verdict=GREEN\n" as *u8) } else { o = og_cat(line, o, " verdict=RED\n" as *u8) } 196 sys_write(fd, line, o) 197 } 198 fdi = fdi + 1 199 } 200 if logfd > 0 { sys_close(logfd) } 201 if pass == 6 { return 0 } 202 return 1 203}