|
|
@@ -5,7 +5,6 @@ import { fileURLToPath } from "url"
|
|
|
import { createElement } from "react"
|
|
|
import pWaitFor from "p-wait-for"
|
|
|
|
|
|
-import type { HistoryItem } from "@roo-code/types"
|
|
|
import { setLogger } from "@roo-code/vscode-shim"
|
|
|
|
|
|
import {
|
|
|
@@ -23,8 +22,8 @@ import { JsonEventEmitter } from "@/agent/json-event-emitter.js"
|
|
|
|
|
|
import { createClient } from "@/lib/sdk/index.js"
|
|
|
import { loadToken, loadSettings } from "@/lib/storage/index.js"
|
|
|
+import { readWorkspaceTaskSessions, resolveWorkspaceResumeSessionId } from "@/lib/task-history/index.js"
|
|
|
import { isRecord } from "@/lib/utils/guards.js"
|
|
|
-import { arePathsEqual } from "@/lib/utils/path.js"
|
|
|
import { getEnvVarName, getApiKeyFromEnv } from "@/lib/utils/provider.js"
|
|
|
import { runOnboarding } from "@/lib/utils/onboarding.js"
|
|
|
import { getDefaultExtensionPath } from "@/lib/utils/extension.js"
|
|
|
@@ -105,38 +104,6 @@ async function warmRooModels(host: ExtensionHost): Promise<void> {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-function extractTaskHistoryFromMessage(message: unknown): HistoryItem[] | undefined {
|
|
|
- if (!isRecord(message)) {
|
|
|
- return undefined
|
|
|
- }
|
|
|
-
|
|
|
- if (message.type === "state") {
|
|
|
- const state = isRecord(message.state) ? message.state : undefined
|
|
|
- if (Array.isArray(state?.taskHistory)) {
|
|
|
- return state.taskHistory as HistoryItem[]
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (message.type === "taskHistoryUpdated" && Array.isArray(message.taskHistory)) {
|
|
|
- return message.taskHistory as HistoryItem[]
|
|
|
- }
|
|
|
-
|
|
|
- return undefined
|
|
|
-}
|
|
|
-
|
|
|
-function getMostRecentTaskIdInWorkspace(taskHistory: HistoryItem[], workspacePath: string): string | undefined {
|
|
|
- const workspaceTasks = taskHistory.filter(
|
|
|
- (item) => typeof item.workspace === "string" && arePathsEqual(item.workspace, workspacePath),
|
|
|
- )
|
|
|
-
|
|
|
- if (workspaceTasks.length === 0) {
|
|
|
- return undefined
|
|
|
- }
|
|
|
-
|
|
|
- const sorted = [...workspaceTasks].sort((a, b) => b.ts - a.ts)
|
|
|
- return sorted[0]?.id
|
|
|
-}
|
|
|
-
|
|
|
export async function run(promptArg: string | undefined, flagOptions: FlagOptions) {
|
|
|
setLogger({
|
|
|
info: () => {},
|
|
|
@@ -360,6 +327,18 @@ export async function run(promptArg: string | undefined, flagOptions: FlagOption
|
|
|
}
|
|
|
|
|
|
const useStdinPromptStream = flagOptions.stdinPromptStream
|
|
|
+ let resolvedResumeSessionId: string | undefined
|
|
|
+
|
|
|
+ if (isResumeRequested) {
|
|
|
+ const workspaceSessions = await readWorkspaceTaskSessions(effectiveWorkspacePath)
|
|
|
+ try {
|
|
|
+ resolvedResumeSessionId = resolveWorkspaceResumeSessionId(workspaceSessions, requestedSessionId)
|
|
|
+ } catch (error) {
|
|
|
+ const message = error instanceof Error ? error.message : String(error)
|
|
|
+ console.error(`[CLI] Error: ${message}`)
|
|
|
+ process.exit(1)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
if (!isTuiEnabled) {
|
|
|
if (!prompt && !useStdinPromptStream && !isResumeRequested) {
|
|
|
@@ -394,8 +373,8 @@ export async function run(promptArg: string | undefined, flagOptions: FlagOption
|
|
|
createElement(App, {
|
|
|
...extensionHostOptions,
|
|
|
initialPrompt: prompt,
|
|
|
- initialSessionId: requestedSessionId,
|
|
|
- continueSession: shouldContinueSession,
|
|
|
+ initialSessionId: resolvedResumeSessionId,
|
|
|
+ continueSession: false,
|
|
|
version: VERSION,
|
|
|
createExtensionHost: (opts: ExtensionHostOptions) => new ExtensionHost(opts),
|
|
|
}),
|
|
|
@@ -422,16 +401,6 @@ export async function run(promptArg: string | undefined, flagOptions: FlagOption
|
|
|
let keepAliveInterval: NodeJS.Timeout | undefined
|
|
|
let isShuttingDown = false
|
|
|
let hostDisposed = false
|
|
|
- let taskHistorySnapshot: HistoryItem[] = []
|
|
|
-
|
|
|
- const onExtensionMessage = (message: unknown) => {
|
|
|
- const taskHistory = extractTaskHistoryFromMessage(message)
|
|
|
- if (taskHistory) {
|
|
|
- taskHistorySnapshot = taskHistory
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- host.on("extensionWebviewMessage", onExtensionMessage)
|
|
|
|
|
|
const jsonEmitter = useJsonOutput
|
|
|
? new JsonEventEmitter({
|
|
|
@@ -497,7 +466,6 @@ export async function run(promptArg: string | undefined, flagOptions: FlagOption
|
|
|
}
|
|
|
|
|
|
hostDisposed = true
|
|
|
- host.off("extensionWebviewMessage", onExtensionMessage)
|
|
|
jsonEmitter?.detach()
|
|
|
await host.dispose()
|
|
|
}
|
|
|
@@ -594,22 +562,7 @@ export async function run(promptArg: string | undefined, flagOptions: FlagOption
|
|
|
}
|
|
|
|
|
|
if (isResumeRequested) {
|
|
|
- const resolvedSessionId =
|
|
|
- requestedSessionId ||
|
|
|
- getMostRecentTaskIdInWorkspace(taskHistorySnapshot, effectiveWorkspacePath)
|
|
|
-
|
|
|
- if (requestedSessionId && taskHistorySnapshot.length > 0) {
|
|
|
- const hasRequestedTask = taskHistorySnapshot.some((item) => item.id === requestedSessionId)
|
|
|
- if (!hasRequestedTask) {
|
|
|
- throw new Error(`Session not found in task history: ${requestedSessionId}`)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!resolvedSessionId) {
|
|
|
- throw new Error("No previous tasks found to continue in this workspace.")
|
|
|
- }
|
|
|
-
|
|
|
- await bootstrapResumeForStdinStream(host, resolvedSessionId)
|
|
|
+ await bootstrapResumeForStdinStream(host, resolvedResumeSessionId!)
|
|
|
}
|
|
|
|
|
|
await runStdinStreamMode({
|
|
|
@@ -621,22 +574,7 @@ export async function run(promptArg: string | undefined, flagOptions: FlagOption
|
|
|
})
|
|
|
} else {
|
|
|
if (isResumeRequested) {
|
|
|
- const resolvedSessionId =
|
|
|
- requestedSessionId ||
|
|
|
- getMostRecentTaskIdInWorkspace(taskHistorySnapshot, effectiveWorkspacePath)
|
|
|
-
|
|
|
- if (requestedSessionId && taskHistorySnapshot.length > 0) {
|
|
|
- const hasRequestedTask = taskHistorySnapshot.some((item) => item.id === requestedSessionId)
|
|
|
- if (!hasRequestedTask) {
|
|
|
- throw new Error(`Session not found in task history: ${requestedSessionId}`)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!resolvedSessionId) {
|
|
|
- throw new Error("No previous tasks found to continue in this workspace.")
|
|
|
- }
|
|
|
-
|
|
|
- await host.resumeTask(resolvedSessionId)
|
|
|
+ await host.resumeTask(resolvedResumeSessionId!)
|
|
|
} else {
|
|
|
await host.runTask(prompt!)
|
|
|
}
|