Loading...
Loading...
Generate and manage tmux sessions for parallel sub-coordinators using git worktrees. Used when all sections are ready for execution.
npx skill4agent add blueif16/amazing-claude-code-plugins execution-managerdocs/prds/reddit-bot/sections/auth# 读取 meta.yaml 获取项目信息
project_name=$(yq '.project' meta.yaml)
sections=$(yq '.sections | keys' meta.yaml)
# 对每个部分:
for section in $sections; do
branch="${project_name}/${section}"
section_path="docs/prds/${project_name}/sections/${section}"
# 创建 worktree
git worktree add ../worktrees/${section} -b ${branch}
# 创建 tmux 会话并初始化子协调器
tmux new-session -d -s ${section} -c ../worktrees/${section} \
claude "You are Sub Coordinator for ${section}. Read fix-engine skill. Task files in .task/ directory. Begin."
# 更新 meta.yaml 状态
yq -i ".sections.${section}.status = \"in_progress\"" meta.yaml
donegit worktree list | grep {section-id}-c ../worktrees/{section-id}# 监控状态变量
all_done=false
check_interval=30 # 秒
while [ "$all_done" = false ]; do
echo "检查所有部分状态..."
completed_count=0
blocked_count=0
in_progress_count=0
total_sections=$(yq '.sections | length' meta.yaml)
# 检查每个部分的状态
for section in $(yq '.sections | keys | .[]' meta.yaml); do
status=$(yq ".sections.${section}.status" meta.yaml)
case "$status" in
completed)
((completed_count++))
echo "✅ $section: COMPLETE"
;;
blocked)
((blocked_count++))
echo "❌ $section: BLOCKED"
;;
in_progress)
((in_progress_count++))
# 检查 tmux 会话是否还在运行
if ! tmux has-session -t "$section" 2>/dev/null; then
echo "⚠️ $section: tmux 会话异常退出"
yq -i ".sections.${section}.status = \"blocked\"" meta.yaml
else
# 检查最近输出
last_output=$(tmux capture-pane -t "$section" -p | tail -20)
echo "🔄 $section: WORKING"
fi
;;
esac
done
# 检查是否所有部分都完成或阻塞
if [ $((completed_count + blocked_count)) -eq $total_sections ]; then
all_done=true
echo ""
echo "所有部分已完成或阻塞,准备合并..."
echo "- 已完成: $completed_count"
echo "- 已阻塞: $blocked_count"
echo ""
# 自动调用 merge-resolver
if [ $completed_count -gt 0 ]; then
echo "调用 merge-resolver 处理已完成的部分..."
# 这里 Claude 会调用 merge-resolver skill
# 人工只需在 merge-resolver 完成后看到最终报告
else
echo "没有已完成的部分可以合并"
echo "所有部分都被阻塞,需要人工干预"
fi
else
echo ""
echo "状态摘要: $completed_count 完成, $in_progress_count 进行中, $blocked_count 阻塞"
echo "等待 ${check_interval} 秒后再次检查..."
sleep $check_interval
fi
donetmux send-keystmux send-keys -t {section-id} "状态更新?" Entertmux send-keys -t {section-id} "额外上下文:..." Entercompletedblockedcompletedcompletedblockedin_progresstmux kill-session -t {section-id}
git worktree remove ../worktrees/{section-id}
git branch -d {section-id} # 仅在合并后# 列出所有工作会话
tmux ls
# 查看工作输出(最后50行,非阻塞)
tmux capture-pane -t {section-id} -p | tail -50
# 向工作会话发送后续指令
tmux send-keys -t {section-id} "Also handle edge case X" Enter
# 附加到会话实时观察(Ctrl+B D 分离)
tmux attach -t {section-id}
# 终止卡住的工作会话
tmux kill-session -t {section-id}# 创建带新分支的 worktree
git worktree add ../worktrees/{section-id} -b {section-id}
# 列出所有 worktrees
git worktree list
# 删除 worktree(合并后)
git worktree remove ../worktrees/{section-id}
# 清理过期的 worktree 引用
git worktree prune
# 从主分支合并完成的部分
git merge {section-id} --no-ff -m "Merge {section-id}"