Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a86cdd225 | ||
|
|
9438727551 |
No files matched your search
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* CursorDriver — `ProviderDriver` for the Cursor Agent (`agent`) runtime.
|
||||
*
|
||||
* Cursor exposes an ACP-based CLI. The driver is still a plain value, but
|
||||
* its snapshot uses `makeManagedServerProvider`'s optional `enrichSnapshot`
|
||||
* hook to run the slow ACP model-capability probe in the background without
|
||||
* blocking the initial `ready`-state publish.
|
||||
* Cursor exposes an ACP-based CLI. Model catalog and capability refreshes
|
||||
* happen during the managed provider status check via Cursor's
|
||||
* `list_available_models` extension method.
|
||||
*
|
||||
* Text generation is supported via the ACP runtime — `makeCursorTextGeneration`
|
||||
* drives `runtime.prompt` with a structured-output schema and collects the
|
||||
@@ -139,20 +138,17 @@ export const CursorDriver: ProviderDriver<CursorSettings, CursorDriverEnv> = {
|
||||
initialSnapshot: (settings) =>
|
||||
buildInitialCursorProviderSnapshot(settings).pipe(Effect.map(stampIdentity)),
|
||||
checkProvider,
|
||||
// Preserve the background ACP model-capability probe that used to
|
||||
// live on `CursorProviderLive`. Only fires when the snapshot reports
|
||||
// an authenticated, enabled provider with at least one non-custom
|
||||
// model whose capabilities haven't been captured yet.
|
||||
// Model catalog and capabilities come exclusively from Cursor's
|
||||
// list_available_models extension method during provider checks.
|
||||
enrichSnapshot: ({ settings, snapshot: currentSnapshot, publishSnapshot }) =>
|
||||
enrichCursorSnapshot({
|
||||
settings,
|
||||
environment: processEnv,
|
||||
snapshot: currentSnapshot,
|
||||
maintenanceCapabilities,
|
||||
publishSnapshot,
|
||||
stampIdentity,
|
||||
httpClient,
|
||||
}).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner)),
|
||||
}),
|
||||
refreshInterval: SNAPSHOT_REFRESH_INTERVAL,
|
||||
}).pipe(
|
||||
Effect.mapError(
|
||||
|
||||
@@ -6,18 +6,16 @@ import * as FileSystem from "effect/FileSystem";
|
||||
import * as Path from "effect/Path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type * as EffectAcpSchema from "effect-acp/schema";
|
||||
import type { CursorSettings, ServerProviderModel } from "@t3tools/contracts";
|
||||
import type { CursorSettings } from "@t3tools/contracts";
|
||||
import { createModelCapabilities } from "@t3tools/shared/model";
|
||||
|
||||
import {
|
||||
buildCursorProviderSnapshot,
|
||||
buildCursorCapabilitiesFromConfigOptions,
|
||||
checkCursorProviderStatus,
|
||||
discoverCursorModelCapabilitiesViaAcp,
|
||||
discoverCursorModelsViaAcp,
|
||||
getCursorFallbackModels,
|
||||
getCursorParameterizedModelPickerUnsupportedMessage,
|
||||
mergeCursorDiscoveredModelCapabilities,
|
||||
parseCursorAboutOutput,
|
||||
parseCursorCliConfigChannel,
|
||||
parseCursorVersionDate,
|
||||
@@ -302,8 +300,6 @@ const baseCursorSettings: CursorSettings = {
|
||||
customModels: [],
|
||||
};
|
||||
|
||||
const emptyCapabilities = createModelCapabilities({ optionDescriptors: [] });
|
||||
|
||||
describe("getCursorFallbackModels", () => {
|
||||
it("does not publish any built-in cursor models before ACP discovery", () => {
|
||||
expect(
|
||||
@@ -489,101 +485,6 @@ describe("discoverCursorModelsViaAcp", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("discoverCursorModelCapabilitiesViaAcp", () => {
|
||||
it("discovers model capabilities through Cursor's list_available_models extension method", async () => {
|
||||
const { exitLogPath, wrapperPath } = await runNode(
|
||||
makeExitLogFixture("cursor-capabilities-exit-log-"),
|
||||
);
|
||||
const existingModels: ReadonlyArray<ServerProviderModel> = [
|
||||
{ slug: "default", name: "Auto", isCustom: false, capabilities: emptyCapabilities },
|
||||
{ slug: "composer-2", name: "Composer 2", isCustom: false, capabilities: emptyCapabilities },
|
||||
{ slug: "gpt-5.4", name: "GPT-5.4", isCustom: false, capabilities: emptyCapabilities },
|
||||
{
|
||||
slug: "claude-opus-4-6",
|
||||
name: "Opus 4.6",
|
||||
isCustom: false,
|
||||
capabilities: emptyCapabilities,
|
||||
},
|
||||
];
|
||||
|
||||
const models = await Effect.runPromise(
|
||||
discoverCursorModelCapabilitiesViaAcp(
|
||||
{
|
||||
enabled: true,
|
||||
binaryPath: wrapperPath,
|
||||
apiEndpoint: "",
|
||||
customModels: [],
|
||||
},
|
||||
existingModels,
|
||||
).pipe(Effect.provide(NodeServices.layer)),
|
||||
);
|
||||
|
||||
expect(models.map((model) => model.slug)).toEqual([
|
||||
"default",
|
||||
"composer-2",
|
||||
"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 runNode(waitForFileContent(exitLogPath));
|
||||
expect(exitLog.match(/SIGTERM/g)?.length ?? 0).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("mergeCursorDiscoveredModelCapabilities", () => {
|
||||
it("keeps existing built-in models when the discovered response is partial", () => {
|
||||
const reasoningCapabilities = createModelCapabilities({
|
||||
optionDescriptors: [
|
||||
selectDescriptor("reasoning", "Reasoning", [
|
||||
{ id: "low", label: "Low" },
|
||||
{ id: "high", label: "High", isDefault: true },
|
||||
]),
|
||||
],
|
||||
});
|
||||
const existingModels: ReadonlyArray<ServerProviderModel> = [
|
||||
{ slug: "default", name: "Auto", isCustom: false, capabilities: emptyCapabilities },
|
||||
{ slug: "composer-2", name: "Composer 2", isCustom: false, capabilities: emptyCapabilities },
|
||||
{
|
||||
slug: "custom-local",
|
||||
name: "custom-local",
|
||||
isCustom: true,
|
||||
capabilities: emptyCapabilities,
|
||||
},
|
||||
];
|
||||
|
||||
const merged = mergeCursorDiscoveredModelCapabilities(existingModels, [
|
||||
{
|
||||
slug: "composer-2",
|
||||
name: "Composer 2",
|
||||
isCustom: false,
|
||||
capabilities: reasoningCapabilities,
|
||||
},
|
||||
]);
|
||||
|
||||
expect(merged.map((model) => model.slug)).toEqual(["default", "composer-2"]);
|
||||
expect(merged.find((model) => model.slug === "composer-2")?.capabilities).toEqual(
|
||||
reasoningCapabilities,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseCursorAboutOutput", () => {
|
||||
it("parses json about output and forwards subscription metadata", () => {
|
||||
expect(
|
||||
|
||||
@@ -367,50 +367,6 @@ function buildCursorDiscoveredModels(
|
||||
});
|
||||
}
|
||||
|
||||
function hasCursorModelCapabilities(model: Pick<ServerProviderModel, "capabilities">): boolean {
|
||||
return (model.capabilities?.optionDescriptors?.length ?? 0) > 0;
|
||||
}
|
||||
|
||||
export function mergeCursorDiscoveredModelCapabilities(
|
||||
existingModels: ReadonlyArray<ServerProviderModel>,
|
||||
discoveredModels: ReadonlyArray<ServerProviderModel>,
|
||||
): ReadonlyArray<ServerProviderModel> {
|
||||
const discoveredBySlug = new Map(
|
||||
discoveredModels.filter((model) => !model.isCustom).map((model) => [model.slug, model]),
|
||||
);
|
||||
const seen = new Set<string>();
|
||||
const mergedModels: Array<ServerProviderModel> = [];
|
||||
|
||||
for (const model of existingModels) {
|
||||
if (model.isCustom || seen.has(model.slug)) {
|
||||
continue;
|
||||
}
|
||||
seen.add(model.slug);
|
||||
const discovered = discoveredBySlug.get(model.slug);
|
||||
mergedModels.push(
|
||||
discovered
|
||||
? {
|
||||
...model,
|
||||
name: discovered.name || model.name,
|
||||
capabilities: hasCursorModelCapabilities(discovered)
|
||||
? discovered.capabilities
|
||||
: model.capabilities,
|
||||
}
|
||||
: model,
|
||||
);
|
||||
}
|
||||
|
||||
for (const model of discoveredModels) {
|
||||
if (model.isCustom || seen.has(model.slug)) {
|
||||
continue;
|
||||
}
|
||||
seen.add(model.slug);
|
||||
mergedModels.push(model);
|
||||
}
|
||||
|
||||
return mergedModels;
|
||||
}
|
||||
|
||||
function buildCursorDiscoveredModelsFromAvailableModelsResponse(
|
||||
response: typeof CursorListAvailableModelsResponse.Type,
|
||||
): ReadonlyArray<ServerProviderModel> {
|
||||
@@ -604,19 +560,6 @@ export const discoverCursorModelsViaAcp = (
|
||||
environment: NodeJS.ProcessEnv = process.env,
|
||||
) => discoverCursorModelsViaListAvailableModels(cursorSettings, environment);
|
||||
|
||||
export const discoverCursorModelCapabilitiesViaAcp = (
|
||||
cursorSettings: CursorSettings,
|
||||
existingModels: ReadonlyArray<ServerProviderModel>,
|
||||
environment: NodeJS.ProcessEnv = process.env,
|
||||
) =>
|
||||
discoverCursorModelsViaListAvailableModels(cursorSettings, environment).pipe(
|
||||
Effect.withSpan("cursor-acp-model-capability-discovery", {
|
||||
attributes: {
|
||||
"cursor.acp.existing_model_count": existingModels.length,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
export function getCursorFallbackModels(
|
||||
cursorSettings: Pick<CursorSettings, "customModels">,
|
||||
): ReadonlyArray<ServerProviderModel> {
|
||||
@@ -1147,36 +1090,26 @@ export const checkCursorProviderStatus = Effect.fn("checkCursorProviderStatus")(
|
||||
});
|
||||
});
|
||||
|
||||
export function hasUncapturedCursorModels(snapshot: Pick<ServerProvider, "models">): boolean {
|
||||
return snapshot.models.some((model) => !model.isCustom && !hasCursorModelCapabilities(model));
|
||||
}
|
||||
|
||||
/**
|
||||
* Background capability enrichment for a Cursor snapshot.
|
||||
* Background maintenance enrichment for a Cursor snapshot.
|
||||
*
|
||||
* Used by `CursorDriver` as the `makeManagedServerProvider.enrichSnapshot`
|
||||
* hook: runs the slow ACP per-model capability probe, and republishes the
|
||||
* snapshot through `publishSnapshot` when new capabilities arrive. Skips
|
||||
* the probe when the provider is disabled, unauthenticated, or has no
|
||||
* uncaptured models. Keeps `EMPTY_CAPABILITIES` and the `PROVIDER` literal
|
||||
* private to this module.
|
||||
* hook: republishes update/version advisory metadata without performing any
|
||||
* model or capability discovery. Cursor model data comes exclusively from
|
||||
* `cursor/list_available_models` during provider status checks.
|
||||
*/
|
||||
export const enrichCursorSnapshot = (input: {
|
||||
readonly settings: CursorSettings;
|
||||
readonly environment?: NodeJS.ProcessEnv;
|
||||
readonly snapshot: ServerProvider;
|
||||
readonly maintenanceCapabilities: ProviderMaintenanceCapabilities;
|
||||
readonly publishSnapshot: (snapshot: ServerProvider) => Effect.Effect<void>;
|
||||
readonly stampIdentity?: (snapshot: ServerProvider) => ServerProvider;
|
||||
readonly httpClient: HttpClient.HttpClient;
|
||||
}): Effect.Effect<void, never, ChildProcessSpawner.ChildProcessSpawner> => {
|
||||
const { settings, snapshot, publishSnapshot } = input;
|
||||
}): Effect.Effect<void> => {
|
||||
const { snapshot, publishSnapshot } = input;
|
||||
const stampIdentity = input.stampIdentity ?? ((value) => value);
|
||||
|
||||
const enrichVersionAdvisory = enrichProviderSnapshotWithVersionAdvisory(
|
||||
snapshot,
|
||||
input.maintenanceCapabilities,
|
||||
).pipe(
|
||||
return enrichProviderSnapshotWithVersionAdvisory(snapshot, input.maintenanceCapabilities).pipe(
|
||||
Effect.provideService(HttpClient.HttpClient, input.httpClient),
|
||||
Effect.flatMap((enrichedSnapshot) =>
|
||||
publishSnapshot(stampIdentity(enrichedSnapshot)).pipe(Effect.as(enrichedSnapshot)),
|
||||
@@ -1184,48 +1117,7 @@ export const enrichCursorSnapshot = (input: {
|
||||
Effect.catchCause((cause) =>
|
||||
Effect.logWarning("Cursor version advisory enrichment failed", {
|
||||
cause: Cause.pretty(cause),
|
||||
}).pipe(Effect.as(snapshot)),
|
||||
}).pipe(Effect.asVoid),
|
||||
),
|
||||
);
|
||||
|
||||
return enrichVersionAdvisory.pipe(
|
||||
Effect.flatMap((baseSnapshot) => {
|
||||
if (
|
||||
!settings.enabled ||
|
||||
baseSnapshot.auth.status === "unauthenticated" ||
|
||||
!hasUncapturedCursorModels(baseSnapshot)
|
||||
) {
|
||||
return Effect.void;
|
||||
}
|
||||
|
||||
return discoverCursorModelCapabilitiesViaAcp(
|
||||
settings,
|
||||
baseSnapshot.models,
|
||||
input.environment,
|
||||
).pipe(
|
||||
Effect.flatMap((discoveredModels) => {
|
||||
if (discoveredModels.length === 0) {
|
||||
return Effect.void;
|
||||
}
|
||||
return publishSnapshot(
|
||||
stampIdentity({
|
||||
...baseSnapshot,
|
||||
models: providerModelsFromSettings(
|
||||
mergeCursorDiscoveredModelCapabilities(baseSnapshot.models, discoveredModels),
|
||||
PROVIDER,
|
||||
settings.customModels,
|
||||
EMPTY_CAPABILITIES,
|
||||
),
|
||||
}),
|
||||
);
|
||||
}),
|
||||
Effect.catchCause((cause) =>
|
||||
Effect.logWarning("Cursor ACP background capability enrichment failed", {
|
||||
models: baseSnapshot.models.map((model) => model.slug),
|
||||
cause: Cause.pretty(cause),
|
||||
}).pipe(Effect.asVoid),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user