Skip to content

feat(agents): an agents port between webviews over Tauri events - #1737

Closed
loganj wants to merge 1 commit into
agent-host-port-session-retypefrom
agent-host-event-port
Closed

loganj wants to merge 1 commit into
agent-host-port-session-retypefrom
agent-host-event-port

Conversation

@loganj

@loganj loganj commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

🤖

Summary

  • Stacked on feat(agents): session state and the retype preview over the agents port #1734. In layer 3 the agents service runs in a hidden agents web view and the screens stay in main. A MessagePort cannot connect two web views, so this adds a port that carries the agents protocol over Tauri events.
  • Nothing uses it yet, so behavior does not change. The agents window PR will connect the two pages with it and add the event permissions.

Details

  • eventPort(from, to) returns the port shape the protocol already uses (onmessage, postMessage, close). AgentsPort in port.ts names that shape, and MessagePort still fits it.
  • Order: separate emits are separate IPC requests and can arrive out of order. The protocol needs a call's answer to arrive after the state push before it. So each frame has a sequence number, and the receiver holds a frame until the frames before it have arrived.
  • Startup and reload: each page load is a session. A page announces its session once it listens, and answers a new peer's announcement with its own. Until it knows the peer, it holds what it sends. Frames name the session they are for. When a page reloads, the other page starts again with the new session and drops late frames from the old one. What was sent to a page that reloaded is lost with it.
  • Frames also name the sending web view, so a third web view cannot pose as the peer.
  • connectAgents now sends hello on connect, and the service answers it with a full push. A screens' page that reloads gets the current state without waiting for a change.
  • Messages are JSON on this path. The protocol already sends plain data.

Testing

  • event-port.test.ts, over a fake event bus that delivers each batch in reverse and as JSON:
    • Frames that arrive out of order are delivered in the order sent.
    • What a page sends before the other page is up waits for it.
    • A reloaded page is served afresh, and the old page's late frame is dropped.
    • Frames for another web view are ignored.
  • port.test.ts: the real service and client over two event ports, with the screens' page loading first. Then the screens' page reloads and still gets the state.
  • Mutation checks: each of these makes its test fail: removing the hold that restores order, removing the drop of a reloaded page's frames, and removing hello.
  • tsc --noEmit, Biome, and vitest run src/features/agents (726 passed) pass.

🤖 Generated with Claude Code

The agents protocol can now run between pages in two webviews. Frames
are numbered and held until their turn, since separate emits can arrive
out of order and an answer must not overtake its state push. Each page
load is a session: a page announces itself once it listens, holds what
it sends until it knows the other page, and drops late frames from a
page that reloaded. The screens' client says hello on connect, so a
reloaded screens' page gets the current state without waiting for a
change. Nothing uses it yet.

Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Logan Johnson <loganj@squareup.com>
@loganj

loganj commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Closing this PR because the column stack contains its work. event-port.ts is in #1893 (#1893), and link.ts from #1833 (#1833) replaces port.ts.

@loganj loganj closed this Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant