Skip to content

Commit bc751d9

Browse files
committed
refactor(generator): update prompt for strict commit message rules
- enforce single commit message generation - clarify primary type selection and output format - improve instructions for imperative mood and description length
1 parent 4a257d2 commit bc751d9

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

lua/codecompanion/_extensions/gitcommit/generator.lua

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,34 +73,37 @@ end
7373
---@return string prompt The formatted prompt
7474
function Generator._create_prompt(diff, lang)
7575
return string.format(
76-
[[Generate Conventional Commit compliant messages
76+
[[You are a commit message generator. Generate exactly ONE Conventional Commit message for the provided git diff.
7777
78-
When to use:
79-
• When analyzing git diffs for commit messages
80-
• When standardizing commit format across projects
81-
• When ensuring consistent commit message patterns
82-
• When generating structured commit documentation
83-
84-
Best practices:
85-
• Must include required type (feat, fix, docs, style, refactor, perf, test, chore)
86-
• Use lowercase for type, optional scope in parentheses
87-
• Start description with imperative verb, keep under 50 characters
88-
• Add body with bullet points for complex changes
89-
• Ensure language matches specification: %s
78+
CRITICAL RULES:
79+
1. Generate ONLY ONE commit message, never multiple messages
80+
2. Analyze ALL changes in the diff as a single logical unit
81+
3. Choose the most significant change type if multiple types exist
82+
4. Respond with ONLY the commit message, no additional text or explanations
9083
9184
Format: type(scope): description
9285
93-
Example:
86+
Types: feat, fix, docs, style, refactor, perf, test, chore
87+
Language: %s
88+
89+
Requirements:
90+
- Use imperative mood ("add" not "added")
91+
- Keep description under 50 characters
92+
- Add body with bullet points for complex changes only if necessary
93+
- Choose the primary type that best represents the overall change
94+
95+
Example output format:
9496
feat(auth): add OAuth2 integration
9597
9698
- implement Google OAuth provider
97-
- update user authentication flow
98-
- add integration tests
99+
- update authentication flow
99100
100-
Generate commit message for this diff:
101+
Generate ONE commit message for this diff:
101102
```diff
102103
%s
103-
```]],
104+
```
105+
106+
Response format: Return only the commit message, nothing else.]],
104107
lang or "English",
105108
diff
106109
)

0 commit comments

Comments
 (0)