-
-
Notifications
You must be signed in to change notification settings - Fork 64
feat: configurable keybinding system with agent presets #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IShaalan
wants to merge
16
commits into
johannesjo:main
Choose a base branch
from
IShaalan:feature/configurable-keybindings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6c83e5f
feat(keybindings): add types, default binding registry, and tests
IShaalan 2dc7687
fix(keybindings): align binding IDs with spec naming convention
IShaalan 064b25f
fix(keybindings): use cmdOrCtrl for cross-platform bindings
IShaalan c7dc121
feat(keybindings): add presets and resolution logic with conflict det…
IShaalan 98cf05c
feat(keybindings): add backend persistence with atomic writes and fal…
IShaalan cd623cf
feat(keybindings): add frontend store with reactive resolution and pe…
IShaalan c240991
refactor(shortcuts): wire app-layer shortcuts to binding registry
IShaalan f8132b8
refactor(terminal): wire terminal shortcuts to binding registry
IShaalan 0c8a521
feat(keybindings): interactive keybinding editor with presets and con…
IShaalan 100dcc2
feat(keybindings): add opt-in migration banner for existing users
IShaalan ffa8ab1
fix(keybindings): show unbound bindings in editor with dash indicator
IShaalan d55512b
fix(keybindings): fix reactivity bug, add dismiss to banner, gitignor…
IShaalan e989b39
fix(keybindings): scope user overrides per preset
IShaalan cfc6029
fix(keybindings): let Escape propagate to close dialog during recording
IShaalan 98aa5d8
fix(keybindings): improve conflict detection, perf, and code quality
IShaalan 0bf49d7
fix(keybindings): address PR review feedback
IShaalan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,4 @@ release | |
| .idea | ||
| .claude | ||
| .DS_Store | ||
| docs/plans | ||
| docs/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { describe, expect, it, beforeEach, afterEach } from 'vitest'; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import os from 'os'; | ||
| import { loadKeybindings, saveKeybindings } from '../keybindings.js'; | ||
|
|
||
| describe('keybindings persistence', () => { | ||
| let tmpDir: string; | ||
|
|
||
| beforeEach(() => { | ||
| tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'keybindings-test-')); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| fs.rmSync(tmpDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it('returns default config when file does not exist', () => { | ||
| const result = loadKeybindings(tmpDir); | ||
| expect(result).toEqual({ preset: 'default', overridesByPreset: {} }); | ||
| }); | ||
|
|
||
| it('saves and loads a keybinding config', () => { | ||
| const config = { | ||
| preset: 'claude-code', | ||
| overridesByPreset: { | ||
| 'claude-code': { | ||
| 'app.toggle-sidebar': { key: 'b', modifiers: { cmdOrCtrl: true, shift: true } }, | ||
| }, | ||
| }, | ||
| }; | ||
| saveKeybindings(tmpDir, JSON.stringify(config)); | ||
| const loaded = loadKeybindings(tmpDir); | ||
| expect(loaded).toEqual(config); | ||
| }); | ||
|
|
||
| it('falls back to default on corrupted file', () => { | ||
| fs.writeFileSync(path.join(tmpDir, 'keybindings.json'), 'not json', 'utf8'); | ||
| const result = loadKeybindings(tmpDir); | ||
| expect(result).toEqual({ preset: 'default', overridesByPreset: {} }); | ||
| }); | ||
|
|
||
| it('falls back to backup on corrupted primary', () => { | ||
| const config = { preset: 'claude-code', overridesByPreset: {} }; | ||
| fs.writeFileSync(path.join(tmpDir, 'keybindings.json'), 'corrupted', 'utf8'); | ||
| fs.writeFileSync(path.join(tmpDir, 'keybindings.json.bak'), JSON.stringify(config), 'utf8'); | ||
| const result = loadKeybindings(tmpDir); | ||
| expect(result).toEqual(config); | ||
| }); | ||
|
|
||
| it('accepts legacy flat userOverrides format', () => { | ||
| const legacy = { | ||
| preset: 'claude-code', | ||
| userOverrides: { | ||
| 'app.toggle-sidebar': { key: 'b', modifiers: { cmdOrCtrl: true, shift: true } }, | ||
| }, | ||
| }; | ||
| fs.writeFileSync(path.join(tmpDir, 'keybindings.json'), JSON.stringify(legacy), 'utf8'); | ||
| const loaded = loadKeybindings(tmpDir); | ||
| expect(loaded.preset).toBe('claude-code'); | ||
| expect(loaded.userOverrides).toEqual(legacy.userOverrides); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
|
|
||
| const FILENAME = 'keybindings.json'; | ||
|
|
||
| /** | ||
| * Persisted keybinding config. | ||
| * - `overridesByPreset` is the current shape (per-preset user overrides) | ||
| * - `userOverrides` is the legacy flat shape (still accepted on load) | ||
| */ | ||
| export interface PersistedKeybindings { | ||
| preset: string; | ||
| overridesByPreset?: Record<string, Record<string, unknown>>; | ||
| /** @deprecated use overridesByPreset. Still read for backward compat. */ | ||
| userOverrides?: Record<string, unknown>; | ||
| } | ||
|
|
||
| const DEFAULT_CONFIG: PersistedKeybindings = { | ||
| preset: 'default', | ||
| overridesByPreset: {}, | ||
| }; | ||
|
|
||
| function isValidShape(parsed: unknown): parsed is PersistedKeybindings { | ||
| if (!parsed || typeof parsed !== 'object') return false; | ||
| const obj = parsed as Record<string, unknown>; | ||
| if (typeof obj.preset !== 'string') return false; | ||
| if (obj.overridesByPreset !== undefined && typeof obj.overridesByPreset !== 'object') { | ||
| return false; | ||
| } | ||
| if (obj.userOverrides !== undefined && typeof obj.userOverrides !== 'object') return false; | ||
| return true; | ||
| } | ||
|
|
||
| export function loadKeybindings(dir: string): PersistedKeybindings { | ||
| const filePath = path.join(dir, FILENAME); | ||
| const bakPath = filePath + '.bak'; | ||
|
|
||
| for (const candidate of [filePath, bakPath]) { | ||
| try { | ||
| if (fs.existsSync(candidate)) { | ||
| const content = fs.readFileSync(candidate, 'utf8'); | ||
| if (content.trim()) { | ||
| const parsed: unknown = JSON.parse(content); | ||
| if (isValidShape(parsed)) { | ||
| return parsed; | ||
| } | ||
| } | ||
| } | ||
| } catch { | ||
| // Try next candidate | ||
| } | ||
| } | ||
|
|
||
| return { ...DEFAULT_CONFIG }; | ||
| } | ||
|
|
||
| export function saveKeybindings(dir: string, json: string): void { | ||
| const filePath = path.join(dir, FILENAME); | ||
| fs.mkdirSync(dir, { recursive: true }); | ||
|
|
||
| // Validate JSON before writing | ||
| JSON.parse(json); | ||
|
|
||
| const tmpPath = filePath + '.tmp'; | ||
| try { | ||
| fs.writeFileSync(tmpPath, json, 'utf8'); | ||
|
|
||
| if (fs.existsSync(filePath)) { | ||
| try { | ||
| fs.copyFileSync(filePath, filePath + '.bak'); | ||
| } catch { | ||
| /* ignore */ | ||
| } | ||
| } | ||
|
|
||
| fs.renameSync(tmpPath, filePath); | ||
| } catch (err) { | ||
| try { | ||
| fs.unlinkSync(tmpPath); | ||
| } catch { | ||
| /* ignore */ | ||
| } | ||
| throw err; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.