diff --git a/.changeset/clean-boats-film.md b/.changeset/clean-boats-film.md new file mode 100644 index 00000000..681d4298 --- /dev/null +++ b/.changeset/clean-boats-film.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Fixes issue where deleting tasks wasn't clearing the task metadata or context history files; let model recording fail gracefully diff --git a/package-lock.json b/package-lock.json index 561b86b5..291b9f6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "claude-dev", - "version": "3.10.0", + "version": "3.10.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "claude-dev", - "version": "3.10.0", + "version": "3.10.1", "license": "Apache-2.0", "dependencies": { "@anthropic-ai/bedrock-sdk": "^0.12.4", diff --git a/src/core/controller/index.ts b/src/core/controller/index.ts index edb02689..f2e81281 100644 --- a/src/core/controller/index.ts +++ b/src/core/controller/index.ts @@ -1704,6 +1704,8 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont taskDirPath: string apiConversationHistoryFilePath: string uiMessagesFilePath: string + contextHistoryFilePath: string + taskMetadataFilePath: string apiConversationHistory: Anthropic.MessageParam[] }> { const history = ((await getGlobalState(this.context, "taskHistory")) as HistoryItem[] | undefined) || [] @@ -1712,6 +1714,8 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont const taskDirPath = path.join(this.context.globalStorageUri.fsPath, "tasks", id) const apiConversationHistoryFilePath = path.join(taskDirPath, GlobalFileNames.apiConversationHistory) const uiMessagesFilePath = path.join(taskDirPath, GlobalFileNames.uiMessages) + const contextHistoryFilePath = path.join(taskDirPath, GlobalFileNames.contextHistory) + const taskMetadataFilePath = path.join(taskDirPath, GlobalFileNames.taskMetadata) const fileExists = await fileExistsAtPath(apiConversationHistoryFilePath) if (fileExists) { const apiConversationHistory = JSON.parse(await fs.readFile(apiConversationHistoryFilePath, "utf8")) @@ -1720,6 +1724,8 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont taskDirPath, apiConversationHistoryFilePath, uiMessagesFilePath, + contextHistoryFilePath, + taskMetadataFilePath, apiConversationHistory, } } @@ -1791,22 +1797,28 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont console.debug("cleared task") } - const { taskDirPath, apiConversationHistoryFilePath, uiMessagesFilePath } = await this.getTaskWithId(id) - + const { + taskDirPath, + apiConversationHistoryFilePath, + uiMessagesFilePath, + contextHistoryFilePath, + taskMetadataFilePath, + } = await this.getTaskWithId(id) + const legacyMessagesFilePath = path.join(taskDirPath, "claude_messages.json") const updatedTaskHistory = await this.deleteTaskFromState(id) // Delete the task files - const apiConversationHistoryFileExists = await fileExistsAtPath(apiConversationHistoryFilePath) - if (apiConversationHistoryFileExists) { - await fs.unlink(apiConversationHistoryFilePath) - } - const uiMessagesFileExists = await fileExistsAtPath(uiMessagesFilePath) - if (uiMessagesFileExists) { - await fs.unlink(uiMessagesFilePath) - } - const legacyMessagesFilePath = path.join(taskDirPath, "claude_messages.json") - if (await fileExistsAtPath(legacyMessagesFilePath)) { - await fs.unlink(legacyMessagesFilePath) + for (const filePath of [ + apiConversationHistoryFilePath, + uiMessagesFilePath, + contextHistoryFilePath, + taskMetadataFilePath, + legacyMessagesFilePath, + ]) { + const fileExists = await fileExistsAtPath(filePath) + if (fileExists) { + await fs.unlink(filePath) + } } await fs.rmdir(taskDirPath) // succeeds if the dir is empty diff --git a/src/core/task/index.ts b/src/core/task/index.ts index d85c3d7a..ca10fa7e 100644 --- a/src/core/task/index.ts +++ b/src/core/task/index.ts @@ -3113,8 +3113,11 @@ export class Task { throw new Error("Cline instance aborted") } + // Used to know what models were used in the task if user wants to export metadata for error reporting purposes if (this.apiProvider && this.api.getModel().id) { - await this.modelContextTracker.recordModelUsage(this.apiProvider, this.api.getModel().id, this.chatSettings.mode) + try { + await this.modelContextTracker.recordModelUsage(this.apiProvider, this.api.getModel().id, this.chatSettings.mode) + } catch {} } if (this.consecutiveMistakeCount >= 3) {