Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(shortcuts): reject conflicting individual resets

yuxinod432ef47d90c
diff --git a/apps/desktop/src/components/settings/KeyboardShortcutsSection.tsx b/apps/desktop/src/components/settings/KeyboardShortcutsSection.tsx
index 85edcc00b..7d5c242ee 100644
--- a/apps/desktop/src/components/settings/KeyboardShortcutsSection.tsx
+++ b/apps/desktop/src/components/settings/KeyboardShortcutsSection.tsx
@@ -96,6 +96,23 @@ export function KeyboardShortcutsSection({ settings, platform, saveSettings }: P
} else {
next[shortcut.id] = binding;
}
+ const conflict = KEYBOARD_SHORTCUTS.find(
+ (candidate) =>
+ candidate.id !== shortcut.id &&
+ keybindingsConflict(
+ resolveKeybinding(candidate, settings.keybindings, platform),
+ resolveKeybinding(shortcut, next, platform),
+ ),
+ );
+ if (conflict) {
+ setError({
+ id: shortcut.id,
+ message: t("settings.shortcutConflict", {
+ action: t(shortcutLabelKey(conflict.id)),
+ }),
+ });
+ return;
+ }
setSavingId(shortcut.id);
setError(null);
try {
@@ -132,23 +149,6 @@ export function KeyboardShortcutsSection({ settings, platform, saveSettings }: P
setError({ id: shortcut.id, message: t("settings.shortcutReserved") });
return;
}
- const conflict = KEYBOARD_SHORTCUTS.find(
- (candidate) =>
- candidate.id !== shortcut.id &&
- keybindingsConflict(
- resolveKeybinding(candidate, settings.keybindings, platform),
- binding,
- ),
- );
- if (conflict) {
- setError({
- id: shortcut.id,
- message: t("settings.shortcutConflict", {
- action: t(shortcutLabelKey(conflict.id)),
- }),
- });
- return;
- }
void storeBinding(shortcut, binding);
};
diff --git a/docs/spec/04-ux/06-settings-ia.md b/docs/spec/04-ux/06-settings-ia.md
index d043475ad..a752c4507 100644
--- a/docs/spec/04-ux/06-settings-ia.md
+++ b/docs/spec/04-ux/06-settings-ia.md
@@ -240,7 +240,8 @@ a usage tab.
are rejected with an inline error; an unbound action never participates in
conflict checks
- each override can be restored independently and all overrides can be
- restored together
+ restored together; an individual reset rejects a default already used by
+ another action, preserving both mappings and showing the same conflict error
- overrides persist in optional `AppSettings.keybindings`; a missing entry
uses the platform default, a valid string uses the custom binding, and
`null` disables the action. macOS native-menu accelerators and
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 0aa54929f..32969e62b 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -4724,7 +4724,11 @@ identify the platform validation still needed.
`Alt + Shift + W` and confirm the window hides to the tray with no
close-behaviour prompt and with the app still running; from another
application, press it again and confirm the window returns and focuses.
- 13) Seed one profile with a stored customized `closeWindow` binding and one
+ 13) Disable New task, assign its default chord to Search, then reset New task
+ individually. Confirm the conflict error preserves both mappings and Search
+ still opens with that chord. Repeat with New task customized instead of disabled;
+ free the default by resetting Search, then retry New task reset.
+ 14) Seed one profile with a stored customized `closeWindow` binding and one
with a customized `summonWindow` binding; confirm each profile keeps that
binding on the single toggle row after restart and that `Cmd/Ctrl + Shift +
W` registers nothing.
@@ -4736,7 +4740,8 @@ identify the platform validation still needed.
Unbound displays as a localized explicit state, participates in no conflicts,
dispatches no old or default chord, persists across restart, removes the
macOS accelerator, and disables the Windows launcher fallback layers;
- individual and global reset restore the shared defaults; Keyboard shortcuts is
+ individual reset rejects an occupied default without changing either action;
+ conflict-free individual and global reset restore the shared defaults; Keyboard shortcuts is
its own Settings destination. Modifier-only and IME keydowns dispatch nothing,
and a held history chord traverses only once per physical press. The
window-visibility key is one toggle on `Alt + Shift + W` — a visible, focused
diff --git a/docs/zh-CN/spec/04-ux/06-settings-ia.md b/docs/zh-CN/spec/04-ux/06-settings-ia.md
index 44bead94d..302192489 100644
--- a/docs/zh-CN/spec/04-ux/06-settings-ia.md
+++ b/docs/zh-CN/spec/04-ux/06-settings-ia.md
@@ -150,7 +150,8 @@ Token 用量**不是设置目的地**(D335 / ADR 0173)。已完成回合历
- 每个绑定都可以明确设为“未绑定”;该状态仍可编辑,且不同于恢复默认值
- 重复的应用程序绑定和 operating-system/editor-reserved 和弦
会以内联错误拒绝;未绑定的操作不参与冲突检查
- - 每个覆盖都可以独立恢复,并且所有覆盖都可以一起恢复
+ - 每个覆盖都可以独立恢复,并且所有覆盖都可以一起恢复;单项恢复时若默认组合
+ 已被其他操作占用,则保留两项绑定并显示同样的冲突错误
- 覆盖持续存在于可选的 `AppSettings.keybindings` 中:缺少属性使用平台默认值,
合法字符串使用自定义绑定,`null` 表示明确禁用;macOS 本机菜单加速器和
渲染器拥有的快捷键从同一张映射更新
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 35e0ca654..b72b01347 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -2977,12 +2977,15 @@ PI-Desktop 图标;两个表面都不会暴露库存 Electron 名称或图标
确认所有行都恢复默认。9) 在 macOS 上检查每次保存/恢复后的本机菜单加速器。10)
在 Windows 上禁用插件启动器,确认旧的全局绑定、聚焦窗口后备和 Alt+Space host
后备都已关闭。11) 单独按下并释放 Ctrl/Command,确认 IME 候选,并长按
- back/forward 组合以产生重复。
+ back/forward 组合以产生重复。12) 禁用 New task,把其默认组合分配给 Search,
+ 再单独恢复 New task;确认出现冲突提示、两项绑定不变,且该组合仍能打开 Search。
+ 将 New task 改为自定义绑定后重复测试;恢复 Search 释放组合后,再恢复 New task。
- **预期**:操作分为导航、Agent 和窗口,并使用平台原生按键标签;录制有可见焦点
且 `Escape` 取消;自定义 Search 组合立即生效、替换旧组合、跨重启保留并更新
macOS 菜单;重复、无修饰符和保留组合以内联错误拒绝;“未绑定”是明确的本地化
状态,不参与冲突、不响应旧或默认组合、可跨重启保存,并会移除 macOS 加速器和
- Windows 启动器后备层;单项和全局恢复都返回共享默认值。仅修饰符和 IME 按键不
+ Windows 启动器后备层;单项恢复遇到默认组合已被占用时拒绝保存,保留两项绑定;
+ 无冲突的单项恢复和全局恢复都返回共享默认值。仅修饰符和 IME 按键不
会发送命令,长按历史组合每次物理按压只遍历一次。窗口可见性只有一个开关键
`Alt + Shift + W` —— 可见且在前台的窗口隐藏到托盘,其余情况显示并获得焦点 ——
且绝不走关闭路径,因此不会弹出关闭行为询问、也不会退出应用;该键刻意避开
diff --git a/package.json b/package.json
index 4bb784178..4f43b9849 100644
--- a/package.json
+++ b/package.json
@@ -61,6 +61,7 @@
"test:e2e:collaboration": "node scripts/e2e-session-collaboration.mjs",
"test:e2e:session-completion": "node scripts/e2e-session-completion.mjs",
"test:e2e:remote-host": "node scripts/e2e-remote-host.mjs",
+ "test:e2e:shortcut-settings": "node scripts/test-shortcut-settings.mjs",
"test:e2e:dialog-overflow": "node scripts/test-dialog-overflow.mjs"
},
"devDependencies": {
diff --git a/scripts/test-shortcut-settings.mjs b/scripts/test-shortcut-settings.mjs
new file mode 100644
index 000000000..a0adaff58
--- /dev/null
+++ b/scripts/test-shortcut-settings.mjs
@@ -0,0 +1,109 @@
+/** Exercise the production shortcut component in isolated Electron/Chromium. */
+import assert from "node:assert/strict";
+import { spawn } from "node:child_process";
+import { mkdtemp, writeFile, rm } from "node:fs/promises";
+import { createRequire } from "node:module";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { repositoryRoot, resolveElectronBinary } from "./e2e/boot.mjs";
+
+const root = repositoryRoot();
+const temp = await mkdtemp(join(tmpdir(), "pi-shortcut-settings-"));
+const { build } = createRequire(new URL("../packages/agent-runtime/package.json", import.meta.url))("esbuild");
+try {
+ await build({
+ stdin: {
+ resolveDir: join(root, "apps/desktop"), loader: "jsx",
+ contents: `
+import React, { act, useState } from "react";
+import { createRoot } from "react-dom/client";
+import i18n from "i18next";
+import { initReactI18next } from "react-i18next";
+import { catalogs, flattenCatalog } from "@pi-desktop/i18n";
+import { KeyboardShortcutsSection } from "./src/components/settings/KeyboardShortcutsSection";
+window.IS_REACT_ACT_ENVIRONMENT = true;
+await i18n.use(initReactI18next).init({ lng: "en", keySeparator: false,
+ resources: { en: { translation: flattenCatalog(catalogs.en) } } });
+const root = createRoot(document.getElementById("root"));
+const check = (value, message) => { if (!value) throw new Error(message); };
+const label = (action, id) => i18n.t("settings.shortcut" + action, {
+ action: i18n.t("settings.shortcutAction." + id),
+});
+const button = (name) => {
+ const found = [...document.querySelectorAll("button")].find(b =>
+ b.getAttribute("aria-label") === name || b.textContent === name);
+ check(found && !found.disabled, "Missing enabled button: " + name);
+ return found;
+};
+const click = async (name) => { await act(async () => button(name).click()); };
+const bind = async (id, platform, key) => {
+ await click(label("Change", id));
+ await act(async () => button(label("Change", id)).dispatchEvent(new KeyboardEvent("keydown", {
+ key, bubbles: true, cancelable: true,
+ metaKey: platform === "darwin", ctrlKey: platform !== "darwin",
+ })));
+};
+window.runTests = async () => {
+ for (const platform of ["darwin", "win32", "linux"]) {
+ let saved;
+ function Harness() {
+ const [settings, setSettings] = useState({ keybindings: {} });
+ saved = settings.keybindings;
+ return <KeyboardShortcutsSection settings={settings} platform={platform}
+ saveSettings={async patch => setSettings(s => ({ ...s, ...patch }))} />;
+ }
+ await act(async () => root.render(<Harness key={platform} />));
+ await click(label("Disable", "newTask"));
+ check(saved.newTask === null, "Disable must persist Unbound");
+ await bind("openSearch", platform, "n");
+ check(saved.openSearch === "Mod+N", "Search can use the freed binding");
+ await click(label("Reset", "newTask"));
+ check(saved.newTask === null && saved.openSearch === "Mod+N",
+ platform + ": conflicting reset must preserve both mappings");
+ check(document.querySelector('[role="alert"]')?.textContent ===
+ i18n.t("settings.shortcutConflict", { action: i18n.t("settings.shortcutAction.openSearch") }),
+ "Reset must identify the conflicting action inline");
+ await click(label("Reset", "openSearch"));
+ await click(label("Reset", "newTask"));
+ check(Object.keys(saved).length === 0, "Reset succeeds once the default is free");
+ await bind("openSearch", platform, "n");
+ check(Object.keys(saved).length === 0 && document.querySelector('[role="alert"]'),
+ "Manual assignment must still reject conflicts");
+ await bind("newTask", platform, "F8");
+ await bind("openSearch", platform, "n");
+ await click(label("Reset", "newTask"));
+ check(saved.newTask === "Mod+F8" && saved.openSearch === "Mod+N",
+ "Conflicting reset must preserve a custom binding too");
+ await click(i18n.t("settings.shortcutResetAll"));
+ check(Object.keys(saved).length === 0 && !document.querySelector('[role="alert"]'),
+ "Global reset must clear overrides and errors together");
+ }
+ await act(async () => root.unmount());
+ return "PASS: shortcut disable, reassign, conflicting reset, recovery and global reset on three platforms";
+};`,
+ },
+ outfile: join(temp, "fixture.js"), bundle: true, format: "esm", platform: "browser", jsx: "automatic",
+ define: { "process.env.NODE_ENV": '"development"', "import.meta.env.DEV": "false" },
+ });
+ await writeFile(join(temp, "index.html"), '<div id="root"></div><script type="module" src="fixture.js"></script>');
+ await writeFile(join(temp, "runner.cjs"), `
+const { app, BrowserWindow } = require("electron");
+app.setPath("userData", ${JSON.stringify(join(temp, "profile"))});
+app.whenReady().then(async () => {
+ const win = new BrowserWindow({ show: false, webPreferences: { backgroundThrottling: false } });
+ try {
+ await win.loadFile(${JSON.stringify(join(temp, "index.html"))});
+ console.log(await win.webContents.executeJavaScript("window.runTests()"));
+ app.exit(0);
+ } catch (error) { console.error(error); app.exit(1); }
+});`);
+ const env = { ...process.env };
+ delete env.ELECTRON_RUN_AS_NODE;
+ const child = spawn(resolveElectronBinary(root).electronBinary, [join(temp, "runner.cjs")], { env, stdio: "inherit" });
+ const timeout = setTimeout(() => child.kill(), 30_000);
+ const code = await new Promise((resolve, reject) => { child.on("exit", resolve); child.on("error", reject); });
+ clearTimeout(timeout);
+ assert.equal(code, 0, "Mounted shortcut interaction regression");
+} finally {
+ await rm(temp, { recursive: true, force: true });
+}