code wiki / _hdl_build / nx_vizsla_health_gate.nx
nx_vizsla_health_gate.nx source
↩ module page · 211 lines · 9301 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"
25import "nx_gate_verdict.nx"
26
27func og_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
28func og_p(s: *u8) -> i64 { sys_write(1, s, og_slen(s)); return 0 }
29
30func og_cat(dst: *u8, off: i64, s: *u8) -> i64 {
31 var i: i64 = 0
32 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 }
33 return off + i
34}
35
36func og_catn(dst: *u8, off: i64, v: i64) -> i64 {
37 var o: i64 = off
38 var m: i64 = v
39 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m }
40 let t: *u8 = sys_mmap(28)
41 var k: i64 = 0
42 if m == 0 { t[0] = 48 as u8; k = 1 }
43 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
44 var i: i64 = 0
45 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 }
46 return o + k
47}
48
49func og_write(path: *u8, content: *u8) -> i64 {
50 let fd: i64 = sys_openat_wr(path, 0x1a4)
51 if fd < 0 { return 0 - 1 }
52 sys_write(fd, content, og_slen(content))
53 sys_close(fd)
54 return 0
55}
56
57func og_readall(path: *u8, szout: *i64) -> *u8 {
58 let fd: i64 = sys_openat_rd(path)
59 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 }
60 let sz: i64 = sys_lseek(fd, 0, 2)
61 sys_lseek(fd, 0, 0)
62 let buf: *u8 = sys_mmap(sz + 64)
63 var got: i64 = 0
64 var n: i64 = 1
65 while n > 0 { n = sys_read(fd, (buf as i64 + got) as *u8, 65536); if n > 0 { got = got + n } }
66 sys_close(fd)
67 szout[0] = got
68 return buf
69}
70
71func og_runv(elf: *u8, args: *i64, outpath: *u8) -> i64 {
72 let pid: i64 = sys_fork()
73 if pid == 0 {
74 if (outpath as i64) != 0 {
75 let ofd: i64 = sys_openat_wr(outpath, 0x1a4)
76 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) }
77 }
78 let argv: *i64 = sys_mmap(128) as *i64
79 argv[0] = elf as i64
80 var i: i64 = 0
81 var go: i64 = 1
82 while go == 1 { if args[i] == 0 { go = 0 } else { argv[i + 1] = args[i]; i = i + 1 } }
83 argv[i + 1] = 0
84 let envp: *i64 = sys_mmap(16) as *i64
85 envp[0] = 0
86 sys_execve(elf, argv, envp)
87 sys_exit(127)
88 }
89 let st: *i64 = sys_mmap(16) as *i64
90 sys_wait4(pid, st, 0)
91 let sig: i64 = st[0] & 0x7f
92 if sig != 0 { return 128 + sig }
93 return (st[0] >> 8) & 0xff
94}
95
96func og_has(path: *u8, needle: *u8) -> i64 {
97 let szp: *i64 = sys_mmap(16) as *i64
98 let b: *u8 = og_readall(path, szp)
99 let sz: i64 = szp[0]
100 let n: i64 = og_slen(needle)
101 if sz < n { return 0 }
102 var i: i64 = 0
103 while i + n <= sz {
104 var ok: i64 = 1
105 var j: i64 = 0
106 while j < n { if b[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 } }
107 if ok == 1 { return 1 }
108 i = i + 1
109 }
110 return 0
111}
112
113func og_row(name: *u8, pass: i64) -> i64 {
114 og_p("ROW " as *u8); og_p(name)
115 if pass == 1 { og_p(" PASS\n" as *u8) } else { og_p(" FAIL\n" as *u8) }
116 return pass
117}
118
119func og_args(a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8) -> *i64 {
120 let a: *i64 = sys_mmap(64) as *i64
121 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
122 return a
123}
124
125func og_join(base: *u8, name: *u8) -> *u8 {
126 let p: *u8 = sys_mmap(512)
127 var o: i64 = 0
128 o = og_cat(p, o, base); o = og_cat(p, o, name); p[o] = 0 as u8
129 return p
130}
131
132func main(argc: i64, argv: *i64) -> i64 {
133 og_p("=== VIZSLA HEALTH GATE: relationship intelligence (recency+frequency+reciprocity -> health) ===\n" as *u8)
134 var ob: *u8 = "buildroot/_build/nx_vizsla_health.sov.elf" as *u8
135 if argc > 1 { ob = argv[1] as *u8 }
136 let pr: i64 = sys_openat_rd(ob)
137 if pr >= 0 { sys_close(pr) }
138 else {
139 og_p(" instrument missing -> rebuilding via durable runner\n" as *u8)
140 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)
141 }
142
143 let base: *u8 = sys_mmap(256)
144 var bo: i64 = 0
145 bo = og_cat(base, bo, "/tmp/vzhG" as *u8); bo = og_catn(base, bo, sys_now_us()); bo = og_cat(base, bo, "_" as *u8)
146 base[bo] = 0 as u8
147
148 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)
149 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)
150
151 let logp: *u8 = og_join(base, "h.relate_log.txt" as *u8)
152 let pfx: *u8 = og_join(base, "h.relate-" as *u8)
153 let cpath: *u8 = og_join(base, "h.contacts.txt" as *u8)
154 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)
155
156 var pass: i64 = 0
157 var r: i64 = 0
158
159 og_runv(ob, og_args("score" as *u8, pfx, cpath, "2026-06-23" as *u8, 0 as *u8), "/tmp/vzh_s.txt" as *u8)
160
161 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)
162 pass = pass + og_row("mom-thriving" as *u8, r)
163
164 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)
165 pass = pass + og_row("alex-steady" as *u8, r)
166
167 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)
168 pass = pass + og_row("pat-at-risk" as *u8, r)
169
170 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)
171 pass = pass + og_row("sam-new" as *u8, r)
172
173 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)
174 pass = pass + og_row("verdict" as *u8, r)
175
176 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)
177 r = 0
178 if rc6 == 1 { r = 1 }
179 pass = pass + og_row("neg-no-contacts" as *u8, r)
180
181 let permil: i64 = (pass * 1000) / 6
182 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4)
183 var fdi: i64 = 0
184 while fdi < 2 {
185 var fd: i64 = 1
186 if fdi == 1 { fd = logfd }
187 if fd > 0 {
188 let line: *u8 = sys_mmap(256)
189 var o: i64 = 0
190 o = og_cat(line, o, "VIZSLA-HEALTH-GATE epoch=" as *u8)
191 o = og_catn(line, o, sys_now_realtime_sec())
192 o = og_cat(line, o, " rows=6 pass=" as *u8)
193 o = og_catn(line, o, pass)
194 o = og_cat(line, o, " permil=" as *u8)
195 o = og_catn(line, o, permil)
196 if pass == 6 { o = og_cat(line, o, " verdict=GREEN\n" as *u8) } else { o = og_cat(line, o, " verdict=RED\n" as *u8) }
197 sys_write(fd, line, o)
198 }
199 fdi = fdi + 1
200 }
201 if logfd > 0 { sys_close(logfd) }
202 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
203 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
204 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
205 let ctr__dry: *i64 = gv_ctr()
206 ctr__dry[0] = pass
207 ctr__dry[1] = 6
208 let rc__dry: i64 = gv_verdict("VIZSLA-HEALTH-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
209 sys_exit(rc__dry)
210 return rc__dry
211}