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.

fix(canvas): make "New terminal here" mean here on a remote project

albaneselorenzo27c83121e8d5
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 3e8560c36..9b45bfa90 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -492,6 +492,7 @@ import {
createDinoNode,
createTriggerNode,
createFilesNode,
+ sshBindingForCwd,
createDiffNode,
createEditorNode,
createGroupNode,
@@ -3599,10 +3600,13 @@ export function Canvas() {
console.info(
`[nodeterm] node-create agent=- project=${targetProjectId} group=${groupId ?? '-'} cwd=${cwd ?? '-'}`
)
+ // In an SSH project the node is stamped remote (runs over the project's master) and
+ // `createTerminalNode` roots it at `ssh.remoteCwd`, which silently discards a caller's
+ // "here" — see `sshBindingForCwd` for the whole reasoning. With no override this is
+ // byte-identical to before.
+ const ssh = sshBindingForCwd(project?.ssh, cwdOverride)
setNodes((ns) => {
- // In an SSH project the node is stamped remote (runs over the project's master); the
- // factory takes the project's ssh and roots the terminal at its remoteCwd.
- const node = createTerminalNode(ns.length, cwd, center ?? emptyNodePos(), initialCommand, project?.ssh)
+ const node = createTerminalNode(ns.length, cwd, center ?? emptyNodePos(), initialCommand, ssh)
return [...ns, groupId ? parentInto(node, groupId) : node]
})
markDirty()
diff --git a/src/renderer/nodes/FilesNode.tsx b/src/renderer/nodes/FilesNode.tsx
index a332e1bdb..07eac57f2 100644
--- a/src/renderer/nodes/FilesNode.tsx
+++ b/src/renderer/nodes/FilesNode.tsx
@@ -235,7 +235,13 @@ export function FilesNode({ id, data, selected }: NodeProps<CanvasNode>) {
if (entry) {
items.push({ label: entry.dir ? 'Open folder' : 'Open', onClick: () => open(entry) })
}
- if (!entry || entry.dir) {
+ // "here" has to be somewhere a terminal can actually be opened. `addTerminal` spawns
+ // against the ACTIVE project, and a relay project carries no `ssh` binding — so on a relay
+ // tab this would hand the PEER's path to a plain local terminal, the same wrong-machine
+ // mistake `fileOpenTarget` refuses for `shell.openPath`. Spawning onto a peer's core is a
+ // real feature, not a one-liner, so the row is withheld rather than faked. (An SSH project
+ // is fine: `addTerminal` now rebinds `remoteCwd` to the requested directory.)
+ if ((!entry || entry.dir) && source !== 'relay') {
items.push({
label: 'New terminal here',
onClick: () =>
@@ -257,7 +263,7 @@ export function FilesNode({ id, data, selected }: NodeProps<CanvasNode>) {
}
setMenu({ x: e.clientX, y: e.clientY, items })
},
- [cwd, open, create, api, localShell]
+ [cwd, open, create, api, localShell, source]
)
const toggleCollapse = () =>
diff --git a/src/renderer/state/workspace.test.ts b/src/renderer/state/workspace.test.ts
index fbfd8d141..e42f60edc 100644
--- a/src/renderer/state/workspace.test.ts
+++ b/src/renderer/state/workspace.test.ts
@@ -20,6 +20,7 @@ import {
reparentNode,
resolveNewNodeAccount,
selectedRootIds,
+ sshBindingForCwd,
ungroupNodes
} from './workspace'
import type { CanvasNode } from './workspace'
@@ -1079,3 +1080,32 @@ describe('createAgentNode prompt injection', () => {
expect(createAgentNode('gemini', 0, undefined, undefined, 'do X').data.initialCommand).toBe("gemini 'do X'")
})
})
+
+describe('sshBindingForCwd', () => {
+ const ssh = { server: { host: 'h', user: 'u' }, remoteCwd: '/srv/app' } as never
+
+ // The bug: "New terminal here" on an SSH project opened at the project root, because
+ // createTerminalNode does `cwd: ssh ? ssh.remoteCwd : cwd` and threw the request away.
+ it('rebinds remoteCwd to the directory the caller actually named', () => {
+ expect(sshBindingForCwd(ssh, '/srv/app/src/renderer')).toMatchObject({
+ remoteCwd: '/srv/app/src/renderer'
+ })
+ })
+
+ it('leaves the binding alone when no directory was named', () => {
+ expect(sshBindingForCwd(ssh, undefined)).toBe(ssh)
+ })
+
+ // An SSH project can still carry a LOCAL project.cwd. Promoting a resolved cwd instead of an
+ // explicit override would root remote terminals at a path from the wrong machine, so the
+ // trigger is the override and nothing else.
+ it('never invents a binding for a local project', () => {
+ expect(sshBindingForCwd(undefined, '/home/me/work')).toBeUndefined()
+ })
+
+ it('does not mutate the project\'s own binding', () => {
+ const before = { ...(ssh as object) }
+ sshBindingForCwd(ssh, '/elsewhere')
+ expect(ssh).toEqual(before)
+ })
+})
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.ts
index b9309457d..de57e4653 100644
--- a/src/renderer/state/workspace.ts
+++ b/src/renderer/state/workspace.ts
@@ -301,6 +301,26 @@ export function nodeSshFor(
return { server: projectSsh.server, remoteCwd: cwd || projectSsh.remoteCwd }
}
+/**
+ * The ssh binding a terminal should be created with when the caller named a directory.
+ *
+ * `createTerminalNode` roots a remote node at `ssh.remoteCwd` and ignores its `cwd` argument
+ * (`cwd: ssh ? ssh.remoteCwd : cwd`). That is right for a plain "new terminal" and wrong for
+ * every caller that meant a SPECIFIC directory — a file manager's "New terminal here", a Source
+ * Control action scoped to a checkout — because on an SSH project the request was discarded in
+ * silence and the terminal opened at the project root.
+ *
+ * Keyed on an EXPLICIT override, never on a resolved cwd: an SSH project can still carry a local
+ * `project.cwd`, and promoting that to `remoteCwd` would root remote terminals at a path from the
+ * wrong machine. With no override the binding is returned untouched.
+ */
+export function sshBindingForCwd(
+ ssh: Project['ssh'] | undefined,
+ cwdOverride: string | undefined
+): Project['ssh'] | undefined {
+ return ssh && cwdOverride ? { ...ssh, remoteCwd: cwdOverride } : ssh
+}
+
export function createTerminalNode(
index: number,
cwd?: string,