# Batching Algorithm Reference

## Topological Sort with Batch Grouping

The `/implement` skill uses a topological sort to determine execution order,
then groups tasks into batches for parallel execution.

## Algorithm

1. Build adjacency list from `_dependencies_table.md`
2. Compute in-degree for each task node
3. Initialize batch 0 with all nodes that have in-degree 0
4. For each batch:
   a. Select up to 4 tasks from the ready set
   b. Check file ownership — if two tasks would write the same file, defer one to the next batch
   c. Launch selected tasks as parallel implementer subagents
   d. When all complete, remove them from the graph and decrement in-degrees of dependents
   e. Add newly zero-in-degree nodes to the next batch's ready set
5. Repeat until the graph is empty

## File Ownership Conflict Resolution

When two tasks in the same batch map to overlapping files:
- Prefer to run the lower-numbered task first (it's more foundational)
- Defer the higher-numbered task to the next batch
- If both have equal priority, ask the user

## Complexity Budget

Each batch should not exceed 20 total complexity points.
If it does, split the batch and let the user choose which tasks to include.
