Skip to content

Commit d3ef7e8

Browse files
fix(cursor): send the catalog's default model parameters on every Cursor run (pingdotgg#28722)
1 parent 148612e commit d3ef7e8

6 files changed

Lines changed: 106 additions & 8 deletions

File tree

‎packages/provider-cursor/src/server/adapter.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ const CURSOR_AGENT_SETTING_SOURCES = [
307307
export function makeCursorAgentOptions(input: {
308308
readonly apiKey?: string;
309309
readonly modelSelection: ModelSelection;
310+
readonly models?: ReadonlyArray<ServerProviderModel>;
310311
readonly runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy;
311312
readonly threadId: ThreadId;
312313
readonly mcpSession: McpProviderSession.McpProviderSessionConfig | undefined;
@@ -315,7 +316,7 @@ export function makeCursorAgentOptions(input: {
315316
const policy = cursorRuntimeAgentPolicy(input.runtimePolicy, input.platform);
316317
const mcpServers = cursorMcpServers(input.mcpSession);
317318
return {
318-
model: cursorSdkModelSelection(input.modelSelection),
319+
model: cursorSdkModelSelection(input.modelSelection, input.models),
319320
name: `T3 Code ${input.threadId}`,
320321
mode: input.runtimePolicy.interactionMode === "plan" ? "plan" : "agent",
321322
...(input.apiKey === undefined ? {} : { apiKey: input.apiKey }),
@@ -2296,6 +2297,7 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
22962297
const options = makeCursorAgentOptions({
22972298
...(apiKey === undefined ? {} : { apiKey }),
22982299
modelSelection: openInput.modelSelection,
2300+
models: adapterOptions.getModels?.() ?? [],
22992301
runtimePolicy: openInput.runtimePolicy,
23002302
platform,
23012303
threadId: openInput.threadId,
@@ -2486,7 +2488,10 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
24862488
message,
24872489
summarize: compacted,
24882490
options: {
2489-
model: cursorSdkModelSelection(turnInput.modelSelection),
2491+
model: cursorSdkModelSelection(
2492+
turnInput.modelSelection,
2493+
adapterOptions.getModels?.() ?? [],
2494+
),
24902495
mode: turnInput.runtimePolicy.interactionMode === "plan" ? "plan" : "agent",
24912496
...(Object.keys(turnMcpServers).length === 0
24922497
? {}

‎packages/provider-cursor/src/server/driver.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ it.layer(layerTest)("CursorDriver", (it) => {
389389
allowance: DEFAULT_HANDOFF_TOKEN_CAP,
390390
},
391391
catalogDefault: {
392-
model: { id: "claude-opus-5-5" },
392+
model: { id: "claude-opus-5-5", params: [{ id: "context", value: "1m" }] },
393393
window: 1_000_000,
394394
allowance: DEFAULT_HANDOFF_TOKEN_CAP,
395395
},

‎packages/provider-cursor/src/server/driver.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export const CursorDriver: ProviderDriver<
208208
processEnv,
209209
auth.requireApiKey,
210210
auth.withAccess,
211+
() => catalogModels,
211212
);
212213

213214
const checkProvider = auth.readApiKey.pipe(
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { ProviderInstanceId } from "@t3tools/contracts";
2+
import { describe, expect, it } from "vite-plus/test";
3+
4+
import { cursorSdkModelSelection } from "./sdkModel.ts";
5+
import { buildCursorDiscoveredModelsFromSdk } from "./status.ts";
6+
7+
const instanceId = ProviderInstanceId.make("cursor");
8+
const models = buildCursorDiscoveredModelsFromSdk([
9+
{
10+
id: "grok-4.5",
11+
displayName: "Grok 4.5",
12+
parameters: [
13+
{
14+
id: "effort",
15+
displayName: "Effort",
16+
values: [{ value: "low" }, { value: "medium" }, { value: "high" }],
17+
},
18+
{ id: "fast", displayName: "Fast", values: [{ value: "false" }, { value: "true" }] },
19+
],
20+
variants: [
21+
{
22+
displayName: "Grok 4.5 High Fast",
23+
isDefault: true,
24+
params: [
25+
{ id: "effort", value: "high" },
26+
{ id: "fast", value: "true" },
27+
],
28+
},
29+
],
30+
},
31+
]);
32+
33+
describe("cursorSdkModelSelection", () => {
34+
it.each([
35+
{
36+
name: "fills unset catalog parameters and keeps Fast off",
37+
options: undefined,
38+
params: [
39+
{ id: "effort", value: "high" },
40+
{ id: "fast", value: "false" },
41+
],
42+
},
43+
{
44+
name: "keeps explicit options",
45+
options: [
46+
{ id: "effort", value: "low" },
47+
{ id: "fastMode", value: true },
48+
],
49+
params: [
50+
{ id: "effort", value: "low" },
51+
{ id: "fast", value: "true" },
52+
],
53+
},
54+
])("$name", ({ options, params }) => {
55+
const selection = cursorSdkModelSelection(
56+
{ instanceId, model: "grok-4.5", ...(options === undefined ? {} : { options }) },
57+
models,
58+
);
59+
expect({
60+
...selection,
61+
params: selection.params?.toSorted((a, b) => a.id.localeCompare(b.id)),
62+
}).toEqual({
63+
id: "grok-4.5",
64+
params,
65+
});
66+
});
67+
68+
it("sends no parameters for a model missing from the catalog", () => {
69+
expect(cursorSdkModelSelection({ instanceId, model: "auto" }, models)).toEqual({
70+
id: "default",
71+
});
72+
});
73+
});

‎packages/provider-cursor/src/server/sdkModel.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,27 @@ export function cursorContextWindowTokens(
5555
return Number.isSafeInteger(tokens) && tokens > 0 ? tokens : undefined;
5656
}
5757

58-
export function cursorSdkModelSelection(modelSelection: ModelSelection): CursorSdkModelSelection {
58+
export function cursorSdkModelSelection(
59+
modelSelection: ModelSelection,
60+
models: ReadonlyArray<ServerProviderModel> = [],
61+
): CursorSdkModelSelection {
62+
const explicit = modelSelection.options ?? [];
63+
const descriptors =
64+
models.find((model) => model.slug === modelSelection.model)?.capabilities?.optionDescriptors ??
65+
[];
66+
// Some Cursor plans reject runs that leave a catalog parameter unset; T3 keeps Fast off until picked.
67+
const defaults = descriptors.flatMap((descriptor) => {
68+
if (explicit.some((option) => option.id === descriptor.id)) return [];
69+
const value = descriptor.id === "fastMode" ? false : getProviderOptionCurrentValue(descriptor);
70+
return value === undefined ? [] : [{ id: descriptor.id, value }];
71+
});
72+
const options = [...explicit, ...defaults];
5973
return {
6074
id: modelSelection.model === "auto" ? "default" : modelSelection.model,
61-
...(modelSelection.options === undefined || modelSelection.options.length === 0
75+
...(options.length === 0
6276
? {}
6377
: {
64-
params: modelSelection.options.map((option): ModelParameterValue => ({
78+
params: options.map((option): ModelParameterValue => ({
6579
id: cursorSdkParameterId(option.id),
6680
value: String(option.value),
6781
})),

‎packages/provider-cursor/src/server/textGeneration.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import * as Effect from "effect/Effect";
55
import * as Option from "effect/Option";
66
import * as Schema from "effect/Schema";
77

8-
import { type ProviderSetupError, TextGenerationError } from "@t3tools/contracts";
8+
import {
9+
type ProviderSetupError,
10+
type ServerProviderModel,
11+
TextGenerationError,
12+
} from "@t3tools/contracts";
913
import type { CursorSettings } from "../settings.ts";
1014

1115
import * as TextGenerationOperations from "@t3tools/provider-core/server/textGenerationOperations";
@@ -51,6 +55,7 @@ export const makeCursorTextGeneration = Effect.fn("makeCursorTextGeneration")(fu
5155
environment?: NodeJS.ProcessEnv,
5256
resolveApiKey?: Effect.Effect<string, ProviderSetupError>,
5357
withAccess?: CursorAuth["withAccess"],
58+
getModels?: () => ReadonlyArray<ServerProviderModel>,
5459
) {
5560
const fs = yield* FileSystem.FileSystem;
5661
const sdk = yield* CursorSdk.CursorSdk;
@@ -117,7 +122,7 @@ export const makeCursorTextGeneration = Effect.fn("makeCursorTextGeneration")(fu
117122
const agentOptions = {
118123
apiKey,
119124
mode: "plan",
120-
model: cursorSdkModelSelection(modelSelection),
125+
model: cursorSdkModelSelection(modelSelection, getModels?.() ?? []),
121126
local: {
122127
cwd,
123128
store,

0 commit comments

Comments
 (0)