Claude Desktop's Code tab runs Claude Code on ~/.claude/settings.json with every model Desktop lists. Claude Code takes one window (CLAUDE_CODE_MAX_CONTEXT_TOKENS) for every model it doesn't know, and magpie told it the least of Desktop's (#1458), so one small model held a 500K or 1M one to its 131K. Now, while Desktop is on magpie, magpie tells Claude Code the largest window of Desktop's models and of Claude Code's own main and tier models, and holds each model below it to its own with modelSettings.<id>.autoCompactWindow (claudePlan, claude_budget.go). CLAUDE_CODE_AUTO_COMPACT_WINDOW would take precedence over those, so in this mode magpie's working window goes in the top-level autoCompactWindow instead, and an entry is written only where a model's window or threshold differs from what it would run at without one. Claude models (and groups of them) are left out as before. magpie's entries and top-level value are stashed and go when Desktop leaves magpie. The user's own entries, top-level value and variables are never written over: an entry of theirs past its model's window (or "auto") holds the largest to that window, and with a CLAUDE_CODE_AUTO_COMPACT_WINDOW of theirs the least window is told as before. Desktop off is unchanged. Verified with real Claude Code 2.1.296 in a sandbox CLAUDE_CONFIG_DIR, on a settings.json written through magpie's editor: /context shows 256k for mythos-magpie-2's entry, 131k for magpie/v/gpt-6.1-sol (dotted key, with and without [1m]), and the top-level 272k for a model without an entry, under a 1M MAX_CONTEXT_TOKENS. Tests: TestClaudePlan and TestBudgetPath (new), and TestClaudeDesktopContextWindow / TestClaudeDesktopAloneContextWindow rewritten (largest window, per-model entries, Full window, the user's entry and top-level kept, Desktop off removing only magpie's). They fail on the old claude.go (256000 told), and with the skip of the user's entries removed from claudePlan. Run: go test ./internal/agent (full), gofmt -l, go vet for darwin, GOOS=linux -tags nogui and GOOS=windows.
73 lines
3.5 KiB
Go
73 lines
3.5 KiB
Go
package agent
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
// TestClaudePlan (#2025): the largest window of the models is the one
|
|
// Claude Code is told, and each model whose own differs from the one it
|
|
// would run at without an entry gets one; a "[1m]" model counts as 1M, the
|
|
// user's own entries are theirs, and one past its model's window holds the
|
|
// largest to that window.
|
|
func TestClaudePlan(t *testing.T) {
|
|
models := []claudeBudget{
|
|
{id: "mythos-magpie-1", window: 500000, compact: 272000},
|
|
{id: "mythos-magpie-2", window: 131000, compact: 272000},
|
|
{id: "anthropic/magpie-3[1m]", window: 1000000, long: true, compact: 272000},
|
|
{id: "anthropic/magpie-4", compact: -1},
|
|
{id: "magpie/v/gpt-6.1-sol", window: 400000, compact: -1},
|
|
}
|
|
top, entries := claudePlan(models, 272000, nil)
|
|
want := map[string]int{"mythos-magpie-2": 131000, "anthropic/magpie-4": 500000, "magpie/v/gpt-6.1-sol": 400000}
|
|
if top != 500000 || !reflect.DeepEqual(entries, want) {
|
|
t.Fatalf("magpie's default: %d %v", top, entries)
|
|
}
|
|
// no top-level window: every model runs at the largest, a [1m] one at 1M
|
|
top, entries = claudePlan(models, 0, nil)
|
|
want = map[string]int{"mythos-magpie-1": 272000, "mythos-magpie-2": 131000, "anthropic/magpie-3": 272000, "magpie/v/gpt-6.1-sol": 400000}
|
|
if top != 500000 || !reflect.DeepEqual(entries, want) {
|
|
t.Fatalf("no default: %d %v", top, entries)
|
|
}
|
|
// the user's own entries are theirs; "auto" on the 131K one holds the
|
|
// largest to its window
|
|
top, entries = claudePlan(models, 0, map[string]string{"mythos-magpie-2": "auto", "magpie/v/gpt-6.1-sol": "100000"})
|
|
want = map[string]int{"anthropic/magpie-3": 272000}
|
|
if top != 131000 || !reflect.DeepEqual(entries, want) {
|
|
t.Fatalf("the user's own: %d %v", top, entries)
|
|
}
|
|
// one within the model's window is kept as it is, and doesn't hold
|
|
// the largest
|
|
top, entries = claudePlan(models, 0, map[string]string{"mythos-magpie-2": "50000"})
|
|
want = map[string]int{"mythos-magpie-1": 272000, "anthropic/magpie-3": 272000, "magpie/v/gpt-6.1-sol": 400000}
|
|
if top != 500000 || !reflect.DeepEqual(entries, want) {
|
|
t.Fatalf("the user's 50000: %d %v", top, entries)
|
|
}
|
|
// the user's top-level window is the one a model without a threshold of
|
|
// its own is held to; two ids Claude Code matches as one get the
|
|
// smaller window
|
|
top, entries = claudePlan([]claudeBudget{{id: "a", window: 1000000}, {id: "b", window: 200000}, {id: "B", window: 128000}}, 300000, nil)
|
|
if top != 1000000 || !reflect.DeepEqual(entries, map[string]int{"b": 128000}) {
|
|
t.Fatalf("the user's top-level: %d %v", top, entries)
|
|
}
|
|
// only 1M ones, or no window known: nothing to tell
|
|
if top, entries = claudePlan([]claudeBudget{{id: "x[1m]", window: 1000000, long: true}, {id: "y"}}, 0, nil); top != 0 || entries != nil {
|
|
t.Fatalf("nothing known: %d %v", top, entries)
|
|
}
|
|
// an id magpie's editor can't put in a key path gets no entry
|
|
if _, entries = claudePlan([]claudeBudget{{id: "a", window: 400000}, {id: "b*", window: 100000}}, 0, nil); len(entries) != 0 {
|
|
t.Fatalf("b*: %v", entries)
|
|
}
|
|
}
|
|
|
|
// TestBudgetPath: a dot in a model's id is part of its key, as Claude Code
|
|
// reads it, and the "[1m]" mark is not.
|
|
func TestBudgetPath(t *testing.T) {
|
|
if p := budgetPath("magpie/v/gpt-6.1-sol[1m]"); p != `modelSettings.magpie/v/gpt-6\.1-sol.autoCompactWindow` {
|
|
t.Fatal(p)
|
|
}
|
|
if got := budgetsRead(`{"a.b":{"autoCompactWindow":5},"c":{"autoCompactWindow":"auto"},"d":{"effortLevel":"high"}}`); !reflect.DeepEqual(got, map[string]string{"a.b": "5", "c": "auto"}) {
|
|
t.Fatal(got)
|
|
}
|
|
}
|