-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathindex.ts
More file actions
47 lines (37 loc) · 1.51 KB
/
Copy pathindex.ts
File metadata and controls
47 lines (37 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os from "os"
import path from "path"
import { readTaskSessionsFromStoragePath, type TaskSessionEntry } from "@roo-code/core/cli"
import { arePathsEqual } from "@/lib/utils/path.js"
const DEFAULT_CLI_TASK_STORAGE_PATH = path.join(os.homedir(), ".vscode-mock", "global-storage")
/**
* @internal
*/
export function getDefaultCliTaskStoragePath(): string {
return DEFAULT_CLI_TASK_STORAGE_PATH
}
export function filterSessionsForWorkspace(sessions: TaskSessionEntry[], workspacePath: string): TaskSessionEntry[] {
return sessions
.filter((session) => typeof session.workspace === "string" && arePathsEqual(session.workspace, workspacePath))
.sort((a, b) => b.ts - a.ts)
}
export async function readWorkspaceTaskSessions(
workspacePath: string,
storagePath = DEFAULT_CLI_TASK_STORAGE_PATH,
): Promise<TaskSessionEntry[]> {
const sessions = await readTaskSessionsFromStoragePath(storagePath)
return filterSessionsForWorkspace(sessions, workspacePath)
}
export function resolveWorkspaceResumeSessionId(sessions: TaskSessionEntry[], requestedSessionId?: string): string {
if (requestedSessionId) {
const hasRequestedSession = sessions.some((session) => session.id === requestedSessionId)
if (!hasRequestedSession) {
throw new Error(`Session not found in current workspace: ${requestedSessionId}`)
}
return requestedSessionId
}
const mostRecentSessionId = sessions[0]?.id
if (!mostRecentSessionId) {
throw new Error("No previous tasks found to continue in this workspace.")
}
return mostRecentSessionId
}