mcpField
A
agent-swarm-pr

agent-swarm-pr

github.com/ruvnet开发80.0k1.1k 次安装今天更新
代码仓库

关于 agent-swarm-pr

通过 GitHub Pull Request 上下文协调多 Agent 的 PR 管理技能,覆盖代码审查、验证、集成与生命周期自动化。可依据 PR 标签分配 Agent,并通过评论触发群组操作。

主要功能

  1. 01基于 PR 创建协作群组
  2. 02按标签分配 Agent
  3. 03通过评论执行群组命令
  4. 04多 PR 协调与依赖分析
  5. 05审查、修复和合并协调

适用场景

  1. 01按 PR 类型安排审查 Agent
  2. 02从 PR 评论启动协作任务
  3. 03协调相关 PR 并分析依赖

MCP 相关

使用 GitHub MCP 工具读取、创建、更新和合并 PR,并通过 Claude Flow MCP 工具初始化协作群组、分配 Agent、编排任务及同步状态。

安装

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

$npx skills add https://github.com/ruvnet/ruflo --skill agent-swarm-pr

安装后在 Claude Code 中输入/agent-swarm-pr确认已加载。

详细介绍


name: swarm-pr description: 拉取请求群组管理 Agent,可协调多 Agent 代码审查、验证和集成工作流,并自动管理 PR 生命周期 type: development color: "#4ECDC4" tools:

  • mcp__github__get_pull_request
  • mcp__github__create_pull_request
  • mcp__github__update_pull_request
  • mcp__github__list_pull_requests
  • mcp__github__create_pr_comment
  • mcp__github__get_pr_diff
  • mcp__github__merge_pull_request
  • mcp__claude-flow__swarm_init
  • mcp__claude-flow__agent_spawn
  • mcp__claude-flow__task_orchestrate
  • mcp__claude-flow__memory_usage
  • mcp__claude-flow__coordination_sync
  • TodoWrite
  • TodoRead
  • Bash
  • Grep
  • Read
  • Write
  • Edit hooks: pre:
    • "Initialize PR-specific swarm with diff analysis and impact assessment"
    • "Analyze PR complexity and assign optimal agent topology"
    • "Store PR metadata and diff context in swarm memory" post:
    • "Update PR with comprehensive swarm review results"
    • "Coordinate merge decisions based on swarm analysis"
    • "Generate PR completion metrics and learnings"

群组 PR——通过拉取请求管理群组

概述

直接通过 GitHub 拉取请求创建和管理 AI 群组,通过智能多 Agent 协作与开发工作流无缝集成。

核心功能

1. 基于 PR 创建群组
# Create swarm from PR description using gh CLI
gh pr view 123 --json body,title,labels,files | npx ruv-swarm swarm create-from-pr

# Auto-spawn agents based on PR labels
gh pr view 123 --json labels | npx ruv-swarm swarm auto-spawn

# Create swarm with PR context
gh pr view 123 --json body,labels,author,assignees | \
  npx ruv-swarm swarm init --from-pr-data
2. PR 评论命令

通过 PR 评论执行群组命令:


$swarm init mesh 6
$swarm spawn coder "Implement authentication"
$swarm spawn tester "Write unit tests"
$swarm status
3. 自动化 PR 工作流
# .github$workflows$swarm-pr.yml
name: Swarm PR Handler
on:
  pull_request:
    types: [opened, labeled]
  issue_comment:
    types: [created]

jobs:
  swarm-handler:
    runs-on: ubuntu-latest
    steps:
      - uses: actions$checkout@v3
      - name: Handle Swarm Command
        run: |
          if [[ "${{ github.event.comment.body }}" == $swarm* ]]; then
            npx ruv-swarm github handle-comment \
              --pr ${{ github.event.pull_request.number }} \
              --comment "${{ github.event.comment.body }}"
          fi

PR 标签集成

自动分配 Agent

将 PR 标签映射到 Agent 类型:

{
  "label-mapping": {
    "bug": ["debugger", "tester"],
    "feature": ["architect", "coder", "tester"],
    "refactor": ["analyst", "coder"],
    "docs": ["researcher", "writer"],
    "performance": ["analyst", "optimizer"]
  }
}
基于标签的拓扑结构
# Small PR (< 100 lines): ring topology
# Medium PR (100-500 lines): mesh topology  
# Large PR (> 500 lines): hierarchical topology
npx ruv-swarm github pr-topology --pr 123

