(cwd, target, options = {})
| 297 | } |
| 298 | |
| 299 | export 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 | } |
no test coverage detected