v2/src/task/README.md
Comprehensive task management with orchestration features for Claude-Flow. Integrates seamlessly with TodoWrite/TodoRead for coordination and Memory for state persistence.
Task Management System
├── TaskEngine (Core)
│ ├── Task Creation & Management
│ ├── Dependency Resolution
│ ├── Resource Allocation
│ ├── Execution Orchestration
│ └── Progress Tracking
├── TaskCoordinator (Orchestration)
│ ├── TodoWrite/TodoRead Integration
│ ├── Memory Coordination
│ ├── Batch Operations
│ ├── Agent Launching
│ └── Swarm Patterns
└── Commands (CLI)
├── task create
├── task list
├── task status
├── task cancel
└── task workflow
import { TaskEngine, TaskCoordinator } from './task';
const engine = new TaskEngine(10); // max 10 concurrent tasks
const coordinator = new TaskCoordinator(engine, memoryManager);
// Create a task with dependencies
const task = await engine.createTask({
type: 'development',
description: 'Implement user authentication',
priority: 80,
dependencies: [{ taskId: 'design-task-123', type: 'finish-to-start' }],
resourceRequirements: [
{ resourceId: 'cpu', type: 'cpu', amount: 2, unit: 'cores' },
{ resourceId: 'memory', type: 'memory', amount: 1024, unit: 'MB' },
],
schedule: {
deadline: new Date('2024-02-15T18:00:00Z'),
},
tags: ['auth', 'security', 'backend'],
});
// Create comprehensive task breakdown
const todos = await coordinator.createTaskTodos(
'Build e-commerce platform',
{
strategy: 'development',
batchOptimized: true,
parallelExecution: true,
memoryCoordination: true,
},
context,
);
// Todos automatically include:
// - System architecture design (high priority)
// - Frontend development (parallel execution)
// - Backend development (parallel execution)
// - Testing and integration (depends on frontend/backend)
// Launch coordinated agents using Task tool pattern
const agentIds = await coordinator.launchParallelAgents(
[
{
agentType: 'researcher',
objective: 'Research microservices patterns',
mode: 'researcher',
memoryKey: 'microservices_research',
batchOptimized: true,
},
{
agentType: 'architect',
objective: 'Design system architecture',
mode: 'architect',
memoryKey: 'system_architecture',
batchOptimized: true,
},
{
agentType: 'coder',
objective: 'Implement core services',
mode: 'coder',
memoryKey: 'core_implementation',
batchOptimized: true,
},
],
context,
);
// Store findings for cross-agent coordination
await coordinator.storeInMemory(
'research_findings',
{
bestPractices: ['microservices', 'event-driven'],
technologies: ['nodejs', 'redis', 'postgresql'],
patterns: ['saga', 'cqrs', 'event-sourcing'],
},
{
namespace: 'project_coordination',
tags: ['research', 'architecture'],
},
);
// Other agents can retrieve and use this data
const findings = await coordinator.retrieveFromMemory('research_findings', 'project_coordination');
// Coordinate multiple operations for efficiency
const results = await coordinator.coordinateBatchOperations(
[
{
type: 'read',
targets: ['src/**/*.ts'],
configuration: { pattern: 'class.*{' },
},
{
type: 'search',
targets: ['docs/**/*.md'],
configuration: { term: 'API documentation' },
},
{
type: 'analyze',
targets: ['package.json', 'tsconfig.json'],
configuration: { focus: 'dependencies' },
},
],
context,
);
# Create comprehensive task with all options
claude-flow task create development "Implement authentication" \
--priority 80 \
--dependencies "task-123,task-456" \
--dep-type finish-to-start \
--assign backend-team \
--tags "auth,security,backend" \
--deadline "2024-02-15T18:00:00Z" \
--cpu 2 \
--memory 1024 \
--max-retries 5 \
--rollback previous-checkpoint
# List with advanced filtering and visualization
claude-flow task list \
--status running,pending \
--priority 70-100 \
--tags auth,security \
--sort deadline \
--sort-dir asc \
--format table \
--show-dependencies \
--show-progress \
--limit 20
# Detailed status with all metrics
claude-flow task status task-789 \
--show-logs \
--show-checkpoints \
--show-metrics \
--show-dependencies \
--show-resources \
--watch
# Safe cancellation with rollback
claude-flow task cancel task-789 \
--reason "Requirements changed" \
--cascade \
--dry-run
# Create workflow
claude-flow task workflow create "E-commerce Platform" \
--description "Complete development workflow" \
--max-concurrent 8 \
--strategy priority-based \
--error-handling continue-on-error
# Execute workflow with monitoring
claude-flow task workflow execute workflow-123 \
--variables '{"environment":"staging"}' \
--monitor
# Visualize dependency graph
claude-flow task workflow visualize workflow-123 \
--format dot \
--output workflow-graph.dot
Single coordinator manages all agents:
await coordinator.coordinateSwarm(
'Development project',
{ coordinationMode: 'centralized' },
agents,
);
Multiple coordinators for different aspects:
await coordinator.coordinateSwarm(
'Complex system development',
{ coordinationMode: 'distributed' },
agents,
);
Tree structure with team leads:
await coordinator.coordinateSwarm(
'Enterprise development',
{ coordinationMode: 'hierarchical' },
agents,
);
Peer-to-peer coordination:
await coordinator.coordinateSwarm('Adaptive development', { coordinationMode: 'mesh' }, agents);
Mixed patterns based on requirements:
await coordinator.coordinateSwarm(
'Complex adaptive project',
{ coordinationMode: 'hybrid' },
agents,
);
The task management system is designed to work seamlessly with Claude Code's batch tools:
retryPolicy: {
maxAttempts: 3,
backoffMs: 1000,
backoffMultiplier: 2
}
previous-checkpoint: Roll back to last checkpointinitial-state: Roll back to task startcustom: Use custom rollback handlerSee the examples directory for comprehensive usage examples including:
Detailed API documentation is available in the API docs.
See CONTRIBUTING.md for guidelines on contributing to the task management system.