cursor: its models have a context window — 1M for the ones Cursor names 1M, else 200K (less where the model's own is smaller), so Codex, Pi, OpenCode, Crush and the rest no longer take them for a small or unknown window; and Claude Code is given a 1M model as <id>[1m], its mark for one, so it no longer compacts at 200K (it drops the mark before asking, and magpie takes a value with it too). Asked on X

This commit is contained in:
yetone
2026-09-26 17:49:06 +08:00
parent 7b69b22a76
commit f0bd9fac87
4 changed files with 99 additions and 4 deletions
+19 -2
View File
@@ -146,7 +146,7 @@ func claude(home string) *Agent {
// Only the catalog's models; Claude Code's own short aliases are
// not something any API lists, and a compiled-in copy would just
// go stale.
return append(group(name, own), viaMagpie("claude", "")...)
return append(group(name, own), claudeViaMagpie()...)
},
}}
for _, tier := range claudeTiers {
@@ -187,7 +187,7 @@ func claude(home string) *Agent {
if !routed() {
return nil
}
return viaMagpie("claude", "")
return claudeViaMagpie()
},
})
}
@@ -215,6 +215,23 @@ func claude(home string) *Agent {
}
}
// claudeViaMagpie is what magpie serves Claude Code, a model with a window
// of 1M or more marked [1m]: Claude Code takes any other for 200K, and
// compacts long before a 1M model needs it. It drops the mark before asking.
func claudeViaMagpie() []Option {
big := map[string]bool{}
for _, m := range magpieModels("claude") {
big[m.ID] = m.Context >= 1_000_000
}
opts := viaMagpie("claude", "")
for i, o := range opts {
if big[o.Ref] {
opts[i].Value += "[1m]"
}
}
return opts
}
// claudeManaged is where an administrator's Claude Code settings live; a var
// so tests can point it elsewhere.
var claudeManaged = func() string {
+53 -1
View File
@@ -14,6 +14,8 @@ import (
"os/exec"
"path/filepath"
"regexp"
"slices"
"strconv"
"strings"
"sync"
"time"
@@ -145,11 +147,61 @@ func parseCursorModels(out string) []catalog.Model {
}
name := strings.TrimSpace(strings.TrimSuffix(strings.TrimSpace(m[2]), "(default)"))
name = strings.TrimSpace(strings.TrimSuffix(name, "(current)"))
ms = append(ms, catalog.Model{ID: m[1], Name: name})
ms = append(ms, catalog.Model{ID: m[1], Name: name, Context: cursorContext(m[1], name)})
}
return ms
}
// cursorDefaultContext is the context Cursor gives a model it doesn't name
// as a 1M one.
const cursorDefaultContext = 200_000
var (
cursorMillion = regexp.MustCompile(`\b(\d+)M\b`)
cursorVariant = regexp.MustCompile(`-(fast|none|low|medium|high|xhigh|extra-high|max|thinking)$`)
)
// cursorContext is how much of a conversation Cursor lets a model hold. Its
// ids ("claude-opus-5-5-high-fast") are its own, so no catalog knows them,
// and an agent given none took every Cursor model for its own default: a
// 1M one compacted at a fifth of it, and a 200K one — Cursor's own, where
// the name doesn't say 1M — was sent more than Cursor keeps. The name says
// which is which ("Claude Opus 5.5 1M"); under it, a model known to hold
// less keeps its own.
func cursorContext(id, name string) int {
if m := cursorMillion.FindStringSubmatch(name); m != nil {
n, _ := strconv.Atoi(m[1])
return n * 1_000_000
}
base := strings.TrimPrefix(id, "cursor-")
for {
b := cursorVariant.ReplaceAllString(base, "")
if b == base {
break
}
base = b
}
if base == "auto" { // Cursor's pick, not a model of that name
return cursorDefaultContext
}
if n := catalog.ContextOf(base); n > 0 && n < cursorDefaultContext {
return n
}
return cursorDefaultContext
}
// withCursorContexts fills in a saved list's contexts, fetched before
// magpie kept them.
func withCursorContexts(ms []catalog.Model) []catalog.Model {
out := slices.Clone(ms)
for i, m := range out {
if m.Context == 0 {
out[i].Context = cursorContext(m.ID, m.Name)
}
}
return out
}
var cursorLoginURL = regexp.MustCompile(`https://\S+`)
// startCursorSignIn runs `cursor-agent login` without its browser, hands its
+21
View File
@@ -15,3 +15,24 @@ func TestParseCursorModels(t *testing.T) {
}
}
}
// Cursor's names say which of its models hold 1M; the rest hold its 200K
func TestCursorContext(t *testing.T) {
for _, c := range []struct {
id, name string
want int
}{
{"claude-opus-5-5-high-fast", "Claude Opus 5.5 1M High Fast", 1_000_000},
{"gpt-5.6-sol-xhigh", "GPT-5.6 Sol 1M Extra High", 1_000_000},
{"gpt-5.5-medium-fast", "GPT-5.5 Fast", 200_000},
{"composer-2.5", "Composer 2.5", 200_000},
{"auto", "Auto", 200_000},
} {
if got := cursorContext(c.id, c.name); got != c.want {
t.Errorf("%s (%s): %d, want %d", c.id, c.name, got, c.want)
}
}
if ms := withCursorContexts(parseCursorModels("x-1 - X 1M\n")); ms[0].Context != 1_000_000 {
t.Fatalf("%+v", ms)
}
}
+6 -1
View File
@@ -36,6 +36,9 @@ func (p Provider) Available() []catalog.Model {
}
}
if live, _, ok := catalog.Live(p.ID); ok {
if p.ID == "cursor" {
live = withCursorContexts(live)
}
return catalog.Decorate(live, known)
}
if signedIn {
@@ -380,7 +383,9 @@ func providerEntries() []Entry {
// and the bare model id when exactly one provider serves it.
// A group's id resolves to its first member.
func Resolve(id string) (Provider, string, bool) {
id = strings.TrimSpace(id)
// Claude Code's mark for a model with a 1M window; it drops it before
// asking, but a value in its settings still has it
id = strings.TrimSuffix(strings.TrimSpace(id), "[1m]")
if strings.HasPrefix(id, GroupPrefix) {
for _, e := range Catalog() {
if e.ID == id {