The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): carry forward keybind overrides written after boot
teknium1f8a9d4d6a4d8
diff --git a/apps/desktop/src/store/keybinds.test.ts b/apps/desktop/src/store/keybinds.test.tsindex cbc30313783..12d785ac38a 100644--- a/apps/desktop/src/store/keybinds.test.ts+++ b/apps/desktop/src/store/keybinds.test.ts@@ -6,7 +6,17 @@ function storedDiff(): Record<string, string[]> {return JSON.parse(window.localStorage.getItem(STORAGE_KEY) ?? '{}')}-describe('keybinds store boot persist', () => {+const DEMO_CONTRIBUTION = {+ data: { id: 'demo.late', label: 'Demo', run: () => undefined },+ id: 'demo:late',+ plugin: 'demo'+}++// #116331: the writer (`persistBindings`) diffs over the action universe at+// call time, while the reader keeps unknown ids verbatim for plugins that+// register late. A persist that runs while a contributed action is not (yet /+// any more) registered must not wipe its stored override.+describe('keybinds store persist vs late-registered contributed actions', () => {beforeEach(() => {window.localStorage.clear()vi.resetModules()@@ -17,22 +27,35 @@ describe('keybinds store boot persist', () => {// registered yet at boot, so the id is unknown to `allKeybindActions()`.window.localStorage.setItem(STORAGE_KEY, JSON.stringify({ 'demo.late': ['mod+alt+l'] }))- await import('./keybinds')+ const { bindingsFor } = await import('./keybinds')// The boot-time subscribe persist must carry the unknown id forward// instead of overwriting storage with only the registered actions.expect(storedDiff()).toEqual({ 'demo.late': ['mod+alt+l'] })++ // Once the plugin registers, the saved rebind resolves for its action.+ const { registry } = await import('@/contrib/registry')+ const { KEYBINDS_AREA } = await import('@/lib/keybinds/actions')+ registry.register({ area: KEYBINDS_AREA, ...DEMO_CONTRIBUTION })+ expect(bindingsFor('demo.late')).toEqual(['mod+alt+l'])})- it('keeps unregistered overrides when the user rebinds a built-in', async () => {- window.localStorage.setItem(STORAGE_KEY, JSON.stringify({ 'demo.late': ['mod+alt+l'] }))+ it('keeps an override written after boot when the plugin unloads and another action is rebound', async () => {+ const { bindingsFor, setBinding } = await import('./keybinds')+ const { registry } = await import('@/contrib/registry')+ const { KEYBINDS_AREA } = await import('@/lib/keybinds/actions')++ const unload = registry.register({ area: KEYBINDS_AREA, ...DEMO_CONTRIBUTION })+ setBinding('demo.late', ['mod+alt+l'])+ expect(storedDiff()).toEqual({ 'demo.late': ['mod+alt+l'] })- const { setBinding } = await import('./keybinds')+ unload()setBinding('session.new', ['mod+shift+n'])expect(storedDiff()).toEqual({'demo.late': ['mod+alt+l'],- 'session.new': ['mod+shift+n'],+ 'session.new': ['mod+shift+n']})+ expect(bindingsFor('demo.late')).toEqual(['mod+alt+l'])})})diff --git a/apps/desktop/src/store/keybinds.ts b/apps/desktop/src/store/keybinds.tsindex 4706ce04e66..4baede8b288 100644--- a/apps/desktop/src/store/keybinds.ts+++ b/apps/desktop/src/store/keybinds.ts@@ -67,8 +67,11 @@ function persistBindings(bindings: KeybindBindings): void {// Actions contributed after boot (plugins register late) are missing// from the registry when the boot-time subscribe fires. Carry their- // stored overrides forward so the persist does not wipe them.- for (const [id, combos] of Object.entries(storedOverrides)) {+ // stored overrides forward so the persist does not wipe them. Re-read+ // storage rather than the module-init snapshot: an override written after+ // boot (plugin registered → rebound → unloaded) is otherwise invisible here+ // and the next persist of any other action drops it.+ for (const [id, combos] of Object.entries(readStoredOverrides())) {if (!(id in defaults)) {diff[id] = combos}