interplane.Get Omega
Read in your language

hop

Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.

Brought by drakestapleton

branch main Branches Tags History

hop / Omega / tests / mutant-fuse / mut.om

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