Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dull-hats-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"roo-cline": patch
---

Add a JSONL version of task persistence
56 changes: 56 additions & 0 deletions src/core/task-persistence/taskMessages.jsonl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as path from "path"
import * as fs from "fs/promises"
import * as readline from "readline"
import { createReadStream } from "fs"

import { fileExistsAtPath } from "../../utils/fs"

import { GlobalFileNames } from "../../shared/globalFileNames"
import { ClineMessage } from "../../shared/ExtensionMessage"
import { getTaskDirectoryPath } from "../../shared/storagePathManager"

import type { ReadTaskMessagesOptions, SaveTaskMessagesOptions } from "./taskMessages"

export async function readTaskMessages({
taskId,
globalStoragePath,
}: ReadTaskMessagesOptions): Promise<ClineMessage[]> {
const taskDir = await getTaskDirectoryPath(globalStoragePath, taskId)
const filePath = path.join(taskDir, `${GlobalFileNames.apiConversationHistory}l`)
const fileExists = await fileExistsAtPath(filePath)

if (!fileExists) {
return []
}

const messages: ClineMessage[] = []
const fileStream = createReadStream(filePath, { encoding: "utf8" })
const rl = readline.createInterface({ input: fileStream, crlfDelay: Infinity })

for await (const line of rl) {
if (line.trim()) {
messages.push(JSON.parse(line))
}
}

return messages
}

export async function writeTaskMessages({ messages, taskId, globalStoragePath }: SaveTaskMessagesOptions) {
const taskDir = await getTaskDirectoryPath(globalStoragePath, taskId)
const filePath = path.join(taskDir, `${GlobalFileNames.apiConversationHistory}l`)
const content = messages.map((message) => JSON.stringify(message)).join("\n")
await fs.writeFile(filePath, content)
}

export type AppendTaskMessageOptions = {
message: ClineMessage
taskId: string
globalStoragePath: string
}

export async function appendTaskMessage({ message, taskId, globalStoragePath }: AppendTaskMessageOptions) {
const taskDir = await getTaskDirectoryPath(globalStoragePath, taskId)
const filePath = path.join(taskDir, `${GlobalFileNames.apiConversationHistory}l`)
await fs.appendFile(filePath, JSON.stringify(message) + "\n")
}
2 changes: 1 addition & 1 deletion src/core/task-persistence/taskMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { findLastIndex } from "../../shared/array"
import { HistoryItem } from "../../shared/HistoryItem"
import { getTaskDirectoryPath } from "../../shared/storagePathManager"

const taskSizeCache = new NodeCache({ stdTTL: 5 * 60, checkperiod: 30 })
const taskSizeCache = new NodeCache({ stdTTL: 30, checkperiod: 5 * 60 })
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I swapped these original; the TTL should be 30s and the check period doesn't really matter.


export type TaskMetadataOptions = {
messages: ClineMessage[]
Expand Down
Loading