Skip to main content

BranchEngine

Struct BranchEngine 

Source
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

Source

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.

Source

pub async fn open(config: BranchConfig) -> BranchResult<Self>

Opens an existing workspace without creating a new trunk.

Source

pub fn config(&self) -> &BranchConfig

Returns the engine configuration.

Source

pub fn store(&self) -> Arc<BranchStore>

Returns the shared branch store.

Source

pub fn dag(&self) -> Arc<DagGraph>

Returns the shared DAG graph.

Source

pub fn lifecycle(&self) -> Arc<BranchLifecycle>

Returns the lifecycle coordinator.

Source

pub async fn get(&self, id: Uuid) -> BranchResult<Branch>

Retrieves a branch by ID.

Source

pub async fn get_by_name(&self, name: &str) -> BranchResult<Branch>

Retrieves a branch by human-readable name within the workspace.

Source

pub async fn list( &self, status: Option<BranchStatus>, ) -> BranchResult<Vec<Branch>>

Lists all branches in the workspace, optionally filtered by status.

Source

pub async fn trunk(&self) -> BranchResult<Branch>

Returns the trunk branch.

Source

pub async fn fork( &self, parent_id: Uuid, name: &str, description: Option<&str>, ) -> BranchResult<Branch>

Forks a new branch from parent_id.

Source

pub async fn fork_trunk(&self, name: &str) -> BranchResult<Branch>

Forks a new branch from the trunk.

Source

pub async fn discard(&self, id: Uuid) -> BranchResult<()>

Discards a branch, marking it as inactive.

Source

pub async fn archive(&self, id: Uuid) -> BranchResult<()>

Archives a branch.

Source

pub async fn diff(&self, a: Uuid, b: Uuid) -> BranchResult<DiffResult>

Computes the diff between two branches.

Source

pub async fn compare_branches( &self, a: Uuid, b: Uuid, ) -> BranchResult<DiffResult>

Compares two branches using the same semantics as Self::diff.

Source

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.

Source

pub async fn merge_preview( &self, source: Uuid, target: Uuid, ) -> BranchResult<MergePreview>

Previews a three-way merge without applying any changes.

Source

pub async fn commit(&self, cherry: CherryPick) -> BranchResult<CommitResult>

Executes a selective cherry-pick commit.

Source

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.

Source

pub async fn commit_to_trunk( &self, source_id: Uuid, ) -> BranchResult<CommitResult>

Commits all entities from source_id to the trunk branch.

Source

pub async fn simulate<F, Fut>( &self, parent_id: Uuid, scenario: SimulationScenario, agent_fn: F, ) -> BranchResult<EvaluationReport>
where F: FnOnce(SqlitePool) -> Fut, Fut: Future<Output = BranchResult<Value>>,

Runs an agent simulation in an isolated sandbox branch.

Returns an evaluation report with diff, metrics, and a promotion recommendation.

Source

pub async fn lineage(&self, branch_id: Uuid) -> BranchResult<Vec<Uuid>>

Returns the ancestor lineage of a branch as an ordered list (root-first).

Source

pub async fn dag_dot(&self) -> BranchResult<String>

Exports the branch DAG as a Graphviz DOT string.

Source

pub async fn metrics(&self, branch_id: Uuid) -> BranchResult<BranchMetrics>

Returns up-to-date metrics for the given branch.

Source

pub async fn workspace_report(&self) -> BranchResult<WorkspaceReport>

Generates a workspace-wide metrics report.

Source

pub async fn gc(&self) -> BranchResult<GcReport>

Runs snapshot garbage collection, deleting orphaned and discarded branch data.

Source

pub async fn start_gc_scheduler(&self) -> BranchResult<()>

Starts the background GC scheduler if it is not already running.

Source

pub async fn stop_gc_scheduler(&self) -> BranchResult<()>

Stops the background GC scheduler and waits for shutdown completion.

Source

pub async fn shutdown(&self) -> BranchResult<()>

Gracefully shuts down background tasks owned by the engine.

Trait Implementations§

Source§

impl Clone for BranchEngine

Source§

fn clone(&self) -> BranchEngine

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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