@@ -85,6 +85,22 @@ func findGitRoot(dir string) (string, error) {
85
85
}
86
86
87
87
const styleGuideFilename = "COMMITS.md"
88
+ const defaultUserStyleGuide = `
89
+ 1. Limit the subject line to 50 characters.
90
+ 2. Use the imperative mood in the subject line.
91
+ 3. Capitalize the subject line such as "Fix Issue 886" and don't end it with a period.
92
+ 4. The subject line should summarize the main change concisely.
93
+ 5. Only include a body if absolutely necessary for complex changes.
94
+ 6. If a body is needed, separate it from the subject with a blank line.
95
+ 7. Wrap the body at 72 characters.
96
+ 8. In the body, explain the why, not the what (the diff shows the what).
97
+ 9. Use bullet points in the body only for truly distinct changes.
98
+ 10. Be extremely concise. Assume the reader can understand the diff.
99
+ 11. Never repeat information between the subject and body.
100
+ 12. Do not repeat commit messages from previous commits.
101
+ 13. Prioritize clarity and brevity over completeness.
102
+ 14. Adhere to the repository's commit style if it exists.
103
+ `
88
104
89
105
// findRepoStyleGuide searches for "COMMITS.md" in the repository root of dir
90
106
// and returns its contents.
@@ -101,7 +117,7 @@ func findRepoStyleGuide(dir string) (string, error) {
101
117
}
102
118
return "" , fmt .Errorf ("read style guide: %w" , err )
103
119
}
104
- return string (styleGuide ), nil
120
+ return strings . TrimSpace ( string (styleGuide ) ), nil
105
121
}
106
122
107
123
func findUserStyleGuide () (string , error ) {
@@ -116,8 +132,7 @@ func findUserStyleGuide() (string, error) {
116
132
}
117
133
return "" , fmt .Errorf ("read user style guide: %w" , err )
118
134
}
119
-
120
- return string (styleGuide ), nil
135
+ return strings .TrimSpace (string (styleGuide )), nil
121
136
}
122
137
123
138
func BuildPrompt (
@@ -132,21 +147,7 @@ func BuildPrompt(
132
147
Role : openai .ChatMessageRoleSystem ,
133
148
Content : strings .Join ([]string {
134
149
"You are a tool called `aicommit` that generates high quality commit messages for git diffs." ,
135
- "Generate only the commit message, without any additional text. Follow these guidelines:" ,
136
- "1. Limit the subject line to 50 characters." ,
137
- "2. Use the imperative mood in the subject line." ,
138
- "3. Capitalize the subject line and don't end it with a period." ,
139
- "4. The subject line should summarize the main change concisely." ,
140
- "5. Only include a body if absolutely necessary for complex changes." ,
141
- "6. If a body is needed, separate it from the subject with a blank line." ,
142
- "7. Wrap the body at 72 characters." ,
143
- "8. In the body, explain the why, not the what (the diff shows the what)." ,
144
- "9. Use bullet points in the body only for truly distinct changes." ,
145
- "10. Be extremely concise. Assume the reader can understand the diff." ,
146
- "11. Never repeat information between the subject and body." ,
147
- "12. Do not repeat commit messages from previous commits." ,
148
- "13. Prioritize clarity and brevity over completeness." ,
149
- "14. Adhere to the repository's commit style if it exists." ,
150
+ "Generate only the commit message, without any additional text." ,
150
151
}, "\n " ),
151
152
},
152
153
}
@@ -258,12 +259,13 @@ func BuildPrompt(
258
259
if err != nil {
259
260
return nil , fmt .Errorf ("find user style guide: %w" , err )
260
261
}
261
- if userStyleGuide != "" {
262
- resp = append (resp , openai.ChatCompletionMessage {
263
- Role : openai .ChatMessageRoleSystem ,
264
- Content : "This user has a preferred style guide:\n " + userStyleGuide ,
265
- })
262
+ if userStyleGuide == "" {
263
+ userStyleGuide = defaultUserStyleGuide
266
264
}
265
+ resp = append (resp , openai.ChatCompletionMessage {
266
+ Role : openai .ChatMessageRoleSystem ,
267
+ Content : "This user has a preferred style guide:\n " + userStyleGuide ,
268
+ })
267
269
}
268
270
269
271
resp = append (resp , openai.ChatCompletionMessage {
0 commit comments