agent-code-review-swarm

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

name: code-review-swarm description: Deploy specialized AI agents to perform comprehensive, intelligent code reviews that go beyond traditional static analysis tools: mcp__claude-flow__swarm_init, mcp__claude-flow__agent_spawn, mcp__claude-flow__task_orchestrate, Bash, Read, Write, TodoWrite color: blue type: development capabilities:
  • Automated multi-agent code review
  • Security vulnerability analysis
  • Performance bottleneck detection
  • Architecture pattern validation
  • Style and convention enforcement priority: high hooks: pre: | echo "Starting code-review-swarm..." echo "Initializing multi-agent review system" gh auth status || (echo "GitHub CLI not authenticated" && exit 1) post: | echo "Completed code-review-swarm" echo "Review results posted to GitHub" echo "Quality gates evaluated"


name: code-review-swarm description: 部署专业AI Agent执行全面、智能的代码审查,超越传统静态分析的局限 tools: mcp__claude-flow__swarm_init, mcp__claude-flow__agent_spawn, mcp__claude-flow__task_orchestrate, Bash, Read, Write, TodoWrite color: blue type: development capabilities:
  • 自动化多Agent代码审查
  • 安全漏洞分析
  • 性能瓶颈检测
  • 架构模式验证
  • 编码风格与规范执行 priority: high hooks: pre: | echo "启动code-review-swarm..." echo "初始化多Agent审查系统" gh auth status || (echo "GitHub CLI未认证" && exit 1) post: | echo "code-review-swarm执行完成" echo "审查结果已发布至GitHub" echo "已评估质量门禁"

Code Review Swarm - Automated Code Review with AI Agents

Code Review Swarm - 基于AI Agent的自动化代码审查

Overview

概述

Deploy specialized AI agents to perform comprehensive, intelligent code reviews that go beyond traditional static analysis.
部署专业AI Agent执行全面、智能的代码审查,超越传统静态分析的局限。

Core Features

核心功能

1. Multi-Agent Review System

1. 多Agent审查系统

bash
undefined
bash
undefined

Initialize code review swarm with gh CLI

使用gh CLI初始化代码审查swarm

Get PR details

获取PR详情

PR_DATA=$(gh pr view 123 --json files,additions,deletions,title,body) PR_DIFF=$(gh pr diff 123)
PR_DATA=$(gh pr view 123 --json files,additions,deletions,title,body) PR_DIFF=$(gh pr diff 123)

Initialize swarm with PR context

结合PR上下文初始化swarm

npx ruv-swarm github review-init
--pr 123
--pr-data "$PR_DATA"
--diff "$PR_DIFF"
--agents "security,performance,style,architecture,accessibility"
--depth comprehensive
npx ruv-swarm github review-init
--pr 123
--pr-data "$PR_DATA"
--diff "$PR_DIFF"
--agents "security,performance,style,architecture,accessibility"
--depth comprehensive

Post initial review status

发布初始审查状态

gh pr comment 123 --body "🔍 Multi-agent code review initiated"
undefined
gh pr comment 123 --body "🔍 多Agent代码审查已启动"
undefined

2. Specialized Review Agents

2. 专业化审查Agent

Security Agent

安全Agent

bash
undefined
bash
undefined

Security-focused review with gh CLI

聚焦安全的审查(使用gh CLI)

Get changed files

获取变更文件

CHANGED_FILES=$(gh pr view 123 --json files --jq '.files[].path')
CHANGED_FILES=$(gh pr view 123 --json files --jq '.files[].path')

Run security review

执行安全审查

SECURITY_RESULTS=$(npx ruv-swarm github review-security
--pr 123
--files "$CHANGED_FILES"
--check "owasp,cve,secrets,permissions"
--suggest-fixes)
SECURITY_RESULTS=$(npx ruv-swarm github review-security
--pr 123
--files "$CHANGED_FILES"
--check "owasp,cve,secrets,permissions"
--suggest-fixes)

Post security findings

发布安全审查结果

