feat: Implement workflow phases for test generation and execution

- Added Phase 1: Session Start to detect input mode and create test workflow session.
- Added Phase 2: Test Context Gather to gather test context via coverage analysis or codebase scan.
- Added Phase 3: Test Concept Enhanced to analyze test requirements using Gemini and generate multi-layered test requirements.
- Added Phase 4: Test Task Generate to create test-specific tasks based on analysis results.
- Added Phase 5: Test Cycle Execute to manage iterative test execution and fix cycles with adaptive strategies.
- Introduced BottomPanel component for terminal dashboard with Queue and Inspector tabs.
This commit is contained in:
catlog22
2026-02-14 21:35:55 +08:00
parent 0d805efe87
commit d535ab4749
27 changed files with 2004 additions and 2363 deletions

View File

@@ -0,0 +1,459 @@
---
name: workflow-tdd
description: Unified TDD workflow skill combining 6-phase TDD planning with Red-Green-Refactor task chain generation, and 4-phase TDD verification with compliance reporting. Triggers on "workflow:tdd-plan", "workflow:tdd-verify".
allowed-tools: Skill, Task, AskUserQuestion, TaskCreate, TaskUpdate, TaskList, Read, Write, Edit, Bash, Glob, Grep
---
# Workflow TDD
Unified TDD workflow skill combining TDD planning (Red-Green-Refactor task chain generation with test-first development structure) and TDD verification (compliance validation with quality gate reporting). Produces IMPL_PLAN.md, task JSONs with internal TDD cycles, and TDD_COMPLIANCE_REPORT.md.
## Architecture Overview
```
┌──────────────────────────────────────────────────────────────────┐
│ Workflow TDD Orchestrator (SKILL.md) │
│ → Route by mode: plan | verify │
│ → Pure coordinator: Execute phases, parse outputs, pass context │
└──────────────────────────────┬───────────────────────────────────┘
┌───────────────────────┴───────────────────────┐
↓ ↓
┌─────────────┐ ┌───────────┐
│ Plan Mode │ │ Verify │
│ (default) │ │ Mode │
│ Phase 1-6 │ │ Phase 7 │
└──────┬──────┘ └───────────┘
┌─────┼─────┬─────┬─────┬─────┐
↓ ↓ ↓ ↓ ↓ ↓
┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐
│ 1 │ │ 2 │ │ 3 │ │ 4 │ │ 5 │ │ 6 │
│Ses│ │Ctx│ │Tst│ │Con│ │Gen│ │Val│
└───┘ └───┘ └───┘ └───┘ └─┬─┘ └───┘
┌───────────┐
│ Confirm │─── Verify ──→ Phase 7
│ (choice) │─── Execute ─→ Skill("workflow-execute")
└───────────┘─── Review ──→ /workflow:status
```
## Key Design Principles
1. **Pure Orchestrator**: SKILL.md routes and coordinates only; execution detail lives in phase files
2. **Progressive Phase Loading**: Read phase docs ONLY when that phase is about to execute
3. **Multi-Mode Routing**: Single skill handles plan/verify via mode detection
4. **Task Attachment Model**: Sub-command tasks are ATTACHED, executed sequentially, then COLLAPSED
5. **Auto-Continue**: After each phase completes, automatically execute next pending phase
6. **TDD Iron Law**: NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST - enforced in task structure
## Auto Mode
When `--yes` or `-y`: Auto-continue all phases (skip confirmations), use recommended conflict resolutions, auto-select "Verify Plan Quality" after plan completion.
## Mode Detection
```javascript
const args = $ARGUMENTS
const mode = detectMode(args)
function detectMode(args) {
// Skill trigger determines mode
if (skillName === 'workflow:tdd-verify') return 'verify'
return 'plan' // default: workflow:tdd-plan
}
```
## Execution Flow
### Plan Mode (default)
```
Input Parsing:
└─ Convert user input to TDD structured format (GOAL/SCOPE/CONTEXT/TEST_FOCUS)
Phase 1: Session Discovery
└─ Ref: phases/01-session-discovery.md
└─ Output: sessionId (WFS-xxx)
Phase 2: Context Gathering
└─ Ref: phases/02-context-gathering.md
├─ Tasks attached: Analyze structure → Identify integration → Generate package
└─ Output: contextPath + conflictRisk
Phase 3: Test Coverage Analysis
└─ Ref: phases/03-test-coverage-analysis.md
├─ Tasks attached: Detect framework → Analyze coverage → Identify gaps
└─ Output: testContextPath
Phase 4: Conflict Resolution (conditional: conflictRisk ≥ medium)
└─ Decision (conflictRisk check):
├─ conflictRisk ≥ medium → Ref: phases/04-conflict-resolution.md
│ ├─ Tasks attached: Detect conflicts → Log analysis → Apply strategies
│ └─ Output: conflict-resolution.json
└─ conflictRisk < medium → Skip to Phase 5
Phase 5: TDD Task Generation
└─ Ref: phases/05-tdd-task-generation.md
├─ Tasks attached: Discovery → Planning → Output
└─ Output: IMPL_PLAN.md, IMPL-*.json, TODO_LIST.md
Phase 6: TDD Structure Validation
└─ Ref: phases/06-tdd-structure-validation.md
└─ Output: Validation report + Plan Confirmation Gate
Plan Confirmation (User Decision Gate):
└─ Decision (user choice):
├─ "Verify TDD Compliance" (Recommended) → Route to Phase 7 (tdd-verify)
├─ "Start Execution" → Skill(skill="workflow-execute")
└─ "Review Status Only" → Route to /workflow:status
```
### Verify Mode
```
Phase 7: TDD Verification
└─ Ref: phases/07-tdd-verify.md
└─ Output: TDD_COMPLIANCE_REPORT.md with quality gate recommendation
```
**Phase Reference Documents** (read on-demand when phase executes):
| Phase | Document | Purpose | Mode |
|-------|----------|---------|------|
| 1 | [phases/01-session-discovery.md](phases/01-session-discovery.md) | Create or discover TDD workflow session | plan |
| 2 | [phases/02-context-gathering.md](phases/02-context-gathering.md) | Gather project context and analyze codebase | plan |
| 3 | [phases/03-test-coverage-analysis.md](phases/03-test-coverage-analysis.md) | Analyze test coverage and framework detection | plan |
| 4 | [phases/04-conflict-resolution.md](phases/04-conflict-resolution.md) | Detect and resolve conflicts (conditional) | plan |
| 5 | [phases/05-tdd-task-generation.md](phases/05-tdd-task-generation.md) | Generate TDD tasks with Red-Green-Refactor cycles | plan |
| 6 | [phases/06-tdd-structure-validation.md](phases/06-tdd-structure-validation.md) | Validate TDD structure and present confirmation gate | plan |
| 7 | [phases/07-tdd-verify.md](phases/07-tdd-verify.md) | Full TDD compliance verification with quality gate | verify |
## Core Rules
1. **Start Immediately**: First action is mode detection + TaskCreate initialization, second action is phase execution
2. **No Preliminary Analysis**: Do not read files, analyze structure, or gather context before Phase 1
3. **Parse Every Output**: Extract required data from each phase output for next phase
4. **Auto-Continue via TaskList**: Check TaskList status to execute next pending phase automatically
5. **Track Progress**: Update TaskCreate/TaskUpdate dynamically with task attachment/collapse pattern
6. **Task Attachment Model**: Skill execute **attaches** sub-tasks to current workflow. Orchestrator **executes** these attached tasks itself, then **collapses** them after completion
7. **Progressive Phase Loading**: Read phase docs ONLY when that phase is about to execute
8. **DO NOT STOP**: Continuous multi-phase workflow. After executing all attached tasks, immediately collapse them and execute next phase
9. **TDD Context**: All descriptions include "TDD:" prefix
## TDD Compliance Requirements
### The Iron Law
```
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
```
**Enforcement Method**:
- Phase 5: `implementation` 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` 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
## Input Processing
**Convert User Input to TDD Structured Format**:
1. **Simple text** → Add TDD context:
```
User: "Build authentication system"
Structured:
TDD: Authentication System
GOAL: Build authentication system
SCOPE: Core authentication features
CONTEXT: New implementation
TEST_FOCUS: Authentication scenarios
```
2. **Detailed text** → Extract components with TEST_FOCUS:
```
User: "Add JWT authentication with email/password login and token refresh"
Structured:
TDD: JWT Authentication
GOAL: Implement JWT-based authentication
SCOPE: Email/password login, token generation, token refresh endpoints
CONTEXT: JWT token-based security, refresh token rotation
TEST_FOCUS: Login flow, token validation, refresh rotation, error cases
```
3. **File/Issue** → Read and structure with TDD
## Data Flow
### Plan Mode
```
User Input (task description)
[Convert to TDD Structured Format]
↓ Structured Description:
↓ TDD: [Feature Name]
↓ GOAL: [objective]
↓ SCOPE: [boundaries]
↓ CONTEXT: [background]
↓ TEST_FOCUS: [test scenarios]
Phase 1: session:start --auto "TDD: structured-description"
↓ Output: sessionId
Phase 2: context-gather --session sessionId "structured-description"
↓ Input: sessionId + structured description
↓ Output: contextPath (context-package.json) + conflictRisk
Phase 3: test-context-gather --session sessionId
↓ Input: sessionId
↓ Output: testContextPath (test-context-package.json)
Phase 4: conflict-resolution [conditional: conflictRisk ≥ medium]
↓ Input: sessionId + contextPath + conflictRisk
↓ Output: conflict-resolution.json
↓ Skip if conflictRisk is none/low → proceed directly to Phase 5
Phase 5: task-generate-tdd --session sessionId
↓ Input: sessionId + all accumulated context
↓ Output: IMPL_PLAN.md, IMPL-*.json, TODO_LIST.md
Phase 6: TDD Structure Validation (internal)
↓ Validate Red-Green-Refactor structure
↓ Present Plan Confirmation Gate
Plan Confirmation (User Decision Gate):
├─ "Verify TDD Compliance" (Recommended) → Route to Phase 7
├─ "Start Execution" → Skill(skill="workflow-execute")
└─ "Review Status Only" → Route to /workflow:status
```
### Verify Mode
```
Input: --session sessionId (or auto-detect)
Phase 7: Session discovery → Chain validation → Coverage analysis → Report
↓ Output: TDD_COMPLIANCE_REPORT.md with quality gate
```
**Session Memory Flow**: Each phase receives session ID, which provides access to:
- Previous task summaries
- Existing context and analysis
- Session-specific configuration
## TodoWrite Pattern
**Core Concept**: Dynamic task attachment and collapse for real-time visibility into TDD workflow execution.
> **Implementation Note**: Phase files use `TodoWrite` syntax to describe the conceptual tracking pattern. At runtime, these are implemented via `TaskCreate/TaskUpdate/TaskList` tools. Map as follows:
> - Initial list creation → `TaskCreate` for each item
> - Status changes → `TaskUpdate({ taskId, status })`
> - Sub-task attachment → `TaskCreate` + `TaskUpdate({ addBlockedBy })`
> - Sub-task collapse → `TaskUpdate({ status: "completed" })` + `TaskUpdate({ status: "deleted" })` for collapsed sub-items
### Key Principles
1. **Task Attachment** (when phase executed):
- Sub-tasks are **attached** to orchestrator's TodoWrite
- **Phase 3, 4, 5**: Multiple sub-tasks attached
- **Phase 1, 2, 6**: Single task (atomic)
- First attached task marked as `in_progress`, others as `pending`
- Orchestrator **executes** these attached tasks sequentially
2. **Task Collapse** (after sub-tasks complete):
- **Applies to Phase 3, 4, 5**: Remove detailed sub-tasks from TodoWrite
- **Collapse** to high-level phase summary
- **Phase 1, 2, 6**: No collapse needed (single task, just mark completed)
- Maintains clean orchestrator-level view
3. **Continuous Execution**: After completion, automatically proceed to next pending phase
**Lifecycle**: Initial pending → Phase executed (tasks ATTACHED) → Sub-tasks executed sequentially → Phase completed (tasks COLLAPSED for 3/4/5, marked completed for 1/2/6) → Next phase → Repeat
### Initial State (Plan Mode):
```json
[
{"content": "Phase 1: Session Discovery", "status": "in_progress", "activeForm": "Executing session discovery"},
{"content": "Phase 2: Context Gathering", "status": "pending", "activeForm": "Executing context gathering"},
{"content": "Phase 3: Test Coverage Analysis", "status": "pending", "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"}
]
```
**Note**: Phase 4 (Conflict Resolution) is added dynamically after Phase 2 if conflictRisk ≥ medium.
### Phase 3 (Tasks Attached):
```json
[
{"content": "Phase 1: Session Discovery", "status": "completed"},
{"content": "Phase 2: Context Gathering", "status": "completed"},
{"content": "Phase 3: Test Coverage Analysis", "status": "in_progress"},
{"content": " → Detect test framework and conventions", "status": "in_progress"},
{"content": " → Analyze existing test coverage", "status": "pending"},
{"content": " → Identify coverage gaps", "status": "pending"},
{"content": "Phase 5: TDD Task Generation", "status": "pending"},
{"content": "Phase 6: TDD Structure Validation", "status": "pending"}
]
```
### Phase 3 (Collapsed):
```json
[
{"content": "Phase 1: Session Discovery", "status": "completed"},
{"content": "Phase 2: Context Gathering", "status": "completed"},
{"content": "Phase 3: Test Coverage Analysis", "status": "completed"},
{"content": "Phase 5: TDD Task Generation", "status": "pending"},
{"content": "Phase 6: TDD Structure Validation", "status": "pending"}
]
```
### Phase 5 (Tasks Attached):
```json
[
{"content": "Phase 1: Session Discovery", "status": "completed"},
{"content": "Phase 2: Context Gathering", "status": "completed"},
{"content": "Phase 3: Test Coverage Analysis", "status": "completed"},
{"content": "Phase 5: TDD Task Generation", "status": "in_progress"},
{"content": " → Discovery - analyze TDD requirements", "status": "in_progress"},
{"content": " → Planning - design Red-Green-Refactor cycles", "status": "pending"},
{"content": " → Output - generate IMPL tasks with internal TDD phases", "status": "pending"},
{"content": "Phase 6: TDD Structure Validation", "status": "pending"}
]
```
**Note**: See individual Phase descriptions for detailed TodoWrite Update examples.
## Post-Phase Updates
### Memory State Check
After heavy phases (Phase 2-3), evaluate context window usage:
- If memory usage is high (>110K tokens or approaching context limits):
```javascript
Skill(skill="compact")
```
- Memory compaction is particularly important after analysis phases
### Planning Notes (Optional)
Similar to workflow-plan, a `planning-notes.md` can accumulate context across phases if needed. See Phase 1 for initialization.
## Error Handling
- **Parsing Failure**: If output parsing fails, retry command once, then report error
- **Validation Failure**: Report which file/data is missing or invalid
- **Command Failure**: Keep phase `in_progress`, report error to user, do not proceed
- **TDD Validation Failure**: Report incomplete chains or wrong dependencies
- **Session Not Found** (verify mode): Report error with available sessions list
### 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 `/workflow:tools:context-gather` |
| 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 `/workflow:tools:test-context-gather` |
| 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 |
### 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 `/workflow:execute`
## Coordinator Checklist
### Plan Mode
- **Pre-Phase**: Convert user input to TDD structured format (TDD/GOAL/SCOPE/CONTEXT/TEST_FOCUS)
- Initialize TaskCreate before any command (Phase 4 added dynamically after Phase 2)
- Execute Phase 1 immediately with structured description
- Parse session ID from Phase 1 output, store in memory
- Pass session ID and structured description to Phase 2 command
- Parse context path from Phase 2 output, store in memory
- **Extract conflictRisk from context-package.json**: Determine Phase 4 execution
- Execute Phase 3 (test coverage analysis) with sessionId
- Parse testContextPath from Phase 3 output, store in memory
- **If conflictRisk ≥ medium**: Launch Phase 4 conflict-resolution with sessionId and contextPath
- Wait for Phase 4 to finish executing (if executed), verify conflict-resolution.json created
- **If conflictRisk is none/low**: Skip Phase 4, proceed directly to Phase 5
- Pass session ID to Phase 5 command (TDD task generation)
- Verify all Phase 5 outputs (IMPL_PLAN.md, IMPL-*.json, TODO_LIST.md)
- Execute Phase 6 (internal TDD structure validation)
- **Plan Confirmation Gate**: Present user with choice (Verify → Phase 7 / Execute / Review Status)
- **If user selects Verify**: Read phases/07-tdd-verify.md, execute Phase 7 in-process
- **If user selects Execute**: Skill(skill="workflow-execute")
- **If user selects Review**: Route to /workflow:status
- **Auto mode (--yes)**: Auto-select "Verify TDD Compliance", then auto-continue to execute if APPROVED
- Update TaskCreate/TaskUpdate after each phase
- After each phase, automatically continue to next phase based on TaskList status
### Verify Mode
- Detect/validate session (from --session flag or auto-detect)
- Initialize TaskCreate with verification tasks
- Execute Phase 7 through all sub-phases (session validation → chain validation → coverage analysis → report generation)
- Present quality gate result and next step options
## Related Skills
**Prerequisite Skills**:
- None - TDD planning is self-contained (can optionally run brainstorm commands before)
**Called by Plan Mode** (6 phases):
- `/workflow:session:start` - Phase 1: Create or discover TDD workflow session
- `/workflow:tools:context-gather` - Phase 2: Gather project context and analyze codebase
- `/workflow:tools:test-context-gather` - Phase 3: Analyze existing test patterns and coverage
- `/workflow:tools:conflict-resolution` - Phase 4: Detect and resolve conflicts (conditional)
- `/compact` - Phase 4: Memory optimization (if context approaching limits)
- `/workflow:tools:task-generate-tdd` - Phase 5: Generate TDD tasks with Red-Green-Refactor cycles
**Called by Verify Mode**:
- `/workflow:tools:tdd-coverage-analysis` - Phase 7: Test coverage and cycle analysis
**Follow-up Skills**:
- `/workflow:tdd-verify` - Verify TDD compliance (can also invoke via verify mode)
- `/workflow:plan-verify` - Verify plan quality and dependencies
- `/workflow:status` - Review TDD task breakdown
- `Skill(skill="workflow-execute")` - Begin TDD implementation

View File

@@ -0,0 +1,57 @@
# Phase 1: Session Discovery
Create or discover TDD workflow session and extract session ID.
## Objective
- Create a new TDD workflow session via `/workflow:session:start`
- Extract session ID for subsequent phases
## Execution
### Step 1.1: Execute Session Start
```javascript
Skill(skill="workflow:session:start", args="--type tdd --auto \"TDD: [structured-description]\"")
```
**TDD Structured Format**:
```
TDD: [Feature Name]
GOAL: [Objective]
SCOPE: [Included/excluded]
CONTEXT: [Background]
TEST_FOCUS: [Test scenarios]
```
**Example**:
```
TDD: JWT Authentication
GOAL: Implement JWT-based authentication
SCOPE: Email/password login, token generation, token refresh endpoints
CONTEXT: Existing user database schema, REST API
TEST_FOCUS: Login flow, token validation, refresh rotation, error cases
```
### 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
**After Phase 1**: Return to user showing Phase 1 results, then auto-continue to Phase 2
## Output
- **Variable**: `sessionId` (WFS-xxx)
- **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).

View File

@@ -0,0 +1,53 @@
# Phase 2: Context Gathering
Gather project context and analyze codebase for TDD planning.
## Objective
- Gather project context via context-search agents
- Generate context-package.json with codebase analysis
- Extract conflictRisk to determine Phase 4 execution
## Execution
### Step 2.1: Execute Context Gathering
```javascript
Skill(skill="workflow:tools:context-gather", args="--session [sessionId] \"TDD: [structured-description]\"")
```
**Use Same Structured Description**: Pass the same structured format from Phase 1.
**Input**: `sessionId` from Phase 1
### Step 2.2: 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
### Step 2.3: Extract conflictRisk
```javascript
const contextPackage = Read(contextPath)
const conflictRisk = contextPackage.conflict_risk // "none" | "low" | "medium" | "high"
```
**Note**: conflictRisk determines whether Phase 4 (Conflict Resolution) will execute.
**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
## Output
- **Variable**: `contextPath` (path to context-package.json)
- **Variable**: `conflictRisk` ("none" | "low" | "medium" | "high")
- **TodoWrite**: Mark Phase 2 completed, Phase 3 in_progress
## Next Phase
Return to orchestrator, then auto-continue to [Phase 3: Test Coverage Analysis](03-test-coverage-analysis.md).

View File

@@ -0,0 +1,78 @@
# Phase 3: Test Coverage Analysis
Analyze existing test coverage, detect test framework, and identify coverage gaps.
## Objective
- Analyze existing codebase for test patterns and conventions
- Detect current test coverage and framework
- Identify related components and integration points
- Generate test-context-package.json
## Execution
### Step 3.1: Execute Test Context Gathering
```javascript
Skill(skill="workflow:tools:test-context-gather", args="--session [sessionId]")
```
**Purpose**: Analyze existing codebase for:
- Existing test patterns and conventions
- Current test coverage
- Related components and integration points
- Test framework detection
### Step 3.2: Parse Output
- Extract: testContextPath (`.workflow/active/[sessionId]/.process/test-context-package.json`)
**Validation**:
- test-context-package.json exists and is valid JSON
- Contains framework detection results
### TodoWrite Update (Phase 3 Skill executed - 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"}
]
```
**Note**: Phase 3 tasks completed and collapsed to summary.
**After Phase 3**: Return to user showing test coverage results, then auto-continue to Phase 4/5 (depending on conflict_risk)
## Output
- **Variable**: `testContextPath` (path to test-context-package.json)
- **TodoWrite**: Mark Phase 3 completed
## Next Phase
Based on `conflictRisk` from Phase 2:
- If conflictRisk ≥ medium → [Phase 4: Conflict Resolution](04-conflict-resolution.md)
- If conflictRisk < medium → Skip to [Phase 5: TDD Task Generation](05-tdd-task-generation.md)

