Worktrees #
The worktrees extension creates and tracks version-control checkouts for sessions and agents. Its extension registers host calls and managed context. The work splits in two:
sdk/worktreeis the contract: theProvidera version-control extension contributes withextension.WorktreePlugin, theWorktreerecord, theWorktreesrecord of theworktreescapability, theOriginsreads linked groups take, and path, file, and command helpers for providers.- Core's
worktreeis the host's service: theworktreestable, placement and naming, provider detection, occupancy, and removal with its followers. It builds the capability and the origin reads. It keeps the edge toobservation/busthat tells which session is running.
| Function | Owner |
|---|---|
Repo, VcsEntry, CreateSpec, Provider, Worktree, to_json |
SDK |
Worktrees, Request, Origins, no_origins |
SDK: the capability's and the origin reads' types |
join_path, relative_subdir, parent_dir, find_checkout, present, strip_suffix |
SDK: path helpers for providers |
exec, is_dir, is_file, read_file, ensure_dir, delete_tree |
SDK: exec runs through the Runner the host hands a provider callback |
apply, initialise, forget_session |
Core: the table, which the daemon creates at startup, and the cleanup runtime.cleaners runs for a deleted session |
valid_name, repo_slug, sanitize_slug, base_dir, worktree_path, worktree_id |
Core: where checkouts go under albedo's home and how they are named |
detect |
Core: the first enabled provider that claims a directory |
create, create_for_agent, attach_session |
Core, through the capability's create, create_for_agent, and attach_session |
get, for_session, for_workspace, list, remove, running_occupant |
Core, gated under Sessions (capability.functions). Extensions reach all but for_workspace through the capability |
capability, origins |
Core: the capability over a session's providers and every declared extension's followers, and the origin reads |
Layout #
worktree.base_dir places managed checkouts under $ALBEDO_HOME/wt.
worktree_path adds a repository slug and a chosen name. The record
distinguishes the checkout path from workspace, which preserves the origin's
subdirectory within the checkout. origin records the originating workspace.
Creation rejects remote SSH locations.
Worktree providers #
A worktree.Provider detects a repository and implements creation, listing, and
removal for its version-control system. Each callback receives the
local_command.Runner
it runs git or jj through, which the host supplies from
local_run, so a
provider starts no process itself. worktree.detect selects a matching enabled
provider. worktree.create creates the checkout and records it. If recording
fails, it attempts to remove the checkout. A capability Request may name a
provider kind, which the host matches without case. See
worktree.gleam and the
extension dispatch.
The worktrees capability #
Extensions create, find, and remove worktrees through worktrees on
host.Context and extension.Preparation, never by importing core. The record
binds the session's enabled providers, and its remove runs every declared
extension's followers. Each function takes the caller's storage handle. A
worktree names the session that works in it, so the field needs Sessions as
well as Worktrees, and core's reads still check Sessions on the handle. A
denied capability answers every operation with the refusal, and for_session
and running_occupant with None. The worktrees and agents extensions declare
it. The field once held the providers list under Providers; the providers no
longer reach extensions.
Python #
The Python binding exposes asynchronous
worktrees.create, get, query, list, and remove. A Worktree record
includes its ID, repository, workspace, kind, revision, branch, session, and
existence state. query supports filters. list returns the matching records.
worktree.remove refuses the main checkout and paths outside the managed base.
Without force, it refuses a worktree occupied by a running session. Removal
deletes the checkout, then runs every declared extension's WorktreeRemoved
follower in the transaction that deletes the
record. The capability binds those followers. The work extension's follower
moves work-ledger entries to the origin checkout. Closing an agent does not
automatically delete its worktree. See
remove and the
extension instructions.
Agents #
The extension accepts a worktree for agent creation, or a request to create one for the agent. The agent's workspace then points into that checkout. See the worktrees extension and agents.
Managed context #
For a session associated with a worktree, the extension adds context naming the checkout and origin. Its context identifies the origin as the shared scope for memory and the work ledger. See workspaces for locations and links.