/**
 * Fix history persistence and backup/rollback SSH helpers.
 * Stores fix operations per server with remote backup support.
 * History entries are validated with Zod .strict() to prevent bloat.
 */
import { z } from "zod";
import type { FixExecutionLogEntry, FixHistoryEntry } from "./types.js";
/** Remote base directory for fix backups on the managed server */
export declare const REMOTE_BACKUP_BASE = "/root/.kastell/fix-backups";
export declare const fixHistoryEntrySchema: z.ZodObject<{
    fixId: z.ZodString;
    serverIp: z.ZodString;
    serverName: z.ZodString;
    timestamp: z.ZodString;
    checks: z.ZodArray<z.ZodString>;
    scoreBefore: z.ZodNumber;
    scoreAfter: z.ZodNullable<z.ZodNumber>;
    status: z.ZodEnum<{
        failed: "failed";
        applied: "applied";
        "rolled-back": "rolled-back";
    }>;
    backupPath: z.ZodOptional<z.ZodString>;
    executionLog: z.ZodOptional<z.ZodArray<z.ZodObject<{
        checkId: z.ZodString;
        command: z.ZodString;
        stdout: z.ZodString;
        stderr: z.ZodString;
        durationMs: z.ZodNumber;
        success: z.ZodBoolean;
    }, z.core.$strip>>>;
    source: z.ZodOptional<z.ZodEnum<{
        fix: "fix";
        doctor: "doctor";
        plugin: "plugin";
    }>>;
    pluginName: z.ZodOptional<z.ZodString>;
}, z.core.$strict>;
export declare function truncateExecutionLog(log: FixExecutionLogEntry[]): FixExecutionLogEntry[];
/**
 * Load fix history for a specific server IP.
 * Returns empty array if no history exists, file is corrupt, or any entry fails Zod .strict() validation.
 */
export declare function loadFixHistory(serverIp: string): FixHistoryEntry[];
/**
 * Save fix history entry.
 * Appends to existing history, caps at MAX_ENTRIES_PER_SERVER per server.
 * Uses atomic write pattern (write then rename) for safety.
 * Wrapped in withFileLock to prevent concurrent write corruption.
 */
export declare function saveFixHistory(entry: FixHistoryEntry): Promise<void>;
/**
 * Generate a new fix ID in "fix-YYYY-MM-DD-NNN" format.
 * NNN is a daily counter per server — increments if same server has fixes today.
 */
export declare function generateFixId(serverIp: string): string;
/**
 * Get the last successfully applied fix ID for a server.
 * Skips "rolled-back" and "failed" status entries.
 * Returns null if no applied fix exists.
 */
export declare function getLastFixId(serverIp: string): string | null;
/**
 * Save a rollback history entry for a previously applied fix.
 * Encapsulates the fix ID naming convention (appends "-rollback").
 */
export declare function saveRollbackEntry(entry: FixHistoryEntry, scoreAfter: number | null): Promise<void>;
/**
 * Extract absolute file paths from a fix command.
 * Matches /etc/..., /root/..., /var/..., /usr/..., /home/... paths.
 * Returns [] for sysctl/systemctl/useradd commands (no file paths to back up).
 */
export declare function extractFilePathsFromFixCommand(cmd: string): string[];
/**
 * Backup files on remote server before fix.
 * Uses mirror directory structure: /root/.kastell/fix-backups/{fixId}/etc/ssh/sshd_config
 * For sysctl-type fixes, captures current value in restore-commands.sh.
 * Returns the backup directory path.
 */
export declare function backupFilesBeforeFix(ip: string, fixId: string, fixCommands: Array<{
    checkId: string;
    fixCommand: string;
}>, extraBackupPaths?: string[]): Promise<string>;
/**
 * Rollback a fix by restoring files from backup directory.
 * 1. Runs restore-commands.sh if exists (sysctl rollback)
 * 2. Finds all backed-up files and copies them back to original paths
 */
export declare function rollbackFix(ip: string, backupPath: string): Promise<{
    restored: string[];
    errors: string[];
}>;
/**
 * Roll back all applied fixes for a server in reverse-chronological order.
 * Continues on individual failure, collecting all errors.
 */
export declare function rollbackAllFixes(ip: string): Promise<{
    rolledBack: string[];
    errors: string[];
}>;
/**
 * Roll back all fixes from newest down to and including the target fix-id.
 * Returns error if target fix-id is not found or not in applied state.
 */
export declare function rollbackToFix(ip: string, targetFixId: string): Promise<{
    rolledBack: string[];
    errors: string[];
}>;
/**
 * Prune old backup directories on remote server.
 * Keeps last 20, deletes oldest. Called after successful fix apply.
 */
export declare function backupRemoteCleanup(ip: string): Promise<void>;
//# sourceMappingURL=fix-history.d.ts.map