@@ -37,6 +37,10 @@ export abstract class ShadowCheckpointService extends EventEmitter {
3737 return ! ! this . git
3838 }
3939
40+ public getCurrentCheckpoint ( ) : string | undefined {
41+ return this . _checkpoints . length > 0 ? this . _checkpoints [ this . _checkpoints . length - 1 ] : this . baseHash
42+ }
43+
4044 constructor ( taskId : string , checkpointsDir : string , workspaceDir : string , log : ( message : string ) => void ) {
4145 super ( )
4246
@@ -74,7 +78,36 @@ export abstract class ShadowCheckpointService extends EventEmitter {
7478 if ( await fileExistsAtPath ( this . dotGitDir ) ) {
7579 this . log ( `[${ this . constructor . name } #initShadowGit] shadow git repo already exists at ${ this . dotGitDir } ` )
7680 await this . writeExcludeFile ( )
77- this . baseHash = await git . revparse ( [ "HEAD" ] )
81+
82+ // Restore checkpoint history from git log
83+ try {
84+ // Get the initial commit (first commit in the repo)
85+ const initialCommit = await git
86+ . raw ( [ "rev-list" , "--max-parents=0" , "HEAD" ] )
87+ . then ( ( result ) => result . trim ( ) )
88+ this . baseHash = initialCommit
89+
90+ // Get all commits from initial commit to HEAD to restore checkpoint history
91+ const logResult = await git . log ( { from : initialCommit , to : "HEAD" } )
92+ if ( logResult . all . length > 1 ) {
93+ // Skip the first commit (baseHash) and get the rest as checkpoints
94+ this . _checkpoints = logResult . all
95+ . slice ( 0 , - 1 )
96+ . map ( ( commit ) => commit . hash )
97+ . reverse ( )
98+ this . log (
99+ `[${ this . constructor . name } #initShadowGit] restored ${ this . _checkpoints . length } checkpoints from git history` ,
100+ )
101+ } else {
102+ this . baseHash = await git . revparse ( [ "HEAD" ] )
103+ }
104+ } catch ( error ) {
105+ this . log (
106+ `[${ this . constructor . name } #initShadowGit] failed to restore checkpoint history: ${ error instanceof Error ? error . message : String ( error ) } ` ,
107+ )
108+ // Fallback to simple HEAD approach
109+ this . baseHash = await git . revparse ( [ "HEAD" ] )
110+ }
78111 } else {
79112 this . log ( `[${ this . constructor . name } #initShadowGit] creating shadow git repo at ${ this . checkpointsDir } ` )
80113 await git . init ( )
0 commit comments