diff --git a/internal/agent/workbuddy.go b/internal/agent/workbuddy.go index 7ade53207..1b8262692 100644 --- a/internal/agent/workbuddy.go +++ b/internal/agent/workbuddy.go @@ -9,6 +9,7 @@ package agent // [{"id":"deepseek/pro","name":…,"vendor":"magpie","apiKey":"magpie-workbuddy", // "url":"http://127.0.0.1:3425/v1/chat/completions", // "maxInputTokens":…,"maxOutputTokens":…, +// "contextWindow":{"supportedLengths":[200000,…],"defaultLength":…}, // "supportsToolCall":true,"supportsImages":…,"supportsReasoning":true, // "reasoning":{"supportedEfforts":[…],"canDisableThinking":…,"defaultEffort":…}}] // @@ -350,6 +351,10 @@ func buddyWriteAt(path, agent string, on bool, where place) error { return edit.WriteAtomic(path, append(b, '\n')) } +// buddySmallWindow is the smaller context WorkBuddy offers beside a +// model's whole window, the size its own models offer. +const buddySmallWindow = 200000 + // buddyModel is one of magpie's models as a models.json entry, under // agent's key. func buddyModel(agent, id, name string, context, output int, images bool, efforts []string) map[string]any { @@ -362,6 +367,13 @@ func buddyModel(agent, id, name string, context, output int, images bool, effort "maxInputTokens": context, "supportsToolCall": true, "supportsImages": images, "supportsReasoning": false, } + // WorkBuddy offers a choice of context in its model menu only for a + // model whose contextWindow lists two sizes or more (its own Opus has + // 200K and 1M); the session's budget is defaultLength, or the smallest + // size when it is missing, so it is set to the whole window as before + if context > buddySmallWindow { + e["contextWindow"] = map[string]any{"supportedLengths": []int{buddySmallWindow, context}, "defaultLength": context} + } // without it WorkBuddy caps every reply at its own default; output // comes already trimmed (zcodeOutput) unless the user set it (outputOr) if out := output; out > 0 { diff --git a/internal/agent/workbuddy_test.go b/internal/agent/workbuddy_test.go index f9547a31d..f7e5c394f 100644 --- a/internal/agent/workbuddy_test.go +++ b/internal/agent/workbuddy_test.go @@ -126,6 +126,21 @@ func TestWorkBuddyEfforts(t *testing.T) { } } +// A model with more than 200K of context gets WorkBuddy's context menu, +// set to its whole window (xiao9could on X: no context button for Opus). +func TestWorkBuddyContextChoice(t *testing.T) { + e := buddyModel("workbuddy", "claude/claude-opus-5-5", "Opus", 1000000, 128000, true, nil) + cw, _ := e["contextWindow"].(map[string]any) + if l, _ := cw["supportedLengths"].([]int); len(l) != 2 || l[0] != 200000 || l[1] != 1000000 || cw["defaultLength"] != 1000000 || e["maxInputTokens"] != 1000000 { + t.Fatalf("%v", e) + } + for _, c := range []int{0, 128000, 200000} { + if e := buddyModel("workbuddy", "x/y", "Y", c, 0, false, nil); e["contextWindow"] != nil { + t.Fatalf("%d: %v", c, e) + } + } +} + // WorkBuddy pointed at a magpie on another machine stays there through a // sync, with that magpie's key (悠悠哥 on Discord: models moved to the // magpie on a NAS were put back on this machine's), while one on this