source dump of claude code
at main 43 lines 1.3 kB view raw
1import { logEvent } from '../services/analytics/index.js' 2import { 3 getDefaultMainLoopModelSetting, 4 isOpus1mMergeEnabled, 5 parseUserSpecifiedModel, 6} from '../utils/model/model.js' 7import { 8 getSettingsForSource, 9 updateSettingsForSource, 10} from '../utils/settings/settings.js' 11 12/** 13 * Migrate users with 'opus' pinned in their settings to 'opus[1m]' when they 14 * are eligible for the merged Opus 1M experience (Max/Team Premium on 1P). 15 * 16 * CLI invocations with --model opus are unaffected: that flag is a runtime 17 * override and does not touch userSettings, so it continues to use plain Opus. 18 * 19 * Pro subscribers are skipped — they retain separate Opus and Opus 1M options. 20 * 3P users are skipped — their model strings are full model IDs, not aliases. 21 * 22 * Idempotent: only writes if userSettings.model is exactly 'opus'. 23 */ 24export function migrateOpusToOpus1m(): void { 25 if (!isOpus1mMergeEnabled()) { 26 return 27 } 28 29 const model = getSettingsForSource('userSettings')?.model 30 if (model !== 'opus') { 31 return 32 } 33 34 const migrated = 'opus[1m]' 35 const modelToSet = 36 parseUserSpecifiedModel(migrated) === 37 parseUserSpecifiedModel(getDefaultMainLoopModelSetting()) 38 ? undefined 39 : migrated 40 updateSettingsForSource('userSettings', { model: modelToSet }) 41 42 logEvent('tengu_opus_to_opus1m_migration', {}) 43}