openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
48 lines (47 loc) • 2.58 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { r as truncateUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs";
import { n as sanitizeTerminalText } from "./safe-text-C80HAQ2e.mjs";
import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs";
//#region src/infra/exec-auto-review.ts
const EXEC_AUTO_REVIEW_DENIAL_GUIDANCE = "Do not attempt the same outcome through a workaround, indirect execution, or policy circumvention. Proceed only with a materially safer alternative, or ask the user to approve this exact command after explaining the risk.";
const EXEC_AUTO_REVIEW_SHELL_STARTUP_WARNING = "Exec auto-review skipped: login or interactive shell startup requires human approval";
const EXEC_AUTO_REVIEW_DISPATCH_IDENTITY_WARNING = "Exec auto-review skipped: dispatch chain cannot be bound";
function formatExecAutoReviewAssessment(e) {
return `risk=${e.risk}${e.userAuthorization ? `, authorization=${e.userAuthorization}` : ""}`;
}
/** Keeps reviewer and provider explanations safe for human-facing approval text. */
function normalizeExecAutoReviewRationale(e, t) {
const n = normalizeOptionalString(e);
const r = sanitizeTerminalText(n ?? t).replace(/[\p{Cf}\u2028\u2029]/gu, "").replace(/\s+/gu, " ").trim();
return truncateUtf16Safe(r || t, 500);
}
/** Turns reviewer and provider failures into a bounded, redacted human-review decision. */
function buildExecAutoReviewFailureDecision(e, t) {
return {
decision: "ask",
risk: "unknown",
rationale: normalizeExecAutoReviewRationale(`${e}: ${formatErrorMessage(t)}`, e)
};
}
/** Reviewer failures become ask decisions; each approval owner applies its own policy. */
async function resolveExecAutoReviewDecision(e, t) {
try {
return await e(t);
} catch (e) {
return buildExecAutoReviewFailureDecision("exec reviewer failed", e);
}
}
/**
* Conservative fallback used when no model-backed reviewer is available.
* Auto mode must never become a static allowlist; without a reviewer, defer to
* the normal human approval route.
*/
const defaultExecAutoReviewer = (e) => {
return {
decision: "ask",
rationale: `no model-backed exec reviewer is configured for ${e.host}`,
risk: e.analysis.inlineEval ? "medium" : "unknown"
};
};
//#endregion
export { defaultExecAutoReviewer as a, resolveExecAutoReviewDecision as c, buildExecAutoReviewFailureDecision as i, EXEC_AUTO_REVIEW_DISPATCH_IDENTITY_WARNING as n, formatExecAutoReviewAssessment as o, EXEC_AUTO_REVIEW_SHELL_STARTUP_WARNING as r, normalizeExecAutoReviewRationale as s, EXEC_AUTO_REVIEW_DENIAL_GUIDANCE as t };