Skip to content

Commit d796e14

Browse files
authored
Merge pull request #14 from sudoeren/fix/improve-ai-commit-suggestions
fix: strengthen AI prompt for multi-line commit messages
2 parents 382fdb6 + dde1fbe commit d796e14

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

src/helpers/ai.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -228,42 +228,48 @@ async function generateCommitSuggestions(
228228
instructionText = `\nIMPORTANT USER INSTRUCTION: ${activeInstruction}\n`;
229229
}
230230

231-
const prompt = `You are a Git commit message generator. Based on the following changes${activeInstruction ? " and the user instruction" : ""}, suggest ${count} different commit messages. Each should be in Conventional Commits format.
231+
const prompt = `You are a Git commit message generator. Based on the following changes${activeInstruction ? " and the user instruction" : ""}, suggest ${count} different commit messages. Each MUST follow Conventional Commits format with a detailed body.
232232
${instructionText}
233233
Changed files:
234234
${filesList.join("\n")}
235235
236236
Diff:
237237
${diff.substring(0, 3000)}
238238
239-
For each suggestion, write:
240-
1. **Subject line**: Type, scope (optional), and brief description. Max 50 characters. Use imperative mood.
241-
2. **Blank line**
242-
3. **Body**: Explain WHAT changed and WHY. Wrap at 72 characters. Use bullet points for multiple changes.
239+
CRITICAL FORMAT REQUIREMENTS:
240+
Each suggestion MUST have:
241+
1. Subject line (max 50 chars): type(scope): brief description
242+
2. Empty line
243+
3. Body section with 2-4 bullet points explaining WHAT changed and WHY
243244
244-
Separate each suggestion with "---" on its own line.
245+
EXAMPLE 1:
246+
feat(auth): add JWT token validation
245247
246-
Example format:
247-
feat: add user authentication
248+
- Implement token verification middleware
249+
- Add refresh token rotation for security
250+
- Store tokens in httpOnly cookies
248251
249-
- Implement JWT token validation
250-
- Add login endpoint with rate limiting
251-
- Store refresh tokens securely
252+
EXAMPLE 2:
253+
fix(ui): resolve dark mode contrast issues
252254
253-
---
255+
- Update color palette for better accessibility
256+
- Add CSS variables for theme switching
257+
- Test with WCAG 2.1 AA standards
254258
255-
fix: resolve memory leak in cache
259+
EXAMPLE 3:
260+
refactor(api): optimize database queries
256261
257-
- Clear expired entries every 5 minutes
258-
- Use WeakMap for object references
262+
- Add indexes for frequently queried fields
263+
- Implement query caching with Redis
264+
- Reduce response time by 40%
259265
260-
Write exactly ${count} suggestions, no other explanations.`;
266+
Write exactly ${count} suggestions following this format. Separate each with "---" on its own line. Do NOT write single-line messages.`;
261267

262268
const messages = [
263269
{
264270
role: "system",
265271
content:
266-
"You are a helpful assistant that generates professional Git commit messages. Always include a subject line and a detailed body explaining the changes.",
272+
"You are a professional Git commit message writer. ALWAYS generate multi-line messages with a subject and detailed body. Never write single-line commits.",
267273
},
268274
{
269275
role: "user",
@@ -276,7 +282,7 @@ Write exactly ${count} suggestions, no other explanations.`;
276282

277283
for (let attempt = 0; attempt < maxRetries; attempt++) {
278284
try {
279-
const content = await callProvider(config.aiProvider, messages, 0.7, 600);
285+
const content = await callProvider(config.aiProvider, messages, 0.7, 1000);
280286

281287
if (!content || content.trim().length < 10) {
282288
throw new Error(`AI Provider (${config.aiProvider}) returned empty or too short response: "${content}"`);

0 commit comments

Comments
 (0)