nx_clipcheck_gate.nx source
↩ module page · 265 lines · 14663 B
1// nx_clipcheck_gate.nx -- GATE for the animation clipping ruler (debt 1786578438). A NEW DETECTOR
2// IS GUILTY UNTIL PROVEN: these teeth prove the geometry core fires on a planted clip, stays
3// silent on a clean pose, and that the eligibility rule excludes bind-inside joints (the false-
4// positive class hips/shoulders would be). The real shipped clip runs behind gv_need as a census.
5// T7 is the NXA byte-level decode proof; T8 is the BVH CONTROL-LANE proof (synthetic BVH through
6// the real parser+FK+capsule with exact planted geometry); T10 is the standing mocap-self-
7// clearance control census on the real salsa source (the two-instruments law, run every beat).
8// license_tier: ORIGINAL expect_exit: 0
9import "nx_syscalls.nx"
10import "nx_clipcheck.nx"
11import "nx_gate_verdict.nx"
12
13func g_cat(b: *u8, o: i64, s: *u8) -> i64 {
14 var i: i64 = 0
15 while s[i] != (0 as u8) { b[o + i] = s[i]; i = i + 1 }
16 return o + i
17}
18
19func main() -> i64 {
20 let ctr: *i64 = gv_ctr()
21 gv_head("nx_clipcheck_gate -- the clipping ruler bites on planted clips and stays silent on clean poses" as *u8)
22 sys_mkdir("/tmp/nx_clipcheck_gate" as *u8, 0x1ed)
23
24 // shared axis: torso at x=0,y=0, z 40..80 of a 17000 (0.01mm) stature, floor at z=0
25 let AX: *i64 = sys_mmap(8*8) as *i64
26 AX[0] = 0
27 AX[1] = 0
28 AX[2] = 68000
29 AX[3] = 136000
30 AX[4] = 0
31 let R: *i64 = sys_mmap(16*8) as *i64
32 var z: i64 = 0
33 while z < 10 { R[z] = 0; z = z + 1 }
34
35 // T1 CLEAN: a wrist 500mm out at chest height -> zero penetration recorded
36 cc_meas(50000, 0, 100000, 9, 0, AX, R)
37 gv_check("T1 clean pose: far joint records zero torso and floor penetration" as *u8, (R[0] == 0) as i64 + (R[3] == 0) as i64 == 2, ctr)
38
39 // T2 PLANTED TORSO CLIP: joint ON the axis at chest height -> depth exactly TORSO_R+LIMB_R
40 cc_meas(0, 0, 100000, 9, 7, AX, R)
41 var t2: i64 = 0
42 if R[0] == CC_TORSO_R + CC_LIMB_R { if R[1] == 7 { if R[2] == 9 { t2 = 1 } } }
43 gv_puts(" planted torso depth=" as *u8); gv_num(R[0]/100); gv_puts("mm (want " as *u8); gv_num((CC_TORSO_R+CC_LIMB_R)/100); gv_puts(")\n" as *u8)
44 gv_check("T2 planted torso clip fires: exact depth, key and joint NAMED" as *u8, t2, ctr)
45
46 // T3 PLANTED FLOOR CLIP: joint 50mm below the sole -> floor depth 50mm + limb radius
47 cc_meas(50000, 0, 0 - 5000, 11, 3, AX, R)
48 var t3: i64 = 0
49 if R[3] == 5000 + CC_LIMB_R { if R[4] == 3 { if R[5] == 11 { t3 = 1 } } }
50 gv_puts(" planted floor depth=" as *u8); gv_num(R[3]/100); gv_puts("mm\n" as *u8)
51 gv_check("T3 planted floor clip fires: exact depth, key and joint NAMED" as *u8, t3, ctr)
52
53 // T4 neg-control-eligibility: a hip-like bind (90mm off axis) sits INSIDE capsule+grace --
54 // the eligibility rule (bind distance) must exclude it, or every hip is a false positive
55 let bd: i64 = cc_pseg(9000, 0, 70000, AX[0], AX[1], AX[2], AX[3])
56 gv_check("T4 neg-control-eligibility: hip-like bind measures INSIDE capsule+grace (excluded by rule)" as *u8, (bd <= CC_TORSO_R + CC_LIMB_R + CC_GRACE) as i64, ctr)
57
58 // T5 segment-distance geometry: above the capsule top, distance includes the vertical gap
59 let dtop: i64 = cc_pseg(0, 0, 150000, AX[0], AX[1], AX[2], AX[3])
60 gv_check("T5 capsule end-cap: distance above the top includes the vertical gap" as *u8, (dtop == 14000) as i64, ctr)
61
62 // T6 the SHIPPED clip scans end-to-end (census: numbers must exist; verdict judged elsewhere)
63 var have: i64 = 0
64 let fd: i64 = sys_openat_rd("sites/nishifamily/world/ref9d_salsa4.nxa" as *u8)
65 if fd >= 0 { have = 1; sys_close(fd) }
66 if gv_need("sites/nishifamily/world/ref9d_salsa4.nxa" as *u8, have, ctr) == 1 {
67 let R2: *i64 = sys_mmap(16*8) as *i64
68 let rc: i64 = cc_scan_nxa("sites/nishifamily/world/ref9d_salsa4.nxa" as *u8, R2)
69 var t6: i64 = 0
70 if rc == 0 { if R2[6] > 0 { if R2[7] > 0 { t6 = 1 } } }
71 gv_puts(" salsa4: eligible=" as *u8); gv_num(R2[6])
72 gv_puts(" measured=" as *u8); gv_num(R2[7])
73 gv_puts(" worst_torso_mm=" as *u8); gv_num(R2[0]/100)
74 gv_puts(" worst_floor_mm=" as *u8); gv_num(R2[3]/100)
75 gv_puts("\n" as *u8)
76 gv_check("T6 shipped salsa4 scans: eligible tracks found, keys measured, numbers reported" as *u8, t6, ctr)
77 }
78
79 // ---- T7 BYTE-LEVEL DECODE PROOF: a synthetic NXA through the REAL reader+scanner ----
80 // 2 joints (spine origin + a wrist 500mm out), 1 chn-2 track, 2 keys: key0 dt=0 (clean),
81 // key1 dt=(-500,+7,-300)mm -- negative sign-extension, x100 scale, key indexing, TOC+payload
82 // checksums all exercised end-to-end. Expected penetration EXACT: axis-dist 7mm -> 140-7=133mm.
83 let SK: i64 = 17
84 let AN: i64 = 8
85 let fw2: i64 = 4 + 8 + SK + AN
86 let F: *i64 = sys_mmap(fw2*8 + 64) as *i64
87 F[0] = nxa_magic()
88 F[1] = 1
89 F[2] = 2
90 let skoff: i64 = 32 + 64
91 let anoff: i64 = skoff + SK*8
92 // SKEL payload at word (skoff/8)
93 let sk0: i64 = skoff/8
94 F[sk0] = 2
95 F[sk0+1] = 0 - 1
96 F[sk0+2] = 0
97 F[sk0+3] = 0
98 F[sk0+4] = 0
99 var zz: i64 = 5
100 while zz < 9 { F[sk0+zz] = 0; zz = zz + 1 }
101 F[sk0+9] = 0
102 F[sk0+10] = 50000
103 F[sk0+11] = 0
104 F[sk0+12] = 100000
105 var zz2: i64 = 13
106 while zz2 < 17 { F[sk0+zz2] = 0; zz2 = zz2 + 1 }
107 // ANIM payload
108 let an0: i64 = anoff/8
109 F[an0] = 1
110 F[an0+1] = 1
111 F[an0+2] = 2
112 F[an0+3] = 2
113 F[an0+4] = 0
114 F[an0+5] = 0
115 let dgxw: i64 = (0 - 500) & 0xffff
116 let dgyw: i64 = 7
117 let dgzw: i64 = (0 - 300) & 0xffff
118 F[an0+6] = 100
119 F[an0+7] = (dgxw << 16) | (dgyw << 32) | (dgzw << 48)
120 // TOC rows (word 4..11) + checksums via the SAME lib the reader uses
121 F[4] = nxa_tag4("SKEL" as *u8)
122 F[5] = skoff
123 F[6] = SK
124 F[7] = nxa_check2(1, ((F as i64) + skoff) as *i64, SK)
125 F[8] = nxa_tag4("ANIM" as *u8)
126 F[9] = anoff
127 F[10] = AN
128 F[11] = nxa_check2(1, ((F as i64) + anoff) as *i64, AN)
129 F[3] = nxa_check2(1, ((F as i64) + 32) as *i64, 8)
130 let sp: *u8 = "/tmp/nx_clipcheck_gate/synth.nxa" as *u8
131 let sfd: i64 = sys_openat_wr(sp, 0x1a4)
132 if sfd < 0 { gv_puts(" FIXTURE-FAIL: cannot open synth path\n" as *u8) }
133 if sfd >= 0 { sys_write(sfd, F as *u8, fw2*8); sys_close(sfd) }
134 let R3: *i64 = sys_mmap(16*8) as *i64
135 let src: i64 = cc_scan_nxa(sp, R3)
136 var t7: i64 = 0
137 if src == 0 { if R3[6] == 1 { if R3[7] == 2 { if R3[0] == 13300 { if R3[1] == 1 { if R3[2] == 1 { if R3[3] == 0 { t7 = 1 } } } } } } }
138 gv_puts(" synth: rc=" as *u8); gv_num(src)
139 gv_puts(" eligible=" as *u8); gv_num(R3[6])
140 gv_puts(" measured=" as *u8); gv_num(R3[7])
141 gv_puts(" worst_torso=" as *u8); gv_num(R3[0])
142 gv_puts(" (want 13300) key=" as *u8); gv_num(R3[1])
143 gv_puts(" joint=" as *u8); gv_num(R3[2])
144 gv_puts("\n" as *u8)
145 gv_check("T7 DECODE PROOF: synthetic NXA through the real reader -- negative dt sign-extended, x100 scale, exact 133.00mm at key 1 joint 1" as *u8, t7, ctr)
146
147 // ---- T8 BVH CONTROL-LANE PROOF: a synthetic BVH through the REAL parser+FK+capsule ----
148 // THE FIXTURE IS BUILT TO KILL THE EXTENT HEURISTIC: a wide T-pose whose SPAN (28) exceeds
149 // its HEIGHT (26) -- extent-based up-detection provably picks X here (it did, live, on the
150 // CMU salsa source before this tooth existed); bone-length-weighted alignment picks Y
151 // (acc Y=36000 > X=32000, margin 6.6% -- deliberately inside the discriminating zone, above
152 // the 5% ambiguity refusal). 9 joints: Hips / Chest / Head / two 2-segment arms / two legs.
153 // Scaled to the T7 synthetic NXA (statn=100000, statb=26000). Frame 0 all-zero: torso clean,
154 // both feet AT the floor -> floor pen exactly CC_LIMB_R at key 0 joint 7, 4 floor counts over
155 // 2 frames. Frame 1 bends the right ELBOW (ArmR Rz 180): ForeR folds from (14,8,0) to
156 // (-2,8,0) -> scaled axis-dist 7692 -> penetration 14000-7692=6308 at key 1 joint 4
157 // (asserted 6200..6420: integer-trig quantization declared). Eligibility partition exact:
158 // Head + 2 arms + 2 forearms + 2 legs = 7; Hips (just below band) and Chest (in band) excluded.
159 let bb: *u8 = sys_mmap(4096)
160 var bo: i64 = 0
161 bo = g_cat(bb, bo, "HIERARCHY\nROOT Hips\n{\n" as *u8)
162 bo = g_cat(bb, bo, "OFFSET 0.00 0.00 0.00\n" as *u8)
163 bo = g_cat(bb, bo, "CHANNELS 6 Xposition Yposition Zposition Zrotation Xrotation Yrotation\n" as *u8)
164 bo = g_cat(bb, bo, "JOINT Chest\n{\n" as *u8)
165 bo = g_cat(bb, bo, "OFFSET 0.00 8.00 0.00\n" as *u8)
166 bo = g_cat(bb, bo, "CHANNELS 3 Zrotation Xrotation Yrotation\n" as *u8)
167 bo = g_cat(bb, bo, "JOINT Head\n{\n" as *u8)
168 bo = g_cat(bb, bo, "OFFSET 0.00 8.00 0.00\n" as *u8)
169 bo = g_cat(bb, bo, "CHANNELS 3 Zrotation Xrotation Yrotation\n" as *u8)
170 bo = g_cat(bb, bo, "End Site\n{\nOFFSET 0.00 1.00 0.00\n}\n}\n" as *u8)
171 bo = g_cat(bb, bo, "JOINT ArmR\n{\n" as *u8)
172 bo = g_cat(bb, bo, "OFFSET 6.00 0.00 0.00\n" as *u8)
173 bo = g_cat(bb, bo, "CHANNELS 3 Zrotation Xrotation Yrotation\n" as *u8)
174 bo = g_cat(bb, bo, "JOINT ForeR\n{\n" as *u8)
175 bo = g_cat(bb, bo, "OFFSET 8.00 0.00 0.00\n" as *u8)
176 bo = g_cat(bb, bo, "CHANNELS 3 Zrotation Xrotation Yrotation\n" as *u8)
177 bo = g_cat(bb, bo, "End Site\n{\nOFFSET 1.00 0.00 0.00\n}\n}\n}\n" as *u8)
178 bo = g_cat(bb, bo, "JOINT ArmL\n{\n" as *u8)
179 bo = g_cat(bb, bo, "OFFSET -6.00 0.00 0.00\n" as *u8)
180 bo = g_cat(bb, bo, "CHANNELS 3 Zrotation Xrotation Yrotation\n" as *u8)
181 bo = g_cat(bb, bo, "JOINT ForeL\n{\n" as *u8)
182 bo = g_cat(bb, bo, "OFFSET -8.00 0.00 0.00\n" as *u8)
183 bo = g_cat(bb, bo, "CHANNELS 3 Zrotation Xrotation Yrotation\n" as *u8)
184 bo = g_cat(bb, bo, "End Site\n{\nOFFSET -1.00 0.00 0.00\n}\n}\n}\n}\n" as *u8)
185 bo = g_cat(bb, bo, "JOINT LegL\n{\n" as *u8)
186 bo = g_cat(bb, bo, "OFFSET 2.00 -10.00 0.00\n" as *u8)
187 bo = g_cat(bb, bo, "CHANNELS 3 Zrotation Xrotation Yrotation\n" as *u8)
188 bo = g_cat(bb, bo, "End Site\n{\nOFFSET 0.00 -1.00 0.00\n}\n}\n" as *u8)
189 bo = g_cat(bb, bo, "JOINT LegR\n{\n" as *u8)
190 bo = g_cat(bb, bo, "OFFSET -2.00 -10.00 0.00\n" as *u8)
191 bo = g_cat(bb, bo, "CHANNELS 3 Zrotation Xrotation Yrotation\n" as *u8)
192 bo = g_cat(bb, bo, "End Site\n{\nOFFSET 0.00 -1.00 0.00\n}\n}\n}\n" as *u8)
193 bo = g_cat(bb, bo, "MOTION\nFrames: 2\nFrame Time: 0.0333333\n" as *u8)
194 bo = g_cat(bb, bo, "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" as *u8)
195 bo = g_cat(bb, bo, "0 0 0 0 0 0 0 0 0 0 0 0 180 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" as *u8)
196 bb[bo] = 0 as u8
197 let bp: *u8 = "/tmp/nx_clipcheck_gate/ctrl.bvh" as *u8
198 let bfd: i64 = sys_openat_wr(bp, 0x1a4)
199 if bfd < 0 { gv_puts(" FIXTURE-FAIL: cannot open ctrl.bvh path\n" as *u8) }
200 if bfd >= 0 { sys_write(bfd, bb, bo); sys_close(bfd) }
201 let R4: *i64 = sys_mmap(16*8) as *i64
202 let brc: i64 = cc_scan_bvh(bp, sp, 0 - 1, R4)
203 var t8: i64 = 0
204 if brc == 0 { if R4[6] == 7 { if R4[7] == 14 { if R4[8] == 1 { if R4[9] == 4 {
205 if R4[0] >= 6200 { if R4[0] <= 6420 { if R4[1] == 1 { if R4[2] == 4 {
206 if R4[3] == CC_LIMB_R { if R4[4] == 0 { if R4[5] == 7 {
207 if R4[10] == 1 { if R4[11] == 0 { t8 = 1 } }
208 } } }
209 } } } }
210 } } } } }
211 gv_puts(" bvh-ctrl: rc=" as *u8); gv_num(brc)
212 gv_puts(" eligible=" as *u8); gv_num(R4[6])
213 gv_puts(" measured=" as *u8); gv_num(R4[7])
214 gv_puts(" torso_keys=" as *u8); gv_num(R4[8])
215 gv_puts(" floor_keys=" as *u8); gv_num(R4[9])
216 gv_puts(" worst_torso=" as *u8); gv_num(R4[0])
217 gv_puts(" (want 6200..6420) key=" as *u8); gv_num(R4[1])
218 gv_puts(" joint=" as *u8); gv_num(R4[2])
219 gv_puts(" worst_floor=" as *u8); gv_num(R4[3])
220 gv_puts(" up=" as *u8); gv_num(R4[10])
221 gv_puts(" side=" as *u8); gv_num(R4[11])
222 gv_puts("\n" as *u8)
223 gv_check("T8 BVH CONTROL PROOF: span-exceeds-height T-pose (extent-up provably fails here, bone-alignment picks Y) -- planted elbow-bend penetrates at key 1 joint 4, floor exact at the feet, eligibility partition exact" as *u8, t8, ctr)
224
225 // ---- T9 neg-control-missing-bvh: an absent source must REFUSE (4), never fabricate ----
226 let R5: *i64 = sys_mmap(16*8) as *i64
227 let nrc: i64 = cc_scan_bvh("/tmp/nx_clipcheck_gate/absent.bvh" as *u8, sp, 0 - 1, R5)
228 gv_check("T9 neg-control-missing-bvh refuses with rc=4" as *u8, (nrc == 4) as i64, ctr)
229
230 // ---- T10 THE STANDING CONTROL CENSUS: the real salsa SOURCE against the same capsule ----
231 // (the mocap-self-clearance control, debt 1786598036: if the source clips where the NXA lane
232 // clips, the retarget is faithful. Numbers printed every beat; comparison judged in session.)
233 var haveb: i64 = 0
234 let cfd: i64 = sys_openat_rd("knowledge/cmu_salsa.bvh" as *u8)
235 if cfd >= 0 { haveb = 1; sys_close(cfd) }
236 var haven: i64 = 0
237 let nfd: i64 = sys_openat_rd("sites/nishifamily/world/ref9d.nxa" as *u8)
238 if nfd >= 0 { haven = 1; sys_close(nfd) }
239 var haveboth: i64 = 0
240 if haveb == 1 { if haven == 1 { haveboth = 1 } }
241 if gv_need("knowledge/cmu_salsa.bvh + sites/nishifamily/world/ref9d.nxa" as *u8, haveboth, ctr) == 1 {
242 let R6: *i64 = sys_mmap(16*8) as *i64
243 // up=y (axis 1) VERIFIED FROM THE DATA, not convention: nx_bvhfk pos frame 0 puts Head
244 // at wy=24823 and the feet at wy~400-1100 (2026-08-13). Auto-detection correctly REFUSES
245 // on this skeleton (bone-alignment acc y=41308 vs x=39487, within 5% -- arm span rivals
246 // height), so the verified hint is the honest lane.
247 let crc: i64 = cc_scan_bvh("knowledge/cmu_salsa.bvh" as *u8, "sites/nishifamily/world/ref9d.nxa" as *u8, 1, R6)
248 var t10: i64 = 0
249 if crc == 0 { if R6[6] > 0 { if R6[7] > 0 { t10 = 1 } } }
250 gv_puts(" salsa-source: eligible=" as *u8); gv_num(R6[6])
251 gv_puts(" measured=" as *u8); gv_num(R6[7])
252 gv_puts(" torso_keys=" as *u8); gv_num(R6[8])
253 gv_puts(" floor_keys=" as *u8); gv_num(R6[9])
254 gv_puts(" worst_torso_mm=" as *u8); gv_num(R6[0]/100)
255 gv_puts(" at key=" as *u8); gv_num(R6[1])
256 gv_puts(" joint=" as *u8); gv_num(R6[2])
257 gv_puts(" worst_floor_mm=" as *u8); gv_num(R6[3]/100)
258 gv_puts("\n" as *u8)
259 gv_check("T10 mocap-self-clearance control census: the salsa SOURCE measured by the same capsule, numbers reported" as *u8, t10, ctr)
260 }
261
262 let rc2: i64 = gv_verdict("CLIPCHECK-GATE" as *u8, ctr, "the clipping ruler: exact planted depths fire with key+joint named, clean poses silent, bind-inside joints excluded, wire decode byte-proven, bvh control lane planted-proven, source census standing" as *u8)
263 sys_exit(rc2)
264 return rc2
265}