code wiki / _hdl_build / nx_mmbench.nx
nx_mmbench.nx source
↩ module page · 513 lines · 27351 B
1// nx_mmbench.nx -- THE MEDIA-MANAGER + COMPANION CAPABILITY RULER.
2//
3// WHY: the ecosystem had NO product-grade ruler for either plane. nx_media_census grades the
4// codec/room subsystem; nx_companion_census grades us against the OLD Elder AI platform. Neither
5// answers "how far is our media manager + companion from the products people actually use".
6// Without that number the build order is TASTE. This organ makes it ARITHMETIC.
7//
8// RULER = 12 REAL reference products (Jellyfin/Plex/Emby/Sonarr/qBittorrent/Kavita/yt-dlp/Immich
9// for media; Character.AI/Replika/SillyTavern/ChatGPT-memory for companion). Each declares the
10// capability vector it actually ships. We score OUR organs per capability and COMPUTE (never
11// assert) coverage + a demand-ranked GAP QUEUE. That queue IS the build order.
12//
13// HONEST BY CONSTRUCTION (the anti-author-optimism teeth):
14// - every HAVE must NAME an evidence artifact, and this organ STATS IT AT RUN TIME. A HAVE whose
15// artifact is absent is LIAR-KILLED to GAP -- not warned about, DOWNGRADED. unproven = ABSENT.
16// - a HAVE with NO named evidence is UNGROUNDED and capped at PARTIAL. You cannot assert a win.
17// - coverage is COMPUTED from the surviving rows, so a liar-kill MOVES THE HEADLINE DOWN.
18// - only capabilities some reference product actually ships count toward the denominator, so we
19// cannot inflate the score by inventing axes nobody else has.
20// - scan honesty (law L011): caps_scanned/titles_scanned/coverage_complete are emitted, never implied.
21// Self-contained (imports only nx_syscalls) so it runs on the NAS as an MCP tool.
22// license_tier: ORIGINAL expect_exit: 0
23import "nx_mmbench_lib.nx"
24
25const NC: i64 = 56
26const NT: i64 = 12
27const DOM_MEDIA: i64 = 0
28const DOM_COMP: i64 = 1
29const GAPQ_SHOW: i64 = 14
30
31// register up to 10 capability ids as REQUIRED by reference title t. -1 = unused.
32func nd(mat: *i64, t: i64, a: i64, b: i64, c: i64, d: i64, e: i64, f: i64, g: i64, h: i64, i: i64, j: i64) -> i64 {
33 if a>=0 { mat[t*NC+a]=1 }
34 if b>=0 { mat[t*NC+b]=1 }
35 if c>=0 { mat[t*NC+c]=1 }
36 if d>=0 { mat[t*NC+d]=1 }
37 if e>=0 { mat[t*NC+e]=1 }
38 if f>=0 { mat[t*NC+f]=1 }
39 if g>=0 { mat[t*NC+g]=1 }
40 if h>=0 { mat[t*NC+h]=1 }
41 if i>=0 { mat[t*NC+i]=1 }
42 if j>=0 { mat[t*NC+j]=1 }
43 return 0
44}
45func cp(nm: *i64, dm: *i64, vv: *i64, ev: *i64, id: i64, name: *u8, dom: i64, v: i64, evp: *u8) -> i64 {
46 nm[id]=name as i64; dm[id]=dom; vv[id]=v; ev[id]=evp as i64
47 return 0
48}
49
50// ---- OUR DECLARED VERDICTS. Each HAVE names an artifact; main() stats it and liar-kills a false claim.
51func reg_media(nm: *i64, dm: *i64, vv: *i64, ev: *i64) -> i64 {
52 let NONE: *u8 = 0 as *u8
53 cp(nm,dm,vv,ev, 0,"library-scan-catalog" as *u8, DOM_MEDIA,V_HAVE,"/volume1/ai/galx/nx_media_ingest_pipeline.elf" as *u8)
54 cp(nm,dm,vv,ev, 1,"content-dedup-cid" as *u8, DOM_MEDIA,V_HAVE,"knowledge/store/mvault-manifest.txt" as *u8)
55 cp(nm,dm,vv,ev, 2,"incremental-rescan-resume" as *u8, DOM_MEDIA,V_HAVE,"knowledge/store/mvaultpath-manifest.txt" as *u8)
56 // BUILT + GATE-PROVEN 6/6 (nx_media_extract_gate: HLS, escaped-JSON, embedded-state, negative
57 // control) but DEPLOYED NOWHERE -> reg_wire omits it -> scores GAP for coverage. This row is the
58 // clearest instance of the built-vs-wired delta the second dimension exists to expose.
59 cp(nm,dm,vv,ev, 3,"metadata-scrape" as *u8, DOM_MEDIA,V_HAVE,"buildroot/runtime/_hdl_build/nx_media_extract.nx" as *u8)
60 cp(nm,dm,vv,ev, 4,"cover-art-poster" as *u8, DOM_MEDIA,V_HAVE,"/volume1/logging/uwunikaa" as *u8)
61 cp(nm,dm,vv,ev, 5,"thumbnail-generate" as *u8, DOM_MEDIA,V_HAVE,"/volume1/ai/galx/nx_galx_thumb.elf" as *u8)
62 cp(nm,dm,vv,ev, 6,"thumbnail-prewarm-at-scale" as *u8,DOM_MEDIA,V_PART,"/volume1/ai/galx/galx_pipeline.log" as *u8)
63 cp(nm,dm,vv,ev, 7,"trickplay-scrub-sprites" as *u8, DOM_MEDIA,V_HAVE,"/volume1/logging/uwunikaa" as *u8)
64 cp(nm,dm,vv,ev, 8,"keyframe-seek-index" as *u8, DOM_MEDIA,V_PART,"/volume1/ai/galx/nx_ts_index.elf" as *u8)
65 cp(nm,dm,vv,ev, 9,"seek-index-backfill-at-scale" as *u8,DOM_MEDIA,V_PART,"/volume1/ai/galx/nx_galx_idx_backfill.elf" as *u8)
66 cp(nm,dm,vv,ev,10,"duration-index" as *u8, DOM_MEDIA,V_HAVE,"/volume1/ai/galx/galx_durindex.log" as *u8)
67 cp(nm,dm,vv,ev,11,"remux-fmp4-cmaf" as *u8, DOM_MEDIA,V_HAVE,"/volume1/ai/galx/nx_ts2fmp4.elf" as *u8)
68 cp(nm,dm,vv,ev,12,"matroska-remux" as *u8, DOM_MEDIA,V_HAVE,"/volume1/ai/galx/nx_mkv2fmp4.elf" as *u8)
69 cp(nm,dm,vv,ev,13,"hevc-h265-index" as *u8, DOM_MEDIA,V_GAP,NONE)
70 cp(nm,dm,vv,ev,14,"adaptive-bitrate-ladder" as *u8, DOM_MEDIA,V_GAP,NONE)
71 cp(nm,dm,vv,ev,15,"range-request-serve" as *u8, DOM_MEDIA,V_HAVE,"/volume1/ai/galx/nx_gallery_serve.elf" as *u8)
72 cp(nm,dm,vv,ev,16,"resume-watch-state" as *u8, DOM_MEDIA,V_GAP,NONE)
73 cp(nm,dm,vv,ev,17,"subtitle-tracks" as *u8, DOM_MEDIA,V_GAP,NONE)
74 cp(nm,dm,vv,ev,18,"audio-track-select" as *u8, DOM_MEDIA,V_GAP,NONE)
75 cp(nm,dm,vv,ev,19,"faceted-browse" as *u8, DOM_MEDIA,V_PART,"/volume1/ai/galx/nx_gallery_gateway.elf" as *u8)
76 cp(nm,dm,vv,ev,20,"library-fulltext-search" as *u8, DOM_MEDIA,V_PART,NONE)
77 cp(nm,dm,vv,ev,21,"collections-series" as *u8, DOM_MEDIA,V_GAP,NONE)
78 return 0
79}
80func reg_media2(nm: *i64, dm: *i64, vv: *i64, ev: *i64) -> i64 {
81 let NONE: *u8 = 0 as *u8
82 cp(nm,dm,vv,ev,22,"torrent-leech" as *u8, DOM_MEDIA,V_PART,"nx_torrent_leech_probe.elf" as *u8)
83 cp(nm,dm,vv,ev,23,"torrent-seed" as *u8, DOM_MEDIA,V_HAVE,"nx_torrent_seed.elf" as *u8)
84 cp(nm,dm,vv,ev,24,"dht-magnet" as *u8, DOM_MEDIA,V_HAVE,"nx_torrent_mkinfo.elf" as *u8)
85 cp(nm,dm,vv,ev,25,"tracker-multi" as *u8, DOM_MEDIA,V_HAVE,"buildroot/runtime/torrent_trackers.txt" as *u8)
86 // 2026-07-26: PARTIAL+dark -> HAVE+wired. nx_feed_extract (RSS 2.0 + Atom parser, in-tree since
87 // 07-05) was a LIBRARY with no main(), so nothing could call it. Wrote nx_feedfetch, the missing
88 // CLI consumer, and PROVED BOTH PATHS on live sites: reddit .rss -> 25 items parsed; lwn.net page
89 // shell -> discovered /headlines/rss -> 15 items. ⚠I had earlier published that this organ was
90 // "deploy work, not build work" -- WRONG: a library cannot be deployed into reachability.
91 cp(nm,dm,vv,ev,26,"rss-auto-acquire" as *u8, DOM_MEDIA,V_HAVE,"buildroot/runtime/_hdl_build/nx_feed_extract.nx" as *u8)
92 cp(nm,dm,vv,ev,27,"download-queue-manager" as *u8, DOM_MEDIA,V_PART,NONE)
93 cp(nm,dm,vv,ev,28,"site-scraper-adapters" as *u8, DOM_MEDIA,V_PART,"buildroot/runtime/_hdl_build/nx_archive_capture.nx" as *u8)
94 cp(nm,dm,vv,ev,29,"manga-multipage-reader" as *u8, DOM_MEDIA,V_GAP,NONE)
95 cp(nm,dm,vv,ev,30,"auth-gated-access" as *u8, DOM_MEDIA,V_HAVE,"/volume1/ai/galx/nx_gallery_gateway.elf" as *u8)
96 cp(nm,dm,vv,ev,31,"multi-user-profiles" as *u8, DOM_MEDIA,V_GAP,NONE)
97 cp(nm,dm,vv,ev,32,"watch-history" as *u8, DOM_MEDIA,V_GAP,NONE)
98 cp(nm,dm,vv,ev,33,"dup-reclaim-report" as *u8, DOM_MEDIA,V_HAVE,"knowledge/store/mvault-manifest.txt" as *u8)
99 cp(nm,dm,vv,ev,34,"live-dvr-record" as *u8, DOM_MEDIA,V_HAVE,"/volume1/logging/uwunikaa" as *u8)
100 cp(nm,dm,vv,ev,35,"image-upscale" as *u8, DOM_MEDIA,V_HAVE,"/volume1/ai/galx/nx_galx_upscale.elf" as *u8)
101 cp(nm,dm,vv,ev,36,"responsive-mobile-ui" as *u8, DOM_MEDIA,V_PART,NONE)
102 cp(nm,dm,vv,ev,37,"client-api" as *u8, DOM_MEDIA,V_HAVE,"/volume1/ai/galx/nx_gallery_gateway.elf" as *u8)
103 return 0
104}
105
106func reg_comp(nm: *i64, dm: *i64, vv: *i64, ev: *i64) -> i64 {
107 let NONE: *u8 = 0 as *u8
108 cp(nm,dm,vv,ev,38,"persona-data-driven" as *u8, DOM_COMP,V_HAVE,"/volume1/ai/gen/elara_appearance.txt" as *u8)
109 cp(nm,dm,vv,ev,39,"persistent-memory" as *u8, DOM_COMP,V_HAVE,"/volume1/ai/gen/elara_mem.log" as *u8)
110 cp(nm,dm,vv,ev,40,"memory-consolidation-dream" as *u8,DOM_COMP,V_GAP,NONE)
111 cp(nm,dm,vv,ev,41,"emotion-state-model" as *u8, DOM_COMP,V_HAVE,"/volume1/ai/gen/elara_state.txt" as *u8)
112 cp(nm,dm,vv,ev,42,"state-drives-voice" as *u8, DOM_COMP,V_HAVE,"/volume1/ai/gen/elara_state.txt" as *u8)
113 cp(nm,dm,vv,ev,43,"state-drives-visuals" as *u8, DOM_COMP,V_HAVE,"/volume1/ai/gen/elara_shots.txt" as *u8)
114 cp(nm,dm,vv,ev,44,"day-arc-life-sim" as *u8, DOM_COMP,V_PART,NONE)
115 cp(nm,dm,vv,ev,45,"proactive-initiation" as *u8, DOM_COMP,V_GAP,NONE)
116 cp(nm,dm,vv,ev,46,"identity-locked-gen" as *u8, DOM_COMP,V_PART,"/volume1/ai/gen/elara_loras.txt" as *u8)
117 cp(nm,dm,vv,ev,47,"in-chat-photo-gen" as *u8, DOM_COMP,V_HAVE,"/volume1/ai/gen/nx_gen_live_probe.elf" as *u8)
118 cp(nm,dm,vv,ev,48,"async-batch-gen" as *u8, DOM_COMP,V_PART,"/volume1/ai/gen/batchjob-1030448077.json" as *u8)
119 cp(nm,dm,vv,ev,49,"voice-tts" as *u8, DOM_COMP,V_GAP,NONE)
120 cp(nm,dm,vv,ev,50,"voice-input-stt" as *u8, DOM_COMP,V_GAP,NONE)
121 cp(nm,dm,vv,ev,51,"relationship-progression" as *u8, DOM_COMP,V_PART,NONE)
122 cp(nm,dm,vv,ev,52,"multi-character" as *u8, DOM_COMP,V_GAP,NONE)
123 cp(nm,dm,vv,ev,53,"cross-device-continuity" as *u8, DOM_COMP,V_HAVE,"/volume1/ai/gen/elara_mem.log" as *u8)
124 cp(nm,dm,vv,ev,54,"companion-ui-surface" as *u8, DOM_COMP,V_HAVE,"/volume1/ai/gen/elara_ui.html" as *u8)
125 cp(nm,dm,vv,ev,55,"self-heal-keeper" as *u8, DOM_COMP,V_HAVE,"/volume1/ai/gen/gen_keeper.sh" as *u8)
126 return 0
127}
128// ---- DEPLOYMENT MAP: which capabilities have their implementation ON THE LIVE HOST.
129// A capability missing from this list is DARK: it may be fully built and gate-proven in the source
130// tree, but the product cannot reach it, so it scores GAP for coverage. The BUILT-vs-WIRED delta is
131// the migration backlog, stated as a number instead of a feeling.
132func wr(w: *i64, id: i64, p: *u8) -> i64 { w[id]=p as i64; return 0 }
133// STRONG WIRING: name the LIVE SERVING BINARY and the string that proves it reaches this organ.
134// Where a pair is registered, mere deployment is no longer enough -- the serving binary must actually
135// reference the organ, or the capability is DARK however present its files are.
136func sv(sb: *i64, nd: *i64, id: i64, binpath: *u8, needle: *u8) -> i64 { sb[id]=binpath as i64; nd[id]=needle as i64; return 0 }
137func reg_serving(sb: *i64, nd: *i64) -> i64 {
138 // VERIFIED on the live host before registering: nx_gallery_serve.elf contains the literal fork path.
139 sv(sb,nd, 8,"/volume1/ai/galx/nx_gallery_serve.elf" as *u8,"nx_ts_index.elf" as *u8)
140 sv(sb,nd,11,"/volume1/ai/galx/nx_gallery_serve.elf" as *u8,"nx_ts2fmp4.elf" as *u8)
141 sv(sb,nd, 9,"/volume1/ai/galx/nx_galx_idx_backfill.elf" as *u8,"nx_ts_index.elf" as *u8)
142 sv(sb,nd, 5,"/volume1/ai/galx/nx_media_ingest_pipeline.elf" as *u8,"nx_galx_thumb" as *u8)
143 sv(sb,nd,12,"/volume1/ai/galx/nx_gallery_serve.elf" as *u8,"nx_mkv2fmp4.elf" as *u8)
144 sv(sb,nd,35,"/volume1/ai/galx/nx_gallery_serve.elf" as *u8,"nx_galx_upscale" as *u8)
145 return 0
146}
147func reg_wire(w: *i64) -> i64 {
148 wr(w, 0,"/volume1/ai/galx/nx_media_ingest_pipeline.elf" as *u8)
149 wr(w, 1,"knowledge/store/mvault-manifest.txt" as *u8)
150 wr(w, 2,"knowledge/store/mvaultpath-manifest.txt" as *u8)
151 // 2026-07-25: metadata-scrape moved DARK -> WIRED. nx_yt_probe (which imports mx_extract) is now
152 // built, promoted and registered as the MCP tool nx_media_probe, and was PROVEN on a live page:
153 // archive.org fetched over our own TLS (200, 192734B) -> best media URL at confidence 90 + title
154 // "Big Buck Bunny : Free Download...". Per the declared floor this counts as WIRED (deployed and
155 // callable). It is NOT yet invoked by the ingest pipeline -- that wiring is the next rung.
156 wr(w, 3,"nx_yt_probe.elf" as *u8)
157 wr(w,26,"nx_feedfetch.elf" as *u8) // rss-auto-acquire: live-proven on reddit + lwn.net feeds
158 wr(w, 4,"/volume1/logging/uwunikaa" as *u8)
159 wr(w, 5,"/volume1/ai/galx/nx_galx_thumb.elf" as *u8)
160 wr(w, 6,"/volume1/ai/galx/nx_galx_thumb_prewarm.elf" as *u8)
161 wr(w, 7,"/volume1/logging/uwunikaa" as *u8)
162 wr(w, 8,"/volume1/ai/galx/nx_ts_index.elf" as *u8)
163 wr(w, 9,"/volume1/ai/galx/nx_galx_idx_backfill.elf" as *u8)
164 wr(w,10,"/volume1/ai/galx/nx_galx_durindex.elf" as *u8)
165 wr(w,11,"/volume1/ai/galx/nx_ts2fmp4.elf" as *u8)
166 wr(w,12,"/volume1/ai/galx/nx_mkv2fmp4.elf" as *u8)
167 wr(w,15,"/volume1/ai/galx/nx_gallery_serve.elf" as *u8)
168 wr(w,19,"/volume1/ai/galx/nx_gallery_gateway.elf" as *u8)
169 wr(w,22,"nx_torrent_leech_probe.elf" as *u8)
170 wr(w,23,"nx_torrent_seed.elf" as *u8)
171 wr(w,24,"nx_torrent_mkinfo.elf" as *u8)
172 wr(w,25,"nx_torrent_seed.elf" as *u8)
173 wr(w,30,"/volume1/ai/galx/nx_gallery_gateway.elf" as *u8)
174 wr(w,33,"knowledge/store/mvault-manifest.txt" as *u8)
175 wr(w,34,"/volume1/logging/uwunikaa" as *u8)
176 wr(w,35,"/volume1/ai/galx/nx_galx_upscale.elf" as *u8)
177 wr(w,37,"/volume1/ai/galx/nx_gallery_gateway.elf" as *u8)
178 wr(w,38,"/volume1/ai/gen/elara_appearance.txt" as *u8)
179 wr(w,39,"/volume1/ai/gen/elara_mem.log" as *u8)
180 wr(w,41,"/volume1/ai/gen/elara_state.txt" as *u8)
181 wr(w,42,"/volume1/ai/gen/elara_state.txt" as *u8)
182 wr(w,43,"/volume1/ai/gen/elara_shots.txt" as *u8)
183 wr(w,46,"/volume1/ai/gen/elara_loras.txt" as *u8)
184 wr(w,47,"/volume1/ai/gen/nx_gen_live_probe.elf" as *u8)
185 wr(w,48,"/volume1/ai/gen/batchjob-1030448077.json" as *u8)
186 wr(w,53,"/volume1/ai/gen/elara_mem.log" as *u8)
187 wr(w,54,"/volume1/ai/gen/elara_ui.html" as *u8)
188 wr(w,55,"/volume1/ai/gen/gen_keeper.sh" as *u8)
189 return 0
190}
191
192// ---- THE BAR: 12 real reference products and the capability vector each actually ships.
193// A capability NO reference product ships is excluded from the denominator by construction, so we
194// cannot inflate coverage by inventing axes nobody else has.
195func reg_titles(tnm: *i64, tdm: *i64, mat: *i64) -> i64 {
196 tnm[0]="Jellyfin" as i64; tdm[0]=DOM_MEDIA
197 nd(mat,0, 0, 3, 4, 5, 6, 7, 8, 9,10,11)
198 nd(mat,0,12,13,14,15,16,17,18,19,20,21)
199 nd(mat,0,30,31,32,34,36,37,-1,-1,-1,-1)
200 tnm[1]="Plex" as i64; tdm[1]=DOM_MEDIA
201 nd(mat,1, 0, 3, 4, 5, 6, 7, 8, 9,10,11)
202 nd(mat,1,12,13,14,15,16,17,18,19,20,21)
203 nd(mat,1,30,31,32,34,36,37,-1,-1,-1,-1)
204 tnm[2]="Emby" as i64; tdm[2]=DOM_MEDIA
205 nd(mat,2, 0, 3, 4, 5, 7, 8,10,11,12,13)
206 nd(mat,2,14,15,16,17,18,19,20,21,30,31)
207 nd(mat,2,32,34,36,37,-1,-1,-1,-1,-1,-1)
208 tnm[3]="Sonarr-Radarr" as i64; tdm[3]=DOM_MEDIA
209 nd(mat,3, 0, 3, 4,21,26,27,30,37,-1,-1)
210 tnm[4]="qBittorrent" as i64; tdm[4]=DOM_MEDIA
211 nd(mat,4,22,23,24,25,26,27,30,37,-1,-1)
212 tnm[5]="Kavita-Komga" as i64; tdm[5]=DOM_MEDIA
213 nd(mat,5, 0, 3, 4, 5,19,20,21,29,30,31)
214 nd(mat,5,32,36,37,-1,-1,-1,-1,-1,-1,-1)
215 tnm[6]="yt-dlp" as i64; tdm[6]=DOM_MEDIA
216 nd(mat,6, 3,27,28,37,-1,-1,-1,-1,-1,-1)
217 tnm[7]="Immich" as i64; tdm[7]=DOM_MEDIA
218 nd(mat,7, 0, 1, 2, 4, 5,19,20,30,31,33)
219 nd(mat,7,36,37,-1,-1,-1,-1,-1,-1,-1,-1)
220 tnm[8]="Character.AI" as i64; tdm[8]=DOM_COMP
221 nd(mat,8,38,39,44,45,46,47,51,52,53,54)
222 tnm[9]="Replika" as i64; tdm[9]=DOM_COMP
223 nd(mat,9,38,39,40,41,42,43,44,45,46,47)
224 nd(mat,9,49,50,51,53,54,-1,-1,-1,-1,-1)
225 tnm[10]="SillyTavern" as i64; tdm[10]=DOM_COMP
226 nd(mat,10,38,39,40,43,46,47,49,52,53,54)
227 tnm[11]="ChatGPT-memory" as i64; tdm[11]=DOM_COMP
228 nd(mat,11,39,40,47,53,54,-1,-1,-1,-1,-1)
229 return 0
230}
231func main(argc: i64, argv: *i64) -> i64 {
232 let capnm: *i64 = sys_mmap(NC*8) as *i64
233 let capdm: *i64 = sys_mmap(NC*8) as *i64
234 let capv: *i64 = sys_mmap(NC*8) as *i64
235 let capev: *i64 = sys_mmap(NC*8) as *i64
236 let capf: *i64 = sys_mmap(NC*8) as *i64
237 let capdd: *i64 = sys_mmap(NC*8) as *i64
238 let capfl: *i64 = sys_mmap(NC*8) as *i64
239 let gq: *i64 = sys_mmap(NC*8) as *i64
240 let capwr: *i64 = sys_mmap(NC*8) as *i64 // deployment artifact (0 = DARK)
241 let capsb: *i64 = sys_mmap(NC*8) as *i64 // live serving binary (0 = no strong test available)
242 let capnd: *i64 = sys_mmap(NC*8) as *i64 // needle proving the serving binary reaches the organ
243 let capwv: *i64 = sys_mmap(NC*8) as *i64 // wiring verdict, computed ONCE (binary scans are costly)
244 let capu: *i64 = sys_mmap(NC*8) as *i64 // USABLE verdict = built verdict gated by wiring
245 let tnm: *i64 = sys_mmap(NT*8) as *i64
246 let tdm: *i64 = sys_mmap(NT*8) as *i64
247 let mat: *i64 = sys_mmap(NT*NC*8) as *i64
248 var z: i64 = 0
249 while z<NC { capnm[z]=0; capdm[z]=0; capv[z]=0; capev[z]=0; capf[z]=0; capdd[z]=0; capfl[z]=0; gq[z]=0; capwr[z]=0; capu[z]=0; capsb[z]=0; capnd[z]=0; capwv[z]=0; z=z+1 }
250 z=0
251 while z<NT { tnm[z]=0; tdm[z]=0; z=z+1 }
252 z=0
253 while z<NT*NC { mat[z]=0; z=z+1 }
254
255 var want_json: i64 = 0
256 var want_gapq: i64 = 0
257 if argc>1 {
258 if streq(argv[1] as *u8, "json" as *u8)==1 { want_json=1 }
259 if streq(argv[1] as *u8, "gapq" as *u8)==1 { want_gapq=1 }
260 }
261
262 reg_media(capnm,capdm,capv,capev)
263 reg_media2(capnm,capdm,capv,capev)
264 reg_comp(capnm,capdm,capv,capev)
265 reg_wire(capwr)
266 reg_serving(capsb,capnd)
267 reg_titles(tnm,tdm,mat)
268
269 // ---- DEMAND: how many reference products ship this capability. Demand IS the ranking weight.
270 var c: i64 = 0
271 while c<NC {
272 var t: i64 = 0
273 var d: i64 = 0
274 while t<NT { if mat[t*NC+c]==1 { d=d+1 } t=t+1 }
275 capdd[c]=d
276 c=c+1
277 }
278
279 // ---- EVIDENCE AUDIT (the liar-kill). Runs BEFORE any number is computed, so a false claim
280 // cannot reach the headline. flag 1 = artifact named but ABSENT -> GAP. flag 2 = HAVE with no
281 // artifact named at all -> capped PARTIAL (you may not assert an unproven win).
282 var killed: i64 = 0
283 var ungrounded: i64 = 0
284 c = 0
285 var r: i64 = 0
286 while c<NC {
287 r = aud(capv[c], capev[c])
288 capf[c]=r/10
289 capfl[c]=r%10
290 if capfl[c]==1 { killed=killed+1 }
291 if capfl[c]==2 { ungrounded=ungrounded+1 }
292 capwv[c]=wired_ref(capwr[c], capsb[c], capnd[c])
293 capu[c]=capf[c]
294 if capwv[c]==0 { capu[c]=V_GAP }
295 c=c+1
296 }
297 // DARK = built to some degree but not reachable from the live host. This count is the migration
298 // backlog: code we already own and already paid for, that no user can currently touch.
299 var dark: i64 = 0
300 c=0
301 while c<NC {
302 if capdd[c]>=1 {
303 // DARK requires ACTUAL BUILD EVIDENCE. A capability with no artifact named is merely
304 // unevidenced -- calling it "built but not deployed" would overstate what we own, which
305 // is the same author-optimism this ruler exists to prevent. (Evidence named-but-absent is
306 // already liar-killed to GAP upstream, so capev!=0 here means the artifact really exists.)
307 if capev[c]!=0 {
308 if capf[c]>V_GAP {
309 if capwv[c]==0 { dark=dark+1 }
310 }
311 }
312 }
313 c=c+1
314 }
315
316 // ---- COVERAGE over DEMANDED capabilities only (axes no reference product ships are excluded).
317 var sc: i64=0
318 var mx: i64=0
319 var scm: i64=0
320 var mxm: i64=0
321 var scc: i64=0
322 var mxc: i64=0
323 var ndem: i64=0
324 var nours: i64=0
325 var scb: i64=0
326 c=0
327 while c<NC {
328 if capdd[c]==0 { nours=nours+1 }
329 if capdd[c]>=1 {
330 ndem=ndem+1
331 // HEADLINE COVERAGE USES THE *USABLE* VERDICT, not the built one. A capability the
332 // product cannot reach does not count, however good its code is.
333 sc=sc+capu[c]; mx=mx+2
334 scb=scb+capf[c]
335 if capdm[c]==DOM_MEDIA { scm=scm+capu[c]; mxm=mxm+2 }
336 if capdm[c]==DOM_COMP { scc=scc+capu[c]; mxc=mxc+2 }
337 }
338 c=c+1
339 }
340 var perm: i64=0
341 var permm: i64=0
342 var permc: i64=0
343 var permb: i64=0
344 if mx>0 { perm = sc*1000/mx }
345 if mx>0 { permb = scb*1000/mx }
346 if mxm>0 { permm = scm*1000/mxm }
347 if mxc>0 { permc = scc*1000/mxc }
348
349 // ---- GAP QUEUE: demanded caps we do not fully have, ranked by demand desc (breadth = urgency).
350 var ng: i64=0
351 c=0
352 while c<NC {
353 if capdd[c]>=1 {
354 if capu[c]<V_HAVE { gq[ng]=c; ng=ng+1 }
355 }
356 c=c+1
357 }
358 var gi: i64=0
359 var tmp: i64=0
360 while gi<ng {
361 var best: i64=gi
362 var gj: i64=gi+1
363 while gj<ng {
364 var swapit: i64=0
365 if capdd[gq[gj]] > capdd[gq[best]] { swapit=1 }
366 if capdd[gq[gj]] == capdd[gq[best]] {
367 if capu[gq[gj]] < capu[gq[best]] { swapit=1 }
368 }
369 if swapit==1 { best=gj }
370 gj=gj+1
371 }
372 tmp=gq[gi]; gq[gi]=gq[best]; gq[best]=tmp
373 gi=gi+1
374 }
375 // ---- EMIT ------------------------------------------------------------------------
376 if want_json==1 {
377 sw("{\"organ\":\"nx_mmbench\",\"coverage_permil\":" as *u8); sn(perm)
378 sw(",\"built_permil\":" as *u8); sn(permb)
379 sw(",\"dark_caps\":" as *u8); sn(dark)
380 sw(",\"media_permil\":" as *u8); sn(permm)
381 sw(",\"companion_permil\":" as *u8); sn(permc)
382 sw(",\"caps_scanned\":" as *u8); sn(NC)
383 sw(",\"caps_demanded\":" as *u8); sn(ndem)
384 sw(",\"caps_ours_only\":" as *u8); sn(nours)
385 sw(",\"titles_scanned\":" as *u8); sn(NT)
386 sw(",\"liar_killed\":" as *u8); sn(killed)
387 sw(",\"ungrounded\":" as *u8); sn(ungrounded)
388 sw(",\"coverage_complete\":1,\"gap_queue\":[" as *u8)
389 var q: i64=0
390 while q<ng {
391 if q>0 { sw("," as *u8) }
392 sw("{\"cap\":\"" as *u8); sw(capnm[gq[q]] as *u8)
393 sw("\",\"demand\":" as *u8); sn(capdd[gq[q]])
394 sw(",\"usable\":\"" as *u8); sw(vstr(capu[gq[q]]))
395 sw("\",\"built\":\"" as *u8); sw(vstr(capf[gq[q]]))
396 // Must use the SAME definition as the dark_caps headline, or a consumer reading these
397 // rows would count every unevidenced gap as "already built" and wildly overstate what we own.
398 sw("\",\"dark\":" as *u8)
399 var dk: i64 = 0
400 if capev[gq[q]]!=0 {
401 if capf[gq[q]]>V_GAP {
402 if capwv[gq[q]]==0 { dk=1 }
403 }
404 }
405 if dk==1 { sw("1" as *u8) } else { sw("0" as *u8) }
406 sw("}" as *u8)
407 q=q+1
408 }
409 sw("]}\n" as *u8)
410 return 0
411 }
412
413 if want_gapq==0 {
414 sw("=== nx_mmbench -- MEDIA-MANAGER + COMPANION capability ruler vs 12 real reference products ===\n" as *u8)
415 sw("bar = what each product actually ships. Every verdict is COMPUTED, never asserted. A HAVE must\n" as *u8)
416 sw("name an evidence artifact that EXISTS ON DISK NOW -- an absent artifact is LIAR-KILLED to GAP,\n" as *u8)
417 sw("which MOVES THE HEADLINE DOWN. Capabilities no reference product ships are excluded from the\n" as *u8)
418 sw("denominator, so coverage cannot be inflated with invented axes.\n\n" as *u8)
419 sw("-- PER-CAPABILITY (demanded by at least one reference product) --\n" as *u8)
420 var c2: i64=0
421 while c2<NC {
422 if capdd[c2]>=1 {
423 sw(" [" as *u8); sw(vstr(capu[c2])); sw("]\t" as *u8)
424 if capdm[c2]==DOM_MEDIA { sw("media\t" as *u8) }
425 if capdm[c2]==DOM_COMP { sw("comp \t" as *u8) }
426 sw(capnm[c2] as *u8)
427 sw(" demand=" as *u8); sn(capdd[c2])
428 if capfl[c2]==1 {
429 sw(" <== LIAR-KILLED, evidence absent: " as *u8); sw(capev[c2] as *u8)
430 }
431 if capfl[c2]==2 {
432 sw(" [UNGROUNDED: HAVE with no named artifact -> capped PARTIAL]" as *u8)
433 }
434 if capev[c2]!=0 {
435 if capf[c2]>V_GAP {
436 if capwv[c2]==0 {
437 sw(" <== DARK: built=" as *u8); sw(vstr(capf[c2]))
438 sw(" but deployed NOWHERE, so it counts as GAP" as *u8)
439 }
440 }
441 }
442 sw("\n" as *u8)
443 }
444 c2=c2+1
445 }
446 sw("\n-- OURS-ONLY (we ship it, no reference product does -- EXCLUDED from the denominator) --\n" as *u8)
447 c2=0
448 while c2<NC {
449 if capdd[c2]==0 {
450 sw(" [" as *u8); sw(vstr(capf[c2])); sw("]\t" as *u8); sw(capnm[c2] as *u8); sw("\n" as *u8)
451 }
452 c2=c2+1
453 }
454 sw("\n-- PER-REFERENCE-PRODUCT READINESS (how much of THIS product we could stand in for) --\n" as *u8)
455 var t2: i64=0
456 while t2<NT {
457 var need: i64=0
458 var got: i64=0
459 var c3: i64=0
460 while c3<NC {
461 if mat[t2*NC+c3]==1 { need=need+1; got=got+capu[c3] }
462 c3=c3+1
463 }
464 var rp: i64=0
465 if need>0 { rp = got*1000/(need*2) }
466 sw(" " as *u8); sw(tnm[t2] as *u8); sw("\t" as *u8); sn(rp); sw(" permil (caps " as *u8); sn(need); sw(")\n" as *u8)
467 t2=t2+1
468 }
469 sw("\n" as *u8)
470 }
471
472 sw("-- GAP QUEUE = THE BUILD ORDER (demand-ranked: a gap N products ship outranks one 1 ships) --\n" as *u8)
473 var q2: i64=0
474 while q2<ng {
475 if q2<GAPQ_SHOW {
476 sw(" " as *u8); sn(q2+1); sw(". " as *u8); sw(capnm[gq[q2]] as *u8)
477 sw("\tdemand=" as *u8); sn(capdd[gq[q2]])
478 sw("\tnow=" as *u8); sw(vstr(capu[gq[q2]]))
479 if capfl[gq[q2]]==1 { sw("\t(was claimed HAVE, liar-killed)" as *u8) }
480 if capev[gq[q2]]!=0 {
481 if capf[gq[q2]]>V_GAP {
482 if capwv[gq[q2]]==0 {
483 sw("\t<== DARK: already built=" as *u8); sw(vstr(capf[gq[q2]]))
484 sw(", needs DEPLOY not code" as *u8)
485 }
486 }
487 }
488 sw("\n" as *u8)
489 }
490 q2=q2+1
491 }
492 if ng>GAPQ_SHOW { sw(" ... " as *u8); sn(ng-GAPQ_SHOW); sw(" more open gaps not shown (queue is complete, display is capped)\n" as *u8) }
493
494 if want_gapq==0 {
495 sw("\n-- HEADLINE (computed) --\n" as *u8)
496 sw(" coverage_permil=" as *u8); sn(perm)
497 sw(" media=" as *u8); sn(permm)
498 sw(" companion=" as *u8); sn(permc); sw("\n" as *u8)
499 sw(" built_permil=" as *u8); sn(permb)
500 sw(" dark_caps=" as *u8); sn(dark)
501 sw(" <- BUILT counts code that exists; COVERAGE counts only what the product can reach.\n" as *u8)
502 sw(" The gap between them is the migration backlog: capability already paid for, not wired.\n" as *u8)
503 sw(" caps_scanned=" as *u8); sn(NC)
504 sw(" caps_demanded=" as *u8); sn(ndem)
505 sw(" caps_ours_only=" as *u8); sn(nours)
506 sw(" titles_scanned=" as *u8); sn(NT)
507 sw(" coverage_complete=1\n" as *u8)
508 sw(" liar_killed=" as *u8); sn(killed)
509 sw(" ungrounded=" as *u8); sn(ungrounded)
510 sw(" open_gaps=" as *u8); sn(ng); sw("\n" as *u8)
511 }
512 return 0
513}