pub struct ContextGraph<S> { /* private fields */ }Expand description
The embeddable core API: an agent runtime links this directly and calls
commit/checkout inline per turn.
Implementations§
Source§impl<S: CommitStore + RefStore> ContextGraph<S>
impl<S: CommitStore + RefStore> ContextGraph<S>
pub fn new(store: S) -> Self
pub fn store(&self) -> &S
Sourcepub async fn resolve(&self, target: &CheckoutTarget) -> Result<CommitId>
pub async fn resolve(&self, target: &CheckoutTarget) -> Result<CommitId>
Resolves a checkout target to a concrete commit id, without materializing.
§Errors
GraphError::CommitNotFoundif a commit target does not exist.GraphError::BranchNotFoundif a branch target does not exist.
Sourcepub async fn commit(
&self,
parent: Option<CommitId>,
author: Author,
delta: Delta,
metadata: Metadata,
) -> Result<CommitId>
pub async fn commit( &self, parent: Option<CommitId>, author: Author, delta: Delta, metadata: Metadata, ) -> Result<CommitId>
Creates a new commit as a child of parent (None for a root
commit). Content-addressed and idempotent: identical content always
returns the same id without creating a duplicate node. Does not move
any branch pointer — see commit_advancing_branch for the combined
op used by normal per-turn agent loops.
§Errors
GraphError::ParentNotFoundifparentisSomeand the referenced commit is not in the store.GraphError::Storageif the underlying store fails to persist.
Sourcepub async fn commit_advancing_branch(
&self,
branch_name: &str,
author: Author,
delta: Delta,
metadata: Metadata,
) -> Result<CommitId>
pub async fn commit_advancing_branch( &self, branch_name: &str, author: Author, delta: Delta, metadata: Metadata, ) -> Result<CommitId>
Commits a new turn and advances branch_name to point at it in one
step. The commit is durably written before the branch pointer moves,
so no reader can ever observe a branch pointing at a not-yet-persisted
commit.
Commits a new turn and advances branch_name to point at it in one
step. The commit is durably written before the branch pointer moves,
so no reader can ever observe a branch pointing at a not-yet-persisted
commit.
§Errors
Any error returned by commit (e.g. parent not
found) or store.set_branch.
Sourcepub async fn branch(&self, name: &str, at_commit_id: CommitId) -> Result<()>
pub async fn branch(&self, name: &str, at_commit_id: CommitId) -> Result<()>
Creates a new branch pointer at an existing commit. Fails if the branch already exists or the commit does not.
§Errors
GraphError::CommitNotFoundifat_commit_idis not in the store.GraphError::BranchAlreadyExistsif a branch namednameis already defined.
Sourcepub async fn move_branch(
&self,
name: &str,
to_commit_id: CommitId,
) -> Result<()>
pub async fn move_branch( &self, name: &str, to_commit_id: CommitId, ) -> Result<()>
Moves an existing branch pointer to a different (existing) commit.
§Errors
GraphError::BranchNotFoundif no branch namednameexists.GraphError::CommitNotFoundifto_commit_idis not in the store.
pub async fn delete_branch(&self, name: &str) -> Result<()>
pub async fn list_branches(&self) -> Result<Vec<(String, CommitId)>>
Sourcepub async fn checkout(
&self,
target: CheckoutTarget,
) -> Result<MaterializedContext>
pub async fn checkout( &self, target: CheckoutTarget, ) -> Result<MaterializedContext>
Materializes the ordered message list a model would see at target.
Sourcepub async fn fork(
&self,
from_commit_id: CommitId,
new_branch_name: &str,
) -> Result<()>
pub async fn fork( &self, from_commit_id: CommitId, new_branch_name: &str, ) -> Result<()>
Explicit speculative-branch creation: “try two continuations from the
same decision point” in one call. Semantically identical to branch
(a fork is a branch at an existing commit) but exposed under its
own name since it’s the primary developer-facing verb for A/B’ing a
decision point — including forking again from an existing fork.
Sourcepub async fn rollback(
&self,
branch_name: &str,
to_commit_id: CommitId,
) -> Result<()>
pub async fn rollback( &self, branch_name: &str, to_commit_id: CommitId, ) -> Result<()>
Moves branch_name backward to to_commit_id. Matches git’s reset
semantics: commits “ahead” of the new position are not deleted — they
remain reachable by hash, or by any other branch still pointing past
them.
Sourcepub async fn log(
&self,
target: CheckoutTarget,
filter: &LogFilter,
offset: usize,
limit: usize,
) -> Result<LogPage>
pub async fn log( &self, target: CheckoutTarget, filter: &LogFilter, offset: usize, limit: usize, ) -> Result<LogPage>
Walks the ancestry of target (a commit, or a branch’s current
head) newest-first, applying filter and then offset/limit
pagination.
Sourcepub async fn diff(
&self,
from: CheckoutTarget,
to: CheckoutTarget,
) -> Result<ContextDiff>
pub async fn diff( &self, from: CheckoutTarget, to: CheckoutTarget, ) -> Result<ContextDiff>
Structural diff between two materialized contexts. from/to can
each independently be a commit or a branch’s current head, so this
covers both the commit-pair and branch-pair forms.
Sourcepub async fn merge(
&self,
branch_a: &str,
branch_b: &str,
strategy: MergeStrategy,
) -> Result<CommitId>
pub async fn merge( &self, branch_a: &str, branch_b: &str, strategy: MergeStrategy, ) -> Result<CommitId>
Merges branch_b into branch_a, creating an explicit merge commit
and advancing branch_a to it. See crate::merge for why this never
silently merges divergent conversation content.
Auto Trait Implementations§
impl<S> Forget for ContextGraph<S>
impl<S> Freeze for ContextGraph<S>where
S: Freeze,
impl<S> Move for ContextGraph<S>
impl<S> RefUnwindSafe for ContextGraph<S>where
S: RefUnwindSafe,
impl<S> Send for ContextGraph<S>where
S: Send,
impl<S> Sync for ContextGraph<S>where
S: Sync,
impl<S> Unpin for ContextGraph<S>where
S: Unpin,
impl<S> UnsafeUnpin for ContextGraph<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for ContextGraph<S>where
S: UnwindSafe,
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> 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