pub struct BranchEngine { /* private fields */ }Expand description
Unified coordinator for all claw-branch capabilities.
BranchEngine is the primary entry point for library consumers. It owns all
subsystems and exposes a single, consistent async API.
This engine does not perform authorization checks. Use it when your runtime already validates caller permissions externally.
For workspace-scoped authorization checks at this crate boundary, enable the
guarded feature and use GuardedBranchEngine.
§Quick-start
use claw_branch::{BranchConfig, BranchEngine};
use std::path::PathBuf;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let config = BranchConfig::builder()
.workspace_dir(PathBuf::from("/tmp/myproject"))
.build()?;
let engine = BranchEngine::new(config, Path::new("/data/trunk.db")).await?;
let feature = engine.fork_trunk("feature/my-idea").await?;
let diff = engine.diff(engine.trunk().await?.id, feature.id).await?;
println!("{} entities changed", diff.stats.modified);
Ok(())
}Implementations§
Source§impl BranchEngine
impl BranchEngine
Sourcepub async fn new(
config: BranchConfig,
trunk_db_path: &Path,
) -> BranchResult<Self>
pub async fn new( config: BranchConfig, trunk_db_path: &Path, ) -> BranchResult<Self>
Creates a new workspace, initialising all subsystems and creating the trunk branch.
trunk_db_path is the source database that will be copied into the trunk branch snapshot.
Sourcepub async fn open(config: BranchConfig) -> BranchResult<Self>
pub async fn open(config: BranchConfig) -> BranchResult<Self>
Opens an existing workspace without creating a new trunk.
Sourcepub fn config(&self) -> &BranchConfig
pub fn config(&self) -> &BranchConfig
Returns the engine configuration.
Sourcepub fn store(&self) -> Arc<BranchStore>
pub fn store(&self) -> Arc<BranchStore>
Returns the shared branch store.
Sourcepub fn lifecycle(&self) -> Arc<BranchLifecycle>
pub fn lifecycle(&self) -> Arc<BranchLifecycle>
Returns the lifecycle coordinator.
Sourcepub async fn get(&self, id: Uuid) -> BranchResult<Branch>
pub async fn get(&self, id: Uuid) -> BranchResult<Branch>
Retrieves a branch by ID.
Sourcepub async fn get_by_name(&self, name: &str) -> BranchResult<Branch>
pub async fn get_by_name(&self, name: &str) -> BranchResult<Branch>
Retrieves a branch by human-readable name within the workspace.
Sourcepub async fn list(
&self,
status: Option<BranchStatus>,
) -> BranchResult<Vec<Branch>>
pub async fn list( &self, status: Option<BranchStatus>, ) -> BranchResult<Vec<Branch>>
Lists all branches in the workspace, optionally filtered by status.
Sourcepub async fn trunk(&self) -> BranchResult<Branch>
pub async fn trunk(&self) -> BranchResult<Branch>
Returns the trunk branch.
Sourcepub async fn fork(
&self,
parent_id: Uuid,
name: &str,
description: Option<&str>,
) -> BranchResult<Branch>
pub async fn fork( &self, parent_id: Uuid, name: &str, description: Option<&str>, ) -> BranchResult<Branch>
Forks a new branch from parent_id.
Sourcepub async fn fork_trunk(&self, name: &str) -> BranchResult<Branch>
pub async fn fork_trunk(&self, name: &str) -> BranchResult<Branch>
Forks a new branch from the trunk.
Sourcepub async fn discard(&self, id: Uuid) -> BranchResult<()>
pub async fn discard(&self, id: Uuid) -> BranchResult<()>
Discards a branch, marking it as inactive.
Sourcepub async fn archive(&self, id: Uuid) -> BranchResult<()>
pub async fn archive(&self, id: Uuid) -> BranchResult<()>
Archives a branch.
Sourcepub async fn diff(&self, a: Uuid, b: Uuid) -> BranchResult<DiffResult>
pub async fn diff(&self, a: Uuid, b: Uuid) -> BranchResult<DiffResult>
Computes the diff between two branches.
Sourcepub async fn compare_branches(
&self,
a: Uuid,
b: Uuid,
) -> BranchResult<DiffResult>
pub async fn compare_branches( &self, a: Uuid, b: Uuid, ) -> BranchResult<DiffResult>
Compares two branches using the same semantics as Self::diff.
Sourcepub async fn merge(
&self,
source: Uuid,
target: Uuid,
strategy: MergeStrategy,
) -> BranchResult<MergeResult>
pub async fn merge( &self, source: Uuid, target: Uuid, strategy: MergeStrategy, ) -> BranchResult<MergeResult>
Merges source into target using the given strategy.
Uses the parent of source as the merge base. Falls back to target as base
when no explicit common ancestor is available.
Sourcepub async fn merge_preview(
&self,
source: Uuid,
target: Uuid,
) -> BranchResult<MergePreview>
pub async fn merge_preview( &self, source: Uuid, target: Uuid, ) -> BranchResult<MergePreview>
Previews a three-way merge without applying any changes.
Sourcepub async fn commit(&self, cherry: CherryPick) -> BranchResult<CommitResult>
pub async fn commit(&self, cherry: CherryPick) -> BranchResult<CommitResult>
Executes a selective cherry-pick commit.
Sourcepub async fn cherry_pick(
&self,
source_id: Uuid,
target_id: Uuid,
selections: Vec<EntitySelection>,
message: Option<String>,
) -> BranchResult<CommitResult>
pub async fn cherry_pick( &self, source_id: Uuid, target_id: Uuid, selections: Vec<EntitySelection>, message: Option<String>, ) -> BranchResult<CommitResult>
Cherry-picks selected entities from source into target.
Sourcepub async fn commit_to_trunk(
&self,
source_id: Uuid,
) -> BranchResult<CommitResult>
pub async fn commit_to_trunk( &self, source_id: Uuid, ) -> BranchResult<CommitResult>
Commits all entities from source_id to the trunk branch.
Sourcepub async fn simulate<F, Fut>(
&self,
parent_id: Uuid,
scenario: SimulationScenario,
agent_fn: F,
) -> BranchResult<EvaluationReport>
pub async fn simulate<F, Fut>( &self, parent_id: Uuid, scenario: SimulationScenario, agent_fn: F, ) -> BranchResult<EvaluationReport>
Runs an agent simulation in an isolated sandbox branch.
Returns an evaluation report with diff, metrics, and a promotion recommendation.
Sourcepub async fn lineage(&self, branch_id: Uuid) -> BranchResult<Vec<Uuid>>
pub async fn lineage(&self, branch_id: Uuid) -> BranchResult<Vec<Uuid>>
Returns the ancestor lineage of a branch as an ordered list (root-first).
Sourcepub async fn dag_dot(&self) -> BranchResult<String>
pub async fn dag_dot(&self) -> BranchResult<String>
Exports the branch DAG as a Graphviz DOT string.
Sourcepub async fn metrics(&self, branch_id: Uuid) -> BranchResult<BranchMetrics>
pub async fn metrics(&self, branch_id: Uuid) -> BranchResult<BranchMetrics>
Returns up-to-date metrics for the given branch.
Sourcepub async fn workspace_report(&self) -> BranchResult<WorkspaceReport>
pub async fn workspace_report(&self) -> BranchResult<WorkspaceReport>
Generates a workspace-wide metrics report.
Sourcepub async fn gc(&self) -> BranchResult<GcReport>
pub async fn gc(&self) -> BranchResult<GcReport>
Runs snapshot garbage collection, deleting orphaned and discarded branch data.
Sourcepub async fn start_gc_scheduler(&self) -> BranchResult<()>
pub async fn start_gc_scheduler(&self) -> BranchResult<()>
Starts the background GC scheduler if it is not already running.
Sourcepub async fn stop_gc_scheduler(&self) -> BranchResult<()>
pub async fn stop_gc_scheduler(&self) -> BranchResult<()>
Stops the background GC scheduler and waits for shutdown completion.
Sourcepub async fn shutdown(&self) -> BranchResult<()>
pub async fn shutdown(&self) -> BranchResult<()>
Gracefully shuts down background tasks owned by the engine.
Trait Implementations§
Source§impl Clone for BranchEngine
impl Clone for BranchEngine
Source§fn clone(&self) -> BranchEngine
fn clone(&self) -> BranchEngine
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BranchEngine
impl !RefUnwindSafe for BranchEngine
impl Send for BranchEngine
impl Sync for BranchEngine
impl Unpin for BranchEngine
impl UnsafeUnpin for BranchEngine
impl !UnwindSafe for BranchEngine
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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