@@ -98,6 +98,8 @@ export class Cline {
9898 apiConfiguration : ApiConfiguration ,
9999 customInstructions ?: string ,
100100 diffEnabled ?: boolean ,
101+ isInteractiveMode ?: boolean ,
102+ browserPort ?: string ,
101103 task ?: string ,
102104 images ?: string [ ] ,
103105 historyItem ?: HistoryItem ,
@@ -108,6 +110,8 @@ export class Cline {
108110 this . urlContentFetcher = new UrlContentFetcher ( provider . context )
109111 this . browserSession = new BrowserSession ( provider . context )
110112 this . diffViewProvider = new DiffViewProvider ( cwd )
113+ this . isInteractiveMode = isInteractiveMode ?? false
114+ this . browserPort = browserPort ?? "7333"
111115 this . customInstructions = customInstructions
112116 if ( diffEnabled && this . api . getModel ( ) . id ) {
113117 this . diffStrategy = getDiffStrategy ( this . api . getModel ( ) . id )
@@ -633,48 +637,29 @@ export class Cline {
633637 if ( responseImages && responseImages . length > 0 ) {
634638 newUserContent . push ( ...formatResponse . imageBlocks ( responseImages ) )
635639 }
636- const wasInteractiveBrowser = ( lastRelevantMessageIndex > 0 ) ? modifiedClineMessages [ lastRelevantMessageIndex - 1 ] . text ?. includes ( "interactive mode" ) : false
640+ const state = await this . providerRef . deref ( ) ?. getState ( )
641+ const wasInteractiveBrowser = state ?. isInteractiveMode
637642 let hadBrowserPort = '' ;
638643 if ( wasInteractiveBrowser ) {
639- const match = modifiedClineMessages [ lastRelevantMessageIndex - 1 ] . text ?. match ( / \( b r o w s e r P o r t \s * = \s * ( \d + ) \) / )
640- if ( match ) {
641- hadBrowserPort = match [ 1 ] ?? this . browserPort ;
642- this . providerRef . deref ( ) ?. outputChannel . appendLine ( `resumeTaskFromHistory :: browserPort :: ${ hadBrowserPort } ` )
643- }
644+ hadBrowserPort = state ?. browserPort ;
645+ this . providerRef . deref ( ) ?. outputChannel . appendLine ( `resumeTaskFromHistory :: browserPort :: ${ hadBrowserPort } ` )
644646 }
645647 await this . overwriteApiConversationHistory ( modifiedApiConversationHistory )
646648 await this . initiateTaskLoop ( newUserContent , wasInteractiveBrowser , hadBrowserPort )
647649 }
648650
649651 private async initiateTaskLoop ( userContent : UserContent , wasInteractiveBrowser : boolean = false , hadBrowserPort : string = '' ) : Promise < void > {
650- // Check if any text block contains "interactive mode"
651- const hasInteractiveMode = userContent . some ( ( block ) => {
652- if ( block . type === "text" && typeof block . text === "string" ) {
653- return ( block . type === "text" &&
654- typeof block . text === "string" &&
655- block . text . toLowerCase ( ) . includes ( "interactive mode" ) )
656- } else {
657- return false
658- }
659- }
660- ) || wasInteractiveBrowser ;
652+ const state = await this . providerRef . deref ( ) ?. getState ( )
653+ const hasInteractiveMode = state ?. isInteractiveMode ?? wasInteractiveBrowser
654+
661655
662656 this . providerRef . deref ( ) ?. outputChannel . appendLine ( `initiateTaskLoop :: hasInteractiveMode :: ${ hasInteractiveMode } ` )
663657
664658 // Set interactive mode flag if found in text
665659 if ( hasInteractiveMode ) {
666660 this . isInteractiveMode = true ;
667-
668- // Parse browserPort if specified in text blocks
669- userContent . forEach ( ( block ) => {
670- if ( block . type === "text" && typeof block . text === "string" ) {
671- const match = block . text . match ( / \( b r o w s e r P o r t \s * = \s * ( \d + ) \) / )
672- if ( match ) {
673- this . browserPort = match [ 1 ] ?? hadBrowserPort ;
674- this . providerRef . deref ( ) ?. outputChannel . appendLine ( `initiateTaskLoop :: browserPort :: ${ this . browserPort } ` )
675- }
676- }
677- } )
661+ this . browserPort = state ?. browserPort ?? hadBrowserPort
662+ this . providerRef . deref ( ) ?. outputChannel . appendLine ( `initiateTaskLoop :: browserPort :: ${ this . browserPort } ` )
678663 }
679664
680665 let nextUserContent = userContent ;
@@ -1863,12 +1848,25 @@ export class Cline {
18631848 userContent : UserContent ,
18641849 includeFileDetails : boolean = false ,
18651850 isInteractiveMode : boolean = false ,
1866- browserPort : string = '7333'
1851+ browserPort ? : string
18671852 ) : Promise < boolean > {
1853+ if ( this . presentAssistantMessageHasPendingUpdates ) {
1854+ this . presentAssistantMessage ( )
1855+ }
1856+
1857+ const state = await this . providerRef . deref ( ) ?. getState ( )
1858+ // Use optional chaining and provide defaults
1859+ this . isInteractiveMode = isInteractiveMode ?? state ?. isInteractiveMode ?? false
1860+ this . browserPort = browserPort ?? state ?. browserPort ?? "7333"
1861+
1862+ // Store interactive mode state
1863+ if ( state ?. isInteractiveMode !== undefined ) {
1864+ this . isInteractiveMode = state . isInteractiveMode
1865+ }
1866+
18681867 if ( this . abort ) {
18691868 throw new Error ( "Cline instance aborted" )
18701869 }
1871-
18721870 // Store interactive mode state
18731871 this . isInteractiveMode = isInteractiveMode ;
18741872
0 commit comments