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

ai-code-review-toolkit

v0.0.3

Published

AI-powered git code review toolkit with optional local RAG knowledge base

Readme

AI 代码审查 English Md

基于人工智能的git pre-commit钩子,提供自动化代码审查功能,支持自定义规则。

功能特性

  • 🤖 多模型支持: 支持OpenAI、Deepseek、Ollama和LM Studio
  • 🔍 智能差异分析: 聚焦有意义的变更,忽略删除内容
  • ⚙️ 可定制规则: 安全检查、性能优化、代码风格
  • ✏️ 自定义提示: 完全自定义审查标准和提示词
  • 📊 分级反馈: 高/中/低严重性分类
  • 🛠 简单集成: 通过npm安装和配置

安装

npm install --save-dev ai-code-review-toolkit
# 或
yarn add -D ai-code-review-toolkit

添加到git pre-commit钩子:

npx ai-review install

检查 / 卸载 / 强制重装:

npx ai-review check
npx ai-review uninstall
npx ai-review install --force

如果已安装husky:

npx ai-review install

支持 Yarn PnP:如果仓库根目录存在.pnp.cjs,已安装的 hook 会优先通过 yarn ai-review run 执行(若可用则回退到 corepack yarn)。

旧方式(由 husky 命令执行):

.package.json
{
  "husky": {
    "hooks": {
      "pre-commit": "npx ai-review run"
    }
  }
}

配置

方式1: package.json

"aiCheckConfig": {
  "providerType": "openai",
  "apiKey": "your-api-key",
  "model": "gpt-4",
  "baseURL": "https://api.openai.com",
  "timeoutMs": 120000,
  "concurrency": 2,
  "maxRetries": 1,
  "retryDelayMs": 500,
  "diffContextLines": 3,
  "maxChunkSize": 4000,
  "language": "english",
  "ignoreDeletions": true,
  "stripUnchangedCommentLines": true,
  "checkSecurity": true,
  "checkPerformance": true,
  "checkStyle": false,
  "enabledFileExtensions": ".html, .js, .jsx, .ts, .tsx, .vue"
}

方式2: .env文件

providerType=openai
baseURL=http://localhost:11434
model=gpt-4
maxChunkSize=4000
language=chinese

如果同时存在package.jsonaiCheckConfig)和.env,将合并配置,并以.env优先。

环境变量(process.env)优先级最高,会覆盖 .envpackage.json

为避免与系统常见环境变量冲突(例如 LANGUAGE),本工具只会读取:

  • 与配置项完全同名(区分大小写)的 env,例如 providerTypebaseURLapiKey
  • 或带前缀(推荐)的 env:AI_REVIEW_* / AI_CODE_REVIEW_KIT_*,例如 AI_REVIEW_PROVIDER_TYPEAI_REVIEW_BASE_URLAI_REVIEW_API_KEY

关于 baseURL / embeddingsBaseURL

  • 建议填写 API 根路径,例如 https://example.comhttps://example.com/v1
  • 避免填写完整 endpoint,例如 .../v1/responses / .../v1/chat/completions(工具会尝试自动归一化,但根路径更稳定)

项目知识库(本地 RAG)

支持基于 LanceDB 的本地项目级 RAG:先离线构建索引,review 时针对当前 diff chunk 做向量检索,把相关片段注入到 prompt 中增强审查。

构建索引(手动触发):

npx ai-review index

最小配置示例(写入 aiCheckConfig):

{
  "enableRag": true,
  "knowledgeBasePaths": ["."],
  "knowledgeBaseIndexDir": ".ai-reviewer-cache/lancedb",
  "knowledgeBaseTable": "project_kb",
  "ragTopK": 6,
  "ragMaxChars": 8000,
  "embeddingsBaseURL": "https://api.openai.com",
  "embeddingsModel": "text-embedding-3-small"
}

说明:

  • 缓存目录:.ai-reviewer-cache/(建议加入 gitignore,不提交)
  • LanceDB 默认会保留历史版本。本工具会在每次 ai-review index 后自动清理旧版本,避免缓存无限增长;你也可以随时安全删除 .ai-reviewer-cache/ 并重新构建。
  • 若索引不存在,会提示你执行 ai-review index,并自动降级为普通 review(不会阻断)
  • embeddings 配置优先级:优先使用 embeddingsBaseURL/embeddingsApiKey/embeddingsModel,否则回退到 baseURL/apiKey(需兼容 OpenAI embeddings 接口)

完整配置选项

