From 36ca5432dd4d61434045b96bf5d3d63bf82b17c9 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 13 Oct 2026 13:08:10 +0800 Subject: [PATCH] claude: /model's magpie models follow Names in agents' lists (love1sbug on X) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit love1sbug on X, on v0.1.1220: switching Names in agents' lists (Agent 列表里的名称) between Off, Not on names I set and On still changed nothing in the agent's model list. For Claude Code that was so: the modelPicker magpie writes into ~/.claude/settings.json labelled every model with viaMagpie's Option.Label, the name alone (magpie's own picker shows the provider in its Note), so no mode changed a row. SyncCatalog did rewrite the file on each change, with the same rows. writePicker now labels each row as every other agent's list names the model: provider.Labels over the catalog Claude Code is shown (listLabels in route.go), so On gives "GLM-4.6 · Relay" and "Mix · routing group", Not on names I set drops it from a name the user gave, Off drops it everywhere. A description that would repeat what the label says ("Relay · via magpie" under "GLM-4.6 · Relay") is "via magpie". TestClaudePickerFollowsSuffixMode sets each mode through provider.SetSuffixMode with catalog.Changed = SyncCatalog, as magpie does, and reads the labels and descriptions back from settings.json; it fails on the old claude.go (every mode gave "GLM-4.6"). The routing group test now expects "Auto DeepSeek · routing group" / "via magpie". Run: go test -tags nogui ./internal/agent ./internal/gui ./internal/provider; gofmt -l; go vet on darwin, GOOS=linux, GOOS=windows. Not tried: a real Claude Code's /model reading the new labels (the picker's label key is the one magpie wrote before, only its text changed). --- internal/agent/claude.go | 12 ++- internal/agent/claude_picker_group_test.go | 2 +- internal/agent/claude_picker_names_test.go | 85 ++++++++++++++++++++++ internal/agent/route.go | 13 ++++ 4 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 internal/agent/claude_picker_names_test.go diff --git a/internal/agent/claude.go b/internal/agent/claude.go index e1ef09e67..f76673c06 100644 --- a/internal/agent/claude.go +++ b/internal/agent/claude.go @@ -732,12 +732,22 @@ func claudeIn(at place) *Agent { } } } + // each row's label is the model's name as every agent's list calls + // it, by the Provider in model names setting (provider.Labels): the + // picker took the name alone, so none of the setting's three ways + // changed /model (love1sbug on X). A description that would say the + // provider the label already says is left "via magpie". + labels := listLabels("claude") rows := []any{} for _, o := range viaMagpie("claude", "") { if slices.ContainsFunc(onTier, func(v string) bool { return claudeSameModel(v, o.Value) }) { continue } - rows = append(rows, map[string]any{"model": spell(mark1M(o.Value)), "label": cmp.Or(o.Label, o.Value), "description": o.Note}) + label, note := cmp.Or(labels[o.Ref], o.Label, o.Value), o.Note + if by, ok := strings.CutSuffix(note, " · via magpie"); ok && label != o.Label && strings.HasSuffix(label, " · "+by) { + note = "via magpie" + } + rows = append(rows, map[string]any{"model": spell(mark1M(o.Value)), "label": label, "description": note}) } if len(rows) == 0 { return dropPicker() diff --git a/internal/agent/claude_picker_group_test.go b/internal/agent/claude_picker_group_test.go index 51dbd7a56..ccafe3c0d 100644 --- a/internal/agent/claude_picker_group_test.go +++ b/internal/agent/claude_picker_group_test.go @@ -69,7 +69,7 @@ func TestClaudePickerListsRoutingGroups(t *testing.T) { t.Fatalf("picker has %d options, want the group and 30 models: %v", len(opts), listed()) } // the group, first, as the model Claude Code was set to is spelled - if g := opts[0]; g["model"] != main || g["label"] != "Auto DeepSeek" || g["description"] != "routing group · via magpie" { + if g := opts[0]; g["model"] != main || g["label"] != "Auto DeepSeek · routing group" || g["description"] != "via magpie" { t.Fatalf("first option %v, want the group as %q: %v", g, main, listed()) } for _, m := range models { diff --git a/internal/agent/claude_picker_names_test.go b/internal/agent/claude_picker_names_test.go new file mode 100644 index 000000000..dbd93e02c --- /dev/null +++ b/internal/agent/claude_picker_names_test.go @@ -0,0 +1,85 @@ +package agent + +import ( + "encoding/json" + "path/filepath" + "testing" + + "github.com/yetone/magpie/internal/catalog" + "github.com/yetone/magpie/internal/edit" + "github.com/yetone/magpie/internal/provider" +) + +// love1sbug on X: switching Names in agents' lists between Off, Not on +// names I set and On changed nothing in Claude Code's /model, as its +// modelPicker labelled every model by its name alone. Each row is now +// labelled as every agent's list names the model (provider.Labels), and +// written again when the setting changes; a description that would repeat +// the provider the label says is left "via magpie". +func TestClaudePickerFollowsSuffixMode(t *testing.T) { + home := syncHome(t) + if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"glm-4.6", "glm-5"}}); err != nil { + t.Fatal(err) + } + if err := provider.SetModelName("relay/glm-5", "My GLM"); err != nil { + t.Fatal(err) + } + if err := provider.SaveGroup(provider.Group{ID: "mix", Name: "Mix", Members: []string{"relay/glm-4.6", "relay/glm-5"}}); err != nil { + t.Fatal(err) + } + path := filepath.Join(home, ".claude", "settings.json") + writeFile(t, path, `{"theme":"dark"}`) + if err := claude(home).Apply("model", "relay/glm-4.6"); err != nil { + t.Fatal(err) + } + catalog.Changed = SyncCatalog + t.Cleanup(func() { catalog.Changed = nil }) + rows := func() map[string][2]string { + t.Helper() + var p struct { + Options []struct{ Model, Label, Description string } + } + raw, _ := edit.GetJSON(path, "modelPicker") + if err := json.Unmarshal([]byte(raw), &p); err != nil { + t.Fatalf("modelPicker: %v\n%s", err, readFile(path)) + } + out := map[string][2]string{} + for _, o := range p.Options { + out[o.Model] = [2]string{o.Label, o.Description} + } + return out + } + for _, c := range []struct { + mode string + glm, mine, mix string + glmNote, mixNot string + }{ + {provider.SuffixOn, "GLM-4.6 · Relay", "My GLM · Relay", "Mix · routing group", "via magpie", "via magpie"}, + {provider.SuffixOwn, "GLM-4.6 · Relay", "My GLM", "Mix", "via magpie", "routing group · via magpie"}, + {provider.SuffixOff, "GLM-4.6", "My GLM", "Mix", "Relay · via magpie", "routing group · via magpie"}, + {provider.SuffixOn, "GLM-4.6 · Relay", "My GLM · Relay", "Mix · routing group", "via magpie", "via magpie"}, + } { + if err := provider.SetSuffixMode(c.mode); err != nil { + t.Fatal(err) + } + got := rows() + want := map[string][2]string{ + "relay/glm-4.6": {c.glm, c.glmNote}, + "relay/glm-5": {c.mine, ""}, + "group/mix": {c.mix, c.mixNot}, + } + for id, w := range want { + g, ok := got[id] + if !ok { + for k := range got { + if k == id+"[1m]" { + g, ok = got[k], true + } + } + } + if !ok || g[0] != w[0] || w[1] != "" && g[1] != w[1] { + t.Fatalf("%s: %s is %q, want %q (%v)", c.mode, id, g, w, got) + } + } + } +} diff --git a/internal/agent/route.go b/internal/agent/route.go index 092b90f7b..0f5e831cd 100644 --- a/internal/agent/route.go +++ b/internal/agent/route.go @@ -71,6 +71,19 @@ func viaMagpie(agent, prefix string) []Option { return append(groups, out...) } +// listLabels are the names the agent's own list calls the catalog's models +// by, by id: provider.Labels, which follows the Provider in model names +// setting, where an Option's Label is the name alone for magpie's picker. +func listLabels(agent string) map[string]string { + shown, _ := provider.CatalogFor(agent) + labels := provider.Labels(shown) + out := make(map[string]string, len(shown)) + for i, e := range shown { + out[e.ID] = labels[i] + } + return out +} + // viaMagpieFor is viaMagpie without the agent's own account: Codex CLI going // through magpie to its own ChatGPT login would only add a hop. func viaMagpieFor(agentID, prefix string) []Option {