Skip to content

Commit 95c3a8b

Browse files
committed
limit grep line length to 2000
1 parent f1bb587 commit 95c3a8b

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

packages/opencode/src/tool/grep.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { Ripgrep } from "../file/ripgrep"
55
import DESCRIPTION from "./grep.txt"
66
import { Instance } from "../project/instance"
77

8+
const MAX_LINE_LENGTH = 2000
9+
810
export const GrepTool = Tool.define("grep", {
911
description: DESCRIPTION,
1012
parameters: z.object({
@@ -96,7 +98,9 @@ export const GrepTool = Tool.define("grep", {
9698
currentFile = match.path
9799
outputLines.push(`${match.path}:`)
98100
}
99-
outputLines.push(` Line ${match.lineNum}: ${match.lineText}`)
101+
const truncatedLineText =
102+
match.lineText.length > MAX_LINE_LENGTH ? match.lineText.substring(0, MAX_LINE_LENGTH) + "..." : match.lineText
103+
outputLines.push(` Line ${match.lineNum}: ${truncatedLineText}`)
100104
}
101105

102106
if (truncated) {

0 commit comments

Comments
 (0)