fix: startup fallback overwrites user's default model with Sonnet (#29)
This commit is contained in:
parent
f214912e66
commit
afa1fffaac
2 changed files with 8 additions and 6 deletions
11
src/cli.ts
11
src/cli.ts
|
|
@ -17,9 +17,10 @@ await runWizardIfNeeded(authStorage)
|
|||
const modelRegistry = new ModelRegistry(authStorage)
|
||||
const settingsManager = SettingsManager.create(agentDir)
|
||||
|
||||
// Always ensure defaults: anthropic/claude-sonnet-4-6, thinking off.
|
||||
// Validates on every startup — catches stale settings from prior installs
|
||||
// Validate configured model on startup — catches stale settings from prior installs
|
||||
// (e.g. grok-2 which no longer exists) and fresh installs with no settings.
|
||||
// Only resets the default when the configured model no longer exists in the registry;
|
||||
// never overwrites a valid user choice.
|
||||
const configuredProvider = settingsManager.getDefaultProvider()
|
||||
const configuredModel = settingsManager.getDefaultModel()
|
||||
const allModels = modelRegistry.getAll()
|
||||
|
|
@ -27,10 +28,10 @@ const configuredExists = configuredProvider && configuredModel &&
|
|||
allModels.some((m) => m.provider === configuredProvider && m.id === configuredModel)
|
||||
|
||||
if (!configuredModel || !configuredExists) {
|
||||
// Preferred default: anthropic/claude-sonnet-4-6
|
||||
// Fallback: pick the best available Anthropic model
|
||||
const preferred =
|
||||
allModels.find((m) => m.provider === 'anthropic' && m.id === 'claude-sonnet-4-6') ||
|
||||
allModels.find((m) => m.provider === 'anthropic' && m.id.includes('sonnet')) ||
|
||||
allModels.find((m) => m.provider === 'anthropic' && m.id === 'claude-opus-4-6') ||
|
||||
allModels.find((m) => m.provider === 'anthropic' && m.id.includes('opus')) ||
|
||||
allModels.find((m) => m.provider === 'anthropic')
|
||||
if (preferred) {
|
||||
settingsManager.setDefaultModelAndProvider(preferred.provider, preferred.id)
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ export function loadStoredEnvKeys(authStorage: AuthStorage): void {
|
|||
for (const [provider, envVar] of providers) {
|
||||
if (!process.env[envVar]) {
|
||||
const cred = authStorage.get(provider)
|
||||
if (cred?.type === 'api_key') {
|
||||
if (cred?.type === 'api_key' && cred.key) {
|
||||
process.env[envVar] = cred.key as string
|
||||
}
|
||||
}
|
||||
|
|
@ -167,6 +167,7 @@ export async function runWizardIfNeeded(authStorage: AuthStorage): Promise<void>
|
|||
process.stdout.write(` ${green}✓${reset} ${key.label} saved\n\n`)
|
||||
savedCount++
|
||||
} else {
|
||||
authStorage.set(key.provider, { type: 'api_key', key: '' })
|
||||
process.stdout.write(` ${dim}↷ ${key.label} skipped${reset}\n\n`)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue