Skip to content
This repository was archived by the owner on Apr 30, 2026. It is now read-only.

Commit b11cccc

Browse files
linjaksonclaude
andcommitted
fix(adversarial-review): truncate branch diff to 60KB to fit context window
大型 PR 的 branch diff 動輒上 MB,整段塞進 adversarial-review prompt 會撐爆 context window,Codex 在 review 中段就停止讀後續檔案。 - 移除 git diff --binary 旗標(context 中沒人解 binary,純浪費 token) - 加 60KB 上限,超過時截斷並標記 "[... diff truncated to fit context window — use tool calls to inspect remaining files ...]",引導 Codex 主動用 tool calls 拉剩餘檔案 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent b169820 commit b11cccc

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎plugins/codex/scripts/lib/git.mjs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,29 @@ function collectWorkingTreeContext(cwd, state) {
168168
};
169169
}
170170

171+
const MAX_DIFF_BYTES = 60000;
172+
171173
function collectBranchContext(cwd, baseRef) {
172174
const mergeBase = gitChecked(cwd, ["merge-base", "HEAD", baseRef]).stdout.trim();
173175
const commitRange = `${mergeBase}..HEAD`;
174176
const currentBranch = getCurrentBranch(cwd);
175177
const logOutput = gitChecked(cwd, ["log", "--oneline", "--decorate", commitRange]).stdout.trim();
176178
const diffStat = gitChecked(cwd, ["diff", "--stat", commitRange]).stdout.trim();
177-
const diff = gitChecked(cwd, ["diff", "--binary", "--no-ext-diff", "--submodule=diff", commitRange]).stdout;
179+
let diff = gitChecked(cwd, ["diff", "--no-ext-diff", "--submodule=diff", commitRange]).stdout;
180+
181+
let truncated = false;
182+
if (Buffer.byteLength(diff, "utf8") > MAX_DIFF_BYTES) {
183+
diff = diff.slice(0, MAX_DIFF_BYTES);
184+
truncated = true;
185+
}
178186

179187
return {
180188
mode: "branch",
181189
summary: `Reviewing branch ${currentBranch} against ${baseRef} from merge-base ${mergeBase}.`,
182190
content: [
183191
formatSection("Commit Log", logOutput),
184192
formatSection("Diff Stat", diffStat),
185-
formatSection("Branch Diff", diff)
193+
formatSection("Branch Diff", diff + (truncated ? "\n\n[... diff truncated to fit context window — use tool calls to inspect remaining files ...]" : ""))
186194
].join("\n")
187195
};
188196
}

0 commit comments

Comments
 (0)