Files
magpie/internal/cli/visible_cli.go
T
yetone 81a24cf8fe groups: a found group is listed as auto/<model id as the vendor spells it>
ZeroClover asked on X: Auto Group ids group/auto-<slug> can't be looked
up on models.dev. A found group is now listed and written as
auto/<model>, e.g. auto/claude-opus-5.5: /v1/models, the catalog, agent
configs, the GUI's Routing page and the CLI. Context and output limits
come from the model's metadata as before.

What stays the same:
- The internal id is still group/auto-<slug> (Group.Ref() gives the
  public one). Every old form is still accepted as input forever:
  provider.CanonicalRef turns auto/<model>[:level][[1m]] into it at the
  gateway (validateModel), keys, stats, affinity and usage, so both ids
  route to the same group and count as one.
- A key's model list allows a model by either id, group/* included
  (allows() in key_models.go).
- Hand-made groups stay group/<id>.
- A provider whose stored id is "auto" keeps its models: while one
  exists, found groups are listed by their old id (AutoRefsOn) and
  auto/<x> means that provider's model. Documented in
  docs/subsystems/gateway-routing.md.

Agent configs: SyncCatalog rewrites a field that holds a found group's
old id (renameFoundGroups), but only while the value is still what
applied.json says magpie wrote; a value the user set stays. A pick by
the old id written now is written as auto/<model> (Apply). Hidden,
picked and ordered model lists saved by the old id hold for the new one
(visible.go), and a bare model id still reaches its found group (bare.go).

Claude Code is given a dotted Claude version dashed (ClaudeSpelled), so
auto/claude-sonnet-4.5 sits in its settings as auto/claude-sonnet-4-5.
That routes to the same group, but with found groups off nothing reads
it back dotted, and Reseat took the field for changed and left the agent
on a group that was gone. Reseat now compares a group pick by its
canonical id (samePick). The old ids had no dots, so this is new with
auto/<model>.

Run at this tree (sandbox HOME, caches pinned):
- gofmt -l: clean. go vet ./...: clean on darwin, GOOS=linux -tags
  nogui, GOOS=windows.
- go test -p 4 -timeout 45m ./...: every package ok except agent and
  gateway, whose failures were the tests' expected ids (updated here)
  and two regressions now fixed (bare ids; desktop models hiding groups
  by prefix). Every failing test passes on rerun. Load average was
  ~210-290 from other sessions throughout.
- Reruns: provider, cli, codexcat ok. internal/gui: only
  TestSetAnswersWhileDevinAndProvidersHang fails (set slow/slow-1 took
  10.19s), and it fails the same in a git-archive export of 33dbdcc52.
- agent and gateway in full, -p 2 -timeout 120m: gateway ok (2996s).
  agent failed four tests that still expected the old ids
  (TestOmp/PiModelsAskedOnTheirNativeAPI, TestReseatFoundGroupsOff,
  TestReseatKeepsAFoundGroupWithAProviderOff); updating them showed the
  Reseat bug above. After the fix, go test -count=1 -timeout 120m
  ./internal/agent/: ok (1000s, load ~160-220).
- GUI files the change reaches, chromium and webkit: group-found-off and
  the routing files pass, except routing-bodies, routing-model-rest,
  routing-keys-fold and routing-request-metrics, which fail the same with
  33dbdcc52's JS.

Broken by hand and watched red, then restored: CanonicalRef in
validateModel (both-ids routing test), allows() (key tests both ways),
the Save refusal and AutoRefsOn checks in Ref/CanonicalRef (provider
named auto), catalog.Lists' preference (models.dev lookup of the part
after auto/), renameFoundGroups' applied.json check and its SyncCatalog
call (user values kept), PublicRef in visible.go, the codexcat prefix,
samePick in Reseat (TestReseatFoundGroupsOff: opus left on the gone
group).
TestBareModelIDsShared was red before the bare.go fix.

Not verified: no real agent, vendor or models.dev client run; no run on
the Windows box. Settings pickers (vision, title model) holding a saved
group/auto-... value may show it as saved. codexcat can't tell a stored
"auto" provider apart, so its models lose the "text only" hint. The
pre-existing reds above are not filed.
2026-10-20 00:18:51 +08:00

186 lines
6.5 KiB
Go