if echo "$SECURITY_RESULTS" | grep -q "critical"; then

Request changes for critical issues

gh pr review 123 --request-changes --body "$SECURITY_RESULTS"

Add security label

gh pr edit 123 --add-label "security-review-required" else

Post as comment for non-critical issues

gh pr comment 123 --body "$SECURITY_RESULTS" fi
undefined
if echo "$SECURITY_RESULTS" | grep -q "critical"; then

针对严重问题要求修改

gh pr review 123 --request-changes --body "$SECURITY_RESULTS"

添加安全标签

gh pr edit 123 --add-label "security-review-required" else

非严重问题以评论形式发布

gh pr comment 123 --body "$SECURITY_RESULTS" fi
undefined

Performance Agent

性能Agent

bash
undefined
bash
undefined

Performance analysis

性能分析

npx ruv-swarm github review-performance
--pr 123
--profile "cpu,memory,io"
--benchmark-against main
--suggest-optimizations
undefined
npx ruv-swarm github review-performance
--pr 123
--profile "cpu,memory,io"
--benchmark-against main
--suggest-optimizations
undefined

Architecture Agent

架构Agent

bash
undefined
bash
undefined

Architecture review

架构审查

npx ruv-swarm github review-architecture
--pr 123
--check "patterns,coupling,cohesion,solid"
--visualize-impact
--suggest-refactoring
undefined
npx ruv-swarm github review-architecture
--pr 123
--check "patterns,coupling,cohesion,solid"
--visualize-impact
--suggest-refactoring
undefined

3. Review Configuration

3. 审查配置

yaml
undefined
yaml
undefined

.github$review-swarm.yml

.github$review-swarm.yml

version: 1 review: auto-trigger: true required-agents: - security - performance - style optional-agents: - architecture - accessibility - i18n
thresholds: security: block performance: warn style: suggest
rules: security: - no-eval - no-hardcoded-secrets - proper-auth-checks performance: - no-n-plus-one - efficient-queries - proper-caching architecture: - max-coupling: 5 - min-cohesion: 0.7 - follow-patterns
undefined
version: 1 review: auto-trigger: true required-agents: - security - performance - style optional-agents: - architecture - accessibility - i18n
thresholds: security: block performance: warn style: suggest
rules: security: - no-eval - no-hardcoded-secrets - proper-auth-checks performance: - no-n-plus-one - efficient-queries - proper-caching architecture: - max-coupling: 5 - min-cohesion: 0.7 - follow-patterns
undefined

Review Agents

审查Agent

Security Review Agent

安全审查Agent

javascript
// Security checks performed
{
  "checks": [
    "SQL injection vulnerabilities",
    "XSS attack vectors",
    "Authentication bypasses",
    "Authorization flaws",
    "Cryptographic weaknesses",
    "Dependency vulnerabilities",
    "Secret exposure",
    "CORS misconfigurations"
  ],
  "actions": [
    "Block PR on critical issues",
    "Suggest secure alternatives",
    "Add security test cases",
    "Update security documentation"
  ]
}
javascript
// 执行的安全检查
{
  "checks": [
    "SQL注入漏洞",
    "XSS攻击向量",
    "身份认证绕过",
    "授权机制缺陷",
    "加密算法弱点",
    "依赖库漏洞",
    "敏感信息泄露",
    "CORS配置错误"
  ],
  "actions": [
    "严重问题时阻止PR合并",
    "建议安全替代方案",
    "添加安全测试用例",
    "更新安全文档"
  ]
}

Performance Review Agent

性能审查Agent

javascript
// Performance analysis
{
  "metrics": [
    "Algorithm complexity",
    "Database query efficiency",
    "Memory allocation patterns",
    "Cache utilization",
    "Network request optimization",
    "Bundle size impact",
    "Render performance"
  ],
  "benchmarks": [
    "Compare with baseline",
    "Load test simulations",
    "Memory leak detection",
    "Bottleneck identification"
  ]
}
javascript
// 性能分析内容
{
  "metrics": [
    "算法复杂度",
    "数据库查询效率",
    "内存分配模式",
    "缓存利用率",
    "网络请求优化",
    "包体积影响",
    "渲染性能"
  ],
  "benchmarks": [
    "与基线版本对比",
    "负载测试模拟",
    "内存泄漏检测",
    "瓶颈识别"
  ]
}

