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(node-icon): resolve a ./ icon only where its cwd is this machine's

albaneselorenzo90ca2dc819b5
diff --git a/src/renderer/components/NodeIconPicker.tsx b/src/renderer/components/NodeIconPicker.tsx
index eb08018d4..b8bbb4b0a 100644
--- a/src/renderer/components/NodeIconPicker.tsx
+++ b/src/renderer/components/NodeIconPicker.tsx
@@ -26,6 +26,7 @@ import { createPortal } from 'react-dom'
import { create } from 'zustand'
import {
iconFileName,
+ localIconCwd,
type NodeIcon,
nodeIconMime,
normalizeNodeIcon,
@@ -193,7 +194,9 @@ function NodeIconPicker({
// An SSH project writes app-locally (its cwd is on another machine), so `portableIconPath`
// is handed the LOCAL cwd only — for an SSH project that is undefined and the path stays
// absolute, which is exactly the non-travelling icon that case can honestly offer.
- const stored = portableIconPath(saved, project.ssh ? undefined : project.cwd)
+ // `localIconCwd` is that rule, and the READ side asks the same function: written twice, the
+ // two copies drifted and the read side resolved a remote-rooted path against the local fs.
+ const stored = portableIconPath(saved, localIconCwd(project))
const next = normalizeNodeIcon({ type: 'image', path: stored })
if (!next) {
// The extension was already accepted above, so this is no longer "wrong file type" — it
diff --git a/src/renderer/lib/nodeIconImage.ts b/src/renderer/lib/nodeIconImage.ts
index b92c687c6..1a44436af 100644
--- a/src/renderer/lib/nodeIconImage.ts
+++ b/src/renderer/lib/nodeIconImage.ts
@@ -20,7 +20,7 @@
*/
import { useEffect, useState } from 'react'
import type { FsApi } from '@shared/types'
-import { type NodeIcon, nodeIconMime, resolveIconPath } from '@shared/node-icon'
+import { localIconCwd, type NodeIcon, nodeIconMime, resolveIconPath } from '@shared/node-icon'
import { sessionForProject } from '../session/session'
import { useProjects } from '../state/projects'
@@ -84,7 +84,11 @@ export function useNodeIconSrc(icon: NodeIcon | undefined, projectId?: string):
const activeProjectId = useProjects((s) => s.activeProjectId)
const pid = projectId ?? activeProjectId
const storedPath = icon?.type === 'image' ? icon.path : null
- const cwd = useProjects((s) => (pid ? s.getProject(pid)?.cwd : undefined))
+ // `localIconCwd`, not `project.cwd` — the single definition of "which cwd may a `./` icon be
+ // resolved against", shared with the picker's write side so the two cannot drift again. Selected
+ // down to ONE primitive here on purpose: the project object is rebuilt on every node
+ // serialization, so returning it would re-run this effect on every canvas edit.
+ const cwd = useProjects((s) => (pid ? localIconCwd(s.getProject(pid)) : undefined))
const [src, setSrc] = useState<string | null>(null)
useEffect(() => {
diff --git a/src/shared/node-icon.test.ts b/src/shared/node-icon.test.ts
index 9f80cbf57..214818980 100644
--- a/src/shared/node-icon.test.ts
+++ b/src/shared/node-icon.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest'
import {
iconFileName,
+ localIconCwd,
nodeIconMime,
normalizeNodeIcon,
portableIconPath,
@@ -265,3 +266,29 @@ describe('iconFileName', () => {
expect(nodeIconMime('C:\\dir.with.dots\\README')).toBeUndefined()
})
})
+
+// The read side and the write side must agree about which cwd a `./` icon may resolve against.
+// They disagreed: the picker excluded an SSH project, `useNodeIconSrc` did not — so a `./` icon
+// authored by someone with the repo checked out locally resolved, on the SSH client, to the same
+// relative path under a REMOTE root and was then read through the LOCAL fs.
+describe('localIconCwd', () => {
+ it('gives a local project its own cwd', () => {
+ expect(localIconCwd({ cwd: '/repo' })).toBe('/repo')
+ })
+
+ it('refuses an SSH project’s cwd — that path is on the host, the read is not', () => {
+ expect(localIconCwd({ cwd: '/srv/repo', ssh: { server: {}, remoteCwd: '/srv/repo' } })).toBeUndefined()
+ // ...which makes a `./` icon simply not draw, rather than read an unrelated local file.
+ expect(
+ resolveIconPath('./images/a.png', localIconCwd({ cwd: '/srv/repo', ssh: {} }))
+ ).toBeUndefined()
+ // An absolute path is unaffected — and absolute is what the write side stores for SSH.
+ expect(resolveIconPath('/appdata/canvas-images/a.png', localIconCwd({ cwd: '/srv/repo', ssh: {} })))
+ .toBe('/appdata/canvas-images/a.png')
+ })
+
+ it('answers undefined for a cwd-less or unknown project rather than guessing', () => {
+ expect(localIconCwd({})).toBeUndefined()
+ expect(localIconCwd(undefined)).toBeUndefined()
+ })
+})
diff --git a/src/shared/node-icon.ts b/src/shared/node-icon.ts
index 6cc18a0d7..7b65a32d8 100644
--- a/src/shared/node-icon.ts
+++ b/src/shared/node-icon.ts
@@ -271,3 +271,26 @@ export function resolveIconPath(storedPath: string, projectCwd?: string): string
// two entries for one file.
return `${root}/${rel.replace(/\\/g, '/')}`
}
+
+/**
+ * The cwd a `./` icon path may be resolved against, given a project — or undefined when there
+ * isn't one it can honestly use.
+ *
+ * This exists because the rule was written TWICE and the two copies drifted, which is the failure
+ * this repo warns about elsewhere. The picker's write side already said
+ * `project.ssh ? undefined : project.cwd`; the read side said only `project.cwd`. For an SSH
+ * project those are different facts: `cwd` is a path on the REMOTE host, while the icon is read
+ * through the LOCAL `api.fs` (an SSH project runs on the local session — only a RELAY tab's api
+ * belongs to another machine). So a `./` icon written by someone who has that repo checked out
+ * locally resolved, on the SSH client, to the same relative path under a remote root — and asked
+ * this machine to read it. That is a local file that has nothing to do with the icon, and it is
+ * shown if it happens to exist.
+ *
+ * Answering undefined means the icon does not draw, which is the honest outcome: that file is on
+ * a machine whose filesystem this reader cannot see. Absolute paths are unaffected, and absolute
+ * is exactly what the write side stores for an SSH project.
+ */
+export function localIconCwd(project: { cwd?: string; ssh?: unknown } | undefined): string | undefined {
+ if (!project || project.ssh) return undefined
+ return project.cwd
+}