@@ -327,49 +327,107 @@ async function getUserConfirmation(chain) {
327327
328328---
329329
330- ### Phase 4: Setup TODO Tracking
330+ ### Phase 4: Setup TODO Tracking & Status File
331331
332332` ` ` javascript
333- function setupTodoTracking (chain , workflow ) {
333+ function setupTodoTracking (chain , workflow , analysis ) {
334+ const sessionId = ` ccw-${ Date .now ()} ` ;
335+ const stateDir = ` .workflow/.ccw/${ sessionId} ` ;
336+ Bash (` mkdir -p "${ stateDir} "` );
337+
334338 const todos = chain .map ((step , i ) => ({
335339 content: ` CCW:${ workflow} : [${ i + 1 } /${ chain .length } ] ${ step .cmd } ` ,
336340 status: i === 0 ? ' in_progress' : ' pending' ,
337341 activeForm: ` Executing ${ step .cmd } `
338342 }));
339343 TodoWrite ({ todos });
344+
345+ // Initialize status.json for hook tracking
346+ const state = {
347+ session_id: sessionId,
348+ workflow: workflow,
349+ status: ' running' ,
350+ created_at: new Date ().toISOString (),
351+ updated_at: new Date ().toISOString (),
352+ analysis: analysis,
353+ command_chain: chain .map ((step , idx ) => ({
354+ index: idx,
355+ command: step .cmd ,
356+ status: idx === 0 ? ' running' : ' pending'
357+ })),
358+ current_index: 0
359+ };
360+
361+ Write (` ${ stateDir} /status.json` , JSON .stringify (state, null , 2 ));
362+
363+ return { sessionId, stateDir, state };
340364}
341365` ` `
342366
343- **Output**: ` - > CCW : rapid: [1 / 3 ] / workflow: lite- plan | CCW : rapid: [2 / 3 ] / workflow: lite- execute | ... `
367+ **Output**:
368+ - TODO: ` - > CCW : rapid: [1 / 3 ] / workflow: lite- plan | CCW : rapid: [2 / 3 ] / workflow: lite- execute | ... `
369+ - Status File: ` .workflow / .ccw / {session_id}/ status .json `
344370
345371---
346372
347373### Phase 5: Execute Command Chain
348374
349375` ` ` javascript
350- async function executeCommandChain (chain , workflow ) {
376+ async function executeCommandChain (chain , workflow , trackingState ) {
351377 let previousResult = null ;
378+ const { sessionId , stateDir , state } = trackingState;
352379
353380 for (let i = 0 ; i < chain .length ; i++ ) {
354381 try {
382+ // Update status: mark current as running
383+ state .command_chain [i].status = ' running' ;
384+ state .current_index = i;
385+ state .updated_at = new Date ().toISOString ();
386+ Write (` ${ stateDir} /status.json` , JSON .stringify (state, null , 2 ));
387+
355388 const fullCommand = assembleCommand (chain[i], previousResult);
356389 const result = await Skill ({ skill: fullCommand });
357390
358391 previousResult = { ... result, success: true };
392+
393+ // Update status: mark current as completed, next as running
394+ state .command_chain [i].status = ' completed' ;
395+ if (i + 1 < chain .length ) {
396+ state .command_chain [i + 1 ].status = ' running' ;
397+ }
398+ state .updated_at = new Date ().toISOString ();
399+ Write (` ${ stateDir} /status.json` , JSON .stringify (state, null , 2 ));
400+
359401 updateTodoStatus (i, chain .length , workflow, ' completed' );
360402
361403 } catch (error) {
404+ // Update status on error
405+ state .command_chain [i].status = ' failed' ;
406+ state .status = ' error' ;
407+ state .updated_at = new Date ().toISOString ();
408+ Write (` ${ stateDir} /status.json` , JSON .stringify (state, null , 2 ));
409+
362410 const action = await handleError (chain[i], error, i);
363411 if (action === ' retry' ) {
412+ state .command_chain [i].status = ' pending' ;
413+ state .status = ' running' ;
364414 i-- ; // Retry
365415 } else if (action === ' abort' ) {
416+ state .status = ' failed' ;
417+ Write (` ${ stateDir} /status.json` , JSON .stringify (state, null , 2 ));
366418 return { success: false , error: error .message };
367419 }
368420 // 'skip' - continue
421+ state .status = ' running' ;
369422 }
370423 }
371424
372- return { success: true , completed: chain .length };
425+ // Mark workflow as completed
426+ state .status = ' completed' ;
427+ state .updated_at = new Date ().toISOString ();
428+ Write (` ${ stateDir} /status.json` , JSON .stringify (state, null , 2 ));
429+
430+ return { success: true , completed: chain .length , sessionId };
373431}
374432
375433// Assemble full command with session/plan parameters
@@ -434,16 +492,19 @@ Phase 3: User Confirmation (optional)
434492 | -- Show pipeline visualization
435493 + -- Allow adjustment
436494 |
437- Phase 4 : Setup TODO Tracking
438- + -- Create todos with CCW prefix
495+ Phase 4 : Setup TODO Tracking & Status File
496+ | -- Create todos with CCW prefix
497+ + -- Initialize .workflow / .ccw / {session_id}/ status .json
439498 |
440499Phase 5 : Execute Command Chain
441500 | -- For each command:
501+ | | -- Update status .json (current= running)
442502 | | -- Assemble full command
443503 | | -- Execute via Skill
504+ | | -- Update status .json (current= completed, next= running)
444505 | | -- Update TODO status
445506 | + -- Handle errors (retry/ skip/ abort)
446- + -- Return workflow result
507+ + -- Mark status . json as completed
447508` ` `
448509
449510---
@@ -482,7 +543,9 @@ Phase 5: Execute Command Chain
482543
483544## State Management
484545
485- **TodoWrite-Based Tracking**: All execution state tracked via TodoWrite with ` CCW : ` prefix.
546+ ### Dual Tracking System
547+
548+ **1. TodoWrite-Based Tracking** (UI Display): All execution state tracked via TodoWrite with ` CCW : ` prefix.
486549
487550` ` ` javascript
488551// Initial state
@@ -500,7 +563,57 @@ todos = [
500563];
501564` ` `
502565
503- **vs ccw-coordinator**: Extensive state.json with task_id, status transitions, hook callbacks.
566+ **2. Status.json Tracking**: Persistent state file for workflow monitoring.
567+
568+ **Location**: ` .workflow / .ccw / {session_id}/ status .json `
569+
570+ **Structure**:
571+ ` ` ` json
572+ {
573+ " session_id" : " ccw-1706123456789" ,
574+ " workflow" : " rapid" ,
575+ " status" : " running|completed|failed|error" ,
576+ " created_at" : " 2025-02-01T10:30:00Z" ,
577+ " updated_at" : " 2025-02-01T10:35:00Z" ,
578+ " analysis" : {
579+ " goal" : " Add user authentication" ,
580+ " scope" : [" auth" ],
581+ " constraints" : [],
582+ " task_type" : " feature" ,
583+ " complexity" : " medium"
584+ },
585+ " command_chain" : [
586+ {
587+ " index" : 0 ,
588+ " command" : " /workflow:lite-plan" ,
589+ " status" : " completed"
590+ },
591+ {
592+ " index" : 1 ,
593+ " command" : " /workflow:lite-execute" ,
594+ " status" : " running"
595+ },
596+ {
597+ " index" : 2 ,
598+ " command" : " /workflow:test-cycle-execute" ,
599+ " status" : " pending"
600+ }
601+ ],
602+ " current_index" : 1
603+ }
604+ ` ` `
605+
606+ **Status Values**:
607+ - ` running` : Workflow executing commands
608+ - ` completed` : All commands finished
609+ - ` failed` : User aborted or unrecoverable error
610+ - ` error` : Command execution failed (during error handling)
611+
612+ **Command Status Values**:
613+ - ` pending` : Not started
614+ - ` running` : Currently executing
615+ - ` completed` : Successfully finished
616+ - ` failed` : Execution failed
504617
505618---
506619
@@ -527,20 +640,6 @@ todos = [
527640
528641---
529642
530- ## Type Comparison: ccw vs ccw-coordinator
531-
532- | Aspect | ccw | ccw-coordinator |
533- |--------|-----|-----------------|
534- | **Type** | Main process (Skill) | External CLI (ccw cli + hook callbacks) |
535- | **Execution** | Synchronous blocking | Async background with hook completion |
536- | **Workflow** | Auto intent-based selection | Manual chain building |
537- | **Intent Analysis** | 5-phase clarity check | 3-phase requirement analysis |
538- | **State** | TodoWrite only (in-memory) | state.json + checkpoint/resume |
539- | **Error Handling** | Retry/skip/abort (interactive) | Retry/skip/abort (via AskUser) |
540- | **Use Case** | Auto workflow for any task | Manual orchestration, large chains |
541-
542- ---
543-
544643## Usage
545644
546645` ` ` bash
0 commit comments