Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/fix-read-dual-limit-status.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions packages/agent-core/src/tools/builtin/file/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,11 @@ export class ReadTool implements BuiltinTool<ReadInput> {
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) {
Expand Down
13 changes: 13 additions & 0 deletions packages/agent-core/test/tools/read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Loading