UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

4 lines • 2.77 kB
import{n as safeParseJsonRecord}from"./json-coercion-DNNwq4_v.mjs";import{n as normalizeAgentId}from"./agent-id-cOfqmfln.mjs";import"./session-key-BPgKfU2m.mjs";import{n as listAgentEntries}from"./agent-roster-4XrgUgPK.mjs";import"./agent-scope-config-CG9CFpGX.mjs";import{a as getOpenClawDatabaseMaintenanceScope}from"./openclaw-state-maintenance-context-D-pYfco8.mjs";import{s as resolveOpenClawStateSqlitePath}from"./openclaw-state-db.paths-CbgXfEg1.mjs";import"./openclaw-state-db-async-lifecycle-DlV0ztcV.mjs";import{r as resolveLegacyAgentRosterOwner}from"./legacy.roster-CU2eR_i6.mjs";import{a as resolveCronJobsStorePathFromConfig}from"./paths-BFxu7LPC.mjs";import{t as note}from"./note-e4DtVgg2.mjs";import{c as resolveStoredCronJobOwner,s as repairLegacyCronJobOwnersForDoctor}from"./store-repair-CIGQuno0.mjs";import{i as loadLegacyCronRepairState}from"./legacy-repair-Bpgsh7Eq.mjs";import{n as createCronOwnerWriteRefusalError,t as canDeferRehearsalCronMigration}from"./io.cron-owner-refusal-IGr9kDDI.mjs"; //!src/commands/doctor/cron/legacy-owner.ts 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();if(s.warnings?.length)note(s.warnings.join(` `),`Doctor warnings`);return s.changed>0?[`Preserved ownership for ${s.changed} legacy cron job(s); unassigned jobs retain ${r}.`,`Saved pre-repair cron backup: ${s.backupPath}`]:[]}export{repairLegacyCronOwnersBeforeConfigWrite};