Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 576f1bdc2a feat(vcs): project conventions for Generate Commit Message with Agent
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
2026-11-17 21:52:52 +08:00
10 змінених файлів з 106 додано та 4 видалено

No files matched your search

+3
Переглянути файл
@@ -135,6 +135,8 @@ pub struct CommitSettings {
/// `Settings::default()`, or `SettingsStore::set` rejects the key as unknown.
#[specta(optional)]
pub double_click_opens_diff: Option<bool>,
/// Team conventions for Generate Commit Message with Agent, added to its prompt.
pub agent_instructions: String,
}
impl Default for CommitSettings {
@@ -156,6 +158,7 @@ impl Default for CommitSettings {
wrap_at_margin: false,
disabled_plugin_checks: Vec::new(),
double_click_opens_diff: None,
agent_instructions: String::new(),
}
}
}
+1
Переглянути файл
@@ -846,6 +846,7 @@ mod tests {
"wrapAtMargin": false,
"disabledPluginChecks": [],
"doubleClickOpensDiff": null,
"agentInstructions": "",
})
);
}
+2
Переглянути файл
@@ -3583,6 +3583,8 @@ export type CommitSettings = {
* `Settings::default()`, or `SettingsStore::set` rejects the key as unknown.
*/
doubleClickOpensDiff?: boolean | null,
/** Team conventions for Generate Commit Message with Agent, added to its prompt. */
agentInstructions?: string,
};
export type Commit_Deserialize = {
+9
Переглянути файл
@@ -112,6 +112,15 @@ describe("commitMessagePrompt", () => {
it("leaves out the style hint without earlier commits", () => {
expect(commitMessagePrompt(PATCH, 72, [])).not.toContain("latest commits");
});
it("adds the project's commit conventions before the recent subjects", () => {
const prompt = commitMessagePrompt(PATCH, 72, ["fix: y"], " Use Conventional Commits.\nPrefix the issue key. ");
const conventions = prompt.indexOf("Follow these conventions for commit messages here:\nUse Conventional Commits.");
expect(conventions).toBeGreaterThan(0);
expect(prompt).toContain("Prefix the issue key.\n");
expect(conventions).toBeLessThan(prompt.indexOf("latest commits"));
expect(commitMessagePrompt(PATCH, 72, [], " \n ")).not.toContain("conventions");
});
});
describe("commitMessageOf", () => {
+14 -2
Переглянути файл
@@ -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 {
+27
Переглянути файл
@@ -244,3 +244,30 @@
.toolsLayout .alignedRow {
grid-template-columns: subgrid;
}
/* Multi-line setting (agent instructions): a text field frame, full width. */
.instructions {
box-sizing: border-box;
width: 100%;
min-height: 72px;
padding: var(--space-1-5) var(--space-2);
border: 0;
border-radius: var(--radius-control, 4px);
background: var(--bg-field, var(--bg-button));
box-shadow: inset 0 0 0 1px var(--border-button);
color: var(--fg-strong);
font: inherit;
font-size: var(--fs-ui);
resize: vertical;
outline: none;
-webkit-user-select: text;
user-select: text;
}
.instructions::placeholder {
color: var(--fg-faint);
}
.instructions:focus {
box-shadow:
inset 0 0 0 1px var(--focus-ring),
0 0 0 1px var(--focus-ring);
}
+36
Переглянути файл
@@ -277,6 +277,31 @@ function MessageLimits() {
);
}
function AgentInstructionsRow() {
const [value, set] = useSetting<string>("vcs.commit.agentInstructions");
const id = useId();
return (
<Row
label="Instructions for Generate Commit Message with Agent"
htmlFor={id}
hint="Added to the agent's prompt, e.g. a commit format, issue key prefixes or the language to write in."
stacked
>
<textarea
id={id}
className={styles.instructions}
rows={4}
spellCheck={false}
placeholder={tx(
"Use Conventional Commits (feat:, fix:, …) and start with the issue key if the branch has one.",
)}
value={value}
onChange={(e) => set(e.target.value)}
/>
</Row>
);
}
function CommitChecks() {
return (
<Grid
@@ -402,6 +427,17 @@ export const VCS_PAGES: PageSpec[] = [
},
],
},
{
title: "Commit Message Generation",
options: [
{
kind: "custom",
label: "Instructions for Generate Commit Message with Agent",
keywords: ["agent", "ai", "prompt", "conventional commits"],
component: AgentInstructionsRow,
},
],
},
{
title: "Commit Checks",
options: [
+5 -1
Переглянути файл
@@ -2377,5 +2377,9 @@
"Additional servers": "Additional servers",
"Run alongside the one above": "Run alongside the one above",
"The agent jar changed since you approved it. Approve the new jar before the next launch.": "The agent jar changed since you approved it. Approve the new jar before the next launch.",
"Approve new jar": "Approve new jar"
"Approve new jar": "Approve new jar",
"Commit Message Generation": "Commit Message Generation",
"Instructions for Generate Commit Message with Agent": "Instructions for Generate Commit Message with Agent",
"Added to the agent's prompt, e.g. a commit format, issue key prefixes or the language to write in.": "Added to the agent's prompt, e.g. a commit format, issue key prefixes or the language to write in.",
"Use Conventional Commits (feat:, fix:, …) and start with the issue key if the branch has one.": "Use Conventional Commits (feat:, fix:, …) and start with the issue key if the branch has one."
}
+5 -1
Переглянути файл
@@ -8755,5 +8755,9 @@
"Additional servers": "附加服务器",
"Run alongside the one above": "与上面选中的服务器同时运行",
"The agent jar changed since you approved it. Approve the new jar before the next launch.": "Agent jar 在授权后发生了变化。请先批准新的 jar,再启动应用。",
"Approve new jar": "批准新的 jar"
"Approve new jar": "批准新的 jar",
"Commit Message Generation": "提交信息生成",
"Instructions for Generate Commit Message with Agent": "用 Agent 生成提交信息时的要求",
"Added to the agent's prompt, e.g. a commit format, issue key prefixes or the language to write in.": "会加到 Agent 的提示词里,例如提交格式、问题编号前缀或使用的语言。",
"Use Conventional Commits (feat:, fix:, …) and start with the issue key if the branch has one.": "使用 Conventional Commits(feat:、fix: 等),分支带问题编号时以它开头。"
}
+4
Переглянути файл
@@ -59,6 +59,8 @@ export interface CommitSettingsValid {
disabledPluginChecks: string[];
/** Double-click opens the diff (`true`), the source file (`false`), or follows the interface (`null`). */
doubleClickOpensDiff: boolean | null;
/** Team conventions for Generate Commit Message with Agent, added to its prompt. */
agentInstructions: string;
}
export interface VcsSettingsValid {
@@ -274,6 +276,7 @@ export const DEFAULT_WORKFLOW: WorkflowSettings = {
wrapAtMargin: false,
disabledPluginChecks: [],
doubleClickOpensDiff: null,
agentInstructions: "",
},
confirmation: {
onCreate: "ask",
@@ -433,6 +436,7 @@ export function validateVcs(raw: unknown): VcsSettingsValid {
wrapAtMargin: bool(c.wrapAtMargin, d.commit.wrapAtMargin),
disabledPluginChecks: strings(c.disabledPluginChecks, d.commit.disabledPluginChecks),
doubleClickOpensDiff: tri(c.doubleClickOpensDiff),
agentInstructions: text(c.agentInstructions, d.commit.agentInstructions),
},
confirmation: {
onCreate: oneOf(conf.onCreate, confirm, d.confirmation.onCreate),