UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.49 kB
import{t as e}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import{a as t}from"./openclaw-state-read-pid-alive-C5QrpWWk.mjs";import{n,t as r}from"./openclaw-state-read-runtime-binary-BjmkF9EB.mjs";import i from"node:path";import{spawnSync as a}from"node:child_process";import{ProcSafeError as o}from"@openclaw/proc-safe/errors";import{readProcessCommand as s}from"@openclaw/proc-safe/inspect";let c=!1;const l=/\[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=a(`/usr/sbin/lsof`,[`-a`,`-p`,String(e),`-d`,`txt`,`-Fn`],t),r=n.status===0?/^n(\/.+)$/mu.exec(n.stdout)?.[1]:void 0,o=r&&a(`/bin/ps`,[`-o`,`ucomm=`,`-p`,String(e)],t);return o&&o.status===0&&o.stdout.trim()===i.basename(r).slice(0,16)?r:void 0}function isRedactedSystemImage(e){if(!e.startsWith(`/System/`))return!1;let t=a(`/usr/bin/codesign`,[`-d`,`--entitlements`,`-`,e],{encoding:`utf8`,timeout:2e3});return t.status===0&&l.test(t.stdout)}function readCommandWithServiceMarker(e){try{return s(e,{environmentKeys:[`OPENCLAW_SERVICE_MARKER`]})}catch(t){if(!(t instanceof o)||t.code!==`incomplete`)throw t;let a=s(e);return a&&[a.executable,a.argv[0]??``].some(e=>n(e)||r(e)||i.basename(e)===`tsx`)?{...a,serviceMarkerUnavailable:!0}:a}}function readDarwinProcessCommand(n,r,i={}){try{let e=i.serviceMarker===!1?s(n):readCommandWithServiceMarker(n);if(!e)return;let t=e.environment.OPENCLAW_SERVICE_MARKER;return{argv:[...e.argv],executable:e.executable,...t===void 0?{}:{serviceMarker:t},...`serviceMarkerUnavailable`in e?{serviceMarkerUnavailable:!0}:{}}}catch(i){if(!(i instanceof o))throw i;if(i.code===`layout-mismatch`||i.code===`incomplete`){let e=readDarwinImagePath(n);if(e&&isRedactedSystemImage(e))return{argvUnavailable:!0,executable:e,...r?{owner:r}:{}};throw i}if(i.code===`unsupported-platform`&&process.platform===`darwin`)throw Error(`Cannot inspect Darwin process arguments under Rosetta; run OpenClaw with native arm64 Node.js.`,{cause:i});if(i.code!==`access-denied`&&i.code!==`operation-failed`)throw i;if(t(n))return;if(r===`different`)return c||(c=!0,e(`process/census`).debug(`Unreadable Darwin arguments for another UID do not establish capture custody.`,{pid:n,code:i.code})),{argvUnavailable:!0,owner:r};throw Error(`Could not classify PID ${n}: cannot inspect Darwin arguments (${i.code}).`,{cause:i})}}export{readDarwinProcessCommand as t};