UNPKG

agent-device

Version:

Open source device layer for AI coding agents: a CLI, MCP server, and typed Node.js API to control mobile, web, TV, and desktop apps on devices and simulators, locally or in the cloud.

2 lines • 2.77 kB
import{v as e}from"./sdk-contracts.js";import{k as t}from"./sdk-batch-runner.js";import{et as n}from"./sdk-io.js";import{T as r}from"./sdk-device.js";import"./command.js";import{c as i,s as a}from"./tool-provider.js";import{t as o}from"./physical-device-control.js";import{r as s}from"./simctl.js";import{r as c}from"./plist.js";import l from"node:path";import{fileURLToPath as u}from"node:url";const d=15e3;function f(e){let n=[];for(let r of t(e)){let e=r.match(/^(\d+)\s+([0-9]+(?:\.[0-9]+)?)\s+(\d+)\s+(.+)$/);if(!e)continue;let[t,i,a,o]=e.slice(1);if(t===void 0||i===void 0||a===void 0||o===void 0)continue;let s=Number(t),c=Number(i),l=Number(a),u=o.trim();!Number.isFinite(s)||!Number.isFinite(c)||!Number.isFinite(l)||n.push({pid:s,cpuPercent:c,rssKb:l,command:u})}return n}async function p(t,n){let i=r(t)?await h(n):await g(t,n),a=r(t)?l.join(i,`Contents`,`Info.plist`):l.join(i,`Info.plist`),o=await c(a,`CFBundleExecutable`);if(!o)throw new e(`COMMAND_FAILED`,`Failed to resolve executable for ${n}`,{appBundleId:n,appPath:i});return{executableName:o,executablePath:r(t)?l.join(i,`Contents`,`MacOS`,o):l.join(i,o)}}async function m(t,n){let{appBundleUrl:r,processes:i}=await o(t).resolveAppProcesses(t,n),a=u(r);if(i.length===0)throw new e(`COMMAND_FAILED`,`No running process found for ${n}`,{appBundleId:n,deviceId:t.id,appBundlePath:a,hint:`Run open <app> for this session again to ensure the iOS app is active, then retry perf.`});return i}async function h(t){let r=`kMDItemCFBundleIdentifier == "${t.replaceAll(`"`,String.raw`\"`)}"`,i=n(await a(`mdfind`,[r],{allowFailure:!0,timeoutMs:d}),`Failed to resolve macOS app bundle for ${t}`,{appBundleId:t}).stdout.split(` `).map(e=>e.trim()).find(e=>e.endsWith(`.app`));if(!i)throw new e(`APP_NOT_INSTALLED`,`No macOS app found for ${t}`,{appBundleId:t});return i}async function g(t,r){let a=s(t,[`get_app_container`,t.id,r,`app`]),o=n(await i(a,{allowFailure:!0,timeoutMs:d}),`Failed to resolve iOS simulator app container for ${r}`,{appBundleId:r,hint:`Ensure the iOS simulator app is installed and booted, then retry perf.`}).stdout.trim();if(o.length===0)throw new e(`APP_NOT_INSTALLED`,`No iOS simulator app container found for ${r}`,{appBundleId:r});return o}async function _(e,t){let n=r(e)?await a(`ps`,[`-axo`,`pid=,%cpu=,rss=,command=`],{timeoutMs:d}):await v(s(e,[`spawn`,e.id,`ps`,`-axo`,`pid=,%cpu=,rss=,command=`])),{matchesAppleExecutableProcess:i}=await import(`./perf-process-identity.js`);return f(n.stdout).filter(e=>i(e.command,t))}async function v(e){let t=await i(e,{allowFailure:!0,timeoutMs:d});return t.exitCode===0?t:await a(`ps`,[`-axo`,`pid=,%cpu=,rss=,command=`],{timeoutMs:d})}export{_ as readAppleProcessSamples,p as resolveAppleExecutable,m as resolveIosDevicePerfTarget};