Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy
Rust
add cursor catalog and proxy login
Raine Virtac9446ad87ec5
diff --git a/README.md b/README.mdindex a76de8b..941d13b 100644--- a/README.md+++ b/README.md@@ -71,14 +71,13 @@ it in any browser, confirm the code, and the CLI polls until done.**Cursor Agent:**```sh-cursor-agent login+claude-code-proxy cursor auth loginclaude-code-proxy cursor auth status```-Cursor authentication is managed by Cursor Agent. The proxy discovers the same-stored credentials (`cursor-access-token` on macOS Keychain, or Cursor's-`auth.json` on other platforms). You can also set `CCP_CURSOR_AUTH_TOKEN` for-the proxy process.+Cursor authentication uses Cursor's browser login, but the proxy stores its own+tokens. It does not read Cursor Agent's Keychain/auth.json. You can also set+`CCP_CURSOR_AUTH_TOKEN` for the proxy process.On macOS credentials go to Keychain. On Windows they are written under`%APPDATA%\claude-code-proxy\<provider>\auth.json`; on Linux they are written@@ -109,7 +108,7 @@ upstream for each request is chosen from `ANTHROPIC_MODEL`.- `gpt-5.5`, `gpt-5.4`, `gpt-5.3-codex`, `gpt-5.3-codex-spark`, `gpt-5.4-mini`, `gpt-5.2` → **codex**- `kimi-for-coding`, `kimi-k2.6`, `k2.6` → **kimi**-- `cursor`, `cursor-plan`, `cursor-ask`, `composer-2.5-fast`, `cursor:<raw-model>` → **cursor**+- `cursor`, `cursor-plan`, `cursor-ask`, `composer-2.5-fast`, `cursor:<model-id>`, `cursor-plan:<model-id>`, `cursor-ask:<model-id>` → **cursor**An unknown model returns a 400 listing the supported ids. There is noimplicit default provider.@@ -329,8 +328,16 @@ Supported proxy model ids:- `cursor-plan` — same model with Cursor `AGENT_MODE_PLAN`- `cursor-ask` — same model with Cursor `AGENT_MODE_ASK`- `composer-2.5`, `composer-2.5-fast`-- `cursor:<raw-model>` — send a raw Cursor model id, with a trailing `-fast`- converted into Cursor's `fast=true` model parameter+- `cursor:<model-id>` — force any Cursor Agent model id through Cursor+- `cursor-plan:<model-id>` — same model with Cursor `AGENT_MODE_PLAN`+- `cursor-ask:<model-id>` — same model with Cursor `AGENT_MODE_ASK`++The prefixed forms are the recommended way to select Cursor's full model+catalog. They avoid collisions with other proxy providers, for example+`gpt-5.2` can remain a Codex model while `cursor:gpt-5.2` forces Cursor.+The catalog advertised by `/v1/models` is generated from+`cursor-agent --list-models`; unknown future ids are still accepted with+`cursor:<raw-model>`.Plan mode can also be selected per request with metadata:@@ -352,9 +359,9 @@ Auth:| Command | What it does || -------------------- | ------------------------------------------------------------------- |-| `cursor auth login` | Prints the required `cursor-agent login` command |-| `cursor auth status` | Shows discovered Cursor credential source and token expiry |-| `cursor auth logout` | Clears discovered Cursor credentials from Cursor's local auth store |+| `cursor auth login` | Browser login and proxy-owned Cursor token storage |+| `cursor auth status` | Shows proxy-owned Cursor credential source and token expiry |+| `cursor auth logout` | Clears proxy-owned Cursor credentials |## How it works@@ -389,7 +396,7 @@ sequenceDiagram| [`serve`](#serve) | Start the proxy on `PORT` || `codex auth login` / `device` / `status` / `logout` | Codex OAuth management || `kimi auth login` / `status` / `logout` | Kimi OAuth management |-| `cursor auth login` / `status` / `logout` | Cursor credential status |+| `cursor auth login` / `status` / `logout` | Cursor OAuth management |---@@ -521,15 +528,13 @@ Removes stored auth credentials (Keychain entry on macOS, file elsewhere). Run#### `cursor auth login`-Cursor login is handled by Cursor Agent itself:-```sh-cursor-agent login+claude-code-proxy cursor auth login```-The proxy command prints that setup instruction and exits. This avoids using-`cursor-agent` as a request upstream while still matching Cursor Agent's-credential storage.+Starts Cursor's browser login flow, polls `api2.cursor.sh/auth/poll`, and+stores the resulting Cursor access/refresh tokens in the proxy's own auth+store. The proxy does not read or write Cursor Agent's Keychain/auth.json.#### `cursor auth status`@@ -547,7 +552,7 @@ claude-code-proxy cursor auth logout```Clears Cursor credentials from the discovered local auth store. Run-`cursor-agent login` again to re-authenticate.+`claude-code-proxy cursor auth login` again to re-authenticate.---@@ -625,7 +630,7 @@ Windows, and at| `CCP_CURSOR_BASE_URL` | `cursor.baseUrl` | `https://api2.cursor.sh` | Override Cursor's API base URL || `CCP_CURSOR_CLIENT_VERSION` | `cursor.clientVersion` | `cli-2026.06.04-5fd875e` | Override Cursor client version headers || `CCP_CURSOR_AGENT_BUNDLE` | `cursor.agentBundle` | auto-detected | Path to Cursor Agent's bundled `index.js` used only for protobuf schemas |-| `CCP_CURSOR_AUTH_TOKEN` | — | unset | Use this Cursor bearer token instead of local Cursor Agent credential storage |+| `CCP_CURSOR_AUTH_TOKEN` | — | unset | Use this Cursor bearer token instead of local claude-code-proxy Cursor auth storage || `CCP_ORIGINATOR` | — | `claude-code-proxy` | Fallback for `CCP_CODEX_ORIGINATOR` || `CCP_USER_AGENT` | — | unset | Fallback for `CCP_CODEX_USER_AGENT` and `CCP_KIMI_USER_AGENT` |@@ -679,12 +684,11 @@ sticky sessions or shared state before enabling continuation.`${XDG_CONFIG_HOME:-$HOME/.config}/claude-code-proxy/kimi/device_id`; Windowsuses `%APPDATA%\claude-code-proxy\kimi\device_id`. Reused for the lifetimeof the install.-- Cursor tokens — discovered from Cursor Agent's auth store, not stored under- `claude-code-proxy`. On macOS the provider reads Keychain account- `cursor-user` with services `cursor-access-token`, `cursor-refresh-token`,- and `cursor-api-key`. On Linux it reads- `${XDG_CONFIG_HOME:-$HOME/.config}/cursor/auth.json`; on Windows it reads- `%APPDATA%\Cursor\auth.json`. `CCP_CURSOR_AUTH_TOKEN` overrides discovery.+- Cursor tokens — macOS uses Keychain under service+ `claude-code-proxy.cursor`. Linux uses+ `${XDG_CONFIG_HOME:-$HOME/.config}/claude-code-proxy/cursor/auth.json`.+ Windows uses `%APPDATA%\claude-code-proxy\cursor\auth.json`.+ `CCP_CURSOR_AUTH_TOKEN` overrides local proxy-owned storage.## Limitationsdiff --git a/src/paths.test.ts b/src/paths.test.tsindex 30ca864..038d5f6 100644--- a/src/paths.test.ts+++ b/src/paths.test.ts@@ -1,6 +1,7 @@import { describe, expect, it } from "bun:test";import {codexAuthFile,+ cursorAuthFile,kimiAuthFile,kimiDeviceIdFile,legacyConfigDir,@@ -97,6 +98,9 @@ describe("provider paths", () => {expect(kimiAuthFile(deps)).toBe("C:\\Users\\u\\AppData\\Roaming\\claude-code-proxy\\kimi\\auth.json",);+ expect(cursorAuthFile(deps)).toBe(+ "C:\\Users\\u\\AppData\\Roaming\\claude-code-proxy\\cursor\\auth.json",+ );expect(kimiDeviceIdFile(deps)).toBe("C:\\Users\\u\\AppData\\Roaming\\claude-code-proxy\\kimi\\device_id",);diff --git a/src/paths.ts b/src/paths.tsindex d06515d..a3791f6 100644--- a/src/paths.ts+++ b/src/paths.ts@@ -65,6 +65,10 @@ export function kimiAuthFile(deps: DirResolverEnv = defaults()): string {return pathFor(deps.platform).join(resolveConfigDir(deps), "kimi", "auth.json");}+export function cursorAuthFile(deps: DirResolverEnv = defaults()): string {+ return pathFor(deps.platform).join(resolveConfigDir(deps), "cursor", "auth.json");+}+export function kimiDeviceIdFile(deps: DirResolverEnv = defaults()): string {return pathFor(deps.platform).join(resolveConfigDir(deps), "kimi", "device_id");}diff --git a/src/providers/cursor/auth/login.ts b/src/providers/cursor/auth/login.tsnew file mode 100644index 0000000..3abc043--- /dev/null+++ b/src/providers/cursor/auth/login.ts@@ -0,0 +1,112 @@+import { createHash, randomBytes, randomUUID } from "node:crypto";+import { execFile } from "node:child_process";+import { platform } from "node:os";+import { promisify } from "node:util";+import { cursorBaseUrl } from "../../../config.ts";+import { saveCursorAuth, type CursorAuth } from "./token-store.ts";++const execFileAsync = promisify(execFile);+const CURSOR_WEBSITE_URL = "https://cursor.com";++interface LoginMetadata {+ uuid: string;+ verifier: string;+}++interface CursorLoginResult {+ accessToken: string;+ refreshToken: string;+}++function base64Url(bytes: Buffer): string {+ return bytes.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");+}++function sleep(ms: number): Promise<void> {+ return new Promise((resolve) => setTimeout(resolve, ms));+}++export function createCursorLogin(): { loginUrl: string; metadata: LoginMetadata } {+ const verifier = base64Url(randomBytes(32));+ const challenge = base64Url(createHash("sha256").update(verifier).digest());+ const uuid = randomUUID();+ const loginUrl = `${CURSOR_WEBSITE_URL}/loginDeepControl?challenge=${challenge}&uuid=${uuid}&mode=login&redirectTarget=cli`;+ return { loginUrl, metadata: { uuid, verifier } };+}++export async function openCursorLoginUrl(url: string): Promise<void> {+ if (platform() === "darwin") {+ await execFileAsync("open", [url]);+ return;+ }+ if (platform() === "win32") {+ await execFileAsync("cmd", ["/c", "start", "", url]);+ return;+ }+ await execFileAsync("xdg-open", [url]);+}++export async function waitForCursorLogin(+ metadata: LoginMetadata,+ opts: { maxAttempts?: number; onProgress?: (attempt: number) => void } = {},+): Promise<CursorLoginResult | undefined> {+ const maxAttempts = opts.maxAttempts ?? 150;+ let consecutiveErrors = 0;+ for (let attempt = 0; attempt < maxAttempts; attempt++) {+ const delay = Math.min(1000 * Math.pow(1.2, attempt), 10_000);+ try {+ const base = cursorBaseUrl().replace(/\/$/, "");+ const resp = await fetch(`${base}/auth/poll?uuid=${metadata.uuid}&verifier=${metadata.verifier}`, {+ headers: { "content-type": "application/json" },+ });+ if (resp.status === 404) {+ consecutiveErrors = 0;+ opts.onProgress?.(attempt);+ await sleep(delay);+ continue;+ }+ if (!resp.ok) {+ consecutiveErrors += 1;+ if (consecutiveErrors >= 3) return undefined;+ await sleep(delay);+ continue;+ }+ const parsed = await resp.json();+ if (parsed && typeof parsed === "object") {+ const obj = parsed as Record<string, unknown>;+ if (typeof obj.accessToken === "string" && typeof obj.refreshToken === "string") {+ return { accessToken: obj.accessToken, refreshToken: obj.refreshToken };+ }+ }+ return undefined;+ } catch {+ consecutiveErrors += 1;+ if (consecutiveErrors >= 3) return undefined;+ await sleep(delay);+ }+ }+ return undefined;+}++export async function runCursorLogin(): Promise<CursorAuth | undefined> {+ const login = createCursorLogin();+ console.log("Open this URL to authenticate with Cursor:");+ console.log(login.loginUrl);+ console.log();+ try {+ await openCursorLoginUrl(login.loginUrl);+ } catch (err) {+ console.log(`Could not open browser automatically: ${String(err)}`);+ }+ console.log("Waiting for Cursor login...");+ const result = await waitForCursorLogin(login.metadata, {+ onProgress(attempt) {+ if (attempt > 0 && attempt % 10 === 0) process.stdout.write(".");+ },+ });+ if (!result) return undefined;+ return saveCursorAuth({+ accessToken: result.accessToken,+ refreshToken: result.refreshToken,+ });+}diff --git a/src/providers/cursor/auth/token-store.ts b/src/providers/cursor/auth/token-store.tsindex c56036f..317060c 100644--- a/src/providers/cursor/auth/token-store.ts+++ b/src/providers/cursor/auth/token-store.ts@@ -1,7 +1,8 @@-import { readFile, unlink } from "node:fs/promises";-import { homedir } from "node:os";-import { join } from "node:path";-import { keychainGet, keychainDelete } from "../../../keychain.ts";+import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";+import { dirname, join } from "node:path";+import { cursorBaseUrl } from "../../../config.ts";+import { keychainDelete, keychainGet, keychainSet } from "../../../keychain.ts";+import { cursorAuthFile, legacyConfigDir } from "../../../paths.ts";import { parseJwtClaims, tokenExpiryMs } from "./jwt.ts";export interface CursorAuth {@@ -20,32 +21,27 @@ interface CursorAuthFile {apiKey?: string;}-const CURSOR_KEYCHAIN_ACCOUNT = "cursor-user";-const ACCESS_TOKEN_SERVICE = "cursor-access-token";-const REFRESH_TOKEN_SERVICE = "cursor-refresh-token";-const API_KEY_SERVICE = "cursor-api-key";+const KEYCHAIN_SERVICE = "claude-code-proxy.cursor";+const KEYCHAIN_ACCOUNT = "auth";+const REFRESH_EXPIRY_SKEW_MS = 60_000;export async function loadCursorAuth(env: NodeJS.ProcessEnv = process.env): Promise<CursorAuth | undefined> {const envToken = env.CCP_CURSOR_AUTH_TOKEN || env.CURSOR_AUTH_TOKEN;if (envToken) return authFromToken(envToken, "environment");if (process.platform === "darwin") {- const accessToken = keychainGet(ACCESS_TOKEN_SERVICE, CURSOR_KEYCHAIN_ACCOUNT);- if (accessToken) {- return enrich({- accessToken,- refreshToken: keychainGet(REFRESH_TOKEN_SERVICE, CURSOR_KEYCHAIN_ACCOUNT),- apiKey: keychainGet(API_KEY_SERVICE, CURSOR_KEYCHAIN_ACCOUNT),- source: "macOS Keychain",- });- }+ const raw = keychainGet(KEYCHAIN_SERVICE, KEYCHAIN_ACCOUNT);+ if (!raw) return undefined;+ const parsed = JSON.parse(raw) as CursorAuthFile;+ if (!parsed.accessToken) return undefined;+ return refreshIfNeeded(enrich({ ...parsed, accessToken: parsed.accessToken, source: cursorAuthLocation() }));}- for (const path of cursorAuthFileCandidates(env)) {+ for (const path of authFileCandidates()) {try {const raw = await readFile(path, "utf8");const parsed = JSON.parse(raw) as CursorAuthFile;- if (parsed.accessToken) return enrich({ ...parsed, accessToken: parsed.accessToken, source: path });+ if (parsed.accessToken) return refreshIfNeeded(enrich({ ...parsed, accessToken: parsed.accessToken, source: path }));} catch (err: any) {if (err?.code !== "ENOENT") throw err;}@@ -56,13 +52,11 @@ export async function loadCursorAuth(env: NodeJS.ProcessEnv = process.env): Promexport async function clearCursorAuth(): Promise<void> {if (process.platform === "darwin") {- keychainDelete(ACCESS_TOKEN_SERVICE, CURSOR_KEYCHAIN_ACCOUNT);- keychainDelete(REFRESH_TOKEN_SERVICE, CURSOR_KEYCHAIN_ACCOUNT);- keychainDelete(API_KEY_SERVICE, CURSOR_KEYCHAIN_ACCOUNT);+ keychainDelete(KEYCHAIN_SERVICE, KEYCHAIN_ACCOUNT);return;}- for (const path of cursorAuthFileCandidates(process.env)) {+ for (const path of authFileCandidates()) {try {await unlink(path);} catch (err: any) {@@ -71,21 +65,36 @@ export async function clearCursorAuth(): Promise<void> {}}+export async function saveCursorAuth(auth: CursorAuthFile): Promise<CursorAuth> {+ if (!auth.accessToken) throw new Error("Cursor auth accessToken is required");+ if (process.platform === "darwin") {+ keychainSet(KEYCHAIN_SERVICE, KEYCHAIN_ACCOUNT, JSON.stringify(auth));+ return enrich({ ...auth, accessToken: auth.accessToken, source: cursorAuthLocation() });+ }++ const path = cursorAuthFile();+ await mkdir(dirname(path), { recursive: true, mode: 0o700 });+ const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;+ await writeFile(tmp, JSON.stringify(auth, null, 2), { encoding: "utf8", mode: 0o600 });+ await rename(tmp, path);+ return enrich({ ...auth, accessToken: auth.accessToken, source: path });+}+export function cursorAuthLocation(): string {- return process.platform === "darwin" ? "Cursor macOS Keychain" : cursorAuthFileCandidates(process.env)[0]!;+ return process.platform === "darwin" ? "macOS Keychain (claude-code-proxy.cursor)" : cursorAuthFile();}export function missingAuthMessage(): string {return ["Cursor authentication was not found.",- "Run `cursor-agent login` once, or set CCP_CURSOR_AUTH_TOKEN/CURSOR_AUTH_TOKEN.",- "On macOS the provider reads Keychain services cursor-access-token, cursor-refresh-token, and cursor-api-key for account cursor-user.",+ "Run `claude-code-proxy cursor auth login`, or set CCP_CURSOR_AUTH_TOKEN/CURSOR_AUTH_TOKEN.",+ "The proxy stores Cursor credentials in its own claude-code-proxy.cursor storage, not Cursor Agent's Keychain/auth.json.",].join(" ");}export function expiredAuthMessage(auth: CursorAuth): string {const expires = auth.expires ? new Date(auth.expires).toISOString() : "unknown";- return `Cursor access token from ${auth.source} is expired or near expiry (${expires}). Run \`cursor-agent login\` again or set CCP_CURSOR_AUTH_TOKEN.`;+ return `Cursor access token from ${auth.source} is expired or near expiry (${expires}). Run \`claude-code-proxy cursor auth login\` again or set CCP_CURSOR_AUTH_TOKEN.`;}function authFromToken(accessToken: string, source: string): CursorAuth {@@ -102,14 +111,41 @@ function enrich(auth: Omit<CursorAuth, "expires" | "userId" | "email"> & Partial};}-function cursorAuthFileCandidates(env: NodeJS.ProcessEnv): string[] {- if (process.platform === "win32") {- const appData = env.APPDATA || join(homedir(), "AppData", "Roaming");- return [join(appData, "Cursor", "auth.json")];+async function refreshIfNeeded(auth: CursorAuth): Promise<CursorAuth> {+ if (!auth.refreshToken || !auth.expires || auth.expires > Date.now() + REFRESH_EXPIRY_SKEW_MS) {+ return auth;}- if (process.platform === "darwin") {- return [join(homedir(), ".cursor", "auth.json")];+ const refreshed = await refreshCursorAuth(auth.refreshToken);+ if (!refreshed) return auth;+ return saveCursorAuth({+ accessToken: refreshed.accessToken,+ refreshToken: refreshed.refreshToken,+ apiKey: auth.apiKey,+ });+}++async function refreshCursorAuth(refreshToken: string): Promise<{ accessToken: string; refreshToken: string } | undefined> {+ const resp = await fetch(`${cursorBaseUrl().replace(/\/$/, "")}/auth/refresh`, {+ method: "POST",+ headers: {+ "content-type": "application/json",+ authorization: `Bearer ${refreshToken}`,+ },+ body: JSON.stringify({}),+ });+ if (!resp.ok) return undefined;+ const parsed = await resp.json();+ if (parsed && typeof parsed === "object") {+ const obj = parsed as Record<string, unknown>;+ if (typeof obj.accessToken === "string" && typeof obj.refreshToken === "string") {+ return { accessToken: obj.accessToken, refreshToken: obj.refreshToken };+ }}- const configHome = env.XDG_CONFIG_HOME || join(homedir(), ".config");- return [join(configHome, "cursor", "auth.json")];+ return undefined;+}++function authFileCandidates(): string[] {+ const primary = cursorAuthFile();+ const legacy = join(legacyConfigDir(), "cursor", "auth.json");+ return legacy === primary ? [primary] : [primary, legacy];}diff --git a/src/providers/cursor/index.ts b/src/providers/cursor/index.tsindex f8c5db7..cd8dd3a 100644--- a/src/providers/cursor/index.ts+++ b/src/providers/cursor/index.ts@@ -15,6 +15,7 @@ import {missingAuthMessage,clearCursorAuth,} from "./auth/token-store.ts";+import { runCursorLogin } from "./auth/login.ts";import { renderCursorPrompt } from "./translate/request.ts";import { CURSOR_SUPPORTED_MODELS, resolveCursorModel } from "./translate/model.ts";import {@@ -153,9 +154,16 @@ async function handleMessages(const cli: CliHandlers = {async login() {- console.log("Cursor login is managed by Cursor Agent.");- console.log("Run: cursor-agent login");- console.log("Or set CCP_CURSOR_AUTH_TOKEN/CURSOR_AUTH_TOKEN for this proxy.");+ const auth = await runCursorLogin();+ if (!auth) {+ console.error("Cursor login did not complete.");+ process.exit(1);+ }+ console.log();+ console.log(`Logged in. Storage: ${auth.source}`);+ if (auth.email) console.log(`Email: ${auth.email}`);+ if (auth.userId) console.log(`User: ${auth.userId}`);+ if (auth.expires) console.log(`Expires: ${new Date(auth.expires).toISOString()}`);},async status() {const auth = await loadCursorAuth();diff --git a/src/providers/cursor/translate/catalog.ts b/src/providers/cursor/translate/catalog.tsnew file mode 100644index 0000000..8e9ec9b--- /dev/null+++ b/src/providers/cursor/translate/catalog.ts@@ -0,0 +1,136 @@+// Generated from `cursor-agent --list-models` on 2026-06-07.+// Cursor models are account-gated and change over time; the resolver also+// accepts cursor:<raw-model> for ids that are not in this snapshot.+export const CURSOR_AGENT_MODEL_IDS = [+ "auto",+ "gpt-5.3-codex-low",+ "gpt-5.3-codex-low-fast",+ "gpt-5.3-codex",+ "gpt-5.3-codex-fast",+ "gpt-5.3-codex-high",+ "gpt-5.3-codex-high-fast",+ "gpt-5.3-codex-xhigh",+ "gpt-5.3-codex-xhigh-fast",+ "gpt-5.2",+ "gpt-5.2-codex-low",+ "gpt-5.2-codex-low-fast",+ "gpt-5.2-codex",+ "gpt-5.2-codex-fast",+ "gpt-5.2-codex-high",+ "gpt-5.2-codex-high-fast",+ "gpt-5.2-codex-xhigh",+ "gpt-5.2-codex-xhigh-fast",+ "gpt-5.1-codex-max-low",+ "gpt-5.1-codex-max-low-fast",+ "gpt-5.1-codex-max-medium",+ "gpt-5.1-codex-max-medium-fast",+ "gpt-5.1-codex-max-high",+ "gpt-5.1-codex-max-high-fast",+ "gpt-5.1-codex-max-xhigh",+ "gpt-5.1-codex-max-xhigh-fast",+ "composer-2.5",+ "claude-opus-4-8-thinking-high",+ "claude-opus-4-8-thinking-high-fast",+ "gpt-5.5-high",+ "gpt-5.5-high-fast",+ "claude-opus-4-7-thinking-high",+ "claude-opus-4-7-thinking-high-fast",+ "gpt-5.4-high",+ "gpt-5.4-high-fast",+ "claude-4.6-opus-high-thinking",+ "composer-2.5-fast",+ "claude-opus-4-8-low",+ "claude-opus-4-8-low-fast",+ "claude-opus-4-8-medium",+ "claude-opus-4-8-medium-fast",+ "claude-opus-4-8-high",+ "claude-opus-4-8-high-fast",+ "claude-opus-4-8-xhigh",+ "claude-opus-4-8-xhigh-fast",+ "claude-opus-4-8-max",+ "claude-opus-4-8-max-fast",+ "claude-opus-4-8-thinking-low",+ "claude-opus-4-8-thinking-low-fast",+ "claude-opus-4-8-thinking-medium",+ "claude-opus-4-8-thinking-medium-fast",+ "claude-opus-4-8-thinking-xhigh",+ "claude-opus-4-8-thinking-xhigh-fast",+ "claude-opus-4-8-thinking-max",+ "claude-opus-4-8-thinking-max-fast",+ "gpt-5.5-none",+ "gpt-5.5-none-fast",+ "gpt-5.5-low",+ "gpt-5.5-low-fast",+ "gpt-5.5-medium",+ "gpt-5.5-medium-fast",+ "gpt-5.5-extra-high",+ "gpt-5.5-extra-high-fast",+ "claude-4.6-sonnet-medium",+ "claude-4.6-sonnet-medium-thinking",+ "claude-opus-4-7-low",+ "claude-opus-4-7-low-fast",+ "claude-opus-4-7-medium",+ "claude-opus-4-7-medium-fast",+ "claude-opus-4-7-high",+ "claude-opus-4-7-high-fast",+ "claude-opus-4-7-xhigh",+ "claude-opus-4-7-xhigh-fast",+ "claude-opus-4-7-max",+ "claude-opus-4-7-max-fast",+ "claude-opus-4-7-thinking-low",+ "claude-opus-4-7-thinking-low-fast",+ "claude-opus-4-7-thinking-medium",+ "claude-opus-4-7-thinking-medium-fast",+ "claude-opus-4-7-thinking-xhigh",+ "claude-opus-4-7-thinking-xhigh-fast",+ "claude-opus-4-7-thinking-max",+ "claude-opus-4-7-thinking-max-fast",+ "grok-build-0.1",+ "gpt-5.4-low",+ "gpt-5.4-medium",+ "gpt-5.4-medium-fast",+ "gpt-5.4-xhigh",+ "gpt-5.4-xhigh-fast",+ "claude-4.6-opus-high",+ "claude-4.6-opus-max",+ "claude-4.6-opus-high-thinking-fast",+ "claude-4.6-opus-max-thinking",+ "claude-4.6-opus-max-thinking-fast",+ "claude-4.5-opus-high",+ "claude-4.5-opus-high-thinking",+ "gpt-5.2-low",+ "gpt-5.2-low-fast",+ "gpt-5.2-fast",+ "gpt-5.2-high",+ "gpt-5.2-high-fast",+ "gpt-5.2-xhigh",+ "gpt-5.2-xhigh-fast",+ "gemini-3.1-pro",+ "gpt-5.4-mini-none",+ "gpt-5.4-mini-low",+ "gpt-5.4-mini-medium",+ "gpt-5.4-mini-high",+ "gpt-5.4-mini-xhigh",+ "gpt-5.4-nano-none",+ "gpt-5.4-nano-low",+ "gpt-5.4-nano-medium",+ "gpt-5.4-nano-high",+ "gpt-5.4-nano-xhigh",+ "grok-4.3",+ "claude-4.5-sonnet",+ "claude-4.5-sonnet-thinking",+ "gpt-5.1-low",+ "gpt-5.1",+ "gpt-5.1-high",+ "gemini-3-flash",+ "gemini-3.5-flash",+ "gpt-5.1-codex-mini-low",+ "gpt-5.1-codex-mini",+ "gpt-5.1-codex-mini-high",+ "claude-4-sonnet",+ "claude-4-sonnet-thinking",+ "gpt-5-mini",+ "kimi-k2.5",+] as const;++export const CURSOR_AGENT_MODEL_ID_SET = new Set<string>(CURSOR_AGENT_MODEL_IDS);diff --git a/src/providers/cursor/translate/model.test.ts b/src/providers/cursor/translate/model.test.tsindex 60262b0..19fe1fa 100644--- a/src/providers/cursor/translate/model.test.ts+++ b/src/providers/cursor/translate/model.test.ts@@ -1,5 +1,6 @@import { describe, expect, it } from "bun:test";-import { resolveCursorModel } from "./model.ts";+import { CURSOR_AGENT_MODEL_IDS } from "./catalog.ts";+import { CURSOR_SUPPORTED_MODELS, isCursorModel, resolveCursorModel } from "./model.ts";describe("Cursor model selection", () => {it("maps cursor aliases to composer fast", () => {@@ -33,4 +34,34 @@ describe("Cursor model selection", () => {parameters: [{ id: "fast", value: "true" }],});});++ it("preserves exact Cursor catalog ids", () => {+ const selected = resolveCursorModel({+ model: "cursor:gpt-5.5-high-fast",+ metadata: undefined,+ });++ expect(selected.mode).toBe("AGENT_MODE_AGENT");+ expect(selected.requestedModel).toEqual({ modelId: "gpt-5.5-high-fast" });+ });++ it("supports prefixed plan and ask variants for catalog ids", () => {+ expect(resolveCursorModel({ model: "cursor-plan:gpt-5.5-high", metadata: undefined })).toEqual({+ mode: "AGENT_MODE_PLAN",+ requestedModel: { modelId: "gpt-5.5-high" },+ });+ expect(resolveCursorModel({ model: "cursor-ask:claude-opus-4-8-thinking-high", metadata: undefined })).toEqual({+ mode: "AGENT_MODE_ASK",+ requestedModel: { modelId: "claude-opus-4-8-thinking-high" },+ });+ });++ it("advertises current Cursor Agent models with unambiguous prefixes", () => {+ expect(CURSOR_AGENT_MODEL_IDS.length).toBeGreaterThan(100);+ expect(CURSOR_SUPPORTED_MODELS.has("cursor:gpt-5.5-high")).toBe(true);+ expect(CURSOR_SUPPORTED_MODELS.has("cursor-plan:gpt-5.5-high")).toBe(true);+ expect(CURSOR_SUPPORTED_MODELS.has("cursor-ask:gpt-5.5-high")).toBe(true);+ expect(isCursorModel("cursor:kimi-k2.5")).toBe(true);+ expect(isCursorModel("gpt-5.2")).toBe(false);+ });});diff --git a/src/providers/cursor/translate/model.ts b/src/providers/cursor/translate/model.tsindex 5a02127..4f2455b 100644--- a/src/providers/cursor/translate/model.ts+++ b/src/providers/cursor/translate/model.ts@@ -1,12 +1,13 @@import type { CursorAgentMode, CursorModelRequest } from "../client.ts";import type { AnthropicRequest } from "../../../anthropic/schema.ts";+import { CURSOR_AGENT_MODEL_IDS, CURSOR_AGENT_MODEL_ID_SET } from "./catalog.ts";export interface CursorModelSelection {requestedModel: CursorModelRequest;mode: CursorAgentMode;}-export const CURSOR_SUPPORTED_MODELS = new Set([+const LEGACY_CURSOR_MODELS = ["cursor","cursor-agent","cursor-composer",@@ -15,22 +16,40 @@ export const CURSOR_SUPPORTED_MODELS = new Set(["cursor-ask","composer-2.5","composer-2.5-fast",+] as const;++export const CURSOR_SUPPORTED_MODELS = new Set<string>([+ ...LEGACY_CURSOR_MODELS,+ ...CURSOR_AGENT_MODEL_IDS.map((id) => `cursor:${id}`),+ ...CURSOR_AGENT_MODEL_IDS.map((id) => `cursor-plan:${id}`),+ ...CURSOR_AGENT_MODEL_IDS.map((id) => `cursor-ask:${id}`),]);+const CURSOR_MODEL_PREFIXES = [+ { prefix: "cursor-plan:", mode: "AGENT_MODE_PLAN" as const },+ { prefix: "cursor-ask:", mode: "AGENT_MODE_ASK" as const },+ { prefix: "cursor-agent:", mode: "AGENT_MODE_AGENT" as const },+ { prefix: "cursor:", mode: undefined },+];+export function isCursorModel(model: string): boolean {- return CURSOR_SUPPORTED_MODELS.has(model) || model.startsWith("cursor:");+ return CURSOR_SUPPORTED_MODELS.has(model) || CURSOR_MODEL_PREFIXES.some((p) => model.startsWith(p.prefix));}export function resolveCursorModel(req: Pick<AnthropicRequest, "model" | "metadata">): CursorModelSelection {let mode = modeFromMetadata(req.metadata);+ const prefixed = splitCursorModelPrefix(req.model);+ if (prefixed) {+ return {+ requestedModel: parseRawCursorModel(prefixed.raw),+ mode: prefixed.mode ?? mode ?? "AGENT_MODE_AGENT",+ };+ }+if (req.model === "cursor-plan") mode = "AGENT_MODE_PLAN";else if (req.model === "cursor-ask") mode = "AGENT_MODE_ASK";else mode ??= "AGENT_MODE_AGENT";- if (req.model.startsWith("cursor:")) {- return { requestedModel: parseRawCursorModel(req.model.slice("cursor:".length)), mode };- }-switch (req.model) {case "cursor":case "cursor-agent":@@ -51,6 +70,7 @@ export function resolveCursorModel(req: Pick<AnthropicRequest, "model" | "metada}function parseRawCursorModel(raw: string): CursorModelRequest {+ if (CURSOR_AGENT_MODEL_ID_SET.has(raw)) return { modelId: raw };if (raw.endsWith("-fast")) {return {modelId: raw.slice(0, -"-fast".length),@@ -60,6 +80,13 @@ function parseRawCursorModel(raw: string): CursorModelRequest {return { modelId: raw };}+function splitCursorModelPrefix(model: string): { raw: string; mode?: CursorAgentMode } | undefined {+ for (const p of CURSOR_MODEL_PREFIXES) {+ if (model.startsWith(p.prefix)) return { raw: model.slice(p.prefix.length), mode: p.mode };+ }+ return undefined;+}+function modeFromMetadata(metadata: unknown): CursorAgentMode | undefined {if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) return undefined;const value = (metadata as Record<string, unknown>).cursor_mode ?? (metadata as Record<string, unknown>).cursorMode;