@@ -165,6 +165,8 @@ export class ClineProvider
165165
166166 this . marketplaceManager = new MarketplaceManager ( this . context , this . customModesManager )
167167
168+ // Forward <most> task events to the provider.
169+ // We do something fairly similar for the IPC-based API.
168170 this . taskCreationCallback = ( instance : Task ) => {
169171 this . emit ( RooCodeEventName . TaskCreated , instance )
170172
@@ -346,18 +348,18 @@ export class ClineProvider
346348 let task = this . clineStack . pop ( )
347349
348350 if ( task ) {
351+ task . emit ( RooCodeEventName . TaskUnfocused )
352+
349353 try {
350354 // Abort the running task and set isAbandoned to true so
351355 // all running promises will exit as well.
352356 await task . abortTask ( true )
353357 } catch ( e ) {
354358 this . log (
355- `[removeClineFromStack] encountered error while aborting task ${ task . taskId } .${ task . instanceId } : ${ e . message } ` ,
359+ `[ClineProvider# removeClineFromStack] abortTask() failed ${ task . taskId } .${ task . instanceId } : ${ e . message } ` ,
356360 )
357361 }
358362
359- task . emit ( RooCodeEventName . TaskUnfocused )
360-
361363 // Remove event listeners before clearing the reference.
362364 const cleanupFunctions = this . taskEventListeners . get ( task )
363365
@@ -405,12 +407,6 @@ export class ClineProvider
405407 await this . getCurrentTask ( ) ?. resumePausedTask ( lastMessage )
406408 }
407409
408- // Clear the current task without treating it as a subtask.
409- // This is used when the user cancels a task that is not a subtask.
410- async clearTask ( ) {
411- await this . removeClineFromStack ( )
412- }
413-
414410 resumeTask ( taskId : string ) : void {
415411 // Use the existing showTaskWithId method which handles both current and historical tasks
416412 this . showTaskWithId ( taskId ) . catch ( ( error ) => {
@@ -1307,6 +1303,16 @@ export class ClineProvider
13071303 await this . createTaskWithHistoryItem ( { ...historyItem , rootTask, parentTask } )
13081304 }
13091305
1306+ // Clear the current task without treating it as a subtask.
1307+ // This is used when the user cancels a task that is not a subtask.
1308+ async clearTask ( ) {
1309+ if ( this . clineStack . length > 0 ) {
1310+ const task = this . clineStack [ this . clineStack . length - 1 ]
1311+ console . log ( `[clearTask] clearing task ${ task . taskId } .${ task . instanceId } ` )
1312+ await this . removeClineFromStack ( )
1313+ }
1314+ }
1315+
13101316 async updateCustomInstructions ( instructions ?: string ) {
13111317 // User may be clearing the field.
13121318 await this . updateGlobalState ( "customInstructions" , instructions || undefined )
@@ -1585,6 +1591,7 @@ export class ClineProvider
15851591 } )
15861592 } catch ( error ) {
15871593 console . error ( "Failed to fetch marketplace data:" , error )
1594+
15881595 // Send empty data on error to prevent UI from hanging
15891596 this . postMessageToWebview ( {
15901597 type : "marketplaceData" ,
@@ -2213,24 +2220,23 @@ export class ClineProvider
22132220 if ( bridge ) {
22142221 const currentTask = this . getCurrentTask ( )
22152222
2216- if ( currentTask && ! currentTask . bridge ) {
2223+ if ( currentTask && ! currentTask . enableBridge ) {
22172224 try {
2218- currentTask . bridge = bridge
2219- await currentTask . bridge . subscribeToTask ( currentTask )
2225+ currentTask . enableBridge = true
2226+ await BridgeOrchestrator . subscribeToTask ( currentTask )
22202227 } catch ( error ) {
2221- const message = `[ClineProvider#remoteControlEnabled] subscribeToTask failed - ${ error instanceof Error ? error . message : String ( error ) } `
2228+ const message = `[ClineProvider#remoteControlEnabled] BridgeOrchestrator. subscribeToTask() failed: ${ error instanceof Error ? error . message : String ( error ) } `
22222229 this . log ( message )
22232230 console . error ( message )
22242231 }
22252232 }
22262233 } else {
22272234 for ( const task of this . clineStack ) {
2228- if ( task . bridge ) {
2235+ if ( task . enableBridge ) {
22292236 try {
2230- await task . bridge . unsubscribeFromTask ( task . taskId )
2231- task . bridge = null
2237+ await BridgeOrchestrator . getInstance ( ) ?. unsubscribeFromTask ( task . taskId )
22322238 } catch ( error ) {
2233- const message = `[ClineProvider#remoteControlEnabled] unsubscribeFromTask failed - ${ error instanceof Error ? error . message : String ( error ) } `
2239+ const message = `[ClineProvider#remoteControlEnabled] BridgeOrchestrator# unsubscribeFromTask() failed: ${ error instanceof Error ? error . message : String ( error ) } `
22342240 this . log ( message )
22352241 console . error ( message )
22362242 }
0 commit comments