code wiki / (root) / nx_convo_gate.nx

nx_convo_gate.nx source

↩ module page · 119 lines · 5822 B

1// nx_convo_gate.nx -- REFEREE for WRITING rung W-CONVO-1 (nx_convo). 2// 3// [T1] KEEP TOPICS GOING: picks the least-recently-used eligible topic, and after 4// it is marked used the NEXT call picks a different one (no immediate repeat). 5// [T2] difficulty eligibility: a too-hard topic is skipped even when it is the 6// least recently used (NEG-CONTROL); widening the window admits it. 7// [T3] RESPECT-GATE (anti-manipulation): high-confidence + low-respect attempt is 8// DISQUALIFIED (-1); a respectful attempt scores; raising respect flips it. 9// [T4] ADAPTIVE DIFFICULTY: up on strong score (capped), down on weak (floored), 10// unchanged in between. 11// 12// Evidence -> stdout + knowledge/status/convo_gate.log. Exit 0 GREEN / 1 RED. 13// Sovereign x86_64. license_tier: ORIGINAL 14import "nx_syscalls_x86_64.nx" 15import "nx_convo.nx" 16 17func gp(logfd: i64, s: *u8) -> i64 { 18 var n: i64 = 0 19 while s[n] != (0 as u8) { n = n + 1 } 20 sys_write(1, s, n) 21 if logfd > 0 { sys_write(logfd, s, n) } 22 return 0 23} 24func gn(logfd: i64, v: i64) -> i64 { 25 var m: i64 = v 26 if m < 0 { 27 sys_write(1, "-\x00" as *u8, 1) 28 if logfd > 0 { sys_write(logfd, "-\x00" as *u8, 1) } 29 m = 0 - m 30 } 31 let bb: *u8 = sys_mmap(32) 32 let t: *u8 = sys_mmap(32) 33 var k: i64 = 0 34 if m == 0 { t[0] = 48 as u8; k = 1 } 35 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 36 var i: i64 = 0 37 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 38 sys_write(1, bb, k) 39 if logfd > 0 { sys_write(logfd, bb, k) } 40 return 0 41} 42func pr_kv(logfd: i64, label: *u8, got: i64, exp: i64) -> i64 { 43 gp(logfd, label) 44 gp(logfd, " got=\x00" as *u8); gn(logfd, got) 45 gp(logfd, " exp=\x00" as *u8); gn(logfd, exp) 46 if got == exp { gp(logfd, " OK\n\x00" as *u8); return 1 } 47 gp(logfd, " FAIL\n\x00" as *u8) 48 return 0 49} 50func pr_cond(logfd: i64, label: *u8, cond: i64) -> i64 { 51 gp(logfd, label) 52 if cond != 0 { 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/convo_gate.log\x00" as *u8, 0x1a4) 59 gp(logfd, "CONVO-GATE W-CONVO-1 (keep-topics-going / respect-gated rubric / adaptive)\n\x00" as *u8) 60 61 let lu: *i64 = sys_mmap(64) as *i64 62 let df: *i64 = sys_mmap(64) as *i64 63 var ok: i64 = 1 64 65 // ---- T1: keep topics going (LRU among eligible), no immediate repeat ---- 66 gp(logfd, " [T1] keep-topics-going: LRU eligible, then no repeat\n\x00" as *u8) 67 lu[0] = 5; lu[1] = 2; lu[2] = 9; lu[3] = 2 68 df[0] = 1; df[1] = 1; df[2] = 1; df[3] = 3 69 let pick1: i64 = cv_next_topic(lu, df, 4, 2, 0) // level 2, window 0 -> {0,1,2}; lu min=2 @1 70 if pr_kv(logfd, " first pick\x00" as *u8, pick1, 1) == 0 { ok = 0 } 71 lu[pick1] = 10 // mark used at turn 10 72 let pick2: i64 = cv_next_topic(lu, df, 4, 2, 0) // now {0,1,2} lu=[5,10,9] min=5 @0 73 if pr_kv(logfd, " second pick (different)\x00" as *u8, pick2, 0) == 0 { ok = 0 } 74 var diff_ok: i64 = 0 75 if pick2 != pick1 { diff_ok = 1 } 76 if pr_cond(logfd, " no immediate repeat\x00" as *u8, diff_ok) == 0 { ok = 0 } 77 78 // ---- T2: difficulty eligibility (NEG-CONTROL) ---- 79 gp(logfd, " [T2] too-hard topic skipped though least recently used\n\x00" as *u8) 80 lu[0] = 5; lu[1] = 4; lu[2] = 9; lu[3] = 0 // topic3 is LRU but hard (diff 3) 81 df[0] = 1; df[1] = 1; df[2] = 1; df[3] = 3 82 let pk: i64 = cv_next_topic(lu, df, 4, 2, 0) // window 0 -> 3 ineligible -> {0,1,2} min=4 @1 83 if pr_kv(logfd, " skip-hard pick\x00" as *u8, pk, 1) == 0 { ok = 0 } 84 let pkw: i64 = cv_next_topic(lu, df, 4, 2, 1) // window 1 -> level+1=3 admits topic3 (LRU) 85 if pr_kv(logfd, " widen-window admits hard\x00" as *u8, pkw, 3) == 0 { ok = 0 } 86 87 // ---- T3: respect-gate (anti-manipulation) ---- 88 gp(logfd, " [T3] respect-gate: pushy attempt disqualified, respectful scores\n\x00" as *u8) 89 let sc: *i64 = sys_mmap(64) as *i64 90 let wt: *i64 = sys_mmap(64) as *i64 91 wt[0] = 1; wt[1] = 1; wt[2] = 1; wt[3] = 1 // axes: warmth/authenticity/respect/confidence 92 // pushy: high confidence(900), low respect(300 < gate 600) 93 sc[0] = 700; sc[1] = 400; sc[2] = 300; sc[3] = 900 94 if pr_kv(logfd, " pushy attempt DISQUALIFIED\x00" as *u8, cv_rubric(sc, wt, 4, 2, 600), 0 - 1) == 0 { ok = 0 } 95 // respectful: respect 800 >= 600 -> avg (700+800+800+700)/4 = 750 96 sc[0] = 700; sc[1] = 800; sc[2] = 800; sc[3] = 700 97 if pr_kv(logfd, " respectful attempt score\x00" as *u8, cv_rubric(sc, wt, 4, 2, 600), 750) == 0 { ok = 0 } 98 // flip the pushy attempt by raising respect to 650 -> (700+400+650+900)/4 = 662 99 sc[0] = 700; sc[1] = 400; sc[2] = 650; sc[3] = 900 100 if pr_kv(logfd, " raising respect flips pass\x00" as *u8, cv_rubric(sc, wt, 4, 2, 600), 662) == 0 { ok = 0 } 101 102 // ---- T4: adaptive difficulty ---- 103 gp(logfd, " [T4] adaptive difficulty up/down/hold + caps\n\x00" as *u8) 104 if pr_kv(logfd, " strong -> up\x00" as *u8, cv_level_adjust(2, 800, 700, 300, 0, 5), 3) == 0 { ok = 0 } 105 if pr_kv(logfd, " weak -> down\x00" as *u8, cv_level_adjust(2, 200, 700, 300, 0, 5), 1) == 0 { ok = 0 } 106 if pr_kv(logfd, " mid -> hold\x00" as *u8, cv_level_adjust(2, 500, 700, 300, 0, 5), 2) == 0 { ok = 0 } 107 if pr_kv(logfd, " up capped at max\x00" as *u8, cv_level_adjust(5, 800, 700, 300, 0, 5), 5) == 0 { ok = 0 } 108 109 if ok == 1 { 110 gp(logfd, "CONVO-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8) 111 if logfd > 0 { sys_close(logfd) } 112 sys_exit(0) 113 return 0 114 } 115 gp(logfd, "CONVO-GATE result=FAIL verdict=RED\n\x00" as *u8) 116 if logfd > 0 { sys_close(logfd) } 117 sys_exit(1) 118 return 1 119}