UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

45 lines (44 loc) • 2.27 kB
import { i as resolveEnvironmentValue } from "./process-env-DVJdcOcM.mjs"; import { c as resolveCommandResolutionFromArgv } from "./exec-command-resolution-DaBYjPqy.mjs"; import { r as CronStreamPolicyDeniedError } from "./stream-exec-authority-CRx6XpZo.mjs"; import { c as prepareSystemRunMutableFileBinding, d as revalidateSystemRunMutableFileBindingSync } from "./system-run-approval-binding-B3btPgad.mjs"; import { n as captureApprovedCwdSnapshotSync, r as revalidateApprovedCwdSnapshot, t as APPROVAL_CWD_DRIFT_DENIED_MESSAGE } from "./system-run-cwd-binding-RQPTyu1g.mjs"; import path from "node:path"; //#region src/gateway/cron-stream-execution-binding.ts /** Pins the proposal through approval and save; the committed watcher keeps its path-based lifecycle. */ async function prepareCronStreamExecutionBinding(e) { const t = [...e.argv]; const n = path.resolve(e.cwd ?? process.cwd()); const r = captureApprovedCwdSnapshotSync(n); if (!r.ok) throw new Error(r.message); const i = r.snapshot.cwd; const a = { ...process.env }; const o = resolveCommandResolutionFromArgv(t, i, a, process.platform, { useCache: false }); if (!o?.execution.resolvedPath && !o?.execution.resolvedRealPath) throw new Error("SYSTEM_RUN_DENIED: approval requires a resolved executable"); const s = await prepareSystemRunMutableFileBinding({ command: { kind: "segments", segments: [{ raw: t.join(" "), argv: t, sourceArgv: t, resolution: o }], shellCommand: false }, cwd: i, env: a }); if (!s.ok) throw new Error(s.message); return { assertCurrent() { if (path.resolve(e.cwd ?? process.cwd()) !== n || !revalidateApprovedCwdSnapshot(r.snapshot)) throw new CronStreamPolicyDeniedError(APPROVAL_CWD_DRIFT_DENIED_MESSAGE); if (resolveEnvironmentValue(process.env, "PATH") !== resolveEnvironmentValue(a, "PATH") || resolveEnvironmentValue(process.env, "PATHEXT") !== resolveEnvironmentValue(a, "PATHEXT")) throw new CronStreamPolicyDeniedError("SYSTEM_RUN_DENIED: approval executable search environment changed"); const t = revalidateSystemRunMutableFileBindingSync({ binding: s.binding, cwd: i }); if (!t.ok) throw new CronStreamPolicyDeniedError(t.message); } }; } //#endregion export { prepareCronStreamExecutionBinding };