Fix #5173: Save checkpoints before tool execution instead of after

- Move checkpoint saving logic to occur before file-modifying tools are executed
- This ensures checkpoints capture the workspace state before changes are made
- Remove old logic that saved checkpoints after tool execution
- Fixes issue where checkpoints were not being created before code modifications
- Restores ability to compare versions and roll back changes as expected
This commit is contained in:
Roo Code 2025-06-30 07:49:37 +00:00
parent 3a8ba27615
commit 5a9c9f099f

View file

@ -406,6 +406,12 @@ export async function presentAssistantMessage(cline: Task) {
}
}
// Save checkpoint before any file-modifying tool is executed
const fileModifyingTools = ["write_to_file", "apply_diff", "insert_content", "search_and_replace"]
if (fileModifyingTools.includes(block.name)) {
await checkpointSave(cline)
}
switch (block.name) {
case "write_to_file":
await writeToFileTool(cline, block, askApproval, handleError, pushToolResult, removeClosingTag)
@ -521,13 +527,8 @@ export async function presentAssistantMessage(cline: Task) {
break
}
const recentlyModifiedFiles = cline.fileContextTracker.getAndClearCheckpointPossibleFile()
if (recentlyModifiedFiles.length > 0) {
// TODO: We can track what file changes were made and only
// checkpoint those files, this will be save storage.
await checkpointSave(cline)
}
// Clear the checkpoint possible files since we now save checkpoints before tool execution
cline.fileContextTracker.getAndClearCheckpointPossibleFile()
// Seeing out of bounds is fine, it means that the next too call is being
// built up and ready to add to assistantMessageContent to present.