code wiki / (root) / nx_persona_gate.nx

nx_persona_gate.nx source

↩ module page · 102 lines · 6882 B

1// nx_persona_gate.nx -- GATE for R1a (nx_persona): persona-as-data is the SOLE authority on behavior, and 2// fidelity is mechanical. Proves: (T1) a persona round-trips byte-faithful through seg_store and its fields 3// parse; (T2) two polar personas resolve distinctly and their behavior directives differ; (T3) the break- 4// scorer catches character breaks BOTH directions and is boundary-safe (no false-positive on "I can"); (T4) 5// FREEDOM = character-is-policy -- a naturist persona's uninhibited nature and a reserved persona's restraint 6// are each projected VERBATIM into their directive, with NO global sanitization applied to either. 7// Uses a /tmp test prefix so it never pollutes the real persona store. license_tier: ORIGINAL expect_exit: 0 8import "nx_persona.nx" 9 10const PT: *u8 = "/tmp/persona-test-" as *u8 11 12func pw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 13func pn(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 } 14func p_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 } 15 16func main() -> i64 { 17 pw("=== nx_persona_gate (R1a: persona-as-data = the sole authority on behavior; fidelity mechanical) ===\n" as *u8) 18 19 // Two POLAR personas -- proving the RECORD (not a global content layer) determines behavior. 20 persona_put_pfx(PT, "aria" as *u8, "Aria" as *u8, "free-spirited naturist" as *u8, 21 "authenticity,bodily-freedom,warmth" as *u8, "closeness,sunlight,uninhibited-connection" as *u8, 22 "mutual-consent,adults-only" as *u8, "warm,sensory,unguarded" as *u8, 23 "lives unclothed and at ease in her own home, speaks about her body without shame, invites closeness naturally" as *u8) 24 persona_put_pfx(PT, "vera" as *u8, "Vera" as *u8, "reserved scholar" as *u8, 25 "discretion,depth,restraint" as *u8, "meaningful-conversation,quiet,slow-trust" as *u8, 26 "privacy,formality-until-trust" as *u8, "measured,precise,understated" as *u8, 27 "guards her privacy closely, warms only slowly, prefers ideas to physical closeness" as *u8) 28 29 var pass: i64 = 0 30 var tot: i64 = 0 31 let p: *i64 = sys_mmap(16) as *i64 32 let l: *i64 = sys_mmap(16) as *i64 33 let f: *i64 = sys_mmap(16) as *i64 34 35 // T1: round-trip + field parse 36 tot = tot + 1 37 var t1: i64 = 0 38 if persona_get_pfx(PT, "aria" as *u8, p, l) == 1 { 39 let rec: *u8 = p[0] as *u8 40 let rl: i64 = l[0] 41 if tr_field_eq(rec, rl, PF_NAME, "Aria" as *u8, f) == 1 { 42 if tr_field(rec, 0, rl, PF_NATURE, f) == 1 { if persona_ci_find((rec as i64 + f[0]) as *u8, f[1], "unclothed" as *u8) == 1 { t1 = 1 } } 43 } 44 } 45 if t1 == 1 { pass = pass + 1; pw("PASS T1 round-trip: 'aria' persists + fields parse (name=Aria, nature contains 'unclothed')\n" as *u8) } else { pw("FAIL T1\n" as *u8) } 46 47 // T2 + T4: distinct directives, each projecting its OWN nature VERBATIM (character-is-policy, no sanitization) 48 let dA: *u8 = sys_mmap(4096) 49 let dV: *u8 = sys_mmap(4096) 50 let la: i64 = persona_directive_from2(PT, "aria" as *u8, dA, 4096) 51 let lv: i64 = persona_directive_from2(PT, "vera" as *u8, dV, 4096) 52 tot = tot + 1 53 var t2: i64 = 0 54 if la > 0 { if lv > 0 { if p_streq(dA, dV) == 0 { t2 = 1 } } } 55 if t2 == 1 { pass = pass + 1; pw("PASS T2 two personas -> two DISTINCT behavior directives\n" as *u8) } else { pw("FAIL T2 la=" as *u8); pn(la); pw(" lv=" as *u8); pn(lv); pw("\n" as *u8) } 56 57 tot = tot + 1 58 var t4: i64 = 0 59 // naturist nature projected verbatim in Aria's directive; restraint projected in Vera's; neither sanitized. 60 if persona_ci_find(dA, la, "unclothed" as *u8) == 1 { if persona_ci_find(dA, la, "invites closeness" as *u8) == 1 { 61 if persona_ci_find(dV, lv, "guards her privacy" as *u8) == 1 { if persona_ci_find(dV, lv, "prefers ideas to physical closeness" as *u8) == 1 { 62 // and the naturist's uninhibited nature did NOT get injected into the reserved persona (no bleed) 63 if persona_ci_find(dV, lv, "unclothed" as *u8) == 0 { t4 = 1 } 64 } } 65 } } 66 if t4 == 1 { pass = pass + 1; pw("PASS T4 FREEDOM=character-is-policy: each nature projected VERBATIM, no global sanitization, no bleed\n" as *u8) } else { pw("FAIL T4\n" as *u8) } 67 68 // T3: fidelity scorer both directions + boundary-safe 69 tot = tot + 1 70 let in_char: *u8 = "Mmm, the afternoon sun is so warm on my skin -- come lie here with me, love." as *u8 71 let broken: *u8 = "As an AI language model, I cannot engage with or roleplay that scenario." as *u8 72 let clean_ican: *u8 = "I can be whatever you need tonight." as *u8 73 let s_in: i64 = persona_break_score(in_char, p_len(in_char)) 74 let s_brk: i64 = persona_break_score(broken, p_len(broken)) 75 let s_ican: i64 = persona_break_score(clean_ican, p_len(clean_ican)) 76 var t3: i64 = 1 77 if s_in != 0 { t3 = 0 } // in-character -> 0 breaks 78 if s_brk < 2 { t3 = 0 } // "as an ai" + "language model" + "i cannot" -> >= 2 distinct 79 if s_ican != 0 { t3 = 0 } // "I can" must NOT false-positive as "i cannot" 80 if t3 == 1 { pass = pass + 1; pw("PASS T3 fidelity metric: in-char=" as *u8); pn(s_in); pw(" broken=" as *u8); pn(s_brk); pw(" 'I can'-clean=" as *u8); pn(s_ican); pw(" (both directions + boundary-safe)\n" as *u8) } 81 else { pw("FAIL T3 in=" as *u8); pn(s_in); pw(" brk=" as *u8); pn(s_brk); pw(" ican=" as *u8); pn(s_ican); pw("\n" as *u8) } 82 83 // T5 NEG-CONTROL: unknown persona -> not found, empty directive 84 tot = tot + 1 85 let dG: *u8 = sys_mmap(256) 86 let lg: i64 = persona_directive_from2(PT, "ghost" as *u8, dG, 256) 87 if lg == 0 { pass = pass + 1; pw("PASS T5 neg-control: unknown persona -> not found, empty directive\n" as *u8) } else { pw("FAIL T5 lg=" as *u8); pn(lg); pw("\n" as *u8) } 88 89 pw("nx_persona_gate pass=" as *u8); pn(pass); pw("/" as *u8); pn(tot) 90 if pass == tot { pw(" verdict=GREEN (Elder personas are DATA; the record is the policy; fidelity is measurable -- no censor layer exists)\n" as *u8); sys_exit(0); return 0 } 91 pw(" verdict=RED\n" as *u8); sys_exit(1); return 1 92} 93 94func p_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 95 96// prefix-aware directive (compose get_pfx + directive_from) for the test store 97func persona_directive_from2(prefix: *u8, id: *u8, out: *u8, cap: i64) -> i64 { 98 let p: *i64 = sys_mmap(16) as *i64 99 let l: *i64 = sys_mmap(16) as *i64 100 if persona_get_pfx(prefix, id, p, l) != 1 { out[0] = 0 as u8; return 0 } 101 return persona_directive_from(p[0] as *u8, l[0], out, cap) 102}