summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-05-27 20:48:32 +0900
committerAdam Malczewski <[email protected]>2026-05-27 20:48:32 +0900
commit4f0ed4ed9456e30344228f0106f6bb104417da3d (patch)
tree191712ddafcf4f9e63bde143b30f8e27f767e3ab
parent9ac04b96801ef254f46d77d3314ae36a1ad79aed (diff)
downloaddispatch-4f0ed4ed9456e30344228f0106f6bb104417da3d.tar.gz
dispatch-4f0ed4ed9456e30344228f0106f6bb104417da3d.zip
fix(core): handle empty file in read_file line counting
-rw-r--r--packages/core/src/tools/read-file.ts7
1 files changed, 7 insertions, 0 deletions
diff --git a/packages/core/src/tools/read-file.ts b/packages/core/src/tools/read-file.ts
index 2c10be4..fa82dce 100644
--- a/packages/core/src/tools/read-file.ts
+++ b/packages/core/src/tools/read-file.ts
@@ -79,6 +79,13 @@ export function createReadFileTool(workingDirectory: string): ToolDefinition {
return `Error reading file: ${err instanceof Error ? err.message : String(err)}`;
}
+ // A truly empty file (0 bytes) would otherwise slip through the
+ // line-counting below: `"".split("\n")` is `[""]` and there's no
+ // trailing newline, yielding a spurious `totalLines === 1`.
+ if (raw === "") {
+ return `(empty file: ${filePath})`;
+ }
+
const allLines = raw.split("\n");
// `split("\n")` produces an extra empty entry when the file ends with a
// newline. The total line count we report to the caller should match