@@ -16,18 +16,29 @@ import { DIFF_VIEW_URI_SCHEME } from "../../integrations/editor/DiffViewProvider
1616
1717import { CheckpointServiceOptions , RepoPerTaskCheckpointService } from "../../services/checkpoints"
1818
19- export async function getCheckpointService ( cline : Task ) {
19+ export async function getCheckpointService (
20+ cline : Task ,
21+ { interval = 250 , timeout = 15_000 } : { interval ?: number ; timeout ?: number } = { } ,
22+ ) {
2023 if ( ! cline . enableCheckpoints ) {
2124 return undefined
2225 }
2326
2427 if ( cline . checkpointService ) {
25- return cline . checkpointService
26- }
27-
28- if ( cline . checkpointServiceInitializing ) {
29- console . log ( "[Task#getCheckpointService] checkpoint service is still initializing" )
30- return undefined
28+ if ( cline . checkpointServiceInitializing ) {
29+ console . log ( "[Task#getCheckpointService] checkpoint service is still initializing" )
30+ const service = cline . checkpointService
31+ await pWaitFor (
32+ ( ) => {
33+ console . log ( "[Task#getCheckpointService] waiting for service to initialize" )
34+ return service . isInitialized
35+ } ,
36+ { interval, timeout } ,
37+ )
38+ return service . isInitialized ? cline . checkpointService : undefined
39+ } else {
40+ return cline . checkpointService
41+ }
3142 }
3243
3344 const provider = cline . providerRef . deref ( )
@@ -69,8 +80,8 @@ export async function getCheckpointService(cline: Task) {
6980 }
7081
7182 const service = RepoPerTaskCheckpointService . create ( options )
72-
7383 cline . checkpointServiceInitializing = true
84+ cline . checkpointService = service
7485
7586 // Check if Git is installed before initializing the service
7687 // Note: This is intentionally fire-and-forget to match the original IIFE pattern
@@ -120,7 +131,6 @@ async function checkGitInstallation(
120131 const isCheckpointNeeded =
121132 typeof cline . clineMessages . find ( ( { say } ) => say === "checkpoint_saved" ) === "undefined"
122133
123- cline . checkpointService = service
124134 cline . checkpointServiceInitializing = false
125135
126136 if ( isCheckpointNeeded ) {
@@ -167,31 +177,6 @@ async function checkGitInstallation(
167177 }
168178}
169179
170- async function getInitializedCheckpointService (
171- cline : Task ,
172- { interval = 250 , timeout = 15_000 } : { interval ?: number ; timeout ?: number } = { } ,
173- ) {
174- const service = await getCheckpointService ( cline )
175-
176- if ( ! service || service . isInitialized ) {
177- return service
178- }
179-
180- try {
181- await pWaitFor (
182- ( ) => {
183- console . log ( "[Task#getCheckpointService] waiting for service to initialize" )
184- return service . isInitialized
185- } ,
186- { interval, timeout } ,
187- )
188-
189- return service
190- } catch ( err ) {
191- return undefined
192- }
193- }
194-
195180export async function checkpointSave ( cline : Task , force = false ) {
196181 const service = await getCheckpointService ( cline )
197182
@@ -222,7 +207,7 @@ export type CheckpointRestoreOptions = {
222207}
223208
224209export async function checkpointRestore ( cline : Task , { ts, commitHash, mode } : CheckpointRestoreOptions ) {
225- const service = await getInitializedCheckpointService ( cline )
210+ const service = await getCheckpointService ( cline )
226211
227212 if ( ! service ) {
228213 return
@@ -290,7 +275,7 @@ export type CheckpointDiffOptions = {
290275}
291276
292277export async function checkpointDiff ( cline : Task , { ts, previousCommitHash, commitHash, mode } : CheckpointDiffOptions ) {
293- const service = await getInitializedCheckpointService ( cline )
278+ const service = await getCheckpointService ( cline )
294279
295280 if ( ! service ) {
296281 return
0 commit comments