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 / core / openclaw / main.om

194 lines · 3235 bytes Raw Blame History
1note core/openclaw/main.om: CLI entrypoint for pure-Omega openclaw agent runtime
2note Composed after si/directives/om2.om and core/openclaw/lib.om.
3note Reads line-delimited JSON tool-call envelopes on stdin, drives the deterministic
4note turn state machine, and emits JSONL turn outcomes on stdout.
5
6const CLI_IN_CAP ulong 65536
7global cli_in uchar 65536
8global cli_in_len ulong 1
9global cli_parsed_u64 ulong 1
10
11text fl_caps "--caps"
12text fl_budget "--budget"
13text fl_turns "--max-turns"
14text cli_err_io "openclaw: I/O error\n"
15text cli_err_args "openclaw: invalid or excessive CLI arguments\n"
16
17fn cli_buf_eq buf view uchar * n ulong pat view uchar * to bool
18if ne n len pat
19ret false
20end
21for i ulong n bound 64
22if ne get buf i get pat i
23ret false
24end
25end
26ret true
27end
28
29fn cli_parse_u64_ok buf view uchar * n ulong to bool
30if or eq n 0 gt n 20
31ret false
32end
33val = ulong 0
34for i ulong n bound 64
35c = get buf i
36if not and ge c 48 le c 57
37ret false
38end
39d = ulong sub c 48
40if gt val ulong 1844674407370955161
41ret false
42end
43if and eq val ulong 1844674407370955161 gt d 5
44ret false
45end
46val = add mul val 10 d
47end
48put cli_parsed_u64 0 val
49ret true
50end
51
52fn cli_read_stdin to long
53total = ulong 0
54while lt total CLI_IN_CAP bound 65536
55k = read 0 cli_in total sub CLI_IN_CAP total
56if lt k 0
57ret k
58end
59if eq k 0
60break
61end
62total = add total ulong k
63end
64put cli_in_len 0 total
65ret long total
66end
67
68fn cli_load_line ls ulong nlen ulong to void
69n = nlen
70if gt n OC_ENV_CAP
71n = OC_ENV_CAP
72end
73for i ulong n bound 4096
74put oc_env i get cli_in add ls i
75end
76put oc_env_len 0 n
77end
78
79fn cli_flag_kind buf view uchar * n ulong to ulong
80if cli_buf_eq buf n fl_caps
81ret 1
82end
83if cli_buf_eq buf n fl_budget
84ret 2
85end
86if cli_buf_eq buf n fl_turns
87ret 3
88end
89ret 0
90end
91
92fn cli_read_arg_u64 idx ulong to bool
93vbuf = new uchar 64 0
94rv = argread idx vbuf 0 64
95if le rv 0
96ret false
97end
98ret cli_parse_u64_ok vbuf ulong rv
99end
100
101fn cli_init_from_args to bool
102ac_raw = argcnt
103if or lt ac_raw 0 gt ac_raw 64
104ret false
105end
106caps = or CAP_READ CAP_WRITE
107max_t = ulong 32
108tok_b = ulong 4096
109ac = ulong ac_raw
110abuf = new uchar 64 0
111i = ulong 1
112while lt i ac bound 64
113r = argread i abuf 0 64
114if gt r 0
115fk = cli_flag_kind abuf ulong r
116if gt fk 0
117if ge add i 1 ac
118ret false
119end
120if not cli_read_arg_u64 add i 1
121ret false
122end
123if eq fk 1
124caps = get cli_parsed_u64 0
125else
126if eq fk 2
127tok_b = get cli_parsed_u64 0
128else
129max_t = get cli_parsed_u64 0
130end
131end
132i = add i 1
133end
134end
135i = add i 1
136end
137oc_session_init caps max_t tok_b max_t
138ret true
139end
140
141fn cli_process_lines to int
142total = get cli_in_len 0
143pos = ulong 0
144while lt pos total bound 65536
145ls = pos
146while lt pos total bound 65536
147if eq get cli_in pos 10
148break
149end
150pos = add pos 1
151end
152le_p = pos
153if gt le_p ls
154if eq get cli_in sub le_p 1 13
155le_p = sub le_p 1
156end
157end
158if gt le_p ls
159cli_load_line ls sub le_p ls
160st = oc_run_turn
161if gt st ST_REFUSED
162ret 2
163end
164olen = oc_format_turn_jsonl
165ok = oc_write_out 1 olen
166if not ok
167ret 2
168end
169end
170if lt pos total
171pos = add pos 1
172end
173end
174ret 0
175end
176
177fn main to int
178if not cli_init_from_args
179ea = write 2 cli_err_args 0 len cli_err_args
180if lt ea 0
181ret 2
182end
183ret 2
184end
185got = cli_read_stdin
186if lt got 0
187ew = write 2 cli_err_io 0 len cli_err_io
188if lt ew 0
189ret 2
190end
191ret 2
192end
193ret cli_process_lines
194end