agent-device 0.11.0 → 0.11.1

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.
@@ -0,0 +1,3 @@
1
+ import{AsyncLocalStorage as e}from"node:async_hooks";import t,{createHash as r}from"node:crypto";import n,{existsSync as i,promises as o}from"node:fs";import a from"node:os";import s from"node:path";import{PNG as l}from"pngjs";import{URL as d,fileURLToPath as u,pathToFileURL as c}from"node:url";import{spawn as p,spawnSync as f}from"node:child_process";let m=new e,h=/(token|secret|password|authorization|cookie|api[_-]?key|access[_-]?key|private[_-]?key)/i,g=/(bearer\s+[a-z0-9._-]+|(?:api[_-]?key|token|secret|password)\s*[=:]\s*\S+)/i;function w(){return t.randomBytes(8).toString("hex")}async function I(e,r){let n={...e,diagnosticId:`${Date.now().toString(36)}-${t.randomBytes(4).toString("hex")}`,events:[]};return await m.run(n,r)}function S(){let e=m.getStore();return e?{diagnosticId:e.diagnosticId,requestId:e.requestId,session:e.session,command:e.command,debug:e.debug}:{}}function v(e){let t=m.getStore();if(!t)return;let r={ts:new Date().toISOString(),level:e.level??"info",phase:e.phase,session:t.session,requestId:t.requestId,command:t.command,durationMs:e.durationMs,data:e.data?b(e.data):void 0};if(t.events.push(r),!t.debug)return;let i=`[agent-device][diag] ${JSON.stringify(r)}
2
+ `;try{t.logPath&&n.appendFile(t.logPath,i,()=>{}),t.traceLogPath&&n.appendFile(t.traceLogPath,i,()=>{}),t.logPath||t.traceLogPath||process.stderr.write(i)}catch{}}async function y(e,t,r){let n=Date.now();try{let i=await t();return v({level:"info",phase:e,durationMs:Date.now()-n,data:r}),i}catch(t){throw v({level:"error",phase:e,durationMs:Date.now()-n,data:{...r??{},error:t instanceof Error?t.message:String(t)}}),t}}function A(e={}){let t=m.getStore();if(!t||!e.force&&!t.debug||0===t.events.length)return null;try{let e=(t.session??"default").replace(/[^a-zA-Z0-9._-]/g,"_"),r=new Date().toISOString().slice(0,10),i=s.join(a.homedir(),".agent-device","logs",e,r);n.mkdirSync(i,{recursive:!0});let o=new Date().toISOString().replace(/[:.]/g,"-"),l=s.join(i,`${o}-${t.diagnosticId}.ndjson`),d=t.events.map(e=>JSON.stringify(b(e)));return n.writeFileSync(l,`${d.join("\n")}
3
+ `),t.events=[],l}catch{return null}}function b(e){return function e(t,r,n){if(null==t)return t;if("string"==typeof t){var i=t,o=n;let e=i.trim();if(!e)return i;if(o&&h.test(o)||g.test(e))return"[REDACTED]";let r=function(e){try{let t=new URL(e);return t.search&&(t.search="?REDACTED"),(t.username||t.password)&&(t.username="REDACTED",t.password="REDACTED"),t.toString()}catch{return null}}(e);return r||(e.length>400?`${e.slice(0,200)}...<truncated>`:e)}if("object"!=typeof t)return t;if(r.has(t))return"[Circular]";if(r.add(t),Array.isArray(t))return t.map(t=>e(t,r));let a={};for(let[n,i]of Object.entries(t)){if(h.test(n)){a[n]="[REDACTED]";continue}a[n]=e(i,r,n)}return a}(e,new WeakSet)}class E extends Error{code;details;cause;constructor(e,t,r,n){super(t),this.code=e,this.details=r,this.cause=n}}function $(e){return e instanceof E?e:e instanceof Error?new E("UNKNOWN",e.message,void 0,e):new E("UNKNOWN","Unknown error",{err:e})}function N(e,t={}){let r=$(e),n=r.details?b(r.details):void 0,i=n&&"string"==typeof n.hint?n.hint:void 0,o=(n&&"string"==typeof n.diagnosticId?n.diagnosticId:void 0)??t.diagnosticId,a=(n&&"string"==typeof n.logPath?n.logPath:void 0)??t.logPath,s=i??function(e){switch(e){case"INVALID_ARGS":return"Check command arguments and run --help for usage examples.";case"SESSION_NOT_FOUND":return"Run open first or pass an explicit device selector.";case"TOOL_MISSING":return"Install required platform tooling and ensure it is available in PATH.";case"DEVICE_NOT_FOUND":return"Verify the target device is booted/connected and selectors match.";case"UNSUPPORTED_OPERATION":return"This command is not available for the selected platform/device.";case"COMMAND_FAILED":default:return"Retry with --debug and inspect diagnostics log for details.";case"UNAUTHORIZED":return"Refresh daemon metadata and retry the command."}}(r.code),l=function(e){if(!e)return;let t={...e};return delete t.hint,delete t.diagnosticId,delete t.logPath,Object.keys(t).length>0?t:void 0}(n),d=function(e,t,r){if("COMMAND_FAILED"!==e||r?.processExitError!==!0)return t;let n=function(e){let t=[/^an error was encountered processing the command/i,/^underlying error\b/i,/^simulator device failed to complete the requested operation/i];for(let r of e.split("\n")){let e=r.trim();if(e&&!t.some(t=>t.test(e)))return e.length>200?`${e.slice(0,200)}...`:e}return null}("string"==typeof r?.stderr?r.stderr:"");return n||t}(r.code,r.message,n);return{code:r.code,message:d,hint:s,diagnosticId:o,logPath:a,details:l}}let D="<wifi|airplane|location> <on|off>",x="appearance <light|dark|toggle>",_="faceid <match|nonmatch|enroll|unenroll>",T="touchid <match|nonmatch|enroll|unenroll>",L="fingerprint <match|nonmatch>",O="permission <grant|deny|reset> <camera|microphone|photos|contacts|contacts-limited|notifications|calendar|location|location-always|media-library|motion|reminders|siri> [full|limited]",M="permission <grant|reset> <accessibility|screen-recording|input-monitoring>",C=`settings ${D} | settings ${x} | settings ${_} | settings ${T} | settings ${L} | settings ${O} | settings ${M}`,k=`settings requires ${D}, ${x}, ${_}, ${T}, ${L}, ${O}, or ${M}`,P=["app","frontmost-app","desktop","menubar"];function R(e){let t=e?.trim().toLowerCase();if("app"===t||"frontmost-app"===t||"desktop"===t||"menubar"===t)return t;throw new E("INVALID_ARGS",`Invalid surface: ${e}. Use ${P.join("|")}.`)}function F(e){var t;let r,n=B(e.label),i=B(e.value),o=B(e.identifier),a=(t=o)&&!/^[\w.]+:id\/[\w.-]+$/i.test(t)&&!/^_?NS:\d+$/i.test(t)?o:"";return(r=j(e.type??"")).includes("textfield")||r.includes("securetextfield")||r.includes("searchfield")||r.includes("edittext")||r.includes("textview")||r.includes("textarea")?i||n||a:n||i||a}function B(e){return"string"==typeof e?e.trim():""}function j(e){let t=e.trim().replace(/XCUIElementType/gi,"").replace(/^AX/,"").toLowerCase(),r=Math.max(t.lastIndexOf("."),t.lastIndexOf("/"));return -1!==r&&(t=t.slice(r+1)),t}function G(e,t={}){let r=[],n=[];for(let i of e){let e=i.depth??0;for(;r.length>0&&e<=r[r.length-1];)r.pop();let o=i.label?.trim()||i.value?.trim()||i.identifier?.trim()||"",a=V(i.type??"Element"),s="group"===a&&!o;s&&r.push(e);let l=s?e:Math.max(0,e-r.length);n.push({node:i,depth:l,type:a,text:z(i,l,s,a,t)})}return n}function z(e,t,r,n,i={}){var o,a,s,l,d;let u,c,p=n??V(e.type??"Element"),f=(u=F(e),{text:u,isLargeSurface:c=function(e,t){if("text-view"===t||"text-field"===t||"search"===t)return!0;let r=j(e.type??""),n=`${e.role??""} ${e.subrole??""}`.toLowerCase();return r.includes("textview")||r.includes("textarea")||r.includes("textfield")||r.includes("securetextfield")||r.includes("searchfield")||r.includes("edittext")||n.includes("text area")||n.includes("text field")}(e,p),shouldSummarize:c&&!!(o=u)&&(o.length>80||/[\r\n]/.test(o))}),m=(a=e,s=p,l=i,d=f,l.summarizeTextSurfaces&&d.shouldSummarize&&function(e,t,r){let n=B(e.label);if(n&&n!==r)return n;let i=B(e.identifier);if(i&&!q(i)&&i!==r)return i;switch(t){case"text":case"text-view":return"Text view";case"text-field":return"Text field";case"search":return"Search field";default:return""}}(a,s,d.text)||U(a,s)),h=" ".repeat(t),g=e.ref?`@${e.ref}`:"",w=(function(e,t,r,n){let i,o=[];if(!1===e.enabled&&o.push("disabled"),!r.summarizeTextSurfaces||(!0===e.selected&&o.push("selected"),H(t)&&o.push("editable"),function(e,t){if("scroll-area"===t)return!0;let r=(e.type??"").toLowerCase(),n=`${e.role??""} ${e.subrole??""}`.toLowerCase();return r.includes("scroll")||n.includes("scroll")}(e,t)&&o.push("scrollable"),!n.shouldSummarize))return o;return o.push(`preview:"${((i=n.text.replace(/\s+/g," ").trim()).length<=48?i:`${i.slice(0,45)}...`).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`),o.push("truncated"),[...new Set(o)]})(e,p,i,f).map(e=>` [${e}]`).join(""),I=m?` "${m}"`:"";return r?`${h}${g} [${p}]${w}`.trimEnd():`${h}${g} [${p}]${I}${w}`.trimEnd()}function U(e,t){let r=e.label?.trim(),n=e.value?.trim();if(H(t)){if(n)return n;if(r)return r}else if(r)return r;if(n)return n;let i=e.identifier?.trim();return!i||q(i)&&("group"===t||"image"===t||"list"===t||"collection"===t)?"":i}function V(e){let t=e.replace(/XCUIElementType/gi,"").toLowerCase(),r=e.includes(".")&&(e.startsWith("android.")||e.startsWith("androidx.")||e.startsWith("com."));switch(t.includes(".")&&(t=t.replace(/^android\.widget\./,"").replace(/^android\.view\./,"").replace(/^android\.webkit\./,"").replace(/^androidx\./,"").replace(/^com\.google\.android\./,"").replace(/^com\.android\./,"")),t){case"application":return"application";case"navigationbar":return"navigation-bar";case"tabbar":return"tab-bar";case"button":case"imagebutton":return"button";case"link":return"link";case"cell":return"cell";case"statictext":case"checkedtextview":return"text";case"textfield":case"edittext":return"text-field";case"textview":return r?"text":"text-view";case"textarea":return"text-view";case"switch":return"switch";case"slider":return"slider";case"image":case"imageview":return"image";case"webview":return"webview";case"framelayout":case"linearlayout":case"relativelayout":case"constraintlayout":case"viewgroup":case"view":case"group":return"group";case"listview":case"recyclerview":return"list";case"collectionview":return"collection";case"searchfield":return"search";case"segmentedcontrol":return"segmented-control";case"window":return"window";case"checkbox":return"checkbox";case"radio":return"radio";case"menuitem":return"menu-item";case"toolbar":return"toolbar";case"scrollarea":case"scrollview":case"nestedscrollview":return"scroll-area";case"table":return"table";default:return t||"element"}}function H(e){return"text-field"===e||"text-view"===e||"search"===e}function q(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function J(){try{let e=W();return JSON.parse(n.readFileSync(s.join(e,"package.json"),"utf8")).version??"0.0.0"}catch{return"0.0.0"}}function W(){let e=s.dirname(u(import.meta.url)),t=e;for(let e=0;e<6;e+=1){let e=s.join(t,"package.json");if(n.existsSync(e))return t;t=s.dirname(t)}return e}function K(e){return e?{message:e}:{}}function X(e,t){return t?{...e,message:t}:e}function Z(e){return"string"==typeof e?.message&&e.message.length>0?e.message:null}async function Q(e,t,r={}){return new Promise((n,i)=>{let o=p(e,t,{cwd:r.cwd,env:r.env,stdio:["pipe","pipe","pipe"],detached:r.detached}),a="",s=r.binaryStdout?Buffer.alloc(0):void 0,l="",d=!1,u=ei(r.timeoutMs),c=u?setTimeout(()=>{d=!0,o.kill("SIGKILL")},u):null;r.binaryStdout||o.stdout.setEncoding("utf8"),o.stderr.setEncoding("utf8"),void 0!==r.stdin&&o.stdin.write(r.stdin),o.stdin.end(),o.stdout.on("data",e=>{r.binaryStdout?s=Buffer.concat([s??Buffer.alloc(0),Buffer.isBuffer(e)?e:Buffer.from(e)]):a+=e}),o.stderr.on("data",e=>{l+=e}),o.on("error",r=>{(c&&clearTimeout(c),"ENOENT"===r.code)?i(new E("TOOL_MISSING",`${e} not found in PATH`,{cmd:e},r)):i(new E("COMMAND_FAILED",`Failed to run ${e}`,{cmd:e,args:t},r))}),o.on("close",o=>{c&&clearTimeout(c);let p=o??1;d&&u?i(new E("COMMAND_FAILED",`${e} timed out after ${u}ms`,{cmd:e,args:t,stdout:a,stderr:l,exitCode:p,timeoutMs:u})):0===p||r.allowFailure?n({stdout:a,stderr:l,exitCode:p,stdoutBuffer:s}):i(new E("COMMAND_FAILED",`${e} exited with code ${p}`,{cmd:e,args:t,stdout:a,stderr:l,exitCode:p,processExitError:!0}))})})}async function Y(e){try{var t;let{shell:r,args:n}=(t=e,"win32"===process.platform?{shell:"cmd.exe",args:["/c","where",t]}:{shell:"bash",args:["-lc",`command -v ${t}`]}),i=await Q(r,n,{allowFailure:!0});return 0===i.exitCode&&i.stdout.trim().length>0}catch{return!1}}function ee(e,t,r={}){let n=f(e,t,{cwd:r.cwd,env:r.env,stdio:["pipe","pipe","pipe"],encoding:r.binaryStdout?void 0:"utf8",input:r.stdin,timeout:ei(r.timeoutMs)});if(n.error){let i=n.error.code;if("ETIMEDOUT"===i)throw new E("COMMAND_FAILED",`${e} timed out after ${ei(r.timeoutMs)}ms`,{cmd:e,args:t,timeoutMs:ei(r.timeoutMs)},n.error);if("ENOENT"===i)throw new E("TOOL_MISSING",`${e} not found in PATH`,{cmd:e},n.error);throw new E("COMMAND_FAILED",`Failed to run ${e}`,{cmd:e,args:t},n.error)}let i=r.binaryStdout?Buffer.isBuffer(n.stdout)?n.stdout:Buffer.from(n.stdout??""):void 0,o=r.binaryStdout?"":"string"==typeof n.stdout?n.stdout:(n.stdout??"").toString(),a="string"==typeof n.stderr?n.stderr:(n.stderr??"").toString(),s=n.status??1;if(0!==s&&!r.allowFailure)throw new E("COMMAND_FAILED",`${e} exited with code ${s}`,{cmd:e,args:t,stdout:o,stderr:a,exitCode:s,processExitError:!0});return{stdout:o,stderr:a,exitCode:s,stdoutBuffer:i}}function et(e,t,r={}){p(e,t,{cwd:r.cwd,env:r.env,stdio:"ignore",detached:!0}).unref()}async function er(e,t,r={}){return new Promise((n,i)=>{let o=p(e,t,{cwd:r.cwd,env:r.env,stdio:["pipe","pipe","pipe"],detached:r.detached});r.onSpawn?.(o);let a="",s="",l=r.binaryStdout?Buffer.alloc(0):void 0;r.binaryStdout||o.stdout.setEncoding("utf8"),o.stderr.setEncoding("utf8"),void 0!==r.stdin&&o.stdin.write(r.stdin),o.stdin.end(),o.stdout.on("data",e=>{if(r.binaryStdout){l=Buffer.concat([l??Buffer.alloc(0),Buffer.isBuffer(e)?e:Buffer.from(e)]);return}let t=String(e);a+=t,r.onStdoutChunk?.(t)}),o.stderr.on("data",e=>{let t=String(e);s+=t,r.onStderrChunk?.(t)}),o.on("error",r=>{"ENOENT"===r.code?i(new E("TOOL_MISSING",`${e} not found in PATH`,{cmd:e},r)):i(new E("COMMAND_FAILED",`Failed to run ${e}`,{cmd:e,args:t},r))}),o.on("close",o=>{let d=o??1;0===d||r.allowFailure?n({stdout:a,stderr:s,exitCode:d,stdoutBuffer:l}):i(new E("COMMAND_FAILED",`${e} exited with code ${d}`,{cmd:e,args:t,stdout:a,stderr:s,exitCode:d,processExitError:!0}))})})}function en(e,t,r={}){let n=p(e,t,{cwd:r.cwd,env:r.env,stdio:["ignore","pipe","pipe"],detached:r.detached}),i="",o="";n.stdout.setEncoding("utf8"),n.stderr.setEncoding("utf8"),n.stdout.on("data",e=>{i+=e}),n.stderr.on("data",e=>{o+=e});let a=new Promise((a,s)=>{n.on("error",r=>{"ENOENT"===r.code?s(new E("TOOL_MISSING",`${e} not found in PATH`,{cmd:e},r)):s(new E("COMMAND_FAILED",`Failed to run ${e}`,{cmd:e,args:t},r))}),n.on("close",n=>{let l=n??1;0===l||r.allowFailure?a({stdout:i,stderr:o,exitCode:l}):s(new E("COMMAND_FAILED",`${e} exited with code ${l}`,{cmd:e,args:t,stdout:i,stderr:o,exitCode:l,processExitError:!0}))})});return{child:n,wait:a}}function ei(e){if(!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t}let eo=[/(^|[\/\s"'=])dist\/src\/daemon\.js($|[\s"'])/,/(^|[\/\s"'=])src\/daemon\.ts($|[\s"'])/];function ea(e){if(!Number.isInteger(e)||e<=0)return!1;try{return process.kill(e,0),!0}catch(e){return"EPERM"===e.code}}function es(e){if(!Number.isInteger(e)||e<=0)return null;try{let t=ee("ps",["-p",String(e),"-o","lstart="],{allowFailure:!0,timeoutMs:1e3});if(0!==t.exitCode)return null;let r=t.stdout.trim();return r.length>0?r:null}catch{return null}}function el(e){if(!Number.isInteger(e)||e<=0)return null;try{let t=ee("ps",["-p",String(e),"-o","command="],{allowFailure:!0,timeoutMs:1e3});if(0!==t.exitCode)return null;let r=t.stdout.trim();return r.length>0?r:null}catch{return null}}function ed(e,t){let r;if(!ea(e))return!1;if(t){let r=es(e);if(!r||r!==t)return!1}let n=el(e);return!!n&&!!(r=n.toLowerCase().replaceAll("\\","/")).includes("agent-device")&&eo.some(e=>e.test(r))}function eu(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 ec(e,t){if(!ea(e))return!0;let r=Date.now();for(;Date.now()-r<t;)if(await new Promise(e=>setTimeout(e,50)),!ea(e))return!0;return!ea(e)}async function ep(e,t){!ed(e,t.expectedStartTime)||!eu(e,"SIGTERM")||await ec(e,t.termTimeoutMs)||eu(e,"SIGKILL")&&await ec(e,t.killTimeoutMs)}function ef(e){return e?.HOME?.trim()||a.homedir()}function em(e,t={}){return"~"===e?ef(t.env):e.startsWith("~/")?s.join(ef(t.env),e.slice(2)):e}function eh(e,t={}){let r=em(e,t);return s.isAbsolute(r)?r:s.resolve(t.cwd??process.cwd(),r)}function eg(e){let t,r=(t=(e??"").trim())?eh(t):s.join(em("~"),".agent-device");return{baseDir:r,infoPath:s.join(r,"daemon.json"),lockPath:s.join(r,"daemon.lock"),logPath:s.join(r,"daemon.log"),sessionsDir:s.join(r,"sessions")}}function ew(e){let t=(e??"").trim().toLowerCase();return"http"===t?"http":"dual"===t?"dual":"socket"}function eI(e){let t=(e??"").trim().toLowerCase();return"auto"===t?"auto":"socket"===t?"socket":"http"===t?"http":"auto"}function eS(e){return"tenant"===(e??"").trim().toLowerCase()?"tenant":"none"}function ev(e){if(!e)return;let t=e.trim();if(t&&/^[a-zA-Z0-9._-]{1,128}$/.test(t))return t}let ey=100,eA=new Set(["batch","replay"]),eb=new Set(["command","positionals","flags","runtime"]);function eE(e){let t;try{t=JSON.parse(e)}catch{throw new E("INVALID_ARGS","Batch steps must be valid JSON.")}if(!Array.isArray(t)||0===t.length)throw new E("INVALID_ARGS","Batch steps must be a non-empty JSON array.");return t}function e$(e,t){if(!Array.isArray(e)||0===e.length)throw new E("INVALID_ARGS","batch requires a non-empty batchSteps array.");if(e.length>t)throw new E("INVALID_ARGS",`batch has ${e.length} steps; max allowed is ${t}.`);let r=[];for(let t=0;t<e.length;t+=1){let n=e[t];if(!n||"object"!=typeof n)throw new E("INVALID_ARGS",`Invalid batch step at index ${t}.`);let i=Object.keys(n).filter(e=>!eb.has(e));if(i.length>0){let e=i.map(e=>`"${e}"`).join(", ");throw new E("INVALID_ARGS",`Batch step ${t+1} has unknown field(s): ${e}. Allowed fields: command, positionals, flags, runtime.`)}let o="string"==typeof n.command?n.command.trim().toLowerCase():"";if(!o)throw new E("INVALID_ARGS",`Batch step ${t+1} requires command.`);if(eA.has(o))throw new E("INVALID_ARGS",`Batch step ${t+1} cannot run ${o}.`);if(void 0!==n.positionals&&!Array.isArray(n.positionals))throw new E("INVALID_ARGS",`Batch step ${t+1} positionals must be an array.`);let a=n.positionals??[];if(a.some(e=>"string"!=typeof e))throw new E("INVALID_ARGS",`Batch step ${t+1} positionals must contain only strings.`);if(void 0!==n.flags&&("object"!=typeof n.flags||Array.isArray(n.flags)||!n.flags))throw new E("INVALID_ARGS",`Batch step ${t+1} flags must be an object.`);if(void 0!==n.runtime&&("object"!=typeof n.runtime||Array.isArray(n.runtime)||!n.runtime))throw new E("INVALID_ARGS",`Batch step ${t+1} runtime must be an object.`);r.push({command:o,positionals:a,flags:n.flags??{},runtime:n.runtime})}return r}function eN(e){let t=e.appId??e.bundleId??e.packageName;return{session:e.session,appId:t,appBundleId:e.bundleId,package:e.packageName}}function eD(e,t,r){return{deviceId:t,deviceName:r,..."android"===e?{serial:t}:"ios"===e?{udid:t}:{}}}function ex(e,t={}){let r=t.includeAndroidSerial??!0;return{platform:e.platform,target:e.target,device:e.name,id:e.id,..."ios"===e.platform?{device_udid:e.ios?.udid??e.id,ios_simulator_device_set:e.ios?.simulatorSetPath??null}:{},..."android"===e.platform&&r?{serial:e.android?.serial??e.id}:{}}}function e_(e){return{name:e.name,...ex(e.device,{includeAndroidSerial:!1}),createdAt:e.createdAt}}function eT(e){return{platform:e.platform,id:e.id,name:e.name,kind:e.kind,target:e.target,..."boolean"==typeof e.booted?{booted:e.booted}:{}}}function eL(e){let t=e.created?"Created":"Reused",r=e.booted?" (booted)":"";return X({udid:e.udid,device:e.device,runtime:e.runtime,ios_simulator_device_set:e.iosSimulatorDeviceSet??null,created:e.created,booted:e.booted},`${t}: ${e.device} ${e.udid}${r}`)}function eO(e){return e.bundleId??e.package??e.app}function eM(e){return X({app:e.app,appPath:e.appPath,platform:e.platform,...e.appId?{appId:e.appId}:{},...e.bundleId?{bundleId:e.bundleId}:{},...e.package?{package:e.package}:{}},`Installed: ${eO(e)}`)}function eC(e){return e.appName??e.bundleId??e.packageName??e.launchTarget}function ek(e){return X({launchTarget:e.launchTarget,...e.appName?{appName:e.appName}:{},...e.appId?{appId:e.appId}:{},...e.bundleId?{bundleId:e.bundleId}:{},...e.packageName?{package:e.packageName}:{},...e.installablePath?{installablePath:e.installablePath}:{},...e.archivePath?{archivePath:e.archivePath}:{},...e.materializationId?{materializationId:e.materializationId}:{},...e.materializationExpiresAt?{materializationExpiresAt:e.materializationExpiresAt}:{}},`Installed: ${eC(e)}`)}function eP(e){let t=e.appName??e.appBundleId??e.session;return X({session:e.session,...e.appName?{appName:e.appName}:{},...e.appBundleId?{appBundleId:e.appBundleId}:{},...e.startup?{startup:e.startup}:{},...e.runtime?{runtime:e.runtime}:{},...e.device?ex(e.device):{}},t?`Opened: ${t}`:"Opened")}function eR(e){return{session:e.session,...e.shutdown?{shutdown:e.shutdown}:{},...K(e.session?`Closed: ${e.session}`:"Closed")}}function eF(e){return{nodes:e.nodes,truncated:e.truncated,...e.appName?{appName:e.appName}:{},...e.appBundleId?{appBundleId:e.appBundleId}:{}}}function eB(e,t){try{return l.sync.read(e)}catch(e){throw new E("COMMAND_FAILED",`Failed to decode ${t} as PNG`,{label:t,reason:e instanceof Error?e.message:String(e)})}}export{TextDecoder,styleText}from"node:util";export{default as node_net}from"node:net";export{default as node_http}from"node:http";export{default as node_https}from"node:https";export{E as AppError,ey as DEFAULT_BATCH_MAX_STEPS,l as PNG,P as SESSION_SURFACES,k as SETTINGS_INVALID_ARGS_MESSAGE,C as SETTINGS_USAGE_OVERRIDE,$ as asAppError,eN as buildAppIdentifiers,eD as buildDeviceIdentifiers,G as buildSnapshotDisplayLines,r as createHash,w as createRequestId,eB as decodePng,U as displayLabel,v as emitDiagnostic,i as existsSync,em as expandUserHomePath,d as external_node_url_URL,F as extractReadableText,u as fileURLToPath,W as findProjectRoot,A as flushDiagnosticsToSessionFile,V as formatRole,z as formatSnapshotLine,S as getDiagnosticsMeta,ed as isAgentDeviceDaemonProcess,ea as isProcessAlive,t as node_crypto,n as node_fs,a as node_os,s as node_path,N as normalizeError,ev as normalizeTenantId,eE as parseBatchStepsJson,R as parseSessionSurface,c as pathToFileURL,o as promises,Z as readCommandMessage,el as readProcessCommand,es as readProcessStartTime,J as readVersion,eg as resolveDaemonPaths,ew as resolveDaemonServerMode,eI as resolveDaemonTransportPreference,eO as resolveDeployResultTarget,eC as resolveInstallFromSourceResultTarget,eS as resolveSessionIsolationMode,eh as resolveUserPath,Q as runCmd,en as runCmdBackground,et as runCmdDetached,er as runCmdStreaming,ee as runCmdSync,eR as serializeCloseResult,eM as serializeDeployResult,eT as serializeDevice,eL as serializeEnsureSimulatorResult,ek as serializeInstallFromSourceResult,eP as serializeOpenResult,e_ as serializeSessionListEntry,eF as serializeSnapshotResult,p as spawn,ep as stopProcessForTakeover,K as successText,e$ as validateAndNormalizeBatchSteps,Y as whichCmd,y as withDiagnosticTimer,I as withDiagnosticsScope,X as withSuccessText};