openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 10.3 kB
JavaScript
import{t as e}from"./plugin-preparation-rolldown-runtime-C5ba_Z9N.mjs";import{$ as t,U as n,i as r,t as i}from"./plugin-preparation-diagnostic-events-C0NITktC.mjs";import{AsyncLocalStorage as a}from"node:async_hooks";import"node:fs";import o from"node:path";import"node:child_process";function normalizeExecutableToken(e){let t=o.win32.basename(e),r=o.posix.basename(e),i=t.length<r.length?t:r;return n(i).replace(/\.(?:exe|cmd|bat|com)$/,``)}const s=/* @__PURE__ */ new Set([`-lc`,`-c`,`--command`,`--commands`,`--cmdline`]);[...s];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 c=[...expandPowerShellSwitchPrefixForms(`command`,`c`),...expandPowerShellSwitchPrefixForms(`commandwithargs`,`cwa`),...expandPowerShellSwitchForms([`cwa`])],l=expandPowerShellSwitchPrefixForms(`file`,`f`),u=new Set(l);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 d=/* @__PURE__ */ new Set([...expandPowerShellSwitchPrefixForms(`encodedcommand`,`e`),...expandPowerShellSwitchPrefixForms(`ec`,`e`)]),f=/* @__PURE__ */ new Set([...c,...l,...d]),p=new Set(c),m=/* @__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`])]),h=/* @__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:h.has(e)?2:1}function isPowerShellOptionToken(e){return e.startsWith(`-`)||/^\/[A-Za-z][A-Za-z0-9]*$/.test(e)}function resolveInlineCommandMatch(e,t,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=n(o);if(s===`--`)break;let c=r.allowCombinedC?o:s,l=t.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,f,{isOptionToken:isPowerShellOptionToken,restValueFlags:p,stopAtFirstNonOption:!0,valueOptions:m})}function isPowerShellInlineFileCommandFlag(e){return u.has(n(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}var g=/* @__PURE__ */ e({emitChildProcessSpawnSample:()=>emitChildProcessSpawnSample,prepareChildProcessSpawnRecorder:()=>prepareChildProcessSpawnRecorder,recordChildProcessSpawn:()=>recordChildProcessSpawn,withChildProcessOperation:()=>withChildProcessOperation,withGitProcessOperation:()=>withGitProcessOperation});const _=t(Symbol.for(`openclaw.childProcessSpawnCounts`),()=>({counts:/* @__PURE__ */ new Map,sampledAt:performance.now()})),v=/^(node|bun|git|ps|pgrep|lsof|sh|bash|zsh|cmd|powershell|pwsh|npm|pnpm|python|python3|uv|ssh|openclaw)$/,y=/* @__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`]),b=t(Symbol.for(`openclaw.gitSpawnOperation`),()=>new a),x=/* @__PURE__ */ new Set([`agent.exec`,`agent.cli`,`agent.file-read`,`shell.snapshot`,`service.relay`,`service.manager`,`plugin.capture-reclamation`,`worktree.filesystem`,`worktree.cleanup`,`worktree.maintenance`]),S=t(Symbol.for(`openclaw.childSpawnOperation`),()=>new a);function withChildProcessOperation(e,t,n=`override`){return n==="default"&&S.getStore()!==void 0?t():S.run(x.has(e)?e:`unknown`,t)}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],s,{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"&&b.getStore()!==void 0?t():b.run(y.has(e)?e:`unknown`,t)}function prepareChildProcessSpawnRecorder(e,t=[],n){if(!i())return;let r=resolveOomScoreWrappedCommand(e,t),a=r?t.slice(3):t,s=o.win32.basename(r??e).toLowerCase().replace(/\.(exe|cmd)$/,``),c=v.test(s)?s:`other`,l=c===`git`?b.getStore()??S.getStore()??unscopedGitOperation(a):n??S.getStore()??unscopedProcessOperation(c,s,a),u=`${c}:${l}`;return()=>{if(i()){let e=_.counts.get(u);_.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)}function emitChildProcessSpawnSample(){let e=performance.now();if(!i()){_.counts.clear(),_.sampledAt=e;return}let t=e-_.sampledAt;if(!(t<6e4)){for(let{family:e,operation:n,count:i}of _.counts.values())r({type:`diagnostic.child_process.spawn`,family:e,operation:n,count:i,intervalMs:t});_.counts.clear(),_.sampledAt=e}}export{g as n,recordChildProcessSpawn as t};