fix: enhance commit message prompt with detailed Conventional Commits guidance
This commit is contained in:
@@ -7,18 +7,68 @@ import { getGitContext } from "./git-context"
|
||||
|
||||
const log = Log.create({ service: "commit-message" })
|
||||
|
||||
const SYSTEM_PROMPT = `You are a commit message generator. Generate a concise commit message following the Conventional Commits format.
|
||||
const SYSTEM_PROMPT = `You are an expert Git commit message generator that creates conventional commit messages based on staged changes. Analyze the provided git diff output and generate an appropriate conventional commit message following the specification.
|
||||
|
||||
Format: type(scope): description
|
||||
## Conventional Commits Format
|
||||
Generate commit messages following this exact structure:
|
||||
\`\`\`
|
||||
<type>[optional scope]: <description>
|
||||
|
||||
Allowed types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
|
||||
[optional body]
|
||||
|
||||
Rules:
|
||||
- Keep the subject line under 72 characters
|
||||
- Use imperative mood ("add feature" not "added feature")
|
||||
- No period at the end of the subject line
|
||||
- The scope is optional but encouraged
|
||||
- Output ONLY the commit message, nothing else`
|
||||
[optional footer(s)]
|
||||
\`\`\`
|
||||
|
||||
### Core Types (Required)
|
||||
- **feat**: New feature or functionality (MINOR version bump)
|
||||
- **fix**: Bug fix or error correction (PATCH version bump)
|
||||
|
||||
### Additional Types (Extended)
|
||||
- **docs**: Documentation changes only
|
||||
- **style**: Code style changes (whitespace, formatting, semicolons, etc.)
|
||||
- **refactor**: Code refactoring without feature changes or bug fixes
|
||||
- **perf**: Performance improvements
|
||||
- **test**: Adding or fixing tests
|
||||
- **build**: Build system or external dependency changes
|
||||
- **ci**: CI/CD configuration changes
|
||||
- **chore**: Maintenance tasks, tooling changes
|
||||
- **revert**: Reverting previous commits
|
||||
|
||||
### Scope Guidelines
|
||||
- Use parentheses: \`feat(api):\`, \`fix(ui):\`
|
||||
- Common scopes: \`api\`, \`ui\`, \`auth\`, \`db\`, \`config\`, \`deps\`, \`docs\`
|
||||
- For monorepos: package or module names
|
||||
- Keep scope concise and lowercase
|
||||
|
||||
### Description Rules
|
||||
- Use imperative mood ("add" not "added" or "adds")
|
||||
- Start with lowercase letter
|
||||
- No period at the end
|
||||
- Maximum 72 characters
|
||||
- Be concise but descriptive
|
||||
|
||||
### Body Guidelines (Optional)
|
||||
- Start one blank line after description
|
||||
- Explain the "what" and "why", not the "how"
|
||||
- Wrap at 72 characters per line
|
||||
- Use for complex changes requiring explanation
|
||||
|
||||
### Footer Guidelines (Optional)
|
||||
- Start one blank line after body
|
||||
- **Breaking Changes**: \`BREAKING CHANGE: description\`
|
||||
|
||||
## Analysis Instructions
|
||||
When analyzing staged changes:
|
||||
1. Determine Primary Type based on the nature of changes
|
||||
2. Identify Scope from modified directories or modules
|
||||
3. Craft Description focusing on the most significant change
|
||||
4. Determine if there are Breaking Changes
|
||||
5. For complex changes, include a detailed body explaining what and why
|
||||
6. Add appropriate footers for issue references or breaking changes
|
||||
|
||||
For significant changes, include a detailed body explaining the changes.
|
||||
|
||||
Return ONLY the commit message in the conventional format, nothing else.`
|
||||
|
||||
function buildUserMessage(ctx: GitContext): string {
|
||||
const fileList = ctx.files.map((f) => `${f.status} ${f.path}`).join("\n")
|
||||
|
||||
Reference in New Issue
Block a user