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:
24
x.js
24
x.js
@@ -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) {
|
function buildMostRecentCommitPromptGerman(commits) {
|
||||||
if (!commits || commits.length === 0) return null;
|
if (!commits || commits.length === 0) return null;
|
||||||
const c0 = commits[0];
|
const c0 = commits[0];
|
||||||
@@ -122,14 +135,21 @@ async function summarizeMostRecentCommitDE() {
|
|||||||
const prompt = buildMostRecentCommitPromptGerman(commits);
|
const prompt = buildMostRecentCommitPromptGerman(commits);
|
||||||
if (!prompt) return null;
|
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 {
|
try {
|
||||||
const summary = await callLLMOpenAICompatible({
|
const summary = await callLLMOpenAICompatible({
|
||||||
baseUrl,
|
baseUrl,
|
||||||
apiKey,
|
apiKey,
|
||||||
model,
|
model,
|
||||||
system: prompt.system,
|
system: systemWithDiff,
|
||||||
user: prompt.user,
|
user: prompt.user,
|
||||||
timeoutMs: 15000
|
timeoutMs: 20000
|
||||||
});
|
});
|
||||||
if (!summary) return null;
|
if (!summary) return null;
|
||||||
return summary;
|
return summary;
|
||||||
|
|||||||
Reference in New Issue
Block a user