| 参数 | 类型 | 默认值 | 描述 | |-----------|------|---------|-------------| | providerType | string | "openai" | AI提供商类型(openai、deepseek、zhipu、ollama或LMStudio) | | apiKey | string | - | 提供商API密钥(Ollama和LM Studio不需要) | | model | string | "gpt-3.5-turbo" | 模型名称 | | temperature | number | 0.2 | 控制AI输出的随机性(值越高越随机) | | baseURL | string | "https://api.openai.com" (OpenAI)"https://api.deepseek.com" (Deepseek)"https://open.bigmodel.cn/api/paas/v4" (智谱)"http://localhost:11434" (Ollama)"http://127.0.0.1:1234" (LM Studio)| API基础URL(可包含或省略/v1后缀) | | useResponsesApi | boolean | false | 强制对 OpenAI 兼容提供商使用 Responses API(/responses) | | timeoutMs | number | 120000 | 请求超时时间(毫秒) | | concurrency | number | 2 | 最大并行AI请求数 | | maxRetries | number | 1 | 调用失败/格式错误时的重试次数 | | retryDelayMs | number | 500 | 重试基础延迟(毫秒),指数退避 | | diffContextLines | number | 3 | git diff --unified上下文行数 | | maxChunkSize | number | 12000 | 最大差异块大小(字符数) | | customPrompts | string | '' |自定义提示模板。当提供时,将完全替换默认的安全(checkSecurity)、性能(checkPerformance)和风格(checkStyle)检查。 | | language | string | "chinese" | 输出语言 | | strict | boolean | true | 调用API时如果发生错误导致pre-commit结果不通过 | | skipReview | boolean | false | 跳过 AI 审查(直接通过) | | correctedResult | boolean | true | 当AI返回结果中的result字段与列表中特定检测项结果不匹配时,系统会根据实际检测问题自动修正最终判定结果。 | | showNormal | boolean | false | 显示低/中严重性问题 | | ignoreDeletions | boolean | true | 发送给AI前移除删除行(-...) | | stripUnchangedCommentLines | boolean | true | 移除未变更的纯注释上下文行(例如 // ...) | | checkSecurity | boolean | true | 启用安全检查 | | checkPerformance | boolean | true | 启用性能检查 | | checkStyle | boolean | false | 启用风格检查 | | enabledFileExtensions | string | '.html, .js, .jsx, .ts, .tsx, .vue' | 需要审查的文件类型 | | enableRag | boolean | false | 开启本地 RAG 知识检索增强 | | knowledgeBasePaths | string|string[] | '' | 需要索引的路径(例如 ["."] 或 "src,docs") | | knowledgeBaseIndexDir | string | '.ai-reviewer-cache/lancedb' | LanceDB 索引目录(相对仓库根目录) | | knowledgeBaseTable | string | 'project_kb' | LanceDB 表名 | | ragTopK | number | 6 | 检索 Top K 片段 | | ragMaxChars | number | 8000 | 注入 prompt 的最大字符数 | | embeddingsProviderType | string | '' | embeddings 提供商类型(默认跟随 providerType) | | embeddingsBaseURL | string | '' | embeddings baseURL(不填则使用提供商默认值) | | embeddingsApiKey | string | '' | embeddings 接口的 API key | | embeddingsModel | string | 提供商默认 | embeddings 模型(OpenAI: text-embedding-3-small,智谱: embedding-3) | | embeddingsDimensions | number | null | embeddings 输出维度(可选,需模型/服务端支持) |

审查流程

  1. 差异提取: 通过git diff --cached获取暂存变更
  2. 文件过滤: 仅处理指定扩展名的文件
  3. 分块处理: 将大差异分割为可管理的块
  4. AI分析: 将块发送到配置的AI提供商
  5. 结果聚合: 合并所有块的结果
  6. 输出: 按严重性分组显示问题

示例输出

Find 1 changed files...
Running code review with AI: The content will be reviewed in 1 sessions for better accuracy.

X Code review was not passed.Please fix the following high-level issues and try again.
- src/auth.js: [高] - 安全问题 - 硬编码的API密钥
  Suggested fix: 使用环境变量存储敏感信息
- src/db.js: [中] - 性能问题 - 缺少数据库连接池
  Suggested fix: 实现连接池减少连接开销

√ Code review passed.

支持的提供商

OpenAI

  • 必填: apiKey
  • 可选: model (默认: gpt-3.5-turbo), baseURL (默认: https://api.openai.com)
  • 模型: gpt-4, gpt-3.5-turbo

Deepseek

  • 必填: apiKey
  • 可选: model (默认: deepseek-chat), baseURL (默认: https://api.deepseek.com)
  • 模型: deepseek-chat、deepseek-reasoner

智谱(BigModel)

  • 必填: apiKey
  • 可选: model(默认: glm-4), baseURL(默认: https://open.bigmodel.cn/api/paas/v4)
  • embeddings:建议设置 embeddingsProviderType: "zhipu"embeddingsModel: "embedding-3"(可选 embeddingsDimensions

Ollama (本地AI模型)

  • 必填: 无(本地运行)
  • 可选: model (默认: gpt-3.5-turbo), baseURL (默认: http://localhost:11434)
  • 设置:
    1. 安装Ollama: https://ollama.ai/
    2. 下载模型: ollama pull <模型名称>
    3. 常用模型: llama2, codellama, mistral
  • 示例.env配置:
    providerType=ollama
    model=codellama
    baseURL=http://localhost:11434

LMStudio (本地AI模型)

  • 必填: 无(本地运行)
  • 可选: model (默认: qwen/qwq-32b), baseURL (默认: http://127.0.0.1:1234)

故障排除

钩子未运行

  • 检查.git/hooks/pre-commit是否存在且可执行
  • 确认文件包含node path/to/ai-review.js

API错误

  • 验证API密钥和基础URL(Ollama不需要)
  • 检查网络连接
  • 设置strict: false允许API错误时提交

未发现变更

  • 检查enabledFileExtensions是否匹配您的文件类型
  • 确认变更已暂存(git add)

The returned data format does not conform to the specification

模型未能生成有效的JSON输出,表明其遵循指令的能力可能有限。请确保模型能够生成结构化数据。

许可证

ISC