mcpField
R
review

review

github.com/0xdarkmatter测试与质量7856 次安装2 周前更新
代码仓库

关于 review

review 是用于审查代码变更的技能,适合检查暂存内容、指定文件或 Pull Request 的开发者。它会按文件类型调度审查,并按严重程度整理问题;关键问题可自动创建任务。

主要功能

  1. 01审查暂存、未提交或指定变更
  2. 02通过 GitHub CLI 获取 PR 差异
  3. 03按文件类型调度审查
  4. 04按安全、性能等重点检查
  5. 05支持快速、常规和深入审查
  6. 06关键问题自动创建任务

适用场景

  1. 01提交前审查暂存的代码变更
  2. 02检查某个文件或分支差异
  3. 03审查 GitHub Pull Request
  4. 04以 JSON 格式输出供 CI/CD 使用

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/0xdarkmatter/claude-mods --skill review

安装后在 Claude Code 中输入/review确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

framework-checks.md
assets/
.gitkeep
references/
.gitkeep
scripts/
.gitkeep

详细介绍

Review Skill - AI 代码审查

对暂存的更改、指定文件或拉取请求进行全面的代码审查。根据文件类型,分派预加载相关 -ops 技能的通用审查员,并自动为严重问题创建任务。

架构

review [target] [--focus] [--depth]
    │
    ├─→ Step 1: Determine Scope
    │     ├─ No args → git diff --cached (staged)
    │     ├─ --all → git diff HEAD (all uncommitted)
    │     ├─ File path → specific file diff
    │     └─ --pr N → gh pr diff N
    │
    ├─→ Step 2: Analyze Changes (parallel)
    │     ├─ delta for syntax-highlighted diff
    │     ├─ difft for semantic diff (structural)
    │     ├─ Categorize: logic, style, test, docs, config
    │     └─ Identify touched modules/components
    │
    ├─→ Step 3: Load Project Standards
    │     ├─ AGENTS.md, CLAUDE.md conventions
    │     ├─ .eslintrc, .prettierrc, pyproject.toml
    │     ├─ Detect test framework
    │     └─ Check CI config for existing linting
    │
    ├─→ Step 4: Route to Reviewers (general-purpose + skill preload)
    │     ├─ TypeScript → general-purpose, preload typescript-ops
    │     ├─ React/JSX → general-purpose, preload react-ops
    │     ├─ Python → general-purpose, preload python-pytest-ops
    │     ├─ Go → general-purpose, preload go-ops
    │     ├─ Rust → general-purpose, preload rust-ops
    │     ├─ Vue → general-purpose, preload vue-ops
    │     ├─ SQL/migrations → general-purpose, preload postgres-ops
    │     ├─ Cypress/E2E → general-purpose, preload cypress-ops
    │     ├─ Cloudflare/Workers → general-purpose, preload cloudflare-ops
    │     ├─ Shell/bash → general-purpose, preload bash-ops
    │     ├─ Claude extensions → general-purpose, preload claude-code-ops
    │     ├─ Multi-domain → parallel general-purpose dispatch
    │     └─ All reviewers preload: security-ops + testing-ops context
    │
    ├─→ Step 5: Generate Review
    │     ├─ Severity: CRITICAL / WARNING / SUGGESTION / PRAISE
    │     ├─ Line-specific comments (file:line refs)
    │     ├─ Suggested fixes as diff blocks
    │     └─ Overall verdict: Ready to commit? Y/N
    │
    └─→ Step 6: Integration
          ├─ Auto-create tasks (TaskCreate) for CRITICAL issues
          ├─ Link to /save for tracking
          └─ Suggest follow-up: /testgen, /explain

执行步骤

步骤 1:确定范围
# Default: staged changes
git diff --cached --name-only

# Check if anything is staged
STAGED=$(git diff --cached --name-only | wc -l)
if [ "$STAGED" -eq 0 ]; then
    echo "No staged changes. Use --all for uncommitted or specify a file."
    git status --short
fi

审查 PR 时:

gh pr diff $PR_NUMBER --patch

审查指定文件时:

git diff HEAD -- "$FILE"

进行基线比较时(--base):

git diff $BASE_BRANCH...HEAD
步骤 2:分析更改

运行语义差异分析(尽可能并行):

使用 difft(语义分析):

