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(provider): preserve upstream thinking protocol defaults
zszz3f8c3712a3057
diff --cc apps/desktop/electron/main/models-dev-catalog.tsindex 8788b9fe9,eb830dca4..a12384ec1--- a/apps/desktop/electron/main/models-dev-catalog.ts+++ b/apps/desktop/electron/main/models-dev-catalog.ts@@@ -416,6 -418,10 +418,12 @@@ function modelFromRawconst reasoningPublished = typeof raw.reasoning === "boolean";const reasoning = raw.reasoning === true;const reasoningOptions = parseReasoningOptions(raw.reasoning_options);+ const thinkingProtocol: ThinkingProtocol | undefined =- providerKey === "anthropic" && reasoningOptions?.some((option) => option.type === "effort")++ providerKey === "anthropic" && reasoning &&++ reasoningOptions?.some((option) => option.type === "effort") &&++ !reasoningOptions.some((option) => option.type === "budget_tokens")+ ? "adaptive"+ : undefined;const limit = parseLimit(raw.limit);const experimental = publishedExperimental(raw.experimental);const providerMetadata = publishedMetadata(raw.provider);diff --cc docs/spec/03-runtime/11-provider-model-system.mdindex f27f41df5,44387b834..cf31aefc8--- a/docs/spec/03-runtime/11-provider-model-system.md+++ b/docs/spec/03-runtime/11-provider-model-system.md@@@ -125,8 -119,8 +125,12 @@@ models.dev record publishes a reasonin`budget_tokens` option (for example Opus 4.7+, Opus 5.x, Fable). Those modelsreject `thinking.type=enabled` with HTTP 400, and models.dev carries no pi-aicompat record, so without the flag pi-ai would fall back to budget thinking.--Models that still publish `budget_tokens` keep budget thinking, and an--explicit catalog `compat` record is preserved.++Models that still publish `budget_tokens`, including those that also publish++`effort`, keep budget thinking by default. The catalog uses this same rule++for the protocol displayed in model settings. An explicit++`ModelBinding.thinkingProtocol` selection (`legacy` or `adaptive`) overrides++the default; an absent field preserves the existing inference. An explicit++catalog `compat` record is preserved.An Anthropic Messages row the catalog cannot identify (for example a customgateway URL serving an id several publishers list) still falls back to thediff --cc docs/spec/06-delivery/04-e2e-test-plan.mdindex aa5456842,f889abd0a..798ed8b8e--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@@ -183,6 -183,26 +183,29 @@@- Keep validation evidence tied to the commit the gate ran on, plus any latercommit that changes the landed executable content.+ ### E2E-PROVIDER-adaptive-thinking-protocol++ - **Preconditions:** Isolated provider settings fixture with an Anthropic+ Messages provider and models `claude-opus-5-5` and a legacy Claude model;+ no live credentials.+ - **Steps:** Open a configured model's Advanced settings, inspect the+ thinking-protocol row, save an adaptive model with `medium`, then submit a+ request through the local Anthropic transport fixture. Repeat with the+ legacy model.+ - **Expected:** The adaptive model sends `thinking.type=adaptive` and+ `output_config.effort=medium`; the legacy model sends the existing+ budget-based thinking shape. Omitting the new field on an old binding keeps- legacy behavior after reload.++ the existing inference after reload: effort-only models use adaptive, while++ models publishing `budget_tokens` (including effort + budget combinations)++ retain budget thinking. Explicit standard/adaptive selections override++ those defaults.+ - **Specs:** 03-runtime/11-provider-model-system; 03-runtime/12-provider-config-schema.+ - **Acceptance:** Provider/model protocol selection and wire compatibility.+ - **Milestone:** Maintenance.+ - **Status:** Protocol coverage is automated in the agent-runtime provider+ binding tests; desktop settings coverage remains part of the provider model+ configuration E2E fixture.+## 2. Non-goals- Full UI-driven automated coverage; protocol and source-contract automation isdiff --cc packages/agent-runtime/src/provider-binding.test.tsindex ccd53816c,1290c0d83..cb4c5ff6f--- a/packages/agent-runtime/src/provider-binding.test.ts+++ b/packages/agent-runtime/src/provider-binding.test.ts@@@ -117,41 -117,93 +117,129 @@@ describe("Anthropic runtime endpoint",expect(urls).toEqual(["https://gw.example/anthropic/v1/messages?beta=true"]);});+ it("signs a plain Anthropic API-key row without a Bearer header", async () => {+ const provider: RuntimeProviderConfig = {+ ...keyedProvider,+ id: "anthropic-api-key-row",+ name: "Anthropic",+ baseUrl: "https://api.anthropic.com",+ modelId: "claude-sonnet-4-6",+ apiStyle: "anthropic_messages",+ };+ const model = buildProviderModel(provider);+ let request: Request | undefined;+ const fetch = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {+ request = new Request(input, init);+ return new Response(+ JSON.stringify({ type: "error", error: { type: "invalid_request_error", message: "test response" } }),+ { status: 400, headers: { "content-type": "application/json" } },+ );+ });++ const result = await createProviderModels(provider, model)+ .streamSimple(+ model,+ {+ systemPrompt: "system",+ messages: [{ role: "user", content: "hello", timestamp: Date.now() }],+ tools: [],+ },+ { fetch, maxRetries: 0 },+ )+ .result();++ expect(result.stopReason).toBe("error");+ expect(request?.headers.get("x-api-key")).toBe("sk-test");+ expect(request?.headers.get("Authorization")).toBeNull();+ });+++ it("uses adaptive thinking for models explicitly marked adaptive", async () => {+ const provider: RuntimeProviderConfig = {+ ...keyedProvider,+ id: "anthropic-adaptive",+ name: "Anthropic adaptive",+ baseUrl: "https://api.anthropic.com",+ modelId: "claude-opus-5-5",+ apiStyle: "anthropic_messages",+ supportsReasoning: true,+ supportedThinkingLevels: ["off", "medium"],+ modelConfig: {+ source: "models.dev",+ name: "Claude Opus 5.5",+ baseUrl: "https://api.anthropic.com",+ reasoning: true,+ thinkingProtocol: "adaptive",+ thinkingLevelMap: { medium: "medium" },+ input: ["text"],+ contextWindow: 200_000,+ maxTokens: 16_000,+ },+ };+ const model = buildProviderModel(provider);+ const requests: Record<string, unknown>[] = [];+ const fetch = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {+ requests.push(JSON.parse(String(init?.body)) as Record<string, unknown>);+ return new Response("bad request", { status: 400 });+ });++ await createProviderModels(provider, model)+ .streamSimple(+ model,+ { systemPrompt: "system", messages: [{ role: "user", content: "hello", timestamp: Date.now() }], tools: [] },+ { reasoning: "medium", fetch },+ )+ .result();++ expect(model.compat).toMatchObject({ forceAdaptiveThinking: true });+ expect(requests[0]).toMatchObject({+ thinking: { type: "adaptive" },+ output_config: { effort: "medium" },+ });+ });++ it("keeps the legacy budget request for legacy models", async () => {+ const provider: RuntimeProviderConfig = {+ ...keyedProvider,+ id: "anthropic-legacy",+ name: "Anthropic legacy",+ baseUrl: "https://api.anthropic.com",+ modelId: "claude-opus-4-5",+ apiStyle: "anthropic_messages",+ supportsReasoning: true,+ supportedThinkingLevels: ["off", "medium"],+ modelConfig: {+ source: "models.dev",+ name: "Claude Opus 4.5",+ baseUrl: "https://api.anthropic.com",+ reasoning: true,+ reasoningOptions: [{ type: "effort", values: ["low", "medium", "high"] }],+ thinkingProtocol: "legacy",+ input: ["text"],+ contextWindow: 200_000,+ maxTokens: 16_000,+ },+ };+ const model = buildProviderModel(provider);+ const requests: Record<string, unknown>[] = [];+ const fetch = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {+ requests.push(JSON.parse(String(init?.body)) as Record<string, unknown>);+ return new Response("bad request", { status: 400 });+ });++ await createProviderModels(provider, model)+ .streamSimple(+ model,+ { systemPrompt: "system", messages: [{ role: "user", content: "hello", timestamp: Date.now() }], tools: [] },+ { reasoning: "medium", fetch },+ )+ .result();++ expect(model.compat).toMatchObject({ forceAdaptiveThinking: false });+ expect(requests[0]).toMatchObject({+ thinking: { type: "enabled" },+ });+ expect((requests[0].thinking as Record<string, unknown>).budget_tokens).toEqual(expect.any(Number));+ });});describe("Anthropic adaptive thinking from models.dev reasoning options", () => {