Files
Claude-Code-Workflow/.codex/skills/ccw-loop/phases/actions/action-init.md
catlog22 2819f3597f feat: Add validation action and orchestrator for CCW Loop
- Implemented the VALIDATE action to run tests, check coverage, and generate reports.
- Created orchestrator for managing CCW Loop execution using Codex subagent pattern.
- Defined state schema for unified loop state management.
- Updated action catalog with new actions and their specifications.
- Enhanced CLI and issue routes to support new features and data structures.
- Improved documentation for Codex subagent design principles and action flow.
2026-01-22 22:32:37 +08:00

3.1 KiB

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

const state = JSON.parse(Read(`.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

const progressDir = `.loop/${loopId}.progress`

// Directories created by orchestrator, verify they exist
// mkdir -p ${progressDir}

Step 3: Analyze Task and Generate Tasks

// Analyze task description
const taskDescription = state.description

// Generate 3-7 development tasks based on analysis
// Use ACE search or smart_search to find relevant patterns

const 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

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

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(`.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:
- .loop/{loopId}.json: skill_state initialized
- .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