code wiki / _hdl_build / nx_ciq_sclass_gate.nx
nx_ciq_sclass_gate.nx source
↩ module page · 144 lines · 9435 B
1// nx_ciq_sclass_gate.nx -- "check if it hits s class exceed" (operator). Grades the 3-modality CIQ publish
2// bundle (human/ai/machine) for S-CLASS EXCEED on READABILITY + INTEGRITY, measured not asserted:
3// 1. MODALITY COVERAGE: all 3 artifacts exist + non-empty (human html, ai md, machine records).
4// 2. FAITHFULNESS (the integrity core): parse EVERY machine record and cross-check its execute/vision
5// against the SOVEREIGN seg_store (ss_get the independent score record). 100% must match -- a single
6// hallucinated/drifted number fails the gate. This is the anti-overclaim guarantee BY CONSTRUCTION.
7// 3. HUMAN guard-readiness: epoch= freshness stamp present, NO placeholder (TODO/PLACEHOLDER/lorem).
8// 4. AI structure: every market named + machine-parseable claim lines.
9// S-CLASS EXCEED vs the analyst baseline (1 modality = human PDF, unverifiable numbers, 3rd-party format):
10// ours = 3 modalities + faithfulness-VERIFIED + sovereign format. EXCEED on >=1 axis with parity on the
11// rest = S-class (mirrors nx_wiki_exceed's honest parity+exceed rule). Honest BEHIND + worklist otherwise.
12// 100% sovereign. license_tier: ORIGINAL expect_exit: 0
13import "nx_syscalls.nx"
14import "nx_canon_cid.nx"
15import "nx_seg_store.nx"
16import "nx_uxf_decode.nx"
17import "nx_gate_verdict.nx"
18
19const SG_STORE: *u8 = "knowledge/store/ciq-"
20const SG_HUMAN: *u8 = "knowledge/staging/ciq_report.html"
21const SG_AI: *u8 = "knowledge/staging/ciq_report_ai.md"
22const SG_MACHINE: *u8 = "knowledge/staging/ciq_report_machine.nxr"
23
24func sw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
25func sn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 }
26func g_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 }
27func g_pint(s: *u8) -> i64 { var v: i64=0; var i: i64=0; var go: i64=1; while go==1 { let c: i64=s[i]; if c>=48 { if c<=57 { v=v*10+(c-48); i=i+1 } else { go=0 } } else { go=0 } } return v }
28func g_field(dk: *i64, dv: *i64, nf: i64, name: *u8) -> *u8 { var f: i64=0; while f<nf { if g_streq(dk[f] as *u8, name)==1 { return dv[f] as *u8 } f=f+1 } return 0 as *u8 }
29func g_read(path: *u8, buf: *u8, cap: i64) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 - 1 } var n: i64 = 0; var r: i64 = 1; while r > 0 { r = sys_read(fd, ((buf as i64)+n) as *u8, cap - n); if r > 0 { n = n + r } } sys_close(fd); buf[n] = 0 as u8; return n }
30func g_contains(hay: *u8, n: i64, needle: *u8) -> i64 { var nl: i64=0; while needle[nl]!=(0 as u8){ nl=nl+1 } if nl==0 { return 1 } var i: i64=0; while i + nl <= n { var j: i64=0; var ok: i64=1; while j < nl { if hay[i+j] != needle[j] { ok=0; j=nl } else { j=j+1 } } if ok==1 { return 1 } i=i+1 } return 0 }
31
32// find "key" in line starting at p, copy its value (until space/newline/NUL) into out; returns 1 if found
33// (stops at end-of-line so it never reads the next record).
34func g_sval(line: *u8, p: i64, key: *u8, out: *u8) -> i64 {
35 var kl: i64=0; while key[kl]!=(0 as u8){ kl=kl+1 }
36 var i: i64=p
37 var res: i64=0
38 var scan: i64=1
39 while scan==1 {
40 let ch: i64=line[i]
41 if ch==0 { scan=0 }
42 else { if ch==10 { scan=0 }
43 else {
44 var j: i64=0; var ok: i64=1
45 while j<kl { if line[i+j]!=key[j] { ok=0; j=kl } else { j=j+1 } }
46 if ok==1 {
47 var s: i64=i+kl; var o: i64=0; var go: i64=1
48 while go==1 {
49 let c: i64=line[s]
50 if c==0 { go=0 } else { if c==32 { go=0 } else { if c==10 { go=0 } else { out[o]=line[s]; o=o+1; s=s+1 } } }
51 }
52 out[o]=0 as u8; res=1; scan=0
53 }
54 i=i+1
55 } }
56 }
57 return res
58}
59// 1 if the 4 bytes at line[p] are "rec "
60func g_isrec(line: *u8, p: i64) -> i64 { if line[p]!=(114 as u8){return 0} if line[p+1]!=(101 as u8){return 0} if line[p+2]!=(99 as u8){return 0} if line[p+3]!=(32 as u8){return 0} return 1 }
61
62func main() -> i64 {
63 let H: *u8 = sys_mmap(262144); let hn: i64 = g_read(SG_HUMAN, H, 262140)
64 let A: *u8 = sys_mmap(262144); let an: i64 = g_read(SG_AI, A, 262140)
65 let M: *u8 = sys_mmap(262144); let mn: i64 = g_read(SG_MACHINE, M, 262140)
66
67 sw("=== nx_ciq_sclass_gate -- S-class-exceed readability + integrity check ===\n" as *u8)
68 var mod_ok: i64 = 0
69 if hn > 0 { mod_ok = mod_ok + 1 }
70 if an > 0 { mod_ok = mod_ok + 1 }
71 if mn > 0 { mod_ok = mod_ok + 1 }
72 sw("modality coverage: human=" as *u8); sn(hn); sw("B ai=" as *u8); sn(an); sw("B machine=" as *u8); sn(mn); sw("B (" as *u8); sn(mod_ok); sw("/3 present)\n" as *u8)
73
74 // human guard-readiness
75 var human_ok: i64 = 1
76 if g_contains(H, hn, "epoch=" as *u8) == 0 { human_ok = 0 }
77 if g_contains(H, hn, "TODO" as *u8) == 1 { human_ok = 0 }
78 if g_contains(H, hn, "PLACEHOLDER" as *u8) == 1 { human_ok = 0 }
79 if g_contains(H, hn, "lorem" as *u8) == 1 { human_ok = 0 }
80
81 // FAITHFULNESS: every machine record's numbers must equal the seg_store
82 let gp: *i64 = sys_mmap(8) as *i64; let gl: *i64 = sys_mmap(8) as *i64
83 let dk: *i64 = sys_mmap(8 * 16) as *i64; let dv: *i64 = sys_mmap(8 * 16) as *i64
84 let mkt: *u8 = sys_mmap(128); let eb: *u8 = sys_mmap(128); let xb: *u8 = sys_mmap(64); let vb: *u8 = sys_mmap(64)
85 var recs: i64 = 0; var fmatch: i64 = 0; var mismatch: i64 = 0
86 var p: i64 = 0
87 while p < mn {
88 if g_isrec(M, p) == 1 {
89 let g1: i64 = g_sval(M, p, "market=" as *u8, mkt)
90 let g2: i64 = g_sval(M, p, "entity=" as *u8, eb)
91 let g3: i64 = g_sval(M, p, "execute=" as *u8, xb)
92 let g4: i64 = g_sval(M, p, "vision=" as *u8, vb)
93 var allf: i64 = 0
94 if g1==1 { if g2==1 { if g3==1 { if g4==1 { allf = 1 } } } }
95 if allf == 1 {
96 recs = recs + 1
97 let rex: i64 = g_pint(xb); let rvs: i64 = g_pint(vb)
98 let kb: *u8 = sys_mmap(256); var ko: i64=0
99 ko=ss_cat(kb,ko,"ciq:" as *u8); ko=ss_cat(kb,ko,mkt); ko=ss_cat(kb,ko,":score:" as *u8); ko=ss_cat(kb,ko,eb); kb[ko]=0 as u8
100 var sok: i64 = 0
101 if ss_get(SG_STORE, kb, gp, gl)==1 {
102 let snf: i64 = canon_decode(gp[0] as *u8, gl[0], dk, dv, 16)
103 let sex: i64 = g_pint(g_field(dk, dv, snf, "execute" as *u8))
104 let svs: i64 = g_pint(g_field(dk, dv, snf, "vision" as *u8))
105 if sex==rex { if svs==rvs { sok = 1 } }
106 }
107 if sok==1 { fmatch = fmatch + 1 } else { mismatch = mismatch + 1; sw(" FAITHFULNESS MISS market=" as *u8); sw(mkt); sw(" entity=" as *u8); sw(eb); sw("\n" as *u8) }
108 }
109 }
110 var nl: i64 = 0
111 while nl == 0 { if p >= mn { nl = 1 } else { if M[p]==(10 as u8) { p = p + 1; nl = 1 } else { p = p + 1 } } }
112 }
113 var faith: i64 = 1000
114 if recs > 0 { faith = (fmatch * 1000) / recs }
115 sw("faithfulness: " as *u8); sn(fmatch); sw("/" as *u8); sn(recs); sw(" machine records match the seg_store = " as *u8); sn(faith); sw(" permil\n" as *u8)
116 sw("human guard-ready (epoch + no placeholder): " as *u8); if human_ok==1 { sw("YES" as *u8) } else { sw("NO" as *u8) } sw("\n" as *u8)
117
118 // measured S-class-exceed vs analyst baseline (1 modality, unverifiable numbers, 3rd-party format)
119 sw("-- measured vs analyst baseline --\n" as *u8)
120 sw(" modalities: ours=" as *u8); sn(mod_ok); sw(" vs baseline=1 (human-only) -> " as *u8); if mod_ok > 1 { sw("EXCEED\n" as *u8) } else { sw("parity\n" as *u8) }
121 sw(" numeric faithfulness: ours=verified(" as *u8); sn(faith); sw(") vs baseline=unverifiable -> " as *u8); if faith==1000 { sw("EXCEED\n" as *u8) } else { sw("BEHIND\n" as *u8) }
122 sw(" format: ours=sovereign(html+md+nxr) vs baseline=3rd-party(pdf) -> EXCEED\n" as *u8)
123
124 var exceed_axes: i64 = 0
125 if mod_ok > 1 { exceed_axes = exceed_axes + 1 }
126 if faith == 1000 { exceed_axes = exceed_axes + 1 }
127 exceed_axes = exceed_axes + 1 // sovereign format
128 var parity_ok: i64 = 0
129 if mod_ok == 3 { if human_ok == 1 { if recs > 0 { parity_ok = 1 } } }
130
131 // S-class = parity on the floor (all modalities + guard-ready + has data) AND faithfulness perfect AND exceed>=1
132 var green: i64 = 0
133 if parity_ok == 1 { if faith == 1000 { if exceed_axes >= 1 { green = 1 } } }
134 sw("exceed_axes=" as *u8); sn(exceed_axes); sw(" parity_floor=" as *u8); if parity_ok==1 { sw("met" as *u8) } else { sw("UNMET" as *u8) } sw("\n" as *u8)
135 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
136 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
137 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
138 let ctr__dry: *i64 = gv_ctr()
139 ctr__dry[0] = green
140 ctr__dry[1] = 1
141 let rc__dry: i64 = gv_verdict("CIQ-SCLASS-GATE" as *u8, ctr__dry, "HITS S-CLASS EXCEED (3-modality, faithfulness-verified vs seg_store, sovereign format; ready for family-gated publish)" as *u8)
142 sys_exit(rc__dry)
143 return rc__dry
144}