/**
 * Auto-salvage hook.
 *
 * Background: ricky's `--run` mode spawns a workflow subprocess that does
 * real implementation work in a worktree (writes files, runs tests) but
 * sometimes hangs at a review / fix / final-review step before reaching
 * `createGitHubStep`. The outer `gtimeout` then SIGTERMs the whole tree
 * and no PR opens — even though the worktree contains a perfectly good
 * implementation. The user has been manually salvaging these for days:
 *
 *   git -C <worktree> add . && git commit -m "<spec>" && git push && gh pr create
 *
 * This module automates that recovery. On every `--run` exit (success or
 * failure), if the spec carries `Target repo`, `Target branch`, and
 * `Worktree` metadata and the worktree has uncommitted work, we:
 *
 *   1. `git add .` (after resetting the workflow artifacts dir so internal
 *      bookkeeping files aren't committed).
 *   2. `git commit -m "<inferred title>" -m "<provenance + status>"`.
 *   3. `git push -u origin <branch>` — never `--force`.
 *   4. `gh pr create --repo AgentWorkforce/<repo>` with a body derived from
 *      the spec's `## Spec acceptance` / `## Test plan` sections (or the
 *      first 1500 chars of the spec body as a fallback).
 *
 * Salvage is additive: it never swallows the original exit code. The
 * caller still exits with whatever code ricky was about to exit with.
 *
 */
export type SalvageOutcome = 'salvaged' | 'skipped' | 'failed';
export interface SalvageResult {
    outcome: SalvageOutcome;
    reason: string;
    prUrl?: string;
    worktree?: string;
    branch?: string;
    probeError?: string;
}
export interface SalvageExitContext {
    /** The exit code ricky is about to return to the caller. */
    exitCode: number;
    /**
     * Optional human label for why ricky exited (e.g. "sigterm",
     * "workflow-failure"). Included in the commit body for provenance.
     */
    reason?: string;
}
export interface SalvageOptions {
    /** Disable salvage entirely (mirrors CLI `--no-auto-salvage`). */
    disabled?: boolean;
    /**
     * Environment to read `RICKY_DISABLE_AUTO_SALVAGE` from. Override for
     * tests; defaults to `process.env`.
     */
    env?: NodeJS.ProcessEnv;
}
export interface SalvageRuntime {
    git: GitClient;
    gh: GhClient;
    fs: FsProbe;
    logger: SalvageLogger;
    /** Owner used when opening GitHub PRs. Defaults to AgentWorkforce. */
    owner?: string;
}
export interface GitClient {
    /** Returns true when the path is the top of a git work tree. */
    isGitWorkTree(path: string): Promise<boolean>;
    /** `git -C <path> status --porcelain`. */
    status(path: string): Promise<string>;
    /** `git -C <path> rev-parse --abbrev-ref HEAD`. */
    currentBranch(path: string): Promise<string>;
    /** `git -C <path> reset <pathspec>` — unstage only. */
    reset(path: string, pathspec: string): Promise<void>;
    /** `git -C <path> add <pathspec>`. */
    add(path: string, pathspec: string): Promise<void>;
    /** Returns true when there is at least one staged change ready to commit. */
    hasStagedChanges(path: string): Promise<boolean>;
    /** `git -C <path> commit -m <subject> -m <body>`. */
    commit(path: string, subject: string, body: string): Promise<void>;
    /** `git -C <path> push -u origin <branch>` — must NOT pass --force. */
    push(path: string, branch: string): Promise<void>;
    /** `git -C <path> ls-remote --heads origin <branch>` — returns true when the branch exists on the remote. */
    remoteBranchExists(path: string, branch: string): Promise<boolean>;
}
export interface GhClient {
    /** `gh pr list --repo <owner>/<repo> --head <branch>`. */
    listPrs(repo: string, branch: string, owner: string): Promise<readonly {
        url: string;
    }[]>;
    /** `gh pr create --repo <owner>/<repo> --title <t> --body <b>`. */
    createPr(repo: string, branch: string, title: string, body: string, owner: string): Promise<{
        url: string;
    }>;
}
export interface FsProbe {
    /** Returns true when the path exists on disk. */
    exists(path: string): Promise<boolean>;
}
export interface SalvageLogger {
    /** Receives a single structured `[ricky auto-salvage] ...` line on stderr. */
    log(line: string): void;
}
/**
 * Main entry point. Always returns a structured result and emits a single
 * structured `[ricky auto-salvage] ...` line on the runtime logger. Never
 * throws — internal failures are surfaced as `outcome: 'failed'`.
 */
export declare function runAutoSalvage(specMarkdown: string, exitContext: SalvageExitContext, runtime: SalvageRuntime, options?: SalvageOptions): Promise<SalvageResult>;
