diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts index 45344c73..251fad02 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.ts +++ b/packages/cli/src/ui/hooks/useGeminiStream.ts @@ -912,17 +912,31 @@ export const useGeminiStream = ( } try { - let commitHash = await gitService?.createFileSnapshot( - `Snapshot for ${toolCall.request.name}`, - ); + if (!gitService) { + onDebugMessage( + `Checkpointing is enabled but Git service is not available. Failed to create snapshot for ${filePath}. Ensure Git is installed and working properly.`, + ); + continue; + } + + let commitHash: string | undefined; + try { + commitHash = await gitService.createFileSnapshot( + `Snapshot for ${toolCall.request.name}`, + ); + } catch (error) { + onDebugMessage( + `Failed to create new snapshot: ${getErrorMessage(error)}. Attempting to use current commit.`, + ); + } if (!commitHash) { - commitHash = await gitService?.getCurrentCommitHash(); + commitHash = await gitService.getCurrentCommitHash(); } if (!commitHash) { onDebugMessage( - `Failed to create snapshot for ${filePath}. Skipping restorable tool call.`, + `Failed to create snapshot for ${filePath}. Checkpointing may not be working properly. Ensure Git is installed and the project directory is accessible.`, ); continue; } @@ -959,9 +973,9 @@ export const useGeminiStream = ( ); } catch (error) { onDebugMessage( - `Failed to write restorable tool call file: ${getErrorMessage( + `Failed to create checkpoint for ${filePath}: ${getErrorMessage( error, - )}`, + )}. This may indicate a problem with Git or file system permissions.`, ); } } diff --git a/packages/core/src/services/gitService.ts b/packages/core/src/services/gitService.ts index f93a5dc6..702df5ae 100644 --- a/packages/core/src/services/gitService.ts +++ b/packages/core/src/services/gitService.ts @@ -31,7 +31,13 @@ export class GitService { 'Checkpointing is enabled, but Git is not installed. Please install Git or disable checkpointing to continue.', ); } - this.setupShadowGitRepository(); + try { + await this.setupShadowGitRepository(); + } catch (error) { + throw new Error( + `Failed to initialize checkpointing: ${error instanceof Error ? error.message : 'Unknown error'}. Please check that Git is working properly or disable checkpointing.`, + ); + } } verifyGitAvailability(): Promise { @@ -105,10 +111,16 @@ export class GitService { } async createFileSnapshot(message: string): Promise { - const repo = this.shadowGitRepository; - await repo.add('.'); - const commitResult = await repo.commit(message); - return commitResult.commit; + try { + const repo = this.shadowGitRepository; + await repo.add('.'); + const commitResult = await repo.commit(message); + return commitResult.commit; + } catch (error) { + throw new Error( + `Failed to create checkpoint snapshot: ${error instanceof Error ? error.message : 'Unknown error'}. Checkpointing may not be working properly.`, + ); + } } async restoreProjectFromSnapshot(commitHash: string): Promise {