mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-10 02:24:35 +08:00
- Implemented `prep-loop.md` for ccw-loop, detailing source discovery, validation, task transformation, and auto-loop configuration. - Created `prep-plan.md` for workflow planning, covering environment checks, task quality assessment, execution preferences, and final confirmation. - Defined schemas and integration points for `prep-package.json` in both ccw-loop and workflow-plan skills, ensuring proper validation and task handling. - Added error handling mechanisms for various scenarios during the preparation phases.
175 lines
3.8 KiB
Markdown
175 lines
3.8 KiB
Markdown
# Action: INIT
|
|
|
|
Initialize CCW Loop session, create directory structure and initial state.
|
|
|
|
## Purpose
|
|
|
|
- Create session directory structure
|
|
- Initialize state file with skill_state
|
|
- Analyze task description to generate development tasks
|
|
- Prepare execution environment
|
|
|
|
## Preconditions
|
|
|
|
- [ ] state.status === 'running'
|
|
- [ ] state.skill_state === null
|
|
|
|
## Execution Steps
|
|
|
|
### Step 1: Verify Control Signals
|
|
|
|
```javascript
|
|
const state = JSON.parse(Read(`${projectRoot}/.workflow/.loop/${loopId}.json`))
|
|
|
|
if (state.status !== 'running') {
|
|
return {
|
|
action: 'INIT',
|
|
status: 'failed',
|
|
message: `Cannot init: status is ${state.status}`,
|
|
next_action: state.status === 'paused' ? 'PAUSED' : 'STOPPED'
|
|
}
|
|
}
|
|
```
|
|
|
|
### Step 2: Create Directory Structure
|
|
|
|
```javascript
|
|
const progressDir = `${projectRoot}/.workflow/.loop/${loopId}.progress`
|
|
|
|
// Directories created by orchestrator, verify they exist
|
|
// mkdir -p ${progressDir}
|
|
```
|
|
|
|
### Step 3: Analyze Task and Generate Tasks
|
|
|
|
```javascript
|
|
// Check if prep tasks already loaded by orchestrator (from prep-package)
|
|
// If skill_state already has tasks (pre-populated by Phase 1), skip generation
|
|
const existingTasks = state.skill_state?.develop?.tasks
|
|
if (existingTasks && existingTasks.length > 0) {
|
|
console.log(`✓ Using ${existingTasks.length} pre-built tasks from prep-package`)
|
|
console.log(` Source: ${state.prep_source?.tool || 'unknown'}`)
|
|
// Skip to Step 4 — tasks already available
|
|
tasks = existingTasks
|
|
} else {
|
|
// No prep tasks — analyze task description and generate 3-7 development tasks
|
|
const taskDescription = state.description
|
|
|
|
// Generate 3-7 development tasks based on analysis
|
|
// Use ACE search or smart_search to find relevant patterns
|
|
|
|
tasks = [
|
|
{
|
|
id: 'task-001',
|
|
description: 'Task description based on analysis',
|
|
tool: 'gemini',
|
|
mode: 'write',
|
|
status: 'pending',
|
|
priority: 1,
|
|
files: [],
|
|
created_at: getUtc8ISOString(),
|
|
completed_at: null
|
|
}
|
|
// ... more tasks
|
|
]
|
|
}
|
|
```
|
|
|
|
### Step 4: Initialize Progress Document
|
|
|
|
```javascript
|
|
const progressPath = `${progressDir}/develop.md`
|
|
|
|
const progressInitial = `# Development Progress
|
|
|
|
**Loop ID**: ${loopId}
|
|
**Task**: ${taskDescription}
|
|
**Started**: ${getUtc8ISOString()}
|
|
|
|
---
|
|
|
|
## Task List
|
|
|
|
${tasks.map((t, i) => `${i + 1}. [ ] ${t.description}`).join('\n')}
|
|
|
|
---
|
|
|
|
## Progress Timeline
|
|
|
|
`
|
|
|
|
Write(progressPath, progressInitial)
|
|
```
|
|
|
|
### Step 5: Update State
|
|
|
|
```javascript
|
|
const skillState = {
|
|
current_action: 'init',
|
|
last_action: null,
|
|
completed_actions: [],
|
|
mode: mode,
|
|
|
|
develop: {
|
|
total: tasks.length,
|
|
completed: 0,
|
|
current_task: null,
|
|
tasks: tasks,
|
|
last_progress_at: null
|
|
},
|
|
|
|
debug: {
|
|
active_bug: null,
|
|
hypotheses_count: 0,
|
|
hypotheses: [],
|
|
confirmed_hypothesis: null,
|
|
iteration: 0,
|
|
last_analysis_at: null
|
|
},
|
|
|
|
validate: {
|
|
pass_rate: 0,
|
|
coverage: 0,
|
|
test_results: [],
|
|
passed: false,
|
|
failed_tests: [],
|
|
last_run_at: null
|
|
},
|
|
|
|
errors: []
|
|
}
|
|
|
|
state.skill_state = skillState
|
|
state.updated_at = getUtc8ISOString()
|
|
Write(`${projectRoot}/.workflow/.loop/${loopId}.json`, JSON.stringify(state, null, 2))
|
|
```
|
|
|
|
## Output Format
|
|
|
|
```
|
|
ACTION_RESULT:
|
|
- action: INIT
|
|
- status: success
|
|
- message: Session initialized with {N} development tasks
|
|
|
|
FILES_UPDATED:
|
|
- {projectRoot}/.workflow/.loop/{loopId}.json: skill_state initialized
|
|
- {projectRoot}/.workflow/.loop/{loopId}.progress/develop.md: Progress document created
|
|
|
|
NEXT_ACTION_NEEDED: {DEVELOP (auto) | MENU (interactive)}
|
|
```
|
|
|
|
## Error Handling
|
|
|
|
| Error Type | Recovery |
|
|
|------------|----------|
|
|
| Directory creation failed | Report error, stop |
|
|
| Task analysis failed | Create single generic task |
|
|
| State write failed | Retry once, then stop |
|
|
|
|
## Next Actions
|
|
|
|
- Success (auto mode): `DEVELOP`
|
|
- Success (interactive): `MENU`
|
|
- Failed: Report error
|