|
| 1 | +--- |
| 2 | +name: changelog-generator |
| 3 | +description: Generate and maintain CHANGELOG.md following Keep a Changelog format with human-readable descriptions. Use when: (1) Creating initial changelog from git tags, (2) Updating changelog for new releases, (3) Generating unreleased section for pull requests. Rule: NEVER use commit messages as source of truth - analyze code diffs instead. |
| 4 | +--- |
| 5 | + |
| 6 | +# Changelog Generator |
| 7 | + |
| 8 | +Generates and maintains CHANGELOG.md following the Keep a Changelog format with clear, specific, and self-sufficient descriptions. |
| 9 | + |
| 10 | +## Dependencies |
| 11 | + |
| 12 | +- `phly/keep-a-changelog` - Installed in project |
| 13 | +- Git - For analyzing code changes |
| 14 | +- Filesystem - For reading/writing CHANGELOG.md |
| 15 | + |
| 16 | +## Key Commands |
| 17 | + |
| 18 | +```bash |
| 19 | +vendor/bin/changelog # Main CLI |
| 20 | +vendor/bin/changelog add:entry # Add entry to version |
| 21 | +vendor/bin/changelog release # Create release |
| 22 | +``` |
| 23 | + |
| 24 | +## Execution Pipeline (Deterministic) |
| 25 | + |
| 26 | +### Stage 1: Initial State |
| 27 | + |
| 28 | +1. Check if CHANGELOG.md exists and has content: |
| 29 | + ```bash |
| 30 | + ls -la CHANGELOG.md 2>/dev/null || echo "NO_FILE" |
| 31 | + ``` |
| 32 | + |
| 33 | +### Stage 2: Version Discovery |
| 34 | + |
| 35 | +1. List all tags sorted semantically: |
| 36 | + ```bash |
| 37 | + git tag --sort=-version:refname |
| 38 | + ``` |
| 39 | + |
| 40 | +2. Identify: |
| 41 | + - Last documented version in CHANGELOG |
| 42 | + - Tags not yet documented |
| 43 | + |
| 44 | +### Stage 3: Historical Content Generation |
| 45 | + |
| 46 | +**Case A: No CHANGELOG or Empty** |
| 47 | + |
| 48 | +For each tag (ascending order): |
| 49 | +1. Calculate diff between current tag and previous tag (or first commit for initial version) |
| 50 | +2. Analyze code diff to infer changes (NOT commit messages) |
| 51 | +3. Group changes by type (Added, Changed, Fixed, Removed, Deprecated, Security) |
| 52 | +4. Insert version section |
| 53 | + |
| 54 | +**B: Existing CHANGELOG** |
| 55 | + |
| 56 | +1. Identify last documented version |
| 57 | +2. For each subsequent tag: |
| 58 | + - Generate diff between versions |
| 59 | + - Insert new section in changelog |
| 60 | + |
| 61 | +### Stage 4: Unreleased Section |
| 62 | + |
| 63 | +1. Calculate diff between last documented tag and HEAD |
| 64 | +2. Generate [Unreleased] section with current changes |
| 65 | + |
| 66 | +## Change Classification (Inferred from Diff) |
| 67 | + |
| 68 | +Analyze actual code changes, NOT commit messages: |
| 69 | + |
| 70 | +| Pattern | Category | |
| 71 | +|---------|----------| |
| 72 | +| New files, new classes, new methods | Added | |
| 73 | +| Behavior changes, refactors, signature changes | Changed | |
| 74 | +| Bug fixes, validation fixes | Fixed | |
| 75 | +| Deleted classes, removed methods | Removed | |
| 76 | +| @deprecated markers | Deprecated | |
| 77 | +| Security patches | Security | |
| 78 | + |
| 79 | +## Quality Rules |
| 80 | + |
| 81 | +- **SHORT**: One line per change |
| 82 | +- **SPECIFIC**: Include class/method names |
| 83 | +- **SELF-SUFFICIENT**: Understand without reading code |
| 84 | +- **FUNCTIONAL**: Describe impact, not implementation |
| 85 | + |
| 86 | +Good: "Added `Bootstrapper::bootstrap()` to create CHANGELOG.md when missing" |
| 87 | +Bad: "Add bootstrap command" |
| 88 | + |
| 89 | +## Integration with keep-a-changelog |
| 90 | + |
| 91 | +Use CLI commands when possible: |
| 92 | + |
| 93 | +```bash |
| 94 | +# Add unreleased entry |
| 95 | +vendor/bin/changelog add:entry --unreleased --type=added "Description" |
| 96 | + |
| 97 | +# Add release entry |
| 98 | +vendor/bin/changelog add:entry 1.0.0 --type=added "Description" |
| 99 | + |
| 100 | +# Create release |
| 101 | +vendor/bin/changelog release 1.0.0 --date="2026-04-11" |
| 102 | +``` |
| 103 | + |
| 104 | +Edit CHANGELOG.md directly if CLI insufficient. |
| 105 | + |
| 106 | +## Verification |
| 107 | + |
| 108 | +Valid changelog MUST have: |
| 109 | +- All sections: Added, Changed, Deprecated, Removed, Fixed, Security |
| 110 | +- No "Nothing." placeholders (unless truly empty) |
| 111 | +- Reverse chronological order (newest first) |
| 112 | +- [Unreleased] at top when applicable |
| 113 | + |
| 114 | +## Reference Files |
| 115 | + |
| 116 | +- [references/keep-a-changelog-format.md](references/keep-a-changelog-format.md) - Format spec |
| 117 | +- [references/change-categories.md](references/change-categories.md) - Classification guide |
| 118 | +- [references/description-patterns.md](references/description-patterns.md) - Human-readable patterns |
0 commit comments