Skip to content

Commit 788a100

Browse files
committed
fix(scm): 🐛 address commit message settings review feedback
1 parent 4c18cb1 commit 788a100

10 files changed

Lines changed: 56 additions & 12 deletions

File tree

packages/types/src/global-settings.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { languagesSchema } from "./vscode.js"
2323
*/
2424
export const DEFAULT_WRITE_DELAY_MS = 1000
2525

26+
/** Schema for optional Git context included with generated commit message prompts. */
2627
export const commitMessageGitContextSchema = z.object({
2728
diffContextLines: z.number().int().min(0).max(20).optional(),
2829
includeDiffStats: z.boolean().optional(),
@@ -37,6 +38,7 @@ export const commitMessageGitContextSchema = z.object({
3738

3839
export type CommitMessageGitContextSettings = z.infer<typeof commitMessageGitContextSchema>
3940

41+
/** Default Git context options for commit message generation. */
4042
export const defaultCommitMessageGitContextSettings: Required<CommitMessageGitContextSettings> = {
4143
diffContextLines: 3,
4244
includeDiffStats: true,
@@ -49,23 +51,30 @@ export const defaultCommitMessageGitContextSettings: Required<CommitMessageGitCo
4951
recentCommitDiffCount: 1,
5052
}
5153

54+
/** Default attribution template appended to generated commit messages when enabled. */
5255
export const DEFAULT_COMMIT_MESSAGE_ATTRIBUTION_TEMPLATE = "Assisted-by: ${agentName}:${providerModel} [${toolName}]"
5356

57+
/** Schema for the optional attribution footer appended to generated commit messages. */
5458
export const commitMessageAttributionSchema = z.object({
5559
enabled: z.boolean().optional(),
5660
template: z.string().optional(),
5761
})
5862

5963
export type CommitMessageAttributionSettings = z.infer<typeof commitMessageAttributionSchema>
6064

65+
/** Default attribution settings for commit message generation. */
6166
export const defaultCommitMessageAttributionSettings: Required<CommitMessageAttributionSettings> = {
6267
enabled: false,
6368
template: DEFAULT_COMMIT_MESSAGE_ATTRIBUTION_TEMPLATE,
6469
}
6570

71+
/** Maximum number of named commit-message profiles users can store. */
6672
export const MAX_COMMIT_MESSAGE_PROFILES = 5
73+
74+
/** Stable id used by the synthesized default commit-message profile. */
6775
export const DEFAULT_COMMIT_MESSAGE_PROFILE_ID = "default"
6876

77+
/** Schema for one named commit-message generation profile. */
6978
export const commitMessageProfileSchema = z.object({
7079
id: z.string().optional(),
7180
name: z.string().optional(),
@@ -75,6 +84,7 @@ export const commitMessageProfileSchema = z.object({
7584
attribution: commitMessageAttributionSchema.optional(),
7685
})
7786

87+
/** Schema for persisted commit-message profile settings. */
7888
export const commitMessageProfilesSchema = z.object({
7989
activeProfileId: z.string().optional(),
8090
profiles: z.array(commitMessageProfileSchema).max(MAX_COMMIT_MESSAGE_PROFILES).optional(),
@@ -83,6 +93,7 @@ export const commitMessageProfilesSchema = z.object({
8393
export type CommitMessageProfileSettings = z.infer<typeof commitMessageProfileSchema>
8494
export type CommitMessageProfilesSettings = z.infer<typeof commitMessageProfilesSchema>
8595

96+
/** Fully-normalized commit-message profile used by runtime code and UI controls. */
8697
export type NormalizedCommitMessageProfile = Omit<
8798
CommitMessageProfileSettings,
8899
"id" | "name" | "gitContext" | "attribution"
@@ -94,17 +105,25 @@ export type NormalizedCommitMessageProfile = Omit<
94105
}
95106

96107
export interface NormalizedCommitMessageProfiles {
108+
/** Id of the profile currently selected for generation. */
97109
activeProfileId: string
110+
/** Normalized profiles available for generation. */
98111
profiles: NormalizedCommitMessageProfile[]
99112
}
100113

114+
/** Legacy single-profile settings used when named profiles are not stored yet. */
101115
export interface CommitMessageProfileFallbackSettings {
116+
/** Optional custom prompt from the legacy support prompt setting. */
102117
prompt?: string
118+
/** Optional API configuration id from the legacy single-profile setting. */
103119
apiConfigId?: string
120+
/** Optional Git context settings from the legacy single-profile setting. */
104121
gitContext?: CommitMessageGitContextSettings
122+
/** Optional attribution settings from the legacy single-profile setting. */
105123
attribution?: CommitMessageAttributionSettings
106124
}
107125

126+
/** Normalizes Git context settings and clamps numeric options to supported bounds. */
108127
export function normalizeCommitMessageGitContextSettings(
109128
settings?: CommitMessageGitContextSettings,
110129
): Required<CommitMessageGitContextSettings> {
@@ -132,6 +151,7 @@ export function normalizeCommitMessageGitContextSettings(
132151
}
133152
}
134153

154+
/** Normalizes attribution settings and restores the default template when needed. */
135155
export function normalizeCommitMessageAttributionSettings(
136156
settings?: CommitMessageAttributionSettings,
137157
): Required<CommitMessageAttributionSettings> {
@@ -142,6 +162,7 @@ export function normalizeCommitMessageAttributionSettings(
142162
}
143163
}
144164

165+
/** Normalizes persisted profiles or creates a default profile from fallback settings. */
145166
export function normalizeCommitMessageProfiles(
146167
settings?: CommitMessageProfilesSettings,
147168
fallback: CommitMessageProfileFallbackSettings = {},
@@ -179,6 +200,7 @@ export function normalizeCommitMessageProfiles(
179200
}
180201
}
181202

203+
/** Returns the active normalized commit-message profile. */
182204
export function getActiveCommitMessageProfile(
183205
settings?: CommitMessageProfilesSettings,
184206
fallback?: CommitMessageProfileFallbackSettings,
@@ -187,10 +209,12 @@ export function getActiveCommitMessageProfile(
187209
return normalized.profiles.find((profile) => profile.id === normalized.activeProfileId) ?? normalized.profiles[0]!
188210
}
189211

212+
/** Creates a locally unique id for a new commit-message profile. */
190213
export function createCommitMessageProfileId(): string {
191214
return `profile-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`
192215
}
193216

217+
/** Creates the next available display name for a new commit-message profile. */
194218
export function createCommitMessageProfileName(profiles: Array<{ name?: string }>): string {
195219
for (let index = profiles.length + 1; index <= MAX_COMMIT_MESSAGE_PROFILES + 1; index++) {
196220
const candidate = `Profile ${index}`

src/i18n/locales/hi/common.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/services/commit-message/__tests__/profileSettings.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe("commit message profile settings", () => {
5353
expect(settings.activeProfileId).toBe("profile-1")
5454
})
5555

56-
it("merges default Git context settings for each profile", () => {
56+
it("clamps recent commit diff count while merging default Git context settings", () => {
5757
const contextProxy = createContextProxy({
5858
commitMessageProfiles: {
5959
activeProfileId: "detailed",

src/services/commit-message/attribution.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ const ATTRIBUTION_TOOL_NAME = "Zoo Code"
1010
const UNKNOWN_VALUE = "unknown"
1111

1212
export interface CommitMessageAttributionTemplateValues {
13+
/** Name of the AI agent that assisted with the commit message. */
1314
agentName: string
15+
/** Name of the tool that produced the commit message. */
1416
toolName: string
17+
/** Provider key used for generation. */
1518
provider: string
19+
/** Model identifier used for generation. */
1620
model: string
21+
/** Combined provider/model value for compact templates. */
1722
providerModel: string
1823
}
1924

25+
/** Creates the attribution footer for a generated commit message when enabled. */
2026
export function createCommitMessageAttribution(
2127
settings: CommitMessageAttributionSettings | undefined,
2228
apiConfiguration: ProviderSettings,
@@ -38,6 +44,7 @@ export function createCommitMessageAttribution(
3844
})
3945
}
4046

47+
/** Replaces supported attribution placeholders with concrete generation metadata. */
4148
export function applyCommitMessageAttributionTemplate(
4249
template: string,
4350
values: CommitMessageAttributionTemplateValues,
@@ -48,6 +55,7 @@ export function applyCommitMessageAttributionTemplate(
4855
)
4956
}
5057

58+
/** Appends attribution once, preserving messages that already include the same footer. */
5159
export function appendCommitMessageAttribution(message: string, attribution: string): string {
5260
const cleanedMessage = message.trim()
5361
const cleanedAttribution = attribution.trim()

src/services/commit-message/gitContextSettings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { normalizeCommitMessageGitContextSettings, type CommitMessageGitContextSettings } from "@roo-code/types"
1+
import { type CommitMessageGitContextSettings } from "@roo-code/types"
22

33
import type { GitContextCollectorOptions } from "../git-context"
44
import { getActiveCommitMessageProfileSettings } from "./profileSettings"

src/services/commit-message/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ export function registerCommitMessageProvider(
1010
const commitProvider = new CommitMessageProvider(context, outputChannel)
1111
context.subscriptions.push(commitProvider)
1212

13-
commitProvider.activate().catch((error) => {
14-
outputChannel.appendLine(t("common:commitMessage.activationFailed", { error: error.message }))
15-
console.error("Commit message provider activation failed:", error)
16-
})
17-
18-
outputChannel.appendLine(t("common:commitMessage.providerRegistered"))
13+
commitProvider
14+
.activate()
15+
.then(() => {
16+
outputChannel.appendLine(t("common:commitMessage.providerRegistered"))
17+
})
18+
.catch((error) => {
19+
outputChannel.appendLine(t("common:commitMessage.activationFailed", { error: error.message }))
20+
console.error("Commit message provider activation failed:", error)
21+
})
1922
}

src/services/commit-message/profileSettings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import {
1111
import { ContextProxy } from "../../core/config/ContextProxy"
1212

1313
export interface CommitMessageProfileContextProxy {
14+
/** Reads persisted extension setting values by key. */
1415
getValue(key: any): unknown
1516
}
1617

18+
/** Reads all commit-message profiles, normalized with legacy single-profile fallbacks. */
1719
export function getCommitMessageProfileSettings(
1820
contextProxy: CommitMessageProfileContextProxy = ContextProxy.instance,
1921
): NormalizedCommitMessageProfiles {
@@ -23,6 +25,7 @@ export function getCommitMessageProfileSettings(
2325
)
2426
}
2527

28+
/** Reads the active commit-message profile for generator/provider runtime decisions. */
2629
export function getActiveCommitMessageProfileSettings(
2730
contextProxy: CommitMessageProfileContextProxy = ContextProxy.instance,
2831
): NormalizedCommitMessageProfile {
@@ -32,12 +35,14 @@ export function getActiveCommitMessageProfileSettings(
3235
)
3336
}
3437

38+
/** Reads the raw persisted commit-message profiles object if present. */
3539
function readCommitMessageProfiles(
3640
contextProxy: CommitMessageProfileContextProxy,
3741
): CommitMessageProfilesSettings | undefined {
3842
return contextProxy.getValue("commitMessageProfiles") as CommitMessageProfilesSettings | undefined
3943
}
4044

45+
/** Reads legacy single-profile settings used to synthesize the default profile. */
4146
function readSingleProfileFallback(contextProxy: CommitMessageProfileContextProxy) {
4247
const customSupportPrompts = (contextProxy.getValue("customSupportPrompts") || {}) as Record<
4348
string,

webview-ui/src/components/settings/__tests__/CommitMessagePromptSettings.spec.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ describe("CommitMessagePromptSettings", () => {
251251
/>,
252252
)
253253

254-
fireEvent.click(screen.getAllByRole("checkbox")[3])
254+
fireEvent.click(
255+
screen.getByRole("checkbox", {
256+
name: /supportPrompts\.commitMessage\.gitContext\.includeRecentCommitBodies/i,
257+
}),
258+
)
255259

256260
expect(setCommitMessageProfiles).toHaveBeenCalledWith({
257261
activeProfileId: "release",

webview-ui/src/i18n/locales/ja/prompts.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/pl/prompts.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)