diff --git a/README.md b/README.md index a394c2d..784c1ec 100644 --- a/README.md +++ b/README.md @@ -536,12 +536,21 @@ 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 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 +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. @@ -549,7 +558,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/llp/0006-config-schema-loading-routing.explainer.md b/llp/0006-config-schema-loading-routing.explainer.md index 1a9d3c1..3ce5fee 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,43 @@ 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, 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`; 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`; 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 + (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 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()`, `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 + (`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. `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 @@ -251,12 +286,18 @@ 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 claude-code no-tools fallback runs at `min(level, medium)`.** 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 CLI's default, which can be higher than the agent's own `low`. So - `fallbackEffort` caps the level at `medium` and never raises it, and `runClaudePrompt` passes - that for the fallback. Only the claude-code engine applies this cap. +- **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 CLI's default, which can be higher than the agent's own + `low`. So `fallbackEffort` caps the level at `medium` and never raises it, and `runClaudePrompt` + passes that for the fallback. Only the claude-code engine applies this cap. 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 @@ -270,8 +311,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..e122f28 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(); }); @@ -888,8 +893,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 +907,144 @@ 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, 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 = { + astra: "opencode", + pro: "opencode", + neon: "opencode", + vertex: "opencode", + grok: "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 (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. + 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 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: 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: 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" }, + ] as unknown as LoadedAgent[]; + const note = agentEffortNote(agents, { verifier: "claude-code" }, []); + expect(note).toContain("Fix: rename the agent file"); + expect(note?.endsWith("Fix: rename the agent file")).toBe(true); +}); + 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"); + expect(note).not.toContain("run 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..65cd47e 100644 --- a/src/__tests__/opencode.test.ts +++ b/src/__tests__/opencode.test.ts @@ -18,6 +18,10 @@ import { serverStopped, STACK_VERIFIER_AGENT, META_MODEL_API_BASE_URL, + opencodeEffortStyle, + OPENCODE_BUILTIN_AGENTS, + 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 +62,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 +693,88 @@ 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" }, + // 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"); + 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("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", () => { + 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: "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" }, + ], + }), + ) 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(); + // 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(); + } +}); + +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", + ]); +}); + +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/__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/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 78a0ee2..1fbfcaf 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,9 @@ import { AgentTimeoutError, CLAUDE_CODE_ENGINE, CROSS_CUTTING_AGENT, + GOOGLE_THINKING_LEVELS, + OPENCODE_BUILTIN_AGENTS, + opencodeEffortStyle, STACK_VERIFIER_AGENT, VERIFIER_AGENT, withTransientRetry, @@ -810,51 +819,132 @@ 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) && + !OPENCODE_BUILTIN_AGENTS.has(agent.id) && + engineOf[agent.id] === "opencode" && + 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) && + !OPENCODE_BUILTIN_AGENTS.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); + // 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); + // 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" + + (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) { 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 (ecr passes one only for ${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 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 - // reviewer's own model: after a rename, an OpenCode model would still ignore `effort`. - const fixedRoleViaOpencode = declared + // 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); + // 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) && engineForModel(agent.model ?? "") === "opencode", + (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 ` + "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)` + : "") + + (fixedRoleGoogleLevel.length > 0 + ? `, and give ${fixedRoleGoogleLevel.join(", ")} one of ` + + `${[...GOOGLE_THINKING_LEVELS].join(", ")} (OpenCode's Google adapter takes no other)` : ""), ); } 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/…` (or an `upstream: "openai"` alias), `google/…`, `google-vertex/…` or `xai/…`'; + /** * 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..2ff0f6a 100644 --- a/src/core/opencode.ts +++ b/src/core/opencode.ts @@ -5,12 +5,18 @@ 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. 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"; @@ -274,6 +280,88 @@ 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 and xAI's adapter read `reasoningEffort`, Google's reads + * `thinkingConfig.thinkingLevel`. + */ +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, 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. + */ +// @ref LLP 0006#agent-effort [implements] — OpenCode-routed effort, per provider adapter +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 alias = auth.find((entry) => entry.provider === provider && entry.upstream); + if (alias) { + return alias.upstream === "openai" ? "openai" : null; + } + if (provider === "openai") { + return "openai"; + } + if (provider === "google" || provider === "google-vertex") { + return "google"; + } + if (provider === "xai") { + return "xai"; + } + return null; +} + +/** + * The levels the pinned OpenCode's Google adapter takes for `thinkingLevel`. With + * 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"]); + +/** + * 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` (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" || style === "xai") { + return { reasoningEffort: effort }; + } + return GOOGLE_THINKING_LEVELS.has(effort) ? { thinkingConfig: { thinkingLevel: effort } } : null; +} + +/** + * 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. + */ +// @ref LLP 0006#agent-effort [implements] — no level on OpenCode's own agent ids, which other sessions use +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( config: LoadedConfig, @@ -282,11 +370,25 @@ export function buildOpencodeConfig( ): Record { const agent: Record = {}; for (const reviewer of config.agents) { + // 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) && + !OPENCODE_BUILTIN_AGENTS.has(reviewer.id) + ? 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", 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, diff --git a/src/core/review.ts b/src/core/review.ts index 4bba427..ba44e10 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; @@ -2385,10 +2388,11 @@ 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); + 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..dd901c0 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/…` - // 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 agent reasons on + // `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 "policy": {