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): keep the border suppressed through activation changes
Linuxdazhao2b52999879a6
diff --git a/apps/desktop/electron/main/window-native-snap.ts b/apps/desktop/electron/main/window-native-snap.tsindex bcbb100f3..36f13b54d 100644--- a/apps/desktop/electron/main/window-native-snap.ts+++ b/apps/desktop/electron/main/window-native-snap.ts@@ -27,6 +27,8 @@ export async function installWindowsNativeSnap(};const refresh = () => { void apply().catch(reportFailure); };window.on("show", refresh);+ window.on("focus", refresh);+ window.on("blur", refresh);window.on("restore", refresh);window.on("maximize", refresh);window.on("unmaximize", refresh);@@ -34,6 +36,8 @@ export async function installWindowsNativeSnap(window.once("closed", () => {disposed = true;window.removeListener("show", refresh);+ window.removeListener("focus", refresh);+ window.removeListener("blur", refresh);window.removeListener("restore", refresh);window.removeListener("maximize", refresh);window.removeListener("unmaximize", refresh);diff --git a/apps/desktop/test/window-native-snap.test.mjs b/apps/desktop/test/window-native-snap.test.mjsindex 2ddbe62df..29a0cb6f6 100644--- a/apps/desktop/test/window-native-snap.test.mjs+++ b/apps/desktop/test/window-native-snap.test.mjs@@ -29,7 +29,7 @@ test("native snap is ready before startup continues and survives window transitiparams: { nativeHandle: "305419896", ownerPid: process.pid },timeout: 5_000,});- for (const event of ["show", "maximize", "unmaximize", "restore"]) {+ for (const event of ["show", "focus", "blur", "maximize", "unmaximize", "restore"]) {const count = f.calls.length;f.window.emit(event);await controller.flush();@@ -64,7 +64,7 @@ test("closing a window cancels queued native mutations and removes its subscriptf.window.emit("closed");await controller.flush();assert.equal(f.calls.length, count);- for (const event of ["show", "maximize", "unmaximize", "restore", "leave-full-screen"]) {+ for (const event of ["show", "focus", "blur", "maximize", "unmaximize", "restore", "leave-full-screen"]) {assert.equal(f.window.listenerCount(event), 0);}});diff --git a/docs/adr/windows-native-snap-without-frame-insets.md b/docs/adr/windows-native-snap-without-frame-insets.mdindex 7606095fd..3fb39e6df 100644--- a/docs/adr/windows-native-snap-without-frame-insets.md+++ b/docs/adr/windows-native-snap-without-frame-insets.md@@ -28,12 +28,16 @@ HWND owner before mutation. Share this validation with the corner RPC. No rawhandle or new channel is exposed to renderer, preload, plugins, or remote clients.Main awaits initial application before showing the window and reapplies after-show, restore, maximize, unmaximize, and leaving fullscreen. Active fullscreen+show, focus/blur, restore, maximize, unmaximize, and leaving fullscreen. Active fullscreenis excluded; closing cancels queued work and subscriptions. Errors are loggedwithout preventing startup, and later transitions can retry with the currentHost. Existing minimum sizes, persistence, resizing, corners, fullscreeninterlocks, and maximize/work-area correction remain unchanged.+Activation changes also refresh the border hint: DWM requires applications to+maintain border appearance across activation, and replay exposed a painted rim+after focus transfer when only show/restore events refreshed it.+## Consequences`test:e2e:window-snap` exercises the production Main service and compiled Host indiff --git a/docs/spec/04-ux/07-ui-design-system.md b/docs/spec/04-ux/07-ui-design-system.mdindex 51c37de43..bda93063a 100644--- a/docs/spec/04-ux/07-ui-design-system.md+++ b/docs/spec/04-ux/07-ui-design-system.md@@ -6,6 +6,8 @@ The main window retains Electron's `frame: false` / `thickFrame: false` clientlayout. Host restores the shell's native snap/caption styles and suppressesWindows 11's DWM outline. Keyboard and physical titlebar-drag snapping remainOS-owned; left/right/bottom pixels remain renderer-owned without native insets.+Focus and blur reapply the native border hint without moving, sizing or+activating the window; fullscreen keeps its existing exclusion.Existing minimum sizes, corner preferences, fullscreen and work-area maximizecorrection remain in effect. Hover Snap Layouts on the custom maximize buttonis not provided by this style repair. Seediff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 78e845d99..8227e3598 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -14145,6 +14145,8 @@ baseline/candidate JSON, timestamped logs, stdout/stderr and normal/snapped/maximized/restored client PNGs. Upload artifacts even on failure; excludeprofiles and redact runtime/user paths. See[native replay procedure](../../project/windows-native-snap-replay.md).+Repeat pixel checks after transferring focus away and back, including a+PowerShell-launched fixture; activation must not restore the native outline.- **Preconditions**: PI-Desktop is open in a normal, non-maximized window onmacOS, Windows, or Linux. On Windows, the left, bottom, and right rim mustdiff --git a/scripts/e2e/fixtures/window-snap/main.cjs b/scripts/e2e/fixtures/window-snap/main.cjsindex df838f962..889b08469 100644--- a/scripts/e2e/fixtures/window-snap/main.cjs+++ b/scripts/e2e/fixtures/window-snap/main.cjs@@ -19,10 +19,17 @@ let corners;let quitting = false;const logger = { app: (...args) => console.error(...args) };const resolve = (name) => path.isAbsolute(name) ? name : path.join(root, name);-const publish = (name, value) => {+const publish = async (name, value) => {const destination = path.join(root, name);fs.writeFileSync(destination + ".tmp", JSON.stringify(value));- fs.renameSync(destination + ".tmp", destination);+ const deadline = performance.now() + 5000;+ for (;;) {+ try { await fs.promises.rename(destination + ".tmp", destination); return; }+ catch (error) {+ if (!["EPERM", "EBUSY", "EACCES"].includes(error.code) || performance.now() >= deadline) throw error;+ await new Promise((done) => setTimeout(done, 25));+ }+ }};app.whenReady().then(async () => {@@ -75,7 +82,7 @@ app.whenReady().then(async () => {scaleFactor: screen.getDisplayMatching(window.getBounds()).scaleFactor });const flush = async () => { if (snap) await snap.flush(); if (corners) await corners.flush(); };await flush();- publish("ready.json", snapshot());+ await publish("ready.json", snapshot());let active = false;timer = setInterval(async () => {const file = path.join(root, "command.json");@@ -96,7 +103,7 @@ app.whenReady().then(async () => {if (command.action === "fullscreen") setWindowFullScreen(window, command.value, true);await new Promise((done) => setTimeout(done, 500));await flush();- publish("state.json", { ...snapshot(), id: command.id });+ await publish("state.json", { ...snapshot(), id: command.id });} catch (error) {fs.writeFileSync(path.join(root, "fixture-error.txt"), String(error.stack || error));} finally { active = false; }diff --git a/scripts/e2e/probe-window-snap.cs b/scripts/e2e/probe-window-snap.csindex 3efe6b92c..915450f14 100644--- a/scripts/e2e/probe-window-snap.cs+++ b/scripts/e2e/probe-window-snap.cs@@ -35,7 +35,6 @@ public static class WindowSnapProbe {[DllImport("gdi32.dll")] static extern int GetDeviceCaps(IntPtr dc,int index);[DllImport("dwmapi.dll")] static extern int DwmIsCompositionEnabled(out bool enabled);[DllImport("dwmapi.dll")] static extern int DwmGetWindowAttribute(IntPtr h, int attribute, out SnapRect r, int size);- [DllImport("dwmapi.dll",EntryPoint="DwmGetWindowAttribute")] static extern int DwmGetColor(IntPtr h, int attribute, out uint color, int size);static readonly string Root = AppDomain.CurrentDomain.BaseDirectory;static readonly JavaScriptSerializer Json = new JavaScriptSerializer();static readonly string RunId = Guid.NewGuid().ToString("N");@@ -67,15 +66,13 @@ public static class WindowSnapProbe {static SnapRect Rect(IntPtr window) { SnapRect rect; Check(GetWindowRect(window, out rect), "read window bounds"); return rect; }static Dictionary<string, object> Bounds(IntPtr window) {var r = Rect(window); SnapRect client, visible; var origin = new SnapPoint();- uint borderColor;int borderResult=DwmGetColor(window,34,out borderColor,4);Check(GetClientRect(window, out client) && ClientToScreen(window, ref origin), "read client bounds");Check(DwmGetWindowAttribute(window, 9, out visible, 16) >= 0, "read DWM visible frame");return new Dictionary<string, object> {{"x",r.Left},{"y",r.Top},{"width",r.Right-r.Left},{"height",r.Bottom-r.Top},{"clientX",origin.X},{"clientY",origin.Y},{"clientWidth",client.Right},{"clientHeight",client.Bottom},{"visibleX",visible.Left},{"visibleY",visible.Top},{"visibleWidth",visible.Right-visible.Left},{"visibleHeight",visible.Bottom-visible.Top},- {"style","0x"+GetWindowLong(window,-16).ToString("X8")},- {"borderColorResult",borderResult},{"borderColor","0x"+borderColor.ToString("X8")}+ {"style","0x"+GetWindowLong(window,-16).ToString("X8")}};}static bool IsRect(IntPtr window, int x, int y, int width, int height) {diff --git a/scripts/e2e/run-window-snap.ps1 b/scripts/e2e/run-window-snap.ps1index cd3dde1be..7ea1bfea6 100644--- a/scripts/e2e/run-window-snap.ps1+++ b/scripts/e2e/run-window-snap.ps1@@ -21,6 +21,12 @@ function Write-Json($path, $value) {function Write-RunnerLog($message) {[IO.File]::AppendAllText((Join-Path $ArtifactDirectory 'runner.log'), [DateTime]::UtcNow.ToString('o') + ' ' + $message + [Environment]::NewLine)}+function Get-Sha256($path) {+ $stream = [IO.File]::OpenRead($path)+ $hash = [Security.Cryptography.SHA256]::Create()+ try { return [BitConverter]::ToString($hash.ComputeHash($stream)).Replace('-', '').ToLowerInvariant() }+ finally { $hash.Dispose(); $stream.Dispose() }+}try {Write-RunnerLog 'checking source and desktop metadata'if (-not $source.clean) { throw 'Native acceptance requires a clean source checkout.' }@@ -30,8 +36,8 @@ try {$options.hostBinary = Resolve-Binary $options.hostBinary$options.electronBinary = Resolve-Binary $options.electronBinaryWrite-RunnerLog 'hashing native binaries'- $summary.hostSha256 = (Get-FileHash $options.hostBinary -Algorithm SHA256).Hash.ToLowerInvariant()- $summary.electronSha256 = (Get-FileHash $options.electronBinary -Algorithm SHA256).Hash.ToLowerInvariant()+ $summary.hostSha256 = Get-Sha256 $options.hostBinary+ $summary.electronSha256 = Get-Sha256 $options.electronBinaryNew-Item -ItemType Directory $scratch | Out-NullWrite-RunnerLog 'compiling native probe'Add-Type -Path (Join-Path $root 'probe.cs') -OutputAssembly (Join-Path $scratch 'probe.exe') -OutputType WindowsApplication -ReferencedAssemblies System.dll,System.Drawing.dll,System.Windows.Forms.dll,System.Web.Extensions.dll@@ -103,7 +109,7 @@ try {if (Test-Path (Join-Path $scratch 'probe.exe')) { Copy-Item (Join-Path $scratch 'probe.exe') $ArtifactDirectory }$hashes = Get-ChildItem $ArtifactDirectory -Recurse -File | Where-Object Name -ne 'active-directory.txt' | ForEach-Object {$relative = $_.FullName.Substring($ArtifactDirectory.Length + 1).Replace('\', '/')- (Get-FileHash $_.FullName -Algorithm SHA256).Hash.ToLowerInvariant() + ' ' + $relative+ (Get-Sha256 $_.FullName) + ' ' + $relative}[IO.File]::WriteAllLines((Join-Path $ArtifactDirectory 'SHA256SUMS'), [string[]]$hashes)Remove-Item (Join-Path $ArtifactDirectory 'active-directory.txt') -ErrorAction SilentlyContinue