Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(desktop): prevent accidental Ctrl+R reload
vastsa07f630a72625
diff --git a/apps/desktop/electron/main/bootstrap/startup.ts b/apps/desktop/electron/main/bootstrap/startup.tsindex 4caf0754e..d91209bee 100644--- a/apps/desktop/electron/main/bootstrap/startup.ts+++ b/apps/desktop/electron/main/bootstrap/startup.ts@@ -372,7 +372,7 @@ export function registerApplicationStartup(deps: StartupDependencies): void {}, 300);// Headless boot probe for automated e2e (scripts/e2e-electron-boot.mjs):- // verifies sandboxed preload bridge + a full IPC round-trip, then quits.+ // verifies the preload bridge, IPC round-trips, and Ctrl+R guard, then quits.if (process.env.PI_DESKTOP_BOOT_PROBE === "1") {setTimeout(() => {void (async () => {@@ -412,6 +412,42 @@ export function registerApplicationStartup(deps: StartupDependencies): void {};})()`,);+ let ctrlRPrevented = false;+ const observeCtrlR = (+ event: Electron.Event,+ input: Electron.Input,+ ) => {+ if (+ input.type === "keyDown" &&+ input.code === "KeyR" &&+ input.control &&+ !input.meta &&+ !input.alt &&+ !input.shift+ ) {+ ctrlRPrevented = event.defaultPrevented;+ }+ };+ window!.webContents.on("before-input-event", observeCtrlR);+ try {+ window!.webContents.sendInputEvent({+ type: "keyDown",+ keyCode: "R",+ modifiers: ["control"],+ });+ window!.webContents.sendInputEvent({+ type: "keyUp",+ keyCode: "R",+ modifiers: ["control"],+ });+ await new Promise((resolve) => setTimeout(resolve, 100));+ } finally {+ window!.webContents.removeListener(+ "before-input-event",+ observeCtrlR,+ );+ }+ probe.ctrlRBlocked = ctrlRPrevented;probe.appName = app.getName();probe.menuCount = Menu.getApplicationMenu()?.items.length ?? 0;if (!host || !window) throw new Error("session-list probe requires a healthy desktop");diff --git a/apps/desktop/electron/main/bootstrap/window.ts b/apps/desktop/electron/main/bootstrap/window.tsindex 48776a118..578ac7eb3 100644--- a/apps/desktop/electron/main/bootstrap/window.ts+++ b/apps/desktop/electron/main/bootstrap/window.ts@@ -497,6 +497,18 @@ export async function createWindow({// null, so F12 is wired here; macOS additionally inherits Cmd+Alt+I from// the View menu role (see application-menu.ts).window.webContents.on("before-input-event", (event, input) => {+ const isReloadChord =+ input.type === "keyDown" &&+ input.code === "KeyR" &&+ input.control &&+ !input.meta &&+ !input.alt &&+ !input.shift;+ if (isReloadChord) {+ // Keep an accidental browser reload from discarding transient app-shell state.+ event.preventDefault();+ return;+ }const isPluginLauncherChord =process.platform === "win32" &&windowState.pluginLauncherBinding === "Alt+Space" &&diff --git a/apps/desktop/test/window-menu.test.mjs b/apps/desktop/test/window-menu.test.mjsindex f452c98a7..92fff6bfd 100644--- a/apps/desktop/test/window-menu.test.mjs+++ b/apps/desktop/test/window-menu.test.mjs@@ -145,6 +145,35 @@ test("developer mode gates every devtools entry point in the main process", () =);});+test("the main app shell consumes unmodified Ctrl+R before Chromium reloads", () => {+ const handlerStart = mainSource.indexOf(+ 'window.webContents.on("before-input-event"',+ );+ const handlerEnd = mainSource.indexOf("\n });", handlerStart);+ const handler = mainSource.slice(handlerStart, handlerEnd);+ const reloadGuard = handler.slice(+ handler.indexOf("if (isReloadChord)"),+ handler.indexOf("const isPluginLauncherChord"),+ );+ assert.match(+ handler,+ /const isReloadChord =\s*input\.type === "keyDown" &&\s*input\.code === "KeyR" &&\s*input\.control &&\s*!input\.meta &&\s*!input\.alt &&\s*!input\.shift;/,+ );+ assert.match(reloadGuard, /event\.preventDefault\(\);\s*return;/);+ assert.ok(+ handler.indexOf("if (isReloadChord)") <+ handler.indexOf("const isPluginLauncherChord"),+ "reload prevention must run before other focused-window shortcuts",+ );+ assert.ok(+ handler.indexOf("if (isReloadChord)") <+ handler.indexOf(+ 'if (input.type !== "keyDown" || !windowState.developerMode) return;',+ ),+ "reload prevention must not depend on developer mode",+ );+});+test("Windows and Linux use menu-free frameless chrome with window controls", () => {assert.match(mainSource,diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.mdindex 405ef864e..1275fbab6 100644--- a/docs/spec/04-ux/09-interaction-patterns.md+++ b/docs/spec/04-ux/09-interaction-patterns.md@@ -51,6 +51,9 @@application menubar; command-only shortcuts are discoverable via commandpalette search (keyword "shortcut" or "keybinding").- Shortcuts must not conflict with macOS system shortcuts or common browser shortcuts+- The main application shell consumes unmodified `Ctrl + R` before Chromium+ handles its browser reload shortcut; the macOS `Cmd + R` menu accelerator+ and explicit **Reload** menu action remain unchanged.- Never override `Cmd/Ctrl + C`, `Cmd/Ctrl + V`, `Cmd/Ctrl + A`, `Cmd/Ctrl + S`- Shortcuts are consistent across macOS (Cmd) and Windows/Linux (Ctrl)- A missing shortcut override uses the shared platform default; a validdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 3624acda3..30db460dc 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -5264,6 +5264,10 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.with a customized `summonWindow` binding; confirm each profile keeps thatbinding on the single toggle row after restart and that `Cmd/Ctrl + Shift +W` registers nothing.+ 15) With an unsent composer draft in the main window, press unmodified+ `Ctrl + R`; confirm the renderer remains loaded and the draft remains intact.+ On macOS, confirm `Cmd + R` and the explicit View → Reload menu action are+ unchanged.- **Expected**: Actions are grouped as Navigation, Agent, and Window withplatform-native key labels; recording has visible focus and `Escape` cancels;the custom Search chord takes effect immediately, replaces the old chord,@@ -5275,6 +5279,8 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.individual reset rejects an occupied default without changing either action;conflict-free individual and global reset restore the shared defaults; Keyboard shortcuts isits own Settings destination. Modifier-only and IME keydowns dispatch nothing,+ an unmodified `Ctrl + R` is consumed before Chromium reloads the main renderer,+ preserving the unsent draft; macOS `Cmd + R` and View → Reload remain available.and a held history chord traverses only once per physical press. Thewindow-visibility key is one toggle on `Alt + Shift + W` — a visible, focusedwindow hides to the tray, anything else shows and focuses — and it never@@ -5287,9 +5293,10 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.`03-runtime/01-ipc-protocol.md`- **Acceptance**: F (settings persistence), Quality (keyboard accessibility)- **Milestone**: M5-- **Status**: Unit-covered (`keyboard-shortcuts.test.ts`,- `settings-keyboard-shortcuts.test.mjs`, `window-toggle-shortcut.test.mjs`,- host settings RPC test); rendered scenario Draft+- **Status**: Shortcut unit-covered (`keyboard-shortcuts.test.ts`,+ `settings-keyboard-shortcuts.test.mjs`, `window-menu.test.mjs`,+ `window-toggle-shortcut.test.mjs`); `test:e2e:boot` verifies the main-window+ Ctrl+R input is consumed. The full rendered settings journey remains Draft.#### E2E-073a: Developer mode gates the developer-tools consolediff --git a/scripts/e2e-electron-boot.mjs b/scripts/e2e-electron-boot.mjsindex ea11b468e..d97501b43 100644--- a/scripts/e2e-electron-boot.mjs+++ b/scripts/e2e-electron-boot.mjs@@ -121,6 +121,7 @@ child.on("close", (code) => {projectRemove?.ok === true &&projectRemove.removed === false &&projectRemove.sessionsRemoved === 0;+ const ctrlRBlocked = probe?.ctrlRBlocked === true;if (code === 0 &&probe?.ok &&@@ -129,7 +130,8 @@ child.on("close", (code) => {(process.platform === "darwin" || probe.maximized === true) &&menuContractOk &&sessionListOk &&- projectRemoveOk+ projectRemoveOk &&+ ctrlRBlocked) {const menuDetail =process.platform === "darwin"@@ -147,6 +149,7 @@ child.on("close", (code) => {"projectRemove IPC round-trip through the sandboxed preload " +`{removed:${probe.projectRemove.removed}, sessionsRemoved:${probe.projectRemove.sessionsRemoved}}`,);+ console.log("PASS E2E-072-main-window-ctrl-r-blocked");cleanup(0);} else {console.error("FAIL boot-probe —", JSON.stringify(probe));