migrateLegacyOpusToCurrent.ts
migrations/migrateLegacyOpusToCurrent.ts
No strong subsystem tag
58
Lines
1974
Bytes
1
Exports
5
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with general runtime concerns. It contains 58 lines, 5 detected imports, and 1 detected exports.
Important relationships
- migrations/migrateAutoUpdatesToSettings.ts
- migrations/migrateBypassPermissionsAcceptedToSettings.ts
- migrations/migrateEnableAllProjectMcpServersToSettings.ts
- migrations/migrateFennecToOpus.ts
- migrations/migrateOpusToOpus1m.ts
- migrations/migrateReplBridgeEnabledToRemoteControlAtStartup.ts
- migrations/migrateSonnet1mToSonnet45.ts
- migrations/migrateSonnet45ToSonnet46.ts
Detected exports
migrateLegacyOpusToCurrent
Keywords
modelsettingsopusutilsusersettingsanalyticsmetadata_i_verified_this_is_not_code_or_filepathslogeventsaveglobalconfigislegacymodelremapenabledgetapiprovider
Detected imports
../services/analytics/index.js../utils/config.js../utils/model/model.js../utils/model/providers.js../utils/settings/settings.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
import {
type AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
logEvent,
} from '../services/analytics/index.js'
import { saveGlobalConfig } from '../utils/config.js'
import { isLegacyModelRemapEnabled } from '../utils/model/model.js'
import { getAPIProvider } from '../utils/model/providers.js'
import {
getSettingsForSource,
updateSettingsForSource,
} from '../utils/settings/settings.js'
/**
* Migrate first-party users off explicit Opus 4.0/4.1 model strings.
*
* The 'opus' alias already resolves to Opus 4.6 for 1P, so anyone still
* on an explicit 4.0/4.1 string pinned it in settings before 4.5 launched.
* parseUserSpecifiedModel now silently remaps these at runtime anyway —
* this migration cleans up the settings file so /model shows the right
* thing, and sets a timestamp so the REPL can show a one-time notification.
*
* Only touches userSettings. Legacy strings in project/local/policy settings
* are left alone (we can't/shouldn't rewrite those) and are still remapped at
* runtime by parseUserSpecifiedModel. Reading and writing the same source
* keeps this idempotent without a completion flag, and avoids silently
* promoting 'opus' to the global default for users who only pinned it in one
* project.
*/
export function migrateLegacyOpusToCurrent(): void {
if (getAPIProvider() !== 'firstParty') {
return
}
if (!isLegacyModelRemapEnabled()) {
return
}
const model = getSettingsForSource('userSettings')?.model
if (
model !== 'claude-opus-4-20250514' &&
model !== 'claude-opus-4-1-20250805' &&
model !== 'claude-opus-4-0' &&
model !== 'claude-opus-4-1'
) {
return
}
updateSettingsForSource('userSettings', { model: 'opus' })
saveGlobalConfig(current => ({
...current,
legacyOpusMigrationTimestamp: Date.now(),
}))
logEvent('tengu_legacy_opus_migration', {
from_model:
model as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
})
}