diff --git a/.changeset/polite-mangos-report.md b/.changeset/polite-mangos-report.md new file mode 100644 index 00000000..6264fcf7 --- /dev/null +++ b/.changeset/polite-mangos-report.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Add support for bad commitHashes already stored in ui_messages.json diff --git a/src/integrations/checkpoints/CheckpointTracker.ts b/src/integrations/checkpoints/CheckpointTracker.ts index 756fa1ef..b0dcae6e 100644 --- a/src/integrations/checkpoints/CheckpointTracker.ts +++ b/src/integrations/checkpoints/CheckpointTracker.ts @@ -46,6 +46,14 @@ class CheckpointTracker { private lastRetrievedShadowGitConfigWorkTree?: string private gitOperations: GitOperations + /** + * Helper method to clean commit hashes that might have a "HEAD " prefix. + * Used for backward compatibility with old tasks that stored hashes with the prefix. + */ + private cleanCommitHash(hash: string): string { + return hash.startsWith("HEAD ") ? hash.slice(5) : hash + } + /** * Creates a new CheckpointTracker instance to manage checkpoints for a specific task. * The constructor is private - use the static create() method to instantiate. @@ -242,7 +250,7 @@ class CheckpointTracker { const gitPath = await getShadowGitPath(this.globalStoragePath, this.taskId, this.cwdHash) const git = simpleGit(path.dirname(gitPath)) console.debug(`Using shadow git at: ${gitPath}`) - await git.reset(["--hard", commitHash]) // Hard reset to target commit + await git.reset(["--hard", this.cleanCommitHash(commitHash)]) // Hard reset to target commit console.debug(`Successfully reset to checkpoint: ${commitHash}`) const durationMs = Math.round(performance.now() - startTime) @@ -283,7 +291,8 @@ class CheckpointTracker { // Stage all changes so that untracked files appear in diff summary await this.gitOperations.addCheckpointFiles(git) - const diffRange = rhsHash ? `${lhsHash}..${rhsHash}` : lhsHash + const cleanRhs = rhsHash ? this.cleanCommitHash(rhsHash) : undefined + const diffRange = cleanRhs ? `${this.cleanCommitHash(lhsHash)}..${cleanRhs}` : this.cleanCommitHash(lhsHash) console.info(`Diff range: ${diffRange}`) const diffSummary = await git.diffSummary([diffRange]) @@ -294,7 +303,7 @@ class CheckpointTracker { let beforeContent = "" try { - beforeContent = await git.show([`${lhsHash}:${filePath}`]) + beforeContent = await git.show([`${this.cleanCommitHash(lhsHash)}:${filePath}`]) } catch (_) { // file didn't exist in older commit => remains empty } @@ -302,7 +311,7 @@ class CheckpointTracker { let afterContent = "" if (rhsHash) { try { - afterContent = await git.show([`${rhsHash}:${filePath}`]) + afterContent = await git.show([`${this.cleanCommitHash(rhsHash)}:${filePath}`]) } catch (_) { // file didn't exist in newer commit => remains empty } @@ -347,7 +356,8 @@ class CheckpointTracker { // Stage all changes so that untracked files appear in diff summary await this.gitOperations.addCheckpointFiles(git) - const diffRange = rhsHash ? `${lhsHash}..${rhsHash}` : lhsHash + const cleanRhs = rhsHash ? this.cleanCommitHash(rhsHash) : undefined + const diffRange = cleanRhs ? `${this.cleanCommitHash(lhsHash)}..${cleanRhs}` : this.cleanCommitHash(lhsHash) const diffSummary = await git.diffSummary([diffRange]) const durationMs = Math.round(performance.now() - startTime)