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(window): restrict recovery pinning to macOS
Xuese24c0894bda45
diff --git a/apps/desktop/electron/main/bootstrap/window.ts b/apps/desktop/electron/main/bootstrap/window.tsindex 4d833409a..df2216395 100644--- a/apps/desktop/electron/main/bootstrap/window.ts+++ b/apps/desktop/electron/main/bootstrap/window.ts@@ -900,8 +900,8 @@ export async function createWindow({// so the reservation replan below is treated as an OS-owned adjustment.windowState.workPanelUserMovePending = false;applyWorkPanelReservation();- // Brief pin only when actively recovering from a shelf.- if (shelved || electronTiny) {+ // Only macOS runs the watchdog that releases this temporary recovery pin.+ if (process.platform === "darwin" && (shelved || electronTiny)) {window.setAlwaysOnTop(true, "floating");pinUntil = Date.now() + 4000;} else {diff --git a/apps/desktop/test/window-topmost-lifecycle.test.mjs b/apps/desktop/test/window-topmost-lifecycle.test.mjsnew file mode 100644index 000000000..33f5720bc--- /dev/null+++ b/apps/desktop/test/window-topmost-lifecycle.test.mjs@@ -0,0 +1,132 @@+import assert from "node:assert/strict";+import { EventEmitter } from "node:events";+import { stripTypeScriptTypes } from "node:module";+import test from "node:test";+import vm from "node:vm";+import {+ clampMinimumSizeToWorkArea,+ emptyWorkPanelReservationState,+ windowBoundsEqual,+} from "../electron/main/work-panel-window.ts";+import { readMainModule } from "./helpers/source-contracts.mjs";++const source = await readMainModule("bootstrap/window.ts");+// Execute the production recovery, event wiring and watchdog without booting Electron.+const recovery = source.slice(+ source.indexOf(" const CODEX_BOUNDS ="),+ source.indexOf(' window.on("resize", observeNativeWorkPanelResize)'),+);+const watchdogStart = source.indexOf(" const boundsWatchdog:");+const watchdog = source.slice(watchdogStart, source.indexOf(' window.on("closed",', watchdogStart));++function createRecoveryWindow(platform, { tiny = false, visible = true, minimized = false } = {}) {+ let now = 10000;+ let bounds = { x: 80, y: 70, width: tiny ? 300 : 1000, height: 700 };+ let topmost = false;+ let nextTimer = 0;+ const timers = new Map();+ const calls = [];+ const window = Object.assign(new EventEmitter(), {+ isMaximized: () => false,+ isMinimized: () => minimized,+ isVisible: () => visible,+ getBounds: () => ({ ...bounds }),+ restore: () => { minimized = false; calls.push("restore"); },+ setMinimumSize: () => calls.push("minimum"),+ setAlwaysOnTop: (value) => { topmost = value; calls.push(value ? "pin" : "unpin"); },+ show: () => { visible = true; calls.push("show"); },+ hide: () => { visible = false; calls.push("hide"); },+ focus: () => calls.push("focus"),+ moveTop: () => calls.push("raise"),+ setBounds: (value) => { bounds = { ...value }; calls.push("bounds"); },+ setSize: (width, height) => { bounds = { ...bounds, width, height }; },+ setPosition: (x, y) => { bounds = { ...bounds, x, y }; },+ });+ const schedule = (callback, delay, repeat = false) => {+ const id = ++nextTimer;+ timers.set(id, { callback, at: now + delay, delay, repeat });+ return id;+ };+ vm.runInNewContext(stripTypeScriptTypes(`${recovery}\n${watchdog}`), {+ window,+ windowState: {},+ windowMinWidth: 800,+ windowMinHeight: 560,+ windowBoundsSettleMs: 300,+ isLiveWindow: () => true,+ screen: { getDisplayMatching: () => ({ workArea: { x: 0, y: 0, width: 1920, height: 1080 } }) },+ clampMinimumSizeToWorkArea,+ emptyWorkPanelReservationState,+ windowBoundsEqual,+ applyWorkPanelReservation: () => {},+ existsSync: () => false,+ process: { platform },+ Date: { now: () => now },+ console: { log: () => {} },+ setTimeout: (callback, delay) => schedule(callback, delay),+ clearTimeout: (id) => timers.delete(id),+ setInterval: (callback, delay) => schedule(callback, delay, true),+ clearInterval: (id) => timers.delete(id),+ });+ return {+ window,+ calls,+ get topmost() { return topmost; },+ get timerCount() { return timers.size; },+ advance(ms) {+ const end = now + ms;+ for (;;) {+ const next = [...timers].filter(([, timer]) => timer.at <= end)+ .sort((a, b) => a[1].at - b[1].at)[0];+ if (!next) break;+ const [id, timer] = next;+ now = timer.at;+ if (timer.repeat) timer.at += timer.delay;+ else timers.delete(id);+ timer.callback();+ }+ now = end;+ },+ };+}++for (const platform of ["win32", "linux", "darwin"]) {+ for (const event of ["show", "focus", "restore"]) {+ test(`${platform}: ${event} recovers tiny geometry with platform-owned pin cleanup`, () => {+ const app = createRecoveryWindow(platform, { tiny: true });+ app.window.emit(event);+ assert.deepEqual(app.window.getBounds(), { x: 40, y: 30, width: 1200, height: 800 });+ if (platform === "darwin") {+ assert.equal(app.topmost, true);+ app.advance(3999);+ assert.equal(app.topmost, true, "keep the recovery pin until its deadline");+ app.advance(501);+ assert.equal(app.topmost, false, "the existing watchdog must release the expired pin");+ } else {+ app.advance(10000);+ }+ app.window.emit("focus");+ assert.equal(app.topmost, false, "normal focus must not leave the window pinned");+ assert.equal(app.calls.includes("pin"), platform === "darwin");+ if (platform !== "darwin") assert.equal(app.timerCount, 0, "no layer watchdog off macOS");+ });+ }++ test(`${platform}: normal focus does not raise or resize the window`, () => {+ const app = createRecoveryWindow(platform);+ app.window.emit("focus");+ assert.deepEqual(app.calls, []);+ assert.deepEqual(app.window.getBounds(), { x: 80, y: 70, width: 1000, height: 700 });+ });++ for (const state of [{ visible: false }, { minimized: true }]) {+ test(`${platform}: hidden/minimized tiny windows preserve user state ${JSON.stringify(state)}`, () => {+ const app = createRecoveryWindow(platform, { tiny: true, ...state });+ for (const event of ["show", "focus", "restore"]) app.window.emit(event);+ app.advance(10000);+ assert.deepEqual(app.calls, []);+ assert.equal(app.topmost, false);+ assert.deepEqual(app.window.getBounds(), { x: 80, y: 70, width: 300, height: 700 });+ });+ }+}diff --git a/docs/spec/04-ux/07-ui-design-system.md b/docs/spec/04-ux/07-ui-design-system.mdindex 0048d643f..4d9ffdd34 100644--- a/docs/spec/04-ux/07-ui-design-system.md+++ b/docs/spec/04-ux/07-ui-design-system.md@@ -1459,7 +1459,7 @@ adjacent form inputs; dense surfaces may override that metric locally.- Floating composer plate: Codex elevated-primary (`#212121f5` / `color-mix(gray-800 96%, transparent)`) with standard elevation-prominent (`0 0 0 .5px` stroke + `0 3px 7.5px #0000000a` + `0 0 20px #0000000d`); no heavier night-only lift- Light workspace chips capsule: elevated gray `#f4f4f4` (not pure white-on-white)- Combined workspace chips: elevated translucent plate over main, not flat main gray-- Stage Manager (macOS only): host re-asserts min bounds while collapsed (permanent watchdog). The watchdog does not run on Windows/Linux, so no platform re-layers its own window unprompted (D447)+- Stage Manager (macOS only): host re-asserts min bounds while collapsed (permanent watchdog). The watchdog and temporary recovery pin are macOS-only; Windows/Linux bounds recovery stays at the normal window layer so switching to another app never leaves PI-Desktop above it (D447).## Destination pagesdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex ced0b4975..af6e8bcc6 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -10541,6 +10541,15 @@ This test plan spec is accepted when:- On macOS with Stage Manager, shrink or unfocus the PI window until width < 800 or height < 560.- Expect the shell to re-assert a Codex-like footprint (~1200×800, min 800×560 capped to the display work area) and keep restoring while still collapsed (not only during the first 20s after launch).- The recovery watchdog is macOS-only (D447). On Windows/Linux it must not run at all: the app must never re-layer or re-raise its own window unprompted. Focus another window, then confirm PI-Desktop stays behind it instead of jumping back to the top of the stack, and that a stacking check (`xprop -root _NET_CLIENT_LIST_STACKING`) never shows it returning to the top periodically.+- Windows regression: trigger tiny-bounds recovery through show, focus, or+ restore, then Alt+Tab to another app. PI-Desktop must stay behind that app+ immediately and after four seconds. Ordinary focus must not resize or raise it;+ hidden/minimized windows keep their state. Recovery must never enable+ always-on-top off macOS.+- Automated lifecycle coverage: `window-topmost-lifecycle.test.mjs` executes the+ production recovery handlers and watchdog with controlled time, including the+ unchanged macOS temporary pin and release. Native Alt+Tab validation remains+ a separate platform check.### US-UI-20 Dark floating composer box- Switch to dark theme on chat home.