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): effective bindings + platform-resolved conflict detection
enesfc4eca60ccd3
diff --git a/src/shared/keybindings.test.ts b/src/shared/keybindings.test.tsindex 1acafb1a3..c950f44a6 100644--- a/src/shared/keybindings.test.ts+++ b/src/shared/keybindings.test.ts@@ -3,7 +3,10 @@ import {COMMAND_DEFINITIONS,COMMANDS_BY_ID,isCommandId,- normalizeBindingForCommand+ normalizeBindingForCommand,+ getEffectiveBindings,+ bindingIdentity,+ findKeybindingConflicts} from './keybindings'import { parseShortcut } from './shortcut'@@ -93,3 +96,56 @@ describe('normalizeBindingForCommand', () => {}})})++describe('getEffectiveBindings', () => {+ it('returns platform defaults with no override', () => {+ expect(getEffectiveBindings('terminal.copySelection', {}, true)).toEqual(['Cmd+C'])+ expect(getEffectiveBindings('terminal.copySelection', {}, false)).toEqual([+ 'Cmd+Shift+C', 'Ctrl+Insert'+ ])+ })+ it('an override replaces defaults; [] disables', () => {+ const o = { 'node.newTerminal': ['Cmd+Shift+T'], 'canvas.undo': [] as string[] }+ expect(getEffectiveBindings('node.newTerminal', o, true)).toEqual(['Cmd+Shift+T'])+ expect(getEffectiveBindings('canvas.undo', o, true)).toEqual([])+ })+})++describe('bindingIdentity', () => {+ it('resolves Cmd and literal Ctrl to the same identity on non-mac', () => {+ expect(bindingIdentity('Cmd+K', false)).toBe(bindingIdentity('Ctrl+K', false))+ })+ it('keeps them distinct on mac', () => {+ expect(bindingIdentity('Cmd+K', true)).not.toBe(bindingIdentity('Ctrl+K', true))+ })+})++describe('findKeybindingConflicts', () => {+ it('reports nothing for pure defaults', () => {+ expect(findKeybindingConflicts({}, true)).toEqual([])+ expect(findKeybindingConflicts({}, false)).toEqual([])+ })+ it('the shipped default table is conflict-free even under full scrutiny', () => {+ expect(findKeybindingConflicts({}, true, { includeDefaults: true })).toEqual([])+ expect(findKeybindingConflicts({}, false, { includeDefaults: true })).toEqual([])+ })+ it('flags an override colliding with a default in the same bucket', () => {+ const conflicts = findKeybindingConflicts({ 'canvas.fitAll': ['Cmd+K'] }, true)+ expect(conflicts).toEqual([+ { binding: 'Cmd+K', commandIds: ['app.commandPalette', 'canvas.fitAll'] }+ ])+ })+ it('flags a cross-spelling collision on non-mac (Ctrl+K vs Cmd+K)', () => {+ const conflicts = findKeybindingConflicts({ 'canvas.fitAll': ['Ctrl+K'] }, false)+ expect(conflicts.map((c) => c.commandIds)).toEqual([['app.commandPalette', 'canvas.fitAll']])+ })+ it('does not flag collisions across buckets', () => {+ // terminal.find is Cmd+F in the terminal bucket; an app-bucket Cmd+F is legal.+ expect(findKeybindingConflicts({ 'canvas.fitAll': ['Cmd+F'] }, true)).toEqual([])+ })+ it('two disabled commands never conflict', () => {+ expect(+ findKeybindingConflicts({ 'canvas.fitAll': [], 'canvas.groupSelection': [] }, true)+ ).toEqual([])+ })+})diff --git a/src/shared/keybindings.ts b/src/shared/keybindings.tsindex d559c4334..28b24cea8 100644--- a/src/shared/keybindings.ts+++ b/src/shared/keybindings.ts@@ -171,3 +171,76 @@ export function normalizeBindingForCommand(}return { ok: true, value: serializeShortcut(p) }}++/** User overrides, as stored in settings.json under `keybindings`. Absent id = defaults;+ * `[]` = disabled. */+export type KeybindingOverrides = Partial<Record<CommandId, readonly string[]>>++export function getEffectiveBindings(+ id: CommandId,+ overrides: KeybindingOverrides,+ isMac: boolean+): readonly string[] {+ const override = overrides[id]+ if (override !== undefined) return override+ const def = COMMANDS_BY_ID.get(id)+ if (!def) return []+ return isMac ? def.defaultBindings.darwin : def.defaultBindings.other+}++/** Platform-resolved identity: two spellings that press the same physical modifiers + key get+ * the same identity (`Cmd+K` === `Ctrl+K` on non-mac, but not on mac). */+export function bindingIdentity(binding: string, isMac: boolean): string {+ const p = parseShortcut(binding)+ const m = resolvedModifiers(p, isMac)+ return [+ m.meta ? 'M' : '',+ m.ctrl ? 'C' : '',+ m.alt ? 'A' : '',+ m.shift ? 'S' : '',+ ':',+ p.key ?? '(hold)'+ ].join('')+}++/** Commands sharing a bucket compete for the same keys. 'app' and 'canvas' share one global+ * keyspace (both dispatch from the window listener; canvas commands are merely inert while+ * the board is open); terminal and scm are their own focused surfaces. */+export function conflictBucket(scope: CommandScope): 'global' | 'terminal' | 'scm' {+ return scope === 'app' || scope === 'canvas' ? 'global' : scope+}++export interface KeybindingConflict {+ /** Canonical string of one colliding spelling (the first seen). */+ binding: string+ /** Sorted ids of every command holding the identity. */+ commandIds: CommandId[]+}++/** Collisions between effective bindings within a bucket. By default only collisions touching+ * at least one overridden command are reported (shipped defaults are asserted conflict-free+ * by a registry test using `includeDefaults: true` — user-facing surfaces never nag about+ * stock bindings). */+export function findKeybindingConflicts(+ overrides: KeybindingOverrides,+ isMac: boolean,+ opts: { includeDefaults?: boolean } = {}+): KeybindingConflict[] {+ const byBucketAndIdentity = new Map<string, { binding: string; ids: Set<CommandId> }>()+ for (const def of COMMAND_DEFINITIONS) {+ for (const binding of getEffectiveBindings(def.id, overrides, isMac)) {+ const key = `${conflictBucket(def.scope)} ${bindingIdentity(binding, isMac)}`+ const entry = byBucketAndIdentity.get(key) ?? { binding, ids: new Set<CommandId>() }+ entry.ids.add(def.id)+ byBucketAndIdentity.set(key, entry)+ }+ }+ const conflicts: KeybindingConflict[] = []+ for (const { binding, ids } of byBucketAndIdentity.values()) {+ if (ids.size < 2) continue+ const commandIds = [...ids].sort()+ const touchesOverride = commandIds.some((id) => overrides[id] !== undefined)+ if (opts.includeDefaults || touchesOverride) conflicts.push({ binding, commandIds })+ }+ return conflicts+}