pub struct AgentWorktree { /* private fields */ }Expand description
A subagent’s private checkout.
Implementations§
Source§impl AgentWorktree
impl AgentWorktree
Sourcepub fn create(workdir: &Path, agent_id: &str) -> Result<Self>
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.
Sourcepub fn project_root(&self) -> &Path
pub fn project_root(&self) -> &Path
Top level of the project this work merges back into. Callers serializing merges key their lock on this.
Sourcepub fn pending_files(&self) -> Result<Vec<PathBuf>>
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![]).
Sourcepub fn merge_into_project(&mut self) -> Result<MergeOutcome>
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.
Sourcepub fn destroy(self)
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.