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(kanban): route card file links by the card's project; keep .html editable outside link opens

review236add16856c
diff --git a/CLAUDE.md b/CLAUDE.md
index e77252007..27c2b9074 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -1654,8 +1654,15 @@ session.
found" + Copy path; "Couldn't check: <reason>" when its existence could not be checked) — its
press was already swallowed, and a silent swallow reads as broken.
Downloads report in a `DownloadStrip` floated over the terminal, not in a drawer that may be
- shut. The kanban card modal gets URL rows only (no file links there) and no "Open in canvas
- browser" (the node would land under the board).
+ shut. The kanban card modal's right-click menu has URL rows only and no "Open in canvas
+ browser" (the node would land under the board). Its Cmd/Ctrl+click DOES follow file links, with
+ main's token model and lookup, but routed by the CARD's project, not the active one
+ (`lib/cardFileLinks.ts` — the Omni board opens cards from every project; any doubt turns file
+ links off): a file opens in `LocalFilePreviewModal` over the card (HTML copied into the agent-web
+ jail and shown under its strict CSP; source text in a browser tab, which has no webview), whose
+ "Open on canvas" is offered only for a card of the active project. On the canvas a LOCAL `.html`
+ opened by a link or that button renders as a WebNode (`fileViewerKind`'s `renderHtml`, carried as
+ `view: true` on `nodeterm:open-file`); Explorer, ⌘K and the files node still open it in the editor.
**Hovering a link says what a click opens** (`terminal/link-hover.ts`): the RESOLVED absolute
path — which of the two cwds held it — plus the gestures, `<abs> (⌘-click to open · ⇧⌘-click to
open with default app)` (Ctrl/Shift+Ctrl off-mac; a directory reads "reveal" / "open in
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 325ab2570..d3c717be1 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -5555,15 +5555,22 @@ export function Canvas() {
[confirmAndMount]
)
- /** Open a file in the appropriate canvas viewer. Local HTML gets a locked-down WebNode;
- * Markdown/text, images and PDFs use EditorNode (which already provides their previews), and
- * audio/video use VideoNode. `sshFs` must be passed explicitly by the
+ /** Open a file in the appropriate canvas viewer. Markdown/text, images and PDFs use EditorNode
+ * (which already provides their previews), audio/video use VideoNode, and a LOCAL .html opened
+ * with `renderHtml` (a terminal link / card preview — never Explorer or ⌘K, where the user is
+ * editing the source) renders in a WebNode: a sandboxed <webview>, no node integration, the
+ * same surface `show-web --file` uses. `sshFs` must be passed explicitly by the
* caller: only genuinely-remote, Explorer-opened files in an SSH project pass `true`; native
* dialog / quick-open paths are LOCAL and stay local (so their ⌘S never writes to the host).
* A file that is already open focuses its existing node instead of stacking a duplicate;
* a fresh node is born `selected` so React Flow elevates it above the node stack. */
const openFile = useCallback(
- (filePath: string, center?: { x: number; y: number }, sshFs?: boolean) => {
+ (
+ filePath: string,
+ center?: { x: number; y: number },
+ sshFs?: boolean,
+ opts: { renderHtml?: boolean } = {}
+ ) => {
const existing = nodesRef.current.find(
(n) =>
(n.type === 'editor' || n.type === 'video' || n.type === 'web') &&
@@ -5573,7 +5580,7 @@ export function Canvas() {
focusNodeRef.current(existing.id)
return
}
- const viewerKind = fileViewerKind(filePath, sshFs)
+ const viewerKind = fileViewerKind(filePath, { sshFs, renderHtml: opts.renderHtml })
setNodes((ns) => [
...ns.map((n) => (n.selected ? { ...n, selected: false } : n)),
{
@@ -5757,14 +5764,16 @@ export function Canvas() {
useEffect(() => {
const uncoverCanvas = (): void => {
const projectId = useProjects.getState().activeProjectId
- if (isGlobalKanbanOpen()) useViewMode.getState().toggleGlobalKanban()
- if (isKanbanOpen(projectId)) useViewMode.getState().toggle(projectId)
+ if (isGlobalKanbanOpen() || isKanbanOpen(projectId)) showCanvas(projectId)
}
const onOpen = (e: Event): void => {
- const d = (e as CustomEvent<{ path: string; ssh?: boolean }>).detail
+ const d = (e as CustomEvent<{ path: string; ssh?: boolean; view?: boolean }>).detail
if (d?.path) {
uncoverCanvas()
- openFile(d.path, undefined, d.ssh)
+ // `view` = a terminal link / card preview asking to SEE the file: a local .html renders as a
+ // page. Explorer, ⌘K and the files node leave it unset and keep editing the source. A
+ // browser tab has no <webview>, so it always gets the editor.
+ openFile(d.path, undefined, d.ssh, { renderHtml: !!d.view && !isBrowserRuntime() })
}
}
const onReveal = (e: Event): void => {
diff --git a/src/renderer/canvas/open-file-view.source.test.ts b/src/renderer/canvas/open-file-view.source.test.ts
new file mode 100644
index 000000000..0437ae3c8
--- /dev/null
+++ b/src/renderer/canvas/open-file-view.source.test.ts
@@ -0,0 +1,31 @@
+import { readFileSync } from 'node:fs'
+import { join } from 'node:path'
+import { describe, expect, it } from 'vitest'
+
+// `view: true` on `nodeterm:open-file` is what turns a local .html into a rendered WebNode
+// (Canvas.openFile → fileViewerKind's `renderHtml`). Only a request to SEE a file may carry it — a
+// terminal link and the card preview's "Open on canvas". Explorer, ⌘K and the files node open .html
+// to EDIT its source, so they must not.
+const read = (rel: string): string =>
+ readFileSync(join(__dirname, '..', rel), 'utf8').replace(/\r\n/g, '\n')
+
+const dispatches = (src: string): string[] =>
+ [...src.matchAll(/new CustomEvent\('nodeterm:open-file',\s*\{[\s\S]*?\}\s*\)/g)].map((m) => m[0])
+
+describe('nodeterm:open-file view flag', () => {
+ it('terminal links and the card preview ask to view', () => {
+ for (const rel of ['nodes/TerminalNode.tsx', 'components/kanban/LocalFilePreviewModal.tsx']) {
+ const ds = dispatches(read(rel))
+ expect(ds.length, rel).toBeGreaterThan(0)
+ for (const d of ds) expect(d, rel).toMatch(/view:\s*true/)
+ }
+ })
+
+ it('the files node opens to edit', () => {
+ for (const d of dispatches(read('nodes/FilesNode.tsx'))) expect(d).not.toMatch(/view:/)
+ })
+
+ it('Canvas renders HTML only for a view request, never in a browser tab', () => {
+ expect(read('canvas/Canvas.tsx')).toContain('renderHtml: !!d.view && !isBrowserRuntime()')
+ })
+})
diff --git a/src/renderer/components/kanban/CardModal.test.tsx b/src/renderer/components/kanban/CardModal.test.tsx
index ee2a342c8..3bdae1059 100644
--- a/src/renderer/components/kanban/CardModal.test.tsx
+++ b/src/renderer/components/kanban/CardModal.test.tsx
@@ -40,10 +40,12 @@ vi.mock('./ModalTerminal', async () => {
ModalTerminal: ({
nodeId,
covered,
+ projectId,
onOpenFile
}: {
nodeId: string
covered?: boolean
+ projectId?: string
onOpenFile?: (file: { path: string; projectId: string; ssh: boolean }) => void
}) => {
useEffect(() => {
@@ -53,7 +55,13 @@ vi.mock('./ModalTerminal', async () => {
}
}, [])
return (
- <div className="kanban-modal__term" data-node-id={nodeId} data-covered={String(!!covered)} tabIndex={0}>
+ <div
+ className="kanban-modal__term"
+ data-node-id={nodeId}
+ data-project-id={projectId}
+ data-covered={String(!!covered)}
+ tabIndex={0}
+ >
Terminal Mock
<button
className="modal-terminal-file-link"
@@ -174,6 +182,8 @@ describe('CardModal', () => {
)
)
+ // File links resolve against the CARD's project, which the modal hands to its live viewer.
+ expect(document.body.querySelector<HTMLElement>('.kanban-modal__term')?.dataset.projectId).toBe('p1')
act(() => {
document.body.querySelector<HTMLButtonElement>('.modal-terminal-file-link')!.click()
})
diff --git a/src/renderer/components/kanban/CardModal.tsx b/src/renderer/components/kanban/CardModal.tsx
index 09150078c..82b486aab 100644
--- a/src/renderer/components/kanban/CardModal.tsx
+++ b/src/renderer/components/kanban/CardModal.tsx
@@ -655,6 +655,7 @@ export function CardModal({ session, projectId, projectName, projectColor, colum
searchOpen={searchOpen}
onCloseSearch={() => setSearchOpen(false)}
covered={mdOpen}
+ projectId={projectId}
onOpenFile={setPreviewFile}
/>
{/* The ⌘M face is laid OVER the live viewer (the pane anchors it), never swapped
diff --git a/src/renderer/components/kanban/LocalFilePreviewModal.test.tsx b/src/renderer/components/kanban/LocalFilePreviewModal.test.tsx
new file mode 100644
index 000000000..65f149fc7
--- /dev/null
+++ b/src/renderer/components/kanban/LocalFilePreviewModal.test.tsx
@@ -0,0 +1,116 @@
+// @vitest-environment jsdom
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { resetDialogStack } from '../dialog-stack'
+import { useProjects } from '../../state/projects'
+
+const h = vi.hoisted(() => ({
+ browser: false,
+ localRead: vi.fn(async (_p: string) => 'local text'),
+ sshRead: vi.fn(async (_p: string) => 'remote text'),
+ sshFsFor: [] as string[],
+ api: null as unknown
+}))
+
+vi.mock('../../session/session', () => ({
+ // A STABLE api, like the real session's: the component memoizes its filesystem on it.
+ useSession: () => {
+ h.api ??= { fs: { read: h.localRead, readBinary: vi.fn() } }
+ return { api: h.api }
+ }
+}))
+vi.mock('../../terminal/ssh-fs', () => ({
+ sshFs: (projectId: string) => {
+ h.sshFsFor.push(projectId)
+ return { read: h.sshRead, readBinary: vi.fn() }
+ }
+}))
+vi.mock('../../bridge/runtime', () => ({ isBrowserRuntime: () => h.browser }))
+
+import { LocalFilePreviewModal } from './LocalFilePreviewModal'
+
+const flush = async (): Promise<void> => {
+ for (let i = 0; i < 5; i++) await act(async () => {})
+}
+
+describe('LocalFilePreviewModal', () => {
+ let host: HTMLDivElement
+ let root: Root
+ const writeHtml = vi.fn(async () => '/userData/agent-web/x.html')
+ const allow = vi.fn(async () => 'nt-media://x')
+
+ beforeEach(() => {
+ resetDialogStack()
+ h.browser = false
+ h.sshFsFor.length = 0
+ h.localRead.mockClear()
+ h.sshRead.mockClear()
+ writeHtml.mockClear()
+ ;(window as unknown as { nodeTerminal: unknown }).nodeTerminal = { media: { writeHtml, allow } }
+ useProjects.setState({ activeProjectId: 'local1' })
+ host = document.createElement('div')
+ document.body.append(host)
+ root = createRoot(host)
+ })
+
+ afterEach(() => {
+ act(() => root.unmount())
+ document.body.innerHTML = ''
+ })
+
+ it("reads an SSH card's file through THAT card's project, and offers no canvas jump off-project", async () => {
+ act(() =>
+ root.render(
+ <LocalFilePreviewModal file={{ path: '/srv/app/notes.txt', projectId: 'ssh1', ssh: true }} onClose={vi.fn()} />
+ )
+ )
+ await flush()
+ expect(h.sshFsFor).toEqual(['ssh1'])
+ expect(h.localRead).not.toHaveBeenCalled()
+ expect(document.body.querySelector('.local-file-preview__body pre')?.textContent).toBe('remote text')
+ // The active project is local1: "Open on canvas" would land on the wrong canvas.
+ expect(document.body.querySelector('[title="Open on canvas"]')).toBeNull()
+ })
+
+ it('opens on the canvas as a VIEW for a card of the active project', async () => {
+ const seen: unknown[] = []
+ const on = (e: Event): void => void seen.push((e as CustomEvent).detail)
+ window.addEventListener('nodeterm:open-file', on)
+ act(() =>
+ root.render(
+ <LocalFilePreviewModal file={{ path: '/p/report.txt', projectId: 'local1', ssh: false }} onClose={vi.fn()} />
+ )
+ )
+ await flush()
+ act(() => document.body.querySelector<HTMLButtonElement>('[title="Open on canvas"]')!.click())
+ window.removeEventListener('nodeterm:open-file', on)
+ expect(seen).toEqual([{ path: '/p/report.txt', ssh: false, view: true }])
+ })
+
+ it('renders HTML from the CSP jail on desktop', async () => {
+ h.localRead.mockResolvedValueOnce('<h1>hi</h1>')
+ act(() =>
+ root.render(
+ <LocalFilePreviewModal file={{ path: '/p/page.html', projectId: 'local1', ssh: false }} onClose={vi.fn()} />
+ )
+ )
+ await flush()
+ expect(writeHtml).toHaveBeenCalledWith('<h1>hi</h1>')
+ expect(document.body.querySelector('webview')?.getAttribute('src')).toBe('nt-media://x')
+ })
+
+ it('shows HTML source in a browser tab (no webview, no jail)', async () => {
+ h.browser = true
+ h.localRead.mockResolvedValueOnce('<h1>hi</h1>')
+ act(() =>
+ root.render(
+ <LocalFilePreviewModal file={{ path: '/p/page.html', projectId: 'local1', ssh: false }} onClose={vi.fn()} />
+ )
+ )
+ await flush()
+ expect(writeHtml).not.toHaveBeenCalled()
+ expect(document.body.querySelector('webview')).toBeNull()
+ expect(document.body.querySelector('.local-file-preview__body pre')?.textContent).toBe('<h1>hi</h1>')
+ })
+})
diff --git a/src/renderer/components/kanban/LocalFilePreviewModal.tsx b/src/renderer/components/kanban/LocalFilePreviewModal.tsx
index ae1999518..531cc234a 100644
--- a/src/renderer/components/kanban/LocalFilePreviewModal.tsx
+++ b/src/renderer/components/kanban/LocalFilePreviewModal.tsx
@@ -12,9 +12,13 @@ import {
import { useSession } from '../../session/session'
import { useProjects } from '../../state/projects'
import { sshFs } from '../../terminal/ssh-fs'
+import { isBrowserRuntime } from '../../bridge/runtime'
export interface LocalFileTarget {
path: string
+ /** The CARD's project — the filesystem the link was resolved against (may not be the active one). */
+ projectId: string
+ /** The path lives on that SSH project's host. */
ssh: boolean
}
@@ -29,12 +33,23 @@ interface LocalFilePreviewModalProps {
export function LocalFilePreviewModal({ file, onClose }: LocalFilePreviewModalProps) {
const isTopDialog = useDialogStack()
const { api } = useSession()
- const activeProjectId = useProjects((s) => s.activeProjectId)
+ // The same filesystem the link was existence-checked against: the CARD's project, never the
+ // active one (the Omni board opens cards from every project).
const fs = useMemo(
- () => (file.ssh && activeProjectId ? sshFs(activeProjectId) : api.fs),
- [activeProjectId, api, file.ssh]
+ () => (file.ssh ? sshFs(file.projectId) : api.fs),
+ [api, file.projectId, file.ssh]
)
- const kind = useMemo<LocalFilePreviewKind>(() => localFilePreviewKind(file.path), [file.path])
+ // "Open on canvas" opens in the ACTIVE project's canvas, so it is offered only for a card of that
+ // project — a file of another project's card would land on the wrong canvas (and, for an SSH
+ // card, be read off the wrong machine).
+ const onActiveCanvas = useProjects((s) => s.activeProjectId === file.projectId)
+ // A browser tab has no <webview> and no agent-web jail (media.writeHtml is a bridge stub), so the
+ // Server Edition shows an HTML file's source instead of a page that could never render.
+ const browser = isBrowserRuntime()
+ const kind = useMemo<LocalFilePreviewKind>(() => {
+ const k = localFilePreviewKind(file.path)
+ return k === 'html' && browser ? 'text' : k
+ }, [file.path, browser])
const fileName = file.path.replace(/\\/g, '/').split('/').pop() || file.path
const [content, setContent] = useState('')
const [binarySrc, setBinarySrc] = useState('')
@@ -144,7 +159,7 @@ export function LocalFilePreviewModal({ file, onClose }: LocalFilePreviewModalPr
const openOnCanvas = (): void => {
window.dispatchEvent(
- new CustomEvent('nodeterm:open-file', { detail: { path: file.path, ssh: file.ssh } })
+ new CustomEvent('nodeterm:open-file', { detail: { path: file.path, ssh: file.ssh, view: true } })
)
}
@@ -154,9 +169,11 @@ export function LocalFilePreviewModal({ file, onClose }: LocalFilePreviewModalPr
<div className="local-file-preview__header">
<span className="local-file-preview__title" title={file.path}>{fileName}</span>
<span className="local-file-preview__path" title={file.path}>{file.path}</span>
- <button className="kanban-modal__action" title="Open on canvas" onClick={openOnCanvas}>
- <IconExternal />
- </button>
+ {onActiveCanvas && (
+ <button className="kanban-modal__action" title="Open on canvas" onClick={openOnCanvas}>
+ <IconExternal />
+ </button>
+ )}
<button className="kanban-modal__action" title="Close preview" onClick={onClose}>
<IconClose />
</button>
diff --git a/src/renderer/components/kanban/ModalTerminal.tsx b/src/renderer/components/kanban/ModalTerminal.tsx
index 26c745bd2..aacd07a47 100644
--- a/src/renderer/components/kanban/ModalTerminal.tsx
+++ b/src/renderer/components/kanban/ModalTerminal.tsx
@@ -21,7 +21,7 @@ import { useProjects } from '../../state/projects'
import { useSession } from '../../session/session'
import { isHostedReadOnly } from '../../state/hostedTeams'
import { useSettings } from '../../state/settings'
-import { isMacPlatform } from '@shared/platform-utils'
+import { isMacPlatform, isWindowsPlatform } from '@shared/platform-utils'
import {
FONT_ZOOM_NODE_ATTR,
requestTerminalFontZoom,
@@ -34,11 +34,24 @@ import { clipboardImages, droppedPaths, pasteHasText, pastedFiles } from '../../
import { guardMiddleClickPaste } from '../../terminal/middle-click'
import { attachCopyOnSelect } from '../../terminal/copy-on-select'
import {
+ cachedCwd,
+ createFileLinkProvider,
createOsc8LinkHandler,
createUrlLinkProvider,
+ fileMissMessage,
installLinkClickFallback,
- installLinkContextMenu
+ installLinkContextMenu,
+ makeDirListingLookup,
+ type UnverifiedPath
} from '../../terminal/file-links'
+import { isBrowserRuntime } from '../../bridge/runtime'
+import { fileLinkDialect } from '../../terminal/file-link-dialect'
+import { hostPlatformFor } from '../../terminal/host-platform'
+import { sshFs } from '../../terminal/ssh-fs'
+import { cardFileLinkRoute } from '../../lib/cardFileLinks'
+import { projectSessionSource } from '../LiveLinkChip'
+import type { LocalFileTarget } from './LocalFilePreviewModal'
+import type { FsApi } from '@shared/types'
import { urlLinkMenuItems } from '../../terminal/link-menu'
import { ContextMenu } from '../ContextMenu'
import { parseOsc52 } from '../../terminal/osc52'
@@ -114,11 +127,44 @@ interface ModalTerminalProps {
* completion, which a quick ⌘M can precede). Same rules as the canvas node's ⌘M face.
*/
covered?: boolean
+ /** The project this CARD belongs to — not necessarily the active one (the Omni board opens cards
+ * from every project). File links resolve against this project's filesystem; absent = no file
+ * links (see `cardFileLinkRoute`). */
+ projectId?: string
+ /** A file link was activated: the card modal previews it in its own overlay instead of uncovering
+ * the canvas. Absent = file links are not offered at all. */
+ onOpenFile?: (file: LocalFileTarget) => void
}
-export function ModalTerminal({ nodeId, spawn, searchOpen, onCloseSearch, covered = false }: ModalTerminalProps) {
+export function ModalTerminal({
+ nodeId,
+ spawn,
+ searchOpen,
+ onCloseSearch,
+ covered = false,
+ projectId,
+ onOpenFile
+}: ModalTerminalProps) {
const session = useSession()
const { api } = session
+ // Read at click time from the lifecycle effect, which runs once per mount.
+ const projectIdRef = useRef(projectId)
+ projectIdRef.current = projectId
+ const onOpenFileRef = useRef(onOpenFile)
+ onOpenFileRef.current = onOpenFile
+ // MIRROR TerminalNode: the path dialect belongs to the core that owns the filesystem, never this
+ // window's OS. A ref, so resolving it never re-runs the lifecycle effect.
+ const corePlatformRef = useRef<string | null>(null)
+ useEffect(() => {
+ let live = true
+ corePlatformRef.current = null
+ void hostPlatformFor(api).then((platform) => {
+ if (live) corePlatformRef.current = platform
+ })
+ return () => {
+ live = false
+ }
+ }, [api])
const hostRef = useRef<HTMLDivElement>(null)
const middleClickPaste = useSettings((st) => st.settings.terminalMiddleClickPaste)
// Chromium pastes the X PRIMARY selection into xterm's hidden textarea on middle click — a path
@@ -177,8 +223,8 @@ export function ModalTerminal({ nodeId, spawn, searchOpen, onCloseSearch, covere
hasSelection: () => !!termRef.current?.hasSelection(),
enabled: !reportsOwnCopy(spawn.agentId as AgentId | undefined)
})
- // Right-click on a URL → the canvas node's link menu, URL rows only (no file links here — see the
- // link wiring in the lifecycle effect).
+ // Right-click on a URL → the canvas node's link menu, URL rows only (file rows act on the active
+ // project — see the link wiring in the lifecycle effect).
const [linkMenu, setLinkMenu] = useState<{ x: number; y: number; url: string } | null>(null)
// Same search machinery as the canvas node: capture-indexed matches + xterm highlight.
@@ -256,26 +302,103 @@ export function ModalTerminal({ nodeId, spawn, searchOpen, onCloseSearch, covere
let dead = false
const cleanups: Array<() => void> = []
- // MIRROR TerminalNode's link wiring, minus file links. The provider handles Cmd/Ctrl+click on
- // URL text when mouse-reporting is off (plain-shell sessions); the capture-phase fallback is
- // what works under tmux/agent mouse-reporting — the norm, and the only path on which the OSC 8
- // linkHandler above can ever fire in a tmux-backed session (xterm's own link activation is
- // swallowed by the mouse report, see installLinkClickFallback). File links stay a canvas-node
- // affordance: the modal has no project-fs/dialect routing, and resolving a path against the
- // wrong machine is worse than not linking it — hence fileEnabled: false, not stub deps that
- // pretend to resolve.
+ // MIRROR TerminalNode's link wiring. The URL provider handles Cmd/Ctrl+click on URL text when
+ // mouse-reporting is off (plain-shell sessions); the capture-phase fallback is what works under
+ // tmux/agent mouse-reporting — the norm, and the only path on which the OSC 8 linkHandler above
+ // can ever fire in a tmux-backed session (xterm's own link activation is swallowed by the mouse
+ // report, see installLinkClickFallback).
+ // File links use main's token model and lookup unchanged, but resolve against the CARD's project
+ // (`cardFileLinkRoute`), not the active one: the Omni board opens cards from every project, and
+ // resolving a path against the wrong machine is worse than not linking it — so any doubt (no
+ // project, a relay/server core, a session on a host the project's fs does not cover, an unknown
+ // core platform) turns file links off. An activated file opens in the card's own preview.
const openUrl = (uri: string): void => window.nodeTerminal.shell.openExternal(uri)
+ const route = () => {
+ const id = projectIdRef.current
+ if (!id || !onOpenFileRef.current) return null
+ const project = useProjects.getState().projects.find((p) => p.id === id)
+ return cardFileLinkRoute({ project, source: projectSessionSource(id), spawn })
+ }
+ const projectFs = (): FsApi | null => {
+ const r = route()
+ if (!r) return null
+ return r.ssh ? sshFs(projectIdRef.current!) : api.fs
+ }
+ const pathConvention = (): { windows?: boolean } | null => {
+ const r = route()
+ if (!r) return null
+ const dialect = fileLinkDialect({
+ source: 'local',
+ browserRuntime: isBrowserRuntime(),
+ viewerWindows: isWindowsPlatform(),
+ corePlatform: corePlatformRef.current,
+ sshProject: r.sshProject,
+ standaloneSsh: r.standaloneSsh
+ })
+ return dialect ? { windows: dialect === 'windows' } : null
+ }
+ const lookup = makeDirListingLookup(
+ async (dir) => {
+ const fs = projectFs()
+ if (!fs) throw new Error('no filesystem to check it on')
+ return fs.list(dir)
+ },
+ 3000,
+ pathConvention
+ )
+ const getCwd = (): string | undefined => spawn.cwd || undefined
+ // The pane's CURRENT directory — the second anchor for a relative path (see CwdSources).
+ const getLiveCwd = cachedCwd(() => api.pty.paneCwd(nodeId))
+ const fileEnabled = (): boolean => pathConvention() !== null
+ const openFile = (abs: string, isDir: boolean): void => {
+ const r = route()
+ const id = projectIdRef.current
+ if (!r || !id) return
+ if (isDir) {
+ // The Explorer drawer only shows the ACTIVE project; revealing a folder of another project's
+ // card there would show the wrong tree.
+ if (id === useProjects.getState().activeProjectId)
+ window.dispatchEvent(new CustomEvent('nodeterm:reveal-file', { detail: { path: abs } }))
+ else
+ window.dispatchEvent(
+ new CustomEvent('nodeterm:toast', {
+ detail: { kind: 'error', message: `Open this card's project to reveal ${abs}` }
+ })
+ )
+ return
+ }
+ onOpenFileRef.current?.({ path: abs, projectId: id, ssh: r.ssh })
+ }
+ const onMissing = (token: string, miss: { tried: string[]; unverified?: UnverifiedPath[] }): void => {
+ window.dispatchEvent(
+ new CustomEvent('nodeterm:toast', { detail: { kind: 'error', message: fileMissMessage(token, miss) } })
+ )
+ }
term.registerLinkProvider(createUrlLinkProvider(term, openUrl))
+ term.registerLinkProvider(
+ createFileLinkProvider(term, {
+ getCwd,
+ getLiveCwd,
+ lookup,
+ activate: openFile,
+ convention: pathConvention
+ })
+ )
if (term.element) {
cleanups.push(
installLinkClickFallback(term, term.element, {
- getCwd: () => undefined,
- lookup: () => Promise.resolve({ exists: false, dir: false }),
- activateFile: () => {},
+ getCwd,
+ getLiveCwd,
+ lookup,
+ activateFile: openFile,
+ onMissing,
openUrl,
- fileEnabled: () => false
+ fileEnabled,
+ convention: pathConvention
}).dispose
)
+ // Right-click stays URL-only here: the canvas node's file rows (download, reveal in the OS,
+ // open a terminal) act on the active project, which may not be this card's.
cleanups.push(
installLinkContextMenu(term, term.element, {
getCwd: () => undefined,
diff --git a/src/renderer/lib/cardFileLinks.test.ts b/src/renderer/lib/cardFileLinks.test.ts
new file mode 100644
index 000000000..3dfd9efd7
--- /dev/null
+++ b/src/renderer/lib/cardFileLinks.test.ts
@@ -0,0 +1,53 @@
+import { describe, expect, it } from 'vitest'
+import { cardFileLinkRoute } from './cardFileLinks'
+
+const host = { host: 'box', user: 'me' } as never
+const other = { host: 'elsewhere', user: 'me' } as never
+
+describe('cardFileLinkRoute', () => {
+ it('routes a local card to the local filesystem', () => {
+ expect(cardFileLinkRoute({ project: { id: 'p1' }, source: 'local', spawn: {} })).toEqual({
+ ssh: false,
+ sshProject: false,
+ standaloneSsh: false
+ })
+ })
+
+ it("routes an SSH card through the CARD's project, whatever project is active", () => {
+ // The Omni board opens this card while a LOCAL project is active: the route is decided by the
+ // card's own project, so the path is checked on the host it was printed on.
+ const r = cardFileLinkRoute({
+ project: { id: 'ssh1', ssh: { server: host } },
+ source: 'local',
+ spawn: { ssh: host, sshRemoteTmux: true }
+ })
+ expect(r).toEqual({ ssh: true, sshProject: true, standaloneSsh: false })
+ })
+
+ it('refuses an unknown project, and a relay/server core', () => {
+ expect(cardFileLinkRoute({ project: undefined, source: 'local', spawn: {} })).toBeNull()
+ expect(cardFileLinkRoute({ project: { id: 'p' }, source: 'relay', spawn: {} })).toBeNull()
+ expect(cardFileLinkRoute({ project: { id: 'p' }, source: 'server', spawn: {} })).toBeNull()
+ expect(cardFileLinkRoute({ project: { id: 'p' }, source: null, spawn: {} })).toBeNull()
+ })
+
+ it('refuses a remote session its project has no filesystem for', () => {
+ // A plain `ssh` node in a local project: its output names paths on another machine.
+ expect(cardFileLinkRoute({ project: { id: 'p' }, source: 'local', spawn: { ssh: host } })).toBeNull()
+ // A host attachment: the SSH project's fs is ITS host, not the one this session runs on.
+ expect(
+ cardFileLinkRoute({
+ project: { id: 'ssh1', ssh: { server: host } },
+ source: 'local',
+ spawn: { ssh: other, sshRemoteTmux: true }
+ })
+ ).toBeNull()
+ expect(
+ cardFileLinkRoute({
+ project: { id: 'ssh1', ssh: { server: host } },
+ source: 'local',
+ spawn: { sshRemoteTmux: true }
+ })
+ ).toBeNull()
+ })
+})
diff --git a/src/renderer/lib/cardFileLinks.ts b/src/renderer/lib/cardFileLinks.ts
new file mode 100644
index 000000000..b08c1b5ee
--- /dev/null
+++ b/src/renderer/lib/cardFileLinks.ts
@@ -0,0 +1,46 @@
+import { sshConnectionIdForProject, type SshConnection } from '@shared/ssh'
+import type { SessionSource } from '../session/session'
+
+/** Where a card-modal terminal's file links resolve: the filesystem to existence-check against
+ * (`ssh` = the CARD's SSH project over its ControlMaster, else the local core's fs) plus the facts
+ * `fileLinkDialect` needs. */
+export interface CardFileLinkRoute {
+ ssh: boolean
+ sshProject: boolean
+ standaloneSsh: boolean
+}
+
+/**
+ * Route the file links of the card modal's live viewer — or refuse to (`null` = no file links).
+ *
+ * The canvas node asks the ACTIVE project, because a node only ever lives in the active canvas.
+ * A card does not: the Omni board opens cards from every project, so the modal must ask the CARD's
+ * project (`projectId`), never the active one — or a click on an SSH card while a local project is
+ * active would existence-check (and open) a same-looking path on THIS machine. Every doubt fails
+ * closed, because an absent link is recoverable and the wrong machine's file is not:
+ * - the project is unknown;
+ * - its core is not this app's local one (`source` — a relay/server tab's files live on another
+ * core, which this modal's `api` does not reach);
+ * - the session runs on a host the project's fs API does not cover: a plain `ssh` node in a local
+ * project, or a host attachment (a node on a different host than its SSH project's).
+ */
+export function cardFileLinkRoute(facts: {
+ project: { id: string; ssh?: { server?: SshConnection } } | undefined
+ source: SessionSource | null
+ spawn: { ssh?: SshConnection; sshRemoteTmux?: boolean }
+}): CardFileLinkRoute | null {
+ const { project, source, spawn } = facts
+ if (!project || source !== 'local') return null
+ const remoteSession = !!spawn.ssh || !!spawn.sshRemoteTmux
+ if (!project.ssh) {
+ // A local project: a remote session's output names paths on a host we have no fs API for.
+ return remoteSession ? null : { ssh: false, sshProject: false, standaloneSsh: false }
+ }
+ // An SSH project: its fs API is the project's host. A session there is either on that host
+ // (the project's own scope) or attached to another one, whose paths it cannot check.
+ if (remoteSession) {
+ if (!spawn.ssh) return null
+ if (sshConnectionIdForProject(project.id, spawn.ssh, project.ssh.server) !== project.id) return null
+ }
+ return { ssh: true, sshProject: true, standaloneSsh: false }
+}
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 3777057a8..fede07c04 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -1492,7 +1492,9 @@ export function TerminalNode({
send(new CustomEvent('nodeterm:open-url-node', { detail: { url, sourceNodeId: id } })),
copy: (text) => window.nodeTerminal.clipboard.writeText(text),
openFile: (abs) =>
- send(new CustomEvent('nodeterm:open-file', { detail: { path: abs, ssh: activeIsSsh } })),
+ send(
+ new CustomEvent('nodeterm:open-file', { detail: { path: abs, ssh: activeIsSsh, view: true } })
+ ),
revealInExplorer: (abs) =>
send(new CustomEvent('nodeterm:reveal-file', { detail: { path: abs } })),
revealInOs: (abs) => window.nodeTerminal.shell.reveal(abs),
@@ -3310,7 +3312,10 @@ export function TerminalNode({
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 } })
+ // `view`: a link asks to SEE the file, so a local .html renders as a page (Canvas.openFile).
+ new CustomEvent('nodeterm:open-file', {
+ detail: { path: abs, ssh: projectFs().ssh, view: true }
+ })
)
}
// Shift+Cmd/Ctrl+click → the OS default app (a directory → the OS file manager). The same
diff --git a/src/renderer/state/workspace.media.test.ts b/src/renderer/state/workspace.media.test.ts
index f520ce092..2764fc67a 100644
--- a/src/renderer/state/workspace.media.test.ts
+++ b/src/renderer/state/workspace.media.test.ts
@@ -18,13 +18,21 @@ describe('video/web nodes', () => {
})
it('routes generated documents to their built-in canvas viewers', () => {
- expect(fileViewerKind('/tmp/page.html')).toBe('web')
- expect(fileViewerKind('/tmp/page.htm')).toBe('web')
+ const view = { renderHtml: true }
+ expect(fileViewerKind('/tmp/page.html', view)).toBe('web')
+ expect(fileViewerKind('/tmp/page.htm', view)).toBe('web')
+ expect(fileViewerKind('/tmp/interview.mp3', view)).toBe('video')
+ expect(fileViewerKind('/tmp/notes.md', view)).toBe('editor')
+ expect(fileViewerKind('/tmp/report.pdf', view)).toBe('editor')
+ expect(fileViewerKind('/tmp/screenshot.png', view)).toBe('editor')
+ })
+
+ it('keeps .html in the editor unless a LOCAL view was asked for', () => {
+ // Explorer / ⌘K / files node: .html means "edit the source".
+ expect(fileViewerKind('/tmp/page.html')).toBe('editor')
expect(fileViewerKind('/tmp/interview.mp3')).toBe('video')
- expect(fileViewerKind('/tmp/notes.md')).toBe('editor')
- expect(fileViewerKind('/tmp/report.pdf')).toBe('editor')
- expect(fileViewerKind('/tmp/screenshot.png')).toBe('editor')
- expect(fileViewerKind('/tmp/page.html', true)).toBe('editor')
+ // An SSH project's page lives on the host; a WebNode can only serve this machine's disk.
+ expect(fileViewerKind('/tmp/page.html', { renderHtml: true, sshFs: true })).toBe('editor')
})
it('isVideoFile matches common video extensions, not images', () => {
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.ts
index c7870a289..1f571d8c0 100644
--- a/src/renderer/state/workspace.ts
+++ b/src/renderer/state/workspace.ts
@@ -1009,10 +1009,15 @@ export function isVideoFile(path: string): boolean {
return VIDEO_EXTS.includes(ext)
}
-/** Pick the canvas surface used for a linked file. Remote HTML stays source-editable because a
- * WebNode can only serve a local file; every other preview works through EditorNode's routed fs. */
-export function fileViewerKind(path: string, sshFs = false): 'editor' | 'video' | 'web' {
- if (!sshFs && isHtmlFile(path)) return 'web'
+/** Pick the canvas surface for a file. HTML renders as a page only when the caller asked to VIEW
+ * it (`renderHtml` — a terminal link, not Explorer/⌘K, where .html means "edit the source"), and
+ * only locally: a WebNode serves a file off THIS machine's disk, so an SSH project's page stays in
+ * the editor. Every other preview works through EditorNode's routed fs. */
+export function fileViewerKind(
+ path: string,
+ opts: { sshFs?: boolean; renderHtml?: boolean } = {}
+): 'editor' | 'video' | 'web' {
+ if (opts.renderHtml && !opts.sshFs && isHtmlFile(path)) return 'web'
if (isMediaFile(path)) return 'video'
return 'editor'
}
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 6539c9f80..b06a13cf5 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -12850,7 +12850,7 @@ button.pull-checks__name {
text-overflow: ellipsis;
white-space: nowrap;
color: rgba(var(--tint-rgb), 0.4);
- font-family: var(--mono-font, monospace);
+ font-family: ui-monospace, monospace;
font-size: 10px;
}
.local-file-preview__body {
@@ -12896,7 +12896,7 @@ button.pull-checks__name {
white-space: pre-wrap;
word-break: break-word;
color: rgba(var(--tint-rgb), 0.88);
- font: 12px/1.55 var(--mono-font, monospace);
+ font: 12px/1.55 ui-monospace, monospace;
}
.local-file-preview__message {
position: absolute;
@@ -12908,7 +12908,7 @@ button.pull-checks__name {
font-size: 12px;
}
.local-file-preview__message--error {
- color: rgba(255, 120, 120, 0.88);
+ color: var(--danger);
}
/* ---- Node comments flyout: the header 💬 expands the board-log feed to the node's right ---- */