agent-device 0.20.8 → 0.20.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -31
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.8.apk → agent-device-android-ime-helper-0.20.9.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.9.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.8.manifest.json → agent-device-android-ime-helper-0.20.9.manifest.json} +4 -4
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.8.apk → agent-device-android-snapshot-helper-0.20.9.apk} +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.9.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.8.manifest.json → agent-device-android-snapshot-helper-0.20.9.manifest.json} +6 -6
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.h +3 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.m +13 -7
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +4 -112
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+FlatSnapshotFiltering.swift +9 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXPresentation.swift +90 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +46 -10
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/agent-device-client.js +2 -2
- package/dist/src/android-adb.d.ts +5 -5
- package/dist/src/android-adb.js +1 -1
- package/dist/src/android.js +1 -1
- package/dist/src/app-helpers.js +1 -1
- package/dist/src/app-lifecycle.js +6 -7
- package/dist/src/app-lifecycle2.js +2 -2
- package/dist/src/app-log-reconnect.js +1 -1
- package/dist/src/app-log-runtime.js +3 -3
- package/dist/src/app-resolution.js +2 -2
- package/dist/src/app-state.js +2 -0
- package/dist/src/appearance.js +1 -0
- package/dist/src/apps.js +5 -5
- package/dist/src/artifacts.d.ts +1 -1
- package/dist/src/audio-probe.js +1 -1
- package/dist/src/auth-session.js +1 -1
- package/dist/src/backend-snapshot-options.js +1 -0
- package/dist/src/boot-diagnostics.js +2 -2
- package/dist/src/bounds.js +1 -0
- package/dist/src/byte-limit-stream.js +1 -0
- package/dist/src/cancel.js +1 -0
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +25 -20
- package/dist/src/cli.js +6 -6
- package/dist/src/client-metro.js +1 -1
- package/dist/src/command-catalog.js +1 -0
- package/dist/src/command-metadata.js +1 -1
- package/dist/src/command-schema.js +1 -1
- package/dist/src/command-surface.js +1 -1
- package/dist/src/config.js +1 -0
- package/dist/src/connection-runtime.js +1 -1
- package/dist/src/connection.js +3 -3
- package/dist/src/contracts.js +1 -1
- package/dist/src/debug-symbols.js +3 -3
- package/dist/src/device-claim-inspection.js +1 -1
- package/dist/src/device-input-state.js +1 -1
- package/dist/src/device-ready.js +1 -1
- package/dist/src/device2.js +2 -2
- package/dist/src/dispatch.js +1 -1
- package/dist/src/entities.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/finders.js +1 -1
- package/dist/src/generic-settle.js +1 -1
- package/dist/src/generic.js +1 -1
- package/dist/src/harmonyos.js +1 -1
- package/dist/src/hdc.js +1 -1
- package/dist/src/helper-package-install.js +1 -0
- package/dist/src/helper.js +2 -2
- package/dist/src/host-process.js +1 -1
- package/dist/src/ime-lifecycle.js +2 -9
- package/dist/src/ime-recovery-marker.js +1 -0
- package/dist/src/index.d.ts +24 -15
- package/dist/src/index.js +1 -1
- package/dist/src/input-actions.js +4 -4
- package/dist/src/input-actions2.js +1 -1
- package/dist/src/input-actions3.js +1 -1
- package/dist/src/install-artifact.js +1 -1
- package/dist/src/install-artifact2.js +1 -1
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-common.js +1 -0
- package/dist/src/interaction-runtime.js +1 -1
- package/dist/src/interaction-snapshot.js +1 -1
- package/dist/src/interaction.js +1 -1
- package/dist/src/interaction2.js +1 -0
- package/dist/src/interactor.js +2 -2
- package/dist/src/interactor2.js +1 -1
- package/dist/src/interactors.js +1 -0
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +4 -7
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/inventory.js +1 -1
- package/dist/src/keyed-lock.js +1 -0
- package/dist/src/lease-context.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/limrun-runtime-dependencies.js +1 -1
- package/dist/src/limrun.d.ts +3 -1
- package/dist/src/limrun.js +1 -1
- package/dist/src/linux.js +1 -1
- package/dist/src/location-coordinates.js +1 -0
- package/dist/src/logcat.js +1 -1
- package/dist/src/manifest.js +1 -1
- package/dist/src/observability.js +1 -0
- package/dist/src/owner-identity.js +1 -1
- package/dist/src/perf.js +4 -0
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/platform-runtime-app-log-process.js +1 -1
- package/dist/src/platform-runtime-host.js +1 -1
- package/dist/src/platform-runtime-network-web-transport.js +1 -1
- package/dist/src/platform-runtime-open-target.js +1 -0
- package/dist/src/platform-runtime-operation-host.js +4 -4
- package/dist/src/platform-runtime-runtime-hints.js +2 -0
- package/dist/src/platform-runtime-screen-recording-apple-runner-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-apple-runner-transport.js +1 -1
- package/dist/src/platform-runtime-screen-recording-apple-transport.js +1 -1
- package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-web-host.js +1 -1
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/platform-runtime2.js +1 -0
- package/dist/src/plist.js +1 -1
- package/dist/src/png-resize.js +1 -0
- package/dist/src/png-worker-contract.js +1 -1
- package/dist/src/prepare-kind.js +13 -13
- package/dist/src/process-lock.js +1 -1
- package/dist/src/project-runtime.js +1 -0
- package/dist/src/provider-webdriver.js +1 -1
- package/dist/src/provider.js +1 -0
- package/dist/src/proxy.js +1 -1
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-runtime.js +1 -1
- package/dist/src/record-trace.js +1 -1
- package/dist/src/recording-export-quality.js +1 -0
- package/dist/src/registry.js +29 -26
- package/dist/src/remote-config2.js +1 -1
- package/dist/src/replay.js +1 -1
- package/dist/src/reporting.js +3 -3
- package/dist/src/rolldown-runtime.js +1 -0
- package/dist/src/runner-client.js +1 -0
- package/dist/src/runner-disposal.js +1 -1
- package/dist/src/runner-lease.js +1 -1
- package/dist/src/runner-sequence.js +1 -1
- package/dist/src/runtime-transport.js +1 -1
- package/dist/src/runtime.js +3 -3
- package/dist/src/runtime2.js +4 -3
- package/dist/src/runtime3.js +1 -3
- package/dist/src/runtime4.js +3 -1
- package/dist/src/runtime5.js +1 -1
- package/dist/src/runtime6.js +1 -1
- package/dist/src/runtime7.js +1 -1
- package/dist/src/runtime8.js +1 -0
- package/dist/src/runtime9.js +1 -0
- package/dist/src/scoped-provider.js +1 -0
- package/dist/src/screenshot-density.js +1 -0
- package/dist/src/screenshot-geometry.js +1 -0
- package/dist/src/screenshot-result.js +4 -4
- package/dist/src/screenshot.js +1 -1
- package/dist/src/sdk-android-adb.d.ts +20 -2
- package/dist/src/sdk-android-adb.js +3 -3
- package/dist/src/sdk-batch-runner.js +3 -3
- package/dist/src/sdk-contracts.d.ts +3 -3
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-device.js +1 -1
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-io.js +1 -1
- package/dist/src/sdk-remote-config.js +1 -1
- package/dist/src/sdk-selectors.d.ts +19 -19
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/sdk.js +1 -0
- package/dist/src/selector-runtime.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 +1 -30
- package/dist/src/session2.js +28 -0
- package/dist/src/setting-state.js +1 -1
- package/dist/src/shared.js +1 -1
- package/dist/src/simctl.js +1 -0
- package/dist/src/simulator-state.js +1 -0
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-runtime.js +1 -1
- package/dist/src/snapshot-session.js +1 -1
- package/dist/src/snapshot.js +8 -1
- package/dist/src/snapshot2.js +1 -1
- package/dist/src/snapshot3.js +1 -0
- package/dist/src/src.js +1 -1
- package/dist/src/src2.js +1 -2
- package/dist/src/src3.js +2 -1
- package/dist/src/string-enum.js +1 -0
- package/dist/src/tool-provider.js +3 -3
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/update-check.js +1 -1
- package/dist/src/verdict.js +1 -0
- package/dist/src/verified-file.js +1 -0
- package/dist/src/version.js +1 -1
- package/dist/src/video.js +1 -1
- package/dist/src/web.js +1 -1
- package/package.json +8 -4
- package/server.json +3 -3
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.8.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.8.apk.sha256 +0 -1
- package/dist/src/interaction-touch-reference-frame.js +0 -1
- package/dist/src/notifications.js +0 -1
- package/dist/src/platform-runtime-toolchain-host.js +0 -1
- package/dist/src/text-surface.js +0 -1
- package/dist/src/tool-provider3.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{n as e}from"./rolldown-runtime.js";import{D as t,_ as n}from"./sdk-contracts.js";import r from"node:path";import i from"node:crypto";import{AsyncLocalStorage as a}from"node:async_hooks";import o,{constants as s}from"node:fs";import c from"node:os";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 a;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 v(){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 ne(e){e&&h.getStore()?.sensitiveValues.add(e)}function re(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 y(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?b(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&&(S(t.logPath,r),t.liveWrittenEventCount=t.events.length),t.traceLogPath&&S(t.traceLogPath,r),t.debug&&!t.logPath&&!t.traceLogPath&&process.stderr.write(`[agent-device][diag] ${r}`)}catch{}}async function ie(e,t,n){let r=Date.now();try{let i=await t();return y({level:`info`,phase:e,durationMs:Date.now()-r,data:n}),i}catch(t){throw y({level:`error`,phase:e,durationMs:Date.now()-r,data:{...n??{},error:t instanceof Error?t.message:String(t)}}),t}}function ae(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(b(t,e)));S(t.logPath,`${n.join(`
|
|
2
2
|
`)}\n`)}let n=t.logPath;return t.events=[],t.liveWrittenEventCount=0,n}let e=oe(t.session??`default`),n=new Date().toISOString().slice(0,10),i=r.join(c.homedir(),`.agent-device`,`logs`,e,n);o.mkdirSync(i,{recursive:!0});let a=new Date().toISOString().replace(/[:.]/g,`-`),s=r.join(i,`${a}-${t.diagnosticId}.ndjson`),l=t.events.map(e=>JSON.stringify(b(t,e)));return o.writeFileSync(s,`${l.join(`
|
|
3
|
-
`)}\n`),t.events=[],s}catch{return null}}function b(e,n){return x(t(n),[...e.sensitiveValues].sort((e,t)=>t.length-e.length))}function x(e,t){return typeof e==`string`?t.reduce((e,t)=>e.replaceAll(t,`[REDACTED]`),e):Array.isArray(e)?e.map(e=>x(e,t)):!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,x(n,t)]))}function oe(e){return e.replace(/[^a-zA-Z0-9._-]/g,`_`)}function S(e,t){o.mkdirSync(r.dirname(e),{recursive:!0}),o.appendFileSync(e,t,`utf8`)}const se=new Set([`1`,`true`,`yes`,`on`]),ce=new Set([`0`,`false`,`no`,`off`]);function le(e){return`AGENT_DEVICE_${e.replace(/([A-Z])/g,`_$1`).replace(/[^A-Za-z0-9_]/g,`_`).toUpperCase()}`}function ue(e,t,r,i){if(e.multiple)return(Array.isArray(t)?t:[t]).map(t=>ue({...e,multiple:!1},t,r,i));if(e.type===`boolean`)return de(t,r,i);if(e.type===`booleanOrString`){if(typeof t==`boolean`)return t;if(typeof t==`string`&&C(t)!==void 0)return C(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 fe(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)||e.type===`int`&&!Number.isInteger(a))throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected ${e.type===`int`?`integer`:`number`}.`);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 de(e,t,r){if(typeof e==`boolean`)return e;if(typeof e==`string`){let t=C(e);if(t!==void 0)return t}throw new n(`INVALID_ARGS`,`Invalid value for "${r}" in ${t}. Expected boolean.`)}function C(e){let t=e.trim().toLowerCase();if(se.has(t))return!0;if(ce.has(t))return!1}function fe(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.`)}var pe=e({coerceExecResult:()=>O,execFailureDetails:()=>V,isExecutablePath:()=>H,requireExecSuccess:()=>we,resolveExecutableOverridePath:()=>A,resolveFileOverridePath:()=>j,runCmd:()=>E,runCmdBackground:()=>F,runCmdDetached:()=>N,runCmdDetachedMonitored:()=>P,runCmdStreaming:()=>D,runCmdSync:()=>M,whichCmd:()=>_e,withCommandExecutorOverride:()=>ge,withoutCommandExecutorOverride:()=>T});const me=/^[A-Za-z0-9][A-Za-z0-9._+-]*$/,he=[`.com`,`.exe`,`.bat`,`.cmd`],w=new a;async function ge(e,t){return e?await w.run(e,t):await t()}async function T(e){return await w.run(void 0,e)}async function E(e,t,n={}){let r=w.getStore()?.(e,t,n);return r?O(await r):await k(e,t,n)}async function D(e,t,n={}){let r=w.getStore()?.(e,t,n);return r?O(await r):await k(e,t,n)}function O(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 k(e,t,n={}){let r=R(e),i=I();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=U(n.timeoutMs),m=f?setTimeout(()=>{d=!0,W(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(be(r,e,t,i)),W(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(Te(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(Se(r,e,t,f,p,c,u));return}let g=Ee(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 _e(e){let t=Oe(e);if(!t)return!1;if(r.isAbsolute(t))return H(t);let n=process.env.PATH;if(!n)return!1;let i=ke();for(let e of n.split(r.delimiter)){let n=e.trim();if(n){for(let e of Ae(t,i))if(await H(r.join(n,e)))return!0}}return!1}async function A(e,t){let r=De(e,t,`executable`);if(r){if(!await H(r))throw new n(`TOOL_MISSING`,`${t} points to a missing or non-executable file: ${r}`,{envName:t,path:r});return r}}async function j(e,t){let r=De(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 M(e,t,r={}){let i=R(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:U(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 ${U(r.timeoutMs)}ms`,{cmd:e,args:t,timeoutMs:U(r.timeoutMs)},a.error):o===`ENOENT`?z(i,e,a.error):B(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 Ce(i,e,t,l,s,c);return{stdout:s,stderr:c,exitCode:l,stdoutBuffer:o}}function N(e,t,n={}){return P(e,t,n).pid}function P(e,t,n={}){let r=p(R(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 F(e,t,n={}){let r=R(e),i=I(),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(Te(l,r,e,t,n))}),a.on(`close`,a=>{l.dispose(),i.emitBackgroundCompletion(e,t,`exit`);let d=a??1,f=Ee(l,r,e,t,d,n.allowFailure,o,s);if(f){u(f);return}c({stdout:o,stderr:s,exitCode:d})})})}}function I(){let e=v(),t=e.debug===!0,n=C(process.env.AGENT_DEVICE_EXEC_TRACE??``)===!0;if(!t&&!n)return ve();n&&e.flushOnSuccess!==!0&&_({flushOnSuccess:!0});let r=Date.now(),i=!1;return{emitForegroundCompletion:(e,t)=>{i||(i=!0,L({cmd:e,args:t,startedAtMs:r}))},emitBackgroundSpawn:(e,t)=>{L({cmd:e,args:t,data:{event:`spawn`}})},emitBackgroundCompletion:(e,t,n)=>{i||(i=!0,L({cmd:e,args:t,startedAtMs:r,data:{event:n}}))}}}function ve(){return{emitForegroundCompletion:()=>{},emitBackgroundSpawn:()=>{},emitBackgroundCompletion:()=>{}}}function L(e){let t=e.args.slice(0,6);y({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 R(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 ye(e,t,n,r){return r.code===`ENOENT`?z(e,t,r):B(e,t,n,r)}function z(e,t,r){return new n(`TOOL_MISSING`,`${e} not found in PATH`,{cmd:t},r)}function B(e,t,r,i){return new n(`COMMAND_FAILED`,`Failed to run ${e}`,{cmd:t,args:r},i)}function be(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 xe(e,t,r){return new n(`COMMAND_FAILED`,`request canceled`,{cmd:t,args:r,executable:e,reason:`request_canceled`})}function Se(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 Ce(e,t,r,i,a,o){return new n(`COMMAND_FAILED`,`${e} exited with code ${i}`,V({stdout:a,stderr:o,exitCode:i},{cmd:t,args:r}))}function we(e,t,r){if(e.exitCode===0)return e;throw new n(`COMMAND_FAILED`,t,V(e,typeof r==`function`?r(e):r))}function V(e,t){return{stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode,processExitError:!0,...t}}function Te(e,t,n,r,i){return e.didAbort?xe(t,n,r):ye(t,n,r,i)}function Ee(e,t,n,r,i,a,o,s){return e.didAbort?xe(t,n,r):i!==0&&!a?Ce(t,n,r,i,o,s):null}function De(e,t,i){let a=e?.trim();if(a){if(!r.isAbsolute(a)||a.includes(`\0`))throw new n(`INVALID_ARGS`,`${t} must be an absolute ${i} path, not ${JSON.stringify(e)}`,{envName:t,path:e});return a}}function Oe(e){let t=e.trim();return!t||t.includes(`\0`)?null:r.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 H(e){try{return await je(e)?(await d(e,process.platform===`win32`?s.F_OK:s.X_OK),!0):!1}catch{return!1}}async function je(e){try{return(await f(e)).isFile()}catch{return!1}}function U(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,W(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 W(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:()=>q,attachAdbFailureHint:()=>K,classifyAdbFailure:()=>Re,createAndroidPortReverseManager:()=>Ye,createDeviceAdbExecutor:()=>X,createLocalAndroidAdbProvider:()=>We,installAndroidAdbPackage:()=>Ze,pullAndroidAdbFile:()=>Xe,resolveAndroidAdbExecutor:()=>Ge,resolveAndroidAdbProvider:()=>Z,resolveAndroidTextInjector:()=>qe,resolveAndroidTouchProvider:()=>Je,resolveScopedAndroidAdbBackgroundTransport:()=>Ke,withAndroidAdbProvider:()=>Qe});const 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=Object.freeze({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}const G=new a;function K(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 q(e,t,r){return K(new n(`COMMAND_FAILED`,e,t.exitCode===0?{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode,...r}:V(t,r)))}function J(e){return async(...t)=>{try{return await e(...t)}catch(e){throw K(e)}}}const Be=new WeakSet;function Ve(e){if(Be.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 Be.add(t),t}function Y(e){return async(...t)=>O(await e(...t))}function X(e){return He(e.id)}function He(e){return J(async(t,n)=>await T(async()=>await E(`adb`,[`-s`,e,...t],{...n,detached:process.platform!==`win32`})))}function Ue(e){return(t,n)=>{let r=F(`adb`,[`-s`,e,...t],{...n,allowFailure:!0,captureOutput:!1});return r.wait.catch(()=>{}),r.child}}function We(e){let t=X(e);return{exec:t,spawn:Ue(e.id),reverse:nt(t),pull:async(e,n,r)=>await t([`pull`,e,n],r),install:async(e,n)=>{let{installArgs:r,execOptions:i}=at(n);return await t([`install`,...r,e],i)}}}function Ge(e,t){let n=G.getStore();return t||(n?.serial===e.id?n.provider.exec:X(e))}function Z(e,t){if(t)return Q(t);let n=G.getStore();return n?.serial===e.id?Q(n.provider):We(e)}function Ke(e){let t=G.getStore();return t?.serial===e.id?{mode:`transport-composed`,...t.provider.spawn?{spawn:t.provider.spawn}:{}}:{mode:`local`}}function qe(e){let t=G.getStore();return t?.serial===e.id?t.provider.text:void 0}function Je(e){let t=G.getStore();return t?.serial===e.id&&t.provider.touch?t.provider:void 0}function Ye(e){let t=Q(e);if(t.reverse&&tt.has(t.reverse))return t.reverse;let r=t.reverse??nt(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 tt.add(a),a}function Q(e){return Ve(typeof e==`function`?{exec:e}:e)}async function Xe(e,t,r){let{device:i,provider:a,...o}=r??{},s=$(i,a),c=s?.pull;if(c)return await T(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 T(async()=>await l([`pull`,e,t],o))}async function Ze(e,t){let{device:r,provider:i,...a}=t??{},o=$(r,i),s=o?.install;if(s)return await T(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}=at(a);return await T(async()=>await c([`install`,...l,e],u))}function $(e,t){if(t)return Q(t);if(e)return Z(e);let n=G.getStore();if(n)return Q(n.provider)}async function Qe(e,t,n){if(!e)return await n();let r={provider:Q(e),serial:t.serial},i=$e(r);return await G.run(r,async()=>await ge(i,n))}function $e(e){return(t,n,r)=>{if(t!==`adb`)return;let i=et(n,e.serial);if(i)return T(async()=>await e.provider.exec(i,r))}}function et(e,t){if(!(e[0]!==`-s`||!e[1])&&e[1]===t)return e.slice(2)}const tt=new WeakSet;function nt(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&&!it(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?rt(r.stdout,t):[]}}}function rt(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 it(e,t){let n=`${e}\n${t}`.toLowerCase();return n.includes(`listener`)&&n.includes(`not found`)}function at(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{
|
|
3
|
+
`)}\n`),t.events=[],s}catch{return null}}function b(e,n){return x(t(n),[...e.sensitiveValues].sort((e,t)=>t.length-e.length))}function x(e,t){return typeof e==`string`?t.reduce((e,t)=>e.replaceAll(t,`[REDACTED]`),e):Array.isArray(e)?e.map(e=>x(e,t)):!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,x(n,t)]))}function oe(e){return e.replace(/[^a-zA-Z0-9._-]/g,`_`)}function S(e,t){o.mkdirSync(r.dirname(e),{recursive:!0}),o.appendFileSync(e,t,`utf8`)}const se=new Set([`1`,`true`,`yes`,`on`]),ce=new Set([`0`,`false`,`no`,`off`]);function le(e){return`AGENT_DEVICE_${e.replace(/([A-Z])/g,`_$1`).replace(/[^A-Za-z0-9_]/g,`_`).toUpperCase()}`}function ue(e,t,r,i){if(e.multiple)return(Array.isArray(t)?t:[t]).map(t=>ue({...e,multiple:!1},t,r,i));if(e.type===`boolean`)return de(t,r,i);if(e.type===`booleanOrString`){if(typeof t==`boolean`)return t;if(typeof t==`string`&&C(t)!==void 0)return C(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 fe(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)||e.type===`int`&&!Number.isInteger(a))throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected ${e.type===`int`?`integer`:`number`}.`);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 de(e,t,r){if(typeof e==`boolean`)return e;if(typeof e==`string`){let t=C(e);if(t!==void 0)return t}throw new n(`INVALID_ARGS`,`Invalid value for "${r}" in ${t}. Expected boolean.`)}function C(e){let t=e.trim().toLowerCase();if(se.has(t))return!0;if(ce.has(t))return!1}function fe(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.`)}var pe=e({coerceExecResult:()=>O,execFailureDetails:()=>V,isExecutablePath:()=>H,requireExecSuccess:()=>we,resolveExecutableOverridePath:()=>A,resolveFileOverridePath:()=>ve,runCmd:()=>E,runCmdBackground:()=>P,runCmdDetached:()=>M,runCmdDetachedMonitored:()=>N,runCmdStreaming:()=>D,runCmdSync:()=>j,whichCmd:()=>_e,withCommandExecutorOverride:()=>ge,withoutCommandExecutorOverride:()=>T});const me=/^[A-Za-z0-9][A-Za-z0-9._+-]*$/,he=[`.com`,`.exe`,`.bat`,`.cmd`],w=new a;async function ge(e,t){return e?await w.run(e,t):await t()}async function T(e){return await w.run(void 0,e)}async function E(e,t,n={}){let r=w.getStore()?.(e,t,n);return r?O(await r):await k(e,t,n)}async function D(e,t,n={}){let r=w.getStore()?.(e,t,n);return r?O(await r):await k(e,t,n)}function O(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 k(e,t,n={}){let r=L(e),i=F();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=U(n.timeoutMs),m=f?setTimeout(()=>{d=!0,W(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(xe(r,e,t,i)),W(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(Te(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(Se(r,e,t,f,p,c,u));return}let g=Ee(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 _e(e){let t=Oe(e);if(!t)return!1;if(r.isAbsolute(t))return H(t);let n=process.env.PATH;if(!n)return!1;let i=ke();for(let e of n.split(r.delimiter)){let n=e.trim();if(n){for(let e of Ae(t,i))if(await H(r.join(n,e)))return!0}}return!1}async function A(e,t){let r=De(e,t,`executable`);if(r){if(!await H(r))throw new n(`TOOL_MISSING`,`${t} points to a missing or non-executable file: ${r}`,{envName:t,path:r});return r}}async function ve(e,t){let r=De(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 j(e,t,r={}){let i=L(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:U(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 ${U(r.timeoutMs)}ms`,{cmd:e,args:t,timeoutMs:U(r.timeoutMs)},a.error):o===`ENOENT`?R(i,e,a.error):z(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 Ce(i,e,t,l,s,c);return{stdout:s,stderr:c,exitCode:l,stdoutBuffer:o}}function M(e,t,n={}){return N(e,t,n).pid}function N(e,t,n={}){let r=p(L(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 P(e,t,n={}){let r=L(e),i=F(),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(Te(l,r,e,t,n))}),a.on(`close`,a=>{l.dispose(),i.emitBackgroundCompletion(e,t,`exit`);let d=a??1,f=Ee(l,r,e,t,d,n.allowFailure,o,s);if(f){u(f);return}c({stdout:o,stderr:s,exitCode:d})})})}}function F(){let e=v(),t=e.debug===!0,n=C(process.env.AGENT_DEVICE_EXEC_TRACE??``)===!0;if(!t&&!n)return ye();n&&e.flushOnSuccess!==!0&&_({flushOnSuccess:!0});let r=Date.now(),i=!1;return{emitForegroundCompletion:(e,t)=>{i||(i=!0,I({cmd:e,args:t,startedAtMs:r}))},emitBackgroundSpawn:(e,t)=>{I({cmd:e,args:t,data:{event:`spawn`}})},emitBackgroundCompletion:(e,t,n)=>{i||(i=!0,I({cmd:e,args:t,startedAtMs:r,data:{event:n}}))}}}function ye(){return{emitForegroundCompletion:()=>{},emitBackgroundSpawn:()=>{},emitBackgroundCompletion:()=>{}}}function I(e){let t=e.args.slice(0,6);y({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 L(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 be(e,t,n,r){return r.code===`ENOENT`?R(e,t,r):z(e,t,n,r)}function R(e,t,r){return new n(`TOOL_MISSING`,`${e} not found in PATH`,{cmd:t},r)}function z(e,t,r,i){return new n(`COMMAND_FAILED`,`Failed to run ${e}`,{cmd:t,args:r},i)}function xe(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 B(e,t,r){return new n(`COMMAND_FAILED`,`request canceled`,{cmd:t,args:r,executable:e,reason:`request_canceled`})}function Se(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 Ce(e,t,r,i,a,o){return new n(`COMMAND_FAILED`,`${e} exited with code ${i}`,V({stdout:a,stderr:o,exitCode:i},{cmd:t,args:r}))}function we(e,t,r){if(e.exitCode===0)return e;throw new n(`COMMAND_FAILED`,t,V(e,typeof r==`function`?r(e):r))}function V(e,t){return{stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode,processExitError:!0,...t}}function Te(e,t,n,r,i){return e.didAbort?B(t,n,r):be(t,n,r,i)}function Ee(e,t,n,r,i,a,o,s){return e.didAbort?B(t,n,r):i!==0&&!a?Ce(t,n,r,i,o,s):null}function De(e,t,i){let a=e?.trim();if(a){if(!r.isAbsolute(a)||a.includes(`\0`))throw new n(`INVALID_ARGS`,`${t} must be an absolute ${i} path, not ${JSON.stringify(e)}`,{envName:t,path:e});return a}}function Oe(e){let t=e.trim();return!t||t.includes(`\0`)?null:r.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 H(e){try{return await je(e)?(await d(e,process.platform===`win32`?s.F_OK:s.X_OK),!0):!1}catch{return!1}}async function je(e){try{return(await f(e)).isFile()}catch{return!1}}function U(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,W(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 W(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:()=>q,attachAdbFailureHint:()=>K,classifyAdbFailure:()=>Re,createAndroidPortReverseManager:()=>Ye,createDeviceAdbExecutor:()=>X,createLocalAndroidAdbProvider:()=>We,installAndroidAdbPackage:()=>Ze,pullAndroidAdbFile:()=>Xe,resolveAndroidAdbExecutor:()=>Ge,resolveAndroidAdbProvider:()=>Z,resolveAndroidTextInjector:()=>qe,resolveAndroidTouchProvider:()=>Je,resolveScopedAndroidAdbBackgroundTransport:()=>Ke,withAndroidAdbProvider:()=>Qe});const 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=Object.freeze({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}const G=new a;function K(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 q(e,t,r){return K(new n(`COMMAND_FAILED`,e,t.exitCode===0?{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode,...r}:V(t,r)))}function J(e){return async(...t)=>{try{return await e(...t)}catch(e){throw K(e)}}}const Be=new WeakSet;function Ve(e){if(Be.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 Be.add(t),t}function Y(e){return async(...t)=>O(await e(...t))}function X(e){return He(e.id)}function He(e){return J(async(t,n)=>await T(async()=>await E(`adb`,[`-s`,e,...t],{...n,detached:process.platform!==`win32`})))}function Ue(e){return(t,n)=>{let r=P(`adb`,[`-s`,e,...t],{...n,allowFailure:!0,captureOutput:!1});return r.wait.catch(()=>{}),r.child}}function We(e){let t=X(e);return{exec:t,spawn:Ue(e.id),reverse:nt(t),pull:async(e,n,r)=>await t([`pull`,e,n],r),install:async(e,n)=>{let{installArgs:r,execOptions:i}=at(n);return await t([`install`,...r,e],i)}}}function Ge(e,t){let n=G.getStore();return t||(n?.serial===e.id?n.provider.exec:X(e))}function Z(e,t){if(t)return Q(t);let n=G.getStore();return n?.serial===e.id?Q(n.provider):We(e)}function Ke(e){let t=G.getStore();return t?.serial===e.id?{mode:`transport-composed`,...t.provider.spawn?{spawn:t.provider.spawn}:{}}:{mode:`local`}}function qe(e){let t=G.getStore();return t?.serial===e.id?t.provider.text:void 0}function Je(e){let t=G.getStore();return t?.serial===e.id&&t.provider.touch?t.provider:void 0}function Ye(e){let t=Q(e);if(t.reverse&&tt.has(t.reverse))return t.reverse;let r=t.reverse??nt(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 tt.add(a),a}function Q(e){return Ve(typeof e==`function`?{exec:e}:e)}async function Xe(e,t,r){let{device:i,provider:a,...o}=r??{},s=$(i,a),c=s?.pull;if(c)return await T(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 T(async()=>await l([`pull`,e,t],o))}async function Ze(e,t){let{device:r,provider:i,...a}=t??{},o=$(r,i),s=o?.install;if(s)return await T(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}=at(a);return await T(async()=>await c([`install`,...l,e],u))}function $(e,t){if(t)return Q(t);if(e)return Z(e);let n=G.getStore();if(n)return Q(n.provider)}async function Qe(e,t,n){if(!e)return await n();let r={provider:Q(e),serial:t.serial},i=$e(r);return await G.run(r,async()=>await ge(i,n))}function $e(e){return(t,n,r)=>{if(t!==`adb`)return;let i=et(n,e.serial);if(i)return T(async()=>await e.provider.exec(i,r))}}function et(e,t){if(!(e[0]!==`-s`||!e[1])&&e[1]===t)return e.slice(2)}const tt=new WeakSet;function nt(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&&!it(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?rt(r.stdout,t):[]}}}function rt(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 it(e,t){let n=`${e}\n${t}`.toLowerCase();return n.includes(`listener`)&&n.includes(`not found`)}function at(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{y as A,_e as C,ue as D,C as E,ie as F,te as I,v as M,ne as N,re as O,_ as P,j as S,le as T,E as _,Xe as a,N as b,qe as c,O as d,V as f,A as g,we as h,Ze as i,ae as j,g as k,Je as l,H as m,q as n,Ge as o,pe as p,Ye as r,Z as s,Fe as t,Qe as u,P as v,T as w,D as x,M as y};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{_ as e,a as t,i as n,u as r,v as i}from"./sdk-contracts.js";import{
|
|
2
|
-
`).map(e=>e.trim()).filter(e=>e.length>0)}function
|
|
3
|
-
`],[`r`,`\r`],[`t`,` `]]);function b(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Selector expression cannot be empty`);let r=Ze(n);if(r.length===0)throw new e(`INVALID_ARGS`,`Selector expression cannot be empty`);return{raw:n,selectors:r.map(e=>Ye(e))}}function x(e){try{return b(e)}catch{return null}}function qe(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 y.has(e)}return y.has(t.toLowerCase())}function Je(e){let t=e.trim(),n=t.indexOf(`=`);if(n===-1)return null;let r=t.slice(0,n).trim().toLowerCase();if(!r||y.has(r))return null;let i=t.slice(n+1).trim();if(!i)return null;let a=et(i).trim();return a?{key:r,value:a}:null}function S(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||!qe(t))break;r+=1;let n=e.slice(0,r).join(` `).trim();n&&x(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 Ye(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Selector segment cannot be empty`);let r=Qe(n);if(r.length===0)throw new e(`INVALID_ARGS`,`Invalid selector segment: ${t}`);return{raw:n,terms:r.map(Xe)}}function Xe(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(!He.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(),a=n.slice(r+1).trim();if(!y.has(i))throw new e(`INVALID_ARGS`,`Unknown selector key: ${i}`);if(!a)throw new e(`INVALID_ARGS`,`Missing selector value for key: ${i}`);if(He.has(i)){let t=rt(a);if(t===null)throw new e(`INVALID_ARGS`,`Invalid boolean value for ${i}: ${a}`);return{key:i,value:t}}return{key:i,value:et(a)}}function Ze(t){let n=[],r=``,i=null;for(let a=0;a<t.length;a+=1){let o=t[a];if((o===`"`||o===`'`)&&!it(t,a)){i=$e(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 Qe(t){let n=[],r=``,i=null;for(let e=0;e<t.length;e+=1){let a=t.charAt(e);if((a===`"`||a===`'`)&&!it(t,e)){i=$e(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 $e(e,t){return e?e===t?null:e:t}function et(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?tt(t.slice(1,-1)):t}function tt(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=nt(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 nt(e){return Ke.get(e)??null}function rt(e){let t=et(e).toLowerCase();return t===`true`?!0:t===`false`?!1:null}function it(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}const at=[`any`,`text`,`label`,`value`,`role`,`id`],ot=[`text`,`label`,`value`,`role`,`id`];function st(e){let t=e?.toLowerCase();return t===`press`||t===`tap`?`click`:t}function ct(e){return e===`exists`||e===`wait`||e===`get_text`||e===`get_attrs`||e===`list`}function lt(e,t,n,r={}){let i=w(n);if(!i)return{matches:[],score:0};let a=0,o=[];for(let n of e){if(r.requireRect&&!n.rect)continue;let e=ut(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 ut(e,t,n){switch(t){case`role`:return dt(e.type,n);case`label`:return C(e.label,n);case`value`:return C(e.value,n);case`id`:return C(e.identifier,n);default:return Math.max(C(e.label,n),C(e.value,n),C(e.identifier,n))}}function C(e,t){let n=w(e??``);return n?n===t?2:+!!n.includes(t):0}function dt(e,t){let n=ft(e??``);return n?n===t?2:+!!n.includes(t):0}function w(e){return e.trim().toLowerCase().replace(/\s+/g,` `)}function ft(e){let t=e.trim();return t?(t=(t.split(`.`).pop()??t).replace(/XCUIElementType/gi,``).toLowerCase(),t):``}const pt=`find requires a value`,mt=`find actions: click (default; press/tap are aliases), list, focus, fill, type, exists, wait, get text, get attrs — there is no longpress/swipe find action. Run find "<text>" list to inspect every match with its @ref without acting, then dispatch the gesture on the chosen ref, e.g. longpress @eNN.`;function ht(e,t){if(e.length===0)return{ok:!1,code:`INVALID_ARGS`,message:`find requires a locator or text`};let n=vt([...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:pt}}const gt=[`exists`,`list`,`click`,`focus`];function _t(e){return gt.includes(e)}function vt(t){let n=`any`,r=0;ot.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=st(a[0]);if(_t(o))return{locator:n,query:i,action:o};if(o===`get`)return{locator:n,query:i,action:yt(a[1])};if(o===`wait`){let e=xt(a[1]);return{locator:n,query:i,action:`wait`,timeoutMs:e??void 0}}if(o===`fill`||o===`type`)return{locator:n,query:i,action:o,value:a.slice(1).join(` `)};throw new e(`INVALID_ARGS`,`Unsupported find action: ${a[0]}`,{hint:mt})}function yt(t){let n=t?.toLowerCase();if(n===`text`)return`get_text`;if(n===`attrs`)return`get_attrs`;throw new e(`INVALID_ARGS`,`find get only supports text or attrs`)}function bt(e,t){return e!==`any`||!t.includes(`=`)&&!t.includes(`||`)?null:x(t)?t:null}function xt(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}function T(e,t,n){return t.terms.every(t=>St(e,t,n))}function St(e,t,n){switch(t.key){case`id`:return E(e.identifier,String(t.value));case`role`:return E(_(e.type??``),String(t.value));case`label`:return E(e.label,String(t.value));case`value`:return E(e.value,String(t.value));case`text`:return E(Ae(e),String(t.value));case`appname`:return E(e.appName,String(t.value));case`windowtitle`:return E(e.windowTitle,String(t.value));case`visible`:return v(e)===!!t.value;case`hidden`:return!v(e)==!!t.value;case`editable`:return Be(e,n)===!!t.value;case`selected`:return e.selected===!0==!!t.value;case`focused`:return e.focused===!0==!!t.value;case`enabled`:return e.enabled!==!1==!!t.value;case`hittable`:return e.hittable===!0==!!t.value;default:return!1}}function E(e,t){return w(e??``)===w(t)}function D(e,t,n){let r=n.requireRect??!1,i=n.requireUnique??!0,a=[];for(let[o,s]of t.selectors.entries()){let t=Ot(e,s,n.platform,r);if(a.push({selector:s.raw,matches:t.count}),!(t.count===0||!t.firstNode)){if(i&&t.count!==1){if(!n.disambiguateAmbiguous||!t.disambiguated||!t.tiebreak)continue;return{node:t.disambiguated,selector:s,selectorIndex:o,matches:t.count,diagnostics:a,disambiguation:{matchCount:t.count,tiebreak:t.tiebreak,alternatives:t.candidates.filter(e=>e!==t.disambiguated)}}}return{node:t.firstNode,selector:s,selectorIndex:o,matches:t.count,diagnostics:a}}}return null}function Ct(e,t,n){let r=n.requireRect??!1;for(let[i,a]of t.selectors.entries()){let t=e.filter(e=>r&&!e.rect?!1:T(e,a,n.platform));if(t.length>0)return{selector:a,selectorIndex:i,matchedNodes:t}}return null}function wt(e,t,n){let r=n.requireRect??!1,i=[];for(let[a,o]of t.selectors.entries()){let t=Mt(e,o,n.platform,r);if(i.push({selector:o.raw,matches:t}),t>0)return{selectorIndex:a,selector:o,matches:t,diagnostics:i}}return null}const Tt=`Snapshot refs expire when the UI changes. Run snapshot -i and retry with a fresh @ref.`;function Et(e){return e.some(e=>e.matches>1)?`Add more terms to disambiguate (e.g. role=button text="Sign in"), use an @ref from snapshot -i, or use find <text> --first/--last.`:`Selector text/label values match exactly (quote multi-word values: text="Sign in"). Run snapshot -i to see current elements and refs, or use find <text> for contains matching.`}function Dt(e,t,n){if(t.length===0)return`Selector did not match: ${e}`;let r=t.map(e=>`${e.selector} -> ${e.matches}`).join(`, `);return n.unique??!0?`Selector did not resolve uniquely (${r})`:`Selector did not match (${r})`}function Ot(e,t,n,r){let i=0,a=null,o=[],s={best:null,bestVisible:!1,tie:!1},c,l=t=>(c??=h(e),Fe(t,e,c));for(let c of e)r&&!c.rect||T(c,t,n)&&(i+=1,a??=c,o.push(c),kt(s,c,l));return{count:i,firstNode:a,disambiguated:s.tie?null:s.best,tiebreak:s.tie?null:At(o,s.best,l),candidates:o}}function kt(e,t,n){if(!e.best){e.best=t;return}e.bestVisible||=n(e.best);let r=n(t);if(r!==e.bestVisible){r&&(e.best=t,e.bestVisible=!0,e.tie=!1);return}let i=Nt(t,e.best);i.result>0?(e.best=t,e.tie=!1):i.result===0&&(e.tie=!0)}function At(e,t,n){if(!t)return null;let r=null;for(let i of e)i!==t&&(!r||jt(i,r,n).result>0)&&(r=i);return r?jt(t,r,n).criterion:null}function jt(e,t,n){let r=n(e);return r===n(t)?Nt(e,t):{result:r?1:-1,criterion:`visible`}}function Mt(e,t,n,r){let i=0;for(let a of e)r&&!a.rect||T(a,t,n)&&(i+=1);return i}function Nt(e,t){let n=e.depth??0,r=t.depth??0;if(n!==r)return{result:n>r?1:-1,criterion:`deepest`};let i=Pt(e),a=Pt(t);return i===a?{result:0,criterion:null}:{result:i<a?1:-1,criterion:`smallest-area`}}function Pt(e){return e.rect?e.rect.width*e.rect.height:1/0}const Ft={act:{ambiguity:`reject-candidates`,requireRect:!0},actCoveredDiagnosis:{ambiguity:`first-match`,requireRect:!0},readText:{ambiguity:`disambiguate`,requireRect:!1},readUnique:{ambiguity:`fail-closed`,requireRect:!1},readAny:{ambiguity:`first-match`,requireRect:!1},wait:{ambiguity:`first-match`,requireRect:!1},findAct:{ambiguity:`reject-candidates`,requireRect:!0}};function It(e){return e.ambiguity===`first-match`?{requireRect:e.requireRect,requireUnique:!1}:{requireRect:e.requireRect,requireUnique:!0,disambiguateAmbiguous:e.ambiguity===`disambiguate`}}function Lt(e,t,n,r){let i=n.ambiguity,a=Ct(e,t,{...r,requireRect:n.requireRect});if(!a||a.matchedNodes.length===0)return{kind:`none`};if(i===`first-match`)return zt(a);if(i===`reject-candidates`)return a.matchedNodes.length>1?Rt(a):zt(a);let o=D(e,t,{...r,...It({ambiguity:i,requireRect:n.requireRect})});return o?{kind:`resolved`,resolution:o,matchedNodes:a.matchedNodes}:Rt(a)}function Rt(e){return{kind:`ambiguous`,selector:e.selector.raw,selectorIndex:e.selectorIndex,matchedNodes:e.matchedNodes}}function zt(e){let t=e.matchedNodes[0];return t?{kind:`resolved`,matchedNodes:e.matchedNodes,resolution:{node:t,selector:e.selector,selectorIndex:e.selectorIndex,matches:e.matchedNodes.length,diagnostics:[{selector:e.selector.raw,matches:e.matchedNodes.length}]}}:{kind:`none`}}function O(e,t){return{ok:!1,code:`INVALID_ARGS`,message:e,...t?{hint:t}:{}}}function Bt(e){return[`visible`,`hidden`,`exists`,`editable`,`selected`,`focused`,`text`].includes(e)}function Vt(e){let t=e.toLowerCase();return Bt(t)?{ok:!0,predicate:t}:O(`is requires predicate: visible|hidden|exists|editable|selected|focused|text`,Ht)}const Ht=`Use "is <predicate> <selector>" or "is <selector> <predicate>". visible|hidden|editable|selected|focused double as selector keys: a bare predicate token after the selector is read as the predicate, so write key=true (e.g. visible=true) inside the selector to use it as a filter instead.`;function Ut(e){if(Bt((e[0]??``).toLowerCase()))return e;for(let t=1;t<e.length;t+=1){let n=(e[t]??``).toLowerCase();if(Bt(n)&&x(e.slice(0,t).join(` `)))return[n,...e.slice(0,t),...e.slice(t+1)]}return e}function Wt(e){let{predicate:t,node:n,nodes:r,expectedText:i,platform:a}=e,o=Ae(n),s=Be(n,a),c=n.selected===!0,l=n.focused===!0,u=t===`text`?v(n):Gt(n,r,a),d=!1;switch(t){case`visible`:d=u;break;case`hidden`:d=!u;break;case`editable`:d=s;break;case`selected`:d=c;break;case`focused`:d=l;break;case`text`:d=o===(i??``);break}let f=t===`text`?`expected="${i??``}" actual="${o}"`:`actual=${JSON.stringify({visible:u,editable:s,selected:c,focused:l})}`;return{pass:d,actualText:o,details:f}}function Gt(e,t,n){if(n===`android`&&e.visibleToUser===!1)return!1;if(g(e.rect))return Kt(e,t);if(e.rect)return!1;if(n!==`android`&&e.hittable===!0)return!0;let r=qt(e,t,n);return r?g(r.rect)?Kt(r,t):n!==`android`&&r.hittable===!0:!1}function Kt(e,t){return Pe(e,t)}function qt(e,t,n){return Se(t,e,h(t),e=>ze(e,n)?e:null)}function Jt(e){let t=Ut(e),n=t[0]??``;return{predicate:n,split:S(t.slice(1),{preferTrailingValue:n===`text`})}}const Yt=`is requires a selector expression`,Xt=`is text requires expected text value`;function Zt(e){let{predicate:t,split:n}=Jt([...e]),r=Vt(t);if(!r.ok)return r;if(!n)return O(Yt);let i=n.rest.join(` `).trim();return r.predicate===`text`&&!i?O(Xt):r.predicate!==`text`&&n.rest.length>0?O(`is ${r.predicate} does not accept trailing values`):{ok:!0,predicate:r.predicate,selectorExpression:n.selectorExpression,expectedText:i}}function Qt(e){return e===`text`||e===`attrs`?{ok:!0,format:e}:O(`get only supports text or attrs`)}function $t(e){let t=e[0];if(t?.startsWith(`@`)){let n=e.slice(1).join(` `).trim();return{ok:!0,ref:t,...n?{label:n}:{}}}let n=e.join(` `).trim();return n?{ok:!0,selector:n}:O(`get requires @ref or selector expression`)}function en(e){return e?{ok:!0,text:e}:O(`wait requires text`)}function tn(t,n,r={}){let i=t[n];if(i===void 0)return;if(!Number.isInteger(i))throw new e(`INVALID_ARGS`,`Expected ${n} to be an integer.`);let a=i;if(r.min!==void 0&&a<r.min)throw new e(`INVALID_ARGS`,`Expected ${n} to be at least ${r.min}.`);if(r.max!==void 0&&a>r.max)throw new e(`INVALID_ARGS`,`Expected ${n} to be at most ${r.max}.`);return a}function nn(t,n,r={}){let i=t[n];if(i!==void 0){if(typeof i!=`number`||!Number.isFinite(i))throw new e(`INVALID_ARGS`,`Expected ${n} to be a finite number.`);if(r.min!==void 0&&i<r.min)throw new e(`INVALID_ARGS`,`Expected ${n} to be at least ${r.min}.`);if(r.max!==void 0&&i>r.max)throw new e(`INVALID_ARGS`,`Expected ${n} to be at most ${r.max}.`);return i}}const rn=/^#\s*agent-device:target-v(\d+)(?:\s+(\S.*))?$/,an=/^#\s*agent-device:targets-v(\d+)(?:\s+(\S.*))?$/,on=4096;function sn(e){return e.normalize(`NFC`)}function cn(e){if(e===void 0)return;let t=sn(e);return t.length>0?t:void 0}function ln(e){return sn(e)}function un(e){if(e===void 0)return;let t=sn(e).trim().replace(/\s+/g,` `);return t.length>0?t:void 0}function k(e){return Buffer.byteLength(e,`utf8`)}function dn(e,t){if(k(e)<=t)return e;let n=e.length;for(;n>0&&k(e.slice(0,n))>t;)--n;if(n>0){let t=e.charCodeAt(n-1);t>=55296&&t<=56319&&--n}return e.slice(0,n)}function fn(e){let t={};return e.id!==void 0&&(t.id=e.id),t.role=e.role,e.label!==void 0&&(t.label=e.label),t.ancestry=e.ancestry.map(pn),t.sibling=e.sibling,t.viewportOrder=e.viewportOrder,e.scrollRegion&&(t.scrollRegion=mn(e.scrollRegion)),e.rect&&(t.rect=hn(e.rect)),t.verification=e.verification,t}function pn(e){let t={role:e.role};return e.label!==void 0&&(t.label=e.label),t}function mn(e){let t={role:e.role};return e.id!==void 0&&(t.id=e.id),e.label!==void 0&&(t.label=e.label),t}function hn(e){return{x:e.x,y:e.y,width:e.width,height:e.height}}function gn(e){return JSON.stringify(fn(e))}function _n(e){return`# agent-device:target-v1 ${gn(e)}`}function vn(e){return JSON.stringify({source:fn(e.source),destination:fn(e.destination)})}function yn(e){return`# agent-device:targets-v1 ${vn(e)}`}function bn(e){let t=e.trim(),n=an.exec(t);return n?Number(n[1])===1?{kind:`v1`,evidence:xn((n[2]??``).trim())}:{kind:`future-version`}:{kind:`none`}}function xn(t){if(k(t)>8320)throw new e(`INVALID_ARGS`,`targets-v1 annotation exceeds the 8320-byte payload cap.`);let n;try{n=JSON.parse(t)}catch{throw new e(`INVALID_ARGS`,`targets-v1 annotation is not valid JSON.`)}if(typeof n!=`object`||!n||Array.isArray(n))throw new e(`INVALID_ARGS`,`targets-v1 annotation must be a JSON object.`);let r=n;if(r.source===void 0||r.destination===void 0)throw new e(`INVALID_ARGS`,`targets-v1 annotation requires source and destination evidence.`);return{source:Cn(JSON.stringify(r.source)),destination:Cn(JSON.stringify(r.destination))}}function Sn(e){let t=e.trim();if(!t.startsWith(`#`))return{kind:`none`};let n=rn.exec(t);return n?Number(n[1])===1?{kind:`v1`,evidence:Cn((n[2]??``).trim())}:{kind:`future-version`}:{kind:`none`}}function Cn(t){if(k(t)>4096)throw new e(`INVALID_ARGS`,`target-v1 annotation exceeds the ${on}-byte payload cap.`);let n;try{n=JSON.parse(t)}catch{throw new e(`INVALID_ARGS`,`target-v1 annotation is not valid JSON.`)}if(typeof n!=`object`||!n||Array.isArray(n))throw new e(`INVALID_ARGS`,`target-v1 annotation must be a JSON object.`);let r=n,i=wn(r.role,`role`),a=Tn(r.id,`id`),o=En(r.label,`label`),s=On(r.ancestry),c=An(r.sibling,`sibling`,0),l=An(r.viewportOrder,`viewportOrder`,0),u=jn(r.scrollRegion),d=Mn(r.rect),f=Nn(r.verification);return{...a===void 0?{}:{id:a},role:i,...o===void 0?{}:{label:o},ancestry:s,sibling:c,viewportOrder:l,...u?{scrollRegion:u}:{},...d?{rect:d}:{},verification:f}}function wn(t,n){if(t===void 0)throw new e(`INVALID_ARGS`,`target-v1 "${n}" is required.`);if(typeof t!=`string`)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a string.`);return Dn(ln(t),n)}function Tn(t,n){if(t===void 0)return;if(typeof t!=`string`)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a string.`);let r=cn(t);return r===void 0?void 0:Dn(r,n)}function En(t,n){if(t===void 0)return;if(typeof t!=`string`)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a string.`);let r=un(t);return r===void 0?void 0:Dn(r,n)}function Dn(t,n){if(k(t)>256)throw new e(`INVALID_ARGS`,`target-v1 "${n}" exceeds the 256-byte field cap.`);return t}function On(t){if(t===void 0)return[];if(!Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "ancestry" must be an array.`);if(t.length>8)throw new e(`INVALID_ARGS`,`target-v1 "ancestry" exceeds the 8-entry cap.`);return t.map((e,t)=>kn(e,t))}function kn(t,n){if(typeof t!=`object`||!t||Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "ancestry[${n}]" must be an object.`);let r=t,i=wn(r.role,`ancestry[${n}].role`),a=En(r.label,`ancestry[${n}].label`);return{role:i,...a===void 0?{}:{label:a}}}function An(t,n,r){if(t===void 0)return r;if(typeof t!=`number`||!Number.isSafeInteger(t)||t<0)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a non-negative integer.`);return t}function jn(t){if(t===void 0)return;if(typeof t!=`object`||!t||Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "scrollRegion" must be an object.`);let n=t,r=wn(n.role,`scrollRegion.role`),i=Tn(n.id,`id`),a=En(n.label,`scrollRegion.label`);return{role:r,...i===void 0?{}:{id:i},...a===void 0?{}:{label:a}}}function Mn(t){if(t===void 0)return;if(typeof t!=`object`||!t||Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "rect" must be an object.`);let n=t;return{x:A(n.x,`rect.x`),y:A(n.y,`rect.y`),width:A(n.width,`rect.width`),height:A(n.height,`rect.height`)}}function A(t,n){if(typeof t!=`number`||!Number.isFinite(t))throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a finite number.`);return t}function Nn(t){if(t===`verified`||t===`unverifiable`)return t;throw new e(`INVALID_ARGS`,`target-v1 "verification" must be "verified" or "unverifiable".`)}function Pn(e){let t=ln(_(e.type??``)),n=cn(e.identifier),r=un(e.label);return{...n===void 0?{}:{id:dn(n,256)},role:dn(t,256),...r===void 0?{}:{label:dn(r,256)}}}function Fn(e,t){return e.id===t.id&&e.role===t.role&&e.label===t.label}function In(e,t){let n=0;for(let r of e)Pn(r).id===t&&(n+=1);return n}function Ln(e,t){if(e.id===void 0||In(t,e.id)<=1)return e;let{role:n,label:r}=e;return{role:n,...r===void 0?{}:{label:r}}}function Rn(e,t){let n=0;for(let r of e)if(r.parentIndex===t.parentIndex){if(r.index===t.index)return n;n+=1}return 0}function zn(e,t){return{documentOrder:e.index,sibling:Rn(t,e)}}function Bn(e,t){return e.documentOrder===t.documentOrder&&e.sibling===t.sibling}function Vn(e){return{...e.id===void 0?{}:{id:e.id},role:e.role,...e.label===void 0?{}:{label:e.label}}}function Hn(e,t){return t.id===void 0?e.role===t.role&&e.label===t.label:e.id===t.id}function Un(e,t){if(e.length<t.length)return!1;for(let[n,r]of t.entries()){let t=e[n];if(!t||t.role!==r.role||r.label!==void 0&&t.label!==r.label)return!1}return!0}function Wn(e,t){let n=[];return e.id!==t.id&&n.push(`id: recorded=${e.id??`(none)`} observed=${t.id??`(none)`}`),e.role!==t.role&&n.push(`role: recorded=${e.role} observed=${t.role}`),e.label!==t.label&&n.push(`label: recorded=${e.label??`(none)`} observed=${t.label??`(none)`}`),n}function Gn(e){return e?`${e.role}${e.label?`/${e.label}`:``}`:`(missing)`}function Kn(e,t){return!t||t.role!==e.role?!0:e.label!==void 0&&t.label!==e.label}function qn(e,t){for(let[n,r]of e.entries()){let e=t[n];if(Kn(r,e))return[`ancestry[${n}]: recorded=${Gn(r)} observed=${Gn(e)}`]}return[]}function Jn(e,t,n={}){let r=[],i=_(e.type??``),a=Yn(e,n.nodes),o=M(e.label),s=M(e.value),c=M(Ae(e)),l=n.action===`fill`;a&&r.push(`id=${j(a)}`),i&&o&&r.push(l?`role=${j(i)} label=${j(o)} editable=true`:`role=${j(i)} label=${j(o)}`),o&&r.push(l?`label=${j(o)} editable=true`:`label=${j(o)}`),s&&r.push(l?`value=${j(s)} editable=true`:`value=${j(s)}`),c&&c!==o&&c!==s&&r.push(l?`text=${j(c)} editable=true`:`text=${j(c)}`),i&&l&&!r.some(e=>e.includes(`editable=true`))&&r.push(`role=${j(i)} editable=true`);let u=Xn(r);return u.length===0&&i&&u.push(l?`role=${j(i)} editable=true`:`role=${j(i)}`),u.length===0&&v(e)&&u.push(`visible=true`),u}function Yn(e,t){let n=M(e.identifier);if(!n||!t)return n;let r=Pn(e).id;return r===void 0?n:In(t,r)>1?null:n}function Xn(e){return Array.from(new Set(e))}function j(e){return JSON.stringify(e)}function M(e){return e&&e.trim()||null}function Zn(e,t){let n=e===`is`?Jt([...t]).split:S([...t]);return n?x(n.selectorExpression)?{kind:`expression`,expression:n.selectorExpression,rest:n.rest}:{kind:`invalid`}:{kind:`not-applicable`}}function Qn(e){return{platform:e.platform,...It({ambiguity:e.allowDisambiguation?`disambiguate`:`fail-closed`,requireRect:e.requireRect})}}function $n(e,t,n){let r=x(e);if(!r)return{kind:`unresolved`,reason:`parse-invalid`,matchedNodes:[]};let i=D(t,r,Qn(n));if(i){let e=t.filter(e=>n.requireRect&&!e.rect?!1:T(e,i.selector,n.platform));return{kind:`resolved`,winner:i.node,matchedNodes:e,matchCount:e.length,...i.disambiguation?{disambiguation:{tiebreak:i.disambiguation.tiebreak,matchCount:i.disambiguation.matchCount,alternatives:i.disambiguation.alternatives}}:{}}}let a=Ct(t,r,{platform:n.platform,requireRect:n.requireRect})?.matchedNodes??[];return{kind:`unresolved`,reason:a.length>0?`ambiguous`:`no-match`,matchedNodes:a}}function er(e,t,n={}){return Jn(e,t,n)}function tr(e,t,n){let r=x(e);if(!r)return;let i=D(t,r,Qn(n));if(i)return{node:i.node,basis:rr(i.selector)}}function nr(e){if(!e)return;let t=x(e);if(!t)return;let n=t.selectors.flatMap(e=>e.terms.flatMap(e=>(e.key===`label`||e.key===`text`||e.key===`id`)&&typeof e.value==`string`?[e.value]:[]));if(n.length===0)return;let r=n[0];return r&&n.every(e=>e===r)?r:void 0}function rr(e){let t=new Set(e.terms.map(e=>e.key));if(t.has(`id`))return`id`;let n=t.has(`role`),r=t.has(`label`)||t.has(`text`);return n&&r?`role-label`:r||t.has(`value`)?`label`:`other`}function ir(e,t){let n=x(e);if(!n)return e.includes(`=`)||e.includes(`||`)?null:e;let r=new Set(t.textKeys);return n.selectors.length>1?ar(n.selectors,r):or(n.selectors[0],r,new Set(t.booleanKeys))}function ar(e,t){let n=e.map(e=>{let n=e.terms.length===1?e.terms[0]:void 0;return n&&t.has(n.key)&&typeof n.value==`string`?n.value:void 0}),r=n[0];return r!==void 0&&n.every(e=>e===r)?r:null}function or(e,t,n){if(!e)return null;let r={},i=0;for(let a of e.terms){if(sr(a,t,`string`))i+=1;else if(!sr(a,n,`boolean`))return null;r[a.key]=a.value}return i<=1&&Object.keys(r).length>0?r:null}function sr(e,t,n){return t.has(e.key)&&typeof e.value===n}function cr(e){let t=x(e);if(!t||t.selectors.length!==1)return null;let n=t.selectors[0];if(!n||n.terms.length!==1)return null;let r=n.terms[0];return!r||typeof r.value!=`string`||r.key!==`id`&&r.key!==`label`&&r.key!==`text`&&r.key!==`value`?null:{key:r.key,value:r.value,raw:n.raw}}function lr(e,t){if(!t)return!1;let n=x(e);return n?n.selectors.some(e=>e.terms.some(e=>(e.key===`text`||e.key===`label`||e.key===`value`)&&typeof e.value==`string`&&e.value.includes(t))):!1}function ur(e){return b(e).selectors.map(e=>e.raw)}function dr(e){return x(e)!==null}function fr(e,t,n){let r=Ct(e,b(t),n);return r?{...r,selector:r.selector.raw}:null}function pr(e,t,n,r){let i=Lt(e,b(t),n,r);return i.kind===`resolved`?{...i,resolution:{...i.resolution,selector:i.resolution.selector.raw}}:i}function N(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}function mr(e){let t=e[0];if(t===void 0)return null;let n=N(t);if(n!==null)return{kind:`sleep`,durationMs:n};let r=N(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?N(t[1]):null;return{kind:`stable`,quietMs:t.length>0?N(t[0]):null,timeoutMs:n}}if(t.startsWith(`@`))return{kind:`ref`,rawRef:t,timeoutMs:r};let i=S(r===null?e.slice():e.slice(0,-1));return i&&i.rest.length===0&&dr(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 hr(e){let t=mr(e);return t?t.kind===`sleep`?t.durationMs:t.timeoutMs:null}const gr=24e4,P={budget:{source:`none`},envelopeMs:9e4,onTimeout:`reset-daemon`},_r={click:`settle-and-verify`,press:`settle-and-verify`,fill:`settle-and-verify`,longpress:`settle`,scroll:`settle`,back:`settle`};function vr(e){if(e!==void 0)return _r[e]}const F=new Set([`com.google.android.inputmethod.latin`,`com.samsung.android.honeyboard`,`com.touchtype.swiftkey`,`com.microsoft.swiftkey`]);function yr(e){let t=I(e.packageName),n=(e.resourceId??``).toLowerCase(),r=I(e.activeInputMethodPackage);if(t&&r&&t===r)return{inputMethodOwned:!0,source:`active-input-method`};if(r&&n.startsWith(`${r}:id/`))return{inputMethodOwned:!0,source:`active-input-method-resource`};if(t&&F.has(t))return{inputMethodOwned:!0,source:`known-ime-package`};for(let e of F)if(n.startsWith(`${e}:id/`))return{inputMethodOwned:!0,source:`known-ime-resource`};return{inputMethodOwned:!1,source:`app`}}function br(e,t,n){return yr({packageName:e,resourceId:t,activeInputMethodPackage:n}).inputMethodOwned}function xr(e){return yr(e).inputMethodOwned}function Sr(e){let t=I(e);return!!(t&&F.has(t))}function Cr(e){let t=(e??``).toLowerCase();for(let e of F)if(t.startsWith(`${e}:id/`))return!0;return!1}function wr(e,t,n){return!e&&!t?`unknown`:br(e,t,n)?`ime`:`app`}function Tr(e){for(let t of[/\bmCurMethodId=([^\s]+)/i,/\bmCurId=([^\s]+)/i,/\bmCurrentInputMethodId=([^\s]+)/i,/\bcurMethodId=([^\s]+)/i]){let n=Er(e.match(t)?.[1]);if(n)return n}}function Er(e){let t=(e??``).trim();if(t)return I((t.split(`/`)[0]??``).match(/[a-zA-Z0-9_.]+/)?.[0])}function I(e){return(e??``).trim().toLowerCase()||void 0}const Dr=`com.android.systemui`;function Or(e){let t=e??``;if(!t.startsWith(`com.android.systemui:id/`))return!1;let n=t.slice(`${Dr}:id/`.length);return/(^|_)(status_bar|navigation_bar)(_|$)/.test(n)}function kr(e){return`systemChrome`in e&&e.systemChrome===!0}function Ar(e){if(!kr(e))return e;let{systemChrome:t,...n}=e;return n}function jr(e){return e.some(kr)?e.map(Ar):e}const Mr={ios:`iOS`,ipados:`iPadOS`,tvos:`tvOS`,watchos:`watchOS`,visionos:`visionOS`,macos:`macOS`},Nr={visionos:`visionOS uses spatial input and does not support two-finger touch synthesis.`,tvos:`tvOS has no touch input — this gesture is supported on Android and the iOS simulator only.`,macos:`macOS automation has no multi-touch input — this gesture is supported on Android and the iOS simulator only.`};function Pr(t,n){if(!l(t.platform))throw Fr(n,t.platform);let r=u(t);if(!((r===`ios`||r===`ipados`)&&t.kind===`simulator`))throw r===`ios`||r===`ipados`?new e(`UNSUPPORTED_OPERATION`,`gesture ${n} is not supported on physical iOS devices`,{hint:`Two-finger gesture synthesis is iOS-simulator only — not available on physical iOS devices.`}):Fr(n,Mr[r],Nr[r])}function Fr(t,n,r){return new e(`UNSUPPORTED_OPERATION`,`gesture ${t} is not supported on ${n}`,r===void 0?void 0:{hint:r})}function Ir(e){let t=e.state??`stopped`;return{audio:`probe`,state:t,active:t===`running`,heard:!1,source:e.source,backend:e.backend,durationMs:e.durationMs,elapsedMs:e.elapsedMs??0,bucketMs:e.bucketMs,sampleCount:0,mediaElementCount:e.mediaElementCount,sourceCount:e.sourceCount??0,rmsDbfs:[],peakDbfs:[],reason:e.reason,notes:e.notes}}function Lr(e,t){let n=Vr(e),r=Rr(n),i=zr(n.rmsDbfs),a=zr(n.peakDbfs),o=[...Br(n.notes)??[],...t.notes??[]];return{audio:`probe`,state:r,active:r===`running`&&Hr(n.active,t.activeFallback??!0),heard:n.heard===!0,source:t.source,backend:R(n.backend)??t.backend,durationMs:L(n.durationMs,t.durationMs),elapsedMs:L(n.elapsedMs,t.elapsedMs),bucketMs:L(n.bucketMs,t.bucketMs),sampleCount:L(n.sampleCount,i.length),mediaElementCount:t.mediaElementCount===void 0?Ur(n.mediaElementCount):L(n.mediaElementCount,t.mediaElementCount),sourceCount:L(n.sourceCount,t.sourceCount??0),rmsDbfs:i,peakDbfs:a,startedAt:R(n.startedAt),stoppedAt:R(n.stoppedAt),reason:R(n.reason),notes:o.length>0?o:void 0}}function Rr(e){return e.state===`running`?`running`:`stopped`}function L(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function zr(e){if(!Array.isArray(e))return[];let t=[];for(let n of e)typeof n==`number`&&Number.isFinite(n)&&t.push(n);return t}function Br(e){if(Array.isArray(e))return e.filter(e=>typeof e==`string`)}function Vr(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function Hr(e,t){return typeof e==`boolean`?e:t}function R(e){return typeof e==`string`?e:void 0}function Ur(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function Wr(e){return process.platform===`darwin`&&(s(e)||a(e)&&e.kind===`simulator`||e.platform===`android`&&e.kind===`emulator`)}function Gr(e){return e.platform===`web`||Wr(e)}function Kr(e){if(typeof e!=`object`||!e)throw ei();let t=e,n=Object.keys(t).sort();if(!(t.kind===`legacy`&&z(n,[`kind`]))&&!(t.kind===`inventory`&&z(n,[`kind`,`use`])&&Yr(t.use))&&!(t.kind===`device-runtime`&&z(n,[`kind`,`use`])&&Xr(t.use))&&!(t.kind===`device-runtime`&&z(n,[`kind`,`uses`])&&qr(t.uses)))throw ei()}function qr(e){if(!Array.isArray(e)||e.length===0||!e.every(Xr))return!1;let t=e.map(Jr);return new Set(t).size===t.length}function Jr(e){return JSON.stringify({required:[...e.required].sort(),preferred:[...e.preferred].sort()})}function Yr(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.kind===`device-inventory`&&z(Object.keys(t).sort(),[`kind`])}function Xr(e){if(typeof e!=`object`||!e)return!1;let t=e,n=Zr(t.required),r=Zr(t.preferred);return!n||!r||!Qr(n)||!Qr(r)||!$r(n,r)?!1:z(Object.keys(t).sort(),[`preferred`,`required`])}function Zr(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:null}function Qr(e){return new Set(e).size===e.length}function $r(e,t){let n=new Set(e);return t.every(e=>!n.has(e))}function z(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function ei(){return TypeError(`Command platform execution must declare exactly one of legacy, inventory, or device-runtime`)}var ti=class{#e=[];#t=`open`;get disposed(){return this.#t===`disposed`}defer(e){this.#n(),this.#e.push(e)}use(e){return this.defer(async()=>await e[Symbol.asyncDispose]()),e}async[Symbol.asyncDispose](){if(this.#t===`disposed`)return;if(this.#t===`disposing`)throw TypeError(`Async cleanup stack disposal is already in progress`);this.#t=`disposing`;let e=[];for(;this.#e.length>0;){let t=this.#e.pop();if(t)try{await t()}catch(t){e.push(t)}}if(this.#t=`disposed`,e.length===1)throw e[0];if(e.length>1)throw AggregateError(e,`Multiple asynchronous cleanups failed`)}#n(){if(this.#t!==`open`)throw TypeError(`Cannot register cleanup after disposal has begun`)}},ni=class{#e;#t=`pending`;constructor(e){this.#e=e}get pending(){return this.#t===`pending`}transfer(){if(this.#t!==`pending`)throw TypeError(`Cannot transfer handle in ${this.#t} state`);return this.#t=`transferred`,this.#e}async[Symbol.asyncDispose](){this.#t===`pending`&&(this.#t=`disposed`,await this.#e[Symbol.asyncDispose]())}};function B(){return e=>{let t=ri(e.required,`required`),n=ri(e.preferred??[],`preferred`),r=n.find(e=>t.includes(e));if(r!==void 0)throw TypeError(`Runtime operation cannot be both required and preferred: ${r}`);return Object.freeze({required:t,preferred:n})}}function ri(e,t){let n=[...e];if(new Set(n).size!==n.length)throw TypeError(`Runtime use contains duplicate ${t} operations`);return Object.freeze(n)}function ii(e){if(!o(e))throw TypeError(`Unknown local runtime family: ${String(e)}`);return Object.freeze({kind:`local-family`,family:e})}function ai(e,t){let n=e.trim(),r=t.trim();if(n.length===0||r.length===0)throw TypeError(`Provider runtime owner requires non-empty provider and instance identities`);return Object.freeze({kind:`provider-runtime`,provider:n,instance:r})}function oi(e){return e.kind===`local-family`?`local:${e.family}`:`provider:${JSON.stringify([e.provider,e.instance])}`}function si(e,t){return oi(e)===oi(t)}function ci(e,t){let n={},r={};for(let i of t.required){let t=li(e.facts.operations,i);if(n[i]=t,!t.available)throw mi(i,t);r[i]=fi(e.operations,i)}for(let i of t.preferred){let t=li(e.facts.operations,i);n[i]=t,t.available&&(r[i]=fi(e.operations,i))}return Object.freeze({device:e.device,owner:e.owner,facts:Object.freeze(n),operations:Object.freeze(r)})}function li(e,t){let n=e[t];if(!ui(n))throw hi(`Runtime owner omitted the ${t} fact`);let r=di(n);if(r)return r;throw hi(`Runtime owner returned an invalid ${t} fact`)}function ui(e){return typeof e==`object`&&!!e&&`available`in e}function di(e){if(e.available===!0)return Object.freeze({available:!0});if(e.available===!1&&pi(e.reason)&&!(e.hint!==void 0&&typeof e.hint!=`string`))return Object.freeze({available:!1,reason:e.reason,...e.hint===void 0?{}:{hint:e.hint}})}function fi(e,t){let n=e[t];if(typeof n!=`function`)throw hi(`Runtime owner advertised ${t} without an implementation`);return n}function pi(e){return e===`unsupported-platform-leaf`||e===`unsupported-device-kind`||e===`unsupported-device-backend`||e===`unsupported-provider-mode`||e===`owner-capability-missing`}function mi(t,n){return new e(`UNSUPPORTED_OPERATION`,`Runtime operation ${t} is unavailable`,{reason:n.reason,hint:n.hint})}function hi(t){return new e(`COMMAND_FAILED`,t,{reason:`runtime-contract-invalid`,hint:`This is an agent-device runtime contract bug; report the selected device and command.`})}function gi(e){return e.status===`cleaned`||e.status===`already-missing`}const _i=`app-log`,vi=`screen-recording`,yi=B(),bi=yi({required:[`screenRecordingStart`]}),xi=yi({required:[`screenRecordingReattach`,`screenRecordingCleanup`]}),Si=yi({required:[]}),Ci=yi({required:[],preferred:[`screenRecordingStart`]}),wi=Object.freeze([bi,xi]);function Ti(t){switch((t.action??``).toLowerCase()){case`start`:if(!Ei(t.scope??`app`))throw new e(`INVALID_ARGS`,`record scope must be app, device, or system`);return Object.freeze({kind:`start`,use:bi});case`stop`:return t.hasLiveHandle===!0?Object.freeze({kind:`stop-live`,use:Si}):Object.freeze({kind:`stop-recovery`,use:xi});default:throw new e(`INVALID_ARGS`,`record requires start or stop`)}}function Ei(e){return e===`app`||e===`device`||e===`system`}function Di(e){if(Kr(e),e.kind!==`device-runtime`||!(`uses`in e))throw ki();let t=e.uses.map(Oi),n=wi.map(Oi),r=new Set(t),i=new Set(n);if(t.length!==n.length||r.size!==t.length||[...r].some(e=>!i.has(e)))throw ki()}function Oi(e){return JSON.stringify({required:[...e.required].sort(),preferred:[...e.preferred].sort()})}function ki(){return TypeError(`Record runtime execution must declare exactly the uses selected by its two runtime-bearing plans`)}const Ai=B(),ji=Ai({required:[`networkDump`]}),Mi=Ai({required:[],preferred:[`networkDump`]}),Ni=[`dump`,`log`],Pi=[`summary`,`headers`,`body`,`all`];function Fi(t){let n=(t.action??`dump`).toLowerCase(),r=(t.include??`summary`).toLowerCase();if(!Ii(n))throw new e(`INVALID_ARGS`,`network requires dump or log`);if(!Li(r))throw new e(`INVALID_ARGS`,`network --include must be summary, headers, body, or all`);return Object.freeze({action:n,include:r,use:ji})}function Ii(e){return Ni.some(t=>t===e)}function Li(e){return Pi.some(t=>t===e)}const Ri=B(),V=Ri({required:[`appLogInspect`]}),zi=Ri({required:[`appLogInspect`,`appLogDoctor`]}),Bi=Ri({required:[`appLogInspect`,`appLogStart`]}),Vi=Ri({required:[],preferred:[`appLogInspect`]}),Hi=Object.freeze([V,zi,Bi]);function Ui(t){let n=(t.action??`path`).toLowerCase();if(t.restart&&n!==`clear`)throw new e(`INVALID_ARGS`,`logs --restart is only supported with logs clear`);switch(n){case`path`:return Object.freeze({kind:`path`,requiresAppSession:!1,use:V});case`start`:return Object.freeze({kind:`start`,requiresAppSession:!0,use:Bi});case`stop`:return Object.freeze({kind:`stop`,requiresAppSession:!1,use:V});case`doctor`:return Object.freeze({kind:`doctor`,requiresAppSession:!1,use:zi});case`mark`:return Object.freeze({kind:`mark`,marker:t.marker??``,requiresAppSession:!1,use:V});case`clear`:return t.restart?Object.freeze({kind:`clear-restart`,requiresAppSession:!0,use:Bi}):Object.freeze({kind:`clear`,requiresAppSession:!1,use:V});default:throw new e(`INVALID_ARGS`,`logs requires path, start, stop, doctor, mark, or clear`)}}function Wi(e){let t=new Map;for(let n of e){if(!o(n.family))throw TypeError(`Unknown platform family registration: ${String(n.family)}`);if(t.has(n.family))throw TypeError(`Duplicate platform family registration: ${n.family}`);t.set(n.family,Gi(n))}let n=c.filter(e=>!t.has(e));if(n.length>0)throw TypeError(`Missing platform family registrations: ${n.join(`, `)}`);let r=Object.freeze([...c]),i=Object.freeze(r.map(e=>Ki(t,e)));return Object.freeze({families:r,modules:i,get:e=>Ki(t,e)})}function Gi(e){return Object.freeze({...e})}function Ki(e,t){let n=e.get(t);if(!n)throw TypeError(`Missing platform family registration: ${t}`);return n}const qi=Object.freeze({kind:`device-inventory`}),Ji={leaseAdmissionExempt:!0,sessionExecutionLockExempt:!0},H={leaseAdmissionExempt:!0,sessionExecutionLockExempt:!0,selectorValidationExempt:!0},Yi=()=>!0,Xi=e=>(e.positionals?.[0]??``).toLowerCase()===`start`,Zi=e=>e.command===`test`&&(typeof e.flags?.shardAll==`number`||typeof e.flags?.shardSplit==`number`),Qi=new Set([`status`,`get`]),$i=e=>aa(e,Qi,`status`),ea=new Set([`get`,`wait`]),ta=e=>aa(e,ea,`get`),na=e=>oa(e,Qi,`status`),ra=e=>oa(e,ea,`get`),ia=e=>{try{return ct(vt(e.positionals??[]).action)?`observes-app`:`mutates-app`}catch{return`mutates-app`}};function aa(e,t,n){return t.has((e.positionals?.[0]??n).toLowerCase())?`preserve`:`may-invalidate`}function oa(e,t,n){return t.has((e.positionals?.[0]??n).toLowerCase())?`observes-app`:`mutates-app`}const U={simulator:!0,device:!0},W={emulator:!0,device:!0,unknown:!0},sa={emulator:!0},G={device:!0},K={},q={apple:U,android:W,linux:G},ca={...q,vega:sa},la={apple:U,android:W,linux:K},ua={apple:U,android:W,linux:K},J={recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:U,android:W,linux:G},timeoutPolicy:P,batchable:!0},Y={...P,onTimeout:`preserve-daemon`},da={...P,envelopeMs:18e4},fa={...P,budget:{source:`flag`,envelope:`widen`,defaultBudgetMs:1e4},onTimeout:`preserve-daemon`},pa={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}}},ma={fields:{delayMs:{defaultValue:0}}};function X(e,t){return vr(e)===void 0?t:fa}function Z(e){let t=vr(e);if(t===void 0)throw Error(`Missing post-action observation descriptor support for ${e}`);return t}const ha=[{name:`lease_allocate`,catalog:{group:`internal`,key:`leaseAllocate`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...Ji},timeoutPolicy:P,batchable:!1},{name:`lease_heartbeat`,catalog:{group:`internal`,key:`leaseHeartbeat`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...Ji},timeoutPolicy:P,batchable:!1},{name:`lease_release`,catalog:{group:`internal`,key:`leaseRelease`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...Ji},timeoutPolicy:P,batchable:!1},{name:`artifacts`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...Ji},timeoutPolicy:P,batchable:!1},{name:`session_list`,catalog:{group:`internal`,key:`sessionList`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,...H},timeoutPolicy:P,batchable:!1},{name:`session_save_script`,catalog:{group:`internal`,key:`sessionSaveScript`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`publication`},timeoutPolicy:P,batchable:!1},{name:`devices`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,...H},timeoutPolicy:P,batchable:!0,platformExecution:{kind:`inventory`,use:qi}},{name:`capabilities`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,preferExplicitDeviceOverExistingSession:!0,...H},timeoutPolicy:P,batchable:!0},{name:`doctor`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,allowSessionlessDefaultDevice:Yi,...H},timeoutPolicy:P,batchable:!0},{name:`apps`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,preferExplicitDeviceOverExistingSession:!0},capability:la,timeoutPolicy:P,batchable:!0},{name:`boot`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`may-invalidate`,sessionKind:`state`},capability:{apple:U,android:W,linux:K},timeoutPolicy:P,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:K},timeoutPolicy:P,batchable:!0},{name:`appstate`,catalog:{group:`public`,key:`appState`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`state`},capability:{apple:U,android:W,linux:K},timeoutPolicy:P,batchable:!0},{name:`perf`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},capability:{apple:U,android:W,linux:K},timeoutPolicy:P,batchable:!0},{name:`logs`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},platformExecution:{kind:`device-runtime`,uses:Hi},timeoutPolicy:P,batchable:!0},{name:`events`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`,allowInvalidRecording:!0,...H},timeoutPolicy:P,batchable:!1},{name:`network`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},platformExecution:{kind:`device-runtime`,use:ji},timeoutPolicy:P,batchable:!0},{name:`audio`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},capability:{apple:U,android:{emulator:!0},linux:K},timeoutPolicy:P,batchable:!0},{name:`replay`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,sessionKind:`replay`,skipSessionlessProviderDevice:Zi,saveScriptFlagOwner:!0},timeoutPolicy:{...P,budget:{source:`flag`}},batchable:!1},{name:`test`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,sessionKind:`replay`,skipSessionlessProviderDevice:Zi},timeoutPolicy:{...P,envelopeMs:`unbounded`},batchable:!0},{name:`runtime`,catalog:{group:`internal`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`},timeoutPolicy:P,batchable:!1},{name:`clipboard`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`session`,refFrameEffect:`preserve`},dispatch:{},capability:{apple:U,android:W,linux:G},timeoutPolicy:P,batchable:!0},{name:`keyboard`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:na,daemon:{route:`session`,refFrameEffect:$i,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:U,android:W,linux:K},timeoutPolicy:P,batchable:!0},{name:`install`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},capability:ua,timeoutPolicy:da,batchable:!0},{name:`reinstall`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},capability:ua,timeoutPolicy:da,batchable:!0},{name:`install_source`,catalog:{group:`internal`,key:`installSource`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},timeoutPolicy:da,batchable:!1},{name:`release_materialized_paths`,catalog:{group:`internal`,key:`releaseMaterializedPaths`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,...H},timeoutPolicy:P,batchable:!1},{name:`push`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:{simulator:!0},android:W,linux:K},timeoutPolicy:P,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:U,android:W,linux:K},timeoutPolicy:P,batchable:!0},{name:`open`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`,allowSessionlessDefaultDevice:Yi,saveScriptFlagOwner:!0},dispatch:{},capability:ca,timeoutPolicy:P,batchable:!0},{name:`prepare`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`},capability:{apple:U,android:{},linux:K},timeoutPolicy:{budget:{source:`flag`},envelopeMs:gr,onTimeout:`reset-daemon`},batchable:!1,mcpExposed:!1},{name:`batch`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`},timeoutPolicy:P,batchable:!1},{name:`close`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`,allowInvalidRecording:!0,saveScriptFlagOwner:!0},dispatch:{},capability:ca,timeoutPolicy:P,batchable:!0},{name:`snapshot`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},dispatch:{},capability:q,timeoutPolicy:{...Y,budget:{source:`flag`}},batchable:!0},{name:`diff`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},capability:q,timeoutPolicy:P,batchable:!0},{name:`wait`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,targetIdentityVerification:`post-resolution`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},capability:q,timeoutPolicy:{...Y,budget:{source:`positional-parser`,parser:hr}},batchable:!0},{name:`alert`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:ra,daemon:{route:`snapshot`,refFrameEffect:ta},capability:{apple:U,android:W,linux:K},timeoutPolicy:P,batchable:!0},{name:`settings`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`snapshot`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:U,android:W,linux:K},timeoutPolicy:P,batchable:!0},{name:`react-native`,catalog:{group:`public`,key:`reactNative`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`reactNative`,refFrameEffect:`may-invalidate`},capability:{apple:U,android:W,linux:K},timeoutPolicy:P,batchable:!0},{name:`record`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`recordTrace`,refFrameEffect:`preserve`,allowInvalidRecording:!0,allowSessionlessDefaultDevice:Xi},platformExecution:{kind:`device-runtime`,uses:wi},timeoutPolicy:P,batchable:!0},{name:`trace`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`recordTrace`,refFrameEffect:`preserve`},timeoutPolicy:P,batchable:!0},{name:`find`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:ia,daemon:{route:`find`,refFrameEffect:`may-invalidate`},capability:q,timeoutPolicy:Y,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:U,android:W,linux:G},timeoutPolicy:X(`click`,Y),postActionObservation:Z(`click`),responseDataTransform:pa,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:U,android:W,linux:G},timeoutPolicy:X(`fill`,Y),postActionObservation:Z(`fill`),responseDataTransform:ma,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:U,android:W,linux:G},timeoutPolicy:{...fa,envelopeMs:21e4},postActionObservation:Z(`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:U,android:W,linux:G},timeoutPolicy:X(`press`,Y),postActionObservation:Z(`press`),responseDataTransform:pa,batchable:!0},{name:`type`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:q,timeoutPolicy:X(`type`,Y),batchable:!0},{name:`get`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`interaction`,refFrameEffect:`preserve`},capability:q,timeoutPolicy:X(`get`,Y),batchable:!0},{name:`read`,catalog:{group:`dispatch-alias`},recordsSessionAction:!1,dispatch:{},timeoutPolicy:P,batchable:!1},{name:`is`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`interaction`,refFrameEffect:`preserve`},capability:q,timeoutPolicy:X(`is`,Y),batchable:!0},{name:`back`,catalog:{group:`public`},...J,capability:{...J.capability,vega:sa},timeoutPolicy:X(`back`,P),postActionObservation:Z(`back`)},{name:`gesture`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,targetIdentityVerification:`pre-dispatch`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},capability:q,timeoutPolicy:P,batchable:!0},{name:`home`,catalog:{group:`public`},...J,capability:{...J.capability,vega:sa}},{name:`tv-remote`,catalog:{group:`public`,key:`tvRemote`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:U,android:W,vega:sa,linux:K},timeoutPolicy:P,batchable:!0},{name:`orientation`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:U,android:W,linux:K},timeoutPolicy:P,batchable:!0},{name:`scroll`,catalog:{group:`public`},...J,timeoutPolicy:X(`scroll`,P),postActionObservation:Z(`scroll`)},{name:`swipe`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},capability:{apple:U,android:W,linux:G},timeoutPolicy:P,batchable:!0},{name:`focus`,catalog:{group:`public`},...J},{name:`screenshot`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`generic`,refFrameEffect:`preserve`},dispatch:{},capability:q,timeoutPolicy:P,batchable:!0},{name:`viewport`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:{},android:{},linux:K},timeoutPolicy:P,batchable:!1},{name:`app-switcher`,catalog:{group:`public`,key:`appSwitcher`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:U,android:W,linux:K},timeoutPolicy:P,batchable:!0},{name:`install-from-source`,catalog:{group:`public`,key:`installFromSource`},recordsSessionAction:!0,recordingEffect:`mutates-app`,capability:ua,timeoutPolicy:P,batchable:!0},{name:`debug`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:P,batchable:!1},{name:`daemon`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:P,batchable:!1,mcpExposed:!1},{name:`device`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:P,batchable:!1,mcpExposed:!1},{name:`metro`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:P,batchable:!1},{name:`session`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:P,batchable:!1},{name:`cdp`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:P,batchable:!1,mcpExposed:!1},{name:`auth`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:P,batchable:!1,mcpExposed:!1},{name:`connect`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:P,batchable:!1,mcpExposed:!1},{name:`connection`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:P,batchable:!1,mcpExposed:!1},{name:`disconnect`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:P,batchable:!1,mcpExposed:!1},{name:`mcp`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:P,batchable:!1,mcpExposed:!1},{name:`proxy`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:P,batchable:!1,mcpExposed:!1},{name:`react-devtools`,catalog:{group:`local-cli`,key:`reactDevtools`},recordsSessionAction:!1,timeoutPolicy:P,batchable:!1,mcpExposed:!1},{name:`web`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:P,batchable:!1,mcpExposed:!1}],ga=new Set([`public`,`local-cli`]),_a=new Set(ha.filter(e=>ga.has(Ca(e))).map(e=>e.name)),Q=ha.map(e=>{let t=`platformExecution`in e?e.platformExecution:{kind:`legacy`};return Kr(t),e.name===`record`&&Di(t),{...e,mcpExposed:xa(e),platformExecution:t}});function va(e){return Q.filter(t=>Ca(t)===e).map(e=>[wa(e),e.name])}function ya(){return Q.filter(e=>Sa(e)).map(e=>e.name).sort()}const $=new Map(Q.map(e=>[e.name,e]));function ba(e){return _a.has(e)}function xa(e){return e.mcpExposed??_a.has(e.name)}function Sa(e){return e.mcpExposed&&ba(e.name)}function Ca(e){return e.catalog.group}function wa(e){return e.catalog.key??e.name}const Ta=new Map(Q.map(e=>[e.name,e.timeoutPolicy])),Ea=new Map(Array.from($.values()).flatMap(e=>e.responseDataTransform?[[e.name,e.responseDataTransform]]:[]));function Da(e){if(e!==void 0)return $.get(e)?.postActionObservation}function Oa(e){return Da(e)!==void 0}function ka(e){return Da(e)===`settle-and-verify`}function Aa(e){return e===void 0?P:Ta.get(e)??P}function ja(e){if(e!==void 0)return Ea.get(e)}function Ma(e){return e===void 0?!1:$.get(e)?.recordsSessionAction??!1}function Na(e){return $.get(e)?.targetIdentityVerification}function Pa(e){let t=$.get(e.command);if(t?.recordsSessionAction)return typeof t.recordingEffect==`function`?t.recordingEffect(e):t.recordingEffect}function Fa(){return[...new Set(Array.from(Ea.values()).flatMap(e=>Object.keys(e.fields)))].sort()}function Ia(e){return Number.isInteger(e)&&e>=1&&e<=1e3}function La(t,n){if(t>n)throw new e(`INVALID_ARGS`,`batch has ${t} steps; max allowed is ${n}.`)}function Ra(t,n){if(!d(t))throw new e(`INVALID_ARGS`,`Invalid batch step ${n}.`);return t}function za(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 Ba(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 Va(e){let t=e.trim();if(!t||/\s/.test(t))return!1;let n=/^([A-Za-z][A-Za-z0-9+.-]*):(.+)$/.exec(t);if(!n)return!1;let r=n[1]?.toLowerCase(),i=n[2]??``;return r===`http`||r===`https`||r===`ws`||r===`wss`||r===`ftp`||r===`ftps`?i.startsWith(`//`):!0}function Ha(e){let t=e.trim().split(`:`)[0]?.toLowerCase();return t===`http`||t===`https`}function Ua(e,t){let n=e?.trim();if(n)return n;if(Ha(t))return`com.apple.mobilesafari`}function Wa(e){let t=[];for(let n of e)n.daemon&&t.push({command:n.name,...n.daemon,replayScopedAction:n.recordsSessionAction});return t}function Ga(e){let t={};for(let n of e)n.capability&&(t[n.name]=n.capability);return t}function Ka(e){return e.filter(e=>e.batchable).map(e=>e.name)}const qa=Ka(Q),Ja=new Set([`batch`,`replay`]),Ya=[`command`,`positionals`,`input`,`flags`,`runtime`],Xa=[`platform`,`target`,`device`,`udid`,`serial`,`verbose`,`out`],Za=new Set(qa);function Qa(e){return Za.has(e)}function $a(e){return typeof e==`string`?e.trim().toLowerCase():``}function eo(t,n){let r=$a(t);if(Qa(r))return r;throw new e(`INVALID_ARGS`,`Batch step ${n} command is not available through command batch: ${String(t)}`)}function to(t,n){if(Ja.has(t))throw new e(`INVALID_ARGS`,`Batch step ${n} cannot run ${t}.`)}const no=new Set(Ya);async function ro(e,t,n){let r=uo(e.flags),a=r?.batchOnError??`stop`;if(a!==`stop`)return fo(`INVALID_ARGS`,`Unsupported batch on-error mode: ${a}.`);let o=r?.batchMaxSteps??100;if(!Ia(o))return fo(`INVALID_ARGS`,`Invalid batch max-steps: ${String(r?.batchMaxSteps)}`);try{let i=io(r?.batchSteps,o),a=Date.now(),s=[];for(let[r,a]of i.entries()){let o=await lo(e,t,a,n,r+1,r===i.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:r,total:i.length,partialResults:s}}};s.push(o.result)}return{ok:!0,data:{total:i.length,executed:i.length,totalDurationMs:Date.now()-a,results:s}}}catch(e){let t=i(e);return fo(t.code,t.message,t.details)}}function io(t,n){if(!Array.isArray(t)||t.length===0)throw new e(`INVALID_ARGS`,`batch requires a non-empty batchSteps array.`);La(t.length,n);let r=[];for(let n=0;n<t.length;n+=1){let i=t[n];if(!m(i))throw new e(`INVALID_ARGS`,`Invalid batch step at index ${n}.`);let a=Object.keys(i).filter(e=>!no.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=$a(i.command);if(!o)throw new e(`INVALID_ARGS`,`Batch step ${n+1} requires command.`);if(to(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&&!m(i.flags))throw new e(`INVALID_ARGS`,`Batch step ${n+1} flags must be an object.`);if(i.input!==void 0&&!m(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:Ba(i.runtime,n+1)})}return r}function ao(e,t){let{batchSteps:n,batchOnError:r,batchMaxSteps:i,...a}=t??{};return oo(uo(e),a)}function oo(e,t){let n=uo(e)??{},r=t;for(let e of Xa)r[e]===void 0&&n[e]!==void 0&&(r[e]=n[e]);return t}function so(e,n){return t(e)?n?e:`digest`:e}function co(e,t){let n=e?.responseLevel,r=so(n,t);return r===n?e:{...e,responseLevel:r}}async function lo(e,t,n,r,i,a){let o=Date.now(),s=ao(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:co(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 uo(e){return e}function fo(e,t,n){return{ok:!1,error:{code:e,message:t,...n?{details:n}:{}}}}export{jr as $,oe as $n,Ft as $t,Fi as A,Me as An,Hn as At,oi as B,Se as Bn,gn as Bt,ja as C,Re as Cn,M as Ct,Vi as D,ze as Dn,Wn as Dt,Wi as E,Ie as En,qn as Et,_i as F,De as Fn,on as Ft,Gr as G,m as Gn,Yt as Gt,si as H,be as Hn,tn as Ht,gi as I,Ee as In,yn as It,Lr as J,ce as Jn,Zt as Jt,Wr as K,ue as Kn,$t as Kt,ii as L,we as Ln,_n as Lt,Ci as M,_ as Mn,zn as Mt,xi as N,Te as Nn,Rn as Nt,Ui as O,je as On,Fn as Ot,vi as P,g as Pn,Bn as Pt,Or as Q,ae as Qn,Ut as Qt,ci as R,Ce as Rn,bn as Rt,Ma as S,v as Sn,Jn as St,Na as T,Fe as Tn,Ln as Tt,ti as U,_e as Un,nn as Ut,B as V,xe as Vn,k as Vt,ni as W,ge as Wn,Xt as Wt,Dr as X,re as Xn,Vt as Xt,Pr as Y,ie as Yn,en as Yt,kr as Z,se as Zn,Wt as Zt,ka as _,qe as _n,er as _t,Ga as a,at as an,Cr as at,ya as b,x as bn,$n as bt,Ha as c,ht as cn,mr as ct,Ia as d,st as dn,fr as dt,Tt as en,ne as er,Ar as et,Ba as f,vt as fn,ir as ft,Oa as g,Ge as gn,lr as gt,Q as h,Je as hn,pr as ht,eo as i,Et as in,Sr as it,Ti as j,ke as jn,Pn as jt,Mi as k,Le as kn,Un as kt,Ua as l,lt as ln,N as lt,Ra as m,Ue as mn,cr as mt,ro as n,Dt as nn,ve as nr,yr as nt,Wa as o,pt as on,Tr as ot,za as p,bt as pn,ur as pt,Ir as q,le as qn,Qt as qt,qa as r,D as rn,d as rr,xr as rt,Va as s,mt as sn,gr as st,oo as t,wt as tn,ye as tr,wr as tt,La as u,ct as un,dr as ut,Fa as v,b as vn,nr as vt,Aa as w,Pe as wn,Vn as wt,Pa as x,Be as xn,tr as xt,va as y,S as yn,Zn as yt,ai as z,h as zn,Sn as zt};
|
|
1
|
+
import{_ as e,a as t,i as n,u as r,v as i}from"./sdk-contracts.js";import{T as a,c as o,d as s,l as c,n as l,s as u,x as d}from"./sdk-device.js";function f(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ee(t,n,r,i){let a=r(t[n]);if(a===void 0)throw new e(`COMMAND_FAILED`,i,{response:t});return a}function te(e,t,n){return n(e[t])}function ne(e,t,n){let r=e[t];return r===null?null:n(r)}function re(e,t){return ee(e,t,fe,`Daemon response is missing "${t}".`)}function ie(e,t){return te(e,t,fe)}function ae(e,t){return ne(e,t,fe)}function oe(e,t){return ee(e,t,pe,`Daemon response is missing numeric "${t}".`)}function se(e,t){return ee(e,t,me,`Daemon response has invalid "${t}".`)}function ce(e,t){return ee(e,t,he,`Daemon response has invalid "${t}".`)}function le(e,t){return te(e,t,ge)??`mobile`}function ue(e){if(!m(e))return;let t=p(e,`x`),n=p(e,`y`),r=p(e,`width`),i=p(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 de(e){if(!m(e))return;let t=p(e,`x`),n=p(e,`y`);if(!(t===void 0||n===void 0))return{x:t,y:n}}function p(e,t){let n=e[t];return typeof n==`number`?n:void 0}function fe(e){return typeof e==`string`&&e.length>0?e:void 0}function pe(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function me(e){return e===`apple`?`ios`:e===`ios`||e===`macos`||e===`android`||e===`harmonyos`||e===`vega`||e===`linux`||e===`web`?e:void 0}function he(e){return e===`simulator`||e===`emulator`||e===`device`?e:void 0}function ge(e){return e===`tv`||e===`mobile`||e===`desktop`?e:void 0}function _e(t){if(!m(t))throw new e(`COMMAND_FAILED`,`Daemon returned an unexpected response shape.`,{value:t});return t}function m(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ve(e){return m(e)?e:void 0}function ye(e){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t}function be(e){return e.split(`
|
|
2
|
+
`).map(e=>e.trim()).filter(e=>e.length>0)}function h(e,t){return{ok:!1,code:`INVALID_ARGS`,message:e,...t?{hint:t}:{}}}function g(e){return!!(e&&[e.x,e.y,e.width,e.height].every(Number.isFinite)&&e.width>0&&e.height>0)}function xe(e,t){return t.x>=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height}function Se(e){return e.width*e.height}function Ce(e,t,n){return t>=e.x&&t<=e.x+e.width&&n>=e.y&&n<=e.y+e.height}function _(e){let t=null,n=-1;for(let r of e){let e=r.width*r.height;e>n&&(t=r,n=e)}return t}function we(e,t){return Te(e.x,e.x+e.width,t.x,t.x+t.width)&&Te(e.y,e.y+e.height,t.y,t.y+t.height)}function Te(e,t,n,r){return Math.max(e,n)<=Math.min(t,r)}function Ee(e){let t=`${e??``}`.toLowerCase();return t.includes(`scroll`)||t.includes(`recyclerview`)||t.includes(`listview`)||t.includes(`gridview`)||t.includes(`collectionview`)||t===`table`}function De(e){return Ee(e.type)?!0:`${e.role??``} ${e.subrole??``}`.toLowerCase().includes(`scroll`)}function v(e){return new Map(e.map(e=>[e.index,e]))}function Oe(e,t,n,r){let i=t,a=new Set;for(;typeof i.parentIndex==`number`&&!a.has(i.index);){if(a.add(i.index),i=n.get(i.parentIndex)??e[i.parentIndex],!i)return null;let t=r(i);if(t!==null)return t}return null}function ke(e,t,n){return Oe(e,t,v(e),e=>n(e)?e:null)}function y(e){let t=e.trim().replace(/XCUIElementType/gi,``).replace(/^AX/,``).toLowerCase(),n=Math.max(t.lastIndexOf(`.`),t.lastIndexOf(`/`));return n!==-1&&(t=t.slice(n+1)),t}function Ae(e,t){let n=y(e);return n?t===`android`?n.includes(`edittext`)||n.includes(`autocompletetextview`):n.includes(`textfield`)||n.includes(`securetextfield`)||n.includes(`searchfield`)||n.includes(`textview`)||n.includes(`textarea`)||n===`search`:!0}function je(e){let t=e.trim();return!(!t||/^(true|false)$/i.test(t)||/^\d+$/.test(t))}function Me(e){return[e.label,e.value,e.identifier].map(e=>typeof e==`string`?e.trim():``).filter(e=>e.length>0)[0]??``}function Ne(e){let t=[e.type,e.role,e.subrole].map(e=>y(e??``)).join(` `);return t.includes(`application`)||t.includes(`window`)}function Pe(e,t){let n=r(t),i=e.flatMap(e=>Fe(e.rect)?[{node:e,rect:e.rect}]:[]),a=i.filter(e=>Ne(e.node)).map(e=>e.rect),o=e=>Ce(e,n.x,n.y);return _(a.filter(o))??_(a)??_(i.map(e=>e.rect).filter(o))}function Fe(e){return e?Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.width)&&Number.isFinite(e.height):!1}function Ie(e,t,n=v(t)){if(!e.rect)return!0;let r=ze(e,t,n);return r?we(e.rect,r):!0}function Le(e,t,n=v(t)){if(!e.rect)return!0;if(!Ie(e,t,n))return!1;let r=Pe(t,e.rect);return Re(e.rect,r)}function Re(e,t){return!t||t.width<=0||t.height<=0?!0:Ce(t,e.x+e.width/2,e.y+e.height/2)}function ze(e,t,n=v(t)){return Be(e,n,e=>!!e.rect)?.rect||Pe(t,e.rect??{x:0,y:0,width:0,height:0})}function Be(e,t,n=()=>!0){let r=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);){if(i.add(r.index),n(r)&&De(r))return r;r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0}return null}function Ve(e,t){if(t===`android`&&e.visibleToUser===!1)return!1;let n=y(e.type??``);return n.includes(`application`)||n.includes(`window`)||n.includes(`scrollview`)||n.includes(`tableview`)||n.includes(`collectionview`)||n===`table`||n===`list`||n===`listview`?!1:t===`android`?e.hittable===!0&&g(e.rect):e.hittable===!0||g(e.rect)}function b(e){return e.hittable===!0?!0:e.rect?e.rect.width>0&&e.rect.height>0:!1}function He(e,t){return Ae(e.type??``,t)&&e.enabled!==!1}const Ue=new Set([`id`,`role`,`text`,`label`,`value`,`appname`,`windowtitle`]),We=new Set([`visible`,`hidden`,`editable`,`selected`,`focused`,`enabled`,`hittable`]),x=new Set([...Ue,...We]),Ge=[...x],Ke=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 qe(e){return Ke.has(e.trim().toLowerCase())}const Je=new Map([[`"`,`"`],[`'`,`'`],[`\\`,`\\`],[`/`,`/`],[`b`,`\b`],[`f`,`\f`],[`n`,`
|
|
3
|
+
`],[`r`,`\r`],[`t`,` `]]);function Ye(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Selector expression cannot be empty`);let r=tt(n);if(r.length===0)throw new e(`INVALID_ARGS`,`Selector expression cannot be empty`);return{raw:n,selectors:r.map(e=>$e(e))}}function S(e){try{return Ye(e)}catch{return null}}function Xe(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 x.has(e)}return x.has(t.toLowerCase())}function Ze(e){let t=e.trim(),n=t.indexOf(`=`);if(n===-1)return null;let r=t.slice(0,n).trim().toLowerCase();if(!r||x.has(r))return null;let i=t.slice(n+1).trim();if(!i)return null;let a=it(i).trim();return a?{key:r,value:a}:null}function Qe(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||!Xe(t))break;r+=1;let n=e.slice(0,r).join(` `).trim();n&&S(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 $e(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Selector segment cannot be empty`);let r=nt(n);if(r.length===0)throw new e(`INVALID_ARGS`,`Invalid selector segment: ${t}`);return{raw:n,terms:r.map(et)}}function et(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(!We.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(),a=n.slice(r+1).trim();if(!x.has(i))throw new e(`INVALID_ARGS`,`Unknown selector key: ${i}`);if(!a)throw new e(`INVALID_ARGS`,`Missing selector value for key: ${i}`);if(We.has(i)){let t=st(a);if(t===null)throw new e(`INVALID_ARGS`,`Invalid boolean value for ${i}: ${a}`);return{key:i,value:t}}return{key:i,value:it(a)}}function tt(t){let n=[],r=``,i=null;for(let a=0;a<t.length;a+=1){let o=t[a];if((o===`"`||o===`'`)&&!ct(t,a)){i=rt(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 nt(t){let n=[],r=``,i=null;for(let e=0;e<t.length;e+=1){let a=t.charAt(e);if((a===`"`||a===`'`)&&!ct(t,e)){i=rt(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 rt(e,t){return e?e===t?null:e:t}function it(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?at(t.slice(1,-1)):t}function at(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=ot(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 ot(e){return Je.get(e)??null}function st(e){let t=it(e).toLowerCase();return t===`true`?!0:t===`false`?!1:null}function ct(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function lt(e){return[`visible`,`hidden`,`exists`,`editable`,`selected`,`focused`,`text`].includes(e)}function ut(e){let t=e.toLowerCase();return lt(t)?{ok:!0,predicate:t}:h(`is requires predicate: visible|hidden|exists|editable|selected|focused|text`,dt)}const dt=`Use "is <predicate> <selector>" or "is <selector> <predicate>". visible|hidden|editable|selected|focused double as selector keys: a bare predicate token after the selector is read as the predicate, so write key=true (e.g. visible=true) inside the selector to use it as a filter instead.`;function ft(e){if(lt((e[0]??``).toLowerCase()))return e;for(let t=1;t<e.length;t+=1){let n=(e[t]??``).toLowerCase();if(lt(n)&&S(e.slice(0,t).join(` `)))return[n,...e.slice(0,t),...e.slice(t+1)]}return e}function pt(e){let{predicate:t,node:n,nodes:r,expectedText:i,platform:a}=e,o=Me(n),s=He(n,a),c=n.selected===!0,l=n.focused===!0,u=t===`text`?b(n):mt(n,r,a),d=!1;switch(t){case`visible`:d=u;break;case`hidden`:d=!u;break;case`editable`:d=s;break;case`selected`:d=c;break;case`focused`:d=l;break;case`text`:d=o===(i??``);break}let f=t===`text`?`expected="${i??``}" actual="${o}"`:`actual=${JSON.stringify({visible:u,editable:s,selected:c,focused:l})}`;return{pass:d,actualText:o,details:f}}function mt(e,t,n){if(n===`android`&&e.visibleToUser===!1)return!1;if(g(e.rect))return ht(e,t);if(e.rect)return!1;if(n!==`android`&&e.hittable===!0)return!0;let r=gt(e,t,n);return r?g(r.rect)?ht(r,t):n!==`android`&&r.hittable===!0:!1}function ht(e,t){return Ie(e,t)}function gt(e,t,n){return Oe(t,e,v(t),e=>Ve(e,n)?e:null)}function _t(e){let t=ft(e),n=t[0]??``;return{predicate:n,split:Qe(t.slice(1),{preferTrailingValue:n===`text`})}}const vt=`is requires a selector expression`,yt=`is text requires expected text value`;function bt(e){let{predicate:t,split:n}=_t([...e]),r=ut(t);if(!r.ok)return r;if(!n)return h(vt);let i=n.rest.join(` `).trim();return r.predicate===`text`&&!i?h(yt):r.predicate!==`text`&&n.rest.length>0?h(`is ${r.predicate} does not accept trailing values`):{ok:!0,predicate:r.predicate,selectorExpression:n.selectorExpression,expectedText:i}}function xt(e){return e===`text`||e===`attrs`?{ok:!0,format:e}:h(`get only supports text or attrs`)}function St(e){let t=e[0];if(t?.startsWith(`@`)){let n=e.slice(1).join(` `).trim();return{ok:!0,ref:t,...n?{label:n}:{}}}let n=e.join(` `).trim();return n?{ok:!0,selector:n}:h(`get requires @ref or selector expression`)}function Ct(e){return e?{ok:!0,text:e}:h(`wait requires text`)}function wt(t,n,r={}){let i=t[n];if(i===void 0)return;if(!Number.isInteger(i))throw new e(`INVALID_ARGS`,`Expected ${n} to be an integer.`);let a=i;if(r.min!==void 0&&a<r.min)throw new e(`INVALID_ARGS`,`Expected ${n} to be at least ${r.min}.`);if(r.max!==void 0&&a>r.max)throw new e(`INVALID_ARGS`,`Expected ${n} to be at most ${r.max}.`);return a}function Tt(t,n,r={}){let i=t[n];if(i!==void 0){if(typeof i!=`number`||!Number.isFinite(i))throw new e(`INVALID_ARGS`,`Expected ${n} to be a finite number.`);if(r.min!==void 0&&i<r.min)throw new e(`INVALID_ARGS`,`Expected ${n} to be at least ${r.min}.`);if(r.max!==void 0&&i>r.max)throw new e(`INVALID_ARGS`,`Expected ${n} to be at most ${r.max}.`);return i}}const Et=/^#\s*agent-device:target-v(\d+)(?:\s+(\S.*))?$/,Dt=/^#\s*agent-device:targets-v(\d+)(?:\s+(\S.*))?$/,Ot=4096;function kt(e){return e.normalize(`NFC`)}function At(e){if(e===void 0)return;let t=kt(e);return t.length>0?t:void 0}function jt(e){return kt(e)}function Mt(e){if(e===void 0)return;let t=kt(e).trim().replace(/\s+/g,` `);return t.length>0?t:void 0}function C(e){return Buffer.byteLength(e,`utf8`)}function Nt(e,t){if(C(e)<=t)return e;let n=e.length;for(;n>0&&C(e.slice(0,n))>t;)--n;if(n>0){let t=e.charCodeAt(n-1);t>=55296&&t<=56319&&--n}return e.slice(0,n)}function Pt(e){let t={};return e.id!==void 0&&(t.id=e.id),t.role=e.role,e.label!==void 0&&(t.label=e.label),t.ancestry=e.ancestry.map(Ft),t.sibling=e.sibling,t.viewportOrder=e.viewportOrder,e.scrollRegion&&(t.scrollRegion=It(e.scrollRegion)),e.rect&&(t.rect=Lt(e.rect)),t.verification=e.verification,t}function Ft(e){let t={role:e.role};return e.label!==void 0&&(t.label=e.label),t}function It(e){let t={role:e.role};return e.id!==void 0&&(t.id=e.id),e.label!==void 0&&(t.label=e.label),t}function Lt(e){return{x:e.x,y:e.y,width:e.width,height:e.height}}function Rt(e){return JSON.stringify(Pt(e))}function zt(e){return`# agent-device:target-v1 ${Rt(e)}`}function Bt(e){return JSON.stringify({source:Pt(e.source),destination:Pt(e.destination)})}function Vt(e){return`# agent-device:targets-v1 ${Bt(e)}`}function Ht(e){let t=e.trim(),n=Dt.exec(t);return n?Number(n[1])===1?{kind:`v1`,evidence:Ut((n[2]??``).trim())}:{kind:`future-version`}:{kind:`none`}}function Ut(t){if(C(t)>8320)throw new e(`INVALID_ARGS`,`targets-v1 annotation exceeds the 8320-byte payload cap.`);let n;try{n=JSON.parse(t)}catch{throw new e(`INVALID_ARGS`,`targets-v1 annotation is not valid JSON.`)}if(typeof n!=`object`||!n||Array.isArray(n))throw new e(`INVALID_ARGS`,`targets-v1 annotation must be a JSON object.`);let r=n;if(r.source===void 0||r.destination===void 0)throw new e(`INVALID_ARGS`,`targets-v1 annotation requires source and destination evidence.`);return{source:Gt(JSON.stringify(r.source)),destination:Gt(JSON.stringify(r.destination))}}function Wt(e){let t=e.trim();if(!t.startsWith(`#`))return{kind:`none`};let n=Et.exec(t);return n?Number(n[1])===1?{kind:`v1`,evidence:Gt((n[2]??``).trim())}:{kind:`future-version`}:{kind:`none`}}function Gt(t){if(C(t)>4096)throw new e(`INVALID_ARGS`,`target-v1 annotation exceeds the ${Ot}-byte payload cap.`);let n;try{n=JSON.parse(t)}catch{throw new e(`INVALID_ARGS`,`target-v1 annotation is not valid JSON.`)}if(typeof n!=`object`||!n||Array.isArray(n))throw new e(`INVALID_ARGS`,`target-v1 annotation must be a JSON object.`);let r=n,i=Kt(r.role,`role`),a=qt(r.id,`id`),o=Jt(r.label,`label`),s=Xt(r.ancestry),c=Qt(r.sibling,`sibling`,0),l=Qt(r.viewportOrder,`viewportOrder`,0),u=$t(r.scrollRegion),d=en(r.rect),f=nn(r.verification);return{...a===void 0?{}:{id:a},role:i,...o===void 0?{}:{label:o},ancestry:s,sibling:c,viewportOrder:l,...u?{scrollRegion:u}:{},...d?{rect:d}:{},verification:f}}function Kt(t,n){if(t===void 0)throw new e(`INVALID_ARGS`,`target-v1 "${n}" is required.`);if(typeof t!=`string`)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a string.`);return Yt(jt(t),n)}function qt(t,n){if(t===void 0)return;if(typeof t!=`string`)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a string.`);let r=At(t);return r===void 0?void 0:Yt(r,n)}function Jt(t,n){if(t===void 0)return;if(typeof t!=`string`)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a string.`);let r=Mt(t);return r===void 0?void 0:Yt(r,n)}function Yt(t,n){if(C(t)>256)throw new e(`INVALID_ARGS`,`target-v1 "${n}" exceeds the 256-byte field cap.`);return t}function Xt(t){if(t===void 0)return[];if(!Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "ancestry" must be an array.`);if(t.length>8)throw new e(`INVALID_ARGS`,`target-v1 "ancestry" exceeds the 8-entry cap.`);return t.map((e,t)=>Zt(e,t))}function Zt(t,n){if(typeof t!=`object`||!t||Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "ancestry[${n}]" must be an object.`);let r=t,i=Kt(r.role,`ancestry[${n}].role`),a=Jt(r.label,`ancestry[${n}].label`);return{role:i,...a===void 0?{}:{label:a}}}function Qt(t,n,r){if(t===void 0)return r;if(typeof t!=`number`||!Number.isSafeInteger(t)||t<0)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a non-negative integer.`);return t}function $t(t){if(t===void 0)return;if(typeof t!=`object`||!t||Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "scrollRegion" must be an object.`);let n=t,r=Kt(n.role,`scrollRegion.role`),i=qt(n.id,`id`),a=Jt(n.label,`scrollRegion.label`);return{role:r,...i===void 0?{}:{id:i},...a===void 0?{}:{label:a}}}function en(t){if(t===void 0)return;if(typeof t!=`object`||!t||Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "rect" must be an object.`);let n=t;return{x:tn(n.x,`rect.x`),y:tn(n.y,`rect.y`),width:tn(n.width,`rect.width`),height:tn(n.height,`rect.height`)}}function tn(t,n){if(typeof t!=`number`||!Number.isFinite(t))throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a finite number.`);return t}function nn(t){if(t===`verified`||t===`unverifiable`)return t;throw new e(`INVALID_ARGS`,`target-v1 "verification" must be "verified" or "unverifiable".`)}function rn(e){let t=jt(y(e.type??``)),n=At(e.identifier),r=Mt(e.label);return{...n===void 0?{}:{id:Nt(n,256)},role:Nt(t,256),...r===void 0?{}:{label:Nt(r,256)}}}function an(e,t){return e.id===t.id&&e.role===t.role&&e.label===t.label}function on(e,t){let n=0;for(let r of e)rn(r).id===t&&(n+=1);return n}function sn(e,t){if(e.id===void 0||on(t,e.id)<=1)return e;let{role:n,label:r}=e;return{role:n,...r===void 0?{}:{label:r}}}function cn(e,t){let n=0;for(let r of e)if(r.parentIndex===t.parentIndex){if(r.index===t.index)return n;n+=1}return 0}function ln(e,t){return{documentOrder:e.index,sibling:cn(t,e)}}function un(e,t){return e.documentOrder===t.documentOrder&&e.sibling===t.sibling}function dn(e){return{...e.id===void 0?{}:{id:e.id},role:e.role,...e.label===void 0?{}:{label:e.label}}}function fn(e,t){return t.id===void 0?e.role===t.role&&e.label===t.label:e.id===t.id}function pn(e,t){if(e.length<t.length)return!1;for(let[n,r]of t.entries()){let t=e[n];if(!t||t.role!==r.role||r.label!==void 0&&t.label!==r.label)return!1}return!0}function mn(e,t){let n=[];return e.id!==t.id&&n.push(`id: recorded=${e.id??`(none)`} observed=${t.id??`(none)`}`),e.role!==t.role&&n.push(`role: recorded=${e.role} observed=${t.role}`),e.label!==t.label&&n.push(`label: recorded=${e.label??`(none)`} observed=${t.label??`(none)`}`),n}function hn(e){return e?`${e.role}${e.label?`/${e.label}`:``}`:`(missing)`}function gn(e,t){return!t||t.role!==e.role?!0:e.label!==void 0&&t.label!==e.label}function _n(e,t){for(let[n,r]of e.entries()){let e=t[n];if(gn(r,e))return[`ancestry[${n}]: recorded=${hn(r)} observed=${hn(e)}`]}return[]}function vn(e,t,n={}){let r=[],i=y(e.type??``),a=yn(e,n.nodes),o=T(e.label),s=T(e.value),c=T(Me(e)),l=n.action===`fill`;a&&r.push(`id=${w(a)}`),i&&o&&r.push(l?`role=${w(i)} label=${w(o)} editable=true`:`role=${w(i)} label=${w(o)}`),o&&r.push(l?`label=${w(o)} editable=true`:`label=${w(o)}`),s&&r.push(l?`value=${w(s)} editable=true`:`value=${w(s)}`),c&&c!==o&&c!==s&&r.push(l?`text=${w(c)} editable=true`:`text=${w(c)}`),i&&l&&!r.some(e=>e.includes(`editable=true`))&&r.push(`role=${w(i)} editable=true`);let u=bn(r);return u.length===0&&i&&u.push(l?`role=${w(i)} editable=true`:`role=${w(i)}`),u.length===0&&b(e)&&u.push(`visible=true`),u}function yn(e,t){let n=T(e.identifier);if(!n||!t)return n;let r=rn(e).id;return r===void 0?n:on(t,r)>1?null:n}function bn(e){return Array.from(new Set(e))}function w(e){return JSON.stringify(e)}function T(e){return e&&e.trim()||null}const xn=[`any`,`text`,`label`,`value`,`role`,`id`],Sn=[`text`,`label`,`value`,`role`,`id`];function Cn(e){let t=e?.toLowerCase();return t===`press`||t===`tap`?`click`:t}function wn(e){return e===`exists`||e===`wait`||e===`get_text`||e===`get_attrs`||e===`list`}function Tn(e,t,n,r={}){let i=D(n);if(!i)return{matches:[],score:0};let a=0,o=[];for(let n of e){if(r.requireRect&&!n.rect)continue;let e=En(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 En(e,t,n){switch(t){case`role`:return Dn(e.type,n);case`label`:return E(e.label,n);case`value`:return E(e.value,n);case`id`:return E(e.identifier,n);default:return Math.max(E(e.label,n),E(e.value,n),E(e.identifier,n))}}function E(e,t){let n=D(e??``);return n?n===t?2:+!!n.includes(t):0}function Dn(e,t){let n=On(e??``);return n?n===t?2:+!!n.includes(t):0}function D(e){return e.trim().toLowerCase().replace(/\s+/g,` `)}function On(e){let t=e.trim();return t?(t=(t.split(`.`).pop()??t).replace(/XCUIElementType/gi,``).toLowerCase(),t):``}const kn=`find requires a value`,An=`find actions: click (default; press/tap are aliases), list, focus, fill, type, exists, wait, get text, get attrs — there is no longpress/swipe find action. Run find "<text>" list to inspect every match with its @ref without acting, then dispatch the gesture on the chosen ref, e.g. longpress @eNN.`;function jn(e,t){if(e.length===0)return{ok:!1,code:`INVALID_ARGS`,message:`find requires a locator or text`};let n=Pn([...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:kn}}const Mn=[`exists`,`list`,`click`,`focus`];function Nn(e){return Mn.includes(e)}function Pn(t){let n=`any`,r=0;Sn.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=Cn(a[0]);if(Nn(o))return{locator:n,query:i,action:o};if(o===`get`)return{locator:n,query:i,action:Fn(a[1])};if(o===`wait`){let e=Ln(a[1]);return{locator:n,query:i,action:`wait`,timeoutMs:e??void 0}}if(o===`fill`||o===`type`)return{locator:n,query:i,action:o,value:a.slice(1).join(` `)};throw new e(`INVALID_ARGS`,`Unsupported find action: ${a[0]}`,{hint:An})}function Fn(t){let n=t?.toLowerCase();if(n===`text`)return`get_text`;if(n===`attrs`)return`get_attrs`;throw new e(`INVALID_ARGS`,`find get only supports text or attrs`)}function In(e,t){return e!==`any`||!t.includes(`=`)&&!t.includes(`||`)?null:S(t)?t:null}function Ln(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}function O(e,t,n){return t.terms.every(t=>Rn(e,t,n))}function Rn(e,t,n){switch(t.key){case`id`:return k(e.identifier,String(t.value));case`role`:return k(y(e.type??``),String(t.value));case`label`:return k(e.label,String(t.value));case`value`:return k(e.value,String(t.value));case`text`:return k(Me(e),String(t.value));case`appname`:return k(e.appName,String(t.value));case`windowtitle`:return k(e.windowTitle,String(t.value));case`visible`:return b(e)===!!t.value;case`hidden`:return!b(e)==!!t.value;case`editable`:return He(e,n)===!!t.value;case`selected`:return e.selected===!0==!!t.value;case`focused`:return e.focused===!0==!!t.value;case`enabled`:return e.enabled!==!1==!!t.value;case`hittable`:return e.hittable===!0==!!t.value;default:return!1}}function k(e,t){return D(e??``)===D(t)}function zn(e,t,n){let r=n.requireRect??!1,i=n.requireUnique??!0,a=[];for(let[o,s]of t.selectors.entries()){let t=Gn(e,s,n.platform,r);if(a.push({selector:s.raw,matches:t.count}),!(t.count===0||!t.firstNode)){if(i&&t.count!==1){if(!n.disambiguateAmbiguous||!t.disambiguated||!t.tiebreak)continue;return{node:t.disambiguated,selector:s,selectorIndex:o,matches:t.count,diagnostics:a,disambiguation:{matchCount:t.count,tiebreak:t.tiebreak,alternatives:t.candidates.filter(e=>e!==t.disambiguated)}}}return{node:t.firstNode,selector:s,selectorIndex:o,matches:t.count,diagnostics:a}}}return null}function Bn(e,t,n){let r=n.requireRect??!1;for(let[i,a]of t.selectors.entries()){let t=e.filter(e=>r&&!e.rect?!1:O(e,a,n.platform));if(t.length>0)return{selector:a,selectorIndex:i,matchedNodes:t}}return null}function Vn(e,t,n){let r=n.requireRect??!1,i=[];for(let[a,o]of t.selectors.entries()){let t=Yn(e,o,n.platform,r);if(i.push({selector:o.raw,matches:t}),t>0)return{selectorIndex:a,selector:o,matches:t,diagnostics:i}}return null}const Hn=`Snapshot refs expire when the UI changes. Run snapshot -i and retry with a fresh @ref.`;function Un(e){return e.some(e=>e.matches>1)?`Add more terms to disambiguate (e.g. role=button text="Sign in"), use an @ref from snapshot -i, or use find <text> --first/--last.`:`Selector text/label values match exactly (quote multi-word values: text="Sign in"). Run snapshot -i to see current elements and refs, or use find <text> for contains matching.`}function Wn(e,t,n){if(t.length===0)return`Selector did not match: ${e}`;let r=t.map(e=>`${e.selector} -> ${e.matches}`).join(`, `);return n.unique??!0?`Selector did not resolve uniquely (${r})`:`Selector did not match (${r})`}function Gn(e,t,n,r){let i=0,a=null,o=[],s={best:null,bestVisible:!1,tie:!1},c,l=t=>(c??=v(e),Le(t,e,c));for(let c of e)r&&!c.rect||O(c,t,n)&&(i+=1,a??=c,o.push(c),Kn(s,c,l));return{count:i,firstNode:a,disambiguated:s.tie?null:s.best,tiebreak:s.tie?null:qn(o,s.best,l),candidates:o}}function Kn(e,t,n){if(!e.best){e.best=t;return}e.bestVisible||=n(e.best);let r=n(t);if(r!==e.bestVisible){r&&(e.best=t,e.bestVisible=!0,e.tie=!1);return}let i=Xn(t,e.best);i.result>0?(e.best=t,e.tie=!1):i.result===0&&(e.tie=!0)}function qn(e,t,n){if(!t)return null;let r=null;for(let i of e)i!==t&&(!r||Jn(i,r,n).result>0)&&(r=i);return r?Jn(t,r,n).criterion:null}function Jn(e,t,n){let r=n(e);return r===n(t)?Xn(e,t):{result:r?1:-1,criterion:`visible`}}function Yn(e,t,n,r){let i=0;for(let a of e)r&&!a.rect||O(a,t,n)&&(i+=1);return i}function Xn(e,t){let n=e.depth??0,r=t.depth??0;if(n!==r)return{result:n>r?1:-1,criterion:`deepest`};let i=Zn(e),a=Zn(t);return i===a?{result:0,criterion:null}:{result:i<a?1:-1,criterion:`smallest-area`}}function Zn(e){return e.rect?e.rect.width*e.rect.height:1/0}const Qn={act:{ambiguity:`reject-candidates`,requireRect:!0},actCoveredDiagnosis:{ambiguity:`first-match`,requireRect:!0},readText:{ambiguity:`disambiguate`,requireRect:!1},readUnique:{ambiguity:`fail-closed`,requireRect:!1},readAny:{ambiguity:`first-match`,requireRect:!1},wait:{ambiguity:`first-match`,requireRect:!1},findAct:{ambiguity:`reject-candidates`,requireRect:!0},readList:{ambiguity:`reject-candidates`,requireRect:!1}};function $n(e){return e.ambiguity===`first-match`?{requireRect:e.requireRect,requireUnique:!1}:{requireRect:e.requireRect,requireUnique:!0,disambiguateAmbiguous:e.ambiguity===`disambiguate`}}function er(e,t){let n=e===`is`?_t([...t]).split:Qe([...t]);return n?S(n.selectorExpression)?{kind:`expression`,expression:n.selectorExpression,rest:n.rest}:{kind:`invalid`}:{kind:`not-applicable`}}function tr(e){return{platform:e.platform,...$n({ambiguity:e.allowDisambiguation?`disambiguate`:`fail-closed`,requireRect:e.requireRect})}}function nr(e,t,n){let r=S(e);if(!r)return{kind:`unresolved`,reason:`parse-invalid`,matchedNodes:[]};let i=zn(t,r,tr(n));if(i){let e=t.filter(e=>n.requireRect&&!e.rect?!1:O(e,i.selector,n.platform));return{kind:`resolved`,winner:i.node,matchedNodes:e,matchCount:e.length,...i.disambiguation?{disambiguation:{tiebreak:i.disambiguation.tiebreak,matchCount:i.disambiguation.matchCount,alternatives:i.disambiguation.alternatives}}:{}}}let a=Bn(t,r,{platform:n.platform,requireRect:n.requireRect})?.matchedNodes??[];return{kind:`unresolved`,reason:a.length>0?`ambiguous`:`no-match`,matchedNodes:a}}function rr(e,t,n={}){return vn(e,t,n)}function ir(e,t,n){let r=S(e);if(!r)return;let i=zn(t,r,tr(n));if(i)return{node:i.node,basis:or(i.selector)}}function ar(e){if(!e)return;let t=S(e);if(!t)return;let n=t.selectors.flatMap(e=>e.terms.flatMap(e=>(e.key===`label`||e.key===`text`||e.key===`id`)&&typeof e.value==`string`?[e.value]:[]));if(n.length===0)return;let r=n[0];return r&&n.every(e=>e===r)?r:void 0}function or(e){let t=new Set(e.terms.map(e=>e.key));if(t.has(`id`))return`id`;let n=t.has(`role`),r=t.has(`label`)||t.has(`text`);return n&&r?`role-label`:r||t.has(`value`)?`label`:`other`}function sr(e,t){let n=S(e);if(!n)return e.includes(`=`)||e.includes(`||`)?null:e;let r=new Set(t.textKeys);return n.selectors.length>1?cr(n.selectors,r):lr(n.selectors[0],r,new Set(t.booleanKeys))}function cr(e,t){let n=e.map(e=>{let n=e.terms.length===1?e.terms[0]:void 0;return n&&t.has(n.key)&&typeof n.value==`string`?n.value:void 0}),r=n[0];return r!==void 0&&n.every(e=>e===r)?r:null}function lr(e,t,n){if(!e)return null;let r={},i=0;for(let a of e.terms){if(ur(a,t,`string`))i+=1;else if(!ur(a,n,`boolean`))return null;r[a.key]=a.value}return i<=1&&Object.keys(r).length>0?r:null}function ur(e,t,n){return t.has(e.key)&&typeof e.value===n}function dr(e){let t=S(e);if(!t||t.selectors.length!==1)return null;let n=t.selectors[0];if(!n||n.terms.length!==1)return null;let r=n.terms[0];return!r||typeof r.value!=`string`||r.key!==`id`&&r.key!==`label`&&r.key!==`text`&&r.key!==`value`?null:{key:r.key,value:r.value,raw:n.raw}}function fr(e,t){if(!t)return!1;let n=S(e);return n?n.selectors.some(e=>e.terms.some(e=>(e.key===`text`||e.key===`label`||e.key===`value`)&&typeof e.value==`string`&&e.value.includes(t))):!1}function pr(e){return Ye(e).selectors.map(e=>e.raw)}function mr(e){return S(e)!==null}function A(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}function hr(e){let t=e[0];if(t===void 0)return null;let n=A(t);if(n!==null)return{kind:`sleep`,durationMs:n};let r=A(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?A(t[1]):null;return{kind:`stable`,quietMs:t.length>0?A(t[0]):null,timeoutMs:n}}if(t.startsWith(`@`))return{kind:`ref`,rawRef:t,timeoutMs:r};let i=Qe(r===null?e.slice():e.slice(0,-1));return i&&i.rest.length===0&&mr(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 gr(e){let t=hr(e);return t?t.kind===`sleep`?t.durationMs:t.timeoutMs:null}const _r=24e4,j={budget:{source:`none`},envelopeMs:9e4,onTimeout:`reset-daemon`},vr={click:`settle-and-verify`,press:`settle-and-verify`,fill:`settle-and-verify`,longpress:`settle`,scroll:`settle`,back:`settle`};function yr(e){if(e!==void 0)return vr[e]}const br=new Set([`com.google.android.inputmethod.latin`,`com.samsung.android.honeyboard`,`com.touchtype.swiftkey`,`com.microsoft.swiftkey`]);function xr(e){let t=M(e.packageName),n=(e.resourceId??``).toLowerCase(),r=M(e.activeInputMethodPackage);if(t&&r&&t===r)return{inputMethodOwned:!0,source:`active-input-method`};if(r&&n.startsWith(`${r}:id/`))return{inputMethodOwned:!0,source:`active-input-method-resource`};if(t&&br.has(t))return{inputMethodOwned:!0,source:`known-ime-package`};for(let e of br)if(n.startsWith(`${e}:id/`))return{inputMethodOwned:!0,source:`known-ime-resource`};return{inputMethodOwned:!1,source:`app`}}function Sr(e,t,n){return xr({packageName:e,resourceId:t,activeInputMethodPackage:n}).inputMethodOwned}function Cr(e){return xr(e).inputMethodOwned}function wr(e){return Cr({packageName:e.bundleId,resourceId:e.identifier})}function Tr(e){let t=M(e);return!!(t&&br.has(t))}function Er(e){let t=(e??``).toLowerCase();for(let e of br)if(t.startsWith(`${e}:id/`))return!0;return!1}function Dr(e,t,n){return!e&&!t?`unknown`:Sr(e,t,n)?`ime`:`app`}function Or(e){for(let t of[/\bmCurMethodId=([^\s]+)/i,/\bmCurId=([^\s]+)/i,/\bmCurrentInputMethodId=([^\s]+)/i,/\bcurMethodId=([^\s]+)/i]){let n=kr(e.match(t)?.[1]);if(n)return n}}function kr(e){let t=(e??``).trim();if(t)return M((t.split(`/`)[0]??``).match(/[a-zA-Z0-9_.]+/)?.[0])}function M(e){return(e??``).trim().toLowerCase()||void 0}const Ar=new Set([`empty-helper-output`,`system-window-only`,`content-poor-app-window`]);function jr(e){return typeof e==`string`&&Ar.has(e)}function Mr(e){if(!e||typeof e!=`object`)return!1;let t=e.details?.androidSnapshotHelperFailureReason;return jr(t)}const Nr=`com.android.systemui`;function Pr(e){let t=e??``;if(!t.startsWith(`com.android.systemui:id/`))return!1;let n=t.slice(`${Nr}:id/`.length);return/(^|_)(status_bar|navigation_bar)(_|$)/.test(n)}function Fr(e){return`systemChrome`in e&&e.systemChrome===!0}function Ir(e){if(!Fr(e))return e;let{systemChrome:t,...n}=e;return n}function Lr(e){return e.some(Fr)?e.map(Ir):e}const Rr={ios:`iOS`,ipados:`iPadOS`,tvos:`tvOS`,watchos:`watchOS`,visionos:`visionOS`,macos:`macOS`},zr={visionos:`visionOS uses spatial input and does not support two-finger touch synthesis.`,tvos:`tvOS has no touch input — this gesture is supported on Android and the iOS simulator only.`,macos:`macOS automation has no multi-touch input — this gesture is supported on Android and the iOS simulator only.`};function Br(t,n){if(!u(t.platform))throw Vr(n,t.platform);let r=d(t);if(!((r===`ios`||r===`ipados`)&&t.kind===`simulator`))throw r===`ios`||r===`ipados`?new e(`UNSUPPORTED_OPERATION`,`gesture ${n} is not supported on physical iOS devices`,{hint:`Two-finger gesture synthesis is iOS-simulator only — not available on physical iOS devices.`}):Vr(n,Rr[r],zr[r])}function Vr(t,n,r){return new e(`UNSUPPORTED_OPERATION`,`gesture ${t} is not supported on ${n}`,r===void 0?void 0:{hint:r})}function Hr(e){let t=e.state??`stopped`;return{audio:`probe`,state:t,active:t===`running`,heard:!1,source:e.source,backend:e.backend,durationMs:e.durationMs,elapsedMs:e.elapsedMs??0,bucketMs:e.bucketMs,sampleCount:0,mediaElementCount:e.mediaElementCount,sourceCount:e.sourceCount??0,rmsDbfs:[],peakDbfs:[],reason:e.reason,notes:e.notes}}function Ur(e,t){let n=qr(e),r=Wr(n),i=Gr(n.rmsDbfs),a=Gr(n.peakDbfs),o=[...Kr(n.notes)??[],...t.notes??[]];return{audio:`probe`,state:r,active:r===`running`&&Jr(n.active,t.activeFallback??!0),heard:n.heard===!0,source:t.source,backend:P(n.backend)??t.backend,durationMs:N(n.durationMs,t.durationMs),elapsedMs:N(n.elapsedMs,t.elapsedMs),bucketMs:N(n.bucketMs,t.bucketMs),sampleCount:N(n.sampleCount,i.length),mediaElementCount:t.mediaElementCount===void 0?Yr(n.mediaElementCount):N(n.mediaElementCount,t.mediaElementCount),sourceCount:N(n.sourceCount,t.sourceCount??0),rmsDbfs:i,peakDbfs:a,startedAt:P(n.startedAt),stoppedAt:P(n.stoppedAt),reason:P(n.reason),notes:o.length>0?o:void 0}}function Wr(e){return e.state===`running`?`running`:`stopped`}function N(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function Gr(e){if(!Array.isArray(e))return[];let t=[];for(let n of e)typeof n==`number`&&Number.isFinite(n)&&t.push(n);return t}function Kr(e){if(Array.isArray(e))return e.filter(e=>typeof e==`string`)}function qr(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function Jr(e,t){return typeof e==`boolean`?e:t}function P(e){return typeof e==`string`?e:void 0}function Yr(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function Xr(e){return process.platform===`darwin`&&(c(e)||o(e)&&e.kind===`simulator`||e.platform===`android`&&e.kind===`emulator`)}function Zr(e){return e.platform===`web`||Xr(e)}function Qr(e){if(!s(e))throw TypeError(`Unknown local runtime family: ${String(e)}`);return Object.freeze({kind:`local-family`,family:e})}function $r(e,t){let n=e.trim(),r=t.trim();if(n.length===0||r.length===0)throw TypeError(`Provider runtime owner requires non-empty provider and instance identities`);return Object.freeze({kind:`provider-runtime`,provider:n,instance:r})}function ei(e){return e.kind===`local-family`?`local:${e.family}`:`provider:${JSON.stringify([e.provider,e.instance])}`}function ti(e,t){return ei(e)===ei(t)}function ni(e,t){let n={},r={};for(let i of t.required){let t=ri(e.facts.operations,i);if(n[i]=t,!t.available)throw ci(i,t);r[i]=oi(e.operations,i)}for(let i of t.preferred){let t=ri(e.facts.operations,i);n[i]=t,t.available&&(r[i]=oi(e.operations,i))}return Object.freeze({device:e.device,owner:e.owner,facts:Object.freeze(n),operations:Object.freeze(r)})}function ri(e,t){let n=e[t];if(!ii(n))throw li(`Runtime owner omitted the ${t} fact`);let r=ai(n);if(r)return r;throw li(`Runtime owner returned an invalid ${t} fact`)}function ii(e){return typeof e==`object`&&!!e&&`available`in e}function ai(e){if(e.available===!0)return Object.freeze({available:!0});if(e.available===!1&&si(e.reason)&&!(e.hint!==void 0&&typeof e.hint!=`string`))return Object.freeze({available:!1,reason:e.reason,...e.hint===void 0?{}:{hint:e.hint}})}function oi(e,t){let n=e[t];if(typeof n!=`function`)throw li(`Runtime owner advertised ${t} without an implementation`);return n}function si(e){return e===`unsupported-platform-leaf`||e===`unsupported-device-kind`||e===`unsupported-device-backend`||e===`unsupported-provider-mode`||e===`owner-capability-missing`}function ci(t,n){return new e(`UNSUPPORTED_OPERATION`,`Runtime operation ${t} is unavailable`,{reason:n.reason,hint:n.hint})}function li(t){return new e(`COMMAND_FAILED`,t,{reason:`runtime-contract-invalid`,hint:`This is an agent-device runtime contract bug; report the selected device and command.`})}function ui(){return e=>{let t=di(e.required,`required`),n=di(e.preferred??[],`preferred`),r=n.find(e=>t.includes(e));if(r!==void 0)throw TypeError(`Runtime operation cannot be both required and preferred: ${r}`);return Object.freeze({required:t,preferred:n})}}function di(e,t){let n=[...e];if(new Set(n).size!==n.length)throw TypeError(`Runtime use contains duplicate ${t} operations`);return Object.freeze(n)}const F=ui(),fi=F({required:[`bootTarget`]}),pi=F({required:[`bootTargetHeadless`]}),mi=F({required:[`ensureReady`,`listApps`]}),hi=Object.freeze([fi,pi]),gi=Object.freeze({kind:`boot-target`,operation:`bootTarget`,use:fi}),_i=Object.freeze({kind:`boot-target-headless`,operation:`bootTargetHeadless`,use:pi});function vi(e){return e.headless?_i:gi}const yi=F({required:[`ensureReady`,`appState`]}),bi=Object.freeze([yi]),xi=F({required:[`shutdownTarget`]}),Si=F({required:[`deployApp`]}),Ci=F({required:[`ensureReady`,`materializeAppSource`,`deployMaterializedApp`]}),wi=F({required:[`ensureReady`,`sendPushNotification`]});function Ti(e){if(typeof e!=`object`||!e)throw Ni();let t=e,n=Object.keys(t).sort();if(!(t.kind===`none`&&I(n,[`kind`]))&&!(t.kind===`legacy`&&I(n,[`kind`]))&&!(t.kind===`inventory`&&I(n,[`kind`,`use`])&&Oi(t.use))&&!(t.kind===`device-runtime`&&I(n,[`kind`,`use`])&&ki(t.use))&&!(t.kind===`device-runtime`&&I(n,[`kind`,`uses`])&&Ei(t.uses)))throw Ni()}function Ei(e){if(!Array.isArray(e)||e.length===0||!e.every(ki))return!1;let t=e.map(Di);return new Set(t).size===t.length}function Di(e){return JSON.stringify({required:[...e.required].sort(),preferred:[...e.preferred].sort()})}function Oi(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.kind===`device-inventory`&&I(Object.keys(t).sort(),[`kind`])}function ki(e){if(typeof e!=`object`||!e)return!1;let t=e,n=Ai(t.required),r=Ai(t.preferred);return!n||!r||!ji(n)||!ji(r)||!Mi(n,r)?!1:I(Object.keys(t).sort(),[`preferred`,`required`])}function Ai(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:null}function ji(e){return new Set(e).size===e.length}function Mi(e,t){let n=new Set(e);return t.every(e=>!n.has(e))}function I(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function Ni(){return TypeError(`Command platform execution must declare exactly one of none, legacy, inventory, or device-runtime`)}var Pi=class{#e=[];#t=`open`;get disposed(){return this.#t===`disposed`}defer(e){this.#n(),this.#e.push(e)}use(e){return this.defer(async()=>await e[Symbol.asyncDispose]()),e}async[Symbol.asyncDispose](){if(this.#t===`disposed`)return;if(this.#t===`disposing`)throw TypeError(`Async cleanup stack disposal is already in progress`);this.#t=`disposing`;let e=[];for(;this.#e.length>0;){let t=this.#e.pop();if(t)try{await t()}catch(t){e.push(t)}}if(this.#t=`disposed`,e.length===1)throw e[0];if(e.length>1)throw AggregateError(e,`Multiple asynchronous cleanups failed`)}#n(){if(this.#t!==`open`)throw TypeError(`Cannot register cleanup after disposal has begun`)}},Fi=class{#e;#t=`pending`;constructor(e){this.#e=e}get pending(){return this.#t===`pending`}transfer(){if(this.#t!==`pending`)throw TypeError(`Cannot transfer handle in ${this.#t} state`);return this.#t=`transferred`,this.#e}async[Symbol.asyncDispose](){this.#t===`pending`&&(this.#t=`disposed`,await this.#e[Symbol.asyncDispose]())}};const L=new Map;async function Ii(e,t){let n=L.get(e);if(n){await n;return}let r,i=new Promise(e=>{r=e});L.set(e,i);try{await t()}finally{L.get(e)===i&&L.delete(e),r()}}async function Li(e){await L.get(e)}const Ri=[`metroHost`,`metroPort`,`bundleUrl`];function zi(e){return Ri.some(t=>e[t]!==void 0)}const Bi=[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`,`applyRuntimeHints`,`clearRuntimeHints`,`closeApplication`,`finalizeApplicationClose`,`prepareAppleRunner`,`configureProviderPortReverse`];function Vi(e){return Object.freeze({resolveOpenTarget:e.resolveOpenTarget,prepareApplicationOpen:e.prepareApplicationOpen,openApplication:e.openApplication,applyRuntimeHints:e.applyRuntimeHints,clearRuntimeHints:e.clearRuntimeHints,closeApplication:e.closeApplication,finalizeApplicationClose:e.finalizeApplicationClose,prepareAppleRunner:e.prepareAppleRunner,configureProviderPortReverse:e.configureProviderPortReverse})}function Hi(e,t){return Object.freeze(Object.fromEntries(Bi.flatMap(n=>t[n].available?[[n,e[n]]]:[])))}function Ui(e,t,n){return Object.freeze({device:e,owner:t,facts:Wi(e,t,n),operations:Object.freeze({}),[Symbol.asyncDispose]:async()=>void 0})}function Wi(e,t,n){let{appLog:r,apps:i,appDeployment:o,appState:s,network:c,screenRecording:l,readiness:u,shutdown:d,lifecycle:f}=Gi(n);return Object.freeze({device:{...a(e),providerMode:t.kind===`local-family`?`local`:`provider-runtime`},operations:{appLogInspect:r,appLogDoctor:r,appLogStart:r,appLogReattach:r,appLogCleanup:r,listApps:i,deployApp:o,materializeAppSource:o,deployMaterializedApp:o,sendPushNotification:o,appState:s,networkDump:c,screenRecordingStart:l,screenRecordingReattach:l,screenRecordingCleanup:l,ensureReady:u,bootTarget:u,bootTargetHeadless:u,shutdownTarget:d,...f}})}function Gi(e){return Object.freeze({appLog:Object.freeze({...e.appLog}),apps:Object.freeze({...e.apps??e.network}),appDeployment:Object.freeze({...e.appDeployment??e.network}),appState:Object.freeze({...e.appState??e.network}),network:Object.freeze({...e.network}),screenRecording:Object.freeze({...e.screenRecording??e.network}),readiness:Object.freeze({...e.readiness??e.network}),shutdown:Object.freeze({...e.shutdown??e.network}),lifecycle:Vi(e.lifecycle)})}function Ki(e){return e.status===`cleaned`||e.status===`already-missing`}const qi=`app-log`,Ji=`screen-recording`,Yi=F({required:[`screenRecordingStart`]}),Xi=F({required:[`screenRecordingReattach`,`screenRecordingCleanup`]}),Zi=F({required:[]}),Qi=F({required:[],preferred:[`screenRecordingStart`]}),$i=Object.freeze([Yi,Xi]);function ea(t){switch((t.action??``).toLowerCase()){case`start`:if(!ta(t.scope??`app`))throw new e(`INVALID_ARGS`,`record scope must be app, device, or system`);return Object.freeze({kind:`start`,use:Yi});case`stop`:return t.hasLiveHandle===!0?Object.freeze({kind:`stop-live`,use:Zi}):Object.freeze({kind:`stop-recovery`,use:Xi});default:throw new e(`INVALID_ARGS`,`record requires start or stop`)}}function ta(e){return e===`app`||e===`device`||e===`system`}function na(e){if(Ti(e),e.kind!==`device-runtime`||!(`uses`in e))throw ia();let t=e.uses.map(ra),n=$i.map(ra),r=new Set(t),i=new Set(n);if(t.length!==n.length||r.size!==t.length||[...r].some(e=>!i.has(e)))throw ia()}function ra(e){return JSON.stringify({required:[...e.required].sort(),preferred:[...e.preferred].sort()})}function ia(){return TypeError(`Record runtime execution must declare exactly the uses selected by its two runtime-bearing plans`)}const aa=F({required:[`networkDump`]}),oa=F({required:[],preferred:[`networkDump`]}),sa=[`dump`,`log`],ca=[`summary`,`headers`,`body`,`all`];function la(t){let n=(t.action??`dump`).toLowerCase(),r=(t.include??`summary`).toLowerCase();if(!ua(n))throw new e(`INVALID_ARGS`,`network requires dump or log`);if(!da(r))throw new e(`INVALID_ARGS`,`network --include must be summary, headers, body, or all`);return Object.freeze({action:n,include:r,use:aa})}function ua(e){return sa.some(t=>t===e)}function da(e){return ca.some(t=>t===e)}function R(e){let t=e.trim();if(!t||/\s/.test(t))return!1;let n=/^([A-Za-z][A-Za-z0-9+.-]*):(.+)$/.exec(t);if(!n)return!1;let r=n[1]?.toLowerCase(),i=n[2]??``;return r===`http`||r===`https`||r===`ws`||r===`wss`||r===`ftp`||r===`ftps`?i.startsWith(`//`):!0}function fa(e){let t=e.trim().split(`:`)[0]?.toLowerCase();return t===`http`||t===`https`}function pa(e,t){let n=e?.trim();if(n)return n;if(fa(t))return`com.apple.mobilesafari`}const ma=`--launch-console is supported only for iOS simulator app launches`,ha=`--launch-console requires a direct app launch and cannot be used with URL opens`;function ga(e,t,n){return{requestId:e.requestId,signal:n,appBundleId:t,verbose:e.verbose,logPath:e.logPath,traceLogPath:e.traceLogPath,iosXctestrunFile:e.iosXctestrunFile,iosXctestDerivedDataPath:e.iosXctestDerivedDataPath,iosXctestEnvDir:e.iosXctestEnvDir,runnerLeaseContext:e.runnerLeaseContext}}function _a(t){let{device:n,signal:r,ownership:i}=t;return Object.freeze({device:n,signal:r,resolveInteractor:async(a,o)=>{let s=ga(a,o,r);if(i===`local`)return await t.resolveLocalInteractor(n,s);let c=i.resolveInteractor(s);if(c)return c;throw new e(`UNSUPPORTED_OPERATION`,`Provider-owned application lifecycle operation has no bound provider interactor.`,{reason:`provider-runtime-interactor-missing`,deviceId:n.id})}})}function va(e){return _a({device:e.device,signal:e.signal,resolveLocalInteractor:e.resolveInteractor,ownership:`local`})}function ya(e){return _a({device:e.device,signal:e.signal,ownership:{kind:`provider`,resolveInteractor:e.resolveInteractor}})}async function ba(e){let{device:t,positionals:n,execution:r}=e;xa(n);let i=n[0],a=n[1];if(!i){await Sa(e);return}if(Ca(t,r),a!==void 0){await wa(e,i,a);return}await Ta(e,i)}function xa(t){if(t.length>2)throw new e(`INVALID_ARGS`,`open accepts at most two arguments: <app|url> [url]`)}async function Sa(t){if(t.execution.launchConsole)throw new e(`INVALID_ARGS`,`--launch-console requires an app target`);if(t.execution.launchArgs&&t.execution.launchArgs.length>0)throw new e(`INVALID_ARGS`,`--launch-args requires an app target`);await t.interactor.openDevice()}function Ca(t,n){if(n.launchConsole&&(!o(t)||t.kind!==`simulator`))throw new e(`UNSUPPORTED_OPERATION`,ma);if(t.platform===`linux`&&n.launchArgs&&n.launchArgs.length>0)throw new e(`UNSUPPORTED_OPERATION`,`--launch-args is not supported on Linux.`)}async function wa(t,n,r){if(R(n))throw new e(`INVALID_ARGS`,`open <app> <url> requires an app target as the first argument`);if(!R(r))throw new e(`INVALID_ARGS`,`open <app> <url> requires a valid URL target`);if(t.execution.launchConsole)throw new e(`INVALID_ARGS`,ha);await t.interactor.open(n,{activity:t.execution.activity,appBundleId:t.appBundleId,launchArgs:t.execution.launchArgs?[...t.execution.launchArgs]:void 0,terminateRunningApp:t.terminateRunningApp,url:r})}async function Ta(t,n){let{execution:r,interactor:i}=t;if(r.launchConsole&&R(n))throw new e(`INVALID_ARGS`,ha);if(r.clearAppState){if(R(n))throw new e(`INVALID_ARGS`,`Clearing app state requires an app target, not a deep link.`);await i.setSetting(`clear-app-state`,`clear`,n)}await i.open(n,{activity:r.activity,appBundleId:t.appBundleId,launchConsole:r.launchConsole,launchArgs:r.launchArgs?[...r.launchArgs]:void 0,terminateRunningApp:t.terminateRunningApp})}function Ea(t){let{binding:n}=t,r=async()=>{throw new e(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for ${t.owner}.`)};return Object.freeze({resolveOpenTarget:async e=>ka(t.openTargetIdentity,e),prepareApplicationOpen:async()=>void 0,openApplication:async e=>await Da(t,e),applyRuntimeHints:r,clearRuntimeHints:r,closeApplication:async e=>{await Aa({device:n.device,interactor:await n.resolveInteractor(e.execution,e.appBundleId),positionals:e.positionals})},finalizeApplicationClose:async()=>({}),prepareAppleRunner:r,configureProviderPortReverse:t.configureProviderPortReverse??r})}async function Da(e,t){let{binding:n}=e,r=await n.resolveInteractor(t.execution,t.appBundleId);e.closeBeforeRelaunch&&t.relaunch&&t.target!==void 0&&await Aa({device:n.device,interactor:r,positionals:[t.appBundleId??t.target]}),await ba({device:n.device,interactor:r,positionals:t.positionals,appBundleId:t.appBundleId,execution:t.execution});let i=Oa(t);return i&&await ba({device:n.device,interactor:r,positionals:[i],appBundleId:t.appBundleId,execution:{...t.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0}}),{appBundleId:t.appBundleId,timing:{}}}function Oa(e){let t=e.runtimeLaunchUrl?.trim(),n=e.positionals.length===1?e.positionals[0]?.trim():void 0;if(!(!t||!n||R(n)))return t}function ka(e,t){let n=t.target;if(e===`app-name`)return Object.freeze(n===void 0?{}:{appName:n});let r=n?.trim(),i=r&&r.includes(`.`)&&!R(r)?r:t.currentAppBundleId;return Object.freeze({...i===void 0?{}:{appBundleId:i},...n===void 0?{}:{appName:n}})}async function Aa(e){let{device:t,interactor:n,positionals:r}=e,i=r[0];if(!i){t.platform===`web`&&await n.close(``);return}await n.close(i)}const ja=F({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`]}),Ma=F({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`,`applyRuntimeHints`]}),Na=F({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`,`clearRuntimeHints`]}),Pa=F({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`,`applyRuntimeHints`,`clearRuntimeHints`]});function Fa(e){return e.applyRuntimeHints&&e.clearRemovedRuntimeHints?Object.freeze({kind:`open-apply-and-clear-runtime-hints`,use:Pa}):e.applyRuntimeHints?Object.freeze({kind:`open-apply-runtime-hints`,use:Ma}):e.clearRemovedRuntimeHints?Object.freeze({kind:`open-clear-runtime-hints`,use:Na}):Object.freeze({kind:`open`,use:ja})}const Ia=Object.freeze([ja,Ma,Na,Pa]),La=F({required:[`closeApplication`,`finalizeApplicationClose`]}),Ra=F({required:[`closeApplication`,`finalizeApplicationClose`,`clearRuntimeHints`]}),za=Object.freeze([La,Ra]),Ba=F({required:[`finalizeApplicationClose`]}),Va=F({required:[`finalizeApplicationClose`,`clearRuntimeHints`]}),Ha=F({required:[`prepareAppleRunner`]}),Ua=F({required:[`clearRuntimeHints`]}),Wa=F({required:[`configureProviderPortReverse`]}),Ga=Object.freeze([Ua,Wa]),z=F({required:[`appLogInspect`]}),Ka=F({required:[`appLogInspect`,`appLogDoctor`]}),qa=F({required:[`appLogInspect`,`appLogStart`]}),Ja=F({required:[],preferred:[`appLogInspect`]}),Ya=Object.freeze([z,Ka,qa]);function Xa(t){let n=(t.action??`path`).toLowerCase();if(t.restart&&n!==`clear`)throw new e(`INVALID_ARGS`,`logs --restart is only supported with logs clear`);switch(n){case`path`:return Object.freeze({kind:`path`,requiresAppSession:!1,use:z});case`start`:return Object.freeze({kind:`start`,requiresAppSession:!0,use:qa});case`stop`:return Object.freeze({kind:`stop`,requiresAppSession:!1,use:z});case`doctor`:return Object.freeze({kind:`doctor`,requiresAppSession:!1,use:Ka});case`mark`:return Object.freeze({kind:`mark`,marker:t.marker??``,requiresAppSession:!1,use:z});case`clear`:return t.restart?Object.freeze({kind:`clear-restart`,requiresAppSession:!0,use:qa}):Object.freeze({kind:`clear`,requiresAppSession:!1,use:z});default:throw new e(`INVALID_ARGS`,`logs requires path, start, stop, doctor, mark, or clear`)}}function Za(e){let t=new Map;for(let n of e){if(!s(n.family))throw TypeError(`Unknown platform family registration: ${String(n.family)}`);if(t.has(n.family))throw TypeError(`Duplicate platform family registration: ${n.family}`);t.set(n.family,Qa(n))}let n=l.filter(e=>!t.has(e));if(n.length>0)throw TypeError(`Missing platform family registrations: ${n.join(`, `)}`);let r=Object.freeze([...l]),i=Object.freeze(r.map(e=>$a(t,e)));return Object.freeze({families:r,modules:i,get:e=>$a(t,e)})}function Qa(e){return Object.freeze({...e})}function $a(e,t){let n=e.get(t);if(!n)throw TypeError(`Missing platform family registration: ${t}`);return n}const eo=Object.freeze({kind:`device-inventory`});function to(e){let t=e.platformExecution;if(t===void 0)throw TypeError(`Command descriptor "${e.name}" must declare platformExecution (none, legacy, inventory, or device-runtime); there is no registry-entry default`);if(Ti(t),t.kind===`none`&&e.capability!==void 0)throw TypeError(`Command descriptor "${e.name}" declares platformExecution none but keeps a capability bucket; a command with platform admission is not platform-free`);return t}const no={leaseAdmissionExempt:!0,sessionExecutionLockExempt:!0},B={leaseAdmissionExempt:!0,sessionExecutionLockExempt:!0,selectorValidationExempt:!0},ro=()=>!0,io=e=>(e.positionals?.[0]??``).toLowerCase()===`start`,ao=e=>e.command===`test`&&(typeof e.flags?.shardAll==`number`||typeof e.flags?.shardSplit==`number`),oo=new Set([`status`,`get`]),so=e=>mo(e,oo,`status`),co=new Set([`get`,`wait`]),lo=e=>mo(e,co,`get`),uo=e=>ho(e,oo,`status`),fo=e=>ho(e,co,`get`),po=e=>{try{return wn(Pn(e.positionals??[]).action)?`observes-app`:`mutates-app`}catch{return`mutates-app`}};function mo(e,t,n){return t.has((e.positionals?.[0]??n).toLowerCase())?`preserve`:`may-invalidate`}function ho(e,t,n){return t.has((e.positionals?.[0]??n).toLowerCase())?`observes-app`:`mutates-app`}const V={simulator:!0,device:!0},H={emulator:!0,device:!0,unknown:!0},go={emulator:!0},U={device:!0},W={},G={apple:V,android:H,linux:U},K={kind:`none`},q={kind:`legacy`},J={recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:V,android:H,linux:U},timeoutPolicy:j,batchable:!0},Y={...j,onTimeout:`preserve-daemon`},_o={...j,envelopeMs:18e4},vo={...j,budget:{source:`flag`,envelope:`widen`,defaultBudgetMs:1e4},onTimeout:`preserve-daemon`},yo={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}}},bo={fields:{delayMs:{defaultValue:0}}};function X(e,t){return yr(e)===void 0?t:vo}function Z(e){let t=yr(e);if(t===void 0)throw Error(`Missing post-action observation descriptor support for ${e}`);return t}const xo=[{name:`lease_allocate`,catalog:{group:`internal`,key:`leaseAllocate`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...no},timeoutPolicy:j,batchable:!1,platformExecution:K},{name:`lease_heartbeat`,catalog:{group:`internal`,key:`leaseHeartbeat`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...no},timeoutPolicy:j,batchable:!1,platformExecution:K},{name:`lease_release`,catalog:{group:`internal`,key:`leaseRelease`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...no},timeoutPolicy:j,batchable:!1,platformExecution:K},{name:`artifacts`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...no},timeoutPolicy:j,batchable:!1,platformExecution:K},{name:`session_list`,catalog:{group:`internal`,key:`sessionList`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,...B},timeoutPolicy:j,batchable:!1,platformExecution:K},{name:`session_save_script`,catalog:{group:`internal`,key:`sessionSaveScript`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`publication`},timeoutPolicy:j,batchable:!1,platformExecution:K},{name:`devices`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,...B},timeoutPolicy:j,batchable:!0,platformExecution:{kind:`inventory`,use:eo}},{name:`capabilities`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,preferExplicitDeviceOverExistingSession:!0,...B},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`doctor`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,allowSessionlessDefaultDevice:ro,...B},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`apps`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,preferExplicitDeviceOverExistingSession:!0},platformExecution:{kind:`device-runtime`,uses:[mi]},timeoutPolicy:j,batchable:!0},{name:`boot`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`may-invalidate`,sessionKind:`state`},platformExecution:{kind:`device-runtime`,uses:hi},timeoutPolicy:j,batchable:!0},{name:`shutdown`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`may-invalidate`,sessionKind:`state`},platformExecution:{kind:`device-runtime`,use:xi},timeoutPolicy:j,batchable:!0},{name:`appstate`,catalog:{group:`public`,key:`appState`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`state`},platformExecution:{kind:`device-runtime`,uses:bi},timeoutPolicy:j,batchable:!0},{name:`perf`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},capability:{apple:V,android:H,linux:W},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`logs`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},platformExecution:{kind:`device-runtime`,uses:Ya},timeoutPolicy:j,batchable:!0},{name:`events`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`,allowInvalidRecording:!0,...B},timeoutPolicy:j,batchable:!1,platformExecution:q},{name:`network`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},platformExecution:{kind:`device-runtime`,use:aa},timeoutPolicy:j,batchable:!0},{name:`audio`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},capability:{apple:V,android:{emulator:!0},linux:W},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`replay`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,sessionKind:`replay`,skipSessionlessProviderDevice:ao,saveScriptFlagOwner:!0},timeoutPolicy:{...j,budget:{source:`flag`}},batchable:!1,platformExecution:q},{name:`test`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,sessionKind:`replay`,skipSessionlessProviderDevice:ao},timeoutPolicy:{...j,envelopeMs:`unbounded`},batchable:!0,platformExecution:q},{name:`runtime`,catalog:{group:`internal`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`},timeoutPolicy:j,batchable:!1,platformExecution:{kind:`device-runtime`,uses:Ga}},{name:`clipboard`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`session`,refFrameEffect:`preserve`},dispatch:{},capability:{apple:V,android:H,linux:U},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`keyboard`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:uo,daemon:{route:`session`,refFrameEffect:so,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:V,android:H,linux:W},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`install`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},platformExecution:{kind:`device-runtime`,use:Si},timeoutPolicy:_o,batchable:!0},{name:`reinstall`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},platformExecution:{kind:`device-runtime`,use:Si},timeoutPolicy:_o,batchable:!0},{name:`install_source`,catalog:{group:`internal`,key:`installSource`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},platformExecution:{kind:`device-runtime`,use:Ci},timeoutPolicy:_o,batchable:!1},{name:`release_materialized_paths`,catalog:{group:`internal`,key:`releaseMaterializedPaths`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,...B},timeoutPolicy:j,batchable:!1,platformExecution:K},{name:`push`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},platformExecution:{kind:`device-runtime`,use:wi},timeoutPolicy:j,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:V,android:H,linux:W},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`open`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`,allowSessionlessDefaultDevice:ro,saveScriptFlagOwner:!0},timeoutPolicy:j,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Ia}},{name:`prepare`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`},timeoutPolicy:{budget:{source:`flag`},envelopeMs:_r,onTimeout:`reset-daemon`},batchable:!1,mcpExposed:!1,platformExecution:{kind:`device-runtime`,use:Ha}},{name:`batch`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`},timeoutPolicy:j,batchable:!1,platformExecution:q},{name:`close`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`,allowInvalidRecording:!0,saveScriptFlagOwner:!0},timeoutPolicy:j,batchable:!0,platformExecution:{kind:`device-runtime`,uses:za}},{name:`snapshot`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},dispatch:{},capability:G,timeoutPolicy:{...Y,budget:{source:`flag`}},batchable:!0,platformExecution:q},{name:`diff`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},capability:G,timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`wait`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,targetIdentityVerification:`post-resolution`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},capability:G,timeoutPolicy:{...Y,budget:{source:`positional-parser`,parser:gr}},batchable:!0,platformExecution:q},{name:`alert`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:fo,daemon:{route:`snapshot`,refFrameEffect:lo},capability:{apple:V,android:H,linux:W},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`settings`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`snapshot`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:V,android:H,linux:W},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`react-native`,catalog:{group:`public`,key:`reactNative`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`reactNative`,refFrameEffect:`may-invalidate`},capability:{apple:V,android:H,linux:W},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`record`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`recordTrace`,refFrameEffect:`preserve`,allowInvalidRecording:!0,allowSessionlessDefaultDevice:io},platformExecution:{kind:`device-runtime`,uses:$i},timeoutPolicy:j,batchable:!0},{name:`trace`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`recordTrace`,refFrameEffect:`preserve`},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`find`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:po,daemon:{route:`find`,refFrameEffect:`may-invalidate`},capability:G,timeoutPolicy:Y,batchable:!0,platformExecution:q},{name:`click`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},capability:{apple:V,android:H,linux:U},timeoutPolicy:X(`click`,Y),postActionObservation:Z(`click`),responseDataTransform:yo,batchable:!0,platformExecution:q},{name:`fill`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:V,android:H,linux:U},timeoutPolicy:X(`fill`,Y),postActionObservation:Z(`fill`),responseDataTransform:bo,batchable:!0,platformExecution:q},{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:V,android:H,linux:U},timeoutPolicy:{...vo,envelopeMs:21e4},postActionObservation:Z(`longpress`),batchable:!0,platformExecution:q},{name:`press`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:V,android:H,linux:U},timeoutPolicy:X(`press`,Y),postActionObservation:Z(`press`),responseDataTransform:yo,batchable:!0,platformExecution:q},{name:`type`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:G,timeoutPolicy:X(`type`,Y),batchable:!0,platformExecution:q},{name:`get`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`interaction`,refFrameEffect:`preserve`},capability:G,timeoutPolicy:X(`get`,Y),batchable:!0,platformExecution:q},{name:`read`,catalog:{group:`dispatch-alias`},recordsSessionAction:!1,dispatch:{},timeoutPolicy:j,batchable:!1,platformExecution:q},{name:`is`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`interaction`,refFrameEffect:`preserve`},capability:G,timeoutPolicy:X(`is`,Y),batchable:!0,platformExecution:q},{name:`back`,catalog:{group:`public`},...J,capability:{...J.capability,vega:go},timeoutPolicy:X(`back`,j),postActionObservation:Z(`back`),platformExecution:q},{name:`gesture`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,targetIdentityVerification:`pre-dispatch`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},capability:G,timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`home`,catalog:{group:`public`},...J,capability:{...J.capability,vega:go},platformExecution:q},{name:`tv-remote`,catalog:{group:`public`,key:`tvRemote`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:V,android:H,vega:go,linux:W},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`orientation`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:V,android:H,linux:W},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`scroll`,catalog:{group:`public`},...J,timeoutPolicy:X(`scroll`,j),postActionObservation:Z(`scroll`),platformExecution:q},{name:`swipe`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},capability:{apple:V,android:H,linux:U},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`focus`,catalog:{group:`public`},...J,platformExecution:q},{name:`screenshot`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`generic`,refFrameEffect:`preserve`},dispatch:{},capability:G,timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`viewport`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:{},android:{},linux:W},timeoutPolicy:j,batchable:!1,platformExecution:q},{name:`app-switcher`,catalog:{group:`public`,key:`appSwitcher`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:V,android:H,linux:W},timeoutPolicy:j,batchable:!0,platformExecution:q},{name:`install-from-source`,catalog:{group:`public`,key:`installFromSource`},recordsSessionAction:!0,recordingEffect:`mutates-app`,platformExecution:{kind:`device-runtime`,use:Ci},timeoutPolicy:j,batchable:!0},{name:`debug`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:j,batchable:!1,platformExecution:q},{name:`daemon`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:j,batchable:!1,mcpExposed:!1,platformExecution:q},{name:`device`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:j,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`metro`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:j,batchable:!1,platformExecution:K},{name:`session`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:j,batchable:!1,platformExecution:K},{name:`cdp`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:j,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`auth`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:j,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`connect`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:j,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`connection`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:j,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`disconnect`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:j,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`mcp`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:j,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`proxy`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:j,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`react-devtools`,catalog:{group:`local-cli`,key:`reactDevtools`},recordsSessionAction:!1,timeoutPolicy:j,batchable:!1,mcpExposed:!1,platformExecution:q},{name:`web`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:j,batchable:!1,mcpExposed:!1,platformExecution:q}],So=new Set([`public`,`local-cli`]),Co=new Set(xo.filter(e=>So.has(ko(e))).map(e=>e.name)),Q=xo.map(e=>{let t=to(e);return e.name===`record`&&na(t),{...e,mcpExposed:Do(e),platformExecution:t}});function wo(e){return Q.filter(t=>ko(t)===e).map(e=>[Ao(e),e.name])}function To(){return Q.filter(e=>Oo(e)).map(e=>e.name).sort()}const $=new Map(Q.map(e=>[e.name,e]));function Eo(e){return Co.has(e)}function Do(e){return e.mcpExposed??Co.has(e.name)}function Oo(e){return e.mcpExposed&&Eo(e.name)}function ko(e){return e.catalog.group}function Ao(e){return e.catalog.key??e.name}const jo=new Map(Q.map(e=>[e.name,e.timeoutPolicy])),Mo=new Map(Array.from($.values()).flatMap(e=>e.responseDataTransform?[[e.name,e.responseDataTransform]]:[]));function No(e){if(e!==void 0)return $.get(e)?.postActionObservation}function Po(e){return No(e)!==void 0}function Fo(e){return No(e)===`settle-and-verify`}function Io(e){return e===void 0?j:jo.get(e)??j}function Lo(e){if(e!==void 0)return Mo.get(e)}function Ro(e){return e===void 0?!1:$.get(e)?.recordsSessionAction??!1}function zo(e){return $.get(e)?.targetIdentityVerification}function Bo(e){let t=$.get(e.command);if(t?.recordsSessionAction)return typeof t.recordingEffect==`function`?t.recordingEffect(e):t.recordingEffect}function Vo(){return[...new Set(Array.from(Mo.values()).flatMap(e=>Object.keys(e.fields)))].sort()}function Ho(e){return Number.isInteger(e)&&e>=1&&e<=1e3}function Uo(t,n){if(t>n)throw new e(`INVALID_ARGS`,`batch has ${t} steps; max allowed is ${n}.`)}function Wo(t,n){if(!f(t))throw new e(`INVALID_ARGS`,`Invalid batch step ${n}.`);return t}function Go(t,n){let r=t.input;if(!f(r))throw new e(`INVALID_ARGS`,`Batch step ${n} input must be an object.`);return r}function Ko(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 qo(e){let t=[];for(let n of e)n.daemon&&t.push({command:n.name,...n.daemon,replayScopedAction:n.recordsSessionAction});return t}function Jo(e){let t={};for(let n of e)n.capability&&(t[n.name]=n.capability);return t}function Yo(e){return e.filter(e=>e.batchable).map(e=>e.name)}const Xo=Yo(Q),Zo=new Set([`batch`,`replay`]),Qo=[`command`,`positionals`,`input`,`flags`,`runtime`],$o=[`platform`,`target`,`device`,`udid`,`serial`,`verbose`,`out`],es=new Set(Xo);function ts(e){return es.has(e)}function ns(e){return typeof e==`string`?e.trim().toLowerCase():``}function rs(t,n){let r=ns(t);if(ts(r))return r;throw new e(`INVALID_ARGS`,`Batch step ${n} command is not available through command batch: ${String(t)}`)}function is(t,n){if(Zo.has(t))throw new e(`INVALID_ARGS`,`Batch step ${n} cannot run ${t}.`)}const as=new Set(Qo);async function os(e,t,n){let r=ps(e.flags),a=r?.batchOnError??`stop`;if(a!==`stop`)return ms(`INVALID_ARGS`,`Unsupported batch on-error mode: ${a}.`);let o=r?.batchMaxSteps??100;if(!Ho(o))return ms(`INVALID_ARGS`,`Invalid batch max-steps: ${String(r?.batchMaxSteps)}`);try{let i=ss(r?.batchSteps,o),a=Date.now(),s=[];for(let[r,a]of i.entries()){let o=await fs(e,t,a,n,r+1,r===i.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,...o.error.retriable===void 0?{}:{retriable:o.error.retriable},...o.error.supportedOn===void 0?{}:{supportedOn:o.error.supportedOn},details:{...o.error.details??{},step:o.step,command:a.command,positionals:a.positionals,executed:r,total:i.length,partialResults:s}}};s.push(o.result)}return{ok:!0,data:{total:i.length,executed:i.length,totalDurationMs:Date.now()-a,results:s}}}catch(e){let t=i(e);return ms(t.code,t.message,t.details)}}function ss(t,n){if(!Array.isArray(t)||t.length===0)throw new e(`INVALID_ARGS`,`batch requires a non-empty batchSteps array.`);Uo(t.length,n);let r=[];for(let n=0;n<t.length;n+=1){let i=t[n];if(!m(i))throw new e(`INVALID_ARGS`,`Invalid batch step at index ${n}.`);let a=Object.keys(i).filter(e=>!as.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=ns(i.command);if(!o)throw new e(`INVALID_ARGS`,`Batch step ${n+1} requires command.`);if(is(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&&!m(i.flags))throw new e(`INVALID_ARGS`,`Batch step ${n+1} flags must be an object.`);if(i.input!==void 0&&!m(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:Ko(i.runtime,n+1)})}return r}function cs(e,t){let{batchSteps:n,batchOnError:r,batchMaxSteps:i,...a}=t??{};return ls(ps(e),a)}function ls(e,t){let n=ps(e)??{},r=t;for(let e of $o)r[e]===void 0&&n[e]!==void 0&&(r[e]=n[e]);return t}function us(e,n){return t(e)?n?e:`digest`:e}function ds(e,t){let n=e?.responseLevel,r=us(n,t);return r===n?e:{...e,responseLevel:r}}async function fs(e,t,n,r,i,a){let o=Date.now(),s=cs(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:ds(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 ps(e){return e}function ms(e,t,n){return{ok:!1,error:{code:e,message:t,...n?{details:n}:{}}}}export{Xi as $,Ye as $n,nr as $t,Ba as A,un as An,de as Ar,Nr as At,ya as B,yt as Bn,ye as Br,Er as Bt,Za as C,mn as Cn,we as Cr,ei as Ct,La as D,rn as Dn,ve as Dr,Hr as Dt,Ua as E,fn as En,xe as Er,Xr as Et,Na as F,Wt as Fn,ce as Fr,Mr as Ft,ma as G,Ct as Gn,mr as Gt,Aa as H,St as Hn,_r as Ht,Ha as I,Rt as In,oe as Ir,Dr as It,pa as J,ft as Jn,dr as Jt,R as K,ut as Kn,sr as Kt,Fa as L,C as Ln,se as Lr,wr as Lt,ja as M,Vt as Mn,le as Mr,Pr as Mt,Pa as N,zt as Nn,ae as Nr,Lr as Nt,Ra as O,ln as On,_e as Or,Ur as Ot,Ma as P,Ht as Pn,ie as Pr,Ir as Pt,Qi as Q,Xe as Qn,er as Qt,Ea as R,wt as Rn,re as Rr,Cr as Rt,zo as S,_n as Sn,g as Sr,$r as St,Xa as T,pn as Tn,Se as Tr,Zr as Tt,ba as U,xt as Un,hr as Ut,Oa as V,vt as Vn,f as Vr,Or as Vt,ha as W,bt as Wn,A as Wt,la as X,Ze as Xn,rr as Xt,oa as Y,Ge as Yn,fr as Yt,ea as Z,qe as Zn,ar as Zt,To as _,In as _n,ke as _r,F as _t,Jo as a,Wn as an,Ie as ar,Vi as at,Lo as b,dn as bn,Ee as br,Qr as bt,Ho as c,Un as cn,Ve as cr,Ii as ct,Wo as d,An as dn,Pe as dr,Fi as dt,ir as en,Qe as er,Ji as et,Q as f,jn as fn,Me as fr,Si as ft,wo as g,Pn as gn,v as gr,mi as gt,Vo as h,Cn as hn,y as hr,yi as ht,rs as i,Vn as in,Be as ir,Wi as it,Va as j,Ot as jn,ue as jr,Fr as jt,Wa as k,cn as kn,m as kr,Br as kt,Ko as l,xn as ln,Ne as lr,Li as lt,Fo as m,wn as mn,je as mr,wi as mt,os as n,$n as nn,He as nr,Ki as nt,qo as o,Bn as on,Le as or,Hi as ot,Po as p,Tn as pn,Ae as pr,Ci as pt,fa as q,pt as qn,pr as qt,Xo as r,Hn as rn,b as rr,Ui as rt,Uo as s,zn as sn,Re as sr,zi as st,ls as t,Qn as tn,S as tr,qi as tt,Go as u,kn as un,ze as ur,Pi as ut,Bo as v,vn,Oe as vr,vi as vt,Ja as w,an as wn,_ as wr,ti as wt,Io as x,sn as xn,Ce as xr,ni as xt,Ro as y,T as yn,De as yr,xi as yt,va as z,Tt as zn,be as zr,Tr as zt};
|
|
@@ -29,8 +29,8 @@ type DeviceInfo = {
|
|
|
29
29
|
* The daemon renders it; it never re-derives degradation from node shapes.
|
|
30
30
|
*
|
|
31
31
|
* Defined here (the foundational snapshot type module) rather than in
|
|
32
|
-
* snapshot-quality.ts so SnapshotNode can reference it without a cyclic import;
|
|
33
|
-
* snapshot-quality.ts
|
|
32
|
+
* snapshot-quality/verdict.ts so SnapshotNode can reference it without a cyclic import;
|
|
33
|
+
* snapshot-quality/verdict.ts owns the validation logic.
|
|
34
34
|
*/
|
|
35
35
|
/**
|
|
36
36
|
* Which capture STRATEGY produced a snapshot, within one platform's plan —
|
|
@@ -146,7 +146,7 @@ type SnapshotState = {
|
|
|
146
146
|
/**
|
|
147
147
|
* Android: the capture is an occluding system surface (notification shade, quick settings)
|
|
148
148
|
* rather than app content. Consumers that surface this tree to the agent must disclose the
|
|
149
|
-
* occlusion (see
|
|
149
|
+
* occlusion (see core/android-system-surface-disclosure.ts).
|
|
150
150
|
*/
|
|
151
151
|
systemSurfaceOnly?: boolean;
|
|
152
152
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const
|
|
2
|
-
`)){let e=t.trim();if(!e||
|
|
1
|
+
import{n as e}from"./rolldown-runtime.js";const t=/(token|secret|password|authorization|cookie|api[_-]?key|access[_-]?key|private[_-]?key|user[_-]?code|device[_-]?code|refresh[_-]?credential)/i,n=/\b(?:bearer\s+[a-z0-9._-]+|adc_(?:agent|live|refresh|cli)_[a-z0-9._-]+)\b/gi,r=/\b([a-z0-9_-]*(?:api[_-]?key|token|secret|password|user[_-]?code|device[_-]?code|refresh[_-]?credential)[a-z0-9_-]*)(\s*[=:]\s*)("[^"]*"|'[^']*'|\S+)/gi,i=/https?:\/\/[^\s"'<>]+/gi;function a(e){return o(e,new WeakSet)}function o(e,n,r){if(e==null)return e;if(typeof e==`string`)return s(e,r);if(typeof e!=`object`)return e;if(n.has(e))return`[Circular]`;if(n.add(e),Array.isArray(e))return e.map(e=>o(e,n));let i={};for(let[r,a]of Object.entries(e)){if(t.test(r)){i[r]=`[REDACTED]`;continue}i[r]=o(a,n,r)}return i}function s(e,i){let a=e.trim();if(!a)return e;if(i&&t.test(i))return`[REDACTED]`;let o=c(a);return o=o.replace(n,`[REDACTED]`),o=o.replace(r,(e,t,n,r,i,a)=>u({key:t,separator:n,rawValue:r,offset:i,input:a})||l(r)?e:`${t}${n}[REDACTED]`),o===a?a.length>400?`${a.slice(0,200)}...<truncated>`:a:o}function c(e){return e.replace(i,e=>d(e)??e)}function l(e){return/^adc_(?:agent|live|refresh|cli)_\.\.\.$/i.test(e)}function u(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 d(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}}var f=e({AppError:()=>h,KNOWN_APP_ERROR_CODES:()=>p,asAppError:()=>_,defaultHintForCode:()=>j,isAgentDeviceError:()=>v,normalizeAgentDeviceError:()=>y,normalizeError:()=>b,retriableForErrorCode:()=>A,throwDaemonError:()=>g,toAppErrorCode:()=>m});const p=[`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 m(e,t=`COMMAND_FAILED`){return typeof e==`string`&&e.length>0?e:t}var h=class extends Error{code;details;cause;constructor(e,t,n,r){super(t),this.code=e,this.details=n,this.cause=r}};function g(e){throw new h(m(e.code),e.message,{...e.details??{},hint:e.hint,diagnosticId:e.diagnosticId,logPath:e.logPath,retriable:e.retriable,supportedOn:e.supportedOn})}function _(e,t=`UNKNOWN`){return e instanceof h?e:e instanceof Error?new h(t,e.message,void 0,e):new h(t,`Unknown error`,{err:e})}function v(e){return e instanceof h}function y(e,t={}){return b(e,t)}function b(e,t={}){let n=_(e),r=n.details?a(n.details):void 0,i=T(r,`diagnosticId`)??t.diagnosticId,o=T(r,`logPath`)??t.logPath,s=T(r,`hint`)??j(n.code),c=E(r,`retriable`)??A(n.code),l=T(r,`supportedOn`),u=D(r),d=ee(n.code,n.message,r);return{code:n.code,message:d,hint:s,diagnosticId:i,logPath:o,...c===void 0?{}:{retriable:c},...l===void 0?{}:{supportedOn:l},details:u}}const x=/^\S+ exited with code -?\d+$/;function ee(e,t,n){if(e!==`COMMAND_FAILED`||n?.processExitError!==!0)return t;let r=w(typeof n?.stderr==`string`?n.stderr:``);return r?x.test(t)?r:t.includes(r)?t:`${t}: ${r}`:t}const S=[/^an error was encountered processing the command/i,/^underlying error\b/i,/^simulator device failed to complete the requested operation/i],C=/^(?:(?:adb|xcrun|simctl):\s*)?(?:error:\s*)?/i;function w(e){for(let t of e.split(`
|
|
2
|
+
`)){let e=t.trim();if(!e||S.some(t=>t.test(e)))continue;let n=e.replace(C,``).trim();if(n)return n.length>200?`${n.slice(0,200)}...`:n}return null}function T(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function E(e,t){let n=e?.[t];return typeof n==`boolean`?n:void 0}function D(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 O={DEVICE_IN_USE:!0};function k(e){return p.includes(e)}function A(e){return k(e)?O[e]:void 0}function j(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 M(e){return e===`xctest`||e===`android`||e===`harmonyos-arkui`||e===`macos-helper`||e===`linux-atspi`||e===`web`}function N(e){return e===void 0||e===`xctest`||e===`android`||e===`harmonyos-arkui`}function P(e){return e.map((e,t)=>({...e,ref:`e${t+1}`}))}const F=/^~s(\d+)$/,I=`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 L(e){let t=e.trim(),n=t.indexOf(`~`);if(n===-1)return{base:t};let r=F.exec(t.slice(n));return!r||n===0?null:{base:t.slice(0,n),generation:Number(r[1])}}function R(e){let t=L(e);if(!t)return null;let n=t.base;return n.startsWith(`@`)?n.slice(1)||null:n.startsWith(`e`)?n:null}function z(e,t){return e.find(e=>e.ref===t)??null}function B(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,customActions:e?.customActions===!0})}function V(e){if(e)return{depth:e.snapshotDepth,interactiveOnly:e.snapshotInteractiveOnly,raw:e.snapshotRaw,scope:e.snapshotScope,customActions:e.snapshotCustomActions}}function H(e){return{x:Math.round(e.x+e.width/2),y:Math.round(e.y+e.height/2)}}const U=[`summary`,`headers`,`body`,`all`],W=[`digest`,`default`,`full`];function G(e){return e!==void 0&&e!=="default"}function K(e){return{parse(t){return e(t,`$`)}}}function q(e,t){throw Error(`${e}: ${t}`)}function J(e,t){return(!e||typeof e!=`object`||Array.isArray(e))&&q(t,`Expected an object`),e}function Y(e,t){return typeof e!=`string`&&q(t,`Expected a string`),e}function X(e,t){return Number.isInteger(e)||q(t,`Expected an integer`),e}function Z(e,t){return Array.isArray(e)||q(t,`Expected an array`),e}function Q(e,t,n){let r=e[t];return r===void 0?void 0:Y(r,`${n}.${t}`)}function te(e,t,n){let r=e[t];if(r!==void 0)return Z(r,`${n}.${t}`).map((e,r)=>Y(e,`${n}.${t}[${String(r)}]`))}function ne(e,t,n){let r=e[t];return r===void 0?void 0:X(r,`${n}.${t}`)}function $(e,t,n){let r=e[t];return r===void 0?void 0:J(r,`${n}.${t}`)}function re(e,t,n,r){let i=e[t];if(i!==void 0)return(typeof i!=`string`||!n.includes(i))&&q(`${r}.${t}`,`Expected one of: ${n.join(`, `)}`),i}const ie=K((e,t)=>{let n=J(e,t);return{platform:re(n,`platform`,[`ios`,`android`],t),metroHost:Q(n,`metroHost`,t),metroPort:ne(n,`metroPort`,t),bundleUrl:Q(n,`bundleUrl`,t),launchUrl:Q(n,`launchUrl`,t)}});function ae(e,t){let n=e.id;return n==null||typeof n!=`string`&&typeof n!=`number`&&q(`${t}.id`,`Expected a string, number, or null`),n}const oe=K((e,t)=>{let n=J(e,t);return{jsonrpc:Q(n,`jsonrpc`,t),id:ae(n,t),method:Q(n,`method`,t),params:n.params}}),se=K((e,t)=>{let n=J(e,t);return{token:Q(n,`token`,t),session:Q(n,`session`,t),command:Q(n,`command`,t),positionals:te(n,`positionals`,t),input:$(n,`input`,t),flags:$(n,`flags`,t),runtime:$(n,`runtime`,t),meta:$(n,`meta`,t)}});export{b as C,a as D,m as E,y as S,g as T,h as _,G as a,f as b,P as c,z as d,M as f,N as g,L as h,ie as i,B as l,V as m,W as n,oe as o,R as p,se as r,I as s,U as t,H as u,_ as v,A as w,v as x,j as y};
|
package/dist/src/sdk-device.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e}from"./sdk-contracts.js";function t(e){return Object.freeze({family:e.platform,...e.appleOs===void 0?{}:{appleOs:e.appleOs},kind:e.kind,...e.target===void 0?{}:{target:e.target},...e.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.iosPhysicalDeviceBackend}})}function n(e){return Object.freeze({id:e.id,...t(e)})}function r(e){return JSON.stringify([e.id,...o(e)])}function i(e,t){return r(e)===r(t)}function a(e,t){return JSON.stringify(o(e))===JSON.stringify(o(t))}function o(e){return[e.family,e.appleOs??null,e.kind,e.target??null,e.iosPhysicalDeviceBackend??null]}const s=[`ios`,`ipados`,`tvos`,`watchos`,`visionos`,`macos`],c=[`apple`,`android`,`harmonyos`,`vega`,`linux`,`web`],l=[`ios`,`macos`,`android`,`harmonyos`,`vega`,`linux`,`web`],u=[...c,`ios`,`macos`],d=[`mobile`,`tv`,`desktop`];function f(e){return e===`apple`||e===`ios`||e===`macos`}function p(e){return e.appleOs===`macos`||e.platform===`macos`}function m(e){return f(e.platform)&&!p(e)}function h(e){return e.platform===`android`||e.platform===`harmonyos`||f(e.platform)&&!p(e)}function g(e){return f(e.platform)?p(e)?`macos`:`ios`:e.platform}function _(e){return e===`macos`?{platform:`apple`,appleOs:`macos`}:e===`ios`?{platform:`apple`}:{platform:e}}function v(e){return f(e.platform)&&e.target===`tv`}function y(e){return e.appleOs?e.appleOs:e.platform===`macos`?`macos`:v(e)?`tvos`:`ios`}function b(e){return c.includes(e)}function x(e){return l.includes(e)}function S(e){return s.includes(e)}function C(e,t){return t?t===`apple`?f(e.platform):t===`ios`?f(e.platform)&&!p(e):t===`macos`?f(e.platform)&&p(e):e.platform===t:!0}function w(e,t){return t?T(t):e===`macos`||e===`desktop`?`macOS`:e===`tv`?`tvOS`:`iOS`}function T(e){switch(e){case`tvos`:return`tvOS`;case`macos`:return`macOS`;case`visionos`:return`visionOS`;default:return`iOS`}}function E(e){let{simulatorSetPath:t,platform:n,target:r}=e;if(t&&!(n===`macos`||r===`desktop`))return t}function D(e){return e.map((e,t)=>({device:e,index:t})).sort((e,t)=>
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";function t(e){return Object.freeze({family:e.platform,...e.appleOs===void 0?{}:{appleOs:e.appleOs},kind:e.kind,...e.target===void 0?{}:{target:e.target},...e.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.iosPhysicalDeviceBackend}})}function n(e){return Object.freeze({id:e.id,...t(e)})}function r(e){return JSON.stringify([e.id,...o(e)])}function i(e,t){return r(e)===r(t)}function a(e,t){return JSON.stringify(o(e))===JSON.stringify(o(t))}function o(e){return[e.family,e.appleOs??null,e.kind,e.target??null,e.iosPhysicalDeviceBackend??null]}const s=[`ios`,`ipados`,`tvos`,`watchos`,`visionos`,`macos`],c=[`apple`,`android`,`harmonyos`,`vega`,`linux`,`web`],l=[`ios`,`macos`,`android`,`harmonyos`,`vega`,`linux`,`web`],u=[...c,`ios`,`macos`],d=[`mobile`,`tv`,`desktop`];function f(e){return e===`apple`||e===`ios`||e===`macos`}function p(e){return e.appleOs===`macos`||e.platform===`macos`}function m(e){return f(e.platform)&&!p(e)}function h(e){return e.platform===`android`||e.platform===`harmonyos`||f(e.platform)&&!p(e)}function g(e){return f(e.platform)?p(e)?`macos`:`ios`:e.platform}function _(e){return e===`macos`?{platform:`apple`,appleOs:`macos`}:e===`ios`?{platform:`apple`}:{platform:e}}function v(e){return f(e.platform)&&e.target===`tv`}function y(e){return e.appleOs?e.appleOs:e.platform===`macos`?`macos`:v(e)?`tvos`:`ios`}function b(e){return c.includes(e)}function x(e){return l.includes(e)}function S(e){return s.includes(e)}function C(e,t){return t?t===`apple`?f(e.platform):t===`ios`?f(e.platform)&&!p(e):t===`macos`?f(e.platform)&&p(e):e.platform===t:!0}function w(e,t){return t?T(t):e===`macos`||e===`desktop`?`macOS`:e===`tv`?`tvOS`:`iOS`}function T(e){switch(e){case`tvos`:return`tvOS`;case`macos`:return`macOS`;case`visionos`:return`visionOS`;default:return`iOS`}}function E(e){let{simulatorSetPath:t,platform:n,target:r}=e;if(t&&!(n===`macos`||r===`desktop`))return t}function D(e){return e.map((e,t)=>({device:e,index:t})).sort((e,t)=>H(e,t)).map(({device:e})=>e)}function O(e){return!e||e===`apple`||e===`ios`}async function k(e,t,n={}){let r=e.filter(e=>I(e,t));return A(r,t)||N(r,t.deviceName)||(G(r)&&(r=D(r)),P(r,t,n))}function A(e,t){if(t.udid)return j(e,t.udid);if(t.serial)return M(e,t)}function j(t,n){let r=t.find(e=>e.id===n&&f(e.platform));if(!r)throw new e(`DEVICE_NOT_FOUND`,`No Apple device with UDID ${n}`);return r}function M(t,n){let r=t.find(e=>e.id===n.serial&&R(e.platform));if(!r)throw new e(`DEVICE_NOT_FOUND`,z(n));return r}function N(t,n){if(!n)return;let r=V(n),i=t.find(e=>V(e.name)===r);if(!i)throw new e(`DEVICE_NOT_FOUND`,`No device named ${n}`);return i}function P(e,t,n){let r=e[0];if(r!==void 0&&e.length===1)return r;e.length===0&&B(t,n);let i=F(e);return i||B(t,n),i}function F(e){let t=e.filter(e=>e.kind!==`device`),n=t.length>0?t:e;if(G(n))return n[0];let r=n.filter(e=>e.booted),i=r[0];return i&&r.length===1?i:r[0]??n[0]}function I(e,t,n={}){return C(e,t.platform)&&(!t.target||(e.target??`mobile`)===t.target)&&(!n.includeExplicitSelectors||L(e,t))}function L(e,t){return!(t.udid&&!(e.id===t.udid&&f(e.platform))||t.serial&&!(e.id===t.serial&&R(e.platform))||t.deviceName&&V(e.name)!==V(t.deviceName))}function R(e){return e===`android`||e===`harmonyos`||e===`vega`}function z(e){return e.platform===`android`?`No Android device with serial ${e.serial}`:e.platform===`vega`?`No Vega VVD with serial ${e.serial}`:e.platform===`harmonyos`?`No HarmonyOS device with serial ${e.serial}`:`No Android, HarmonyOS device, or Vega VVD with serial ${e.serial}`}function B(t,n){let r=n.simulatorSetPath;throw r&&O(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 V(e){return e.toLowerCase().replace(/_/g,` `).replace(/\s+/g,` `).trim()}function H(e,t){return U(e.device)-U(t.device)||Number(t.device.booted===!0)-Number(e.device.booted===!0)||e.device.name.localeCompare(t.device.name)||e.index-t.index}function U(e){return e.kind===`simulator`?W(e,0,1,2,3):e.kind===`device`&&f(e.platform)&&!p(e)?W(e,10,11,12,13):14}function W(e,t,n,r,i){return{mobile:K(e.name)?n:t,tv:r,desktop:i}[e.target??`mobile`]}function G(e){return e.length>0&&e.every(e=>f(e.platform))}function K(e){return/\bipad\b/i.test(e)}export{n as C,a as D,i as E,D as S,t as T,g as _,_ as a,k as b,m as c,b as d,x as f,C as g,I as h,l as i,p as l,v as m,c as n,S as o,R as p,u as r,f as s,d as t,h as u,w as v,r as w,y as x,E as y};
|
package/dist/src/sdk-finders.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{pn 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};
|