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.

fix(keybindings): close the final review's menu-leg and notice gaps

enes9b23c774f0d9
diff --git a/CLAUDE.md b/CLAUDE.md
index 707933322..214dc39bf 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -1628,9 +1628,11 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord mea
Shortcuts, read everywhere through `normalizeTerminalShortcutPolicy` because it is
hand-editable) never stands anything down under `app-first`, whatever the mirror reports — that
is the byte-identical guarantee for a user who never touched it. Under `terminal-first` with a
- focused terminal, main stops claiming its chords AND disables the menu's Minimize/Close items
- (see **Window chrome**): not calling `preventDefault` alone would hand ⌘M straight to
- `{role:'minimize'}`, which is strictly worse than having no policy.
+ focused terminal, main stops claiming its chords AND disables the command-style menu items in
+ `menuItemIdsToSuspend` — Minimize, Toggle Kanban Board (⌘⇧B) and Settings (⌘,) everywhere, plus
+ Close 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.
- **`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 is
change-deduped (it never re-asserts), so a page that died mid-report, a reload, or a window that
@@ -1918,15 +1920,29 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord mea
Cmd+W (`app:close-node`) and Cmd+0 (`app:zoom-actual-size`) are taken back the same way. **The
application menu is OURS**: `buildAppMenu` (`main/index.ts`) calls `Menu.setApplicationMenu` and
re-runs on every settings change. (This bullet used to claim we never call it — false since that
- function landed; check the template, not Electron's defaults.) Menu accelerators are handled
- ABOVE the page on every platform, so a chord one of them owns never reaches the renderer at all —
- which is why those three are stolen in `before-input-event`, and why the **terminal-first
- stand-down has a menu leg**: while a terminal owns the keys under `terminal-first`,
- `syncMenuForStandDown` disables the menu's Minimize (`MENU_ITEM_ID_MINIMIZE`, every platform)
- and, on Windows/Linux, Close (`MENU_ITEM_ID_CLOSE`), because a disabled item suppresses its
- accelerator and only then do ⌘M / Ctrl+W fall through to the terminal. `keydown-intercept.test.ts`
- pins both the stolen chords and those item ids — `getMenuItemById` answers `null` for a typo and
- the fail-safe is to do nothing, which is indistinguishable from the feature working.
+ function landed; check the template, not Electron's defaults.) **COMMAND-style accelerators are
+ handled ABOVE the page on every platform** — Minimize, Close, Toggle Kanban Board, Settings,
+ Reload — so a chord one of those owns never reaches the renderer, which is why those three are
+ stolen in `before-input-event`. **This is not a blanket claim about the whole menu:** the Edit
+ submenu's standard `{role:'cut'|'copy'|'paste'|'selectAll'|…}` items behave differently — Chromium
+ routes them into the focused element, so ⌘C in a terminal or a text field does the ordinary thing
+ and 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
+ named 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
+ the ones a reader gets wrong: they are **not** intercepted chords at all but ordinary registry
+ commands (`view.kanbanToggle` / `app.settings`), so the renderer's dispatcher could never stand
+ them down itself — under app-first the menu takes them before the keydown exists, which is also
+ why their capture NOTICE is raised at the IPC receivers in `Canvas.tsx` rather than by the
+ dispatcher. **Reload (⌘R / ⌘⇧R) is the named exception and stays live while stood down**: it is
+ the 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`.
+ `keydown-intercept.test.ts` pins both the stolen chords and the suspended item ids (including
+ that the list does not silently grow) — `getMenuItemById` answers `null` for a typo and the
+ fail-safe is to do nothing, which is indistinguishable from the feature working.
- **Theme**: macOS dark palette as CSS tokens in `styles.css` `:root` (`--accent` = systemBlue,
label/separator opacities, SF font stack). Canvas background is black with dot grid.
diff --git a/src/main/index.ts b/src/main/index.ts
index c027c51e4..be7e09513 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -90,7 +90,9 @@ import {
import { setMainWindow, getMainWindow, sendToMain, closeAction, createCrashReloadPolicy } from './main-window'
import {
MENU_ITEM_ID_CLOSE,
+ MENU_ITEM_ID_KANBAN,
MENU_ITEM_ID_MINIMIZE,
+ MENU_ITEM_ID_SETTINGS,
installKeydownIntercepts,
menuItemIdsToSuspend,
navigationClearsRecording,
@@ -304,6 +306,11 @@ const currentInterceptBindings = (): KeydownInterceptBindings =>
// `onChange`, never per keystroke. Normalized through the shared helper so an unknown value from a
// hand-edited settings.json reads as the default `app-first` — i.e. as "keep intercepting", which
// is the direction that leaves the app working.
+// FIRST-READ STALENESS IS BENIGN, and the ordering is what makes it so: `settingsStore.init()` runs
+// in `whenReady` well before `createWindow` → `buildAppMenu`, whose trailing `syncMenuForStandDown`
+// is the earliest possible read of this memo — so the value it latches is already the user's saved
+// policy, never DEFAULT_SETTINGS, and every later change arrives on `onChange`. The memo can
+// therefore only ever hold what settings.json says.
let interceptPolicy: TerminalShortcutPolicy | null = null
const currentInterceptPolicy = (): TerminalShortcutPolicy =>
(interceptPolicy ??= normalizeTerminalShortcutPolicy(settingsStore.get().terminalShortcutPolicy))
@@ -529,7 +536,13 @@ function buildAppMenu(win: BrowserWindow): void {
const send = (channel: string): void => {
if (!win.isDestroyed()) win.webContents.send(channel)
}
+ // ONE object, placed into BOTH templates below (mac's app menu, off-mac's own `Settings` menu),
+ // so `MENU_ITEM_ID_SETTINGS` resolves on every platform — which is why `menuItemIdsToSuspend`
+ // lists it unconditionally. ⌘, is an ordinary registry command (`app.settings`), not an
+ // intercepted chord: the menu just takes it above the page, and disabling this item under the
+ // stand-down is the only way it can reach a focused terminal.
const settingsItem: Electron.MenuItemConstructorOptions = {
+ id: MENU_ITEM_ID_SETTINGS,
label: isMac ? 'Settings…' : 'Settings',
accelerator: 'CmdOrCtrl+,',
click: () => send(IPC.appOpenSettings)
@@ -543,6 +556,12 @@ function buildAppMenu(win: BrowserWindow): void {
// so a reload only re-hydrates the canvas from the workspace store — it never drops a session
// (same path the crash-reload policy uses). No interceptor claims ⌘R, so the accelerator is
// honest (unlike ⌘0, which `installKeydownIntercepts` owns for zoom-to-100%).
+ //
+ // These two carry NO id and are the NAMED EXCEPTION to the stand-down (see
+ // `menuItemIdsToSuspend`): ⌘R / ⌘⇧R keep working over a focused terminal under terminal-first,
+ // because a renderer wedged badly enough to stop dispatching keys is exactly when the user
+ // needs the lever — and the reload is also what resets `terminalFocused` / `shortcutRecording`
+ // in main. Do not "complete" the suspend list with them.
{ role: 'reload' },
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
@@ -562,6 +581,11 @@ function buildAppMenu(win: BrowserWindow): void {
click: () => send(IPC.appFitView)
},
{
+ // `viewSubmenu` goes into BOTH templates, so this id resolves on every platform (the same
+ // reason `menuItemIdsToSuspend` lists it unconditionally). ⌘⇧B is a registry command
+ // (`view.kanbanToggle`) the menu happens to own above the page; suspending the item is what
+ // lets a terminal-first user's ⌘⇧B reach the shell like every other chord.
+ id: MENU_ITEM_ID_KANBAN,
label: 'Toggle Kanban Board',
accelerator: 'CmdOrCtrl+Shift+B',
click: () => send(IPC.appToggleKanban)
@@ -666,6 +690,12 @@ function buildAppMenu(win: BrowserWindow): void {
* nothing matches) → xterm → the PTY. That is what makes "everything reaches the shell" true for
* ⌘M and Ctrl+W too, not just for ⌘0 and mac's ⌘W.
*
+ * The list is `menuItemIdsToSuspend` and it also carries **Toggle Kanban Board (⌘⇧B)** and
+ * **Settings (⌘,)** on every platform. Those two are not intercepted chords at all — they are
+ * ordinary registry commands the menu simply takes above the page, which is why the dispatcher
+ * 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
@@ -676,8 +706,9 @@ function buildAppMenu(win: BrowserWindow): void {
* 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, Window ▸ Minimize is
- * greyed out to the MOUSE as well. It re-enables the moment focus leaves the terminal (and the
+ * 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
* 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.
diff --git a/src/main/keydown-intercept.test.ts b/src/main/keydown-intercept.test.ts
index 64de4c3e7..4b37e0cd2 100644
--- a/src/main/keydown-intercept.test.ts
+++ b/src/main/keydown-intercept.test.ts
@@ -3,7 +3,9 @@ import { IPC } from '../shared/ipc'
import { MAIN_INTERCEPTED_COMMAND_IDS } from '../shared/keybindings'
import {
MENU_ITEM_ID_CLOSE,
+ MENU_ITEM_ID_KANBAN,
MENU_ITEM_ID_MINIMIZE,
+ MENU_ITEM_ID_SETTINGS,
installKeydownIntercepts,
keydownIntercept,
menuItemIdsToSuspend,
@@ -491,12 +493,45 @@ describe('terminal-first stands every interception down while a terminal is focu
* menu items for exactly as long as the intercepts are stood down, and this list is which ones.
*/
describe('menuItemIdsToSuspend', () => {
- it('is minimize everywhere and, off-mac, close as well', () => {
+ it('suspends minimize, kanban and settings everywhere, and close only off-mac', () => {
// The mac template has no `{role:'close'}` at all (Window ▸ Minimize / Zoom / Front), which is
// exactly why `keydownIntercept` is ⌘W's only handler there. Listing a close id on mac would
// be a no-op today and a silent lie the day someone adds the role.
- expect(menuItemIdsToSuspend(true)).toEqual([MENU_ITEM_ID_MINIMIZE])
- expect(menuItemIdsToSuspend(false)).toEqual([MENU_ITEM_ID_MINIMIZE, MENU_ITEM_ID_CLOSE])
+ //
+ // Kanban and Settings, by contrast, ARE on both templates — `buildAppMenu` builds one
+ // `viewSubmenu` array and one `settingsItem` object and puts each into the mac and the
+ // Windows/Linux template — so an asymmetry for them would be the lie instead.
+ expect(menuItemIdsToSuspend(true)).toEqual([
+ MENU_ITEM_ID_MINIMIZE,
+ MENU_ITEM_ID_KANBAN,
+ MENU_ITEM_ID_SETTINGS
+ ])
+ expect(menuItemIdsToSuspend(false)).toEqual([
+ MENU_ITEM_ID_MINIMIZE,
+ MENU_ITEM_ID_KANBAN,
+ MENU_ITEM_ID_SETTINGS,
+ MENU_ITEM_ID_CLOSE
+ ])
+ })
+
+ // ⌘⇧B and ⌘, are ordinary registry commands, not intercepted chords — the menu simply takes them
+ // above the page, so under terminal-first they were the two chords that did NOT reach the shell.
+ // Membership is the whole fix, which is why it is pinned per-id rather than only by the arrays.
+ it('carries the two menu-owned registry chords on both platforms', () => {
+ for (const isMac of [true, false]) {
+ expect(menuItemIdsToSuspend(isMac)).toContain(MENU_ITEM_ID_KANBAN)
+ expect(menuItemIdsToSuspend(isMac)).toContain(MENU_ITEM_ID_SETTINGS)
+ }
+ })
+
+ // The named exception. `{role:'reload'}` / `{role:'forceReload'}` keep their accelerators while
+ // stood down ON PURPOSE: a wedged renderer is exactly when ⌘R is needed, and a main-frame
+ // navigation is one of the three sites that reset `terminalFocused` / `shortcutRecording`. There
+ // is no id to assert the absence of, so this pins the LENGTH — a fourth/fifth entry appearing
+ // here (a reload id being the likely one) reds this test and sends the author to the comment.
+ it('does not grow silently — reload is deliberately not suspended', () => {
+ expect(menuItemIdsToSuspend(true)).toHaveLength(3)
+ expect(menuItemIdsToSuspend(false)).toHaveLength(4)
})
// The ids are the ONLY link between `buildAppMenu`'s template and the sync that disables the
@@ -504,9 +539,14 @@ describe('menuItemIdsToSuspend', () => {
// which looks exactly like the feature working. Both sides import these constants, so the typo
// class cannot happen; this pins that they are distinct and non-empty.
it('the ids are distinct and non-empty', () => {
- expect(MENU_ITEM_ID_MINIMIZE).toBeTruthy()
- expect(MENU_ITEM_ID_CLOSE).toBeTruthy()
- expect(MENU_ITEM_ID_MINIMIZE).not.toBe(MENU_ITEM_ID_CLOSE)
+ const ids = [
+ MENU_ITEM_ID_MINIMIZE,
+ MENU_ITEM_ID_CLOSE,
+ MENU_ITEM_ID_KANBAN,
+ MENU_ITEM_ID_SETTINGS
+ ]
+ for (const id of ids) expect(id).toBeTruthy()
+ expect(new Set(ids).size).toBe(ids.length)
})
})
diff --git a/src/main/keydown-intercept.ts b/src/main/keydown-intercept.ts
index 379ab2336..4e11c3156 100644
--- a/src/main/keydown-intercept.ts
+++ b/src/main/keydown-intercept.ts
@@ -225,13 +225,18 @@ export function policyStandsDown(
}
/**
- * Menu item ids `buildAppMenu` stamps on the two roles whose ACCELERATORS survive an intercept
+ * 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
* looks them up — because `getMenuItemById` answers `null` for a typo and the fail-safe there is to
* do nothing, which is indistinguishable from the feature working.
*/
export const MENU_ITEM_ID_MINIMIZE = 'window-minimize'
export const MENU_ITEM_ID_CLOSE = 'window-close'
+/** View ▸ Toggle Kanban Board (⌘⇧B). In `viewSubmenu`, which BOTH templates include. */
+export const MENU_ITEM_ID_KANBAN = 'view-kanban-toggle'
+/** The Settings item (⌘,) — mac's app menu, off-mac's own `Settings` menu; ONE `settingsItem`
+ * object shared by both templates, so the id exists on every platform. */
+export const MENU_ITEM_ID_SETTINGS = 'app-settings'
/**
* PURE. Which menu items must be disabled while the intercepts are stood down.
@@ -252,13 +257,33 @@ export const MENU_ITEM_ID_CLOSE = 'window-close'
* 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.
*
- * mac carries only minimize: the mac template has no `{role:'close'}` at all (Window ▸ Minimize /
- * Zoom / Front), which is exactly why `keydownIntercept` is ⌘W's only handler there.
+ * 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
+ * Settings are on BOTH platforms — one `viewSubmenu` array and one `settingsItem` object are shared
+ * by the two templates — so they are suspended on both.
+ *
+ * **What suspending kanban/settings actually buys, since neither is an intercepted chord.** ⌘⇧B and
+ * ⌘, are ordinary REGISTRY commands (`view.kanbanToggle` / `app.settings`); the renderer's
+ * dispatcher would resolve them if it ever saw the keydown, but under app-first the MENU takes them
+ * above the page and the dispatcher never runs. Disabling the items removes that theft, so under
+ * terminal-first with a terminal focused the chord reaches the page → the resolver, which REFUSES
+ * it (a terminal context under terminal-first matches only commands flagged `allowInTerminal`, and
+ * that flag is app-first-only) → xterm → the PTY. Without these two ids, terminal-first would
+ * deliver every chord to the shell EXCEPT the two the menu happened to own, which is the same
+ * inconsistency the minimize/close leg exists to remove.
+ *
+ * **RELOAD (⌘R / ⌘⇧R) is deliberately NOT here — named exception, do not "complete" the list.**
+ * `{role:'reload'}` / `{role:'forceReload'}` are the app's crash-recovery lever: a renderer wedged
+ * badly enough to stop dispatching keys is exactly when the user needs them, and a policy that
+ * suspended them would take the lever away precisely in the state that calls for it. The recovery
+ * also depends on the reload actually happening in MAIN — a main-frame navigation is one of the
+ * three sites that reset `terminalFocused`/`shortcutRecording` (see `navigationClearsRecording`),
+ * so suspending reload would strand the very bits a stuck page leaves set. The cost is honest and
+ * small: a terminal-first user's ⌘R reloads the window instead of reaching the shell.
*/
export function menuItemIdsToSuspend(isMac: boolean): string[] {
- return isMac
- ? [MENU_ITEM_ID_MINIMIZE]
- : [MENU_ITEM_ID_MINIMIZE, MENU_ITEM_ID_CLOSE]
+ const shared = [MENU_ITEM_ID_MINIMIZE, MENU_ITEM_ID_KANBAN, MENU_ITEM_ID_SETTINGS]
+ return isMac ? shared : [...shared, MENU_ITEM_ID_CLOSE]
}
/** The renderer channel a claimed action is forwarded on. */
@@ -299,9 +324,11 @@ export interface KeydownInterceptTarget {
* **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, 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 instead of recording. Concretely, the stand-down fully delivers **⌘0** everywhere and
+ * `{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;
@@ -318,8 +345,9 @@ export interface KeydownInterceptTarget {
*
* **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 `{role:'minimize'}` (and, off-mac, `{role:'close'}`) for exactly as long as
- * `isStoodDown` is true, via the ids in `menuItemIdsToSuspend` below. It has to: not calling
+ * 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
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index f413e915d..8b95be13c 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -4001,12 +4001,17 @@ export function Canvas() {
// IPC carries no context. Notice only: nothing is consumed, and the close below runs
// exactly as it did before (`noteTerminalCapture` is silent under terminal-first, on a
// repeat, and outside a focused terminal).
- if (isTerminalTarget(document.activeElement as unknown as ContextElement | null)) {
- noteTerminalCapture('node.close')
- }
const ids = nodesRef.current.filter((n) => n.selected).map((n) => n.id)
- if (ids.length) deleteNodes(ids)
- else window.nodeTerminal.closeWindow()
+ // The notice sits INSIDE the branch that actually captured the key. With nothing selected
+ // ⌘W closes the WINDOW, and a notice raised there would burn this command's once-ever slot
+ // on a banner nobody can read — the window is going away in the same tick — leaving the user
+ // permanently unable to be told why ⌘W stops reaching their shell.
+ if (ids.length) {
+ if (isTerminalTarget(document.activeElement as unknown as ContextElement | null)) {
+ noteTerminalCapture('node.close')
+ }
+ deleteNodes(ids)
+ } else window.nodeTerminal.closeWindow()
})
}, [deleteNodes])
@@ -4033,8 +4038,18 @@ export function Canvas() {
useEffect(() => {
return window.nodeTerminal.onFitView(() => fitAll())
}, [fitAll])
+ // ⌘⇧B and ⌘, are the other two chords the dispatcher can never notice — not because main steals
+ // them (it does not; they are ordinary registry commands) but because the MENU owns their
+ // accelerators above the page under app-first, so the window keydown listener never runs and its
+ // notice half never fires. Like the two receivers above, the notice is raised HERE and asks the
+ // live focus, since the IPC carries no context. Notice ONLY: nothing is consumed, the toggle and
+ // the settings open run exactly as before, and `noteTerminalCapture` is silent under
+ // terminal-first, on a repeat, and outside a focused terminal.
useEffect(() => {
return window.nodeTerminal.onToggleKanban(() => {
+ if (isTerminalTarget(document.activeElement as unknown as ContextElement | null)) {
+ noteTerminalCapture('view.kanbanToggle')
+ }
const id = useProjects.getState().activeProjectId
if (id) useViewMode.getState().toggle(id)
})
@@ -4043,6 +4058,9 @@ export function Canvas() {
// Cmd+, keydown handler alone would leave the menu item inert — main forwards it as IPC.
useEffect(() => {
return window.nodeTerminal.onOpenSettings(() => {
+ if (isTerminalTarget(document.activeElement as unknown as ContextElement | null)) {
+ noteTerminalCapture('app.settings')
+ }
setSettingsSection(undefined)
setSettingsOpen(true)
})
diff --git a/src/renderer/components/ShortcutCaptureBanner.test.tsx b/src/renderer/components/ShortcutCaptureBanner.test.tsx
new file mode 100644
index 000000000..649f54d18
--- /dev/null
+++ b/src/renderer/components/ShortcutCaptureBanner.test.tsx
@@ -0,0 +1,196 @@
+// @vitest-environment jsdom
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import type { CommandId } from '@shared/keybindings'
+import { DEFAULT_SETTINGS } from '@shared/types'
+import { useSettings } from '../state/settings'
+import { ShortcutCaptureBanner } from './ShortcutCaptureBanner'
+
+/**
+ * The banner is the only surface that ever SHOWS a capture notice, and until now nothing pressed
+ * it — `keybindingOverrides.test.ts` runs in the node environment and can assert only the settings
+ * half (the once-ever ledger, the terminal-first silence). Everything below is the other half: the
+ * `window` event → visible strip → dismissal path, which is where a queue-less design, a restarted
+ * clock and two `null` copy cases all live.
+ *
+ * FAKE TIMERS, and the coupling documented in `terminalFocusMirror.test.ts` applies here too:
+ * `vi.useFakeTimers()` does NOT fake microtasks in this repo's configuration, so React's own
+ * flushing still happens naturally inside `act` — advance the CLOCK with
+ * `vi.advanceTimersByTime` and let `act` settle the render. Never try to "advance" a microtask.
+ * The 12s auto-dismiss is a `setTimeout` in an effect, so every advance has to be wrapped in
+ * `act` or the resulting `setCurrent(null)` never reaches the DOM being asserted on.
+ */
+
+;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
+
+// jsdom reports a non-mac platform, and the body quotes a PLATFORM-FORMATTED chord ('⌘K' vs
+// 'Ctrl+K'). Pin macOS so the assertions name one spelling — `isMacPlatform()` is read at call
+// time, never captured at module load.
+Object.defineProperty(window.navigator, 'platform', { value: 'MacIntel', configurable: true })
+
+/** Must be a FRESH `keybindings` object every time: `activeKeybindingOverrides` memoizes on that
+ * object's identity, so mutating one in place would serve the previous sanitize. */
+const setKb = (kb: Record<string, readonly string[]> | undefined): void =>
+ useSettings.setState({ settings: { ...DEFAULT_SETTINGS, keybindings: kb as never } })
+
+const onOpenShortcuts = vi.fn()
+let host: HTMLDivElement
+let root: Root | null = null
+
+function render(): void {
+ host = document.createElement('div')
+ document.body.appendChild(host)
+ root = createRoot(host)
+ act(() => root!.render(<ShortcutCaptureBanner onOpenShortcuts={onOpenShortcuts} />))
+}
+
+/** What `noteTerminalCapture` dispatches. Raised directly here: the DECISION to raise it is
+ * already pinned in `keybindingOverrides.test.ts`, and this file is about what happens after. */
+function capture(commandId: string): void {
+ act(() =>
+ window.dispatchEvent(
+ new CustomEvent('nodeterm:shortcut-captured', { detail: { commandId: commandId as CommandId } })
+ )
+ )
+}
+
+const tick = (ms: number): void => {
+ act(() => {
+ vi.advanceTimersByTime(ms)
+ })
+}
+
+const banner = (): HTMLElement | null => host.querySelector<HTMLElement>('.announce-banner')
+const title = (): string | undefined =>
+ host.querySelector<HTMLElement>('.announce-banner__title')?.textContent ?? undefined
+const body = (): string | undefined =>
+ host.querySelector<HTMLElement>('.announce-banner__body')?.textContent ?? undefined
+const btn = (label: string): HTMLButtonElement =>
+ [...host.querySelectorAll('button')].find((b) => b.textContent === label) as HTMLButtonElement
+const click = (el: HTMLElement): void => {
+ act(() => el.dispatchEvent(new MouseEvent('click', { bubbles: true })))
+}
+
+beforeEach(() => {
+ vi.useFakeTimers()
+ onOpenShortcuts.mockClear()
+ setKb(undefined)
+})
+
+afterEach(() => {
+ if (root) {
+ const r = root
+ root = null
+ act(() => r.unmount())
+ host.remove()
+ }
+ vi.useRealTimers()
+})
+
+describe('ShortcutCaptureBanner', () => {
+ it('renders nothing until a capture arrives', () => {
+ render()
+ expect(banner()).toBeNull()
+ })
+
+ it('a bound command renders its title and a body quoting the chord in force', () => {
+ render()
+ capture('app.commandPalette')
+ expect(banner()).not.toBeNull()
+ expect(title()).toBe('Command palette')
+ // The chord is read through `chipFor`, so this is the EFFECTIVE binding, not the registry
+ // default — the remap case below is the same assertion with an override in place.
+ expect(body()).toContain('⌘K')
+ expect(body()).toContain('Command palette')
+ expect(body()).toContain('terminal-first')
+ })
+
+ it('quotes the user’s own chord after a remap, never the registry default', () => {
+ setKb({ 'app.commandPalette': ['Cmd+Alt+P'] })
+ render()
+ capture('app.commandPalette')
+ expect(body()).toContain('⌘⌥P')
+ expect(body()).not.toContain('⌘K')
+ })
+
+ it('a second capture REPLACES the first and restarts the 12s clock', () => {
+ render()
+ capture('app.commandPalette')
+ tick(8_000)
+ expect(title()).toBe('Command palette')
+
+ capture('app.settings')
+ // Replaced, not queued: the first notice is gone the instant the second arrives.
+ expect(title()).toBe('Open settings')
+ expect(body()).toContain('⌘,')
+
+ // 8s past the FIRST capture's deadline (16s in) — a clock that had been inherited rather than
+ // restarted would have dismissed the strip here.
+ tick(8_000)
+ expect(title()).toBe('Open settings')
+ // …and the second one's own 12s still lands.
+ tick(4_000)
+ expect(banner()).toBeNull()
+ })
+
+ it('auto-dismisses at 12s, and not a tick before', () => {
+ render()
+ capture('app.commandPalette')
+ tick(11_999)
+ expect(banner()).not.toBeNull()
+ tick(1)
+ expect(banner()).toBeNull()
+ })
+
+ it('Open Shortcuts calls the prop AND clears the strip', () => {
+ render()
+ capture('app.commandPalette')
+ click(btn('Open Shortcuts'))
+ expect(onOpenShortcuts).toHaveBeenCalledTimes(1)
+ // Both halves matter: opening the settings page behind a strip that stays up would leave the
+ // user reading a notice about the very screen they are now looking at.
+ expect(banner()).toBeNull()
+ })
+
+ it('the ✕ dismisses without opening Settings', () => {
+ render()
+ capture('app.commandPalette')
+ click(btn('✕'))
+ expect(banner()).toBeNull()
+ expect(onOpenShortcuts).not.toHaveBeenCalled()
+ })
+
+ it('an id the registry does not know renders nothing', () => {
+ render()
+ // The id arrives inside a `CustomEvent.detail` off `window`, so its `CommandId` type is a
+ // compile-time claim and nothing more — a stale or forged one must be silence, not a hole.
+ capture('app.notACommand')
+ expect(banner()).toBeNull()
+ })
+
+ it('a DISABLED (unbound) command renders nothing — the sentence is built around its chord', () => {
+ setKb({ 'app.commandPalette': [] })
+ render()
+ capture('app.commandPalette')
+ expect(banner()).toBeNull()
+ })
+
+ it('a malformed event with no commandId renders nothing', () => {
+ render()
+ act(() => window.dispatchEvent(new CustomEvent('nodeterm:shortcut-captured')))
+ expect(banner()).toBeNull()
+ })
+
+ it('stops listening once unmounted', () => {
+ render()
+ const r = root!
+ root = null
+ act(() => r.unmount())
+ // No throw, no state update on a dead root — the subscription is torn down in the effect's
+ // cleanup, and a leaked one would surface here as a React warning about an unmounted update.
+ capture('app.commandPalette')
+ expect(host.querySelector('.announce-banner')).toBeNull()
+ host.remove()
+ })
+})
diff --git a/src/renderer/components/settings/sections/ShortcutsSection.tsx b/src/renderer/components/settings/sections/ShortcutsSection.tsx
index 537013a90..fae14991a 100644
--- a/src/renderer/components/settings/sections/ShortcutsSection.tsx
+++ b/src/renderer/components/settings/sections/ShortcutsSection.tsx
@@ -68,7 +68,7 @@ const NOTES: Partial<Record<CommandId, string>> = {
* knows about commands) decide whether a *setting* is on screen. */
const POLICY_LABEL = 'While a terminal has focus'
const POLICY_DESCRIPTION =
- "App shortcuts first (the default): shared shortcuts like ⌘K keep working over a focused terminal, and the first time one is captured that way the terminal says so — once per chord, ever. Terminal first: every chord but the terminal's own reaches the shell or TUI, including Close (⌘W / Ctrl+W), Minimize (⌘M / Ctrl+M), actual size (⌘0) and the ⌘1–9 project jumps — the application menu's Minimize and Close entries grey out while a terminal is focused, so those chords can reach it."
+ "App shortcuts first (the default): shared shortcuts like ⌘K keep working over a focused terminal, and the first time one is captured that way the terminal says so — once per chord, ever. Terminal first: every chord but the terminal's own reaches the shell or TUI, including Close (⌘W / Ctrl+W), Minimize (⌘M / Ctrl+M), actual size (⌘0), the kanban board (⌘⇧B), Settings (⌘,) and the ⌘1–9 project jumps — the matching application-menu entries grey out while a terminal is focused, so those chords can reach it. Reload (⌘R / ⌘⇧R) is the one exception and always stays with the app, so a stuck window can still be recovered."
const POLICY_ROW: SettingsSearchEntry = {
title: POLICY_LABEL,
description: POLICY_DESCRIPTION,
diff --git a/src/renderer/lib/keybindingOverrides.test.ts b/src/renderer/lib/keybindingOverrides.test.ts
index c2ea47fea..531446bc4 100644
--- a/src/renderer/lib/keybindingOverrides.test.ts
+++ b/src/renderer/lib/keybindingOverrides.test.ts
@@ -127,9 +127,16 @@ describe('setKeybindingOverride', () => {
})
})
-// NODE ENV, deliberately: this file runs without jsdom (see the note on noteTerminalCapture),
-// so only the SETTINGS side is asserted here. The 'nodeterm:shortcut-captured' event is
-// window-guarded and its dispatch is covered by the banner's jsdom test.
+// NODE ENV, deliberately: this file runs without jsdom (see the note on noteTerminalCapture), so
+// only the SETTINGS side is asserted here — WHETHER a notice is raised (the policy gate, the
+// once-ever ledger), never what it looks like.
+//
+// The other side is `components/ShortcutCaptureBanner.test.tsx` (jsdom): it dispatches
+// 'nodeterm:shortcut-captured' ITSELF and asserts what the banner does with it — copy, replacement,
+// the 12s clock, dismissal, and the two silent cases (unknown id, unbound command). Be precise
+// about the seam: nothing presses `noteTerminalCapture`'s own `window.dispatchEvent` line, which is
+// `typeof window` guarded and cannot run here. The two files meet at the event NAME and its
+// `detail.commandId` shape, and that agreement is by convention, not by a test.
describe('terminalShortcutPolicy / noteTerminalCapture', () => {
const seen = () => useSettings.getState().settings.seenShortcutCaptureNotices
const setSettings = (patch: Record<string, unknown>) =>