interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / protocol / synapse / pulse / src / 10pulse.om

1926 lines · 36688 bytes Raw Blame History
1note synapse-pulse 10pulse.om: reconcile the claims ledger with GitHub and live omp sessions.
2global gop ulong 16
3global gopl ulong 16
4global gfl ulong 8
5global gnow ulong 2
6global gco ulong 16384
7global gcl ulong 16384
8global gca uchar 1024
9global gkd uchar 1024
10global gcn ulong 1
11global gtk uint 24576
12global gtn ulong 1024
13global grpo ulong 128
14global grpl ulong 128
15global grp uchar 128
16global grn ulong 1
17global gprr ulong 8192
18global gprn ulong 8192
19global gprs uchar 8192
20global gprm uchar 8192
21global gprho ulong 8192
22global gprhl ulong 8192
23global gprc ulong 1
24global gcnt ulong 32
25global gout uchar 4194304
26global gon ulong 1
27global gfp ulong 8
28global gstop uint 32
29global garr ulong 16
30global gstopn ulong 1
31global gmo ulong 1
32global gss ulong 4
33global ghs ulong 16
34global ghit uchar 1024
35
36text tusage "usage: synapse-pulse [--home DIR] run [--alert] [--alert-dir DIR] [--gh PATH] [--sessions DIR] [--claims-bin PATH] [--offline FIXTUREDIR] [--now YYYY-MM-DDTHH:MM:SSZ]"
37text trun "run"
38text thome "--home"
39text talert "--alert"
40text tadir "--alert-dir"
41text tgh "--gh"
42text tsess "--sessions"
43text tcbin "--claims-bin"
44text toff "--offline"
45text tnow "--now"
46text tenvh "AIEN_COORD_HOME="
47text tenvhm "HOME="
48text tdhome "/.local/state/aien-coord"
49text tenvpath "PATH="
50text tdadir "/.local/state/aienos/watch"
51text tdgh "/.local/bin/gh"
52text tdsess "/.omp/agent/sessions"
53text tdpath "/usr/bin:/bin"
54text tnohome "synapse-pulse: no --home, AIEN_COORD_HOME or HOME"
55text tbadenvh "synapse-pulse: HOME must be an absolute path"
56text tnohadir "synapse-pulse: HOME is not set: pass --alert-dir DIR or set HOME"
57text tnohgh "synapse-pulse: HOME is not set: pass --gh PATH or set HOME"
58text tnohsess "synapse-pulse: HOME is not set: pass --sessions DIR or set HOME"
59text tnohkid "synapse-pulse: HOME is not set: the gh child needs HOME (set HOME, or use --offline)"
60text tnocbin "synapse-pulse: --claims-bin PATH is required (absolute path to synapse-claims)"
61text tbadnow "synapse-pulse: --now must be YYYY-MM-DDTHH:MM:SSZ"
62text tlist "list"
63text tall "--all"
64text tconf "conflicts"
65text texpire "expire"
66text tagent "--agent"
67text tpulse "pulse"
68text tslpu "/pulse"
69text tsletag "/pulse/etags"
70text tslfind "/pulse/findings.jsonl"
71text tslreq "/pulse/requests.log"
72text tsl "/"
73text tetag ".etag"
74text tbody ".body"
75text thttp ".http"
76text tenv "/usr/bin/env"
77text tapi "api"
78text tdi "-i"
79text tdh "-H"
80text tinm "If-None-Match: "
81text tclfail "synapse-pulse: synapse-claims failed: "
82text tclbad "synapse-pulse: malformed synapse-claims output line"
83text tkid "id"
84text tkagent "agent"
85text tksess "session"
86text tkkind "kind"
87text tktarg "target"
88text tkmode "mode"
89text tkstate "state"
90text tkint "intent"
91text tkexp "expires"
92text tkact "active"
93text tksince "since"
94text tka "a"
95text tkb "b"
96text tkreas "reason"
97text tkop "op"
98text tknum "number"
99text tkmerg "merged_at"
100text tkhead "head"
101text tkref "ref"
102text tkfile "filename"
103text topen "open"
104text tclosed "closed"
105text tprepo "repo:"
106text tpbr "branch:"
107text tppath "path:"
108text tppr "pr:"
109text tpext "ext:"
110text tmerged "MERGED"
111text tdeploy "DEPLOYED"
112text tjsonl ".jsonl"
113text tpulls "/pulls?state=all&per_page=50"
114text tfiles "/files?per_page=100"
115text trepos "repos/"
116text tpullsl "/pulls/"
117text tqk "{\"kind\":\""
118text tqsev "\",\"severity\":\""
119text tqrepo "\",\"repo\":"
120text tqtarg ",\"target\":"
121text tqid ",\"id\":"
122text tqagent ",\"agent\":"
123text tqsess ",\"session\":"
124text tqpr ",\"pr\":"
125text tqpath ",\"path\":"
126text tqoid ",\"other_id\":"
127text tqoag ",\"other_agent\":"
128text tqdet ",\"detail\":"
129text tqend "}\n"
130text tsevw "warn"
131text tsevi "info"
132text tseve "error"
133text fexp "expired_lease"
134text fdead "dead_session"
135text funk "unknown_session"
136text funcl "unclaimed_pr"
137text fstcon "status_contradicted"
138text fdup "duplicate_work"
139text fconf "conflict"
140text tstops "with from into this that them they were been have will also make should would could than then when what which there their about after before over under only just more most some such each other being does done must need"
141text tcap "synapse-pulse: GitHub request cap (40 per run) reached; skipped: "
142text tghfail "synapse-pulse: GitHub read failed: "
143text tbig "synapse-pulse: response over 983040 bytes, skipped: "
144text tnofix "synapse-pulse: offline fixture missing: "
145text tsp " "
146text tinmeq " inm="
147text tstateq " status="
148text tbyteq " bytes="
149text tsrceq " source="
150text tsgh "gh"
151text tsoff "offline"
152text tscache "cache"
153text tdash "-"
154text texpok "synapse-pulse: exec synapse-claims expire --agent pulse exit="
155text tevents " events="
156text tkalert "COORD-DRIFT"
157text tslalert "/ALERT"
158text tslalog "/alerts.log"
159text tsince " (since "
160text tdetails "; details "
161text tclear "/alerts.log; clear with: aien-watch clear COORD-DRIFT)\n"
162text tresolv " RESOLVED COORD-DRIFT "
163text tcolsp ": "
164text tkalcol "COORD-DRIFT:"
165
166fn pu_ob c uchar to void
167n = get gon 0
168if ge n len gout
169put gfl 7 1
170ret
171end
172put gout n c
173put gon 0 add n 1
174end
175
176fn pu_ot t view uchar * to void
177for i ulong len t
178pu_ob get t i
179end
180end
181
182fn pu_od v ulong to void
183m = syn_mark
184syn_pd v
185for i ulong syn_len m
186pu_ob get gsp add m i
187end
188syn_rew m
189end
190
191fn pu_hex v ulong to uchar
192if lt v 10
193ret uchar add 48 v
194end
195ret uchar add 87 v
196end
197
198note pu_oq: write pool string (o,n) as a JSON string; control bytes are escaped
199fn pu_oq o ulong n ulong to void
200pu_ob 34
201for i ulong n
202c = get gsp add o i
203if or eq c 34 eq c 92
204pu_ob 92
205pu_ob c
206else
207if lt c 32
208pu_ob 92
209if eq c 10
210pu_ob 110
211else
212if eq c 9
213pu_ob 116
214else
215if eq c 13
216pu_ob 114
217else
218pu_ob 117
219pu_ob 48
220pu_ob 48
221pu_ob pu_hex ulong shr c 4
222pu_ob pu_hex ulong and c 15
223end
224end
225end
226else
227pu_ob c
228end
229end
230end
231pu_ob 34
232end
233
234fn pu_cf c ulong f ulong to ulong
235ret get gco add mul c 16 f
236end
237
238fn pu_cl c ulong f ulong to ulong
239ret get gcl add mul c 16 f
240end
241
242fn pu_oqf c ulong f ulong to void
243if ge c get gcn 0
244pu_ob 34
245pu_ob 34
246ret
247end
248pu_oq pu_cf c f pu_cl c f
249end
250
251note pu_fnd: one finding line with the fixed 12 keys; gfp 0 pr, 1/2 path, 3/4 detail
252note sev 0 info, 1 warn, 2 error; c and oc are claim rows (oc 4294967295 = none)
253fn pu_fnd kind view uchar * sev ulong c ulong oc ulong to void
254if and gt sev 0 eq get gcnt 8 0
255put gcnt 8 1
256put gcnt 9 get gfp 3
257put gcnt 10 get gfp 4
258end
259pu_ot tqk
260pu_ot kind
261pu_ot tqsev
262if eq sev 0
263pu_ot tsevi
264put gcnt 1 add get gcnt 1 1
265else
266if eq sev 1
267pu_ot tsevw
268else
269pu_ot tseve
270end
271put gcnt 0 add get gcnt 0 1
272end
273pu_ot tqrepo
274pu_oqf c 9
275pu_ot tqtarg
276pu_oqf c 4
277pu_ot tqid
278pu_oqf c 0
279pu_ot tqagent
280pu_oqf c 1
281pu_ot tqsess
282pu_oqf c 2
283pu_ot tqpr
284pu_od get gfp 0
285pu_ot tqpath
286pu_oq get gfp 1 get gfp 2
287pu_ot tqoid
288pu_oqf oc 0
289pu_ot tqoag
290pu_oqf oc 1
291pu_ot tqdet
292pu_oq get gfp 3 get gfp 4
293pu_ot tqend
294put gfp 0 0
295put gfp 1 0
296put gfp 2 0
297put gfp 3 0
298put gfp 4 0
299end
300
301note pu_det: mark the detail text that starts at pool offset m
302fn pu_det m ulong to void
303put gfp 3 m
304put gfp 4 syn_len m
305end
306
307fn pu_opt i ulong to bool
308ret ne get gopl i 0
309end
310
311note pu_popt: append option i (a pool string) to the pool
312fn pu_popt i ulong to void
313syn_ps get gop i get gopl i
314end
315
316fn pu_pathi i ulong t view uchar * to ulong
317m = syn_mark
318pu_popt i
319syn_pt t
320ret m
321end
322
323fn pu_cargv to void
324syn_ainit
325syn_ap get gop 4 get gopl 4
326syn_at thome
327syn_ap get gop 0 get gopl 0
328if eq get gfl 2 1
329syn_at tnow
330syn_ap get gop 6 get gopl 6
331end
332end
333
334fn pu_errout pre view uchar * to void
335w = write 2 pre 0 len pre
336c = get gxs 0
337m = syn_mark
338syn_pd ulong c
339w = write 2 gsp m syn_len m
340syn_rew m
341w = write 2 tsp 0 1
342w = write 2 gerrb 0 get gerrn 0
343w = write 2 tnl 0 1
344end
345
346note pu_key: field number of member key token at src off; 20 for active, 99 otherwise
347fn pu_key src view uchar * off ulong to ulong
348if js_streq src off tkid
349ret 0
350end
351if js_streq src off tkagent
352ret 1
353end
354if js_streq src off tksess
355ret 2
356end
357if js_streq src off tkkind
358ret 3
359end
360if js_streq src off tktarg
361ret 4
362end
363if js_streq src off tkmode
364ret 5
365end
366if js_streq src off tkstate
367ret 6
368end
369if js_streq src off tkint
370ret 7
371end
372if js_streq src off tkexp
373ret 8
374end
375if js_streq src off tksince
376ret 11
377end
378if js_streq src off tkact
379ret 20
380end
381ret 99
382end
383
384note pu_soff: source offset of token v when it is a string, else jsnone (string offsets are below 983040)
385fn pu_soff tape view uint * v ulong to ulong
386if ne js_type tape v jsstr
387ret jsnone
388end
389ret js_off tape v
390end
391
392note pu_sval: decode the string at source offset off (pu_soff) into the pool; offset returned, gxs 2 =
393note length (0 if off is jsnone). Takes the offset, not the token, to stay within six parameter slots.
394fn pu_sval src view uchar * off ulong tmp edit uchar * to ulong
395m = syn_mark
396put gxs 2 0
397if eq off jsnone
398ret m
399end
400n = js_sget src off tmp
401if lt n 0
402ret m
403end
404syn_pa tmp 0 ulong n
405put gxs 2 n
406ret m
407end
408
409note pu_memb: value token of member key in object token get gmo 0, or jsnone. The object token comes
410note in gmo because src, tape and key (two slots each) already fill the six parameter slots.
411fn pu_memb src view uchar * tape view uint * key view uchar * to ulong
412o = get gmo 0
413if ne js_type tape o jsobj
414ret jsnone
415end
416k = js_first tape o
417while ne k jsnone bound 999999
418if js_streq src js_off tape k key
419ret add k 1
420end
421k = js_mnext tape k
422end
423ret jsnone
424end
425
426note pu_derive: kind code, repo (field 9) and rest (field 10) from the target string
427fn pu_derive c ulong to void
428o = pu_cf c 4
429n = pu_cl c 4
430b = mul c 16
431k = uchar 0
432p = ulong 0
433sep = uchar 0
434if syn_pre o n tprepo
435k = 1
436p = len tprepo
437end
438if syn_pre o n tpbr
439k = 2
440p = len tpbr
441sep = 35
442end
443if syn_pre o n tppath
444k = 3
445p = len tppath
446sep = 58
447end
448if syn_pre o n tppr
449k = 4
450p = len tppr
451sep = 35
452end
453if syn_pre o n tpext
454k = 5
455end
456put gkd c k
457if or eq k 0 eq k 5
458ret
459end
460e = n
461if ne sep 0
462e = syn_find o n p sep
463end
464put gco add b 9 add o p
465put gcl add b 9 sub e p
466if lt e n
467put gco add b 10 add add o e 1
468put gcl add b 10 sub sub n e 1
469end
470end
471
472text tmany "synapse-pulse: over 1024 claims"
473text texpbad "synapse-pulse: claim expires is not YYYY-MM-DDTHH:MM:SSZ"
474note pu_setcf: claim row c field f is pool string o, length as pu_sval left it in gxs 2
475fn pu_setcf c ulong f ulong o ulong to void
476x = add mul c 16 f
477put gco x o
478put gcl x ulong get gxs 2
479end
480
481fn pu_ldrow src view uchar * tape edit uint * tmp edit uchar * to long
482if lt js_parse src tape len src 0
483ret neg long 65
484end
485if ne js_type tape 0 jsobj
486ret neg long 65
487end
488c = get gcn 0
489if ge c 1024
490syn_die tmany 70
491end
492for f ulong 16
493put gco add mul c 16 f 0
494put gcl add mul c 16 f 0
495end
496put gca c 0
497k = js_first tape 0
498while ne k jsnone bound 999999
499f = pu_key src js_off tape k
500if lt f 12
501pu_setcf c f pu_sval src pu_soff tape add k 1 tmp
502end
503if eq f 20
504if eq js_type tape add k 1 jstrue
505put gca c 1
506end
507end
508k = js_mnext tape k
509end
510if eq pu_cl c 0 0
511ret neg long 65
512end
513if ne pu_cl c 8 0
514t = syn_tsp pu_cf c 8 pu_cl c 8
515if eq get gxs 2 0
516w = write 2 texpbad 0 len texpbad
517w = write 2 tnl 0 1
518ret neg long 65
519end
520end
521put gcn 0 add c 1
522pu_derive c
523ret 0
524end
525
526note pu_eol: offset i ends a line of raw[0..n): i is n or raw[i] is a newline
527fn pu_eol raw view uchar * i ulong n ulong to bool
528if eq i n
529ret true
530end
531ret eq get raw syn_min i sub len raw 1 10
532end
533
534note pu_lines: kind 0 list rows, 1 conflicts, 2 expire events; returns rows or negative
535fn pu_lines raw view uchar * n ulong kind ulong to long
536tape = new uint 65536 0
537tmp = new uchar 65536 0
538rows = js_init tape 65536 64
539rows = 0
540s = ulong 0
541for i ulong add n 1
542if pu_eol raw i n
543if gt i s
544q = long 0
545if eq kind 0
546q = pu_ldrow part raw s sub i s tape tmp
547end
548if eq kind 1
549q = pu_cfrow part raw s sub i s tape tmp
550end
551if eq kind 2
552q = pu_exrow part raw s sub i s tape tmp
553end
554if lt q 0
555w = write 2 tclbad 0 len tclbad
556w = write 2 tnl 0 1
557ret q
558end
559rows = add rows 1
560end
561s = add i 1
562end
563end
564ret rows
565end
566
567note pu_byid: claim row with id (o,n), or 4294967295
568fn pu_byid o ulong n ulong to ulong
569for c ulong get gcn 0
570if syn_peq pu_cf c 0 pu_cl c 0 o n
571ret c
572end
573end
574ret 4294967295
575end
576
577text tdconf "ledger conflict "
578text tvs " vs "
579fn pu_cfrow src view uchar * tape edit uint * tmp edit uchar * to long
580if lt js_parse src tape len src 0
581ret neg long 65
582end
583put gmo 0 0
584a = pu_memb src tape tka
585b = pu_memb src tape tkb
586if or eq a jsnone eq b jsnone
587ret neg long 65
588end
589put gmo 0 a
590a = pu_memb src tape tkid
591put gmo 0 b
592b = pu_memb src tape tkid
593if or eq a jsnone eq b jsnone
594ret neg long 65
595end
596m = syn_mark
597o = pu_sval src pu_soff tape a tmp
598a = pu_byid o ulong get gxs 2
599o = pu_sval src pu_soff tape b tmp
600b = pu_byid o ulong get gxs 2
601syn_rew m
602put gmo 0 0
603rs = pu_memb src tape tkreas
604m = syn_mark
605syn_pt tdconf
606if ne rs jsnone
607o = pu_sval src pu_soff tape rs tmp
608end
609syn_pb 58
610syn_pb 32
611if lt a get gcn 0
612syn_ps pu_cf a 4 pu_cl a 4
613end
614syn_pt tvs
615if lt b get gcn 0
616syn_ps pu_cf b 4 pu_cl b 4
617end
618pu_det m
619pu_fnd fconf 2 a b
620ret 0
621end
622
623text tdexp "lease expired at "
624text tdexp2 "; pulse appended the expire event"
625fn pu_exrow src view uchar * tape edit uint * tmp edit uchar * to long
626r = js_parse src tape len src
627if lt r 0
628ret neg long 65
629end
630put gmo 0 0
631ix = pu_memb src tape tkid
632if eq ix jsnone
633ret neg long 65
634end
635m = syn_mark
636o = pu_sval src pu_soff tape ix tmp
637c = pu_byid o ulong get gxs 2
638syn_rew m
639if ge c get gcn 0
640ret 0
641end
642m = syn_mark
643syn_pt tdexp
644syn_ps pu_cf c 8 pu_cl c 8
645syn_pt tdexp2
646pu_det m
647pu_fnd fexp 1 c 4294967295
648ret 0
649end
650
651text tclbig "synapse-pulse: synapse-claims list output over 3 MiB"
652fn pu_ldclaims to long
653raw = new uchar 3145728 0
654pu_cargv
655syn_at tlist
656syn_at tall
657n = syn_run raw 120000000000
658if ne get gxs 0 0
659pu_errout tclfail
660ret neg long 70
661end
662if gt get gxs 1 long len raw
663syn_die tclbig 70
664end
665r = pu_lines raw n 0
666ret r
667end
668
669fn pu_ldconf to long
670raw = new uchar 1048576 0
671pu_cargv
672syn_at tconf
673n = syn_run raw 120000000000
674if gt get gxs 0 1
675pu_errout tclfail
676ret neg long 70
677end
678r = pu_lines raw n 1
679ret r
680end
681
682fn pu_expire to long
683need = ulong 0
684for c ulong get gcn 0
685if and eq get gca c 0 ne pu_cl c 8 0
686t = syn_tsp pu_cf c 8 pu_cl c 8
687if and eq get gxs 2 1 le t get gnow 0
688need = 1
689end
690end
691end
692if eq need 0
693ret 0
694end
695raw = new uchar 1048576 0
696pu_cargv
697syn_at texpire
698syn_at tagent
699syn_at tpulse
700n = syn_run raw 120000000000
701w = write 2 texpok 0 len texpok
702m = syn_mark
703syn_pd ulong get gxs 0
704w = write 2 gsp m syn_len m
705syn_rew m
706if ne get gxs 0 0
707w = write 2 tnl 0 1
708pu_errout tclfail
709ret neg long 70
710end
711r = pu_lines raw n 2
712w = write 2 tevents 0 len tevents
713m = syn_mark
714syn_pd ulong r
715w = write 2 gsp m syn_len m
716syn_rew m
717w = write 2 tnl 0 1
718ret r
719end
720
721note sessions: claim session is an absolute .jsonl path, a top-level session uuid or a dotted omp agent id
722fn pu_mtime po ulong pn ulong to long
723st = new uchar 128 0
724r = stat gsp po pn st 0 128
725if lt r 0
726ret neg long 1
727end
728v = ulong 0
729for i ulong 8
730v = or v shl ulong get st add 88 i mul i 8
731end
732ret long v
733end
734
735fn pu_isuuid o ulong n ulong to bool
736if ne n 36
737ret false
738end
739for i ulong 36
740c = get gsp add o i
741if or or eq i 8 eq i 13 or eq i 18 eq i 23
742if ne c 45
743ret false
744end
745else
746if not or and ge c 48 le c 57 and ge c 97 le c 102
747ret false
748end
749end
750end
751ret true
752end
753
754note pu_agpath: append the subagent file path for agent id (so,sn) under the session dir prefix already in the pool
755fn pu_agpath so ulong sn ulong to void
756for i ulong sn
757if eq get gsp add so i 46
758syn_ps so i
759syn_pb 47
760end
761end
762syn_ps so sn
763syn_pt tjsonl
764end
765
766note pu_u16: little-endian 16-bit value at db[p]
767fn pu_u16 db view uchar * p ulong to ulong
768ret or ulong get db p shl ulong get db add p 1 8
769end
770
771note pu_dend: first offset from e that holds a zero byte or reaches lim (end of a dirent name)
772fn pu_dend db view uchar * e ulong lim ulong to ulong
773x = e
774while and lt x lim ne get db x 0 bound 4096
775x = add x 1
776end
777ret x
778end
779
780note pu_sfx: db[a..a+l) equals pool bytes gsp[q..q+l)
781fn pu_sfx db view uchar * a ulong q ulong l ulong to bool
782for j ulong l
783if ne get db add a j get gsp add q j
784ret false
785end
786end
787ret true
788end
789
790note session lookup state in gss: 0-1 session string (so,sn) of the claim, 2 mode (1 uuid, 2 agent id)
791note pu_scone: mtime of slug dir (po,pn) entry db[nm..e) when it belongs to the session, else -1
792fn pu_scone db view uchar * nm ulong e ulong po ulong pn ulong to long
793t = neg long 1
794m = syn_mark
795syn_ps po pn
796syn_pb 47
797syn_pa db nm sub e nm
798if eq get gss 2 1
799q = syn_mark
800syn_pb 95
801syn_ps get gss 0 get gss 1
802syn_pt tjsonl
803l = syn_len q
804syn_rew q
805ok = false
806if ge sub e nm l
807ok = pu_sfx db sub e l q l
808end
809if not ok
810syn_rew m
811end
812end
813if eq get gss 2 2
814syn_pb 47
815pu_agpath get gss 0 get gss 1
816end
817if gt syn_len m 0
818t = pu_mtime m syn_len m
819end
820syn_rew m
821ret t
822end
823
824note pu_scan2: entries of one slug dir (po,pn); best mtime for the session in gss
825fn pu_scan2 po ulong pn ulong to long
826best = neg long 1
827fd = fopen gsp po pn 524288 0
828if lt fd 0
829ret best
830end
831db = new uchar 32768 0
832while true bound 100000
833k = getdnts int fd db 0 len db
834if le k 0
835break
836end
837p = ulong 0
838while lt p ulong k bound 100000
839rl = pu_u16 db add p 16
840nm = add p 19
841e = pu_dend db nm add p rl
842if gt sub e nm 2
843t = pu_scone db nm e po pn
844if gt t best
845best = t
846end
847end
848if eq rl 0
849break
850end
851p = add p rl
852end
853end
854c = fclose int fd
855ret best
856end
857
858note pu_slugs: best mtime for the session in gss over every slug dir under --sessions
859fn pu_slugs to long
860best = neg long 1
861fd = fopen gsp get gop 3 get gopl 3 524288 0
862if lt fd 0
863ret best
864end
865db = new uchar 32768 0
866while true bound 100000
867k = getdnts int fd db 0 len db
868if le k 0
869break
870end
871p = ulong 0
872while lt p ulong k bound 100000
873rl = pu_u16 db add p 16
874nm = add p 19
875e = pu_dend db nm add p rl
876if and gt sub e nm 0 ne get db nm 46
877m = syn_mark
878pu_popt 3
879syn_pb 47
880syn_pa db nm sub e nm
881t = pu_scan2 m syn_len m
882if gt t best
883best = t
884end
885syn_rew m
886end
887if eq rl 0
888break
889end
890p = add p rl
891end
892end
893r = fclose int fd
894ret best
895end
896
897fn pu_sessmt c ulong to long
898so = pu_cf c 2
899sn = pu_cl c 2
900if eq sn 0
901ret neg long 1
902end
903if eq get gsp so 47
904ret pu_mtime so sn
905end
906put gss 0 so
907put gss 1 sn
908put gss 2 2
909if pu_isuuid so sn
910put gss 2 1
911end
912ret pu_slugs
913end
914
915text tdunk "session not found under --sessions (accepted: omp agent id, session uuid, absolute .jsonl path)"
916text tddead "active lease but session file last written "
917text tddead2 " (over 2h ago)"
918fn pu_sessions to void
919for c ulong get gcn 0
920if eq get gca c 1
921t = pu_sessmt c
922if lt t 0
923m = syn_mark
924syn_pt tdunk
925pu_det m
926pu_fnd funk 0 c 4294967295
927else
928if gt get gnow 0 add ulong t 7200
929m = syn_mark
930syn_pt tddead
931syn_tsw ulong t
932syn_pt tddead2
933pu_det m
934pu_fnd fdead 1 c 4294967295
935end
936end
937end
938end
939end
940
941note intent tokens: lower-case alphanumeric runs of 4+ bytes, FNV-1a 32, stop words dropped
942fn pu_lc c uchar to uchar
943if and ge c 65 le c 90
944ret uchar add c 32
945end
946ret c
947end
948
949fn pu_isan c uchar to bool
950ret or or and ge c 48 le c 57 and ge c 97 le c 122 and ge c 65 le c 90
951end
952
953fn pu_isstop h uint to bool
954for i ulong get gstopn 0
955if eq get gstop i h
956ret true
957end
958end
959ret false
960end
961
962note pu_tkdup: hash h is a stop word or already among the first cnt tokens of claim row c
963fn pu_tkdup c ulong cnt ulong h uint to bool
964if pu_isstop h
965ret true
966end
967for j ulong cnt
968if eq get gtk add mul c 24 j h
969ret true
970end
971end
972ret false
973end
974
975note pu_toks: hash the tokens of (o,n); mode 0 fills the stop list, mode 1 fills claim row c
976fn pu_toks o ulong n ulong mode ulong c ulong to void
977h = uint 2166136261
978k = ulong 0
979cnt = ulong 0
980for i ulong add n 1
981ch = uchar 32
982if lt i n
983ch = get gsp add o i
984end
985if pu_isan ch
986h = mul xor h uint pu_lc ch 16777619
987k = add k 1
988else
989if ge k 4
990if eq mode 0
991if lt get gstopn 0 32
992put gstop get gstopn 0 h
993put gstopn 0 add get gstopn 0 1
994end
995else
996if lt cnt 24
997if not pu_tkdup c cnt h
998put gtk add mul c 24 cnt h
999cnt = add cnt 1
1000end
1001end
1002end
1003end
1004h = 2166136261
1005k = 0
1006end
1007end
1008if eq mode 1
1009put gtn c cnt
1010end
1011end
1012
1013text tddup "intents share "
1014text tddup2 " of "
1015text tddup3 " tokens: "
1016text tddup4 " || "
1017note pu_tkcnt: tokens of claim row b equal to x
1018fn pu_tkcnt b ulong x uint to ulong
1019k = ulong 0
1020for j ulong get gtn b
1021if eq get gtk add mul b 24 j x
1022k = add k 1
1023end
1024end
1025ret k
1026end
1027
1028note pu_shared: token pairs equal between claim rows a and b
1029fn pu_shared a ulong b ulong to ulong
1030sh = ulong 0
1031for i ulong get gtn a
1032x = get gtk add mul a 24 i
1033sh = add sh pu_tkcnt b x
1034end
1035ret sh
1036end
1037
1038fn pu_dup to void
1039for c ulong get gcn 0
1040put gtn c 0
1041if eq get gca c 1
1042pu_toks pu_cf c 7 pu_cl c 7 1 c
1043end
1044end
1045n = get gcn 0
1046for a ulong n
1047for b ulong n
1048if and and lt a b eq get gca a 1 eq get gca b 1
1049if not syn_peq pu_cf a 1 pu_cl a 1 pu_cf b 1 pu_cl b 1
1050sh = pu_shared a b
1051mn = syn_min get gtn a get gtn b
1052if and ge sh 3 ge mul sh 2 mn
1053m = syn_mark
1054syn_pt tddup
1055syn_pd sh
1056syn_pt tddup2
1057syn_pd mn
1058syn_pt tddup3
1059syn_ps pu_cf a 7 pu_cl a 7
1060syn_pt tddup4
1061syn_ps pu_cf b 7 pu_cl b 7
1062pu_det m
1063pu_fnd fdup 1 a b
1064end
1065end
1066end
1067end
1068end
1069end
1070
1071note repos with active claims; grp marks repos holding an active path claim
1072fn pu_repos to void
1073put grn 0 0
1074for c ulong get gcn 0
1075rl = pu_cl c 9
1076if and eq get gca c 1 ne rl 0
1077ro = pu_cf c 9
1078f = get grn 0
1079for r ulong get grn 0
1080if syn_peq get grpo r get grpl r ro rl
1081f = r
1082end
1083end
1084if and eq f get grn 0 lt f 128
1085put grpo f ro
1086put grpl f rl
1087put grp f 0
1088put grn 0 add f 1
1089end
1090if and lt f get grn 0 eq get gkd c 3
1091put grp f 1
1092end
1093end
1094end
1095end
1096
1097note pu_segst: pool offset t starts a path segment of the string that begins at s
1098fn pu_segst s ulong t ulong to bool
1099if eq t s
1100ret true
1101end
1102ret eq get gsp sub t 1 47
1103end
1104
1105note glob: * matches inside one path segment, ** any depth (including none)
1106fn pu_glob p ulong pe ulong s ulong se ulong to bool
1107if eq p pe
1108ret eq s se
1109end
1110c = get gsp p
1111if eq c 42
1112if and lt add p 1 pe eq get gsp add p 1 42
1113q = add p 2
1114if and lt q pe eq get gsp q 47
1115for i ulong add sub se s 1
1116if pu_segst s add s i
1117if pu_glob add q 1 pe add s i se
1118ret true
1119end
1120end
1121end
1122ret false
1123end
1124for i ulong add sub se s 1
1125if pu_glob q pe add s i se
1126ret true
1127end
1128end
1129ret false
1130end
1131for i ulong add sub se s 1
1132if pu_glob add p 1 pe add s i se
1133ret true
1134end
1135if lt add s i se
1136if eq get gsp add s i 47
1137ret false
1138end
1139end
1140end
1141ret false
1142end
1143if eq s se
1144ret false
1145end
1146if ne c get gsp s
1147ret false
1148end
1149ret pu_glob add p 1 pe add s 1 se
1150end
1151
1152note GitHub: cache key is the request path with / replaced by ,
1153fn pu_key2 po ulong pn ulong to ulong
1154m = syn_mark
1155for i ulong pn
1156c = get gsp add po i
1157if eq c 47
1158c = 44
1159end
1160syn_pb c
1161end
1162ret m
1163end
1164
1165fn pu_lognum t view uchar * v ulong to void
1166syn_pt t
1167syn_pd v
1168end
1169
1170fn pu_reqlog po ulong pn ulong eo ulong en ulong st ulong bl ulong to void
1171m = syn_mark
1172syn_tsw div ulong realns 1000000000
1173syn_pb 32
1174syn_ps po pn
1175syn_pt tinmeq
1176if eq en 0
1177syn_pt tdash
1178else
1179syn_ps eo en
1180end
1181pu_lognum tstateq st
1182pu_lognum tbyteq bl
1183syn_pt tsrceq
1184if eq st 304
1185syn_pt tscache
1186else
1187if eq get gfl 1 1
1188syn_pt tsoff
1189else
1190syn_pt tsgh
1191end
1192end
1193syn_pb 10
1194l = syn_len m
1195p = pu_pathi 0 tslreq
1196fd = fopen gsp p syn_len p 525377 420
1197if ge fd 0
1198w = write int fd gsp m l
1199c = fclose int fd
1200end
1201syn_rew m
1202end
1203
1204text tetagh "etag:"
1205note pu_lower: ASCII lower-case of byte
1206fn pu_hdr a view uchar * s ulong e ulong to bool
1207if lt sub e s 5
1208ret false
1209end
1210for i ulong 5
1211if ne pu_lc get a add s i get tetagh i
1212ret false
1213end
1214end
1215ret true
1216end
1217
1218note pu_gh request state in ghs: 0 pool base, 1-2 cache key, 3-4 etag file path, 5-6 stored etag,
1219note 7-8 etag of the response
1220note pu_ghetag: cache key and etag file path of (po,pn) into the pool; the stored etag after them
1221fn pu_ghetag po ulong pn ulong to void
1222ko = pu_key2 po pn
1223put ghs 1 ko
1224put ghs 2 syn_len ko
1225ep = pu_pathi 0 tsletag
1226syn_pb 47
1227syn_ps ko get ghs 2
1228syn_pt tetag
1229put ghs 3 ep
1230put ghs 4 syn_len ep
1231eb = new uchar 1024 0
1232el = syn_rfile ep get ghs 4 eb
1233put ghs 5 syn_mark
1234en = ulong 0
1235if gt el 0
1236for i ulong ulong el
1237c = get eb i
1238if and ne c 10 ne c 13
1239syn_pb c
1240en = add en 1
1241end
1242end
1243end
1244put ghs 6 en
1245end
1246
1247note pu_ghget: raw response of (po,pn) into obf (fixture or gh api -i); its length, or -2 after cleanup
1248fn pu_ghget obf edit uchar * po ulong pn ulong to long
1249if eq get gfl 1 1
1250fp = pu_pathi 5 tsl
1251syn_ps get ghs 1 get ghs 2
1252syn_pt thttp
1253r = syn_rfile fp syn_len fp obf
1254if lt r 0
1255w = write 2 tnofix 0 len tnofix
1256w = write 2 gsp fp syn_len fp
1257w = write 2 tnl 0 1
1258syn_rew get ghs 0
1259put gcnt 3 add get gcnt 3 1
1260ret neg long 2
1261end
1262ret r
1263end
1264syn_ainit
1265syn_at tenv
1266syn_ap get gop 9 get gopl 9
1267syn_ap get gop 10 get gopl 10
1268syn_ap get gop 2 get gopl 2
1269syn_at tapi
1270syn_at tdi
1271if gt get ghs 6 0
1272syn_at tdh
1273h = syn_mark
1274syn_pt tinm
1275syn_ps get ghs 5 get ghs 6
1276syn_ap h syn_len h
1277end
1278syn_ap po pn
1279n = syn_run obf 60000000000
1280if gt get gxs 0 1
1281w = write 2 tghfail 0 len tghfail
1282w = write 2 gsp po pn
1283pu_errout tsp
1284syn_rew get ghs 0
1285put gcnt 3 add get gcnt 3 1
1286ret neg long 2
1287end
1288ret long n
1289end
1290
1291note pu_ghst: HTTP status from the first line of the response obf[0..n)
1292fn pu_ghst obf view uchar * n ulong to ulong
1293st = ulong 0
1294if and gt n 12 eq get obf 0 72
1295sp = ulong 0
1296while and lt sp n ne get obf sp 32 bound 64
1297sp = add sp 1
1298end
1299for i ulong 3
1300c = ulong get obf syn_min add add sp 1 i sub n 1
1301st = add mul st 10 sub c 48
1302end
1303end
1304ret st
1305end
1306
1307note pu_skipsp: first offset from v below e that is not a space
1308fn pu_skipsp a view uchar * v ulong e ulong to ulong
1309x = v
1310while and lt x e eq get a x 32 bound 4096
1311x = add x 1
1312end
1313ret x
1314end
1315
1316note pu_ghhdr: body offset of the response obf[0..n); appends its etag to the pool (ghs 7-8)
1317fn pu_ghhdr obf view uchar * n ulong to ulong
1318ls = ulong 0
1319bo = n
1320put ghs 7 syn_mark
1321nen = ulong 0
1322ln = ulong 0
1323for i ulong n
1324if eq get obf i 10
1325e = i
1326if gt e ls
1327if eq get obf sub e 1 13
1328e = sub e 1
1329end
1330end
1331if and gt ln 0 eq e ls
1332bo = add i 1
1333break
1334end
1335if and gt ln 0 pu_hdr obf ls e
1336v = pu_skipsp obf add ls 5 e
1337syn_pa obf v sub e v
1338nen = sub e v
1339end
1340ln = add ln 1
1341ls = add i 1
1342end
1343end
1344put ghs 8 nen
1345ret bo
1346end
1347
1348note pu_gh200: move the body (bo,bl) to obf[0..), cache body and etag, log; returns bl
1349fn pu_gh200 obf edit uchar * po ulong pn ulong bo ulong bl ulong to long
1350for i ulong bl
1351put obf i get obf add bo i
1352end
1353bp = pu_pathi 0 tsletag
1354syn_pb 47
1355syn_ps get ghs 1 get ghs 2
1356syn_pt tbody
1357fd = syn_wbeg bp syn_len bp
1358if ge fd 0
1359w = write int fd obf 0 bl
1360r = syn_wend fd bp syn_len bp
1361end
1362if gt get ghs 8 0
1363ep2 = syn_mark
1364syn_ps get ghs 3 get ghs 4
1365fd = syn_wbeg ep2 get ghs 4
1366if ge fd 0
1367w = write int fd gsp get ghs 7 get ghs 8
1368r = syn_wend fd ep2 get ghs 4
1369end
1370end
1371pu_reqlog po pn get ghs 5 get ghs 6 200 bl
1372syn_rew get ghs 0
1373put gcnt 4 add get gcnt 4 1
1374ret long bl
1375end
1376
1377note pu_gh304: cached body into obf[0..); its length, or -2 (etag dropped) when the cache is gone
1378fn pu_gh304 obf edit uchar * po ulong pn ulong to long
1379bp = pu_pathi 0 tsletag
1380syn_pb 47
1381syn_ps get ghs 1 get ghs 2
1382syn_pt tbody
1383r = syn_rfile bp syn_len bp obf
1384if lt r 0
1385q = unlink gsp get ghs 3 get ghs 4
1386w = write 2 tghfail 0 len tghfail
1387w = write 2 gsp po pn
1388w = write 2 tnl 0 1
1389syn_rew get ghs 0
1390put gcnt 3 add get gcnt 3 1
1391ret neg long 2
1392end
1393pu_reqlog po pn get ghs 5 get ghs 6 304 ulong r
1394syn_rew get ghs 0
1395put gcnt 4 add get gcnt 4 1
1396ret r
1397end
1398
1399note pu_gh: GET path (po,pn); body moved to out[0..); returns body length, -1 cap, -2 failure, -3 too large
1400fn pu_gh obf edit uchar * po ulong pn ulong to long
1401if ge get gcnt 2 40
1402w = write 2 tcap 0 len tcap
1403w = write 2 gsp po pn
1404w = write 2 tnl 0 1
1405put gcnt 5 add get gcnt 5 1
1406ret neg long 1
1407end
1408put gcnt 2 add get gcnt 2 1
1409put ghs 0 syn_mark
1410pu_ghetag po pn
1411r = pu_ghget obf po pn
1412if lt r 0
1413ret r
1414end
1415n = ulong r
1416if gt get gxs 1 long len obf
1417w = write 2 tbig 0 len tbig
1418w = write 2 gsp po pn
1419w = write 2 tnl 0 1
1420syn_rew get ghs 0
1421ret neg long 3
1422end
1423st = pu_ghst obf n
1424bo = pu_ghhdr obf n
1425bl = sub n syn_min bo n
1426if eq st 200
1427ret pu_gh200 obf po pn bo bl
1428end
1429if eq st 304
1430ret pu_gh304 obf po pn
1431end
1432pu_reqlog po pn get ghs 5 get ghs 6 st bl
1433w = write 2 tghfail 0 len tghfail
1434w = write 2 gsp po pn
1435w = write 2 tnl 0 1
1436syn_rew get ghs 0
1437put gcnt 3 add get gcnt 3 1
1438ret neg long 2
1439end
1440
1441text tbadpr "synapse-pulse: PR list did not parse"
1442note pu_pulls: tape lives in this frame and the response buffer in pu_pullt's, so neither frame passes
1443note omc's 4 MiB per-function stack cap (error 23); the chain stays inside the 8 MiB program stack
1444fn pu_pulls r ulong to void
1445tape = new uint 786432 0
1446pu_pullt r tape
1447end
1448
1449note pu_prel: PR object in gmo into row gprc (number, state, merged, head ref); false without a number
1450fn pu_prel obf view uchar * tape view uint * tmp edit uchar * to bool
1451v = pu_memb obf tape tknum
1452if eq v jsnone
1453ret false
1454end
1455i = get gprc 0
1456put gprn i js_tou obf js_off tape v
1457put gprs i 2
1458v = pu_memb obf tape tkstate
1459if ne v jsnone
1460if js_streq obf js_off tape v topen
1461put gprs i 1
1462end
1463end
1464put gprm i 0
1465v = pu_memb obf tape tkmerg
1466if ne v jsnone
1467if eq js_type tape v jsstr
1468put gprm i 1
1469end
1470end
1471put gprho i 0
1472put gprhl i 0
1473v = pu_memb obf tape tkhead
1474if ne v jsnone
1475put gmo 0 v
1476v = pu_memb obf tape tkref
1477if ne v jsnone
1478o = pu_sval obf pu_soff tape v tmp
1479put gprho i o
1480put gprhl i ulong get gxs 2
1481end
1482end
1483ret true
1484end
1485
1486fn pu_pullt r ulong tape edit uint * to void
1487obf = new uchar 1114112 0
1488tmp = new uchar 8192 0
1489m = syn_mark
1490syn_pt trepos
1491syn_ps get grpo r get grpl r
1492syn_pt tpulls
1493n = pu_gh obf m syn_len m
1494syn_rew m
1495if lt n 0
1496ret
1497end
1498if gt n 983040
1499w = write 2 tbig 0 len tbig
1500w = write 2 tnl 0 1
1501ret
1502end
1503q = js_init tape 983040 64
1504q = js_parse obf tape ulong n
1505if or lt q 0 ne js_type tape 0 jsarr
1506w = write 2 tbadpr 0 len tbadpr
1507w = write 2 tnl 0 1
1508ret
1509end
1510e = js_first tape 0
1511while ne e jsnone bound 100000
1512put gmo 0 e
1513i = get gprc 0
1514if lt i 8192
1515if pu_prel obf tape tmp
1516put gprr i r
1517put gprc 0 add i 1
1518end
1519end
1520e = js_enext tape e
1521end
1522end
1523
1524note pu_prclaimed: an active pr: or branch: claim covers PR row i
1525fn pu_prclaim i ulong to bool
1526r = get gprr i
1527for c ulong get gcn 0
1528if and eq get gca c 1 syn_peq pu_cf c 9 pu_cl c 9 get grpo r get grpl r
1529k = get gkd c
1530if eq k 4
1531v = syn_pdec pu_cf c 10 pu_cl c 10
1532if and eq get gxs 2 1 eq v get gprn i
1533ret true
1534end
1535end
1536if and eq k 2 ne get gprhl i 0
1537if syn_peq pu_cf c 10 pu_cl c 10 get gprho i get gprhl i
1538ret true
1539end
1540end
1541end
1542end
1543ret false
1544end
1545
1546text tdunc1 "open PR #"
1547text tdunc2 " (head "
1548text tdunc3 ") changes a path held by "
1549text tdunc4 " and no pr: or branch: claim covers it"
1550note pu_files: tape here, response buffer in pu_filet (same 4 MiB per-frame split as pu_pulls)
1551fn pu_files i ulong to void
1552tape = new uint 786432 0
1553pu_filet i tape
1554end
1555
1556note pu_fhit: claim c is an active path claim on repo row r, not yet reported (ghit), whose glob
1557note matches the changed file (fo,fl)
1558fn pu_fhit c ulong r ulong fo ulong fl ulong to bool
1559if ne get gca c 1
1560ret false
1561end
1562if ne get gkd c 3
1563ret false
1564end
1565if ne get ghit c 0
1566ret false
1567end
1568if not syn_peq pu_cf c 9 pu_cl c 9 get grpo r get grpl r
1569ret false
1570end
1571po = pu_cf c 10
1572pe = add po pu_cl c 10
1573ret pu_glob po pe fo add fo fl
1574end
1575
1576note pu_fmatch: changed file (fo,fl) of PR row i against active path claims not yet reported (ghit)
1577fn pu_fmatch i ulong fo ulong fl ulong to void
1578r = get gprr i
1579for c ulong get gcn 0
1580if pu_fhit c r fo fl
1581put ghit c 1
1582m = syn_mark
1583syn_pt tdunc1
1584syn_pd get gprn i
1585syn_pt tdunc2
1586syn_ps get gprho i get gprhl i
1587syn_pt tdunc3
1588syn_ps pu_cf c 1 pu_cl c 1
1589syn_pt tdunc4
1590pu_det m
1591put gfp 0 get gprn i
1592put gfp 1 fo
1593put gfp 2 fl
1594pu_fnd funcl 1 c 4294967295
1595end
1596end
1597end
1598
1599fn pu_filet i ulong tape edit uint * to void
1600obf = new uchar 1114112 0
1601tmp = new uchar 8192 0
1602for c ulong 1024
1603put ghit c 0
1604end
1605r = get gprr i
1606m = syn_mark
1607syn_pt trepos
1608syn_ps get grpo r get grpl r
1609syn_pt tpullsl
1610syn_pd get gprn i
1611syn_pt tfiles
1612n = pu_gh obf m syn_len m
1613syn_rew m
1614if or lt n 0 gt n 983040
1615ret
1616end
1617q = js_init tape 983040 64
1618q = js_parse obf tape ulong n
1619if or lt q 0 ne js_type tape 0 jsarr
1620ret
1621end
1622e = js_first tape 0
1623while ne e jsnone bound 100000
1624put gmo 0 e
1625fv = pu_memb obf tape tkfile
1626if ne fv jsnone
1627fo = pu_sval obf pu_soff tape fv tmp
1628pu_fmatch i fo ulong get gxs 2
1629end
1630e = js_enext tape e
1631end
1632end
1633
1634fn pu_prrow r ulong num ulong to ulong
1635for i ulong get gprc 0
1636if and eq get gprr i r eq get gprn i num
1637ret i
1638end
1639end
1640ret 4294967295
1641end
1642
1643fn pu_ridx o ulong n ulong to ulong
1644for r ulong get grn 0
1645if syn_peq get grpo r get grpl r o n
1646ret r
1647end
1648end
1649ret 4294967295
1650end
1651
1652text tdst1 "claim state "
1653text tdst2 " but GitHub PR is not merged (state "
1654text tdst3 "GitHub PR is closed ("
1655text tunm "not merged"
1656text tdst4 ") but the claim is still active"
1657text tdst5 "claim state "
1658text tdst6 " but no GitHub PR from this branch is merged"
1659note pu_stpr: pr: claim c on repo row r; mg when the claim state is merged or deployed
1660fn pu_stpr c ulong r ulong mg bool to void
1661v = syn_pdec pu_cf c 10 pu_cl c 10
1662i = pu_prrow r v
1663if ge i get gprc 0
1664ret
1665end
1666put gfp 0 v
1667if and mg eq get gprm i 0
1668m = syn_mark
1669syn_pt tdst1
1670syn_ps pu_cf c 6 pu_cl c 6
1671syn_pt tdst2
1672if eq get gprs i 1
1673syn_pt topen
1674else
1675syn_pt tclosed
1676end
1677syn_pb 41
1678pu_det m
1679pu_fnd fstcon 1 c 4294967295
1680else
1681if and eq get gca c 1 eq get gprs i 2
1682m = syn_mark
1683syn_pt tdst3
1684if eq get gprm i 1
1685syn_pt tmerged
1686else
1687syn_pt tunm
1688end
1689syn_pt tdst4
1690pu_det m
1691pu_fnd fstcon 1 c 4294967295
1692end
1693end
1694put gfp 0 0
1695end
1696
1697note pu_stbr: merged or deployed branch: claim c on repo row r with PRs from it but none merged
1698fn pu_stbr c ulong r ulong to void
1699seen = ulong 0
1700any = ulong 0
1701co = pu_cf c 10
1702cl = pu_cl c 10
1703for i ulong get gprc 0
1704if eq get gprr i r
1705if syn_peq get gprho i get gprhl i co cl
1706seen = add seen 1
1707any = or any ulong get gprm i
1708end
1709end
1710end
1711if and gt seen 0 eq any 0
1712m = syn_mark
1713syn_pt tdst5
1714syn_ps pu_cf c 6 pu_cl c 6
1715syn_pt tdst6
1716pu_det m
1717pu_fnd fstcon 1 c 4294967295
1718end
1719end
1720
1721fn pu_status to void
1722for c ulong get gcn 0
1723k = get gkd c
1724r = pu_ridx pu_cf c 9 pu_cl c 9
1725if lt r get grn 0
1726mg = or syn_seq pu_cf c 6 pu_cl c 6 tmerged syn_seq pu_cf c 6 pu_cl c 6 tdeploy
1727if eq k 4
1728pu_stpr c r mg
1729end
1730if and eq k 2 mg
1731pu_stbr c r
1732end
1733end
1734end
1735end
1736
1737fn pu_github to void
1738for r ulong get grn 0
1739pu_pulls r
1740end
1741for i ulong get gprc 0
1742if and eq get gprs i 1 eq get grp get gprr i 1
1743if not pu_prclaim i
1744pu_files i
1745end
1746end
1747end
1748pu_status
1749end
1750
1751note alert in exactly the aien-watch format; kind COORD-DRIFT
1752note pu_alch: byte allowed in an alert KIND (A-Z, 0-9, -)
1753fn pu_alch c uchar to bool
1754if and ge c 65 le c 90
1755ret true
1756end
1757if and ge c 48 le c 57
1758ret true
1759end
1760ret eq c 45
1761end
1762
1763fn pu_alkeep a view uchar * s ulong e ulong to bool
1764if pu_isdrift a s e
1765ret false
1766end
1767if ge s e
1768ret false
1769end
1770c = get a s
1771if or lt c 65 gt c 90
1772ret false
1773end
1774i = add s 1
1775while lt i e bound 4096
1776c = get a i
1777if eq c 58
1778ret and lt add i 1 e eq get a add i 1 32
1779end
1780if not pu_alch c
1781ret false
1782end
1783i = add i 1
1784end
1785ret false
1786end
1787
1788fn pu_isdrift a view uchar * s ulong e ulong to bool
1789if lt sub e s len tkalcol
1790ret false
1791end
1792for i ulong len tkalcol
1793if ne get a add s i get tkalcol i
1794ret false
1795end
1796end
1797ret true
1798end
1799
1800fn pu_alog m ulong to void
1801p = pu_pathi 1 tslalog
1802fd = fopen gsp p syn_len p 525377 420
1803syn_rew p
1804if ge fd 0
1805w = write int fd gsp m syn_len m
1806c = fclose int fd
1807end
1808end
1809
1810note pu_alsel: sel 0 appends the COORD-DRIFT lines (each cut to 400 bytes, joined by newline) and
1811note returns their count; sel 1 appends every other well-formed KIND line with its newline
1812fn pu_alsel buf view uchar * nn ulong sel ulong to ulong
1813ls = ulong 0
1814cnt = ulong 0
1815for i ulong add nn 1
1816if or eq i nn eq get buf syn_min i sub len buf 1 10
1817if gt i ls
1818if eq sel 0
1819if pu_isdrift buf ls i
1820if gt cnt 0
1821syn_pb 10
1822end
1823syn_pa buf ls syn_min sub i ls 400
1824cnt = add cnt 1
1825end
1826else
1827if pu_alkeep buf ls i
1828syn_pa buf ls sub i ls
1829syn_pb 10
1830cnt = add cnt 1
1831end
1832end
1833end
1834ls = add i 1
1835end
1836end
1837ret cnt
1838end
1839
1840note pu_flat: aien-watch text rule: newline, tab, CR to space; squeeze spaces; first 600 bytes
1841fn pu_flat xo ulong tn ulong to void
1842sp = false
1843k = ulong 0
1844for i ulong tn
1845c = get gsp add xo i
1846if or or eq c 10 eq c 9 eq c 13
1847c = 32
1848end
1849if not and sp eq c 32
1850if lt k 600
1851syn_pb c
1852k = add k 1
1853end
1854end
1855sp = eq c 32
1856end
1857end
1858
1859note pu_alwr: replace the alert file (ap,apl) with the pool text from kp, or remove it when empty
1860fn pu_alwr ap ulong apl ulong kp ulong to void
1861kl = syn_len kp
1862if gt kl 0
1863fd = syn_wbeg ap apl
1864if ge fd 0
1865w = write int fd gsp kp kl
1866r = syn_wend fd ap apl
1867end
1868else
1869r = unlink gsp ap apl
1870end
1871end
1872
1873note pu_alert: mode 1 raise with text (xo,tn), mode 0 resolve; garr holds the pool pieces
1874fn pu_alert mode ulong xo ulong tn ulong to void
1875buf = new uchar 262144 0
1876base = syn_mark
1877syn_tsw div ulong realns 1000000000
1878put garr 0 base
1879put garr 1 syn_len base
1880ap = pu_pathi 1 tslalert
1881apl = syn_len ap
1882n = syn_rfile ap apl buf
1883nn = ulong 0
1884if gt n 0
1885nn = ulong n
1886end
1887put garr 2 syn_mark
1888nd = pu_alsel buf nn 0
1889put garr 3 syn_len get garr 2
1890if and eq mode 0 eq nd 0
1891syn_rew base
1892ret
1893end
1894put garr 4 syn_mark
1895if eq mode 1
1896pu_flat xo tn
1897end
1898put garr 5 syn_len get garr 4
1899kp = syn_mark
1900nd = pu_alsel buf nn 1
1901if eq mode 1
1902syn_pt tkalcol
1903syn_pb 32
1904syn_ps get garr 4 get garr 5
1905syn_pt tsince
1906syn_ps get garr 0 get garr 1
1907syn_pt tdetails
1908pu_popt 1
1909syn_pt tclear
1910end
1911pu_alwr ap apl kp
1912lm = syn_mark
1913syn_ps get garr 0 get garr 1
1914if eq mode 1
1915syn_pb 32
1916syn_pt tkalert
1917syn_pb 32
1918syn_ps get garr 4 get garr 5
1919else
1920syn_pt tresolv
1921syn_ps get garr 2 get garr 3
1922end
1923syn_pb 10
1924pu_alog lm
1925syn_rew base
1926end