Skip to content

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

fix(shell): run the Stage Manager bounds watchdog on macOS only

Scott3175c604b94c
diff --git a/apps/desktop/electron/main/bootstrap/window.ts b/apps/desktop/electron/main/bootstrap/window.ts
index a9c3e78e9..6c0b7981d 100644
--- a/apps/desktop/electron/main/bootstrap/window.ts
+++ b/apps/desktop/electron/main/bootstrap/window.ts
@@ -880,6 +880,18 @@ export async function createWindow({
clearInterval(boundsWatchdog);
return;
}
+ // Stage Manager recovery is macOS-only: the CG bounds helper it reads
+ // exists there alone (D039, D053, D083), and the minimum window size makes
+ // the tiny-bounds test unreachable elsewhere. On Windows/Linux this
+ // interval had nothing to recover and only cleared the window layer every
+ // 1.5s — and Mutter answers that repeated `_NET_WM_STATE` removal by
+ // raising the window (`meta_window_unmake_above` → `meta_window_raise`),
+ // so the app kept yanking itself above whatever the user had just focused
+ // (D447).
+ if (process.platform !== "darwin") {
+ clearInterval(boundsWatchdog);
+ return;
+ }
const cg = readCgBounds();
const electronBounds = window.getBounds();
if (!cg && cgHelperAvailable) missingCgStreak += 1;
diff --git a/apps/desktop/test/bounds-watchdog-platform.test.mjs b/apps/desktop/test/bounds-watchdog-platform.test.mjs
new file mode 100644
index 000000000..3976eb6d8
--- /dev/null
+++ b/apps/desktop/test/bounds-watchdog-platform.test.mjs
@@ -0,0 +1,67 @@
+/**
+ * The Stage Manager bounds watchdog is macOS-only (D447).
+ *
+ * Behavioral: the platform rule is the whole decision — macOS keeps the
+ * recovery watchdog, every other platform turns it off.
+ *
+ * Contract: `createWindow` clears the interval before it can read CG bounds or
+ * re-layer the window, so no platform other than macOS repeats a
+ * `setAlwaysOnTop(false)` that a window manager answers by raising the window.
+ */
+import assert from "node:assert/strict";
+import test from "node:test";
+import { register } from "node:module";
+import { dirname, join } from "node:path";
+import { fileURLToPath, pathToFileURL } from "node:url";
+import { readMainModule } from "./helpers/source-contracts.mjs";
+
+const here = dirname(fileURLToPath(import.meta.url));
+register(pathToFileURL(join(here, "helpers/ts-import-hooks.mjs")));
+
+const windowSource = await readMainModule("bootstrap/window.ts");
+
+/** The `boundsWatchdog` interval body, from its `setInterval` to its closing. */
+function watchdogBody() {
+ const start = windowSource.indexOf("const boundsWatchdog = setInterval(");
+ assert.notEqual(start, -1, "the bounds watchdog interval must exist");
+ const end = windowSource.indexOf("}, 1500);", start);
+ assert.notEqual(end, -1, "the watchdog must keep its 1500ms cadence");
+ return windowSource.slice(start, end);
+}
+
+test("the bounds watchdog turns itself off outside macOS", () => {
+ const body = watchdogBody();
+ const guard = body.indexOf('if (process.platform !== "darwin")');
+ assert.notEqual(guard, -1, "the watchdog must be gated on darwin");
+ // The guard has to clear the interval, or it keeps ticking forever.
+ const guardBlock = body.slice(guard, body.indexOf("const cg = readCgBounds();", guard));
+ assert.match(guardBlock, /clearInterval\(boundsWatchdog\);/);
+ assert.match(guardBlock, /return;/);
+ // And it has to run before the watchdog can touch the window layer, which is
+ // what Mutter answers by raising the window.
+ assert.ok(
+ guard < body.indexOf("setAlwaysOnTop(false)"),
+ "the platform guard must precede the always-on-top reset",
+ );
+ assert.ok(
+ guard < body.indexOf("ensureStableBounds(true)"),
+ "the platform guard must precede shelf recovery",
+ );
+ // macOS keeps the Stage Manager path intact (D039, D053, D083).
+ assert.match(body, /readCgBounds\(\)/);
+ assert.match(body, /ensureStableBounds\(true\)/);
+});
+
+test("no other platform path re-layers the window on a timer", () => {
+ // A repeating timer that clears the always-on-top layer is exactly what
+ // Mutter turns into a raise, so it may only exist behind the darwin guard.
+ const intervals = windowSource.split("setInterval(").slice(1);
+ for (const chunk of intervals) {
+ if (!chunk.includes("setAlwaysOnTop")) continue;
+ assert.match(
+ windowSource,
+ /if \(process\.platform !== "darwin"\) \{\s*clearInterval\(boundsWatchdog\);\s*return;\s*\}/,
+ "a window-layer timer must be macOS-only",
+ );
+ }
+});
diff --git a/docs/spec/04-ux/07-ui-design-system.md b/docs/spec/04-ux/07-ui-design-system.md
index 7b8ff2b31..9b64633be 100644
--- a/docs/spec/04-ux/07-ui-design-system.md
+++ b/docs/spec/04-ux/07-ui-design-system.md
@@ -1300,7 +1300,7 @@ Full component contract and usage rules: [08-component-spec.md §17](08-componen
- 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: host re-asserts min bounds while collapsed (permanent watchdog)
+- 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)
## Destination pages
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index e85f0133f..887791a65 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -7804,9 +7804,10 @@ This test plan spec is accepted when:
- Every visible composer control changes the active session, opens its menu, or
submits/aborts the current turn.
-### US-UI-19 Permanent Stage Manager bounds restore
+### US-UI-19 Permanent Stage Manager bounds restore (macOS only)
- On macOS with Stage Manager, shrink or unfocus the PI window until width < 1040 or height < 700.
- Expect the shell to re-assert a Codex-like footprint (~1200×800, min 1040×700) 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.
### US-UI-20 Dark floating composer box
- Switch to dark theme on chat home.
diff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.md
index ba9e36102..515fbc8db 100644
--- a/docs/spec/08-meta/decisions-log.md
+++ b/docs/spec/08-meta/decisions-log.md
@@ -86,6 +86,7 @@ This log freezes previously open questions into concrete decisions.
| D409 | Host-owned session collaboration messages | *(amended by D446)* **Amend ADR 0237 / ADR 0165 / ADR 0213: Rust host-core owns a durable session-collaboration ledger keyed by message id and real source/target Session IDs. Plugin-mediated `spawn`, `send`, `status`, `result`, and `cancel` operations use the reviewed desktop-control gateway; the sender is bound to the active plugin Agent tool invocation, target turns retain their existing configuration, and each delivery is claimed by its actual durable turn. Completion callbacks are durable, at-most-once, and reference the settled turn. Provenance is persisted with transcript rows and cannot be forged, stripped, or edited through regeneration. The additive schema v16 migration retains queued work across restart without unattended replay, applies permission ceilings and bounded autonomous hops, and keeps the existing Task family unchanged. See ADR 0239 and E2E-PLUGIN-session-orchestrator-real-workers.** | The plugin's prior create/prompt polling path could infer neither a durable turn outcome nor a safe bidirectional sender identity. A host-owned ledger makes delivery, provenance, callback, cancellation, and restart behavior auditable without restoring the withdrawn A2A protocol. |
| D410 | Independent session discovery and navigable collaboration projections | **Amend ADR 0239: add the reviewed read operation `session/collaboration/list`, bounded to 100 non-deleted Agent sessions and redacted to Session IDs, titles, status, updated time, readable provider/model labels, and bounded creation links. Extend the sidebar projection with readable model labels and at most eight created-session references. Render creator/created-session references as keyboard-focusable navigation buttons; independent sessions do not receive fabricated creator links. No renderer storage ownership or collaboration mutation boundary changes. See ADR 0240, E2E-SESSION-independent-top-level-communication, and E2E-SESSION-hover-card-model-and-links.** | Existing Session IDs were valid send targets but could be undiscoverable when they were not created by the plugin, while the hover card exposed only IDs and non-interactive provenance. A bounded host directory and navigable projection make durable sessions communicable and explainable without exposing transcripts or credentials. |
| D446 | Silent completion notices | **Amend D409 / ADR 0239 and the D193 silent-turn contract for issue #504: the first settled assistant reply to a current Host-resolved completion notice may end with no visible text and no tool call without silent-turn recovery or `EMPTY_MODEL_RESPONSE`. The exception is spent by that reply (silent, textual, or a tool batch), survives a provider retry of the same attempt, and is revoked once accepted user steering enters the model context. Only provenance Main resolved from the Host ledger enables it (`kind: completion`, the current target session, nonempty message and reply-to IDs); prompt text, plugin content, task/message deliveries, and restored history cannot. An accepted silent reply is persisted as an empty completed row but is excluded from runtime entries and model context, as a restored transcript already is. See the ADR 0239 amendment and E2E-SESSION-completion-notice-allows-silence.** | The completion prompt already says no acknowledgement is needed, yet the runtime retried the silence and reported a failure after a task that had succeeded (issue #504). Bounding the exception to one ledger-verified reply keeps ordinary prompts, deliveries, tool work, and user steering under D193, and keeping the empty reply out of context avoids a provider rejecting the next request. |
+| D447 | Stage Manager bounds watchdog is macOS-only | **The permanent 1.5s `boundsWatchdog` in `bootstrap/window.ts` runs on macOS alone; every other platform clears the interval on its first tick. Its two inputs are macOS-only (the `/tmp/pi-window-bounds` CG helper, and a "window smaller than 500x400" test the 1040x700 minimum window size makes unreachable), so elsewhere it could never recover anything and only called `window.setAlwaysOnTop(false)` forever. On Linux/X11 that repeats a `_NET_WM_STATE` removal, and Mutter answers it by raising the window (`meta_window_unmake_above` calls `meta_window_raise` unconditionally), so the app yanked itself back to the top of the stack about 1.5s after the user focused another window even though `_NET_WM_STATE` never carried `_NET_WM_STATE_ABOVE`. macOS Stage Manager recovery is unchanged. See D039, D053, D083 and US-UI-19.** | A window that re-raises itself over whatever the user just focused is not usable, and the interval had no purpose off macOS; the fix removes the message instead of teaching each platform to tolerate it. |
| D413 | Skill market public-HTTPS catalog fetch | **Additive: Settings → Skills Market discovers SKILL.md catalogs in Electron main under a shared public-HTTPS policy (syntactic public host + DNS classification + per-hop redirect re-validation). The renderer does not fetch. Install remains `skills.create`. Catalog ids match host `valid_capability_id`. Expanded documents over 128 KiB are refused. Builtin titles are English. See ADR 0243, E2E-SKILL-MARKET-*, issue #287.** | Community skill discovery needs main-process egress without a plugin-marketplace host allowlist, and copied classifiers would collide with the MCP market. |
| D421 | Native Pi session continuation | **Amend baseline D007: discover Pi v3 sessions as source-discriminated projections and continue them through coding-agent `AgentSession`/`SessionManager` against their canonical JSONL. Rust remains authoritative for Desktop SQLite/transcripts. Native continuation requires exact saved provider/auth, project trust, canonical path/header identity, and a cooperative lease plus byte/leaf validation; failures remain browseable/read-only. First slice excludes native rename/delete/move/revisions/Plan/Goal/queue/collaboration; the 2026-09-14 ADR 0254 amendment adds native fork with exact stream re-keying and inode-tracked publication; the side-chat panel it added is retired by ADR 0268. See ADR 0254 and E2E-SESSION-native-pi-*.** | Importing a flattened copy cannot preserve Pi's tree or make later Desktop turns visible to Pi Web. |
| D412 | Delta-only coalesced streaming updates | **Amend the local `message_update` contract: append-only streaming frames carry `stream: delta` plus `deltaText`/`deltaThinking` (and reset flags) without growing `content`/`thinking`. Runtime coalesces those frames every 16ms and flushes before semantic boundaries. AgentHost, inflight checkpoints, and the renderer apply deltas; `message_start`/`message_end` remain full snapshots. Transcript activity parts keep object identity when only the tail token changes. Protocol version stays 11. See ADR 0242, E2E-STREAM-long-turn-keeps-realtime, and issue #299.** | Each token re-serialized the full assistant snapshot across sidecar, AgentHost, and IPC, so a long turn cost O(n²) bytes and backlogged later short chunks. |
diff --git a/docs/zh-CN/spec/04-ux/07-ui-design-system.md b/docs/zh-CN/spec/04-ux/07-ui-design-system.md
index 9afb5abf7..c89580103 100644
--- a/docs/zh-CN/spec/04-ux/07-ui-design-system.md
+++ b/docs/zh-CN/spec/04-ux/07-ui-design-system.md
@@ -1169,7 +1169,7 @@ Linux 保留淡入淡出和滑动退出。
- 浮动输入框板:Codex 升高主线 (`#212121f5` / `color-mix(gray-800 96%, transparent)`) 和标准升高突出线 (`0 0 0 .5px` 笔画 + `0 3px 7.5px #0000000a` + `0 0 20px #0000000d`);没有更重的夜间专用电梯
- 轻型工作空间芯片胶囊:升高的灰色 `#f4f4f4`(不是纯白底白字)
- 组合工作区芯片:在主板上升高半透明板,而不是平坦的主灰色
-- 舞台管理器:主机在折叠时重新声明最小边界(永久看门狗)
+- 舞台管理器(仅 macOS):主机在折叠时重新声明最小边界(永久看门狗)。该看门狗不在 Windows/Linux 上运行,因此没有任何平台会自行重新调整自己窗口的层级(D447)
## 目标页面
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 b7735d795..383c38f32 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
@@ -5286,9 +5286,10 @@ IPC 请求无法关闭。
-### US-UI-19 永久舞台管理器边界恢复
+### US-UI-19 永久舞台管理器边界恢复(仅 macOS)
- 在使用 Stage Manager 的 macOS 上,缩小或取消聚焦 PI 窗口,直到宽度 < 1040 或高度 < 700。
- 预计外壳会重新声明类似 Codex 的足迹(~1200×800,最小 1040×700)并在仍然折叠的情况下继续恢复(不仅在发射后的前 20 秒内)。
+- 该恢复看门狗仅限 macOS(D447)。在 Windows/Linux 上它必须完全不运行:应用绝不能在无人操作时重新调整或抬升自己的窗口。聚焦其他窗口,确认 PI-Desktop 留在其后方而不是跳回窗口栈顶端,并且栈序检查(`xprop -root _NET_CLIENT_LIST_STACKING`)不会显示它周期性回到顶端。
### US-UI-20 深色浮动编辑框
- 在聊天主页切换到深色主题。
diff --git a/docs/zh-CN/spec/08-meta/decisions-log.md b/docs/zh-CN/spec/08-meta/decisions-log.md
index 9a2577b83..1874be648 100644
--- a/docs/zh-CN/spec/08-meta/decisions-log.md
+++ b/docs/zh-CN/spec/08-meta/decisions-log.md
@@ -89,6 +89,7 @@
| D409 | 宿主拥有的会话协作消息 | *(由 D446 修订)* **修订 ADR 0237 / ADR 0165 / ADR 0213:Rust host-core 拥有以消息 id 和真实源/目标 Session ID 为键的持久会话协作 ledger。插件驱动的 `spawn`、`send`、`status`、`result` 和 `cancel` 使用已审查的 desktop-control 网关;发送者绑定当前插件 Agent 工具调用,目标回合保留原有配置,每条投递由实际持久回合认领。完成回调持久化且最多一次,并引用已结算回合。来源信息随转录行持久化,不能在重生成中伪造、剥离或编辑。增量架构 v16 迁移在重启后保留排队工作但不无人值守重放,执行权限上限和有界自主跳数,同时保持既有 Task 系列不变。见 ADR 0239 与 E2E-PLUGIN-session-orchestrator-real-workers。** | 插件之前的创建/提示轮询路径既无法推断持久回合结果,也无法安全确认双向发送者身份。宿主拥有的 ledger 让投递、来源、回调、取消和重启行为可审计,同时不恢复已撤回的 A2A 协议。 |
| D410 | 独立会话发现与可导航协作投影 | **修订 ADR 0239:新增经审查的 `session/collaboration/list` 读取操作,限制为最多 100 个未删除 Agent 会话,并只返回 Session ID、标题、状态、更新时间、可读 provider/model 标签和有界创建关系。侧边栏投影增加可读模型标签和最多八个已创建会话引用。创建者/已创建会话引用渲染为可键盘聚焦的导航按钮;独立会话不伪造创建者链接。不改变渲染器存储归属或协作写入边界。见 ADR 0240、E2E-SESSION-independent-top-level-communication 和 E2E-SESSION-hover-card-model-and-links。** | 现有 Session ID 虽然是有效发送目标,但未由插件创建的会话可能不可发现;hover 卡片也只暴露 ID,来源信息不可交互。有界 host 目录和可导航投影让持久会话可通信、可解释,同时不暴露转录或凭据。 |
| D446 | 完成通知允许静默 | **针对 issue #504 修订 D409 / ADR 0239 及 D193 静默回合契约:对当前由 Host 账本解析的完成通知,其第一条结算的 assistant 回复可以没有可见文本也没有工具调用,而不触发静默回合恢复或 `EMPTY_MODEL_RESPONSE`。该例外由这条回复消耗(无论静默、有文本还是工具批次),在同一次尝试的 provider 重试中保留,并在被接受的用户 steering 进入模型上下文后立即撤销。只有 Main 从 Host 账本解析出的来源信息才能开启它(`kind: completion`、目标为当前会话、消息 ID 与回复目标 ID 非空);提示文本、插件内容、task/message 投递和恢复的历史都不能。被接受的静默回复仍以空的已完成行持久化,但不进入运行时条目和模型上下文,与恢复转录的处理一致。见 ADR 0239 修订段与 E2E-SESSION-completion-notice-allows-silence。** | 完成提示已经声明无需确认,运行时却重试这次静默并在任务已成功后报错(issue #504)。把例外限定在一条经账本校验的回复上,让普通提示、投递、工具工作和用户 steering 继续遵守 D193;空回复不进入上下文,避免下一次请求被 provider 拒绝。 |
+| D447 | 舞台管理器边界看门狗仅限 macOS | **`bootstrap/window.ts` 中常驻的 1.5 秒 `boundsWatchdog` 只在 macOS 运行;其他平台在第一次 tick 时即清除该定时器。它的两个输入都只存在于 macOS(`/tmp/pi-window-bounds` CG 辅助程序,以及“窗口小于 500×400”这一被 1040×700 最小窗口尺寸变得不可达的判断),因此在别处它什么也恢复不了,只会永远调用 `window.setAlwaysOnTop(false)`。在 Linux/X11 上这会重复发送 `_NET_WM_STATE` 移除消息,而 Mutter 收到后会抬升窗口(`meta_window_unmake_above` 无条件调用 `meta_window_raise`),于是用户刚聚焦其他窗口约 1.5 秒后,应用就自己跳回窗口栈顶端——即使 `_NET_WM_STATE` 从未包含 `_NET_WM_STATE_ABOVE`。macOS 的舞台管理器恢复行为不变。见 D039、D053、D083 与 US-UI-19。** | 一个会反复盖到用户刚聚焦窗口之上的窗口无法使用,而该定时器在 macOS 之外毫无用途;修复选择消除这条消息,而不是让每个平台去容忍它。 |
| D413 | 技能市场公网 HTTPS 目录拉取 | **增量:设置 → 技能市场由 Electron 主进程按共享公网 HTTPS 策略发现 SKILL.md(公网主机语法 + DNS 分类 + 逐跳 redirect)。渲染层不发网。安装仍走 `skills.create`。目录 id 与 host `valid_capability_id` 对齐。展开后超过 128 KiB 拒绝写入。内置标题为英文。见 ADR 0243、E2E-SKILL-MARKET-*、issue #287。** | 社区技能发现需要主进程出网,且不能复用插件市场的主机允许列表;复制分类器会与 MCP 市场撞名。 |
| D421 | Native Pi 会话续接 | **修订基线 D007:把 Pi v3 会话发现为按来源区分的投影,并通过 coding-agent `AgentSession`/`SessionManager` 针对其规范 JSONL 继续会话。Rust host-core 仍是 Desktop SQLite/Desktop 成绩单的权威;原生回合不进入 Desktop outbox,也不产生导入副本。原生续接要求精确的已存 provider/auth、项目信任、规范路径/头身份,以及带字节/叶节点校验的协作租约;失败保持可浏览/只读。首片不含原生 rename/delete/move/revisions/Plan/Goal/queue/collaboration;2026-09-14 的 ADR 0254 修订加入原生 fork,含精确流重键与 inode 跟踪的发布;该修订加入的侧边聊天面板已由 ADR 0268 移除。见 ADR 0254 与 E2E-SESSION-native-pi-*。** | 导入扁平副本无法保留 Pi 的树结构,也无法让之后 Desktop 的回合对 Pi Web 可见。 |
| D412 | 仅增量且合并的流式更新 | **修订本地 `message_update` 契约:追加型流式帧携带 `stream: delta` 以及 `deltaText`/`deltaThinking`(和 reset 标志),不再附带增长中的 `content`/`thinking`。运行时每 16ms 合并这些帧,并在语义边界前立即 flush。AgentHost、进行中检查点和渲染器应用增量;`message_start`/`message_end` 仍是完整快照。仅尾部 token 变化时,转录活动 part 保持对象身份。协议版本仍为 11。见 ADR 0242、E2E-STREAM-long-turn-keeps-realtime 和 issue #299。** | 每个 token 都在 sidecar、AgentHost 和 IPC 上重新序列化完整助手快照,长回合接近 O(n²) 字节并让后续短块排队变慢。 |