/** * Worktree lifecycle — manages host git worktrees for tasks. * * A worktree is a `git worktree add`'d directory at * `/-/` (where `worktreeDir` defaults to * `projectDir`). The source repo it is cut from may live under a different * per-repo `projectDirOverride`. Callers go through the `worktrees` namespace; * the module owns creation, listing, removal, and teardown (workspace-close + * worktree-remove paired) so callers don't reach into git directly. */ import { type ResolvedConfig } from "./config.ts"; import { type WorkspaceProbe } from "./workspaces.ts"; export type WorktreeKind = "host"; export declare class WorktreeAlreadyExistsError extends Error { readonly dir: string; constructor(dir: string); } export interface WorktreeEntry { repository: string; /** Source task id, lowercased — e.g. "team-220" or "gc-20260608-001". */ task: string; /** Slash-free `-`, except when `adoptedBranch` is true. */ branchName: string; dir: string; kind: WorktreeKind; /** * True when `branchName` is a pre-existing branch groundcrew checked out but * did not create (e.g. an open PR via `crew open`). Such a branch must never * be deleted on teardown — doing so would destroy the user's local branch. */ adoptedBranch?: boolean; } export interface WorktreeSpec { repository: string; task: string; } export interface WorktreeOpenSpec { repository: string; task: string; /** Existing branch to check out (the PR head), used verbatim. */ branch: string; } declare function branchNameForTask(config: ResolvedConfig, task: string): string; /** * The directory the agent and its setup hooks actually run in. Equals the * worktree root unless the repo recipe sets a `workdir`, in which case it is * `/` — a monorepo subproject inside a sparse checkout. * Pure path resolution; existence is enforced at create time by * assertWorkdirPresent. */ export declare function resolveLaunchDir(config: ResolvedConfig, repository: string, worktreeDir: string): string; export type WorktreeDirtiness = { kind: "dirty"; modified: number; untracked: number; } | { kind: "clean"; } | { kind: "unknown"; }; export declare function isRecoverableRemovalError(error: unknown): boolean; export interface ForceRemoveDirectoryOptions { attempts?: number; delayMs?: number; remove?: (target: string) => void; } export declare function forceRemoveDirectory(targetDir: string, options?: ForceRemoveDirectoryOptions): Promise; declare function list(config: ResolvedConfig): WorktreeEntry[]; declare function findByTask(config: ResolvedConfig, task: string): WorktreeEntry[]; export interface PredictedWorktreeEntry { branchName: string; worktreeDir: string; } declare function predictedEntry(config: ResolvedConfig, repository: string, task: string): PredictedWorktreeEntry; declare function create(config: ResolvedConfig, spec: WorktreeSpec, signal?: AbortSignal): Promise; declare function open(config: ResolvedConfig, spec: WorktreeOpenSpec, signal?: AbortSignal): Promise; declare function remove(config: ResolvedConfig, entry: WorktreeEntry, options?: { force?: boolean; signal?: AbortSignal; }): Promise; export type TeardownStep = "workspace_close" | "worktree_remove"; export interface TeardownFailure { entry: WorktreeEntry; step: TeardownStep; error: unknown; } export interface TeardownResult { /** Tasks whose Workspace was closed (deduped per task). */ closed: string[]; /** Worktrees successfully removed. */ removed: WorktreeEntry[]; /** Per-entry failures; teardown continues past them. */ failures: TeardownFailure[]; workspaceProbe: WorkspaceProbe; } declare function teardown(config: ResolvedConfig, entries: readonly WorktreeEntry[], options?: { force?: boolean; signal?: AbortSignal; }): Promise; declare function probeWorkingTree(input: { worktreeDir: string; signal?: AbortSignal; }): Promise; export declare const worktrees: { create: typeof create; open: typeof open; list: typeof list; findByTask: typeof findByTask; predictedEntry: typeof predictedEntry; remove: typeof remove; teardown: typeof teardown; branchNameForTask: typeof branchNameForTask; probeWorkingTree: typeof probeWorkingTree; }; export {}; //# sourceMappingURL=worktrees.d.ts.map