From 602cec160c377c4cff4b69e2132d7810f2257c36 Mon Sep 17 00:00:00 2001 From: cyning Date: Fri, 12 Jun 2026 14:21:46 +0800 Subject: [PATCH] fix(read): report both line and byte caps when dual limits hit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #94 — finishMessage uses independent checks so MAX_LINES and MAX_BYTES messages appear together; add regression test. Co-authored-by: Cursor --- .changeset/fix-read-dual-limit-status.md | 8 ++++++++ packages/agent-core/src/tools/builtin/file/read.ts | 6 ++++-- packages/agent-core/test/tools/read.test.ts | 13 +++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 .changeset/fix-read-dual-limit-status.md diff --git a/.changeset/fix-read-dual-limit-status.md b/.changeset/fix-read-dual-limit-status.md new file mode 100644 index 000000000..901e15c2e --- /dev/null +++ b/.changeset/fix-read-dual-limit-status.md @@ -0,0 +1,8 @@ +--- +"@moonshot-ai/agent-core": patch +"@moonshot-ai/kimi-code": patch +--- + +fix(read): report both MAX_LINES and MAX_BYTES caps when both are hit + +Fixes #94 diff --git a/packages/agent-core/src/tools/builtin/file/read.ts b/packages/agent-core/src/tools/builtin/file/read.ts index e9aa6472f..c9fde6b5d 100644 --- a/packages/agent-core/src/tools/builtin/file/read.ts +++ b/packages/agent-core/src/tools/builtin/file/read.ts @@ -446,9 +446,11 @@ export class ReadTool implements BuiltinTool { parts.push(`Total lines in file: ${String(input.totalLines)}.`); if (input.maxLinesReached) { parts.push(`Max ${String(MAX_LINES)} lines reached.`); - } else if (input.maxBytesReached) { + } + if (input.maxBytesReached) { parts.push(`Max ${String(MAX_BYTES)} bytes reached.`); - } else if (lineCount < input.requestedLines) { + } + if (!input.maxLinesReached && !input.maxBytesReached && lineCount < input.requestedLines) { parts.push('End of file reached.'); } if (input.truncatedLineNumbers.length > 0) { diff --git a/packages/agent-core/test/tools/read.test.ts b/packages/agent-core/test/tools/read.test.ts index 4ab97c1bb..b81ad526a 100644 --- a/packages/agent-core/test/tools/read.test.ts +++ b/packages/agent-core/test/tools/read.test.ts @@ -622,6 +622,19 @@ describe('ReadTool', () => { expect(result.output).not.toContain(`${String(MAX_LINES + 1)}\tline ${String(MAX_LINES + 1)}`); }); + it('reports both line and byte caps when both limits are hit', async () => { + const longLine = 'x'.repeat(200); + const content = Array.from({ length: MAX_LINES + 1 }, () => longLine).join('\n'); + const tool = toolWithContent(content); + + const result = await executeTool(tool, context({ path: '/tmp/dual-limit.txt' })); + const output = toolContentString(result); + + expect(output).toContain(`Max ${String(MAX_LINES)} lines reached.`); + expect(output).toContain(`Max ${String(MAX_BYTES)} bytes reached.`); + expect(output).not.toContain('End of file reached.'); + }); + it('tail byte truncation keeps the newest lines closest to EOF', async () => { const numLines = Math.floor(MAX_BYTES / 1001) + 20; const content = Array.from({ length: numLines }, (_, i) => {