/** * Shared git worktree helper for service connectors. * * Provides create/cleanup with a cross-adapter ownership registry * that prevents one adapter from removing a worktree another is using. * * Every git invocation here is async and carries an explicit timeout. These * helpers are reachable from agent-invokable connector operations (the * static-server `serve`/`stop` ops), so a git call whose `cwd` sits on a wedged * mount used to park the runner's single event loop indefinitely. */ /** * Result of a successful `createWorktree` call. The `cleanup` function removes the * worktree when no other owners are registered for the same path. * @docLink packages/connectors/api-reference#worktree-result */ export interface WorktreeResult { /** Absolute path to the worktree directory. */ path: string; /** Resolved full SHA of the ref. */ ref: string; /** Branch name if ref was a branch. */ branch?: string; /** Remove the worktree. Fails if other owners exist in registry. */ cleanup: () => Promise; } /** * Summary entry returned by `listWorktrees`. * @docLink packages/connectors/api-reference#worktree-info */ export interface WorktreeInfo { /** Absolute path to the worktree. */ path: string; /** HEAD commit SHA. */ head: string; /** Branch reference, if a named branch is checked out. */ branch?: string; } declare class WorktreeRegistryImpl { private readonly entries; register(path: string, owner: string): void; deregister(path: string, owner: string): void; isInUse(path: string): boolean; owners(path: string): string[]; } /** * Module-level singleton registry shared across all service-connector adapters in the same process. * Prevents one adapter from removing a worktree that another adapter is still using. * @docLink packages/connectors/api-reference#worktree-registry */ export declare const worktreeRegistry: WorktreeRegistryImpl; /** * Deadline for metadata-only git queries (`rev-parse`, `worktree list`). These * read `.git` and return immediately on a healthy repository; anything slower * means the filesystem under `cwd` is not answering. */ export declare const GIT_QUERY_TIMEOUT_MS = 15000; /** * Deadline for git operations that touch the working tree (`worktree add`, * `worktree remove`, `worktree prune`). Checking out a large tree is legitimate * work, so the budget is wider than a query's. */ export declare const GIT_WORKTREE_TIMEOUT_MS = 120000; /** * Walk up from `fromDir` to find the git repository root. * @param fromDir - Any directory inside a git repository. * @returns Absolute path to the repository root. * @throws {Error} when no git repository is found, or when git does not answer * within {@link GIT_QUERY_TIMEOUT_MS}. * @docLink packages/connectors/api-reference#find-git-root */ export declare function findGitRoot(fromDir: string): Promise; /** * Create a git worktree for `ref` under `baseDir` and register it with `worktreeRegistry`. * The returned `WorktreeResult.cleanup()` removes the worktree when no other owners remain. * @param opts - Repo root, git ref, base directory, optional label, and owner ID. * @returns Path, resolved SHA, branch name, and `cleanup()` function. * @throws {Error} if the ref cannot be resolved. * @docLink packages/connectors/api-reference#create-worktree */ export declare function createWorktree(opts: { repoRoot: string; ref: string; baseDir: string; label?: string; owner: string; }): Promise; /** * List all git worktrees for a repository. * @param repoRoot - Absolute path to the git repository root. * @returns Array of `WorktreeInfo` objects parsed from `git worktree list --porcelain`. * @docLink packages/connectors/api-reference#list-worktrees */ export declare function listWorktrees(repoRoot: string): Promise; export {}; //# sourceMappingURL=worktree.d.ts.map