diff --git a/internal/fsext/fileutil.go b/internal/fsext/fileutil.go index e350b61f6c4fd02c0088cc1f2f5c35c0bbc45259..2793c11116d1f3574b9ce051afd76e6d056c7030 100644 --- a/internal/fsext/fileutil.go +++ b/internal/fsext/fileutil.go @@ -23,48 +23,12 @@ var ( func init() { var err error - rgPath, err = exec.LookPath("rg") - if err != nil { - slog.Warn("Ripgrep (rg) not found in $PATH. Some features might be limited or slower.") - } fzfPath, err = exec.LookPath("fzf") if err != nil { slog.Warn("FZF not found in $PATH. Some features might be limited or slower.") } } -func GetRgCmd(globPattern string) *exec.Cmd { - if rgPath == "" { - return nil - } - rgArgs := []string{ - "--files", - "-L", - "--null", - } - if globPattern != "" { - if !filepath.IsAbs(globPattern) && !strings.HasPrefix(globPattern, "/") { - globPattern = "/" + globPattern - } - rgArgs = append(rgArgs, "--glob", globPattern) - } - return exec.Command(rgPath, rgArgs...) -} - -func GetRgSearchCmd(pattern, path, include string) *exec.Cmd { - if rgPath == "" { - return nil - } - // Use -n to show line numbers and include the matched line - args := []string{"-H", "-n", pattern} - if include != "" { - args = append(args, "--glob", include) - } - args = append(args, path) - - return exec.Command(rgPath, args...) -} - type FileInfo struct { Path string ModTime time.Time diff --git a/internal/llm/tools/glob.go b/internal/llm/tools/glob.go index c70c76b7d2dbd798118a54859e5672dacc6e1304..0c1ac102c2f76f6abc7fb25a2e4c11e38e125444 100644 --- a/internal/llm/tools/glob.go +++ b/internal/llm/tools/glob.go @@ -1,14 +1,9 @@ package tools import ( - "bytes" "context" "encoding/json" "fmt" - "log/slog" - "os/exec" - "path/filepath" - "sort" "strings" "github.com/charmbracelet/crush/internal/fsext" @@ -139,49 +134,5 @@ func (g *globTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error) } func globFiles(pattern, searchPath string, limit int) ([]string, bool, error) { - cmdRg := fsext.GetRgCmd(pattern) - if cmdRg != nil { - cmdRg.Dir = searchPath - matches, err := runRipgrep(cmdRg, searchPath, limit) - if err == nil { - return matches, len(matches) >= limit && limit > 0, nil - } - slog.Warn(fmt.Sprintf("Ripgrep execution failed: %v. Falling back to doublestar.", err)) - } - return fsext.GlobWithDoubleStar(pattern, searchPath, limit) } - -func runRipgrep(cmd *exec.Cmd, searchRoot string, limit int) ([]string, error) { - out, err := cmd.CombinedOutput() - if err != nil { - if ee, ok := err.(*exec.ExitError); ok && ee.ExitCode() == 1 { - return nil, nil - } - return nil, fmt.Errorf("ripgrep: %w\n%s", err, out) - } - - var matches []string - for p := range bytes.SplitSeq(out, []byte{0}) { - if len(p) == 0 { - continue - } - absPath := string(p) - if !filepath.IsAbs(absPath) { - absPath = filepath.Join(searchRoot, absPath) - } - if fsext.SkipHidden(absPath) { - continue - } - matches = append(matches, absPath) - } - - sort.SliceStable(matches, func(i, j int) bool { - return len(matches[i]) < len(matches[j]) - }) - - if limit > 0 && len(matches) > limit { - matches = matches[:limit] - } - return matches, nil -}