MCPcopy
hub / github.com/openai/codex-plugin-cc / collectReviewContext

Function collectReviewContext

plugins/codex/scripts/lib/git.mjs:299–346  ·  view source on GitHub ↗
(cwd, target, options = {})

Source from the content-addressed store, hash-verified

297}
298
299export function collectReviewContext(cwd, target, options = {}) {
300 const repoRoot = getRepoRoot(cwd);
301 const currentBranch = getCurrentBranch(repoRoot);
302 const maxInlineFiles = normalizeMaxInlineFiles(options.maxInlineFiles);
303 const maxInlineDiffBytes = normalizeMaxInlineDiffBytes(options.maxInlineDiffBytes);
304 let details;
305 let includeDiff;
306 let diffBytes;
307
308 if (target.mode === "working-tree") {
309 const state = getWorkingTreeState(repoRoot);
310 diffBytes = measureCombinedGitOutputBytes(
311 repoRoot,
312 [
313 ["diff", "--cached", "--binary", "--no-ext-diff", "--submodule=diff"],
314 ["diff", "--binary", "--no-ext-diff", "--submodule=diff"]
315 ],
316 maxInlineDiffBytes
317 );
318 includeDiff =
319 options.includeDiff ??
320 (listUniqueFiles(state.staged, state.unstaged, state.untracked).length <= maxInlineFiles &&
321 diffBytes <= maxInlineDiffBytes);
322 details = collectWorkingTreeContext(repoRoot, state, { includeDiff });
323 } else {
324 const comparison = buildBranchComparison(repoRoot, target.baseRef);
325 const fileCount = gitChecked(repoRoot, ["diff", "--name-only", comparison.commitRange]).stdout.trim().split("\n").filter(Boolean).length;
326 diffBytes = measureGitOutputBytes(
327 repoRoot,
328 ["diff", "--binary", "--no-ext-diff", "--submodule=diff", comparison.commitRange],
329 maxInlineDiffBytes
330 );
331 includeDiff = options.includeDiff ?? (fileCount <= maxInlineFiles && diffBytes <= maxInlineDiffBytes);
332 details = collectBranchContext(repoRoot, target.baseRef, { includeDiff, comparison });
333 }
334
335 return {
336 cwd: repoRoot,
337 repoRoot,
338 branch: currentBranch,
339 target,
340 fileCount: details.changedFiles.length,
341 diffBytes,
342 inputMode: includeDiff ? "inline-diff" : "self-collect",
343 collectionGuidance: buildAdversarialCollectionGuidance({ includeDiff }),
344 ...details
345 };
346}

Callers 2

git.test.mjsFile · 0.90
executeReviewRunFunction · 0.90

Calls 13

getRepoRootFunction · 0.85
getCurrentBranchFunction · 0.85
normalizeMaxInlineFilesFunction · 0.85
getWorkingTreeStateFunction · 0.85
listUniqueFilesFunction · 0.85
buildBranchComparisonFunction · 0.85
gitCheckedFunction · 0.85
measureGitOutputBytesFunction · 0.85
collectBranchContextFunction · 0.85

Tested by

no test coverage detected