--- name: git-smart-commit description: Generate intelligent conventional commit messages from staged changes. Analyzes diffs, auto-detects scope and breaking changes, and commits with approval. --- # Git Smart Commit Generate a precise conventional commit message from the currently staged changes, then commit after user approval. ## Steps ### 1. Gather Context Run these commands to understand the staged changes and recent commit style: ``` git diff --cached --stat git diff --cached git log --oneline -10 ``` If there are no staged changes, inform the user and suggest they stage files first (`git add `). Do not proceed with an empty diff. ### 2. Analyze the Diff Examine every file in the staged diff. Determine: - **What changed**: New files, modified logic, deleted code, config changes, dependency updates. - **Why it changed**: Infer intent from the nature of the change (new feature, bug fix, refactor, etc.). - **Scope**: Derive scope from the file paths. Use the most specific meaningful directory or module name. - `src/auth/login.ts` -> scope is `auth` - `tests/utils/parser.test.js` -> scope is `utils` - `package.json` only -> scope is `deps` - `.github/workflows/ci.yml` -> scope is `ci` - Multiple unrelated scopes -> omit scope or use the dominant one. - **Breaking changes**: Look for removed public APIs, renamed exports, changed function signatures, deleted fields, major dependency version bumps, or migration-requiring config changes. ### 3. Select Commit Type Choose exactly one type based on priority: | Type | When to use | |------------|-------------| | `feat` | New feature or capability added | | `fix` | Bug fix or correction | | `docs` | Documentation only changes | | `refactor` | Code restructuring with no behavior change | | `perf` | Performance improvement | | `test` | Adding or updating tests | | `ci` | CI/CD pipeline changes | | `build` | Build system or dependency changes | | `chore` | Maintenance tasks, tooling, config | | `style` | Formatting, whitespace, semicolons (no logic change) | | `revert` | Reverting a previous commit | ### 4. Compose the Commit Message Follow this structure: ``` ():