@@ -167,6 +167,8 @@ export class ClineProvider
167167
168168 this . marketplaceManager = new MarketplaceManager ( this . context , this . customModesManager )
169169
170+ // Forward <most> task events to the provider.
171+ // We do something fairly similar for the IPC-based API.
170172 this . taskCreationCallback = ( instance : Task ) => {
171173 this . emit ( RooCodeEventName . TaskCreated , instance )
172174
@@ -348,18 +350,18 @@ export class ClineProvider
348350 let task = this . clineStack . pop ( )
349351
350352 if ( task ) {
353+ task . emit ( RooCodeEventName . TaskUnfocused )
354+
351355 try {
352356 // Abort the running task and set isAbandoned to true so
353357 // all running promises will exit as well.
354358 await task . abortTask ( true )
355359 } catch ( e ) {
356360 this . log (
357- `[removeClineFromStack] encountered error while aborting task ${ task . taskId } .${ task . instanceId } : ${ e . message } ` ,
361+ `[ClineProvider# removeClineFromStack] abortTask() failed ${ task . taskId } .${ task . instanceId } : ${ e . message } ` ,
358362 )
359363 }
360364
361- task . emit ( RooCodeEventName . TaskUnfocused )
362-
363365 // Remove event listeners before clearing the reference.
364366 const cleanupFunctions = this . taskEventListeners . get ( task )
365367
@@ -407,12 +409,6 @@ export class ClineProvider
407409 await this . getCurrentTask ( ) ?. resumePausedTask ( lastMessage )
408410 }
409411
410- // Clear the current task without treating it as a subtask.
411- // This is used when the user cancels a task that is not a subtask.
412- async clearTask ( ) {
413- await this . removeClineFromStack ( )
414- }
415-
416412 resumeTask ( taskId : string ) : void {
417413 // Use the existing showTaskWithId method which handles both current and historical tasks
418414 this . showTaskWithId ( taskId ) . catch ( ( error ) => {
@@ -1365,6 +1361,16 @@ export class ClineProvider
13651361 await this . createTaskWithHistoryItem ( { ...historyItem , rootTask, parentTask, preservedFCOState } )
13661362 }
13671363
1364+ // Clear the current task without treating it as a subtask.
1365+ // This is used when the user cancels a task that is not a subtask.
1366+ async clearTask ( ) {
1367+ if ( this . clineStack . length > 0 ) {
1368+ const task = this . clineStack [ this . clineStack . length - 1 ]
1369+ console . log ( `[clearTask] clearing task ${ task . taskId } .${ task . instanceId } ` )
1370+ await this . removeClineFromStack ( )
1371+ }
1372+ }
1373+
13681374 async updateCustomInstructions ( instructions ?: string ) {
13691375 // User may be clearing the field.
13701376 await this . updateGlobalState ( "customInstructions" , instructions || undefined )
@@ -1643,6 +1649,7 @@ export class ClineProvider
16431649 } )
16441650 } catch ( error ) {
16451651 console . error ( "Failed to fetch marketplace data:" , error )
1652+
16461653 // Send empty data on error to prevent UI from hanging
16471654 this . postMessageToWebview ( {
16481655 type : "marketplaceData" ,
@@ -2272,24 +2279,23 @@ export class ClineProvider
22722279 if ( bridge ) {
22732280 const currentTask = this . getCurrentTask ( )
22742281
2275- if ( currentTask && ! currentTask . bridge ) {
2282+ if ( currentTask && ! currentTask . enableBridge ) {
22762283 try {
2277- currentTask . bridge = bridge
2278- await currentTask . bridge . subscribeToTask ( currentTask )
2284+ currentTask . enableBridge = true
2285+ await BridgeOrchestrator . subscribeToTask ( currentTask )
22792286 } catch ( error ) {
2280- const message = `[ClineProvider#remoteControlEnabled] subscribeToTask failed - ${ error instanceof Error ? error . message : String ( error ) } `
2287+ const message = `[ClineProvider#remoteControlEnabled] BridgeOrchestrator. subscribeToTask() failed: ${ error instanceof Error ? error . message : String ( error ) } `
22812288 this . log ( message )
22822289 console . error ( message )
22832290 }
22842291 }
22852292 } else {
22862293 for ( const task of this . clineStack ) {
2287- if ( task . bridge ) {
2294+ if ( task . enableBridge ) {
22882295 try {
2289- await task . bridge . unsubscribeFromTask ( task . taskId )
2290- task . bridge = null
2296+ await BridgeOrchestrator . getInstance ( ) ?. unsubscribeFromTask ( task . taskId )
22912297 } catch ( error ) {
2292- const message = `[ClineProvider#remoteControlEnabled] unsubscribeFromTask failed - ${ error instanceof Error ? error . message : String ( error ) } `
2298+ const message = `[ClineProvider#remoteControlEnabled] BridgeOrchestrator# unsubscribeFromTask() failed: ${ error instanceof Error ? error . message : String ( error ) } `
22932299 this . log ( message )
22942300 console . error ( message )
22952301 }
0 commit comments