AgentSkillsCN

commit

以规范化的提交信息格式创建 Git 提交。当用户输入 /commit 时,可使用此技能。

SKILL.md
--- frontmatter
name: commit
description: "Create git commits with conventional commit messages. Use when user says /commit."
user-invocable: true
allowed-tools:
  - Read
  - Bash
  - Glob
  - Grep

Commit

Purpose

Create standardized git commits following Conventional Commits specification. Analyzes changes to determine appropriate type, scope, and message.

Quick Reference

  • Setup: /commit configure (run once per project)
  • Usage: /commit (uses saved scopes)
  • Update: /commit learn (re-analyze scopes from recent commits)
  • Config: Depends on installation model (see Save Location)

Commands

CommandPurposeWhen to Use
/commit configureAnalyze project for commit scopesFirst time in a project
/commit learnUpdate scopes from recent commitsAfter project changes
/commitCreate commit using saved scopesNormal usage

/commit configure

When: First time using /commit in a project

What it does:

  1. Scans project structure for scope candidates
  2. Analyzes recent commit history for patterns
  3. Proposes scope configuration to user
  4. Saves config based on plugin installation scope

Discovery Process

code
1. SCAN PROJECT STRUCTURE
   ├─ Top-level src/ directories
   ├─ Workspace packages (package.json workspaces)
   ├─ Go modules (go.work)
   └─ Python packages (pyproject.toml)

2. ANALYZE COMMIT HISTORY
   ├─ Extract scopes from last 100 commits
   ├─ Count frequency of each scope
   └─ Identify naming patterns

3. PROPOSE TO USER
   └─ Show discovered scopes, wait for approval

Proposal Format

yaml
# Proposed Commit Configuration
# Review and approve to save to .claude/skills/commit.yaml

scopes:
  - name: api
    description: "REST API endpoints"
    paths: ["src/api/", "api/"]
  - name: auth
    description: "Authentication and authorization"
    paths: ["src/auth/", "src/middleware/auth"]
  - name: db
    description: "Database and migrations"
    paths: ["src/db/", "migrations/"]
  - name: ui
    description: "User interface components"
    paths: ["src/components/", "src/pages/"]
  - name: core
    description: "Core business logic"
    paths: ["src/core/", "src/domain/"]
  - name: infra
    description: "Infrastructure and deployment"
    paths: ["infra/", "terraform/", "k8s/"]
  - name: deps
    description: "Dependencies"
    paths: ["package.json", "go.mod", "Cargo.toml"]
  - name: ci
    description: "CI/CD configuration"
    paths: [".github/", ".gitlab-ci.yml"]

types:
  changelog_worthy: [feat, fix, perf]
  internal: [chore, ci, test, docs, style, refactor, build]

rules:
  max_title_length: 50
  require_scope: false
  require_body: false
  forbidden_words: ["stuff", "things", "misc", "update", "improve"]

Save Location

Config path depends on the installation model. Detect which model is active by checking whether this skill is running from inside .claude/skills/commit/ (my-workflow) or from an external plugin directory (standalone).

Installation ModelConfig FileHow to Detect
Standalone (external plugin).claude/skills/commit.yamlSkill files are NOT inside .claude/skills/commit/
my-workflow (copied into project).claude/skills/commit/commit.yamlSkill files ARE inside .claude/skills/commit/

Precedence when reading (first found wins):

  1. .claude/skills/commit/commit.yaml (my-workflow installation)
  2. .claude/skills/commit.yaml (standalone installation)
  3. Skill defaults

/commit learn

When: Project structure changed, want to update scopes

What it does:

  1. Re-analyzes project structure
  2. Scans recent commits for new scopes
  3. Proposes updates to config
  4. Updates existing config file (respects installation model)

/commit (Normal Usage)

When: Creating a commit

Reads config from (first found):

  1. .claude/skills/commit/commit.yaml (copied installation)
  2. .claude/skills/commit.yaml (plugin installation)
  3. Skill defaults

Workflow

code
1. PRE-COMMIT CHECKS (before any commit)
   ├─ Check not on main/master branch
   ├─ Check no secrets in staged files (.env, credentials, .pem, .key)
   └─ STOP if any check fails

2. ANALYZE CHANGES
   ├─ git status --porcelain
   ├─ git diff --staged
   └─ git diff (unstaged)

3. DETERMINE SCOPE
   └─ Match changed files to scopes from config

4. GENERATE MESSAGE
   ├─ Type: from change analysis
   ├─ Scope: from config mapping
   └─ Subject: from change description

5. USER CONFIRMATION
   └─ Show message, wait for approval

6. EXECUTE COMMIT
   └─ git commit with approved message

Conventional Commit Format

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

<optional body - 1-2 sentences>

Commit Types

TypePurposeChangelog
featNew featureYes
fixBug fixYes
docsDocumentation onlyNo
styleFormatting (no logic)No
refactorCode refactorNo
perfPerformance improvementYes
testAdd/update testsNo
buildBuild system/depsNo
ciCI/config changesNo
choreMaintenanceNo
revertRevert commitYes

Rules

  • Title ≤ 50 characters
  • Title is SPECIFIC (no vague words)
  • Imperative mood ("add" not "added")
  • Body: 1-2 sentences max, or omit
  • Focus on WORK done, not file operations
  • Never commit secrets
  • NO AI attribution
  • NO ticket references (put in PR instead)

AI Attribution Policy

STRICTLY FORBIDDEN - Never include:

  • Co-Authored-By: Claude or any AI name
  • 🤖 emoji or AI-related emojis
  • "Generated by", "Created with"
  • Any reference to AI tools

Git Safety

  • NEVER commit directly to main/master
  • NEVER run destructive commands
  • NEVER skip hooks unless user asks
  • If hook fails: fix issue, create NEW commit (don't amend)

Examples

Good:

code
feat(auth): add OAuth2 login support

Adds Google and GitHub OAuth providers.
code
fix(api): handle null response from external service
code
refactor(db): extract query builder to separate module

Bad:

  • chore: update stuff (vague)
  • feat(api): improved performance (past tense)
  • docs: add file to docs folder (file-focused)

Config Schema

yaml
# .claude/skills/commit.yaml (plugin installation)
# .claude/skills/commit/commit.yaml (copied installation)
version: 1
discovered_at: "ISO timestamp"

scopes:
  - name: "scope-name"
    description: "what it covers"
    paths: ["paths/", "that/match/"]

types:
  changelog_worthy: [feat, fix, perf]
  internal: [chore, ci, test, docs, style, refactor, build]

rules:
  max_title_length: 50
  require_scope: false
  require_body: false
  forbidden_words: []