mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-15 02:42:45 +08:00
Add quality standards and team command design patterns documentation
- Introduced a new quality standards document outlining assessment criteria for team command .md files, including completeness, pattern compliance, integration, and consistency dimensions. - Established quality gates and issue classification for errors, warnings, and informational notes. - Created a comprehensive team command design patterns document detailing infrastructure and collaboration patterns, including message bus integration, YAML front matter requirements, task lifecycle, five-phase execution structure, and error handling. - Included a pattern selection guide for collaboration scenarios to enhance team interaction models.
This commit is contained in:
@@ -226,13 +226,13 @@ function decomposeTasks(issue, exploration) {
|
||||
scope: inferScope(group), // Module path
|
||||
action: inferAction(group), // Create | Update | Implement | ...
|
||||
description: group.description,
|
||||
modification_points: mapModificationPoints(group),
|
||||
files: mapFiles(group), // [{path, target, change, action?, conflict_risk?}]
|
||||
implementation: generateSteps(group), // Step-by-step guide
|
||||
test: {
|
||||
unit: generateUnitTests(group),
|
||||
commands: ['npm test']
|
||||
},
|
||||
acceptance: {
|
||||
convergence: {
|
||||
criteria: generateCriteria(group), // Quantified checklist
|
||||
verification: generateVerification(group)
|
||||
},
|
||||
@@ -242,7 +242,7 @@ function decomposeTasks(issue, exploration) {
|
||||
message_template: generateCommitMsg(group)
|
||||
},
|
||||
depends_on: inferDependencies(group, tasks),
|
||||
priority: calculatePriority(group) // 1-5 (1=highest)
|
||||
priority: calculatePriorityEnum(group) // "critical"|"high"|"medium"|"low"
|
||||
}));
|
||||
|
||||
// GitHub Reply Task: Add final task if issue has github_url
|
||||
@@ -254,20 +254,20 @@ function decomposeTasks(issue, exploration) {
|
||||
scope: 'github',
|
||||
action: 'Notify',
|
||||
description: `Comment on GitHub issue to report completion status`,
|
||||
modification_points: [],
|
||||
files: [],
|
||||
implementation: [
|
||||
`Generate completion summary (tasks completed, files changed)`,
|
||||
`Post comment via: gh issue comment ${issue.github_number || extractNumber(issue.github_url)} --body "..."`,
|
||||
`Include: solution approach, key changes, verification results`
|
||||
],
|
||||
test: { unit: [], commands: [] },
|
||||
acceptance: {
|
||||
convergence: {
|
||||
criteria: ['GitHub comment posted successfully', 'Comment includes completion summary'],
|
||||
verification: ['Check GitHub issue for new comment']
|
||||
},
|
||||
commit: null, // No commit for notification task
|
||||
depends_on: lastTaskId ? [lastTaskId] : [], // Depends on last implementation task
|
||||
priority: 5 // Lowest priority (run last)
|
||||
priority: "low" // Lowest priority (run last)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -370,10 +370,10 @@ Each line is a solution JSON containing tasks. Schema: `cat ~/.ccw/workflows/cli
|
||||
### 3.2 Validation Checklist
|
||||
|
||||
- [ ] ACE search performed for each issue
|
||||
- [ ] All modification_points verified against codebase
|
||||
- [ ] All files[] paths verified against codebase
|
||||
- [ ] Tasks have 2+ implementation steps
|
||||
- [ ] All 5 lifecycle phases present
|
||||
- [ ] Quantified acceptance criteria with verification
|
||||
- [ ] Quantified convergence criteria with verification
|
||||
- [ ] Dependencies form valid DAG
|
||||
- [ ] Commit follows conventional commits
|
||||
|
||||
@@ -389,7 +389,7 @@ Each line is a solution JSON containing tasks. Schema: `cat ~/.ccw/workflows/cli
|
||||
4. Fetch issue details via `ccw issue status <id> --json`
|
||||
5. **Analyze failure history**: Check `issue.feedback` for type='failure', stage='execute'
|
||||
6. **For replanning**: Reference previous failures in `solution.approach`, add prevention steps
|
||||
7. Quantify acceptance.criteria with testable conditions
|
||||
7. Quantify convergence.criteria with testable conditions
|
||||
8. Validate DAG before output
|
||||
9. Evaluate each solution with `analysis` and `score`
|
||||
10. Write solutions to `.workflow/issues/solutions/{issue-id}.jsonl` (append mode)
|
||||
|
||||
@@ -1,513 +0,0 @@
|
||||
---
|
||||
name: codex-coordinator
|
||||
description: Command orchestration tool for Codex - analyze requirements, recommend command chain, execute sequentially with state persistence
|
||||
argument-hint: "TASK=\"<task description>\" [--depth=standard|deep] [--auto-confirm] [--verbose]"
|
||||
---
|
||||
|
||||
# Codex Coordinator Command
|
||||
|
||||
Interactive orchestration tool for Codex commands: analyze task → discover commands → recommend chain → execute sequentially → track state.
|
||||
|
||||
**Execution Model**: Intelligent agent-driven workflow. Claude analyzes each phase and orchestrates command execution.
|
||||
|
||||
## Core Concept: Minimum Execution Units (最小执行单元)
|
||||
|
||||
### What is a Minimum Execution Unit?
|
||||
|
||||
**Definition**: A set of commands that must execute together as an atomic group to achieve a meaningful workflow milestone. Splitting these commands breaks the logical flow and creates incomplete states.
|
||||
|
||||
**Why This Matters**:
|
||||
- **Prevents Incomplete States**: Avoid stopping after task generation without execution
|
||||
- **User Experience**: User gets complete results, not intermediate artifacts requiring manual follow-up
|
||||
- **Workflow Integrity**: Maintains logical coherence of multi-step operations
|
||||
|
||||
### Codex Minimum Execution Units
|
||||
|
||||
**Planning + Execution Units** (规划+执行单元):
|
||||
|
||||
| Unit Name | Commands | Purpose | Output |
|
||||
|-----------|----------|---------|--------|
|
||||
| **Quick Implementation** | lite-plan-a → execute | Lightweight plan and immediate execution | Working code |
|
||||
| **Bug Fix** | lite-fix → execute | Quick bug diagnosis and fix execution | Fixed code |
|
||||
| **Issue Workflow** | issue-discover → issue-plan → issue-queue → issue-execute | Complete issue lifecycle | Completed issues |
|
||||
| **Discovery & Analysis** | issue-discover → issue-discover-by-prompt | Issue discovery with multiple perspectives | Generated issues |
|
||||
| **Brainstorm to Execution** | brainstorm-with-file → execute | Brainstorm ideas then implement | Working code |
|
||||
|
||||
**With-File Workflows** (文档化单元):
|
||||
|
||||
| Unit Name | Commands | Purpose | Output |
|
||||
|-----------|----------|---------|--------|
|
||||
| **Brainstorm With File** | brainstorm-with-file | Multi-perspective ideation with documentation | brainstorm.md |
|
||||
| **Debug With File** | debug-with-file | Hypothesis-driven debugging with documentation | understanding.md |
|
||||
| **Analyze With File** | analyze-with-file | Collaborative analysis with documentation | discussion.md |
|
||||
| **Clean & Analyze** | clean → analyze-with-file | Cleanup then analyze | Cleaned code + analysis |
|
||||
|
||||
### Command-to-Unit Mapping (命令与最小单元的映射)
|
||||
|
||||
| Command | Precedes | Atomic Units |
|
||||
|---------|----------|--------------|
|
||||
| lite-plan-a | execute, brainstorm-with-file | Quick Implementation |
|
||||
| lite-fix | execute | Bug Fix |
|
||||
| issue-discover | issue-plan | Issue Workflow |
|
||||
| issue-plan | issue-queue | Issue Workflow |
|
||||
| issue-queue | issue-execute | Issue Workflow |
|
||||
| brainstorm-with-file | execute, issue-execute | Brainstorm to Execution |
|
||||
| debug-with-file | execute | Debug With File |
|
||||
| analyze-with-file | (standalone) | Analyze With File |
|
||||
| clean | analyze-with-file, execute | Clean & Analyze |
|
||||
| quick-plan-with-file | execute | Quick Planning with File |
|
||||
| merge-plans-with-file | execute | Merge Multiple Plans |
|
||||
| unified-execute-with-file | (terminal) | Execute with File Tracking |
|
||||
|
||||
### Atomic Group Rules
|
||||
|
||||
1. **Never Split Units**: Coordinator must recommend complete units, not partial chains
|
||||
2. **Multi-Unit Participation**: Some commands can participate in multiple units
|
||||
3. **User Override**: User can explicitly request partial execution (advanced mode)
|
||||
4. **Visualization**: Pipeline view shows unit boundaries with 【 】markers
|
||||
5. **Validation**: Before execution, verify all unit commands are included
|
||||
|
||||
**Example Pipeline with Units**:
|
||||
```
|
||||
需求 → 【lite-plan-a → execute】→ 代码 → 【issue-discover → issue-plan → issue-queue → issue-execute】→ 完成
|
||||
└──── Quick Implementation ────┘ └────────── Issue Workflow ─────────┘
|
||||
```
|
||||
|
||||
## 3-Phase Workflow
|
||||
|
||||
### Phase 1: Analyze Requirements
|
||||
|
||||
Parse task to extract: goal, scope, complexity, and task type.
|
||||
|
||||
```javascript
|
||||
function analyzeRequirements(taskDescription) {
|
||||
return {
|
||||
goal: extractMainGoal(taskDescription), // e.g., "Fix login bug"
|
||||
scope: extractScope(taskDescription), // e.g., ["auth", "login"]
|
||||
complexity: determineComplexity(taskDescription), // 'simple' | 'medium' | 'complex'
|
||||
task_type: detectTaskType(taskDescription) // See task type patterns below
|
||||
};
|
||||
}
|
||||
|
||||
// Task Type Detection Patterns
|
||||
function detectTaskType(text) {
|
||||
// Priority order (first match wins)
|
||||
if (/fix|bug|error|crash|fail|debug|diagnose/.test(text)) return 'bugfix';
|
||||
if (/生成|generate|discover|找出|issue|问题/.test(text)) return 'discovery';
|
||||
if (/plan|规划|设计|design|analyze|分析/.test(text)) return 'analysis';
|
||||
if (/清理|cleanup|clean|refactor|重构/.test(text)) return 'cleanup';
|
||||
if (/头脑|brainstorm|创意|ideation/.test(text)) return 'brainstorm';
|
||||
if (/合并|merge|combine|batch/.test(text)) return 'batch-planning';
|
||||
return 'feature'; // Default
|
||||
}
|
||||
|
||||
// Complexity Assessment
|
||||
function determineComplexity(text) {
|
||||
let score = 0;
|
||||
if (/refactor|重构|migrate|迁移|architect|架构|system|系统/.test(text)) score += 2;
|
||||
if (/multiple|多个|across|跨|all|所有|entire|整个/.test(text)) score += 2;
|
||||
if (/integrate|集成|api|database|数据库/.test(text)) score += 1;
|
||||
if (/security|安全|performance|性能|scale|扩展/.test(text)) score += 1;
|
||||
return score >= 4 ? 'complex' : score >= 2 ? 'medium' : 'simple';
|
||||
}
|
||||
```
|
||||
|
||||
**Display to user**:
|
||||
```
|
||||
Analysis Complete:
|
||||
Goal: [extracted goal]
|
||||
Scope: [identified areas]
|
||||
Complexity: [level]
|
||||
Task Type: [detected type]
|
||||
```
|
||||
|
||||
### Phase 2: Discover Commands & Recommend Chain
|
||||
|
||||
Dynamic command chain assembly using task type and complexity matching.
|
||||
|
||||
#### Available Codex Commands (Discovery)
|
||||
|
||||
All commands from `~/.codex/prompts/`:
|
||||
- **Planning**: @~/.codex/prompts/lite-plan-a.md, @~/.codex/prompts/lite-plan-b.md, @~/.codex/prompts/lite-plan-c.md, @~/.codex/prompts/quick-plan-with-file.md, @~/.codex/prompts/merge-plans-with-file.md
|
||||
- **Execution**: @~/.codex/prompts/execute.md, @~/.codex/prompts/unified-execute-with-file.md
|
||||
- **Bug Fixes**: @~/.codex/prompts/lite-fix.md, @~/.codex/prompts/debug-with-file.md
|
||||
- **Discovery**: @~/.codex/prompts/issue-discover.md, @~/.codex/prompts/issue-discover-by-prompt.md, @~/.codex/prompts/issue-plan.md, @~/.codex/prompts/issue-queue.md, @~/.codex/prompts/issue-execute.md
|
||||
- **Analysis**: @~/.codex/prompts/analyze-with-file.md
|
||||
- **Brainstorming**: @~/.codex/prompts/brainstorm-with-file.md, @~/.codex/prompts/brainstorm-to-cycle.md
|
||||
- **Cleanup**: @~/.codex/prompts/clean.md, @~/.codex/prompts/compact.md
|
||||
|
||||
#### Recommendation Algorithm
|
||||
|
||||
```javascript
|
||||
async function recommendCommandChain(analysis) {
|
||||
// Step 1: 根据任务类型确定流程
|
||||
const { inputPort, outputPort } = determinePortFlow(analysis.task_type, analysis.complexity);
|
||||
|
||||
// Step 2: Claude 根据命令特性和任务特征,智能选择命令序列
|
||||
const chain = selectChainByTaskType(analysis);
|
||||
|
||||
return chain;
|
||||
}
|
||||
|
||||
// 任务类型对应的端口流
|
||||
function determinePortFlow(taskType, complexity) {
|
||||
const flows = {
|
||||
'bugfix': { flow: ['lite-fix', 'execute'], depth: complexity === 'complex' ? 'deep' : 'standard' },
|
||||
'discovery': { flow: ['issue-discover', 'issue-plan', 'issue-queue', 'issue-execute'], depth: 'standard' },
|
||||
'analysis': { flow: ['analyze-with-file'], depth: complexity === 'complex' ? 'deep' : 'standard' },
|
||||
'cleanup': { flow: ['clean'], depth: 'standard' },
|
||||
'brainstorm': { flow: ['brainstorm-with-file', 'execute'], depth: complexity === 'complex' ? 'deep' : 'standard' },
|
||||
'batch-planning': { flow: ['merge-plans-with-file', 'execute'], depth: 'standard' },
|
||||
'feature': { flow: complexity === 'complex' ? ['lite-plan-b'] : ['lite-plan-a', 'execute'], depth: complexity === 'complex' ? 'deep' : 'standard' }
|
||||
};
|
||||
return flows[taskType] || flows['feature'];
|
||||
}
|
||||
```
|
||||
|
||||
#### Display to User
|
||||
|
||||
```
|
||||
Recommended Command Chain:
|
||||
|
||||
Pipeline (管道视图):
|
||||
需求 → @~/.codex/prompts/lite-plan-a.md → 计划 → @~/.codex/prompts/execute.md → 代码完成
|
||||
|
||||
Commands (命令列表):
|
||||
1. @~/.codex/prompts/lite-plan-a.md
|
||||
2. @~/.codex/prompts/execute.md
|
||||
|
||||
Proceed? [Confirm / Show Details / Adjust / Cancel]
|
||||
```
|
||||
|
||||
### Phase 2b: Get User Confirmation
|
||||
|
||||
Ask user for confirmation before proceeding with execution.
|
||||
|
||||
```javascript
|
||||
async function getUserConfirmation(chain) {
|
||||
const response = await AskUserQuestion({
|
||||
questions: [{
|
||||
question: 'Proceed with this command chain?',
|
||||
header: 'Confirm Chain',
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: 'Confirm and execute', description: 'Proceed with commands' },
|
||||
{ label: 'Show details', description: 'View each command' },
|
||||
{ label: 'Adjust chain', description: 'Remove or reorder' },
|
||||
{ label: 'Cancel', description: 'Abort' }
|
||||
]
|
||||
}]
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
```
|
||||
|
||||
### Phase 3: Execute Sequential Command Chain
|
||||
|
||||
```javascript
|
||||
async function executeCommandChain(chain, analysis) {
|
||||
const sessionId = `codex-coord-${Date.now()}`;
|
||||
const stateDir = `.workflow/.codex-coordinator/${sessionId}`;
|
||||
|
||||
// Create state directory
|
||||
const state = {
|
||||
session_id: sessionId,
|
||||
status: 'running',
|
||||
created_at: new Date().toISOString(),
|
||||
analysis: analysis,
|
||||
command_chain: chain.map((cmd, idx) => ({ ...cmd, index: idx, status: 'pending' })),
|
||||
execution_results: [],
|
||||
};
|
||||
|
||||
// Save initial state
|
||||
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
|
||||
|
||||
for (let i = 0; i < chain.length; i++) {
|
||||
const cmd = chain[i];
|
||||
console.log(`[${i+1}/${chain.length}] Executing: @~/.codex/prompts/${cmd.name}.md`);
|
||||
|
||||
// Update status to running
|
||||
state.command_chain[i].status = 'running';
|
||||
state.updated_at = new Date().toISOString();
|
||||
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
|
||||
|
||||
try {
|
||||
// Build command with parameters using full path
|
||||
let commandStr = `@~/.codex/prompts/${cmd.name}.md`;
|
||||
|
||||
// Add parameters based on previous results and task context
|
||||
if (i > 0 && state.execution_results.length > 0) {
|
||||
const lastResult = state.execution_results[state.execution_results.length - 1];
|
||||
commandStr += ` --resume="${lastResult.session_id || lastResult.artifact}"`;
|
||||
}
|
||||
|
||||
// For analysis-based commands, add depth parameter
|
||||
if (analysis.complexity === 'complex' && (cmd.name.includes('analyze') || cmd.name.includes('plan'))) {
|
||||
commandStr += ` --depth=deep`;
|
||||
}
|
||||
|
||||
// Add task description for planning commands
|
||||
if (cmd.type === 'planning' && i === 0) {
|
||||
commandStr += ` TASK="${analysis.goal}"`;
|
||||
}
|
||||
|
||||
// Execute command via Bash (spawning as background task)
|
||||
// Format: @~/.codex/prompts/command-name.md [] parameters
|
||||
// Note: This simulates the execution; actual implementation uses hook callbacks
|
||||
console.log(`Executing: ${commandStr}`);
|
||||
|
||||
// Save execution record
|
||||
state.execution_results.push({
|
||||
index: i,
|
||||
command: cmd.name,
|
||||
status: 'in-progress',
|
||||
started_at: new Date().toISOString(),
|
||||
session_id: null,
|
||||
artifact: null
|
||||
});
|
||||
|
||||
state.command_chain[i].status = 'completed';
|
||||
state.updated_at = new Date().toISOString();
|
||||
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
|
||||
|
||||
console.log(`[${i+1}/${chain.length}] ✓ Completed: @~/.codex/prompts/${cmd.name}.md`);
|
||||
|
||||
} catch (error) {
|
||||
state.command_chain[i].status = 'failed';
|
||||
state.updated_at = new Date().toISOString();
|
||||
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
|
||||
|
||||
console.log(`❌ Command failed: ${error.message}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
state.status = 'completed';
|
||||
state.updated_at = new Date().toISOString();
|
||||
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
|
||||
|
||||
console.log(`\n✅ Orchestration Complete: ${state.session_id}`);
|
||||
return state;
|
||||
}
|
||||
```
|
||||
|
||||
## State File Structure
|
||||
|
||||
**Location**: `.workflow/.codex-coordinator/{session_id}/state.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"session_id": "codex-coord-20250129-143025",
|
||||
"status": "running|waiting|completed|failed",
|
||||
"created_at": "2025-01-29T14:30:25Z",
|
||||
"updated_at": "2025-01-29T14:35:45Z",
|
||||
"analysis": {
|
||||
"goal": "Fix login authentication bug",
|
||||
"scope": ["auth", "login"],
|
||||
"complexity": "medium",
|
||||
"task_type": "bugfix"
|
||||
},
|
||||
"command_chain": [
|
||||
{
|
||||
"index": 0,
|
||||
"name": "lite-fix",
|
||||
"type": "bugfix",
|
||||
"status": "completed"
|
||||
},
|
||||
{
|
||||
"index": 1,
|
||||
"name": "execute",
|
||||
"type": "execution",
|
||||
"status": "pending"
|
||||
}
|
||||
],
|
||||
"execution_results": [
|
||||
{
|
||||
"index": 0,
|
||||
"command": "lite-fix",
|
||||
"status": "completed",
|
||||
"started_at": "2025-01-29T14:30:25Z",
|
||||
"session_id": "fix-login-2025-01-29",
|
||||
"artifact": ".workflow/.lite-fix/fix-login-2025-01-29/fix-plan.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Status Values
|
||||
|
||||
- `running`: Orchestrator actively executing
|
||||
- `waiting`: Paused, waiting for external events
|
||||
- `completed`: All commands finished successfully
|
||||
- `failed`: Error occurred or user aborted
|
||||
|
||||
## Task Type Routing (Pipeline Summary)
|
||||
|
||||
**Note**: 【 】marks Minimum Execution Units (最小执行单元) - these commands must execute together.
|
||||
|
||||
| Task Type | Pipeline | Minimum Units |
|
||||
|-----------|----------|---|
|
||||
| **bugfix** | Bug报告 →【@~/.codex/prompts/lite-fix.md → @~/.codex/prompts/execute.md】→ 修复代码 | Bug Fix |
|
||||
| **discovery** | 需求 →【@~/.codex/prompts/issue-discover.md → @~/.codex/prompts/issue-plan.md → @~/.codex/prompts/issue-queue.md → @~/.codex/prompts/issue-execute.md】→ 完成 issues | Issue Workflow |
|
||||
| **analysis** | 需求 → @~/.codex/prompts/analyze-with-file.md → 分析报告 | Analyze With File |
|
||||
| **cleanup** | 代码库 → @~/.codex/prompts/clean.md → 清理完成 | Cleanup |
|
||||
| **brainstorm** | 主题 →【@~/.codex/prompts/brainstorm-with-file.md → @~/.codex/prompts/execute.md】→ 实现代码 | Brainstorm to Execution |
|
||||
| **batch-planning** | 需求集合 →【@~/.codex/prompts/merge-plans-with-file.md → @~/.codex/prompts/execute.md】→ 代码完成 | Merge Multiple Plans |
|
||||
| **feature** (simple) | 需求 →【@~/.codex/prompts/lite-plan-a.md → @~/.codex/prompts/execute.md】→ 代码 | Quick Implementation |
|
||||
| **feature** (complex) | 需求 → @~/.codex/prompts/lite-plan-b.md → 详细计划 → @~/.codex/prompts/execute.md → 代码 | Complex Planning |
|
||||
|
||||
## Available Commands Reference
|
||||
|
||||
### Planning Commands
|
||||
|
||||
| Command | Purpose | Usage | Output |
|
||||
|---------|---------|-------|--------|
|
||||
| **lite-plan-a** | Lightweight merged-mode planning | `@~/.codex/prompts/lite-plan-a.md TASK="..."` | plan.json |
|
||||
| **lite-plan-b** | Multi-angle exploration planning | `@~/.codex/prompts/lite-plan-b.md TASK="..."` | plan.json |
|
||||
| **lite-plan-c** | Parallel angle planning | `@~/.codex/prompts/lite-plan-c.md TASK="..."` | plan.json |
|
||||
| **quick-plan-with-file** | Quick planning with file tracking | `@~/.codex/prompts/quick-plan-with-file.md TASK="..."` | plan + docs |
|
||||
| **merge-plans-with-file** | Merge multiple plans | `@~/.codex/prompts/merge-plans-with-file.md PLANS="..."` | merged-plan.json |
|
||||
|
||||
### Execution Commands
|
||||
|
||||
| Command | Purpose | Usage | Output |
|
||||
|---------|---------|-------|--------|
|
||||
| **execute** | Execute tasks from plan | `@~/.codex/prompts/execute.md SESSION=".../plan/"` | Working code |
|
||||
| **unified-execute-with-file** | Execute with file tracking | `@~/.codex/prompts/unified-execute-with-file.md SESSION="..."` | Code + tracking |
|
||||
|
||||
### Bug Fix Commands
|
||||
|
||||
| Command | Purpose | Usage | Output |
|
||||
|---------|---------|-------|--------|
|
||||
| **lite-fix** | Quick bug diagnosis and planning | `@~/.codex/prompts/lite-fix.md BUG="..."` | fix-plan.json |
|
||||
| **debug-with-file** | Hypothesis-driven debugging | `@~/.codex/prompts/debug-with-file.md BUG="..."` | understanding.md |
|
||||
|
||||
### Discovery Commands
|
||||
|
||||
| Command | Purpose | Usage | Output |
|
||||
|---------|---------|-------|--------|
|
||||
| **issue-discover** | Multi-perspective issue discovery | `@~/.codex/prompts/issue-discover.md PATTERN="src/**"` | issues.jsonl |
|
||||
| **issue-discover-by-prompt** | Prompt-based discovery | `@~/.codex/prompts/issue-discover-by-prompt.md PROMPT="..."` | issues |
|
||||
| **issue-plan** | Plan issue solutions | `@~/.codex/prompts/issue-plan.md --all-pending` | issue-plans.json |
|
||||
| **issue-queue** | Form execution queue | `@~/.codex/prompts/issue-queue.md --from-plan` | queue.json |
|
||||
| **issue-execute** | Execute issue queue | `@~/.codex/prompts/issue-execute.md QUEUE="..."` | Completed |
|
||||
|
||||
### Analysis Commands
|
||||
|
||||
| Command | Purpose | Usage | Output |
|
||||
|---------|---------|-------|--------|
|
||||
| **analyze-with-file** | Collaborative analysis | `@~/.codex/prompts/analyze-with-file.md TOPIC="..."` | discussion.md |
|
||||
|
||||
### Brainstorm Commands
|
||||
|
||||
| Command | Purpose | Usage | Output |
|
||||
|---------|---------|-------|--------|
|
||||
| **brainstorm-with-file** | Multi-perspective brainstorming | `@~/.codex/prompts/brainstorm-with-file.md TOPIC="..."` | brainstorm.md |
|
||||
| **brainstorm-to-cycle** | Bridge brainstorm to execution | `@~/.codex/prompts/brainstorm-to-cycle.md` | Executable plan |
|
||||
|
||||
### Utility Commands
|
||||
|
||||
| Command | Purpose | Usage | Output |
|
||||
|---------|---------|-------|--------|
|
||||
| **clean** | Intelligent code cleanup | `@~/.codex/prompts/clean.md` | Cleaned code |
|
||||
| **compact** | Compact session memory | `@~/.codex/prompts/compact.md SESSION="..."` | Compressed state |
|
||||
|
||||
## Execution Flow
|
||||
|
||||
```
|
||||
User Input: TASK="..."
|
||||
↓
|
||||
Phase 1: analyzeRequirements(task)
|
||||
↓
|
||||
Phase 2: recommendCommandChain(analysis)
|
||||
Display pipeline and commands
|
||||
↓
|
||||
User Confirmation
|
||||
↓
|
||||
Phase 3: executeCommandChain(chain, analysis)
|
||||
├─ For each command:
|
||||
│ ├─ Update state to "running"
|
||||
│ ├─ Build command string with parameters
|
||||
│ ├─ Execute @command [] with parameters
|
||||
│ ├─ Save execution results
|
||||
│ └─ Update state to "completed"
|
||||
↓
|
||||
Output completion summary
|
||||
```
|
||||
|
||||
## Key Design Principles
|
||||
|
||||
1. **Atomic Execution** - Never split minimum execution units
|
||||
2. **State Persistence** - All state saved to JSON
|
||||
3. **User Control** - Confirmation before execution
|
||||
4. **Context Passing** - Parameters chain across commands
|
||||
5. **Resume Support** - Can resume from state.json
|
||||
6. **Intelligent Routing** - Task type determines command chain
|
||||
7. **Complexity Awareness** - Different paths for simple vs complex tasks
|
||||
|
||||
## Command Invocation Format
|
||||
|
||||
**Format**: `@~/.codex/prompts/<command-name>.md <parameters>`
|
||||
|
||||
**Examples**:
|
||||
```bash
|
||||
@~/.codex/prompts/lite-plan-a.md TASK="Implement user authentication"
|
||||
@~/.codex/prompts/execute.md SESSION=".workflow/.lite-plan/..."
|
||||
@~/.codex/prompts/lite-fix.md BUG="Login fails with 404 error"
|
||||
@~/.codex/prompts/issue-discover.md PATTERN="src/auth/**"
|
||||
@~/.codex/prompts/brainstorm-with-file.md TOPIC="Improve user onboarding"
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Situation | Action |
|
||||
|-----------|--------|
|
||||
| Unknown task type | Default to feature implementation |
|
||||
| Command not found | Error: command not available |
|
||||
| Execution fails | Report error, offer retry or skip |
|
||||
| Invalid parameters | Validate and ask for correction |
|
||||
| Circular dependency | Detect and report |
|
||||
| All commands fail | Report and suggest manual intervention |
|
||||
|
||||
## Session Management
|
||||
|
||||
**Resume Previous Session**:
|
||||
```
|
||||
1. Find session in .workflow/.codex-coordinator/
|
||||
2. Load state.json
|
||||
3. Identify last completed command
|
||||
4. Restart from next pending command
|
||||
```
|
||||
|
||||
**View Session Progress**:
|
||||
```
|
||||
cat .workflow/.codex-coordinator/{session-id}/state.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Execution Instructions
|
||||
|
||||
The coordinator workflow follows these steps:
|
||||
|
||||
1. **Parse Input**: Extract task description from TASK parameter
|
||||
2. **Analyze**: Determine goal, scope, complexity, and task type
|
||||
3. **Recommend**: Build optimal command chain based on analysis
|
||||
4. **Confirm**: Display pipeline and request user approval
|
||||
5. **Execute**: Run commands sequentially with state tracking
|
||||
6. **Report**: Display final results and artifacts
|
||||
|
||||
To use this coordinator, invoke it as a Claude Code command (not a Codex command):
|
||||
|
||||
From the Claude Code CLI, you would call Codex commands like:
|
||||
```bash
|
||||
@~/.codex/prompts/lite-plan-a.md TASK="Your task description"
|
||||
```
|
||||
|
||||
Or with options:
|
||||
```bash
|
||||
@~/.codex/prompts/lite-plan-a.md TASK="..." --depth=deep
|
||||
```
|
||||
|
||||
This coordinator orchestrates such Codex commands based on your task requirements.
|
||||
@@ -337,7 +337,7 @@ Execute each task in order (T1 → T2 → T3 → ...):
|
||||
For each task:
|
||||
- Follow task.implementation steps
|
||||
- Run task.test commands
|
||||
- Verify task.acceptance criteria
|
||||
- Verify task.convergence criteria
|
||||
- Do NOT commit after each task
|
||||
|
||||
### Step 3: Commit Solution (Once)
|
||||
@@ -380,7 +380,7 @@ On success, run:
|
||||
"tests_passed": true,
|
||||
"verification": {
|
||||
"all_tests_passed": true,
|
||||
"acceptance_criteria_met": true,
|
||||
"convergence_criteria_met": true,
|
||||
"regression_checked": true
|
||||
},
|
||||
"summary": "<brief description of accomplishment>"
|
||||
|
||||
@@ -105,12 +105,12 @@ interface Task {
|
||||
description: string;
|
||||
|
||||
implementation: string[]; // Step-by-step guide
|
||||
acceptance: {
|
||||
convergence: {
|
||||
criteria: string[]; // What defines success
|
||||
verification: string[]; // How to verify
|
||||
};
|
||||
|
||||
priority: number; // 1-5
|
||||
priority: string; // "critical"|"high"|"medium"|"low"
|
||||
depends_on: string[]; // Task dependencies
|
||||
}
|
||||
```
|
||||
@@ -146,7 +146,7 @@ Phase 5: Generate Solution Tasks
|
||||
├─ T1: Research & Validate (if main_challenges exist)
|
||||
├─ T2: Design & Specification (if key_strengths exist)
|
||||
├─ T3+: Implementation tasks (from idea.next_steps)
|
||||
└─ Each task includes: implementation steps + acceptance criteria
|
||||
└─ Each task includes: implementation steps + convergence criteria
|
||||
|
||||
Phase 6: Bind Solution
|
||||
├─ Write solution to .workflow/issues/solutions/{issue-id}.jsonl
|
||||
@@ -214,7 +214,7 @@ Phase 7: Next Steps
|
||||
- **Title**: `idea.title`
|
||||
- **Scope**: implementation
|
||||
- **Action**: Implement
|
||||
- **Generic implementation + acceptance criteria**
|
||||
- **Generic implementation + convergence criteria**
|
||||
|
||||
## Priority Calculation
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ ${issueList}
|
||||
- Solution ID format: SOL-{issue-id}-{uid} (uid: 4 random alphanumeric chars, e.g., a7x9)
|
||||
- Single solution per issue → auto-bind via ccw issue bind
|
||||
- Multiple solutions → register only, return pending_selection
|
||||
- Tasks must have quantified acceptance.criteria
|
||||
- Tasks must have quantified convergence.criteria
|
||||
|
||||
### Return Summary
|
||||
{"bound":[{"issue_id":"...","solution_id":"...","task_count":N}],"pending_selection":[{"issue_id":"...","solutions":[{"id":"...","description":"...","task_count":N}]}]}
|
||||
@@ -323,8 +323,8 @@ Before completing, verify:
|
||||
- [ ] All input issues have solutions in `solutions/{issue-id}.jsonl`
|
||||
- [ ] Single solution issues are auto-bound (`bound_solution_id` set)
|
||||
- [ ] Multi-solution issues returned in `pending_selection` for user choice
|
||||
- [ ] Each solution has executable tasks with `modification_points`
|
||||
- [ ] Task acceptance criteria are quantified (not vague)
|
||||
- [ ] Each solution has executable tasks with `files`
|
||||
- [ ] Task convergence criteria are quantified (not vague)
|
||||
- [ ] Conflicts detected and reported (if multiple issues touch same files)
|
||||
- [ ] Issue status updated to `planned` after binding
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ ccw issue queue delete <queue-id> Delete queue from history
|
||||
Phase 1: Solution Loading & Distribution
|
||||
├─ Load issues.jsonl, filter by status='planned' + bound_solution_id
|
||||
├─ Read solutions/{issue-id}.jsonl, find bound solution
|
||||
├─ Extract files_touched from task modification_points
|
||||
├─ Extract files_touched from task files[] or modification_points (legacy)
|
||||
├─ Build solution objects array
|
||||
└─ If --queues > 1: Partition solutions into N groups (minimize cross-group file conflicts)
|
||||
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
---
|
||||
name: spec
|
||||
description: Specification generator - 6 phase document chain producing product brief, PRD, architecture, and epics. Triggers on "generate spec", "create specification", "spec generator".
|
||||
argument-hint: "[-y|--yes] [-c|--continue] \"idea or requirement description\""
|
||||
allowed-tools: TodoWrite(*), Task(*), AskUserQuestion(*), Read(*), Grep(*), Glob(*), Bash(*), Edit(*), Write(*)
|
||||
---
|
||||
|
||||
## Auto Mode
|
||||
|
||||
When `--yes` or `-y`: Auto-confirm decisions, use recommended defaults, skip interactive validation.
|
||||
|
||||
# Workflow Spec Command (/workflow:spec)
|
||||
|
||||
## Quick Start
|
||||
|
||||
```bash
|
||||
# Basic usage
|
||||
/workflow:spec "Build a task management system with real-time collaboration"
|
||||
|
||||
# Auto mode (skip all confirmations)
|
||||
/workflow:spec -y "User authentication system with OAuth2 and 2FA"
|
||||
|
||||
# Continue existing session
|
||||
/workflow:spec -c "task management"
|
||||
|
||||
# Combined
|
||||
/workflow:spec -y -c "task management"
|
||||
```
|
||||
|
||||
**Skill**: `spec-generator`
|
||||
**Output Directory**: `.workflow/.spec/SPEC-{slug}-{YYYY-MM-DD}/`
|
||||
**Core Flow**: Discovery -> Product Brief -> PRD -> Architecture -> Epics -> Readiness Check
|
||||
|
||||
## What This Command Does
|
||||
|
||||
Generates a complete specification package through 6 sequential phases:
|
||||
|
||||
1. **Discovery**: Analyze seed idea, explore codebase (optional), establish session
|
||||
2. **Product Brief**: Multi-CLI analysis (Product/Technical/User perspectives)
|
||||
3. **Requirements (PRD)**: Functional + non-functional requirements with MoSCoW priorities
|
||||
4. **Architecture**: Component design, tech stack, ADRs with review
|
||||
5. **Epics & Stories**: Implementation breakdown with dependency mapping
|
||||
6. **Readiness Check**: Cross-document validation, quality scoring, handoff
|
||||
|
||||
## Output Artifacts
|
||||
|
||||
| Phase | Artifact | Description |
|
||||
|-------|----------|-------------|
|
||||
| 1 | `spec-config.json` | Session configuration and state |
|
||||
| 1 | `discovery-context.json` | Codebase exploration (optional) |
|
||||
| 2 | `product-brief.md` | Product brief with multi-perspective synthesis |
|
||||
| 3 | `requirements/` | `_index.md` + `REQ-NNN-{slug}.md` + `NFR-{type}-NNN-{slug}.md` |
|
||||
| 4 | `architecture/` | `_index.md` + `ADR-NNN-{slug}.md` |
|
||||
| 5 | `epics/` | `_index.md` + `EPIC-NNN-{slug}.md` |
|
||||
| 6 | `readiness-report.md` | Quality validation report |
|
||||
| 6 | `spec-summary.md` | One-page executive summary |
|
||||
|
||||
## Flags
|
||||
|
||||
| Flag | Description |
|
||||
|------|-------------|
|
||||
| `-y`, `--yes` | Auto mode: skip all confirmations, use defaults |
|
||||
| `-c`, `--continue` | Resume from last completed phase |
|
||||
|
||||
## After Completion
|
||||
|
||||
The readiness check (Phase 6) offers handoff to execution workflows:
|
||||
|
||||
- `/workflow:lite-plan` - Execute one Epic at a time (direct text input)
|
||||
- `/workflow:req-plan-with-file` - Generate execution roadmap
|
||||
- `/workflow:plan` - Full planning for entire scope
|
||||
- `/issue:new` - Create issues per Epic
|
||||
|
||||
### Plan Integration (Automatic Bridge)
|
||||
|
||||
When selecting "Full planning" or "Create roadmap", Phase 6 automatically:
|
||||
|
||||
1. Creates a WFS session via `/workflow:session:start`
|
||||
2. Generates `.brainstorming/` bridge files in the session directory:
|
||||
- `guidance-specification.md` — synthesized from spec outputs (product-brief + requirements + architecture key decisions)
|
||||
- `feature-specs/feature-index.json` — maps each Epic to a Feature entry
|
||||
- `feature-specs/F-{num}-{slug}.md` — individual feature spec per Epic
|
||||
3. Invokes the downstream workflow (`/workflow:plan` or `/workflow:req-plan-with-file`)
|
||||
|
||||
The `context-search-agent` auto-discovers these `.brainstorming/` files and populates `context-package.json.brainstorm_artifacts`, which `action-planning-agent` consumes via the standard priority chain: `guidance_specification` → `feature_index` → `feature_specs`. No manual bridging required.
|
||||
|
||||
## When to Use
|
||||
|
||||
- Starting a new product/feature from scratch
|
||||
- Need structured specification before implementation
|
||||
- Want multi-perspective analysis of an idea
|
||||
- Need traceable requirement -> architecture -> story chain
|
||||
- Replacing ad-hoc brainstorming with structured output
|
||||
|
||||
## Compared to Other Workflows
|
||||
|
||||
| Workflow | Use When |
|
||||
|----------|----------|
|
||||
| `/workflow:spec` | Need full specification package before any coding |
|
||||
| `/workflow:brainstorm-with-file` | Exploring ideas, not ready for structure |
|
||||
| `/workflow:lite-plan` | Have clear requirements, ready to implement |
|
||||
| `/workflow:plan` | Have requirements, need detailed task planning |
|
||||
| `/workflow:req-plan-with-file` | Have requirements, need layered roadmap |
|
||||
|
||||
---
|
||||
|
||||
**Now execute spec-generator for**: $ARGUMENTS
|
||||
@@ -1,453 +0,0 @@
|
||||
# Claude Code Hooks - 当前实现 vs 官方标准对比报告
|
||||
|
||||
## 执行摘要
|
||||
|
||||
当前 CCW 代码库中的钩子实现**不符合 Claude Code 官方标准**。存在以下主要问题:
|
||||
|
||||
1. ❌ **钩子事件名称不符合官方标准** - 使用了错误的事件名称
|
||||
2. ❌ **配置结构不同** - 自定义了配置格式,不符合官方规范
|
||||
3. ❌ **使用了不存在的事件类型** - 某些事件在官方钩子系统中不存在
|
||||
4. ❌ **文档与实现不一致** - 代码中的注释引用的是自定义实现,而非官方标准
|
||||
|
||||
---
|
||||
|
||||
## 详细对比
|
||||
|
||||
### 1. 钩子事件名称对比
|
||||
|
||||
#### ❌ 当前实现(错误)
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"session-start": [], // ❌ 错误:应为 SessionStart
|
||||
"session-end": [], // ❌ 错误:应为 SessionEnd
|
||||
"file-modified": [], // ❌ 错误:官方不支持此事件
|
||||
"context-request": [], // ❌ 错误:官方不支持此事件
|
||||
"PostToolUse": [] // ✅ 正确
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### ✅ 官方标准(正确)
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"SessionStart": [], // ✅ 当会话开始或恢复时触发
|
||||
"UserPromptSubmit": [], // ✅ 当用户提交提示词时触发
|
||||
"PreToolUse": [], // ✅ 工具调用前触发,可以阻止
|
||||
"PermissionRequest": [], // ✅ 权限对话出现时触发
|
||||
"PostToolUse": [], // ✅ 工具调用成功后触发
|
||||
"PostToolUseFailure": [], // ✅ 工具调用失败时触发
|
||||
"Notification": [], // ✅ 通知发送时触发
|
||||
"SubagentStart": [], // ✅ 子代理生成时触发
|
||||
"SubagentStop": [], // ✅ 子代理完成时触发
|
||||
"Stop": [], // ✅ Claude 完成响应时触发
|
||||
"PreCompact": [], // ✅ 上下文压缩前触发
|
||||
"SessionEnd": [] // ✅ 会话终止时触发
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 配置结构对比
|
||||
|
||||
#### ❌ 当前实现(自定义结构)
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"session-start": [
|
||||
{
|
||||
"name": "Progressive Disclosure",
|
||||
"description": "Injects progressive disclosure index",
|
||||
"enabled": true,
|
||||
"handler": "internal:context",
|
||||
"timeout": 5000,
|
||||
"failMode": "silent"
|
||||
}
|
||||
]
|
||||
},
|
||||
"hookSettings": {
|
||||
"globalTimeout": 60000,
|
||||
"defaultFailMode": "silent",
|
||||
"allowAsync": true,
|
||||
"enableLogging": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**问题:**
|
||||
- 使用了非标准字段:`name`, `description`, `enabled`, `handler`, `failMode`
|
||||
- 使用了自定义的 `hookSettings` 配置
|
||||
- 结构过度复杂化
|
||||
|
||||
#### ✅ 官方标准(简洁标准)
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"SessionStart": [
|
||||
{
|
||||
"matcher": "startup|resume|clear|compact",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "bash /path/to/script.sh",
|
||||
"timeout": 600,
|
||||
"async": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**优点:**
|
||||
- 简洁明了的三层结构:事件 → 匹配器 → 处理器
|
||||
- 标准的字段集:`type`, `command`, `timeout`, `async`
|
||||
- 支持三种处理器类型:`command`, `prompt`, `agent`
|
||||
|
||||
### 3. 官方支持的钩子事件及其触发时机
|
||||
|
||||
| 事件名称 | 触发时机 | 可阻止 | 匹配器支持 |
|
||||
|---------|---------|--------|-----------|
|
||||
| `SessionStart` | 会话开始或恢复 | ❌ | startup, resume, clear, compact |
|
||||
| `UserPromptSubmit` | 用户提交提示词前 | ✅ | ❌ |
|
||||
| `PreToolUse` | 工具调用前 | ✅ | 工具名称 |
|
||||
| `PermissionRequest` | 权限对话出现时 | ✅ | 工具名称 |
|
||||
| `PostToolUse` | 工具调用成功后 | ❌ | 工具名称 |
|
||||
| `PostToolUseFailure` | 工具调用失败时 | ❌ | 工具名称 |
|
||||
| `Notification` | 通知发送时 | ❌ | 通知类型 |
|
||||
| `SubagentStart` | 子代理生成时 | ❌ | 代理类型 |
|
||||
| `SubagentStop` | 子代理完成时 | ✅ | 代理类型 |
|
||||
| `Stop` | Claude 完成响应时 | ✅ | ❌ |
|
||||
| `PreCompact` | 上下文压缩前 | ❌ | manual, auto |
|
||||
| `SessionEnd` | 会话终止时 | ❌ | 终止原因 |
|
||||
|
||||
**当前实现不支持的事件:**
|
||||
- ❌ `file-modified` - 官方系统中不存在
|
||||
- ❌ `context-request` - 官方系统中不存在
|
||||
|
||||
### 4. 处理器类型对比
|
||||
|
||||
#### ❌ 当前实现
|
||||
|
||||
仅支持一种:`handler: "internal:context"`(自定义内部处理器)
|
||||
|
||||
#### ✅ 官方标准
|
||||
|
||||
支持三种标准类型:
|
||||
|
||||
1. **Command hooks** (`type: "command"`)
|
||||
```json
|
||||
{
|
||||
"type": "command",
|
||||
"command": "bash /path/to/script.sh",
|
||||
"timeout": 600,
|
||||
"async": false
|
||||
}
|
||||
```
|
||||
|
||||
2. **Prompt hooks** (`type: "prompt"`)
|
||||
```json
|
||||
{
|
||||
"type": "prompt",
|
||||
"prompt": "Evaluate if this is safe to execute: $ARGUMENTS",
|
||||
"model": "haiku",
|
||||
"timeout": 30
|
||||
}
|
||||
```
|
||||
|
||||
3. **Agent hooks** (`type: "agent"`)
|
||||
```json
|
||||
{
|
||||
"type": "agent",
|
||||
"prompt": "Verify tests pass: $ARGUMENTS",
|
||||
"model": "haiku",
|
||||
"timeout": 60
|
||||
}
|
||||
```
|
||||
|
||||
### 5. 匹配器对比
|
||||
|
||||
#### ❌ 当前实现
|
||||
|
||||
没有明确的匹配器概念,而是使用:
|
||||
- `handler: "internal:context"` - 内部处理
|
||||
- 没有工具级别的过滤
|
||||
|
||||
#### ✅ 官方标准
|
||||
|
||||
完整的匹配器系统:
|
||||
|
||||
```json
|
||||
{
|
||||
"PreToolUse": [
|
||||
{
|
||||
"matcher": "Edit|Write", // 仅在 Edit 或 Write 工具时触发
|
||||
"hooks": [ ... ]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**支持的匹配器:**
|
||||
- **工具事件**:`Bash`, `Edit`, `Write`, `Read`, `Glob`, `Grep`, `Task`, `WebFetch`, `WebSearch`
|
||||
- **MCP工具**:`mcp__memory__.*`, `mcp__.*__write.*`
|
||||
- **会话事件**:`startup`, `resume`, `clear`, `compact`
|
||||
- **通知类型**:`permission_prompt`, `idle_prompt`, `auth_success`
|
||||
- **代理类型**:`Bash`, `Explore`, `Plan`
|
||||
|
||||
### 6. 输入/输出机制对比
|
||||
|
||||
#### ❌ 当前实现
|
||||
|
||||
- 未定义标准的 stdin/stdout 通信协议
|
||||
- 使用了自定义的环境变量:`$SESSION_ID`, `$FILE_PATH`, `$PROJECT_PATH`
|
||||
|
||||
#### ✅ 官方标准
|
||||
|
||||
**标准 JSON stdin 输入:**
|
||||
```json
|
||||
{
|
||||
"session_id": "abc123",
|
||||
"transcript_path": "/path/to/transcript.jsonl",
|
||||
"cwd": "/current/dir",
|
||||
"permission_mode": "default",
|
||||
"hook_event_name": "PreToolUse",
|
||||
"tool_name": "Bash",
|
||||
"tool_input": {
|
||||
"command": "npm test"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**标准 exit code 输出:**
|
||||
- **exit 0**: 成功,解析 stdout 的 JSON 决策
|
||||
- **exit 2**: 阻止性错误,stderr 成为 Claude 的反馈
|
||||
- **其他码**: 非阻止性错误,stderr 显示在详细模式
|
||||
|
||||
**标准 JSON stdout 输出:**
|
||||
```json
|
||||
{
|
||||
"hookSpecificOutput": {
|
||||
"hookEventName": "PreToolUse",
|
||||
"permissionDecision": "allow|deny|ask",
|
||||
"permissionDecisionReason": "explanation"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 7. 文件位置对比
|
||||
|
||||
#### 当前实现
|
||||
|
||||
示例配置文件位置:
|
||||
- `ccw/src/templates/hooks-config-example.json`
|
||||
|
||||
#### ✅ 官方标准
|
||||
|
||||
标准配置位置(优先级顺序):
|
||||
1. `~/.claude/settings.json` - 全局用户配置
|
||||
2. `.claude/settings.json` - 项目配置(可提交)
|
||||
3. `.claude/settings.local.json` - 项目本地配置(gitignored)
|
||||
4. 插件 `hooks/hooks.json` - 插件内部
|
||||
5. Skill/Agent frontmatter - 技能或代理
|
||||
|
||||
---
|
||||
|
||||
## 代码库中的具体问题位置
|
||||
|
||||
### 1. 错误的配置示例
|
||||
|
||||
**文件:** `ccw/src/templates/hooks-config-example.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"session-start": [ ... ], // ❌ 应为 SessionStart
|
||||
"session-end": [ ... ], // ❌ 应为 SessionEnd
|
||||
"file-modified": [ ... ], // ❌ 不存在的事件
|
||||
"context-request": [ ... ] // ❌ 不存在的事件
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**应改为:**
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"SessionStart": [
|
||||
{
|
||||
"matcher": "startup|resume",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "echo 'Session started'"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"PostToolUse": [
|
||||
{
|
||||
"matcher": "Write|Edit",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "prettier --write $FILE_PATH"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"SessionEnd": [
|
||||
{
|
||||
"matcher": "clear",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "echo 'Session ended'"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 错误的命令注释
|
||||
|
||||
**文件:** `ccw/src/commands/hook.ts`
|
||||
|
||||
当前代码引用了自定义的钩子处理逻辑,但不符合官方标准。
|
||||
|
||||
---
|
||||
|
||||
## 修复建议
|
||||
|
||||
### 优先级 1:关键修复
|
||||
|
||||
- [ ] 更新 `hooks-config-example.json` 使用官方事件名称
|
||||
- [ ] 更新配置结构以符合官方三层标准
|
||||
- [ ] 移除不支持的事件类型:`file-modified`, `context-request`
|
||||
- [ ] 文档化官方支持的事件列表
|
||||
|
||||
### 优先级 2:功能对齐
|
||||
|
||||
- [ ] 实现官方的标准 JSON stdin/stdout 通信
|
||||
- [ ] 实现标准的 exit code 处理
|
||||
- [ ] 支持标准的匹配器系统
|
||||
|
||||
### 优先级 3:增强
|
||||
|
||||
- [ ] 添加对 `prompt` 和 `agent` 处理器类型的支持
|
||||
- [ ] 实现标准的异步钩子支持(`async: true`)
|
||||
- [ ] 添加对环境变量持久化的支持(`CLAUDE_ENV_FILE`)
|
||||
|
||||
---
|
||||
|
||||
## 官方示例
|
||||
|
||||
### 例1:格式化代码后自动执行
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"PostToolUse": [
|
||||
{
|
||||
"matcher": "Edit|Write",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "jq -r '.tool_input.file_path' | xargs npx prettier --write"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 例2:阻止编辑受保护文件
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"PreToolUse": [
|
||||
{
|
||||
"matcher": "Edit|Write",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/protect-files.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 例3:会话开始时重新注入上下文
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"SessionStart": [
|
||||
{
|
||||
"matcher": "compact",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "echo 'Use Bun, not npm. Run bun test before committing.'"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 例4:基于条件的权限决策
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"PreToolUse": [
|
||||
{
|
||||
"matcher": "Bash",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"prompt": "Is this a safe command to run? $ARGUMENTS"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 参考资源
|
||||
|
||||
- 官方指南:https://code.claude.com/docs/en/hooks-guide
|
||||
- 官方参考:https://code.claude.com/docs/en/hooks
|
||||
- 官方示例:https://github.com/anthropics/claude-code/tree/main/examples/hooks
|
||||
|
||||
---
|
||||
|
||||
## 总结
|
||||
|
||||
当前 CCW 的钩子实现是基于自定义规范的,**完全不兼容** Claude Code 官方钩子系统。为了与官方标准对齐,需要进行彻底的重构,包括:
|
||||
|
||||
1. ✅ 采用官方的事件名称(已在 `.claude/docs/` 文件中提供)
|
||||
2. ✅ 采用官方的三层配置结构
|
||||
3. ✅ 实现官方的 JSON stdin/stdout 通信协议
|
||||
4. ✅ 移除不存在的自定义事件
|
||||
5. ✅ 支持官方的三种处理器类型
|
||||
|
||||
这样才能确保当用户将 CCW 的配置迁移到真实的 Claude Code CLI 时,能够正常工作。
|
||||
@@ -1,224 +0,0 @@
|
||||
# Claude Code Hooks - 文档索引
|
||||
|
||||
本目录包含 Claude Code 官方钩子系统的完整文档和分析报告。
|
||||
|
||||
---
|
||||
|
||||
## 📚 官方文档(已下载)
|
||||
|
||||
### 1. HOOKS_OFFICIAL_GUIDE.md
|
||||
- **来源**: https://code.claude.com/docs/en/hooks-guide
|
||||
- **内容**: 官方钩子指南,包含快速入门、常见用例、配置教程
|
||||
- **适用**: 初次使用钩子系统的开发者
|
||||
|
||||
### 2. HOOKS_OFFICIAL_REFERENCE.md
|
||||
- **来源**: https://code.claude.com/docs/en/hooks
|
||||
- **内容**: 完整的技术参考,包含所有事件的 schema、输入输出格式、配置选项
|
||||
- **适用**: 需要查阅具体事件参数和配置细节的开发者
|
||||
|
||||
### 3. HOOKS_QUICK_REFERENCE.md
|
||||
- **内容**: 快速查阅指南,包含所有事件列表、配置模板、常见用例
|
||||
- **适用**: 需要快速查找特定配置或事件信息的开发者
|
||||
|
||||
---
|
||||
|
||||
## 📊 分析报告
|
||||
|
||||
### 4. HOOKS_ANALYSIS_REPORT.md
|
||||
- **内容**: 当前 CCW 钩子实现 vs 官方标准对比分析
|
||||
- **包含**:
|
||||
- 当前实现存在的问题
|
||||
- 事件名称对比
|
||||
- 配置结构对比
|
||||
- 修复建议和优先级
|
||||
- **适用**: 需要了解当前实现与官方标准差异的开发者
|
||||
|
||||
---
|
||||
|
||||
## 💻 示例代码
|
||||
|
||||
### 5. ../examples/hooks_bash_command_validator.py
|
||||
- **来源**: https://github.com/anthropics/claude-code/blob/main/examples/hooks/bash_command_validator_example.py
|
||||
- **内容**: 官方示例 - Bash 命令验证器
|
||||
- **功能**: 拦截 Bash 命令,建议使用 ripgrep 替代 grep
|
||||
- **适用**: 学习如何编写 PreToolUse 钩子的开发者
|
||||
|
||||
---
|
||||
|
||||
## 🎯 官方钩子事件列表
|
||||
|
||||
### 官方支持的 12 个钩子事件
|
||||
|
||||
| # | 事件名称 | 触发时机 | 可阻止 |
|
||||
|---|---------|---------|--------|
|
||||
| 1 | `SessionStart` | 会话开始或恢复 | ❌ |
|
||||
| 2 | `UserPromptSubmit` | 用户提交提示词前 | ✅ |
|
||||
| 3 | `PreToolUse` | 工具调用前 | ✅ |
|
||||
| 4 | `PermissionRequest` | 权限对话出现时 | ✅ |
|
||||
| 5 | `PostToolUse` | 工具调用成功后 | ❌ |
|
||||
| 6 | `PostToolUseFailure` | 工具调用失败后 | ❌ |
|
||||
| 7 | `Notification` | 通知发送时 | ❌ |
|
||||
| 8 | `SubagentStart` | 子代理生成时 | ❌ |
|
||||
| 9 | `SubagentStop` | 子代理完成时 | ✅ |
|
||||
| 10 | `Stop` | Claude完成响应时 | ✅ |
|
||||
| 11 | `PreCompact` | 上下文压缩前 | ❌ |
|
||||
| 12 | `SessionEnd` | 会话终止时 | ❌ |
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ 当前实现的主要问题
|
||||
|
||||
### 问题 1: 事件名称不符合官方标准
|
||||
|
||||
❌ **当前使用(错误):**
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"session-start": [], // 错误
|
||||
"session-end": [], // 错误
|
||||
"file-modified": [], // 不存在
|
||||
"context-request": [] // 不存在
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
✅ **官方标准(正确):**
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"SessionStart": [], // 正确
|
||||
"SessionEnd": [], // 正确
|
||||
"PostToolUse": [], // 使用其他官方事件
|
||||
"PreToolUse": [] // 替代自定义事件
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 问题 2: 配置结构不符合官方标准
|
||||
|
||||
❌ **当前结构(自定义):**
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"session-start": [
|
||||
{
|
||||
"name": "...",
|
||||
"enabled": true,
|
||||
"handler": "internal:context",
|
||||
"failMode": "silent"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
✅ **官方结构(标准):**
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"SessionStart": [
|
||||
{
|
||||
"matcher": "startup|resume",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "bash script.sh",
|
||||
"timeout": 600
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔗 外部资源
|
||||
|
||||
### 官方资源
|
||||
- **官方指南**: https://code.claude.com/docs/en/hooks-guide
|
||||
- **官方参考**: https://code.claude.com/docs/en/hooks
|
||||
- **GitHub 示例**: https://github.com/anthropics/claude-code/tree/main/examples/hooks
|
||||
- **配置博客**: https://claude.com/blog/how-to-configure-hooks
|
||||
|
||||
### 社区资源
|
||||
- [Claude Code Hooks 从入门到实战 - 知乎](https://zhuanlan.zhihu.com/p/1969164730326324920)
|
||||
- [GitHub: claude-code-best-practices](https://github.com/xiaobei930/claude-code-best-practices)
|
||||
- [Claude Code power user customization](https://claude.com/blog/how-to-configure-hooks)
|
||||
|
||||
---
|
||||
|
||||
## 📖 推荐阅读顺序
|
||||
|
||||
### 对于初学者
|
||||
1. `HOOKS_QUICK_REFERENCE.md` - 快速了解钩子概念
|
||||
2. `HOOKS_OFFICIAL_GUIDE.md` - 学习如何配置和使用
|
||||
3. `hooks_bash_command_validator.py` - 查看示例代码
|
||||
|
||||
### 对于开发者(修复当前实现)
|
||||
1. `HOOKS_ANALYSIS_REPORT.md` - 了解问题和修复方案
|
||||
2. `HOOKS_OFFICIAL_REFERENCE.md` - 查阅技术细节
|
||||
3. `HOOKS_OFFICIAL_GUIDE.md` - 学习最佳实践
|
||||
|
||||
### 对于高级用户
|
||||
1. `HOOKS_OFFICIAL_REFERENCE.md` - 完整技术参考
|
||||
2. 官方 GitHub 仓库 - 更多示例
|
||||
3. `HOOKS_QUICK_REFERENCE.md` - 快速查阅
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ 快速开始
|
||||
|
||||
### 查看当前配置
|
||||
```bash
|
||||
# 在 Claude Code CLI 中
|
||||
/hooks
|
||||
```
|
||||
|
||||
### 创建第一个钩子(格式化代码)
|
||||
`.claude/settings.json`:
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"PostToolUse": [
|
||||
{
|
||||
"matcher": "Edit|Write",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "jq -r '.tool_input.file_path' | xargs prettier --write"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 调试钩子
|
||||
```bash
|
||||
claude --debug # 查看详细执行日志
|
||||
```
|
||||
|
||||
在 CLI 中按 `Ctrl+O` 切换详细模式
|
||||
|
||||
---
|
||||
|
||||
## 📝 文档更新
|
||||
|
||||
- **创建时间**: 2026-02-01
|
||||
- **官方文档版本**: 最新(截至 2026-02-01)
|
||||
- **下次更新建议**: 当 Claude Code 发布新版本时
|
||||
|
||||
---
|
||||
|
||||
## 🔍 搜索关键词
|
||||
|
||||
钩子、Hooks、事件、Events、SessionStart、PreToolUse、PostToolUse、配置、Configuration、命令、Command、Prompt、Agent、阻止、Block、通知、Notification
|
||||
|
||||
---
|
||||
|
||||
**需要帮助?**
|
||||
|
||||
参考 `HOOKS_QUICK_REFERENCE.md` 获取快速答案,或查阅 `HOOKS_OFFICIAL_REFERENCE.md` 获取完整技术细节。
|
||||
@@ -1,124 +0,0 @@
|
||||
# Claude Code Hooks - Official Guide
|
||||
|
||||
> Complete official documentation from https://code.claude.com/docs/en/hooks-guide
|
||||
|
||||
## Automate workflows with hooks
|
||||
|
||||
Run shell commands automatically when Claude Code edits files, finishes tasks, or needs input. Format code, send notifications, validate commands, and enforce project rules.
|
||||
|
||||
### Hook lifecycle
|
||||
|
||||
Hooks fire at specific points during a Claude Code session. The official hook events are:
|
||||
|
||||
| Event | When it fires |
|
||||
| :------------------- | :--------------------------------------------------- |
|
||||
| `SessionStart` | When a session begins or resumes |
|
||||
| `UserPromptSubmit` | When you submit a prompt, before Claude processes it |
|
||||
| `PreToolUse` | Before a tool call executes. Can block it |
|
||||
| `PermissionRequest` | When a permission dialog appears |
|
||||
| `PostToolUse` | After a tool call succeeds |
|
||||
| `PostToolUseFailure` | After a tool call fails |
|
||||
| `Notification` | When Claude Code sends a notification |
|
||||
| `SubagentStart` | When a subagent is spawned |
|
||||
| `SubagentStop` | When a subagent finishes |
|
||||
| `Stop` | When Claude finishes responding |
|
||||
| `PreCompact` | Before context compaction |
|
||||
| `SessionEnd` | When a session terminates |
|
||||
|
||||
### Hook handler types
|
||||
|
||||
There are three types of hook handlers:
|
||||
|
||||
1. **Command hooks** (`type: "command"`): Run a shell command
|
||||
2. **Prompt hooks** (`type: "prompt"`): Use Claude model for single-turn evaluation
|
||||
3. **Agent hooks** (`type: "agent"`): Spawn subagent with tool access
|
||||
|
||||
### Configuration structure
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"EventName": [
|
||||
{
|
||||
"matcher": "ToolName|AnotherTool",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "bash /path/to/script.sh",
|
||||
"timeout": 600,
|
||||
"async": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Hook input (stdin)
|
||||
|
||||
Common fields for all events:
|
||||
- `session_id`: Current session ID
|
||||
- `transcript_path`: Path to conversation JSON
|
||||
- `cwd`: Current working directory
|
||||
- `permission_mode`: Current permission mode
|
||||
- `hook_event_name`: Name of the event that fired
|
||||
|
||||
Event-specific fields depend on the event type.
|
||||
|
||||
### Hook output (exit codes and stdout)
|
||||
|
||||
- **Exit 0**: Success. Parse stdout for JSON decision
|
||||
- **Exit 2**: Blocking error. stderr text becomes Claude's feedback
|
||||
- **Any other code**: Non-blocking error
|
||||
|
||||
### Tool matchers
|
||||
|
||||
Available for: `PreToolUse`, `PostToolUse`, `PostToolUseFailure`, `PermissionRequest`
|
||||
|
||||
Tool names:
|
||||
- Built-in: `Bash`, `Edit`, `Write`, `Read`, `Glob`, `Grep`, `Task`, `WebFetch`, `WebSearch`
|
||||
- MCP tools: `mcp__<server>__<tool>` (e.g., `mcp__github__search_repositories`)
|
||||
|
||||
### Event matchers
|
||||
|
||||
Different events match on different fields:
|
||||
- `SessionStart`: `startup`, `resume`, `clear`, `compact`
|
||||
- `SessionEnd`: `clear`, `logout`, `prompt_input_exit`, `bypass_permissions_disabled`, `other`
|
||||
- `Notification`: `permission_prompt`, `idle_prompt`, `auth_success`, `elicitation_dialog`
|
||||
- `SubagentStart`/`SubagentStop`: agent type (e.g., `Bash`, `Explore`, `Plan`)
|
||||
- `PreCompact`: `manual`, `auto`
|
||||
|
||||
### Hook configuration locations
|
||||
|
||||
| Location | Scope |
|
||||
|----------|-------|
|
||||
| `~/.claude/settings.json` | All your projects |
|
||||
| `.claude/settings.json` | Single project |
|
||||
| `.claude/settings.local.json` | Single project (gitignored) |
|
||||
| Plugin `hooks/hooks.json` | When plugin enabled |
|
||||
| Skill/Agent frontmatter | While component active |
|
||||
|
||||
### Best practices
|
||||
|
||||
✅ **DO:**
|
||||
- Use command hooks for deterministic actions
|
||||
- Use prompt hooks for judgment-based decisions
|
||||
- Use agent hooks when verification requires file inspection
|
||||
- Quote all shell variables: `"$VAR"`
|
||||
- Use absolute paths with `$CLAUDE_PROJECT_DIR`
|
||||
- Set appropriate timeouts
|
||||
- Use async hooks for long-running operations
|
||||
- Keep hooks fast (< 10 seconds by default)
|
||||
|
||||
❌ **DON'T:**
|
||||
- Trust input data blindly
|
||||
- Use relative paths
|
||||
- Put sensitive data in hook output
|
||||
- Create infinite loops in Stop hooks
|
||||
- Run blocking operations without async
|
||||
|
||||
---
|
||||
|
||||
See https://code.claude.com/docs/en/hooks-guide for complete guide
|
||||
See https://code.claude.com/docs/en/hooks for reference documentation
|
||||
@@ -1,268 +0,0 @@
|
||||
# Claude Code Hooks - Official Reference
|
||||
|
||||
> Complete official reference from https://code.claude.com/docs/en/hooks
|
||||
|
||||
## Hooks reference
|
||||
|
||||
This is the complete technical reference for Claude Code hooks.
|
||||
|
||||
### Hook events reference
|
||||
|
||||
#### SessionStart
|
||||
|
||||
**When it fires:** When a session begins or resumes
|
||||
|
||||
**Matchers:**
|
||||
- `startup` - New session
|
||||
- `resume` - `--resume`, `--continue`, or `/resume`
|
||||
- `clear` - `/clear`
|
||||
- `compact` - Auto or manual compaction
|
||||
|
||||
**Input schema:**
|
||||
```json
|
||||
{
|
||||
"session_id": "abc123",
|
||||
"transcript_path": "/path/to/transcript.jsonl",
|
||||
"cwd": "/current/working/dir",
|
||||
"permission_mode": "default",
|
||||
"hook_event_name": "SessionStart",
|
||||
"source": "startup|resume|clear|compact",
|
||||
"model": "claude-sonnet-4-5-20250929"
|
||||
}
|
||||
```
|
||||
|
||||
**Output control:**
|
||||
- Exit 0: Text written to stdout is added to Claude's context
|
||||
- Can use `additionalContext` in JSON output
|
||||
- Cannot block session start
|
||||
|
||||
**Special variables:**
|
||||
- `CLAUDE_ENV_FILE`: Write `export` statements to persist environment variables
|
||||
|
||||
#### UserPromptSubmit
|
||||
|
||||
**When it fires:** When user submits a prompt, before Claude processes it
|
||||
|
||||
**Input schema:**
|
||||
```json
|
||||
{
|
||||
"session_id": "abc123",
|
||||
"hook_event_name": "UserPromptSubmit",
|
||||
"prompt": "User's prompt text here"
|
||||
}
|
||||
```
|
||||
|
||||
**Output control:**
|
||||
- Exit 0: Plain text stdout is added as context
|
||||
- `decision: "block"` prevents prompt processing
|
||||
- `additionalContext` adds context to Claude
|
||||
|
||||
#### PreToolUse
|
||||
|
||||
**When it fires:** Before a tool call executes
|
||||
|
||||
**Matchers:** Tool names (Bash, Edit, Write, Read, etc.)
|
||||
|
||||
**Tool input schemas:**
|
||||
- `Bash`: `command`, `description`, `timeout`, `run_in_background`
|
||||
- `Write`: `file_path`, `content`
|
||||
- `Edit`: `file_path`, `old_string`, `new_string`, `replace_all`
|
||||
- `Read`: `file_path`, `offset`, `limit`
|
||||
- `Glob`: `pattern`, `path`
|
||||
- `Grep`: `pattern`, `path`, `glob`, `output_mode`, `-i`, `multiline`
|
||||
- `WebFetch`: `url`, `prompt`
|
||||
- `WebSearch`: `query`, `allowed_domains`, `blocked_domains`
|
||||
- `Task`: `prompt`, `description`, `subagent_type`, `model`
|
||||
|
||||
**Output control:**
|
||||
- `permissionDecision`: `"allow"`, `"deny"`, `"ask"`
|
||||
- `permissionDecisionReason`: Explanation
|
||||
- `updatedInput`: Modify tool input before execution
|
||||
- `additionalContext`: Add context to Claude
|
||||
|
||||
#### PermissionRequest
|
||||
|
||||
**When it fires:** When permission dialog appears
|
||||
|
||||
**Input schema:** Similar to PreToolUse but fires when permission needed
|
||||
|
||||
**Output control:**
|
||||
- `decision.behavior`: `"allow"` or `"deny"`
|
||||
- `decision.updatedInput`: Modify input before execution
|
||||
- `decision.message`: For deny, tells Claude why
|
||||
|
||||
#### PostToolUse
|
||||
|
||||
**When it fires:** After a tool call succeeds
|
||||
|
||||
**Input schema:** Includes both `tool_input` and `tool_response`
|
||||
|
||||
**Output control:**
|
||||
- `decision: "block"` to flag issue to Claude
|
||||
- `additionalContext`: Add context
|
||||
- `updatedMCPToolOutput`: For MCP tools, replace output
|
||||
|
||||
#### PostToolUseFailure
|
||||
|
||||
**When it fires:** After a tool call fails
|
||||
|
||||
**Input schema:** Includes `error` and `is_interrupt` fields
|
||||
|
||||
**Output control:**
|
||||
- `additionalContext`: Provide context about the failure
|
||||
|
||||
#### Notification
|
||||
|
||||
**When it fires:** When Claude Code sends a notification
|
||||
|
||||
**Matchers:**
|
||||
- `permission_prompt` - Permission needed
|
||||
- `idle_prompt` - Claude idle
|
||||
- `auth_success` - Auth successful
|
||||
- `elicitation_dialog` - Dialog shown
|
||||
|
||||
**Input schema:**
|
||||
```json
|
||||
{
|
||||
"hook_event_name": "Notification",
|
||||
"message": "Notification text",
|
||||
"title": "Title",
|
||||
"notification_type": "permission_prompt|idle_prompt|..."
|
||||
}
|
||||
```
|
||||
|
||||
#### SubagentStart
|
||||
|
||||
**When it fires:** When subagent is spawned
|
||||
|
||||
**Matchers:** Agent types (Bash, Explore, Plan, or custom)
|
||||
|
||||
**Input schema:**
|
||||
```json
|
||||
{
|
||||
"hook_event_name": "SubagentStart",
|
||||
"agent_id": "agent-abc123",
|
||||
"agent_type": "Explore"
|
||||
}
|
||||
```
|
||||
|
||||
**Output control:**
|
||||
- `additionalContext`: Add context to subagent
|
||||
|
||||
#### SubagentStop
|
||||
|
||||
**When it fires:** When subagent finishes
|
||||
|
||||
**Input schema:** Similar to SubagentStart with `stop_hook_active` field
|
||||
|
||||
#### Stop
|
||||
|
||||
**When it fires:** When Claude finishes responding
|
||||
|
||||
**Input schema:**
|
||||
```json
|
||||
{
|
||||
"hook_event_name": "Stop",
|
||||
"stop_hook_active": false|true
|
||||
}
|
||||
```
|
||||
|
||||
**Output control:**
|
||||
- `decision: "block"` prevents Claude from stopping
|
||||
- `reason`: Required when blocking, tells Claude why to continue
|
||||
- Check `stop_hook_active` to prevent infinite loops
|
||||
|
||||
#### PreCompact
|
||||
|
||||
**When it fires:** Before context compaction
|
||||
|
||||
**Matchers:**
|
||||
- `manual` - `/compact`
|
||||
- `auto` - Auto-compact when context full
|
||||
|
||||
**Input schema:**
|
||||
```json
|
||||
{
|
||||
"hook_event_name": "PreCompact",
|
||||
"trigger": "manual|auto",
|
||||
"custom_instructions": ""
|
||||
}
|
||||
```
|
||||
|
||||
#### SessionEnd
|
||||
|
||||
**When it fires:** When session terminates
|
||||
|
||||
**Matchers:**
|
||||
- `clear` - `/clear`
|
||||
- `logout` - User logged out
|
||||
- `prompt_input_exit` - User exited during prompt
|
||||
- `bypass_permissions_disabled` - Bypass disabled
|
||||
- `other` - Other reasons
|
||||
|
||||
**Input schema:**
|
||||
```json
|
||||
{
|
||||
"hook_event_name": "SessionEnd",
|
||||
"reason": "clear|logout|..."
|
||||
}
|
||||
```
|
||||
|
||||
### Prompt-based hooks
|
||||
|
||||
**Type:** `"prompt"`
|
||||
|
||||
**Configuration:**
|
||||
```json
|
||||
{
|
||||
"type": "prompt",
|
||||
"prompt": "Your prompt here. Use $ARGUMENTS for input JSON",
|
||||
"model": "haiku",
|
||||
"timeout": 30
|
||||
}
|
||||
```
|
||||
|
||||
**Response schema:**
|
||||
```json
|
||||
{
|
||||
"ok": true|false,
|
||||
"reason": "Explanation if ok is false"
|
||||
}
|
||||
```
|
||||
|
||||
### Agent-based hooks
|
||||
|
||||
**Type:** `"agent"`
|
||||
|
||||
**Configuration:**
|
||||
```json
|
||||
{
|
||||
"type": "agent",
|
||||
"prompt": "Your prompt here. Use $ARGUMENTS for input JSON",
|
||||
"model": "haiku",
|
||||
"timeout": 60
|
||||
}
|
||||
```
|
||||
|
||||
**Response schema:** Same as prompt hooks
|
||||
|
||||
### Async hooks
|
||||
|
||||
**For command hooks only:**
|
||||
```json
|
||||
{
|
||||
"type": "command",
|
||||
"command": "...",
|
||||
"async": true,
|
||||
"timeout": 300
|
||||
}
|
||||
```
|
||||
|
||||
- Doesn't block Claude's execution
|
||||
- Cannot return decisions
|
||||
- Output delivered on next conversation turn
|
||||
- Max 50 turns per session
|
||||
|
||||
---
|
||||
|
||||
See https://code.claude.com/docs/en/hooks for full reference
|
||||
@@ -1,390 +0,0 @@
|
||||
# Claude Code Hooks - 快速参考
|
||||
|
||||
## 12 个官方钩子事件
|
||||
|
||||
| # | 事件名称 | 触发时机 | 可阻止 | 匹配器 |
|
||||
|---|---------|---------|--------|--------|
|
||||
| 1 | `SessionStart` | 会话开始/恢复 | ❌ | startup, resume, clear, compact |
|
||||
| 2 | `UserPromptSubmit` | 用户提交提示词前 | ✅ | ❌ 不支持 |
|
||||
| 3 | `PreToolUse` | 工具调用前 | ✅ | 工具名称 |
|
||||
| 4 | `PermissionRequest` | 权限对话时 | ✅ | 工具名称 |
|
||||
| 5 | `PostToolUse` | 工具成功后 | ❌ | 工具名称 |
|
||||
| 6 | `PostToolUseFailure` | 工具失败后 | ❌ | 工具名称 |
|
||||
| 7 | `Notification` | 发送通知时 | ❌ | 通知类型 |
|
||||
| 8 | `SubagentStart` | 子代理开始 | ❌ | 代理类型 |
|
||||
| 9 | `SubagentStop` | 子代理完成 | ✅ | 代理类型 |
|
||||
| 10 | `Stop` | Claude完成响应 | ✅ | ❌ 不支持 |
|
||||
| 11 | `PreCompact` | 上下文压缩前 | ❌ | manual, auto |
|
||||
| 12 | `SessionEnd` | 会话终止 | ❌ | 终止原因 |
|
||||
|
||||
---
|
||||
|
||||
## 配置模板
|
||||
|
||||
### 基础结构
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"EventName": [
|
||||
{
|
||||
"matcher": "pattern",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command|prompt|agent",
|
||||
"command": "...",
|
||||
"timeout": 600,
|
||||
"async": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 工具名称(用于匹配器)
|
||||
|
||||
### 内置工具
|
||||
```
|
||||
Bash, Edit, Write, Read, Glob, Grep, Task, WebFetch, WebSearch
|
||||
```
|
||||
|
||||
### MCP 工具
|
||||
```
|
||||
mcp__<server>__<tool>
|
||||
mcp__memory__.*
|
||||
mcp__.*__write.*
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Exit Codes
|
||||
|
||||
| Code | 含义 | Claude反馈 |
|
||||
|------|------|-----------|
|
||||
| 0 | 成功 | 解析 stdout JSON,允许操作 |
|
||||
| 2 | 阻止 | stderr 发送给 Claude,阻止操作 |
|
||||
| 其他 | 错误 | stderr 仅在详细模式显示 |
|
||||
|
||||
---
|
||||
|
||||
## 标准 JSON 输入(stdin)
|
||||
|
||||
```json
|
||||
{
|
||||
"session_id": "abc123",
|
||||
"transcript_path": "/path/to/transcript.jsonl",
|
||||
"cwd": "/current/dir",
|
||||
"permission_mode": "default",
|
||||
"hook_event_name": "PreToolUse",
|
||||
"tool_name": "Bash",
|
||||
"tool_input": {
|
||||
"command": "npm test"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 标准 JSON 输出(stdout, exit 0)
|
||||
|
||||
### PreToolUse
|
||||
```json
|
||||
{
|
||||
"hookSpecificOutput": {
|
||||
"hookEventName": "PreToolUse",
|
||||
"permissionDecision": "allow|deny|ask",
|
||||
"permissionDecisionReason": "explanation"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### UserPromptSubmit
|
||||
```json
|
||||
{
|
||||
"decision": "block",
|
||||
"reason": "explanation",
|
||||
"hookSpecificOutput": {
|
||||
"hookEventName": "UserPromptSubmit",
|
||||
"additionalContext": "context string"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Stop
|
||||
```json
|
||||
{
|
||||
"decision": "block",
|
||||
"reason": "Must complete tasks X, Y, Z"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 处理器类型
|
||||
|
||||
### 1. Command Hook
|
||||
```json
|
||||
{
|
||||
"type": "command",
|
||||
"command": "bash /path/to/script.sh",
|
||||
"timeout": 600,
|
||||
"async": false
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Prompt Hook
|
||||
```json
|
||||
{
|
||||
"type": "prompt",
|
||||
"prompt": "Evaluate: $ARGUMENTS",
|
||||
"model": "haiku",
|
||||
"timeout": 30
|
||||
}
|
||||
```
|
||||
|
||||
响应格式:
|
||||
```json
|
||||
{
|
||||
"ok": true|false,
|
||||
"reason": "explanation if ok is false"
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Agent Hook
|
||||
```json
|
||||
{
|
||||
"type": "agent",
|
||||
"prompt": "Verify tests pass: $ARGUMENTS",
|
||||
"model": "haiku",
|
||||
"timeout": 60
|
||||
}
|
||||
```
|
||||
|
||||
响应格式:与 Prompt Hook 相同
|
||||
|
||||
---
|
||||
|
||||
## 环境变量
|
||||
|
||||
### 标准变量
|
||||
```bash
|
||||
$CLAUDE_PROJECT_DIR # 项目根目录
|
||||
$CLAUDE_PLUGIN_ROOT # 插件根目录(插件内部使用)
|
||||
$CLAUDE_CODE_REMOTE # "true" 在远程环境
|
||||
```
|
||||
|
||||
### SessionStart 特殊变量
|
||||
```bash
|
||||
$CLAUDE_ENV_FILE # 持久化环境变量的文件路径
|
||||
```
|
||||
|
||||
用法:
|
||||
```bash
|
||||
#!/bin/bash
|
||||
if [ -n "$CLAUDE_ENV_FILE" ]; then
|
||||
echo 'export NODE_ENV=production' >> "$CLAUDE_ENV_FILE"
|
||||
fi
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 常见用例
|
||||
|
||||
### 1. 格式化代码
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"PostToolUse": [
|
||||
{
|
||||
"matcher": "Edit|Write",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "jq -r '.tool_input.file_path' | xargs prettier --write"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 阻止危险命令
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"PreToolUse": [
|
||||
{
|
||||
"matcher": "Bash",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-rm.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
脚本 `block-rm.sh`:
|
||||
```bash
|
||||
#!/bin/bash
|
||||
COMMAND=$(jq -r '.tool_input.command')
|
||||
if echo "$COMMAND" | grep -q 'rm -rf'; then
|
||||
echo "Blocked: rm -rf is not allowed" >&2
|
||||
exit 2
|
||||
fi
|
||||
exit 0
|
||||
```
|
||||
|
||||
### 3. 通知用户
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"Notification": [
|
||||
{
|
||||
"matcher": "permission_prompt",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "osascript -e 'display notification \"Claude needs your attention\"'"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4. 确认任务完成
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"Stop": [
|
||||
{
|
||||
"hooks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"prompt": "Check if all tasks complete: $ARGUMENTS"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 5. 异步运行测试
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"PostToolUse": [
|
||||
{
|
||||
"matcher": "Write",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "/path/to/run-tests.sh",
|
||||
"async": true,
|
||||
"timeout": 120
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 6. 会话开始注入上下文
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"SessionStart": [
|
||||
{
|
||||
"matcher": "compact",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "echo 'Reminder: use Bun, not npm'"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 配置位置
|
||||
|
||||
| 位置 | 作用域 | 可共享 |
|
||||
|------|--------|--------|
|
||||
| `~/.claude/settings.json` | 全局用户 | ❌ |
|
||||
| `.claude/settings.json` | 单个项目 | ✅ |
|
||||
| `.claude/settings.local.json` | 单个项目 | ❌ (gitignored) |
|
||||
| 插件 `hooks/hooks.json` | 插件启用时 | ✅ |
|
||||
| Skill/Agent frontmatter | 组件活动时 | ✅ |
|
||||
|
||||
---
|
||||
|
||||
## 调试技巧
|
||||
|
||||
### 1. 详细模式
|
||||
```bash
|
||||
claude --debug # 查看完整钩子执行细节
|
||||
Ctrl+O # 切换详细模式(实时)
|
||||
```
|
||||
|
||||
### 2. 测试钩子脚本
|
||||
```bash
|
||||
echo '{"tool_name":"Bash","tool_input":{"command":"ls"}}' | ./my-hook.sh
|
||||
echo $? # 检查退出码
|
||||
```
|
||||
|
||||
### 3. 检查钩子配置
|
||||
```
|
||||
/hooks # 交互式钩子管理器
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 最佳实践
|
||||
|
||||
✅ **推荐:**
|
||||
- 总是引用 shell 变量:`"$VAR"`
|
||||
- 使用绝对路径:`"$CLAUDE_PROJECT_DIR"/script.sh`
|
||||
- 设置合理的超时时间
|
||||
- 验证和清理输入数据
|
||||
- 在 Stop 钩子中检查 `stop_hook_active`
|
||||
- 使用 async 进行长时间运行的操作
|
||||
|
||||
❌ **避免:**
|
||||
- 直接信任输入数据
|
||||
- 使用相对路径
|
||||
- 在钩子输出中暴露敏感数据
|
||||
- 创建无限循环(尤其在 Stop 钩子)
|
||||
- 没有设置超时的阻塞操作
|
||||
|
||||
---
|
||||
|
||||
## 官方资源
|
||||
|
||||
- **指南**: https://code.claude.com/docs/en/hooks-guide
|
||||
- **参考**: https://code.claude.com/docs/en/hooks
|
||||
- **示例**: https://github.com/anthropics/claude-code/tree/main/examples/hooks
|
||||
|
||||
---
|
||||
|
||||
## 本地文档
|
||||
|
||||
- `HOOKS_OFFICIAL_GUIDE.md` - 官方指南中文版
|
||||
- `HOOKS_OFFICIAL_REFERENCE.md` - 官方参考中文版
|
||||
- `HOOKS_ANALYSIS_REPORT.md` - 当前实现对比分析
|
||||
- `hooks_bash_command_validator.py` - 官方示例脚本
|
||||
@@ -1,85 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Claude Code Hook: Bash Command Validator
|
||||
=========================================
|
||||
This hook runs as a PreToolUse hook for the Bash tool.
|
||||
It validates bash commands against a set of rules before execution.
|
||||
In this case it changes grep calls to using rg.
|
||||
|
||||
Read more about hooks here: https://code.claude.com/docs/en/hooks
|
||||
|
||||
Make sure to change your path to your actual script.
|
||||
|
||||
Configuration for .claude/settings.json:
|
||||
|
||||
{
|
||||
"hooks": {
|
||||
"PreToolUse": [
|
||||
{
|
||||
"matcher": "Bash",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "python3 /path/to/bash_command_validator.py"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
|
||||
# Define validation rules as a list of (regex pattern, message) tuples
|
||||
_VALIDATION_RULES = [
|
||||
(
|
||||
r"^grep\b(?!.*\|)",
|
||||
"Use 'rg' (ripgrep) instead of 'grep' for better performance and features",
|
||||
),
|
||||
(
|
||||
r"^find\s+\S+\s+-name\b",
|
||||
"Use 'rg --files | rg pattern' or 'rg --files -g pattern' instead of 'find -name' for better performance",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def _validate_command(command: str) -> list[str]:
|
||||
issues = []
|
||||
for pattern, message in _VALIDATION_RULES:
|
||||
if re.search(pattern, command):
|
||||
issues.append(message)
|
||||
return issues
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
input_data = json.load(sys.stdin)
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"Error: Invalid JSON input: {e}", file=sys.stderr)
|
||||
# Exit code 1 shows stderr to the user but not to Claude
|
||||
sys.exit(1)
|
||||
|
||||
tool_name = input_data.get("tool_name", "")
|
||||
if tool_name != "Bash":
|
||||
sys.exit(0)
|
||||
|
||||
tool_input = input_data.get("tool_input", {})
|
||||
command = tool_input.get("command", "")
|
||||
|
||||
if not command:
|
||||
sys.exit(0)
|
||||
|
||||
issues = _validate_command(command)
|
||||
if issues:
|
||||
for message in issues:
|
||||
print(f"• {message}", file=sys.stderr)
|
||||
# Exit code 2 blocks tool call and shows stderr to Claude
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
381
.claude/skills/brainstorm/SKILL.md
Normal file
381
.claude/skills/brainstorm/SKILL.md
Normal file
@@ -0,0 +1,381 @@
|
||||
---
|
||||
name: brainstorm
|
||||
description: Unified brainstorming skill with dual-mode operation - auto pipeline and single role analysis. Triggers on "brainstorm", "头脑风暴".
|
||||
allowed-tools: Skill(*), Task(conceptual-planning-agent, context-search-agent), AskUserQuestion(*), TodoWrite(*), Read(*), Write(*), Edit(*), Glob(*), Bash(*)
|
||||
---
|
||||
|
||||
# Brainstorm
|
||||
|
||||
Unified brainstorming skill combining interactive framework generation, multi-role parallel analysis, and cross-role synthesis into a single entry point with two operational modes.
|
||||
|
||||
## Architecture Overview
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ /brainstorm │
|
||||
│ Unified Entry Point + Interactive Routing │
|
||||
└───────────────────────┬─────────────────────────────────────┘
|
||||
│
|
||||
┌─────────┴─────────┐
|
||||
↓ ↓
|
||||
┌─────────────────┐ ┌──────────────────┐
|
||||
│ Auto Mode │ │ Single Role Mode │
|
||||
│ (自动模式) │ │ (单角色分析模式) │
|
||||
└────────┬────────┘ └────────┬─────────┘
|
||||
│ │
|
||||
┌────────┼────────┐ │
|
||||
↓ ↓ ↓ ↓
|
||||
Phase 2 Phase 3 Phase 4 Phase 3
|
||||
Artifacts N×Role Synthesis 1×Role
|
||||
(7步) Analysis (8步) Analysis
|
||||
并行 (4步)
|
||||
```
|
||||
|
||||
**Data Flow**:
|
||||
```
|
||||
Auto Mode:
|
||||
Phase 2 (artifacts) → guidance-specification.md + selected_roles[]
|
||||
→ Phase 3 (N × role-analysis) → {role}/analysis*.md
|
||||
→ Phase 4 (synthesis) → feature-specs/ + feature-index.json
|
||||
|
||||
Single Role Mode:
|
||||
Phase 3 (1 × role-analysis) → {role}/analysis*.md
|
||||
```
|
||||
|
||||
## Key Design Principles
|
||||
|
||||
1. **Dual-Mode Routing**: Interactive mode selection via AskUserQuestion, with parameter-based auto-detection
|
||||
2. **Progressive Phase Loading**: Phase files loaded on-demand via `Ref:` markers, not all at once
|
||||
3. **Task Attachment/Collapse**: Sub-tasks attached during phase execution, collapsed after completion
|
||||
4. **Session Continuity**: All phases share session state via workflow-session.json
|
||||
5. **Auto-Continue Execution**: Phases chain automatically without user intervention between them
|
||||
|
||||
## Auto Mode
|
||||
|
||||
When `--yes` or `-y`: Auto-select auto mode, skip interactive routing question, auto-select recommended roles, skip all clarification questions, use default answers.
|
||||
|
||||
## Execution Flow
|
||||
|
||||
### Phase 1: Mode Detection & Interactive Routing
|
||||
Ref: phases/01-mode-routing.md
|
||||
|
||||
Parse arguments, detect mode from flags/parameters, or ask user via AskUserQuestion.
|
||||
|
||||
**Mode Detection Rules**:
|
||||
1. If `--yes` or `-y` flag present → **Auto Mode** (no question asked)
|
||||
2. If first arg matches a known role name → **Single Role Mode** (no question asked)
|
||||
3. If `--session` flag present without role name → **Ask user**
|
||||
4. Otherwise → **Ask user via AskUserQuestion**
|
||||
|
||||
**Output**: `execution_mode` ("auto" | "single-role"), parsed parameters
|
||||
|
||||
---
|
||||
|
||||
### Auto Mode Execution (execution_mode = "auto")
|
||||
|
||||
#### Phase 2: Interactive Framework Generation
|
||||
Ref: phases/02-artifacts.md
|
||||
|
||||
Seven-phase interactive workflow: Context collection → Topic analysis → Role selection → Role questions → Conflict resolution → Final check → Generate specification.
|
||||
|
||||
**Input**: topic description, --count N, --yes flag
|
||||
**Output**: guidance-specification.md, workflow-session.json (selected_roles[], session_id)
|
||||
|
||||
**TodoWrite**: Attach 7 sub-tasks (Phase 0-5), execute sequentially, collapse on completion.
|
||||
|
||||
#### Phase 3: Parallel Role Analysis
|
||||
Ref: phases/03-role-analysis.md
|
||||
|
||||
Execute role analysis for EACH selected role in parallel.
|
||||
|
||||
**Input**: selected_roles[] from Phase 2, session_id, guidance-specification.md
|
||||
**Output**: {role}/analysis*.md for each role
|
||||
|
||||
**Parallel Execution**: Launch N role-analysis calls simultaneously (one message with multiple Skill invokes). Each role with `--skip-questions` flag.
|
||||
|
||||
For ui-designer: append `--style-skill {package}` if provided.
|
||||
|
||||
**TodoWrite**: Attach N parallel sub-tasks, execute concurrently, collapse on completion.
|
||||
|
||||
#### Phase 4: Synthesis Integration
|
||||
Ref: phases/04-synthesis.md
|
||||
|
||||
Eight-phase cross-role synthesis: Discovery → File discovery → Cross-role analysis → User interaction → Document updates → Feature spec generation → Feature index → Finalization.
|
||||
|
||||
**Input**: session_id from Phase 2, all role analysis files from Phase 3
|
||||
**Output**: Updated analyses, feature-specs/, feature-index.json
|
||||
|
||||
**TodoWrite**: Attach synthesis sub-tasks, execute sequentially, collapse on completion.
|
||||
|
||||
---
|
||||
|
||||
### Single Role Mode Execution (execution_mode = "single-role")
|
||||
|
||||
#### Phase 3: Single Role Analysis
|
||||
Ref: phases/03-role-analysis.md
|
||||
|
||||
Execute role analysis for ONE specified role with optional interactive context gathering.
|
||||
|
||||
**Input**: role_name, --session, --update, --include-questions, --skip-questions, --style-skill
|
||||
**Output**: {role}/analysis*.md
|
||||
|
||||
**TodoWrite**: Attach 4 sub-tasks (Detection → Context → Agent → Validation), execute sequentially.
|
||||
|
||||
---
|
||||
|
||||
**Phase Reference Documents** (read on-demand when phase executes):
|
||||
|
||||
| Phase | Document | Purpose | Used By |
|
||||
|-------|----------|---------|---------|
|
||||
| 1 | [phases/01-mode-routing.md](phases/01-mode-routing.md) | Parameter parsing, mode detection, interactive routing | Both modes |
|
||||
| 2 | [phases/02-artifacts.md](phases/02-artifacts.md) | Interactive framework generation (7 phases) | Auto mode only |
|
||||
| 3 | [phases/03-role-analysis.md](phases/03-role-analysis.md) | Role-specific analysis generation | Both modes |
|
||||
| 4 | [phases/04-synthesis.md](phases/04-synthesis.md) | Cross-role synthesis and feature specs | Auto mode only |
|
||||
|
||||
## Core Rules
|
||||
|
||||
1. **Start with Mode Detection**: First action is Phase 1 (parse args + detect mode)
|
||||
2. **Interactive Routing**: If mode cannot be determined from args, ASK user via AskUserQuestion
|
||||
3. **No Preliminary Analysis**: Do not analyze topic before Phase 2 - artifacts handles all analysis
|
||||
4. **Parse Every Output**: Extract selected_roles from workflow-session.json after Phase 2
|
||||
5. **Auto-Continue via TodoList**: Check TodoList status to execute next pending phase automatically
|
||||
6. **Task Attachment Model**: Skill and Task executes attach sub-tasks to current workflow
|
||||
7. **⚠️ CRITICAL: DO NOT STOP**: Continuous multi-phase workflow in auto mode. After executing all attached tasks, immediately collapse them and execute next phase
|
||||
8. **Parallel Execution**: Auto mode Phase 3 attaches multiple agent tasks simultaneously for concurrent execution
|
||||
9. **Single Role Independence**: Single role mode operates independently without requiring artifacts or synthesis
|
||||
|
||||
## Input Processing
|
||||
|
||||
### Parameter Parsing
|
||||
|
||||
```javascript
|
||||
// Parse from user input (argument string)
|
||||
const args = parseArguments(user_input);
|
||||
|
||||
// Flags
|
||||
const auto_yes = args.includes('--yes') || args.includes('-y');
|
||||
const count = extractFlag(args, '--count', 3); // default 3, max 9
|
||||
const session_id = extractFlag(args, '--session', null);
|
||||
const update_mode = args.includes('--update');
|
||||
const include_questions = args.includes('--include-questions');
|
||||
const skip_questions = args.includes('--skip-questions');
|
||||
const style_skill = extractFlag(args, '--style-skill', null);
|
||||
|
||||
// Role detection
|
||||
const VALID_ROLES = [
|
||||
'data-architect', 'product-manager', 'product-owner', 'scrum-master',
|
||||
'subject-matter-expert', 'system-architect', 'test-strategist',
|
||||
'ui-designer', 'ux-expert'
|
||||
];
|
||||
const first_arg = args[0]; // first non-flag argument
|
||||
const is_role = VALID_ROLES.includes(first_arg);
|
||||
|
||||
// Mode detection
|
||||
if (auto_yes) {
|
||||
execution_mode = 'auto';
|
||||
topic = extractTopic(args);
|
||||
} else if (is_role) {
|
||||
execution_mode = 'single-role';
|
||||
role_name = first_arg;
|
||||
} else {
|
||||
execution_mode = null; // Ask user
|
||||
topic = extractTopic(args);
|
||||
}
|
||||
```
|
||||
|
||||
### Usage Examples
|
||||
|
||||
```bash
|
||||
# Auto mode - full pipeline
|
||||
/brainstorm "Build real-time collaboration platform" --count 3
|
||||
/brainstorm -y "GOAL: Build platform SCOPE: 100 users" --count 5
|
||||
/brainstorm "Design payment system" --style-skill material-design
|
||||
|
||||
# Single role mode - individual analysis
|
||||
/brainstorm system-architect --session WFS-xxx
|
||||
/brainstorm ux-expert --include-questions
|
||||
/brainstorm ui-designer --session WFS-xxx --update --style-skill material-design
|
||||
/brainstorm product-manager --skip-questions
|
||||
|
||||
# Ambiguous - will ask interactively
|
||||
/brainstorm --session WFS-xxx
|
||||
/brainstorm
|
||||
```
|
||||
|
||||
## Data Flow
|
||||
|
||||
```
|
||||
Phase 1 (Mode Routing):
|
||||
Input: user arguments
|
||||
Output: execution_mode, parsed_params
|
||||
↓
|
||||
┌───────┴───────┐
|
||||
Auto Single Role
|
||||
↓ ↓
|
||||
Phase 2: Phase 3:
|
||||
Input: topic, count, auto_yes
|
||||
Output: session_id ─────────────→ Input: role_name, session_id
|
||||
selected_roles[] skip/include questions
|
||||
guidance-specification.md style_skill
|
||||
↓ Output: {role}/analysis*.md
|
||||
Phase 3:
|
||||
Input: selected_roles[], session_id
|
||||
guidance-specification.md
|
||||
style_skill (for ui-designer)
|
||||
Output: {role}/analysis*.md (N files)
|
||||
↓
|
||||
Phase 4:
|
||||
Input: session_id, all analysis files
|
||||
Output: Updated analyses
|
||||
feature-specs/F-{id}-{slug}.md
|
||||
feature-index.json
|
||||
```
|
||||
|
||||
## TodoWrite Pattern
|
||||
|
||||
### Auto Mode Lifecycle
|
||||
|
||||
```
|
||||
Initial → Phase 1 Mode Routing (completed)
|
||||
→ Phase 2 Artifacts (in_progress)
|
||||
→ 7 sub-tasks ATTACHED (Phase 0-5)
|
||||
→ Execute sequentially
|
||||
→ Sub-tasks COLLAPSED
|
||||
→ Phase 3 Parallel Role Analysis (in_progress)
|
||||
→ N role sub-tasks ATTACHED simultaneously
|
||||
→ Execute concurrently
|
||||
→ Sub-tasks COLLAPSED
|
||||
→ Phase 4 Synthesis (in_progress)
|
||||
→ 8 sub-tasks ATTACHED
|
||||
→ Execute sequentially
|
||||
→ Sub-tasks COLLAPSED
|
||||
→ All completed
|
||||
```
|
||||
|
||||
### Single Role Mode Lifecycle
|
||||
|
||||
```
|
||||
Initial → Phase 1 Mode Routing (completed)
|
||||
→ Phase 3 Role Analysis (in_progress)
|
||||
→ 4 sub-tasks ATTACHED (Detection → Context → Agent → Validation)
|
||||
→ Execute sequentially
|
||||
→ Sub-tasks COLLAPSED
|
||||
→ Completed
|
||||
```
|
||||
|
||||
### Initial TodoWrite (Auto Mode)
|
||||
|
||||
```json
|
||||
[
|
||||
{"content": "Phase 1: Mode detection and parameter parsing", "status": "in_progress", "activeForm": "Detecting mode"},
|
||||
{"content": "Phase 2: Interactive Framework Generation", "status": "pending", "activeForm": "Generating framework"},
|
||||
{"content": "Phase 3: Parallel Role Analysis", "status": "pending", "activeForm": "Executing parallel analysis"},
|
||||
{"content": "Phase 4: Synthesis Integration", "status": "pending", "activeForm": "Executing synthesis"}
|
||||
]
|
||||
```
|
||||
|
||||
### Initial TodoWrite (Single Role Mode)
|
||||
|
||||
```json
|
||||
[
|
||||
{"content": "Phase 1: Mode detection and parameter parsing", "status": "in_progress", "activeForm": "Detecting mode"},
|
||||
{"content": "Phase 3: Single role analysis for {role_name}", "status": "pending", "activeForm": "Executing role analysis"}
|
||||
]
|
||||
```
|
||||
|
||||
## Session Management
|
||||
|
||||
**⚡ FIRST ACTION**: Check `.workflow/active/` for existing sessions
|
||||
|
||||
**Multiple Sessions Support**:
|
||||
- Different Claude instances can have different brainstorming sessions
|
||||
- If multiple sessions found, prompt user to select
|
||||
- If single session found, use it
|
||||
- If no session exists:
|
||||
- Auto mode: Create `WFS-[topic-slug]`
|
||||
- Single role mode: ERROR if no session (must run auto mode first)
|
||||
|
||||
**Session Continuity**: All phases share session state via `workflow-session.json`
|
||||
|
||||
## Available Roles
|
||||
|
||||
| Role ID | Title | Focus Area |
|
||||
|---------|-------|------------|
|
||||
| `data-architect` | 数据架构师 | Data models, storage strategies, data flow |
|
||||
| `product-manager` | 产品经理 | Product strategy, roadmap, prioritization |
|
||||
| `product-owner` | 产品负责人 | Backlog management, user stories, acceptance criteria |
|
||||
| `scrum-master` | 敏捷教练 | Process facilitation, impediment removal |
|
||||
| `subject-matter-expert` | 领域专家 | Domain knowledge, business rules, compliance |
|
||||
| `system-architect` | 系统架构师 | Technical architecture, scalability, integration |
|
||||
| `test-strategist` | 测试策略师 | Test strategy, quality assurance |
|
||||
| `ui-designer` | UI设计师 | Visual design, mockups, design systems |
|
||||
| `ux-expert` | UX专家 | User research, information architecture, journey |
|
||||
|
||||
**Role Selection**: Auto mode → handled by artifacts (Phase 2). Single role mode → user specifies directly.
|
||||
|
||||
## Output Structure
|
||||
|
||||
```
|
||||
.workflow/active/WFS-{topic}/
|
||||
├── workflow-session.json # Session metadata ONLY
|
||||
├── .process/
|
||||
│ └── context-package.json # Phase 0 output (auto mode)
|
||||
└── .brainstorming/
|
||||
├── guidance-specification.md # Framework (Phase 2, auto mode)
|
||||
├── feature-index.json # Feature index (Phase 4, auto mode)
|
||||
├── feature-specs/ # Feature specs (Phase 4, auto mode)
|
||||
│ ├── F-001-{slug}.md
|
||||
│ └── F-00N-{slug}.md
|
||||
├── {role}/
|
||||
│ ├── {role}-context.md # Interactive Q&A responses
|
||||
│ ├── analysis.md # Main/index document
|
||||
│ ├── analysis-cross-cutting.md # Cross-feature (feature_mode)
|
||||
│ └── analysis-F-{id}-{slug}.md # Per-feature (feature_mode)
|
||||
└── synthesis-specification.md # Integration (Phase 4, auto mode)
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Error | Recovery | Mode |
|
||||
|-------|----------|------|
|
||||
| Invalid role name | Show valid roles list, ask again | Single Role |
|
||||
| No active session | Auto mode: create new. Single role: error with guidance | Both |
|
||||
| Role selection failure | Default to product-manager | Auto |
|
||||
| Agent execution failure | Agent-specific retry with minimal dependencies | Both |
|
||||
| Template loading issues | Graceful degradation | Both |
|
||||
| Synthesis conflicts | Highlight disagreements without forced resolution | Auto |
|
||||
| Context overflow (>100KB) | Read only analysis.md index files | Auto |
|
||||
|
||||
**Context Overflow Protection**:
|
||||
- Per-role limits: < 3000 words main, < 2000 words sub-docs, max 5 sub-docs
|
||||
- Synthesis protection: If total > 100KB, read only `analysis.md` (not sub-documents)
|
||||
- Recovery: reduce scope (--count 2) → use --summary-only → manual synthesis
|
||||
|
||||
## Coordinator Checklist
|
||||
|
||||
**Pre-Phase Actions**:
|
||||
- [ ] Read Phase document via `Ref:` marker
|
||||
- [ ] Verify prerequisites (session exists, required files present)
|
||||
- [ ] Mark phase as `in_progress` in TodoWrite
|
||||
- [ ] Attach sub-tasks if applicable
|
||||
|
||||
**Post-Phase Actions**:
|
||||
- [ ] Validate phase outputs exist
|
||||
- [ ] Collapse sub-tasks to phase summary
|
||||
- [ ] Mark phase as `completed` in TodoWrite
|
||||
- [ ] Auto-continue to next pending phase (auto mode)
|
||||
- [ ] Report completion (single role mode)
|
||||
|
||||
## Related Commands
|
||||
|
||||
**Prerequisites**:
|
||||
- `/workflow:session:start` - Start a new workflow session (optional, brainstorm creates its own)
|
||||
|
||||
**Follow-ups** (after brainstorm completes):
|
||||
- `/workflow:plan --session {sessionId}` - Generate implementation plan
|
||||
- `/workflow:brainstorm:synthesis --session {sessionId}` - Run synthesis standalone (if skipped)
|
||||
|
||||
## Reference Information
|
||||
|
||||
**Template Source**: `~/.ccw/workflows/cli-templates/planning-roles/`
|
||||
**Style SKILL Packages**: `.claude/skills/style-{package-name}/`
|
||||
207
.claude/skills/brainstorm/phases/01-mode-routing.md
Normal file
207
.claude/skills/brainstorm/phases/01-mode-routing.md
Normal file
@@ -0,0 +1,207 @@
|
||||
# Phase 1: Mode Detection & Interactive Routing
|
||||
|
||||
Parse user arguments, detect execution mode from flags/parameters, or interactively ask the user which mode to use via AskUserQuestion.
|
||||
|
||||
## Objective
|
||||
|
||||
- Parse all command arguments and flags
|
||||
- Detect execution mode automatically when possible
|
||||
- Ask user via AskUserQuestion when mode is ambiguous
|
||||
- Initialize TodoWrite with mode-appropriate task list
|
||||
- Route to correct execution path
|
||||
|
||||
## Execution
|
||||
|
||||
### Step 1.1: Parameter Parsing
|
||||
|
||||
```javascript
|
||||
// Parse from user input (argument string)
|
||||
const args = parseArguments(user_input);
|
||||
|
||||
// Flags
|
||||
const auto_yes = args.includes('--yes') || args.includes('-y');
|
||||
const count = extractFlag(args, '--count', 3); // default 3, max 9
|
||||
if (count > 9) count = 9; // Cap at maximum
|
||||
const session_id = extractFlag(args, '--session', null);
|
||||
const update_mode = args.includes('--update');
|
||||
const include_questions = args.includes('--include-questions');
|
||||
const skip_questions = args.includes('--skip-questions');
|
||||
const style_skill = extractFlag(args, '--style-skill', null);
|
||||
|
||||
// Role detection
|
||||
const VALID_ROLES = [
|
||||
'data-architect', 'product-manager', 'product-owner', 'scrum-master',
|
||||
'subject-matter-expert', 'system-architect', 'test-strategist',
|
||||
'ui-designer', 'ux-expert'
|
||||
];
|
||||
const first_arg = getFirstNonFlagArg(args);
|
||||
const is_role = VALID_ROLES.includes(first_arg);
|
||||
|
||||
// Topic extraction (everything that's not a flag or role)
|
||||
const topic = is_role ? null : extractTopic(args);
|
||||
```
|
||||
|
||||
### Step 1.2: Style-Skill Validation
|
||||
|
||||
```javascript
|
||||
if (style_skill) {
|
||||
const skill_path = `.claude/skills/style-${style_skill}/SKILL.md`;
|
||||
if (fileExists(skill_path)) {
|
||||
style_skill_package = style_skill;
|
||||
style_reference_path = `.workflow/reference_style/${style_skill}`;
|
||||
// "✓ Style SKILL package found: style-{style_skill}"
|
||||
} else {
|
||||
// "⚠ WARNING: Style SKILL package not found: {style_skill}"
|
||||
style_skill_package = null;
|
||||
}
|
||||
} else {
|
||||
style_skill_package = null;
|
||||
}
|
||||
```
|
||||
|
||||
### Step 1.3: Mode Detection
|
||||
|
||||
```javascript
|
||||
// Auto-detection rules (ordered by priority)
|
||||
if (auto_yes) {
|
||||
// --yes flag explicitly requests auto mode
|
||||
execution_mode = 'auto';
|
||||
} else if (is_role) {
|
||||
// First arg is a valid role name → single role mode
|
||||
execution_mode = 'single-role';
|
||||
role_name = first_arg;
|
||||
} else if (topic && !session_id) {
|
||||
// Topic provided without session → likely auto mode, but ask
|
||||
execution_mode = null; // Ask user
|
||||
} else {
|
||||
// Ambiguous → ask user
|
||||
execution_mode = null;
|
||||
}
|
||||
```
|
||||
|
||||
### Step 1.4: Interactive Mode Selection (when mode is null)
|
||||
|
||||
```javascript
|
||||
if (execution_mode === null) {
|
||||
AskUserQuestion({
|
||||
questions: [{
|
||||
question: "请选择头脑风暴模式",
|
||||
header: "模式选择",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{
|
||||
label: "自动模式 (推荐)",
|
||||
description: "完整流程:框架生成 → 多角色并行分析 → 跨角色综合。适合新主题的全面分析"
|
||||
},
|
||||
{
|
||||
label: "单角色分析",
|
||||
description: "为单个角色生成分析文档。适合补充已有会话的角色视角或迭代更新"
|
||||
}
|
||||
]
|
||||
}]
|
||||
});
|
||||
|
||||
// Route based on user selection
|
||||
if (user_selected === "自动模式 (推荐)") {
|
||||
execution_mode = 'auto';
|
||||
} else {
|
||||
execution_mode = 'single-role';
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Step 1.5: Single Role Mode - Role Selection (if needed)
|
||||
|
||||
When entering single-role mode without a role name specified:
|
||||
|
||||
```javascript
|
||||
if (execution_mode === 'single-role' && !role_name) {
|
||||
// Need to ask which role
|
||||
AskUserQuestion({
|
||||
questions: [{
|
||||
question: "请选择要执行分析的角色",
|
||||
header: "角色选择",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "system-architect", description: "系统架构师 - 技术架构、可扩展性、集成模式" },
|
||||
{ label: "ux-expert", description: "UX专家 - 用户研究、信息架构、用户旅程" },
|
||||
{ label: "product-manager", description: "产品经理 - 产品策略、路线图、优先级" },
|
||||
{ label: "ui-designer", description: "UI设计师 - 视觉设计、高保真原型、设计系统" }
|
||||
]
|
||||
}]
|
||||
});
|
||||
// Note: If user needs a role not in top 4, they select "Other" and type it
|
||||
role_name = user_selected;
|
||||
|
||||
// Validate role name
|
||||
if (!VALID_ROLES.includes(role_name)) {
|
||||
// ERROR with valid roles list
|
||||
// EXIT
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Step 1.6: Session Detection
|
||||
|
||||
```javascript
|
||||
if (!session_id) {
|
||||
// Find active sessions
|
||||
const sessions = Glob('.workflow/active/WFS-*/');
|
||||
|
||||
if (sessions.length > 1) {
|
||||
// Multiple sessions → ask user to select
|
||||
// Use AskUserQuestion with session list
|
||||
} else if (sessions.length === 1) {
|
||||
session_id = extractSessionId(sessions[0]);
|
||||
} else {
|
||||
if (execution_mode === 'auto') {
|
||||
// Will be created by artifacts phase
|
||||
session_id = null; // artifacts handles creation
|
||||
} else {
|
||||
// Single role mode requires existing session
|
||||
// ERROR: "No active session. Run /brainstorm 'topic' first"
|
||||
// EXIT
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Step 1.7: Initialize TodoWrite
|
||||
|
||||
```javascript
|
||||
if (execution_mode === 'auto') {
|
||||
TodoWrite({
|
||||
todos: [
|
||||
{ content: "Phase 1: Mode detection and parameter parsing", status: "completed", activeForm: "Detecting mode" },
|
||||
{ content: "Phase 2: Interactive Framework Generation", status: "pending", activeForm: "Generating framework" },
|
||||
{ content: "Phase 3: Parallel Role Analysis", status: "pending", activeForm: "Executing parallel analysis" },
|
||||
{ content: "Phase 4: Synthesis Integration", status: "pending", activeForm: "Executing synthesis" }
|
||||
]
|
||||
});
|
||||
} else {
|
||||
TodoWrite({
|
||||
todos: [
|
||||
{ content: "Phase 1: Mode detection and parameter parsing", status: "completed", activeForm: "Detecting mode" },
|
||||
{ content: `Phase 3: ${role_name} analysis`, status: "pending", activeForm: `Executing ${role_name} analysis` }
|
||||
]
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## Output
|
||||
|
||||
- **Variable**: `execution_mode` ("auto" | "single-role")
|
||||
- **Variable**: `role_name` (single-role mode only)
|
||||
- **Variable**: `topic` (auto mode only)
|
||||
- **Variable**: `session_id` (may be null for auto mode - artifacts creates it)
|
||||
- **Variable**: `count` (auto mode, default 3)
|
||||
- **Variable**: `auto_yes` (boolean)
|
||||
- **Variable**: `style_skill_package` (optional)
|
||||
- **Variable**: `update_mode`, `include_questions`, `skip_questions` (single-role flags)
|
||||
- **TodoWrite**: Phase 1 completed, subsequent phases pending
|
||||
|
||||
## Next Phase
|
||||
|
||||
Return to orchestrator:
|
||||
- If `execution_mode === 'auto'` → Continue to [Phase 2: Artifacts](02-artifacts.md)
|
||||
- If `execution_mode === 'single-role'` → Continue to [Phase 3: Role Analysis](03-role-analysis.md)
|
||||
457
.claude/skills/brainstorm/phases/02-artifacts.md
Normal file
457
.claude/skills/brainstorm/phases/02-artifacts.md
Normal file
@@ -0,0 +1,457 @@
|
||||
# Phase 2: Interactive Framework Generation (Artifacts)
|
||||
|
||||
Seven-phase interactive workflow generating confirmed guidance specification through role-based analysis and synthesis. This phase handles all user interaction for topic exploration, role selection, and decision gathering.
|
||||
|
||||
## Objective
|
||||
|
||||
- Collect project context automatically (Phase 0)
|
||||
- Analyze topic and extract keywords/challenges (Phase 1)
|
||||
- Select roles via intelligent recommendation + user confirmation (Phase 2)
|
||||
- Generate deep role-specific questions (Phase 3)
|
||||
- Resolve cross-role conflicts (Phase 4)
|
||||
- Final clarification and feature decomposition (Phase 4.5)
|
||||
- Generate declarative guidance-specification.md (Phase 5)
|
||||
|
||||
## Auto Mode
|
||||
|
||||
When `--yes` or `-y`: Auto-select recommended roles, skip all clarification questions, use default answers.
|
||||
|
||||
## TodoWrite Integration
|
||||
|
||||
**TodoWrite Rule**: EXTEND auto-parallel's task list (NOT replace/overwrite)
|
||||
|
||||
**When called from auto mode**:
|
||||
- Find artifacts parent task → Mark "in_progress"
|
||||
- APPEND sub-tasks (Phase 0-5) → Mark each as completes
|
||||
- When Phase 5 completes → Mark parent "completed"
|
||||
- PRESERVE all other auto-parallel tasks
|
||||
|
||||
**Standalone Mode**:
|
||||
```json
|
||||
[
|
||||
{"content": "Initialize session", "status": "pending", "activeForm": "Initializing"},
|
||||
{"content": "Phase 0: Context collection", "status": "pending", "activeForm": "Phase 0"},
|
||||
{"content": "Phase 1: Topic analysis (2-4 questions)", "status": "pending", "activeForm": "Phase 1"},
|
||||
{"content": "Phase 2: Role selection", "status": "pending", "activeForm": "Phase 2"},
|
||||
{"content": "Phase 3: Role questions (per role)", "status": "pending", "activeForm": "Phase 3"},
|
||||
{"content": "Phase 4: Conflict resolution", "status": "pending", "activeForm": "Phase 4"},
|
||||
{"content": "Phase 4.5: Final clarification + Feature decomposition", "status": "pending", "activeForm": "Phase 4.5"},
|
||||
{"content": "Phase 5: Generate specification", "status": "pending", "activeForm": "Phase 5"}
|
||||
]
|
||||
```
|
||||
|
||||
## Execution
|
||||
|
||||
### Session Management
|
||||
|
||||
- Check `.workflow/active/` for existing sessions
|
||||
- Multiple → Prompt selection | Single → Use it | None → Create `WFS-[topic-slug]`
|
||||
- Parse `--count N` parameter (default: 3)
|
||||
- Store decisions in `workflow-session.json`
|
||||
|
||||
### Phase 0: Context Collection
|
||||
|
||||
**Goal**: Gather project context BEFORE user interaction
|
||||
|
||||
**Steps**:
|
||||
1. Check if `context-package.json` exists → Skip if valid
|
||||
2. Invoke `context-search-agent` (BRAINSTORM MODE - lightweight)
|
||||
3. Output: `.workflow/active/WFS-{session-id}/.process/context-package.json`
|
||||
|
||||
**Graceful Degradation**: If agent fails, continue to Phase 1 without context
|
||||
|
||||
```javascript
|
||||
Task(
|
||||
subagent_type="context-search-agent",
|
||||
run_in_background=false,
|
||||
description="Gather project context for brainstorm",
|
||||
prompt=`
|
||||
Execute context-search-agent in BRAINSTORM MODE (Phase 1-2 only).
|
||||
|
||||
Session: ${session_id}
|
||||
Task: ${task_description}
|
||||
Output: .workflow/${session_id}/.process/context-package.json
|
||||
|
||||
Required fields: metadata, project_context, assets, dependencies, conflict_detection
|
||||
`
|
||||
)
|
||||
```
|
||||
|
||||
### Phase 1: Topic Analysis
|
||||
|
||||
**Goal**: Extract keywords/challenges enriched by Phase 0 context
|
||||
|
||||
**Steps**:
|
||||
1. Load Phase 0 context (tech_stack, modules, conflict_risk)
|
||||
2. Deep topic analysis (entities, challenges, constraints, metrics)
|
||||
3. Generate 2-4 context-aware probing questions
|
||||
4. AskUserQuestion → Store to `session.intent_context`
|
||||
|
||||
**Example**:
|
||||
```javascript
|
||||
AskUserQuestion({
|
||||
questions: [
|
||||
{
|
||||
question: "实时协作平台的主要技术挑战?",
|
||||
header: "核心挑战",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "实时数据同步", description: "100+用户同时在线,状态同步复杂度高" },
|
||||
{ label: "可扩展性架构", description: "用户规模增长时的系统扩展能力" },
|
||||
{ label: "冲突解决机制", description: "多用户同时编辑的冲突处理策略" }
|
||||
]
|
||||
},
|
||||
{
|
||||
question: "MVP阶段最关注的指标?",
|
||||
header: "优先级",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "功能完整性", description: "实现所有核心功能" },
|
||||
{ label: "用户体验", description: "流畅的交互体验和响应速度" },
|
||||
{ label: "系统稳定性", description: "高可用性和数据一致性" }
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
```
|
||||
|
||||
**⚠️ CRITICAL**: Questions MUST reference topic keywords. Generic "Project type?" violates dynamic generation.
|
||||
|
||||
### Phase 2: Role Selection
|
||||
|
||||
**Goal**: User selects roles from intelligent recommendations
|
||||
|
||||
**Available Roles**: data-architect, product-manager, product-owner, scrum-master, subject-matter-expert, system-architect, test-strategist, ui-designer, ux-expert
|
||||
|
||||
**Steps**:
|
||||
1. Analyze Phase 1 keywords → Recommend count+2 roles with rationale
|
||||
2. AskUserQuestion (multiSelect=true) → Store to `session.selected_roles`
|
||||
3. If count+2 > 4, split into multiple rounds
|
||||
|
||||
**Example**:
|
||||
```javascript
|
||||
AskUserQuestion({
|
||||
questions: [{
|
||||
question: "请选择 3 个角色参与头脑风暴分析",
|
||||
header: "角色选择",
|
||||
multiSelect: true,
|
||||
options: [
|
||||
{ label: "system-architect", description: "实时同步架构设计和技术选型" },
|
||||
{ label: "ui-designer", description: "协作界面用户体验和状态展示" },
|
||||
{ label: "product-manager", description: "功能优先级和MVP范围决策" },
|
||||
{ label: "data-architect", description: "数据同步模型和存储方案设计" }
|
||||
]
|
||||
}]
|
||||
})
|
||||
```
|
||||
|
||||
**⚠️ CRITICAL**: User MUST interact. NEVER auto-select without confirmation (unless --yes flag).
|
||||
|
||||
### Phase 3: Role-Specific Questions
|
||||
|
||||
**Goal**: Generate deep questions mapping role expertise to Phase 1 challenges
|
||||
|
||||
**Algorithm**:
|
||||
1. FOR each selected role:
|
||||
- Map Phase 1 challenges to role domain
|
||||
- Generate 3-4 questions (implementation depth, trade-offs, edge cases)
|
||||
- AskUserQuestion per role → Store to `session.role_decisions[role]`
|
||||
2. Process roles sequentially (one at a time for clarity)
|
||||
3. If role needs > 4 questions, split into multiple rounds
|
||||
|
||||
**Example** (system-architect):
|
||||
```javascript
|
||||
AskUserQuestion({
|
||||
questions: [
|
||||
{
|
||||
question: "100+ 用户实时状态同步方案?",
|
||||
header: "状态同步",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "Event Sourcing", description: "完整事件历史,支持回溯,存储成本高" },
|
||||
{ label: "集中式状态管理", description: "实现简单,单点瓶颈风险" },
|
||||
{ label: "CRDT", description: "去中心化,自动合并,学习曲线陡" }
|
||||
]
|
||||
},
|
||||
{
|
||||
question: "两个用户同时编辑冲突如何解决?",
|
||||
header: "冲突解决",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "自动合并", description: "用户无感知,可能产生意外结果" },
|
||||
{ label: "手动解决", description: "用户控制,增加交互复杂度" },
|
||||
{ label: "版本控制", description: "保留历史,需要分支管理" }
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
```
|
||||
|
||||
### Phase 4: Conflict Resolution
|
||||
|
||||
**Goal**: Resolve ACTUAL conflicts from Phase 3 answers
|
||||
|
||||
**Algorithm**:
|
||||
1. Analyze Phase 3 answers for conflicts:
|
||||
- Contradictory choices (e.g., "fast iteration" vs "complex Event Sourcing")
|
||||
- Missing integration (e.g., "Optimistic updates" but no conflict handling)
|
||||
- Implicit dependencies (e.g., "Live cursors" but no auth defined)
|
||||
2. Generate clarification questions referencing SPECIFIC Phase 3 choices
|
||||
3. AskUserQuestion (max 4 per call, multi-round) → Store to `session.cross_role_decisions`
|
||||
4. If NO conflicts: Skip Phase 4 (inform user: "未检测到跨角色冲突,跳过Phase 4")
|
||||
|
||||
**Example**:
|
||||
```javascript
|
||||
AskUserQuestion({
|
||||
questions: [{
|
||||
question: "CRDT 与 UI 回滚期望冲突,如何解决?\n背景:system-architect选择CRDT,ui-designer期望回滚UI",
|
||||
header: "架构冲突",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "采用 CRDT", description: "保持去中心化,调整UI期望" },
|
||||
{ label: "显示合并界面", description: "增加用户交互,展示冲突详情" },
|
||||
{ label: "切换到 OT", description: "支持回滚,增加服务器复杂度" }
|
||||
]
|
||||
}]
|
||||
})
|
||||
```
|
||||
|
||||
### Phase 4.5: Final Clarification
|
||||
|
||||
**Purpose**: Ensure no important points missed before generating specification
|
||||
|
||||
**Steps**:
|
||||
1. Ask initial check:
|
||||
```javascript
|
||||
AskUserQuestion({
|
||||
questions: [{
|
||||
question: "在生成最终规范之前,是否有前面未澄清的重点需要补充?",
|
||||
header: "补充确认",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "无需补充", description: "前面的讨论已经足够完整" },
|
||||
{ label: "需要补充", description: "还有重要内容需要澄清" }
|
||||
]
|
||||
}]
|
||||
})
|
||||
```
|
||||
2. If "需要补充":
|
||||
- Analyze user's additional points
|
||||
- Generate progressive questions (not role-bound, interconnected)
|
||||
- AskUserQuestion (max 4 per round) → Store to `session.additional_decisions`
|
||||
- Repeat until user confirms completion
|
||||
3. If "无需补充": Proceed to Feature Decomposition
|
||||
|
||||
**Progressive Pattern**: Questions interconnected, each round informs next, continue until resolved.
|
||||
|
||||
#### Feature Decomposition
|
||||
|
||||
After final clarification, extract implementable feature units from all Phase 1-4 decisions.
|
||||
|
||||
**Steps**:
|
||||
1. Analyze all accumulated decisions (`intent_context` + `role_decisions` + `cross_role_decisions` + `additional_decisions`)
|
||||
2. Extract candidate features: each must be an independently implementable unit with clear boundaries
|
||||
3. Generate candidate list (max 8 features) with structured format:
|
||||
- Feature ID: `F-{3-digit}` (e.g., F-001)
|
||||
- Name: kebab-case slug (e.g., `real-time-sync`, `user-auth`)
|
||||
- Description: one-sentence summary of the feature's scope
|
||||
- Related roles: which roles' decisions drive this feature
|
||||
- Priority: High / Medium / Low
|
||||
4. Present candidate list to user for confirmation:
|
||||
```javascript
|
||||
AskUserQuestion({
|
||||
questions: [{
|
||||
question: "以下是从讨论中提取的功能点清单:\n\nF-001: [name] - [description]\nF-002: [name] - [description]\n...\n\n是否需要调整?",
|
||||
header: "功能点确认",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "确认无误", description: "功能点清单完整且合理,继续生成规范" },
|
||||
{ label: "需要调整", description: "需要增加、删除或修改功能点" }
|
||||
]
|
||||
}]
|
||||
})
|
||||
```
|
||||
5. If "需要调整": Collect adjustments and re-present until user confirms
|
||||
6. Store confirmed list to `session.feature_list`
|
||||
|
||||
**Constraints**:
|
||||
- Maximum 8 features (if more candidates, merge related items)
|
||||
- Each feature MUST be independently implementable (no implicit cross-feature dependencies)
|
||||
- Feature ID format: `F-{3-digit}` (F-001, F-002, ...)
|
||||
- Feature slug: kebab-case, descriptive of the feature scope
|
||||
|
||||
**Granularity Guidelines** (用于验证功能点粒度是否合适):
|
||||
|
||||
| Signal | Too Coarse | Just Right | Too Fine |
|
||||
|--------|-----------|------------|----------|
|
||||
| 实现范围 | 需要 5+ 个独立模块协同 | 1-3 个模块,边界清晰 | 单个函数或单个 API 端点 |
|
||||
| 角色关注 | 所有角色都深度涉及 | 2-4 个角色有实质贡献 | 仅 1 个角色关注 |
|
||||
| 可测试性 | 无法写出清晰的验收标准 | 可定义 3-5 条可测量验收标准 | 验收标准等同于单元测试 |
|
||||
| 依赖关系 | 与其他功能点循环依赖 | 依赖关系单向且可识别 | 无任何外部依赖(可能遗漏) |
|
||||
|
||||
**Quality Validation** (Step 3 提取候选功能点后,逐条验证):
|
||||
1. **独立性检查**: 该功能点是否可以在其他功能点未完成时独立交付?若否 → 考虑合并或重新划分
|
||||
2. **完整性检查**: 该功能点是否覆盖了一个用户可感知的完整价值?若否 → 可能太细,考虑合并
|
||||
3. **粒度均衡检查**: 各功能点之间的复杂度是否大致均衡(最大不超过最小的 3 倍)?若否 → 拆分过大的或合并过小的
|
||||
4. **边界清晰检查**: 是否能用一句话描述该功能点的输入和输出?若否 → 边界模糊,需重新定义
|
||||
|
||||
**Handling Vague Requirements** (当用户需求模糊时的额外步骤):
|
||||
- 如果 Phase 1-4 的决策不足以支撑功能点分解(如缺少具体业务场景、技术选型未定),在 Step 4 确认时**主动告知用户**哪些功能点的粒度可能不够精确
|
||||
- 对不确定的功能点标注 `Priority: TBD`,在后续 synthesis 阶段通过跨角色分析进一步明确
|
||||
- 如果候选功能点 ≤ 2 个,可能是需求过于抽象 → 提示用户补充更多具体场景后再分解
|
||||
|
||||
### Phase 5: Generate Specification
|
||||
|
||||
**Steps**:
|
||||
1. Load all decisions: `intent_context` + `selected_roles` + `role_decisions` + `cross_role_decisions` + `additional_decisions` + `feature_list`
|
||||
2. Transform Q&A to declarative: Questions → Headers, Answers → CONFIRMED/SELECTED statements
|
||||
3. Generate `guidance-specification.md`
|
||||
4. Update `workflow-session.json` (metadata only)
|
||||
5. Validate: No interrogative sentences, all decisions traceable
|
||||
|
||||
## Question Guidelines
|
||||
|
||||
### Core Principle
|
||||
|
||||
**Target**: 开发者(理解技术但需要从用户需求出发)
|
||||
|
||||
**Question Structure**: `[业务场景/需求前提] + [技术关注点]`
|
||||
**Option Structure**: `标签:[技术方案] + 说明:[业务影响] + [技术权衡]`
|
||||
|
||||
### Quality Rules
|
||||
|
||||
**MUST Include**:
|
||||
- ✅ All questions in Chinese (用中文提问)
|
||||
- ✅ 业务场景作为问题前提
|
||||
- ✅ 技术选项的业务影响说明
|
||||
- ✅ 量化指标和约束条件
|
||||
|
||||
**MUST Avoid**:
|
||||
- ❌ 纯技术选型无业务上下文
|
||||
- ❌ 过度抽象的用户体验问题
|
||||
- ❌ 脱离话题的通用架构问题
|
||||
|
||||
### Phase-Specific Requirements
|
||||
|
||||
| Phase | Focus | Key Requirements |
|
||||
|-------|-------|------------------|
|
||||
| 1 | 意图理解 | Reference topic keywords, 用户场景、业务约束、优先级 |
|
||||
| 2 | 角色推荐 | Intelligent analysis (NOT keyword mapping), explain relevance |
|
||||
| 3 | 角色问题 | Reference Phase 1 keywords, concrete options with trade-offs |
|
||||
| 4 | 冲突解决 | Reference SPECIFIC Phase 3 choices, explain impact on both roles |
|
||||
|
||||
### Multi-Round Execution Pattern
|
||||
|
||||
```javascript
|
||||
const BATCH_SIZE = 4;
|
||||
for (let i = 0; i < allQuestions.length; i += BATCH_SIZE) {
|
||||
const batch = allQuestions.slice(i, i + BATCH_SIZE);
|
||||
AskUserQuestion({ questions: batch });
|
||||
// Store responses before next round
|
||||
}
|
||||
```
|
||||
|
||||
## Output
|
||||
|
||||
### Generated Files
|
||||
|
||||
**File**: `.workflow/active/WFS-{topic}/.brainstorming/guidance-specification.md`
|
||||
|
||||
```markdown
|
||||
# [Project] - Confirmed Guidance Specification
|
||||
|
||||
**Metadata**: [timestamp, type, focus, roles]
|
||||
|
||||
## 1. Project Positioning & Goals
|
||||
**CONFIRMED Objectives**: [from topic + Phase 1]
|
||||
**CONFIRMED Success Criteria**: [from Phase 1 answers]
|
||||
|
||||
## 2-N. [Role] Decisions
|
||||
### SELECTED Choices
|
||||
**[Question topic]**: [User's answer]
|
||||
- **Rationale**: [From option description]
|
||||
- **Impact**: [Implications]
|
||||
|
||||
### Cross-Role Considerations
|
||||
**[Conflict resolved]**: [Resolution from Phase 4]
|
||||
- **Affected Roles**: [Roles involved]
|
||||
|
||||
## Cross-Role Integration
|
||||
**CONFIRMED Integration Points**: [API/Data/Auth from multiple roles]
|
||||
|
||||
## Risks & Constraints
|
||||
**Identified Risks**: [From answers] → Mitigation: [Approach]
|
||||
|
||||
## Next Steps
|
||||
**⚠️ Automatic Continuation** (when called from auto mode):
|
||||
- Auto mode assigns agents for role-specific analysis
|
||||
- Each selected role gets conceptual-planning-agent
|
||||
- Agents read this guidance-specification.md for context
|
||||
|
||||
## Feature Decomposition
|
||||
|
||||
**Constraints**: Max 8 features | Each independently implementable | ID format: F-{3-digit}
|
||||
|
||||
| Feature ID | Name | Description | Related Roles | Priority |
|
||||
|------------|------|-------------|---------------|----------|
|
||||
| F-001 | [kebab-case-slug] | [One-sentence scope] | [role1, role2] | High/Medium/Low |
|
||||
| F-002 | [kebab-case-slug] | [One-sentence scope] | [role1] | High/Medium/Low |
|
||||
|
||||
## Appendix: Decision Tracking
|
||||
| Decision ID | Category | Question | Selected | Phase | Rationale |
|
||||
|-------------|----------|----------|----------|-------|-----------|
|
||||
| D-001 | Intent | [Q] | [A] | 1 | [Why] |
|
||||
| D-002 | Roles | [Selected] | [Roles] | 2 | [Why] |
|
||||
| D-003+ | [Role] | [Q] | [A] | 3 | [Why] |
|
||||
```
|
||||
|
||||
### Session Metadata
|
||||
|
||||
```json
|
||||
{
|
||||
"session_id": "WFS-{topic-slug}",
|
||||
"type": "brainstorming",
|
||||
"topic": "{original user input}",
|
||||
"selected_roles": ["system-architect", "ui-designer", "product-manager"],
|
||||
"phase_completed": "artifacts",
|
||||
"timestamp": "2025-10-24T10:30:00Z",
|
||||
"count_parameter": 3,
|
||||
"style_skill_package": null
|
||||
}
|
||||
```
|
||||
|
||||
**⚠️ Rule**: Session JSON stores ONLY metadata. All guidance content goes to guidance-specification.md.
|
||||
|
||||
### Validation Checklist
|
||||
|
||||
- ✅ No interrogative sentences (use CONFIRMED/SELECTED)
|
||||
- ✅ Every decision traceable to user answer
|
||||
- ✅ Cross-role conflicts resolved or documented
|
||||
- ✅ Next steps concrete and specific
|
||||
- ✅ No content duplication between .json and .md
|
||||
- ✅ Feature Decomposition table present with validated entries
|
||||
|
||||
### Governance Rules
|
||||
|
||||
- All decisions MUST use CONFIRMED/SELECTED (NO "?" in decision sections)
|
||||
- Every decision MUST trace to user answer
|
||||
- Conflicts MUST be resolved (not marked "TBD")
|
||||
- Next steps MUST be actionable
|
||||
- Topic preserved as authoritative reference
|
||||
|
||||
**CRITICAL**: Guidance is single source of truth for downstream phases. Ambiguity violates governance.
|
||||
|
||||
### Update Mechanism
|
||||
|
||||
```
|
||||
IF guidance-specification.md EXISTS:
|
||||
Prompt: "Regenerate completely / Update sections / Cancel"
|
||||
ELSE:
|
||||
Run full Phase 0-5 flow
|
||||
```
|
||||
|
||||
- **TodoWrite**: Mark Phase 2 completed, collapse sub-tasks to summary
|
||||
|
||||
## Next Phase
|
||||
|
||||
Return to orchestrator, then auto-continue to [Phase 3: Role Analysis](03-role-analysis.md) (auto mode: parallel execution for all selected roles).
|
||||
718
.claude/skills/brainstorm/phases/03-role-analysis.md
Normal file
718
.claude/skills/brainstorm/phases/03-role-analysis.md
Normal file
@@ -0,0 +1,718 @@
|
||||
# Phase 3: Role Analysis
|
||||
|
||||
Unified role-specific analysis generation with interactive context gathering, framework alignment, and incremental update support. Supports both parallel execution (auto mode, N roles simultaneously) and single-role execution.
|
||||
|
||||
## Objective
|
||||
|
||||
- Validate role name and detect session
|
||||
- Gather interactive context via role-specific questions (optional)
|
||||
- Execute conceptual-planning-agent with role template and framework
|
||||
- Support feature-point output organization when feature list available
|
||||
- Support incremental updates to existing analyses
|
||||
- Validate output and update session metadata
|
||||
|
||||
## Supported Roles
|
||||
|
||||
| Role ID | Title | Focus Area | Context Questions |
|
||||
|---------|-------|------------|-------------------|
|
||||
| `ux-expert` | UX专家 | User research, information architecture, user journey | 4 |
|
||||
| `ui-designer` | UI设计师 | Visual design, high-fidelity mockups, design systems | 4 |
|
||||
| `system-architect` | 系统架构师 | Technical architecture, scalability, integration patterns | 5 |
|
||||
| `product-manager` | 产品经理 | Product strategy, roadmap, prioritization | 4 |
|
||||
| `product-owner` | 产品负责人 | Backlog management, user stories, acceptance criteria | 4 |
|
||||
| `scrum-master` | 敏捷教练 | Process facilitation, impediment removal, team dynamics | 3 |
|
||||
| `subject-matter-expert` | 领域专家 | Domain knowledge, business rules, compliance | 4 |
|
||||
| `data-architect` | 数据架构师 | Data models, storage strategies, data flow | 5 |
|
||||
| `api-designer` | API设计师 | API contracts, versioning, integration patterns | 4 |
|
||||
|
||||
## Execution
|
||||
|
||||
### Auto Mode Parallel Execution
|
||||
|
||||
When called from auto mode, launch N role-analysis calls simultaneously:
|
||||
|
||||
```javascript
|
||||
// Single message with multiple Skill invokes for parallelism
|
||||
// For each selected role:
|
||||
Skill(skill="workflow:brainstorm:role-analysis", args="{role-name} --session {session-id} --skip-questions")
|
||||
|
||||
// For ui-designer with style-skill:
|
||||
Skill(skill="workflow:brainstorm:role-analysis", args="ui-designer --session {session-id} --skip-questions --style-skill {style_skill_package}")
|
||||
```
|
||||
|
||||
**Parallel Safety**: Each role operates independently on its own directory. No cross-agent dependencies.
|
||||
|
||||
### Step 3.1: Detection & Validation
|
||||
|
||||
**Step 3.1.1: Role Validation**
|
||||
```bash
|
||||
VALIDATE role_name IN [
|
||||
ux-expert, ui-designer, system-architect, product-manager,
|
||||
product-owner, scrum-master, subject-matter-expert,
|
||||
data-architect, api-designer
|
||||
]
|
||||
IF invalid:
|
||||
ERROR: "Unknown role: {role_name}. Use one of: ux-expert, ui-designer, ..."
|
||||
EXIT
|
||||
```
|
||||
|
||||
**Step 3.1.2: Session Detection**
|
||||
```bash
|
||||
IF --session PROVIDED:
|
||||
session_id = --session
|
||||
brainstorm_dir = .workflow/active/{session_id}/.brainstorming/
|
||||
ELSE:
|
||||
FIND .workflow/active/WFS-*/
|
||||
IF multiple:
|
||||
PROMPT user to select
|
||||
ELSE IF single:
|
||||
USE existing
|
||||
ELSE:
|
||||
ERROR: "No active session. Run /brainstorm 'topic' first"
|
||||
EXIT
|
||||
|
||||
VALIDATE brainstorm_dir EXISTS
|
||||
```
|
||||
|
||||
**Step 3.1.3: Framework Detection & Feature List Extraction**
|
||||
```bash
|
||||
framework_file = {brainstorm_dir}/guidance-specification.md
|
||||
IF framework_file EXISTS:
|
||||
framework_mode = true
|
||||
LOAD framework_content
|
||||
# Extract Feature Decomposition table from guidance-specification.md
|
||||
feature_list = EXTRACT_TABLE(framework_content, "Feature Decomposition")
|
||||
# feature_list format: [{id: "F-001", slug: "real-time-sync", description: "...", roles: [...], priority: "High"}, ...]
|
||||
IF feature_list NOT EMPTY:
|
||||
feature_mode = true # Use feature-point organization for sub-documents
|
||||
ELSE:
|
||||
feature_mode = false # Fall back to arbitrary-topic organization
|
||||
ELSE:
|
||||
WARN: "No framework found - will create standalone analysis"
|
||||
framework_mode = false
|
||||
feature_mode = false
|
||||
```
|
||||
|
||||
**Step 3.1.4: Update Mode Detection**
|
||||
```bash
|
||||
existing_analysis = {brainstorm_dir}/{role_name}/analysis*.md
|
||||
IF --update FLAG OR existing_analysis EXISTS:
|
||||
update_mode = true
|
||||
IF --update NOT PROVIDED:
|
||||
ASK: "Analysis exists. Update or regenerate?"
|
||||
OPTIONS: ["Incremental update", "Full regenerate", "Cancel"]
|
||||
ELSE:
|
||||
update_mode = false
|
||||
```
|
||||
|
||||
### Step 3.2: Interactive Context Gathering
|
||||
|
||||
**Trigger Conditions**:
|
||||
- Default: Always ask unless `--skip-questions` provided
|
||||
- `--include-questions`: Force context gathering even if analysis exists
|
||||
- `--skip-questions`: Skip all interactive questions
|
||||
|
||||
**Step 3.2.1: Load Role Configuration**
|
||||
```javascript
|
||||
const roleConfig = {
|
||||
'ux-expert': {
|
||||
title: 'UX专家',
|
||||
focus_area: 'User research, information architecture, user journey',
|
||||
question_categories: ['User Intent', 'Requirements', 'UX'],
|
||||
question_count: 4,
|
||||
template: '~/.ccw/workflows/cli-templates/planning-roles/ux-expert.md'
|
||||
},
|
||||
'ui-designer': {
|
||||
title: 'UI设计师',
|
||||
focus_area: 'Visual design, high-fidelity mockups, design systems',
|
||||
question_categories: ['Requirements', 'UX', 'Feasibility'],
|
||||
question_count: 4,
|
||||
template: '~/.ccw/workflows/cli-templates/planning-roles/ui-designer.md'
|
||||
},
|
||||
'system-architect': {
|
||||
title: '系统架构师',
|
||||
focus_area: 'Technical architecture, scalability, integration patterns',
|
||||
question_categories: ['Scale & Performance', 'Technical Constraints', 'Architecture Complexity', 'Non-Functional Requirements'],
|
||||
question_count: 5,
|
||||
template: '~/.ccw/workflows/cli-templates/planning-roles/system-architect.md'
|
||||
},
|
||||
'product-manager': {
|
||||
title: '产品经理',
|
||||
focus_area: 'Product strategy, roadmap, prioritization',
|
||||
question_categories: ['User Intent', 'Requirements', 'Process'],
|
||||
question_count: 4,
|
||||
template: '~/.ccw/workflows/cli-templates/planning-roles/product-manager.md'
|
||||
},
|
||||
'product-owner': {
|
||||
title: '产品负责人',
|
||||
focus_area: 'Backlog management, user stories, acceptance criteria',
|
||||
question_categories: ['Requirements', 'Decisions', 'Process'],
|
||||
question_count: 4,
|
||||
template: '~/.ccw/workflows/cli-templates/planning-roles/product-owner.md'
|
||||
},
|
||||
'scrum-master': {
|
||||
title: '敏捷教练',
|
||||
focus_area: 'Process facilitation, impediment removal, team dynamics',
|
||||
question_categories: ['Process', 'Risk', 'Decisions'],
|
||||
question_count: 3,
|
||||
template: '~/.ccw/workflows/cli-templates/planning-roles/scrum-master.md'
|
||||
},
|
||||
'subject-matter-expert': {
|
||||
title: '领域专家',
|
||||
focus_area: 'Domain knowledge, business rules, compliance',
|
||||
question_categories: ['Requirements', 'Feasibility', 'Terminology'],
|
||||
question_count: 4,
|
||||
template: '~/.ccw/workflows/cli-templates/planning-roles/subject-matter-expert.md'
|
||||
},
|
||||
'data-architect': {
|
||||
title: '数据架构师',
|
||||
focus_area: 'Data models, storage strategies, data flow',
|
||||
question_categories: ['Architecture', 'Scale & Performance', 'Technical Constraints', 'Feasibility'],
|
||||
question_count: 5,
|
||||
template: '~/.ccw/workflows/cli-templates/planning-roles/data-architect.md'
|
||||
},
|
||||
'api-designer': {
|
||||
title: 'API设计师',
|
||||
focus_area: 'API contracts, versioning, integration patterns',
|
||||
question_categories: ['Architecture', 'Requirements', 'Feasibility', 'Decisions'],
|
||||
question_count: 4,
|
||||
template: '~/.ccw/workflows/cli-templates/planning-roles/api-designer.md'
|
||||
}
|
||||
};
|
||||
|
||||
config = roleConfig[role_name];
|
||||
```
|
||||
|
||||
**Step 3.2.2: Generate Role-Specific Questions**
|
||||
|
||||
**9-Category Taxonomy**:
|
||||
|
||||
| Category | Focus | Example Question Pattern |
|
||||
|----------|-------|--------------------------|
|
||||
| User Intent | 用户目标 | "该分析的核心目标是什么?" |
|
||||
| Requirements | 需求细化 | "需求的优先级如何排序?" |
|
||||
| Architecture | 架构决策 | "技术栈的选择考量?" |
|
||||
| UX | 用户体验 | "交互复杂度的取舍?" |
|
||||
| Feasibility | 可行性 | "资源约束下的实现范围?" |
|
||||
| Risk | 风险管理 | "风险容忍度是多少?" |
|
||||
| Process | 流程规范 | "开发迭代的节奏?" |
|
||||
| Decisions | 决策确认 | "冲突的解决方案?" |
|
||||
| Terminology | 术语统一 | "统一使用哪个术语?" |
|
||||
| Scale & Performance | 性能扩展 | "预期的负载和性能要求?" |
|
||||
| Technical Constraints | 技术约束 | "现有技术栈的限制?" |
|
||||
| Architecture Complexity | 架构复杂度 | "架构的复杂度权衡?" |
|
||||
| Non-Functional Requirements | 非功能需求 | "可用性和可维护性要求?" |
|
||||
|
||||
**Question Generation Algorithm**:
|
||||
```javascript
|
||||
async function generateQuestions(role_name, framework_content) {
|
||||
const config = roleConfig[role_name];
|
||||
const questions = [];
|
||||
|
||||
// Parse framework for keywords
|
||||
const keywords = extractKeywords(framework_content);
|
||||
|
||||
// Generate category-specific questions
|
||||
for (const category of config.question_categories) {
|
||||
const question = generateCategoryQuestion(category, keywords, role_name);
|
||||
questions.push(question);
|
||||
}
|
||||
|
||||
return questions.slice(0, config.question_count);
|
||||
}
|
||||
```
|
||||
|
||||
**Step 3.2.3: Multi-Round Question Execution**
|
||||
|
||||
```javascript
|
||||
const BATCH_SIZE = 4;
|
||||
const user_context = {};
|
||||
|
||||
for (let i = 0; i < questions.length; i += BATCH_SIZE) {
|
||||
const batch = questions.slice(i, i + BATCH_SIZE);
|
||||
const currentRound = Math.floor(i / BATCH_SIZE) + 1;
|
||||
const totalRounds = Math.ceil(questions.length / BATCH_SIZE);
|
||||
|
||||
console.log(`\n[Round ${currentRound}/${totalRounds}] ${config.title} 上下文询问\n`);
|
||||
|
||||
AskUserQuestion({
|
||||
questions: batch.map(q => ({
|
||||
question: q.question,
|
||||
header: q.category.substring(0, 12),
|
||||
multiSelect: false,
|
||||
options: q.options.map(opt => ({
|
||||
label: opt.label,
|
||||
description: opt.description
|
||||
}))
|
||||
}))
|
||||
});
|
||||
|
||||
// Store responses before next round
|
||||
for (const answer of responses) {
|
||||
user_context[answer.question] = {
|
||||
answer: answer.selected,
|
||||
category: answer.category,
|
||||
timestamp: new Date().toISOString()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Save context to file
|
||||
Write(
|
||||
`${brainstorm_dir}/${role_name}/${role_name}-context.md`,
|
||||
formatUserContext(user_context)
|
||||
);
|
||||
```
|
||||
|
||||
**Question Quality Rules**:
|
||||
|
||||
**MUST Include**:
|
||||
- ✅ All questions in Chinese (用中文提问)
|
||||
- ✅ 业务场景作为问题前提
|
||||
- ✅ 技术选项的业务影响说明
|
||||
- ✅ 量化指标和约束条件
|
||||
|
||||
**MUST Avoid**:
|
||||
- ❌ 纯技术选型无业务上下文
|
||||
- ❌ 过度抽象的通用问题
|
||||
- ❌ 脱离框架的重复询问
|
||||
|
||||
### Step 3.3: Agent Execution
|
||||
|
||||
**Step 3.3.1: Load Session Metadata**
|
||||
```bash
|
||||
session_metadata = Read(.workflow/active/{session_id}/workflow-session.json)
|
||||
original_topic = session_metadata.topic
|
||||
selected_roles = session_metadata.selected_roles
|
||||
```
|
||||
|
||||
**Step 3.3.2: Prepare Agent Context**
|
||||
```javascript
|
||||
const agentContext = {
|
||||
role_name: role_name,
|
||||
role_config: roleConfig[role_name],
|
||||
output_location: `${brainstorm_dir}/${role_name}/`,
|
||||
framework_mode: framework_mode,
|
||||
feature_mode: feature_mode,
|
||||
feature_list: feature_mode ? feature_list : null,
|
||||
framework_path: framework_mode ? `${brainstorm_dir}/guidance-specification.md` : null,
|
||||
update_mode: update_mode,
|
||||
user_context: user_context,
|
||||
original_topic: original_topic,
|
||||
session_id: session_id
|
||||
};
|
||||
```
|
||||
|
||||
**Step 3.3.3: Execute Conceptual Planning Agent**
|
||||
|
||||
**Framework-Based Analysis** (when guidance-specification.md exists):
|
||||
```javascript
|
||||
// Build feature list injection block (only when feature_mode is true)
|
||||
const featureListBlock = feature_mode ? `
|
||||
## Feature Point List (from guidance-specification.md Feature Decomposition)
|
||||
${feature_list.map(f => `- **${f.id}** (${f.slug}): ${f.description} [Priority: ${f.priority}]`).join('\n')}
|
||||
|
||||
**IMPORTANT - Feature-Point Output Organization**:
|
||||
- Generate ONE sub-document per feature: analysis-F-{id}-{slug}.md (e.g., analysis-${feature_list[0].id}-${feature_list[0].slug}.md)
|
||||
- Generate ONE cross-cutting document: analysis-cross-cutting.md
|
||||
- analysis.md is a role overview INDEX only (< 1500 words), NOT a full analysis
|
||||
- Each feature sub-document < 2000 words, cross-cutting < 2000 words
|
||||
- Total across all files < 15000 words
|
||||
` : `
|
||||
## Output Organization (fallback: no feature list available)
|
||||
- Generate analysis.md as main document (< 3000 words)
|
||||
- Optionally split into analysis-{slug}.md sub-documents (max 5, < 2000 words each)
|
||||
- Total < 15000 words
|
||||
`;
|
||||
|
||||
Task(
|
||||
subagent_type="conceptual-planning-agent",
|
||||
run_in_background=false,
|
||||
description=`Generate ${role_name} analysis`,
|
||||
prompt=`
|
||||
[FLOW_CONTROL]
|
||||
|
||||
Execute ${role_name} analysis for existing topic framework
|
||||
|
||||
## Context Loading
|
||||
ASSIGNED_ROLE: ${role_name}
|
||||
OUTPUT_LOCATION: ${agentContext.output_location}
|
||||
ANALYSIS_MODE: ${framework_mode ? "framework_based" : "standalone"}
|
||||
FEATURE_MODE: ${feature_mode}
|
||||
UPDATE_MODE: ${update_mode}
|
||||
|
||||
## Flow Control Steps
|
||||
1. **load_topic_framework**
|
||||
- Action: Load structured topic discussion framework
|
||||
- Command: Read(${agentContext.framework_path})
|
||||
- Output: topic_framework_content
|
||||
|
||||
2. **load_role_template**
|
||||
- Action: Load ${role_name} planning template
|
||||
- Command: Read(${roleConfig[role_name].template})
|
||||
- Output: role_template_guidelines
|
||||
|
||||
3. **load_session_metadata**
|
||||
- Action: Load session metadata and user intent
|
||||
- Command: Read(.workflow/active/${session_id}/workflow-session.json)
|
||||
- Output: session_context
|
||||
|
||||
4. **load_user_context** (if exists)
|
||||
- Action: Load interactive context responses
|
||||
- Command: Read(${brainstorm_dir}/${role_name}/${role_name}-context.md)
|
||||
- Output: user_context_answers
|
||||
|
||||
5. **${update_mode ? 'load_existing_analysis' : 'skip'}**
|
||||
${update_mode ? `
|
||||
- Action: Load existing analysis for incremental update
|
||||
- Command: Read(${brainstorm_dir}/${role_name}/analysis.md)
|
||||
- Output: existing_analysis_content
|
||||
` : ''}
|
||||
|
||||
${featureListBlock}
|
||||
|
||||
## Analysis Requirements
|
||||
**Primary Reference**: Original user prompt from workflow-session.json is authoritative
|
||||
**Framework Source**: Address all discussion points in guidance-specification.md from ${role_name} perspective
|
||||
**User Context Integration**: Incorporate interactive Q&A responses into analysis
|
||||
**Role Focus**: ${roleConfig[role_name].focus_area}
|
||||
**Template Integration**: Apply role template guidelines within framework structure
|
||||
${feature_mode ? `**Feature Organization**: Organize analysis by feature points - each feature gets its own sub-document. Cross-cutting concerns go into analysis-cross-cutting.md.` : ''}
|
||||
|
||||
## Expected Deliverables
|
||||
${feature_mode ? `
|
||||
1. **analysis.md** - Role overview index (< 1500 words): role perspective summary, feature point index with @-references to sub-documents, cross-cutting summary
|
||||
2. **analysis-cross-cutting.md** - Cross-feature decisions (< 2000 words): architecture decisions, technology choices, shared patterns that span multiple features
|
||||
3. **analysis-F-{id}-{slug}.md** - One per feature (< 2000 words each): role-specific analysis, recommendations, considerations for that feature
|
||||
4. **Framework Reference**: @../guidance-specification.md (if framework_mode)
|
||||
5. **User Context Reference**: @./${role_name}-context.md (if user context exists)
|
||||
6. **User Intent Alignment**: Validate against session_context
|
||||
` : `
|
||||
1. **analysis.md** (main document, optionally with analysis-{slug}.md sub-documents)
|
||||
2. **Framework Reference**: @../guidance-specification.md (if framework_mode)
|
||||
3. **User Context Reference**: @./${role_name}-context.md (if user context exists)
|
||||
4. **User Intent Alignment**: Validate against session_context
|
||||
`}
|
||||
|
||||
## Update Requirements (if UPDATE_MODE)
|
||||
- **Preserve Structure**: Maintain existing analysis structure
|
||||
- **Add "Clarifications" Section**: Document new user context with timestamp
|
||||
- **Merge Insights**: Integrate new perspectives without removing existing content
|
||||
- **Resolve Conflicts**: If new context contradicts existing analysis, document both and recommend resolution
|
||||
|
||||
## Completion Criteria
|
||||
- Address each discussion point from guidance-specification.md with ${role_name} expertise
|
||||
- Provide actionable recommendations from ${role_name} perspective within analysis files
|
||||
- All output files MUST start with "analysis" prefix (no recommendations.md or other naming)
|
||||
${feature_mode ? `- Each feature from the feature list has a corresponding analysis-F-{id}-{slug}.md file
|
||||
- analysis-cross-cutting.md exists with cross-feature decisions
|
||||
- analysis.md serves as index (< 1500 words), NOT a full analysis document` : ''}
|
||||
- Reference framework document using @ notation for integration
|
||||
- Update workflow-session.json with completion status
|
||||
`
|
||||
);
|
||||
```
|
||||
|
||||
### Step 3.4: Validation & Finalization
|
||||
|
||||
**Step 3.4.1: Validate Output**
|
||||
```bash
|
||||
VERIFY EXISTS: ${brainstorm_dir}/${role_name}/analysis.md
|
||||
VERIFY CONTAINS: "@../guidance-specification.md" (if framework_mode)
|
||||
IF user_context EXISTS:
|
||||
VERIFY CONTAINS: "@./${role_name}-context.md" OR "## Clarifications" section
|
||||
```
|
||||
|
||||
**Step 3.4.2: Update Session Metadata**
|
||||
```json
|
||||
{
|
||||
"phases": {
|
||||
"BRAINSTORM": {
|
||||
"${role_name}": {
|
||||
"status": "${update_mode ? 'updated' : 'completed'}",
|
||||
"completed_at": "timestamp",
|
||||
"framework_addressed": true,
|
||||
"context_gathered": true,
|
||||
"output_location": "${brainstorm_dir}/${role_name}/analysis.md",
|
||||
"update_history": [
|
||||
{
|
||||
"timestamp": "ISO8601",
|
||||
"mode": "${update_mode ? 'incremental' : 'initial'}",
|
||||
"context_questions": "question_count"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Step 3.4.3: Completion Report**
|
||||
```markdown
|
||||
✅ ${roleConfig[role_name].title} Analysis Complete
|
||||
|
||||
**Output**: ${brainstorm_dir}/${role_name}/analysis.md
|
||||
**Mode**: ${update_mode ? 'Incremental Update' : 'New Generation'}
|
||||
**Framework**: ${framework_mode ? '✓ Aligned' : '✗ Standalone'}
|
||||
**Context Questions**: ${question_count} answered
|
||||
|
||||
${update_mode ? '
|
||||
**Changes**:
|
||||
- Added "Clarifications" section with new user context
|
||||
- Merged new insights into existing sections
|
||||
- Resolved conflicts with framework alignment
|
||||
' : ''}
|
||||
|
||||
**Next Steps**:
|
||||
${selected_roles.length > 1 ? `
|
||||
- Continue with other roles: ${selected_roles.filter(r => r !== role_name).join(', ')}
|
||||
- Run synthesis: /brainstorm --session ${session_id} (auto mode)
|
||||
` : `
|
||||
- Clarify insights: /brainstorm --session ${session_id} (auto mode)
|
||||
- Generate plan: /workflow:plan --session ${session_id}
|
||||
`}
|
||||
```
|
||||
|
||||
## Output
|
||||
|
||||
### Directory Layout
|
||||
|
||||
**Feature-point mode** (when `feature_list` available):
|
||||
```
|
||||
.workflow/active/WFS-{session}/.brainstorming/
|
||||
├── guidance-specification.md
|
||||
└── {role-name}/
|
||||
├── {role-name}-context.md # Interactive Q&A responses
|
||||
├── analysis.md # Role overview INDEX (< 1500 words)
|
||||
├── analysis-cross-cutting.md # Cross-feature decisions (< 2000 words)
|
||||
├── analysis-F-001-{slug}.md # Per-feature analysis (< 2000 words)
|
||||
├── analysis-F-002-{slug}.md
|
||||
└── analysis-F-00N-{slug}.md # One per feature (max 8)
|
||||
```
|
||||
|
||||
**Fallback mode** (when `feature_list` NOT available):
|
||||
```
|
||||
.workflow/active/WFS-{session}/.brainstorming/
|
||||
├── guidance-specification.md
|
||||
└── {role-name}/
|
||||
├── {role-name}-context.md # Interactive Q&A responses
|
||||
├── analysis.md # Main analysis (REQUIRED)
|
||||
└── analysis-{slug}.md # Section documents (optional, max 5)
|
||||
```
|
||||
|
||||
### Document Structure Templates
|
||||
|
||||
#### Feature-Point Mode: analysis.md (Role Overview Index, < 1500 words)
|
||||
|
||||
```markdown
|
||||
# ${roleConfig[role_name].title} Analysis: [Topic from Framework]
|
||||
|
||||
## Framework Reference
|
||||
**Topic Framework**: @../guidance-specification.md
|
||||
**Role Focus**: ${roleConfig[role_name].focus_area}
|
||||
**User Context**: @./${role_name}-context.md
|
||||
|
||||
## Role Perspective Overview
|
||||
[Brief summary of this role's perspective on the overall project]
|
||||
|
||||
## Feature Point Index
|
||||
| Feature | Sub-document | Key Insight |
|
||||
|---------|-------------|-------------|
|
||||
| F-001: [name] | @./analysis-F-001-{slug}.md | [One-line summary] |
|
||||
| F-002: [name] | @./analysis-F-002-{slug}.md | [One-line summary] |
|
||||
|
||||
## Cross-Cutting Summary
|
||||
**Full analysis**: @./analysis-cross-cutting.md
|
||||
[Brief overview of cross-feature decisions and shared patterns]
|
||||
|
||||
---
|
||||
*Generated by ${role_name} analysis addressing structured framework*
|
||||
```
|
||||
|
||||
#### Feature-Point Mode: analysis-cross-cutting.md (< 2000 words)
|
||||
|
||||
```markdown
|
||||
# Cross-Cutting Analysis: ${roleConfig[role_name].title}
|
||||
|
||||
## Architecture Decisions
|
||||
[Decisions that span multiple features]
|
||||
|
||||
## Technology Choices
|
||||
[Shared technology selections and rationale]
|
||||
|
||||
## Shared Patterns
|
||||
[Common patterns, constraints, and conventions across features]
|
||||
|
||||
## ${roleConfig[role_name].title} Recommendations
|
||||
[Role-wide strategic recommendations]
|
||||
```
|
||||
|
||||
#### Feature-Point Mode: analysis-F-{id}-{slug}.md (< 2000 words each)
|
||||
|
||||
```markdown
|
||||
# Feature ${id}: [Feature Name] - ${roleConfig[role_name].title} Analysis
|
||||
|
||||
## Feature Overview
|
||||
[Role-specific perspective on this feature's scope and goals]
|
||||
|
||||
## Analysis
|
||||
[Detailed role-specific analysis for this feature]
|
||||
|
||||
## Recommendations
|
||||
[Actionable recommendations for this feature from role perspective]
|
||||
|
||||
## Dependencies & Risks
|
||||
[Cross-feature dependencies and risks from role viewpoint]
|
||||
```
|
||||
|
||||
#### Fallback Mode: analysis.md (New Generation)
|
||||
|
||||
```markdown
|
||||
# ${roleConfig[role_name].title} Analysis: [Topic from Framework]
|
||||
|
||||
## Framework Reference
|
||||
**Topic Framework**: @../guidance-specification.md
|
||||
**Role Focus**: ${roleConfig[role_name].focus_area}
|
||||
**User Context**: @./${role_name}-context.md
|
||||
|
||||
## User Context Summary
|
||||
**Context Gathered**: ${question_count} questions answered
|
||||
**Categories**: ${question_categories.join(', ')}
|
||||
|
||||
${user_context ? formatContextSummary(user_context) : ''}
|
||||
|
||||
## Discussion Points Analysis
|
||||
[Address each point from guidance-specification.md with ${role_name} expertise]
|
||||
|
||||
### Core Requirements (from framework)
|
||||
[Role-specific perspective on requirements]
|
||||
|
||||
### Technical Considerations (from framework)
|
||||
[Role-specific technical analysis]
|
||||
|
||||
### User Experience Factors (from framework)
|
||||
[Role-specific UX considerations]
|
||||
|
||||
### Implementation Challenges (from framework)
|
||||
[Role-specific challenges and solutions]
|
||||
|
||||
### Success Metrics (from framework)
|
||||
[Role-specific metrics and KPIs]
|
||||
|
||||
## ${roleConfig[role_name].title} Specific Recommendations
|
||||
[Role-specific actionable strategies]
|
||||
|
||||
---
|
||||
*Generated by ${role_name} analysis addressing structured framework*
|
||||
*Context gathered: ${new Date().toISOString()}*
|
||||
```
|
||||
|
||||
#### Incremental Update Structure
|
||||
|
||||
```markdown
|
||||
# ${roleConfig[role_name].title} Analysis: [Topic]
|
||||
|
||||
## Framework Reference
|
||||
[Existing content preserved]
|
||||
|
||||
## Clarifications
|
||||
### Session ${new Date().toISOString().split('T')[0]}
|
||||
${Object.entries(user_context).map(([q, a]) => `
|
||||
- **Q**: ${q} (Category: ${a.category})
|
||||
**A**: ${a.answer}
|
||||
`).join('\n')}
|
||||
|
||||
## User Context Summary
|
||||
[Updated with new context]
|
||||
|
||||
## Discussion Points Analysis
|
||||
[Existing content enhanced with new insights]
|
||||
|
||||
[Rest of sections updated based on clarifications]
|
||||
```
|
||||
|
||||
### Parameter Combinations
|
||||
|
||||
| Scenario | Command | Behavior |
|
||||
|----------|---------|----------|
|
||||
| New analysis | `/brainstorm ux-expert` | Generate + ask context questions |
|
||||
| Quick generation | `/brainstorm ux-expert --skip-questions` | Generate without context |
|
||||
| Update existing | `/brainstorm ux-expert --update` | Ask clarifications + merge |
|
||||
| Force questions | `/brainstorm ux-expert --include-questions` | Ask even if exists |
|
||||
| Specific session | `/brainstorm ux-expert --session WFS-xxx` | Target specific session |
|
||||
|
||||
### Quality Assurance
|
||||
|
||||
**Required Analysis Elements**:
|
||||
- [ ] Framework discussion points addressed (if framework_mode)
|
||||
- [ ] User context integrated (if context gathered)
|
||||
- [ ] Role template guidelines applied
|
||||
- [ ] Output files follow naming convention (analysis*.md only)
|
||||
- [ ] Framework reference using @ notation
|
||||
- [ ] Session metadata updated
|
||||
- [ ] Feature-point organization used when feature_list available (if feature_mode)
|
||||
- [ ] analysis.md is index only (< 1500 words) when in feature_mode
|
||||
- [ ] analysis-cross-cutting.md exists when in feature_mode
|
||||
- [ ] One analysis-F-{id}-{slug}.md per feature when in feature_mode
|
||||
|
||||
**Context Quality**:
|
||||
- [ ] Questions in Chinese with business context
|
||||
- [ ] Options include technical trade-offs
|
||||
- [ ] Categories aligned with role focus
|
||||
- [ ] No generic questions unrelated to framework
|
||||
|
||||
**Update Quality** (if update_mode):
|
||||
- [ ] "Clarifications" section added with timestamp
|
||||
- [ ] New insights merged without content loss
|
||||
- [ ] Conflicts documented and resolved
|
||||
- [ ] Framework alignment maintained
|
||||
|
||||
- **TodoWrite**: Mark Phase 3 completed (auto mode: collapse N parallel sub-tasks to summary)
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Error | Recovery |
|
||||
|-------|----------|
|
||||
| Invalid role name | Show valid roles list, exit |
|
||||
| No active session | Error with guidance to run /brainstorm first |
|
||||
| Missing framework | Warn and generate standalone analysis |
|
||||
| Agent execution failure | Check error.log, retry with --skip-questions |
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
### Batch Role Generation (via auto mode)
|
||||
```bash
|
||||
# Auto mode handles multiple roles in parallel
|
||||
/brainstorm "topic" --count 3
|
||||
# → Internally calls role-analysis for each selected role with --skip-questions
|
||||
```
|
||||
|
||||
### Manual Multi-Role Workflow
|
||||
```bash
|
||||
# 1. Create framework
|
||||
/brainstorm "Build real-time collaboration platform" --count 3
|
||||
|
||||
# 2. Generate each role with context
|
||||
/brainstorm system-architect --include-questions
|
||||
/brainstorm ui-designer --include-questions
|
||||
/brainstorm product-manager --include-questions
|
||||
|
||||
# 3. Synthesize insights
|
||||
/brainstorm --session WFS-xxx
|
||||
```
|
||||
|
||||
### Iterative Refinement
|
||||
```bash
|
||||
# Initial generation
|
||||
/brainstorm ux-expert
|
||||
|
||||
# User reviews and wants more depth
|
||||
/brainstorm ux-expert --update --include-questions
|
||||
# → Asks clarification questions, merges new insights
|
||||
```
|
||||
|
||||
## Next Phase
|
||||
|
||||
Return to orchestrator:
|
||||
- If auto mode → Continue to [Phase 4: Synthesis](04-synthesis.md)
|
||||
- If single-role mode → Workflow complete, report results
|
||||
783
.claude/skills/brainstorm/phases/04-synthesis.md
Normal file
783
.claude/skills/brainstorm/phases/04-synthesis.md
Normal file
@@ -0,0 +1,783 @@
|
||||
# Phase 4: Synthesis Integration
|
||||
|
||||
Eight-phase workflow to eliminate ambiguities, enhance conceptual depth, and generate per-feature specifications through cross-role analysis and user clarification.
|
||||
|
||||
## Objective
|
||||
|
||||
- Discover and validate all role analysis files
|
||||
- Execute cross-role analysis to identify consensus, conflicts, and gaps
|
||||
- Present enhancement recommendations and clarification questions to user
|
||||
- Update role analyses in parallel with enhancements and clarifications
|
||||
- Generate consolidated feature specifications (feature_mode)
|
||||
- Generate feature index for downstream consumers (feature_mode)
|
||||
- Update context package and session metadata
|
||||
|
||||
## Auto Mode
|
||||
|
||||
When `--yes` or `-y`: Auto-select all enhancements, skip clarification questions, use default answers.
|
||||
|
||||
## Quick Reference
|
||||
|
||||
### Phase Summary
|
||||
|
||||
| Phase | Goal | Executor | Output |
|
||||
|-------|------|----------|--------|
|
||||
| 1 | Session detection | Main flow | session_id, brainstorm_dir |
|
||||
| 2 | File discovery | Main flow | role_analysis_paths |
|
||||
| 3A | Cross-role analysis | Agent | enhancement_recommendations, feature_conflict_map |
|
||||
| 4 | User interaction | Main flow + AskUserQuestion | update_plan |
|
||||
| 5 | Document updates | Parallel agents | Updated analysis*.md |
|
||||
| 6 | Feature spec generation | Parallel agents | feature-specs/F-{id}-{slug}.md [feature_mode] |
|
||||
| 6.5 | Feature index generation | Main flow | feature-index.json [feature_mode] |
|
||||
| 7 | Finalization | Main flow | context-package.json, report |
|
||||
|
||||
### AskUserQuestion Pattern
|
||||
|
||||
```javascript
|
||||
// Enhancement selection (multi-select)
|
||||
AskUserQuestion({
|
||||
questions: [{
|
||||
question: "请选择要应用的改进建议",
|
||||
header: "改进选择",
|
||||
multiSelect: true,
|
||||
options: [
|
||||
{ label: "EP-001: API Contract", description: "添加详细的请求/响应 schema 定义" },
|
||||
{ label: "EP-002: User Intent", description: "明确用户需求优先级和验收标准" }
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
// Clarification questions (single-select, multi-round)
|
||||
AskUserQuestion({
|
||||
questions: [
|
||||
{
|
||||
question: "MVP 阶段的核心目标是什么?",
|
||||
header: "用户意图",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "快速验证", description: "最小功能集,快速上线获取反馈" },
|
||||
{ label: "技术壁垒", description: "完善架构,为长期发展打基础" },
|
||||
{ label: "功能完整", description: "覆盖所有规划功能,延迟上线" }
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
```
|
||||
|
||||
## Task Tracking
|
||||
|
||||
```json
|
||||
[
|
||||
{"content": "Detect session and validate analyses", "status": "pending", "activeForm": "Detecting session"},
|
||||
{"content": "Discover role analysis file paths", "status": "pending", "activeForm": "Discovering paths"},
|
||||
{"content": "Execute analysis agent (cross-role analysis + feature conflict map)", "status": "pending", "activeForm": "Executing analysis"},
|
||||
{"content": "Present enhancements via AskUserQuestion", "status": "pending", "activeForm": "Selecting enhancements"},
|
||||
{"content": "Clarification questions via AskUserQuestion", "status": "pending", "activeForm": "Clarifying"},
|
||||
{"content": "Execute parallel update agents", "status": "pending", "activeForm": "Updating documents"},
|
||||
{"content": "Generate parallel feature specs (feature_mode only)", "status": "pending", "activeForm": "Generating feature specs"},
|
||||
{"content": "Generate feature-index.json (feature_mode only)", "status": "pending", "activeForm": "Building feature index"},
|
||||
{"content": "Update context package and metadata", "status": "pending", "activeForm": "Finalizing"}
|
||||
]
|
||||
```
|
||||
|
||||
## Execution
|
||||
|
||||
### Phase 1: Discovery & Validation
|
||||
|
||||
1. **Detect Session**: Use `--session` parameter or find `.workflow/active/WFS-*`
|
||||
2. **Validate Files**:
|
||||
- `guidance-specification.md` (optional, warn if missing)
|
||||
- `*/analysis*.md` (required, error if empty)
|
||||
3. **Load User Intent**: Extract from `workflow-session.json`
|
||||
4. **Detect Feature Mode**: Check if role analyses use feature-point organization
|
||||
```javascript
|
||||
// Feature mode is active when:
|
||||
// 1. guidance-specification.md contains Feature Decomposition table
|
||||
// 2. Role directories contain analysis-F-{id}-*.md files
|
||||
const has_feature_decomposition = guidanceSpecContent &&
|
||||
guidanceSpecContent.includes('Feature Decomposition');
|
||||
const has_feature_subdocs = Glob(`${brainstorm_dir}/*/analysis-F-*-*.md`).length > 0;
|
||||
const feature_mode = has_feature_decomposition && has_feature_subdocs;
|
||||
|
||||
// Extract feature_list from guidance-spec if feature_mode
|
||||
if (feature_mode) {
|
||||
feature_list = extractFeatureDecompositionTable(guidanceSpecContent);
|
||||
// feature_list: [{id, slug, description, roles, priority}, ...]
|
||||
}
|
||||
```
|
||||
|
||||
### Phase 2: Role Discovery & Path Preparation
|
||||
|
||||
**Main flow prepares file paths for Agent**:
|
||||
|
||||
1. **Discover Analysis Files**:
|
||||
- Glob: `.workflow/active/WFS-{session}/.brainstorming/*/analysis*.md`
|
||||
- Supports: analysis.md + analysis-{slug}.md (max 5)
|
||||
|
||||
2. **Extract Role Information**:
|
||||
- `role_analysis_paths`: Relative paths
|
||||
- `participating_roles`: Role names from directories
|
||||
|
||||
3. **Pass to Agent**: session_id, brainstorm_dir, role_analysis_paths, participating_roles
|
||||
|
||||
### Phase 3A: Analysis & Enhancement Agent
|
||||
|
||||
**Agent executes cross-role analysis**:
|
||||
|
||||
**Input Optimization (feature_mode)**: When feature_mode is active, only read `{role}/analysis.md` index files (NOT sub-documents like `analysis-F-{id}-*.md` or `analysis-cross-cutting.md`). This reduces input tokens from ~39K to ~4.5K while preserving the role perspective overview, feature point index, and cross-cutting summary needed for conflict detection.
|
||||
|
||||
**Input (fallback mode)**: When feature_mode is NOT active, read all `{role}/analysis*.md` files as before.
|
||||
|
||||
```javascript
|
||||
// Prepare input paths based on mode
|
||||
const analysis_input_paths = feature_mode
|
||||
? participating_roles.map(r => `${brainstorm_dir}/${r}/analysis.md`) // Index files only (~4.5K total)
|
||||
: role_analysis_paths; // All analysis files (fallback)
|
||||
|
||||
Task(conceptual-planning-agent, `
|
||||
## Agent Mission
|
||||
Analyze role documents, identify conflicts/gaps, generate enhancement recommendations.
|
||||
${feature_mode ? 'Additionally, generate feature_conflict_map for per-feature consensus/conflicts across roles.' : ''}
|
||||
|
||||
## Input
|
||||
- brainstorm_dir: ${brainstorm_dir}
|
||||
- analysis_input_paths: ${analysis_input_paths}
|
||||
- participating_roles: ${participating_roles}
|
||||
- feature_mode: ${feature_mode}
|
||||
${feature_mode ? `- guidance_spec_path: ${brainstorm_dir}/guidance-specification.md (read Feature Decomposition section only)` : ''}
|
||||
|
||||
## Flow Control Steps
|
||||
1. load_session_metadata → Read workflow-session.json
|
||||
2. load_role_analyses → Read analysis files from analysis_input_paths
|
||||
${feature_mode ? '(INDEX files only - each ~500-800 words with role overview, feature index table, cross-cutting summary)' : '(All analysis files)'}
|
||||
${feature_mode ? `3. load_feature_decomposition → Read Feature Decomposition table from guidance-specification.md
|
||||
4. cross_role_analysis → Identify consensus, conflicts, gaps, ambiguities
|
||||
5. generate_feature_conflict_map → For each feature in Feature Decomposition, extract per-feature consensus/conflicts/cross-references from role index summaries
|
||||
6. generate_recommendations → Format as EP-001, EP-002, ...` : `3. cross_role_analysis → Identify consensus, conflicts, gaps, ambiguities
|
||||
4. generate_recommendations → Format as EP-001, EP-002, ...`}
|
||||
|
||||
## Output Format
|
||||
|
||||
### enhancement_recommendations (always)
|
||||
[
|
||||
{
|
||||
"id": "EP-001",
|
||||
"title": "API Contract Specification",
|
||||
"affected_roles": ["system-architect", "api-designer"],
|
||||
"category": "Architecture",
|
||||
"current_state": "High-level API descriptions",
|
||||
"enhancement": "Add detailed contract definitions",
|
||||
"rationale": "Enables precise implementation",
|
||||
"priority": "High"
|
||||
}
|
||||
]
|
||||
|
||||
${feature_mode ? `### feature_conflict_map (feature_mode only)
|
||||
Bridge artifact from Phase 3A to Phase 6. One entry per feature from Feature Decomposition.
|
||||
|
||||
{
|
||||
"F-001": {
|
||||
"consensus": [
|
||||
"All roles agree on real-time sync via WebSocket",
|
||||
"Event-driven architecture preferred"
|
||||
],
|
||||
"conflicts": [
|
||||
{
|
||||
"topic": "State management approach",
|
||||
"views": {
|
||||
"system-architect": "Server-authoritative with CRDT",
|
||||
"ux-expert": "Optimistic local-first updates"
|
||||
},
|
||||
"resolution": "Hybrid: optimistic local with server reconciliation via CRDT because balances UX responsiveness with data consistency, tradeoff: increased client complexity",
|
||||
"confidence": "[RESOLVED]",
|
||||
"applies_when": "Online mode with collaborative editing"
|
||||
}
|
||||
],
|
||||
"cross_refs": [
|
||||
"F-003 (offline-mode) depends on sync conflict resolution strategy"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
**feature_conflict_map Rules**:
|
||||
- One entry per feature ID from guidance-specification.md Feature Decomposition
|
||||
- consensus[]: Statements where 2+ roles explicitly agree
|
||||
- conflicts[]: Disagreements with topic, per-role positions, and suggested resolution
|
||||
- cross_refs[]: References to other features or cross-cutting docs
|
||||
- If a feature has no conflicts, set conflicts to empty array
|
||||
- Keep each entry concise: aim for 100-200 words per feature
|
||||
|
||||
**Resolution Quality Requirements**:
|
||||
1. **Actionable**: resolution must be directly executable. Bad: "需要权衡" → Good: "采用 JWT 无状态认证,RefreshToken 存 HttpOnly Cookie"
|
||||
2. **Justified**: Explain why. Format: "[方案] because [原因],tradeoff: [代价]"
|
||||
3. **Scoped**: If limited scope, mark "Applies when: [条件]"
|
||||
4. **Confidence**: [RESOLVED] | [SUGGESTED] | [UNRESOLVED]
|
||||
` : ''}
|
||||
`)
|
||||
```
|
||||
|
||||
**Phase 3A Output Storage**:
|
||||
```javascript
|
||||
// Store enhancement_recommendations for Phase 4
|
||||
const enhancement_recommendations = agent_output.enhancement_recommendations;
|
||||
|
||||
// Store feature_conflict_map for Phase 6 (feature_mode only)
|
||||
const feature_conflict_map = feature_mode ? agent_output.feature_conflict_map : null;
|
||||
```
|
||||
|
||||
### Phase 4: User Interaction
|
||||
|
||||
**All interactions via AskUserQuestion (Chinese questions)**
|
||||
|
||||
#### Step 1: Enhancement Selection
|
||||
|
||||
```javascript
|
||||
// If enhancements > 4, split into multiple rounds
|
||||
const enhancements = [...]; // from Phase 3A
|
||||
const BATCH_SIZE = 4;
|
||||
|
||||
for (let i = 0; i < enhancements.length; i += BATCH_SIZE) {
|
||||
const batch = enhancements.slice(i, i + BATCH_SIZE);
|
||||
|
||||
AskUserQuestion({
|
||||
questions: [{
|
||||
question: `请选择要应用的改进建议 (第${Math.floor(i/BATCH_SIZE)+1}轮)`,
|
||||
header: "改进选择",
|
||||
multiSelect: true,
|
||||
options: batch.map(ep => ({
|
||||
label: `${ep.id}: ${ep.title}`,
|
||||
description: `影响: ${ep.affected_roles.join(', ')} | ${ep.enhancement}`
|
||||
}))
|
||||
}]
|
||||
})
|
||||
|
||||
// Store selections before next round
|
||||
}
|
||||
|
||||
// User can also skip: provide "跳过" option
|
||||
```
|
||||
|
||||
#### Step 2: Clarification Questions
|
||||
|
||||
```javascript
|
||||
// Generate questions based on 9-category taxonomy scan
|
||||
// Categories: User Intent, Requirements, Architecture, UX, Feasibility, Risk, Process, Decisions, Terminology
|
||||
|
||||
const clarifications = [...]; // from analysis
|
||||
const BATCH_SIZE = 4;
|
||||
|
||||
for (let i = 0; i < clarifications.length; i += BATCH_SIZE) {
|
||||
const batch = clarifications.slice(i, i + BATCH_SIZE);
|
||||
const currentRound = Math.floor(i / BATCH_SIZE) + 1;
|
||||
const totalRounds = Math.ceil(clarifications.length / BATCH_SIZE);
|
||||
|
||||
AskUserQuestion({
|
||||
questions: batch.map(q => ({
|
||||
question: q.question,
|
||||
header: q.category.substring(0, 12),
|
||||
multiSelect: false,
|
||||
options: q.options.map(opt => ({
|
||||
label: opt.label,
|
||||
description: opt.description
|
||||
}))
|
||||
}))
|
||||
})
|
||||
|
||||
// Store answers before next round
|
||||
}
|
||||
```
|
||||
|
||||
### Question Guidelines
|
||||
|
||||
**Target**: 开发者(理解技术但需要从用户需求出发)
|
||||
|
||||
**Question Structure**: `[跨角色分析发现] + [需要澄清的决策点]`
|
||||
**Option Structure**: `标签:[具体方案] + 说明:[业务影响] + [技术权衡]`
|
||||
|
||||
**9-Category Taxonomy**:
|
||||
|
||||
| Category | Focus | Example Question Pattern |
|
||||
|----------|-------|--------------------------|
|
||||
| User Intent | 用户目标 | "MVP阶段核心目标?" + 验证/壁垒/完整性 |
|
||||
| Requirements | 需求细化 | "功能优先级如何排序?" + 核心/增强/可选 |
|
||||
| Architecture | 架构决策 | "技术栈选择考量?" + 熟悉度/先进性/成熟度 |
|
||||
| UX | 用户体验 | "交互复杂度取舍?" + 简洁/丰富/渐进 |
|
||||
| Feasibility | 可行性 | "资源约束下的范围?" + 最小/标准/完整 |
|
||||
| Risk | 风险管理 | "风险容忍度?" + 保守/平衡/激进 |
|
||||
| Process | 流程规范 | "迭代节奏?" + 快速/稳定/灵活 |
|
||||
| Decisions | 决策确认 | "冲突解决方案?" + 方案A/方案B/折中 |
|
||||
| Terminology | 术语统一 | "统一使用哪个术语?" + 术语A/术语B |
|
||||
|
||||
**Quality Rules**:
|
||||
|
||||
**MUST Include**:
|
||||
- ✅ All questions in Chinese (用中文提问)
|
||||
- ✅ 基于跨角色分析的具体发现
|
||||
- ✅ 选项包含业务影响说明
|
||||
- ✅ 解决实际的模糊点或冲突
|
||||
|
||||
**MUST Avoid**:
|
||||
- ❌ 与角色分析无关的通用问题
|
||||
- ❌ 重复已在 artifacts 阶段确认的内容
|
||||
- ❌ 过于细节的实现级问题
|
||||
|
||||
#### Step 3: Build Update Plan
|
||||
|
||||
```javascript
|
||||
update_plan = {
|
||||
"role1": {
|
||||
"enhancements": ["EP-001", "EP-003"],
|
||||
"clarifications": [
|
||||
{"question": "...", "answer": "...", "category": "..."}
|
||||
]
|
||||
},
|
||||
"role2": {
|
||||
"enhancements": ["EP-002"],
|
||||
"clarifications": [...]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Phase 5: Parallel Document Update Agents
|
||||
|
||||
**Execute in parallel** (one agent per role):
|
||||
|
||||
```javascript
|
||||
// Single message with multiple Task calls for parallelism
|
||||
Task(conceptual-planning-agent, `
|
||||
## Agent Mission
|
||||
Apply enhancements and clarifications to ${role} analysis
|
||||
|
||||
## Input
|
||||
- role: ${role}
|
||||
- analysis_path: ${brainstorm_dir}/${role}/analysis.md
|
||||
- enhancements: ${role_enhancements}
|
||||
- clarifications: ${role_clarifications}
|
||||
- original_user_intent: ${intent}
|
||||
|
||||
## Flow Control Steps
|
||||
1. load_current_analysis → Read analysis file
|
||||
2. add_clarifications_section → Insert Q&A section
|
||||
3. apply_enhancements → Integrate into relevant sections
|
||||
4. resolve_contradictions → Remove conflicts
|
||||
5. enforce_terminology → Align terminology
|
||||
6. validate_intent → Verify alignment with user intent
|
||||
7. write_updated_file → Save changes
|
||||
|
||||
## Output
|
||||
Updated ${role}/analysis.md
|
||||
`)
|
||||
```
|
||||
|
||||
**Agent Characteristics**:
|
||||
- **Isolation**: Each agent updates exactly ONE role (parallel safe)
|
||||
- **Dependencies**: Zero cross-agent dependencies
|
||||
- **Validation**: All updates must align with original_user_intent
|
||||
|
||||
### Phase 6: Parallel Feature Spec Generation [feature_mode only]
|
||||
|
||||
**Skip condition**: If `feature_mode` is false, skip Phase 6 and Phase 6.5 entirely. Proceed directly to Phase 7.
|
||||
|
||||
**Purpose**: Generate one consolidated feature specification per feature by aggregating all role perspectives.
|
||||
|
||||
#### Step 1: Prepare Feature Spec Directory
|
||||
|
||||
```javascript
|
||||
const feature_specs_dir = `${brainstorm_dir}/feature-specs`;
|
||||
// Ensure directory exists (create if not)
|
||||
```
|
||||
|
||||
#### Step 2: Build Per-Feature Input Bundles
|
||||
|
||||
```javascript
|
||||
const feature_bundles = feature_list.map(feature => {
|
||||
const fid = feature.id;
|
||||
const slug = feature.slug;
|
||||
|
||||
const role_analysis_files = participating_roles
|
||||
.map(role => `${brainstorm_dir}/${role}/analysis-${fid}-${slug}.md`)
|
||||
.filter(path => fileExists(path));
|
||||
|
||||
return {
|
||||
feature_id: fid,
|
||||
feature_slug: slug,
|
||||
feature_name: feature.description,
|
||||
feature_priority: feature.priority,
|
||||
conflict_map_entry: feature_conflict_map[fid],
|
||||
role_analysis_files: role_analysis_files,
|
||||
contributing_roles: role_analysis_files.map(f => extractRoleName(f)),
|
||||
output_path: `${feature_specs_dir}/${fid}-${slug}.md`
|
||||
};
|
||||
});
|
||||
```
|
||||
|
||||
#### Step 3: Execute Parallel Feature Spec Agents
|
||||
|
||||
**Execute in parallel** (one agent per feature):
|
||||
|
||||
```javascript
|
||||
Task(conceptual-planning-agent, `
|
||||
## Agent Mission
|
||||
Generate consolidated feature specification for ${feature.feature_id}: ${feature.feature_name}
|
||||
by aggregating all role-specific analyses with conflict resolution.
|
||||
|
||||
## Input
|
||||
- feature_id: ${feature.feature_id}
|
||||
- feature_slug: ${feature.feature_slug}
|
||||
- feature_name: ${feature.feature_name}
|
||||
- feature_priority: ${feature.feature_priority}
|
||||
- role_analysis_files: ${feature.role_analysis_files}
|
||||
- conflict_map_entry: ${JSON.stringify(feature.conflict_map_entry)}
|
||||
- output_path: ${feature.output_path}
|
||||
- guidance_spec_feature_section: (Feature Decomposition row for this feature)
|
||||
|
||||
## Flow Control Steps
|
||||
1. load_role_analyses → Read all role-specific analysis files for this feature
|
||||
(Each file ~1500-2000 words, total ~6.5K words for 3-4 roles)
|
||||
2. apply_conflict_map → Use conflict_map_entry to identify resolved/unresolved conflicts
|
||||
3. four_layer_aggregation → Apply aggregation rules (see below)
|
||||
4. generate_feature_spec → Write consolidated spec using template
|
||||
5. write_output → Save to output_path
|
||||
|
||||
## Four-Layer Aggregation Rules
|
||||
|
||||
### Layer 1: Direct Reference
|
||||
- Quote role analyses directly when consensus exists
|
||||
- Format: "[Role] recommends: [direct quote]"
|
||||
- Use for undisputed technical recommendations
|
||||
|
||||
### Layer 2: Structured Extraction
|
||||
- Extract and organize key information from each role into unified structure
|
||||
- Merge complementary perspectives
|
||||
- De-duplicate overlapping content across roles
|
||||
|
||||
### Layer 3: Conflict Distillation
|
||||
- **[RESOLVED]**: State the resolution directly as a design decision. Format: "**Decision**: [resolution]. **Rationale**: [from conflict.resolution]. **Trade-off**: [tradeoff]."
|
||||
- **[SUGGESTED]**: Adopt the suggested resolution but mark source. Format: "**Recommended**: [resolution] (suggested by Phase 3A cross-role analysis). **Rationale**: [reason]. **Alternative**: [strongest competing view]."
|
||||
- **[UNRESOLVED]**: Do NOT pick a side. Present all options neutrally. Format: "**[DECISION NEEDED]**: [topic]. **Options**: [role1: approach1] vs [role2: approach2]. **Evaluation**: [pros/cons of each]. **Impact if deferred**: [consequence]."
|
||||
- **Unresolved escalation**: If 2+ [UNRESOLVED] conflicts, add warning at top of Section 2
|
||||
|
||||
### Layer 4: Cross-Feature Annotation
|
||||
- Add explicit dependency notes with feature IDs
|
||||
- Document integration points with other features
|
||||
- Note shared constraints or patterns
|
||||
|
||||
## Feature Spec Template (7 Sections, target 1500-2500 words)
|
||||
|
||||
---
|
||||
# Feature Spec: ${feature.feature_id} - ${feature.feature_name}
|
||||
|
||||
**Priority**: ${feature.feature_priority}
|
||||
**Contributing Roles**: [list of roles]
|
||||
**Status**: Draft (from synthesis)
|
||||
|
||||
## 1. Requirements Summary
|
||||
[Consolidated requirements from all role perspectives]
|
||||
- Functional requirements (from product-manager, product-owner)
|
||||
- User experience requirements (from ux-expert, ui-designer)
|
||||
- Technical requirements (from system-architect, data-architect, api-designer)
|
||||
- Domain requirements (from subject-matter-expert)
|
||||
|
||||
## 2. Design Decisions [CORE SECTION]
|
||||
[Key architectural and design decisions with rationale - 40%+ of word count]
|
||||
For each decision:
|
||||
- **Decision**: [What was decided]
|
||||
- **Context**: [Why this decision was needed]
|
||||
- **Options Considered**: [Alternatives from different roles]
|
||||
- **Chosen Approach**: [Selected option with rationale]
|
||||
- **Trade-offs**: [What we gain vs. what we sacrifice]
|
||||
- **Source**: [Which role(s) drove this decision]
|
||||
|
||||
## 3. Interface Contract
|
||||
[API endpoints, data models, component interfaces]
|
||||
- External interfaces (API contracts from api-designer)
|
||||
- Internal interfaces (component boundaries from system-architect)
|
||||
- Data interfaces (schemas from data-architect)
|
||||
- User interfaces (interaction patterns from ux-expert/ui-designer)
|
||||
|
||||
## 4. Constraints & Risks
|
||||
[Technical constraints, business risks, mitigation strategies]
|
||||
- Performance constraints (from system-architect)
|
||||
- Data constraints (from data-architect)
|
||||
- UX constraints (from ux-expert)
|
||||
- Business/domain constraints (from subject-matter-expert)
|
||||
- Risk mitigation strategies (from scrum-master)
|
||||
|
||||
## 5. Acceptance Criteria
|
||||
[Testable criteria for feature completion]
|
||||
- Functional acceptance (from product-owner user stories)
|
||||
- Performance acceptance (from system-architect NFRs)
|
||||
- UX acceptance (from ux-expert usability criteria)
|
||||
- Data integrity acceptance (from data-architect)
|
||||
|
||||
## 6. Detailed Analysis References
|
||||
[Pointers back to role-specific analysis documents]
|
||||
- @../{role}/analysis-${feature.feature_id}-${feature.feature_slug}.md for each contributing role
|
||||
- @../guidance-specification.md#feature-decomposition
|
||||
|
||||
## 7. Cross-Feature Dependencies
|
||||
[Dependencies on and from other features]
|
||||
- **Depends on**: [Feature IDs this feature requires]
|
||||
- **Required by**: [Feature IDs that depend on this feature]
|
||||
- **Shared patterns**: References to analysis-cross-cutting.md patterns
|
||||
- **Integration points**: [Specific interfaces between features]
|
||||
---
|
||||
|
||||
## Completion Criteria
|
||||
- All 7 sections populated with aggregated content
|
||||
- Section 2 (Design Decisions) is the most detailed section (40%+ of word count)
|
||||
- All conflicts from conflict_map_entry addressed with resolutions
|
||||
- Cross-feature dependencies explicitly documented
|
||||
- Word count between 1500-2500
|
||||
- No placeholder text except [DECISION NEEDED] for genuinely unresolved items
|
||||
`)
|
||||
```
|
||||
|
||||
**Agent Characteristics (Phase 6)**:
|
||||
- **Isolation**: Each agent processes exactly ONE feature (parallel safe)
|
||||
- **Dependencies**: Requires Phase 3A feature_conflict_map and Phase 5 updated role analyses
|
||||
- **Input budget**: ~6.5K words per agent (3-4 role sub-docs + conflict map entry)
|
||||
- **Output budget**: 1500-2500 words per feature spec
|
||||
|
||||
### Phase 6.5: Feature Index Generation [feature_mode only]
|
||||
|
||||
**Skip condition**: Same as Phase 6 - skip if `feature_mode` is false.
|
||||
|
||||
**Purpose**: Collect all Phase 6 outputs and generate structured `feature-index.json`.
|
||||
|
||||
#### Step 1: Collect Feature Spec Outputs
|
||||
|
||||
```javascript
|
||||
const feature_spec_files = Glob(`${brainstorm_dir}/feature-specs/F-*-*.md`);
|
||||
|
||||
const cross_cutting_specs = participating_roles
|
||||
.map(role => `${brainstorm_dir}/${role}/analysis-cross-cutting.md`)
|
||||
.filter(path => fileExists(path));
|
||||
```
|
||||
|
||||
#### Step 2: Generate feature-index.json
|
||||
|
||||
```javascript
|
||||
const feature_index = {
|
||||
"version": "1.0",
|
||||
"generated_at": new Date().toISOString(),
|
||||
"session_id": session_id,
|
||||
"feature_mode": true,
|
||||
"features": feature_list.map(feature => {
|
||||
const fid = feature.id;
|
||||
const slug = feature.slug;
|
||||
const spec_path = `feature-specs/${fid}-${slug}.md`;
|
||||
const spec_exists = fileExists(`${brainstorm_dir}/${spec_path}`);
|
||||
|
||||
const contributing_roles = participating_roles.filter(role =>
|
||||
fileExists(`${brainstorm_dir}/${role}/analysis-${fid}-${slug}.md`)
|
||||
);
|
||||
|
||||
const cross_cutting_refs = feature_conflict_map[fid]
|
||||
? feature_conflict_map[fid].cross_refs
|
||||
: [];
|
||||
|
||||
return {
|
||||
"id": fid,
|
||||
"slug": slug,
|
||||
"name": feature.description,
|
||||
"priority": feature.priority,
|
||||
"spec_path": spec_exists ? spec_path : null,
|
||||
"contributing_roles": contributing_roles,
|
||||
"cross_cutting_refs": cross_cutting_refs
|
||||
};
|
||||
}),
|
||||
"cross_cutting_specs": cross_cutting_specs.map(path =>
|
||||
path.replace(brainstorm_dir + '/', '')
|
||||
)
|
||||
};
|
||||
|
||||
Write(
|
||||
`${brainstorm_dir}/feature-index.json`,
|
||||
JSON.stringify(feature_index, null, 2)
|
||||
);
|
||||
```
|
||||
|
||||
#### feature-index.json Schema
|
||||
|
||||
```json
|
||||
{
|
||||
"version": "1.0",
|
||||
"generated_at": "2026-02-11T10:00:00.000Z",
|
||||
"session_id": "WFS-xxx",
|
||||
"feature_mode": true,
|
||||
"features": [
|
||||
{
|
||||
"id": "F-001",
|
||||
"slug": "real-time-sync",
|
||||
"name": "Real-time collaborative synchronization",
|
||||
"priority": "High",
|
||||
"spec_path": "feature-specs/F-001-real-time-sync.md",
|
||||
"contributing_roles": ["system-architect", "ux-expert", "data-architect"],
|
||||
"cross_cutting_refs": ["F-003 offline-mode depends on sync strategy"]
|
||||
}
|
||||
],
|
||||
"cross_cutting_specs": [
|
||||
"system-architect/analysis-cross-cutting.md",
|
||||
"ux-expert/analysis-cross-cutting.md"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**Consumers**: `action-planning-agent` reads feature-index.json to generate task JSONs. `code-developer` loads individual feature specs as implementation context.
|
||||
|
||||
### Phase 7: Finalization
|
||||
|
||||
#### Step 1: Update Context Package
|
||||
|
||||
```javascript
|
||||
const context_pkg = Read(".workflow/active/WFS-{session}/.process/context-package.json")
|
||||
|
||||
// Update guidance-specification if exists
|
||||
// Update synthesis-specification if exists
|
||||
// Re-read all role analysis files
|
||||
// Update metadata timestamps
|
||||
|
||||
// If feature_mode: add feature-index.json and feature-specs paths
|
||||
if (feature_mode) {
|
||||
context_pkg.feature_index_path = `${brainstorm_dir}/feature-index.json`;
|
||||
context_pkg.feature_specs_dir = `${brainstorm_dir}/feature-specs/`;
|
||||
context_pkg.feature_mode = true;
|
||||
}
|
||||
|
||||
Write(context_pkg_path, JSON.stringify(context_pkg))
|
||||
```
|
||||
|
||||
#### Step 2: Update Session Metadata
|
||||
|
||||
```json
|
||||
{
|
||||
"phases": {
|
||||
"BRAINSTORM": {
|
||||
"status": "clarification_completed",
|
||||
"clarification_completed": true,
|
||||
"completed_at": "timestamp",
|
||||
"participating_roles": ["..."],
|
||||
"clarification_results": {
|
||||
"enhancements_applied": ["EP-001", "EP-002"],
|
||||
"questions_asked": 3,
|
||||
"categories_clarified": ["Architecture", "UX"],
|
||||
"roles_updated": ["role1", "role2"]
|
||||
},
|
||||
"feature_spec_results": {
|
||||
"feature_mode": true,
|
||||
"features_generated": ["F-001", "F-002", "F-003"],
|
||||
"feature_index_path": ".brainstorming/feature-index.json",
|
||||
"feature_specs_dir": ".brainstorming/feature-specs/",
|
||||
"conflict_map_generated": true
|
||||
},
|
||||
"quality_metrics": {
|
||||
"user_intent_alignment": "validated",
|
||||
"ambiguity_resolution": "complete",
|
||||
"terminology_consistency": "enforced"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Note**: `feature_spec_results` only present when `feature_mode` is true.
|
||||
|
||||
#### Step 3: Completion Report
|
||||
|
||||
```markdown
|
||||
## Synthesis Complete
|
||||
|
||||
**Session**: {sessionId}
|
||||
**Enhancements Applied**: EP-001, EP-002, EP-003
|
||||
**Questions Answered**: 3/5
|
||||
**Roles Updated**: role1, role2, role3
|
||||
|
||||
### Feature Specs (feature_mode only)
|
||||
**Feature Specs Generated**: F-001, F-002, F-003
|
||||
**Feature Index**: .brainstorming/feature-index.json
|
||||
**Spec Directory**: .brainstorming/feature-specs/
|
||||
|
||||
### Next Steps
|
||||
PROCEED: `/workflow:plan --session {session-id}`
|
||||
```
|
||||
|
||||
## Output
|
||||
|
||||
**Location (role analyses)**: `.workflow/active/WFS-{session}/.brainstorming/[role]/analysis*.md`
|
||||
**Location (feature specs)**: `.workflow/active/WFS-{session}/.brainstorming/feature-specs/F-{id}-{slug}.md` [feature_mode]
|
||||
**Location (feature index)**: `.workflow/active/WFS-{session}/.brainstorming/feature-index.json` [feature_mode]
|
||||
|
||||
**Updated Directory Structure** (feature_mode):
|
||||
```
|
||||
.workflow/active/WFS-{session}/.brainstorming/
|
||||
├── guidance-specification.md
|
||||
├── feature-index.json # Phase 6.5 output
|
||||
├── feature-specs/ # Phase 6 output directory
|
||||
│ ├── F-001-{slug}.md # Consolidated feature spec (1500-2500 words)
|
||||
│ ├── F-002-{slug}.md
|
||||
│ └── F-00N-{slug}.md
|
||||
├── {role-1}/
|
||||
│ ├── analysis.md # Role overview index (read by Phase 3A)
|
||||
│ ├── analysis-cross-cutting.md
|
||||
│ ├── analysis-F-001-{slug}.md # Per-feature detail (read by Phase 6)
|
||||
│ └── analysis-F-002-{slug}.md
|
||||
└── {role-N}/
|
||||
└── ...
|
||||
```
|
||||
|
||||
**Updated Role Analysis Structure**:
|
||||
```markdown
|
||||
## Clarifications
|
||||
### Session {date}
|
||||
- **Q**: {question} (Category: {category})
|
||||
**A**: {answer}
|
||||
|
||||
## {Existing Sections}
|
||||
{Refined content based on clarifications}
|
||||
```
|
||||
|
||||
**Changes**:
|
||||
- User intent validated/corrected
|
||||
- Requirements more specific/measurable
|
||||
- Architecture with rationale
|
||||
- Ambiguities resolved, placeholders removed
|
||||
- Consistent terminology
|
||||
- Feature specs generated with cross-role conflict resolution [feature_mode]
|
||||
- Feature index provides structured access for downstream consumers [feature_mode]
|
||||
|
||||
## Quality Checklist
|
||||
|
||||
**Content**:
|
||||
- All role analyses loaded/analyzed
|
||||
- Cross-role analysis (consensus, conflicts, gaps)
|
||||
- 9-category ambiguity scan
|
||||
- Questions prioritized
|
||||
|
||||
**Analysis**:
|
||||
- User intent validated
|
||||
- Cross-role synthesis complete
|
||||
- Ambiguities resolved
|
||||
- Terminology consistent
|
||||
|
||||
**Documents**:
|
||||
- Clarifications section formatted
|
||||
- Sections reflect answers
|
||||
- No placeholders (TODO/TBD)
|
||||
- Valid Markdown
|
||||
|
||||
**Feature Specs (feature_mode only)**:
|
||||
- Phase 3A reads only analysis.md index files (not sub-documents), input token <= 5K words
|
||||
- feature_conflict_map generated with consensus/conflicts/cross_refs per feature
|
||||
- Phase 6 parallel agents defined: one per feature, input token <= 7K words each
|
||||
- Feature spec template has 7 sections, Section 2 (Design Decisions) is core
|
||||
- Four-layer aggregation rules applied
|
||||
- Each feature spec is 1500-2500 words
|
||||
- feature-index.json generated with features[] + cross_cutting_specs[]
|
||||
- feature-specs/ directory created with F-{id}-{slug}.md files
|
||||
|
||||
- **TodoWrite**: Mark Phase 4 completed, collapse all sub-tasks to summary
|
||||
|
||||
## Next Phase
|
||||
|
||||
Return to orchestrator. Auto mode workflow is now complete. Report final summary to user.
|
||||
@@ -147,7 +147,7 @@ ${issueList}
|
||||
- Solution ID format: SOL-{issue-id}-{uid} (uid: 4 random alphanumeric chars, e.g., a7x9)
|
||||
- Single solution per issue → auto-bind via ccw issue bind
|
||||
- Multiple solutions → register only, return pending_selection
|
||||
- Tasks must have quantified acceptance.criteria
|
||||
- Tasks must have quantified convergence.criteria
|
||||
|
||||
### Return Summary
|
||||
{"bound":[{"issue_id":"...","solution_id":"...","task_count":N}],"pending_selection":[{"issue_id":"...","solutions":[{"id":"...","description":"...","task_count":N}]}]}
|
||||
@@ -279,8 +279,8 @@ Before completing, verify:
|
||||
- [ ] All input issues have solutions in `solutions/{issue-id}.jsonl`
|
||||
- [ ] Single solution issues are auto-bound (`bound_solution_id` set)
|
||||
- [ ] Multi-solution issues returned in `pending_selection` for user choice
|
||||
- [ ] Each solution has executable tasks with `modification_points`
|
||||
- [ ] Task acceptance criteria are quantified (not vague)
|
||||
- [ ] Each solution has executable tasks with `files`
|
||||
- [ ] Task convergence criteria are quantified (not vague)
|
||||
- [ ] Conflicts detected and reported (if multiple issues touch same files)
|
||||
- [ ] Issue status updated to `planned` after binding
|
||||
|
||||
|
||||
@@ -66,13 +66,15 @@ interface Task {
|
||||
scope: string; // Required: module path or feature area
|
||||
action: Action; // Required: Create|Update|Implement|...
|
||||
description?: string;
|
||||
modification_points?: Array<{file, target, change}>;
|
||||
files?: Array<{path, target?, change?, action?, conflict_risk?}>;
|
||||
modification_points?: Array<{file, target, change}>; // Legacy, prefer files
|
||||
implementation: string[]; // Required: step-by-step guide
|
||||
test?: { unit?, integration?, commands?, coverage_target? };
|
||||
acceptance: { criteria: string[], verification: string[] }; // Required
|
||||
test?: { unit?, integration?, commands?, coverage_target?, manual_checks? };
|
||||
convergence: { criteria: string[], verification?: string | string[] }; // Required
|
||||
acceptance?: { criteria: string[], verification: string[] }; // Legacy, prefer convergence
|
||||
commit?: { type, scope, message_template, breaking? };
|
||||
depends_on?: string[];
|
||||
priority?: number; // 1-5 (default: 3)
|
||||
priority?: string | number; // "critical"|"high"|"medium"|"low" or 1-5
|
||||
}
|
||||
|
||||
type Action = 'Create' | 'Update' | 'Implement' | 'Refactor' | 'Add' | 'Delete' | 'Configure' | 'Test' | 'Fix';
|
||||
@@ -187,19 +189,16 @@ function extractFromLitePlan(folderPath) {
|
||||
scope: t.scope || '',
|
||||
action: t.action || 'Implement',
|
||||
description: t.description || t.title,
|
||||
modification_points: t.modification_points || [],
|
||||
files: t.files || (t.modification_points || []).map(mp => ({path: mp.file, target: mp.target, change: mp.change})),
|
||||
implementation: Array.isArray(t.implementation) ? t.implementation : [t.implementation || ''],
|
||||
test: t.verification ? {
|
||||
unit: t.verification.unit_tests,
|
||||
integration: t.verification.integration_tests,
|
||||
commands: t.verification.manual_checks
|
||||
} : {},
|
||||
acceptance: {
|
||||
criteria: Array.isArray(t.acceptance) ? t.acceptance : [t.acceptance || ''],
|
||||
verification: t.verification?.manual_checks || []
|
||||
},
|
||||
convergence: normalizeConvergence(t.acceptance, t.convergence),
|
||||
depends_on: t.depends_on || [],
|
||||
priority: 3
|
||||
priority: t.priority || 'medium'
|
||||
})),
|
||||
metadata: {
|
||||
source_type: 'lite-plan',
|
||||
@@ -243,13 +242,10 @@ function extractFromWorkflowSession(sessionPath) {
|
||||
scope: task.scope || inferScopeFromTask(task),
|
||||
action: capitalizeAction(task.type) || 'Implement',
|
||||
description: task.description,
|
||||
modification_points: task.implementation?.modification_points || [],
|
||||
files: task.files || (task.implementation?.modification_points || []).map(mp => ({path: mp.file, target: mp.target, change: mp.change})),
|
||||
implementation: task.implementation?.steps || [],
|
||||
test: task.implementation?.test || {},
|
||||
acceptance: {
|
||||
criteria: task.acceptance_criteria || [],
|
||||
verification: task.verification_steps || []
|
||||
},
|
||||
convergence: normalizeConvergence(task.acceptance_criteria, task.convergence),
|
||||
commit: task.commit,
|
||||
depends_on: (task.depends_on || []).map(d => d.replace(/^IMPL-0*/, 'T')),
|
||||
priority: task.priority || 3
|
||||
@@ -271,10 +267,11 @@ function extractFromWorkflowSession(sessionPath) {
|
||||
}
|
||||
|
||||
function inferScopeFromTask(task) {
|
||||
if (task.implementation?.modification_points?.length) {
|
||||
const files = task.implementation.modification_points.map(m => m.file);
|
||||
// Find common directory prefix
|
||||
const dirs = files.map(f => f.split('/').slice(0, -1).join('/'));
|
||||
// Prefer new files[] field, fall back to legacy modification_points
|
||||
const filePaths = task.files?.map(f => f.path) ||
|
||||
task.implementation?.modification_points?.map(m => m.file) || [];
|
||||
if (filePaths.length) {
|
||||
const dirs = filePaths.map(f => f.split('/').slice(0, -1).join('/'));
|
||||
return [...new Set(dirs)][0] || '';
|
||||
}
|
||||
return '';
|
||||
@@ -339,15 +336,12 @@ ${fileContent}`;
|
||||
scope: t.scope || '',
|
||||
action: validateAction(t.action) || 'Implement',
|
||||
description: t.description || t.title,
|
||||
modification_points: t.modification_points || [],
|
||||
files: t.files || (t.modification_points || []).map(mp => ({path: mp.file, target: mp.target, change: mp.change})),
|
||||
implementation: Array.isArray(t.implementation) ? t.implementation : [t.implementation || ''],
|
||||
test: t.test || {},
|
||||
acceptance: {
|
||||
criteria: Array.isArray(t.acceptance) ? t.acceptance : [t.acceptance || ''],
|
||||
verification: t.verification || []
|
||||
},
|
||||
convergence: normalizeConvergence(t.acceptance, t.convergence),
|
||||
depends_on: t.depends_on || [],
|
||||
priority: t.priority || 3
|
||||
priority: t.priority || 'medium'
|
||||
}));
|
||||
|
||||
return {
|
||||
@@ -391,12 +385,12 @@ function extractFromJsonFile(filePath) {
|
||||
scope: t.scope || '',
|
||||
action: t.action || 'Implement',
|
||||
description: t.description || t.title,
|
||||
modification_points: t.modification_points || [],
|
||||
files: t.files || (t.modification_points || []).map(mp => ({path: mp.file, target: mp.target, change: mp.change})),
|
||||
implementation: Array.isArray(t.implementation) ? t.implementation : [t.implementation || ''],
|
||||
test: t.test || t.verification || {},
|
||||
acceptance: normalizeAcceptance(t.acceptance),
|
||||
convergence: normalizeConvergence(t.acceptance, t.convergence),
|
||||
depends_on: t.depends_on || [],
|
||||
priority: t.priority || 3
|
||||
priority: t.priority || 'medium'
|
||||
}));
|
||||
|
||||
return {
|
||||
@@ -416,11 +410,13 @@ function extractFromJsonFile(filePath) {
|
||||
throw new Error('E002: JSON file does not contain valid plan structure (missing tasks array)');
|
||||
}
|
||||
|
||||
function normalizeAcceptance(acceptance) {
|
||||
if (!acceptance) return { criteria: [], verification: [] };
|
||||
if (typeof acceptance === 'object' && acceptance.criteria) return acceptance;
|
||||
if (Array.isArray(acceptance)) return { criteria: acceptance, verification: [] };
|
||||
return { criteria: [String(acceptance)], verification: [] };
|
||||
function normalizeConvergence(acceptance, convergence) {
|
||||
// Prefer new convergence field; fall back to legacy acceptance
|
||||
const source = convergence || acceptance;
|
||||
if (!source) return { criteria: [], verification: [] };
|
||||
if (typeof source === 'object' && source.criteria) return source;
|
||||
if (Array.isArray(source)) return { criteria: source, verification: [] };
|
||||
return { criteria: [String(source)], verification: [] };
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -93,12 +93,12 @@ interface Task {
|
||||
description: string;
|
||||
|
||||
implementation: string[]; // Step-by-step guide
|
||||
acceptance: {
|
||||
convergence: {
|
||||
criteria: string[]; // What defines success
|
||||
verification: string[]; // How to verify
|
||||
};
|
||||
|
||||
priority: number; // 1-5
|
||||
priority: string; // "critical"|"high"|"medium"|"low"
|
||||
depends_on: string[]; // Task dependencies
|
||||
}
|
||||
```
|
||||
@@ -152,7 +152,7 @@ Phase 5: Generate Solution Tasks
|
||||
├─ T1: Research & Validate (if main_challenges exist)
|
||||
├─ T2: Design & Specification (if key_strengths exist)
|
||||
├─ T3+: Implementation tasks (from idea.next_steps)
|
||||
└─ Each task includes: implementation steps + acceptance criteria
|
||||
└─ Each task includes: implementation steps + convergence criteria
|
||||
```
|
||||
|
||||
### Step 3.6: Bind Solution
|
||||
@@ -228,7 +228,7 @@ Phase 7: Next Steps
|
||||
- **Title**: `idea.title`
|
||||
- **Scope**: implementation
|
||||
- **Action**: Implement
|
||||
- **Generic implementation + acceptance criteria**
|
||||
- **Generic implementation + convergence criteria**
|
||||
|
||||
## Priority Calculation
|
||||
|
||||
|
||||
@@ -120,13 +120,13 @@ Phase 1 collects ALL roles at once (not one at a time):
|
||||
- Coordinator is always generated
|
||||
- Worker roles collected as a batch
|
||||
|
||||
### Pattern 5: Spec Reference (No Duplication)
|
||||
### Pattern 5: Self-Contained Specs
|
||||
|
||||
Design pattern specs are referenced from team-command-designer:
|
||||
Design pattern specs are included locally in `specs/`:
|
||||
```
|
||||
specs → ../team-command-designer/specs/team-design-patterns.md
|
||||
specs → ../team-command-designer/specs/collaboration-patterns.md
|
||||
specs → ../team-command-designer/specs/quality-standards.md
|
||||
specs/team-design-patterns.md # Infrastructure patterns (8) + collaboration index
|
||||
specs/collaboration-patterns.md # 10 collaboration patterns with convergence control
|
||||
specs/quality-standards.md # Quality criteria
|
||||
```
|
||||
|
||||
---
|
||||
@@ -139,9 +139,9 @@ specs → ../team-command-designer/specs/quality-standards.md
|
||||
|
||||
| Document | Purpose | When |
|
||||
|----------|---------|------|
|
||||
| [../team-command-designer/specs/team-design-patterns.md](../team-command-designer/specs/team-design-patterns.md) | Infrastructure patterns (8) + collaboration index | **Must read** |
|
||||
| [../team-command-designer/specs/collaboration-patterns.md](../team-command-designer/specs/collaboration-patterns.md) | 10 collaboration patterns with convergence control | **Must read** |
|
||||
| [../team-command-designer/specs/quality-standards.md](../team-command-designer/specs/quality-standards.md) | Quality criteria | Must read before generation |
|
||||
| [specs/team-design-patterns.md](specs/team-design-patterns.md) | Infrastructure patterns (8) + collaboration index | **Must read** |
|
||||
| [specs/collaboration-patterns.md](specs/collaboration-patterns.md) | 10 collaboration patterns with convergence control | **Must read** |
|
||||
| [specs/quality-standards.md](specs/quality-standards.md) | Quality criteria | Must read before generation |
|
||||
|
||||
### Template Files (Must read before generation)
|
||||
|
||||
@@ -166,8 +166,8 @@ specs → ../team-command-designer/specs/quality-standards.md
|
||||
|
||||
```
|
||||
Phase 0: Specification Study (MANDATORY)
|
||||
-> Read: ../team-command-designer/specs/team-design-patterns.md
|
||||
-> Read: ../team-command-designer/specs/collaboration-patterns.md
|
||||
-> Read: specs/team-design-patterns.md
|
||||
-> Read: specs/collaboration-patterns.md
|
||||
-> Read: templates/skill-router-template.md + templates/role-template.md
|
||||
-> Read: 1-2 existing team commands for reference
|
||||
-> Output: Internalized requirements (in-memory)
|
||||
|
||||
@@ -13,7 +13,7 @@ Collect team definition and ALL role definitions in one pass.
|
||||
## Input
|
||||
|
||||
- User request (`$ARGUMENTS` or interactive input)
|
||||
- Specification: `../team-command-designer/specs/team-design-patterns.md` (read in Phase 0)
|
||||
- Specification: `specs/team-design-patterns.md` (read in Phase 0)
|
||||
|
||||
## Execution Steps
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ Analyze applicable patterns for each role in the team.
|
||||
## Input
|
||||
|
||||
- Dependency: `team-config.json` (Phase 1)
|
||||
- Specification: `../team-command-designer/specs/team-design-patterns.md` (read in Phase 0)
|
||||
- Specification: `specs/team-design-patterns.md` (read in Phase 0)
|
||||
|
||||
## Execution Steps
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ Verify quality and deliver the final skill package.
|
||||
## Input
|
||||
|
||||
- Dependency: `{workDir}/preview/` (Phase 3), `integration-report.json` (Phase 4)
|
||||
- Specification: `../team-command-designer/specs/quality-standards.md`
|
||||
- Specification: `specs/quality-standards.md`
|
||||
|
||||
## Execution Steps
|
||||
|
||||
|
||||
1341
.claude/skills/team-skill-designer/specs/collaboration-patterns.md
Normal file
1341
.claude/skills/team-skill-designer/specs/collaboration-patterns.md
Normal file
File diff suppressed because it is too large
Load Diff
126
.claude/skills/team-skill-designer/specs/quality-standards.md
Normal file
126
.claude/skills/team-skill-designer/specs/quality-standards.md
Normal file
@@ -0,0 +1,126 @@
|
||||
# Quality Standards for Team Commands
|
||||
|
||||
Quality assessment criteria for generated team command .md files.
|
||||
|
||||
## When to Use
|
||||
|
||||
| Phase | Usage | Section |
|
||||
|-------|-------|---------|
|
||||
| Phase 5 | Score generated command | All dimensions |
|
||||
| Phase 3 | Guide generation quality | Checklist |
|
||||
|
||||
---
|
||||
|
||||
## Quality Dimensions
|
||||
|
||||
### 1. Completeness (25%)
|
||||
|
||||
| Score | Criteria |
|
||||
|-------|----------|
|
||||
| 100% | All 15 required sections present with substantive content |
|
||||
| 80% | 12+ sections present, minor gaps in non-critical areas |
|
||||
| 60% | Core sections present (front matter, message bus, 5 phases, error handling) |
|
||||
| 40% | Missing critical sections |
|
||||
| 0% | Skeleton only |
|
||||
|
||||
**Required Sections Checklist:**
|
||||
- [ ] YAML front matter with `group: team`
|
||||
- [ ] Overview with core capabilities
|
||||
- [ ] Role Definition (name, responsibility, communication)
|
||||
- [ ] Message Bus section with team_msg examples
|
||||
- [ ] Message Types table
|
||||
- [ ] Execution Process overview diagram
|
||||
- [ ] Phase 1: Task Discovery implementation
|
||||
- [ ] Phase 2: Context Loading implementation
|
||||
- [ ] Phase 3: Core Work implementation
|
||||
- [ ] Phase 4: Validation/Summary implementation
|
||||
- [ ] Phase 5: Report + Loop implementation
|
||||
- [ ] Error Handling table
|
||||
- [ ] Code examples in all phases
|
||||
|
||||
### 2. Pattern Compliance (25%)
|
||||
|
||||
| Score | Criteria |
|
||||
|-------|----------|
|
||||
| 100% | All 8 infrastructure patterns + selected collaboration patterns fully implemented |
|
||||
| 80% | 6 core infra patterns + at least 1 collaboration pattern with convergence |
|
||||
| 60% | Minimum 6 infra patterns, collaboration patterns present but incomplete |
|
||||
| 40% | Missing critical patterns (message bus or task lifecycle) |
|
||||
| 0% | No pattern compliance |
|
||||
|
||||
**Infrastructure Pattern Checklist:**
|
||||
- [ ] Pattern 1: Message bus - team_msg before every SendMessage
|
||||
- [ ] Pattern 1b: CLI fallback - `ccw team` CLI fallback section with parameter mapping
|
||||
- [ ] Pattern 2: YAML front matter - all fields present, group: team
|
||||
- [ ] Pattern 3: Task lifecycle - TaskList/Get/Update flow
|
||||
- [ ] Pattern 4: Five-phase structure - all 5 phases present
|
||||
- [ ] Pattern 5: Complexity-adaptive (if applicable)
|
||||
- [ ] Pattern 6: Coordinator spawn compatible
|
||||
- [ ] Pattern 7: Error handling table
|
||||
- [ ] Pattern 8: Session files (if applicable)
|
||||
|
||||
**Collaboration Pattern Checklist:**
|
||||
- [ ] At least one CP selected (CP-1 minimum)
|
||||
- [ ] Each selected CP has convergence criteria defined
|
||||
- [ ] Each selected CP has feedback loop mechanism
|
||||
- [ ] Each selected CP has timeout/fallback behavior
|
||||
- [ ] CP-specific message types registered in message bus section
|
||||
- [ ] Escalation path defined (CP-5) for error scenarios
|
||||
|
||||
### 3. Integration (25%)
|
||||
|
||||
| Score | Criteria |
|
||||
|-------|----------|
|
||||
| 100% | All integration checks pass, spawn snippet ready |
|
||||
| 80% | Minor integration notes, no blocking issues |
|
||||
| 60% | Some checks need attention but functional |
|
||||
| 40% | Task prefix conflict or missing critical tools |
|
||||
| 0% | Incompatible with team system |
|
||||
|
||||
### 4. Consistency (25%)
|
||||
|
||||
| Score | Criteria |
|
||||
|-------|----------|
|
||||
| 100% | Role name, task prefix, message types consistent throughout |
|
||||
| 80% | Minor inconsistencies in non-critical areas |
|
||||
| 60% | Some mixed terminology but intent clear |
|
||||
| 40% | Confusing or contradictory content |
|
||||
| 0% | Internally inconsistent |
|
||||
|
||||
---
|
||||
|
||||
## Quality Gates
|
||||
|
||||
| Gate | Threshold | Action |
|
||||
|------|-----------|--------|
|
||||
| PASS | >= 80% | Deliver to `.claude/commands/team/{team-name}/` |
|
||||
| REVIEW | 60-79% | Fix recommendations, re-validate |
|
||||
| FAIL | < 60% | Major rework needed, re-run from Phase 3 |
|
||||
|
||||
---
|
||||
|
||||
## Issue Classification
|
||||
|
||||
### Errors (Must Fix)
|
||||
|
||||
- Missing YAML front matter
|
||||
- Missing `group: team`
|
||||
- No message bus section
|
||||
- No task lifecycle (TaskList/Get/Update)
|
||||
- No SendMessage to coordinator
|
||||
- Task prefix conflicts with existing
|
||||
|
||||
### Warnings (Should Fix)
|
||||
|
||||
- Missing error handling table
|
||||
- Incomplete Phase implementation (skeleton only)
|
||||
- Missing team_msg before some SendMessage calls
|
||||
- Missing CLI fallback section (`### CLI 回退` with `ccw team` examples)
|
||||
- No complexity-adaptive routing when role is complex
|
||||
|
||||
### Info (Nice to Have)
|
||||
|
||||
- Code examples could be more detailed
|
||||
- Additional message type examples
|
||||
- Session file structure documentation
|
||||
- CLI integration examples
|
||||
472
.claude/skills/team-skill-designer/specs/team-design-patterns.md
Normal file
472
.claude/skills/team-skill-designer/specs/team-design-patterns.md
Normal file
@@ -0,0 +1,472 @@
|
||||
# Team Command Design Patterns
|
||||
|
||||
> Extracted from 5 production team commands: coordinate, plan, execute, test, review
|
||||
> Extended with 10 collaboration patterns for diverse team interaction models
|
||||
|
||||
---
|
||||
|
||||
## Pattern Architecture
|
||||
|
||||
```
|
||||
Team Design Patterns
|
||||
├── Section A: Infrastructure Patterns (8) ← HOW to build a team command
|
||||
│ ├── Pattern 1: Message Bus Integration
|
||||
│ ├── Pattern 2: YAML Front Matter
|
||||
│ ├── Pattern 3: Task Lifecycle
|
||||
│ ├── Pattern 4: Five-Phase Execution
|
||||
│ ├── Pattern 5: Complexity-Adaptive Routing
|
||||
│ ├── Pattern 6: Coordinator Spawn Integration
|
||||
│ ├── Pattern 7: Error Handling Table
|
||||
│ └── Pattern 8: Session File Structure
|
||||
│
|
||||
└── Section B: Collaboration Patterns (10) ← HOW agents interact
|
||||
├── CP-1: Linear Pipeline (线性流水线)
|
||||
├── CP-2: Review-Fix Cycle (审查修复循环)
|
||||
├── CP-3: Parallel Fan-out/Fan-in (并行扇出扇入)
|
||||
├── CP-4: Consensus Gate (共识门控)
|
||||
├── CP-5: Escalation Chain (逐级升级)
|
||||
├── CP-6: Incremental Delivery (增量交付)
|
||||
├── CP-7: Swarming (群策攻关)
|
||||
├── CP-8: Consulting/Advisory (咨询顾问)
|
||||
├── CP-9: Dual-Track (双轨并行)
|
||||
└── CP-10: Post-Mortem (复盘回顾)
|
||||
```
|
||||
|
||||
**Section B** collaboration patterns are documented in: [collaboration-patterns.md](collaboration-patterns.md)
|
||||
|
||||
---
|
||||
|
||||
## When to Use
|
||||
|
||||
| Phase | Usage | Section |
|
||||
|-------|-------|---------|
|
||||
| Phase 0 | Understand all patterns before design | All sections |
|
||||
| Phase 2 | Select applicable infrastructure + collaboration patterns | Pattern catalog |
|
||||
| Phase 3 | Apply patterns during generation | Implementation details |
|
||||
| Phase 4 | Verify compliance | Checklists |
|
||||
|
||||
---
|
||||
|
||||
# Section A: Infrastructure Patterns
|
||||
|
||||
## Pattern 1: Message Bus Integration
|
||||
|
||||
Every teammate must use `mcp__ccw-tools__team_msg` for persistent logging before every `SendMessage`.
|
||||
|
||||
### Structure
|
||||
|
||||
```javascript
|
||||
// BEFORE every SendMessage, call:
|
||||
mcp__ccw-tools__team_msg({
|
||||
operation: "log",
|
||||
team: teamName,
|
||||
from: "<role-name>", // planner | executor | tester | <new-role>
|
||||
to: "coordinator",
|
||||
type: "<message-type>",
|
||||
summary: "<human-readable summary>",
|
||||
ref: "<optional file path>",
|
||||
data: { /* optional structured payload */ }
|
||||
})
|
||||
```
|
||||
|
||||
### Standard Message Types
|
||||
|
||||
| Type | Direction | Trigger | Payload |
|
||||
|------|-----------|---------|---------|
|
||||
| `plan_ready` | planner -> coordinator | Plan generation complete | `{ taskCount, complexity }` |
|
||||
| `plan_approved` | coordinator -> planner | Plan reviewed | `{ approved: true }` |
|
||||
| `plan_revision` | planner -> coordinator | Plan modified per feedback | `{ changes }` |
|
||||
| `task_unblocked` | coordinator -> any | Dependency resolved | `{ taskId }` |
|
||||
| `impl_complete` | executor -> coordinator | Implementation done | `{ changedFiles, syntaxClean }` |
|
||||
| `impl_progress` | any -> coordinator | Progress update | `{ batch, total }` |
|
||||
| `test_result` | tester -> coordinator | Test cycle end | `{ passRate, iterations }` |
|
||||
| `review_result` | tester -> coordinator | Review done | `{ verdict, findings }` |
|
||||
| `fix_required` | any -> coordinator | Critical issues | `{ details[] }` |
|
||||
| `error` | any -> coordinator | Blocking error | `{ message }` |
|
||||
| `shutdown` | coordinator -> all | Team dissolved | `{}` |
|
||||
|
||||
### Collaboration Pattern Message Types
|
||||
|
||||
| Type | Used By | Direction | Trigger |
|
||||
|------|---------|-----------|---------|
|
||||
| `vote` | CP-4 Consensus | any -> coordinator | Agent casts vote on proposal |
|
||||
| `escalate` | CP-5 Escalation | any -> coordinator | Agent escalates unresolved issue |
|
||||
| `increment_ready` | CP-6 Incremental | executor -> coordinator | Increment delivered for validation |
|
||||
| `swarm_join` | CP-7 Swarming | any -> coordinator | Agent joins swarm on blocker |
|
||||
| `consult_request` | CP-8 Consulting | any -> specialist | Agent requests expert advice |
|
||||
| `consult_response` | CP-8 Consulting | specialist -> requester | Expert provides advice |
|
||||
| `sync_checkpoint` | CP-9 Dual-Track | any -> coordinator | Track reaches sync point |
|
||||
| `retro_finding` | CP-10 Post-Mortem | any -> coordinator | Retrospective insight |
|
||||
|
||||
### Adding New Message Types
|
||||
|
||||
When designing a new role, define role-specific message types following the convention:
|
||||
- `{action}_ready` - Work product ready for review
|
||||
- `{action}_complete` - Work phase finished
|
||||
- `{action}_progress` - Intermediate progress update
|
||||
|
||||
### CLI Fallback
|
||||
|
||||
When `mcp__ccw-tools__team_msg` MCP is unavailable, use `ccw team` CLI as equivalent fallback:
|
||||
|
||||
```javascript
|
||||
// Fallback: Replace MCP call with Bash CLI (parameters map 1:1)
|
||||
Bash(`ccw team log --team "${teamName}" --from "<role>" --to "coordinator" --type "<type>" --summary "<summary>" [--ref <path>] [--data '<json>'] --json`)
|
||||
```
|
||||
|
||||
**Parameter mapping**: `team_msg(params)` → `ccw team <operation> --team <team> [--from/--to/--type/--summary/--ref/--data/--id/--last] [--json]`
|
||||
|
||||
**Coordinator** uses all 4 operations: `log`, `list`, `status`, `read`
|
||||
**Teammates** primarily use: `log`
|
||||
|
||||
### Message Bus Section Template
|
||||
|
||||
```markdown
|
||||
## 消息总线
|
||||
|
||||
每次 SendMessage **前**,必须调用 `mcp__ccw-tools__team_msg` 记录消息:
|
||||
|
||||
\`\`\`javascript
|
||||
mcp__ccw-tools__team_msg({ operation: "log", team: teamName, from: "<role>", to: "coordinator", type: "<type>", summary: "<summary>" })
|
||||
\`\`\`
|
||||
|
||||
### 支持的 Message Types
|
||||
|
||||
| Type | 方向 | 触发时机 | 说明 |
|
||||
|------|------|----------|------|
|
||||
| `<type>` | <role> → coordinator | <when> | <what> |
|
||||
|
||||
### CLI 回退
|
||||
|
||||
当 `mcp__ccw-tools__team_msg` MCP 不可用时,使用 `ccw team` CLI 作为等效回退:
|
||||
|
||||
\`\`\`javascript
|
||||
// 回退: 将 MCP 调用替换为 Bash CLI(参数一一对应)
|
||||
Bash(\`ccw team log --team "${teamName}" --from "<role>" --to "coordinator" --type "<type>" --summary "<summary>" --json\`)
|
||||
\`\`\`
|
||||
|
||||
**参数映射**: `team_msg(params)` → `ccw team log --team <team> --from <role> --to coordinator --type <type> --summary "<text>" [--ref <path>] [--data '<json>'] [--json]`
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Pattern 2: YAML Front Matter
|
||||
|
||||
Every team command file must start with standardized YAML front matter.
|
||||
|
||||
### Structure
|
||||
|
||||
```yaml
|
||||
---
|
||||
name: <command-name>
|
||||
description: Team <role> - <capabilities in Chinese>
|
||||
argument-hint: ""
|
||||
allowed-tools: SendMessage(*), TaskUpdate(*), TaskList(*), TaskGet(*), TodoWrite(*), Read(*), Write(*), Edit(*), Bash(*), Glob(*), Grep(*), Task(*)
|
||||
group: team
|
||||
---
|
||||
```
|
||||
|
||||
### Field Rules
|
||||
|
||||
| Field | Rule | Example |
|
||||
|-------|------|---------|
|
||||
| `name` | Lowercase, matches filename | `plan`, `execute`, `test` |
|
||||
| `description` | `Team <role> -` prefix + Chinese capability list | `Team planner - 多角度代码探索、结构化实现规划` |
|
||||
| `argument-hint` | Empty string for teammates, has hint for coordinator | `""` |
|
||||
| `allowed-tools` | Start with `SendMessage(*), TaskUpdate(*), TaskList(*), TaskGet(*)` | See each role |
|
||||
| `group` | Always `team` | `team` |
|
||||
|
||||
### Minimum Tool Set (All Teammates)
|
||||
|
||||
```
|
||||
SendMessage(*), TaskUpdate(*), TaskList(*), TaskGet(*), TodoWrite(*), Read(*), Bash(*), Glob(*), Grep(*)
|
||||
```
|
||||
|
||||
### Role-Specific Additional Tools
|
||||
|
||||
| Role Type | Additional Tools |
|
||||
|-----------|-----------------|
|
||||
| Read-only (reviewer, analyzer) | None extra |
|
||||
| Write-capable (executor, fixer) | `Write(*), Edit(*)` |
|
||||
| Agent-delegating (planner, executor) | `Task(*)` |
|
||||
|
||||
---
|
||||
|
||||
## Pattern 3: Task Lifecycle
|
||||
|
||||
All teammates follow the same task discovery and lifecycle pattern.
|
||||
|
||||
### Standard Flow
|
||||
|
||||
```javascript
|
||||
// Step 1: Find my tasks
|
||||
const tasks = TaskList()
|
||||
const myTasks = tasks.filter(t =>
|
||||
t.subject.startsWith('<PREFIX>-') && // PLAN-*, IMPL-*, TEST-*, REVIEW-*
|
||||
t.owner === '<role-name>' &&
|
||||
t.status === 'pending' &&
|
||||
t.blockedBy.length === 0 // Not blocked
|
||||
)
|
||||
|
||||
// Step 2: No tasks -> idle
|
||||
if (myTasks.length === 0) return
|
||||
|
||||
// Step 3: Claim task (lowest ID first)
|
||||
const task = TaskGet({ taskId: myTasks[0].id })
|
||||
TaskUpdate({ taskId: task.id, status: 'in_progress' })
|
||||
|
||||
// Step 4: Execute work
|
||||
// ... role-specific logic ...
|
||||
|
||||
// Step 5: Complete and loop
|
||||
TaskUpdate({ taskId: task.id, status: 'completed' })
|
||||
|
||||
// Step 6: Check for next task
|
||||
const nextTasks = TaskList().filter(t =>
|
||||
t.subject.startsWith('<PREFIX>-') &&
|
||||
t.owner === '<role-name>' &&
|
||||
t.status === 'pending' &&
|
||||
t.blockedBy.length === 0
|
||||
)
|
||||
if (nextTasks.length > 0) {
|
||||
// Continue with next task -> back to Step 3
|
||||
}
|
||||
```
|
||||
|
||||
### Task Prefix Convention
|
||||
|
||||
| Prefix | Role | Example |
|
||||
|--------|------|---------|
|
||||
| `PLAN-` | planner | `PLAN-001: Explore and plan implementation` |
|
||||
| `IMPL-` | executor | `IMPL-001: Implement approved plan` |
|
||||
| `TEST-` | tester | `TEST-001: Test-fix cycle` |
|
||||
| `REVIEW-` | tester | `REVIEW-001: Code review and requirement verification` |
|
||||
| `<NEW>-` | new role | Must be unique, uppercase, hyphen-suffixed |
|
||||
|
||||
### Task Chain (defined in coordinate.md)
|
||||
|
||||
```
|
||||
PLAN-001 → IMPL-001 → TEST-001 + REVIEW-001
|
||||
↑ blockedBy ↑ blockedBy
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Pattern 4: Five-Phase Execution Structure
|
||||
|
||||
Every team command follows a consistent 5-phase internal structure.
|
||||
|
||||
### Standard Phases
|
||||
|
||||
| Phase | Purpose | Common Actions |
|
||||
|-------|---------|----------------|
|
||||
| Phase 1: Task Discovery | Find and claim assigned tasks | TaskList, TaskGet, TaskUpdate |
|
||||
| Phase 2: Context Loading | Load necessary context for work | Read plan/config, detect framework |
|
||||
| Phase 3: Core Work | Execute primary responsibility | Role-specific logic |
|
||||
| Phase 4: Validation/Summary | Verify work quality | Syntax check, criteria verification |
|
||||
| Phase 5: Report + Loop | Report to coordinator, check next | SendMessage, TaskUpdate, TaskList |
|
||||
|
||||
### Phase Structure Template
|
||||
|
||||
```markdown
|
||||
### Phase N: <Phase Name>
|
||||
|
||||
\`\`\`javascript
|
||||
// Implementation code
|
||||
\`\`\`
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Pattern 5: Complexity-Adaptive Routing
|
||||
|
||||
All roles that process varying-difficulty tasks should implement adaptive routing.
|
||||
|
||||
### Decision Logic
|
||||
|
||||
```javascript
|
||||
function assessComplexity(description) {
|
||||
let score = 0
|
||||
if (/refactor|architect|restructure|module|system/.test(description)) score += 2
|
||||
if (/multiple|across|cross/.test(description)) score += 2
|
||||
if (/integrate|api|database/.test(description)) score += 1
|
||||
if (/security|performance/.test(description)) score += 1
|
||||
return score >= 4 ? 'High' : score >= 2 ? 'Medium' : 'Low'
|
||||
}
|
||||
```
|
||||
|
||||
### Routing Table
|
||||
|
||||
| Complexity | Direct Claude | CLI Agent | Sub-agent |
|
||||
|------------|---------------|-----------|-----------|
|
||||
| Low | Direct execution | - | - |
|
||||
| Medium | - | `cli-explore-agent` / `cli-lite-planning-agent` | - |
|
||||
| High | - | CLI agent | `code-developer` / `universal-executor` |
|
||||
|
||||
### Sub-agent Delegation Pattern
|
||||
|
||||
```javascript
|
||||
Task({
|
||||
subagent_type: "<agent-type>",
|
||||
run_in_background: false,
|
||||
description: "<brief description>",
|
||||
prompt: `
|
||||
## Task Objective
|
||||
${taskDescription}
|
||||
|
||||
## Output Location
|
||||
${sessionFolder}/${outputFile}
|
||||
|
||||
## MANDATORY FIRST STEPS
|
||||
1. Read: .workflow/project-tech.json (if exists)
|
||||
2. Read: .workflow/project-guidelines.json (if exists)
|
||||
|
||||
## Expected Output
|
||||
${expectedFormat}
|
||||
`
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Pattern 6: Coordinator Spawn Integration
|
||||
|
||||
New teammates must be spawnable from coordinate.md using standard pattern.
|
||||
|
||||
### Skill Path Format (Folder-Based)
|
||||
|
||||
Team commands use folder-based organization with colon-separated skill paths:
|
||||
|
||||
```
|
||||
File location: .claude/commands/team/{team-name}/{role-name}.md
|
||||
Skill path: team:{team-name}:{role-name}
|
||||
|
||||
Example:
|
||||
.claude/commands/team/spec/analyst.md → team:spec:analyst
|
||||
.claude/commands/team/security/scanner.md → team:security:scanner
|
||||
```
|
||||
|
||||
### Spawn Template
|
||||
|
||||
```javascript
|
||||
Task({
|
||||
subagent_type: "general-purpose",
|
||||
team_name: teamName,
|
||||
name: "<role-name>",
|
||||
prompt: `You are team "${teamName}" <ROLE>.
|
||||
|
||||
When you receive <PREFIX>-* tasks, call Skill(skill="team:${teamName}:<role-name>") to execute.
|
||||
|
||||
Current requirement: ${taskDescription}
|
||||
Constraints: ${constraints}
|
||||
|
||||
## Message Bus (Required)
|
||||
Before each SendMessage, call mcp__ccw-tools__team_msg:
|
||||
mcp__ccw-tools__team_msg({ operation: "log", team: "${teamName}", from: "<role>", to: "coordinator", type: "<type>", summary: "<summary>" })
|
||||
|
||||
Workflow:
|
||||
1. TaskList -> find <PREFIX>-* tasks assigned to you
|
||||
2. Skill(skill="team:${teamName}:<role-name>") to execute
|
||||
3. team_msg log + SendMessage results to coordinator
|
||||
4. TaskUpdate completed -> check next task`
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Pattern 7: Error Handling Table
|
||||
|
||||
Every command ends with a standardized error handling table.
|
||||
|
||||
### Template
|
||||
|
||||
```markdown
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| No tasks available | Idle, wait for coordinator assignment |
|
||||
| Plan/Context file not found | Notify coordinator, request location |
|
||||
| Sub-agent failure | Retry once, then fallback to direct execution |
|
||||
| Max iterations exceeded | Report to coordinator, suggest intervention |
|
||||
| Critical issue beyond scope | SendMessage fix_required to coordinator |
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Pattern 8: Session File Structure
|
||||
|
||||
Roles that produce artifacts follow standard session directory patterns.
|
||||
|
||||
### Convention
|
||||
|
||||
```
|
||||
.workflow/.team-<purpose>/{identifier}-{YYYY-MM-DD}/
|
||||
├── <work-product-files>
|
||||
├── manifest.json (if multiple outputs)
|
||||
└── .task/ (if generating task files)
|
||||
├── TASK-001.json
|
||||
└── TASK-002.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# Section B: Collaboration Patterns
|
||||
|
||||
> Complete specification: [collaboration-patterns.md](collaboration-patterns.md)
|
||||
|
||||
## Collaboration Pattern Quick Reference
|
||||
|
||||
Every collaboration pattern has these standard elements:
|
||||
|
||||
| Element | Description |
|
||||
|---------|-------------|
|
||||
| **Entry Condition** | When to activate this pattern |
|
||||
| **Workflow** | Step-by-step execution flow |
|
||||
| **Convergence Criteria** | How the pattern terminates successfully |
|
||||
| **Feedback Loop** | How information flows back to enable correction |
|
||||
| **Timeout/Fallback** | What happens when the pattern doesn't converge |
|
||||
| **Max Iterations** | Hard limit on cycles (where applicable) |
|
||||
|
||||
### Pattern Selection Guide
|
||||
|
||||
| Scenario | Recommended Pattern | Why |
|
||||
|----------|-------------------|-----|
|
||||
| Standard feature development | CP-1: Linear Pipeline | Well-defined sequential stages |
|
||||
| Code review with fixes needed | CP-2: Review-Fix Cycle | Iterative improvement until quality met |
|
||||
| Multi-angle analysis needed | CP-3: Fan-out/Fan-in | Parallel exploration, aggregated results |
|
||||
| Critical decision (architecture, security) | CP-4: Consensus Gate | Multiple perspectives before committing |
|
||||
| Agent stuck / self-repair failed | CP-5: Escalation Chain | Progressive expertise levels |
|
||||
| Large feature (many files) | CP-6: Incremental Delivery | Validated increments reduce risk |
|
||||
| Blocking issue stalls pipeline | CP-7: Swarming | All resources on one problem |
|
||||
| Domain-specific expertise needed | CP-8: Consulting | Expert advice without role change |
|
||||
| Design + Implementation parallel | CP-9: Dual-Track | Faster delivery with sync checkpoints |
|
||||
| Post-completion learning | CP-10: Post-Mortem | Capture insights for future improvement |
|
||||
|
||||
---
|
||||
|
||||
## Pattern Summary Checklist
|
||||
|
||||
When designing a new team command, verify:
|
||||
|
||||
### Infrastructure Patterns
|
||||
- [ ] YAML front matter with `group: team`
|
||||
- [ ] Message bus section with `team_msg` logging
|
||||
- [ ] CLI fallback section with `ccw team` CLI examples and parameter mapping
|
||||
- [ ] Role-specific message types defined
|
||||
- [ ] Task lifecycle: TaskList -> TaskGet -> TaskUpdate flow
|
||||
- [ ] Unique task prefix (no collision with existing PLAN/IMPL/TEST/REVIEW, scan `team/**/*.md`)
|
||||
- [ ] 5-phase execution structure
|
||||
- [ ] Complexity-adaptive routing (if applicable)
|
||||
- [ ] Coordinator spawn template integration
|
||||
- [ ] Error handling table
|
||||
- [ ] SendMessage communication to coordinator only
|
||||
- [ ] Session file structure (if producing artifacts)
|
||||
|
||||
### Collaboration Patterns
|
||||
- [ ] At least one collaboration pattern selected
|
||||
- [ ] Convergence criteria defined (max iterations / quality gate / timeout)
|
||||
- [ ] Feedback loop implemented (how results flow back)
|
||||
- [ ] Timeout/fallback behavior specified
|
||||
- [ ] Pattern-specific message types registered
|
||||
- [ ] Coordinator aware of pattern (can route messages accordingly)
|
||||
99
.claude/skills/workflow-plan/phases/01-session-discovery.md
Normal file
99
.claude/skills/workflow-plan/phases/01-session-discovery.md
Normal file
@@ -0,0 +1,99 @@
|
||||
# Phase 1: Session Discovery
|
||||
|
||||
Create or discover workflow session and initialize planning notes document.
|
||||
|
||||
## Objective
|
||||
|
||||
- Create a new workflow session via `/workflow:session:start`
|
||||
- Extract session ID for subsequent phases
|
||||
- Initialize planning-notes.md with user intent and N+1 context structure
|
||||
|
||||
## Execution
|
||||
|
||||
### Step 1.1: Execute Session Start
|
||||
|
||||
```javascript
|
||||
Skill(skill="workflow:session:start", args="--auto \"[structured-task-description]\"")
|
||||
```
|
||||
|
||||
**Task Description Structure**:
|
||||
```
|
||||
GOAL: [Clear, concise objective]
|
||||
SCOPE: [What's included/excluded]
|
||||
CONTEXT: [Relevant background or constraints]
|
||||
```
|
||||
|
||||
**Example**:
|
||||
```
|
||||
GOAL: Build JWT-based authentication system
|
||||
SCOPE: User registration, login, token validation
|
||||
CONTEXT: Existing user database schema, REST API endpoints
|
||||
```
|
||||
|
||||
### Step 1.2: Parse Output
|
||||
|
||||
- Extract: `SESSION_ID: WFS-[id]` (store as `sessionId`)
|
||||
|
||||
**Validation**:
|
||||
- Session ID successfully extracted
|
||||
- Session directory `.workflow/active/[sessionId]/` exists
|
||||
|
||||
**Note**: Session directory contains `workflow-session.json` (metadata). Do NOT look for `manifest.json` here - it only exists in `.workflow/archives/` for archived sessions.
|
||||
|
||||
**TodoWrite**: Mark phase 1 completed, phase 2 in_progress
|
||||
|
||||
### Step 1.3: Initialize Planning Notes
|
||||
|
||||
After Phase 1, initialize planning-notes.md with user intent:
|
||||
|
||||
```javascript
|
||||
// Create planning notes document with N+1 context support
|
||||
const planningNotesPath = `.workflow/active/${sessionId}/planning-notes.md`
|
||||
const userGoal = structuredDescription.goal
|
||||
const userConstraints = structuredDescription.context || "None specified"
|
||||
|
||||
Write(planningNotesPath, `# Planning Notes
|
||||
|
||||
**Session**: ${sessionId}
|
||||
**Created**: ${new Date().toISOString()}
|
||||
|
||||
## User Intent (Phase 1)
|
||||
|
||||
- **GOAL**: ${userGoal}
|
||||
- **KEY_CONSTRAINTS**: ${userConstraints}
|
||||
|
||||
---
|
||||
|
||||
## Context Findings (Phase 2)
|
||||
(To be filled by context-gather)
|
||||
|
||||
## Conflict Decisions (Phase 3)
|
||||
(To be filled if conflicts detected)
|
||||
|
||||
## Consolidated Constraints (Phase 4 Input)
|
||||
1. ${userConstraints}
|
||||
|
||||
---
|
||||
|
||||
## Task Generation (Phase 4)
|
||||
(To be filled by action-planning-agent)
|
||||
|
||||
## N+1 Context
|
||||
### Decisions
|
||||
| Decision | Rationale | Revisit? |
|
||||
|----------|-----------|----------|
|
||||
|
||||
### Deferred
|
||||
- [ ] (For N+1)
|
||||
`)
|
||||
```
|
||||
|
||||
## Output
|
||||
|
||||
- **Variable**: `sessionId` (WFS-xxx)
|
||||
- **File**: `.workflow/active/[sessionId]/planning-notes.md`
|
||||
- **TodoWrite**: Mark Phase 1 completed, Phase 2 in_progress
|
||||
|
||||
## Next Phase
|
||||
|
||||
Return to orchestrator, then auto-continue to [Phase 2: Context Gathering](02-context-gathering.md).
|
||||
105
.claude/skills/workflow-plan/phases/02-context-gathering.md
Normal file
105
.claude/skills/workflow-plan/phases/02-context-gathering.md
Normal file
@@ -0,0 +1,105 @@
|
||||
# Phase 2: Context Gathering
|
||||
|
||||
Gather project context and analyze codebase via context-gather tool.
|
||||
|
||||
## Objective
|
||||
|
||||
- Gather project context using context-search-agent
|
||||
- Identify critical files, architecture patterns, and constraints
|
||||
- Detect conflict risk level for Phase 3 decision
|
||||
- Update planning-notes.md with findings
|
||||
|
||||
## Execution
|
||||
|
||||
### Step 2.1: Execute Context Gathering
|
||||
|
||||
```javascript
|
||||
Skill(skill="workflow:tools:context-gather", args="--session [sessionId] \"[structured-task-description]\"")
|
||||
```
|
||||
|
||||
**Use Same Structured Description**: Pass the same structured format from Phase 1
|
||||
|
||||
**Input**: `sessionId` from Phase 1
|
||||
|
||||
**Parse Output**:
|
||||
- Extract: context-package.json path (store as `contextPath`)
|
||||
- Typical pattern: `.workflow/active/[sessionId]/.process/context-package.json`
|
||||
|
||||
**Validation**:
|
||||
- Context package path extracted
|
||||
- File exists and is valid JSON
|
||||
- `prioritized_context` field exists
|
||||
|
||||
### TodoWrite Update (Phase 2 Skill executed - tasks attached)
|
||||
|
||||
```json
|
||||
[
|
||||
{"content": "Phase 1: Session Discovery", "status": "completed", "activeForm": "Executing session discovery"},
|
||||
{"content": "Phase 2: Context Gathering", "status": "in_progress", "activeForm": "Executing context gathering"},
|
||||
{"content": " → Analyze codebase structure", "status": "in_progress", "activeForm": "Analyzing codebase structure"},
|
||||
{"content": " → Identify integration points", "status": "pending", "activeForm": "Identifying integration points"},
|
||||
{"content": " → Generate context package", "status": "pending", "activeForm": "Generating context package"},
|
||||
{"content": "Phase 4: Task Generation", "status": "pending", "activeForm": "Executing task generation"}
|
||||
]
|
||||
```
|
||||
|
||||
**Note**: Skill execute **attaches** context-gather's 3 tasks. Orchestrator **executes** these tasks sequentially.
|
||||
|
||||
### TodoWrite Update (Phase 2 completed - tasks collapsed)
|
||||
|
||||
```json
|
||||
[
|
||||
{"content": "Phase 1: Session Discovery", "status": "completed", "activeForm": "Executing session discovery"},
|
||||
{"content": "Phase 2: Context Gathering", "status": "completed", "activeForm": "Executing context gathering"},
|
||||
{"content": "Phase 4: Task Generation", "status": "pending", "activeForm": "Executing task generation"}
|
||||
]
|
||||
```
|
||||
|
||||
**Note**: Phase 2 tasks completed and collapsed to summary.
|
||||
|
||||
### Step 2.2: Update Planning Notes
|
||||
|
||||
After context gathering completes, update planning-notes.md with findings:
|
||||
|
||||
```javascript
|
||||
// Read context-package to extract key findings
|
||||
const contextPackage = JSON.parse(Read(contextPath))
|
||||
const conflictRisk = contextPackage.conflict_detection?.risk_level || 'low'
|
||||
const criticalFiles = (contextPackage.exploration_results?.aggregated_insights?.critical_files || [])
|
||||
.slice(0, 5).map(f => f.path)
|
||||
const archPatterns = contextPackage.project_context?.architecture_patterns || []
|
||||
const constraints = contextPackage.exploration_results?.aggregated_insights?.constraints || []
|
||||
|
||||
// Append Phase 2 findings to planning-notes.md
|
||||
Edit(planningNotesPath, {
|
||||
old: '## Context Findings (Phase 2)\n(To be filled by context-gather)',
|
||||
new: `## Context Findings (Phase 2)
|
||||
|
||||
- **CRITICAL_FILES**: ${criticalFiles.join(', ') || 'None identified'}
|
||||
- **ARCHITECTURE**: ${archPatterns.join(', ') || 'Not detected'}
|
||||
- **CONFLICT_RISK**: ${conflictRisk}
|
||||
- **CONSTRAINTS**: ${constraints.length > 0 ? constraints.join('; ') : 'None'}`
|
||||
})
|
||||
|
||||
// Append Phase 2 constraints to consolidated list
|
||||
Edit(planningNotesPath, {
|
||||
old: '## Consolidated Constraints (Phase 4 Input)',
|
||||
new: `## Consolidated Constraints (Phase 4 Input)
|
||||
${constraints.map((c, i) => `${i + 2}. [Context] ${c}`).join('\n')}`
|
||||
})
|
||||
```
|
||||
|
||||
**Auto-Continue**: Return to user showing Phase 2 results, then auto-continue to Phase 3/4 (depending on `conflictRisk`).
|
||||
|
||||
## Output
|
||||
|
||||
- **Variable**: `contextPath` (path to context-package.json)
|
||||
- **Variable**: `conflictRisk` (none/low/medium/high)
|
||||
- **File**: `context-package.json`
|
||||
- **TodoWrite**: Mark Phase 2 completed, determine Phase 3 or Phase 4
|
||||
|
||||
## Next Phase
|
||||
|
||||
Return to orchestrator. Orchestrator checks `conflictRisk`:
|
||||
- If `conflictRisk >= medium` → [Phase 3: Conflict Resolution](03-conflict-resolution.md)
|
||||
- If `conflictRisk < medium` → [Phase 4: Task Generation](04-task-generation.md)
|
||||
134
.claude/skills/workflow-plan/phases/03-conflict-resolution.md
Normal file
134
.claude/skills/workflow-plan/phases/03-conflict-resolution.md
Normal file
@@ -0,0 +1,134 @@
|
||||
# Phase 3: Conflict Resolution
|
||||
|
||||
Detect and resolve conflicts with CLI analysis. This phase is **conditional** - only executes when `conflict_risk >= medium`.
|
||||
|
||||
## Objective
|
||||
|
||||
- Detect conflicts between planned changes and existing codebase
|
||||
- Present conflicts to user with resolution strategies
|
||||
- Apply selected resolution strategies
|
||||
- Update planning-notes.md with conflict decisions
|
||||
|
||||
## Trigger Condition
|
||||
|
||||
Only execute when context-package.json indicates `conflict_risk` is "medium" or "high".
|
||||
If `conflict_risk` is "none" or "low", skip directly to Phase 4.
|
||||
|
||||
## Execution
|
||||
|
||||
### Step 3.1: Execute Conflict Resolution
|
||||
|
||||
```javascript
|
||||
Skill(skill="workflow:tools:conflict-resolution", args="--session [sessionId] --context [contextPath]")
|
||||
```
|
||||
|
||||
**Input**:
|
||||
- sessionId from Phase 1
|
||||
- contextPath from Phase 2
|
||||
- conflict_risk from context-package.json
|
||||
|
||||
**Parse Output**:
|
||||
- Extract: Execution status (success/skipped/failed)
|
||||
- Verify: conflict-resolution.json file path (if executed)
|
||||
|
||||
**Validation**:
|
||||
- File `.workflow/active/[sessionId]/.process/conflict-resolution.json` exists (if executed)
|
||||
|
||||
**Skip Behavior**:
|
||||
- If conflict_risk is "none" or "low", skip directly to Phase 4
|
||||
- Display: "No significant conflicts detected, proceeding to task generation"
|
||||
|
||||
### TodoWrite Update (Phase 3 Skill executed - tasks attached, if conflict_risk >= medium)
|
||||
|
||||
```json
|
||||
[
|
||||
{"content": "Phase 1: Session Discovery", "status": "completed", "activeForm": "Executing session discovery"},
|
||||
{"content": "Phase 2: Context Gathering", "status": "completed", "activeForm": "Executing context gathering"},
|
||||
{"content": "Phase 3: Conflict Resolution", "status": "in_progress", "activeForm": "Resolving conflicts"},
|
||||
{"content": " → Detect conflicts with CLI analysis", "status": "in_progress", "activeForm": "Detecting conflicts"},
|
||||
{"content": " → Present conflicts to user", "status": "pending", "activeForm": "Presenting conflicts"},
|
||||
{"content": " → Apply resolution strategies", "status": "pending", "activeForm": "Applying resolution strategies"},
|
||||
{"content": "Phase 4: Task Generation", "status": "pending", "activeForm": "Executing task generation"}
|
||||
]
|
||||
```
|
||||
|
||||
**Note**: Skill execute **attaches** conflict-resolution's 3 tasks. Orchestrator **executes** these tasks sequentially.
|
||||
|
||||
### TodoWrite Update (Phase 3 completed - tasks collapsed)
|
||||
|
||||
```json
|
||||
[
|
||||
{"content": "Phase 1: Session Discovery", "status": "completed", "activeForm": "Executing session discovery"},
|
||||
{"content": "Phase 2: Context Gathering", "status": "completed", "activeForm": "Executing context gathering"},
|
||||
{"content": "Phase 3: Conflict Resolution", "status": "completed", "activeForm": "Resolving conflicts"},
|
||||
{"content": "Phase 4: Task Generation", "status": "pending", "activeForm": "Executing task generation"}
|
||||
]
|
||||
```
|
||||
|
||||
**Note**: Phase 3 tasks completed and collapsed to summary.
|
||||
|
||||
### Step 3.2: Update Planning Notes
|
||||
|
||||
After conflict resolution completes (if executed), update planning-notes.md:
|
||||
|
||||
```javascript
|
||||
// If Phase 3 was executed, update planning-notes.md
|
||||
if (conflictRisk === 'medium' || conflictRisk === 'high') {
|
||||
const conflictResPath = `.workflow/active/${sessionId}/.process/conflict-resolution.json`
|
||||
|
||||
if (fs.existsSync(conflictResPath)) {
|
||||
const conflictRes = JSON.parse(Read(conflictResPath))
|
||||
const resolved = conflictRes.resolved_conflicts || []
|
||||
const modifiedArtifacts = conflictRes.modified_artifacts || []
|
||||
const planningConstraints = conflictRes.planning_constraints || []
|
||||
|
||||
// Update Phase 3 section
|
||||
Edit(planningNotesPath, {
|
||||
old: '## Conflict Decisions (Phase 3)\n(To be filled if conflicts detected)',
|
||||
new: `## Conflict Decisions (Phase 3)
|
||||
|
||||
- **RESOLVED**: ${resolved.map(r => `${r.type} → ${r.strategy}`).join('; ') || 'None'}
|
||||
- **MODIFIED_ARTIFACTS**: ${modifiedArtifacts.join(', ') || 'None'}
|
||||
- **CONSTRAINTS**: ${planningConstraints.join('; ') || 'None'}`
|
||||
})
|
||||
|
||||
// Append Phase 3 constraints to consolidated list
|
||||
if (planningConstraints.length > 0) {
|
||||
const currentNotes = Read(planningNotesPath)
|
||||
const constraintCount = (currentNotes.match(/^\d+\./gm) || []).length
|
||||
|
||||
Edit(planningNotesPath, {
|
||||
old: '## Consolidated Constraints (Phase 4 Input)',
|
||||
new: `## Consolidated Constraints (Phase 4 Input)
|
||||
${planningConstraints.map((c, i) => `${constraintCount + i + 1}. [Conflict] ${c}`).join('\n')}`
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Auto-Continue**: Return to user showing conflict resolution results and selected strategies, then auto-continue.
|
||||
|
||||
**Auto Mode (--yes)**: When `--yes` flag is active, conflict-resolution sub-command automatically applies recommended resolution strategies without user confirmation. The orchestrator passes the `--yes` flag through to `workflow:tools:conflict-resolution`.
|
||||
|
||||
### Step 3.3: Memory State Check
|
||||
|
||||
Evaluate current context window usage and memory state:
|
||||
|
||||
- If memory usage is high (>120K tokens or approaching context limits):
|
||||
|
||||
```javascript
|
||||
Skill(skill="compact")
|
||||
```
|
||||
|
||||
- Memory compaction is particularly important after analysis phase which may generate extensive documentation
|
||||
- Ensures optimal performance and prevents context overflow
|
||||
|
||||
## Output
|
||||
|
||||
- **File**: `conflict-resolution.json` (if conflicts resolved)
|
||||
- **TodoWrite**: Mark Phase 3 completed, Phase 4 in_progress
|
||||
|
||||
## Next Phase
|
||||
|
||||
Return to orchestrator, then auto-continue to [Phase 4: Task Generation](04-task-generation.md).
|
||||
603
.claude/skills/workflow-plan/phases/06-replan.md
Normal file
603
.claude/skills/workflow-plan/phases/06-replan.md
Normal file
@@ -0,0 +1,603 @@
|
||||
# Phase 6: Interactive Replan
|
||||
|
||||
Interactive workflow replanning with session-level artifact updates and boundary clarification through guided questioning.
|
||||
|
||||
## Objective
|
||||
|
||||
- Intelligently replan workflow sessions or individual tasks
|
||||
- Interactive clarification to define modification boundaries
|
||||
- Impact analysis with automatic detection of affected files and dependencies
|
||||
- Backup management with restore capability
|
||||
- Comprehensive artifact updates (IMPL_PLAN.md, TODO_LIST.md, task JSONs)
|
||||
|
||||
## Entry Point
|
||||
|
||||
Triggered via `/workflow:replan` (Replan Mode).
|
||||
|
||||
## Operation Modes
|
||||
|
||||
### Session Replan Mode
|
||||
|
||||
```bash
|
||||
# Auto-detect active session
|
||||
/workflow:replan "requirements text"
|
||||
|
||||
# Explicit session
|
||||
/workflow:replan --session WFS-oauth "requirements text"
|
||||
|
||||
# File-based input
|
||||
/workflow:replan --session WFS-oauth requirements-update.md
|
||||
|
||||
# Interactive mode
|
||||
/workflow:replan --interactive
|
||||
```
|
||||
|
||||
### Task Replan Mode
|
||||
|
||||
```bash
|
||||
# Direct task update
|
||||
/workflow:replan IMPL-1 "requirements text"
|
||||
|
||||
# Task with explicit session
|
||||
/workflow:replan --session WFS-oauth IMPL-2 "requirements text"
|
||||
|
||||
# Interactive mode
|
||||
/workflow:replan IMPL-1 --interactive
|
||||
```
|
||||
|
||||
## Language Convention
|
||||
|
||||
Interactive question options use Chinese (user-facing UI text) with English identifiers in parentheses. Structural content uses English. This is intentional for Chinese-language workflows.
|
||||
|
||||
## Execution
|
||||
|
||||
### Input Parsing
|
||||
|
||||
**Parse flags**:
|
||||
```javascript
|
||||
const sessionFlag = $ARGUMENTS.match(/--session\s+(\S+)/)?.[1]
|
||||
const interactive = $ARGUMENTS.includes('--interactive')
|
||||
const taskIdMatch = $ARGUMENTS.match(/\b(IMPL-\d+(?:\.\d+)?)\b/)
|
||||
const taskId = taskIdMatch?.[1]
|
||||
```
|
||||
|
||||
### Step 6.1: Mode Detection & Session Discovery
|
||||
|
||||
**Process**:
|
||||
1. **Detect Operation Mode**:
|
||||
- Check if task ID provided (IMPL-N or IMPL-N.M format) → Task mode
|
||||
- Otherwise → Session mode
|
||||
|
||||
2. **Discover/Validate Session**:
|
||||
- Use `--session` flag if provided
|
||||
- Otherwise auto-detect from `.workflow/active/`
|
||||
- Validate session exists
|
||||
|
||||
3. **Load Session Context**:
|
||||
- Read `workflow-session.json`
|
||||
- List existing tasks
|
||||
- Read `IMPL_PLAN.md` and `TODO_LIST.md`
|
||||
|
||||
4. **Parse Execution Intent** (from requirements text):
|
||||
```javascript
|
||||
// Dynamic tool detection from cli-tools.json
|
||||
// Read enabled tools: ["gemini", "qwen", "codex", ...]
|
||||
const enabledTools = loadEnabledToolsFromConfig(); // See ~/.claude/cli-tools.json
|
||||
|
||||
// Build dynamic patterns from enabled tools
|
||||
function buildExecPatterns(tools) {
|
||||
const patterns = {
|
||||
agent: /改为\s*Agent\s*执行|使用\s*Agent\s*执行/i
|
||||
};
|
||||
tools.forEach(tool => {
|
||||
// Pattern: "使用 {tool} 执行" or "改用 {tool}"
|
||||
patterns[`cli_${tool}`] = new RegExp(
|
||||
`使用\\s*(${tool})\\s*执行|改用\\s*(${tool})`, 'i'
|
||||
);
|
||||
});
|
||||
return patterns;
|
||||
}
|
||||
|
||||
const execPatterns = buildExecPatterns(enabledTools);
|
||||
|
||||
let executionIntent = null
|
||||
for (const [key, pattern] of Object.entries(execPatterns)) {
|
||||
if (pattern.test(requirements)) {
|
||||
executionIntent = key.startsWith('cli_')
|
||||
? { method: 'cli', cli_tool: key.replace('cli_', '') }
|
||||
: { method: 'agent', cli_tool: null }
|
||||
break
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Output**: Session validated, context loaded, mode determined, **executionIntent parsed**
|
||||
|
||||
---
|
||||
|
||||
### Auto Mode Support
|
||||
|
||||
When `--yes` or `-y` flag is used, the command skips interactive clarification and uses safe defaults:
|
||||
|
||||
```javascript
|
||||
const autoYes = $ARGUMENTS.includes('--yes') || $ARGUMENTS.includes('-y')
|
||||
```
|
||||
|
||||
**Auto Mode Defaults**:
|
||||
- **Modification Scope**: `tasks_only` (safest - only update task details)
|
||||
- **Affected Modules**: All modules related to the task
|
||||
- **Task Changes**: `update_only` (no structural changes)
|
||||
- **Dependency Changes**: `no` (preserve existing dependencies)
|
||||
- **User Confirmation**: Auto-confirm execution
|
||||
|
||||
**Note**: `--interactive` flag overrides `--yes` flag (forces interactive mode).
|
||||
|
||||
---
|
||||
|
||||
### Step 6.2: Interactive Requirement Clarification
|
||||
|
||||
**Purpose**: Define modification scope through guided questioning
|
||||
|
||||
**Auto Mode Check**:
|
||||
```javascript
|
||||
if (autoYes && !interactive) {
|
||||
// Use defaults and skip to Step 6.3
|
||||
console.log(`[--yes] Using safe defaults for replan:`)
|
||||
console.log(` - Scope: tasks_only`)
|
||||
console.log(` - Changes: update_only`)
|
||||
console.log(` - Dependencies: preserve existing`)
|
||||
|
||||
userSelections = {
|
||||
scope: 'tasks_only',
|
||||
modules: 'all_affected',
|
||||
task_changes: 'update_only',
|
||||
dependency_changes: false
|
||||
}
|
||||
// Proceed to Step 6.3
|
||||
}
|
||||
```
|
||||
|
||||
#### Session Mode Questions
|
||||
|
||||
**Q1: Modification Scope**
|
||||
```javascript
|
||||
Options:
|
||||
- 仅更新任务细节 (tasks_only)
|
||||
- 修改规划方案 (plan_update)
|
||||
- 重构任务结构 (task_restructure)
|
||||
- 全面重规划 (comprehensive)
|
||||
```
|
||||
|
||||
**Q2: Affected Modules** (if scope >= plan_update)
|
||||
```javascript
|
||||
Options: Dynamically generated from existing tasks' focus_paths
|
||||
- 认证模块 (src/auth)
|
||||
- 用户管理 (src/user)
|
||||
- 全部模块
|
||||
```
|
||||
|
||||
**Q3: Task Changes** (if scope >= task_restructure)
|
||||
```javascript
|
||||
Options:
|
||||
- 添加/删除任务 (add_remove)
|
||||
- 合并/拆分任务 (merge_split)
|
||||
- 仅更新内容 (update_only)
|
||||
// Note: Max 4 options for AskUserQuestion
|
||||
```
|
||||
|
||||
**Q4: Dependency Changes**
|
||||
```javascript
|
||||
Options:
|
||||
- 是,需要重新梳理依赖
|
||||
- 否,保持现有依赖
|
||||
```
|
||||
|
||||
#### Task Mode Questions
|
||||
|
||||
**Q1: Update Type**
|
||||
```javascript
|
||||
Options:
|
||||
- 需求和验收标准 (requirements & acceptance)
|
||||
- 实现方案 (implementation_approach)
|
||||
- 文件范围 (focus_paths)
|
||||
- 依赖关系 (depends_on)
|
||||
- 全部更新
|
||||
```
|
||||
|
||||
**Q2: Ripple Effect**
|
||||
```javascript
|
||||
Options:
|
||||
- 是,需要同步更新依赖任务
|
||||
- 否,仅影响当前任务
|
||||
- 不确定,请帮我分析
|
||||
```
|
||||
|
||||
**Output**: User selections stored, modification boundaries defined
|
||||
|
||||
---
|
||||
|
||||
### Step 6.3: Impact Analysis & Planning
|
||||
|
||||
**Step 6.3.1: Analyze Required Changes**
|
||||
|
||||
Determine affected files based on clarification:
|
||||
|
||||
```typescript
|
||||
interface ImpactAnalysis {
|
||||
affected_files: {
|
||||
impl_plan: boolean;
|
||||
todo_list: boolean;
|
||||
session_meta: boolean;
|
||||
tasks: string[];
|
||||
};
|
||||
|
||||
operations: {
|
||||
type: 'create' | 'update' | 'delete' | 'merge' | 'split';
|
||||
target: string;
|
||||
reason: string;
|
||||
}[];
|
||||
|
||||
backup_strategy: {
|
||||
timestamp: string;
|
||||
files: string[];
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
**Step 6.3.2: Generate Modification Plan**
|
||||
|
||||
```markdown
|
||||
## Modification Plan
|
||||
|
||||
### Impact Scope
|
||||
- [ ] IMPL_PLAN.md: Update technical section 3
|
||||
- [ ] TODO_LIST.md: Add 2 new tasks, delete 1 obsolete task
|
||||
- [ ] IMPL-001.json: Update implementation approach
|
||||
- [ ] workflow-session.json: Update task count
|
||||
|
||||
### Change Operations
|
||||
1. **Create**: IMPL-004.json (2FA implementation)
|
||||
2. **Update**: IMPL-001.json (add 2FA preparation)
|
||||
3. **Delete**: IMPL-003.json (replaced by new approach)
|
||||
```
|
||||
|
||||
**Step 6.3.3: User Confirmation**
|
||||
|
||||
```javascript
|
||||
// Parse --yes flag
|
||||
const autoYes = $ARGUMENTS.includes('--yes') || $ARGUMENTS.includes('-y')
|
||||
|
||||
if (autoYes) {
|
||||
// Auto mode: Auto-confirm execution
|
||||
console.log(`[--yes] Auto-confirming replan execution`)
|
||||
userConfirmation = 'confirm'
|
||||
// Proceed to Step 6.4
|
||||
} else {
|
||||
// Interactive mode: Ask user
|
||||
AskUserQuestion({
|
||||
questions: [{
|
||||
question: "Modification plan generated. Confirm action:",
|
||||
header: "Confirm",
|
||||
options: [
|
||||
{ label: "Confirm Execute", description: "Apply all modifications" },
|
||||
{ label: "Adjust Plan", description: "Re-answer questions to adjust scope" },
|
||||
{ label: "Cancel", description: "Abort this replan" }
|
||||
],
|
||||
multiSelect: false
|
||||
}]
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
**Output**: Modification plan confirmed or adjusted
|
||||
|
||||
---
|
||||
|
||||
### Step 6.4: Backup Creation
|
||||
|
||||
**Process**:
|
||||
|
||||
1. **Create Backup Directory**:
|
||||
```bash
|
||||
timestamp=$(date -u +"%Y-%m-%dT%H-%M-%S")
|
||||
backup_dir=".workflow/active/$SESSION_ID/.process/backup/replan-$timestamp"
|
||||
mkdir -p "$backup_dir"
|
||||
```
|
||||
|
||||
2. **Backup All Affected Files**:
|
||||
- IMPL_PLAN.md
|
||||
- TODO_LIST.md
|
||||
- workflow-session.json
|
||||
- Affected task JSONs
|
||||
|
||||
3. **Create Backup Manifest**:
|
||||
```markdown
|
||||
# Replan Backup Manifest
|
||||
|
||||
**Timestamp**: {timestamp}
|
||||
**Reason**: {replan_reason}
|
||||
**Scope**: {modification_scope}
|
||||
|
||||
## Restoration Command
|
||||
cp {backup_dir}/* .workflow/active/{session}/
|
||||
```
|
||||
|
||||
**Output**: All files safely backed up with manifest
|
||||
|
||||
---
|
||||
|
||||
### Step 6.5: Apply Modifications
|
||||
|
||||
**Step 6.5.1: Update IMPL_PLAN.md** (if needed)
|
||||
|
||||
Use Edit tool to modify specific sections:
|
||||
- Update affected technical sections
|
||||
- Update modification date
|
||||
|
||||
**Step 6.5.2: Update TODO_LIST.md** (if needed)
|
||||
|
||||
- Add new tasks with `[ ]` checkbox
|
||||
- Mark deleted tasks as `[x] ~~task~~ (obsolete)`
|
||||
- Update modified task descriptions
|
||||
|
||||
**Step 6.5.3: Update Task JSONs**
|
||||
|
||||
For each affected task:
|
||||
```typescript
|
||||
const updated_task = {
|
||||
...task,
|
||||
context: {
|
||||
...task.context,
|
||||
requirements: [...updated_requirements],
|
||||
acceptance: [...updated_acceptance]
|
||||
},
|
||||
flow_control: {
|
||||
...task.flow_control,
|
||||
implementation_approach: [...updated_steps]
|
||||
},
|
||||
// Update execution config if intent detected
|
||||
...(executionIntent && {
|
||||
meta: {
|
||||
...task.meta,
|
||||
execution_config: {
|
||||
method: executionIntent.method,
|
||||
cli_tool: executionIntent.cli_tool,
|
||||
enable_resume: executionIntent.method !== 'agent'
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
Write({
|
||||
file_path: `.workflow/active/${SESSION_ID}/.task/${task_id}.json`,
|
||||
content: JSON.stringify(updated_task, null, 2)
|
||||
});
|
||||
```
|
||||
|
||||
**Note**: Implementation approach steps are NO LONGER modified. CLI execution is controlled by task-level `meta.execution_config` only.
|
||||
|
||||
**Step 6.5.4: Create New Tasks** (if needed)
|
||||
|
||||
Generate complete task JSON with all required fields:
|
||||
- id, title, status
|
||||
- meta (type, agent)
|
||||
- context (requirements, focus_paths, acceptance)
|
||||
- flow_control (pre_analysis, implementation_approach, target_files)
|
||||
|
||||
**Step 6.5.5: Delete Obsolete Tasks** (if needed)
|
||||
|
||||
Move to backup instead of hard delete:
|
||||
```bash
|
||||
mv ".workflow/active/$SESSION_ID/.task/{task-id}.json" "$backup_dir/"
|
||||
```
|
||||
|
||||
**Step 6.5.6: Update Session Metadata**
|
||||
|
||||
Update workflow-session.json:
|
||||
- progress.current_tasks
|
||||
- progress.last_replan
|
||||
- replan_history array
|
||||
|
||||
**Output**: All modifications applied, artifacts updated
|
||||
|
||||
---
|
||||
|
||||
### Step 6.6: Verification & Summary
|
||||
|
||||
**Step 6.6.1: Verify Consistency**
|
||||
|
||||
1. Validate all task JSONs are valid JSON
|
||||
2. Check task count within limits (max 10)
|
||||
3. Verify dependency graph is acyclic
|
||||
|
||||
**Step 6.6.2: Generate Change Summary**
|
||||
|
||||
```markdown
|
||||
## Replan Complete
|
||||
|
||||
### Session Info
|
||||
- **Session**: {session-id}
|
||||
- **Timestamp**: {timestamp}
|
||||
- **Backup**: {backup-path}
|
||||
|
||||
### Change Summary
|
||||
**Scope**: {scope}
|
||||
**Reason**: {reason}
|
||||
|
||||
### Modified Files
|
||||
- IMPL_PLAN.md: {changes}
|
||||
- TODO_LIST.md: {changes}
|
||||
- Task JSONs: {count} files updated
|
||||
|
||||
### Task Changes
|
||||
- **Added**: {task-ids}
|
||||
- **Deleted**: {task-ids}
|
||||
- **Updated**: {task-ids}
|
||||
|
||||
### Rollback
|
||||
cp {backup-path}/* .workflow/active/{session}/
|
||||
```
|
||||
|
||||
**Output**: Summary displayed, replan complete
|
||||
|
||||
## TodoWrite Progress Tracking
|
||||
|
||||
### Session Mode Progress
|
||||
|
||||
```json
|
||||
[
|
||||
{"content": "Mode detection and session discovery", "status": "completed", "activeForm": "Detecting mode and discovering session"},
|
||||
{"content": "Interactive requirement clarification", "status": "completed", "activeForm": "Clarifying requirements interactively"},
|
||||
{"content": "Impact analysis and plan generation", "status": "completed", "activeForm": "Analyzing impact and generating plan"},
|
||||
{"content": "Backup creation", "status": "completed", "activeForm": "Creating backup"},
|
||||
{"content": "Apply modifications to artifacts", "status": "completed", "activeForm": "Applying modifications"},
|
||||
{"content": "Verify consistency", "status": "completed", "activeForm": "Verifying consistency"}
|
||||
]
|
||||
```
|
||||
|
||||
### Task Mode Progress
|
||||
|
||||
```json
|
||||
[
|
||||
{"content": "Detect session and load task", "status": "completed", "activeForm": "Detecting session and loading task"},
|
||||
{"content": "Interactive update confirmation", "status": "completed", "activeForm": "Confirming update interactively"},
|
||||
{"content": "Apply task modifications", "status": "completed", "activeForm": "Applying task modifications"}
|
||||
]
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Session Errors
|
||||
|
||||
```bash
|
||||
# No active session found
|
||||
ERROR: No active session found
|
||||
Run /workflow:session:start to create a session
|
||||
|
||||
# Session not found
|
||||
ERROR: Session WFS-invalid not found
|
||||
Available sessions: [list]
|
||||
|
||||
# No changes specified
|
||||
WARNING: No modifications specified
|
||||
Use --interactive mode or provide requirements
|
||||
```
|
||||
|
||||
### Task Errors
|
||||
|
||||
```bash
|
||||
# Task not found
|
||||
ERROR: Task IMPL-999 not found in session
|
||||
Available tasks: [list]
|
||||
|
||||
# Task completed
|
||||
WARNING: Task IMPL-001 is completed
|
||||
Consider creating new task for additional work
|
||||
|
||||
# Circular dependency
|
||||
ERROR: Circular dependency detected
|
||||
Resolve dependency conflicts before proceeding
|
||||
```
|
||||
|
||||
### Validation Errors
|
||||
|
||||
```bash
|
||||
# Task limit exceeded
|
||||
ERROR: Replan would create 12 tasks (limit: 10)
|
||||
Consider: combining tasks, splitting sessions, or removing tasks
|
||||
|
||||
# Invalid JSON
|
||||
ERROR: Generated invalid JSON
|
||||
Backup preserved, rolling back changes
|
||||
```
|
||||
|
||||
## File Structure
|
||||
|
||||
```
|
||||
.workflow/active/WFS-session-name/
|
||||
├── workflow-session.json
|
||||
├── IMPL_PLAN.md
|
||||
├── TODO_LIST.md
|
||||
├── .task/
|
||||
│ ├── IMPL-001.json
|
||||
│ ├── IMPL-002.json
|
||||
│ └── IMPL-003.json
|
||||
└── .process/
|
||||
├── context-package.json
|
||||
└── backup/
|
||||
└── replan-{timestamp}/
|
||||
├── MANIFEST.md
|
||||
├── IMPL_PLAN.md
|
||||
├── TODO_LIST.md
|
||||
├── workflow-session.json
|
||||
└── IMPL-*.json
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Session Replan - Add Feature
|
||||
|
||||
```bash
|
||||
/workflow:replan "Add 2FA support"
|
||||
|
||||
# Interactive clarification
|
||||
Q: Modification scope?
|
||||
A: Comprehensive replan
|
||||
|
||||
Q: Affected modules?
|
||||
A: Auth module, API endpoints
|
||||
|
||||
Q: Task changes?
|
||||
A: Add new tasks, update content
|
||||
|
||||
# Execution
|
||||
Backup created
|
||||
IMPL_PLAN.md updated
|
||||
TODO_LIST.md updated
|
||||
IMPL-004.json created
|
||||
IMPL-001.json, IMPL-002.json updated
|
||||
|
||||
Replan complete! Added 1 task, updated 2 tasks
|
||||
```
|
||||
|
||||
### Task Replan - Update Requirements
|
||||
|
||||
```bash
|
||||
/workflow:replan IMPL-002 "Update acceptance criteria to include rate limiting"
|
||||
|
||||
# Interactive clarification
|
||||
Q: Update type?
|
||||
A: Requirements and acceptance criteria
|
||||
|
||||
Q: Ripple effect?
|
||||
A: Yes, sync dependent tasks
|
||||
|
||||
# Execution
|
||||
Backup created
|
||||
IMPL-002.json updated
|
||||
- context.requirements updated
|
||||
- context.acceptance updated
|
||||
IMPL-003.json updated (dependent task synced)
|
||||
|
||||
Task requirements updated with ripple effect applied
|
||||
```
|
||||
|
||||
### Task Replan - Change Execution Method
|
||||
|
||||
```bash
|
||||
/workflow:replan IMPL-001 "Use Codex for execution"
|
||||
|
||||
# Semantic parsing detects executionIntent:
|
||||
# { method: 'cli', cli_tool: 'codex' }
|
||||
|
||||
# Execution (no interactive questions needed)
|
||||
Backup created
|
||||
IMPL-001.json updated
|
||||
- meta.execution_config = { method: 'cli', cli_tool: 'codex', enable_resume: true }
|
||||
|
||||
Task execution method updated: Agent → CLI (codex)
|
||||
```
|
||||
|
||||
## Completion
|
||||
|
||||
Phase 6 is a terminal phase. Replan complete with backup and summary.
|
||||
@@ -1,747 +0,0 @@
|
||||
---
|
||||
name: workflow-tdd-plan
|
||||
description: TDD workflow planning with Red-Green-Refactor task chain generation, test-first development structure, cycle tracking, and post-execution compliance verification. Triggers on "workflow:tdd-plan", "workflow:tdd-verify".
|
||||
allowed-tools: Task, AskUserQuestion, TodoWrite, Read, Write, Edit, Bash, Glob, Grep, Skill
|
||||
---
|
||||
|
||||
# Workflow TDD Plan
|
||||
|
||||
6-phase TDD planning workflow that orchestrates session discovery, context gathering, test coverage analysis, conflict resolution, and TDD task generation to produce implementation plans with Red-Green-Refactor cycles. Includes post-execution TDD compliance verification.
|
||||
|
||||
## Architecture Overview
|
||||
|
||||
```
|
||||
┌──────────────────────────────────────────────────────────────────┐
|
||||
│ Workflow TDD Plan Orchestrator (SKILL.md) │
|
||||
│ → Pure coordinator: Execute phases, parse outputs, pass context │
|
||||
└───────────────┬──────────────────────────────────────────────────┘
|
||||
│
|
||||
┌────────────┼────────────┬────────────┬────────────┐
|
||||
↓ ↓ ↓ ↓ ↓
|
||||
┌────────┐ ┌────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
|
||||
│ Phase 1│ │ Phase 2│ │ Phase 3 │ │ Phase 4 │ │ Phase 5 │
|
||||
│Session │ │Context │ │Test Covg │ │Conflict │ │TDD Task │
|
||||
│Discover│ │Gather │ │Analysis │ │Resolve │ │Generate │
|
||||
│ (ext) │ │ (ext) │ │ (local) │ │(ext,cond)│ │ (local) │
|
||||
└────────┘ └────────┘ └──────────┘ └──────────┘ └──────────┘
|
||||
↓ ↓ ↓ ↓ ↓
|
||||
sessionId contextPath testContext resolved IMPL_PLAN.md
|
||||
conflict_risk artifacts task JSONs
|
||||
|
||||
Phase 6: TDD Structure Validation (inline in SKILL.md)
|
||||
|
||||
Post-execution verification:
|
||||
┌──────────────┐ ┌───────────────────┐
|
||||
│ TDD Verify │────→│ Coverage Analysis │
|
||||
│ (local) │ │ (local) │
|
||||
└──────────────┘ └───────────────────┘
|
||||
phases/03-tdd- phases/04-tdd-
|
||||
verify.md coverage-analysis.md
|
||||
```
|
||||
|
||||
## Key Design Principles
|
||||
|
||||
1. **Pure Orchestrator**: Execute phases in sequence, parse outputs, pass context between them
|
||||
2. **Auto-Continue**: All phases run autonomously without user intervention between phases
|
||||
3. **Task Attachment Model**: Sub-tasks are attached/collapsed dynamically in TodoWrite
|
||||
4. **Progressive Phase Loading**: Phase docs are read on-demand, not all at once
|
||||
5. **Conditional Execution**: Phase 4 only executes when conflict_risk >= medium
|
||||
6. **TDD-First**: Every feature starts with a failing test (Red phase)
|
||||
|
||||
**CLI Tool Selection**: CLI tool usage is determined semantically from user's task description. Include "use Codex/Gemini/Qwen" in your request for CLI execution.
|
||||
|
||||
**Task Attachment Model**:
|
||||
- Skill execute **expands workflow** by attaching sub-tasks to current TodoWrite
|
||||
- When executing a sub-command, its internal tasks are attached to the orchestrator's TodoWrite
|
||||
- Orchestrator **executes these attached tasks** sequentially
|
||||
- After completion, attached tasks are **collapsed** back to high-level phase summary
|
||||
- This is **task expansion**, not external delegation
|
||||
|
||||
**Auto-Continue Mechanism**:
|
||||
- TodoList tracks current phase status and dynamically manages task attachment/collapse
|
||||
- When each phase finishes executing, automatically execute next pending phase
|
||||
- All phases run autonomously without user interaction
|
||||
- **CONTINUOUS EXECUTION** - Do not stop until all phases complete
|
||||
|
||||
## Auto Mode
|
||||
|
||||
When `--yes` or `-y`: Auto-continue all phases (skip confirmations), use recommended conflict resolutions, skip TDD clarifications.
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
Skill(skill="workflow-tdd-plan", args="<task description>")
|
||||
Skill(skill="workflow-tdd-plan", args="[-y|--yes] \"<task description>\"")
|
||||
|
||||
# Flags
|
||||
-y, --yes Skip all confirmations (auto mode)
|
||||
|
||||
# Arguments
|
||||
<task description> Task description text, TDD-structured format, or path to .md file
|
||||
|
||||
# Examples
|
||||
Skill(skill="workflow-tdd-plan", args="\"Build user authentication with tests\"") # Simple TDD task
|
||||
Skill(skill="workflow-tdd-plan", args="\"Add JWT auth with email/password and token refresh\"") # Detailed task
|
||||
Skill(skill="workflow-tdd-plan", args="-y \"Implement payment processing\"") # Auto mode
|
||||
Skill(skill="workflow-tdd-plan", args="\"tdd-requirements.md\"") # From file
|
||||
```
|
||||
|
||||
## TDD Compliance Requirements
|
||||
|
||||
### The Iron Law
|
||||
|
||||
```
|
||||
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
|
||||
```
|
||||
|
||||
**Enforcement Method**:
|
||||
- Phase 5: `implementation_approach` includes test-first steps (Red → Green → Refactor)
|
||||
- Green phase: Includes test-fix-cycle configuration (max 3 iterations)
|
||||
- Auto-revert: Triggered when max iterations reached without passing tests
|
||||
|
||||
**Verification**: Phase 6 validates Red-Green-Refactor structure in all generated tasks
|
||||
|
||||
### TDD Compliance Checkpoint
|
||||
|
||||
| Checkpoint | Validation Phase | Evidence Required |
|
||||
|------------|------------------|-------------------|
|
||||
| Test-first structure | Phase 5 | `implementation_approach` has 3 steps |
|
||||
| Red phase exists | Phase 6 | Step 1: `tdd_phase: "red"` |
|
||||
| Green phase with test-fix | Phase 6 | Step 2: `tdd_phase: "green"` + test-fix-cycle |
|
||||
| Refactor phase exists | Phase 6 | Step 3: `tdd_phase: "refactor"` |
|
||||
|
||||
### Core TDD Principles
|
||||
|
||||
**Red Flags - STOP and Reassess**:
|
||||
- Code written before test
|
||||
- Test passes immediately (no Red phase witnessed)
|
||||
- Cannot explain why test should fail
|
||||
- "Just this once" rationalization
|
||||
- "Tests after achieve same goals" thinking
|
||||
|
||||
**Why Order Matters**:
|
||||
- Tests written after code pass immediately → proves nothing
|
||||
- Test-first forces edge case discovery before implementation
|
||||
- Tests-after verify what was built, not what's required
|
||||
|
||||
## Core Rules
|
||||
|
||||
1. **Start Immediately**: First action is TodoWrite initialization, second action is execute Phase 1
|
||||
2. **No Preliminary Analysis**: Do not read files before Phase 1
|
||||
3. **Parse Every Output**: Extract required data for next phase
|
||||
4. **Auto-Continue via TodoList**: Check TodoList status to execute next pending phase automatically
|
||||
5. **Track Progress**: Update TodoWrite dynamically with task attachment/collapse pattern
|
||||
6. **TDD Context**: All descriptions include "TDD:" prefix
|
||||
7. **Task Attachment Model**: Skill execute **attaches** sub-tasks to current workflow. Orchestrator **executes** these attached tasks itself, then **collapses** them after completion
|
||||
8. **CRITICAL: DO NOT STOP**: Continuous multi-phase workflow. After executing all attached tasks, immediately collapse them and execute next phase
|
||||
|
||||
## Execution Flow
|
||||
|
||||
```
|
||||
Input Parsing:
|
||||
└─ Convert user input to TDD-structured format (TDD:/GOAL/SCOPE/CONTEXT/TEST_FOCUS)
|
||||
|
||||
Phase 1: Session Discovery
|
||||
└─ Ref: workflow-plan/phases/01-session-discovery.md (external)
|
||||
└─ Output: sessionId (WFS-xxx)
|
||||
|
||||
Phase 2: Context Gathering
|
||||
└─ Ref: workflow-plan/phases/02-context-gathering.md (external)
|
||||
├─ Tasks attached: Analyze structure → Identify integration → Generate package
|
||||
└─ Output: contextPath + conflict_risk
|
||||
|
||||
Phase 3: Test Coverage Analysis ← ATTACHED (3 tasks)
|
||||
└─ Ref: phases/01-test-context-gather.md
|
||||
├─ Phase 3.1: Detect test framework
|
||||
├─ Phase 3.2: Analyze existing test coverage
|
||||
└─ Phase 3.3: Identify coverage gaps
|
||||
└─ Output: test-context-package.json ← COLLAPSED
|
||||
|
||||
Phase 4: Conflict Resolution (conditional)
|
||||
└─ Decision (conflict_risk check):
|
||||
├─ conflict_risk ≥ medium → Ref: workflow-plan/phases/03-conflict-resolution.md (external)
|
||||
│ ├─ Tasks attached: Detect conflicts → Present to user → Apply strategies
|
||||
│ └─ Output: Modified brainstorm artifacts ← COLLAPSED
|
||||
└─ conflict_risk < medium → Skip to Phase 5
|
||||
|
||||
Phase 5: TDD Task Generation ← ATTACHED (3 tasks)
|
||||
└─ Ref: phases/02-task-generate-tdd.md
|
||||
├─ Phase 5.1: Discovery - analyze TDD requirements
|
||||
├─ Phase 5.2: Planning - design Red-Green-Refactor cycles
|
||||
└─ Phase 5.3: Output - generate IMPL tasks with internal TDD phases
|
||||
└─ Output: IMPL-*.json, IMPL_PLAN.md ← COLLAPSED
|
||||
|
||||
Phase 6: TDD Structure Validation (inline)
|
||||
└─ Internal validation + summary returned
|
||||
└─ Recommend: plan-verify (external)
|
||||
|
||||
Return:
|
||||
└─ Summary with recommended next steps
|
||||
```
|
||||
|
||||
### Phase Reference Documents
|
||||
|
||||
**Local phases** (read on-demand when phase executes):
|
||||
|
||||
| Phase | Document | Purpose |
|
||||
|-------|----------|---------|
|
||||
| Phase 3 | [phases/01-test-context-gather.md](phases/01-test-context-gather.md) | Test coverage context gathering via test-context-search-agent |
|
||||
| Phase 5 | [phases/02-task-generate-tdd.md](phases/02-task-generate-tdd.md) | TDD task JSON generation via action-planning-agent |
|
||||
|
||||
**External phases** (from workflow-plan skill):
|
||||
|
||||
| Phase | Document | Purpose |
|
||||
|-------|----------|---------|
|
||||
| Phase 1 | workflow-plan/phases/01-session-discovery.md | Session creation/discovery |
|
||||
| Phase 2 | workflow-plan/phases/02-context-gathering.md | Project context collection |
|
||||
| Phase 4 | workflow-plan/phases/03-conflict-resolution.md | Conflict detection and resolution (conditional) |
|
||||
|
||||
**Post-execution verification**:
|
||||
|
||||
| Phase | Document | Purpose |
|
||||
|-------|----------|---------|
|
||||
| TDD Verify | [phases/03-tdd-verify.md](phases/03-tdd-verify.md) | TDD compliance verification with quality gate |
|
||||
| Coverage Analysis | [phases/04-tdd-coverage-analysis.md](phases/04-tdd-coverage-analysis.md) | Test coverage and cycle analysis (called by TDD Verify) |
|
||||
|
||||
## 6-Phase Execution
|
||||
|
||||
### Phase 1: Session Discovery
|
||||
|
||||
**Step 1.1: Execute** - Session discovery and initialization
|
||||
|
||||
Read and execute: `workflow-plan/phases/01-session-discovery.md` with `--type tdd --auto "TDD: [structured-description]"`
|
||||
|
||||
**TDD Structured Format**:
|
||||
```
|
||||
TDD: [Feature Name]
|
||||
GOAL: [Objective]
|
||||
SCOPE: [Included/excluded]
|
||||
CONTEXT: [Background]
|
||||
TEST_FOCUS: [Test scenarios]
|
||||
```
|
||||
|
||||
**Parse**: Extract sessionId
|
||||
|
||||
**TodoWrite**: Mark phase 1 completed, phase 2 in_progress
|
||||
|
||||
**After Phase 1**: Return to user showing Phase 1 results, then auto-continue to Phase 2
|
||||
|
||||
---
|
||||
|
||||
### Phase 2: Context Gathering
|
||||
|
||||
**Step 2.1: Execute** - Context gathering and analysis
|
||||
|
||||
Read and execute: `workflow-plan/phases/02-context-gathering.md` with `--session [sessionId] "TDD: [structured-description]"`
|
||||
|
||||
**Use Same Structured Description**: Pass the same structured format from Phase 1
|
||||
|
||||
**Input**: `sessionId` from Phase 1
|
||||
|
||||
**Parse Output**:
|
||||
- Extract: context-package.json path (store as `contextPath`)
|
||||
- Typical pattern: `.workflow/active/[sessionId]/.process/context-package.json`
|
||||
|
||||
**Validation**:
|
||||
- Context package path extracted
|
||||
- File exists and is valid JSON
|
||||
|
||||
**TodoWrite**: Mark phase 2 completed, phase 3 in_progress
|
||||
|
||||
**After Phase 2**: Return to user showing Phase 2 results, then auto-continue to Phase 3
|
||||
|
||||
---
|
||||
|
||||
### Phase 3: Test Coverage Analysis
|
||||
|
||||
**Step 3.1: Execute** - Test coverage analysis and framework detection
|
||||
|
||||
Read and execute: `phases/01-test-context-gather.md` with `--session [sessionId]`
|
||||
|
||||
**Purpose**: Analyze existing codebase for:
|
||||
- Existing test patterns and conventions
|
||||
- Current test coverage
|
||||
- Related components and integration points
|
||||
- Test framework detection
|
||||
|
||||
**Parse**: Extract testContextPath (`.workflow/active/[sessionId]/.process/test-context-package.json`)
|
||||
|
||||
**TodoWrite Update (Phase 3 - tasks attached)**:
|
||||
```json
|
||||
[
|
||||
{"content": "Phase 1: Session Discovery", "status": "completed", "activeForm": "Executing session discovery"},
|
||||
{"content": "Phase 2: Context Gathering", "status": "completed", "activeForm": "Executing context gathering"},
|
||||
{"content": "Phase 3: Test Coverage Analysis", "status": "in_progress", "activeForm": "Executing test coverage analysis"},
|
||||
{"content": " → Detect test framework and conventions", "status": "in_progress", "activeForm": "Detecting test framework"},
|
||||
{"content": " → Analyze existing test coverage", "status": "pending", "activeForm": "Analyzing test coverage"},
|
||||
{"content": " → Identify coverage gaps", "status": "pending", "activeForm": "Identifying coverage gaps"},
|
||||
{"content": "Phase 5: TDD Task Generation", "status": "pending", "activeForm": "Executing TDD task generation"},
|
||||
{"content": "Phase 6: TDD Structure Validation", "status": "pending", "activeForm": "Validating TDD structure"}
|
||||
]
|
||||
```
|
||||
|
||||
**Note**: Skill execute **attaches** test-context-gather's 3 tasks. Orchestrator **executes** these tasks.
|
||||
|
||||
**Next Action**: Tasks attached → **Execute Phase 3.1-3.3** sequentially
|
||||
|
||||
**TodoWrite Update (Phase 3 completed - tasks collapsed)**:
|
||||
```json
|
||||
[
|
||||
{"content": "Phase 1: Session Discovery", "status": "completed", "activeForm": "Executing session discovery"},
|
||||
{"content": "Phase 2: Context Gathering", "status": "completed", "activeForm": "Executing context gathering"},
|
||||
{"content": "Phase 3: Test Coverage Analysis", "status": "completed", "activeForm": "Executing test coverage analysis"},
|
||||
{"content": "Phase 5: TDD Task Generation", "status": "pending", "activeForm": "Executing TDD task generation"},
|
||||
{"content": "Phase 6: TDD Structure Validation", "status": "pending", "activeForm": "Validating TDD structure"}
|
||||
]
|
||||
```
|
||||
|
||||
**After Phase 3**: Return to user showing test coverage results, then auto-continue to Phase 4/5
|
||||
|
||||
---
|
||||
|
||||
### Phase 4: Conflict Resolution (Optional)
|
||||
|
||||
**Trigger**: Only execute when context-package.json indicates conflict_risk is "medium" or "high"
|
||||
|
||||
**Step 4.1: Execute** - Conflict detection and resolution
|
||||
|
||||
Read and execute: `workflow-plan/phases/03-conflict-resolution.md` with `--session [sessionId] --context [contextPath]`
|
||||
|
||||
**Input**:
|
||||
- sessionId from Phase 1
|
||||
- contextPath from Phase 2
|
||||
- conflict_risk from context-package.json
|
||||
|
||||
**Parse Output**:
|
||||
- Extract: Execution status (success/skipped/failed)
|
||||
- Verify: conflict-resolution.json file path (if executed)
|
||||
|
||||
**Skip Behavior**:
|
||||
- If conflict_risk is "none" or "low", skip directly to Phase 5
|
||||
- Display: "No significant conflicts detected, proceeding to TDD task generation"
|
||||
|
||||
**TodoWrite Update (Phase 4 - tasks attached, if conflict_risk >= medium)**:
|
||||
```json
|
||||
[
|
||||
{"content": "Phase 1: Session Discovery", "status": "completed", "activeForm": "Executing session discovery"},
|
||||
{"content": "Phase 2: Context Gathering", "status": "completed", "activeForm": "Executing context gathering"},
|
||||
{"content": "Phase 3: Test Coverage Analysis", "status": "completed", "activeForm": "Executing test coverage analysis"},
|
||||
{"content": "Phase 4: Conflict Resolution", "status": "in_progress", "activeForm": "Executing conflict resolution"},
|
||||
{"content": " → Detect conflicts with CLI analysis", "status": "in_progress", "activeForm": "Detecting conflicts"},
|
||||
{"content": " → Log and analyze detected conflicts", "status": "pending", "activeForm": "Analyzing conflicts"},
|
||||
{"content": " → Apply resolution strategies", "status": "pending", "activeForm": "Applying resolution strategies"},
|
||||
{"content": "Phase 5: TDD Task Generation", "status": "pending", "activeForm": "Executing TDD task generation"},
|
||||
{"content": "Phase 6: TDD Structure Validation", "status": "pending", "activeForm": "Validating TDD structure"}
|
||||
]
|
||||
```
|
||||
|
||||
**TodoWrite Update (Phase 4 completed - tasks collapsed)**:
|
||||
```json
|
||||
[
|
||||
{"content": "Phase 1: Session Discovery", "status": "completed", "activeForm": "Executing session discovery"},
|
||||
{"content": "Phase 2: Context Gathering", "status": "completed", "activeForm": "Executing context gathering"},
|
||||
{"content": "Phase 3: Test Coverage Analysis", "status": "completed", "activeForm": "Executing test coverage analysis"},
|
||||
{"content": "Phase 4: Conflict Resolution", "status": "completed", "activeForm": "Executing conflict resolution"},
|
||||
{"content": "Phase 5: TDD Task Generation", "status": "pending", "activeForm": "Executing TDD task generation"},
|
||||
{"content": "Phase 6: TDD Structure Validation", "status": "pending", "activeForm": "Validating TDD structure"}
|
||||
]
|
||||
```
|
||||
|
||||
**After Phase 4**: Return to user showing conflict resolution results, then auto-continue to Phase 5
|
||||
|
||||
**Memory State Check**:
|
||||
- Evaluate current context window usage and memory state
|
||||
- If memory usage is high (>110K tokens or approaching context limits):
|
||||
|
||||
**Step 4.5: Execute** - Memory compaction (external skill: compact)
|
||||
|
||||
- This optimizes memory before proceeding to Phase 5
|
||||
- Memory compaction is particularly important after analysis phase which may generate extensive documentation
|
||||
|
||||
---
|
||||
|
||||
### Phase 5: TDD Task Generation
|
||||
|
||||
**Step 5.1: Execute** - TDD task generation via action-planning-agent with Phase 0 user configuration
|
||||
|
||||
Read and execute: `phases/02-task-generate-tdd.md` with `--session [sessionId]`
|
||||
|
||||
**Note**: Phase 0 now includes:
|
||||
- Supplementary materials collection (file paths or inline content)
|
||||
- Execution method preference (Agent/Hybrid/CLI)
|
||||
- CLI tool preference (Codex/Gemini/Qwen/Auto)
|
||||
- These preferences are passed to agent for task generation
|
||||
|
||||
**Parse**: Extract feature count, task count, CLI execution IDs assigned
|
||||
|
||||
**Validate**:
|
||||
- IMPL_PLAN.md exists (unified plan with TDD Implementation Tasks section)
|
||||
- IMPL-*.json files exist (one per feature, or container + subtasks for complex features)
|
||||
- TODO_LIST.md exists with internal TDD phase indicators
|
||||
- Each IMPL task includes:
|
||||
- `meta.tdd_workflow: true`
|
||||
- `meta.cli_execution_id: {session_id}-{task_id}`
|
||||
- `meta.cli_execution: { "strategy": "new|resume|fork|merge_fork", ... }`
|
||||
- `flow_control.implementation_approach` with exactly 3 steps (red/green/refactor)
|
||||
- Green phase includes test-fix-cycle configuration
|
||||
- `context.focus_paths`: absolute or clear relative paths
|
||||
- `flow_control.pre_analysis`: includes exploration integration_points analysis
|
||||
- IMPL_PLAN.md contains workflow_type: "tdd" in frontmatter
|
||||
- Task count <=18 (compliance with hard limit)
|
||||
|
||||
**Red Flag Detection** (Non-Blocking Warnings):
|
||||
- Task count >18: `Warning: Task count exceeds hard limit - request re-scope`
|
||||
- Missing cli_execution_id: `Warning: Task lacks CLI execution ID for resume support`
|
||||
- Missing test-fix-cycle: `Warning: Green phase lacks auto-revert configuration`
|
||||
- Generic task names: `Warning: Vague task names suggest unclear TDD cycles`
|
||||
- Missing focus_paths: `Warning: Task lacks clear file scope for implementation`
|
||||
|
||||
**Action**: Log warnings to `.workflow/active/[sessionId]/.process/tdd-warnings.log` (non-blocking)
|
||||
|
||||
**TodoWrite Update (Phase 5 - tasks attached)**:
|
||||
```json
|
||||
[
|
||||
{"content": "Phase 1: Session Discovery", "status": "completed", "activeForm": "Executing session discovery"},
|
||||
{"content": "Phase 2: Context Gathering", "status": "completed", "activeForm": "Executing context gathering"},
|
||||
{"content": "Phase 3: Test Coverage Analysis", "status": "completed", "activeForm": "Executing test coverage analysis"},
|
||||
{"content": "Phase 5: TDD Task Generation", "status": "in_progress", "activeForm": "Executing TDD task generation"},
|
||||
{"content": " → Discovery - analyze TDD requirements", "status": "in_progress", "activeForm": "Analyzing TDD requirements"},
|
||||
{"content": " → Planning - design Red-Green-Refactor cycles", "status": "pending", "activeForm": "Designing TDD cycles"},
|
||||
{"content": " → Output - generate IMPL tasks with internal TDD phases", "status": "pending", "activeForm": "Generating TDD tasks"},
|
||||
{"content": "Phase 6: TDD Structure Validation", "status": "pending", "activeForm": "Validating TDD structure"}
|
||||
]
|
||||
```
|
||||
|
||||
**TodoWrite Update (Phase 5 completed - tasks collapsed)**:
|
||||
```json
|
||||
[
|
||||
{"content": "Phase 1: Session Discovery", "status": "completed", "activeForm": "Executing session discovery"},
|
||||
{"content": "Phase 2: Context Gathering", "status": "completed", "activeForm": "Executing context gathering"},
|
||||
{"content": "Phase 3: Test Coverage Analysis", "status": "completed", "activeForm": "Executing test coverage analysis"},
|
||||
{"content": "Phase 5: TDD Task Generation", "status": "completed", "activeForm": "Executing TDD task generation"},
|
||||
{"content": "Phase 6: TDD Structure Validation", "status": "in_progress", "activeForm": "Validating TDD structure"}
|
||||
]
|
||||
```
|
||||
|
||||
### Phase 6: TDD Structure Validation & Action Plan Verification (RECOMMENDED)
|
||||
|
||||
**Internal validation first, then recommend external verification**
|
||||
|
||||
**Internal Validation**:
|
||||
1. Each task contains complete TDD workflow (Red-Green-Refactor internally)
|
||||
2. Task structure validation:
|
||||
- `meta.tdd_workflow: true` in all IMPL tasks
|
||||
- `meta.cli_execution_id` present (format: {session_id}-{task_id})
|
||||
- `meta.cli_execution` strategy assigned (new/resume/fork/merge_fork)
|
||||
- `flow_control.implementation_approach` has exactly 3 steps
|
||||
- Each step has correct `tdd_phase`: "red", "green", "refactor"
|
||||
- `context.focus_paths` are absolute or clear relative paths
|
||||
- `flow_control.pre_analysis` includes exploration integration analysis
|
||||
3. Dependency validation:
|
||||
- Sequential features: IMPL-N depends_on ["IMPL-(N-1)"] if needed
|
||||
- Complex features: IMPL-N.M depends_on ["IMPL-N.(M-1)"] for subtasks
|
||||
- CLI execution strategies correctly assigned based on dependency graph
|
||||
4. Agent assignment: All IMPL tasks use @code-developer
|
||||
5. Test-fix cycle: Green phase step includes test-fix-cycle logic with max_iterations
|
||||
6. Task count: Total tasks <=18 (simple + subtasks hard limit)
|
||||
7. User configuration:
|
||||
- Execution method choice reflected in task structure
|
||||
- CLI tool preference documented in implementation guidance (if CLI selected)
|
||||
|
||||
**Red Flag Checklist** (from TDD best practices):
|
||||
- [ ] No tasks skip Red phase (`tdd_phase: "red"` exists in step 1)
|
||||
- [ ] Test files referenced in Red phase (explicit paths, not placeholders)
|
||||
- [ ] Green phase has test-fix-cycle with `max_iterations` configured
|
||||
- [ ] Refactor phase has clear completion criteria
|
||||
|
||||
**Non-Compliance Warning Format**:
|
||||
```
|
||||
Warning TDD Red Flag: [issue description]
|
||||
Task: [IMPL-N]
|
||||
Recommendation: [action to fix]
|
||||
```
|
||||
|
||||
**Evidence Gathering** (Before Completion Claims):
|
||||
|
||||
```bash
|
||||
# Verify session artifacts exist
|
||||
ls -la .workflow/active/[sessionId]/{IMPL_PLAN.md,TODO_LIST.md}
|
||||
ls -la .workflow/active/[sessionId]/.task/IMPL-*.json
|
||||
|
||||
# Count generated artifacts
|
||||
echo "IMPL tasks: $(ls .workflow/active/[sessionId]/.task/IMPL-*.json 2>/dev/null | wc -l)"
|
||||
|
||||
# Sample task structure verification (first task)
|
||||
jq '{id, tdd: .meta.tdd_workflow, cli_id: .meta.cli_execution_id, phases: [.flow_control.implementation_approach[].tdd_phase]}' \
|
||||
"$(ls .workflow/active/[sessionId]/.task/IMPL-*.json | head -1)"
|
||||
```
|
||||
|
||||
**Evidence Required Before Summary**:
|
||||
| Evidence Type | Verification Method | Pass Criteria |
|
||||
|---------------|---------------------|---------------|
|
||||
| File existence | `ls -la` artifacts | All files present |
|
||||
| Task count | Count IMPL-*.json | Count matches claims (<=18) |
|
||||
| TDD structure | jq sample extraction | Shows red/green/refactor + cli_execution_id |
|
||||
| CLI execution IDs | jq extraction | All tasks have cli_execution_id assigned |
|
||||
| Warning log | Check tdd-warnings.log | Logged (may be empty) |
|
||||
|
||||
**Return Summary**:
|
||||
```
|
||||
TDD Planning complete for session: [sessionId]
|
||||
|
||||
Features analyzed: [N]
|
||||
Total tasks: [M] (1 task per simple feature + subtasks for complex features)
|
||||
|
||||
Task breakdown:
|
||||
- Simple features: [K] tasks (IMPL-1 to IMPL-K)
|
||||
- Complex features: [L] features with [P] subtasks
|
||||
- Total task count: [M] (within 18-task hard limit)
|
||||
|
||||
Structure:
|
||||
- IMPL-1: {Feature 1 Name} (Internal: Red → Green → Refactor)
|
||||
- IMPL-2: {Feature 2 Name} (Internal: Red → Green → Refactor)
|
||||
- IMPL-3: {Complex Feature} (Container)
|
||||
- IMPL-3.1: {Sub-feature A} (Internal: Red → Green → Refactor)
|
||||
- IMPL-3.2: {Sub-feature B} (Internal: Red → Green → Refactor)
|
||||
[...]
|
||||
|
||||
Plans generated:
|
||||
- Unified Implementation Plan: .workflow/active/[sessionId]/IMPL_PLAN.md
|
||||
(includes TDD Implementation Tasks section with workflow_type: "tdd")
|
||||
- Task List: .workflow/active/[sessionId]/TODO_LIST.md
|
||||
(with internal TDD phase indicators and CLI execution strategies)
|
||||
- Task JSONs: .workflow/active/[sessionId]/.task/IMPL-*.json
|
||||
(with cli_execution_id and execution strategies for resume support)
|
||||
|
||||
TDD Configuration:
|
||||
- Each task contains complete Red-Green-Refactor cycle
|
||||
- Green phase includes test-fix cycle (max 3 iterations)
|
||||
- Auto-revert on max iterations reached
|
||||
- CLI execution strategies: new/resume/fork/merge_fork based on dependency graph
|
||||
|
||||
User Configuration Applied:
|
||||
- Execution Method: [agent|hybrid|cli]
|
||||
- CLI Tool Preference: [codex|gemini|qwen|auto]
|
||||
- Supplementary Materials: [included|none]
|
||||
- Task generation follows cli-tools-usage.md guidelines
|
||||
|
||||
ACTION REQUIRED: Before execution, ensure you understand WHY each Red phase test is expected to fail.
|
||||
This is crucial for valid TDD - if you don't know why the test fails, you can't verify it tests the right thing.
|
||||
|
||||
Recommended Next Steps:
|
||||
1. plan-verify (external) --session [sessionId] # Verify TDD plan quality and dependencies
|
||||
2. workflow:execute (external) --session [sessionId] # Start TDD execution with CLI strategies
|
||||
3. phases/03-tdd-verify.md [sessionId] # Post-execution TDD compliance check
|
||||
|
||||
Quality Gate: Consider running plan-verify to validate TDD task structure, dependencies, and CLI execution strategies
|
||||
```
|
||||
|
||||
## Input Processing
|
||||
|
||||
Convert user input to TDD-structured format:
|
||||
|
||||
**Simple text** → Add TDD context
|
||||
**Detailed text** → Extract components with TEST_FOCUS
|
||||
**File/Issue** → Read and structure with TDD
|
||||
|
||||
## Data Flow
|
||||
|
||||
```
|
||||
User Input (task description)
|
||||
↓
|
||||
[Convert to TDD Structured Format]
|
||||
↓ TDD Structured Description:
|
||||
↓ TDD: [Feature Name]
|
||||
↓ GOAL: [objective]
|
||||
↓ SCOPE: [boundaries]
|
||||
↓ CONTEXT: [background]
|
||||
↓ TEST_FOCUS: [test scenarios]
|
||||
↓
|
||||
Phase 1: session:start --type tdd --auto "TDD: structured-description"
|
||||
↓ Output: sessionId
|
||||
↓
|
||||
Phase 2: context-gather --session sessionId "TDD: structured-description"
|
||||
↓ Output: contextPath + conflict_risk
|
||||
↓
|
||||
Phase 3: test-context-gather --session sessionId
|
||||
↓ Output: testContextPath (test-context-package.json)
|
||||
↓
|
||||
Phase 4: conflict-resolution [AUTO-TRIGGERED if conflict_risk >= medium]
|
||||
↓ Output: Modified brainstorm artifacts
|
||||
↓ Skip if conflict_risk is none/low → proceed directly to Phase 5
|
||||
↓
|
||||
Phase 5: task-generate-tdd --session sessionId
|
||||
↓ Output: IMPL_PLAN.md, task JSONs, TODO_LIST.md
|
||||
↓
|
||||
Phase 6: Internal validation + summary
|
||||
↓
|
||||
Return summary to user
|
||||
```
|
||||
|
||||
## TodoWrite Pattern
|
||||
|
||||
**Core Concept**: Dynamic task attachment and collapse for TDD workflow with test coverage analysis and Red-Green-Refactor cycle generation.
|
||||
|
||||
### Key Principles
|
||||
|
||||
1. **Task Attachment** (when Skill executed):
|
||||
- Sub-command's internal tasks are **attached** to orchestrator's TodoWrite
|
||||
- First attached task marked as `in_progress`, others as `pending`
|
||||
- Orchestrator **executes** these attached tasks sequentially
|
||||
|
||||
2. **Task Collapse** (after sub-tasks complete):
|
||||
- Remove detailed sub-tasks from TodoWrite
|
||||
- **Collapse** to high-level phase summary
|
||||
- Maintains clean orchestrator-level view
|
||||
|
||||
3. **Continuous Execution**:
|
||||
- After collapse, automatically proceed to next pending phase
|
||||
- No user intervention required between phases
|
||||
- TodoWrite dynamically reflects current execution state
|
||||
|
||||
**Lifecycle Summary**: Initial pending tasks → Phase executed (tasks ATTACHED) → Sub-tasks executed sequentially → Phase completed (tasks COLLAPSED to summary) → Next phase begins (conditional Phase 4 if conflict_risk >= medium) → Repeat until all phases complete.
|
||||
|
||||
### TDD-Specific Features
|
||||
|
||||
- **Phase 3**: Test coverage analysis detects existing patterns and gaps
|
||||
- **Phase 5**: Generated IMPL tasks contain internal Red-Green-Refactor cycles
|
||||
- **Conditional Phase 4**: Conflict resolution only if conflict_risk >= medium
|
||||
|
||||
**Note**: See individual Phase descriptions (Phase 3, 4, 5) for detailed TodoWrite Update examples with full JSON structures.
|
||||
|
||||
## Execution Flow Diagram
|
||||
|
||||
```
|
||||
TDD Workflow Orchestrator
|
||||
│
|
||||
├─ Phase 1: Session Discovery
|
||||
│ └─ workflow-plan/phases/01-session-discovery.md --auto
|
||||
│ └─ Returns: sessionId
|
||||
│
|
||||
├─ Phase 2: Context Gathering
|
||||
│ └─ workflow-plan/phases/02-context-gathering.md
|
||||
│ └─ Returns: context-package.json path
|
||||
│
|
||||
├─ Phase 3: Test Coverage Analysis ← ATTACHED (3 tasks)
|
||||
│ └─ phases/01-test-context-gather.md
|
||||
│ ├─ Phase 3.1: Detect test framework
|
||||
│ ├─ Phase 3.2: Analyze existing test coverage
|
||||
│ └─ Phase 3.3: Identify coverage gaps
|
||||
│ └─ Returns: test-context-package.json ← COLLAPSED
|
||||
│
|
||||
├─ Phase 4: Conflict Resolution (conditional)
|
||||
│ IF conflict_risk >= medium:
|
||||
│ └─ workflow-plan/phases/03-conflict-resolution.md ← ATTACHED (3 tasks)
|
||||
│ ├─ Phase 4.1: Detect conflicts with CLI
|
||||
│ ├─ Phase 4.2: Log and analyze detected conflicts
|
||||
│ └─ Phase 4.3: Apply resolution strategies
|
||||
│ └─ Returns: conflict-resolution.json ← COLLAPSED
|
||||
│ ELSE:
|
||||
│ └─ Skip to Phase 5
|
||||
│
|
||||
├─ Phase 5: TDD Task Generation ← ATTACHED (3 tasks)
|
||||
│ └─ phases/02-task-generate-tdd.md
|
||||
│ ├─ Phase 5.1: Discovery - analyze TDD requirements
|
||||
│ ├─ Phase 5.2: Planning - design Red-Green-Refactor cycles
|
||||
│ └─ Phase 5.3: Output - generate IMPL tasks with internal TDD phases
|
||||
│ └─ Returns: IMPL-*.json, IMPL_PLAN.md ← COLLAPSED
|
||||
│ (Each IMPL task contains internal Red-Green-Refactor cycle)
|
||||
│
|
||||
└─ Phase 6: TDD Structure Validation
|
||||
└─ Internal validation + summary returned
|
||||
└─ Recommend: plan-verify (external)
|
||||
|
||||
Key Points:
|
||||
• ← ATTACHED: Sub-tasks attached to orchestrator TodoWrite
|
||||
• ← COLLAPSED: Sub-tasks executed and collapsed to phase summary
|
||||
• TDD-specific: Each generated IMPL task contains complete Red-Green-Refactor cycle
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
- **Parsing failure**: Retry once, then report
|
||||
- **Validation failure**: Report missing/invalid data
|
||||
- **Command failure**: Keep phase in_progress, report error
|
||||
- **TDD validation failure**: Report incomplete chains or wrong dependencies
|
||||
|
||||
### TDD Warning Patterns
|
||||
|
||||
| Pattern | Warning Message | Recommended Action |
|
||||
|---------|----------------|-------------------|
|
||||
| Task count >10 | High task count detected | Consider splitting into multiple sessions |
|
||||
| Missing test-fix-cycle | Green phase lacks auto-revert | Add `max_iterations: 3` to task config |
|
||||
| Red phase missing test path | Test file path not specified | Add explicit test file paths |
|
||||
| Generic task names | Vague names like "Add feature" | Use specific behavior descriptions |
|
||||
| No refactor criteria | Refactor phase lacks completion criteria | Define clear refactor scope |
|
||||
|
||||
### Non-Blocking Warning Policy
|
||||
|
||||
**All warnings are advisory** - they do not halt execution:
|
||||
1. Warnings logged to `.process/tdd-warnings.log`
|
||||
2. Summary displayed in Phase 6 output
|
||||
3. User decides whether to address before execution
|
||||
|
||||
### Error Handling Quick Reference
|
||||
|
||||
| Error Type | Detection | Recovery Action |
|
||||
|------------|-----------|-----------------|
|
||||
| Parsing failure | Empty/malformed output | Retry once, then report |
|
||||
| Missing context-package | File read error | Re-run context-gather (workflow-plan/phases/02-context-gathering.md) |
|
||||
| Invalid task JSON | jq parse error | Report malformed file path |
|
||||
| Task count exceeds 18 | Count validation >=19 | Request re-scope, split into multiple sessions |
|
||||
| Missing cli_execution_id | All tasks lack ID | Regenerate tasks with phase 0 user config |
|
||||
| Test-context missing | File not found | Re-run phases/01-test-context-gather.md |
|
||||
| Phase timeout | No response | Retry phase, check CLI connectivity |
|
||||
| CLI tool not available | Tool not in cli-tools.json | Fall back to alternative preferred tool |
|
||||
|
||||
## Post-Execution: TDD Verification
|
||||
|
||||
After TDD tasks have been executed (via workflow:execute), run TDD compliance verification:
|
||||
|
||||
Read and execute: `phases/03-tdd-verify.md` with `--session [sessionId]`
|
||||
|
||||
This generates a comprehensive TDD_COMPLIANCE_REPORT.md with quality gate recommendation.
|
||||
|
||||
## Related Skills
|
||||
|
||||
**Prerequisite**:
|
||||
- None - TDD planning is self-contained (can optionally run brainstorm before)
|
||||
|
||||
**Called by This Skill** (6 phases):
|
||||
- workflow-plan/phases/01-session-discovery.md - Phase 1: Create or discover TDD workflow session
|
||||
- workflow-plan/phases/02-context-gathering.md - Phase 2: Gather project context and analyze codebase
|
||||
- phases/01-test-context-gather.md - Phase 3: Analyze existing test patterns and coverage
|
||||
- workflow-plan/phases/03-conflict-resolution.md - Phase 4: Detect and resolve conflicts (conditional)
|
||||
- compact (external skill) - Phase 4.5: Memory optimization (if context approaching limits)
|
||||
- phases/02-task-generate-tdd.md - Phase 5: Generate TDD tasks
|
||||
|
||||
**Follow-up**:
|
||||
- plan-verify (external) - Recommended: Verify TDD plan quality and structure before execution
|
||||
- workflow:status (external) - Review TDD task breakdown
|
||||
- workflow:execute (external) - Begin TDD implementation
|
||||
- phases/03-tdd-verify.md - Post-execution: Verify TDD compliance and generate quality report
|
||||
|
||||
## Next Steps Decision Table
|
||||
|
||||
| Situation | Recommended Action | Purpose |
|
||||
|-----------|-------------------|---------|
|
||||
| First time planning | Run plan-verify (external) | Validate task structure before execution |
|
||||
| Warnings in tdd-warnings.log | Review log, refine tasks | Address Red Flags before proceeding |
|
||||
| High task count warning | Consider new session | Split into focused sub-sessions |
|
||||
| Ready to implement | Run workflow:execute (external) | Begin TDD Red-Green-Refactor cycles |
|
||||
| After implementation | Run phases/03-tdd-verify.md | Generate TDD compliance report |
|
||||
| Need to review tasks | Run workflow:status (external) | Inspect current task breakdown |
|
||||
|
||||
### TDD Workflow State Transitions
|
||||
|
||||
```
|
||||
workflow-tdd-plan (this skill)
|
||||
↓
|
||||
[Planning Complete] ──→ plan-verify (external, recommended)
|
||||
↓
|
||||
[Verified/Ready] ─────→ workflow:execute (external)
|
||||
↓
|
||||
[Implementation] ─────→ phases/03-tdd-verify.md (post-execution)
|
||||
↓
|
||||
[Quality Report] ─────→ Done or iterate
|
||||
```
|
||||
@@ -1,213 +0,0 @@
|
||||
# Phase 1: Test Context Gather
|
||||
|
||||
## Overview
|
||||
|
||||
Orchestrator command that invokes `test-context-search-agent` to gather comprehensive test coverage context for test generation workflows. Generates standardized `test-context-package.json` with coverage analysis, framework detection, and source implementation context.
|
||||
|
||||
## Core Philosophy
|
||||
|
||||
- **Agent Delegation**: Delegate all test coverage analysis to `test-context-search-agent` for autonomous execution
|
||||
- **Detection-First**: Check for existing test-context-package before executing
|
||||
- **Coverage-First**: Analyze existing test coverage before planning new tests
|
||||
- **Source Context Loading**: Import implementation summaries from source session
|
||||
- **Standardized Output**: Generate `.workflow/active/{test_session_id}/.process/test-context-package.json`
|
||||
|
||||
## Execution Process
|
||||
|
||||
```
|
||||
Input Parsing:
|
||||
├─ Parse flags: --session
|
||||
└─ Validation: test_session_id REQUIRED
|
||||
|
||||
Step 1: Test-Context-Package Detection
|
||||
└─ Decision (existing package):
|
||||
├─ Valid package exists → Return existing (skip execution)
|
||||
└─ No valid package → Continue to Step 2
|
||||
|
||||
Step 2: Invoke Test-Context-Search Agent
|
||||
├─ Phase 1: Session Validation & Source Context Loading
|
||||
│ ├─ Detection: Check for existing test-context-package
|
||||
│ ├─ Test session validation
|
||||
│ └─ Source context loading (summaries, changed files)
|
||||
├─ Phase 2: Test Coverage Analysis
|
||||
│ ├─ Track 1: Existing test discovery
|
||||
│ ├─ Track 2: Coverage gap analysis
|
||||
│ └─ Track 3: Coverage statistics
|
||||
└─ Phase 3: Framework Detection & Packaging
|
||||
├─ Framework identification
|
||||
├─ Convention analysis
|
||||
└─ Generate test-context-package.json
|
||||
|
||||
Step 3: Output Verification
|
||||
└─ Verify test-context-package.json created
|
||||
```
|
||||
|
||||
## Execution Flow
|
||||
|
||||
### Step 1: Test-Context-Package Detection
|
||||
|
||||
**Execute First** - Check if valid package already exists:
|
||||
|
||||
```javascript
|
||||
const testContextPath = `.workflow/${test_session_id}/.process/test-context-package.json`;
|
||||
|
||||
if (file_exists(testContextPath)) {
|
||||
const existing = Read(testContextPath);
|
||||
|
||||
// Validate package belongs to current test session
|
||||
if (existing?.metadata?.test_session_id === test_session_id) {
|
||||
console.log("Valid test-context-package found for session:", test_session_id);
|
||||
console.log("Coverage Stats:", existing.test_coverage.coverage_stats);
|
||||
console.log("Framework:", existing.test_framework.framework);
|
||||
console.log("Missing Tests:", existing.test_coverage.missing_tests.length);
|
||||
return existing; // Skip execution, return existing
|
||||
} else {
|
||||
console.warn("Invalid test_session_id in existing package, re-generating...");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Step 2: Invoke Test-Context-Search Agent
|
||||
|
||||
**Only execute if Step 1 finds no valid package**
|
||||
|
||||
```javascript
|
||||
Task(
|
||||
subagent_type="test-context-search-agent",
|
||||
run_in_background=false,
|
||||
description="Gather test coverage context",
|
||||
prompt=`
|
||||
|
||||
## Execution Mode
|
||||
**PLAN MODE** (Comprehensive) - Full Phase 1-3 execution
|
||||
|
||||
## Session Information
|
||||
- **Test Session ID**: ${test_session_id}
|
||||
- **Output Path**: .workflow/${test_session_id}/.process/test-context-package.json
|
||||
|
||||
## Mission
|
||||
Execute complete test-context-search-agent workflow for test generation planning:
|
||||
|
||||
### Phase 1: Session Validation & Source Context Loading
|
||||
1. **Detection**: Check for existing test-context-package (early exit if valid)
|
||||
2. **Test Session Validation**: Load test session metadata, extract source_session reference
|
||||
3. **Source Context Loading**: Load source session implementation summaries, changed files, tech stack
|
||||
|
||||
### Phase 2: Test Coverage Analysis
|
||||
Execute coverage discovery:
|
||||
- **Track 1**: Existing test discovery (find *.test.*, *.spec.* files)
|
||||
- **Track 2**: Coverage gap analysis (match implementation files to test files)
|
||||
- **Track 3**: Coverage statistics (calculate percentages, identify gaps by module)
|
||||
|
||||
### Phase 3: Framework Detection & Packaging
|
||||
1. Framework identification from package.json/requirements.txt
|
||||
2. Convention analysis from existing test patterns
|
||||
3. Generate and validate test-context-package.json
|
||||
|
||||
## Output Requirements
|
||||
Complete test-context-package.json with:
|
||||
- **metadata**: test_session_id, source_session_id, task_type, complexity
|
||||
- **source_context**: implementation_summaries, tech_stack, project_patterns
|
||||
- **test_coverage**: existing_tests[], missing_tests[], coverage_stats
|
||||
- **test_framework**: framework, version, test_pattern, conventions
|
||||
- **assets**: implementation_summary[], existing_test[], source_code[] with priorities
|
||||
- **focus_areas**: Test generation guidance based on coverage gaps
|
||||
|
||||
## Quality Validation
|
||||
Before completion verify:
|
||||
- [ ] Valid JSON format with all required fields
|
||||
- [ ] Source session context loaded successfully
|
||||
- [ ] Test coverage gaps identified
|
||||
- [ ] Test framework detected (or marked as 'unknown')
|
||||
- [ ] Coverage percentage calculated correctly
|
||||
- [ ] Missing tests catalogued with priority
|
||||
- [ ] Execution time < 30 seconds (< 60s for large codebases)
|
||||
|
||||
Execute autonomously following agent documentation.
|
||||
Report completion with coverage statistics.
|
||||
`
|
||||
)
|
||||
```
|
||||
|
||||
### Step 3: Output Verification
|
||||
|
||||
After agent completes, verify output:
|
||||
|
||||
```javascript
|
||||
// Verify file was created
|
||||
const outputPath = `.workflow/${test_session_id}/.process/test-context-package.json`;
|
||||
if (!file_exists(outputPath)) {
|
||||
throw new Error("Agent failed to generate test-context-package.json");
|
||||
}
|
||||
|
||||
// Load and display summary
|
||||
const testContext = Read(outputPath);
|
||||
console.log("Test context package generated successfully");
|
||||
console.log("Coverage:", testContext.test_coverage.coverage_stats.coverage_percentage + "%");
|
||||
console.log("Tests to generate:", testContext.test_coverage.missing_tests.length);
|
||||
```
|
||||
|
||||
## Parameter Reference
|
||||
|
||||
| Parameter | Type | Required | Description |
|
||||
|-----------|------|----------|-------------|
|
||||
| `--session` | string | Yes | Test workflow session ID (e.g., WFS-test-auth) |
|
||||
|
||||
## Output Schema
|
||||
|
||||
Refer to `test-context-search-agent.md` Phase 3.2 for complete `test-context-package.json` schema.
|
||||
|
||||
**Key Sections**:
|
||||
- **metadata**: Test session info, source session reference, complexity
|
||||
- **source_context**: Implementation summaries with changed files and tech stack
|
||||
- **test_coverage**: Existing tests, missing tests with priorities, coverage statistics
|
||||
- **test_framework**: Framework name, version, patterns, conventions
|
||||
- **assets**: Categorized files with relevance (implementation_summary, existing_test, source_code)
|
||||
- **focus_areas**: Test generation guidance based on analysis
|
||||
|
||||
## Success Criteria
|
||||
|
||||
- Valid test-context-package.json generated in `.workflow/active/{test_session_id}/.process/`
|
||||
- Source session context loaded successfully
|
||||
- Test coverage gaps identified (>90% accuracy)
|
||||
- Test framework detected and documented
|
||||
- Execution completes within 30 seconds (60s for large codebases)
|
||||
- All required schema fields present and valid
|
||||
- Coverage statistics calculated correctly
|
||||
- Agent reports completion with statistics
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Error | Cause | Resolution |
|
||||
|-------|-------|------------|
|
||||
| Package validation failed | Invalid test_session_id in existing package | Re-run agent to regenerate |
|
||||
| Source session not found | Invalid source_session reference | Verify test session metadata |
|
||||
| No implementation summaries | Source session incomplete | Complete source session first |
|
||||
| Agent execution timeout | Large codebase or slow analysis | Increase timeout, check file access |
|
||||
| Missing required fields | Agent incomplete execution | Check agent logs, verify schema compliance |
|
||||
| No test framework detected | Missing test dependencies | Agent marks as 'unknown', manual specification needed |
|
||||
|
||||
## Integration
|
||||
|
||||
### Called By
|
||||
- SKILL.md (Phase 3: Test Coverage Analysis)
|
||||
|
||||
### Calls
|
||||
- `test-context-search-agent` - Autonomous test coverage analysis
|
||||
|
||||
## Notes
|
||||
|
||||
- **Detection-first**: Always check for existing test-context-package before invoking agent
|
||||
- **No redundancy**: This command is a thin orchestrator, all logic in agent
|
||||
- **Framework agnostic**: Supports Jest, Mocha, pytest, RSpec, Go testing, etc.
|
||||
- **Coverage focus**: Primary goal is identifying implementation files without tests
|
||||
|
||||
---
|
||||
|
||||
## Post-Phase Update
|
||||
|
||||
After Phase 1 (Test Context Gather) completes:
|
||||
- **Output Created**: `test-context-package.json` in `.workflow/active/{session}/.process/`
|
||||
- **Data Available**: Test coverage stats, framework info, missing tests list
|
||||
- **Next Action**: Continue to Phase 4 (Conflict Resolution, if conflict_risk >= medium) or Phase 5 (TDD Task Generation)
|
||||
- **TodoWrite**: Collapse Phase 3 sub-tasks to "Phase 3: Test Coverage Analysis: completed"
|
||||
@@ -1,746 +0,0 @@
|
||||
## Auto Mode
|
||||
|
||||
When `--yes` or `-y`: Skip user questions, use defaults (no materials, Agent executor).
|
||||
|
||||
# Phase 2: TDD Task Generation
|
||||
|
||||
## Overview
|
||||
Autonomous TDD task JSON and IMPL_PLAN.md generation using action-planning-agent with two-phase execution: discovery and document generation. Generates complete Red-Green-Refactor cycles contained within each task.
|
||||
|
||||
## Core Philosophy
|
||||
- **Agent-Driven**: Delegate execution to action-planning-agent for autonomous operation
|
||||
- **Two-Phase Flow**: Discovery (context gathering) → Output (document generation)
|
||||
- **Memory-First**: Reuse loaded documents from conversation memory
|
||||
- **MCP-Enhanced**: Use MCP tools for advanced code analysis and research
|
||||
- **Semantic CLI Selection**: CLI tool usage determined from user's task description, not flags
|
||||
- **Agent Simplicity**: Agent generates content with semantic CLI detection
|
||||
- **Path Clarity**: All `focus_paths` prefer absolute paths (e.g., `D:\\project\\src\\module`), or clear relative paths from project root (e.g., `./src/module`)
|
||||
- **TDD-First**: Every feature starts with a failing test (Red phase)
|
||||
- **Feature-Complete Tasks**: Each task contains complete Red-Green-Refactor cycle
|
||||
- **Quantification-Enforced**: All test cases, coverage requirements, and implementation scope MUST include explicit counts and enumerations
|
||||
|
||||
## Task Strategy & Philosophy
|
||||
|
||||
### Optimized Task Structure (Current)
|
||||
- **1 feature = 1 task** containing complete TDD cycle internally
|
||||
- Each task executes Red-Green-Refactor phases sequentially
|
||||
- Task count = Feature count (typically 5 features = 5 tasks)
|
||||
|
||||
**Previous Approach** (Deprecated):
|
||||
- 1 feature = 3 separate tasks (TEST-N.M, IMPL-N.M, REFACTOR-N.M)
|
||||
- 5 features = 15 tasks with complex dependency chains
|
||||
- High context switching cost between phases
|
||||
|
||||
### When to Use Subtasks
|
||||
- Feature complexity >2500 lines or >6 files per TDD cycle
|
||||
- Multiple independent sub-features needing parallel execution
|
||||
- Strong technical dependency blocking (e.g., API before UI)
|
||||
- Different tech stacks or domains within feature
|
||||
|
||||
### Task Limits
|
||||
- **Maximum 18 tasks** (hard limit for TDD workflows)
|
||||
- **Feature-based**: Complete functional units with internal TDD cycles
|
||||
- **Hierarchy**: Flat (<=5 simple features) | Two-level (6-10 for complex features with sub-features)
|
||||
- **Re-scope**: If >18 tasks needed, break project into multiple TDD workflow sessions
|
||||
|
||||
### TDD Cycle Mapping
|
||||
- **Old approach**: 1 feature = 3 tasks (TEST-N.M, IMPL-N.M, REFACTOR-N.M)
|
||||
- **Current approach**: 1 feature = 1 task (IMPL-N with internal Red-Green-Refactor phases)
|
||||
- **Complex features**: 1 container (IMPL-N) + subtasks (IMPL-N.M) when necessary
|
||||
|
||||
## Execution Process
|
||||
|
||||
```
|
||||
Input Parsing:
|
||||
├─ Parse flags: --session
|
||||
└─ Validation: session_id REQUIRED
|
||||
|
||||
Phase 1: Discovery & Context Loading (Memory-First)
|
||||
├─ Load session context (if not in memory)
|
||||
├─ Load context package (if not in memory)
|
||||
├─ Load test context package (if not in memory)
|
||||
├─ Extract & load role analyses from context package
|
||||
├─ Load conflict resolution (if exists)
|
||||
└─ Optional: MCP external research
|
||||
|
||||
Phase 2: Agent Execution (Document Generation)
|
||||
├─ Pre-agent template selection (semantic CLI detection)
|
||||
├─ Invoke action-planning-agent
|
||||
├─ Generate TDD Task JSON Files (.task/IMPL-*.json)
|
||||
│ └─ Each task: complete Red-Green-Refactor cycle internally
|
||||
├─ Create IMPL_PLAN.md (TDD variant)
|
||||
└─ Generate TODO_LIST.md with TDD phase indicators
|
||||
```
|
||||
|
||||
## Execution Lifecycle
|
||||
|
||||
### Phase 0: User Configuration (Interactive)
|
||||
|
||||
**Purpose**: Collect user preferences before TDD task generation to ensure generated tasks match execution expectations and provide necessary supplementary context.
|
||||
|
||||
**User Questions**:
|
||||
```javascript
|
||||
AskUserQuestion({
|
||||
questions: [
|
||||
{
|
||||
question: "Do you have supplementary materials or guidelines to include?",
|
||||
header: "Materials",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "No additional materials", description: "Use existing context only" },
|
||||
{ label: "Provide file paths", description: "I'll specify paths to include" },
|
||||
{ label: "Provide inline content", description: "I'll paste content directly" }
|
||||
]
|
||||
},
|
||||
{
|
||||
question: "Select execution method for generated TDD tasks:",
|
||||
header: "Execution",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "Agent (Recommended)", description: "Claude agent executes Red-Green-Refactor cycles directly" },
|
||||
{ label: "Hybrid", description: "Agent orchestrates, calls CLI for complex steps (Red/Green phases)" },
|
||||
{ label: "CLI Only", description: "All TDD cycles via CLI tools (codex/gemini/qwen)" }
|
||||
]
|
||||
},
|
||||
{
|
||||
question: "If using CLI, which tool do you prefer?",
|
||||
header: "CLI Tool",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "Codex (Recommended)", description: "Best for TDD Red-Green-Refactor cycles" },
|
||||
{ label: "Gemini", description: "Best for analysis and large context" },
|
||||
{ label: "Qwen", description: "Alternative analysis tool" },
|
||||
{ label: "Auto", description: "Let agent decide per-task" }
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
```
|
||||
|
||||
**Handle Materials Response**:
|
||||
```javascript
|
||||
if (userConfig.materials === "Provide file paths") {
|
||||
// Follow-up question for file paths
|
||||
const pathsResponse = AskUserQuestion({
|
||||
questions: [{
|
||||
question: "Enter file paths to include (comma-separated or one per line):",
|
||||
header: "Paths",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "Enter paths", description: "Provide paths in text input" }
|
||||
]
|
||||
}]
|
||||
})
|
||||
userConfig.supplementaryPaths = parseUserPaths(pathsResponse)
|
||||
}
|
||||
```
|
||||
|
||||
**Build userConfig**:
|
||||
```javascript
|
||||
const userConfig = {
|
||||
supplementaryMaterials: {
|
||||
type: "none|paths|inline",
|
||||
content: [...], // Parsed paths or inline content
|
||||
},
|
||||
executionMethod: "agent|hybrid|cli",
|
||||
preferredCliTool: "codex|gemini|qwen|auto",
|
||||
enableResume: true // Always enable resume for CLI executions
|
||||
}
|
||||
```
|
||||
|
||||
**Pass to Agent**: Include `userConfig` in agent prompt for Phase 2.
|
||||
|
||||
---
|
||||
|
||||
### Phase 1: Context Preparation & Discovery
|
||||
|
||||
**Command Responsibility**: Command prepares session paths and metadata, provides to agent for autonomous context loading.
|
||||
|
||||
**Memory-First Rule**: Skip file loading if documents already in conversation memory
|
||||
|
||||
**Progressive Loading Strategy**: Load context incrementally due to large analysis.md file sizes:
|
||||
- **Core**: session metadata + context-package.json (always load)
|
||||
- **Selective**: synthesis_output OR (guidance + relevant role analyses) - NOT all role analyses
|
||||
- **On-Demand**: conflict resolution (if conflict_risk >= medium), test context
|
||||
|
||||
**Path Clarity Requirement**: All `focus_paths` prefer absolute paths (e.g., `D:\\project\\src\\module`), or clear relative paths from project root (e.g., `./src/module`)
|
||||
|
||||
**Session Path Structure** (Provided by Command to Agent):
|
||||
```
|
||||
.workflow/active/WFS-{session-id}/
|
||||
├── workflow-session.json # Session metadata
|
||||
├── .process/
|
||||
│ ├── context-package.json # Context package with artifact catalog
|
||||
│ ├── test-context-package.json # Test coverage analysis
|
||||
│ └── conflict-resolution.json # Conflict resolution (if exists)
|
||||
├── .task/ # Output: Task JSON files
|
||||
│ ├── IMPL-1.json
|
||||
│ ├── IMPL-2.json
|
||||
│ └── ...
|
||||
├── IMPL_PLAN.md # Output: TDD implementation plan
|
||||
└── TODO_LIST.md # Output: TODO list with TDD phases
|
||||
```
|
||||
|
||||
**Command Preparation**:
|
||||
1. **Assemble Session Paths** for agent prompt:
|
||||
- `session_metadata_path`: `.workflow/active/{session-id}/workflow-session.json`
|
||||
- `context_package_path`: `.workflow/active/{session-id}/.process/context-package.json`
|
||||
- `test_context_package_path`: `.workflow/active/{session-id}/.process/test-context-package.json`
|
||||
- Output directory paths
|
||||
|
||||
2. **Provide Metadata** (simple values):
|
||||
- `session_id`: WFS-{session-id}
|
||||
- `workflow_type`: "tdd"
|
||||
- `mcp_capabilities`: {exa_code, exa_web, code_index}
|
||||
|
||||
3. **Pass userConfig** from Phase 0
|
||||
|
||||
**Agent Context Package** (Agent loads autonomously):
|
||||
```javascript
|
||||
{
|
||||
"session_id": "WFS-[session-id]",
|
||||
"workflow_type": "tdd",
|
||||
|
||||
// Core (ALWAYS load)
|
||||
"session_metadata": {
|
||||
// If in memory: use cached content
|
||||
// Else: Load from workflow-session.json
|
||||
},
|
||||
"context_package": {
|
||||
// If in memory: use cached content
|
||||
// Else: Load from context-package.json
|
||||
},
|
||||
|
||||
// Selective (load based on progressive strategy)
|
||||
"brainstorm_artifacts": {
|
||||
// Loaded from context-package.json → brainstorm_artifacts section
|
||||
"synthesis_output": {"path": "...", "exists": true}, // Load if exists (highest priority)
|
||||
"guidance_specification": {"path": "...", "exists": true}, // Load if no synthesis
|
||||
"role_analyses": [ // Load SELECTIVELY based on task relevance
|
||||
{
|
||||
"role": "system-architect",
|
||||
"files": [{"path": "...", "type": "primary|supplementary"}]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
// On-Demand (load if exists)
|
||||
"test_context_package": {
|
||||
// Load from test-context-package.json
|
||||
// Contains existing test patterns and coverage analysis
|
||||
},
|
||||
"conflict_resolution": {
|
||||
// Load from conflict-resolution.json if conflict_risk >= medium
|
||||
// Check context-package.conflict_detection.resolution_file
|
||||
},
|
||||
|
||||
// Capabilities
|
||||
"mcp_capabilities": {
|
||||
"exa_code": true,
|
||||
"exa_web": true,
|
||||
"code_index": true
|
||||
},
|
||||
|
||||
// User configuration from Phase 0
|
||||
"user_config": {
|
||||
// From Phase 0 AskUserQuestion
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Discovery Actions**:
|
||||
1. **Load Session Context** (if not in memory)
|
||||
```javascript
|
||||
if (!memory.has("workflow-session.json")) {
|
||||
Read(.workflow/active/{session-id}/workflow-session.json)
|
||||
}
|
||||
```
|
||||
|
||||
2. **Load Context Package** (if not in memory)
|
||||
```javascript
|
||||
if (!memory.has("context-package.json")) {
|
||||
Read(.workflow/active/{session-id}/.process/context-package.json)
|
||||
}
|
||||
```
|
||||
|
||||
3. **Load Test Context Package** (if not in memory)
|
||||
```javascript
|
||||
if (!memory.has("test-context-package.json")) {
|
||||
Read(.workflow/active/{session-id}/.process/test-context-package.json)
|
||||
}
|
||||
```
|
||||
|
||||
4. **Extract & Load Role Analyses** (from context-package.json)
|
||||
```javascript
|
||||
// Extract role analysis paths from context package
|
||||
const roleAnalysisPaths = contextPackage.brainstorm_artifacts.role_analyses
|
||||
.flatMap(role => role.files.map(f => f.path));
|
||||
|
||||
// Load each role analysis file
|
||||
roleAnalysisPaths.forEach(path => Read(path));
|
||||
```
|
||||
|
||||
5. **Load Conflict Resolution** (from conflict-resolution.json, if exists)
|
||||
```javascript
|
||||
// Check for new conflict-resolution.json format
|
||||
if (contextPackage.conflict_detection?.resolution_file) {
|
||||
Read(contextPackage.conflict_detection.resolution_file) // .process/conflict-resolution.json
|
||||
}
|
||||
// Fallback: legacy brainstorm_artifacts path
|
||||
else if (contextPackage.brainstorm_artifacts?.conflict_resolution?.exists) {
|
||||
Read(contextPackage.brainstorm_artifacts.conflict_resolution.path)
|
||||
}
|
||||
```
|
||||
|
||||
6. **Code Analysis with Native Tools** (optional - enhance understanding)
|
||||
```bash
|
||||
# Find relevant test files and patterns
|
||||
find . -name "*test*" -type f
|
||||
rg "describe|it\(|test\(" -g "*.ts"
|
||||
```
|
||||
|
||||
7. **MCP External Research** (optional - gather TDD best practices)
|
||||
```javascript
|
||||
// Get external TDD examples and patterns
|
||||
mcp__exa__get_code_context_exa(
|
||||
query="TypeScript TDD best practices Red-Green-Refactor",
|
||||
tokensNum="dynamic"
|
||||
)
|
||||
```
|
||||
|
||||
### Phase 2: Agent Execution (TDD Document Generation)
|
||||
|
||||
**Purpose**: Generate TDD planning documents (IMPL_PLAN.md, task JSONs, TODO_LIST.md) - planning only, NOT code implementation.
|
||||
|
||||
**Agent Invocation**:
|
||||
```javascript
|
||||
Task(
|
||||
subagent_type="action-planning-agent",
|
||||
run_in_background=false,
|
||||
description="Generate TDD planning documents (IMPL_PLAN.md, task JSONs, TODO_LIST.md)",
|
||||
prompt=`
|
||||
## TASK OBJECTIVE
|
||||
Generate TDD implementation planning documents (IMPL_PLAN.md, task JSONs, TODO_LIST.md) for workflow session
|
||||
|
||||
IMPORTANT: This is PLANNING ONLY - you are generating planning documents, NOT implementing code.
|
||||
|
||||
CRITICAL: Follow the progressive loading strategy (load analysis.md files incrementally due to file size):
|
||||
- **Core**: session metadata + context-package.json (always)
|
||||
- **Selective**: synthesis_output OR (guidance + relevant role analyses) - NOT all
|
||||
- **On-Demand**: conflict resolution (if conflict_risk >= medium), test context
|
||||
|
||||
## SESSION PATHS
|
||||
Input:
|
||||
- Session Metadata: .workflow/active/{session-id}/workflow-session.json
|
||||
- Context Package: .workflow/active/{session-id}/.process/context-package.json
|
||||
- Test Context: .workflow/active/{session-id}/.process/test-context-package.json
|
||||
|
||||
Output:
|
||||
- Task Dir: .workflow/active/{session-id}/.task/
|
||||
- IMPL_PLAN: .workflow/active/{session-id}/IMPL_PLAN.md
|
||||
- TODO_LIST: .workflow/active/{session-id}/TODO_LIST.md
|
||||
|
||||
## CONTEXT METADATA
|
||||
Session ID: {session-id}
|
||||
Workflow Type: TDD
|
||||
MCP Capabilities: {exa_code, exa_web, code_index}
|
||||
|
||||
## USER CONFIGURATION (from Phase 0)
|
||||
Execution Method: ${userConfig.executionMethod} // agent|hybrid|cli
|
||||
Preferred CLI Tool: ${userConfig.preferredCliTool} // codex|gemini|qwen|auto
|
||||
Supplementary Materials: ${userConfig.supplementaryMaterials}
|
||||
|
||||
## EXECUTION METHOD MAPPING
|
||||
Based on userConfig.executionMethod, set task-level meta.execution_config:
|
||||
|
||||
"agent" →
|
||||
meta.execution_config = { method: "agent", cli_tool: null, enable_resume: false }
|
||||
Agent executes Red-Green-Refactor phases directly
|
||||
|
||||
"cli" →
|
||||
meta.execution_config = { method: "cli", cli_tool: userConfig.preferredCliTool, enable_resume: true }
|
||||
Agent executes pre_analysis, then hands off full context to CLI via buildCliHandoffPrompt()
|
||||
|
||||
"hybrid" →
|
||||
Per-task decision: Analyze TDD cycle complexity, set method to "agent" OR "cli" per task
|
||||
- Simple cycles (<=5 test cases, <=3 files) → method: "agent"
|
||||
- Complex cycles (>5 test cases, >3 files, integration tests) → method: "cli"
|
||||
CLI tool: userConfig.preferredCliTool, enable_resume: true
|
||||
|
||||
IMPORTANT: Do NOT add command field to implementation_approach steps. Execution routing is controlled by task-level meta.execution_config.method only.
|
||||
|
||||
## EXPLORATION CONTEXT (from context-package.exploration_results)
|
||||
- Load exploration_results from context-package.json
|
||||
- Use aggregated_insights.critical_files for focus_paths generation
|
||||
- Apply aggregated_insights.constraints to acceptance criteria
|
||||
- Reference aggregated_insights.all_patterns for implementation approach
|
||||
- Use aggregated_insights.all_integration_points for precise modification locations
|
||||
- Use conflict_indicators for risk-aware task sequencing
|
||||
|
||||
## CONFLICT RESOLUTION CONTEXT (if exists)
|
||||
- Check context-package.conflict_detection.resolution_file for conflict-resolution.json path
|
||||
- If exists, load .process/conflict-resolution.json:
|
||||
- Apply planning_constraints as task constraints (for brainstorm-less workflows)
|
||||
- Reference resolved_conflicts for implementation approach alignment
|
||||
- Handle custom_conflicts with explicit task notes
|
||||
|
||||
## TEST CONTEXT INTEGRATION
|
||||
- Load test-context-package.json for existing test patterns and coverage analysis
|
||||
- Extract test framework configuration (Jest/Pytest/etc.)
|
||||
- Identify existing test conventions and patterns
|
||||
- Map coverage gaps to TDD Red phase test targets
|
||||
|
||||
## TDD DOCUMENT GENERATION TASK
|
||||
|
||||
**Agent Configuration Reference**: All TDD task generation rules, quantification requirements, Red-Green-Refactor cycle structure, quality standards, and execution details are defined in action-planning-agent.
|
||||
|
||||
### TDD-Specific Requirements Summary
|
||||
|
||||
#### Task Structure Philosophy
|
||||
- **1 feature = 1 task** containing complete TDD cycle internally
|
||||
- Each task executes Red-Green-Refactor phases sequentially
|
||||
- Task count = Feature count (typically 5 features = 5 tasks)
|
||||
- Subtasks only when complexity >2500 lines or >6 files per cycle
|
||||
- **Maximum 18 tasks** (hard limit for TDD workflows)
|
||||
|
||||
#### TDD Cycle Mapping
|
||||
- **Simple features**: IMPL-N with internal Red-Green-Refactor phases
|
||||
- **Complex features**: IMPL-N (container) + IMPL-N.M (subtasks)
|
||||
- Each cycle includes: test_count, test_cases array, implementation_scope, expected_coverage
|
||||
|
||||
#### Required Outputs Summary
|
||||
|
||||
##### 1. TDD Task JSON Files (.task/IMPL-*.json)
|
||||
- **Location**: \`.workflow/active/{session-id}/.task/\`
|
||||
- **Schema**: 6-field structure with TDD-specific metadata
|
||||
- \`id, title, status, context_package_path, meta, context, flow_control\`
|
||||
- \`meta.tdd_workflow\`: true (REQUIRED)
|
||||
- \`meta.max_iterations\`: 3 (Green phase test-fix cycle limit)
|
||||
- \`meta.cli_execution_id\`: Unique CLI execution ID (format: \`{session_id}-{task_id}\`)
|
||||
- \`meta.cli_execution\`: Strategy object (new|resume|fork|merge_fork)
|
||||
- \`context.tdd_cycles\`: Array with quantified test cases and coverage
|
||||
- \`context.focus_paths\`: Absolute or clear relative paths (enhanced with exploration critical_files)
|
||||
- \`flow_control.implementation_approach\`: Exactly 3 steps with \`tdd_phase\` field
|
||||
1. Red Phase (\`tdd_phase: "red"\`): Write failing tests
|
||||
2. Green Phase (\`tdd_phase: "green"\`): Implement to pass tests
|
||||
3. Refactor Phase (\`tdd_phase: "refactor"\`): Improve code quality
|
||||
- \`flow_control.pre_analysis\`: Include exploration integration_points analysis
|
||||
- **meta.execution_config**: Set per userConfig.executionMethod (agent/cli/hybrid)
|
||||
- **Details**: See action-planning-agent.md § TDD Task JSON Generation
|
||||
|
||||
##### 2. IMPL_PLAN.md (TDD Variant)
|
||||
- **Location**: \`.workflow/active/{session-id}/IMPL_PLAN.md\`
|
||||
- **Template**: \`~/.ccw/workflows/cli-templates/prompts/workflow/impl-plan-template.txt\`
|
||||
- **TDD-Specific Frontmatter**: workflow_type="tdd", tdd_workflow=true, feature_count, task_breakdown
|
||||
- **TDD Implementation Tasks Section**: Feature-by-feature with internal Red-Green-Refactor cycles
|
||||
- **Context Analysis**: Artifact references and exploration insights
|
||||
- **Details**: See action-planning-agent.md § TDD Implementation Plan Creation
|
||||
|
||||
##### 3. TODO_LIST.md
|
||||
- **Location**: \`.workflow/active/{session-id}/TODO_LIST.md\`
|
||||
- **Format**: Hierarchical task list with internal TDD phase indicators (Red → Green → Refactor)
|
||||
- **Status**: ▸ (container), [ ] (pending), [x] (completed)
|
||||
- **Links**: Task JSON references and summaries
|
||||
- **Details**: See action-planning-agent.md § TODO List Generation
|
||||
|
||||
### CLI EXECUTION ID REQUIREMENTS (MANDATORY)
|
||||
|
||||
Each task JSON MUST include:
|
||||
- **meta.cli_execution_id**: Unique ID for CLI execution (format: \`{session_id}-{task_id}\`)
|
||||
- **meta.cli_execution**: Strategy object based on depends_on:
|
||||
- No deps → \`{ "strategy": "new" }\`
|
||||
- 1 dep (single child) → \`{ "strategy": "resume", "resume_from": "parent-cli-id" }\`
|
||||
- 1 dep (multiple children) → \`{ "strategy": "fork", "resume_from": "parent-cli-id" }\`
|
||||
- N deps → \`{ "strategy": "merge_fork", "resume_from": ["id1", "id2", ...] }\`
|
||||
- **Type**: \`resume_from: string | string[]\` (string for resume/fork, array for merge_fork)
|
||||
|
||||
**CLI Execution Strategy Rules**:
|
||||
1. **new**: Task has no dependencies - starts fresh CLI conversation
|
||||
2. **resume**: Task has 1 parent AND that parent has only this child - continues same conversation
|
||||
3. **fork**: Task has 1 parent BUT parent has multiple children - creates new branch with parent context
|
||||
4. **merge_fork**: Task has multiple parents - merges all parent contexts into new conversation
|
||||
|
||||
**Execution Command Patterns**:
|
||||
- new: \`ccw cli -p "[prompt]" --tool [tool] --mode write --id [cli_execution_id]\`
|
||||
- resume: \`ccw cli -p "[prompt]" --resume [resume_from] --tool [tool] --mode write\`
|
||||
- fork: \`ccw cli -p "[prompt]" --resume [resume_from] --id [cli_execution_id] --tool [tool] --mode write\`
|
||||
- merge_fork: \`ccw cli -p "[prompt]" --resume [resume_from.join(',')] --id [cli_execution_id] --tool [tool] --mode write\` (resume_from is array)
|
||||
|
||||
### Quantification Requirements (MANDATORY)
|
||||
|
||||
**Core Rules**:
|
||||
1. **Explicit Test Case Counts**: Red phase specifies exact number with enumerated list
|
||||
2. **Quantified Coverage**: Acceptance includes measurable percentage (e.g., ">=85%")
|
||||
3. **Detailed Implementation Scope**: Green phase enumerates files, functions, line counts
|
||||
4. **Enumerated Refactoring Targets**: Refactor phase lists specific improvements with counts
|
||||
|
||||
**TDD Phase Formats**:
|
||||
- **Red Phase**: "Write N test cases: [test1, test2, ...]"
|
||||
- **Green Phase**: "Implement N functions in file lines X-Y: [func1() X1-Y1, func2() X2-Y2, ...]"
|
||||
- **Refactor Phase**: "Apply N refactorings: [improvement1 (details), improvement2 (details), ...]"
|
||||
- **Acceptance**: "All N tests pass with >=X% coverage: verify by [test command]"
|
||||
|
||||
**Validation Checklist**:
|
||||
- [ ] Every Red phase specifies exact test case count with enumerated list
|
||||
- [ ] Every Green phase enumerates files, functions, and estimated line counts
|
||||
- [ ] Every Refactor phase lists specific improvements with counts
|
||||
- [ ] Every acceptance criterion includes measurable coverage percentage
|
||||
- [ ] tdd_cycles array contains test_count and test_cases for each cycle
|
||||
- [ ] No vague language ("comprehensive", "complete", "thorough")
|
||||
- [ ] cli_execution_id and cli_execution strategy assigned to each task
|
||||
|
||||
### Agent Execution Summary
|
||||
|
||||
**Key Steps** (Detailed instructions in action-planning-agent.md):
|
||||
1. Load task JSON template from provided path
|
||||
2. Extract and decompose features with TDD cycles
|
||||
3. Generate TDD task JSON files enforcing quantification requirements
|
||||
4. Create IMPL_PLAN.md using TDD template variant
|
||||
5. Generate TODO_LIST.md with TDD phase indicators
|
||||
6. Update session state with TDD metadata
|
||||
|
||||
**Quality Gates** (Full checklist in action-planning-agent.md):
|
||||
- Task count <=18 (hard limit)
|
||||
- Each task has meta.tdd_workflow: true
|
||||
- Each task has exactly 3 implementation steps with tdd_phase field ("red", "green", "refactor")
|
||||
- Each task has meta.cli_execution_id and meta.cli_execution strategy
|
||||
- Green phase includes test-fix cycle logic with max_iterations
|
||||
- focus_paths are absolute or clear relative paths (from exploration critical_files)
|
||||
- Artifact references mapped correctly from context package
|
||||
- Exploration context integrated (critical_files, constraints, patterns, integration_points)
|
||||
- Conflict resolution context applied (if conflict_risk >= medium)
|
||||
- Test context integrated (existing test patterns and coverage analysis)
|
||||
- Documents follow TDD template structure
|
||||
- CLI tool selection based on userConfig.executionMethod
|
||||
- Quantification requirements enforced (explicit counts, measurable acceptance, exact targets)
|
||||
|
||||
## SUCCESS CRITERIA
|
||||
- All planning documents generated successfully:
|
||||
- Task JSONs valid and saved to .task/ directory with cli_execution_id
|
||||
- IMPL_PLAN.md created with complete TDD structure
|
||||
- TODO_LIST.md generated matching task JSONs
|
||||
- CLI execution strategies assigned based on task dependencies
|
||||
- Return completion status with document count and task breakdown summary
|
||||
|
||||
## OUTPUT SUMMARY
|
||||
Generate all three documents and report:
|
||||
- TDD task JSON files created: N files (IMPL-*.json) with cli_execution_id assigned
|
||||
- TDD cycles configured: N cycles with quantified test cases
|
||||
- CLI execution strategies: new/resume/fork/merge_fork assigned per dependency graph
|
||||
- Artifacts integrated: synthesis-spec/guidance-specification, relevant role analyses
|
||||
- Exploration context: critical_files, constraints, patterns, integration_points
|
||||
- Test context integrated: existing patterns and coverage
|
||||
- Conflict resolution: applied (if conflict_risk >= medium)
|
||||
- Session ready for TDD execution
|
||||
`
|
||||
)
|
||||
```
|
||||
|
||||
### Agent Context Passing
|
||||
|
||||
**Context Delegation Model**: Command provides paths and metadata, agent loads context autonomously using progressive loading strategy.
|
||||
|
||||
**Command Provides** (in agent prompt):
|
||||
```javascript
|
||||
// Command assembles these simple values and paths for agent
|
||||
const commandProvides = {
|
||||
// Session paths
|
||||
session_metadata_path: ".workflow/active/WFS-{id}/workflow-session.json",
|
||||
context_package_path: ".workflow/active/WFS-{id}/.process/context-package.json",
|
||||
test_context_package_path: ".workflow/active/WFS-{id}/.process/test-context-package.json",
|
||||
output_task_dir: ".workflow/active/WFS-{id}/.task/",
|
||||
output_impl_plan: ".workflow/active/WFS-{id}/IMPL_PLAN.md",
|
||||
output_todo_list: ".workflow/active/WFS-{id}/TODO_LIST.md",
|
||||
|
||||
// Simple metadata
|
||||
session_id: "WFS-{id}",
|
||||
workflow_type: "tdd",
|
||||
mcp_capabilities: { exa_code: true, exa_web: true, code_index: true },
|
||||
|
||||
// User configuration from Phase 0
|
||||
user_config: {
|
||||
supplementaryMaterials: { type: "...", content: [...] },
|
||||
executionMethod: "agent|hybrid|cli",
|
||||
preferredCliTool: "codex|gemini|qwen|auto",
|
||||
enableResume: true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Agent Loads Autonomously** (progressive loading):
|
||||
```javascript
|
||||
// Agent executes progressive loading based on memory state
|
||||
const agentLoads = {
|
||||
// Core (ALWAYS load if not in memory)
|
||||
session_metadata: loadIfNotInMemory(session_metadata_path),
|
||||
context_package: loadIfNotInMemory(context_package_path),
|
||||
|
||||
// Selective (based on progressive strategy)
|
||||
// Priority: synthesis_output > guidance + relevant_role_analyses
|
||||
brainstorm_content: loadSelectiveBrainstormArtifacts(context_package),
|
||||
|
||||
// On-Demand (load if exists and relevant)
|
||||
test_context: loadIfExists(test_context_package_path),
|
||||
conflict_resolution: loadConflictResolution(context_package),
|
||||
|
||||
// Optional (if MCP available)
|
||||
exploration_results: extractExplorationResults(context_package),
|
||||
external_research: executeMcpResearch() // If needed
|
||||
}
|
||||
```
|
||||
|
||||
**Progressive Loading Implementation** (agent responsibility):
|
||||
1. **Check memory first** - skip if already loaded
|
||||
2. **Load core files** - session metadata + context-package.json
|
||||
3. **Smart selective loading** - synthesis_output OR (guidance + task-relevant role analyses)
|
||||
4. **On-demand loading** - test context, conflict resolution (if conflict_risk >= medium)
|
||||
5. **Extract references** - exploration results, artifact paths from context package
|
||||
|
||||
## TDD Task Structure Reference
|
||||
|
||||
This section provides quick reference for TDD task JSON structure. For complete implementation details, see the agent invocation prompt in Phase 2 above.
|
||||
|
||||
**Quick Reference**:
|
||||
- Each TDD task contains complete Red-Green-Refactor cycle
|
||||
- Task ID format: `IMPL-N` (simple) or `IMPL-N.M` (complex subtasks)
|
||||
- Required metadata:
|
||||
- `meta.tdd_workflow: true`
|
||||
- `meta.max_iterations: 3`
|
||||
- `meta.cli_execution_id: "{session_id}-{task_id}"`
|
||||
- `meta.cli_execution: { "strategy": "new|resume|fork|merge_fork", ... }`
|
||||
- Context: `tdd_cycles` array with quantified test cases and coverage:
|
||||
```javascript
|
||||
tdd_cycles: [
|
||||
{
|
||||
test_count: 5, // Number of test cases to write
|
||||
test_cases: ["case1", "case2"], // Enumerated test scenarios
|
||||
implementation_scope: "...", // Files and functions to implement
|
||||
expected_coverage: ">=85%" // Coverage target
|
||||
}
|
||||
]
|
||||
```
|
||||
- Context: `focus_paths` use absolute or clear relative paths
|
||||
- Flow control: Exactly 3 steps with `tdd_phase` field ("red", "green", "refactor")
|
||||
- Flow control: `pre_analysis` includes exploration integration_points analysis
|
||||
- **meta.execution_config**: Set per `userConfig.executionMethod` (agent/cli/hybrid)
|
||||
- See Phase 2 agent prompt for full schema and requirements
|
||||
|
||||
## Output Files Structure
|
||||
```
|
||||
.workflow/active/{session-id}/
|
||||
├── IMPL_PLAN.md # Unified plan with TDD Implementation Tasks section
|
||||
├── TODO_LIST.md # Progress tracking with internal TDD phase indicators
|
||||
├── .task/
|
||||
│ ├── IMPL-1.json # Complete TDD task (Red-Green-Refactor internally)
|
||||
│ ├── IMPL-2.json # Complete TDD task
|
||||
│ ├── IMPL-3.json # Complex feature container (if needed)
|
||||
│ ├── IMPL-3.1.json # Complex feature subtask (if needed)
|
||||
│ ├── IMPL-3.2.json # Complex feature subtask (if needed)
|
||||
│ └── ...
|
||||
└── .process/
|
||||
├── conflict-resolution.json # Conflict resolution results (if conflict_risk >= medium)
|
||||
├── test-context-package.json # Test coverage analysis
|
||||
├── context-package.json # Input from context-gather
|
||||
├── context_package_path # Path to smart context package
|
||||
└── green-fix-iteration-*.md # Fix logs from Green phase test-fix cycles
|
||||
```
|
||||
|
||||
**File Count**:
|
||||
- **Old approach**: 5 features = 15 task JSON files (TEST/IMPL/REFACTOR x 5)
|
||||
- **New approach**: 5 features = 5 task JSON files (IMPL-N x 5)
|
||||
- **Complex feature**: 1 feature = 1 container + M subtasks (IMPL-N + IMPL-N.M)
|
||||
|
||||
## Validation Rules
|
||||
|
||||
### Task Completeness
|
||||
- Every IMPL-N must contain complete TDD workflow in `flow_control.implementation_approach`
|
||||
- Each task must have 3 steps with `tdd_phase`: "red", "green", "refactor"
|
||||
- Every task must have `meta.tdd_workflow: true`
|
||||
|
||||
### Dependency Enforcement
|
||||
- Sequential features: IMPL-N depends_on ["IMPL-(N-1)"] if needed
|
||||
- Complex feature subtasks: IMPL-N.M depends_on ["IMPL-N.(M-1)"] or parent dependencies
|
||||
- No circular dependencies allowed
|
||||
|
||||
### Task Limits
|
||||
- Maximum 18 total tasks (simple + subtasks) - hard limit for TDD workflows
|
||||
- Flat hierarchy (<=5 tasks) or two-level (6-18 tasks with containers)
|
||||
- Re-scope requirements if >18 tasks needed
|
||||
|
||||
### TDD Workflow Validation
|
||||
- `meta.tdd_workflow` must be true
|
||||
- `flow_control.implementation_approach` must have exactly 3 steps
|
||||
- Each step must have `tdd_phase` field ("red", "green", or "refactor")
|
||||
- Green phase step must include test-fix cycle logic
|
||||
- `meta.max_iterations` must be present (default: 3)
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Input Validation Errors
|
||||
| Error | Cause | Resolution |
|
||||
|-------|-------|------------|
|
||||
| Session not found | Invalid session ID | Verify session exists |
|
||||
| Context missing | Incomplete planning | Run context-gather first |
|
||||
|
||||
### TDD Generation Errors
|
||||
| Error | Cause | Resolution |
|
||||
|-------|-------|------------|
|
||||
| Task count exceeds 18 | Too many features or subtasks | Re-scope requirements or merge features into multiple TDD sessions |
|
||||
| Missing test framework | No test config | Configure testing first |
|
||||
| Invalid TDD workflow | Missing tdd_phase or incomplete flow_control | Fix TDD structure in ANALYSIS_RESULTS.md |
|
||||
| Missing tdd_workflow flag | Task doesn't have meta.tdd_workflow: true | Add TDD workflow metadata |
|
||||
|
||||
## Integration
|
||||
|
||||
**Called By**: SKILL.md (Phase 5: TDD Task Generation)
|
||||
**Invokes**: `action-planning-agent` for autonomous task generation
|
||||
**Followed By**: Phase 6 (TDD Structure Validation in SKILL.md), then workflow:execute (external)
|
||||
|
||||
**CLI Tool Selection**: Determined semantically from user's task description. Include "use Codex/Gemini/Qwen" in your request for CLI execution.
|
||||
|
||||
**Output**:
|
||||
- TDD task JSON files in `.task/` directory (IMPL-N.json format)
|
||||
- IMPL_PLAN.md with TDD Implementation Tasks section
|
||||
- TODO_LIST.md with internal TDD phase indicators
|
||||
- Session state updated with task count and TDD metadata
|
||||
- MCP enhancements integrated (if available)
|
||||
|
||||
## Test Coverage Analysis Integration
|
||||
|
||||
The TDD workflow includes test coverage analysis (via phases/01-test-context-gather.md) to:
|
||||
- Detect existing test patterns and conventions
|
||||
- Identify current test coverage gaps
|
||||
- Discover test framework and configuration
|
||||
- Enable integration with existing tests
|
||||
|
||||
This makes TDD workflow context-aware instead of assuming greenfield scenarios.
|
||||
|
||||
## Iterative Green Phase with Test-Fix Cycle
|
||||
|
||||
IMPL (Green phase) tasks include automatic test-fix cycle:
|
||||
|
||||
**Process Flow**:
|
||||
1. **Initial Implementation**: Write minimal code to pass tests
|
||||
2. **Test Execution**: Run test suite
|
||||
3. **Success Path**: Tests pass → Complete task
|
||||
4. **Failure Path**: Tests fail → Enter iterative fix cycle:
|
||||
- **Gemini Diagnosis**: Analyze failures with bug-fix template
|
||||
- **Fix Application**: Agent executes fixes directly
|
||||
- **Retest**: Verify fix resolves failures
|
||||
- **Repeat**: Up to max_iterations (default: 3)
|
||||
5. **Safety Net**: Auto-revert all changes if max iterations reached
|
||||
|
||||
## Configuration Options
|
||||
- **meta.max_iterations**: Number of fix attempts in Green phase (default: 3)
|
||||
- **meta.execution_config.method**: Execution routing (agent/cli) determined from userConfig.executionMethod
|
||||
|
||||
---
|
||||
|
||||
## Post-Phase Update
|
||||
|
||||
After Phase 2 (TDD Task Generation) completes:
|
||||
- **Output Created**: IMPL_PLAN.md, TODO_LIST.md, IMPL-*.json task files in `.task/` directory
|
||||
- **TDD Structure**: Each task contains complete Red-Green-Refactor cycle internally
|
||||
- **CLI Execution IDs**: All tasks assigned unique cli_execution_id for resume support
|
||||
- **Next Action**: Phase 6 (TDD Structure Validation) in SKILL.md
|
||||
- **TodoWrite**: Collapse Phase 5 sub-tasks to "Phase 5: TDD Task Generation: completed"
|
||||
@@ -1,575 +0,0 @@
|
||||
# Phase 3: TDD Verify
|
||||
|
||||
## Goal
|
||||
|
||||
Verify TDD workflow execution quality by validating Red-Green-Refactor cycle compliance, test coverage completeness, and task chain structure integrity. This phase orchestrates multiple analysis steps and generates a comprehensive compliance report with quality gate recommendation.
|
||||
|
||||
**Output**: A structured Markdown report saved to `.workflow/active/WFS-{session}/TDD_COMPLIANCE_REPORT.md` containing:
|
||||
- Executive summary with compliance score and quality gate recommendation
|
||||
- Task chain validation (TEST → IMPL → REFACTOR structure)
|
||||
- Test coverage metrics (line, branch, function)
|
||||
- Red-Green-Refactor cycle verification
|
||||
- Best practices adherence assessment
|
||||
- Actionable improvement recommendations
|
||||
|
||||
## Operating Constraints
|
||||
|
||||
**ORCHESTRATOR MODE**:
|
||||
- This phase coordinates coverage analysis (`phases/04-tdd-coverage-analysis.md`) and internal validation
|
||||
- MAY write output files: TDD_COMPLIANCE_REPORT.md (primary report), .process/*.json (intermediate artifacts)
|
||||
- MUST NOT modify source task files or implementation code
|
||||
- MUST NOT create or delete tasks in the workflow
|
||||
|
||||
**Quality Gate Authority**: The compliance report provides a binding recommendation (BLOCK_MERGE / REQUIRE_FIXES / PROCEED_WITH_CAVEATS / APPROVED) based on objective compliance criteria.
|
||||
|
||||
## Core Responsibilities
|
||||
- Verify TDD task chain structure (TEST → IMPL → REFACTOR)
|
||||
- Analyze test coverage metrics
|
||||
- Validate TDD cycle execution quality
|
||||
- Generate compliance report with quality gate recommendation
|
||||
|
||||
## Execution Process
|
||||
|
||||
```
|
||||
Input Parsing:
|
||||
└─ Decision (session argument):
|
||||
├─ --session provided → Use provided session
|
||||
└─ No session → Auto-detect active session
|
||||
|
||||
Phase 1: Session Discovery & Validation
|
||||
├─ Detect or validate session directory
|
||||
├─ Check required artifacts exist (.task/*.json, .summaries/*)
|
||||
└─ ERROR if invalid or incomplete
|
||||
|
||||
Phase 2: Task Chain Structure Validation
|
||||
├─ Load all task JSONs from .task/
|
||||
├─ Validate TDD structure: TEST-N.M → IMPL-N.M → REFACTOR-N.M
|
||||
├─ Verify dependencies (depends_on)
|
||||
├─ Validate meta fields (tdd_phase, agent)
|
||||
└─ Extract chain validation data
|
||||
|
||||
Phase 3: Coverage & Cycle Analysis
|
||||
├─ Read and execute: phases/04-tdd-coverage-analysis.md
|
||||
├─ Parse: test-results.json, coverage-report.json, tdd-cycle-report.md
|
||||
└─ Extract coverage metrics and TDD cycle verification
|
||||
|
||||
Phase 4: Compliance Report Generation
|
||||
├─ Aggregate findings from Phases 1-3
|
||||
├─ Calculate compliance score (0-100)
|
||||
├─ Determine quality gate recommendation
|
||||
├─ Generate TDD_COMPLIANCE_REPORT.md
|
||||
└─ Display summary to user
|
||||
```
|
||||
|
||||
## 4-Phase Execution
|
||||
|
||||
### Phase 1: Session Discovery & Validation
|
||||
|
||||
**Step 1.1: Detect Session**
|
||||
```bash
|
||||
IF --session parameter provided:
|
||||
session_id = provided session
|
||||
ELSE:
|
||||
# Auto-detect active session
|
||||
active_sessions = bash(find .workflow/active/ -name "WFS-*" -type d 2>/dev/null)
|
||||
IF active_sessions is empty:
|
||||
ERROR: "No active workflow session found. Use --session <session-id>"
|
||||
EXIT
|
||||
ELSE IF active_sessions has multiple entries:
|
||||
# Use most recently modified session
|
||||
session_id = bash(ls -td .workflow/active/WFS-*/ 2>/dev/null | head -1 | xargs basename)
|
||||
ELSE:
|
||||
session_id = basename(active_sessions[0])
|
||||
|
||||
# Derive paths
|
||||
session_dir = .workflow/active/WFS-{session_id}
|
||||
task_dir = session_dir/.task
|
||||
summaries_dir = session_dir/.summaries
|
||||
process_dir = session_dir/.process
|
||||
```
|
||||
|
||||
**Step 1.2: Validate Required Artifacts**
|
||||
```bash
|
||||
# Check task files exist
|
||||
task_files = Glob(task_dir/*.json)
|
||||
IF task_files.count == 0:
|
||||
ERROR: "No task JSON files found. Run TDD planning (SKILL.md) first"
|
||||
EXIT
|
||||
|
||||
# Check summaries exist (optional but recommended for full analysis)
|
||||
summaries_exist = EXISTS(summaries_dir)
|
||||
IF NOT summaries_exist:
|
||||
WARNING: "No .summaries/ directory found. Some analysis may be limited."
|
||||
```
|
||||
|
||||
**Output**: session_id, session_dir, task_files list
|
||||
|
||||
---
|
||||
|
||||
### Phase 2: Task Chain Structure Validation
|
||||
|
||||
**Step 2.1: Load and Parse Task JSONs**
|
||||
```bash
|
||||
# Single-pass JSON extraction using jq
|
||||
validation_data = bash("""
|
||||
# Load all tasks and extract structured data
|
||||
cd '{session_dir}/.task'
|
||||
|
||||
# Extract all task IDs
|
||||
task_ids=$(jq -r '.id' *.json 2>/dev/null | sort)
|
||||
|
||||
# Extract dependencies for IMPL tasks
|
||||
impl_deps=$(jq -r 'select(.id | startswith("IMPL")) | .id + ":" + (.context.depends_on[]? // "none")' *.json 2>/dev/null)
|
||||
|
||||
# Extract dependencies for REFACTOR tasks
|
||||
refactor_deps=$(jq -r 'select(.id | startswith("REFACTOR")) | .id + ":" + (.context.depends_on[]? // "none")' *.json 2>/dev/null)
|
||||
|
||||
# Extract meta fields
|
||||
meta_tdd=$(jq -r '.id + ":" + (.meta.tdd_phase // "missing")' *.json 2>/dev/null)
|
||||
meta_agent=$(jq -r '.id + ":" + (.meta.agent // "missing")' *.json 2>/dev/null)
|
||||
|
||||
# Output as JSON
|
||||
jq -n --arg ids "$task_ids" \
|
||||
--arg impl "$impl_deps" \
|
||||
--arg refactor "$refactor_deps" \
|
||||
--arg tdd "$meta_tdd" \
|
||||
--arg agent "$meta_agent" \
|
||||
'{ids: $ids, impl_deps: $impl, refactor_deps: $refactor, tdd: $tdd, agent: $agent}'
|
||||
""")
|
||||
```
|
||||
|
||||
**Step 2.2: Validate TDD Chain Structure**
|
||||
```
|
||||
Parse validation_data JSON and validate:
|
||||
|
||||
For each feature N (extracted from task IDs):
|
||||
1. TEST-N.M exists?
|
||||
2. IMPL-N.M exists?
|
||||
3. REFACTOR-N.M exists? (optional but recommended)
|
||||
4. IMPL-N.M.context.depends_on contains TEST-N.M?
|
||||
5. REFACTOR-N.M.context.depends_on contains IMPL-N.M?
|
||||
6. TEST-N.M.meta.tdd_phase == "red"?
|
||||
7. TEST-N.M.meta.agent == "@code-review-test-agent"?
|
||||
8. IMPL-N.M.meta.tdd_phase == "green"?
|
||||
9. IMPL-N.M.meta.agent == "@code-developer"?
|
||||
10. REFACTOR-N.M.meta.tdd_phase == "refactor"?
|
||||
|
||||
Calculate:
|
||||
- chain_completeness_score = (complete_chains / total_chains) * 100
|
||||
- dependency_accuracy = (correct_deps / total_deps) * 100
|
||||
- meta_field_accuracy = (correct_meta / total_meta) * 100
|
||||
```
|
||||
|
||||
**Output**: chain_validation_report (JSON structure with validation results)
|
||||
|
||||
---
|
||||
|
||||
### Phase 3: Coverage & Cycle Analysis
|
||||
|
||||
**Step 3.1: Call Coverage Analysis Phase**
|
||||
|
||||
Read and execute the coverage analysis phase:
|
||||
- **Phase file**: `phases/04-tdd-coverage-analysis.md`
|
||||
- **Args**: `--session {session_id}`
|
||||
|
||||
**Step 3.2: Parse Output Files**
|
||||
```bash
|
||||
# Check required outputs exist
|
||||
IF NOT EXISTS(process_dir/test-results.json):
|
||||
WARNING: "test-results.json not found. Coverage analysis incomplete."
|
||||
coverage_data = null
|
||||
ELSE:
|
||||
coverage_data = Read(process_dir/test-results.json)
|
||||
|
||||
IF NOT EXISTS(process_dir/coverage-report.json):
|
||||
WARNING: "coverage-report.json not found. Coverage metrics incomplete."
|
||||
metrics = null
|
||||
ELSE:
|
||||
metrics = Read(process_dir/coverage-report.json)
|
||||
|
||||
IF NOT EXISTS(process_dir/tdd-cycle-report.md):
|
||||
WARNING: "tdd-cycle-report.md not found. Cycle validation incomplete."
|
||||
cycle_data = null
|
||||
ELSE:
|
||||
cycle_data = Read(process_dir/tdd-cycle-report.md)
|
||||
```
|
||||
|
||||
**Step 3.3: Extract Coverage Metrics**
|
||||
```
|
||||
If coverage_data exists:
|
||||
- line_coverage_percent
|
||||
- branch_coverage_percent
|
||||
- function_coverage_percent
|
||||
- uncovered_files (list)
|
||||
- uncovered_lines (map: file -> line ranges)
|
||||
|
||||
If cycle_data exists:
|
||||
- red_phase_compliance (tests failed initially?)
|
||||
- green_phase_compliance (tests pass after impl?)
|
||||
- refactor_phase_compliance (tests stay green during refactor?)
|
||||
- minimal_implementation_score (was impl minimal?)
|
||||
```
|
||||
|
||||
**Output**: coverage_analysis, cycle_analysis
|
||||
|
||||
---
|
||||
|
||||
### Phase 4: Compliance Report Generation
|
||||
|
||||
**Step 4.1: Calculate Compliance Score**
|
||||
```
|
||||
Base Score: 100 points
|
||||
|
||||
Deductions:
|
||||
Chain Structure:
|
||||
- Missing TEST task: -30 points per feature
|
||||
- Missing IMPL task: -30 points per feature
|
||||
- Missing REFACTOR task: -10 points per feature
|
||||
- Wrong dependency: -15 points per error
|
||||
- Wrong agent: -5 points per error
|
||||
- Wrong tdd_phase: -5 points per error
|
||||
|
||||
TDD Cycle Compliance:
|
||||
- Test didn't fail initially: -10 points per feature
|
||||
- Tests didn't pass after IMPL: -20 points per feature
|
||||
- Tests broke during REFACTOR: -15 points per feature
|
||||
- Over-engineered IMPL: -10 points per feature
|
||||
|
||||
Coverage Quality:
|
||||
- Line coverage < 80%: -5 points
|
||||
- Branch coverage < 70%: -5 points
|
||||
- Function coverage < 80%: -5 points
|
||||
- Critical paths uncovered: -10 points
|
||||
|
||||
Final Score: Max(0, Base Score - Total Deductions)
|
||||
```
|
||||
|
||||
**Step 4.2: Determine Quality Gate**
|
||||
```
|
||||
IF score >= 90 AND no_critical_violations:
|
||||
recommendation = "APPROVED"
|
||||
ELSE IF score >= 70 AND critical_violations == 0:
|
||||
recommendation = "PROCEED_WITH_CAVEATS"
|
||||
ELSE IF score >= 50:
|
||||
recommendation = "REQUIRE_FIXES"
|
||||
ELSE:
|
||||
recommendation = "BLOCK_MERGE"
|
||||
```
|
||||
|
||||
**Step 4.3: Generate Report**
|
||||
```bash
|
||||
report_content = Generate markdown report (see structure below)
|
||||
report_path = "{session_dir}/TDD_COMPLIANCE_REPORT.md"
|
||||
Write(report_path, report_content)
|
||||
```
|
||||
|
||||
**Step 4.4: Display Summary to User**
|
||||
```bash
|
||||
echo "=== TDD Verification Complete ==="
|
||||
echo "Session: {session_id}"
|
||||
echo "Report: {report_path}"
|
||||
echo ""
|
||||
echo "Quality Gate: {recommendation}"
|
||||
echo "Compliance Score: {score}/100"
|
||||
echo ""
|
||||
echo "Chain Validation: {chain_completeness_score}%"
|
||||
echo "Line Coverage: {line_coverage}%"
|
||||
echo "Branch Coverage: {branch_coverage}%"
|
||||
echo ""
|
||||
echo "Next: Review full report for detailed findings"
|
||||
```
|
||||
|
||||
## TodoWrite Pattern (Optional)
|
||||
|
||||
**Note**: As an orchestrator phase, TodoWrite tracking is optional and primarily useful for long-running verification processes. For most cases, the 4-phase execution is fast enough that progress tracking adds noise without value.
|
||||
|
||||
```javascript
|
||||
// Only use TodoWrite for complex multi-session verification
|
||||
// Skip for single-session verification
|
||||
```
|
||||
|
||||
## Validation Logic
|
||||
|
||||
### Chain Validation Algorithm
|
||||
```
|
||||
1. Load all task JSONs from .workflow/active/{sessionId}/.task/
|
||||
2. Extract task IDs and group by feature number
|
||||
3. For each feature:
|
||||
- Check TEST-N.M exists
|
||||
- Check IMPL-N.M exists
|
||||
- Check REFACTOR-N.M exists (optional but recommended)
|
||||
- Verify IMPL-N.M depends_on TEST-N.M
|
||||
- Verify REFACTOR-N.M depends_on IMPL-N.M
|
||||
- Verify meta.tdd_phase values
|
||||
- Verify meta.agent assignments
|
||||
4. Calculate chain completeness score
|
||||
5. Report incomplete or invalid chains
|
||||
```
|
||||
|
||||
### Quality Gate Criteria
|
||||
|
||||
| Recommendation | Score Range | Critical Violations | Action |
|
||||
|----------------|-------------|---------------------|--------|
|
||||
| **APPROVED** | ≥90 | 0 | Safe to merge |
|
||||
| **PROCEED_WITH_CAVEATS** | ≥70 | 0 | Can proceed, address minor issues |
|
||||
| **REQUIRE_FIXES** | ≥50 | Any | Must fix before merge |
|
||||
| **BLOCK_MERGE** | <50 | Any | Block merge until resolved |
|
||||
|
||||
**Critical Violations**:
|
||||
- Missing TEST or IMPL task for any feature
|
||||
- Tests didn't fail initially (Red phase violation)
|
||||
- Tests didn't pass after IMPL (Green phase violation)
|
||||
- Tests broke during REFACTOR (Refactor phase violation)
|
||||
|
||||
## Output Files
|
||||
```
|
||||
.workflow/active/WFS-{session-id}/
|
||||
├── TDD_COMPLIANCE_REPORT.md # Comprehensive compliance report
|
||||
└── .process/
|
||||
├── test-results.json # From phases/04-tdd-coverage-analysis.md
|
||||
├── coverage-report.json # From phases/04-tdd-coverage-analysis.md
|
||||
└── tdd-cycle-report.md # From phases/04-tdd-coverage-analysis.md
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Session Discovery Errors
|
||||
| Error | Cause | Resolution |
|
||||
|-------|-------|------------|
|
||||
| No active session | No WFS-* directories | Provide --session explicitly |
|
||||
| Multiple active sessions | Multiple WFS-* directories | Provide --session explicitly |
|
||||
| Session not found | Invalid session-id | Check available sessions |
|
||||
|
||||
### Validation Errors
|
||||
| Error | Cause | Resolution |
|
||||
|-------|-------|------------|
|
||||
| Task files missing | Incomplete planning | Run TDD planning (SKILL.md) first |
|
||||
| Invalid JSON | Corrupted task files | Regenerate tasks |
|
||||
| Missing summaries | Tasks not executed | Execute tasks before verify |
|
||||
|
||||
### Analysis Errors
|
||||
| Error | Cause | Resolution |
|
||||
|-------|-------|------------|
|
||||
| Coverage tool missing | No test framework | Configure testing first |
|
||||
| Tests fail to run | Code errors | Fix errors before verify |
|
||||
| Coverage analysis fails | phases/04-tdd-coverage-analysis.md error | Check analysis output |
|
||||
|
||||
## Integration
|
||||
|
||||
### Phase Chain
|
||||
- **Called After**: Task execution completes (all TDD tasks done)
|
||||
- **Calls**: `phases/04-tdd-coverage-analysis.md`
|
||||
- **Related Skills**: SKILL.md (orchestrator), `workflow-plan/` (session management)
|
||||
|
||||
### When to Use
|
||||
- After completing all TDD tasks in a workflow
|
||||
- Before merging TDD workflow branch
|
||||
- For TDD process quality assessment
|
||||
- To identify missing TDD steps
|
||||
|
||||
## TDD Compliance Report Structure
|
||||
|
||||
```markdown
|
||||
# TDD Compliance Report - {Session ID}
|
||||
|
||||
**Generated**: {timestamp}
|
||||
**Session**: WFS-{sessionId}
|
||||
**Workflow Type**: TDD
|
||||
|
||||
---
|
||||
|
||||
## Executive Summary
|
||||
|
||||
### Quality Gate Decision
|
||||
|
||||
| Metric | Value | Status |
|
||||
|--------|-------|--------|
|
||||
| Compliance Score | {score}/100 | {status_emoji} |
|
||||
| Chain Completeness | {percentage}% | {status} |
|
||||
| Line Coverage | {percentage}% | {status} |
|
||||
| Branch Coverage | {percentage}% | {status} |
|
||||
| Function Coverage | {percentage}% | {status} |
|
||||
|
||||
### Recommendation
|
||||
|
||||
**{RECOMMENDATION}**
|
||||
|
||||
**Decision Rationale**:
|
||||
{brief explanation based on score and violations}
|
||||
|
||||
**Quality Gate Criteria**:
|
||||
- **APPROVED**: Score ≥90, no critical violations
|
||||
- **PROCEED_WITH_CAVEATS**: Score ≥70, no critical violations
|
||||
- **REQUIRE_FIXES**: Score ≥50 or critical violations exist
|
||||
- **BLOCK_MERGE**: Score <50
|
||||
|
||||
---
|
||||
|
||||
## Chain Analysis
|
||||
|
||||
### Feature 1: {Feature Name}
|
||||
**Status**: Complete
|
||||
**Chain**: TEST-1.1 → IMPL-1.1 → REFACTOR-1.1
|
||||
|
||||
| Phase | Task | Status | Details |
|
||||
|-------|------|--------|---------|
|
||||
| Red | TEST-1.1 | Pass | Test created and failed with clear message |
|
||||
| Green | IMPL-1.1 | Pass | Minimal implementation made test pass |
|
||||
| Refactor | REFACTOR-1.1 | Pass | Code improved, tests remained green |
|
||||
|
||||
### Feature 2: {Feature Name}
|
||||
**Status**: Incomplete
|
||||
**Chain**: TEST-2.1 → IMPL-2.1 (Missing REFACTOR-2.1)
|
||||
|
||||
| Phase | Task | Status | Details |
|
||||
|-------|------|--------|---------|
|
||||
| Red | TEST-2.1 | Pass | Test created and failed |
|
||||
| Green | IMPL-2.1 | Warning | Implementation seems over-engineered |
|
||||
| Refactor | REFACTOR-2.1 | Missing | Task not completed |
|
||||
|
||||
**Issues**:
|
||||
- REFACTOR-2.1 task not completed (-10 points)
|
||||
- IMPL-2.1 implementation exceeded minimal scope (-10 points)
|
||||
|
||||
### Chain Validation Summary
|
||||
|
||||
| Metric | Value |
|
||||
|--------|-------|
|
||||
| Total Features | {count} |
|
||||
| Complete Chains | {count} ({percent}%) |
|
||||
| Incomplete Chains | {count} |
|
||||
| Missing TEST | {count} |
|
||||
| Missing IMPL | {count} |
|
||||
| Missing REFACTOR | {count} |
|
||||
| Dependency Errors | {count} |
|
||||
| Meta Field Errors | {count} |
|
||||
|
||||
---
|
||||
|
||||
## Test Coverage Analysis
|
||||
|
||||
### Coverage Metrics
|
||||
|
||||
| Metric | Coverage | Target | Status |
|
||||
|--------|----------|--------|--------|
|
||||
| Line Coverage | {percentage}% | ≥80% | {status} |
|
||||
| Branch Coverage | {percentage}% | ≥70% | {status} |
|
||||
| Function Coverage | {percentage}% | ≥80% | {status} |
|
||||
|
||||
### Coverage Gaps
|
||||
|
||||
| File | Lines | Issue | Priority |
|
||||
|------|-------|-------|----------|
|
||||
| src/auth/service.ts | 45-52 | Uncovered error handling | HIGH |
|
||||
| src/utils/parser.ts | 78-85 | Uncovered edge case | MEDIUM |
|
||||
|
||||
---
|
||||
|
||||
## TDD Cycle Validation
|
||||
|
||||
### Red Phase (Write Failing Test)
|
||||
- {N}/{total} features had failing tests initially ({percent}%)
|
||||
- Compliant features: {list}
|
||||
- Non-compliant features: {list}
|
||||
|
||||
**Violations**:
|
||||
- Feature 3: No evidence of initial test failure (-10 points)
|
||||
|
||||
### Green Phase (Make Test Pass)
|
||||
- {N}/{total} implementations made tests pass ({percent}%)
|
||||
- Compliant features: {list}
|
||||
- Non-compliant features: {list}
|
||||
|
||||
**Violations**:
|
||||
- Feature 2: Implementation over-engineered (-10 points)
|
||||
|
||||
### Refactor Phase (Improve Quality)
|
||||
- {N}/{total} features completed refactoring ({percent}%)
|
||||
- Compliant features: {list}
|
||||
- Non-compliant features: {list}
|
||||
|
||||
**Violations**:
|
||||
- Feature 2, 4: Refactoring step skipped (-20 points total)
|
||||
|
||||
---
|
||||
|
||||
## Best Practices Assessment
|
||||
|
||||
### Strengths
|
||||
- Clear test descriptions
|
||||
- Good test coverage
|
||||
- Consistent naming conventions
|
||||
- Well-structured code
|
||||
|
||||
### Areas for Improvement
|
||||
- Some implementations over-engineered in Green phase
|
||||
- Missing refactoring steps
|
||||
- Test failure messages could be more descriptive
|
||||
|
||||
---
|
||||
|
||||
## Detailed Findings by Severity
|
||||
|
||||
### Critical Issues ({count})
|
||||
{List of critical issues with impact and remediation}
|
||||
|
||||
### High Priority Issues ({count})
|
||||
{List of high priority issues with impact and remediation}
|
||||
|
||||
### Medium Priority Issues ({count})
|
||||
{List of medium priority issues with impact and remediation}
|
||||
|
||||
### Low Priority Issues ({count})
|
||||
{List of low priority issues with impact and remediation}
|
||||
|
||||
---
|
||||
|
||||
## Recommendations
|
||||
|
||||
### Required Fixes (Before Merge)
|
||||
1. Complete missing REFACTOR tasks (Features 2, 4)
|
||||
2. Verify initial test failures for Feature 3
|
||||
3. Fix tests that broke during refactoring
|
||||
|
||||
### Recommended Improvements
|
||||
1. Simplify over-engineered implementations
|
||||
2. Add edge case tests for Features 1, 3
|
||||
3. Improve test failure message clarity
|
||||
4. Increase branch coverage to >85%
|
||||
|
||||
### Optional Enhancements
|
||||
1. Add more descriptive test names
|
||||
2. Consider parameterized tests for similar scenarios
|
||||
3. Document TDD process learnings
|
||||
|
||||
---
|
||||
|
||||
## Metrics Summary
|
||||
|
||||
| Metric | Value |
|
||||
|--------|-------|
|
||||
| Total Features | {count} |
|
||||
| Complete Chains | {count} ({percent}%) |
|
||||
| Compliance Score | {score}/100 |
|
||||
| Critical Issues | {count} |
|
||||
| High Issues | {count} |
|
||||
| Medium Issues | {count} |
|
||||
| Low Issues | {count} |
|
||||
| Line Coverage | {percent}% |
|
||||
| Branch Coverage | {percent}% |
|
||||
| Function Coverage | {percent}% |
|
||||
|
||||
---
|
||||
|
||||
**Report End**
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Post-Phase Update
|
||||
|
||||
After TDD Verify completes:
|
||||
- **Output Created**: `TDD_COMPLIANCE_REPORT.md` in session directory
|
||||
- **Data Produced**: Compliance score, quality gate recommendation, chain validation, coverage metrics
|
||||
- **Next Action**: Based on quality gate - APPROVED (merge), REQUIRE_FIXES (iterate), BLOCK_MERGE (rework)
|
||||
- **TodoWrite**: Mark "TDD Verify: completed" with quality gate result
|
||||
@@ -1,287 +0,0 @@
|
||||
# Phase 4: TDD Coverage Analysis
|
||||
|
||||
## Overview
|
||||
Analyze test coverage and verify Red-Green-Refactor cycle execution for TDD workflow validation.
|
||||
|
||||
## Core Responsibilities
|
||||
- Extract test files from TEST tasks
|
||||
- Run test suite with coverage
|
||||
- Parse coverage metrics
|
||||
- Verify TDD cycle execution (Red -> Green -> Refactor)
|
||||
- Generate coverage and cycle reports
|
||||
|
||||
## Execution Process
|
||||
|
||||
```
|
||||
Input Parsing:
|
||||
├─ Parse flags: --session
|
||||
└─ Validation: session_id REQUIRED
|
||||
|
||||
Phase 1: Extract Test Tasks
|
||||
└─ Find TEST-*.json files and extract focus_paths
|
||||
|
||||
Phase 2: Run Test Suite
|
||||
└─ Decision (test framework):
|
||||
├─ Node.js → npm test --coverage --json
|
||||
├─ Python → pytest --cov --json-report
|
||||
└─ Other → [test_command] --coverage --json
|
||||
|
||||
Phase 3: Parse Coverage Data
|
||||
├─ Extract line coverage percentage
|
||||
├─ Extract branch coverage percentage
|
||||
├─ Extract function coverage percentage
|
||||
└─ Identify uncovered lines/branches
|
||||
|
||||
Phase 4: Verify TDD Cycle
|
||||
└─ FOR each TDD chain (TEST-N.M → IMPL-N.M → REFACTOR-N.M):
|
||||
├─ Red Phase: Verify tests created and failed initially
|
||||
├─ Green Phase: Verify tests now pass
|
||||
└─ Refactor Phase: Verify code quality improved
|
||||
|
||||
Phase 5: Generate Analysis Report
|
||||
└─ Create tdd-cycle-report.md with coverage metrics and cycle verification
|
||||
```
|
||||
|
||||
## Execution Lifecycle
|
||||
|
||||
### Phase 1: Extract Test Tasks
|
||||
```bash
|
||||
find .workflow/active/{session_id}/.task/ -name 'TEST-*.json' -exec jq -r '.context.focus_paths[]' {} \;
|
||||
```
|
||||
|
||||
**Output**: List of test directories/files from all TEST tasks
|
||||
|
||||
### Phase 2: Run Test Suite
|
||||
```bash
|
||||
# Node.js/JavaScript
|
||||
npm test -- --coverage --json > .workflow/active/{session_id}/.process/test-results.json
|
||||
|
||||
# Python
|
||||
pytest --cov --json-report > .workflow/active/{session_id}/.process/test-results.json
|
||||
|
||||
# Other frameworks (detect from project)
|
||||
[test_command] --coverage --json-output .workflow/active/{session_id}/.process/test-results.json
|
||||
```
|
||||
|
||||
**Output**: test-results.json with coverage data
|
||||
|
||||
### Phase 3: Parse Coverage Data
|
||||
```bash
|
||||
jq '.coverage' .workflow/active/{session_id}/.process/test-results.json > .workflow/active/{session_id}/.process/coverage-report.json
|
||||
```
|
||||
|
||||
**Extract**:
|
||||
- Line coverage percentage
|
||||
- Branch coverage percentage
|
||||
- Function coverage percentage
|
||||
- Uncovered lines/branches
|
||||
|
||||
### Phase 4: Verify TDD Cycle
|
||||
|
||||
For each TDD chain (TEST-N.M -> IMPL-N.M -> REFACTOR-N.M):
|
||||
|
||||
**1. Red Phase Verification**
|
||||
```bash
|
||||
# Check TEST task summary
|
||||
cat .workflow/active/{session_id}/.summaries/TEST-N.M-summary.md
|
||||
```
|
||||
|
||||
Verify:
|
||||
- Tests were created
|
||||
- Tests failed initially
|
||||
- Failure messages were clear
|
||||
|
||||
**2. Green Phase Verification**
|
||||
```bash
|
||||
# Check IMPL task summary
|
||||
cat .workflow/active/{session_id}/.summaries/IMPL-N.M-summary.md
|
||||
```
|
||||
|
||||
Verify:
|
||||
- Implementation was completed
|
||||
- Tests now pass
|
||||
- Implementation was minimal
|
||||
|
||||
**3. Refactor Phase Verification**
|
||||
```bash
|
||||
# Check REFACTOR task summary
|
||||
cat .workflow/active/{session_id}/.summaries/REFACTOR-N.M-summary.md
|
||||
```
|
||||
|
||||
Verify:
|
||||
- Refactoring was completed
|
||||
- Tests still pass
|
||||
- Code quality improved
|
||||
|
||||
### Phase 5: Generate Analysis Report
|
||||
|
||||
Create `.workflow/active/{session_id}/.process/tdd-cycle-report.md`:
|
||||
|
||||
```markdown
|
||||
# TDD Cycle Analysis - {Session ID}
|
||||
|
||||
## Coverage Metrics
|
||||
- **Line Coverage**: {percentage}%
|
||||
- **Branch Coverage**: {percentage}%
|
||||
- **Function Coverage**: {percentage}%
|
||||
|
||||
## Coverage Details
|
||||
### Covered
|
||||
- {covered_lines} lines
|
||||
- {covered_branches} branches
|
||||
- {covered_functions} functions
|
||||
|
||||
### Uncovered
|
||||
- Lines: {uncovered_line_numbers}
|
||||
- Branches: {uncovered_branch_locations}
|
||||
|
||||
## TDD Cycle Verification
|
||||
|
||||
### Feature 1: {Feature Name}
|
||||
**Chain**: TEST-1.1 -> IMPL-1.1 -> REFACTOR-1.1
|
||||
|
||||
- [PASS] **Red Phase**: Tests created and failed initially
|
||||
- [PASS] **Green Phase**: Implementation made tests pass
|
||||
- [PASS] **Refactor Phase**: Refactoring maintained green tests
|
||||
|
||||
### Feature 2: {Feature Name}
|
||||
**Chain**: TEST-2.1 -> IMPL-2.1 -> REFACTOR-2.1
|
||||
|
||||
- [PASS] **Red Phase**: Tests created and failed initially
|
||||
- [WARN] **Green Phase**: Tests pass but implementation seems over-engineered
|
||||
- [PASS] **Refactor Phase**: Refactoring maintained green tests
|
||||
|
||||
[Repeat for all features]
|
||||
|
||||
## TDD Compliance Summary
|
||||
- **Total Chains**: {N}
|
||||
- **Complete Cycles**: {N}
|
||||
- **Incomplete Cycles**: {0}
|
||||
- **Compliance Score**: {score}/100
|
||||
|
||||
## Gaps Identified
|
||||
- Feature 3: Missing initial test failure verification
|
||||
- Feature 5: No refactoring step completed
|
||||
|
||||
## Recommendations
|
||||
- Complete missing refactoring steps
|
||||
- Add edge case tests for Feature 2
|
||||
- Verify test failure messages are descriptive
|
||||
```
|
||||
|
||||
## Output Files
|
||||
```
|
||||
.workflow/active/{session-id}/
|
||||
└── .process/
|
||||
├── test-results.json # Raw test execution results
|
||||
├── coverage-report.json # Parsed coverage data
|
||||
└── tdd-cycle-report.md # TDD cycle analysis
|
||||
```
|
||||
|
||||
## Test Framework Detection
|
||||
|
||||
Auto-detect test framework from project:
|
||||
|
||||
```bash
|
||||
# Check for test frameworks
|
||||
if [ -f "package.json" ] && grep -q "jest\|mocha\|vitest" package.json; then
|
||||
TEST_CMD="npm test -- --coverage --json"
|
||||
elif [ -f "pytest.ini" ] || [ -f "setup.py" ]; then
|
||||
TEST_CMD="pytest --cov --json-report"
|
||||
elif [ -f "Cargo.toml" ]; then
|
||||
TEST_CMD="cargo test -- --test-threads=1 --nocapture"
|
||||
elif [ -f "go.mod" ]; then
|
||||
TEST_CMD="go test -coverprofile=coverage.out -json ./..."
|
||||
else
|
||||
TEST_CMD="echo 'No supported test framework found'"
|
||||
fi
|
||||
```
|
||||
|
||||
## TDD Cycle Verification Algorithm
|
||||
|
||||
```
|
||||
For each feature N:
|
||||
1. Load TEST-N.M-summary.md
|
||||
IF summary missing:
|
||||
Mark: "Red phase incomplete"
|
||||
SKIP to next feature
|
||||
|
||||
CHECK: Contains "test" AND "fail"
|
||||
IF NOT found:
|
||||
Mark: "Red phase verification failed"
|
||||
ELSE:
|
||||
Mark: "Red phase [PASS]"
|
||||
|
||||
2. Load IMPL-N.M-summary.md
|
||||
IF summary missing:
|
||||
Mark: "Green phase incomplete"
|
||||
SKIP to next feature
|
||||
|
||||
CHECK: Contains "pass" OR "green"
|
||||
IF NOT found:
|
||||
Mark: "Green phase verification failed"
|
||||
ELSE:
|
||||
Mark: "Green phase [PASS]"
|
||||
|
||||
3. Load REFACTOR-N.M-summary.md
|
||||
IF summary missing:
|
||||
Mark: "Refactor phase incomplete"
|
||||
CONTINUE (refactor is optional)
|
||||
|
||||
CHECK: Contains "refactor" AND "pass"
|
||||
IF NOT found:
|
||||
Mark: "Refactor phase verification failed"
|
||||
ELSE:
|
||||
Mark: "Refactor phase [PASS]"
|
||||
|
||||
4. Calculate chain score:
|
||||
- Red + Green + Refactor all [PASS] = 100%
|
||||
- Red + Green [PASS], Refactor missing = 80%
|
||||
- Red [PASS], Green missing = 40%
|
||||
- All missing = 0%
|
||||
```
|
||||
|
||||
## Coverage Metrics Calculation
|
||||
|
||||
```bash
|
||||
# Parse coverage from test-results.json
|
||||
line_coverage=$(jq '.coverage.lineCoverage' test-results.json)
|
||||
branch_coverage=$(jq '.coverage.branchCoverage' test-results.json)
|
||||
function_coverage=$(jq '.coverage.functionCoverage' test-results.json)
|
||||
|
||||
# Calculate overall score
|
||||
overall_score=$(echo "($line_coverage + $branch_coverage + $function_coverage) / 3" | bc)
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Test Execution Errors
|
||||
| Error | Cause | Resolution |
|
||||
|-------|-------|------------|
|
||||
| Test framework not found | No test config | Configure test framework first |
|
||||
| Tests fail to run | Syntax errors | Fix code before analysis |
|
||||
| Coverage not available | Missing coverage tool | Install coverage plugin |
|
||||
|
||||
### Cycle Verification Errors
|
||||
| Error | Cause | Resolution |
|
||||
|-------|-------|------------|
|
||||
| Summary missing | Task not executed | Execute tasks before analysis |
|
||||
| Invalid summary format | Corrupted file | Re-run task to regenerate |
|
||||
| No test evidence | Tests not committed | Ensure tests are committed |
|
||||
|
||||
## Integration
|
||||
|
||||
### Phase Chain
|
||||
- **Called By**: `phases/03-tdd-verify.md` (Coverage & Cycle Analysis step)
|
||||
- **Calls**: Test framework commands (npm test, pytest, etc.)
|
||||
- **Followed By**: Compliance report generation in `phases/03-tdd-verify.md`
|
||||
|
||||
---
|
||||
|
||||
## Post-Phase Update
|
||||
|
||||
After TDD Coverage Analysis completes:
|
||||
- **Output Created**: `test-results.json`, `coverage-report.json`, `tdd-cycle-report.md` in `.process/`
|
||||
- **Data Produced**: Coverage metrics (line/branch/function), TDD cycle verification results per feature
|
||||
- **Next Action**: Return data to `phases/03-tdd-verify.md` for compliance report aggregation
|
||||
- **TodoWrite**: Mark "Coverage & Cycle Analysis: completed"
|
||||
Reference in New Issue
Block a user