Skip to main content

Graph

Struct Graph 

Source
pub struct Graph {
    pub project: Option<ProjectMeta>,
    pub nodes: Vec<Node>,
    pub edges: Vec<Edge>,
}
Expand description

A complete GID graph with nodes and edges.

Fields§

§project: Option<ProjectMeta>§nodes: Vec<Node>§edges: Vec<Edge>

Implementations§

Source§

impl Graph

Source

pub fn new() -> Self

Source

pub fn get_node(&self, id: &str) -> Option<&Node>

Source

pub fn get_node_mut(&mut self, id: &str) -> Option<&mut Node>

Source

pub fn add_node(&mut self, node: Node)

Source

pub fn remove_node(&mut self, id: &str) -> Option<Node>

Source

pub fn update_status(&mut self, id: &str, status: NodeStatus) -> bool

Source

pub fn add_edge(&mut self, edge: Edge)

Source

pub fn remove_edge(&mut self, from: &str, to: &str, relation: Option<&str>)

Source

pub fn add_edge_dedup(&mut self, edge: Edge) -> bool

Add an edge with deduplication check.

Returns true if the edge was added (new), false if it already existed. An edge is considered duplicate if the (from, to, relation) triple matches.

§Examples
use gid_core::{Graph, Edge};

let mut g = Graph::new();
let edge = Edge::new("a", "b", "depends_on");
assert!(g.add_edge_dedup(edge.clone())); // Returns true (new edge)
assert!(!g.add_edge_dedup(edge)); // Returns false (duplicate)
Source

pub fn add_feature(&mut self, name: &str, tasks: &[TaskSpec]) -> String

Create a feature node with task nodes and all edges in one operation.

  • Creates feat-{slug} feature node
  • Creates task-{feature_slug}-{task_slug} task nodes
  • Adds implements edges from each task to the feature
  • Adds depends_on edges between tasks per TaskSpec.deps (matched by title)
  • Returns the feature node ID
Source

pub fn add_task( &mut self, title: &str, for_feature: Option<&str>, depends_on: &[String], tags: &[String], priority: Option<u8>, ) -> String

Add a standalone task node (no parent feature required). Returns the task node ID.

Source

pub fn merge_feature_nodes( &mut self, feature_id: &str, incoming: Graph, ) -> (usize, usize)

Merge incoming nodes into this graph, scoped to a specific feature.

  1. Finds all existing task nodes that implements the target feature
  2. Removes those old task nodes (cascading edge cleanup via remove_node)
  3. Adds all incoming nodes
  4. Adds implements edges from incoming task nodes to the feature
  5. Adds incoming edges with deduplication

Returns (removed_count, added_count) for reporting.

Source

pub fn resolve_node(&self, reference: &str) -> Vec<&Node>

Resolve a node reference to actual node(s) using a 7-tier priority cascade.

Priority tiers (highest to lowest):

  1. Exact ID match
  2. Exact title match (case-insensitive)
  3. Structural segment match (:, -, / delimiters)
  4. Word segment match (_ delimiter)
  5. File path match
  6. Title substring match (case-insensitive)
  7. ID substring match (case-insensitive)

Returns a vector of matching nodes. Empty vector if no match found. May return multiple nodes if there’s ambiguity (e.g., multiple substring matches).

§Examples
use gid_core::{Graph, Node};

let mut g = Graph::new();
g.add_node(Node::new("feat-auth", "Authentication Feature"));
g.add_node(Node::new("impl-jwt", "Implement JWT validation"));

// Exact ID match
let results = g.resolve_node("feat-auth");
assert_eq!(results.len(), 1);
assert_eq!(results[0].id, "feat-auth");

// Case-insensitive title match
let results = g.resolve_node("authentication feature");
assert_eq!(results.len(), 1);

// No match
let results = g.resolve_node("nonexistent");
assert_eq!(results.len(), 0);
Source

pub fn edges_from(&self, id: &str) -> Vec<&Edge>

Source

pub fn edges_to(&self, id: &str) -> Vec<&Edge>

Source

pub fn code_nodes(&self) -> Vec<&Node>

Get all code nodes (source == “extract”)

Source

pub fn project_nodes(&self) -> Vec<&Node>

Get all project nodes (source == “project” or legacy None)

Source

pub fn code_edges(&self) -> Vec<&Edge>

Get all code edges (source == “extract”)

Source

pub fn project_edges(&self) -> Vec<&Edge>

Get all project edges (not code, not bridge)

Source

pub fn bridge_edges(&self) -> Vec<&Edge>

Get all bridge edges (source == “auto-bridge”)

Source

pub fn ready_tasks(&self) -> Vec<&Node>

Get tasks that are ready (todo + all depends_on are done). Only considers project nodes; code nodes are excluded.

Uses pre-built HashMaps for O(N+M) instead of O(N×M×N).

Source

pub fn tasks_by_status(&self, status: &NodeStatus) -> Vec<&Node>

Get tasks by status.

Source

pub fn summary(&self) -> GraphSummary

Summary statistics (counts only project nodes, not code nodes).

Source

pub fn summary_text(&self) -> String

Get a human-readable text summary of the graph state.

Source

pub fn health(&self) -> f64

Calculate graph health score (0.0 to 1.0).

Health is based on:

  • Progress: ratio of done tasks to total
  • Flow: ratio of ready tasks to remaining (non-blocked) tasks
  • Connectivity: graphs with edges are healthier than isolated nodes

Returns 1.0 for a fully complete graph, 0.0 for an empty or stuck graph.

Source

pub fn mark_task_done(&mut self, node_id: &str) -> bool

Mark a task as done. Returns true if found and updated.

Source

pub fn get_executable_tasks(&self) -> Vec<Task>

Get executable tasks (alias for ready_tasks, returns owned Task structs).

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

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 Graph

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Graph

Source§

fn default() -> Graph

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Graph

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl KnowledgeGraph for Graph

Source§

fn get_knowledge_mut(&mut self, node_id: &str) -> Option<&mut KnowledgeNode>

Get mutable access to a node’s knowledge storage
Source§

fn get_knowledge(&self, node_id: &str) -> Option<&KnowledgeNode>

Get read access to a node’s knowledge storage
Source§

fn get_incoming_edges(&self, node_id: &str) -> Vec<String>

Get edges pointing to a node (for upstream lookups)
Source§

impl KnowledgeManagement for Graph

Source§

fn store_finding(&mut self, node_id: &str, key: &str, value: &str) -> Result<()>

Store a finding in a node
Source§

fn get_finding(&self, node_id: &str, key: &str) -> Option<String>

Get a finding from a node or any upstream node
Source§

fn get_upstream_findings(&self, node_id: &str, key: &str) -> Option<String>

Get finding from upstream nodes recursively
Source§

fn cache_file(&mut self, node_id: &str, path: &str, content: &str) -> Result<()>

Cache file content in a node
Source§

fn get_cached_file(&self, node_id: &str, path: &str) -> Option<String>

Get cached file from this node or upstream
Source§

fn record_tool_call( &mut self, node_id: &str, tool_name: &str, summary: &str, ) -> Result<()>

Record a tool call
Source§

fn get_tool_history(&self, node_id: &str) -> Vec<ToolCallRecord>

Get all tool calls from this and upstream nodes
Source§

fn get_knowledge_context(&self, node_id: &str) -> String

Get all findings from this and upstream nodes as formatted context
Source§

fn collect_upstream_findings_all( &self, node_id: &str, findings: &mut HashMap<String, String>, )

Helper to collect all findings recursively
Source§

impl Serialize for Graph

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

§

impl UnwindSafe for Graph

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,