Skip to main content

Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

The core execution engine for CODA.

Manages project configuration, prompt templates, and orchestrates interactions with the Claude Agent SDK.

Implementations§

Source§

impl Engine

Source

pub async fn new(project_root: PathBuf) -> Result<Self, CoreError>

Creates a new engine for the given project root.

Loads configuration from .coda/config.yml (falling back to defaults if the file doesn’t exist), initializes the prompt manager with built-in templates, and loads any custom templates from configured extra directories.

§Errors

Returns CoreError if configuration parsing fails or template loading encounters an error.

Source

pub fn project_root(&self) -> &Path

Returns a reference to the project root directory.

Source

pub fn prompt_manager(&self) -> &PromptManager

Returns a reference to the prompt manager.

Source

pub fn config(&self) -> &CodaConfig

Returns a reference to the project configuration.

Source

pub fn git(&self) -> &dyn GitOps

Returns a reference to the git operations implementation.

Source

pub fn gh(&self) -> &dyn GhOps

Returns a reference to the GitHub CLI operations implementation.

Source

pub async fn init(&self) -> Result<(), CoreError>

Initializes the current repository as a CODA project.

The init flow performs two agent calls:

  1. query(Planner) with init/analyze_repo to analyze the repository structure, tech stack, and architecture.
  2. query(Coder) with init/setup_project to create .coda/, .trees/, config.yml, .coda.md, and update .gitignore.
§Errors

Returns CoreError::ConfigError if the project is already initialized (.coda/ exists), or CoreError::AgentError if agent calls fail.

Source

pub fn plan(&self, feature_slug: &str) -> Result<PlanSession, CoreError>

Starts an interactive planning session for a feature.

Validates the slug format and checks for duplicate features before creating a PlanSession wrapping a ClaudeClient with the Planner profile for multi-turn conversation. The session must be explicitly connected and finalized by the caller (typically the CLI layer).

§Errors

Returns CoreError::PlanError if the slug is invalid or a feature with the same slug already exists. Returns other CoreError variants if the session cannot be created.

Source

pub fn list_features(&self) -> Result<Vec<FeatureState>, CoreError>

Lists all features: active worktrees from .trees/ and merged features from .coda/.

Delegates to FeatureScanner::list.

§Errors

Returns CoreError::ConfigError if neither .trees/ nor .coda/ contains any features and .trees/ does not exist.

Source

pub fn feature_status( &self, feature_slug: &str, ) -> Result<FeatureState, CoreError>

Returns detailed state for a specific feature identified by its slug.

Delegates to FeatureScanner::get.

§Errors

Returns CoreError::ConfigError if .trees/ does not exist, or CoreError::StateError if no matching feature is found.

Source

pub async fn run( &self, feature_slug: &str, progress_tx: Option<UnboundedSender<RunEvent>>, ) -> Result<Vec<TaskResult>, CoreError>

Executes a feature development run through all phases.

Reads state.yml and resumes from the last completed phase. Uses a single continuous ClaudeClient session with the Coder profile to execute setup → implement → test → review → verify → PR.

When progress_tx is provided, emits RunEvents for real-time progress display.

§Errors

Returns CoreError if the runner cannot be created or any phase fails after all retries.

Source

pub fn scan_cleanable_worktrees( &self, ) -> Result<Vec<CleanedWorktree>, CoreError>

Cleans up worktrees whose corresponding PR has been merged or closed.

For each feature in .trees/:

  1. If state.yml contains a PR number, queries its status via gh pr view.
  2. Otherwise, queries gh pr list --head <branch> to discover the PR.
  3. If the PR is MERGED or CLOSED, removes the worktree and deletes the local branch.

Scans features and returns candidates whose PR is merged or closed.

Does not delete anything. Use remove_worktrees to perform the actual removal after user confirmation.

§Errors

Returns CoreError if .trees/ does not exist.

Source

pub fn remove_worktrees( &self, candidates: &[CleanedWorktree], ) -> Result<Vec<CleanedWorktree>, CoreError>

Removes worktrees and branches for the given candidates.

For each candidate, removes the git worktree, deletes the local branch, and cleans up the corresponding log directory at .coda/<slug>/logs/.

Designed to be called after scan_cleanable_worktrees and user confirmation.

§Errors

Returns CoreError if a git operation fails during removal.

Source

pub fn clean_logs(&self) -> Result<Vec<String>, CoreError>

Removes log directories for all features under .coda/*/logs/.

Scans the .coda/ directory for feature subdirectories that contain a logs/ child, deletes each one, and returns the list of feature slugs whose logs were successfully cleaned.

§Errors

Returns CoreError::ConfigError if .coda/ cannot be read.

Trait Implementations§

Source§

impl Debug for Engine

Source§

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

Formats the value using the given formatter. Read more

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