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

@ysicing/codereview

v1.1.7

Published

Multi-agent code review system powered by Claude Agent SDK

Downloads

172

Readme

Multi-Agent Code Review

基于 Claude Agent SDK 的多智能体代码评审系统,参考 Claude Code 官方 code-review 插件设计。

特性

  • 多代理并行评审 - 安全、性能、质量、Bug 四维度并行检测
  • 两阶段验证 - 检测 + 验证,过滤假阳性
  • 智能文件过滤 - 自动忽略图片、二进制、锁文件等,专注代码评审
  • CLAUDE.md 合规检查 - 自动发现并检查项目规范
  • 多语言支持 - 中英文输出,提示词分离维护
  • GitHub 集成 - 支持直接发布评审到 PR
  • PR 资格检查 - 自动跳过 draft、closed、已审查的 PR
  • 多种输出格式 - Terminal、Markdown、JSON、GitHub Comment

架构

┌─────────────────────────────────────────────────────────────┐
│                    Orchestrator Agent                        │
│              (任务分发、结果聚合、两阶段验证)                   │
└─────────────────────────────────────────────────────────────┘
                            │
        ┌───────────────────┼───────────────────┐
        │                   │                   │
        ▼                   ▼                   ▼
┌─────────────┐  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐
│  Security   │  │ Performance │  │   Quality   │  │    Bug      │
│  Reviewer   │  │  Reviewer   │  │  Reviewer   │  │  Detector   │
│  (Sonnet)   │  │  (Sonnet)   │  │  (Sonnet)   │  │   (Opus)    │
└─────────────┘  └─────────────┘  └─────────────┘  └─────────────┘
        │                   │                   │
        └───────────────────┼───────────────────┘
                            ▼
┌─────────────┐      ┌─────────────────┐
│  CLAUDE.md  │      │ Issue Validator │
│  Reviewer   │─────▶│     (Opus)      │
│  (Sonnet)   │      │  过滤假阳性      │
└─────────────┘      └─────────────────┘

代理职责

| Agent | 职责 | 模型 | |-------|------|------| | security-reviewer | 注入漏洞、认证授权、敏感数据泄露、OWASP Top 10 | Sonnet | | performance-reviewer | N+1 查询、内存泄漏、O(n²) 算法、阻塞 I/O | Sonnet | | quality-reviewer | 错误处理、类型安全、Promise 异常、资源泄漏 | Sonnet | | bug-detector | 逻辑错误、空值访问、边界条件、竞态条件 | Opus | | claudemd-reviewer | CLAUDE.md 规范合规性检查 | Sonnet | | issue-validator | 验证问题真实性,过滤假阳性 | Opus |

HIGH SIGNAL 原则: 只报告确定的问题,宁可漏报也不误报。

安装

# 克隆项目
git clone <repo-url>
cd codereview

# 安装依赖
npm install

# 构建
npm run build

# 运行测试
npm test

# 全局安装(可选)
npm link

配置

配置按以下优先级读取:

1. 环境变量(优先)

export ANTHROPIC_API_KEY=sk-ant-xxx
export ANTHROPIC_BASE_URL=https://api.anthropic.com  # 可选

2. 配置文件

创建 ~/.claude/settings.json

{
  "env": {
    "ANTHROPIC_API_KEY": "sk-ant-xxx",
    "ANTHROPIC_BASE_URL": "https://api.anthropic.com"
  }
}

使用

基本用法

# 评审 PR(输出到终端)
codereview pr

# 评审 PR 并发布到 GitHub
codereview pr --comment

# 评审 PR(对比指定分支)
codereview pr --base develop

# 评审指定文件
codereview files src/auth.ts src/api.ts

# 评审整个目录
codereview dir src/

维度选择

# 只做安全评审
codereview pr --aspects security

# 安全 + Bug 检测
codereview pr --aspects security,bugs

# 全部维度(默认)
codereview pr --aspects security,performance,quality,bugs

输出控制

# 英文输出
codereview pr --lang en

# 终端显示 + 保存到 Markdown
codereview pr -s review.md

# 仅保存到 JSON 文件
codereview pr -o review.json -f json

# 详细进度显示
codereview pr --verbose

GitHub 集成

# 评审并发布到 PR(需要 gh CLI)
codereview pr --comment

# 强制评审(跳过 draft/已审查检查)
codereview pr --comment --force

参数说明

| 参数 | 说明 | 默认值 | |------|------|--------| | -f, --format | 输出格式:json/markdown/terminal | terminal | | -o, --output | 仅输出到文件(不显示终端) | - | | -s, --save | 终端显示 + 同时保存到文件 | - | | -b, --base | PR 对比分支 | main | | -a, --aspects | 评审维度(逗号分隔):security,performance,quality,bugs | security,performance,quality,bugs | | -l, --lang | 输出语言:zh/en | zh | | -i, --include | 只评审匹配的文件(glob 模式) | - | | -e, --exclude | 排除匹配的文件(glob 模式) | - | | -c, --comment | 发布评审到 GitHub PR | false | | --force | 跳过 PR 资格检查 | false | | --default-sonnet-model | 全部代理使用 Sonnet(更快、更便宜) | false | | -v, --verbose | 显示详细进度 | false | | -V, --version | 显示版本号 | - |

