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
impl Engine
Sourcepub async fn new(project_root: PathBuf) -> Result<Self, CoreError>
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.
Sourcepub fn project_root(&self) -> &Path
pub fn project_root(&self) -> &Path
Returns a reference to the project root directory.
Sourcepub fn prompt_manager(&self) -> &PromptManager
pub fn prompt_manager(&self) -> &PromptManager
Returns a reference to the prompt manager.
Sourcepub fn config(&self) -> &CodaConfig
pub fn config(&self) -> &CodaConfig
Returns a reference to the project configuration.
Sourcepub fn gh(&self) -> &dyn GhOps
pub fn gh(&self) -> &dyn GhOps
Returns a reference to the GitHub CLI operations implementation.
Sourcepub async fn init(&self) -> Result<(), CoreError>
pub async fn init(&self) -> Result<(), CoreError>
Initializes the current repository as a CODA project.
The init flow performs two agent calls:
query(Planner)withinit/analyze_repoto analyze the repository structure, tech stack, and architecture.query(Coder)withinit/setup_projectto 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.
Sourcepub fn plan(&self, feature_slug: &str) -> Result<PlanSession, CoreError>
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.
Sourcepub fn list_features(&self) -> Result<Vec<FeatureState>, CoreError>
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.
Sourcepub fn feature_status(
&self,
feature_slug: &str,
) -> Result<FeatureState, CoreError>
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.
Sourcepub async fn run(
&self,
feature_slug: &str,
progress_tx: Option<UnboundedSender<RunEvent>>,
) -> Result<Vec<TaskResult>, CoreError>
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.
Sourcepub fn scan_cleanable_worktrees(
&self,
) -> Result<Vec<CleanedWorktree>, CoreError>
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/:
- If
state.ymlcontains a PR number, queries its status viagh pr view. - Otherwise, queries
gh pr list --head <branch>to discover the PR. - If the PR is
MERGEDorCLOSED, 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.
Sourcepub fn remove_worktrees(
&self,
candidates: &[CleanedWorktree],
) -> Result<Vec<CleanedWorktree>, CoreError>
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.
Sourcepub fn clean_logs(&self) -> Result<Vec<String>, CoreError>
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.