View File

@@ -0,0 +1,95 @@
# Phase 4: Conflict Resolution (Conditional)
Detect and resolve conflicts when conflict risk is medium or high.
## Objective
- Execute conflict detection and resolution only when conflictRisk ≥ medium
- Generate conflict-resolution.json with resolution strategies
- Skip directly to Phase 5 if conflictRisk is none/low
## Trigger Condition
**Only execute when**: `context-package.json` indicates `conflict_risk` is "medium" or "high"
**Skip Behavior**: If conflict_risk is "none" or "low", skip directly to Phase 5. Display: "No significant conflicts detected, proceeding to TDD task generation"
## Execution
### Step 4.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
### Step 4.2: 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)
### TodoWrite Update (Phase 4 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: 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"}
]
```
**Note**: Skill execute **attaches** conflict-resolution's 3 tasks. Orchestrator **executes** these tasks.
**Next Action**: Tasks attached → **Execute Phase 4.1-4.3** sequentially
### 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"}
]
```
**Note**: Phase 4 tasks completed and collapsed to summary.
**After Phase 4**: Return to user showing conflict resolution results and selected strategies, then auto-continue to Phase 5
### Memory State Check
After Phase 4, evaluate current context window usage and memory state:
- If memory usage is high (>110K tokens or approaching context limits):
```javascript
Skill(skill="compact")
```
- This optimizes memory before proceeding to Phase 5
- Memory compaction is particularly important after analysis phase which may generate extensive documentation
- Ensures optimal performance and prevents context overflow
## Output
- **File**: `.workflow/active/[sessionId]/.process/conflict-resolution.json` (if executed)
- **TodoWrite**: Mark Phase 4 completed, Phase 5 in_progress
## Next Phase
Return to orchestrator, then auto-continue to [Phase 5: TDD Task Generation](05-tdd-task-generation.md).

