Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 7ec32f8

Browse files
committed
improve read tool end-of-file detection to prevent infinite loops
1 parent 205492c commit 7ec32f8

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

packages/opencode/src/tool/read.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,14 @@ export const ReadTool = Tool.define("read", {
134134
let output = "<file>\n"
135135
output += content.join("\n")
136136

137-
if (lines.length > offset + content.length) {
138-
output += `\n\n(File has more lines. Use 'offset' parameter to read beyond line ${offset + content.length})`
137+
const totalLines = lines.length
138+
const lastReadLine = offset + content.length
139+
const hasMoreLines = totalLines > lastReadLine
140+
141+
if (hasMoreLines) {
142+
output += `\n\n(File has more lines. Use 'offset' parameter to read beyond line ${lastReadLine})`
143+
} else {
144+
output += `\n\n(End of file - total ${totalLines} lines)`
139145
}
140146
output += "\n</file>"
141147

0 commit comments

Comments
 (0)