Files
magpie/internal/agent/claudedesktop_models.go
T
yetone ae060550b9 claude-desktop: a tier's pick runs with its tier's Claude prompt (behavesAs)
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.
2026-11-03 09:33:25 +08:00

85 lines
2.6 KiB
Go

package agent
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"slices"
"strings"
"github.com/yetone/magpie/internal/edit"
"github.com/yetone/magpie/internal/gateway"
)
// While a model is picked for one of Claude Desktop's tiers, magpie's
// profile carries inferenceModels (gateway.DesktopInferenceModels): the
// list Desktop's Code tab hands Claude Code each pick's behavesAs from,
// so a pick runs with the prompt of the Claude model of its tier
// (moer2831). Without a pick there is none, and Desktop finds magpie's
// models on its own as before. The list is magpie's only while it is what
// magpie wrote: desktopModelsMark keeps the hash of each list magpie
// wrote (the one before a write too, until the write is done), and a list
// with any other hash is the user's, which magpie never writes over or
// takes away. Desktop reads its profile at start-up only.
const desktopModelsMark = "claude-desktop.models"
// desktopModelsHash is a list's hash, the same however it is spaced.
func desktopModelsHash(raw []byte) string {
var v any
if json.Unmarshal(raw, &v) != nil {
return ""
}
b, _ := json.Marshal(v)
sum := sha256.Sum256(b)
return hex.EncodeToString(sum[:])
}
// desktopSyncModels writes p's inferenceModels as magpie lists them now,
// takes away the one magpie wrote when nothing is picked, and leaves the
// user's own alone.
func desktopSyncModels(p desktopPaths) error {
if !desktopWired(p) {
return nil
}
want, ok := gateway.DesktopInferenceModels()
if !ok {
return nil // the picks unknown: what is there stays
}
key := desktopModelsMark + p.key
marks := strings.Fields(stashShared()[key])
b, err := edit.Read(p.prof)
if err != nil || b == nil {
return err // no profile: desktopOn writes one, then this
}
raw, has := edit.GetJSONRaw(p.prof, "inferenceModels")
if has && !slices.Contains(marks, desktopModelsHash([]byte(raw))) {
return nil // the user's
}
if want == nil {
if has {
if err := edit.DelJSON(p.prof, "inferenceModels"); err != nil {
return err
}
}
forget(key)
return nil
}
next, err := json.Marshal(want)
if err != nil {
return err
}
h := desktopModelsHash(next)
if has && desktopModelsHash([]byte(raw)) == h {
stash(map[string]string{key: h})
return nil
}
// marked before it is written: a write cut short leaves a list magpie
// still knows for its own
stash(map[string]string{key: strings.Join(append(marks, h), " ")})
if err := edit.SetJSON(p.prof, edit.KV{Path: "inferenceModels", Value: json.RawMessage(next)}); err != nil {
return err
}
stash(map[string]string{key: h})
return nil
}