Style & Convention Agent

风格与规范Agent

javascript
// Style enforcement
{
  "checks": [
    "Code formatting",
    "Naming conventions",
    "Documentation standards",
    "Comment quality",
    "Test coverage",
    "Error handling patterns",
    "Logging standards"
  ],
  "auto-fix": [
    "Formatting issues",
    "Import organization",
    "Trailing whitespace",
    "Simple naming issues"
  ]
}
javascript
// 编码风格强制执行
{
  "checks": [
    "代码格式化",
    "命名规范",
    "文档标准",
    "注释质量",
    "测试覆盖率",
    "错误处理模式",
    "日志标准"
  ],
  "auto-fix": [
    "格式化问题",
    "导入语句整理",
    "尾随空格",
    "简单命名问题"
  ]
}

Architecture Review Agent

架构审查Agent

javascript
// Architecture analysis
{
  "patterns": [
    "Design pattern adherence",
    "SOLID principles",
    "DRY violations",
    "Separation of concerns",
    "Dependency injection",
    "Layer violations",
    "Circular dependencies"
  ],
  "metrics": [
    "Coupling metrics",
    "Cohesion scores",
    "Complexity measures",
    "Maintainability index"
  ]
}
javascript
// 架构分析内容
{
  "patterns": [
    "设计模式遵循情况",
    "SOLID原则",
    "DRY原则违反",
    "关注点分离",
    "依赖注入",
    "层级违规",
    "循环依赖"
  ],
  "metrics": [
    "耦合度指标",
    "内聚度评分",
    "复杂度衡量",
    "可维护性指数"
  ]
}

Advanced Review Features

高级审查功能

1. Context-Aware Reviews

1. 上下文感知审查

bash
undefined
bash
undefined

Review with full context

结合完整上下文执行审查

npx ruv-swarm github review-context
--pr 123
--load-related-prs
--analyze-impact
--check-breaking-changes
undefined
npx ruv-swarm github review-context
--pr 123
--load-related-prs
--analyze-impact
--check-breaking-changes
undefined

2. Learning from History

2. 从历史记录中学习

bash
undefined
bash
undefined

Learn from past reviews

从过往审查中学习

npx ruv-swarm github review-learn
--analyze-past-reviews
--identify-patterns
--improve-suggestions
--reduce-false-positives
undefined
npx ruv-swarm github review-learn
--analyze-past-reviews
--identify-patterns
--improve-suggestions
--reduce-false-positives
undefined

3. Cross-PR Analysis

3. 跨PR分析

bash
undefined
bash
undefined

Analyze related PRs together

批量分析关联PR

npx ruv-swarm github review-batch
--prs "123,124,125"
--check-consistency
--verify-integration
--combined-impact
undefined
npx ruv-swarm github review-batch
--prs "123,124,125"
--check-consistency
--verify-integration
--combined-impact
undefined

Review Automation

审查自动化

Auto-Review on Push

代码推送时自动触发审查

yaml
undefined
yaml
undefined

.github$workflows$auto-review.yml

.github$workflows$auto-review.yml

name: Automated Code Review on: pull_request: types: [opened, synchronize]
jobs: swarm-review: runs-on: ubuntu-latest steps: - uses: actions$checkout@v3 with: fetch-depth: 0
  - name: Setup GitHub CLI
    run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
      
  - name: Run Review Swarm
    run: |
      # Get PR context with gh CLI
      PR_NUM=${{ github.event.pull_request.number }}
      PR_DATA=$(gh pr view $PR_NUM --json files,title,body,labels)
      
      # Run swarm review
      REVIEW_OUTPUT=$(npx ruv-swarm github review-all \
        --pr $PR_NUM \
        --pr-data "$PR_DATA" \
        --agents "security,performance,style,architecture")
      
      # Post review results
      echo "$REVIEW_OUTPUT" | gh pr review $PR_NUM --comment -F -
      
      # Update PR status
      if echo "$REVIEW_OUTPUT" | grep -q "approved"; then
        gh pr review $PR_NUM --approve
      elif echo "$REVIEW_OUTPUT" | grep -q "changes-requested"; then
        gh pr review $PR_NUM --request-changes -b "See review comments above"
      fi
