(options: DiffScopeOptions)
| 15 | } |
| 16 | |
| 17 | export async function runPrep(options: DiffScopeOptions): Promise<string> { |
| 18 | const { scope, rawDiff, mergeBaseSha } = await resolveDiffScope(options); |
| 19 | |
| 20 | const allFiles = parseGitDiff(rawDiff); |
| 21 | const stageIgnore = loadStageIgnore(readRepoRoot()); |
| 22 | const { files } = filterFilesForLlm(allFiles, stageIgnore); |
| 23 | |
| 24 | const formattedHunks = files |
| 25 | .flatMap((file) => file.hunks.map((hunk) => formatHunkForPrompt(file, hunk))) |
| 26 | .join("\n\n"); |
| 27 | |
| 28 | const commitMessages = getCommitMessages(mergeBaseSha, scope.headSha); |
| 29 | |
| 30 | const sections = ["=== COMMIT MESSAGES ===", commitMessages, "", "=== HUNKS ===", formattedHunks]; |
| 31 | |
| 32 | const filePath = path.join(tmpdir(), `stage-prep-${Date.now()}.txt`); |
| 33 | writeFileSync(filePath, sections.join("\n"), "utf8"); |
| 34 | |
| 35 | return filePath; |
| 36 | } |
no test coverage detected