@@ -691,34 +691,37 @@ export class AgenticChatController implements ChatHandlers {
691691 }
692692
693693 #processReadOrList( toolUse : ToolUse , chatResultStream : AgenticChatResultStream ) : ChatMessage | undefined {
694- if ( toolUse . name !== 'fsRead' ) {
695- //TODO: Implement list directory UX in next PR.
696- return { }
697- }
698- let messageId = toolUse . toolUseId || ''
699- if ( chatResultStream . getMessageIdToUpdate ( ) ) {
700- messageId = chatResultStream . getMessageIdToUpdate ( ) !
701- } else if ( messageId ) {
702- chatResultStream . setMessageIdToUpdate ( messageId )
694+ const operationType = toolUse . name === 'fsRead' ? 'read' : 'listDir'
695+ let messageIdToUpdate = toolUse . toolUseId !
696+
697+ if ( operationType === 'read' || operationType === 'listDir' ) {
698+ const currentId = chatResultStream . getMessageIdToUpdateForTool ( operationType )
699+
700+ if ( currentId ) {
701+ messageIdToUpdate = currentId
702+ } else {
703+ chatResultStream . setMessageIdToUpdateForTool ( operationType , messageIdToUpdate )
704+ }
703705 }
706+
704707 const currentPath = ( toolUse . input as unknown as FsReadParams | ListDirectoryParams ) ?. path
705708 if ( ! currentPath ) return
706- const existingPaths = chatResultStream . getMessageOperation ( messageId ) ?. filePaths || [ ]
709+ const existingPaths = chatResultStream . getMessageOperation ( messageIdToUpdate ) ?. filePaths || [ ]
707710 // Check if path already exists in the list
708711 const isPathAlreadyProcessed = existingPaths . some ( path => path . relativeFilePath === currentPath )
709712 if ( ! isPathAlreadyProcessed ) {
710713 const currentFileDetail = {
711714 relativeFilePath : currentPath ,
712715 lineRanges : [ { first : - 1 , second : - 1 } ] ,
713716 }
714- const operationType = toolUse . name === 'fsRead' ? 'read' : 'listDir'
715- if ( operationType === 'read' ) {
716- chatResultStream . addMessageOperation ( messageId , operationType , [ ... existingPaths , currentFileDetail ] )
717- }
717+ chatResultStream . addMessageOperation ( messageIdToUpdate , operationType , [
718+ ... existingPaths ,
719+ currentFileDetail ,
720+ ] )
718721 }
719722 let title : string
720- const itemCount = chatResultStream . getMessageOperation ( messageId ) ?. filePaths . length
721- const filePathsPushed = chatResultStream . getMessageOperation ( messageId ) ?. filePaths ?? [ ]
723+ const itemCount = chatResultStream . getMessageOperation ( messageIdToUpdate ) ?. filePaths . length
724+ const filePathsPushed = chatResultStream . getMessageOperation ( messageIdToUpdate ) ?. filePaths ?? [ ]
722725 if ( ! itemCount ) {
723726 title = 'Gathering context'
724727 } else {
@@ -742,7 +745,7 @@ export class AgenticChatController implements ChatHandlers {
742745 return {
743746 type : 'tool' ,
744747 contextList,
745- messageId,
748+ messageId : messageIdToUpdate ,
746749 body : '' ,
747750 }
748751 }
0 commit comments