Skip to main content
Complete guide for integrating AI agents with TaskMaster’s autonomous TDD workflow system.

Overview

TaskMaster provides a complete TDD workflow orchestration system that enables AI agents to autonomously implement features following strict Test-Driven Development practices. The system manages workflow state, git operations, test validation, and progress tracking.

Key Features

  • TDD State Machine: Enforces RED → GREEN → COMMIT cycle
  • Git Integration: Automated branch creation, commits with metadata
  • Test Validation: Ensures RED phase has failures, GREEN phase passes
  • Progress Tracking: Subtask completion, attempt counting, error logging
  • State Persistence: Automatic workflow state management
  • Dual Interface: CLI commands and MCP tools for flexibility

Architecture

Component Responsibilities

WorkflowOrchestrator
  • Manages TDD state machine transitions
  • Tracks current subtask and progress
  • Enforces workflow rules and validations
  • Emits events for state changes
GitAdapter
  • Creates and manages workflow branches
  • Stages files and creates commits
  • Validates git repository state
  • Provides safety checks (clean working tree, etc.)
TestResultValidator
  • Validates RED phase has test failures
  • Validates GREEN phase has all tests passing
  • Parses test results from various formats
CommitMessageGenerator
  • Generates conventional commit messages
  • Embeds workflow metadata (subtask ID, phase, etc.)
  • Follows project commit conventions

Getting Started

Prerequisites

  1. TaskMaster initialized project with subtasks
  2. Git repository with clean working tree
  3. Test framework configured (vitest, jest, etc.)

Quick Start

CLI Commands

All commands support --json flag for machine-readable output.

tm autopilot start <taskId>

Initialize a new TDD workflow for a task. Options:
  • --max-attempts <number>: Maximum attempts per subtask (default: 3)
  • --force: Force start even if workflow exists
  • --project-root <path>: Project root directory
  • --json: Output JSON
Example:
JSON Output:

tm autopilot resume

Resume a previously started workflow from saved state. Example:

tm autopilot next

Get the next action to perform with detailed context. JSON Output:

tm autopilot status

Get comprehensive workflow progress and state information. Example:

tm autopilot complete

Complete the current TDD phase with test result validation. Options:
  • --results <json>: Test results JSON string
Example:
Validation Rules:
  • RED Phase: Must have at least one failing test
  • GREEN Phase: All tests must pass (failed === 0)

tm autopilot commit

Create a git commit with enhanced message generation. Options:
  • --message <text>: Custom commit message (optional)
  • --files <paths...>: Specific files to stage (optional)
Example:

tm autopilot abort

Abort the workflow and clean up state (preserves git branch and code). Example:

MCP Tools

MCP tools provide the same functionality as CLI commands for programmatic integration.

autopilot_start

Parameters:
Returns:

autopilot_resume

Parameters:

autopilot_next

Parameters:
Returns:

autopilot_status

Parameters:
Returns:

autopilot_complete_phase

Parameters:

autopilot_commit

Parameters:

autopilot_abort

Parameters:

Workflow Phases

Phase Diagram

Phase Descriptions

PREFLIGHT
  • Validate task has subtasks
  • Check git repository state
  • Verify preconditions
BRANCH_SETUP
  • Create workflow branch: task-{taskId}
  • Checkout new branch
  • Initialize workflow context
SUBTASK_LOOP
  • RED Phase: Write failing tests
    • Action: generate_test
    • Validation: At least one test must fail
    • Files: Test files
  • GREEN Phase: Implement code
    • Action: implement_code
    • Validation: All tests must pass
    • Files: Implementation files
  • COMMIT Phase: Create commit
    • Action: commit_changes
    • Auto-generates commit message
    • Advances to next subtask
FINALIZE
  • All subtasks complete
  • Workflow ready for review/merge
COMPLETE
  • Workflow finished
  • State can be cleaned up

Responsibility Matrix

Clear division of responsibilities between AI Agent and TaskMaster.

AI Agent Responsibilities

  1. Read and understand subtask requirements
  2. Write test code that validates the requirement
  3. Run test suite using project’s test command
  4. Parse test output into JSON format
  5. Report results to TaskMaster for validation
  6. Write implementation to satisfy tests
  7. Request commits when GREEN phase complete
  8. Handle errors and retry within attempt limits

TaskMaster Responsibilities

  1. Manage workflow state machine
  2. Enforce TDD rules (RED must fail, GREEN must pass)
  3. Track progress (completed, current, attempts)
  4. Create git commits with enhanced messages
  5. Manage git branches and repository safety
  6. Validate transitions between phases
  7. Persist state for resumability
  8. Generate reports and activity logs

Examples

Complete TDD Cycle Example

1. Start Workflow

2. Get Next Action

3. Write Failing Test

AI Agent creates tests/start.test.ts:

4. Run Tests (Should Fail)

Parse output to JSON:

5. Complete RED Phase

6. Implement Code

AI Agent creates src/commands/start.ts:

7. Run Tests (Should Pass)

Parse output:

8. Complete GREEN Phase

9. Commit Changes

MCP Integration Example

Error Handling

Common Errors and Solutions

Workflow Already Exists

Error:
Solution:

RED Phase Validation Failed

Error:
Solution: The test isn’t actually testing the new feature. Write a test that validates the new behavior that doesn’t exist yet.

GREEN Phase Validation Failed

Error:
Solution: Implementation isn’t complete. Debug failing test and fix implementation.

No Staged Changes

Error:
Solution: Ensure you’ve actually created/modified files before committing.

Git Working Tree Not Clean

Error:
Solution:

Error Recovery Patterns

Retry Pattern

Graceful Degradation

Troubleshooting

Workflow State Issues

Problem: State file corrupted or inconsistent Solution:

Test Results Parsing

Problem: Test output format not recognized Solution: Ensure test results JSON has required fields:

Branch Conflicts

Problem: Workflow branch already exists Solution:

Permission Issues

Problem: Cannot write to .taskmaster directory Solution:

State Persistence Failures

Problem: State not saving between commands Solution:

Working with AI Agents

Example prompts for AI agents (Claude Code, Cursor, etc.) to use the TDD workflow.

Starting a Task

RED Phase - Writing Failing Tests

GREEN Phase - Implementing

Handling Errors

Checking Progress

Resuming Work


Additional Resources