source dump of claude code
at main 57 lines 2.0 kB view raw
1import { 2 type AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, 3 logEvent, 4} from '../services/analytics/index.js' 5import { saveGlobalConfig } from '../utils/config.js' 6import { isLegacyModelRemapEnabled } from '../utils/model/model.js' 7import { getAPIProvider } from '../utils/model/providers.js' 8import { 9 getSettingsForSource, 10 updateSettingsForSource, 11} from '../utils/settings/settings.js' 12 13/** 14 * Migrate first-party users off explicit Opus 4.0/4.1 model strings. 15 * 16 * The 'opus' alias already resolves to Opus 4.6 for 1P, so anyone still 17 * on an explicit 4.0/4.1 string pinned it in settings before 4.5 launched. 18 * parseUserSpecifiedModel now silently remaps these at runtime anyway — 19 * this migration cleans up the settings file so /model shows the right 20 * thing, and sets a timestamp so the REPL can show a one-time notification. 21 * 22 * Only touches userSettings. Legacy strings in project/local/policy settings 23 * are left alone (we can't/shouldn't rewrite those) and are still remapped at 24 * runtime by parseUserSpecifiedModel. Reading and writing the same source 25 * keeps this idempotent without a completion flag, and avoids silently 26 * promoting 'opus' to the global default for users who only pinned it in one 27 * project. 28 */ 29export function migrateLegacyOpusToCurrent(): void { 30 if (getAPIProvider() !== 'firstParty') { 31 return 32 } 33 34 if (!isLegacyModelRemapEnabled()) { 35 return 36 } 37 38 const model = getSettingsForSource('userSettings')?.model 39 if ( 40 model !== 'claude-opus-4-20250514' && 41 model !== 'claude-opus-4-1-20250805' && 42 model !== 'claude-opus-4-0' && 43 model !== 'claude-opus-4-1' 44 ) { 45 return 46 } 47 48 updateSettingsForSource('userSettings', { model: 'opus' }) 49 saveGlobalConfig(current => ({ 50 ...current, 51 legacyOpusMigrationTimestamp: Date.now(), 52 })) 53 logEvent('tengu_legacy_opus_migration', { 54 from_model: 55 model as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, 56 }) 57}