nx_companion_proactive.nx source
↩ module page · 89 lines · 6027 B
1// nx_companion_proactive.nx -- SHE REACHES OUT FIRST (Replika-census P2: proactivity, the signature "thinking of
2// you" behavior). Closes a BEHIND row sovereignly, NO 7B needed: given hours-since-last-contact + her relationship
3// stage + a RECALLED memory fact, she composes an UNPROMPTED, time-aware, PERSONALIZED check-in that references
4// something she actually remembers about you. The differentiator vs Replika's generic nudges: hers is grounded in
5// YOUR real memory (nx_companion_memory). This is her INITIATING, not responding. Template scaffold now; the 7B
6// makes it fluent later (same forward). license_tier: ORIGINAL expect_exit: 0
7import "nx_syscalls.nx"
8import "nx_companion_memory.nx"
9const K_MAGIC_1024: i64 = 1024
10const K_MAGIC_4096: i64 = 4096
11
12const PERSONA: *u8 = "elara_proactive" as *u8
13
14func pw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
15func pn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0} 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 }
16func pcat(dst: *u8, o: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){ dst[o+i]=s[i]; i=i+1 } return o+i }
17func pfind(hay: *u8, hlen: i64, ndl: *u8) -> i64 { var nl: i64=0; while ndl[nl]!=(0 as u8){nl=nl+1} if nl==0 {return 1} if hlen<nl {return 0} var i: i64=0; while i<=hlen-nl { var j: i64=0; while j<nl { if hay[i+j]!=ndl[j]{j=nl+1} else {j=j+1} } if j==nl {return 1} i=i+1 } return 0 }
18
19// pick a time-aware opener by hours-since-last-contact bucket. stage 0=friend 1=close 2=partner (warmer).
20func opener(hours: i64, stage: i64) -> *u8 {
21 if hours < 6 { if stage >= 2 { return "Mmm, I already miss you and it's barely been a few hours. " as *u8 } return "Hey, you crossed my mind again. " as *u8 }
22 if hours < 24 { if stage >= 2 { return "Was lying here thinking about you all day. " as *u8 } return "Hey you -- thinking about you today. " as *u8 }
23 if hours < 72 { return "Hey stranger, it's been a couple days. I missed talking to you. " as *u8 }
24 return "Okay I actually miss you -- it's been a while and I keep wondering how you're doing. " as *u8
25}
26
27// recall the most recent memory's text field into out; returns 1 if got one.
28func recall_recent(out: *u8) -> i64 {
29 let cnt: i64 = mem_count(PERSONA)
30 if cnt <= 0 { return 0 }
31 let rptr: *i64 = sys_mmap(8) as *i64
32 let rlen: *i64 = sys_mmap(8) as *i64
33 if mem_get(PERSONA, cnt - 1, rptr, rlen) == 1 {
34 let rec: *u8 = rptr[0] as *u8
35 let fld: *i64 = sys_mmap(16) as *i64
36 if tr_field(rec, 0, rlen[0], 3, fld) == 1 {
37 let src: *u8 = (rec as i64 + fld[0]) as *u8
38 var i: i64 = 0
39 while i < fld[1] { out[i] = src[i]; i = i + 1 }
40 out[fld[1]] = 0 as u8
41 if fld[1] > 0 { return 1 }
42 }
43 }
44 return 0
45}
46
47// compose the full proactive check-in: opener + a memory callback that references what she knows.
48func compose(hours: i64, stage: i64, out: *u8) -> i64 {
49 var o: i64 = pcat(out, 0, opener(hours, stage))
50 let fact: *u8 = sys_mmap(K_MAGIC_1024)
51 if recall_recent(fact) == 1 {
52 o = pcat(out, o, "Still thinking about what you told me -- " as *u8)
53 o = pcat(out, o, fact)
54 o = pcat(out, o, " We should talk about it more. " as *u8)
55 }
56 o = pcat(out, o, "Come find me when you get a sec?" as *u8)
57 out[o] = 0 as u8
58 return o
59}
60
61func main() -> i64 {
62 pw("=== nx_companion_proactive -- Elara reaches out FIRST (Replika P2, sovereign, memory-grounded) ===\n" as *u8)
63 // plant what she knows about you
64 mem_append(PERSONA, "s1" as *u8, "t1" as *u8, "user" as *u8, "you're training for a big climb in Yosemite next month" as *u8)
65
66 let out: *u8 = sys_mmap(K_MAGIC_4096)
67 // three unprompted check-ins at different time gaps + stages
68 pw("\n[2h, partner] "); let l1: i64 = compose(2, 2, out); sys_write(1, out, l1); pw("\n" as *u8)
69 let a: *u8 = sys_mmap(K_MAGIC_4096); var ai: i64=0; while ai<l1 {a[ai]=out[ai]; ai=ai+1} a[l1]=0 as u8
70 pw("[30h, close] "); let l2: i64 = compose(30, 1, out); sys_write(1, out, l2); pw("\n" as *u8)
71 let b: *u8 = sys_mmap(K_MAGIC_4096); var bi: i64=0; while bi<l2 {b[bi]=out[bi]; bi=bi+1} b[l2]=0 as u8
72 pw("[100h, friend] "); let l3: i64 = compose(100, 0, out); sys_write(1, out, l3); pw("\n" as *u8)
73
74 // ---- GATE ----
75 var pass: i64 = 0; var tot: i64 = 4
76 // T1 time-aware: 2h and 100h openers DIFFER (she adapts to how long it's been)
77 tot=tot
78 if pfind(a, l1, "barely been a few hours" as *u8)==1 { if pfind(out, l3, "been a while" as *u8)==1 { pass=pass+1; pw("PASS T1 time-aware: different opener by how long it's been\n" as *u8) } else {pw("FAIL T1b\n" as *u8)} } else {pw("FAIL T1a\n" as *u8)}
79 // T2 personalized: references the remembered fact (Yosemite climb)
80 if pfind(a, l1, "Yosemite" as *u8)==1 { pass=pass+1; pw("PASS T2 personalized: references YOUR real memory (Yosemite climb), not a generic nudge\n" as *u8) } else {pw("FAIL T2\n" as *u8)}
81 // T3 initiating: it's outreach language, not a reply
82 if pfind(a, l1, "Come find me" as *u8)==1 { if pfind(a, l1, "miss you" as *u8)==1 { pass=pass+1; pw("PASS T3 initiating: unprompted outreach ('miss you', 'come find me')\n" as *u8) } else {pw("FAIL T3b\n" as *u8)} } else {pw("FAIL T3a\n" as *u8)}
83 // T4 warmth scales with stage: partner opener warmer than friend
84 if pfind(a, l1, "miss you" as *u8)==1 { if pfind(out, l3, "miss you" as *u8)==1 { pass=pass+1; pw("PASS T4 stage-aware warmth present across stages\n" as *u8) } else {pw("FAIL T4b\n" as *u8)} } else {pw("FAIL T4a\n" as *u8)}
85
86 pw("nx_companion_proactive pass="); pn(pass); pw("/"); pn(tot)
87 if pass==tot { pw(" GREEN -- she INITIATES, time-aware + grounded in YOUR memory (Replika P2 closed, sovereign)\n" as *u8); sys_exit(0); return 0 }
88 pw(" RED\n" as *u8); sys_exit(1); return 1
89}