Stylish conventional commits. Offline-first. AI-optional.
Stage your files, run one command, get a commit message that looks like you meant it.
有品味的 Conventional Commits。离线优先,AI 可选。
暂存改动,一条命令,写出像你认真写过的提交信息。
Companion spirit to diff-vibe: commits here, pull requests there.
Pair walkthrough (EN/中文), helper script, and CI sample: examples/pair-workflow.md · examples/commit-msg.sh · examples/github-actions.yml (ship in the npm tarball).
与 diff-vibe 成对:这边写 commit,那边写 PR。
成对流程与可复制脚本见 examples/(随 npm 包发布)。
npm i -g @webywz/vibe-commit
npx @webywz/vibe-commitRequires Node.js 18.18+ and git. Package: @webywz/vibe-commit. Binary: vibe-commit.
需要 Node.js 18.18+ 与 git。包名 @webywz/vibe-commit,命令仍是 vibe-commit。
git add -p
vibe-commit # propose from staged diff
vibe-commit --vibe playful --commit # write the commit
vibe-commit --breaking --dry-run # force ! + BREAKING CHANGE footer
vibe-commit --dry-run # print only (default; wins over --commit)
vibe-commit --github --quiet --no-ai # Actions annotations (CI)
vibe-commit --fail-above 70 --github --quiet --no-ai # CI gate: exit 1 if riskScore > 70
vibe-commit --html # self-contained HTML report on stdout (ember)
vibe-commit --html --theme fog # same report, fog palette
vibe-commit --html --theme aurora # polar-night / northern-lights palette
vibe-commit --html report.html --theme midnight # write HTML to file (creates parent dirs)
vibe-commit --list-themes # print HTML theme names (one per line)
vibe-commit --list-themes --json # same names as a JSON array
vibe-commit --out report.txt # write report to file
vibe-commit --json --out data.json # write JSON to file (stdout also prints)
vibe-commit --copy # copy title+body when a clipboard tool is available
vibe-commit --json --copy --quiet # still copies the human message, not the JSON
git commit -m "$(vibe-commit --dry-run)"
vibe-commit init # auto-detect hook manager and install
vibe-commit init --force # force overwrite existing hook/config
vibe-commit install # same auto-detect as init
vibe-commit install --force # overwrite existing hook/config
vibe-commit uninstall --force # remove unmanaged hook/config too| Flag / command | What it does · 作用 |
|---|---|
--commit |
Run git commit with the proposed message · 用生成信息执行提交 |
--dry-run |
Print only; never commit (default) · 只打印,不提交(默认) |
--type <type> |
Force feat / fix / docs / style / refactor / perf / test / build / ci / chore |
--scope <scope> |
Override inferred scope · 覆盖推断出的 scope |
--vibe <style> |
playful | pro | terse (default: pro) |
--locale <locale> |
en | zh (default: en) · 提交信息主题语言 |
--no-ai |
Skip the API even if OPENAI_API_KEY is set · 即使有 Key 也不走 AI |
--no-color |
Disable ANSI colors in human-readable output (also via NO_COLOR env) · 禁用人类可读输出的 ANSI 颜色(也可通过 NO_COLOR 环境变量) |
--breaking |
Force breaking (! + BREAKING CHANGE: footer = subject) · 强制破坏性变更(! + footer 文本即 subject) |
--json |
Machine-readable proposal (propose) or result (init/install/uninstall) · 机器可读提案(propose)或结果(init/install/uninstall) |
--html [path] |
Self-contained HTML report (stdout, or write to path; offline, no CDN). Cannot share stdout with --json · 自包含 HTML 报告(stdout 或写入路径;离线、无 CDN)。不能与 --json 同时占用 stdout |
--theme <name> |
HTML palette only: ember (default, 0.1.27 look), fog, midnight, paper, aurora · 仅 HTML 配色:ember(默认,与 0.1.27 相同)、fog、midnight、paper、aurora |
--list-themes |
Print available HTML theme names (one per line; --json: JSON array). Does not require staged changes · 打印可用 HTML 主题名(每行一个;加 --json 则输出 JSON 数组)。不需要暂存改动 |
--github |
Emit GitHub Actions ::notice / ::warning / ::error annotations; write GITHUB_OUTPUT + GITHUB_STEP_SUMMARY when set · 输出 Actions 注解,并在环境变量存在时写 Job 输出与 Summary |
--quiet |
Suppress the pretty terminal report; --json / --github still emit · 抑制漂亮终端报告 |
--max-annotations <n> |
Cap --github annotation lines (default: 20; invalid → UsageError) · 限制注解条数 |
--out <file> |
Write report (or JSON body with --json) to file (propose only) · 写报告(或搭配 --json 写 JSON)到文件(仅 propose) |
--fail-above <n> |
Propose-only CI gate: after reports emit, exit 1 if riskScore > n (integer 0–100). Omit = off. Compatible with --json / --github / --quiet / --html / --out · 仅 propose:报告输出后再判定,风险分 > n 则以 1 退出(整数 0–100;省略则关闭) |
--copy |
Propose only: copy the conventional commit title + body (same text you would paste into git commit) when pbcopy / wl-copy / xclip / xsel is available. With --json, still copies the human message, not the JSON. No tool → skip silently (exit 0 unless something else fails). Compatible with --quiet / --github / --html / --fail-above · 仅 propose:有剪贴板工具时复制标题+正文(不是 JSON / 漂亮终端装饰);没有则静默跳过 |
init [--path] [--force] [--json] |
Auto-detect hook manager and install (husky → simple-git-hooks → bare .git/hooks) · 自动检测钩子管理器并安装 |
install [--path] [--force] [--json] |
Same auto-detect installer as init · 与 init 相同的自动检测安装 |
uninstall [--path] [--force] [--json] |
Remove the managed hook (all managers); --force also removes unmanaged · 卸载已管理钩子;--force 也移除未管理的 |
--force |
Force overwrite (init/install) or remove unmanaged (uninstall) · 强制覆盖(init/install)或移除未管理钩子(uninstall) |
-h / -v |
Help / version · 帮助 / 版本 |
Offline heuristic also marks breaking when the staged diff removes public exports or bumps a package.json major version, and always attaches a BREAKING CHANGE: footer when breaking is true (so --json body matches the formatted message). Forced --breaking puts the subject in the footer; heuristic breaking still prefers a more specific bilingual reason when one is available. Dry-run prints a one-line cause; --json may include breakingReason.
离线启发式在删掉公开 export、或 package.json 主版本升级时也会标 breaking;只要 breaking 为真就会补上 BREAKING CHANGE: footer(--json 的 body 与格式化输出一致)。强制 --breaking 时 footer 文本即 subject;启发式推断 breaking 时仍可用更具体的双语原因。干跑会打一行原因;--json 可带 breakingReason。
git add -p
npx --yes @webywz/vibe-commit --commit
npx --yes @webywz/diff-vibe@^0.1.8 --base main --createCommits here · PRs there. Full walkthrough (EN/中文), commit-msg.sh, and Actions sample live in examples/. Companion-side snippets: diff-vibe examples.
这边写 commit,那边写 PR。完整成对流程与脚本见 examples/。成对仓库示例:diff-vibe examples。
Vibes · 语气
- pro — default. Imperative, review-ready. · 默认:祈使句,可进 review。
- terse — headline only, filler gone. · 只留标题,去掉废话。
- playful — a little personality, still safe for a real repo. · 带一点性格,但仍适合正经仓库。
$ vibe-commit
vibe-commit · heuristic · feat
1 file · +124 −8
proposed
feat(heuristic): infer conventional commit type from staged diffs
next vibe-commit --commit
vibe-commit init # auto-detect and install
vibe-commit init --force # overwrite existing hook/config
vibe-commit init --json # machine-readable output
vibe-commit init --path ~/projects/app
vibe-commit install # same auto-detect as init
vibe-commit install --force # overwrite existing hook/config
vibe-commit install --json # machine-readable output
vibe-commit install --path ~/projects/app
vibe-commit uninstall
vibe-commit uninstall --force # also remove unmanaged hook/config
vibe-commit uninstall --json # machine-readable outputWith --json, init, install, and uninstall print only JSON to stdout:
init --json:
{
"manager": "husky",
"targetPath": "/path/to/.husky/prepare-commit-msg",
"created": true,
"updated": false,
"backedUp": false
}install --json:
{
"ok": true,
"action": "installed",
"manager": "bare",
"path": "/path/to/.git/hooks/prepare-commit-msg",
"hookPath": "/path/to/.git/hooks/prepare-commit-msg",
"created": true,
"updated": false,
"backedUp": false
}uninstall --json:
{
"ok": true,
"action": "removed",
"manager": "bare",
"path": "/path/to/.git/hooks/prepare-commit-msg",
"hookPath": "/path/to/.git/hooks/prepare-commit-msg",
"removed": true,
"restored": false
}On error with --json, the output is { "ok": false, "error": "..." } on stderr with non-zero exit.
init auto-detects your hook manager in this order:
- husky — if
package.jsonhas ahuskydependency or.husky/directory exists- Writes
.husky/prepare-commit-msg
- Writes
- simple-git-hooks — if
package.jsonhassimple-git-hooksdependency or config- Sets
simple-git-hooks.prepare-commit-msginpackage.json - After
init, runnpx simple-git-hooksto install
- Sets
- bare .git/hooks — fallback
- Writes
.git/hooks/prepare-commit-msgdirectly
- Writes
init 自动检测钩子管理器,顺序如下:
- husky —
package.json有husky依赖或存在.husky/目录- 写入
.husky/prepare-commit-msg
- 写入
- simple-git-hooks —
package.json有simple-git-hooks依赖或配置- 在
package.json中设置simple-git-hooks.prepare-commit-msg init后需运行npx simple-git-hooks来安装
- 在
- bare .git/hooks — 兜底
- 直接写入
.git/hooks/prepare-commit-msg
- 直接写入
After init or install, plain git commit (no -m) fills an empty or comment-only message file with a conventional proposal.
init 或 install 后,裸 git commit(没有 -m)会在空 / 仅注释的提交说明里填入提案。
| Situation · 情况 | Behavior · 行为 |
|---|---|
Source is merge, squash, or commit (amend) |
Leave the message alone · 不改 |
Message already has non-comment text (e.g. git commit -m) |
Never overwrite · 绝不覆盖 |
| No staged changes / generator error | Exit 0 — never break the commit · 以 0 退出,不打断提交 |
| Hook/config already exists (not managed) | init / install refuse without --force · init / install 拒绝(除非 --force) |
Conflict behavior · 冲突行为
- If
initorinstallfinds a hook or config entry that already exists and is not managed by vibe-commit (no# BEGIN VIBE-COMMITmarkers or a different simple-git-hooks command), it refuses with exit 1 and shows a bilingual error unless--forceis passed. - With
--force, existing file hooks (husky / bare) are backed up asprepare-commit-msg.vibe-backupand chained after ours. simple-git-hooks config is overwritten in place (no file backup). - Managed blocks (already installed by vibe-commit) are updated in place without
--force. uninstallremoves managed hooks for the detected manager. Unmanaged hooks stay unless--forceis passed (file hooks: restore backup if present, else delete; simple-git-hooks: drop the config entry).
如果 init 或 install 发现已有钩子或配置且不由 vibe-commit 管理(没有 # BEGIN VIBE-COMMIT 标记或不同的 simple-git-hooks 命令),会以退出码 1 拒绝并显示双语错误信息,除非传递了 --force。
使用 --force 时,husky / bare 的现有钩子会备份为 prepare-commit-msg.vibe-backup 并链式调用;simple-git-hooks 配置就地覆盖(无文件备份)。
已管理的代码块(已由 vibe-commit 安装)会就地更新,无需 --force。
uninstall 按检测到的管理器移除已管理钩子;未管理的钩子仅在 --force 时移除(有备份则恢复,否则删除)。
Hook stays offline by default (VIBE_COMMIT_HOOK_AI=1 to allow AI). Unique markers (# BEGIN VIBE-COMMIT … # END VIBE-COMMIT) keep uninstall clean. A foreign prepare-commit-msg is backed up to prepare-commit-msg.vibe-backup and chained after ours.
钩子默认离线;设 VIBE_COMMIT_HOOK_AI=1 才允许 AI。用标记块保证干净卸载。已有外来钩子会备份并链式调用。
vibe-commit supports English (en, default) and Chinese (zh) commit subjects:
vibe-commit 支持英文(en,默认)和中文(zh)提交信息主题:
vibe-commit --locale zh --dry-run # Chinese subject: 添加/修复/更新...
vibe-commit --locale en --dry-run # English subject: add/fix/update...Configuration precedence · 配置优先级:
- CLI flag
--locale - Environment variable
VIBE_COMMIT_LOCALE - Project config (
.vibe-commit.jsonorpackage.json#vibeCommit) - Default
en
// .vibe-commit.json
{
"locale": "zh",
"vibe": "pro"
}// package.json
{
"vibeCommit": {
"locale": "zh",
"vibe": "terse"
}
}Both heuristic and AI engines respect the locale setting. The --json output includes a locale field. Propose --json also includes riskScore (0–100).
启发式引擎和 AI 引擎都会遵循 locale 设置。--json 输出包含 locale 字段。
export OPENAI_API_KEY=sk-...
export OPENAI_MODEL=gpt-4o-mini # optional
export OPENAI_BASE_URL=https://api.openai.com/v1
export VIBE_COMMIT_VIBE=pro # or VIBE
export VIBE_COMMIT_LOCALE=zh # or en (default)
export NO_COLOR=1 # disable ANSI colors (any non-empty value)OpenAI-compatible Chat Completions. Missing key, timeout, or 4xx/5xx → silent fallback to the offline heuristic. See .env.example. Unstaged files are never sent; huge diffs are truncated.
兼容 OpenAI Chat Completions。没 Key、超时或 4xx/5xx → 静默回退离线启发式。可参考 .env.example。不会上传未暂存文件;过大 diff 会截断。
Set NO_COLOR (any non-empty value) or use --no-color to disable ANSI colors in human-readable output. --json output is always plain JSON.
设置 NO_COLOR(任意非空值)或使用 --no-color 禁用人类可读输出的 ANSI 颜色。--json 输出始终为纯 JSON。
import { proposeHeuristic, formatCommit } from "@webywz/vibe-commit";
const message = proposeHeuristic({ diff, vibe: "pro" });
console.log(formatCommit(message));
// feat(auth): add login- Reads staged changes only (
git diff --cached). Unstaged noise is ignored. 只读 已暂存 改动;忽略未暂存噪音。 - Offline heuristic always on: paths + hunk keywords + added identifiers →
type,scope,subject. 离线启发式始终开启:路径 + hunk 关键词 + 新增标识 →type/scope/subject。README/docs/→docs*.test.ts/test/→test.github/workflows→ci- lockfiles /
package.json→chore fix/bug/crashin the diff →fix- new files /
export function→feat
- Optional AI draft with automatic heuristic fallback. 可选 AI 草稿,失败自动回退启发式。
- Breaking when the diff removes a public
export, bumps apackage.jsonmajor, already has aBREAKING CHANGE:footer, or you pass--breaking. Forced--breakingputs the subject in the footer; heuristic cases keep a more specific bilingual reason when available. Dry-run shows why;--jsonmay includebreakingReason. 破坏性变更:删公开export、主版本升级、diff 里已有 footer,或传--breaking。强制--breaking时 footer 用 subject;启发式仍可用更具体的双语原因。干跑说明原因;--json可带breakingReason。 - Managed
prepare-commit-msghook viainstall/uninstall. 通过install/uninstall管理prepare-commit-msg钩子。 - GitHub Actions mode:
--githubemits Checks annotations; optional--quiet/--max-annotations; writes job outputs + step summary whenGITHUB_OUTPUT/GITHUB_STEP_SUMMARYare set. Optional--fail-above <n>exits 1 after those outputs whenriskScore> n (breaking= 100,fix= 70,feat/perf/refactor= 45, other types = 15). Seeexamples/github-actions.yml. GitHub Actions 模式:--github输出 Checks 注解;可选--quiet/--max-annotations;环境变量存在时写 Job 输出与 Summary。可选--fail-above <n>在输出之后若riskScore> n 则以 1 退出(breaking= 100,fix= 70,feat/perf/refactor= 45,其余类型 = 15)。示例见examples/github-actions.yml。 - HTML report:
--html [path]writes a self-contained offline page (proposed message, vibe/heuristic signals, file summary, confidence / tips). No CDN, no external CSS/JS/fonts. Omit path → stdout; give a path → write the file (parent dirs created).--theme <name>swaps CSS-variable palettes (emberdefault = 0.1.27 look, plusfog,midnight,paper,aurora); it does not change JSON, pretty, GitHub annotations,--fail-above,--locale, or scoring.--list-themesprints those names (one per line;--list-themes --jsonis a JSON array) without requiring staged changes. Mutually exclusive with--json. Combined with--githubon stdout, annotations go to stderr so the HTML stays parseable. HTML 报告:--html [path]写出离线自包含页面(提案、vibe/启发式信号、文件摘要、把握 / 提示)。无 CDN、无外部 CSS/JS/字体。省略路径 → stdout;给出路径 → 写文件(自动创建父目录)。--theme <name>只换 CSS 变量配色(默认ember与 0.1.27 相同,另有fog/midnight/paper/aurora);不影响 JSON、终端漂亮输出、GitHub 注解、--fail-above、--locale或打分。--list-themes打印这些主题名(每行一个;--list-themes --json为 JSON 数组),不需要暂存改动。与--json互斥。与--github联用且 HTML 走 stdout 时,注解改走 stderr,保持 HTML 可解析。
- npm ·
@webywz/vibe-commit - Source · github.com/webywz/vibe-commit
- Related · diff-vibe · prompt-diff
- Pair workflow · examples/pair-workflow.md
- GitHub Actions · examples/github-actions.yml
- License · MIT
npm install && npm test && npm run build
node dist/cli.js --help