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
feat(keybindings): command registry with platform default table
enes1e6f617fab06
diff --git a/src/shared/keybindings.test.ts b/src/shared/keybindings.test.tsnew file mode 100644index 000000000..eb3d9b5c4--- /dev/null+++ b/src/shared/keybindings.test.ts@@ -0,0 +1,38 @@+import { describe, it, expect } from 'vitest'+import { COMMAND_DEFINITIONS, COMMANDS_BY_ID, isCommandId } from './keybindings'+import { parseShortcut } from './shortcut'++describe('registry invariants', () => {+ it('has unique ids and a map that covers them all', () => {+ const ids = COMMAND_DEFINITIONS.map((d) => d.id)+ expect(new Set(ids).size).toBe(ids.length)+ expect(COMMANDS_BY_ID.size).toBe(ids.length)+ for (const d of COMMAND_DEFINITIONS) expect(COMMANDS_BY_ID.get(d.id)).toBe(d)+ })++ it('every default binding parses, and keyed defaults carry a key', () => {+ for (const d of COMMAND_DEFINITIONS) {+ for (const s of [...d.defaultBindings.darwin, ...d.defaultBindings.other]) {+ const p = parseShortcut(s)+ if (d.allowHoldChord) continue+ expect(p.key, `${d.id}: ${s}`).not.toBeNull()+ }+ }+ })++ it('pins the defaults that PR 2 will wire (behavior contract)', () => {+ expect(COMMANDS_BY_ID.get('app.commandPalette')?.defaultBindings.darwin).toEqual(['Cmd+K'])+ expect(COMMANDS_BY_ID.get('node.close')?.defaultBindings.other).toEqual(['Cmd+W'])+ expect(COMMANDS_BY_ID.get('canvas.redo')?.defaultBindings.other).toEqual(['Cmd+Shift+Z', 'Cmd+Y'])+ expect(COMMANDS_BY_ID.get('terminal.copySelection')?.defaultBindings.other).toEqual([+ 'Cmd+Shift+C', 'Ctrl+Insert'+ ])+ expect(COMMANDS_BY_ID.get('speech.dictation')?.defaultBindings.darwin).toEqual(['Cmd+Alt'])+ expect(COMMANDS_BY_ID.get('canvas.fitAll')?.defaultBindings.darwin).toEqual([])+ })++ it('isCommandId accepts known ids and rejects unknowns', () => {+ expect(isCommandId('node.newTerminal')).toBe(true)+ expect(isCommandId('node.selfDestruct')).toBe(false)+ })+})diff --git a/src/shared/keybindings.ts b/src/shared/keybindings.tsnew file mode 100644index 000000000..019de9c34--- /dev/null+++ b/src/shared/keybindings.ts@@ -0,0 +1,131 @@+/**+ * The keybinding registry + engine, shared by main, renderer, and the Server Edition bridge.+ * Registry, validation, effective-binding resolution, conflict detection, override+ * sanitization, and the pure event→command resolver all live in this one module so the+ * dispatchers, Settings UI, and ShortcutsPanel cannot drift apart. Builds on shortcut.ts —+ * canonical binding strings are shortcut.ts strings (`Cmd` = abstract primary modifier,+ * `Ctrl` = literal Control, modifier-only chords = hold-to-talk).+ */+import { parseShortcut, serializeShortcut, resolvedModifiers } from './shortcut'+import type { ParsedShortcut, ShortcutKeyEvent } from './shortcut'++export type CommandScope = 'app' | 'canvas' | 'terminal' | 'scm'+export type CommandGroup = 'General' | 'Canvas' | 'Nodes' | 'Terminal' | 'Source Control' | 'Speech'++export interface CommandDefinition {+ id: CommandId+ /** English row label for ShortcutsPanel and the Settings section. */+ title: string+ group: CommandGroup+ scope: CommandScope+ /** Canonical shortcut.ts strings. `other` covers linux + win32 — widen to three buckets+ * only when a real default needs to differ between them. Empty array = unassigned. */+ defaultBindings: { darwin: readonly string[]; other: readonly string[] }+ /** May fire while a real input/textarea/contentEditable is focused (xterm excluded). */+ allowWhileTyping?: boolean+ /** May fire while an xterm has focus. Scope 'terminal' implies it. */+ allowInTerminal?: boolean+ /** Permits modifier-less bindings, restricted to SAFE_BARE_KEYS. */+ allowBareKey?: boolean+ /** Permits modifier-only hold chords (hold-to-talk). */+ allowHoldChord?: boolean+}++export type CommandId =+ | 'app.commandPalette'+ | 'app.settings'+ | 'app.shortcutsPanel'+ | 'view.kanbanToggle'+ | 'panel.explorer'+ | 'panel.sourceControl'+ | 'panel.sessions'+ | 'canvas.undo'+ | 'canvas.redo'+ | 'canvas.deleteSelection'+ | 'canvas.fitAll'+ | 'canvas.groupSelection'+ | 'node.newTerminal'+ | 'node.newAgent'+ | 'node.close'+ | 'node.toggleMarkdown'+ | 'terminal.find'+ | 'terminal.copySelection'+ | 'scm.commit'+ | 'speech.dictation'++/** Same defaults on every platform. */+const both = (...bindings: string[]): { darwin: string[]; other: string[] } => ({+ darwin: bindings,+ other: [...bindings]+})++export const COMMAND_DEFINITIONS: readonly CommandDefinition[] = [+ // General — the Canvas.tsx:4491 block today; fires while an xterm has focus, and (bug,+ // fixed in the dispatch PR) also while typing. allowWhileTyping is deliberately absent.+ { id: 'app.commandPalette', title: 'Command palette', group: 'General', scope: 'app',+ defaultBindings: both('Cmd+K'), allowInTerminal: true },+ { id: 'app.settings', title: 'Open settings', group: 'General', scope: 'app',+ defaultBindings: both('Cmd+Comma'), allowInTerminal: true },+ { id: 'app.shortcutsPanel', title: 'Keyboard shortcuts panel', group: 'General', scope: 'app',+ defaultBindings: both('Cmd+Slash'), allowInTerminal: true },+ { id: 'view.kanbanToggle', title: 'Toggle kanban board', group: 'General', scope: 'app',+ defaultBindings: both('Cmd+Shift+B'), allowInTerminal: true },+ { id: 'panel.explorer', title: 'Toggle explorer panel', group: 'General', scope: 'app',+ defaultBindings: both('Cmd+Shift+E'), allowInTerminal: true },+ { id: 'panel.sourceControl', title: 'Toggle source control panel', group: 'General', scope: 'app',+ defaultBindings: both('Cmd+Shift+G'), allowInTerminal: true },+ { id: 'panel.sessions', title: 'Pin sessions sidebar', group: 'General', scope: 'app',+ defaultBindings: both('Cmd+Shift+L'), allowInTerminal: true },++ // Canvas — inert while the kanban board is open (scope 'canvas'), blocked while typing.+ { id: 'canvas.undo', title: 'Undo', group: 'Canvas', scope: 'canvas',+ defaultBindings: both('Cmd+Z') },+ { id: 'canvas.redo', title: 'Redo', group: 'Canvas', scope: 'canvas',+ defaultBindings: { darwin: ['Cmd+Shift+Z'], other: ['Cmd+Shift+Z', 'Cmd+Y'] } },+ { id: 'canvas.deleteSelection', title: 'Delete selection', group: 'Canvas', scope: 'canvas',+ // Backspace off-mac deletes text too often to risk as a bare default.+ defaultBindings: { darwin: ['Delete', 'Backspace'], other: ['Delete'] },+ allowBareKey: true },+ { id: 'canvas.fitAll', title: 'Fit all nodes in view', group: 'Canvas', scope: 'canvas',+ defaultBindings: both() },+ { id: 'canvas.groupSelection', title: 'Group selection', group: 'Canvas', scope: 'canvas',+ defaultBindings: both() },++ // Nodes+ { id: 'node.newTerminal', title: 'New terminal node', group: 'Nodes', scope: 'canvas',+ defaultBindings: both('Cmd+T') },+ { id: 'node.newAgent', title: 'New agent node', group: 'Nodes', scope: 'canvas',+ // Non-mac note: Ctrl+Shift+C is a common terminal-copy convention; kept for parity+ // with current behavior, revisit with telemetry.+ defaultBindings: both('Cmd+Shift+C') },+ // Main-process intercepted today (unconditional): keep firing everywhere.+ { id: 'node.close', title: 'Close node / window', group: 'Nodes', scope: 'app',+ defaultBindings: both('Cmd+W'), allowInTerminal: true, allowWhileTyping: true },+ { id: 'node.toggleMarkdown', title: 'Toggle markdown view', group: 'Nodes', scope: 'app',+ defaultBindings: both('Cmd+M'), allowInTerminal: true, allowWhileTyping: true },++ // Terminal+ { id: 'terminal.find', title: 'Find in terminal', group: 'Terminal', scope: 'terminal',+ defaultBindings: both('Cmd+F') },+ { id: 'terminal.copySelection', title: 'Copy terminal selection', group: 'Terminal',+ scope: 'terminal',+ // Plain Ctrl+C stays SIGINT off-mac; Cmd+Shift+C resolves to Ctrl+Shift+C there.+ defaultBindings: { darwin: ['Cmd+C'], other: ['Cmd+Shift+C', 'Ctrl+Insert'] } },++ // Source control (local handler; registry supplies label + remap)+ { id: 'scm.commit', title: 'Commit', group: 'Source Control', scope: 'scm',+ defaultBindings: both('Cmd+Enter'), allowWhileTyping: true },++ // Speech — the migrated dictation chord; hold-to-talk by default.+ { id: 'speech.dictation', title: 'Dictate', group: 'Speech', scope: 'app',+ defaultBindings: both('Cmd+Alt'),+ allowHoldChord: true, allowInTerminal: true, allowWhileTyping: true }+]++export const COMMANDS_BY_ID: ReadonlyMap<CommandId, CommandDefinition> = new Map(+ COMMAND_DEFINITIONS.map((d) => [d.id, d])+)++export function isCommandId(v: string): v is CommandId {+ return COMMANDS_BY_ID.has(v as CommandId)+}