interplane.Get Omega
Read in your language

omega-harness

Agent skills for operating, encoding and communicating in Omega (.om) and the AIEN repositories

Brought by drakestapleton

branch main Branches Tags History

omega-harness / tools / rules.om

1152 lines · 21373 bytes Raw Blame History
1om2
2note rules: the agents' standing rules, from one rules source plus one machine's overlay.
3note
4note rules lint SRC [OVL] check both files; a line of the public SRC may not hold `~/`, `$HOME`,
5note `/home/`, `/Users/`, `/root/`, `/srv/`, `/var/`, `/etc/`, `127.0.0.1`,
6note the host name `spark` (lowercase) or a private repository name
7note (`omega-pearl`, `aien-crypto`), Linear URLs or DRA issue IDs: those go in the overlay
8note rules render SRC OVL PROG HEAD [PATH] the instruction file for PROG, on stdout
9note rules targets SRC OVL `target PROG PATH`, `skills - DIR` and `alarm - FILE` lines
10note rules fit SRC OVL HEAD for each OVL `cap CHARS PATH`: render the target with that PATH and count
11note its characters (UTF-8 code points, as a reader that decodes the file
12note counts them); prints `fit PROG PATH N of CHARS ok|OVER`; exit 1 when
13note a render is over its cap or a cap names no target
14note
15note SRC is rules/rules.txt; OVL is the overlay, kept on one machine and never published. Both have one
16note format, one record per line group:
17note rule ID begins a rule; ID is lowercase letters, digits and `-`, unique over both files
18note date YYYY-MM-DD the date of the statement the rule rests on
19note said TEXT Drake's exact words, when they exist (any number of lines; kept, not rendered)
20note for P ... the programs it applies to: claude, codex, agents, omp, watchdog, generic; `all`
21note includes claude, codex, agents and omp. A generic reader gets agents and generic
22note rules. If its configured cap is exceeded and an agents target is available, it
23note gets the rules marked generic plus directions to the full agents file.
24note order N where it goes in every file it is rendered into (ascending; ties keep SRC
25note before OVL, then file order)
26note | TEXT or | one line of the rendered rule, or an empty one
27note end ends the rule
28note Outside a rule, a line is empty, a comment (`#`), or, in OVL only, `target PROG PATH` (PROG's
29note instruction file on this machine), `skills DIR` (an installed skills directory), `alarm FILE`
30note (where a failed install is reported) or `cap CHARS PATH` (the most characters the reader of the
31note target PATH keeps; `fit` and tools/install.sh refuse a render over it). A rendered file is a header
32note naming HEAD (the last commit that changed the rules) and each rule for PROG in order, separated by an
33note empty line. Same inputs, same bytes. Exit 0 done, 1 lint findings or a render over its cap, 2 usage,
34note read error or a malformed file.
35
36global rb uchar 16777216
37global obuf uchar 16777216
38global ab uchar 4096
39global hd uchar 128
40global nb uchar 32
41global rs ulong 65536
42global re ulong 65536
43global ro ulong 65536
44global rm ulong 65536
45global rk ulong 65536
46global dn uchar 65536
47global st ulong 32
48
49const capb ulong 16777216
50const capr ulong 65536
51const s_n ulong 0
52const s_ns ulong 1
53const s_on ulong 2
54const s_nr ulong 3
55const s_bad ulong 4
56const s_ln ulong 5
57const s_hl ulong 6
58const s_ls ulong 7
59const s_le ulong 8
60const s_al ulong 9
61note allm preserves the shared rules for claude, codex, agents and omp.
62const allm ulong 15
63const genm ulong 32
64
65text a_lint "lint"
66text a_render "render"
67text a_tgts "targets"
68text a_fit "fit"
69text p_claude "claude"
70text p_codex "codex"
71text p_agents "agents"
72text p_omp "omp"
73text p_watch "watchdog"
74text p_gen "generic"
75text p_all "all"
76text w_rule "rule "
77text w_date "date "
78text w_said "said "
79text w_for "for "
80text w_order "order "
81text w_end "end"
82text w_bar "|"
83text w_target "target "
84text w_skills "skills "
85text w_alarm "alarm "
86text w_cap "cap "
87text k_home "~/"
88text k_home2 "/home/"
89text k_users "/Users/"
90text k_srv "/srv/"
91text k_spark "spark"
92text k_pearl "omega-pearl"
93text k_crypto "aien-crypto"
94text k_local "127.0.0.1"
95text k_dhome "$HOME"
96text k_root "/root/"
97text k_var "/var/"
98text k_etc "/etc/"
99text k_linear "linear.app/"
100text k_issue "DRA-"
101text m_use "usage: rules lint SRC [OVL] | rules render SRC OVL PROG HEAD [PATH] | rules targets SRC OVL | rules fit SRC OVL HEAD\n"
102text m_read "rules: cannot read "
103text m_full "rules: refused, the rules files fill the 16777216-byte buffer\n"
104text m_many "rules: refused, more than 65536 rules\n"
105text m_alarm "rules: alarm: the rules files are over half of the 16777216-byte buffer\n"
106text m_prog "rules: unknown program: "
107text f_line ": "
108text f_src "SRC"
109text f_ovl "OVL"
110text f_out "outside a rule, expected rule, a comment or an empty line (OVL also target, skills, alarm or cap)"
111text f_in "inside a rule, expected date, said, for, order, | or end"
112text f_noid "a rule ID is lowercase letters, digits and -"
113text f_dup "the rule ID is used twice"
114text f_nodate "the rule has no date YYYY-MM-DD"
115text f_nofor "the rule has no for line, or names an unknown program"
116text f_noord "the rule has no order N"
117text f_notext "the rule has no | line"
118text f_open "the file ends inside a rule"
119text f_priv "the public rules source holds a home path, host path, host name or private name; move it to the overlay"
120text f_tgt "a target line is `target PROG PATH`: one program (claude, codex, agents, omp, watchdog or generic), one space, and a path"
121text f_cap "a cap line is `cap CHARS PATH`: 1 to 18 digits, one space, and a path"
122text t_fit "fit "
123text t_of " of "
124text t_ok " ok\n"
125text t_over " OVER\n"
126text t_notgt "fit: no target line for the cap path "
127text f_rule " rule "
128text f_rules " rules, "
129text f_tg "findings\n"
130text m_lint "rules: "
131text h_1 "<!-- Generated for "
132text h_2 " by omega-harness tools/rules.om from rules/rules.txt at "
133text h_3 " and this machine's overlay. Do not edit this file: change the rules source and land it, or change the overlay, then run tools/install.sh. -->\n"
134text nl "\n"
135text sp " "
136text dash "- "
137text g_1 "\n## Additional standing rules\nRead the full agent instructions at the following location before doing project work:\n"
138text m_dup_target "more than one target uses the same path"
139text m_path "rules: path is not configured for this program\n"
140text m_over "rules: requested render exceeds its configured cap\n"
141
142note ---------------------------------------------------------------- output
143
144fn wfd fd int t view uchar * to void
145n = len t
146p = ulong 0
147while lt p n bound 4096
148k = write fd t p sub n p
149if le k 0
150exit 2
151end
152p = add p ulong k
153end
154end
155
156fn wnum fd int v ulong to void
157i = ulong 32
158n = v
159while true bound 21
160i = sub i 1
161put nb i uchar add rem n 10 48
162n = div n 10
163if eq n 0
164break
165end
166end
167while lt i 32 bound 32
168k = write fd nb i sub 32 i
169if le k 0
170exit 2
171end
172i = add i ulong k
173end
174end
175
176fn wrb fd int a ulong b ulong to void
177p = a
178while lt p b bound 16777216
179k = write fd rb p sub b p
180if le k 0
181exit 2
182end
183p = add p ulong k
184end
185end
186
187fn o c uchar to void
188n = get st s_on
189if eq n capb
190wfd 2 m_full
191exit 2
192end
193put obuf n c
194put st s_on add n 1
195end
196
197fn ot t view uchar * to void
198for i ulong len t bound 4096
199o get t i
200end
201end
202
203fn orb a ulong b ulong to void
204i = a
205while lt i b bound 16777216
206o get rb i
207i = add i 1
208end
209end
210
211fn flush to void
212n = get st s_on
213p = ulong 0
214while lt p n bound 16777216
215k = write 1 obuf p sub n p
216if le k 0
217exit 2
218end
219p = add p ulong k
220end
221put st s_on 0
222end
223
224note ---------------------------------------------------------------- input
225
226note ldarg: argument i into ab; its length, or a refusal
227fn ldarg i ulong to ulong
228k = argread i ab 0 4096
229if lt k 0
230wfd 2 m_use
231exit 2
232end
233ret ulong k
234end
235
236fn argis t view uchar * k ulong to bool
237if ne k len t
238ret false
239end
240for i ulong k bound 4096
241if ne get ab i get t i
242ret false
243end
244end
245ret true
246end
247
248note ldfile: the file named by argument i, appended to rb
249fn ldfile i ulong to void
250m = ldarg i
251f = fopen ab 0 m 0 0
252if lt f 0
253wfd 2 m_read
254z = write 2 ab 0 m
255wfd 2 nl
256exit 2
257end
258n = get st s_n
259while true bound 16777217
260if eq n capb
261wfd 2 m_full
262exit 2
263end
264k = read int f rb n sub capb n
265if lt k 0
266wfd 2 m_read
267y = write 2 ab 0 m
268wfd 2 nl
269exit 2
270end
271if eq k 0
272break
273end
274n = add n ulong k
275end
276z = fclose int f
277if gt n 0
278if ne get rb sub n 1 10
279if eq n capb
280wfd 2 m_full
281exit 2
282end
283put rb n 10
284n = add n 1
285end
286end
287put st s_n n
288end
289
290note ---------------------------------------------------------------- lines
291
292fn lend p ulong to ulong
293n = get st s_n
294q = p
295while lt q n bound 16777216
296if eq get rb q 10
297ret q
298end
299q = add q 1
300end
301ret n
302end
303
304note lpre: the line [p, e) begins with t
305fn lpre p ulong e ulong t view uchar * to bool
306n = len t
307if lt sub e p n
308ret false
309end
310for i ulong n bound 64
311if ne get rb add p i get t i
312ret false
313end
314end
315ret true
316end
317
318fn lis p ulong e ulong t view uchar * to bool
319if ne sub e p len t
320ret false
321end
322ret lpre p e t
323end
324
325note has: rb[a, b) holds t
326fn has a ulong b ulong t view uchar * to bool
327n = len t
328if lt sub b a n
329ret false
330end
331m = sub b n
332i = a
333while le i m bound 16777216
334same = true
335for j ulong n bound 64
336if ne get rb add i j get t j
337same = false
338break
339end
340end
341if same
342ret true
343end
344i = add i 1
345end
346ret false
347end
348
349fn isdig c uchar to bool
350ret and ge c 48 le c 57
351end
352
353fn isid c uchar to bool
354if isdig c
355ret true
356end
357if and ge c 97 le c 122
358ret true
359end
360ret eq c 45
361end
362
363note word: the program word rb[a, b) as a bit (claude 1, codex 2, agents 4, omp 8, watchdog 16, generic 32, all 15), else 0
364fn wbit a ulong b ulong to ulong
365m = sub b a
366if lis a b p_claude
367ret 1
368end
369if lis a b p_codex
370ret 2
371end
372if lis a b p_agents
373ret 4
374end
375if lis a b p_omp
376ret 8
377end
378if lis a b p_watch
379ret 16
380end
381if lis a b p_all
382ret allm
383end
384if lis a b p_gen
385ret genm
386end
387ret 0
388end
389
390note forbits: the programs of a `for` line [p, e); 0 when one word is unknown
391fn forbits p ulong e ulong to ulong
392m = ulong 0
393i = add p len w_for
394while lt i e bound 4096
395while lt i e bound 4096
396if ne get rb i 32
397break
398end
399i = add i 1
400end
401if ge i e
402break
403end
404j = i
405while lt j e bound 4096
406if eq get rb j 32
407break
408end
409j = add j 1
410end
411b = wbit i j
412if eq b 0
413ret 0
414end
415m = or m b
416i = j
417end
418ret m
419end
420
421note pnum: the decimal rb[a, b) of 1 to 18 digits; the largest ulong (no order) for anything else
422fn pnum a ulong b ulong to ulong
423v = ulong 0
424i = a
425if or eq a b gt sub b a 18
426ret 18446744073709551615
427end
428while lt i b bound 18
429c = get rb i
430if not isdig c
431ret 18446744073709551615
432end
433v = add mul v 10 ulong sub c 48
434i = add i 1
435end
436ret v
437end
438
439fn dig2 a ulong to ulong
440ret add mul ulong sub get rb a 48 10 ulong sub get rb add a 1 48
441end
442
443note isdate: rb[a, b) is YYYY-MM-DD with a month 01..12 and a day 01..31
444fn isdate a ulong b ulong to bool
445if ne sub b a 10
446ret false
447end
448for i ulong 10
449c = get rb add a i
450if or eq i 4 eq i 7
451if ne c 45
452ret false
453end
454else
455if not isdig c
456ret false
457end
458end
459end
460m = dig2 add a 5
461d = dig2 add a 8
462if or lt m 1 gt m 12
463ret false
464end
465ret and ge d 1 le d 31
466end
467
468note ---------------------------------------------------------------- parse
469
470note fnd: a lint finding at line s_ln of SRC or OVL
471fn fnd ovl bool m view uchar * to void
472if ovl
473wfd 1 f_ovl
474else
475wfd 1 f_src
476end
477wfd 1 f_line
478wnum 1 get st s_ln
479wfd 1 f_line
480wfd 1 m
481wfd 1 nl
482put st s_bad add get st s_bad 1
483end
484
485fn ideq a ulong b ulong c ulong d ulong to bool
486if ne sub b a sub d c
487ret false
488end
489k = sub b a
490for i ulong k bound 4096
491if ne get rb add a i get rb add c i
492ret false
493end
494end
495ret true
496end
497
498note newrule: the rule line [p, e) at index r; its ID must be well formed and new
499fn newrule p ulong e ulong r ulong ovl bool to void
500if eq r capr
501wfd 2 m_many
502exit 2
503end
504a = add p len w_rule
505if eq a e
506fnd ovl f_noid
507end
508i = a
509while lt i e bound 4096
510if not isid get rb i
511fnd ovl f_noid
512break
513end
514i = add i 1
515end
516for j ulong r bound 65536
517s = get rs j
518if ideq a e add s len w_rule lend s
519fnd ovl f_dup
520end
521end
522put rs r p
523put ro r 18446744073709551615
524put rm r 0
525put rk r 0
526put dn r 0
527if ovl
528put rk r 1
529end
530end
531
532note parse: every line of rb; the rules into rs, re, ro, rm, rk (0 SRC, 1 OVL)
533fn parse to void
534n = get st s_n
535ns = get st s_ns
536r = ulong 0
537inr = false
538txt = false
539p = ulong 0
540while lt p n bound 16777216
541if eq p ns
542if inr
543put st s_ln 0
544fnd false f_open
545inr = false
546end
547put st s_ln 0
548end
549ovl = ge p ns
550e = lend p
551put st s_ln add get st s_ln 1
552if inr
553txt = line p e r ovl txt
554if lis p e w_end
555put re r e
556if not txt
557fnd ovl f_notext
558end
559if eq get dn r 0
560fnd ovl f_nodate
561end
562if eq get rm r 0
563fnd ovl f_nofor
564end
565if eq get ro r 18446744073709551615
566fnd ovl f_noord
567end
568r = add r 1
569inr = false
570end
571else
572if lpre p e w_rule
573newrule p e r ovl
574inr = true
575txt = false
576else
577outer p e ovl
578end
579end
580p = add e 1
581end
582if inr
583fnd true f_open
584end
585put st s_nr r
586end
587
588note line: one line [p, e) inside rule r; returns whether the rule has text now
589fn line p ulong e ulong r ulong ovl bool txt bool to bool
590if lis p e w_end
591ret txt
592end
593if lpre p e w_bar
594if or eq sub e p 1 eq get rb add p 1 32
595ret true
596end
597fnd ovl f_in
598ret txt
599end
600if lpre p e w_date
601if isdate add p len w_date e
602put dn r 1
603else
604fnd ovl f_nodate
605end
606ret txt
607end
608if lpre p e w_said
609ret txt
610end
611if lpre p e w_for
612put rm r forbits p e
613ret txt
614end
615if lpre p e w_order
616put ro r pnum add p len w_order e
617ret txt
618end
619fnd ovl f_in
620ret txt
621end
622
623note okt: the target line [p, e) is `target PROG PATH`: one known program (not `all`), one space, a path
624fn okt p ulong e ulong to bool
625a = add p len w_target
626q = a
627while lt q e bound 4096
628if eq get rb q 32
629break
630end
631q = add q 1
632end
633b = wbit a q
634if or eq b 0 eq b allm
635ret false
636end
637if ge add q 1 e
638ret false
639end
640ret ne get rb add q 1 32
641end
642
643note outer: a line outside every rule
644fn outer p ulong e ulong ovl bool to void
645if eq p e
646ret
647end
648if eq get rb p 35
649ret
650end
651if ovl
652if lpre p e w_target
653if not okt p e
654fnd ovl f_tgt
655else
656a = add p len w_target
657while ne get rb a 32 bound 4096
658a = add a 1
659end
660if ne tfind add a 1 e p
661fnd ovl m_dup_target
662end
663end
664ret
665end
666if or lpre p e w_skills lpre p e w_alarm
667ret
668end
669if lpre p e w_cap
670if not okc p e
671fnd ovl f_cap
672end
673ret
674end
675end
676fnd ovl f_out
677end
678
679note okc: the OVL line [p, e) is `cap CHARS PATH`: 1 to 18 digits, one space, a path
680fn okc p ulong e ulong to bool
681a = add p len w_cap
682q = a
683while lt q e bound 4096
684if eq get rb q 32
685break
686end
687q = add q 1
688end
689if eq pnum a q 18446744073709551615
690ret false
691end
692if ge add q 1 e
693ret false
694end
695ret ne get rb add q 1 32
696end
697
698note private: the public SRC holds no home path, host path, host name or private name
699fn private to void
700ns = get st s_ns
701p = ulong 0
702put st s_ln 0
703while lt p ns bound 16777216
704e = lend p
705put st s_ln add get st s_ln 1
706if or has p e k_home or has p e k_home2 or has p e k_users has p e k_srv
707fnd false f_priv
708else
709if or has p e k_spark or has p e k_pearl or has p e k_crypto has p e k_local
710fnd false f_priv
711else
712if or has p e k_dhome or has p e k_root or has p e k_var has p e k_etc
713fnd false f_priv
714else
715if or has p e k_linear has p e k_issue
716fnd false f_priv
717end
718end
719end
720end
721p = add e 1
722end
723end
724
725note ---------------------------------------------------------------- render
726
727note orule: the | lines of rule r
728fn orule r ulong to void
729p = get rs r
730e = get re r
731while lt p e bound 16777216
732q = lend p
733if lpre p q w_bar
734if gt sub q p 1
735orb add p 2 q
736end
737o 10
738end
739p = add q 1
740end
741end
742
743note pick: the next rule in order for program bit m, after the ones marked done; capr when none
744fn pick m ulong to ulong
745nr = get st s_nr
746best = capr
747for i ulong nr bound 65536
748if and eq get dn i 0 ne and get rm i m 0
749if eq best capr
750best = i
751else
752if lt get ro i get ro best
753best = i
754end
755end
756end
757end
758ret best
759end
760
761note tprog: the program bit of the OVL `target PROG PATH` line [p, e); 0 for any other line
762fn tprog p ulong e ulong to ulong
763if not lpre p e w_target
764ret 0
765end
766a = add p len w_target
767q = a
768while lt q e bound 4096
769if eq get rb q 32
770break
771end
772q = add q 1
773end
774ret wbit a q
775end
776
777note Print the path of a full agents file, if one exists. Its unchanged render contains all shared and agents-only rules.
778fn agentptr to bool
779p = get st s_ns
780while lt p get st s_n bound 16777216
781e = lend p
782if eq tprog p e 4
783ot g_1
784orb add p len w_target e
785o 10
786ret true
787end
788p = add e 1
789end
790ret false
791end
792
793note build: the file for program bit m into obuf (the header names ab[0, s_al) and hd)
794fn build m ulong compact bool to void
795nr = get st s_nr
796for i ulong nr bound 65536
797put dn i 0
798end
799ot h_1
800for j ulong get st s_al bound 4096
801o get ab j
802end
803ot h_2
804for k ulong get st s_hl bound 128
805o get hd k
806end
807ot h_3
808if eq m genm
809if not compact
810m = or m 4
811else
812if not agentptr
813m = or m 4
814end
815end
816end
817c = ulong 0
818while true bound 65537
819r = pick m
820if eq r capr
821break
822end
823put dn r 1
824o 10
825orule r
826c = add c 1
827end
828end
829
830
831note ---------------------------------------------------------------- fit
832
833note tfind: the start of the OVL `target PROG PATH` line whose PATH is rb[a, b); s_n when there is none
834fn tfind a ulong b ulong to ulong
835n = get st s_n
836p = get st s_ns
837while lt p n bound 16777216
838e = lend p
839if lpre p e w_target
840s = add p len w_target
841while lt s e bound 4096
842if eq get rb s 32
843break
844end
845s = add s 1
846end
847if lt s e
848if ideq add s 1 e a b
849ret p
850end
851end
852end
853p = add e 1
854end
855ret n
856end
857
858note nchars: the characters of obuf (UTF-8 code points: every byte that is not a continuation byte)
859fn nchars to ulong
860n = get st s_on
861c = ulong 0
862for i ulong n bound 16777216
863if ne and get obuf i 192 128
864c = add c 1
865end
866end
867ret c
868end
869
870note Rebuild only an oversized generic render. The same selection is used by fit and by installation.
871fn boundedbuild m ulong lim ulong to ulong
872put st s_on 0
873build m false
874k = nchars
875if and eq m genm gt k lim
876put st s_on 0
877build m true
878k = nchars
879end
880ret k
881end
882
883note A path comparison uses the complete byte span, including any interior spaces.
884fn patharg a ulong e ulong size ulong to bool
885if ne sub e a size
886ret false
887end
888for i ulong size bound 4096
889if ne get ab i get rb add a i
890ret false
891end
892end
893ret true
894end
895
896note For the exact target and program, return the strictest cap or the maximum ulong if uncapped.
897fn pathlimit size ulong program ulong to ulong
898lim = ulong 18446744073709551615
899found = false
900p = get st s_ns
901while lt p get st s_n bound 16777216
902e = lend p
903cap = lpre p e w_cap
904if or cap eq tprog p e program
905a = add p len w_target
906if cap
907a = add p len w_cap
908end
909q = a
910while lt q e bound 4096
911if eq get rb q 32
912break
913end
914q = add q 1
915end
916if patharg add q 1 e size
917if cap
918v = pnum a q
919if lt v lim
920lim = v
921end
922else
923found = true
924end
925end
926end
927p = add e 1
928end
929if not found
930wfd 2 m_path
931exit 2
932end
933ret lim
934end
935
936note fit: every OVL `cap CHARS PATH` line against the render of its target; a finding for each render over
937note its cap and each cap without a target
938fn fit to void
939n = get st s_n
940p = get st s_ns
941while lt p n bound 16777216
942e = lend p
943if lpre p e w_cap
944a = add p len w_cap
945q = a
946while lt q e bound 4096
947if eq get rb q 32
948break
949end
950q = add q 1
951end
952lim = pnum a q
953t = tfind add q 1 e
954if eq t n
955wfd 1 t_notgt
956wrb 1 add q 1 e
957wfd 1 nl
958put st s_bad add get st s_bad 1
959else
960g = add t len w_target
961h = g
962while lt h e bound 4096
963if eq get rb h 32
964break
965end
966h = add h 1
967end
968for i ulong sub h g bound 4096
969put ab i get rb add g i
970end
971put st s_al sub h g
972k = boundedbuild wbit g h lim
973put st s_on 0
974wfd 1 t_fit
975wrb 1 g h
976wfd 1 sp
977wrb 1 add q 1 e
978wfd 1 sp
979wnum 1 k
980wfd 1 t_of
981wnum 1 lim
982if gt k lim
983wfd 1 t_over
984put st s_bad add get st s_bad 1
985else
986wfd 1 t_ok
987end
988end
989end
990p = add e 1
991end
992end
993
994note ---------------------------------------------------------------- targets
995
996fn targets to void
997n = get st s_n
998p = get st s_ns
999while lt p n bound 16777216
1000e = lend p
1001if lpre p e w_target
1002orb p e
1003o 10
1004end
1005if lpre p e w_skills
1006ot w_skills
1007ot dash
1008orb add p len w_skills e
1009o 10
1010end
1011if lpre p e w_alarm
1012ot w_alarm
1013ot dash
1014orb add p len w_alarm e
1015o 10
1016end
1017p = add e 1
1018end
1019flush
1020end
1021
1022note ---------------------------------------------------------------- main
1023
1024fn main to int
1025c = argcnt
1026if lt c 3
1027wfd 2 m_use
1028ret 2
1029end
1030k = ldarg 1
1031mode = ulong 9
1032if argis a_lint k
1033mode = ulong 0
1034end
1035if argis a_render k
1036mode = ulong 1
1037end
1038if argis a_tgts k
1039mode = ulong 2
1040end
1041if argis a_fit k
1042mode = ulong 3
1043end
1044if and eq mode 1 and ne c 6 ne c 7
1045wfd 2 m_use
1046ret 2
1047end
1048if or eq mode 9 or and eq mode 2 ne c 4 and eq mode 3 ne c 5
1049wfd 2 m_use
1050ret 2
1051end
1052if and eq mode 0 gt c 4
1053wfd 2 m_use
1054ret 2
1055end
1056put st s_n 0
1057put st s_on 0
1058put st s_bad 0
1059ldfile 2
1060put st s_ns get st s_n
1061if ge c 4
1062ldfile 3
1063end
1064parse
1065if eq mode 0
1066private
1067if gt get st s_n div capb 2
1068wfd 1 m_alarm
1069put st s_bad add get st s_bad 1
1070end
1071wfd 1 m_lint
1072wnum 1 get st s_nr
1073wfd 1 f_rules
1074wnum 1 get st s_bad
1075wfd 1 sp
1076wfd 1 f_tg
1077if ne get st s_bad 0
1078ret 1
1079end
1080ret 0
1081end
1082if ne get st s_bad 0
1083ret 2
1084end
1085if eq mode 2
1086targets
1087ret 0
1088end
1089hi = ulong 5
1090if eq mode 3
1091hi = ulong 4
1092end
1093h = ldarg hi
1094if gt h 128
1095wfd 2 m_use
1096ret 2
1097end
1098for i ulong h bound 128
1099put hd i get ab i
1100end
1101put st s_hl h
1102if eq mode 3
1103fit
1104if ne get st s_bad 0
1105ret 1
1106end
1107ret 0
1108end
1109lim = ulong 18446744073709551615
1110a = ldarg 4
1111m = wbit2 a
1112if eq m 0
1113wfd 2 m_prog
1114z = write 2 ab 0 a
1115wfd 2 nl
1116ret 2
1117end
1118if eq c 7
1119lim = pathlimit ldarg 6 m
1120a = ldarg 4
1121end
1122put st s_al a
1123if gt boundedbuild m lim lim
1124wfd 2 m_over
1125ret 1
1126end
1127flush
1128ret 0
1129end
1130
1131note wbit2: the program named by ab[0, a)
1132fn wbit2 a ulong to ulong
1133if argis p_claude a
1134ret 1
1135end
1136if argis p_codex a
1137ret 2
1138end
1139if argis p_agents a
1140ret 4
1141end
1142if argis p_omp a
1143ret 8
1144end
1145if argis p_watch a
1146ret 16
1147end
1148if argis p_gen a
1149ret genm
1150end
1151ret 0
1152end