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 / aienux / crates / allen-reflex / reflex_route.om

1466 lines · 32538 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3note
4note aienux/crates/allen-reflex/reflex_route.om: ALLEN Tower & Interactive Routing in pure OM-2.
5note Library unit (no om2 header line, no fn main). Prefix: arx_.
6note Requires reflex.om before it and om/tls/sha2.om in the same concatenated unit.
7
8note =========================================================================
9note Section 13: ALLEN Tower (Scheduling Orchestrator & Mneme Digest)
10note =========================================================================
11
12const ARX_TIER_PORTABLE uchar 0
13const ARX_TIER_PI5_HOST uchar 1
14const ARX_TIER_SPARK_HOST uchar 2
15const ARX_TIER_SPARK_QEMU uchar 3
16const ARX_TIER_SPARK_GB10 uchar 4
17const ARX_TIER_SPARK_NVRM uchar 5
18
19const ARX_TW_ACT_REUSE uchar 0
20const ARX_TW_ACT_JOIN uchar 1
21const ARX_TW_ACT_PI5 uchar 2
22const ARX_TW_ACT_SPARK_HOST uchar 3
23const ARX_TW_ACT_SPARK_GPU uchar 4
24
25const ARX_TW_WHY_CACHED uchar 0
26const ARX_TW_WHY_INFLIGHT uchar 1
27const ARX_TW_WHY_PI5 uchar 2
28const ARX_TW_WHY_SPARK_HOST uchar 3
29const ARX_TW_WHY_SPARK_GPU uchar 4
30const ARX_TW_WHY_UNCACHEABLE uchar 5
31
32const ARX_TW_MAX_RCPTS ulong 64
33const ARX_TW_MAX_INF ulong 16
34const ARX_TW_GATE_STRIDE ulong 64
35
36global arx_tw_max_rcpts ulong 1
37global arx_tw_max_inf ulong 1
38global arx_tw_rcpt_n ulong 1
39global arx_tw_rcpt_gate uchar 4096
40global arx_tw_rcpt_glen ulong 64
41global arx_tw_rcpt_tier uchar 64
42global arx_tw_rcpt_din uchar 2048
43global arx_tw_rcpt_drcpt uchar 2048
44
45global arx_tw_inf_used uchar 16
46global arx_tw_inf_gate uchar 1024
47global arx_tw_inf_glen ulong 16
48global arx_tw_inf_tier uchar 16
49global arx_tw_inf_din uchar 512
50
51global arx_tw_dec_act uchar 1
52global arx_tw_dec_why uchar 1
53global arx_tw_dec_slot ulong 1
54global arx_tw_dec_rcpt uchar 32
55global arx_tw_dec_gate uchar 64
56global arx_tw_dec_glen ulong 1
57
58text arx_tw_domain "ALLEN-TOWER-INPUT-V1"
59text arx_tw_s_act0 "reuse_receipt"
60text arx_tw_s_act1 "join_inflight"
61text arx_tw_s_act2 "run_pi5_local"
62text arx_tw_s_act3 "dispatch_spark_host"
63text arx_tw_s_act4 "queue_spark_gb10"
64
65text arx_tw_s_why0 "cached_pass_receipt"
66text arx_tw_s_why1 "inflight_duplicate"
67text arx_tw_s_why2 "tier_local_pi5"
68text arx_tw_s_why3 "tier_spark_host_pool"
69text arx_tw_s_why4 "tier_spark_gpu_serial"
70text arx_tw_s_why5 "uncacheable_gate"
71
72text arx_tw_j1 "{\"tower_action\":\""
73text arx_tw_j2 "\",\"gate\":\""
74text arx_tw_j3 "\",\"why\":\""
75text arx_tw_j4 "\"}"
76text arx_hex_digits "0123456789abcdef"
77
78fn arx_combine_mneme_digest decl view uchar 32 pins view uchar 32 reads view uchar * n_reads ulong dst edit uchar 32 to void
79ctx = new ulong 40 0
80nul1 = new uchar 1 0
81cnt_le = new uchar 8 0
82sha256_init ctx
83sha256_update ctx arx_tw_domain
84sha256_update ctx nul1
85sha256_update ctx decl
86sha256_update ctx pins
87put cnt_le 0 uchar and n_reads 255
88put cnt_le 1 uchar and shr n_reads 8 255
89put cnt_le 2 uchar and shr n_reads 16 255
90put cnt_le 3 uchar and shr n_reads 24 255
91put cnt_le 4 uchar and shr n_reads 32 255
92put cnt_le 5 uchar and shr n_reads 40 255
93put cnt_le 6 uchar and shr n_reads 48 255
94put cnt_le 7 uchar and shr n_reads 56 255
95sha256_update ctx cnt_le
96i = ulong 0
97while lt i n_reads bound 64
98sha256_update ctx part reads mul i 32 32
99i = add i 1
100end
101sha256_final ctx dst
102end
103
104fn arx_tower_init max_rcpts ulong max_inf ulong to void
105mr = max_rcpts
106if gt mr ARX_TW_MAX_RCPTS
107mr = ARX_TW_MAX_RCPTS
108end
109mi = max_inf
110if gt mi ARX_TW_MAX_INF
111mi = ARX_TW_MAX_INF
112end
113put arx_tw_max_rcpts 0 mr
114put arx_tw_max_inf 0 mi
115put arx_tw_rcpt_n 0 0
116i = ulong 0
117while lt i ARX_TW_MAX_INF bound 16
118put arx_tw_inf_used i 0
119i = add i 1
120end
121end
122
123fn arx_tw_match_rcpt idx ulong gate view uchar * tier uchar din view uchar 32 to bool
124if ne get arx_tw_rcpt_tier idx tier
125ret false
126end
127gn = len gate
128if ne get arx_tw_rcpt_glen idx gn
129ret false
130end
131gb = mul idx ARX_TW_GATE_STRIDE
132i = ulong 0
133while lt i gn bound 64
134if ne get arx_tw_rcpt_gate add gb i get gate i
135ret false
136end
137i = add i 1
138end
139db = mul idx 32
140i = ulong 0
141while lt i 32 bound 32
142if ne get arx_tw_rcpt_din add db i get din i
143ret false
144end
145i = add i 1
146end
147ret true
148end
149
150fn arx_tw_match_inf idx ulong gate view uchar * tier uchar din view uchar 32 to bool
151if eq get arx_tw_inf_used idx 0
152ret false
153end
154if ne get arx_tw_inf_tier idx tier
155ret false
156end
157gn = len gate
158if ne get arx_tw_inf_glen idx gn
159ret false
160end
161gb = mul idx ARX_TW_GATE_STRIDE
162i = ulong 0
163while lt i gn bound 64
164if ne get arx_tw_inf_gate add gb i get gate i
165ret false
166end
167i = add i 1
168end
169db = mul idx 32
170i = ulong 0
171while lt i 32 bound 32
172if ne get arx_tw_inf_din add db i get din i
173ret false
174end
175i = add i 1
176end
177ret true
178end
179
180fn arx_tower_complete_inflight gate view uchar * tier uchar din view uchar 32 to bool
181mi = get arx_tw_max_inf 0
182i = ulong 0
183while lt i mi bound 16
184if arx_tw_match_inf i gate tier din
185put arx_tw_inf_used i 0
186ret true
187end
188i = add i 1
189end
190ret false
191end
192
193fn arx_tw_shift_rcpts to void
194rn = get arx_tw_rcpt_n 0
195if le rn 1
196put arx_tw_rcpt_n 0 0
197ret
198end
199i = ulong 1
200while lt i rn bound 64
201d = sub i 1
202put arx_tw_rcpt_tier d get arx_tw_rcpt_tier i
203gl = get arx_tw_rcpt_glen i
204put arx_tw_rcpt_glen d gl
205sb = mul i ARX_TW_GATE_STRIDE
206db = mul d ARX_TW_GATE_STRIDE
207k = ulong 0
208while lt k gl bound 64
209put arx_tw_rcpt_gate add db k get arx_tw_rcpt_gate add sb k
210k = add k 1
211end
212si = mul i 32
213di = mul d 32
214k = ulong 0
215while lt k 32 bound 32
216put arx_tw_rcpt_din add di k get arx_tw_rcpt_din add si k
217put arx_tw_rcpt_drcpt add di k get arx_tw_rcpt_drcpt add si k
218k = add k 1
219end
220i = add i 1
221end
222put arx_tw_rcpt_n 0 sub rn 1
223end
224
225fn arx_tw_store_rcpt_gate rn ulong gate view uchar * to void
226gn = len gate
227if gt gn ARX_TW_GATE_STRIDE
228gn = ARX_TW_GATE_STRIDE
229end
230put arx_tw_rcpt_glen rn gn
231gb = mul rn ARX_TW_GATE_STRIDE
232k = ulong 0
233while lt k gn bound 64
234put arx_tw_rcpt_gate add gb k get gate k
235k = add k 1
236end
237end
238
239fn arx_tw_store_rcpt_digs rn ulong din view uchar 32 drcpt view uchar 32 to void
240db = mul rn 32
241k = ulong 0
242while lt k 32 bound 32
243put arx_tw_rcpt_din add db k get din k
244put arx_tw_rcpt_drcpt add db k get drcpt k
245k = add k 1
246end
247end
248
249fn arx_tower_record_pass gate view uchar * tier uchar din view uchar 32 drcpt view uchar 32 to void
250ign_c = arx_tower_complete_inflight gate tier din
251rn = get arx_tw_rcpt_n 0
252i = ulong 0
253while lt i rn bound 64
254if arx_tw_match_rcpt i gate tier din
255arx_tw_store_rcpt_digs i din drcpt
256ret
257end
258i = add i 1
259end
260mr = get arx_tw_max_rcpts 0
261if eq mr 0
262ret
263end
264if ge rn mr
265arx_tw_shift_rcpts
266rn = get arx_tw_rcpt_n 0
267end
268put arx_tw_rcpt_tier rn tier
269arx_tw_store_rcpt_gate rn gate
270arx_tw_store_rcpt_digs rn din drcpt
271put arx_tw_rcpt_n 0 add rn 1
272end
273
274fn arx_tw_insert_inf gate view uchar * tier uchar din view uchar 32 to void
275gn = len gate
276if gt gn ARX_TW_GATE_STRIDE
277gn = ARX_TW_GATE_STRIDE
278end
279mi = get arx_tw_max_inf 0
280i = ulong 0
281while lt i mi bound 16
282if eq get arx_tw_inf_used i 0
283put arx_tw_inf_used i 1
284put arx_tw_inf_tier i tier
285put arx_tw_inf_glen i gn
286gb = mul i ARX_TW_GATE_STRIDE
287k = ulong 0
288while lt k gn bound 64
289put arx_tw_inf_gate add gb k get gate k
290k = add k 1
291end
292db = mul i 32
293k = ulong 0
294while lt k 32 bound 32
295put arx_tw_inf_din add db k get din k
296k = add k 1
297end
298ret
299end
300i = add i 1
301end
302end
303
304fn arx_tw_copy_dec_gate gate view uchar * to void
305gn = len gate
306if gt gn ARX_TW_GATE_STRIDE
307gn = ARX_TW_GATE_STRIDE
308end
309put arx_tw_dec_glen 0 gn
310k = ulong 0
311while lt k gn bound 64
312put arx_tw_dec_gate k get gate k
313k = add k 1
314end
315end
316
317fn arx_tw_copy_dec_rcpt idx ulong to void
318db = mul idx 32
319k = ulong 0
320while lt k 32 bound 32
321put arx_tw_dec_rcpt k get arx_tw_rcpt_drcpt add db k
322k = add k 1
323end
324end
325
326fn arx_tower_schedule gate view uchar * tier uchar din view uchar 32 cacheable bool to uchar
327arx_tw_copy_dec_gate gate
328act = ARX_TW_ACT_SPARK_GPU
329twhy = ARX_TW_WHY_SPARK_GPU
330if or eq tier ARX_TIER_PORTABLE eq tier ARX_TIER_PI5_HOST
331act = ARX_TW_ACT_PI5
332twhy = ARX_TW_WHY_PI5
333else
334if or eq tier ARX_TIER_SPARK_HOST eq tier ARX_TIER_SPARK_QEMU
335act = ARX_TW_ACT_SPARK_HOST
336twhy = ARX_TW_WHY_SPARK_HOST
337end
338end
339if not cacheable
340put arx_tw_dec_act 0 act
341put arx_tw_dec_why 0 ARX_TW_WHY_UNCACHEABLE
342ret act
343end
344rn = get arx_tw_rcpt_n 0
345i = ulong 0
346while lt i rn bound 64
347if arx_tw_match_rcpt i gate tier din
348arx_tw_copy_dec_rcpt i
349put arx_tw_dec_act 0 ARX_TW_ACT_REUSE
350put arx_tw_dec_why 0 ARX_TW_WHY_CACHED
351ret ARX_TW_ACT_REUSE
352end
353i = add i 1
354end
355mi = get arx_tw_max_inf 0
356i = ulong 0
357while lt i mi bound 16
358if arx_tw_match_inf i gate tier din
359put arx_tw_dec_act 0 ARX_TW_ACT_JOIN
360put arx_tw_dec_why 0 ARX_TW_WHY_INFLIGHT
361put arx_tw_dec_slot 0 i
362ret ARX_TW_ACT_JOIN
363end
364i = add i 1
365end
366arx_tw_insert_inf gate tier din
367put arx_tw_dec_act 0 act
368put arx_tw_dec_why 0 twhy
369ret act
370end
371
372fn arx_tw_push_escaped dst edit uchar * pos ulong src view uchar * to ulong
373p = pos
374n = len src
375i = ulong 0
376while lt i n bound 256
377c = get src i
378if eq c 34
379put dst p 92
380put dst add p 1 34
381p = add p 2
382else
383if eq c 92
384put dst p 92
385put dst add p 1 92
386p = add p 2
387else
388if eq c 10
389put dst p 92
390put dst add p 1 110
391p = add p 2
392else
393if eq c 13
394put dst p 92
395put dst add p 1 114
396p = add p 2
397else
398if eq c 9
399put dst p 92
400put dst add p 1 116
401p = add p 2
402else
403if lt c 0x20
404put dst p 92
405put dst add p 1 117
406put dst add p 2 48
407put dst add p 3 48
408put dst add p 4 get arx_hex_digits ulong shr c 4
409put dst add p 5 get arx_hex_digits ulong and c 15
410p = add p 6
411else
412put dst p c
413p = add p 1
414end
415end
416end
417end
418end
419end
420i = add i 1
421end
422ret p
423end
424
425fn arx_tower_decision_json dst edit uchar * to ulong
426gbuf = new uchar 64 0
427p = ulong 0
428p = arx_copy_bytes dst p arx_tw_j1
429act = get arx_tw_dec_act 0
430if eq act ARX_TW_ACT_REUSE
431p = arx_copy_bytes dst p arx_tw_s_act0
432else
433if eq act ARX_TW_ACT_JOIN
434p = arx_copy_bytes dst p arx_tw_s_act1
435else
436if eq act ARX_TW_ACT_PI5
437p = arx_copy_bytes dst p arx_tw_s_act2
438else
439if eq act ARX_TW_ACT_SPARK_HOST
440p = arx_copy_bytes dst p arx_tw_s_act3
441else
442p = arx_copy_bytes dst p arx_tw_s_act4
443end
444end
445end
446end
447p = arx_copy_bytes dst p arx_tw_j2
448gl = get arx_tw_dec_glen 0
449k = ulong 0
450while lt k gl bound 64
451put gbuf k get arx_tw_dec_gate k
452k = add k 1
453end
454p = arx_tw_push_escaped dst p part gbuf 0 gl
455p = arx_copy_bytes dst p arx_tw_j3
456w = get arx_tw_dec_why 0
457if eq w ARX_TW_WHY_CACHED
458p = arx_copy_bytes dst p arx_tw_s_why0
459else
460if eq w ARX_TW_WHY_INFLIGHT
461p = arx_copy_bytes dst p arx_tw_s_why1
462else
463if eq w ARX_TW_WHY_PI5
464p = arx_copy_bytes dst p arx_tw_s_why2
465else
466if eq w ARX_TW_WHY_SPARK_HOST
467p = arx_copy_bytes dst p arx_tw_s_why3
468else
469if eq w ARX_TW_WHY_SPARK_GPU
470p = arx_copy_bytes dst p arx_tw_s_why4
471else
472p = arx_copy_bytes dst p arx_tw_s_why5
473end
474end
475end
476end
477end
478p = arx_copy_bytes dst p arx_tw_j4
479ret p
480end
481
482note =========================================================================
483note Section 14: Interactive Routing (route.rs)
484note =========================================================================
485
486const ARX_INTERACTIVE_MAX ulong 512
487const ARX_PST1_HEADER ulong 224
488const ARX_PST1_PAYLOAD_MAX ulong 800
489
490const ARX_RT_LOCAL_DET uchar 0
491const ARX_RT_MEMORY uchar 1
492const ARX_RT_CLARIFY uchar 2
493const ARX_RT_REFUSE uchar 3
494const ARX_RT_LOCAL_MODEL uchar 4
495const ARX_RT_SPARK_INF uchar 5
496const ARX_RT_SPARK_OM uchar 6
497const ARX_RT_APPROVAL uchar 7
498const ARX_RT_NONE uchar 255
499
500const ARX_THEN_APPROVE uchar 0
501const ARX_THEN_DENY uchar 1
502const ARX_THEN_CANCEL uchar 2
503const ARX_THEN_REMEMBER uchar 3
504const ARX_THEN_PREFER uchar 4
505const ARX_THEN_NOTE_TASK uchar 5
506const ARX_THEN_SPARK_TASK uchar 6
507const ARX_THEN_NONE uchar 255
508
509const ARX_SPK_OWNER uchar 0
510const ARX_SPK_GUEST uchar 1
511
512const ARX_NR_STORE uchar 0
513const ARX_NR_NO_CONSENT uchar 1
514const ARX_NR_DESK uchar 2
515const ARX_NR_NO_MODEL uchar 3
516const ARX_NR_SPARK_DOWN uchar 4
517const ARX_NR_NONE uchar 255
518
519const ARX_RWHY_SCORED uchar 0
520const ARX_RWHY_EXACT uchar 1
521const ARX_RWHY_POLICY uchar 2
522const ARX_RWHY_NO_USER uchar 3
523const ARX_RWHY_TOO_LONG uchar 4
524const ARX_RWHY_NON_ASCII uchar 5
525const ARX_RWHY_NO_WORDS uchar 6
526const ARX_RWHY_CORE_CLARIFY uchar 7
527const ARX_RWHY_MISSING_SUBJ uchar 8
528const ARX_RWHY_UNFAMILIAR uchar 9
529const ARX_RWHY_UNSURE uchar 10
530const ARX_RWHY_NOTHING_PEND uchar 11
531const ARX_RWHY_MODEL_UNAVAIL uchar 12
532const ARX_RWHY_GUEST_SCOPE uchar 13
533const ARX_RWHY_OUT_OF_CAP uchar 14
534const ARX_RWHY_SPARK_CUE uchar 15
535
536note --- RouteCtx globals ---
537global arx_rctx_speaker uchar 1
538global arx_rctx_consent uchar 1
539global arx_rctx_pending uchar 1
540global arx_rctx_caps uint 1
541global arx_rctx_has_model uchar 1
542global arx_rctx_model uchar 64
543global arx_rctx_mlen ulong 1
544global arx_rctx_subj uchar 32
545global arx_rctx_min_sim f32 1
546global arx_rctx_min_margin f32 1
547
548note --- DecisionProposal output globals ---
549global arx_prop_req ulong 1
550global arx_prop_sess ulong 1
551global arx_prop_speaker uchar 1
552global arx_prop_obj uchar 32
553global arx_prop_route uchar 1
554global arx_prop_then uchar 1
555global arx_prop_not_ready uchar 1
556global arx_prop_fallback uchar 1
557global arx_prop_why uchar 1
558global arx_prop_refuse uchar 1
559global arx_prop_label uchar 1
560global arx_prop_has_txt uchar 1
561global arx_prop_txt uchar 64
562global arx_prop_tlen ulong 1
563global arx_prop_has_pst1 uchar 1
564global arx_prop_pst1 uchar 32
565
566text arx_rt_obj_dom "AIEN_E2E_OBJECTIVE_V1\n"
567text arx_rt_cause_dom "AIENOS_PST1_CAUSE_V1\n"
568text arx_rt_task_dom "AIENOS_PST1_TASK_V1\n"
569text arx_rt_idem_dom "AIENOS_PST1_IDEMPOTENCE_V1\n"
570
571text arx_rt_model_words "gpt chatgpt claude gemini llama tinyllama mistral qwen danube phi grok deepseek gemma copilot"
572text arx_rt_spark_verbs "run compile build benchmark train test verify execute measure compute"
573text arx_rt_w_spark "spark"
574text arx_rt_w_gb10 "gb10"
575
576fn arx_route_runs_without_owner r uchar to bool
577if eq r ARX_RT_LOCAL_DET
578ret true
579end
580if eq r ARX_RT_MEMORY
581ret true
582end
583if eq r ARX_RT_LOCAL_MODEL
584ret true
585end
586if eq r ARX_RT_SPARK_INF
587ret true
588end
589ret false
590end
591
592fn arx_cal_frozen mode uchar to void
593if eq mode ARX_MODE_REFLEX
594put arx_rctx_min_sim 0 0.20f32
595put arx_rctx_min_margin 0 -1.0e38f32
596else
597if eq mode ARX_MODE_NEAREST
598put arx_rctx_min_sim 0 0.35f32
599put arx_rctx_min_margin 0 -1.0e38f32
600else
601put arx_rctx_min_sim 0 -1.0f32
602put arx_rctx_min_margin 0 0.15f32
603end
604end
605end
606
607fn arx_cal_off to void
608put arx_rctx_min_sim 0 -1.0f32
609put arx_rctx_min_margin 0 -1.0e38f32
610end
611
612fn arx_rctx_set_model has_m bool name view uchar * to void
613if not has_m
614put arx_rctx_has_model 0 0
615put arx_rctx_mlen 0 0
616ret
617end
618n = len name
619if gt n 64
620n = 64
621end
622i = ulong 0
623while lt i n bound 64
624put arx_rctx_model i get name i
625i = add i 1
626end
627put arx_rctx_mlen 0 n
628put arx_rctx_has_model 0 1
629end
630
631fn arx_objective_id msg view uchar * dst edit uchar 32 to void
632ctx = new ulong 40 0
633sha256_init ctx
634sha256_update ctx arx_rt_obj_dom
635sha256_update ctx msg
636sha256_final ctx dst
637end
638
639fn arx_put_be64 dst edit uchar * off ulong v ulong to void
640put dst off uchar and shr v 56 255
641put dst add off 1 uchar and shr v 48 255
642put dst add off 2 uchar and shr v 40 255
643put dst add off 3 uchar and shr v 32 255
644put dst add off 4 uchar and shr v 24 255
645put dst add off 5 uchar and shr v 16 255
646put dst add off 6 uchar and shr v 8 255
647put dst add off 7 uchar and v 255
648end
649
650fn arx_pst1_fill_hdr subj view uchar 32 dst edit uchar * to void
651ctx = new ulong 40 0
652be8 = new uchar 8 0
653cause_id = new uchar 32 0
654tmp_h = new uchar 32 0
655sha256_init ctx
656sha256_update ctx arx_rt_cause_dom
657arx_put_be64 be8 0 get arx_prop_sess 0
658sha256_update ctx be8
659arx_put_be64 be8 0 get arx_prop_req 0
660sha256_update ctx be8
661i = ulong 0
662while lt i 32 bound 32
663put tmp_h i get arx_prop_obj i
664i = add i 1
665end
666sha256_update ctx tmp_h
667sha256_final ctx cause_id
668i = ulong 0
669while lt i ARX_PST1_HEADER bound 224
670put dst i 0
671i = add i 1
672end
673put dst 0 1
674put dst 1 1
675i = ulong 0
676while lt i 32 bound 32
677put dst add 4 i get cause_id i
678put dst add 68 i get arx_prop_obj i
679put dst add 100 i get subj i
680i = add i 1
681end
682sha256_init ctx
683sha256_update ctx arx_rt_task_dom
684sha256_update ctx cause_id
685sha256_final ctx tmp_h
686i = ulong 0
687while lt i 16 bound 16
688put dst add 148 i get tmp_h i
689i = add i 1
690end
691sha256_init ctx
692sha256_update ctx arx_rt_idem_dom
693sha256_update ctx cause_id
694sha256_final ctx tmp_h
695i = ulong 0
696while lt i 16 bound 16
697put dst add 164 i get tmp_h i
698i = add i 1
699end
700put dst 184 1
701end
702
703fn arx_pst1_request route uchar payload view uchar * subj view uchar 32 dst edit uchar * to ulong
704tmp_h = new uchar 32 0
705if not or eq route ARX_RT_SPARK_INF eq route ARX_RT_SPARK_OM
706ret 0
707end
708pn = len payload
709if gt pn ARX_PST1_PAYLOAD_MAX
710ret 0
711end
712if lt len dst add ARX_PST1_HEADER pn
713ret 0
714end
715arx_pst1_fill_hdr subj dst
716put dst 188 uchar and shr pn 8 255
717put dst 189 uchar and pn 255
718ign_h = sha2_digest 256 payload tmp_h
719i = ulong 0
720while lt i 32 bound 32
721put dst add 192 i get tmp_h i
722i = add i 1
723end
724i = ulong 0
725while lt i pn bound 800
726put dst add ARX_PST1_HEADER i get payload i
727i = add i 1
728end
729ret add ARX_PST1_HEADER pn
730end
731
732fn arx_eq_ci a view uchar * b view uchar * to bool
733na = len a
734if ne na len b
735ret false
736end
737i = ulong 0
738while lt i na bound 256
739if ne arx_to_lower get a i arx_to_lower get b i
740ret false
741end
742i = add i 1
743end
744ret true
745end
746
747fn arx_word_in_list_ci w view uchar * lst view uchar * to bool
748n = len lst
749i = ulong 0
750while lt i n bound 512
751if eq get lst i 32
752i = add i 1
753continue
754end
755ws = i
756while lt i n bound 512
757if eq get lst i 32
758break
759end
760i = add i 1
761end
762if arx_eq_ci w part lst ws sub i ws
763ret true
764end
765end
766ret false
767end
768
769fn arx_named_model_unavail msg view uchar * to bool
770im = new uchar 64 0
771has_im = ne get arx_rctx_has_model 0 0
772imlen = get arx_rctx_mlen 0
773if has_im
774k = ulong 0
775while lt k imlen bound 64
776put im k get arx_rctx_model k
777k = add k 1
778end
779end
780n = len msg
781i = ulong 0
782while lt i n bound 512
783if not arx_is_alnum get msg i
784i = add i 1
785continue
786end
787ws = i
788while lt i n bound 512
789if not arx_is_alnum get msg i
790break
791end
792i = add i 1
793end
794if arx_word_in_list_ci part msg ws sub i ws arx_rt_model_words
795if not has_im
796ret true
797end
798if not arx_eq_ci part msg ws sub i ws part im 0 imlen
799ret true
800end
801ret false
802end
803end
804ret false
805end
806
807fn arx_spark_cue msg view uchar * to bool
808has_sp = false
809has_vb = false
810n = len msg
811i = ulong 0
812while lt i n bound 512
813if not arx_is_alnum get msg i
814i = add i 1
815continue
816end
817ws = i
818while lt i n bound 512
819if not arx_is_alnum get msg i
820break
821end
822i = add i 1
823end
824if or arx_eq_ci part msg ws sub i ws arx_rt_w_spark arx_eq_ci part msg ws sub i ws arx_rt_w_gb10
825has_sp = true
826end
827if arx_word_in_list_ci part msg ws sub i ws arx_rt_spark_verbs
828has_vb = true
829end
830end
831ret and has_sp has_vb
832end
833
834fn arx_prop_reset req_id ulong sess_id ulong to void
835put arx_prop_req 0 req_id
836put arx_prop_sess 0 sess_id
837put arx_prop_speaker 0 get arx_rctx_speaker 0
838i = ulong 0
839while lt i 32 bound 32
840put arx_prop_obj i 0
841put arx_prop_pst1 i 0
842i = add i 1
843end
844put arx_prop_route 0 ARX_RT_CLARIFY
845put arx_prop_then 0 ARX_THEN_NONE
846put arx_prop_not_ready 0 ARX_NR_NONE
847put arx_prop_fallback 0 ARX_RT_NONE
848put arx_prop_why 0 ARX_RWHY_NO_USER
849put arx_prop_refuse 0 ARX_REFUSE_NONE
850put arx_prop_label 0 ARX_ACT_CLARIFY
851put arx_prop_has_txt 0 0
852put arx_prop_tlen 0 0
853put arx_prop_has_pst1 0 0
854end
855
856fn arx_propose_dispatch act uchar msg view uchar * to uchar
857owner = eq get arx_rctx_speaker 0 ARX_SPK_OWNER
858caps = get arx_rctx_caps 0
859has_cons = ne get arx_rctx_consent 0 0
860if or eq act ARX_ACT_STATUS or eq act ARX_ACT_HELP eq act ARX_ACT_EVIDENCE
861put arx_prop_route 0 ARX_RT_LOCAL_DET
862ret ARX_RT_LOCAL_DET
863end
864if eq act ARX_ACT_NONE
865put arx_prop_route 0 ARX_RT_LOCAL_DET
866put arx_prop_why 0 ARX_RWHY_OUT_OF_CAP
867ret ARX_RT_LOCAL_DET
868end
869if or eq act ARX_ACT_RECALL eq act ARX_ACT_FACTS
870if not owner
871put arx_prop_route 0 ARX_RT_REFUSE
872put arx_prop_why 0 ARX_RWHY_GUEST_SCOPE
873ret ARX_RT_REFUSE
874end
875put arx_prop_route 0 ARX_RT_MEMORY
876if not has_cons
877put arx_prop_not_ready 0 ARX_NR_NO_CONSENT
878else
879if eq and caps 1 0
880put arx_prop_not_ready 0 ARX_NR_STORE
881end
882end
883ret ARX_RT_MEMORY
884end
885if or eq act ARX_ACT_REMEMBER or eq act ARX_ACT_PREFER eq act ARX_ACT_TASK
886if not owner
887put arx_prop_route 0 ARX_RT_REFUSE
888put arx_prop_why 0 ARX_RWHY_GUEST_SCOPE
889ret ARX_RT_REFUSE
890end
891if and eq act ARX_ACT_TASK arx_spark_cue msg
892put arx_prop_route 0 ARX_RT_SPARK_OM
893put arx_prop_why 0 ARX_RWHY_SPARK_CUE
894put arx_prop_then 0 ARX_THEN_SPARK_TASK
895if eq and caps 2 0
896put arx_prop_not_ready 0 ARX_NR_DESK
897else
898if eq and caps 8 0
899put arx_prop_not_ready 0 ARX_NR_SPARK_DOWN
900end
901end
902ret ARX_RT_SPARK_OM
903end
904put arx_prop_route 0 ARX_RT_APPROVAL
905if eq act ARX_ACT_REMEMBER
906put arx_prop_then 0 ARX_THEN_REMEMBER
907else
908if eq act ARX_ACT_PREFER
909put arx_prop_then 0 ARX_THEN_PREFER
910else
911put arx_prop_then 0 ARX_THEN_NOTE_TASK
912end
913end
914if and ne act ARX_ACT_TASK not has_cons
915put arx_prop_not_ready 0 ARX_NR_NO_CONSENT
916else
917if eq and caps 2 0
918put arx_prop_not_ready 0 ARX_NR_DESK
919else
920if eq and caps 1 0
921put arx_prop_not_ready 0 ARX_NR_STORE
922end
923end
924end
925ret ARX_RT_APPROVAL
926end
927if eq act ARX_ACT_PROMPT
928if and owner arx_spark_cue msg
929put arx_prop_route 0 ARX_RT_SPARK_OM
930put arx_prop_why 0 ARX_RWHY_SPARK_CUE
931put arx_prop_then 0 ARX_THEN_SPARK_TASK
932if eq and caps 2 0
933put arx_prop_not_ready 0 ARX_NR_DESK
934else
935if eq and caps 8 0
936put arx_prop_not_ready 0 ARX_NR_SPARK_DOWN
937end
938end
939ret ARX_RT_SPARK_OM
940end
941if ne and caps 4 0
942put arx_prop_route 0 ARX_RT_LOCAL_MODEL
943ret ARX_RT_LOCAL_MODEL
944end
945put arx_prop_route 0 ARX_RT_SPARK_INF
946if eq and caps 8 0
947put arx_prop_not_ready 0 ARX_NR_SPARK_DOWN
948end
949ret ARX_RT_SPARK_INF
950end
951if or eq act ARX_ACT_APPROVE or eq act ARX_ACT_DENY eq act ARX_ACT_CANCEL
952if eq get arx_rctx_pending 0 0
953put arx_prop_route 0 ARX_RT_CLARIFY
954put arx_prop_why 0 ARX_RWHY_NOTHING_PEND
955ret ARX_RT_CLARIFY
956end
957if not owner
958put arx_prop_route 0 ARX_RT_REFUSE
959put arx_prop_why 0 ARX_RWHY_GUEST_SCOPE
960ret ARX_RT_REFUSE
961end
962put arx_prop_route 0 ARX_RT_APPROVAL
963if eq act ARX_ACT_APPROVE
964put arx_prop_then 0 ARX_THEN_APPROVE
965else
966if eq act ARX_ACT_DENY
967put arx_prop_then 0 ARX_THEN_DENY
968else
969put arx_prop_then 0 ARX_THEN_CANCEL
970end
971end
972if eq and caps 2 0
973put arx_prop_not_ready 0 ARX_NR_DESK
974end
975ret ARX_RT_APPROVAL
976end
977if eq act ARX_ACT_CLARIFY
978put arx_prop_route 0 ARX_RT_CLARIFY
979put arx_prop_why 0 ARX_RWHY_CORE_CLARIFY
980ret ARX_RT_CLARIFY
981end
982put arx_prop_route 0 ARX_RT_REFUSE
983ret ARX_RT_REFUSE
984end
985
986fn arx_propose_attach_pst1 rt uchar msg view uchar * to void
987subj = new uchar 32 0
988pst = new uchar 1024 0
989dig = new uchar 32 0
990if not or eq rt ARX_RT_SPARK_INF eq rt ARX_RT_SPARK_OM
991ret
992end
993i = ulong 0
994while lt i 32 bound 32
995put subj i get arx_rctx_subj i
996i = add i 1
997end
998plen = arx_pst1_request rt msg subj pst
999if gt plen 0
1000ign_d = sha2_digest 256 part pst 0 plen dig
1001i = ulong 0
1002while lt i 32 bound 32
1003put arx_prop_pst1 i get dig i
1004i = add i 1
1005end
1006put arx_prop_has_pst1 0 1
1007end
1008end
1009
1010fn arx_propose req_id ulong sess_id ulong to uchar
1011msg = new uchar 512 0
1012obj = new uchar 32 0
1013arx_prop_reset req_id sess_id
1014tn = get arx_turn_n 0
1015has_u = false
1016last_u = ulong 0
1017i = ulong 0
1018while lt i tn bound 32
1019if eq get arx_turn_role i ARX_ROLE_USER
1020has_u = true
1021last_u = i
1022end
1023i = add i 1
1024end
1025if not has_u
1026ret ARX_RT_CLARIFY
1027end
1028raw_n = get arx_turn_raw_len last_u
1029mlen = arx_load_turn_buf last_u msg
1030arx_objective_id part msg 0 mlen obj
1031i = ulong 0
1032while lt i 32 bound 32
1033put arx_prop_obj i get obj i
1034i = add i 1
1035end
1036if gt raw_n ARX_INTERACTIVE_MAX
1037put arx_prop_route 0 ARX_RT_REFUSE
1038put arx_prop_why 0 ARX_RWHY_TOO_LONG
1039ret ARX_RT_REFUSE
1040end
1041i = ulong 0
1042while lt i mlen bound 512
1043b = get msg i
1044if or lt b 0x20 gt b 0x7e
1045put arx_prop_route 0 ARX_RT_CLARIFY
1046put arx_prop_why 0 ARX_RWHY_NON_ASCII
1047ret ARX_RT_CLARIFY
1048end
1049i = add i 1
1050end
1051act = arx_decide
1052put arx_prop_label 0 act
1053if ne get arx_dec_has_txt 0 0
1054put arx_prop_has_txt 0 1
1055tl = get arx_dec_txt_len 0
1056put arx_prop_tlen 0 tl
1057i = ulong 0
1058while lt i tl bound 64
1059put arx_prop_txt i get arx_dec_txt i
1060i = add i 1
1061end
1062end
1063ew = get arx_exp_why 0
1064if eq ew ARX_WHY_POLICY
1065put arx_prop_route 0 ARX_RT_REFUSE
1066put arx_prop_why 0 ARX_RWHY_POLICY
1067put arx_prop_refuse 0 get arx_exp_refuse 0
1068put arx_prop_has_txt 0 0
1069ret ARX_RT_REFUSE
1070end
1071if eq ew ARX_WHY_NO_USER_TURN
1072put arx_prop_why 0 ARX_RWHY_NO_USER
1073ret ARX_RT_CLARIFY
1074end
1075if eq ew ARX_WHY_INPUT_TOO_LONG
1076put arx_prop_route 0 ARX_RT_REFUSE
1077put arx_prop_why 0 ARX_RWHY_TOO_LONG
1078ret ARX_RT_REFUSE
1079end
1080if eq ew ARX_WHY_NO_WORDS
1081put arx_prop_why 0 ARX_RWHY_NO_WORDS
1082ret ARX_RT_CLARIFY
1083end
1084if eq ew ARX_WHY_SPAN
1085put arx_prop_why 0 ARX_RWHY_MISSING_SUBJ
1086ret ARX_RT_CLARIFY
1087end
1088if ne ew ARX_WHY_EXACT_RECALL
1089if lt get arx_exp_best_sim 0 get arx_rctx_min_sim 0
1090put arx_prop_route 0 ARX_RT_CLARIFY
1091put arx_prop_why 0 ARX_RWHY_UNFAMILIAR
1092put arx_prop_has_txt 0 0
1093ret ARX_RT_CLARIFY
1094end
1095if lt get arx_exp_margin 0 get arx_rctx_min_margin 0
1096put arx_prop_route 0 ARX_RT_CLARIFY
1097put arx_prop_why 0 ARX_RWHY_UNSURE
1098put arx_prop_has_txt 0 0
1099ret ARX_RT_CLARIFY
1100end
1101end
1102if eq ew ARX_WHY_EXACT_RECALL
1103put arx_prop_why 0 ARX_RWHY_EXACT
1104else
1105put arx_prop_why 0 ARX_RWHY_SCORED
1106end
1107if arx_named_model_unavail part msg 0 mlen
1108put arx_prop_route 0 ARX_RT_CLARIFY
1109put arx_prop_why 0 ARX_RWHY_MODEL_UNAVAIL
1110put arx_prop_has_txt 0 0
1111ret ARX_RT_CLARIFY
1112end
1113rt = arx_propose_dispatch act part msg 0 mlen
1114if ne get arx_prop_not_ready 0 ARX_NR_NONE
1115put arx_prop_fallback 0 ARX_RT_LOCAL_DET
1116end
1117arx_propose_attach_pst1 rt part msg 0 mlen
1118ret rt
1119end
1120
1121text arx_p_s1 "{\"req\":"
1122text arx_p_s2 ",\"session\":"
1123text arx_p_s3 ",\"speaker\":\""
1124text arx_p_s4 "\",\"objective\":\""
1125text arx_p_s5 "\",\"route\":\""
1126text arx_p_s6 "\",\"then\":\""
1127text arx_p_s7 "\",\"ready\":\""
1128text arx_p_s8 "\",\"fallback\":\""
1129text arx_p_s9 "\",\"why\":\""
1130text arx_p_s10 "\",\"label\":\""
1131text arx_p_s11 "\",\"text\":\""
1132text arx_p_s12 "\",\"pst1\":\""
1133text arx_p_s13 "\",\"grants\":\"none\"}"
1134text arx_p_owner "owner"
1135text arx_p_guest "guest"
1136text arx_p_yes "yes"
1137text arx_p_no "no:"
1138text arx_p_dash "-"
1139
1140text arx_rt_n0 "local_deterministic"
1141text arx_rt_n1 "memory"
1142text arx_rt_n2 "clarify"
1143text arx_rt_n3 "refuse"
1144text arx_rt_n4 "local_model"
1145text arx_rt_n5 "spark_inference"
1146text arx_rt_n6 "spark_omegese"
1147text arx_rt_n7 "approval_needed"
1148
1149text arx_th_n0 "approve"
1150text arx_th_n1 "deny"
1151text arx_th_n2 "cancel"
1152text arx_th_n3 "remember"
1153text arx_th_n4 "prefer"
1154text arx_th_n5 "note_task"
1155text arx_th_n6 "spark_task"
1156
1157text arx_nr_n0 "store_absent"
1158text arx_nr_n1 "no_memory_consent"
1159text arx_nr_n2 "owner_desk_absent"
1160text arx_nr_n3 "no_local_model"
1161text arx_nr_n4 "spark_link_down"
1162
1163text arx_rw_n0 "scored"
1164text arx_rw_n1 "exact_recall"
1165text arx_rw_n2 "policy"
1166text arx_rw_n3 "no_user_turn"
1167text arx_rw_n4 "input_too_long"
1168text arx_rw_n5 "non_ascii"
1169text arx_rw_n6 "no_words"
1170text arx_rw_n7 "core_clarify"
1171text arx_rw_n8 "missing_subject"
1172text arx_rw_n9 "unfamiliar"
1173text arx_rw_n10 "unsure"
1174text arx_rw_n11 "nothing_pending"
1175text arx_rw_n12 "model_unavailable"
1176text arx_rw_n13 "guest_scope"
1177text arx_rw_n14 "out_of_capability"
1178text arx_rw_n15 "spark_cue"
1179
1180text arx_rr_n1 ":rule-break"
1181text arx_rr_n2 ":override"
1182text arx_rr_n3 ":forbidden-verb"
1183text arx_rr_n4 ":blanket-approval"
1184text arx_rr_n5 ":data-order"
1185
1186fn arx_push_u64 dst edit uchar * pos ulong val ulong to ulong
1187buf = new uchar 20 0
1188v = val
1189i = ulong 20
1190while gt i 0 bound 20
1191i = sub i 1
1192put buf i add uchar 48 uchar rem v 10
1193v = div v 10
1194if eq v 0
1195break
1196end
1197end
1198p = pos
1199while lt i 20 bound 20
1200put dst p get buf i
1201p = add p 1
1202i = add i 1
1203end
1204ret p
1205end
1206
1207fn arx_push_hex32 dst edit uchar * pos ulong src view uchar 32 to ulong
1208p = pos
1209i = ulong 0
1210while lt i 32 bound 32
1211b = get src i
1212put dst p get arx_hex_digits ulong shr b 4
1213put dst add p 1 get arx_hex_digits ulong and b 15
1214p = add p 2
1215i = add i 1
1216end
1217ret p
1218end
1219
1220fn arx_write_route_name r uchar dst edit uchar * pos ulong to ulong
1221if eq r ARX_RT_LOCAL_DET
1222ret arx_copy_bytes dst pos arx_rt_n0
1223end
1224if eq r ARX_RT_MEMORY
1225ret arx_copy_bytes dst pos arx_rt_n1
1226end
1227if eq r ARX_RT_CLARIFY
1228ret arx_copy_bytes dst pos arx_rt_n2
1229end
1230if eq r ARX_RT_REFUSE
1231ret arx_copy_bytes dst pos arx_rt_n3
1232end
1233if eq r ARX_RT_LOCAL_MODEL
1234ret arx_copy_bytes dst pos arx_rt_n4
1235end
1236if eq r ARX_RT_SPARK_INF
1237ret arx_copy_bytes dst pos arx_rt_n5
1238end
1239if eq r ARX_RT_SPARK_OM
1240ret arx_copy_bytes dst pos arx_rt_n6
1241end
1242if eq r ARX_RT_APPROVAL
1243ret arx_copy_bytes dst pos arx_rt_n7
1244end
1245ret arx_copy_bytes dst pos arx_p_dash
1246end
1247
1248fn arx_write_then_name t uchar dst edit uchar * pos ulong to ulong
1249if eq t ARX_THEN_APPROVE
1250ret arx_copy_bytes dst pos arx_th_n0
1251end
1252if eq t ARX_THEN_DENY
1253ret arx_copy_bytes dst pos arx_th_n1
1254end
1255if eq t ARX_THEN_CANCEL
1256ret arx_copy_bytes dst pos arx_th_n2
1257end
1258if eq t ARX_THEN_REMEMBER
1259ret arx_copy_bytes dst pos arx_th_n3
1260end
1261if eq t ARX_THEN_PREFER
1262ret arx_copy_bytes dst pos arx_th_n4
1263end
1264if eq t ARX_THEN_NOTE_TASK
1265ret arx_copy_bytes dst pos arx_th_n5
1266end
1267if eq t ARX_THEN_SPARK_TASK
1268ret arx_copy_bytes dst pos arx_th_n6
1269end
1270ret arx_copy_bytes dst pos arx_p_dash
1271end
1272
1273fn arx_write_rwhy_name w uchar dst edit uchar * pos ulong to ulong
1274if eq w ARX_RWHY_SCORED
1275ret arx_copy_bytes dst pos arx_rw_n0
1276end
1277if eq w ARX_RWHY_EXACT
1278ret arx_copy_bytes dst pos arx_rw_n1
1279end
1280if eq w ARX_RWHY_POLICY
1281p = arx_copy_bytes dst pos arx_rw_n2
1282rr = get arx_prop_refuse 0
1283if eq rr ARX_REFUSE_RULE_BREAK
1284ret arx_copy_bytes dst p arx_rr_n1
1285end
1286if eq rr ARX_REFUSE_OVERRIDE
1287ret arx_copy_bytes dst p arx_rr_n2
1288end
1289if eq rr ARX_REFUSE_FORBIDDEN
1290ret arx_copy_bytes dst p arx_rr_n3
1291end
1292if eq rr ARX_REFUSE_BLANKET
1293ret arx_copy_bytes dst p arx_rr_n4
1294end
1295if eq rr ARX_REFUSE_DATA_ORDER
1296ret arx_copy_bytes dst p arx_rr_n5
1297end
1298ret p
1299end
1300if eq w ARX_RWHY_NO_USER
1301ret arx_copy_bytes dst pos arx_rw_n3
1302end
1303if eq w ARX_RWHY_TOO_LONG
1304ret arx_copy_bytes dst pos arx_rw_n4
1305end
1306if eq w ARX_RWHY_NON_ASCII
1307ret arx_copy_bytes dst pos arx_rw_n5
1308end
1309if eq w ARX_RWHY_NO_WORDS
1310ret arx_copy_bytes dst pos arx_rw_n6
1311end
1312if eq w ARX_RWHY_CORE_CLARIFY
1313ret arx_copy_bytes dst pos arx_rw_n7
1314end
1315if eq w ARX_RWHY_MISSING_SUBJ
1316ret arx_copy_bytes dst pos arx_rw_n8
1317end
1318if eq w ARX_RWHY_UNFAMILIAR
1319ret arx_copy_bytes dst pos arx_rw_n9
1320end
1321if eq w ARX_RWHY_UNSURE
1322ret arx_copy_bytes dst pos arx_rw_n10
1323end
1324if eq w ARX_RWHY_NOTHING_PEND
1325ret arx_copy_bytes dst pos arx_rw_n11
1326end
1327if eq w ARX_RWHY_MODEL_UNAVAIL
1328ret arx_copy_bytes dst pos arx_rw_n12
1329end
1330if eq w ARX_RWHY_GUEST_SCOPE
1331ret arx_copy_bytes dst pos arx_rw_n13
1332end
1333if eq w ARX_RWHY_OUT_OF_CAP
1334ret arx_copy_bytes dst pos arx_rw_n14
1335end
1336ret arx_copy_bytes dst pos arx_rw_n15
1337end
1338
1339fn arx_proposal_json dst edit uchar * to ulong
1340tmp32 = new uchar 32 0
1341p = ulong 0
1342p = arx_copy_bytes dst p arx_p_s1
1343p = arx_push_u64 dst p get arx_prop_req 0
1344p = arx_copy_bytes dst p arx_p_s2
1345p = arx_push_u64 dst p get arx_prop_sess 0
1346p = arx_copy_bytes dst p arx_p_s3
1347if eq get arx_prop_speaker 0 ARX_SPK_OWNER
1348p = arx_copy_bytes dst p arx_p_owner
1349else
1350p = arx_copy_bytes dst p arx_p_guest
1351end
1352p = arx_copy_bytes dst p arx_p_s4
1353i = ulong 0
1354while lt i 32 bound 32
1355put tmp32 i get arx_prop_obj i
1356i = add i 1
1357end
1358p = arx_push_hex32 dst p tmp32
1359p = arx_copy_bytes dst p arx_p_s5
1360p = arx_write_route_name get arx_prop_route 0 dst p
1361p = arx_copy_bytes dst p arx_p_s6
1362p = arx_write_then_name get arx_prop_then 0 dst p
1363p = arx_copy_bytes dst p arx_p_s7
1364nr = get arx_prop_not_ready 0
1365if eq nr ARX_NR_NONE
1366p = arx_copy_bytes dst p arx_p_yes
1367else
1368p = arx_copy_bytes dst p arx_p_no
1369if eq nr ARX_NR_STORE
1370p = arx_copy_bytes dst p arx_nr_n0
1371else
1372if eq nr ARX_NR_NO_CONSENT
1373p = arx_copy_bytes dst p arx_nr_n1
1374else
1375if eq nr ARX_NR_DESK
1376p = arx_copy_bytes dst p arx_nr_n2
1377else
1378if eq nr ARX_NR_NO_MODEL
1379p = arx_copy_bytes dst p arx_nr_n3
1380else
1381p = arx_copy_bytes dst p arx_nr_n4
1382end
1383end
1384end
1385end
1386end
1387p = arx_copy_bytes dst p arx_p_s8
1388p = arx_write_route_name get arx_prop_fallback 0 dst p
1389p = arx_copy_bytes dst p arx_p_s9
1390p = arx_write_rwhy_name get arx_prop_why 0 dst p
1391p = arx_copy_bytes dst p arx_p_s10
1392p = arx_act_write_name get arx_prop_label 0 dst p
1393p = arx_copy_bytes dst p arx_p_s11
1394if ne get arx_prop_has_txt 0 0
1395tl = get arx_prop_tlen 0
1396i = ulong 0
1397while lt i tl bound 64
1398put dst add p i get arx_prop_txt i
1399i = add i 1
1400end
1401p = add p tl
1402end
1403p = arx_copy_bytes dst p arx_p_s12
1404if ne get arx_prop_has_pst1 0 0
1405i = ulong 0
1406while lt i 32 bound 32
1407put tmp32 i get arx_prop_pst1 i
1408i = add i 1
1409end
1410p = arx_push_hex32 dst p tmp32
1411else
1412p = arx_copy_bytes dst p arx_p_dash
1413end
1414p = arx_copy_bytes dst p arx_p_s13
1415ret p
1416end
1417
1418fn arx_hex_val c uchar to int
1419if ge c 48
1420if le c 57
1421ret int sub c 48
1422end
1423end
1424if ge c 97
1425if le c 102
1426ret add 10 int sub c 97
1427end
1428end
1429if ge c 65
1430if le c 70
1431ret add 10 int sub c 65
1432end
1433end
1434ret -1
1435end
1436
1437fn arx_pct_decode src view uchar * dst edit uchar * to long
1438n = len src
1439cap = len dst
1440i = ulong 0
1441j = ulong 0
1442while lt i n bound 4096
1443if ge j cap
1444ret -1
1445end
1446b = get src i
1447if eq b 37
1448if ge add i 2 n
1449ret -1
1450end
1451hi = arx_hex_val get src add i 1
1452lo = arx_hex_val get src add i 2
1453if or lt hi 0 lt lo 0
1454ret -1
1455end
1456put dst j uchar or shl hi 4 lo
1457j = add j 1
1458i = add i 3
1459else
1460put dst j b
1461j = add j 1
1462i = add i 1
1463end
1464end
1465ret long j
1466end