|
|
@@ -18,6 +18,7 @@ import (
|
|
|
"time"
|
|
|
|
|
|
"charm.land/fantasy"
|
|
|
+ "github.com/charmbracelet/crush/internal/config"
|
|
|
"github.com/charmbracelet/crush/internal/csync"
|
|
|
"github.com/charmbracelet/crush/internal/fsext"
|
|
|
)
|
|
|
@@ -100,7 +101,7 @@ func escapeRegexPattern(pattern string) string {
|
|
|
return escaped
|
|
|
}
|
|
|
|
|
|
-func NewGrepTool(workingDir string) fantasy.AgentTool {
|
|
|
+func NewGrepTool(workingDir string, config config.ToolGrep) fantasy.AgentTool {
|
|
|
return fantasy.NewAgentTool(
|
|
|
GrepToolName,
|
|
|
string(grepDescription),
|
|
|
@@ -109,7 +110,6 @@ func NewGrepTool(workingDir string) fantasy.AgentTool {
|
|
|
return fantasy.NewTextErrorResponse("pattern is required"), nil
|
|
|
}
|
|
|
|
|
|
- // If literal_text is true, escape the pattern
|
|
|
searchPattern := params.Pattern
|
|
|
if params.LiteralText {
|
|
|
searchPattern = escapeRegexPattern(params.Pattern)
|
|
|
@@ -120,7 +120,10 @@ func NewGrepTool(workingDir string) fantasy.AgentTool {
|
|
|
searchPath = workingDir
|
|
|
}
|
|
|
|
|
|
- matches, truncated, err := searchFiles(ctx, searchPattern, searchPath, params.Include, 100)
|
|
|
+ searchCtx, cancel := context.WithTimeout(ctx, config.GetTimeout())
|
|
|
+ defer cancel()
|
|
|
+
|
|
|
+ matches, truncated, err := searchFiles(searchCtx, searchPattern, searchPath, params.Include, 100)
|
|
|
if err != nil {
|
|
|
return fantasy.NewTextErrorResponse(fmt.Sprintf("error searching files: %v", err)), nil
|
|
|
}
|