openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
2 lines • 4.92 kB
JavaScript
import{W as e,t}from"./sqlite-readonly-subsystem-Bfq7Sewc.mjs";import{t as n}from"./sqlite-readonly-path-existence-lfal2A68.mjs";import{n as r,t as i}from"./sqlite-readonly-runtime-binary-CQkI442k.mjs";import{bt as a,ht as o}from"./sqlite-readonly-location.worker.js";import{t as s}from"./sqlite-readonly-windows-appcontainer-spawn-DGtrwkIS.mjs";import c from"node:path";import l from"node:fs";import{execFileSync as u,spawnSync as d}from"node:child_process";import{ProcSafeError as f}from"@openclaw/proc-safe/errors";import{readProcessCommand as p}from"@openclaw/proc-safe/inspect";let m=!1;const h=/\[Key\] com\.apple\.private\.no-read-procargs\s*\[Value\]\s*\[Bool\] true|<key>com\.apple\.private\.no-read-procargs<\/key>\s*<true\/>/u;function readDarwinImagePath(e){let t={encoding:`utf8`,timeout:2e3},n=d(`/usr/sbin/lsof`,[`-a`,`-p`,String(e),`-d`,`txt`,`-Fn`],t),r=n.status===0?/^n(\/.+)$/mu.exec(n.stdout)?.[1]:void 0,i=r&&d(`/bin/ps`,[`-o`,`ucomm=`,`-p`,String(e)],t);return i&&i.status===0&&i.stdout.trim()===c.basename(r).slice(0,16)?r:void 0}function isRedactedSystemImage(e){if(!e.startsWith(`/System/`))return!1;let t=d(`/usr/bin/codesign`,[`-d`,`--entitlements`,`-`,e],{encoding:`utf8`,timeout:2e3});return t.status===0&&h.test(t.stdout)}function readCommandWithServiceMarker(e){try{return p(e,{environmentKeys:[`OPENCLAW_SERVICE_MARKER`]})}catch(t){if(!(t instanceof f)||t.code!==`incomplete`)throw t;let n=p(e);return n&&[n.executable,n.argv[0]??``].some(e=>r(e)||i(e)||c.basename(e)===`tsx`)?{...n,serviceMarkerUnavailable:!0}:n}}function readDarwinProcessCommand(e,n,r={}){try{let t=r.serviceMarker===!1?p(e):readCommandWithServiceMarker(e);if(!t)return;let n=t.environment.OPENCLAW_SERVICE_MARKER;return{argv:[...t.argv],executable:t.executable,...n===void 0?{}:{serviceMarker:n},...`serviceMarkerUnavailable`in t?{serviceMarkerUnavailable:!0}:{}}}catch(r){if(!(r instanceof f))throw r;if(r.code===`layout-mismatch`||r.code===`incomplete`){let t=readDarwinImagePath(e);if(t&&isRedactedSystemImage(t))return{argvUnavailable:!0,executable:t,...n?{owner:n}:{}};throw r}if(r.code===`unsupported-platform`&&process.platform===`darwin`)throw Error(`Cannot inspect Darwin process arguments under Rosetta; run OpenClaw with native arm64 Node.js.`,{cause:r});if(r.code!==`access-denied`&&r.code!==`operation-failed`)throw r;if(o(e))return;if(n===`different`)return m||(m=!0,t(`process/census`).debug(`Unreadable Darwin arguments for another UID do not establish capture custody.`,{pid:e,code:r.code})),{argvUnavailable:!0,owner:n};throw Error(`Could not classify PID ${e}: cannot inspect Darwin arguments (${r.code}).`,{cause:r})}}const g=`C:\\Windows`,_=5e3;let v=null;function locateWindowsRegExe(){let e=c.win32.join(g,`System32`,`reg.exe`);return n(e,l.constants.R_OK)?e:null}function trimTrailingSeparators(e){let t=c.win32.parse(e),n=e;for(;n.length>t.root.length&&/[\\/]/.test(n.at(-1)??``);)n=n.slice(0,-1);return n}function normalizeWindowsInstallRoot(e){if(typeof e!=`string`)return null;let t=e.trim();if(!t||t.includes(`\0`)||t.includes(`\r`)||t.includes(`
`)||t.includes(`;`))return null;let n=trimTrailingSeparators(c.win32.normalize(t));if(!c.win32.isAbsolute(n)||n.startsWith(`\\\\`))return null;let r=c.win32.parse(n);return!/^[A-Za-z]:\\$/.test(r.root)||n.length<=r.root.length?null:n}function getEnvValueCaseInsensitive(e,t){let n=e[t];if(n!==void 0)return n;let r=t.toUpperCase(),i=Object.keys(e).find(e=>e.toUpperCase()===r);return i?e[i]:void 0}function queryWindowsRegistryValue(t,n,r){let i=locateWindowsRegExe();if(!i)return null;for(let o of[[`/reg:64`],[]]){let c=r===void 0?_:Math.min(_,Math.ceil(r-performance.now()));if(c<=0)return null;s();try{let r=u(i,[`query`,t,`/v`,n,...o],{env:a(),encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`],timeout:c,windowsHide:!0}),s=RegExp(`^\\s*${e(n)}\\s+REG_[A-Z0-9_]+\\s+(.+)$`,`im`),l=r.match(s)?.[1]?.trim();if(l)return l}catch{}}return null}function resolveSystemRootFromEnv(e){return normalizeWindowsInstallRoot(getEnvValueCaseInsensitive(e,`SystemRoot`))??normalizeWindowsInstallRoot(getEnvValueCaseInsensitive(e,`WINDIR`))??g}function getProcessRoots(e){if(!v){let t={};for(let e of[`SystemRoot`,`WINDIR`,`ProgramFiles`,`ProgramFiles(x86)`,`ProgramW6432`])t[e]=getEnvValueCaseInsensitive(process.env,e);let n={env:t,systemRoot:normalizeWindowsInstallRoot(queryWindowsRegistryValue(`HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion`,`SystemRoot`,e)??void 0)??resolveSystemRootFromEnv(t)};if(e!==void 0&&performance.now()>=e)return n;v=n}return v}function getWindowsSystemRoot(e,t){if(e!==process.env)return resolveSystemRootFromEnv(e);let n=getProcessRoots(t);return n.installRoots?.systemRoot??n.systemRoot}function getWindowsPowerShellExePath(e=process.env,t){return c.win32.join(getWindowsSystemRoot(e,t),`System32`,`WindowsPowerShell`,`v1.0`,`powershell.exe`)}export{readDarwinProcessCommand as n,getWindowsPowerShellExePath as t};