View File

@@ -0,0 +1,105 @@
# Phase 5: TDD Task Generation
Generate TDD tasks with Red-Green-Refactor cycles via action-planning-agent.
## Objective
- Generate IMPL_PLAN.md, task JSONs, and TODO_LIST.md with TDD structure
- Each task contains internal Red-Green-Refactor cycle
- Include Phase 0 user configuration (execution method, CLI tool preference)
## Execution
### Step 5.1: Execute TDD Task Generation
```javascript
Skill(skill="workflow:tools:task-generate-tdd", args="--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
**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.
### Step 5.2: Parse Output
Extract: feature count, task count, CLI execution IDs assigned
### Step 5.3: Validate Outputs
- `plan.json` exists (structured plan overview with `_metadata.plan_type: "tdd"`)
- `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`
- `cli_execution.id: {session_id}-{task_id}`
- `cli_execution: { "strategy": "new|resume|fork|merge_fork", ... }`
- `implementation` with exactly 3 steps (red/green/refactor)
- Green phase includes test-fix-cycle configuration
- `focus_paths`: absolute or clear relative paths (enhanced with exploration critical_files)
- `pre_analysis`: includes exploration integration_points analysis
- `IMPL_PLAN.md` contains `workflow_type: "tdd"` in frontmatter
- User configuration applied:
- If executionMethod == "cli" or "hybrid": command field added to steps
- CLI tool preference reflected in execution guidance
- Task count ≤18 (compliance with hard limit)
### Red Flag Detection (Non-Blocking Warnings)
- Task count >18: `⚠️ Task count exceeds hard limit - request re-scope`
- Missing cli_execution.id: `⚠️ Task lacks CLI execution ID for resume support`
- Missing test-fix-cycle: `⚠️ Green phase lacks auto-revert configuration`
- Generic task names: `⚠️ Vague task names suggest unclear TDD cycles`
- Missing focus_paths: `⚠️ Task lacks clear file scope for implementation`
**Action**: Log warnings to `.workflow/active/[sessionId]/.process/tdd-warnings.log` (non-blocking)
### TodoWrite Update (Phase 5 Skill executed - 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"}
]
```
**Note**: Skill execute **attaches** task-generate-tdd's 3 tasks. Orchestrator **executes** these tasks. Each generated IMPL task will contain internal Red-Green-Refactor cycle.
**Next Action**: Tasks attached → **Execute Phase 5.1-5.3** sequentially
### 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"}
]
```
**Note**: Phase 5 tasks completed and collapsed to summary. Each generated IMPL task contains complete Red-Green-Refactor cycle internally.
## Output
- **File**: `plan.json` (structured plan overview)
- **File**: `IMPL_PLAN.md` (unified plan with TDD Implementation Tasks section)
- **File**: `IMPL-*.json` (task JSONs with internal TDD cycles)
- **File**: `TODO_LIST.md` (task list with TDD phase indicators)
- **File**: `.process/tdd-warnings.log` (non-blocking warnings)
- **TodoWrite**: Mark Phase 5 completed, Phase 6 in_progress
## Next Phase
Return to orchestrator, then auto-continue to [Phase 6: TDD Structure Validation](06-tdd-structure-validation.md).

View File

@@ -0,0 +1,179 @@
# Phase 6: TDD Structure Validation & Plan Confirmation
Internal validation of TDD task structure and user decision gate for next steps.
## Objective
- Validate Red-Green-Refactor structure in all generated tasks
- Verify TDD compliance checkpoints
- Gather evidence before claiming completion
- Present Plan Confirmation Gate to user
## Execution
### Step 6.1: Internal Validation
Validate each generated task contains complete TDD workflow:
1. **Task structure validation**:
- `meta.tdd_workflow: true` in all IMPL tasks
- `cli_execution.id` present (format: {session_id}-{task_id})
- `cli_execution` strategy assigned (new/resume/fork/merge_fork)
- `implementation` has exactly 3 steps
- Each step has correct `tdd_phase`: "red", "green", "refactor"
- `focus_paths` are absolute or clear relative paths
- `pre_analysis` includes exploration integration analysis
2. **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
3. **Agent assignment**: All IMPL tasks use @code-developer
4. **Test-fix cycle**: Green phase step includes test-fix-cycle logic with max_iterations
5. **Task count**: Total tasks ≤18 (simple + subtasks hard limit)
6. **User configuration**:
- Execution method choice reflected in task structure
- CLI tool preference documented in implementation guidance (if CLI selected)
### Step 6.2: 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**:
```
⚠️ TDD Red Flag: [issue description]
Task: [IMPL-N]
Recommendation: [action to fix]
```
### Step 6.3: Evidence Gathering
Before claiming completion, verify artifacts exist:
```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: .cli_execution.id, phases: [.implementation[].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) |
### Step 6.4: Plan Confirmation Gate
Present user with action choices:
```javascript
console.log(`
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.
`);
// Ask user for next action
const userChoice = AskUserQuestion({
questions: [{
question: "TDD Planning complete. What would you like to do next?",
header: "Next Action",
multiSelect: false,
options: [
{
label: "Verify TDD Compliance (Recommended)",
description: "Run full TDD compliance verification to check task chain structure, coverage, and Red-Green-Refactor cycle quality."
},
{
label: "Start Execution",
description: "Begin implementing TDD tasks immediately with Red-Green-Refactor cycles."
},
{
label: "Review Status Only",
description: "View TDD task breakdown and session status without taking further action."
}
]
}]
});
// Execute based on user choice
if (userChoice === "Verify TDD Compliance (Recommended)") {
// Route to Phase 7 (tdd-verify) within this skill
// Orchestrator reads phases/07-tdd-verify.md and executes
} else if (userChoice === "Start Execution") {
Skill(skill="workflow-execute", args="--session " + sessionId);
} else if (userChoice === "Review Status Only") {
Skill(skill="workflow:status", args="--session " + sessionId);
}
```
**Auto Mode (--yes)**: Auto-select "Verify TDD Compliance", then auto-continue to execute if quality gate is APPROVED.
## Output
- **Validation**: TDD structure verified
- **User Decision**: Route to Phase 7 / Execute / Review
- **TodoWrite**: Mark Phase 6 completed
## Next Phase (Conditional)
Based on user's plan confirmation choice:
- If "Verify" → [Phase 7: TDD Verification](07-tdd-verify.md)
- If "Execute" → Skill(skill="workflow-execute")
- If "Review" → External: /workflow:status

