@@ -30,7 +30,6 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
3030 private readonly sidebarProvider : ClineProvider
3131 private readonly context : vscode . ExtensionContext
3232 private readonly ipc ?: IpcServer
33- private readonly taskMap = new Map < string , ClineProvider > ( )
3433 private readonly log : ( ...args : unknown [ ] ) => void
3534 private logfile ?: string
3635
@@ -65,35 +64,37 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
6564 ipc . listen ( )
6665 this . log ( `[API] ipc server started: socketPath=${ socketPath } , pid=${ process . pid } , ppid=${ process . ppid } ` )
6766
68- ipc . on ( IpcMessageType . TaskCommand , async ( _clientId , { commandName , data } ) => {
69- switch ( commandName ) {
67+ ipc . on ( IpcMessageType . TaskCommand , async ( _clientId , command ) => {
68+ switch ( command . commandName ) {
7069 case TaskCommandName . StartNewTask :
71- this . log ( `[API] StartNewTask -> ${ data . text } , ${ JSON . stringify ( data . configuration ) } ` )
72- await this . startNewTask ( data )
70+ this . log (
71+ `[API] StartNewTask -> ${ command . data . text } , ${ JSON . stringify ( command . data . configuration ) } ` ,
72+ )
73+ await this . startNewTask ( command . data )
7374 break
7475 case TaskCommandName . CancelTask :
75- this . log ( `[API] CancelTask -> ${ data } ` )
76- await this . cancelTask ( data )
76+ this . log ( `[API] CancelTask` )
77+ await this . cancelCurrentTask ( )
7778 break
7879 case TaskCommandName . CloseTask :
79- this . log ( `[API] CloseTask -> ${ data } ` )
80+ this . log ( `[API] CloseTask` )
8081 await vscode . commands . executeCommand ( "workbench.action.files.saveFiles" )
8182 await vscode . commands . executeCommand ( "workbench.action.closeWindow" )
8283 break
8384 case TaskCommandName . ResumeTask :
84- this . log ( `[API] ResumeTask -> ${ data } ` )
85+ this . log ( `[API] ResumeTask -> ${ command . data } ` )
8586 try {
86- await this . resumeTask ( data )
87+ await this . resumeTask ( command . data )
8788 } catch ( error ) {
8889 const errorMessage = error instanceof Error ? error . message : String ( error )
89- this . log ( `[API] ResumeTask failed for taskId ${ data } : ${ errorMessage } ` )
90+ this . log ( `[API] ResumeTask failed for taskId ${ command . data } : ${ errorMessage } ` )
9091 // Don't rethrow - we want to prevent IPC server crashes
9192 // The error is logged for debugging purposes
9293 }
9394 break
9495 case TaskCommandName . SendMessage :
95- this . log ( `[API] SendMessage -> ${ data . text } ` )
96- await this . sendMessage ( data . text , data . images )
96+ this . log ( `[API] SendMessage -> ${ command . data . text } ` )
97+ await this . sendMessage ( command . data . text , command . data . images )
9798 break
9899 }
99100 } )
@@ -181,20 +182,6 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
181182 await this . sidebarProvider . cancelTask ( )
182183 }
183184
184- public async cancelTask ( taskId : string ) {
185- const provider = this . taskMap . get ( taskId )
186-
187- if ( provider ) {
188- await provider . cancelTask ( )
189- this . taskMap . delete ( taskId )
190- } else {
191- // Fallback: taskMap entry may have been removed on TaskCompleted
192- // but the task is still the current task on the provider's stack
193- // (e.g. after SendMessage resumed a completed task).
194- await this . sidebarProvider . cancelTask ( )
195- }
196- }
197-
198185 public async sendMessage ( text ?: string , images ?: string [ ] ) {
199186 await this . sidebarProvider . postMessageToWebview ( { type : "invoke" , invoke : "sendMessage" , text, images } )
200187 }
@@ -217,7 +204,6 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
217204
218205 task . on ( RooCodeEventName . TaskStarted , async ( ) => {
219206 this . emit ( RooCodeEventName . TaskStarted , task . taskId )
220- this . taskMap . set ( task . taskId , provider )
221207 await this . fileLog ( `[${ new Date ( ) . toISOString ( ) } ] taskStarted -> ${ task . taskId } \n` )
222208 } )
223209
@@ -226,16 +212,13 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
226212 isSubtask : ! ! task . parentTaskId ,
227213 } )
228214
229- this . taskMap . delete ( task . taskId )
230-
231215 await this . fileLog (
232216 `[${ new Date ( ) . toISOString ( ) } ] taskCompleted -> ${ task . taskId } | ${ JSON . stringify ( tokenUsage , null , 2 ) } | ${ JSON . stringify ( toolUsage , null , 2 ) } \n` ,
233217 )
234218 } )
235219
236220 task . on ( RooCodeEventName . TaskAborted , ( ) => {
237221 this . emit ( RooCodeEventName . TaskAborted , task . taskId )
238- this . taskMap . delete ( task . taskId )
239222 } )
240223
241224 task . on ( RooCodeEventName . TaskFocused , ( ) => {
0 commit comments