pub struct CodeGraph {
pub nodes: Vec<CodeNode>,
pub edges: Vec<CodeEdge>,
pub outgoing: HashMap<String, Vec<usize>>,
pub incoming: HashMap<String, Vec<usize>>,
pub node_index: HashMap<String, usize>,
}Expand description
A code dependency graph extracted from source files.
Fields§
§nodes: Vec<CodeNode>§edges: Vec<CodeEdge>§outgoing: HashMap<String, Vec<usize>>Adjacency list: node_id → indices into self.edges (outgoing)
incoming: HashMap<String, Vec<usize>>Reverse adjacency list: node_id → indices into self.edges (incoming)
node_index: HashMap<String, usize>Node lookup: node_id → index into self.nodes
Implementations§
Source§impl CodeGraph
impl CodeGraph
Sourcepub fn extract_cached(
repo_dir: &Path,
repo_name: &str,
base_commit: &str,
) -> Self
pub fn extract_cached( repo_dir: &Path, repo_name: &str, base_commit: &str, ) -> Self
Extract with per-repo cache. Cache key = repo_name + base_commit. If a cached graph exists on disk, returns it instantly. Otherwise extracts fresh and saves to cache.
Sourcepub fn extract_from_dir(dir: &Path) -> Self
pub fn extract_from_dir(dir: &Path) -> Self
Extract code graph from a directory.
Sourcepub fn build_indexes(&mut self)
pub fn build_indexes(&mut self)
Build adjacency indexes for O(1) lookups.
Sourcepub fn outgoing_edges(&self, node_id: &str) -> impl Iterator<Item = &CodeEdge>
pub fn outgoing_edges(&self, node_id: &str) -> impl Iterator<Item = &CodeEdge>
Get outgoing edges from a node.
Sourcepub fn incoming_edges(&self, node_id: &str) -> impl Iterator<Item = &CodeEdge>
pub fn incoming_edges(&self, node_id: &str) -> impl Iterator<Item = &CodeEdge>
Get incoming edges to a node.
Sourcepub fn node_by_id(&self, node_id: &str) -> Option<&CodeNode>
pub fn node_by_id(&self, node_id: &str) -> Option<&CodeNode>
Find node by id.
Sourcepub fn get_callers(&self, node_id: &str) -> Vec<&CodeNode>
pub fn get_callers(&self, node_id: &str) -> Vec<&CodeNode>
Get all callers of a function/method.
Sourcepub fn get_callees(&self, node_id: &str) -> Vec<&CodeNode>
pub fn get_callees(&self, node_id: &str) -> Vec<&CodeNode>
Get all callees of a function/method.
Sourcepub fn get_dependencies(&self, node_id: &str) -> Vec<&CodeNode>
pub fn get_dependencies(&self, node_id: &str) -> Vec<&CodeNode>
Get dependencies of a node (what it depends on)
Sourcepub fn get_impact(&self, node_id: &str) -> Vec<&CodeNode>
pub fn get_impact(&self, node_id: &str) -> Vec<&CodeNode>
Get nodes that depend on this node (impact analysis).
Sourcepub fn find_relevant_nodes(&self, keywords: &[&str]) -> Vec<&CodeNode>
pub fn find_relevant_nodes(&self, keywords: &[&str]) -> Vec<&CodeNode>
Find nodes matching keywords in name or path.
Sourcepub fn impact_analysis(&self, changed_node_ids: &[&str]) -> ImpactReport<'_>
pub fn impact_analysis(&self, changed_node_ids: &[&str]) -> ImpactReport<'_>
Full impact analysis: given nodes to change, return affected nodes + tests
Find test files/functions related to given source nodes.
Sourcepub fn format_impact_for_llm(
&self,
changed_node_ids: &[&str],
repo_dir: &Path,
) -> String
pub fn format_impact_for_llm( &self, changed_node_ids: &[&str], repo_dir: &Path, ) -> String
Format impact analysis as context string for LLM
Sourcepub fn trace_causal_chains_from_symptoms(
&self,
symptom_node_ids: &[&str],
max_depth: usize,
max_chains: usize,
) -> Vec<CausalChain>
pub fn trace_causal_chains_from_symptoms( &self, symptom_node_ids: &[&str], max_depth: usize, max_chains: usize, ) -> Vec<CausalChain>
Trace causal chains from symptom nodes to potential root causes.
Sourcepub fn trace_causal_chains(
&self,
changed_node_ids: &[&str],
failed_p2p_tests: &[String],
failed_f2p_tests: &[String],
) -> String
pub fn trace_causal_chains( &self, changed_node_ids: &[&str], failed_p2p_tests: &[String], failed_f2p_tests: &[String], ) -> String
Trace causal chains from changed nodes to failed tests.
Sourcepub fn bfs_path(
&self,
from: &str,
to: &str,
max_depth: usize,
) -> Option<Vec<String>>
pub fn bfs_path( &self, from: &str, to: &str, max_depth: usize, ) -> Option<Vec<String>>
BFS shortest path from from to to.
Sourcepub fn get_node_summary(&self, node_id: &str, repo_dir: &Path) -> String
pub fn get_node_summary(&self, node_id: &str, repo_dir: &Path) -> String
Get a summary of a node: name, file, line, and first 15 lines of code.
Sourcepub fn extract_snippets(
&self,
nodes: &[&CodeNode],
repo_dir: &Path,
max_lines: usize,
) -> HashMap<String, String>
pub fn extract_snippets( &self, nodes: &[&CodeNode], repo_dir: &Path, max_lines: usize, ) -> HashMap<String, String>
Extract code snippets for nodes.
Sourcepub fn format_for_llm(&self, keywords: &[&str], max_chars: usize) -> String
pub fn format_for_llm(&self, keywords: &[&str], max_chars: usize) -> String
Format graph for LLM context.
Sourcepub fn grep_for_identifiers(
&self,
repo_dir: &Path,
identifiers: &[&str],
) -> Vec<CodeNode>
pub fn grep_for_identifiers( &self, repo_dir: &Path, identifiers: &[&str], ) -> Vec<CodeNode>
Search for identifiers in repo via grep
Sourcepub fn extract_keywords(problem_statement: &str) -> Vec<&str>
pub fn extract_keywords(problem_statement: &str) -> Vec<&str>
Extract keywords from a problem statement
Sourcepub fn has_node(&self, file_path: &str, name: &str) -> bool
pub fn has_node(&self, file_path: &str, name: &str) -> bool
Check if graph has a node with given file and name
Sourcepub fn find_node(&self, file_path: &str, name: &str) -> Option<&CodeNode>
pub fn find_node(&self, file_path: &str, name: &str) -> Option<&CodeNode>
Find a node by file and name
Sourcepub fn add_file_nodes(
&mut self,
repo_dir: &Path,
file_path: &Path,
target_names: Option<&[String]>,
) -> Result<()>
pub fn add_file_nodes( &mut self, repo_dir: &Path, file_path: &Path, target_names: Option<&[String]>, ) -> Result<()>
Add nodes from a specific file
Sourcepub fn get_schema(&self) -> String
pub fn get_schema(&self) -> String
Return graph schema information
Sourcepub fn get_file_summary(&self, file_path: &str) -> String
pub fn get_file_summary(&self, file_path: &str) -> String
Get file-level summary
Sourcepub fn analyze_test_failures(
&self,
changed_node_ids: &[&str],
failed_test_names: &[String],
_repo_dir: &Path,
) -> String
pub fn analyze_test_failures( &self, changed_node_ids: &[&str], failed_test_names: &[String], _repo_dir: &Path, ) -> String
Analyze test failures using graph structure. Given changed nodes and failed test names, trace call chains and explain WHY tests failed.
Sourcepub fn find_symptom_nodes(
&self,
problem_statement: &str,
test_names: &str,
) -> Vec<&CodeNode>
pub fn find_symptom_nodes( &self, problem_statement: &str, test_names: &str, ) -> Vec<&CodeNode>
Find symptom nodes from test names and issue text.
Parses test names (JSON array or newline-separated), finds matching test nodes. Also finds nodes mentioned in issue text (functions/classes in error messages/tracebacks). Returns combined list, tests first.
Sourcepub fn build_unified_graph(
&self,
relevant_nodes: &[&CodeNode],
snippets: &HashMap<String, String>,
issue_id: &str,
issue_description: &str,
) -> UnifiedGraphResult
pub fn build_unified_graph( &self, relevant_nodes: &[&CodeNode], snippets: &HashMap<String, String>, issue_id: &str, issue_description: &str, ) -> UnifiedGraphResult
Build a unified graph combining code nodes with task structure. Returns a simplified representation suitable for task planning.