Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(cursor): the picker lists every model the ACP session offers (#4027)
Aditya Umale80012e69dd8b
diff --git a/docs/cursor.md b/docs/cursor.mdindex 66eaaafb49..cd93634e5b 100644--- a/docs/cursor.md+++ b/docs/cursor.md@@ -36,11 +36,16 @@ missing login shows as unauthenticated rather than crashing the fleet.## Models-The picker starts from a small static catalog and refreshes from plain-`cursor-agent models` output (`slug - Label`, with `(default)` / `(current)` markers).-Live ids are merged into the main cloud rail (not the local-models pane). A-failed listing keeps the last usable catalog (then the static fallback) rather-than emptying the rail.+The picker starts from a small static catalog and refreshes from the models an+ACP session advertises: OpenMausBot opens `cursor-agent acp`, sends+`initialize` and `session/new` in an empty folder, and stops, so the refresh+sends no prompt. Each advertised model shows once under its plain slug+(`grok-4.7[...]` as `grok-4.7`, `default[]` as `auto`). A static entry stays+only when the session offers its model. `cursor-agent models` lists only `auto`+on CLI 2026.10.22, so it answers only when no session opens (`slug - Label`,+with `(default)` / `(current)` markers). Live ids are merged into the main cloud+rail (not the local-models pane). A failed listing keeps the last usable+catalog (then the static fallback) rather than emptying the rail.`--model <id>` is passed as a global CLI flag before `acp`. Current CLIs(checked with 2026.09.28) ignore that flag in ACP sessions: every sessiondiff --git a/server/drivers/acp/cursor.test.ts b/server/drivers/acp/cursor.test.tsindex b308fa4372..5e3dc4912e 100644--- a/server/drivers/acp/cursor.test.ts+++ b/server/drivers/acp/cursor.test.ts@@ -11,6 +11,7 @@ import { removeTempDir } from "../../testing/cleanup.ts";import {classifyCursorError,createCursorAgentDriver,+ cursorCatalogFromSession,CursorAgentDriver,decodeCursorAuthStatus,decodeCursorAuthText,@@ -101,6 +102,28 @@ cursor-text - Cursor Text});});+describe("cursorCatalogFromSession", () => {+ it("offers one flat slug per base, names default[] auto, and keeps only the static entries the session offers", () => {+ expect(cursorCatalogFromSession([+ { id: "default[]", label: "Auto" },+ { id: "grok-4.7[reasoning_effort=high,fast=true]", label: "grok-4.7" },+ { id: "grok-4.7[reasoning_effort=high,fast=false]", label: "grok-4.7" },+ { id: "gpt-5.3-codex[reasoning=medium]", label: "Codex 5.3" },+ ])).toEqual({+ default: "auto",+ options: [+ { id: "auto", label: "Auto" },+ { id: "gpt-5.3-codex", label: "Codex 5.3" },+ { id: "grok-4.7", label: "Grok 4.7" },+ ],+ });+ });++ it("returns null when the session advertises nothing, so the text list can answer", () => {+ expect(cursorCatalogFromSession([])).toBeNull();+ });+});+describe("classifyCursorError", () => {it("maps auth and subscription failures onto provider codes", () => {expect(classifyCursorError({ code: -32000, message: "Authentication required" })).toBe("invalid_credentials");@@ -157,6 +180,60 @@ describe("CursorAgentDriver", () => {}});+ it("lists every model the ACP session advertises when `cursor-agent models` lists only auto", async () => {+ ensureDirs();+ chmodSync(FAKE_CLI, 0o755);+ const scratch = mkdtempSync(join(tmpdir(), "omb-cursor-acp-catalog-"));+ scratchDirs.push(scratch);+ const dump = join(scratch, "dump.json");+ const rpc = join(scratch, "rpc.jsonl");+ // Cursor CLI 2026.10.22-27dcf5f: `models` prints only `auto`, session/new lists 32.+ process.env.FAKE_ACP_MODELS_LIST = "auto-only";+ process.env.FAKE_ACP_SESSION_MODELS = [+ "auto-smart[optimize_for=balanced]|Auto Balance",+ "grok-4.7[context=256k,reasoning_effort=high,fast=true]|grok-4.7",+ "composer-2.5[fast=true]|composer-2.5",+ "gpt-5.6-sol[context=272k,reasoning=medium,fast=false]|gpt-5.6-sol",+ "gpt-5.3-codex[reasoning=medium,fast=false]|gpt-5.3-codex",+ "kimi-k3[reasoning=max]|kimi-k3",+ "glm-5.2[reasoning=high]|glm-5.2",+ ].join(",");+ process.env.FAKE_ACP_RPC_APPEND_FILE = rpc;++ const instance = await createCursorAgentDriver().create({+ instanceId: "cursor-acp-catalog",+ displayName: "Cursor",+ environment: {},+ enabled: true,+ config: { cli: FAKE_CLI, fullAuto: false },+ });+ const recorder = recordEvents(instance.adapter);+ try {+ expect(instance.models.default).toBe("auto");+ expect(instance.models.options.map((option) => option.id)).toEqual([+ "auto", "composer-2.5", "composer-2.5-fast", "gpt-5.3-codex",+ "auto-smart", "grok-4.7", "gpt-5.6-sol", "kimi-k3", "glm-5.2",+ ]);+ expect(instance.models.options.find((option) => option.id === "auto-smart")?.label).toBe("Auto Balance");+ const methods = readFileSync(rpc, "utf8").trim().split("\n").map((line) => JSON.parse(line).method);+ expect(methods).toContain("session/new");+ expect(methods).not.toContain("session/prompt");+ expect(methods).not.toContain("session/set_model");++ process.env.FAKE_ACP_DUMP = dump;+ const turn = await instance.adapter.sendTurn({ threadId: "t-cursor-acp-catalog", text: "hi", model: "gpt-5.6-sol" });+ expect(await recorder.until((e) => e.type === "turn.completed" && e.turnId === turn.turnId)).toMatchObject({ ok: true });+ expect(JSON.parse(readFileSync(`${dump}.config.json`, "utf8"))).toEqual([+ { method: "session/set_model", params: { sessionId: expect.any(String), modelId: "gpt-5.6-sol[context=272k,reasoning=medium,fast=false]" } },+ ]);+ } finally {+ recorder.stop();+ await instance.dispose();+ delete process.env.FAKE_ACP_MODELS_LIST;+ delete process.env.FAKE_ACP_SESSION_MODELS;+ }+ });+it("treats CURSOR_API_KEY as signed in without asking the CLI", async () => {chmodSync(FAKE_CLI, 0o755);const instance = await CursorAgentDriver.create({diff --git a/server/drivers/acp/cursor.ts b/server/drivers/acp/cursor.tsindex 30576bff21..7978922c32 100644--- a/server/drivers/acp/cursor.ts+++ b/server/drivers/acp/cursor.ts@@ -5,6 +5,7 @@ import type { ModelCatalog, ProviderErrorCode } from "../../contracts.ts";import { titleCaseModelId } from "../../contracts.ts";import { execCli } from "../../procs.ts";import { createAcpDriver, type AcpSupport } from "./core.ts";+import { discoverAcpModels } from "./custom-model-catalog.ts";import type { AcpQuestionRequest } from "./question-requests.ts";import {capAnswerEcho, formatQuestionAnswers, MAX_QUESTIONS, parseChoices, parseProtocolAskQuestions, pickedOptionLabels, questionAnswersById,@@ -99,6 +100,10 @@ export const STATIC_CURSOR_MODELS: ModelCatalog = {],};+/** Without parameterizedModelPicker Cursor (CLI 2026.10.19) offers only `composer-2.5[fast=true]`, so a+ * `composer-2.5` bot bills as Fast; with it, Fast is a separate `fast` config option. */+const CURSOR_CLIENT_META = { parameterizedModelPicker: true };+const SLUG = /^[a-z0-9][a-z0-9._:+-]*$/i;const EXEC_TIMEOUT_MS = 8_000;@@ -145,6 +150,17 @@ function pushModel(options.push({ id, label: labelFor(id, label), ...(custom ? { custom: true as const } : {}) });}+function withUnseen(first: ModelCatalog["options"], rest: ModelCatalog["options"]): ModelCatalog["options"] {+ const merged = first.map((option) => ({ ...option }));+ const seen = new Set(merged.map((option) => option.id));+ for (const option of rest) {+ if (seen.has(option.id)) continue;+ seen.add(option.id);+ merged.push(option);+ }+ return merged;+}+export function decodeCursorModelCatalog(payload: unknown): ModelCatalog | null {const records: unknown[] = Array.isArray(payload)? payload@@ -182,14 +198,7 @@ export function decodeCursorModelCatalog(payload: unknown): ModelCatalog | null: undefined) ??(seen.has(STATIC_CURSOR_MODELS.default) ? STATIC_CURSOR_MODELS.default : options[0]!.id);- const merged: ModelCatalog["options"] = STATIC_CURSOR_MODELS.options.map((option) => ({ ...option }));- const mergedSeen = new Set(merged.map((option) => option.id));- for (const option of options) {- if (mergedSeen.has(option.id)) continue;- mergedSeen.add(option.id);- merged.push(option);- }- return { default: defaultId, options: merged };+ return { default: defaultId, options: withUnseen(STATIC_CURSOR_MODELS.options, options) };}function stripModelMarkers(label: string): { label: string; isDefault: boolean; isCurrent: boolean } {@@ -228,18 +237,11 @@ export function decodeCursorModelText(text: string): ModelCatalog | null {if (isCurrent) markedCurrent = id;}if (!options.length) return null;- const merged: ModelCatalog["options"] = STATIC_CURSOR_MODELS.options.map((option) => ({ ...option }));- const mergedSeen = new Set(merged.map((option) => option.id));- for (const option of options) {- if (mergedSeen.has(option.id)) continue;- mergedSeen.add(option.id);- merged.push(option);- }const defaultId =(markedDefault && seen.has(markedDefault) ? markedDefault : undefined) ??(markedCurrent && seen.has(markedCurrent) ? markedCurrent : undefined) ??(seen.has(STATIC_CURSOR_MODELS.default) ? STATIC_CURSOR_MODELS.default : options[0]!.id);- return { default: defaultId, options: merged };+ return { default: defaultId, options: withUnseen(STATIC_CURSOR_MODELS.options, options) };}function truthyAuthFlag(value: unknown): boolean | null {@@ -311,11 +313,30 @@ export async function probeCursorAuth(return false;}+export function cursorCatalogFromSession(advertised: ModelCatalog["options"]): ModelCatalog | null {+ const discovered: ModelCatalog["options"] = [];+ const bases = new Set<string>();+ for (const model of advertised) {+ const raw = model.id.split("[")[0]!.trim();+ const id = raw.toLowerCase() === "default" ? STATIC_CURSOR_MODELS.default : raw;+ pushModel(discovered, bases, id, model.label.trim().toLowerCase() === id.toLowerCase() ? titleCaseModelId(id, /[-_]+/) : model.label);+ }+ if (!discovered.length) return null;+ const offered = STATIC_CURSOR_MODELS.options+ .filter((option) => option.id === STATIC_CURSOR_MODELS.default || bases.has(option.id.replace(/-fast$/, "")));+ return { default: STATIC_CURSOR_MODELS.default, options: withUnseen(offered, discovered) };+}++/** `cursor-agent models` (2026.10.22) lists only `auto` while session/new lists every model the account can use, so the+ * session answers first; the text list stands in for a CLI that cannot open one. */export async function fetchCursorModels(cli: string,env: Record<string, string | undefined>,run: typeof execCli = execCli,): Promise<ModelCatalog> {+ const fromSession = await discoverAcpModels(env, cli, ["acp"], { variants: false, clientCapabilitiesMeta: CURSOR_CLIENT_META })+ .then((catalog) => cursorCatalogFromSession(catalog.options), () => null);+ if (fromSession) return fromSession;// Live CLI prints plain text (`slug - Label`); `--format json` is not supported yet.for (const args of [["models"], ["--list-models"]] as const) {const stdout = await execText(run, cli, [...args], env);@@ -454,9 +475,7 @@ const support = (run: typeof execCli): AcpSupport => ({isAuthenticated: (env, config) => probeCursorAuth(config.cli || "cursor-agent", env, run),classifyError: classifyCursorError,- // Without parameterizedModelPicker Cursor (CLI 2026.10.19) offers only `composer-2.5[fast=true]`, so a- // `composer-2.5` bot bills as Fast; with it, Fast is a separate `fast` config option.- clientCapabilitiesMeta: { parameterizedModelPicker: true },+ clientCapabilitiesMeta: CURSOR_CLIENT_META,async configureSession({ request, sessionId, turn, sessionModels, currentModelId, configOptions, notice }) {if (!turn.model) return;diff --git a/server/drivers/acp/custom-model-catalog.ts b/server/drivers/acp/custom-model-catalog.tsindex 3accb025f0..56a76be5e5 100644--- a/server/drivers/acp/custom-model-catalog.ts+++ b/server/drivers/acp/custom-model-catalog.ts@@ -25,6 +25,8 @@ export interface AcpDiscoveryOptions {variants?: boolean;/** The catalog default when the agent offers it; otherwise the session's current model. */default?: string;+ /** Sent as `clientCapabilities._meta` in initialize, as a turn session sends it, so both see the same model list. */+ clientCapabilitiesMeta?: Record<string, unknown>;/** The picker label for an advertised model, given session/new's result verbatim. */label?(model: { id: string; label: string }, sessionNew: unknown): string;/** Close stdin and give the agent this many milliseconds to exit on its own, so it can release what it holds,@@ -170,7 +172,11 @@ export async function discoverAcpModels(await request("initialize", {protocolVersion: 1,clientInfo: { name: DISCOVERY_CLIENT_NAME, version: "1" },- clientCapabilities: { fs: { readTextFile: false, writeTextFile: false }, terminal: false },+ clientCapabilities: {+ fs: { readTextFile: false, writeTextFile: false },+ terminal: false,+ ...(discovery.clientCapabilitiesMeta ? { _meta: discovery.clientCapabilitiesMeta } : {}),+ },});const initial = await request("session/new", { cwd, mcpServers: [] });const rawSessionId = record(initial)?.sessionId;diff --git a/server/testing/fake-acp-cli.ts b/server/testing/fake-acp-cli.tsindex feb56643cb..cfa7cc0966 100755--- a/server/testing/fake-acp-cli.ts+++ b/server/testing/fake-acp-cli.ts@@ -39,6 +39,7 @@// a new session starts on AGY_ACP_DEFAULT_MODEL when set, taken unchecked as agy_acp_server 1.1.1 does// FAKE_ACP_MODELS_FILE the same list, read once at startup, as `opencode acp` never re-reads a login// FAKE_ACP_MODELS_LIST=v2 OpenCode 2: `models` answers empty with exit 0, `models --verbose` exits 1+// FAKE_ACP_MODELS_LIST=auto-only Cursor CLI 2026.10.22: `models` lists only `auto`// FAKE_ACP_VERBOSE_FAIL_ONCE marker path: the first `models --verbose` fails, like a new OpenCode home's first run// FAKE_ACP_MODEL_STICKS set_config_option succeeds but keeps the old model// FAKE_ACP_EXIT_ON_MODEL the process exits when set_config_option selects this model@@ -294,6 +295,10 @@ if (argv[0] === "models" || argv.includes("--list-models")) {}process.exit(0);}+ if (process.env.FAKE_ACP_MODELS_LIST === "auto-only") {+ console.log(["Available models", "", "auto - Auto (default)"].join("\n"));+ process.exit(0);+ }if (models.length) {const verbose = argv.includes("--verbose");console.log(