feat(vcs): project conventions for Generate Commit Message with Agent (#4014)

Settings › Version Control › Commit gets a Commit Message Generation section with a multi-line field (vcs.commit.agentInstructions, global or per project). Its text is added to the agent's prompt as the conventions to follow, ahead of the style taken from recent commit subjects.

Closes #3934
This commit is contained in:
l0ng-ai
2026-11-17 21:53:38 +08:00
committed by GitHub
parent 55e778897f
commit 6ab7627fc4
10 changed files with 106 additions and 4 deletions
+14 -2
View File
@@ -44,7 +44,12 @@ export function fitPatch(patch: string, budget = PATCH_BUDGET, perFile = FILE_BU
return omitted.length ? `${out}\nDiff omitted for: ${omitted.join(", ")}\n` : out;
}
export function commitMessagePrompt(patch: string, subjectLimit: number, recentSubjects: readonly string[]): string {
export function commitMessagePrompt(
patch: string,
subjectLimit: number,
recentSubjects: readonly string[],
instructions = "",
): string {
const lines = [
"Write a commit message",
"",
@@ -54,6 +59,8 @@ export function commitMessagePrompt(patch: string, subjectLimit: number, recentS
"- Don't edit files or run commands. The whole diff is below.",
"- Reply with the commit message only: no quotes, no code fence, no commentary.",
];
// The project's own conventions (Settings › Version Control › Commit) come before the style of recent commits.
if (instructions.trim()) lines.push("", "Follow these conventions for commit messages here:", instructions.trim());
if (recentSubjects.length) {
lines.push(
"",
@@ -250,7 +257,12 @@ async function generate(): Promise<void> {
const { commit } = workflowSettings().vcs;
const subjects = await recentSubjects(changes.roots[0]);
const prompt = commitMessagePrompt(changes.patch, commit.limitSubject ? commit.subjectLimit : 72, subjects);
const prompt = commitMessagePrompt(
changes.patch,
commit.limitSubject ? commit.subjectLimit : 72,
subjects,
commit.agentInstructions,
);
let task: AgentTask | undefined;
let release = () => {};
try {