Probe Cursor available models for capabilities
- Add `cursor/list_available_models` support to the ACP mock agent - Use the new model list response for Cursor model discovery and capability enrichment - Update tests to cover the extension path and reduced probe teardown
This commit is contained in:
1 parent
8d1d699f88
commit
c517cfab3d
3 files changed
+120
-108
No files matched your search
@@ -182,6 +182,35 @@ function configOptions(): ReadonlyArray<AcpSchema.SessionConfigOption> {
|
||||
];
|
||||
}
|
||||
|
||||
function modelConfigOptionsFor(modelId: string): ReadonlyArray<AcpSchema.SessionConfigOption> {
|
||||
const previousModelId = currentModelId;
|
||||
try {
|
||||
currentModelId = modelId;
|
||||
return configOptions().filter(
|
||||
(option) => option.category !== "mode" && option.category !== "model",
|
||||
);
|
||||
} finally {
|
||||
currentModelId = previousModelId;
|
||||
}
|
||||
}
|
||||
|
||||
function availableModels(): ReadonlyArray<{
|
||||
readonly value: string;
|
||||
readonly name: string;
|
||||
readonly configOptions: ReadonlyArray<AcpSchema.SessionConfigOption>;
|
||||
}> {
|
||||
return [
|
||||
{ value: "default", name: "Auto" },
|
||||
{ value: "composer-2", name: "Composer 2" },
|
||||
{ value: "gpt-5.4", name: "GPT-5.4" },
|
||||
{ value: "claude-opus-4-6", name: "Opus 4.6" },
|
||||
].map((model) => ({
|
||||
value: model.value,
|
||||
name: model.name,
|
||||
configOptions: modelConfigOptionsFor(model.value),
|
||||
}));
|
||||
}
|
||||
|
||||
const availableModes: ReadonlyArray<AcpSchema.SessionMode> = [
|
||||
{
|
||||
id: "ask",
|
||||
@@ -516,6 +545,12 @@ const program = Effect.gen(function* () {
|
||||
);
|
||||
|
||||
yield* agent.handleUnknownExtRequest((method, params) => {
|
||||
if (method === "cursor/list_available_models") {
|
||||
return Effect.succeed({
|
||||
models: availableModels(),
|
||||
});
|
||||
}
|
||||
|
||||
if (method !== "session/mode/set") {
|
||||
return Effect.fail(AcpError.AcpRequestError.methodNotFound(method));
|
||||
}
|
||||
|
||||
@@ -471,7 +471,7 @@ describe("discoverCursorModelsViaAcp", () => {
|
||||
});
|
||||
|
||||
describe("discoverCursorModelCapabilitiesViaAcp", () => {
|
||||
it("closes all ACP probe runtimes after capability enrichment completes", async () => {
|
||||
it("discovers model capabilities through Cursor's list_available_models extension method", async () => {
|
||||
const tempDir = await mkdtemp(path.join(os.tmpdir(), "cursor-capabilities-exit-log-"));
|
||||
const exitLogPath = path.join(tempDir, "exit.log");
|
||||
const wrapperPath = await makeMockAgentWrapper({
|
||||
@@ -507,9 +507,26 @@ describe("discoverCursorModelCapabilitiesViaAcp", () => {
|
||||
"gpt-5.4",
|
||||
"claude-opus-4-6",
|
||||
]);
|
||||
expect(models.find((model) => model.slug === "gpt-5.4")?.capabilities).toEqual(
|
||||
createModelCapabilities({
|
||||
optionDescriptors: [
|
||||
selectDescriptor("reasoning", "Reasoning", [
|
||||
{ id: "low", label: "Low" },
|
||||
{ id: "medium", label: "Medium", isDefault: true },
|
||||
{ id: "high", label: "High" },
|
||||
{ id: "xhigh", label: "Extra High" },
|
||||
]),
|
||||
selectDescriptor("contextWindow", "Context", [
|
||||
{ id: "272k", label: "272K", isDefault: true },
|
||||
{ id: "1m", label: "1M" },
|
||||
]),
|
||||
booleanDescriptor("fastMode", "Fast", false),
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
const exitLog = await waitForFileContent(exitLogPath);
|
||||
expect(exitLog.match(/SIGTERM/g)?.length ?? 0).toBe(4);
|
||||
expect(exitLog.match(/SIGTERM/g)?.length ?? 0).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -46,8 +46,6 @@ const EMPTY_CAPABILITIES: ModelCapabilities = createModelCapabilities({
|
||||
});
|
||||
|
||||
const CURSOR_ACP_MODEL_DISCOVERY_TIMEOUT_MS = 15_000;
|
||||
const CURSOR_ACP_MODEL_CAPABILITY_TIMEOUT = "4 seconds";
|
||||
const CURSOR_ACP_MODEL_DISCOVERY_CONCURRENCY = 4;
|
||||
const CURSOR_REFRESH_INTERVAL = "1 hour";
|
||||
const CURSOR_PARAMETERIZED_MODEL_PICKER_MIN_VERSION_DATE = 2026_04_08;
|
||||
export const CURSOR_PARAMETERIZED_MODEL_PICKER_CAPABILITIES = {
|
||||
@@ -104,6 +102,16 @@ interface CursorAcpDiscoveredModel {
|
||||
readonly capabilities: ModelCapabilities;
|
||||
}
|
||||
|
||||
interface CursorAcpAvailableModel {
|
||||
readonly value?: unknown;
|
||||
readonly name?: unknown;
|
||||
readonly configOptions?: unknown;
|
||||
}
|
||||
|
||||
interface CursorAcpListAvailableModelsResponse {
|
||||
readonly models?: unknown;
|
||||
}
|
||||
|
||||
function flattenSessionConfigSelectOptions(
|
||||
configOption: EffectAcpSchema.SessionConfigOption | undefined,
|
||||
): ReadonlyArray<CursorSessionSelectOption> {
|
||||
@@ -392,6 +400,41 @@ export function buildCursorDiscoveredModelsFromConfigOptions(
|
||||
);
|
||||
}
|
||||
|
||||
function buildCursorDiscoveredModelsFromAvailableModelsResponse(
|
||||
response: unknown,
|
||||
): ReadonlyArray<ServerProviderModel> {
|
||||
const models = (response as CursorAcpListAvailableModelsResponse | null | undefined)?.models;
|
||||
if (!Array.isArray(models)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return buildCursorDiscoveredModels(
|
||||
models.flatMap((entry) => {
|
||||
if (!entry || typeof entry !== "object") {
|
||||
return [];
|
||||
}
|
||||
|
||||
const model = entry as CursorAcpAvailableModel;
|
||||
const slug = typeof model.value === "string" ? model.value.trim() : "";
|
||||
const name = typeof model.name === "string" ? model.name.trim() : "";
|
||||
if (!slug || !name) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const configOptions = Array.isArray(model.configOptions)
|
||||
? (model.configOptions as ReadonlyArray<EffectAcpSchema.SessionConfigOption>)
|
||||
: [];
|
||||
return [
|
||||
{
|
||||
slug,
|
||||
name,
|
||||
capabilities: buildCursorCapabilitiesFromConfigOptions(configOptions),
|
||||
},
|
||||
];
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const makeCursorAcpProbeRuntime = (cursorSettings: CursorSettings) =>
|
||||
Effect.gen(function* () {
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
@@ -525,117 +568,34 @@ export function resolveCursorAcpConfigUpdates(
|
||||
return updates;
|
||||
}
|
||||
|
||||
export const discoverCursorModelsViaAcp = (cursorSettings: CursorSettings) =>
|
||||
const discoverCursorModelsViaListAvailableModels = (cursorSettings: CursorSettings) =>
|
||||
withCursorAcpProbeRuntime(cursorSettings, (acp) =>
|
||||
Effect.map(acp.start(), (started) =>
|
||||
buildCursorDiscoveredModelsFromConfigOptions(started.sessionSetupResult.configOptions ?? []),
|
||||
Effect.gen(function* () {
|
||||
yield* acp.start();
|
||||
const response = yield* acp.request("cursor/list_available_models", {});
|
||||
return buildCursorDiscoveredModelsFromAvailableModelsResponse(response);
|
||||
}),
|
||||
);
|
||||
|
||||
export const discoverCursorModelsViaAcp = (cursorSettings: CursorSettings) =>
|
||||
discoverCursorModelsViaListAvailableModels(cursorSettings).pipe(
|
||||
Effect.catchCause(() =>
|
||||
withCursorAcpProbeRuntime(cursorSettings, (acp) =>
|
||||
Effect.map(acp.start(), (started) =>
|
||||
buildCursorDiscoveredModelsFromConfigOptions(
|
||||
started.sessionSetupResult.configOptions ?? [],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
export const discoverCursorModelCapabilitiesViaAcp = (
|
||||
cursorSettings: CursorSettings,
|
||||
existingModels: ReadonlyArray<ServerProviderModel>,
|
||||
_existingModels: ReadonlyArray<ServerProviderModel>,
|
||||
) =>
|
||||
withCursorAcpProbeRuntime(cursorSettings, (acp) =>
|
||||
Effect.gen(function* () {
|
||||
const started = yield* acp.start();
|
||||
const initialConfigOptions = started.sessionSetupResult.configOptions ?? [];
|
||||
const modelOption = findCursorModelConfigOption(initialConfigOptions);
|
||||
const modelChoices = flattenSessionConfigSelectOptions(modelOption);
|
||||
if (!modelOption || modelChoices.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const currentModelValue =
|
||||
modelOption.type === "select" ? modelOption.currentValue?.trim() || undefined : undefined;
|
||||
const capabilitiesBySlug = new Map<string, ModelCapabilities>();
|
||||
if (currentModelValue) {
|
||||
capabilitiesBySlug.set(
|
||||
currentModelValue,
|
||||
buildCursorCapabilitiesFromConfigOptions(initialConfigOptions),
|
||||
);
|
||||
}
|
||||
|
||||
const targetModelSlugs = new Set(
|
||||
existingModels
|
||||
.filter((model) => !model.isCustom && !hasCursorModelCapabilities(model))
|
||||
.map((model) => model.slug),
|
||||
);
|
||||
if (targetModelSlugs.size === 0) {
|
||||
return buildCursorDiscoveredModels(
|
||||
modelChoices.map((modelChoice) => ({
|
||||
slug: modelChoice.value.trim(),
|
||||
name: modelChoice.name.trim(),
|
||||
capabilities: capabilitiesBySlug.get(modelChoice.value.trim()) ?? EMPTY_CAPABILITIES,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
const probedCapabilities = yield* Effect.forEach(
|
||||
modelChoices,
|
||||
(modelChoice) => {
|
||||
const modelSlug = modelChoice.value.trim();
|
||||
if (!modelSlug || !targetModelSlugs.has(modelSlug) || capabilitiesBySlug.has(modelSlug)) {
|
||||
return Effect.void.pipe(
|
||||
Effect.as<readonly [string, ModelCapabilities] | undefined>(undefined),
|
||||
);
|
||||
}
|
||||
|
||||
return withCursorAcpProbeRuntime(cursorSettings, (probeAcp) =>
|
||||
Effect.gen(function* () {
|
||||
const probeStarted = yield* probeAcp.start();
|
||||
const probeConfigOptions = probeStarted.sessionSetupResult.configOptions ?? [];
|
||||
const probeModelOption = findCursorModelConfigOption(probeConfigOptions);
|
||||
const probeCurrentModelValue =
|
||||
probeModelOption?.type === "select"
|
||||
? probeModelOption.currentValue?.trim() || undefined
|
||||
: undefined;
|
||||
yield* Effect.annotateCurrentSpan({
|
||||
"cursor.acp.model.value": modelSlug,
|
||||
"cursor.acp.model.currentValue": probeCurrentModelValue,
|
||||
"cursor.acp.config_option_id": probeModelOption?.id ?? modelOption.id,
|
||||
});
|
||||
const nextConfigOptions =
|
||||
probeCurrentModelValue === modelSlug
|
||||
? probeConfigOptions
|
||||
: yield* probeAcp
|
||||
.setConfigOption(probeModelOption?.id ?? modelOption.id, modelSlug)
|
||||
.pipe(Effect.map((response) => response.configOptions ?? probeConfigOptions));
|
||||
return [
|
||||
modelSlug,
|
||||
buildCursorCapabilitiesFromConfigOptions(nextConfigOptions),
|
||||
] as const;
|
||||
}),
|
||||
).pipe(
|
||||
Effect.timeout(CURSOR_ACP_MODEL_CAPABILITY_TIMEOUT),
|
||||
Effect.retry({ times: 3 }),
|
||||
Effect.withSpan("cursor-acp-model-capability-probe"),
|
||||
Effect.catchCause((cause) =>
|
||||
Effect.logWarning("Cursor ACP capability probe failed", {
|
||||
modelSlug,
|
||||
cause: Cause.pretty(cause),
|
||||
}),
|
||||
),
|
||||
);
|
||||
},
|
||||
{ concurrency: CURSOR_ACP_MODEL_DISCOVERY_CONCURRENCY },
|
||||
);
|
||||
|
||||
for (const entry of probedCapabilities) {
|
||||
if (!entry) {
|
||||
continue;
|
||||
}
|
||||
capabilitiesBySlug.set(entry[0], entry[1]);
|
||||
}
|
||||
|
||||
return buildCursorDiscoveredModels(
|
||||
modelChoices.map((modelChoice) => ({
|
||||
slug: modelChoice.value.trim(),
|
||||
name: modelChoice.name.trim(),
|
||||
capabilities: capabilitiesBySlug.get(modelChoice.value.trim()) ?? EMPTY_CAPABILITIES,
|
||||
})),
|
||||
);
|
||||
}).pipe(Effect.withSpan("cursor-acp-model-capability-discovery", {})),
|
||||
discoverCursorModelsViaListAvailableModels(cursorSettings).pipe(
|
||||
Effect.withSpan("cursor-acp-model-capability-discovery", {}),
|
||||
);
|
||||
|
||||
export function getCursorFallbackModels(
|
||||
|
||||
Reference in new issue
Block a user