From 94387275516349ddba2fc04e319f31d660ba3ae6 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 3 Jun 2026 09:53:33 -0700 Subject: [PATCH] Remove Cursor background model enrichment --- .../src/provider/Drivers/CursorDriver.ts | 16 +-- .../provider/Layers/CursorProvider.test.ts | 101 +------------- .../src/provider/Layers/CursorProvider.ts | 126 ++---------------- 3 files changed, 18 insertions(+), 225 deletions(-) diff --git a/apps/server/src/provider/Drivers/CursorDriver.ts b/apps/server/src/provider/Drivers/CursorDriver.ts index 46347091b4..ba532864c4 100644 --- a/apps/server/src/provider/Drivers/CursorDriver.ts +++ b/apps/server/src/provider/Drivers/CursorDriver.ts @@ -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 = { 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( diff --git a/apps/server/src/provider/Layers/CursorProvider.test.ts b/apps/server/src/provider/Layers/CursorProvider.test.ts index f43ab04cee..c4fd6090ba 100644 --- a/apps/server/src/provider/Layers/CursorProvider.test.ts +++ b/apps/server/src/provider/Layers/CursorProvider.test.ts @@ -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 = [ - { 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 = [ - { 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( diff --git a/apps/server/src/provider/Layers/CursorProvider.ts b/apps/server/src/provider/Layers/CursorProvider.ts index 551825df3e..064fa8dfe3 100644 --- a/apps/server/src/provider/Layers/CursorProvider.ts +++ b/apps/server/src/provider/Layers/CursorProvider.ts @@ -367,50 +367,6 @@ function buildCursorDiscoveredModels( }); } -function hasCursorModelCapabilities(model: Pick): boolean { - return (model.capabilities?.optionDescriptors?.length ?? 0) > 0; -} - -export function mergeCursorDiscoveredModelCapabilities( - existingModels: ReadonlyArray, - discoveredModels: ReadonlyArray, -): ReadonlyArray { - const discoveredBySlug = new Map( - discoveredModels.filter((model) => !model.isCustom).map((model) => [model.slug, model]), - ); - const seen = new Set(); - const mergedModels: Array = []; - - 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 { @@ -604,19 +560,6 @@ export const discoverCursorModelsViaAcp = ( environment: NodeJS.ProcessEnv = process.env, ) => discoverCursorModelsViaListAvailableModels(cursorSettings, environment); -export const discoverCursorModelCapabilitiesViaAcp = ( - cursorSettings: CursorSettings, - existingModels: ReadonlyArray, - 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, ): ReadonlyArray { @@ -1147,36 +1090,30 @@ export const checkCursorProviderStatus = Effect.fn("checkCursorProviderStatus")( }); }); -export function hasUncapturedCursorModels(snapshot: Pick): 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; readonly stampIdentity?: (snapshot: ServerProvider) => ServerProvider; readonly httpClient: HttpClient.HttpClient; -}): Effect.Effect => { +}): Effect.Effect => { const { settings, snapshot, publishSnapshot } = input; const stampIdentity = input.stampIdentity ?? ((value) => value); - const enrichVersionAdvisory = enrichProviderSnapshotWithVersionAdvisory( - snapshot, - input.maintenanceCapabilities, - ).pipe( + if (!settings.enabled || snapshot.auth.status === "unauthenticated") { + return Effect.void; + } + + return enrichProviderSnapshotWithVersionAdvisory(snapshot, input.maintenanceCapabilities).pipe( Effect.provideService(HttpClient.HttpClient, input.httpClient), Effect.flatMap((enrichedSnapshot) => publishSnapshot(stampIdentity(enrichedSnapshot)).pipe(Effect.as(enrichedSnapshot)), @@ -1184,48 +1121,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), - ), - ); - }), - ); };