nx_galx_media_census.nx source
↩ module page · 153 lines · 7928 B
1// nx_galx_media_census.nx -- SOVEREIGN media-delivery census for the gallery (operator 2026-06-23:
2// "most of the media wasnt working its not fast its not ai upscaling on demand ... dont use sh use our
3// own nishi ecosystem"). Replaces the sh recon with a sovereign organ: reads the LIVE NAS state directly
4// via syscalls (the NAS is mounted at /mnt/nas_ai = /volume1/ai on the box), samples coverage per media
5// type, classifies WORKING/DEGRADED. No sh, no pipelines. license_tier: ORIGINAL
6//
7// IMAGE THUMBS : thumbs/<cid>.jpg present? (cold => /thumb falls back to full-res = slow grid)
8// VIDEO POSTERS : <video>-poster.jpg present? (absent => /vidthumb 404 = blank video tile = "not working")
9import "nx_syscalls.nx"
10import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
11const MC_MAGIC_2048: i64 = 2048
12
13const MC_CAP: i64 = 524288 // 512KB bounded prefix (flaky-SMB tolerant; enough for the sample)
14const MC_SAMPLES: i64 = 60
15const MC_BASE: *u8 = "/mnt/nas_ai/galx"
16
17func mc_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
18func mc_puts(s: *u8) -> i64 { sys_write(1, s, mc_strlen(s)); return 0 }
19// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
20// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
21// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
22// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
23func mc_putn(v: i64) -> i64 { nxi_out(v); return 0 }
24func mc_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 }
25
26func mc_find(buf: *u8, lo: i64, hi: i64, pat: *u8, pl: i64) -> i64 {
27 if pl == 0 { return 0 - 1 }
28 var i: i64 = lo
29 while i + pl <= hi {
30 var j: i64 = 0
31 while j < pl { if buf[i + j] != pat[j] { j = pl + 1 } else { j = j + 1 } }
32 if j == pl { return i }
33 i = i + 1
34 }
35 return 0 - 1
36}
37
38func mc_read_prefix(path: *u8, buf: *u8, cap: i64) -> i64 {
39 let fd: i64 = sys_openat_rd(path)
40 if fd < 0 { return 0 - 1 }
41 let n: i64 = sys_read(fd, buf, cap)
42 sys_close(fd)
43 return n
44}
45func mc_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
46
47// IMAGE THUMBS: each view_index line is a 69-char cid; check /mnt/nas_ai/galx/thumbs/<cid>.jpg
48func mc_sample_thumbs(buf: *u8, n: i64, out_tot: *i64) -> i64 {
49 var have: i64 = 0; var tot: i64 = 0
50 var i: i64 = 0; var ls: i64 = 0
51 while i <= n {
52 var eol: i64 = 0
53 if i == n { eol = 1 } else { if buf[i] == (10 as u8) { eol = 1 } }
54 if eol == 1 {
55 if tot < MC_SAMPLES {
56 var ce: i64 = i
57 if ce > ls { if buf[ce - 1] == (13 as u8) { ce = ce - 1 } } // strip CR
58 if ce - ls >= 10 {
59 let p: *u8 = sys_mmap(512)
60 var o: i64 = mc_cat(p, 0, MC_BASE)
61 o = mc_cat(p, o, "/thumbs/" as *u8)
62 var k: i64 = ls
63 while k < ce { p[o] = buf[k]; o = o + 1; k = k + 1 }
64 o = mc_cat(p, o, ".jpg" as *u8); p[o] = 0 as u8
65 tot = tot + 1
66 if mc_exists(p) == 1 { have = have + 1 }
67 }
68 }
69 ls = i + 1
70 }
71 i = i + 1
72 }
73 out_tot[0] = tot
74 return have
75}
76
77// VIDEO POSTERS: each vid_paths line carries a /volume1/ai/... path; poster = <path-no-ext>-poster.jpg,
78// mapped to /mnt/nas_ai (= /volume1/ai). Check existence.
79func mc_sample_posters(buf: *u8, n: i64, out_tot: *i64) -> i64 {
80 var have: i64 = 0; var tot: i64 = 0
81 var i: i64 = 0; var ls: i64 = 0
82 while i <= n {
83 var eol: i64 = 0
84 if i == n { eol = 1 } else { if buf[i] == (10 as u8) { eol = 1 } }
85 if eol == 1 {
86 if tot < MC_SAMPLES {
87 let vp: i64 = mc_find(buf, ls, i, "/volume1/ai" as *u8, 11)
88 if vp >= 0 {
89 var pend: i64 = i
90 var t: i64 = vp
91 while t < i { if buf[t] == (9 as u8) { pend = t; t = i } else { t = t + 1 } }
92 if pend > ls { if buf[pend - 1] == (13 as u8) { pend = pend - 1 } }
93 var dot: i64 = pend
94 var d: i64 = vp
95 while d < pend { if buf[d] == (46 as u8) { dot = d } d = d + 1 }
96 let p: *u8 = sys_mmap(MC_MAGIC_2048)
97 var o: i64 = mc_cat(p, 0, "/mnt/nas_ai" as *u8) // map /volume1/ai -> /mnt/nas_ai
98 var k: i64 = vp + 11
99 while k < dot { p[o] = buf[k]; o = o + 1; k = k + 1 }
100 o = mc_cat(p, o, "-poster.jpg" as *u8); p[o] = 0 as u8
101 tot = tot + 1
102 if mc_exists(p) == 1 { have = have + 1 }
103 }
104 }
105 ls = i + 1
106 }
107 i = i + 1
108 }
109 out_tot[0] = tot
110 return have
111}
112
113func mc_pct(have: i64, tot: i64) -> i64 { if tot <= 0 { return 0 } return (have * 100) / tot }
114func mc_verd(have: i64, tot: i64) -> i64 {
115 let pc: i64 = mc_pct(have, tot)
116 if pc >= 90 { mc_puts("WORKING " as *u8) } else { if pc >= 25 { mc_puts("PARTIAL " as *u8) } else { mc_puts("DEGRADED" as *u8) } }
117 return 0
118}
119
120func main() -> i64 {
121 mc_puts("=== NISHI GALLERY MEDIA-DELIVERY CENSUS (sovereign; reads live NAS /mnt/nas_ai/galx) ===\n" as *u8)
122 let buf: *u8 = sys_mmap(MC_CAP + 16)
123
124 let vn: i64 = mc_read_prefix("/mnt/nas_ai/galx/knowledge/status/galx_view_index.txt" as *u8, buf, MC_CAP)
125 if vn <= 0 { mc_puts("MEDIA-CENSUS FAIL: cannot read view_index (NAS mount down?)\n" as *u8); sys_exit(1); return 1 }
126 let tt: *i64 = sys_mmap(16) as *i64
127 let th: i64 = mc_sample_thumbs(buf, vn, tt)
128 mc_puts("IMAGE THUMBS "); mc_verd(th, tt[0]); mc_puts(" sample "); mc_putn(th); mc_puts("/"); mc_putn(tt[0])
129 mc_puts(" cached ("); mc_putn(mc_pct(th, tt[0])); mc_puts("%) of ~235445 images -> cold cell = full-res fallback = slow\n" as *u8)
130
131 let pn: i64 = mc_read_prefix("/mnt/nas_ai/galx/knowledge/status/galx_vid_paths.tsv" as *u8, buf, MC_CAP)
132 if pn <= 0 { mc_puts("VIDEO POSTERS : cannot read vid_paths (no recordings index?)\n" as *u8) }
133 else {
134 let pt: *i64 = sys_mmap(16) as *i64
135 let ph: i64 = mc_sample_posters(buf, pn, pt)
136 // HONESTY GUARD: the file has lines (pn>0) but ZERO matched /volume1/ai means the recordings live on
137 // a DIFFERENT volume (/volume1/logging), which is NOT mounted in WSL (only /volume1/ai is). We are
138 // BLIND here, not DEGRADED. Emitting "DEGRADED 0/0" would be a FALSE delivery alarm -- the exact kind
139 // of misleading signal the operator banned. Report the blind spot + route to the authoritative check.
140 if pt[0] == 0 {
141 mc_puts("VIDEO POSTERS CANNOT-VERIFY recordings live on /volume1/logging, NOT mounted in WSL (only /volume1/ai is)\n" as *u8)
142 mc_puts(" -> this WSL census is BLIND to poster coverage; do NOT read this as a failure.\n" as *u8)
143 mc_puts(" -> authoritative check runs ON the NAS: nx_nas_run + nx_galx_vid_audit (/volume1/logging visible there)\n" as *u8)
144 } else {
145 mc_puts("VIDEO POSTERS "); mc_verd(ph, pt[0]); mc_puts(" sample "); mc_putn(ph); mc_puts("/"); mc_putn(pt[0])
146 mc_puts(" present ("); mc_putn(mc_pct(ph, pt[0])); mc_puts("%) -> absent poster = /vidthumb 404 = blank video tile\n" as *u8)
147 }
148 }
149
150 mc_puts("AI UPSCALE ABSENT on-demand super-resolution not wired (stack exists: nx_upsample/nx_vae_decode/nx_conv2d/gguf+safetensors loaders)\n" as *u8)
151 mc_puts("MEDIA-CENSUS done (sovereign read; sample-based coverage)\n" as *u8)
152 sys_exit(0); return 0
153}