import { type FileHandle } from "node:fs/promises";
/** Why a session file's tail was set aside: a write that hit a full disk, any other failed write, or found on open. */
export type SessionRecoveryCause = "disk_full" | "write_failed" | "unknown";
/** One repair of a session file: the incomplete bytes were copied to `backupPath` (never deleted) and cut. */
export interface SessionRecovery {
    readonly cause: SessionRecoveryCause;
    readonly backupPath: string;
    readonly droppedBytes: number;
    /** The one-time notice for the person. */
    readonly notice: string;
}
export declare function sessionRecoveryCause(error: unknown): SessionRecoveryCause;
/**
 * Copies torn bytes to `<path>.torn-<time>-<id>` through the atomic session-file writer (temp file, fsync, rename),
 * so a full disk leaves no partial copy, and returns the recovery to report. Throws when the copy is refused.
 */
export declare function backupTornBytes(path: string, bytes: Buffer, cause: SessionRecoveryCause): SessionRecovery;
/**
 * Cuts a JSONL session file back to its last complete line, first copying what it cuts aside (senpi#4295). An append
 * that failed part-way (ENOSPC) can leave a partial line, and the next append would be glued onto it, losing both
 * entries on reload. A file that already ends in a newline is left untouched and returns undefined; a refused copy
 * throws before anything is cut.
 */
export declare function truncateToLastCompleteLine(path: string, cause: SessionRecoveryCause): SessionRecovery | undefined;
/**
 * Closes and removes a session file whose first flush failed part-way, then rethrows the write
 * error. The first flush creates the file exclusively, so a partial file left behind would fail
 * every later flush with EEXIST while memory kept growing. A failed close does not skip the
 * removal; any cleanup failure is thrown together with the write error.
 */
export declare function discardFailedFirstFlush(path: string, fd: number, writeError: unknown): never;
/**
 * `discardFailedFirstFlush` for the asynchronous header write: closes `handle` (when it is still open)
 * and removes the file that write created, then rethrows the write error.
 */
export declare function discardFailedFirstFlushAsync(path: string, handle: FileHandle | undefined, writeError: unknown): Promise<never>;
//# sourceMappingURL=session-write-recovery.d.ts.map