agent: with Claude Code's own models hidden, a tier's model keeps its /model row and the switch rewrites settings.json at once (#4548)
Two gaps in the previous commit's replaceBuiltInOptions: - writePicker leaves out the row of a model a tier is on at an effort (#1616), since Claude Code shows it as that tier's row. With replaceBuiltInOptions Claude Code drops the tier rows along with its built-in lineup (2.1.316: only the Default row and the picker's own stay), so such a model was in /model nowhere. While the switch hides Claude Code's own models, every model keeps its row. - SetOwnModelsHidden saved the setting without catalog.Touched, unlike SetHiddenModels, so flipping the switch in the GUI left Claude Code's settings.json as it was until some other change re-synced it. Tests: TestClaudePickerLeavesOutATiersModelAtItsEffort gains the replace case (Terra on Haiku at max is listed); TestOwnModelsSwitchTellsTheAgents counts catalog.Changed per flip. Reviewed and run by yetone at the batch head overcac655c14(this commit, the four others from ggbdpq's #4495/#4548/#4512/#3260 patches and the #4548 follow-up), on mote: - gofmt -l clean; go vet ./... for darwin, linux (-tags nogui), windows; go build ./... for darwin and windows. - go test -tags nogui -count=1 -timeout 45m ./...: every package ok but internal/gui, with two filed reds: TestSettingsSaveKeepsWhatItDoesNotSend (#4514), red alone at origin/maincac655c14too, and TestColdTurnsTaken (#4510), red only in the full run. Rebased afterwards ontoe94fb18b8, a usage-page change that touches none of these files. - Windows (xiaomi-gpu): go test -run 'TestVSCode|TestClaudePicker' ./internal/agent ok. TestCopilotFolderFromAnIDEPluginIsNotTheCLI is red there atcac655c14too (#1827). - Broken by hand: each half reverted alone -> TestClaudePickerLeavesOutATiersModelAtItsEffort and TestOwnModelsSwitchTellsTheAgents red.
This commit is contained in:
@@ -969,8 +969,16 @@ func claudeIn(at place) *Agent {
|
||||
// ids whole, so a tier fixed at an effort (codex/gpt-6-luna:max)
|
||||
// kept its model's row as a second entry (#1616, iTanX). That row
|
||||
// is left out here; a tier at no effort Claude Code matches itself.
|
||||
// With the own-models switch on, replaceBuiltInOptions takes the
|
||||
// tier rows out of /model with the built-in lineup (Claude Code
|
||||
// keeps only the Default row and the picker's own), so a tier's
|
||||
// model keeps its row then, or it would be in /model nowhere.
|
||||
replace := provider.OwnModelsHidden("claude")
|
||||
var onTier []string
|
||||
for _, t := range claudeTiers {
|
||||
if replace {
|
||||
break
|
||||
}
|
||||
if v := env(tierEnv(t)); v != "" {
|
||||
if _, e := tierAt(v); e != "" {
|
||||
onTier = append(onTier, v)
|
||||
@@ -1013,7 +1021,7 @@ func claudeIn(at place) *Agent {
|
||||
// row stays, Claude Code keeping it as its own fallback. The flag
|
||||
// goes again with the switch on, the whole picker written either way.
|
||||
picker := map[string]any{"options": rows}
|
||||
if provider.OwnModelsHidden("claude") {
|
||||
if replace {
|
||||
picker["replaceBuiltInOptions"] = true
|
||||
}
|
||||
stash(map[string]string{pickerKey: "1"})
|
||||
|
||||
@@ -77,4 +77,15 @@ func TestClaudePickerLeavesOutATiersModelAtItsEffort(t *testing.T) {
|
||||
if got := listed(); !slices.Contains(got, "cx/gpt-6-luna") || slices.Contains(got, "cx/gpt-6-terra") {
|
||||
t.Fatalf("picker %v: want Luna listed again and Terra, now on Haiku at max, left out", got)
|
||||
}
|
||||
// with Claude Code's own models hidden the picker says
|
||||
// replaceBuiltInOptions, which takes the tier rows out of /model too
|
||||
// (#4548): Terra, on Haiku at max, keeps its row then, or it would be
|
||||
// in /model nowhere
|
||||
if err := provider.SetOwnModelsHidden("claude", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
set("model", "cx/gpt-6.1-sol")
|
||||
if got := listed(); !slices.Contains(got, "cx/gpt-6-terra") || !slices.Contains(got, "cx/gpt-6-luna") {
|
||||
t.Fatalf("picker %v with the built-in rows replaced: want Terra, on Haiku at max, listed beside Luna", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,3 +110,32 @@ func TestSetCompactAt(t *testing.T) {
|
||||
t.Errorf("full window: %d", s.Compact())
|
||||
}
|
||||
}
|
||||
|
||||
// The own-models switch reaches an agent's own config too (Claude Code's
|
||||
// modelPicker says replaceBuiltInOptions, #4548), so flipping it tells the
|
||||
// agents, as a hidden model's change does; a flip to where it already is
|
||||
// tells them nothing.
|
||||
func TestOwnModelsSwitchTellsTheAgents(t *testing.T) {
|
||||
limitsHome(t)
|
||||
told := 0
|
||||
catalog.Changed = func() { told++ }
|
||||
t.Cleanup(func() { catalog.Changed = nil })
|
||||
if err := SetOwnModelsHidden("claude", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if told != 1 || !OwnModelsHidden("claude") {
|
||||
t.Fatalf("hidden: told %d times, hidden=%v; want once, true", told, OwnModelsHidden("claude"))
|
||||
}
|
||||
if err := SetOwnModelsHidden("claude", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if told != 1 {
|
||||
t.Fatalf("told %d times for a flip that changed nothing; want once in all", told)
|
||||
}
|
||||
if err := SetOwnModelsHidden("claude", false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if told != 2 || OwnModelsHidden("claude") {
|
||||
t.Fatalf("shown: told %d times, hidden=%v; want twice, false", told, OwnModelsHidden("claude"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,7 +294,14 @@ func SetOwnModelsHidden(agent string, on bool) error {
|
||||
} else {
|
||||
s.OwnModelsHidden = slices.DeleteFunc(s.OwnModelsHidden, func(a string) bool { return a == agent })
|
||||
}
|
||||
return settings.Save(s)
|
||||
if err := settings.Save(s); err != nil {
|
||||
return err
|
||||
}
|
||||
// an agent's own config says the switch too (Claude Code's modelPicker
|
||||
// replaceBuiltInOptions, #4548), so it is written again now, as a
|
||||
// hidden model's change is
|
||||
catalog.Touched()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Families are the families providers and groups are tagged with, sorted.
|
||||
|
||||
Reference in New Issue
Block a user