UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.09 kB
import{i as resolveEnvironmentValue}from"./process-env-BMQKxoSL.mjs";import{l as resolveCommandResolutionFromArgv}from"./exec-command-resolution-BI7wY-6_.mjs";import{r as CronStreamPolicyDeniedError}from"./stream-exec-authority-UA5ezVpo.mjs";import{c as prepareSystemRunMutableFileBinding,u as revalidateSystemRunMutableFileBinding}from"./system-run-approval-binding-BW8Wp0Lw.mjs";import{n as captureApprovedCwdSnapshot,r as revalidateApprovedCwdSnapshot,t as APPROVAL_CWD_DRIFT_DENIED_MESSAGE}from"./system-run-cwd-binding-CbFlZEGD.mjs";import path from"node:path"; //!src/gateway/cron-stream-execution-binding.ts async function prepareCronStreamExecutionBinding(e){const t=[...e.argv];const n=path.resolve(e.cwd??process.cwd());const r=await captureApprovedCwdSnapshot(n);if(!r.ok)throw new Error(r.message);const i=r.snapshot.cwd;const a={...process.env};const o=await 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);const assertCurrent=()=>{if(path.resolve(e.cwd??process.cwd())!==n)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`)};return{assertCurrent,async revalidate(){assertCurrent();if(!await revalidateApprovedCwdSnapshot(r.snapshot))throw new CronStreamPolicyDeniedError(APPROVAL_CWD_DRIFT_DENIED_MESSAGE);const e=await revalidateSystemRunMutableFileBinding({binding:s.binding,cwd:i});assertCurrent();if(!e.ok)throw new CronStreamPolicyDeniedError(e.message)}}}export{prepareCronStreamExecutionBinding};