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/hop/blob/main/Omega/hopfuse.om # hop Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key. Brought by drakestapleton Sign in to star 1 stars 1 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `hop / Omega / hopfuse.om` 645 lines ยท 12289 bytes Raw Blame History 1 note hopfuse: how Hop chooses minds for a request, and how it judges a round of their answers. 2 note Native ABI v1 (OM-1). Contract: Omega/FUSE.md. One call, 256 ulong words in, 256 out, no state. 3 note Word 2 of the input is the operation: 1 PLAN (which seats, in what shape), 2 JUDGE (is there 4 note consensus). The vocabulary follows omega-mv spec/cognitive-routing.md: a requirement, the 5 note cheapest ladder expected to meet it, bounded escalation, an ensemble class, and a refusal in 6 note place of a silent approximation. Malformed input fails closed as verdict 1 INVALID. An unknown 7 note difficulty is never treated as trivial, and an unknown or failed seat is never chosen. 8 9 note code: reason r at input word i, packed as r*256+i (never 0 for r >= 1) 10 fn code r ulong i ulong to ulong 11 ret add mul r 256 i 12 end 13 14 fn bitset m ulong b ulong to bool 15 ret ne and m shl ulong 1 b 0 16 end 17 18 note field f of row r. Rows start at word 16 and are 6 words long. 19 note PLAN seat: 0 id, 1 tier, 2 family, 3 cost, 4 state, 5 capabilities 20 note JUDGE record: 0 seat id, 1 status, 2 confidence, 3 deltas, 4 agree, 5 zero 21 fn fld inp view ulong 256 r ulong f ulong to ulong 22 ret get inp add add 16 mul r 6 f 23 end 24 25 note a seat may be chosen when it is ready (1) or limited (2). Unknown (0) and down (3) never are. 26 fn usable inp view ulong 256 s ulong to ulong 27 st = fld inp s 4 28 if eq st 1 29 ret 1 30 end 31 if eq st 2 32 ret 1 33 end 34 ret 0 35 end 36 37 note what it costs to choose a seat. A limited seat counts `2000000` more than its price, which is 38 note above any ready seat's price, so a limited seat is taken only when no ready one can do it. 39 fn ceff inp view ulong 256 s ulong to ulong 40 c = fld inp s 3 41 if eq fld inp s 4 2 42 ret add c `2000000` 43 end 44 ret c 45 end 46 47 note how strong a seat counts when the strongest is wanted: its tier, and 4 more when it is ready, 48 note so any ready seat ranks above any limited one 49 fn rank inp view ulong 256 s ulong to ulong 50 if eq fld inp s 4 1 51 ret add fld inp s 1 4 52 end 53 ret fld inp s 1 54 end 55 56 note 1 when seat s may be chosen and has capability bit b (0 answer, 1 act) 57 fn can inp view ulong 256 s ulong b ulong to ulong 58 if eq usable inp s 0 59 ret 0 60 end 61 if bitset fld inp s 5 b 62 ret 1 63 end 64 ret 0 65 end 66 67 note cheapest seat with capability b and tier at least t that is not in mask m. 99 when none. 68 fn cheapest inp view ulong 256 n ulong b ulong t ulong m ulong to ulong 69 best = ulong 99 70 bc = ulong 0 71 for s ulong n 72 if eq can inp s b 1 73 if ge fld inp s 1 t 74 if not bitset m s 75 c = ceff inp s 76 if eq best 99 77 best = s 78 bc = c 79 else 80 if lt c bc 81 best = s 82 bc = c 83 end 84 end 85 end 86 end 87 end 88 end 89 ret best 90 end 91 92 note strongest seat with capability b and tier at least t that is not in mask m and whose family 93 note is not in family mask fm: ready before limited, then highest tier, then cheapest, then first 94 note given. 99 when none. 95 fn strong inp view ulong 256 n ulong b ulong m ulong t ulong fm ulong to ulong 96 best = ulong 99 97 bt = ulong 0 98 bc = ulong 0 99 for s ulong n 100 if eq can inp s b 1 101 if ge fld inp s 1 t 102 if not bitset m s 103 if not bitset fm fld inp s 2 104 st = rank inp s 105 c = ceff inp s 106 if eq best 99 107 best = s 108 bt = st 109 bc = c 110 else 111 if gt st bt 112 best = s 113 bt = st 114 bc = c 115 else 116 if eq st bt 117 if lt c bc 118 best = s 119 bc = c 120 end 121 end 122 end 123 end 124 end 125 end 126 end 127 end 128 end 129 ret best 130 end 131 132 note one PLAN seat row: id, tier 1..4, family 1..31, cost, state 0..3, capability mask 0..3 133 fn chkseat inp view ulong 256 r ulong to ulong 134 b = add 16 mul r 6 135 if gt get inp b 65535 136 ret code 15 b 137 end 138 t = get inp add b 1 139 if eq t 0 140 ret code 6 add b 1 141 end 142 if gt t 4 143 ret code 6 add b 1 144 end 145 f = get inp add b 2 146 if eq f 0 147 ret code 7 add b 2 148 end 149 if gt f 31 150 ret code 7 add b 2 151 end 152 if gt get inp add b 3 `1000000` 153 ret code 5 add b 3 154 end 155 if gt get inp add b 4 3 156 ret code 14 add b 4 157 end 158 if gt get inp add b 5 3 159 ret code 9 add b 5 160 end 161 ret 0 162 end 163 164 note one JUDGE record row: seat id, status 0..4, confidence in parts per million, deltas, agree, 0 165 fn chkrec inp view ulong 256 r ulong to ulong 166 b = add 16 mul r 6 167 if gt get inp b 65535 168 ret code 15 b 169 end 170 if gt get inp add b 1 4 171 ret code 14 add b 1 172 end 173 if gt get inp add b 2 `1000000` 174 ret code 5 add b 2 175 end 176 if gt get inp add b 3 1000 177 ret code 5 add b 3 178 end 179 if gt get inp add b 4 1 180 ret code 7 add b 4 181 end 182 if ne get inp add b 5 0 183 ret code 10 add b 5 184 end 185 ret 0 186 end 187 188 fn dupid inp view ulong 256 n ulong to ulong 189 for r ulong n 190 a = fld inp r 0 191 for q ulong r 192 if eq a fld inp q 0 193 ret code 8 add 16 mul r 6 194 end 195 end 196 end 197 ret 0 198 end 199 200 note the words 4..15 of a PLAN: kind 1..3, difficulty 0..5, stakes 0..3, confidence, most seats at 201 note once 1..8, most escalations 0..3, flags 0..7, then zeros 202 fn chkplan inp view ulong 256 to ulong 203 k = get inp 4 204 if eq k 0 205 ret code 12 4 206 end 207 if gt k 3 208 ret code 12 4 209 end 210 if gt get inp 5 5 211 ret code 12 5 212 end 213 if gt get inp 6 3 214 ret code 12 6 215 end 216 if gt get inp 7 `1000000` 217 ret code 5 7 218 end 219 p = get inp 8 220 if eq p 0 221 ret code 12 8 222 end 223 if gt p 8 224 ret code 12 8 225 end 226 if gt get inp 9 3 227 ret code 12 9 228 end 229 if gt get inp 10 7 230 ret code 12 10 231 end 232 for i ulong 16 233 if ge i 11 234 if ne get inp i 0 235 ret code 13 i 236 end 237 end 238 end 239 ret 0 240 end 241 242 note the words 4..15 of a JUDGE: rounds done 0..3, most rounds 0..3, then zeros 243 fn chkjudge inp view ulong 256 to ulong 244 if gt get inp 4 3 245 ret code 12 4 246 end 247 if gt get inp 5 3 248 ret code 12 5 249 end 250 for i ulong 16 251 if ge i 6 252 if ne get inp i 0 253 ret code 13 i 254 end 255 end 256 end 257 ret 0 258 end 259 260 fn chkhead inp view ulong 256 to ulong 261 for i ulong 256 262 if gt get inp i `9223372036854775807` 263 ret code 4 i 264 end 265 end 266 if ne get inp 0 `1212568915` 267 ret code 1 0 268 end 269 if ne get inp 1 1 270 ret code 2 1 271 end 272 op = get inp 2 273 if eq op 0 274 ret code 3 2 275 end 276 if gt op 2 277 ret code 3 2 278 end 279 n = get inp 3 280 e = ulong 0 281 if eq op 1 282 if gt n 16 283 ret code 11 3 284 end 285 e = chkplan inp 286 else 287 if gt n 8 288 ret code 11 3 289 end 290 e = chkjudge inp 291 end 292 if ne e 0 293 ret e 294 end 295 p = add 16 mul n 6 296 while lt p 256 bound 256 297 if ne get inp p 0 298 ret code 10 p 299 end 300 p = add p 1 301 end 302 for r ulong n 303 if eq op 1 304 e = chkseat inp r 305 else 306 e = chkrec inp r 307 end 308 if ne e 0 309 ret e 310 end 311 end 312 ret dupid inp n 313 end 314 315 fn zero res edit ulong 256 to void 316 for i ulong 256 317 put res i 0 318 end 319 end 320 321 fn invalid res edit ulong 256 e ulong to ulong 322 zero res 323 put res 0 `1212568915` 324 put res 1 1 325 put res 2 1 326 put res 3 div e 256 327 put res 4 rem e 256 328 ret 1 329 end 330 331 note the difficulty the plan must meet. An unknown difficulty counts as standard (3), never less. 332 note A triage that was not sure (under 600000) raises it one step, to hard at most. High stakes 333 note raise it one more step. Why it was raised goes to word 12: 1 unknown, 2 unsure, 4 stakes. 334 fn level inp view ulong 256 res edit ulong 256 to ulong 335 d = get inp 5 336 fl = ulong 0 337 if eq d 0 338 d = ulong 3 339 fl = or fl 1 340 end 341 if lt get inp 7 600000 342 if lt d 4 343 d = add d 1 344 fl = or fl 2 345 end 346 end 347 if eq get inp 6 3 348 if lt d 5 349 d = add d 1 350 fl = or fl 4 351 end 352 end 353 put res 12 fl 354 ret d 355 end 356 357 note role 4 for every seat that may not be chosen (unknown or down) 358 fn mark inp view ulong 256 res edit ulong 256 n ulong to void 359 for s ulong n 360 if eq usable inp s 0 361 put res add 32 s 4 362 end 363 end 364 end 365 366 note flag 32 in word 12 when a chosen seat is a limited one 367 fn flaglim inp view ulong 256 res edit ulong 256 n ulong to void 368 for s ulong n 369 r = get res add 32 s 370 if ge r 1 371 if le r 3 372 if eq fld inp s 4 2 373 put res 12 or get res 12 32 374 end 375 end 376 end 377 end 378 end 379 380 note write seat s as chosen seat number i: its id at 16+i, role 1, and its cost added to word 11 381 fn take inp view ulong 256 res edit ulong 256 i ulong s ulong to void 382 put res add 16 i fld inp s 0 383 put res add 32 s 1 384 put res 11 add get res 11 ceff inp s 385 end 386 387 note the escalation rungs after the first seat: each time the cheapest seat of a higher tier than 388 note the rung before, at most as many as word 9 allows. Returns the number of rungs in all. 389 fn climb inp view ulong 256 res edit ulong 256 n ulong b ulong first ulong to ulong 390 m = ulong 1 391 cur = fld inp first 1 392 mask = shl ulong 1 first 393 for k ulong 3 394 if lt k get inp 9 395 nx = cheapest inp n b add cur 1 mask 396 if ne nx 99 397 take inp res m nx 398 cur = fld inp nx 1 399 mask = or mask shl ulong 1 nx 400 m = add m 1 401 end 402 end 403 end 404 ret m 405 end 406 407 note one seat, then stronger ones if its answer is not accepted. t is the wanted tier, b the 408 note capability the work needs. Returns the number of rungs; 0 when no seat can do it. When no seat 409 note reaches the wanted tier the strongest one is taken and flag 16 says so. 410 fn ladder inp view ulong 256 res edit ulong 256 n ulong t ulong b ulong to ulong 411 first = cheapest inp n b t 0 412 if eq first 99 413 first = strong inp n b 0 1 0 414 if eq first 99 415 ret 0 416 end 417 put res 12 or get res 12 16 418 end 419 take inp res 0 first 420 m = climb inp res n b first 421 put res 7 m 422 ret m 423 end 424 425 note the proposers of a fusion: seats of tier 3 or more that can answer, one per family first 426 note (strongest, then cheapest), at most as many as word 8 allows. If that gives fewer than two, 427 note one more of a family already used may join. Returns how many were chosen. 428 fn proposers inp view ulong 256 res edit ulong 256 n ulong to ulong 429 mask = ulong 0 430 fm = ulong 0 431 m = ulong 0 432 for i ulong 8 433 if lt m get inp 8 434 s = strong inp n 0 mask 3 fm 435 if ne s 99 436 take inp res m s 437 mask = or mask shl ulong 1 s 438 fm = or fm shl ulong 1 fld inp s 2 439 m = add m 1 440 end 441 end 442 end 443 if lt m 2 444 s = strong inp n 0 mask 3 0 445 if ne s 99 446 take inp res m s 447 m = add m 1 448 end 449 end 450 put res 7 m 451 ret m 452 end 453 454 note undo what proposers wrote, when a fusion cannot be formed 455 fn unpick inp view ulong 256 res edit ulong 256 n ulong to void 456 for i ulong 8 457 put res add 16 i 0 458 end 459 for s ulong n 460 if eq get res add 32 s 1 461 put res add 32 s 0 462 end 463 end 464 put res 7 0 465 put res 11 0 466 end 467 468 note the seat that fuses (strongest that can answer) and, for work that changes things, the seat 469 note that carries it out (strongest that can act). Returns 0, or 81 when nothing can act. 470 fn fusers inp view ulong 256 res edit ulong 256 n ulong to ulong 471 sy = strong inp n 0 0 1 0 472 if eq sy 99 473 ret 80 474 end 475 put res 8 fld inp sy 0 476 if eq get res add 32 sy 0 477 put res add 32 sy 2 478 put res 11 add get res 11 ceff inp sy 479 end 480 if eq get inp 4 3 481 ex = strong inp n 1 0 1 0 482 if eq ex 99 483 ret 81 484 end 485 put res 9 fld inp ex 0 486 if eq get res add 32 ex 0 487 put res add 32 ex 3 488 put res 11 add get res 11 ceff inp ex 489 end 490 end 491 r = ulong 1 492 if eq get inp 6 3 493 r = ulong 2 494 end 495 put res 10 r 496 ret 0 497 end 498 499 note why nothing can be chosen: 80 no seat is ready at all, 81 seats are ready but none can do it 500 fn whynot inp view ulong 256 n ulong to ulong 501 for s ulong n 502 if eq usable inp s 1 503 ret 81 504 end 505 end 506 ret 80 507 end 508 509 note PLAN. Verdicts: 2 REFUSED, 3 DIRECT, 4 SINGLE, 5 LADDER, 6 FUSION. 510 fn plan inp view ulong 256 res edit ulong 256 n ulong to ulong 511 put res 8 `18446744073709551615` 512 put res 9 `18446744073709551615` 513 d = level inp res 514 put res 6 d 515 t = d 516 if ge d 4 517 t = ulong 4 518 end 519 put res 5 t 520 fl = get inp 10 521 if bitset fl 0 522 put res 2 3 523 ret 3 524 end 525 mark inp res n 526 b = ulong 0 527 if eq get inp 4 3 528 b = ulong 1 529 end 530 want = ulong 0 531 if eq d 5 532 want = ulong 1 533 end 534 if bitset fl 1 535 want = ulong 1 536 end 537 if bitset fl 2 538 want = ulong 0 539 end 540 if lt get inp 8 2 541 want = ulong 0 542 end 543 if eq want 1 544 m = proposers inp res n 545 if ge m 2 546 f = fusers inp res n 547 if ne f 0 548 put res 2 2 549 put res 3 f 550 ret 2 551 end 552 flaglim inp res n 553 put res 2 6 554 ret 6 555 end 556 unpick inp res n 557 put res 12 or get res 12 8 558 end 559 m = ladder inp res n t b 560 if eq m 0 561 put res 2 2 562 put res 3 whynot inp n 563 ret 2 564 end 565 flaglim inp res n 566 v = ulong 4 567 if gt m 1 568 v = ulong 5 569 end 570 put res 2 v 571 ret v 572 end 573 574 note JUDGE. A record is usable when its status is 1. A usable record agrees only when it says so 575 note and proposes no change; anything else is dissent, and an unknown status is never agreement. 576 note Verdicts: 7 CONSENSUS, 8 ANOTHER_ROUND, 9 SETTLE, 10 ONE_VOICE, 11 NONE. 577 fn judge inp view ulong 256 res edit ulong 256 n ulong to ulong 578 u = ulong 0 579 dis = ulong 0 580 td = ulong 0 581 mc = ulong `18446744073709551615` 582 for r ulong n 583 if eq fld inp r 1 1 584 put res add 16 u fld inp r 0 585 u = add u 1 586 c = fld inp r 2 587 if lt c mc 588 mc = c 589 end 590 dl = fld inp r 3 591 td = add td dl 592 cls = ulong 1 593 if eq fld inp r 4 0 594 cls = ulong 2 595 end 596 if gt dl 0 597 cls = ulong 2 598 end 599 if eq cls 2 600 dis = add dis 1 601 end 602 put res add 32 r cls 603 else 604 put res add 32 r 3 605 end 606 end 607 put res 5 u 608 put res 6 td 609 put res 7 mc 610 put res 8 dis 611 v = ulong 9 612 if eq u 0 613 v = ulong 11 614 else 615 if eq u 1 616 v = ulong 10 617 else 618 if eq dis 0 619 v = ulong 7 620 else 621 if lt get inp 4 get inp 5 622 v = ulong 8 623 end 624 end 625 end 626 end 627 put res 2 v 628 ret v 629 end 630 631 note entry 632 fn hopfuse inp view ulong 256 res edit ulong 256 to ulong 633 e = chkhead inp 634 if ne e 0 635 ret invalid res e 636 end 637 zero res 638 put res 0 `1212568915` 639 put res 1 1 640 n = get inp 3 641 if eq get inp 2 2 642 ret judge inp res n 643 end 644 ret plan inp res n 645 end