openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
7 lines (6 loc) • 2.6 kB
JavaScript
import{r as terminalText}from"./safe-text-B_QTgn0s.mjs";import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{a as resolveCronJobsStorePathFromConfig}from"./paths-BFxu7LPC.mjs";import{t as note}from"./note-e4DtVgg2.mjs";import{r as loadCronJobsStoreWithConfigJobsReadOnly}from"./read-only-CWdlWw2g.mjs";import{a as summarizeBackupFreshness,o as summarizeBackupTargets,r as readBackupRuns}from"./backup-run-records-5G1D5f34.mjs";import{i as summarizeBackupSchedules}from"./backup-command-SjLQXBkh.mjs";
//!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(`
`);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(`
`)}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(`
`),`Backups`)}export{noteBackupDoctorHint as n,buildBackupStatusValue as t};