/** * WorktreeManager - Virtual worktree isolation service. * * Manages named worktrees under /.ag-bash/worktrees//, allowing * agents to work in isolated directory contexts with independent branches. * Each worktree tracks its originating cwd so the user can seamlessly * return after exiting. * * Publishes lifecycle events to SharedStateBus: * worktree:created, worktree:enter, worktree:exit, worktree:deleted */ import type { SharedStateBus } from "./SharedStateBus.js"; export interface Worktree { id: string; name: string; /** Absolute VFS path, e.g. /.ag-bash/worktrees/my-feature/ */ path: string; /** Branch name associated with this worktree */ branch: string; /** The cwd that was active before entering this worktree */ originalCwd: string; createdAt: number; } export interface CreateWorktreeOpts { name: string; branch?: string; originalCwd: string; } export declare class WorktreeManager { private worktrees; private activeWorktree; private bus; private nextWorktreeId; setBus(bus: SharedStateBus): void; /** * Create a new worktree under /.ag-bash/worktrees//. * * If no branch is specified the default is `worktree/`. * Throws if a worktree with the same name already exists. */ createWorktree(opts: CreateWorktreeOpts): Worktree; /** * Set a worktree as the active one, identified by ID or name. * * Throws if the worktree does not exist. */ enterWorktree(idOrName: string): Worktree; /** * Exit the currently active worktree and return its original cwd. * * Returns null if no worktree is active. */ exitWorktree(): { originalCwd: string; } | null; /** Return the currently active worktree, or undefined if none. */ getActive(): Worktree | undefined; /** Return a defensive copy of all worktrees. */ listWorktrees(): Worktree[]; /** * Delete a worktree by ID or name. * * If the deleted worktree is the active one, the active reference is * cleared. Returns true if a worktree was found and removed. */ deleteWorktree(idOrName: string): boolean; /** * Find a worktree by its ID or name. * * Returns a defensive copy or undefined if not found. */ getWorktree(idOrName: string): Worktree | undefined; }