Skip to main content

AgentWorktree

Struct AgentWorktree 

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

A subagent’s private checkout.

Implementations§

Source§

impl AgentWorktree

Source

pub fn create(workdir: &Path, agent_id: &str) -> Result<Self>

Create an isolated checkout for agent_id, seeded with workdir’s current uncommitted state.

workdir is the session’s directory; it may be the repo top level or any directory under it. The child is rooted at the matching relative path inside the worktree, so a session running in crates/foo gives its children a crates/foo too and relative paths in the prompt still mean what they say.

§Errors

workdir not being inside a git repository, and a repository whose HEAD is unborn — there is no commit to branch a checkout from. Then any git or filesystem step: locating the top level, worktree add, the checkout, and seeding the uncommitted state. A seeding failure destroys the checkout before returning, so a failed create never leaves a half-seeded worktree for a child to work against.

Source

pub fn root(&self) -> &Path

Where the child should run.

Source

pub fn project_root(&self) -> &Path

Top level of the project this work merges back into. Callers serializing merges key their lock on this.

Source

pub fn base(&self) -> &str

The commit the child’s work is currently measured against.

Source

pub fn pending_files(&self) -> Result<Vec<PathBuf>>

Absolute project paths the child’s pending work would touch.

Callers checkpoint these before Self::merge_into_project, so a merged patch is as recoverable through /restore as any other tool’s mutation. Reading them separately (rather than out of the merge result) is what lets the snapshot happen before the files change.

Sorted and deduplicated, so a caller can feed them straight to a multi-path lock acquisition without risking a deadlock against another caller holding the same paths in a different order.

§Errors

Only computing the pending patch — a git invocation against the checkout. A child that has changed nothing yields Ok(vec![]).

Source

pub fn merge_into_project(&mut self) -> Result<MergeOutcome>

Apply the child’s work to the project.

Callers must serialize this across concurrent children — two patches applying at once reintroduce exactly the interleaving the worktree exists to prevent.

§Errors

Computing the patch, running the dry-run git apply --check, saving a rejected patch, and the real apply. A patch that does not apply is not among them — that is MergeOutcome::Conflicted, with the project untouched. An Err from the real apply is the one case where the project may be partly changed: the dry run passed, so it should not happen, and the message says so.

Source

pub fn destroy(self)

Remove the checkout. Best-effort: a worktree we cannot delete is disk we can reclaim later (see gc_orphaned_worktrees), never a reason to fail the agent whose work already merged.

Trait Implementations§

Source§

impl Debug for AgentWorktree

Source§

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

Formats the value using the given formatter. 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> 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> Same for T

Source§

type Output = T

Should always be Self
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