Files
plugins/packages/cursor/maxmode.test.mjs
T
geoqiao 8cd5a0fad8 cursor 0.2.0: the list is Cursor's picker, a model once per context size with that window; effort and fast are the request's (#51)
* cursor 0.2.0: the list is Cursor's picker, a model once for each context size with that window (claude-opus-5-5@300k, @1m), and effort and fast are the request's, sent as the variant's parameters

The usable list (AgentService/GetUsableModels) names a model once for each effort and speed, and the window was read off the name: 1M when it said 1M, else 200K. The names say 1M of models Cursor serves at 300K outside Max Mode ("Claude Opus 5.5 1M"), and nothing of the 300K Sonnet and Haiku or the 256K Grok have, so on this account 110 of 153 names gave a wrong window: Opus too large, Sonnet, Haiku and Grok too small, and the agents compacted at the wrong point. The request carried no context parameter either, so the window Cursor ran at was its own choice, not the one magpie reported. The same id could go to a 300K and a 1M variant.

Now the list is Cursor's model picker alone (AiService/AvailableModels, asked as the CLI asks it: useModelParameters, doNotUseMarkdown), the way pi-cursor-sdk lists Cursor's catalog. A model with a context parameter is offered once for each size, as <model>@<size> named "<name> @ <size>", its window that many tokens; one without is offered once, its window Cursor's contextTokenLimit (Max Mode's for a model served only there), 200K when Cursor gives none. Effort is not a model of its own: the model's efforts (effort / reasoning_effort / reasoning; extra-high is xhigh) are its variants, the request's reasoning_effort is fitted to the nearest and sent as that parameter, and none turns a Claude's thinking off. Fast is not one either: a service_tier of priority or fast sends fast=true, anything else fast=false, so it is paid for only when asked. A request goes as the variant those parameters pick, by the variant's legacySlug (claude-opus-5-5-medium): the agent API refuses the picker's base name with 502 "AI Model Not Found: Model name is not valid". It goes in Max Mode when that variant is Max Mode's (a 1M size; Opus 300K with fast), or, with no variant for the size, when the size is over Cursor's limit outside it; the "Max Mode Required" retry stays. Hidden, Tab-only and chat-only models stay out, as in the CLI.

The ids change (cursor/claude-opus-5-5 is cursor/claude-opus-5-5@300k; the -fast, -low and -thinking models are gone), so 0.2.0: a model picked in magpie or an agent's config has to be picked again. An id the list doesn't have goes to Cursor as it is named, with the default window. poolBase and firstParty take the @size off, so usage pools as before (grok-4.7@256k Cursor Models, claude-opus-5-5@300k Other Models).

context.test.mjs (new) covers the list, the windows, the variants and the request's parameters and mode; maxmode.test.mjs (rewritten) checks what reaches a fake agent API; usage.test.mjs adds the sized ids. HOME=$(mktemp -d) bun test: 45 pass, 0 fail; check.mjs cursor passes. Tried with a real Cursor account: claude-opus-5-5@300k goes as claude-opus-5-5-medium with context=300k and answers, grok-4.6 as cursor-grok-4.6-high, and pi -p --model magpie/cursor/claude-opus-5-5@300k answers; the base name got the 502 above.

* cursor 0.2.0: an id 0.1.x listed still runs as the variant it stood for, and a variant the account hasn't got is neither offered nor asked for (review of #51)

An id the new list doesn't have went to Cursor as it was named. The ids 0.1.11 listed are families of the variants' own ids (claude-opus-5-5, claude-opus-5-5-fast, claude-haiku-5-5-thinking, cursor-grok-4.6), and they are saved in agents' configs, magpie's picks and routing groups: request(raw, "claude-opus-5-5", "high") was {id: "claude-opus-5-5", params: [], maxMode: false}, the bare name the agent API answers 502 "AI Model Not Found" for, with the effort dropped.

Now an id the list doesn't have is read as one of Cursor's own (named): a variant's legacySlug is that variant; a family of them, taken apart as 0.1.x's splitID did, is the family's variant nearest the default, fast for a -fast family, thinking as the family says, at the effort the id names when the request names none; the picker's name for a model, one of its legacySlugs or idAliases, is its default. Each is at the variant's context size, the default's when two sizes share the id. The request's reasoning_effort and service_tier count as for a listed model. The family is tried before the picker's name, so claude-haiku-5-5 stays the Claude without thinking it was in 0.1.11 where Cursor has variants named so; where it has none it is the model's default. Anything else still goes as it is named.

The usable list (AgentService/GetUsableModels) is read again, beside the picker: a variant whose legacySlug isn't in it is dropped, the model's efforts and sizes are the ones its remaining variants have, and a request no remaining variant matches goes as the nearest of them, not as the default's id with parameters the account hasn't got. A model the usable list has nothing of is the picker's alone (GLM-5.3, as 0.1.7 found) and is kept whole; a usable list Cursor can't give leaves the picker as it is.

