Skip to content

Commit 52900cf

Browse files
committed
bug fixes
Checkpoints were not being set on continuing a chat so new checkpoints were initialized. Diffs were pulling the wring checkpoints so it was checking against itself
1 parent 5967a60 commit 52900cf

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

src/integrations/editor/DiffViewProvider.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { formatResponse } from "../../core/prompts/responses"
1111
import { diagnosticsToProblemsString, getNewDiagnostics } from "../diagnostics"
1212
import { ClineSayTool } from "../../shared/ExtensionMessage"
1313
import { Task } from "../../core/task/Task"
14+
import { checkpointSave } from "../../core/checkpoints"
1415

1516
import { DecorationController } from "./DecorationController"
1617

@@ -204,9 +205,13 @@ export class DiffViewProvider {
204205
// Track this file change in the FileChangeManager when LLM saves edits
205206
if (task.fileChangeManager && task.checkpointService && this.relPath) {
206207
try {
207-
// Get the current checkpoint to use as the "to" checkpoint
208-
const currentCheckpoint = task.checkpointService.baseHash
209-
if (currentCheckpoint) {
208+
// Create a checkpoint FIRST to capture the file changes
209+
const fileUri = vscode.Uri.file(path.join(task.cwd, this.relPath))
210+
await checkpointSave(task, false, [fileUri])
211+
212+
// Now get the newly created checkpoint
213+
const newCheckpoint = task.checkpointService.getCurrentCheckpoint()
214+
if (newCheckpoint) {
210215
// Calculate line differences
211216
const lineDiff = (
212217
await import("../../services/file-changes/FileChangeManager")
@@ -224,7 +229,7 @@ export class DiffViewProvider {
224229
this.relPath,
225230
changeType,
226231
fromCheckpoint,
227-
currentCheckpoint,
232+
newCheckpoint,
228233
lineDiff.linesAdded,
229234
lineDiff.linesRemoved,
230235
)

src/services/checkpoints/ShadowCheckpointService.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)