openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
139 lines (138 loc) • 5.55 kB
JavaScript
import { r as resolveAgentConfig, x as resolveSessionAgentId } from "./agent-scope-config-DmXgFGKP.mjs";
import "./agent-scope-BwB8YH6y.mjs";
import { l as resolveExecModeFromPolicy, o as normalizeExecTarget, u as resolveExecModePolicy } from "./exec-approvals-core-puBAw1bE.mjs";
import { n as maxAsk, r as minSecurity } from "./exec-approvals-policy-BGzNHuNm.mjs";
import { t as applyExecPolicyLayer } from "./exec-policy-B0KOmSWr.mjs";
import { o as resolveSessionPermissionExecPolicy } from "./session-permission-exec-mode-vqqWNPSg.mjs";
import { r as resolveSandboxRuntimeStatus, s as withSandboxRuntimeStatusInWorker } from "./runtime-status-C5ZOG7YR.mjs";
import { t as resolveExecApprovalsFromFileInternal } from "./exec-approvals-resolver-C6IwmycS.mjs";
import { a as loadExecApprovalsReadOnlyAsync, r as loadExecApprovals } from "./exec-approvals-store-BUZ9uOWF.mjs";
import "./exec-approvals-rOfoWejC.mjs";
import { i as resolveExecTarget, t as isRequestedExecTargetAllowed } from "./bash-tools.exec-target-DBNJnOXQ.mjs";
//#region src/agents/exec-defaults.ts
function resolveExecConfigState(e) {
const t = e.cfg ?? {};
const n = e.scope?.kind === "defaults" ? void 0 : e.agentId ?? resolveSessionAgentId({
sessionKey: e.sessionKey,
config: t
});
const r = t.tools?.exec;
const i = n ? resolveAgentConfig(t, n)?.tools?.exec : void 0;
return {
cfg: t,
host: e.execOverrides?.host ?? normalizeExecTarget(e.sessionEntry?.execHost) ?? i?.host ?? r?.host ?? "auto",
agentId: n,
agentExec: i,
globalExec: r
};
}
function resolveNodeExecEligibility(e, t) {
const n = t ?? resolveExecDefaults(e);
const r = e.cfg?.gateway?.nodes?.commands?.deny?.some((e) => e.trim() === "system.run");
return {
canExec: n.canRequestNode && n.security !== "deny" && !r,
...n.node ? { node: n.node } : {}
};
}
/** Resolve node availability without reading the approval store on the caller thread. */
async function resolveNodeExecEligibilityAsync(e) {
return resolveNodeExecEligibility(e, await resolveExecDefaultsAsync(e));
}
/** Resolve policy inputs first; only the host-floor branch requests approval state. */
function prepareExecDefaults(e, t) {
const { cfg: n, host: r, agentId: i, agentExec: a, globalExec: o } = resolveExecConfigState(e);
const s = e.sessionKey ? t ?? resolveSandboxRuntimeStatus({
cfg: n,
agentId: i,
sessionKey: e.sessionKey,
preparedSessionEntry: e.sessionEntry
}) : void 0;
const c = e.sessionEntry?.sandbox === "required" || s?.sandboxRequired === true;
const l = e.sandboxAvailable ?? s?.sandboxed ?? false;
const u = resolveExecTarget({
configuredTarget: r,
elevatedRequested: e.elevatedRequested === true && !c,
sandboxAvailable: l,
sandboxRequired: c
});
const d = u.effectiveHost === "sandbox" ? "deny" : "full";
const f = e.sessionEntry?.permissionMode ? resolveSessionPermissionExecPolicy({ mode: e.sessionEntry.permissionMode }, e.execOverrides) : void 0;
const p = e.sessionEntry?.permissionMode === "full" && f?.security === "full";
const resolve = (t) => {
let n = f ?? {
security: t?.security ?? d,
ask: t?.ask ?? "off"
};
if (!f) for (const t of [
o,
a,
e.execOverrides
]) n = applyExecPolicyLayer(n, t);
const r = resolveExecModePolicy(n);
const i = t?.security !== void 0 ? minSecurity(r.security, t.security) : r.security;
const s = t?.ask !== void 0 ? maxAsk(r.ask, t.ask) : r.ask;
const c = i === r.security && s === r.ask ? r.mode : resolveExecModeFromPolicy({
security: i,
ask: s
});
return {
host: u.configuredTarget,
effectiveHost: u.effectiveHost,
mode: c,
security: i,
ask: s,
node: e.execOverrides?.node ?? e.sessionEntry?.execNode ?? a?.node ?? o?.node,
canRequestNode: isRequestedExecTargetAllowed({
configuredTarget: u.configuredTarget,
requestedTarget: "node",
sandboxAvailable: l
})
};
};
if (u.effectiveHost === "sandbox" || p) return {
kind: "resolved",
defaults: resolve(void 0)
};
return {
kind: "needs-approvals",
suppliedApprovals: e.execApprovals,
resolve: (e) => resolve(resolveExecApprovalsFromFileInternal({
file: e,
agentId: i,
overrides: {
security: d,
ask: "off"
}
}).agent)
};
}
function resolveExecDefaults(e, t) {
const n = prepareExecDefaults(e, t);
return n.kind === "resolved" ? n.defaults : n.resolve(n.suppliedApprovals ?? loadExecApprovals());
}
/** Prepare session classification and host approval floors through their existing workers. */
async function resolveExecDefaultsAsync(e) {
const { agentId: t } = resolveExecConfigState(e);
const resolve = (t) => resolvePreparedExecDefaultsAsync(prepareExecDefaults(e, t), loadExecApprovalsReadOnlyAsync);
if (e.sessionEntry !== void 0) return resolve(resolveSandboxRuntimeStatus({
cfg: e.cfg,
agentId: t,
sessionKey: e.sessionKey,
preparedSessionEntry: e.sessionEntry
}));
return withSandboxRuntimeStatusInWorker({
cfg: e.cfg,
agentId: t,
sessionKey: e.sessionKey
}, {
env: process.env,
cwd: process.cwd(),
assertCurrent: () => {}
}, resolve);
}
/** Called inside retained session-reader scopes, before synchronous tool construction. */
async function resolvePreparedExecDefaultsAsync(e, t) {
return e.kind === "resolved" ? e.defaults : e.resolve(e.suppliedApprovals ?? await t());
}
//#endregion
export { resolveNodeExecEligibility as a, resolveExecDefaultsAsync as i, resolveExecConfigState as n, resolveNodeExecEligibilityAsync as o, resolveExecDefaults as r, resolvePreparedExecDefaultsAsync as s, prepareExecDefaults as t };