export interface WorktreeInfo { path: string; branch: string; commitHash: string; } /** * Arbitrated create (IMP-950): exclusive lock on the main repo while the * worktree is registered. Returns null when the workspace stays busy past * the wait budget - the caller reports failure instead of corrupting state. */ export declare function createWorktreeAsync(repoPath: string, branch: string, baseBranch: string, taskId: string, agentId?: string): Promise; /** Arbitrated remove (IMP-950). */ export declare function removeWorktreeAsync(repoPath: string, worktreePath: string, agentId?: string): Promise; export interface SafeRemoveResult { removed: boolean; /** Uncommitted changes existed and were committed+pushed before removal. */ rescued?: boolean; /** Branch the rescue commit landed on (also where preserved work lives * when removal was refused). */ branch?: string; commitHash?: string; /** Refused because the tree was dirty and could not be rescued. */ dirty?: boolean; path?: string; error?: string; } /** * DATA-LOSS GUARD (2026-08-25 Ptad incident): a zombie requeue tore down a * live worker's worktree; the old removeWorktree() ran `git checkout -- .` + * `git clean -fd` first and vaporized hours of uncommitted agent work. * * Safe removal order: * 1. dirty? -> rescue: `git add -A` + WIP commit on the worktree branch, * pushed to origin. Removal only proceeds once the work exists on the * remote. * 2. rescue fails (no remote / push error) -> REFUSE. The directory is * left untouched for human recovery; caller alerts instead of deleting. * 3. clean (or rescued) -> remove, then sweep an empty husk dir Windows * sometimes leaves behind. * Never discards anything - there is no `checkout -- .`/`clean -fd` here. */ export declare function removeWorktreeSafeAsync(repoPath: string, worktreePath: string, opts?: { agentId?: string; reason?: string; }): Promise; export interface GitStatus { branch: string; dirty: boolean; ahead: number; files: string[]; } /** * Get the worktree root directory for a project. * Derived from the project's linked path. */ export declare function getWorktreeRoot(projectPath: string): string; /** * Create a new Git worktree for an orchestrator task. */ export declare function createWorktree(repoPath: string, branch: string, baseBranch: string, taskId: string): WorktreeInfo; /** * Remove a Git worktree. * DATA-LOSS GUARD: uncommitted changes are rescued via a WIP commit on the * worktree branch before removal - this function NEVER discards work. * (`git checkout -- .` + `git clean -fd` here previously vaporized a live * worker's uncommitted files during zombie cleanup - 2026-08-25 Ptad.) */ export declare function removeWorktree(repoPath: string, worktreePath: string): void; /** * Get git status for a worktree. */ export declare function gitStatus(worktreePath: string): GitStatus; /** * Commit changes in a worktree. */ export declare function gitCommit(worktreePath: string, message: string, files?: string[]): string; /** * Merge a branch into the integration branch - arbitrated (IMP-950). * gitMerge CHECKS OUT the target branch inside the MAIN repo tree; without * the lock a concurrent session could have its working files swapped * mid-edit. Returns { skipped: true } when the workspace stayed busy. */ export declare function gitMergeAsync(repoPath: string, sourceBranch: string, targetBranch: string, agentId?: string): Promise<{ success: boolean; conflictFiles?: string[]; skipped?: boolean; }>; /** * Merge a branch into the integration branch. */ export declare function gitMerge(repoPath: string, sourceBranch: string, targetBranch: string): { success: boolean; conflictFiles?: string[]; }; /** * Get the diff for a worktree. */ export declare function gitDiff(worktreePath: string): string; /** * Push a branch to a remote. * Uses the given remote name (defaults to 'origin'). Returns success or the error. */ export declare function gitPush(repoPath: string, branch: string, remote?: string, setUpstream?: boolean): { success: boolean; remoteRef?: string; error?: string; }; /** * Revert the last commit in a worktree (git revert HEAD --no-edit). * Returns the new commit hash after the revert. */ export declare function gitRevertHead(worktreePath: string): { commitHash: string; }; /** * Hard reset a worktree to a specific commit (git reset --hard ). * Discards ALL uncommitted changes and moves HEAD to the target commit. */ export declare function gitResetHead(worktreePath: string, commitHash: string): { success: boolean; }; /** * Get the remote URL for a git repo. Returns null if not a git repo or no remote. */ export declare function gitRemoteUrl(repoPath: string, remote?: string): string | null; /** * Check whether a directory is a git repository. */ export declare function isGitRepo(dir: string): boolean; /** * Initialize a git repository in a directory (git init + optional remote). * Returns the origin URL if a remote was added, else null. */ export declare function gitInit(dir: string, remoteName?: string, originUrl?: string): { success: boolean; originUrl?: string; error?: string; }; /** * Ensure a directory is a git repository. If not, initialise it. * This allows the orchestrator to work on projects that have no git repo yet. */ export declare function ensureRepoExists(repoPath: string): void; /** * Detect a sensible base branch for auto-created worktrees (IMP-950): * origin/HEAD > current branch > 'main'. Never throws. */ export declare function detectDefaultBranch(repoPath: string): string; /** * Ensure a local bare repo exists and is configured as the origin remote for * `repoPath`. When no remote is configured (the user hasn't linked a GitHub / * Gitea repo), this allows `git push` to succeed against a local bare repo * at `~/.teamshare/bare-repos/.git/`. */ export declare function ensureLocalBareRepo(repoPath: string, projectId: string): string;