Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

cmd: set OpenCode default model in config (#15127)

Jeffrey Morgan31f968fe1f0f
diff --git a/cmd/launch/opencode.go b/cmd/launch/opencode.go
index 3a0b2ae8e..48a004e64 100644
--- a/cmd/launch/opencode.go
+++ b/cmd/launch/opencode.go
@@ -147,6 +147,7 @@ func (o *OpenCode) Edit(modelList []string) error {
ollama["models"] = models
provider["ollama"] = ollama
config["provider"] = provider
+ config["model"] = "ollama/" + modelList[0]
configData, err := json.MarshalIndent(config, "", " ")
if err != nil {
diff --git a/cmd/launch/opencode_test.go b/cmd/launch/opencode_test.go
index c1833430d..62d1558e6 100644
--- a/cmd/launch/opencode_test.go
+++ b/cmd/launch/opencode_test.go
@@ -49,6 +49,7 @@ func TestOpenCodeEdit(t *testing.T) {
t.Fatal(err)
}
assertOpenCodeModelExists(t, configPath, "llama3.2")
+ assertOpenCodeDefaultModel(t, configPath, "ollama/llama3.2")
assertOpenCodeRecentModel(t, statePath, 0, "ollama", "llama3.2")
})
@@ -157,11 +158,13 @@ func TestOpenCodeEdit(t *testing.T) {
o.Edit([]string{"llama3.2", "mistral"})
assertOpenCodeModelExists(t, configPath, "llama3.2")
assertOpenCodeModelExists(t, configPath, "mistral")
+ assertOpenCodeDefaultModel(t, configPath, "ollama/llama3.2")
// Then remove one by only selecting the other
o.Edit([]string{"llama3.2"})
assertOpenCodeModelExists(t, configPath, "llama3.2")
assertOpenCodeModelNotExists(t, configPath, "mistral")
+ assertOpenCodeDefaultModel(t, configPath, "ollama/llama3.2")
})
t.Run("preserve user customizations on managed models", func(t *testing.T) {
@@ -338,6 +341,22 @@ func assertOpenCodeModelNotExists(t *testing.T, path, model string) {
}
}
+func assertOpenCodeDefaultModel(t *testing.T, path, want string) {
+ t.Helper()
+ data, err := os.ReadFile(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var cfg map[string]any
+ if err := json.Unmarshal(data, &cfg); err != nil {
+ t.Fatal(err)
+ }
+ got, _ := cfg["model"].(string)
+ if got != want {
+ t.Fatalf("default model = %q, want %q", got, want)
+ }
+}
+
func assertOpenCodeRecentModel(t *testing.T, path string, index int, providerID, modelID string) {
t.Helper()
data, err := os.ReadFile(path)