@@ -18,6 +18,7 @@ import (
1818 "time"
1919
2020 "charm.land/fantasy"
21+ "github.com/charmbracelet/crush/internal/config"
2122 "github.com/charmbracelet/crush/internal/csync"
2223 "github.com/charmbracelet/crush/internal/fsext"
2324)
@@ -100,7 +101,7 @@ func escapeRegexPattern(pattern string) string {
100101 return escaped
101102}
102103
103−func NewGrepTool(workingDir string) fantasy.AgentTool {
104+func NewGrepTool(workingDir string, config config.ToolGrep) fantasy.AgentTool {
104105 return fantasy.NewAgentTool(
105106 GrepToolName,
106107 string(grepDescription),
@@ -109,7 +110,6 @@ func NewGrepTool(workingDir string) fantasy.AgentTool {
109110 return fantasy.NewTextErrorResponse("pattern is required"), nil
110111 }
111112
112− // If literal_text is true, escape the pattern
113113 searchPattern := params.Pattern
114114 if params.LiteralText {
115115 searchPattern = escapeRegexPattern(params.Pattern)
@@ -120,7 +120,10 @@ func NewGrepTool(workingDir string) fantasy.AgentTool {
120120 searchPath = workingDir
121121 }
122122
123− matches, truncated, err := searchFiles(ctx, searchPattern, searchPath, params.Include, 100)
123+ searchCtx, cancel := context.WithTimeout(ctx, config.GetTimeout())
124+ defer cancel()
125+
126+ matches, truncated, err := searchFiles(searchCtx, searchPattern, searchPath, params.Include, 100)
124127 if err != nil {
125128 return fantasy.NewTextErrorResponse(fmt.Sprintf("error searching files: %v", err)), nil
126129 }