Skip to content

Commit bf3c480

Browse files
committed
fix(dashboard-agent): report the line read_file actually reached when the cap cuts a range
1 parent 3bd052b commit bf3c480

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

internal-packages/dashboard-agent/src/repo-tools.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@ describe("repo-tools", () => {
139139
expect(res.startLine).toBe(3000);
140140
});
141141

142+
it("read_file reports the last line it actually served when the cap cuts a range short", async () => {
143+
const res: any = await call(tools.read_file, {
144+
path: "src/trigger/narrow.ts",
145+
startLine: 1,
146+
endLine: 4000,
147+
});
148+
expect(res.truncated).toBe(true);
149+
const served = res.content.split("\n");
150+
expect(served).toHaveLength(MAX_READ_LINES);
151+
expect(res.startLine).toBe(1);
152+
expect(res.endLine).toBe(MAX_READ_LINES);
153+
});
154+
142155
it("read_file leaves a small file untruncated", async () => {
143156
const res: any = await call(tools.read_file, { path: "src/trigger/order.ts" });
144157
expect(res.truncated).toBe(false);

internal-packages/dashboard-agent/src/repo-tools.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,14 @@ export function buildRepoTools(
268268
const from = Math.max(1, startLine ?? 1);
269269
const to = Math.min(lines.length, endLine ?? lines.length);
270270
const range = capRead(lines.slice(from - 1, to).join("\n"));
271+
// The cap can cut the range short, and a line number that outruns the
272+
// content is a citation anchored to a line the model never saw.
273+
const served = Math.min(to, from + range.content.split("\n").length - 1);
271274
return {
272275
path,
273276
content: range.content,
274277
startLine: from,
275-
endLine: to,
278+
endLine: served,
276279
...(range.truncated ? { truncated: true, notice: READ_TRUNCATION_NOTICE } : {}),
277280
};
278281
}

0 commit comments

Comments
 (0)