From 9b68fe09b58c8bc10f14ce71a5025291ab823356 Mon Sep 17 00:00:00 2001 From: Daniel Riccio Date: Wed, 2 Jul 2025 09:00:58 -0500 Subject: [PATCH] refactor(migration): Consolidate task history migration logic to use ContextProxy --- src/extension.ts | 7 ++-- src/utils/migrateSettings.ts | 76 ++---------------------------------- 2 files changed, 8 insertions(+), 75 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index bd43bcbf8a..f31ca74d54 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -59,8 +59,11 @@ export async function activate(context: vscode.ExtensionContext) { context.subscriptions.push(outputChannel) outputChannel.appendLine(`${Package.name} extension activated - ${JSON.stringify(Package)}`) + // Create contextProxy instance before migrations + const contextProxy = await ContextProxy.getInstance(context) + // Migrate old settings to new - await migrateSettings(context, outputChannel) + await migrateSettings(context, outputChannel, contextProxy) // Initialize telemetry service. const telemetryService = TelemetryService.createInstance() @@ -96,8 +99,6 @@ export async function activate(context: vscode.ExtensionContext) { if (!context.globalState.get("allowedCommands")) { context.globalState.update("allowedCommands", defaultCommands) } - - const contextProxy = await ContextProxy.getInstance(context) const codeIndexManager = CodeIndexManager.getInstance(context) try { diff --git a/src/utils/migrateSettings.ts b/src/utils/migrateSettings.ts index b5a49925be..10bf289311 100644 --- a/src/utils/migrateSettings.ts +++ b/src/utils/migrateSettings.ts @@ -17,6 +17,7 @@ const deprecatedCustomModesJSONFilename = "custom_modes.json" export async function migrateSettings( context: vscode.ExtensionContext, outputChannel: vscode.OutputChannel, + contextProxy: ContextProxy, ): Promise { // Legacy file names that need to be migrated to the new names in GlobalFileNames const fileMigrations = [ @@ -58,8 +59,9 @@ export async function migrateSettings( // Special migration for custom_modes.json to custom_modes.yaml with content transformation await migrateCustomModesToYaml(settingsDir, outputChannel) - // Migrate task history from global state to workspace state - await migrateTaskHistoryToWorkspace(context, outputChannel) + // Migrate task history from global state to workspace state using ContextProxy + const workspaceFolder = vscode.workspace.workspaceFolders?.[0] + await migrateTaskHistoryWithContextProxy(contextProxy, workspaceFolder) } catch (error) { outputChannel.appendLine(`Error in file migrations: ${error}`) } @@ -119,76 +121,6 @@ async function migrateCustomModesToYaml(settingsDir: string, outputChannel: vsco } } -/** - * Migrates task history from global state to workspace state - * This ensures each workspace has its own isolated task history - * - * TODO: Remove this migration code in September 2025 (6 months after implementation) - */ -async function migrateTaskHistoryToWorkspace( - context: vscode.ExtensionContext, - outputChannel: vscode.OutputChannel, -): Promise { - try { - // Check if we've already performed this migration - const migrationKey = "taskHistoryMigratedToWorkspace" - const alreadyMigrated = context.globalState.get(migrationKey, false) - - if (alreadyMigrated) { - outputChannel.appendLine("Task history migration already completed, skipping") - return - } - - // Get the current workspace folder - const workspaceFolder = vscode.workspace.workspaceFolders?.[0] - if (!workspaceFolder) { - outputChannel.appendLine("No workspace folder found, skipping task history migration") - return - } - - // Get task history from global state - const globalSettings = context.globalState.get("globalSettings") - if (!globalSettings?.taskHistory || globalSettings.taskHistory.length === 0) { - outputChannel.appendLine("No task history found in global state, skipping migration") - // Mark as migrated even if there's no data to prevent future checks - await context.globalState.update(migrationKey, true) - return - } - - const taskHistory = globalSettings.taskHistory - const currentWorkspacePath = workspaceFolder.uri.fsPath - - // Filter tasks that belong to the current workspace - const workspaceTasks = taskHistory.filter((task: any) => task.workspace === currentWorkspacePath) - - if (workspaceTasks.length > 0) { - // Get current workspace settings - const workspaceSettings = context.workspaceState.get("workspaceSettings", {}) - - // Add the filtered task history to workspace settings - workspaceSettings.taskHistory = workspaceTasks - - // Save to workspace state - await context.workspaceState.update("workspaceSettings", workspaceSettings) - - outputChannel.appendLine(`Successfully migrated ${workspaceTasks.length} tasks to workspace state`) - } else { - outputChannel.appendLine("No tasks found for current workspace, nothing to migrate") - } - - // Remove taskHistory from global settings - delete globalSettings.taskHistory - await context.globalState.update("globalSettings", globalSettings) - - // Mark migration as complete - await context.globalState.update(migrationKey, true) - - outputChannel.appendLine("Task history migration completed successfully") - } catch (error) { - outputChannel.appendLine(`Error migrating task history: ${error}`) - } -} - /** * Migrates task history from global state to workspace state using ContextProxy * This is used for the new architecture with ContextProxy