Skip to content

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.

docs(keybindings): close the final review's honesty gaps + pin the armed-recorder guard

enes9dec2a488054
diff --git a/CLAUDE.md b/CLAUDE.md
index 92d74eaca..9fbc4db33 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -1589,6 +1589,41 @@ disappearing" rather than as an occasional cull. The `vm_stat` reader is what ma
again; the grace window was never the thing that was wrong.
+## Keybindings (registry, overrides, dispatch)
+
+Every user-facing chord is a registry command, and the whole engine is **one module**:
+`src/shared/keybindings.ts` holds the command registry, per-command validation
+(`normalizeBindingForCommand`), effective-binding resolution, conflict detection, override
+sanitization and the pure event→command resolver. **Do not split it** — main, the renderer and the
+Server Edition bridge all import it, and a second copy of any of those five is how the dispatcher,
+the Settings section and ShortcutsPanel start disagreeing about what a chord means.
+
+- **Overrides live in `settings.keybindings`** (hand-editable JSON): an absent id = the registry
+ default, `[]` = **disabled**, a list = exactly those chords. It is **sanitized at READ**
+ (`sanitizeKeybindingOverrides` → `renderer/lib/keybindingOverrides.ts`, memoized on the raw
+ object's identity), which is what makes a hand-edited file safe; the Settings section refuses a
+ bad candidate BEFORE saving (`commitCandidate`) so the user learns which chord was refused
+ instead of watching it vanish on the next launch. The write path is raw and the gates read the
+ sanitized map, so a dropped hand-edit is invisible in the UI but still on disk until a UI write
+ or Reset replaces the map.
+- **Dispatch has exactly two owners.** The renderer's is ONE window `keydown` listener in
+ `Canvas.tsx`, on the **bubble** phase — the Settings recorder's `stopPropagation` on an armed
+ capture depends on that, and moving it to capture would let a recorded chord fire the command it
+ is being bound to. The main process's is `src/main/keydown-intercept.ts`, a **closed allowlist**
+ of chords it must steal back from the application menu before the page ever sees them.
+- **Invariants**
+ - **Never read `settings.speech.shortcut`.** The dictation chord is `dictationBinding()` (the
+ first effective `speech.dictation` binding); the legacy field is a **downgrade mirror only**,
+ written by `setKeybindingOverride` so an older build still finds the user's chord.
+ - **`isHoldChord('')` is TRUE** (an all-false parse has a null key), and `''` is what a DISABLED
+ dictation binding reads as — so every caller owes an explicit `=== ''` check first. Without it
+ a disabled binding arms a modifier-less hold chord that fires on any keydown.
+ - **`MAIN_INTERCEPTED_COMMAND_IDS` must mirror the registry-backed commands `keydown-intercept.ts`
+ actually resolves** (`keydown-intercept.test.ts` pins it). The Settings UI's app-wide shadow
+ warning reads that list and cannot derive it — main is not importable from the renderer. Note
+ what the pin cannot cover: a HARDCODED intercept (the `Digit0` branch) has no command id, so it
+ swallows its chord app-wide with the recorder reporting no conflict.
+
## Canvas interaction & panels (`Canvas.tsx` is the hub)
- **Context menus** (`components/ContextMenu.tsx`, portal, icons from `components/icons.tsx`):
diff --git a/README.md b/README.md
index a66c9388b..9676e6dd3 100644
--- a/README.md
+++ b/README.md
@@ -110,7 +110,7 @@ LAN**. The same canvas also runs self-hosted in any browser (Server Edition).
### Talk to your terminal
-Hold `⌘⇧D` and say it. On-device **Whisper** transcribes locally — review the text,
+Hold `⌘⌥` and say it. On-device **Whisper** transcribes locally — review the text,
then **Send** (nothing auto-submits). Your voice never leaves the machine.
</td>
@@ -132,7 +132,7 @@ GitHub Copilot / opencode / Grok / custom) · 📝 **Sticky note** (link to an a
agent sessions (`claude --resume`). The macOS app **ships its own tmux**, so this works
with nothing installed; a tmux already on your system is always used in preference to it,
and terminals opened before an upgrade stay as they were until you refresh the node.
-- **Talk to your terminal** — on-device Whisper dictation (⌘⇧D): speak, review, send.
+- **Talk to your terminal** — on-device Whisper dictation (hold ⌘⌥): speak, review, send.
- **Agent superpowers** — **context links** so agent nodes read each other's transcripts
on demand; Claude-only **branch a conversation** and **managed accounts** for several
logged-in Claude identities side by side; agents can drive the canvas (open nodes,
@@ -233,6 +233,8 @@ npm run server:dev # build + run the browser Server Edition (needs Node 22 + tmu
## ⌨️ Keyboard shortcuts
+These are the defaults — every one of them is remappable in **Settings → Keyboard Shortcuts**.
+
| Shortcut | Action |
| --- | --- |
| `⌘K` | Command palette |
@@ -241,7 +243,7 @@ npm run server:dev # build + run the browser Server Edition (needs Node 22 + tmu
| `⌘W` | Close the selected node |
| `⌘Z` / `⌘⇧Z` | Undo / Redo |
| `⌘M` | Toggle markdown view (terminal / editor) |
-| `⌘⇧D` | Dictate into the focused terminal |
+| Hold `⌘⌥` (`Ctrl+Alt`) | Dictate into the focused terminal |
| `⌘⇧E` | File explorer |
| `⌘,` | Settings · `⌘/` Shortcuts |
| `Right-click` | Actions menu (empty space or node) |
diff --git a/src/core/settings-store.ts b/src/core/settings-store.ts
index b90e462ca..86135243c 100644
--- a/src/core/settings-store.ts
+++ b/src/core/settings-store.ts
@@ -26,6 +26,12 @@ function mergeSettings(saved: Partial<Settings> | null | undefined): Settings {
// write path keeps it in sync so an older build still finds the user's chord).
// A shortcut EQUAL to the default seeds nothing: the override would only restate what the
// registry already says, and would then pin that chord against any future default change.
+ // **Seeding here is not the same as surviving.** The value written below is a plain override,
+ // so the READ path's sanitizer (`sanitizeKeybindingOverrides`) can still STRIP it: if the
+ // legacy chord collides with another command's effective binding in the same conflict bucket,
+ // every OVERRIDDEN participant of that conflict is deleted — the seed goes, dictation silently
+ // falls back to the registry default chord, and the user's own colliding override is dropped
+ // with it. The only signal is a console warning; nothing surfaces in the UI.
if (
merged.speech.shortcut !== DEFAULT_SETTINGS.speech.shortcut &&
!(merged.keybindings && "speech.dictation" in merged.keybindings)
diff --git a/src/renderer/components/settings/sections/ShortcutsSection.test.tsx b/src/renderer/components/settings/sections/ShortcutsSection.test.tsx
index 0a3223a4a..e591ce07a 100644
--- a/src/renderer/components/settings/sections/ShortcutsSection.test.tsx
+++ b/src/renderer/components/settings/sections/ShortcutsSection.test.tsx
@@ -23,10 +23,9 @@ const kb = (): Record<string, readonly string[]> =>
let host: HTMLDivElement
let root: Root | null = null
-function render(query = ''): void {
- host = document.createElement('div')
- document.body.appendChild(host)
- root = createRoot(host)
+/** Re-render into the SAME root, so component identity survives a query change — which is the
+ * whole point of the armed-recorder test below. */
+function rerender(query: string): void {
act(() =>
root!.render(
<SettingsSearchContext.Provider value={query}>
@@ -36,6 +35,17 @@ function render(query = ''): void {
)
}
+function render(query = ''): void {
+ host = document.createElement('div')
+ document.body.appendChild(host)
+ root = createRoot(host)
+ rerender(query)
+}
+
+const setRecording = (): ReturnType<typeof vi.fn> =>
+ (window as unknown as { nodeTerminal: { shortcuts: { setRecording: ReturnType<typeof vi.fn> } } })
+ .nodeTerminal.shortcuts.setRecording
+
/** The section shell's card body — `divide-y [&>*]:py-5`, so every direct child DRAWS. */
const body = (): Element => host.querySelector<HTMLElement>('#shortcuts')!.lastElementChild!
@@ -163,6 +173,37 @@ describe('ShortcutsSection rows', () => {
expect(dictate.textContent).toContain('Disabled')
expect(dictate.textContent).toContain('hold to talk')
})
+
+ // `ShortcutRecorderButton.release` is guarded by `armedRef`, and this section is where that
+ // guard is actually reachable: every row is a `SearchableRow`, which returns `null` for a row
+ // the query does not match, so typing in the settings search box unmounts a BATCH of recorders
+ // at once. The main-process recording bit is ONE global boolean — an unconditional
+ // `setRecording(false)` in that cleanup would clear the ARMED recorder's bit from under it and
+ // re-arm the ⌘W/⌘M intercepts mid-capture.
+ it('keeps the global recording bit while non-armed sibling recorders unmount', () => {
+ render()
+ click(recorder('terminal.copySelection', 'Record')!)
+ expect(setRecording()).toHaveBeenCalledWith(true)
+
+ // 'tmux' matches only Copy terminal selection (via its note) — every other row unmounts, and
+ // the armed one keeps its identity (stable group/row keys), so it is still armed.
+ rerender('tmux')
+ expect([...host.querySelectorAll('[data-command]')].map((el) =>
+ el.getAttribute('data-command')
+ )).toEqual(['terminal.copySelection'])
+ expect(
+ recorder('terminal.copySelection', 'Press keys…')?.getAttribute('data-shortcut-recording')
+ ).toBe('true')
+ expect(setRecording()).not.toHaveBeenCalledWith(false)
+
+ // …and the armed instance still owes the release on its own unmount (Settings closed
+ // mid-recording fires no blur), exactly once.
+ const r = root!
+ root = null
+ act(() => r.unmount())
+ host.remove()
+ expect(setRecording().mock.calls.filter((c) => c[0] === false)).toHaveLength(1)
+ })
})
describe('commitCandidate', () => {
diff --git a/src/renderer/components/settings/sections/ShortcutsSection.tsx b/src/renderer/components/settings/sections/ShortcutsSection.tsx
index 3879d889f..00a901c4c 100644
--- a/src/renderer/components/settings/sections/ShortcutsSection.tsx
+++ b/src/renderer/components/settings/sections/ShortcutsSection.tsx
@@ -216,7 +216,11 @@ export function ShortcutsSection({ isActive }: { isActive: boolean }): React.JSX
<SettingsSection
id="shortcuts"
title="Keyboard Shortcuts"
- description="Remap any command. Overrides are stored in settings.json under `keybindings`; Disable turns a command's shortcut off, Reset restores its default. macOS owns ⌘M for Window ▸ Minimize, so that one chord cannot be recorded here."
+ // The limitation is the application MENU's, not macOS's: its accelerators are handled above
+ // the page on every platform, so the main-process stand-down cannot deliver them to the
+ // recorder. Minimize is in the menu everywhere; Close only on Windows/Linux (the mac
+ // template has no {role:'close'}) — see `src/main/keydown-intercept.ts`.
+ description="Remap any command. Overrides are stored in settings.json under `keybindings`; Disable turns a command's shortcut off, Reset restores its default. The application menu owns Minimize (⌘M / Ctrl+M) and, on Windows/Linux, Close (Ctrl+W); those chords cannot be recorded here."
isActive={isActive}
searchEntries={entries}
>
diff --git a/src/renderer/components/settings/shortcutRecording.ts b/src/renderer/components/settings/shortcutRecording.ts
index 8a3c498fe..d1a454fd3 100644
--- a/src/renderer/components/settings/shortcutRecording.ts
+++ b/src/renderer/components/settings/shortcutRecording.ts
@@ -3,6 +3,9 @@
* SpeechSection `ShortcutCaptureField` (one hard-wired dictation chord) into a decision function
* any command row can drive, and closes the two gaps that field shipped with.
*
+ * `ShortcutCaptureField` and its `anyModDown` helper were both REMOVED in this series — they are
+ * named below only to record which bug each gap was; there is nothing left in the tree to grep.
+ *
* Two commit shapes, exactly as the v3 chord grammar defines them:
* - A KEYED chord (primary modifier + a non-modifier key) commits IMMEDIATELY on keydown.
* - A HOLD chord (modifier keys only — permitted only when `allowHold`, i.e. the command's
diff --git a/src/renderer/lib/keybindingOverrides.ts b/src/renderer/lib/keybindingOverrides.ts
index 780f8a9f9..a9c7c477f 100644
--- a/src/renderer/lib/keybindingOverrides.ts
+++ b/src/renderer/lib/keybindingOverrides.ts
@@ -62,7 +62,14 @@ export function chipFor(id: CommandId, isMac: boolean = isMacPlatform()): string
* `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. */
+ * of a broken value it cannot parse.
+ *
+ * **Raw in, sanitized out — the two maps are not the same map.** This writes into the RAW
+ * `settings.keybindings` object, while every UI gate (the chips, Disable/Reset visibility,
+ * `commitCandidate`'s conflict check) reads the SANITIZED one. So a hand-edited entry the
+ * sanitizer drops — an unknown id, an invalid chord, a conflict participant — is invisible to
+ * the gate yet still sitting on disk, and it stays there until a UI write for that command, or
+ * a Reset, replaces the map. */
export function setKeybindingOverride(id: CommandId, bindings: readonly string[] | null): void {
const state = useSettings.getState()
const next: KeybindingOverrides = { ...(state.settings.keybindings ?? {}) }