agent-device 0.12.7 → 0.12.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/113.js +1 -1
- package/dist/src/1974.js +2 -0
- package/dist/src/3883.js +1 -0
- package/dist/src/3918.js +32 -0
- package/dist/src/4057.js +1 -0
- package/dist/src/4829.js +1 -0
- package/dist/src/4993.js +1 -0
- package/dist/src/7556.js +1 -0
- package/dist/src/7651.js +1 -0
- package/dist/src/7847.js +1 -0
- package/dist/src/8164.js +1 -0
- package/dist/src/8564.js +3 -0
- package/dist/src/9076.js +1 -0
- package/dist/src/9152.js +1 -0
- package/dist/src/9323.js +5 -0
- package/dist/src/9366.js +1 -0
- package/dist/src/9542.js +2 -0
- package/dist/src/9818.js +1 -0
- package/dist/src/989.js +1 -0
- package/dist/src/android-apps.js +1 -1
- package/dist/src/artifacts.js +1 -1
- package/dist/src/backend.js +1 -1
- package/dist/src/bin.d.ts +1 -0
- package/dist/src/bin.js +68 -70
- package/dist/src/commands/index.d.ts +4 -1
- package/dist/src/commands/index.js +1 -1
- package/dist/src/contracts.d.ts +3 -1
- package/dist/src/contracts.js +1 -1
- package/dist/src/daemon.d.ts +1 -0
- package/dist/src/daemon.js +15 -15
- package/dist/src/finders.js +1 -1
- package/dist/src/index.d.ts +17 -11
- package/dist/src/index.js +1 -3
- package/dist/src/install-source.js +1 -1
- package/dist/src/io.js +1 -1
- package/dist/src/metro-companion.d.ts +1 -0
- package/dist/src/metro.d.ts +9 -11
- package/dist/src/metro.js +1 -1
- package/dist/src/remote-config.js +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/testing/conformance.js +1 -1
- package/dist/src/update-check-entry.d.ts +1 -0
- package/package.json +9 -1
- package/skills/agent-device/references/exploration.md +1 -0
- package/skills/agent-device/references/remote-tenancy.md +9 -6
- package/skills/agent-device/references/verification.md +3 -0
- package/dist/src/152.js +0 -1
- package/dist/src/164.js +0 -1
- package/dist/src/556.js +0 -1
- package/dist/src/57.js +0 -1
- package/dist/src/641.js +0 -38
- package/dist/src/818.js +0 -1
- package/dist/src/974.js +0 -2
- /package/dist/src/{267.js → 3267.js} +0 -0
- /package/dist/src/{1~rslib-runtime.js → rslib-runtime.js} +0 -0
package/dist/src/113.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import e from"node:fs";import t from"node:path";import{fileURLToPath as r}from"node:url";import{runCmdDetached as n}from"./
|
|
1
|
+
import e from"node:fs";import t from"node:path";import{fileURLToPath as r}from"node:url";import{runCmdDetached as n}from"./9818.js";let i="agent-device",o="--agent-device-run-update-check";function a(a){var c,p,u,m,h,f,g;let k,v,y;if(!(!(!(c=a).command||"help"===c.command||"test"===c.command||c.flags.help||c.flags.version||c.flags.json||process.env.CI?.trim()||"test"===process.env.NODE_ENV||process.env.AGENT_DEVICE_NO_UPDATE_NOTIFIER?.trim())&&process.stderr.isTTY))return;let S=Date.now(),V=t.join(a.stateDir,"update-check.json"),w=s(V);p=w,u=a.currentVersion,!p.latestVersion||0>=l(p.latestVersion,u)||!0===p.prompted||(process.stderr.write(`Update available: ${i} ${a.currentVersion} -> ${w.latestVersion}. Run \`npm install -g ${i}@latest\` to upgrade the CLI and bundled skills.
|
|
2
2
|
`),d(V,{...w,prompted:!0})),m=w,h=S,(void 0===(k=function(e){if(!e)return;let t=Date.parse(e);return Number.isNaN(t)?void 0:t}(m.checkedAt))||h-k>=12096e5)&&(f=V,g=a.currentVersion,y=(v=function(){let n=r(import.meta.url),i=t.extname(n)||".js",o=t.join(t.dirname(n),`update-check-entry${i}`);if(!e.existsSync(o))throw Error(`Update check entrypoint not found at ${o}. Rebuild the package to include the update-check worker entry.`);return o}()).endsWith(".ts")?["--experimental-strip-types"]:[],n(process.execPath,[...y,v,o,f,g]))}async function c(e){let t=Date.now(),r=s(e.cachePath);try{let n=await p()??void 0;if(!n||0>=l(n,e.currentVersion))return void d(e.cachePath,{checkedAt:new Date(t).toISOString()});d(e.cachePath,{checkedAt:new Date(t).toISOString(),latestVersion:n,prompted:r.latestVersion===n&&!0===r.prompted})}catch{d(e.cachePath,{...r,checkedAt:new Date(t).toISOString()})}}function s(t){try{let r=JSON.parse(e.readFileSync(t,"utf8"));return{checkedAt:"string"==typeof r.checkedAt?r.checkedAt:void 0,latestVersion:"string"==typeof r.latestVersion?r.latestVersion:void 0,prompted:!0===r.prompted}}catch{return{}}}function d(r,n){try{e.mkdirSync(t.dirname(r),{recursive:!0}),e.writeFileSync(r,`${JSON.stringify(n,null,2)}
|
|
3
3
|
`,"utf8")}catch{}}async function p(){let e=await fetch(`https://registry.npmjs.org/${i}/latest`,{signal:AbortSignal.timeout(3500),headers:{accept:"application/json"}});if(!e.ok)return;let t=await e.json();return"string"==typeof t.version&&t.version.trim().length>0?t.version.trim():void 0}function l(e,t){return e.localeCompare(t,void 0,{numeric:!0})}function u(e){if(e[0]!==o)return null;let t=e[1]?.trim(),r=e[2]?.trim();return t&&r?{cachePath:t,currentVersion:r}:null}export{a as maybeRunUpgradeNotifier,u as readUpdateCheckWorkerArgs,c as runUpdateCheckWorker};
|
package/dist/src/1974.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"node:fs";import r from"node:path";import{createHash as t}from"node:crypto";import{fileURLToPath as n}from"node:url";import{runCmdDetached as o,runCmdSync as a}from"./9818.js";import{readProcessCommand as i,waitForProcessExit as s,isProcessAlive as l,readProcessStartTime as c}from"./3883.js";import{METRO_COMPANION_RUN_ARG as u,normalizeBaseUrl as d,buildBundleUrl as p,ENV_SERVER_BASE_URL as m,ENV_LOCAL_BASE_URL as f,ENV_STATE_PATH as h,ENV_LAUNCH_URL as g,ENV_SCOPE_TENANT_ID as y,ENV_SCOPE_RUN_ID as b,ENV_BEARER_TOKEN as S,ENV_SCOPE_LEASE_ID as w}from"./320.js";import{AppError as _}from"./9152.js";import{resolveUserPath as U}from"./3267.js";import{sleep as I}from"./4829.js";let E="metro-companion";function P(e){return t("sha256").update(e).digest("hex")}function k(e){return e?.trim()?e.trim():void 0}function v(e,t){let n=r.join(e,".agent-device");if(!t)return{statePath:r.join(n,"metro-companion.json"),logPath:r.join(n,"metro-companion.log")};let o=P(t).slice(0,12),a=r.join(n,E);return{statePath:r.join(a,`metro-companion-${o}.json`),logPath:r.join(a,`metro-companion-${o}.log`)}}function M(r){try{let t=JSON.parse(e.readFileSync(r,"utf8"));if(!Number.isInteger(t.pid)||0>=Number(t.pid)||"string"!=typeof t.serverBaseUrl||"string"!=typeof t.localBaseUrl||"string"!=typeof t.tokenHash||0===t.tokenHash.length)return null;let n=Array.isArray(t.consumers)?t.consumers.filter(e=>"string"==typeof e&&e.length>0):[];return{pid:Number(t.pid),startTime:"string"==typeof t.startTime?t.startTime:void 0,command:"string"==typeof t.command?t.command:void 0,serverBaseUrl:t.serverBaseUrl,localBaseUrl:t.localBaseUrl,launchUrl:k("string"==typeof t.launchUrl?t.launchUrl:void 0),bridgeScope:function(e){if(!(!e||"object"!=typeof e||Array.isArray(e))&&"string"==typeof e.tenantId&&"string"==typeof e.runId&&"string"==typeof e.leaseId)return{tenantId:e.tenantId,runId:e.runId,leaseId:e.leaseId}}(t.bridgeScope),tokenHash:t.tokenHash,consumers:n}}catch{return null}}function A(t,n){e.mkdirSync(r.dirname(t),{recursive:!0}),e.writeFileSync(t,`${JSON.stringify(n,null,2)}
|
|
2
|
+
`,"utf8")}function N(r){try{let t=e.readdirSync(r);0===t.length&&e.rmdirSync(r)}catch{}}function R(t){let n=r.dirname(t.statePath),o=r.dirname(t.logPath);var a=t.statePath;try{e.unlinkSync(a)}catch{}var i=t.logPath;try{e.unlinkSync(i)}catch{}N(n),o!==n&&N(o),r.basename(n)===E&&N(r.dirname(n))}function $(e){return e.includes(u)}function x(e){return k(e.consumerKey)??k(e.profileKey)??null}function j(e,r){return!r||e.consumers.includes(r)?e:{...e,consumers:[...e.consumers,r]}}async function T(e){if(!l(e.pid))return;let r=i(e.pid);if(r&&$(r)){try{process.kill(e.pid,"SIGTERM")}catch(r){let e=r.code;if("ESRCH"===e||"EPERM"===e)return;throw r}if(!await s(e.pid,1e3)){try{process.kill(e.pid,"SIGKILL")}catch(r){let e=r.code;if("ESRCH"===e||"EPERM"===e)return;throw r}await s(e.pid,1e3)}}}async function B(t){let a=x(t),s=v(t.projectRoot,t.profileKey),p=M(s.statePath);if(p&&function(e,r){var t,n;if(!l(e.pid))return!1;if(e.startTime){let r=c(e.pid);if(!r||r!==e.startTime)return!1}let o=i(e.pid);return!!o&&!!$(o)&&!!e.bridgeScope&&e.serverBaseUrl===d(r.serverBaseUrl)&&e.localBaseUrl===d(r.localBaseUrl)&&e.launchUrl===k(r.launchUrl)&&(t=e.bridgeScope,n=r.bridgeScope,t.tenantId===n.tenantId&&t.runId===n.runId&&t.leaseId===n.leaseId)&&e.tokenHash===P(r.bearerToken)}(p,t)){let e=j(p,a);return e!==p&&A(s.statePath,e),{pid:p.pid,spawned:!1,statePath:s.statePath,logPath:s.logPath}}p&&(await T(p),R(s));let _=function(t,a){let s=function(){let t=n(import.meta.url),o=r.extname(t)||".js",a=r.join(r.dirname(t),`metro-companion${o}`);if(!e.existsSync(a))throw Error(`Metro companion entrypoint not found at ${a}. Rebuild the package to include the companion worker entry.`);return a}(),l=s.endsWith(".ts")?["--experimental-strip-types"]:[];e.mkdirSync(r.dirname(a),{recursive:!0});let p=e.openSync(a,"a"),_=0;try{let e;_=o(process.execPath,[...l,s,u],{env:((e={...t.env??process.env,[m]:d(t.serverBaseUrl),[S]:t.bearerToken,[f]:d(t.localBaseUrl),[h]:v(t.projectRoot,t.profileKey).statePath})[y]=t.bridgeScope.tenantId,e[b]=t.bridgeScope.runId,e[w]=t.bridgeScope.leaseId,t.launchUrl?.trim()?e[g]=t.launchUrl.trim():delete e[g],e),stdio:["ignore",p,p]})}finally{e.closeSync(p)}if(!Number.isInteger(_)||_<=0)throw Error("Failed to start Metro companion process.");return{pid:_,startTime:c(_)??void 0,command:i(_)??void 0,serverBaseUrl:d(t.serverBaseUrl),localBaseUrl:d(t.localBaseUrl),launchUrl:k(t.launchUrl),bridgeScope:t.bridgeScope,tokenHash:P(t.bearerToken),consumers:[]}}(t,s.logPath);return A(s.statePath,j(_,a)),{pid:_.pid,spawned:!0,statePath:s.statePath,logPath:s.logPath}}async function C(e){let r=x(e),t=v(e.projectRoot,e.profileKey),n=M(t.statePath);if(!n)return R(t),{stopped:!1,statePath:t.statePath};let o=r?{...n,consumers:n.consumers.filter(e=>e!==r)}:{...n,consumers:[]};return o.consumers.length>0?(A(t.statePath,o),{stopped:!1,statePath:t.statePath}):(await T(n),R(t),{stopped:!0,statePath:t.statePath})}function K(e){return"string"==typeof e&&e.trim()?d(e.trim()):""}function H(e){return"string"==typeof e&&e.trim()?e.trim():void 0}function D(e,r,t){return U(e,{env:r,cwd:t})}function O(r){try{return e.accessSync(r,e.constants.F_OK),!0}catch{return!1}}function J(e,r,t){if(null==e||""===e)return r;let n=Number.parseInt(String(e),10);return Number.isInteger(n)?Math.max(n,t):r}function L(e,r){return{platform:r,bundleUrl:p(e,r)}}function G(e,r){return{platform:r,metroHost:H(e?.metro_host),metroPort:e?.metro_port,bundleUrl:H(e?.metro_bundle_url),launchUrl:H(e?.launch_url)}}async function F(e){await I(e)}async function V(e,r,t={}){try{let n=await fetch(e,{headers:t,signal:AbortSignal.timeout(r)});return{ok:n.ok,status:n.status,body:await n.text()}}catch(t){if(t instanceof Error&&"TimeoutError"===t.name)throw Error(`Timed out fetching ${e} after ${r}ms`);throw t}}async function q(e,r){try{let t=await V(e,r);return t.ok&&t.body.includes("packager-status:running")}catch{return!1}}async function z(e){if(Number.isInteger(e)&&!(e<=0)){try{process.kill(e,"SIGTERM")}catch(r){let e=r.code;if("ESRCH"===e||"EPERM"===e)return;throw r}if(!await s(e,1e3)){try{process.kill(e,"SIGKILL")}catch(r){let e=r.code;if("ESRCH"===e||"EPERM"===e)return;throw r}await s(e,1e3)}}}function W(e,r){let t=Error(e);return t.retryable=r,t}function X(e,r){return!!(e>=500||408===e||425===e||429===e||JSON.stringify(r).includes("Metro companion is not connected"))}function Y(e){return!!(e&&"object"==typeof e&&"retryable"in e&&!0===e.retryable)}async function Q(e){let r;try{var t,n;r=await fetch(`${e.baseUrl}/api/metro/bridge`,{method:"POST",headers:(t=e.baseUrl,n=e.bearerToken,{Authorization:`Bearer ${n}`,"Content-Type":"application/json",...t.includes("ngrok")?{"ngrok-skip-browser-warning":"1"}:{}}),body:JSON.stringify({...e.scope,...e.runtime?{ios_runtime:e.runtime}:{},timeout_ms:e.timeoutMs}),signal:AbortSignal.timeout(e.timeoutMs)})}catch(r){if(r instanceof Error&&"TimeoutError"===r.name)throw W(`/api/metro/bridge timed out after ${e.timeoutMs}ms calling ${e.baseUrl}/api/metro/bridge`,!0);throw W(r instanceof Error?r.message:String(r),!0)}let o=function(e,r,t){if(!e)return{};try{let r=JSON.parse(e);if(!r||"object"!=typeof r||Array.isArray(r))throw Error("Expected a JSON object");return r}catch(a){let n=e.slice(0,200),o=a instanceof Error?a.message:String(a);throw W(`/api/metro/bridge returned invalid JSON (${r}) from ${t}: ${o}. body=${JSON.stringify(n)}`,X(r,e))}}(await r.text(),r.status,e.baseUrl);if(!r.ok)throw W(`/api/metro/bridge failed (${r.status}): ${JSON.stringify(o)}`,X(r.status,o));var a=o;let i=a.data??a;if(!i||"object"!=typeof i||Array.isArray(i))throw W("/api/metro/bridge returned malformed descriptor: Expected a JSON object.",!1);try{return{enabled:i.enabled,baseUrl:i.base_url,statusUrl:i.status_url??"",bundleUrl:i.bundle_url??"",iosRuntime:G(i.ios_runtime,"ios"),androidRuntime:G(i.android_runtime,"android"),upstream:{bundleUrl:i.upstream.bundle_url??"",host:i.upstream.host??"",port:i.upstream.port??0,statusUrl:i.upstream.status_url??""},probe:{reachable:i.probe.reachable,statusCode:i.probe.status_code,latencyMs:i.probe.latency_ms,detail:i.probe.detail}}}catch(e){throw W(`/api/metro/bridge returned malformed descriptor: ${e instanceof Error?e.message:String(e)}`,!1)}}function Z(e,r,t,n,o){let a=[`Metro bridge is required for this run but could not be configured via ${e}/api/metro/bridge.`];return r&&a.push(`bridgeError=${r}`),t?.probe.reachable===!1&&a.push(`bridgeProbe=${t.probe.detail||`unreachable (status ${t.probe.statusCode||0})`}`),n&&n!==r&&a.push(`initialBridgeError=${n}`),o&&a.push(`metroCompanionLog=${o}`),a.join(" ")}async function ee(e,r,t){let n=Date.now()+r;for(;Date.now()<n;){let r=Math.min(t,Math.max(n-Date.now(),1));if(await q(e,r))return!0;let o=Math.min(500,Math.max(n-Date.now(),0));o>0&&await F(o)}return!1}async function er(e){let r=Date.now()+e.startupTimeoutMs,t=null,n=null;for(;Date.now()<r;){try{let r=await Q({baseUrl:e.baseUrl,bearerToken:e.bearerToken,scope:e.scope,runtime:e.runtime,timeoutMs:e.probeTimeoutMs});if(!1!==r.probe.reachable)return r;t=r,n=null}catch(e){if(n=e instanceof Error?e.message:String(e),!Y(e))break}let o=Math.min(1e3,Math.max(r-Date.now(),0));o>0&&await F(o)}throw Error(Z(e.baseUrl,n,t,e.initialBridgeError,e.companionLogPath))}async function et(t={}){let n=t.env??process.env,i=process.cwd(),s=D(t.projectRoot??i,n,i),l=function(t,n){if("auto"!==n)return n;let o=function(t){let n=r.join(t,"package.json");if(!O(n))throw new _("INVALID_ARGS",`package.json not found at ${n}`);return JSON.parse(e.readFileSync(n,"utf8"))}(t);return"string"==typeof({...o.dependencies??{},...o.devDependencies??{}}).expo?"expo":"react-native"}(s,t.kind??"auto"),c=function(e){if(null==e||""===e)return 8081;let r=Number.parseInt(String(e),10);if(!Number.isInteger(r)||r<1||r>65535)throw new _("INVALID_ARGS",`Invalid Metro port: ${String(e)}. Use 1-65535.`);return r}(t.metroPort??8081),u=H(t.listenHost)??"0.0.0.0",d=H(t.statusHost)??"127.0.0.1",p=K(t.publicBaseUrl),m=J(t.startupTimeoutMs,18e4,3e4),f=J(t.probeTimeoutMs,1e4,1e3),h=t.reuseExisting??!0,g=t.installDependenciesIfNeeded??!0,y=t.runtimeFilePath?D(t.runtimeFilePath,n,i):null,b=D(t.logPath??r.join(s,".agent-device","metro.log"),n,i);if(!p&&!K(t.proxyBaseUrl))throw new _("INVALID_ARGS","metro prepare requires --public-base-url <url>.");let{proxyEnabled:S,proxyBaseUrl:w,proxyBearerToken:U}=function(e,r){if(e&&!r)throw new _("INVALID_ARGS","metro prepare requires proxy auth when --proxy-base-url is provided. Pass --bearer-token or set AGENT_DEVICE_PROXY_TOKEN.");if(!e&&r)throw new _("INVALID_ARGS","metro prepare requires --proxy-base-url when proxy auth is provided.");return{proxyEnabled:!!(e&&r),proxyBaseUrl:e,proxyBearerToken:r}}(K(t.proxyBaseUrl),H(t.proxyBearerToken)??""),I=S?function(e){if(!e?.tenantId||!e.runId||!e.leaseId)throw new _("INVALID_ARGS","metro prepare with proxy requires tenantId, runId, and leaseId bridge scope.");return e}(t.bridgeScope):null,E=g?function(t,n){if(function(r){try{return e.statSync(r).isDirectory()}catch{return!1}}(r.join(t,"node_modules")))return{installed:!1};let o=O(r.join(t,"pnpm-lock.yaml"))?{command:"pnpm",installArgs:["install"]}:O(r.join(t,"yarn.lock"))?{command:"yarn",installArgs:["install"]}:{command:"npm",installArgs:["install"]};return a(o.command,o.installArgs,{cwd:t,env:n}),{installed:!0,packageManager:o.command}}(s,n):{installed:!1},P=`http://${d}:${c}/status`,k=!1,v=!1,M=0;if(h&&await q(P,f))v=!0;else if(k=!0,M=function(t,n,a,i,s,l){let c="expo"===n?{command:"npx",installArgs:["expo","start","--host","lan","--port",String(a)]}:{command:"npx",installArgs:["react-native","start","--host",i,"--port",String(a)]};e.mkdirSync(r.dirname(s),{recursive:!0});let u=e.openSync(s,"a"),d=0;try{d=o(c.command,c.installArgs,{cwd:t,env:l,stdio:["ignore",u,u]})}finally{e.closeSync(u)}if(!Number.isInteger(d)||d<=0)throw Error("Failed to start Metro. Expected a detached child PID.");return{pid:d}}(s,l,c,u,b,n).pid,!await ee(P,m,f))throw await z(M).catch(()=>{}),Error(`Metro did not become ready at ${P} within ${m}ms. Check ${b}.`);let A=p?L(p,"ios"):{platform:"ios"},N=p?L(p,"android"):{platform:"android"},R=null,$=null;if(I)try{R=await Q({baseUrl:w,bearerToken:U,scope:I,timeoutMs:f})}catch(e){if(!Y(e))throw e;$=e instanceof Error?e.message:String(e)}if(I&&(!R||!1===R.probe.reachable)){let e;try{e=(await B({projectRoot:s,serverBaseUrl:w,bearerToken:U,bridgeScope:I,localBaseUrl:`http://${d}:${c}`,launchUrl:H(t.launchUrl),profileKey:H(t.companionProfileKey),consumerKey:H(t.companionConsumerKey),env:n})).logPath}catch(e){throw Error(Z(w,e instanceof Error?e.message:String(e),R,$))}try{R=await er({baseUrl:w,bearerToken:U,scope:I,probeTimeoutMs:f,startupTimeoutMs:m,initialBridgeError:$,companionLogPath:e})}catch(e){throw e instanceof Error?e:Error(String(e))}}I&&function(e,r){if(!r?.iosRuntime.bundleUrl)throw Error(Z(e,"bridge descriptor is missing ios_runtime.metro_bundle_url",r))}(w,R);let x=R?.iosRuntime??A,j=R?.androidRuntime??N,T={projectRoot:s,kind:l,dependenciesInstalled:E.installed,packageManager:E.packageManager??null,started:k,reused:v,pid:M,logPath:b,statusUrl:P,runtimeFilePath:y,iosRuntime:x,androidRuntime:j,bridge:R};return y&&(e.mkdirSync(r.dirname(y),{recursive:!0}),e.writeFileSync(y,JSON.stringify(T,null,2))),T}export{L as buildMetroRuntimeHints,B as ensureMetroCompanion,et as prepareMetroRuntime,C as stopMetroCompanion};
|
package/dist/src/3883.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{runCmdSync as e}from"./9818.js";import{sleep as t}from"./4829.js";let r=[/(^|[/\s"'=])dist\/src\/daemon\.js($|[\s"'])/,/(^|[/\s"'=])src\/daemon\.ts($|[\s"'])/];function n(e){if(!Number.isInteger(e)||e<=0)return!1;try{return process.kill(e,0),!0}catch(e){return"EPERM"===e.code}}function i(t){if(!Number.isInteger(t)||t<=0)return null;try{let r=e("ps",["-p",String(t),"-o","lstart="],{allowFailure:!0,timeoutMs:1e3});if(0!==r.exitCode)return null;let n=r.stdout.trim();return n.length>0?n:null}catch{return null}}function o(t){if(!Number.isInteger(t)||t<=0)return null;try{let r=e("ps",["-p",String(t),"-o","command="],{allowFailure:!0,timeoutMs:1e3});if(0!==r.exitCode)return null;let n=r.stdout.trim();return n.length>0?n:null}catch{return null}}function l(e,t){let l;if(!n(e))return!1;if(t){let r=i(e);if(!r||r!==t)return!1}let s=o(e);return!!s&&!!(l=s.toLowerCase().replaceAll("\\","/")).includes("agent-device")&&r.some(e=>e.test(l))}function s(e,t){try{return process.kill(e,t),!0}catch(t){let e=t.code;if("ESRCH"===e||"EPERM"===e)return!1;throw t}}async function u(e,r){if(!n(e))return!0;let i=Date.now();for(;Date.now()-i<r;)if(await t(50),!n(e))return!0;return!n(e)}async function c(e,t){!l(e,t.expectedStartTime)||!s(e,"SIGTERM")||await u(e,t.termTimeoutMs)||s(e,"SIGKILL")&&await u(e,t.killTimeoutMs)}export{l as isAgentDeviceDaemonProcess,n as isProcessAlive,o as readProcessCommand,i as readProcessStartTime,c as stopProcessForTakeover,u as waitForProcessExit};
|