diff options
| author | Dax Raad <[email protected]> | 2025-11-13 21:41:06 -0500 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2025-11-13 21:41:06 -0500 |
| commit | 7ec32f834ecad7b9b18439b938cc67c590a36b79 (patch) | |
| tree | 28f1bd7728d55ad5de6727588291f209a5d1a4e8 | |
| parent | 205492c7e8a8b70048728ee05f1fd06b60b69115 (diff) | |
| download | opencode-7ec32f834ecad7b9b18439b938cc67c590a36b79.tar.gz opencode-7ec32f834ecad7b9b18439b938cc67c590a36b79.zip | |
improve read tool end-of-file detection to prevent infinite loops
| -rw-r--r-- | packages/opencode/src/tool/read.ts | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/packages/opencode/src/tool/read.ts b/packages/opencode/src/tool/read.ts index fc33463a3..7dc41ea53 100644 --- a/packages/opencode/src/tool/read.ts +++ b/packages/opencode/src/tool/read.ts @@ -134,8 +134,14 @@ export const ReadTool = Tool.define("read", { let output = "<file>\n" output += content.join("\n") - if (lines.length > offset + content.length) { - output += `\n\n(File has more lines. Use 'offset' parameter to read beyond line ${offset + content.length})` + const totalLines = lines.length + const lastReadLine = offset + content.length + const hasMoreLines = totalLines > lastReadLine + + if (hasMoreLines) { + output += `\n\n(File has more lines. Use 'offset' parameter to read beyond line ${lastReadLine})` + } else { + output += `\n\n(End of file - total ${totalLines} lines)` } output += "\n</file>" |
