mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-10 02:24:35 +08:00
restore: 恢复 ccw-loop-b skill
This commit is contained in:
301
.codex/skills/ccw-loop-b/README.md
Normal file
301
.codex/skills/ccw-loop-b/README.md
Normal file
@@ -0,0 +1,301 @@
|
|||||||
|
# CCW Loop-B: Hybrid Orchestrator Pattern
|
||||||
|
|
||||||
|
Iterative development workflow using coordinator + specialized workers architecture.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
CCW Loop-B implements a flexible orchestration pattern:
|
||||||
|
- **Coordinator**: Main agent managing state, user interaction, worker scheduling
|
||||||
|
- **Workers**: Specialized agents (init, develop, debug, validate, complete)
|
||||||
|
- **Modes**: Interactive / Auto / Parallel execution
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
```
|
||||||
|
Coordinator (Main Agent)
|
||||||
|
|
|
||||||
|
+-- Spawns Workers
|
||||||
|
| - ccw-loop-b-init.md
|
||||||
|
| - ccw-loop-b-develop.md
|
||||||
|
| - ccw-loop-b-debug.md
|
||||||
|
| - ccw-loop-b-validate.md
|
||||||
|
| - ccw-loop-b-complete.md
|
||||||
|
|
|
||||||
|
+-- Batch Wait (parallel mode)
|
||||||
|
+-- Sequential Wait (auto/interactive)
|
||||||
|
+-- State Management
|
||||||
|
+-- User Interaction
|
||||||
|
```
|
||||||
|
|
||||||
|
## Subagent API
|
||||||
|
|
||||||
|
Core APIs for worker orchestration:
|
||||||
|
|
||||||
|
| API | 作用 |
|
||||||
|
|-----|------|
|
||||||
|
| `spawn_agent({ message })` | 创建 worker,返回 `agent_id` |
|
||||||
|
| `wait({ ids, timeout_ms })` | 等待结果(唯一取结果入口) |
|
||||||
|
| `send_input({ id, message })` | 继续交互 |
|
||||||
|
| `close_agent({ id })` | 关闭回收 |
|
||||||
|
|
||||||
|
**可用模式**: 单 agent 深度交互 / 多 agent 并行 / 混合模式
|
||||||
|
|
||||||
|
## Execution Modes
|
||||||
|
|
||||||
|
### Interactive Mode (default)
|
||||||
|
|
||||||
|
Coordinator displays menu, user selects action, spawns corresponding worker.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
/ccw-loop-b TASK="Implement feature X"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Flow**:
|
||||||
|
1. Init: Parse task, create breakdown
|
||||||
|
2. Menu: Show options to user
|
||||||
|
3. User selects action (develop/debug/validate)
|
||||||
|
4. Spawn worker for selected action
|
||||||
|
5. Wait for result
|
||||||
|
6. Display result, back to menu
|
||||||
|
7. Repeat until complete
|
||||||
|
|
||||||
|
### Auto Mode
|
||||||
|
|
||||||
|
Automated sequential execution following predefined workflow.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
/ccw-loop-b --mode=auto TASK="Fix bug Y"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Flow**:
|
||||||
|
1. Init → 2. Develop → 3. Validate → 4. Complete
|
||||||
|
|
||||||
|
If issues found: loop back to Debug → Develop → Validate
|
||||||
|
|
||||||
|
### Parallel Mode
|
||||||
|
|
||||||
|
Spawn multiple workers simultaneously, batch wait for results.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
/ccw-loop-b --mode=parallel TASK="Analyze module Z"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Flow**:
|
||||||
|
1. Init: Create analysis plan
|
||||||
|
2. Spawn workers in parallel: [develop, debug, validate]
|
||||||
|
3. Batch wait: `wait({ ids: [w1, w2, w3] })`
|
||||||
|
4. Merge results
|
||||||
|
5. Coordinator decides next action
|
||||||
|
6. Complete
|
||||||
|
|
||||||
|
## Session Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
.workflow/.loop/
|
||||||
|
+-- {loopId}.json # Master state
|
||||||
|
+-- {loopId}.workers/ # Worker outputs
|
||||||
|
| +-- init.output.json
|
||||||
|
| +-- develop.output.json
|
||||||
|
| +-- debug.output.json
|
||||||
|
| +-- validate.output.json
|
||||||
|
| +-- complete.output.json
|
||||||
|
+-- {loopId}.progress/ # Human-readable logs
|
||||||
|
+-- develop.md
|
||||||
|
+-- debug.md
|
||||||
|
+-- validate.md
|
||||||
|
+-- summary.md
|
||||||
|
```
|
||||||
|
|
||||||
|
## Worker Responsibilities
|
||||||
|
|
||||||
|
| Worker | Role | Specialization |
|
||||||
|
|--------|------|----------------|
|
||||||
|
| **init** | Session initialization | Task parsing, breakdown, planning |
|
||||||
|
| **develop** | Code implementation | File operations, pattern matching, incremental development |
|
||||||
|
| **debug** | Problem diagnosis | Root cause analysis, hypothesis testing, fix recommendations |
|
||||||
|
| **validate** | Testing & verification | Test execution, coverage analysis, quality gates |
|
||||||
|
| **complete** | Session finalization | Summary generation, commit preparation, cleanup |
|
||||||
|
|
||||||
|
## Usage Examples
|
||||||
|
|
||||||
|
### Example 1: Simple Feature Implementation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
/ccw-loop-b TASK="Add user logout function"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Auto flow**:
|
||||||
|
- Init: Parse requirements
|
||||||
|
- Develop: Implement logout in `src/auth.ts`
|
||||||
|
- Validate: Run tests
|
||||||
|
- Complete: Generate commit message
|
||||||
|
|
||||||
|
### Example 2: Bug Investigation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
/ccw-loop-b TASK="Fix memory leak in WebSocket handler"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Interactive flow**:
|
||||||
|
1. Init: Parse issue
|
||||||
|
2. User selects "debug" → Spawn debug worker
|
||||||
|
3. Debug: Root cause analysis → recommends fix
|
||||||
|
4. User selects "develop" → Apply fix
|
||||||
|
5. User selects "validate" → Verify fix works
|
||||||
|
6. User selects "complete" → Generate summary
|
||||||
|
|
||||||
|
### Example 3: Comprehensive Analysis
|
||||||
|
|
||||||
|
```bash
|
||||||
|
/ccw-loop-b --mode=parallel TASK="Analyze payment module for improvements"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Parallel flow**:
|
||||||
|
- Spawn [develop, debug, validate] workers simultaneously
|
||||||
|
- Develop: Analyze code quality and patterns
|
||||||
|
- Debug: Identify potential issues
|
||||||
|
- Validate: Check test coverage
|
||||||
|
- Wait for all three to complete
|
||||||
|
- Merge findings into comprehensive report
|
||||||
|
|
||||||
|
### Example 4: Resume Existing Loop
|
||||||
|
|
||||||
|
```bash
|
||||||
|
/ccw-loop-b --loop-id=loop-b-20260122-abc123
|
||||||
|
```
|
||||||
|
|
||||||
|
Continues from previous state, respects status (running/paused).
|
||||||
|
|
||||||
|
## Key Features
|
||||||
|
|
||||||
|
### 1. Worker Specialization
|
||||||
|
|
||||||
|
Each worker focuses on one domain:
|
||||||
|
- **No overlap**: Clear boundaries between workers
|
||||||
|
- **Reusable**: Same worker for different tasks
|
||||||
|
- **Composable**: Combine workers for complex workflows
|
||||||
|
|
||||||
|
### 2. Flexible Coordination
|
||||||
|
|
||||||
|
Coordinator adapts to mode:
|
||||||
|
- **Interactive**: Menu-driven, user controls flow
|
||||||
|
- **Auto**: Predetermined sequence
|
||||||
|
- **Parallel**: Concurrent execution with batch wait
|
||||||
|
|
||||||
|
### 3. State Management
|
||||||
|
|
||||||
|
Unified state at `.workflow/.loop/{loopId}.json`:
|
||||||
|
- **API compatible**: Works with CCW API
|
||||||
|
- **Extension fields**: Skill-specific data in `skill_state`
|
||||||
|
- **Worker outputs**: Structured JSON for each action
|
||||||
|
|
||||||
|
### 4. Progress Tracking
|
||||||
|
|
||||||
|
Human-readable logs:
|
||||||
|
- **Per-worker progress**: `{action}.md` files
|
||||||
|
- **Summary**: Consolidated achievements
|
||||||
|
- **Commit-ready**: Formatted commit messages
|
||||||
|
|
||||||
|
## Best Practices
|
||||||
|
|
||||||
|
1. **Start with Init**: Always initialize before execution
|
||||||
|
2. **Use appropriate mode**:
|
||||||
|
- Interactive: Complex tasks needing user decisions
|
||||||
|
- Auto: Well-defined workflows
|
||||||
|
- Parallel: Independent analysis tasks
|
||||||
|
3. **Clean up workers**: `close_agent()` after each worker completes
|
||||||
|
4. **Batch wait wisely**: Use in parallel mode for efficiency
|
||||||
|
5. **Track progress**: Document in progress files
|
||||||
|
6. **Validate often**: After each develop phase
|
||||||
|
|
||||||
|
## Implementation Patterns
|
||||||
|
|
||||||
|
### Pattern 1: Single Worker Deep Interaction
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const workerId = spawn_agent({ message: workerPrompt })
|
||||||
|
const result1 = wait({ ids: [workerId] })
|
||||||
|
|
||||||
|
// Continue with same worker
|
||||||
|
send_input({ id: workerId, message: "Continue with next task" })
|
||||||
|
const result2 = wait({ ids: [workerId] })
|
||||||
|
|
||||||
|
close_agent({ id: workerId })
|
||||||
|
```
|
||||||
|
|
||||||
|
### Pattern 2: Multi-Worker Parallel
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const workers = {
|
||||||
|
develop: spawn_agent({ message: developPrompt }),
|
||||||
|
debug: spawn_agent({ message: debugPrompt }),
|
||||||
|
validate: spawn_agent({ message: validatePrompt })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Batch wait
|
||||||
|
const results = wait({ ids: Object.values(workers), timeout_ms: 900000 })
|
||||||
|
|
||||||
|
// Process all results
|
||||||
|
Object.values(workers).forEach(id => close_agent({ id }))
|
||||||
|
```
|
||||||
|
|
||||||
|
### Pattern 3: Sequential Worker Chain
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const actions = ['init', 'develop', 'validate', 'complete']
|
||||||
|
|
||||||
|
for (const action of actions) {
|
||||||
|
const workerId = spawn_agent({ message: buildPrompt(action) })
|
||||||
|
const result = wait({ ids: [workerId] })
|
||||||
|
|
||||||
|
updateState(action, result)
|
||||||
|
close_agent({ id: workerId })
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Error Handling
|
||||||
|
|
||||||
|
| Error | Recovery |
|
||||||
|
|-------|----------|
|
||||||
|
| Worker timeout | `send_input` request convergence |
|
||||||
|
| Worker fails | Log error, coordinator decides retry strategy |
|
||||||
|
| Partial results | Use completed workers, mark incomplete |
|
||||||
|
| State corruption | Rebuild from progress files |
|
||||||
|
|
||||||
|
## File Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
.codex/skills/ccw-loop-b/
|
||||||
|
+-- SKILL.md # Entry point
|
||||||
|
+-- README.md # This file
|
||||||
|
+-- phases/
|
||||||
|
| +-- state-schema.md # State structure definition
|
||||||
|
+-- specs/
|
||||||
|
+-- action-catalog.md # Action reference
|
||||||
|
|
||||||
|
.codex/agents/
|
||||||
|
+-- ccw-loop-b-init.md # Worker: Init
|
||||||
|
+-- ccw-loop-b-develop.md # Worker: Develop
|
||||||
|
+-- ccw-loop-b-debug.md # Worker: Debug
|
||||||
|
+-- ccw-loop-b-validate.md # Worker: Validate
|
||||||
|
+-- ccw-loop-b-complete.md # Worker: Complete
|
||||||
|
```
|
||||||
|
|
||||||
|
## Comparison: ccw-loop vs ccw-loop-b
|
||||||
|
|
||||||
|
| Aspect | ccw-loop | ccw-loop-b |
|
||||||
|
|--------|----------|------------|
|
||||||
|
| Pattern | Single agent, multi-phase | Coordinator + workers |
|
||||||
|
| Worker model | Single agent handles all | Specialized workers per action |
|
||||||
|
| Parallelization | Sequential only | Supports parallel mode |
|
||||||
|
| Flexibility | Fixed sequence | Mode-based (interactive/auto/parallel) |
|
||||||
|
| Best for | Simple linear workflows | Complex tasks needing specialization |
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
To add new workers:
|
||||||
|
1. Create worker role file in `.codex/agents/`
|
||||||
|
2. Define clear responsibilities
|
||||||
|
3. Update `action-catalog.md`
|
||||||
|
4. Add worker to coordinator spawn logic
|
||||||
|
5. Test integration with existing workers
|
||||||
323
.codex/skills/ccw-loop-b/SKILL.md
Normal file
323
.codex/skills/ccw-loop-b/SKILL.md
Normal file
@@ -0,0 +1,323 @@
|
|||||||
|
---
|
||||||
|
name: CCW Loop-B
|
||||||
|
description: Hybrid orchestrator pattern for iterative development. Coordinator + specialized workers with batch wait support. Triggers on "ccw-loop-b".
|
||||||
|
argument-hint: TASK="<task description>" [--loop-id=<id>] [--mode=<interactive|auto|parallel>]
|
||||||
|
---
|
||||||
|
|
||||||
|
# CCW Loop-B - Hybrid Orchestrator Pattern
|
||||||
|
|
||||||
|
协调器 + 专用 worker 的迭代开发工作流。支持单 agent 深度交互、多 agent 并行、混合模式灵活切换。
|
||||||
|
|
||||||
|
## Arguments
|
||||||
|
|
||||||
|
| Arg | Required | Description |
|
||||||
|
|-----|----------|-------------|
|
||||||
|
| TASK | No | Task description (for new loop) |
|
||||||
|
| --loop-id | No | Existing loop ID to continue |
|
||||||
|
| --mode | No | `interactive` (default) / `auto` / `parallel` |
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
```
|
||||||
|
+------------------------------------------------------------+
|
||||||
|
| Main Coordinator |
|
||||||
|
| 职责: 状态管理 + worker 调度 + 结果汇聚 + 用户交互 |
|
||||||
|
+------------------------------------------------------------+
|
||||||
|
|
|
||||||
|
+--------------------+--------------------+
|
||||||
|
| | |
|
||||||
|
v v v
|
||||||
|
+----------------+ +----------------+ +----------------+
|
||||||
|
| Worker-Develop | | Worker-Debug | | Worker-Validate|
|
||||||
|
| 专注: 代码实现 | | 专注: 问题诊断 | | 专注: 测试验证 |
|
||||||
|
+----------------+ +----------------+ +----------------+
|
||||||
|
```
|
||||||
|
|
||||||
|
## Execution Modes
|
||||||
|
|
||||||
|
### Mode: Interactive (default)
|
||||||
|
|
||||||
|
协调器展示菜单,用户选择 action,spawn 对应 worker 执行。
|
||||||
|
|
||||||
|
```
|
||||||
|
Coordinator -> Show menu -> User selects -> spawn worker -> wait -> Display result -> Loop
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mode: Auto
|
||||||
|
|
||||||
|
自动按预设顺序执行,worker 完成后自动切换到下一阶段。
|
||||||
|
|
||||||
|
```
|
||||||
|
Init -> Develop -> [if issues] Debug -> Validate -> [if fail] Loop back -> Complete
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mode: Parallel
|
||||||
|
|
||||||
|
并行 spawn 多个 worker 分析不同维度,batch wait 汇聚结果。
|
||||||
|
|
||||||
|
```
|
||||||
|
Coordinator -> spawn [develop, debug, validate] in parallel -> wait({ ids: all }) -> Merge -> Decide
|
||||||
|
```
|
||||||
|
|
||||||
|
## Session Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
.workflow/.loop/
|
||||||
|
+-- {loopId}.json # Master state
|
||||||
|
+-- {loopId}.workers/ # Worker outputs
|
||||||
|
| +-- develop.output.json
|
||||||
|
| +-- debug.output.json
|
||||||
|
| +-- validate.output.json
|
||||||
|
+-- {loopId}.progress/ # Human-readable progress
|
||||||
|
+-- develop.md
|
||||||
|
+-- debug.md
|
||||||
|
+-- validate.md
|
||||||
|
+-- summary.md
|
||||||
|
```
|
||||||
|
|
||||||
|
## Subagent API
|
||||||
|
|
||||||
|
| API | 作用 |
|
||||||
|
|-----|------|
|
||||||
|
| `spawn_agent({ message })` | 创建 agent,返回 `agent_id` |
|
||||||
|
| `wait({ ids, timeout_ms })` | 等待结果(唯一取结果入口) |
|
||||||
|
| `send_input({ id, message })` | 继续交互 |
|
||||||
|
| `close_agent({ id })` | 关闭回收 |
|
||||||
|
|
||||||
|
## Implementation
|
||||||
|
|
||||||
|
### Coordinator Logic
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// ==================== HYBRID ORCHESTRATOR ====================
|
||||||
|
|
||||||
|
// 1. Initialize
|
||||||
|
const loopId = args['--loop-id'] || generateLoopId()
|
||||||
|
const mode = args['--mode'] || 'interactive'
|
||||||
|
let state = readOrCreateState(loopId, taskDescription)
|
||||||
|
|
||||||
|
// 2. Mode selection
|
||||||
|
switch (mode) {
|
||||||
|
case 'interactive':
|
||||||
|
await runInteractiveMode(loopId, state)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'auto':
|
||||||
|
await runAutoMode(loopId, state)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'parallel':
|
||||||
|
await runParallelMode(loopId, state)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Interactive Mode (单 agent 交互或按需 spawn worker)
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
async function runInteractiveMode(loopId, state) {
|
||||||
|
while (state.status === 'running') {
|
||||||
|
// Show menu, get user choice
|
||||||
|
const action = await showMenuAndGetChoice(state)
|
||||||
|
|
||||||
|
if (action === 'exit') break
|
||||||
|
|
||||||
|
// Spawn specialized worker for the action
|
||||||
|
const workerId = spawn_agent({
|
||||||
|
message: buildWorkerPrompt(action, loopId, state)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Wait for worker completion
|
||||||
|
const result = wait({ ids: [workerId], timeout_ms: 600000 })
|
||||||
|
const output = result.status[workerId].completed
|
||||||
|
|
||||||
|
// Update state and display result
|
||||||
|
state = updateState(loopId, action, output)
|
||||||
|
displayResult(output)
|
||||||
|
|
||||||
|
// Cleanup worker
|
||||||
|
close_agent({ id: workerId })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Auto Mode (顺序执行 worker 链)
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
async function runAutoMode(loopId, state) {
|
||||||
|
const actionSequence = ['init', 'develop', 'debug', 'validate', 'complete']
|
||||||
|
let currentIndex = state.skill_state?.action_index || 0
|
||||||
|
|
||||||
|
while (currentIndex < actionSequence.length && state.status === 'running') {
|
||||||
|
const action = actionSequence[currentIndex]
|
||||||
|
|
||||||
|
// Spawn worker
|
||||||
|
const workerId = spawn_agent({
|
||||||
|
message: buildWorkerPrompt(action, loopId, state)
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = wait({ ids: [workerId], timeout_ms: 600000 })
|
||||||
|
const output = result.status[workerId].completed
|
||||||
|
|
||||||
|
// Parse worker result to determine next step
|
||||||
|
const workerResult = parseWorkerResult(output)
|
||||||
|
|
||||||
|
// Update state
|
||||||
|
state = updateState(loopId, action, output)
|
||||||
|
|
||||||
|
close_agent({ id: workerId })
|
||||||
|
|
||||||
|
// Determine next action
|
||||||
|
if (workerResult.needs_loop_back) {
|
||||||
|
// Loop back to develop or debug
|
||||||
|
currentIndex = actionSequence.indexOf(workerResult.loop_back_to)
|
||||||
|
} else if (workerResult.status === 'failed') {
|
||||||
|
// Stop on failure
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
currentIndex++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parallel Mode (批量 spawn + wait)
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
async function runParallelMode(loopId, state) {
|
||||||
|
// Spawn multiple workers in parallel
|
||||||
|
const workers = {
|
||||||
|
develop: spawn_agent({ message: buildWorkerPrompt('develop', loopId, state) }),
|
||||||
|
debug: spawn_agent({ message: buildWorkerPrompt('debug', loopId, state) }),
|
||||||
|
validate: spawn_agent({ message: buildWorkerPrompt('validate', loopId, state) })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Batch wait for all workers
|
||||||
|
const results = wait({
|
||||||
|
ids: Object.values(workers),
|
||||||
|
timeout_ms: 900000 // 15 minutes for all
|
||||||
|
})
|
||||||
|
|
||||||
|
// Collect outputs
|
||||||
|
const outputs = {}
|
||||||
|
for (const [role, workerId] of Object.entries(workers)) {
|
||||||
|
outputs[role] = results.status[workerId].completed
|
||||||
|
close_agent({ id: workerId })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge and analyze results
|
||||||
|
const mergedAnalysis = mergeWorkerOutputs(outputs)
|
||||||
|
|
||||||
|
// Update state with merged results
|
||||||
|
updateState(loopId, 'parallel-analysis', mergedAnalysis)
|
||||||
|
|
||||||
|
// Coordinator decides next action based on merged results
|
||||||
|
const decision = decideNextAction(mergedAnalysis)
|
||||||
|
return decision
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Worker Prompt Builder
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
function buildWorkerPrompt(action, loopId, state) {
|
||||||
|
const workerRoles = {
|
||||||
|
develop: '~/.codex/agents/ccw-loop-b-develop.md',
|
||||||
|
debug: '~/.codex/agents/ccw-loop-b-debug.md',
|
||||||
|
validate: '~/.codex/agents/ccw-loop-b-validate.md',
|
||||||
|
init: '~/.codex/agents/ccw-loop-b-init.md',
|
||||||
|
complete: '~/.codex/agents/ccw-loop-b-complete.md'
|
||||||
|
}
|
||||||
|
|
||||||
|
return `
|
||||||
|
## TASK ASSIGNMENT
|
||||||
|
|
||||||
|
### MANDATORY FIRST STEPS (Agent Execute)
|
||||||
|
1. **Read role definition**: ${workerRoles[action]} (MUST read first)
|
||||||
|
2. Read: .workflow/project-tech.json
|
||||||
|
3. Read: .workflow/project-guidelines.json
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## LOOP CONTEXT
|
||||||
|
|
||||||
|
- **Loop ID**: ${loopId}
|
||||||
|
- **Action**: ${action}
|
||||||
|
- **State File**: .workflow/.loop/${loopId}.json
|
||||||
|
- **Output File**: .workflow/.loop/${loopId}.workers/${action}.output.json
|
||||||
|
- **Progress File**: .workflow/.loop/${loopId}.progress/${action}.md
|
||||||
|
|
||||||
|
## CURRENT STATE
|
||||||
|
|
||||||
|
${JSON.stringify(state, null, 2)}
|
||||||
|
|
||||||
|
## TASK DESCRIPTION
|
||||||
|
|
||||||
|
${state.description}
|
||||||
|
|
||||||
|
## EXPECTED OUTPUT
|
||||||
|
|
||||||
|
\`\`\`
|
||||||
|
WORKER_RESULT:
|
||||||
|
- action: ${action}
|
||||||
|
- status: success | failed | needs_input
|
||||||
|
- summary: <brief summary>
|
||||||
|
- files_changed: [list]
|
||||||
|
- next_suggestion: <suggested next action>
|
||||||
|
- loop_back_to: <action name if needs loop back>
|
||||||
|
|
||||||
|
DETAILED_OUTPUT:
|
||||||
|
<structured output specific to action type>
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
Execute the ${action} action now.
|
||||||
|
`
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Worker Roles
|
||||||
|
|
||||||
|
| Worker | Role File | 专注领域 |
|
||||||
|
|--------|-----------|----------|
|
||||||
|
| init | ccw-loop-b-init.md | 会话初始化、任务解析 |
|
||||||
|
| develop | ccw-loop-b-develop.md | 代码实现、重构 |
|
||||||
|
| debug | ccw-loop-b-debug.md | 问题诊断、假设验证 |
|
||||||
|
| validate | ccw-loop-b-validate.md | 测试执行、覆盖率 |
|
||||||
|
| complete | ccw-loop-b-complete.md | 总结收尾 |
|
||||||
|
|
||||||
|
## State Schema
|
||||||
|
|
||||||
|
See [phases/state-schema.md](phases/state-schema.md)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Interactive mode (default)
|
||||||
|
/ccw-loop-b TASK="Implement user authentication"
|
||||||
|
|
||||||
|
# Auto mode
|
||||||
|
/ccw-loop-b --mode=auto TASK="Fix login bug"
|
||||||
|
|
||||||
|
# Parallel analysis mode
|
||||||
|
/ccw-loop-b --mode=parallel TASK="Analyze and improve payment module"
|
||||||
|
|
||||||
|
# Resume existing loop
|
||||||
|
/ccw-loop-b --loop-id=loop-b-20260122-abc123
|
||||||
|
```
|
||||||
|
|
||||||
|
## Error Handling
|
||||||
|
|
||||||
|
| Situation | Action |
|
||||||
|
|-----------|--------|
|
||||||
|
| Worker timeout | send_input 请求收敛 |
|
||||||
|
| Worker failed | Log error, 协调器决策是否重试 |
|
||||||
|
| Batch wait partial timeout | 使用已完成结果继续 |
|
||||||
|
| State corrupted | 从 progress 文件重建 |
|
||||||
|
|
||||||
|
## Best Practices
|
||||||
|
|
||||||
|
1. **协调器保持轻量**: 只做调度和状态管理,具体工作交给 worker
|
||||||
|
2. **Worker 职责单一**: 每个 worker 专注一个领域
|
||||||
|
3. **结果标准化**: Worker 输出遵循统一 WORKER_RESULT 格式
|
||||||
|
4. **灵活模式切换**: 根据任务复杂度选择合适模式
|
||||||
|
5. **及时清理**: Worker 完成后 close_agent 释放资源
|
||||||
257
.codex/skills/ccw-loop-b/phases/orchestrator.md
Normal file
257
.codex/skills/ccw-loop-b/phases/orchestrator.md
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
# Orchestrator (Hybrid Pattern)
|
||||||
|
|
||||||
|
协调器负责状态管理、worker 调度、结果汇聚。
|
||||||
|
|
||||||
|
## Role
|
||||||
|
|
||||||
|
```
|
||||||
|
Read state -> Select mode -> Spawn workers -> Wait results -> Merge -> Update state -> Loop/Exit
|
||||||
|
```
|
||||||
|
|
||||||
|
## State Management
|
||||||
|
|
||||||
|
### Read State
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
function readState(loopId) {
|
||||||
|
const stateFile = `.workflow/.loop/${loopId}.json`
|
||||||
|
return fs.existsSync(stateFile)
|
||||||
|
? JSON.parse(Read(stateFile))
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Create State
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
function createState(loopId, taskDescription, mode) {
|
||||||
|
const now = new Date().toISOString()
|
||||||
|
|
||||||
|
return {
|
||||||
|
loop_id: loopId,
|
||||||
|
title: taskDescription.substring(0, 100),
|
||||||
|
description: taskDescription,
|
||||||
|
mode: mode,
|
||||||
|
status: 'running',
|
||||||
|
current_iteration: 0,
|
||||||
|
max_iterations: 10,
|
||||||
|
created_at: now,
|
||||||
|
updated_at: now,
|
||||||
|
skill_state: {
|
||||||
|
phase: 'init',
|
||||||
|
action_index: 0,
|
||||||
|
workers_completed: [],
|
||||||
|
parallel_results: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Mode Handlers
|
||||||
|
|
||||||
|
### Interactive Mode
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
async function runInteractiveMode(loopId, state) {
|
||||||
|
while (state.status === 'running') {
|
||||||
|
// 1. Show menu
|
||||||
|
const action = await showMenu(state)
|
||||||
|
if (action === 'exit') break
|
||||||
|
|
||||||
|
// 2. Spawn worker
|
||||||
|
const worker = spawn_agent({
|
||||||
|
message: buildWorkerPrompt(action, loopId, state)
|
||||||
|
})
|
||||||
|
|
||||||
|
// 3. Wait for result
|
||||||
|
const result = wait({ ids: [worker], timeout_ms: 600000 })
|
||||||
|
|
||||||
|
// 4. Handle timeout
|
||||||
|
if (result.timed_out) {
|
||||||
|
send_input({ id: worker, message: 'Please converge and output WORKER_RESULT' })
|
||||||
|
const retryResult = wait({ ids: [worker], timeout_ms: 300000 })
|
||||||
|
if (retryResult.timed_out) {
|
||||||
|
console.log('Worker timeout, skipping')
|
||||||
|
close_agent({ id: worker })
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. Process output
|
||||||
|
const output = result.status[worker].completed
|
||||||
|
state = processWorkerOutput(loopId, action, output, state)
|
||||||
|
|
||||||
|
// 6. Cleanup
|
||||||
|
close_agent({ id: worker })
|
||||||
|
|
||||||
|
// 7. Display result
|
||||||
|
displayResult(output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Auto Mode
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
async function runAutoMode(loopId, state) {
|
||||||
|
const sequence = ['init', 'develop', 'debug', 'validate', 'complete']
|
||||||
|
let idx = state.skill_state?.action_index || 0
|
||||||
|
|
||||||
|
while (idx < sequence.length && state.status === 'running') {
|
||||||
|
const action = sequence[idx]
|
||||||
|
|
||||||
|
// Spawn and wait
|
||||||
|
const worker = spawn_agent({ message: buildWorkerPrompt(action, loopId, state) })
|
||||||
|
const result = wait({ ids: [worker], timeout_ms: 600000 })
|
||||||
|
const output = result.status[worker].completed
|
||||||
|
close_agent({ id: worker })
|
||||||
|
|
||||||
|
// Parse result
|
||||||
|
const workerResult = parseWorkerResult(output)
|
||||||
|
state = processWorkerOutput(loopId, action, output, state)
|
||||||
|
|
||||||
|
// Determine next
|
||||||
|
if (workerResult.loop_back_to) {
|
||||||
|
idx = sequence.indexOf(workerResult.loop_back_to)
|
||||||
|
} else if (workerResult.status === 'failed') {
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
idx++
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update action index
|
||||||
|
state.skill_state.action_index = idx
|
||||||
|
saveState(loopId, state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parallel Mode
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
async function runParallelMode(loopId, state) {
|
||||||
|
// Spawn all workers
|
||||||
|
const workers = {
|
||||||
|
develop: spawn_agent({ message: buildWorkerPrompt('develop', loopId, state) }),
|
||||||
|
debug: spawn_agent({ message: buildWorkerPrompt('debug', loopId, state) }),
|
||||||
|
validate: spawn_agent({ message: buildWorkerPrompt('validate', loopId, state) })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Batch wait
|
||||||
|
const results = wait({
|
||||||
|
ids: Object.values(workers),
|
||||||
|
timeout_ms: 900000
|
||||||
|
})
|
||||||
|
|
||||||
|
// Collect outputs
|
||||||
|
const outputs = {}
|
||||||
|
for (const [role, id] of Object.entries(workers)) {
|
||||||
|
if (results.status[id].completed) {
|
||||||
|
outputs[role] = results.status[id].completed
|
||||||
|
}
|
||||||
|
close_agent({ id })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge analysis
|
||||||
|
state.skill_state.parallel_results = outputs
|
||||||
|
saveState(loopId, state)
|
||||||
|
|
||||||
|
// Coordinator analyzes merged results
|
||||||
|
return analyzeAndDecide(outputs)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Worker Prompt Template
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
function buildWorkerPrompt(action, loopId, state) {
|
||||||
|
const roleFiles = {
|
||||||
|
init: '~/.codex/agents/ccw-loop-b-init.md',
|
||||||
|
develop: '~/.codex/agents/ccw-loop-b-develop.md',
|
||||||
|
debug: '~/.codex/agents/ccw-loop-b-debug.md',
|
||||||
|
validate: '~/.codex/agents/ccw-loop-b-validate.md',
|
||||||
|
complete: '~/.codex/agents/ccw-loop-b-complete.md'
|
||||||
|
}
|
||||||
|
|
||||||
|
return `
|
||||||
|
## TASK ASSIGNMENT
|
||||||
|
|
||||||
|
### MANDATORY FIRST STEPS
|
||||||
|
1. **Read role definition**: ${roleFiles[action]}
|
||||||
|
2. Read: .workflow/project-tech.json
|
||||||
|
3. Read: .workflow/project-guidelines.json
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## CONTEXT
|
||||||
|
- Loop ID: ${loopId}
|
||||||
|
- Action: ${action}
|
||||||
|
- State: ${JSON.stringify(state, null, 2)}
|
||||||
|
|
||||||
|
## TASK
|
||||||
|
${state.description}
|
||||||
|
|
||||||
|
## OUTPUT FORMAT
|
||||||
|
\`\`\`
|
||||||
|
WORKER_RESULT:
|
||||||
|
- action: ${action}
|
||||||
|
- status: success | failed | needs_input
|
||||||
|
- summary: <brief>
|
||||||
|
- files_changed: []
|
||||||
|
- next_suggestion: <action>
|
||||||
|
- loop_back_to: <action or null>
|
||||||
|
|
||||||
|
DETAILED_OUTPUT:
|
||||||
|
<action-specific output>
|
||||||
|
\`\`\`
|
||||||
|
`
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Result Processing
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
function parseWorkerResult(output) {
|
||||||
|
const result = {
|
||||||
|
action: 'unknown',
|
||||||
|
status: 'unknown',
|
||||||
|
summary: '',
|
||||||
|
files_changed: [],
|
||||||
|
next_suggestion: null,
|
||||||
|
loop_back_to: null
|
||||||
|
}
|
||||||
|
|
||||||
|
const match = output.match(/WORKER_RESULT:\s*([\s\S]*?)(?:DETAILED_OUTPUT:|$)/)
|
||||||
|
if (match) {
|
||||||
|
const lines = match[1].split('\n')
|
||||||
|
for (const line of lines) {
|
||||||
|
const m = line.match(/^-\s*(\w+):\s*(.+)$/)
|
||||||
|
if (m) {
|
||||||
|
const [, key, value] = m
|
||||||
|
if (key === 'files_changed') {
|
||||||
|
try { result.files_changed = JSON.parse(value) } catch {}
|
||||||
|
} else {
|
||||||
|
result[key] = value.trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Termination Conditions
|
||||||
|
|
||||||
|
1. User exits (interactive)
|
||||||
|
2. Sequence complete (auto)
|
||||||
|
3. Worker failed with no recovery
|
||||||
|
4. Max iterations reached
|
||||||
|
5. API paused/stopped
|
||||||
|
|
||||||
|
## Best Practices
|
||||||
|
|
||||||
|
1. **Worker 生命周期**: spawn → wait → close,不保留 worker
|
||||||
|
2. **结果持久化**: Worker 输出写入 `.workflow/.loop/{loopId}.workers/`
|
||||||
|
3. **状态同步**: 每次 worker 完成后更新 state
|
||||||
|
4. **超时处理**: send_input 请求收敛,再超时则跳过
|
||||||
181
.codex/skills/ccw-loop-b/phases/state-schema.md
Normal file
181
.codex/skills/ccw-loop-b/phases/state-schema.md
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
# State Schema (CCW Loop-B)
|
||||||
|
|
||||||
|
## Master State Structure
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"loop_id": "loop-b-20260122-abc123",
|
||||||
|
"title": "Implement user authentication",
|
||||||
|
"description": "Full task description here",
|
||||||
|
"mode": "interactive | auto | parallel",
|
||||||
|
"status": "running | paused | completed | failed",
|
||||||
|
"current_iteration": 3,
|
||||||
|
"max_iterations": 10,
|
||||||
|
"created_at": "2026-01-22T10:00:00.000Z",
|
||||||
|
"updated_at": "2026-01-22T10:30:00.000Z",
|
||||||
|
|
||||||
|
"skill_state": {
|
||||||
|
"phase": "develop | debug | validate | complete",
|
||||||
|
"action_index": 2,
|
||||||
|
"workers_completed": ["init", "develop"],
|
||||||
|
"parallel_results": null,
|
||||||
|
"pending_tasks": [],
|
||||||
|
"completed_tasks": [],
|
||||||
|
"findings": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Field Descriptions
|
||||||
|
|
||||||
|
### Core Fields (API Compatible)
|
||||||
|
|
||||||
|
| Field | Type | Description |
|
||||||
|
|-------|------|-------------|
|
||||||
|
| `loop_id` | string | Unique identifier |
|
||||||
|
| `title` | string | Short title (max 100 chars) |
|
||||||
|
| `description` | string | Full task description |
|
||||||
|
| `mode` | enum | Execution mode |
|
||||||
|
| `status` | enum | Current status |
|
||||||
|
| `current_iteration` | number | Iteration counter |
|
||||||
|
| `max_iterations` | number | Safety limit |
|
||||||
|
| `created_at` | ISO string | Creation timestamp |
|
||||||
|
| `updated_at` | ISO string | Last update timestamp |
|
||||||
|
|
||||||
|
### Skill State Fields
|
||||||
|
|
||||||
|
| Field | Type | Description |
|
||||||
|
|-------|------|-------------|
|
||||||
|
| `phase` | enum | Current execution phase |
|
||||||
|
| `action_index` | number | Position in action sequence (auto mode) |
|
||||||
|
| `workers_completed` | array | List of completed worker actions |
|
||||||
|
| `parallel_results` | object | Merged results from parallel mode |
|
||||||
|
| `pending_tasks` | array | Tasks waiting to be executed |
|
||||||
|
| `completed_tasks` | array | Tasks already done |
|
||||||
|
| `findings` | array | Discoveries during execution |
|
||||||
|
|
||||||
|
## Worker Output Structure
|
||||||
|
|
||||||
|
Each worker writes to `.workflow/.loop/{loopId}.workers/{action}.output.json`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"action": "develop",
|
||||||
|
"status": "success",
|
||||||
|
"summary": "Implemented 3 functions",
|
||||||
|
"files_changed": ["src/auth.ts", "src/utils.ts"],
|
||||||
|
"next_suggestion": "validate",
|
||||||
|
"loop_back_to": null,
|
||||||
|
"timestamp": "2026-01-22T10:15:00.000Z",
|
||||||
|
"detailed_output": {
|
||||||
|
"tasks_completed": [
|
||||||
|
{ "id": "T1", "description": "Create auth module" }
|
||||||
|
],
|
||||||
|
"metrics": {
|
||||||
|
"lines_added": 150,
|
||||||
|
"lines_removed": 20
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Progress File Structure
|
||||||
|
|
||||||
|
Human-readable progress in `.workflow/.loop/{loopId}.progress/{action}.md`:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
# Develop Progress
|
||||||
|
|
||||||
|
## Session: loop-b-20260122-abc123
|
||||||
|
|
||||||
|
### Iteration 1 (2026-01-22 10:15)
|
||||||
|
|
||||||
|
**Task**: Implement auth module
|
||||||
|
|
||||||
|
**Changes**:
|
||||||
|
- Created `src/auth.ts` with login/logout functions
|
||||||
|
- Added JWT token handling in `src/utils.ts`
|
||||||
|
|
||||||
|
**Status**: Success
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Iteration 2 (2026-01-22 10:30)
|
||||||
|
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
## Status Transitions
|
||||||
|
|
||||||
|
```
|
||||||
|
+--------+
|
||||||
|
| init |
|
||||||
|
+--------+
|
||||||
|
|
|
||||||
|
v
|
||||||
|
+------> +---------+
|
||||||
|
| | develop |
|
||||||
|
| +---------+
|
||||||
|
| |
|
||||||
|
| +--------+--------+
|
||||||
|
| | |
|
||||||
|
| v v
|
||||||
|
| +-------+ +---------+
|
||||||
|
| | debug |<------| validate|
|
||||||
|
| +-------+ +---------+
|
||||||
|
| | |
|
||||||
|
| +--------+--------+
|
||||||
|
| |
|
||||||
|
| v
|
||||||
|
| [needs fix?]
|
||||||
|
| yes | | no
|
||||||
|
| v v
|
||||||
|
+------------+ +----------+
|
||||||
|
| complete |
|
||||||
|
+----------+
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parallel Results Schema
|
||||||
|
|
||||||
|
When `mode === 'parallel'`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"parallel_results": {
|
||||||
|
"develop": {
|
||||||
|
"status": "success",
|
||||||
|
"summary": "...",
|
||||||
|
"suggestions": []
|
||||||
|
},
|
||||||
|
"debug": {
|
||||||
|
"status": "success",
|
||||||
|
"issues_found": [],
|
||||||
|
"suggestions": []
|
||||||
|
},
|
||||||
|
"validate": {
|
||||||
|
"status": "success",
|
||||||
|
"test_results": {},
|
||||||
|
"coverage": {}
|
||||||
|
},
|
||||||
|
"merged_at": "2026-01-22T10:45:00.000Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Directory Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
.workflow/.loop/
|
||||||
|
+-- loop-b-20260122-abc123.json # Master state
|
||||||
|
+-- loop-b-20260122-abc123.workers/
|
||||||
|
| +-- init.output.json
|
||||||
|
| +-- develop.output.json
|
||||||
|
| +-- debug.output.json
|
||||||
|
| +-- validate.output.json
|
||||||
|
| +-- complete.output.json
|
||||||
|
+-- loop-b-20260122-abc123.progress/
|
||||||
|
+-- develop.md
|
||||||
|
+-- debug.md
|
||||||
|
+-- validate.md
|
||||||
|
+-- summary.md
|
||||||
|
```
|
||||||
383
.codex/skills/ccw-loop-b/specs/action-catalog.md
Normal file
383
.codex/skills/ccw-loop-b/specs/action-catalog.md
Normal file
@@ -0,0 +1,383 @@
|
|||||||
|
# Action Catalog (CCW Loop-B)
|
||||||
|
|
||||||
|
Complete reference of worker actions and their capabilities.
|
||||||
|
|
||||||
|
## Action Matrix
|
||||||
|
|
||||||
|
| Action | Worker Agent | Purpose | Input Requirements | Output |
|
||||||
|
|--------|--------------|---------|-------------------|--------|
|
||||||
|
| init | ccw-loop-b-init.md | Session initialization | Task description | Task breakdown + execution plan |
|
||||||
|
| develop | ccw-loop-b-develop.md | Code implementation | Task list | Code changes + progress update |
|
||||||
|
| debug | ccw-loop-b-debug.md | Problem diagnosis | Issue description | Root cause analysis + fix suggestions |
|
||||||
|
| validate | ccw-loop-b-validate.md | Testing and verification | Files to test | Test results + coverage report |
|
||||||
|
| complete | ccw-loop-b-complete.md | Session finalization | All worker outputs | Summary + commit message |
|
||||||
|
|
||||||
|
## Detailed Action Specifications
|
||||||
|
|
||||||
|
### INIT
|
||||||
|
|
||||||
|
**Purpose**: Parse requirements, create execution plan
|
||||||
|
|
||||||
|
**Preconditions**:
|
||||||
|
- `status === 'running'`
|
||||||
|
- `skill_state === null` (first time)
|
||||||
|
|
||||||
|
**Input**:
|
||||||
|
```
|
||||||
|
- Task description (text)
|
||||||
|
- Project context files
|
||||||
|
```
|
||||||
|
|
||||||
|
**Execution**:
|
||||||
|
1. Read `.workflow/project-tech.json`
|
||||||
|
2. Read `.workflow/project-guidelines.json`
|
||||||
|
3. Parse task into phases
|
||||||
|
4. Create task breakdown
|
||||||
|
5. Generate execution plan
|
||||||
|
|
||||||
|
**Output**:
|
||||||
|
```
|
||||||
|
WORKER_RESULT:
|
||||||
|
- action: init
|
||||||
|
- status: success
|
||||||
|
- summary: "Initialized with 5 tasks"
|
||||||
|
- next_suggestion: develop
|
||||||
|
|
||||||
|
TASK_BREAKDOWN:
|
||||||
|
- T1: Create auth module
|
||||||
|
- T2: Implement JWT utils
|
||||||
|
- T3: Write tests
|
||||||
|
- T4: Validate implementation
|
||||||
|
- T5: Documentation
|
||||||
|
|
||||||
|
EXECUTION_PLAN:
|
||||||
|
1. Develop (T1-T2)
|
||||||
|
2. Validate (T3-T4)
|
||||||
|
3. Complete (T5)
|
||||||
|
```
|
||||||
|
|
||||||
|
**Effects**:
|
||||||
|
- `skill_state.pending_tasks` populated
|
||||||
|
- Progress structure created
|
||||||
|
- Ready for develop phase
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### DEVELOP
|
||||||
|
|
||||||
|
**Purpose**: Implement code, create/modify files
|
||||||
|
|
||||||
|
**Preconditions**:
|
||||||
|
- `skill_state.pending_tasks.length > 0`
|
||||||
|
- `status === 'running'`
|
||||||
|
|
||||||
|
**Input**:
|
||||||
|
```
|
||||||
|
- Task list from state
|
||||||
|
- Project conventions
|
||||||
|
- Existing code patterns
|
||||||
|
```
|
||||||
|
|
||||||
|
**Execution**:
|
||||||
|
1. Load pending tasks
|
||||||
|
2. Find existing patterns
|
||||||
|
3. Implement tasks one by one
|
||||||
|
4. Update progress file
|
||||||
|
5. Mark tasks completed
|
||||||
|
|
||||||
|
**Output**:
|
||||||
|
```
|
||||||
|
WORKER_RESULT:
|
||||||
|
- action: develop
|
||||||
|
- status: success
|
||||||
|
- summary: "Implemented 3 tasks"
|
||||||
|
- files_changed: ["src/auth.ts", "src/utils.ts"]
|
||||||
|
- next_suggestion: validate
|
||||||
|
|
||||||
|
DETAILED_OUTPUT:
|
||||||
|
tasks_completed: [T1, T2]
|
||||||
|
metrics:
|
||||||
|
lines_added: 180
|
||||||
|
lines_removed: 15
|
||||||
|
```
|
||||||
|
|
||||||
|
**Effects**:
|
||||||
|
- Files created/modified
|
||||||
|
- `skill_state.completed_tasks` updated
|
||||||
|
- Progress documented
|
||||||
|
|
||||||
|
**Failure Modes**:
|
||||||
|
- Pattern unclear → suggest debug
|
||||||
|
- Task blocked → mark blocked, continue
|
||||||
|
- Partial completion → set `loop_back_to: "develop"`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### DEBUG
|
||||||
|
|
||||||
|
**Purpose**: Diagnose issues, root cause analysis
|
||||||
|
|
||||||
|
**Preconditions**:
|
||||||
|
- Issue exists (test failure, bug report, etc.)
|
||||||
|
- `status === 'running'`
|
||||||
|
|
||||||
|
**Input**:
|
||||||
|
```
|
||||||
|
- Issue description
|
||||||
|
- Error messages
|
||||||
|
- Stack traces
|
||||||
|
- Reproduction steps
|
||||||
|
```
|
||||||
|
|
||||||
|
**Execution**:
|
||||||
|
1. Understand problem symptoms
|
||||||
|
2. Gather evidence from code
|
||||||
|
3. Form hypothesis
|
||||||
|
4. Test hypothesis
|
||||||
|
5. Document root cause
|
||||||
|
6. Suggest fixes
|
||||||
|
|
||||||
|
**Output**:
|
||||||
|
```
|
||||||
|
WORKER_RESULT:
|
||||||
|
- action: debug
|
||||||
|
- status: success
|
||||||
|
- summary: "Root cause: memory leak in event listeners"
|
||||||
|
- next_suggestion: develop (apply fixes)
|
||||||
|
|
||||||
|
ROOT_CAUSE_ANALYSIS:
|
||||||
|
hypothesis: "Listener accumulation"
|
||||||
|
confidence: high
|
||||||
|
evidence: [...]
|
||||||
|
mechanism: "Detailed explanation"
|
||||||
|
|
||||||
|
FIX_RECOMMENDATIONS:
|
||||||
|
1. Add removeAllListeners() on disconnect
|
||||||
|
2. Verification: Monitor memory usage
|
||||||
|
```
|
||||||
|
|
||||||
|
**Effects**:
|
||||||
|
- `skill_state.findings` updated
|
||||||
|
- Fix recommendations documented
|
||||||
|
- Ready for develop to apply fixes
|
||||||
|
|
||||||
|
**Failure Modes**:
|
||||||
|
- Insufficient info → request more data
|
||||||
|
- Multiple hypotheses → rank by likelihood
|
||||||
|
- Inconclusive → suggest investigation areas
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### VALIDATE
|
||||||
|
|
||||||
|
**Purpose**: Run tests, check coverage, quality gates
|
||||||
|
|
||||||
|
**Preconditions**:
|
||||||
|
- Code exists to validate
|
||||||
|
- `status === 'running'`
|
||||||
|
|
||||||
|
**Input**:
|
||||||
|
```
|
||||||
|
- Files to test
|
||||||
|
- Test configuration
|
||||||
|
- Coverage requirements
|
||||||
|
```
|
||||||
|
|
||||||
|
**Execution**:
|
||||||
|
1. Identify test framework
|
||||||
|
2. Run unit tests
|
||||||
|
3. Run integration tests
|
||||||
|
4. Measure coverage
|
||||||
|
5. Check quality (lint, types, security)
|
||||||
|
6. Generate report
|
||||||
|
|
||||||
|
**Output**:
|
||||||
|
```
|
||||||
|
WORKER_RESULT:
|
||||||
|
- action: validate
|
||||||
|
- status: success
|
||||||
|
- summary: "113 tests pass, coverage 95%"
|
||||||
|
- next_suggestion: complete (all pass) | develop (fix failures)
|
||||||
|
|
||||||
|
TEST_RESULTS:
|
||||||
|
unit_tests: { passed: 98, failed: 0 }
|
||||||
|
integration_tests: { passed: 15, failed: 0 }
|
||||||
|
coverage: "95%"
|
||||||
|
|
||||||
|
QUALITY_CHECKS:
|
||||||
|
lint: ✓ Pass
|
||||||
|
types: ✓ Pass
|
||||||
|
security: ✓ Pass
|
||||||
|
```
|
||||||
|
|
||||||
|
**Effects**:
|
||||||
|
- Test results documented
|
||||||
|
- Coverage measured
|
||||||
|
- Quality gates verified
|
||||||
|
|
||||||
|
**Failure Modes**:
|
||||||
|
- Tests fail → document failures, suggest fixes
|
||||||
|
- Coverage low → identify gaps
|
||||||
|
- Quality issues → flag problems
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### COMPLETE
|
||||||
|
|
||||||
|
**Purpose**: Finalize session, generate summary, commit
|
||||||
|
|
||||||
|
**Preconditions**:
|
||||||
|
- All tasks completed
|
||||||
|
- Tests passing
|
||||||
|
- `status === 'running'`
|
||||||
|
|
||||||
|
**Input**:
|
||||||
|
```
|
||||||
|
- All worker outputs
|
||||||
|
- Progress files
|
||||||
|
- Current state
|
||||||
|
```
|
||||||
|
|
||||||
|
**Execution**:
|
||||||
|
1. Read all worker outputs
|
||||||
|
2. Consolidate achievements
|
||||||
|
3. Verify completeness
|
||||||
|
4. Generate summary
|
||||||
|
5. Prepare commit message
|
||||||
|
6. Cleanup and archive
|
||||||
|
|
||||||
|
**Output**:
|
||||||
|
```
|
||||||
|
WORKER_RESULT:
|
||||||
|
- action: complete
|
||||||
|
- status: success
|
||||||
|
- summary: "Session completed successfully"
|
||||||
|
- next_suggestion: null
|
||||||
|
|
||||||
|
SESSION_SUMMARY:
|
||||||
|
achievements: [...]
|
||||||
|
files_changed: [...]
|
||||||
|
test_results: { ... }
|
||||||
|
quality_checks: { ... }
|
||||||
|
|
||||||
|
COMMIT_SUGGESTION:
|
||||||
|
message: "feat: ..."
|
||||||
|
files: [...]
|
||||||
|
ready_for_pr: true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Effects**:
|
||||||
|
- `status` → 'completed'
|
||||||
|
- Summary file created
|
||||||
|
- Progress archived
|
||||||
|
- Commit message ready
|
||||||
|
|
||||||
|
**Failure Modes**:
|
||||||
|
- Pending tasks remain → mark partial
|
||||||
|
- Quality gates fail → list failures
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Action Flow Diagrams
|
||||||
|
|
||||||
|
### Interactive Mode Flow
|
||||||
|
|
||||||
|
```
|
||||||
|
+------+
|
||||||
|
| INIT |
|
||||||
|
+------+
|
||||||
|
|
|
||||||
|
v
|
||||||
|
+------+ user selects
|
||||||
|
| MENU |-------------+
|
||||||
|
+------+ |
|
||||||
|
^ v
|
||||||
|
| +--------------+
|
||||||
|
| | spawn worker |
|
||||||
|
| +--------------+
|
||||||
|
| |
|
||||||
|
| v
|
||||||
|
| +------+-------+
|
||||||
|
+---------| wait result |
|
||||||
|
+------+-------+
|
||||||
|
|
|
||||||
|
v
|
||||||
|
+------+-------+
|
||||||
|
| update state |
|
||||||
|
+--------------+
|
||||||
|
|
|
||||||
|
v
|
||||||
|
[completed?] --no--> [back to MENU]
|
||||||
|
|
|
||||||
|
yes
|
||||||
|
v
|
||||||
|
+----------+
|
||||||
|
| COMPLETE |
|
||||||
|
+----------+
|
||||||
|
```
|
||||||
|
|
||||||
|
### Auto Mode Flow
|
||||||
|
|
||||||
|
```
|
||||||
|
+------+ +---------+ +-------+ +----------+ +----------+
|
||||||
|
| INIT | ---> | DEVELOP | ---> | DEBUG | ---> | VALIDATE | ---> | COMPLETE |
|
||||||
|
+------+ +---------+ +-------+ +----------+ +----------+
|
||||||
|
^ | |
|
||||||
|
| +--- [issues] |
|
||||||
|
+--------------------------------+
|
||||||
|
[tests fail]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parallel Mode Flow
|
||||||
|
|
||||||
|
```
|
||||||
|
+------+
|
||||||
|
| INIT |
|
||||||
|
+------+
|
||||||
|
|
|
||||||
|
v
|
||||||
|
+---------------------+
|
||||||
|
| spawn all workers |
|
||||||
|
| [develop, debug, |
|
||||||
|
| validate] |
|
||||||
|
+---------------------+
|
||||||
|
|
|
||||||
|
v
|
||||||
|
+---------------------+
|
||||||
|
| wait({ ids: all }) |
|
||||||
|
+---------------------+
|
||||||
|
|
|
||||||
|
v
|
||||||
|
+---------------------+
|
||||||
|
| merge results |
|
||||||
|
+---------------------+
|
||||||
|
|
|
||||||
|
v
|
||||||
|
+---------------------+
|
||||||
|
| coordinator decides |
|
||||||
|
+---------------------+
|
||||||
|
|
|
||||||
|
v
|
||||||
|
+----------+
|
||||||
|
| COMPLETE |
|
||||||
|
+----------+
|
||||||
|
```
|
||||||
|
|
||||||
|
## Worker Coordination
|
||||||
|
|
||||||
|
| Scenario | Worker Sequence | Mode |
|
||||||
|
|----------|-----------------|------|
|
||||||
|
| Simple task | init → develop → validate → complete | Auto |
|
||||||
|
| Complex task | init → develop → debug → develop → validate → complete | Auto |
|
||||||
|
| Bug fix | init → debug → develop → validate → complete | Auto |
|
||||||
|
| Analysis | init → [develop \|\| debug \|\| validate] → complete | Parallel |
|
||||||
|
| Interactive | init → menu → user selects → worker → menu → ... | Interactive |
|
||||||
|
|
||||||
|
## Best Practices
|
||||||
|
|
||||||
|
1. **Init always first**: Parse requirements before execution
|
||||||
|
2. **Validate often**: After each develop phase
|
||||||
|
3. **Debug when needed**: Don't skip diagnosis
|
||||||
|
4. **Complete always last**: Ensure proper cleanup
|
||||||
|
5. **Use parallel wisely**: For independent analysis tasks
|
||||||
|
6. **Follow sequence**: In auto mode, respect dependencies
|
||||||
Reference in New Issue
Block a user