openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
39 lines (38 loc) • 2.28 kB
JavaScript
import { t as formatCliCommand } from "./command-format-C7YfyMTd.js";
import { r as withExistingOpenClawStateDatabaseReadOnly } from "./openclaw-state-db-readonly-BRgmrGHt.js";
import { t as note } from "./note-DqHk3fA1.js";
import { n as readLatestSuccessfulBackupRun, t as readLatestBackupRun } from "./backup-run-records-BNUh01Bt.js";
//#region src/commands/backup-health.ts
const BACKUP_STALE_AFTER_MS = 12096e5;
/** Read backup freshness without creating or repairing an absent state database. */
function readBackupFreshness(env) {
return withExistingOpenClawStateDatabaseReadOnly(({ db }) => ({
latest: readLatestBackupRun(db),
latestOk: readLatestSuccessfulBackupRun(db)
}), { env }) ?? {};
}
/** Format the compact status overview value for the latest backup attempt. */
function buildBackupStatusValue(params) {
const latest = params.freshness.latest;
if (!latest) return "none recorded";
const age = params.formatTimeAgo(Math.max(0, (params.now ?? Date.now()) - latest.createdAt));
return latest.status === "ok" ? `last ok ${age} (${latest.kind}${latest.pushFailed ? ", push failing" : ""})` : `last attempt failed ${age} (${latest.kind})`;
}
/** Build the informational Doctor hint for missing or stale successful backups. */
function buildBackupDoctorHint(params) {
const latestOk = params.freshness.latestOk;
if (latestOk?.pushFailed) return ["The newest local Git backup succeeded, but its requested push failed.", `Check the configured Git remote for ${latestOk.archivePath}, then retry the backup.`].join("\n");
if (!(!latestOk || (params.now ?? Date.now()) - latestOk.createdAt > BACKUP_STALE_AFTER_MS)) return null;
return [
latestOk ? "The newest successful backup is more than 14 days old." : "No successful backup is recorded.",
`Create one now with ${formatCliCommand("openclaw backup create")}.`,
`Schedule versioned backups with ${formatCliCommand("openclaw backup enable --repository <dir>")}.`
].join("\n");
}
/** Emit the non-repairing backup freshness hint when it applies. */
function noteBackupDoctorHint(env) {
const hint = buildBackupDoctorHint({ freshness: readBackupFreshness(env) });
if (hint) note(hint, "Backups");
}
//#endregion
export { noteBackupDoctorHint as n, readBackupFreshness as r, buildBackupStatusValue as t };