feat(T3.3): implement task dependency graph
- Add internal/graph package for dependency management
- Implement DependencyGraph for task ordering
- Support task dependencies and prerequisite tracking
- Validate graph for cycles (no circular dependencies)
- Topological sort for execution order (Kahn's algorithm)
- Track task status (pending, completed, failed)
- Get ready-to-execute tasks based on dependencies
- Get tasks that depend on a given task
- Check if task can execute (all deps complete)
- Calculate critical path through graph
- Task metadata support
- 23 graph tests, all passing
Features:
- AddTask() - add task to graph
- AddDependency(dependent, prerequisite) - specify ordering
- ValidateGraph() - check for cycles
- GetTopologicalOrder() - execution order
- GetReadyTasks() - tasks ready to run
- MarkCompleted(taskID) - mark as done
- MarkFailed(taskID) - mark as failed
- GetDependencies(taskID) - what task depends on
- GetDependents(taskID) - what depends on task
- CanExecuteTask(taskID) - check if ready
- GetCriticalPath() - longest path in graph
Graph Properties:
- Directed acyclic graph (DAG)
- Cycle detection (prevents deadlocks)
- Multi-dependency support (diamond dependencies)
- Status tracking (pending/completed/failed)
- Thread-safe (RWMutex)
- Kahn's algorithm for topological sort
- O(V+E) for validation and sorting
Example Usage:
- T0.1 Analyze (no deps)
- T0.2 Implement (depends on T0.1)
- T0.3 Test (depends on T0.2)
- T0.4 Review (depends on T0.2, T0.3)
Ready Detection:
- T0.1 ready (no dependencies)
- After T0.1 complete: T0.2 ready
- After T0.2 complete: T0.3 ready
- After T0.2, T0.3 complete: T0.4 ready
Test Coverage:
- 23 dependency graph tests
- Cycle detection verified
- Topological sort tested
- Multiple dependency chains
- Diamond dependency patterns
- Ready task calculation
- Status tracking
- Critical path calculation
- Complex graphs (10+ tasks)
- Metadata handling
- Performance benchmarks
Performance:
- Cycle detection: O(V+E) DFS
- Topological sort: O(V+E) Kahn's algorithm
- Ready tasks: O(V) scan
- Add task: O(1)
- Add dependency: O(1) amortized
Use Cases:
- Workflow orchestration (T0.1 -> T0.2 -> T0.3 -> ...)
- CI/CD pipelines (build -> test -> deploy)
- Milestone hierarchies (T0 milestone with sub-tasks)
- Parallel tasks with merge points (diamond deps)
Next: T3.4 (Human-in-the-loop gates)