PR 群组命令

从 PR 初始化
# Create swarm with PR context using gh CLI
PR_DIFF=$(gh pr diff 123)
PR_INFO=$(gh pr view 123 --json title,body,labels,files,reviews)

npx ruv-swarm github pr-init 123 \
  --auto-agents \
  --pr-data "$PR_INFO" \
  --diff "$PR_DIFF" \
  --analyze-impact
进度更新
# Post swarm progress to PR using gh CLI
PROGRESS=$(npx ruv-swarm github pr-progress 123 --format markdown)

gh pr comment 123 --body "$PROGRESS"

# Update PR labels based on progress
if [[ $(echo "$PROGRESS" | grep -o '[0-9]\+%' | sed 's/%//') -gt 90 ]]; then
  gh pr edit 123 --add-label "ready-for-review"
fi
代码审查集成
# Create review agents with gh CLI integration
PR_FILES=$(gh pr view 123 --json files --jq '.files[].path')

# Run swarm review
REVIEW_RESULTS=$(npx ruv-swarm github pr-review 123 \
  --agents "security,performance,style" \
  --files "$PR_FILES")

# Post review comments using gh CLI
echo "$REVIEW_RESULTS" | jq -r '.comments[]' | while read -r comment; do
  FILE=$(echo "$comment" | jq -r '.file')
  LINE=$(echo "$comment" | jq -r '.line')
  BODY=$(echo "$comment" | jq -r '.body')
  
  gh pr review 123 --comment --body "$BODY"
done

高级功能

1. 多 PR 群组协作
# Coordinate swarms across related PRs
npx ruv-swarm github multi-pr \
  --prs "123,124,125" \
  --strategy "parallel" \
  --share-memory
2. PR 依赖分析
# Analyze PR dependencies
npx ruv-swarm github pr-deps 123 \
  --spawn-agents \
  --resolve-conflicts
3. 自动修复 PR
# Auto-fix PR issues
npx ruv-swarm github pr-fix 123 \
  --issues "lint,test-failures" \
  --commit-fixes

最佳实践

1. PR 模板

## Swarm Configuration
- Topology: [mesh$hierarchical$ring$star]
- Max Agents: [number]
- Auto-spawn: [yes$no]
- Priority: [high$medium$low]

## Tasks for Swarm
- [ ] Task 1 description
- [ ] Task 2 description
2. 状态检查
# Require swarm completion before merge
required_status_checks:
  contexts:
    - "swarm$tasks-complete"
    - "swarm$tests-pass"
    - "swarm$review-approved"
3. PR 合并自动化
# Auto-merge when swarm completes using gh CLI
# Check swarm completion status
SWARM_STATUS=$(npx ruv-swarm github pr-status 123)

if [[ "$SWARM_STATUS" == "complete" ]]; then
  # Check review requirements
  REVIEWS=$(gh pr view 123 --json reviews --jq '.reviews | length')
  
  if [[ $REVIEWS -ge 2 ]]; then
    # Enable auto-merge
    gh pr merge 123 --auto --squash
  fi
fi

Webhook 集成

设置 Webhook 处理程序
// webhook-handler.js
const { createServer } = require('http');
const { execSync } = require('child_process');

createServer((req, res) => {
  if (req.url === '$github-webhook') {
    const event = JSON.parse(body);
    
    if (event.action === 'opened' && event.pull_request) {
      execSync(`npx ruv-swarm github pr-init ${event.pull_request.number}`);
    }
    
    res.writeHead(200);
    res.end('OK');
  }
}).listen(3000);

示例

功能开发 PR
# PR #456: Add user authentication
npx ruv-swarm github pr-init 456 \
  --topology hierarchical \
  --agents "architect,coder,tester,security" \
  --auto-assign-tasks
Bug 修复 PR
# PR #789: Fix memory leak
npx ruv-swarm github pr-init 789 \
  --topology mesh \
  --agents "debugger,analyst,tester" \
  --priority high
文档 PR
# PR #321: Update API docs
npx ruv-swarm github pr-init 321 \
  --topology ring \
  --agents "researcher,writer,reviewer" \
  --validate-links

指标与报告

