code wiki / _hdl_build / nx_eco_scorecard.nx
nx_eco_scorecard.nx source
↩ module page · 318 lines · 18446 B
1// nx_eco_scorecard.nx -- SOVEREIGN ECOSYSTEM HEALTH SCORECARD, graded against the REAL industry battery
2// (operator 2026-07-20: "industry benchmarking of ecosystems ... sovereign versions of state of the art tooling
3// ... proper non navel gazing grading and evidence, from god up"). This is our own implementation of what
4// SonarQube/SQALE, OpenSSF Scorecard, CISQ ISO/IEC 5055 and ISO/IEC 25010 do -- zero third-party, all integer.
5//
6// ANTI-FLATTERY BY CONSTRUCTION: the HEADLINE is benchmark_coverage_permil = how much of the external battery we
7// have actually BUILT sovereignly (HAVE=2, PARTIAL=1, GAP=0), NOT a letter grade. A good letter on a battery we
8// barely implement is navel-gazing, so the letter never travels without its coverage. Every threshold cited is the
9// PUBLISHED external one, carried as DATA in knowledge/registry/ecosystem_benchmarks.tsv (rule 11), never in code.
10// SQALE (SonarQube): td_ratio = remediation / (30 min per LOC x LOC); A<=50 B<=100 C<=200 D<=500 E>500 permil
11// Duplication gate: SonarQube quality gate <=3pct (30 permil) duplicated code
12// OpenSSF Scorecard: 18 checks x 0-10, aggregate = risk-weighted (Critical 10 / High 7.5 / Med 5 / Low 2.5)
13// SCOPE = the from-god atlas lineage: organ_count is SELF-MEASURED by walking the live source tree, so the
14// denominator is the real ecosystem, not a flattering subset. Fails closed: no manifest -> RED, no grade without data.
15// NATIVE INFORMATION MANAGEMENT (2026-07-20): the battery, the OpenSSF check map and the ricketiness classes are
16// read from sovereign SEG-STORE PLANES (knowledge/store/ecobench- · openssf- · favela-), NOT from .tsv files --
17// the standing "no tsv, nishi formats" law. Migrated losslessly + round-trip-verified by nx_tsv_migrate.
18// license_tier: ORIGINAL expect_exit: 0
19import "nx_sovjson_lib.nx"
20import "nx_store_seed_lib.nx"
21import "nx_seg_store.nx"
22import "nx_syscalls.nx"
23import "nx_estate_path.nx" // ep_anchor: the CWD must not decide this organ's verdict
24const SC_MAGIC_3900: i64 = 3900
25const SC_MAGIC_131072: i64 = 131072
26const SC_MAGIC_4096: i64 = 4096
27const SC_MAGIC_262144: i64 = 262144
28
29const SC_PLANE_CAP: i64 = 1048576
30
31const SC_LOC_PER_ORGAN: i64 = 120 // disclosed constant: mean source lines per organ (audit by re-measuring)
32const SC_DEV_MIN_PER_LOC: i64 = 30 // SonarQube DEFAULT cost-to-develop-one-line, in minutes (external constant)
33const SC_MIN_PER_SEV_OPEN: i64 = 240 // disclosed: half a day to ROOT one open workaround class, per severity point
34const SC_MIN_PER_SEV_MIT: i64 = 60 // disclosed: residual hour per severity point once mitigated
35const SC_DUP_GATE_PERMIL: i64 = 30 // SonarQube duplicated-code quality gate = 3 percent
36
37func sc_puts(s: *u8) -> i64 { return sj_puts(s) }
38func sc_cat(o: *u8, at: i64, s: *u8) -> i64 { return sj_cat(o, at, s) }
39func sc_catf(o: *u8, at: i64, p: *u8, n: i64) -> i64 { var i: i64=0; var a: i64=at; while i<n { o[a]=p[i]; a=a+1; i=i+1 } return a }
40func sc_catn(o: *u8, at: i64, v: i64) -> i64 { return sj_catn(o, at, v) }
41func sc_count(buf: *u8, n: i64, needle: *u8) -> i64 {
42 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1}
43 if nl==0 { return 0 }
44 var c: i64=0
45 var i: i64=0
46 while i+nl<=n {
47 var j: i64=0
48 var ok: i64=1
49 while j<nl { if buf[i+j]!=needle[j] { ok=0; j=nl } else { j=j+1 } }
50 if ok==1 { c=c+1; i=i+nl } else { i=i+1 }
51 }
52 return c
53}
54// split [ls,lend) into tab fields -> fs/fl; returns field count
55func sc_split(buf: *u8, ls: i64, lend: i64, fs: *i64, fl: *i64, maxf: i64) -> i64 {
56 var nf: i64=0
57 var p: i64=ls
58 var fstart: i64=ls
59 while p<lend {
60 if buf[p]==(9 as u8) {
61 if nf<maxf { fs[nf]=fstart; fl[nf]=p-fstart; nf=nf+1 }
62 fstart=p+1
63 }
64 p=p+1
65 }
66 if nf<maxf { fs[nf]=fstart; fl[nf]=lend-fstart; nf=nf+1 }
67 return nf
68}
69func sc_atoi(buf: *u8, s: i64, n: i64) -> i64 {
70 var v: i64=0
71 var i: i64=0
72 while i<n { let c: i64=buf[s+i] as i64; if c>=48 { if c<=57 { v=v*10+(c-48) } } i=i+1 }
73 return v
74}
75func sc_isdotdot(nm: *u8) -> i64 { if nm[0]==(46 as u8){ if nm[1]==(0 as u8){return 1} if nm[1]==(46 as u8){ if nm[2]==(0 as u8){return 1} } } return 0 }
76func sc_join(buf: *u8, base_n: i64, name: *u8) -> i64 { buf[base_n]=47 as u8; var o: i64=base_n+1; var i: i64=0; while name[i]!=(0 as u8){buf[o]=name[i];o=o+1;i=i+1} return o }
77// SELF-MEASURED ecosystem scope: recursively count *.nx source organs (the real from-god population)
78func sc_walk_nx(p: *u8, pn: i64, depth: i64) -> i64 {
79 if depth>6 { return 0 }
80 if pn>SC_MAGIC_3900 { return 0 }
81 p[pn]=0 as u8
82 let fd: i64=sys_openat_rd(p)
83 if fd<0 { return 0 }
84 let dbuf: *u8=sys_mmap(SC_MAGIC_131072)
85 var cnt: i64=0
86 var go: i64=1
87 while go==1 {
88 let nr: i64=sys_getdents64(fd, dbuf, SC_MAGIC_131072)
89 if nr<=0 { go=0 } else {
90 var off: i64=0
91 while off<nr {
92 let rec: *u8=(dbuf as i64+off) as *u8
93 let ty: i64=dirent_type(rec)
94 let nm: *u8=dirent_name(rec)
95 if sc_isdotdot(nm)==0 {
96 let cs: i64=sc_join(p, pn, nm)
97 if ty==4 { cnt=cnt+sc_walk_nx(p, cs, depth+1) }
98 else {
99 if cs>=3 { if p[cs-3]==(46 as u8) { if p[cs-2]==(110 as u8) { if p[cs-1]==(120 as u8) { cnt=cnt+1 } } } }
100 }
101 }
102 off=off+dirent_reclen(rec)
103 }
104 }
105 }
106 sys_close(fd)
107 return cnt
108}
109
110func main() -> i64 {
111 // ANCHOR FIRST (2026-08-04): run from buildroot this organ read an EMPTY/absent estate
112 // and fail-closed RED (or, worse, appended to a SECOND store). Its subject is the
113 // estate, so the caller's working directory must not decide its verdict.
114 ep_anchor()
115 let szp: *i64=sys_mmap(16) as *i64
116 let bb: *u8=sys_mmap(SC_PLANE_CAP)
117 let bn: i64=sts_load("knowledge/store/ecobench-\x00" as *u8, bb, SC_PLANE_CAP-SC_MAGIC_4096)
118 if bn<=0 {
119 sc_puts("ECO-SCORECARD RED -- native plane knowledge/store/ecobench- ABSENT or EMPTY (fail-closed: no grade without the external battery)\n" as *u8)
120 sys_exit(1)
121 return 1
122 }
123 let fs: *i64=sys_mmap(128) as *i64
124 let fl: *i64=sys_mmap(128) as *i64
125 let jb: *u8=sys_mmap(SC_MAGIC_262144)
126 var j: i64=0
127 j=sc_cat(jb, j, "{\x22v\x22:1,\x22domain\x22:\x22ecosystem-health\x22,\x22title\x22:\x22Sovereign ecosystem health scorecard -- graded against the external industry battery (SQALE/SonarQube, OpenSSF Scorecard, CISQ ISO-5055, ISO-25010, DORA, CHAOSS)\x22" as *u8)
128
129 // ---- SCOPE: self-measured from-god organ population
130 let pbuf: *u8=sys_mmap(SC_MAGIC_4096)
131 var rn: i64=0
132 let root: *u8="buildroot/runtime\x00" as *u8
133 while root[rn]!=(0 as u8) { pbuf[rn]=root[rn]; rn=rn+1 }
134 var organs: i64=sc_walk_nx(pbuf, rn, 0)
135 var scope_src: *u8="buildroot/runtime (live recursive .nx walk)\x00" as *u8
136 if organs==0 {
137 // laptop/alternate layout: fall back to runtime/ and DECLARE which root was measured
138 rn=0
139 let r2: *u8="runtime\x00" as *u8
140 while r2[rn]!=(0 as u8) { pbuf[rn]=r2[rn]; rn=rn+1 }
141 organs=sc_walk_nx(pbuf, rn, 0)
142 scope_src="runtime (live recursive .nx walk)\x00" as *u8
143 }
144
145 // ---- INDUSTRY BATTERY: emit each external standard + our sovereign status (the honest headline)
146 var nb: i64=0; var cov: i64=0
147 j=sc_cat(jb, j, ",\x22benchmarks\x22:[" as *u8)
148 var first: i64=1
149 var i: i64=0
150 while i<bn {
151 let ls: i64=i
152 var le: i64=ls
153 var scan: i64=1
154 while scan==1 { if le>=bn { scan=0 } else { if bb[le]==(10 as u8) { scan=0 } else { le=le+1 } } }
155 let lend: i64=le
156 i=le+1
157 if lend-ls>5 { if bb[ls]!=(35 as u8) {
158 let nf: i64=sc_split(bb, ls, lend, fs, fl, 6)
159 if nf==6 {
160 let st: i64=bb[fs[4]] as i64
161 var w: i64=0
162 if st==72 { w=2 }
163 if st==80 { w=1 }
164 cov=cov+w
165 nb=nb+1
166 if first==0 { j=sc_cat(jb, j, "," as *u8) }
167 first=0
168 j=sc_cat(jb, j, "{\x22standard\x22:\x22" as *u8); j=sc_catf(jb, j, (bb as i64+fs[0]) as *u8, fl[0])
169 j=sc_cat(jb, j, "\x22,\x22measures\x22:\x22" as *u8); j=sc_catf(jb, j, (bb as i64+fs[1]) as *u8, fl[1])
170 j=sc_cat(jb, j, "\x22,\x22industry_threshold\x22:\x22" as *u8); j=sc_catf(jb, j, (bb as i64+fs[2]) as *u8, fl[2])
171 j=sc_cat(jb, j, "\x22,\x22sovereign_tool\x22:\x22" as *u8);j=sc_catf(jb, j, (bb as i64+fs[3]) as *u8, fl[3])
172 j=sc_cat(jb, j, "\x22,\x22status\x22:\x22" as *u8); j=sc_catf(jb, j, (bb as i64+fs[4]) as *u8, fl[4])
173 j=sc_cat(jb, j, "\x22,\x22evidence\x22:\x22" as *u8); j=sc_catf(jb, j, (bb as i64+fs[5]) as *u8, fl[5])
174 j=sc_cat(jb, j, "\x22}" as *u8)
175 }
176 } }
177 }
178 var covp: i64=0
179 if nb>0 { covp=(cov*1000)/(nb*2) }
180 j=sc_cat(jb, j, "]" as *u8)
181
182 // ---- SOVEREIGN SQALE (SonarQube method, external constants, disclosed)
183 var remed: i64=0; var nopen: i64=0; var nmit: i64=0; var nroot: i64=0
184 let fb: *u8=sys_mmap(SC_PLANE_CAP)
185 let fnl: i64=sts_load("knowledge/store/favela-\x00" as *u8, fb, SC_PLANE_CAP-SC_MAGIC_4096)
186 var fmeasured: i64=0
187 if fnl>0 {
188 fmeasured=1
189 let fn: i64=fnl
190 var k: i64=0
191 while k<fn {
192 let ls2: i64=k
193 var le2: i64=ls2
194 var sc2: i64=1
195 while sc2==1 { if le2>=fn { sc2=0 } else { if fb[le2]==(10 as u8) { sc2=0 } else { le2=le2+1 } } }
196 let lend2: i64=le2
197 k=le2+1
198 if lend2-ls2>5 { if fb[ls2]!=(35 as u8) {
199 let nf2: i64=sc_split(fb, ls2, lend2, fs, fl, 7)
200 if nf2==7 {
201 let sev: i64=(fb[fs[2]] as i64)-48
202 let stc: i64=fb[fs[3]] as i64
203 if stc==111 { remed=remed+sev*SC_MIN_PER_SEV_OPEN; nopen=nopen+1 }
204 if stc==109 { remed=remed+sev*SC_MIN_PER_SEV_MIT; nmit=nmit+1 }
205 if stc==114 { nroot=nroot+1 }
206 }
207 } }
208 }
209 }
210 let devmin: i64=organs*SC_LOC_PER_ORGAN*SC_DEV_MIN_PER_LOC
211 var tdr: i64=0-1
212 if devmin>0 { tdr=(remed*1000)/devmin }
213 var rating: *u8="UNMEASURED\x00" as *u8
214 if tdr>=0 {
215 rating="A\x00" as *u8
216 if tdr>50 { rating="B\x00" as *u8 }
217 if tdr>100 { rating="C\x00" as *u8 }
218 if tdr>200 { rating="D\x00" as *u8 }
219 if tdr>500 { rating="E\x00" as *u8 }
220 }
221 j=sc_cat(jb, j, ",\x22sqale\x22:{\x22method\x22:\x22SonarQube/SQALE technical-debt ratio = remediation_min / (30 min-per-LOC x LOC)\x22,\x22remediation_min\x22:" as *u8); j=sc_catn(jb, j, remed)
222 j=sc_cat(jb, j, ",\x22development_min\x22:" as *u8); j=sc_catn(jb, j, devmin)
223 j=sc_cat(jb, j, ",\x22td_ratio_permil\x22:" as *u8); j=sc_catn(jb, j, tdr)
224 j=sc_cat(jb, j, ",\x22rating\x22:\x22" as *u8); j=sc_cat(jb, j, rating)
225 j=sc_cat(jb, j, "\x22,\x22bands_permil\x22:\x22A<=50 B<=100 C<=200 D<=500 E>500 (SonarQube default grid)\x22" as *u8)
226 j=sc_cat(jb, j, ",\x22constants_disclosed\x22:{\x22loc_per_organ\x22:120,\x22dev_min_per_loc\x22:30,\x22min_per_sev_open\x22:240,\x22min_per_sev_mitigated\x22:60}" as *u8)
227 j=sc_cat(jb, j, ",\x22caveat\x22:\x22SQALE measures debt DENSITY over total development effort, NOT absolute hazard. A good letter here does NOT mean clean: our CISQ/ISO-5055 CWE weakness detectors are a declared GAP, so undetected debt is not in the numerator. Read the letter ONLY next to benchmark_coverage_permil and the open structural-hazard count.\x22}" as *u8)
228
229 // ---- DUPLICATION vs the SonarQube quality gate
230 var dupc: i64=0-1
231 let dl: *u8=sys_read_file("knowledge/status/dup_source.log\x00" as *u8, szp)
232 if (dl as i64)!=0 { dupc=sc_count(dl, szp[0], "DUP basename:\x00" as *u8) }
233 var dupp: i64=0-1
234 if dupc>=0 { if organs>0 { dupp=(dupc*1000)/organs } }
235 var dupv: *u8="UNMEASURED\x00" as *u8
236 if dupp>=0 { dupv="PASS\x00" as *u8; if dupp>SC_DUP_GATE_PERMIL { dupv="FAIL\x00" as *u8 } }
237 j=sc_cat(jb, j, ",\x22duplication\x22:{\x22dup_basenames\x22:" as *u8); j=sc_catn(jb, j, dupc)
238 j=sc_cat(jb, j, ",\x22ratio_permil\x22:" as *u8); j=sc_catn(jb, j, dupp)
239 j=sc_cat(jb, j, ",\x22gate_permil\x22:" as *u8); j=sc_catn(jb, j, SC_DUP_GATE_PERMIL)
240 j=sc_cat(jb, j, ",\x22verdict\x22:\x22" as *u8); j=sc_cat(jb, j, dupv)
241 j=sc_cat(jb, j, "\x22,\x22honest\x22:\x22SonarQube counts duplicated LINES; ours are whole-file basename collisions in the build tree -- FEWER but each is a build-resolution landmine (a rebuild can silently pick the stale twin). Passing the line-ratio gate does NOT clear the hazard; it is graded separately by operational severity (seq207, sev8).\x22}" as *u8)
242
243 // ---- OpenSSF Scorecard (sovereign map, risk-weighted per the published scheme)
244 var wsum: i64=0; var wmax: i64=0; var nchk: i64=0
245 let ob: *u8=sys_mmap(SC_PLANE_CAP)
246 let onl: i64=sts_load("knowledge/store/openssf-\x00" as *u8, ob, SC_PLANE_CAP-SC_MAGIC_4096)
247 j=sc_cat(jb, j, ",\x22openssf_scorecard\x22:{\x22method\x22:\x22aggregate = risk-weighted mean of 0-10 checks (Critical 10 / High 7.5 / Medium 5 / Low 2.5)\x22,\x22checks\x22:[" as *u8)
248 var f2: i64=1
249 if onl>0 {
250 let on: i64=onl
251 var m: i64=0
252 while m<on {
253 let ls3: i64=m
254 var le3: i64=ls3
255 var sc3: i64=1
256 while sc3==1 { if le3>=on { sc3=0 } else { if ob[le3]==(10 as u8) { sc3=0 } else { le3=le3+1 } } }
257 let lend3: i64=le3
258 m=le3+1
259 if lend3-ls3>5 { if ob[ls3]!=(35 as u8) {
260 let nf3: i64=sc_split(ob, ls3, lend3, fs, fl, 4)
261 if nf3==4 {
262 let wt: i64=sc_atoi(ob, fs[1], fl[1])
263 let sco: i64=sc_atoi(ob, fs[2], fl[2])
264 wsum=wsum+sco*wt
265 wmax=wmax+10*wt
266 nchk=nchk+1
267 if f2==0 { j=sc_cat(jb, j, "," as *u8) }
268 f2=0
269 j=sc_cat(jb, j, "{\x22check\x22:\x22" as *u8); j=sc_catf(jb, j, (ob as i64+fs[0]) as *u8, fl[0])
270 j=sc_cat(jb, j, "\x22,\x22weight\x22:" as *u8); j=sc_catn(jb, j, wt)
271 j=sc_cat(jb, j, ",\x22score\x22:" as *u8); j=sc_catn(jb, j, sco)
272 j=sc_cat(jb, j, ",\x22sovereign\x22:\x22" as *u8); j=sc_catf(jb, j, (ob as i64+fs[3]) as *u8, fl[3])
273 j=sc_cat(jb, j, "\x22}" as *u8)
274 }
275 } }
276 }
277 }
278 var agg: i64=0-1
279 if wmax>0 { agg=(wsum*1000)/wmax }
280 j=sc_cat(jb, j, "],\x22checks_mapped\x22:" as *u8); j=sc_catn(jb, j, nchk)
281 j=sc_cat(jb, j, ",\x22checks_in_standard\x22:18,\x22aggregate_permil\x22:" as *u8); j=sc_catn(jb, j, agg)
282 j=sc_cat(jb, j, ",\x22honest\x22:\x22scores are our OWN assessment carried as editable data, not an upstream Scorecard run -- an external run is the triangulating rung. High marks concentrate where sovereignty structurally wins (zero third-party deps = perfect pinning + nothing to update, build-from-source, capability tokens); low marks are real (fuzzing 3, SAST 4, contributors 3).\x22}" as *u8)
283
284 // ---- ricketiness cross-signal (the favela lens feeds ISO-25010 maintainability)
285 j=sc_cat(jb, j, ",\x22ricketiness\x22:{\x22source\x22:\x22nx_favela_census (workaround-class lens)\x22,\x22measured\x22:" as *u8); j=sc_catn(jb, j, fmeasured)
286 j=sc_cat(jb, j, ",\x22open_classes\x22:" as *u8); j=sc_catn(jb, j, nopen)
287 j=sc_cat(jb, j, ",\x22mitigated_classes\x22:" as *u8); j=sc_catn(jb, j, nmit)
288 j=sc_cat(jb, j, ",\x22rooted_classes\x22:" as *u8); j=sc_catn(jb, j, nroot)
289 j=sc_cat(jb, j, ",\x22maps_to\x22:\x22ISO-25010 Maintainability + SQALE remediation numerator\x22}" as *u8)
290
291 // ---- scope + headline
292 j=sc_cat(jb, j, ",\x22scope\x22:{\x22organs_self_measured\x22:" as *u8); j=sc_catn(jb, j, organs)
293 j=sc_cat(jb, j, ",\x22measured_root\x22:\x22" as *u8); j=sc_cat(jb, j, scope_src)
294 j=sc_cat(jb, j, "\x22,\x22from_god_lineage\x22:\x22the atlas from-god organ graph (nx_eco_graph, ~16.6k nodes / ~42.9k edges at last F224 ingest) -- every graded organ traces root-to-god; the denominator is the WHOLE population, not a flattering subset\x22}" as *u8)
295 j=sc_cat(jb, j, ",\x22benchmarks_total\x22:" as *u8); j=sc_catn(jb, j, nb)
296 j=sc_cat(jb, j, ",\x22benchmark_coverage_permil\x22:" as *u8); j=sc_catn(jb, j, covp)
297 j=sc_cat(jb, j, ",\x22headline\x22:\x22benchmark_coverage_permil is THE number: how much of the external industry battery we have built a sovereign version of (HAVE=2, PARTIAL=1, GAP=0). Letter grades are meaningless without it -- a clean SQALE letter on a battery we barely implement is exactly the navel-gazing this scorecard exists to prevent.\x22" as *u8)
298 j=sc_cat(jb, j, ",\x22information_management\x22:{\x22format\x22:\x22NATIVE sovereign seg-store planes -- zero .tsv\x22,\x22planes\x22:[\x22knowledge/store/ecobench-\x22,\x22knowledge/store/openssf-\x22,\x22knowledge/store/favela-\x22],\x22migrated_by\x22:\x22nx_tsv_migrate (data-lossless, round-trip verified, non-destructive)\x22}" as *u8)
299 j=sc_cat(jb, j, ",\x22envelope\x22:\x22thresholds are the PUBLISHED external ones carried as plane rows (knowledge/store/ecobench-); OpenSSF scores are self-assessed not upstream-run; SQALE constants are disclosed estimates; -1 = evidence absent = UNMEASURED, never a silent 0; GAP rows are filed rungs, not omissions.\x22}" as *u8)
300 sys_write(1, jb, j)
301 sys_write(1, "\n" as *u8, 1)
302
303 let lf: i64=sys_openat_wr("knowledge/status/eco_scorecard.log\x00" as *u8, 0x1a4)
304 if lf>=0 {
305 sys_write(lf, jb, j)
306 let tail: *u8=sys_mmap(256)
307 var t: i64=0
308 t=sc_cat(tail, t, "\nVERDICT=GREEN benchmarks=" as *u8); t=sc_catn(tail, t, nb)
309 t=sc_cat(tail, t, " coverage=" as *u8); t=sc_catn(tail, t, covp)
310 t=sc_cat(tail, t, " sqale=" as *u8); t=sc_cat(tail, t, rating)
311 t=sc_cat(tail, t, " openssf=" as *u8); t=sc_catn(tail, t, agg)
312 t=sc_cat(tail, t, " organs=" as *u8); t=sc_catn(tail, t, organs)
313 t=sc_cat(tail, t, "\n" as *u8)
314 sys_write(lf, tail, t)
315 sys_close(lf)
316 }
317 return 0
318}