Skip to content

Commit 602cec1

Browse files
CyningMMcursoragent
andcommitted
fix(read): report both line and byte caps when dual limits hit
Fixes #94 — finishMessage uses independent checks so MAX_LINES and MAX_BYTES messages appear together; add regression test. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 596cadd commit 602cec1

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@moonshot-ai/agent-core": patch
3+
"@moonshot-ai/kimi-code": patch
4+
---
5+
6+
fix(read): report both MAX_LINES and MAX_BYTES caps when both are hit
7+
8+
Fixes #94

packages/agent-core/src/tools/builtin/file/read.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,11 @@ export class ReadTool implements BuiltinTool<ReadInput> {
446446
parts.push(`Total lines in file: ${String(input.totalLines)}.`);
447447
if (input.maxLinesReached) {
448448
parts.push(`Max ${String(MAX_LINES)} lines reached.`);
449-
} else if (input.maxBytesReached) {
449+
}
450+
if (input.maxBytesReached) {
450451
parts.push(`Max ${String(MAX_BYTES)} bytes reached.`);
451-
} else if (lineCount < input.requestedLines) {
452+
}
453+
if (!input.maxLinesReached && !input.maxBytesReached && lineCount < input.requestedLines) {
452454
parts.push('End of file reached.');
453455
}
454456
if (input.truncatedLineNumbers.length > 0) {

packages/agent-core/test/tools/read.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,19 @@ describe('ReadTool', () => {
622622
expect(result.output).not.toContain(`${String(MAX_LINES + 1)}\tline ${String(MAX_LINES + 1)}`);
623623
});
624624

625+
it('reports both line and byte caps when both limits are hit', async () => {
626+
const longLine = 'x'.repeat(200);
627+
const content = Array.from({ length: MAX_LINES + 1 }, () => longLine).join('\n');
628+
const tool = toolWithContent(content);
629+
630+
const result = await executeTool(tool, context({ path: '/tmp/dual-limit.txt' }));
631+
const output = toolContentString(result);
632+
633+
expect(output).toContain(`Max ${String(MAX_LINES)} lines reached.`);
634+
expect(output).toContain(`Max ${String(MAX_BYTES)} bytes reached.`);
635+
expect(output).not.toContain('End of file reached.');
636+
});
637+
625638
it('tail byte truncation keeps the newest lines closest to EOF', async () => {
626639
const numLines = Math.floor(MAX_BYTES / 1001) + 20;
627640
const content = Array.from({ length: numLines }, (_, i) => {

0 commit comments

Comments
 (0)