Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/core/assistant-message/presentAssistantMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checkpoint is now saved before executing file-modifying tools. Consider wrapping 'await checkpointSave(cline)' in a try/catch block to ensure that a failure in saving a checkpoint doesn't halt tool execution.

}

switch (block.name) {
case "write_to_file":
await writeToFileTool(cline, block, askApproval, handleError, pushToolResult, removeClosingTag)
Expand Down Expand Up @@ -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.
Expand Down