import type { GitOperationStatus } from '@agent-tower/shared';
export { GitError, BranchExistsError, BranchNotFoundError, InvalidBranchNameError, WorktreeDirtyError, MergeConflictError, BranchesDivergedError, RebaseInProgressError, } from './git-cli.js';
export interface WorktreeInfo {
    /** Absolute path to the worktree directory */
    path: string;
    /** HEAD commit hash */
    head: string;
    /** Branch name (empty for detached HEAD) */
    branch: string;
    /** Whether this is the bare/main worktree */
    bare: boolean;
}
export interface BranchStatus {
    ahead: number;
    behind: number;
}
export interface WorktreeStatus {
    /** Number of staged + unstaged modified files */
    changedFiles: number;
    /** Number of untracked files */
    untrackedFiles: number;
}
export interface DiffResult {
    /** Full diff output */
    diff: string;
    /** Summary stat output */
    stat: string;
}
export interface WorktreeRemoveResult {
    /** Outcome of the remove attempt. */
    status: 'removed' | 'missing' | 'stale_removed' | 'unregistered';
    /** Absolute path that was checked/removed. */
    path: string;
    /** Whether the path is under this project's managed .worktrees directory. */
    managed: boolean;
}
export interface BranchDeleteOptions {
    /** Branches that must never be deleted, such as the project main/base branch. */
    protectedBranches?: Array<string | null | undefined>;
}
export interface BranchDeleteResult {
    /** Outcome of the delete attempt. */
    status: 'deleted' | 'empty' | 'protected' | 'missing' | 'checked_out' | 'failed';
    /** Normalized branch name that was evaluated. */
    branchName: string;
    /** Optional detail for checked_out/failed outcomes. */
    reason?: string;
}
export declare class WorktreeManager {
    private repoPath;
    private worktreeBaseDir;
    constructor(repoPath: string);
    /**
     * List all worktrees with parsed metadata.
     * Parses `git worktree list --porcelain` output.
     */
    listWorktrees(): Promise<WorktreeInfo[]>;
    /**
     * Get branch divergence status (ahead/behind) relative to a base branch.
     */
    getBranchStatus(branchName: string, baseBranch: string): Promise<BranchStatus>;
    /**
     * Get the working tree status of a worktree (changed + untracked file counts).
     */
    getWorktreeStatus(worktreePath: string): Promise<WorktreeStatus>;
    /**
     * Check whether a worktree has no uncommitted changes.
     */
    isWorktreeClean(worktreePath: string): Promise<boolean>;
    /**
     * Check whether a branch exists (local).
     */
    checkBranchExists(branchName: string): Promise<boolean>;
    /**
     * Delete a local branch when it is safe to discard.
     *
     * This intentionally skips protected base branches, missing branches, and
     * branches currently checked out in the main repo or any registered worktree.
     */
    deleteBranchIfSafe(branchName: string | null | undefined, options?: BranchDeleteOptions): Promise<BranchDeleteResult>;
    /**
     * Create a new worktree with a new branch.
     *
     * - Validates branch name
     * - Checks branch does not already exist
     * - Creates the worktree base directory if needed
     */
    create(branchName: string, startPoint?: string): Promise<string>;
    /**
     * Remove a worktree. If the worktree does not exist, this is a no-op.
     */
    remove(worktreePath: string): Promise<WorktreeRemoveResult>;
    /**
     * Ensure a worktree exists for an existing branch. If the worktree directory
     * is already valid, return its path. Otherwise, recreate it.
     *
     * Used when reactivating a MERGED workspace — the branch was preserved via
     * update-ref but the worktree directory was removed.
     *
     * 参考: vibe-kanban crates/services/src/services/worktree_manager.rs:93-123
     */
    ensureWorktreeExists(branchName: string): Promise<string>;
    /**
     * Get the diff of a worktree branch against a base branch.
     * Returns both the full diff and a stat summary.
     */
    getDiff(worktreePath: string, baseBranch: string): Promise<string>;
    getDiff(worktreePath: string, baseBranch: string, options: {
        withStat: true;
    }): Promise<DiffResult>;
    /**
     * Squash-merge a worktree branch into the target branch.
     *
     * Performs the following steps:
     * 1. Verify the worktree is clean
     * 2. Check branch divergence — fail if base branch has advanced
     * 3. Checkout target branch in the main repo
     * 4. Execute `git merge --squash --no-commit <task_branch>`
     * 5. Commit the squash merge
     * 6. Remove the worktree and delete the task branch
     */
    merge(worktreePath: string, targetBranch: string, options?: {
        commitMessage?: string;
    }): Promise<{
        sha: string;
        taskBranch: string;
    }>;
    /**
     * Merge a child workspace branch into its parent workspace branch.
     *
     * This keeps the parent workspace branch as the integration branch for a
     * TeamRun. The merge commit is created in the parent worktree with --no-ff.
     */
    mergeIntoWorktree(sourceWorktreePath: string, targetWorktreePath: string, options?: {
        commitMessage?: string;
    }): Promise<{
        sha: string;
        sourceBranch: string;
        targetBranch: string;
    }>;
    /**
     * Prune stale worktree references.
     */
    prune(): Promise<void>;
    /**
     * Rebase the current branch in the worktree onto the latest base branch.
     * Uses `git rebase --onto <baseBranch> <mergeBase> <taskBranch>`.
     *
     * - If a rebase is already in progress, throws RebaseInProgressError
     * - On conflict, throws MergeConflictError with ConflictOp.REBASE (preserves rebase state)
     * - On non-conflict failure, auto-aborts to keep repo clean
     */
    rebase(worktreePath: string, baseBranch: string): Promise<void>;
    /**
     * Get the current Git operation status of a worktree.
     */
    getGitOperationStatus(worktreePath: string, baseBranch: string): Promise<GitOperationStatus>;
    /**
     * Abort the current in-progress Git operation (rebase or merge).
     * If no operation is in progress, this is a no-op.
     */
    abortOperation(worktreePath: string): Promise<void>;
    /**
     * Alias for `listWorktrees()`, returns just the paths.
     * Kept for backward compatibility with existing callers.
     */
    list(): Promise<string[]>;
    /**
     * Assert that a branch exists; throw BranchNotFoundError if not.
     */
    private ensureBranchExists;
    private getCurrentBranch;
    private findWorktreeForBranch;
    /**
     * Parse the porcelain output of `git worktree list --porcelain`.
     *
     * Format:
     * ```
     * worktree /path/to/main
     * HEAD abc123
     * branch refs/heads/main
     *
     * worktree /path/to/wt
     * HEAD def456
     * branch refs/heads/feature
     * ```
     */
    private parseWorktreeListOutput;
    private pathExists;
    private isManagedWorktreePath;
    private isRegisteredWorktreePath;
    private hasRegisteredDescendantWorktree;
    private normalizeExistingPath;
    private removeUnregisteredPath;
    /**
     * Get the list of conflicted files from a failed merge.
     */
    private getConflictedFiles;
    /**
     * Get the list of conflicted files in a specific worktree path.
     */
    private getConflictedFilesIn;
    /**
     * Check if a rebase is in progress in the given worktree.
     * Detects by checking for rebase-merge or rebase-apply directories.
     */
    private isRebaseInProgress;
    /**
     * Check if a merge is in progress in the given worktree.
     * Detects by verifying MERGE_HEAD exists.
     */
    private isMergeInProgress;
}
//# sourceMappingURL=worktree.manager.d.ts.map