feat(web): add a reset-all button to keybindings settings
Closes #4576
Problem
Keybindings settings can reset a single row to its default, but there is no way to get the whole set back. A user carrying customizations from an older version can end up with conflicting bindings and no recourse short of hand-editing keybindings.json — which is exactly what someone in that state does not want to do, and which the issue calls out directly.
Change
server.resetKeybindingsRPC →Keybindings.resetKeybindingRulesToDefaults, which rewrites the config withDEFAULT_KEYBINDINGS, refreshes the cache, and emits the change event like the existing upsert/remove paths.- Reset button in the Keybindings settings header, beside Add keybinding and Open keybindings.json. It confirms first, since it discards every customization at once.
Two deliberate behaviors, both covered by tests:
- Project script bindings (
script.*) are kept. They have no default to restore, so dropping them would delete shortcuts the reset cannot give back. The confirm dialog says so. - A config that fails to parse is replaced outright instead of erroring. A malformed
keybindings.jsonis the state this button exists to escape, so refusing to overwrite it would defeat the feature.upsertKeybindingRulekeeps its existing refuse-to-overwrite behavior.
Tests
apps/server/src/keybindings.test.ts:
- reset restores the defaults, drops customizations, and keeps the
script.*rule; - reset replaces a malformed config with the defaults.
vp test run src/keybindings.test.ts — 23 passed. (fails when config directory is not writable fails on this Windows host both with and without this change: fs.chmod does not restrict the directory there. Verified against a clean tree.)
Typecheck clean for packages/contracts, packages/client-runtime, apps/server, apps/web; lint and format checked on the changed files.
Verified in the app
Ran the web stack against an isolated --home-dir, planted a customized keybindings.json (remapped sidebar.toggle and terminal.toggle, plus a script.run-tests.run binding), and clicked the button:
- confirm text: "Reset all keybindings to their defaults? / Every customization is discarded. Project script bindings are kept."
- on disk afterwards: the non-script rules are byte-identical to
DEFAULT_KEYBINDINGS, the remapped shortcuts are gone, andscript.run-tests.runsurvives; - the table updates live, 42 bindings (41 defaults + the script rule).
Not included
The issue also floats migrations for defaults that change upstream. That is a separate mechanism and is not part of this change; the startup sync still backfills newly added defaults as it did before.
🤖 Generated with Claude Code
[!NOTE] Medium Risk Bulk-writes user keybinding config and overwrites malformed files on reset; behavior is intentional but can surprise users who relied on a broken on-disk file.
Overview Adds reset all keybindings to defaults end-to-end: a new
server.resetKeybindingsRPC (orchestration operate scope) wired through contracts, client-runtime, and the Keybindings settings header.Server-side
resetKeybindingRulesToDefaultsrewriteskeybindings.jsonwithDEFAULT_KEYBINDINGS, keepsscript.*rules, updates cache, and broadcasts changes like upsert/remove. Malformed configs are replaced on reset (unlike upsert, which still refuses to overwrite). Unreadable configs fail without writing. If script rules exceed the cap after reset, defaults are never dropped—oldest script entries are trimmed and a warning is logged.The settings UI adds a Reset all to defaults control with confirmation (notes that script bindings stay), guards against environment changes while the dialog is open, and surfaces errors via toasts.
Tests cover happy path, malformed replacement, read failure, and max-count script truncation.
Reviewed by Cursor Bugbot for commit 1e832d8a8a4eeea3c4f6ab127f8c02eac13063e4. Bugbot is set up for automated code reviews on this repo. Configure here.
[!NOTE]
Add a reset-all button to keybindings settings
- Adds a "Reset All" toolbar button in KeybindingsSettings.tsx that prompts for confirmation before resetting keybindings to defaults.
- Implements
resetKeybindingRulesToDefaultsin keybindings.ts: writes defaults plus any existing script bindings, updates the in-memory cache, and broadcasts a change event.- Exposes a new
server.resetKeybindingsWebSocket RPC in ws.ts, gated by orchestration operate scope.- Script bindings are preserved up to
MAX_KEYBINDINGS_COUNT; excess script rules are dropped (trailing rules survive) with a warning logged.- Risk: malformed keybinding configs are silently overwritten on reset; configs that cannot be read (e.g. a directory at the path) return a failure instead.
Macroscope summarized 1e832d8.
[!IMPORTANT]
Review skipped
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
41c0b958-619c-43ee-883f-08614f876524You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- [ ] 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Approvability
Verdict: Needs human review
This PR introduces a new user-facing feature (reset-all keybindings button) with a new RPC endpoint, backend logic, and UI components. New features introducing user-facing behavior warrant human review even when well-tested and self-contained.
You can customize Macroscope's approvability policy. Learn more.
All three findings were correct. Fixed in 90f7248d4.
Effect.result swallowed filesystem errors (flagged by both bots) — the worst of the three. loadWritableCustomKeybindingsConfig fails for fs.exists, fs.readFileString, and parse errors, and I collapsed all of them to []. A transient read error would have written defaults over a config whose script.* bindings were still on disk — the exact data loss the preserve logic exists to prevent.
The reset now goes through loadRuntimeCustomKeybindingsConfig, which already draws that line correctly: an unparseable config yields an empty rule set (with issues), while a read failure propagates. So a malformed config is still replaced — that is the point of the button — but an unreadable one aborts the reset instead of overwriting it.
The max-count cap dropped defaults, not scripts — slice(-MAX) keeps the tail, so with enough script bindings the reset would fail to restore the defaults it exists to restore. Now the preserved scripts are truncated to MAX_KEYBINDINGS_COUNT - DEFAULT_KEYBINDINGS.length and the drop is logged.
Stale environment id across the confirm dialog — the handler captured primaryEnvironment.environmentId at render and awaited a native modal before sending. It now re-checks the current primary environment after the dialog resolves and bails if it changed.
Two tests added:
refuses to reset a keybindings config it cannot read— a directory at the config path makes the read fail the way a transient filesystem error would; the reset fails and the path is untouched.keeps every default when preserved script bindings exceed the max count— 220 script rules in, all 41 defaults still present and the file capped at 256.
vp test run src/keybindings.test.ts — 25 passed. (fails when config directory is not writable still fails on this Windows host with and without the change; fs.chmod does not restrict directories there.) Typecheck, lint, and format clean for apps/server and apps/web.
Both follow-up findings were correct. Fixed in 327f00c1c.
Script truncation dropped the wrong end. I capped with slice(0, budget), keeping the earliest scripts — but later rules have higher precedence everywhere else in this file (mergeWithDefaultKeybindings and syncDefaultKeybindingsOnStartup both keep the tail, and say so). So the cap could discard the script bindings actually in effect and keep the ones they shadow. Now drops from the front.
The existing cap test passed either way, which is why it did not catch this. It now asserts the surviving scripts are exactly the trailing ones, so the direction is pinned.
Silent abort after confirm. The environment guard I added in the previous round returned without feedback, so a user who confirmed a reset that then did not run had no way to tell. It now toasts "Keybindings were not reset — the active environment changed while the confirmation was open."
vp test run src/keybindings.test.ts — 25 passed, same single pre-existing Windows failure (fails when config directory is not writable; fs.chmod does not restrict directories on this host, and it fails identically on a clean tree). Typecheck, lint, and format clean for apps/server and apps/web.