code wiki / (root) / nx_teacher_mastery.nx

nx_teacher_mastery.nx source

↩ module page · 168 lines · 8242 B

1// nx_teacher_mastery.nx -- the TRAINER's honest CAPABILITY measure (Teacher arc, rung R3b). 2// 3// The trainer's coverage meter ([[project-tsv-native-migration-janitor-2026-06-20]]) measures SCHEDULING 4// (fraction of insights under spaced practice) -- NOT a proven capability gain. This rung adds the honest 5// gap: MASTERY = the team can RECALL an insight's rule on demand, and it is mastered ONLY IF the recall is 6// mechanically correct (the rule is contained in the answer) -- you cannot fake mastery with a wrong answer 7// (Rule 4, no-overclaim, liar-kill). Mastery is DISTINCT from coverage: coverage = attempted; mastery = 8// answered correctly. The before/after capability lift = mastery_rate rising as the team correctly recalls. 9// 10// HONEST SCOPE: this is the measurement SUBSTRATE. Real mastery requires the team's OWN independent recalls 11// (its reasoning produces the answers) fed to mst_attempt; this organ does the mechanical correctness check 12// + the append-only mastery record. Imports ONLY nx_native_config (shallow -> small object). No network, 13// no hardware writes (Rule 26). license_tier: ORIGINAL 14import "nx_native_config.nx" 15import "nx_syscalls.nx" 16const K_MAGIC_8192: i64 = 8192 17 18func mst_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != 0 as u8 { n = n + 1 } sys_write(1, s, n); return 0 } 19func mst_putn(v: i64) -> i64 { 20 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 21 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 22 let d: *u8 = sys_mmap(24); var k: i64 = 0 23 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 24 var j: i64 = k - 1 25 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 } 26 return 0 27} 28func mst_streq(a: *u8, b: *u8) -> i64 { 29 var i: i64 = 0 30 while a[i] != 0 as u8 { if a[i] != b[i] { return 0 } i = i + 1 } 31 if b[i] != 0 as u8 { return 0 } 32 return 1 33} 34func mst_atoi(s: *u8) -> i64 { 35 if (s as i64) == 0 { return 0 } 36 var v: i64 = 0; var i: i64 = 0 37 while s[i] != (0 as u8) { let c: i64 = s[i] as i64; if c >= 48 { if c <= 57 { v = v * 10 + (c - 48) } } i = i + 1 } 38 return v 39} 40func mst_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 41// is `needle` (NUL-term) a substring of `hay` (NUL-term)? -- the recall-correctness check. 42func mst_contains(hay: *u8, needle: *u8) -> i64 { 43 let hl: i64 = mst_slen(hay) 44 let nl: i64 = mst_slen(needle) 45 if nl == 0 { return 0 } 46 var i: i64 = 0 47 while i + nl <= hl { 48 var j: i64 = 0; var ok: i64 = 1 49 while j < nl { if hay[i+j] != needle[j] { ok = 0; j = nl } else { j = j + 1 } } 50 if ok == 1 { return 1 } 51 i = i + 1 52 } 53 return 0 54} 55// copy the rule of the insight whose id==want from the cap store into out (NUL-term). 1=found. 56func mst_rule_of(cap_store: *u8, want: *u8, out: *u8) -> i64 { 57 let h: *i64 = ncfg_open(cap_store) 58 if (h as i64) == 0 { out[0] = 0 as u8; return 0 } 59 let cnt: i64 = ncfg_count(h, "insight\x00" as *u8) 60 let rk: *i64 = sys_mmap(8 * 16) as *i64 61 let rv: *i64 = sys_mmap(8 * 16) as *i64 62 var i: i64 = 0 63 while i < cnt { 64 let rf: i64 = ncfg_row(h, "insight\x00" as *u8, i, rk, rv, 16) 65 if rf > 0 { 66 let idb: *u8 = ncfg_field(rk, rv, rf, "id\x00" as *u8) 67 if (idb as i64) != 0 { if mst_streq(idb, want) == 1 { 68 let rb: *u8 = ncfg_field(rk, rv, rf, "rule\x00" as *u8) 69 var j: i64 = 0 70 if (rb as i64) != 0 { while rb[j] != (0 as u8) { out[j] = rb[j]; j = j + 1 } } 71 out[j] = 0 as u8 72 return 1 73 } } 74 } 75 i = i + 1 76 } 77 out[0] = 0 as u8 78 return 0 79} 80// append an attempt record {id, mastered} to the mastery store (offset append, last-wins by id). 81func mst_append(mastery_store: *u8, id: *u8, mastered: i64) -> i64 { 82 let h0: *i64 = ncfg_open(mastery_store) 83 var base: i64 = 0 84 if (h0 as i64) != 0 { base = ncfg_count(h0, "mst\x00" as *u8) } 85 let w: *i64 = ncfg_begin() 86 let kb: *i64 = sys_mmap(8 * 8) as *i64 87 let vb: *i64 = sys_mmap(8 * 8) as *i64 88 let ms: *u8 = sys_mmap(8) 89 if mastered == 1 { ms[0] = 49 as u8 } else { ms[0] = 48 as u8 } // "1" / "0" 90 ms[1] = 0 as u8 91 kb[0] = ("id\x00") as i64; vb[0] = (id as i64) 92 kb[1] = ("mastered\x00") as i64; vb[1] = (ms as i64) 93 ncfg_add_row(w, "mst\x00" as *u8, base, kb, vb, 2) 94 ncfg_set_count(w, "mst\x00" as *u8, base + 1) 95 return ncfg_commit(mastery_store, w) 96} 97// ATTEMPT a drill: the team's `answer` is mastered IFF it mechanically contains the insight's rule. records it. 98func mst_attempt(cap_store: *u8, mastery_store: *u8, id: *u8, answer: *u8) -> i64 { 99 let rule: *u8 = sys_mmap(K_MAGIC_8192) 100 if mst_rule_of(cap_store, id, rule) == 0 { return 0 } // unknown id -> no fabricated mastery 101 var mastered: i64 = 0 102 if mst_contains(answer, rule) == 1 { mastered = 1 } // real recall, not faked 103 mst_append(mastery_store, id, mastered) 104 return mastered 105} 106// current mastery of `id` (last attempt): 1 mastered, 0 not / never attempted. 107func mst_mastered(mastery_store: *u8, id: *u8) -> i64 { 108 let h: *i64 = ncfg_open(mastery_store) 109 if (h as i64) == 0 { return 0 } 110 let cnt: i64 = ncfg_count(h, "mst\x00" as *u8) 111 let rk: *i64 = sys_mmap(8 * 16) as *i64 112 let rv: *i64 = sys_mmap(8 * 16) as *i64 113 var got: i64 = 0 114 var i: i64 = 0 115 while i < cnt { 116 let rf: i64 = ncfg_row(h, "mst\x00" as *u8, i, rk, rv, 16) 117 if rf > 0 { 118 let idb: *u8 = ncfg_field(rk, rv, rf, "id\x00" as *u8) 119 if (idb as i64) != 0 { if mst_streq(idb, id) == 1 { got = mst_atoi(ncfg_field(rk, rv, rf, "mastered\x00" as *u8)) } } 120 } 121 i = i + 1 122 } 123 return got 124} 125// MEASURED capability: how many cap insights are currently mastered. (the honest before/after metric) 126func mst_rate(cap_store: *u8, mastery_store: *u8) -> i64 { 127 let h: *i64 = ncfg_open(cap_store) 128 if (h as i64) == 0 { return 0 } 129 let cnt: i64 = ncfg_count(h, "insight\x00" as *u8) 130 let rk: *i64 = sys_mmap(8 * 16) as *i64 131 let rv: *i64 = sys_mmap(8 * 16) as *i64 132 var mastered: i64 = 0 133 var i: i64 = 0 134 while i < cnt { 135 let rf: i64 = ncfg_row(h, "insight\x00" as *u8, i, rk, rv, 16) 136 if rf > 0 { 137 let idb: *u8 = ncfg_field(rk, rv, rf, "id\x00" as *u8) 138 if (idb as i64) != 0 { if mst_mastered(mastery_store, idb) == 1 { mastered = mastered + 1 } } 139 } 140 i = i + 1 141 } 142 return mastered 143} 144 145func main() -> i64 { 146 mst_puts("=== Nishi Teacher MASTERY: honest capability measure (drill recall, mechanically checked) ===\n") 147 let cap: *u8 = "knowledge/store/teacher-capability-\x00" as *u8 148 let mastery: *u8 = "knowledge/store/teacher-mastery-\x00" as *u8 149 let h: *i64 = ncfg_open(cap) 150 var total: i64 = 0 151 if (h as i64) != 0 { total = ncfg_count(h, "insight\x00" as *u8) } 152 mst_puts(" insights="); mst_putn(total); mst_puts(" mastered(before)="); mst_putn(mst_rate(cap, mastery)); mst_puts("\n") 153 154 // SUBSTRATE DEMO (the real loop feeds the team's OWN recalls): a CORRECT recall of BL-001's rule masters it; 155 // a WRONG answer for LM-001 does NOT (liar-kill). We fetch BL-001's rule to simulate a correct recall. 156 let buf: *u8 = sys_mmap(K_MAGIC_8192) 157 if mst_rule_of(cap, "BL-001\x00" as *u8, buf) == 1 { 158 let ok: i64 = mst_attempt(cap, mastery, "BL-001\x00" as *u8, buf) // correct recall 159 mst_puts(" attempt BL-001 (correct recall) -> mastered="); mst_putn(ok); mst_puts("\n") 160 } 161 let wrong: i64 = mst_attempt(cap, mastery, "LM-001\x00" as *u8, "i dont remember this one\x00" as *u8) // wrong 162 mst_puts(" attempt LM-001 (wrong answer) -> mastered="); mst_putn(wrong); mst_puts(" (cannot fake mastery)\n") 163 164 mst_puts(" mastered(after)="); mst_putn(mst_rate(cap, mastery)); mst_puts("/"); mst_putn(total) 165 mst_puts(" -- HONEST: mastery rises ONLY on a correct recall; coverage(scheduled) != mastery(proven recall).\n") 166 mst_puts(" (real capability lift = the team's OWN recalls via mst_attempt + this mechanical check; this demo simulates one correct + one wrong.)\n") 167 sys_exit(0); return 0 168}