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

@ttjl/ai-code-review

v1.0.1

Published

AI 驱动的代码审查工具 - 基于 Git Hooks 和阿里百炼 qwen3-max 自动审查前端代码

Readme

AI 驱动的代码审查工具

基于 Git Hooks 和阿里云百炼 qwen-max 的自动化代码审查系统,用于在代码提交前验证代码质量、规范和潜在的安全问题。

✨ 特性

  • 🔍 智能代码审查: 使用阿里云百炼 qwen-max 进行深度代码分析
  • 🚀 自动化集成: 通过 Git Hooks 在提交前自动触发
  • 📝 多文件类型支持: 支持 JavaScript、TypeScript、Vue、CSS 等
  • ⚙️ 灵活配置: 支持自定义审查规则和输出格式
  • 📊 详细报告: 生成控制台彩色输出和 JSON 格式报告
  • 🎯 问题分类: 代码质量、安全、性能、最佳实践等多维度审查

核心技术栈

  • Git Hooks 管理: Lefthook
  • 运行环境: Node.js >= 18.0.0
  • AI SDK: 阿里云百炼 SDK (@alicloud/ai-2024-06-01)
  • AI 模型: qwen-max-latest

📦 安装

全局安装

npm install -g @ttjl/ai-code-review

项目本地安装

npm install -D @ttjl/ai-code-review

🚀 快速开始

1. 配置 API Key

有两种方式配置阿里云百炼 API Key:

方式一: 在配置文件中配置(推荐)

.ai-reviewrc.json 中直接配置:

{
  "ai": {
    "apiKey": "sk-your-api-key-here",
    "model": "qwen-max-latest"
  }
}

方式二: 使用环境变量

创建 .env 文件:

cp .env.example .env

编辑 .env 文件,添加你的阿里云百炼 API Key:

DASHSCOPE_API_KEY=your_dashscope_api_key_here

优先级: 配置文件中的 API Key 优先级高于环境变量。

获取 API Key: https://bailian.console.aliyun.com/

2. 初始化配置

ai-review init

这将创建 .ai-reviewrc.json 配置文件。

3. 检查环境

ai-review check

4. 手动触发审查

ai-review review

⚙️ 配置

.ai-reviewrc.json 配置文件示例:

{
  "review": {
    "enabled": true,
    "onFail": "block",
    "maxFiles": 20
  },
  "files": {
    "include": ["**/*.js", "**/*.ts", "**/*.tsx", "**/*.vue"],
    "exclude": ["node_modules/**", "dist/**"]
  },
  "ai": {
    "apiKey": "sk-your-api-key-here",
    "baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1",
    "model": "qwen-max-latest",
    "temperature": 0.3
  },
  "rules": {
    "codeQuality": true,
    "security": true,
    "bestPractices": true
  }
}

配置说明:

  • ai.apiKey: 阿里云百炼 API Key(可选,不配置则使用环境变量)
  • ai.baseUrl: API 地址(可选,默认为阿里云百炼兼容模式地址)
  • ai.model: 使用的模型名称(默认: qwen-max-latest)
  • ai.temperature: 温度参数,控制输出随机性(0-1)
  • ai.maxTokens: 最大 token 数

📖 使用方法

命令行工具

# 执行代码审查
ai-review review

# 初始化配置文件
ai-review init

# 显示当前配置
ai-review config

# 检查环境配置
ai-review check

Git Hooks 集成

当你暂存文件并执行 git commit 时,代码审查会自动运行:

git add .
git commit  # 自动触发 AI 代码审查

如果发现问题,提交将被阻止(取决于 review.onFail 配置)。

📊 审查报告

控制台输出

============================================================
  代码审查总结
============================================================

  📁 审查文件: 5
  ❌ 错误: 2
  ⚠️  警告: 3
  ℹ️  提示: 1

============================================================

JSON 报告

审查报告会保存在 reports/ 目录下:

{
  "timestamp": "2026-01-02T00:00:00.000Z",
  "summary": {
    "totalFiles": 5,
    "totalIssues": 6,
    "bySeverity": {
      "error": 2,
      "warning": 3,
      "info": 1
    }
  },
  "files": [...],
  "issues": [...]
}

🛠️ 开发

安装依赖

npm install

运行测试

npm test

代码检查

npm run lint

格式化代码

npm run format

📝 项目结构

ai-code-review/
├── src/
│   ├── core/              # 核心逻辑
│   │   ├── ai-client.js       # AI 客户端
│   │   ├── config-loader.js   # 配置加载器
│   │   ├── file-collector.js  # 文件收集器
│   │   └── reviewer.js        # 审查器
│   ├── formatters/        # 输出格式化
│   │   ├── console-formatter.js
│   │   └── json-formatter.js
│   ├── utils/             # 工具函数
│   │   ├── git.js
│   │   └── error-handler.js
│   └── cli/               # 命令行工具
│       └── index.js
├── bin/                    # 可执行命令
├── config/                 # 默认配置
├── templates/              # 配置模板
├── lefthook.yml           # Git Hooks 配置
└── package.json

⚠️ 注意事项

API 配额

阿里云百炼 API 有调用频率限制。如果遇到配额问题,可以考虑:

  1. 减少单次审查的文件数量 (maxFiles)
  2. 增加 API 调用间隔
  3. 查看 阿里云百炼定价页面了解详情

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📄 许可证

MIT License