UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

48 lines (47 loc) • 2.99 kB
import { n as safeParseJsonRecord } from "./json-coercion-CaJLaav-.mjs"; import { n as normalizeAgentId } from "./agent-id-CQjtp2ft.mjs"; import "./session-key-CqAyZeVk.mjs"; import { n as listAgentEntries } from "./agent-roster-t1ooUdXp.mjs"; import "./agent-scope-config-DmXgFGKP.mjs"; import { a as getOpenClawDatabaseMaintenanceScope } from "./openclaw-state-maintenance-context-D6i7Zdhn.mjs"; import { s as resolveOpenClawStateSqlitePath } from "./openclaw-state-db.paths-R3ArRCcz.mjs"; import "./openclaw-state-db-async-lifecycle-CH8q4Sdl.mjs"; import { r as resolveLegacyAgentRosterOwner } from "./legacy.roster-BcYJITMZ.mjs"; import { a as resolveCronJobsStorePathFromConfig } from "./paths-CY4cvrR6.mjs"; import { c as resolveStoredCronJobOwner, s as repairLegacyCronJobOwnersForDoctor } from "./store-repair-Dv1WdfLr.mjs"; import { i as loadLegacyCronRepairState } from "./legacy-repair-D9TVWPHm.mjs"; import { n as createCronOwnerWriteRefusalError, t as canDeferRehearsalCronMigration } from "./io.cron-owner-refusal-D4hqLyjp.mjs"; //#region src/commands/doctor/cron/legacy-owner.ts /** Runs under Doctor's config lock before retiring the source roster's owner marker. */ async function repairLegacyCronOwnersBeforeConfigWrite(e) { const t = e.env ?? process.env; const n = e.snapshot.sourceConfigBeforeMigrations ?? e.snapshot.sourceConfig; const r = [e.snapshot.sourceConfigBeforeMigrations, e.snapshot.parsed].map(resolveLegacyAgentRosterOwner).find((e) => e !== void 0); if (!r) return []; if (await canDeferRehearsalCronMigration(n, e.snapshot.path, t)) return []; e.assertCurrent?.(); const i = resolveCronJobsStorePathFromConfig(n, t); const a = await loadLegacyCronRepairState({ cfg: e.snapshot.config, storePath: i, env: t, readOnly: true }); e.assertCurrent?.(); if (!(a?.rawJobs.some((e) => !resolveStoredCronJobOwner(e)) || a?.ownerRows.some((e) => !resolveStoredCronJobOwner(safeParseJsonRecord(e.job_json))))) return []; if (!listAgentEntries(e.nextConfig).some((e) => normalizeAgentId(e.id) === normalizeAgentId(r))) throw createCronOwnerWriteRefusalError(`Doctor cannot retire legacy cron owner ${r} while its jobs are unassigned. Preserve that agent and rerun "openclaw doctor --fix" first.`); const o = getOpenClawDatabaseMaintenanceScope(); if (!o?.ownsSchemaMaintenance) throw createCronOwnerWriteRefusalError("Cron ownership repair requires Doctor maintenance. Run \"openclaw doctor --fix\" before retrying the config write."); const assertCurrent = () => { e.assertCurrent?.(); o.assertDatabaseAccess(resolveOpenClawStateSqlitePath(t)); }; const s = await repairLegacyCronJobOwnersForDoctor({ env: t }, { assertCurrent, assertOwnedInTransaction: assertCurrent }, i, r); assertCurrent(); return s.changed > 0 ? [`Preserved ownership for ${s.changed} legacy cron job(s); unassigned jobs retain ${r}.`, `Saved pre-repair cron backup: ${s.backupPath}`] : []; } //#endregion export { repairLegacyCronOwnersBeforeConfigWrite };