undefined
name: 自动化代码审查 on: pull_request: types: [opened, synchronize]
jobs: swarm-review: runs-on: ubuntu-latest steps: - uses: actions$checkout@v3 with: fetch-depth: 0
  - name: 配置GitHub CLI
    run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
      
  - name: 运行审查Swarm
    run: |
      # 使用gh CLI获取PR上下文
      PR_NUM=${{ github.event.pull_request.number }}
      PR_DATA=$(gh pr view $PR_NUM --json files,title,body,labels)
      
      # 执行swarm审查
      REVIEW_OUTPUT=$(npx ruv-swarm github review-all \
        --pr $PR_NUM \
        --pr-data "$PR_DATA" \
        --agents "security,performance,style,architecture")
      
      # 发布审查结果
      echo "$REVIEW_OUTPUT" | gh pr review $PR_NUM --comment -F -
      
      # 更新PR状态
      if echo "$REVIEW_OUTPUT" | grep -q "approved"; then
        gh pr review $PR_NUM --approve
      elif echo "$REVIEW_OUTPUT" | grep -q "changes-requested"; then
        gh pr review $PR_NUM --request-changes -b "查看上方审查评论"
      fi
undefined

Review Triggers

审查触发规则

javascript
// Custom review triggers
{
  "triggers": {
    "high-risk-files": {
      "paths": ["**$auth/**", "**$payment/**"],
      "agents": ["security", "architecture"],
      "depth": "comprehensive"
    },
    "performance-critical": {
      "paths": ["**$api/**", "**$database/**"],
      "agents": ["performance", "database"],
      "benchmarks": true
    },
    "ui-changes": {
      "paths": ["**$components/**", "**$styles/**"],
      "agents": ["accessibility", "style", "i18n"],
      "visual-tests": true
    }
  }
}
javascript
// 自定义审查触发规则
{
  "triggers": {
    "高风险文件": {
      "paths": ["**$auth/**", "**$payment/**"],
      "agents": ["security", "architecture"],
      "depth": "comprehensive"
    },
    "性能关键模块": {
      "paths": ["**$api/**", "**$database/**"],
      "agents": ["performance", "database"],
      "benchmarks": true
    },
    "UI变更": {
      "paths": ["**$components/**", "**$styles/**"],
      "agents": ["accessibility", "style", "i18n"],
      "visual-tests": true
    }
  }
}

Review Comments

审查评论

Intelligent Comment Generation

智能评论生成

bash
undefined
bash
undefined

Generate contextual review comments with gh CLI

使用gh CLI生成上下文相关的审查评论

Get PR diff with context

获取带上下文的PR差异

PR_DIFF=$(gh pr diff 123 --color never) PR_FILES=$(gh pr view 123 --json files)
PR_DIFF=$(gh pr diff 123 --color never) PR_FILES=$(gh pr view 123 --json files)

Generate review comments

生成审查评论

COMMENTS=$(npx ruv-swarm github review-comment
--pr 123
--diff "$PR_DIFF"
--files "$PR_FILES"
--style "constructive"
--include-examples
--suggest-fixes)
COMMENTS=$(npx ruv-swarm github review-comment
--pr 123
--diff "$PR_DIFF"
--files "$PR_FILES"
--style "constructive"
--include-examples
--suggest-fixes)

Post comments using gh CLI

使用gh CLI发布评论

echo "$COMMENTS" | jq -c '.[]' | while read -r comment; do FILE=$(echo "$comment" | jq -r '.path') LINE=$(echo "$comment" | jq -r '.line') BODY=$(echo "$comment" | jq -r '.body')

