/** * Corrupt/missing state handling with recovery support. * * Provides: * - `loadWithRecovery()` — load a state file, reporting errors clearly * with optional backup before any recovery attempt. * - `backupStateFile()` — create a timestamped backup copy of a file. * - `detectConflictMarkers()` — scan a file for git conflict markers and * produce a report with resolution steps. * * Key invariant: the original file is NEVER modified or discarded. * Backups are copies; the original stays intact until the user explicitly * resolves the issue. * * Requirements: 4.6, 4.7 */ import type { SchemaValidator } from './yaml-helpers.js'; /** * Result of a recovery-aware load attempt. * * - `data`: the parsed content if successful, null otherwise. * - `recovered`: true if a backup was created during this load attempt. * - `backupPath`: path to the backup file if one was created, null otherwise. * - `error`: human-readable error message if loading failed, null on success. */ export interface RecoveryResult { data: T | null; recovered: boolean; backupPath: string | null; error: string | null; } /** * Report produced when git conflict markers are detected in a state file. */ export interface ConflictReport { /** Path to the file containing conflict markers. */ filePath: string; /** Fields that appear to be in conflict (best-effort extraction). */ conflictingFields: string[]; /** Human-readable resolution steps. */ resolutionSteps: string[]; } /** * Create a timestamped backup of a state file. * * Naming convention: `.backup.` * (colons in the timestamp are replaced with hyphens for filesystem safety). * * The original file is NOT modified — the backup is a pure copy. * * @param filePath - Absolute path to the file to back up. * @returns The absolute path to the created backup file. * @throws {YamlLoadError} If the source file does not exist. */ export declare function backupStateFile(filePath: string): string; /** * Detect git conflict markers in a file and produce a resolution report. * * Scans the file content for `<<<<<<<`, `=======`, `>>>>>>>` marker lines. * If any are found, attempts to identify which YAML fields are in conflict * by parsing the "ours" and "theirs" sections. * * @param filePath - Absolute path to the file to check. * @returns A ConflictReport if markers are found, null otherwise. */ export declare function detectConflictMarkers(filePath: string): ConflictReport | null; /** * Load a state file with recovery support. * * Behavior: * - If the file is missing: returns an error result naming the file. * - If the file has conflict markers: returns an error result describing * the conflicts, optionally backs up before returning. * - If the file is corrupt (invalid YAML or fails validation): * a) Reports which file is invalid and why. * b) Optionally creates a backup copy before returning. * c) NEVER modifies or discards the original file. * * @param filePath - Absolute path to the state file to load. * @param validate - Optional schema validator. * @param opts - Options: `backup` controls whether a backup is created on error. * @returns A RecoveryResult describing the outcome. */ export declare function loadWithRecovery(filePath: string, validate?: SchemaValidator, opts?: { backup?: boolean; }): RecoveryResult; //# sourceMappingURL=state-recovery.d.ts.map