nx_triage_ground.nx source
↩ module page · 192 lines · 8115 B
1// nx_triage_ground.nx -- EVIDENCE-GROUNDS the capability-triage registry's has_organ column against
2// DISK FACTS, eating the debt "the registry is Claude's hand-seeded opinion" (the subtlest navel-
3// gaze). COMPOSES the EXISTING engine `nx_capability_census` (cc_our_grade: exceed-gate > organ >
4// absent -- "never self-scored", per its own doctrine) instead of reinventing it (the round-4
5// lesson). Per probeable row (bare nx_[a-z0-9_]+ runtime organ) it derives the disk-fact grade and
6// flags where my claimed has_organ DISAGREES -> DISCREPANCY = a label the disk can't back (wrong
7// name or fabrication). NAS backends / external / descriptive names = UNPROBEABLE (honest). This is
8// the self-hosting-analysis local half: the loop's has_organ stops being asserted, starts being
9// measured. usage: nx_triage_ground scan [registry] Always exit 0; journals a summary.
10// license_tier: ORIGINAL expect_exit: 0
11import "nx_syscalls.nx"
12import "nx_crashresume_census_core.nx" // ccz_read / ccz_cat_* / ccz_num_at / ccz_slen / sys_fstatat
13const TG_MAGIC_65536: i64 = 65536
14const TG_MAGIC_65535: i64 = 65535
15
16// disk-fact grade -- MIRRORS nx_capability_census.cc_our_grade semantics (exceed-gate > organ >
17// absent, never self-scored). Inlined (3 fstatat checks) because that engine's import chain
18// (nx_research_extract...) does not expand cleanly here, and its proliferation-worthy VALUE is the
19// competitor-corpus attestation (cc_comp_attest) -- NOT this trivial primitive. Naming-aware (our
20// core/gate convention): a `<name>_gate.nx` is the strongest signal (built AND liar-killed).
21
22const TG_GROUNDED: i64 = 0
23const TG_DISCREPANCY: i64 = 1 // has_organ=1 but disk ABSENT -> fix the label
24const TG_UNDERCLAIM: i64 = 2 // has_organ=0 but disk shows it
25const TG_UNPROBEABLE: i64 = 3
26
27func tg_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
28func tg_putn(v: i64) -> i64 { nxi_out(v); return 0 }
29func tg_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 }
30
31// pure verdict: claimed has_organ vs disk `present` (grade>=3), for a probeable row.
32func tg_verdict(probeable: i64, has_organ: i64, grade: i64) -> i64 {
33 if probeable == 0 { return TG_UNPROBEABLE }
34 var present: i64 = 0
35 if grade >= 3 { present = 1 }
36 if has_organ == 1 {
37 if present == 1 { return TG_GROUNDED }
38 return TG_DISCREPANCY
39 }
40 if present == 1 { return TG_UNDERCLAIM }
41 return TG_GROUNDED
42}
43
44func tg_vname(v: i64) -> *u8 {
45 if v == TG_GROUNDED { return "GROUNDED" as *u8 }
46 if v == TG_DISCREPANCY { return "DISCREPANCY(claim>disk -- FIX LABEL)" as *u8 }
47 if v == TG_UNDERCLAIM { return "UNDERCLAIM" as *u8 }
48 return "UNPROBEABLE" as *u8
49}
50
51func tg_probeable(name: *u8, n: i64) -> i64 {
52 if n < 4 { return 0 }
53 if name[0] != (110 as u8) { return 0 }
54 if name[1] != (120 as u8) { return 0 }
55 if name[2] != (95 as u8) { return 0 }
56 var i: i64 = 0
57 while i < n {
58 let c: i64 = name[i] as i64
59 var ok: i64 = 0
60 if c >= 97 { if c <= 122 { ok = 1 } }
61 if c >= 48 { if c <= 57 { ok = 1 } }
62 if c == 95 { ok = 1 }
63 if ok == 0 { return 0 }
64 i = i + 1
65 }
66 return 1
67}
68
69// copy the idx-th '|' field of buf[ls..le) into out (NUL-term). returns length or -1.
70func tg_field(buf: *u8, ls: i64, le: i64, idx: i64, out: *u8) -> i64 {
71 var f: i64 = 0
72 var s: i64 = ls
73 var i: i64 = ls
74 var go: i64 = 1
75 while go == 1 {
76 go = 0
77 if i <= le {
78 var atend: i64 = 0
79 if i == le { atend = 1 }
80 var atbar: i64 = 0
81 if i < le { if buf[i] == (124 as u8) { atbar = 1 } }
82 if atend == 1 { if f == idx { var o: i64 = 0; var k: i64 = s; while k < i { out[o] = buf[k]; o = o + 1; k = k + 1 } out[o] = 0 as u8; return o } f = f + 1 }
83 else {
84 if atbar == 1 { if f == idx { var o2: i64 = 0; var k2: i64 = s; while k2 < i { out[o2] = buf[k2]; o2 = o2 + 1; k2 = k2 + 1 } out[o2] = 0 as u8; return o2 } f = f + 1; s = i + 1 }
85 i = i + 1
86 go = 1
87 }
88 }
89 }
90 return 0 - 1
91}
92
93// build "runtime/<name><suffix>.nx"
94func tg_path(name: *u8, suffix: *u8, out: *u8) -> i64 {
95 var o: i64 = 0
96 o = ccz_cat_str(out, o, "runtime/" as *u8)
97 o = ccz_cat_str(out, o, name)
98 o = ccz_cat_str(out, o, suffix)
99 o = ccz_cat_str(out, o, ".nx" as *u8)
100 return o
101}
102
103func tg_exists(path: *u8) -> i64 {
104 let sb: *u8 = sys_mmap(256)
105 if sys_fstatat(path, sb) < 0 { return 0 }
106 return 1
107}
108
109// disk-fact grade (mirrors cc_our_grade): 4 = gate exists (built+liar-killed), 3 = source exists, 0 absent.
110func tg_grade(name: *u8) -> i64 {
111 let p: *u8 = sys_mmap(512)
112 tg_path(name, "_gate" as *u8, p)
113 if tg_exists(p) == 1 { return 4 }
114 tg_path(name, "" as *u8, p)
115 if tg_exists(p) == 1 { return 3 }
116 tg_path(name, "_core" as *u8, p)
117 if tg_exists(p) == 1 { return 3 }
118 return 0
119}
120
121func main(argc: i64, argv: *i64) -> i64 {
122 var reg: *u8 = "knowledge/capability_triage.reg" as *u8
123 if argc >= 3 { if tg_streq(argv[1] as *u8, "scan" as *u8) == 1 { reg = argv[2] as *u8 } }
124
125 let buf: *u8 = sys_mmap(TG_MAGIC_65536)
126 let n: i64 = ccz_read(reg, buf, TG_MAGIC_65535)
127 if n <= 0 { tg_puts("TGROUND no-registry\n" as *u8); return 0 }
128
129 let organ: *u8 = sys_mmap(128)
130 let hstr: *u8 = sys_mmap(32)
131 let op: *u8 = sys_mmap(512)
132 let gp: *u8 = sys_mmap(512)
133 let ep: *i64 = sys_mmap(16) as *i64
134 var rows: i64 = 0
135 var grounded: i64 = 0
136 var discrep: i64 = 0
137 var underc: i64 = 0
138 var unprob: i64 = 0
139
140 var ls: i64 = 0
141 while ls < n {
142 var le: i64 = ls
143 var go: i64 = 1
144 while go == 1 { go = 0; if le < n { if buf[le] != (10 as u8) { le = le + 1; go = 1 } } }
145 var i: i64 = ls
146 go = 1
147 while go == 1 { go = 0; if i < le { let c: i64 = buf[i] as i64; if c == 32 { i = i + 1; go = 1 } else { if c == 9 { i = i + 1; go = 1 } } } }
148 var skip: i64 = 0
149 if i >= le { skip = 1 }
150 if skip == 0 { if buf[i] == (35 as u8) { skip = 1 } }
151 if skip == 0 {
152 if tg_field(buf, ls, le, 1, organ) >= 0 {
153 if tg_field(buf, ls, le, 2, hstr) >= 0 {
154 let claimed: i64 = ccz_num_at(hstr, ccz_slen(hstr), 0, ep)
155 let prob: i64 = tg_probeable(organ, ccz_slen(organ))
156 var grade: i64 = 0
157 if prob == 1 { grade = tg_grade(organ) }
158 let v: i64 = tg_verdict(prob, claimed, grade)
159 rows = rows + 1
160 if v == TG_GROUNDED { grounded = grounded + 1 }
161 if v == TG_DISCREPANCY { discrep = discrep + 1 }
162 if v == TG_UNDERCLAIM { underc = underc + 1 }
163 if v == TG_UNPROBEABLE { unprob = unprob + 1 }
164 tg_puts("TGROUND " as *u8); tg_puts(organ)
165 tg_puts(" claim_has=" as *u8); tg_putn(claimed)
166 tg_puts(" disk_grade=" as *u8); tg_putn(grade)
167 tg_puts(" -> " as *u8); tg_puts(tg_vname(v))
168 tg_puts("\n" as *u8)
169 }
170 }
171 }
172 ls = le + 1
173 }
174
175 let line: *u8 = sys_mmap(512)
176 var o: i64 = 0
177 o = ccz_cat_str(line, o, "TGROUND-SUM rows=" as *u8)
178 o = ccz_cat_num(line, o, rows)
179 o = ccz_cat_str(line, o, " grounded=" as *u8)
180 o = ccz_cat_num(line, o, grounded)
181 o = ccz_cat_str(line, o, " DISCREPANCY=" as *u8)
182 o = ccz_cat_num(line, o, discrep)
183 o = ccz_cat_str(line, o, " underclaim=" as *u8)
184 o = ccz_cat_num(line, o, underc)
185 o = ccz_cat_str(line, o, " unprobeable=" as *u8)
186 o = ccz_cat_num(line, o, unprob)
187 o = ccz_cat_str(line, o, "\n" as *u8)
188 sys_write(1, line, o)
189 let lfd: i64 = sys_openat_append("knowledge/status/triage_ground.log" as *u8, 420)
190 if lfd >= 0 { sys_write(lfd, line, o); sys_close(lfd) }
191 return 0
192}