( context: vscode.ExtensionContext, outputChannel: vscode.OutputChannel, )
| 14 | * TODO: Remove this migration code in September 2025 (6 months after implementation) |
| 15 | */ |
| 16 | export async function migrateSettings( |
| 17 | context: vscode.ExtensionContext, |
| 18 | outputChannel: vscode.OutputChannel, |
| 19 | ): Promise<void> { |
| 20 | // First, migrate commands from old defaults (security fix) |
| 21 | await migrateDefaultCommands(context, outputChannel) |
| 22 | // Legacy file names that need to be migrated to the new names in GlobalFileNames |
| 23 | const fileMigrations = [ |
| 24 | // custom_modes.json to custom_modes.yaml is handled separately below |
| 25 | { oldName: "cline_custom_modes.json", newName: deprecatedCustomModesJSONFilename }, |
| 26 | { oldName: "cline_mcp_settings.json", newName: GlobalFileNames.mcpSettings }, |
| 27 | ] |
| 28 | |
| 29 | try { |
| 30 | const settingsDir = await getSettingsDirectoryPath(context.globalStorageUri.fsPath) |
| 31 | |
| 32 | // Check if settings directory exists first |
| 33 | if (!(await fileExistsAtPath(settingsDir))) { |
| 34 | outputChannel.appendLine("No settings directory found, no migrations necessary") |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | // Process each file migration |
| 39 | try { |
| 40 | for (const migration of fileMigrations) { |
| 41 | const oldPath = path.join(settingsDir, migration.oldName) |
| 42 | const newPath = path.join(settingsDir, migration.newName) |
| 43 | |
| 44 | // Only migrate if old file exists and new file doesn't exist yet |
| 45 | // This ensures we don't overwrite any existing new files |
| 46 | const oldFileExists = await fileExistsAtPath(oldPath) |
| 47 | const newFileExists = await fileExistsAtPath(newPath) |
| 48 | |
| 49 | if (oldFileExists && !newFileExists) { |
| 50 | await fs.rename(oldPath, newPath) |
| 51 | outputChannel.appendLine(`Renamed ${migration.oldName} to ${migration.newName}`) |
| 52 | } else { |
| 53 | outputChannel.appendLine( |
| 54 | `Skipping migration of ${migration.oldName} to ${migration.newName}: ${oldFileExists ? "new file already exists" : "old file not found"}`, |
| 55 | ) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Special migration for custom_modes.json to custom_modes.yaml with content transformation |
| 60 | await migrateCustomModesToYaml(settingsDir, outputChannel) |
| 61 | } catch (error) { |
| 62 | outputChannel.appendLine(`Error in file migrations: ${error}`) |
| 63 | } |
| 64 | } catch (error) { |
| 65 | outputChannel.appendLine(`Error migrating settings files: ${error}`) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Special migration function to convert custom_modes.json to YAML format |
no test coverage detected