This repository has been archived on 2026-08-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
openclaw/skills/dev-workflow/prompts/parallel-development.md
T

5.5 KiB

并行开发阶段 Prompt 模板

目标

按波次启动子代理执行开发任务,同波内并行执行,波间串行。

开发子代理 Prompt

你是一个专业的开发者。请实现以下任务。

## 任务信息

**任务ID**: {task_id}
**任务名称**: {task_name}

## 任务描述
{task_description}

## 输入
{task_inputs}

## 输出要求
{task_outputs}

## 实现要点
{implementation_points}

## 验收标准
{acceptance_criteria}

## 项目上下文

### 技术栈
{tech_stack}

### 文件结构
{file_structure}

### 相关文件
{related_files}

## 开发要求

1. **代码质量**
   - 遵循项目代码规范
   - 添加必要的注释
   - 编写清晰的函数/变量命名

2. **测试**
   - 为新代码编写单元测试
   - 测试文件放在 tests/ 目录

3. **文档**
   - 更新相关文档
   - 添加必要的 docstring

4. **提交**
   - 完成后说明修改了哪些文件
   - 列出主要改动点

## 输出格式

完成后请输出:

```markdown
# 任务完成报告

## 任务: {task_id} - {task_name}

## 修改的文件
- {file_1}: [改动说明]
- {file_2}: [改动说明]

## 主要实现
1. [实现点1]
2. [实现点2]

## 测试
- 新增测试: {test_files}
- 测试通过: 是/否

## 注意事项
- [需要注意的点]

## 遗留问题
- [如有未完成的部分]

请开始开发。


## 波次执行逻辑

```python
import subprocess
import json
from concurrent.futures import ThreadPoolExecutor, as_completed

def execute_wave(wave_num: int, tasks: list, spec: dict):
    """执行一个波次的开发任务"""
    
    print(f"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
    print(f" WAVE {wave_num} - 并行执行 {len(tasks)} 个任务")
    print(f"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
    
    results = []
    
    with ThreadPoolExecutor(max_workers=len(tasks)) as executor:
        futures = {}
        
        for task_id in tasks:
            task = spec["tasks"][task_id]
            
            # 构建子代理 prompt
            prompt = build_developer_prompt(task, spec)
            
            # 提交子代理任务
            future = executor.submit(
                spawn_developer_agent,
                task_id=task_id,
                prompt=prompt
            )
            futures[future] = task_id
        
        # 收集结果
        for future in as_completed(futures):
            task_id = futures[future]
            try:
                result = future.result()
                results.append({
                    "task_id": task_id,
                    "status": "success",
                    "output": result
                })
                print(f"  ✓ {task_id} 完成")
            except Exception as e:
                results.append({
                    "task_id": task_id,
                    "status": "failed",
                    "error": str(e)
                })
                print(f"  ✗ {task_id} 失败: {e}")
    
    return results


def execute_all_waves(execution_plan: dict, spec: dict):
    """执行所有波次"""
    
    all_results = {}
    
    for wave_num in sorted(execution_plan.keys()):
        wave_key = f"wave_{wave_num}"
        tasks = execution_plan[wave_key]
        
        wave_results = execute_wave(wave_num, tasks, spec)
        all_results[wave_key] = wave_results
        
        # 检查是否有失败
        failed = [r for r in wave_results if r["status"] == "failed"]
        if failed:
            print(f"\n⚠️ Wave {wave_num} 有 {len(failed)} 个任务失败")
            # 可以选择重试或停止
    
    return all_results

子代理启动

def spawn_developer_agent(task_id: str, prompt: str) -> str:
    """启动开发子代理"""
    
    # 使用 sessions_spawn 启动子代理
    result = subprocess.run([
        "openclaw", "agent", "spawn",
        "--task", prompt,
        "--cwd", get_project_root(),
        "--timeout", "1800",  # 30分钟超时
        "--output", f".planning/dev-workflow/development/{task_id}.json"
    ], capture_output=True, text=True)
    
    if result.returncode != 0:
        raise Exception(f"子代理启动失败: {result.stderr}")
    
    return result.stdout

进度监控

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 DEV-WORKFLOW ► 开发进度
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Wave 1: ✓✓✓ (3/3 完成)
Wave 2: ✓→○ (1/3 进行中)
Wave 3: ○○ (0/2 等待中)

总进度: 4/8 任务 (50%)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

状态更新

{
  "phases": {
    "6": {
      "status": "completed",
      "waves": {
        "wave_1": {"status": "completed", "tasks": ["TASK-001", "TASK-002", "TASK-003"]},
        "wave_2": {"status": "completed", "tasks": ["TASK-004", "TASK-005"]},
        "wave_3": {"status": "completed", "tasks": ["TASK-006", "TASK-007", "TASK-008"]}
      },
      "total_tasks": 8,
      "completed_tasks": 8
    }
  }
}