agent-device 0.20.0 → 0.20.2
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/README.md +2 -3
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.0.apk → agent-device-android-ime-helper-0.20.2.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.2.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.0.manifest.json → agent-device-android-ime-helper-0.20.2.manifest.json} +4 -4
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.0.apk → agent-device-android-snapshot-helper-0.20.2.apk} +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.2.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.0.manifest.json → agent-device-android-snapshot-helper-0.20.2.manifest.json} +6 -6
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +2 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +30 -16
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +1 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +0 -21
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +8 -3
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Orientation.swift +92 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +4 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +1 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +2 -1
- package/dist/src/agent-device-client.js +2 -2
- package/dist/src/android-input-method-overlays.js +1 -1
- package/dist/src/android.js +1 -1
- package/dist/src/app-lifecycle.js +5 -5
- package/dist/src/app-log-request-scope.js +1 -1
- package/dist/src/app-resolution.js +1 -1
- package/dist/src/apple-multitouch-support.js +1 -1
- package/dist/src/apps.js +5 -5
- package/dist/src/boot-diagnostics.js +2 -2
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +81 -24
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +14 -14
- package/dist/src/click-button.d.ts +5 -0
- package/dist/src/client-metro.js +1 -0
- package/dist/src/command-metadata.js +1 -1
- package/dist/src/command-schema.js +3 -3
- package/dist/src/compatibility-policy.js +1 -0
- package/dist/src/context.js +1 -1
- package/dist/src/contracts.d.ts +2 -2
- package/dist/src/debug-symbols.js +1 -1
- package/dist/src/device-input-state.js +1 -1
- package/dist/src/device.js +9 -0
- package/dist/src/devices2.js +1 -1
- package/dist/src/devices4.js +1 -0
- package/dist/src/find.js +1 -1
- package/dist/src/finders.js +1 -1
- package/dist/src/generic.js +1 -1
- package/dist/src/gesture-plan-types.js +1 -0
- package/dist/src/gesture-plan.js +1 -0
- package/dist/src/index.d.ts +1205 -1309
- package/dist/src/input-actions.js +4 -4
- package/dist/src/install-artifact.js +5 -1
- package/dist/src/install-artifact2.js +1 -0
- package/dist/src/interaction-snapshot.js +1 -1
- package/dist/src/interaction.d.ts +3 -6
- package/dist/src/interaction.js +1 -1
- package/dist/src/interactor.js +2 -2
- package/dist/src/interactor2.js +1 -0
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +14 -22
- package/dist/src/lease-context.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/limrun.d.ts +361 -0
- package/dist/src/limrun.js +1 -0
- package/dist/src/linux.js +1 -1
- package/dist/src/logcat.js +1 -5
- package/dist/src/method-scope.js +1 -0
- package/dist/src/metro.d.ts +72 -3
- package/dist/src/metro.js +1 -1
- package/dist/src/metro2.js +1 -1
- package/dist/src/notifications.js +1 -1
- package/dist/src/physical-device-control.js +1 -0
- package/dist/src/plist.js +1 -0
- package/dist/src/react-native.js +1 -1
- package/dist/src/recording-export-quality.js +15 -0
- package/dist/src/register-builtins.js +1 -1
- package/dist/src/registry.js +24 -24
- package/dist/src/remote-config.d.ts +5 -2
- package/dist/src/remote-config.js +1 -1
- package/dist/src/remote-config2.js +1 -0
- package/dist/src/reporting.js +8 -8
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-disposal.js +1 -2
- package/dist/src/runner-lease.js +1 -1
- package/dist/src/runner-provider.js +1 -1
- package/dist/src/runtime-transport.js +1 -1
- package/dist/src/runtime.js +3 -3
- package/dist/src/runtime2.js +1 -1
- package/dist/src/sdk-android-adb.d.ts +4 -24
- package/dist/src/sdk-android-adb.js +4 -4
- package/dist/src/sdk-batch-runner.d.ts +13 -3
- package/dist/src/sdk-batch-runner.js +3 -2
- package/dist/src/sdk-contracts.d.ts +31 -91
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-device.js +1 -1
- package/dist/src/sdk-finders.d.ts +3 -2
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-remote-config.d.ts +83 -53
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selector-vocabulary.js +1 -1
- package/dist/src/selectors.d.ts +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/server.js +2 -2
- package/dist/src/session-target-evidence.js +1 -1
- package/dist/src/session.js +8 -8
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-diagnostics.js +4 -4
- package/dist/src/snapshot2.js +1 -1
- package/dist/src/tool-provider.js +3 -3
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/tool-provider3.js +1 -0
- package/dist/src/tv-remote.d.ts +213 -0
- package/dist/src/unsupported-interactor.js +1 -0
- package/dist/src/web.js +1 -1
- package/dist/src/xml.js +2 -0
- package/package.json +41 -19
- package/server.json +2 -2
- package/skills/agent-device/SKILL.md +5 -3
- package/smithery.yaml +1 -1
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.0.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.0.apk.sha256 +0 -1
- package/dist/src/android-system-chrome.js +0 -1
- package/dist/src/client-metro-companion.js +0 -1
- package/dist/src/config.js +0 -1
- package/dist/src/daemon-shutdown-report.js +0 -1
- package/dist/src/project-runtime.js +0 -1
- package/dist/src/scoped-provider.js +0 -1
- package/dist/src/sdk-batch.js +0 -2
- package/dist/src/snapshot-quality.js +0 -1
- package/dist/src/tv-remote.js +0 -15
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime.js";import{T as t,_ as n}from"./sdk-contracts.js";import{AsyncLocalStorage as r}from"node:async_hooks";import i from"node:crypto";import a,{constants as o}from"node:fs";import s from"node:os";import c from"node:path";import{pipeline as l}from"node:stream/promises";import{Readable as u}from"node:stream";import{access as d,stat as f}from"node:fs/promises";import{spawn as p,spawnSync as m}from"node:child_process";const h=new r;function g(){return i.randomBytes(8).toString(`hex`)}function ee(){return`${Date.now().toString(36)}-${i.randomBytes(4).toString(`hex`)}`}async function te(e,t){let n={...e,diagnosticId:ee(),events:[],liveWrittenEventCount:0,phaseCounts:new Map};return await h.run(n,t)}function
|
|
2
|
-
`)}\n`)}let
|
|
3
|
-
`)}\n`),n.events=[],l}catch{return null}}function se(e){return e.replace(/[^a-zA-Z0-9._-]/g,`_`)}function v(e,t){a.mkdirSync(c.dirname(e),{recursive:!0}),a.appendFileSync(e,t,`utf8`)}const ce=new Set([`1`,`true`,`yes`,`on`]),le=new Set([`0`,`false`,`no`,`off`]);function ue(e){return`AGENT_DEVICE_${e.replace(/([A-Z])/g,`_$1`).replace(/[^A-Za-z0-9_]/g,`_`).toUpperCase()}`}function de(e,t,r,i){if(e.multiple)return(Array.isArray(t)?t:[t]).map(t=>de({...e,multiple:!1},t,r,i));if(e.type===`boolean`)return fe(t,r,i);if(e.type===`booleanOrString`){if(typeof t==`boolean`)return t;if(typeof t==`string`&&y(t)!==void 0)return y(t);if(typeof t==`string`&&t.trim().length>0)return t;throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected boolean or non-empty string.`)}if(e.type===`string`){if(typeof t==`string`&&t.trim().length>0)return t;throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected non-empty string.`)}if(e.type===`enum`){if(e.setValue!==void 0)return pe(e,t,r,i);if(typeof t!=`string`||!e.enumValues?.includes(t))throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected one of: ${e.enumValues?.join(`, `)}.`);return t}let a=typeof t==`number`?t:typeof t==`string`?Number(t):NaN;if(!Number.isFinite(a)||!Number.isInteger(a))throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected integer.`);if(typeof e.min==`number`&&a<e.min)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Must be >= ${e.min}.`);if(typeof e.max==`number`&&a>e.max)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Must be <= ${e.max}.`);return a}function fe(e,t,r){if(typeof e==`boolean`)return e;if(typeof e==`string`){let t=y(e);if(t!==void 0)return t}throw new n(`INVALID_ARGS`,`Invalid value for "${r}" in ${t}. Expected boolean.`)}function y(e){let t=e.trim().toLowerCase();if(ce.has(t))return!0;if(le.has(t))return!1}function pe(e,t,r,i){let a=e.setValue;if(t===a)return a;if(typeof t==`string`){let e=t.trim();if(e===``||e===`true`||e===`1`)return a;if(e===`false`||e===`0`)return}if(t===!0)return a;if(t!==!1)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected boolean-like value for enum flag.`)}const me=/^[A-Za-z0-9][A-Za-z0-9._+-]*$/,he=[`.com`,`.exe`,`.bat`,`.cmd`],b=new r;async function ge(e,t){return e?await b.run(e,t):await t()}async function x(e){return await b.run(void 0,e)}async function S(e,t,n={}){let r=b.getStore()?.(e,t,n);return r?C(await r):await w(e,t,n)}async function _e(e,t,n={}){let r=b.getStore()?.(e,t,n);return r?C(await r):await w(e,t,n)}function C(e){let t=typeof e.stdout==`string`?e.stdout:String(e.stdout??``),n=typeof e.stderr==`string`?e.stderr:String(e.stderr??``),r=typeof e.exitCode==`number`?e.exitCode:1;return t===e.stdout&&n===e.stderr&&r===e.exitCode?e:{...e,stdout:t,stderr:n,exitCode:r}}function w(e,t,n={}){let r=k(e),i=D();return new Promise((a,o)=>{let s=p(r,t,{cwd:n.cwd,env:n.env,stdio:[`pipe`,`pipe`,`pipe`],detached:n.detached,windowsHide:!0,shell:!1});n.onSpawn?.(s);let c=``,l=n.binaryStdout?[]:void 0,u=``,d=!1,f=V(n.timeoutMs),m=f?setTimeout(()=>{d=!0,U(s,n.detached)},f):null,h=H(s,n);n.binaryStdout||s.stdout.setEncoding(`utf8`),s.stderr.setEncoding(`utf8`),Ae(s,n.stdin).catch(i=>{h.didAbort||d||je(i)||(o(Te(r,e,t,i)),U(s,n.detached))}),s.stdout.on(`data`,e=>{if(n.binaryStdout){l?.push(Buffer.isBuffer(e)?e:Buffer.from(e));return}let t=String(e);c+=t,n.onStdoutChunk?.(t)}),s.stderr.on(`data`,e=>{let t=String(e);u+=t,n.onStderrChunk?.(t)}),s.on(`error`,n=>{m&&clearTimeout(m),h.dispose(),i.emitForegroundCompletion(e,t),o(F(h,r,e,t,n))}),s.on(`close`,s=>{m&&clearTimeout(m),h.dispose(),i.emitForegroundCompletion(e,t);let p=s??1;if(!h.didAbort&&d&&f){o(Ee(r,e,t,f,p,c,u));return}let g=I(h,r,e,t,p,n.allowFailure,c,u);if(g){o(g);return}a({stdout:c,stderr:u,exitCode:p,stdoutBuffer:l?Buffer.concat(l):void 0})})})}async function ve(e){let t=R(e);if(!t)return!1;if(c.isAbsolute(t))return z(t);let n=process.env.PATH;if(!n)return!1;let r=Oe();for(let e of n.split(c.delimiter)){let n=e.trim();if(n){for(let e of ke(t,r))if(await z(c.join(n,e)))return!0}}return!1}async function ye(e,t){let r=L(e,t,`executable`);if(r){if(!await z(r))throw new n(`TOOL_MISSING`,`${t} points to a missing or non-executable file: ${r}`,{envName:t,path:r});return r}}async function be(e,t){let r=L(e,t,`file`);if(r){if(!await B(r))throw new n(`TOOL_MISSING`,`${t} points to a missing or non-file path: ${r}`,{envName:t,path:r});return r}}function xe(e,t,r={}){let i=k(e),a=m(i,t,{cwd:r.cwd,env:r.env,stdio:[`pipe`,`pipe`,`pipe`],encoding:r.binaryStdout?void 0:`utf8`,input:r.stdin,timeout:V(r.timeoutMs),windowsHide:!0,shell:!1,...r.maxBuffer===void 0?{}:{maxBuffer:r.maxBuffer}});if(a.error){let o=a.error.code;throw o===`ETIMEDOUT`?new n(`COMMAND_FAILED`,`${i} timed out after ${V(r.timeoutMs)}ms`,{cmd:e,args:t,timeoutMs:V(r.timeoutMs)},a.error):o===`ENOENT`?A(i,e,a.error):j(i,e,t,a.error)}let o=r.binaryStdout?Buffer.isBuffer(a.stdout)?a.stdout:Buffer.from(a.stdout??``):void 0,s=r.binaryStdout?``:typeof a.stdout==`string`?a.stdout:(a.stdout??``).toString(),c=typeof a.stderr==`string`?a.stderr:(a.stderr??``).toString(),l=a.status??1;if(l!==0&&!r.allowFailure)throw N(i,e,t,l,s,c);return{stdout:s,stderr:c,exitCode:l,stdoutBuffer:o}}function Se(e,t,n={}){return T(e,t,n).pid}function T(e,t,n={}){let r=p(k(e),t,{cwd:n.cwd,env:n.env,stdio:n.stdio??`ignore`,detached:!0,windowsHide:!0,shell:!1}),i=r.pid??0,a=new Promise(e=>{r.once(`error`,t=>{e({pid:i,error:t.message})}),r.once(`exit`,(t,n)=>{e({pid:i,...typeof t==`number`?{exitCode:t}:{},...n?{signal:n}:{}})})});return r.unref(),{pid:i,exited:a}}function E(e,t,n={}){let r=k(e),i=D(),a=p(r,t,{cwd:n.cwd,env:n.env,stdio:n.stdio??[`ignore`,`pipe`,`pipe`],detached:n.detached,windowsHide:!0,shell:!1});i.emitBackgroundSpawn(e,t);let o=``,s=``,c=n.captureOutput??!0,l=H(a,n);return c&&(a.stdout?.setEncoding(`utf8`),a.stderr?.setEncoding(`utf8`),a.stdout?.on(`data`,e=>{o+=e}),a.stderr?.on(`data`,e=>{s+=e})),{child:a,wait:new Promise((c,u)=>{a.on(`error`,n=>{l.dispose(),i.emitBackgroundCompletion(e,t,`error`),u(F(l,r,e,t,n))}),a.on(`close`,a=>{l.dispose(),i.emitBackgroundCompletion(e,t,`exit`);let d=a??1,f=I(l,r,e,t,d,n.allowFailure,o,s);if(f){u(f);return}c({stdout:o,stderr:s,exitCode:d})})})}}function D(){let e=re(),t=e.debug===!0,n=y(process.env.AGENT_DEVICE_EXEC_TRACE??``)===!0;if(!t&&!n)return Ce();n&&e.flushOnSuccess!==!0&&ne({flushOnSuccess:!0});let r=Date.now(),i=!1;return{emitForegroundCompletion:(e,t)=>{i||(i=!0,O({cmd:e,args:t,startedAtMs:r}))},emitBackgroundSpawn:(e,t)=>{O({cmd:e,args:t,data:{event:`spawn`}})},emitBackgroundCompletion:(e,t,n)=>{i||(i=!0,O({cmd:e,args:t,startedAtMs:r,data:{event:n}}))}}}function Ce(){return{emitForegroundCompletion:()=>{},emitBackgroundSpawn:()=>{},emitBackgroundCompletion:()=>{}}}function O(e){let t=e.args.slice(0,6);_({level:`debug`,phase:`exec_command`,durationMs:e.startedAtMs===void 0?void 0:Math.max(0,Date.now()-e.startedAtMs),data:{command:e.cmd,argsPrefix:t,...e.args.length>t.length?{omittedArgCount:e.args.length-t.length}:{},...e.data??{}}})}function k(e){let t=R(e);if(!t)throw new n(`INVALID_ARGS`,`Invalid executable command: ${JSON.stringify(e)}`,{cmd:e,hint:`Use a bare command name from PATH or an absolute executable path.`});return t}function we(e,t,n,r){return r.code===`ENOENT`?A(e,t,r):j(e,t,n,r)}function A(e,t,r){return new n(`TOOL_MISSING`,`${e} not found in PATH`,{cmd:t},r)}function j(e,t,r,i){return new n(`COMMAND_FAILED`,`Failed to run ${e}`,{cmd:t,args:r},i)}function Te(e,t,r,i){return new n(`COMMAND_FAILED`,`Failed to write stdin for ${e}`,{cmd:t,args:r},i instanceof Error?i:void 0)}function M(e,t,r){return new n(`COMMAND_FAILED`,`request canceled`,{cmd:t,args:r,executable:e,reason:`request_canceled`})}function Ee(e,t,r,i,a,o,s){return new n(`COMMAND_FAILED`,`${e} timed out after ${i}ms`,{cmd:t,args:r,stdout:o,stderr:s,exitCode:a,timeoutMs:i})}function N(e,t,r,i,a,o){return new n(`COMMAND_FAILED`,`${e} exited with code ${i}`,P({stdout:a,stderr:o,exitCode:i},{cmd:t,args:r}))}function De(e,t,r){if(e.exitCode===0)return e;throw new n(`COMMAND_FAILED`,t,P(e,typeof r==`function`?r(e):r))}function P(e,t){return{stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode,processExitError:!0,...t}}function F(e,t,n,r,i){return e.didAbort?M(t,n,r):we(t,n,r,i)}function I(e,t,n,r,i,a,o,s){return e.didAbort?M(t,n,r):i!==0&&!a?N(t,n,r,i,o,s):null}function L(e,t,r){let i=e?.trim();if(i){if(!c.isAbsolute(i)||i.includes(`\0`))throw new n(`INVALID_ARGS`,`${t} must be an absolute ${r} path, not ${JSON.stringify(e)}`,{envName:t,path:e});return i}}function R(e){let t=e.trim();return!t||t.includes(`\0`)?null:c.isAbsolute(t)?t:t.includes(`/`)||t.includes(`\\`)?null:me.test(t)?t:null}function Oe(){if(process.platform!==`win32`)return[``];let e=process.env.PATHEXT;if(!e)return he;let t=e.split(`;`).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0);return t.length>0?t:he}function ke(e,t){if(process.platform!==`win32`)return[e];let n=e.toLowerCase();return t.some(e=>n.endsWith(e))?[e]:t.map(t=>`${e}${t}`)}async function z(e){try{return await B(e)?(await d(e,process.platform===`win32`?o.F_OK:o.X_OK),!0):!1}catch{return!1}}async function B(e){try{return(await f(e)).isFile()}catch{return!1}}function V(e){if(!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t}function H(e,t){let n=!1,r=()=>{n=!0,U(e,t.detached)};return t.signal?.aborted?r():t.signal?.addEventListener(`abort`,r,{once:!0}),{get didAbort(){return n},dispose:()=>{t.signal?.removeEventListener(`abort`,r)}}}function U(e,t){if(t&&e.pid&&process.platform!==`win32`)try{process.kill(-e.pid,`SIGKILL`);return}catch{}e.kill(`SIGKILL`)}async function Ae(e,t){if(e.stdin){if(t===void 0){e.stdin?.end();return}await l(u.from([t]),e.stdin)}}function je(e){return e instanceof Error&&`code`in e&&e.code===`EPIPE`}var Me=e({androidAdbResultError:()=>q,attachAdbFailureHint:()=>K,classifyAdbFailure:()=>G,createAndroidPortReverseManager:()=>Ue,createDeviceAdbExecutor:()=>X,createLocalAndroidAdbProvider:()=>Be,installAndroidAdbPackage:()=>Ge,pullAndroidAdbFile:()=>We,resolveAndroidAdbExecutor:()=>Ve,resolveAndroidAdbProvider:()=>Z,resolveAndroidTextInjector:()=>He,resolveAndroidTouchProvider:()=>Q,withAndroidAdbProvider:()=>qe});const W=new r,Ne=[{reason:`device_unauthorized`,pattern:/device unauthorized|device still authorizing/,hint:`USB debugging is not authorized — accept the authorization prompt on the device screen (re-plug the cable if none appears), then retry.`},{reason:`device_offline`,pattern:/device offline/,hint:`The device is connected but offline — wait for it to finish booting or run adb reconnect, then retry.`,retriable:!0},{reason:`multiple_devices`,pattern:/more than one (?:device\/emulator|device and emulator)/,hint:`Multiple Android devices are connected — pass --serial <serial> (see adb devices) to select one.`},{reason:`no_devices`,pattern:/no devices\/emulators found|no devices found/,hint:`No Android devices detected — boot an emulator or connect a device and verify it appears in adb devices.`},{reason:`device_not_found`,pattern:/device (?:'[^']*' )?not found/,hint:`The device disconnected or is restarting — verify it is listed in adb devices, then retry.`,retriable:!0},{reason:`server_version_mismatch`,pattern:/adb server version \(\d+\) doesn't match this client/,hint:`Multiple adb installs conflict — adb restarts its server automatically, so retry; align PATH to a single adb to stop recurrences.`,retriable:!0},{reason:`connection_dropped`,pattern:/transport error|connection reset|broken pipe|protocol fault/,hint:`The adb connection dropped — retry; if it persists, run adb kill-server and reconnect the device.`,retriable:!0},{reason:`install_insufficient_storage`,pattern:/install_failed_insufficient_storage/,hint:`The device is out of storage — free up space or uninstall unused apps, then retry the install.`,matchStdout:!0},{reason:`install_update_incompatible`,pattern:/install_failed_update_incompatible/,hint:`The installed app has an incompatible signature — uninstall the existing app first, then retry the install.`,matchStdout:!0},{reason:`install_version_downgrade`,pattern:/install_failed_version_downgrade/,hint:`The APK is older than the installed app — uninstall the app first (or install with downgrade allowed), then retry.`,matchStdout:!0},{reason:`install_failed`,pattern:/install_failed_\w+|install_parse_failed_\w+/,hint:`The Android package installer rejected the APK — see the INSTALL_FAILED code in the error output for the exact cause.`,matchStdout:!0}],Pe={reason:`timeout`,hint:`adb timed out — the adb server may be wedged. Run adb kill-server && adb start-server, check adb devices, then retry.`};function G(e,t=``){let n=e.toLowerCase(),r=t.toLowerCase();for(let{pattern:e,matchStdout:t,...i}of Ne)if(e.test(n)||t&&e.test(r))return i}function K(e){if(!(e instanceof n)||e.code!==`COMMAND_FAILED`)return e;let t=Fe(e);return t&&(e.details={...e.details,adbFailure:t.reason,...typeof e.details?.hint==`string`?{}:{hint:t.hint},...t.retriable!==void 0&&e.details?.retriable===void 0?{retriable:t.retriable}:{}}),e}function Fe(e){return typeof e.details?.timeoutMs==`number`?Pe:G(typeof e.details?.stderr==`string`?e.details.stderr:``,typeof e.details?.stdout==`string`?e.details.stdout:``)}function q(e,t,r){return K(new n(`COMMAND_FAILED`,e,t.exitCode===0?{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode,...r}:P(t,r)))}function J(e){return async(...t)=>{try{return await e(...t)}catch(e){throw K(e)}}}const Ie=new WeakSet;function Le(e){if(Ie.has(e))return e;let t={...e,exec:J(Y(e.exec)),...e.pull?{pull:J(Y(e.pull))}:{},...e.install?{install:J(Y(e.install))}:{},...e.installBundle?{installBundle:J(e.installBundle)}:{}};return Ie.add(t),t}function Y(e){return async(...t)=>C(await e(...t))}function X(e){return Re(e.id)}function Re(e){return J(async(t,n)=>await x(async()=>await S(`adb`,[`-s`,e,...t],{...n,detached:process.platform!==`win32`})))}function ze(e){return(t,n)=>{let r=E(`adb`,[`-s`,e,...t],{...n,allowFailure:!0,captureOutput:!1});return r.wait.catch(()=>{}),r.child}}function Be(e){let t=X(e);return{exec:t,spawn:ze(e.id),reverse:Ze(t),pull:async(e,n,r)=>await t([`pull`,e,n],r),install:async(e,n)=>{let{installArgs:r,execOptions:i}=et(n);return await t([`install`,...r,e],i)}}}function Ve(e,t){let n=W.getStore();return t||(n?.serial===e.id?n.provider.exec:X(e))}function Z(e,t){if(t)return $(t);let n=W.getStore();return n?.serial===e.id?$(n.provider):Be(e)}function He(e){let t=W.getStore();return t?.serial===e.id?t.provider.text:void 0}function Q(e){let t=W.getStore();return t?.serial===e.id&&t.provider.touch?t.provider:void 0}function Ue(e){let t=$(e);if(t.reverse&&Xe.has(t.reverse))return t.reverse;let r=t.reverse??Ze(t.exec),i=new Map,a={async ensure(e,t){let a=i.get(e.local);if(a&&a.ownerId!==e.ownerId)throw new n(`COMMAND_FAILED`,`Android port reverse ${e.local} is already owned by ${a.ownerId??`another session`}`,{current:a,requested:e});a?.remote!==e.remote&&(await r.ensure(e,t),i.set(e.local,{...e}))},async remove(e,t){if(!i.has(e)){await r.remove(e,t);return}await r.remove(e,t),i.delete(e)},async removeAllOwned(e,t){let n=[...i.values()].filter(t=>t.ownerId===e).map(e=>e.local);if(n.length===0){await r.removeAllOwned(e,t);return}for(let e of n)await r.remove(e,t),i.delete(e)},async list(e){return r.list?await r.list(e):[...i.values()]}};return Xe.add(a),a}function $(e){return Le(typeof e==`function`?{exec:e}:e)}async function We(e,t,r){let{device:i,provider:a,...o}=r??{},s=Ke(i,a),c=s?.pull;if(c)return await x(async()=>await c(e,t,o));let l=s?.exec;if(!l)throw new n(`COMMAND_FAILED`,`Android adb pull requires an adb provider`);return await x(async()=>await l([`pull`,e,t],o))}async function Ge(e,t){let{device:r,provider:i,...a}=t??{},o=Ke(r,i),s=o?.install;if(s)return await x(async()=>await s(e,a));let c=o?.exec;if(!c)throw new n(`COMMAND_FAILED`,`Android adb install requires an adb provider`);let{installArgs:l,execOptions:u}=et(a);return await x(async()=>await c([`install`,...l,e],u))}function Ke(e,t){if(t)return $(t);if(e)return Z(e);let n=W.getStore();if(n)return $(n.provider)}async function qe(e,t,n){if(!e)return await n();let r={provider:$(e),serial:t.serial},i=Je(r);return await W.run(r,async()=>await ge(i,n))}function Je(e){return(t,n,r)=>{if(t!==`adb`)return;let i=Ye(n,e.serial);if(i)return x(async()=>await e.provider.exec(i,r))}}function Ye(e,t){if(!(e[0]!==`-s`||!e[1])&&e[1]===t)return e.slice(2)}const Xe=new WeakSet;function Ze(e){let t=new Map;return{async ensure(n,r){if(await e([`reverse`,n.local,n.remote],{allowFailure:!1,signal:r?.signal,timeoutMs:r?.timeoutMs}),n.ownerId){let e=t.get(n.ownerId)??new Set;e.add(n.local),t.set(n.ownerId,e)}},async remove(n,r){let i=await e([`reverse`,`--remove`,n],{allowFailure:!0,signal:r?.signal,timeoutMs:r?.timeoutMs});if(i.exitCode!==0&&!$e(i.stdout,i.stderr))throw q(`Failed to remove Android port reverse ${n}`,i,{local:n});for(let e of t.values())e.delete(n)},async removeAllOwned(e,n){let r=[...t.get(e)??[]];for(let e of r)await this.remove(e,n);t.delete(e)},async list(n){let r=await e([`reverse`,`--list`],{allowFailure:!0,signal:n?.signal,timeoutMs:n?.timeoutMs});return r.exitCode===0?Qe(r.stdout,t):[]}}}function Qe(e,t){let n=new Map;for(let[e,r]of t)for(let t of r)n.set(t,e);return e.split(`
|
|
4
|
-
`).map(e=>e.trim().split(/\s+/)).filter(e=>e.length>=3).map(([,e,t])=>{let r=e;return{local:r,remote:t,ownerId:n.get(r)}})}function
|
|
1
|
+
import{t as e}from"./rolldown-runtime.js";import{T as t,_ as n}from"./sdk-contracts.js";import{AsyncLocalStorage as r}from"node:async_hooks";import i from"node:crypto";import a,{constants as o}from"node:fs";import s from"node:os";import c from"node:path";import{pipeline as l}from"node:stream/promises";import{Readable as u}from"node:stream";import{access as d,stat as f}from"node:fs/promises";import{spawn as p,spawnSync as m}from"node:child_process";const h=new r;function g(){return i.randomBytes(8).toString(`hex`)}function ee(){return`${Date.now().toString(36)}-${i.randomBytes(4).toString(`hex`)}`}async function te(e,t){let n={...e,diagnosticId:ee(),events:[],liveWrittenEventCount:0,phaseCounts:new Map,sensitiveValues:new Set};return await h.run(n,t)}function _(e){let t=h.getStore();t&&Object.assign(t,e)}function ne(){let e=h.getStore();return e?{diagnosticId:e.diagnosticId,requestId:e.requestId,session:e.session,command:e.command,debug:e.debug,flushOnSuccess:e.flushOnSuccess}:{}}function re(e){e&&h.getStore()?.sensitiveValues.add(e)}function ie(e){let t=h.getStore();if(!t)return 0;let n=0;for(let r of e)n+=t.phaseCounts.get(r)??0;return n}function v(e){let t=h.getStore();if(!t)return;let n={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?y(t,e.data):void 0};if(t.events.push(n),t.phaseCounts.set(e.phase,(t.phaseCounts.get(e.phase)??0)+1),!t.debug&&!t.traceLogPath)return;let r=`${JSON.stringify(n)}\n`;try{t.debug&&t.logPath&&(x(t.logPath,r),t.liveWrittenEventCount=t.events.length),t.traceLogPath&&x(t.traceLogPath,r),t.debug&&!t.logPath&&!t.traceLogPath&&process.stderr.write(`[agent-device][diag] ${r}`)}catch{}}async function ae(e,t,n){let r=Date.now();try{let i=await t();return v({level:`info`,phase:e,durationMs:Date.now()-r,data:n}),i}catch(t){throw v({level:`error`,phase:e,durationMs:Date.now()-r,data:{...n??{},error:t instanceof Error?t.message:String(t)}}),t}}function oe(e={}){let t=h.getStore();if(!t||!e.force&&!t.debug&&!t.flushOnSuccess||t.events.length===0)return null;try{if(t.logPath){let e=t.events.slice(t.liveWrittenEventCount);if(e.length>0){let n=e.map(e=>JSON.stringify(y(t,e)));x(t.logPath,`${n.join(`
|
|
2
|
+
`)}\n`)}let n=t.logPath;return t.events=[],t.liveWrittenEventCount=0,n}let e=se(t.session??`default`),n=new Date().toISOString().slice(0,10),r=c.join(s.homedir(),`.agent-device`,`logs`,e,n);a.mkdirSync(r,{recursive:!0});let i=new Date().toISOString().replace(/[:.]/g,`-`),o=c.join(r,`${i}-${t.diagnosticId}.ndjson`),l=t.events.map(e=>JSON.stringify(y(t,e)));return a.writeFileSync(o,`${l.join(`
|
|
3
|
+
`)}\n`),t.events=[],o}catch{return null}}function y(e,n){return b(t(n),[...e.sensitiveValues].sort((e,t)=>t.length-e.length))}function b(e,t){return typeof e==`string`?t.reduce((e,t)=>e.replaceAll(t,`[REDACTED]`),e):Array.isArray(e)?e.map(e=>b(e,t)):!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,b(n,t)]))}function se(e){return e.replace(/[^a-zA-Z0-9._-]/g,`_`)}function x(e,t){a.mkdirSync(c.dirname(e),{recursive:!0}),a.appendFileSync(e,t,`utf8`)}const ce=new Set([`1`,`true`,`yes`,`on`]),le=new Set([`0`,`false`,`no`,`off`]);function ue(e){return`AGENT_DEVICE_${e.replace(/([A-Z])/g,`_$1`).replace(/[^A-Za-z0-9_]/g,`_`).toUpperCase()}`}function de(e,t,r,i){if(e.multiple)return(Array.isArray(t)?t:[t]).map(t=>de({...e,multiple:!1},t,r,i));if(e.type===`boolean`)return fe(t,r,i);if(e.type===`booleanOrString`){if(typeof t==`boolean`)return t;if(typeof t==`string`&&S(t)!==void 0)return S(t);if(typeof t==`string`&&t.trim().length>0)return t;throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected boolean or non-empty string.`)}if(e.type===`string`){if(typeof t==`string`&&t.trim().length>0)return t;throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected non-empty string.`)}if(e.type===`enum`){if(e.setValue!==void 0)return pe(e,t,r,i);if(typeof t!=`string`||!e.enumValues?.includes(t))throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected one of: ${e.enumValues?.join(`, `)}.`);return t}let a=typeof t==`number`?t:typeof t==`string`?Number(t):NaN;if(!Number.isFinite(a)||!Number.isInteger(a))throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected integer.`);if(typeof e.min==`number`&&a<e.min)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Must be >= ${e.min}.`);if(typeof e.max==`number`&&a>e.max)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Must be <= ${e.max}.`);return a}function fe(e,t,r){if(typeof e==`boolean`)return e;if(typeof e==`string`){let t=S(e);if(t!==void 0)return t}throw new n(`INVALID_ARGS`,`Invalid value for "${r}" in ${t}. Expected boolean.`)}function S(e){let t=e.trim().toLowerCase();if(ce.has(t))return!0;if(le.has(t))return!1}function pe(e,t,r,i){let a=e.setValue;if(t===a)return a;if(typeof t==`string`){let e=t.trim();if(e===``||e===`true`||e===`1`)return a;if(e===`false`||e===`0`)return}if(t===!0)return a;if(t!==!1)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected boolean-like value for enum flag.`)}const me=/^[A-Za-z0-9][A-Za-z0-9._+-]*$/,he=[`.com`,`.exe`,`.bat`,`.cmd`],C=new r;async function ge(e,t){return e?await C.run(e,t):await t()}async function w(e){return await C.run(void 0,e)}async function T(e,t,n={}){let r=C.getStore()?.(e,t,n);return r?E(await r):await D(e,t,n)}async function _e(e,t,n={}){let r=C.getStore()?.(e,t,n);return r?E(await r):await D(e,t,n)}function E(e){let t=typeof e.stdout==`string`?e.stdout:String(e.stdout??``),n=typeof e.stderr==`string`?e.stderr:String(e.stderr??``),r=typeof e.exitCode==`number`?e.exitCode:1;return t===e.stdout&&n===e.stderr&&r===e.exitCode?e:{...e,stdout:t,stderr:n,exitCode:r}}function D(e,t,n={}){let r=M(e),i=A();return new Promise((a,o)=>{let s=p(r,t,{cwd:n.cwd,env:n.env,stdio:[`pipe`,`pipe`,`pipe`],detached:n.detached,windowsHide:!0,shell:!1});n.onSpawn?.(s);let c=``,l=n.binaryStdout?[]:void 0,u=``,d=!1,f=H(n.timeoutMs),m=f?setTimeout(()=>{d=!0,U(s,n.detached)},f):null,h=Me(s,n);n.binaryStdout||s.stdout.setEncoding(`utf8`),s.stderr.setEncoding(`utf8`),Ne(s,n.stdin).catch(i=>{h.didAbort||d||Pe(i)||(o(Te(r,e,t,i)),U(s,n.detached))}),s.stdout.on(`data`,e=>{if(n.binaryStdout){l?.push(Buffer.isBuffer(e)?e:Buffer.from(e));return}let t=String(e);c+=t,n.onStdoutChunk?.(t)}),s.stderr.on(`data`,e=>{let t=String(e);u+=t,n.onStderrChunk?.(t)}),s.on(`error`,n=>{m&&clearTimeout(m),h.dispose(),i.emitForegroundCompletion(e,t),o(R(h,r,e,t,n))}),s.on(`close`,s=>{m&&clearTimeout(m),h.dispose(),i.emitForegroundCompletion(e,t);let p=s??1;if(!h.didAbort&&d&&f){o(Ee(r,e,t,f,p,c,u));return}let g=z(h,r,e,t,p,n.allowFailure,c,u);if(g){o(g);return}a({stdout:c,stderr:u,exitCode:p,stdoutBuffer:l?Buffer.concat(l):void 0})})})}async function ve(e){let t=Oe(e);if(!t)return!1;if(c.isAbsolute(t))return V(t);let n=process.env.PATH;if(!n)return!1;let r=ke();for(let e of n.split(c.delimiter)){let n=e.trim();if(n){for(let e of Ae(t,r))if(await V(c.join(n,e)))return!0}}return!1}async function ye(e,t){let r=B(e,t,`executable`);if(r){if(!await V(r))throw new n(`TOOL_MISSING`,`${t} points to a missing or non-executable file: ${r}`,{envName:t,path:r});return r}}async function be(e,t){let r=B(e,t,`file`);if(r){if(!await je(r))throw new n(`TOOL_MISSING`,`${t} points to a missing or non-file path: ${r}`,{envName:t,path:r});return r}}function xe(e,t,r={}){let i=M(e),a=m(i,t,{cwd:r.cwd,env:r.env,stdio:[`pipe`,`pipe`,`pipe`],encoding:r.binaryStdout?void 0:`utf8`,input:r.stdin,timeout:H(r.timeoutMs),windowsHide:!0,shell:!1,...r.maxBuffer===void 0?{}:{maxBuffer:r.maxBuffer}});if(a.error){let o=a.error.code;throw o===`ETIMEDOUT`?new n(`COMMAND_FAILED`,`${i} timed out after ${H(r.timeoutMs)}ms`,{cmd:e,args:t,timeoutMs:H(r.timeoutMs)},a.error):o===`ENOENT`?N(i,e,a.error):P(i,e,t,a.error)}let o=r.binaryStdout?Buffer.isBuffer(a.stdout)?a.stdout:Buffer.from(a.stdout??``):void 0,s=r.binaryStdout?``:typeof a.stdout==`string`?a.stdout:(a.stdout??``).toString(),c=typeof a.stderr==`string`?a.stderr:(a.stderr??``).toString(),l=a.status??1;if(l!==0&&!r.allowFailure)throw I(i,e,t,l,s,c);return{stdout:s,stderr:c,exitCode:l,stdoutBuffer:o}}function Se(e,t,n={}){return O(e,t,n).pid}function O(e,t,n={}){let r=p(M(e),t,{cwd:n.cwd,env:n.env,stdio:n.stdio??`ignore`,detached:!0,windowsHide:!0,shell:!1}),i=r.pid??0,a=new Promise(e=>{r.once(`error`,t=>{e({pid:i,error:t.message})}),r.once(`exit`,(t,n)=>{e({pid:i,...typeof t==`number`?{exitCode:t}:{},...n?{signal:n}:{}})})});return r.unref(),{pid:i,exited:a}}function k(e,t,n={}){let r=M(e),i=A(),a=p(r,t,{cwd:n.cwd,env:n.env,stdio:n.stdio??[`ignore`,`pipe`,`pipe`],detached:n.detached,windowsHide:!0,shell:!1});i.emitBackgroundSpawn(e,t);let o=``,s=``,c=n.captureOutput??!0,l=Me(a,n);return c&&(a.stdout?.setEncoding(`utf8`),a.stderr?.setEncoding(`utf8`),a.stdout?.on(`data`,e=>{o+=e}),a.stderr?.on(`data`,e=>{s+=e})),{child:a,wait:new Promise((c,u)=>{a.on(`error`,n=>{l.dispose(),i.emitBackgroundCompletion(e,t,`error`),u(R(l,r,e,t,n))}),a.on(`close`,a=>{l.dispose(),i.emitBackgroundCompletion(e,t,`exit`);let d=a??1,f=z(l,r,e,t,d,n.allowFailure,o,s);if(f){u(f);return}c({stdout:o,stderr:s,exitCode:d})})})}}function A(){let e=ne(),t=e.debug===!0,n=S(process.env.AGENT_DEVICE_EXEC_TRACE??``)===!0;if(!t&&!n)return Ce();n&&e.flushOnSuccess!==!0&&_({flushOnSuccess:!0});let r=Date.now(),i=!1;return{emitForegroundCompletion:(e,t)=>{i||(i=!0,j({cmd:e,args:t,startedAtMs:r}))},emitBackgroundSpawn:(e,t)=>{j({cmd:e,args:t,data:{event:`spawn`}})},emitBackgroundCompletion:(e,t,n)=>{i||(i=!0,j({cmd:e,args:t,startedAtMs:r,data:{event:n}}))}}}function Ce(){return{emitForegroundCompletion:()=>{},emitBackgroundSpawn:()=>{},emitBackgroundCompletion:()=>{}}}function j(e){let t=e.args.slice(0,6);v({level:`debug`,phase:`exec_command`,durationMs:e.startedAtMs===void 0?void 0:Math.max(0,Date.now()-e.startedAtMs),data:{command:e.cmd,argsPrefix:t,...e.args.length>t.length?{omittedArgCount:e.args.length-t.length}:{},...e.data??{}}})}function M(e){let t=Oe(e);if(!t)throw new n(`INVALID_ARGS`,`Invalid executable command: ${JSON.stringify(e)}`,{cmd:e,hint:`Use a bare command name from PATH or an absolute executable path.`});return t}function we(e,t,n,r){return r.code===`ENOENT`?N(e,t,r):P(e,t,n,r)}function N(e,t,r){return new n(`TOOL_MISSING`,`${e} not found in PATH`,{cmd:t},r)}function P(e,t,r,i){return new n(`COMMAND_FAILED`,`Failed to run ${e}`,{cmd:t,args:r},i)}function Te(e,t,r,i){return new n(`COMMAND_FAILED`,`Failed to write stdin for ${e}`,{cmd:t,args:r},i instanceof Error?i:void 0)}function F(e,t,r){return new n(`COMMAND_FAILED`,`request canceled`,{cmd:t,args:r,executable:e,reason:`request_canceled`})}function Ee(e,t,r,i,a,o,s){return new n(`COMMAND_FAILED`,`${e} timed out after ${i}ms`,{cmd:t,args:r,stdout:o,stderr:s,exitCode:a,timeoutMs:i})}function I(e,t,r,i,a,o){return new n(`COMMAND_FAILED`,`${e} exited with code ${i}`,L({stdout:a,stderr:o,exitCode:i},{cmd:t,args:r}))}function De(e,t,r){if(e.exitCode===0)return e;throw new n(`COMMAND_FAILED`,t,L(e,typeof r==`function`?r(e):r))}function L(e,t){return{stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode,processExitError:!0,...t}}function R(e,t,n,r,i){return e.didAbort?F(t,n,r):we(t,n,r,i)}function z(e,t,n,r,i,a,o,s){return e.didAbort?F(t,n,r):i!==0&&!a?I(t,n,r,i,o,s):null}function B(e,t,r){let i=e?.trim();if(i){if(!c.isAbsolute(i)||i.includes(`\0`))throw new n(`INVALID_ARGS`,`${t} must be an absolute ${r} path, not ${JSON.stringify(e)}`,{envName:t,path:e});return i}}function Oe(e){let t=e.trim();return!t||t.includes(`\0`)?null:c.isAbsolute(t)?t:t.includes(`/`)||t.includes(`\\`)?null:me.test(t)?t:null}function ke(){if(process.platform!==`win32`)return[``];let e=process.env.PATHEXT;if(!e)return he;let t=e.split(`;`).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0);return t.length>0?t:he}function Ae(e,t){if(process.platform!==`win32`)return[e];let n=e.toLowerCase();return t.some(e=>n.endsWith(e))?[e]:t.map(t=>`${e}${t}`)}async function V(e){try{return await je(e)?(await d(e,process.platform===`win32`?o.F_OK:o.X_OK),!0):!1}catch{return!1}}async function je(e){try{return(await f(e)).isFile()}catch{return!1}}function H(e){if(!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t}function Me(e,t){let n=!1,r=()=>{n=!0,U(e,t.detached)};return t.signal?.aborted?r():t.signal?.addEventListener(`abort`,r,{once:!0}),{get didAbort(){return n},dispose:()=>{t.signal?.removeEventListener(`abort`,r)}}}function U(e,t){if(t&&e.pid&&process.platform!==`win32`)try{process.kill(-e.pid,`SIGKILL`);return}catch{}e.kill(`SIGKILL`)}async function Ne(e,t){if(e.stdin){if(t===void 0){e.stdin?.end();return}await l(u.from([t]),e.stdin)}}function Pe(e){return e instanceof Error&&`code`in e&&e.code===`EPIPE`}var Fe=e({androidAdbResultError:()=>K,attachAdbFailureHint:()=>G,classifyAdbFailure:()=>Re,createAndroidPortReverseManager:()=>qe,createDeviceAdbExecutor:()=>Y,createLocalAndroidAdbProvider:()=>We,installAndroidAdbPackage:()=>Ye,pullAndroidAdbFile:()=>Je,resolveAndroidAdbExecutor:()=>Ge,resolveAndroidAdbProvider:()=>X,resolveAndroidTextInjector:()=>Ke,resolveAndroidTouchProvider:()=>Z,withAndroidAdbProvider:()=>Ze});const W=new r,Ie=[{reason:`device_unauthorized`,pattern:/device unauthorized|device still authorizing/,hint:`USB debugging is not authorized — accept the authorization prompt on the device screen (re-plug the cable if none appears), then retry.`},{reason:`device_offline`,pattern:/device offline/,hint:`The device is connected but offline — wait for it to finish booting or run adb reconnect, then retry.`,retriable:!0},{reason:`multiple_devices`,pattern:/more than one (?:device\/emulator|device and emulator)/,hint:`Multiple Android devices are connected — pass --serial <serial> (see adb devices) to select one.`},{reason:`no_devices`,pattern:/no devices\/emulators found|no devices found/,hint:`No Android devices detected — boot an emulator or connect a device and verify it appears in adb devices.`},{reason:`device_not_found`,pattern:/device (?:'[^']*' )?not found/,hint:`The device disconnected or is restarting — verify it is listed in adb devices, then retry.`,retriable:!0},{reason:`server_version_mismatch`,pattern:/adb server version \(\d+\) doesn't match this client/,hint:`Multiple adb installs conflict — adb restarts its server automatically, so retry; align PATH to a single adb to stop recurrences.`,retriable:!0},{reason:`connection_dropped`,pattern:/transport error|connection reset|broken pipe|protocol fault/,hint:`The adb connection dropped — retry; if it persists, run adb kill-server and reconnect the device.`,retriable:!0},{reason:`install_insufficient_storage`,pattern:/install_failed_insufficient_storage/,hint:`The device is out of storage — free up space or uninstall unused apps, then retry the install.`,matchStdout:!0},{reason:`install_update_incompatible`,pattern:/install_failed_update_incompatible/,hint:`The installed app has an incompatible signature — uninstall the existing app first, then retry the install.`,matchStdout:!0},{reason:`install_version_downgrade`,pattern:/install_failed_version_downgrade/,hint:`The APK is older than the installed app — uninstall the app first (or install with downgrade allowed), then retry.`,matchStdout:!0},{reason:`install_failed`,pattern:/install_failed_\w+|install_parse_failed_\w+/,hint:`The Android package installer rejected the APK — see the INSTALL_FAILED code in the error output for the exact cause.`,matchStdout:!0}],Le={reason:`timeout`,hint:`adb timed out — the adb server may be wedged. Run adb kill-server && adb start-server, check adb devices, then retry.`};function Re(e,t=``){let n=e.toLowerCase(),r=t.toLowerCase();for(let{pattern:e,matchStdout:t,...i}of Ie)if(e.test(n)||t&&e.test(r))return i}function G(e){if(!(e instanceof n)||e.code!==`COMMAND_FAILED`)return e;let t=ze(e);return t&&(e.details={...e.details,adbFailure:t.reason,...typeof e.details?.hint==`string`?{}:{hint:t.hint},...t.retriable!==void 0&&e.details?.retriable===void 0?{retriable:t.retriable}:{}}),e}function ze(e){return typeof e.details?.timeoutMs==`number`?Le:Re(typeof e.details?.stderr==`string`?e.details.stderr:``,typeof e.details?.stdout==`string`?e.details.stdout:``)}function K(e,t,r){return G(new n(`COMMAND_FAILED`,e,t.exitCode===0?{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode,...r}:L(t,r)))}function q(e){return async(...t)=>{try{return await e(...t)}catch(e){throw G(e)}}}const Be=new WeakSet;function Ve(e){if(Be.has(e))return e;let t={...e,exec:q(J(e.exec)),...e.pull?{pull:q(J(e.pull))}:{},...e.install?{install:q(J(e.install))}:{},...e.installBundle?{installBundle:q(e.installBundle)}:{}};return Be.add(t),t}function J(e){return async(...t)=>E(await e(...t))}function Y(e){return He(e.id)}function He(e){return q(async(t,n)=>await w(async()=>await T(`adb`,[`-s`,e,...t],{...n,detached:process.platform!==`win32`})))}function Ue(e){return(t,n)=>{let r=k(`adb`,[`-s`,e,...t],{...n,allowFailure:!0,captureOutput:!1});return r.wait.catch(()=>{}),r.child}}function We(e){let t=Y(e);return{exec:t,spawn:Ue(e.id),reverse:tt(t),pull:async(e,n,r)=>await t([`pull`,e,n],r),install:async(e,n)=>{let{installArgs:r,execOptions:i}=$(n);return await t([`install`,...r,e],i)}}}function Ge(e,t){let n=W.getStore();return t||(n?.serial===e.id?n.provider.exec:Y(e))}function X(e,t){if(t)return Q(t);let n=W.getStore();return n?.serial===e.id?Q(n.provider):We(e)}function Ke(e){let t=W.getStore();return t?.serial===e.id?t.provider.text:void 0}function Z(e){let t=W.getStore();return t?.serial===e.id&&t.provider.touch?t.provider:void 0}function qe(e){let t=Q(e);if(t.reverse&&et.has(t.reverse))return t.reverse;let r=t.reverse??tt(t.exec),i=new Map,a={async ensure(e,t){let a=i.get(e.local);if(a&&a.ownerId!==e.ownerId)throw new n(`COMMAND_FAILED`,`Android port reverse ${e.local} is already owned by ${a.ownerId??`another session`}`,{current:a,requested:e});a?.remote!==e.remote&&(await r.ensure(e,t),i.set(e.local,{...e}))},async remove(e,t){if(!i.has(e)){await r.remove(e,t);return}await r.remove(e,t),i.delete(e)},async removeAllOwned(e,t){let n=[...i.values()].filter(t=>t.ownerId===e).map(e=>e.local);if(n.length===0){await r.removeAllOwned(e,t);return}for(let e of n)await r.remove(e,t),i.delete(e)},async list(e){return r.list?await r.list(e):[...i.values()]}};return et.add(a),a}function Q(e){return Ve(typeof e==`function`?{exec:e}:e)}async function Je(e,t,r){let{device:i,provider:a,...o}=r??{},s=Xe(i,a),c=s?.pull;if(c)return await w(async()=>await c(e,t,o));let l=s?.exec;if(!l)throw new n(`COMMAND_FAILED`,`Android adb pull requires an adb provider`);return await w(async()=>await l([`pull`,e,t],o))}async function Ye(e,t){let{device:r,provider:i,...a}=t??{},o=Xe(r,i),s=o?.install;if(s)return await w(async()=>await s(e,a));let c=o?.exec;if(!c)throw new n(`COMMAND_FAILED`,`Android adb install requires an adb provider`);let{installArgs:l,execOptions:u}=$(a);return await w(async()=>await c([`install`,...l,e],u))}function Xe(e,t){if(t)return Q(t);if(e)return X(e);let n=W.getStore();if(n)return Q(n.provider)}async function Ze(e,t,n){if(!e)return await n();let r={provider:Q(e),serial:t.serial},i=Qe(r);return await W.run(r,async()=>await ge(i,n))}function Qe(e){return(t,n,r)=>{if(t!==`adb`)return;let i=$e(n,e.serial);if(i)return w(async()=>await e.provider.exec(i,r))}}function $e(e,t){if(!(e[0]!==`-s`||!e[1])&&e[1]===t)return e.slice(2)}const et=new WeakSet;function tt(e){let t=new Map;return{async ensure(n,r){if(await e([`reverse`,n.local,n.remote],{allowFailure:!1,signal:r?.signal,timeoutMs:r?.timeoutMs}),n.ownerId){let e=t.get(n.ownerId)??new Set;e.add(n.local),t.set(n.ownerId,e)}},async remove(n,r){let i=await e([`reverse`,`--remove`,n],{allowFailure:!0,signal:r?.signal,timeoutMs:r?.timeoutMs});if(i.exitCode!==0&&!rt(i.stdout,i.stderr))throw K(`Failed to remove Android port reverse ${n}`,i,{local:n});for(let e of t.values())e.delete(n)},async removeAllOwned(e,n){let r=[...t.get(e)??[]];for(let e of r)await this.remove(e,n);t.delete(e)},async list(n){let r=await e([`reverse`,`--list`],{allowFailure:!0,signal:n?.signal,timeoutMs:n?.timeoutMs});return r.exitCode===0?nt(r.stdout,t):[]}}}function nt(e,t){let n=new Map;for(let[e,r]of t)for(let t of r)n.set(t,e);return e.split(`
|
|
4
|
+
`).map(e=>e.trim().split(/\s+/)).filter(e=>e.length>=3).map(([,e,t])=>{let r=e;return{local:r,remote:t,ownerId:n.get(r)}})}function rt(e,t){let n=`${e}\n${t}`.toLowerCase();return n.includes(`listener`)&&n.includes(`not found`)}function $(e){let{replace:t,allowTestPackages:n,allowDowngrade:r,grantPermissions:i,...a}=e??{},o=[];return t&&o.push(`-r`),n&&o.push(`-t`),r&&o.push(`-d`),i&&o.push(`-g`),{installArgs:o,execOptions:a}}export{g as A,xe as C,S as D,ue as E,_ as F,ae as I,te as L,oe as M,ne as N,de as O,re as P,_e as S,w as T,be as _,Ye as a,Se as b,X as c,Ze as d,E as f,ye as g,De as h,qe as i,v as j,ie as k,Ke as l,V as m,K as n,Je as o,L as p,G as r,Ge as s,Fe as t,Z as u,T as v,ve as w,O as x,k as y};
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import { o as DaemonRequest, s as DaemonResponse } from "./sdk-contracts.js";
|
|
2
|
-
//#region src/
|
|
1
|
+
import { o as DaemonRequest, s as DaemonResponse, v as SessionRuntimeHints } from "./sdk-contracts.js";
|
|
2
|
+
//#region src/contracts/batch-step.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* One step of a daemon batch, as submitted.
|
|
5
|
+
*
|
|
6
|
+
* Declared here rather than in `core/batch.ts` because the public API vocabulary
|
|
7
|
+
* (`contracts/client-replay.ts`) is stated in terms of it, and `core/` sits above contracts. The
|
|
8
|
+
* `runtime` field used to be written as `DaemonRequest['runtime']`, which pulled the whole daemon
|
|
9
|
+
* request type in to say `SessionRuntimeHints` — the same type, one zone lower.
|
|
10
|
+
*/
|
|
3
11
|
type DaemonBatchStep = {
|
|
4
12
|
command: string;
|
|
5
13
|
positionals?: string[];
|
|
6
14
|
input?: Record<string, unknown>;
|
|
7
15
|
flags?: Record<string, unknown>;
|
|
8
|
-
runtime?:
|
|
16
|
+
runtime?: SessionRuntimeHints;
|
|
9
17
|
};
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/core/batch.d.ts
|
|
10
20
|
type BatchFlags = Record<string, unknown> & {
|
|
11
21
|
batchOnError?: 'stop';
|
|
12
22
|
batchMaxSteps?: number;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import{_ as e,a as t,i as n,v as r}from"./sdk-contracts.js";
|
|
2
|
-
`).map(e=>e.trim()).filter(e=>e.length>0)}function j(e){return Number.isInteger(e)&&e>=1&&e<=1e3}function M(t,n){if(t>n)throw new e(`INVALID_ARGS`,`batch has ${t} steps; max allowed is ${n}.`)}function N(t,n){if(!D(t))throw new e(`INVALID_ARGS`,`Invalid batch step ${n}.`);return t}function P(t,n){let r=t.input;if(!D(r))throw new e(`INVALID_ARGS`,`Batch step ${n} input must be an object.`);return r}function F(t,r){if(t!==void 0)try{return n.parse(t)}catch(t){throw new e(`INVALID_ARGS`,`Batch step ${r} runtime is invalid: ${t instanceof Error?t.message:String(t)}`)}}const I=new Set(s);async function L(e,t,n){let i=W(e.flags),a=i?.batchOnError??`stop`;if(a!==`stop`)return G(`INVALID_ARGS`,`Unsupported batch on-error mode: ${a}.`);let o=i?.batchMaxSteps??100;if(!j(o))return G(`INVALID_ARGS`,`Invalid batch max-steps: ${String(i?.batchMaxSteps)}`);try{let r=R(i?.batchSteps,o),a=Date.now(),s=[];for(let[i,a]of r.entries()){let o=await U(e,t,a,n,i+1,i===r.length-1);if(!o.ok)return{ok:!1,error:{code:o.error.code,message:`Batch failed at step ${o.step} (${a.command}): ${o.error.message}`,hint:o.error.hint,diagnosticId:o.error.diagnosticId,logPath:o.error.logPath,details:{...o.error.details??{},step:o.step,command:a.command,positionals:a.positionals,executed:i,total:r.length,partialResults:s}}};s.push(o.result)}return{ok:!0,data:{total:r.length,executed:r.length,totalDurationMs:Date.now()-a,results:s}}}catch(e){let t=r(e);return G(t.code,t.message,t.details)}}function R(t,n){if(!Array.isArray(t)||t.length===0)throw new e(`INVALID_ARGS`,`batch requires a non-empty batchSteps array.`);M(t.length,n);let r=[];for(let n=0;n<t.length;n+=1){let o=t[n];if(!D(o))throw new e(`INVALID_ARGS`,`Invalid batch step at index ${n}.`);let s=Object.keys(o).filter(e=>!I.has(e));if(s.length>0){let t=s.map(e=>`"${e}"`).join(`, `);throw new e(`INVALID_ARGS`,`Batch step ${n+1} has unknown field(s): ${t}. Allowed fields: command, positionals, input, flags, runtime.`)}let c=i(o.command);if(!c)throw new e(`INVALID_ARGS`,`Batch step ${n+1} requires command.`);if(a(c,n+1),o.positionals!==void 0&&!Array.isArray(o.positionals))throw new e(`INVALID_ARGS`,`Batch step ${n+1} positionals must be an array.`);let l=o.positionals??[];if(l.some(e=>typeof e!=`string`))throw new e(`INVALID_ARGS`,`Batch step ${n+1} positionals must contain only strings.`);if(o.flags!==void 0&&!D(o.flags))throw new e(`INVALID_ARGS`,`Batch step ${n+1} flags must be an object.`);if(o.input!==void 0&&!D(o.input))throw new e(`INVALID_ARGS`,`Batch step ${n+1} input must be an object.`);r.push({command:c,positionals:l,input:o.input,flags:o.flags??{},runtime:F(o.runtime,n+1)})}return r}function z(e,t){let{batchSteps:n,batchOnError:r,batchMaxSteps:i,...a}=t??{};return B(W(e),a)}function B(e,t){let n=W(e)??{},r=t;for(let e of o)r[e]===void 0&&n[e]!==void 0&&(r[e]=n[e]);return t}function V(e,n){return t(e)?n?e:`digest`:e}function H(e,t){let n=e?.responseLevel,r=V(n,t);return r===n?e:{...e,responseLevel:r}}async function U(e,t,n,r,i,a){let o=Date.now(),s=z(e.flags,n.flags);s.session===void 0&&(s.session=t);let c=await r({token:e.token,session:t,command:n.command,positionals:n.positionals,input:n.input,flags:s,runtime:n.runtime===void 0?e.runtime:n.runtime,meta:H(e.meta,a)}),l=Date.now()-o;return c.ok?{ok:!0,step:i,result:{step:i,command:n.command,ok:!0,data:c.data??{},durationMs:l}}:{ok:!1,step:i,error:c.error}}function W(e){return e}function G(e,t,n){return{ok:!1,error:{code:e,message:t,...n?{details:n}:{}}}}export{m as _,F as a,A as b,O as c,y as d,v as f,g,f as h,j as i,E as l,p as m,L as n,P as o,_ as p,M as r,N as s,B as t,D as u,h as v,k as x,d as y};
|
|
1
|
+
import{_ as e,a as t,i as n,v as r}from"./sdk-contracts.js";const i=new Set([`id`,`role`,`text`,`label`,`value`,`appname`,`windowtitle`]),a=new Set([`visible`,`hidden`,`editable`,`selected`,`focused`,`enabled`,`hittable`]),o=new Set([...i,...a]),s=[...o],c=new Set(`button.imagebutton.link.cell.statictext.checkedtextview.textfield.textbox.edittext.textarea.switch.slider.image.imageview.webview.framelayout.linearlayout.relativelayout.constraintlayout.viewgroup.view.listview.recyclerview.collectionview.list.searchfield.segmentedcontrol.group.window.checkbox.radio.menuitem.toolbar.scrollarea.scrollview.nestedscrollview.table.application.navigationbar.tabbar.tab.alert.dialog.header`.split(`.`));function ee(e){return c.has(e.trim().toLowerCase())}const te=new Map([[`"`,`"`],[`'`,`'`],[`\\`,`\\`],[`/`,`/`],[`b`,`\b`],[`f`,`\f`],[`n`,`
|
|
2
|
+
`],[`r`,`\r`],[`t`,` `]]);function ne(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Selector expression cannot be empty`);let r=oe(n);if(r.length===0)throw new e(`INVALID_ARGS`,`Selector expression cannot be empty`);return{raw:n,selectors:r.map(e=>ie(e))}}function l(e){try{return ne(e)}catch{return null}}function u(e){let t=e.trim();if(!t)return!1;if(t===`||`)return!0;let n=t.indexOf(`=`);if(n!==-1){let e=t.slice(0,n).trim().toLowerCase();return o.has(e)}return o.has(t.toLowerCase())}function re(e){let t=e.trim(),n=t.indexOf(`=`);if(n===-1)return null;let r=t.slice(0,n).trim().toLowerCase();if(!r||o.has(r))return null;let i=t.slice(n+1).trim();if(!i)return null;let a=p(i).trim();return a?{key:r,value:a}:null}function d(e,t={}){if(e.length===0)return null;let n=t.preferTrailingValue??!1,r=0,i=[];for(;r<e.length;){let t=e[r];if(t===void 0||!u(t))break;r+=1;let n=e.slice(0,r).join(` `).trim();n&&l(n)&&i.push(r)}if(i.length===0)return null;let a=i.at(-1);if(a===void 0)return null;let o=a;if(n)for(let t=i.length-1;t>=0;--t){let n=i[t];if(n!==void 0&&n<e.length){o=n;break}}let s=e.slice(0,o).join(` `).trim();return s?{selectorExpression:s,rest:e.slice(o)}:null}function ie(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Selector segment cannot be empty`);let r=se(n);if(r.length===0)throw new e(`INVALID_ARGS`,`Invalid selector segment: ${t}`);return{raw:n,terms:r.map(ae)}}function ae(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Empty selector term`);let r=n.indexOf(`=`);if(r===-1){let r=n.toLowerCase();if(!a.has(r))throw new e(`INVALID_ARGS`,`Invalid selector term "${t}", expected key=value`);return{key:r,value:!0}}let i=n.slice(0,r).trim().toLowerCase(),s=n.slice(r+1).trim();if(!o.has(i))throw new e(`INVALID_ARGS`,`Unknown selector key: ${i}`);if(!s)throw new e(`INVALID_ARGS`,`Missing selector value for key: ${i}`);if(a.has(i)){let t=ue(s);if(t===null)throw new e(`INVALID_ARGS`,`Invalid boolean value for ${i}: ${s}`);return{key:i,value:t}}return{key:i,value:p(s)}}function oe(t){let n=[],r=``,i=null;for(let a=0;a<t.length;a+=1){let o=t[a];if((o===`"`||o===`'`)&&!m(t,a)){i=f(i,o),r+=o;continue}if(!i&&o===`|`&&t[a+1]===`|`){let i=r.trim();if(!i)throw new e(`INVALID_ARGS`,`Invalid selector fallback expression: ${t}`);n.push(i),r=``,a+=1;continue}r+=o}let a=r.trim();if(!a)throw new e(`INVALID_ARGS`,`Invalid selector fallback expression: ${t}`);return n.push(a),n}function se(t){let n=[],r=``,i=null;for(let e=0;e<t.length;e+=1){let a=t.charAt(e);if((a===`"`||a===`'`)&&!m(t,e)){i=f(i,a),r+=a;continue}if(!i&&/\s/.test(a)){r.trim()&&n.push(r.trim()),r=``;continue}r+=a}if(i)throw new e(`INVALID_ARGS`,`Unclosed quote in selector: ${t}`);return r.trim()&&n.push(r.trim()),n}function f(e,t){return e?e===t?null:e:t}function p(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?ce(t.slice(1,-1)):t}function ce(e){let t=``,n=0;for(;n<e.length;){let r=e.charAt(n);if(r!==`\\`){t+=r,n+=1;continue}let i=e.charAt(n+1);if(!i){t+=r,n+=1;continue}let a=le(i);if(a!==null){t+=a,n+=2;continue}if(i===`u`){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(Number.parseInt(r,16)),n+=6;continue}}t+=r,n+=1}return t}function le(e){return te.get(e)??null}function ue(e){let t=p(e).toLowerCase();return t===`true`?!0:t===`false`?!1:null}function m(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}const de=[`any`,`text`,`label`,`value`,`role`,`id`],fe=[`text`,`label`,`value`,`role`,`id`];function pe(e){return e===`exists`||e===`wait`||e===`get_text`||e===`get_attrs`}function me(e,t,n,r={}){let i=g(n);if(!i)return{matches:[],score:0};let a=0,o=[];for(let n of e){if(r.requireRect&&!n.rect)continue;let e=he(n,t,i);if(!(e<=0)){if(e>a){a=e,o.length=0,o.push(n);continue}e===a&&o.push(n)}}return{matches:o,score:a}}function he(e,t,n){switch(t){case`role`:return ge(e.type,n);case`label`:return h(e.label,n);case`value`:return h(e.value,n);case`id`:return h(e.identifier,n);default:return Math.max(h(e.label,n),h(e.value,n),h(e.identifier,n))}}function h(e,t){let n=g(e??``);return n?n===t?2:+!!n.includes(t):0}function ge(e,t){let n=_e(e??``);return n?n===t?2:+!!n.includes(t):0}function g(e){return e.trim().toLowerCase().replace(/\s+/g,` `)}function _e(e){let t=e.trim();return t?(t=(t.split(`.`).pop()??t).replace(/XCUIElementType/gi,``).toLowerCase(),t):``}const ve=`find requires a value`;function ye(e,t){if(e.length===0)return{ok:!1,code:`INVALID_ARGS`,message:`find requires a locator or text`};let n=_([...e]);return n.query?t?.findFirst&&t?.findLast?{ok:!1,code:`INVALID_ARGS`,message:`find accepts only one of --first or --last`}:{ok:!0,parsed:n}:{ok:!1,code:`INVALID_ARGS`,message:ve}}function _(t){let n=`any`,r=0;fe.includes(t[0])&&(n=t[0],r=1);let i=t[r]??``,a=t.slice(r+1);if(a.length===0)return{locator:n,query:i,action:`click`};let o=a[0]?.toLowerCase();if(o===`get`){let t=a[1]?.toLowerCase();if(t===`text`)return{locator:n,query:i,action:`get_text`};if(t===`attrs`)return{locator:n,query:i,action:`get_attrs`};throw new e(`INVALID_ARGS`,`find get only supports text or attrs`)}if(o===`wait`){let e=xe(a[1]);return{locator:n,query:i,action:`wait`,timeoutMs:e??void 0}}if(o===`exists`)return{locator:n,query:i,action:`exists`};if(o===`click`)return{locator:n,query:i,action:`click`};if(o===`focus`)return{locator:n,query:i,action:`focus`};if(o===`fill`){let e=a.slice(1).join(` `);return{locator:n,query:i,action:`fill`,value:e}}if(o===`type`){let e=a.slice(1).join(` `);return{locator:n,query:i,action:`type`,value:e}}throw new e(`INVALID_ARGS`,`Unsupported find action: ${a[0]}`)}function be(e,t){return e!==`any`||!t.includes(`=`)&&!t.includes(`||`)?null:l(t)}function xe(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}function v(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}function y(e){let t=e[0];if(t===void 0)return null;let n=v(t);if(n!==null)return{kind:`sleep`,durationMs:n};let r=v(e[e.length-1]);if(t===`text`)return{kind:`text`,text:(r===null?e.slice(1).join(` `):e.slice(1,-1).join(` `)).trim(),timeoutMs:r};if(t===`stable`){let t=e.slice(1),n=t.length>1?v(t[1]):null;return{kind:`stable`,quietMs:t.length>0?v(t[0]):null,timeoutMs:n}}if(t.startsWith(`@`))return{kind:`ref`,rawRef:t,timeoutMs:r};let i=d(r===null?e.slice():e.slice(0,-1));return i&&i.rest.length===0&&l(i.selectorExpression)?{kind:`selector`,selectorExpression:i.selectorExpression,timeoutMs:r}:{kind:`text`,text:(r===null?e.join(` `):e.slice(0,-1).join(` `)).trim(),timeoutMs:r}}function Se(e){let t=y(e);return t?t.kind===`sleep`?t.durationMs:t.timeoutMs:null}const b=24e4,x={budget:{source:`none`},envelopeMs:9e4,onTimeout:`reset-daemon`},Ce={click:`settle-and-verify`,press:`settle-and-verify`,fill:`settle-and-verify`,longpress:`settle`};function S(e){if(e!==void 0)return Ce[e]}const C={leaseAdmissionExempt:!0,sessionExecutionLockExempt:!0},w={leaseAdmissionExempt:!0,sessionExecutionLockExempt:!0,selectorValidationExempt:!0},T=()=>!0,we=e=>(e.positionals?.[0]??``).toLowerCase()===`start`,E=e=>e.command===`test`&&(typeof e.flags?.shardAll==`number`||typeof e.flags?.shardSplit==`number`),D=new Set([`status`,`get`]),Te=e=>k(e,D,`status`),O=new Set([`get`,`wait`]),Ee=e=>k(e,O,`get`),De=e=>A(e,D,`status`),Oe=e=>A(e,O,`get`),ke=e=>{try{return pe(_(e.positionals??[]).action)?`observes-app`:`mutates-app`}catch{return`mutates-app`}};function k(e,t,n){return t.has((e.positionals?.[0]??n).toLowerCase())?`preserve`:`may-invalidate`}function A(e,t,n){return t.has((e.positionals?.[0]??n).toLowerCase())?`observes-app`:`mutates-app`}const j={simulator:!0,device:!0},M={emulator:!0,device:!0,unknown:!0},N={emulator:!0},P={device:!0},F={},I={apple:j,android:M,linux:P},L={...I,vega:N},Ae={apple:j,android:M,linux:F},R={apple:j,android:M,linux:F},z={recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:j,android:M,linux:P},timeoutPolicy:x,batchable:!0},B={...x,onTimeout:`preserve-daemon`},V={...x,envelopeMs:18e4},H={...x,budget:{source:`flag`,envelope:`widen`,defaultBudgetMs:1e4},onTimeout:`preserve-daemon`},je={fields:{count:{defaultValue:1,omitDefault:!0},intervalMs:{defaultValue:0,omitDefault:!0},holdMs:{defaultValue:0,omitDefault:!0},jitterPx:{defaultValue:0,omitDefault:!0},doubleTap:{defaultValue:!1,omitDefault:!0}}},Me={fields:{delayMs:{defaultValue:0}}};function U(e){return S(e)===void 0?B:H}function W(e){let t=S(e);if(t===void 0)throw Error(`Missing post-action observation descriptor support for ${e}`);return t}const Ne=[{name:`lease_allocate`,catalog:{group:`internal`,key:`leaseAllocate`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...C},timeoutPolicy:x,batchable:!1},{name:`lease_heartbeat`,catalog:{group:`internal`,key:`leaseHeartbeat`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...C},timeoutPolicy:x,batchable:!1},{name:`lease_release`,catalog:{group:`internal`,key:`leaseRelease`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...C},timeoutPolicy:x,batchable:!1},{name:`artifacts`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...C},timeoutPolicy:x,batchable:!1},{name:`session_list`,catalog:{group:`internal`,key:`sessionList`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,...w},timeoutPolicy:x,batchable:!1},{name:`session_save_script`,catalog:{group:`internal`,key:`sessionSaveScript`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`publication`},timeoutPolicy:x,batchable:!1},{name:`devices`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,...w},timeoutPolicy:x,batchable:!0},{name:`capabilities`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,preferExplicitDeviceOverExistingSession:!0,...w},timeoutPolicy:x,batchable:!0},{name:`doctor`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,allowSessionlessDefaultDevice:T,...w},timeoutPolicy:x,batchable:!0},{name:`apps`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,preferExplicitDeviceOverExistingSession:!0},capability:Ae,timeoutPolicy:x,batchable:!0},{name:`boot`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`may-invalidate`,sessionKind:`state`},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`shutdown`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`may-invalidate`,sessionKind:`state`},capability:{apple:{simulator:!0},android:{emulator:!0},linux:F},timeoutPolicy:x,batchable:!0},{name:`appstate`,catalog:{group:`public`,key:`appState`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`state`},timeoutPolicy:x,batchable:!0},{name:`perf`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`logs`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`events`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`,allowInvalidRecording:!0,...w},timeoutPolicy:x,batchable:!1},{name:`network`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`audio`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},capability:{apple:j,android:{emulator:!0},linux:F},timeoutPolicy:x,batchable:!0},{name:`replay`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,sessionKind:`replay`,skipSessionlessProviderDevice:E},timeoutPolicy:{...x,budget:{source:`flag`}},batchable:!1},{name:`test`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,sessionKind:`replay`,skipSessionlessProviderDevice:E},timeoutPolicy:{...x,envelopeMs:`unbounded`},batchable:!0},{name:`runtime`,catalog:{group:`internal`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`},timeoutPolicy:x,batchable:!1},{name:`clipboard`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`session`,refFrameEffect:`preserve`},dispatch:{},capability:{apple:j,android:M,linux:P},timeoutPolicy:x,batchable:!0},{name:`keyboard`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:De,daemon:{route:`session`,refFrameEffect:Te,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`install`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},capability:R,timeoutPolicy:V,batchable:!0},{name:`reinstall`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},capability:R,timeoutPolicy:V,batchable:!0},{name:`install_source`,catalog:{group:`internal`,key:`installSource`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},timeoutPolicy:V,batchable:!1},{name:`release_materialized_paths`,catalog:{group:`internal`,key:`releaseMaterializedPaths`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,...w},timeoutPolicy:x,batchable:!1},{name:`push`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:{simulator:!0},android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`trigger-app-event`,catalog:{group:`public`,key:`triggerAppEvent`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`open`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`,allowSessionlessDefaultDevice:T},dispatch:{},capability:L,timeoutPolicy:x,batchable:!0},{name:`prepare`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`},capability:{apple:j,android:{},linux:F},timeoutPolicy:{budget:{source:`flag`},envelopeMs:b,onTimeout:`reset-daemon`},batchable:!1,mcpExposed:!1},{name:`batch`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`},timeoutPolicy:x,batchable:!1},{name:`close`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`,allowInvalidRecording:!0},dispatch:{},capability:L,timeoutPolicy:x,batchable:!0},{name:`snapshot`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},dispatch:{},capability:I,timeoutPolicy:{...B,budget:{source:`flag`}},batchable:!0},{name:`diff`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},capability:I,timeoutPolicy:x,batchable:!0},{name:`wait`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,targetIdentityVerification:`post-resolution`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},capability:I,timeoutPolicy:{...B,budget:{source:`positional-parser`,parser:Se}},batchable:!0},{name:`alert`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:Oe,daemon:{route:`snapshot`,refFrameEffect:Ee},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`settings`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`snapshot`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`react-native`,catalog:{group:`public`,key:`reactNative`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`reactNative`,refFrameEffect:`may-invalidate`},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`record`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`recordTrace`,refFrameEffect:`preserve`,allowInvalidRecording:!0,allowSessionlessDefaultDevice:we},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`trace`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`recordTrace`,refFrameEffect:`preserve`},timeoutPolicy:x,batchable:!0},{name:`find`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:ke,daemon:{route:`find`,refFrameEffect:`may-invalidate`},capability:I,timeoutPolicy:B,batchable:!0},{name:`click`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},capability:{apple:j,android:M,linux:P},timeoutPolicy:U(`click`),postActionObservation:W(`click`),responseDataTransform:je,batchable:!0},{name:`fill`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:j,android:M,linux:P},timeoutPolicy:U(`fill`),postActionObservation:W(`fill`),responseDataTransform:Me,batchable:!0},{name:`longpress`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`,key:`longPress`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:j,android:M,linux:P},timeoutPolicy:{...H,envelopeMs:21e4},postActionObservation:W(`longpress`),batchable:!0},{name:`press`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:j,android:M,linux:P},timeoutPolicy:U(`press`),postActionObservation:W(`press`),responseDataTransform:je,batchable:!0},{name:`type`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:I,timeoutPolicy:U(`type`),batchable:!0},{name:`get`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`interaction`,refFrameEffect:`preserve`},capability:I,timeoutPolicy:U(`get`),batchable:!0},{name:`read`,catalog:{group:`dispatch-alias`},recordsSessionAction:!1,dispatch:{},timeoutPolicy:x,batchable:!1},{name:`is`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`interaction`,refFrameEffect:`preserve`},capability:I,timeoutPolicy:U(`is`),batchable:!0},{name:`back`,catalog:{group:`public`},...z,capability:{...z.capability,vega:N}},{name:`gesture`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},capability:I,timeoutPolicy:x,batchable:!0},{name:`home`,catalog:{group:`public`},...z,capability:{...z.capability,vega:N}},{name:`tv-remote`,catalog:{group:`public`,key:`tvRemote`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:j,android:M,vega:N,linux:F},timeoutPolicy:x,batchable:!0},{name:`orientation`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`scroll`,catalog:{group:`public`},...z},{name:`swipe`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},capability:{apple:j,android:M,linux:P},timeoutPolicy:x,batchable:!0},{name:`focus`,catalog:{group:`public`},...z},{name:`screenshot`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`generic`,refFrameEffect:`preserve`},dispatch:{},capability:I,timeoutPolicy:x,batchable:!0},{name:`viewport`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:j,android:{},linux:F},timeoutPolicy:x,batchable:!1},{name:`app-switcher`,catalog:{group:`public`,key:`appSwitcher`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`install-from-source`,catalog:{group:`public`,key:`installFromSource`},recordsSessionAction:!0,recordingEffect:`mutates-app`,capability:R,timeoutPolicy:x,batchable:!0},{name:`debug`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1},{name:`daemon`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`device`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`metro`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1},{name:`session`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1},{name:`cdp`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`auth`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`connect`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`connection`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`disconnect`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`mcp`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`proxy`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`react-devtools`,catalog:{group:`local-cli`,key:`reactDevtools`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`web`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1}],Pe=new Set([`public`,`local-cli`]),G=new Set(Ne.filter(e=>Pe.has(Be(e))).map(e=>e.name)),K=Ne.map(e=>({...e,mcpExposed:Re(e)}));function Fe(e){return K.filter(t=>Be(t)===e).map(e=>[Ve(e),e.name])}function Ie(){return K.filter(e=>ze(e)).map(e=>e.name).sort()}const q=new Map(K.map(e=>[e.name,e]));function Le(e){return G.has(e)}function Re(e){return e.mcpExposed??G.has(e.name)}function ze(e){return e.mcpExposed&&Le(e.name)}function Be(e){return e.catalog.group}function Ve(e){return e.catalog.key??e.name}const He=new Map(K.map(e=>[e.name,e.timeoutPolicy])),Ue=new Map(Array.from(q.values()).flatMap(e=>e.responseDataTransform?[[e.name,e.responseDataTransform]]:[]));function We(e){if(e!==void 0)return q.get(e)?.postActionObservation}function Ge(e){return We(e)!==void 0}function Ke(e){return We(e)===`settle-and-verify`}function qe(e){return e===void 0?x:He.get(e)??x}function Je(e){if(e!==void 0)return Ue.get(e)}function Ye(e){return e===void 0?!1:q.get(e)?.recordsSessionAction??!1}function Xe(e){return q.get(e)?.targetIdentityVerification}function Ze(e){let t=q.get(e.command);if(t?.recordsSessionAction)return typeof t.recordingEffect==`function`?t.recordingEffect(e):t.recordingEffect}function Qe(){return[...new Set(Array.from(Ue.values()).flatMap(e=>Object.keys(e.fields)))].sort()}function J(t,n,r,i){let a=r(t[n]);if(a===void 0)throw new e(`COMMAND_FAILED`,i,{response:t});return a}function $e(e,t,n){return n(e[t])}function et(e,t,n){let r=e[t];return r===null?null:n(r)}function tt(e,t){return J(e,t,X,`Daemon response is missing "${t}".`)}function nt(e,t){return $e(e,t,X)}function rt(e,t){return et(e,t,X)}function it(e,t){return J(e,t,ut,`Daemon response is missing numeric "${t}".`)}function at(e,t){return J(e,t,dt,`Daemon response has invalid "${t}".`)}function ot(e,t){return J(e,t,ft,`Daemon response has invalid "${t}".`)}function st(e,t){return $e(e,t,pt)??`mobile`}function ct(e){if(!Z(e))return;let t=Y(e,`x`),n=Y(e,`y`),r=Y(e,`width`),i=Y(e,`height`);if(!(t===void 0||n===void 0||r===void 0||i===void 0))return{x:t,y:n,width:r,height:i}}function lt(e){if(!Z(e))return;let t=Y(e,`x`),n=Y(e,`y`);if(!(t===void 0||n===void 0))return{x:t,y:n}}function Y(e,t){let n=e[t];return typeof n==`number`?n:void 0}function X(e){return typeof e==`string`&&e.length>0?e:void 0}function ut(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function dt(e){return e===`apple`?`ios`:e===`ios`||e===`macos`||e===`android`||e===`vega`||e===`linux`||e===`web`?e:void 0}function ft(e){return e===`simulator`||e===`emulator`||e===`device`?e:void 0}function pt(e){return e===`tv`||e===`mobile`||e===`desktop`?e:void 0}function mt(t){if(!Z(t))throw new e(`COMMAND_FAILED`,`Daemon returned an unexpected response shape.`,{value:t});return t}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ht(e){return Z(e)?e:void 0}function gt(e){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t}function _t(e){return e.split(`
|
|
3
|
+
`).map(e=>e.trim()).filter(e=>e.length>0)}function vt(e){return Number.isInteger(e)&&e>=1&&e<=1e3}function yt(t,n){if(t>n)throw new e(`INVALID_ARGS`,`batch has ${t} steps; max allowed is ${n}.`)}function bt(t,n){if(!Z(t))throw new e(`INVALID_ARGS`,`Invalid batch step ${n}.`);return t}function xt(t,n){let r=t.input;if(!Z(r))throw new e(`INVALID_ARGS`,`Batch step ${n} input must be an object.`);return r}function St(t,r){if(t!==void 0)try{return n.parse(t)}catch(t){throw new e(`INVALID_ARGS`,`Batch step ${r} runtime is invalid: ${t instanceof Error?t.message:String(t)}`)}}function Ct(e){let t=[];for(let n of e)n.daemon&&t.push({command:n.name,...n.daemon,replayScopedAction:n.recordsSessionAction});return t}function wt(e){let t={};for(let n of e)n.capability&&(t[n.name]=n.capability);return t}function Tt(e){return e.filter(e=>e.batchable).map(e=>e.name)}const Et=Tt(K),Dt=new Set([`batch`,`replay`]),Ot=[`command`,`positionals`,`input`,`flags`,`runtime`],kt=[`platform`,`target`,`device`,`udid`,`serial`,`verbose`,`out`],At=new Set(Et);function jt(e){return At.has(e)}function Mt(e){return typeof e==`string`?e.trim().toLowerCase():``}function Nt(t,n){let r=Mt(t);if(jt(r))return r;throw new e(`INVALID_ARGS`,`Batch step ${n} command is not available through command batch: ${String(t)}`)}function Pt(t,n){if(Dt.has(t))throw new e(`INVALID_ARGS`,`Batch step ${n} cannot run ${t}.`)}const Ft=new Set(Ot);async function It(e,t,n){let i=Q(e.flags),a=i?.batchOnError??`stop`;if(a!==`stop`)return $(`INVALID_ARGS`,`Unsupported batch on-error mode: ${a}.`);let o=i?.batchMaxSteps??100;if(!vt(o))return $(`INVALID_ARGS`,`Invalid batch max-steps: ${String(i?.batchMaxSteps)}`);try{let r=Lt(i?.batchSteps,o),a=Date.now(),s=[];for(let[i,a]of r.entries()){let o=await Ht(e,t,a,n,i+1,i===r.length-1);if(!o.ok)return{ok:!1,error:{code:o.error.code,message:`Batch failed at step ${o.step} (${a.command}): ${o.error.message}`,hint:o.error.hint,diagnosticId:o.error.diagnosticId,logPath:o.error.logPath,details:{...o.error.details??{},step:o.step,command:a.command,positionals:a.positionals,executed:i,total:r.length,partialResults:s}}};s.push(o.result)}return{ok:!0,data:{total:r.length,executed:r.length,totalDurationMs:Date.now()-a,results:s}}}catch(e){let t=r(e);return $(t.code,t.message,t.details)}}function Lt(t,n){if(!Array.isArray(t)||t.length===0)throw new e(`INVALID_ARGS`,`batch requires a non-empty batchSteps array.`);yt(t.length,n);let r=[];for(let n=0;n<t.length;n+=1){let i=t[n];if(!Z(i))throw new e(`INVALID_ARGS`,`Invalid batch step at index ${n}.`);let a=Object.keys(i).filter(e=>!Ft.has(e));if(a.length>0){let t=a.map(e=>`"${e}"`).join(`, `);throw new e(`INVALID_ARGS`,`Batch step ${n+1} has unknown field(s): ${t}. Allowed fields: command, positionals, input, flags, runtime.`)}let o=Mt(i.command);if(!o)throw new e(`INVALID_ARGS`,`Batch step ${n+1} requires command.`);if(Pt(o,n+1),i.positionals!==void 0&&!Array.isArray(i.positionals))throw new e(`INVALID_ARGS`,`Batch step ${n+1} positionals must be an array.`);let s=i.positionals??[];if(s.some(e=>typeof e!=`string`))throw new e(`INVALID_ARGS`,`Batch step ${n+1} positionals must contain only strings.`);if(i.flags!==void 0&&!Z(i.flags))throw new e(`INVALID_ARGS`,`Batch step ${n+1} flags must be an object.`);if(i.input!==void 0&&!Z(i.input))throw new e(`INVALID_ARGS`,`Batch step ${n+1} input must be an object.`);r.push({command:o,positionals:s,input:i.input,flags:i.flags??{},runtime:St(i.runtime,n+1)})}return r}function Rt(e,t){let{batchSteps:n,batchOnError:r,batchMaxSteps:i,...a}=t??{};return zt(Q(e),a)}function zt(e,t){let n=Q(e)??{},r=t;for(let e of kt)r[e]===void 0&&n[e]!==void 0&&(r[e]=n[e]);return t}function Bt(e,n){return t(e)?n?e:`digest`:e}function Vt(e,t){let n=e?.responseLevel,r=Bt(n,t);return r===n?e:{...e,responseLevel:r}}async function Ht(e,t,n,r,i,a){let o=Date.now(),s=Rt(e.flags,n.flags);s.session===void 0&&(s.session=t);let c=await r({token:e.token,session:t,command:n.command,positionals:n.positionals,input:n.input,flags:s,runtime:n.runtime===void 0?e.runtime:n.runtime,meta:Vt(e.meta,a)}),ee=Date.now()-o;return c.ok?{ok:!0,step:i,result:{step:i,command:n.command,ok:!0,data:c.data??{},durationMs:ee}}:{ok:!1,step:i,error:c.error}}function Q(e){return e}function $(e,t,n){return{ok:!1,error:{code:e,message:t,...n?{details:n}:{}}}}export{d as $,Fe as A,de as B,tt as C,Ge as D,K as E,qe as F,g as G,ye as H,Xe as I,s as J,_ as K,b as L,Ze as M,Ye as N,Ke as O,Je as P,ne as Q,y as R,at as S,gt as T,me as U,ve as V,pe as W,ee as X,re as Y,u as Z,st as _,wt as a,ot as b,vt as c,bt as d,l as et,ht as f,ct as g,lt as h,Nt as i,Ie as j,Qe as k,St as l,Z as m,It as n,Ct as o,mt as p,be as q,Et as r,yt as s,zt as t,xt as u,rt as v,_t as w,it as x,nt as y,v as z};
|
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
//#region src/kernel/device.d.ts
|
|
2
2
|
declare const APPLE_OS_VALUES: readonly ['ios', 'ipados', 'tvos', 'watchos', 'visionos', 'macos'];
|
|
3
3
|
type AppleOS = (typeof APPLE_OS_VALUES)[number];
|
|
4
|
-
declare const PLATFORMS: readonly ['apple', 'android', 'linux', 'web'];
|
|
4
|
+
declare const PLATFORMS: readonly ['apple', 'android', 'vega', 'linux', 'web'];
|
|
5
5
|
type Platform = (typeof PLATFORMS)[number];
|
|
6
|
-
declare const PUBLIC_PLATFORMS: readonly ['ios', 'macos', 'android', 'linux', 'web'];
|
|
6
|
+
declare const PUBLIC_PLATFORMS: readonly ['ios', 'macos', 'android', 'vega', 'linux', 'web'];
|
|
7
7
|
type PublicPlatform = (typeof PUBLIC_PLATFORMS)[number];
|
|
8
|
-
declare const PLATFORM_SELECTORS: readonly ["apple", "android", "linux", "web", "ios", "macos"];
|
|
8
|
+
declare const PLATFORM_SELECTORS: readonly ["apple", "android", "vega", "linux", "web", "ios", "macos"];
|
|
9
9
|
type PlatformSelector = (typeof PLATFORM_SELECTORS)[number];
|
|
10
10
|
declare const DEVICE_KINDS: readonly ['simulator', 'emulator', 'device'];
|
|
11
11
|
type DeviceKind = (typeof DEVICE_KINDS)[number];
|
|
12
12
|
declare const DEVICE_TARGETS: readonly ['mobile', 'tv', 'desktop'];
|
|
13
13
|
type DeviceTarget = (typeof DEVICE_TARGETS)[number];
|
|
14
|
+
type DeviceInfo = {
|
|
15
|
+
platform: Platform;
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
kind: DeviceKind;
|
|
19
|
+
target?: DeviceTarget;
|
|
20
|
+
appleOs?: AppleOS;
|
|
21
|
+
booted?: boolean;
|
|
22
|
+
simulatorSetPath?: string;
|
|
23
|
+
iosPhysicalDeviceBackend?: 'coredevice' | 'xctest';
|
|
24
|
+
};
|
|
14
25
|
//#endregion
|
|
15
26
|
//#region src/kernel/snapshot.d.ts
|
|
16
27
|
/**
|
|
@@ -39,6 +50,12 @@ type Point = {
|
|
|
39
50
|
x: number;
|
|
40
51
|
y: number;
|
|
41
52
|
};
|
|
53
|
+
type SnapshotOptions = {
|
|
54
|
+
interactiveOnly?: boolean;
|
|
55
|
+
depth?: number;
|
|
56
|
+
scope?: string;
|
|
57
|
+
raw?: boolean;
|
|
58
|
+
};
|
|
42
59
|
type RawSnapshotNode = {
|
|
43
60
|
index: number;
|
|
44
61
|
type?: string;
|
|
@@ -115,7 +132,16 @@ type ScreenshotOverlayRef = {
|
|
|
115
132
|
declare function centerOfRect(rect: Rect): Point;
|
|
116
133
|
//#endregion
|
|
117
134
|
//#region src/kernel/errors.d.ts
|
|
118
|
-
|
|
135
|
+
/**
|
|
136
|
+
* The known error codes as a value, so gates can enumerate them: every code
|
|
137
|
+
* here must resolve a hint through `defaultHintForCode`, and every code
|
|
138
|
+
* `retriableForErrorCode` classifies must have a recovery quiz in the help
|
|
139
|
+
* benchmark (scripts/__tests__/help-conformance-error-recovery-coverage.test.ts).
|
|
140
|
+
* `KnownAppErrorCode` is derived from this array, so a new code cannot be added
|
|
141
|
+
* to the type without entering the enumeration.
|
|
142
|
+
*/
|
|
143
|
+
declare const KNOWN_APP_ERROR_CODES: readonly ['INVALID_ARGS', 'DEVICE_NOT_FOUND', 'DEVICE_IN_USE', 'TOOL_MISSING', 'APP_NOT_INSTALLED', 'UNSUPPORTED_PLATFORM', 'UNSUPPORTED_OPERATION', 'NOT_IMPLEMENTED', 'COMMAND_FAILED', 'SESSION_NOT_FOUND', 'UNAUTHORIZED', 'AMBIGUOUS_MATCH', 'REPLAY_DIVERGENCE', 'REPAIR_SESSION_EXPIRED', 'REPAIR_COMMIT_FAILED', 'UNKNOWN'];
|
|
144
|
+
type KnownAppErrorCode = (typeof KNOWN_APP_ERROR_CODES)[number];
|
|
119
145
|
type AppErrorCode = KnownAppErrorCode | (string & {});
|
|
120
146
|
/**
|
|
121
147
|
* Details bag for AppError. Free-form context is allowed, but these keys carry
|
|
@@ -173,55 +199,6 @@ declare function normalizeError(err: unknown, context?: {
|
|
|
173
199
|
}): NormalizedError;
|
|
174
200
|
declare function defaultHintForCode(code: string): string | undefined;
|
|
175
201
|
//#endregion
|
|
176
|
-
//#region src/contracts/debug-symbols.d.ts
|
|
177
|
-
type DebugSymbolsOptions = {
|
|
178
|
-
action?: 'symbols';
|
|
179
|
-
artifact: string;
|
|
180
|
-
dsym?: string;
|
|
181
|
-
searchPath?: string;
|
|
182
|
-
out?: string;
|
|
183
|
-
cwd?: string;
|
|
184
|
-
};
|
|
185
|
-
type DebugSymbolsImage = {
|
|
186
|
-
name: string;
|
|
187
|
-
uuid: string;
|
|
188
|
-
arch?: string;
|
|
189
|
-
dsymPath: string;
|
|
190
|
-
binaryPath: string;
|
|
191
|
-
};
|
|
192
|
-
type DebugSymbolsCrashFrame = {
|
|
193
|
-
index: number;
|
|
194
|
-
image: string;
|
|
195
|
-
address: string;
|
|
196
|
-
symbol?: string;
|
|
197
|
-
};
|
|
198
|
-
type DebugSymbolsCrashSummary = {
|
|
199
|
-
format: 'ips' | 'text';
|
|
200
|
-
appName?: string;
|
|
201
|
-
bundleId?: string;
|
|
202
|
-
version?: string;
|
|
203
|
-
incident?: string;
|
|
204
|
-
timestamp?: string;
|
|
205
|
-
exceptionType?: string;
|
|
206
|
-
exceptionCodes?: string;
|
|
207
|
-
terminationReason?: string;
|
|
208
|
-
crashedThread?: number;
|
|
209
|
-
topFrames: DebugSymbolsCrashFrame[];
|
|
210
|
-
findings: string[];
|
|
211
|
-
};
|
|
212
|
-
type DebugSymbolsResult = {
|
|
213
|
-
kind: 'debugSymbols';
|
|
214
|
-
platform: 'apple';
|
|
215
|
-
artifactPath: string;
|
|
216
|
-
outPath: string;
|
|
217
|
-
crash: DebugSymbolsCrashSummary;
|
|
218
|
-
matchedImages: DebugSymbolsImage[];
|
|
219
|
-
symbolicatedFrames: number;
|
|
220
|
-
skippedImages: number;
|
|
221
|
-
warnings?: string[];
|
|
222
|
-
message: string;
|
|
223
|
-
};
|
|
224
|
-
//#endregion
|
|
225
202
|
//#region src/kernel/contracts.d.ts
|
|
226
203
|
type SessionRuntimeHints = {
|
|
227
204
|
platform?: 'ios' | 'android';
|
|
@@ -345,43 +322,6 @@ type DaemonResponse = {
|
|
|
345
322
|
ok: false;
|
|
346
323
|
error: DaemonError;
|
|
347
324
|
};
|
|
348
|
-
type LeaseAllocatePayload = {
|
|
349
|
-
token?: string;
|
|
350
|
-
session?: string;
|
|
351
|
-
tenantId?: string;
|
|
352
|
-
tenant?: string;
|
|
353
|
-
runId?: string;
|
|
354
|
-
ttlMs?: number;
|
|
355
|
-
backend?: LeaseBackend;
|
|
356
|
-
leaseProvider?: string;
|
|
357
|
-
deviceKey?: string;
|
|
358
|
-
clientId?: string;
|
|
359
|
-
};
|
|
360
|
-
type LeaseHeartbeatPayload = {
|
|
361
|
-
token?: string;
|
|
362
|
-
session?: string;
|
|
363
|
-
tenantId?: string;
|
|
364
|
-
tenant?: string;
|
|
365
|
-
runId?: string;
|
|
366
|
-
leaseId?: string;
|
|
367
|
-
ttlMs?: number;
|
|
368
|
-
backend?: LeaseBackend;
|
|
369
|
-
leaseProvider?: string;
|
|
370
|
-
deviceKey?: string;
|
|
371
|
-
clientId?: string;
|
|
372
|
-
};
|
|
373
|
-
type LeaseReleasePayload = {
|
|
374
|
-
token?: string;
|
|
375
|
-
session?: string;
|
|
376
|
-
tenantId?: string;
|
|
377
|
-
tenant?: string;
|
|
378
|
-
runId?: string;
|
|
379
|
-
leaseId?: string;
|
|
380
|
-
backend?: LeaseBackend;
|
|
381
|
-
leaseProvider?: string;
|
|
382
|
-
deviceKey?: string;
|
|
383
|
-
clientId?: string;
|
|
384
|
-
};
|
|
385
325
|
type JsonRpcId = string | number | null;
|
|
386
326
|
type JsonRpcRequestEnvelope<TParams = unknown> = {
|
|
387
327
|
jsonrpc?: string;
|
|
@@ -390,4 +330,4 @@ type JsonRpcRequestEnvelope<TParams = unknown> = {
|
|
|
390
330
|
params?: TParams;
|
|
391
331
|
};
|
|
392
332
|
//#endregion
|
|
393
|
-
export {
|
|
333
|
+
export { SnapshotNode as A, DeviceTarget as B, normalizeAgentDeviceError as C, Rect as D, RawSnapshotNode as E, SnapshotVisibility as F, PlatformSelector as H, centerOfRect as I, AppleOS as L, SnapshotQualityVerdict as M, SnapshotState as N, ScreenshotOverlayRef as O, SnapshotUnchanged as P, DeviceInfo as R, isAgentDeviceError as S, Point as T, PublicPlatform as U, Platform as V, SessionIsolationMode as _, DaemonLockPolicy as a, NormalizedError as b, DaemonResponseData as c, JsonRpcId as d, JsonRpcRequestEnvelope as f, ResponseLevel as g, ResponseCost as h, DaemonInstallSource as i, SnapshotOptions as j, SnapshotBackend as k, DaemonServerMode as l, NetworkIncludeMode as m, DaemonArtifactType as n, DaemonRequest as o, LeaseBackend as p, DaemonError as r, DaemonResponse as s, DaemonArtifact as t, DaemonTransportPreference as u, SessionRuntimeHints as v, normalizeError as w, defaultHintForCode as x, AppError as y, DeviceKind as z };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=/(token|secret|password|authorization|cookie|api[_-]?key|access[_-]?key|private[_-]?key|user[_-]?code|device[_-]?code|refresh[_-]?credential)/i,t=/\b(?:bearer\s+[a-z0-9._-]+|adc_(?:agent|live|refresh|cli)_[a-z0-9._-]+)\b/gi,n=/\b([a-z0-9_-]*(?:api[_-]?key|token|secret|password|user[_-]?code|device[_-]?code|refresh[_-]?credential)[a-z0-9_-]*)(\s*[=:]\s*)("[^"]*"|'[^']*'|\S+)/gi,r=/https?:\/\/[^\s"'<>]+/gi;function i(e){return a(e,new WeakSet)}function a(t,n,r){if(t==null)return t;if(typeof t==`string`)return o(t,r);if(typeof t!=`object`)return t;if(n.has(t))return`[Circular]`;if(n.add(t),Array.isArray(t))return t.map(e=>a(e,n));let i={};for(let[r,o]of Object.entries(t)){if(e.test(r)){i[r]=`[REDACTED]`;continue}i[r]=a(o,n,r)}return i}function o(r,i){let a=r.trim();if(!a)return r;if(i&&e.test(i))return`[REDACTED]`;let o=s(a);return o=o.replace(t,`[REDACTED]`),o=o.replace(n,(e,t,n,r,i,a)=>l({key:t,separator:n,rawValue:r,offset:i,input:a})||c(r)?e:`${t}${n}[REDACTED]`),o===a?a.length>400?`${a.slice(0,200)}...<truncated>`:a:o}function s(e){return e.replace(r,e=>u(e)??e)}function c(e){return/^adc_(?:agent|live|refresh|cli)_\.\.\.$/i.test(e)}function l(e){if(e.key.toLowerCase()!==`token`||!e.separator.includes(`:`))return!1;try{return new URL(e.rawValue).pathname.replace(/\/+$/,``)===`/api-keys`?/(?:^|\b)(?:service\/)?api\s+$/i.test(e.input.slice(0,e.offset)):!1}catch{return!1}}function u(e){try{let t=new URL(e);return t.search&&=`?REDACTED`,(t.username||t.password)&&(t.username=`REDACTED`,t.password=`REDACTED`),t.toString()}catch{return null}}function
|
|
2
|
-
`)){let e=t.trim();if(!e||
|
|
1
|
+
const e=/(token|secret|password|authorization|cookie|api[_-]?key|access[_-]?key|private[_-]?key|user[_-]?code|device[_-]?code|refresh[_-]?credential)/i,t=/\b(?:bearer\s+[a-z0-9._-]+|adc_(?:agent|live|refresh|cli)_[a-z0-9._-]+)\b/gi,n=/\b([a-z0-9_-]*(?:api[_-]?key|token|secret|password|user[_-]?code|device[_-]?code|refresh[_-]?credential)[a-z0-9_-]*)(\s*[=:]\s*)("[^"]*"|'[^']*'|\S+)/gi,r=/https?:\/\/[^\s"'<>]+/gi;function i(e){return a(e,new WeakSet)}function a(t,n,r){if(t==null)return t;if(typeof t==`string`)return o(t,r);if(typeof t!=`object`)return t;if(n.has(t))return`[Circular]`;if(n.add(t),Array.isArray(t))return t.map(e=>a(e,n));let i={};for(let[r,o]of Object.entries(t)){if(e.test(r)){i[r]=`[REDACTED]`;continue}i[r]=a(o,n,r)}return i}function o(r,i){let a=r.trim();if(!a)return r;if(i&&e.test(i))return`[REDACTED]`;let o=s(a);return o=o.replace(t,`[REDACTED]`),o=o.replace(n,(e,t,n,r,i,a)=>l({key:t,separator:n,rawValue:r,offset:i,input:a})||c(r)?e:`${t}${n}[REDACTED]`),o===a?a.length>400?`${a.slice(0,200)}...<truncated>`:a:o}function s(e){return e.replace(r,e=>u(e)??e)}function c(e){return/^adc_(?:agent|live|refresh|cli)_\.\.\.$/i.test(e)}function l(e){if(e.key.toLowerCase()!==`token`||!e.separator.includes(`:`))return!1;try{return new URL(e.rawValue).pathname.replace(/\/+$/,``)===`/api-keys`?/(?:^|\b)(?:service\/)?api\s+$/i.test(e.input.slice(0,e.offset)):!1}catch{return!1}}function u(e){try{let t=new URL(e);return t.search&&=`?REDACTED`,(t.username||t.password)&&(t.username=`REDACTED`,t.password=`REDACTED`),t.toString()}catch{return null}}const d=[`INVALID_ARGS`,`DEVICE_NOT_FOUND`,`DEVICE_IN_USE`,`TOOL_MISSING`,`APP_NOT_INSTALLED`,`UNSUPPORTED_PLATFORM`,`UNSUPPORTED_OPERATION`,`NOT_IMPLEMENTED`,`COMMAND_FAILED`,`SESSION_NOT_FOUND`,`UNAUTHORIZED`,`AMBIGUOUS_MATCH`,`REPLAY_DIVERGENCE`,`REPAIR_SESSION_EXPIRED`,`REPAIR_COMMIT_FAILED`,`UNKNOWN`];function f(e,t=`COMMAND_FAILED`){return typeof e==`string`&&e.length>0?e:t}var p=class extends Error{code;details;cause;constructor(e,t,n,r){super(t),this.code=e,this.details=n,this.cause=r}};function m(e,t=`UNKNOWN`){return e instanceof p?e:e instanceof Error?new p(t,e.message,void 0,e):new p(t,`Unknown error`,{err:e})}function h(e){return e instanceof p}function g(e,t={}){return _(e,t)}function _(e,t={}){let n=m(e),r=n.details?i(n.details):void 0,a=C(r,`diagnosticId`)??t.diagnosticId,o=C(r,`logPath`)??t.logPath,s=C(r,`hint`)??k(n.code),c=w(r,`retriable`)??O(n.code),l=C(r,`supportedOn`),u=T(r),d=y(n.code,n.message,r);return{code:n.code,message:d,hint:s,diagnosticId:a,logPath:o,...c===void 0?{}:{retriable:c},...l===void 0?{}:{supportedOn:l},details:u}}const v=/^\S+ exited with code -?\d+$/;function y(e,t,n){if(e!==`COMMAND_FAILED`||n?.processExitError!==!0)return t;let r=S(typeof n?.stderr==`string`?n.stderr:``);return r?v.test(t)?r:t.includes(r)?t:`${t}: ${r}`:t}const b=[/^an error was encountered processing the command/i,/^underlying error\b/i,/^simulator device failed to complete the requested operation/i],x=/^(?:(?:adb|xcrun|simctl):\s*)?(?:error:\s*)?/i;function S(e){for(let t of e.split(`
|
|
2
|
+
`)){let e=t.trim();if(!e||b.some(t=>t.test(e)))continue;let n=e.replace(x,``).trim();if(n)return n.length>200?`${n.slice(0,200)}...`:n}return null}function C(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function w(e,t){let n=e?.[t];return typeof n==`boolean`?n:void 0}function T(e){if(!e)return;let t={...e};return delete t.hint,delete t.diagnosticId,delete t.logPath,delete t.retriable,delete t.supportedOn,Object.keys(t).length>0?t:void 0}const E={DEVICE_IN_USE:!0};function D(e){return d.includes(e)}function O(e){return D(e)?E[e]:void 0}function k(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`APP_NOT_INSTALLED`:return`Run apps to discover the exact installed package or bundle id, or install the app before open.`;case`UNSUPPORTED_OPERATION`:return`This command is not available for the selected platform/device.`;case`UNSUPPORTED_PLATFORM`:return`This platform is not supported for the requested operation; run devices to inspect available targets.`;case`AMBIGUOUS_MATCH`:return`Multiple candidates matched. Narrow the query or pass an exact identifier.`;case`DEVICE_IN_USE`:return`The device is busy with another agent-device request; retry once it frees up.`;case`REPLAY_DIVERGENCE`:return`Read details.divergence (screen/suggestions) for repair context, or rerun with --json for the full report.`;case`REPAIR_SESSION_EXPIRED`:return`The --save-script repair session was reaped before it was finalized; re-run replay <script> --save-script from the start.`;case`REPAIR_COMMIT_FAILED`:return`The repair transaction completed, but committing its healed script failed at teardown (no-clobber refusal or a filesystem error); inspect the target path/permissions, then re-run replay <script> --save-script to retry.`;case`NOT_IMPLEMENTED`:return`This command is part of the planned API but is not implemented yet.`;case`COMMAND_FAILED`:return`Retry with --debug and inspect diagnostics log for details.`;case`UNAUTHORIZED`:return`Refresh daemon metadata and retry the command.`;case`UNKNOWN`:return`Unexpected internal error. Retry with --debug and report the diagnostics log if it persists.`;default:return`Retry with --debug and inspect diagnostics log for details.`}}function A(e){return e===`xctest`||e===`android`||e===`macos-helper`||e===`linux-atspi`||e===`web`}function j(e){return e===void 0||e===`xctest`||e===`android`}function M(e){return e.map((e,t)=>({...e,ref:`e${t+1}`}))}const N=/^~s(\d+)$/,P=`Refs look like @e12, optionally pinned to the snapshot generation that minted them: @e12~s3 (the ref, then "~s" and the refsGeneration reported by the issuing snapshot/find response).`;function F(e){let t=e.trim(),n=t.indexOf(`~`);if(n===-1)return{base:t};let r=N.exec(t.slice(n));return!r||n===0?null:{base:t.slice(0,n),generation:Number(r[1])}}function I(e){let t=F(e);if(!t)return null;let n=t.base;return n.startsWith(`@`)?n.slice(1)||null:n.startsWith(`e`)?n:null}function L(e,t){return e.find(e=>e.ref===t)??null}function R(e){return JSON.stringify({interactiveOnly:e?.interactiveOnly===!0,depth:typeof e?.depth==`number`?e.depth:null,scope:e?.scope?.trim()||null,raw:e?.raw===!0})}function z(e){if(e)return{depth:e.snapshotDepth,interactiveOnly:e.snapshotInteractiveOnly,raw:e.snapshotRaw,scope:e.snapshotScope}}function B(e){return{x:Math.round(e.x+e.width/2),y:Math.round(e.y+e.height/2)}}const V=[`summary`,`headers`,`body`,`all`],ee=[`digest`,`default`,`full`];function H(e){return e!==void 0&&e!=="default"}function U(e){return{parse(t){return e(t,`$`)}}}function W(e,t){throw Error(`${e}: ${t}`)}function G(e,t){return(!e||typeof e!=`object`||Array.isArray(e))&&W(t,`Expected an object`),e}function K(e,t){return typeof e!=`string`&&W(t,`Expected a string`),e}function q(e,t){return Number.isInteger(e)||W(t,`Expected an integer`),e}function J(e,t){return Array.isArray(e)||W(t,`Expected an array`),e}function Y(e,t,n){let r=e[t];return r===void 0?void 0:K(r,`${n}.${t}`)}function X(e,t,n){let r=e[t];if(r!==void 0)return J(r,`${n}.${t}`).map((e,r)=>K(e,`${n}.${t}[${String(r)}]`))}function Z(e,t,n){let r=e[t];return r===void 0?void 0:q(r,`${n}.${t}`)}function Q(e,t,n){let r=e[t];return r===void 0?void 0:G(r,`${n}.${t}`)}function $(e,t,n,r){let i=e[t];if(i!==void 0)return(typeof i!=`string`||!n.includes(i))&&W(`${r}.${t}`,`Expected one of: ${n.join(`, `)}`),i}const te=U((e,t)=>{let n=G(e,t);return{platform:$(n,`platform`,[`ios`,`android`],t),metroHost:Y(n,`metroHost`,t),metroPort:Z(n,`metroPort`,t),bundleUrl:Y(n,`bundleUrl`,t),launchUrl:Y(n,`launchUrl`,t)}});function ne(e,t){let n=e.id;return n==null||typeof n!=`string`&&typeof n!=`number`&&W(`${t}.id`,`Expected a string, number, or null`),n}const re=U((e,t)=>{let n=G(e,t);return{jsonrpc:Y(n,`jsonrpc`,t),id:ne(n,t),method:Y(n,`method`,t),params:n.params}}),ie=U((e,t)=>{let n=G(e,t);return{token:Y(n,`token`,t),session:Y(n,`session`,t),command:Y(n,`command`,t),positionals:X(n,`positionals`,t),input:Q(n,`input`,t),flags:Q(n,`flags`,t),runtime:Q(n,`runtime`,t),meta:Q(n,`meta`,t)}});export{O as C,_ as S,i as T,p as _,H as a,h as b,M as c,L as d,A as f,j as g,F as h,te as i,R as l,z as m,ee as n,re as o,I as p,ie as r,P as s,V as t,B as u,m as v,f as w,g as x,k as y};
|
package/dist/src/sdk-device.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e}from"./sdk-contracts.js";const t=[`ios`,`ipados`,`tvos`,`watchos`,`visionos`,`macos`],n=[`apple`,`android`,`linux`,`web`],r=[`ios`,`macos`,`android`,`linux`,`web`],i=[...n,`ios`,`macos`],a=[`mobile`,`tv`,`desktop`];function o(e){return e===`apple`||e===`ios`||e===`macos`}function s(e){return e.appleOs===`macos`||e.platform===`macos`}function c(e){return o(e.platform)&&!s(e)}function l(e){return e.platform===`android`||o(e.platform)&&!s(e)}function u(e){return o(e.platform)?s(e)?`macos`:`ios`:e.platform}function d(e){return e===`macos`?{platform:`apple`,appleOs:`macos`}:e===`ios`?{platform:`apple`}:{platform:e}}function f(e){return o(e.platform)&&e.target===`tv`}function p(e){return e.appleOs?e.appleOs:e.platform===`macos`?`macos`:f(e)?`tvos`:`ios`}function m(e){return r.includes(e)}function h(e){return t.includes(e)}function g(e,t){return t?t===`apple`?o(e.platform):t===`ios`?o(e.platform)&&!s(e):t===`macos`?o(e.platform)&&s(e):e.platform===t:!0}function _(e,t){return t?v(t):e===`macos`||e===`desktop`?`macOS`:e===`tv`?`tvOS`:`iOS`}function v(e){switch(e){case`tvos`:return`tvOS`;case`macos`:return`macOS`;case`visionos`:return`visionOS`;default:return`iOS`}}function y(e){let{simulatorSetPath:t,platform:n,target:r}=e;if(t&&!(n===`macos`||r===`desktop`))return t}function b(e){return e.map((e,t)=>({device:e,index:t})).sort((e,t)=>
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";const t=[`ios`,`ipados`,`tvos`,`watchos`,`visionos`,`macos`],n=[`apple`,`android`,`vega`,`linux`,`web`],r=[`ios`,`macos`,`android`,`vega`,`linux`,`web`],i=[...n,`ios`,`macos`],a=[`mobile`,`tv`,`desktop`];function o(e){return e===`apple`||e===`ios`||e===`macos`}function s(e){return e.appleOs===`macos`||e.platform===`macos`}function c(e){return o(e.platform)&&!s(e)}function l(e){return e.platform===`android`||o(e.platform)&&!s(e)}function u(e){return o(e.platform)?s(e)?`macos`:`ios`:e.platform}function d(e){return e===`macos`?{platform:`apple`,appleOs:`macos`}:e===`ios`?{platform:`apple`}:{platform:e}}function f(e){return o(e.platform)&&e.target===`tv`}function p(e){return e.appleOs?e.appleOs:e.platform===`macos`?`macos`:f(e)?`tvos`:`ios`}function m(e){return r.includes(e)}function h(e){return t.includes(e)}function g(e,t){return t?t===`apple`?o(e.platform):t===`ios`?o(e.platform)&&!s(e):t===`macos`?o(e.platform)&&s(e):e.platform===t:!0}function _(e,t){return t?v(t):e===`macos`||e===`desktop`?`macOS`:e===`tv`?`tvOS`:`iOS`}function v(e){switch(e){case`tvos`:return`tvOS`;case`macos`:return`macOS`;case`visionos`:return`visionOS`;default:return`iOS`}}function y(e){let{simulatorSetPath:t,platform:n,target:r}=e;if(t&&!(n===`macos`||r===`desktop`))return t}function b(e){return e.map((e,t)=>({device:e,index:t})).sort((e,t)=>A(e,t)).map(({device:e})=>e)}function x(e){return!e||e===`apple`||e===`ios`}async function S(t,n,r={}){let i=t.filter(e=>w(e,n));if(n.udid){let t=i.find(e=>e.id===n.udid&&o(e.platform));if(!t)throw new e(`DEVICE_NOT_FOUND`,`No Apple device with UDID ${n.udid}`);return t}if(n.serial){let t=i.find(e=>e.id===n.serial&&E(e.platform));if(!t)throw new e(`DEVICE_NOT_FOUND`,D(n));return t}if(r.allowStoppedAndroidAvdPlaceholders!==!0&&(i=i.filter(e=>!C(e))),n.deviceName){let t=k(n.deviceName),r=i.find(e=>k(e.name)===t);if(!r)throw new e(`DEVICE_NOT_FOUND`,`No device named ${n.deviceName}`);return r}N(i)&&(i=b(i));let a=i[0];if(a!==void 0&&i.length===1)return a;i.length===0&&O(n,r);let s=i.filter(e=>e.kind!==`device`),c=s.length>0?s:i,l=c.filter(e=>e.booted),u=l[0];if(u&&l.length===1&&!N(c))return u;let d=N(c)?c[0]:l[0]??c[0];return d||O(n,r),d}function C(e){return e.platform===`android`&&e.kind===`emulator`&&e.booted===!1&&!/^emulator-\d+$/.test(e.id)}function w(e,t,n={}){return g(e,t.platform)&&(!t.target||(e.target??`mobile`)===t.target)&&(!n.includeExplicitSelectors||T(e,t))}function T(e,t){return!(t.udid&&!(e.id===t.udid&&o(e.platform))||t.serial&&!(e.id===t.serial&&E(e.platform))||t.deviceName&&k(e.name)!==k(t.deviceName))}function E(e){return e===`android`||e===`vega`}function D(e){return e.platform===`android`?`No Android device with serial ${e.serial}`:e.platform===`vega`?`No Vega VVD with serial ${e.serial}`:`No Android device or Vega VVD with serial ${e.serial}`}function O(t,n){let r=n.simulatorSetPath;throw r&&x(t.platform)?new e(`DEVICE_NOT_FOUND`,`No devices found in the scoped simulator set`,{simulatorSetPath:r,hint:`The simulator set at "${r}" appears to be empty. Create a compatible simulator first with xcrun simctl --set "${r}" create, or remove the scoped simulator set.`,selector:t}):new e(`DEVICE_NOT_FOUND`,`No devices found`,{selector:t})}function k(e){return e.toLowerCase().replace(/_/g,` `).replace(/\s+/g,` `).trim()}function A(e,t){return j(e.device)-j(t.device)||Number(t.device.booted===!0)-Number(e.device.booted===!0)||e.device.name.localeCompare(t.device.name)||e.index-t.index}function j(e){return e.kind===`simulator`?M(e,0,1,2,3):e.kind===`device`&&o(e.platform)&&!s(e)?M(e,10,11,12,13):14}function M(e,t,n,r,i){return{mobile:P(e.name)?n:t,tv:r,desktop:i}[e.target??`mobile`]}function N(e){return e.length>0&&e.every(e=>o(e.platform))}function P(e){return/\bipad\b/i.test(e)}export{y as _,h as a,b,s as c,E as d,f,_ as g,u as h,d as i,l,g as m,i as n,o,w as p,r,c as s,a as t,m as u,S as v,p as y};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as SnapshotNode } from "./sdk-contracts.js";
|
|
2
2
|
//#region src/selectors/parse.d.ts
|
|
3
3
|
type SelectorKey = 'id' | 'role' | 'text' | 'label' | 'value' | 'appname' | 'windowtitle' | 'visible' | 'hidden' | 'editable' | 'selected' | 'focused' | 'enabled' | 'hittable';
|
|
4
4
|
type SelectorTerm = {
|
|
@@ -40,13 +40,14 @@ type FindAction = {
|
|
|
40
40
|
kind: 'wait';
|
|
41
41
|
timeoutMs?: number;
|
|
42
42
|
};
|
|
43
|
-
|
|
43
|
+
type ParsedFindArgs = {
|
|
44
44
|
locator: FindLocator;
|
|
45
45
|
query: string;
|
|
46
46
|
action: FindAction['kind'];
|
|
47
47
|
value?: string;
|
|
48
48
|
timeoutMs?: number;
|
|
49
49
|
};
|
|
50
|
+
declare function parseFindArgs(args: string[]): ParsedFindArgs;
|
|
50
51
|
//#endregion
|
|
51
52
|
//#region src/finders.d.ts
|
|
52
53
|
type FindMatchOptions = {
|
package/dist/src/sdk-finders.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{U as e}from"./sdk-batch-runner.js";function t(t,n,r,i){return e(t,n,r,typeof i==`boolean`?{requireRect:i}:i)}export{t};
|