interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / om / serve / cli.om

234 lines · 4619 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note core/sovereign-core/om/serve/cli.om
3note Pure OM-2 conversion of aien-cli subcommand & flag dispatcher.
4note Parses subcommands (serve, chat, models, health, version) and validates flags
5note (--port 1..65535, --max-tokens 1..4096, --model NAME) fail-closed.
6
7const CLI_OK ulong 0
8const CLI_ERR_EMPTY ulong 1
9const CLI_ERR_UNKNOWN_CMD ulong 2
10const CLI_ERR_UNKNOWN_FLAG ulong 3
11const CLI_ERR_MISSING_VAL ulong 4
12const CLI_ERR_BAD_PORT ulong 5
13const CLI_ERR_BAD_MAX_TOKENS ulong 6
14const CLI_ERR_MISSING_MODEL ulong 7
15const CLI_ERR_DUP_FLAG ulong 8
16const CLI_ERR_TOO_MANY_ARGS ulong 9
17
18const CLI_CMD_NONE ulong 0
19const CLI_CMD_SERVE ulong 1
20const CLI_CMD_CHAT ulong 2
21const CLI_CMD_MODELS ulong 3
22const CLI_CMD_HEALTH ulong 4
23const CLI_CMD_VERSION ulong 5
24
25note Parsed CLI state:
26note [0]=cmd, [1]=port, [2]=max_tokens, [3]=has_port, [4]=has_max_tokens, [5]=has_model, [6]=model_len, [7]=argc
27global cli_state ulong 8
28global cli_model uchar 64
29global cli_arg_off ulong 16
30global cli_arg_len ulong 16
31
32text cli_s_serve "serve"
33text cli_s_chat "chat"
34text cli_s_models "models"
35text cli_s_health "health"
36text cli_s_version "version"
37text cli_f_port "--port"
38text cli_f_maxt "--max-tokens"
39text cli_f_model "--model"
40
41fn cli_reset to void
42for i ulong 8
43put cli_state i 0
44end
45put cli_state 1 8080
46put cli_state 2 512
47for i ulong 64
48put cli_model i uchar 0
49end
50for i ulong 16
51put cli_arg_off i 0
52put cli_arg_len i 0
53end
54end
55
56fn cli_cmd to ulong
57ret get cli_state 0
58end
59
60fn cli_port to ulong
61ret get cli_state 1
62end
63
64fn cli_max_tokens to ulong
65ret get cli_state 2
66end
67
68fn cli_model_len to ulong
69ret get cli_state 6
70end
71
72fn cli_tok_eq line view uchar * idx ulong lit view uchar * to bool
73off = get cli_arg_off idx
74tlen = get cli_arg_len idx
75if ne tlen len lit
76ret false
77end
78for i ulong tlen bound 64
79if ne get line add off i get lit i
80ret false
81end
82end
83ret true
84end
85
86fn cli_tok_u64 line view uchar * idx ulong to ulong
87off = get cli_arg_off idx
88tlen = get cli_arg_len idx
89if or eq tlen 0 gt tlen 10
90ret 18446744073709551615
91end
92acc = ulong 0
93for i ulong tlen bound 16
94b = get line add off i
95if or lt b uchar 48 gt b uchar 57
96ret 18446744073709551615
97end
98acc = add mul acc 10 ulong sub b uchar 48
99end
100ret acc
101end
102
103note Split whitespace-delimited arguments into cli_arg_off / cli_arg_len.
104fn cli_tokenize line view uchar * to ulong
105n = len line
106argc = ulong 0
107i = ulong 0
108while lt i n bound 512
109while lt i n bound 512
110b = get line i
111if or eq b uchar 32 eq b uchar 9
112i = add i 1
113else
114break
115end
116end
117if ge i n
118break
119end
120if ge argc 16
121ret CLI_ERR_TOO_MANY_ARGS
122end
123start = i
124while lt i n bound 512
125b = get line i
126if or eq b uchar 32 eq b uchar 9
127break
128end
129i = add i 1
130end
131put cli_arg_off argc start
132put cli_arg_len argc sub i start
133argc = add argc 1
134end
135put cli_state 7 argc
136ret CLI_OK
137end
138
139note Parse and validate a CLI command line fail-closed.
140fn cli_dispatch line view uchar * to ulong
141cli_reset
142tst = cli_tokenize line
143if ne tst CLI_OK
144ret tst
145end
146argc = get cli_state 7
147if eq argc 0
148ret CLI_ERR_EMPTY
149end
150cmd = CLI_CMD_NONE
151if cli_tok_eq line 0 cli_s_serve
152cmd = CLI_CMD_SERVE
153else
154if cli_tok_eq line 0 cli_s_chat
155cmd = CLI_CMD_CHAT
156else
157if cli_tok_eq line 0 cli_s_models
158cmd = CLI_CMD_MODELS
159else
160if cli_tok_eq line 0 cli_s_health
161cmd = CLI_CMD_HEALTH
162else
163if cli_tok_eq line 0 cli_s_version
164cmd = CLI_CMD_VERSION
165end
166end
167end
168end
169end
170if eq cmd CLI_CMD_NONE
171ret CLI_ERR_UNKNOWN_CMD
172end
173put cli_state 0 cmd
174idx = ulong 1
175while lt idx argc bound 16
176if cli_tok_eq line idx cli_f_port
177if ne get cli_state 3 0
178ret CLI_ERR_DUP_FLAG
179end
180if ge add idx 1 argc
181ret CLI_ERR_MISSING_VAL
182end
183p = cli_tok_u64 line add idx 1
184if or eq p 0 or gt p 65535 eq p 18446744073709551615
185ret CLI_ERR_BAD_PORT
186end
187put cli_state 1 p
188put cli_state 3 1
189idx = add idx 2
190continue
191end
192if cli_tok_eq line idx cli_f_maxt
193if ne get cli_state 4 0
194ret CLI_ERR_DUP_FLAG
195end
196if ge add idx 1 argc
197ret CLI_ERR_MISSING_VAL
198end
199mt = cli_tok_u64 line add idx 1
200if or eq mt 0 or gt mt 4096 eq mt 18446744073709551615
201ret CLI_ERR_BAD_MAX_TOKENS
202end
203put cli_state 2 mt
204put cli_state 4 1
205idx = add idx 2
206continue
207end
208if cli_tok_eq line idx cli_f_model
209if ne get cli_state 5 0
210ret CLI_ERR_DUP_FLAG
211end
212if ge add idx 1 argc
213ret CLI_ERR_MISSING_VAL
214end
215moff = get cli_arg_off add idx 1
216mlen = get cli_arg_len add idx 1
217if or eq mlen 0 gt mlen 64
218ret CLI_ERR_MISSING_MODEL
219end
220for k ulong mlen bound 64
221put cli_model k get line add moff k
222end
223put cli_state 5 1
224put cli_state 6 mlen
225idx = add idx 2
226continue
227end
228ret CLI_ERR_UNKNOWN_FLAG
229end
230if and eq cmd CLI_CMD_CHAT eq get cli_state 5 0
231ret CLI_ERR_MISSING_MODEL
232end
233ret CLI_OK
234end