code wiki / _hdl_build / nx_companion_identity.nx
nx_companion_identity.nx source
↩ module page · 111 lines · 8099 B
1// nx_companion_identity.nx -- the COMPANION IDENTITY / PHENOTYPE-GENOME object: turns "who a companion is"
2// (data-driven per-character files: elara_appearance/loras/shots.txt) + presentation into the identity portion of
3// a gen prompt. First-class + reusable = the seat for many companions (customize + proc-gen) and the digital-twin /
4// genome direction. Extracted from nx_gen_orchestrator (monolith -> objects); behaviour-preserving. Object model:
5// companion_arch.md. ⚠identity terms are Z-IMAGE COUNTERBALANCED (see the counterbalance registry) -- do not naive-edit.
6// Self-contained (private ci_* helpers) so there is zero symbol collision with the orchestrator. license_tier: ORIGINAL
7import "nx_syscalls.nx"
8
9func ci_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
10func ci_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var i: i64=0; while s[i]!=(0 as u8){dst[o]=s[i]; o=o+1; i=i+1} return o }
11
12// a companion's visual identity (data-driven elara_appearance.txt; baked default = a CLEARLY-ADULT early-20s anchor,
13// counterweighted vs Z-Image's 40s age-up drift). Identity carries FIGURE not exposed anatomy (wardrobe resolves that).
14func go_load_appearance(out: *u8, cap: i64) -> i64 {
15 let lp: *i64 = sys_mmap(16) as *i64
16 let b: *u8 = sys_read_file("elara_appearance.txt" as *u8, lp)
17 if (b as i64) != 0 { if lp[0] > 0 {
18 var n: i64 = lp[0]; if n > cap-1 { n = cap-1 }
19 var i: i64 = 0; while i < n { out[i]=b[i]; i=i+1 } out[n]=0 as u8; return n
20 } }
21 let d: *u8 = "photograph of Elara, a recognizable young woman in her early twenties, a sexually mature adult woman (clearly grown and adult, NOT middle-aged, NOT a teenager), platinum blonde hair, light blue eyes, an attractive feminine face, golden sun-kissed tanned skin with real natural skin texture, a curvy voluptuous top-heavy hourglass figure with a large full bust, narrow waist, delicate silver cross necklace" as *u8
22 let n2: i64 = ci_cat(out, 0, d); out[n2]=0 as u8; return n2
23}
24// realism loras (data-driven elara_loras.txt); default = realism stack, NOT nudity-forcing; NSFW loras stay scene-gated.
25func go_load_loras(out: *u8, cap: i64) -> i64 {
26 let lp: *i64 = sys_mmap(16) as *i64
27 let b: *u8 = sys_read_file("elara_loras.txt" as *u8, lp)
28 if (b as i64) != 0 { if lp[0] > 0 {
29 var n: i64 = lp[0]; if n > cap-1 { n = cap-1 }
30 var i: i64 = 0; while i < n { if (b[i]&0xff) >= 32 { out[i]=b[i] } else { out[i]=32 as u8 } i=i+1 } out[n]=0 as u8; return n
31 } }
32 let d: *u8 = "<lora:RealisticSnapshot-Zimage-Turbov5:0.7> <lora:amateur_photography_zimage_v1:0.45>" as *u8
33 let n2: i64 = ci_cat(out, 0, d); out[n2]=0 as u8; return n2
34}
35// the REALISM TRIGGER PREFIX (data-driven elara_trigger.txt): the realism LoRA's own activation vocabulary,
36// placed at the VERY FRONT of the prompt (the early-RoPE position, ahead of the camera line). RESTORED
37// 2026-08-27 from the pre-docker-parking gen-img composition (svc-config gen-img/default_loras, row dated
38// 2026-04-25: `<lora tags><trigger words>, <prompt>`). The 2026-08-19 June-repro A/B measured this
39// request-side injection as the DOMINANT term of the June look (dhash 74 -> 48 against the original, while
40// the engine flags alone moved nothing), and the sovereign path had dropped it when the orchestrator replaced
41// gen-img. Contract: file MISSING -> the baked June prefix; file present but BLANK (only whitespace) -> NO
42// prefix (a blank file is a decision, never a fallback); control bytes become spaces, trailing spaces trimmed.
43func go_load_trigger(out: *u8, cap: i64) -> i64 {
44 let lp: *i64 = sys_mmap(16) as *i64
45 let b: *u8 = sys_read_file("elara_trigger.txt" as *u8, lp)
46 if (b as i64) != 0 { if lp[0] > 0 {
47 var n: i64 = lp[0]; if n > cap-1 { n = cap-1 }
48 var i: i64 = 0; while i < n { if (b[i]&0xff) >= 32 { out[i]=b[i] } else { out[i]=32 as u8 } i=i+1 }
49 var e: i64 = n; while e > 0 { if (out[e-1]&0xff) == 32 { e=e-1 } else { out[e]=0 as u8; return e } }
50 out[0]=0 as u8; return 0
51 } }
52 let d: *u8 = "amateur digital snapshot, candid, smartphone capture, detailed skin texture, visible pores, visible vellus hair, subsurface scattering, wide-angle lens, depth of field" as *u8
53 let n2: i64 = ci_cat(out, 0, d); out[n2]=0 as u8; return n2
54}
55// the QUALITY TAIL (data-driven elara_quality.txt). MEASURED 2026-08-06 against the 568,944-row
56// beauty_evaluations corpus (elder-ai-platform/data-vault/beauty.db, the OLD platform's scorer).
57// !! SCOPE THIS CLAIM CAREFULLY -- I got it wrong once and this is the correction. Pooling ALL months
58// conflates "this vocabulary is bad" with "this feature was still being repaired then". Restricted to
59// the POST-REPAIR window (>=2026-05, n=97,345 face-present rows) the honest findings are:
60// - "photorealistic" / "8k" / "high detail" occur ZERO times in the recent corpus. The mature system
61// had ABANDONED booru-style quality tags. That is evidence of DISUSE, not of measured harm: the
62// pooled sample showed -0.0275 for "photorealistic" but the recent sample cannot test it at all.
63// - "dewy" +0.0243 (n=82,504) is a genuine, well-sampled lift. It carries this default.
64// - "catchlight"/"freckles"/"visible pores" appear in ~98% of recent rows, so they have NO usable
65// present-vs-absent contrast. They are the mature BASELINE vocabulary, kept for that reason -- NOT
66// because they were measured to lift anything.
67// *** LAW: A TERM PRESENT IN ~98% OF A CORPUS CANNOT BE MEASURED BY PRESENCE/ABSENCE -- near-universal
68// coverage destroys the contrast, and reading the tiny residue as a lift is a sampling artifact.
69// *** LAW: A LOW SCORE DURING A PERIOD OF ACTIVE REPAIR IS EVIDENCE ABOUT THE REPAIR, NOT THE SUBJECT.
70func go_load_quality(out: *u8, cap: i64) -> i64 {
71 let lp: *i64 = sys_mmap(16) as *i64
72 let b: *u8 = sys_read_file("elara_quality.txt" as *u8, lp)
73 if (b as i64) != 0 { if lp[0] > 0 {
74 var n: i64 = lp[0]; if n > cap-1 { n = cap-1 }
75 var i: i64 = 0; while i < n { if (b[i]&0xff) >= 32 { out[i]=b[i] } else { out[i]=32 as u8 } i=i+1 } out[n]=0 as u8; return n
76 } }
77 let d: *u8 = "dewy highlight on her cheekbones, bright clear eyes with a defined limbal ring and real catchlight, faint freckles across her nose, fine texture visible on her skin with visible pores" as *u8
78 let n2: i64 = ci_cat(out, 0, d); out[n2]=0 as u8; return n2
79}
80// photographic-STYLE variety (data-driven elara_shots.txt), rotated by seed; STYLE tokens only (never a setting) so
81// they never fight the scene. One descriptor per line; baked default below.
82func go_pick_shot(out: *u8, cap: i64, idx: i64) -> i64 {
83 let lp: *i64 = sys_mmap(16) as *i64
84 var b: *u8 = sys_read_file("elara_shots.txt" as *u8, lp)
85 var n: i64 = 0
86 if (b as i64) != 0 { n = lp[0] }
87 if n <= 0 {
88 b = "candid iphone selfie, natural skin texture, subtle skin pores and freckles\n35mm film photograph, soft natural grain, true-to-life colors\ngolden hour warm sunlight, shallow depth of field, gentle bokeh\nsoft overcast daylight, crisp sharp focus, fine realistic skin detail\ncozy warm indoor lamp light, creamy background bokeh\nbright clean natural daylight, high detail, lifelike complexion\nmoody cinematic low light, soft rim light, filmic tones" as *u8
89 n = ci_slen(b)
90 }
91 var lines: i64 = 1; var i: i64 = 0
92 while i < n { if (b[i]&0xff)==10 { lines=lines+1 } i=i+1 }
93 var target: i64 = idx % lines
94 if target < 0 { target = 0 - target }
95 var cur: i64 = 0; var ls: i64 = 0; i = 0
96 var start: i64 = 0; var end: i64 = 0
97 var got: i64 = 0
98 while i <= n {
99 var atend: i64 = 0
100 if i==n { atend=1 } else { if (b[i]&0xff)==10 { atend=1 } }
101 if atend==1 {
102 if cur==target { start=ls; end=i; got=1; i=n }
103 cur=cur+1; ls=i+1
104 }
105 i=i+1
106 }
107 if got==0 { out[0]=0 as u8; return 0 }
108 var o: i64 = 0; var k: i64 = start
109 while k < end { if o<cap-1 { out[o]=b[k]; o=o+1 } k=k+1 }
110 out[o]=0 as u8; return o
111}