From c29816c310f021d99e057425a6f174b5fd0faa01 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sun, 9 Feb 2025 22:44:35 -0800 Subject: [PATCH] Create checkpoint at beginning of task --- src/core/Cline.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 81f5b13d11..7d40127edf 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -2978,6 +2978,12 @@ export class Cline { // get previous api req's index to check token usage and determine if we need to truncate conversation history const previousApiReqIndex = findLastIndex(this.clineMessages, (m) => m.say === "api_req_started") + // Save checkpoint if this is the first API request + const isFirstRequest = this.clineMessages.filter((m) => m.say === "api_req_started").length === 0 + if (isFirstRequest) { + await this.say("checkpoint_created") // no hash since we need to wait for CheckpointTracker to be initialized + } + // getting verbose details is an expensive operation, it uses globby to top-down build file structure of project which for large projects can take a few seconds // for the best UX we show a placeholder api_req_started message with a loading spinner as this happens await this.say( @@ -3001,6 +3007,16 @@ export class Cline { } } + // Now that checkpoint tracker is initialized, update the dummy checkpoint_created message with the commit hash. (This is necessary since we use the API request loading as an opportunity to initialize the checkpoint tracker, which can take some time) + if (isFirstRequest) { + const commitHash = await this.checkpointTracker?.commit() + const lastCheckpointMessage = findLast(this.clineMessages, (m) => m.say === "checkpoint_created") + if (lastCheckpointMessage) { + lastCheckpointMessage.lastCheckpointHash = commitHash + await this.saveClineMessages() + } + } + const [parsedUserContent, environmentDetails] = await this.loadContext(userContent, includeFileDetails) userContent = parsedUserContent // add environment details as its own text block, separate from tool results