export interface Worktree { /** Working directory of the isolated checkout. */ path: string; /** Branch created for this session. */ branch: string; /** The original repository the worktree belongs to. */ repo: string; } /** True if `cwd` is inside a git working tree. */ export declare function isGitRepo(cwd: string): boolean; /** * Creates an isolated git worktree off the repo's current HEAD, on a fresh * branch, so an agent's edits stay contained until the user merges them. * The checkout lives under ~/.shadok-ai/worktrees to avoid polluting the repo. */ export declare function createWorktree(repo: string, tag: string): Worktree; /** * Removes a worktree only if it has no uncommitted changes (git refuses a * dirty removal without --force, which we intentionally don't pass — work is * never discarded automatically). */ export declare function removeWorktreeIfClean(wt: Worktree): void; /** * Cleanup when a session ends: remove its worktree checkout if it has no * uncommitted changes (`git worktree remove` without --force refuses a dirty * tree — work is never discarded), and delete its branch only if it has NO * commits beyond the base (an agent that did nothing). A branch with commits * survives so the work stays recoverable (listPastSessions / the recover panel). * Returns what happened, for logging. A repo-root session (no `shadok-ai/` * branch) is a no-op. */ export declare function pruneWorktree(repo: string, branch: string | null | undefined): "removed" | "kept" | "none"; /** * Ensures a worktree checkout exists at `dir` for `branch`, recreating it * from the branch if it was removed. Lets a past session be reopened even * after its folder was reclaimed (the branch always survives). */ export declare function ensureWorktreeCheckout(repo: string, branch: string, dir: string): boolean; export interface PastSession { branch: string; /** Full session id (from the transcript), or null if none was recorded. */ sessionId: string | null; /** Worktree checkout path (may not exist on disk). */ cwd: string; dirExists: boolean; /** First user prompt of the session, for recognition. */ preview: string; /** Commits ahead of the base branch. */ commits: number; /** Whether the branch has any diff vs the base. */ hasChanges: boolean; /** Last activity (ms since epoch). */ mtime: number; } /** * Lists every past shadok-ai worktree session of a repo — recoverable from * their branch even if the checkout was reclaimed — newest first, so * unfinished work can be reopened and continued. */ export declare function listPastSessions(repo: string): PastSession[]; export interface DiffResult { status: string; diff: string; branch: string | null; } /** * Returns the changes made in `cwd`: `git status` plus the full diff. Given the * originating `repo` (a worktree session), diffs against the fork point off its * base branch, so committed work shows too and the base's own work doesn't; * otherwise diffs the working tree against HEAD. * * Note this is the merge-base and not `git diff base...HEAD`: the three-dot * form stops at the branch tip, which would hide everything the agent has not * committed yet — and uncommitted work is most of what the panel is for. */ export declare function gitDiff(cwd: string, repo?: string | null): DiffResult;