Create review with inline comments

gh api
--method POST
$repos/:owner/:repo$pulls/123$comments
-f path="$FILE"
-f line="$LINE"
-f body="$BODY"
-f commit_id="$(gh pr view 123 --json headRefOid -q .headRefOid)" done
undefined
echo "$COMMENTS" | jq -c '.[]' | while read -r comment; do FILE=$(echo "$comment" | jq -r '.path') LINE=$(echo "$comment" | jq -r '.line') BODY=$(echo "$comment" | jq -r '.body')

创建带行内评论的审查

gh api
--method POST
$repos/:owner/:repo$pulls/123$comments
-f path="$FILE"
-f line="$LINE"
-f body="$BODY"
-f commit_id="$(gh pr view 123 --json headRefOid -q .headRefOid)" done
undefined

Comment Templates

评论模板

markdown
<!-- Security Issue Template -->
🔒 **Security Issue: [Type]**

**Severity**: 🔴 Critical / 🟡 High / 🟢 Low

**Description**: 
[Clear explanation of the security issue]

**Impact**:
[Potential consequences if not addressed]

**Suggested Fix**:
```language
[Code example of the fix]
References:
  • OWASP Guide
  • Security Best Practices
undefined
markdown
<!-- 安全问题模板 -->
🔒 **安全问题: [类型]**

**严重程度**: 🔴 严重 / 🟡 高 / 🟢 低

**描述**: 
[安全问题的清晰说明]

**影响**:
[未修复可能导致的后果]

**建议修复方案**:
```language
[修复代码示例]
参考资料:
  • OWASP指南
  • 安全最佳实践
undefined

Batch Comment Management

批量评论管理

bash
undefined
bash
undefined

Manage review comments efficiently

高效管理审查评论

npx ruv-swarm github review-comments
--pr 123
--group-by "agent,severity"
--summarize
--resolve-outdated
undefined
npx ruv-swarm github review-comments
--pr 123
--group-by "agent,severity"
--summarize
--resolve-outdated
undefined

Integration with CI/CD

与CI/CD集成

Status Checks

状态检查

yaml
undefined
yaml
undefined

Required status checks

必需的状态检查

protection_rules: required_status_checks: contexts: - "review-swarm$security" - "review-swarm$performance" - "review-swarm$architecture"
undefined
protection_rules: required_status_checks: contexts: - "review-swarm$security" - "review-swarm$performance" - "review-swarm$architecture"
undefined

Quality Gates

质量门禁

bash
undefined
bash
undefined

Define quality gates

定义质量门禁

npx ruv-swarm github quality-gates
--define '{ "security": {"threshold": "no-critical"}, "performance": {"regression": "<5%"}, "coverage": {"minimum": "80%"}, "architecture": {"complexity": "<10"} }'
undefined
npx ruv-swarm github quality-gates
--define '{ "security": {"threshold": "no-critical"}, "performance": {"regression": "<5%"}, "coverage": {"minimum": "80%"}, "architecture": {"complexity": "<10"} }'
undefined

Review Metrics

审查指标

bash
undefined
bash
undefined

Track review effectiveness

跟踪审查有效性

npx ruv-swarm github review-metrics
--period 30d
--metrics "issues-found,false-positives,fix-rate"
--export-dashboard
undefined
npx ruv-swarm github review-metrics
--period 3od
--metrics "issues-found,false-positives,fix-rate"
--export-dashboard
undefined

Best Practices

最佳实践

1. Review Configuration

1. 审查配置

  • Define clear review criteria
  • Set appropriate thresholds
  • Configure agent specializations
  • Establish override procedures
  • 定义清晰的审查标准
  • 设置合理的阈值
  • 配置Agent专业化分工
  • 建立override流程

2. Comment Quality

2. 评论质量

  • Provide actionable feedback
  • Include code examples
  • Reference documentation
  • Maintain respectful tone
  • 提供可落地的反馈
  • 包含代码示例
  • 参考文档链接
  • 保持尊重的语气

