MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / expand_subgraph

Method expand_subgraph

src/context/builder.rs:297–376  ·  view source on GitHub ↗

Expands the subgraph around entry points using BFS traversal.

(
        &self,
        entry_points: &[Node],
        options: &BuildContextOptions,
    )

Source from the content-addressed store, hash-verified

295
296 /// Expands the subgraph around entry points using BFS traversal.
297 async fn expand_subgraph(
298 &self,
299 entry_points: &[Node],
300 options: &BuildContextOptions,
301 ) -> Result<Subgraph> {
302 debug_assert!(
303 options.traversal_depth > 0,
304 "traversal_depth must be positive"
305 );
306 debug_assert!(
307 options.max_nodes > 0,
308 "max_nodes must be positive for expand_subgraph"
309 );
310 let traverser = GraphTraverser::new(self.db);
311 let mut all_nodes: Vec<Node> = Vec::new();
312 let mut all_edges: Vec<Edge> = Vec::new();
313 let mut all_roots: Vec<String> = Vec::new();
314 let mut seen_node_ids: HashSet<String> = HashSet::new();
315 let mut seen_edge_keys: HashSet<(String, String, String)> = HashSet::new();
316
317 let traversal_opts = TraversalOptions {
318 max_depth: options.traversal_depth as u32,
319 edge_kinds: None,
320 node_kinds: None,
321 direction: TraversalDirection::Both,
322 limit: options.max_nodes as u32,
323 include_start: true,
324 };
325
326 for node in entry_points {
327 let sub = traverser.traverse_bfs(&node.id, &traversal_opts).await?;
328
329 for root in sub.roots {
330 if !all_roots.contains(&root) {
331 all_roots.push(root);
332 }
333 }
334
335 for n in sub.nodes {
336 if seen_node_ids.insert(n.id.clone()) {
337 all_nodes.push(n);
338 }
339 }
340
341 for e in sub.edges {
342 let key = (
343 e.source.clone(),
344 e.target.clone(),
345 e.kind.as_str().to_string(),
346 );
347 if seen_edge_keys.insert(key) {
348 all_edges.push(e);
349 }
350 }
351
352 if all_nodes.len() >= options.max_nodes {
353 break;
354 }

Callers 2

build_contextMethod · 0.80
find_relevant_contextMethod · 0.80

Calls 6

traverse_bfsMethod · 0.80
pushMethod · 0.80
insertMethod · 0.80
collectMethod · 0.80
containsMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected