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): persist client canvas edits + re-broadcast on host project switch
enesea54ac7347c1
diff --git a/src/main/pty-manager.ts b/src/main/pty-manager.tsindex 1a551e7d3..7887d7d42 100644--- a/src/main/pty-manager.ts+++ b/src/main/pty-manager.ts@@ -175,7 +175,9 @@ export class PtyManager {* the node id as the `persistKey` reattaches the existing `nt-<nodeId>` session if it exists,* or creates it otherwise (graceful fallback). Used by the relay host so a mirrored terminal* resumes the host's live session instead of opening a blank shell. Pair with `captureSnapshot`- * to paint the current screen before live output starts streaming.+ * to paint the current screen before live output starts streaming. Note: reusing+ * `new-session -A -D` detaches the host's own local tmux client (a takeover) — acceptable+ * because the B5 host is unattended while a client is mirroring it.*/attachDetached(persistKey: string,@@ -204,17 +206,6 @@ export class PtyManager {}}- /** Whether a tmux session for this node id currently exists (host attach-vs-create decision). */- async hasSession(persistKey: string): Promise<boolean> {- if (!this.tmuxPath) return false- try {- await runAsync(this.tmuxPath, ['-L', TMUX_SOCKET, 'has-session', '-t', sessionName(persistKey)])- return true- } catch {- return false- }- }-private spawnSession(options: PtyCreateOptions,webContentsId: number | null,diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex eb70f69f0..1110f0902 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -371,6 +371,11 @@ export function Canvas() {// Let load-induced changes settle before we start tracking edits as dirty.const t = setTimeout(() => {loadingRef.current = false+ // The broadcast effect early-returns while `loadingRef` is set and isn't re-triggered by the+ // reset, so push the freshly-loaded project's canvas once now — otherwise a connected client+ // keeps mirroring the previous project until the host's next edit. Benign with no client+ // attached (main only forwards to a live client).+ window.nodeTerminal.remoteHost.sendCanvasState({ nodes: flowToNodeStates(nodesRef.current) })// Consume a cross-project focus request (notification click on a background node).const pending = pendingFocusRef.currentif (pending) {@@ -437,22 +442,20 @@ export function Canvas() {}, [nodes])// Apply a client's mutation to React Flow — the host's single writer. Serialize the live nodes,- // apply the mutation, and convert back, guarded by `loadingRef` so the resulting `setNodes` does- // not mark the project dirty (it's a remote edit; the normal change path persists it). The- // change re-triggers the broadcast effect above, echoing the authoritative state to the client.+ // apply the mutation, and convert back. A direct `setNodes(...)` bypasses `handleNodesChange`,+ // so we must mark the project dirty EXPLICITLY — otherwise a client-driven move/delete is lost+ // on host restart/project switch. The `[nodes]` change re-triggers the broadcast effect above,+ // echoing the authoritative state back to the client (intended). The remote edit is also picked+ // up by the undo-snapshot effect, which is acceptable.useEffect(() => {return window.nodeTerminal.remoteHost.onApplyMutation((mutation) => {- loadingRef.current = truesetNodes((ns) => {const next = applyCanvasMutation(flowToNodeStates(ns), mutation)return nodeStatesToFlow(next)})- // Release the guard after the state flush so dirty-marking resumes for local edits.- queueMicrotask(() => {- loadingRef.current = false- })+ markDirty()})- }, [setNodes])+ }, [setNodes, markDirty])// Record an undo snapshot when the canvas settles (debounced; skips drag frames/loads).useEffect(() => {diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.tsindex d672ed1e4..ace95b848 100644--- a/src/renderer/state/workspace.ts+++ b/src/renderer/state/workspace.ts@@ -100,33 +100,6 @@ export function createTerminalNode(}}-/**- * Creates a terminal node bound to a REMOTE host over the relay. Identical to a local terminal- * except `data.remote.connectionId` is set, which makes TerminalNode pick RemoteTransport instead- * of LocalTransport. Not persisted (see flowToNodeStates).- */-export function createRemoteTerminalNode(- connectionId: string,- index: number,- center?: { x: number; y: number }-): CanvasNode {- return {- id: nextId('remote'),- type: 'terminal',- position: placeAt(center, index, TERMINAL_SIZE.width, TERMINAL_SIZE.height),- width: TERMINAL_SIZE.width,- height: TERMINAL_SIZE.height,- style: { width: TERMINAL_SIZE.width, height: TERMINAL_SIZE.height },- data: {- title: 'Remote terminal',- color: NODE_COLORS[index % NODE_COLORS.length],- group: null,- tags: [],- remote: { connectionId }- }- }-}-/*** Path to the bridge MCP config, fetched once from main at boot (see Canvas). When set, new* Claude nodes launch with `--mcp-config <path>` so the Session Bridge tools are available indiff --git a/test/remote/b5-e2e.test.ts b/test/remote/b5-e2e.test.tsindex 150e3b57e..15b07d204 100644--- a/test/remote/b5-e2e.test.ts+++ b/test/remote/b5-e2e.test.ts@@ -381,7 +381,7 @@ describe('B5 remote project mirror end-to-end (real relay + real handlers + fake// === (5) E2EE: no host->relay frame leaks plaintext (node id / file payload) ===expect(hostSentFrames.length).toBeGreaterThan(0)- for (const needleStr of ['hello', contents]) {+ for (const needleStr of ['hello', contents, 'n-1']) {const needle = Buffer.from(needleStr)const leaked = hostSentFrames.find((frame) => Buffer.from(frame).includes(needle))expect(leaked, `a host->relay frame leaked the plaintext "${needleStr}"`).toBeUndefined()