pub struct DependencyGraph { /* private fields */ }Expand description
A directed acyclic graph representing task dependencies.
Edges go from a task to the tasks it depends on (its blocked_by set).
For example, if task B is blocked by task A, we store B -> {A}.
Implementations§
Source§impl DependencyGraph
impl DependencyGraph
Sourcepub fn from_tasks(tasks: &[TaskFile]) -> Self
pub fn from_tasks(tasks: &[TaskFile]) -> Self
Build a dependency graph from a slice of tasks.
Sourcepub fn would_create_cycle(&self, task_id: &str, depends_on: &str) -> bool
pub fn would_create_cycle(&self, task_id: &str, depends_on: &str) -> bool
Check whether adding an edge task_id -> depends_on would create a cycle.
Uses BFS starting from depends_on, following existing dependency edges.
If we can reach task_id from depends_on, adding this edge would
create a cycle.
Sourcepub fn add_dependency(&mut self, task_id: &str, depends_on: &str) -> Result<()>
pub fn add_dependency(&mut self, task_id: &str, depends_on: &str) -> Result<()>
Add a dependency edge: task_id is now blocked by depends_on.
Returns an error if this would create a cycle.
Sourcepub fn get_blocked_by(&self, task_id: &str) -> Vec<String>
pub fn get_blocked_by(&self, task_id: &str) -> Vec<String>
Get the list of task IDs that task_id is blocked by.
Sourcepub fn get_blocks(&self, task_id: &str) -> Vec<String>
pub fn get_blocks(&self, task_id: &str) -> Vec<String>
Get the list of task IDs that task_id blocks.
Sourcepub fn is_ready(&self, task_id: &str, tasks: &[TaskFile]) -> bool
pub fn is_ready(&self, task_id: &str, tasks: &[TaskFile]) -> bool
Check whether a task is ready to run (all its dependencies are completed or deleted).
Sourcepub fn to_mermaid(&self, tasks: &[TaskFile]) -> String
pub fn to_mermaid(&self, tasks: &[TaskFile]) -> String
Export the dependency graph as a Mermaid diagram.
Nodes are colored by status:
- Pending: light gray
- InProgress: light blue
- Completed: light green
- Deleted: light pink
Edges represent blocked_by relationships: dep --> task.
Sourcepub fn to_dot(&self, tasks: &[TaskFile]) -> String
pub fn to_dot(&self, tasks: &[TaskFile]) -> String
Export the dependency graph as a Graphviz DOT diagram.
Same information as to_mermaid but in DOT syntax.
Sourcepub fn critical_path(&self, tasks: &[TaskFile]) -> Vec<String>
pub fn critical_path(&self, tasks: &[TaskFile]) -> Vec<String>
Compute the critical path (longest dependency chain) through the graph.
Uses topological sort + dynamic programming:
longest[node] = max(longest[dep] + 1) for each dependency.
Deleted tasks are excluded from the computation. Returns task IDs in dependency-first order (root → leaf).
Sourcepub fn to_terminal(&self, tasks: &[TaskFile]) -> String
pub fn to_terminal(&self, tasks: &[TaskFile]) -> String
Render the DAG as a terminal-friendly Unicode diagram with ANSI colors.
Groups tasks by topological level (phase) and draws connectors. Status is shown with colored symbols:
○Pending (gray),◉InProgress (blue),●Completed (green),✗Deleted (red)
Task DAG ─────────────────────────────────
Phase 0
├── ● #1 CC: Concurrency analysis
├── ● #2 Codex: Security audit
└── ● #3 Gemini: API design review
│
▼
Phase 1
├── ◉ #4 Codex: Fix proposals ← #1, #2
└── ○ #5 Gemini: Refactoring ← #2, #3
│
▼
Phase 2
└── ○ #6 CC: Final synthesis ← #4, #5Sourcepub fn to_terminal_plain(&self, tasks: &[TaskFile]) -> String
pub fn to_terminal_plain(&self, tasks: &[TaskFile]) -> String
Render the DAG as a plain-text terminal diagram (no ANSI colors).
Identical layout to to_terminal but without
escape sequences, suitable for logging or file output.
Sourcepub fn topological_sort(&self) -> Result<Vec<String>>
pub fn topological_sort(&self) -> Result<Vec<String>>
Compute a topological ordering of the tasks (Kahn’s algorithm).
Returns task IDs in an order where dependencies come before dependents. Returns an error if the graph contains a cycle.
Trait Implementations§
Source§impl Clone for DependencyGraph
impl Clone for DependencyGraph
Source§fn clone(&self) -> DependencyGraph
fn clone(&self) -> DependencyGraph
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DependencyGraph
impl RefUnwindSafe for DependencyGraph
impl Send for DependencyGraph
impl Sync for DependencyGraph
impl Unpin for DependencyGraph
impl UnwindSafe for DependencyGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more