UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 9.35 kB
import{a as e}from"./openclaw-state-read-map-size-DJbMcZYM.mjs";import{l as t,v as n}from"./openclaw-state-read-home-dir-BQZX1pD2.mjs";import"node:fs";import r from"node:path";import"node:child_process";import{AsyncLocalStorage as i}from"node:async_hooks";function normalizeExecutableToken(e){let n=r.win32.basename(e),i=r.posix.basename(e),a=n.length<i.length?n:i;return t(a).replace(/\.(?:exe|cmd|bat|com)$/,``)}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 n=t(e);return[`-${n}`,`--${n}`,`/${n}`]})}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`]);function countSeparateValueOptionChars(e,t){let n=0;for(let r=1;r<e.length;r+=1){let i=e[r];(i===`o`||i===`O`&&t!==`zsh`)&&(n+=1)}return n}function parseCombinedCommandFlag(e,t){if(e.length<2||e[0]!==`-`||e[1]===`-`)return null;let n=e.slice(1),r=n.indexOf(`c`);if(r===-1||n.includes(`-`))return null;let i=n.slice(r+1);return i&&!/^[A-Za-z]+$/.test(i)?{attachedCommand:i,separateValueCount:0}:{attachedCommand:null,separateValueCount:countSeparateValueOptionChars(e,t)}}function combinedSeparateValueOptionCount(e,t){return e.length<2||e[0]!==`-`&&e[0]!==`+`||e[1]===`-`||e.slice(1).includes(`-`)?0:countSeparateValueOptionChars(e,t)}function advancePosixInlineOptionScan(e,t){let n=combinedSeparateValueOptionCount(e,t);return n>0?1+n:p.has(e)?2:1}function isPowerShellOptionToken(e){return e.startsWith(`-`)||/^\/[A-Za-z][A-Za-z0-9]*$/.test(e)}function resolveInlineCommandMatch(e,n,r={}){let i=normalizeExecutableToken(e[0]??``);for(let a=1;a<e.length;){let o=e[a]?.trim();if(!o){a+=1;continue}let s=t(o);if(s===`--`)break;let c=r.allowCombinedC?o:s,l=n.has(c),u=!l&&r.allowCombinedC?parseCombinedCommandFlag(o,i):null;if(l||u){if(u&&u.attachedCommand!==null)return{command:u.attachedCommand.trim()||null,valueTokenIndex:a};let t=a+1+(u?.separateValueCount??0),n=!u&&t>=e.length?null:t;return{command:(l&&r.restValueFlags?.has(c)?e.slice(a+1).map(e=>e.trim()).join(` `).trim():e[t]?.trim())||null,valueTokenIndex:n}}if(r.valueOptions?.has(s)){a+=2;continue}let d=r.isOptionToken?.(o)??(o.startsWith(`-`)||o.startsWith(`+`));if(r.stopAtFirstNonOption&&!d||r.allowCombinedC&&!o.startsWith(`-`)&&!o.startsWith(`+`))break;a+=r.allowCombinedC?advancePosixInlineOptionScan(o,i):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(t(e))}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]==='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" "$@"')&&t[2]?t[2]:void 0}const m=n(Symbol.for(`openclaw.childProcessSpawnCounts`),()=>({counts:/* @__PURE__ */ new Map,sampledAt:performance.now()})),h=/^(node|bun|git|ps|pgrep|lsof|sh|bash|zsh|cmd|powershell|pwsh|npm|pnpm|python|python3|uv|ssh|openclaw)$/,g=/* @__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`]),_=n(Symbol.for(`openclaw.gitSpawnOperation`),()=>new i),v=n(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"&&_.getStore()!==void 0?t():_.run(g.has(e)?e:`unknown`,t)}function prepareChildProcessSpawnRecorder(t,n=[],i){if(!e())return;let a=resolveOomScoreWrappedCommand(t,n),o=a?n.slice(3):n,s=r.win32.basename(a??t).toLowerCase().replace(/\.(exe|cmd)$/,``),c=h.test(s)?s:`other`,l=c===`git`?_.getStore()??v.getStore()??unscopedGitOperation(o):i??v.getStore()??unscopedProcessOperation(c,s,o),u=`${c}:${l}`;return()=>{if(e()){let e=m.counts.get(u);m.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};