nx_emit_gate.nx source
↩ module page · 128 lines · 6076 B
1// nx_emit_gate.nx -- REFEREE for WRITING rung W-ING-4 (nx_emit): the END-TO-END
2// demonstration the operator asked for -- a multi-scene STORY run through the whole
3// pipeline -> register route + per-scene IMAGE PROMPTS + COMPANION CONTEXT.
4//
5// The story here is a tasteful (SFW) romance: the engine is register-blind, so this
6// proves the exact machinery the operator points at an explicit Literotica-class
7// story on the local-LLM lane (with their own roster + lexicon + register terms).
8//
9// [T1..T4] per-scene image prompt + companion context = exact expected strings.
10// [T5] register route on the whole story -> SFW lane (mild romance below threshold).
11// [T6] NEG-CONTROL: an entity-free scene -> EMPTY prompt (never fabricates a tag).
12//
13// Evidence -> stdout + knowledge/status/emit_gate.log. Exit 0/1. Sovereign.
14import "nx_syscalls_x86_64.nx"
15import "nx_emit.nx"
16import "nx_register.nx"
17
18func gp(logfd: i64, s: *u8) -> i64 {
19 var n: i64 = 0
20 while s[n] != (0 as u8) { n = n + 1 }
21 sys_write(1, s, n)
22 if logfd > 0 { sys_write(logfd, s, n) }
23 return 0
24}
25func gn(logfd: i64, v: i64) -> i64 {
26 var m: i64 = v
27 if m < 0 { sys_write(1, "-\x00" as *u8, 1); if logfd > 0 { sys_write(logfd, "-\x00" as *u8, 1) } m = 0 - m }
28 let bb: *u8 = sys_mmap(32)
29 let t: *u8 = sys_mmap(32)
30 var k: i64 = 0
31 if m == 0 { t[0] = 48 as u8; k = 1 }
32 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
33 var i: i64 = 0
34 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
35 sys_write(1, bb, k)
36 if logfd > 0 { sys_write(logfd, bb, k) }
37 return 0
38}
39func slen(s: *u8) -> i64 {
40 var n: i64 = 0
41 while s[n] != (0 as u8) { n = n + 1 }
42 return n
43}
44func streq(a: *u8, b: *u8) -> i64 {
45 var i: i64 = 0
46 while a[i] != (0 as u8) {
47 if a[i] != b[i] { return 0 }
48 i = i + 1
49 }
50 if b[i] != (0 as u8) { return 0 }
51 return 1
52}
53func pr_str(logfd: i64, label: *u8, got: *u8, exp: *u8) -> i64 {
54 gp(logfd, label); gp(logfd, " [\x00" as *u8); gp(logfd, got); gp(logfd, "]\x00" as *u8)
55 if streq(got, exp) == 1 { gp(logfd, " OK\n\x00" as *u8); return 1 }
56 gp(logfd, " FAIL exp[\x00" as *u8); gp(logfd, exp); gp(logfd, "]\n\x00" as *u8)
57 return 0
58}
59func pr_kv(logfd: i64, label: *u8, got: i64, exp: i64) -> i64 {
60 gp(logfd, label); gp(logfd, " got=\x00" as *u8); gn(logfd, got); gp(logfd, " exp=\x00" as *u8); gn(logfd, exp)
61 if got == exp { gp(logfd, " OK\n\x00" as *u8); return 1 }
62 gp(logfd, " FAIL\n\x00" as *u8); return 0
63}
64
65func main() -> i64 {
66 let logfd: i64 = sys_openat_append("knowledge/status/emit_gate.log\x00" as *u8, 0x1a4)
67 gp(logfd, "EMIT-GATE W-ING-4 (story -> image prompts + companion context)\n\x00" as *u8)
68
69 // --- the work + the operator-supplied DATA (here: benign SFW) ---
70 let story: *u8 = "Mira stepped into the garden at dusk. The roses glowed in the fading light. \"You came,\" Mira whispered.\n\nDev took her hand. The night was warm and tender. They danced beneath the stars.\x00" as *u8
71 let roster: *u8 = "mira\x00dev\x00" as *u8
72 let dterms: *u8 = "garden\x00dusk\x00night\x00tender\x00warm\x00" as *u8
73
74 var ok: i64 = 1
75 let scenes: *i64 = sys_mmap(256) as *i64
76 let nsc: i64 = ig_extract(story, slen(story), roster, 2, scenes, 8) // stride 7 (5+2)
77 if pr_kv(logfd, " nscenes\x00" as *u8, nsc, 2) == 0 { ok = 0 }
78
79 let dst: *u8 = sys_mmap(512)
80
81 // ---- scene 0 ----
82 gp(logfd, " [scene0] image prompt:\x00" as *u8)
83 em_image_prompt(story, scenes[0], scenes[1], roster, 2, dterms, 5, dst)
84 if pr_str(logfd, "\x00" as *u8, dst, "mira, garden, dusk\x00" as *u8) == 0 { ok = 0 }
85 gp(logfd, " [scene0] companion ctx:\x00" as *u8)
86 em_companion_ctx(story, scenes[0], scenes[1], roster, 2, dterms, 5, dst)
87 if pr_str(logfd, "\x00" as *u8, dst, "present: mira | desc: garden, dusk | dialogue: 1\x00" as *u8) == 0 { ok = 0 }
88
89 // ---- scene 1 (base 7) ----
90 gp(logfd, " [scene1] image prompt:\x00" as *u8)
91 em_image_prompt(story, scenes[7], scenes[8], roster, 2, dterms, 5, dst)
92 if pr_str(logfd, "\x00" as *u8, dst, "dev, night, tender, warm\x00" as *u8) == 0 { ok = 0 }
93 gp(logfd, " [scene1] companion ctx:\x00" as *u8)
94 em_companion_ctx(story, scenes[7], scenes[8], roster, 2, dterms, 5, dst)
95 if pr_str(logfd, "\x00" as *u8, dst, "present: dev | desc: night, tender, warm | dialogue: 0\x00" as *u8) == 0 { ok = 0 }
96
97 // ---- focus-first ordering: subject character leads the prompt ----
98 gp(logfd, " [focus] subject leads:\x00" as *u8)
99 let fr: *u8 = "alice\x00bob\x00" as *u8
100 let fs: *u8 = "Bob ran. Bob shouted. Alice watched.\x00" as *u8 // bob has more mentions => focus
101 em_image_prompt_focus(fs, 0, slen(fs), fr, 2, 1, dterms, 0, dst) // focus = bob (index 1)
102 if pr_str(logfd, "\x00" as *u8, dst, "bob, alice\x00" as *u8) == 0 { ok = 0 }
103
104 // ---- T5: register route for the whole story (mild romance -> SFW) ----
105 let rterms: *u8 = "whispered\x00tender\x00warm\x00" as *u8
106 let rw: *i64 = sys_mmap(64) as *i64
107 rw[0] = 1; rw[1] = 1; rw[2] = 1
108 let rscore: i64 = rg_score(story, 0, slen(story), rterms, rw, 3)
109 gp(logfd, " [route] story intensity score=\x00" as *u8); gn(logfd, rscore); gp(logfd, " (threshold 5)\n\x00" as *u8)
110 if pr_kv(logfd, " route(0=SFW)\x00" as *u8, rg_decision(rscore, 5, 1, 1, 1), 0) == 0 { ok = 0 }
111
112 // ---- T6: NEG-CONTROL entity-free scene -> empty prompt ----
113 let blank: *u8 = "The wind blew softly.\x00" as *u8
114 em_image_prompt(blank, 0, slen(blank), roster, 2, dterms, 5, dst)
115 gp(logfd, " [neg] entity-free prompt len=\x00" as *u8); gn(logfd, slen(dst)); gp(logfd, "\n\x00" as *u8)
116 if pr_kv(logfd, " empty prompt\x00" as *u8, slen(dst), 0) == 0 { ok = 0 }
117
118 if ok == 1 {
119 gp(logfd, "EMIT-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8)
120 if logfd > 0 { sys_close(logfd) }
121 sys_exit(0)
122 return 0
123 }
124 gp(logfd, "EMIT-GATE result=FAIL verdict=RED\n\x00" as *u8)
125 if logfd > 0 { sys_close(logfd) }
126 sys_exit(1)
127 return 1
128}