Skip to main content

DependencyGraph

Struct DependencyGraph 

Source
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

Source

pub fn from_tasks(tasks: &[TaskFile]) -> Self

Build a dependency graph from a slice of tasks.

Source

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.

Source

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.

Source

pub fn get_blocked_by(&self, task_id: &str) -> Vec<String>

Get the list of task IDs that task_id is blocked by.

Source

pub fn get_blocks(&self, task_id: &str) -> Vec<String>

Get the list of task IDs that task_id blocks.

Source

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).

Source

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.

Source

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.

Source

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).

Source

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, #5
Source

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.

Source

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

Source§

fn clone(&self) -> DependencyGraph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DependencyGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more