npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zhuxb-clouds/ai-code-review

v1.4.1

Published

基于 OpenAI API 的 Git Hooks 集成方案,自动代码审查并生成 Conventional Commits 提交信息

Readme

AI Code Reviewer & Commit Generator

English | [简体中文]

基于 Node.js 和 OpenAI-compatible API 的 Git Hooks 集成方案。在执行 git commit 时自动进行代码审查,并根据 Diff 自动生成符合 Conventional Commits 规范的提交信息。

支持的 AI 提供商: OpenAI, DeepSeek, Gemini

🚀 核心特性

  • 自动化审查:在代码提交前拦截潜在 Bug 或不规范实践
  • 语义化提交:自动撰写符合 Conventional Commits 规范的提交信息
  • 无感集成:通过 Git Hooks 实现,无需改变原有开发习惯
  • 成本可控:支持 Diff 大小限制,避免 Token 浪费
  • 一键安装:作为 npm 包安装到任何项目
  • 多提供商支持:支持 OpenAI、DeepSeek、Gemini 等
  • 代理支持:支持 HTTP/HTTPS/SOCKS5 代理

🛠️ 技术架构

git commit → Husky (prepare-commit-msg) → ai-review-hook → AI API (OpenAI/DeepSeek/Gemini)
                                                 ↓
                                    ✅ 通过:自动填充 Commit Message
                                    ❌ 失败:拦截提交并输出建议

📦 快速开始

1. 安装到你的项目

# 安装为开发依赖
npm install ai-code-review -D

# 初始化(自动安装 Husky 并配置 Git Hook)
npx ai-review init

2. 配置环境变量

复制生成的 .env.example.env 并填入你的 API Key:

cp .env.example .env

使用 OpenAI

AI_PROVIDER=openai
OPENAI_API_KEY=sk-your-openai-key-here
OPENAI_MODEL=gpt-4o-mini

使用 DeepSeek

AI_PROVIDER=deepseek
DEEPSEEK_API_KEY=sk-your-deepseek-key-here
# OPENAI_MODEL=deepseek-chat  # 可选,默认 deepseek-chat

使用 Gemini

AI_PROVIDER=gemini
GEMINI_API_KEY=your-gemini-api-key-here
# OPENAI_MODEL=gemini-2.5-flash  # 可选,默认 gemini-2.5-flash

使用代理

HTTPS_PROXY=http://127.0.0.1:7890

⚠️ 安全提示.env 已自动添加到 .gitignore,请勿手动提交!

3. 开始使用

# 正常开发并暂存更改
git add .

# 发起提交(推荐不带 -m,让 AI 生成)
git commit

# AI 会自动审查并生成提交信息
# 🔍 正在进行 AI 代码审查...
# ✅ AI Review 通过
# 📝 生成的提交信息: feat(auth): add JWT token validation

📂 安装后的目录结构

your-project/
├── .husky/
│   └── prepare-commit-msg     # Git Hook(自动创建)
├── .env                       # API Key(自己创建,不要提交!)
├── .env.example               # 配置示例(自动创建)
├── .reviewignore              # AI 审查忽略文件(可选)
├── .reviewignore.example      # 忽略规则示例(自动创建)
├── .gitignore                 # 已包含 .env
└── package.json               # 包含 ai-code-review 依赖

🚫 文件忽略配置 (.reviewignore)

创建 .reviewignore 文件来跳过某些文件的 AI 审查,语法类似 .gitignore

# 复制示例文件
cp .reviewignore.example .reviewignore

支持的语法

# 注释
# 这是一个注释

# 通配符
package-lock.json   # 匹配特定文件
*.min.js            # * 匹配任意字符(不包括 /)
dist/               # 匹配整个目录
**/*.snap           # ** 匹配任意路径层级

# 否定模式
*.md                # 忽略所有 markdown
!README.md          # 但不忽略 README.md

常见配置示例

# 锁文件
package-lock.json
pnpm-lock.yaml
yarn.lock

# 生成的文件
*.min.js
*.bundle.js
dist/
build/

# 文档和资源
*.md
*.svg
*.png

# 测试快照
__snapshots__/
*.snap

⌨️ CLI 命令

# 完整初始化(安装 Husky + 配置 Hook)
npx ai-review init

# 仅配置 Hook(如果 Husky 已安装)
npx ai-review setup

# 显示帮助
npx ai-review help

跳过 AI Review

# 使用 -m 参数时自动跳过 AI 生成(直接使用你的消息)
git commit -m "feat: your message"

# merge/squash/amend 提交也会自动跳过
git merge feature-branch
git commit --amend

⚙️ 配置选项

通过环境变量配置:

基础配置

| 环境变量 | 默认值 | 说明 | | ------------------ | -------- | ---------------------------------------------------------------------------------------------- | | AI_PROVIDER | openai | AI 提供商:openaideepseekgemini | | OPENAI_API_KEY | - | OpenAI API Key(使用 OpenAI 时必填) | | DEEPSEEK_API_KEY | - | DeepSeek API Key(使用 DeepSeek 时必填) | | GEMINI_API_KEY | - | Gemini API Key(使用 Gemini 时必填) | | OPENAI_BASE_URL | 自动设置 | 自定义 API 地址(可覆盖默认) | | OPENAI_MODEL | 自动设置 | 模型名称(OpenAI 默认 gpt-4o-mini,DeepSeek 默认 deepseek-chat,Gemini 默认 gemini-2.5-flash) |

网络配置

| 环境变量 | 默认值 | 说明 | | ------------- | ------ | -------------------------- | | HTTPS_PROXY | - | HTTP/HTTPS/SOCKS5 代理地址 | | HTTP_PROXY | - | 同上,备选 |

行为配置

| 环境变量 | 默认值 | 说明 | | ------------------------- | --------------- | -------------------------- | | AI_REVIEW_MAX_DIFF_SIZE | 15000 | 最大 Diff 字符数,超出截断 | | AI_REVIEW_TIMEOUT | 30000 | API 请求超时时间(毫秒) | | AI_REVIEW_MAX_RETRIES | 3 | 失败时最大重试次数 | | AI_REVIEW_RETRY_DELAY | 1000 | 重试间隔时间(毫秒) | | AI_REVIEW_VERBOSE | false | 启用详细日志 | | AI_REVIEW_SKIP_BUILD | false | 跳过构建检查 | | AI_REVIEW_BUILD_COMMAND | npm run build | 构建命令 |


📄 License

MIT