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(terminal): registry chords xterm would consume now bubble to the dispatcher
enesa70d683a5116
diff --git a/src/renderer/components/kanban/ModalTerminal.tsx b/src/renderer/components/kanban/ModalTerminal.tsxindex d0630d317..5cb7b2b61 100644--- a/src/renderer/components/kanban/ModalTerminal.tsx+++ b/src/renderer/components/kanban/ModalTerminal.tsx@@ -7,7 +7,7 @@ import { reportsOwnCopy } from '@shared/agents/config'import type { AgentId } from '@shared/agents/config'import { readsClaudeTranscript } from '../../lib/transcriptGates'import { liveProjectJumpTarget } from '../../lib/projectJump'-import { terminalShortcutPolicy } from '../../lib/keybindingOverrides'+import { terminalChordBubbles, terminalShortcutPolicy } from '../../lib/keybindingOverrides'import { FindBar } from '../FindBar'import { useAgentStatus } from '../../state/agentStatus'import { useProjects } from '../../state/projects'@@ -207,8 +207,16 @@ export function ModalTerminal({ nodeId, spawn, searchOpen, onCloseSearch }: Modaterm.attachCustomKeyEventHandler((e) => {const ownsProjectJump =terminalShortcutPolicy() !== 'terminal-first' && liveProjectJumpTarget(e) !== null- const action = terminalKeyAction(e, term.hasSelection(), ownsProjectJump)+ // MIRROR TerminalNode's registryOwns — but with `kanbanOpen: true` ALWAYS: the modal only+ // exists over the board, where the resolver refuses canvas-scope commands (directional+ // focus etc. mean nothing here), so those chords keep reaching the pty; app-scope+ // allowInTerminal commands still bubble, matching what the dispatcher would claim.+ const registryOwns = terminalChordBubbles(e, true)+ const action = terminalKeyAction(e, term.hasSelection(), ownsProjectJump, registryOwns)if (action === 'pass') return true+ // 'bubble': hand the chord to the window dispatcher — no preventDefault (it bails on+ // defaultPrevented), no xterm processing. See TerminalNode's twin comment.+ if (action === 'bubble') return falsee.preventDefault()if (action === 'copy') window.nodeTerminal.clipboard.writeText(term.getSelection())else if (action === 'shift-enter' && sessionId) transport.write(sessionId, SHIFT_ENTER_SEQ)diff --git a/src/renderer/lib/keybindingOverrides.test.ts b/src/renderer/lib/keybindingOverrides.test.tsindex 531446bc4..f1b67fe9a 100644--- a/src/renderer/lib/keybindingOverrides.test.ts+++ b/src/renderer/lib/keybindingOverrides.test.ts@@ -5,7 +5,7 @@ import { useSettings } from '../state/settings'import {activeKeybindingOverrides, effectiveBindings, commandKeys, commandTooltip, chipFor,setKeybindingOverride, commandKeysFor, dictationBinding,- terminalShortcutPolicy, noteTerminalCapture+ terminalShortcutPolicy, terminalChordBubbles, noteTerminalCapture} from './keybindingOverrides'const setKb = (kb: unknown) =>@@ -200,3 +200,57 @@ describe('commandKeysFor / dictationBinding', () => {expect(dictationBinding()).toBe('')})})++describe('terminalChordBubbles', () => {+ // Platform-independent by construction: every case pins an explicit literal-Ctrl override, so+ // the assertions do not depend on which platform the test host reports.+ const bubbleEv = (p: Partial<ShortcutKeyEvent>): ShortcutKeyEvent => ({+ metaKey: false,+ ctrlKey: false,+ shiftKey: false,+ altKey: false,+ key: 'ArrowLeft',+ ...p+ })++ it('true for an allowInTerminal canvas command the dispatcher would claim', () => {+ setKb({ 'node.focusLeft': ['Ctrl+Shift+ArrowLeft'] })+ expect(+ terminalChordBubbles(bubbleEv({ ctrlKey: true, shiftKey: true, key: 'ArrowLeft' }), false)+ ).toBe(true)+ })++ it('false under terminal-first — the chord stays with the shell', () => {+ useSettings.setState({+ settings: {+ ...DEFAULT_SETTINGS,+ keybindings: { 'node.focusLeft': ['Ctrl+Shift+ArrowLeft'] } as never,+ terminalShortcutPolicy: 'terminal-first'+ }+ })+ expect(+ terminalChordBubbles(bubbleEv({ ctrlKey: true, shiftKey: true, key: 'ArrowLeft' }), false)+ ).toBe(false)+ })++ it('false over the kanban board for a canvas-scope command', () => {+ setKb({ 'node.focusLeft': ['Ctrl+Shift+ArrowLeft'] })+ expect(+ terminalChordBubbles(bubbleEv({ ctrlKey: true, shiftKey: true, key: 'ArrowLeft' }), true)+ ).toBe(false)+ })++ it('false for a terminal-scope command — its local listener owns the chord', () => {+ setKb({ 'terminal.find': ['Ctrl+Shift+F1'] })+ expect(+ terminalChordBubbles(bubbleEv({ ctrlKey: true, shiftKey: true, key: 'F1' }), false)+ ).toBe(false)+ })++ it('false for a chord nothing resolves', () => {+ setKb(undefined)+ expect(+ terminalChordBubbles(bubbleEv({ ctrlKey: true, shiftKey: true, key: 'F12' }), false)+ ).toBe(false)+ })+})diff --git a/src/renderer/lib/keybindingOverrides.ts b/src/renderer/lib/keybindingOverrides.tsindex abc6ca3cc..8d7c5219a 100644--- a/src/renderer/lib/keybindingOverrides.ts+++ b/src/renderer/lib/keybindingOverrides.ts@@ -7,8 +7,10 @@*/import {getEffectiveBindings, sanitizeKeybindingOverrides, normalizeTerminalShortcutPolicy,+ resolveCommandForKeyEvent, COMMANDS_BY_ID,type CommandId, type KeybindingOverrides, type TerminalShortcutPolicy} from '@shared/keybindings'+import type { ShortcutKeyEvent } from '@shared/shortcut'import { shortcutKeyParts } from '@shared/shortcut'import { isMacPlatform } from '@shared/platform-utils'import { DEFAULT_SETTINGS } from '@shared/types'@@ -107,6 +109,33 @@ export function terminalShortcutPolicy(): TerminalShortcutPolicy {return normalizeTerminalShortcutPolicy(useSettings.getState().settings.terminalShortcutPolicy)}+/** Should this keydown, seen INSIDE a focused terminal, bypass xterm and bubble to the window+ * dispatcher? True only when the live registry resolves it to an app/canvas command that is+ * allowed in terminals. This is the caller-side matcher for `terminalKeyAction`'s `registryOwns`+ * (the one-matcher discipline `ownsProjectJump` set): xterm's own keymap CONSUMES some chords —+ * modified arrows become `CSI 1;N x` and the event is cancelled — so without this, a registry+ * chord like Ctrl+Shift+Arrow never reaches the dispatcher from the one place it targets.+ * Everything the resolver already encodes applies for free: under terminal-first the resolver+ * refuses non-terminal-scope commands (the chord stays with the shell), an unbound/remapped+ * chord follows the live overrides, and `kanbanOpen` refuses canvas-scope commands so a modal+ * terminal over the board keeps its bytes. Terminal-SCOPE commands are excluded — their local+ * listeners own them and this helper must not reroute their chords. */+export function terminalChordBubbles(e: ShortcutKeyEvent, kanbanOpen: boolean): boolean {+ const id = resolveCommandForKeyEvent(+ e,+ {+ typing: false,+ terminal: true,+ terminalFirst: terminalShortcutPolicy() === 'terminal-first',+ kanbanOpen+ },+ activeKeybindingOverrides(),+ isMacPlatform()+ )+ if (id === null) return false+ return COMMANDS_BY_ID.get(id)?.scope !== 'terminal'+}+/** Once per command, ever (persisted in settings so Server Edition shares it): record that* app-first captured this command's chord from a focused terminal, and tell the banner.* Silent under terminal-first — nothing is being taken from the terminal there.diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex d6ea5513a..2c3166d5f 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -143,7 +143,7 @@ import { PresenceChips } from '../components/PresenceChips'import { useAgentNodes } from '../state/agentNodes'import { useTerminalFocus } from '../state/terminalFocus'import { useProjects } from '../state/projects'-import { useViewMode, viewFor } from '../state/viewMode'+import { isKanbanOpen, useViewMode, viewFor } from '../state/viewMode'import { useSshConn } from '../state/sshConn'import { useWorktrees } from '../state/worktrees'import { isRemoteSessionNode } from '@shared/worktree'@@ -172,7 +172,12 @@ import { agentEnvSnapshot } from '@renderer/lib/agentEnv'import { normalizedAgentModel } from '@shared/agents/model-gateway'import { ensureActivePermissionMode } from '../state/permissionMode'import { buildSshArgs, sshConnectionIdForProject, sshHostKey, type SshConnection } from '@shared/ssh'-import { chipFor, effectiveBindings, terminalShortcutPolicy } from '../lib/keybindingOverrides'+import {+ chipFor,+ effectiveBindings,+ terminalChordBubbles,+ terminalShortcutPolicy+} from '../lib/keybindingOverrides'import { matchesShortcut } from '@shared/shortcut'import { hintLabel, isWindowsPlatform, isMacPlatform } from '@shared/platform-utils'import { ColumnPill } from '../components/kanban/ColumnPill'@@ -2533,8 +2538,18 @@ export function TerminalNode({term.attachCustomKeyEventHandler((e) => {const ownsProjectJump =terminalShortcutPolicy() !== 'terminal-first' && liveProjectJumpTarget(e) !== null- const action = terminalKeyAction(e, term.hasSelection(), ownsProjectJump)+ const registryOwns = terminalChordBubbles(+ e,+ isKanbanOpen(useProjects.getState().activeProjectId ?? '')+ )+ const action = terminalKeyAction(e, term.hasSelection(), ownsProjectJump, registryOwns)if (action === 'pass') return true+ // 'bubble': the window dispatcher owns this chord (an allowInTerminal registry command).+ // Return false so xterm skips its own keymap — which would consume e.g. Ctrl+Shift+Arrow+ // into a CSI write and cancel the event — and DO NOT preventDefault: the dispatcher bails+ // on defaultPrevented events, so a prevented bubble would kill the very dispatch this+ // exists to reach.+ if (action === 'bubble') return falsee.preventDefault()if (action === 'copy') window.nodeTerminal.clipboard.writeText(term.getSelection())// Shift+Enter → ESC+CR so agent CLIs insert a newline instead of submittingdiff --git a/src/renderer/terminal/terminal-config.test.ts b/src/renderer/terminal/terminal-config.test.tsindex a8fb34a2d..04f30f838 100644--- a/src/renderer/terminal/terminal-config.test.ts+++ b/src/renderer/terminal/terminal-config.test.ts@@ -528,6 +528,43 @@ describe('terminalKeyAction', () => {expect(terminalKeyAction(ev({ ctrlKey: true, shiftKey: true }), false)).toBe('swallow')})+ // `registryOwns` (decided by the caller via `terminalChordBubbles`): the window dispatcher will+ // claim this chord, so xterm must neither process nor cancel it — 'bubble' = return false with+ // NO preventDefault. Deliberately the LAST branch: chords with a local owner keep it.+ it('bubbles a registry-owned keydown that nothing local owns', () => {+ const arrow = { key: 'ArrowLeft', code: 'ArrowLeft', ctrlKey: true, shiftKey: true }+ expect(terminalKeyAction(ev(arrow), false, false, true)).toBe('bubble')+ // default false = byte-identical pre-feature behavior+ expect(terminalKeyAction(ev(arrow), false)).toBe('pass')+ expect(terminalKeyAction(ev(arrow), false, false, false)).toBe('pass')+ })++ it('never bubbles a chord a local owner already claims, and never on keyup', () => {+ // copy chord (selection) beats bubble+ expect(terminalKeyAction(ev({ ctrlKey: true, shiftKey: true }), true, false, true)).toBe('copy')+ // copy chord (no selection) still swallows — SIGINT must never reach the pty+ expect(terminalKeyAction(ev({ ctrlKey: true, shiftKey: true }), false, false, true)).toBe(+ 'swallow'+ )+ // shift-enter keeps its remap+ expect(+ terminalKeyAction(ev({ key: 'Enter', code: 'Enter', shiftKey: true }), false, false, true)+ ).toBe('shift-enter')+ // project-jump swallow wins over bubble+ expect(terminalKeyAction(ev({ key: '1', code: 'Digit1', metaKey: true }), false, true, true)).toBe(+ 'swallow'+ )+ // keyup never bubbles — the dispatcher only acts on keydown+ expect(+ terminalKeyAction(+ ev({ key: 'ArrowLeft', code: 'ArrowLeft', ctrlKey: true, shiftKey: true, type: 'keyup' }),+ false,+ false,+ true+ )+ ).toBe('pass')+ })+it('exports the ESC+CR sequence', () => {expect(SHIFT_ENTER_SEQ).toBe('\x1b\r')})diff --git a/src/renderer/terminal/terminal-config.ts b/src/renderer/terminal/terminal-config.tsindex 39ac9b5ec..12fa04d40 100644--- a/src/renderer/terminal/terminal-config.ts+++ b/src/renderer/terminal/terminal-config.ts@@ -766,7 +766,7 @@ export function copyKeyAction(e: CopyShortcutEvent, hasSelection: boolean): Copy*/export const SHIFT_ENTER_SEQ = '\x1b\r'-export type TerminalKeyAction = CopyKeyAction | 'shift-enter'+export type TerminalKeyAction = CopyKeyAction | 'shift-enter' | 'bubble'/*** Superset of `copyKeyAction` used by the terminal's custom key handler.@@ -785,7 +785,8 @@ export type TerminalKeyAction = CopyKeyAction | 'shift-enter'export function terminalKeyAction(e: CopyShortcutEvent,hasSelection: boolean,- ownsProjectJump = false+ ownsProjectJump = false,+ registryOwns = false): TerminalKeyAction {if (e.type === 'keydown' &&@@ -797,5 +798,15 @@ export function terminalKeyAction()return 'shift-enter'if (ownsProjectJump) return 'swallow'- return copyKeyAction(e, hasSelection)+ const base = copyKeyAction(e, hasSelection)+ if (base !== 'pass') return base+ // `registryOwns` — decided by the caller via `terminalChordBubbles`, the same live-registry+ // matcher discipline as `ownsProjectJump` — means the window dispatcher will claim this chord+ // (an allowInTerminal app/canvas command). 'bubble' tells the consumer to return false WITHOUT+ // preventDefault: xterm skips its own keymap (which would turn e.g. Ctrl+Shift+Arrow into a+ // `CSI 1;N x` write and CANCEL the event, so the dispatcher never sees it) and the untouched+ // event bubbles to the window listener. Deliberately LAST: the copy chords and Shift+Enter+ // keep their existing owners whatever the registry says.+ if (e.type === 'keydown' && registryOwns) return 'bubble'+ return 'pass'}