code wiki / (root) / nx_descriptor_gate.nx

nx_descriptor_gate.nx source

↩ module page · 122 lines · 5609 B

1// nx_descriptor_gate.nx -- REFEREE for WRITING rung W-ING-2 (nx_descriptor). 2// 3// [T1] exact per-category descriptor counts on a single scene. 4// [T2] NEG-CONTROL whole-word: "forestry" != "forest", "midnight" != "night" 5// -> a descriptor-free profile (no fabricated tags). 6// [T3] E2E PIPELINE: ig_extract (segment) -> dx_profile per scene range yields 7// the correct per-scene image-gen profile (the real companion/image-gen 8// path), proving the two organs compose. 9// 10// Lexicon (DATA): forest/castle=SETTING(0) night/dawn=TIME(1) tense/calm=MOOD(2) 11// rain=WEATHER(3). Benign by design -- the operator/lane extend the lexicon. 12// 13// Evidence -> stdout + knowledge/status/descriptor_gate.log. Exit 0/1. 14// Sovereign x86_64. license_tier: ORIGINAL 15import "nx_syscalls_x86_64.nx" 16import "nx_descriptor.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 { 28 sys_write(1, "-\x00" as *u8, 1) 29 if logfd > 0 { sys_write(logfd, "-\x00" as *u8, 1) } 30 m = 0 - m 31 } 32 let bb: *u8 = sys_mmap(32) 33 let t: *u8 = sys_mmap(32) 34 var k: i64 = 0 35 if m == 0 { t[0] = 48 as u8; k = 1 } 36 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 37 var i: i64 = 0 38 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 39 sys_write(1, bb, k) 40 if logfd > 0 { sys_write(logfd, bb, k) } 41 return 0 42} 43func slen(s: *u8) -> i64 { 44 var n: i64 = 0 45 while s[n] != (0 as u8) { n = n + 1 } 46 return n 47} 48func pr_kv(logfd: i64, label: *u8, got: i64, exp: i64) -> i64 { 49 gp(logfd, label) 50 gp(logfd, " got=\x00" as *u8); gn(logfd, got) 51 gp(logfd, " exp=\x00" as *u8); gn(logfd, exp) 52 if got == exp { gp(logfd, " OK\n\x00" as *u8); return 1 } 53 gp(logfd, " FAIL\n\x00" as *u8) 54 return 0 55} 56 57func main() -> i64 { 58 let logfd: i64 = sys_openat_append("knowledge/status/descriptor_gate.log\x00" as *u8, 0x1a4) 59 gp(logfd, "DESCRIPTOR-GATE W-ING-2 (scene -> image-gen descriptor profile)\n\x00" as *u8) 60 61 // lexicon: 7 terms + parallel category ids 62 let terms: *u8 = "forest\x00castle\x00night\x00dawn\x00tense\x00calm\x00rain\x00" as *u8 63 let cats: *i64 = sys_mmap(64) as *i64 64 cats[0] = 0 // forest SETTING 65 cats[1] = 0 // castle SETTING 66 cats[2] = 1 // night TIME 67 cats[3] = 1 // dawn TIME 68 cats[4] = 2 // tense MOOD 69 cats[5] = 2 // calm MOOD 70 cats[6] = 3 // rain WEATHER 71 let prof: *i64 = sys_mmap(64) as *i64 72 var ok: i64 = 1 73 74 // ---- T1: direct profile of one scene ---- 75 gp(logfd, " [T1] profile of \"...dark forest. The night was tense... Rain fell.\"\n\x00" as *u8) 76 let sc: *u8 = "They camped in the dark forest. The night was tense and cold. Rain fell.\x00" as *u8 77 let tot: i64 = dx_profile(sc, 0, slen(sc), terms, cats, 7, 4, prof) 78 if pr_kv(logfd, " SETTING\x00" as *u8, prof[0], 1) == 0 { ok = 0 } 79 if pr_kv(logfd, " TIME\x00" as *u8, prof[1], 1) == 0 { ok = 0 } 80 if pr_kv(logfd, " MOOD\x00" as *u8, prof[2], 1) == 0 { ok = 0 } 81 if pr_kv(logfd, " WEATHER\x00" as *u8, prof[3], 1) == 0 { ok = 0 } 82 if pr_kv(logfd, " total\x00" as *u8, tot, 4) == 0 { ok = 0 } 83 84 // ---- T2: NEG-CONTROL whole-word ---- 85 gp(logfd, " [T2] NEG-CONTROL (forestry!=forest, midnight!=night)\n\x00" as *u8) 86 let nc: *u8 = "The forestry office at midnight.\x00" as *u8 87 let tot2: i64 = dx_profile(nc, 0, slen(nc), terms, cats, 7, 4, prof) 88 if pr_kv(logfd, " SETTING\x00" as *u8, prof[0], 0) == 0 { ok = 0 } 89 if pr_kv(logfd, " TIME\x00" as *u8, prof[1], 0) == 0 { ok = 0 } 90 if pr_kv(logfd, " total\x00" as *u8, tot2, 0) == 0 { ok = 0 } 91 92 // ---- T3: E2E pipeline segment -> profile per scene ---- 93 gp(logfd, " [T3] E2E: ig_extract (segment) -> dx_profile per scene\n\x00" as *u8) 94 let work: *u8 = "The forest grew dark as night fell.\n\nInside the castle at dawn, all was calm.\x00" as *u8 95 let scenes: *i64 = sys_mmap(256) as *i64 96 let nsc: i64 = ig_extract(work, slen(work), "\x00" as *u8, 0, scenes, 8) // no roster: just segment 97 if pr_kv(logfd, " nscenes\x00" as *u8, nsc, 2) == 0 { ok = 0 } 98 // scene 0 range = scenes[0..1]; profile it 99 let p0: i64 = dx_profile(work, scenes[0], scenes[1], terms, cats, 7, 4, prof) 100 gp(logfd, " scene0 profile:\n\x00" as *u8) 101 if pr_kv(logfd, " SETTING(forest)\x00" as *u8, prof[0], 1) == 0 { ok = 0 } 102 if pr_kv(logfd, " TIME(night)\x00" as *u8, prof[1], 1) == 0 { ok = 0 } 103 if pr_kv(logfd, " MOOD\x00" as *u8, prof[2], 0) == 0 { ok = 0 } 104 // scene 1 range = scenes[5..6] (stride 5 when nnames=0) 105 let p1: i64 = dx_profile(work, scenes[5], scenes[6], terms, cats, 7, 4, prof) 106 gp(logfd, " scene1 profile:\n\x00" as *u8) 107 if pr_kv(logfd, " SETTING(castle)\x00" as *u8, prof[0], 1) == 0 { ok = 0 } 108 if pr_kv(logfd, " TIME(dawn)\x00" as *u8, prof[1], 1) == 0 { ok = 0 } 109 if pr_kv(logfd, " MOOD(calm)\x00" as *u8, prof[2], 1) == 0 { ok = 0 } 110 if pr_kv(logfd, " WEATHER\x00" as *u8, prof[3], 0) == 0 { ok = 0 } 111 112 if ok == 1 { 113 gp(logfd, "DESCRIPTOR-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8) 114 if logfd > 0 { sys_close(logfd) } 115 sys_exit(0) 116 return 0 117 } 118 gp(logfd, "DESCRIPTOR-GATE result=FAIL verdict=RED\n\x00" as *u8) 119 if logfd > 0 { sys_close(logfd) } 120 sys_exit(1) 121 return 1 122}