11import { GrokClient , GrokMessage , GrokToolCall } from "../grok/client" ;
22import { GROK_TOOLS } from "../grok/tools" ;
3- import { TextEditorTool , BashTool , TodoTool , ConfirmationTool } from "../tools" ;
3+ import {
4+ TextEditorTool ,
5+ BashTool ,
6+ TodoTool ,
7+ ConfirmationTool ,
8+ SearchTool ,
9+ } from "../tools" ;
410import { ToolResult } from "../types" ;
511import { EventEmitter } from "events" ;
612import { createTokenCounter , TokenCounter } from "../utils/token-counter" ;
@@ -31,6 +37,7 @@ export class GrokAgent extends EventEmitter {
3137 private bash : BashTool ;
3238 private todoTool : TodoTool ;
3339 private confirmationTool : ConfirmationTool ;
40+ private search : SearchTool ;
3441 private chatHistory : ChatEntry [ ] = [ ] ;
3542 private messages : GrokMessage [ ] = [ ] ;
3643 private tokenCounter : TokenCounter ;
@@ -43,6 +50,7 @@ export class GrokAgent extends EventEmitter {
4350 this . bash = new BashTool ( ) ;
4451 this . todoTool = new TodoTool ( ) ;
4552 this . confirmationTool = new ConfirmationTool ( ) ;
53+ this . search = new SearchTool ( ) ;
4654 this . tokenCounter = createTokenCounter ( "grok-4-latest" ) ;
4755
4856 // Load custom instructions
@@ -61,6 +69,7 @@ You have access to these tools:
6169- create_file: Create new files with content (ONLY use this for files that don't exist yet)
6270- str_replace_editor: Replace text in existing files (ALWAYS use this to edit or update existing files)
6371- bash: Execute bash commands (use for searching, file discovery, navigation, and system operations)
72+ - search: Unified search tool for finding text content or files (similar to Cursor's search functionality)
6473- create_todo_list: Create a visual todo list for planning and tracking tasks
6574- update_todo_list: Update existing todos in your todo list
6675
@@ -74,9 +83,9 @@ IMPORTANT TOOL USAGE RULES:
7483- Use create_file ONLY when creating entirely new files that don't exist
7584
7685SEARCHING AND EXPLORATION:
77- - Use bash with commands like 'find', 'grep', 'rg' (ripgrep), 'ls', etc. for searching files and content
78- - Examples: 'find . -name "*.js"', 'grep -r "function" src/', 'rg "import.*react"'
79- - Use bash for directory navigation, file discovery, and content searching
86+ - Use search for fast, powerful text search across files or finding files by name (unified search tool)
87+ - Examples: search for text content like "import.*react", search for files like "component.tsx"
88+ - Use bash with commands like 'find', 'grep', 'rg', 'ls' for complex file operations and navigation
8089- view_file is best for reading specific files you already know exist
8190
8291When a user asks you to edit, update, modify, or change an existing file:
@@ -550,6 +559,19 @@ Current working directory: ${process.cwd()}`,
550559 case "update_todo_list" :
551560 return await this . todoTool . updateTodoList ( args . updates ) ;
552561
562+ case "search" :
563+ return await this . search . search ( args . query , {
564+ searchType : args . search_type ,
565+ includePattern : args . include_pattern ,
566+ excludePattern : args . exclude_pattern ,
567+ caseSensitive : args . case_sensitive ,
568+ wholeWord : args . whole_word ,
569+ regex : args . regex ,
570+ maxResults : args . max_results ,
571+ fileTypes : args . file_types ,
572+ includeHidden : args . include_hidden ,
573+ } ) ;
574+
553575 default :
554576 return {
555577 success : false ,
0 commit comments