@@ -16,11 +16,7 @@ import { TokenUsage } from "../schemas"
1616import { ApiHandler , buildApiHandler } from "../api"
1717import { ApiStream } from "../api/transform/stream"
1818import { DIFF_VIEW_URI_SCHEME , DiffViewProvider } from "../integrations/editor/DiffViewProvider"
19- import {
20- CheckpointServiceOptions ,
21- RepoPerTaskCheckpointService ,
22- RepoPerWorkspaceCheckpointService ,
23- } from "../services/checkpoints"
19+ import { CheckpointServiceOptions , RepoPerTaskCheckpointService } from "../services/checkpoints"
2420import { findToolName , formatContentBlockToMarkdown } from "../integrations/misc/export-markdown"
2521import { fetchInstructionsTool } from "./tools/fetchInstructionsTool"
2622import { listFilesTool } from "./tools/listFilesTool"
@@ -30,7 +26,6 @@ import { Terminal } from "../integrations/terminal/Terminal"
3026import { TerminalRegistry } from "../integrations/terminal/TerminalRegistry"
3127import { UrlContentFetcher } from "../services/browser/UrlContentFetcher"
3228import { listFiles } from "../services/glob/list-files"
33- import { CheckpointStorage } from "../shared/checkpoints"
3429import { ApiConfiguration } from "../shared/api"
3530import { findLastIndex } from "../shared/array"
3631import { combineApiRequests } from "../shared/combineApiRequests"
@@ -104,7 +99,6 @@ export type ClineOptions = {
10499 customInstructions ?: string
105100 enableDiff ?: boolean
106101 enableCheckpoints ?: boolean
107- checkpointStorage ?: CheckpointStorage
108102 fuzzyMatchThreshold ?: number
109103 consecutiveMistakeLimit ?: number
110104 task ?: string
@@ -162,8 +156,8 @@ export class Cline extends EventEmitter<ClineEvents> {
162156
163157 // checkpoints
164158 private enableCheckpoints : boolean
165- private checkpointStorage : CheckpointStorage
166- private checkpointService ?: RepoPerTaskCheckpointService | RepoPerWorkspaceCheckpointService
159+ private checkpointService ?: RepoPerTaskCheckpointService
160+ private checkpointServiceInitializing = false
167161
168162 // streaming
169163 isWaitingForFirstChunk = false
@@ -184,7 +178,6 @@ export class Cline extends EventEmitter<ClineEvents> {
184178 customInstructions,
185179 enableDiff = false ,
186180 enableCheckpoints = true ,
187- checkpointStorage = "task" ,
188181 fuzzyMatchThreshold = 1.0 ,
189182 consecutiveMistakeLimit = 3 ,
190183 task,
@@ -223,7 +216,6 @@ export class Cline extends EventEmitter<ClineEvents> {
223216 this . providerRef = new WeakRef ( provider )
224217 this . diffViewProvider = new DiffViewProvider ( this . cwd )
225218 this . enableCheckpoints = enableCheckpoints
226- this . checkpointStorage = checkpointStorage
227219
228220 this . rootTask = rootTask
229221 this . parentTask = parentTask
@@ -2399,6 +2391,11 @@ export class Cline extends EventEmitter<ClineEvents> {
23992391 return this . checkpointService
24002392 }
24012393
2394+ if ( this . checkpointServiceInitializing ) {
2395+ console . log ( "[Cline#getCheckpointService] checkpoint service is still initializing" )
2396+ return undefined
2397+ }
2398+
24022399 const log = ( message : string ) => {
24032400 console . log ( message )
24042401
@@ -2409,19 +2406,21 @@ export class Cline extends EventEmitter<ClineEvents> {
24092406 }
24102407 }
24112408
2409+ console . log ( "[Cline#getCheckpointService] initializing checkpoints service" )
2410+
24122411 try {
24132412 const workspaceDir = getWorkspacePath ( )
24142413
24152414 if ( ! workspaceDir ) {
2416- log ( "[Cline#initializeCheckpoints ] workspace folder not found, disabling checkpoints" )
2415+ log ( "[Cline#getCheckpointService ] workspace folder not found, disabling checkpoints" )
24172416 this . enableCheckpoints = false
24182417 return undefined
24192418 }
24202419
24212420 const globalStorageDir = this . providerRef . deref ( ) ?. context . globalStorageUri . fsPath
24222421
24232422 if ( ! globalStorageDir ) {
2424- log ( "[Cline#initializeCheckpoints ] globalStorageDir not found, disabling checkpoints" )
2423+ log ( "[Cline#getCheckpointService ] globalStorageDir not found, disabling checkpoints" )
24252424 this . enableCheckpoints = false
24262425 return undefined
24272426 }
@@ -2433,28 +2432,26 @@ export class Cline extends EventEmitter<ClineEvents> {
24332432 log,
24342433 }
24352434
2436- // Only `task` is supported at the moment until we figure out how
2437- // to fully isolate the `workspace` variant.
2438- // const service =
2439- // this.checkpointStorage === "task"
2440- // ? RepoPerTaskCheckpointService.create(options)
2441- // : RepoPerWorkspaceCheckpointService.create(options)
2442-
24432435 const service = RepoPerTaskCheckpointService . create ( options )
24442436
2437+ this . checkpointServiceInitializing = true
2438+
24452439 service . on ( "initialize" , ( ) => {
2440+ log ( "[Cline#getCheckpointService] service initialized" )
2441+
24462442 try {
24472443 const isCheckpointNeeded =
24482444 typeof this . clineMessages . find ( ( { say } ) => say === "checkpoint_saved" ) === "undefined"
24492445
24502446 this . checkpointService = service
2447+ this . checkpointServiceInitializing = false
24512448
24522449 if ( isCheckpointNeeded ) {
2453- log ( "[Cline#initializeCheckpoints ] no checkpoints found, saving initial checkpoint" )
2450+ log ( "[Cline#getCheckpointService ] no checkpoints found, saving initial checkpoint" )
24542451 this . checkpointSave ( )
24552452 }
24562453 } catch ( err ) {
2457- log ( "[Cline#initializeCheckpoints ] caught error in on('initialize'), disabling checkpoints" )
2454+ log ( "[Cline#getCheckpointService ] caught error in on('initialize'), disabling checkpoints" )
24582455 this . enableCheckpoints = false
24592456 }
24602457 } )
@@ -2464,29 +2461,31 @@ export class Cline extends EventEmitter<ClineEvents> {
24642461 this . providerRef . deref ( ) ?. postMessageToWebview ( { type : "currentCheckpointUpdated" , text : to } )
24652462
24662463 this . say ( "checkpoint_saved" , to , undefined , undefined , { isFirst, from, to } ) . catch ( ( err ) => {
2467- log ( "[Cline#initializeCheckpoints ] caught unexpected error in say('checkpoint_saved')" )
2464+ log ( "[Cline#getCheckpointService ] caught unexpected error in say('checkpoint_saved')" )
24682465 console . error ( err )
24692466 } )
24702467 } catch ( err ) {
24712468 log (
2472- "[Cline#initializeCheckpoints ] caught unexpected error in on('checkpoint'), disabling checkpoints" ,
2469+ "[Cline#getCheckpointService ] caught unexpected error in on('checkpoint'), disabling checkpoints" ,
24732470 )
24742471 console . error ( err )
24752472 this . enableCheckpoints = false
24762473 }
24772474 } )
24782475
2476+ log ( "[Cline#getCheckpointService] initializing shadow git" )
2477+
24792478 service . initShadowGit ( ) . catch ( ( err ) => {
24802479 log (
2481- `[Cline#initializeCheckpoints ] caught unexpected error in initShadowGit, disabling checkpoints (${ err . message } )` ,
2480+ `[Cline#getCheckpointService ] caught unexpected error in initShadowGit, disabling checkpoints (${ err . message } )` ,
24822481 )
24832482 console . error ( err )
24842483 this . enableCheckpoints = false
24852484 } )
24862485
24872486 return service
24882487 } catch ( err ) {
2489- log ( "[Cline#initializeCheckpoints ] caught unexpected error, disabling checkpoints" )
2488+ log ( "[Cline#getCheckpointService ] caught unexpected error, disabling checkpoints" )
24902489 this . enableCheckpoints = false
24912490 return undefined
24922491 }
0 commit comments