package cli
import (
"fmt"
"maps"
"slices"
"strings"
"github.com/yetone/magpie/internal/agent"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// Which models each agent is shown, from the terminal: magpie visible.
const visibleUsage = `usage:
magpie visible which models each agent is shown
magpie visible <agent> <name>[,<name>…] show the agent only these: families (a tag set with
magpie provider set <id> family=relay, or magpie group set),
provider ids and group ids
magpie visible <agent> all show the agent every model again
magpie visible <agent> --only-picked show the agent only the models ticked for it now; a model
that comes later, of any provider, stays off until it is
ticked in its list on the Agents page
magpie visible <agent> --show-new show it the models that come later again (the default)
An agent not narrowed is shown every model. The gateway's model list and the model lists
magpie writes into the agents' files are narrowed alike; a model kept from an agent still
answers when the agent asks for it by name. magpie models <agent> shows what it is shown,
and why the others aren't. --only-picked and --show-new keep the models shown as they are,
and keep the providers, families and groups the agent is narrowed to.
e.g. magpie provider set opencode-go family=ocgo
magpie group set gpt-plus-auto family=relay
magpie visible zcode relay,ocgo`
// names is every name a visibility can hold: the families, and the
// providers' and groups' ids.
func visibleNames() []string {
names := provider.Families()
for _, p := range provider.All() {
names = append(names, p.ID)
}
for _, g := range provider.Groups() {
names = append(names, g.ID)
}
return names
}
func visibleCmd(args []string) error {
if len(args) > 0 && slices.Contains([]string{"help", "-h", "--help"}, args[0]) {
fmt.Println(visibleUsage)
return nil
}
s := settings.Load()
if len(args) == 0 {
if len(s.Visible) == 0 && len(s.PickedModels) == 0 {
fmt.Println(muted.Render(" every agent is shown every model · magpie visible <agent> <family>,… narrows one"))
}
ids := slices.Collect(maps.Keys(s.Visible))
for id := range s.PickedModels {
if !slices.Contains(ids, id) {
ids = append(ids, id)
}
}
slices.Sort(ids)
for _, id := range ids {
shown, hidden := provider.CatalogFor(id)
var says []string
if names, ok := s.Visible[id]; ok {
says = append(says, strings.Join(names, ", "))
}
if _, ok := s.PickedModels[id]; ok {
says = append(says, "only models picked")
}
fmt.Printf(" %s %s %s\n", pad(id, 12), strings.Join(says, " · "),
muted.Render(fmt.Sprintf("%d shown, %d not", len(shown), len(hidden))))
}
if fs := provider.Families(); len(fs) > 0 {
fmt.Println(faint.Render(" families: " + strings.Join(fs, ", ")))
}
return nil
}
a, err := agent.Find(args[0])
if err != nil {
return err
}
// VisibleTo looks the id up lowered, so the key kept here — and taken
// back out — is lowered alike, a WSL id's case and all
id := strings.ToLower(a.ID)
if len(args) == 1 {
return models([]string{id})
}
if len(args) == 2 && (args[1] == "--only-picked" || args[1] == "--show-new") {
if err := provider.SetOnlyPicked(id, args[1] == "--only-picked"); err != nil {
return err
}
fmt.Println(green.Render("✓"), "saved")
return models([]string{id})
}
list := splitList(strings.Join(args[1:], ","))
if len(list) == 1 && strings.EqualFold(list[0], "all") {
delete(s.Visible, id)
} else {
known := visibleNames()
for i, n := range list {
n = strings.TrimPrefix(provider.CanonicalRef(n), provider.GroupPrefix)
if !slices.ContainsFunc(known, func(k string) bool { return strings.EqualFold(k, n) }) {
return fmt.Errorf("%s is no family, provider or group (families: %s; magpie provider set <id> family=%s makes one)",
n, orNone(provider.Families()), n)
}
list[i] = n
}
if s.Visible == nil {
s.Visible = map[string][]string{}
}
s.Visible[id] = list
}
if err := settings.Save(s); err != nil {
return err
}
if catalog.Changed != nil {
catalog.Changed() // the agents' files follow
}
fmt.Println(green.Render("✓"), "saved")
return models([]string{id})
}
func orNone(xs []string) string {
if len(xs) == 0 {
return "none yet"
}
return strings.Join(xs, ", ")
}
// explainHidden says what is kept from an agent, and why: what the kept
// models go by, none of which its visibility names, and how many its list
// on the Agents page leaves out besides — the ones not picked, for an
// agent shown only the models picked for it.
func explainHidden(id string, hidden []provider.Entry) {
_, kept := provider.ListedFor(id)
if n := len(hidden) - len(kept); n > 0 {
if _, only := provider.PickedModels(id); only {
fmt.Println(faint.Render(" " + id + " is shown only the models picked for it: " + fmt.Sprint(n) + " not picked, and a new one stays off until it is ticked · magpie visible " + id + " --show-new shows new ones"))
} else {
fmt.Println(faint.Render(" " + fmt.Sprint(n) + " taken out of " + id + "'s list on the Agents page"))
}
} else if _, only := provider.PickedModels(id); only {
fmt.Println(faint.Render(" " + id + " is shown only the models picked for it; a new one stays off until it is ticked · magpie visible " + id + " --show-new shows new ones"))
}
hidden = kept
names, ok := provider.VisibleTo(id)
if !ok {
fmt.Println(faint.Render(" " + id + " is shown every provider's models · magpie visible " + id + " <family>,… narrows it"))
return
}
fmt.Println(faint.Render(" " + id + " is shown " + strings.Join(names, ", ")))
if len(hidden) == 0 {
return
}
by := map[string][]string{}
var order []string
for _, e := range hidden {
k := strings.Join(e.Names()[:1], "")
if e.Family == "" {
k = "no family · " + k
} else {
k = "family " + k
}
if _, seen := by[k]; !seen {
order = append(order, k)
}
by[k] = append(by[k], e.ID)
}
fmt.Println(amber.Render(" ! "+fmt.Sprint(len(hidden))) + muted.Render(" kept from "+id+", in none of those:"))
for _, k := range order {
ids := by[k]
more := ""
if len(ids) > 4 {
ids, more = ids[:4], fmt.Sprintf(" +%d", len(by[k])-4)
}
fmt.Println(muted.Render(" " + k + ": " + strings.Join(ids, ", ") + more))
}
}