openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
76 lines (75 loc) • 3.24 kB
JavaScript
import { n as sanitizeTerminalText } from "./safe-text-C80HAQ2e.mjs";
import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs";
import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs";
import { t as note } from "./note-CnLgHvug.mjs";
import { r as validateInstallPolicyStatic, t as probeInstallPolicy } from "./install-policy-3Frq4hdS.mjs";
import path from "node:path";
import fs from "node:fs/promises";
import os from "node:os";
//#region src/commands/doctor-install-policy.ts
async function collectInstallPolicyHealthLines(e, t = {}) {
const n = await validateInstallPolicyStatic(e);
if (!n.enabled) return [];
const report = (e, n, r) => {
const a = {
checkId: "core/doctor/install-policy",
severity: n,
message: e,
category: n === "error" ? "fix-now" : "recommended",
path: "security.installPolicy.exec",
fixHint: r,
docsUrl: "https://docs.openclaw.ai/gateway/security/tool-permissions#plugins"
};
if (t.onFinding) t.onFinding(a);
else i.push(`- ${n.toUpperCase()}: ${e}`, `- ${r}`);
};
const r = "Correct security.installPolicy.exec and its command permissions, then run openclaw doctor --deep. Covered installs and updates remain blocked until the policy check succeeds.";
const i = [`- Install policy enabled for: ${n.targets.length > 0 ? n.targets.join(", ") : "none"}`];
for (const e of n.issues) report(sanitizeTerminalText(e.message), e.severity, r);
if (n.issues.some((e) => e.severity === "error")) {
if (!t.onFinding) i.push("- Installs and updates for covered targets will be blocked until this is fixed.");
return i;
}
if (!t.deep) {
i.push(`- Static checks passed. Run ${formatCliCommand("openclaw doctor --deep")} to execute a synthetic policy check.`);
return i;
}
const a = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-install-policy-probe-"));
try {
const n = await probeInstallPolicy({
config: e,
env: t.env,
logger: {},
sourcePath: a
});
if (n?.warning) {
report(`Deep check returned a warning: ${sanitizeTerminalText(n.warning.reason)}`, "warning", "No repair is needed if this is your intended policy. Review each real install warning; covered installs require explicit acknowledgement when this warning is returned. Doctor does not approve an install.");
return i;
}
if (!n?.blocked) {
i.push("- Deep check allowed the synthetic install request.");
return i;
}
if (n.blocked.code === "security_scan_blocked") {
i.push(`- Deep check reached the policy command and the policy blocked the synthetic request: ${sanitizeTerminalText(n.blocked.reason)}`);
return i;
}
report(`Deep check failed closed: ${sanitizeTerminalText(n.blocked.reason)}`, "error", r);
} catch (e) {
report(`Deep check could not run: ${sanitizeTerminalText(formatErrorMessage(e))}`, "error", r);
} finally {
await fs.rm(a, {
recursive: true,
force: true
});
}
if (!t.onFinding) i.push("- Installs and updates for covered targets will be blocked until this is fixed.");
return i;
}
async function noteInstallPolicyHealth(e, t = {}) {
const n = await collectInstallPolicyHealthLines(e, t);
if (n.length === 0) return;
note(n.join("\n"), "Install policy");
}
//#endregion
export { noteInstallPolicyHealth };