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
6 changes: 6 additions & 0 deletions .changeset/read-tool-dual-cap-message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@moonshot-ai/agent-core": patch
"@moonshot-ai/kimi-code": patch
---

Report both MAX_LINES and MAX_BYTES limits in Read tool status when both are reached.
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 @@ -435,9 +435,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
17 changes: 17 additions & 0 deletions packages/agent-core/test/tools/read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,23 @@ describe('ReadTool', () => {
expect(result.output).not.toContain(`${String(MAX_LINES + 1)}\tline ${String(MAX_LINES + 1)}`);
});

it('reports both MAX_LINES and MAX_BYTES when both caps are hit', async () => {
const lineCount = MAX_LINES + 5;
const lineContent = 'x'.repeat(105);
const content = Array.from({ length: lineCount }, (_, i) => `${lineContent} ${String(i + 1)}`).join(
'\n',
);
const tool = toolWithContent(content);

const result = await executeTool(tool, context({ path: '/tmp/both-caps.txt' }));
const output = toolContentString(result);

expect(result.isError).toBeFalsy();
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