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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(canvas): gate the file copy to where it can succeed, and stop paying for the wheel DOM walk
Claude Code3bb329df0ed3
diff --git a/src/main/clipboard-files.test.ts b/src/main/clipboard-files.test.tsindex a81aa10c5..e0b4f05c2 100644--- a/src/main/clipboard-files.test.ts+++ b/src/main/clipboard-files.test.ts@@ -31,6 +31,23 @@ describe('writeFilesToClipboard', () => {expect(writeFilesToClipboard('not-an-array', dependencies())).toBe(false)})+ it('caps the selection, counting only the files it kept', () => {+ const paths = (n: number): string[] => Array.from({ length: n }, (_, i) => `/tmp/f${i}`)+ const at = dependencies()+ // Exactly at the cap is still one copy, not a truncated one.+ expect(writeFilesToClipboard(paths(64), at)).toBe(true)+ expect(vi.mocked(at.writeBuffer).mock.calls[0][1].toString().match(/<string>/g)).toHaveLength(64)+ // One over refuses outright — a partial pasteboard is worse than none, because the user+ // cannot see which files it dropped.+ expect(writeFilesToClipboard(paths(65), dependencies())).toBe(false)+ // Duplicates are folded before the cap is charged, so 65 entries naming 64 files still fit.+ const dupes = dependencies()+ expect(writeFilesToClipboard([...paths(64), '/tmp/f0'], dupes)).toBe(true)+ expect(vi.mocked(dupes.writeBuffer).mock.calls[0][1].toString().match(/<string>/g)).toHaveLength(+ 64+ )+ })+it('fails closed when the OS clipboard write fails', () => {expect(writeFilesToClipboard(diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 915c12ed2..a354701e4 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -2566,13 +2566,18 @@ export function Canvas() {const onWheel = (e: WheelEvent) => {if (canvasLocked) returnif (!e.ctrlKey && !e.metaKey) {- const overNativeScrollable = !!(e.target as HTMLElement | null)?.closest('.nowheel')+ // The ancestor walk is the expensive part of this handler at ~120 Hz, so it is memoized+ // per packet AND never run for a packet no guard asks about (a plain wheel with wheelZoom+ // off, which is the default, walks nothing at all).+ const target = e.target as HTMLElement | null+ let scroller: boolean | undefined+ const overNativeScrollable = (): boolean => (scroller ??= !!target?.closest('.nowheel'))// A macOS trackpad's two-finger scroll pans the canvas outside native scroll surfaces;// inside them (terminal, Monaco, markdown) it scrolls that surface as before.if (wheelRouting.destination(e, isMac, overNativeScrollable) === 'flow-pan') return- if (overNativeScrollable) return// pinch (ctrl+wheel) / Cmd/Ctrl+scroll always zoom; plain wheel only when opted inif (!wheelZoom) return+ if (overNativeScrollable()) return}e.preventDefault()e.stopPropagation()@@ -4825,9 +4830,20 @@ export function Canvas() {return}// Nothing selected as text: copy the selected file-backed nodes as FILE REFERENCES, so- // Finder (or any file-aware app) pastes the actual files. Desktop/macOS only — the browser- // stub answers false and the banner says why.- const paths = selectedLocalFilePaths(nodesRef.current)+ // Finder (or any file-aware app) pastes the actual files.+ //+ // Gated to where it can actually succeed, because the failure path raises a banner that+ // stays until dismissed — and before this feature the keystroke was a silent no-op, which+ // is what every other machine must keep getting. `writeFilesToClipboard` is darwin-gated+ // in main and the browser bridge stub answers false, so on a non-mac renderer (desktop OR+ // Server Edition) this branch could only ever produce that banner, wearing macOS-specific+ // copy on a Linux box. The board is an opaque overlay over the canvas, so a copy there+ // would act on a selection the user cannot see (the canvas-only-shortcut discipline).+ const projects = useProjects.getState()+ if (!isMac || isKanbanOpen(projects.activeProjectId)) return+ const paths = selectedLocalFilePaths(nodesRef.current, {+ projectIsRelay: !!projects.getProject(projects.activeProjectId ?? '')?.remote+ })if (!paths.length) returne.preventDefault()void window.nodeTerminal.clipboarddiff --git a/src/renderer/canvas/canvas-file-copy.test.ts b/src/renderer/canvas/canvas-file-copy.test.tsindex 85fb01df5..117b8348f 100644--- a/src/renderer/canvas/canvas-file-copy.test.ts+++ b/src/renderer/canvas/canvas-file-copy.test.ts@@ -28,6 +28,21 @@ describe('selectedLocalFilePaths', () => {).toEqual(['/tmp/image.png', '/tmp/video.mp4', '/tmp/page.html'])})+ it('copies nothing at all from a relay tab, whose paths describe the PEER disk', () => {+ // Not "filters the remote ones out": in a relay tab EVERY path is the peer's, and the local+ // statSync can silently match a same-named local file. The whole gesture is off.+ expect(+ selectedLocalFilePaths([node('image', 'editor', '/home/me/proj/src/x.ts')], {+ projectIsRelay: true+ })+ ).toEqual([])+ expect(+ selectedLocalFilePaths([node('image', 'editor', '/home/me/proj/src/x.ts')], {+ projectIsRelay: false+ })+ ).toEqual(['/home/me/proj/src/x.ts'])+ })+it('excludes unselected, remote, missing and non-file node kinds', () => {const unselected = node('unselected', 'editor', '/tmp/a')unselected.selected = falsediff --git a/src/renderer/canvas/canvas-file-copy.ts b/src/renderer/canvas/canvas-file-copy.tsindex 1440d325a..42cf2c135 100644--- a/src/renderer/canvas/canvas-file-copy.ts+++ b/src/renderer/canvas/canvas-file-copy.ts@@ -2,8 +2,25 @@ import type { CanvasNode } from '../state/workspace'const LOCAL_FILE_NODE_TYPES = new Set(['editor', 'video', 'web'])+export interface LocalFileCopyScope {+ /**+ * The active project is a RELAY tab — a live client of another machine's core. Its nodes' paths+ * describe the PEER's disk, but `window.nodeTerminal.clipboard` is this machine's preload, so+ * copying them would hand peer paths to a local `statSync`: usually a miss, but when the same+ * repo is checked out on both machines it silently puts a DIFFERENT file on the pasteboard.+ * A relay tab is marked at the PROJECT level (`Project.remote`) and never on the node, so this+ * fact cannot be read off `nodes` — it has to be passed in. Same hazard the `show-image`+ * control verb documents ("or, worse, open a same-named local file").+ */+ projectIsRelay?: boolean+}+/** Paths represented by the selected local file-backed nodes, in canvas order and without dupes. */-export function selectedLocalFilePaths(nodes: CanvasNode[]): string[] {+export function selectedLocalFilePaths(+ nodes: CanvasNode[],+ scope: LocalFileCopyScope = {}+): string[] {+ if (scope.projectIsRelay) return []const seen = new Set<string>()const paths: string[] = []for (const node of nodes) {diff --git a/src/renderer/canvas/wheel-gesture.test.ts b/src/renderer/canvas/wheel-gesture.test.tsindex 8c12a52a1..90a831179 100644--- a/src/renderer/canvas/wheel-gesture.test.ts+++ b/src/renderer/canvas/wheel-gesture.test.ts@@ -19,6 +19,9 @@ const gesture = (wheelDeltaY: o.wheelDeltaY})+const yes = () => true+const no = () => false+describe('MacWheelGestureRouter', () => {it('keeps a notched macOS mouse wheel on the user-configured zoom path', () => {const router = new MacWheelGestureRouter()@@ -42,18 +45,18 @@ describe('MacWheelGestureRouter', () => {it('keeps trackpad scrolling native over terminal and other native scroll surfaces', () => {const router = new MacWheelGestureRouter()- expect(router.destination(gesture(6.25), true, true, 1000)).toBe('native')- expect(router.destination(gesture(6.25), true, false, 1400)).toBe('flow-pan')- expect(router.destination(gesture(100, { wheelDeltaY: -120 }), true, true, 1800)).toBe('native')+ expect(router.destination(gesture(6.25), true, yes, 1000)).toBe('native')+ expect(router.destination(gesture(6.25), true, no, 1400)).toBe('flow-pan')+ expect(router.destination(gesture(100, { wheelDeltaY: -120 }), true, yes, 1800)).toBe('native')})it('does not pan over a non-terminal native scroller, and still knows the gesture is a trackpad', () => {const router = new MacWheelGestureRouter()// A trackpad gesture that begins over Monaco / a markdown pane scrolls THAT surface...- expect(router.destination(gesture(6.25), true, true, 1000)).toBe('native')+ expect(router.destination(gesture(6.25), true, yes, 1000)).toBe('native')// ...but the packet still classified the device, so continuing the same gesture off the// scroller pans the canvas instead of falling back to the mouse-notch (zoom) path.- expect(router.destination(gesture(75), true, false, 1100)).toBe('flow-pan')+ expect(router.destination(gesture(75), true, no, 1100)).toBe('flow-pan')})it('keeps pinch, Cmd-wheel, line-mode wheel and other platforms off the override', () => {diff --git a/src/renderer/canvas/wheel-gesture.ts b/src/renderer/canvas/wheel-gesture.tsindex 31addf18d..6f37fdd0c 100644--- a/src/renderer/canvas/wheel-gesture.ts+++ b/src/renderer/canvas/wheel-gesture.ts@@ -39,13 +39,19 @@ export class MacWheelGestureRouter {return false}+ /**+ * `overNativeScrollable` is a THUNK, not a boolean: the caller answers it with a DOM ancestor+ * walk and this runs on every wheel packet (~120 Hz through a trackpad pan), so it must not be+ * paid for the packets that never reach the question — a non-trackpad wheel is answered by+ * `shouldPan` alone.+ */destination(event: WheelGesture,mac: boolean,- overNativeScrollable: boolean,+ overNativeScrollable: () => boolean,now = performance.now()): MacWheelDestination {if (!this.shouldPan(event, mac, now)) return 'native'- return overNativeScrollable ? 'native' : 'flow-pan'+ return overNativeScrollable() ? 'native' : 'flow-pan'}}