mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-04-20 03:02:51 -04:00
fix(generate): forward context through chunked large-diff prompt path
When a staged diff exceeds MAX_REQUEST_TOKENS, generateCommitMessageByDiff routes through getCommitMsgsPromisesFromFileDiffs → getMessagesPromisesByChangesInFile → generateCommitMessageChatCompletionPrompt to produce one sub-prompt per chunk. That entire chain was threading `fullGitMojiSpec` but never `context`, so `-c/--context` was silently dropped for any diff large enough to trigger chunking, even though the simple (non-chunked) path forwarded it correctly. Add a `context` parameter to each of the three helpers and thread it through to generateCommitMessageChatCompletionPrompt so the user's context is present in every sub-prompt.
This commit is contained in:
@@ -130,7 +130,7 @@ async function handleModelNotFoundError(
|
||||
...existingConfig,
|
||||
OCO_MODEL: newModel
|
||||
} as any);
|
||||
console.log(chalk.green('✔') + ' Model saved as default\n');
|
||||
console.log(chalk.green('√') + ' Model saved as default\n');
|
||||
}
|
||||
|
||||
return newModel;
|
||||
@@ -168,7 +168,8 @@ export const generateCommitMessageByDiff = async (
|
||||
const commitMessagePromises = await getCommitMsgsPromisesFromFileDiffs(
|
||||
diff,
|
||||
MAX_REQUEST_TOKENS,
|
||||
fullGitMojiSpec
|
||||
fullGitMojiSpec,
|
||||
context
|
||||
);
|
||||
|
||||
const commitMessages = [] as string[];
|
||||
@@ -228,7 +229,8 @@ function getMessagesPromisesByChangesInFile(
|
||||
fileDiff: string,
|
||||
separator: string,
|
||||
maxChangeLength: number,
|
||||
fullGitMojiSpec: boolean
|
||||
fullGitMojiSpec: boolean,
|
||||
context: string
|
||||
) {
|
||||
const hunkHeaderSeparator = '@@ ';
|
||||
const [fileHeader, ...fileDiffByLines] = fileDiff.split(hunkHeaderSeparator);
|
||||
@@ -256,7 +258,8 @@ function getMessagesPromisesByChangesInFile(
|
||||
async (lineDiff) => {
|
||||
const messages = await generateCommitMessageChatCompletionPrompt(
|
||||
separator + lineDiff,
|
||||
fullGitMojiSpec
|
||||
fullGitMojiSpec,
|
||||
context
|
||||
);
|
||||
|
||||
return engine.generateCommitMessage(messages);
|
||||
@@ -305,7 +308,8 @@ function splitDiff(diff: string, maxChangeLength: number) {
|
||||
export const getCommitMsgsPromisesFromFileDiffs = async (
|
||||
diff: string,
|
||||
maxDiffLength: number,
|
||||
fullGitMojiSpec: boolean
|
||||
fullGitMojiSpec: boolean,
|
||||
context: string
|
||||
) => {
|
||||
const separator = 'diff --git ';
|
||||
|
||||
@@ -323,14 +327,16 @@ export const getCommitMsgsPromisesFromFileDiffs = async (
|
||||
fileDiff,
|
||||
separator,
|
||||
maxDiffLength,
|
||||
fullGitMojiSpec
|
||||
fullGitMojiSpec,
|
||||
context
|
||||
);
|
||||
|
||||
commitMessagePromises.push(...messagesPromises);
|
||||
} else {
|
||||
const messages = await generateCommitMessageChatCompletionPrompt(
|
||||
separator + fileDiff,
|
||||
fullGitMojiSpec
|
||||
fullGitMojiSpec,
|
||||
context
|
||||
);
|
||||
|
||||
const engine = getEngine();
|
||||
|
||||
Reference in New Issue
Block a user