Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/protocol/synapse/mcp/src/10mcp.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / protocol / synapse / mcp / src / 10mcp.om` 1214 lines ยท 27413 bytes Raw Blame History 1 note synapse-mcp 10mcp.om: MCP stdio server (JSON-RPC 2.0, one message per line) over the coordination CLIs. 2 note Every tool is one fixed argv executed without a shell; argument values are separate argv records. 3 global gop ulong 4 4 global gopl ulong 4 5 global gid ulong 2 6 global gbad ulong 2 7 global gq ulong 4 8 note gobj 0: JSON object token searched by mc_get and pu_memb2; gv 0: value token found by mc_get 9 note gnm 0: offset of the tool name for mc_build (omc allows six parameter slots; a sized-* view takes two) 10 global gobj ulong 1 11 global gv ulong 1 12 global gnm ulong 1 13 global gln ulong 2 14 15 text musage "usage: synapse-mcp --bin-dir DIR [--home DIR]" 16 text mbindir "--bin-dir" 17 text mhome "--home" 18 text menvh "AIEN_COORD_HOME=" 19 text menvhm "HOME=" 20 text mdhome "/.local/state/aien-coord" 21 text mnohome "synapse-mcp: no --home, AIEN_COORD_HOME or HOME" 22 text mnobin "synapse-mcp: --bin-dir must be an absolute directory" 23 text mtrunc "[stdout truncated at `1048576` bytes]\n" 24 text mkjrpc "jsonrpc" 25 text mk20 "2.0" 26 text mkid "id" 27 text mkmeth "method" 28 text mkpar "params" 29 text mkname "name" 30 text mkargs "arguments" 31 text mminit "initialize" 32 text mmping "ping" 33 text mmlist "tools/list" 34 text mmcall "tools/call" 35 text mrpre "{\"jsonrpc\":\"2.0\",\"id\":" 36 text mridnul "null" 37 text mrres ",\"result\":" 38 text mrerr ",\"error\":{\"code\":" 39 text mrmsg ",\"message\":\"" 40 text mrend "\"}}\n" 41 text mrclose "}\n" 42 text mrinit "{\"protocolVersion\":\"2025-06-18\",\"capabilities\":{\"tools\":{\"listChanged\":false}},\"serverInfo\":{\"name\":\"synapse-mcp\",\"version\":\"0.1.0\"},\"instructions\":\"AIEN coordination tools: claim before you work, check who holds a target, read drift findings.\"}" 43 text mrempty "{}" 44 text mrtext "{\"content\":[{\"type\":\"text\",\"text\":\"" 45 text mriserr "\"}],\"isError\":" 46 text mtrue "true" 47 text mfalse "false" 48 text mexitc "{\"exit_code\":" 49 text mwhoc "{\"who\":\"" 50 text mwhoe "\",\"exit_code\":" 51 text mcl "}" 52 text mmeparse "Parse error" 53 text mmeinv "Invalid Request" 54 text mmenome "Method not found" 55 text mmeparm "Invalid params" 56 text mmetool "Unknown tool" 57 text mbadarg "Invalid params: bad or missing argument" 58 text mbadunk "Invalid params: unknown argument" 59 text mbadlong "Invalid params: arguments too long" 60 text mbadobj "Invalid params: arguments must be an object" 61 text mtoolong "synapse-mcp: request line over `1048576` bytes" 62 63 text mbclaims "/synapse-claims" 64 text mbmap "/synapse-map" 65 text mbpulse "/synapse-pulse" 66 text mbboard "/synapse-board" 67 text mcclaim "claim" 68 text mcrenew "renew" 69 text mcrel "release" 70 text mcstate "state" 71 text mcwho "who" 72 text mclist "list" 73 text mcconf "conflicts" 74 text mcver "verify" 75 text mcwhere "where" 76 text mctree "tree" 77 text mccheck "check" 78 text mcrun "run" 79 text mcrender "render" 80 text mfagent "--agent" 81 text mfsess "--session" 82 text mftarg "--target" 83 text mfttl "--ttl" 84 text mfmode "--mode" 85 text mfstate "--state" 86 text mfint "--intent" 87 text mfevid "--evidence" 88 text mfid "--id" 89 text mfall "--all" 90 text mfprefix "--agent-prefix" 91 text mflimit "--limit" 92 text mftext "--text" 93 text mfalert "--alert" 94 text mfcbin "--claims-bin" 95 text mfclaims "--claims" 96 text mfmap "--map" 97 text mffind "--findings" 98 text mfout "--out" 99 text makagent "agent" 100 text maksess "session" 101 text maktarg "target" 102 text makttl "ttl" 103 text makmode "mode" 104 text makstate "state" 105 text makint "intent" 106 text makevid "evidence" 107 text makid "id" 108 text makall "all" 109 text maklane "lane" 110 text maktask "task" 111 text maklimit "limit" 112 text maktext "text" 113 text makalert "alert" 114 text mkrepo "repo" 115 text mrepoc "repo:" 116 text mslboard "/board" 117 text mslbcl "/board/claims.jsonl" 118 text mslmap "/map.jsonl" 119 text mslfind "/pulse/findings.jsonl" 120 text mlisterr "synapse-mcp: synapse-claims list --all failed; board not rendered" 121 text mwrerr "synapse-mcp: could not write HOME/board/claims.jsonl; board not rendered" 122 123 text mtn01 "coord_where" 124 text mtn02 "coord_tree" 125 text mtn03 "coord_check" 126 text mtn04 "coord_claim" 127 text mtn05 "coord_renew" 128 text mtn06 "coord_release" 129 text mtn07 "coord_state" 130 text mtn08 "coord_who" 131 text mtn09 "coord_list" 132 text mtn10 "coord_conflicts" 133 text mtn11 "coord_verify" 134 text mtn12 "coord_pulse" 135 text mtn13 "coord_board" 136 text mtn14 "coord_lane" 137 138 text ml00 "{\"tools\":[" 139 text ml01 "{\"name\":\"coord_where\",\"description\":\"Rank aien-dev repositories for a task (synapse-map where) and show who holds claims on the top 3 (synapse-claims who repo:R).\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"task\":{\"type\":\"string\",\"description\":\"plain-words task\"},\"limit\":{\"type\":\"integer\",\"minimum\":1}},\"required\":[\"task\"],\"additionalProperties\":false}}," 140 text ml02 "{\"name\":\"coord_tree\",\"description\":\"Repository parent tree (synapse-map tree).\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"text\":{\"type\":\"boolean\"}},\"additionalProperties\":false}}," 141 text ml03 "{\"name\":\"coord_check\",\"description\":\"Repository map findings: orphans, missing or archived parents, duplicate purposes (synapse-map check).\",\"inputSchema\":{\"type\":\"object\",\"properties\":{},\"additionalProperties\":false}}," 142 text ml04 "{\"name\":\"coord_claim\",\"description\":\"Claim a target before working on it. Exit 2 means another agent holds it; the holder is returned.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"agent\":{\"type\":\"string\"},\"session\":{\"type\":\"string\"},\"target\":{\"type\":\"string\",\"description\":\"repo:O/R | branch:O/R#ref | path:O/R:glob | pr:O/R#N | ext:...\"},\"ttl\":{\"type\":\"integer\",\"minimum\":1},\"mode\":{\"type\":\"string\",\"enum\":[\"excl\",\"shared\"]},\"state\":{\"type\":\"string\"},\"intent\":{\"type\":\"string\"},\"evidence\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}},\"required\":[\"agent\",\"session\",\"target\"],\"additionalProperties\":false}}," 143 text ml05 "{\"name\":\"coord_renew\",\"description\":\"Extend a claim lease you hold.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"agent\":{\"type\":\"string\"},\"id\":{\"type\":\"string\"},\"ttl\":{\"type\":\"integer\",\"minimum\":1}},\"required\":[\"agent\",\"id\"],\"additionalProperties\":false}}," 144 text ml06 "{\"name\":\"coord_release\",\"description\":\"Release a claim you hold, optionally with a final state and evidence.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"agent\":{\"type\":\"string\"},\"id\":{\"type\":\"string\"},\"state\":{\"type\":\"string\"},\"evidence\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}},\"required\":[\"agent\",\"id\"],\"additionalProperties\":false}}," 145 text ml07 "{\"name\":\"coord_state\",\"description\":\"Record a state change (e.g. PR_OPEN, MERGED) on a claim you hold.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"agent\":{\"type\":\"string\"},\"id\":{\"type\":\"string\"},\"state\":{\"type\":\"string\"},\"evidence\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}},\"required\":[\"agent\",\"id\",\"state\"],\"additionalProperties\":false}}," 146 text ml08 "{\"name\":\"coord_who\",\"description\":\"Active claims overlapping a target.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"target\":{\"type\":\"string\"}},\"required\":[\"target\"],\"additionalProperties\":false}}," 147 text ml09 "{\"name\":\"coord_list\",\"description\":\"Active claims (all claims with all=true).\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"all\":{\"type\":\"boolean\"}},\"additionalProperties\":false}}," 148 text ml10 "{\"name\":\"coord_conflicts\",\"description\":\"Conflicting active claim pairs.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{},\"additionalProperties\":false}}," 149 text ml11 "{\"name\":\"coord_verify\",\"description\":\"Verify the claims ledger hash chain and signatures.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{},\"additionalProperties\":false}}," 150 text ml12 "{\"name\":\"coord_pulse\",\"description\":\"Reconcile claims with GitHub and live sessions; returns drift findings (synapse-pulse run).\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"alert\":{\"type\":\"boolean\"}},\"additionalProperties\":false}}," 151 text ml13 "{\"name\":\"coord_board\",\"description\":\"Render the generated board (BOARD.md, index.html) from claims, map and findings.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{},\"additionalProperties\":false}}," 152 text ml14 "{\"name\":\"coord_lane\",\"description\":\"Agents in a lane: active claims whose agent id starts with the lane prefix. Message these agents (parent and children) instead of agent://all.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"lane\":{\"type\":\"string\",\"description\":\"agent id prefix, e.g. Coordination\"}},\"required\":[\"lane\"],\"additionalProperties\":false}}" 153 text ml99 "]}" 154 155 note ======== output ======== 156 fn mc_flush m ulong to void 157 n = syn_len m 158 k = ulong 0 159 while lt k n bound 999999 160 w = write 1 gsp add m k sub n k 161 if le w 0 162 exit 70 163 end 164 k = add k ulong w 165 end 166 syn_rew m 167 end 168 169 fn mc_hex v ulong to uchar 170 if lt v 10 171 ret uchar add v 48 172 end 173 ret uchar add v 87 174 end 175 176 note mc_qb: append byte c JSON-escaped (no quotes) 177 fn mc_qb c uchar to void 178 if or eq c 34 eq c 92 179 syn_pb 92 180 syn_pb c 181 ret 182 end 183 if eq c 10 184 syn_pb 92 185 syn_pb 110 186 ret 187 end 188 if eq c 9 189 syn_pb 92 190 syn_pb 116 191 ret 192 end 193 if eq c 13 194 syn_pb 92 195 syn_pb 114 196 ret 197 end 198 if lt c 32 199 syn_pb 92 200 syn_pb 117 201 syn_pb 48 202 syn_pb 48 203 syn_pb mc_hex shr ulong c 4 204 syn_pb mc_hex and ulong c 15 205 ret 206 end 207 syn_pb c 208 end 209 210 fn mc_qa a view uchar * o ulong n ulong to void 211 for i ulong n 212 mc_qb get a add o i 213 end 214 end 215 216 note mc_qerr: JSON-escape the captured stderr (gerrb, gerrn 0 bytes); a global cannot be an argument 217 fn mc_qerr to void 218 for i ulong get gerrn 0 219 mc_qb get gerrb i 220 end 221 end 222 223 fn mc_qt t view uchar * to void 224 for i ulong len t 225 mc_qb get t i 226 end 227 end 228 229 fn mc_qp o ulong n ulong to void 230 for i ulong n 231 mc_qb get gsp add o i 232 end 233 end 234 235 note mc_head: response prefix with the request id (or null) 236 fn mc_head to ulong 237 m = syn_mark 238 syn_pt mrpre 239 if eq get gid 1 0 240 syn_pt mridnul 241 else 242 syn_ps get gid 0 get gid 1 243 end 244 ret m 245 end 246 247 fn mc_err code ulong msg view uchar * to void 248 m = mc_head 249 syn_pt mrerr 250 syn_pb 45 251 syn_pd code 252 syn_pt mrmsg 253 mc_qt msg 254 syn_pt mrend 255 mc_flush m 256 end 257 258 note mc_errp: error with a message held in the pool at (o,n) 259 fn mc_errp code ulong o ulong n ulong to void 260 m = mc_head 261 syn_pt mrerr 262 syn_pb 45 263 syn_pd code 264 syn_pt mrmsg 265 mc_qp o n 266 syn_pt mrend 267 mc_flush m 268 end 269 270 fn mc_okt t view uchar * to void 271 m = mc_head 272 syn_pt mrres 273 syn_pt t 274 syn_pt mrclose 275 mc_flush m 276 end 277 278 fn mc_list to void 279 m = mc_head 280 syn_pt mrres 281 syn_pt ml00 282 syn_pt ml01 283 syn_pt ml02 284 syn_pt ml03 285 syn_pt ml04 286 syn_pt ml05 287 syn_pt ml06 288 syn_pt ml07 289 syn_pt ml08 290 syn_pt ml09 291 syn_pt ml10 292 syn_pt ml11 293 syn_pt ml12 294 syn_pt ml13 295 syn_pt ml14 296 syn_pt ml99 297 syn_pt mrclose 298 mc_flush m 299 end 300 301 note ======== argument records ======== 302 note gbad 0: 0 ok, 1 bad value (gbad 1 = key text index), 2 unknown key, 3 too long, 4 not an object 303 note gq 0: arguments consumed so far 304 fn mc_bad k ulong why ulong to void 305 if eq get gbad 0 0 306 put gbad 0 why 307 put gbad 1 k 308 end 309 end 310 311 fn mc_room n ulong to bool 312 if gt add add get gavs 0 n 16 4000 313 ret false 314 end 315 if ge get gavs 1 60 316 ret false 317 end 318 ret true 319 end 320 321 note mc_val: check decoded string tmp[0..n) and add it as one record; false when refused 322 fn mc_val tmp view uchar * n ulong to bool 323 if or eq n 0 eq get tmp 0 45 324 ret false 325 end 326 for i ulong n 327 if eq get tmp i 0 328 ret false 329 end 330 end 331 if not mc_room n 332 put gbad 0 3 333 ret false 334 end 335 m = syn_mark 336 syn_pa tmp 0 n 337 syn_ap m n 338 syn_rew m 339 ret true 340 end 341 342 fn mc_flag f view uchar * to bool 343 if not mc_room len f 344 put gbad 0 3 345 ret false 346 end 347 syn_at f 348 ret true 349 end 350 351 note mc_get: gv 0 = value token for key in args object gobj 0, or jsnone; counts the key as consumed 352 fn mc_get src view uchar * tape view uint * key view uchar * to void 353 put gv 0 jsnone 354 a = get gobj 0 355 if eq a jsnone 356 ret 357 end 358 k = js_first tape a 359 while ne k jsnone bound 999999 360 if js_streq src js_off tape k key 361 put gq 0 add get gq 0 1 362 put gv 0 add k 1 363 ret 364 end 365 k = js_mnext tape k 366 end 367 end 368 369 note mc_sval: string value of gv 0 into tmp; its length, or -1 when absent or refused; req: must be present 370 fn mc_sval src view uchar * tape view uint * tmp edit uchar * to long 371 v = get gv 0 372 if eq v jsnone 373 if eq get gq 1 1 374 mc_bad 0 1 375 end 376 put gq 1 0 377 ret -1 378 end 379 put gq 1 0 380 if ne js_type tape v jsstr 381 mc_bad 0 1 382 ret -1 383 end 384 n = js_sget src js_off tape v tmp 385 if lt n 0 386 mc_bad 0 1 387 ret -1 388 end 389 ret n 390 end 391 392 note mc_semit: string argument from mc_sval (n bytes of tmp) as option flag + value 393 fn mc_semit tmp view uchar * n long flag view uchar * to void 394 if lt n 0 395 ret 396 end 397 if not mc_flag flag 398 ret 399 end 400 mc_spos tmp n 401 end 402 403 note mc_spos: string argument from mc_sval as one positional record (omc `e5b32567` gives an empty text a 404 note wrong length, omega-mv #775, so positionals do not pass an empty flag text) 405 fn mc_spos tmp view uchar * n long to void 406 if lt n 0 407 ret 408 end 409 if not mc_val tmp ulong n 410 mc_bad 0 1 411 end 412 end 413 414 note mc_int: integer argument (JSON unsigned integer >= 1) as option flag 415 fn mc_int src view uchar * tape view uint * flag view uchar * to void 416 v = get gv 0 417 if eq v jsnone 418 ret 419 end 420 if ne js_type tape v jsnum 421 mc_bad 0 1 422 ret 423 end 424 if not js_isu src js_off tape v 425 mc_bad 0 1 426 ret 427 end 428 x = js_tou src js_off tape v 429 if or eq x 0 gt x `99999999` 430 mc_bad 0 1 431 ret 432 end 433 if not mc_flag flag 434 ret 435 end 436 m = syn_mark 437 syn_pd x 438 syn_ap m syn_len m 439 syn_rew m 440 end 441 442 note mc_bool: boolean argument; true adds the flag 443 fn mc_bool tape view uint * flag view uchar * to void 444 v = get gv 0 445 if eq v jsnone 446 ret 447 end 448 t = js_type tape v 449 if eq t jstrue 450 r = mc_flag flag 451 ret 452 end 453 if ne t jsfalse 454 mc_bad 0 1 455 end 456 end 457 458 note mc_evid: array of strings; each element becomes --evidence-style flag mfevid + value 459 fn mc_evid src view uchar * tape view uint * tmp edit uchar * to void 460 v = get gv 0 461 if eq v jsnone 462 ret 463 end 464 if ne js_type tape v jsarr 465 mc_bad 0 1 466 ret 467 end 468 e = js_first tape v 469 while ne e jsnone bound 999999 470 if ne js_type tape e jsstr 471 mc_bad 0 1 472 ret 473 end 474 n = js_sget src js_off tape e tmp 475 if lt n 0 476 mc_bad 0 1 477 ret 478 end 479 if not mc_flag mfevid 480 ret 481 end 482 if not mc_val tmp ulong n 483 mc_bad 0 1 484 ret 485 end 486 e = js_enext tape e 487 end 488 end 489 490 note mc_req1: mark the next mc_sval as required 491 fn mc_req1 to void 492 put gq 1 1 493 end 494 495 note mc_bin: start an argv for CLI t in bin-dir, then --home H when home is set 496 fn mc_bin t view uchar * home bool to void 497 syn_ainit 498 m = syn_mark 499 syn_ps get gop 0 get gopl 0 500 syn_pt t 501 syn_ap m syn_len m 502 syn_rew m 503 if home 504 syn_at mhome 505 syn_ps get gop 1 get gopl 1 506 m2 = sub syn_mark get gopl 1 507 syn_ap m2 get gopl 1 508 syn_rew m2 509 end 510 end 511 512 note mc_done: true when the arguments were all consumed and valid, else sends -32602 513 fn mc_done tape view uint * a ulong to bool 514 if ne a jsnone 515 if and eq get gbad 0 0 ne get gq 0 js_nkids tape a 516 put gbad 0 2 517 end 518 end 519 w = get gbad 0 520 if eq w 0 521 ret true 522 end 523 if eq w 2 524 mc_err 32602 mbadunk 525 ret false 526 end 527 if eq w 3 528 mc_err 32602 mbadlong 529 ret false 530 end 531 if eq w 4 532 mc_err 32602 mbadobj 533 ret false 534 end 535 mc_err 32602 mbadarg 536 ret false 537 end 538 539 note ======== running ======== 540 note mc_runap: run gav, append stdout, exit line and (on failure) stderr, all JSON-escaped; returns exit code 541 fn mc_runap obf edit uchar * to ulong 542 n = syn_run obf `300000000000` 543 c = ulong get gxs 0 544 mc_rout obf n c 545 ret c 546 end 547 548 note mc_rout: append n bytes of stdout, the exit line and (on failure) stderr of the last syn_run 549 fn mc_rout obf view uchar * n ulong c ulong to void 550 mc_qnl obf n 551 mc_qt mexitc 552 syn_pd c 553 mc_qt mcl 554 mc_qb 10 555 if gt get gxs 1 long n 556 mc_qt mtrunc 557 end 558 if ne c 0 559 mc_qerr 560 end 561 end 562 563 note mc_qnl: append obf[0..n) JSON-escaped, ending with a newline when it is not empty 564 note (and is eager in Omega, so the n > 0 guard is a separate if) 565 fn mc_qnl obf view uchar * n ulong to void 566 mc_qa obf 0 n 567 if gt n 0 568 if ne get obf sub n 1 10 569 mc_qb 10 570 end 571 end 572 end 573 574 fn mc_tail c ulong to void 575 syn_pt mriserr 576 if and ne c 0 and ne c 1 ne c 2 577 syn_pt mtrue 578 else 579 syn_pt mfalse 580 end 581 syn_pb 125 582 syn_pb 125 583 syn_pb 10 584 end 585 586 note mc_exec: run the prepared argv and send the tool result 587 fn mc_exec to void 588 obf = new uchar `1048576` 0 589 m = mc_head 590 syn_pt mrres 591 syn_pt mrtext 592 c = mc_runap obf 593 mc_tail c 594 mc_flush m 595 end 596 597 note coord_where: map where, then claims who repo:R for the first three result repos 598 fn mc_where src view uchar * tape edit uint * tmp edit uchar * to void 599 a = get gobj 0 600 mc_bin mbmap true 601 syn_at mcwhere 602 mc_req1 603 mc_get src tape maktask 604 sv = mc_sval src tape tmp 605 mc_spos tmp sv 606 mc_get src tape maklimit 607 mc_int src tape mflimit 608 if not mc_done tape a 609 ret 610 end 611 mc_wrun tape tmp 612 end 613 614 note mc_wrun: second half of coord_where (split out to stay within omc's 16 registers). The who targets are 615 note collected in the pool before the response starts, so they never land inside it. 616 fn mc_wrun tape edit uint * tmp edit uchar * to void 617 obf = new uchar `1048576` 0 618 n = syn_run obf `300000000000` 619 c = ulong get gxs 0 620 r = js_init tape 65536 16 621 rp = syn_mark 622 k = mc_wscan part obf 0 n tape tmp 623 m = mc_head 624 syn_pt mrres 625 syn_pt mrtext 626 mc_rout obf n c 627 mc_who3 obf rp k 628 mc_tail c 629 mc_flush m 630 syn_rew rp 631 end 632 633 note mc_wscan: per newline-terminated line of out (first three with a repo), mc_wrepo; returns how many appended 634 fn mc_wscan lns view uchar * tape edit uint * tmp edit uchar * to ulong 635 n = len lns 636 k = ulong 0 637 s = ulong 0 638 for i ulong add n 1 639 nl = eq i n 640 if not nl 641 nl = eq get lns i 10 642 end 643 if nl 644 if and gt i s lt k 3 645 k = add k mc_wrepo part lns s sub i s tape tmp 646 end 647 s = add i 1 648 end 649 end 650 ret k 651 end 652 653 note mc_wrepo: when line ln parses and has a string "repo", append "claims who repo:R" target; 1 if appended 654 fn mc_wrepo ln view uchar * tape edit uint * tmp edit uchar * to ulong 655 q = js_parse ln tape len ln 656 if gt q 0 657 v = pu_rmemb ln tape mkrepo 658 if and ne v jsnone eq js_type tape v jsstr 659 x = js_sget ln js_off tape v tmp 660 if gt x 0 661 syn_pt mrepoc 662 syn_pa tmp 0 ulong x 663 syn_pb 10 664 ret 1 665 end 666 end 667 end 668 ret 0 669 end 670 671 note pu_rmemb: value token of key in the root object, or jsnone 672 fn pu_rmemb src view uchar * tape view uint * key view uchar * to ulong 673 if ne js_type tape 0 jsobj 674 ret jsnone 675 end 676 k = js_first tape 0 677 while ne k jsnone bound 999999 678 if js_streq src js_off tape k key 679 ret add k 1 680 end 681 k = js_mnext tape k 682 end 683 ret jsnone 684 end 685 686 note mc_who3: for each newline-terminated target in the pool from rp (k of them), run claims who 687 fn mc_who3 obf edit uchar * rp ulong k ulong to void 688 put gq 2 rp 689 put gq 3 0 690 for j ulong k 691 p = get gq 2 692 e = syn_find p 4096 0 10 693 mc_bin mbclaims true 694 syn_at mcwho 695 syn_ap p e 696 put gq 2 add add p e 1 697 mc_who1 obf p e 698 end 699 end 700 701 fn mc_who1 obf edit uchar * p ulong e ulong to void 702 n = syn_run obf `300000000000` 703 c = ulong get gxs 0 704 mc_qnl obf n 705 mc_qt mwhoc 706 mc_qp p e 707 mc_qt mwhoe 708 syn_pd c 709 mc_qt mcl 710 mc_qb 10 711 if ne c 0 712 mc_qerr 713 end 714 end 715 716 note coord_board: claims list --all into HOME/board/claims.jsonl, then board render 717 fn mc_board tape view uint * a ulong to void 718 if not mc_done tape a 719 ret 720 end 721 obf = new uchar `1048576` 0 722 m = mc_head 723 syn_pt mrres 724 syn_pt mrtext 725 mc_bin mbclaims true 726 syn_at mclist 727 syn_at mfall 728 n = syn_run obf `300000000000` 729 c = ulong get gxs 0 730 if or ne c 0 gt get gxs 1 long n 731 mc_qt mlisterr 732 mc_qb 10 733 mc_qerr 734 mc_tail 70 735 mc_flush m 736 ret 737 end 738 d = syn_mark 739 syn_ps get gop 1 get gopl 1 740 syn_pt mslboard 741 r = syn_mkdir d syn_len d 742 syn_rew d 743 if not mc_bwrite obf n 744 mc_qt mwrerr 745 mc_qb 10 746 mc_tail 70 747 mc_flush m 748 ret 749 end 750 mc_bin mbboard false 751 syn_at mcrender 752 mc_barg mfclaims mslbcl 753 mc_barg mfmap mslmap 754 mc_barg mffind mslfind 755 mc_barg mfout mslboard 756 c = mc_runap obf 757 mc_tail c 758 mc_flush m 759 end 760 761 note mc_bpath: HOME + suffix t appended to the pool; gq 2, 3 = offset, length. The pool also holds the 762 note response being built, so every caller rewinds to gq 2 once the path is used. 763 fn mc_bpath t view uchar * to void 764 p = syn_mark 765 syn_ps get gop 1 get gopl 1 766 syn_pt t 767 put gq 2 p 768 put gq 3 syn_len p 769 end 770 771 note mc_barg: argv records flag f and HOME + suffix t 772 fn mc_barg f view uchar * t view uchar * to void 773 syn_at f 774 mc_bpath t 775 syn_ap get gq 2 get gq 3 776 syn_rew get gq 2 777 end 778 779 note mc_bwrite: write obf[0..n) to HOME/board/claims.jsonl (temp file, sync, rename); false on any failure 780 fn mc_bwrite obf view uchar * n ulong to bool 781 mc_bpath mslbcl 782 fd = syn_wbeg get gq 2 get gq 3 783 if lt fd 0 784 syn_rew get gq 2 785 ret false 786 end 787 w = write int fd obf 0 n 788 r = syn_wend fd get gq 2 get gq 3 789 syn_rew get gq 2 790 ret and eq w long n eq r 0 791 end 792 793 note ======== tools/call ======== 794 fn mc_call src view uchar * tape edit uint * tmp edit uchar * to void 795 p = get gobj 0 796 put gbad 0 0 797 put gq 0 0 798 put gq 1 0 799 if or eq p jsnone ne js_type tape p jsobj 800 mc_err 32602 mmeparm 801 ret 802 end 803 put gobj 0 p 804 nt = pu_memb2 src tape mkname 805 if or eq nt jsnone ne js_type tape nt jsstr 806 mc_err 32602 mmeparm 807 ret 808 end 809 a = pu_memb2 src tape mkargs 810 put gobj 0 a 811 if ne a jsnone 812 if ne js_type tape a jsobj 813 mc_err 32602 mbadobj 814 ret 815 end 816 end 817 o = js_off tape nt 818 if js_streq src o mtn01 819 mc_where src tape tmp 820 ret 821 end 822 if js_streq src o mtn13 823 mc_board tape a 824 ret 825 end 826 put gnm 0 o 827 if not mc_build src tape tmp 828 mc_err 32602 mmetool 829 ret 830 end 831 if mc_done tape a 832 mc_exec 833 end 834 end 835 836 note pu_memb2: value token of key in object gobj 0, or jsnone 837 fn pu_memb2 src view uchar * tape view uint * key view uchar * to ulong 838 o = get gobj 0 839 k = js_first tape o 840 while ne k jsnone bound 999999 841 if js_streq src js_off tape k key 842 ret add k 1 843 end 844 k = js_mnext tape k 845 end 846 ret jsnone 847 end 848 849 note mc_build: argv for the single-exec tools; false for an unknown tool name 850 fn mc_build src view uchar * tape view uint * tmp edit uchar * to bool 851 o = get gnm 0 852 if js_streq src o mtn02 853 mc_bin mbmap true 854 syn_at mctree 855 mc_get src tape maktext 856 mc_bool tape mftext 857 ret true 858 end 859 if js_streq src o mtn03 860 mc_bin mbmap true 861 syn_at mccheck 862 ret true 863 end 864 if js_streq src o mtn04 865 mc_bin mbclaims true 866 syn_at mcclaim 867 mc_req1 868 mc_get src tape makagent 869 sv = mc_sval src tape tmp 870 mc_semit tmp sv mfagent 871 mc_req1 872 mc_get src tape maksess 873 sv = mc_sval src tape tmp 874 mc_semit tmp sv mfsess 875 mc_req1 876 mc_get src tape maktarg 877 sv = mc_sval src tape tmp 878 mc_semit tmp sv mftarg 879 mc_get src tape makttl 880 mc_int src tape mfttl 881 mc_get src tape makmode 882 sv = mc_sval src tape tmp 883 mc_semit tmp sv mfmode 884 mc_get src tape makstate 885 sv = mc_sval src tape tmp 886 mc_semit tmp sv mfstate 887 mc_get src tape makint 888 sv = mc_sval src tape tmp 889 mc_semit tmp sv mfint 890 mc_get src tape makevid 891 mc_evid src tape tmp 892 ret true 893 end 894 if js_streq src o mtn05 895 mc_bin mbclaims true 896 syn_at mcrenew 897 mc_req1 898 mc_get src tape makagent 899 sv = mc_sval src tape tmp 900 mc_semit tmp sv mfagent 901 mc_req1 902 mc_get src tape makid 903 sv = mc_sval src tape tmp 904 mc_semit tmp sv mfid 905 mc_get src tape makttl 906 mc_int src tape mfttl 907 ret true 908 end 909 if js_streq src o mtn06 910 mc_bin mbclaims true 911 syn_at mcrel 912 mc_req1 913 mc_get src tape makagent 914 sv = mc_sval src tape tmp 915 mc_semit tmp sv mfagent 916 mc_req1 917 mc_get src tape makid 918 sv = mc_sval src tape tmp 919 mc_semit tmp sv mfid 920 mc_get src tape makstate 921 sv = mc_sval src tape tmp 922 mc_semit tmp sv mfstate 923 mc_get src tape makevid 924 mc_evid src tape tmp 925 ret true 926 end 927 if js_streq src o mtn07 928 mc_bin mbclaims true 929 syn_at mcstate 930 mc_req1 931 mc_get src tape makagent 932 sv = mc_sval src tape tmp 933 mc_semit tmp sv mfagent 934 mc_req1 935 mc_get src tape makid 936 sv = mc_sval src tape tmp 937 mc_semit tmp sv mfid 938 mc_req1 939 mc_get src tape makstate 940 sv = mc_sval src tape tmp 941 mc_semit tmp sv mfstate 942 mc_get src tape makevid 943 mc_evid src tape tmp 944 ret true 945 end 946 if js_streq src o mtn08 947 mc_bin mbclaims true 948 syn_at mcwho 949 mc_req1 950 mc_get src tape maktarg 951 sv = mc_sval src tape tmp 952 mc_spos tmp sv 953 ret true 954 end 955 if js_streq src o mtn09 956 mc_bin mbclaims true 957 syn_at mclist 958 mc_get src tape makall 959 mc_bool tape mfall 960 ret true 961 end 962 if js_streq src o mtn10 963 mc_bin mbclaims true 964 syn_at mcconf 965 ret true 966 end 967 if js_streq src o mtn11 968 mc_bin mbclaims true 969 syn_at mcver 970 ret true 971 end 972 if js_streq src o mtn12 973 mc_bin mbpulse true 974 syn_at mcrun 975 syn_at mfcbin 976 m = syn_mark 977 syn_ps get gop 0 get gopl 0 978 syn_pt mbclaims 979 syn_ap m syn_len m 980 syn_rew m 981 mc_get src tape makalert 982 mc_bool tape mfalert 983 ret true 984 end 985 if js_streq src o mtn14 986 mc_bin mbclaims true 987 syn_at mclist 988 syn_at mfprefix 989 mc_req1 990 mc_get src tape maklane 991 sv = mc_sval src tape tmp 992 mc_spos tmp sv 993 ret true 994 end 995 ret false 996 end 997 998 note ======== one request line ======== 999 fn mc_req src view uchar * tape edit uint * tmp edit uchar * to void 1000 base = syn_mark 1001 put gid 1 0 1002 r = js_parse src tape len src 1003 if lt r 0 1004 mc_err 32700 mmeparse 1005 ret 1006 end 1007 if ne js_type tape 0 jsobj 1008 mc_err 32600 mmeinv 1009 ret 1010 end 1011 iv = pu_rmemb src tape mkid 1012 if ne iv jsnone 1013 t = js_type tape iv 1014 if and and ne t jsstr ne t jsnum ne t jsnull 1015 mc_err 32600 mmeinv 1016 ret 1017 end 1018 m = syn_mark 1019 syn_pa src js_off tape iv js_span tape iv 1020 put gid 0 m 1021 put gid 1 js_span tape iv 1022 end 1023 mv = pu_rmemb src tape mkmeth 1024 jv = pu_rmemb src tape mkjrpc 1025 ok = and ne mv jsnone ne jv jsnone 1026 if ok 1027 ok = and eq js_type tape mv jsstr eq js_type tape jv jsstr 1028 end 1029 if ok 1030 ok = js_streq src js_off tape jv mk20 1031 end 1032 if eq iv jsnone 1033 syn_rew base 1034 ret 1035 end 1036 if not ok 1037 mc_err 32600 mmeinv 1038 syn_rew base 1039 ret 1040 end 1041 o = js_off tape mv 1042 if js_streq src o mminit 1043 mc_okt mrinit 1044 else 1045 if js_streq src o mmping 1046 mc_okt mrempty 1047 else 1048 if js_streq src o mmlist 1049 mc_list 1050 else 1051 if js_streq src o mmcall 1052 pv = pu_rmemb src tape mkpar 1053 put gobj 0 pv 1054 mc_call src tape tmp 1055 else 1056 mc_err 32601 mmenome 1057 end 1058 end 1059 end 1060 end 1061 syn_rew base 1062 end 1063 1064 note ======== main ======== 1065 note mc_pre: b starts with t (caller checks the length) 1066 fn mc_pre b view uchar * t view uchar * to bool 1067 for j ulong len t 1068 if ne get b j get t j 1069 ret false 1070 end 1071 end 1072 ret true 1073 end 1074 1075 note mc_envopt: option i = the environment value after prefix t; false when no variable has that prefix 1076 fn mc_envopt i ulong t view uchar * to bool 1077 b = new uchar 8192 0 1078 for e ulong ulong envcnt 1079 n = envread e b 0 len b 1080 if gt n long len t 1081 if mc_pre b t 1082 m = syn_mark 1083 syn_pa b len t sub ulong n len t 1084 put gop i m 1085 put gopl i syn_len m 1086 ret true 1087 end 1088 end 1089 end 1090 ret false 1091 end 1092 1093 fn mc_args to void 1094 n = ulong argcnt 1095 i = ulong 1 1096 while lt i n bound 1000 1097 o = syn_arg i 1098 l = ulong get gxs 2 1099 k = ulong 99 1100 if syn_seq o l mbindir 1101 k = 0 1102 end 1103 if syn_seq o l mhome 1104 k = 1 1105 end 1106 if or eq k 99 ge add i 1 n 1107 syn_die musage 64 1108 end 1109 v = syn_arg add i 1 1110 vl = ulong get gxs 2 1111 if or eq vl 0 ne get gsp v 47 1112 syn_die musage 64 1113 end 1114 put gop k v 1115 put gopl k vl 1116 i = add i 2 1117 end 1118 if eq get gopl 0 0 1119 syn_die mnobin 64 1120 end 1121 if eq get gopl 1 0 1122 if not mc_envopt 1 menvh 1123 if not mc_envopt 1 menvhm 1124 syn_die mnohome 64 1125 end 1126 syn_pt mdhome 1127 put gopl 1 syn_len get gop 1 1128 end 1129 end 1130 if eq get gopl 1 0 1131 syn_die mnohome 64 1132 end 1133 end 1134 1135 fn mc_loop to void 1136 buf = new uchar `1048576` 0 1137 tape = new uint 524288 0 1138 tmp = new uchar 65536 0 1139 put gln 0 0 1140 put gln 1 0 1141 eof = false 1142 note bound is 1..999999 per loop; 4295 x 999999 reads keeps the original `4294967295` limit 1143 while not eof bound 4295 1144 while not eof bound 999999 1145 eof = mc_chunk buf tape tmp 1146 end 1147 end 1148 bl = get gln 0 1149 if and gt bl 0 eq get gln 1 0 1150 mc_line part buf 0 bl tape tmp 1151 end 1152 end 1153 1154 note mc_chunk: read one block of stdin and answer each complete line; true at end of input 1155 note gln 0: bytes of the pending line in buf; gln 1: 1 when that line overflowed buf 1156 fn mc_chunk buf edit uchar * tape edit uint * tmp edit uchar * to bool 1157 rd = new uchar 65536 0 1158 eof = false 1159 r = read 0 rd 0 len rd 1160 if le r 0 1161 eof = true 1162 r = 0 1163 end 1164 for i ulong ulong r 1165 c = get rd i 1166 bl = get gln 0 1167 if eq c 10 1168 if eq get gln 1 1 1169 put gid 1 0 1170 mc_err 32700 mmeparse 1171 else 1172 mc_line part buf 0 bl tape tmp 1173 end 1174 put gln 0 0 1175 put gln 1 0 1176 else 1177 if lt bl len buf 1178 put buf bl c 1179 put gln 0 add bl 1 1180 else 1181 put gln 1 1 1182 end 1183 end 1184 end 1185 ret eof 1186 end 1187 1188 note mc_line: strip a trailing CR, skip blank lines, parse and answer 1189 fn mc_line buf view uchar * tape edit uint * tmp edit uchar * to void 1190 n = len buf 1191 if gt n 0 1192 if eq get buf sub n 1 13 1193 n = sub n 1 1194 end 1195 end 1196 blank = true 1197 for i ulong n 1198 c = get buf i 1199 if and and ne c 32 ne c 9 ne c 13 1200 blank = false 1201 end 1202 end 1203 if blank 1204 ret 1205 end 1206 r = js_init tape 983040 64 1207 mc_req part buf 0 n tape tmp 1208 end 1209 1210 fn main to int 1211 mc_args 1212 mc_loop 1213 ret 0 1214 end