code wiki / _hdl_build / nx_team_harmony.nx
nx_team_harmony.nx source
↩ module page · 236 lines · 13801 B
1// nx_team_harmony.nx -- THE ORCHESTRA: the Nishi team judges ITSELF and its COUNTERPARTS on the
2// ability to orchestrate and make "music" through total harmony (operator 2026-06-22). NOT Claude
3// grading -- the ecosystem measures itself from REAL signals, liar-killed:
4// SELF-judgment(role) = PRESENT (organ on disk) + OWNS (accountable for >=1 RACI activity)
5// COUNTERPART-judgment(role) = BOUND (named in the RACI contract) + PLAYING (live rows in the
6// sovereign roles- store) -- "the team's contract includes me AND I am
7// actually playing for them."
8// HARMONY(role) = SELF + PEER (0..4); IN-HARMONY iff == 4 (exists, owns, bound, AND playing).
9// MUSIC = TOTAL harmony scored by the WEAKEST section, not the average -- a few stars cannot fake
10// a full orchestra. MUSIC only when every section is in.
11// Grounds the roster + ownership in the VALIDATED RACI contract (knowledge/registry/nishi_raci.tsv,
12// the SSOT nx_raci enforces) + live activity in the sovereign seg-store via nx_role_store rs_count.
13// Sovereign. license_tier: ORIGINAL
14import "nx_role_store.nx"
15import "nx_syscalls.nx"
16import "nx_raci_sov.nx" // raci_read_all -- RACI from the SOVEREIGN store (NO TSV; flip 2026-07-16)
17const TH_MAGIC_2026: i64 = 2026
18
19// TH_RACI retired 2026-07-16: RACI reads from the sovereign store (raci_read_all)
20const TH_MAXROWS: i64 = 512
21const TH_STR: i64 = 40
22const TH_CAP: i64 = 262144
23const TH_LOG: *u8 = "knowledge/status/team_harmony.log"
24
25func th_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
26func th_n(v: i64) -> i64 {
27 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
28 var m: i64 = v
29 let t: *u8 = sys_mmap(24); var k: i64 = 0
30 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
31 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 }
32 sys_write(1, o, w); return 0
33}
34func th_pad(s: *u8, width: i64) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); var p: i64 = width - n; while p > 0 { th_w(" " as *u8); p = p - 1 } return 0 }
35func th_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 }
36func th_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 }
37func th_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 }
38func th_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 }
39
40func th_read(path: *u8, buf: *u8, cap: i64) -> i64 {
41 let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 - 1 }
42 var off: i64 = 0; var go: i64 = 1
43 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 } } }
44 sys_close(fd); return off
45}
46func th_field(line: *u8, len: i64, idx: i64, out: *u8, outcap: i64) -> i64 {
47 var f: i64 = 0; var i: i64 = 0; var w: i64 = 0
48 while i < len { let c: i64 = line[i] as i64
49 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 } } }
50 i = i + 1 }
51 if f == idx { out[w] = 0 as u8; return 1 }
52 return 0
53}
54
55// load the RACI matrix into caller arrays roleS[]/letS[] (each TH_MAXROWS*TH_STR). returns nrows.
56func th_load(roleS: *u8, letS: *u8) -> i64 {
57 let buf: *u8 = sys_mmap(TH_CAP); let n: i64 = raci_read_all(buf, TH_CAP)
58 if n <= 0 { return 0 - 1 }
59 let f: *u8 = sys_mmap(TH_STR)
60 var nrows: i64 = 0; var ls: i64 = 0; var i: i64 = 0
61 while i <= n {
62 var nl: i64 = 0; if i >= n { nl = 1 } else { if buf[i] == (10 as u8) { nl = 1 } }
63 if nl == 1 {
64 let ll: i64 = i - ls
65 if ll > 0 {
66 let line: *u8 = ((buf as i64) + ls) as *u8
67 if line[0] != (35 as u8) {
68 if th_field(line, ll, 0, f, TH_STR) == 1 { if f[0] != (0 as u8) {
69 if nrows < TH_MAXROWS {
70 th_cpy(((roleS as i64) + nrows * TH_STR) as *u8, f, TH_STR)
71 th_field(line, ll, 2, ((letS as i64) + nrows * TH_STR) as *u8, TH_STR)
72 nrows = nrows + 1
73 }
74 } }
75 }
76 }
77 ls = i + 1
78 }
79 i = i + 1
80 }
81 return nrows
82}
83
84func th_bound(roleS: *u8, nrows: i64, role: *u8) -> i64 {
85 var i: i64 = 0
86 while i < nrows { if th_streq(((roleS as i64) + i * TH_STR) as *u8, role) == 1 { return 1 } i = i + 1 }
87 return 0
88}
89func th_owns(roleS: *u8, letS: *u8, nrows: i64, role: *u8) -> i64 {
90 var c: i64 = 0; var i: i64 = 0
91 while i < nrows {
92 if th_streq(((roleS as i64) + i * TH_STR) as *u8, role) == 1 { if th_has(((letS as i64) + i * TH_STR) as *u8, 65) == 1 { c = c + 1 } }
93 i = i + 1
94 }
95 return c
96}
97func th_present(organ: *u8) -> i64 {
98 let p: *u8 = sys_mmap(512); let stb: *u8 = sys_mmap(256)
99 var o: i64 = th_cat(p, 0, "runtime/_hdl_build/" as *u8); o = th_cat(p, o, organ); o = th_cat(p, o, ".nx" as *u8); p[o] = 0 as u8
100 if sys_fstatat(p, stb) == 0 { return 1 }
101 let p2: *u8 = sys_mmap(512)
102 var o2: i64 = th_cat(p2, 0, "runtime/" as *u8); o2 = th_cat(p2, o2, organ); o2 = th_cat(p2, o2, ".nx" as *u8); p2[o2] = 0 as u8
103 if sys_fstatat(p2, stb) == 0 { return 1 }
104 return 0
105}
106func th_playing(channel: *u8) -> i64 { if rs_count(channel) > 0 { return 1 } return 0 }
107// sovereign RACI extension (roles- store "raciext"): is `role` listed (want_A=0) / Accountable
108// (want_A=1)? Lets conductor/race be bound + own without any TSV write.
109func th_ext(role: *u8, want_A: i64) -> i64 {
110 let n: i64 = rs_count("raciext" as *u8)
111 let pq: *i64 = sys_mmap(16) as *i64; let lq: *i64 = sys_mmap(16) as *i64
112 let fr: *u8 = sys_mmap(TH_STR); let fl: *u8 = sys_mmap(TH_STR)
113 var i: i64 = 0
114 while i < n {
115 if rs_get_seq("raciext" as *u8, i, pq, lq) == 1 {
116 th_field(pq[0] as *u8, lq[0], 0, fr, TH_STR)
117 if th_streq(fr, role) == 1 {
118 if want_A == 0 { return 1 }
119 th_field(pq[0] as *u8, lq[0], 2, fl, TH_STR)
120 if th_has(fl, 65) == 1 { return 1 }
121 }
122 }
123 i = i + 1
124 }
125 return 0
126}
127
128// DELIVERING: does the role's channel hold a COMPLETED (status APPLIED) row, not just a cue?
129// This is the deep signal -- engagement (a PENDING cue) is not performance.
130func th_delivering(channel: *u8) -> i64 {
131 let n: i64 = rs_count(channel)
132 let pq: *i64 = sys_mmap(16) as *i64; let lq: *i64 = sys_mmap(16) as *i64
133 let fld: *u8 = sys_mmap(TH_STR)
134 var i: i64 = 0
135 while i < n {
136 if rs_get_seq(channel, i, pq, lq) == 1 {
137 th_field(pq[0] as *u8, lq[0], 1, fld, TH_STR)
138 if th_streq(fld, "APPLIED" as *u8) == 1 { return 1 }
139 if th_streq(fld, "EXCEED" as *u8) == 1 { return 1 }
140 }
141 i = i + 1
142 }
143 return 0
144}
145
146// EXCELLING: a channel row with status EXCEED -- work that MEASURABLY EXCEEDS a named alternative
147// (gate-proven), not merely APPLIED. The S-class bar; the 5th tier the critics demand.
148func th_exceeding(channel: *u8) -> i64 {
149 let n: i64 = rs_count(channel)
150 let pq: *i64 = sys_mmap(16) as *i64; let lq: *i64 = sys_mmap(16) as *i64
151 let fld: *u8 = sys_mmap(TH_STR)
152 var i: i64 = 0
153 while i < n {
154 if rs_get_seq(channel, i, pq, lq) == 1 { th_field(pq[0] as *u8, lq[0], 1, fld, TH_STR); if th_streq(fld, "EXCEED" as *u8) == 1 { return 1 } }
155 i = i + 1
156 }
157 return 0
158}
159
160// judge ONE role on THREE tiers. base = present+owns+bound (table stakes, 0..3). ENGAGEMENT +engaged
161// (cued); PERFORMANCE +delivering(APPLIED|EXCEED); EXCELLENCE +exceeding(EXCEED = measured win). tally:
162// t[0]=count t[1]=eng_in t[3]=eng_weak t[4]=perf_in t[5]=perf_weak t[6]=excel_in t[7]=excel_weak.
163func th_judge(role: *u8, organ: *u8, channel: *u8, roleS: *u8, letS: *u8, nrows: i64, t: *i64) -> i64 {
164 let present: i64 = th_present(organ)
165 var owns: i64 = th_owns(roleS, letS, nrows, role)
166 if th_ext(role, 1) == 1 { owns = owns + 1 }
167 var bound: i64 = th_bound(roleS, nrows, role)
168 if bound == 0 { if th_ext(role, 0) == 1 { bound = 1 } }
169 let engaged: i64 = th_playing(channel)
170 let delivering: i64 = th_delivering(channel)
171 let exceeding: i64 = th_exceeding(channel)
172 var ownsb: i64 = 0; if owns > 0 { ownsb = 1 }
173 let base: i64 = present + ownsb + bound
174 let eng_h: i64 = base + engaged
175 let perf_h: i64 = base + delivering
176 let excel_h: i64 = base + exceeding
177 var eng_in: i64 = 0; if eng_h == 4 { eng_in = 1 }
178 var perf_in: i64 = 0; if perf_h == 4 { perf_in = 1 }
179 var excel_in: i64 = 0; if excel_h == 4 { excel_in = 1 }
180 th_w(" " as *u8); th_pad(role, 12)
181 th_w(" base=" as *u8); th_n(base); th_w("/3 | engaged=" as *u8); th_n(engaged); th_w(" deliver=" as *u8); th_n(delivering); th_w(" EXCEED=" as *u8); th_n(exceeding); th_w(" " as *u8)
182 if excel_in == 1 { th_w("[EXCELLING]\n" as *u8) } else { if perf_in == 1 { th_w("[delivering]\n" as *u8) } else { if eng_in == 1 { th_w("[engaged]\n" as *u8) } else { th_w("[silent]\n" as *u8) } } }
183 t[0] = t[0] + 1; t[1] = t[1] + eng_in; t[4] = t[4] + perf_in; t[6] = t[6] + excel_in
184 if t[0] == 1 { t[3] = eng_h; t[5] = perf_h; t[7] = excel_h } else { if eng_h < t[3] { t[3] = eng_h } if perf_h < t[5] { t[5] = perf_h } if excel_h < t[7] { t[7] = excel_h } }
185 return excel_h
186}
187
188func main(argc: i64, argv: *i64) -> i64 {
189 let roleS: *u8 = sys_mmap(TH_MAXROWS * TH_STR)
190 let letS: *u8 = sys_mmap(TH_MAXROWS * TH_STR)
191 let nrows: i64 = th_load(roleS, letS)
192 if nrows < 0 { th_w("HARMONY: RACI contract unreadable\n" as *u8); sys_exit(2); return 2 }
193 th_w("=== NISHI ORCHESTRA -- the team judges itself + its counterparts on TOTAL HARMONY ===\n" as *u8)
194 th_w("(RACI " as *u8); th_n(nrows); th_w(" cells. base=PRESENT+OWNS+BOUND; ENG +engaged(cued), PERF +delivering(APPLIED work). MUSIC = every section DELIVERING)\n\n" as *u8)
195
196 let t: *i64 = sys_mmap(64) as *i64
197 th_judge("pm" as *u8, "nx_pm_sclass" as *u8, "pmcoord" as *u8, roleS, letS, nrows, t)
198 th_judge("researcher" as *u8, "nx_research_fetch" as *u8, "researcherq" as *u8, roleS, letS, nrows, t)
199 th_judge("engineer" as *u8, "nx_engineer" as *u8, "engineerq" as *u8, roleS, letS, nrows, t)
200 th_judge("doctor" as *u8, "nx_doctor" as *u8, "doctorq" as *u8, roleS, letS, nrows, t)
201 th_judge("warden" as *u8, "nx_warden" as *u8, "wardenq" as *u8, roleS, letS, nrows, t)
202 th_judge("publisher" as *u8, "nx_publisher" as *u8, "publisherq" as *u8, roleS, letS, nrows, t)
203 th_judge("supervisor" as *u8, "nx_supervised_dispatch" as *u8, "supervisorq" as *u8, roleS, letS, nrows, t)
204 th_judge("workstream" as *u8, "nx_ws_board" as *u8, "workstreamq" as *u8, roleS, letS, nrows, t)
205 th_judge("conductor" as *u8, "nx_conductor" as *u8, "conductorq" as *u8, roleS, letS, nrows, t)
206 th_judge("racing" as *u8, "nx_racing" as *u8, "racingq" as *u8, roleS, letS, nrows, t)
207
208 let real_n: i64 = t[0]; let eng_in: i64 = t[1]
209 let perf_in: i64 = t[4]
210 let excel_in: i64 = t[6]; let excel_weak: i64 = t[7]
211
212 th_w("\n -- liar-kill --\n" as *u8)
213 let pt: *i64 = sys_mmap(64) as *i64
214 let ph: i64 = th_judge("phantom" as *u8, "nx_no_such_role_zzz" as *u8, "phantomq" as *u8, roleS, letS, nrows, pt)
215 var liar_ok: i64 = 0; if ph < 4 { liar_ok = 1 }
216
217 th_w("\n=== ENGAGEMENT (table stakes): " as *u8); th_n(eng_in); th_w("/" as *u8); th_n(real_n); th_w(" cued ===\n" as *u8)
218 th_w("=== PERFORMANCE (delivered): " as *u8); th_n(perf_in); th_w("/" as *u8); th_n(real_n); th_w(" APPLIED ===\n" as *u8)
219 th_w("=== EXCELLENCE (S-class EXCEED): " as *u8); th_n(excel_in); th_w("/" as *u8); th_n(real_n); th_w(" measured wins (weakest=" as *u8); th_n(excel_weak); th_w("/4) ===\n" as *u8)
220 var music: i64 = 0
221 if excel_in == real_n { if excel_weak == 4 { if liar_ok == 1 { music = 1 } } }
222
223 let buf: *u8 = sys_mmap(256); var o: i64 = 0
224 o = th_cat(buf, o, "TEAM-HARMONY engaged=" as *u8); o = o + rs_itoa(((buf as i64) + o) as *u8, eng_in)
225 o = th_cat(buf, o, "/" as *u8); o = o + rs_itoa(((buf as i64) + o) as *u8, real_n)
226 o = th_cat(buf, o, " performing=" as *u8); o = o + rs_itoa(((buf as i64) + o) as *u8, perf_in)
227 o = th_cat(buf, o, "/" as *u8); o = o + rs_itoa(((buf as i64) + o) as *u8, real_n)
228 o = th_cat(buf, o, " excelling=" as *u8); o = o + rs_itoa(((buf as i64) + o) as *u8, excel_in)
229 o = th_cat(buf, o, "/" as *u8); o = o + rs_itoa(((buf as i64) + o) as *u8, real_n)
230 if music == 1 { o = th_cat(buf, o, " verdict=MUSIC" as *u8) } else { o = th_cat(buf, o, " verdict=NOT-S-CLASS" as *u8) }
231 rs_append("harmony" as *u8, buf, o)
232
233 if music == 1 { th_w("VERDICT: MUSIC -- every section MEASURABLY EXCEEDS a named alternative (S-class, gate-proven, liar-killed).\n" as *u8); sys_exit(0); return 0 }
234 th_w("VERDICT: NOT S-CLASS -- excellence is the bar (measured wins over named alternatives), and it is " as *u8); th_n(excel_in); th_w("/" as *u8); th_n(real_n); th_w(". Delivery is not excellence; presence is not delivery. Earn measured EXCEEDs.\n" as *u8)
235 sys_exit(1); return 1
236}