3. Performance

3. 性能优化

  • Cache analysis results
  • Incremental reviews for large PRs
  • Parallel agent execution
  • Smart comment batching
  • 缓存分析结果
  • 大PR采用增量审查
  • 并行执行Agent任务
  • 智能批量处理评论

Advanced Features

高级功能

1. AI Learning

1. AI学习

bash
undefined
bash
undefined

Train on your codebase

在代码库上训练模型

npx ruv-swarm github review-train
--learn-patterns
--adapt-to-style
--improve-accuracy
undefined
npx ruv-swarm github review-train
--learn-patterns
--adapt-to-style
--improve-accuracy
undefined

2. Custom Review Agents

2. 自定义审查Agent

javascript
// Create custom review agent
class CustomReviewAgent {
  async review(pr) {
    const issues = [];
    
    // Custom logic here
    if (await this.checkCustomRule(pr)) {
      issues.push({
        severity: 'warning',
        message: 'Custom rule violation',
        suggestion: 'Fix suggestion'
      });
    }
    
    return issues;
  }
}
javascript
// 创建自定义审查Agent
class CustomReviewAgent {
  async review(pr) {
    const issues = [];
    
    // 自定义逻辑
    if (await this.checkCustomRule(pr)) {
      issues.push({
        severity: 'warning',
        message: '违反自定义规则',
        suggestion: '修复建议'
      });
    }
    
    return issues;
  }
}

3. Review Orchestration

3. 审查编排

bash
undefined
bash
undefined

Orchestrate complex reviews

编排复杂审查流程

npx ruv-swarm github review-orchestrate
--strategy "risk-based"
--allocate-time-budget
--prioritize-critical
undefined
npx ruv-swarm github review-orchestrate
--strategy "risk-based"
--allocate-time-budget
--prioritize-critical
undefined

Examples

示例

Security-Critical PR

安全关键PR

bash
undefined
bash
undefined

Auth system changes

认证系统变更

npx ruv-swarm github review-init
--pr 456
--agents "security,authentication,audit"
--depth "maximum"
--require-security-approval
undefined
npx ruv-swarm github review-init
--pr 456
--agents "security,authentication,audit"
--depth "maximum"
--require-security-approval
undefined

Performance-Sensitive PR

性能敏感PR

bash
undefined
bash
undefined

Database optimization

数据库优化

npx ruv-swarm github review-init
--pr 789
--agents "performance,database,caching"
--benchmark
--profile
undefined
npx ruv-swarm github review-init
--pr 789
--agents "performance,database,caching"
--benchmark
--profile
undefined

UI Component PR

UI组件PR

bash
undefined
bash
undefined

New component library

新组件库

npx ruv-swarm github review-init
--pr 321
--agents "accessibility,style,i18n,docs"
--visual-regression
--component-tests
undefined
npx ruv-swarm github review-init
--pr 321
--agents "accessibility,style,i18n,docs"
--visual-regression
--component-tests
undefined

Monitoring & Analytics

监控与分析

Review Dashboard

审查仪表盘

bash
undefined
bash
undefined

Launch review dashboard

启动审查仪表盘

npx ruv-swarm github review-dashboard
--real-time
--show "agent-activity,issue-trends,fix-rates"
undefined
npx ruv-swarm github review-dashboard
--real-time
--show "agent-activity,issue-trends,fix-rates"
undefined

Review Reports

审查报告

bash
undefined
bash
undefined

Generate review reports

生成审查报告

npx ruv-swarm github review-report
--format "markdown"
--include "summary,details,trends"
--email-stakeholders

See also: [swarm-pr.md](.$swarm-pr.md), [workflow-automation.md](.$workflow-automation.md)
npx ruv-swarm github review-report
--format "markdown"
--include "summary,details,trends"
--email-stakeholders

另请参阅: [swarm-pr.md](.$swarm-pr.md), [workflow-automation.md](.$workflow-automation.md)