From 85b026575ead7e14e429027a78c500370a38c10c Mon Sep 17 00:00:00 2001 From: szdziedzic Date: Thu, 26 Nov 2026 14:11:13 +0100 Subject: [PATCH 1/9] feat: pass agent effort to OpenAI and Google models through OpenCode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `effort` reached only `anthropic/…` agents (the claude-code engine's `--effort`). OpenCode hands unknown agent-config keys to the provider as model options, so buildOpencodeConfig now adds one per reviewer with `effort`, chosen by opencodeEffortStyle from the model's provider: - openai/… (and an alias with upstream "openai"): reasoningEffort, sent as the Responses API reasoning.effort. - google/… and google-vertex/…: thinkingConfig.thinkingLevel, in place of the "high" that OpenCode sends to Gemini by default. Observed with the pinned OpenCode 1.19.5 against a local mock endpoint, using the agent entries buildOpencodeConfig produces. Other OpenCode providers still get the "has no effect" run note, which now names only those. Fixed-role passes never get a level. ecr passes the level as written; a provider that does not take it fails the pass with its own error. Co-Authored-By: Claude Opus 5.5 --- README.md | 20 ++++-- ...config-schema-loading-routing.explainer.md | 24 +++++-- src/__tests__/claude-code.test.ts | 63 ++++++++++++++++--- src/__tests__/opencode.test.ts | 42 ++++++++++++- src/__tests__/review-internals.test.ts | 5 ++ src/core/claude-code.ts | 51 +++++++++------ src/core/opencode.ts | 62 +++++++++++++++++- src/core/review.ts | 7 ++- templates/config.jsonc | 6 +- 9 files changed, 234 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index a394c2d..a172721 100644 --- a/README.md +++ b/README.md @@ -536,12 +536,20 @@ comment (and in the terminal) with the fix, and `ecr doctor` fails on them: frontmatter below an HTML comment, a byte-order mark or blank lines (all its keys are ignored), and a comment that breaks `alwaysRun`, `model` or `temperature`. -`effort` sets how much reasoning the model spends on that agent's passes. Only -models that run through the Claude Code CLI (`anthropic/…`) read it; for any other -model the review prints a note and ignores it. Leave it out to use the CLI default. -The model must also support effort: the CLI sends no level to a model without -effort support (Claude Haiku 4.5 is one), and ecr does not check this. A model can -also take only some of the levels. +`effort` sets how much reasoning the model spends on that agent's passes. ecr +passes it for these models, and for any other model the review prints a note and +ignores it. Leave it out to use the provider's default. + +| Model | How the level is sent | +| --- | --- | +| `anthropic/…` (Claude Code CLI) | `--effort ` | +| `openai/…`, or an alias with `upstream: "openai"` (OpenCode) | `reasoningEffort`, sent as the Responses API `reasoning.effort` | +| `google/…`, `google-vertex/…` (OpenCode) | `thinkingConfig.thinkingLevel`, in place of OpenCode's default `high` | + +ecr passes the level as written and does not check which levels a model takes. A +model without effort support can drop it (the Claude Code CLI sends no level to +Claude Haiku 4.5), and a provider can reject a level its model does not take, which +fails that agent's passes with the provider's error. A higher level costs more and takes longer, so set it on the agent that needs depth (a correctness reviewer that must trace callers), not on every agent. A value that is not a level is listed under **Review setup**, and the agent runs at the default. diff --git a/llp/0006-config-schema-loading-routing.explainer.md b/llp/0006-config-schema-loading-routing.explainer.md index cb50226..adcbafa 100644 --- a/llp/0006-config-schema-loading-routing.explainer.md +++ b/llp/0006-config-schema-loading-routing.explainer.md @@ -226,7 +226,7 @@ reviewers raised in the class "needs a logic trace" (eval run `full-v2-tune`, 20 is private and not in this repo; no person checked the analysis). Depth is a per-agent need, and it costs time and money, so it is a per-agent key and not a run-level flag. -- **Only the claude-code engine reads it.** `startClaudeCode` copies the declared levels into +- **The claude-code engine passes it as a flag.** `startClaudeCode` copies the declared levels into `ClaudeCodeHandle.efforts`, and `runClaudePrompt` passes `--effort ` for that agent's passes [observed] (`buildClaudeArgs` `effort`; tests in `src/__tests__/claude-code.test.ts`). The fixed roles (cross-cutting, verifier, adjudicator, stack verifier, coordinator) have no entry and @@ -239,8 +239,22 @@ per-agent key and not a run-level flag. session archive's `NON_REVIEWER_AGENTS`, so the two cannot drift. The levels live in a `Map`, so an id such as `constructor` cannot read an inherited `Object.prototype` value (both found in review of the first version, PR #118). -- **An OpenCode-routed agent ignores it, with a note.** `agentEffortNote` names those agents once - per run, the same way `claudeTemperatureNote` reports a temperature the CLI cannot take. +- **OpenCode passes it for OpenAI and Google models.** OpenCode hands unknown agent-config keys to + the provider as model options. `buildOpencodeConfig` adds one per reviewer with `effort`, chosen + by `opencodeEffortStyle` from the model's provider (an alias takes its auth entry's `upstream`): + `openai` gets `reasoningEffort`, `google` and `google-vertex` get + `thinkingConfig.thinkingLevel`. Observed with the pinned OpenCode 1.19.5 against a local mock + endpoint (2026-11-26) [observed]: with no key, an `openai/gpt-6.2-astra` request carried no + `reasoning` field; `reasoningEffort: "xhigh"` and `"max"` arrived as `reasoning.effort`; a + `google/gemini-4-neon` request carried `thinkingConfig: {includeThoughts: true, thinkingLevel: + "high"}` with no key, and `thinkingLevel: "low"` replaced the `high`. Only reviewer entries get + the key: the fixed roles are written after the reviewer loop, so a reviewer that shares a fixed + role's id cannot give that pass its level. Not observed: the ChatGPT/Codex sign-in path and a + real provider's response to each level. ecr passes the level as written; a provider that does + not take it fails that agent's passes with its own error. +- **Any other OpenCode-routed agent ignores it, with a note.** `agentEffortNote` names agents whose + OpenCode provider takes no level (Meta, OpenAI-compatible and others) once per run, the same way + `claudeTemperatureNote` reports a temperature the CLI cannot take. `selectReviewers`, which `runReview` calls, builds it from the selected reviewer list, after the `paths` filter and the router, so an agent either of them left out is never named. A later step (a blocking pre-check, the budget) can still skip a named agent, so the note states a fact about @@ -270,8 +284,8 @@ per-agent key and not a run-level flag. warnings behave the same way, so a fix belongs to all per-agent warnings at once. An unmatched quote (`effort: "max`) loads as `max`, because the shared frontmatter reader strips each quote on its own for every key. -- **`REVIEWER_MODEL` does not clear it.** The override can move an agent to a model that runs - through OpenCode; the note then reports the ignored level. +- **`REVIEWER_MODEL` does not clear it.** The override can move an agent to another provider; the + level then goes to that provider, or the note reports it as ignored. ## Budgets and Chunking Defaults diff --git a/src/__tests__/claude-code.test.ts b/src/__tests__/claude-code.test.ts index d9ffe6c..5c6cd75 100644 --- a/src/__tests__/claude-code.test.ts +++ b/src/__tests__/claude-code.test.ts @@ -888,8 +888,10 @@ test("agentEffortNote: names the agents whose effort an OpenCode-routed model ig { id: "b", effort: "low" }, { id: "c" }, ] as unknown as LoadedAgent[]; - expect(agentEffortNote(agents, { a: "claude-code", b: "claude-code", c: "opencode" })).toBeNull(); - const note = agentEffortNote(agents, { a: "claude-code", b: "opencode", c: "opencode" }); + expect( + agentEffortNote(agents, { a: "claude-code", b: "claude-code", c: "opencode" }, []), + ).toBeNull(); + const note = agentEffortNote(agents, { a: "claude-code", b: "opencode", c: "opencode" }, []); expect(note).toContain("has no effect for b:"); expect(note).not.toContain("for a"); }); @@ -900,35 +902,76 @@ test("agentEffortNote: an agent that does not run in this review is not named", // although the engine map still has entries for both ids. const selected = [{ id: "alpha", effort: "high" }] as unknown as LoadedAgent[]; expect( - agentEffortNote(selected, { alpha: "claude-code", ios: "opencode", verifier: "claude-code" }), + agentEffortNote( + selected, + { alpha: "claude-code", ios: "opencode", verifier: "claude-code" }, + [], + ), ).toBeNull(); }); +test("agentEffortNote: OpenAI and Google models take a level through OpenCode; others do not", () => { + const agents = [ + { id: "astra", effort: "high", model: "openai/gpt-6.2-astra" }, + { id: "pro", effort: "high", model: "openai-api/gpt-5.5-pro" }, + { id: "neon", effort: "high", model: "google/gemini-4-neon" }, + { id: "vertex", effort: "high", model: "google-vertex/gemini-4-neon" }, + { id: "muse", effort: "high", model: "meta/muse-spark-1.3" }, + ] as unknown as LoadedAgent[]; + const engineOf = { + astra: "opencode", + pro: "opencode", + neon: "opencode", + vertex: "opencode", + muse: "opencode", + } as const; + const auth = [ + { provider: "openai-api", mode: "api-key", tokenEnv: "OPENAI_API_KEY", upstream: "openai" }, + ] as unknown as AuthConfigEntry[]; + const named = (note: string | null) => note?.match(/has no effect for ([^:]+):/)?.[1]; + const note = agentEffortNote(agents, engineOf, auth); + expect(note).toContain( + "the model of each runs through OpenCode on a provider ecr passes no level to", + ); + expect(named(note)).toBe("muse"); + // Without the alias's auth entry, `openai-api` is not known to be OpenAI. + expect(named(agentEffortNote(agents, engineOf, []))).toBe("pro, muse"); +}); + +test("agentEffortNote: a fixed-role reviewer on OpenAI is told only to rename", () => { + const agents = [ + { id: "verifier", effort: "max", model: "openai/gpt-6.2-astra" }, + ] as unknown as LoadedAgent[]; + const note = agentEffortNote(agents, { verifier: "claude-code" }, []); + expect(note).toContain("Fix: rename the agent file"); + expect(note).not.toContain("give verifier a model"); +}); + test("agentEffortNote: reports both reasons in one note", () => { const agents = [ { id: "ios", effort: "high" }, { id: "verifier", effort: "max" }, ] as unknown as LoadedAgent[]; - const note = agentEffortNote(agents, { ios: "opencode", verifier: "claude-code" }); - expect(note).toContain("has no effect for ios: only the claude-code engine reads it"); + const note = agentEffortNote(agents, { ios: "opencode", verifier: "claude-code" }, []); + expect(note).toContain("has no effect for ios: the model of each runs through OpenCode"); expect(note).toContain("; `effort` has no effect for verifier: the id is also a built-in pass"); }); -test("agentEffortNote: a fixed-role reviewer on an OpenCode model is told to change the model too", () => { +test("agentEffortNote: a fixed-role reviewer on a model that takes no level is told to change the model too", () => { const agents = [ - { id: "verifier", effort: "max", model: "openai/gpt-6-astra" }, + { id: "verifier", effort: "max", model: "meta/muse-spark-1.3" }, { id: "coordinator", effort: "high", model: "anthropic/claude-opus-5-5" }, ] as unknown as LoadedAgent[]; // The engine map describes the built-in passes (claude here), not the reviewer files. - const note = agentEffortNote(agents, { verifier: "claude-code", coordinator: "claude-code" }); - expect(note).toContain("Fix: rename the agent file, and run verifier on an `anthropic/…` model"); + const note = agentEffortNote(agents, { verifier: "claude-code", coordinator: "claude-code" }, []); + expect(note).toContain("Fix: rename the agent file, and run verifier on a model that takes a level"); expect(note).toContain("`REVIEWER_MODEL` when that is set"); expect(note).not.toContain("give verifier, coordinator"); }); test("agentEffortNote: a reviewer that shares a fixed role's id is told to rename", () => { const agents = [{ id: "verifier", effort: "max" }] as unknown as LoadedAgent[]; - const note = agentEffortNote(agents, { verifier: "opencode" }); + const note = agentEffortNote(agents, { verifier: "opencode" }, []); expect(note).toContain("has no effect for verifier: the id is also a built-in pass"); expect(note).toContain("Fix: rename the agent file"); expect(note).not.toContain("runs through OpenCode"); diff --git a/src/__tests__/opencode.test.ts b/src/__tests__/opencode.test.ts index 791f153..3f3d47c 100644 --- a/src/__tests__/opencode.test.ts +++ b/src/__tests__/opencode.test.ts @@ -18,6 +18,9 @@ import { serverStopped, STACK_VERIFIER_AGENT, META_MODEL_API_BASE_URL, + opencodeEffortStyle, + VERIFIER_AGENT, + CROSS_CUTTING_AGENT, } from "../core/opencode.js"; import type { OpencodeHandle } from "../core/opencode.js"; import type { ClaudeCodeHandle } from "../core/claude-code.js"; @@ -58,7 +61,7 @@ test("resolveEngineDispatch: per-agent router picks the right engine and claude /** Minimal LoadedConfig for buildOpencodeConfig tests. */ function configWith(overrides: { - agents?: Array<{ id: string; model: string }>; + agents?: Array<{ id: string; model: string; effort?: string }>; coordinatorModel?: string; auth?: unknown[]; }): LoadedConfig { @@ -689,3 +692,40 @@ describe("Recording an OpenCode pass for the session archive", () => { expect(handle.capture?.count).toBe(0); }, 20_000); }); + +test("opencodeEffortStyle: OpenAI and Google families take a level; others do not", () => { + const alias = [ + { provider: "openai-api", mode: "api-key", tokenEnv: "OPENAI_API_KEY", upstream: "openai" }, + { provider: "claude-api", mode: "api-key", tokenEnv: "ANTHROPIC_KEY_2", upstream: "anthropic" }, + ] as unknown as LoadedConfig["auth"]; + expect(opencodeEffortStyle("openai/gpt-6.2-astra", [])).toBe("openai"); + expect(opencodeEffortStyle("openai-api/gpt-5.5-pro", alias)).toBe("openai"); + expect(opencodeEffortStyle("openai-api/gpt-5.5-pro", [])).toBeNull(); + expect(opencodeEffortStyle("google/gemini-4-neon", [])).toBe("google"); + expect(opencodeEffortStyle("google-vertex/gemini-4-neon", [])).toBe("google"); + expect(opencodeEffortStyle("claude-api/claude-opus-5-5", alias)).toBeNull(); + expect(opencodeEffortStyle("meta/muse-spark-1.3", [])).toBeNull(); + expect(opencodeEffortStyle("gpt-6.2-astra", [])).toBeNull(); +}); + +test("buildOpencodeConfig passes a reviewer's effort as its provider's option, and only a reviewer's", () => { + const opencode = buildOpencodeConfig( + configWith({ + agents: [ + { id: "astra", model: "openai/gpt-6.2-astra", effort: "xhigh" }, + { id: "neon", model: "google/gemini-4-neon", effort: "low" }, + { id: "muse", model: "meta/muse-spark-1.3", effort: "high" }, + { id: "plain", model: "openai/gpt-6.2-astra" }, + { id: "verifier", model: "openai/gpt-6.2-astra", effort: "max" }, + ], + }), + ) as { agent: Record> }; + expect(opencode.agent.astra!.reasoningEffort).toBe("xhigh"); + expect(opencode.agent.astra!.thinkingConfig).toBeUndefined(); + expect(opencode.agent.neon!.thinkingConfig).toEqual({ thinkingLevel: "low" }); + expect(opencode.agent.neon!.reasoningEffort).toBeUndefined(); + for (const id of ["muse", "plain", VERIFIER_AGENT, CROSS_CUTTING_AGENT, "coordinator"]) { + expect(opencode.agent[id]!.reasoningEffort, id).toBeUndefined(); + expect(opencode.agent[id]!.thinkingConfig, id).toBeUndefined(); + } +}); diff --git a/src/__tests__/review-internals.test.ts b/src/__tests__/review-internals.test.ts index ab5a2f5..e611362 100644 --- a/src/__tests__/review-internals.test.ts +++ b/src/__tests__/review-internals.test.ts @@ -942,6 +942,7 @@ describe("selectReviewers: the effort note names only selected reviewers", () => candidates: [alpha, ios], route: async () => ({ agents: [alpha], routed: true }), engineOf, + auth: [], progress: (line) => lines.push(line), }); expect(result.selectedAgents.map((a) => a.id)).toEqual(["alpha"]); @@ -955,6 +956,7 @@ describe("selectReviewers: the effort note names only selected reviewers", () => await selectReviewers({ candidates: [alpha, ios], engineOf, + auth: [], progress: (line) => lines.push(line), }); const note = lines.find((line) => line.startsWith("Note: `effort`")); @@ -968,6 +970,7 @@ describe("selectReviewers: the effort note names only selected reviewers", () => candidates: [alpha, verifier], route: async () => ({ agents: [alpha], routed: true }), engineOf, + auth: [], progress: (line) => routedOut.push(line), }); expect(routedOut.some((line) => line.includes("effort"))).toBe(false); @@ -977,6 +980,7 @@ describe("selectReviewers: the effort note names only selected reviewers", () => candidates: [alpha, verifier], route: async () => ({ agents: [alpha, verifier], routed: true }), engineOf, + auth: [], progress: (line) => selected.push(line), }); expect(selected.find((line) => line.startsWith("Note: `effort`"))).toContain( @@ -990,6 +994,7 @@ describe("selectReviewers: the effort note names only selected reviewers", () => candidates: [alpha, ios], route: async () => ({ agents: [alpha, ios], routed: false }), engineOf, + auth: [], progress: (line) => lines.push(line), }); expect(result.selectedAgents.map((a) => a.id)).toEqual(["alpha", "ios"]); diff --git a/src/core/claude-code.ts b/src/core/claude-code.ts index 78a0ee2..aa3f0cb 100644 --- a/src/core/claude-code.ts +++ b/src/core/claude-code.ts @@ -4,7 +4,13 @@ import { tmpdir } from "node:os"; import path from "node:path"; import { fallbackEffort } from "../config/schema.js"; -import type { AgentEffort, LoadedAgent, LoadedConfig, McpServerConfig } from "../config/schema.js"; +import type { + AgentEffort, + AuthConfigEntry, + LoadedAgent, + LoadedConfig, + McpServerConfig, +} from "../config/schema.js"; import { checkAuthEntry } from "./auth.js"; import { pathInside, resolveOnPath, run } from "./exec.js"; import { assertMcpServerTokenEnvs, mcpGrantEnvironment, mcpServerGrants } from "./mcp-servers.js"; @@ -15,6 +21,7 @@ import { AgentTimeoutError, CLAUDE_CODE_ENGINE, CROSS_CUTTING_AGENT, + opencodeEffortStyle, STACK_VERIFIER_AGENT, VERIFIER_AGENT, withTransientRetry, @@ -810,19 +817,27 @@ export function buildAgentEfforts(config: LoadedConfig): Map, + auth: readonly AuthConfigEntry[], ): string | null { const declared = agents.filter((agent) => agent.effort); + const takesNoLevel = (model: string): boolean => + engineForModel(model) === "opencode" && opencodeEffortStyle(model, auth) === null; const viaOpencode = declared - .filter((agent) => !FIXED_ROLE_IDS.has(agent.id) && engineOf[agent.id] === "opencode") + .filter( + (agent) => + !FIXED_ROLE_IDS.has(agent.id) && + engineOf[agent.id] === "opencode" && + takesNoLevel(agent.model ?? ""), + ) .map((agent) => agent.id); const fixedRole = declared .filter((agent) => FIXED_ROLE_IDS.has(agent.id)) @@ -830,31 +845,31 @@ export function agentEffortNote( const notes: string[] = []; if (viaOpencode.length > 0) { notes.push( - `\`effort\` has no effect for ${viaOpencode.join(", ")}: only the claude-code engine ` + - "reads it, and the model of each runs through OpenCode", + `\`effort\` has no effect for ${viaOpencode.join(", ")}: the model of each runs through ` + + `OpenCode on a provider ecr passes no level to (${EFFORT_PROVIDERS})`, ); } // The engine map's entry for a fixed-role id describes the built-in pass, so read the - // reviewer's own model: after a rename, an OpenCode model would still ignore `effort`. - const fixedRoleViaOpencode = declared - .filter( - (agent) => FIXED_ROLE_IDS.has(agent.id) && engineForModel(agent.model ?? "") === "opencode", - ) + // reviewer's own model: after a rename, a model that takes no level still ignores it. + const fixedRoleNoLevel = declared + .filter((agent) => FIXED_ROLE_IDS.has(agent.id) && takesNoLevel(agent.model ?? "")) .map((agent) => agent.id); if (fixedRole.length > 0) { notes.push( `\`effort\` has no effect for ${fixedRole.join(", ")}: the id is also a built-in pass, which ` + "runs at the default effort. Fix: rename the agent file" + - (fixedRoleViaOpencode.length > 0 - ? `, and run ${fixedRoleViaOpencode.join(", ")} on an \`anthropic/…\` model (its ` + - "`model:`, or `REVIEWER_MODEL` when that is set), because only the claude-code " + - "engine reads `effort`" + (fixedRoleNoLevel.length > 0 + ? `, and run ${fixedRoleNoLevel.join(", ")} on a model that takes a level ` + + `(${EFFORT_PROVIDERS}; its \`model:\`, or \`REVIEWER_MODEL\` when that is set)` : ""), ); } return notes.length > 0 ? notes.join("; ") : null; } +/** The model families ecr passes an effort level to, for the run notes. */ +const EFFORT_PROVIDERS = "`anthropic/…`, `openai/…`, `google/…` or `google-vertex/…`"; + /** * Preserve actionable process diagnostics without copying arbitrary stderr into a * public Actions log. A non-empty stream may already contain model/tool content, so diff --git a/src/core/opencode.ts b/src/core/opencode.ts index dbaa07f..2404bc0 100644 --- a/src/core/opencode.ts +++ b/src/core/opencode.ts @@ -5,7 +5,12 @@ import path from "node:path"; import { createOpencode } from "@opencode-ai/sdk"; -import type { LoadedConfig, McpServerConfig } from "../config/schema.js"; +import type { + AgentEffort, + AuthConfigEntry, + LoadedConfig, + McpServerConfig, +} from "../config/schema.js"; // Type-only: erased at compile time, so it creates NO runtime import cycle. The // Claude engine is reached at runtime via dynamic import() in the dispatch // branches below; claude-code.ts statically imports the shared helpers here. @@ -274,6 +279,55 @@ export const ADJUDICATOR_AGENT = "adjudicator"; // that structural, like the coordinator. export const STACK_VERIFIER_AGENT = "stack-verifier"; +/** + * How an OpenCode provider's SDK takes a reasoning level from an agent's config: + * OpenAI's Responses adapter reads `reasoningEffort`, Google's reads + * `thinkingConfig.thinkingLevel`. + */ +export type OpencodeEffortStyle = "openai" | "google"; + +/** + * The effort style for a model id, or null when ecr does not pass a level to that + * provider. An upstream alias (auth entry `openai-api` with upstream `openai`) takes its + * upstream's style. Meta, OpenAI-compatible and other providers get null. + */ +// @ref LLP 0006#agent-effort [implements] — OpenCode-routed effort, per provider family +export function opencodeEffortStyle( + model: string, + auth: readonly AuthConfigEntry[], +): OpencodeEffortStyle | null { + const slash = model.indexOf("/"); + if (slash <= 0) { + return null; + } + const provider = model.slice(0, slash); + const family = + auth.find((entry) => entry.provider === provider && entry.upstream)?.upstream ?? provider; + if (family === "openai") { + return "openai"; + } + if (family === "google" || family === "google-vertex") { + return "google"; + } + return null; +} + +/** + * The agent-config keys that carry a reasoning level for an effort style. OpenCode + * passes unknown agent keys to the provider as model options; observed with OpenCode + * 1.19.5 against a mock endpoint (LLP 0006): `reasoningEffort` becomes the Responses + * API's `reasoning.effort`, and `thinkingConfig.thinkingLevel` replaces the `high` that + * OpenCode sends to Gemini by default. + */ +export function opencodeEffortOptions( + style: OpencodeEffortStyle, + effort: AgentEffort, +): Record { + return style === "openai" + ? { reasoningEffort: effort } + : { thinkingConfig: { thinkingLevel: effort } }; +} + /** Build the inline OpenCode config (agents + coordinator) from a repo config. */ export function buildOpencodeConfig( config: LoadedConfig, @@ -282,11 +336,17 @@ export function buildOpencodeConfig( ): Record { const agent: Record = {}; for (const reviewer of config.agents) { + const effortStyle = reviewer.effort ? opencodeEffortStyle(reviewer.model, config.auth) : null; agent[reviewer.id] = { description: `${reviewer.id} reviewer`, mode: "all", model: reviewer.model, temperature: reviewer.temperature, + // Only reviewers: the fixed roles below are written after this loop, so a reviewer + // that shares a fixed role's id cannot give that pass its level. + ...(reviewer.effort && effortStyle + ? opencodeEffortOptions(effortStyle, reviewer.effort) + : {}), prompt: `You are the ${reviewer.id} code reviewer. Follow the user message exactly and return only the requested JSON.`, tools: { ...reviewer.tools, diff --git a/src/core/review.ts b/src/core/review.ts index 4bba427..6349842 100644 --- a/src/core/review.ts +++ b/src/core/review.ts @@ -1,7 +1,7 @@ // @ref LLP 0002#pipeline-stages [implements] — the mode-agnostic pipeline core owning budgets, coverage, and logging import path from "node:path"; -import type { LoadedAgent, LoadedConfig } from "../config/schema.js"; +import type { AuthConfigEntry, LoadedAgent, LoadedConfig } from "../config/schema.js"; import type { PreparedReadRoot, ReviewSource, @@ -710,6 +710,7 @@ export async function runReview( } : {}), engineOf, + auth: config.auth, progress, }); @@ -2368,6 +2369,8 @@ export async function selectReviewers(args: { candidates: LoadedAgent[]; route?: () => Promise; engineOf: Record; + /** The run's credentials: a provider alias takes its upstream's effort support. */ + auth: readonly AuthConfigEntry[]; progress: (line: string) => void; }): Promise<{ selectedAgents: LoadedAgent[]; notRouted: string[] }> { let selectedAgents = args.candidates; @@ -2388,7 +2391,7 @@ export async function selectReviewers(args: { // `effort` reaches only the `claude` CLI, and never a fixed pass. Say so once for a // selected reviewer whose level has no effect, so the setting does not fail silently. // @ref LLP 0006#agent-effort [implements] — built from the selected reviewer list, after the paths filter and the router, so an agent either of them left out is never named; a later pre-check or budget limit can still skip a named one - const effortNote = agentEffortNote(selectedAgents, args.engineOf); + const effortNote = agentEffortNote(selectedAgents, args.engineOf, args.auth); if (effortNote) { args.progress(`Note: ${effortNote}`); } diff --git a/templates/config.jsonc b/templates/config.jsonc index d9e396b..77646ee 100644 --- a/templates/config.jsonc +++ b/templates/config.jsonc @@ -14,9 +14,9 @@ // e.g. `---\nmodel: anthropic/claude-opus-5-5\n---`. `paths: ["packages/ios/**"]` // there limits an agent to changes that touch those globs, and `mention: [octocat]` // names the people the review mentions when that agent asks for a human review. - // `effort: high` (low, medium, high, xhigh or max) sets how much an `anthropic/…` - // agent reasons, on a model that supports effort (Haiku 4.5 does not); other models - // ignore it. + // `effort: high` (low, medium, high, xhigh or max) sets how much an `anthropic/…`, + // `openai/…` or `google/…` agent reasons, on a model that supports effort (Claude + // Haiku 4.5 does not); other models ignore it. // @ref LLP 0009#config-and-prompt-templates [implements] — suggestions off by default, not a schema limit "policy": { From 274fb153a45aac25e99b49b791bf7d8c0d84d2f3 Mon Sep 17 00:00:00 2001 From: szdziedzic Date: Thu, 26 Nov 2026 14:22:12 +0100 Subject: [PATCH 2/9] fix: send no Google level the adapter rejects, and none for non-OpenAI aliases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Astra review of 4f6afb5: - With the pinned OpenCode 1.19.5, thinkingLevel xhigh or max fails inside the Google adapter ("invalid google provider options") before any request, on google/… and google-vertex/…, so every pass of that agent failed. GOOGLE_THINKING_LEVELS is now low, medium, high: for xhigh and max ecr sends no key, the model runs at OpenCode's default, and the run note names the agent, its level and the levels that work. - An alias with upstream "google" is built on @ai-sdk/openai-compatible, so a Google key reached the endpoint as a stray top-level field and the note stayed silent. opencodeEffortStyle now follows the adapter ecr creates: only an upstream "openai" alias takes a level. - The config template lists every route and the Google limit; the comment at selectReviewers no longer says only the claude CLI reads it. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- ...config-schema-loading-routing.explainer.md | 16 ++++-- src/__tests__/claude-code.test.ts | 29 +++++++++++ src/__tests__/opencode.test.ts | 16 +++++- src/core/claude-code.ts | 19 +++++++ src/core/opencode.ts | 50 ++++++++++++------- src/core/review.ts | 5 +- templates/config.jsonc | 7 +-- 8 files changed, 114 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index a172721..b2542c0 100644 --- a/README.md +++ b/README.md @@ -544,7 +544,7 @@ ignores it. Leave it out to use the provider's default. | --- | --- | | `anthropic/…` (Claude Code CLI) | `--effort ` | | `openai/…`, or an alias with `upstream: "openai"` (OpenCode) | `reasoningEffort`, sent as the Responses API `reasoning.effort` | -| `google/…`, `google-vertex/…` (OpenCode) | `thinkingConfig.thinkingLevel`, in place of OpenCode's default `high` | +| `google/…`, `google-vertex/…` (OpenCode) | `thinkingConfig.thinkingLevel`, in place of OpenCode's default `high`; only `low`, `medium` or `high` (for `xhigh` and `max` ecr sends no level, and the run note says so) | ecr passes the level as written and does not check which levels a model takes. A model without effort support can drop it (the Claude Code CLI sends no level to diff --git a/llp/0006-config-schema-loading-routing.explainer.md b/llp/0006-config-schema-loading-routing.explainer.md index adcbafa..9a5d98a 100644 --- a/llp/0006-config-schema-loading-routing.explainer.md +++ b/llp/0006-config-schema-loading-routing.explainer.md @@ -241,15 +241,23 @@ per-agent key and not a run-level flag. (both found in review of the first version, PR #118). - **OpenCode passes it for OpenAI and Google models.** OpenCode hands unknown agent-config keys to the provider as model options. `buildOpencodeConfig` adds one per reviewer with `effort`, chosen - by `opencodeEffortStyle` from the model's provider (an alias takes its auth entry's `upstream`): - `openai` gets `reasoningEffort`, `google` and `google-vertex` get - `thinkingConfig.thinkingLevel`. Observed with the pinned OpenCode 1.19.5 against a local mock + by `opencodeEffortStyle` from the adapter ecr gives the model's provider: native `openai` and an + alias with `upstream: "openai"` (built on `@ai-sdk/openai`) get `reasoningEffort`; native + `google` and `google-vertex` get `thinkingConfig.thinkingLevel`. Any other alias, including + `upstream: "google"` (built on `@ai-sdk/openai-compatible`), gets nothing: a Google key on that + adapter reached a mock endpoint as a top-level `thinkingConfig` on `/chat/completions` (found in + review of PR #119). Observed with the pinned OpenCode 1.19.5 against a local mock endpoint (2026-11-26) [observed]: with no key, an `openai/gpt-6.2-astra` request carried no `reasoning` field; `reasoningEffort: "xhigh"` and `"max"` arrived as `reasoning.effort`; a `google/gemini-4-neon` request carried `thinkingConfig: {includeThoughts: true, thinkingLevel: "high"}` with no key, and `thinkingLevel: "low"` replaced the `high`. Only reviewer entries get the key: the fixed roles are written after the reviewer loop, so a reviewer that shares a fixed - role's id cannot give that pass its level. Not observed: the ChatGPT/Codex sign-in path and a + role's id cannot give that pass its level. The pinned Google adapter takes `thinkingLevel` + `minimal`, `low`, `medium` and `high`; with `xhigh` or `max` the pass failed inside OpenCode + ("invalid google provider options") with no request sent, on `google/…` and `google-vertex/…` + [observed]. So `GOOGLE_THINKING_LEVELS` is `low`, `medium`, `high`: for the other two ecr sends no + key, the model runs at OpenCode's default (`high`), and the run note names the agent, its level + and the levels that work. Not observed: the ChatGPT/Codex sign-in path and a real provider's response to each level. ecr passes the level as written; a provider that does not take it fails that agent's passes with its own error. - **Any other OpenCode-routed agent ignores it, with a note.** `agentEffortNote` names agents whose diff --git a/src/__tests__/claude-code.test.ts b/src/__tests__/claude-code.test.ts index 5c6cd75..a528106 100644 --- a/src/__tests__/claude-code.test.ts +++ b/src/__tests__/claude-code.test.ts @@ -938,6 +938,35 @@ test("agentEffortNote: OpenAI and Google models take a level through OpenCode; o expect(named(agentEffortNote(agents, engineOf, []))).toBe("pro, muse"); }); +test("agentEffortNote: a Google level the pinned adapter rejects is named with the levels it takes", () => { + const agents = [ + { id: "neon", effort: "xhigh", model: "google/gemini-4-neon" }, + { id: "vertex", effort: "max", model: "google-vertex/gemini-4-neon" }, + { id: "ok", effort: "medium", model: "google/gemini-4-neon" }, + ] as unknown as LoadedAgent[]; + const note = agentEffortNote( + agents, + { neon: "opencode", vertex: "opencode", ok: "opencode" }, + [], + ); + expect(note).toContain("has no effect for neon (xhigh), vertex (max): OpenCode's Google adapter"); + expect(note).toContain("takes only low, medium, high"); + expect(note).toContain("Fix: use one of those levels"); + expect(note).not.toContain("ok ("); +}); + +test("agentEffortNote: a Google-upstream alias takes no level and is named", () => { + const agents = [ + { id: "gem", effort: "high", model: "gemini-api/gemini-4-neon" }, + ] as unknown as LoadedAgent[]; + const auth = [ + { provider: "gemini-api", mode: "api-key", tokenEnv: "GEMINI_KEY_2", upstream: "google" }, + ] as unknown as AuthConfigEntry[]; + expect(agentEffortNote(agents, { gem: "opencode" }, auth)).toContain( + "has no effect for gem: the model of each runs through OpenCode on a provider ecr passes no level to", + ); +}); + test("agentEffortNote: a fixed-role reviewer on OpenAI is told only to rename", () => { const agents = [ { id: "verifier", effort: "max", model: "openai/gpt-6.2-astra" }, diff --git a/src/__tests__/opencode.test.ts b/src/__tests__/opencode.test.ts index 3f3d47c..f13456e 100644 --- a/src/__tests__/opencode.test.ts +++ b/src/__tests__/opencode.test.ts @@ -697,6 +697,8 @@ test("opencodeEffortStyle: OpenAI and Google families take a level; others do no const alias = [ { provider: "openai-api", mode: "api-key", tokenEnv: "OPENAI_API_KEY", upstream: "openai" }, { provider: "claude-api", mode: "api-key", tokenEnv: "ANTHROPIC_KEY_2", upstream: "anthropic" }, + // ecr builds this alias with the OpenAI-compatible adapter, not Google's. + { provider: "gemini-api", mode: "api-key", tokenEnv: "GEMINI_KEY_2", upstream: "google" }, ] as unknown as LoadedConfig["auth"]; expect(opencodeEffortStyle("openai/gpt-6.2-astra", [])).toBe("openai"); expect(opencodeEffortStyle("openai-api/gpt-5.5-pro", alias)).toBe("openai"); @@ -704,6 +706,7 @@ test("opencodeEffortStyle: OpenAI and Google families take a level; others do no expect(opencodeEffortStyle("google/gemini-4-neon", [])).toBe("google"); expect(opencodeEffortStyle("google-vertex/gemini-4-neon", [])).toBe("google"); expect(opencodeEffortStyle("claude-api/claude-opus-5-5", alias)).toBeNull(); + expect(opencodeEffortStyle("gemini-api/gemini-4-neon", alias)).toBeNull(); expect(opencodeEffortStyle("meta/muse-spark-1.3", [])).toBeNull(); expect(opencodeEffortStyle("gpt-6.2-astra", [])).toBeNull(); }); @@ -714,6 +717,8 @@ test("buildOpencodeConfig passes a reviewer's effort as its provider's option, a agents: [ { id: "astra", model: "openai/gpt-6.2-astra", effort: "xhigh" }, { id: "neon", model: "google/gemini-4-neon", effort: "low" }, + { id: "neon-x", model: "google/gemini-4-neon", effort: "xhigh" }, + { id: "vertex-max", model: "google-vertex/gemini-4-neon", effort: "max" }, { id: "muse", model: "meta/muse-spark-1.3", effort: "high" }, { id: "plain", model: "openai/gpt-6.2-astra" }, { id: "verifier", model: "openai/gpt-6.2-astra", effort: "max" }, @@ -724,7 +729,16 @@ test("buildOpencodeConfig passes a reviewer's effort as its provider's option, a expect(opencode.agent.astra!.thinkingConfig).toBeUndefined(); expect(opencode.agent.neon!.thinkingConfig).toEqual({ thinkingLevel: "low" }); expect(opencode.agent.neon!.reasoningEffort).toBeUndefined(); - for (const id of ["muse", "plain", VERIFIER_AGENT, CROSS_CUTTING_AGENT, "coordinator"]) { + // The pinned Google adapter rejects xhigh and max, so they get no key at all. + for (const id of [ + "neon-x", + "vertex-max", + "muse", + "plain", + VERIFIER_AGENT, + CROSS_CUTTING_AGENT, + "coordinator", + ]) { expect(opencode.agent[id]!.reasoningEffort, id).toBeUndefined(); expect(opencode.agent[id]!.thinkingConfig, id).toBeUndefined(); } diff --git a/src/core/claude-code.ts b/src/core/claude-code.ts index aa3f0cb..fa1ff2c 100644 --- a/src/core/claude-code.ts +++ b/src/core/claude-code.ts @@ -21,6 +21,7 @@ import { AgentTimeoutError, CLAUDE_CODE_ENGINE, CROSS_CUTTING_AGENT, + GOOGLE_THINKING_LEVELS, opencodeEffortStyle, STACK_VERIFIER_AGENT, VERIFIER_AGENT, @@ -839,6 +840,17 @@ export function agentEffortNote( takesNoLevel(agent.model ?? ""), ) .map((agent) => agent.id); + // A Google model whose level the pinned adapter rejects gets no level (opencodeEffortOptions). + const googleLevelNotTaken = declared + .filter( + (agent) => + !FIXED_ROLE_IDS.has(agent.id) && + engineOf[agent.id] === "opencode" && + opencodeEffortStyle(agent.model ?? "", auth) === "google" && + agent.effort !== undefined && + !GOOGLE_THINKING_LEVELS.has(agent.effort), + ) + .map((agent) => `${agent.id} (${agent.effort})`); const fixedRole = declared .filter((agent) => FIXED_ROLE_IDS.has(agent.id)) .map((agent) => agent.id); @@ -849,6 +861,13 @@ export function agentEffortNote( `OpenCode on a provider ecr passes no level to (${EFFORT_PROVIDERS})`, ); } + if (googleLevelNotTaken.length > 0) { + notes.push( + `\`effort\` has no effect for ${googleLevelNotTaken.join(", ")}: OpenCode's Google adapter ` + + `takes only ${[...GOOGLE_THINKING_LEVELS].join(", ")}, so ecr sends no level and the model ` + + "runs at OpenCode's default. Fix: use one of those levels", + ); + } // The engine map's entry for a fixed-role id describes the built-in pass, so read the // reviewer's own model: after a rename, a model that takes no level still ignores it. const fixedRoleNoLevel = declared diff --git a/src/core/opencode.ts b/src/core/opencode.ts index 2404bc0..36379c5 100644 --- a/src/core/opencode.ts +++ b/src/core/opencode.ts @@ -288,10 +288,12 @@ export type OpencodeEffortStyle = "openai" | "google"; /** * The effort style for a model id, or null when ecr does not pass a level to that - * provider. An upstream alias (auth entry `openai-api` with upstream `openai`) takes its - * upstream's style. Meta, OpenAI-compatible and other providers get null. + * provider. Native `openai` gets the OpenAI style, native `google` and `google-vertex` the + * Google style. An alias (an auth entry with `upstream`) follows the adapter + * `buildOpencodeConfig` creates for it: only `upstream: "openai"` gets `@ai-sdk/openai`, + * so only that alias takes a level. Meta, OpenAI-compatible and other providers get null. */ -// @ref LLP 0006#agent-effort [implements] — OpenCode-routed effort, per provider family +// @ref LLP 0006#agent-effort [implements] — OpenCode-routed effort, per provider adapter export function opencodeEffortStyle( model: string, auth: readonly AuthConfigEntry[], @@ -301,31 +303,41 @@ export function opencodeEffortStyle( return null; } const provider = model.slice(0, slash); - const family = - auth.find((entry) => entry.provider === provider && entry.upstream)?.upstream ?? provider; - if (family === "openai") { + const alias = auth.find((entry) => entry.provider === provider && entry.upstream); + if (alias) { + return alias.upstream === "openai" ? "openai" : null; + } + if (provider === "openai") { return "openai"; } - if (family === "google" || family === "google-vertex") { + if (provider === "google" || provider === "google-vertex") { return "google"; } return null; } /** - * The agent-config keys that carry a reasoning level for an effort style. OpenCode - * passes unknown agent keys to the provider as model options; observed with OpenCode - * 1.19.5 against a mock endpoint (LLP 0006): `reasoningEffort` becomes the Responses - * API's `reasoning.effort`, and `thinkingConfig.thinkingLevel` replaces the `high` that - * OpenCode sends to Gemini by default. + * The levels the pinned OpenCode's Google adapter takes for `thinkingLevel`. With + * OpenCode 1.19.5, `xhigh` and `max` fail locally with "invalid google provider options" + * and no request is sent (LLP 0006), so ecr sends no level for them. + */ +export const GOOGLE_THINKING_LEVELS: ReadonlySet = new Set(["low", "medium", "high"]); + +/** + * The agent-config keys that carry a reasoning level for an effort style, or null when + * the style's adapter does not take that level. OpenCode passes unknown agent keys to + * the provider as model options; observed with OpenCode 1.19.5 against a mock endpoint + * (LLP 0006): `reasoningEffort` becomes the Responses API's `reasoning.effort`, and + * `thinkingConfig.thinkingLevel` replaces the `high` that OpenCode sends to Gemini. */ export function opencodeEffortOptions( style: OpencodeEffortStyle, effort: AgentEffort, -): Record { - return style === "openai" - ? { reasoningEffort: effort } - : { thinkingConfig: { thinkingLevel: effort } }; +): Record | null { + if (style === "openai") { + return { reasoningEffort: effort }; + } + return GOOGLE_THINKING_LEVELS.has(effort) ? { thinkingConfig: { thinkingLevel: effort } } : null; } /** Build the inline OpenCode config (agents + coordinator) from a repo config. */ @@ -337,6 +349,8 @@ export function buildOpencodeConfig( const agent: Record = {}; for (const reviewer of config.agents) { const effortStyle = reviewer.effort ? opencodeEffortStyle(reviewer.model, config.auth) : null; + const effortOptions = + reviewer.effort && effortStyle ? opencodeEffortOptions(effortStyle, reviewer.effort) : null; agent[reviewer.id] = { description: `${reviewer.id} reviewer`, mode: "all", @@ -344,9 +358,7 @@ export function buildOpencodeConfig( temperature: reviewer.temperature, // Only reviewers: the fixed roles below are written after this loop, so a reviewer // that shares a fixed role's id cannot give that pass its level. - ...(reviewer.effort && effortStyle - ? opencodeEffortOptions(effortStyle, reviewer.effort) - : {}), + ...effortOptions, prompt: `You are the ${reviewer.id} code reviewer. Follow the user message exactly and return only the requested JSON.`, tools: { ...reviewer.tools, diff --git a/src/core/review.ts b/src/core/review.ts index 6349842..ba44e10 100644 --- a/src/core/review.ts +++ b/src/core/review.ts @@ -2388,8 +2388,9 @@ export async function selectReviewers(args: { .filter((agent) => !selectedAgents.includes(agent)) .map((agent) => agent.id); - // `effort` reaches only the `claude` CLI, and never a fixed pass. Say so once for a - // selected reviewer whose level has no effect, so the setting does not fail silently. + // `effort` reaches the `claude` CLI and OpenCode's OpenAI and Google adapters, and never + // a fixed pass. Say so once for a selected reviewer whose level has no effect, so the + // setting does not fail silently. // @ref LLP 0006#agent-effort [implements] — built from the selected reviewer list, after the paths filter and the router, so an agent either of them left out is never named; a later pre-check or budget limit can still skip a named one const effortNote = agentEffortNote(selectedAgents, args.engineOf, args.auth); if (effortNote) { diff --git a/templates/config.jsonc b/templates/config.jsonc index 77646ee..abf1404 100644 --- a/templates/config.jsonc +++ b/templates/config.jsonc @@ -14,9 +14,10 @@ // e.g. `---\nmodel: anthropic/claude-opus-5-5\n---`. `paths: ["packages/ios/**"]` // there limits an agent to changes that touch those globs, and `mention: [octocat]` // names the people the review mentions when that agent asks for a human review. - // `effort: high` (low, medium, high, xhigh or max) sets how much an `anthropic/…`, - // `openai/…` or `google/…` agent reasons, on a model that supports effort (Claude - // Haiku 4.5 does not); other models ignore it. + // `effort: high` (low, medium, high, xhigh or max) sets how much an agent reasons on + // `anthropic/…`, `openai/…` (or an `upstream: "openai"` alias), `google/…` or + // `google-vertex/…` models; Google takes only low, medium or high. Other models ignore + // it, and so does a model without effort support (Claude Haiku 4.5). README: "effort". // @ref LLP 0009#config-and-prompt-templates [implements] — suggestions off by default, not a schema limit "policy": { From 9752d90f11579286a7f5241199a3270f98bc8865 Mon Sep 17 00:00:00 2001 From: szdziedzic Date: Thu, 26 Nov 2026 14:38:25 +0100 Subject: [PATCH 3/9] fix: run the OpenCode no-tools fallback at the default effort Kudo's multi-model review of PR #118 found that a timed-out pass, retried with no tools under a short cap, kept the agent's level; #118 now sends no level there on the claude-code engine. The same holds for OpenCode, which has no per-prompt level, so buildOpencodeConfig also registers each reviewer that has an effort option as `__default-effort` without it, and opencodePassAgent sends the fallback prompts (maxToolCalls 0) as that copy. Polling and activity labels keep the reviewer's own id. Observed with OpenCode 1.19.5 against a mock endpoint: the reviewer's entry sent reasoning.effort "xhigh", the copy sent no reasoning field. Also format the rebase conflict resolution (fmt:check). Co-Authored-By: Claude Opus 5.5 --- src/__tests__/claude-code.test.ts | 4 ++- src/__tests__/opencode.test.ts | 32 +++++++++++++++++ src/core/opencode.ts | 57 +++++++++++++++++++++++++++---- 3 files changed, 86 insertions(+), 7 deletions(-) diff --git a/src/__tests__/claude-code.test.ts b/src/__tests__/claude-code.test.ts index a528106..68a0569 100644 --- a/src/__tests__/claude-code.test.ts +++ b/src/__tests__/claude-code.test.ts @@ -993,7 +993,9 @@ test("agentEffortNote: a fixed-role reviewer on a model that takes no level is t ] as unknown as LoadedAgent[]; // The engine map describes the built-in passes (claude here), not the reviewer files. const note = agentEffortNote(agents, { verifier: "claude-code", coordinator: "claude-code" }, []); - expect(note).toContain("Fix: rename the agent file, and run verifier on a model that takes a level"); + expect(note).toContain( + "Fix: rename the agent file, and run verifier on a model that takes a level", + ); expect(note).toContain("`REVIEWER_MODEL` when that is set"); expect(note).not.toContain("give verifier, coordinator"); }); diff --git a/src/__tests__/opencode.test.ts b/src/__tests__/opencode.test.ts index f13456e..215a8e9 100644 --- a/src/__tests__/opencode.test.ts +++ b/src/__tests__/opencode.test.ts @@ -19,6 +19,9 @@ import { STACK_VERIFIER_AGENT, META_MODEL_API_BASE_URL, opencodeEffortStyle, + opencodePassAgent, + defaultEffortAgentIds, + DEFAULT_EFFORT_AGENT_SUFFIX, VERIFIER_AGENT, CROSS_CUTTING_AGENT, } from "../core/opencode.js"; @@ -743,3 +746,32 @@ test("buildOpencodeConfig passes a reviewer's effort as its provider's option, a expect(opencode.agent[id]!.thinkingConfig, id).toBeUndefined(); } }); + +test("the no-tools fallback of a reviewer with an OpenCode level runs as its default-effort copy", () => { + const built = buildOpencodeConfig( + configWith({ + agents: [ + { id: "astra", model: "openai/gpt-6.2-astra", effort: "xhigh" }, + { id: "neon-x", model: "google/gemini-4-neon", effort: "xhigh" }, + { id: "plain", model: "openai/gpt-6.2-astra" }, + ], + }), + ) as { agent: Record> }; + const copy = built.agent[`astra${DEFAULT_EFFORT_AGENT_SUFFIX}`]!; + expect(copy.reasoningEffort).toBeUndefined(); + // Everything else matches the reviewer's own entry. + const { reasoningEffort, ...rest } = built.agent.astra!; + expect(reasoningEffort).toBe("xhigh"); + expect(copy).toEqual(rest); + // No copy without an effort option to drop (a level Google rejects sends none). + expect(built.agent[`neon-x${DEFAULT_EFFORT_AGENT_SUFFIX}`]).toBeUndefined(); + expect(built.agent[`plain${DEFAULT_EFFORT_AGENT_SUFFIX}`]).toBeUndefined(); + + const handle = { defaultEffortAgents: defaultEffortAgentIds(built) }; + expect([...handle.defaultEffortAgents]).toEqual(["astra"]); + expect(opencodePassAgent(handle, "astra", 0)).toBe(`astra${DEFAULT_EFFORT_AGENT_SUFFIX}`); + expect(opencodePassAgent(handle, "astra", undefined)).toBe("astra"); + expect(opencodePassAgent(handle, "astra", 12)).toBe("astra"); + expect(opencodePassAgent(handle, "plain", 0)).toBe("plain"); + expect(opencodePassAgent({}, "astra", 0)).toBe("astra"); +}); diff --git a/src/core/opencode.ts b/src/core/opencode.ts index 36379c5..00af1f8 100644 --- a/src/core/opencode.ts +++ b/src/core/opencode.ts @@ -169,6 +169,11 @@ export interface OpencodeHandle { engineOf?: (agent: string) => Engine; /** Each configured MCP server tool set to false, merged into every no-tools request. */ mcpToolsOff?: Record; + /** + * Reviewer ids that have a default-effort copy in the OpenCode config (their + * no-tools fallback runs as that copy, opencodePassAgent). + */ + defaultEffortAgents?: ReadonlySet; /** The configured MCP servers, so progress lines log only granted calls, by name. */ mcpServers?: Record; /** Set on a CI run that publishes sessions. Absent means capture stays off. */ @@ -340,6 +345,38 @@ export function opencodeEffortOptions( return GOOGLE_THINKING_LEVELS.has(effort) ? { thinkingConfig: { thinkingLevel: effort } } : null; } +/** + * Suffix of the copy of a reviewer that runs at the default effort. buildOpencodeConfig + * registers one for each reviewer that has an OpenCode effort option. + */ +export const DEFAULT_EFFORT_AGENT_SUFFIX = "__default-effort"; + +/** The reviewer ids that have a default-effort copy in a built OpenCode config. */ +export function defaultEffortAgentIds(config: unknown): Set { + const agents = (config as { agent?: Record } | null)?.agent ?? {}; + return new Set( + Object.keys(agents) + .filter((id) => id.endsWith(DEFAULT_EFFORT_AGENT_SUFFIX)) + .map((id) => id.slice(0, -DEFAULT_EFFORT_AGENT_SUFFIX.length)), + ); +} + +/** + * The OpenCode agent a pass runs as. A no-tools fallback pass (maxToolCalls 0) retries a + * timed-out pass under a short cap, so a reviewer with a level runs it as its + * default-effort copy: a deep level under that cap would likely time out again. + */ +// @ref LLP 0006#agent-effort [implements] — the no-tools fallback pass takes no level +export function opencodePassAgent( + handle: Pick, + agent: string, + maxToolCalls: number | undefined, +): string { + return maxToolCalls === 0 && handle.defaultEffortAgents?.has(agent) + ? `${agent}${DEFAULT_EFFORT_AGENT_SUFFIX}` + : agent; +} + /** Build the inline OpenCode config (agents + coordinator) from a repo config. */ export function buildOpencodeConfig( config: LoadedConfig, @@ -351,14 +388,11 @@ export function buildOpencodeConfig( const effortStyle = reviewer.effort ? opencodeEffortStyle(reviewer.model, config.auth) : null; const effortOptions = reviewer.effort && effortStyle ? opencodeEffortOptions(effortStyle, reviewer.effort) : null; - agent[reviewer.id] = { + const entry = { description: `${reviewer.id} reviewer`, mode: "all", model: reviewer.model, temperature: reviewer.temperature, - // Only reviewers: the fixed roles below are written after this loop, so a reviewer - // that shares a fixed role's id cannot give that pass its level. - ...effortOptions, prompt: `You are the ${reviewer.id} code reviewer. Follow the user message exactly and return only the requested JSON.`, tools: { ...reviewer.tools, @@ -366,6 +400,14 @@ export function buildOpencodeConfig( ...opencodeGrantedTools(mcpProxy?.servers, reviewer.id), }, }; + // Only reviewers: the fixed roles below are written after this loop, so a reviewer + // that shares a fixed role's id cannot give that pass its level. + agent[reviewer.id] = effortOptions ? { ...entry, ...effortOptions } : entry; + if (effortOptions) { + // The same reviewer at the default effort, for its no-tools fallback pass + // (opencodePassAgent), as the claude-code engine does. + agent[`${reviewer.id}${DEFAULT_EFFORT_AGENT_SUFFIX}`] = entry; + } } agent[CROSS_CUTTING_AGENT] = { description: "Cross-file reviewer: issues spanning multiple changed files.", @@ -592,6 +634,7 @@ export async function startOpencode( mcpServers?: Record, ): Promise { const mcpToolsOff = opencodeMcpToolsOff(mcpServers); + const defaultEffortAgents = defaultEffortAgentIds(config); // Make our pinned CLI win over any global install (see bundledOpencodeBinDir). // The SDK takes no `env`, so PATH is the only lever; it spreads `process.env` at // spawn time, so setting it here reaches the child. @@ -634,6 +677,7 @@ export async function startOpencode( }, rateLimit: new RateLimitWatch(), ...(Object.keys(mcpToolsOff).length > 0 ? { mcpToolsOff, mcpServers } : {}), + ...(defaultEffortAgents.size > 0 ? { defaultEffortAgents } : {}), }; } @@ -1061,6 +1105,7 @@ export async function promptAgent( const { runClaudePrompt } = await import("./claude-code.js"); return runClaudePrompt(dispatch.claudeHandle, args); } + const passAgent = opencodePassAgent(handle, args.agent, args.maxToolCalls); const maxWaitMs = args.maxWaitMs ?? DEFAULT_MAX_WAIT_MS; // ONE deadline for the whole pass, shared by the first attempt and any stall // retry, so retrying a wedged request can never push the pass past its declared @@ -1104,7 +1149,7 @@ export async function promptAgent( : "time budget reached — asking for findings so far", ); await sendSessionPrompt(handle, sessionID, { - agent: args.agent, + agent: passAgent, system: args.system, text: FINALIZE_PROMPT, tools: { ...NO_TOOLS, ...handle.mcpToolsOff }, @@ -1144,7 +1189,7 @@ export async function promptAgent( ); const reportedTools = new Set(); await sendSessionPrompt(handle, session.id, { - agent: args.agent, + agent: passAgent, system: args.system, text: args.text, // A pass with no tool budget must not reach a remote MCP server either. From fa22f36c0aae490e2b0181b9bbc0ec6b7ef14a3e Mon Sep 17 00:00:00 2001 From: szdziedzic Date: Thu, 26 Nov 2026 15:17:11 +0100 Subject: [PATCH 4/9] fix: give the OpenCode fallback a min(level, medium) copy, safely Gemini Neon review of 753305d: - A reviewer that shares a fixed role's id (agents/cross-cutting.md) left a `__default-effort` copy behind, and the built-in pass's no-tools fallback then ran as that copy, with the reviewer's model, prompt and tools. Fixed-role ids now get no level and no copy. - The handle inferred copies from any agent name ending in the suffix, so a real agent file with that name could take over another reviewer's fallback. opencodeFallbackAgents now computes the map from the loaded config, skips a copy id that is already an agent id, and runReview hands the map to startOpencode. - A copy with no level ran at the provider's default, which can be higher than the agent's own level (Gemini's default is high). The copy now carries fallbackEffort (min(level, medium), as #118 does on the claude-code engine), and exists only when that differs from the reviewer's own options. Renamed to `__fallback-effort`. - The corrective re-emit of a fallback pass ran as the reviewer at its full level; it now runs as the same copy. - The run note for a fixed-role reviewer on Google xhigh/max also names the levels Google takes; a test assertion that could never fail now checks the note's end; the effort docs no longer say only the claude-code engine reads it. Observed with OpenCode 1.19.5 against a mock endpoint, using the config buildOpencodeConfig produces: xhigh OpenAI reviewer "xhigh", its copy "medium"; max Google reviewer OpenCode's default "high", its copy "medium". Co-Authored-By: Claude Opus 5.5 --- ...config-schema-loading-routing.explainer.md | 19 +++- src/__tests__/claude-code.test.ts | 12 ++- src/__tests__/opencode.test.ts | 70 +++++++++----- src/config/schema.ts | 5 +- src/core/claude-code.ts | 17 +++- src/core/opencode.ts | 94 ++++++++++++------- src/core/review.ts | 2 + 7 files changed, 152 insertions(+), 67 deletions(-) diff --git a/llp/0006-config-schema-loading-routing.explainer.md b/llp/0006-config-schema-loading-routing.explainer.md index 9a5d98a..3d42f23 100644 --- a/llp/0006-config-schema-loading-routing.explainer.md +++ b/llp/0006-config-schema-loading-routing.explainer.md @@ -254,8 +254,10 @@ per-agent key and not a run-level flag. the key: the fixed roles are written after the reviewer loop, so a reviewer that shares a fixed role's id cannot give that pass its level. The pinned Google adapter takes `thinkingLevel` `minimal`, `low`, `medium` and `high`; with `xhigh` or `max` the pass failed inside OpenCode - ("invalid google provider options") with no request sent, on `google/…` and `google-vertex/…` - [observed]. So `GOOGLE_THINKING_LEVELS` is `low`, `medium`, `high`: for the other two ecr sends no + (an invalid-provider-options error) with no request sent, on `google/…` and `google-vertex/…` + [observed]. OpenCode's model catalog lists more variants for some Gemini models; the limit comes + from the bundled Google SDK's option schema, so re-check it when the OpenCode pins move. So + `GOOGLE_THINKING_LEVELS` is `low`, `medium`, `high`: for the other two ecr sends no key, the model runs at OpenCode's default (`high`), and the run note names the agent, its level and the levels that work. Not observed: the ChatGPT/Codex sign-in path and a real provider's response to each level. ecr passes the level as written; a provider that does @@ -278,7 +280,18 @@ per-agent key and not a run-level flag. (found in a multi-model review of PR #118, not measured in a live run), and sending no level would use the provider's default, which can be higher than the agent's own `low` (OpenCode sends Gemini `high` by default; found in review of PR #119). So `fallbackEffort` caps the level at - `medium` and never raises it, and `runClaudePrompt` passes that for the fallback. + `medium` and never raises it, and `runClaudePrompt` passes that for the fallback. OpenCode reads + the level from the agent config, so `opencodeFallbackAgents` gives each reviewer whose fallback + options differ from its own a copy, `__fallback-effort`, at the fallback level; + `opencodePassAgent` sends the fallback's prompts, including the corrective re-emit, as that copy. + No copy for a fixed-role id (it would become the built-in pass's fallback) or when the copy id is + already an agent id; `runReview` hands the map to `startOpencode` instead of the handle inferring + it from agent names (both found in review of PR #119). Observed with OpenCode 1.19.5 against a + mock endpoint, using the config `buildOpencodeConfig` produces (2026-11-26) [observed]: an + `xhigh` OpenAI reviewer sent `reasoning.effort: "xhigh"` and its copy `"medium"`; a `max` Google + reviewer sent OpenCode's default `thinkingLevel: "high"` and its copy `"medium"`. An OpenCode per-prompt `variant` exists, + but it maps to catalog variants, which the alias models ecr declares do not have (per that + review, not checked here). - **An invalid level never stops a review.** `parseAgentEffort` returns a setup warning with the fix and no `effort`, so the agent runs at the default. The warning does not repeat the value: a backtick in it would close the code span in the review comment, and setup notes are not diff --git a/src/__tests__/claude-code.test.ts b/src/__tests__/claude-code.test.ts index 68a0569..8865c13 100644 --- a/src/__tests__/claude-code.test.ts +++ b/src/__tests__/claude-code.test.ts @@ -967,13 +967,21 @@ test("agentEffortNote: a Google-upstream alias takes no level and is named", () ); }); +test("agentEffortNote: a fixed-role reviewer on Google xhigh is also told the levels Google takes", () => { + const agents = [ + { id: "verifier", effort: "xhigh", model: "google/gemini-4-neon" }, + ] as unknown as LoadedAgent[]; + const note = agentEffortNote(agents, { verifier: "claude-code" }, []); + expect(note).toContain("Fix: rename the agent file, and give verifier one of low, medium, high"); +}); + test("agentEffortNote: a fixed-role reviewer on OpenAI is told only to rename", () => { const agents = [ { id: "verifier", effort: "max", model: "openai/gpt-6.2-astra" }, ] as unknown as LoadedAgent[]; const note = agentEffortNote(agents, { verifier: "claude-code" }, []); expect(note).toContain("Fix: rename the agent file"); - expect(note).not.toContain("give verifier a model"); + expect(note?.endsWith("Fix: rename the agent file")).toBe(true); }); test("agentEffortNote: reports both reasons in one note", () => { @@ -997,7 +1005,7 @@ test("agentEffortNote: a fixed-role reviewer on a model that takes no level is t "Fix: rename the agent file, and run verifier on a model that takes a level", ); expect(note).toContain("`REVIEWER_MODEL` when that is set"); - expect(note).not.toContain("give verifier, coordinator"); + expect(note).not.toContain("run verifier, coordinator"); }); test("agentEffortNote: a reviewer that shares a fixed role's id is told to rename", () => { diff --git a/src/__tests__/opencode.test.ts b/src/__tests__/opencode.test.ts index 215a8e9..504eaf2 100644 --- a/src/__tests__/opencode.test.ts +++ b/src/__tests__/opencode.test.ts @@ -20,8 +20,8 @@ import { META_MODEL_API_BASE_URL, opencodeEffortStyle, opencodePassAgent, - defaultEffortAgentIds, - DEFAULT_EFFORT_AGENT_SUFFIX, + opencodeFallbackAgents, + FALLBACK_AGENT_SUFFIX, VERIFIER_AGENT, CROSS_CUTTING_AGENT, } from "../core/opencode.js"; @@ -747,31 +747,51 @@ test("buildOpencodeConfig passes a reviewer's effort as its provider's option, a } }); -test("the no-tools fallback of a reviewer with an OpenCode level runs as its default-effort copy", () => { - const built = buildOpencodeConfig( - configWith({ - agents: [ - { id: "astra", model: "openai/gpt-6.2-astra", effort: "xhigh" }, - { id: "neon-x", model: "google/gemini-4-neon", effort: "xhigh" }, - { id: "plain", model: "openai/gpt-6.2-astra" }, - ], - }), - ) as { agent: Record> }; - const copy = built.agent[`astra${DEFAULT_EFFORT_AGENT_SUFFIX}`]!; - expect(copy.reasoningEffort).toBeUndefined(); - // Everything else matches the reviewer's own entry. - const { reasoningEffort, ...rest } = built.agent.astra!; +test("a reviewer's no-tools fallback runs as a copy at min(level, medium), only when that differs", () => { + const config = configWith({ + agents: [ + { id: "astra", model: "openai/gpt-6.2-astra", effort: "xhigh" }, + { id: "astra-low", model: "openai/gpt-6.2-astra", effort: "low" }, + { id: "neon-x", model: "google/gemini-4-neon", effort: "xhigh" }, + { id: "neon-low", model: "google/gemini-4-neon", effort: "low" }, + { id: "plain", model: "openai/gpt-6.2-astra" }, + // A reviewer that shares a fixed role's id gets no level and no copy: a copy + // would become the built-in pass's fallback. + { id: "cross-cutting", model: "openai/gpt-6.2-astra", effort: "high" }, + // The copy id is taken by a real reviewer, so `dup` gets no copy. + { id: "dup", model: "openai/gpt-6.2-astra", effort: "max" }, + { id: `dup${FALLBACK_AGENT_SUFFIX}`, model: "google/gemini-4-neon" }, + ], + }); + const copies = opencodeFallbackAgents(config); + expect([...copies]).toEqual([ + ["astra", `astra${FALLBACK_AGENT_SUFFIX}`], + ["neon-x", `neon-x${FALLBACK_AGENT_SUFFIX}`], + ]); + + const built = buildOpencodeConfig(config) as { agent: Record> }; + const { reasoningEffort, ...astraRest } = built.agent.astra!; expect(reasoningEffort).toBe("xhigh"); - expect(copy).toEqual(rest); - // No copy without an effort option to drop (a level Google rejects sends none). - expect(built.agent[`neon-x${DEFAULT_EFFORT_AGENT_SUFFIX}`]).toBeUndefined(); - expect(built.agent[`plain${DEFAULT_EFFORT_AGENT_SUFFIX}`]).toBeUndefined(); - - const handle = { defaultEffortAgents: defaultEffortAgentIds(built) }; - expect([...handle.defaultEffortAgents]).toEqual(["astra"]); - expect(opencodePassAgent(handle, "astra", 0)).toBe(`astra${DEFAULT_EFFORT_AGENT_SUFFIX}`); + expect(built.agent[`astra${FALLBACK_AGENT_SUFFIX}`]).toEqual({ + ...astraRest, + reasoningEffort: "medium", + }); + // Google xhigh sends no level on the main pass; its fallback sends medium. + expect(built.agent["neon-x"]!.thinkingConfig).toBeUndefined(); + expect(built.agent[`neon-x${FALLBACK_AGENT_SUFFIX}`]!.thinkingConfig).toEqual({ + thinkingLevel: "medium", + }); + for (const id of ["astra-low", "neon-low", "plain", "cross-cutting"]) { + expect(built.agent[`${id}${FALLBACK_AGENT_SUFFIX}`], id).toBeUndefined(); + } + // The real reviewer keeps its own entry. + expect(built.agent[`dup${FALLBACK_AGENT_SUFFIX}`]!.model).toBe("google/gemini-4-neon"); + + const handle = { fallbackAgents: copies }; + expect(opencodePassAgent(handle, "astra", 0)).toBe(`astra${FALLBACK_AGENT_SUFFIX}`); expect(opencodePassAgent(handle, "astra", undefined)).toBe("astra"); expect(opencodePassAgent(handle, "astra", 12)).toBe("astra"); - expect(opencodePassAgent(handle, "plain", 0)).toBe("plain"); + expect(opencodePassAgent(handle, "astra-low", 0)).toBe("astra-low"); + expect(opencodePassAgent(handle, "cross-cutting", 0)).toBe("cross-cutting"); expect(opencodePassAgent({}, "astra", 0)).toBe("astra"); }); diff --git a/src/config/schema.ts b/src/config/schema.ts index 01fcb55..5a56f5e 100644 --- a/src/config/schema.ts +++ b/src/config/schema.ts @@ -584,7 +584,7 @@ export const ScopeReviewConfigSchema = ReviewConfigSchema.omit({ }); export type RawScopeReviewConfig = z.infer; -/** The effort levels the `claude` CLI takes for `--effort`. */ +/** The effort levels an agent may set. Each engine maps them (LLP 0006, "Agent Effort"). */ export const AGENT_EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"] as const; export type AgentEffort = (typeof AGENT_EFFORT_LEVELS)[number]; @@ -623,7 +623,8 @@ export interface LoadedAgent { paths?: string[]; /** * Frontmatter `effort`: how much reasoning the model spends on this agent's passes. - * Only the claude-code engine reads it. Absent means the CLI's own default. + * The claude-code engine passes it as `--effort`; OpenCode passes it for OpenAI and + * Google models (opencodeEffortStyle). Absent means the provider's own default. */ effort?: AgentEffort; /** diff --git a/src/core/claude-code.ts b/src/core/claude-code.ts index fa1ff2c..753b68f 100644 --- a/src/core/claude-code.ts +++ b/src/core/claude-code.ts @@ -873,6 +873,16 @@ export function agentEffortNote( const fixedRoleNoLevel = declared .filter((agent) => FIXED_ROLE_IDS.has(agent.id) && takesNoLevel(agent.model ?? "")) .map((agent) => agent.id); + // After a rename, a Google model still drops a level its adapter does not take. + const fixedRoleGoogleLevel = declared + .filter( + (agent) => + FIXED_ROLE_IDS.has(agent.id) && + opencodeEffortStyle(agent.model ?? "", auth) === "google" && + agent.effort !== undefined && + !GOOGLE_THINKING_LEVELS.has(agent.effort), + ) + .map((agent) => agent.id); if (fixedRole.length > 0) { notes.push( `\`effort\` has no effect for ${fixedRole.join(", ")}: the id is also a built-in pass, which ` + @@ -880,6 +890,10 @@ export function agentEffortNote( (fixedRoleNoLevel.length > 0 ? `, and run ${fixedRoleNoLevel.join(", ")} on a model that takes a level ` + `(${EFFORT_PROVIDERS}; its \`model:\`, or \`REVIEWER_MODEL\` when that is set)` + : "") + + (fixedRoleGoogleLevel.length > 0 + ? `, and give ${fixedRoleGoogleLevel.join(", ")} one of ` + + `${[...GOOGLE_THINKING_LEVELS].join(", ")} (OpenCode's Google adapter takes no other)` : ""), ); } @@ -887,7 +901,8 @@ export function agentEffortNote( } /** The model families ecr passes an effort level to, for the run notes. */ -const EFFORT_PROVIDERS = "`anthropic/…`, `openai/…`, `google/…` or `google-vertex/…`"; +const EFFORT_PROVIDERS = + '`anthropic/…`, `openai/…` (or an `upstream: "openai"` alias), `google/…` or `google-vertex/…`'; /** * Preserve actionable process diagnostics without copying arbitrary stderr into a diff --git a/src/core/opencode.ts b/src/core/opencode.ts index 00af1f8..418a460 100644 --- a/src/core/opencode.ts +++ b/src/core/opencode.ts @@ -5,6 +5,7 @@ import path from "node:path"; import { createOpencode } from "@opencode-ai/sdk"; +import { fallbackEffort } from "../config/schema.js"; import type { AgentEffort, AuthConfigEntry, @@ -16,6 +17,7 @@ import type { // branches below; claude-code.ts statically imports the shared helpers here. import type { ClaudeCodeHandle, Engine } from "./claude-code.js"; import type { SessionCapture } from "./session-archive.js"; +import { NON_REVIEWER_AGENTS } from "./session-archive.js"; import { pathInside, resolveOnPath } from "./exec.js"; import { RateLimitWatch } from "./throttle.js"; import { OPENCODE_RESEARCH_TOOLS, toolMap } from "./tools.js"; @@ -170,10 +172,10 @@ export interface OpencodeHandle { /** Each configured MCP server tool set to false, merged into every no-tools request. */ mcpToolsOff?: Record; /** - * Reviewer ids that have a default-effort copy in the OpenCode config (their - * no-tools fallback runs as that copy, opencodePassAgent). + * Reviewer id → its fallback copy in the OpenCode config (opencodeFallbackAgents); the + * reviewer's no-tools fallback runs as that copy (opencodePassAgent). */ - defaultEffortAgents?: ReadonlySet; + fallbackAgents?: ReadonlyMap; /** The configured MCP servers, so progress lines log only granted calls, by name. */ mcpServers?: Record; /** Set on a CI run that publishes sessions. Absent means capture stays off. */ @@ -323,7 +325,7 @@ export function opencodeEffortStyle( /** * The levels the pinned OpenCode's Google adapter takes for `thinkingLevel`. With - * OpenCode 1.19.5, `xhigh` and `max` fail locally with "invalid google provider options" + * OpenCode 1.19.5, `xhigh` and `max` fail locally with an invalid-provider-options error * and no request is sent (LLP 0006), so ecr sends no level for them. */ export const GOOGLE_THINKING_LEVELS: ReadonlySet = new Set(["low", "medium", "high"]); @@ -345,36 +347,52 @@ export function opencodeEffortOptions( return GOOGLE_THINKING_LEVELS.has(effort) ? { thinkingConfig: { thinkingLevel: effort } } : null; } +/** Suffix of a reviewer's fallback copy (see opencodeFallbackAgents). */ +export const FALLBACK_AGENT_SUFFIX = "__fallback-effort"; + /** - * Suffix of the copy of a reviewer that runs at the default effort. buildOpencodeConfig - * registers one for each reviewer that has an OpenCode effort option. + * Reviewer id → the id of its fallback copy: the same OpenCode agent with the level of + * `fallbackEffort` (min(level, medium)), which the reviewer's no-tools fallback pass runs + * as, because OpenCode takes the level from the agent config. Only reviewers whose + * fallback options differ from their own get a copy. None for a fixed-role id (the + * built-in pass replaces that entry, so a copy would hijack the built-in pass's fallback) + * or when the copy id is already an agent id. */ -export const DEFAULT_EFFORT_AGENT_SUFFIX = "__default-effort"; - -/** The reviewer ids that have a default-effort copy in a built OpenCode config. */ -export function defaultEffortAgentIds(config: unknown): Set { - const agents = (config as { agent?: Record } | null)?.agent ?? {}; - return new Set( - Object.keys(agents) - .filter((id) => id.endsWith(DEFAULT_EFFORT_AGENT_SUFFIX)) - .map((id) => id.slice(0, -DEFAULT_EFFORT_AGENT_SUFFIX.length)), - ); +// @ref LLP 0006#agent-effort [implements] — the no-tools fallback runs at min(level, medium); OpenCode needs a copy agent for it +export function opencodeFallbackAgents(config: LoadedConfig): Map { + const taken = new Set([...config.agents.map((agent) => agent.id), ...NON_REVIEWER_AGENTS]); + const copies = new Map(); + for (const reviewer of config.agents) { + if (!reviewer.effort || NON_REVIEWER_AGENTS.has(reviewer.id)) { + continue; + } + const style = opencodeEffortStyle(reviewer.model, config.auth); + if (!style) { + continue; + } + const own = opencodeEffortOptions(style, reviewer.effort); + const fallback = opencodeEffortOptions(style, fallbackEffort(reviewer.effort)); + if (JSON.stringify(own) === JSON.stringify(fallback)) { + continue; + } + const copy = `${reviewer.id}${FALLBACK_AGENT_SUFFIX}`; + if (!taken.has(copy)) { + copies.set(reviewer.id, copy); + } + } + return copies; } /** - * The OpenCode agent a pass runs as. A no-tools fallback pass (maxToolCalls 0) retries a - * timed-out pass under a short cap, so a reviewer with a level runs it as its - * default-effort copy: a deep level under that cap would likely time out again. + * The OpenCode agent a pass runs as: a no-tools fallback pass (maxToolCalls 0) of a + * reviewer with a fallback copy runs as that copy; every other pass as the agent itself. */ -// @ref LLP 0006#agent-effort [implements] — the no-tools fallback pass takes no level export function opencodePassAgent( - handle: Pick, + handle: Pick, agent: string, maxToolCalls: number | undefined, ): string { - return maxToolCalls === 0 && handle.defaultEffortAgents?.has(agent) - ? `${agent}${DEFAULT_EFFORT_AGENT_SUFFIX}` - : agent; + return maxToolCalls === 0 ? (handle.fallbackAgents?.get(agent) ?? agent) : agent; } /** Build the inline OpenCode config (agents + coordinator) from a repo config. */ @@ -384,8 +402,14 @@ export function buildOpencodeConfig( mcpProxy?: McpProxyRuntime, ): Record { const agent: Record = {}; + const fallbackAgents = opencodeFallbackAgents(config); for (const reviewer of config.agents) { - const effortStyle = reviewer.effort ? opencodeEffortStyle(reviewer.model, config.auth) : null; + // No level for a reviewer that shares a fixed role's id: the built-in pass written + // after this loop replaces its entry. + const effortStyle = + reviewer.effort && !NON_REVIEWER_AGENTS.has(reviewer.id) + ? opencodeEffortStyle(reviewer.model, config.auth) + : null; const effortOptions = reviewer.effort && effortStyle ? opencodeEffortOptions(effortStyle, reviewer.effort) : null; const entry = { @@ -400,13 +424,13 @@ export function buildOpencodeConfig( ...opencodeGrantedTools(mcpProxy?.servers, reviewer.id), }, }; - // Only reviewers: the fixed roles below are written after this loop, so a reviewer - // that shares a fixed role's id cannot give that pass its level. agent[reviewer.id] = effortOptions ? { ...entry, ...effortOptions } : entry; - if (effortOptions) { - // The same reviewer at the default effort, for its no-tools fallback pass - // (opencodePassAgent), as the claude-code engine does. - agent[`${reviewer.id}${DEFAULT_EFFORT_AGENT_SUFFIX}`] = entry; + const copy = fallbackAgents.get(reviewer.id); + if (copy && effortStyle && reviewer.effort) { + agent[copy] = { + ...entry, + ...opencodeEffortOptions(effortStyle, fallbackEffort(reviewer.effort)), + }; } } agent[CROSS_CUTTING_AGENT] = { @@ -632,9 +656,10 @@ export async function resolveOpencodeCli(): Promise { export async function startOpencode( config: unknown, mcpServers?: Record, + /** opencodeFallbackAgents for the config this server runs. */ + fallbackAgents?: ReadonlyMap, ): Promise { const mcpToolsOff = opencodeMcpToolsOff(mcpServers); - const defaultEffortAgents = defaultEffortAgentIds(config); // Make our pinned CLI win over any global install (see bundledOpencodeBinDir). // The SDK takes no `env`, so PATH is the only lever; it spreads `process.env` at // spawn time, so setting it here reaches the child. @@ -677,7 +702,7 @@ export async function startOpencode( }, rateLimit: new RateLimitWatch(), ...(Object.keys(mcpToolsOff).length > 0 ? { mcpToolsOff, mcpServers } : {}), - ...(defaultEffortAgents.size > 0 ? { defaultEffortAgents } : {}), + ...(fallbackAgents && fallbackAgents.size > 0 ? { fallbackAgents } : {}), }; } @@ -1412,7 +1437,8 @@ export async function promptAndParse( try { const baseline = (await fetchMessages(handle, first.sessionID)).length; await sendSessionPrompt(handle, first.sessionID, { - agent: args.agent, + // The same agent the pass ran as: a fallback pass re-emits at its fallback level. + agent: opencodePassAgent(handle, args.agent, args.maxToolCalls), system: args.system, text: CORRECTIVE, // Re-emit only: the investigation is done, so no tools are needed and diff --git a/src/core/review.ts b/src/core/review.ts index ba44e10..12983bc 100644 --- a/src/core/review.ts +++ b/src/core/review.ts @@ -20,6 +20,7 @@ import { AgentTimeoutError, assertModelsResolvable, buildOpencodeConfig, + opencodeFallbackAgents, CLAUDE_CODE_ENGINE, CROSS_CUTTING_AGENT, promptAndParse, @@ -531,6 +532,7 @@ export async function runReview( opencodeHandle = await startOpencode( buildOpencodeConfig(config, researchRuntime, mcpProxy), mcpProxy?.servers, + opencodeFallbackAgents(config), ); } } catch (error) { From df799db15922d52c3420204480896e0e9d747ff9 Mon Sep 17 00:00:00 2001 From: szdziedzic Date: Thu, 26 Nov 2026 15:28:00 +0100 Subject: [PATCH 5/9] fix: drop the OpenCode fallback copy; no level on OpenCode's own agents Astra review of fa22f36: - The fallback copy at min(level, medium) sent a level the author never wrote, and a model can reject it (GPT-5 pro takes only `high`, per the provider's docs), which turned a working setup into failed passes. ecr cannot know which lower levels each OpenAI or Google model takes, so on OpenCode every prompt of a pass, including the no-tools fallback, finalize and corrective, now runs at the agent's own level. This removes the copy agent, its map on the handle and its start-up wiring. The claude-code engine keeps fallbackEffort (#118). - A reviewer named `compaction` replaced OpenCode's own agent, and its level then reached other reviewers' session compaction. OpenCode 1.19.5 defines build, compaction, explore, general, plan, summary and title (app.agents(), observed); buildOpencodeConfig gives these ids no level (OPENCODE_BUILTIN_AGENTS) and the run note says to rename the file. Kept from the previous commits: no level for ecr's fixed-role ids, the fixed-role note's Google levels, the alias in the provider list, and the test fix. Co-Authored-By: Claude Opus 5.5 --- ...config-schema-loading-routing.explainer.md | 25 ++--- src/__tests__/claude-code.test.ts | 12 +++ src/__tests__/opencode.test.ts | 72 +++++--------- src/core/claude-code.ts | 18 ++++ src/core/opencode.ts | 98 +++++-------------- src/core/review.ts | 2 - 6 files changed, 92 insertions(+), 135 deletions(-) diff --git a/llp/0006-config-schema-loading-routing.explainer.md b/llp/0006-config-schema-loading-routing.explainer.md index 3d42f23..5c78c79 100644 --- a/llp/0006-config-schema-loading-routing.explainer.md +++ b/llp/0006-config-schema-loading-routing.explainer.md @@ -262,6 +262,12 @@ per-agent key and not a run-level flag. and the levels that work. Not observed: the ChatGPT/Codex sign-in path and a real provider's response to each level. ecr passes the level as written; a provider that does not take it fails that agent's passes with its own error. +- **No level on OpenCode's own agent ids.** OpenCode 1.19.5 defines `build`, `compaction`, + `explore`, `general`, `plan`, `summary` and `title` (`app.agents()`, 2026-11-26) [observed]; a + reviewer config with one of these ids replaces that agent, and `compaction`, `summary` and `title` + also run for other sessions. A reviewer level there reached another reviewer's session + compaction (found in review of PR #119), so `buildOpencodeConfig` gives these ids no level + (`OPENCODE_BUILTIN_AGENTS`), and the run note tells the author to rename the file. - **Any other OpenCode-routed agent ignores it, with a note.** `agentEffortNote` names agents whose OpenCode provider takes no level (Meta, OpenAI-compatible and others) once per run, the same way `claudeTemperatureNote` reports a temperature the CLI cannot take. @@ -280,18 +286,13 @@ per-agent key and not a run-level flag. (found in a multi-model review of PR #118, not measured in a live run), and sending no level would use the provider's default, which can be higher than the agent's own `low` (OpenCode sends Gemini `high` by default; found in review of PR #119). So `fallbackEffort` caps the level at - `medium` and never raises it, and `runClaudePrompt` passes that for the fallback. OpenCode reads - the level from the agent config, so `opencodeFallbackAgents` gives each reviewer whose fallback - options differ from its own a copy, `__fallback-effort`, at the fallback level; - `opencodePassAgent` sends the fallback's prompts, including the corrective re-emit, as that copy. - No copy for a fixed-role id (it would become the built-in pass's fallback) or when the copy id is - already an agent id; `runReview` hands the map to `startOpencode` instead of the handle inferring - it from agent names (both found in review of PR #119). Observed with OpenCode 1.19.5 against a - mock endpoint, using the config `buildOpencodeConfig` produces (2026-11-26) [observed]: an - `xhigh` OpenAI reviewer sent `reasoning.effort: "xhigh"` and its copy `"medium"`; a `max` Google - reviewer sent OpenCode's default `thinkingLevel: "high"` and its copy `"medium"`. An OpenCode per-prompt `variant` exists, - but it maps to catalog variants, which the alias models ecr declares do not have (per that - review, not checked here). + `medium` and never raises it, and `runClaudePrompt` passes that for the fallback. On OpenCode + the fallback, and the finalize and corrective prompts, run at the agent's own level: OpenCode reads + the level from the agent config, and ecr cannot know which lower levels a model takes (GPT-5 pro + takes only `high`, per the provider's docs cited in review of PR #119), so it never sends a level + the author did not write. An earlier version of PR #119 gave each such reviewer a + `__fallback-effort` copy at `min(level, medium)`; review showed it could send a rejected + level, so it was removed. - **An invalid level never stops a review.** `parseAgentEffort` returns a setup warning with the fix and no `effort`, so the agent runs at the default. The warning does not repeat the value: a backtick in it would close the code span in the review comment, and setup notes are not diff --git a/src/__tests__/claude-code.test.ts b/src/__tests__/claude-code.test.ts index 8865c13..9bd7e71 100644 --- a/src/__tests__/claude-code.test.ts +++ b/src/__tests__/claude-code.test.ts @@ -975,6 +975,18 @@ test("agentEffortNote: a fixed-role reviewer on Google xhigh is also told the le expect(note).toContain("Fix: rename the agent file, and give verifier one of low, medium, high"); }); +test("agentEffortNote: an OpenCode reviewer named after an OpenCode built-in agent is told to rename", () => { + const agents = [ + { id: "compaction", effort: "xhigh", model: "openai/gpt-6.2-astra" }, + ] as unknown as LoadedAgent[]; + const note = agentEffortNote(agents, { compaction: "opencode" }, []); + expect(note).toContain("has no effect for compaction: the id is also an OpenCode built-in agent"); + expect(note).toContain("Fix: rename the agent file"); + expect(note).not.toContain("runs through OpenCode on a provider"); + // On the claude-code engine the level does apply, so there is no note. + expect(agentEffortNote(agents, { compaction: "claude-code" }, [])).toBeNull(); +}); + test("agentEffortNote: a fixed-role reviewer on OpenAI is told only to rename", () => { const agents = [ { id: "verifier", effort: "max", model: "openai/gpt-6.2-astra" }, diff --git a/src/__tests__/opencode.test.ts b/src/__tests__/opencode.test.ts index 504eaf2..1233991 100644 --- a/src/__tests__/opencode.test.ts +++ b/src/__tests__/opencode.test.ts @@ -19,9 +19,7 @@ import { STACK_VERIFIER_AGENT, META_MODEL_API_BASE_URL, opencodeEffortStyle, - opencodePassAgent, - opencodeFallbackAgents, - FALLBACK_AGENT_SUFFIX, + OPENCODE_BUILTIN_AGENTS, VERIFIER_AGENT, CROSS_CUTTING_AGENT, } from "../core/opencode.js"; @@ -747,51 +745,27 @@ test("buildOpencodeConfig passes a reviewer's effort as its provider's option, a } }); -test("a reviewer's no-tools fallback runs as a copy at min(level, medium), only when that differs", () => { - const config = configWith({ - agents: [ - { id: "astra", model: "openai/gpt-6.2-astra", effort: "xhigh" }, - { id: "astra-low", model: "openai/gpt-6.2-astra", effort: "low" }, - { id: "neon-x", model: "google/gemini-4-neon", effort: "xhigh" }, - { id: "neon-low", model: "google/gemini-4-neon", effort: "low" }, - { id: "plain", model: "openai/gpt-6.2-astra" }, - // A reviewer that shares a fixed role's id gets no level and no copy: a copy - // would become the built-in pass's fallback. - { id: "cross-cutting", model: "openai/gpt-6.2-astra", effort: "high" }, - // The copy id is taken by a real reviewer, so `dup` gets no copy. - { id: "dup", model: "openai/gpt-6.2-astra", effort: "max" }, - { id: `dup${FALLBACK_AGENT_SUFFIX}`, model: "google/gemini-4-neon" }, - ], - }); - const copies = opencodeFallbackAgents(config); - expect([...copies]).toEqual([ - ["astra", `astra${FALLBACK_AGENT_SUFFIX}`], - ["neon-x", `neon-x${FALLBACK_AGENT_SUFFIX}`], +test("buildOpencodeConfig gives no level to a reviewer that shares an OpenCode built-in agent id", () => { + const opencode = buildOpencodeConfig( + configWith({ + agents: [ + { id: "compaction", model: "openai/gpt-6.2-astra", effort: "xhigh" }, + { id: "title", model: "google/gemini-4-neon", effort: "low" }, + { id: "astra", model: "openai/gpt-6.2-astra", effort: "xhigh" }, + ], + }), + ) as { agent: Record> }; + // OpenCode also runs these for other sessions (compaction, titles), so no level there. + expect(opencode.agent.compaction!.reasoningEffort).toBeUndefined(); + expect(opencode.agent.title!.thinkingConfig).toBeUndefined(); + expect(opencode.agent.astra!.reasoningEffort).toBe("xhigh"); + expect([...OPENCODE_BUILTIN_AGENTS].sort()).toEqual([ + "build", + "compaction", + "explore", + "general", + "plan", + "summary", + "title", ]); - - const built = buildOpencodeConfig(config) as { agent: Record> }; - const { reasoningEffort, ...astraRest } = built.agent.astra!; - expect(reasoningEffort).toBe("xhigh"); - expect(built.agent[`astra${FALLBACK_AGENT_SUFFIX}`]).toEqual({ - ...astraRest, - reasoningEffort: "medium", - }); - // Google xhigh sends no level on the main pass; its fallback sends medium. - expect(built.agent["neon-x"]!.thinkingConfig).toBeUndefined(); - expect(built.agent[`neon-x${FALLBACK_AGENT_SUFFIX}`]!.thinkingConfig).toEqual({ - thinkingLevel: "medium", - }); - for (const id of ["astra-low", "neon-low", "plain", "cross-cutting"]) { - expect(built.agent[`${id}${FALLBACK_AGENT_SUFFIX}`], id).toBeUndefined(); - } - // The real reviewer keeps its own entry. - expect(built.agent[`dup${FALLBACK_AGENT_SUFFIX}`]!.model).toBe("google/gemini-4-neon"); - - const handle = { fallbackAgents: copies }; - expect(opencodePassAgent(handle, "astra", 0)).toBe(`astra${FALLBACK_AGENT_SUFFIX}`); - expect(opencodePassAgent(handle, "astra", undefined)).toBe("astra"); - expect(opencodePassAgent(handle, "astra", 12)).toBe("astra"); - expect(opencodePassAgent(handle, "astra-low", 0)).toBe("astra-low"); - expect(opencodePassAgent(handle, "cross-cutting", 0)).toBe("cross-cutting"); - expect(opencodePassAgent({}, "astra", 0)).toBe("astra"); }); diff --git a/src/core/claude-code.ts b/src/core/claude-code.ts index 753b68f..61849d5 100644 --- a/src/core/claude-code.ts +++ b/src/core/claude-code.ts @@ -22,6 +22,7 @@ import { CLAUDE_CODE_ENGINE, CROSS_CUTTING_AGENT, GOOGLE_THINKING_LEVELS, + OPENCODE_BUILTIN_AGENTS, opencodeEffortStyle, STACK_VERIFIER_AGENT, VERIFIER_AGENT, @@ -836,6 +837,7 @@ export function agentEffortNote( .filter( (agent) => !FIXED_ROLE_IDS.has(agent.id) && + !OPENCODE_BUILTIN_AGENTS.has(agent.id) && engineOf[agent.id] === "opencode" && takesNoLevel(agent.model ?? ""), ) @@ -845,6 +847,7 @@ export function agentEffortNote( .filter( (agent) => !FIXED_ROLE_IDS.has(agent.id) && + !OPENCODE_BUILTIN_AGENTS.has(agent.id) && engineOf[agent.id] === "opencode" && opencodeEffortStyle(agent.model ?? "", auth) === "google" && agent.effort !== undefined && @@ -854,7 +857,22 @@ export function agentEffortNote( const fixedRole = declared .filter((agent) => FIXED_ROLE_IDS.has(agent.id)) .map((agent) => agent.id); + // buildOpencodeConfig gives an OpenCode built-in agent id no level (other sessions use it). + const opencodeBuiltin = declared + .filter( + (agent) => + !FIXED_ROLE_IDS.has(agent.id) && + OPENCODE_BUILTIN_AGENTS.has(agent.id) && + engineOf[agent.id] === "opencode", + ) + .map((agent) => agent.id); const notes: string[] = []; + if (opencodeBuiltin.length > 0) { + notes.push( + `\`effort\` has no effect for ${opencodeBuiltin.join(", ")}: the id is also an OpenCode ` + + "built-in agent, which other sessions use. Fix: rename the agent file", + ); + } if (viaOpencode.length > 0) { notes.push( `\`effort\` has no effect for ${viaOpencode.join(", ")}: the model of each runs through ` + diff --git a/src/core/opencode.ts b/src/core/opencode.ts index 418a460..c70748c 100644 --- a/src/core/opencode.ts +++ b/src/core/opencode.ts @@ -5,7 +5,6 @@ import path from "node:path"; import { createOpencode } from "@opencode-ai/sdk"; -import { fallbackEffort } from "../config/schema.js"; import type { AgentEffort, AuthConfigEntry, @@ -171,11 +170,6 @@ export interface OpencodeHandle { engineOf?: (agent: string) => Engine; /** Each configured MCP server tool set to false, merged into every no-tools request. */ mcpToolsOff?: Record; - /** - * Reviewer id → its fallback copy in the OpenCode config (opencodeFallbackAgents); the - * reviewer's no-tools fallback runs as that copy (opencodePassAgent). - */ - fallbackAgents?: ReadonlyMap; /** The configured MCP servers, so progress lines log only granted calls, by name. */ mcpServers?: Record; /** Set on a CI run that publishes sessions. Absent means capture stays off. */ @@ -347,53 +341,21 @@ export function opencodeEffortOptions( return GOOGLE_THINKING_LEVELS.has(effort) ? { thinkingConfig: { thinkingLevel: effort } } : null; } -/** Suffix of a reviewer's fallback copy (see opencodeFallbackAgents). */ -export const FALLBACK_AGENT_SUFFIX = "__fallback-effort"; - -/** - * Reviewer id → the id of its fallback copy: the same OpenCode agent with the level of - * `fallbackEffort` (min(level, medium)), which the reviewer's no-tools fallback pass runs - * as, because OpenCode takes the level from the agent config. Only reviewers whose - * fallback options differ from their own get a copy. None for a fixed-role id (the - * built-in pass replaces that entry, so a copy would hijack the built-in pass's fallback) - * or when the copy id is already an agent id. - */ -// @ref LLP 0006#agent-effort [implements] — the no-tools fallback runs at min(level, medium); OpenCode needs a copy agent for it -export function opencodeFallbackAgents(config: LoadedConfig): Map { - const taken = new Set([...config.agents.map((agent) => agent.id), ...NON_REVIEWER_AGENTS]); - const copies = new Map(); - for (const reviewer of config.agents) { - if (!reviewer.effort || NON_REVIEWER_AGENTS.has(reviewer.id)) { - continue; - } - const style = opencodeEffortStyle(reviewer.model, config.auth); - if (!style) { - continue; - } - const own = opencodeEffortOptions(style, reviewer.effort); - const fallback = opencodeEffortOptions(style, fallbackEffort(reviewer.effort)); - if (JSON.stringify(own) === JSON.stringify(fallback)) { - continue; - } - const copy = `${reviewer.id}${FALLBACK_AGENT_SUFFIX}`; - if (!taken.has(copy)) { - copies.set(reviewer.id, copy); - } - } - return copies; -} - /** - * The OpenCode agent a pass runs as: a no-tools fallback pass (maxToolCalls 0) of a - * reviewer with a fallback copy runs as that copy; every other pass as the agent itself. + * The agents OpenCode 1.19.5 defines itself (`app.agents()` with `builtIn: true`, + * observed 2026-11-26). `compaction`, `summary` and `title` run for every session, so a + * reviewer that shares one of these ids must not give it a level (LLP 0006). Re-check when + * the OpenCode pins move. */ -export function opencodePassAgent( - handle: Pick, - agent: string, - maxToolCalls: number | undefined, -): string { - return maxToolCalls === 0 ? (handle.fallbackAgents?.get(agent) ?? agent) : agent; -} +export const OPENCODE_BUILTIN_AGENTS: ReadonlySet = new Set([ + "build", + "compaction", + "explore", + "general", + "plan", + "summary", + "title", +]); /** Build the inline OpenCode config (agents + coordinator) from a repo config. */ export function buildOpencodeConfig( @@ -402,21 +364,26 @@ export function buildOpencodeConfig( mcpProxy?: McpProxyRuntime, ): Record { const agent: Record = {}; - const fallbackAgents = opencodeFallbackAgents(config); for (const reviewer of config.agents) { - // No level for a reviewer that shares a fixed role's id: the built-in pass written - // after this loop replaces its entry. + // No level for an id the engine or OpenCode also uses: ecr's fixed roles replace the + // entry after this loop, and an OpenCode built-in agent (compaction, title, …) also + // runs for other sessions, so a level there would reach them. const effortStyle = - reviewer.effort && !NON_REVIEWER_AGENTS.has(reviewer.id) + reviewer.effort && + !NON_REVIEWER_AGENTS.has(reviewer.id) && + !OPENCODE_BUILTIN_AGENTS.has(reviewer.id) ? opencodeEffortStyle(reviewer.model, config.auth) : null; const effortOptions = reviewer.effort && effortStyle ? opencodeEffortOptions(effortStyle, reviewer.effort) : null; - const entry = { + agent[reviewer.id] = { description: `${reviewer.id} reviewer`, mode: "all", model: reviewer.model, temperature: reviewer.temperature, + // Only reviewers: the fixed roles below are written after this loop, so a reviewer + // that shares a fixed role's id cannot give that pass its level. + ...effortOptions, prompt: `You are the ${reviewer.id} code reviewer. Follow the user message exactly and return only the requested JSON.`, tools: { ...reviewer.tools, @@ -424,14 +391,6 @@ export function buildOpencodeConfig( ...opencodeGrantedTools(mcpProxy?.servers, reviewer.id), }, }; - agent[reviewer.id] = effortOptions ? { ...entry, ...effortOptions } : entry; - const copy = fallbackAgents.get(reviewer.id); - if (copy && effortStyle && reviewer.effort) { - agent[copy] = { - ...entry, - ...opencodeEffortOptions(effortStyle, fallbackEffort(reviewer.effort)), - }; - } } agent[CROSS_CUTTING_AGENT] = { description: "Cross-file reviewer: issues spanning multiple changed files.", @@ -656,8 +615,6 @@ export async function resolveOpencodeCli(): Promise { export async function startOpencode( config: unknown, mcpServers?: Record, - /** opencodeFallbackAgents for the config this server runs. */ - fallbackAgents?: ReadonlyMap, ): Promise { const mcpToolsOff = opencodeMcpToolsOff(mcpServers); // Make our pinned CLI win over any global install (see bundledOpencodeBinDir). @@ -702,7 +659,6 @@ export async function startOpencode( }, rateLimit: new RateLimitWatch(), ...(Object.keys(mcpToolsOff).length > 0 ? { mcpToolsOff, mcpServers } : {}), - ...(fallbackAgents && fallbackAgents.size > 0 ? { fallbackAgents } : {}), }; } @@ -1130,7 +1086,6 @@ export async function promptAgent( const { runClaudePrompt } = await import("./claude-code.js"); return runClaudePrompt(dispatch.claudeHandle, args); } - const passAgent = opencodePassAgent(handle, args.agent, args.maxToolCalls); const maxWaitMs = args.maxWaitMs ?? DEFAULT_MAX_WAIT_MS; // ONE deadline for the whole pass, shared by the first attempt and any stall // retry, so retrying a wedged request can never push the pass past its declared @@ -1174,7 +1129,7 @@ export async function promptAgent( : "time budget reached — asking for findings so far", ); await sendSessionPrompt(handle, sessionID, { - agent: passAgent, + agent: args.agent, system: args.system, text: FINALIZE_PROMPT, tools: { ...NO_TOOLS, ...handle.mcpToolsOff }, @@ -1214,7 +1169,7 @@ export async function promptAgent( ); const reportedTools = new Set(); await sendSessionPrompt(handle, session.id, { - agent: passAgent, + agent: args.agent, system: args.system, text: args.text, // A pass with no tool budget must not reach a remote MCP server either. @@ -1437,8 +1392,7 @@ export async function promptAndParse( try { const baseline = (await fetchMessages(handle, first.sessionID)).length; await sendSessionPrompt(handle, first.sessionID, { - // The same agent the pass ran as: a fallback pass re-emits at its fallback level. - agent: opencodePassAgent(handle, args.agent, args.maxToolCalls), + agent: args.agent, system: args.system, text: CORRECTIVE, // Re-emit only: the investigation is done, so no tools are needed and diff --git a/src/core/review.ts b/src/core/review.ts index 12983bc..ba44e10 100644 --- a/src/core/review.ts +++ b/src/core/review.ts @@ -20,7 +20,6 @@ import { AgentTimeoutError, assertModelsResolvable, buildOpencodeConfig, - opencodeFallbackAgents, CLAUDE_CODE_ENGINE, CROSS_CUTTING_AGENT, promptAndParse, @@ -532,7 +531,6 @@ export async function runReview( opencodeHandle = await startOpencode( buildOpencodeConfig(config, researchRuntime, mcpProxy), mcpProxy?.servers, - opencodeFallbackAgents(config), ); } } catch (error) { From 3bca5281177db55711094edebf88115a8a29245d Mon Sep 17 00:00:00 2001 From: szdziedzic Date: Thu, 26 Nov 2026 15:31:04 +0100 Subject: [PATCH 6/9] fix: say which providers take a level in the ignored-effort note MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gemini Neon review of fa22f36: the provider list in the note followed "a provider ecr passes no level to", so it read as a list of providers that take no level. It now says "ecr passes one only for …". Co-Authored-By: Claude Opus 5.5 --- src/__tests__/claude-code.test.ts | 2 +- src/core/claude-code.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/__tests__/claude-code.test.ts b/src/__tests__/claude-code.test.ts index 9bd7e71..c25c22b 100644 --- a/src/__tests__/claude-code.test.ts +++ b/src/__tests__/claude-code.test.ts @@ -931,7 +931,7 @@ test("agentEffortNote: OpenAI and Google models take a level through OpenCode; o const named = (note: string | null) => note?.match(/has no effect for ([^:]+):/)?.[1]; const note = agentEffortNote(agents, engineOf, auth); expect(note).toContain( - "the model of each runs through OpenCode on a provider ecr passes no level to", + "the model of each runs through OpenCode on a provider ecr passes no level to (ecr passes one only for `anthropic/…`", ); expect(named(note)).toBe("muse"); // Without the alias's auth entry, `openai-api` is not known to be OpenAI. diff --git a/src/core/claude-code.ts b/src/core/claude-code.ts index 61849d5..74ec452 100644 --- a/src/core/claude-code.ts +++ b/src/core/claude-code.ts @@ -876,7 +876,7 @@ export function agentEffortNote( if (viaOpencode.length > 0) { notes.push( `\`effort\` has no effect for ${viaOpencode.join(", ")}: the model of each runs through ` + - `OpenCode on a provider ecr passes no level to (${EFFORT_PROVIDERS})`, + `OpenCode on a provider ecr passes no level to (ecr passes one only for ${EFFORT_PROVIDERS})`, ); } if (googleLevelNotTaken.length > 0) { From 4d4137b9ac0bcdda46bb7c2dde050c22101a203b Mon Sep 17 00:00:00 2001 From: szdziedzic Date: Thu, 26 Nov 2026 15:38:10 +0100 Subject: [PATCH 7/9] fix: full fix in the built-in-id note; precise Google default wording Astra final review of 3bca528 (approve with comments): - The note for an OpenCode built-in agent id said only to rename the file; on a model that takes no level, or Google xhigh/max, the next run then gave a second fix. It now gives both in one note, as the fixed-role note does. - OpenCode's Google default varies by model (Gemini 4 Neon: high; a gemini-2.5-flash request carried no thinkingLevel), so the README, the LLP and the note no longer call `high` the default for every model. - The built-in agent list comment names the field app.agents() returns (`native: true`). - The LLP fallback heading says the cap is Claude Code's; OpenCode keeps the level. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- ...config-schema-loading-routing.explainer.md | 7 +++--- src/__tests__/claude-code.test.ts | 15 +++++++++++ src/core/claude-code.ts | 25 +++++++++++++++++-- src/core/opencode.ts | 2 +- 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b2542c0..b607cd0 100644 --- a/README.md +++ b/README.md @@ -544,7 +544,7 @@ ignores it. Leave it out to use the provider's default. | --- | --- | | `anthropic/…` (Claude Code CLI) | `--effort ` | | `openai/…`, or an alias with `upstream: "openai"` (OpenCode) | `reasoningEffort`, sent as the Responses API `reasoning.effort` | -| `google/…`, `google-vertex/…` (OpenCode) | `thinkingConfig.thinkingLevel`, in place of OpenCode's default `high`; only `low`, `medium` or `high` (for `xhigh` and `max` ecr sends no level, and the run note says so) | +| `google/…`, `google-vertex/…` (OpenCode) | `thinkingConfig.thinkingLevel`, in place of the model's default (OpenCode sends `high` for Gemini 4 Neon); only `low`, `medium` or `high` (for `xhigh` and `max` ecr sends no level, and the run note says so) | ecr passes the level as written and does not check which levels a model takes. A model without effort support can drop it (the Claude Code CLI sends no level to diff --git a/llp/0006-config-schema-loading-routing.explainer.md b/llp/0006-config-schema-loading-routing.explainer.md index 5c78c79..3e64642 100644 --- a/llp/0006-config-schema-loading-routing.explainer.md +++ b/llp/0006-config-schema-loading-routing.explainer.md @@ -258,12 +258,13 @@ per-agent key and not a run-level flag. [observed]. OpenCode's model catalog lists more variants for some Gemini models; the limit comes from the bundled Google SDK's option schema, so re-check it when the OpenCode pins move. So `GOOGLE_THINKING_LEVELS` is `low`, `medium`, `high`: for the other two ecr sends no - key, the model runs at OpenCode's default (`high`), and the run note names the agent, its level + key, the model runs at its default in OpenCode (`high` for Gemini 4 Neon; a `google/gemini-2.5-flash` + request carried no `thinkingLevel`, per review of PR #119), and the run note names the agent, its level and the levels that work. Not observed: the ChatGPT/Codex sign-in path and a real provider's response to each level. ecr passes the level as written; a provider that does not take it fails that agent's passes with its own error. - **No level on OpenCode's own agent ids.** OpenCode 1.19.5 defines `build`, `compaction`, - `explore`, `general`, `plan`, `summary` and `title` (`app.agents()`, 2026-11-26) [observed]; a + `explore`, `general`, `plan`, `summary` and `title` (`app.agents()`, `native: true`, 2026-11-26) [observed]; a reviewer config with one of these ids replaces that agent, and `compaction`, `summary` and `title` also run for other sessions. A reviewer level there reached another reviewer's session compaction (found in review of PR #119), so `buildOpencodeConfig` gives these ids no level @@ -281,7 +282,7 @@ per-agent key and not a run-level flag. #118 against a local mock endpoint, not re-run here). The engine does not check model support. - **Only reviewer files take it.** `effort` in `coordinator.md` or `shared.md` frontmatter has no effect, so the loader adds a setup warning that says to remove it, instead of ignoring it. -- **The no-tools fallback pass runs at `min(level, medium)`.** A timed-out pass is retried with no +- **The Claude Code no-tools fallback runs at `min(level, medium)`; OpenCode keeps the level.** A timed-out pass is retried with no tools under a short cap (`maxToolCalls: 0`). A deep level there would likely time out again (found in a multi-model review of PR #118, not measured in a live run), and sending no level would use the provider's default, which can be higher than the agent's own `low` (OpenCode sends diff --git a/src/__tests__/claude-code.test.ts b/src/__tests__/claude-code.test.ts index c25c22b..f4acd50 100644 --- a/src/__tests__/claude-code.test.ts +++ b/src/__tests__/claude-code.test.ts @@ -987,6 +987,21 @@ test("agentEffortNote: an OpenCode reviewer named after an OpenCode built-in age expect(agentEffortNote(agents, { compaction: "claude-code" }, [])).toBeNull(); }); +test("agentEffortNote: an OpenCode built-in id on Google max is also told the levels Google takes", () => { + const agents = [ + { id: "compaction", effort: "max", model: "google/gemini-4-neon" }, + { id: "title", effort: "high", model: "meta/muse-spark-1.3" }, + ] as unknown as LoadedAgent[]; + const note = agentEffortNote(agents, { compaction: "opencode", title: "opencode" }, []); + expect(note).toContain( + "has no effect for compaction, title: the id is also an OpenCode built-in agent", + ); + expect(note).toContain("and run title on a model that takes a level"); + expect(note).toContain("and give compaction one of low, medium, high"); + // One note only: the built-in id is not also listed as a plain OpenCode or Google case. + expect(note?.split("has no effect").length).toBe(2); +}); + test("agentEffortNote: a fixed-role reviewer on OpenAI is told only to rename", () => { const agents = [ { id: "verifier", effort: "max", model: "openai/gpt-6.2-astra" }, diff --git a/src/core/claude-code.ts b/src/core/claude-code.ts index 74ec452..ebc1989 100644 --- a/src/core/claude-code.ts +++ b/src/core/claude-code.ts @@ -866,11 +866,32 @@ export function agentEffortNote( engineOf[agent.id] === "opencode", ) .map((agent) => agent.id); + // After a rename, the model still has to take a level; say so in the same note. + const builtinNoLevel = opencodeBuiltin.filter((id) => + takesNoLevel(declared.find((agent) => agent.id === id)?.model ?? ""), + ); + const builtinGoogleLevel = declared + .filter( + (agent) => + opencodeBuiltin.includes(agent.id) && + opencodeEffortStyle(agent.model ?? "", auth) === "google" && + agent.effort !== undefined && + !GOOGLE_THINKING_LEVELS.has(agent.effort), + ) + .map((agent) => agent.id); const notes: string[] = []; if (opencodeBuiltin.length > 0) { notes.push( `\`effort\` has no effect for ${opencodeBuiltin.join(", ")}: the id is also an OpenCode ` + - "built-in agent, which other sessions use. Fix: rename the agent file", + "built-in agent, which other sessions use. Fix: rename the agent file" + + (builtinNoLevel.length > 0 + ? `, and run ${builtinNoLevel.join(", ")} on a model that takes a level ` + + `(${EFFORT_PROVIDERS}; its \`model:\`, or \`REVIEWER_MODEL\` when that is set)` + : "") + + (builtinGoogleLevel.length > 0 + ? `, and give ${builtinGoogleLevel.join(", ")} one of ` + + `${[...GOOGLE_THINKING_LEVELS].join(", ")} (OpenCode's Google adapter takes no other)` + : ""), ); } if (viaOpencode.length > 0) { @@ -883,7 +904,7 @@ export function agentEffortNote( notes.push( `\`effort\` has no effect for ${googleLevelNotTaken.join(", ")}: OpenCode's Google adapter ` + `takes only ${[...GOOGLE_THINKING_LEVELS].join(", ")}, so ecr sends no level and the model ` + - "runs at OpenCode's default. Fix: use one of those levels", + "runs at the model's default in OpenCode. Fix: use one of those levels", ); } // The engine map's entry for a fixed-role id describes the built-in pass, so read the diff --git a/src/core/opencode.ts b/src/core/opencode.ts index c70748c..ab7a56a 100644 --- a/src/core/opencode.ts +++ b/src/core/opencode.ts @@ -342,7 +342,7 @@ export function opencodeEffortOptions( } /** - * The agents OpenCode 1.19.5 defines itself (`app.agents()` with `builtIn: true`, + * The agents OpenCode 1.19.5 defines itself (`app.agents()` with `native: true`, * observed 2026-11-26). `compaction`, `summary` and `title` run for every session, so a * reviewer that shares one of these ids must not give it a level (LLP 0006). Re-check when * the OpenCode pins move. From 24144b9f6a45f20e355150605062327ca271aa00 Mon Sep 17 00:00:00 2001 From: szdziedzic Date: Thu, 26 Nov 2026 15:41:52 +0100 Subject: [PATCH 8/9] docs: list OpenCode's own agent names; cover the guards in tests Gemini Neon final review of 3bca528 (approve with comments): - The README now says that an OpenCode-routed file named after one of OpenCode's own agents gets no effort, as a fixed-role file does. - agentEffortNote's doc comment lists all four cases. - buildAgentEfforts' test includes `compaction`, which keeps its level on the claude-code engine. Its other nits (one note with the full fix for a built-in id, the LLP heading) were fixed in 4d4137b, whose test also fails if the duplicate- note guards are removed. Co-Authored-By: Claude Opus 5.5 --- README.md | 4 +++- src/__tests__/claude-code.test.ts | 7 ++++++- src/core/claude-code.ts | 6 ++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b607cd0..0276146 100644 --- a/README.md +++ b/README.md @@ -557,7 +557,9 @@ is not a level is listed under **Review setup**, and the agent runs at the defau files take it. An agent file in `agents/` named after a built-in pass (`verifier.md`, `cross-cutting.md`, `adjudicator.md`, `stack-verifier.md` or `coordinator.md`) gets -no effort; the review note says to rename it. +no effort; the review note says to rename it. The same holds, on OpenCode-routed +models, for a file named after one of OpenCode's own agents (`build.md`, +`compaction.md`, `explore.md`, `general.md`, `plan.md`, `summary.md`, `title.md`). `paths` limits an agent to the changes it covers. It takes a list of repo-relative globs in the routing dialect: `*` stays within a directory, `**` crosses diff --git a/src/__tests__/claude-code.test.ts b/src/__tests__/claude-code.test.ts index f4acd50..a772d10 100644 --- a/src/__tests__/claude-code.test.ts +++ b/src/__tests__/claude-code.test.ts @@ -874,11 +874,16 @@ test("buildAgentEfforts: no entry for a reviewer that shares a fixed role's id", agents: [ { id: "correctness", effort: "high" }, ...fixedRoles.map((id) => ({ id, effort: "max" })), + // An OpenCode built-in id keeps its level on the claude-code engine. + { id: "compaction", effort: "high" }, { id: "constructor" }, ], } as unknown as LoadedConfig; const efforts = buildAgentEfforts(config); - expect([...efforts]).toEqual([["correctness", "high"]]); + expect([...efforts]).toEqual([ + ["correctness", "high"], + ["compaction", "high"], + ]); expect(efforts.get("constructor")).toBeUndefined(); }); diff --git a/src/core/claude-code.ts b/src/core/claude-code.ts index ebc1989..a1fa5ba 100644 --- a/src/core/claude-code.ts +++ b/src/core/claude-code.ts @@ -820,8 +820,10 @@ export function buildAgentEfforts(config: LoadedConfig): Map Date: Thu, 26 Nov 2026 17:12:59 +0100 Subject: [PATCH 9/9] feat: pass agent effort to xAI (Grok) models through OpenCode Asked for in Kudo's review of #118. OpenCode's xAI adapter (@ai-sdk/xai) reads the same agent key as OpenAI: with the pinned OpenCode 1.19.5 against a mock endpoint, an `xai/grok-4.7` request to /chat/completions carried no level field with no key, and reasoningEffort "low", "high" and "xhigh" arrived as reasoning_effort. opencodeEffortStyle now maps native `xai` to an `xai` style with that key. Which levels xAI's API accepts is not verified; like the other providers, ecr passes the level as written. Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + ...06-config-schema-loading-routing.explainer.md | 10 +++++++--- src/__tests__/claude-code.test.ts | 4 +++- src/__tests__/opencode.test.ts | 9 +++++++++ src/core/claude-code.ts | 2 +- src/core/opencode.ts | 16 ++++++++++------ templates/config.jsonc | 4 ++-- 7 files changed, 33 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 0276146..784c1ec 100644 --- a/README.md +++ b/README.md @@ -545,6 +545,7 @@ ignores it. Leave it out to use the provider's default. | `anthropic/…` (Claude Code CLI) | `--effort ` | | `openai/…`, or an alias with `upstream: "openai"` (OpenCode) | `reasoningEffort`, sent as the Responses API `reasoning.effort` | | `google/…`, `google-vertex/…` (OpenCode) | `thinkingConfig.thinkingLevel`, in place of the model's default (OpenCode sends `high` for Gemini 4 Neon); only `low`, `medium` or `high` (for `xhigh` and `max` ecr sends no level, and the run note says so) | +| `xai/…` (Grok, OpenCode) | `reasoningEffort`, sent as Chat Completions `reasoning_effort` | ecr passes the level as written and does not check which levels a model takes. A model without effort support can drop it (the Claude Code CLI sends no level to diff --git a/llp/0006-config-schema-loading-routing.explainer.md b/llp/0006-config-schema-loading-routing.explainer.md index d40f682..3ce5fee 100644 --- a/llp/0006-config-schema-loading-routing.explainer.md +++ b/llp/0006-config-schema-loading-routing.explainer.md @@ -239,18 +239,22 @@ per-agent key and not a run-level flag. session archive's `NON_REVIEWER_AGENTS`, so the two cannot drift. The levels live in a `Map`, so an id such as `constructor` cannot read an inherited `Object.prototype` value (both found in review of the first version, PR #118). -- **OpenCode passes it for OpenAI and Google models.** OpenCode hands unknown agent-config keys to +- **OpenCode passes it for OpenAI, Google and xAI models.** OpenCode hands unknown agent-config keys to the provider as model options. `buildOpencodeConfig` adds one per reviewer with `effort`, chosen by `opencodeEffortStyle` from the adapter ecr gives the model's provider: native `openai` and an alias with `upstream: "openai"` (built on `@ai-sdk/openai`) get `reasoningEffort`; native - `google` and `google-vertex` get `thinkingConfig.thinkingLevel`. Any other alias, including + `google` and `google-vertex` get `thinkingConfig.thinkingLevel`; native `xai` (Grok, on + `@ai-sdk/xai`) gets `reasoningEffort`. Any other alias, including `upstream: "google"` (built on `@ai-sdk/openai-compatible`), gets nothing: a Google key on that adapter reached a mock endpoint as a top-level `thinkingConfig` on `/chat/completions` (found in review of PR #119). Observed with the pinned OpenCode 1.19.5 against a local mock endpoint (2026-11-26) [observed]: with no key, an `openai/gpt-6.2-astra` request carried no `reasoning` field; `reasoningEffort: "xhigh"` and `"max"` arrived as `reasoning.effort`; a `google/gemini-4-neon` request carried `thinkingConfig: {includeThoughts: true, thinkingLevel: - "high"}` with no key, and `thinkingLevel: "low"` replaced the `high`. Only reviewer entries get + "high"}` with no key, and `thinkingLevel: "low"` replaced the `high`; an `xai/grok-4.7` request to + `/chat/completions` carried no level field with no key, and `reasoningEffort` `"low"`, `"high"` and + `"xhigh"` arrived as `reasoning_effort` (asked for in review of PR #118; which levels xAI's API + accepts is not verified). Only reviewer entries get the key: the fixed roles are written after the reviewer loop, so a reviewer that shares a fixed role's id cannot give that pass its level. The pinned Google adapter takes `thinkingLevel` `minimal`, `low`, `medium` and `high`; with `xhigh` or `max` the pass failed inside OpenCode diff --git a/src/__tests__/claude-code.test.ts b/src/__tests__/claude-code.test.ts index a772d10..e122f28 100644 --- a/src/__tests__/claude-code.test.ts +++ b/src/__tests__/claude-code.test.ts @@ -915,12 +915,13 @@ test("agentEffortNote: an agent that does not run in this review is not named", ).toBeNull(); }); -test("agentEffortNote: OpenAI and Google models take a level through OpenCode; others do not", () => { +test("agentEffortNote: OpenAI, Google and xAI models take a level through OpenCode; others do not", () => { const agents = [ { id: "astra", effort: "high", model: "openai/gpt-6.2-astra" }, { id: "pro", effort: "high", model: "openai-api/gpt-5.5-pro" }, { id: "neon", effort: "high", model: "google/gemini-4-neon" }, { id: "vertex", effort: "high", model: "google-vertex/gemini-4-neon" }, + { id: "grok", effort: "high", model: "xai/grok-4.7" }, { id: "muse", effort: "high", model: "meta/muse-spark-1.3" }, ] as unknown as LoadedAgent[]; const engineOf = { @@ -928,6 +929,7 @@ test("agentEffortNote: OpenAI and Google models take a level through OpenCode; o pro: "opencode", neon: "opencode", vertex: "opencode", + grok: "opencode", muse: "opencode", } as const; const auth = [ diff --git a/src/__tests__/opencode.test.ts b/src/__tests__/opencode.test.ts index 1233991..65cd47e 100644 --- a/src/__tests__/opencode.test.ts +++ b/src/__tests__/opencode.test.ts @@ -710,6 +710,7 @@ test("opencodeEffortStyle: OpenAI and Google families take a level; others do no expect(opencodeEffortStyle("gemini-api/gemini-4-neon", alias)).toBeNull(); expect(opencodeEffortStyle("meta/muse-spark-1.3", [])).toBeNull(); expect(opencodeEffortStyle("gpt-6.2-astra", [])).toBeNull(); + expect(opencodeEffortStyle("xai/grok-4.7", [])).toBe("xai"); }); test("buildOpencodeConfig passes a reviewer's effort as its provider's option, and only a reviewer's", () => { @@ -769,3 +770,11 @@ test("buildOpencodeConfig gives no level to a reviewer that shares an OpenCode b "title", ]); }); + +test("buildOpencodeConfig passes a Grok reviewer's level as reasoningEffort", () => { + const opencode = buildOpencodeConfig( + configWith({ agents: [{ id: "grok", model: "xai/grok-4.7", effort: "xhigh" }] }), + ) as { agent: Record> }; + expect(opencode.agent.grok!.reasoningEffort).toBe("xhigh"); + expect(opencode.agent.grok!.thinkingConfig).toBeUndefined(); +}); diff --git a/src/core/claude-code.ts b/src/core/claude-code.ts index a1fa5ba..1fbfcaf 100644 --- a/src/core/claude-code.ts +++ b/src/core/claude-code.ts @@ -943,7 +943,7 @@ export function agentEffortNote( /** The model families ecr passes an effort level to, for the run notes. */ const EFFORT_PROVIDERS = - '`anthropic/…`, `openai/…` (or an `upstream: "openai"` alias), `google/…` or `google-vertex/…`'; + '`anthropic/…`, `openai/…` (or an `upstream: "openai"` alias), `google/…`, `google-vertex/…` or `xai/…`'; /** * Preserve actionable process diagnostics without copying arbitrary stderr into a diff --git a/src/core/opencode.ts b/src/core/opencode.ts index 26a44b1..2ff0f6a 100644 --- a/src/core/opencode.ts +++ b/src/core/opencode.ts @@ -282,15 +282,15 @@ export const STACK_VERIFIER_AGENT = "stack-verifier"; /** * How an OpenCode provider's SDK takes a reasoning level from an agent's config: - * OpenAI's Responses adapter reads `reasoningEffort`, Google's reads + * OpenAI's Responses adapter and xAI's adapter read `reasoningEffort`, Google's reads * `thinkingConfig.thinkingLevel`. */ -export type OpencodeEffortStyle = "openai" | "google"; +export type OpencodeEffortStyle = "openai" | "google" | "xai"; /** * The effort style for a model id, or null when ecr does not pass a level to that * provider. Native `openai` gets the OpenAI style, native `google` and `google-vertex` the - * Google style. An alias (an auth entry with `upstream`) follows the adapter + * Google style, native `xai` (Grok) the xAI style. An alias (an auth entry with `upstream`) follows the adapter * `buildOpencodeConfig` creates for it: only `upstream: "openai"` gets `@ai-sdk/openai`, * so only that alias takes a level. Meta, OpenAI-compatible and other providers get null. */ @@ -314,6 +314,9 @@ export function opencodeEffortStyle( if (provider === "google" || provider === "google-vertex") { return "google"; } + if (provider === "xai") { + return "xai"; + } return null; } @@ -328,14 +331,15 @@ export const GOOGLE_THINKING_LEVELS: ReadonlySet = new Set(["low", * The agent-config keys that carry a reasoning level for an effort style, or null when * the style's adapter does not take that level. OpenCode passes unknown agent keys to * the provider as model options; observed with OpenCode 1.19.5 against a mock endpoint - * (LLP 0006): `reasoningEffort` becomes the Responses API's `reasoning.effort`, and - * `thinkingConfig.thinkingLevel` replaces the `high` that OpenCode sends to Gemini. + * (LLP 0006): `reasoningEffort` becomes the Responses API's `reasoning.effort` (OpenAI) + * and Chat Completions' `reasoning_effort` (xAI), and `thinkingConfig.thinkingLevel` + * replaces the `high` that OpenCode sends to Gemini 4 Neon. */ export function opencodeEffortOptions( style: OpencodeEffortStyle, effort: AgentEffort, ): Record | null { - if (style === "openai") { + if (style === "openai" || style === "xai") { return { reasoningEffort: effort }; } return GOOGLE_THINKING_LEVELS.has(effort) ? { thinkingConfig: { thinkingLevel: effort } } : null; diff --git a/templates/config.jsonc b/templates/config.jsonc index abf1404..dd901c0 100644 --- a/templates/config.jsonc +++ b/templates/config.jsonc @@ -15,8 +15,8 @@ // there limits an agent to changes that touch those globs, and `mention: [octocat]` // names the people the review mentions when that agent asks for a human review. // `effort: high` (low, medium, high, xhigh or max) sets how much an agent reasons on - // `anthropic/…`, `openai/…` (or an `upstream: "openai"` alias), `google/…` or - // `google-vertex/…` models; Google takes only low, medium or high. Other models ignore + // `anthropic/…`, `openai/…` (or an `upstream: "openai"` alias), `google/…`, + // `google-vertex/…` or `xai/…` models; Google takes only low, medium or high. Other models ignore // it, and so does a model without effort support (Claude Haiku 4.5). README: "effort". // @ref LLP 0009#config-and-prompt-templates [implements] — suggestions off by default, not a schema limit