fix(grep): reduce the max output of the grep tool

kujtimiihoxha created

Change summary

internal/llm/tools/grep.go | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

Detailed changes

internal/llm/tools/grep.go 🔗

@@ -93,7 +93,10 @@ type grepTool struct {
 	workingDir string
 }
 
-const GrepToolName = "grep"
+const (
+	GrepToolName        = "grep"
+	maxGrepContentWidth = 500
+)
 
 //go:embed grep.md
 var grepDescription []byte
@@ -188,7 +191,11 @@ func (g *grepTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
 				fmt.Fprintf(&output, "%s:\n", match.path)
 			}
 			if match.lineNum > 0 {
-				fmt.Fprintf(&output, "  Line %d: %s\n", match.lineNum, match.lineText)
+				lineText := match.lineText
+				if len(lineText) > maxGrepContentWidth {
+					lineText = lineText[:maxGrepContentWidth] + "..."
+				}
+				fmt.Fprintf(&output, "  Line %d: %s\n", match.lineNum, lineText)
 			} else {
 				fmt.Fprintf(&output, "  %s\n", match.path)
 			}