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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ai-reviewer-bedrock

v1.0.0

Published

AI-powered git pre-commit hook for automated code review

Readme

AI 代码审查 English

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

功能特性

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

安装

npm install --save-dev ai-pre-commit-reviewer

添加到git pre-commit钩子:

npx add-ai-review

如果已安装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/v1",
  "maxChunkSize": 4000,
  "language": "chinese",
  "checkSecurity": true,
  "checkPerformance": true,
  "checkStyle": true,
  "enabledFileExtensions": ".html, .js, .jsx, .ts, .tsx, .vue"
}

方式2: .env文件

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

完整配置选项

| 参数 | 类型 | 默认值 | 描述 | |-----------|------|---------|-------------| | providerType | string | "openai" | AI提供商类型(openai、deepseek或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)"http://localhost:11434" (Ollama)"http://127.0.0.1:1234" (LM Studio)| API基础URL | | maxChunkSize | number | 12000 | 最大差异块大小(字符数) | | customPrompts | string | '' | 自定义提示模板。当提供时,将完全替换默认的安全(checkSecurity)、性能(checkPerformance)和风格(checkStyle)检查。 | | customPromptsPath | string | '' | 自定义提示词文件路径(.js或.json)。自定义提示词将与默认提示词合并。 | | customPromptsConfig | object | '' | 自定义提示词配置对象。将与默认提示词合并。 | | language | string | "chinese" | 输出语言 | | strict | boolean | true | 调用API时如果发生错误导致pre-commit结果不通过 | | correctedResult | boolean | true | 当AI返回结果中的result字段与列表中特定检测项结果不匹配时,系统会根据实际检测问题自动修正最终判定结果。 | | showNormal | boolean | false | 显示低/中严重性问题 | | checkSecurity | boolean | true | 启用安全检查(XSS、CSRF、CORS等) | | checkPerformance | boolean | true | 启用性能检查(内存泄露、重复监听、高频逻辑优化等) | | checkStyle | boolean | true | 启用代码风格检查(命名规范、类型声明、控制流、UI组件命名等) | | enabledFileExtensions | string | '.html, .js, .jsx, .ts, .tsx, .vue' | 需要审查的文件类型 |

审查流程

  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

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)

Claude (AWS Bedrock)

  • 必填: AWS SSO 登录 (aws sso login --profile your-profile)
  • 可选: model (默认: us.anthropic.claude-sonnet-4-5-20250929-v1:0), awsRegion (默认: us-east-1), awsProfile
  • 模型: us.anthropic.claude-sonnet-4-5-20250929-v1:0, us.anthropic.claude-opus-4-1-20250805-v1:0, us.anthropic.claude-haiku-4-5-20251001-v1:0
  • 示例配置:
    {
      "aiCheckConfig": {
        "providerType": "claude",
        "model": "us.anthropic.claude-sonnet-4-5-20250929-v1:0",
        "awsRegion": "us-east-1",
        "awsProfile": "wepie-claude"
      }
    }

自定义提示词

可以通过三种方式自定义提示词:

方式1: 自定义提示词文件(推荐)

在项目根目录创建 custom-prompts.jscustom-prompts.json 文件:

custom-prompts.js:

export default {
  system: `额外的系统上下文...`,
  rules: {
    general: {
      checks: [
        "你的自定义检查项"
      ]
    }
  }
}

custom-prompts.json:

{
  "rules": {
    "general": {
      "checks": ["你的自定义检查项"]
    }
  }
}

然后在 package.json 中配置:

{
  "aiCheckConfig": {
    "customPromptsPath": "./custom-prompts.js"
  }
}

方式2: 配置对象

直接在 package.json 中配置:

{
  "aiCheckConfig": {
    "customPromptsConfig": {
      "rules": {
        "general": {
          "checks": ["你的自定义检查项"]
        }
      }
    }
  }
}

注意: 自定义提示词会与默认提示词合并,而不是替换。数组会合并,字符串会追加。

故障排除

钩子未运行

  • 检查.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