文件过滤

默认情况下,AI 只评审代码和配置文件,自动忽略:

  • 图片:*.png, *.jpg, *.gif, *.svg, *.ico 等
  • 字体:*.woff, *.ttf, *.eot 等
  • 二进制:*.exe, *.dll, *.so, *.wasm 等
  • 锁文件:package-lock.json, yarn.lock, go.sum 等
  • 依赖目录:node_modules/, vendor/, dist/, build/ 等

可用 --include--exclude 覆盖默认行为:

# 只评审 Go 文件
codereview pr -i "*.go"

# 排除测试文件
codereview pr -e "**/test/**,**/*_test.go"

# 只评审 TypeScript,排除测试
codereview pr -i "*.ts,*.tsx" -e "**/*.test.ts"

PR 资格检查

使用 --comment 时,自动检查以下条件(可用 --force 跳过):

  • PR 未关闭(非 closed/merged)
  • PR 非草稿(非 draft)
  • PR 未被 Claude 评审过
  • PR 非 trivial 变更(如仅版本号更新)

CLAUDE.md 合规检查

当项目存在 CLAUDE.md 文件时,会自动启用合规检查:

  1. 自动发现根目录的 CLAUDE.md
  2. 自动发现修改文件目录中的 CLAUDE.md
  3. 启动 claudemd-reviewer 代理检查合规性
  4. 验证器会交叉验证 CLAUDE.md 规则引用

Docker

构建镜像

docker build -t codereview:latest .

运行

docker run \
  -e ANTHROPIC_API_KEY=sk-ant-xxx \
  -e GITHUB_TOKEN=ghp-xxx \
  -v $(pwd):/workspace \
  -w /workspace \
  codereview:latest

环境变量

| 变量 | 说明 | 必需 | |------|------|------| | ANTHROPIC_API_KEY | Claude API Key | ✅ | | ANTHROPIC_BASE_URL | 自定义 API 端点 | ❌ | | GITHUB_TOKEN | GitHub Token | ❌ | | PLUGIN_MODE | pr/files/dir | ❌ | | PLUGIN_BASE | PR 对比分支 | ❌ | | PLUGIN_FORMAT | json/markdown/terminal | ❌ | | PLUGIN_ASPECTS | 评审维度 | ❌ | | PLUGIN_LANG | 输出语言 | ❌ |

CI/CD 集成

Drone CI

kind: pipeline
type: docker
name: code-review

trigger:
  event:
    - pull_request

steps:
  - name: multi-agent-review
    image: your-registry/codereview:latest
    settings:
      api_key:
        from_secret: anthropic_api_key
      github_token:
        from_secret: github_token
      mode: pr
      base: ${DRONE_TARGET_BRANCH}
      format: json
      aspects: security,performance,quality,bugs
      lang: zh

Harness

- step:
    type: Run
    name: Multi-Agent Review
    spec:
      image: your-registry/codereview:latest
      command: /entrypoint.sh
      envVariables:
        ANTHROPIC_API_KEY: <+secrets.getValue("anthropic_api_key")>
        PLUGIN_MODE: pr
        PLUGIN_ASPECTS: security,performance,quality,bugs

输出示例

Terminal

Code Review Report
Score: 75/100

Summary:
在 src/ 目录中发现了多个安全和质量问题。最关键的是权限绕过配置和命令注入风险。

Issues (3):
  [CRITICAL] [security] <security-reviewer> src/auth.ts:45
    SQL injection vulnerability in user query
    → Use parameterized queries instead of string concatenation

  [HIGH] [performance] <performance-reviewer> src/api.ts:120
    N+1 query in user list endpoint
    → Use eager loading or batch queries

  [MEDIUM] [quality] <quality-reviewer> src/utils.ts:30
    Unhandled promise rejection
    → Add try-catch or .catch() handler

GitHub PR Comment

## Code review

Found 2 issues:

1. SQL injection vulnerability in user query (security)

https://github.com/owner/repo/blob/abc123.../src/auth.ts#L44-L47

> **Suggestion:** Use parameterized queries

2. N+1 query in user list endpoint (performance)

https://github.com/owner/repo/blob/abc123.../src/api.ts#L119-L122

---

Generated with [Claude Code](https://claude.ai/code)

<sub>If this code review was useful, please react with 👍. Otherwise, react with 👎.</sub>

开发

# 开发模式运行
npm run dev -- pr --aspects security

# 构建
npm run build

# 运行测试
npm test

# 监听模式测试
npm run test:watch

# 测试覆盖率
npm run test:coverage

# 类型检查
npx tsc --noEmit

测试覆盖

✓ src/config.test.ts (6 tests)
✓ src/formatters.test.ts (23 tests)
✓ src/github.test.ts (3 tests)
✓ src/agents.test.ts (25 tests)
✓ src/orchestrator.test.ts (11 tests)

Test Files: 5 passed
Tests: 68 passed

License

MIT