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 "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"

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

Initialize code review swarm with gh CLI

Get PR details

Get PR details

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

Initialize swarm with PR context

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

Post initial review status

gh pr comment 123 --body "🔍 Multi-agent code review initiated"
undefined
gh pr comment 123 --body "🔍 Multi-agent code review initiated"
undefined

2. Specialized Review Agents

2. 专业化审查Agent

Security Agent

安全审查Agent

bash
undefined
bash
undefined

Security-focused review with gh CLI

Security-focused review with gh CLI

Get changed files

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

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

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

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

Performance Agent

性能审查Agent

bash
undefined
bash
undefined

Performance analysis

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

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
// 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"
  ]
}

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
// 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"
  ]
}

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
// 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"
  ]
}

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
// 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"
  ]
}

Advanced Review Features

高级审查功能

1. Context-Aware Reviews

1. 上下文感知审查

bash
undefined
bash
undefined

Review with full context

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

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

Analyze related PRs together

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: 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

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
// 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
    }
  }
}

Review Comments

审查评论

Intelligent Comment Generation

智能评论生成

bash
undefined
bash
undefined

Generate contextual review comments with gh CLI

Generate contextual review comments with gh CLI

Get PR diff with context

Get PR diff with context

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

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

Post comments using 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')

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

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
<!-- 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

Batch Comment Management

批量评论管理

bash
undefined
bash
undefined

Manage review comments efficiently

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

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

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

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 30d
--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

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
// 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;
  }
}

3. Review Orchestration

3. 审查编排

bash
undefined
bash
undefined

Orchestrate complex reviews

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

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

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

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

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

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)