fix: improve review inline/body discipline and agent reliability
This commit is contained in:
+5
-4
@@ -4,7 +4,7 @@ import type { ToolContext } from "./server.ts";
|
||||
import { execute, tool } from "./shared.ts";
|
||||
|
||||
/** Hard cap on returned content to avoid flooding the model's context window. */
|
||||
const MAX_CHARS = 6000;
|
||||
const MAX_CHARS = 20000;
|
||||
|
||||
export const ReadFileParams = type({
|
||||
path: type.string.describe("absolute path to the file to read"),
|
||||
@@ -17,9 +17,10 @@ export function ReadFileTool(_ctx: ToolContext) {
|
||||
name: "read_file",
|
||||
description:
|
||||
"Read lines from a file. Use this to read sections of the PR diff returned by checkout_pr. " +
|
||||
`Returns at most ${MAX_CHARS} characters — use narrow line ranges to stay within budget. ` +
|
||||
"Read selectively: only the files most relevant to the review, not the entire diff at once. " +
|
||||
"Example: `read_file({ path: diffPath, start_line: 5, end_line: 42 })`.",
|
||||
`Returns at most ${MAX_CHARS} characters. ` +
|
||||
"Prefer fewer, wider reads: read large contiguous ranges rather than many small ones. " +
|
||||
"If the TOC lists 10 files, read 3-4 wide ranges that cover them rather than 10 separate calls. " +
|
||||
"Example: `read_file({ path: diffPath, start_line: 5, end_line: 200 })`.",
|
||||
parameters: ReadFileParams,
|
||||
execute: execute(async ({ path, start_line, end_line }) => {
|
||||
let content: string;
|
||||
|
||||
+15
-4
@@ -236,6 +236,11 @@ function postProcessBody(
|
||||
if (validComments.length === 0) return body;
|
||||
|
||||
const commentedPaths = new Set(validComments.map((c) => c.path));
|
||||
// Also match short filenames (e.g. "data-settings.tsx") since the body often
|
||||
// uses basenames while inline comments store full repo-relative paths.
|
||||
const commentedBasenames = new Set(
|
||||
validComments.map((c) => c.path.split("/").pop() ?? c.path),
|
||||
);
|
||||
|
||||
const sectionRegex = /^### .+$/gm;
|
||||
const matches: Array<{ index: number; heading: string }> = [];
|
||||
@@ -254,13 +259,19 @@ function postProcessBody(
|
||||
const toRemove: Array<{ start: number; end: number }> = [];
|
||||
for (const section of sections) {
|
||||
const content = body.slice(section.start, section.end);
|
||||
let matched: string | undefined;
|
||||
for (const path of commentedPaths) {
|
||||
if (content.includes(path)) {
|
||||
toRemove.push({ start: section.start, end: section.end });
|
||||
log.info(`stripped duplicate body section "${section.heading.slice(0, 80)}" — already covered by inline comment on ${path}`);
|
||||
break;
|
||||
if (content.includes(path)) { matched = path; break; }
|
||||
}
|
||||
if (!matched) {
|
||||
for (const basename of commentedBasenames) {
|
||||
if (content.includes(basename)) { matched = basename; break; }
|
||||
}
|
||||
}
|
||||
if (matched) {
|
||||
toRemove.push({ start: section.start, end: section.end });
|
||||
log.info(`stripped duplicate body section "${section.heading.slice(0, 80)}" — already covered by inline comment on ${matched}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (toRemove.length === 0) return body;
|
||||
|
||||
Reference in New Issue
Block a user