openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
41 lines (40 loc) • 2.35 kB
JavaScript
import { s as pathMayExistSync } from "./path-existence-Co7-GyVr.mjs";
import { d as resolveExecApprovalsPath } from "./exec-approvals-config-BBzEUJlE.mjs";
import { r as formatDoctorStateRepairFailure } from "./state-repair-message-CG0JUAZp.mjs";
import path from "node:path";
//#region src/infra/exec-approvals-migration-gate.ts
const DOCTOR_CLAIM_SUFFIX = ".doctor-importing";
const legacyAbsenceCache = /* @__PURE__ */ new Set();
/**
* Doctor repairs whichever state directory its own environment resolves to, so a bare
* `openclaw doctor --fix` repairs the default root while a scoped install stays blocked.
* Name the directory whenever this process is scoped to a non-default one. Say it in
* prose rather than as a `VAR=value cmd` one-liner, which no Windows shell accepts.
*/
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";
}
};
/** Refuse runtime access until Doctor owns the one-time legacy import. */
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();
}
//#endregion
export { assertNoPendingLegacyExecApprovals as n, resetExecApprovalsMigrationGateForTest as r, ExecApprovalsMigrationRequiredError as t };