Skip to main content

gitcortex_core/
store.rs

1use std::path::Path;
2
3use crate::{
4    error::Result,
5    graph::{Edge, GraphDiff, Node},
6};
7
8/// Backend-agnostic interface for the knowledge graph store.
9///
10/// The v0.1 implementation is `KuzuGraphStore` (local embedded DB).
11/// A remote backend can be plugged in by implementing this trait without
12/// touching the indexer or MCP layers.
13pub trait GraphStore: Send + Sync {
14    // ── Write operations ─────────────────────────────────────────────────────
15
16    /// Apply an incremental diff to the named branch's graph.
17    fn apply_diff(&mut self, branch: &str, diff: &GraphDiff) -> Result<()>;
18
19    // ── Read operations ──────────────────────────────────────────────────────
20
21    /// Find all nodes matching `name` (exact, case-sensitive) on `branch`.
22    fn lookup_symbol(&self, branch: &str, name: &str) -> Result<Vec<Node>>;
23
24    /// Find all call-site nodes whose outgoing `Calls` edge points to a node
25    /// named `function_name` on `branch`.
26    fn find_callers(&self, branch: &str, function_name: &str) -> Result<Vec<Node>>;
27
28    /// List all top-level definitions in `file` on `branch`.
29    fn list_definitions(&self, branch: &str, file: &Path) -> Result<Vec<Node>>;
30
31    /// Return all nodes in `branch`'s graph.
32    fn list_all_nodes(&self, branch: &str) -> Result<Vec<Node>>;
33
34    /// Return all edges in `branch`'s graph.
35    fn list_all_edges(&self, branch: &str) -> Result<Vec<Edge>>;
36
37    /// Return the graph delta between two branches as a `GraphDiff`.
38    /// Nodes/edges present in `to` but not `from` are in `added_*`.
39    /// Nodes/edges present in `from` but not `to` are in `removed_*`.
40    fn branch_diff(&self, from: &str, to: &str) -> Result<GraphDiff>;
41
42    // ── Indexing state ───────────────────────────────────────────────────────
43
44    /// Last commit SHA successfully indexed for `branch`. `None` if the branch
45    /// has never been indexed.
46    fn last_indexed_sha(&self, branch: &str) -> Result<Option<String>>;
47
48    /// Persist the commit SHA after a successful index run.
49    fn set_last_indexed_sha(&mut self, branch: &str, sha: &str) -> Result<()>;
50}