UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

139 lines (138 loc) • 6.01 kB
import { r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs"; import { n as sanitizeForLog } from "./ansi-CZa2t0Hf.mjs"; import { r as listAgentEntriesWithSource } from "./agent-roster-t1ooUdXp.mjs"; import "./agent-scope-config-DmXgFGKP.mjs"; import { c as resolveCommandResolutionFromArgv } from "./exec-command-resolution-DaBYjPqy.mjs"; import { d as normalizeSafeBinName, n as isTrustedSafeBinPath, t as getTrustedSafeBinDirs, u as listRiskyConfiguredSafeBins } from "./exec-safe-bin-trust-DOHJJ8Cr.mjs"; import { i as resolveMergedSafeBinProfileFixtures, n as listInterpreterLikeSafeBins } from "./exec-safe-bin-runtime-policy-DUQ-JlOU.mjs"; import { n as normalizeConfiguredTrustedSafeBinDirs, t as normalizeConfiguredSafeBins } from "./exec-safe-bin-config-EFTvuM64.mjs"; //#region src/commands/doctor/shared/exec-safe-bins.ts function collectExecSafeBinScopes(e) { const t = []; const n = asNullableRecord(e.tools?.exec); const r = normalizeConfiguredTrustedSafeBinDirs(n?.safeBinTrustedDirs); const i = [{ exec: n, scopePath: "tools.exec", local: void 0 }, ...listAgentEntriesWithSource(e).map(({ entry: e, source: t }) => { const n = asNullableRecord(e.tools?.exec); return { exec: n, local: n, scopePath: t.kind === "entries" ? `agents.entries.${t.key}.tools.exec` : `agents.list.${t.index}.tools.exec` }; })]; for (const { exec: e, scopePath: a, local: o } of i) { if (!e) continue; const i = normalizeConfiguredSafeBins(e.safeBins); if (i.length === 0) continue; t.push({ scopePath: a, safeBins: i, exec: e, mergedProfiles: resolveMergedSafeBinProfileFixtures({ global: n, local: o }) ?? {}, trustedSafeBinDirs: getTrustedSafeBinDirs({ extraDirs: [...r, ...normalizeConfiguredTrustedSafeBinDirs(o?.safeBinTrustedDirs)] }) }); } return t; } function inspectSafeBinProfiles(e) { const t = new Set(listInterpreterLikeSafeBins(e.safeBins)); const n = listRiskyConfiguredSafeBins(e.safeBins); const r = new Set(n.map((e) => e.bin)); return { interpreterBins: t, riskyHits: n, missingBins: e.safeBins.filter((t) => !e.mergedProfiles[t] && !r.has(normalizeSafeBinName(t))) }; } function scanExecSafeBinCoverage(e) { const t = []; for (const n of collectExecSafeBinScopes(e)) { const { interpreterBins: e, riskyHits: r, missingBins: i } = inspectSafeBinProfiles(n); for (const r of i) t.push({ scopePath: n.scopePath, bin: r, kind: "missingProfile", isInterpreter: e.has(r) }); for (const e of r) t.push({ scopePath: n.scopePath, bin: e.bin, kind: "riskySemantics", warning: e.warning }); } return t; } function scanExecSafeBinTrustedDirHints(e) { const t = []; for (const n of collectExecSafeBinScopes(e)) for (const e of n.safeBins) { const r = resolveCommandResolutionFromArgv([e]); if (!r?.execution.resolvedPath) continue; if (isTrustedSafeBinPath({ resolvedPath: r.execution.resolvedPath, trustedDirs: n.trustedSafeBinDirs })) continue; t.push({ scopePath: n.scopePath, bin: e, resolvedPath: r.execution.resolvedPath }); } return t; } function collectLimitedWarnings(e, t, n) { const r = e.slice(0, 5).map(t); if (e.length > 5) r.push(`- ${e.length - 5} more ${n}`); return r; } function collectExecSafeBinCoverageWarnings(e) { const t = e.hits.filter((e) => e.kind === "missingProfile" && e.isInterpreter); const n = e.hits.filter((e) => e.kind === "missingProfile" && !e.isInterpreter); const r = e.hits.filter((e) => e.kind === "riskySemantics"); const i = [ ...collectLimitedWarnings(t, (e) => `- ${sanitizeForLog(e.scopePath)}.safeBins includes interpreter/runtime '${sanitizeForLog(e.bin)}' without profile.`, "interpreter/runtime safeBins entries are missing profiles."), ...collectLimitedWarnings(n, (e) => `- ${sanitizeForLog(e.scopePath)}.safeBins entry '${sanitizeForLog(e.bin)}' is missing safeBinProfiles.${sanitizeForLog(e.bin)}.`, "custom safeBins entries are missing profiles."), ...collectLimitedWarnings(r, (e) => `- ${sanitizeForLog(e.scopePath)}.safeBins includes '${sanitizeForLog(e.bin)}': ${sanitizeForLog(e.warning ?? "prefer explicit allowlist entries or approval-gated runs.")}`, "safeBins entries should not use the low-risk safeBins fast path.") ]; if (n.length > 0) i.push(`- Run "${e.doctorFixCommand}" to scaffold missing custom safeBinProfiles entries.`); return i; } function collectExecSafeBinTrustedDirHintWarnings(e) { if (e.length === 0) return []; const t = collectLimitedWarnings(e, (e) => `- ${sanitizeForLog(e.scopePath)}.safeBins entry '${sanitizeForLog(e.bin)}' resolves to '${sanitizeForLog(e.resolvedPath)}' outside trusted safe-bin dirs.`, "safeBins entries resolve outside trusted safe-bin dirs."); t.push("- If intentional, add the binary directory to tools.exec.safeBinTrustedDirs (global or agent scope)."); return t; } function maybeRepairExecSafeBinProfiles(e) { const t = structuredClone(e); const n = []; const r = []; for (const e of collectExecSafeBinScopes(t)) { const { interpreterBins: t, riskyHits: i, missingBins: a } = inspectSafeBinProfiles(e); for (const t of i) r.push(`- ${e.scopePath}.safeBins includes '${t.bin}': ${t.warning}`); if (a.length === 0) continue; const o = asNullableRecord(e.exec.safeBinProfiles) ?? (e.exec.safeBinProfiles = {}); for (const i of a) { if (t.has(i)) { r.push(`- ${e.scopePath}.safeBins includes interpreter/runtime '${i}' without profile; remove it from safeBins or use explicit allowlist entries.`); continue; } if (o[i] !== void 0) continue; o[i] = {}; n.push(`- ${e.scopePath}.safeBinProfiles.${i}: added scaffold profile {} (review and tighten flags/positionals).`); } } return { config: n.length > 0 || r.length > 0 ? t : e, changes: n, warnings: r }; } //#endregion export { scanExecSafeBinTrustedDirHints as a, scanExecSafeBinCoverage as i, collectExecSafeBinTrustedDirHintWarnings as n, maybeRepairExecSafeBinProfiles as r, collectExecSafeBinCoverageWarnings as t };