@@ -22,17 +22,20 @@ import {
2222 type ClineSay ,
2323 type ClineAsk ,
2424 type IdleAsk ,
25+ type ResumableAsk ,
2526 type InteractiveAsk ,
2627 type ToolProgressStatus ,
2728 type HistoryItem ,
2829 RooCodeEventName ,
2930 TelemetryEventName ,
31+ TaskStatus ,
3032 TodoItem ,
3133 DEFAULT_CONSECUTIVE_MISTAKE_LIMIT ,
3234 getApiProtocol ,
3335 getModelId ,
3436 isIdleAsk ,
3537 isInteractiveAsk ,
38+ isResumableAsk ,
3639} from "@roo-code/types"
3740import { TelemetryService } from "@roo-code/telemetry"
3841import { CloudService , ExtensionBridgeService } from "@roo-code/cloud"
@@ -184,8 +187,12 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
184187 providerRef : WeakRef < ClineProvider >
185188 private readonly globalStoragePath : string
186189 abort : boolean = false
190+
191+ // TaskStatus
187192 idleAsk ?: IdleAsk
193+ resumableAsk ?: ResumableAsk
188194 interactiveAsk ?: InteractiveAsk
195+
189196 didFinishAbortingStream = false
190197 abandoned = false
191198 isInitialized = false
@@ -293,7 +300,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
293300 this . taskId = historyItem ? historyItem . id : crypto . randomUUID ( )
294301
295302 this . metadata = {
296- taskId : this . taskId ,
297303 task : historyItem ? historyItem . task : task ,
298304 images : historyItem ? [ ] : images ,
299305 }
@@ -500,6 +506,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
500506 if ( this . _taskMode === undefined ) {
501507 throw new Error ( "Task mode accessed before initialization. Use getTaskMode() or wait for taskModeReady." )
502508 }
509+
503510 return this . _taskMode
504511 }
505512
@@ -720,29 +727,39 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
720727 // block (via the `pWaitFor`).
721728 const isBlocking = ! ( this . askResponse !== undefined || this . lastMessageTs !== askTs )
722729 const isStateMutable = ! partial && isBlocking
723-
724- // The task will enter an idle state.
725- let goIdleTimeout : NodeJS . Timeout | undefined
726-
727- if ( isStateMutable && isIdleAsk ( type ) ) {
728- goIdleTimeout = setTimeout ( ( ) => {
729- this . idleAsk = undefined
730- this . emit ( RooCodeEventName . TaskActive , this . taskId )
731- } , 1000 )
730+ let stateMutationTimeouts : NodeJS . Timeout [ ] = [ ]
731+
732+ if ( isStateMutable ) {
733+ if ( isInteractiveAsk ( type ) ) {
734+ stateMutationTimeouts . push (
735+ setTimeout ( ( ) => {
736+ this . interactiveAsk = type
737+ this . emit ( RooCodeEventName . TaskInteractive , this . taskId , type , askTs )
738+ } , 1_000 ) ,
739+ )
740+ } else if ( isResumableAsk ( type ) ) {
741+ stateMutationTimeouts . push (
742+ setTimeout ( ( ) => {
743+ this . resumableAsk = type
744+ this . emit ( RooCodeEventName . TaskResumable , this . taskId )
745+ } , 1_000 ) ,
746+ )
747+ } else if ( isIdleAsk ( type ) ) {
748+ stateMutationTimeouts . push (
749+ setTimeout ( ( ) => {
750+ this . idleAsk = type
751+ this . emit ( RooCodeEventName . TaskIdle , this . taskId )
752+ } , 1_000 ) ,
753+ )
754+ }
732755 }
733756
734- // The task will enter a "user interaction required" state.
735- let goInteractiveTimeout : NodeJS . Timeout | undefined
736-
737- if ( isStateMutable && ! isInteractiveAsk ( type ) ) {
738- goInteractiveTimeout = setTimeout ( ( ) => {
739- this . interactiveAsk = undefined
740- this . emit ( RooCodeEventName . TaskActive , this . taskId )
741- } , 1000 )
742- }
757+ console . log (
758+ `[Task#${ this . taskId } ] pWaitFor askResponse(${ type } ) -> blocking (isStateMutable = ${ isStateMutable } , stateMutationTimeouts = ${ stateMutationTimeouts . length } )` ,
759+ )
743760
744- console . log ( `[Task#${ this . taskId } ] pWaitFor askResponse(${ type } ) -> blocking` )
745761 await pWaitFor ( ( ) => this . askResponse !== undefined || this . lastMessageTs !== askTs , { interval : 100 } )
762+
746763 console . log ( `[Task#${ this . taskId } ] pWaitFor askResponse(${ type } ) -> unblocked (${ this . askResponse } )` )
747764
748765 if ( this . lastMessageTs !== askTs ) {
@@ -758,20 +775,12 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
758775 this . askResponseImages = undefined
759776
760777 // Cancel the timeouts if they are still running.
761- if ( goIdleTimeout ) {
762- clearTimeout ( goIdleTimeout )
763- }
764-
765- if ( goInteractiveTimeout ) {
766- clearTimeout ( goInteractiveTimeout )
767- }
768-
769- goIdleTimeout = undefined
770- goInteractiveTimeout = undefined
778+ stateMutationTimeouts . forEach ( ( timeout ) => clearTimeout ( timeout ) )
771779
772780 // Switch back to an active state.
773- if ( this . idleAsk || this . interactiveAsk ) {
781+ if ( this . idleAsk || this . resumableAsk || this . interactiveAsk ) {
774782 this . idleAsk = undefined
783+ this . resumableAsk = undefined
775784 this . interactiveAsk = undefined
776785 this . emit ( RooCodeEventName . TaskActive , this . taskId )
777786 }
@@ -1066,12 +1075,11 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
10661075 }
10671076
10681077 public async resumePausedTask ( lastMessage : string ) {
1069- // Release this Cline instance from paused state.
10701078 this . isPaused = false
1071- this . emit ( RooCodeEventName . TaskUnpaused )
1079+ this . emit ( RooCodeEventName . TaskUnpaused , this . taskId )
10721080
10731081 // Fake an answer from the subtask that it has completed running and
1074- // this is the result of what it has done add the message to the chat
1082+ // this is the result of what it has done add the message to the chat
10751083 // history and to the webview ui.
10761084 try {
10771085 await this . say ( "subtask_result" , lastMessage )
@@ -2556,4 +2564,24 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
25562564 public get cwd ( ) {
25572565 return this . workspacePath
25582566 }
2567+
2568+ public get taskStatus ( ) : TaskStatus {
2569+ if ( this . interactiveAsk ) {
2570+ return TaskStatus . Interactive
2571+ }
2572+
2573+ if ( this . resumableAsk ) {
2574+ return TaskStatus . Resumable
2575+ }
2576+
2577+ if ( this . idleAsk ) {
2578+ return TaskStatus . Idle
2579+ }
2580+
2581+ return TaskStatus . Running
2582+ }
2583+
2584+ public get taskAsk ( ) : ClineAsk | undefined {
2585+ return this . idleAsk || this . resumableAsk || this . interactiveAsk
2586+ }
25592587}
0 commit comments