fix(coding-agent): honor caller-supplied read selector limit

The ignoreResultLimits flag now gates only the byte-budget tail-truncate,
never the explicit line window. Reads of internal URLs (skill, local,
memory) with a line range previously returned the tail of the file
instead of the requested window for files larger than the byte budget.
This commit is contained in:
can1357
2026-05-19 19:15:49 +09:00
parent 784ac0b6cf
commit f48af07d3a
+3 -6
View File
@@ -800,10 +800,7 @@ export class ReadTool implements AgentTool<typeof readSchema, ReadToolDetails> {
// context (added below if offset is explicit).
const requestedStart = offset ? Math.max(0, offset - 1) : 0;
const ignoreResultLimits = options.ignoreResultLimits ?? false;
const requestedEnd =
limit !== undefined && !ignoreResultLimits
? Math.min(requestedStart + limit, allLines.length)
: allLines.length;
const requestedEnd = limit !== undefined ? Math.min(requestedStart + limit, allLines.length) : allLines.length;
// Expand only on sides the user actually constrained: leading context
// when offset>1, trailing context when a finite limit was set.
const expanded = expandRangeWithContext(
@@ -811,7 +808,7 @@ export class ReadTool implements AgentTool<typeof readSchema, ReadToolDetails> {
requestedEnd,
allLines.length,
offset !== undefined && offset > 1,
limit !== undefined && !ignoreResultLimits,
limit !== undefined,
);
const startLine = expanded.startLine;
const endLineExpanded = expanded.endLine;
@@ -842,7 +839,7 @@ export class ReadTool implements AgentTool<typeof readSchema, ReadToolDetails> {
const endLine = endLineExpanded;
const selectedContent = allLines.slice(startLine, endLine).join("\n");
const userLimitedLines = limit !== undefined && !ignoreResultLimits ? endLine - startLine : undefined;
const userLimitedLines = limit !== undefined ? endLine - startLine : undefined;
const truncation = ignoreResultLimits ? noTruncResult(selectedContent) : truncateHead(selectedContent);
const shouldAddHashLines = displayMode.hashLines;