mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-06 08:18:39 +00:00
Refactor claude_messages.json
This commit is contained in:
parent
d67523596b
commit
372c4df3bf
2 changed files with 26 additions and 14 deletions
|
|
@ -151,10 +151,17 @@ export class Cline {
|
|||
}
|
||||
|
||||
private async getSavedClaudeMessages(): Promise<ClineMessage[]> {
|
||||
const filePath = path.join(await this.ensureTaskDirectoryExists(), GlobalFileNames.claudeMessages)
|
||||
const fileExists = await fileExistsAtPath(filePath)
|
||||
if (fileExists) {
|
||||
const filePath = path.join(await this.ensureTaskDirectoryExists(), GlobalFileNames.uiMessages)
|
||||
if (await fileExistsAtPath(filePath)) {
|
||||
return JSON.parse(await fs.readFile(filePath, "utf8"))
|
||||
} else {
|
||||
// check old location
|
||||
const oldPath = path.join(await this.ensureTaskDirectoryExists(), "claude_messages.json")
|
||||
if (await fileExistsAtPath(oldPath)) {
|
||||
const data = JSON.parse(await fs.readFile(oldPath, "utf8"))
|
||||
await fs.unlink(oldPath) // remove old file
|
||||
return data
|
||||
}
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
|
@ -171,7 +178,7 @@ export class Cline {
|
|||
|
||||
private async saveClaudeMessages() {
|
||||
try {
|
||||
const filePath = path.join(await this.ensureTaskDirectoryExists(), GlobalFileNames.claudeMessages)
|
||||
const filePath = path.join(await this.ensureTaskDirectoryExists(), GlobalFileNames.uiMessages)
|
||||
await fs.writeFile(filePath, JSON.stringify(this.claudeMessages))
|
||||
// combined as they are in ChatView
|
||||
const apiMetrics = getApiMetrics(combineApiRequests(combineCommandSequences(this.claudeMessages.slice(1))))
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ type GlobalStateKey =
|
|||
|
||||
export const GlobalFileNames = {
|
||||
apiConversationHistory: "api_conversation_history.json",
|
||||
claudeMessages: "claude_messages.json",
|
||||
uiMessages: "ui_messages.json",
|
||||
openRouterModels: "openrouter_models.json",
|
||||
}
|
||||
|
||||
|
|
@ -651,7 +651,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|||
historyItem: HistoryItem
|
||||
taskDirPath: string
|
||||
apiConversationHistoryFilePath: string
|
||||
claudeMessagesFilePath: string
|
||||
uiMessagesFilePath: string
|
||||
apiConversationHistory: Anthropic.MessageParam[]
|
||||
}> {
|
||||
const history = ((await this.getGlobalState("taskHistory")) as HistoryItem[] | undefined) || []
|
||||
|
|
@ -659,7 +659,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|||
if (historyItem) {
|
||||
const taskDirPath = path.join(this.context.globalStorageUri.fsPath, "tasks", id)
|
||||
const apiConversationHistoryFilePath = path.join(taskDirPath, GlobalFileNames.apiConversationHistory)
|
||||
const claudeMessagesFilePath = path.join(taskDirPath, GlobalFileNames.claudeMessages)
|
||||
const uiMessagesFilePath = path.join(taskDirPath, GlobalFileNames.uiMessages)
|
||||
const fileExists = await fileExistsAtPath(apiConversationHistoryFilePath)
|
||||
if (fileExists) {
|
||||
const apiConversationHistory = JSON.parse(await fs.readFile(apiConversationHistoryFilePath, "utf8"))
|
||||
|
|
@ -667,12 +667,13 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|||
historyItem,
|
||||
taskDirPath,
|
||||
apiConversationHistoryFilePath,
|
||||
claudeMessagesFilePath,
|
||||
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")
|
||||
}
|
||||
|
|
@ -696,20 +697,24 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|||
await this.clearTask()
|
||||
}
|
||||
|
||||
const { taskDirPath, apiConversationHistoryFilePath, claudeMessagesFilePath } = await this.getTaskWithId(id)
|
||||
const { taskDirPath, apiConversationHistoryFilePath, uiMessagesFilePath } = await this.getTaskWithId(id)
|
||||
|
||||
await this.deleteTaskFromState(id)
|
||||
|
||||
// Delete the task files
|
||||
const apiConversationHistoryFileExists = await fileExistsAtPath(apiConversationHistoryFilePath)
|
||||
if (apiConversationHistoryFileExists) {
|
||||
await fs.unlink(apiConversationHistoryFilePath)
|
||||
}
|
||||
const claudeMessagesFileExists = await fileExistsAtPath(claudeMessagesFilePath)
|
||||
if (claudeMessagesFileExists) {
|
||||
await fs.unlink(claudeMessagesFilePath)
|
||||
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)
|
||||
}
|
||||
await fs.rmdir(taskDirPath) // succeeds if the dir is empty
|
||||
|
||||
await this.deleteTaskFromState(id)
|
||||
}
|
||||
|
||||
async deleteTaskFromState(id: string) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue