Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
chore: merge latest main into extension lifecycle fix
Jack1e9c23d131f4
diff --cc docs/spec/06-delivery/04-e2e-test-plan.mdindex 47e63b1b8,ba3dbb65d..63a79429d--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@@ -14566,28 -14568,20 +14568,45 @@@ artifact identity and independent revie`docs/project/hosted-search-contract-verification.md`. Never record privateconversation content or credentials. A skipped test remains NOT RUN, not PASS.+### E2E-HOOKS-cancel-and-dispose++- **Issue #816 extension:** Cancel a command while its prompt is visible and+ verify the real renderer removes the dialog, no later prompts or exec occur,+ and the next command/turn succeeds. The trusted-extension Electron driver+ checks the DOM via CDP. Runner tests cover long commands, stopped context waits,+ tool cancellation and late updates, detached header payloads and recovery;+ process tests use a real parent/child tree with readiness synchronization.++- **Preconditions:** An isolated Desktop profile, deterministic local provider,+ and a trusted plugin with a waiting preflight handler.+- **Steps:** Start a prompt; stop while the handler waits; release the old+ handler; send another prompt. Repeat with runtime disposal. Load another+ fixture with stalled startup/shutdown handlers and a deferred event.+- **Expected:** No provider request starts for the stopped/disposed prompt;+ the next prompt completes. Late results cannot restart work. Shutdown runs+ once, waits time out per handler, and deferred registrations are diagnosed+ without disabling supported handlers.+- **Specs:** 07-plugins/16 §6.+- **Acceptance:** Responsive cancellation and bounded extension lifecycle waits.+- **Milestone:** Hooks P0.+- **Status:** Runner and real Runtime/local-HTTP integration automated in+ `extensions/runner.test.ts` and `extensions/runtime-lifecycle.test.ts`.+ The trusted-extension Electron driver exercises the Stop path through the+ real renderer via CDP and records the visible and retired dialog states.+ ## Composer command source, manual compaction, and empty transcript reads (#795)++ **Scope:** the composer's slash dispatch, the manual compaction RPC, and the+ renderer's durable transcript reads. No real model or provider is contacted.++ | Scenario | Expected |+ | --- | --- |+ | `/compact` typed while `composer/commands` fails | The submission is refused with `chat.slashCommandSourceUnavailable`, the draft survives, and no prompt reaches the session. The failed read is not cached, so the next submit retries it. |+ | A warm command source | A builtin still dispatches locally, while a template and an unknown alias still travel as prompt text. |+ | A manual compaction that outlives its transport deadline | The host re-reads the durable compaction record and reports success when a new checkpoint landed, logs the mismatch, and rethrows the timeout when none did. A verdict the sidecar reported itself is never reconciled. |+ | A transcript window that reads empty for a session with history | The selection re-reads once, keeps the snapshot the user already has, and otherwise reports `chat.sessionTranscriptEmpty`; the empty page is never cached, so hover prefetch cannot re-serve it. |++ **Automation:** `node --test apps/desktop/test/slash-command-source.test.mjs`,+ `node --test apps/desktop/test/session-transcript-empty-read.test.mjs`,+ `node --test apps/desktop/test/plugin-timeout-budgets.test.mjs`,+ `pnpm --filter @pi-desktop/shared test`, and+ `pnpm --filter @pi-desktop/host-runtime test`.diff --cc docs/spec/08-meta/decisions-log.mdindex 5b53c9982,0c590d35a..8ececefa8--- a/docs/spec/08-meta/decisions-log.md+++ b/docs/spec/08-meta/decisions-log.md@@@ -6596,16 -6596,82 +6596,95 @@@ that was sitting at the bottom — incl`apps/desktop/test/image-generation-default.test.mjs`, with`provider-model-config.test.mjs` asserting the add branch consults them.+## 2026-09-21 — Bound Desktop trusted-extension lifecycle waits++- Apply the existing 30-second handler budget to notification, startup and+ shutdown handlers as well as result handlers; module loading and factory+ initialization each use the same budget. This changes previously unbounded+ waits, including event handlers waiting for a UI answer.+- Abort retires current waits; disposal rejects new dispatches and runs shutdown+ once. Late settlements cannot supply results to the retired dispatch. Existing+ fail-open error handling, result folding, plugin ownership and permissions+ remain unchanged. In-process code is not forcibly terminated.+- Deferred events remain registrable and now appear in existing diagnostics.+ See `07-plugins/16-trusted-extensions.md` §6 and+ `E2E-HOOKS-cancel-and-dispose`.+ ## 2026-09-22 — An unreadable command source refuses a slash submission (D613, issue #795)++ - Composer send-time resolution read the merged command list and swallowed a+ failure as `null`, which the submit path could not tell apart from "no such+ command". `/compact` typed while that IPC read failed was therefore sent to the+ model as literal prompt text, and the model acted on it as an instruction.+ - Resolution now answers with three outcomes instead of one nullable value:+ resolved (builtin/plugin/extension dispatch), unknown (templates, aliases, and+ id-less entries continue as prompt text), and unavailable. Unavailable refuses+ the submission, keeps the draft, and shows+ `chat.slashCommandSourceUnavailable`. The failed read leaves the TTL cache+ cold, so the next submit retries it; a warm cache still resolves through a+ source blip.+ - The refusal is fail-closed on purpose: only the command source can say whether+ `/name` is a control command, so while it cannot be read a `name` that looks+ like plain text is refused rather than guessed. Templates and genuinely unknown+ aliases keep the old prompt path. Pinned by+ `apps/desktop/test/slash-command-source.test.mjs` and+ `03-runtime/01-ipc-protocol.md` §13c.++ ## 2026-09-22 — A manual compaction has its own transport deadline and a durable verdict (D614, issue #795)++ - `agent.compact` is a blocking RPC that spends a whole model summary request+ inside the sidecar: pi serializes the conversation, streams the summary, and+ retries a transient failure. It ran under the flat 130s transport default, so a+ ~158s compaction on an 888KB context ended as `sidecar RPC timeout` while the+ sidecar kept working and persisted the checkpoint — the user was told the+ compaction failed, and the next turn proved it had succeeded.+ - The deadline is now derived from the ceilings the sidecar actually enforces:+ one stream watchdog (180s) per attempt, `1 + 3` attempts, the 2s/4s/8s retry+ backoff, and transport slack — `AGENT_COMPACT_RPC_TIMEOUT_MS`, deliberately+ per-method rather than a wider global default.+ - Either host path (Electron `agentCompact` IPC and `RuntimeService.compact`)+ also stops treating a transport timeout as the sidecar's verdict: it re-reads+ the durable `session.compaction` record and reports success when a new+ checkpoint landed, logs the mismatch, and rethrows the timeout otherwise. A+ verdict the sidecar reported itself is never reconciled. Pinned by+ `packages/host-runtime/src/runtime-service.test.ts`,+ `packages/shared/src/protocol.test.ts`,+ `apps/desktop/test/plugin-timeout-budgets.test.mjs`, and+ `03-runtime/01-ipc-protocol.md` §5.4.++ ## 2026-09-22 — An empty transcript read is retried and never cached (D615, issue #795)++ - The renderer treated every durable `session.get` window as the truth, and+ cached it. A window that came back empty for a session with thousands of+ messages — the host answers such a read from a transcript file it may be+ rewriting — was stored as an empty snapshot, hover prefetch re-served it, and+ the pane stayed blank until the app restarted. Nothing distinguished a failed+ or stale read from an empty conversation, and no path retried one.+ - A read is now judged against the session's own count: zero messages for a+ session the sidebar counts as having history triggers one more read, then keeps+ the snapshot the user already has, and otherwise reports+ `chat.sessionTranscriptEmpty`. The empty page is never written to the+ transcript cache, so a hover prefetch cannot poison every later open.+ - This is a defense, not the host-side root cause: the transcript rewrite is the+ reporter's 0.15.1 storage layout, and the read side still answers "session+ exists, no messages" instead of reporting an unreadable transcript. See+ `04-ux/09-interaction-patterns.md` §Session isolation across tabs.++ ## 2026-09-22 — A renderer that never reaches its first state gets a bounded surface and a quit channel (D616)++ - The renderer's startup had no timeout of its own: `bootstrap()` either+ publishes the initial state or nothing, so one read that never settled left the+ window on the boot surface with no menu, no data, and nothing to act on except+ force-quitting the process (issue #831). The renderer now watches its own wait.+ `STARTUP_SLOW_HINT_MS` (30s) adds logs, diagnostics, and quit to the boot+ surface without calling the boot a failure; `STARTUP_STALLED_MS` (180s) turns it+ into the recovery surface, which also offers a retry that re-runs `bootstrap()`.+ - Both bounds sit above the main↔host RPC ceiling (`DEFAULT_RPC_TIMEOUT_MS`,+ 130s), so a slow but successful boot is never read as a failure, and the+ watchdog never cancels the startup it watches: a boot that finishes replaces the+ surface with the shell. The recovery surface replaces the splash (exactly one+ boot surface is mounted), and the renderer-drawn window controls stay above it,+ so a frameless Windows/Linux window can always be closed.+ - The renderer gains the quit channel `pi-desktop/app/quit` (`api.quitApp()`),+ whose handler calls `app.quit()` exactly like the Quit menu item, so the ordered+ shutdown, the confirmation dialog, and the close behavior stay the ones the app+ already has. See `03-runtime/07-process-model.md` §3 and E2E-076.diff --cc docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex 31d466579,aa612a8be..c1e8260b8--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@@ -8675,21 -8677,19 +8677,37 @@@ the latest destination. These assertion**证据:** 记录构建和测试退出码、基线 SHA、依赖版本、产物标识及独立评审,报告位于`docs/project/hosted-search-contract-verification.md`。不得记录真实会话或凭据。未执行明确标为 NOT RUN,不得标为 PASS。+### E2E-HOOKS-cancel-and-dispose++- **#816 扩展验收:** 命令弹窗显示期间 Stop,真实渲染层移除弹窗,后续弹窗和 exec+ 不再发生,下一命令或回合正常。Electron 驱动通过 CDP 检查 DOM;Runner 测试覆盖+ 长命令、上下文等待取消、工具进度退役及头部副本;进程测试通过就绪信号同步真实父子进程。++- **前置条件:** 隔离 Desktop 配置、本地确定性模型,以及含等待型请求前处理器的可信插件。+- **步骤:** 发送消息,在处理器等待时停止,释放旧处理器后再次发送。另测等待时销毁+ Runtime,并加载启动/关闭挂起以及注册未接通事件的夹具。+- **预期:** 被停止或销毁的请求不调用模型,后续消息正常完成。迟到结果不能重启工作。+ 关闭只执行一次,各处理器等待有界,未接通事件产生诊断但不禁用正常处理器。+- **规范:** 07-plugins/16 §6。+- **验收:** 取消及时生效,扩展生命周期等待有界。+- **里程碑:** Hooks P0。+- **状态:** Runner 与真实 Runtime/本地 HTTP 集成通过+ `extensions/runner.test.ts`、`extensions/runtime-lifecycle.test.ts` 自动验证。+ 可信扩展 Electron 驱动通过 CDP 在真实渲染层执行 Stop 路径,并记录弹窗显示和+ 退役后的状态。+ ## Composer 指令源、手动压缩与空记录读取(#795)++ **范围:** composer 的斜杠分发、手动压缩 RPC,以及渲染层的持久化记录读取。不调用真实模型或+ 提供商。++ | 场景 | 必须观察到的结果 |+ | --- | --- |+ | `composer/commands` 失败时输入 `/compact` | 提交被拒绝并显示 `chat.slashCommandSourceUnavailable`,草稿保留,没有任何提示词进入会话。失败的读取不入缓存,因此下一次发送会重试。 |+ | 指令源缓存仍热 | 内置指令仍在本地分发;模板与未知别名仍走提示词路径。 |+ | 手动压缩超过其传输超时 | 宿主重新读取持久化压缩记录:发现新检查点已落盘就报告成功并记录该不一致,未落盘则原样抛出超时。sidecar 自己报告的判定绝不被改写。 |+ | 有历史的会话读到空记录窗口 | 选择流程再读一次,随后保留用户已有的快照,否则显示 `chat.sessionTranscriptEmpty`;这类空页绝不入缓存,因此悬停预取不会反复提供它。 |++ **自动化:** `node --test apps/desktop/test/slash-command-source.test.mjs`、+ `node --test apps/desktop/test/session-transcript-empty-read.test.mjs`、+ `node --test apps/desktop/test/plugin-timeout-budgets.test.mjs`、+ `pnpm --filter @pi-desktop/shared test`、`pnpm --filter @pi-desktop/host-runtime test`。diff --cc docs/zh-CN/spec/08-meta/decisions-log.mdindex 209daa2b5,9e4b9b966..df0bffc0e--- a/docs/zh-CN/spec/08-meta/decisions-log.md+++ b/docs/zh-CN/spec/08-meta/decisions-log.md@@@ -4678,11 -4678,62 +4678,70 @@@ that amendment are retired by ADR 0268`apps/desktop/test/image-generation-default.test.mjs` 固定,`provider-model-config.test.mjs` 断言新增分支会走这两个判断。+## 2026-09-21 — 限制 Desktop 可信扩展生命周期等待++- 现有 30 秒处理器预算扩展到通知、启动和关闭事件;模块加载、工厂初始化分别使用+ 同一预算。此前无界的等待变为有界,事件内等待 UI 回答也受此限制。+- 中止使当前等待失效;销毁拒绝新派发且只执行一次关闭。迟到完成不能向旧派发提供+ 结果。既有失败继续、结果归并、插件归属和权限不变,不强制终止进程内代码。+- 未接通事件仍可注册,并在现有诊断中显示。参见+ `07-plugins/16-trusted-extensions.md` §6 与 `E2E-HOOKS-cancel-and-dispose`。+ ## 2026-09-22 —— 指令源不可读时拒绝斜杠提交(D613,issue #795)++ - Composer 在发送时读取合并后的指令列表,并把失败吞成 `null`,而提交路径无法把它与+ “没有这个指令”区分开。于是在该 IPC 读取失败时输入的 `/compact` 会作为字面提示词发给+ 模型,模型据此把它当成指令执行。+ - 解析现在返回三种结果,而不再是一个可空值:已解析(内置 / 插件 / 扩展分发)、未知+ (模板、别名与无 id 条目继续走提示词路径)、不可用。不可用时拒绝提交、保留草稿并显示+ `chat.slashCommandSourceUnavailable`。失败的读取不写 TTL 缓存,因此下一次发送会重试;+ 缓存仍热时,一次数据源抖动不会影响解析。+ - 拒绝是刻意 fail-closed:只有指令源能判断 `/name` 是否为控制指令,因此读不到时,看起来像+ 普通文本的名称也会被拒绝,而不是靠猜测。模板与确实未知的别名保持原有提示词路径。由+ `apps/desktop/test/slash-command-source.test.mjs` 与+ `03-runtime/01-ipc-protocol.md` §13c 固定。++ ## 2026-09-22 —— 手动压缩有自己的传输超时与持久化判定(D614,issue #795)++ - `agent.compact` 是阻塞式 RPC,会在 sidecar 内消耗一次完整的模型摘要请求:pi 序列化会话、+ 流式生成摘要,并重试瞬时失败。它此前沿用扁平的 130 秒传输默认值,因此 888KB 上下文约+ 158 秒的压缩以 `sidecar RPC timeout` 结束,而 sidecar 仍在继续工作并落盘了检查点——用户+ 被告知压缩失败,而下一个回合证明它其实成功了。+ - 超时现在由 sidecar 真正执行的预算推导:每次尝试的流空转看门狗(180 秒)、`1 + 3` 次+ 尝试、2/4/8 秒重试退避,以及传输余量 —— 即 `AGENT_COMPACT_RPC_TIMEOUT_MS`,刻意按方法+ 区分,而不是放宽全局默认值。+ - 两条宿主路径(Electron 的 `agentCompact` IPC 与 `RuntimeService.compact`)也不再把手动+ 压缩的传输超时当作 sidecar 的判定:它们会重新读取持久化的 `session.compaction` 记录,+ 发现新检查点已落盘就报告成功、记录该不一致,否则原样抛出超时。sidecar 自己报告的判定+ 绝不会被这样改写。由 `packages/host-runtime/src/runtime-service.test.ts`、+ `packages/shared/src/protocol.test.ts`、+ `apps/desktop/test/plugin-timeout-budgets.test.mjs` 与+ `03-runtime/01-ipc-protocol.md` §5.4 固定。++ ## 2026-09-22 —— 空记录读取会重试,且绝不入缓存(D615,issue #795)++ - 渲染层把每一次持久化 `session.get` 窗口都当真,并写入缓存。当宿主正在重写记录文件时,+ 对拥有数千条消息的会话返回的空窗口被当成“空快照”存下,侧边栏悬停预取又反复送出它,+ 于是面板一直空白,只有重启应用才能恢复。此前没有任何逻辑区分“读取失败或读到陈旧数据”+ 与“真的空会话”,也没有任何路径重试。+ - 现在的判断依据是会话自己的计数:若侧边栏计为有历史的会话返回零条消息,就再读一次,+ 随后保留用户已有的快照,否则显示 `chat.sessionTranscriptEmpty`。这类空页绝不会写入记录+ 缓存,因此悬停预取不会污染之后每次打开。+ - 这是防御措施,而不是宿主侧根因:记录重写是报告者 0.15.1 的存储布局,而读取侧仍然返回+ “会话存在但没有消息”,而不是报告记录不可读。见 `04-ux/09-interaction-patterns.md`+ §跨选项卡的会话隔离。++ ## 2026-09-22 —— 从未拿到初始状态的渲染器有了有界表面与退出通道(D616)++ - 渲染器的启动过程本身没有超时:`bootstrap()` 要么发布初始状态,要么什么都不发布,+ 因此一次始终没有落地的读取会让窗口一直停在启动表面上——没有菜单、没有数据,除了+ 强杀进程无事可做(issue #831)。渲染器现在自己监视这段等待:+ `STARTUP_SLOW_HINT_MS`(30 秒)在不判定启动失败的前提下为启动表面加上日志、诊断与+ 退出,`STARTUP_STALLED_MS`(180 秒)把它变成恢复表面,后者还提供重跑+ `bootstrap()` 的重试。+ - 两个界限都高于 main↔host 的 RPC 上限(`DEFAULT_RPC_TIMEOUT_MS`,130 秒),因此慢+ 但成功的启动不会被读成失败;看门狗从不取消它所监视的启动,成功完成的启动会用 shell+ 替换该表面。恢复表面替换启动画面(同一时刻只挂载一个启动表面),渲染器绘制的窗口+ 控制按钮保持在其之上,因此无边框的 Windows/Linux 窗口始终可以关闭。+ - 渲染器新增退出通道 `pi-desktop/app/quit`(`api.quitApp()`),其处理函数与“退出”+ 菜单项一样调用 `app.quit()`,因此有序关停、确认对话框和关闭行为都仍是应用已有的+ 那一套。参见 `03-runtime/07-process-model.md` §3 与 E2E-076。