mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-11 02:33:51 +08:00
从子目录执行 skill 时,相对路径 .workflow/ 会导致产物落到错误位置。
通过 git rev-parse --show-toplevel || pwd 检测项目根目录,
所有 .workflow/ 路径引用统一加上 {projectRoot} 前缀确保路径正确。
涉及 72 个文件,覆盖 20+ 个 skill。
3.6 KiB
3.6 KiB
Phase 1: Session Initialization
Create or resume a development loop, initialize state file and directory structure.
Objective
- Parse user arguments (TASK, --loop-id, --auto)
- Create new loop with unique ID OR resume existing loop
- Initialize directory structure for progress files
- Create master state file
- Output: loopId, state, progressDir
Execution
Step 0: Determine Project Root
// Step 0: Determine Project Root
const projectRoot = Bash('git rev-parse --show-toplevel 2>/dev/null || pwd').trim()
Step 1.1: Parse Arguments
const { loopId: existingLoopId, task, mode = 'interactive' } = options
// Validate mutual exclusivity
if (!existingLoopId && !task) {
console.error('Either --loop-id or task description is required')
return { status: 'error', message: 'Missing loopId or task' }
}
// Determine mode
const executionMode = options['--auto'] ? 'auto' : 'interactive'
Step 1.2: Utility Functions
const getUtc8ISOString = () => new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString()
function readLoopState(loopId) {
const stateFile = `${projectRoot}/.workflow/.loop/${loopId}.json`
if (!fs.existsSync(stateFile)) {
return null
}
return JSON.parse(Read(stateFile))
}
Step 1.3: New Loop Creation
When TASK is provided (no --loop-id):
// Generate unique loop ID
const timestamp = getUtc8ISOString().replace(/[-:]/g, '').split('.')[0]
const random = Math.random().toString(36).substring(2, 10)
const loopId = `loop-v2-${timestamp}-${random}`
console.log(`Creating new loop: ${loopId}`)
Create Directory Structure
mkdir -p ${projectRoot}/.workflow/.loop/${loopId}.progress
Initialize State File
function createLoopState(loopId, taskDescription) {
const stateFile = `${projectRoot}/.workflow/.loop/${loopId}.json`
const now = getUtc8ISOString()
const state = {
// API compatible fields
loop_id: loopId,
title: taskDescription.substring(0, 100),
description: taskDescription,
max_iterations: 10,
status: 'running',
current_iteration: 0,
created_at: now,
updated_at: now,
// Skill extension fields (initialized by INIT action)
skill_state: null
}
Write(stateFile, JSON.stringify(state, null, 2))
return state
}
Step 1.4: Resume Existing Loop
When --loop-id is provided:
const loopId = existingLoopId
const state = readLoopState(loopId)
if (!state) {
console.error(`Loop not found: ${loopId}`)
return { status: 'error', message: 'Loop not found' }
}
console.log(`Resuming loop: ${loopId}`)
console.log(`Status: ${state.status}`)
Step 1.5: Control Signal Check
Before proceeding, verify loop status allows continuation:
function checkControlSignals(loopId) {
const state = readLoopState(loopId)
switch (state?.status) {
case 'paused':
return { continue: false, action: 'pause_exit' }
case 'failed':
return { continue: false, action: 'stop_exit' }
case 'running':
return { continue: true, action: 'continue' }
default:
return { continue: false, action: 'stop_exit' }
}
}
Output
- Variable:
loopId- Unique loop identifier - Variable:
state- Initialized or resumed loop state object - Variable:
progressDir-${projectRoot}/.workflow/.loop/${loopId}.progress - Variable:
mode-'interactive'or'auto' - TodoWrite: Mark Phase 1 completed, Phase 2 in_progress
Next Phase
Return to orchestrator, then auto-continue to Phase 2: Orchestration Loop.