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): override write path + main-intercept shadow detection
enesb3e98f9d5aaf
diff --git a/src/renderer/lib/keybindingOverrides.test.ts b/src/renderer/lib/keybindingOverrides.test.tsindex cf99bdf96..d4b6393f3 100644--- a/src/renderer/lib/keybindingOverrides.test.ts+++ b/src/renderer/lib/keybindingOverrides.test.ts@@ -3,7 +3,8 @@ import { DEFAULT_SETTINGS } from '@shared/types'import { matchesShortcut, type ShortcutKeyEvent } from '@shared/shortcut'import { useSettings } from '../state/settings'import {- activeKeybindingOverrides, effectiveBindings, commandKeys, commandTooltip, chipFor+ activeKeybindingOverrides, effectiveBindings, commandKeys, commandTooltip, chipFor,+ setKeybindingOverride, commandKeysFor, dictationBinding} from './keybindingOverrides'const setKb = (kb: unknown) =>@@ -105,3 +106,36 @@ describe('chipFor', () => {expect(chipFor('canvas.fitAll', true)).toBe('')})})++describe('setKeybindingOverride', () => {+ it('set, disable, and reset shape the map correctly', () => {+ setKeybindingOverride('node.newTerminal', ['Cmd+Shift+T'])+ expect(useSettings.getState().settings.keybindings).toEqual({+ 'node.newTerminal': ['Cmd+Shift+T']+ })+ setKeybindingOverride('canvas.undo', [])+ expect(useSettings.getState().settings.keybindings?.['canvas.undo']).toEqual([])+ setKeybindingOverride('node.newTerminal', null)+ expect('node.newTerminal' in (useSettings.getState().settings.keybindings ?? {})).toBe(false)+ })+ it('mirrors speech.dictation into speech.shortcut, and reset restores the default mirror', () => {+ setKeybindingOverride('speech.dictation', ['Cmd+Alt+D'])+ expect(useSettings.getState().settings.speech.shortcut).toBe('Cmd+Alt+D')+ setKeybindingOverride('speech.dictation', null)+ expect(useSettings.getState().settings.speech.shortcut).toBe(DEFAULT_SETTINGS.speech.shortcut)+ })+})++describe('commandKeysFor / dictationBinding', () => {+ it('lists every effective binding', () => {+ expect(commandKeysFor('canvas.deleteSelection', true)).toEqual([['Delete'], ['Backspace']])+ expect(commandKeysFor('canvas.fitAll', true)).toEqual([])+ })+ it('dictationBinding follows the override and reports disabled as empty', () => {+ expect(dictationBinding()).toBe('Cmd+Alt')+ setKeybindingOverride('speech.dictation', ['Cmd+Alt+D'])+ expect(dictationBinding()).toBe('Cmd+Alt+D')+ setKeybindingOverride('speech.dictation', [])+ expect(dictationBinding()).toBe('')+ })+})diff --git a/src/renderer/lib/keybindingOverrides.ts b/src/renderer/lib/keybindingOverrides.tsindex 8b3493e44..780f8a9f9 100644--- a/src/renderer/lib/keybindingOverrides.ts+++ b/src/renderer/lib/keybindingOverrides.ts@@ -11,6 +11,7 @@ import {} from '@shared/keybindings'import { shortcutKeyParts } from '@shared/shortcut'import { isMacPlatform } from '@shared/platform-utils'+import { DEFAULT_SETTINGS } from '@shared/types'import { useSettings } from '../state/settings'const UNSET = Symbol('unset')@@ -53,3 +54,41 @@ export function chipFor(id: CommandId, isMac: boolean = isMacPlatform()): stringconst parts = commandKeys(id, isMac)return isMac ? parts.join('') : parts.join('+')}++/** The single WRITE path for overrides. `null` = reset (delete the key, defaults return);+ * `[]` = disabled. Values are stored as given — callers pass canonical strings from+ * `normalizeBindingForCommand`; the read path's sanitizer remains the safety net for+ * hand-edited files. `speech.dictation` also mirrors its first binding into the legacy+ * `speech.shortcut` field for one release, so a downgraded build keeps the user's chord.+ * On DISABLE (`[]`) `bindings?.[0]` is `undefined`, so the mirror falls back to the DEFAULT+ * chord rather than an empty string: a downgraded build then gets default dictation instead+ * of a broken value it cannot parse. */+export function setKeybindingOverride(id: CommandId, bindings: readonly string[] | null): void {+ const state = useSettings.getState()+ const next: KeybindingOverrides = { ...(state.settings.keybindings ?? {}) }+ if (bindings === null) delete next[id]+ else next[id] = [...bindings]+ if (id === 'speech.dictation') {+ const mirror = bindings?.[0] ?? DEFAULT_SETTINGS.speech.shortcut+ state.update({+ keybindings: next,+ speech: { ...state.settings.speech, shortcut: mirror }+ })+ return+ }+ state.update({ keybindings: next })+}++/** Display parts for EVERY effective binding (the panel shows the first; the Settings section+ * shows them all). [] when unbound/disabled. */+export function commandKeysFor(id: CommandId, isMac: boolean = isMacPlatform()): string[][] {+ return getEffectiveBindings(id, activeKeybindingOverrides(), isMac).map((b) =>+ shortcutKeyParts(b, isMac)+ )+}++/** The dictation chord's single source: the first effective `speech.dictation` binding.+ * `''` = the user disabled it (dictation shortcut off; the mic button still works). */+export function dictationBinding(): string {+ return effectiveBindings('speech.dictation')[0] ?? ''+}diff --git a/src/renderer/state/settings.ts b/src/renderer/state/settings.tsindex af9bec8b0..04433bd8d 100644--- a/src/renderer/state/settings.ts+++ b/src/renderer/state/settings.ts@@ -17,6 +17,9 @@ const SAVE_COALESCE_MS = 300let saveTimer: ReturnType<typeof setTimeout> | null = nulllet pendingSave: Settings | null = nullfunction scheduleSave(next: Settings): void {+ // Same guard as the beforeunload flush below: this module is transitively imported by+ // node-environment unit tests, where `window` doesn't exist and the timer would throw.+ if (typeof window === 'undefined') returnpendingSave = nextif (saveTimer) returnsaveTimer = setTimeout(() => {diff --git a/src/shared/keybindings.test.ts b/src/shared/keybindings.test.tsindex 43ef01773..1af5f304f 100644--- a/src/shared/keybindings.test.ts+++ b/src/shared/keybindings.test.ts@@ -8,7 +8,9 @@ import {bindingIdentity,findKeybindingConflicts,sanitizeKeybindingOverrides,- resolveCommandForKeyEvent+ resolveCommandForKeyEvent,+ MAIN_INTERCEPTED_COMMAND_IDS,+ findMainInterceptShadowing} from './keybindings'import { parseShortcut } from './shortcut'import type { ShortcutKeyEvent } from './shortcut'@@ -410,3 +412,30 @@ describe('resolveCommandForKeyEvent', () => {expect(resolveCommandForKeyEvent(ev({ metaKey: true, key: 'z' }), ctx(), o, true)).toBe('canvas.undo')})})++describe('findMainInterceptShadowing', () => {+ it('flags a main-intercepted remap that shadows another bucket', () => {+ expect(findMainInterceptShadowing('node.close', 'Cmd+F', {}, true)).toEqual(['terminal.find'])+ expect(findMainInterceptShadowing('node.close', 'Cmd+Enter', {}, true)).toEqual(['scm.commit'])+ })+ it('same-bucket collisions are the sanitizer/conflict path, still reported here', () => {+ expect(findMainInterceptShadowing('node.toggleMarkdown', 'Cmd+K', {}, true)).toEqual([+ 'app.commandPalette'+ ])+ })+ it('empty for a clean chord, for non-intercepted commands, and never self-reports', () => {+ expect(findMainInterceptShadowing('node.close', 'Cmd+Alt+F9', {}, true)).toEqual([])+ expect(findMainInterceptShadowing('canvas.undo', 'Cmd+F', {}, true)).toEqual([])+ expect(findMainInterceptShadowing('node.close', 'Cmd+W', {}, true)).toEqual([])+ })+ it('respects overrides and cross-spelling identities', () => {+ const o = { 'terminal.find': ['Cmd+Alt+F9'] }+ expect(findMainInterceptShadowing('node.close', 'Cmd+F', o, true)).toEqual([])+ expect(findMainInterceptShadowing('node.close', 'Ctrl+K', {}, false)).toEqual([+ 'app.commandPalette'+ ])+ })+ it('names exactly the two main-intercepted commands', () => {+ expect(MAIN_INTERCEPTED_COMMAND_IDS).toEqual(['node.close', 'node.toggleMarkdown'])+ })+})diff --git a/src/shared/keybindings.ts b/src/shared/keybindings.tsindex 516de04e7..773a2b4b2 100644--- a/src/shared/keybindings.ts+++ b/src/shared/keybindings.ts@@ -260,6 +260,38 @@ export function findKeybindingConflicts(return conflicts}+/** Commands the MAIN process intercepts via before-input-event. A remap of one of these is+ * swallowed app-wide before any renderer surface sees the key, so the Settings UI must check+ * its candidate against EVERY command — the per-bucket conflict detector cannot see this. */+export const MAIN_INTERCEPTED_COMMAND_IDS: readonly CommandId[] = [+ 'node.close',+ 'node.toggleMarkdown'+]++/** Cross-bucket shadowing check for a candidate binding of a main-intercepted command:+ * every OTHER command whose effective bindings share the candidate's platform identity.+ * Empty for non-intercepted commands (their collisions are the ordinary bucket check). */+export function findMainInterceptShadowing(+ id: CommandId,+ candidate: string,+ overrides: KeybindingOverrides,+ isMac: boolean+): CommandId[] {+ if (!MAIN_INTERCEPTED_COMMAND_IDS.includes(id)) return []+ const target = bindingIdentity(candidate, isMac)+ const hits: CommandId[] = []+ for (const def of COMMAND_DEFINITIONS) {+ if (def.id === id) continue+ for (const binding of getEffectiveBindings(def.id, overrides, isMac)) {+ if (bindingIdentity(binding, isMac) === target) {+ hits.push(def.id)+ break+ }+ }+ }+ return hits+}+/** Validate a raw `settings.keybindings` value (hand-editable JSON) into a safe override map.* Loops until conflict-free so one bad edit cannot leave ambiguous dispatch. This is the* SETTINGS-LOAD path: it applies what survives and warns about what it dropped. It is not the