moer2831 on Discord: a model picked for one of Claude Desktop's tiers ran
in the Code tab on Claude Code's generic prompt, not the one of the
Claude model of that tier ("通用提示词和对应模型提示词差距挺大的,感觉直接
蠢了一个度"). Desktop 4.29 and later hand Claude Code behavesAs only from
a profile's inferenceModels (z3t in 4.4212's app.asar: modelPicker
options with each entry's behavesAs).
What changed:
- gateway.DesktopInferenceModels: while a model is picked for a tier,
the list is every row /v1/models gives Desktop, by its id and in its
order (a non-empty list replaces discovery, pzn), with supports1m,
prefer1m and labelOverride as Desktop read them off the row, and a
pick's anthropicFamilyTier/isFamilyDefault. A pick that isn't a Claude
model gets behavesAs = its tier's newest Claude id (claude-opus-5-5,
claude-sonnet-5-5, claude-haiku-5-5, claude-fable-5-1). Nothing picked
(or a pick no longer listed): no list. Unreadable picks are unknown.
- agent: desktopSyncModels writes it into magpie's Desktop profile on a
tier's Set, as Desktop comes on magpie and on Sync; temp+rename, only
when it changed; taken away when nothing is picked. The list is
magpie's only while its hash is one magpie recorded (stash mark
claude-desktop.models); any other list (the user's) is never written
over or removed.
- Claude Code's modelSettings gets the pick's own window even when it
matches the default (claudeBudget.behaves), since behavesAs would
otherwise give it the Claude model's.
- GUI: the tiers menu ends with one line, "Claude Desktop reads the
tiers as it starts: restart it after a change." (en, zh, zh-TW, ja,
de). The Agents row's Restart already lights from the profile hash.
- docs/subsystems/agent-wiring.md and gateway-routing.md.
Run on mote at this tree (base c86fa2a34): gofmt -l clean; GOOS=linux
(-tags nogui) and GOOS=windows go vet ./internal/agent ./internal/gateway;
go test -count=1 -timeout 45m ./internal/agent ./internal/gateway
./internal/gui ./internal/cli ./internal/tui ./internal/backup
./internal/davsync ./internal/library ./internal/profile ./internal/stats
./internal/uninstall: ok but internal/gateway's
TestCodexPoolSaysTheClientsVersion (passes alone here and at main; #4807)
and internal/gui's TestMainWindowCorners (red the same at origin/main
6a6e4fefa; #3949). GUI (chromium + webkit, every
language they cover): desktop-tiers, i18n-keys, and every file named for
tiers, picks, roles, Desktop, i18n or a language (887 tests,
871 pass; the 16 reds are 4 files red the same at origin/main 6a6e4fefa:
found-skill-pick-remove #4097, menu-input-scroll #3402,
phone-connect-menu #4706/#4707, provider-picks-stay #4397). Not the
whole GUI suite.
Rebased on origin/main a5c1fa4b4 (nothing there touches agent, gateway or
GUI assets but routing.css), then again at the pushed head: go vet
./internal/agent ./internal/gateway; the size budgets,
TestDesktopInferenceModels, TestClaudeDesktop*, TestClaudePlan;
desktop-tiers and i18n-keys in both engines: ok.
Broken by hand, each red: behavesAs left out (TestDesktopInferenceModels);
the window write's behaves check dropped (TestClaudePlan); the sync on a
tier's Set dropped (TestClaudeDesktopModelsList); the user-list guard
off (TestClaudeDesktopModelsList); the menu's line not shown
(desktop-tiers 0 of 4).
Not tried: a real Claude Desktop 4.29 or later (none on mote; this
Mac's is 2.7032 and live). Builds before 4.29 ignore behavesAs and take
the names. Desktop 1.x gets the mythos ids. A user's own gateway profile
applied in Desktop makes magpie's list do nothing.
Thanks moer2831 for the report.
153 lines
4.4 KiB
Go
153 lines
4.4 KiB
Go
package agent
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/edit"
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// moer2831 on Discord: a model picked for a Claude Desktop tier ran in its
|
|
// Code tab on Claude Code's generic prompt. While a tier is picked,
|
|
// magpie's profile lists Desktop's models in inferenceModels, the pick's
|
|
// with behavesAs, and Claude Code is told the pick's window, since it
|
|
// would take the behavesAs model's. The list follows the picks and the
|
|
// catalog, is written only when it changes, goes when nothing is picked,
|
|
// and a list the user wrote is theirs. Picks that can't be read leave it
|
|
// as it is.
|
|
func TestClaudeDesktopModelsList(t *testing.T) {
|
|
home, p := desktopSandbox(t)
|
|
if err := provider.Save(provider.Provider{ID: "v", Name: "V", Chat: "http://127.0.0.1:1/v1", Key: "k", Models: []string{"a", "b"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := catalog.SaveLive("v", "http://127.0.0.1:1/v1", []catalog.Model{{ID: "a", Context: 272000}, {ID: "b", Context: 128000}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cc := filepath.Join(home, ".claude", "settings.json")
|
|
writeFile(t, cc, `{"theme":"dark"}`)
|
|
d := claudeDesktop(home)
|
|
set := func(key, v string) {
|
|
t.Helper()
|
|
if err := d.Field(key).Set(v); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
id := func(ref string) string {
|
|
for _, e := range provider.Catalog() {
|
|
if e.ID == ref {
|
|
return gateway.DesktopID(e)
|
|
}
|
|
}
|
|
t.Fatalf("%s not in the catalog", ref)
|
|
return ""
|
|
}
|
|
list := func() []map[string]any {
|
|
t.Helper()
|
|
raw, ok := edit.GetJSONRaw(p.prof, "inferenceModels")
|
|
if !ok {
|
|
return nil
|
|
}
|
|
var out []map[string]any
|
|
if err := json.Unmarshal([]byte(raw), &out); err != nil {
|
|
t.Fatalf("%v: %s", err, raw)
|
|
}
|
|
return out
|
|
}
|
|
entry := func(ref string) map[string]any {
|
|
t.Helper()
|
|
for _, e := range list() {
|
|
if e["name"] == id(ref) {
|
|
return e
|
|
}
|
|
}
|
|
t.Fatalf("%s not listed: %v", ref, list())
|
|
return nil
|
|
}
|
|
|
|
set("provider", "magpie")
|
|
if l := list(); l != nil {
|
|
t.Fatalf("nothing picked: %v", l)
|
|
}
|
|
|
|
// a's pick for sonnet: the list, a as Sonnet 5.5, and its window told
|
|
set("sonnet", "v/a")
|
|
if l := list(); len(l) != 2 {
|
|
t.Fatalf("a for sonnet: %v", l)
|
|
}
|
|
if e := entry("v/a"); e["behavesAs"] != "claude-sonnet-5-5" || e["anthropicFamilyTier"] != "sonnet" {
|
|
t.Fatalf("a: %v", e)
|
|
}
|
|
if e := entry("v/b"); e["behavesAs"] != nil {
|
|
t.Fatalf("b unpicked: %v", e)
|
|
}
|
|
if v, _ := edit.GetJSON(cc, budgetPath(id("v/a"))); v != "272000" {
|
|
t.Fatalf("a's window in Claude Code's settings: %q\n%s", v, readFile(cc))
|
|
}
|
|
|
|
// unchanged: not written again
|
|
st, _ := os.Stat(p.prof)
|
|
old := st.ModTime().Add(-2 * time.Second)
|
|
os.Chtimes(p.prof, old, old)
|
|
if err := d.Sync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if st, _ := os.Stat(p.prof); !st.ModTime().Equal(old) {
|
|
t.Fatal("the profile was written with nothing changed")
|
|
}
|
|
|
|
// a model added reaches the list with the catalog
|
|
if err := provider.Save(provider.Provider{ID: "w", Name: "W", Chat: "http://127.0.0.1:1/v1", Key: "k", Models: []string{"c"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := d.Sync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if l := list(); len(l) != 3 {
|
|
t.Fatalf("after w/c: %v", l)
|
|
}
|
|
|
|
// picks that can't be read: the list stays
|
|
tiers := filepath.Join(settings.Dir(), "claude-desktop.tiers.json")
|
|
good, err := os.ReadFile(tiers)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
writeFile(t, tiers, `{"sonnet":`)
|
|
if err := d.Sync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if l := list(); len(l) != 3 {
|
|
t.Fatalf("unreadable picks: %v", l)
|
|
}
|
|
writeFile(t, tiers, string(good))
|
|
|
|
// nothing picked: the list goes
|
|
set("sonnet", "")
|
|
if l := list(); l != nil {
|
|
t.Fatalf("pick cleared: %v", l)
|
|
}
|
|
if _, ok := edit.GetJSONRaw(p.prof, "inferenceGatewayBaseUrl"); !ok {
|
|
t.Fatal("the rest of the profile went with the list")
|
|
}
|
|
|
|
// the user's own list is theirs, through a pick and its clearing
|
|
set("haiku", "v/b")
|
|
if err := edit.SetJSON(p.prof, edit.KV{Path: "inferenceModels", Value: []any{map[string]any{"name": "mine"}}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mine, _ := edit.GetJSONRaw(p.prof, "inferenceModels")
|
|
set("sonnet", "v/a")
|
|
set("haiku", "")
|
|
set("sonnet", "")
|
|
if now, _ := edit.GetJSONRaw(p.prof, "inferenceModels"); now != mine {
|
|
t.Fatalf("the user's list: %s, was %s", now, mine)
|
|
}
|
|
}
|