alchaincyf/huashu-skills / huashu-agent-swarm
huashu-agent-swarm
Verified多Agent蜂群并行协作,纯git自组织,适合大型项目开发。当用户提到"蜂群模式"、"多agent"、"并行开发"、"agent swarm"时使用。
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 3.6 KB |
| references/agent-prompt-template.md | markdown | 4.1 KB |
| references/carlini-lessons.md | markdown | 3.3 KB |
| scripts/agent_loop.shexecutable | script | 2.8 KB |
| scripts/dashboard.pyexecutable | script | 20.6 KB |
| scripts/send_input.shexecutable | script | 1.0 KB |
| scripts/setup_project.shexecutable | script | 2.7 KB |
| scripts/start_swarm.shexecutable | script | 3.3 KB |
| scripts/status.shexecutable | script | 2.7 KB |
| scripts/stop_swarm.shexecutable | script | 2.3 KB |
scripts/start_swarm.sh
View on GitHub#!/bin/bash
# start_swarm.sh - 启动Agent蜂群(tmux多pane)
# 用法: bash start_swarm.sh [agent数量] [项目目录]
# 示例: bash start_swarm.sh 8 /path/to/project
set -e
NUM_AGENTS="${1:-8}"
PROJECT_DIR="${2:-.}"
PROJECT_DIR="$(cd "$PROJECT_DIR" && pwd)"
SKILL_DIR="$(cd "$(dirname "$0")/.." && pwd)"
PROJECT_NAME="$(basename "$PROJECT_DIR")"
SESSION="swarm-${PROJECT_NAME}"
LOG_DIR="${PROJECT_DIR}/agent_logs"
# ===== 前置检查 =====
if ! command -v tmux >/dev/null 2>&1; then
echo "错误: 请先安装tmux"
echo " macOS: brew install tmux"
echo " Ubuntu: sudo apt install tmux"
exit 1
fi
if ! command -v claude >/dev/null 2>&1; then
echo "错误: 请先安装 claude CLI"
exit 1
fi
if [ ! -f "$PROJECT_DIR/AGENT_PROMPT.md" ]; then
echo "错误: 找不到 AGENT_PROMPT.md"
echo "请先运行: bash $SKILL_DIR/scripts/setup_project.sh $PROJECT_DIR"
exit 1
fi
if [ ! -d "$PROJECT_DIR/.git" ]; then
echo "错误: $PROJECT_DIR 不是git仓库"
exit 1
fi
echo "=== 启动蜂群模式 ==="
echo "项目: $PROJECT_DIR"
echo "Agent数量: $NUM_AGENTS"
echo "tmux session: $SESSION"
echo ""
# ===== 创建日志目录 =====
mkdir -p "$LOG_DIR"
# ===== 确保main分支存在且有至少一个commit =====
cd "$PROJECT_DIR"
MAIN_BRANCH=$(git branch --show-current)
# ===== 创建 git worktrees =====
echo "创建 git worktrees..."
for i in $(seq 1 "$NUM_AGENTS"); do
AGENT_DIR="${PROJECT_DIR}-agent-${i}"
BRANCH_NAME="agent-${i}-work"
if [ -d "$AGENT_DIR" ]; then
echo " Agent-${i}: worktree已存在,跳过"
else
# 创建agent专用分支的worktree
git worktree add "$AGENT_DIR" -b "$BRANCH_NAME" "$MAIN_BRANCH" 2>/dev/null || \
git worktree add "$AGENT_DIR" "$BRANCH_NAME" 2>/dev/null || {
echo " Agent-${i}: 创建worktree失败,尝试清理后重试..."
git worktree prune
git branch -D "$BRANCH_NAME" 2>/dev/null || true
git worktree add "$AGENT_DIR" -b "$BRANCH_NAME" "$MAIN_BRANCH"
}
echo " Agent-${i}: worktree 创建完成 → $AGENT_DIR"
fi
# 同步AGENT_PROMPT.md和TASKS.md到worktree
cp "$PROJECT_DIR/AGENT_PROMPT.md" "$AGENT_DIR/AGENT_PROMPT.md"
[ -f "$PROJECT_DIR/TASKS.md" ] && cp "$PROJECT_DIR/TASKS.md" "$AGENT_DIR/TASKS.md"
done
echo ""
# ===== 创建tmux session =====
echo "创建 tmux session..."
tmux kill-session -t "$SESSION" 2>/dev/null || true
# 创建session并启动第一个agent
AGENT_DIR="${PROJECT_DIR}-agent-1"
tmux new-session -d -s "$SESSION" -x 200 -y 50 \
"AGENT_ID=1 WORK_DIR='$AGENT_DIR' LOG_DIR='$LOG_DIR' bash '$SKILL_DIR/scripts/agent_loop.sh'; read"
# 为后续agent创建新pane
for i in $(seq 2 "$NUM_AGENTS"); do
AGENT_DIR="${PROJECT_DIR}-agent-${i}"
tmux split-window -t "$SESSION" \
"AGENT_ID=$i WORK_DIR='$AGENT_DIR' LOG_DIR='$LOG_DIR' bash '$SKILL_DIR/scripts/agent_loop.sh'; read"
# 重新排列布局
tmux select-layout -t "$SESSION" tiled
done
echo ""
echo "=== 蜂群已启动!==="
echo ""
echo "查看agent工作:"
echo " tmux attach -t $SESSION"
echo ""
echo "查看状态:"
echo " bash $SKILL_DIR/scripts/status.sh $PROJECT_DIR"
echo ""
echo "停止所有agent:"
echo " bash $SKILL_DIR/scripts/stop_swarm.sh $PROJECT_DIR"
echo ""
# 自动attach到tmux session
tmux attach -t "$SESSION"
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |