code wiki / (root) / nx_companion_photo_gate.nx

nx_companion_photo_gate.nx source

↩ module page · 92 lines · 6004 B

1// nx_companion_photo_gate.nx -- GATE for nx_companion_photo: the companion shares a grounded self-image AND 2// remembers it, coherently. (T1) a share advances the arc and returns a gen request carrying her identity + 3// current outfit; (T2) the same share writes an episodic memory "I sent you a photo of me <look, scene>"; 4// (T3) two shares -> two distinct memories with DIFFERENT looks (variety flows into what she remembers too). 5// Fresh /tmp visual + memory stores. license_tier: ORIGINAL expect_exit: 0 6import "nx_companion_photo.nx" 7import "nx_gate_verdict.nx" 8 9func gw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 10func gn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 } 11func gfind(hay: *u8, hlen: i64, needle: *u8) -> i64 { 12 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} 13 if nl==0 { return 1 } 14 if hlen<nl { return 0 } 15 var i: i64=0 16 while i<=hlen-nl { var m: i64=1; var c: i64=0; while c<nl { if hay[i+c]!=needle[c]{m=0;c=nl} else {c=c+1} } if m==1 {return 1} i=i+1 } 17 return 0 18} 19func gpeq(a: *u8, al: i64, b: *u8, bl: i64) -> i64 { if al!=bl {return 0} var i: i64=0; while i<al { if a[i]!=b[i]{return 0} i=i+1 } return 1 } 20func gmk(dst: *u8, tag: *u8, ms: i64) -> i64 { var o: i64=0; var i: i64=0; let pre: *u8="/tmp/photo-" as *u8; while pre[i]!=(0 as u8){dst[o]=pre[i];o=o+1;i=i+1} i=0; while tag[i]!=(0 as u8){dst[o]=tag[i];o=o+1;i=i+1} dst[o]=0x2D as u8; o=o+1; var m: i64=ms; var d: i64=7; while d>=0{dst[o+d]=(48+(m%10)) as u8; m=m/10; d=d-1} o=o+8; dst[o]=0x2D as u8; o=o+1; dst[o]=0 as u8; return o } 21 22func main() -> i64 { 23 gw("=== nx_companion_photo_gate (she shares a grounded photo AND remembers it) ===\n" as *u8) 24 let ms: i64 = sys_now_ms() % 100000000 25 let VPX: *u8 = sys_mmap(256); gmk(VPX, "v" as *u8, ms) 26 let MPX: *u8 = sys_mmap(256); gmk(MPX, "m" as *u8, ms) 27 28 vid_put_pfx(VPX, "aria" as *u8, 29 "Aria, long dark chestnut hair, hazel eyes, fair freckled skin" as *u8, 30 "wearing a loose tee|wearing a sundress|natural and at ease in her own skin|wearing a silk robe" as *u8, 31 "in a sunlit bedroom|in a golden-hour garden|in a warm kitchen" as *u8, 32 "reading|stretching in the light" as *u8) 33 34 var pass: i64 = 0 35 var tot: i64 = 0 36 let req: *u8 = sys_mmap(32768) 37 let sp: *i64 = sys_mmap(16) as *i64 38 let p: *i64 = sys_mmap(16) as *i64 39 let l: *i64 = sys_mmap(16) as *i64 40 41 // T1: share advances arc + returns a grounded gen request 42 tot=tot+1 43 let rl1: i64 = companion_share_photo_pfx(VPX, MPX, "aria" as *u8, "s1" as *u8, "1000" as *u8, req, 32768, sp) 44 var t1: i64 = 0 45 if sp[0] >= 1 { if gfind(req, rl1, "chestnut" as *u8)==1 { if gfind(req, rl1, "\"prompt\":" as *u8)==1 { t1=1 } } } 46 if t1==1 { pass=pass+1; gw("PASS T1 share: arc advanced to step " as *u8); gn(sp[0]); gw(", gen request carries her identity(chestnut)\n" as *u8) } else { gw("FAIL T1 step=" as *u8); gn(sp[0]); gw("\n" as *u8) } 47 48 // T2: the episodic memory recorded the shared photo, coherent with the look 49 tot=tot+1 50 var t2: i64 = 0 51 if mem_get_pfx(MPX, "aria" as *u8, 0, p, l) == 1 { 52 let f: *i64 = sys_mmap(16) as *i64 53 if tr_field(p[0] as *u8, 0, l[0], MF_TEXT, f) == 1 { 54 let tp: *u8 = (p[0] + f[0]) as *u8 55 if gfind(tp, f[1], "sent you a photo of me" as *u8)==1 { t2=1 } 56 } 57 } 58 if t2==1 { pass=pass+1; gw("PASS T2 memory: 'I sent you a photo of me <look, scene>' recorded (share == recall)\n" as *u8) } else { gw("FAIL T2\n" as *u8) } 59 60 // T3: two shares -> two distinct memories with different looks (variety in what she remembers) 61 tot=tot+1 62 companion_share_photo_pfx(VPX, MPX, "aria" as *u8, "s1" as *u8, "1001" as *u8, req, 32768, sp) 63 var t3: i64 = 0 64 let a: *u8 = sys_mmap(4096); let b: *u8 = sys_mmap(4096) 65 if mem_count_pfx(MPX, "aria" as *u8) == 2 { 66 let f: *i64 = sys_mmap(16) as *i64 67 // ⚠HOISTED: `((p[0]+f[0]+i) as *u8)[0]` is an INLINE CAST-INDEX, which nx_cc miscompiles SILENTLY 68 // -- it does not crash, so a bad read here would quietly corrupt the copied bytes and T3 would be 69 // comparing garbage while looking healthy. nx_pagerank_build_gate.nx:38 documents the same shape 70 // ('temp, NOT inline (pp[0] as *i64)[0] -- inline cast-index miscompiles'); debt 1785532031, gotcha 71 // banked 2026-07-31. Bind the base pointer ONCE outside the loop, then index it. 72 mem_get_pfx(MPX, "aria" as *u8, 0, p, l); tr_field(p[0] as *u8, 0, l[0], MF_TEXT, f) 73 let ab: *u8 = (p[0]+f[0]) as *u8 74 var la: i64=0; var i: i64=0; while i<f[1] { a[la]=ab[i]; la=la+1; i=i+1 } a[la]=0 as u8 75 mem_get_pfx(MPX, "aria" as *u8, 1, p, l); tr_field(p[0] as *u8, 0, l[0], MF_TEXT, f) 76 let bb: *u8 = (p[0]+f[0]) as *u8 77 var lb: i64=0; i=0; while i<f[1] { b[lb]=bb[i]; lb=lb+1; i=i+1 } b[lb]=0 as u8 78 if gpeq(a, la, b, lb)==0 { t3=1 } 79 } 80 if t3==1 { pass=pass+1; gw("PASS T3 variety in memory: two shares -> two DIFFERENT remembered looks\n" as *u8) } else { gw("FAIL T3\n" as *u8) } 81 82 gw("nx_companion_photo_gate pass=" as *u8); gn(pass); gw("/" as *u8); gn(tot) 83 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 84 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 85 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 86 let ctr__dry: *i64 = gv_ctr() 87 ctr__dry[0] = pass 88 ctr__dry[1] = tot 89 let rc__dry: i64 = gv_verdict("COMPANION-PHOTO-GATE" as *u8, ctr__dry, "she talks, remembers, AND shares grounded self-images that vary -- one coherent being)" as *u8) 90 sys_exit(rc__dry) 91 return rc__dry 92}