From 769bef793050a496cc191ac6d577b63751bf4a1c Mon Sep 17 00:00:00 2001 From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com> Date: Wed, 11 Nov 2026 19:10:46 +0000 Subject: [PATCH] fix(cursor): list Cursor's CLI models in the Settings default-model picker (#41219) --- .../AgentLaunchChoiceEditor.test.tsx | 34 ++++++++++++++++--- .../use-agent-settings-model-catalog.ts | 25 +++++++++++--- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/renderer/src/components/agent/launch-settings/AgentLaunchChoiceEditor.test.tsx b/src/renderer/src/components/agent/launch-settings/AgentLaunchChoiceEditor.test.tsx index 646469bf414..f2ed4781e13 100644 --- a/src/renderer/src/components/agent/launch-settings/AgentLaunchChoiceEditor.test.tsx +++ b/src/renderer/src/components/agent/launch-settings/AgentLaunchChoiceEditor.test.tsx @@ -5,14 +5,19 @@ import { getDefaultSettings } from '../../../../../shared/constants' import { resetHostModelCatalogSnapshotsForTests } from '@/runtime/native-chat/model-catalogs/host-model-catalog-snapshots' import { useAppStore } from '@/store' import { TooltipProvider } from '../../ui/tooltip' +import type { RuntimeClientTarget } from '../../../../../shared/runtime-client-target' import { AgentLaunchChoiceEditor } from './AgentLaunchChoiceEditor' const call = vi.hoisted(() => vi.fn()) +const discover = vi.hoisted(() => vi.fn()) const menus = vi.hoisted(() => new Map()) vi.mock('@/runtime/native-chat/requests/structured-agent-session-call', () => ({ callStructuredAgentSession: call })) +vi.mock('@/runtime/source-control/git/runtime-git-generation-client', () => ({ + discoverRuntimeCommitMessageModels: discover +})) vi.mock('./AgentChoiceMenu', () => ({ AgentChoiceMenu: ({ label, @@ -49,16 +54,20 @@ const LISTED = { const HOST = { kind: 'environment', environmentId: 'env-1' } as const -function renderEditor(model?: string): void { +function renderEditor( + model?: string, + agent: 'codex' | 'cursor' = 'codex', + catalogTarget: RuntimeClientTarget = HOST +): void { render( {}} /> @@ -70,6 +79,7 @@ describe('AgentLaunchChoiceEditor model list', () => { beforeEach(() => { call.mockReset() + discover.mockReset() menus.clear() resetHostModelCatalogSnapshotsForTests() }) @@ -99,4 +109,20 @@ describe('AgentLaunchChoiceEditor model list', () => { await act(async () => answerOlder(LISTED)) expect(menus.get('Model')).toEqual(['__agent_default__', 'gpt-wrapped']) }) + + it("lists the local Cursor CLI's models", async () => { + // The host's structured catalog has no Cursor listing; Settings must not settle for it. + call.mockResolvedValue({ origin: 'unknown' }) + discover.mockResolvedValueOnce({ + success: true, + catalogOrigin: 'probe', + models: [ + { id: 'auto', label: 'Auto', isDefault: true }, + { id: 'claude-opus-5-5-max', label: 'Claude Opus 5.5 Max' } + ] + }) + useAppStore.setState({ settings: getDefaultSettings('') }) + renderEditor(undefined, 'cursor', { kind: 'local' }) + await waitFor(() => expect(menus.get('Model')).toContain('claude-opus-5-5-max')) + }) }) diff --git a/src/renderer/src/components/agent/launch-settings/use-agent-settings-model-catalog.ts b/src/renderer/src/components/agent/launch-settings/use-agent-settings-model-catalog.ts index 8965a1f4a95..dc38bb37afe 100644 --- a/src/renderer/src/components/agent/launch-settings/use-agent-settings-model-catalog.ts +++ b/src/renderer/src/components/agent/launch-settings/use-agent-settings-model-catalog.ts @@ -17,6 +17,11 @@ import { subscribeHostAgentLaunchSettings } from '@/runtime/agent-launch-setting import { callStructuredAgentSession } from '@/runtime/native-chat/requests/structured-agent-session-call' import { structuredAgentSessionHostKey } from '@/runtime/native-chat/host-capabilities/structured-agent-session-host-capability' import { useAppStore } from '@/store' +import { + agentPickerListsCliModels, + readAgentPickerCliModelCatalog +} from '../agent-launch-picker-cli-model-catalog' +import { resolveWorktreeModelDiscoveryRuntime } from '../../native-chat/session/options/catalog/native-chat-session-option-discovery' const SETTINGS_LAUNCH = { newLaunch: true, seedsModel: true } @@ -65,14 +70,24 @@ export function useAgentSettingsModelCatalog( return } let stale = false + // Like the launch picker, an agent with no structured chat lists through this machine's CLI; + // a workspace-less read can't route that to another host, so other hosts keep the seed. + const cliRuntime = + isLocal && agentPickerListsCliModels({ agent }) + ? resolveWorktreeModelDiscoveryRuntime(useAppStore.getState(), null) + : null // Not recorded in the new-chat snapshot: an account answer there would drop newer workspace answers. // Old hosts refuse waitForListing, so wait only once the host says a listing is running. + const fetchCatalog = (wait: boolean): Promise => + cliRuntime + ? readAgentPickerCliModelCatalog(agent, cliRuntime) + : callStructuredAgentSession( + readTarget, + 'agentSession.modelCatalog', + wait ? { agent, waitForListing: true } : { agent } + ) const read = (wait: boolean): void => { - void callStructuredAgentSession( - readTarget, - 'agentSession.modelCatalog', - wait ? { agent, waitForListing: true } : { agent } - ) + void fetchCatalog(wait) .then((catalog) => { if (stale) { return