@@ -7,14 +7,15 @@ import pWaitFor from "p-wait-for"
77import * as path from "path"
88import * as vscode from "vscode"
99import simpleGit from "simple-git"
10- import { setPanel } from "../../activate/registerCommands"
1110
11+ import { setPanel } from "../../activate/registerCommands"
1212import { ApiConfiguration , ApiProvider , ModelInfo , API_CONFIG_KEYS } from "../../shared/api"
1313import { findLast } from "../../shared/array"
1414import { supportPrompt } from "../../shared/support-prompt"
1515import { GlobalFileNames } from "../../shared/globalFileNames"
1616import { SecretKey , GlobalStateKey , SECRET_KEYS , GLOBAL_STATE_KEYS } from "../../shared/globalState"
1717import { HistoryItem } from "../../shared/HistoryItem"
18+ import { CheckpointStorage } from "../../shared/checkpoints"
1819import { ApiConfigMeta , ExtensionMessage } from "../../shared/ExtensionMessage"
1920import { checkoutDiffPayloadSchema , checkoutRestorePayloadSchema , WebviewMessage } from "../../shared/WebviewMessage"
2021import { Mode , PromptComponent , defaultModeSlug , ModeConfig } from "../../shared/modes"
@@ -28,6 +29,7 @@ import { getTheme } from "../../integrations/theme/getTheme"
2829import WorkspaceTracker from "../../integrations/workspace/WorkspaceTracker"
2930import { McpHub } from "../../services/mcp/McpHub"
3031import { McpServerManager } from "../../services/mcp/McpServerManager"
32+ import { ShadowCheckpointService } from "../../services/checkpoints/ShadowCheckpointService"
3133import { fileExistsAtPath } from "../../utils/fs"
3234import { playSound , setSoundEnabled , setSoundVolume } from "../../utils/sound"
3335import { singleCompletionHandler } from "../../utils/single-completion-handler"
@@ -47,7 +49,7 @@ import { getOllamaModels } from "../../api/providers/ollama"
4749import { getVsCodeLmModels } from "../../api/providers/vscode-lm"
4850import { getLmStudioModels } from "../../api/providers/lmstudio"
4951import { ACTION_NAMES } from "../CodeActionProvider"
50- import { Cline } from "../Cline"
52+ import { Cline , ClineOptions } from "../Cline"
5153import { openMention } from "../mentions"
5254import { getNonce } from "./getNonce"
5355import { getUri } from "./getUri"
@@ -525,22 +527,43 @@ export class ClineProvider implements vscode.WebviewViewProvider {
525527 const modePrompt = customModePrompts ?. [ mode ] as PromptComponent
526528 const effectiveInstructions = [ globalInstructions , modePrompt ?. customInstructions ] . filter ( Boolean ) . join ( "\n\n" )
527529
528- // TODO: The `checkpointStorage` value should be derived from the
529- // task data on disk; the current setting could be different than
530- // the setting at the time the task was created.
530+ const taskId = historyItem . id
531+ const globalStorageDir = this . contextProxy . globalStorageUri . fsPath
532+ const workspaceDir = vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath ?? ""
533+
534+ const checkpoints : Pick < ClineOptions , "enableCheckpoints" | "checkpointStorage" > = {
535+ enableCheckpoints,
536+ checkpointStorage,
537+ }
538+
539+ if ( enableCheckpoints ) {
540+ try {
541+ checkpoints . checkpointStorage = await ShadowCheckpointService . getTaskStorage ( {
542+ taskId,
543+ globalStorageDir,
544+ workspaceDir,
545+ } )
546+
547+ this . log (
548+ `[ClineProvider#initClineWithHistoryItem] Using ${ checkpoints . checkpointStorage } storage for ${ taskId } ` ,
549+ )
550+ } catch ( error ) {
551+ checkpoints . enableCheckpoints = false
552+ this . log ( `[ClineProvider#initClineWithHistoryItem] Error getting task storage: ${ error . message } ` )
553+ }
554+ }
531555
532556 const newCline = new Cline ( {
533557 provider : this ,
534558 apiConfiguration,
535559 customInstructions : effectiveInstructions ,
536560 enableDiff,
537- enableCheckpoints,
538- checkpointStorage,
561+ ...checkpoints ,
539562 fuzzyMatchThreshold,
540563 historyItem,
541564 experiments,
542565 } )
543- // get this cline task number id from the history item and set it to newCline
566+
544567 newCline . setTaskNumber ( historyItem . number )
545568 await this . addClineToStack ( newCline )
546569 }
@@ -2069,21 +2092,20 @@ export class ClineProvider implements vscode.WebviewViewProvider {
20692092 // delete task from the task history state
20702093 await this . deleteTaskFromState ( id )
20712094
2072- // check if checkpoints are enabled
2073- const { enableCheckpoints } = await this . getState ( )
20742095 // get the base directory of the project
20752096 const baseDir = vscode . workspace . workspaceFolders ?. map ( ( folder ) => folder . uri . fsPath ) . at ( 0 )
20762097
2077- // Delete checkpoints branch.
2078- // TODO: Also delete the workspace branch if it exists.
2079- if ( enableCheckpoints && baseDir ) {
2080- const branchSummary = await simpleGit ( baseDir )
2081- . branch ( [ "-D" , `roo-code-checkpoints-${ id } ` ] )
2082- . catch ( ( ) => undefined )
2098+ // Delete associated shadow repository or branch.
2099+ // TODO: Store `workspaceDir` in the `HistoryItem` object.
2100+ const globalStorageDir = this . contextProxy . globalStorageUri . fsPath
2101+ const workspaceDir = baseDir ?? ""
20832102
2084- if ( branchSummary ) {
2085- console . log ( `[deleteTaskWithId${ id } ] deleted checkpoints branch` )
2086- }
2103+ try {
2104+ await ShadowCheckpointService . deleteTask ( { taskId : id , globalStorageDir, workspaceDir } )
2105+ } catch ( error ) {
2106+ console . error (
2107+ `[deleteTaskWithId${ id } ] failed to delete associated shadow repository or branch: ${ error instanceof Error ? error . message : String ( error ) } ` ,
2108+ )
20872109 }
20882110
20892111 // delete the entire task directory including checkpoints and all content
0 commit comments