code wiki / _hdl_build / nx_team_digest.nx
nx_team_digest.nx source
↩ module page · 164 lines · 7944 B
1// nx_team_digest.nx -- THE OPERATOR FLAG (black box -> visible). Every beat,
2// distill the team's status logs into ONE human digest + a sovereign HTML page
3// (the nishifamily.com feedback surface). Answers the operator's standing
4// questions without a session: where is the ladder, what is the team doing,
5// and -- the one that needs YOU -- what is raised-hand novel work.
6// Sources (read-only tails; cheap): rung_grades.log (ladder), queue_health.log
7// (queue mix), assign_next.log (next pick + raised hands), token_efficiency.log
8// (closed-per-visit trend), gap_gen.log (work the team generated for itself).
9// Outputs: knowledge/status/team_digest.log (text) + knowledge/team_digest.html.
10// license_tier: ORIGINAL
11import "nx_syscalls.nx"
12const K_MAGIC_524288: i64 = 524288
13const K_MAGIC_131072: i64 = 131072
14const K_MAGIC_1024: i64 = 1024
15
16func td_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
17func td_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
18
19func td_read(path: *u8, buf: *u8, cap: i64) -> i64 {
20 let fd: i64 = sys_openat_rd(path)
21 if fd < 0 { return 0 }
22 var n: i64 = 0
23 var r: i64 = sys_read(fd, buf, cap - 1)
24 while r > 0 { n = n + r; if n >= cap - 1 { r = 0 } else { r = sys_read(fd, buf + n, cap - 1 - n) } }
25 sys_close(fd)
26 buf[n] = 0 as u8
27 return n
28}
29
30func td_at(buf: *u8, n: i64, i: i64, pat: *u8, pl: i64) -> i64 {
31 if i + pl > n { return 0 }
32 var k: i64 = 0
33 while k < pl { if buf[i + k] != pat[k] { return 0 } k = k + 1 }
34 return 1
35}
36
37// copy the LAST line containing anchor into out (NUL-term); 1 found / 0 not
38func td_last_line(buf: *u8, n: i64, anchor: *u8, out: *u8, ocap: i64) -> i64 {
39 let al: i64 = td_len(anchor)
40 var found: i64 = 0
41 var ls: i64 = 0
42 var i: i64 = 0
43 while i <= n {
44 var eol: i64 = 0
45 if i == n { eol = 1 } else { if buf[i] == (10 as u8) { eol = 1 } }
46 if eol == 1 {
47 var j: i64 = ls
48 var hit: i64 = 0
49 while j < i { if td_at(buf, n, j, anchor, al) == 1 { hit = 1; j = i } else { j = j + 1 } }
50 if hit == 1 {
51 found = 1
52 var k: i64 = 0
53 var q: i64 = ls
54 while q < i { if k < ocap - 1 { out[k] = buf[q]; k = k + 1 } q = q + 1 }
55 out[k] = 0 as u8
56 }
57 ls = i + 1
58 }
59 i = i + 1
60 }
61 return found
62}
63
64// grade glyph for a rung from rung_grades buf: writes to both fds
65func td_rung(buf: *i64, gb: *u8, gn: i64, ru: i64) -> i64 {
66 let nm: *u8 = sys_mmap(16)
67 nm[0]=114 as u8; nm[1]=117 as u8; nm[2]=110 as u8; nm[3]=103 as u8; nm[4]=61 as u8 // "rung="
68 nm[5]=82 as u8; nm[6]=(48+ru) as u8; nm[7]=32 as u8; nm[8]=0 as u8 // "RN "
69 let line: *u8 = sys_mmap(512)
70 let ok: i64 = td_last_line(gb, gn, nm, line, 512)
71 let tfd: i64 = buf[0]
72 let hfd: i64 = buf[1]
73 td_w(tfd, " R" as *u8); let d: *u8 = sys_mmap(4); d[0]=(48+ru) as u8; d[1]=0 as u8; td_w(tfd, d)
74 td_w(hfd, "<tr><td>R" as *u8); td_w(hfd, d); td_w(hfd, "</td><td>" as *u8)
75 td_w(tfd, ": " as *u8)
76 // extract grade= token
77 var g: *u8 = "?" as *u8
78 if ok == 1 {
79 let ll: i64 = td_len(line)
80 var p: i64 = 0
81 while p < ll {
82 if td_at(line, ll, p, "grade=" as *u8, 6) == 1 {
83 let s: i64 = p + 6
84 if td_at(line, ll, s, "GREEN" as *u8, 5) == 1 { g = "GREEN" as *u8 }
85 if td_at(line, ll, s, "RED" as *u8, 3) == 1 { g = "RED" as *u8 }
86 if td_at(line, ll, s, "ABSENT" as *u8, 6) == 1 { g = "ABSENT (crater)" as *u8 }
87 p = ll
88 }
89 p = p + 1
90 }
91 } else { g = "no-evidence" as *u8 }
92 td_w(tfd, g); td_w(tfd, "\n" as *u8)
93 td_w(hfd, g); td_w(hfd, "</td></tr>\n" as *u8)
94 return 0
95}
96
97func main() -> i64 {
98 let gb: *u8 = sys_mmap(K_MAGIC_524288)
99 let gn: i64 = td_read("knowledge/status/rung_grades.log" as *u8, gb, K_MAGIC_524288)
100 let qb: *u8 = sys_mmap(K_MAGIC_131072)
101 let qnb: i64 = td_read("knowledge/status/queue_health.log" as *u8, qb, K_MAGIC_131072)
102 let ab: *u8 = sys_mmap(K_MAGIC_131072)
103 let anb: i64 = td_read("knowledge/status/assign_next.log" as *u8, ab, K_MAGIC_131072)
104 let eb: *u8 = sys_mmap(K_MAGIC_131072)
105 let enb: i64 = td_read("knowledge/status/token_efficiency.log" as *u8, eb, K_MAGIC_131072)
106
107 let tfd: i64 = sys_openat_wr("knowledge/status/team_digest.log.tmp" as *u8, 0x1a4)
108 let hfd: i64 = sys_openat_wr("knowledge/team_digest.html.tmp" as *u8, 0x1a4)
109 let fds: *i64 = sys_mmap(16) as *i64
110 fds[0] = tfd
111 fds[1] = hfd
112
113 td_w(hfd, "<!doctype html><html><head><meta charset=utf-8><title>Nishi Team Digest</title>" as *u8)
114 td_w(hfd, "<style>body{font-family:system-ui;max-width:760px;margin:2rem auto;color:#1a1a1a}h2{border-bottom:1px solid #ddd;padding-bottom:.2rem}td{padding:.2rem .6rem}.flag{background:#fff3cd;padding:1rem;border-left:4px solid #e0a800}</style></head><body>" as *u8)
115 td_w(hfd, "<h1>Nishi Team -- what's happening</h1>" as *u8)
116 td_w(tfd, "=== NISHI TEAM DIGEST (black box -> visible; the operator flag) ===\n" as *u8)
117
118 // 1. LADDER
119 td_w(tfd, "\n-- LADDER (graded from gate evidence every beat) --\n" as *u8)
120 td_w(hfd, "<h2>Ladder</h2><table>" as *u8)
121 var ru: i64 = 0
122 while ru < 9 { td_rung(fds, gb, gn, ru); ru = ru + 1 }
123 td_w(hfd, "</table>" as *u8)
124
125 // 2. QUEUE
126 let line: *u8 = sys_mmap(K_MAGIC_1024)
127 td_w(tfd, "\n-- QUEUE --\n " as *u8)
128 td_w(hfd, "<h2>Queue</h2><p>" as *u8)
129 if td_last_line(qb, qnb, "QHEALTH " as *u8, line, K_MAGIC_1024) == 1 {
130 td_w(tfd, line); td_w(tfd, "\n" as *u8)
131 td_w(hfd, line); td_w(hfd, "</p>" as *u8)
132 } else { td_w(tfd, "(no queue-health evidence)\n" as *u8); td_w(hfd, "(none)</p>" as *u8) }
133
134 // 3. NEXT PICK (what the team is about to do)
135 td_w(tfd, "\n-- NEXT (the team's own marching order) --\n " as *u8)
136 td_w(hfd, "<h2>Next</h2><p>" as *u8)
137 if td_last_line(ab, anb, "ASSIGNNEXT " as *u8, line, K_MAGIC_1024) == 1 {
138 td_w(tfd, line); td_w(tfd, "\n" as *u8); td_w(hfd, line); td_w(hfd, "</p>" as *u8)
139 } else { td_w(tfd, "(none)\n" as *u8); td_w(hfd, "(none)</p>" as *u8) }
140
141 // 4. NEEDS YOU (the flag: raised-hand novel work)
142 td_w(tfd, "\n-- NEEDS YOU (raised-hand NOVEL work -- engage only here) --\n " as *u8)
143 td_w(hfd, "<h2>Needs you</h2><div class=flag>" as *u8)
144 if td_last_line(ab, anb, "RAISEDHANDS " as *u8, line, K_MAGIC_1024) == 1 {
145 td_w(tfd, line); td_w(tfd, "\n (briefs ready in knowledge/status/tutor_briefs.log -- batched = one visit)\n" as *u8)
146 td_w(hfd, line); td_w(hfd, "<br>Briefs batched in tutor_briefs.log -- one amortized visit." as *u8)
147 } else { td_w(tfd, "(no raised hands)\n" as *u8); td_w(hfd, "no raised hands" as *u8) }
148 td_w(hfd, "</div>" as *u8)
149
150 // 5. EFFICIENCY trend
151 td_w(tfd, "\n-- EFFICIENCY (better results per visit) --\n " as *u8)
152 td_w(hfd, "<h2>Efficiency</h2><p>" as *u8)
153 if td_last_line(eb, enb, "TOKENMETER " as *u8, line, K_MAGIC_1024) == 1 {
154 td_w(tfd, line); td_w(tfd, "\n" as *u8); td_w(hfd, line); td_w(hfd, "</p>" as *u8)
155 } else { td_w(tfd, "(no meter evidence)\n" as *u8); td_w(hfd, "(none)</p>" as *u8) }
156
157 td_w(hfd, "<p style=color:#888>Sovereign NishiLang->HTML. Refreshed every pulse beat.</p></body></html>\n" as *u8)
158 td_w(tfd, "\n=== END DIGEST ===\n" as *u8)
159 if tfd >= 0 { sys_close(tfd); sys_renameat("knowledge/status/team_digest.log.tmp" as *u8, "knowledge/status/team_digest.log" as *u8) }
160 if hfd >= 0 { sys_close(hfd); sys_renameat("knowledge/team_digest.html.tmp" as *u8, "knowledge/team_digest.html" as *u8) }
161 td_w(1, "TEAMDIGEST written=knowledge/status/team_digest.log+team_digest.html verdict=GREEN\n" as *u8)
162 sys_exit(0)
163 return 0
164}