openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
49 lines (48 loc) • 3 kB
JavaScript
import { r as terminalText } from "./safe-text-C80HAQ2e.mjs";
import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs";
import { a as resolveCronJobsStorePathFromConfig } from "./paths-CY4cvrR6.mjs";
import { t as note } from "./note-CnLgHvug.mjs";
import { a as summarizeBackupFreshness, o as summarizeBackupTargets, r as readBackupRuns } from "./backup-run-records-B0d7Qm1y.mjs";
import { r as loadCronJobsStoreWithConfigJobsReadOnly } from "./read-only-C2x_PRgh.mjs";
import { i as summarizeBackupSchedules } from "./backup-command-BiUB26T8.mjs";
//#region src/commands/backup-health.ts
const BACKUP_STALE_AFTER_MS = 12096e5;
function buildBackupStatusValue(e) {
const t = e.freshness.latest;
if (!t) return "none recorded";
const n = e.formatTimeAgo(Math.max(0, Date.now() - t.createdAt));
return t.status === "ok" ? `last ok ${n} (${t.kind}${t.pushFailed ? ", push failing" : ""})` : `last attempt failed ${n} (${t.kind})`;
}
function buildBackupDoctorHint(e) {
const t = e.latestOk;
if (t?.pushFailed) return ["The newest local Git backup succeeded, but its requested push failed.", terminalText`Check the configured Git remote for ${t.archivePath}, then retry the backup.`].join("\n");
if (!(!t || Date.now() - t.createdAt > BACKUP_STALE_AFTER_MS)) return null;
return [
t ? "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 non-repairing freshness hints; configuration and ledger reads never probe destinations. */
async function noteBackupDoctorHint(e, t) {
const n = await readBackupRuns(e);
const r = buildBackupDoctorHint(summarizeBackupFreshness(n));
const i = r ? [r] : [];
if (t) {
const r = await loadCronJobsStoreWithConfigJobsReadOnly(resolveCronJobsStorePathFromConfig(t, e), e);
const a = summarizeBackupSchedules(r.store.jobs);
const o = summarizeBackupTargets(n);
const s = Date.now();
i.push(...a.flatMap((e) => {
if (e.mode !== "offsite" || !e.enabled) return [];
const t = o.find((t) => t.kind === "archive" && t.target === e.target && t.namespace === e.namespace);
const n = t?.latest.status === "failed";
const r = !t?.latestOk || s - t.latestOk.createdAt > 3 * e.everyMs;
if (!n && !r) return [];
return [`${n ? terminalText`The newest offsite backup attempt to ${e.target} failed${t.latest.error ? `: ${t.latest.error}` : "."}` : t?.latestOk ? terminalText`The newest successful offsite backup to ${e.target} is older than three scheduled intervals.` : terminalText`No successful offsite backup to ${e.target} is recorded.`}\nCheck the destination with ${formatCliCommand(terminalText`openclaw storage test ${e.target}`)}.`];
}));
}
if (i.length) note(i.join("\n\n"), "Backups");
}
//#endregion
export { noteBackupDoctorHint as n, buildBackupStatusValue as t };