---
name: gen-commit
description: Generate a git commit message from staged changes following dev1sme/git-skills Conventional Commits convention. Use when ba wants to commit but needs a well-structured commit message.
user-invocable: true
argument-hint: "[ticket-id or context]"
allowed-tools: Bash, Read
model: inherit
context: fork
---

# Generate Commit Message

Sinh commit message chuẩn từ staged changes, theo convention tại [dev1sme/git-skills](https://github.com/dev1sme/git-skills).

**Context thêm:** `$ARGUMENTS`

---

## Các bước

1. Chạy `git diff --staged` để xem nội dung thay đổi
2. Chạy `git status --short` để xem danh sách files
3. Chạy `git log --oneline -5` để hiểu context của commit gần nhất
4. Phân tích → xác định type, scope, subject
5. Sinh commit message → commit ngay

---

## Format

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

<body>

<footer>
```

## 11 Types

| Type | Khi nào dùng |
|---|---|
| `feat` | Thêm tính năng mới |
| `fix` | Sửa bug |
| `docs` | Chỉ thay đổi tài liệu |
| `style` | Format code, không đổi logic (spaces, indent) |
| `refactor` | Tái cấu trúc — không feat, không fix |
| `perf` | Cải thiện performance |
| `test` | Thêm hoặc sửa tests |
| `build` | Build system hoặc dependencies |
| `ci` | CI/CD config |
| `chore` | Việc vặt không ảnh hưởng src/test |
| `revert` | Revert commit trước |

## Rules viết subject

- **Viết thường** chữ đầu tiên
- **Động từ nguyên mẫu**: add, fix, update, remove, extract, migrate...
- **Không dấu chấm** cuối
- **Max 72 ký tự** cho toàn bộ dòng đầu (`type(scope): subject`)
- Mô tả **what** thay đổi, không phải how

## Body (viết khi cần)

- Cách subject **1 dòng trống**
- Giải thích **WHY** — tại sao cần thay đổi này? WHAT đã rõ từ diff
- Mỗi dòng max 72 ký tự

## Footer

```
# Breaking change
BREAKING CHANGE: mô tả impact và migration path

# Issue reference (nếu $ARGUMENTS có ticket ID)
Closes #123
Refs #456
```

---

## Commit Identity

Commit **không được** thêm bất kỳ trailer nào ngoài issue refs:
- ❌ `Co-Authored-By: ...`
- ❌ `Signed-off-by: ...`
- ✅ Chỉ có `Closes #` hoặc `Refs #` nếu có ticket

---

## Sau khi sinh message

Commit ngay bằng:

```bash
git commit -m "$(cat <<'EOF'
<type>(<scope>): <subject>

<body nếu có>

<footer nếu có>
EOF
)"
```

**Không hỏi ba** — commit luôn. Nếu ba muốn chỉnh → `git commit --amend`.
