|
|
@@ -2326,51 +2326,33 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
|
|
|
}> {
|
|
|
const history = ((await this.getGlobalState("taskHistory")) as HistoryItem[] | undefined) || []
|
|
|
const historyItem = history.find((item) => item.id === id)
|
|
|
- if (!historyItem) {
|
|
|
- throw new Error("Task not found in history")
|
|
|
- }
|
|
|
-
|
|
|
- const taskDirPath = path.join(this.contextProxy.globalStorageUri.fsPath, "tasks", id)
|
|
|
- const apiConversationHistoryFilePath = path.join(taskDirPath, GlobalFileNames.apiConversationHistory)
|
|
|
- const uiMessagesFilePath = path.join(taskDirPath, GlobalFileNames.uiMessages)
|
|
|
-
|
|
|
- const fileExists = await fileExistsAtPath(apiConversationHistoryFilePath)
|
|
|
- if (!fileExists) {
|
|
|
- // Instead of silently deleting, throw a specific error
|
|
|
- throw new Error("TASK_FILES_MISSING")
|
|
|
- }
|
|
|
-
|
|
|
- const apiConversationHistory = JSON.parse(await fs.readFile(apiConversationHistoryFilePath, "utf8"))
|
|
|
- return {
|
|
|
- historyItem,
|
|
|
- taskDirPath,
|
|
|
- apiConversationHistoryFilePath,
|
|
|
- uiMessagesFilePath,
|
|
|
- apiConversationHistory,
|
|
|
+ if (historyItem) {
|
|
|
+ const taskDirPath = path.join(this.contextProxy.globalStorageUri.fsPath, "tasks", id)
|
|
|
+ const apiConversationHistoryFilePath = path.join(taskDirPath, GlobalFileNames.apiConversationHistory)
|
|
|
+ const uiMessagesFilePath = path.join(taskDirPath, GlobalFileNames.uiMessages)
|
|
|
+ const fileExists = await fileExistsAtPath(apiConversationHistoryFilePath)
|
|
|
+ if (fileExists) {
|
|
|
+ const apiConversationHistory = JSON.parse(await fs.readFile(apiConversationHistoryFilePath, "utf8"))
|
|
|
+ return {
|
|
|
+ historyItem,
|
|
|
+ taskDirPath,
|
|
|
+ apiConversationHistoryFilePath,
|
|
|
+ uiMessagesFilePath,
|
|
|
+ apiConversationHistory,
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ // if we tried to get a task that doesn't exist, remove it from state
|
|
|
+ // FIXME: this seems to happen sometimes when the json file doesnt save to disk for some reason
|
|
|
+ await this.deleteTaskFromState(id)
|
|
|
+ throw new Error("Task not found")
|
|
|
}
|
|
|
|
|
|
async showTaskWithId(id: string) {
|
|
|
if (id !== this.getCurrentCline()?.taskId) {
|
|
|
- try {
|
|
|
- const { historyItem } = await this.getTaskWithId(id)
|
|
|
- await this.initClineWithHistoryItem(historyItem)
|
|
|
- } catch (error) {
|
|
|
- if (error.message === "TASK_FILES_MISSING") {
|
|
|
- const response = await vscode.window.showWarningMessage(
|
|
|
- t("common:warnings.missing_task_files"),
|
|
|
- t("common:answers.remove"),
|
|
|
- t("common:answers.keep"),
|
|
|
- )
|
|
|
-
|
|
|
- if (response === t("common:answers.remove")) {
|
|
|
- await this.deleteTaskFromState(id)
|
|
|
- await this.postStateToWebview()
|
|
|
- }
|
|
|
- return
|
|
|
- }
|
|
|
- throw error
|
|
|
- }
|
|
|
+ // Non-current task.
|
|
|
+ const { historyItem } = await this.getTaskWithId(id)
|
|
|
+ await this.initClineWithHistoryItem(historyItem) // Clears existing task.
|
|
|
}
|
|
|
|
|
|
await this.postMessageToWebview({ type: "action", action: "chatButtonClicked" })
|
|
|
@@ -2857,28 +2839,4 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
|
|
|
|
|
|
return properties
|
|
|
}
|
|
|
-
|
|
|
- async validateTaskHistory() {
|
|
|
- const history = ((await this.getGlobalState("taskHistory")) as HistoryItem[] | undefined) || []
|
|
|
- const validTasks: HistoryItem[] = []
|
|
|
-
|
|
|
- for (const item of history) {
|
|
|
- const taskDirPath = path.join(this.contextProxy.globalStorageUri.fsPath, "tasks", item.id)
|
|
|
- const apiConversationHistoryFilePath = path.join(taskDirPath, GlobalFileNames.apiConversationHistory)
|
|
|
-
|
|
|
- if (await fileExistsAtPath(apiConversationHistoryFilePath)) {
|
|
|
- validTasks.push(item)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (validTasks.length !== history.length) {
|
|
|
- await this.updateGlobalState("taskHistory", validTasks)
|
|
|
- await this.postStateToWebview()
|
|
|
-
|
|
|
- const removedCount = history.length - validTasks.length
|
|
|
- if (removedCount > 0) {
|
|
|
- await vscode.window.showInformationMessage(t("common:info.history_cleanup", { count: removedCount }))
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|