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
Merge origin/main; port the Tidy canvas shortcut to the keybinding registry
enes8a4bc6ee27ea
diff --cc CLAUDE.mdindex b001b9fac,9fbc4db33..d5f904f67--- a/CLAUDE.md+++ b/CLAUDE.md@@@ -1595,8 -1630,7 +1630,8 @@@ the Settings section and ShortcutsPanepane right-click = add nodes at cursor (terminal / Claude / sticky / open file) + selectall + fit + **Tidy canvas** (`arrangeAllNodes` — packs every top-level node, including groupframes as rigid units, into a non-overlapping grid via `arrangeNodes`, sorted by current- (y, x) so the pack roughly preserves reading order; mirrored in ⌘K as "Tidy canvas" and bound- to ⌘/Ctrl+Shift+A; both- (y, x) so the pack roughly preserves reading order; mirrored in ⌘K as "Tidy canvas"; both++ (y, x) so the pack roughly preserves reading order; mirrored in ⌘K as "Tidy canvas" and in the++ keybinding registry as `canvas.tidy` (default ⌘/Ctrl+Shift+A, remappable); bothhidden below 2 top-level nodes, where it could only be a visual no-op that still writes`project.json`) + restart-idle-agents (the bulk in-place agent restart, mirrored in ⌘K; bothhidden when the canvas holds no restartable agent node, where they could only report "0diff --cc src/renderer/canvas/Canvas.tsxindex fa3cd15f5,d27b40495..779ba72e6--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@@ -5210,101 -5131,154 +5131,155 @@@ export function Canvas()[commitActiveToStore, writeDisk])- // Cmd/Ctrl+K toggles the command palette; Cmd/Ctrl+, opens settings.- useEffect(() => {- const onKey = (e: KeyboardEvent) => {- if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') {- e.preventDefault()- setPaletteOpen((v) => !v)- } else if ((e.metaKey || e.ctrlKey) && e.key === ',') {- e.preventDefault()- setSettingsSection(undefined)- setSettingsOpen(true)- } else if ((e.metaKey || e.ctrlKey) && e.shiftKey && e.key.toLowerCase() === 'e') {- e.preventDefault()- setExplorerOpen((v) => !v)- } else if ((e.metaKey || e.ctrlKey) && e.shiftKey && e.key.toLowerCase() === 'g') {- e.preventDefault()- setScOpen((v) => !v)- } else if ((e.metaKey || e.ctrlKey) && e.shiftKey && e.key.toLowerCase() === 'b') {- e.preventDefault()- const id = useProjects.getState().activeProjectId- if (id) useViewMode.getState().toggle(id)- } else if ((e.metaKey || e.ctrlKey) && e.shiftKey && e.key.toLowerCase() === 'l') {- e.preventDefault()- toggleSessionsPin()- } else if ((e.metaKey || e.ctrlKey) && e.shiftKey && e.key.toLowerCase() === 'a') {- // arrangeAllNodes self-guards (kanban open, <2 top-level nodes) — no refusal needed here.- e.preventDefault()- arrangeAllNodes()- } else if ((e.metaKey || e.ctrlKey) && e.key === '/') {- e.preventDefault()- setShortcutsOpen((v) => !v)- } else if (zoomShortcutChord(e) !== null) {- // ⌘/Ctrl+0 = back to 100%, Shift+1 = fit everything. `liveZoomShortcutAction` is the- // whole decision (see `lib/zoomShortcut.ts`), and the ⌘0 desktop route below asks the same- // one, so the two paths can never disagree about when the chord is allowed to move the- // camera. A null answer means "leave the key alone" — no `preventDefault`, which is what- // keeps Shift+1 typing a `!` wherever the user is actually typing.- const action = liveZoomShortcutAction(e)- if (action) {- e.preventDefault()- if (action === 'zoom-100') zoomTo100()- else fitAll()- }- } else if (projectJumpDigit(e) !== null) {- // Cmd/Ctrl+1-9 jumps to the Nth project — but only when the app actually owns the key- // (desktop shell, and the digit addresses an open project). `liveProjectJumpTarget`- // is the same decision the terminals' swallow asks, so the two can't disagree; a null- // target leaves the key to whatever has focus. `switchProject` no-ops on the active id.- const targetId = liveProjectJumpTarget(e)- if (targetId) {- e.preventDefault()- switchProject(targetId)- }- } else if ((e.metaKey || e.ctrlKey) && !e.shiftKey && e.key.toLowerCase() === 'c') {- // Native text selection wins (markdown, editor and terminal keep their normal copy path).- const tag = (document.activeElement?.tagName || '').toLowerCase()- if (- tag === 'input' ||- tag === 'textarea' ||- document.activeElement?.getAttribute('contenteditable') === 'true' ||- document.activeElement?.closest('.monaco-editor, .xterm')+ // ---- global shortcuts ----+ // The three trailing gestures below are registry-LESS chords (design D2: declared gestures,+ // deliberately not remappable in this PR). The dispatcher hands them the RAW event with no+ // context, so each keeps its OWN guards exactly as today's if-chain branch carried them.+ // Zoom and project-jump are POSITIONAL chords (`e.code`, auto-repeat aware) — fields the+ // dispatcher's structural `GlobalKeyEvent` does not model — and the only dispatch site is the+ // window listener below, which always hands them a real KeyboardEvent.++ // ⌘/Ctrl+0 = back to 100%, Shift+1 = fit everything. `liveZoomShortcutAction` is the whole+ // decision (see `lib/zoomShortcut.ts`), including the typing refusal, and the ⌘0 desktop route+ // below asks the same one, so the two paths can never disagree about when the chord is allowed+ // to move the camera. A null answer means "leave the key alone" — no `preventDefault`, which is+ // what keeps Shift+1 typing a `!` wherever the user is actually typing.+ const zoomGesture = useCallback((raw: GlobalKeyEvent): boolean => {+ const e = raw as KeyboardEvent+ if (zoomShortcutChord(e) === null) return false+ const action = liveZoomShortcutAction(e)+ if (!action) return false+ e.preventDefault()+ if (action === 'zoom-100') zoomTo100()+ else fitAll()+ return true+ }, [zoomTo100, fitAll])++ // Cmd/Ctrl+1-9 jumps to the Nth project — but only when the app actually owns the key (desktop+ // shell, and the digit addresses an open project). `liveProjectJumpTarget` is the same decision+ // the terminals' swallow asks, so the two can't disagree; a null target leaves the key to+ // whatever has focus. `switchProject` no-ops on the active id.+ const projectJumpGesture = useCallback((raw: GlobalKeyEvent): boolean => {+ const e = raw as KeyboardEvent+ if (projectJumpDigit(e) === null) return false+ const targetId = liveProjectJumpTarget(e)+ if (!targetId) return false+ e.preventDefault()+ switchProject(targetId)+ return true+ }, [switchProject])++ const copyGesture = useCallback((e: GlobalKeyEvent): boolean => {+ if (!((e.metaKey || e.ctrlKey) && !e.shiftKey && e.key.toLowerCase() === 'c')) return false+ // Native text selection wins (markdown, editor and terminal keep their normal copy path).+ const tag = (document.activeElement?.tagName || '').toLowerCase()+ if (+ tag === 'input' ||+ tag === 'textarea' ||+ document.activeElement?.getAttribute('contenteditable') === 'true' ||+ document.activeElement?.closest('.monaco-editor, .xterm')+ )+ return false+ const sel = window.getSelection?.()?.toString()+ if (sel) {+ window.nodeTerminal.clipboard.writeText(sel)+ // Claimed, but deliberately WITHOUT preventDefault — exactly as today: the native copy is+ // let through as well.+ return true+ }+ // Nothing selected as text: copy the selected file-backed nodes as FILE REFERENCES, so+ // 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 false+ const paths = selectedLocalFilePaths(nodesRef.current, {+ projectIsRelay: !!projects.getProject(projects.activeProjectId ?? '')?.remote+ })+ if (!paths.length) return false+ e.preventDefault()+ void window.nodeTerminal.clipboard+ .writeFiles(paths)+ .then((copied) => {+ setCopyError(+ copied+ ? null+ : 'Copy failed — only existing local files can be copied from the macOS desktop app.')- return- const sel = window.getSelection?.()?.toString()- if (sel) {- window.nodeTerminal.clipboard.writeText(sel)- 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.- //- // 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) return- e.preventDefault()- void window.nodeTerminal.clipboard- .writeFiles(paths)- .then((copied) => {- setCopyError(- copied- ? null- : 'Copy failed — only existing local files can be copied from the macOS desktop app.'- )- })- .catch(() => setCopyError('Copy failed — the system clipboard is unavailable.'))+ })+ .catch(() => setCopyError('Copy failed — the system clipboard is unavailable.'))+ return true+ }, [setCopyError])++ // ONE window keydown for every registry command + the legacy gestures. The deps live in a+ // ref refreshed each render so the listener is registered once; handlers return whether+ // they claimed the chord (an unavailable surface falls through to the platform).+ const globalKeyDeps = useRef<GlobalKeydownDeps | null>(null)+ globalKeyDeps.current = {+ activeElement: () => document.activeElement as unknown as ContextElement | null,+ kanbanOpen: () => isKanbanOpen(useProjects.getState().activeProjectId),+ overrides: activeKeybindingOverrides,+ isMac,+ handlers: {+ 'app.commandPalette': () => { setPaletteOpen((v) => !v); return true },+ 'app.settings': () => { setSettingsSection(undefined); setSettingsOpen(true); return true },+ 'app.shortcutsPanel': () => { setShortcutsOpen((v) => !v); return true },+ 'view.kanbanToggle': () => {+ const id = useProjects.getState().activeProjectId+ if (!id) return false+ useViewMode.getState().toggle(id)+ return true+ },+ 'panel.explorer': () => { setExplorerOpen((v) => !v); return true },+ 'panel.sourceControl': () => { setScOpen((v) => !v); return true },+ 'panel.sessions': () => { toggleSessionsPin(); return true },+ 'canvas.undo': () => { undo(); return true },+ 'canvas.redo': () => { redo(); return true },+ 'canvas.fitAll': () => { fitAll(); return true },++ 'canvas.tidy': () => { arrangeAllNodes(); return true },+ 'canvas.deleteSelection': deleteSelectionCommand,+ 'node.newTerminal': () => { addTerminal(); return true },+ 'node.newAgent': () => {+ // launchableDefaultAgent, not the raw setting: a default naming a since-removed custom+ // agent would otherwise type its bare `custom:<uuid>` id into the new node's shell.+ addAgentNode(launchableDefaultAgent(useSettings.getState().settings))+ return true}+ // node.close / node.toggleMarkdown: main-process intercepted on desktop; deliberately+ // no renderer handler (the browser owns ⌘W in the Server Edition — see bridge/stubs.ts).+ // terminal.* / scm.commit / speech.dictation: owned by their local listeners.+ },+ gestures: {+ // A KEYED dictation shortcut (e.g. "Cmd+Alt+D") toggles dictation. The chord is the+ // registry's first effective `speech.dictation` binding (`dictationBinding()`), so a+ // remap lands here without touching this file. A modifier-only shortcut (the default,+ // "Cmd+Alt") is hold-to-talk instead — matchesShortcut always returns false for that+ // shape (its `key` is null), so this gesture is naturally a no-op for it; see the+ // dedicated hold-mode effect above, which is what fires in that case. The DISABLED case+ // (`''`) needs no guard for the same reason: an empty parse also has a null key.+ // The dispatcher only offers it in plain app focus (not typing / terminal / kanban).+ keyedDictation: (e) => {+ if (!matchesShortcut(e, dictationBinding(), isMac)) return false+ e.preventDefault()+ toggleDictation()+ return true+ },+ zoom: zoomGesture,+ projectJump: projectJumpGesture,+ copy: copyGesture+ }+ }++ useEffect(() => {+ const onKey = (e: KeyboardEvent) => {+ const deps = globalKeyDeps.current+ if (deps) dispatchGlobalKeydown(e, deps)}window.addEventListener('keydown', onKey)return () => window.removeEventListener('keydown', onKey)diff --cc src/renderer/components/ShortcutsPanel.tsxindex b9e323690,346819db4..1f492e254--- a/src/renderer/components/ShortcutsPanel.tsx+++ b/src/renderer/components/ShortcutsPanel.tsx@@@ -52,8 -84,7 +84,8 @@@ function buildSections(dictationChord:// where a browser insists on handling it too it means the same thing we do ("actual size")// instead of fighting us. Shift+1 is nobody else's key on any surface.{ keys: ['⌘', '0'], label: 'Zoom to 100%' },- { keys: ['⇧', '1'], label: 'Fit view' }+ { keys: ['⇧', '1'], label: 'Fit view' },- { keys: ['⌘', '⇧', 'A'], label: 'Tidy canvas' }++ ...cmd('canvas.tidy', 'Tidy canvas')]},{diff --cc src/shared/keybindings.test.tsindex ccb9afdf9,1af5f304f..680e838d9--- a/src/shared/keybindings.test.ts+++ b/src/shared/keybindings.test.ts@@@ -81,6 -83,6 +83,8 @@@ describe('registry invariants', () =>darwin: ['Delete', 'Backspace'], other: ['Delete', 'Backspace'], allowBareKey: true },{ id: 'canvas.fitAll', title: 'Fit all nodes in view', group: 'Canvas', scope: 'canvas',darwin: [], other: [] },++ { id: 'canvas.tidy', title: 'Tidy canvas', group: 'Canvas', scope: 'canvas',++ darwin: ['Cmd+Shift+A'], other: ['Cmd+Shift+A'] },{ id: 'canvas.groupSelection', title: 'Group selection', group: 'Canvas', scope: 'canvas',darwin: [], other: [] },{ id: 'node.newTerminal', title: 'New terminal node', group: 'Nodes', scope: 'canvas',diff --cc src/shared/keybindings.tsindex 4606501de,7f397f9b6..1048d5ba4--- a/src/shared/keybindings.ts+++ b/src/shared/keybindings.ts@@@ -49,6 -49,6 +49,7 @@@ export type CommandId| 'canvas.redo'| 'canvas.deleteSelection'| 'canvas.fitAll'++ | 'canvas.tidy'| 'canvas.groupSelection'| 'node.newTerminal'| 'node.newAgent'@@@ -94,6 -94,6 +95,9 @@@ export const COMMAND_DEFINITIONS: readoallowBareKey: true },{ id: 'canvas.fitAll', title: 'Fit all nodes in view', group: 'Canvas', scope: 'canvas',defaultBindings: both() },++ { id: 'canvas.tidy', title: 'Tidy canvas', group: 'Canvas', scope: 'canvas',++ // arrangeAllNodes self-guards (kanban open, <2 top-level nodes), same as the ⌘K/menu entries.++ defaultBindings: both('Cmd+Shift+A') },{ id: 'canvas.groupSelection', title: 'Group selection', group: 'Canvas', scope: 'canvas',defaultBindings: both() },