mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 05:01:23 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -8,8 +8,12 @@ import { resolveSandboxToolPolicyForAgent } from "./tool-policy.js";
|
||||
import type { SandboxConfig, SandboxToolPolicyResolved } from "./types.js";
|
||||
|
||||
function shouldSandboxSession(cfg: SandboxConfig, sessionKey: string, mainSessionKey: string) {
|
||||
if (cfg.mode === "off") return false;
|
||||
if (cfg.mode === "all") return true;
|
||||
if (cfg.mode === "off") {
|
||||
return false;
|
||||
}
|
||||
if (cfg.mode === "all") {
|
||||
return true;
|
||||
}
|
||||
return sessionKey.trim() !== mainSessionKey.trim();
|
||||
}
|
||||
|
||||
@@ -17,7 +21,9 @@ function resolveMainSessionKeyForSandbox(params: {
|
||||
cfg?: OpenClawConfig;
|
||||
agentId: string;
|
||||
}): string {
|
||||
if (params.cfg?.session?.scope === "global") return "global";
|
||||
if (params.cfg?.session?.scope === "global") {
|
||||
return "global";
|
||||
}
|
||||
return resolveAgentMainSessionKey({
|
||||
cfg: params.cfg,
|
||||
agentId: params.agentId,
|
||||
@@ -78,20 +84,26 @@ export function formatSandboxToolPolicyBlockedMessage(params: {
|
||||
toolName: string;
|
||||
}): string | undefined {
|
||||
const tool = params.toolName.trim().toLowerCase();
|
||||
if (!tool) return undefined;
|
||||
if (!tool) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const runtime = resolveSandboxRuntimeStatus({
|
||||
cfg: params.cfg,
|
||||
sessionKey: params.sessionKey,
|
||||
});
|
||||
if (!runtime.sandboxed) return undefined;
|
||||
if (!runtime.sandboxed) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const deny = new Set(expandToolGroups(runtime.toolPolicy.deny));
|
||||
const allow = expandToolGroups(runtime.toolPolicy.allow);
|
||||
const allowSet = allow.length > 0 ? new Set(allow) : null;
|
||||
const blockedByDeny = deny.has(tool);
|
||||
const blockedByAllow = allowSet ? !allowSet.has(tool) : false;
|
||||
if (!blockedByDeny && !blockedByAllow) return undefined;
|
||||
if (!blockedByDeny && !blockedByAllow) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const reasons: string[] = [];
|
||||
const fixes: string[] = [];
|
||||
@@ -112,7 +124,9 @@ export function formatSandboxToolPolicyBlockedMessage(params: {
|
||||
lines.push(`Reason: ${reasons.join(" + ")}`);
|
||||
lines.push("Fix:");
|
||||
lines.push(`- agents.defaults.sandbox.mode=off (disable sandbox)`);
|
||||
for (const fix of fixes) lines.push(`- ${fix}`);
|
||||
for (const fix of fixes) {
|
||||
lines.push(`- ${fix}`);
|
||||
}
|
||||
if (runtime.mode === "non-main") {
|
||||
lines.push(`- Use main session key (direct): ${runtime.mainSessionKey}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user