omega-harness
Agent skills for operating, encoding and communicating in Omega (.om) and the AIEN repositories
Brought by drakestapleton
omega-harness / tools / rules.om
| 1 | om2 |
| 2 | note rules: the agents' standing rules, from one rules source plus one machine's overlay. |
| 3 | note |
| 4 | note rules lint SRC [OVL] check both files; a line of the public SRC may not hold `~/`, `$HOME`, |
| 5 | note `/home/`, `/Users/`, `/root/`, `/srv/`, `/var/`, `/etc/`, `127.0.0.1`, |
| 6 | note the host name `spark` (lowercase) or a private repository name |
| 7 | note (`omega-pearl`, `aien-crypto`), Linear URLs or DRA issue IDs: those go in the overlay |
| 8 | note rules render SRC OVL PROG HEAD [PATH] the instruction file for PROG, on stdout |
| 9 | note rules targets SRC OVL `target PROG PATH`, `skills - DIR` and `alarm - FILE` lines |
| 10 | note rules fit SRC OVL HEAD for each OVL `cap CHARS PATH`: render the target with that PATH and count |
| 11 | note its characters (UTF-8 code points, as a reader that decodes the file |
| 12 | note counts them); prints `fit PROG PATH N of CHARS ok|OVER`; exit 1 when |
| 13 | note a render is over its cap or a cap names no target |
| 14 | note |
| 15 | note SRC is rules/rules.txt; OVL is the overlay, kept on one machine and never published. Both have one |
| 16 | note format, one record per line group: |
| 17 | note rule ID begins a rule; ID is lowercase letters, digits and `-`, unique over both files |
| 18 | note date YYYY-MM-DD the date of the statement the rule rests on |
| 19 | note said TEXT Drake's exact words, when they exist (any number of lines; kept, not rendered) |
| 20 | note for P ... the programs it applies to: claude, codex, agents, omp, watchdog, generic; `all` |
| 21 | note includes claude, codex, agents and omp. A generic reader gets agents and generic |
| 22 | note rules. If its configured cap is exceeded and an agents target is available, it |
| 23 | note gets the rules marked generic plus directions to the full agents file. |
| 24 | note order N where it goes in every file it is rendered into (ascending; ties keep SRC |
| 25 | note before OVL, then file order) |
| 26 | note | TEXT or | one line of the rendered rule, or an empty one |
| 27 | note end ends the rule |
| 28 | note Outside a rule, a line is empty, a comment (`#`), or, in OVL only, `target PROG PATH` (PROG's |
| 29 | note instruction file on this machine), `skills DIR` (an installed skills directory), `alarm FILE` |
| 30 | note (where a failed install is reported) or `cap CHARS PATH` (the most characters the reader of the |
| 31 | note target PATH keeps; `fit` and tools/install.sh refuse a render over it). A rendered file is a header |
| 32 | note naming HEAD (the last commit that changed the rules) and each rule for PROG in order, separated by an |
| 33 | note empty line. Same inputs, same bytes. Exit 0 done, 1 lint findings or a render over its cap, 2 usage, |
| 34 | note read error or a malformed file. |
| 35 | |
| 36 | global rb uchar 16777216 |
| 37 | global obuf uchar 16777216 |
| 38 | global ab uchar 4096 |
| 39 | global hd uchar 128 |
| 40 | global nb uchar 32 |
| 41 | global rs ulong 65536 |
| 42 | global re ulong 65536 |
| 43 | global ro ulong 65536 |
| 44 | global rm ulong 65536 |
| 45 | global rk ulong 65536 |
| 46 | global dn uchar 65536 |
| 47 | global st ulong 32 |
| 48 | |
| 49 | const capb ulong 16777216 |
| 50 | const capr ulong 65536 |
| 51 | const s_n ulong 0 |
| 52 | const s_ns ulong 1 |
| 53 | const s_on ulong 2 |
| 54 | const s_nr ulong 3 |
| 55 | const s_bad ulong 4 |
| 56 | const s_ln ulong 5 |
| 57 | const s_hl ulong 6 |
| 58 | const s_ls ulong 7 |
| 59 | const s_le ulong 8 |
| 60 | const s_al ulong 9 |
| 61 | note allm preserves the shared rules for claude, codex, agents and omp. |
| 62 | const allm ulong 15 |
| 63 | const genm ulong 32 |
| 64 | |
| 65 | text a_lint "lint" |
| 66 | text a_render "render" |
| 67 | text a_tgts "targets" |
| 68 | text a_fit "fit" |
| 69 | text p_claude "claude" |
| 70 | text p_codex "codex" |
| 71 | text p_agents "agents" |
| 72 | text p_omp "omp" |
| 73 | text p_watch "watchdog" |
| 74 | text p_gen "generic" |
| 75 | text p_all "all" |
| 76 | text w_rule "rule " |
| 77 | text w_date "date " |
| 78 | text w_said "said " |
| 79 | text w_for "for " |
| 80 | text w_order "order " |
| 81 | text w_end "end" |
| 82 | text w_bar "|" |
| 83 | text w_target "target " |
| 84 | text w_skills "skills " |
| 85 | text w_alarm "alarm " |
| 86 | text w_cap "cap " |
| 87 | text k_home "~/" |
| 88 | text k_home2 "/home/" |
| 89 | text k_users "/Users/" |
| 90 | text k_srv "/srv/" |
| 91 | text k_spark "spark" |
| 92 | text k_pearl "omega-pearl" |
| 93 | text k_crypto "aien-crypto" |
| 94 | text k_local "127.0.0.1" |
| 95 | text k_dhome "$HOME" |
| 96 | text k_root "/root/" |
| 97 | text k_var "/var/" |
| 98 | text k_etc "/etc/" |
| 99 | text k_linear "linear.app/" |
| 100 | text k_issue "DRA-" |
| 101 | text m_use "usage: rules lint SRC [OVL] | rules render SRC OVL PROG HEAD [PATH] | rules targets SRC OVL | rules fit SRC OVL HEAD\n" |
| 102 | text m_read "rules: cannot read " |
| 103 | text m_full "rules: refused, the rules files fill the 16777216-byte buffer\n" |
| 104 | text m_many "rules: refused, more than 65536 rules\n" |
| 105 | text m_alarm "rules: alarm: the rules files are over half of the 16777216-byte buffer\n" |
| 106 | text m_prog "rules: unknown program: " |
| 107 | text f_line ": " |
| 108 | text f_src "SRC" |
| 109 | text f_ovl "OVL" |
| 110 | text f_out "outside a rule, expected rule, a comment or an empty line (OVL also target, skills, alarm or cap)" |
| 111 | text f_in "inside a rule, expected date, said, for, order, | or end" |
| 112 | text f_noid "a rule ID is lowercase letters, digits and -" |
| 113 | text f_dup "the rule ID is used twice" |
| 114 | text f_nodate "the rule has no date YYYY-MM-DD" |
| 115 | text f_nofor "the rule has no for line, or names an unknown program" |
| 116 | text f_noord "the rule has no order N" |
| 117 | text f_notext "the rule has no | line" |
| 118 | text f_open "the file ends inside a rule" |
| 119 | text f_priv "the public rules source holds a home path, host path, host name or private name; move it to the overlay" |
| 120 | text f_tgt "a target line is `target PROG PATH`: one program (claude, codex, agents, omp, watchdog or generic), one space, and a path" |
| 121 | text f_cap "a cap line is `cap CHARS PATH`: 1 to 18 digits, one space, and a path" |
| 122 | text t_fit "fit " |
| 123 | text t_of " of " |
| 124 | text t_ok " ok\n" |
| 125 | text t_over " OVER\n" |
| 126 | text t_notgt "fit: no target line for the cap path " |
| 127 | text f_rule " rule " |
| 128 | text f_rules " rules, " |
| 129 | text f_tg "findings\n" |
| 130 | text m_lint "rules: " |
| 131 | text h_1 "<!-- Generated for " |
| 132 | text h_2 " by omega-harness tools/rules.om from rules/rules.txt at " |
| 133 | text h_3 " and this machine's overlay. Do not edit this file: change the rules source and land it, or change the overlay, then run tools/install.sh. -->\n" |
| 134 | text nl "\n" |
| 135 | text sp " " |
| 136 | text dash "- " |
| 137 | text g_1 "\n## Additional standing rules\nRead the full agent instructions at the following location before doing project work:\n" |
| 138 | text m_dup_target "more than one target uses the same path" |
| 139 | text m_path "rules: path is not configured for this program\n" |
| 140 | text m_over "rules: requested render exceeds its configured cap\n" |
| 141 | |
| 142 | note ---------------------------------------------------------------- output |
| 143 | |
| 144 | fn wfd fd int t view uchar * to void |
| 145 | n = len t |
| 146 | p = ulong 0 |
| 147 | while lt p n bound 4096 |
| 148 | k = write fd t p sub n p |
| 149 | if le k 0 |
| 150 | exit 2 |
| 151 | end |
| 152 | p = add p ulong k |
| 153 | end |
| 154 | end |
| 155 | |
| 156 | fn wnum fd int v ulong to void |
| 157 | i = ulong 32 |
| 158 | n = v |
| 159 | while true bound 21 |
| 160 | i = sub i 1 |
| 161 | put nb i uchar add rem n 10 48 |
| 162 | n = div n 10 |
| 163 | if eq n 0 |
| 164 | break |
| 165 | end |
| 166 | end |
| 167 | while lt i 32 bound 32 |
| 168 | k = write fd nb i sub 32 i |
| 169 | if le k 0 |
| 170 | exit 2 |
| 171 | end |
| 172 | i = add i ulong k |
| 173 | end |
| 174 | end |
| 175 | |
| 176 | fn wrb fd int a ulong b ulong to void |
| 177 | p = a |
| 178 | while lt p b bound 16777216 |
| 179 | k = write fd rb p sub b p |
| 180 | if le k 0 |
| 181 | exit 2 |
| 182 | end |
| 183 | p = add p ulong k |
| 184 | end |
| 185 | end |
| 186 | |
| 187 | fn o c uchar to void |
| 188 | n = get st s_on |
| 189 | if eq n capb |
| 190 | wfd 2 m_full |
| 191 | exit 2 |
| 192 | end |
| 193 | put obuf n c |
| 194 | put st s_on add n 1 |
| 195 | end |
| 196 | |
| 197 | fn ot t view uchar * to void |
| 198 | for i ulong len t bound 4096 |
| 199 | o get t i |
| 200 | end |
| 201 | end |
| 202 | |
| 203 | fn orb a ulong b ulong to void |
| 204 | i = a |
| 205 | while lt i b bound 16777216 |
| 206 | o get rb i |
| 207 | i = add i 1 |
| 208 | end |
| 209 | end |
| 210 | |
| 211 | fn flush to void |
| 212 | n = get st s_on |
| 213 | p = ulong 0 |
| 214 | while lt p n bound 16777216 |
| 215 | k = write 1 obuf p sub n p |
| 216 | if le k 0 |
| 217 | exit 2 |
| 218 | end |
| 219 | p = add p ulong k |
| 220 | end |
| 221 | put st s_on 0 |
| 222 | end |
| 223 | |
| 224 | note ---------------------------------------------------------------- input |
| 225 | |
| 226 | note ldarg: argument i into ab; its length, or a refusal |
| 227 | fn ldarg i ulong to ulong |
| 228 | k = argread i ab 0 4096 |
| 229 | if lt k 0 |
| 230 | wfd 2 m_use |
| 231 | exit 2 |
| 232 | end |
| 233 | ret ulong k |
| 234 | end |
| 235 | |
| 236 | fn argis t view uchar * k ulong to bool |
| 237 | if ne k len t |
| 238 | ret false |
| 239 | end |
| 240 | for i ulong k bound 4096 |
| 241 | if ne get ab i get t i |
| 242 | ret false |
| 243 | end |
| 244 | end |
| 245 | ret true |
| 246 | end |
| 247 | |
| 248 | note ldfile: the file named by argument i, appended to rb |
| 249 | fn ldfile i ulong to void |
| 250 | m = ldarg i |
| 251 | f = fopen ab 0 m 0 0 |
| 252 | if lt f 0 |
| 253 | wfd 2 m_read |
| 254 | z = write 2 ab 0 m |
| 255 | wfd 2 nl |
| 256 | exit 2 |
| 257 | end |
| 258 | n = get st s_n |
| 259 | while true bound 16777217 |
| 260 | if eq n capb |
| 261 | wfd 2 m_full |
| 262 | exit 2 |
| 263 | end |
| 264 | k = read int f rb n sub capb n |
| 265 | if lt k 0 |
| 266 | wfd 2 m_read |
| 267 | y = write 2 ab 0 m |
| 268 | wfd 2 nl |
| 269 | exit 2 |
| 270 | end |
| 271 | if eq k 0 |
| 272 | break |
| 273 | end |
| 274 | n = add n ulong k |
| 275 | end |
| 276 | z = fclose int f |
| 277 | if gt n 0 |
| 278 | if ne get rb sub n 1 10 |
| 279 | if eq n capb |
| 280 | wfd 2 m_full |
| 281 | exit 2 |
| 282 | end |
| 283 | put rb n 10 |
| 284 | n = add n 1 |
| 285 | end |
| 286 | end |
| 287 | put st s_n n |
| 288 | end |
| 289 | |
| 290 | note ---------------------------------------------------------------- lines |
| 291 | |
| 292 | fn lend p ulong to ulong |
| 293 | n = get st s_n |
| 294 | q = p |
| 295 | while lt q n bound 16777216 |
| 296 | if eq get rb q 10 |
| 297 | ret q |
| 298 | end |
| 299 | q = add q 1 |
| 300 | end |
| 301 | ret n |
| 302 | end |
| 303 | |
| 304 | note lpre: the line [p, e) begins with t |
| 305 | fn lpre p ulong e ulong t view uchar * to bool |
| 306 | n = len t |
| 307 | if lt sub e p n |
| 308 | ret false |
| 309 | end |
| 310 | for i ulong n bound 64 |
| 311 | if ne get rb add p i get t i |
| 312 | ret false |
| 313 | end |
| 314 | end |
| 315 | ret true |
| 316 | end |
| 317 | |
| 318 | fn lis p ulong e ulong t view uchar * to bool |
| 319 | if ne sub e p len t |
| 320 | ret false |
| 321 | end |
| 322 | ret lpre p e t |
| 323 | end |
| 324 | |
| 325 | note has: rb[a, b) holds t |
| 326 | fn has a ulong b ulong t view uchar * to bool |
| 327 | n = len t |
| 328 | if lt sub b a n |
| 329 | ret false |
| 330 | end |
| 331 | m = sub b n |
| 332 | i = a |
| 333 | while le i m bound 16777216 |
| 334 | same = true |
| 335 | for j ulong n bound 64 |
| 336 | if ne get rb add i j get t j |
| 337 | same = false |
| 338 | break |
| 339 | end |
| 340 | end |
| 341 | if same |
| 342 | ret true |
| 343 | end |
| 344 | i = add i 1 |
| 345 | end |
| 346 | ret false |
| 347 | end |
| 348 | |
| 349 | fn isdig c uchar to bool |
| 350 | ret and ge c 48 le c 57 |
| 351 | end |
| 352 | |
| 353 | fn isid c uchar to bool |
| 354 | if isdig c |
| 355 | ret true |
| 356 | end |
| 357 | if and ge c 97 le c 122 |
| 358 | ret true |
| 359 | end |
| 360 | ret eq c 45 |
| 361 | end |
| 362 | |
| 363 | note word: the program word rb[a, b) as a bit (claude 1, codex 2, agents 4, omp 8, watchdog 16, generic 32, all 15), else 0 |
| 364 | fn wbit a ulong b ulong to ulong |
| 365 | m = sub b a |
| 366 | if lis a b p_claude |
| 367 | ret 1 |
| 368 | end |
| 369 | if lis a b p_codex |
| 370 | ret 2 |
| 371 | end |
| 372 | if lis a b p_agents |
| 373 | ret 4 |
| 374 | end |
| 375 | if lis a b p_omp |
| 376 | ret 8 |
| 377 | end |
| 378 | if lis a b p_watch |
| 379 | ret 16 |
| 380 | end |
| 381 | if lis a b p_all |
| 382 | ret allm |
| 383 | end |
| 384 | if lis a b p_gen |
| 385 | ret genm |
| 386 | end |
| 387 | ret 0 |
| 388 | end |
| 389 | |
| 390 | note forbits: the programs of a `for` line [p, e); 0 when one word is unknown |
| 391 | fn forbits p ulong e ulong to ulong |
| 392 | m = ulong 0 |
| 393 | i = add p len w_for |
| 394 | while lt i e bound 4096 |
| 395 | while lt i e bound 4096 |
| 396 | if ne get rb i 32 |
| 397 | break |
| 398 | end |
| 399 | i = add i 1 |
| 400 | end |
| 401 | if ge i e |
| 402 | break |
| 403 | end |
| 404 | j = i |
| 405 | while lt j e bound 4096 |
| 406 | if eq get rb j 32 |
| 407 | break |
| 408 | end |
| 409 | j = add j 1 |
| 410 | end |
| 411 | b = wbit i j |
| 412 | if eq b 0 |
| 413 | ret 0 |
| 414 | end |
| 415 | m = or m b |
| 416 | i = j |
| 417 | end |
| 418 | ret m |
| 419 | end |
| 420 | |
| 421 | note pnum: the decimal rb[a, b) of 1 to 18 digits; the largest ulong (no order) for anything else |
| 422 | fn pnum a ulong b ulong to ulong |
| 423 | v = ulong 0 |
| 424 | i = a |
| 425 | if or eq a b gt sub b a 18 |
| 426 | ret 18446744073709551615 |
| 427 | end |
| 428 | while lt i b bound 18 |
| 429 | c = get rb i |
| 430 | if not isdig c |
| 431 | ret 18446744073709551615 |
| 432 | end |
| 433 | v = add mul v 10 ulong sub c 48 |
| 434 | i = add i 1 |
| 435 | end |
| 436 | ret v |
| 437 | end |
| 438 | |
| 439 | fn dig2 a ulong to ulong |
| 440 | ret add mul ulong sub get rb a 48 10 ulong sub get rb add a 1 48 |
| 441 | end |
| 442 | |
| 443 | note isdate: rb[a, b) is YYYY-MM-DD with a month 01..12 and a day 01..31 |
| 444 | fn isdate a ulong b ulong to bool |
| 445 | if ne sub b a 10 |
| 446 | ret false |
| 447 | end |
| 448 | for i ulong 10 |
| 449 | c = get rb add a i |
| 450 | if or eq i 4 eq i 7 |
| 451 | if ne c 45 |
| 452 | ret false |
| 453 | end |
| 454 | else |
| 455 | if not isdig c |
| 456 | ret false |
| 457 | end |
| 458 | end |
| 459 | end |
| 460 | m = dig2 add a 5 |
| 461 | d = dig2 add a 8 |
| 462 | if or lt m 1 gt m 12 |
| 463 | ret false |
| 464 | end |
| 465 | ret and ge d 1 le d 31 |
| 466 | end |
| 467 | |
| 468 | note ---------------------------------------------------------------- parse |
| 469 | |
| 470 | note fnd: a lint finding at line s_ln of SRC or OVL |
| 471 | fn fnd ovl bool m view uchar * to void |
| 472 | if ovl |
| 473 | wfd 1 f_ovl |
| 474 | else |
| 475 | wfd 1 f_src |
| 476 | end |
| 477 | wfd 1 f_line |
| 478 | wnum 1 get st s_ln |
| 479 | wfd 1 f_line |
| 480 | wfd 1 m |
| 481 | wfd 1 nl |
| 482 | put st s_bad add get st s_bad 1 |
| 483 | end |
| 484 | |
| 485 | fn ideq a ulong b ulong c ulong d ulong to bool |
| 486 | if ne sub b a sub d c |
| 487 | ret false |
| 488 | end |
| 489 | k = sub b a |
| 490 | for i ulong k bound 4096 |
| 491 | if ne get rb add a i get rb add c i |
| 492 | ret false |
| 493 | end |
| 494 | end |
| 495 | ret true |
| 496 | end |
| 497 | |
| 498 | note newrule: the rule line [p, e) at index r; its ID must be well formed and new |
| 499 | fn newrule p ulong e ulong r ulong ovl bool to void |
| 500 | if eq r capr |
| 501 | wfd 2 m_many |
| 502 | exit 2 |
| 503 | end |
| 504 | a = add p len w_rule |
| 505 | if eq a e |
| 506 | fnd ovl f_noid |
| 507 | end |
| 508 | i = a |
| 509 | while lt i e bound 4096 |
| 510 | if not isid get rb i |
| 511 | fnd ovl f_noid |
| 512 | break |
| 513 | end |
| 514 | i = add i 1 |
| 515 | end |
| 516 | for j ulong r bound 65536 |
| 517 | s = get rs j |
| 518 | if ideq a e add s len w_rule lend s |
| 519 | fnd ovl f_dup |
| 520 | end |
| 521 | end |
| 522 | put rs r p |
| 523 | put ro r 18446744073709551615 |
| 524 | put rm r 0 |
| 525 | put rk r 0 |
| 526 | put dn r 0 |
| 527 | if ovl |
| 528 | put rk r 1 |
| 529 | end |
| 530 | end |
| 531 | |
| 532 | note parse: every line of rb; the rules into rs, re, ro, rm, rk (0 SRC, 1 OVL) |
| 533 | fn parse to void |
| 534 | n = get st s_n |
| 535 | ns = get st s_ns |
| 536 | r = ulong 0 |
| 537 | inr = false |
| 538 | txt = false |
| 539 | p = ulong 0 |
| 540 | while lt p n bound 16777216 |
| 541 | if eq p ns |
| 542 | if inr |
| 543 | put st s_ln 0 |
| 544 | fnd false f_open |
| 545 | inr = false |
| 546 | end |
| 547 | put st s_ln 0 |
| 548 | end |
| 549 | ovl = ge p ns |
| 550 | e = lend p |
| 551 | put st s_ln add get st s_ln 1 |
| 552 | if inr |
| 553 | txt = line p e r ovl txt |
| 554 | if lis p e w_end |
| 555 | put re r e |
| 556 | if not txt |
| 557 | fnd ovl f_notext |
| 558 | end |
| 559 | if eq get dn r 0 |
| 560 | fnd ovl f_nodate |
| 561 | end |
| 562 | if eq get rm r 0 |
| 563 | fnd ovl f_nofor |
| 564 | end |
| 565 | if eq get ro r 18446744073709551615 |
| 566 | fnd ovl f_noord |
| 567 | end |
| 568 | r = add r 1 |
| 569 | inr = false |
| 570 | end |
| 571 | else |
| 572 | if lpre p e w_rule |
| 573 | newrule p e r ovl |
| 574 | inr = true |
| 575 | txt = false |
| 576 | else |
| 577 | outer p e ovl |
| 578 | end |
| 579 | end |
| 580 | p = add e 1 |
| 581 | end |
| 582 | if inr |
| 583 | fnd true f_open |
| 584 | end |
| 585 | put st s_nr r |
| 586 | end |
| 587 | |
| 588 | note line: one line [p, e) inside rule r; returns whether the rule has text now |
| 589 | fn line p ulong e ulong r ulong ovl bool txt bool to bool |
| 590 | if lis p e w_end |
| 591 | ret txt |
| 592 | end |
| 593 | if lpre p e w_bar |
| 594 | if or eq sub e p 1 eq get rb add p 1 32 |
| 595 | ret true |
| 596 | end |
| 597 | fnd ovl f_in |
| 598 | ret txt |
| 599 | end |
| 600 | if lpre p e w_date |
| 601 | if isdate add p len w_date e |
| 602 | put dn r 1 |
| 603 | else |
| 604 | fnd ovl f_nodate |
| 605 | end |
| 606 | ret txt |
| 607 | end |
| 608 | if lpre p e w_said |
| 609 | ret txt |
| 610 | end |
| 611 | if lpre p e w_for |
| 612 | put rm r forbits p e |
| 613 | ret txt |
| 614 | end |
| 615 | if lpre p e w_order |
| 616 | put ro r pnum add p len w_order e |
| 617 | ret txt |
| 618 | end |
| 619 | fnd ovl f_in |
| 620 | ret txt |
| 621 | end |
| 622 | |
| 623 | note okt: the target line [p, e) is `target PROG PATH`: one known program (not `all`), one space, a path |
| 624 | fn okt p ulong e ulong to bool |
| 625 | a = add p len w_target |
| 626 | q = a |
| 627 | while lt q e bound 4096 |
| 628 | if eq get rb q 32 |
| 629 | break |
| 630 | end |
| 631 | q = add q 1 |
| 632 | end |
| 633 | b = wbit a q |
| 634 | if or eq b 0 eq b allm |
| 635 | ret false |
| 636 | end |
| 637 | if ge add q 1 e |
| 638 | ret false |
| 639 | end |
| 640 | ret ne get rb add q 1 32 |
| 641 | end |
| 642 | |
| 643 | note outer: a line outside every rule |
| 644 | fn outer p ulong e ulong ovl bool to void |
| 645 | if eq p e |
| 646 | ret |
| 647 | end |
| 648 | if eq get rb p 35 |
| 649 | ret |
| 650 | end |
| 651 | if ovl |
| 652 | if lpre p e w_target |
| 653 | if not okt p e |
| 654 | fnd ovl f_tgt |
| 655 | else |
| 656 | a = add p len w_target |
| 657 | while ne get rb a 32 bound 4096 |
| 658 | a = add a 1 |
| 659 | end |
| 660 | if ne tfind add a 1 e p |
| 661 | fnd ovl m_dup_target |
| 662 | end |
| 663 | end |
| 664 | ret |
| 665 | end |
| 666 | if or lpre p e w_skills lpre p e w_alarm |
| 667 | ret |
| 668 | end |
| 669 | if lpre p e w_cap |
| 670 | if not okc p e |
| 671 | fnd ovl f_cap |
| 672 | end |
| 673 | ret |
| 674 | end |
| 675 | end |
| 676 | fnd ovl f_out |
| 677 | end |
| 678 | |
| 679 | note okc: the OVL line [p, e) is `cap CHARS PATH`: 1 to 18 digits, one space, a path |
| 680 | fn okc p ulong e ulong to bool |
| 681 | a = add p len w_cap |
| 682 | q = a |
| 683 | while lt q e bound 4096 |
| 684 | if eq get rb q 32 |
| 685 | break |
| 686 | end |
| 687 | q = add q 1 |
| 688 | end |
| 689 | if eq pnum a q 18446744073709551615 |
| 690 | ret false |
| 691 | end |
| 692 | if ge add q 1 e |
| 693 | ret false |
| 694 | end |
| 695 | ret ne get rb add q 1 32 |
| 696 | end |
| 697 | |
| 698 | note private: the public SRC holds no home path, host path, host name or private name |
| 699 | fn private to void |
| 700 | ns = get st s_ns |
| 701 | p = ulong 0 |
| 702 | put st s_ln 0 |
| 703 | while lt p ns bound 16777216 |
| 704 | e = lend p |
| 705 | put st s_ln add get st s_ln 1 |
| 706 | if or has p e k_home or has p e k_home2 or has p e k_users has p e k_srv |
| 707 | fnd false f_priv |
| 708 | else |
| 709 | if or has p e k_spark or has p e k_pearl or has p e k_crypto has p e k_local |
| 710 | fnd false f_priv |
| 711 | else |
| 712 | if or has p e k_dhome or has p e k_root or has p e k_var has p e k_etc |
| 713 | fnd false f_priv |
| 714 | else |
| 715 | if or has p e k_linear has p e k_issue |
| 716 | fnd false f_priv |
| 717 | end |
| 718 | end |
| 719 | end |
| 720 | end |
| 721 | p = add e 1 |
| 722 | end |
| 723 | end |
| 724 | |
| 725 | note ---------------------------------------------------------------- render |
| 726 | |
| 727 | note orule: the | lines of rule r |
| 728 | fn orule r ulong to void |
| 729 | p = get rs r |
| 730 | e = get re r |
| 731 | while lt p e bound 16777216 |
| 732 | q = lend p |
| 733 | if lpre p q w_bar |
| 734 | if gt sub q p 1 |
| 735 | orb add p 2 q |
| 736 | end |
| 737 | o 10 |
| 738 | end |
| 739 | p = add q 1 |
| 740 | end |
| 741 | end |
| 742 | |
| 743 | note pick: the next rule in order for program bit m, after the ones marked done; capr when none |
| 744 | fn pick m ulong to ulong |
| 745 | nr = get st s_nr |
| 746 | best = capr |
| 747 | for i ulong nr bound 65536 |
| 748 | if and eq get dn i 0 ne and get rm i m 0 |
| 749 | if eq best capr |
| 750 | best = i |
| 751 | else |
| 752 | if lt get ro i get ro best |
| 753 | best = i |
| 754 | end |
| 755 | end |
| 756 | end |
| 757 | end |
| 758 | ret best |
| 759 | end |
| 760 | |
| 761 | note tprog: the program bit of the OVL `target PROG PATH` line [p, e); 0 for any other line |
| 762 | fn tprog p ulong e ulong to ulong |
| 763 | if not lpre p e w_target |
| 764 | ret 0 |
| 765 | end |
| 766 | a = add p len w_target |
| 767 | q = a |
| 768 | while lt q e bound 4096 |
| 769 | if eq get rb q 32 |
| 770 | break |
| 771 | end |
| 772 | q = add q 1 |
| 773 | end |
| 774 | ret wbit a q |
| 775 | end |
| 776 | |
| 777 | note Print the path of a full agents file, if one exists. Its unchanged render contains all shared and agents-only rules. |
| 778 | fn agentptr to bool |
| 779 | p = get st s_ns |
| 780 | while lt p get st s_n bound 16777216 |
| 781 | e = lend p |
| 782 | if eq tprog p e 4 |
| 783 | ot g_1 |
| 784 | orb add p len w_target e |
| 785 | o 10 |
| 786 | ret true |
| 787 | end |
| 788 | p = add e 1 |
| 789 | end |
| 790 | ret false |
| 791 | end |
| 792 | |
| 793 | note build: the file for program bit m into obuf (the header names ab[0, s_al) and hd) |
| 794 | fn build m ulong compact bool to void |
| 795 | nr = get st s_nr |
| 796 | for i ulong nr bound 65536 |
| 797 | put dn i 0 |
| 798 | end |
| 799 | ot h_1 |
| 800 | for j ulong get st s_al bound 4096 |
| 801 | o get ab j |
| 802 | end |
| 803 | ot h_2 |
| 804 | for k ulong get st s_hl bound 128 |
| 805 | o get hd k |
| 806 | end |
| 807 | ot h_3 |
| 808 | if eq m genm |
| 809 | if not compact |
| 810 | m = or m 4 |
| 811 | else |
| 812 | if not agentptr |
| 813 | m = or m 4 |
| 814 | end |
| 815 | end |
| 816 | end |
| 817 | c = ulong 0 |
| 818 | while true bound 65537 |
| 819 | r = pick m |
| 820 | if eq r capr |
| 821 | break |
| 822 | end |
| 823 | put dn r 1 |
| 824 | o 10 |
| 825 | orule r |
| 826 | c = add c 1 |
| 827 | end |
| 828 | end |
| 829 | |
| 830 | |
| 831 | note ---------------------------------------------------------------- fit |
| 832 | |
| 833 | note tfind: the start of the OVL `target PROG PATH` line whose PATH is rb[a, b); s_n when there is none |
| 834 | fn tfind a ulong b ulong to ulong |
| 835 | n = get st s_n |
| 836 | p = get st s_ns |
| 837 | while lt p n bound 16777216 |
| 838 | e = lend p |
| 839 | if lpre p e w_target |
| 840 | s = add p len w_target |
| 841 | while lt s e bound 4096 |
| 842 | if eq get rb s 32 |
| 843 | break |
| 844 | end |
| 845 | s = add s 1 |
| 846 | end |
| 847 | if lt s e |
| 848 | if ideq add s 1 e a b |
| 849 | ret p |
| 850 | end |
| 851 | end |
| 852 | end |
| 853 | p = add e 1 |
| 854 | end |
| 855 | ret n |
| 856 | end |
| 857 | |
| 858 | note nchars: the characters of obuf (UTF-8 code points: every byte that is not a continuation byte) |
| 859 | fn nchars to ulong |
| 860 | n = get st s_on |
| 861 | c = ulong 0 |
| 862 | for i ulong n bound 16777216 |
| 863 | if ne and get obuf i 192 128 |
| 864 | c = add c 1 |
| 865 | end |
| 866 | end |
| 867 | ret c |
| 868 | end |
| 869 | |
| 870 | note Rebuild only an oversized generic render. The same selection is used by fit and by installation. |
| 871 | fn boundedbuild m ulong lim ulong to ulong |
| 872 | put st s_on 0 |
| 873 | build m false |
| 874 | k = nchars |
| 875 | if and eq m genm gt k lim |
| 876 | put st s_on 0 |
| 877 | build m true |
| 878 | k = nchars |
| 879 | end |
| 880 | ret k |
| 881 | end |
| 882 | |
| 883 | note A path comparison uses the complete byte span, including any interior spaces. |
| 884 | fn patharg a ulong e ulong size ulong to bool |
| 885 | if ne sub e a size |
| 886 | ret false |
| 887 | end |
| 888 | for i ulong size bound 4096 |
| 889 | if ne get ab i get rb add a i |
| 890 | ret false |
| 891 | end |
| 892 | end |
| 893 | ret true |
| 894 | end |
| 895 | |
| 896 | note For the exact target and program, return the strictest cap or the maximum ulong if uncapped. |
| 897 | fn pathlimit size ulong program ulong to ulong |
| 898 | lim = ulong 18446744073709551615 |
| 899 | found = false |
| 900 | p = get st s_ns |
| 901 | while lt p get st s_n bound 16777216 |
| 902 | e = lend p |
| 903 | cap = lpre p e w_cap |
| 904 | if or cap eq tprog p e program |
| 905 | a = add p len w_target |
| 906 | if cap |
| 907 | a = add p len w_cap |
| 908 | end |
| 909 | q = a |
| 910 | while lt q e bound 4096 |
| 911 | if eq get rb q 32 |
| 912 | break |
| 913 | end |
| 914 | q = add q 1 |
| 915 | end |
| 916 | if patharg add q 1 e size |
| 917 | if cap |
| 918 | v = pnum a q |
| 919 | if lt v lim |
| 920 | lim = v |
| 921 | end |
| 922 | else |
| 923 | found = true |
| 924 | end |
| 925 | end |
| 926 | end |
| 927 | p = add e 1 |
| 928 | end |
| 929 | if not found |
| 930 | wfd 2 m_path |
| 931 | exit 2 |
| 932 | end |
| 933 | ret lim |
| 934 | end |
| 935 | |
| 936 | note fit: every OVL `cap CHARS PATH` line against the render of its target; a finding for each render over |
| 937 | note its cap and each cap without a target |
| 938 | fn fit to void |
| 939 | n = get st s_n |
| 940 | p = get st s_ns |
| 941 | while lt p n bound 16777216 |
| 942 | e = lend p |
| 943 | if lpre p e w_cap |
| 944 | a = add p len w_cap |
| 945 | q = a |
| 946 | while lt q e bound 4096 |
| 947 | if eq get rb q 32 |
| 948 | break |
| 949 | end |
| 950 | q = add q 1 |
| 951 | end |
| 952 | lim = pnum a q |
| 953 | t = tfind add q 1 e |
| 954 | if eq t n |
| 955 | wfd 1 t_notgt |
| 956 | wrb 1 add q 1 e |
| 957 | wfd 1 nl |
| 958 | put st s_bad add get st s_bad 1 |
| 959 | else |
| 960 | g = add t len w_target |
| 961 | h = g |
| 962 | while lt h e bound 4096 |
| 963 | if eq get rb h 32 |
| 964 | break |
| 965 | end |
| 966 | h = add h 1 |
| 967 | end |
| 968 | for i ulong sub h g bound 4096 |
| 969 | put ab i get rb add g i |
| 970 | end |
| 971 | put st s_al sub h g |
| 972 | k = boundedbuild wbit g h lim |
| 973 | put st s_on 0 |
| 974 | wfd 1 t_fit |
| 975 | wrb 1 g h |
| 976 | wfd 1 sp |
| 977 | wrb 1 add q 1 e |
| 978 | wfd 1 sp |
| 979 | wnum 1 k |
| 980 | wfd 1 t_of |
| 981 | wnum 1 lim |
| 982 | if gt k lim |
| 983 | wfd 1 t_over |
| 984 | put st s_bad add get st s_bad 1 |
| 985 | else |
| 986 | wfd 1 t_ok |
| 987 | end |
| 988 | end |
| 989 | end |
| 990 | p = add e 1 |
| 991 | end |
| 992 | end |
| 993 | |
| 994 | note ---------------------------------------------------------------- targets |
| 995 | |
| 996 | fn targets to void |
| 997 | n = get st s_n |
| 998 | p = get st s_ns |
| 999 | while lt p n bound 16777216 |
| 1000 | e = lend p |
| 1001 | if lpre p e w_target |
| 1002 | orb p e |
| 1003 | o 10 |
| 1004 | end |
| 1005 | if lpre p e w_skills |
| 1006 | ot w_skills |
| 1007 | ot dash |
| 1008 | orb add p len w_skills e |
| 1009 | o 10 |
| 1010 | end |
| 1011 | if lpre p e w_alarm |
| 1012 | ot w_alarm |
| 1013 | ot dash |
| 1014 | orb add p len w_alarm e |
| 1015 | o 10 |
| 1016 | end |
| 1017 | p = add e 1 |
| 1018 | end |
| 1019 | flush |
| 1020 | end |
| 1021 | |
| 1022 | note ---------------------------------------------------------------- main |
| 1023 | |
| 1024 | fn main to int |
| 1025 | c = argcnt |
| 1026 | if lt c 3 |
| 1027 | wfd 2 m_use |
| 1028 | ret 2 |
| 1029 | end |
| 1030 | k = ldarg 1 |
| 1031 | mode = ulong 9 |
| 1032 | if argis a_lint k |
| 1033 | mode = ulong 0 |
| 1034 | end |
| 1035 | if argis a_render k |
| 1036 | mode = ulong 1 |
| 1037 | end |
| 1038 | if argis a_tgts k |
| 1039 | mode = ulong 2 |
| 1040 | end |
| 1041 | if argis a_fit k |
| 1042 | mode = ulong 3 |
| 1043 | end |
| 1044 | if and eq mode 1 and ne c 6 ne c 7 |
| 1045 | wfd 2 m_use |
| 1046 | ret 2 |
| 1047 | end |
| 1048 | if or eq mode 9 or and eq mode 2 ne c 4 and eq mode 3 ne c 5 |
| 1049 | wfd 2 m_use |
| 1050 | ret 2 |
| 1051 | end |
| 1052 | if and eq mode 0 gt c 4 |
| 1053 | wfd 2 m_use |
| 1054 | ret 2 |
| 1055 | end |
| 1056 | put st s_n 0 |
| 1057 | put st s_on 0 |
| 1058 | put st s_bad 0 |
| 1059 | ldfile 2 |
| 1060 | put st s_ns get st s_n |
| 1061 | if ge c 4 |
| 1062 | ldfile 3 |
| 1063 | end |
| 1064 | parse |
| 1065 | if eq mode 0 |
| 1066 | private |
| 1067 | if gt get st s_n div capb 2 |
| 1068 | wfd 1 m_alarm |
| 1069 | put st s_bad add get st s_bad 1 |
| 1070 | end |
| 1071 | wfd 1 m_lint |
| 1072 | wnum 1 get st s_nr |
| 1073 | wfd 1 f_rules |
| 1074 | wnum 1 get st s_bad |
| 1075 | wfd 1 sp |
| 1076 | wfd 1 f_tg |
| 1077 | if ne get st s_bad 0 |
| 1078 | ret 1 |
| 1079 | end |
| 1080 | ret 0 |
| 1081 | end |
| 1082 | if ne get st s_bad 0 |
| 1083 | ret 2 |
| 1084 | end |
| 1085 | if eq mode 2 |
| 1086 | targets |
| 1087 | ret 0 |
| 1088 | end |
| 1089 | hi = ulong 5 |
| 1090 | if eq mode 3 |
| 1091 | hi = ulong 4 |
| 1092 | end |
| 1093 | h = ldarg hi |
| 1094 | if gt h 128 |
| 1095 | wfd 2 m_use |
| 1096 | ret 2 |
| 1097 | end |
| 1098 | for i ulong h bound 128 |
| 1099 | put hd i get ab i |
| 1100 | end |
| 1101 | put st s_hl h |
| 1102 | if eq mode 3 |
| 1103 | fit |
| 1104 | if ne get st s_bad 0 |
| 1105 | ret 1 |
| 1106 | end |
| 1107 | ret 0 |
| 1108 | end |
| 1109 | lim = ulong 18446744073709551615 |
| 1110 | a = ldarg 4 |
| 1111 | m = wbit2 a |
| 1112 | if eq m 0 |
| 1113 | wfd 2 m_prog |
| 1114 | z = write 2 ab 0 a |
| 1115 | wfd 2 nl |
| 1116 | ret 2 |
| 1117 | end |
| 1118 | if eq c 7 |
| 1119 | lim = pathlimit ldarg 6 m |
| 1120 | a = ldarg 4 |
| 1121 | end |
| 1122 | put st s_al a |
| 1123 | if gt boundedbuild m lim lim |
| 1124 | wfd 2 m_over |
| 1125 | ret 1 |
| 1126 | end |
| 1127 | flush |
| 1128 | ret 0 |
| 1129 | end |
| 1130 | |
| 1131 | note wbit2: the program named by ab[0, a) |
| 1132 | fn wbit2 a ulong to ulong |
| 1133 | if argis p_claude a |
| 1134 | ret 1 |
| 1135 | end |
| 1136 | if argis p_codex a |
| 1137 | ret 2 |
| 1138 | end |
| 1139 | if argis p_agents a |
| 1140 | ret 4 |
| 1141 | end |
| 1142 | if argis p_omp a |
| 1143 | ret 8 |
| 1144 | end |
| 1145 | if argis p_watch a |
| 1146 | ret 16 |
| 1147 | end |
| 1148 | if argis p_gen a |
| 1149 | ret genm |
| 1150 | end |
| 1151 | ret 0 |
| 1152 | end |