From edc0ecdd5fc36a91b27859e5f546936c1efce30e Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 19:03:20 +0000 Subject: [PATCH 1/9] =?UTF-8?q?Keyboard=20control=20wave=203:=20=E2=8C=98/?= =?UTF-8?q?=20key=20list,=20fuller=20menu=20bar,=20focus=20after=20onboard?= =?UTF-8?q?ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ⌘/ (and Help → Keyboard Shortcuts) opens a searchable list of every key as set in Settings plus the built-in keys; Settings → Keyboard shortcuts lists the built-in keys too. The new ⌘/ default yields to a saved shortcut. - The menu bar gains View, Go and Chat menus and Help → Keyboard Shortcuts. These items show the current key without taking it from the page, and grey out while the app can't run them (the renderer reports what it can run). On macOS a menu key the page already saw is dropped. - When first-run setup finishes, the message box takes focus, including a Bot's chat opened from setup. - docs/keyboard.md and README. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_018VA6RFnvTu7rNwP4JpjJMZ --- README.md | 2 +- docs/keyboard.md | 25 ++- main/index.ts | 27 ++- main/services/application-menu-core.test.ts | 79 ++++++++- main/services/application-menu-core.ts | 81 ++++++++- .../native-menu-command-contract.test.ts | 14 +- package.json | 2 +- .../keyboard-shortcuts-dialog.test.tsx | 167 ++++++++++++++++++ .../components/keyboard-shortcuts-dialog.tsx | 137 ++++++++++++++ renderer/components/onboarding-flow.tsx | 3 + .../components/settings/shortcut-settings.tsx | 44 ++++- .../lib/assistant-motion-contract.test.ts | 2 +- renderer/lib/command-system-core.test.ts | 25 +++ renderer/lib/command-system-core.ts | 20 +++ renderer/lib/command-system.tsx | 50 +++++- renderer/lib/focus-regions.test.tsx | 65 ++++++- renderer/lib/focus-regions.ts | 28 ++- renderer/lib/ipc.ts | 3 + renderer/lib/shortcut-sheet.test.ts | 69 ++++++++ renderer/lib/shortcut-sheet.ts | 122 +++++++++++++ renderer/main/root-view.tsx | 2 + renderer/shared/built-in-keys.ts | 105 +++++++++++ renderer/shared/keybindings.ts | 16 ++ scripts/ci-test-registry.json | 2 + tests/e2e/bots-starter.spec.ts | 2 + tests/e2e/chat-shell-interactions.spec.ts | 42 +++++ 26 files changed, 1112 insertions(+), 22 deletions(-) create mode 100644 renderer/components/keyboard-shortcuts-dialog.test.tsx create mode 100644 renderer/components/keyboard-shortcuts-dialog.tsx create mode 100644 renderer/lib/shortcut-sheet.test.ts create mode 100644 renderer/lib/shortcut-sheet.ts create mode 100644 renderer/shared/built-in-keys.ts diff --git a/README.md b/README.md index ccafffd290..8c40621140 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ I don't come from a coding background. I'd been bouncing between the coding agen ## Features - **Aiden Live (Beta)** - use the blue orb for an explicitly started voice session with visible listening, thinking, speaking, approval, and error states. First use walks through model access, microphone, and Screen & Accessibility permissions once; computer actions and scheduled tasks retain Aiden's existing approval boundaries. -- **Command palette and shortcuts** - `⌘K` searches commands, chats, models, providers, Settings, appearance actions, Bots, places, workspace tools, and the open chat's actions. Back/forward, stop, attach, model, and approval keys, `F6` between areas, arrow keys in the sidebar, `⌘F` find in chat, `↑` to fix and resend your last message, and `⇧F10` row menus keep everyday work keyboard-only; see [docs/keyboard.md](docs/keyboard.md). One typed command system also powers native menus, visible shortcut labels, transactional global hotkeys, and the searchable Keyboard Shortcuts editor. +- **Command palette and shortcuts** - `⌘K` searches commands, chats, models, providers, Settings, appearance actions, Bots, places, workspace tools, and the open chat's actions. Back/forward, stop, attach, model, and approval keys, `F6` between areas, arrow keys in the sidebar, `⌘F` find in chat, `↑` to fix and resend your last message, and `⇧F10` row menus keep everyday work keyboard-only; `⌘/` lists every key, and the View, Go and Chat menus show them too; see [docs/keyboard.md](docs/keyboard.md). One typed command system also powers native menus, visible shortcut labels, transactional global hotkeys, and the searchable Keyboard Shortcuts editor. - **Commands and explicit skills** - type `/` at the start of the composer to search Aiden app commands, or `$` to search the active workspace's available skills. Commands reuse canonical app workflows; an explicitly selected skill is revalidated for the active workspace, applies to one accepted message, and persists only safe display provenance. - **Native Subagents** - a foreground chat can delegate up to four fresh `scout`, `planner`, `reviewer`, or `implementer` tasks. Children inherit the approved workspace and model, stop with the parent, and appear as a collapsible group in the transcript plus an inspectable **Subagents** view in Environment. While any child works, a pill above the composer (`⌘⇧S` opens its tray of runs, with Stop, Show in chat and the Subagents panel) and a count badge in the chat's top bar keep them visible even with every panel closed. The implementer can edit files and run commands within the parent permission ceiling. diff --git a/docs/keyboard.md b/docs/keyboard.md index 560d989cd3..ea6e868c8b 100644 --- a/docs/keyboard.md +++ b/docs/keyboard.md @@ -5,7 +5,8 @@ the keys that exist today. Keys are shown with Mac symbols; on Linux and Windows, `⌘` is `Ctrl`, `⌥` is `Alt` and `⇧` is `Shift`. Every key in the tables below, except the fixed keys (the approval keys, `/`, -`F6`, the arrow keys and `↑` in the message box), lives in the +`F6`, the arrow keys and `↑` in the message box, listed in +`renderer/shared/built-in-keys.ts` and under **Built-in keys** in Settings), lives in the one command catalog (`renderer/shared/keybindings.ts`), so it can be changed or turned off in **Settings → Keyboard shortcuts**, and the native menus and button tooltips show the current choice. Keys added in a later release never take a shortcut @@ -17,6 +18,7 @@ one starts unassigned. | Key | Does | | --- | --- | | `⌘K` | Command palette: commands, chats, models, providers, Settings, appearance, Bots | +| `⌘/` | Keyboard shortcuts: every key as set in Settings plus the built-in ones, searchable | | `⌘N` / `⇧⌘N` | New chat / New chat in… | | `⇧⌘F` | Search chats | | `⌘1`–`⌘9` | Open the chat with that number (hold `⌘` to see the numbers); on the Bots page, the Bot on that row | @@ -84,6 +86,27 @@ approval appears, screen readers announce it. In the Browser panel, `⌘.` starts page markup instead of stopping the reply, but only while focus is inside the browser. +## Keyboard list and menu bar + +`⌘/` (or **Help → Keyboard Shortcuts**) opens a searchable list of every key, +grouped as General, Moving around, In a chat and Workspace. It shows the keys +as set in Settings, leaves out commands with no key, and includes the built-in +keys with when each one applies. **Change keys…** opens Settings → Keyboard +shortcuts, which lists the same built-in keys under **Built-in keys**, below +the ones you can change. `⌘/` also works from the message box. + +The menu bar has **View** (sidebar, terminal, Environment, the Focus commands), +**Go** (back, forward, previous and next chat, Search chats, Bots, Scheduled, +Profile), **Chat** (model, attach, find, stop and the open chat's actions) and +**Help → Keyboard Shortcuts**, next to File, Edit and Window. Each item shows +its current key, and items that can't run right now (no chat open, nothing to +stop) are greyed out. These items only show their key: the key itself still +follows the rules on this page (for example, it doesn't act while you type in +the terminal). On Linux, `Alt` opens the menu bar. + +When first-run setup finishes, the message box has focus, so you can start +typing straight away. + ## From ⌘K Besides the keyed commands above, the palette lists commands with no default diff --git a/main/index.ts b/main/index.ts index e6efd992c6..6d302f9dcd 100644 --- a/main/index.ts +++ b/main/index.ts @@ -81,7 +81,7 @@ import { effectiveBindings, migrateLegacyKeybindings, } from "../renderer/shared/keybindings.js"; -import { applicationMenuTemplate } from "./services/application-menu-core.js"; +import { applicationMenuTemplate, parseMenuCommandIds } from "./services/application-menu-core.js"; import type { NotificationChannel } from "../renderer/preload-channels.js"; import type { AppSettings, Chat } from "./services/types.js"; import { ONBOARDING_COMPLETE_STORAGE_KEY } from "../renderer/shared/onboarding.js"; @@ -1685,10 +1685,27 @@ registerAppPathOpener(async (path) => { await deliverMainWindowNotification("app:navigate", { path }); }); +// The last settings the menu was built from, and the commands the renderer +// reports it can run now, so the menu can be rebuilt when either changes. +let applicationMenuInputs: { settings: AppSettings; acceleratorsEnabled: boolean } | null = null; +let applicationMenuAvailable: ReadonlySet | null = null; + +ipcMain.handle("app:setMenuCommands", (event, commandIds: unknown) => { + if (!mainWindow || mainWindow.isDestroyed() || event.sender.id !== mainWindow.webContents.id) return false; + const next = parseMenuCommandIds(commandIds); + if (!next) return false; + const current = applicationMenuAvailable; + if (current && current.size === next.size && [...next].every((id) => current.has(id))) return true; + applicationMenuAvailable = next; + if (applicationMenuInputs) setupApplicationMenu(applicationMenuInputs.settings, applicationMenuInputs.acceleratorsEnabled); + return true; +}); + function setupApplicationMenu( settings: AppSettings, acceleratorsEnabled = true, ): void { + applicationMenuInputs = { settings, acceleratorsEnabled }; if (!acceleratorsEnabled) { Menu.setApplicationMenu(null); return; @@ -1701,10 +1718,14 @@ function setupApplicationMenu( platform: process.platform, appName: app.getName(), bindings, + available: applicationMenuAvailable, actions: { checkForUpdates: () => void appUpdateService.checkNow(true), - deliverCommand: (commandId) => - deliverMainWindowNotificationSafely("app:command", { commandId }), + deliverCommand: (commandId, viaKey) => + deliverMainWindowNotificationSafely("app:command", { + commandId, + source: viaKey ? "menu-key" : "menu", + }), reload: (ignoreCache) => { if (mainWindow && !mainWindow.isDestroyed()) { void requestWindowReload(mainWindow, { ignoreCache }); diff --git a/main/services/application-menu-core.test.ts b/main/services/application-menu-core.test.ts index 5b2919bf07..45d14200ec 100644 --- a/main/services/application-menu-core.test.ts +++ b/main/services/application-menu-core.test.ts @@ -1,8 +1,10 @@ import assert from "node:assert/strict"; import test from "node:test"; +import type { MenuItemConstructorOptions } from "electron"; import { applicationMenuTemplate, + parseMenuCommandIds, platformMenuAccelerator, } from "./application-menu-core.js"; @@ -39,7 +41,7 @@ test("Linux menu uses conventional File and Help ownership", () => { }); assert.deepEqual( menu.map((item) => item.label ?? item.role), - ["File", "editMenu", "View", "windowMenu", "Help"], + ["File", "editMenu", "View", "Go", "Chat", "windowMenu", "Help"], ); const serialized = JSON.stringify(menu); assert.equal(serialized.includes("Check for Updates"), false); @@ -54,3 +56,78 @@ test("Linux native menus translate canonical Command bindings to Ctrl", () => { assert.equal(platformMenuAccelerator("Command+Shift+N", "darwin"), "Command+Shift+N"); assert.equal(platformMenuAccelerator(null, "linux"), undefined); }); + +function submenu(menu: MenuItemConstructorOptions[], name: string): MenuItemConstructorOptions[] { + const item = menu.find((entry) => entry.label === name || entry.role === name); + assert.ok(item && Array.isArray(item.submenu), `${name} menu`); + return item.submenu; +} + +function item(items: MenuItemConstructorOptions[], label: string): MenuItemConstructorOptions { + const found = items.find((entry) => entry.label === label); + assert.ok(found, label); + return found; +} + +test("macOS gets View, Go and Chat menus, and Help lists Keyboard Shortcuts", () => { + const menu = applicationMenuTemplate({ + platform: "darwin", + appName: "Aiden Agent", + bindings: { "shortcuts.show": "Command+/", "sidebar.toggle": "Command+B", "chat.find": "Command+F" }, + actions, + }); + assert.deepEqual( + menu.map((entry) => entry.label ?? entry.role), + ["Aiden Agent", "File", "editMenu", "View", "Go", "Chat", "windowMenu", "help"], + ); + assert.equal(item(submenu(menu, "help"), "Keyboard Shortcuts").accelerator, "Command+/"); + assert.equal(item(submenu(menu, "View"), "Toggle Sidebar").accelerator, "Command+B"); + assert.equal(item(submenu(menu, "Chat"), "Find in Chat").accelerator, "Command+F"); + assert.ok(item(submenu(menu, "Go"), "Back")); +}); + +test("menu items for in-app keys show the key as set, without taking it from the page", () => { + const delivered: Array<[string, boolean | undefined]> = []; + const menu = applicationMenuTemplate({ + platform: "linux", + appName: "Aiden Agent", + // A key someone changed in Settings, and one they turned off. + bindings: { "chat.find": "Command+Shift+G", "chat.stop": null }, + actions: { ...actions, deliverCommand: (commandId, viaKey) => delivered.push([commandId, viaKey]) }, + }); + const chat = submenu(menu, "Chat"); + const find = item(chat, "Find in Chat"); + assert.equal(find.accelerator, "CommandOrControl+Shift+G"); + assert.equal(find.registerAccelerator, false, "the page keeps the key"); + assert.equal(item(chat, "Stop Reply").accelerator, undefined); + // A click runs the command; the item's own key comes back marked, for the page to drop. + find.click?.({} as never, undefined, { triggeredByAccelerator: false } as never); + find.click?.({} as never, undefined, { triggeredByAccelerator: true } as never); + assert.deepEqual(delivered, [ + ["chat.find", false], + ["chat.find", true], + ]); +}); + +test("menu items grey out while the app can't run them, once it has said what it can run", () => { + const build = (available: ReadonlySet | null) => + applicationMenuTemplate({ platform: "darwin", appName: "Aiden Agent", bindings: {}, actions, available }); + const before = submenu(build(null), "Chat"); + assert.equal(item(before, "Rename…").enabled, true, "everything works until the app reports"); + const menu = build(new Set(["chat.find", "navigate.back"])); + assert.equal(item(submenu(menu, "Chat"), "Find in Chat").enabled, true); + assert.equal(item(submenu(menu, "Chat"), "Rename…").enabled, false); + assert.equal(item(submenu(menu, "Go"), "Back").enabled, true); + assert.equal(item(submenu(menu, "Go"), "Forward").enabled, false); + // Menu-owned commands stay on: their key always works. + assert.notEqual(item(submenu(menu, "File"), "New Chat").enabled, false); +}); + +test("the app's list of runnable commands keeps only known command ids", () => { + assert.deepEqual([...(parseMenuCommandIds(["chat.find", "nope", 3, null, "navigate.back"]) ?? [])], [ + "chat.find", + "navigate.back", + ]); + assert.equal(parseMenuCommandIds("chat.find"), null); + assert.equal(parseMenuCommandIds(undefined), null); +}); diff --git a/main/services/application-menu-core.ts b/main/services/application-menu-core.ts index 2524b7c5ce..a02602e8ef 100644 --- a/main/services/application-menu-core.ts +++ b/main/services/application-menu-core.ts @@ -1,12 +1,20 @@ import type { MenuItemConstructorOptions } from "electron"; -import { electronAcceleratorForPlatform } from "../../renderer/shared/keybindings.js"; +import { COMMAND_IDS, electronAcceleratorForPlatform } from "../../renderer/shared/keybindings.js"; export interface ApplicationMenuActions { checkForUpdates(): void; - deliverCommand(commandId: string): void; + /** `viaKey`: the item's key fired it, not a click (see `shownItem`). */ + deliverCommand(commandId: string, viaKey?: boolean): void; reload(ignoreCache: boolean): void; } +/** The command ids the renderer reports it can run now; anything else is dropped. */ +export function parseMenuCommandIds(value: unknown): ReadonlySet | null { + if (!Array.isArray(value)) return null; + const known = new Set(COMMAND_IDS); + return new Set(value.filter((id): id is string => typeof id === "string" && known.has(id))); +} + export function platformMenuAccelerator( binding: string | null | undefined, platform: NodeJS.Platform, @@ -20,11 +28,14 @@ export function applicationMenuTemplate({ appName, bindings, actions, + available = null, }: { platform: NodeJS.Platform; appName: string; bindings: Readonly>; actions: ApplicationMenuActions; + /** Commands the renderer can run now; null until it says, when all are enabled. */ + available?: ReadonlySet | null; }): MenuItemConstructorOptions[] { const commandItem = ( label: string, @@ -34,6 +45,20 @@ export function applicationMenuTemplate({ accelerator: platformMenuAccelerator(bindings[commandId], platform), click: () => actions.deliverCommand(commandId), }); + // The renderer owns these keys: whether they act depends on focus and on + // what is open (a text field, the terminal, the browser). So the menu shows + // the key without taking it. On Linux and Windows the key is not registered; + // on macOS the page sees the key first, and a key the page left alone also + // reaches the menu, which hands it back marked `viaKey` for the renderer to + // drop. + const shownItem = (label: string, commandId: string): MenuItemConstructorOptions => ({ + label, + accelerator: platformMenuAccelerator(bindings[commandId], platform), + registerAccelerator: false, + enabled: !available || available.has(commandId), + click: (_item, _window, event) => + actions.deliverCommand(commandId, event?.triggeredByAccelerator === true), + }); const fileItems: MenuItemConstructorOptions[] = [ commandItem("New Chat", "chat.new"), commandItem("New Chat in…", "chat.newIn"), @@ -84,6 +109,14 @@ export function applicationMenuTemplate({ { label: "View", submenu: [ + shownItem("Toggle Sidebar", "sidebar.toggle"), + shownItem("Toggle Terminal", "terminal.toggle"), + shownItem("Toggle Environment", "environment.toggle"), + { type: "separator" }, + shownItem("Focus Sidebar", "focus.sidebar"), + shownItem("Focus Conversation", "focus.chat"), + shownItem("Focus Side Panel", "focus.panel"), + { type: "separator" }, { label: "Reload", accelerator: "CmdOrCtrl+R", @@ -103,12 +136,54 @@ export function applicationMenuTemplate({ { role: "togglefullscreen" }, ], }, + { + label: "Go", + submenu: [ + shownItem("Back", "navigate.back"), + shownItem("Forward", "navigate.forward"), + { type: "separator" }, + shownItem("Previous Chat", "chat.previous"), + shownItem("Next Chat", "chat.next"), + shownItem("Search Chats…", "chat.search"), + { type: "separator" }, + shownItem("Bots", "bots.open"), + shownItem("Open a Bot…", "bots.search"), + shownItem("Scheduled", "scheduled.open"), + shownItem("Profile", "profile.open"), + ], + }, + { + label: "Chat", + submenu: [ + shownItem("Change Model…", "model.change"), + shownItem("Attach Files…", "composer.attach"), + shownItem("Find in Chat", "chat.find"), + shownItem("Stop Reply", "chat.stop"), + { type: "separator" }, + shownItem("Rename…", "chat.rename"), + shownItem("Duplicate", "chat.duplicate"), + shownItem("Fork…", "chat.fork"), + shownItem("Compact", "chat.compact"), + shownItem("Export", "chat.export"), + shownItem("Copy Last Reply", "chat.copyLatest"), + shownItem("Chat Details", "chat.details"), + shownItem("Change Folder Access", "workspace.access"), + { type: "separator" }, + shownItem("Delete…", "chat.delete"), + ], + }, { role: "windowMenu" }, ); - if (platform !== "darwin") { + if (platform === "darwin") { + template.push({ + role: "help", + submenu: [shownItem("Keyboard Shortcuts", "shortcuts.show")], + }); + } else { template.push({ label: "Help", submenu: [ + shownItem("Keyboard Shortcuts", "shortcuts.show"), commandItem("Command Palette…", "commandPalette.toggle"), { type: "separator" }, { role: "about" }, diff --git a/main/services/native-menu-command-contract.test.ts b/main/services/native-menu-command-contract.test.ts index ec634f3d4f..f72fa3c59a 100644 --- a/main/services/native-menu-command-contract.test.ts +++ b/main/services/native-menu-command-contract.test.ts @@ -5,7 +5,7 @@ import { COMMANDS } from "../../renderer/shared/keybindings"; import { applicationMenuTemplate } from "./application-menu-core"; test("catalog native-menu ownership exactly matches derived Electron accelerators", () => { - const delivered = new Set(); + let clicked: string | null = null; const menu = applicationMenuTemplate({ platform: "darwin", appName: "Aiden Agent", @@ -13,26 +13,32 @@ test("catalog native-menu ownership exactly matches derived Electron accelerator actions: { checkForUpdates() {}, deliverCommand(commandId) { - delivered.add(commandId); + clicked = commandId; }, reload() {}, }, }); + // Items that only show a key (registerAccelerator: false) leave it to the + // renderer, so they must not be native-menu commands. + const owned = new Set(); + const shown = new Set(); const invokeItems = (items: typeof menu): void => { for (const item of items) { if (typeof item.click === "function") { + clicked = null; item.click({} as never, {} as never, {} as never); + if (clicked) (item.registerAccelerator === false ? shown : owned).add(clicked); } if (Array.isArray(item.submenu)) invokeItems(item.submenu); } }; invokeItems(menu); - const menuCommandIds = [...delivered].sort(); const catalogCommandIds = COMMANDS.filter((command) => command.nativeMenu) .map((command) => command.id) .sort(); - assert.deepEqual(menuCommandIds, catalogCommandIds); + assert.deepEqual([...owned].sort(), catalogCommandIds); + for (const id of shown) assert.ok(!catalogCommandIds.includes(id as never), id); }); test("shortcut recording removes the application menu before capture begins", () => { diff --git a/package.json b/package.json index 1864e03094..aaa35456a6 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "test:artificial-analysis": "tsx --test main/services/artificial-analysis-cache.test.ts main/services/artificial-analysis-runtime-core.test.ts main/services/artificial-analysis-catalog-core.test.ts main/services/provider-model-info-core.test.ts renderer/lib/settings-section.test.ts", "test:model-insights": "tsx --test main/services/openrouter-benchmark.test.ts main/services/models.test.ts main/services/provider-model-info-core.test.ts main/handlers/ipc-contract.test.ts main/services/model-pace.test.ts main/handlers/model-pace.test.ts renderer/lib/model-pace-queries.test.ts", "test:model-pad": "tsx --test renderer/components/ui-info-hint.test.tsx renderer/components/settings/model-pad/model-pad-settings.test.tsx renderer/components/settings/model-pad/model-pad-autosave.test.tsx renderer/components/settings/model-pad/model-pad-first-visit.test.tsx renderer/components/settings/model-pad/model-pad-siblings.test.tsx renderer/components/settings/model-pad/model-pad-measured-pace.test.tsx renderer/components/settings/model-pad/model-pad-add-popover.test.tsx renderer/components/settings/model-pad/model-pad-tray.test.tsx renderer/components/settings/model-pad/model-pad-data-rows.test.tsx renderer/components/model-pad-markers.test.tsx renderer/components/model-picker-pad.test.tsx renderer/components/model-picker.test.tsx renderer/components/model-hover-details.test.tsx renderer/lib/model-details.test.ts renderer/lib/google-provider-migration.test.ts renderer/lib/model-pad-layout.test.ts renderer/lib/model-pad-pace.test.ts renderer/lib/model-picker-data.test.ts renderer/lib/pi-provider-display.test.ts renderer/shared/model-pad-preferences.test.ts renderer/lib/model-pad-preferences.test.tsx renderer/lib/reduced-motion.test.ts", - "test:command-system": "tsx --test main/services/native-menu-command-contract.test.ts main/services/renderer-readiness-core.test.ts main/services/shortcut-registration-core.test.ts main/services/shortcut-transaction-core.test.ts main/services/superseding-task-core.test.ts renderer/lib/appearance-intent.test.ts renderer/lib/command-palette-contract.test.ts renderer/lib/command-palette-recent.test.ts renderer/lib/new-chat-workspaces.test.ts renderer/lib/command-system-core.test.ts renderer/lib/shortcut-settings-contract.test.ts renderer/lib/use-model-selection.test.ts renderer/shared/keybindings.test.ts renderer/lib/composer-type-focus.test.ts renderer/lib/held-modifier-reveal.test.ts renderer/lib/input-modality.test.ts renderer/lib/focus-regions.test.tsx renderer/components/chat-find-bar.test.tsx renderer/components/composer-edit-last.test.tsx", + "test:command-system": "tsx --test main/services/native-menu-command-contract.test.ts main/services/renderer-readiness-core.test.ts main/services/shortcut-registration-core.test.ts main/services/shortcut-transaction-core.test.ts main/services/superseding-task-core.test.ts renderer/lib/appearance-intent.test.ts renderer/lib/command-palette-contract.test.ts renderer/lib/command-palette-recent.test.ts renderer/lib/new-chat-workspaces.test.ts renderer/lib/command-system-core.test.ts renderer/lib/shortcut-settings-contract.test.ts renderer/lib/use-model-selection.test.ts renderer/shared/keybindings.test.ts renderer/lib/composer-type-focus.test.ts renderer/lib/held-modifier-reveal.test.ts renderer/lib/input-modality.test.ts renderer/lib/focus-regions.test.tsx renderer/components/chat-find-bar.test.tsx renderer/components/composer-edit-last.test.tsx renderer/lib/shortcut-sheet.test.ts renderer/components/keyboard-shortcuts-dialog.test.tsx", "test:slash-commands": "tsx --test main/services/generation-initialization-terminal.test.ts main/handlers/attachments.contract.test.ts main/handlers/chat.parse.test.ts main/handlers/chat-create-params.test.ts main/handlers/chat-session-params.test.ts main/handlers/worktree-create-params.test.ts main/services/chat-workspace-authority.test.ts main/handlers/chats.append.contract.test.ts main/services/attachment-contract.test.ts main/services/attachments.test.ts main/services/chat-append-commit.test.ts main/services/chat-export.test.ts main/services/chat-message-contract.test.ts main/services/chat-session-copy.test.ts main/services/chat-fork-service.test.ts main/services/chat-store-core.test.ts main/services/empty-chat-migration.test.ts main/services/chat-first-message-commit.test.ts main/services/chat-run-input-admission.test.ts main/services/chat-turn-admission.test.ts main/services/generation-messages.test.ts main/services/provider-auth-flow-core.test.ts main/services/provider-list-core.test.ts main/services/provider-artwork-core.test.ts main/services/provider-artwork.test.ts main/services/scheduled-chat-creation.test.ts main/services/skill-invocation-flow.integration.test.ts main/services/skill-invocation-turn.test.ts main/services/skill-registry-core.test.ts main/services/skill-registry.test.ts main/services/skill-tools.test.ts main/services/skills-discovery.test.ts renderer/components/assistant/assistant-ui.test.tsx renderer/components/composer.test.tsx renderer/components/composer-slash-palette.test.tsx renderer/lib/chat-message-queue.test.ts renderer/lib/chat-draft.test.ts renderer/components/message-bubble.test.tsx renderer/lib/chat-copy-view.test.ts renderer/components/fork-summary-card.test.tsx renderer/shared/chat-copy-contract.test.ts renderer/lib/codex-provider-cache.test.ts renderer/lib/composer-submission.test.ts renderer/lib/ipc-stream.test.ts renderer/lib/skill-catalog-workspace.test.ts renderer/lib/slash-command-actions.test.ts renderer/lib/slash-command-core.test.ts renderer/lib/slash-command-performance.test.ts renderer/main/chat-transition.test.tsx renderer/shared/attachment-contract.test.ts renderer/shared/chat-message-contract.test.ts renderer/shared/slash-commands.test.ts renderer/components/settings/skills-settings.test.tsx renderer/lib/composer-type-focus.test.ts renderer/lib/compaction-command-admission.test.ts", "test:rich-links": "tsx --test renderer/lib/rich-link.test.ts renderer/lib/user-message-fold.test.ts renderer/components/message-bubble.test.tsx renderer/lib/streaming-motion-contract.test.ts renderer/components/message-list-settle.test.tsx renderer/components/streaming-markdown-reveal.test.tsx renderer/components/provider-failure-callout.test.tsx", "test:display-image": "tsx --test renderer/components/classifier-approval.test.tsx main/services/pi-model-tools.test.ts main/services/pi-local-classifier.test.ts main/services/display-image-artifact-store.test.ts main/services/display-image-extension.test.ts main/services/generation-timeline.test.ts renderer/components/message-bubble.test.tsx renderer/lib/ipc-stream.test.ts", diff --git a/renderer/components/keyboard-shortcuts-dialog.test.tsx b/renderer/components/keyboard-shortcuts-dialog.test.tsx new file mode 100644 index 0000000000..c5b9db8a1c --- /dev/null +++ b/renderer/components/keyboard-shortcuts-dialog.test.tsx @@ -0,0 +1,167 @@ +// Installs happy-dom and the fake IPC bridge; must stay the first import. +import { emitBotTestNotification, installBotTestIpc, type BotTestIpcCall } from "../main/bots/test-dom"; +import assert from "node:assert/strict"; +import { afterEach, beforeEach, test } from "node:test"; +import * as React from "react"; +import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react"; +import { QueryClientProvider } from "@tanstack/react-query"; +import { createBotTestQueryClient, mountWithBotRouter } from "../main/bots/test-providers"; +import { KeyboardShortcutsDialog } from "./keyboard-shortcuts-dialog"; +import { ShortcutSettings } from "./settings/shortcut-settings"; +import { TooltipProvider } from "./ui"; +import { CommandSystemProvider, useCommandHandler, useCommandSystem } from "../lib/command-system"; +import { applyKeybindingMutation, effectiveBindings, type CommandId } from "../shared/keybindings"; + +let calls: BotTestIpcCall[] = []; + +function install(overrides = applyKeybindingMutation(undefined, { commandId: "chat.find", binding: "Command+Shift+G" })) { + calls = installBotTestIpc({ + "shortcut:get": () => ({ overrides, effective: effectiveBindings(overrides), global: [] }), + "shortcut:setRecording": () => ({ overrides, effective: effectiveBindings(overrides), global: [] }), + "app:setMenuCommands": () => true, + }); +} + +beforeEach(() => install()); +afterEach(cleanup); + +let run: (commandId: CommandId) => boolean = () => false; +function Commands() { + run = useCommandSystem().execute; + return null; +} + +test("⌘/ lists every key as set in Settings, with the built-in ones, and search narrows it", async () => { + await mountWithBotRouter(null, { + initialPath: "/", + sidebar: ( + + + + + ), + }); + await waitFor(() => assert.equal(run("shortcuts.show"), true)); + const dialog = await screen.findByRole("dialog", { name: "Keyboard shortcuts" }); + const find = within(dialog).getByText("Find in chat").closest("li")!; + // The key someone set in Settings, not the default ⌘F. + assert.match(find.textContent ?? "", /Shift\+G|⇧G/u); + assert.ok(within(dialog).getByText("Next / previous area"), "a built-in key"); + assert.ok(within(dialog).getByRole("heading", { name: "In a chat" })); + + const search = within(dialog).getByRole("searchbox", { name: "Search keyboard shortcuts" }); + assert.equal(document.activeElement, search, "ready to type"); + fireEvent.change(search, { target: { value: "F6" } }); + assert.deepEqual( + within(dialog) + .getAllByRole("listitem") + .map((item) => item.querySelector("p")?.textContent), + ["Next / previous area"], + ); + fireEvent.change(search, { target: { value: "nothing like this" } }); + assert.match(within(dialog).getByRole("status").textContent ?? "", /No keys match/u); +}); + +test("Esc closes the list and gives focus back to the message box", async () => { + await mountWithBotRouter(