smart-git-review
v1.0.7
Published
基于 Git Hooks 和 AI 大模型的自动化代码审查工具。支持 commit/push/pull 时自动审查,可植入质量规范到 Claude Code / Kilo Code / Cline 等 AI 编码工具。
Maintainers
Readme
smart-git-review
基于 Git Hooks 和 AI 大模型的自动化代码审查工具。
安装
npm install smart-git-review --save-dev快速开始
# 1. 安装 Hooks
npx git-ai-review install
# 2. 正常使用 git (commit/push 时自动触发审查)
git commit -m "feat: 新功能"审查触发时机
| Hook | 触发时机 | 默认 | 配置项 |
|------|----------|------|--------|
| pre-commit | git commit 前 | ✅ 开启 | reviewOnCommit |
| pre-push | git push 前 | ❌ 关闭 | reviewOnPush |
| post-merge | git pull 后 | ❌ 关闭 | reviewOnPull |
预设规则库
开箱即用的审查规则,涵盖安全、性能、架构、代码质量等维度:
内置规则
| 规则 ID | 描述 | 适用场景 |
|---------|------|----------|
| security | 核心目标:基于 git diff 中的新增和修改行 (+ lines),狙击潜在的安全隐患。 | 所有项目 |
| architecture | 核心目标:基于变更代码,识别设计缺陷、架构腐化、安全韧性与性能风险。 | 所有项目 |
| react-typescript | 核心目标:预防运行时崩溃和性能灾难。 | 所有项目 |
| vue-typescript | 核心目标:预防响应式陷阱、组件通信混乱和性能问题。 | 所有项目 |
| vibe-coding | 核心目标:针对 AI/LM 生成代码特有毒点的精准识别。 | 所有项目 |
| database | 数据库与 ORM 性能审查 | 所有项目 |
| performance | 核心目标:识别代码变更中潜在的性能问题和资源浪费。 | 所有项目 |
| code-smells | 核心目标:识别影响可维护性、可读性、安全性和性能的代码坏味道。 | 所有项目 |
| business-design | 核心目标:检测代码变更中的业务逻辑缺陷,包括状态机错误、并发竞态、权限漏洞、一致性缺失、异步/回调/缓存导致的业务风险等 | 所有项目 |
| grill-me | 核心目标:以对抗性思维挑战每一行代码,假设代码有罪直到证明无罪。 | 所有项目 |
| impeccable | 核心目标:追求代码的无瑕品质,从可读性到健壮性的全面质量检查。 | 所有项目 |
| systematic-debugging | 核心目标:用 4 阶段根因分析法审查代码变更,防止「创可贴式修复」。 | 所有项目 |
| caveman-review | 核心目标:代码应该简单到「caveman 也能理解」。消灭不必要的复杂性,同时守住安全、性能和可维护性底线。 | 所有项目 |
来自 skills.sh 生态的规则
| 规则 ID | 描述 | 来源 |
|---------|------|------|
| web-design-guidelines | Review UI code for Web Interface Guidelines compliance. Use | vercel-labs/agent-skills |
| react-best-practices | React and Next.js performance optimization guidelines from V | vercel-labs/agent-skills |
| verification-before-completion | Use when about to claim work is complete, fixed, or passing, | obra/superpowers |
| supabase-postgres-best-practices | Postgres performance optimization and best practices from Su | supabase/agent-skills |
| supabase | Use when doing ANY task involving Supabase. Triggers: Supaba | supabase/agent-skills |
| receiving-code-review | Use when receiving code review feedback, before implementing | obra/superpowers |
| test-driven-development | Use when implementing any feature or bugfix, before writing | obra/superpowers |
| webapp-testing | Toolkit for interacting with and testing local web applicati | anthropics/skills |
| code-review | Review the changes since a fixed point (commit, branch, tag, | mattpocock/skills |
| resolving-merge-conflicts | Use when you need to resolve an in-progress git merge/rebase | mattpocock/skills |
| improve-codebase-architecture | Scan a codebase for deepening opportunities, present them as | mattpocock/skills |
| diagnosing-bugs | Diagnosis loop for hard bugs and performance regressions. Us | mattpocock/skills |
| setup-pre-commit | Set up Husky pre-commit hooks with lint-staged (Prettier), t | mattpocock/skills |
规则管理
# 列出所有可用规则
npx git-ai-review rules
# 启用规则
npx git-ai-review enable security
npx git-ai-review enable grill-me
# 禁用规则
npx git-ai-review disable vibe-coding配置
在项目根目录创建 .gitaireviewrc.json:
{
"model": "qwen3.6-plus",
"apiUrl": "https://coding.dashscope.aliyuncs.com/v1/chat/completions",
"blockOnCritical": true,
"reviewOnCommit": true,
"reviewOnPush": false,
"reviewOnPull": true,
"presetRules": ["security", "react-typescript", "vibe-coding", "grill-me"]
}环境变量
| 变量名 | 说明 | 默认值 |
|--------|------|--------|
| GIT_AI_REVIEW_API_KEY | API 密钥 | - |
| GIT_AI_REVIEW_MODEL | AI 模型 | qwen3.6-plus |
| GIT_AI_REVIEW_API_URL | API 地址 | 阿里云 DashScope |
规则植入
将质量规范植入到 AI 编码工具(Claude Code / Kilo Code / Cline):
# 自动检测并植入
npx git-ai-review inject
# 指定工具和规则
npx git-ai-review inject --tool claude --rules security,performance许可证
MIT
