mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
improve read tool end-of-file detection to prevent infinite loops
This commit is contained in:
parent
205492c7e8
commit
7ec32f834e
1 changed files with 8 additions and 2 deletions
|
|
@ -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>"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue