UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

187 lines (186 loc) • 6.54 kB
import { y as sortUniqueStrings } from "./string-normalization-DLmfYZXI.mjs"; import { n as listAgentEntries } from "./agent-roster-t1ooUdXp.mjs"; import { A as tryResolveLegacyCompatibilityAgentId } from "./agent-scope-config-DmXgFGKP.mjs"; import { r as DEFAULT_EXEC_APPROVAL_ASK_FALLBACK, u as resolveExecApprovalsDisplayPath } from "./exec-approvals-config-BBzEUJlE.mjs"; import { l as resolveExecModeFromPolicy, u as resolveExecModePolicy } from "./exec-approvals-core-puBAw1bE.mjs"; import { n as maxAsk, o as resolveExecApprovalAllowedDecisions, r as minSecurity } from "./exec-approvals-policy-BGzNHuNm.mjs"; import { t as resolveExecApprovalsFromFileInternal } from "./exec-approvals-resolver-C6IwmycS.mjs"; import "./exec-approvals-rOfoWejC.mjs"; //#region src/infra/exec-approvals-effective.ts const DEFAULT_REQUESTED_SECURITY = "full"; const DEFAULT_REQUESTED_ASK = "off"; const SESSION_EXEC_OVERRIDES_NOTE = "Per-session /exec overrides are not included; run /exec in the relevant session to inspect its current defaults."; function resolveRequestedField(e) { if (e.scopeValue !== void 0) return { value: e.scopeValue, source: e.scopeSource }; if (e.globalValue !== void 0) return { value: e.globalValue, source: e.globalSource }; return { value: e.fallback, source: `OpenClaw default (${e.fallback})` }; } function hasLegacyExecPolicyOverride(e) { return e?.security !== void 0 || e?.ask !== void 0; } function resolveRequestedPolicy(e) { const t = e.scopeExecConfig?.mode || (!hasLegacyExecPolicyOverride(e.scopeExecConfig) ? e.globalExecConfig?.mode : void 0); if (t) { const n = resolveExecModePolicy({ mode: t, security: DEFAULT_REQUESTED_SECURITY, ask: DEFAULT_REQUESTED_ASK }); const r = `${e.scopeExecConfig?.mode ? e.configPath : "tools.exec"}.mode`; return { mode: n.mode, modeSource: r, security: n.security, securitySource: r, ask: n.ask, askSource: r }; } const n = e.globalExecConfig?.mode ? resolveExecModePolicy({ mode: e.globalExecConfig.mode, security: DEFAULT_REQUESTED_SECURITY, ask: DEFAULT_REQUESTED_ASK }) : void 0; const r = resolveRequestedField({ scopeValue: e.scopeExecConfig?.security, globalValue: n?.security ?? e.globalExecConfig?.security, fallback: DEFAULT_REQUESTED_SECURITY, scopeSource: `${e.configPath}.security`, globalSource: n ? "tools.exec.mode" : "tools.exec.security" }); const i = resolveRequestedField({ scopeValue: e.scopeExecConfig?.ask, globalValue: n?.ask ?? e.globalExecConfig?.ask, fallback: DEFAULT_REQUESTED_ASK, scopeSource: `${e.configPath}.ask`, globalSource: n ? "tools.exec.mode" : "tools.exec.ask" }); return { mode: resolveExecModeFromPolicy({ security: r.value, ask: i.value }), modeSource: r.source === i.source ? `derived from ${r.source}` : `derived from ${r.source} and ${i.source}`, security: r.value, securitySource: r.source, ask: i.value, askSource: i.source }; } function collectExecPolicyScopeSnapshots(e) { const t = tryResolveLegacyCompatibilityAgentId(e.cfg); const n = [resolveExecPolicyScopeSnapshot({ approvals: e.approvals, agentId: t, scopeExecConfig: e.cfg.tools?.exec, configPath: "tools.exec", hostPath: e.hostPath, hostDefaults: e.hostDefaults, hostDefaultSource: e.hostDefaultSource, scopeLabel: "tools.exec" })]; const r = e.cfg.tools?.exec; const i = listAgentEntries(e.cfg); const a = new Set(i.filter((e) => e.id !== t || e.tools?.exec !== void 0).map((e) => e.id)); const o = Object.keys(e.approvals.agents ?? {}).filter((e) => e !== "*" && e !== "default" && e !== t); const s = sortUniqueStrings([...a, ...o]); for (const t of s) { const a = i.find((e) => e.id === t); n.push(resolveExecPolicyScopeSnapshot({ approvals: e.approvals, scopeExecConfig: a?.tools?.exec, globalExecConfig: r, configPath: `agents.entries.${t}.tools.exec`, hostPath: e.hostPath, hostDefaults: e.hostDefaults, hostDefaultSource: e.hostDefaultSource, scopeLabel: `agent:${t}`, agentId: t })); } return n; } function resolveExecPolicyScopeSnapshot(e) { const t = resolveRequestedField({ scopeValue: e.scopeExecConfig?.host, globalValue: e.globalExecConfig?.host, fallback: "auto", scopeSource: `${e.configPath}.host`, globalSource: "tools.exec.host" }); const n = resolveRequestedPolicy({ scopeExecConfig: e.scopeExecConfig, globalExecConfig: e.globalExecConfig, configPath: e.configPath }); const r = resolveExecApprovalsFromFileInternal({ file: e.approvals, agentId: e.agentId, overrides: { security: e.hostDefaults?.security ?? n.security, ask: e.hostDefaults?.ask ?? n.ask, ...e.hostDefaults ? { askFallback: e.hostDefaults.askFallback } : {} } }); const i = e.hostPath ?? resolveExecApprovalsDisplayPath(); const formatHostFieldSource = (t, n) => { if (n) return `${i} ${n}`; if (e.hostDefaultSource) return e.hostDefaultSource; if (t === "askFallback") return `OpenClaw default (${DEFAULT_EXEC_APPROVAL_ASK_FALLBACK})`; return "inherits requested tool policy"; }; const a = minSecurity(n.security, r.agent.security); const o = maxAsk(n.ask, r.agent.ask); const s = minSecurity(a, r.agent.askFallback); const c = a === n.security && o === n.ask ? n.mode : resolveExecModeFromPolicy({ security: a, ask: o }); return { scopeLabel: e.scopeLabel, configPath: e.configPath, ...e.agentId ? { agentId: e.agentId } : {}, host: { requested: t.value, requestedSource: t.source }, mode: { requested: n.mode, requestedSource: n.modeSource, effective: c, note: c === n.mode ? "requested mode applies" : "host policy changes effective mode" }, security: { requested: n.security, requestedSource: n.securitySource, host: r.agent.security, hostSource: formatHostFieldSource("security", r.agentSources.security), effective: a, note: a === n.security ? "requested security applies" : "stricter host security wins" }, ask: { requested: n.ask, requestedSource: n.askSource, host: r.agent.ask, hostSource: formatHostFieldSource("ask", r.agentSources.ask), effective: o, note: o === n.ask ? "requested ask applies" : "more aggressive ask wins" }, askFallback: { effective: s, source: formatHostFieldSource("askFallback", r.agentSources.askFallback) }, allowedDecisions: resolveExecApprovalAllowedDecisions({ ask: o }) }; } //#endregion export { collectExecPolicyScopeSnapshots as n, resolveExecPolicyScopeSnapshot as r, SESSION_EXEC_OVERRIDES_NOTE as t };