nx_selfsuff.nx source
↩ module page · 1182 lines · 66348 B
1// nx_selfsuff.nx -- THE SOVEREIGNTY LEDGER: outside DEPENDENCY measured per /compare domain and per
2// organ, so "self sufficiency" is a number with a worklist instead of a feeling.
3//
4// Operator 2026-08-20: "where would be the best investment that drives the most self sufficiency down".
5// Recorded interpretation (feedback-foundation-and-autonomous-frontier-2026-08-20): drive outside
6// DEPENDENCY down / sovereignty UP, across three measurable kinds. TWO of the three are measured HERE.
7// The third -- outside TOOLS -- already has an incumbent (nx_claude_harvest ch_gauge_json) and a second
8// ruler for it would be the duplicate-ruler defect, so this organ does not compute it and SAYS SO
9// rather than quietly leaving a gap.
10//
11// (b) outside SERVICES -- what breaks with no internet, DERIVED FROM WHAT THE CODE CALLS. Every
12// "scheme://host" occurrence that sits INSIDE A STRING LITERAL and OUTSIDE A COMMENT is a host
13// the organ dials. Both halves of that predicate are load-bearing: a scanner that does not skip
14// comments measures the DOCUMENTATION, not the code (measured law 2026-08-06), and a scanner
15// that skips strings measures NOTHING, because the URL *is* a string. Hosts classify against the
16// conf's sovereign= prefixes; everything else is OUTSIDE and is NAMED in the ledger, never only
17// counted.
18// TWO SEPARATE ANSWERS, because they answer two different questions and merging them would
19// silently re-price the whole estate:
20// outside_dep -- distinct outside hosts an organ dials ITSELF, plus distinct carriers it
21// touches at ONE HOP. Sparse and exact; this is the RANKER's coefficient, and
22// it is held at one hop deliberately so a measurement change cannot re-price
23// every rung behind the reader's back.
24// net_dep -- does this organ reach the network AT ALL: DIRECT (a socket primitive in its
25// own code, or a host it dials itself) or VIA-HELPER (it reaches one over the
26// TRANSITIVE import/fork closure). This is the honest answer to "what breaks
27// with no internet", and it needed the closure: an organ that reaches the
28// network through a helper carries NO url literal and NO ".elf" literal, so a
29// same-organ test reports every well-factored caller as sovereign. THAT ERROR
30// LOOKS LIKE GOOD NEWS, which is why it survived a whole build.
31// The closure walks import edges as well as fork edges, seeds itself from the matrix organs and
32// pulls in whatever they reach; lane F proved the import graph ACYCLIC (0 nontrivial SCCs over
33// 18,945 nodes), so the fixpoint terminates. Nodes the closure pulls in are EVIDENCE, not
34// subjects: they are never published in the host partition, the ledger or the roll-up.
35//
36// (c) CLAUDE-IN-THE-LOOP -- an organ whose capability only exists while a seat drives it: absent
37// from every clock row and every roster/registry the conf names, AND forked by nothing in the
38// scanned corpus. When no autonomy source loads, seat_only is -1 UNOBSERVED: an axis that
39// cannot see must ABSTAIN, not acquit.
40// ⚠ SCOPE, STATED BECAUSE IT SETS THE DIRECTION OF THE ERROR: the fork-edge corpus is drawn
41// from the MATRIX ORGANS ONLY, not the whole tree, so an organ forked by some non-matrix organ
42// still reads seat-only here. seat_only is therefore an UPPER BOUND on Claude-dependency, not a
43// floor. The exact version needs a whole-tree fork-edge corpus; nx_forkcensus already builds
44// one, and wiring its artifact in as an auto_file is the named fix.
45// ⚠ AND IT SATURATES: measured 2026-08-20 at 92% of subjects. A signal that fires on everything
46// DISCRIMINATES NOTHING, so seat_only is REPORTED but is NOT the ranker's coefficient. The
47// ranker consumes claude_loop = seat_only AND seat_freq>0 -- an autonomy gap with a WITNESS in
48// the action record -- which is sparse, and outside_dep, which is sparse and exact.
49//
50// The ledger is the input to nx_compare_rank's rk_selfsuff_term: a rung standing on outside dependency
51// is MISPRICED without it (foundation-before-frontier, the same memo's rule 1).
52//
53// usage: nx_selfsuff census [action-journal] [root] -- full population over regen.list, writes ledger
54// nx_selfsuff ledger [root] -- print the ledger as it stands
55//
56// <root> is the NISHIHOST root as seen from the current directory and defaults to ".". It exists
57// because this estate runs organs from TWO cwds -- the serving root and buildroot/ -- and a path that
58// is correct from one silently addresses the OTHER knowledge tree from the other. One knob, printed
59// on every run, beats a path that is quietly wrong.
60import "nx_syscalls.nx"
61import "nx_tool_run.nx"
62
63// ---- caps. Every one ANNOUNCES when it binds; none is a silent cap. ------------------------------
64const SS_SRC_CAP: i64 = 524288 // one organ source; RANK_SRC_CAP's value, inherited not invented
65const SS_FILE_CAP: i64 = 262144 // one .matrix / regen.list / conf; the compare generator's cap
66const SS_MAX_DOM: i64 = 128 // regen.list carried 66 rows on 2026-08-20; ~2x headroom
67const SS_MAX_ORG: i64 = 24576 // matrix subjects PLUS every node the import/fork CLOSURE
68 // reaches. Lane F measured the whole import graph at 18,945
69 // nodes / 49,593 edges and proved it ACYCLIC (0 nontrivial
70 // SCCs), so the closure terminates and fits here; the cap
71 // REFUSES rather than publish a partial closure as a total.
72const SS_NAME_ARENA: i64 = 6291456 // SS_MAX_ORG * 256 B of node path, exactly
73const SS_HOST_MAX: i64 = 65536
74const SS_HOST_ARENA: i64 = 8388608
75const SS_EDGE_MAX: i64 = 1048576
76const SS_EDGE_ARENA: i64 = 33554432
77const SS_HTAB: i64 = 65536 // node-basename -> node index, power of two. NOT a tuning
78 // knob: the closure asks "is this edge already a node?" once
79 // per edge, and the linear scan the rest of this organ uses
80 // would cost edges x nodes = 1e6 x 2e4 = 2e10 ops, two orders
81 // over the 1e8-1e9/sec/core budget. Sized above SS_MAX_ORG so
82 // the table cannot pass half load.
83const SS_NET_ITER: i64 = 64 // fixpoint sweeps for transitive net-capability. The graph is
84 // acyclic so its DEPTH bounds this; exceeding it REFUSES.
85const SS_AUTO_CAP: i64 = 2097152 // the concatenated autonomy corpus (planes + registries)
86const SS_JRNL_CAP: i64 = 4194304 // action-journal window; CH_JWIN's value, inherited
87const SS_LEDGER_CAP: i64 = 4194304
88const SS_TOK: i64 = 256
89const SS_FIELDS: i64 = 24
90const SS_FORK_CAP: i64 = 2097152 // captured stdout of one nx_store_put load; clocksched- resolved
91 // 3,026 segments on 2026-08-20, so a 256 KB capture would have
92 // truncated the autonomy corpus IN SILENCE. It announces instead.
93
94const SS_CH_NL: i64 = 10
95const SS_CH_TAB: i64 = 9
96const SS_CH_SP: i64 = 32
97const SS_CH_QUOTE: i64 = 34
98const SS_CH_HASH: i64 = 35
99const SS_CH_DOT: i64 = 46
100const SS_CH_SLASH: i64 = 47
101const SS_CH_SEMI: i64 = 59
102const SS_CH_COLON: i64 = 58
103const SS_CH_QMARK: i64 = 63
104const SS_CH_AT: i64 = 64
105const SS_CH_EQ: i64 = 61
106const SS_CH_BSLASH: i64 = 92
107const SS_CH_PIPE: i64 = 124
108const SS_CH_MINUS: i64 = 45
109const SS_CH_USCORE: i64 = 95
110const SS_CH_0: i64 = 48
111const SS_CH_9: i64 = 57
112const SS_CH_A: i64 = 65
113const SS_CH_Z: i64 = 90
114const SS_CH_a: i64 = 97
115const SS_CH_z: i64 = 122
116
117func ss_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
118func ss_puts(s: *u8) -> i64 { sys_write(1, s, ss_slen(s)); return 0 }
119func ss_pn(v: i64) -> i64 {
120 if v == 0 { ss_puts("0" as *u8); return 0 }
121 var x: i64 = v
122 if x < 0 { ss_puts("-" as *u8); x = 0 - x }
123 let b: *u8 = sys_mmap(32)
124 var i: i64 = 0
125 while x > 0 { b[i] = ((x - (x / 10) * 10) + SS_CH_0) as u8; x = x / 10; i = i + 1 }
126 while i > 0 { i = i - 1; sys_write(1, (b as i64 + i) as *u8, 1) }
127 return 0
128}
129func ss_nl() -> i64 { let b: *u8 = sys_mmap(8); b[0] = SS_CH_NL as u8; sys_write(1, b, 1); return 0 }
130func ss_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; var oo: i64 = o; while s[i] != (0 as u8) { d[oo] = s[i]; oo = oo + 1; i = i + 1 } d[oo] = 0 as u8; return oo }
131func ss_catc(d: *u8, o: i64, c: i64) -> i64 { d[o] = c as u8; d[o+1] = 0 as u8; return o + 1 }
132func ss_catn(d: *u8, o: i64, v: i64) -> i64 {
133 if v == 0 { d[o] = SS_CH_0 as u8; d[o+1] = 0 as u8; return o + 1 }
134 var x: i64 = v
135 var oo: i64 = o
136 if x < 0 { d[oo] = SS_CH_MINUS as u8; oo = oo + 1; x = 0 - x }
137 let t: *u8 = sys_mmap(32)
138 var i: i64 = 0
139 while x > 0 { t[i] = ((x - (x / 10) * 10) + SS_CH_0) as u8; x = x / 10; i = i + 1 }
140 while i > 0 { i = i - 1; d[oo] = t[i]; oo = oo + 1 }
141 d[oo] = 0 as u8
142 return oo
143}
144func ss_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] == b[i] { if a[i] == (0 as u8) { return 1 } i = i + 1 } return 0 }
145func ss_starts(s: *u8, p: *u8) -> i64 { var i: i64 = 0; while p[i] != (0 as u8) { if s[i] != p[i] { return 0 } i = i + 1 } return 1 }
146func ss_read(path: *u8, b: *u8, cap: i64) -> i64 {
147 let fd: i64 = sys_openat_rd(path)
148 if fd < 0 { return 0 - 1 }
149 var n: i64 = 0
150 var go: i64 = 1
151 while go == 1 { let r: i64 = sys_read(fd, (b as i64 + n) as *u8, cap - n); if r > 0 { n = n + r } else { go = 0 } if n >= cap { go = 0 } }
152 sys_close(fd)
153 return n
154}
155// END OF LINE, with a SEPARATE FLAG -- never by clobbering the cursor. A loop that breaks by writing
156// its own cursor cannot also report where it stopped (measured law; it bit this file's first draft).
157func ss_eol(b: *u8, from: i64, n: i64) -> i64 {
158 var e: i64 = from
159 var fnd: i64 = 0
160 while fnd == 0 {
161 if e >= n { fnd = 1 } else { if b[e] == (SS_CH_NL as u8) { fnd = 1 } else { e = e + 1 } }
162 }
163 return e
164}
165// split a NUL-terminated line on '|' IN PLACE -- the compare generator's splitpipe contract
166func ss_split(s: *u8, fld: *i64, maxf: i64) -> i64 {
167 var c: i64 = 1; fld[0] = s as i64; var i: i64 = 0
168 while s[i] != (0 as u8) { if s[i] == (SS_CH_PIPE as u8) { s[i] = 0 as u8; if c < maxf { fld[c] = (s as i64) + i + 1; c = c + 1 } } i = i + 1 }
169 return c
170}
171// "runtime/_hdl_build/nx_pm_intake.nx" -> "nx_pm_intake" (dir stripped, first extension stripped)
172func ss_base(path: *u8, out: *u8, cap: i64) -> i64 {
173 let n: i64 = ss_slen(path)
174 var s: i64 = 0
175 var i: i64 = 0
176 while i < n { if path[i] == (SS_CH_SLASH as u8) { s = i + 1 } i = i + 1 }
177 var e: i64 = n
178 var j: i64 = s
179 var fnd: i64 = 0
180 while fnd == 0 {
181 if j >= n { fnd = 1 } else { if path[j] == (SS_CH_DOT as u8) { e = j; fnd = 1 } else { j = j + 1 } }
182 }
183 var o: i64 = 0
184 var k: i64 = s
185 while k < e { if o < cap - 1 { out[o] = path[k]; o = o + 1 } k = k + 1 }
186 out[o] = 0 as u8
187 return o
188}
189func ss_ends(s: *u8, sfx: *u8) -> i64 {
190 let n: i64 = ss_slen(s)
191 let m: i64 = ss_slen(sfx)
192 if m > n { return 0 }
193 var i: i64 = 0
194 while i < m { if s[n - m + i] != sfx[i] { return 0 } i = i + 1 }
195 return 1
196}
197// ---------------------------------------------------------------------------------------------
198// THE NODE-BASENAME INDEX. The import/fork closure below asks "is this edge already a node?" ONCE
199// PER EDGE over ~1e6 edges against ~2e4 nodes. The linear scan every other pass in this organ uses
200// would cost 2e10 ops -- two orders of magnitude over the ~1e8-1e9 simple-ops/sec/core budget, i.e.
201// the closure would simply never finish. COUNT THE WORK BEFORE WRITING THE LOOP.
202// Open addressing; values are stored as index+1 so slot 0 can mean EMPTY without a second table.
203// ---------------------------------------------------------------------------------------------
204const SS_FNV_OFF: i64 = 2166136261 // FNV-1a 32-bit offset basis, the published constant
205const SS_FNV_PRIME: i64 = 16777619 // FNV-1a 32-bit prime, the published constant
206const SS_HMOD: i64 = 1073741824 // 2^30. Holding h under this EVERY step makes h*PRIME < 2^54,
207 // so the hash can never overflow i64 -- and a hash that
208 // overflows is a hash whose value depends on the overflow.
209func ss_hash(s: *u8) -> i64 {
210 var h: i64 = SS_FNV_OFF
211 var i: i64 = 0
212 while s[i] != (0 as u8) {
213 h = h + (s[i] as i64)
214 h = h * SS_FNV_PRIME
215 h = h % SS_HMOD
216 i = i + 1
217 }
218 if h < 0 { h = 0 - h }
219 return h % SS_HTAB
220}
221func ss_hfind(tab: *i64, base: *u8, tok: i64, name: *u8) -> i64 {
222 var slot: i64 = ss_hash(name)
223 var tries: i64 = 0
224 var res: i64 = 0 - 1
225 var run: i64 = 1
226 while run == 1 {
227 let v: i64 = tab[slot]
228 if v == 0 { run = 0 } else {
229 let idx: i64 = v - 1
230 if ss_streq((base as i64 + idx * tok) as *u8, name) == 1 { res = idx; run = 0 } else {
231 slot = slot + 1
232 if slot >= SS_HTAB { slot = 0 }
233 tries = tries + 1
234 if tries >= SS_HTAB { run = 0 }
235 }
236 }
237 }
238 return res
239}
240// returns 1 on insert, 0 if the table is full -- the caller REFUSES on 0 rather than lose a node
241// silently, because a node the index cannot see reads as "not network-capable", which is the exact
242// direction of error this whole pass exists to remove.
243func ss_hput(tab: *i64, base: *u8, tok: i64, idx: i64) -> i64 {
244 let name: *u8 = (base as i64 + idx * tok) as *u8
245 var slot: i64 = ss_hash(name)
246 var tries: i64 = 0
247 var res: i64 = 0
248 var run: i64 = 1
249 while run == 1 {
250 if tab[slot] == 0 { tab[slot] = idx + 1; res = 1; run = 0 } else {
251 slot = slot + 1
252 if slot >= SS_HTAB { slot = 0 }
253 tries = tries + 1
254 if tries >= SS_HTAB { run = 0 }
255 }
256 }
257 return res
258}
259// THE ONE HOST CLASSIFIER. It lives in a function because the first draft open-coded the sovereign
260// test in both the counting pass and the ledger-writing pass -- two rulers for one invariant, and the
261// two would have drifted the first time either was refined.
262// 0 OUTSIDE -- a real internet host this organ can and does dial. THE ONLY CLASS THAT COUNTS.
263// 1 SOVEREIGN -- served by our own hardware; still answers with no internet.
264// 2 FIXTURE -- an RFC 2606 reserved / mDNS name. It resolves nowhere: nothing breaks offline.
265// 3 SCHEME-TOKEN -- no dot, so not an internet host at all (nishi://start, doc://sota).
266// 4 NON-DIALLED -- a NAMESPACE AUTHORITY: a real host name that appears as an identifier, never
267// as a fetch (schemas.openxmlformats.org in a .docx writer). Named in conf.
268//
269// ⚠ THIS CLASS WAS FIRST BUILT AS A CAPABILITY TEST -- "does this organ call a socket primitive in
270// code?" -- AND IT OVER-CORRECTED HARD: measured 2026-08-20, OUTSIDE fell 116 -> 2, because THIS
271// ESTATE'S DISCIPLINE IS TO COMPOSE A FETCHER RATHER THAN OPEN ITS OWN SOCKET, so nx_porkbun_domain
272// and nx_acme_issue carry no sys_connect and read as not-network-capable. ★★★★★★A CAPABILITY TEST
273// THAT ASSUMES THE CAPABILITY IS EXERCISED LOCALLY IS BLIND TO EVERY WELL-FACTORED CALLER, AND ITS
274// ERROR LOOKS LIKE GOOD NEWS. The vocabulary is a NAMED LIST instead: the false positives are a small
275// enumerable set of namespace authorities, they are VISIBLE in the ledger when a new one appears, and
276// a name that is missing from the list reads OUTSIDE -- wrong in the direction of over-reporting a
277// dependency, which is the direction that gets looked at.
278func ss_hostclass(h: *u8, sovp: *i64, nsov: i64, resp: *i64, nres: i64, ndp: *i64, nnd: i64) -> i64 {
279 var sv: i64 = 0
280 while sv < nsov { if ss_starts(h, sovp[sv] as *u8) == 1 { return 1 } sv = sv + 1 }
281 var rs: i64 = 0
282 while rs < nres { if ss_ends(h, resp[rs] as *u8) == 1 { return 2 } rs = rs + 1 }
283 var dot: i64 = 0
284 var i: i64 = 0
285 while h[i] != (0 as u8) { if h[i] == (SS_CH_DOT as u8) { dot = 1 } i = i + 1 }
286 if dot == 0 { return 3 }
287 var nd: i64 = 0
288 while nd < nnd { if ss_starts(h, ndp[nd] as *u8) == 1 { return 4 } nd = nd + 1 }
289 return 0
290}
291// root + "/" + rel, into dst. The one place a path is assembled, so the root cannot be forgotten.
292func ss_path(dst: *u8, root: *u8, rel: *u8) -> i64 {
293 var o: i64 = ss_cat(dst, 0, root)
294 o = ss_catc(dst, o, SS_CH_SLASH)
295 o = ss_cat(dst, o, rel)
296 return o
297}
298func ss_identch(c: i64) -> i64 {
299 if c >= SS_CH_a { if c <= SS_CH_z { return 1 } }
300 if c >= SS_CH_A { if c <= SS_CH_Z { return 1 } }
301 if c >= SS_CH_0 { if c <= SS_CH_9 { return 1 } }
302 if c == SS_CH_USCORE { return 1 }
303 return 0
304}
305
306// ---------------------------------------------------------------------------------------------
307// THE SOURCE SCANNER. One pass per organ, line by line, tracking string-vs-comment state, because
308// BOTH halves decide the answer: a "://" in a comment is prose ABOUT a dependency, a "://" in a
309// string IS the dependency. Emits (1) every host dialled and (2) every "<name>.elf" forked.
310// cx[0] = 1 if a table filled -> the caller REFUSES rather than publish a floor as a total.
311// ---------------------------------------------------------------------------------------------
312func ss_scan(buf: *u8, n: i64, harena: *u8, ho: *i64, hp: *i64, hn: *i64, hcapn: i64,
313 earena: *u8, eo: *i64, ep: *i64, en: *i64, ecapn: i64, cx: *i64,
314 mk: *i64, nmk: i64, netout: *i64) -> i64 {
315 netout[0] = 0
316 netout[1] = 0
317 // ---- PASS 1: IMPORT EDGES ONLY, and it is a SEPARATE PASS on purpose. It makes each organ's edge
318 // range SPLIT -- imports first, forks after -- so the autonomy axis can consume FORK EDGES ALONE.
319 // BEING IMPORTED IS NOT BEING INVOKED: a library pulled in by an unrostered organ is no more
320 // autonomous for it. Built as ONE interleaved list the first time, and it silently dropped
321 // seat_only 496 -> 353 and the RANKED claude_loop axis 18 -> 17 -- an UNDER-report of
322 // Claude-dependency, which is the flattering direction and the exact class this organ exists to
323 // remove. An interleaved list cannot be split after the fact, so the split is made here.
324 //
325 // AN ORGAN THAT REACHES THE NETWORK THROUGH A HELPER IS NETWORK-DEPENDENT, and neither a url
326 // literal nor a ".elf" fork literal can see that: the helper arrives by IMPORT and is CALLED.
327 // Line-start anchoring is what the estate's own import resolver requires, so the word "import"
328 // inside prose or inside a string literal cannot manufacture an edge.
329 // netout[1] carries the import count: netcx is a 16-byte mmap, i.e. TWO i64 slots, so this needs
330 // no new parameter and therefore leaves no intermediate state that does not compile.
331 var ip: i64 = 0
332 while ip < n {
333 let iplend: i64 = ss_eol(buf, ip, n)
334 var iw: i64 = ip
335 var wsr: i64 = 1
336 while wsr == 1 {
337 if iw >= iplend { wsr = 0 } else {
338 let wc: i64 = buf[iw] as i64
339 if wc == SS_CH_SP { iw = iw + 1 } else { if wc == SS_CH_TAB { iw = iw + 1 } else { wsr = 0 } }
340 }
341 }
342 if iw < iplend { if ss_starts((buf as i64 + iw) as *u8, "import " as *u8) == 1 {
343 var qs: i64 = 0 - 1
344 var qe: i64 = 0 - 1
345 var qq: i64 = iw + 7
346 while qq < iplend {
347 if buf[qq] == (SS_CH_QUOTE as u8) {
348 if qs < 0 { qs = qq + 1 } else { if qe < 0 { qe = qq } }
349 }
350 qq = qq + 1
351 }
352 if qs > 0 { if qe > qs {
353 var ibs: i64 = qs
354 var iz: i64 = qs
355 while iz < qe { if buf[iz] == (SS_CH_SLASH as u8) { ibs = iz + 1 } iz = iz + 1 }
356 var ibe: i64 = qe
357 if ibe - ibs > 3 { if ss_starts((buf as i64 + ibe - 3) as *u8, ".nx" as *u8) == 1 { ibe = ibe - 3 } }
358 if ibe > ibs {
359 if en[0] < ecapn {
360 let ist: i64 = eo[0]
361 var iq: i64 = ist
362 var iz2: i64 = ibs
363 while iz2 < ibe { earena[iq] = buf[iz2]; iq = iq + 1; iz2 = iz2 + 1 }
364 earena[iq] = 0 as u8; iq = iq + 1
365 ep[en[0]] = (earena as i64) + ist
366 en[0] = en[0] + 1
367 eo[0] = iq
368 netout[1] = netout[1] + 1
369 } else { cx[0] = 1 }
370 }
371 } }
372 } }
373 ip = iplend + 1
374 }
375 // ---- PASS 2: hosts dialled, and ".elf" FORK literals.
376 var i: i64 = 0
377 while i < n {
378 let lend: i64 = ss_eol(buf, i, n)
379 var ins: i64 = 0
380 var j: i64 = i
381 var stop: i64 = 0
382 while j < lend {
383 if stop == 0 {
384 let c: i64 = buf[j] as i64
385 if ins == 0 {
386 // NETWORK CAPABILITY, in CODE (not in a string, not in a comment).
387 // ⚠ THIS NO LONGER GATES THE HOST CLASSES, and the comment that used to say it did
388 // outlived the code by a whole build. It was tried as the host gate and OVER-
389 // CORRECTED: OUTSIDE fell 116 -> 2, because this estate COMPOSES A FETCHER rather
390 // than opening its own socket, so nx_porkbun_domain and nx_acme_issue carry no
391 // sys_connect and read as not-network-capable. The false-positive problem it was
392 // reaching for -- an XML namespace URI in a .docx writer -- is solved by the NAMED
393 // nondialled_host list instead, which is wrong in the direction of OVER-reporting.
394 // What this flag IS now: the DIRECT half of the transitive net-reach below.
395 if netout[0] == 0 {
396 var m: i64 = 0
397 while m < nmk {
398 let mp: *u8 = mk[m] as *u8
399 if buf[j] == mp[0] { if ss_starts((buf as i64 + j) as *u8, mp) == 1 {
400 // DEFINING a syscall wrapper is not CALLING the network. Without this
401 // exclusion nx_syscalls.nx -- which DECLARES sys_connect -- reads
402 // network-capable, every organ in the estate imports it, and the
403 // transitive answer saturates at 100 percent. A SIGNAL THAT FIRES ON
404 // EVERYTHING DISCRIMINATES NOTHING, so the closure would be worthless
405 // in the direction that looks like thoroughness.
406 var isdef: i64 = 0
407 if j - i >= 5 { if ss_starts((buf as i64 + j - 5) as *u8, "func " as *u8) == 1 { isdef = 1 } }
408 if isdef == 0 { netout[0] = 1; m = nmk }
409 } }
410 m = m + 1
411 }
412 }
413 if c == SS_CH_QUOTE { ins = 1 } else {
414 if c == SS_CH_SLASH { if j + 1 < lend { if buf[j+1] == (SS_CH_SLASH as u8) { stop = 1 } } }
415 }
416 } else {
417 if c == SS_CH_BSLASH { j = j + 1 } else {
418 if c == SS_CH_QUOTE { ins = 0 } else {
419 // "://" -> the host token that follows, up to the first delimiter
420 if c == SS_CH_COLON { if j + 3 < lend { if ss_starts((buf as i64 + j) as *u8, "://" as *u8) == 1 {
421 var k: i64 = j + 3
422 let hs: i64 = k
423 var run: i64 = 1
424 while run == 1 {
425 if k >= lend { run = 0 } else {
426 let dd: i64 = buf[k] as i64
427 if dd == SS_CH_SLASH { run = 0 } else {
428 if dd == SS_CH_QUOTE { run = 0 } else {
429 if dd == SS_CH_COLON { run = 0 } else {
430 if dd == SS_CH_SP { run = 0 } else {
431 if dd == SS_CH_QMARK { run = 0 } else {
432 // a backslash ENDS the host: the next bytes are a string escape,
433 // not more hostname. Without this "host\x00" and "host\r\n" were
434 // captured whole and read as two different hosts.
435 if dd == SS_CH_BSLASH { run = 0 } else { k = k + 1 } } } } } }
436 }
437 }
438 if k > hs {
439 if hn[0] < hcapn {
440 let st: i64 = ho[0]
441 var z: i64 = hs
442 var w: i64 = st
443 while z < k { harena[w] = buf[z]; w = w + 1; z = z + 1 }
444 harena[w] = 0 as u8; w = w + 1
445 hp[hn[0]] = (harena as i64) + st
446 hn[0] = hn[0] + 1
447 ho[0] = w
448 } else { cx[0] = 1 }
449 }
450 j = k - 1
451 } } }
452 // "<name>.elf" -> a fork target; back up to the token start so "./x.elf" and
453 // "_offc/x.elf" both yield "x".
454 if c == SS_CH_DOT { if j + 3 < lend { if ss_starts((buf as i64 + j) as *u8, ".elf" as *u8) == 1 {
455 var b2: i64 = j - 1
456 var bs: i64 = j
457 var runb: i64 = 1
458 while runb == 1 {
459 if b2 < i { runb = 0 } else {
460 let d2: i64 = buf[b2] as i64
461 if ss_identch(d2) == 1 { bs = b2; b2 = b2 - 1 } else { runb = 0 }
462 }
463 }
464 if j > bs {
465 if en[0] < ecapn {
466 let st2: i64 = eo[0]
467 var z2: i64 = bs
468 var w2: i64 = st2
469 while z2 < j { earena[w2] = buf[z2]; w2 = w2 + 1; z2 = z2 + 1 }
470 earena[w2] = 0 as u8; w2 = w2 + 1
471 ep[en[0]] = (earena as i64) + st2
472 en[0] = en[0] + 1
473 eo[0] = w2
474 } else { cx[0] = 1 }
475 }
476 j = j + 3
477 } } }
478 } }
479 }
480 }
481 j = j + 1
482 }
483 i = lend + 1
484 }
485 return 0
486}
487
488// ---------------------------------------------------------------------------------------------
489func main(argc: i64, argv: *i64) -> i64 {
490 var verb: *u8 = "census" as *u8
491 if argc > 1 { verb = argv[1] as *u8 }
492 var root: *u8 = "." as *u8
493 if ss_streq(verb, "ledger" as *u8) == 1 { if argc > 2 { root = argv[2] as *u8 } }
494 else { if argc > 3 { root = argv[3] as *u8 } }
495 let ledpath: *u8 = sys_mmap(700)
496 ss_path(ledpath, root, "knowledge/status/selfsuff.ledger" as *u8)
497 if ss_streq(verb, "ledger" as *u8) == 1 {
498 let lb: *u8 = sys_mmap(SS_LEDGER_CAP)
499 let ln2: i64 = ss_read(ledpath, lb, SS_LEDGER_CAP - 8)
500 if ln2 <= 0 { ss_puts("SELFSUFF LEDGER ABSENT: " as *u8); ss_puts(ledpath); ss_puts(" -- run: nx_selfsuff census" as *u8); ss_nl(); return 3 }
501 sys_write(1, lb, ln2)
502 return 0
503 }
504 if ss_streq(verb, "census" as *u8) == 0 {
505 ss_puts("usage: nx_selfsuff census [action-journal] [root] | nx_selfsuff ledger [root]" as *u8); ss_nl(); return 2
506 }
507 var jpath: *u8 = 0 as *u8
508 if argc > 2 { if ss_streq(argv[2] as *u8, "-" as *u8) == 0 { jpath = argv[2] as *u8 } }
509
510 // ---- conf: sovereign host prefixes + the autonomy sources. DATA, never literals in here. ----
511 let cpath: *u8 = sys_mmap(700)
512 ss_path(cpath, root, "buildroot/knowledge/compare/selfsuff.conf" as *u8)
513 let cbuf: *u8 = sys_mmap(SS_FILE_CAP)
514 let cn: i64 = ss_read(cpath, cbuf, SS_FILE_CAP - 8)
515 if cn <= 0 { ss_puts("SELFSUFF REFUSED: no conf at " as *u8); ss_puts(cpath); ss_puts(" -- the sovereign-host vocabulary and the autonomy sources are DATA; without them every host reads OUTSIDE and every organ SEAT-ONLY, which is a confident wrong answer" as *u8); ss_nl(); return 3 }
516 let sovp: *i64 = sys_mmap(128 * 8) as *i64
517 var nsov: i64 = 0
518 let resp: *i64 = sys_mmap(64 * 8) as *i64
519 var nres: i64 = 0
520 let mkp: *i64 = sys_mmap(64 * 8) as *i64
521 var nmk: i64 = 0
522 let ndp: *i64 = sys_mmap(64 * 8) as *i64
523 var nnd: i64 = 0
524 let autof: *i64 = sys_mmap(64 * 8) as *i64
525 var nautof: i64 = 0
526 let autopl: *i64 = sys_mmap(16 * 8) as *i64
527 var nautopl: i64 = 0
528 var cp: i64 = 0
529 while cp < cn {
530 let clend: i64 = ss_eol(cbuf, cp, cn)
531 cbuf[clend] = 0 as u8
532 let cl: *u8 = (cbuf as i64 + cp) as *u8
533 cp = clend + 1
534 if cl[0] != (0 as u8) { if cl[0] != (SS_CH_HASH as u8) {
535 var eqi: i64 = 0 - 1
536 var q: i64 = 0
537 while cl[q] != (0 as u8) { if cl[q] == (SS_CH_EQ as u8) { if eqi < 0 { eqi = q } } q = q + 1 }
538 if eqi > 0 {
539 cl[eqi] = 0 as u8
540 let val: *u8 = (cl as i64 + eqi + 1) as *u8
541 if ss_streq(cl, "sovereign" as *u8) == 1 { if nsov < 128 { sovp[nsov] = val as i64; nsov = nsov + 1 } }
542 if ss_streq(cl, "reserved_suffix" as *u8) == 1 { if nres < 64 { resp[nres] = val as i64; nres = nres + 1 } }
543 if ss_streq(cl, "netmarker" as *u8) == 1 { if nmk < 64 { mkp[nmk] = val as i64; nmk = nmk + 1 } }
544 if ss_streq(cl, "nondialled_host" as *u8) == 1 { if nnd < 64 { ndp[nnd] = val as i64; nnd = nnd + 1 } }
545 if ss_streq(cl, "auto_file" as *u8) == 1 { if nautof < 64 { autof[nautof] = val as i64; nautof = nautof + 1 } }
546 if ss_streq(cl, "auto_plane" as *u8) == 1 { if nautopl < 16 { autopl[nautopl] = val as i64; nautopl = nautopl + 1 } }
547 }
548 } }
549 }
550 ss_puts("=== NX-SELFSUFF CENSUS root=" as *u8); ss_puts(root); ss_puts(" conf sovereign_prefixes=" as *u8); ss_pn(nsov)
551 ss_puts(" reserved_suffixes=" as *u8); ss_pn(nres); ss_puts(" nondialled_hosts=" as *u8); ss_pn(nnd); ss_puts(" netmarkers=" as *u8); ss_pn(nmk)
552 ss_puts(" auto_files=" as *u8); ss_pn(nautof); ss_puts(" auto_planes=" as *u8); ss_pn(nautopl); ss_nl()
553 if nnd == 0 { ss_puts("SELFSUFF REFUSED: no nondialled_host= rows -- without them every XML namespace authority reads as a dialled host and the detector becomes a false-positive machine" as *u8); ss_nl(); return 3 }
554
555 // ---- domains from regen.list (the SAME list the compare generator drives from) ----
556 let rpath: *u8 = sys_mmap(700)
557 ss_path(rpath, root, "buildroot/knowledge/compare/regen.list" as *u8)
558 let rbuf: *u8 = sys_mmap(SS_FILE_CAP)
559 let rn: i64 = ss_read(rpath, rbuf, SS_FILE_CAP - 8)
560 if rn <= 0 { ss_puts("SELFSUFF REFUSED: no regen.list at " as *u8); ss_puts(rpath); ss_nl(); return 3 }
561 let dnm: *i64 = sys_mmap(SS_MAX_DOM * 8) as *i64
562 var ndom: i64 = 0
563 var domcapped: i64 = 0
564 var rp: i64 = 0
565 while rp < rn {
566 let rlend: i64 = ss_eol(rbuf, rp, rn)
567 rbuf[rlend] = 0 as u8
568 let rl: *u8 = (rbuf as i64 + rp) as *u8
569 rp = rlend + 1
570 if rl[0] != (0 as u8) { if rl[0] != (SS_CH_HASH as u8) {
571 if ndom < SS_MAX_DOM { dnm[ndom] = rl as i64; ndom = ndom + 1 } else { domcapped = 1 }
572 } }
573 }
574 if domcapped == 1 { ss_puts("SELFSUFF REFUSED: regen.list exceeds SS_MAX_DOM -- this would publish a PREFIX as a population" as *u8); ss_nl(); return 4 }
575
576 // ---- organ table: DEDUPE TO SUBJECTS. A reference count is not a work count. ----
577 let onm: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
578 let odom: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
579 let orefs: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
580 let namearena: *u8 = sys_mmap(SS_NAME_ARENA)
581 var nao: i64 = 0
582 var norg: i64 = 0
583 var orgcapped: i64 = 0
584 var rowsseen: i64 = 0
585 let fld: *i64 = sys_mmap(SS_FIELDS * 8) as *i64
586 let mbuf: *u8 = sys_mmap(SS_FILE_CAP)
587 let mpath: *u8 = sys_mmap(700)
588 let drows: *i64 = sys_mmap(SS_MAX_DOM * 8) as *i64
589 var d: i64 = 0
590 while d < ndom { drows[d] = 0; d = d + 1 }
591 var nomatrix: i64 = 0
592 d = 0
593 while d < ndom {
594 var mo: i64 = ss_cat(mpath, 0, root)
595 mo = ss_cat(mpath, mo, "/buildroot/knowledge/compare/" as *u8)
596 mo = ss_cat(mpath, mo, dnm[d] as *u8)
597 mo = ss_cat(mpath, mo, ".matrix" as *u8)
598 let mn: i64 = ss_read(mpath, mbuf, SS_FILE_CAP - 8)
599 if mn <= 0 { nomatrix = nomatrix + 1 } else {
600 var mp: i64 = 0
601 while mp < mn {
602 let mlend: i64 = ss_eol(mbuf, mp, mn)
603 mbuf[mlend] = 0 as u8
604 let ml: *u8 = (mbuf as i64 + mp) as *u8
605 mp = mlend + 1
606 if ml[0] != (0 as u8) { if ml[0] != (SS_CH_AT as u8) { if ml[0] != (SS_CH_HASH as u8) {
607 let nf: i64 = ss_split(ml, fld, SS_FIELDS)
608 if nf >= 3 {
609 let org: *u8 = fld[1] as *u8
610 if org[0] != (0 as u8) { if ss_streq(org, "-" as *u8) == 0 {
611 rowsseen = rowsseen + 1
612 drows[d] = drows[d] + 1
613 var hit: i64 = 0 - 1
614 var t: i64 = 0
615 while t < norg { if ss_streq(onm[t] as *u8, org) == 1 { hit = t; t = norg } t = t + 1 }
616 if hit >= 0 { orefs[hit] = orefs[hit] + 1 } else {
617 if norg < SS_MAX_ORG {
618 let st: i64 = nao
619 let cpy: i64 = ss_cat(namearena, st, org)
620 nao = cpy + 1
621 onm[norg] = (namearena as i64) + st
622 odom[norg] = d
623 orefs[norg] = 1
624 norg = norg + 1
625 } else { orgcapped = 1 }
626 }
627 } }
628 }
629 } } }
630 }
631 }
632 d = d + 1
633 }
634 if orgcapped == 1 { ss_puts("SELFSUFF REFUSED: distinct organs exceed SS_MAX_ORG -- a prefix is not a population" as *u8); ss_nl(); return 4 }
635 ss_puts("SUBJECTS domains=" as *u8); ss_pn(ndom); ss_puts(" no_matrix=" as *u8); ss_pn(nomatrix)
636 ss_puts(" matrix_rows=" as *u8); ss_pn(rowsseen); ss_puts(" distinct_organs=" as *u8); ss_pn(norg)
637 ss_puts(" (a reference count is not a work count: " as *u8); ss_pn(rowsseen); ss_puts(" refs collapse to " as *u8); ss_pn(norg); ss_puts(" subjects)" as *u8); ss_nl()
638
639 // ---- scan every distinct organ ONCE. One buffer, reused: never allocate in a hot loop. ----
640 let harena: *u8 = sys_mmap(SS_HOST_ARENA)
641 let hoff: *i64 = sys_mmap(16) as *i64
642 hoff[0] = 0
643 let hptr: *i64 = sys_mmap(SS_HOST_MAX * 8) as *i64
644 let hcnt: *i64 = sys_mmap(16) as *i64
645 hcnt[0] = 0
646 let earena: *u8 = sys_mmap(SS_EDGE_ARENA)
647 let eoff: *i64 = sys_mmap(16) as *i64
648 eoff[0] = 0
649 let eptr: *i64 = sys_mmap(SS_EDGE_MAX * 8) as *i64
650 let ecnt: *i64 = sys_mmap(16) as *i64
651 ecnt[0] = 0
652 let cx: *i64 = sys_mmap(64) as *i64
653 cx[0] = 0
654
655 let ohs: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
656 let ohn: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
657 let oes: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
658 let oen: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
659 let oout: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
660 let oind: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
661 let oseat: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
662 let ofreq: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
663 let oread: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
664 let onet: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
665 let oaux: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
666 let oimp: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
667 let netcx: *i64 = sys_mmap(16) as *i64
668 let sbuf: *u8 = sys_mmap(SS_SRC_CAP)
669 let spath: *u8 = sys_mmap(700)
670 let cpath2: *u8 = sys_mmap(700)
671 // THE CLOSURE'S NODE INDEX. obase is filled AS NODES ARE ADDED -- it used to be filled after the
672 // scan, which is impossible once the scan itself discovers nodes.
673 let obase: *u8 = sys_mmap(SS_MAX_ORG * SS_TOK)
674 let htab: *i64 = sys_mmap(SS_HTAB * 8) as *i64
675 var hz: i64 = 0
676 while hz < SS_HTAB { htab[hz] = 0; hz = hz + 1 }
677 // nmatrix FREEZES the PUBLISHED population before the closure grows the node table. Every count
678 // the ledger, the domain roll-up and the host partition print is bounded by THIS, never by norg:
679 // a carrier the closure pulls in is EVIDENCE, not a subject, and folding it into the published
680 // partition would silently redefine the population -- the exact overlap the estate's own law
681 // forbids (a new bucket that overlaps an existing partition must be a SEPARATE AXIS).
682 let nmatrix: i64 = norg
683 var hfull: i64 = 0
684 var o: i64 = 0
685 while o < norg {
686 oaux[o] = 0
687 ss_base(onm[o] as *u8, (obase as i64 + o * SS_TOK) as *u8, SS_TOK)
688 if ss_hput(htab, obase, SS_TOK, o) == 0 { hfull = 1 }
689 o = o + 1
690 }
691 var unreadable: i64 = 0
692 var srccap: i64 = 0
693 var closcap: i64 = 0
694 var auxadded: i64 = 0
695 var auxunres: i64 = 0
696 var totimp: i64 = 0
697 o = 0
698 while o < norg {
699 oout[o] = 0; oind[o] = 0; oseat[o] = 0; ofreq[o] = 0; onet[o] = 0; oimp[o] = 0
700 ohs[o] = hcnt[0]; oes[o] = ecnt[0]; ohn[o] = 0; oen[o] = 0
701 var so: i64 = ss_cat(spath, 0, root)
702 so = ss_cat(spath, so, "/buildroot/" as *u8)
703 so = ss_cat(spath, so, onm[o] as *u8)
704 let sn: i64 = ss_read(spath, sbuf, SS_SRC_CAP - 8)
705 if sn <= 0 { oread[o] = 0; unreadable = unreadable + 1 } else {
706 oread[o] = 1
707 if sn >= SS_SRC_CAP - 8 { srccap = srccap + 1 }
708 ss_scan(sbuf, sn, harena, hoff, hptr, hcnt, SS_HOST_MAX, earena, eoff, eptr, ecnt, SS_EDGE_MAX, cx, mkp, nmk, netcx)
709 onet[o] = netcx[0]
710 oimp[o] = netcx[1]
711 totimp = totimp + netcx[1]
712 ohn[o] = hcnt[0] - ohs[o]
713 oen[o] = ecnt[0] - oes[o]
714 // ---- FRONTIER EXPANSION, breadth-first: every edge name that is not yet a node BECOMES
715 // one, and this loop keeps walking because norg grows underneath it. The graph is the
716 // import/fork graph lane F proved ACYCLIC, and the node index makes membership O(1), so
717 // the walk terminates and stays inside budget. Probe order MATCHES THE BUILDER's
718 // (_hdl_build first, then runtime) -- report on the file that actually compiles.
719 var k: i64 = 0
720 while k < oen[o] {
721 let enm: *u8 = eptr[oes[o] + k] as *u8
722 if ss_hfind(htab, obase, SS_TOK, enm) < 0 {
723 if norg >= SS_MAX_ORG { closcap = 1 } else {
724 var rp2: i64 = ss_cat(cpath2, 0, root)
725 rp2 = ss_cat(cpath2, rp2, "/buildroot/runtime/_hdl_build/" as *u8)
726 rp2 = ss_cat(cpath2, rp2, enm)
727 rp2 = ss_cat(cpath2, rp2, ".nx" as *u8)
728 var rel: i64 = 0
729 var probe: i64 = sys_openat_rd(cpath2)
730 if probe >= 0 { sys_close(probe); rel = 1 } else {
731 rp2 = ss_cat(cpath2, 0, root)
732 rp2 = ss_cat(cpath2, rp2, "/buildroot/runtime/" as *u8)
733 rp2 = ss_cat(cpath2, rp2, enm)
734 rp2 = ss_cat(cpath2, rp2, ".nx" as *u8)
735 probe = sys_openat_rd(cpath2)
736 if probe >= 0 { sys_close(probe); rel = 2 }
737 }
738 // an edge that resolves to NO source is not a silent zero: it is a fork target
739 // whose subject is absent, and it is COUNTED so the reader can see how much of
740 // the closure could not be walked.
741 if rel == 0 { auxunres = auxunres + 1 } else {
742 let st4: i64 = nao
743 var c4: i64 = st4
744 if rel == 1 { c4 = ss_cat(namearena, c4, "runtime/_hdl_build/" as *u8) } else { c4 = ss_cat(namearena, c4, "runtime/" as *u8) }
745 c4 = ss_cat(namearena, c4, enm)
746 c4 = ss_cat(namearena, c4, ".nx" as *u8)
747 nao = c4 + 1
748 onm[norg] = (namearena as i64) + st4
749 odom[norg] = odom[o]
750 orefs[norg] = 0
751 oaux[norg] = 1
752 ss_base(onm[norg] as *u8, (obase as i64 + norg * SS_TOK) as *u8, SS_TOK)
753 if ss_hput(htab, obase, SS_TOK, norg) == 0 { hfull = 1 }
754 norg = norg + 1
755 auxadded = auxadded + 1
756 }
757 }
758 }
759 k = k + 1
760 }
761 }
762 o = o + 1
763 }
764 if closcap == 1 { ss_puts("SELFSUFF REFUSED: the import/fork closure exceeded SS_MAX_ORG -- a PARTIAL closure published as a total is exactly the under-report this pass exists to remove" as *u8); ss_nl(); return 4 }
765 if hfull == 1 { ss_puts("SELFSUFF REFUSED: the node index filled -- a node the index cannot see reads as NOT network-capable, which is the flattering direction" as *u8); ss_nl(); return 4 }
766 if srccap > 0 { ss_puts("SELFSUFF REFUSED: " as *u8); ss_pn(srccap); ss_puts(" source(s) filled SS_SRC_CAP -- a truncated read cannot support an ABSENCE claim about a host literal" as *u8); ss_nl(); return 4 }
767 if cx[0] == 1 { ss_puts("SELFSUFF REFUSED: host or edge table filled -- this would publish a FLOOR as a total" as *u8); ss_nl(); return 4 }
768
769 // ---- classify hosts: DISTINCT outside hosts per organ, sovereign prefixes from conf ----
770 var totout: i64 = 0
771 var totsov: i64 = 0
772 var totfix: i64 = 0
773 var totsch: i64 = 0
774 var totnd: i64 = 0
775 var auxout: i64 = 0
776 o = 0
777 while o < norg {
778 // A CARRIER THE CLOSURE PULLED IN IS EVIDENCE, NOT A SUBJECT. Its hosts set its OWN
779 // direct-network flag -- that is the whole point of walking to it -- but they must NOT enter
780 // the published host partition, or the population every downstream reader and the gate assert
781 // against would change silently underneath them.
782 var pub: i64 = 0
783 if o < nmatrix { pub = 1 }
784 var k: i64 = 0
785 while k < ohn[o] {
786 let hh: *u8 = hptr[ohs[o] + k] as *u8
787 let cls: i64 = ss_hostclass(hh, sovp, nsov, resp, nres, ndp, nnd)
788 if pub == 1 {
789 if cls == 1 { totsov = totsov + 1 }
790 if cls == 2 { totfix = totfix + 1 }
791 if cls == 3 { totsch = totsch + 1 }
792 if cls == 4 { totnd = totnd + 1 }
793 if cls == 0 { totout = totout + 1 }
794 } else { if cls == 0 { auxout = auxout + 1 } }
795 if cls == 0 {
796 var dup: i64 = 0
797 var k2: i64 = 0
798 while k2 < k { if ss_streq(hptr[ohs[o] + k2] as *u8, hh) == 1 { dup = 1; k2 = k } k2 = k2 + 1 }
799 if dup == 0 { oout[o] = oout[o] + 1 }
800 }
801 k = k + 1
802 }
803 o = o + 1
804 }
805
806 // ---- TRANSITIVE NETWORK REACH. This REPLACES a 1-hop propagation that could only see a carrier
807 // an organ FORKS, and was therefore blind to the helper an organ IMPORTS -- which is how this
808 // estate actually reaches the network (compose a fetcher, never open your own socket). A measure
809 // that misses the via-helper case UNDER-REPORTS outside dependency, and that is the direction
810 // that flatters us. Both edge kinds now sit in one list and the reach is a FIXPOINT, not one hop:
811 // lane F proved this graph ACYCLIC over 18,945 nodes, so it converges; exceeding SS_NET_ITER
812 // REFUSES rather than publish a partial closure as a total.
813 // onetD[o] = DIRECT -- o CALLS a network primitive itself, or dials an OUTSIDE host itself
814 // onetT[o] = REACHES -- DIRECT, or reaches a DIRECT node over import/fork edges (VIA-HELPER)
815 let onetT: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
816 let onetD: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
817 o = 0
818 while o < norg {
819 var dir: i64 = 0
820 if onet[o] == 1 { dir = 1 }
821 if oout[o] > 0 { dir = 1 }
822 onetD[o] = dir
823 onetT[o] = dir
824 o = o + 1
825 }
826 var netiter: i64 = 0
827 var netmoved: i64 = 1
828 var netover: i64 = 0
829 while netmoved == 1 {
830 netmoved = 0
831 netiter = netiter + 1
832 if netiter > SS_NET_ITER { netover = 1 } else {
833 o = 0
834 while o < norg {
835 if onetT[o] == 0 {
836 var k6: i64 = 0
837 while k6 < oen[o] {
838 let e6: *u8 = eptr[oes[o] + k6] as *u8
839 let t6: i64 = ss_hfind(htab, obase, SS_TOK, e6)
840 if t6 >= 0 { if t6 != o { if onetT[t6] == 1 { onetT[o] = 1; netmoved = 1; k6 = oen[o] } } }
841 k6 = k6 + 1
842 }
843 }
844 o = o + 1
845 }
846 }
847 }
848 if netover == 1 { ss_puts("SELFSUFF REFUSED: transitive net-reach did not converge inside SS_NET_ITER -- a partial closure is the flattering direction" as *u8); ss_nl(); return 4 }
849 // ---- CARRIER COUNT: DISTINCT one-hop neighbours that themselves dial an outside host. HELD AT
850 // ONE HOP DELIBERATELY -- it is the ranker's coefficient input, and widening it to the closure
851 // would silently re-price every rung in the estate off the back of a measurement change. The
852 // transitive answer is published BESIDE it as its own axis, not folded into it.
853 o = 0
854 while o < norg {
855 var k: i64 = 0
856 while k < oen[o] {
857 let en2: *u8 = eptr[oes[o] + k] as *u8
858 var dup2: i64 = 0
859 var k3: i64 = 0
860 while k3 < k { if ss_streq(eptr[oes[o] + k3] as *u8, en2) == 1 { dup2 = 1; k3 = k } k3 = k3 + 1 }
861 if dup2 == 0 {
862 let j2: i64 = ss_hfind(htab, obase, SS_TOK, en2)
863 if j2 >= 0 { if j2 != o { if oout[j2] > 0 { oind[o] = oind[o] + 1 } } }
864 }
865 k = k + 1
866 }
867 o = o + 1
868 }
869
870 // ---- AUTONOMY: the conf's clock planes + registries, UNION every fork edge in the corpus. ----
871 // Over-counting autonomy is DELIBERATE: it makes seat_only wrong toward REPORTING LESS.
872 let abuf: *u8 = sys_mmap(SS_AUTO_CAP)
873 var autobytes: i64 = 0
874 var autosrc: i64 = 0
875 var afmissing: i64 = 0
876 var planetrunc: i64 = 0
877 let apath: *u8 = sys_mmap(700)
878 let sppath: *u8 = sys_mmap(700)
879 ss_path(sppath, root, "nx_store_put.elf" as *u8)
880 var pl: i64 = 0
881 while pl < nautopl {
882 let pav: *i64 = sys_mmap(8 * 8) as *i64
883 pav[0] = sppath as i64
884 pav[1] = autopl[pl]
885 pav[2] = "load" as *u8 as i64
886 pav[3] = 0
887 let pout: *u8 = sys_mmap(SS_FORK_CAP)
888 let polen: *i64 = sys_mmap(16) as *i64
889 polen[0] = 0
890 tr_run_capture(sppath, pav, pout, SS_FORK_CAP - 1, polen)
891 if polen[0] >= SS_FORK_CAP - 1 { planetrunc = planetrunc + 1 }
892 if polen[0] > 0 {
893 if autobytes + polen[0] < SS_AUTO_CAP - 8 {
894 var z3: i64 = 0
895 while z3 < polen[0] { abuf[autobytes + z3] = pout[z3]; z3 = z3 + 1 }
896 autobytes = autobytes + polen[0]
897 abuf[autobytes] = SS_CH_NL as u8; autobytes = autobytes + 1
898 autosrc = autosrc + 1
899 }
900 } else { afmissing = afmissing + 1 }
901 pl = pl + 1
902 }
903 var af: i64 = 0
904 while af < nautof {
905 ss_path(apath, root, autof[af] as *u8)
906 let an: i64 = ss_read(apath, (abuf as i64 + autobytes) as *u8, SS_AUTO_CAP - autobytes - 8)
907 if an > 0 { autobytes = autobytes + an; abuf[autobytes] = SS_CH_NL as u8; autobytes = autobytes + 1; autosrc = autosrc + 1 } else { afmissing = afmissing + 1 }
908 af = af + 1
909 }
910 abuf[autobytes] = 0 as u8
911 // REFUSE BEFORE THE LEDGER IS WRITTEN, never after: a truncated autonomy corpus INVENTS seat-only
912 // organs, and a ledger already on disk is what the ranker would read.
913 if planetrunc > 0 { ss_puts("SELFSUFF REFUSED: a clock-plane capture filled SS_FORK_CAP -- a truncated autonomy corpus invents seat-only organs" as *u8); ss_nl(); return 4 }
914 if autobytes >= SS_AUTO_CAP - 16 { ss_puts("SELFSUFF REFUSED: the autonomy corpus filled SS_AUTO_CAP -- same defect, same refusal" as *u8); ss_nl(); return 4 }
915 var autoobserved: i64 = 1
916 if autobytes <= 0 { autoobserved = 0 }
917 // ONE pass over the autonomy corpus: extract identifier tokens and mark the organ they name.
918 // (The inverse -- substring-searching the corpus once per organ -- is O(bytes x organs) and was
919 // the first draft's real cost; count the work before writing the loop.)
920 let oauto: *i64 = sys_mmap(SS_MAX_ORG * 8) as *i64
921 o = 0
922 while o < norg { oauto[o] = 0; o = o + 1 }
923 var autotok: i64 = 0
924 if autoobserved == 1 {
925 var z4: i64 = 0
926 while z4 < autobytes {
927 if ss_identch(abuf[z4] as i64) == 1 {
928 let ts: i64 = z4
929 var run2: i64 = 1
930 while run2 == 1 { if z4 < autobytes { if ss_identch(abuf[z4] as i64) == 1 { z4 = z4 + 1 } else { run2 = 0 } } else { run2 = 0 } }
931 let save: u8 = abuf[z4]
932 abuf[z4] = 0 as u8
933 let tok: *u8 = (abuf as i64 + ts) as *u8
934 autotok = autotok + 1
935 var j3: i64 = 0
936 while j3 < norg {
937 let bn3: *u8 = (obase as i64 + j3 * SS_TOK) as *u8
938 if bn3[0] == tok[0] { if ss_streq(bn3, tok) == 1 { oauto[j3] = 1; j3 = norg } }
939 j3 = j3 + 1
940 }
941 abuf[z4] = save
942 } else { z4 = z4 + 1 }
943 }
944 }
945 // FORKED by anything in the corpus also counts as autonomy -- and FORKED is the operative word.
946 // Each organ's edge range is [oes, oes+oimp) IMPORTS then [oes+oimp, oes+oen) FORKS, so the scan
947 // starts past the import prefix. BEING IMPORTED IS NOT BEING INVOKED: counting imports here read
948 // 143 more organs as autonomous and moved the RANKED claude_loop axis 18 -> 17, i.e. it made the
949 // estate look more autonomous than it is. A measurement change that flatters is the one to catch.
950 var o5: i64 = 0
951 while o5 < norg {
952 var e5: i64 = oes[o5] + oimp[o5]
953 let e5end: i64 = oes[o5] + oen[o5]
954 while e5 < e5end {
955 let en5: *u8 = eptr[e5] as *u8
956 let j5: i64 = ss_hfind(htab, obase, SS_TOK, en5)
957 if j5 >= 0 { oauto[j5] = 1 }
958 e5 = e5 + 1
959 }
960 o5 = o5 + 1
961 }
962 var seatonly: i64 = 0
963 var seatonly_nosrc: i64 = 0
964 var seatunobs: i64 = 0
965 o = 0
966 while o < nmatrix {
967 if autoobserved == 0 { oseat[o] = 0 - 1; seatunobs = seatunobs + 1 } else {
968 if oauto[o] == 0 {
969 oseat[o] = 1
970 // an organ with NO SOURCE cannot be forked by anything, so counting it beside real
971 // organs would merge a WATCH CONTRACT with a wired-but-unautomated capability
972 if oread[o] == 1 { seatonly = seatonly + 1 } else { seatonly_nosrc = seatonly_nosrc + 1 }
973 } else { oseat[o] = 0 }
974 }
975 o = o + 1
976 }
977
978 // ---- FREQUENCY from the action record (optional): how often a seat actually reaches for it ----
979 var jframes: i64 = 0
980 var jtrunc: i64 = 0
981 var jlines: i64 = 0
982 if jpath != (0 as *u8) {
983 let jfull: *u8 = sys_mmap(700)
984 ss_path(jfull, root, jpath)
985 let jbuf: *u8 = sys_mmap(SS_JRNL_CAP)
986 let jn: i64 = ss_read(jfull, jbuf, SS_JRNL_CAP - 8)
987 if jn > 0 {
988 if jn >= SS_JRNL_CAP - 8 { jtrunc = 1 }
989 var jp: i64 = 0
990 while jp < jn {
991 let jend: i64 = ss_eol(jbuf, jp, jn)
992 // field 2 (0-based) of a TAB frame is the tool
993 var f: i64 = 0
994 var fs: i64 = jp
995 var fe: i64 = jp
996 var scan: i64 = jp
997 var got: i64 = 0
998 while scan <= jend {
999 if scan == jend { if f == 2 { fe = jend; got = 1 } scan = jend + 1 } else {
1000 if jbuf[scan] == (SS_CH_TAB as u8) {
1001 if f == 2 { fe = scan; got = 1; scan = jend }
1002 f = f + 1
1003 if f == 2 { fs = scan + 1 }
1004 }
1005 scan = scan + 1
1006 }
1007 }
1008 if got == 1 { if fe > fs {
1009 jlines = jlines + 1
1010 let sc: u8 = jbuf[fe]
1011 jbuf[fe] = 0 as u8
1012 var tool: *u8 = (jbuf as i64 + fs) as *u8
1013 if ss_starts(tool, "mcp__nishi__" as *u8) == 1 { tool = (tool as i64 + 12) as *u8 }
1014 var j6: i64 = 0
1015 while j6 < norg {
1016 let bn6: *u8 = (obase as i64 + j6 * SS_TOK) as *u8
1017 if bn6[0] == tool[0] { if ss_streq(bn6, tool) == 1 { ofreq[j6] = ofreq[j6] + 1; jframes = jframes + 1; j6 = norg } }
1018 j6 = j6 + 1
1019 }
1020 jbuf[fe] = sc
1021 } }
1022 jp = jend + 1
1023 }
1024 }
1025 }
1026
1027 // ---- LEDGER + ROLL-UP. Every count carries its worklist; every partition prints its sum. ----
1028 let led: *u8 = sys_mmap(SS_LEDGER_CAP)
1029 var lo: i64 = 0
1030 lo = ss_cat(led, lo, "# NX-DERIVED: regenerated artefact, not authored memory -- nx_selfsuff census" as *u8); lo = ss_catc(led, lo, SS_CH_NL)
1031 lo = ss_cat(led, lo, "# dep|domain|organ|outside_dep|seat_only|seat_freq|claude_loop|hosts|net_dep" as *u8); lo = ss_catc(led, lo, SS_CH_NL)
1032 lo = ss_cat(led, lo, "# outside_dep = DISTINCT non-sovereign hosts dialled in string literals + DISTINCT carriers forked (1 hop). A FLOOR." as *u8); lo = ss_catc(led, lo, SS_CH_NL)
1033 lo = ss_cat(led, lo, "# seat_only: 1 = no clock row, no roster row, forked by nothing scanned; 0 = autonomous; -1 = UNOBSERVED. An UPPER BOUND (fork corpus = matrix organs only) and it SATURATES: reported, never ranked on." as *u8); lo = ss_catc(led, lo, SS_CH_NL)
1034 lo = ss_cat(led, lo, "# claude_loop = seat_only AND seat_freq>0: an autonomy gap with a WITNESS in the action record. THIS is what the ranker consumes, beside outside_dep." as *u8); lo = ss_catc(led, lo, SS_CH_NL)
1035 lo = ss_cat(led, lo, "# dom|domain|organs|outside_dep_sum|seat_only_count|claude_loop_count" as *u8); lo = ss_catc(led, lo, SS_CH_NL)
1036
1037 var depcarriers: i64 = 0
1038 var sovorgans: i64 = 0
1039 var sumdeps: i64 = 0
1040 var totloop: i64 = 0
1041 let ddep: *i64 = sys_mmap(SS_MAX_DOM * 8) as *i64
1042 let dseat: *i64 = sys_mmap(SS_MAX_DOM * 8) as *i64
1043 let dloop: *i64 = sys_mmap(SS_MAX_DOM * 8) as *i64
1044 let dorg: *i64 = sys_mmap(SS_MAX_DOM * 8) as *i64
1045 d = 0
1046 while d < ndom { ddep[d] = 0; dseat[d] = 0; dloop[d] = 0; dorg[d] = 0; d = d + 1 }
1047 o = 0
1048 while o < nmatrix {
1049 let dtot: i64 = oout[o] + oind[o]
1050 let sflag: i64 = oseat[o]
1051 var scount: i64 = 0
1052 if sflag == 1 { scount = 1 }
1053 var lcount: i64 = 0
1054 if scount == 1 { if ofreq[o] > 0 { lcount = 1 } }
1055 if oread[o] == 1 {
1056 if dtot + lcount > 0 { depcarriers = depcarriers + 1 } else { sovorgans = sovorgans + 1 }
1057 sumdeps = sumdeps + dtot + lcount
1058 totloop = totloop + lcount
1059 let di: i64 = odom[o]
1060 ddep[di] = ddep[di] + dtot
1061 dseat[di] = dseat[di] + scount
1062 dloop[di] = dloop[di] + lcount
1063 dorg[di] = dorg[di] + 1
1064 }
1065 lo = ss_cat(led, lo, "dep" as *u8); lo = ss_catc(led, lo, SS_CH_PIPE)
1066 lo = ss_cat(led, lo, dnm[odom[o]] as *u8); lo = ss_catc(led, lo, SS_CH_PIPE)
1067 lo = ss_cat(led, lo, onm[o] as *u8); lo = ss_catc(led, lo, SS_CH_PIPE)
1068 lo = ss_catn(led, lo, dtot); lo = ss_catc(led, lo, SS_CH_PIPE)
1069 lo = ss_catn(led, lo, sflag); lo = ss_catc(led, lo, SS_CH_PIPE)
1070 lo = ss_catn(led, lo, ofreq[o]); lo = ss_catc(led, lo, SS_CH_PIPE)
1071 lo = ss_catn(led, lo, lcount); lo = ss_catc(led, lo, SS_CH_PIPE)
1072 if oread[o] == 0 { lo = ss_cat(led, lo, "NO-SOURCE-AT-PATH" as *u8) } else {
1073 var wrote: i64 = 0
1074 var k4: i64 = 0
1075 while k4 < ohn[o] {
1076 let h4: *u8 = hptr[ohs[o] + k4] as *u8
1077 if ss_hostclass(h4, sovp, nsov, resp, nres, ndp, nnd) == 0 {
1078 var dup3: i64 = 0
1079 var k5: i64 = 0
1080 while k5 < k4 { if ss_streq(hptr[ohs[o] + k5] as *u8, h4) == 1 { dup3 = 1; k5 = k4 } k5 = k5 + 1 }
1081 if dup3 == 0 { if lo < SS_LEDGER_CAP - 1024 { if wrote == 1 { lo = ss_catc(led, lo, SS_CH_SEMI) } lo = ss_cat(led, lo, h4); wrote = 1 } }
1082 }
1083 k4 = k4 + 1
1084 }
1085 if oind[o] > 0 { if lo < SS_LEDGER_CAP - 1024 { if wrote == 1 { lo = ss_catc(led, lo, SS_CH_SEMI) } lo = ss_cat(led, lo, "1hop_carriers=" as *u8); lo = ss_catn(led, lo, oind[o]); wrote = 1 } }
1086 if wrote == 0 { lo = ss_cat(led, lo, "-" as *u8) }
1087 }
1088 // FIELD 9, APPENDED and never inserted. rk_selfsuff_term guards on nf>=8 and reads fs[3] and
1089 // fs[6], so a TRAILING field is contract-safe -- established by READING that parser, not by
1090 // assuming it. 0 = reaches no network - 1 = DIRECT - 2 = VIA-HELPER (transitive closure).
1091 lo = ss_catc(led, lo, SS_CH_PIPE)
1092 var ndv: i64 = 0
1093 if onetD[o] == 1 { ndv = 1 } else { if onetT[o] == 1 { ndv = 2 } }
1094 lo = ss_catn(led, lo, ndv)
1095 lo = ss_catc(led, lo, SS_CH_NL)
1096 o = o + 1
1097 }
1098 d = 0
1099 while d < ndom {
1100 lo = ss_cat(led, lo, "dom" as *u8); lo = ss_catc(led, lo, SS_CH_PIPE)
1101 lo = ss_cat(led, lo, dnm[d] as *u8); lo = ss_catc(led, lo, SS_CH_PIPE)
1102 lo = ss_catn(led, lo, dorg[d]); lo = ss_catc(led, lo, SS_CH_PIPE)
1103 lo = ss_catn(led, lo, ddep[d]); lo = ss_catc(led, lo, SS_CH_PIPE)
1104 lo = ss_catn(led, lo, dseat[d]); lo = ss_catc(led, lo, SS_CH_PIPE)
1105 lo = ss_catn(led, lo, dloop[d]); lo = ss_catc(led, lo, SS_CH_NL)
1106 d = d + 1
1107 }
1108 let lfd: i64 = sys_openat_wr(ledpath, MODE_0644)
1109 var wroteb: i64 = 0
1110 if lfd >= 0 { wroteb = sys_write(lfd, led, lo); sys_close(lfd) }
1111
1112 let hraw: i64 = totout + totsov + totfix + totsch + totnd
1113 ss_puts("HOSTS raw_occurrences=" as *u8); ss_pn(hraw)
1114 ss_puts(" OUTSIDE=" as *u8); ss_pn(totout); ss_puts(" sovereign=" as *u8); ss_pn(totsov)
1115 ss_puts(" fixture=" as *u8); ss_pn(totfix); ss_puts(" scheme_token=" as *u8); ss_pn(totsch)
1116 ss_puts(" non_dialled=" as *u8); ss_pn(totnd)
1117 ss_puts(" (partition sums " as *u8); ss_pn(totout); ss_puts("+" as *u8); ss_pn(totsov); ss_puts("+" as *u8); ss_pn(totfix); ss_puts("+" as *u8); ss_pn(totsch); ss_puts("+" as *u8); ss_pn(totnd); ss_puts("=" as *u8); ss_pn(hraw); ss_puts(")" as *u8); ss_nl()
1118 ss_puts("EDGES fork_literals=" as *u8); ss_pn(ecnt[0]); ss_puts(" autonomy_sources_loaded=" as *u8); ss_pn(autosrc)
1119 ss_puts(" autonomy_sources_missing=" as *u8); ss_pn(afmissing); ss_puts(" autonomy_bytes=" as *u8); ss_pn(autobytes)
1120 ss_puts(" autonomy_tokens=" as *u8); ss_pn(autotok); ss_puts(" plane_capture_truncated=" as *u8); ss_pn(planetrunc); ss_nl()
1121 var netcapD: i64 = 0
1122 var netviaH: i64 = 0
1123 var netnone: i64 = 0
1124 var oz: i64 = 0
1125 while oz < nmatrix {
1126 if oread[oz] == 1 {
1127 if onetD[oz] == 1 { netcapD = netcapD + 1 } else { if onetT[oz] == 1 { netviaH = netviaH + 1 } else { netnone = netnone + 1 } }
1128 }
1129 oz = oz + 1
1130 }
1131 var netdirAll: i64 = 0
1132 var netreachAll: i64 = 0
1133 oz = 0
1134 while oz < norg { if onetD[oz] == 1 { netdirAll = netdirAll + 1 } if onetT[oz] == 1 { netreachAll = netreachAll + 1 } oz = oz + 1 }
1135 ss_puts("CLOSURE matrix_nodes=" as *u8); ss_pn(nmatrix); ss_puts(" aux_nodes_pulled_in=" as *u8); ss_pn(auxadded)
1136 ss_puts(" total_nodes=" as *u8); ss_pn(norg); ss_puts(" (partition sums " as *u8); ss_pn(nmatrix); ss_puts("+" as *u8); ss_pn(auxadded); ss_puts("=" as *u8); ss_pn(norg); ss_puts(")" as *u8)
1137 ss_puts(" import_edges=" as *u8); ss_pn(totimp); ss_puts(" edge_names_with_no_source=" as *u8); ss_pn(auxunres)
1138 ss_puts(" fixpoint_sweeps=" as *u8); ss_pn(netiter); ss_puts(" aux_outside_host_occurrences=" as *u8); ss_pn(auxout); ss_nl()
1139 ss_puts("NET-DEP with-source SUBJECTS: direct=" as *u8); ss_pn(netcapD); ss_puts(" via_helper=" as *u8); ss_pn(netviaH)
1140 ss_puts(" none=" as *u8); ss_pn(netnone); ss_puts(" (partition sums " as *u8); ss_pn(netcapD); ss_puts("+" as *u8); ss_pn(netviaH); ss_puts("+" as *u8); ss_pn(netnone); ss_puts("=" as *u8); ss_pn(nmatrix - unreadable); ss_puts(")" as *u8); ss_nl()
1141 ss_puts(" <== DIRECT = calls a socket primitive in its OWN code, or dials an outside host itself. VIA_HELPER = reaches one over the TRANSITIVE import/fork closure. A same-organ socket test sees only DIRECT and reports every well-factored caller as sovereign -- an under-report, which is the flattering direction." as *u8); ss_nl()
1142 ss_puts("NET-DEP ALL closure nodes: direct=" as *u8); ss_pn(netdirAll); ss_puts(" reaches_network=" as *u8); ss_pn(netreachAll); ss_puts(" of nodes=" as *u8); ss_pn(norg); ss_nl()
1143 ss_puts("ORGANS total=" as *u8); ss_pn(nmatrix); ss_puts(" with_source=" as *u8); ss_pn(nmatrix - unreadable)
1144 ss_puts(" NO-SOURCE-AT-PATH=" as *u8); ss_pn(unreadable); ss_puts(" (partition sums " as *u8); ss_pn(nmatrix - unreadable); ss_puts("+" as *u8); ss_pn(unreadable); ss_puts("=" as *u8); ss_pn(nmatrix); ss_puts(") <== a NO-SOURCE row is a watch contract's future organ or a stale path, NOT a measurement failure" as *u8); ss_nl()
1145 ss_puts("WITH-SOURCE SPLIT dependent=" as *u8); ss_pn(depcarriers); ss_puts(" fully_sovereign=" as *u8); ss_pn(sovorgans)
1146 ss_puts(" (partition sums " as *u8); ss_pn(depcarriers); ss_puts("+" as *u8); ss_pn(sovorgans); ss_puts("=" as *u8); ss_pn(nmatrix - unreadable); ss_puts(")" as *u8); ss_nl()
1147 ss_puts("SEAT-ONLY with_source=" as *u8); ss_pn(seatonly); ss_puts(" no_source=" as *u8); ss_pn(seatonly_nosrc)
1148 ss_puts(" UNOBSERVED=" as *u8); ss_pn(seatunobs)
1149 ss_puts(" <== UPPER BOUND (the fork corpus is the matrix organs, not the tree) and it SATURATES: reported, never ranked on" as *u8); ss_nl()
1150 ss_puts("CLAUDE-LOOP organs=" as *u8); ss_pn(totloop); ss_puts(" of with_source=" as *u8); ss_pn(nmatrix - unreadable)
1151 ss_puts(" (seat_only AND a WITNESS frame in the action record -- the sparse, evidence-positive axis the ranker consumes)" as *u8); ss_nl()
1152 ss_puts("DEPENDENCY UNITS total=" as *u8); ss_pn(sumdeps); ss_puts(" (outside_dep + claude_loop summed over with-source organs)" as *u8); ss_nl()
1153 if jpath != (0 as *u8) {
1154 ss_puts("ACTION-RECORD frames_matched=" as *u8); ss_pn(jframes); ss_puts(" of tool_frames=" as *u8); ss_pn(jlines)
1155 ss_puts(" window_truncated=" as *u8); ss_pn(jtrunc); ss_nl()
1156 } else { ss_puts("ACTION-RECORD not joined (no journal argument) -- seat_freq is UNMEASURED, not zero" as *u8); ss_nl() }
1157 ss_puts("LEDGER " as *u8); ss_puts(ledpath); ss_puts(" bytes=" as *u8); ss_pn(wroteb); ss_puts(" of " as *u8); ss_pn(lo); ss_nl()
1158 ss_puts("-- DOMAIN WORKLIST ranked by RANKED UNITS = outside_dep + claude_loop (the reason travels with the count) --" as *u8); ss_nl()
1159 var shown: i64 = 0
1160 var pass: i64 = 0
1161 while pass < ndom {
1162 var best: i64 = 0 - 1
1163 var bestv: i64 = 0
1164 d = 0
1165 while d < ndom {
1166 if ddep[d] + dloop[d] > bestv { best = d; bestv = ddep[d] + dloop[d] }
1167 d = d + 1
1168 }
1169 if best < 0 { pass = ndom } else {
1170 ss_puts(" " as *u8); ss_puts(dnm[best] as *u8); ss_puts(" ranked_units=" as *u8); ss_pn(bestv)
1171 ss_puts(" outside_dep=" as *u8); ss_pn(ddep[best])
1172 ss_puts(" claude_loop=" as *u8); ss_pn(dloop[best])
1173 ss_puts(" seat_only=" as *u8); ss_pn(dseat[best]); ss_puts(" organs=" as *u8); ss_pn(dorg[best]); ss_nl()
1174 ddep[best] = 0; dloop[best] = 0
1175 shown = shown + 1
1176 pass = pass + 1
1177 }
1178 }
1179 ss_puts("worklist_rows=" as *u8); ss_pn(shown); ss_puts(" of domains=" as *u8); ss_pn(ndom); ss_puts(" (the remainder measured ZERO ranked dependency)" as *u8); ss_nl()
1180 if wroteb != lo { ss_puts("SELFSUFF REFUSED: ledger short write" as *u8); ss_nl(); return 4 }
1181 return 0
1182}