View File

@@ -0,0 +1,461 @@
# Phase 7: TDD Verification
Full TDD compliance verification with quality gate reporting. Generates comprehensive TDD_COMPLIANCE_REPORT.md.
## Objective
- Verify TDD task chain structure (TEST → IMPL → REFACTOR or internal Red-Green-Refactor)
- Analyze test coverage metrics
- Validate TDD cycle execution quality
- Generate compliance report with quality gate recommendation
## Operating Constraints
**ORCHESTRATOR MODE**:
- This phase coordinates sub-steps and `/workflow:tools:tdd-coverage-analysis`
- 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.
## 4-Step Execution
### Step 7.1: Session Discovery & Validation
```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
```
**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 /workflow:tdd-plan 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
---
### Step 7.2: Task Chain Structure Validation
**Load and Parse Task JSONs**:
```bash
# Single-pass JSON extraction using jq
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}'
```
**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)
---
### Step 7.3: Coverage & Cycle Analysis
**Call Coverage Analysis Sub-command**:
```javascript
Skill(skill="workflow:tools:tdd-coverage-analysis", args="--session {session_id}")
```
**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)
```
**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
---
### Step 7.4: Compliance Report Generation
**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)
```
**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"
```
**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)
**Generate Report**:
```javascript
const report_content = generateComplianceReport(/* see template below */)
const report_path = `${session_dir}/TDD_COMPLIANCE_REPORT.md`
Write(report_path, report_content)
```
**Display Summary to User**:
```
=== TDD Verification Complete ===
Session: {session_id}
Report: {report_path}
Quality Gate: {recommendation}
Compliance Score: {score}/100
Chain Validation: {chain_completeness_score}%
Line Coverage: {line_coverage}%
Branch Coverage: {branch_coverage}%
Next: Review full report for detailed findings
```
## TDD Compliance Report Template
```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 |
### 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 |
|------|-------|-------|----------|
| {file} | {lines} | {issue} | {priority} |
---
## TDD Cycle Validation
### Red Phase (Write Failing Test)
- {N}/{total} features had failing tests initially ({percent}%)
- ✅ Compliant features: {list}
- ❌ Non-compliant features: {list}
### Green Phase (Make Test Pass)
- {N}/{total} implementations made tests pass ({percent}%)
- ✅ Compliant features: {list}
- ❌ Non-compliant features: {list}
### Refactor Phase (Improve Quality)
- {N}/{total} features completed refactoring ({percent}%)
- ✅ Compliant features: {list}
- ❌ Non-compliant features: {list}
---
## Best Practices Assessment
### Strengths
- {strengths}
### Areas for Improvement
- {improvements}
---
## Detailed Findings by Severity
### Critical Issues ({count})
{List of critical issues with impact and remediation}
### High Priority Issues ({count})
{List of high priority issues}
### Medium Priority Issues ({count})
{List of medium priority issues}
### Low Priority Issues ({count})
{List of low priority issues}
---
## Recommendations
### Required Fixes (Before Merge)
1. {required fixes}
### Recommended Improvements
1. {recommended improvements}
### Optional Enhancements
1. {optional enhancements}
---
## 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**
```
## 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 /workflow:tdd-plan 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 |
| Sub-command fails | tdd-coverage-analysis error | Check sub-command logs |
## Output
- **File**: `TDD_COMPLIANCE_REPORT.md` (comprehensive compliance report)
- **Files**: `.process/test-results.json`, `.process/coverage-report.json`, `.process/tdd-cycle-report.md`
## Output Files Structure
```
.workflow/active/WFS-{session-id}/
├── TDD_COMPLIANCE_REPORT.md # Comprehensive compliance report ⭐
└── .process/
├── test-results.json # From tdd-coverage-analysis
├── coverage-report.json # From tdd-coverage-analysis
└── tdd-cycle-report.md # From tdd-coverage-analysis
```
## Next Steps Decision Table
| Situation | Recommended Command | Purpose |
|-----------|---------------------|---------|
| APPROVED | `/workflow:execute` | Start TDD implementation |
| PROCEED_WITH_CAVEATS | `/workflow:execute` | Start with noted caveats |
| REQUIRE_FIXES | Review report, refine tasks | Address issues before proceed |
| BLOCK_MERGE | `/workflow:replan` | Significant restructuring needed |
| After implementation | Re-run `/workflow:tdd-verify` | Verify post-execution compliance |