PR 群组分析
# Generate PR swarm report
npx ruv-swarm github pr-report 123 \
  --metrics "completion-time,agent-efficiency,token-usage" \
  --format markdown
仪表板集成
# Export to GitHub Insights
npx ruv-swarm github export-metrics \
  --pr 123 \
  --to-insights

安全注意事项

  1. 令牌权限:确保 GitHub 令牌具有适当的权限范围
  2. 命令验证:执行前验证所有 PR 评论
  3. 速率限制:为 PR 操作实施速率限制
  4. 审计跟踪:记录所有群组操作,以满足合规要求

与 Claude Code 集成

使用 Claude Code 时:

  1. Claude Code 读取 PR 差异和上下文
  2. 群组根据 PR 类型协调处理方案
  3. 各 Agent 并行处理不同方面
  4. 自动将进度更新发布到 PR
  5. 标记为就绪前进行最终审查

高级群组 PR 协作

多 Agent PR 分析
# Initialize PR-specific swarm with intelligent topology selection
mcp__claude-flow__swarm_init { topology: "mesh", maxAgents: 8 }
mcp__claude-flow__agent_spawn { type: "coordinator", name: "PR Coordinator" }
mcp__claude-flow__agent_spawn { type: "reviewer", name: "Code Reviewer" }
mcp__claude-flow__agent_spawn { type: "tester", name: "Test Engineer" }
mcp__claude-flow__agent_spawn { type: "analyst", name: "Impact Analyzer" }
mcp__claude-flow__agent_spawn { type: "optimizer", name: "Performance Optimizer" }

# Store PR context for swarm coordination
mcp__claude-flow__memory_usage {
  action: "store",
  key: "pr/#{pr_number}$analysis",
  value: { 
    diff: "pr_diff_content", 
    files_changed: ["file1.js", "file2.py"],
    complexity_score: 8.5,
    risk_assessment: "medium"
  }
}

# Orchestrate comprehensive PR workflow
mcp__claude-flow__task_orchestrate {
  task: "Execute multi-agent PR review and validation workflow",
  strategy: "parallel",
  priority: "high",
  dependencies: ["diff_analysis", "test_validation", "security_review"]
}
群组协作的 PR 生命周期
// Pre-hook: PR Initialization and Swarm Setup
const prPreHook = async (prData) => {
  // Analyze PR complexity for optimal swarm configuration
  const complexity = await analyzePRComplexity(prData);
  const topology = complexity > 7 ? "hierarchical" : "mesh";
  
  // Initialize swarm with PR-specific configuration
  await mcp__claude_flow__swarm_init({ topology, maxAgents: 8 });
  
  // Store comprehensive PR context
  await mcp__claude_flow__memory_usage({
    action: "store",
    key: `pr/${prData.number}$context`,
    value: {
      pr: prData,
      complexity,
      agents_assigned: await getOptimalAgents(prData),
      timeline: generateTimeline(prData)
    }
  });
  
  // Coordinate initial agent synchronization
  await mcp__claude_flow__coordination_sync({ swarmId: "current" });
};

// Post-hook: PR Completion and Metrics
const prPostHook = async (results) => {
  // Generate comprehensive PR completion report
  const report = await generatePRReport(results);
  
  // Update PR with final swarm analysis
  await updatePRWithResults(report);
  
  // Store completion metrics for future optimization
  await mcp__claude_flow__memory_usage({
    action: "store",
    key: `pr/${results.number}$completion`,
    value: {
      completion_time: results.duration,
      agent_efficiency: results.agentMetrics,
      quality_score: results.qualityAssessment,
      lessons_learned: results.insights
    }
  });
};
智能 PR 合并协作
# Coordinate merge decision with swarm consensus
mcp__claude-flow__coordination_sync { swarmId: "pr-review-swarm" }

# Analyze merge readiness with multiple agents
mcp__claude-flow__task_orchestrate {
  task: "Evaluate PR merge readiness with comprehensive validation",
  strategy: "sequential",
  priority: "critical"
}

# Store merge decision context
mcp__claude-flow__memory_usage {
  action: "store",
  key: "pr$merge_decisions/#{pr_number}",
  value: {
    ready_to_merge: true,
    validation_passed: true,
    agent_consensus: "approved",
    final_review_score: 9.2
  }
}

另请参阅:swarm-issue.md、sync-coordinator.md、workflow-automation.md

评论

支持 Markdown