UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.76 kB
import{s as pathMayExistSync}from"./path-existence-BR9MXlgL.mjs";import{d as resolveExecApprovalsPath}from"./exec-approvals-config-B_i2AhQm.mjs";import{r as formatDoctorStateRepairFailure}from"./state-repair-message-CmSHWF4H.mjs";import path from"node:path"; //!src/infra/exec-approvals-migration-gate.ts const DOCTOR_CLAIM_SUFFIX=`.doctor-importing`;const legacyAbsenceCache=/* @__PURE__ */ new Set;function doctorFixInstruction(e,t){const n="Run `openclaw doctor --fix`";if(e.endsWith(`#exec_approvals_config`))return`${n} with OPENCLAW_STATE_DIR set to ${path.dirname(path.dirname(e))}`;return t.OPENCLAW_STATE_DIR?.trim()?`${n} with OPENCLAW_STATE_DIR set to ${path.dirname(e)}`:n}var ExecApprovalsMigrationRequiredError=class extends Error{constructor(e,t,n=`Legacy exec approvals exist`,r=process.env){super(t===`doctor`?formatDoctorStateRepairFailure(`${n} at ${e}`,`Stop the Gateway and node hosts, then reconcile this file with a verified copy of the intended exec policy; preserve existing SQLite policy.`):`${n} at ${e}. ${doctorFixInstruction(e,r)} before using exec approvals.`);this.name=`ExecApprovalsMigrationRequiredError`}};function assertNoPendingLegacyExecApprovals(e={}){const t=resolveExecApprovalsPath(e.env);if(legacyAbsenceCache.has(t))return;const n=e.pathMayExist??pathMayExistSync;const r=n(t);const i=n(`${t}${DOCTOR_CLAIM_SUFFIX}`);const a=n(t);if(r||i||a)throw new ExecApprovalsMigrationRequiredError(e.operation===`doctor`&&!r&&!a?`${t}${DOCTOR_CLAIM_SUFFIX}`:t,e.operation,void 0,e.env);legacyAbsenceCache.add(t)}function resetExecApprovalsMigrationGateForTest(){legacyAbsenceCache.clear()}export{assertNoPendingLegacyExecApprovals as n,resetExecApprovalsMigrationGateForTest as r,ExecApprovalsMigrationRequiredError as t};