code wiki / _hdl_build / nx_harmony_conduct.nx
nx_harmony_conduct.nx source
↩ module page · 125 lines · 7008 B
1// nx_harmony_conduct.nx -- THE CONDUCTOR: raise team harmony by performing the PM's `coordinate`
2// accountability for the WHOLE bound team, not just a few (operator: "not just a few"). For every
3// RACI activity it finds the Accountable owner and -- if that owner has NO live coordination in the
4// sovereign roles- store -- routes it its REAL standing accountability (a PENDING activation of the
5// activity it genuinely owns per the VALIDATED nx_raci contract). NOT fabricated busywork: each row
6// activates a role's real RACI duty. IDEMPOTENT: only cues a section whose channel is empty, so
7// re-runs add nothing. This is COORDINATION (every section cued to its part) -- the first half of
8// harmony; sustained performance (completing the routed work) is the ongoing measure.
9// Sovereign (roles- seg-store, no TSV writes). license_tier: ORIGINAL
10import "nx_role_store.nx"
11import "nx_syscalls.nx"
12import "nx_raci_sov.nx" // raci_read_all -- RACI from the SOVEREIGN store (NO TSV; flip 2026-07-16)
13const HC_MAGIC_2026: i64 = 2026
14
15// HC_RACI retired 2026-07-16: RACI reads from the sovereign store (raci_read_all)
16const HC_MAXROWS: i64 = 512
17const HC_STR: i64 = 40
18const HC_CAP: i64 = 262144
19
20func hc_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
21func hc_n(v: i64) -> i64 { if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } var m: i64 = v; let t: *u8 = sys_mmap(24); var k: i64 = 0; while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } let o: *u8 = sys_mmap(24); var w: i64 = 0; var q: i64 = k - 1; while q >= 0 { o[w] = t[q]; w = w + 1; q = q - 1 } sys_write(1, o, w); return 0 }
22func hc_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 }
23func hc_has(s: *u8, ch: i64) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { if (s[i] as i64) == ch { return 1 } i = i + 1 } return 0 }
24func hc_cpy(dst: *u8, src: *u8, max: i64) -> i64 { var i: i64 = 0; while src[i] != (0 as u8) { if i < max - 1 { dst[i] = src[i] } i = i + 1 } dst[i] = 0 as u8; return 0 }
25func hc_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64 = off; var i: i64 = 0; while s[i] != (0 as u8) { dst[o] = s[i]; o = o + 1; i = i + 1 } return o }
26func hc_read(path: *u8, buf: *u8, cap: i64) -> i64 {
27 let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 - 1 }
28 var off: i64 = 0; var go: i64 = 1
29 while go == 1 { if off >= cap { go = 0 } else { let r: i64 = sys_read(fd, ((buf as i64) + off) as *u8, cap - off); if r <= 0 { go = 0 } else { off = off + r } } }
30 sys_close(fd); return off
31}
32func hc_field(line: *u8, len: i64, idx: i64, out: *u8, outcap: i64) -> i64 {
33 var f: i64 = 0; var i: i64 = 0; var w: i64 = 0
34 while i < len { let c: i64 = line[i] as i64
35 if c == 9 { if f == idx { out[w] = 0 as u8; return 1 } f = f + 1 } else { if f == idx { if w < outcap - 1 { out[w] = line[i]; w = w + 1 } } }
36 i = i + 1 }
37 if f == idx { out[w] = 0 as u8; return 1 }
38 return 0
39}
40// load role/activity/letters into caller arrays. returns nrows.
41func hc_load(roleS: *u8, actS: *u8, letS: *u8) -> i64 {
42 let buf: *u8 = sys_mmap(HC_CAP); let n: i64 = raci_read_all(buf, HC_CAP)
43 if n <= 0 { return 0 - 1 }
44 let f: *u8 = sys_mmap(HC_STR)
45 var nrows: i64 = 0; var ls: i64 = 0; var i: i64 = 0
46 while i <= n {
47 var nl: i64 = 0; if i >= n { nl = 1 } else { if buf[i] == (10 as u8) { nl = 1 } }
48 if nl == 1 {
49 let ll: i64 = i - ls
50 if ll > 0 {
51 let line: *u8 = ((buf as i64) + ls) as *u8
52 if line[0] != (35 as u8) {
53 if hc_field(line, ll, 0, f, HC_STR) == 1 { if f[0] != (0 as u8) { if nrows < HC_MAXROWS {
54 hc_cpy(((roleS as i64) + nrows * HC_STR) as *u8, f, HC_STR)
55 hc_field(line, ll, 1, ((actS as i64) + nrows * HC_STR) as *u8, HC_STR)
56 hc_field(line, ll, 2, ((letS as i64) + nrows * HC_STR) as *u8, HC_STR)
57 nrows = nrows + 1
58 } } }
59 }
60 }
61 ls = i + 1
62 }
63 i = i + 1
64 }
65 return nrows
66}
67// the Accountable role for activity `act` -> out. 1 if found.
68func hc_owner(roleS: *u8, actS: *u8, letS: *u8, nrows: i64, act: *u8, out: *u8) -> i64 {
69 var i: i64 = 0
70 while i < nrows {
71 if hc_streq(((actS as i64) + i * HC_STR) as *u8, act) == 1 { if hc_has(((letS as i64) + i * HC_STR) as *u8, 65) == 1 {
72 hc_cpy(out, ((roleS as i64) + i * HC_STR) as *u8, HC_STR); return 1
73 } }
74 i = i + 1
75 }
76 return 0
77}
78// channel for a role: pm -> pmcoord, else <role>q.
79func hc_chan(role: *u8, out: *u8) -> i64 {
80 if hc_streq(role, "pm" as *u8) == 1 { hc_cpy(out, "pmcoord" as *u8, HC_STR); return 0 }
81 var o: i64 = hc_cat(out, 0, role); out[o] = 113 as u8; o = o + 1; out[o] = 0 as u8 // 'q'
82 return 0
83}
84
85func main(argc: i64, argv: *i64) -> i64 {
86 let roleS: *u8 = sys_mmap(HC_MAXROWS * HC_STR)
87 let actS: *u8 = sys_mmap(HC_MAXROWS * HC_STR)
88 let letS: *u8 = sys_mmap(HC_MAXROWS * HC_STR)
89 let nrows: i64 = hc_load(roleS, actS, letS)
90 if nrows < 0 { hc_w("CONDUCT: RACI unreadable\n" as *u8); sys_exit(2); return 2 }
91 hc_w("=== CONDUCTOR: PM coordinates the WHOLE bound team (not just a few) ===\n" as *u8)
92
93 // distinct activities
94 let dact: *u8 = sys_mmap(HC_MAXROWS * HC_STR); var ndact: i64 = 0
95 var r: i64 = 0
96 while r < nrows {
97 let a: *u8 = ((actS as i64) + r * HC_STR) as *u8; var seen: i64 = 0; var d: i64 = 0
98 while d < ndact { if hc_streq(((dact as i64) + d * HC_STR) as *u8, a) == 1 { seen = 1 } d = d + 1 }
99 if seen == 0 { hc_cpy(((dact as i64) + ndact * HC_STR) as *u8, a, HC_STR); ndact = ndact + 1 }
100 r = r + 1
101 }
102
103 var coordinated: i64 = 0; var already: i64 = 0
104 let owner: *u8 = sys_mmap(HC_STR); let chan: *u8 = sys_mmap(HC_STR); let row: *u8 = sys_mmap(256)
105 var k: i64 = 0
106 while k < ndact {
107 let act: *u8 = ((dact as i64) + k * HC_STR) as *u8
108 if hc_owner(roleS, actS, letS, nrows, act, owner) == 1 {
109 hc_chan(owner, chan)
110 if rs_count(chan) > 0 {
111 already = already + 1
112 } else {
113 var o: i64 = hc_cat(row, 0, owner)
114 o = hc_cat(row, o, "\tPENDING\tactivate:" as *u8); o = hc_cat(row, o, act)
115 o = hc_cat(row, o, "\tby=pm-coordinate" as *u8); row[o] = 0 as u8
116 rs_append(chan, row, o)
117 coordinated = coordinated + 1
118 hc_w(" cue -> " as *u8); hc_w(owner); hc_w(" (owns " as *u8); hc_w(act); hc_w(") -> channel " as *u8); hc_w(chan); hc_w(" now live\n" as *u8)
119 }
120 }
121 k = k + 1
122 }
123 hc_w("CONDUCT coordinated=" as *u8); hc_n(coordinated); hc_w(" newly-cued, already-playing=" as *u8); hc_n(already); hc_w("\n" as *u8)
124 sys_exit(0); return 0
125}