GeezerVison is showing github.com — Merge pull request #46 from i2cjak/backplane/device-onboarding-state-… · BackplaneWorks/Backplane@1943ed7
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: AGENTS.md +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -42,6 +42,7 @@ When using Bend: | 42 | 42 | - `src/core/hier.bend`: hierarchical schematics (pure: the sheets a file lists, paths resolved beside their parent, the tree as pre-order rows, where a row sits, its parent and children; a sheet that includes an ancestor is listed but never expanded; laws `hier_*`). main.bend's `Tree.load` reads every file the root reaches after each schematic read and sends the rows (`Sheets`); the window keeps them in the scratch (`@vw.tree`, `@vw.at`) and shows a trail and the sheet list (`Side.*` in layout.bend; actions `vw-sheet`, `vw-open`, `vw-up`). Test: `test/hier_test.bend`; headless: `test/native/sheet_frame.bend ROOT.kicad_sch`. | 43 | 43 | - The board viewer keeps its scene in (layer, key) order, which is paint order, so a frame is one pass (`V.Ops.scene`); items off the panel are culled before any geometry is transformed. The settled scene is drawn once per view into the frame's base by `src/gfx/fresh.bend` (`Fresh.frame`: the ops split into 64 px blocks, dealt over the cores, the image put together; the same image `R.Frame.render` draws), so a pan or zoom redraws it in parallel; the tiles compare a base only where their ops are the same (`Eq.tile`), and `Eq.image` stops at the first difference. Filled polygons are anti-aliased by distance to their nearest edge (`Cov.poly` in raster.bend). Bench: `test/native/viewer_bench.bend FILE [W H]` (pan, zoom and keys with the viewer open, each frame checked exact). Layers turn on and off per kind with a flip mask (`@vw.flip.<kind>`, `V.Look.on`; laws `look_flip_*`, `ops_hidden_draws_nothing`, `pick_hidden_skipped`). Bench: `test/native/board_frame.bend BOARD.kicad_pcb`. | 44 | 44 | - Bots in the window: `src/app/bots.bend` (`Bv`: the sidebar's cats and rooms under the projects, a bot's header and tabs, rooms, remote bots; `Bv.frame` wraps `Lay.frame.x`, whose hooks add to the sidebar and replace the main area), `src/app/space.bend` (`Spv`: a bot's space blocks drawn natively), `src/app/forms.bend` (`Fm`: clipped chips and form fields whose text is the client's `@f.<name>` scratch; nui.bend's `Fld` edits them, focus id `Fld.id(name, enter action, value prefix)`), `src/app/cats.bend` (`Cats`: core/cat.bend's cats flattened once per look+mood into a cache kept in main.bend's `Kept`, posed per frame). Cat frames: 33 ms timer (main.bend's `Shell.cats`) only while `Bv.moving` (a moving mood, window focused: `@blur`, no lightbox). A bot's browser frames load as images keyed `shot:<bot>:<n>` (main.bend's `Shot`). Screens without a window: `build/bots_snap DIR` (`test/native/bots_snap.bend`). | | 45 | +- The owner's machines pair and sync by themselves (client.bend's `Mate.*`: the lower address asks `POST /bots/pair`, owner-trusted, and joins the invite it answers; `--no-tailscale` hubs pair only with `BACKPLANE_PEERS`); Settings' "Your machines" (`Mate.rows`, all four clients) shows each and turns one off (`sync.<name>`: `Far.own`, `Side.projs`). A pull carries the owner's catalog (`Fr.catalog`, `Fh.lasts`, `Fh.cat`), so a client lists a machine's projects at once and marks each "(syncing)", faded, until the link's head passes its last number (`Fr.syncing`, `Label.syncing`). `>machine:slug` names a thread elsewhere (refs.bend's `Refs.x.*`); `src/core/xref.bend` resolves it from the hub's mirror for the agent and answers `thread_read` on it. Laws `mate_*`, `far_catalog_*`, `refs_machine_word`; tests `test/far_test.bend`, `test/refs_test.bend`, `bun test/tools/far_e2e.ts`. See docs/bots.md "Threads elsewhere". | 45 | 46 | - `src/core/far.bend`: threads elsewhere (pure: a linked machine's things named `<link>~<id>`, what a hub shares with the owner's other machines, batches taken once and in order with gaps pulled, a client's fold that never moves its own sequence, requests routed to the owning hub with the real reply preserved, the hub's feed, pushes and mirrors, history epochs and isolated projection resets; laws `far_*`). `src/server/server.bend`'s `Far.*`/`Hub.far.*` do the IO: `POST /far/push`, `/far/log`, `/far/rpc`, mirrors in `<home>/far/<link>.jsonl`. The owner shares projects and ordinary threads as well as bots. `Label.title` names their machine and availability in every UI; a mirrored bot uses the usual bot views, and `Far.arrived` adopts a reported-only choice when its thread arrives (native focus follows in `Nui.unremote`). Discovery offers a head hint and pulls authoritative history with `Far.returned` / `Far.offer`, so a quick owning-hub restart or a hint arriving before ownership recognition cannot strand an old mirror. Phones drop mirrored projects and active rows only once the paired owner has that entity (`Hubs.catalog.*`), and share the sidebar view preference across hubs; hidden fold counts are deduplicated and a paired owner keeps its machine badge. `Hubs.origin.*` also names a direct paired owner on Active rows and focused thread/bot headers, marking an offline socket away without relabeling an already-marked far view. See docs/bots.md "Threads elsewhere". Tests: `test/far_test.bend`, `bun test/tools/far_e2e.ts`; `test/native/far_bench.bend` measures real bot frames, and `test/native/link_bench.bend` times a window switch to another hub. | 46 | 47 | - `src/core/bothub.bend`'s `Dir.*` and `DirWork.*`: per-peer directory merges and a four-slot deduplicating refresh queue (laws `remote_dir_*`). `src/server/botnet.bend` uses two-second connect/four-second total deadlines and atomically caches the directory in `<home>/bots.cache`; the hub publishes each peer as it arrives, restores cached rows away at startup, and refreshes on links and peer return. Tests: `test/botdir_test.bend`, `test/tools/botdir_e2e.ts`. | 47 | 48 | - `src/core/subs.bend`: the Subagents panel (pure): the tasks a thread delegated and what Claude runs for it (Agent calls, background shells and monitors: model.bend's `Bg`, whose line keeps the call, what it was asked and its kind, `Bg.kind`; a shell's row reads "shell: …" and only subagents count as agents). A subagent's lines (`parent_tool_use_id`) go to its own log, `M.Bg.log(thread)` (`@sub:<thread>`, off the timeline; hub.bend's `Sub.*`), never the thread's messages. Rows at work say what they do now; a subagent at work shows its newest steps until shut (`fold` action, key `sub:<call>`); the panel is outlined in the accent with "N at work" while any work, and a sidebar row says "N agents" where its age goes (`Subs.badge`). The panel is open while any row works and folds to its head ("Subagents · 3 done") once all are done; a click on the head opens or shuts it, and that choice holds (`Subs.panel.*`, the `fold` action with key `subs:<thread>`); folded, the web's panel scrolls with the thread instead of sticking to its top. Window `Lay.subs`/`Sa.*` (above the timeline), web `View.subs` (sticky), phones `subs` (above the composer). Laws `subs_*`, `bg_start_keeps_call`; test `test/subagents_test.bend`. | |
Collapse file Copy file name to clipboardExpand all lines: LAWS.bend +84Lines changed: 84 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5739,3 +5739,87 @@ law tour_scroll_up_stops: | 5739 | 5739 |
| 5740 | 5740 | law tour_scroll_none: | 5741 | 5741 | {N.Tour.scroll(0n, 0n, False{}) == 0n : Nat} | | 5742 | + | | 5743 | +# Pairing the owner's machines (client.bend's Mate.*): the hub with the | | 5744 | +# lower address asks a machine of the owner's it is not linked to; never | | 5745 | +# one already linked, never one sync is off with, never from the higher | | 5746 | +law mate_lower_asks: | | 5747 | + {U.Mate.due(True{}, U.Mate.demo("http://100.1.0.1:3787"), Nil{}, M.State.empty()) == [U.MRow{"desk", "http://100.2.0.1:3787", True{}}] : List<&2, U.MRow>} | | 5748 | + | | 5749 | +law mate_higher_waits: | | 5750 | + {U.Mate.due(True{}, U.Mate.demo("http://100.3.0.1:3787"), Nil{}, M.State.empty()) == Nil{} : List<&2, U.MRow>} | | 5751 | + | | 5752 | +law mate_linked_never_asks: | | 5753 | + {U.Mate.due(True{}, U.Mate.demo("http://100.1.0.1:3787"), [BOT.Peer{"p1", "desk", "http://desk.t.ts.net:3787", 0n, False{}}], M.State.empty()) == Nil{} : List<&2, U.MRow>} | | 5754 | + | | 5755 | +law mate_off_never_asks: | | 5756 | + {U.Mate.due(True{}, U.Mate.demo("http://100.1.0.1:3787"), Nil{}, M.State.setting(M.State.empty(), "sync.desk", "off")) == Nil{} : List<&2, U.MRow>} | | 5757 | + | | 5758 | +law mate_no_self_never_asks: | | 5759 | + {U.Mate.due(True{}, U.Mate.demo(""), Nil{}, M.State.empty()) == Nil{} : List<&2, U.MRow>} | | 5760 | + | | 5761 | +# a hub without its own tailnet pairs only with machines BACKPLANE_PEERS | | 5762 | +# names, never with the owner's tailnet machines it lists | | 5763 | +law mate_unnamed_without_tailnet: | | 5764 | + {U.Mate.due(False{}, U.Mate.demo("http://100.1.0.1:3787"), Nil{}, M.State.empty()) == Nil{} : List<&2, U.MRow>} | | 5765 | + | | 5766 | +# the machine asked answers an invite, unless the asker is none of the | | 5767 | +# machines it found, sync with it is off there or a live link reaches it | | 5768 | +law mate_answer_stranger: | | 5769 | + {U.Mate.answer(U.Mate.demo("http://100.3.0.1:3787"), Nil{}, M.State.empty(), "desk", "http://127.0.0.1:9999") == 3n : Nat} | | 5770 | + | | 5771 | +law mate_answer_invites: | | 5772 | + {U.Mate.answer(U.Mate.demo("http://100.3.0.1:3787"), Nil{}, M.State.empty(), "desk", "http://desk.t.ts.net:3787") == 0n : Nat} | | 5773 | + | | 5774 | +law mate_answer_off: | | 5775 | + {U.Mate.answer(U.Mate.demo("http://100.3.0.1:3787"), Nil{}, M.State.setting(M.State.empty(), "sync.desk", "off"), "desk", "http://desk.t.ts.net:3787") == 1n : Nat} | | 5776 | + | | 5777 | +law mate_answer_linked: | | 5778 | + {U.Mate.answer(U.Mate.demo("http://100.3.0.1:3787"), [BOT.Peer{"p1", "desk", "http://desk.t.ts.net:3787", 0n, False{}}], M.State.empty(), "desk", "http://desk.t.ts.net:3787") == 2n : Nat} | | 5779 | + | | 5780 | +# a machine sync is off with lists nothing of its own in the sidebar | | 5781 | +law mate_off_hidden: | | 5782 | + {U.Mate.hidden(FR.Fr.mark(M.State.setting(M.State.empty(), "sync.desk", "off"), "L", "desk", False{}), "L~p1") == True{} : Bool} | | 5783 | + | | 5784 | +law mate_on_shown: | | 5785 | + {U.Mate.hidden(FR.Fr.mark(M.State.empty(), "L", "desk", False{}), "L~p1") == False{} : Bool} | | 5786 | + | | 5787 | +# A catalog lists a link's projects at once; each is catching up until the | | 5788 | +# link's head reaches its last number, and a project here never is | | 5789 | +law far_catalog_stands_in: | | 5790 | + {U.Side.pids(U.Side.sorted(FR.Fr.cat.demo(0n), 0n)) == ["L~p1"] : List<&2, String>} | | 5791 | + | | 5792 | +law far_catalog_syncing: | | 5793 | + {FR.Fr.syncing(FR.Fr.cat.demo(4n), "L~p1") == True{} : Bool} | | 5794 | + | | 5795 | +law far_catalog_caught_up: | | 5796 | + {FR.Fr.syncing(FR.Fr.cat.demo(5n), "L~p1") == False{} : Bool} | | 5797 | + | | 5798 | +law far_catalog_here_never: | | 5799 | + {FR.Fr.syncing(FR.Fr.cat.demo(0n), "p1") == False{} : Bool} | | 5800 | + | | 5801 | +law far_catalog_titled: | | 5802 | + {U.Label.title(FR.Fr.cat.demo(4n), "L~p1", "Board") == "Board · desk (syncing)" : String} | | 5803 | + | | 5804 | +# a change's project: its own, or its thread's | | 5805 | +law far_scope_thread: | | 5806 | + {FR.Fr.scope(M.State.apply(M.State.empty(), M.ThreadCreated{"t1", "p1", "x", M.Local{}, "", "", "claude", "", 1n}), M.MessagePosted{"t1", "m1", M.User{}, "hi", 2n}) == "p1" : String} | | 5807 | + | | 5808 | +law far_scope_project: | | 5809 | + {FR.Fr.scope(M.State.empty(), M.ProjectCreated{"p2", "x", "/x", 1n}) == "p2" : String} | | 5810 | + | | 5811 | +# a thread on another of the owner's machines is `>machine:slug`; a word | | 5812 | +# ending in ':' still names a thread here (`>fix: it fails`) | | 5813 | +law refs_machine_word: | | 5814 | + {RF.Refs.x.word("desk:fix-perf") == True{} : Bool} | | 5815 | + | | 5816 | +law refs_colon_after_stays_here: | | 5817 | + {RF.Refs.x.word("fix:") == False{} : Bool} | | 5818 | + | | 5819 | +# two hubs on one machine compare their loopback addresses, so exactly | | 5820 | +# one of them asks: 4001 asks 4002, and 4003 does not ask 4002 | | 5821 | +law mate_loopback_lower_asks: | | 5822 | + {U.Mate.due(False{}, U.Mate.demo.lo("4001"), Nil{}, M.State.empty()) == [U.MRow{"127.0.0.1", "http://127.0.0.1:4002", True{}}] : List<&2, U.MRow>} | | 5823 | + | | 5824 | +law mate_loopback_higher_waits: | | 5825 | + {U.Mate.due(False{}, U.Mate.demo.lo("4003"), Nil{}, M.State.empty()) == Nil{} : List<&2, U.MRow>} |
Collapse file Copy file name to clipboardExpand all lines: PROOF.bend +69Lines changed: 69 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7463,3 +7463,72 @@ def Laws.tour_scroll_up_stops(): | 7463 | 7463 |
| 7464 | 7464 | def Laws.tour_scroll_none(): | 7465 | 7465 | {==} | | 7466 | + | | 7467 | +def Laws.mate_lower_asks(): | | 7468 | + {==} | | 7469 | + | | 7470 | +def Laws.mate_higher_waits(): | | 7471 | + {==} | | 7472 | + | | 7473 | +def Laws.mate_linked_never_asks(): | | 7474 | + {==} | | 7475 | + | | 7476 | +def Laws.mate_off_never_asks(): | | 7477 | + {==} | | 7478 | + | | 7479 | +def Laws.mate_no_self_never_asks(): | | 7480 | + {==} | | 7481 | + | | 7482 | +def Laws.mate_answer_invites(): | | 7483 | + {==} | | 7484 | + | | 7485 | +def Laws.mate_answer_off(): | | 7486 | + {==} | | 7487 | + | | 7488 | +def Laws.mate_answer_linked(): | | 7489 | + {==} | | 7490 | + | | 7491 | +def Laws.mate_off_hidden(): | | 7492 | + {==} | | 7493 | + | | 7494 | +def Laws.mate_on_shown(): | | 7495 | + {==} | | 7496 | + | | 7497 | +def Laws.far_catalog_stands_in(): | | 7498 | + {==} | | 7499 | + | | 7500 | +def Laws.far_catalog_syncing(): | | 7501 | + {==} | | 7502 | + | | 7503 | +def Laws.far_catalog_caught_up(): | | 7504 | + {==} | | 7505 | + | | 7506 | +def Laws.far_catalog_here_never(): | | 7507 | + {==} | | 7508 | + | | 7509 | +def Laws.far_catalog_titled(): | | 7510 | + {==} | | 7511 | + | | 7512 | +def Laws.far_scope_thread(): | | 7513 | + {==} | | 7514 | + | | 7515 | +def Laws.far_scope_project(): | | 7516 | + {==} | | 7517 | + | | 7518 | +def Laws.mate_unnamed_without_tailnet(): | | 7519 | + {==} | | 7520 | + | | 7521 | +def Laws.mate_answer_stranger(): | | 7522 | + {==} | | 7523 | + | | 7524 | +def Laws.refs_machine_word(): | | 7525 | + {==} | | 7526 | + | | 7527 | +def Laws.refs_colon_after_stays_here(): | | 7528 | + {==} | | 7529 | + | | 7530 | +def Laws.mate_loopback_lower_asks(): | | 7531 | + {==} | | 7532 | + | | 7533 | +def Laws.mate_loopback_higher_waits(): | | 7534 | + {==} |
Collapse file Copy file name to clipboardExpand all lines: docs/bots.md +47Lines changed: 47 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -205,6 +205,7 @@ you type: | 205 | 205 | |---|---|---| | 206 | 206 | | `@name`, `@name@machine` | a bot, here or on a linked machine | the bot is woken (hop 0) with the message and the thread it came from; it can `thread_read` it and answer with `thread_send` | | 207 | 207 | | `>slug` | a thread | the agent is told the thread's id, project and summary | | | 208 | +| `>machine:slug` | a thread on another of the owner's machines | the agent is told what it is and where; `thread_read` reads it | | 208 | 209 | | `%slug` | a project | the agent is told the project's id, folder and summary | | 209 | 210 | | `#slug` | a group chat | the message is posted in the room | | 210 | 211 |
| @@ -222,6 +223,19 @@ the bot hears the message as the person's, with the thread's title, which | 222 | 223 | it cannot read, and answers in the person's conversation with it | 223 | 224 | (`Bots.mention.far`, the same room `bots.tell` writes in). | 224 | 225 |
| | 226 | +Threads synced from the owner's other machines (below, "Threads | | 227 | +elsewhere") are offered as `>machine:slug`, the machine by its name as a | | 228 | +slug (`Refs.x.*`); their rows start with the machine's name, which a query | | 229 | +matches too, and `>machine:` alone offers only that machine's threads. A | | 230 | +`>machine:slug` never names a thread here (`>fix: it fails` still names | | 231 | +`fix`: a slug must follow the colon, laws `refs_machine_word`, | | 232 | +`refs_colon_after_stays_here`). The hub has no read model of other | | 233 | +machines' threads, only its mirror of each, so `src/core/xref.bend` folds | | 234 | +the one mirror a word names when it must: for the agent's | | 235 | +`<references>` block (server.bend's `Far.turn`, around `Bots.turn`), and | | 236 | +for `thread_read` on a `<link>~<id>` (`Xref.read`, answered from the | | 237 | +mirror, before the MCP call reaches the hub). | | 238 | + | 225 | 239 | The menu (`Refs.offer` in `src/core/refs.bend`) ranks by how well the | 226 | 240 | query matches the slug or name (fuzzy), a query of three or more letters | 227 | 241 | found in the summary, then nearness: the same project, recent work, pinned | @@ -591,6 +605,39 @@ owner's (`Far.own` in server.bend: the machines list; laws `far_*_stay_home`). | 591 | 605 | its cached mirror stays visible until then. Direct paired-owner Active rows and focused thread/bot headers keep the machine name too; an offline owner is marked away, and an already-marked mirror keeps its original title. When the paired owner differs from | 592 | 606 | the focused hub, its machine badge remains visible. Hidden Older and Settled | 593 | 607 | counts also drop duplicates. | | 608 | +- Pairing. The owner's machines link by themselves; nobody pastes an | | 609 | + invite (`Mate.*` in client.bend). Every two minutes a hub lists the | | 610 | + tailnet's online machines of its owner that answer `GET /hello` | | 611 | + (`Machines.*`), and each minute it asks those it is not linked to and | | 612 | + whose address is above its own (so of two hubs exactly one asks) with | | 613 | + `POST /bots/pair?name=<its name>&url=<its address>`. Only the owner's | | 614 | + own devices may call it (the tailnet listener's `tailscale whois`, the | | 615 | + same trust as the websocket); the answer is a fresh invite, joined like | | 616 | + a pasted one (`BotJob.join`), unless the asker is none of the machines | | 617 | + the hub found (403: its link could not reach back), sync with it is off | | 618 | + (403) or a live link already reaches it (409). A hub started with | | 619 | + `--no-tailscale` still lists the tailnet machines to switch to but pairs | | 620 | + only with hubs `BACKPLANE_PEERS` names (`named`), so a throwaway hub | | 621 | + never links itself to real ones. Laws `mate_*`; `test/tools/far_e2e.ts` | | 622 | + pairs its two hubs this way. | | 623 | +- Choosing. Settings, Your machines (all four clients, `Mate.rows`) lists | | 624 | + each machine found, how its sync goes (linking, in sync, catching up N | | 625 | + projects, away) and On/Off: the setting `sync.<name>`. Off, nothing is | | 626 | + pushed to it or taken from it (`Far.own`), it is not asked to pair, it | | 627 | + is refused if it asks, and its projects leave the sidebar | | 628 | + (`Side.projs`, law `mate_off_hidden`). | | 629 | +- Catching up. A pull's answer carries the owner's catalog: every project | | 630 | + it shares, with its title, latest activity and the number of its last | | 631 | + shared change (`Fr.catalog`; the feed keeps each project's number as it | | 632 | + grows, `Fh.lasts`). The mirroring hub tells clients and keeps it for | | 633 | + those that join later (`Fh.cat`, the mirror's last chunk). A client | | 634 | + lists every project at once, in its place (a project not arrived yet | | 635 | + stands in with its title and activity), and marks each still catching | | 636 | + up while the link's head is short of its number (`wait~<id>`, | | 637 | + `Fr.syncing`): faded, titled "Board · desk (syncing)", on all four | | 638 | + clients through `Label.title`/`Label.syncing` and the phones' `quiet`. | | 639 | + Projects that have arrived work meanwhile, and nothing pops in or moves. | | 640 | + Laws `far_catalog_*`, `far_scope_*`. | 594 | 641 | - Not mirrored: streamed text while a far turn runs (its messages arrive as | 595 | 642 | they are posted), file viewers for far project threads, and a bot's browser. | 596 | 643 |
| |
|