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): displacing a file manager must not silently point it at /

albaneselorenzofd5dd452750a
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 9b45bfa90..84f58f1f5 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -309,6 +309,7 @@ const sshConnect: SshConnectFn = (scopeId, conn, remoteCwd) =>
const sshDisconnect = (scopeId: string): Promise<unknown> =>
window.nodeTerminal.sshProject.disconnect(scopeId)
import { opensInEditor } from '../lib/openTarget'
+import { displacedFilesPatch } from '../lib/filesNode'
import { newEntryPath, parentDir } from '../lib/explorerCreate'
import {
explorerIsOpen,
@@ -4634,6 +4635,14 @@ export function Canvas() {
* `data.fileMissing` instead of rewritten. The node stays on the canvas (never auto-closed: it
* may hold unsaved Monaco edits the user hasn't copied out yet) and renders a persistent notice.
*
+ * A files node is caught by path wherever it sits (it has no session to disturb, so the `under`
+ * restriction terminals get does not apply) and IS re-pointed — a directory can be, a dead file
+ * cannot. Two things are special because it SHOWS its cwd rather than merely running in it:
+ * with no fallback it is left alone rather than written `undefined`, since `FilesNode` reads
+ * `data.cwd || '/'` and would quietly start listing the filesystem root; and its title is
+ * rewritten alongside when `titleAuto` still holds, because this is the one cwd write that does
+ * not go through `navigate`, the only other place that pairs the two.
+ *
* `respawn` separates the two callers (terminal only — editor/diff has no session to touch):
* - Remove (true): the directory is being deleted under live sessions, so their tmux sessions are
* destroyed and the terminals respawn straight into the fallback cwd.
@@ -4667,6 +4676,13 @@ export function Canvas() {
if (n.type === 'editor' || n.type === 'diff') {
return { ...n, data: { ...n.data, fileMissing: true } }
}
+ if (n.type === 'files') {
+ // A file manager SHOWS its cwd, so re-pointing it is not the same operation as
+ // re-pointing a terminal that merely runs in one. `null` = leave it alone; see
+ // `displacedFilesPatch` for both rules and why the no-fallback case must not write.
+ const patch = displacedFilesPatch(n.data, fallbackCwd)
+ return patch ? { ...n, data: { ...n.data, ...patch } } : n
+ }
return {
...n,
data: {
diff --git a/src/renderer/lib/filesNode.test.ts b/src/renderer/lib/filesNode.test.ts
index 52a055d6c..bdac92919 100644
--- a/src/renderer/lib/filesNode.test.ts
+++ b/src/renderer/lib/filesNode.test.ts
@@ -3,6 +3,7 @@ import {
breadcrumbs,
childPath,
classifyEmptyListing,
+ displacedFilesPatch,
fileOpenTarget,
filterEntries,
folderTitle,
@@ -140,3 +141,23 @@ describe('classifyEmptyListing', () => {
expect(classifyEmptyListing('/repo/link', listed)).toBe('empty')
})
})
+
+describe('displacedFilesPatch', () => {
+ it('re-points to the fallback and renames while the title still tracks the folder', () => {
+ expect(displacedFilesPatch({}, '/repo/src')).toEqual({ cwd: '/repo/src', title: 'src' })
+ })
+
+ // The `titleAuto` contract: a name the user typed is never overwritten by a cwd change,
+ // whether that change came from navigating or from a worktree being removed underneath.
+ it('leaves a hand-typed title alone', () => {
+ expect(displacedFilesPatch({ titleAuto: false }, '/repo/src')).toEqual({ cwd: '/repo/src' })
+ })
+
+ // The one that matters: FilesNode reads `data.cwd || '/'`, so writing undefined would make a
+ // displaced node silently list the filesystem ROOT. Doing nothing leaves it on the dead path,
+ // where the parent-listing probe tells the truth instead.
+ it('refuses to write anything when there is no fallback directory', () => {
+ expect(displacedFilesPatch({}, undefined)).toBeNull()
+ expect(displacedFilesPatch({ titleAuto: false }, '')).toBeNull()
+ })
+})
diff --git a/src/renderer/lib/filesNode.ts b/src/renderer/lib/filesNode.ts
index 38479d2fc..e6464c18e 100644
--- a/src/renderer/lib/filesNode.ts
+++ b/src/renderer/lib/filesNode.ts
@@ -74,6 +74,32 @@ export function folderTitle(path: string): string {
* entry depending on the leg, and mistaking one for "missing" is the false alarm this exists to
* avoid.
*/
+/**
+ * How a files node is re-pointed when the worktree it was living in is removed
+ * (`resetDisplacedCwd`). It is caught by path wherever it sits, like an editor and unlike a
+ * terminal, because it has no session to disturb — and it is re-pointed rather than flagged
+ * `fileMissing`, because a directory can be re-pointed and a dead file cannot.
+ *
+ * `null` means LEAVE IT ALONE, and that is the interesting answer: with no fallback directory
+ * there is nowhere honest to send it, and writing `undefined` is worse than doing nothing —
+ * `FilesNode` reads `data.cwd || '/'`, so the node would silently begin listing the filesystem
+ * ROOT. Left on the dead path, the parent-listing probe says "Could not read this folder", which
+ * is the truth.
+ *
+ * The title rides along while `titleAuto` holds. This is the one cwd write that does NOT go
+ * through `navigate` — the only other place that pairs the two — so without it the node moves to
+ * a new directory still wearing the removed worktree's name.
+ */
+export function displacedFilesPatch(
+ data: { titleAuto?: unknown },
+ fallbackCwd: string | undefined
+): { cwd: string; title?: string } | null {
+ if (!fallbackCwd) return null
+ return data.titleAuto !== false
+ ? { cwd: fallbackCwd, title: folderTitle(fallbackCwd) }
+ : { cwd: fallbackCwd }
+}
+
export type EmptyListingVerdict = 'empty' | 'missing' | 'unknown'
export function classifyEmptyListing(