mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-10 02:24:35 +08:00
4.1 KiB
4.1 KiB
Worker: COMPLETE
Session finalization worker. Aggregate results, generate summary, cleanup.
Purpose
- Aggregate all worker results into comprehensive summary
- Verify completeness of tasks
- Generate commit message suggestion
- Offer expansion options
- Mark loop as completed
Preconditions
state.status === 'running'
Execution
Step 1: Read All Worker Outputs
const workerOutputs = {}
for (const action of ['init', 'develop', 'debug', 'validate']) {
const outputPath = `${workersDir}/${action}.output.json`
if (fs.existsSync(outputPath)) {
workerOutputs[action] = JSON.parse(Read(outputPath))
}
}
Step 2: Aggregate Statistics
const stats = {
duration: Date.now() - new Date(state.created_at).getTime(),
iterations: state.current_iteration,
tasks_completed: state.skill_state.completed_tasks.length,
tasks_total: state.skill_state.completed_tasks.length + state.skill_state.pending_tasks.length,
files_changed: collectAllFilesChanged(workerOutputs),
test_passed: workerOutputs.validate?.summary?.passed || 0,
test_total: workerOutputs.validate?.summary?.total || 0,
coverage: workerOutputs.validate?.coverage || 'N/A'
}
Step 3: Generate Summary
Write(`${progressDir}/summary.md`, `# CCW Loop-B Session Summary
**Loop ID**: ${loopId}
**Task**: ${state.description}
**Mode**: ${state.mode}
**Started**: ${state.created_at}
**Completed**: ${getUtc8ISOString()}
**Duration**: ${formatDuration(stats.duration)}
---
## Results
| Metric | Value |
|--------|-------|
| Iterations | ${stats.iterations} |
| Tasks Completed | ${stats.tasks_completed}/${stats.tasks_total} |
| Tests | ${stats.test_passed}/${stats.test_total} |
| Coverage | ${stats.coverage} |
| Files Changed | ${stats.files_changed.length} |
## Files Changed
${stats.files_changed.map(f => `- \`${f}\``).join('\n') || '- None'}
## Worker Summary
${Object.entries(workerOutputs).map(([action, output]) => `
### ${action}
- Status: ${output.status}
- Summary: ${output.summary}
`).join('\n')}
## Recommendations
${generateRecommendations(stats, state)}
---
*Generated by CCW Loop-B at ${getUtc8ISOString()}*
`)
Step 4: Generate Commit Suggestion
const commitSuggestion = {
message: generateCommitMessage(state.description, stats),
files: stats.files_changed,
ready_for_pr: stats.test_passed > 0 && stats.tasks_completed === stats.tasks_total
}
Step 5: Update State
state.status = 'completed'
state.completed_at = getUtc8ISOString()
state.skill_state.phase = 'complete'
state.skill_state.workers_completed.push('complete')
saveState(loopId, state)
Output Format
WORKER_RESULT:
- action: complete
- status: success
- summary: Loop completed. {tasks_completed} tasks, {test_passed} tests pass
- files_changed: []
- next_suggestion: null
- loop_back_to: null
DETAILED_OUTPUT:
SESSION_SUMMARY:
achievements: [...]
files_changed: [...]
test_results: { passed: N, total: N }
COMMIT_SUGGESTION:
message: "feat: ..."
files: [...]
ready_for_pr: true
EXPANSION_OPTIONS:
1. [test] Add more test cases
2. [enhance] Feature enhancements
3. [refactor] Code refactoring
4. [doc] Documentation updates
Helper Functions
function formatDuration(ms) {
const seconds = Math.floor(ms / 1000)
const minutes = Math.floor(seconds / 60)
const hours = Math.floor(minutes / 60)
if (hours > 0) return `${hours}h ${minutes % 60}m`
if (minutes > 0) return `${minutes}m ${seconds % 60}s`
return `${seconds}s`
}
function generateRecommendations(stats, state) {
const recs = []
if (stats.tasks_completed < stats.tasks_total) recs.push('- Complete remaining tasks')
if (stats.test_passed < stats.test_total) recs.push('- Fix failing tests')
if (stats.coverage !== 'N/A' && parseFloat(stats.coverage) < 80) recs.push(`- Improve coverage (${stats.coverage}%)`)
if (recs.length === 0) recs.push('- Consider code review', '- Update documentation')
return recs.join('\n')
}
Error Handling
| Error | Recovery |
|---|---|
| Missing worker outputs | Generate partial summary |
| State write failed | Retry, then report |