diff options
| author | Adam Malczewski <[email protected]> | 2026-05-27 20:48:32 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-05-27 20:48:32 +0900 |
| commit | 4f0ed4ed9456e30344228f0106f6bb104417da3d (patch) | |
| tree | 191712ddafcf4f9e63bde143b30f8e27f767e3ab | |
| parent | 9ac04b96801ef254f46d77d3314ae36a1ad79aed (diff) | |
| download | dispatch-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.ts | 7 |
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 |
