diff --git a/crates/ide-core/src/workflow_settings.rs b/crates/ide-core/src/workflow_settings.rs index 964ebecbf..8919bc11f 100644 --- a/crates/ide-core/src/workflow_settings.rs +++ b/crates/ide-core/src/workflow_settings.rs @@ -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, + /// 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(), } } } diff --git a/crates/ide-workspace/src/settings.rs b/crates/ide-workspace/src/settings.rs index 66a8b5266..d6b1526e3 100644 --- a/crates/ide-workspace/src/settings.rs +++ b/crates/ide-workspace/src/settings.rs @@ -846,6 +846,7 @@ mod tests { "wrapAtMargin": false, "disabledPluginChecks": [], "doubleClickOpensDiff": null, + "agentInstructions": "", }) ); } diff --git a/src/bindings.ts b/src/bindings.ts index 7c5d17e80..5ec71ca3a 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -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 = { diff --git a/src/features/agents/commitMessage.test.ts b/src/features/agents/commitMessage.test.ts index 3bba0a341..8e604e5c6 100644 --- a/src/features/agents/commitMessage.test.ts +++ b/src/features/agents/commitMessage.test.ts @@ -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", () => { diff --git a/src/features/agents/commitMessage.ts b/src/features/agents/commitMessage.ts index 2d2c66387..d940e6b4d 100644 --- a/src/features/agents/commitMessage.ts +++ b/src/features/agents/commitMessage.ts @@ -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 { 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 { diff --git a/src/features/settings/pages/Workflow.module.css b/src/features/settings/pages/Workflow.module.css index bffa21109..114043808 100644 --- a/src/features/settings/pages/Workflow.module.css +++ b/src/features/settings/pages/Workflow.module.css @@ -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); +} diff --git a/src/features/settings/pages/vcs.tsx b/src/features/settings/pages/vcs.tsx index b052a397b..a7cfb9487 100644 --- a/src/features/settings/pages/vcs.tsx +++ b/src/features/settings/pages/vcs.tsx @@ -277,6 +277,31 @@ function MessageLimits() { ); } +function AgentInstructionsRow() { + const [value, set] = useSetting("vcs.commit.agentInstructions"); + const id = useId(); + return ( + +