@@ -23,6 +23,7 @@ import { languagesSchema } from "./vscode.js"
2323 */
2424export const DEFAULT_WRITE_DELAY_MS = 1000
2525
26+ /** Schema for optional Git context included with generated commit message prompts. */
2627export 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
3839export type CommitMessageGitContextSettings = z . infer < typeof commitMessageGitContextSchema >
3940
41+ /** Default Git context options for commit message generation. */
4042export 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. */
5255export const DEFAULT_COMMIT_MESSAGE_ATTRIBUTION_TEMPLATE = "Assisted-by: ${agentName}:${providerModel} [${toolName}]"
5356
57+ /** Schema for the optional attribution footer appended to generated commit messages. */
5458export const commitMessageAttributionSchema = z . object ( {
5559 enabled : z . boolean ( ) . optional ( ) ,
5660 template : z . string ( ) . optional ( ) ,
5761} )
5862
5963export type CommitMessageAttributionSettings = z . infer < typeof commitMessageAttributionSchema >
6064
65+ /** Default attribution settings for commit message generation. */
6166export 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. */
6672export const MAX_COMMIT_MESSAGE_PROFILES = 5
73+
74+ /** Stable id used by the synthesized default commit-message profile. */
6775export const DEFAULT_COMMIT_MESSAGE_PROFILE_ID = "default"
6876
77+ /** Schema for one named commit-message generation profile. */
6978export 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. */
7888export 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({
8393export type CommitMessageProfileSettings = z . infer < typeof commitMessageProfileSchema >
8494export type CommitMessageProfilesSettings = z . infer < typeof commitMessageProfilesSchema >
8595
96+ /** Fully-normalized commit-message profile used by runtime code and UI controls. */
8697export type NormalizedCommitMessageProfile = Omit <
8798 CommitMessageProfileSettings ,
8899 "id" | "name" | "gitContext" | "attribution"
@@ -94,17 +105,25 @@ export type NormalizedCommitMessageProfile = Omit<
94105}
95106
96107export 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. */
101115export 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. */
108127export 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. */
135155export 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. */
145166export 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. */
182204export 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. */
190213export 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. */
194218export 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 } `
0 commit comments