@@ -189,9 +189,9 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
189189 abort : boolean = false
190190
191191 // TaskStatus
192- idleAsk ?: IdleAsk
193- resumableAsk ?: ResumableAsk
194- interactiveAsk ?: InteractiveAsk
192+ idleAsk ?: ClineMessage
193+ resumableAsk ?: ClineMessage
194+ interactiveAsk ?: ClineMessage
195195
196196 didFinishAbortingStream = false
197197 abandoned = false
@@ -625,6 +625,16 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
625625 }
626626 }
627627
628+ private findMessageByTimestamp ( ts : number ) : ClineMessage | undefined {
629+ for ( let i = this . clineMessages . length - 1 ; i >= 0 ; i -- ) {
630+ if ( this . clineMessages [ i ] . ts === ts ) {
631+ return this . clineMessages [ i ]
632+ }
633+ }
634+
635+ return undefined
636+ }
637+
628638 // Note that `partial` has three valid states true (partial message),
629639 // false (completion of partial message), undefined (individual complete
630640 // message).
@@ -726,36 +736,48 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
726736 // The state is mutable if the message is complete and the task will
727737 // block (via the `pWaitFor`).
728738 const isBlocking = ! ( this . askResponse !== undefined || this . lastMessageTs !== askTs )
729- const isStateMutable = ! partial && isBlocking
730- let stateMutationTimeouts : NodeJS . Timeout [ ] = [ ]
739+ const isStatusMutable = ! partial && isBlocking
740+ let statusMutationTimeouts : NodeJS . Timeout [ ] = [ ]
731741
732- if ( isStateMutable ) {
742+ if ( isStatusMutable ) {
733743 if ( isInteractiveAsk ( type ) ) {
734- stateMutationTimeouts . push (
744+ statusMutationTimeouts . push (
735745 setTimeout ( ( ) => {
736- this . interactiveAsk = type
737- this . emit ( RooCodeEventName . TaskInteractive , this . taskId )
746+ const message = this . findMessageByTimestamp ( askTs )
747+
748+ if ( message ) {
749+ this . interactiveAsk = message
750+ this . emit ( RooCodeEventName . TaskInteractive , this . taskId )
751+ }
738752 } , 1_000 ) ,
739753 )
740754 } else if ( isResumableAsk ( type ) ) {
741- stateMutationTimeouts . push (
755+ statusMutationTimeouts . push (
742756 setTimeout ( ( ) => {
743- this . resumableAsk = type
744- this . emit ( RooCodeEventName . TaskResumable , this . taskId )
757+ const message = this . findMessageByTimestamp ( askTs )
758+
759+ if ( message ) {
760+ this . resumableAsk = message
761+ this . emit ( RooCodeEventName . TaskResumable , this . taskId )
762+ }
745763 } , 1_000 ) ,
746764 )
747765 } else if ( isIdleAsk ( type ) ) {
748- stateMutationTimeouts . push (
766+ statusMutationTimeouts . push (
749767 setTimeout ( ( ) => {
750- this . idleAsk = type
751- this . emit ( RooCodeEventName . TaskIdle , this . taskId )
768+ const message = this . findMessageByTimestamp ( askTs )
769+
770+ if ( message ) {
771+ this . idleAsk = message
772+ this . emit ( RooCodeEventName . TaskIdle , this . taskId )
773+ }
752774 } , 1_000 ) ,
753775 )
754776 }
755777 }
756778
757779 console . log (
758- `[Task#${ this . taskId } ] pWaitFor askResponse(${ type } ) -> blocking (isStateMutable = ${ isStateMutable } , stateMutationTimeouts = ${ stateMutationTimeouts . length } )` ,
780+ `[Task#${ this . taskId } ] pWaitFor askResponse(${ type } ) -> blocking (isStatusMutable = ${ isStatusMutable } , statusMutationTimeouts = ${ statusMutationTimeouts . length } )` ,
759781 )
760782
761783 await pWaitFor ( ( ) => this . askResponse !== undefined || this . lastMessageTs !== askTs , { interval : 100 } )
@@ -775,7 +797,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
775797 this . askResponseImages = undefined
776798
777799 // Cancel the timeouts if they are still running.
778- stateMutationTimeouts . forEach ( ( timeout ) => clearTimeout ( timeout ) )
800+ statusMutationTimeouts . forEach ( ( timeout ) => clearTimeout ( timeout ) )
779801
780802 // Switch back to an active state.
781803 if ( this . idleAsk || this . resumableAsk || this . interactiveAsk ) {
@@ -2581,7 +2603,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
25812603 return TaskStatus . Running
25822604 }
25832605
2584- public get taskAsk ( ) : ClineAsk | undefined {
2606+ public get taskAsk ( ) : ClineMessage | undefined {
25852607 return this . idleAsk || this . resumableAsk || this . interactiveAsk
25862608 }
25872609}
0 commit comments