Skip to content

Commit 1cdf07c

Browse files
committed
refactor(config)!: drop OPENCODE_DELEGATE_READ_MODEL in favour of OPENCODE_DELEGATE_DEFAULT_MODEL
1 parent a30dc12 commit 1cdf07c

6 files changed

Lines changed: 38 additions & 37 deletions

File tree

‎README.md‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,16 @@ git config core.hooksPath hooks/ # pre-commit (staged lint/format), pre-push (
145145
146146
`src/index.ts` is the MCP server entry point (`bun run start`, bundled to `dist/index.js` by `bun run build`); it builds on the `delegate`, `resolveModel`, `buildArgs` and `EventCollector` modules, which also document how `opencode run` is invoked and its JSON stream parsed. Changing `src/` changes the MCP tools, so rebuild and commit `dist/`. The provider preference (direct provider over an aggregator, `OPENCODE_DELEGATE_PREFERRED_PROVIDERS` first) applies to the MCP server only, not to the worker. Variables read by `src/config.ts`:
147147
148-
| Variable | Default | Description |
149-
| --------------------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
150-
| `OPENCODE_BIN` | auto-detected | Path to `opencode` |
151-
| `OPENCODE_DELEGATE_DEFAULT_MODEL` | unset | Model when none given; unset or empty means OpenCode's configured default |
152-
| `OPENCODE_DELEGATE_READ_MODEL` | unset | Model when none given and `auto` is false; unset or empty falls back to `OPENCODE_DELEGATE_DEFAULT_MODEL`, then OpenCode's default |
153-
| `OPENCODE_DELEGATE_AUTO` | `true` | Default for `auto`; `0`, `false`, `no`, `off` disable it |
154-
| `OPENCODE_DELEGATE_TIMEOUT` | `1800` | Seconds before a run is killed |
155-
| `OPENCODE_DELEGATE_MAX_OUTPUT` | `40000` | Maximum response characters returned |
156-
| `OPENCODE_DELEGATE_THINKING` | `true` | Include reasoning blocks in output |
157-
| `OPENCODE_DELEGATE_CWD` | process cwd | Base working directory |
158-
| `OPENCODE_DELEGATE_PREFERRED_PROVIDERS` | none | Comma-separated provider order when a model has several providers |
148+
| Variable | Default | Description |
149+
| --------------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------- |
150+
| `OPENCODE_BIN` | auto-detected | Path to `opencode` |
151+
| `OPENCODE_DELEGATE_DEFAULT_MODEL` | unset | Model when none given, for write and read-only runs; unset or empty means OpenCode's configured default |
152+
| `OPENCODE_DELEGATE_AUTO` | `true` | Default for `auto`; `0`, `false`, `no`, `off` disable it |
153+
| `OPENCODE_DELEGATE_TIMEOUT` | `1800` | Seconds before a run is killed |
154+
| `OPENCODE_DELEGATE_MAX_OUTPUT` | `40000` | Maximum response characters returned |
155+
| `OPENCODE_DELEGATE_THINKING` | `true` | Include reasoning blocks in output |
156+
| `OPENCODE_DELEGATE_CWD` | process cwd | Base working directory |
157+
| `OPENCODE_DELEGATE_PREFERRED_PROVIDERS` | none | Comma-separated provider order when a model has several providers |
159158
160159
## Releasing
161160

