agent-swarm-pr
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesename: swarm-pr
description: Pull request swarm management agent that coordinates multi-agent code review, validation, and integration workflows with automated PR lifecycle management
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"
name: swarm-pr
description: 用于Pull Request(PR)集群管理的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:
- "初始化针对PR的集群,包含差异分析和影响评估"
- "分析PR复杂度并分配最优Agent拓扑结构"
- "将PR元数据和差异上下文存储到集群内存中" post:
- "用完整的集群审查结果更新PR"
- "基于集群分析协调合并决策"
- "生成PR完成指标和经验总结"
Swarm PR - Managing Swarms through Pull Requests
Swarm PR - 通过Pull Request管理Agent集群
Overview
概述
Create and manage AI swarms directly from GitHub Pull Requests, enabling seamless integration with your development workflow through intelligent multi-agent coordination.
直接从GitHub Pull Request创建和管理AI集群,通过智能多Agent协同实现与开发工作流的无缝集成。
Core Features
核心功能
1. PR-Based Swarm Creation
1. 基于PR的集群创建
bash
undefinedbash
undefinedCreate swarm from PR description using gh CLI
使用gh CLI从PR描述创建集群
gh pr view 123 --json body,title,labels,files | npx ruv-swarm swarm create-from-pr
gh pr view 123 --json body,title,labels,files | npx ruv-swarm swarm create-from-pr
Auto-spawn agents based on PR labels
根据PR标签自动生成Agent
gh pr view 123 --json labels | npx ruv-swarm swarm auto-spawn
gh pr view 123 --json labels | npx ruv-swarm swarm auto-spawn
Create swarm with PR context
结合PR上下文创建集群
gh pr view 123 --json body,labels,author,assignees |
npx ruv-swarm swarm init --from-pr-data
npx ruv-swarm swarm init --from-pr-data
undefinedgh pr view 123 --json body,labels,author,assignees |
npx ruv-swarm swarm init --from-pr-data
npx ruv-swarm swarm init --from-pr-data
undefined2. PR Comment Commands
2. PR评论命令
Execute swarm commands via PR comments:
markdown
<!-- In PR comment -->
$swarm init mesh 6
$swarm spawn coder "Implement authentication"
$swarm spawn tester "Write unit tests"
$swarm status通过PR评论执行集群命令:
markdown
<!-- 在PR评论中 -->
$swarm init mesh 6
$swarm spawn coder "Implement authentication"
$swarm spawn tester "Write unit tests"
$swarm status3. Automated PR Workflows
3. 自动化PR工作流
yaml
undefinedyaml
undefined.github$workflows$swarm-pr.yml
.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 ${{ github.event.pull_request.number }}
--comment "${{ github.event.comment.body }}" fi
undefinedname: 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 ${{ github.event.pull_request.number }}
--comment "${{ github.event.comment.body }}" fi
undefinedPR Label Integration
PR标签集成
Automatic Agent Assignment
自动Agent分配
Map PR labels to agent types:
json
{
"label-mapping": {
"bug": ["debugger", "tester"],
"feature": ["architect", "coder", "tester"],
"refactor": ["analyst", "coder"],
"docs": ["researcher", "writer"],
"performance": ["analyst", "optimizer"]
}
}将PR标签映射到Agent类型:
json
{
"label-mapping": {
"bug": ["debugger", "tester"],
"feature": ["architect", "coder", "tester"],
"refactor": ["analyst", "coder"],
"docs": ["researcher", "writer"],
"performance": ["analyst", "optimizer"]
}
}Label-Based Topology
基于标签的拓扑结构
bash
undefinedbash
undefinedSmall PR (< 100 lines): ring topology
小型PR(< 100行):环形拓扑
Medium PR (100-500 lines): mesh topology
中型PR(100-500行):网状拓扑
Large PR (> 500 lines): hierarchical topology
大型PR(> 500行):分层拓扑
npx ruv-swarm github pr-topology --pr 123
undefinednpx ruv-swarm github pr-topology --pr 123
undefinedPR Swarm Commands
PR集群命令
Initialize from PR
从PR初始化
bash
undefinedbash
undefinedCreate swarm with PR context using gh CLI
使用gh CLI结合PR上下文创建集群
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
--auto-agents
--pr-data "$PR_INFO"
--diff "$PR_DIFF"
--analyze-impact
undefinedPR_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
--auto-agents
--pr-data "$PR_INFO"
--diff "$PR_DIFF"
--analyze-impact
undefinedProgress Updates
进度更新
bash
undefinedbash
undefinedPost swarm progress to PR using gh CLI
使用gh CLI将集群进度发布到PR
PROGRESS=$(npx ruv-swarm github pr-progress 123 --format markdown)
gh pr comment 123 --body "$PROGRESS"
PROGRESS=$(npx ruv-swarm github pr-progress 123 --format markdown)
gh pr comment 123 --body "$PROGRESS"
Update PR labels based on progress
根据进度更新PR标签
if [[ $(echo "$PROGRESS" | grep -o '[0-9]+%' | sed 's/%//') -gt 90 ]]; then
gh pr edit 123 --add-label "ready-for-review"
fi
undefinedif [[ $(echo "$PROGRESS" | grep -o '[0-9]+%' | sed 's/%//') -gt 90 ]]; then
gh pr edit 123 --add-label "ready-for-review"
fi
undefinedCode Review Integration
代码审查集成
bash
undefinedbash
undefinedCreate review agents with gh CLI integration
创建结合gh CLI的审查Agent
PR_FILES=$(gh pr view 123 --json files --jq '.files[].path')
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")
--agents "security,performance,style"
--files "$PR_FILES")
REVIEW_RESULTS=$(npx ruv-swarm github pr-review 123
--agents "security,performance,style"
--files "$PR_FILES")
--agents "security,performance,style"
--files "$PR_FILES")
Post review comments using gh CLI
使用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
undefinedecho "$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
undefinedAdvanced Features
高级功能
1. Multi-PR Swarm Coordination
1. 多PR集群协同
bash
undefinedbash
undefinedCoordinate swarms across related PRs
跨关联PR协调集群
npx ruv-swarm github multi-pr
--prs "123,124,125"
--strategy "parallel"
--share-memory
--prs "123,124,125"
--strategy "parallel"
--share-memory
undefinednpx ruv-swarm github multi-pr
--prs "123,124,125"
--strategy "parallel"
--share-memory
--prs "123,124,125"
--strategy "parallel"
--share-memory
undefined2. PR Dependency Analysis
2. PR依赖分析
bash
undefinedbash
undefinedAnalyze PR dependencies
分析PR依赖关系
npx ruv-swarm github pr-deps 123
--spawn-agents
--resolve-conflicts
--spawn-agents
--resolve-conflicts
undefinednpx ruv-swarm github pr-deps 123
--spawn-agents
--resolve-conflicts
--spawn-agents
--resolve-conflicts
undefined3. Automated PR Fixes
3. 自动化PR修复
bash
undefinedbash
undefinedAuto-fix PR issues
自动修复PR问题
npx ruv-swarm github pr-fix 123
--issues "lint,test-failures"
--commit-fixes
--issues "lint,test-failures"
--commit-fixes
undefinednpx ruv-swarm github pr-fix 123
--issues "lint,test-failures"
--commit-fixes
--issues "lint,test-failures"
--commit-fixes
undefinedBest Practices
最佳实践
1. PR Templates
1. PR模板
markdown
<!-- .github$pull_request_template.md -->markdown
<!-- .github/pull_request_template.md -->Swarm Configuration
集群配置
- Topology: [mesh$hierarchical$ring$star]
- Max Agents: [number]
- Auto-spawn: [yes$no]
- Priority: [high$medium$low]
- 拓扑结构: [mesh/hierarchical/ring/star]
- 最大Agent数: [数字]
- 自动生成: [yes/no]
- 优先级: [high/medium/low]
Tasks for Swarm
集群任务
- Task 1 description
- Task 2 description
undefined- 任务1描述
- 任务2描述
undefined2. Status Checks
2. 状态检查
yaml
undefinedyaml
undefinedRequire swarm completion before merge
要求集群完成后才能合并
required_status_checks:
contexts:
- "swarm$tasks-complete"
- "swarm$tests-pass"
- "swarm$review-approved"
undefinedrequired_status_checks:
contexts:
- "swarm/tasks-complete"
- "swarm/tests-pass"
- "swarm/review-approved"
undefined3. PR Merge Automation
3. PR合并自动化
bash
undefinedbash
undefinedAuto-merge when swarm completes using gh CLI
集群完成后使用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
undefinedSWARM_STATUS=$(npx ruv-swarm github pr-status 123)
if [[ "$SWARM_STATUS" == "complete" ]]; then
检查审查要求
REVIEWS=$(gh pr view 123 --json reviews --jq '.reviews | length')
if [[ $REVIEWS -ge 2 ]]; then
# 启用自动合并
gh pr merge 123 --auto --squash
fi
fi
undefinedWebhook Integration
Webhook集成
Setup Webhook Handler
设置Webhook处理器
javascript
// 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);javascript
// 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);Examples
示例
Feature Development PR
功能开发PR
bash
undefinedbash
undefinedPR #456: Add user authentication
PR #456: 添加用户认证
npx ruv-swarm github pr-init 456
--topology hierarchical
--agents "architect,coder,tester,security"
--auto-assign-tasks
--topology hierarchical
--agents "architect,coder,tester,security"
--auto-assign-tasks
undefinednpx ruv-swarm github pr-init 456
--topology hierarchical
--agents "architect,coder,tester,security"
--auto-assign-tasks
--topology hierarchical
--agents "architect,coder,tester,security"
--auto-assign-tasks
undefinedBug Fix PR
Bug修复PR
bash
undefinedbash
undefinedPR #789: Fix memory leak
PR #789: 修复内存泄漏
npx ruv-swarm github pr-init 789
--topology mesh
--agents "debugger,analyst,tester"
--priority high
--topology mesh
--agents "debugger,analyst,tester"
--priority high
undefinednpx ruv-swarm github pr-init 789
--topology mesh
--agents "debugger,analyst,tester"
--priority high
--topology mesh
--agents "debugger,analyst,tester"
--priority high
undefinedDocumentation PR
文档PR
bash
undefinedbash
undefinedPR #321: Update API docs
PR #321: 更新API文档
npx ruv-swarm github pr-init 321
--topology ring
--agents "researcher,writer,reviewer"
--validate-links
--topology ring
--agents "researcher,writer,reviewer"
--validate-links
undefinednpx ruv-swarm github pr-init 321
--topology ring
--agents "researcher,writer,reviewer"
--validate-links
--topology ring
--agents "researcher,writer,reviewer"
--validate-links
undefinedMetrics & Reporting
指标与报告
PR Swarm Analytics
PR集群分析
bash
undefinedbash
undefinedGenerate PR swarm report
生成PR集群报告
npx ruv-swarm github pr-report 123
--metrics "completion-time,agent-efficiency,token-usage"
--format markdown
--metrics "completion-time,agent-efficiency,token-usage"
--format markdown
undefinednpx ruv-swarm github pr-report 123
--metrics "completion-time,agent-efficiency,token-usage"
--format markdown
--metrics "completion-time,agent-efficiency,token-usage"
--format markdown
undefinedDashboard Integration
仪表板集成
bash
undefinedbash
undefinedExport to GitHub Insights
导出到GitHub Insights
npx ruv-swarm github export-metrics
--pr 123
--to-insights
--pr 123
--to-insights
undefinednpx ruv-swarm github export-metrics
--pr 123
--to-insights
--pr 123
--to-insights
undefinedSecurity Considerations
安全注意事项
- Token Permissions: Ensure GitHub tokens have appropriate scopes
- Command Validation: Validate all PR comments before execution
- Rate Limiting: Implement rate limits for PR operations
- Audit Trail: Log all swarm operations for compliance
- 令牌权限:确保GitHub令牌拥有适当的权限范围
- 命令验证:执行前验证所有PR评论中的命令
- 速率限制:为PR操作实现速率限制
- 审计跟踪:记录所有集群操作以符合合规要求
Integration with Claude Code
与Claude Code的集成
When using with Claude Code:
- Claude Code reads PR diff and context
- Swarm coordinates approach based on PR type
- Agents work in parallel on different aspects
- Progress updates posted to PR automatically
- Final review performed before marking ready
使用Claude Code时:
- Claude Code读取PR差异和上下文
- 集群根据PR类型协调工作方式
- 各Agent并行处理不同方面的任务
- 进度更新自动发布到PR
- 标记为就绪前执行最终审查
Advanced Swarm PR Coordination
高级Swarm PR协同
Multi-Agent PR Analysis
多Agent PR分析
bash
undefinedbash
undefinedInitialize PR-specific swarm with intelligent topology selection
初始化针对PR的集群并智能选择拓扑结构
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" }
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
存储PR上下文用于集群协同
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"
}
}
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
协调全面的PR工作流
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"]
}
undefinedmcp__claude-flow__task_orchestrate {
task: "Execute multi-agent PR review and validation workflow",
strategy: "parallel",
priority: "high",
dependencies: ["diff_analysis", "test_validation", "security_review"]
}
undefinedSwarm-Coordinated PR Lifecycle
集群协同的PR生命周期
javascript
// 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
}
});
};javascript
// 前置钩子:PR初始化与集群设置
const prPreHook = async (prData) => {
// 分析PR复杂度以配置最优集群
const complexity = await analyzePRComplexity(prData);
const topology = complexity > 7 ? "hierarchical" : "mesh";
// 使用PR专属配置初始化集群
await mcp__claude_flow__swarm_init({ topology, maxAgents: 8 });
// 存储完整的PR上下文
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)
}
});
// 协调初始Agent同步
await mcp__claude_flow__coordination_sync({ swarmId: "current" });
};
// 后置钩子:PR完成与指标收集
const prPostHook = async (results) => {
// 生成全面的PR完成报告
const report = await generatePRReport(results);
// 用最终集群分析结果更新PR
await updatePRWithResults(report);
// 存储完成指标用于后续优化
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
}
});
};Intelligent PR Merge Coordination
智能PR合并协同
bash
undefinedbash
undefinedCoordinate merge decision with swarm consensus
结合集群共识协调合并决策
mcp__claude-flow__coordination_sync { swarmId: "pr-review-swarm" }
mcp__claude-flow__coordination_sync { swarmId: "pr-review-swarm" }
Analyze merge readiness with multiple agents
多Agent分析合并就绪状态
mcp__claude-flow__task_orchestrate {
task: "Evaluate PR merge readiness with comprehensive validation",
strategy: "sequential",
priority: "critical"
}
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
}
}
See also: [swarm-issue.md](.$swarm-issue.md), [sync-coordinator.md](.$sync-coordinator.md), [workflow-automation.md](.$workflow-automation.md)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](./swarm-issue.md), [sync-coordinator.md](./sync-coordinator.md), [workflow-automation.md](./workflow-automation.md)