Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/protocol/interplane/forge/forge.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / protocol / interplane / forge / forge.om` 2807 lines ยท 49062 bytes Raw Blame History 1 om2 2 note INTERPLANE Forge v1: agents express intent, the forge retains authority. 3 note forge decide [--json] HEAD VERDICT RECEIPT prints "MERGE OK" and exits 0, or "HOLD " and 4 note exits 1 (with --json, one forge-decision/1 JSON object instead). 5 note forge status RID [REVIEWS [RECEIPTS]] lists the live Radicle patches of RID and decides each 6 note patch that has a verdict file. 7 note forge gate RID HEAD [--name N] [--out DIR] [--timeout S] --author A --neg ARGV.. -- ARGV.. runs a 8 note gate and its negative control, each in its own fresh clone at the exact head and process group, 9 note each killed with its group after S seconds (default 1800), and writes the gate receipt. 10 note Spec: docs/FORGE.md. Formats: forge/README.md. Every check fails closed. 11 global m uchar `1048576` 12 global g ulong 64 13 global hs uint 8 14 global hw uint 64 15 global hk uint 64 16 global hv uint 8 17 global hb uchar 64 18 note memory map of m: verdict, receipt, patch head, path, output line, exec packet, 19 note directory records, command output, patch ids, environment, arguments, patch fields 20 const kv ulong 0 21 const vcap ulong 65536 22 const kr ulong 65536 23 const rcap ulong 4096 24 const kh ulong 69632 25 const kp ulong 73728 26 const pcap ulong 4096 27 const kw ulong 77824 28 const wcap ulong 8192 29 const ke ulong 720896 30 const ecap ulong 4096 31 const kd ulong 90112 32 const dcap ulong 32768 33 const ko ulong 131072 34 const ocap ulong 524288 35 const ki ulong 655360 36 const icap ulong 512 37 const kx ulong 659456 38 const krid ulong 671744 39 const krev ulong 672000 40 const krcp ulong 676096 41 const ks ulong 680192 42 const kn ulong 684288 43 const kn2 ulong 684800 44 const kag ulong 688128 45 const acap ulong 4096 46 const kt ulong 692224 47 const kc ulong 692736 48 const knm ulong 693760 49 const kod ulong 693888 50 const kau ulong 695936 51 const kst ulong 696448 52 const kom ulong 698496 53 const krh ulong 700544 54 const ktr ulong 702592 55 const kgs ulong 702656 56 const kns ulong 702720 57 const kos ulong 702784 58 const kna ulong 786432 59 const knb ulong 851968 60 const kbuf ulong 917504 61 const bcap ulong 65536 62 note g slots: 0 output length, 1 verdict length, 2 receipt length, 3 verdict kind, 63 note 4 verdict head offset, 5 reviewer offset, 6 reviewer length, 7 clone offset, 64 note 8 gate_rc, 9 negctl_rc, 10 author offset, 11 author length, 12 receipt keys seen, 65 note 13 command output length, 19 HOME length, 21 PATH length, 16 RID length, 66 note 17 reviews dir length, 18 receipts dir length, 23 status word length, 67 note 24 verdict name length, 25 receipt name length, 30 packet length, 31 packet count, 68 note 32 read end of the spawn pipe, 33 name length, 34 out dir length, 35 author length, 69 note 36 first --neg argument, 37 index of "--", 38 OMC entry length (0: unset), 70 note 39 RAD_HOME entry length (0: unset), 40 temp dir length, 41 JSON output, 42 storage length, 71 note 43 SHA-256 bytes buffered, 44 SHA-256 total bytes, 45 started ns, 46 finished ns, 72 note 47 gate rc, 48 negctl rc, 49 and 50 gate log write and read fd, 51 and 52 negctl log write 73 note and read fd, 53 out files this gate run created, 54 gate timeout in seconds, 55 --timeout seen. 74 note kna and knb hold the normalized reviewer and author for the self-review check. 75 text tverd "VERDICT " 76 text tvw "VERDICT" 77 text tmaf "MERGE_AFTER_FIX " 78 text tmrg "MERGE " 79 text trej "REJECT " 80 text thead "head=" 81 text trevw "reviewer=" 82 text trch "FORGE-RECEIPT v1\n" 83 text tclone "clone=" 84 text tgate "gate_rc=" 85 text tneg "negctl_rc=" 86 text tauth "author=" 87 text tgcmd "gate_cmd=" 88 text tncmd "negctl_cmd=" 89 text tdec "decide" 90 text tstat "status" 91 text tmrgw "MERGE " 92 text tholdw "HOLD " 93 text tok "OK" 94 text tusage "USAGE" 95 text tbadh "BAD_HEAD" 96 text tvunr "VERDICT_UNREADABLE" 97 text tvmal "VERDICT_MALFORMED" 98 text tvmaf "VERDICT_MERGE_AFTER_FIX" 99 text tvrej "VERDICT_REJECT" 100 text thmis "HEAD_MISMATCH" 101 text tnorv "NO_REVIEWER" 102 text trunr "RECEIPT_UNREADABLE" 103 text trmal "RECEIPT_MALFORMED" 104 text tnong "NO_NEGCTL" 105 text tcmis "CLONE_MISMATCH" 106 text tgfail "GATE_FAIL" 107 text tnpass "NEGCTL_PASSED" 108 text tself "SELF_REVIEW" 109 text tvamb "VERDICT_AMBIGUOUS" 110 text tgtmo "GATE_TIMEOUT" 111 text thelp "usage: forge decide [--json] \n forge status [reviews-dir [receipts-dir]]\n forge gate [--name N] [--out DIR] [--timeout S] --author A --neg ARGV.. -- ARGV..\n" 112 text thome "HOME=" 113 text tpath "PATH=" 114 text tdpath "PATH=/usr/local/bin:/usr/bin:/bin" 115 text tenv "/usr/bin/env" 116 text trad "rad" 117 text tpatch "patch" 118 text tlist "list" 119 text tshow "show" 120 text tall "--all" 121 text trepo "--repo" 122 text trevd "/handoffs/hive/manager/reviews" 123 text trcpd "/handoffs/hive/forge/receipts" 124 text tvsuf ".verdict.txt" 125 text trsuf ".receipt.txt" 126 text tlpat " Patch " 127 text tlhead " Head " 128 text tlstat " Status " 129 text tsp "patch " 130 text tsst " status=" 131 text tshd " head=" 132 text tsvd " verdict=" 133 text tsdc " decision=" 134 text tnone "none" 135 text tnorun "NOT_RUN no verdict file" 136 text tsum "forge status " 137 text tspat " patches=" 138 text tsdec " decided=" 139 text tsmrg " merge=" 140 text tshld " hold=" 141 text tsnr " not_run=" 142 text terad "forge: rad failed, exit " 143 text tebad "forge: bad RID\n" 144 text tehome "forge: HOME is not set\n" 145 text tefld "forge: patch fields not found for " 146 text ttrunc "TRUNCATED patches=" 147 text ttrunc2 " examined=" 148 text tramb "RECEIPT_AMBIGUOUS" 149 text tsrc " receipt=" 150 text tgatew "gate" 151 text tjson "--json" 152 text tfname "--name" 153 text tfout "--out" 154 text tfauth "--author" 155 text tfneg "--neg" 156 text tftmo "--timeout" 157 text tdd "--" 158 text tomce "OMC=" 159 text tradh "RAD_HOME=" 160 text tgnos "GIT_CONFIG_NOSYSTEM=1" 161 text tgglob "GIT_CONFIG_GLOBAL=/dev/null" 162 text tgit "git" 163 text tinit "init" 164 text tq "-q" 165 text tdc "-C" 166 text tcfg "-c" 167 text tfetch "fetch" 168 text tnotags "--no-tags" 169 text tadv "advice.detachedHead=false" 170 text tcheck "checkout" 171 text tdetach "--detach" 172 text trevp "rev-parse" 173 text theadw "HEAD" 174 text ttreew "HEAD^{tree}" 175 text tinspect "inspect" 176 text tpayload "--payload" 177 text tnamek "\"name\": \"" 178 text trm "/bin/rm" 179 text trf "-rf" 180 text ttmp "/tmp/forge-gate-" 181 text tstor "/storage/" 182 text tdotrad "/.radicle" 183 text tgdir "/gate" 184 text tndir "/neg" 185 text tglog ".gate.log" 186 text tnlog ".negctl.log" 187 text ttgl "/gate.log" 188 text ttnl "/negctl.log" 189 text tdevnull "/dev/null" 190 text ttree "tree=" 191 text tridk "rid=" 192 text tomck "omc=" 193 text tstart "started=" 194 text tfin "finished=" 195 text tlsha "log_sha256=" 196 text tnlsha "negctl_log_sha256=" 197 text tj1 "{\"schema\":\"forge-decision/1\",\"head\":" 198 text tjnull "null" 199 text tjq "\"" 200 text tjdec ",\"decision\":\"" 201 text tjrsn "\",\"reason\":\"" 202 text tjend "\"}" 203 text tmerge "MERGE" 204 text thold "HOLD" 205 text tgo "forge gate " 206 text tgoh " head=" 207 text tgor " gate_rc=" 208 text tgon " negctl_rc=" 209 text tgorc " receipt=" 210 text teargs "forge: bad gate arguments (a newline in an argument, a command that starts with NAME=, or too long for the receipt)\n" 211 text tename "forge: bad repository name\n" 212 text teclone "forge: fresh clone failed\n" 213 text tetmp "forge: cannot create the temp dir\n" 214 text teout "forge: cannot write the receipt or a log (out dir missing, or an out file already exists)\n" 215 text teomc "forge: OMC is set but cannot be read\n" 216 text tebadh "forge: bad head\n" 217 text terun "forge: cannot run the gate command\n" 218 text tetmo "forge: bad --timeout (whole seconds, 1 to 86400)\n" 219 text ttmo1 "forge: timeout after " 220 text ttmo2 " s, process group killed with SIGKILL, exit status recorded as 124\n" 221 text tamb "ambiguous" 222 text tiso "0000-00-00T00:00:00Z" 223 text trpfx "rad:" 224 225 note ---- byte helpers over m ---- 226 227 note mat: true when m[ps..ps+len t) equals t and the match ends at or before lim 228 fn mat ps ulong lim ulong t view uchar * to bool 229 n = len t 230 if gt add ps n lim 231 ret false 232 end 233 i = ulong 0 234 while lt i n bound 4096 235 if ne get m add ps i get t i 236 ret false 237 end 238 i = add i 1 239 end 240 ret true 241 end 242 243 fn ishex c uchar to bool 244 if and ge c 48 le c 57 245 ret true 246 end 247 if and ge c 97 le c 102 248 ret true 249 end 250 ret false 251 end 252 253 note hex40: exactly 40 lowercase hex digits at m[ps..ps+40), all before lim 254 fn hex40 ps ulong lim ulong to bool 255 if gt add ps 40 lim 256 ret false 257 end 258 i = ulong 0 259 while lt i 40 bound 40 260 if eq ishex get m add ps i false 261 ret false 262 end 263 i = add i 1 264 end 265 ret true 266 end 267 268 note hexn: exactly n lowercase hex digits at m[ps..ps+n) 269 fn hexn ps ulong n ulong to bool 270 i = ulong 0 271 while lt i n bound 4096 272 if eq ishex get m add ps i false 273 ret false 274 end 275 i = add i 1 276 end 277 ret true 278 end 279 280 note argis: argument i is exactly the text t 281 fn argis i ulong t view uchar * to bool 282 n = argread i m add kx 5120 4096 283 if lt n 0 284 ret false 285 end 286 if ne ulong n len t 287 ret false 288 end 289 ret mat add kx 5120 add add kx 5120 len t t 290 end 291 292 fn eqr a ulong b ulong n ulong to bool 293 i = ulong 0 294 while lt i n bound 65536 295 if ne get m add a i get m add b i 296 ret false 297 end 298 i = add i 1 299 end 300 ret true 301 end 302 303 fn cpy dst ulong src ulong n ulong to void 304 i = ulong 0 305 while lt i n bound 65536 306 put m add dst i get m add src i 307 i = add i 1 308 end 309 end 310 311 fn tcpy dst ulong t view uchar * to ulong 312 n = len t 313 i = ulong 0 314 while lt i n bound 4096 315 put m add dst i get t i 316 i = add i 1 317 end 318 ret n 319 end 320 321 note eol: offset of the next newline at or after ps, or lim when there is none 322 fn eol ps ulong lim ulong to ulong 323 p = ps 324 while lt p lim bound `1048576` 325 if eq get m p 10 326 ret p 327 end 328 p = add p 1 329 end 330 ret p 331 end 332 333 note ---- output line ---- 334 335 fn obyte c uchar to void 336 w = get g 0 337 if ge w wcap 338 trap 12 339 end 340 put m add kw w c 341 put g 0 add w 1 342 end 343 344 fn otext t view uchar * to void 345 i = ulong 0 346 n = len t 347 while lt i n bound 4096 348 obyte get t i 349 i = add i 1 350 end 351 end 352 353 fn ocopy ps ulong n ulong to void 354 i = ulong 0 355 while lt i n bound 8192 356 obyte get m add ps i 357 i = add i 1 358 end 359 end 360 361 fn onum v ulong to void 362 b = new uchar 24 0 363 i = ulong 24 364 x = v 365 c = true 366 while c bound 24 367 i = sub i 1 368 put b i uchar add 48 rem x 10 369 x = div x 10 370 if eq x 0 371 c = false 372 end 373 end 374 while lt i 24 bound 24 375 obyte get b i 376 i = add i 1 377 end 378 end 379 380 fn oflush fd int to void 381 w = get g 0 382 o = ulong 0 383 c = true 384 while c bound 8192 385 if ge o w 386 c = false 387 else 388 r = write fd m add kw o sub w o 389 if le r 0 390 c = false 391 else 392 o = add o ulong r 393 end 394 end 395 end 396 put g 0 0 397 end 398 399 fn oreason c int to void 400 if eq c 0 401 otext tok 402 end 403 if eq c 1 404 otext tusage 405 end 406 if eq c 2 407 otext tbadh 408 end 409 if eq c 3 410 otext tvunr 411 end 412 if eq c 4 413 otext tvmal 414 end 415 if eq c 5 416 otext tvmaf 417 end 418 if eq c 6 419 otext tvrej 420 end 421 if eq c 7 422 otext thmis 423 end 424 if eq c 8 425 otext tnorv 426 end 427 if eq c 9 428 otext trunr 429 end 430 if eq c 10 431 otext trmal 432 end 433 if eq c 11 434 otext tnong 435 end 436 if eq c 12 437 otext tcmis 438 end 439 if eq c 13 440 otext tgfail 441 end 442 if eq c 14 443 otext tnpass 444 end 445 if eq c 15 446 otext tself 447 end 448 if eq c 16 449 otext tvamb 450 end 451 if eq c 17 452 otext tramb 453 end 454 if eq c 18 455 otext tgtmo 456 end 457 end 458 459 note odecis: "MERGE OK" or "HOLD " into the output line 460 fn odecis c int to void 461 if eq c 0 462 otext tmrgw 463 else 464 otext tholdw 465 end 466 oreason c 467 end 468 469 note ---- file loading ---- 470 471 note load: read the file named by m[kp..kp+pn) into m[ps..ps+cap); return its length, or -1 when 472 note it cannot be opened or read or does not fit (a file of cap bytes or more does not fit) 473 fn load pn ulong ps ulong cap ulong to long 474 fl = fopen m kp pn 524288 0 475 if lt fl 0 476 ret -1 477 end 478 fd = int fl 479 n = ulong 0 480 r = long 0 481 c = true 482 while c bound `1048576` 483 if ge n cap 484 c = false 485 else 486 r = read fd m add ps n sub cap n 487 if le r 0 488 c = false 489 else 490 n = add n ulong r 491 end 492 end 493 end 494 x = fclose fd 495 if lt r 0 496 ret -1 497 end 498 if ge n cap 499 ret -1 500 end 501 ret long n 502 end 503 504 note ---- verdict ---- 505 506 note pverd: line 1 is exactly "VERDICT head=<40 lowercase hex>" 507 note followed by a newline or the end of the file. Return 0 or 4 (VERDICT_MALFORMED). 508 fn pverd to int 509 n = add kv get g 1 510 if eq mat kv n tverd false 511 ret 4 512 end 513 p = add kv 8 514 k = ulong 0 515 if mat p n tmaf 516 k = ulong 2 517 p = add p 16 518 else 519 if mat p n tmrg 520 k = ulong 1 521 p = add p 6 522 else 523 if mat p n trej 524 k = ulong 3 525 p = add p 7 526 end 527 end 528 end 529 if eq k 0 530 ret 4 531 end 532 if eq mat p n thead false 533 ret 4 534 end 535 p = add p 5 536 if eq hex40 p n false 537 ret 4 538 end 539 q = add p 40 540 if lt q n 541 c = get m q 542 if ne c 10 543 ret 4 544 end 545 end 546 put g 3 k 547 put g 4 p 548 ret scanv n 549 end 550 551 note scanv: no later line may start with VERDICT, and at most one line starts with reviewer=. 552 note The reviewer value names a reviewer only when it holds a printable ASCII byte (33..126); 553 note a control byte in it (below 32 other than tab, or 127) is malformed. 554 fn scanv n ulong to int 555 p = add eol kv n 1 556 put g 5 0 557 put g 6 0 558 seen = false 559 while lt p n bound 65536 560 e = eol p n 561 if mat p e tvw 562 ret 4 563 end 564 if mat p e trevw 565 if seen 566 ret 4 567 end 568 seen = true 569 t = txtchk add p 9 e 570 if eq t 2 571 ret 4 572 end 573 if eq t 0 574 put g 5 add p 9 575 put g 6 sub e add p 9 576 end 577 end 578 p = add e 1 579 end 580 ret 0 581 end 582 583 note txtchk: m[v..e) as asserted text: 0 when it holds a byte in 33..126 and no control byte, 584 note 1 when it is empty or only spaces, tabs and bytes of 128 and above, 2 on a control byte 585 fn txtchk v ulong e ulong to int 586 p = v 587 vis = false 588 while lt p e bound 65536 589 c = get m p 590 if and lt c 32 ne c 9 591 ret 2 592 end 593 if eq c 127 594 ret 2 595 end 596 if and gt c 32 lt c 127 597 vis = true 598 end 599 p = add p 1 600 end 601 if vis 602 ret 0 603 end 604 ret 1 605 end 606 607 note ---- gate receipt (forge-receipt v1) ---- 608 609 note pdec: 1 to 3 decimal digits in m[v..e), value at most 255; 1000 means malformed 610 fn pdec v ulong e ulong to ulong 611 n = sub e v 612 if or eq n 0 gt n 3 613 ret 1000 614 end 615 x = ulong 0 616 i = v 617 while lt i e bound 3 618 c = get m i 619 if or lt c 48 gt c 57 620 ret 1000 621 end 622 x = add mul x 10 ulong sub c 48 623 i = add i 1 624 end 625 if gt x 255 626 ret 1000 627 end 628 ret x 629 end 630 631 note ridok: m[p..p+n) is "rad:" then 1 to 60 ASCII letters and digits 632 fn ridok p ulong n ulong to bool 633 if or lt n 5 gt n 64 634 ret false 635 end 636 if eq mat p add p 4 trpfx false 637 ret false 638 end 639 i = ulong 4 640 while lt i n bound 64 641 c = get m add p i 642 ok = false 643 if and ge c 48 le c 57 644 ok = true 645 end 646 if and ge c 65 le c 90 647 ok = true 648 end 649 if and ge c 97 le c 122 650 ok = true 651 end 652 if eq ok false 653 ret false 654 end 655 i = add i 1 656 end 657 ret true 658 end 659 660 note ronce: receipt key bit seen at most once; return 0 or 10 661 fn ronce bit ulong to int 662 s = get g 12 663 if ne and s bit 0 664 ret 10 665 end 666 put g 12 or s bit 667 ret 0 668 end 669 670 note rhex: the value of key t in m[p..e) is exactly n lowercase hex digits; return 0 or 10 671 fn rhex p ulong e ulong t view uchar * bit ulong n ulong to int 672 v = add p len t 673 if ne sub e v n 674 ret 10 675 end 676 if eq hexn v n false 677 ret 10 678 end 679 ret ronce bit 680 end 681 682 note isoz: m[v..e) is a UTC time YYYY-MM-DDTHH:MM:SSZ (digits where tiso has 0) 683 fn isoz v ulong e ulong to bool 684 if ne sub e v 20 685 ret false 686 end 687 i = ulong 0 688 while lt i 20 bound 20 689 c = get m add v i 690 w = get tiso i 691 if eq w 48 692 if or lt c 48 gt c 57 693 ret false 694 end 695 else 696 if ne c w 697 ret false 698 end 699 end 700 i = add i 1 701 end 702 ret true 703 end 704 705 note rkey: one key=value line m[p..e). Known keys only, each at most once. 706 fn rkey p ulong e ulong to int 707 s = get g 12 708 if mat p e tclone 709 if ne and s 1 0 710 ret 10 711 end 712 v = add p 6 713 if ne sub e v 40 714 ret 10 715 end 716 if eq hex40 v e false 717 ret 10 718 end 719 put g 7 v 720 put g 12 or s 1 721 ret 0 722 end 723 if mat p e tgate 724 if ne and s 2 0 725 ret 10 726 end 727 d = pdec add p 8 e 728 if eq d 1000 729 ret 10 730 end 731 put g 8 d 732 put g 12 or s 2 733 ret 0 734 end 735 if mat p e tneg 736 if ne and s 4 0 737 ret 10 738 end 739 d = pdec add p 10 e 740 if eq d 1000 741 ret 10 742 end 743 put g 9 d 744 put g 12 or s 4 745 ret 0 746 end 747 if mat p e tauth 748 if ne and s 8 0 749 ret 10 750 end 751 v = add p 7 752 if ne txtchk v e 0 753 ret 10 754 end 755 put g 10 v 756 put g 11 sub e v 757 put g 12 or s 8 758 ret 0 759 end 760 if mat p e tgcmd 761 if ne and s 16 0 762 ret 10 763 end 764 put g 12 or s 16 765 ret 0 766 end 767 if mat p e tncmd 768 if ne and s 32 0 769 ret 10 770 end 771 put g 12 or s 32 772 ret 0 773 end 774 if mat p e ttree 775 ret rhex p e ttree 64 40 776 end 777 if mat p e tridk 778 if eq ridok add p 4 sub e add p 4 false 779 ret 10 780 end 781 ret ronce 128 782 end 783 if mat p e tomck 784 if and eq sub e p 8 mat add p 4 e tnone 785 ret ronce 256 786 end 787 ret rhex p e tomck 256 64 788 end 789 if mat p e tstart 790 if eq isoz add p 8 e false 791 ret 10 792 end 793 ret ronce 512 794 end 795 if mat p e tfin 796 if eq isoz add p 9 e false 797 ret 10 798 end 799 ret ronce 1024 800 end 801 if mat p e tlsha 802 ret rhex p e tlsha 2048 64 803 end 804 if mat p e tnlsha 805 ret rhex p e tnlsha 4096 64 806 end 807 ret 10 808 end 809 810 note prcpt: return 0, 10 (RECEIPT_MALFORMED) or 11 (NO_NEGCTL) 811 fn prcpt to int 812 n = add kr get g 2 813 if eq mat kr n trch false 814 ret 10 815 end 816 p = add kr 17 817 put g 12 0 818 while lt p n bound 4096 819 e = eol p n 820 r = rkey p e 821 if ne r 0 822 ret r 823 end 824 p = add e 1 825 end 826 s = get g 12 827 if ne and s 11 11 828 ret 10 829 end 830 if eq and s 4 0 831 ret 11 832 end 833 ret 0 834 end 835 836 note ispun: a space or an ASCII punctuation byte 837 fn ispun c uchar to bool 838 if eq c 32 839 ret true 840 end 841 if and ge c 33 le c 47 842 ret true 843 end 844 if and ge c 58 le c 64 845 ret true 846 end 847 if and ge c 91 le c 96 848 ret true 849 end 850 if and ge c 123 le c 126 851 ret true 852 end 853 ret false 854 end 855 856 note nstrip: drop spaces and ASCII punctuation from both ends of m[d..d+n); return the new length 857 fn nstrip d ulong n ulong to ulong 858 e = n 859 c = true 860 while c bound 65536 861 if eq e 0 862 c = false 863 else 864 if ispun get m add d sub e 1 865 e = sub e 1 866 else 867 c = false 868 end 869 end 870 end 871 s = ulong 0 872 c = true 873 while c bound 65536 874 if ge s e 875 c = false 876 else 877 if ispun get m add d s 878 s = add s 1 879 else 880 c = false 881 end 882 end 883 end 884 cpy d add d s sub e s 885 ret sub e s 886 end 887 888 note norm: copy m[src..src+n) to m[dst..) folded to ASCII lower case; spaces, tabs, "_" and "-" 889 note count as spaces and each run of them becomes one space; then spaces and ASCII punctuation 890 note are stripped from both ends. Return the copied length. Unicode is not folded. 891 fn norm src ulong n ulong dst ulong to ulong 892 o = ulong 0 893 last = ulong 32 894 i = ulong 0 895 while lt i n bound 65536 896 c = ulong get m add src i 897 if or or eq c 32 eq c 9 or eq c 95 eq c 45 898 if ne last 32 899 put m add dst o 32 900 o = add o 1 901 last = ulong 32 902 end 903 else 904 if and ge c 65 le c 90 905 c = add c 32 906 end 907 put m add dst o uchar c 908 o = add o 1 909 last = c 910 end 911 i = add i 1 912 end 913 ret nstrip dst o 914 end 915 916 note hasauth: the normalized reviewer text contains the normalized receipt author (the author 917 note reviewed its own work). An author that normalizes to nothing counts as self-review. 918 fn hasauth to bool 919 rn = norm get g 5 get g 6 kna 920 an = norm get g 10 get g 11 knb 921 if eq an 0 922 ret true 923 end 924 if gt an rn 925 ret false 926 end 927 i = ulong 0 928 lim = sub rn an 929 while le i lim bound 65536 930 if eqr add kna i knb an 931 ret true 932 end 933 i = add i 1 934 end 935 ret false 936 end 937 938 note ---- the merge decision ---- 939 940 note decide: vr and rr are the verdict and receipt load results; the patch head is m[kh..kh+40). 941 note The first failing invariant is the reason. 0 is MERGE; everything else is HOLD. 942 fn decide vr long rr long to int 943 if eq hex40 kh add kh 40 false 944 ret 2 945 end 946 if le vr 0 947 ret 3 948 end 949 c = pverd 950 if ne c 0 951 ret c 952 end 953 k = get g 3 954 if eq k 2 955 ret 5 956 end 957 if eq k 3 958 ret 6 959 end 960 if eq eqr get g 4 kh 40 false 961 ret 7 962 end 963 if eq get g 6 0 964 ret 8 965 end 966 if eq rr long -2 967 ret 17 968 end 969 if le rr 0 970 ret 9 971 end 972 c = prcpt 973 if ne c 0 974 ret c 975 end 976 if eq eqr get g 7 kh 40 false 977 ret 12 978 end 979 if or eq get g 8 124 eq get g 9 124 980 ret 18 981 end 982 if ne get g 8 0 983 ret 13 984 end 985 if eq get g 9 0 986 ret 14 987 end 988 if hasauth 989 ret 15 990 end 991 ret 0 992 end 993 994 note say: print the decision (text, or one forge-decision/1 JSON object when g 41 is 1) 995 fn say c int to int 996 put g 0 0 997 if eq get g 41 1 998 otext tj1 999 if hex40 kh add kh 40 1000 otext tjq 1001 ocopy kh 40 1002 otext tjq 1003 else 1004 otext tjnull 1005 end 1006 otext tjdec 1007 if eq c 0 1008 otext tmerge 1009 else 1010 otext thold 1011 end 1012 otext tjrsn 1013 oreason c 1014 otext tjend 1015 else 1016 odecis c 1017 end 1018 obyte 10 1019 oflush 1 1020 if eq c 0 1021 ret 0 1022 end 1023 ret 1 1024 end 1025 1026 fn cdecide to int 1027 a = ulong argcnt 1028 o = ulong 2 1029 if ge a 3 1030 if argis 2 tjson 1031 put g 41 1 1032 o = ulong 3 1033 end 1034 end 1035 if ne a add o 3 1036 ret say 1 1037 end 1038 hn = argread o m kh 64 1039 if ne hn 40 1040 put m kh 0 1041 ret say 2 1042 end 1043 pn = argread add o 1 m kp pcap 1044 vr = long -1 1045 if gt pn 0 1046 vr = load ulong pn kv vcap 1047 end 1048 if gt vr 0 1049 put g 1 ulong vr 1050 end 1051 qn = argread add o 2 m kp pcap 1052 rr = long -1 1053 if gt qn 0 1054 rr = load ulong qn kr rcap 1055 end 1056 if gt rr 0 1057 put g 2 ulong rr 1058 end 1059 ret say decide vr rr 1060 end 1061 1062 note ---- status: the Radicle edge (rad CLI through /usr/bin/env) ---- 1063 1064 fn pkinit to void 1065 put g 30 2 1066 put g 31 0 1067 end 1068 1069 note pkadd: append one packed-list record m[ps..ps+n) to the exec packet 1070 fn pkadd ps ulong n ulong to void 1071 w = get g 30 1072 if gt add add w 2 n ecap 1073 trap 12 1074 end 1075 put m add ke w uchar and n 255 1076 put m add ke add w 1 uchar shr n 8 1077 cpy add ke add w 2 ps n 1078 put g 30 add add w 2 n 1079 put g 31 add get g 31 1 1080 end 1081 1082 fn pktext t view uchar * to void 1083 w = get g 30 1084 n = len t 1085 if gt add add w 2 n ecap 1086 trap 12 1087 end 1088 put m add ke w uchar and n 255 1089 put m add ke add w 1 uchar shr n 8 1090 x = tcpy add ke add w 2 t 1091 put g 30 add add w 2 n 1092 put g 31 add get g 31 1 1093 end 1094 1095 fn pkdone to ulong 1096 c = get g 31 1097 put m ke uchar and c 255 1098 put m add ke 1 uchar shr c 8 1099 ret get g 30 1100 end 1101 1102 note radpk: /usr/bin/env HOME=.. PATH=.. rad patch [ID] --repo RID; id is m[ps..ps+7) when n > 0 1103 fn radpk verb int ps ulong n ulong to ulong 1104 pkinit 1105 pktext tenv 1106 pkadd kx get g 19 1107 pkadd add kx 1024 get g 21 1108 pktext trad 1109 pktext tpatch 1110 if eq verb 0 1111 pktext tlist 1112 pktext tall 1113 else 1114 pktext tshow 1115 pkadd ps n 1116 end 1117 pktext trepo 1118 pkadd krid get g 16 1119 ret pkdone 1120 end 1121 1122 note spawn: run the packet with stdout on a pipe; return the child pid (read end in g 32) or a negative errno 1123 fn spawn pn ulong to long 1124 pf = new uchar 8 0 1125 r = pipefds pf 0 8 524288 1126 if lt r 0 1127 ret r 1128 end 1129 rfd = int or ulong get pf 0 shl ulong get pf 1 8 1130 wfd = int or ulong get pf 4 shl ulong get pf 5 8 1131 pid = fork 1132 if eq pid 0 1133 y = dupfd wfd 1 0 1134 y = execprog m ke pn 1135 exit 127 1136 end 1137 x = fclose wfd 1138 if lt pid 0 1139 x = fclose rfd 1140 ret pid 1141 end 1142 put g 32 ulong rfd 1143 ret pid 1144 end 1145 1146 note drain: read the child's stdout into m[ko..ko+ocap), length in g 13; true when it overflowed 1147 note (the child is then killed, so a runaway child cannot block the forge) 1148 fn drain rfd int pid long to bool 1149 n = ulong 0 1150 ovf = false 1151 c = true 1152 while c bound `1048576` 1153 if ge n ocap 1154 ovf = true 1155 x = killpid int pid 9 1156 c = false 1157 else 1158 r = read rfd m add ko n sub ocap n 1159 if le r 0 1160 c = false 1161 else 1162 n = add n ulong r 1163 end 1164 end 1165 end 1166 x = fclose rfd 1167 put g 13 n 1168 ret ovf 1169 end 1170 1171 note runcmd: run the packet, capture stdout; return the exit status, or a negative errno 1172 fn runcmd pn ulong to long 1173 st = new uchar 4 0 1174 pid = spawn pn 1175 if lt pid 0 1176 ret pid 1177 end 1178 ovf = drain int get g 32 pid 1179 w = waitpid int pid st 0 4 0 1180 if lt w 0 1181 ret w 1182 end 1183 if ovf 1184 ret -27 1185 end 1186 s = or ulong get st 0 shl ulong get st 1 8 1187 if ne and s 127 0 1188 ret -4 1189 end 1190 ret long and shr s 8 255 1191 end 1192 1193 note envget: copy the environment entry with prefix t into m[ps..ps+cap); return its length or 0 1194 fn envget t view uchar * ps ulong cap ulong to ulong 1195 c = ulong envcnt 1196 i = ulong 0 1197 while lt i c bound 65536 1198 n = envread i m add kx 5120 4096 1199 if gt n 0 1200 if mat add kx 5120 add add kx 5120 ulong n t 1201 if le ulong n cap 1202 cpy ps add kx 5120 ulong n 1203 ret ulong n 1204 end 1205 end 1206 end 1207 i = add i 1 1208 end 1209 ret 0 1210 end 1211 1212 note rowid: a patch table row is the box bar (e2 94 82), a space, a state glyph, spaces, 1213 note 7 hex digits and a space. Return the offset of the digits, or 0. 1214 fn rowid p ulong e ulong to ulong 1215 if gt add p 14 e 1216 ret 0 1217 end 1218 if ne get m p 226 1219 ret 0 1220 end 1221 if ne get m add p 1 148 1222 ret 0 1223 end 1224 if ne get m add p 2 130 1225 ret 0 1226 end 1227 q = add p 3 1228 if ne get m q 32 1229 ret 0 1230 end 1231 q = add q 1 1232 while and lt q e ne get m q 32 bound `1048576` 1233 q = add q 1 1234 end 1235 while and lt q e eq get m q 32 bound `1048576` 1236 q = add q 1 1237 end 1238 s = q 1239 while and lt q e ishex get m q bound `1048576` 1240 q = add q 1 1241 end 1242 if ne sub q s 7 1243 ret 0 1244 end 1245 if ge q e 1246 ret 0 1247 end 1248 if ne get m q 32 1249 ret 0 1250 end 1251 ret s 1252 end 1253 1254 note plist: copy the first icap patch ids of the list output to ki; return the number of rows listed 1255 fn plist to ulong 1256 n = add ko get g 13 1257 p = ko 1258 k = ulong 0 1259 while lt p n bound 524288 1260 e = eol p n 1261 s = rowid p e 1262 if ne s 0 1263 if lt k icap 1264 cpy add ki mul k 8 s 7 1265 end 1266 k = add k 1 1267 end 1268 p = add e 1 1269 end 1270 ret k 1271 end 1272 1273 note lblval: a field row "