Skip to main content

keel_core/
store.rs

1use crate::types::{
2    EdgeChange, EdgeDirection, GraphEdge, GraphError, GraphNode, ModuleProfile, NodeChange,
3};
4
5/// FROZEN CONTRACT — GraphStore trait.
6///
7/// Agent A owns this interface. Agents B and C consume it.
8/// Do NOT modify this trait signature without coordination.
9pub trait GraphStore {
10    /// Look up a node by its content hash.
11    fn get_node(&self, hash: &str) -> Option<GraphNode>;
12
13    /// Look up a node by its internal ID.
14    fn get_node_by_id(&self, id: u64) -> Option<GraphNode>;
15
16    /// Get edges connected to a node in the specified direction.
17    fn get_edges(&self, node_id: u64, direction: EdgeDirection) -> Vec<GraphEdge>;
18
19    /// Get the module profile for a given module node.
20    fn get_module_profile(&self, module_id: u64) -> Option<ModuleProfile>;
21
22    /// Get all nodes in a specific file.
23    fn get_nodes_in_file(&self, file_path: &str) -> Vec<GraphNode>;
24
25    /// Get all module-type nodes in the graph.
26    fn get_all_modules(&self) -> Vec<GraphNode>;
27
28    /// Apply a batch of node changes (add, update, remove).
29    fn update_nodes(&mut self, changes: Vec<NodeChange>) -> Result<(), GraphError>;
30
31    /// Apply a batch of edge changes (add, remove).
32    fn update_edges(&mut self, changes: Vec<EdgeChange>) -> Result<(), GraphError>;
33
34    /// Get previous hashes for rename tracking.
35    fn get_previous_hashes(&self, node_id: u64) -> Vec<String>;
36
37    /// Find modules whose function_name_prefixes contain the given prefix,
38    /// excluding modules in the specified file. Used by W001 placement check.
39    fn find_modules_by_prefix(&self, prefix: &str, exclude_file: &str) -> Vec<ModuleProfile>;
40
41    /// Find nodes with the given name and kind, excluding a specific file.
42    /// Used by W002 duplicate_name check.
43    fn find_nodes_by_name(&self, name: &str, kind: &str, exclude_file: &str) -> Vec<GraphNode>;
44}