import type { GitLogFn } from './git-core'; export type IndexBlockerKind = 'stash-pop' | 'merge' | 'rebase' | 'unknown'; /** Read-only detection result for one git root. */ export interface IndexBlocker { blocked: boolean; kind: IndexBlockerKind; /** Unique paths with unmerged stages (from `git ls-files -u`). */ unmergedFiles: string[]; /** A `teamshare:*` stash entry covers the unmerged content. */ hasStashBackup: boolean; /** Live `stash@{N}` refs of the covering entries (re-read every call). */ stashRefs: string[]; } /** Minimal comment surface (structurally satisfied by `GitRunnerApi`). */ export interface IndexRecoveryApi { addComment(dto: { taskId: string; body: string; }): Promise; } export interface IndexRecoveryRecord { gitRoot: string; repoName: string; kind: IndexBlockerKind; status: 'recovered' | 'blocked'; unmergedFiles: string[]; /** Where the unmerged content is backed up (stash tags / dump folder). */ backup: string[]; /** Stash refs cited AFTER recovery (re-read; tag is the stable id). */ stashRefs: string[]; /** On-disk stage-blob dump (merge/rebase, and best-effort for stash-pop). */ dumpDir?: string; /** Why the tree was left untouched (`status: 'blocked'`). */ reason?: string; /** Exact commands for a human to fix the repo by hand. */ manualCommands?: string[]; } interface UnmergedEntry { path: string; stage: number; sha: string; } interface TeamshareStashEntry { ref: string; tag: string; sha: string; files: string[]; } export declare function markBlockedIndexRepo(gitRoot: string): void; export declare function isBlockedIndexRepo(gitRoot: string): boolean; export declare function clearBlockedIndexRepo(gitRoot: string): void; /** Tests only - drop every blocked marker recorded in this process. */ export declare function clearAllBlockedIndexRepos(): void; /** * Every `teamshare:*` stash entry, newest first. Pure read - never mutates * the stash list. The message tag is matched (stable id), the `stash@{N}` * ref is derived from the CURRENT list position. */ export declare function listTeamshareStashes(gitRoot: string): TeamshareStashEntry[]; /** * Unmerged index entries (`git ls-files -u`), the same signal as * `getConflictedFiles` (`--diff-filter=U`) but with mode/sha/stage so the * recovery ladder can dump the stage blobs. */ export declare function unmergedEntries(gitRoot: string): UnmergedEntry[]; /** * Detect a blocked (unmerged) index. Read-only; never throws. */ export declare function detectIndexBlocker(gitRoot: string): IndexBlocker; /** * Recovery ladder for a blocked index. Synchronous (spawnSync git, same as * the rest of the git layer). Returns the audit record, or null when the * repo was not blocked. * * NEVER drops, clears or re-tags a stash entry; NEVER resets without a * verified backup (retained covering stash entry, plus a stage-blob dump for * merge/rebase). */ export declare function recoverBlockedIndex(gitRoot: string, opts: { cwd: string; log: GitLogFn; blocker?: IndexBlocker; }): IndexRecoveryRecord | null; /** * Build the escalation record for a repo that must be skipped (prepare's * checkout still failed after recovery, or no safe recovery exists). Marks * the repo so prepare/finalize never branch, commit or push it. The caller * posts it with {@link postIndexRecoveryComment}. */ export declare function blockedRecordFor(gitRoot: string, cwd: string, kind: IndexBlockerKind, unmergedFiles: string[], reason: string): IndexRecoveryRecord; /** * Post the audit comment for one recovery attempt: * `[git-index-recovered]` on success, `[git-index-blocked]` when the tree was * deliberately left untouched. Best-effort (never throws). */ export declare function postIndexRecoveryComment(api: IndexRecoveryApi | null | undefined, taskId: string, rec: IndexRecoveryRecord): Promise; /** * Pre-flight: detect a blocked index in every git root under `cwd` and run * the recovery ladder for each. Safe recoveries post `[git-index-recovered]`, * escalations post `[git-index-blocked]` and mark the repo so prepare and * finalize skip it. Orphaned `teamshare:*` stashes are never touched here. * * Insert this AFTER `checkOrphanedStashes` and BEFORE the `stashRepo` loop. */ export declare function preflightRecoverIndexes(cwd: string, taskId: string, api: IndexRecoveryApi | null, log: GitLogFn): Promise; export {};