openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
9 lines • 4.52 kB
JavaScript
import{E as parseStrictNonNegativeInteger,o as asDateTimestampMs}from"./number-coercion-B3CfI447.mjs";import{r as asNullableRecord}from"./record-coerce-BTbqdJ3-.mjs";import{PATH_ALIAS_POLICIES}from"@openclaw/fs-safe/advanced";import{GUEST_FILESYSTEM_PYTHON}from"@openclaw/fs-safe/guest";
//!src/infra/directory-entries.ts
function parseDirectoryEntries(e){const t=JSON.parse(e);if(!Array.isArray(t))throw new Error(`Invalid sandbox directory listing.`);return t.map(e=>{const t=asNullableRecord(e);if(!t||typeof t.name!==`string`||typeof t.isDirectory!==`boolean`)throw new Error(`Invalid sandbox directory entry.`);return{name:t.name,isDirectory:t.isDirectory}})}
//!src/agents/sandbox/fs-bridge-mutation-helper.ts
const SANDBOX_PINNED_MUTATION_PYTHON_CANDIDATES=[`/usr/bin/python3`,`/usr/local/bin/python3`,`/opt/homebrew/bin/python3`,`/bin/python3`];const PINNED_MUTATION_ACTION_LABELS={write:`write files`,create:`create files`,mkdir:`create directories`,remove:`remove files`,"copy-destination":`copy files`};const SANDBOX_PINNED_MUTATION_PYTHON_SHELL_LITERAL=`'${GUEST_FILESYSTEM_PYTHON.replaceAll(`'`,`'\\''`)}'`;const SANDBOX_PINNED_READ_TOO_LARGE_EXIT_CODE=27;const sandboxPinnedReadPython=[`import errno, sys`,`try:`,` exec(${JSON.stringify(GUEST_FILESYSTEM_PYTHON)})`,`except OSError as error:`,` if sys.argv[1] == 'read' and len(sys.argv) > 5 and error.errno == errno.EFBIG:`,` sys.exit(${27})`,` raise`].join(`
`);const SANDBOX_PINNED_READ_PYTHON_SHELL_LITERAL=`'${sandboxPinnedReadPython.replaceAll(`'`,`'\\''`)}'`;function pinnedEntryArgs(e){return[e.mountRootPath,e.relativeParentPath,e.basename]}function buildPinnedMutationArgs(e){switch(e.kind){case`read`:return[e.kind,...pinnedEntryArgs(e.pinned),...e.maxBytes===void 0?[]:[String(e.maxBytes)]];case`write`:case`create`:return[e.kind,...pinnedEntryArgs(e.pinned),e.mkdir?`1`:`0`];case`mkdirp`:case`readdir`:return[e.kind,e.pinned.mountRootPath,e.pinned.relativePath];case`remove`:return[e.kind,...pinnedEntryArgs(e.pinned),e.recursive?`1`:`0`,e.force===false?`0`:`1`]}return[e.kind,...pinnedEntryArgs(e.source),...pinnedEntryArgs(e.destination),e.kind===`rename`||e.mkdir?`1`:`0`]}const PINNED_OPERATION_CHECK_OPTIONS={write:{action:`write files`,requireWritable:true},create:{action:`create files`,requireWritable:true},readdir:{action:`list directories`,allowedType:`directory`},mkdirp:{action:`create directories`,requireWritable:true,allowedType:`directory`},remove:{action:`remove files`,requireWritable:true,allowedType:`file-or-directory`},rename:{action:`rename files`,requireWritable:`subtree`,allowedType:`file-or-directory`},copy:{action:`copy files`,requireWritable:true}};function buildPinnedMutationPlan(e){const t={...PINNED_OPERATION_CHECK_OPTIONS[e.kind]};if(e.kind===`remove`&&e.recursive)t.requireWritable=`subtree`;const n=e.kind===`copy`||e.kind===`rename`?[{target:e.sourceTarget,options:e.kind===`copy`?{action:t.action,allowedType:`file`}:t},{target:e.destinationTarget,options:t}]:[{target:e.target,options:t}];if(e.kind===`remove`||e.kind===`rename`)n[0].options={...n[0].options,aliasPolicy:PATH_ALIAS_POLICIES.unlinkTarget};const r=buildPinnedMutationArgs(e);return{checks:n,script:[`set -eu`,`python_cmd=''`,...SANDBOX_PINNED_MUTATION_PYTHON_CANDIDATES.map(e=>`if [ -z "$python_cmd" ] && [ -x '${e}' ]; then python_cmd='${e}'; fi`),`if [ -z "$python_cmd" ]; then python_cmd=$(command -v python3 2>/dev/null || command -v python 2>/dev/null || true); fi`,`if [ -z "$python_cmd" ]; then`,` echo >&2 'sandbox pinned mutation helper requires python3 or python'`,` exit 127`,`fi`,`python_script=${SANDBOX_PINNED_MUTATION_PYTHON_SHELL_LITERAL}`,`exec "$python_cmd" -c "$python_script" "$@"`].join(`
`),args:r}}
//!src/agents/sandbox/fs-bridge-stat-parse.ts
function hasMultipleHardlinks(e){const t=parseStrictNonNegativeInteger(e);return t===void 0?/^\d+$/.test(e):t>1}function parseSandboxStatSize(e){const t=e??`0`;const n=parseStrictNonNegativeInteger(t);if(n!==void 0)return n;return/^\d+$/.test(t)?Number.MAX_SAFE_INTEGER:0}function parseSandboxStatMtimeMs(e){const t=e??`0`;if(/^\d+(?:\.\d+)?$/.test(t)){const e=Number(t)*1e3;return asDateTimestampMs(e)??0}return asDateTimestampMs(Date.parse(t))??0}export{SANDBOX_PINNED_MUTATION_PYTHON_SHELL_LITERAL as a,buildPinnedMutationPlan as c,PINNED_MUTATION_ACTION_LABELS as i,parseDirectoryEntries as l,parseSandboxStatMtimeMs as n,SANDBOX_PINNED_READ_PYTHON_SHELL_LITERAL as o,parseSandboxStatSize as r,buildPinnedMutationArgs as s,hasMultipleHardlinks as t};