Skip to content

Commit a713809

Browse files
mdesmetclaude
andcommitted
feat: default to altimate-backend model when configured
When no model is explicitly configured and no recently-used model exists, prefer altimate-backend/altimate-default as the default model if altimate credentials are present. This applies to both the main Provider.defaultModel() and the ACP agent defaultModel() fallback chains. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b66d9f5 commit a713809

3 files changed

Lines changed: 173 additions & 0 deletions

File tree

packages/opencode/src/acp/agent.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,16 @@ export namespace ACP {
15771577

15781578
if (specified && !providers.length) return specified
15791579

1580+
// altimate_change start — default to altimate-backend when configured and no model chosen yet
1581+
const altimateProvider = providers.find((p) => p.id === "altimate-backend")
1582+
if (altimateProvider && altimateProvider.models["altimate-default"]) {
1583+
return {
1584+
providerID: ProviderID.make("altimate-backend"),
1585+
modelID: ModelID.make("altimate-default"),
1586+
}
1587+
}
1588+
// altimate_change end
1589+
15801590
const opencodeProvider = providers.find((p) => p.id === "opencode")
15811591
if (opencodeProvider) {
15821592
if (opencodeProvider.models["big-pickle"]) {

packages/opencode/src/provider/provider.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,16 @@ export namespace Provider {
16371637
return { providerID: entry.providerID, modelID: entry.modelID }
16381638
}
16391639

1640+
// altimate_change start — default to altimate-backend when configured and no model chosen yet
1641+
const altimateProvider = providers[ProviderID.make("altimate-backend")]
1642+
if (altimateProvider && altimateProvider.models[ModelID.make("altimate-default")]) {
1643+
return {
1644+
providerID: ProviderID.make("altimate-backend"),
1645+
modelID: ModelID.make("altimate-default"),
1646+
}
1647+
}
1648+
// altimate_change end
1649+
16401650
const provider = Object.values(providers).find((p) => !cfg.provider || Object.keys(cfg.provider).includes(p.id))
16411651
if (!provider) throw new Error("no providers found")
16421652
const [model] = sort(Object.values(provider.models))

packages/opencode/test/provider/provider.test.ts

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { test, expect } from "bun:test"
22
import path from "path"
3+
import fs from "fs/promises"
34

45
import { tmpdir } from "../fixture/fixture"
56
import { Instance } from "../../src/project/instance"
67
import { Provider } from "../../src/provider/provider"
78
import { ProviderID, ModelID } from "../../src/provider/schema"
89
import { Env } from "../../src/env"
10+
import { Global } from "../../src/global"
911

1012
test("provider loaded from env variable", async () => {
1113
await using tmp = await tmpdir({
@@ -2330,4 +2332,155 @@ test("github-copilot is excluded when CODESPACES=true and only GITHUB_TOKEN is s
23302332
},
23312333
})
23322334
})
2335+
2336+
// altimate_change start — tests for altimate-backend default model preference
2337+
test("defaultModel returns altimate-backend when altimate credentials exist and no model configured", async () => {
2338+
await using tmp = await tmpdir({
2339+
init: async (dir) => {
2340+
await Bun.write(
2341+
path.join(dir, "opencode.json"),
2342+
JSON.stringify({
2343+
$schema: "https://altimate.ai/config.json",
2344+
}),
2345+
)
2346+
},
2347+
})
2348+
const originalHome = process.env.OPENCODE_TEST_HOME
2349+
process.env.OPENCODE_TEST_HOME = tmp.path
2350+
const altimateDir = path.join(tmp.path, ".altimate")
2351+
await fs.mkdir(altimateDir, { recursive: true })
2352+
await Bun.write(
2353+
path.join(altimateDir, "altimate.json"),
2354+
JSON.stringify({
2355+
altimateUrl: "https://test.altimate.ai",
2356+
altimateInstanceName: "test-instance",
2357+
altimateApiKey: "test-api-key",
2358+
}),
2359+
)
2360+
try {
2361+
await Instance.provide({
2362+
directory: tmp.path,
2363+
fn: async () => {
2364+
const model = await Provider.defaultModel()
2365+
expect(String(model.providerID)).toBe("altimate-backend")
2366+
expect(String(model.modelID)).toBe("altimate-default")
2367+
},
2368+
})
2369+
} finally {
2370+
process.env.OPENCODE_TEST_HOME = originalHome
2371+
}
2372+
})
2373+
2374+
test("defaultModel prefers altimate-backend over other providers when altimate is configured", async () => {
2375+
await using tmp = await tmpdir({
2376+
init: async (dir) => {
2377+
await Bun.write(
2378+
path.join(dir, "opencode.json"),
2379+
JSON.stringify({
2380+
$schema: "https://altimate.ai/config.json",
2381+
}),
2382+
)
2383+
},
2384+
})
2385+
const originalHome = process.env.OPENCODE_TEST_HOME
2386+
process.env.OPENCODE_TEST_HOME = tmp.path
2387+
const altimateDir = path.join(tmp.path, ".altimate")
2388+
await fs.mkdir(altimateDir, { recursive: true })
2389+
await Bun.write(
2390+
path.join(altimateDir, "altimate.json"),
2391+
JSON.stringify({
2392+
altimateUrl: "https://test.altimate.ai",
2393+
altimateInstanceName: "test-instance",
2394+
altimateApiKey: "test-api-key",
2395+
}),
2396+
)
2397+
try {
2398+
await Instance.provide({
2399+
directory: tmp.path,
2400+
init: async () => {
2401+
Env.set("ANTHROPIC_API_KEY", "test-api-key")
2402+
},
2403+
fn: async () => {
2404+
const providers = await Provider.list()
2405+
// Both providers should be available
2406+
expect(providers["anthropic"]).toBeDefined()
2407+
expect(providers["altimate-backend"]).toBeDefined()
2408+
// But defaultModel should prefer altimate-backend
2409+
const model = await Provider.defaultModel()
2410+
expect(String(model.providerID)).toBe("altimate-backend")
2411+
expect(String(model.modelID)).toBe("altimate-default")
2412+
},
2413+
})
2414+
} finally {
2415+
process.env.OPENCODE_TEST_HOME = originalHome
2416+
}
2417+
})
2418+
2419+
test("defaultModel respects explicit config model over altimate-backend", async () => {
2420+
await using tmp = await tmpdir({
2421+
init: async (dir) => {
2422+
await Bun.write(
2423+
path.join(dir, "opencode.json"),
2424+
JSON.stringify({
2425+
$schema: "https://altimate.ai/config.json",
2426+
model: "anthropic/claude-sonnet-4-20250514",
2427+
}),
2428+
)
2429+
},
2430+
})
2431+
const originalHome = process.env.OPENCODE_TEST_HOME
2432+
process.env.OPENCODE_TEST_HOME = tmp.path
2433+
const altimateDir = path.join(tmp.path, ".altimate")
2434+
await fs.mkdir(altimateDir, { recursive: true })
2435+
await Bun.write(
2436+
path.join(altimateDir, "altimate.json"),
2437+
JSON.stringify({
2438+
altimateUrl: "https://test.altimate.ai",
2439+
altimateInstanceName: "test-instance",
2440+
altimateApiKey: "test-api-key",
2441+
}),
2442+
)
2443+
try {
2444+
await Instance.provide({
2445+
directory: tmp.path,
2446+
init: async () => {
2447+
Env.set("ANTHROPIC_API_KEY", "test-api-key")
2448+
},
2449+
fn: async () => {
2450+
const model = await Provider.defaultModel()
2451+
expect(String(model.providerID)).toBe("anthropic")
2452+
expect(String(model.modelID)).toBe("claude-sonnet-4-20250514")
2453+
},
2454+
})
2455+
} finally {
2456+
process.env.OPENCODE_TEST_HOME = originalHome
2457+
}
2458+
})
2459+
2460+
test("defaultModel falls through to other providers when altimate is not configured", async () => {
2461+
await using tmp = await tmpdir({
2462+
init: async (dir) => {
2463+
await Bun.write(
2464+
path.join(dir, "opencode.json"),
2465+
JSON.stringify({
2466+
$schema: "https://altimate.ai/config.json",
2467+
}),
2468+
)
2469+
},
2470+
})
2471+
await Instance.provide({
2472+
directory: tmp.path,
2473+
init: async () => {
2474+
Env.set("ANTHROPIC_API_KEY", "test-api-key")
2475+
},
2476+
fn: async () => {
2477+
const providers = await Provider.list()
2478+
// altimate-backend should NOT be available (no credentials file)
2479+
expect(providers["altimate-backend"]).toBeUndefined()
2480+
const model = await Provider.defaultModel()
2481+
// Should fall through to anthropic
2482+
expect(String(model.providerID)).toBe("anthropic")
2483+
},
2484+
})
2485+
})
23332486
// altimate_change end

0 commit comments

Comments
 (0)