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
omega-mv / apps / interplane-forge / door / ev1decl.om
| 1 | note door/ (the agent door, docs/AGENT-DOOR.md): the public activity stream <base>events.json |
| 2 | note (schema interplane/events/1, also <base>events and <base>feed with Accept: application/json), |
| 3 | note the feed page <base>feed, and their store: the append-only, hash-chained file <data>events/log. |
| 4 | note Names: functions ev*, globals gev*, texts tev*. Needs collab/ (corefs, coload: the COB model) and |
| 5 | note social/ (the social log parser and the account names) composed; otherwise run.sh composes the |
| 6 | note seam server/nodoor.om, which answers 501 for these pages. |
| 7 | note Collection is change-triggered, never on a clock: before a page of the stream is answered, evcollect |
| 8 | note compares cheap fingerprints (the size of the social log, the change time of the open shelf list, |
| 9 | note and per public repository the change times of the ref folders that every Radicle ref update |
| 10 | note renames into) with the last ones and reads only what changed (docs/AGENT-DOOR.md). |
| 11 | note Log line, tab-separated, sanitized (no tab, newline or control byte inside a field): |
| 12 | note seq time kind actor rid source path json x subject prev |
| 13 | note seq from 1, time epoch seconds from the source record, kind 1..14, actor a did:key or empty, rid |
| 14 | note without rad: or empty, source the object id the event was read from, path and json relative to |
| 15 | note the base, x the verdict word (review) or "<old sha> <count>" (branch moved) or the followed did |
| 16 | note (follow) or the shelf name (open), prev the hex sha256 of the previous line (64 zeros for line 1). |
| 17 | const EVMAX ulong 262144 |
| 18 | const EVLMAX ulong 8192 |
| 19 | const EVBMAX ulong 32768 |
| 20 | text tevdir "events" |
| 21 | text tevrdir "events/r" |
| 22 | text tevlog "events/log" |
| 23 | text tevrp "events/r/" |
| 24 | text tevtmp ".tmp" |
| 25 | text tevlist "open/list.tsv" |
| 26 | text tevfer "for-each-ref" |
| 27 | text tevfmt "--format=%(objectname) %(creatordate:unix) %(refname)" |
| 28 | text tevrh "refs/heads/" |
| 29 | text tevrt "refs/tags" |
| 30 | text tevrtp "refs/tags/" |
| 31 | text tevns "refs/namespaces/" |
| 32 | text tevnst "/refs/tags" |
| 33 | text tevnstp "/refs/tags/" |
| 34 | text tevcpg "refs/namespaces/*/refs/cobs/xyz.radicle.patch/*" |
| 35 | text tevcig "refs/namespaces/*/refs/cobs/xyz.radicle.issue/*" |
| 36 | text tevcpm "/refs/cobs/xyz.radicle.patch/" |
| 37 | text tevcim "/refs/cobs/xyz.radicle.issue/" |
| 38 | text tevrl "rev-list" |
| 39 | text tevcnt "--count" |
| 40 | text tevdots ".." |
| 41 | text tevsrh "/refs/heads" |
| 42 | text tevsrt "/refs/tags" |
| 43 | text tevsns "/refs/namespaces" |
| 44 | text tevspk "/packed-refs" |
| 45 | text tevsrad "/refs/rad" |
| 46 | text tevdidk "did:key:" |
| 47 | text tevsocs "social.log:" |
| 48 | text tevopns "open/list.tsv:" |
| 49 | text tevopnp "open/" |
| 50 | text tevopnj "open.json" |
| 51 | text tevjsx ".json" |
| 52 | text tevpatp "/patches/" |
| 53 | text tevissp "/issues/" |
| 54 | text tevrelp "/releases/tag/" |
| 55 | text tevcmpp "/compare/" |
| 56 | text tevtdot "..." |
| 57 | text tevheld "held" |
| 58 | text tevstor "stored" |
| 59 | text tevwdr "withdrawn" |
| 60 | text tevvacc "accept" |
| 61 | text tevvrej "reject" |
| 62 | text tevmovd " moved" |
| 63 | text tevncom " new commit" |
| 64 | text tevncs "s" |
| 65 | text tevon " on " |
| 66 | text tevlbad "EVENTS-LOG TAMPER: events off at line " |
| 67 | text tevlwr "EVENTS-LOG write failed: events off" |
| 68 | text tevlpas "events: pass " |
| 69 | text tevlpus " us, sources read " |
| 70 | text tevlpev ", events added " |
| 71 | text tevlcob "events: COB not loaded, no events from it: " |
| 72 | text tevlcut "events: ref list longer than the buffer, repository skipped: " |
| 73 | text tevlbfl "events: batch full, flushed early" |
| 74 | note the log index: gevoff[k] is the byte offset of line k (seq k+1); gevoff[gevn] is the end |
| 75 | global gevoff ulong 262145 |
| 76 | global gevn ulong 1 |
| 77 | note gevok: 0 not loaded, 1 loaded and appendable, 2 refused (the chain did not verify, a write failed) |
| 78 | global gevok ulong 1 |
| 79 | global gevprv uchar 32 |
| 80 | note gevset: open-addressing set of event keys (FNV-1a 64 of kind, rid, source and x; never 0) |
| 81 | global gevset ulong 524288 |
| 82 | note per allow-list index: the fingerprint of the repository's ref folders when it was last read |
| 83 | global gevfp ulong 256 |
| 84 | note the social log bytes already read, and the open list fingerprint |
| 85 | global gevsoff ulong 1 |
| 86 | global gevofp ulong 1 |
| 87 | note read buffer (log lines, social lines), the old ref snapshot of one repository, the new one |
| 88 | global gevrb uchar 2097152 |
| 89 | global gevold uchar 4194304 |
| 90 | global gevoldl ulong 1 |
| 91 | global gevnew uchar 4194304 |
| 92 | global gevnewl ulong 1 |
| 93 | global gevst uchar 128 |
| 94 | global gevde uchar 16384 |
| 95 | note the line being written |
| 96 | global gevln uchar 8192 |
| 97 | global gevlnl ulong 1 |
| 98 | note the event being built: kind, time, and its byte fields (each a buffer and its length) |
| 99 | global gevk ulong 1 |
| 100 | global gevt ulong 1 |
| 101 | global gevact uchar 128 |
| 102 | global gevactl ulong 1 |
| 103 | global gevrid uchar 64 |
| 104 | global gevridl ulong 1 |
| 105 | global gevsub uchar 512 |
| 106 | global gevsubl ulong 1 |
| 107 | global gevpth uchar 1024 |
| 108 | global gevpthl ulong 1 |
| 109 | global gevjs uchar 1024 |
| 110 | global gevjsl ulong 1 |
| 111 | global gevsrc uchar 128 |
| 112 | global gevsrcl ulong 1 |
| 113 | global gevx uchar 192 |
| 114 | global gevxl ulong 1 |
| 115 | note the batch of one collection pass: partial lines (time .. subject) sorted by time before append |
| 116 | global gevbat uchar 16777216 |
| 117 | global gevbatl ulong 1 |
| 118 | global gevbo ulong 32768 |
| 119 | global gevbl ulong 32768 |
| 120 | global gevbt ulong 32768 |
| 121 | global gevbi ulong 32768 |
| 122 | global gevbj ulong 32768 |
| 123 | global gevbn ulong 1 |
| 124 | note counters of one collection pass (its stderr line names them with its cost in microseconds) |
| 125 | global gevpr ulong 1 |
| 126 | global gevpe ulong 1 |
| 127 | note changed COB ids of the repository being read: id (40 bytes) and kind (1 patch, 2 issue) |
| 128 | global gevcid uchar 163840 |
| 129 | global gevckd ulong 4096 |
| 130 | global gevcn ulong 1 |
| 131 | note one stderr line (evgb, evgt, evgn, evgc, then evgout) |
| 132 | global gevlg uchar 512 |
| 133 | global gevlgl ulong 1 |
| 134 | fn evgb to void |
| 135 | put gevlgl 0 0 |
| 136 | end |
| 137 | fn evgc c uchar to void |
| 138 | n = get gevlgl 0 |
| 139 | if lt n 510 |
| 140 | put gevlg n c |
| 141 | put gevlgl 0 add n 1 |
| 142 | end |
| 143 | end |
| 144 | fn evgt t view uchar * to void |
| 145 | for i ulong len t bound 256 |
| 146 | evgc get t i |
| 147 | end |
| 148 | end |
| 149 | fn evgn v ulong to void |
| 150 | d = new uchar 24 0 |
| 151 | k = evdec v d |
| 152 | for j ulong k bound 24 |
| 153 | evgc get d j |
| 154 | end |
| 155 | end |
| 156 | fn evgout to void |
| 157 | evgc 10 |
| 158 | w = write 2 gevlg 0 get gevlgl 0 |
| 159 | end |
| 160 | note ---- byte helpers for the line being written |
| 161 | fn evlc c uchar to void |
| 162 | n = get gevlnl 0 |
| 163 | if lt n sub EVLMAX 1 |
| 164 | put gevln n c |
| 165 | put gevlnl 0 add n 1 |
| 166 | end |
| 167 | end |
| 168 | note evdec v d: the decimal digits of v into d at 0; returns their count |
| 169 | fn evdec v ulong d edit uchar 24 to ulong |
| 170 | t = new uchar 24 0 |
| 171 | k = ulong 0 |
| 172 | x = v |
| 173 | for it ulong 21 |
| 174 | put t k uchar add rem x 10 48 |
| 175 | k = add k 1 |
| 176 | x = div x 10 |
| 177 | if eq x 0 |
| 178 | break |
| 179 | end |
| 180 | end |
| 181 | for j ulong k bound 24 |
| 182 | put d j get t sub sub k j 1 |
| 183 | end |
| 184 | ret k |
| 185 | end |
| 186 | fn evlnum v ulong to void |
| 187 | d = new uchar 24 0 |
| 188 | k = evdec v d |
| 189 | for j ulong k bound 24 |
| 190 | evlc get d j |
| 191 | end |
| 192 | end |
| 193 | note evsafe: a field byte as stored: tab, newline and the other control bytes become a space |
| 194 | fn evsafe c uchar to uchar |
| 195 | if or lt c 32 eq c 127 |
| 196 | ret uchar 32 |
| 197 | end |
| 198 | ret c |
| 199 | end |
| 200 | note ---- path helpers: fpth = <data><t> |
| 201 | fn evpath t view uchar * to void |
| 202 | fpb |
| 203 | fpt tfdata |
| 204 | fpt t |
| 205 | end |
| 206 | note evmkdirs: <data>events and <data>events/r (an existing folder is fine) |
| 207 | fn evmkdirs to void |
| 208 | evpath tevdir |
| 209 | x = makedir fpth 0 get fpthl 0 448 |
| 210 | evpath tevrdir |
| 211 | y = makedir fpth 0 get fpthl 0 448 |
| 212 | end |
| 213 | note evstat: stat fpth into gevst; a fingerprint of its change time and size, 0 when it is missing |
| 214 | fn evstat to ulong |
| 215 | r = stat fpth 0 get fpthl 0 gevst 0 128 |
| 216 | if lt r 0 |
| 217 | ret 0 |
| 218 | end |
| 219 | h = ulong 14695981039346656037 |
| 220 | for k ulong 8 |
| 221 | h = evfnv h get gevst add 48 k |
| 222 | h = evfnv h get gevst add 104 k |
| 223 | h = evfnv h get gevst add 112 k |
| 224 | end |
| 225 | ret h |
| 226 | end |
| 227 | fn evst64 o ulong to ulong |
| 228 | v = ulong 0 |
| 229 | for i ulong 8 |
| 230 | b = ulong get gevst add o i |
| 231 | v = or v shl b mul i 8 |
| 232 | end |
| 233 | ret v |
| 234 | end |
| 235 | note ---- event field setters (a collector fills one event, then evemit) |
| 236 | fn evclr to void |
| 237 | put gevk 0 0 |
| 238 | put gevt 0 0 |
| 239 | put gevactl 0 0 |
| 240 | put gevridl 0 0 |
| 241 | put gevsubl 0 0 |
| 242 | put gevpthl 0 0 |
| 243 | put gevjsl 0 0 |
| 244 | put gevsrcl 0 0 |
| 245 | put gevxl 0 0 |
| 246 | end |
| 247 | fn evactc c uchar to void |
| 248 | n = get gevactl 0 |
| 249 | if lt n len gevact |
| 250 | put gevact n evsafe c |
| 251 | put gevactl 0 add n 1 |
| 252 | end |
| 253 | end |
| 254 | fn evactt t view uchar * to void |
| 255 | for i ulong len t bound 128 |
| 256 | evactc get t i |
| 257 | end |
| 258 | end |
| 259 | fn evridc c uchar to void |
| 260 | n = get gevridl 0 |
| 261 | if lt n len gevrid |
| 262 | put gevrid n evsafe c |
| 263 | put gevridl 0 add n 1 |
| 264 | end |
| 265 | end |
| 266 | note evsubc: the subject is one line of at most 400 bytes (evsubend cuts it at a character start) |
| 267 | fn evsubc c uchar to void |
| 268 | n = get gevsubl 0 |
| 269 | if lt n 400 |
| 270 | put gevsub n evsafe c |
| 271 | put gevsubl 0 add n 1 |
| 272 | end |
| 273 | end |
| 274 | fn evsubt t view uchar * to void |
| 275 | for i ulong len t bound 400 |
| 276 | evsubc get t i |
| 277 | end |
| 278 | end |
| 279 | fn evsubend to void |
| 280 | n = get gevsubl 0 |
| 281 | if lt n 400 |
| 282 | ret |
| 283 | end |
| 284 | for it ulong 4 |
| 285 | k = get gevsubl 0 |
| 286 | if eq k 0 |
| 287 | ret |
| 288 | end |
| 289 | c = get gevsub sub k 1 |
| 290 | if ne and c 192 128 |
| 291 | put gevsubl 0 sub k 1 |
| 292 | ret |
| 293 | end |
| 294 | put gevsubl 0 sub k 1 |
| 295 | end |
| 296 | end |
| 297 | note evpthc: one byte of a URL path, percent-encoded unless unreserved or /; evpthr: raw |
| 298 | fn evpthc c uchar to void |
| 299 | if evunres c |
| 300 | evpthr c |
| 301 | ret |
| 302 | end |
| 303 | evpthr 37 |
| 304 | evpthr evhexu shr ulong c 4 |
| 305 | evpthr evhexu and ulong c 15 |
| 306 | end |
| 307 | fn evpthr c uchar to void |
| 308 | n = get gevpthl 0 |
| 309 | if lt n len gevpth |
| 310 | put gevpth n c |
| 311 | put gevpthl 0 add n 1 |
| 312 | end |
| 313 | end |
| 314 | fn evptht t view uchar * to void |
| 315 | for i ulong len t bound 64 |
| 316 | evpthr get t i |
| 317 | end |
| 318 | end |
| 319 | fn evunres c uchar to bool |
| 320 | if and ge c 97 le c 122 |
| 321 | ret true |
| 322 | end |
| 323 | if and ge c 65 le c 90 |
| 324 | ret true |
| 325 | end |
| 326 | if and ge c 48 le c 57 |
| 327 | ret true |
| 328 | end |
| 329 | ret or or eq c 45 eq c 46 or or eq c 95 eq c 126 eq c 47 |
| 330 | end |
| 331 | fn evhexu v ulong to uchar |
| 332 | if lt v 10 |
| 333 | ret uchar add v 48 |
| 334 | end |
| 335 | ret uchar add v 55 |
| 336 | end |
| 337 | note evpthrepo i: path = <owner>/<repo name of i> |
| 338 | fn evpthrepo i ulong to void |
| 339 | put gevpthl 0 0 |
| 340 | evptht tfowner |
| 341 | evpthr 47 |
| 342 | for k ulong frnlen i bound 128 |
| 343 | evpthc frnbyte i k |
| 344 | end |
| 345 | end |
| 346 | note evjsame: json = path (the page answers JSON at its own address with Accept: application/json) |
| 347 | fn evjsame to void |
| 348 | n = get gevpthl 0 |
| 349 | for k ulong n bound 1024 |
| 350 | put gevjs k get gevpth k |
| 351 | end |
| 352 | put gevjsl 0 n |
| 353 | end |
| 354 | fn evjsc c uchar to void |
| 355 | n = get gevjsl 0 |
| 356 | if lt n len gevjs |
| 357 | put gevjs n c |
| 358 | put gevjsl 0 add n 1 |
| 359 | end |
| 360 | end |
| 361 | fn evjst t view uchar * to void |
| 362 | for i ulong len t bound 64 |
| 363 | evjsc get t i |
| 364 | end |
| 365 | end |
| 366 | fn evsrcc c uchar to void |
| 367 | n = get gevsrcl 0 |
| 368 | if lt n len gevsrc |
| 369 | put gevsrc n evsafe c |
| 370 | put gevsrcl 0 add n 1 |
| 371 | end |
| 372 | end |
| 373 | fn evsrct t view uchar * to void |
| 374 | for i ulong len t bound 64 |
| 375 | evsrcc get t i |
| 376 | end |
| 377 | end |
| 378 | fn evsrcnum v ulong to void |
| 379 | d = new uchar 24 0 |
| 380 | k = evdec v d |
| 381 | for j ulong k bound 24 |
| 382 | evsrcc get d j |
| 383 | end |
| 384 | end |
| 385 | fn evxc c uchar to void |
| 386 | n = get gevxl 0 |
| 387 | if lt n len gevx |
| 388 | put gevx n evsafe c |
| 389 | put gevxl 0 add n 1 |
| 390 | end |
| 391 | end |
| 392 | fn evxt t view uchar * to void |
| 393 | for i ulong len t bound 64 |
| 394 | evxc get t i |
| 395 | end |
| 396 | end |
| 397 | note evridi i: the event is about allow-list repository i |
| 398 | fn evridi i ulong to void |
| 399 | put gevridl 0 0 |
| 400 | for k ulong fridlen i bound 64 |
| 401 | evridc fridbyte i k |
| 402 | end |
| 403 | end |
| 404 | note evowndid: the actor is the node delegate (did:key:<tfnid>) |
| 405 | fn evowndid to void |
| 406 | put gevactl 0 0 |
| 407 | evactt tevdidk |
| 408 | evactt tfnid |
| 409 | end |
| 410 | note ---- FNV-1a 64 |
| 411 | fn evfnv h ulong c uchar to ulong |
| 412 | x = xor h ulong c |
| 413 | ret mul x 1099511628211 |
| 414 | end |
| 415 | note evkey: the key of the event being built (kind, rid, source, x) |
| 416 | fn evkey to ulong |
| 417 | h = evfnv ulong 14695981039346656037 uchar get gevk 0 |
| 418 | h = evfnv h 0 |
| 419 | for i ulong get gevridl 0 bound 64 |
| 420 | h = evfnv h get gevrid i |
| 421 | end |
| 422 | h = evfnv h 0 |
| 423 | for i ulong get gevsrcl 0 bound 128 |
| 424 | h = evfnv h get gevsrc i |
| 425 | end |
| 426 | h = evfnv h 0 |
| 427 | for i ulong get gevxl 0 bound 192 |
| 428 | h = evfnv h get gevx i |
| 429 | end |
| 430 | if eq h 0 |
| 431 | ret ulong 1 |
| 432 | end |
| 433 | ret h |
| 434 | end |
| 435 | note ---- the key set |
| 436 | fn evhas k ulong to bool |
| 437 | m = sub len gevset 1 |
| 438 | s = and k m |
| 439 | for it ulong len gevset |
| 440 | v = get gevset s |
| 441 | if eq v 0 |
| 442 | ret false |
| 443 | end |
| 444 | if eq v k |
| 445 | ret true |
| 446 | end |
| 447 | s = and add s 1 m |
| 448 | end |
| 449 | ret false |
| 450 | end |
| 451 | fn evput k ulong to void |
| 452 | m = sub len gevset 1 |
| 453 | s = and k m |
| 454 | for it ulong len gevset |
| 455 | v = get gevset s |
| 456 | if or eq v 0 eq v k |
| 457 | put gevset s k |
| 458 | ret |
| 459 | end |
| 460 | s = and add s 1 m |
| 461 | end |
| 462 | end |
| 463 | note ---- digits |
| 464 | fn evdig c uchar to bool |
| 465 | ret and ge c 48 le c 57 |
| 466 | end |
| 467 | fn evhexd c uchar to bool |
| 468 | if evdig c |
| 469 | ret true |
| 470 | end |
| 471 | ret and ge c 97 le c 102 |
| 472 | end |
| 473 | fn evhexc v ulong to uchar |
| 474 | if lt v 10 |
| 475 | ret uchar add v 48 |
| 476 | end |
| 477 | ret uchar add v 87 |
| 478 | end |
| 479 | note evridpub: the allow-list index of the event's RID (gevrid, no rad:), 9999 when it is not public |
| 480 | fn evridpub to ulong |
| 481 | n = get gevridl 0 |
| 482 | for i ulong get fan 0 bound FAMAX |
| 483 | if eq fridlen i n |
| 484 | same = true |
| 485 | for k ulong n bound 64 |
| 486 | if ne fridbyte i k get gevrid k |
| 487 | same = false |
| 488 | break |
| 489 | end |
| 490 | end |
| 491 | if same |
| 492 | ret i |
| 493 | end |
| 494 | end |
| 495 | end |
| 496 | ret ulong 9999 |
| 497 | end |