‎dist/index.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21528,7 +21528,6 @@ function int2(v, dflt) {
2152821528
var config2 = {
2152921529
bin: resolveBin(),
2153021530
defaultModel: model(process.env.OPENCODE_DELEGATE_DEFAULT_MODEL, undefined),
21531-
readModel: model(process.env.OPENCODE_DELEGATE_READ_MODEL, undefined),
2153221531
auto: bool(process.env.OPENCODE_DELEGATE_AUTO, true),
2153321532
timeoutSec: int2(process.env.OPENCODE_DELEGATE_TIMEOUT, 1800),
2153421533
maxOutputChars: int2(process.env.OPENCODE_DELEGATE_MAX_OUTPUT, 40000),
@@ -21871,7 +21870,7 @@ async function delegate(input, signal) {
2187121870
if (!existsSync2(cwd))
2187221871
throw new Error(`cwd does not exist: ${cwd}`);
2187321872
const auto = input.auto ?? config2.auto;
21874-
const query = input.model ?? (auto ? config2.defaultModel : config2.readModel ?? config2.defaultModel);
21873+
const query = input.model ?? config2.defaultModel;
2187521874
const model = query ? await resolveModelOrThrow(query) : undefined;
2187621875
const files = input.files?.map((f) => isAbsolute(f) ? f : resolve(cwd, f));
2187721876
const before = gitStatus(cwd);
@@ -21988,14 +21987,14 @@ var text = (t, isError = false) => ({
2198821987
});
2198921988
var delegateShape = {
2199021989
prompt: string2().min(1).describe("Complete, self-contained task for the opencode model. It cannot see this conversation: include goal, relevant files/paths, constraints, and acceptance criteria."),
21991-
model: string2().optional().describe(`opencode model: exact 'provider/model' id (e.g. 'xai/grok-4.7') or a loose name ('grok 4.7', 'kimi k3'). Append '#variant' for a reasoning variant. Omit to use the default: ${config2.defaultModel ?? "opencode's default"} for normal tasks, ${config2.readModel ?? config2.defaultModel ?? "opencode's default"} (free) when auto is false.`),
21990+
model: string2().optional().describe(`opencode model: exact 'provider/model' id (e.g. 'xai/grok-4.7') or a loose name ('grok 4.7', 'kimi k3'). Append '#variant' for a reasoning variant. Omit to use the default: ${config2.defaultModel ?? "opencode's configured default model"}.`),
2199221991
cwd: string2().optional().describe("Working directory for the task (absolute, or relative to the server's cwd). Defaults to the current project."),
2199321992
agent: string2().optional().describe("opencode agent to use (e.g. 'build', 'plan', or a custom agent)."),
2199421993
files: array(string2()).optional().describe("Files to attach to the message."),
2199521994
session_id: string2().optional().describe("Continue an existing opencode session (returned by a previous call) for follow-ups."),
2199621995
continue: boolean2().optional().describe("Continue the most recent opencode session in cwd."),
2199721996
fork: boolean2().optional().describe("Fork the session given by session_id/continue instead of appending to it."),
21998-
auto: boolean2().optional().describe(`Auto-approve tool permissions (edits, shell) that are not explicitly denied. Default: ${config2.auto}. Set false for read-only work (reading files, reviews, questions); without a model that also selects the free read model.`),
21997+
auto: boolean2().optional().describe(`Auto-approve tool permissions (edits, shell) that are not explicitly denied. Default: ${config2.auto}. Set false for read-only work (reading files, reviews, questions).`),
2199921998
thinking: boolean2().optional().describe(`Show/enable the model's thinking (reasoning) output (opencode --thinking). Default: ${config2.thinking} (env OPENCODE_DELEGATE_THINKING).`),
2200021999
title: string2().optional().describe("Session title shown in opencode."),
2200122000
timeout_s: number2().int().positive().optional().describe(`Kill the run after this many seconds. Default: ${config2.timeoutSec}.`)

‎src/config.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ export const config = {
4343
bin: resolveBin(),
4444
// No built-in fallback: unset means `-m` is omitted and opencode's configured default model is used.
4545
// Previously hardcoded: "opencode-go/muse-spark-1.3-contributor" (it overrode the user's opencode config).
46+
// Applies to read-only runs (auto: false) too; the separate OPENCODE_DELEGATE_READ_MODEL was removed.
4647
defaultModel: model(process.env.OPENCODE_DELEGATE_DEFAULT_MODEL, undefined),
47-
// Used when no model is given and the run is read-only (auto: false): reading, reviews, questions.
48-
// Previously hardcoded: "opencode/muse-spark-1.3-contributor-free".
49-
readModel: model(process.env.OPENCODE_DELEGATE_READ_MODEL, undefined),
5048
auto: bool(process.env.OPENCODE_DELEGATE_AUTO, true),
5149
timeoutSec: int(process.env.OPENCODE_DELEGATE_TIMEOUT, 1800),
5250
maxOutputChars: int(process.env.OPENCODE_DELEGATE_MAX_OUTPUT, 40000),

‎src/delegate.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ export async function delegate(
4343
const cwd = resolve(config.defaultCwd, input.cwd ?? ".");
4444
if (!existsSync(cwd)) throw new Error(`cwd does not exist: ${cwd}`);
4545
const auto = input.auto ?? config.auto;
46-
const query =
47-
input.model ?? (auto ? config.defaultModel : (config.readModel ?? config.defaultModel));
46+
const query = input.model ?? config.defaultModel;
4847
const model = query ? await resolveModelOrThrow(query) : undefined;
4948
const files = input.files?.map((f) => (isAbsolute(f) ? f : resolve(cwd, f)));
5049

‎src/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const delegateShape = {
4444
.string()
4545
.optional()
4646
.describe(
47-
`opencode model: exact 'provider/model' id (e.g. 'xai/grok-4.7') or a loose name ('grok 4.7', 'kimi k3'). Append '#variant' for a reasoning variant. Omit to use the default: ${config.defaultModel ?? "opencode's default"} for normal tasks, ${config.readModel ?? config.defaultModel ?? "opencode's default"} (free) when auto is false.`,
47+
`opencode model: exact 'provider/model' id (e.g. 'xai/grok-4.7') or a loose name ('grok 4.7', 'kimi k3'). Append '#variant' for a reasoning variant. Omit to use the default: ${config.defaultModel ?? "opencode's configured default model"}.`,
4848
),
4949
cwd: z
5050
.string()
@@ -72,7 +72,7 @@ const delegateShape = {
7272
.boolean()
7373
.optional()
7474
.describe(
75-
`Auto-approve tool permissions (edits, shell) that are not explicitly denied. Default: ${config.auto}. Set false for read-only work (reading files, reviews, questions); without a model that also selects the free read model.`,
75+
`Auto-approve tool permissions (edits, shell) that are not explicitly denied. Default: ${config.auto}. Set false for read-only work (reading files, reviews, questions).`,
7676
),
7777
thinking: z
7878
.boolean()

‎test/config.test.ts‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { join } from "node:path";
44
const root = join(import.meta.dir, "..");
55

66
// config is evaluated at import time, so each case loads it in a fresh process.
7-
function loadModels(env: Record<string, string>): { d: string | null; r: string | null } {
7+
function loadModels(env: Record<string, string>): { d: string | null; hasRead: boolean } {
88
const base = { ...process.env };
99
delete base.OPENCODE_DELEGATE_DEFAULT_MODEL;
1010
delete base.OPENCODE_DELEGATE_READ_MODEL;
@@ -13,30 +13,36 @@ function loadModels(env: Record<string, string>): { d: string | null; r: string
1313
"bun",
1414
"-e",
1515
`const { config } = await import(${JSON.stringify(join(root, "src/config.ts"))});
16-
console.log(JSON.stringify({ d: config.defaultModel ?? null, r: config.readModel ?? null }));`,
16+
console.log(JSON.stringify({ d: config.defaultModel ?? null, hasRead: "readModel" in config }));`,
1717
],
1818
{ env: { ...base, ...env } },
1919
);
2020
return JSON.parse(proc.stdout.toString());
2121
}
2222

23-
describe("default models", () => {
24-
test("unset env leaves both undefined so opencode's configured default is used", () => {
25-
expect(loadModels({})).toEqual({ d: null, r: null });
23+
describe("default model", () => {
24+
test("unset env leaves it undefined so opencode's configured default is used", () => {
25+
expect(loadModels({})).toEqual({ d: null, hasRead: false });
2626
});
2727

28-
test("env vars still override", () => {
29-
expect(
30-
loadModels({
31-
OPENCODE_DELEGATE_DEFAULT_MODEL: "xai/grok-4.7",
32-
OPENCODE_DELEGATE_READ_MODEL: "opencode/beam-free",
33-
}),
34-
).toEqual({ d: "xai/grok-4.7", r: "opencode/beam-free" });
28+
test("OPENCODE_DELEGATE_DEFAULT_MODEL overrides", () => {
29+
expect(loadModels({ OPENCODE_DELEGATE_DEFAULT_MODEL: "xai/grok-4.7" })).toEqual({
30+
d: "xai/grok-4.7",
31+
hasRead: false,
32+
});
3533
});
3634

3735
test("empty env means opencode's default", () => {
38-
expect(
39-
loadModels({ OPENCODE_DELEGATE_DEFAULT_MODEL: "", OPENCODE_DELEGATE_READ_MODEL: " " }),
40-
).toEqual({ d: null, r: null });
36+
expect(loadModels({ OPENCODE_DELEGATE_DEFAULT_MODEL: " " })).toEqual({
37+
d: null,
38+
hasRead: false,
39+
});
40+
});
41+
42+
test("OPENCODE_DELEGATE_READ_MODEL no longer exists", () => {
43+
expect(loadModels({ OPENCODE_DELEGATE_READ_MODEL: "opencode/beam-free" })).toEqual({
44+
d: null,
45+
hasRead: false,
46+
});
4147
});
4248
});

0 commit comments

Comments
 (0)