feat(api): include unified diff in DE summary prompt and extend timeout

Add getLastCommitDiff to fetch the latest commit’s unified diff and
append it to the system prompt for German summaries. Increase LLM call
timeout to handle larger prompts.
This commit is contained in:
sebseb7
2025-08-04 10:41:37 +02:00
parent 0102196e09
commit c2c7e11e00

24
x.js
View File

@@ -40,6 +40,19 @@ async function getLastCommits({ count = 10, repoDir = process.cwd() } = {}) {
}
}
// Get unified diff for the latest commit (against its parent)
async function getLastCommitDiff({ repoDir = process.cwd(), contextLines = 3 } = {}) {
try {
// --pretty=format: to avoid commit message in diff header; use -1 for last commit
const cmd = `git show -1 --unified=${contextLines} --no-color`;
const { stdout } = await execCmd(cmd, { cwd: repoDir, timeoutMs: 8000 });
return stdout || '';
} catch (e) {
logMessage(`getLastCommitDiff failed: ${e.message}`, 'warn');
return '';
}
}
function buildMostRecentCommitPromptGerman(commits) {
if (!commits || commits.length === 0) return null;
const c0 = commits[0];
@@ -122,14 +135,21 @@ async function summarizeMostRecentCommitDE() {
const prompt = buildMostRecentCommitPromptGerman(commits);
if (!prompt) return null;
// Also include the unified diff of the latest commit in the system prompt
const diff = await getLastCommitDiff({ repoDir: process.cwd(), contextLines: 3 });
const systemWithDiff =
`${prompt.system}\n\n` +
`Kontext (unified diff der neuesten Änderung):\n` +
`${diff ? diff.slice(0, 120000) : '(kein Diff verfügbar)'}`;
try {
const summary = await callLLMOpenAICompatible({
baseUrl,
apiKey,
model,
system: prompt.system,
system: systemWithDiff,
user: prompt.user,
timeoutMs: 15000
timeoutMs: 20000
});
if (!summary) return null;
return summary;