pub struct Engine {
pub db: PgPool,
pub search_index: Arc<RwLock<SearchIndex>>,
pub parser: Arc<ParserRegistry>,
pub storage_path: PathBuf,
/* private fields */
}Expand description
The central orchestration layer that ties together Git storage, language parsing, the semantic graph stores, and full-text search.
Internally concurrent: all methods take &self. The SearchIndex is
wrapped in an RwLock (write for mutations, read for queries), and
per-repo Git operations are serialised via repo_locks.
Fields§
§db: PgPool§search_index: Arc<RwLock<SearchIndex>>§parser: Arc<ParserRegistry>§storage_path: PathBufImplementations§
Source§impl Engine
impl Engine
Sourcepub fn new(storage_path: PathBuf, db: PgPool) -> Result<Self>
pub fn new(storage_path: PathBuf, db: PgPool) -> Result<Self>
Create a new Engine instance.
Initialises all graph stores from the provided PgPool, creates the
ParserRegistry with Rust/TypeScript/Python parsers, and opens (or
creates) a Tantivy SearchIndex at storage_path/search_index.
Sourcepub fn symbol_store(&self) -> &SymbolStore
pub fn symbol_store(&self) -> &SymbolStore
Returns a reference to the symbol store for direct DB queries.
Sourcepub fn changeset_store(&self) -> &ChangesetStore
pub fn changeset_store(&self) -> &ChangesetStore
Returns a reference to the changeset store.
Sourcepub fn pipeline_store(&self) -> &PipelineStore
pub fn pipeline_store(&self) -> &PipelineStore
Returns a reference to the pipeline store.
Sourcepub fn workspace_manager(&self) -> &WorkspaceManager
pub fn workspace_manager(&self) -> &WorkspaceManager
Returns a reference to the workspace manager.
Sourcepub fn call_graph_store(&self) -> &CallGraphStore
pub fn call_graph_store(&self) -> &CallGraphStore
Returns a reference to the call graph store for direct DB queries.
Sourcepub fn dep_store(&self) -> &DependencyStore
pub fn dep_store(&self) -> &DependencyStore
Returns a reference to the dependency store for direct DB queries.
Sourcepub fn parser(&self) -> &ParserRegistry
pub fn parser(&self) -> &ParserRegistry
Returns a reference to the parser registry.
Sourcepub fn repo_lock(&self, repo_id: RepoId) -> Arc<RwLock<()>>
pub fn repo_lock(&self, repo_id: RepoId) -> Arc<RwLock<()>>
Returns a per-repo lock for serialising Git operations.
Creates a new lock on first access for a given repo_id.
Sourcepub fn remove_repo_lock(&self, repo_id: RepoId)
pub fn remove_repo_lock(&self, repo_id: RepoId)
Remove the repo lock entry for a deleted repo.
Sourcepub async fn create_repo(&self, name: &str) -> Result<RepoId>
pub async fn create_repo(&self, name: &str) -> Result<RepoId>
Create a new repository.
Generates a UUID, initialises a Git repository at
storage_path/repos/<uuid>, inserts a row into the repositories
table, and returns the new RepoId.
Sourcepub async fn get_repo(&self, name: &str) -> Result<(RepoId, GitRepository)>
pub async fn get_repo(&self, name: &str) -> Result<(RepoId, GitRepository)>
Look up a repository by name.
Returns the RepoId and an opened GitRepository handle.
Sourcepub async fn get_repo_by_db_id(
&self,
repo_id: RepoId,
) -> Result<(RepoId, GitRepository)>
pub async fn get_repo_by_db_id( &self, repo_id: RepoId, ) -> Result<(RepoId, GitRepository)>
Look up a repository by its UUID.
Returns the RepoId and an opened GitRepository handle.
Sourcepub async fn index_repo(
&self,
repo_id: RepoId,
git_repo: &GitRepository,
) -> Result<()>
pub async fn index_repo( &self, repo_id: RepoId, git_repo: &GitRepository, ) -> Result<()>
Perform a full index of a repository.
Walks the working directory (skipping .git), parses every file with a
supported extension, and populates the symbol table, type info store,
call graph, and full-text search index.
Sourcepub async fn update_files(
&self,
repo_id: RepoId,
git_repo: &GitRepository,
changed_files: &[PathBuf],
) -> Result<()>
pub async fn update_files( &self, repo_id: RepoId, git_repo: &GitRepository, changed_files: &[PathBuf], ) -> Result<()>
Incrementally re-index a set of changed files.
For each path: deletes old symbols and call edges, re-parses, and upserts the new data.
Sourcepub async fn update_files_by_root(
&self,
repo_id: RepoId,
root: &Path,
changed_files: &[PathBuf],
) -> Result<()>
pub async fn update_files_by_root( &self, repo_id: RepoId, root: &Path, changed_files: &[PathBuf], ) -> Result<()>
Incrementally re-index a set of changed files, given the repository root path directly.
This variant avoids holding a GitRepository reference (which is
!Sync) across .await points, making the resulting future Send.
Sourcepub async fn query_symbols(
&self,
repo_id: RepoId,
query: &str,
max_results: usize,
) -> Result<Vec<Symbol>>
pub async fn query_symbols( &self, repo_id: RepoId, query: &str, max_results: usize, ) -> Result<Vec<Symbol>>
Search for symbols matching a free-text query.
Uses Tantivy full-text search to find candidate SymbolIds, then
fetches the full Symbol objects from the database.
Sourcepub async fn get_call_graph(
&self,
_repo_id: RepoId,
symbol_id: SymbolId,
) -> Result<(Vec<Symbol>, Vec<Symbol>)>
pub async fn get_call_graph( &self, _repo_id: RepoId, symbol_id: SymbolId, ) -> Result<(Vec<Symbol>, Vec<Symbol>)>
Retrieve the call graph neighbourhood of a symbol.
Returns (callers, callees) — the full Symbol objects for every
direct caller and every direct callee.
Sourcepub async fn codebase_summary(&self, repo_id: RepoId) -> Result<CodebaseSummary>
pub async fn codebase_summary(&self, repo_id: RepoId) -> Result<CodebaseSummary>
Produce a high-level summary of the indexed codebase.
Queries the symbols table for distinct file extensions (→ languages), distinct file paths (→ total_files), and total row count (→ total_symbols).
Source§impl Engine
impl Engine
Sourcepub async fn tool_connect(
&self,
repo_name: &str,
intent: &str,
agent_id: &str,
session_id: Uuid,
changeset_id: Uuid,
) -> Result<ToolConnectResult>
pub async fn tool_connect( &self, repo_name: &str, intent: &str, agent_id: &str, session_id: Uuid, changeset_id: Uuid, ) -> Result<ToolConnectResult>
CONNECT — establish an isolated session workspace.
Sourcepub async fn tool_context(
&self,
session_id: Uuid,
query: &str,
depth: Option<&str>,
_include_tests: Option<bool>,
_max_tokens: Option<u32>,
) -> Result<ToolContextResult>
pub async fn tool_context( &self, session_id: Uuid, query: &str, depth: Option<&str>, _include_tests: Option<bool>, _max_tokens: Option<u32>, ) -> Result<ToolContextResult>
CONTEXT — semantic code search through the session workspace.
Sourcepub async fn tool_read_file(
&self,
session_id: Uuid,
path: &str,
) -> Result<ToolFileReadResult>
pub async fn tool_read_file( &self, session_id: Uuid, path: &str, ) -> Result<ToolFileReadResult>
FILE_READ — read a file through the session workspace overlay.
Sourcepub async fn tool_write_file(
&self,
session_id: Uuid,
changeset_id: Uuid,
path: &str,
content: &str,
) -> Result<ToolFileWriteResult>
pub async fn tool_write_file( &self, session_id: Uuid, changeset_id: Uuid, path: &str, content: &str, ) -> Result<ToolFileWriteResult>
FILE_WRITE — write a file to the session workspace overlay.
Sourcepub async fn tool_submit(
&self,
_session_id: Uuid,
changeset_id: Uuid,
_intent: &str,
) -> Result<ToolSubmitResult>
pub async fn tool_submit( &self, _session_id: Uuid, changeset_id: Uuid, _intent: &str, ) -> Result<ToolSubmitResult>
SUBMIT — submit the session’s workspace changes as a changeset.
Sourcepub async fn tool_session_status(
&self,
session_id: Uuid,
) -> Result<ToolStatusResult>
pub async fn tool_session_status( &self, session_id: Uuid, ) -> Result<ToolStatusResult>
SESSION_STATUS — get the current workspace state.
Sourcepub async fn tool_list_files(
&self,
session_id: Uuid,
prefix: Option<&str>,
) -> Result<ToolFileListResult>
pub async fn tool_list_files( &self, session_id: Uuid, prefix: Option<&str>, ) -> Result<ToolFileListResult>
LIST_FILES — list files visible in the session workspace.
Sourcepub async fn tool_verify_prepare(
&self,
session_id: Uuid,
) -> Result<(Uuid, String)>
pub async fn tool_verify_prepare( &self, session_id: Uuid, ) -> Result<(Uuid, String)>
VERIFY — prepare a session’s changeset for verification.
Returns (changeset_id, repo_name) after validating the session,
checking the changeset, and updating its status to “verifying”.
The actual runner invocation must be done by the caller (since
dk-runner depends on dk-engine, not the other way around).
Sourcepub async fn tool_verify_finalize(
&self,
changeset_id: Uuid,
passed: bool,
) -> Result<()>
pub async fn tool_verify_finalize( &self, changeset_id: Uuid, passed: bool, ) -> Result<()>
VERIFY — finalize after the runner has completed.
Updates the changeset status to “approved” or “rejected” based on whether all steps passed.
Sourcepub async fn tool_merge(
&self,
session_id: Uuid,
message: Option<&str>,
) -> Result<ToolMergeResult>
pub async fn tool_merge( &self, session_id: Uuid, message: Option<&str>, ) -> Result<ToolMergeResult>
MERGE — merge the verified changeset into a Git commit.
Auto Trait Implementations§
impl Freeze for Engine
impl !RefUnwindSafe for Engine
impl Send for Engine
impl Sync for Engine
impl Unpin for Engine
impl UnsafeUnpin for Engine
impl !UnwindSafe for Engine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more