zeph-worktree
Git worktree lifecycle management for Zeph subagents.
Overview
zeph-worktree creates, removes, lists, and reconciles per-subagent git worktrees. Each background subagent that opts into filesystem isolation gets a dedicated worktree cloned from the host repository, preventing concurrent agents from clobbering each other's working trees.
The crate is intentionally narrow in scope — it wraps git worktree subprocess calls with full path sanitization, capability probing, and a configurable timeout. It has no dependency on zeph-core, zeph-subagent, or zeph-channels.
Key types
| Type | Description |
|---|---|
DefaultWorktreeManager |
Production WorktreeManager<DefaultGitRunner> — the type stored by SubAgentManager |
WorktreeManager<R> |
Generic manager parameterised over GitRunner; injectable for testing |
WorktreeHandle |
Live record of one managed worktree (path, branch, subagent ID, creation time) |
DefaultGitRunner |
Production git invocation backend with configurable timeout |
GitRunner |
Trait for abstracting git subprocess calls |
WorktreeError |
All errors this crate can produce |
Usage
[]
= { = "crates/zeph-worktree" }
use PathBuf;
use WorktreeConfig;
use ;
async
[!IMPORTANT] Call
probe_capabilitiesonce at bootstrap. It checks thatgit≥ 2.5 is inPATHand that the target path is a git repository. A missing git binary is caught here, not at first spawn.
Configuration
WorktreeManager is driven by WorktreeConfig from zeph-config:
[]
= true
= "worktree" # "none" | "worktree"
= "head" # "head" | "fresh"
= 30 # clamped to max(1, value)
= true
| Field | Default | Description |
|---|---|---|
enabled |
false |
Enable worktree isolation for background subagents |
bg_isolation |
"none" |
"worktree" creates a dedicated worktree; "none" only holds the CWD lock |
base_ref |
"head" |
"head" branches off current HEAD; "fresh" fetches and branches off origin/<default> |
git_timeout_secs |
30 |
Per-command timeout for all git subprocess calls |
cleanup_on_completion |
true |
Remove the worktree when the subagent finishes |
Invariants
- Path sanitization rejects absolute paths,
..components, and names starting with-before any git call. base_ref = "fresh"never silently falls back to HEAD on fetch failure — it returns an error.git_timeout_secs = 0is clamped to1byDefaultGitRunner.
License
MIT — see LICENSE.