Claude Code 2.1.302 reads CLAUDE_CODE_AUTO_MODE_MODEL for the model its client-side auto mode classifier checks each action with. It doesn't change server-side auto mode, and a classifier model Anthropic sets for the account comes first. The installed 2.1.303 binary has the variable: unset, Claude Code picks the sonnet tier's model, else Sonnet. It refuses claude-sonnet-5-5, claude-opus-5-5 and claude-opus-5 with a warning and uses its own pick instead. - Claude Code gets an "auto mode" field (key auto_mode, Quiet, follows nothing). It can be set only while Claude Code is routed through magpie, only to one of magpie's models, and is written dashed like the other model keys. Its options leave out the three models Claude Code refuses, and Set refuses them too. - A value the user had before magpie routed Claude Code is stashed with their tiers (claudeOwnEnv). It is taken out while wired in and comes back on Disconnect or Claude Code's own model, unless they have set one again since. The restore loop now skips any claudeOwnEnv key the user wrote again. - magpie's own value goes when magpie steps out. A value the user sets while wired in is never touched. - GUI: an "Auto mode" line in the opened row's Tiers, after Subagents, using the app's model picker. Default is noted as Claude Code's own pick. Strings are translated for zh, zh-TW, ja and de. - Docs: agent-wiring.md and reference.md. Run, in a worktree at origin/main33dbdcc52, sandbox HOME, load ~110-135: - gofmt -l: clean. - go vet ./... (darwin), GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./...: clean. - set -o pipefail; go test -timeout 45m ./...: every package ok. - Breaking by hand turned the new tests red: dropping the stash-time removal, the "set again since" check, the no-classifier refusal and the removal on step-out made TestClaudeAutoModeModel, TestClaudeAutoModeUserValue and TestClaudeDisconnect fail. - GUI, playwright 1.62.0, Chromium and WebKit: 84 files the change reaches (agent*, claude*, tier/subagent effort, codex subagent/memories, gui-de, gui-ja, gui-zh-tw, i18n-keys, header-relang, and every file with a Claude row or the model picker), concurrency 4: 1305 of 1306 pass. - The one red is agent-expand-steady "webkit 980px ... slides" ("slid open: 208"). Its fixture has no auto mode field. Alone it passed 3 of 3. Filed as #2935. - claude-auto-mode.test.cjs (new; en and zh, 1100px and 560px, both engines): 8 of 8 pass, and 4 of 4 fail in Chromium on the old app.js. - Not tried against a real Claude Code session. - After rebasing on origin/mainab7ec8c65(three commits, none touching these files): - go vet ./internal/agent and TestClaudeAutoMode*/TestClaudeDisconnect: ok. - claude-auto-mode, tier-effort, i18n-keys and agent-layout, both engines: 23 of 23 pass serially, and 19 of 19 in parallel. - A first parallel try at load ~127 had 16 reds in claude-auto-mode and tier-effort, and its output wasn't kept. It didn't come back in the next three runs.
174 lines
6.3 KiB
Go
174 lines
6.3 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/edit"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// claudeAutoModeHome is a sandbox HOME with a provider serving a Claude
|
|
// model the classifier runs on, one Claude Code refuses for it, and
|
|
// another vendor's, and Claude Code's settings.json holding before.
|
|
func claudeAutoModeHome(t *testing.T, before string) (*Agent, string, func(string) string) {
|
|
t.Helper()
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
|
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Chat: "https://relay.example/v1", Key: "k", Models: []string{"claude-haiku-4-5", "claude-opus-5-5", "deepseek-pro"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
path := filepath.Join(home, ".claude", "settings.json")
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(path, []byte(before), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
env := func(k string) string { v, _ := edit.GetJSON(path, "env."+k); return v }
|
|
return claude(home), path, env
|
|
}
|
|
|
|
// Claude Code's auto mode classifier can have a model of its own
|
|
// (CLAUDE_CODE_AUTO_MODE_MODEL, 2.1.302; Linka on Discord): only while
|
|
// magpie routes Claude Code, only one of magpie's models, never one Claude
|
|
// Code refuses to run its classifier on, and gone again with magpie.
|
|
func TestClaudeAutoModeModel(t *testing.T) {
|
|
a, _, env := claudeAutoModeHome(t, `{}`)
|
|
f := a.Field("auto_mode")
|
|
if f == nil {
|
|
t.Fatal("no auto_mode field")
|
|
}
|
|
if err := f.Set("relay/claude-haiku-4-5"); err == nil {
|
|
t.Fatal("an auto mode model before Claude Code is routed should fail")
|
|
}
|
|
if len(f.Options(nil)) != 0 || f.Get() != "" {
|
|
t.Fatalf("unrouted: %q %v", f.Get(), f.Options(nil))
|
|
}
|
|
if err := a.Field("model").Set("relay/deepseek-pro"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// unset, Claude Code's own pick: magpie writes nothing for it
|
|
if f.Get() != "" || env(claudeAutoModeEnv) != "" {
|
|
t.Fatalf("auto mode should be unset: %v", a.Values())
|
|
}
|
|
opts := f.Options(nil)
|
|
if !containsOption(opts, "relay/claude-haiku-4-5") || !containsOption(opts, "relay/deepseek-pro") {
|
|
t.Fatalf("options miss magpie's models: %v", opts)
|
|
}
|
|
if containsOption(opts, "relay/claude-opus-5-5") {
|
|
t.Fatalf("Opus 5.5 is offered, which Claude Code won't classify with: %v", opts)
|
|
}
|
|
if err := f.Set("relay/claude-opus-5-5"); err == nil || env(claudeAutoModeEnv) != "" {
|
|
t.Fatalf("Opus 5.5 taken: %v %q", err, env(claudeAutoModeEnv))
|
|
}
|
|
if err := f.Set("claude-haiku-4-5"); err == nil || env(claudeAutoModeEnv) != "" {
|
|
t.Fatalf("a model magpie doesn't serve taken: %v %q", err, env(claudeAutoModeEnv))
|
|
}
|
|
if err := f.Set("relay/claude-haiku-4-5"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// written as Claude Code is given a model, with dashes
|
|
if got := env(claudeAutoModeEnv); got != provider.ClaudeSpelled("relay/claude-haiku-4-5") {
|
|
t.Fatalf("env %q", got)
|
|
}
|
|
if f.Get() != "relay/claude-haiku-4-5" {
|
|
t.Fatalf("get %q", f.Get())
|
|
}
|
|
// a new main model leaves it be: it follows no field
|
|
if err := a.Field("model").Set("relay/claude-haiku-4-5"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if f.Get() != "relay/claude-haiku-4-5" {
|
|
t.Fatalf("a new model moved auto mode: %v", a.Values())
|
|
}
|
|
if err := f.Set(""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if env(claudeAutoModeEnv) != "" {
|
|
t.Fatal("clearing left the env behind")
|
|
}
|
|
if err := f.Set("relay/deepseek-pro"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// back to Claude Code as installed: magpie's pick goes with it
|
|
if err := a.Field("model").Set(""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if env(claudeAutoModeEnv) != "" {
|
|
t.Fatalf("reset left the auto mode model behind")
|
|
}
|
|
if err := f.Set(""); err != nil {
|
|
t.Fatalf("clearing while unrouted: %v", err)
|
|
}
|
|
}
|
|
|
|
// An auto mode model the user set before magpie routed Claude Code waits
|
|
// out of the env while magpie is wired in (it would name a model magpie
|
|
// doesn't serve) and comes back after; one they set while magpie is wired
|
|
// in is theirs, and magpie never takes it out.
|
|
func TestClaudeAutoModeUserValue(t *testing.T) {
|
|
t.Run("before", func(t *testing.T) {
|
|
a, path, env := claudeAutoModeHome(t, `{"env":{"CLAUDE_CODE_AUTO_MODE_MODEL":"claude-sonnet-4-6"}}`)
|
|
if err := a.Field("model").Set("relay/deepseek-pro"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if env(claudeAutoModeEnv) != "" || a.Field("auto_mode").Get() != "" {
|
|
t.Fatalf("the user's own auto mode model stayed in while routed: %q", env(claudeAutoModeEnv))
|
|
}
|
|
if err := a.Field("auto_mode").Set("relay/claude-haiku-4-5"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Disconnect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := env(claudeAutoModeEnv); got != "claude-sonnet-4-6" {
|
|
b, _ := os.ReadFile(path)
|
|
t.Fatalf("the user's own auto mode model not back: %q\n%s", got, b)
|
|
}
|
|
})
|
|
t.Run("while routed", func(t *testing.T) {
|
|
a, _, env := claudeAutoModeHome(t, `{}`)
|
|
if err := a.Field("model").Set("relay/deepseek-pro"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
v := "claude-sonnet-4-6"
|
|
if err := edit.SetJSON(filepath.Join(os.Getenv("HOME"), ".claude", "settings.json"), edit.KV{Path: "env." + claudeAutoModeEnv, Value: v}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// another main model, then Claude Code as installed
|
|
if err := a.Field("model").Set("relay/claude-haiku-4-5"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if env(claudeAutoModeEnv) != v {
|
|
t.Fatalf("a new model took the user's auto mode model: %q", env(claudeAutoModeEnv))
|
|
}
|
|
if err := a.Field("model").Set(""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if env(claudeAutoModeEnv) != v {
|
|
t.Fatalf("stepping out took the user's auto mode model: %q", env(claudeAutoModeEnv))
|
|
}
|
|
})
|
|
t.Run("set again before stepping out", func(t *testing.T) {
|
|
a, _, env := claudeAutoModeHome(t, `{"env":{"CLAUDE_CODE_AUTO_MODE_MODEL":"claude-sonnet-4-6"}}`)
|
|
if err := a.Field("model").Set("relay/deepseek-pro"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
v := "claude-haiku-4-5"
|
|
if err := edit.SetJSON(filepath.Join(os.Getenv("HOME"), ".claude", "settings.json"), edit.KV{Path: "env." + claudeAutoModeEnv, Value: v}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Disconnect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if env(claudeAutoModeEnv) != v {
|
|
t.Fatalf("the stash wrote over the user's newer auto mode model: %q", env(claudeAutoModeEnv))
|
|
}
|
|
})
|
|
}
|