diff --git a/apps/server/scripts/acp-mock-agent.ts b/apps/server/scripts/acp-mock-agent.ts index 78373d82e1487..b34edf17addc0 100644 --- a/apps/server/scripts/acp-mock-agent.ts +++ b/apps/server/scripts/acp-mock-agent.ts @@ -197,6 +197,7 @@ function configOptions(): ReadonlyArray { { value: "composer-2", name: "Composer 2" }, { value: "gpt-5.4", name: "GPT-5.4" }, { value: "claude-opus-4-6", name: "Opus 4.6" }, + { value: "claude-sonnet-4-6", name: "Sonnet 4.6" }, ], }, ]; @@ -258,10 +259,11 @@ function configOptions(): ReadonlyArray { }, ]; case "claude-opus-4-6": + case "claude-sonnet-4-6": return [ ...baseOptions, { - configId: "reasoning", + configId: currentModelId === "claude-opus-4-6" ? "effort" : "reasoning_effort", name: "Reasoning", category: "thought_level", type: "select", @@ -845,7 +847,10 @@ const program = Effect.gen(function* () { if (request.configId === "agent" && typeof request.value === "string") { currentAgent = request.value; } - if (request.configId === "reasoning" && typeof request.value === "string") { + if ( + ["reasoning", "effort", "reasoning_effort"].includes(request.configId) && + typeof request.value === "string" + ) { currentReasoning = request.value; } if (request.configId === "context" && typeof request.value === "string") { diff --git a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts index ee82cc06de836..0dce6398cbe15 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts @@ -1235,6 +1235,124 @@ describe("AcpRegistryAdapterV2", () => { }).pipe(Effect.provide(layerTest)), ); + // regression: #24371 Cursor lists only fixed effort presets unless asked for its picker + it.effect("opens Cursor on a plain model with the reasoning effort the thread picked", () => + Effect.gen(function* () { + const path = yield* Path.Path; + const mockAgentPath = yield* path.fromFileUrl( + new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), + ); + const instanceId = ProviderInstanceId.make("acp-registry-cursor"); + const openCursor = Effect.fn("openCursor")(function* (stored: ModelSelection) { + let published: AcpRegistryLiveConfiguration | undefined; + const adapter = yield* makeAcpRegistryAdapterV2({ + selfInvocation: yield* resolveSelfInvocation(), + instanceId, + settings: yield* decodeAcpRegistryAdapterSettings({ agentId: "cursor" }), + environment: {}, + }).pipe( + Effect.provide( + Layer.mergeAll( + Layer.mock(AcpRegistrySupport.AcpRegistryCatalog)({ + resolve: (_settings, cwd) => + Effect.succeed({ + distribution: "local" as const, + spawn: { command: process.execPath, args: [mockAgentPath], cwd }, + }), + }), + Layer.mock(AcpRegistryRuntimeCoordinator.AcpRegistryRuntimeCoordinator)({ + withForegroundStartup: (_startupKey, effect) => effect, + publishLiveConfiguration: (_instanceId, configuration) => + Effect.sync(() => { + published = configuration; + }), + }), + ), + ), + ); + const threadId = ThreadId.make("thread-acp-registry-cursor"); + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ + runtimeMode: "full-access", + interactionMode: "default", + cwd: process.cwd(), + }); + yield* Effect.gen(function* () { + const runtime = yield* adapter.openSession({ + threadId: ThreadId.make("thread-acp-registry-cursor"), + providerSessionId: ProviderSessionId.make("provider-session-acp-registry-cursor"), + modelSelection: stored, + runtimePolicy, + }); + const providerThread = yield* runtime.ensureThread({ + threadId, + modelSelection: stored, + runtimePolicy, + }); + yield* runtime.startTurn( + makeTurnInput({ + threadId, + providerThread, + instanceId, + runtimePolicy, + now: yield* DateTime.now, + ordinal: 1, + modelSelection: stored, + }), + ); + yield* runtime.events.pipe( + Stream.takeUntil((event) => event.type === "turn.terminal"), + Stream.runForEach((event) => + Effect.sync(() => { + if (event.type === "turn.terminal") { + assert.equal(event.status, "completed", event.failure?.message); + } + }), + ), + ); + }).pipe(Effect.scoped); + return published; + }); + + const picked = yield* openCursor({ + instanceId, + model: "gpt-5.4", + options: [{ id: "reasoning", value: "extra-high" }], + }); + assert.equal(picked?.currentModelId, "gpt-5.4"); + assert.deepInclude( + picked?.configOptions.find((option) => option.id === "reasoning"), + { currentValue: "extra-high" }, + ); + for (const [model, id] of [ + ["claude-opus-4-6", "effort"], + ["claude-sonnet-4-6", "reasoning_effort"], + ]) { + const native = yield* openCursor({ instanceId, model: `${model}[${id}=high]` }); + assert.equal(native?.currentModelId, model); + assert.deepInclude( + native?.configOptions.find((option) => option.id === id), + { currentValue: "high" }, + ); + } + const legacy = yield* openCursor({ + instanceId, + model: "gpt-5.4[reasoning=high,context=1m,fast=true]", + options: [{ id: "reasoning", value: "extra-high" }], + }); + assert.equal(legacy?.currentModelId, "gpt-5.4"); + for (const [id, value] of [ + ["reasoning", "extra-high"], + ["context", "1m"], + ["fast", "true"], + ]) { + assert.deepInclude( + legacy?.configOptions.find((option) => option.id === id), + { currentValue: value }, + ); + } + }).pipe(Effect.provide(layerTest), Effect.scoped), + ); + // regression: #26695 cancelling a Copilot prompt kills its background agents it.effect("never steers Copilot by cancelling its prompt", () => Effect.gen(function* () { diff --git a/apps/server/src/provider/AcpRegistryProbe.test.ts b/apps/server/src/provider/AcpRegistryProbe.test.ts index 30915b31d474f..e74671bfc4491 100644 --- a/apps/server/src/provider/AcpRegistryProbe.test.ts +++ b/apps/server/src/provider/AcpRegistryProbe.test.ts @@ -413,6 +413,45 @@ describe("ACP Registry probe", () => { ); }); + // regression: #24371 Cursor lists only fixed effort presets unless asked for its picker + // Live clock: the probe waits a short real grace for command advertisements. + it.live("lists Cursor's plain model ids so its effort stays a separate option", () => { + const catalog = AcpRegistrySupport.AcpRegistryCatalog.of({ + search: () => Effect.die("unused search"), + prepare: () => Effect.die("unused prepare"), + inspect: () => Effect.die("unused inspect"), + uninstallManagedBinary: () => Effect.die("unused uninstall"), + resolve: () => + Effect.succeed({ + distribution: "local" as const, + spawn: { command: "node", args: [mockAgentPath] }, + }), + }); + const probedModels = (agentId: string) => + probeAcpRegistryConfiguration({ + instanceId, + settings: decodeSettings({ agentId }), + cwd: process.cwd(), + environment: process.env, + }).pipe(Effect.map((result) => result.probe.models.map((model) => model.id))); + + return Effect.gen(function* () { + expect(yield* probedModels("cursor")).toEqual([ + "default", + "composer-2", + "gpt-5.4", + "claude-opus-4-6", + "claude-sonnet-4-6", + ]); + expect(yield* probedModels("mock-agent")).toContain( + "gpt-5.3-codex[reasoning=medium,fast=false]", + ); + }).pipe( + Effect.provideService(AcpRegistrySupport.AcpRegistryCatalog, catalog), + Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)), + ); + }); + it.live.each(["succeeds", "fails"] as const)( "deletes its health-probe session when deletion is advertised and %s", (deleteOutcome) => diff --git a/packages/provider-acp-registry/src/server/adapter.ts b/packages/provider-acp-registry/src/server/adapter.ts index 49dc4426b1428..137cb0d7f7f38 100644 --- a/packages/provider-acp-registry/src/server/adapter.ts +++ b/packages/provider-acp-registry/src/server/adapter.ts @@ -18,6 +18,11 @@ import { isCopilotLostSessionError, makeCopilotSubagentRouting, } from "./copilotAcp.ts"; +import { + normalizeCursorModelSelection, + cursorClientCapabilitiesMeta, + isCursorAcpAgent, +} from "./cursorAcp.ts"; import { prefersHttpMcpTransport } from "./mcpTransport.ts"; import { defaultInstanceIdForDriver, ProviderDriverKind } from "@t3tools/contracts"; import { readCustomModelEntries } from "@t3tools/shared/model"; @@ -272,6 +277,12 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu answerablePermissionOptions: devinAnswerablePermissionOptions, } : {}), + ...(isCursorAcpAgent(options.settings) + ? { + clientCapabilitiesMeta: cursorClientCapabilitiesMeta, + normalizeModelSelection: normalizeCursorModelSelection, + } + : {}), ...(copilotRouting === undefined ? {} : { diff --git a/packages/provider-acp-registry/src/server/cursorAcp.ts b/packages/provider-acp-registry/src/server/cursorAcp.ts new file mode 100644 index 0000000000000..2ea262507b959 --- /dev/null +++ b/packages/provider-acp-registry/src/server/cursorAcp.ts @@ -0,0 +1,33 @@ +import type { ModelSelection } from "@t3tools/contracts"; +import type { AcpRegistrySettings } from "../settings.ts"; + +// Without this flag Cursor lists one fixed preset per model, such as +// `claude-opus-5-5[context=300k,effort=medium,fast=false]`. With it Cursor lists +// plain model ids and reports effort, context and fast as config options. +export const cursorClientCapabilitiesMeta = { parameterizedModelPicker: true }; + +// Local installs launch the `cursor-agent` binary directly with no registry id. +export function isCursorAcpAgent(settings: AcpRegistrySettings): boolean { + return ( + (settings.source !== "local" && settings.agentId === "cursor") || + (settings.source === "local" && + /^cursor-agent(\.exe|\.cmd)?$/i.test(settings.commandPath.split(/[\\/]/).pop() ?? "")) + ); +} + +// Preserve preset values when opening threads saved before parameterized negotiation. +export function normalizeCursorModelSelection(selection: ModelSelection): ModelSelection { + const preset = /^(.*)\[([^\]]*)\]$/.exec(selection.model); + if (preset === null) return selection; + const explicit = selection.options ?? []; + const options = preset[2]!.split(",").flatMap((entry) => { + const [id, value] = entry.split("="); + return id !== undefined && + ["reasoning", "effort", "reasoning_effort", "context", "fast"].includes(id) && + value && + !explicit.some((option) => option.id === id) + ? [{ id, value }] + : []; + }); + return { ...selection, model: preset[1]!, options: [...options, ...explicit] }; +} diff --git a/packages/provider-acp-registry/src/server/probe.ts b/packages/provider-acp-registry/src/server/probe.ts index e1689a405a8bc..c9a7b3f945762 100644 --- a/packages/provider-acp-registry/src/server/probe.ts +++ b/packages/provider-acp-registry/src/server/probe.ts @@ -35,6 +35,7 @@ import { flattenSelectChoices, } from "@t3tools/provider-acp/server/sessionConfig"; import * as AcpRegistryRuntimeCoordinator from "./AcpRegistryRuntimeCoordinator.ts"; +import { cursorClientCapabilitiesMeta, isCursorAcpAgent } from "./cursorAcp.ts"; import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime"; const MAX_AUTH_METHODS = 32; @@ -424,6 +425,8 @@ export const probeAcpRegistryConfiguration = Effect.fn("AcpRegistryProbe.probeCo elicitation: { url: {} }, fs: { readTextFile: false, writeTextFile: false }, terminal: false, + // The catalog has to list the same model ids the sessions will offer. + ...(isCursorAcpAgent(input.settings) ? { _meta: cursorClientCapabilitiesMeta } : {}), }, clientInfo: { name: "t3-code-provider-test", version: "0.0.0" }, authenticateOnAuthRequired: false, diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index a9bcc4a16bf58..51d7e70bc2dd2 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -419,6 +419,7 @@ export interface AcpAdapterV2Flavor { ChildProcessSpawner.ChildProcessSpawner | SecureRandom.SecureRandom | Scope.Scope >; readonly customModels?: ReadonlyArray; + readonly normalizeModelSelection?: (selection: ModelSelection) => ModelSelection; /** The agent may run another model than session/new reports, so the model is always written. */ readonly alwaysSetModel?: boolean; /** Values the client shows for options a new session's selection leaves unset. */ @@ -7584,6 +7585,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( const validateModelSelection = Effect.fn("AcpAdapterV2.validateModelSelection")(function* ( modelSelection: ModelSelection, ) { + modelSelection = flavor.normalizeModelSelection?.(modelSelection) ?? modelSelection; const model = flavor.resolveModelId?.(modelSelection) ?? modelSelection.model; if ( flavor.applyModelSelection !== undefined || @@ -7616,6 +7618,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( unsetOptionDefaults: NonNullable = [], ) { yield* Ref.set(activeSelection, null); + modelSelection = flavor.normalizeModelSelection?.(modelSelection) ?? modelSelection; yield* validateModelSelection(modelSelection); const requestedModel = flavor.resolveModelId?.(modelSelection) ?? modelSelection.model; // Invalid params is the agent refusing the value, and the runtime