/** * worktree - Git worktree isolation for subagents. * * Creates a temporary git worktree so an agent works on an isolated copy of the repo. * On completion: * - If no changes: worktree is removed. * - If changes exist: committed to a new branch, worktree is removed. * - The caller is responsible for merging the branch back (see mergeBranch). * * Safety: * - Non-git repos silently fall back to cwd (no worktree created). * - Symbolic links to node_modules are created to avoid reinstalling dependencies. * - Each worktree is created from HEAD in detached mode; changes are committed to a * uniquely-named branch to avoid collisions. * */ export interface WorktreeInfo { path: string; branch: string; originalBranch: string; originalHead: string; repoCwd: string; mailboxLinkCreated?: boolean; } export interface WorktreeCleanupResult { hasChanges: boolean; branch?: string; commitSha?: string; error?: string; } export interface MergeResult { success: boolean; branch: string; error?: string; mergedCommit?: string; } /** * Detect whether cwd is inside a git repository. */ export declare function isGitRepository(cwd: string): boolean; /** * Create a temporary worktree for a subagent. * Returns undefined if not in a git repo or worktree creation fails. * * Business: create a temporary git worktree for sub-agents to provide * directory isolation. The worktree is created at HEAD (detached) so the * main branch is not polluted. Project context files (AGENTS.md, .pi, * etc.) and the mailbox directory are symlinked so the sub-agent can * access project rules and read/write mailbox messages in real time. * The original branch name and HEAD SHA are recorded for later merge. */ export declare function createWorktree(cwd: string, agentId: string, mailboxPath?: string): WorktreeInfo | undefined; /** * Clean up the worktree after agent completion. * * Steps: * 1. Check for changes in worktree. * 2. If no changes: remove worktree, return { hasChanges: false }. * 3. If changes: add + commit to a new branch based on the commit, remove worktree. * * Note: This function does NOT merge back to the original branch. * Call mergeBranch() after all agents in a batch complete for safe merging. * * Business: clean up the worktree after a sub-agent finishes. If the * worktree has changes, commit them to a new branch — do NOT auto-merge. * Merges run sequentially after the batch completes to avoid race * conditions. */ export declare function cleanupWorktree(cwd: string, worktree: WorktreeInfo, agentDescription: string): WorktreeCleanupResult; /** * Merge a branch into the current branch. * Must be called when the working directory is clean (no parallel agents running). * Uses --no-ff --no-edit to create a merge commit preserving history. * * Business: merge a sub-agent's branch into the current branch. Must be * called with a clean working tree (sequentially, after all parallel * agents finish). On conflict, return the error and keep the branch for * manual resolution. */ export declare function mergeBranch(cwd: string, branchName: string): MergeResult; export declare function pruneWorktrees(cwd: string): void; //# sourceMappingURL=worktree.d.ts.map