openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
39 lines (38 loc) • 1.99 kB
JavaScript
import { t as pathMayExistSync } from "./path-existence-CzRtGGnO.js";
import { l as resolveExecApprovalsPath } from "./exec-approvals-config-D1lCGl0_.js";
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(filePath) {
const command = "Run `openclaw doctor --fix`";
return process.env.OPENCLAW_STATE_DIR?.trim() ? `${command} with OPENCLAW_STATE_DIR set to ${path.dirname(filePath)}` : command;
}
var ExecApprovalsMigrationRequiredError = class extends Error {
constructor(filePath) {
super(`Legacy exec approvals exist at ${filePath}. ${doctorFixInstruction(filePath)} before using exec approvals.`);
this.name = "ExecApprovalsMigrationRequiredError";
}
};
/** Refuse runtime access until Doctor owns the one-time legacy import. */
function assertNoPendingLegacyExecApprovals(options = {}) {
const sourcePath = resolveExecApprovalsPath();
if (legacyAbsenceCache.has(sourcePath)) return;
const probe = options.pathMayExist ?? pathMayExistSync;
const sourceBefore = probe(sourcePath);
const claim = probe(`${sourcePath}${DOCTOR_CLAIM_SUFFIX}`);
const sourceAfter = probe(sourcePath);
if (sourceBefore || claim || sourceAfter) throw new ExecApprovalsMigrationRequiredError(sourcePath);
legacyAbsenceCache.add(sourcePath);
}
function resetExecApprovalsMigrationGateForTest() {
legacyAbsenceCache.clear();
}
//#endregion
export { assertNoPendingLegacyExecApprovals as n, resetExecApprovalsMigrationGateForTest as r, ExecApprovalsMigrationRequiredError as t };