fix(cursor): list Cursor's CLI models in the Settings default-model picker (#41219)

This commit is contained in:
Kelvin Amoaba
2026-11-11 19:10:46 +00:00
committed by GitHub
parent d46cf4b295
commit 769bef7930
2 changed files with 50 additions and 9 deletions
@@ -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<string, string[]>())
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(
<TooltipProvider>
<AgentLaunchChoiceEditor
agent="codex"
label="Codex"
agent={agent}
label={agent}
choices={model ? { model } : undefined}
userArgs=""
permission={undefined}
catalogTarget={HOST}
catalogTarget={catalogTarget}
save={async () => {}}
/>
</TooltipProvider>
@@ -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'))
})
})
@@ -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<AgentSessionModelCatalogResult> =>
cliRuntime
? readAgentPickerCliModelCatalog(agent, cliRuntime)
: callStructuredAgentSession<AgentSessionModelCatalogResult>(
readTarget,
'agentSession.modelCatalog',
wait ? { agent, waitForListing: true } : { agent }
)
const read = (wait: boolean): void => {
void callStructuredAgentSession<AgentSessionModelCatalogResult>(
readTarget,
'agentSession.modelCatalog',
wait ? { agent, waitForListing: true } : { agent }
)
void fetchCatalog(wait)
.then((catalog) => {
if (stale) {
return