Files
claude-task-master/.taskmaster/docs/tdd-workflow-phase-0-spike.md
Ralph Khreish 8857417870 feat: implement Phase 0 TDD autopilot dry-run foundation
Implements the complete Phase 0 spike for autonomous TDD workflow with orchestration architecture.

## What's New

### Core Services (tm-core)
- **PreflightChecker**: Validates environment prerequisites
  - Test command detection from package.json
  - Git working tree status validation
  - Required tools availability (git, gh, node, npm)
  - Default branch detection

- **TaskLoaderService**: Comprehensive task validation
  - Task existence and structure validation
  - Subtask dependency analysis with circular detection
  - Execution order calculation via topological sort
  - Helpful expansion suggestions for unready tasks

### CLI Command
- **autopilot command**: `tm autopilot <taskId> --dry-run`
  - Displays complete execution plan without executing
  - Shows preflight check results
  - Lists subtasks in dependency order
  - Preview RED/GREEN/COMMIT phases per subtask
  - Registered in command registry

### Architecture Documentation
- **Phase 0 completion**: Marked tdd-workflow-phase-0-spike.md as complete
- **Orchestration model**: Added execution model section to main workflow doc
  - Clarifies orchestrator guides AI sessions vs direct execution
  - WorkflowOrchestrator API design (getNextWorkUnit, completeWorkUnit)
  - State machine approach for phase transitions

- **Phase 1 roadmap**: New tdd-workflow-phase-1-orchestrator.md
  - Detailed state machine specifications
  - MCP integration plan with new tool definitions
  - Implementation checklist with 6 clear steps
  - Example usage flows

## Technical Details

**Preflight Checks**:
-  Test command detection
-  Git working tree status
-  Required tools validation
-  Default branch detection

**Task Validation**:
-  Task existence check
-  Status validation (no completed/cancelled tasks)
-  Subtask presence validation
-  Dependency resolution with circular detection
-  Execution order calculation

**Architecture Decision**:
Adopted orchestration model where WorkflowOrchestrator maintains state and generates work units, while Claude Code (via MCP) executes the actual work. This provides:
- Clean separation of concerns
- Human-in-the-loop capability
- Simpler implementation (no AI integration in orchestrator)
- Flexible executor support

## Out of Scope (Phase 0)
- Actual test generation
- Actual code implementation
- Git operations (commits, branches, PR)
- Test execution
→ All deferred to Phase 1

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-08 16:46:34 +02:00

4.3 KiB

Phase 0: Spike - Autonomous TDD Workflow COMPLETE

Objective

Validate feasibility and build foundational understanding before full implementation.

Status

COMPLETED - All deliverables implemented and validated.

See apps/cli/src/commands/autopilot.command.ts for implementation.

Scope

  • Implement CLI skeleton tm autopilot with dry-run mode
  • Show planned steps from a real task with subtasks
  • Detect test runner from package.json
  • Detect git state and render preflight report

Deliverables

1. CLI Command Skeleton

  • Create apps/cli/src/commands/autopilot.command.ts
  • Support tm autopilot <taskId> command
  • Implement --dry-run flag
  • Basic help text and usage information

2. Preflight Detection System

  • Detect test runner from package.json (npm test, pnpm test, etc.)
  • Check git working tree state (clean/dirty)
  • Validate required tools are available (git, gh, node/npm)
  • Detect default branch

3. Dry-Run Execution Plan Display

Display planned execution for a task including:

  • Preflight checks status
  • Branch name that would be created
  • Tag that would be set
  • List of subtasks in execution order
  • For each subtask:
    • RED phase: test file that would be created
    • GREEN phase: implementation files that would be modified
    • COMMIT: commit message that would be used
  • Finalization steps: test suite run, coverage check, push, PR creation

4. Task Loading & Validation

  • Load task from TaskMaster state
  • Validate task exists and has subtasks
  • If no subtasks, show message about needing to expand first
  • Show dependency order for subtasks

Example Output

$ tm autopilot 42 --dry-run

Autopilot Plan for Task #42 [analytics]: User metrics tracking
─────────────────────────────────────────────────────────────

Preflight Checks:
  ✓ Working tree is clean
  ✓ Test command detected: npm test
  ✓ Tools available: git, gh, node, npm
  ✓ Current branch: main (will create new branch)
  ✓ Task has 3 subtasks ready to execute

Branch & Tag:
  → Will create branch: analytics/task-42-user-metrics
  → Will set active tag: analytics

Execution Plan (3 subtasks):

  1. Subtask 42.1: Add metrics schema
     RED:    Generate tests → src/__tests__/schema.test.js
     GREEN:  Implement code → src/schema.js
     COMMIT: "feat(metrics): add metrics schema (task 42.1)"

  2. Subtask 42.2: Add collection endpoint [depends on 42.1]
     RED:    Generate tests → src/api/__tests__/metrics.test.js
     GREEN:  Implement code → src/api/metrics.js
     COMMIT: "feat(metrics): add collection endpoint (task 42.2)"

  3. Subtask 42.3: Add dashboard widget [depends on 42.2]
     RED:    Generate tests → src/components/__tests__/MetricsWidget.test.jsx
     GREEN:  Implement code → src/components/MetricsWidget.jsx
     COMMIT: "feat(metrics): add dashboard widget (task 42.3)"

Finalization:
  → Run full test suite with coverage (threshold: 80%)
  → Push branch to origin (will confirm)
  → Create PR targeting main

Estimated commits: 3
Estimated duration: ~20-30 minutes (depends on implementation complexity)

Run without --dry-run to execute.

Success Criteria

  • Dry-run output is clear and matches expected workflow
  • Preflight detection works correctly on the project repo
  • Task loading integrates with existing TaskMaster state
  • No actual git operations or file modifications occur in dry-run mode

Out of Scope

  • Actual test generation
  • Actual code implementation
  • Git operations (branch creation, commits, push)
  • PR creation
  • Test execution

Implementation Notes

  • Reuse existing TaskService from packages/tm-core
  • Use existing git utilities from scripts/modules/utils/git-utils.js
  • Load task/subtask data from .taskmaster/tasks/tasks.json
  • Detect test command via package.json → scripts.test field

Dependencies

  • Existing TaskMaster CLI structure
  • Existing task storage format
  • Git utilities

Estimated Effort

2-3 days

Validation

Test dry-run mode with:

  • Task with 1 subtask
  • Task with multiple subtasks
  • Task with dependencies between subtasks
  • Task without subtasks (should show warning)
  • Dirty git working tree (should warn)
  • Missing tools (should error with helpful message)