Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(b5): mirror shows host nodes — fitView on first snapshot + client requests canvas on connect
enesfc13ac9ebe8a
diff --git a/src/main/remote/client-service.ts b/src/main/remote/client-service.tsindex 1f0ae45cc..cf26c54fb 100644--- a/src/main/remote/client-service.ts+++ b/src/main/remote/client-service.ts@@ -24,7 +24,7 @@ import { IPC } from '../../shared/ipc'import type { CanvasMutation, CanvasState, DirEntry, PtyCreateOptions } from '../../shared/types'import { genKeyPair } from './e2ee'import { OP, type Frame } from './framing'-import { CANVAS_MUTATE_METHOD, CANVAS_STATE_METHOD } from './host-service'+import { CANVAS_MUTATE_METHOD, CANVAS_REQUEST_METHOD, CANVAS_STATE_METHOD } from './host-service'import { decodeOffer } from './pairing'import { connectRelay, type RelaySocket, type RpcRequest } from './relay-socket'import { createSnapshotReassembler, type SnapshotReassembler } from './snapshot'@@ -296,7 +296,9 @@ export function initRemoteClient(win: BrowserWindow, deps?: { isPackaged?: booleourKeys,theirPubB64: offer.hostPublicKeyB64,onReady: () => {- // Bridge established with the host. Handlers are already live; nothing extra to do.+ // Bridge established. Ask the host to (re-)push its current canvas, in case our mirror+ // subscribed after the host's connect-time push (there is no replay otherwise).+ socket.notify(CANVAS_REQUEST_METHOD)},onRpc: (req) => {// The host pushes its canvas snapshot as a one-way `canvas:state` notify (id:''). Route itdiff --git a/src/main/remote/host-service.ts b/src/main/remote/host-service.tsindex c6de80cae..e34ada24b 100644--- a/src/main/remote/host-service.ts+++ b/src/main/remote/host-service.ts@@ -336,6 +336,9 @@ export function createHostHandlers(// full state, client->host one-way mutation command). Kept as constants so both sides agree.export const CANVAS_STATE_METHOD = 'canvas:state'export const CANVAS_MUTATE_METHOD = 'canvas:mutate'+// Client → host: "re-send me the current canvas now." Covers the case where the client mirror+// mounts/subscribes after the host's initial connect-time push (no replay otherwise).+export const CANVAS_REQUEST_METHOD = 'canvas:request'// The slice of RelaySocket the canvas sync needs: a one-way host->client push.export interface CanvasNotifySocket {@@ -544,6 +547,11 @@ export function initRemoteHost(win: BrowserWindow, ptyManager: PtyManager): voidif (latestCanvas) canvasSync?.setState(latestCanvas)},onRpc: (req) => {+ // A client asking for a fresh canvas snapshot → re-push the current one.+ if (req.method === CANVAS_REQUEST_METHOD) {+ canvasSync?.broadcastCurrent()+ return+ }// Canvas mutations route to the canvas sync (which forwards them to the host renderer,// the single writer); everything else is a pty RPC.if (canvasSync?.handleRpc(req)) returndiff --git a/src/renderer/canvas/RemoteSessionView.tsx b/src/renderer/canvas/RemoteSessionView.tsxindex 40003d7c1..d78034f07 100644--- a/src/renderer/canvas/RemoteSessionView.tsx+++ b/src/renderer/canvas/RemoteSessionView.tsx@@ -6,6 +6,7 @@ import {ReactFlowProvider,SelectionMode,useNodesState,+ useReactFlow,type NodeChange} from '@xyflow/react'import type { CanvasMutation, CanvasNodeState } from '@shared/types'@@ -75,6 +76,11 @@ function RemoteSessionCanvas({onClose: () => void}): React.JSX.Element {const [nodes, setNodes, onNodesChange] = useNodesState<CanvasNode>([])+ const { fitView } = useReactFlow()+ // Fit the view once, when the host's nodes first arrive: their positions are the host's canvas+ // coordinates, which may sit far outside the mirror's default (0,0) viewport — without this the+ // mirror looks empty even though the nodes are present.+ const fittedRef = useRef(false)// Guard so applying an inbound host snapshot doesn't echo back as a client mutation.const applyingHostStateRef = useRef(false)// True between drag-start and drag-stop. While the user is actively dragging a node, we ignore@@ -106,6 +112,14 @@ function RemoteSessionCanvas({})}, [connectionId, setNodes])+ // Bring the host's nodes into view the first time they arrive (host coords ≠ mirror viewport).+ useEffect(() => {+ if (fittedRef.current || nodes.length === 0) return+ fittedRef.current = true+ const id = requestAnimationFrame(() => fitView({ padding: 0.2, duration: 0 }))+ return () => cancelAnimationFrame(id)+ }, [nodes, fitView])+// Send the client's optimistic edit upstream (the host applies it; the next snapshot reconciles).const sendMutation = useCallback((mutation: CanvasMutation) => {