answerOf's comment says what pick does with no service_tier (fast off). context.test.mjs checks the PICKER_SKIP names stay out (claude-4.5-haiku, claude-haiku-4-5), each id 0.1.11's offered() gives for the fixture's slugs, variant ids and a model's legacy slug, and the usable list's filter; maxmode.test.mjs checks claude-opus-5-5 reaches the fake agent API as claude-opus-5-5-medium. On b33ec2f's index.mjs the three new context tests and that maxmode test fail. HOME=$(mktemp -d) bun test: 48 pass, 0 fail; check.mjs cursor passes. Not tried with a real Cursor account, and not read against cursor-agent's source (neither is on this machine): the old-id rules follow the review's description and 0.1.11's splitID.
2026-10-08 22:03:11 +08:00

152 lines
7.9 KiB
JavaScript

// A request goes to the agent API as the picker's model with the variant's
// parameters, in Max Mode when that variant is Max Mode's; and a model
// Cursor turns away for want of Max Mode ("Max Mode Required: The model
// "gpt-5.6-luna" requires Max Mode to be enabled", ARNO on Discord) is asked
// again in it — against a fake Cursor: its API a stand-in fetch, its agent
// API an HTTP/2 server here. Nothing reaches Cursor.
import "./nonet.mjs" // first: no request leaves this machine
import { afterAll, afterEach, beforeAll, expect, test } from "bun:test"
import http2 from "node:http2"
import { CursorAuthPlugin, _internal } from "./index.mjs"
const { fields, pb, frame, maxRequired } = _internal
const real = globalThis.fetch
afterEach(() => (globalThis.fetch = real))
const jwt = (exp) => ["e30", Buffer.from(JSON.stringify({ exp })).toString("base64url"), "sig"].join(".")
let n = 0
// a sign-in of its own, so no list kept for another is used
const fresh = () => ({ type: "oauth", access: jwt(Math.floor(Date.now() / 1000) + 7200 + 50_000 + ++n), refresh: "", expires: 0, accountId: "a@b.c" })
const en = (...vs) => ({ enumParameter: { values: vs.map((value) => ({ value })) } })
const v = (pv, o = {}) => ({ parameterValues: Object.entries(pv).map(([id, value]) => ({ id, value })), ...o })
// Cursor's picker, as AvailableModels answers it in JSON
const PICKER = [
{
name: "claude-opus-5-5", clientDisplayName: "Claude Opus 5.5", contextTokenLimit: 300000, contextTokenLimitForMaxMode: 1000000, supportsNonMaxMode: true,
parameterDefinitions: [{ id: "context", parameterType: en("300k", "1m") }, { id: "effort", parameterType: en("medium", "high") }],
variants: [v({ context: "300k", effort: "medium" }, { isDefaultNonMaxConfig: true, legacySlug: "claude-opus-5-5-medium" }), v({ context: "1m", effort: "medium" }, { isMaxMode: true, legacySlug: "claude-opus-5-5-medium" })],
},
{ name: "composer-2.5", clientDisplayName: "Composer 2.5", contextTokenLimit: 200000, supportsNonMaxMode: true, variants: [v({}, { isDefaultNonMaxConfig: true, legacySlug: "composer-2.5" })] },
// Cursor says nothing of Max Mode for it, and refuses it without
{ name: "gpt-5.6-luna", clientDisplayName: "GPT-5.6 Luna", contextTokenLimit: 272000, supportsNonMaxMode: true, parameterDefinitions: [{ id: "reasoning", parameterType: en("low", "high") }], variants: [v({ reasoning: "high" }, { isDefaultNonMaxConfig: true, legacySlug: "gpt-5.6-luna-high" })] },
]
// the agent API: each Run's model noted; one asked for without Max Mode
// that only has it is refused as Cursor refuses it
let server, base
const runs = []
const maxOnly = new Set(["gpt-5.6-luna-high"])
const str = (fs, num) => fs.find((f) => f.num === num)?.data?.toString() ?? ""
const num = (fs, k) => fs.find((f) => f.num === k)?.n ?? 0
beforeAll(async () => {
server = http2.createServer()
server.on("stream", (stream) => {
stream.respond({ ":status": 200, "content-type": "application/connect+proto" })
let buf = Buffer.alloc(0)
let answered = false
stream.on("data", (c) => {
buf = Buffer.concat([buf, c])
if (answered || buf.length < 5 || buf.length < 5 + buf.readUInt32BE(1)) return
answered = true
const rr = fields(fields(buf.subarray(5, 5 + buf.readUInt32BE(1))).find((f) => f.num === 1).data)
const details = fields(rr.find((f) => f.num === 3).data)
const requested = fields(rr.find((f) => f.num === 9).data)
const run = {
model: str(details, 1),
detailsMax: num(details, 7),
requested: str(requested, 1),
requestedMax: num(requested, 2),
params: requested.filter((f) => f.num === 3).map((f) => fields(f.data)).map((p) => [str(p, 1), str(p, 2)]),
}
runs.push(run)
const end = (body) => {
const b = Buffer.from(JSON.stringify(body))
const head = Buffer.alloc(5)
head[0] = 2
head.writeUInt32BE(b.length, 1)
stream.end(Buffer.concat([head, b]))
}
if (maxOnly.has(run.model) && !run.detailsMax) {
const detail = `The model "${run.model}" requires Max Mode to be enabled. Please enable Max Mode and try again.`
return end({ error: { code: "failed_precondition", message: "Error", details: [{ debug: { error: "ERROR_MAX_MODE_REQUIRED", details: { title: "Max Mode Required", detail } } }] } })
}
const update = (k, body) => frame(pb().bytes(1, pb().bytes(k, body)).done())
stream.write(update(1, pb().str(1, "hi").done()))
stream.write(update(14, pb().varint(1, 10).varint(2, 1).done()))
end({})
})
stream.on("error", () => {})
})
await new Promise((r) => server.listen(0, "127.0.0.1", r))
base = `http://127.0.0.1:${server.address().port}`
})
afterAll(() => server.close())
function fakeAPI() {
globalThis.fetch = async (url, init) => {
const u = String(url)
if (u === "https://api2.cursor.sh/aiserver.v1.ServerConfigService/GetServerConfig") return Response.json({ agentUrlConfig: { agentUrl: base } })
if (u === "https://api2.cursor.sh/aiserver.v1.AiService/AvailableModels") {
expect(JSON.parse(init.body)).toEqual({ useModelParameters: true, doNotUseMarkdown: true })
return Response.json({ models: PICKER })
}
throw new Error("the test asked " + u)
}
}
async function ask(auth, model, effort) {
const hooks = await CursorAuthPlugin()
const l = await hooks.auth.loader(async () => auth)
const chat = { model, messages: [{ role: "user", content: "hello" }], ...(effort ? { reasoning_effort: effort } : {}) }
const res = await l.fetch(base + "/v1/chat/completions", { method: "POST", body: JSON.stringify(chat) })
return { status: res.status, body: await res.json() }
}
test("Cursor's Max Mode refusal is recognised", () => {
expect(maxRequired('Max Mode Required: The model "gpt-5.6-luna-low" requires Max Mode to be enabled. Please enable M')).toBe(true)
expect(maxRequired("MAX_MODE_REQUIRED")).toBe(true)
expect(maxRequired("usage limit reached: slow down")).toBe(false)
})
test("a request goes as the picker's model, with the size's parameters, in Max Mode for a Max Mode size", async () => {
fakeAPI()
const auth = fresh()
runs.length = 0
let r = await ask(auth, "claude-opus-5-5@300k")
expect([r.status, r.body.error]).toEqual([200, undefined])
expect(r.body.choices[0].message.content).toBe("hi")
expect(runs).toEqual([{ model: "claude-opus-5-5-medium", detailsMax: 0, requested: "claude-opus-5-5-medium", requestedMax: 0, params: [["context", "300k"], ["effort", "medium"]] }])
runs.length = 0
r = await ask(auth, "claude-opus-5-5@1m", "medium")
expect(r.status).toBe(200)
expect(runs).toEqual([{ model: "claude-opus-5-5-medium", detailsMax: 1, requested: "claude-opus-5-5-medium", requestedMax: 1, params: [["context", "1m"], ["effort", "medium"]] }])
// an id 0.1.11 listed: the variant it stood for, not the picker's bare
// name, which Cursor answers 502 "AI Model Not Found"
runs.length = 0
r = await ask(auth, "claude-opus-5-5")
expect(r.status).toBe(200)
expect(runs).toEqual([{ model: "claude-opus-5-5-medium", detailsMax: 0, requested: "claude-opus-5-5-medium", requestedMax: 0, params: [["context", "300k"], ["effort", "medium"]] }])
runs.length = 0
r = await ask(auth, "composer-2.5")
expect(r.status).toBe(200)
expect(runs).toEqual([{ model: "composer-2.5", detailsMax: 0, requested: "composer-2.5", requestedMax: 0, params: [] }])
})
test("a model Cursor says needs Max Mode is asked again in Max Mode, and so from then on", async () => {
fakeAPI()
const auth = fresh()
runs.length = 0
let r = await ask(auth, "gpt-5.6-luna", "high")
expect([r.status, r.body.error]).toEqual([200, undefined])
expect(runs.map((x) => [x.model, x.detailsMax, x.requestedMax])).toEqual([["gpt-5.6-luna-high", 0, 0], ["gpt-5.6-luna-high", 1, 1]])
runs.length = 0
r = await ask(auth, "gpt-5.6-luna", "high")
expect(r.status).toBe(200)
expect(runs.map((x) => [x.model, x.detailsMax])).toEqual([["gpt-5.6-luna-high", 1]])
})