Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
docs: renumber this branch's decision to D620
vastsa716c62051a54
diff --git a/docs/spec/03-runtime/02-agent-runtime.md b/docs/spec/03-runtime/02-agent-runtime.mdindex 9af2c046b..555013aa7 100644--- a/docs/spec/03-runtime/02-agent-runtime.md+++ b/docs/spec/03-runtime/02-agent-runtime.md@@ -746,7 +746,7 @@ criterion-by-criterion report of what was met and the evidence observed.would leave a message sitting between a call and the result answering it. Amessage that replays a claimed call while carrying a new one keeps its newcall in place; no writer produces that partial replay, and the guard does not- reorder messages to close the gap it leaves (D619).+ reorder messages to close the gap it leaves (D620).- The agent loop owns its context array. `prepareNextTurn` hands pi a copy ofthe live state — for a delegate turn boundary too — exactly as pi's own`createContextSnapshot()` does for `prompt()` and `continue()`: pi's loop@@ -760,7 +760,7 @@ criterion-by-criterion report of what was met and the evidence observed.real one, and the endpoint rejected the turn with`Duplicate tool output for call_id`. In a delegate the same doubling doubledthe estimate at the following boundary and left the trailing row a fallback- carries onto a model it cannot resume from (D619).+ carries onto a model it cannot resume from (D620).- Restored checkpoints clear provider usage from retained assistant messagesfor budgeting. That usage measured the pre-compacted request and must notmake the summary + tail appear as large as the discarded context.diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex b857f4e96..4e854b50b 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -14442,7 +14442,7 @@ the latest destination. These assertions measure work counts, not device FPS.fixture's request carries exactly one result per call. No duplicate-drop line islogged, because the request guard had nothing to drop.- **Specs:** `03-runtime/02-agent-runtime.md` §5c,- `08-meta/decisions-log.md` D619.+ `08-meta/decisions-log.md` D620.- **Acceptance:** C (conversation and stream), Quality.- **Milestone:** Post-MVP regression coverage.- **Automation:** `packages/agent-runtime/src/runtime.test.ts` (loop contextdiff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.mdindex 1b11b61df..b0cb08353 100644--- a/docs/spec/08-meta/decisions-log.md+++ b/docs/spec/08-meta/decisions-log.md@@ -6610,7 +6610,7 @@ that was sitting at the bottom — including after the turn had finished.`apps/desktop/test/image-generation-default.test.mjs`, with`provider-model-config.test.mjs` asserting the add branch consults them.-## 2026-09-22 — The loop owns its context array (D619)+## 2026-09-22 — The loop owns its context array (D620)- A turn whose later iterations ran tools left `state.messages` holding two copiesof every message those iterations appended, and the next turn's first requestdiff --git a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md b/docs/zh-CN/spec/03-runtime/02-agent-runtime.mdindex b8dc4f20a..47c8c740e 100644--- a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md+++ b/docs/zh-CN/spec/03-runtime/02-agent-runtime.md@@ -573,13 +573,13 @@ Goal 批准所承诺的内容与 Plan 批准所承诺的内容完全相同:`mo会以 `tool_use ids must be unique` 拒绝整个回合(issue #718),使该会话无法继续。- 守卫按“上线的 id”比较调用与结果,即 Responses item id 之前、以 `|` 分隔的那一段;当一条辅助消息里的工具调用全部已被更早的消息占有时,整条消息被丢弃,因为保留它剩下的文本会把一条消息塞进调用与回答它的结果之间。若一条消息在复写已占用调用的同时还带一个新调用,则保留该- 消息及其新调用;目前没有写入方会产生这种部分复写,守卫也不会重排消息来填补它留下的空隙(D619)。+ 消息及其新调用;目前没有写入方会产生这种部分复写,守卫也不会重排消息来填补它留下的空隙(D620)。- 智能体循环拥有自己的上下文数组。`prepareNextTurn` 交给 pi 的是实时状态的副本(委托侧的回合边界同样如此),与 pi 自己的`createContextSnapshot()` 在 `prompt()`/`continue()` 里的做法一致:pi 的循环会把每个流式辅助消息与每个工具结果 push 进它拿到的数组,而它的 `message_end` 监听器又把同一消息 push 回 `state.messages`,因此交出活数组会把一个回合中较晚迭代的每条消息都存两份。下一回合的首个请求正是用该数组组装的,其中“带文本与工具调用的辅助消息”的重复项会残留为只剩文本的克隆,卡在调用与结果之间——pi-ai随后会为这个仍处于待配对的调用合成一条输出,与真实结果并列,端点以 `Duplicate tool output for call_id` 拒绝整个回合。在委托运行时,- 同样的重复还会让下一个边界的估算翻倍,并让备用模型拿到的末行无法被 `continue()` 续跑(D619)。+ 同样的重复还会让下一个边界的估算翻倍,并让备用模型拿到的末行无法被 `continue()` 续跑(D620)。- 视觉运行时只从会话绑定的附件、scratch 与项目根目录中水合持久化的图片引用。处于 10 MB 内联安全上限之内的图片会成为临时的 pi-ai 图片块;超限或不可用的图片则退化为安全的 `@path` 回退。超限历史的水合会直接复制文件,不会先把内容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.mdindex a78e423c6..ded9fa255 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@@ -8486,7 +8486,7 @@ the latest destination. These assertions measure work counts, not device FPS.- **步骤:** 发一条提示,让运行时跑完两轮工具调用并在工具轮上结束回合;再发第二条提示。读取运行时保留的状态与夹具收到的出站请求。- **预期:** 保留的状态里每个流式辅助消息与每个工具结果都只有一份;没有结果与它回答的调用被隔开;夹具收到的请求对每次调用只带一个结果。不产生去重日志行,因为请求守卫没有任何东西需要丢弃。-- **规格:** 03-runtime/02-agent-runtime §5c、08-meta/decisions-log D619。**验收:** C(对话与流)、品质。+- **规格:** 03-runtime/02-agent-runtime §5c、08-meta/decisions-log D620。**验收:** C(对话与流)、品质。**里程碑:** Post-MVP 回归覆盖。- **自动化:** `packages/agent-runtime/src/runtime.test.ts`(loop context ownership)通过 `runtime.prompt()` 驱动真实 pi 循环,并读取 `convertToLlm` 交给提供商的视图;`subagent-loop-context.test.ts` 覆盖委托侧的回合边界。两者都到不了适配器自身的输出,diff --git a/docs/zh-CN/spec/08-meta/decisions-log.md b/docs/zh-CN/spec/08-meta/decisions-log.mdindex 505042f49..4e3c37f74 100644--- a/docs/zh-CN/spec/08-meta/decisions-log.md+++ b/docs/zh-CN/spec/08-meta/decisions-log.md@@ -4689,7 +4689,7 @@ that amendment are retired by ADR 0268; the upstream work-panel lifecycle stays.`apps/desktop/test/image-generation-default.test.mjs` 固定,`provider-model-config.test.mjs` 断言新增分支会走这两个判断。-## 2026-09-22 — 循环拥有自己的上下文数组(D619)+## 2026-09-22 — 循环拥有自己的上下文数组(D620)- 当某个回合的较晚迭代跑了工具后,`state.messages` 会把那些迭代追加的每条消息存两份,而下一回合的首个请求正是用该数组组装的。其中“带文本与工具调用的辅助消息”的重复项在请求守卫(D608)之后残留为只剩文本的克隆,卡在调用与回答它的结果之间;pi-ai 随后会为diff --git a/packages/agent-runtime/src/runtime.test.ts b/packages/agent-runtime/src/runtime.test.tsindex 5f2bb3084..916cc7e1c 100644--- a/packages/agent-runtime/src/runtime.test.ts+++ b/packages/agent-runtime/src/runtime.test.ts@@ -9324,7 +9324,7 @@ describe("compaction fallback retention (#827)", () => {});});-describe("DesktopAgentRuntime loop context ownership (D613)", () => {+describe("DesktopAgentRuntime loop context ownership (D620)", () => {/*** Rounds 1 and 2 answer with a tool call and round 3 closes the turn; with* `stopAfterFirstRound` the run ends on the tool round instead, the way a@@ -9473,7 +9473,7 @@ describe("DesktopAgentRuntime loop context ownership (D613)", () => {// The loop appends the streamed assistant message and the tool results to// the context it was handed; pi's `message_end` listener appends the same// object to the state. Sharing one array stored every message of the- // later rounds twice (D613).+ // later rounds twice (D620).const state = (runtime as any).agent.state.messages as AgentMessage[];expect(textBlocks(state)).toEqual(["round 1", "round 2", "round 3"]);expect(toolCallIds(state)).toEqual(["call-1", "call-2"]);@@ -9496,7 +9496,7 @@ describe("DesktopAgentRuntime loop context ownership (D613)", () => {// A Stop ends the run on the second tool round, so those messages are the// ones the next turn's first request is built from — the request that- // production rejected with `Duplicate tool output for call_id` (D613).+ // production rejected with `Duplicate tool output for call_id` (D620).await runtime.prompt("first task", "user-1", "turn-1");requests.length = 0;diff --git a/packages/agent-runtime/src/runtime.ts b/packages/agent-runtime/src/runtime.tsindex 8e7f17d07..31382897d 100644--- a/packages/agent-runtime/src/runtime.ts+++ b/packages/agent-runtime/src/runtime.ts@@ -6032,7 +6032,7 @@ Delegation rules:// request guard as a text-only clone sitting between the call and the// result answering it. pi-ai then closes the still-pending call with a// synthesized "No result provided" output next to the real one — two- // outputs for one call id, which the provider rejects (D619).+ // outputs for one call id, which the provider rejects (D620).// `createContextSnapshot()` copies for the same reason.messages: [...this.agent.state.messages],tools,diff --git a/packages/agent-runtime/src/subagent-loop-context.test.ts b/packages/agent-runtime/src/subagent-loop-context.test.tsindex 3f1c7b4df..37664f7cc 100644--- a/packages/agent-runtime/src/subagent-loop-context.test.ts+++ b/packages/agent-runtime/src/subagent-loop-context.test.ts@@ -7,7 +7,7 @@ import type { RuntimeProviderConfig } from "./provider-binding.js";* What a turn boundary decides — compact, degrade, or report an overflow — is* covered by `subagent-context.test.ts`. This file pins the update the delegate* hands the agent loop instead, because that array is the context every later- * iteration of a run appends to (D619).+ * iteration of a run appends to (D620).*/vi.mock("./subagent-context.js", async (importOriginal) => {const actual = await importOriginal<typeof import("./subagent-context.js")>();@@ -88,7 +88,7 @@ function assistantMessage(text: string) {};}-describe("SubagentRun loop context ownership (D619)", () => {+describe("SubagentRun loop context ownership (D620)", () => {it("hands the loop its own context array at a protected turn boundary", async () => {const agent = createDelegate();agent.state.messages = [@@ -110,7 +110,7 @@ describe("SubagentRun loop context ownership (D619)", () => {// store every message of the run's later iterations twice, and the trailing// row `useNextModel` slices off before a fallback would then leave an// assistant row at the head of what `continue()` refuses to resume from- // (D619).+ // (D620).expect(carried).not.toBe(agent.state.messages);const streamed = assistantMessage("round 2");carried.push(streamed);diff --git a/packages/agent-runtime/src/subagent.ts b/packages/agent-runtime/src/subagent.tsindex 34b05da6e..a1ba6f357 100644--- a/packages/agent-runtime/src/subagent.ts+++ b/packages/agent-runtime/src/subagent.ts@@ -409,7 +409,7 @@ export class SubagentRun {// `state.messages`. Handing over the live array stores each message of// the run's later iterations twice, which doubles the estimate at the// next boundary and leaves `useNextModel` a trailing assistant row it- // cannot resume from (D619).+ // cannot resume from (D620).messages: [...this.agent.state.messages],tools: this.agent.state.tools,},diff --git a/packages/agent-runtime/src/tool-call-dedupe.test.ts b/packages/agent-runtime/src/tool-call-dedupe.test.tsindex e9ea9f315..92f55473c 100644--- a/packages/agent-runtime/src/tool-call-dedupe.test.ts+++ b/packages/agent-runtime/src/tool-call-dedupe.test.ts@@ -71,7 +71,7 @@ describe("dedupeToolCallMessages", () => {// The shape production hit: pi's loop appends the streamed assistant// message and its tool result to the context it was handed, while its own// `message_end` listener appends the same objects to the session state, so- // one round reached the next turn as two copies of each (D619). The+ // one round reached the next turn as two copies of each (D620). The// assistant message carries text *and* a call, so dropping only the call// block would leave a text-only clone between the call and its result.const assistant = assistantMessage([@@ -175,9 +175,9 @@ describe("dedupeToolCallMessages", () => {* The failure this guard exists for is invisible in the runtime's own view of a* request: pi-ai synthesizes the second output inside its provider transform,* after the point a scripted provider can capture. Driving that transform is- * what pins the mechanism the endpoint rejects (D619).+ * what pins the mechanism the endpoint rejects (D620).*/-describe("request wire contract (D619)", () => {+describe("request wire contract (D620)", () => {/** Only the fields the transform reads for a non-normalizing API. */const model = {api: "openai-completions",diff --git a/packages/agent-runtime/src/tool-call-dedupe.ts b/packages/agent-runtime/src/tool-call-dedupe.tsindex cb5e84e34..9f42f0d57 100644--- a/packages/agent-runtime/src/tool-call-dedupe.ts+++ b/packages/agent-runtime/src/tool-call-dedupe.ts@@ -23,7 +23,7 @@ function isRecord(value: unknown): value is RecordLike {* so a replay can address the server-side item, and the adapter sends only the* part before the separator as `call_id`. Two entries whose composite ids* differ in the item half therefore still collide on the wire, so every- * comparison below uses this wire-visible id (D619).+ * comparison below uses this wire-visible id (D620).*/function wireCallId(id: string): string {const separator = id.indexOf("|");@@ -40,7 +40,7 @@ function wireCallId(id: string): string {* A request that separates a call from its result is not merely untidy: pi-ai* closes a call whose result does not follow it with a synthesized* "No result provided" output *and* sends the real result, so one call id- * carries two outputs and the endpoint rejects the whole turn (D608, D619).+ * carries two outputs and the endpoint rejects the whole turn (D608, D620).* Dropping a replayed assistant message whole — rather than keeping the text it* is left with — is what keeps that separation out of the request, and the* duplication the runtime itself produces repeats a message whole, so that is