Просмотр исходного кода

improve read tool end-of-file detection to prevent infinite loops

Dax Raad 3 месяцев назад
Родитель
Сommit
7ec32f834e
1 измененных файлов с 8 добавлено и 2 удалено
  1. 8 2
      packages/opencode/src/tool/read.ts

+ 8 - 2
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>"