/ migrations / migrateReplBridgeEnabledToRemoteControlAtStartup.ts
migrateReplBridgeEnabledToRemoteControlAtStartup.ts
 1  import { saveGlobalConfig } from '../utils/config.js'
 2  
 3  /**
 4   * Migrate the `replBridgeEnabled` config key to `remoteControlAtStartup`.
 5   *
 6   * The old key was an implementation detail that leaked into user-facing config.
 7   * This migration copies the value to the new key and removes the old one.
 8   * Idempotent — only acts when the old key exists and the new one doesn't.
 9   */
10  export function migrateReplBridgeEnabledToRemoteControlAtStartup(): void {
11    saveGlobalConfig(prev => {
12      // The old key is no longer in the GlobalConfig type, so access it via
13      // an untyped cast. Only migrate if the old key exists and the new key
14      // hasn't been set yet.
15      const oldValue = (prev as Record<string, unknown>)['replBridgeEnabled']
16      if (oldValue === undefined) return prev
17      if (prev.remoteControlAtStartup !== undefined) return prev
18      const next = { ...prev, remoteControlAtStartup: Boolean(oldValue) }
19      delete (next as Record<string, unknown>)['replBridgeEnabled']
20      return next
21    })
22  }