/ migrations / migrateFennecToOpus.ts
migrateFennecToOpus.ts
 1  import {
 2    getSettingsForSource,
 3    updateSettingsForSource,
 4  } from '../utils/settings/settings.js'
 5  
 6  /**
 7   * Migrate users on removed fennec model aliases to their new Opus 4.6 aliases.
 8   * - fennec-latest → opus
 9   * - fennec-latest[1m] → opus[1m]
10   * - fennec-fast-latest → opus[1m] + fast mode
11   * - opus-4-5-fast → opus + fast mode
12   *
13   * Only touches userSettings. Reading and writing the same source keeps this
14   * idempotent without a completion flag. Fennec aliases in project/local/policy
15   * settings are left alone — we can't rewrite those, and reading merged
16   * settings here would cause infinite re-runs + silent global promotion.
17   */
18  export function migrateFennecToOpus(): void {
19    if (process.env.USER_TYPE !== 'ant') {
20      return
21    }
22  
23    const settings = getSettingsForSource('userSettings')
24  
25    const model = settings?.model
26    if (typeof model === 'string') {
27      if (model.startsWith('fennec-latest[1m]')) {
28        updateSettingsForSource('userSettings', {
29          model: 'opus[1m]',
30        })
31      } else if (model.startsWith('fennec-latest')) {
32        updateSettingsForSource('userSettings', {
33          model: 'opus',
34        })
35      } else if (
36        model.startsWith('fennec-fast-latest') ||
37        model.startsWith('opus-4-5-fast')
38      ) {
39        updateSettingsForSource('userSettings', {
40          model: 'opus[1m]',
41          fastMode: true,
42        })
43      }
44    }
45  }