Skip to main content

CodeGraph

Struct CodeGraph 

Source
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

Source

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.

Source

pub fn extract_from_dir(dir: &Path) -> Self

Extract code graph from a directory.

Source

pub fn build_indexes(&mut self)

Build adjacency indexes for O(1) lookups.

Source

pub fn outgoing_edges(&self, node_id: &str) -> impl Iterator<Item = &CodeEdge>

Get outgoing edges from a node.

Source

pub fn incoming_edges(&self, node_id: &str) -> impl Iterator<Item = &CodeEdge>

Get incoming edges to a node.

Source

pub fn node_by_id(&self, node_id: &str) -> Option<&CodeNode>

Find node by id.

Source

pub fn get_callers(&self, node_id: &str) -> Vec<&CodeNode>

Get all callers of a function/method.

Source

pub fn get_callees(&self, node_id: &str) -> Vec<&CodeNode>

Get all callees of a function/method.

Source

pub fn get_dependencies(&self, node_id: &str) -> Vec<&CodeNode>

Get dependencies of a node (what it depends on)

Source

pub fn get_impact(&self, node_id: &str) -> Vec<&CodeNode>

Get nodes that depend on this node (impact analysis).

Source

pub fn find_relevant_nodes(&self, keywords: &[&str]) -> Vec<&CodeNode>

Find nodes matching keywords in name or path.

Source

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.

Source

pub fn format_impact_for_llm( &self, changed_node_ids: &[&str], repo_dir: &Path, ) -> String

Format impact analysis as context string for LLM

Source

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.

Source

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.

Source

pub fn bfs_path( &self, from: &str, to: &str, max_depth: usize, ) -> Option<Vec<String>>

BFS shortest path from from to to.

Source

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.

Source

pub fn extract_snippets( &self, nodes: &[&CodeNode], repo_dir: &Path, max_lines: usize, ) -> HashMap<String, String>

Extract code snippets for nodes.

Source

pub fn format_for_llm(&self, keywords: &[&str], max_chars: usize) -> String

Format graph for LLM context.

Source

pub fn grep_for_identifiers( &self, repo_dir: &Path, identifiers: &[&str], ) -> Vec<CodeNode>

Search for identifiers in repo via grep

Source

pub fn extract_keywords(problem_statement: &str) -> Vec<&str>

Extract keywords from a problem statement

Source

pub fn has_node(&self, file_path: &str, name: &str) -> bool

Check if graph has a node with given file and name

Source

pub fn find_node(&self, file_path: &str, name: &str) -> Option<&CodeNode>

Find a node by file and name

Source

pub fn add_file_nodes( &mut self, repo_dir: &Path, file_path: &Path, target_names: Option<&[String]>, ) -> Result<()>

Add nodes from a specific file

Source

pub fn get_schema(&self) -> String

Return graph schema information

Source

pub fn get_file_summary(&self, file_path: &str) -> String

Get file-level summary

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for CodeGraph

Source§

fn clone(&self) -> CodeGraph

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 CodeGraph

Source§

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

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

impl Default for CodeGraph

Source§

fn default() -> CodeGraph

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

impl<'de> Deserialize<'de> for CodeGraph

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 Serialize for CodeGraph

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§

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>,