interplane.Get Omega
Read in your language

sovereign-intelligence

Front door to Drake Stapleton's sovereign stack.

Brought by drakestapleton

branch main Branches Tags History

sovereign-intelligence / compiler / links.om

558 lines · 12329 bytes Raw Blame History
1om2
2note compiler/links.om: the link check of sovereign-intelligence, in pure seeded Omega.
3note
4note Build with the pinned seeded compiler (compiler/README.md names the pin):
5note omc < compiler/links.om > links && chmod +x links
6note Run, from anywhere:
7note links ROOT
8note ROOT is a checkout of this repository. links checks two things and writes nothing:
9note 1. every row of ROOT/repos.tsv, the link table, is a project that is only linked: a
10note name, a valid Radicle ID ("rad:z" then 27 or 28 base58 characters that decode to a
11note 20-byte id), a 40-digit head and a tier of core or rest. The withdrawn crypto
12note projects (any name containing pearl or crypto, in any case, and any RID that starts
13note rad:z2ft64) are refused;
14note 2. no new project source is vendored into SI. The entries of ROOT, ROOT/compiler and
15note ROOT/gpu must each be on the lists below, with the kind named there; .git is
16note skipped. ROOT may hold the regular files README.md, repos.tsv, CITATION.cff,
17note LICENSE, .gitignore and build.sh, README.zh-CN.md (the Simplified Chinese README, exactly
18note that name and only at ROOT; Drake, 2026-11-11, "approved for all"), the untracked build
19note outputs si, si.sh and links (files) and out (build.sh's directory), and the
20note directories .claude, compiler, docs,
21note evidence, gpu, harness, seed, stack, tests and tools: the GitHub line's existing
22note directories, grandfathered as they are, contents unchecked (Drake, 2026-11-07).
23note ROOT/gpu may hold only the directory cuda-crack. ROOT/compiler
24note may hold only the regular files README.md, si.om, gate.om, links.om, inventory.tsv,
25note order.tsv, state.tsv and gate-3c37e6fb.tsv. Any other file, directory or symbolic
26note link there is refused: a project is linked by its RID, never copied in.
27note It prints "links: pass" and the row count, exit 0; or "links: " and the first refusal on
28note stderr, exit 1. Usage errors exit 2.
29
30text tlk "links: "
31text tnl "\n"
32text tusage "usage: links ROOT\n"
33text tpass "pass: "
34text tpass2 " link rows, every RID valid; root, compiler/ and gpu/ hold only SI entries\n"
35text targ "cannot read the command-line argument"
36text topen "cannot open "
37text tread "cannot read "
38text tbig "file over the 1 MiB buffer: "
39text tlong "path over 4000 bytes: "
40text thdr "repos.tsv header is not name TAB rid TAB head TAB tier TAB description: "
41text tcols "repos.tsv line needs 5 tab-separated fields: "
42text tbname "bad project name (letters, digits, . _ - only): "
43text tbrid "RID is not rad:z then 27 or 28 base58 characters of a 20-byte id: "
44text tcrypt "withdrawn crypto project is never linked: "
45text tbhead "head is not a 40-digit lowercase hex commit: "
46text tbtier "tier is not core or rest: "
47text tnone "repos.tsv lists no project"
48text tvend "not an SI file; project source lives on Radicle, never in SI: "
49text trepos "/repos.tsv"
50text tcomp "/compiler"
51text tgpu "/gpu"
52text hdr "name\trid\thead\ttier\tdescription"
53text tradz "rad:z"
54text tbad "rad:z2ft64"
55text tpearl "pearl"
56text tcrypto "crypto"
57text tcore "core"
58text trest "rest"
59text b58 "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
60text tdot "."
61text tdotdot ".."
62text tgit ".git"
63text tcdir "compiler"
64text a1 "README.md"
65text a2 "repos.tsv"
66text a3 "CITATION.cff"
67text a4 "LICENSE"
68text a5 ".gitignore"
69text a6 "si"
70text a7 "si.sh"
71text a8 "links"
72text a9 "build.sh"
73text a10 "README.zh-CN.md"
74text a11 "layers.tsv"
75text d1 ".claude"
76text d2 "docs"
77text d3 "evidence"
78text d4 "gpu"
79text d5 "harness"
80text d6 "seed"
81text d7 "stack"
82text d8 "tests"
83text d9 "tools"
84text g1 "cuda-crack"
85text tout "out"
86text c1 "si.om"
87text c2 "gate.om"
88text c3 "links.om"
89text c4 "inventory.tsv"
90text c5 "order.tsv"
91text c6 "state.tsv"
92text c7 "gate-3c37e6fb.tsv"
93text c8 "rebuild.om"
94
95note src: repos.tsv; pb: the path being checked; rt: ROOT; db: getdents64 records; sb: stat
96global src uchar 1048576
97global pb uchar 4096
98global pbn ulong 1
99global rt uchar 4096
100global rtn ulong 1
101global db uchar 32768
102global sb uchar 128
103note bn: a base58 RID decoded big-endian into 21 bytes; byte 0 must stay 0
104global bn uchar 21
105
106note die: "links: " m, then n bytes of src from o (at most 200), on stderr; exit 1
107fn die m view uchar * o ulong n ulong to void
108k = n
109if gt k 200
110k = 200
111end
112w = write 2 tlk 0 len tlk
113w = write 2 m 0 len m
114if gt k 0
115w = write 2 src o k
116end
117w = write 2 tnl 0 len tnl
118exit 1
119end
120
121note dief: "links: " m and the path pb on stderr; exit 1
122fn dief m view uchar * to void
123w = write 2 tlk 0 len tlk
124w = write 2 m 0 len m
125w = write 2 pb 0 get pbn 0
126w = write 2 tnl 0 len tnl
127exit 1
128end
129
130note proot: pb becomes ROOT
131fn proot to void
132n = get rtn 0
133for i ulong n
134put pb i get rt i
135end
136put pbn 0 n
137end
138
139note padd: append a text to pb
140fn padd t view uchar * to void
141p = get pbn 0
142n = len t
143if gt add p n 4000
144dief tlong
145end
146for i ulong n
147put pb add p i get t i
148end
149put pbn 0 add p n
150end
151
152note eqt: do the n bytes of src at o equal the text t
153fn eqt o ulong n ulong t view uchar * to bool
154if ne n len t
155ret false
156end
157for i ulong n
158if ne get src add o i get t i
159ret false
160end
161end
162ret true
163end
164
165note eqd: do the n bytes of db at o equal the text t
166fn eqd o ulong n ulong t view uchar * to bool
167if ne n len t
168ret false
169end
170for i ulong n
171if ne get db add o i get t i
172ret false
173end
174end
175ret true
176end
177
178fn isaln c uchar to bool
179ret or or and ge c 48 le c 57 and ge c 65 le c 90 and ge c 97 le c 122
180end
181
182note okname: 1..64 bytes of letters, digits, dot, dash, underscore; not ".", "..", or a leading dash
183fn okname o ulong n ulong to bool
184if or eq n 0 gt n 64
185ret false
186end
187if eq get src o 45
188ret false
189end
190for i ulong n
191c = get src add o i
192if not or isaln c or eq c 46 or eq c 45 eq c 95
193ret false
194end
195end
196if eqt o n tdot
197ret false
198end
199ret not eqt o n tdotdot
200end
201
202note b58v: the base58 value of c, or 58 when c is not a base58 character
203fn b58v c uchar to ulong
204for k ulong 58
205if eq c get b58 k
206ret k
207end
208end
209ret 58
210end
211
212note okrid: "rad:z" then 27 or 28 base58 characters whose value fits in 20 bytes
213fn okrid o ulong n ulong to bool
214if or lt n 32 gt n 33
215ret false
216end
217if not eqt o 5 tradz
218ret false
219end
220for j ulong 21
221put bn j 0
222end
223for i ulong sub n 5
224v = b58v get src add add o 5 i
225if eq v 58
226ret false
227end
228cy = v
229for j ulong 21
230q = sub 20 j
231x = add mul ulong get bn q 58 cy
232put bn q uchar and x 255
233cy = shr x 8
234end
235if ne cy 0
236ret false
237end
238end
239ret eq get bn 0 0
240end
241
242note okhex: exactly 40 lowercase hex digits
243fn okhex o ulong n ulong to bool
244if ne n 40
245ret false
246end
247for i ulong n
248c = get src add o i
249if not or and ge c 48 le c 57 and ge c 97 le c 102
250ret false
251end
252end
253ret true
254end
255
256note lowc: byte i of src, an ASCII capital folded to lowercase
257fn lowc i ulong to ulong
258c = ulong get src i
259if and ge c 65 le c 90
260ret add c 32
261end
262ret c
263end
264
265note atci: do the bytes of src at o equal the lowercase text t, ignoring ASCII case
266fn atci o ulong t view uchar * to bool
267for i ulong len t
268if ne lowc add o i ulong get t i
269ret false
270end
271end
272ret true
273end
274
275note hasci: does [o, o+n) of src contain the lowercase text t, ignoring ASCII case
276fn hasci o ulong n ulong t view uchar * to bool
277if lt n len t
278ret false
279end
280for i ulong add sub n len t 1
281if atci add o i t
282ret true
283end
284end
285ret false
286end
287
288note crypto: is this row a withdrawn crypto project: a name containing pearl or crypto in any
289note case, or a RID that starts rad:z2ft64
290fn crypto no ulong nn ulong ro ulong rn ulong to bool
291if hasci no nn tpearl
292ret true
293end
294if hasci no nn tcrypto
295ret true
296end
297if lt rn len tbad
298ret false
299end
300ret eqt ro len tbad tbad
301end
302
303note fo, fe: start and end of the five fields of the current repos.tsv line; fln: field k's length
304global fo ulong 5
305global fe ulong 5
306
307fn fln k ulong to ulong
308ret sub get fe k get fo k
309end
310
311note row: check one repos.tsv line [p, q)
312fn row p ulong q ulong to void
313k = ulong 0
314put fo 0 p
315c = p
316while lt c q bound 1048577
317if eq get src c 9
318if ge k 4
319die tcols p sub q p
320end
321put fe k c
322k = add k 1
323put fo k add c 1
324end
325c = add c 1
326end
327if ne k 4
328die tcols p sub q p
329end
330put fe 4 q
331if not okname get fo 0 fln 0
332die tbname p sub q p
333end
334if crypto get fo 0 fln 0 get fo 1 fln 1
335die tcrypt p sub q p
336end
337if not okrid get fo 1 fln 1
338die tbrid p sub q p
339end
340if not okhex get fo 2 fln 2
341die tbhead p sub q p
342end
343if not or eqt get fo 3 fln 3 tcore eqt get fo 3 fln 3 trest
344die tbtier p sub q p
345end
346end
347
348note rows: read ROOT/repos.tsv, check its header and every row; the row count
349fn rows to ulong
350proot
351padd trepos
352fd = fopen pb 0 get pbn 0 524288 0
353if lt fd 0
354dief topen
355end
356p = ulong 0
357while lt p 1048576 bound 1048577
358k = read int fd src p sub 1048576 p
359if lt k 0
360dief tread
361end
362if eq k 0
363break
364end
365p = add p ulong k
366end
367c = fclose int fd
368if ge p 1048576
369dief tbig
370end
371e = p
372q = ulong 0
373while lt q e bound 1048577
374if eq get src q 10
375break
376end
377q = add q 1
378end
379if not eqt 0 q hdr
380die thdr 0 q
381end
382nr = ulong 0
383s = add q 1
384while lt s e bound 1048577
385t = s
386while lt t e bound 1048577
387if eq get src t 10
388break
389end
390t = add t 1
391end
392row s t
393nr = add nr 1
394s = add t 1
395end
396if eq nr 0
397die tnone 0 0
398end
399ret nr
400end
401
402note rootf, rootd: may [o, o+n) of db stand in ROOT as a regular file, as a directory
403fn rootf o ulong n ulong to bool
404if eqd o n a11
405ret true
406end
407if or or or or eqd o n a1 eqd o n a2 eqd o n a3 eqd o n a4 eqd o n a5
408ret true
409end
410ret or or or or eqd o n a6 eqd o n a7 eqd o n a8 eqd o n a9 eqd o n a10
411end
412
413fn rootd o ulong n ulong to bool
414if or or or or or eqd o n tcdir eqd o n d1 eqd o n d2 eqd o n d3 eqd o n d4 eqd o n d5
415ret true
416end
417ret or or or or eqd o n d6 eqd o n d7 eqd o n d8 eqd o n d9 eqd o n tout
418end
419
420note allowed: may the entry [o, o+n) of db, of file type m, stand in directory set w
421note (1 ROOT, 2 compiler, 3 gpu)
422fn allowed w ulong o ulong n ulong m ulong to bool
423reg = eq m 32768
424dir = eq m 16384
425if eq w 1
426ret or and reg rootf o n and dir rootd o n
427end
428if eq w 3
429ret and dir eqd o n g1
430end
431if not reg
432ret false
433end
434if eqd o n c8
435ret true
436end
437if or or or eqd o n a1 eqd o n c1 eqd o n c2 eqd o n c3
438ret true
439end
440ret or or or eqd o n c4 eqd o n c5 eqd o n c6 eqd o n c7
441end
442
443note entry: check the getdents64 record at p of db in directory pb[0, base) of set w; its length.
444note The entry's type is the record's d_type (byte 18: 4 directory, 8 regular file), whose layout
445note is the same on AArch64 and x86-64 (an lstat buffer is not). Any other d_type, including a
446note symbolic link or DT_UNKNOWN, is not allowed: the check fails closed. compiler/gate.om plants
447note stray files, symbolic links and a stray directory in ROOT, ROOT/compiler and ROOT/gpu; it cannot
448note plant DT_UNKNOWN, which ext4 and tmpfs never return, so a mutant that read DT_UNKNOWN as a
449note directory would pass the gate there.
450fn entry w ulong base ulong p ulong to ulong
451rl = add ulong get db add p 16 mul ulong get db add p 17 256
452if eq rl 0
453dief tread
454end
455o = add p 19
456n = ulong 0
457while lt add o n add p rl bound 32769
458if eq get db add o n 0
459break
460end
461n = add n 1
462end
463if or eqd o n tdot eqd o n tdotdot
464ret rl
465end
466if and eq w 1 eqd o n tgit
467ret rl
468end
469put pb base 47
470if gt add add base 1 n 4000
471dief tlong
472end
473for i ulong n
474put pb add add base 1 i get db add o i
475end
476put pbn 0 add add base 1 n
477t = get db add p 18
478m = ulong 0
479if eq t 8
480m = ulong 32768
481end
482if eq t 4
483m = ulong 16384
484end
485good = allowed w o n m
486if not good
487dief tvend
488end
489put pbn 0 base
490ret rl
491end
492
493note walk: check every entry of the directory pb (set w); pb is restored on return
494fn walk w ulong to void
495base = get pbn 0
496fd = fopen pb 0 base 524288 0
497if lt fd 0
498dief topen
499end
500while true bound 1048577
501k = getdnts int fd db 0 32768
502if lt k 0
503dief tread
504end
505if eq k 0
506break
507end
508p = ulong 0
509while lt p ulong k bound 32769
510p = add p entry w base p
511end
512end
513c = fclose int fd
514end
515
516fn main to int
517if ne argcnt 2
518w = write 2 tusage 0 len tusage
519ret 2
520end
521n = argread 1 rt 0 3900
522if le n 0
523w = write 2 tusage 0 len tusage
524ret 2
525end
526put rtn 0 ulong n
527nr = rows
528proot
529walk 1
530proot
531padd tcomp
532walk 2
533proot
534padd tgpu
535r = lstat pb 0 get pbn 0 sb 0 128
536if eq r 0
537walk 3
538end
539w = write 1 tlk 0 len tlk
540w = write 1 tpass 0 len tpass
541d = new uchar 20 0
542x = nr
543k = ulong 0
544while true bound 21
545put d k uchar add rem x 10 48
546k = add k 1
547x = div x 10
548if eq x 0
549break
550end
551end
552while gt k 0 bound 21
553k = sub k 1
554w = write 1 d k 1
555end
556w = write 1 tpass2 0 len tpass2
557ret 0
558end