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
aien-sovereign-core-mv / om / effects / world.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Effect world check (ACCEPTANCE-v2 2.2) and reconcile record text in seeded Omega. |
| 3 | note Same bytes as aien-runtime effects::world_state (file_sha256, state_from), the reference world |
| 4 | note check, not the confined production path (confined_world_state), followed by |
| 5 | note effects::reconcile_text with no declaration and no objective; om/effects/run.sh compares them. |
| 6 | note Build: cat om/vendor/sha256.om om/effects/world.om | omc > world |
| 7 | note Usage: world TARGET CONTENT_SHA256 PRIOR_SHA256|- INTENT AUTHORIZATION BY |
| 8 | note Output: the record text, newline, sha256 of the text (append's text_sha256), newline; exit 0. |
| 9 | note Refused (exit 2, no output): argument count, arguments over 16 KiB, a target over 4095 bytes, |
| 10 | note a number Rust's u64 parse refuses, an errno with no message in em, a full buffer. |
| 11 | global ga uchar 16384 |
| 12 | global gs ulong 8 |
| 13 | global gl ulong 8 |
| 14 | global ob uchar 65536 |
| 15 | global eb uchar 8192 |
| 16 | global sb uchar 128 |
| 17 | global fb uchar 65536 |
| 18 | global dg uchar 64 |
| 19 | note wk: 0 output length, 1 error length, 2 digest present, 3 error present, 4 refused, |
| 20 | note 5 intent, 6 authorization, 7 state (0 DONE, 1 NOT_DONE, 2 UNRESOLVED). |
| 21 | global wk ulong 8 |
| 22 | text lit "{\"authorization\":~,\"by\":~,\"disk_error\":~,\"disk_sha256\":~,\"intent\":~,\"phase\":\"reconcile\",\"state\":\"~\",\"world\":\"~\"}~null~DONE~NOT_DONE~UNRESOLVED~stat ~: ~ (os error ~)~ is not a regular file~read " |
| 23 | note em: glibc strerror text for the errnos a stat, open or read of a path can give; Rust's |
| 24 | note io::Error prints "<text> (os error N)". Every entry ends in ~. |
| 25 | text em "1 Operation not permitted~2 No such file or directory~5 Input/output error~6 No such device or address~12 Cannot allocate memory~13 Permission denied~14 Bad address~20 Not a directory~21 Is a directory~23 Too many open files in system~24 Too many open files~36 File name too long~40 Too many levels of symbolic links~75 Value too large for defined data type~" |
| 26 | text hx "0123456789abcdef" |
| 27 | text nl "\n" |
| 28 | |
| 29 | note badd: append byte c to the output (d 0) or to the error message (d 1); a full buffer refuses. |
| 30 | fn badd d ulong c uchar to void |
| 31 | if eq d 0 |
| 32 | n0 = get wk 0 |
| 33 | if ge n0 len ob |
| 34 | put wk 4 1 |
| 35 | ret |
| 36 | end |
| 37 | put ob n0 c |
| 38 | put wk 0 add n0 1 |
| 39 | ret |
| 40 | end |
| 41 | n1 = get wk 1 |
| 42 | if ge n1 len eb |
| 43 | put wk 4 1 |
| 44 | ret |
| 45 | end |
| 46 | put eb n1 c |
| 47 | put wk 1 add n1 1 |
| 48 | end |
| 49 | |
| 50 | note frag: append fragment k of lit (fragments are separated by ~, byte 126) to d. |
| 51 | fn frag d ulong k ulong to void |
| 52 | c = ulong 0 |
| 53 | for i ulong len lit |
| 54 | b = get lit i |
| 55 | if eq b 126 |
| 56 | c = add c 1 |
| 57 | else |
| 58 | if eq c k |
| 59 | badd d b |
| 60 | end |
| 61 | end |
| 62 | end |
| 63 | end |
| 64 | |
| 65 | note dec: append v in decimal to d. |
| 66 | fn dec d ulong v ulong to void |
| 67 | p = ulong 1 |
| 68 | while le p div v 10 |
| 69 | p = mul p 10 |
| 70 | end |
| 71 | while ne p 0 |
| 72 | badd d uchar add div v p 48 |
| 73 | v = rem v p |
| 74 | p = div p 10 |
| 75 | end |
| 76 | end |
| 77 | |
| 78 | note esc: append byte c to the output as serde_json writes it inside a string. |
| 79 | fn esc c uchar to void |
| 80 | if or eq c 34 eq c 92 |
| 81 | badd 0 92 |
| 82 | badd 0 c |
| 83 | ret |
| 84 | end |
| 85 | if ge c 32 |
| 86 | badd 0 c |
| 87 | ret |
| 88 | end |
| 89 | badd 0 92 |
| 90 | if eq c 8 |
| 91 | badd 0 98 |
| 92 | ret |
| 93 | end |
| 94 | if eq c 12 |
| 95 | badd 0 102 |
| 96 | ret |
| 97 | end |
| 98 | if eq c 10 |
| 99 | badd 0 110 |
| 100 | ret |
| 101 | end |
| 102 | if eq c 13 |
| 103 | badd 0 114 |
| 104 | ret |
| 105 | end |
| 106 | if eq c 9 |
| 107 | badd 0 116 |
| 108 | ret |
| 109 | end |
| 110 | badd 0 117 |
| 111 | badd 0 48 |
| 112 | badd 0 48 |
| 113 | badd 0 get hx ulong shr c 4 |
| 114 | badd 0 get hx ulong and c 15 |
| 115 | end |
| 116 | |
| 117 | note sarg: append argument i to the output as a JSON string. |
| 118 | fn sarg i ulong to void |
| 119 | badd 0 34 |
| 120 | s = get gs i |
| 121 | for j ulong get gl i |
| 122 | esc get ga add s j |
| 123 | end |
| 124 | badd 0 34 |
| 125 | end |
| 126 | |
| 127 | note serr: append the error message to the output as a JSON string. |
| 128 | fn serr to void |
| 129 | badd 0 34 |
| 130 | for j ulong get wk 1 |
| 131 | esc get eb j |
| 132 | end |
| 133 | badd 0 34 |
| 134 | end |
| 135 | |
| 136 | note apath: append the target (argument 1) to the error message, as Path::display shows it. |
| 137 | fn apath to void |
| 138 | s = get gs 1 |
| 139 | for j ulong get gl 1 |
| 140 | badd 1 get ga add s j |
| 141 | end |
| 142 | end |
| 143 | |
| 144 | note emsg: append "<text> (os error e)" to the error message; an errno outside em refuses. |
| 145 | fn emsg e ulong to void |
| 146 | i = ulong 0 |
| 147 | m = len em |
| 148 | while lt i m |
| 149 | v = ulong 0 |
| 150 | while ne get em i 32 |
| 151 | v = add mul v 10 ulong sub get em i 48 |
| 152 | i = add i 1 |
| 153 | end |
| 154 | i = add i 1 |
| 155 | if eq v e |
| 156 | while ne get em i 126 |
| 157 | badd 1 get em i |
| 158 | i = add i 1 |
| 159 | end |
| 160 | frag 1 14 |
| 161 | dec 1 e |
| 162 | frag 1 15 |
| 163 | ret |
| 164 | end |
| 165 | while ne get em i 126 |
| 166 | i = add i 1 |
| 167 | end |
| 168 | i = add i 1 |
| 169 | end |
| 170 | put wk 4 1 |
| 171 | end |
| 172 | |
| 173 | note eerr: the error message "<stat |read ><target>: <text> (os error e)" (k 12 stat, 17 read). |
| 174 | fn eerr k ulong e ulong to void |
| 175 | frag 1 k |
| 176 | apath |
| 177 | frag 1 13 |
| 178 | emsg e |
| 179 | put wk 3 1 |
| 180 | end |
| 181 | |
| 182 | note hfile: sha256 of the target's bytes into dg (wk 2 = 1), or a read error. |
| 183 | fn hfile to void |
| 184 | z = long 0 |
| 185 | fd = fopen ga get gs 1 get gl 1 524288 0 |
| 186 | if lt fd 0 |
| 187 | eerr 17 ulong sub z fd |
| 188 | ret |
| 189 | end |
| 190 | hreset |
| 191 | more = true |
| 192 | while more |
| 193 | r = read int fd fb 0 len fb |
| 194 | if ne r -4 |
| 195 | if lt r 0 |
| 196 | x = fclose int fd |
| 197 | eerr 17 ulong sub z r |
| 198 | ret |
| 199 | end |
| 200 | if eq r 0 |
| 201 | more = false |
| 202 | else |
| 203 | for i ulong ulong r |
| 204 | if not hpush get fb i |
| 205 | put wk 4 1 |
| 206 | end |
| 207 | end |
| 208 | end |
| 209 | end |
| 210 | end |
| 211 | y = fclose int fd |
| 212 | if not hfinal |
| 213 | put wk 4 1 |
| 214 | ret |
| 215 | end |
| 216 | for j ulong 64 |
| 217 | put dg j get hd j |
| 218 | end |
| 219 | put wk 2 1 |
| 220 | end |
| 221 | |
| 222 | note world: effects::file_sha256. Absent (ENOENT from lstat) leaves wk 2 and wk 3 at 0; a |
| 223 | note lstat error or a target that is not a regular file is an error; else the digest. |
| 224 | note An empty target is absent: Linux answers ENOENT for it, and Omega refuses an empty path |
| 225 | note before the call (trap 3), so the kernel's answer is given here. |
| 226 | fn world to void |
| 227 | if eq get gl 1 0 |
| 228 | ret |
| 229 | end |
| 230 | z = long 0 |
| 231 | r = lstat ga get gs 1 get gl 1 sb 0 128 |
| 232 | if eq r -2 |
| 233 | ret |
| 234 | end |
| 235 | if lt r 0 |
| 236 | eerr 12 ulong sub z r |
| 237 | ret |
| 238 | end |
| 239 | m = or ulong get sb 16 shl ulong get sb 17 8 |
| 240 | if ne and m 61440 32768 |
| 241 | apath |
| 242 | frag 1 16 |
| 243 | put wk 3 1 |
| 244 | ret |
| 245 | end |
| 246 | hfile |
| 247 | end |
| 248 | |
| 249 | note pnum: argument i as a u64, as Rust's str::parse: an optional +, then at least one digit. |
| 250 | fn pnum i ulong to ulong |
| 251 | s = get gs i |
| 252 | n = get gl i |
| 253 | j = ulong 0 |
| 254 | if gt n 0 |
| 255 | if eq get ga s 43 |
| 256 | j = 1 |
| 257 | end |
| 258 | end |
| 259 | if ge j n |
| 260 | put wk 4 1 |
| 261 | ret 0 |
| 262 | end |
| 263 | mx = ulong 0 |
| 264 | mx = sub mx 1 |
| 265 | v = ulong 0 |
| 266 | while lt j n |
| 267 | c = get ga add s j |
| 268 | if or lt c 48 gt c 57 |
| 269 | put wk 4 1 |
| 270 | ret 0 |
| 271 | end |
| 272 | d = ulong sub c 48 |
| 273 | if gt v div sub mx d 10 |
| 274 | put wk 4 1 |
| 275 | ret 0 |
| 276 | end |
| 277 | v = add mul v 10 d |
| 278 | j = add j 1 |
| 279 | end |
| 280 | ret v |
| 281 | end |
| 282 | |
| 283 | note pnone: 1 when argument 3 is exactly "-" (no prior digest: the file was absent). |
| 284 | fn pnone to ulong |
| 285 | if ne get gl 3 1 |
| 286 | ret 0 |
| 287 | end |
| 288 | if ne get ga get gs 3 45 |
| 289 | ret 0 |
| 290 | end |
| 291 | ret 1 |
| 292 | end |
| 293 | |
| 294 | note dgeq: 1 when argument i equals the digest read from the target. |
| 295 | fn dgeq i ulong to ulong |
| 296 | if ne get gl i 64 |
| 297 | ret 0 |
| 298 | end |
| 299 | s = get gs i |
| 300 | for j ulong 64 |
| 301 | if ne get ga add s j get dg j |
| 302 | ret 0 |
| 303 | end |
| 304 | end |
| 305 | ret 1 |
| 306 | end |
| 307 | |
| 308 | note decide: effects::state_from. DONE when the digest is the content; NOT_DONE when the |
| 309 | note digest (or absence) is the prior; else UNRESOLVED, and always UNRESOLVED on an error. |
| 310 | fn decide to ulong |
| 311 | if eq get wk 3 1 |
| 312 | ret 2 |
| 313 | end |
| 314 | if eq get wk 2 0 |
| 315 | if eq pnone 1 |
| 316 | ret 1 |
| 317 | end |
| 318 | ret 2 |
| 319 | end |
| 320 | if eq dgeq 2 1 |
| 321 | ret 0 |
| 322 | end |
| 323 | if eq pnone 0 |
| 324 | if eq dgeq 3 1 |
| 325 | ret 1 |
| 326 | end |
| 327 | end |
| 328 | ret 2 |
| 329 | end |
| 330 | |
| 331 | note record: effects::reconcile_text, keys in serde_json's sorted order, compact. |
| 332 | fn record to void |
| 333 | frag 0 0 |
| 334 | dec 0 get wk 6 |
| 335 | frag 0 1 |
| 336 | sarg 6 |
| 337 | frag 0 2 |
| 338 | if eq get wk 3 1 |
| 339 | serr |
| 340 | else |
| 341 | frag 0 8 |
| 342 | end |
| 343 | frag 0 3 |
| 344 | if eq get wk 2 1 |
| 345 | badd 0 34 |
| 346 | for j ulong 64 |
| 347 | badd 0 get dg j |
| 348 | end |
| 349 | badd 0 34 |
| 350 | else |
| 351 | frag 0 8 |
| 352 | end |
| 353 | frag 0 4 |
| 354 | dec 0 get wk 5 |
| 355 | frag 0 5 |
| 356 | frag 0 add 9 get wk 7 |
| 357 | frag 0 6 |
| 358 | frag 0 add 9 get wk 7 |
| 359 | frag 0 7 |
| 360 | end |
| 361 | |
| 362 | note args: arguments 1..6 into ga; false when they do not fit. |
| 363 | fn args to bool |
| 364 | o = ulong 0 |
| 365 | for i ulong 7 |
| 366 | if gt i 0 |
| 367 | r = argread i ga o sub len ga o |
| 368 | if lt r 0 |
| 369 | ret false |
| 370 | end |
| 371 | put gs i o |
| 372 | put gl i ulong r |
| 373 | o = add o ulong r |
| 374 | end |
| 375 | end |
| 376 | ret true |
| 377 | end |
| 378 | |
| 379 | note wout: write the record, a newline, its sha256 and a newline. |
| 380 | fn wout to bool |
| 381 | o = ulong 0 |
| 382 | m = get wk 0 |
| 383 | while lt o m |
| 384 | w = write 1 ob o sub m o |
| 385 | if ne w -4 |
| 386 | if le w 0 |
| 387 | ret false |
| 388 | end |
| 389 | o = add o ulong w |
| 390 | end |
| 391 | end |
| 392 | if ne write 1 nl 0 1 1 |
| 393 | ret false |
| 394 | end |
| 395 | if ne write 1 hd 0 64 64 |
| 396 | ret false |
| 397 | end |
| 398 | if ne write 1 nl 0 1 1 |
| 399 | ret false |
| 400 | end |
| 401 | ret true |
| 402 | end |
| 403 | |
| 404 | fn main to int |
| 405 | if ne argcnt 7 |
| 406 | ret 2 |
| 407 | end |
| 408 | if not args |
| 409 | ret 2 |
| 410 | end |
| 411 | put wk 5 pnum 4 |
| 412 | put wk 6 pnum 5 |
| 413 | if gt get gl 1 4095 |
| 414 | ret 2 |
| 415 | end |
| 416 | world |
| 417 | if ne get wk 4 0 |
| 418 | ret 2 |
| 419 | end |
| 420 | put wk 7 decide |
| 421 | record |
| 422 | if ne get wk 4 0 |
| 423 | ret 2 |
| 424 | end |
| 425 | hreset |
| 426 | for i ulong get wk 0 |
| 427 | if not hpush get ob i |
| 428 | ret 2 |
| 429 | end |
| 430 | end |
| 431 | if not hfinal |
| 432 | ret 2 |
| 433 | end |
| 434 | if not wout |
| 435 | ret 74 |
| 436 | end |
| 437 | ret 0 |
| 438 | end |