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(main): the menu stands down while a shortcut recorder is armed
enes22c7836cfb8d
diff --git a/CLAUDE.md b/CLAUDE.mdindex 214dc39bf..610354dd4 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -1623,6 +1623,14 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord meawarning reads that list and cannot derive it — main is not importable from the renderer. Notewhat the pin cannot cover: a HARDCODED intercept (the `Digit0` branch) has no command id, so itswallows its chord app-wide with the recorder reporting no conflict.+ - **Dictation has its own conflict bucket** (`conflictBucket` — `speech.dictation` is never in+ `global`), because it never competes at dispatch: the resolver skips it and its own keyed+ listener claims the chord FIRST **in plain app focus only**, which is precedence, not ambiguity.+ Overlap policy is deliberately asymmetric — the LOAD path PERMITS a shared chord (legacy+ settings.json files contain them and `sanitizeKeybindingOverrides` would otherwise strip the+ user's own binding with the migrated one), while the Settings UI REFUSES to create one+ (`commitCandidate`'s two dictation gates, both keyed-only — a modifier-only hold chord renders+ as `…:(hold)` and can never match a keyed identity).- **The terminal-first stand-down is `policyStandsDown(policy, terminalFocused)`, and both halvesare refusals.** `settings.terminalShortcutPolicy` (`app-first` default, Settings → KeyboardShortcuts, read everywhere through `normalizeTerminalShortcutPolicy` because it is@@ -1632,7 +1640,11 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord mea`menuItemIdsToSuspend` — Minimize, Toggle Kanban Board (⌘⇧B) and Settings (⌘,) everywhere, plusClose off-mac, with **Reload deliberately excluded** (see **Window chrome**): not calling`preventDefault` alone would hand ⌘M straight to `{role:'minimize'}`, which is strictly worse- than having no policy.+ than having no policy. **The MENU's state is the composed+ `menuStandsDown(shortcutRecording, policy, terminalFocused)`** — an armed shortcut recorder+ suspends the same items, so ⌘M / ⌘⇧B / ⌘, / off-mac Ctrl+W reach the recorder instead of the+ menu item that owns them; `menuStandsDown(false, …)` is `policyStandsDown(…)` by construction.+ The two INTERCEPT thunks stay independent parameters — only the menu ORs them.- **`terminalFocused` is a MIRROR, and its fail-safe direction is `false` = not focused =intercepts ON.** `renderer/lib/terminalFocusMirror.ts` reports focus changes to main and ischange-deduped (it never re-asserts), so a page that died mid-report, a reload, or a window that@@ -1927,19 +1939,26 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord measubmenu's standard `{role:'cut'|'copy'|'paste'|'selectAll'|…}` items behave differently — Chromiumroutes them into the focused element, so ⌘C in a terminal or a text field does the ordinary thingand does not need stealing. Ask which kind an item is before reasoning from this bullet.- That difference is also why the **terminal-first stand-down has a menu leg**: while a terminal- owns the keys under `terminal-first`, `syncMenuForStandDown` disables the command-style items+ That difference is also why the **stand-down has a menu leg**: while a terminal+ owns the keys under `terminal-first` **or while a shortcut recorder is armed**+ (`menuStandsDown(shortcutRecording, policy, terminalFocused)`), `syncMenuForStandDown` disables+ the command-style itemsnamed in `menuItemIdsToSuspend` — Minimize (`MENU_ITEM_ID_MINIMIZE`), **Toggle Kanban Board(`MENU_ITEM_ID_KANBAN`, ⌘⇧B)** and **Settings (`MENU_ITEM_ID_SETTINGS`, ⌘,)** on every platform,plus Close (`MENU_ITEM_ID_CLOSE`) on Windows/Linux — because a disabled item suppresses its- accelerator and only then do those chords fall through to the terminal. Kanban and Settings are+ accelerator and only then do those chords fall through to the terminal, or to the recorder. The+ recorder leg is why ⌘M is bindable at all, and it fixed a live misfire: ⌘⇧B pressed into an armed+ recorder used to open the kanban board behind the Settings dialog, and ⌘, to re-open Settings.+ Kanban and Settings arethe ones a reader gets wrong: they are **not** intercepted chords at all but ordinary registrycommands (`view.kanbanToggle` / `app.settings`), so the renderer's dispatcher could never standthem down itself — under app-first the menu takes them before the keydown exists, which is alsowhy their capture NOTICE is raised at the IPC receivers in `Canvas.tsx` rather than by thedispatcher. **Reload (⌘R / ⌘⇧R) is the named exception and stays live while stood down**: it isthe crash-recovery lever (a wedged renderer is exactly when it is needed) and a main-frame- navigation is one of the three sites that reset `terminalFocused` / `shortcutRecording`.+ navigation is one of the three sites that reset `terminalFocused` / `shortcutRecording`. It is+ therefore also the one chord a shortcut recorder can never capture, which is what the Keyboard+ Shortcuts section's description now says.`keydown-intercept.test.ts` pins both the stolen chords and the suspended item ids (includingthat the list does not silently grow) — `getMenuItemById` answers `null` for a typo and thefail-safe is to do nothing, which is indistinguishable from the feature working.diff --git a/src/main/index.ts b/src/main/index.tsindex 75326063f..33262da70 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -95,6 +95,7 @@ import {MENU_ITEM_ID_SETTINGS,installKeydownIntercepts,menuItemIdsToSuspend,+ menuStandsDown,navigationClearsRecording,policyStandsDown,resolveInterceptBindings,@@ -630,9 +631,11 @@ function buildAppMenu(win: BrowserWindow): void {{ label: 'View', submenu: viewSubmenu },{label: 'Window',- // `id` on minimize: `syncMenuForStandDown` disables it while the intercepts are stood- // down, so ⌘M falls through to the terminal instead of minimizing the window. mac has no- // `{role:'close'}` here at all — which is why the intercept is ⌘W's only handler on mac.+ // `id` on minimize: `syncMenuForStandDown` disables it while EITHER stand-down is in+ // effect — a terminal focused under terminal-first, or an armed shortcut recorder — so+ // ⌘M falls through to the terminal, or to the recorder, instead of minimizing the+ // window. mac has no `{role:'close'}` here at all — which is why the intercept is ⌘W's+ // only handler on mac.submenu: [{ role: 'minimize', id: MENU_ITEM_ID_MINIMIZE },{ role: 'zoom' },@@ -679,7 +682,16 @@ function buildAppMenu(win: BrowserWindow): void {}/**- * Enable/disable the menu items whose ACCELERATORS would otherwise beat the intercept stand-down.+ * Enable/disable the menu items whose ACCELERATORS would otherwise beat a stand-down.+ *+ * **Two stand-downs share this leg**, composed by `menuStandsDown(shortcutRecording, policy,+ * terminalFocused)`: the terminal-first policy (below) and an armed Settings shortcut RECORDER.+ * The recorder needs it for the same structural reason and a different destination — a menu+ * accelerator is handled above the page, so while it was armed ⌘M minimized the window, ⌘⇧B opened+ * the kanban board behind the dialog and ⌘, re-opened Settings, none of them recordable. With the+ * items suspended those chords reach the recorder. **Reload is still not among them** (see below),+ * so ⌘R / ⌘⇧R remain unrecordable by design. The two INTERCEPT thunks stay independent parameters+ * on `installKeydownIntercepts`; only this single `enabled` boolean ORs them.** `installKeydownIntercepts` standing down means only that main stops calling `preventDefault` —* the key then reaches the page, and if the page ignores it, the MENU, which is handled above the@@ -697,33 +709,38 @@ function buildAppMenu(win: BrowserWindow): void {* never sees them and could not stand them down itself. **Reload (⌘R / ⌘⇧R) is the named* exception** and stays live while stood down; see `menuItemIdsToSuspend`'s comment for why.*- * Called from every place the stood-down answer can change — the `ui:terminal-focus` receiver, the- * policy recompute in `settingsStore.onChange`, `clearRendererKeyState`, and the end of- * `buildAppMenu` (a rebuild resets `enabled`). NEVER per keystroke: this is a menu mutation, and- * `before-input-event` is the one path in the app where work is measured in keystrokes.+ * Called from every place the composed answer can change — the `ui:terminal-focus` receiver, the+ * `ui:shortcut-recording` receiver (the recorder arms and disarms once per chord the user records),+ * the policy recompute in `settingsStore.onChange`, `clearRendererKeyState` (which clears BOTH+ * bits), and the end of `buildAppMenu` (a rebuild resets `enabled`). NEVER per keystroke: this is a+ * menu mutation, and `before-input-event` is the one path in the app where work is measured in+ * keystrokes.** FAIL-SAFE: a missing menu, or an item id that no longer resolves, does nothing at all. That* leaves the pre-feature behaviour (menu enabled, intercepts deciding), which is the direction* where the app still works — the cost is that a silent id drift is invisible, which is why both* sides of the lookup use the same exported constants rather than string literals.*- * KNOWN COST, deliberate: while a terminal is focused under terminal-first, every suspended item —- * Window ▸ Minimize, View ▸ Toggle Kanban Board, Settings, and off-mac Window ▸ Close — is greyed- * out to the MOUSE as well. They re-enable the moment focus leaves the terminal (and the+ * KNOWN COST, deliberate: while either stand-down holds, every suspended item — Window ▸ Minimize,+ * View ▸ Toggle Kanban Board, Settings, and off-mac Window ▸ Close — is greyed out to the MOUSE as+ * well. They re-enable the moment focus leaves the terminal, or the recorder disarms (and the* traffic-light button is unaffected), so this is a visible but self-healing trade. The alternative* — rebuilding the whole menu without those accelerators on every focus change — costs a menu- * rebuild per click between the canvas and a terminal, and closes any menu the user has open.+ * rebuild per click between the canvas and a terminal, and closes any menu the user has open. For+ * the recorder the trade is smaller still: the greyed items sit behind a modal dialog the user+ * opened to record a chord, and the alternative was four chords they could not bind at all.** UNTESTED, and here is why: this is Electron menu mutation reached through the module-level* `Menu` singleton inside `src/main/index.ts`, which no test imports (the same gap the intercept* WIRING has — see `keydown-intercept.ts`'s header on why the decision lives in a pure module).- * The two testable parts were extracted: `policyStandsDown` (the state) and `menuItemIdsToSuspend`- * (the list, including the mac/non-mac asymmetry), both pinned in `keydown-intercept.test.ts`.+ * The testable parts were extracted: `menuStandsDown` (the composed state) over `policyStandsDown`+ * (the policy half) and `menuItemIdsToSuspend` (the list, including the mac/non-mac asymmetry), all+ * pinned in `keydown-intercept.test.ts`.*/function syncMenuForStandDown(): void {const menu = Menu.getApplicationMenu()if (!menu) return- const enabled = !policyStandsDown(currentInterceptPolicy(), terminalFocused)+ const enabled = !menuStandsDown(shortcutRecording, currentInterceptPolicy(), terminalFocused)for (const id of menuItemIdsToSuspend(interceptIsMac)) {const item = menu.getMenuItemById(id)if (item) item.enabled = enabled@@ -1115,6 +1132,13 @@ app.whenReady().then(async () => {ipcMain.on(IPC.uiShortcutRecording, (event, active: boolean) => {if (getMainWindow()?.webContents.id !== event.sender.id) returnshortcutRecording = active === true+ // The menu leg follows recording too (`menuStandsDown`), so an arm/disarm owes a sync — that is+ // what lets ⌘M, ⌘⇧B, ⌘, and off-mac Ctrl+W reach the recorder instead of the menu item that+ // owns them. A recorder arms and disarms once per chord the user records, which is the right+ // cadence for a menu mutation; NEVER per keystroke (same rule as the focus mirror below). It+ // must be INSIDE the guard for the same reason as there: a rejected sender must not move the+ // menu either.+ syncMenuForStandDown()})// The terminal-focus mirror, under the SAME sender guard and for a sharper version of the samediff --git a/src/main/keydown-intercept.test.ts b/src/main/keydown-intercept.test.tsindex 4b37e0cd2..a5cdfc94b 100644--- a/src/main/keydown-intercept.test.ts+++ b/src/main/keydown-intercept.test.ts@@ -9,6 +9,7 @@ import {installKeydownIntercepts,keydownIntercept,menuItemIdsToSuspend,+ menuStandsDown,navigationClearsRecording,policyStandsDown,resolveInterceptBindings,@@ -576,3 +577,45 @@ describe('policyStandsDown', () => {}})})++/**+ * The MENU leg's composed state — what `index.ts`'s `syncMenuForStandDown` asks. The INTERCEPT+ * thunks stay two independent parameters (the describe above pins that); only the menu ORs them,+ * because a menu item is enabled or it is not and both reasons want the same items suspended.+ *+ * Why recording joined at all: a menu accelerator is handled above the page, so while a recorder+ * was armed ⌘M minimized the window, ⌘⇧B opened the kanban board and ⌘, opened Settings instead of+ * being recorded. Suspending the items is what lets the chord reach the recorder.+ */+describe('menuStandsDown', () => {+ it('recording alone suspends the menu leg, under either policy', () => {+ expect(menuStandsDown(true, 'app-first', false)).toBe(true)+ expect(menuStandsDown(true, 'terminal-first', false)).toBe(true)+ })+ it('without recording it is exactly the policy stand-down', () => {+ expect(menuStandsDown(false, 'terminal-first', true)).toBe(true)+ expect(menuStandsDown(false, 'terminal-first', false)).toBe(false)+ expect(menuStandsDown(false, 'app-first', true)).toBe(false)+ })++ // The behaviour contract of this change, stated as a test: with no recorder armed the menu leg+ // is BYTE-IDENTICAL to what it was before recording was composed in, so a user who never opens+ // the Settings recorder sees exactly the previous app.+ it('is exactly policyStandsDown over the whole non-recording matrix', () => {+ for (const policy of ['app-first', 'terminal-first'] as const) {+ for (const focused of [true, false]) {+ expect(menuStandsDown(false, policy, focused)).toBe(policyStandsDown(policy, focused))+ }+ }+ })++ // Recording is the ALWAYS suspension (see `installKeydownIntercepts`): it does not consult the+ // mirror, so a recorder armed with no terminal focused still gets its chords.+ it('recording ignores the focus mirror entirely', () => {+ for (const policy of ['app-first', 'terminal-first'] as const) {+ for (const focused of [true, false]) {+ expect(menuStandsDown(true, policy, focused)).toBe(true)+ }+ }+ })+})diff --git a/src/main/keydown-intercept.ts b/src/main/keydown-intercept.tsindex 4e11c3156..08a6f0ede 100644--- a/src/main/keydown-intercept.ts+++ b/src/main/keydown-intercept.ts@@ -224,6 +224,26 @@ export function policyStandsDown(return policy === 'terminal-first' && terminalFocused}+/**+ * PURE. The MENU leg's composed stand-down state: `index.ts`'s `syncMenuForStandDown` disables+ * `menuItemIdsToSuspend` for exactly as long as this is true.+ *+ * **The menu ORs the two suspensions; the INTERCEPTS do not.** `installKeydownIntercepts` keeps+ * `isRecording` and `isStoodDown` as separate parameters on purpose (unrelated reasons, unrelated+ * schedules — see its doc), and that stays. But a menu item is enabled or it is not: both reasons+ * want the same items suspended, and one boolean is the honest shape for a single `enabled` write.+ *+ * `menuStandsDown(false, …)` is `policyStandsDown(…)` by construction, which is the byte-identical+ * guarantee for every user who never arms the Settings recorder.+ */+export function menuStandsDown(+ recording: boolean,+ policy: TerminalShortcutPolicy,+ terminalFocused: boolean+): boolean {+ return recording || policyStandsDown(policy, terminalFocused)+}+/*** Menu item ids `buildAppMenu` stamps on the items whose ACCELERATORS survive an intercept* stand-down. Exported constants used by both sides — the template that sets them and the sync that@@ -252,10 +272,14 @@ export const MENU_ITEM_ID_SETTINGS = 'app-settings'* nothing matches) → xterm → the PTY. That is what completes "under terminal-first everything* reaches the shell", ⌘M included.*- * **This is NOT the recording stand-down's story** — keep the two apart. Recording is a transient,- * user-initiated arming of a dialog, and its ⌘M limitation (documented on `installKeydownIntercepts`)- * stands: nothing here re-enables recording those chords, because a recorder that silently disabled- * Minimize for the duration of a keypress is a different and worse trade.+ * **The list serves BOTH stand-downs** — the policy one above and an armed shortcut recorder+ * (`menuStandsDown` composes them; `syncMenuForStandDown` disables these items for either). The+ * earlier argument here was that a recorder greying out Minimize was a worse trade than an+ * unrecordable ⌘M; that trade REVERSED once the menu leg existed for the policy anyway. The cost is+ * now a momentary grey-out while a modal recorder is armed — self-healing the instant it disarms —+ * and the benefit is four chords that could not be bound at all: ⌘M everywhere, off-mac Ctrl+W, and+ * ⌘⇧B / ⌘, which did not merely fail to record but FIRED — pressing ⌘⇧B into the recorder opened+ * the kanban board behind the Settings dialog, and ⌘, re-opened Settings.** mac carries no CLOSE id: the mac template has no `{role:'close'}` at all (Window ▸ Minimize /* Zoom / Front), which is exactly why `keydownIntercept` is ⌘W's only handler there. Kanban and@@ -321,18 +345,17 @@ export interface KeydownInterceptTarget {* not forwarding would still hand the recorder nothing — and forwarding is the live bug, since ⌘W* pressed into the recorder deletes the canvas's selected nodes.*- * **What this stand-down does NOT buy, and cannot.** It only stops US from taking the key; it has- * no say over the application MENU, whose accelerators are handled above the page either way. So- * every menu accelerator is unrecordable while this stands down — including **⌘M**, which- * `{role:'minimize'}` owns on every platform, **⌘⇧B** and **⌘,** (View ▸ Toggle Kanban Board and- * Settings, also every platform), and **Ctrl+W** on Windows/Linux, where the Window submenu has a- * `{role:'close'}`. Pressing one of those into an armed recorder minimizes/closes the window, opens- * the board or opens Settings instead of recording. Concretely, the stand-down fully delivers- * **⌘0** everywhere and- * **⌘W on macOS** (neither is in the menu), and cannot deliver ⌘M anywhere. Fixing that means- * suspending the MENU while recording (`Menu.setApplicationMenu(null)` around the armed window, or- * per-item `enabled:false`) — a change to `buildAppMenu`, not to this module. Known limitation;- * see the PR body.+ * **What this stand-down buys on its own, and what the MENU leg adds.** This half only stops US+ * from taking the key; it has no say over the application MENU, whose accelerators are handled+ * above the page either way — so by itself it delivers **⌘0** everywhere and **⌘W on macOS**+ * (neither is in the menu) and nothing else. **The menu now follows recording too**:+ * `index.ts`'s `syncMenuForStandDown` asks `menuStandsDown(recording, policy, terminalFocused)`+ * and disables every item in `menuItemIdsToSuspend` while a recorder is armed, so the suspended+ * items' chords — **⌘M** (`{role:'minimize'}`, every platform), **⌘⇧B** and **⌘,** (View ▸ Toggle+ * Kanban Board and Settings, every platform) and **Ctrl+W** on Windows/Linux — reach the recorder+ * instead of minimizing the window, opening the board or opening Settings. **RELOAD (⌘R / ⌘⇧R)+ * stays unrecordable by design**: it is the app's crash-recovery lever and is deliberately absent+ * from that list (see `menuItemIdsToSuspend`).** `isStoodDown` is the SECOND suspension and the same shape again, but a different fact:* `policyStandsDown(policy, terminalFocused)` — the user chose `terminal-first` AND an xterm@@ -343,18 +366,19 @@ export interface KeydownInterceptTarget {* assert. Both are checked BEFORE `preventDefault` for the same reason: a claimed chord never* reaches the page at all, and the page is exactly who terminal-first stands down FOR.*- * **The policy stand-down DOES get the menu leg the recording one does not** — the two cases are- * different and the paragraph above stays true for recording. `index.ts`'s `syncMenuForStandDown`- * disables every item in `menuItemIdsToSuspend` below — `{role:'minimize'}`, Toggle Kanban Board- * and Settings on all platforms, plus off-mac `{role:'close'}`, with RELOAD deliberately left out —- * for exactly as long as `isStoodDown` is true. It has to: not calling- * `preventDefault` hands the key to the page and, failing that, to the menu, so without the menu- * leg a terminal-first user's ⌘M would minimize the window and their Ctrl+W — readline's kill-word- * — would CLOSE it on Windows/Linux, which is strictly worse than not having the policy. With the- * items disabled the chord completes the trip it was promised: page → the renderer's dispatcher- * (terminal context, terminal-first, nothing matches) → xterm → the PTY. Recording keeps the- * limitation because a recorder that greyed out Minimize for the duration of a keypress is a worse- * trade than an unrecordable ⌘M.+ * **The menu leg is SHARED by the two suspensions, on the same item list.** `index.ts`'s+ * `syncMenuForStandDown` disables every item in `menuItemIdsToSuspend` below —+ * `{role:'minimize'}`, Toggle Kanban Board and Settings on all platforms, plus off-mac+ * `{role:'close'}`, with RELOAD deliberately left out — for exactly as long as+ * `menuStandsDown(recording, policy, terminalFocused)` is true. The policy half has to have it:+ * not calling `preventDefault` hands the key to the page and, failing that, to the menu, so+ * without the menu leg a terminal-first user's ⌘M would minimize the window and their Ctrl+W —+ * readline's kill-word — would CLOSE it on Windows/Linux, which is strictly worse than not having+ * the policy. With the items disabled the chord completes the trip it was promised: page → the+ * renderer's dispatcher (terminal context, terminal-first, nothing matches) → xterm → the PTY.+ * The recording half rides the same list for a different destination: page → the armed recorder.+ * That the ITEM list is shared does not merge the two INTERCEPT thunks — they stay independent+ * parameters below, and only the menu's single `enabled` boolean composes them.** **The stand-down leg cannot be more reliable than the mirror behind it**, and the mirror is a* renderer reporting over fire-and-forget IPC. Every uncertainty therefore resolves to NOT stooddiff --git a/src/renderer/components/settings/sections/ShortcutsSection.tsx b/src/renderer/components/settings/sections/ShortcutsSection.tsxindex e0760b3ce..e12d36cec 100644--- a/src/renderer/components/settings/sections/ShortcutsSection.tsx+++ b/src/renderer/components/settings/sections/ShortcutsSection.tsx@@ -281,11 +281,12 @@ export function ShortcutsSection({ isActive }: { isActive: boolean }): React.JSX<SettingsSectionid="shortcuts"title="Keyboard Shortcuts"- // 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."+ // The one remaining limitation is the application MENU's, not macOS's: its accelerators are+ // handled above the page on every platform. While a recorder is armed main now suspends the+ // items in `menuItemIdsToSuspend` (Minimize, Toggle Kanban Board, Settings, off-mac Close),+ // so those chords reach the recorder — but RELOAD is deliberately never suspended, because it+ // is the crash-recovery lever. 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. Reload (⌘R / ⌘⇧R) cannot be recorded — it always stays with the app."isActive={isActive}searchEntries={entries}>