nx_fetchwall_lib.nx source
↩ module page · 190 lines · 8126 B
1// nx_fetchwall_lib.nx -- IS THIS FETCHED BODY CONTENT, OR A WALL WEARING A 200? (2026-09-03)
2//
3// WHY THIS EXISTS, MEASURED THE DAY IT WAS BUILT. A Google AI Mode share link was fetched by the sovereign
4// client, which reported status=200 body_bytes=92982 SAVED ... grep it to cite. Every one of those words was
5// true and the artifact was a JavaScript gate: title Google Search, a noscript meta-refresh to
6// /httpservice/retry/enablejs, and not one character of the answer. A WALL THAT RETURNS 200 AND 93 KB IS
7// INDISTINGUISHABLE FROM A MIRROR UNTIL SOMEONE READS THE HEAD, and the refs lane cites mirrors by path, so
8// a wall silently becomes a fabricated citation carrying a real provenance row and a real sha256.
9//
10// WHAT IT IS NOT. It is not nx_mirrorintegrity, which measures TRUNCATION -- a different axis that reads this
11// very file as intact, because it IS intact; it is a complete wall. It is not nx_clean_serve, which is a
12// policy transform. The question here is prior to both: does this body carry readable content at all.
13//
14// THE ORDERING IS THE WHOLE DESIGN: STRUCTURE DECIDES WHETHER, MARKERS DECIDE WHICH. The structural axis is
15// bd_fit_text from nx_block_density (Kohlschuetter shallow text features, the webscraping R6 contract) -- the
16// estate's one text-extraction ruler, COMPOSED and not re-implemented -- and it is VOCABULARY-FREE, so it
17// catches walls in languages and phrasings nobody listed. Markers only NAME the family afterwards. A
18// marker-first design would convict every article that mentions cookies or a sign-in link, which is exactly
19// the false-positive class that cost nx_mirrorintegrity a 941-permil FP rate on real data.
20//
21// ABSTAIN, NEVER ACQUIT: an unreadable file and a zero-length body return UNPROVEN, never CONTENT.
22// license_tier: ORIGINAL No hw writes (Rule 26). LIB (no main).
23import "nx_syscalls.nx"
24import "nx_block_density.nx"
25
26const FW_CONTENT: i64 = 0
27const FW_WALL_JS: i64 = 1
28const FW_WALL_CHALLENGE: i64 = 2
29const FW_WALL_CONSENT: i64 = 3
30const FW_WALL_LOGIN: i64 = 4
31const FW_WALL_UNNAMED: i64 = 5
32const FW_EMPTY: i64 = 6
33const FW_UNPROVEN: i64 = 7
34
35const FW_O_VERDICT: i64 = 0
36const FW_O_BODY: i64 = 1
37const FW_O_TEXT: i64 = 2
38const FW_O_PERMIL: i64 = 3
39const FW_O_JS: i64 = 4
40const FW_O_CHAL: i64 = 5
41const FW_O_CONS: i64 = 6
42const FW_O_LOGIN: i64 = 7
43const FW_O_SLOTS: i64 = 8
44const FW_SLOT: i64 = 8
45
46const FW_PERMIL: i64 = 1000
47// The bar. A body whose fitted article text is at least this permil of its own bytes carries content. The
48// gate PRINTS this ratio for the real wall specimen and for every curated content mirror, so the bar is
49// adjudicated on measured rows rather than asserted here -- and it is the ONE number in this file that a
50// future measurement is expected to move.
51const FW_CONTENT_PERMIL: i64 = 30
52// Below this a body cannot be judged as prose at all; it is reported EMPTY rather than convicted as a wall.
53const FW_MIN_BYTES: i64 = 256
54const FW_UPPER_A: i64 = 65
55const FW_UPPER_Z: i64 = 90
56const FW_CASE_DELTA: i64 = 32
57
58func fw_lc(c: i64) -> i64 { if c >= FW_UPPER_A { if c <= FW_UPPER_Z { return c + FW_CASE_DELTA } } return c }
59
60// case-insensitive substring presence. Returns 1 or 0.
61func fw_has(body: *u8, n: i64, lit: *u8) -> i64 {
62 var m: i64 = 0
63 while lit[m] != (0 as u8) { m = m + 1 }
64 if m == 0 { return 0 }
65 if m > n { return 0 }
66 let last: i64 = n - m
67 var i: i64 = 0
68 while i <= last {
69 var j: i64 = 0
70 var ok: i64 = 1
71 while j < m {
72 if fw_lc(body[i + j] as i64) != fw_lc(lit[j] as i64) {
73 ok = 0
74 j = m
75 } else {
76 j = j + 1
77 }
78 }
79 if ok == 1 { return 1 }
80 i = i + 1
81 }
82 return 0
83}
84
85// ---- marker families. Each returns how many of its signals are present, so a single incidental phrase in a
86// real article is visible as a WEAK hit rather than silently deciding a family. ----
87func fw_sig_js(body: *u8, n: i64) -> i64 {
88 var h: i64 = 0
89 if fw_has(body, n, "enablejs" as *u8) == 1 { h = h + 1 }
90 if fw_has(body, n, "enable javascript" as *u8) == 1 { h = h + 1 }
91 if fw_has(body, n, "if you are not redirected" as *u8) == 1 { h = h + 1 }
92 return h
93}
94func fw_sig_challenge(body: *u8, n: i64) -> i64 {
95 var h: i64 = 0
96 if fw_has(body, n, "just a moment" as *u8) == 1 { h = h + 1 }
97 if fw_has(body, n, "cf-browser-verification" as *u8) == 1 { h = h + 1 }
98 if fw_has(body, n, "checking your browser" as *u8) == 1 { h = h + 1 }
99 if fw_has(body, n, "attention required" as *u8) == 1 { h = h + 1 }
100 return h
101}
102func fw_sig_consent(body: *u8, n: i64) -> i64 {
103 var h: i64 = 0
104 if fw_has(body, n, "before you continue" as *u8) == 1 { h = h + 1 }
105 if fw_has(body, n, "consent.google" as *u8) == 1 { h = h + 1 }
106 if fw_has(body, n, "accept all cookies" as *u8) == 1 { h = h + 1 }
107 return h
108}
109func fw_sig_login(body: *u8, n: i64) -> i64 {
110 var h: i64 = 0
111 if fw_has(body, n, "sign in to continue" as *u8) == 1 { h = h + 1 }
112 if fw_has(body, n, "log in to continue" as *u8) == 1 { h = h + 1 }
113 if fw_has(body, n, "please sign in" as *u8) == 1 { h = h + 1 }
114 return h
115}
116
117func fw_name(v: i64) -> *u8 {
118 if v == FW_CONTENT { return "CONTENT" as *u8 }
119 if v == FW_WALL_JS { return "WALL-JS-GATED" as *u8 }
120 if v == FW_WALL_CHALLENGE { return "WALL-BOT-CHALLENGE" as *u8 }
121 if v == FW_WALL_CONSENT { return "WALL-CONSENT" as *u8 }
122 if v == FW_WALL_LOGIN { return "WALL-LOGIN" as *u8 }
123 if v == FW_WALL_UNNAMED { return "WALL-UNNAMED" as *u8 }
124 if v == FW_EMPTY { return "EMPTY" as *u8 }
125 return "UNPROVEN" as *u8
126}
127func fw_is_wall(v: i64) -> i64 {
128 if v >= FW_WALL_JS { if v <= FW_WALL_UNNAMED { return 1 } }
129 return 0
130}
131
132// classify one body. out carries FW_O_* and is fully written on every path.
133func fw_classify(body: *u8, n: i64, out: *i64) -> i64 {
134 var z: i64 = 0
135 while z < FW_O_SLOTS {
136 out[z] = 0
137 z = z + 1
138 }
139 out[FW_O_BODY] = n
140 if n <= 0 {
141 out[FW_O_VERDICT] = FW_UNPROVEN
142 return FW_UNPROVEN
143 }
144 if n < FW_MIN_BYTES {
145 out[FW_O_VERDICT] = FW_EMPTY
146 return FW_EMPTY
147 }
148 // the extraction buffer is DERIVED from the input: fitted text can never exceed the markup that carries
149 // it, so there is no ceiling here to guess wrong in either direction.
150 let cap: i64 = n + 1
151 let txt: *u8 = sys_mmap(cap) as *u8
152 var t: i64 = bd_fit_text(body, n, txt, cap)
153 if t < 0 { t = 0 }
154 out[FW_O_TEXT] = t
155 out[FW_O_PERMIL] = (t * FW_PERMIL) / n
156 out[FW_O_JS] = fw_sig_js(body, n)
157 out[FW_O_CHAL] = fw_sig_challenge(body, n)
158 out[FW_O_CONS] = fw_sig_consent(body, n)
159 out[FW_O_LOGIN] = fw_sig_login(body, n)
160 // STRUCTURE DECIDES WHETHER. A dense body is content even when it talks about cookies and sign-in.
161 if out[FW_O_PERMIL] >= FW_CONTENT_PERMIL {
162 out[FW_O_VERDICT] = FW_CONTENT
163 return FW_CONTENT
164 }
165 // MARKERS DECIDE WHICH. Challenge is tested before JS because a bot-challenge page also carries noscript.
166 if out[FW_O_CHAL] > 0 { out[FW_O_VERDICT] = FW_WALL_CHALLENGE; return FW_WALL_CHALLENGE }
167 if out[FW_O_JS] > 0 { out[FW_O_VERDICT] = FW_WALL_JS; return FW_WALL_JS }
168 if out[FW_O_CONS] > 0 { out[FW_O_VERDICT] = FW_WALL_CONSENT; return FW_WALL_CONSENT }
169 if out[FW_O_LOGIN] > 0 { out[FW_O_VERDICT] = FW_WALL_LOGIN; return FW_WALL_LOGIN }
170 // thin text and no family we can name: still a wall, and SAID to be unnamed rather than called content.
171 out[FW_O_VERDICT] = FW_WALL_UNNAMED
172 return FW_WALL_UNNAMED
173}
174
175// classify a mirrored file. An unreadable path ABSTAINS (UNPROVEN); it never reads as content.
176func fw_classify_file(path: *u8, out: *i64) -> i64 {
177 let lb: *i64 = sys_mmap(FW_SLOT) as *i64
178 lb[0] = 0
179 let body: *u8 = sys_read_file(path, lb)
180 if (body as i64) == 0 {
181 var z: i64 = 0
182 while z < FW_O_SLOTS {
183 out[z] = 0
184 z = z + 1
185 }
186 out[FW_O_VERDICT] = FW_UNPROVEN
187 return FW_UNPROVEN
188 }
189 return fw_classify(body, lb[0], out)
190}