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
2 changes: 1 addition & 1 deletion packages/agent-core/src/tools/builtin/file/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export class ReadTool implements BuiltinTool<ReadInput> {
return this.finishReadResult({
renderedLines,
truncatedLineNumbers,
maxLinesReached: false,
maxLinesReached: effectiveLimit >= MAX_LINES && entries.length >= effectiveLimit,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid reporting the line cap for exact-size tail reads

When line_offset is -MAX_LINES and the file contains exactly MAX_LINES lines, entries.length equals effectiveLimit even though no content was omitted by the internal cap, so the result now reports Max 1000 lines reached. for a complete read. Forward reads only set this flag after seeing an extra eligible line; tail mode needs the same distinction, e.g. requiring more total lines than the retained tail window/effective limit.

Useful? React with 👍 / 👎.

maxBytesReached,
lineEndingStyle,
startLine: renderedCandidates[0]?.entry.lineNo ?? 0,
Expand Down
16 changes: 16 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,22 @@ describe('ReadTool', () => {
expect(result.output).not.toContain(`${String(MAX_LINES + 1)}\tline ${String(MAX_LINES + 1)}`);
});

it('caps tail reads at MAX_LINES', async () => {
const content = Array.from({ length: MAX_LINES + 5 }, (_, i) => `line ${String(i + 1)}`).join(
'\n',
);
const tool = toolWithContent(content);

const result = await executeTool(
tool,
context({ path: '/tmp/tail-big.txt', line_offset: -MAX_LINES }),
);

expect(result.output).toContain(`Max ${String(MAX_LINES)} lines reached.`);
expect(result.output).toContain(`${String(MAX_LINES + 5)}\tline ${String(MAX_LINES + 5)}`);
expect(result.output).toMatch(/^6\tline 6/);
});

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