UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

46 lines (45 loc) • 3.04 kB
import { n as safeParseJsonRecord } from "./json-coercion-pfKbZnCJ.mjs"; import { c as resolveOpenClawStateSqlitePath } from "./openclaw-state-db.paths-CmKkMYdo.mjs"; import { u as getOpenClawDatabaseMaintenanceScope } from "./openclaw-state-db-async-lifecycle-DwFy2ZTk.mjs"; import { n as normalizeAgentId } from "./agent-id-D1-Q6vR4.mjs"; import "./session-key-DY3MOX4N.mjs"; import { n as listAgentEntries } from "./agent-roster-DH6r_8f4.mjs"; import "./agent-scope-config-BEk6-ThS.mjs"; import { r as resolveLegacyAgentRosterOwner } from "./legacy.roster-BkkM_O4n.mjs"; import { n as resolveCronJobsStorePathFromConfig } from "./paths-Dqy-ZJ8r.mjs"; import { t as createCronOwnerWriteRefusalError } from "./io.cron-owner-refusal-D5z8a7rA.mjs"; import { r as loadLegacyCronRepairState } from "./legacy-repair-k8_3q1VU.mjs"; import { a as repairLegacyCronJobOwnersForDoctor, o as resolveStoredCronJobOwner } from "./store-repair-qdlpuWym.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(params) { const env = params.env ?? process.env; const source = params.snapshot.sourceConfigBeforeMigrations ?? params.snapshot.sourceConfig; const legacyOwner = [params.snapshot.sourceConfigBeforeMigrations, params.snapshot.parsed].map(resolveLegacyAgentRosterOwner).find((owner) => owner !== void 0); if (!legacyOwner) return []; params.assertCurrent?.(); const storePath = resolveCronJobsStorePathFromConfig(source, env); const state = await loadLegacyCronRepairState({ cfg: params.snapshot.config, storePath, env, readOnly: true }); params.assertCurrent?.(); if (!(state?.rawJobs.some((job) => !resolveStoredCronJobOwner(job)) || state?.ownerRows.some((row) => !resolveStoredCronJobOwner(safeParseJsonRecord(row.job_json))))) return []; if (!listAgentEntries(params.nextConfig).some((entry) => normalizeAgentId(entry.id) === normalizeAgentId(legacyOwner))) throw createCronOwnerWriteRefusalError(`Doctor cannot retire legacy cron owner ${legacyOwner} while its jobs are unassigned. Preserve that agent and rerun "openclaw doctor --fix" first.`); const maintenance = getOpenClawDatabaseMaintenanceScope(); if (!maintenance?.ownsSchemaMaintenance) throw createCronOwnerWriteRefusalError("Cron ownership repair requires Doctor maintenance. Run \"openclaw doctor --fix\" before retrying the config write."); const assertCurrent = () => { params.assertCurrent?.(); maintenance.assertDatabaseAccess(resolveOpenClawStateSqlitePath(env)); }; const result = await repairLegacyCronJobOwnersForDoctor({ env }, { assertCurrent, assertOwnedInTransaction: assertCurrent }, storePath, legacyOwner); assertCurrent(); return result.changed > 0 ? [`Preserved ownership for ${result.changed} legacy cron job(s); unassigned jobs retain ${legacyOwner}.`, `Saved pre-repair cron backup: ${result.backupPath}`] : []; } //#endregion export { repairLegacyCronOwnersBeforeConfigWrite };