Compare commits

...

3 Commits

Author SHA1 Message Date
Marlon Monroy 080c3dd12d refactor: Remove unused import 2025-03-17 20:33:42 -07:00
Marlon Monroy 4a74bba420 refactor: Pass checkpointTracker as a dependency 2025-03-17 20:31:01 -07:00
Marlon Monroy 8cf35aa41a refactor: Start isolating dependencies from Cline.ts 2025-03-17 20:30:20 -07:00
3 changed files with 53 additions and 33 deletions
+26 -31
View File
@@ -97,7 +97,7 @@ export class Cline {
didFinishAbortingStream = false
abandoned = false
private diffViewProvider: DiffViewProvider
private checkpointTracker?: CheckpointTracker
private checkpointTracker: CheckpointTracker
checkpointTrackerErrorMessage?: string
conversationHistoryDeletedRange?: [number, number]
isInitialized = false
@@ -124,6 +124,7 @@ export class Cline {
autoApprovalSettings: AutoApprovalSettings,
browserSettings: BrowserSettings,
chatSettings: ChatSettings,
checkpointTracker: CheckpointTracker,
customInstructions?: string,
task?: string,
images?: string[],
@@ -144,6 +145,8 @@ export class Cline {
this.autoApprovalSettings = autoApprovalSettings
this.browserSettings = browserSettings
this.chatSettings = chatSettings
this.checkpointTracker = checkpointTracker
if (historyItem) {
this.taskId = historyItem.id
this.conversationHistoryDeletedRange = historyItem.conversationHistoryDeletedRange
@@ -297,22 +300,18 @@ export class Cline {
break
case "taskAndWorkspace":
case "workspace":
if (!this.checkpointTracker && !this.checkpointTrackerErrorMessage) {
try {
this.checkpointTracker = await CheckpointTracker.create(
this.taskId,
this.providerRef.deref()?.context.globalStorageUri.fsPath,
)
} catch (error) {
const errorMessage = error instanceof Error ? error.message : "Unknown error"
console.error("Failed to initialize checkpoint tracker:", errorMessage)
this.checkpointTrackerErrorMessage = errorMessage
await this.providerRef.deref()?.postStateToWebview()
vscode.window.showErrorMessage(errorMessage)
didWorkspaceRestoreFail = true
}
try {
await this.checkpointTracker.trackCheckpointsForTask(this.taskId)
this.checkpointTrackerErrorMessage = undefined
} catch (error) {
const errorMessage = error instanceof Error ? error.message : "Unknown error"
console.error("Failed to initialize checkpoint tracker:", errorMessage)
this.checkpointTrackerErrorMessage = errorMessage
await this.providerRef.deref()?.postStateToWebview()
vscode.window.showErrorMessage(errorMessage)
didWorkspaceRestoreFail = true
}
if (message.lastCheckpointHash && this.checkpointTracker) {
if (message.lastCheckpointHash) {
try {
await this.checkpointTracker.resetHead(message.lastCheckpointHash)
} catch (error) {
@@ -412,21 +411,17 @@ export class Cline {
}
// TODO: handle if this is called from outside original workspace, in which case we need to show user error message we cant show diff outside of workspace?
if (!this.checkpointTracker && !this.checkpointTrackerErrorMessage) {
try {
this.checkpointTracker = await CheckpointTracker.create(
this.taskId,
this.providerRef.deref()?.context.globalStorageUri.fsPath,
)
} catch (error) {
const errorMessage = error instanceof Error ? error.message : "Unknown error"
console.error("Failed to initialize checkpoint tracker:", errorMessage)
this.checkpointTrackerErrorMessage = errorMessage
await this.providerRef.deref()?.postStateToWebview()
vscode.window.showErrorMessage(errorMessage)
relinquishButton()
return
}
try {
this.checkpointTracker.trackCheckpointsForTask(this.taskId)
this.checkpointTrackerErrorMessage = undefined
} catch (error) {
const errorMessage = error instanceof Error ? error.message : "Unknown error"
console.error("Failed to initialize checkpoint tracker:", errorMessage)
this.checkpointTrackerErrorMessage = errorMessage
await this.providerRef.deref()?.postStateToWebview()
vscode.window.showErrorMessage(errorMessage)
relinquishButton()
return
}
let changedFiles:
-1
View File
@@ -35,7 +35,6 @@ import { getUri } from "./getUri"
import { telemetryService } from "../../services/telemetry/TelemetryService"
import { TelemetrySetting } from "../../shared/TelemetrySetting"
import { cleanupLegacyCheckpoints } from "../../integrations/checkpoints/CheckpointMigration"
import CheckpointTracker from "../../integrations/checkpoints/CheckpointTracker"
/*
https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
@@ -45,6 +45,7 @@ class CheckpointTracker {
private cwdHash: string
private lastRetrievedShadowGitConfigWorkTree?: string
private gitOperations: GitOperations
private currentGitPath?: string
/**
* Creates a new CheckpointTracker instance to manage checkpoints for a specific task.
@@ -54,6 +55,7 @@ class CheckpointTracker {
* @param cwd - The current working directory to track files in
* @param cwdHash - Hash of the working directory path for shadow git organization
*/
private constructor(globalStoragePath: string, taskId: string, cwd: string, cwdHash: string) {
this.globalStoragePath = globalStoragePath
this.taskId = taskId
@@ -62,6 +64,30 @@ class CheckpointTracker {
this.gitOperations = new GitOperations(cwd)
}
public async trackCheckpointsForTask(taskId: string) {
//TODO: Should we throw if feature is not enabled?
if (this.isEnabled()) {
console.log("checkpoints are not enabled, task with id %s not tracked", taskId)
return
}
await this.initShadowGit()
const gitPath = ""
this.gitOperations.initShadowGit(gitPath, this.cwd)
telemetryService.captureCheckpointUsage(taskId, "shadow_git_initialized")
}
private async initShadowGit() {
try {
await simpleGit().version()
} catch (error) {
throw new Error("Git must be installed to use checkpoints.") // FIXME: must match what we check for in TaskHeader to show link
}
}
private isEnabled() {
return vscode.workspace.getConfiguration("cline").get<boolean>("enableCheckpoints") ?? true
}
/**
* Creates a new CheckpointTracker instance for tracking changes in a task.
* Handles initialization of the shadow git repository.
@@ -200,7 +226,7 @@ class CheckpointTracker {
* - Shadow git repository doesn't exist
* - Config read fails
* - No worktree is configured
* @throws Error if unable to:
* logs Error if unable to:
* - Access shadow git path
* - Initialize simple-git
* - Read git configuration