Skip to content

Commit 4c57450

Browse files
committed
fix(config): use opencode's configured default model when none is given
1 parent 0389de5 commit 4c57450

5 files changed

Lines changed: 62 additions & 25 deletions

File tree

‎README.md‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,17 @@ git config core.hooksPath hooks/ # pre-commit (staged lint/format), pre-push (
143143
144144
`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`:
145145
146-
| Variable | Default | Description |
147-
| --------------------------------------- | ------------------- | ----------------------------------------------------------------- |
148-
| `OPENCODE_BIN` | auto-detected | Path to `opencode` |
149-
| `OPENCODE_DELEGATE_DEFAULT_MODEL` | see `src/config.ts` | Model when none given; empty string means OpenCode's own default |
150-
| `OPENCODE_DELEGATE_READ_MODEL` | see `src/config.ts` | Model when none given and `auto` is false; empty string as above |
151-
| `OPENCODE_DELEGATE_AUTO` | `true` | Default for `auto`; `0`, `false`, `no`, `off` disable it |
152-
| `OPENCODE_DELEGATE_TIMEOUT` | `1800` | Seconds before a run is killed |
153-
| `OPENCODE_DELEGATE_MAX_OUTPUT` | `40000` | Maximum response characters returned |
154-
| `OPENCODE_DELEGATE_THINKING` | `true` | Include reasoning blocks in output |
155-
| `OPENCODE_DELEGATE_CWD` | process cwd | Base working directory |
156-
| `OPENCODE_DELEGATE_PREFERRED_PROVIDERS` | none | Comma-separated provider order when a model has several providers |
146+
| Variable | Default | Description |
147+
| --------------------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
148+
| `OPENCODE_BIN` | auto-detected | Path to `opencode` |
149+
| `OPENCODE_DELEGATE_DEFAULT_MODEL` | unset | Model when none given; unset or empty means OpenCode's configured default |
150+
| `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 |
151+
| `OPENCODE_DELEGATE_AUTO` | `true` | Default for `auto`; `0`, `false`, `no`, `off` disable it |
152+
| `OPENCODE_DELEGATE_TIMEOUT` | `1800` | Seconds before a run is killed |
153+
| `OPENCODE_DELEGATE_MAX_OUTPUT` | `40000` | Maximum response characters returned |
154+
| `OPENCODE_DELEGATE_THINKING` | `true` | Include reasoning blocks in output |
155+
| `OPENCODE_DELEGATE_CWD` | process cwd | Base working directory |
156+
| `OPENCODE_DELEGATE_PREFERRED_PROVIDERS` | none | Comma-separated provider order when a model has several providers |
157157
158158
## Releasing
159159

‎dist/index.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21527,8 +21527,8 @@ function int2(v, dflt) {
2152721527
}
2152821528
var config2 = {
2152921529
bin: resolveBin(),
21530-
defaultModel: model(process.env.OPENCODE_DELEGATE_DEFAULT_MODEL, "opencode-go/muse-spark-1.3-contributor"),
21531-
readModel: model(process.env.OPENCODE_DELEGATE_READ_MODEL, "opencode/muse-spark-1.3-contributor-free"),
21530+
defaultModel: model(process.env.OPENCODE_DELEGATE_DEFAULT_MODEL, undefined),
21531+
readModel: model(process.env.OPENCODE_DELEGATE_READ_MODEL, undefined),
2153221532
auto: bool(process.env.OPENCODE_DELEGATE_AUTO, true),
2153321533
timeoutSec: int2(process.env.OPENCODE_DELEGATE_TIMEOUT, 1800),
2153421534
maxOutputChars: int2(process.env.OPENCODE_DELEGATE_MAX_OUTPUT, 40000),

‎examples/claude_desktop_config.json‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
"command": "bunx",
55
"args": ["@lehcode/claude-opencode-delegate"],
66
"env": {
7-
"OPENCODE_DELEGATE_CWD": "/home/YOU/projects/my-app",
8-
"OPENCODE_DELEGATE_DEFAULT_MODEL": "opencode-go/muse-spark-1.3-contributor",
9-
"OPENCODE_DELEGATE_READ_MODEL": "opencode/muse-spark-1.3-contributor-free"
7+
"OPENCODE_DELEGATE_CWD": "/home/YOU/projects/my-app"
108
}
119
}
1210
}

‎src/config.ts‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function resolveBin(env = process.env): string {
2424
}
2525

2626
/** Unset → fallback; set to "" → undefined (use opencode's own default). */
27-
function model(v: string | undefined, fallback: string): string | undefined {
27+
function model(v: string | undefined, fallback: string | undefined): string | undefined {
2828
if (v === undefined) return fallback;
2929
return v.trim() || undefined;
3030
}
@@ -41,15 +41,12 @@ function int(v: string | undefined, dflt: number): number {
4141

4242
export const config = {
4343
bin: resolveBin(),
44-
defaultModel: model(
45-
process.env.OPENCODE_DELEGATE_DEFAULT_MODEL,
46-
"opencode-go/muse-spark-1.3-contributor",
47-
),
44+
// No built-in fallback: unset means `-m` is omitted and opencode's configured default model is used.
45+
// Previously hardcoded: "opencode-go/muse-spark-1.3-contributor" (it overrode the user's opencode config).
46+
defaultModel: model(process.env.OPENCODE_DELEGATE_DEFAULT_MODEL, undefined),
4847
// Used when no model is given and the run is read-only (auto: false): reading, reviews, questions.
49-
readModel: model(
50-
process.env.OPENCODE_DELEGATE_READ_MODEL,
51-
"opencode/muse-spark-1.3-contributor-free",
52-
),
48+
// Previously hardcoded: "opencode/muse-spark-1.3-contributor-free".
49+
readModel: model(process.env.OPENCODE_DELEGATE_READ_MODEL, undefined),
5350
auto: bool(process.env.OPENCODE_DELEGATE_AUTO, true),
5451
timeoutSec: int(process.env.OPENCODE_DELEGATE_TIMEOUT, 1800),
5552
maxOutputChars: int(process.env.OPENCODE_DELEGATE_MAX_OUTPUT, 40000),

‎test/config.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { describe, expect, test } from "bun:test";
2+
import { join } from "node:path";
3+
4+
const root = join(import.meta.dir, "..");
5+
6+
// 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 } {
8+
const base = { ...process.env };
9+
delete base.OPENCODE_DELEGATE_DEFAULT_MODEL;
10+
delete base.OPENCODE_DELEGATE_READ_MODEL;
11+
const proc = Bun.spawnSync(
12+
[
13+
"bun",
14+
"-e",
15+
`const { config } = await import(${JSON.stringify(join(root, "src/config.ts"))});
16+
console.log(JSON.stringify({ d: config.defaultModel ?? null, r: config.readModel ?? null }));`,
17+
],
18+
{ env: { ...base, ...env } },
19+
);
20+
return JSON.parse(proc.stdout.toString());
21+
}
22+
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 });
26+
});
27+
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" });
35+
});
36+
37+
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 });
41+
});
42+
});

0 commit comments

Comments
 (0)