Skip to content

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.

refactor(relay): remove data.remote + createRemoteTerminalNode (Stage 4 Task 10)

enes7b4147cd754e
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 50f92c539..65a6f3072 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -2458,8 +2458,7 @@ export function Canvas() {
// Permanent delete: the upcoming unmount must dispose the xterm, not park it (the
// session is being destroyed right here). Also drops an already-parked entry.
if (n.type === 'terminal') disposeTerminalOnUnmount(n.id)
- // Remote terminals have no local persistent session — only destroy local ones.
- if (n.type === 'terminal' && !n.data.remote) transport.destroy(n.id)
+ if (n.type === 'terminal') transport.destroy(n.id)
// Chat nodes: permanently kill the SDK driver + drop the live chat state. The driver
// lives across project switches (only permanent delete kills it), so this belongs here,
// not in node unmount.
@@ -2473,20 +2472,6 @@ export function Canvas() {
useAgentStatus.getState().remove(n.id)
useAgentNodes.getState().clearLoop(n.id)
})
- // Tear down relay connections owned solely by the deleted remote node(s). The model is
- // N:1 (one connection per remote node), but dedupe defensively: only disconnect a
- // connectionId if no *surviving* remote node still uses it, so we never drop a live one.
- const deletedConns = new Set<string>()
- const survivingConns = new Set<string>()
- nodesRef.current.forEach((n) => {
- const conn = (n.data.remote as { connectionId: string } | undefined)?.connectionId
- if (!conn) return
- if (set.has(n.id)) deletedConns.add(conn)
- else survivingConns.add(conn)
- })
- deletedConns.forEach((conn) => {
- if (!survivingConns.has(conn)) void window.nodeTerminal.remoteClient.disconnect(conn)
- })
setNodes((ns) => {
// Free children of any deleted group back to absolute positions.
const groupPos = new Map(
@@ -3090,9 +3075,7 @@ export function Canvas() {
// silently (the confirm closing with nothing happening reads as a bug).
//
// The question is the PROJECT's (does its git — and its tmux — run over ssh?) and the NODE's
- // (`isRemoteSessionNode`: relay `data.remote` OR an SSH project's `data.ssh`/`data.sshRemoteTmux`).
- // Guarding `data.remote` alone asked only about relay nodes, which cannot occur in an SSH project
- // at all — so the one node kind this exists to protect walked straight through it.
+ // (`isRemoteSessionNode`: an SSH project's `data.ssh`/`data.sshRemoteTmux`).
if (isSshProject || isRemoteSessionNode(node.data)) {
setNotice({ kind: 'error', text: WORKTREE_SSH_NOTICE })
return
diff --git a/src/renderer/components/ExplorerPanel.tsx b/src/renderer/components/ExplorerPanel.tsx
index f95f5451c..3707155b1 100644
--- a/src/renderer/components/ExplorerPanel.tsx
+++ b/src/renderer/components/ExplorerPanel.tsx
@@ -158,10 +158,9 @@ function TreeEntry({
* SSH projects browse the REMOTE filesystem (rooted at `project.ssh.remoteCwd`, listed via
* `sshFs(projectId)` over the ControlMaster); local projects use the local fs rooted at `cwd`.
*
- * NOTE (relay, Task 6): the RELAY path is still local-only — in a relay session the host's root cwd
- * isn't known client-side (the local project's `cwd` is the client's). Once `canvas:state` carries
- * the host cwd, this can also switch to `remoteFs(connectionId)` for relay projects (the Editor
- * already proxies over the relay via `data.remote.connectionId`). */
+ * NOTE (relay): a relay session's Explorer is still rooted at the local project's `cwd` — the host's
+ * root cwd isn't known client-side. A relay tab reaches the host fs through its bridged session api
+ * (the same seam TerminalNode/EditorNode use), not a separate per-connection fs client. */
export function ExplorerPanel({ onClose, onOpenFile, reveal }: ExplorerPanelProps) {
const project = useProjects((s) => s.projects.find((p) => p.id === s.activeProjectId))
// SSH projects browse the REMOTE filesystem: root at the project's `remoteCwd` and list over the
diff --git a/src/renderer/nodes/EditorNode.tsx b/src/renderer/nodes/EditorNode.tsx
index feee45275..88f93f7c3 100644
--- a/src/renderer/nodes/EditorNode.tsx
+++ b/src/renderer/nodes/EditorNode.tsx
@@ -3,7 +3,6 @@ import { Handle, NodeResizer, Position, useReactFlow, type NodeProps } from '@xy
import { monaco } from '../editor/monaco-setup'
import { renderMarkdown } from '../lib/markdown'
import { useSettings } from '../state/settings'
-import { remoteFs } from '../terminal/remote-fs'
import { sshFs } from '../terminal/ssh-fs'
import { useProjects } from '../state/projects'
import { useSession } from '../session/session'
@@ -48,17 +47,11 @@ export function EditorNode({ id, data, selected }: NodeProps<CanvasNode>) {
const fileMissing = !!data.fileMissing
// This node's core api (a stable context read — the local session's api IS window.nodeTerminal).
const { api } = useSession()
- // Backend pick (the `FsApi` shape is identical across all three, so the rest of the component is
- // unchanged): a relay session operates on the HOST's filesystem via the relay; an SSH-project
- // editor (`data.sshFs`) on the project's remote fs over the ControlMaster; otherwise the
- // session's fs.
+ // Backend pick (the `FsApi` shape is identical across both, so the rest of the component is
+ // unchanged): an SSH-project editor (`data.sshFs`) operates on the project's remote fs over the
+ // ControlMaster; otherwise the session's fs.
const activeProjectId = useProjects((s) => s.activeProjectId)
- const connectionId = data.remote?.connectionId
- const fs = connectionId
- ? remoteFs(connectionId)
- : data.sshFs && activeProjectId
- ? sshFs(activeProjectId)
- : api.fs
+ const fs = data.sshFs && activeProjectId ? sshFs(activeProjectId) : api.fs
const fileName = filePath.split('/').pop() || 'untitled'
const ext = fileName.includes('.') ? fileName.split('.').pop()!.toLowerCase() : ''
const isImage = ext in IMAGE_MIME
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 46837361e..97d17bd92 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -390,8 +390,8 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
// not exist on the host. Both halves of "remote" are asked: the project (its terminals and its git
// run over ssh — a local project that LATER became an SSH one still carries the old binding, and
// its worktree directory may well still exist locally, so nothing else here would notice) and the
- // node (`isRemoteSessionNode` — an SSH-project terminal carries `data.ssh`/`data.sshRemoteTmux`,
- // never `data.remote`). The affordance is absent, not merely refused on click.
+ // node (`isRemoteSessionNode` — an SSH-project terminal carries `data.ssh`/`data.sshRemoteTmux`).
+ // The affordance is absent, not merely refused on click.
const sshProject = useProjects((s) => !!s.projects.find((p) => p.id === s.activeProjectId)?.ssh)
const remoteSession = sshProject || isRemoteSessionNode(data)
const canMoveIntoWorktree =
@@ -665,28 +665,25 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
if (event.metaKey || event.ctrlKey) window.nodeTerminal.shell.openExternal(uri)
})
)
- // Relay-remote nodes have no client-side fs to verify paths against — URLs only.
- if (!data.remote) {
- const projectFs = (): { fs: FsApi; ssh: boolean } => {
- const st = useProjects.getState()
- const project = st.projects.find((p) => p.id === st.activeProjectId)
- return project?.ssh ? { fs: sshFs(project.id), ssh: true } : { fs: api.fs, ssh: false }
- }
- const lookup = makeDirListingLookup(async (dir) => projectFs().fs.list(dir))
- term.registerLinkProvider(
- createFileLinkProvider(term, {
- getCwd: () => (data.cwd as string | undefined) || undefined,
- lookup,
- activate: (abs, isDir) => {
- if (isDir) window.dispatchEvent(new CustomEvent('nodeterm:reveal-file', { detail: { path: abs } }))
- else
- window.dispatchEvent(
- new CustomEvent('nodeterm:open-file', { detail: { path: abs, ssh: projectFs().ssh } })
- )
- }
- })
- )
+ const projectFs = (): { fs: FsApi; ssh: boolean } => {
+ const st = useProjects.getState()
+ const project = st.projects.find((p) => p.id === st.activeProjectId)
+ return project?.ssh ? { fs: sshFs(project.id), ssh: true } : { fs: api.fs, ssh: false }
}
+ const lookup = makeDirListingLookup(async (dir) => projectFs().fs.list(dir))
+ term.registerLinkProvider(
+ createFileLinkProvider(term, {
+ getCwd: () => (data.cwd as string | undefined) || undefined,
+ lookup,
+ activate: (abs, isDir) => {
+ if (isDir) window.dispatchEvent(new CustomEvent('nodeterm:reveal-file', { detail: { path: abs } }))
+ else
+ window.dispatchEvent(
+ new CustomEvent('nodeterm:open-file', { detail: { path: abs, ssh: projectFs().ssh } })
+ )
+ }
+ })
+ )
}
// Cmd+C (mac) / Ctrl+Shift+C (Linux, Windows) / Ctrl+Insert copy the terminal selection — xterm
@@ -723,7 +720,7 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
let handedOff: ParkedTerminal | null = null
// Kill the PTY client at most once per session: the effect cleanup, a park dispose and a
// still-in-flight spawn continuation can all reach for it. `PtyManager.kill` tolerates a
- // repeat, but `RemoteTransport.kill` forwards to the relay unconditionally.
+ // repeat, but the guard keeps the kill idempotent across all three callers.
const killSession = (sid: string): void => {
if (life.killed) return
life.killed = true
@@ -734,18 +731,6 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
// `!parked` so nothing is wired twice.
const cleanups: Array<() => void> = parked ? parked.cleanups : []
- // Remote nodes: surface a dropped relay connection (host gone / socket closed) so the
- // terminal isn't silently frozen. The actual relay teardown on node *deletion* happens
- // in Canvas.deleteNodes (which can dedupe a connectionId shared by sibling nodes).
- const remoteConn = (data.remote as { connectionId: string } | undefined)?.connectionId
- if (!parked && remoteConn) {
- cleanups.push(
- window.nodeTerminal.remoteClient.onClosed(remoteConn, () => {
- term.write('\r\n\x1b[31m[remote disconnected]\x1b[0m\r\n')
- })
- )
- }
-
// Agent state (busy/idle/attention) comes from the agent's own hooks via the
// agent:status IPC (handled centrally in Canvas) — not from parsing the output here.
// We only surface the conversation topic from the terminal title, when the agent sets one.
@@ -914,7 +899,7 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
// `cleanups` has unsubscribed everything and the session is killed. `life.dead` (flipped
// before the teardown in BOTH paths: the effect cleanup and the park dispose) is the
// authority: past it there is no session left to un-pause, and `transport.setFlow` would
- // address a dead one (RemoteTransport forwards to the relay unconditionally).
+ // address a dead one.
const relieve = (bytes: number): void => {
if (life.dead) return
pending -= bytes
@@ -1655,14 +1640,7 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
className="term-node__close"
title="Close (ends the session)"
onClick={() => {
- const remoteConn = (data.remote as { connectionId: string } | undefined)?.connectionId
- if (remoteConn) {
- // Remote node: no local tmux to destroy; tear down the relay connection
- // (socket + keepalive + main-process map entry). N:1, so this owns it.
- void window.nodeTerminal.remoteClient.disconnect(remoteConn)
- } else {
- transport.destroy(id)
- }
+ transport.destroy(id)
deleteElements({ nodes: [{ id }] })
}}
>
diff --git a/src/renderer/state/workspace.mutation.test.ts b/src/renderer/state/workspace.mutation.test.ts
index b66309cf9..2ca7eb43a 100644
--- a/src/renderer/state/workspace.mutation.test.ts
+++ b/src/renderer/state/workspace.mutation.test.ts
@@ -55,16 +55,6 @@ describe('applyMutationToFlow', () => {
expect(out[0].position).toEqual({ x: 50, y: 0 })
})
- // flowToNodeStates FILTERS remote nodes (transient to a relay connection, never persisted), so
- // the round trip deleted every relay terminal on your canvas on each peer mutation.
- it('keeps relay-remote nodes, which a serialize round trip would delete', () => {
- const nodes = [flowNode('r1', 0, { data: { title: 'r', color: '#fff', group: null, remote: { connectionId: 'c1' } } } as Partial<CanvasNode>), flowNode('a', 0)]
- expect(flowToNodeStates(nodes).map((n) => n.id)).toEqual(['a']) // …the lossy bit, pinned
- const out = applyMutationToFlow(nodes, upsert(state('a', 5)))
- expect(out.map((n) => n.id)).toEqual(['r1', 'a'])
- expect(out[0]).toBe(nodes[0])
- })
-
// initialCommand / respawnNonce / forkFrom are deliberately not serialized. A peer's rename must
// not silently drop them from a node that has not consumed them yet.
it('keeps local-only node data (initialCommand) while applying the peer\'s fields', () => {
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.ts
index c713eaf6e..2bc0e00b0 100644
--- a/src/renderer/state/workspace.ts
+++ b/src/renderer/state/workspace.ts
@@ -87,12 +87,6 @@ export interface NodeData {
accountId?: string
/** group-only: the git worktree this group is bound to (single source of truth). */
worktree?: import('@shared/worktree').GroupWorktree
- /**
- * When set, this terminal runs on a REMOTE host over the relay (RemoteTransport) rather than
- * the local PTY (LocalTransport). Not persisted — remote nodes are transient to a live
- * connection (see flowToNodeStates).
- */
- remote?: { connectionId: string }
/**
* When set, this terminal runs `ssh` to a remote host on the LOCAL PTY (LocalTransport).
* Unlike `remote` (relay), this IS persisted — the node auto-reconnects on relaunch.
@@ -176,33 +170,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 }
- }
- }
-}
-
/**
* Creates a terminal node that runs `ssh` to a saved server on the local PTY. The connection
* is snapshotted inline (`data.ssh`) so the node survives the server being edited/deleted.
@@ -972,9 +939,6 @@ export function flowToNodeStates(nodes: CanvasNode[]): CanvasNodeState[] {
? CHAT_SIZE
: TERMINAL_SIZE
return nodes
- // Remote terminals are transient to a live relay connection — never persist them (their
- // connectionId is dead after a restart, and they'd otherwise reattach to a stray local tmux).
- .filter((n) => !n.data.remote)
.map((n) => {
const kind: NodeKind = (n.type as NodeKind) ?? 'terminal'
const collapsed = !!n.data.collapsed
@@ -1025,9 +989,6 @@ export function flowToNodeStates(nodes: CanvasNode[]): CanvasNodeState[] {
* every peer mutation — 20 times a second while a teammate drags:
* - SELECTION. `nodeStatesToFlow` never sets `selected`, so a teammate's drag wiped your
* box-select / shift-click / select-then-group the instant it landed.
- * - REMOTE NODES. `flowToNodeStates` filters `!n.data.remote` (they are transient to a relay
- * connection and must never persist), so round-tripping DELETED every relay terminal on your
- * canvas.
* - LOCAL-ONLY DATA. `initialCommand`, `respawnNonce`, `forkFrom` never survive a serialize.
* - IDENTITY. Every node object was rebuilt → every node component re-rendered, per mutation.
* Patching in place keeps all four: untouched nodes keep their object identity (React.memo holds),
diff --git a/src/shared/worktree.test.ts b/src/shared/worktree.test.ts
index b55457f97..d5912a491 100644
--- a/src/shared/worktree.test.ts
+++ b/src/shared/worktree.test.ts
@@ -26,14 +26,13 @@ const entry = (path: string, branch: string | null): WorktreeEntry => ({
isBare: false
})
-// Worktrees are local-only in v1, and the gate that keeps a remote session out of one used to ask
-// about `data.remote` — a field ONLY a relay node (`createRemoteTerminalNode`) carries, and one that
-// can never occur inside an SSH project. So the exact node the gate exists to protect — an
-// SSH-PROJECT terminal, created by `createTerminalNode(…, project.ssh)` with `data.ssh` +
-// `data.sshRemoteTmux` — walked straight through it: ↪ destroyed its REMOTE tmux session (running
-// processes and all) and respawned it in a local path that does not exist on the host.
+// Worktrees are local-only in v1, and the gate that keeps a remote session out of one must ask
+// about BOTH SSH markers: the exact node it exists to protect — an SSH-PROJECT terminal, created by
+// `createTerminalNode(…, project.ssh)` with `data.ssh` + `data.sshRemoteTmux` — once walked straight
+// through a one-field guard: ↪ destroyed its REMOTE tmux session (running processes and all) and
+// respawned it in a local path that does not exist on the host.
describe('isRemoteSessionNode', () => {
- it('is true for an SSH-project terminal (data.ssh + data.sshRemoteTmux — never data.remote)', () => {
+ it('is true for an SSH-project terminal (data.ssh + data.sshRemoteTmux)', () => {
expect(
isRemoteSessionNode({
ssh: { host: 'box', user: 'me' },
@@ -42,10 +41,6 @@ describe('isRemoteSessionNode', () => {
).toBe(true)
})
- it('is true for a relay-bound remote terminal (data.remote)', () => {
- expect(isRemoteSessionNode({ remote: { connectionId: 'c1' } })).toBe(true)
- })
-
it('is true when only one of the two SSH markers survived a hand-edited project file', () => {
expect(isRemoteSessionNode({ ssh: { host: 'box', user: 'me' } })).toBe(true)
expect(isRemoteSessionNode({ sshRemoteTmux: true })).toBe(true)
@@ -54,7 +49,7 @@ describe('isRemoteSessionNode', () => {
it('is false for a plain local terminal (nothing changes for the local case)', () => {
expect(isRemoteSessionNode({})).toBe(false)
expect(isRemoteSessionNode(undefined)).toBe(false)
- expect(isRemoteSessionNode({ ssh: undefined, remote: undefined, sshRemoteTmux: false })).toBe(false)
+ expect(isRemoteSessionNode({ ssh: undefined, sshRemoteTmux: false })).toBe(false)
})
})
diff --git a/src/shared/worktree.ts b/src/shared/worktree.ts
index e3f6931bd..ac137fbd0 100644
--- a/src/shared/worktree.ts
+++ b/src/shared/worktree.ts
@@ -32,8 +32,6 @@ export interface WorktreeListResult {
/** The node fields that can say "this session does not run on this machine". */
interface RemoteNodeLike {
- /** Relay-bound node (`createRemoteTerminalNode`) — not persisted. */
- remote?: unknown
/** SSH-PROJECT terminal (`createTerminalNode(..., project.ssh)`) — the connection it runs on. */
ssh?: unknown
/** SSH-PROJECT terminal: its tmux server lives on the host, not here. */
@@ -48,13 +46,12 @@ interface RemoteNodeLike {
* never be moved into one — its session would be destroyed and respawned into a directory that does
* not exist there, and the dead path would be persisted to `project.json`.
*
- * THREE different fields mean "remote", and guarding only one is how the exact node this protects
- * slipped through: `data.remote` is set ONLY by `createRemoteTerminalNode` (relay nodes, never
- * persisted, never inside an SSH project), while an SSH-PROJECT terminal carries `data.ssh` +
- * `data.sshRemoteTmux` and NEVER `data.remote`. Ask about all of them.
+ * An SSH-PROJECT terminal carries BOTH `data.ssh` (the connection it runs on) and
+ * `data.sshRemoteTmux` (its tmux server lives on the host), and guarding only one is how the exact
+ * node this protects slipped through — so ask about both.
*/
export function isRemoteSessionNode(data: RemoteNodeLike | undefined): boolean {
- return !!(data && (data.remote || data.ssh || data.sshRemoteTmux))
+ return !!(data && (data.ssh || data.sshRemoteTmux))
}
/**