Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
merge: land PR #624 provider-hosted web search
vastsa71420b78b58f
diff --cc docs/adr/0296-provider-hosted-web-search-adapter-capability.mdindex 000000000,3b5b410c3..ba56066d0mode 000000,100644..100644--- a/docs/adr/0296-provider-hosted-web-search-adapter-capability.md+++ b/docs/adr/0296-provider-hosted-web-search-adapter-capability.md@@@ -1,0 -1,105 +1,105 @@@-# ADR 0294: Provider-hosted web search as an adapter capability++# ADR 0296: Provider-hosted web search as an adapter capability++ - Status: Proposed+ - Date: 2026-09-19++ ## Context++ Some providers execute web search server-side: Anthropic Messages ships a+ `web_search_20250305` server tool, and OpenAI Responses (plus compatible+ gateways) ships a `web_search` tool. Unlike an MCP search server, the search+ runs inside the provider request, is billed by the provider per search, and+ returns structured blocks (`server_tool_use` + `web_search_tool_result`,+ `web_search_call`, `url_citation` annotations) that the client must keep in+ the conversation for multi-turn grounding.++ PR #570 previously added this as a composer toggle with runtime-level SSE+ re-parsing; it was reverted (#608) with the owner asking for a plugin-shaped+ follow-up. A capability review found the plugin SDK cannot reach the request+ payload, the response stream, the composer, the transcript, or message+ persistence, so "web search as a plugin" would require four new SDK extension+ points — larger than the feature itself. This ADR records the host-built+ shape that landed instead.++ Two upstream facts forced the design:++ - pi-ai 0.85.1 drops vendor search blocks in both adapters: the Anthropic+ stream loop has no `server_tool_use` / `web_search_tool_result` /+ `citations_delta` branches, and the Responses item loop has no+ `web_search_call` slot or annotation handling. Extraction must therefore+ live inside the adapters, not beside them.+ - Anthropic requires `server_tool_use` + `web_search_tool_result` blocks+ (including `encrypted_content`) to be replayed verbatim on later turns.+ A display-only normalization cannot satisfy that; replay needs the raw+ wire blocks.++ ## Decision++ 1. **Capability is declared data, evaluated in one place.** The per-model+ opt-in is `ModelBinding.nativeWebSearch` (settings UI: a checkbox in the+ model's advanced sheet, disabled unless the provider's API style is+ `responses` or `anthropic_messages`). models.dev publishes no hosted-tool+ capability, so there is no catalog default; absent means off. The single+ evaluation point is `resolveNativeWebSearch` in+ `packages/shared/src/native-web-search.ts`, keyed on the resolved wire+ API — never vendor names, base URL hostnames, or model-id substrings.++ 2. **Attachment and extraction live in the pi-ai adapters**, delivered by+ extending `patches/@[email protected]`:+ - `anthropic-messages.js` appends the `web_search_20250305` tool when+ `model.webSearch === true`, captures search blocks as `hostedSearch`+ content parts (raw wire block kept whole, streamed `input_json_delta`+ accumulated so the query is available live), collects `citations_delta`,+ and replays both halves of each pair in order on later turns.+ - `openai-responses(-shared).js` (and the Azure variant's own+ `buildParams`) appends the `web_search` tool, asks for+ `web_search_call.action.sources` via the opt-in `include` channel,+ creates a `hostedSearch` slot for `web_search_call` items, collects+ `url_citation` annotations, and replays the item for the same model.+ Both adapters push a `hosted_search_update` stream event per block+ transition; `patches/@[email protected]` teaches+ the agent loop to forward it as `message_update` — without that second+ patch the events die in the loop's switch and search activity renders only+ when the whole turn finishes. The patches are a stopgap; the same changes+ should be proposed upstream and dropped once released.++ 3. **The flag travels the existing model-config channel.**+ `ModelConfigWithBinding` copies `nativeWebSearch` into+ `ModelConfig.webSearch`; `buildProviderModel` spreads catalog fields into+ the pi-ai `Model`, so no new IPC, sidecar parameter, or runtime rebuild+ hook is needed.++ 4. **Display data and replay data are separated.** The runtime normalizes+ `hostedSearch` blocks into `UiMessage.hostedSearch`+ (`status/rounds[]`, one round per provider search/open-page/find-in-page+ call, shape-checked, junk ignored) for the activity rows; the raw wire blocks stay inside+ pi-ai's message content for replay. Persistence is an additive+ `hostedSearch` transcript block (`ui_to_record` / `record_to_ui`) — no SQL+ migration, per the storage playbook. The wire-slimming functions+ (`streamingMessageIdentity`, `applyMessageUpdate`) carry the field so+ delta frames cannot drop it.++ 5. **UI is a transcript activity row per round, not a composer control.**+ Each round of a `hostedSearch` activity renders as a `HostedSearchRow` on+ the tool-row idiom (icon + name + query summary, chevron disclosure):+ searching state while the round is in flight, sources when expanded.+ Sources are plain text links — no favicon fetches — so reading a+ transcript never leaks source hostnames anywhere (the #579 rule).+ Citation badges in message text are out of scope for v1; links stay+ ordinary markdown links.++ ## Consequences++ - Enabling the tool is per model, always-on while enabled, and takes effect+ on the next turn (runtime rebuild follows from modelConfig change). A+ session-level toggle and composer affordance can layer on later without+ touching the adapter contract.+ - Gateways that mangle replay blocks surface as provider errors on the next+ turn; the user-visible remedy is unchecking the model's opt-in. No silent+ fallback strips the tool — a search that quietly did not happen is worse+ than an error.+ - `pause_turn` keeps pi-ai's existing mapping to `stop`; a long searching+ turn may end early on the official Anthropic wire. This is a known+ limitation to revisit with the upstream patch.+ - Compaction rewrites history and drops search blocks; later turns lose old+ grounding and the model searches again as needed. Documented behavior.diff --cc docs/adr/README.mdindex f31fb6e6d,40b05967a..8764079e1--- a/docs/adr/README.md+++ b/docs/adr/README.md@@@ -320,6 -320,5 +320,7 @@@ Each ADR includes| 0291 | [Remove the speech settings UI](0291-remove-speech-settings-ui.md) | Accepted (amends ADR 0281) || 0292 | [SSH bootstrap for remote hosts](0292-ssh-remote-host-bootstrap.md) | Accepted for implementation (D453; ADR 0205 R2b, extends ADR 0286) || 0293 | [SSH password authentication for the remote-host bootstrap](0293-ssh-password-authentication.md) | Accepted (D454; amends ADR 0292) |-| 0294 | [Provider-hosted web search as an adapter capability](0294-provider-hosted-web-search-adapter-capability.md) | Proposed |+| 0294 | [Project archive is a list + inspector workbench](0294-project-archive-list-inspector.md) | Accepted (D455; amends D267 / D168) |+| 0295 | [Session thinking-parameter omission](0295-session-thinking-parameter-omission.md) | Accepted (D456; amends ADR 0194 / ADR 0144 / ADR 0221) |++| 0296 | [Provider-hosted web search as an adapter capability](0296-provider-hosted-web-search-adapter-capability.md) | Proposed || turn-process-and-thinking-display | [Turn process and thinking presentation](turn-process-and-thinking-display.md) | Accepted |diff --cc docs/spec/03-runtime/11-provider-model-system.mdindex 9d3865e29,6d322f7a4..e116d5264--- a/docs/spec/03-runtime/11-provider-model-system.md+++ b/docs/spec/03-runtime/11-provider-model-system.md@@@ -224,6 -224,15 +224,15 @@@ PI-Desktop must not permanently restriccatalog" rather than an equal-valued override. Agreeing with models.dev istherefore the reset, and no separate reset control or per-capabilityexplanatory copy is required.+ 10a. `nativeWebSearch` is a two-state opt-in (absent means off; there is no+ catalog baseline because models.dev publishes no hosted-tool capability).+ When enabled and the provider's resolved wire API is+ `anthropic_messages` or `responses`, the adapter attaches the provider's+ hosted web search tool (`web_search_20250305` / `web_search`), extracts+ the search activity into `UiMessage.hostedSearch`, and replays the raw- search blocks on later turns (ADR 0294). The checkbox is disabled when++ search blocks on later turns (ADR 0296). The checkbox is disabled when+ the provider's API style is neither of those two. Gateways that do not+ support the tool surface the provider error; the remedy is unchecking.11. `ModelInfo` is the published record the settings surface compares against,so a stored binding must not shape its capabilities or reasoning fields.Effective limits, reasoning and thinking levels are resolved through thediff --cc docs/zh-CN/adr/index.mdindex b58b1b5df,e6ff6a33d..645d19dd4--- a/docs/zh-CN/adr/index.md+++ b/docs/zh-CN/adr/index.md@@@ -299,8 -299,6 +299,9 @@@ ADR 记录那些不应被静默改变�| 0290 | [恢复可拖拽侧边栏宽度,过窄时收起](/adr/0290-resizable-sidebar-collapse-threshold) | 已接受(D451;修订 ADR 0141 / ADR 0238) || 0291 | [移除设置页面的语音界面](/adr/0291-remove-speech-settings-ui) | 已接受(修订 ADR 0281) || 0292 | [远端主机的 SSH 引导](/adr/0292-ssh-remote-host-bootstrap) | 已接受实施(D453;ADR 0205 R2b,扩展 ADR 0286) |+| 0294 | [项目存档改为列表 + 检查器](/adr/0294-project-archive-list-inspector) | 已接受(D455;修订 D267 / D168) |+| 0295 | [会话思考参数不发送](/adr/0295-session-thinking-parameter-omission) | 已接受(D456;修订 ADR 0194 / ADR 0144 / ADR 0221) |++| 0296 | [提供商托管联网搜索作为适配器能力](/adr/0296-provider-hosted-web-search-adapter-capability) | 提议中 |## 什么时候看 ADRdiff --cc docs/zh-CN/spec/03-runtime/11-provider-model-system.mdindex cda3c60ee,8b772b6e1..591d0ab66--- a/docs/zh-CN/spec/03-runtime/11-provider-model-system.md+++ b/docs/zh-CN/spec/03-runtime/11-provider-model-system.md@@@ -201,6 -201,13 +201,13 @@@ PI-Desktop 不得把用户永久限制�10. 设置里的复选框展示的是相对于已发布基线的有效答案;把某一项设回已发布的值,存下来的是"跟随目录",而不是一个取值相同的覆盖。因此与 models.dev保持一致本身就是重置,不需要另外的重置控件,也不需要逐项能力的解释文案。+ 10a. `nativeWebSearch` 是两态的主动开启(缺省即关闭;没有目录基线,因为+ models.dev 不发布托管工具能力)。启用且提供商解析后的线路 API 是+ `anthropic_messages` 或 `responses` 时,适配器会附加提供商托管的联网+ 搜索工具(`web_search_20250305` / `web_search`),把搜索活动提取为- `UiMessage.hostedSearch`,并在后续回合回放原始搜索块(ADR 0294)。++ `UiMessage.hostedSearch`,并在后续回合回放原始搜索块(ADR 0296)。+ 提供商接口风格不属于这两种时复选框禁用。不支持该工具的网关会把+ 提供商错误暴露出来;处理方式是取消勾选。11. `ModelInfo` 是设置界面用来对照的已发布记录,因此已存储的 binding 不得塑造它的能力或推理字段。有效上限、推理与思考级别都通过那个确切的 binding解析;有效的传输模态数组还会额外套用显式的附件覆盖。diff --cc packages/agent-runtime/src/runtime.test.tsindex 0871d78e1,02d4b09ab..6ef74f4c7--- a/packages/agent-runtime/src/runtime.test.ts+++ b/packages/agent-runtime/src/runtime.test.ts@@@ -8200,3 -8163,95 +8200,95 @@@ describe("DesktopAgentRuntime compactioawait runtime.dispose();});});+-describe("DesktopAgentRuntime hosted web search rounds (ADR 0294)", () => {++describe("DesktopAgentRuntime hosted web search rounds (ADR 0296)", () => {+ it("emits each search round as it happens and closes open rounds on message_end", async () => {+ const onEvent = vi.fn();+ const runtime = createRuntime({ onEvent });+ const handleAgentEvent = (runtime as any).handleAgentEvent.bind(runtime);++ const round = (id: string, status: string, query: string, sources: unknown[] = []) => ({+ type: "hostedSearch",+ phase: "web_search_call",+ blockId: id,+ status,+ wire: {+ type: "web_search_call",+ id,+ status,+ action: { type: "search", query, ...(sources.length ? { sources } : {}) },+ },+ });++ await handleAgentEvent({ type: "agent_start" });+ await handleAgentEvent({ type: "turn_start" });+ // Round 1 starts searching.+ await handleAgentEvent({+ type: "message_start",+ message: { role: "assistant", content: [round("ws_1", "in_progress", "first query")] },+ });+ // Round 1 completes and round 2 starts, still without any text.+ await handleAgentEvent({+ type: "message_update",+ message: {+ role: "assistant",+ content: [+ round("ws_1", "completed", "first query", [+ { url: "https://example.com/a", title: "A" },+ ]),+ round("ws_2", "in_progress", "second query"),+ ],+ },+ });+ // The turn ends while round 2 is still open; text arrived meanwhile.+ await handleAgentEvent({+ type: "message_end",+ message: assistantMessage({+ content: [+ round("ws_1", "completed", "first query", [+ { url: "https://example.com/a", title: "A" },+ ]),+ round("ws_2", "in_progress", "second query"),+ { type: "text", text: "The answer." },+ ],+ }),+ });+ await handleAgentEvent({ type: "turn_end" });+ await handleAgentEvent({ type: "agent_end", messages: [] });++ const events = onEvent.mock.calls.map(([envelope]) => (envelope as any).event);+ const searchUpdates = events.filter(+ (event: any) => event.type === "message_update" && event.message?.hostedSearch,+ );+ // Round 1 streamed the moment it started; round 2 the moment it appeared.+ expect(searchUpdates[0]?.message?.hostedSearch?.rounds).toEqual([+ { id: "ws_1", status: "searching", query: "first query", sources: [] },+ ]);+ expect(searchUpdates.at(-1)?.message?.hostedSearch?.rounds).toEqual([+ {+ id: "ws_1",+ status: "completed",+ query: "first query",+ sources: [{ url: "https://example.com/a", title: "A" }],+ },+ { id: "ws_2", status: "searching", query: "second query", sources: [] },+ ]);++ const end = events.find((event: any) => event.type === "message_end");+ // A round still open when the turn ends closes as completed, not left+ // blinking "searching" in a settled transcript.+ expect(end?.message?.hostedSearch).toEqual({+ status: "completed",+ rounds: [+ {+ id: "ws_1",+ status: "completed",+ query: "first query",+ sources: [{ url: "https://example.com/a", title: "A" }],+ },+ { id: "ws_2", status: "completed", query: "second query", sources: [] },+ ],+ });+ await runtime.dispose();+ });+ });