@@ -52,6 +52,7 @@ import { detectCodeOmission } from "../integrations/editor/detect-omission"
5252import { BrowserSession } from "../services/browser/BrowserSession"
5353import { OpenRouterHandler } from "../api/providers/openrouter"
5454import { McpHub } from "../services/mcp/McpHub"
55+ import crypto from "crypto"
5556
5657const cwd =
5758 vscode . workspace . workspaceFolders ?. map ( ( folder ) => folder . uri . fsPath ) . at ( 0 ) ?? path . join ( os . homedir ( ) , "Desktop" ) // may or may not exist but fs checking existence would immediately ask for permission which would be bad UX, need to come up with a better solution
@@ -71,6 +72,7 @@ export class Cline {
7172 customInstructions ?: string
7273 diffStrategy ?: DiffStrategy
7374 diffEnabled : boolean = false
75+ fuzzyMatchThreshold : number = 1.0
7476
7577 apiConversationHistory : ( Anthropic . MessageParam & { ts ?: number } ) [ ] = [ ]
7678 clineMessages : ClineMessage [ ] = [ ]
@@ -105,28 +107,46 @@ export class Cline {
105107 fuzzyMatchThreshold ?: number ,
106108 task ?: string | undefined ,
107109 images ?: string [ ] | undefined ,
108- historyItem ?: HistoryItem | undefined
110+ historyItem ?: HistoryItem | undefined ,
111+ experimentalDiffStrategy : boolean = false ,
109112 ) {
110- this . providerRef = new WeakRef ( provider )
113+ if ( ! task && ! images && ! historyItem ) {
114+ throw new Error ( 'Either historyItem or task/images must be provided' ) ;
115+ }
116+
117+ this . taskId = crypto . randomUUID ( )
111118 this . api = buildApiHandler ( apiConfiguration )
112119 this . terminalManager = new TerminalManager ( )
113120 this . urlContentFetcher = new UrlContentFetcher ( provider . context )
114121 this . browserSession = new BrowserSession ( provider . context )
115- this . diffViewProvider = new DiffViewProvider ( cwd )
116122 this . customInstructions = customInstructions
117123 this . diffEnabled = enableDiff ?? false
118- if ( this . diffEnabled && this . api . getModel ( ) . id ) {
119- this . diffStrategy = getDiffStrategy ( this . api . getModel ( ) . id , fuzzyMatchThreshold ?? 1.0 )
120- }
124+ this . fuzzyMatchThreshold = fuzzyMatchThreshold ?? 1.0
125+ this . providerRef = new WeakRef ( provider )
126+ this . diffViewProvider = new DiffViewProvider ( cwd )
127+
121128 if ( historyItem ) {
122129 this . taskId = historyItem . id
123- this . resumeTaskFromHistory ( )
124- } else if ( task || images ) {
125- this . taskId = Date . now ( ) . toString ( )
130+ }
131+
132+ // Initialize diffStrategy based on current state
133+ this . updateDiffStrategy ( experimentalDiffStrategy )
134+
135+ if ( task || images ) {
126136 this . startTask ( task , images )
127- } else {
128- throw new Error ( "Either historyItem or task/images must be provided" )
137+ } else if ( historyItem ) {
138+ this . resumeTaskFromHistory ( )
139+ }
140+ }
141+
142+ // Add method to update diffStrategy
143+ async updateDiffStrategy ( experimentalDiffStrategy ?: boolean ) {
144+ // If not provided, get from current state
145+ if ( experimentalDiffStrategy === undefined ) {
146+ const { experimentalDiffStrategy : stateExperimentalDiffStrategy } = await this . providerRef . deref ( ) ?. getState ( ) ?? { }
147+ experimentalDiffStrategy = stateExperimentalDiffStrategy ?? false
129148 }
149+ this . diffStrategy = getDiffStrategy ( this . api . getModel ( ) . id , this . fuzzyMatchThreshold , experimentalDiffStrategy )
130150 }
131151
132152 // Storing task to disk for history
@@ -1326,7 +1346,7 @@ export class Cline {
13261346 const originalContent = await fs . readFile ( absolutePath , "utf-8" )
13271347
13281348 // Apply the diff to the original content
1329- const diffResult = this . diffStrategy ?. applyDiff (
1349+ const diffResult = await this . diffStrategy ?. applyDiff (
13301350 originalContent ,
13311351 diffContent ,
13321352 parseInt ( block . params . start_line ?? '' ) ,
0 commit comments