Skip to main content

Engine

Struct Engine 

Source
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: PathBuf

Implementations§

Source§

impl Engine

Source

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.

Source

pub fn symbol_store(&self) -> &SymbolStore

Returns a reference to the symbol store for direct DB queries.

Source

pub fn changeset_store(&self) -> &ChangesetStore

Returns a reference to the changeset store.

Source

pub fn pipeline_store(&self) -> &PipelineStore

Returns a reference to the pipeline store.

Source

pub fn workspace_manager(&self) -> &WorkspaceManager

Returns a reference to the workspace manager.

Source

pub fn call_graph_store(&self) -> &CallGraphStore

Returns a reference to the call graph store for direct DB queries.

Source

pub fn dep_store(&self) -> &DependencyStore

Returns a reference to the dependency store for direct DB queries.

Source

pub fn parser(&self) -> &ParserRegistry

Returns a reference to the parser registry.

Source

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.

Source

pub fn remove_repo_lock(&self, repo_id: RepoId)

Remove the repo lock entry for a deleted repo.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

pub async fn tool_read_file( &self, session_id: Uuid, path: &str, ) -> Result<ToolFileReadResult>

FILE_READ — read a file through the session workspace overlay.

Source

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.

Source

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.

Source

pub async fn tool_session_status( &self, session_id: Uuid, ) -> Result<ToolStatusResult>

SESSION_STATUS — get the current workspace state.

Source

pub async fn tool_list_files( &self, session_id: Uuid, prefix: Option<&str>, ) -> Result<ToolFileListResult>

LIST_FILES — list files visible in the session workspace.

Source

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).

Source

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.

Source

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§

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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> Fruit for T
where T: Send + Downcast,