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.
This commit is contained in:
Daniel Riccio
2025-01-16 17:13:25 -05:00
parent c0d0548479
commit 3ce2e0c6bf
2 changed files with 20 additions and 6 deletions

View File

@@ -72,6 +72,7 @@ export class Cline {
customInstructions?: string customInstructions?: string
diffStrategy?: DiffStrategy diffStrategy?: DiffStrategy
diffEnabled: boolean = false diffEnabled: boolean = false
fuzzyMatchThreshold: number = 1.0
apiConversationHistory: (Anthropic.MessageParam & { ts?: number })[] = [] apiConversationHistory: (Anthropic.MessageParam & { ts?: number })[] = []
clineMessages: ClineMessage[] = [] clineMessages: ClineMessage[] = []
@@ -120,17 +121,17 @@ export class Cline {
this.browserSession = new BrowserSession(provider.context) this.browserSession = new BrowserSession(provider.context)
this.customInstructions = customInstructions this.customInstructions = customInstructions
this.diffEnabled = enableDiff ?? false this.diffEnabled = enableDiff ?? false
this.fuzzyMatchThreshold = fuzzyMatchThreshold ?? 1.0
// 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.providerRef = new WeakRef(provider) this.providerRef = new WeakRef(provider)
this.diffViewProvider = new DiffViewProvider(cwd)
if (historyItem) { if (historyItem) {
this.taskId = historyItem.id this.taskId = historyItem.id
} }
// Initialize diffStrategy based on current state
this.updateDiffStrategy(experimentalDiffStrategy)
if (task || images) { if (task || images) {
this.startTask(task, images) this.startTask(task, images)
} else if (historyItem) { } 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 // Storing task to disk for history
private async ensureTaskDirectoryExists(): Promise<string> { private async ensureTaskDirectoryExists(): Promise<string> {
@@ -1344,7 +1355,6 @@ export class Cline {
success: false, success: false,
error: "No diff strategy available" error: "No diff strategy available"
} }
console.log("diffResult", diffResult)
if (!diffResult.success) { if (!diffResult.success) {
this.consecutiveMistakeCount++ this.consecutiveMistakeCount++
const currentCount = (this.consecutiveMistakeCountForApplyDiff.get(relPath) || 0) + 1 const currentCount = (this.consecutiveMistakeCountForApplyDiff.get(relPath) || 0) + 1

View File

@@ -1072,6 +1072,10 @@ export class ClineProvider implements vscode.WebviewViewProvider {
break break
case "experimentalDiffStrategy": case "experimentalDiffStrategy":
await this.updateGlobalState("experimentalDiffStrategy", message.bool ?? false) 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() await this.postStateToWebview()
} }
}, },