nx_teacher_coordinate.nx source
↩ module page · 78 lines · 4718 B
1// nx_teacher_coordinate.nx -- the COORDINATOR: runs the Nishi TEACHER, TRAINER and PUBLISHER together,
2// in dependency order, through the ONE shared native capability store (the coordination medium).
3//
4// Operator (2026-06-20): "see the nishi teacher and the nishi trainer and the nishi publisher
5// COORDINATING." Pipeline:
6// 1. TEACHER -- tsyn_merge_cols x3: synthesize every insight ledger into knowledge/store/teacher-capability-
7// 2. TRAINER -- trn_coverage / trn_due_count: schedule + measure over that store
8// 3. PUBLISHER -- tpub_emit: emit the curriculum page reflecting BOTH (insights + coverage meter)
9// One SITREP + a durable coordination log. The handoff is through the store, not a private side-channel,
10// so each organ stays single-responsibility (#9) and the loop is re-runnable + idempotent (#10).
11// license_tier: ORIGINAL
12import "nx_teacher_publish.nx"
13import "nx_syscalls.nx"
14
15func co_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != 0 as u8 { n = n + 1 } sys_write(1, s, n); return 0 }
16func co_putn(v: i64) -> i64 {
17 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
18 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
19 let d: *u8 = sys_mmap(24); var k: i64 = 0
20 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
21 var j: i64 = k - 1
22 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 }
23 return 0
24}
25// assemble one framed coordination log line (single write -- torn-write-safe).
26func co_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != 0 as u8 { dst[off + i] = s[i]; i = i + 1 } return off + i }
27func co_catn(dst: *u8, off: i64, v: i64) -> i64 {
28 var m: i64 = v; var o: i64 = off
29 let t: *u8 = sys_mmap(28); var k: i64 = 0
30 if m == 0 { t[0] = 48 as u8; k = 1 }
31 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
32 var i: i64 = 0; while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 }
33 return o + k
34}
35
36func main() -> i64 {
37 co_puts("=== NISHI TEACHER + TRAINER + PUBLISHER -- coordinated run (one shared native store) ===\n")
38 let cap: *u8 = "knowledge/store/teacher-capability-\x00" as *u8
39 let state: *u8 = "knowledge/store/teacher-review-\x00" as *u8
40 let out: *u8 = "web_assets/nishi-curriculum.html\x00" as *u8
41 let now: i64 = sys_now_realtime_sec()
42
43 // 1. TEACHER: synthesize/unify every insight ledger (idempotent -- dedup).
44 co_puts(" [teacher] synthesizing insight ledgers -> unified native store...\n")
45 tsyn_merge_cols("knowledge/_quarantine/registry/build_learnings.tsv\x00" as *u8, "build_learnings\x00" as *u8, cap, 0, 2)
46 tsyn_merge_cols("knowledge/registry/landmines.tsv\x00" as *u8, "landmines\x00" as *u8, cap, 0, 2)
47 tsyn_merge_cols("knowledge/registry/nishi_cardinals.tsv\x00" as *u8, "nishi_cardinals\x00" as *u8, cap, 0, 1)
48 let h: *i64 = ncfg_open(cap)
49 var total: i64 = 0
50 if (h as i64) != 0 { total = ncfg_count(h, "insight\x00" as *u8) }
51
52 // 2. TRAINER: schedule + measure over the teacher's store.
53 let covered: i64 = trn_coverage(cap, state)
54 let due: i64 = trn_due_count(cap, state, now)
55
56 // 3. EMIT the curriculum page = the ARTIFACT the teacher REQUESTS the Nishi Publisher to ship.
57 let bytes: i64 = tpub_emit(cap, state, out, now)
58
59 co_puts(" [teacher] insights="); co_putn(total); co_puts("\n")
60 co_puts(" [trainer] covered="); co_putn(covered); co_puts(" due="); co_putn(due); co_puts("\n")
61 co_puts(" [page] curriculum emitted="); co_putn(bytes); co_puts(" bytes -> web_assets/nishi-curriculum.html\n")
62 co_puts(" HANDOFF: page passed to the NISHI PUBLISHER via pub_submit (nx_pub_teacher_handoff, _hdl_build/ -- a runtime/ file cannot import the _hdl_build publisher). Workstreams REQUEST; the publisher SHIPS -- no direct push.\n")
63
64 // durable coordination log (single framed write).
65 let lb: *u8 = sys_mmap(512)
66 var o: i64 = co_cat(lb, 0, "COORDINATE epoch=" as *u8); o = co_catn(lb, o, now)
67 o = co_cat(lb, o, " insights=" as *u8); o = co_catn(lb, o, total)
68 o = co_cat(lb, o, " covered=" as *u8); o = co_catn(lb, o, covered)
69 o = co_cat(lb, o, " due=" as *u8); o = co_catn(lb, o, due)
70 o = co_cat(lb, o, " curriculum_bytes=" as *u8); o = co_catn(lb, o, bytes)
71 o = co_cat(lb, o, " END\n" as *u8); lb[o] = 0 as u8
72 let lfd: i64 = sys_openat_append("knowledge/status/teacher_coordinate.log\x00" as *u8, 0x1a4)
73 if lfd > 0 { sys_write(lfd, lb, o); sys_close(lfd) }
74
75 co_puts(" COORDINATED: teacher -> trainer -> [curriculum page] -> handed to the NISHI PUBLISHER, all through the ONE native store.\n")
76 if total > 0 { if bytes > 0 { sys_exit(0); return 0 } }
77 sys_exit(1); return 1
78}