interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / gpu / adapters / lib.om

922 lines · 19359 bytes Raw Blame History
1note gpu/adapters/lib.om: pure Omega hardware accelerator adapter layer & spark-adapters router/verifier/distill.
2note Upstream source: spark-adapters/src/{models,router,verifier,distill,lib}.rs plus GB10/multi-vendor hardware table.
3note Compose after si/directives/om2.om; no target line, no fn main.
4
5const AD_OK int 0
6const AD_ERR_NO_DEVICES int 1
7const AD_ERR_BAD_REQ int 2
8const AD_ERR_OFFLINE int 3
9const AD_ERR_VRAM_EXCEEDED int 4
10const AD_ERR_PRECISION int 5
11const AD_ERR_CC_LOW int 6
12
13const VENDOR_ANY ulong 0
14const VENDOR_NVIDIA ulong 1
15const VENDOR_AMD ulong 2
16const VENDOR_APPLE ulong 3
17const VENDOR_CPU ulong 4
18
19const ARCH_GB10_SM121 ulong 121
20const ARCH_H100_SM90 ulong 90
21const ARCH_RTX4090_SM89 ulong 89
22const ARCH_A100_SM80 ulong 80
23const ARCH_MI300X_GFX942 ulong 942
24const ARCH_M4_MAX ulong 400
25const ARCH_ARM64_CPU ulong 1
26
27const CAP_FP16 ulong 0x01
28const CAP_BF16 ulong 0x02
29const CAP_FP8 ulong 0x04
30const CAP_INT8 ulong 0x08
31const CAP_TF32 ulong 0x10
32const CAP_NVFP4 ulong 0x20
33const CAP_UNIFIED ulong 0x40
34const CAP_ALL_MASK ulong 0x7f
35
36const AD_GIB ulong 1073741824
37const AD_MAX_DEV ulong 16
38
39const PROV_OPENAI ulong 1
40const PROV_ANTHROPIC ulong 2
41const PROV_OPENROUTER ulong 3
42const PROV_GEMINI ulong 4
43const PROV_GROQ ulong 5
44const PROV_OLLAMA ulong 6
45const PROV_DEEPSEEK ulong 7
46const PROV_TOGETHER ulong 8
47const PROV_MISTRAL ulong 9
48const PROV_LOCAL_MAX ulong 10
49
50const VERIF_COMPILER ulong 1
51const VERIF_JSON ulong 2
52const VERIF_UNSLOP_STRICT ulong 3
53const VERIF_DUAL_CONSENSUS ulong 4
54
55const CHOSEN_TEACHER ulong 1
56const CHOSEN_STUDENT ulong 2
57
58struct WorkloadReq min_vram ulong req_flags ulong min_cc_maj ulong min_cc_min ulong pref_vendor ulong pref_unified bool end
59struct AdapterSel ok bool err int dev_id ulong score ulong checked ulong eligible ulong end
60struct RouteRes provider ulong ctx_len ulong requires_key bool is_resident bool matched_catalog bool cat_idx ulong end
61struct VerifRes passed bool critical bool score f64 violations ulong delim_ok bool end
62struct DistillDec chosen ulong pref_delta f64 commit_cortex bool end
63
64global ad_obuf uchar 32768
65global ad_olen ulong 1
66
67global ad_dev_cnt ulong 1
68global ad_dev_vendor ulong 16
69global ad_dev_arch ulong 16
70global ad_dev_vram ulong 16
71global ad_dev_cc_maj ulong 16
72global ad_dev_cc_min ulong 16
73global ad_dev_flags ulong 16
74global ad_dev_tflops ulong 16
75global ad_dev_bw ulong 16
76global ad_dev_online ulong 16
77
78text ta_nl "\n"
79text ta_sp " "
80text ta_dot "."
81text ta_minus "-"
82text ta_v_nv "NVIDIA"
83text ta_v_amd "AMD"
84text ta_v_apl "APPLE"
85text ta_v_cpu "CPU"
86text ta_a_gb10 "Blackwell-GB10-SM121"
87text ta_a_h100 "Hopper-H100-SM90"
88text ta_a_a100 "Ampere-A100-SM80"
89text ta_a_4090 "Ada-RTX4090-SM89"
90text ta_a_mi300 "CDNA3-MI300X-GFX942"
91text ta_a_m4 "Apple-M4-Max"
92text ta_a_cpu "ARM64-CPU"
93text ta_hdr "id vendor arch vram_gib cc flags tflops bw_gbps online\n"
94text ta_sep "--------------------------------------------------------------------------\n"
95text ta_sel_ok "SELECT ok=true dev_id="
96text ta_sel_sc " score="
97text ta_sel_el " eligible="
98text ta_sel_ch "/"
99text ta_sel_no "SELECT ok=false refusal_code="
100text ta_f_fp16 "FP16"
101text ta_f_bf16 "BF16"
102text ta_f_fp8 "FP8"
103text ta_f_int8 "INT8"
104text ta_f_tf32 "TF32"
105text ta_f_fp4 "NVFP4"
106text ta_f_uni "UNIFIED"
107text ta_comma ","
108text ta_yes "true"
109text ta_no "false"
110
111note upstream router catalog identifiers and prefixes
112text tr_cat0 "atlas-lightning-omni"
113text tr_cat1 "openai/gpt-4o"
114text tr_cat1m "gpt-4o"
115text tr_cat2 "openai/o3-mini"
116text tr_cat2m "o3-mini"
117text tr_cat3 "anthropic/claude-3-7-sonnet"
118text tr_cat3m "claude-3-7-sonnet-20250219"
119text tr_cat4 "openrouter/auto"
120text tr_cat5 "gemini/gemini-2.5-flash"
121text tr_cat5m "gemini-2.5-flash"
122text tr_cat6 "groq/llama-3.3-70b-versatile"
123text tr_cat6m "llama-3.3-70b-versatile"
124text tr_cat7 "ollama/qwen2.5-coder"
125text tr_cat7m "qwen2.5-coder:7b"
126text tr_cat8 "deepseek/deepseek-chat"
127text tr_cat8m "deepseek-chat"
128
129text tr_p_openai "openai/"
130text tr_p_anth "anthropic/"
131text tr_p_or "openrouter/"
132text tr_p_gem "gemini/"
133text tr_p_groq "groq/"
134text tr_p_oll "ollama/"
135text tr_p_ds "deepseek/"
136
137note upstream verifier banned words, sycophancy phrases, secret signatures
138text tv_b0 "delve"
139text tv_b1 "tapestry"
140text tv_b2 "crucial"
141text tv_b3 "beacon"
142text tv_b4 "game-changer"
143text tv_b5 "unleash"
144text tv_b6 "seamlessly"
145text tv_b7 "elevate"
146text tv_b8 "pivotal"
147
148text tv_s0 "certainly!"
149text tv_s1 "great question!"
150text tv_s2 "sure thing!"
151text tv_s3 "i would be happy to help"
152text tv_s4 "as an ai language model"
153
154text tv_k0 "-----BEGIN PRIVATE KEY-----"
155text tv_k1 "-----BEGIN OPENSSH PRIVATE KEY-----"
156text tv_k2 "sk-proj-"
157text tv_k3 "ghp_"
158
159note ---- buffered stdout writer
160
161fn ad_ob_reset to void
162put ad_olen 0 0
163end
164
165fn ad_ob_byte c uchar to void
166n = get ad_olen 0
167if lt n len ad_obuf
168put ad_obuf n c
169put ad_olen 0 add n 1
170end
171end
172
173fn ad_ob_str s view uchar * to void
174for i ulong len s
175ad_ob_byte get s i
176end
177end
178
179fn ad_ob_u64 v ulong to void
180d = new uchar 24 0
181pos = ulong 24
182x = v
183for it ulong 24
184pos = sub pos 1
185put d pos uchar add rem x 10 48
186x = div x 10
187if eq x 0
188break
189end
190end
191for k ulong sub 24 pos
192ad_ob_byte get d add pos k
193end
194end
195
196fn ad_ob_i64 v long to void
197if lt v 0
198ad_ob_str ta_minus
199ad_ob_u64 ulong neg v
200else
201ad_ob_u64 ulong v
202end
203end
204
205fn ad_ob_flush to void
206total = get ad_olen 0
207off = ulong 0
208note each iteration writes at least 1 byte or aborts, bounded by buffer size 32768
209while lt off total bound 32768
210k = write 1 ad_obuf off sub total off
211if le k 0
212break
213end
214off = add off ulong k
215end
216put ad_olen 0 0
217end
218
219note ---- hardware device capability table
220
221fn adapter_reset_devices to void
222put ad_dev_cnt 0 0
223end
224
225fn adapter_add_device vendor ulong arch ulong vram_gib ulong cc_maj ulong cc_min ulong flags ulong to int
226cnt = get ad_dev_cnt 0
227if ge cnt AD_MAX_DEV
228ret AD_ERR_BAD_REQ
229end
230put ad_dev_vendor cnt vendor
231put ad_dev_arch cnt arch
232put ad_dev_vram cnt mul vram_gib AD_GIB
233put ad_dev_cc_maj cnt cc_maj
234put ad_dev_cc_min cnt cc_min
235put ad_dev_flags cnt flags
236put ad_dev_tflops cnt 100
237put ad_dev_bw cnt 500
238put ad_dev_online cnt 1
239put ad_dev_cnt 0 add cnt 1
240ret AD_OK
241end
242
243fn adapter_set_perf dev_id ulong tflops ulong bw_gbps ulong online bool to void
244if lt dev_id get ad_dev_cnt 0
245put ad_dev_tflops dev_id tflops
246put ad_dev_bw dev_id bw_gbps
247if online
248put ad_dev_online dev_id 1
249else
250put ad_dev_online dev_id 0
251end
252end
253end
254
255fn adapter_init_default_devices to void
256adapter_reset_devices
257note 0: NVIDIA DGX Spark GB10 (SM 12.1, 128 GiB unified LPDDR5X, FP16/BF16/FP8/INT8/TF32/NVFP4/UNIFIED)
258r0 = adapter_add_device VENDOR_NVIDIA ARCH_GB10_SM121 128 12 1 0x7f
259adapter_set_perf 0 250 273 true
260note 1: NVIDIA H100 SXM5 (SM 9.0, 80 GiB HBM3, FP16/BF16/FP8/INT8/TF32)
261r1 = adapter_add_device VENDOR_NVIDIA ARCH_H100_SM90 80 9 0 0x1f
262adapter_set_perf 1 989 3350 true
263note 2: NVIDIA A100 SXM4 (SM 8.0, 40 GiB HBM2e, FP16/BF16/INT8/TF32, no FP8)
264r2 = adapter_add_device VENDOR_NVIDIA ARCH_A100_SM80 40 8 0 0x1b
265adapter_set_perf 2 312 1555 true
266note 3: NVIDIA RTX 4090 (SM 8.9, 24 GiB GDDR6X, FP16/BF16/FP8/INT8/TF32)
267r3 = adapter_add_device VENDOR_NVIDIA ARCH_RTX4090_SM89 24 8 9 0x1f
268adapter_set_perf 3 165 1008 true
269note 4: AMD Instinct MI300X (CDNA3 9.4, 192 GiB HBM3, FP16/BF16/FP8/INT8, no TF32)
270r4 = adapter_add_device VENDOR_AMD ARCH_MI300X_GFX942 192 9 4 0x0f
271adapter_set_perf 4 1307 5300 true
272note 5: Apple M4 Max (64 GiB unified, FP16/BF16/INT8/UNIFIED, no FP8/TF32)
273r5 = adapter_add_device VENDOR_APPLE ARCH_M4_MAX 64 4 0 0x4b
274adapter_set_perf 5 54 546 true
275sum_rc = add r0 add r1 add r2 add r3 add r4 r5
276if ne sum_rc 0
277ret
278end
279end
280
281note ---- capability checking, strict refusal, and deterministic scoring
282
283fn adapter_cc_packed maj ulong mn ulong to ulong
284ret add mul maj 10 mn
285end
286
287fn adapter_check_device dev_id ulong req view WorkloadReq to int
288if ge dev_id get ad_dev_cnt 0
289ret AD_ERR_NO_DEVICES
290end
291if eq get ad_dev_online dev_id 0
292ret AD_ERR_OFFLINE
293end
294if lt get ad_dev_vram dev_id get req min_vram
295ret AD_ERR_VRAM_EXCEEDED
296end
297req_f = get req req_flags
298dev_f = get ad_dev_flags dev_id
299if ne and dev_f req_f req_f
300ret AD_ERR_PRECISION
301end
302dev_cc = adapter_cc_packed get ad_dev_cc_maj dev_id get ad_dev_cc_min dev_id
303req_cc = adapter_cc_packed get req min_cc_maj get req min_cc_min
304if lt dev_cc req_cc
305ret AD_ERR_CC_LOW
306end
307ret AD_OK
308end
309
310fn adapter_score_device dev_id ulong req view WorkloadReq to ulong
311sc = mul get ad_dev_tflops dev_id 10
312sc = add sc mul get ad_dev_bw dev_id 2
313vram_gib = div get ad_dev_vram dev_id AD_GIB
314if gt vram_gib 256
315vram_gib = 256
316end
317sc = add sc mul vram_gib 5
318pv = get req pref_vendor
319if and ne pv VENDOR_ANY eq get ad_dev_vendor dev_id pv
320sc = add sc 50000
321end
322if get req pref_unified
323if ne and get ad_dev_flags dev_id CAP_UNIFIED 0
324sc = add sc 3000
325end
326end
327ret sc
328end
329
330fn adapter_refusal_priority cur int cand int to int
331if eq cur AD_OK
332ret cand
333end
334note Prefer precision or VRAM refusal over generic offline when multiple devices fail
335if eq cand AD_ERR_PRECISION
336ret cand
337end
338if and eq cand AD_ERR_VRAM_EXCEEDED ne cur AD_ERR_PRECISION
339ret cand
340end
341if and eq cand AD_ERR_CC_LOW eq cur AD_ERR_OFFLINE
342ret cand
343end
344ret cur
345end
346
347fn adapter_select req view WorkloadReq sel edit AdapterSel to int
348put sel ok false
349put sel err AD_OK
350put sel dev_id 0
351put sel score 0
352put sel checked 0
353put sel eligible 0
354cnt = get ad_dev_cnt 0
355if eq cnt 0
356put sel err AD_ERR_NO_DEVICES
357ret AD_ERR_NO_DEVICES
358end
359if or eq get req min_vram 0 ne and get req req_flags xor CAP_ALL_MASK 0xffffffffffffffff 0
360put sel err AD_ERR_BAD_REQ
361ret AD_ERR_BAD_REQ
362end
363best_ref = AD_OK
364for i ulong cnt bound 16
365put sel checked add get sel checked 1
366chk = adapter_check_device i req
367if eq chk AD_OK
368sc = adapter_score_device i req
369put sel eligible add get sel eligible 1
370if or not get sel ok gt sc get sel score
371put sel ok true
372put sel dev_id i
373put sel score sc
374end
375else
376best_ref = adapter_refusal_priority best_ref chk
377end
378end
379if not get sel ok
380put sel err best_ref
381ret best_ref
382end
383ret AD_OK
384end
385
386note ---- deterministic hardware probe and selection output
387
388fn ad_ob_vendor v ulong to void
389if eq v VENDOR_NVIDIA
390ad_ob_str ta_v_nv
391ret
392end
393if eq v VENDOR_AMD
394ad_ob_str ta_v_amd
395ret
396end
397if eq v VENDOR_APPLE
398ad_ob_str ta_v_apl
399ret
400end
401ad_ob_str ta_v_cpu
402end
403
404fn ad_ob_arch a ulong to void
405if eq a ARCH_GB10_SM121
406ad_ob_str ta_a_gb10
407ret
408end
409if eq a ARCH_H100_SM90
410ad_ob_str ta_a_h100
411ret
412end
413if eq a ARCH_A100_SM80
414ad_ob_str ta_a_a100
415ret
416end
417if eq a ARCH_RTX4090_SM89
418ad_ob_str ta_a_4090
419ret
420end
421if eq a ARCH_MI300X_GFX942
422ad_ob_str ta_a_mi300
423ret
424end
425if eq a ARCH_M4_MAX
426ad_ob_str ta_a_m4
427ret
428end
429ad_ob_str ta_a_cpu
430end
431
432fn adapter_print_probe to void
433cnt = get ad_dev_cnt 0
434ad_ob_reset
435ad_ob_str ta_hdr
436ad_ob_str ta_sep
437for i ulong cnt bound 16
438ad_ob_u64 i
439ad_ob_str ta_sp
440ad_ob_vendor get ad_dev_vendor i
441ad_ob_str ta_sp
442ad_ob_arch get ad_dev_arch i
443ad_ob_str ta_sp
444ad_ob_u64 div get ad_dev_vram i AD_GIB
445ad_ob_str ta_sp
446ad_ob_u64 get ad_dev_cc_maj i
447ad_ob_str ta_dot
448ad_ob_u64 get ad_dev_cc_min i
449ad_ob_str ta_sp
450ad_ob_u64 get ad_dev_flags i
451ad_ob_str ta_sp
452ad_ob_u64 get ad_dev_tflops i
453ad_ob_str ta_sp
454ad_ob_u64 get ad_dev_bw i
455ad_ob_str ta_sp
456if ne get ad_dev_online i 0
457ad_ob_str ta_yes
458else
459ad_ob_str ta_no
460end
461ad_ob_str ta_nl
462end
463ad_ob_flush
464end
465
466fn adapter_print_selection sel view AdapterSel to void
467ad_ob_reset
468if get sel ok
469ad_ob_str ta_sel_ok
470ad_ob_u64 get sel dev_id
471ad_ob_str ta_sel_sc
472ad_ob_u64 get sel score
473ad_ob_str ta_sel_el
474ad_ob_u64 get sel eligible
475ad_ob_str ta_sel_ch
476ad_ob_u64 get sel checked
477ad_ob_str ta_nl
478else
479ad_ob_str ta_sel_no
480ad_ob_i64 long get sel err
481ad_ob_str ta_nl
482end
483ad_ob_flush
484end
485
486note ---- upstream spark-adapters model provider router (src/router.rs)
487
488fn ad_low c uchar to uchar
489if and ge c 65 le c 90
490ret uchar add c 32
491end
492ret c
493end
494
495fn ad_str_eq a view uchar * b view uchar * to bool
496if ne len a len b
497ret false
498end
499for i ulong len a bound 512
500if ne get a i get b i
501ret false
502end
503end
504ret true
505end
506
507fn ad_str_starts a view uchar * pre view uchar * to bool
508if lt len a len pre
509ret false
510end
511for i ulong len pre bound 128
512if ne get a i get pre i
513ret false
514end
515end
516ret true
517end
518
519fn ad_contains_exact a view uchar * pat view uchar * to bool
520pl = len pat
521al = len a
522if or eq pl 0 lt al pl
523ret false
524end
525lim = add sub al pl 1
526for i ulong lim bound 4096
527ok = true
528for j ulong pl bound 128
529if ne get a add i j get pat j
530ok = false
531break
532end
533end
534if ok
535ret true
536end
537end
538ret false
539end
540
541fn ad_contains_ci a view uchar * pat view uchar * to bool
542pl = len pat
543al = len a
544if or eq pl 0 lt al pl
545ret false
546end
547lim = add sub al pl 1
548for i ulong lim bound 4096
549ok = true
550for j ulong pl bound 128
551if ne ad_low get a add i j ad_low get pat j
552ok = false
553break
554end
555end
556if ok
557ret true
558end
559end
560ret false
561end
562
563fn ad_set_route res edit RouteRes prov ulong ctx ulong rkey bool isres bool cat ulong to void
564put res provider prov
565put res ctx_len ctx
566put res requires_key rkey
567put res is_resident isres
568put res matched_catalog true
569put res cat_idx cat
570end
571
572fn adapter_resolve_catalog q view uchar * res edit RouteRes to bool
573if ad_str_eq q tr_cat0
574ad_set_route res PROV_LOCAL_MAX 32768 false true 0
575ret true
576end
577if or ad_str_eq q tr_cat1 ad_str_eq q tr_cat1m
578ad_set_route res PROV_OPENAI 128000 true false 1
579ret true
580end
581if or ad_str_eq q tr_cat2 ad_str_eq q tr_cat2m
582ad_set_route res PROV_OPENAI 200000 true false 2
583ret true
584end
585if or ad_str_eq q tr_cat3 ad_str_eq q tr_cat3m
586ad_set_route res PROV_ANTHROPIC 200000 true false 3
587ret true
588end
589if ad_str_eq q tr_cat4
590ad_set_route res PROV_OPENROUTER 128000 true false 4
591ret true
592end
593if or ad_str_eq q tr_cat5 ad_str_eq q tr_cat5m
594ad_set_route res PROV_GEMINI 1000000 true false 5
595ret true
596end
597if or ad_str_eq q tr_cat6 ad_str_eq q tr_cat6m
598ad_set_route res PROV_GROQ 128000 true false 6
599ret true
600end
601if or ad_str_eq q tr_cat7 ad_str_eq q tr_cat7m
602ad_set_route res PROV_OLLAMA 32768 false false 7
603ret true
604end
605if or ad_str_eq q tr_cat8 ad_str_eq q tr_cat8m
606ad_set_route res PROV_DEEPSEEK 64000 true false 8
607ret true
608end
609ret false
610end
611
612fn adapter_resolve_route q view uchar * res edit RouteRes to void
613if adapter_resolve_catalog q res
614ret
615end
616put res matched_catalog false
617put res cat_idx 0
618if ad_str_starts q tr_p_openai
619put res provider PROV_OPENAI
620put res ctx_len 128000
621put res requires_key true
622put res is_resident false
623ret
624end
625if ad_str_starts q tr_p_anth
626put res provider PROV_ANTHROPIC
627put res ctx_len 200000
628put res requires_key true
629put res is_resident false
630ret
631end
632if ad_str_starts q tr_p_or
633put res provider PROV_OPENROUTER
634put res ctx_len 128000
635put res requires_key true
636put res is_resident false
637ret
638end
639if ad_str_starts q tr_p_gem
640put res provider PROV_GEMINI
641put res ctx_len 1000000
642put res requires_key true
643put res is_resident false
644ret
645end
646if ad_str_starts q tr_p_groq
647put res provider PROV_GROQ
648put res ctx_len 128000
649put res requires_key true
650put res is_resident false
651ret
652end
653if ad_str_starts q tr_p_oll
654put res provider PROV_OLLAMA
655put res ctx_len 32768
656put res requires_key false
657put res is_resident false
658ret
659end
660if ad_str_starts q tr_p_ds
661put res provider PROV_DEEPSEEK
662put res ctx_len 64000
663put res requires_key true
664put res is_resident false
665ret
666end
667note Fallback to local resident GB10 Modular MAX seat
668put res provider PROV_LOCAL_MAX
669put res ctx_len 32768
670put res requires_key false
671put res is_resident true
672end
673
674note ---- upstream sovereign verifier (src/verifier.rs)
675
676fn ad_has_utf8_dash buf view uchar * b2 uchar to bool
677n = len buf
678if lt n 3
679ret false
680end
681lim = sub n 2
682for i ulong lim bound 4096
683if eq get buf i 0xe2
684if eq get buf add i 1 0x80
685if eq get buf add i 2 b2
686ret true
687end
688end
689end
690end
691ret false
692end
693
694fn ad_check_delimiters buf view uchar * to bool
695stk = new uchar 256 0
696sp = ulong 0
697in_str = false
698esc = false
699for i ulong len buf bound 4096
700c = get buf i
701if esc
702esc = false
703continue
704end
705if eq c 92
706esc = true
707continue
708end
709if eq c 34
710in_str = not in_str
711continue
712end
713if in_str
714continue
715end
716if or eq c 40 or eq c 91 eq c 123
717if ge sp 256
718ret false
719end
720put stk sp c
721sp = add sp 1
722end
723if eq c 41
724if eq sp 0
725ret false
726end
727sp = sub sp 1
728if ne get stk sp 40
729ret false
730end
731end
732if eq c 93
733if eq sp 0
734ret false
735end
736sp = sub sp 1
737if ne get stk sp 91
738ret false
739end
740end
741if eq c 125
742if eq sp 0
743ret false
744end
745sp = sub sp 1
746if ne get stk sp 123
747ret false
748end
749end
750end
751ret eq sp 0
752end
753
754fn ad_check_json_braces buf view uchar * to bool
755first_l = long -1
756last_r = long -1
757for i ulong len buf bound 4096
758c = get buf i
759if and eq c 123 lt first_l 0
760first_l = long i
761end
762if eq c 125
763last_r = long i
764end
765end
766if lt first_l 0
767ret true
768end
769if lt last_r first_l
770ret false
771end
772ret ad_check_delimiters buf
773end
774
775fn ad_count_cliches buf view uchar * to ulong
776hits = ulong 0
777if ad_contains_ci buf tv_b0
778hits = add hits 1
779end
780if ad_contains_ci buf tv_b1
781hits = add hits 1
782end
783if ad_contains_ci buf tv_b2
784hits = add hits 1
785end
786if ad_contains_ci buf tv_b3
787hits = add hits 1
788end
789if ad_contains_ci buf tv_b4
790hits = add hits 1
791end
792if ad_contains_ci buf tv_b5
793hits = add hits 1
794end
795if ad_contains_ci buf tv_b6
796hits = add hits 1
797end
798if ad_contains_ci buf tv_b7
799hits = add hits 1
800end
801if ad_contains_ci buf tv_b8
802hits = add hits 1
803end
804ret hits
805end
806
807fn ad_count_sycophancy buf view uchar * to ulong
808hits = ulong 0
809if ad_contains_ci buf tv_s0
810hits = add hits 1
811end
812if ad_contains_ci buf tv_s1
813hits = add hits 1
814end
815if ad_contains_ci buf tv_s2
816hits = add hits 1
817end
818if ad_contains_ci buf tv_s3
819hits = add hits 1
820end
821if ad_contains_ci buf tv_s4
822hits = add hits 1
823end
824ret hits
825end
826
827fn ad_count_secrets buf view uchar * to ulong
828hits = ulong 0
829if ad_contains_exact buf tv_k0
830hits = add hits 1
831end
832if ad_contains_exact buf tv_k1
833hits = add hits 1
834end
835if ad_contains_exact buf tv_k2
836hits = add hits 1
837end
838if ad_contains_exact buf tv_k3
839hits = add hits 1
840end
841ret hits
842end
843
844fn adapter_verify buf view uchar * strategy ulong res edit VerifRes to void
845score = f64 1.0f64
846viol = ulong 0
847crit = false
848dok = true
849if ad_has_utf8_dash buf 0x94
850viol = add viol 1
851score = sub score 0.25f64
852end
853if ad_has_utf8_dash buf 0x93
854viol = add viol 1
855score = sub score 0.15f64
856end
857hits = ad_count_cliches buf
858if gt hits 0
859viol = add viol hits
860score = sub score mul f64 hits 0.15f64
861end
862hits = ad_count_sycophancy buf
863if gt hits 0
864viol = add viol hits
865score = sub score mul f64 hits 0.20f64
866end
867hits = ad_count_secrets buf
868if gt hits 0
869viol = add viol hits
870crit = true
871score = 0.0f64
872end
873if eq strategy VERIF_COMPILER
874dok = ad_check_delimiters buf
875if not dok
876viol = add viol 1
877score = sub score 0.30f64
878end
879end
880if eq strategy VERIF_JSON
881dok = ad_check_json_braces buf
882if not dok
883viol = add viol 1
884score = sub score 0.30f64
885end
886end
887if eq strategy VERIF_UNSLOP_STRICT
888if gt viol 0
889score = fmin score 0.50f64
890end
891end
892score = fmax 0.0f64 fmin 1.0f64 score
893passed = eq viol 0
894if not passed
895if not crit
896if ge score 0.70f64
897passed = true
898end
899end
900end
901put res passed passed
902put res critical crit
903put res score score
904put res violations viol
905put res delim_ok dok
906end
907
908note ---- upstream distillation preference & Cortex commit selector (src/distill.rs)
909
910fn adapter_distill_select t_pass bool t_score f64 s_pass bool s_score f64 commit_req bool dst edit DistillDec to void
911put dst pref_delta sub t_score s_score
912if and t_pass or not s_pass ge t_score s_score
913put dst chosen CHOSEN_TEACHER
914else
915if and s_pass not t_pass
916put dst chosen CHOSEN_STUDENT
917else
918put dst chosen CHOSEN_TEACHER
919end
920end
921put dst commit_cortex and commit_req and t_pass ge t_score 0.85f64
922end