diff --git a/mobile/src/session/native-chat/input/MobileNativeChatSessionOptionRows.tsx b/mobile/src/session/native-chat/input/MobileNativeChatSessionOptionRows.tsx index 63c69893624..a924e30f56d 100644 --- a/mobile/src/session/native-chat/input/MobileNativeChatSessionOptionRows.tsx +++ b/mobile/src/session/native-chat/input/MobileNativeChatSessionOptionRows.tsx @@ -222,9 +222,9 @@ export function descriptorRowElements( /> ) // No search here: search-only aliases follow a More models toggle, as compact pickers show them. - const more = moreChoices ? choices.filter((choice) => choice.searchOnly) : [] + const more = moreChoices ? choices.filter((choice) => choice.legacy) : [] return [ - ...choices.filter((choice) => !choice.searchOnly).map(choiceRow), + ...choices.filter((choice) => !choice.legacy).map(choiceRow), ...(more.length > 0 && moreChoices ? [ (null) const [query, setQuery] = useState('') + const [legacy, setLegacy] = useState(false) + const searching = Boolean(query.trim()) + const legacyCount = choices.filter((choice) => choice.legacy).length return ( + {legacy && !searching ? ( + setLegacy(false)}> + + {t('agentPicker.legacyModels', 'Legacy models')} + + ) : null} {choices - .filter((choice) => !choice.searchOnly || query.trim()) + .filter( + (choice) => + searching || choice.value === currentValue || Boolean(choice.legacy) === legacy + ) .map((choice) => { const label = nativeChatSessionChoiceLabel(choice, say) const current = choice.value === currentValue @@ -105,6 +117,17 @@ export function NativeChatModelCombobox({ ) })} + {!legacy && !searching && legacyCount > 0 ? ( + setLegacy(true)}> + + {t('agentPicker.legacyModels', 'Legacy models')} + + {t('agentPicker.legacyModelCount', '{{total}} models', { total: legacyCount })} + + + + + ) : null} diff --git a/src/shared/agent-launch/picker/agent-launch-picker-catalog.ts b/src/shared/agent-launch/picker/agent-launch-picker-catalog.ts index a9a897a2ec0..5dbd5171872 100644 --- a/src/shared/agent-launch/picker/agent-launch-picker-catalog.ts +++ b/src/shared/agent-launch/picker/agent-launch-picker-catalog.ts @@ -17,6 +17,7 @@ import { } from '../permissions/tui-agent-permission-choice' import type { TuiAgent } from '../catalog/tui-agent' import type { AgentPickerEntry, AgentPickerModel, AgentPickerSurface } from './agent-launch-picker' +import { legacyAgentModelIds } from '../../legacy-agent-models' type ModelMenuEntry = Pick & Partial< @@ -142,13 +143,16 @@ export function agentPickerModels( ): AgentPickerModel[] { if (!agentPickerUsesComposerModelMenu(entry, surface)) { if (entry.catalog.origin !== 'unknown') { - return entry.catalog.models + return withLegacyModels(entry.agent, entry.catalog.models) } - return (getAgentSessionOptionLaunchCatalog(entry.agent)?.models ?? []).map( - agentPickerModelFromCatalogModel + return withLegacyModels( + entry.agent, + (getAgentSessionOptionLaunchCatalog(entry.agent)?.models ?? []).map( + agentPickerModelFromCatalogModel + ) ) } - return agentPickerModelMenu(entry, surface).rows + return withLegacyModels(entry.agent, agentPickerModelMenu(entry, surface).rows) } /** Terminal discovery is a separate change; these menus keep their existing catalog policy. */ @@ -170,3 +174,10 @@ export function agentPickerModelFromCatalogModel(model: CatalogModel): AgentPick ) } } + +function withLegacyModels(agent: TuiAgent, models: AgentPickerModel[]): AgentPickerModel[] { + const legacy = legacyAgentModelIds(agent, models) + return legacy.size + ? models.map((model) => (legacy.has(model.id) ? { ...model, isLegacy: true } : model)) + : models +} diff --git a/src/shared/agent-session/options/structured-agent-session-option-snapshot.ts b/src/shared/agent-session/options/structured-agent-session-option-snapshot.ts index 8262a3343fa..dbe0efbcc6d 100644 --- a/src/shared/agent-session/options/structured-agent-session-option-snapshot.ts +++ b/src/shared/agent-session/options/structured-agent-session-option-snapshot.ts @@ -215,6 +215,7 @@ function modelOptionSnapshot(state: StructuredAgentSessionOptionState): SessionO models.length === 0 ? [] : nativeChatSessionOptionDescriptors({ + agent: state.record.agent, catalog, models, mode: 'live', diff --git a/src/shared/legacy-agent-models.test.ts b/src/shared/legacy-agent-models.test.ts new file mode 100644 index 00000000000..aaaf43683c5 --- /dev/null +++ b/src/shared/legacy-agent-models.test.ts @@ -0,0 +1,40 @@ +import { describe, expect, it } from 'vitest' +import { legacyAgentModelIds } from './legacy-agent-models' + +type Row = { id: string; isDefault?: boolean; resolvedModel?: string } +const legacy = (agent: string, models: Row[]) => [...legacyAgentModelIds(agent, models)] + +describe('legacyAgentModelIds', () => { + it('folds Codex models superseded in their family or by a newer major line', () => { + const models: Row[] = [ + { id: 'gpt-6.1-sol' }, + { id: 'gpt-6-astra' }, + { id: 'gpt-6-sol' }, + { id: 'gpt-6-luna' }, + { id: 'gpt-5.6-sol' }, + { id: 'gpt-5.6-terra', isDefault: true }, + { id: 'gpt-daybreak-blue-latest' } + ] + expect(legacy('codex', models)).toEqual(['gpt-6-sol', 'gpt-5.6-sol']) + }) + + it('folds Claude aliases whose versioned model is listed', () => { + const live: Row[] = [ + { id: 'claude-fable-5', resolvedModel: 'claude-fable-5' }, + { id: 'fable', resolvedModel: 'claude-fable-5' }, + { id: 'opusplan', resolvedModel: 'claude-opus-5-5' } + ] + expect(legacy('claude', live)).toEqual(['fable']) + const saved: Row[] = [ + { id: 'claude-opus-5-5[1m]' }, + { id: 'opus[1m]' }, + { id: 'opus' }, + { id: 'sonnet' } + ] + expect(legacy('claude', saved)).toEqual(['opus[1m]']) + }) + + it('leaves other agents untouched', () => { + expect(legacy('grok', [{ id: 'grok-4.5' }, { id: 'grok-4.6' }])).toEqual([]) + }) +}) diff --git a/src/shared/legacy-agent-models.ts b/src/shared/legacy-agent-models.ts new file mode 100644 index 00000000000..981b030161d --- /dev/null +++ b/src/shared/legacy-agent-models.ts @@ -0,0 +1,77 @@ +type ListedModel = { id: string; resolvedModel?: string | null; isDefault?: boolean } + +const VERSIONED_MODEL_ID = /^([a-z]+)-(\d+(?:\.\d+)*)(?:-([a-z][a-z0-9-]*))?$/ +const CLAUDE_ALIAS_ID = /^([a-z]+)(\[1m\])?$/ +const CLAUDE_VERSIONED_ID = /^claude-([a-z]+)-\d[\d-]*(\[1m\])?$/ + +type VersionedModelId = { prefix: string; version: number[]; family: string } + +function versionedModelId(id: string): VersionedModelId | null { + const match = VERSIONED_MODEL_ID.exec(id) + return match + ? { prefix: match[1], version: match[2].split('.').map(Number), family: match[3] ?? '' } + : null +} + +function compareVersions(left: readonly number[], right: readonly number[]): number { + for (let index = 0; index < Math.max(left.length, right.length); index++) { + const difference = (left[index] ?? 0) - (right[index] ?? 0) + if (difference !== 0) { + return difference + } + } + return 0 +} + +// Superseded within its family (6-sol by 6.1-sol), or from an older major line than the newest listed. +function isSupersededCodexModel(id: string, models: readonly ListedModel[]): boolean { + const own = versionedModelId(id) + if (!own) { + return false + } + return models.some((row) => { + const other = versionedModelId(row.id) + if (!other || other.prefix !== own.prefix) { + return false + } + return other.family === own.family + ? compareVersions(other.version, own.version) > 0 + : other.version[0] > own.version[0] + }) +} + +// Proven by the row naming the versioned model it runs, or, where a saved list or older host +// dropped that, by a versioned row of the same family (opus beside claude-opus-5-5). +function isCoveredClaudeAlias(model: ListedModel, models: readonly ListedModel[]): boolean { + const resolved = model.resolvedModel + if (resolved && resolved !== model.id) { + return models.some((row) => row.id === resolved && row.resolvedModel === resolved) + } + const alias = CLAUDE_ALIAS_ID.exec(model.id) + return ( + !!alias && + models.some((row) => { + const versioned = CLAUDE_VERSIONED_ID.exec(row.id) + return !!versioned && versioned[1] === alias[1] && versioned[2] === alias[2] + }) + ) +} + +/** Rows every model picker folds under Legacy models; the default and unrecognized ids stay listed. */ +export function legacyAgentModelIds(agent: string, models: readonly ListedModel[]): Set { + const legacy = new Set() + if (agent !== 'claude' && agent !== 'codex') { + return legacy + } + for (const model of models) { + if ( + !model.isDefault && + (agent === 'claude' + ? isCoveredClaudeAlias(model, models) + : isSupersededCodexModel(model.id, models)) + ) { + legacy.add(model.id) + } + } + return legacy +} diff --git a/src/shared/model-alias-rows.ts b/src/shared/model-alias-rows.ts deleted file mode 100644 index c00bef31759..00000000000 --- a/src/shared/model-alias-rows.ts +++ /dev/null @@ -1,12 +0,0 @@ -type ListedRow = { id: string; resolvedModel?: string | null } - -/** An alias row whose versioned row the same list holds: reachable by search, not listed beside it. - * Only a row naming itself as the model it runs counts; a chat's stand-in row for its own id does not. */ -export function isCoveredModelAlias(model: ListedRow, models: readonly ListedRow[]): boolean { - const resolved = model.resolvedModel - return ( - !!resolved && - resolved !== model.id && - models.some((row) => row.id === resolved && row.resolvedModel === resolved) - ) -} diff --git a/src/shared/native-chat/input/native-chat-session-option-snapshot.ts b/src/shared/native-chat/input/native-chat-session-option-snapshot.ts index 3f5a8f9405b..537e86fa0ca 100644 --- a/src/shared/native-chat/input/native-chat-session-option-snapshot.ts +++ b/src/shared/native-chat/input/native-chat-session-option-snapshot.ts @@ -1,6 +1,6 @@ import { AGENT_CHAT_PERMISSION_MODE_OPTION_ID } from '../../agent-launch/permissions/agent-chat-permission-mode' import { labelFromModelId } from '../../model-id-label' -import { isCoveredModelAlias } from '../../model-alias-rows' +import { legacyAgentModelIds } from '../../legacy-agent-models' import type { AgentSessionOptionCatalog, CatalogMidSessionApply, @@ -215,6 +215,7 @@ export type NativeChatShownModel = { /** The model descriptor, then the controls that apply, each showing the chat's value for it. * Values and controls arrive apart, so a caller decides which model's controls apply. */ export function nativeChatSessionOptionDescriptors(args: { + agent: string catalog: AgentSessionOptionCatalog models: readonly CatalogModel[] mode: NativeChatSessionOptionMode @@ -225,16 +226,15 @@ export function nativeChatSessionOptionDescriptors(args: { values: Readonly> modelIsCliDefault: boolean }): SessionOptionDescriptor[] { - const { catalog, models, mode, modelLabel, liveTransport, model } = args + const { agent, catalog, models, mode, modelLabel, liveTransport, model } = args // Callers reconcile tracked models into choices first; the trigger must never show an unlisted selection. - // An alias whose versioned row is listed stays reachable by search, unless the chat is on it. - const modelChoices = models.map(({ id, label, description, resolvedModel }) => ({ + // Legacy rows fold away like the launch picker's, unless the chat is on one. + const legacy = legacyAgentModelIds(agent, models) + const modelChoices = models.map(({ id, label, description }) => ({ value: id, label, ...(description ? { description } : {}), - ...(id !== model.currentId && isCoveredModelAlias({ id, resolvedModel }, models) - ? { searchOnly: true as const } - : {}) + ...(id !== model.currentId && legacy.has(id) ? { legacy: true as const } : {}) })) const modelAction = actionForApply(catalog.modelApply, model.tracked, mode, liveTransport) const snapshot: SessionOptionDescriptor[] = [ @@ -289,6 +289,7 @@ export function buildNativeChatSessionOptionSnapshot(args: { const model = models.find((candidate) => candidate.id === effectiveModelId) return nativeChatSessionOptionDescriptors({ ...args, + agent: record.agent, model: { currentId: effectiveModelId, valueSource: record.model?.source ?? (defaultModelId ? 'default' : 'unknown'), diff --git a/src/shared/native-chat/input/native-chat-session-options.ts b/src/shared/native-chat/input/native-chat-session-options.ts index c2401e3bde4..9e7d165f250 100644 --- a/src/shared/native-chat/input/native-chat-session-options.ts +++ b/src/shared/native-chat/input/native-chat-session-options.ts @@ -6,8 +6,8 @@ export type SessionOptionSelectChoice = { value: string label: string description?: string - /** An alias of a listed versioned row: listed only for a matching search. */ - searchOnly?: true + /** Folded under Legacy models; a matching search still lists it. */ + legacy?: true } /** default describes catalog display, never running-agent evidence. dispatched is sent but unread and may be corrected by reports.