import type { IsoBackendKind } from "@oh-my-pi/pi-natives"; import type { Settings } from "../config/settings.js"; export interface SessionWorktree { /** Absolute, realpath'd worktree root. */ path: string; /** Branch checked out in the worktree (created from the source `HEAD`). */ branch: string; /** Backend that cloned the checkout, or undefined for a plain checkout. */ clonedWith?: IsoBackendKind; /** Why the clone fell back to a plain checkout, when it did. */ cloneError?: string; /** Checkout the worktree was forked from. */ sourceCwd: string; /** Source `HEAD` the worktree branch was created at. */ baseCommit: string; /** Whether uncommitted source changes were carried into the worktree. */ keptChanges: boolean; } /** State of a session-owned worktree at exit. */ export interface SessionWorktreeState { /** Worktree has uncommitted or untracked changes. */ dirty: boolean; /** Branch tip moved off `baseCommit`; the branch is kept on removal. */ moved: boolean; /** Worktree `HEAD` is not the branch tip, so its commits may be on no branch. */ offBranch: boolean; } /** What to do with a session-owned worktree when the session exits. */ export type WorktreeExitAction = "keep" | "remove" | "prompt"; /** * Map the `worktree.onExit` policy and the worktree's state to an exit action. * `remove` only removes worktrees with nothing to lose; anything else prompts. */ export declare function decideWorktreeExit(policy: "keep" | "ask" | "remove", state: SessionWorktreeState): WorktreeExitAction; /** Reports whether a fresh session in `cwd` may get a worktree: a primary git checkout with commits. */ export declare function canAutoCreateWorktree(cwd: string): Promise; /** Default `/wt` branch name: `wt/`. */ export declare function defaultSessionWorktreeBranch(now?: Date): string; /** One-line confirmation shown after the session moved into `worktree`. */ export declare function formatSessionWorktreeSummary(worktree: SessionWorktree, sourceCleaned?: boolean): string; /** * If `worktree.cleanSource` is enabled, resets and cleans the source checkout. * Catches git errors and returns `{ cleaned: true }` on success, or `{ cleaned: false, errorMessage }` on failure. */ export declare function cleanSourceCheckoutIfConfigured(sourceCwd: string, settings: Settings): Promise<{ cleaned: boolean; errorMessage?: string; }>; /** * Create the worktree for `/wt`. Throws with a user-facing message when `cwd` * is not a git checkout, `branch` already exists, or git refuses. */ export declare function createSessionWorktree(cwd: string, settings: Settings, branch: string, options?: { keepChanges?: boolean; }): Promise; /** * Gets the state of `wt`. A missing worktree is not dirty and not off-branch; a * deleted branch has not moved; a missing source repo counts as moved so the * branch is never deleted. */ export declare function inspectSessionWorktree(wt: SessionWorktree): Promise; /** A worktree chosen for removal at exit. */ export interface WorktreeExitPlan { worktree: SessionWorktree; /** Snapshot fingerprint at the time removal was decided or approved. */ approvedFingerprint: string; } /** * Applies `policy` to `owned` and returns the worktrees to remove, newest first. * Calls `confirm` for each worktree that needs a prompt; inspection errors go to * `warn` and keep that worktree. */ export declare function planWorktreeExit(owned: readonly SessionWorktree[], policy: "keep" | "ask" | "remove", confirm: (title: string, message: string) => Promise, warn: (message: string) => void): Promise; /** * Removes the planned worktrees in order, keeping any that changed at all since * removal was decided or approved. Returns one message per kept or failed * worktree, plus a resume note when the worktree holding the process cwd is removed. */ export declare function removeExitWorktrees(plan: readonly WorktreeExitPlan[]): Promise; /** * Force-remove `wt`; also delete its branch unless it `moved` (has new commits). * Throws a user-facing error when git refuses either step. */ export declare function removeSessionWorktree(wt: SessionWorktree, moved: boolean): Promise;