@@ -71,6 +71,7 @@ import { ConversationTracker } from '../../../storages/conversationTracker'
7171import { waitTimeout , Timeout } from '../../../../shared/utilities/timeoutUtils'
7272import { FsReadParams } from '../../../tools/fsRead'
7373import { ListDirectoryParams } from '../../../tools/listDirectory'
74+ import { SanitizedRipgrepOutput } from '../../../tools/grepSearch'
7475
7576export type StaticTextResponseType = 'quick-action-help' | 'onboarding-help' | 'transform' | 'help'
7677
@@ -307,7 +308,13 @@ export class Messenger {
307308 let explanation : string | undefined = undefined
308309 let changeList : Change [ ] | undefined = undefined
309310 let messageIdToUpdate : string | undefined = undefined
310- const isReadOrList : boolean = [ ToolType . FsRead , ToolType . ListDirectory ] . includes (
311+ // eslint-disable-next-line prettier/prettier
312+ const isReadOrList : boolean = [
313+ ToolType . FsRead ,
314+ ToolType . ListDirectory ,
315+ ToolType . GrepSearch ,
316+ ] . includes (
317+ // eslint-disable-next-line prettier/prettier
311318 tool . type
312319 )
313320 if ( tool . type === ToolType . ExecuteBash ) {
@@ -391,6 +398,12 @@ export class Messenger {
391398 ) {
392399 session . setMessageIdToUpdateListDirectory ( toolUse . toolUseId )
393400 }
401+ if (
402+ session . messageIdToUpdateGrepSearch === undefined &&
403+ tool . type === ToolType . GrepSearch
404+ ) {
405+ session . setMessageIdToUpdateGrepSearch ( toolUse . toolUseId )
406+ }
394407 getLogger ( ) . debug (
395408 `SetToolUseWithError: ${ toolUse . name } :${ toolUse . toolUseId } with no error`
396409 )
@@ -743,6 +756,80 @@ export class Messenger {
743756 )
744757 }
745758
759+ private sendGrepSearchToolMessage (
760+ message : string ,
761+ toolUse : ToolUse ,
762+ session : ChatSession ,
763+ tabID : string ,
764+ triggerID : string ,
765+ messageIdToUpdate ?: string
766+ ) {
767+ getLogger ( ) . info ( `Grep search update message is: "${ message } "` )
768+ let searchResults = session . searchResults
769+
770+ // Check if the message contains grep search results
771+ if ( message . includes ( 'Found' ) && message . includes ( 'matches' ) ) {
772+ try {
773+ // Remove the first line summary if present
774+ const jsonStartIndex = message . indexOf ( '{' )
775+ if ( jsonStartIndex !== - 1 ) {
776+ const jsonString = message . substring ( jsonStartIndex )
777+
778+ // Parse the JSON string to get the SanitizedRipgrepOutput
779+ const ripgrepOutput : SanitizedRipgrepOutput = JSON . parse ( jsonString )
780+
781+ // Convert the fileMatches to the format expected by session.searchResults
782+ searchResults = ripgrepOutput . fileMatches . map ( ( file ) => ( {
783+ relativeFilePath : file . filePath ,
784+ // Get line numbers from the matches object
785+ lineRanges : Object . keys ( file . matches || { } ) . map ( ( lineNum ) => ( {
786+ first : parseInt ( lineNum , 10 ) ,
787+ second : parseInt ( lineNum , 10 ) ,
788+ } ) ) ,
789+ } ) )
790+
791+ // Store the search results in the session for context transparency
792+ session . setSearchResults ( searchResults )
793+ }
794+ } catch ( error ) {
795+ getLogger ( ) . error ( `Error parsing grep search results: ${ error } ` )
796+ }
797+ }
798+
799+ const contextList = session . searchResults
800+
801+ const itemCount = contextList . length
802+
803+ // Create a title based on search results
804+ const title =
805+ itemCount === 0 ? 'No search results found' : `Found ${ itemCount } match${ itemCount !== 1 ? 'es' : '' } `
806+
807+ // Send the tool message with the context list
808+ this . dispatcher . sendToolMessage (
809+ new ToolMessage (
810+ {
811+ message : '' ,
812+ messageType : 'answer-part' ,
813+ followUps : undefined ,
814+ followUpsHeader : undefined ,
815+ relatedSuggestions : undefined ,
816+ triggerID,
817+ messageID : messageIdToUpdate ?? toolUse ?. toolUseId ?? '' ,
818+ userIntent : undefined ,
819+ codeBlockLanguage : undefined ,
820+ contextList,
821+ canBeVoted : false ,
822+ buttons : undefined ,
823+ fullWidth : false ,
824+ padding : false ,
825+ codeBlockActions : undefined ,
826+ rootFolderTitle : title ,
827+ } ,
828+ tabID
829+ )
830+ )
831+ }
832+
746833 public sendPartialToolLog (
747834 message : string ,
748835 tabID : string ,
@@ -757,12 +844,18 @@ export class Messenger {
757844 return
758845 }
759846
760- // Handle read tool and list directory messages
847+ // Handle read tool, grep search, and list directory messages
761848 if (
762- ( toolUse ?. name === ToolType . FsRead || toolUse ?. name === ToolType . ListDirectory ) &&
849+ ( toolUse ?. name === ToolType . FsRead ||
850+ toolUse ?. name === ToolType . ListDirectory ||
851+ toolUse ?. name === ToolType . GrepSearch ) &&
763852 ! validation . requiresAcceptance
764853 ) {
765- return this . sendReadAndListDirToolMessage ( toolUse , session , tabID , triggerID , messageIdToUpdate )
854+ if ( toolUse ?. name === ToolType . GrepSearch ) {
855+ return this . sendGrepSearchToolMessage ( message , toolUse , session , tabID , triggerID , messageIdToUpdate )
856+ } else {
857+ return this . sendReadAndListDirToolMessage ( toolUse , session , tabID , triggerID , messageIdToUpdate )
858+ }
766859 }
767860
768861 // Handle file write tool, execute bash tool and bash command output log messages
0 commit comments