code wiki / (root) / nx_ingest_gate.nx

nx_ingest_gate.nx source

↩ module page · 129 lines · 6506 B

1// nx_ingest_gate.nx -- REFEREE for WRITING rung W-ING-1 (nx_ingest). 2// 3// [T1] BATCH: 3-scene text + 2-char roster -> exact per-scene dialogue / focus / 4// total / per-name mention counts. 5// [T2] STREAMING == BATCH: extract each scene independently (as if the LLM 6// streamed it scene-by-scene) and assert IDENTICAL records to the batch 7// pass -- the proof of "real-time == prior". 8// [T3] NEG-CONTROL whole-word: "Yukiko" must NOT count as "Yuki" (substring is 9// not a mention); a standalone "Yuki" does. 10// [T4] NEG-CONTROL empty scene: a scene with no roster characters -> focus = -1, 11// total = 0 (it does not fabricate a present character). 12// 13// Evidence -> stdout + knowledge/status/ingest_gate.log. Exit 0 GREEN / 1 RED. 14// Sovereign x86_64. license_tier: ORIGINAL 15import "nx_syscalls_x86_64.nx" 16import "nx_ingest.nx" 17import "nx_ingest_scene.nx" // ig_* scene/entity extractor -- deleted by the 07-21 dedupe 18 19func gp(logfd: i64, s: *u8) -> i64 { 20 var n: i64 = 0 21 while s[n] != (0 as u8) { n = n + 1 } 22 sys_write(1, s, n) 23 if logfd > 0 { sys_write(logfd, s, n) } 24 return 0 25} 26func gn(logfd: i64, v: i64) -> i64 { 27 var m: i64 = v 28 if m < 0 { 29 sys_write(1, "-\x00" as *u8, 1) 30 if logfd > 0 { sys_write(logfd, "-\x00" as *u8, 1) } 31 m = 0 - m 32 } 33 let bb: *u8 = sys_mmap(32) 34 let t: *u8 = sys_mmap(32) 35 var k: i64 = 0 36 if m == 0 { t[0] = 48 as u8; k = 1 } 37 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 38 var i: i64 = 0 39 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 40 sys_write(1, bb, k) 41 if logfd > 0 { sys_write(logfd, bb, k) } 42 return 0 43} 44func slen(s: *u8) -> i64 { 45 var n: i64 = 0 46 while s[n] != (0 as u8) { n = n + 1 } 47 return n 48} 49func pr_kv(logfd: i64, label: *u8, got: i64, exp: i64) -> i64 { 50 gp(logfd, label) 51 gp(logfd, " got=\x00" as *u8); gn(logfd, got) 52 gp(logfd, " exp=\x00" as *u8); gn(logfd, exp) 53 if got == exp { gp(logfd, " OK\n\x00" as *u8); return 1 } 54 gp(logfd, " FAIL\n\x00" as *u8) 55 return 0 56} 57 58func main() -> i64 { 59 let logfd: i64 = sys_openat_append("knowledge/status/ingest_gate.log\x00" as *u8, 0x1a4) 60 gp(logfd, "INGEST-GATE W-ING-1 (scene/entity extractor -> companion+image-gen DATA)\n\x00" as *u8) 61 62 let roster: *u8 = "yuki\x00kenji\x00" as *u8 // 2 names: 0=yuki 1=kenji 63 var ok: i64 = 1 64 65 // ---- T1: BATCH extraction of a 3-scene work ---- 66 gp(logfd, " [T1] batch extract (3 scenes, roster yuki/kenji)\n\x00" as *u8) 67 let txt: *u8 = "Yuki opened the door. \"Hello,\" she said. Kenji was gone.\n\nKenji ran. Kenji shouted at Kenji's reflection.\n\nThe room was empty. Nobody spoke.\x00" as *u8 68 let out: *i64 = sys_mmap(512) as *i64 // stride 7, plenty 69 let nsc: i64 = ig_extract(txt, slen(txt), roster, 2, out, 8) 70 if pr_kv(logfd, " nscenes\x00" as *u8, nsc, 3) == 0 { ok = 0 } 71 // scene 0 (base 0): "Yuki ... \"Hello,\" ... Kenji ..." 72 gp(logfd, " scene0:\n\x00" as *u8) 73 if pr_kv(logfd, " dialogue\x00" as *u8, out[2], 1) == 0 { ok = 0 } 74 if pr_kv(logfd, " focus\x00" as *u8, out[3], 0) == 0 { ok = 0 } 75 if pr_kv(logfd, " total\x00" as *u8, out[4], 2) == 0 { ok = 0 } 76 if pr_kv(logfd, " yuki\x00" as *u8, out[5], 1) == 0 { ok = 0 } 77 if pr_kv(logfd, " kenji\x00" as *u8, out[6], 1) == 0 { ok = 0 } 78 // scene 1 (base 7): "Kenji ... Kenji ... Kenji's ..." 79 gp(logfd, " scene1:\n\x00" as *u8) 80 if pr_kv(logfd, " dialogue\x00" as *u8, out[9], 0) == 0 { ok = 0 } 81 if pr_kv(logfd, " focus\x00" as *u8, out[10], 1) == 0 { ok = 0 } 82 if pr_kv(logfd, " total\x00" as *u8, out[11], 3) == 0 { ok = 0 } 83 if pr_kv(logfd, " yuki\x00" as *u8, out[12], 0) == 0 { ok = 0 } 84 if pr_kv(logfd, " kenji\x00" as *u8, out[13], 3) == 0 { ok = 0 } 85 // scene 2 (base 14): no characters present 86 gp(logfd, " scene2:\n\x00" as *u8) 87 if pr_kv(logfd, " dialogue\x00" as *u8, out[16], 0) == 0 { ok = 0 } 88 if pr_kv(logfd, " focus\x00" as *u8, out[17], 0 - 1) == 0 { ok = 0 } // T4 empty-scene neg-control 89 if pr_kv(logfd, " total\x00" as *u8, out[18], 0) == 0 { ok = 0 } 90 91 // ---- T2: STREAMING == BATCH (extract each scene alone, same records) ---- 92 gp(logfd, " [T2] streaming==batch (per-scene extraction matches batch)\n\x00" as *u8) 93 let outs: *i64 = sys_mmap(128) as *i64 94 let s0: *u8 = "Yuki opened the door. \"Hello,\" she said. Kenji was gone.\x00" as *u8 95 ig_extract(s0, slen(s0), roster, 2, outs, 1) 96 if pr_kv(logfd, " s0 dialogue\x00" as *u8, outs[2], out[2]) == 0 { ok = 0 } 97 if pr_kv(logfd, " s0 focus\x00" as *u8, outs[3], out[3]) == 0 { ok = 0 } 98 if pr_kv(logfd, " s0 total\x00" as *u8, outs[4], out[4]) == 0 { ok = 0 } 99 if pr_kv(logfd, " s0 yuki\x00" as *u8, outs[5], out[5]) == 0 { ok = 0 } 100 if pr_kv(logfd, " s0 kenji\x00" as *u8, outs[6], out[6]) == 0 { ok = 0 } 101 let s1: *u8 = "Kenji ran. Kenji shouted at Kenji's reflection.\x00" as *u8 102 ig_extract(s1, slen(s1), roster, 2, outs, 1) 103 if pr_kv(logfd, " s1 focus\x00" as *u8, outs[3], out[10]) == 0 { ok = 0 } 104 if pr_kv(logfd, " s1 total\x00" as *u8, outs[4], out[11]) == 0 { ok = 0 } 105 if pr_kv(logfd, " s1 kenji\x00" as *u8, outs[6], out[13]) == 0 { ok = 0 } 106 let s2: *u8 = "The room was empty. Nobody spoke.\x00" as *u8 107 ig_extract(s2, slen(s2), roster, 2, outs, 1) 108 if pr_kv(logfd, " s2 focus\x00" as *u8, outs[3], out[17]) == 0 { ok = 0 } 109 if pr_kv(logfd, " s2 total\x00" as *u8, outs[4], out[18]) == 0 { ok = 0 } 110 111 // ---- T3: NEG-CONTROL whole-word ("Yukiko" != "Yuki") ---- 112 gp(logfd, " [T3] NEG-CONTROL whole-word (Yukiko must not count as Yuki)\n\x00" as *u8) 113 let ry: *u8 = "yuki\x00" as *u8 // 1 name, stride 6 114 let nct: *u8 = "Yukiko announced. Yuki smiled.\x00" as *u8 115 ig_extract(nct, slen(nct), ry, 1, outs, 1) 116 if pr_kv(logfd, " yuki mentions\x00" as *u8, outs[5], 1) == 0 { ok = 0 } // 1, not 2 117 if pr_kv(logfd, " total\x00" as *u8, outs[4], 1) == 0 { ok = 0 } 118 119 if ok == 1 { 120 gp(logfd, "INGEST-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8) 121 if logfd > 0 { sys_close(logfd) } 122 sys_exit(0) 123 return 0 124 } 125 gp(logfd, "INGEST-GATE result=FAIL verdict=RED\n\x00" as *u8) 126 if logfd > 0 { sys_close(logfd) } 127 sys_exit(1) 128 return 1 129}