From 1b4dc99e7cc32404e8ec4af331eede6b342b7286 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 8 Jul 2025 13:45:35 -0400 Subject: [PATCH] refactor(grep): remove ripgrep grep tool --- internal/llm/tools/grep.go | 60 ++------------------------------------ 1 file changed, 2 insertions(+), 58 deletions(-) diff --git a/internal/llm/tools/grep.go b/internal/llm/tools/grep.go index 0b39c63484bb9508e14865215bf5e57430efe468..3f3c43c6173c26663a8b9356dd3d34157dd7f465 100644 --- a/internal/llm/tools/grep.go +++ b/internal/llm/tools/grep.go @@ -7,11 +7,9 @@ import ( "fmt" "io" "os" - "os/exec" "path/filepath" "regexp" "sort" - "strconv" "strings" "sync" "time" @@ -248,12 +246,9 @@ func (g *grepTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error) } func searchFiles(pattern, rootPath, include string, limit int) ([]grepMatch, bool, error) { - matches, err := searchWithRipgrep(pattern, rootPath, include) + matches, err := searchFilesWithRegex(pattern, rootPath, include) if err != nil { - matches, err = searchFilesWithRegex(pattern, rootPath, include) - if err != nil { - return nil, false, err - } + return nil, false, err } sort.Slice(matches, func(i, j int) bool { @@ -268,57 +263,6 @@ func searchFiles(pattern, rootPath, include string, limit int) ([]grepMatch, boo return matches, truncated, nil } -func searchWithRipgrep(pattern, path, include string) ([]grepMatch, error) { - cmd := fsext.GetRgSearchCmd(pattern, path, include) - if cmd == nil { - return nil, fmt.Errorf("ripgrep not found in $PATH") - } - - output, err := cmd.Output() - if err != nil { - if exitErr, ok := err.(*exec.ExitError); ok && exitErr.ExitCode() == 1 { - return []grepMatch{}, nil - } - return nil, err - } - - lines := strings.Split(strings.TrimSpace(string(output)), "\n") - matches := make([]grepMatch, 0, len(lines)) - - for _, line := range lines { - if line == "" { - continue - } - - // Parse ripgrep output format: file:line:content - parts := strings.SplitN(line, ":", 3) - if len(parts) < 3 { - continue - } - - filePath := parts[0] - lineNum, err := strconv.Atoi(parts[1]) - if err != nil { - continue - } - lineText := parts[2] - - fileInfo, err := os.Stat(filePath) - if err != nil { - continue // Skip files we can't access - } - - matches = append(matches, grepMatch{ - path: filePath, - modTime: fileInfo.ModTime(), - lineNum: lineNum, - lineText: lineText, - }) - } - - return matches, nil -} - func searchFilesWithRegex(pattern, rootPath, include string) ([]grepMatch, error) { matches := []grepMatch{}