# Git Commit Formatter

> **Purpose:** Analyze staged changes and generate a properly formatted conventional commit message.

---

## Invocation

```
/commit
```

Runs `git diff --cached --stat` and `git diff --cached` to analyze staged changes.

---

## Conventional Commit Format

```
<type>(<scope>): <description>

[optional body]

[optional footer]
```

### Types

| Type | When to use |
|------|-------------|
| `feat` | New feature or capability |
| `fix` | Bug fix |
| `refactor` | Code restructuring without behavior change |
| `test` | Adding or updating tests |
| `docs` | Documentation only |
| `style` | Formatting, whitespace, semicolons |
| `perf` | Performance improvement |
| `ci` | CI/CD configuration |
| `chore` | Dependencies, tooling, config |
| `build` | Build system or external dependency changes |

### Scope Detection

Infer scope from the changed files:
- `components/auth/*` → `auth`
- `api/skills/*` → `skills-api`
- `lib/utils/*` → `utils`
- Multiple unrelated areas → omit scope

### Description Rules

- Imperative mood: "add" not "added" or "adds"
- No period at the end
- Under 72 characters
- Focus on **why**, not **what** (the diff shows what)

---

## Body Guidelines

Include a body when:
- The change is not obvious from the description
- Multiple files are modified for different reasons
- Breaking changes need explanation

Format:
- Wrap at 72 characters
- Separate from subject with blank line
- Use bullet points for multiple changes

---

## Footer

- `BREAKING CHANGE: <description>` — for breaking API changes
- `Closes #123` — for issue references
- `Co-Authored-By: Name <email>` — for pair programming

---

## Examples

**Simple feature:**
```
feat(auth): add GitHub OAuth login flow
```

**Bug fix with context:**
```
fix(api): prevent duplicate skill submissions

The content checksum was computed before sanitization,
allowing whitespace-only differences to bypass dedup.

Closes #47
```

**Breaking change:**
```
refactor(skills)!: rename focus_pool to engagement_score

BREAKING CHANGE: focus_pool column renamed to engagement_score.
Run migration 20260301 before deploying.
```

## Playground

<!DOCTYPE html><html><head><meta charset='utf-8'><style>*{box-sizing:border-box;margin:0;padding:0}body{background:#0d1117;color:#e6edf3;font-family:monospace;font-size:12px;height:100vh;display:flex;flex-direction:column;overflow:hidden}.header{background:#161b22;border-bottom:1px solid #30363d;padding:8px 14px;font-size:11px;color:#8b949e;display:flex;justify-content:space-between;align-items:center;flex-shrink:0}.title{color:#58a6ff;font-weight:bold;font-size:13px}.panels{display:flex;flex:1;overflow:hidden}.panel{flex:1;overflow:auto;padding:12px;border-right:1px solid #30363d}.panel:last-child{border-right:none}.label{font-size:10px;color:#8b949e;text-transform:uppercase;letter-spacing:.08em;margin-bottom:6px}pre{white-space:pre-wrap;word-break:break-word;line-height:1.5}</style></head><body><div class='header'><span class='title'>Git Commit Formatter</span><span>Example · SkillSlap</span></div><div class='panels'><div class='panel'><div class='label'>Input: Raw description</div><pre><span style='color:#8b949e'>i fixed the thing where users would</span>
<span style='color:#8b949e'>get logged out randomly after like</span>
<span style='color:#8b949e'>30 mins even though their session</span>
<span style='color:#8b949e'>should still be valid. also bumped</span>
<span style='color:#8b949e'>the session timeout from 1h to 8h</span></pre></div><div class='panel'><div class='label'>Output: Commit message</div><pre><span style='color:#3fb950'>fix(auth): prevent premature session expiry</span>

<span style='color:#8b949e'>Sessions were invalidated after 30 min</span>
<span style='color:#8b949e'>due to a clock-skew bug in the JWT</span>
<span style='color:#8b949e'>expiry check (server UTC vs client</span>
<span style='color:#8b949e'>local time comparison).</span>

<span style='color:#8b949e'>Also extends session lifetime from 1h</span>
<span style='color:#8b949e'>to 8h to match UX expectations.</span>

<span style='color:#8b949e'>Fixes #247</span>

<span style='color:#8b949e'>─────────────────────</span>
<span style='color:#8b949e'>Type:    fix  |  Scope: auth</span>
<span style='color:#8b949e'>Breaking: no  |  Refs: #247</span></pre></div></div></body></html>