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-tool-model/blob/main/deployment/conversation/runner.om # omega-tool-model First-party Omega tool-use model source, serving harnesses, and verification records Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-tool-model / deployment / conversation / runner.om` 991 lines ยท 15010 bytes Raw Blame History 1 note Model-driven tools for one bounded arithmetic practice file. Paths from the model never become OS paths. 2 global wsrc uchar 1024 3 global wslen ulong 1 4 global wobs uchar 1024 5 global wolen ulong 1 6 global wans uchar 4096 7 global walen ulong 1 8 global wpath uchar 128 9 global wplen ulong 1 10 global wgoal uchar 256 11 global wglen ulong 1 12 global wbuf uchar 8192 13 global wlen ulong 1 14 global wjob ulong 5 15 global wstate ulong 1 16 global wvalid ulong 1 17 global wcall ulong 1 18 global wclen ulong 1 19 global wtmp uchar 1024 20 global wtlen ulong 1 21 global wargv uchar 1024 22 global wstat uchar 4 23 global wdir uchar 256 24 global wdlen ulong 1 25 global wout uchar 4096 26 global wused ulong 1 27 global wfld uchar 512 28 global wflen ulong 4 29 global wpos ulong 1 30 global wtok uchar 128 31 global wtkn ulong 1 32 text wprog "program.om" 33 text wtest "test.om" 34 text wexe "test.bin" 35 text werr "check.err" 36 text wrout "run.out" 37 text wbase "$HOME/.local/share/omega-tool-model/practice/" 38 text wcomp "$HOME/.local/share/omega-tool-model/round40-conversation/omc" 39 text wexec "./test.bin" 40 41 fn wb c uchar to void 42 if ge get wlen 0 8192 43 exit 90 44 end 45 put wbuf get wlen 0 c 46 put wlen 0 add get wlen 0 1 47 end 48 fn wt s view uchar * to void 49 for i ulong len s 50 wb get s i 51 end 52 end 53 fn wn n ulong to void 54 if ge n 10 55 wn div n 10 56 end 57 wb uchar add rem n 10 48 58 end 59 fn wz to void 60 put wlen 0 0 61 end 62 fn wbyte mode ulong i ulong to uchar 63 if eq mode 1 64 ret get wsrc i 65 end 66 if eq mode 2 67 ret get wobs i 68 end 69 if eq mode 3 70 ret get wans i 71 end 72 if eq mode 4 73 ret get wpath i 74 end 75 if eq mode 5 76 ret get wgoal i 77 end 78 ret get wfld add mul sub mode 6 128 i 79 end 80 fn wlength mode ulong to ulong 81 if eq mode 1 82 ret get wslen 0 83 end 84 if eq mode 2 85 ret get wolen 0 86 end 87 if eq mode 3 88 ret get walen 0 89 end 90 if eq mode 4 91 ret get wplen 0 92 end 93 if eq mode 5 94 ret get wglen 0 95 end 96 ret get wflen sub mode 6 97 end 98 fn wa mode ulong to void 99 for i ulong wlength mode 100 wb wbyte mode i 101 end 102 end 103 fn wj mode ulong to void 104 wb 34 105 for i ulong wlength mode 106 c = wbyte mode i 107 if or eq c 34 eq c 92 108 wb 92 109 wb c 110 else 111 if eq c 10 112 wb 92 113 wb 110 114 else 115 if eq c 13 116 wb 92 117 wb 114 118 else 119 if eq c 9 120 wb 92 121 wb 116 122 else 123 if lt c 32 124 wb 63 125 else 126 wb c 127 end 128 end 129 end 130 end 131 end 132 end 133 wb 34 134 end 135 fn wo s view uchar * to void 136 put wolen 0 len s 137 for i ulong len s 138 put wobs i get s i 139 end 140 end 141 fn wobsbuf to void 142 if gt get wlen 0 1024 143 exit 90 144 end 145 put wolen 0 get wlen 0 146 for i ulong get wlen 0 147 put wobs i get wbuf i 148 end 149 end 150 fn wemit to bool 151 wb 10 152 n = get wlen 0 153 for i ulong n 154 put nbuf i get wbuf i 155 end 156 ret hchunk n 157 end 158 fn wevent kind view uchar * mode ulong to bool 159 wz 160 wt "{\"type\":\"" 161 wt kind 162 wt "\",\"text\":" 163 wj mode 164 wt "}" 165 ret wemit 166 end 167 fn wfinish ok bool msg view uchar * to void 168 wz 169 wt "{\"type\":\"done\",\"passed\":" 170 if ok 171 wt "true" 172 else 173 wt "false" 174 end 175 wt ",\"message\":\"" 176 wt msg 177 wt "\",\"source\":" 178 wj 1 179 wt "}" 180 r = wemit 181 r = streamend 182 end 183 184 note Match exact, host-free line grammar before the compiler is invoked. 185 fn wm at ulong s view uchar * to bool 186 if gt add at len s get wslen 0 187 ret false 188 end 189 for i ulong len s 190 if ne get wsrc add at i get s i 191 ret false 192 end 193 end 194 ret true 195 end 196 fn wconsume at ulong s view uchar * to ulong 197 if not wm at s 198 ret 10000 199 end 200 ret add at len s 201 end 202 fn wsmall at ulong to ulong 203 if ge at get wslen 0 204 ret 10000 205 end 206 c = get wsrc at 207 if or lt c 49 gt c 54 208 ret 10000 209 end 210 ret add at 1 211 end 212 fn wgrammar to bool 213 put wcall 0 0 214 put wclen 0 0 215 p = wconsume 0 "fn calc x int to int\n" 216 if wm p "s = x\nfor i ulong " 217 p = wconsume p "s = x\nfor i ulong " 218 p = wsmall p 219 p = wconsume p "\ns = " 220 if wm p "add" 221 p = add p 3 222 else 223 p = wconsume p "plus" 224 end 225 p = wconsume p " s int " 226 p = wsmall p 227 p = wconsume p "\nend\nret s\nend\n" 228 else 229 if eq get wjob 0 2 230 ret false 231 end 232 p = wconsume p "ret " 233 if or wm p "add" or wm p "mul" wm p "sub" 234 p = add p 3 235 else 236 if wm p "plus" 237 p = add p 4 238 else 239 p = wconsume p "times" 240 end 241 end 242 p = wconsume p " x int " 243 p = wsmall p 244 p = wconsume p "\nend\n" 245 end 246 p = wconsume p "fn main to int\nret calc int " 247 if ge p get wslen 0 248 ret false 249 end 250 put wcall 0 p 251 v = ulong 0 252 start = p 253 while lt p get wslen 0 bound 1024 254 c = get wsrc p 255 if or lt c 48 gt c 57 256 break 257 end 258 v = add mul v 10 ulong sub c 48 259 if gt v 99 260 ret false 261 end 262 p = add p 1 263 end 264 if or eq p start gt sub p start 2 265 ret false 266 end 267 put wclen 0 sub p start 268 if ne v get wjob 1 269 ret false 270 end 271 p = wconsume p "\nend\n" 272 ret eq p get wslen 0 273 end 274 275 fn wsave to bool 276 fd = fopen wprog 0 len wprog 524865 384 277 if lt fd 0 278 ret false 279 end 280 n = write int fd wsrc 0 get wslen 0 281 r = fclose int fd 282 ret and eq n long get wslen 0 eq r 0 283 end 284 fn wload to bool 285 fd = fopen wprog 0 len wprog 524288 0 286 if lt fd 0 287 ret false 288 end 289 n = read int fd wsrc 0 1024 290 r = fclose int fd 291 if or le n 0 gt n 600 292 ret false 293 end 294 put wslen 0 ulong n 295 ret eq r 0 296 end 297 fn wmkdir to bool 298 wz 299 wt wbase 300 wn ulong getpid 301 wb 45 302 wn ulong monons 303 n = get wlen 0 304 for i ulong n 305 put wdir i get wbuf i 306 end 307 put wdlen 0 n 308 if ne makedir wdir 0 n 448 0 309 ret false 310 end 311 ret eq chdir wdir 0 n 0 312 end 313 fn wclean to void 314 r = unlink wprog 0 len wprog 315 r = unlink wtest 0 len wtest 316 r = unlink wexe 0 len wexe 317 r = unlink werr 0 len werr 318 r = unlink wrout 0 len wrout 319 r = chdir wbase 0 len wbase 320 r = rmdir wdir 0 get wdlen 0 321 end 322 fn wwait pid int timeout long to long 323 deadline = add monons timeout 324 for poll ulong 10000 325 r = waitpid pid wstat 0 4 1 326 if eq r long pid 327 if ne get wstat 0 0 328 ret -2 329 end 330 ret long get wstat 1 331 end 332 if lt r 0 333 ret -3 334 end 335 if ge monons deadline 336 r = killpid pid 9 337 r = waitpid pid wstat 0 4 0 338 ret -1 339 end 340 r = sleepns `1000000` 341 end 342 r = killpid pid 9 343 r = waitpid pid wstat 0 4 0 344 ret -1 345 end 346 fn wlaunch mode ulong ifd int ofd int efd int to long 347 wz 348 if eq mode 0 349 wt wcomp 350 else 351 wt wexec 352 end 353 n = get wlen 0 354 put wargv 0 1 355 put wargv 1 0 356 put wargv 2 uchar and n 255 357 put wargv 3 uchar shr n 8 358 for i ulong n 359 put wargv add i 4 get wbuf i 360 end 361 pid = fork 362 if lt pid 0 363 ret -3 364 end 365 if eq pid 0 366 if ne dupfd ifd 0 0 0 367 exit 98 368 end 369 if ne dupfd ofd 1 0 1 370 exit 98 371 end 372 if ne dupfd efd 2 0 2 373 exit 98 374 end 375 r = execprog wargv 0 add n 4 376 exit 98 377 end 378 ret wwait int pid `2000000000` 379 end 380 fn wcompile to long 381 inf = fopen wtest 0 len wtest 524288 0 382 outf = fopen wexe 0 len wexe 524865 384 383 errf = fopen werr 0 len werr 524865 384 384 if or lt inf 0 or lt outf 0 lt errf 0 385 r = fclose int inf 386 r = fclose int outf 387 r = fclose int errf 388 ret -3 389 end 390 rc = wlaunch 0 int inf int outf int errf 391 r = fclose int inf 392 r = fclose int outf 393 r = fclose int errf 394 ret rc 395 end 396 fn wrun to long 397 inf = fopen wtest 0 len wtest 524288 0 398 outf = fopen wrout 0 len wrout 524865 384 399 errf = fopen werr 0 len werr 524865 384 400 if or lt inf 0 or lt outf 0 lt errf 0 401 r = fclose int inf 402 r = fclose int outf 403 r = fclose int errf 404 ret -3 405 end 406 if ne chmod wexe 0 len wexe 448 0 407 r = fclose int inf 408 r = fclose int outf 409 r = fclose int errf 410 ret -3 411 end 412 rc = wlaunch 1 int inf int outf int errf 413 r = fclose int inf 414 r = fclose int outf 415 r = fclose int errf 416 ret rc 417 end 418 fn wtestsrc x ulong to bool 419 wz 420 for i ulong get wcall 0 421 wb get wsrc i 422 end 423 wn x 424 p = add get wcall 0 get wclen 0 425 while lt p get wslen 0 bound 1024 426 wb get wsrc p 427 p = add p 1 428 end 429 fd = fopen wtest 0 len wtest 524865 384 430 if lt fd 0 431 ret false 432 end 433 n = write int fd wbuf 0 get wlen 0 434 r = fclose int fd 435 ret and eq n long get wlen 0 eq r 0 436 end 437 fn wexpected x ulong to ulong 438 if eq get wjob 0 0 439 ret add x get wjob 2 440 end 441 if eq get wjob 0 1 442 ret mul x get wjob 2 443 end 444 ret add x mul get wjob 2 get wjob 3 445 end 446 fn wcheck to bool 447 if not wload 448 wo "Could not read the practice file." 449 ret false 450 end 451 if not wgrammar 452 wo "Refused unsupported source." 453 ret false 454 end 455 for test ulong 4 456 x = get wjob 1 457 if eq test 1 458 x = 0 459 end 460 if eq test 2 461 x = 3 462 end 463 if eq test 3 464 x = 7 465 end 466 if not wtestsrc x 467 wo "Could not prepare the test." 468 ret false 469 end 470 rc = wcompile 471 if ne rc 0 472 if lt rc 0 473 wo "The compiler did not complete." 474 ret false 475 end 476 fd = fopen werr 0 len werr 524288 0 477 n = read int fd wobs 0 1024 478 r = fclose int fd 479 if le n 0 480 wo "Compilation failed." 481 else 482 put wolen 0 ulong n 483 while gt get wolen 0 0 bound 1024 484 p = sub get wolen 0 1 485 if ne get wobs p 10 486 break 487 end 488 put wolen 0 p 489 end 490 end 491 ret false 492 end 493 actual = wrun 494 if lt actual 0 495 wo "The test did not complete." 496 ret false 497 end 498 want = wexpected x 499 wz 500 wt "{\"type\":\"test\",\"input\":" 501 wn x 502 wt ",\"expected\":" 503 wn want 504 wt ",\"actual\":" 505 wn ulong actual 506 wt "}" 507 if not wemit 508 wo "The browser disconnected." 509 ret false 510 end 511 if ne ulong actual want 512 wz 513 wt "Test failed: calc(" 514 wn x 515 wt ") expected " 516 wn want 517 wt ", got " 518 wn ulong actual 519 wt "." 520 wobsbuf 521 ret false 522 end 523 end 524 wo "Tests passed." 525 ret true 526 end 527 528 note Strict JSON object with exactly tool/path, or tool/path/old/new, all bounded strings. 529 fn wspace to void 530 while lt get wpos 0 get walen 0 bound 4096 531 c = get wans get wpos 0 532 if not or or eq c 32 eq c 10 or eq c 13 eq c 9 533 ret 534 end 535 put wpos 0 add get wpos 0 1 536 end 537 end 538 fn wpunc c uchar to bool 539 wspace 540 p = get wpos 0 541 if ge p get walen 0 542 ret false 543 end 544 if ne get wans p c 545 ret false 546 end 547 put wpos 0 add p 1 548 ret true 549 end 550 fn wstring to bool 551 put wtkn 0 0 552 if not wpunc 34 553 ret false 554 end 555 while lt get wpos 0 get walen 0 bound 4096 556 p = get wpos 0 557 c = get wans p 558 put wpos 0 add p 1 559 if eq c 34 560 ret true 561 end 562 if lt c 32 563 ret false 564 end 565 if eq c 92 566 p = get wpos 0 567 if ge p get walen 0 568 ret false 569 end 570 c = get wans p 571 put wpos 0 add p 1 572 if eq c 110 573 c = 10 574 else 575 if eq c 114 576 c = 13 577 else 578 if eq c 116 579 c = 9 580 else 581 if not or eq c 34 or eq c 92 eq c 47 582 ret false 583 end 584 end 585 end 586 end 587 end 588 if ge get wtkn 0 127 589 ret false 590 end 591 put wtok get wtkn 0 c 592 put wtkn 0 add get wtkn 0 1 593 end 594 ret false 595 end 596 fn wtoken s view uchar * to bool 597 if ne get wtkn 0 len s 598 ret false 599 end 600 for i ulong len s 601 if ne get wtok i get s i 602 ret false 603 end 604 end 605 ret true 606 end 607 fn wfield slot ulong s view uchar * to bool 608 if ne get wflen slot len s 609 ret false 610 end 611 for i ulong len s 612 if ne get wfld add mul slot 128 i get s i 613 ret false 614 end 615 end 616 ret true 617 end 618 fn wjson to bool 619 put wpos 0 0 620 for i ulong 4 621 put wflen i 0 622 end 623 if not wpunc 123 624 ret false 625 end 626 mask = ulong 0 627 for field ulong 4 628 if not wstring 629 ret false 630 end 631 slot = ulong 4 632 if wtoken "tool" 633 slot = 0 634 end 635 if wtoken "path" 636 slot = 1 637 end 638 if wtoken "old" 639 slot = 2 640 end 641 if wtoken "new" 642 slot = 3 643 end 644 if eq slot 4 645 ret false 646 end 647 bit = shl ulong 1 slot 648 if ne and mask bit 0 649 ret false 650 end 651 mask = or mask bit 652 if not wpunc 58 653 ret false 654 end 655 if not wstring 656 ret false 657 end 658 put wflen slot get wtkn 0 659 for i ulong get wtkn 0 660 put wfld add mul slot 128 i get wtok i 661 end 662 wspace 663 p = get wpos 0 664 if ge p get walen 0 665 ret false 666 end 667 if eq get wans p 125 668 put wpos 0 add p 1 669 wspace 670 if ne get wpos 0 get walen 0 671 ret false 672 end 673 if wfield 0 "replace_text" 674 ret eq mask 15 675 end 676 ret eq mask 3 677 end 678 if not wpunc 44 679 ret false 680 end 681 end 682 ret false 683 end 684 fn wmatchold at ulong to bool 685 n = get wflen 2 686 if gt add at n get wslen 0 687 ret false 688 end 689 for i ulong n 690 if ne get wsrc add at i get wfld add 256 i 691 ret false 692 end 693 end 694 ret true 695 end 696 fn wpatch to bool 697 oldn = get wflen 2 698 newn = get wflen 3 699 if or eq oldn 0 or gt oldn 40 gt newn 40 700 ret false 701 end 702 count = ulong 0 703 found = ulong 0 704 for i ulong get wslen 0 705 if wmatchold i 706 count = add count 1 707 found = i 708 end 709 end 710 if ne count 1 711 ret false 712 end 713 newsize = add sub get wslen 0 oldn newn 714 if gt newsize 600 715 ret false 716 end 717 put wtlen 0 get wslen 0 718 for i ulong get wslen 0 719 put wtmp i get wsrc i 720 end 721 p = found 722 for i ulong newn 723 put wsrc p get wfld add 384 i 724 p = add p 1 725 end 726 tail = add found oldn 727 while lt tail get wtlen 0 bound 1024 728 put wsrc p get wtmp tail 729 p = add p 1 730 tail = add tail 1 731 end 732 put wslen 0 newsize 733 if not wgrammar 734 put wslen 0 get wtlen 0 735 for i ulong get wtlen 0 736 put wsrc i get wtmp i 737 end 738 ret false 739 end 740 ret wsave 741 end 742 743 fn wprompt to void 744 wz 745 wt "Task: Fix the error in this file and confirm its goal.\nFile: " 746 wa 4 747 wt "\nGoal: " 748 wa 5 749 wt "\nState: " 750 s = get wstate 0 751 if eq s 0 752 wt "unread" 753 end 754 if eq s 1 755 wt "read" 756 end 757 if eq s 2 758 wt "failed" 759 end 760 if eq s 3 761 wt "edited" 762 end 763 if eq s 4 764 wt "checked" 765 end 766 if eq s 5 767 wt "missing" 768 end 769 wb 10 770 if and ne s 0 ne s 5 771 wt "Source:\n" 772 wa 1 773 end 774 if ne s 0 775 wt "Tool result: " 776 wa 2 777 wb 10 778 end 779 wt "Answer:\n" 780 end 781 fn wresponse to bool 782 put walen 0 0 783 for frame ulong 1024 784 if not nreceive 0 2 `30000000000` 785 ret false 786 end 787 n = nlength 788 if eq n 0 789 ret true 790 end 791 if or eq n 65535 gt n 4096 792 ret false 793 end 794 if gt add get walen 0 n 4096 795 ret false 796 end 797 if not nreceive 0 n `2000000000` 798 ret false 799 end 800 for i ulong n 801 put wans add get walen 0 i get nbuf i 802 end 803 put walen 0 add get walen 0 n 804 end 805 ret false 806 end 807 fn wask to bool 808 wprompt 809 n = get wlen 0 810 if gt n 4000 811 ret false 812 end 813 nheader n 814 for i ulong n 815 put nbuf add i 2 get wbuf i 816 end 817 naddress 818 fd = socknew 1 524289 0 819 if lt fd 0 820 ret false 821 end 822 if ne connect int fd naddr 0 add len nsock 3 0 823 r = fclose int fd 824 ret false 825 end 826 put nfd 0 int fd 827 ok = false 828 if nsend 0 add n 2 829 ok = wresponse 830 end 831 r = fclose int fd 832 ret ok 833 end 834 fn wanswer s view uchar * to bool 835 if ne get walen 0 len s 836 ret false 837 end 838 for i ulong len s 839 if ne get wans i get s i 840 ret false 841 end 842 end 843 ret true 844 end 845 fn wrightpath to bool 846 if ne get wflen 1 get wplen 0 847 ret false 848 end 849 for i ulong get wplen 0 850 if ne get wfld add 128 i get wpath i 851 ret false 852 end 853 end 854 ret true 855 end 856 fn waction to bool 857 s = get wstate 0 858 if and wfield 0 "read_file" eq s 0 859 if eq get wjob 4 1 860 put wslen 0 0 861 put wstate 0 5 862 wo "File not found." 863 else 864 if not wload 865 ret false 866 end 867 put wstate 0 1 868 wo "Read succeeded." 869 end 870 ret wevent "observation" 2 871 end 872 if and wfield 0 "omega_check" or eq s 1 eq s 3 873 put wvalid 0 0 874 if wcheck 875 put wstate 0 4 876 put wvalid 0 1 877 else 878 put wstate 0 2 879 end 880 ret wevent "observation" 2 881 end 882 if and wfield 0 "replace_text" eq s 2 883 if not wpatch 884 ret false 885 end 886 put wstate 0 3 887 put wvalid 0 0 888 wo "Edit saved." 889 if not wevent "source" 1 890 ret false 891 end 892 ret wevent "observation" 2 893 end 894 ret false 895 end 896 fn wloop to void 897 put wstate 0 0 898 put wvalid 0 0 899 if not wevent "original" 1 900 ret 901 end 902 for turn ulong 7 903 if not wask 904 wfinish false "The model could not complete this request." 905 ret 906 end 907 if not wevent "action" 3 908 ret 909 end 910 if wanswer "Tests passed." 911 if and eq get wstate 0 4 eq get wvalid 0 1 912 wfinish true "The model completed the job and all four checks passed." 913 else 914 wfinish false "The model claimed success before verification. No success was recorded." 915 end 916 ret 917 end 918 if wanswer "File not found." 919 if eq get wstate 0 5 920 wfinish false "The model correctly reported the missing practice file." 921 else 922 wfinish false "The model incorrectly reported a missing file." 923 end 924 ret 925 end 926 if not wjson 927 wfinish false "The model returned an unsupported action. The run stopped." 928 ret 929 end 930 if not wrightpath 931 wfinish false "The model requested the wrong file. The run stopped." 932 ret 933 end 934 if not waction 935 wfinish false "The requested action was refused or could not finish." 936 ret 937 end 938 end 939 wfinish false "The model reached the seven-step limit without finishing." 940 end 941 fn wrepair to void 942 n = get hsize 0 943 off = get hend 0 944 if lt n 2 945 r = respond400 946 ret 947 end 948 id = get hreq off 949 if or lt id 65 gt id 77 950 r = respond400 951 ret 952 end 953 if ne get hreq add off 1 10 954 r = respond400 955 ret 956 end 957 wjobload ulong sub id 65 958 if gt sub n 2 600 959 r = respond400 960 ret 961 end 962 put wslen 0 sub n 2 963 for i ulong get wslen 0 964 put wsrc i get hreq add add off 2 i 965 end 966 if eq get wjob 4 1 967 put wslen 0 0 968 else 969 if not wgrammar 970 if streamhead 971 wfinish false "This practice area accepts only the small arithmetic program shapes shown in the examples. Keep the same main input." 972 end 973 ret 974 end 975 end 976 if not wmkdir 977 r = respond503 978 ret 979 end 980 if ne get wjob 4 1 981 if not wsave 982 wclean 983 r = respond503 984 ret 985 end 986 end 987 if streamhead 988 wloop 989 end 990 wclean 991 end