Skip to content

Enhance commit message generation with intention-revealing prompts and quality controls#1

Merged
inem merged 3 commits intomainfrom
copilot/fix-31f81c49-913a-4f66-8306-4773c2fb150a
Aug 12, 2025
Merged

Enhance commit message generation with intention-revealing prompts and quality controls#1
inem merged 3 commits intomainfrom
copilot/fix-31f81c49-913a-4f66-8306-4773c2fb150a

Conversation

Copy link
Contributor

Copilot AI commented Aug 12, 2025

This PR significantly improves the quality of AI-generated commit messages by replacing simplistic prompts with rich, intention-revealing instructions and adding robust output quality controls.

Key Improvements

🎯 Rich, Context-Aware Prompts

Replaced basic prompts with comprehensive instructions that:

  • Emphasize inferring the underlying intent/WHY of changes rather than mechanical file listings
  • Enforce imperative mood and encourage specific action verbs (Add, Fix, Refactor, Optimize) over bland terms like "update"
  • Provide tailored guidance for different scenarios:
    • Static assets only → "Refine layout spacing", "Update hero images"
    • Tests only → "Add tests for X feature"
    • Performance changes → "Optimize query building"
    • Error handling → "Handle nil pointer in config loader"

🔄 Two Distinct Prompt Templates

  • File-list mode (..): Derives intent purely from changed file names and static/non-static separation
  • Diff mode (.): Analyzes full diff content plus static file list for deeper context

📏 Enhanced Output Quality

  • Increased token limit: 20 → 40 tokens to allow more nuanced single-line titles
  • Post-processing controls:
    • Ensures single line only (strips content after first newline)
    • Enforces ≤70 character limit with smart truncation
    • Removes quotes, punctuation, and code fences

Example Output Improvements

Before:

Update main.go and styles.css

After:

Add user authentication with responsive login form

Backward Compatibility

✅ All existing functionality preserved:

  • Only processes commit messages "." and ".."
  • Maintains debug logging to .git/commit-msg-debug.log
  • Continues excluding static assets from diffs
  • No new external dependencies

The implementation compiles cleanly and maintains the same CLI interface while dramatically improving commit message quality through better AI instruction and output sanitization.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Improve AI commit message prompt to infer intent Enhance commit message generation with intention-revealing prompts and quality controls Aug 12, 2025
Copilot AI requested a review from inem August 12, 2025 07:45
@inem inem marked this pull request as ready for review August 12, 2025 09:04
@inem inem merged commit 52d953e into main Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants