From 3ce2e0c6bf9e24c58203cc4fb90fa262cbe7f820 Mon Sep 17 00:00:00 2001 From: Daniel Riccio Date: Thu, 16 Jan 2025 17:13:25 -0500 Subject: [PATCH] feat: update diff strategy dynamically - Added `updateDiffStrategy` method to dynamically adjust the diff strategy based on the current state and experimental settings. - Updated ClineProvider to call `updateDiffStrategy` when the experimental diff strategy is modified, ensuring real-time updates in the Cline instance. --- src/core/Cline.ts | 22 ++++++++++++++++------ src/core/webview/ClineProvider.ts | 4 ++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index cbac9df..4487521 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -72,6 +72,7 @@ export class Cline { customInstructions?: string diffStrategy?: DiffStrategy diffEnabled: boolean = false + fuzzyMatchThreshold: number = 1.0 apiConversationHistory: (Anthropic.MessageParam & { ts?: number })[] = [] clineMessages: ClineMessage[] = [] @@ -120,17 +121,17 @@ export class Cline { this.browserSession = new BrowserSession(provider.context) this.customInstructions = customInstructions this.diffEnabled = enableDiff ?? false - - // Prioritize experimentalDiffStrategy from history item if available - const effectiveExperimentalDiffStrategy = historyItem?.experimentalDiffStrategy ?? experimentalDiffStrategy - this.diffStrategy = getDiffStrategy(this.api.getModel().id, fuzzyMatchThreshold ?? 1.0, effectiveExperimentalDiffStrategy) - this.diffViewProvider = new DiffViewProvider(cwd) + this.fuzzyMatchThreshold = fuzzyMatchThreshold ?? 1.0 this.providerRef = new WeakRef(provider) + this.diffViewProvider = new DiffViewProvider(cwd) if (historyItem) { this.taskId = historyItem.id } + // Initialize diffStrategy based on current state + this.updateDiffStrategy(experimentalDiffStrategy) + if (task || images) { this.startTask(task, images) } else if (historyItem) { @@ -138,6 +139,16 @@ export class Cline { } } + // Add method to update diffStrategy + async updateDiffStrategy(experimentalDiffStrategy?: boolean) { + // If not provided, get from current state + if (experimentalDiffStrategy === undefined) { + const { experimentalDiffStrategy: stateExperimentalDiffStrategy } = await this.providerRef.deref()?.getState() ?? {} + experimentalDiffStrategy = stateExperimentalDiffStrategy ?? false + } + this.diffStrategy = getDiffStrategy(this.api.getModel().id, this.fuzzyMatchThreshold, experimentalDiffStrategy) + } + // Storing task to disk for history private async ensureTaskDirectoryExists(): Promise { @@ -1344,7 +1355,6 @@ export class Cline { success: false, error: "No diff strategy available" } - console.log("diffResult", diffResult) if (!diffResult.success) { this.consecutiveMistakeCount++ const currentCount = (this.consecutiveMistakeCountForApplyDiff.get(relPath) || 0) + 1 diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 68b8d29..100dcaa 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -1072,6 +1072,10 @@ export class ClineProvider implements vscode.WebviewViewProvider { break case "experimentalDiffStrategy": await this.updateGlobalState("experimentalDiffStrategy", message.bool ?? false) + // Update diffStrategy in current Cline instance if it exists + if (this.cline) { + await this.cline.updateDiffStrategy(message.bool ?? false) + } await this.postStateToWebview() } },