chore: Enable "curly" rule to avoid single-statement if confusion/errors.

This commit is contained in:
cpojer
2026-01-31 16:19:20 +09:00
parent 009b16fab8
commit 5ceff756e1
1266 changed files with 27871 additions and 9393 deletions

View File

@@ -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}`);
}