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(agent-runtime): drop /fast when an extension switches the model
zszz318a04032700c
diff --git a/docs/adr/0334-openai-fast-mode.md b/docs/adr/0334-openai-fast-mode.mdindex c396fa070..8453adb45 100644--- a/docs/adr/0334-openai-fast-mode.md+++ b/docs/adr/0334-openai-fast-mode.md@@ -48,7 +48,11 @@ in model settings.`openai-codex-responses` or `openai-responses`; the existing pi-ai patchforwards `serviceTier` through `streamSimple`, so the adapters also applytheir own tier pricing. Subagents, compaction, and one-shot plugin requests- build their own options and keep the default tier.+ build their own options and keep the default tier. Authorization belongs to+ the launch model: when a trusted extension switches the runtime to one of+ its own models (bridge `setModel` or agent activation), the runtime clears+ the switch, since that model has no `fastModeAllowed` binding. The next+ launch re-applies it through `setFastMode` from the stored binding.## Alternativesdiff --git a/docs/spec/03-runtime/11-provider-model-system.md b/docs/spec/03-runtime/11-provider-model-system.mdindex a41a17eb2..bb7271f8f 100644--- a/docs/spec/03-runtime/11-provider-model-system.md+++ b/docs/spec/03-runtime/11-provider-model-system.md@@ -398,7 +398,10 @@ higher price; a relay may ignore or rebill the field). The launcher sends`fastMode: true` to the sidecar only when the session switch is on and thestored binding allows it; the runtime adds the field to main-turn requests whoseresolved wire is `openai-codex-responses` or `openai-responses`. Subagents,-compaction, and one-shot requests keep the default tier.+compaction, and one-shot requests keep the default tier. A trusted extension+that moves the runtime to one of its own models clears the switch, because that+model has no binding to opt in; the next launch re-applies it from the+session's stored binding.`ModelBinding.availableForSubagents` (boolean, default false): opt-in flag thatmakes the model available for AI-driven subagent delegation. When enabled, thediff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 7d1619679..baebece52 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -18902,7 +18902,9 @@ host-created files. The full app's file-preview viewer is covered separately.price toast instead. Step 3 clears the mark and the field. Step 4 refuseswith the model-settings hint and stores nothing. Step 5 keeps the switch onthe fork and across restart. Subagent and compaction requests never carry- the field. Remote sessions refuse `/fast`.+ the field. Remote sessions refuse `/fast`. A trusted extension that switches+ the session to its own Responses model sends its next request without the+ field.- **Specs linked**: `03-runtime/11-provider-model-system.md`,`03-runtime/04-data-storage.md` (v26), `04-ux/04-builtin-commands.md`,ADR 0334, issue #1657.@@ -18910,7 +18912,10 @@ host-created files. The full app's file-preview viewer is covered separately.(draft → created session, toggle, refusals, remote, chip),`apps/desktop/test/fast-mode-session-launch.test.mjs` (launch resolution),`packages/agent-runtime/src/fast-mode.test.ts` (request body through the real- pi-ai Responses and Completions adapters), host-core migration, RPC and fork+ pi-ai Responses and Completions adapters),+ `packages/agent-runtime/src/fast-mode-reuse.test.ts` (mid-session switch on a+ reused runtime; an extension model switch drops the tier), host-core+ migration, RPC and forktests. The full settings → `/fast` → captured request path is a manualvalidation scenario.diff --git a/docs/zh-CN/spec/03-runtime/11-provider-model-system.md b/docs/zh-CN/spec/03-runtime/11-provider-model-system.mdindex 1cf918796..25af185ef 100644--- a/docs/zh-CN/spec/03-runtime/11-provider-model-system.md+++ b/docs/zh-CN/spec/03-runtime/11-provider-model-system.md@@ -334,6 +334,8 @@ Responses 协议上启用该勾选框:`openai_codex_responses`(ChatGPT 订另行计费)。只有当会话开关打开且保存的 binding 允许时,启动器才向 sidecar 发送`fastMode: true`;运行时只在解析后的协议为 `openai-codex-responses` 或`openai-responses` 的主回合请求中加入该字段。子代理、压缩和一次性请求保持默认档位。+可信扩展把运行时切换到它自己的模型时会清除该开关,因为该模型没有可供选择加入的+binding;下一次启动会按会话保存的 binding 重新应用。`ModelBinding.availableForSubagents`(布尔值,默认 false):这是一个选择加入的标志,让该模型可用于 AI 驱动的子代理委托。启用后,该模型会出现在注入父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 f9a2837dd..004a83c09 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@@ -10002,7 +10002,7 @@ host-created files. The full app's file-preview viewer is covered separately.- **预期**:第 1 步只在 binding 上保存 `fastModeAllowed`。第 2 步模型芯片显示 Fast 标识,请求体带有`service_tier: "priority"`;Responses API key 模型改为提示按 token 计费的价格。第 3 步清除标识和该字段。第 4 步给出模型设置提示并拒绝,不保存任何状态。第 5 步 fork 和重启后开关保持开启。子代理和压缩请求- 从不携带该字段。远程会话拒绝 `/fast`。+ 从不携带该字段。远程会话拒绝 `/fast`。可信扩展把会话切到它自己的 Responses 模型后,下一条请求不携带该字段。- **关联规格**:`03-runtime/11-provider-model-system.md`、`03-runtime/04-data-storage.md`(v26)、`04-ux/04-builtin-commands.md`、ADR 0334、issue #1657。- **状态**:自动化覆盖见英文版。完整的设置 → `/fast` → 捕获请求路径为手动验证场景。diff --git a/packages/agent-runtime/src/fast-mode-reuse.test.ts b/packages/agent-runtime/src/fast-mode-reuse.test.tsindex 9340b5cf2..03c0888dd 100644--- a/packages/agent-runtime/src/fast-mode-reuse.test.ts+++ b/packages/agent-runtime/src/fast-mode-reuse.test.ts@@ -1,6 +1,11 @@import { describe, expect, it, vi } from "vitest";import type { Agent } from "@earendil-works/pi-agent-core";-import type { Api, Model } from "@earendil-works/pi-ai";+import {+ createAssistantMessageEventStream,+ type Api,+ type AssistantMessage,+ type Model,+} from "@earendil-works/pi-ai";import {DesktopAgentRuntime,@@ -124,3 +129,98 @@ describe("fast mode on a reused runtime", () => {expect(runtime.matches(match)).toBe(true);});});++describe("fast mode across a trusted extension model switch", () => {+ const extensionModel = {+ id: "ext-responses",+ name: "Extension Responses",+ api: "openai-responses",+ provider: "ext-provider",+ baseUrl: "https://extension.example.com/v1",+ reasoning: false,+ input: ["text"],+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },+ contextWindow: 128_000,+ maxTokens: 8_192,+ } as unknown as Model<Api>;++ function extensionAgent(seen: Array<string | undefined>) {+ return {+ key: "ext:agent",+ extensionId: "ext",+ extensionLabel: "Extension",+ id: "agent",+ name: "Extension Agent",+ providerId: "ext-provider",+ models: [extensionModel],+ stream: (model: Model<Api>, _context: unknown, options?: { serviceTier?: string }) => {+ seen.push(options?.serviceTier);+ // Only the options the runtime hands the extension are under test.+ const message = {+ role: "assistant",+ content: [{ type: "text", text: "ok" }],+ api: model.api,+ provider: model.provider,+ model: model.id,+ usage: {+ input: 0,+ output: 0,+ cacheRead: 0,+ cacheWrite: 0,+ totalTokens: 0,+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },+ },+ stopReason: "stop",+ timestamp: 1,+ } as AssistantMessage;+ const stream = createAssistantMessageEventStream();+ queueMicrotask(() => {+ stream.push({ type: "start", partial: message });+ stream.push({ type: "done", reason: "stop", message });+ stream.end(message);+ });+ return stream;+ },+ };+ }++ async function requestExtension(runtime: DesktopAgentRuntime): Promise<void> {+ const internals = runtime as unknown as { agent: Agent; model: Model<Api> };+ const stream = await internals.agent.streamFunction(+ internals.model,+ { messages: [{ role: "user", content: "hi", timestamp: 1 }] } as never,+ {},+ );+ await stream.result();+ }++ it("drops the priority tier when an extension switches the session to its own Responses model", async () => {+ const seen: Array<string | undefined> = [];+ const agent = extensionAgent(seen);+ const runtime = createRuntime(true);+ const internals = runtime as unknown as {+ extensionRunner?: unknown;+ setExtensionModel(model: unknown): Promise<boolean>;+ };+ internals.extensionRunner = {+ hasHandlers: () => false,+ findAgentModel: () => agent,+ };+ try {+ // `/fast` was allowed for the launch model; the bridge's setModel then+ // moves an idle session to an extension model with no such opt-in.+ expect(await internals.setExtensionModel(extensionModel)).toBe(true);+ await requestExtension(runtime);+ expect(seen).toEqual([undefined]);++ // The next launch re-applies the switch from the stored binding; only an+ // explicit allowance there brings the tier back.+ runtime.setFastMode(true);+ await requestExtension(runtime);+ expect(seen).toEqual([undefined, "priority"]);+ } finally {+ internals.extensionRunner = undefined;+ await runtime.dispose();+ }+ });+});diff --git a/packages/agent-runtime/src/runtime.ts b/packages/agent-runtime/src/runtime.tsindex d5d6f07ef..802d28c4a 100644--- a/packages/agent-runtime/src/runtime.ts+++ b/packages/agent-runtime/src/runtime.ts@@ -2876,6 +2876,12 @@ Do not invent objections or turn speculative risks into blockers. Stop when the}private applyExtensionAgent(agent: RegisteredTrustedExtensionAgent, model: Model<Api>): void {+ // `/fast` was authorized for the model the session launched with: Main only+ // sends it when that binding has `fastModeAllowed` (ADR 0334). An extension+ // model has no such opt-in, so switching to it must not carry the priority+ // tier along. The next launch re-applies the switch from the session's+ // stored model through `setFastMode`.+ this.fastMode = false;this.provider = this.extensionProviderFor(agent, model);this.model = model;this.models = createExtensionAgentModels({