openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 9.11 kB
JavaScript
import{Cn as e,R as t,pn as n}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import"node:fs";import r from"node:path";import"node:child_process";import{AsyncLocalStorage as i}from"node:async_hooks";const a=/* @__PURE__ */ new Set([`-lc`,`-c`,`--command`,`--commands`,`--cmdline`]);[...a];function expandPowerShellSwitchPrefixForms(e,t){let n=[];for(let r=t.length;r<=e.length;r+=1){let t=e.slice(0,r);n.push(`-${t}`,`--${t}`,`/${t}`)}return n}function expandPowerShellSwitchForms(e){return e.flatMap(e=>{let t=n(e);return[`-${t}`,`--${t}`,`/${t}`]})}const o=[...expandPowerShellSwitchPrefixForms(`command`,`c`),...expandPowerShellSwitchPrefixForms(`commandwithargs`,`cwa`),...expandPowerShellSwitchForms([`cwa`])],s=expandPowerShellSwitchPrefixForms(`file`,`f`),c=new Set(s);new Set(expandPowerShellSwitchPrefixForms(`noprofile`,`nop`)),[...expandPowerShellSwitchPrefixForms(`configurationfile`,`conf`),...expandPowerShellSwitchPrefixForms(`configurationname`,`config`),...expandPowerShellSwitchPrefixForms(`custompipename`,`cus`),...expandPowerShellSwitchPrefixForms(`encodedarguments`,`encodeda`),...expandPowerShellSwitchForms([`ea`]),...expandPowerShellSwitchPrefixForms(`interactive`,`i`),...expandPowerShellSwitchPrefixForms(`login`,`l`),...expandPowerShellSwitchPrefixForms(`namedpipeservermode`,`nam`),...expandPowerShellSwitchPrefixForms(`noexit`,`noe`),...expandPowerShellSwitchPrefixForms(`psconsolefile`,`pscf`),...expandPowerShellSwitchForms([`pscf`]),...expandPowerShellSwitchPrefixForms(`servermode`,`s`),...expandPowerShellSwitchPrefixForms(`settingsfile`,`settings`),...expandPowerShellSwitchPrefixForms(`socketservermode`,`so`),...expandPowerShellSwitchPrefixForms(`sshservermode`,`ssh`),...expandPowerShellSwitchPrefixForms(`v2socketservermode`,`v2so`)];const l=/* @__PURE__ */ new Set([...expandPowerShellSwitchPrefixForms(`encodedcommand`,`e`),...expandPowerShellSwitchPrefixForms(`ec`,`e`)]),u=/* @__PURE__ */ new Set([...o,...s,...l]),d=new Set(o),f=/* @__PURE__ */ new Set([...expandPowerShellSwitchPrefixForms(`configurationfile`,`conf`),...expandPowerShellSwitchPrefixForms(`configurationname`,`config`),...expandPowerShellSwitchPrefixForms(`custompipename`,`cus`),...expandPowerShellSwitchPrefixForms(`encodedarguments`,`encodeda`),...expandPowerShellSwitchPrefixForms(`executionpolicy`,`ex`),...expandPowerShellSwitchPrefixForms(`inputformat`,`inp`),...expandPowerShellSwitchPrefixForms(`outputformat`,`o`),...expandPowerShellSwitchPrefixForms(`psconsolefile`,`pscf`),...expandPowerShellSwitchPrefixForms(`settingsfile`,`settings`),...expandPowerShellSwitchPrefixForms(`token`,`to`),...expandPowerShellSwitchPrefixForms(`utctimestamp`,`utc`),...expandPowerShellSwitchPrefixForms(`version`,`v`),...expandPowerShellSwitchPrefixForms(`windowstyle`,`w`),...expandPowerShellSwitchPrefixForms(`workingdirectory`,`w`),...expandPowerShellSwitchForms([`ea`,`ep`,`if`,`of`,`pscf`,`wd`])]),p=/* @__PURE__ */ new Set([`--init-file`,`--rcfile`,`-O`,`-o`,`+O`,`+o`]);function countSeparateValueOptionChars(e){let t=0;for(let n=1;n<e.length;n+=1){let r=e[n];(r===`o`||r===`O`)&&(t+=1)}return t}function parseCombinedCommandFlag(e){if(e.length<2||e[0]!==`-`||e[1]===`-`)return null;let t=e.slice(1),n=t.indexOf(`c`);if(n===-1||t.includes(`-`))return null;let r=t.slice(n+1);return r&&!/^[A-Za-z]+$/.test(r)?{attachedCommand:r,separateValueCount:0}:{attachedCommand:null,separateValueCount:countSeparateValueOptionChars(e)}}function combinedSeparateValueOptionCount(e){return e.length<2||e[0]!==`-`&&e[0]!==`+`||e[1]===`-`||e.slice(1).includes(`-`)?0:countSeparateValueOptionChars(e)}function advancePosixInlineOptionScan(e){let t=combinedSeparateValueOptionCount(e);return t>0?1+t:p.has(e)?2:1}function isPowerShellOptionToken(e){return e.startsWith(`-`)||/^\/[A-Za-z][A-Za-z0-9]*$/.test(e)}function resolveInlineCommandMatch(e,t,r={}){for(let i=1;i<e.length;){let a=e[i]?.trim();if(!a){i+=1;continue}let o=n(a);if(o===`--`)break;let s=r.allowCombinedC?a:o,c=t.has(s),l=!c&&r.allowCombinedC?parseCombinedCommandFlag(a):null;if(c||l){if(l&&l.attachedCommand!==null)return{command:l.attachedCommand.trim()||null,valueTokenIndex:i};let t=i+1+(l?.separateValueCount??0),n=!l&&t>=e.length?null:t;return{command:(c&&r.restValueFlags?.has(s)?e.slice(i+1).map(e=>e.trim()).join(` `).trim():e[t]?.trim())||null,valueTokenIndex:n}}if(r.valueOptions?.has(o)){i+=2;continue}let u=r.isOptionToken?.(a)??(a.startsWith(`-`)||a.startsWith(`+`));if(r.stopAtFirstNonOption&&!u||r.allowCombinedC&&!a.startsWith(`-`)&&!a.startsWith(`+`))break;i+=r.allowCombinedC?advancePosixInlineOptionScan(a):1}return{command:null,valueTokenIndex:null}}function resolvePowerShellInlineCommandMatch(e){return resolveInlineCommandMatch(e,u,{isOptionToken:isPowerShellOptionToken,restValueFlags:d,stopAtFirstNonOption:!0,valueOptions:f})}function isPowerShellInlineFileCommandFlag(e){return c.has(n(e))}const m=['echo 1000 > /proc/self/oom_score_adj 2>/dev/null; if [ "${OC_INTERNAL_OOM_EXEC_BASH_ENV+x}" = x ]; then BASH_ENV="$OC_INTERNAL_OOM_EXEC_BASH_ENV"; export BASH_ENV; fi; unset OC_INTERNAL_OOM_EXEC_BASH_ENV','if [ "${OC_INTERNAL_OOM_EXEC_ENV+x}" = x ]; then ENV="$OC_INTERNAL_OOM_EXEC_ENV"; export ENV; fi; unset OC_INTERNAL_OOM_EXEC_ENV','if [ "${OC_INTERNAL_OOM_EXEC_CDPATH+x}" = x ]; then CDPATH="$OC_INTERNAL_OOM_EXEC_CDPATH"; export CDPATH; fi; unset OC_INTERNAL_OOM_EXEC_CDPATH','if [ "${OC_INTERNAL_OOM_EXEC_PS4+x}" = x ]; then PS4="$OC_INTERNAL_OOM_EXEC_PS4"; export PS4; fi; unset OC_INTERNAL_OOM_EXEC_PS4; exec "$0" "$@"'].join(`; `);function resolveOomScoreWrappedCommand(e,t){return e===`/bin/sh`&&t[0]===`-c`&&(t[1]===`echo 1000 > /proc/self/oom_score_adj 2>/dev/null; exec "$0" "$@"`||t[1]===m)&&t[2]?t[2]:void 0}const h=e(Symbol.for(`openclaw.childProcessSpawnCounts`),()=>({counts:/* @__PURE__ */ new Map,sampledAt:performance.now()})),g=/^(node|bun|git|ps|pgrep|lsof|sh|bash|zsh|cmd|powershell|pwsh|npm|pnpm|python|python3|uv|ssh|openclaw)$/,_=/* @__PURE__ */ new Set([`repository.identities`,`repository.branches`,`checkout.revision`,`checkout.context`,`checkout.diff`,`checkout.baseline`,`pull-request.branch-facts`,`worktree.snapshot`,`worktree.cleanup`,`worktree.provision`,`worktree.inspect`,`worktree.recovery`,`workspace.inventory`,`workspace.manifest`,`workspace.result-cleanup`,`project.clone`,`session.materialize`,`publication`,`github.identity`,`project.checkout`,`update.inspect`,`worktree.config`,`worktree.maintenance`,`workspace.sync`,`workspace.result`]),v=e(Symbol.for(`openclaw.gitSpawnOperation`),()=>new i),y=e(Symbol.for(`openclaw.childSpawnOperation`),()=>new i);function unscopedProcessOperation(e,t,n){if(n[0]===`--version`||n[0]===`-v`&&(e===`node`||e===`bun`||t===`gh`))return`unscoped.version`;if(e===`powershell`||e===`pwsh`){let e=[t,...n],{command:r,valueTokenIndex:i}=resolvePowerShellInlineCommandMatch(e);return r!==null&&i!==null&&!isPowerShellInlineFileCommandFlag(e[i-1]??``)?`unscoped.shell-command`:`unscoped.shell`}return/^(sh|bash|zsh)$/.test(e)?resolveInlineCommandMatch([t,...n],a,{allowCombinedC:!0}).command===null?`unscoped.shell`:`unscoped.shell-command`:e===`cmd`?n.some(e=>/^-[a-z]*c$/.test(e)||/^\/(?:c|k)$/i.test(e))?`unscoped.shell-command`:`unscoped.shell`:e===`node`||e===`bun`?`unscoped.runtime`:e===`other`&&/^(gh|docker|podman|which|uname|sw_vers|sysctl|curl|tar)$/.test(t)?`unscoped.${t}`:`unscoped.command`}function unscopedGitOperation(e){let t=0;for(;t<e.length;){let n=e[t];if([`-C`,`-c`,`--git-dir`,`--work-tree`,`--namespace`,`--config-env`].includes(n))t+=2;else if(/^--(?:git-dir|work-tree|namespace|config-env|attr-source)=/u.test(n))t++;else if([`--no-pager`,`--no-optional-locks`,`--no-lazy-fetch`,`--literal-pathspecs`,`--bare`].includes(n))t++;else break}let n=e[t]??``;return/^(config|rev-parse|status|diff|ls-files|rev-list|merge-base|cat-file|symbolic-ref|for-each-ref|show-ref|remote|log|show|hash-object|update-ref|worktree|branch|fetch|clone|init|checkout|read-tree|write-tree|commit-tree|pack-objects|index-pack|maintenance|multi-pack-index|gc|fast-import|add|commit|push|reset|clean|merge|tag|describe|switch|ls-tree|update-index|check-ref-format|diff-tree|diff-index|diff-files|sparse-checkout|checkout-index|check-attr|mktree|var|apply|fsck|ls-remote|rebase|reflog)$/u.test(n)?`unscoped.${n}`:n===`--version`||n===`version`?`unscoped.version`:`unscoped.other`}function withGitProcessOperation(e,t,n=`override`){return e===void 0||n==="default"&&v.getStore()!==void 0?t():v.run(_.has(e)?e:`unknown`,t)}function prepareChildProcessSpawnRecorder(e,n=[],i){if(!t())return;let a=resolveOomScoreWrappedCommand(e,n),o=a?n.slice(3):n,s=r.win32.basename(a??e).toLowerCase().replace(/\.(exe|cmd)$/,``),c=g.test(s)?s:`other`,l=c===`git`?v.getStore()??y.getStore()??unscopedGitOperation(o):i??y.getStore()??unscopedProcessOperation(c,s,o),u=`${c}:${l}`;return()=>{if(t()){let e=h.counts.get(u);h.counts.set(u,{family:c,operation:l,count:(e?.count??0)+1})}}}function recordChildProcessSpawn(e,t,n,r=[]){let i=prepareChildProcessSpawnRecorder(e,r,n);i&&t.once(`spawn`,i)}export{withGitProcessOperation as n,recordChildProcessSpawn as t};