command -v difft >/dev/null 2>&1 && git difftool --tool=difftastic --no-prompt HEAD~1 || git diff HEAD~1

使用 delta(语法高亮):

command -v delta >/dev/null 2>&1 && git diff --cached | delta || git diff --cached

对更改进行分类:

git diff --cached --name-only | while read file; do
    case "$file" in
        *.test.* | *.spec.*) echo "TEST: $file" ;;
        *.md | docs/*) echo "DOCS: $file" ;;
        *.json | *.yaml | *.toml) echo "CONFIG: $file" ;;
        *) echo "CODE: $file" ;;
    esac
done

获取差异统计信息:

git diff --cached --stat
步骤 3:加载项目规范
# Claude Code conventions
cat AGENTS.md 2>/dev/null | head -50
cat CLAUDE.md 2>/dev/null | head -50

# Linting configs
cat .eslintrc* 2>/dev/null | head -30
cat .prettierrc* 2>/dev/null
cat pyproject.toml 2>/dev/null | head -30

# Test framework detection
cat package.json 2>/dev/null | jq '.devDependencies | keys | map(select(test("jest|vitest|mocha|cypress|playwright")))' 2>/dev/null

检查 CI 中是否已有 lint 检查:

cat .github/workflows/*.yml 2>/dev/null | grep -E "eslint|prettier|pylint|ruff" | head -10
步骤 4:分派审查员

分派时优先使用技能:领域知识来自 -ops 技能,通用 general-purpose 子 Agent 会在审查前预加载相关的 SKILL.md。

文件模式分派对象预加载
*.tsgeneral-purposeskills/typescript-ops/SKILL.md
*.tsxgeneral-purposeskills/react-ops/SKILL.md + skills/typescript-ops/SKILL.md
*.vuegeneral-purposeskills/vue-ops/SKILL.md + skills/typescript-ops/SKILL.md
*.pygeneral-purposeskills/python-pytest-ops/SKILL.md(如果使用 ORM,还需加载 skills/sql-ops/SKILL.md)
*.gogeneral-purposeskills/go-ops/SKILL.md
*.rsgeneral-purposeskills/rust-ops/SKILL.md
*.sql, migrations/*general-purposeskills/postgres-ops/SKILL.md
agents/*.md, skills/*, commands/*general-purposeskills/claude-code-ops/SKILL.md
*.test.*, *.spec.*general-purpose(按文件类型加载框架技能)
*.cy.ts, cypress/*general-purposeskills/cypress-ops/SKILL.md + skills/typescript-ops/SKILL.md
*.spec.ts(Playwright)general-purposeskills/playwright-ops/SKILL.md + skills/typescript-ops/SKILL.md
playwright/*, e2e/*general-purposeskills/playwright-ops/SKILL.md + skills/typescript-ops/SKILL.md
wrangler.toml, workers/*general-purposeskills/cloudflare-ops/SKILL.md
*.sh, *.bashgeneral-purposeskills/bash-ops/SKILL.md

通过 Agent 工具调用:

Agent tool with subagent_type: "general-purpose" (or surviving specialist from table)
model: "sonnet"
Prompt includes:
  - Skill preloading (domain knowledge):
    "First, read these files for review context:
     - Read: skills/security-ops/references/owasp-top10-a01-a05.md
     - Read: skills/security-ops/references/owasp-top10-a06-a10.md
     - Read: skills/testing-ops/SKILL.md
     - Read: [Preload column for the matched file pattern]"
  - Diff content
  - Project conventions from AGENTS.md
  - Linting config summaries
  - Requested focus area
  - Request for structured review output

按语言预加载(追加到上述预加载部分):

语言额外预加载原因
Pythonskills/python-pytest-ops/SKILL.md用于覆盖率审查的 Python 测试模式
Goskills/go-ops/SKILL.mdGo 惯用写法及并发注意事项
Rustskills/rust-ops/SKILL.md所有权模式及不安全代码审查
TypeScriptskills/typescript-ops/SKILL.md类型安全模式
步骤 5:生成审查结果

审查员会生成结构化的审查结果:

# Code Review: [scope description]

## Summary

| Metric | Value |
|--------|-------|
| Files reviewed | N |
| Lines changed | +X / -Y |
| Issues found | N (X critical, Y warnings) |

## Verdict

**Ready to commit?** Yes / No

[1-2 sentence summary of overall quality]

---

## Critical Issues

### `src/auth/login.ts:42`

**Issue:** SQL injection vulnerability in user input handling

**Risk:** Attacker can execute arbitrary SQL queries

**Fix:**
```diff
- const query = `SELECT * FROM users WHERE id = ${userId}`;
+ const query = `SELECT * FROM users WHERE id = $1`;
+ const result = await db.query(query, [userId]);

警告

src/components/Form.tsx:89

问题: useEffect 中缺少依赖项

建议: 将 userId 添加到依赖数组中

- useEffect(() => { fetchUser(userId) }, []);
+ useEffect(() => { fetchUser(userId) }, [userId]);

建议

[样式改进、可选增强]


值得肯定之处

[值得指出的优秀模式]


已审查文件

文件更改问题
src/auth/login.ts+42/-81 个严重问题

### Step 6: Integration

**Auto-create tasks for CRITICAL issues:**

TaskCreate: subject: "修复:login.ts:42 中的 SQL 注入" description: "在用户输入处理过程中发现 SQL 注入漏洞。" activeForm: "正在修复 login.ts:42 中的 SQL 注入"


**Link with dependencies for related issues:**

TaskCreate: #1 "修复 login.ts 中的 SQL 注入" TaskCreate: #2 "修复 register.ts 中的 SQL 注入" TaskUpdate: taskId: "2", addBlockedBy: ["1"]


**After fixing issues:**

TaskUpdate: taskId: "1" status: "completed"


---

## Severity System

| Level | Icon | Meaning | Action | Auto-Task? |
|-------|------|---------|--------|------------|
| CRITICAL | :red_circle: | Security bug, data loss risk, crashes | Must fix before merge | Yes |
| WARNING | :yellow_circle: | Logic issues, performance problems | Should address | No |
| SUGGESTION | :blue_circle: | Style, minor improvements | Optional | No |
| PRAISE | :star: | Good patterns worth noting | Recognition | No |

---

## Focus Modes

| Mode | What It Checks |
|------|----------------|
| `--security` | OWASP top 10, secrets in code, injection, auth issues |
| `--perf` | N+1 queries, unnecessary re-renders, complexity, memory |
| `--types` | Type safety, `any` usage, generics, null handling |
| `--tests` | Coverage gaps, test quality, mocking patterns |
| `--style` | Naming, organization, dead code, comments |
| (default) | All of the above |

---

## Depth Modes

| Mode | Behavior |
|------|----------|
| `--quick` | Surface-level scan, obvious issues only |
| `--normal` | Standard review, all severity levels (default) |
| `--thorough` | Deep analysis, traces data flow, checks edge cases |

---

## Advanced Flags

### `--base <branch>` - Baseline Comparison

Compare changes against a specific branch instead of HEAD:

```bash
/review --base main
/review src/ --base develop --thorough
--json - CI/CD 集成

将审查结果输出为 JSON:

{
  "summary": {
    "files_reviewed": 3,
    "lines_changed": { "added": 42, "removed": 8 },
    "issues": { "critical": 1, "warning": 2, "suggestion": 1 }
  },
  "verdict": {
    "ready_to_commit": false,
    "reason": "1 critical issue requires attention"
  },
  "issues": [...]
}

CI/CD 用法:

- name: Code Review
  run: |
    claude "/review --json" > review.json
    if jq -e '.issues[] | select(.severity == "critical")' review.json; then
      exit 1
    fi
--fix - 自动应用修复

自动应用建议的修复:

  1. 执行标准审查
  2. 针对每个可修复的问题,请求确认
  3. 使用 Edit 工具应用已批准的修复
  4. 为已解决的问题创建 TaskUpdate

非交互模式:

/review --fix --auto-approve

CLI 工具集成

工具用途后备方案
delta语法高亮的差异git diff
difft语义/结构差异git diff
ghGitHub PR 操作手动查看差异
rg搜索模式Grep 工具
jq解析 JSON 配置手动读取

优雅降级:

command -v delta >/dev/null 2>&1 && git diff --cached | delta || git diff --cached

集成

命令关联
/explain深入分析标记的代码
/testgen为发现的问题生成测试
/save将审查结果保存到会话状态

评论

支持 Markdown