@@ -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,15 +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- }
191- }
192-
193185 public async sendMessage ( text ?: string , images ?: string [ ] ) {
194186 await this . sidebarProvider . postMessageToWebview ( { type : "invoke" , invoke : "sendMessage" , text, images } )
195187 }
@@ -212,7 +204,6 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
212204
213205 task . on ( RooCodeEventName . TaskStarted , async ( ) => {
214206 this . emit ( RooCodeEventName . TaskStarted , task . taskId )
215- this . taskMap . set ( task . taskId , provider )
216207 await this . fileLog ( `[${ new Date ( ) . toISOString ( ) } ] taskStarted -> ${ task . taskId } \n` )
217208 } )
218209
@@ -221,16 +212,13 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
221212 isSubtask : ! ! task . parentTaskId ,
222213 } )
223214
224- this . taskMap . delete ( task . taskId )
225-
226215 await this . fileLog (
227216 `[${ new Date ( ) . toISOString ( ) } ] taskCompleted -> ${ task . taskId } | ${ JSON . stringify ( tokenUsage , null , 2 ) } | ${ JSON . stringify ( toolUsage , null , 2 ) } \n` ,
228217 )
229218 } )
230219
231220 task . on ( RooCodeEventName . TaskAborted , ( ) => {
232221 this . emit ( RooCodeEventName . TaskAborted , task . taskId )
233- this . taskMap . delete ( task . taskId )
234222 } )
235223
236224 task . on ( RooCodeEventName . TaskFocused , ( ) => {
@@ -301,6 +289,10 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
301289 this . emit ( RooCodeEventName . TaskAskResponded , task . taskId )
302290 } )
303291
292+ task . on ( RooCodeEventName . QueuedMessagesUpdated , ( taskId , messages ) => {
293+ this . emit ( RooCodeEventName . QueuedMessagesUpdated , taskId , messages )
294+ } )
295+
304296 // Task Analytics
305297
306298 task . on ( RooCodeEventName . TaskToolFailed , ( taskId , tool , error ) => {
0 commit comments