agent-device 0.19.2 → 0.19.3
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/android-multitouch-helper/dist/{agent-device-android-multitouch-helper-0.19.2.apk → agent-device-android-multitouch-helper-0.19.3.apk} +0 -0
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.3.apk.sha256 +1 -0
- package/android-multitouch-helper/dist/{agent-device-android-multitouch-helper-0.19.2.manifest.json → agent-device-android-multitouch-helper-0.19.3.manifest.json} +4 -4
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.19.2.apk → agent-device-android-snapshot-helper-0.19.3.apk} +0 -0
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.19.3.apk.sha256 +1 -0
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.19.2.manifest.json → agent-device-android-snapshot-helper-0.19.3.manifest.json} +6 -6
- package/dist/apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.h +7 -0
- package/dist/apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +99 -30
- package/dist/apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +9 -1
- package/dist/apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +21 -8
- package/dist/apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +10 -0
- package/dist/apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SequenceExecution.swift +1 -0
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/android-adb.js +1 -1
- package/dist/src/android-input-ownership.js +1 -1
- package/dist/src/android.js +1 -1
- package/dist/src/app-lifecycle.js +1 -1
- package/dist/src/apple-runner-options.js +1 -1
- package/dist/src/apps.js +5 -5
- package/dist/src/audio-probe.js +1 -1
- package/dist/src/cli-help.js +14 -14
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +11 -11
- package/dist/src/client.js +2 -2
- package/dist/src/contracts.js +1 -1
- package/dist/src/debug-symbols.js +1 -1
- package/dist/src/device-input-state.js +1 -1
- package/dist/src/devices2.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/generic.js +1 -1
- package/dist/src/helper.js +1 -1
- package/dist/src/index.d.ts +11 -7
- package/dist/src/index.js +1 -1
- package/dist/src/input-actions.js +1 -1
- package/dist/src/input-actions2.js +1 -1
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-snapshot.js +1 -1
- package/dist/src/interaction.js +1 -1
- package/dist/src/interactor.js +2 -2
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +20 -16
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/linux.js +1 -1
- package/dist/src/notifications.js +1 -1
- package/dist/src/png-worker-contract.js +1 -1
- package/dist/src/points.js +3 -3
- package/dist/src/providers.js +1 -1
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-trace-recording.js +2 -2
- package/dist/src/record-trace.js +1 -1
- package/dist/src/registry.js +14 -14
- package/dist/src/reporting.js +3 -3
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-sequence.js +1 -1
- package/dist/src/runtime-transport.js +1 -1
- package/dist/src/runtime.js +2 -2
- package/dist/src/sdk-android-adb.js +3 -3
- package/dist/src/sdk-app-inventory.js +1 -1
- package/dist/src/sdk-batch-runner.js +2 -2
- package/dist/src/sdk-batch.js +2 -2
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-device.js +1 -0
- 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.js +1 -1
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/server.js +2 -2
- package/dist/src/session.js +10 -10
- package/dist/src/setting-state.js +1 -1
- package/dist/src/simctl.js +1 -1
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-diagnostics.js +1 -1
- package/dist/src/snapshot.js +1 -1
- package/dist/src/snapshot2.js +2 -2
- package/dist/src/tool-provider.js +2 -2
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/tv-remote.js +12 -12
- package/dist/src/web.js +1 -1
- package/package.json +11 -3
- package/server.json +2 -2
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.2.apk.sha256 +0 -1
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.19.2.apk.sha256 +0 -1
- package/dist/src/snapshot-helper.js +0 -5
package/dist/src/tv-remote.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import{A as e,B as t,F as n,O as r,P as i,j as a,k as o}from"./sdk-contracts.js";import{C as s,S as c,b as l,p as u,w as d,x as f,y as p}from"./sdk-batch.js";import{A as m,C as h,D as g,F as ee,L as te,M as ne,N as re,O as ie,S as ae,T as oe,b as se,j as ce,k as le,m as ue,p as de,w as fe,x as pe,y as me,z as he}from"./sdk-selectors.js";import{b as _}from"./sdk-batch-runner.js";import{n as ge,t as _e}from"./snapshot-quality.js";import{a as ve,i as ye,n as be,o as xe,t as Se}from"./selectors2.js";import{createHash as Ce}from"node:crypto";import we from"node:path";import{styleText as Te}from"node:util";const Ee=Pe(`public`),De=Pe(`internal`),Oe=Pe(`local-cli`),ke={help:`help`},Ae=[`pan`,`fling`,`swipe`,`pinch`,`rotate`,`transform`],je=`gesture requires one of: ${Ae.join(`, `)}`;function Me(){return[...Object.values(Ee),...Object.values(Oe)].sort()}function Ne(e){return Object.values(ke).includes(e)||Object.values(De).includes(e)?!0:Me().includes(e)}function Pe(e){let t={};for(let[n,r]of u(e))t[n]=r;return t}function v(e){return e.width>0&&e.height>0}function Fe(e,t){return!e||!t?!1:e.x>=t.x-2&&e.y>=t.y-2&&e.x+e.width<=t.x+t.width+2&&e.y+e.height<=t.y+t.height+2}function Ie(e,t){if(!e||!t)return!0;let n=e.y+e.height/2,r=t.y+t.height/2;return Math.abs(n-r)<=Math.max(e.height,t.height,1)}function Le(e){return typeof e.parentIndex!=`number`}function y(e){let t=(e.type??``).toLowerCase(),n=(e.identifier??``).trim().toLowerCase();return t.includes(`edittext`)||t.includes(`textfield`)||n===`composer`}function Re(e){let t=(e.type??``).toLowerCase();return t.includes(`scroll`)||t.includes(`list`)||t.includes(`recyclerview`)}function b(e){let t=he(e);if(!t||t!==e.identifier?.trim()||!ze(t))return t;let n=(e.type??``).toLowerCase();return n.includes(`view`)||n.includes(`layout`)||n.includes(`image`)||n.includes(`list`)||n.includes(`recyclerview`)||n.includes(`collection`)?``:t}function x(e){let t=e.trim().replace(/\s+/g,` `).toLowerCase();return!t||/^(true|false|\d+)$/.test(t)?null:t}function ze(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function Be(e,t,n){let r=e;for(;typeof r.parentIndex==`number`;){let e=t.get(r.parentIndex);if(!e)return null;if(n(e))return e;r=e}return null}function Ve(e,t){let n=[],r=[t];for(;r.length>0;){let t=r.pop();for(let i of e)i.parentIndex===t&&(n.push(i),r.push(i.index))}return n}function S(e,t,n){let r=[t];for(;r.length>0;){let t=r.pop();if(!n.has(t)){n.add(t);for(let i of e)i.parentIndex!==t||n.has(i.index)||r.push(i.index)}}}const He=[`button`,`switch`,`checkbox`,`radio`],Ue=[`button`,`image`,`textview`,`view`];function We(e,t,n){for(let r of e){if(t.has(r.index)||!qe(r))continue;let i=Je(Ve(e,r.index),r,t);if(i.label){n.set(r.index,{...r,...n.get(r.index),label:i.label});for(let n of i.removableIndexes)S(e,n,t)}}}function Ge(e,t,n){let r=new Map;for(let i of e){if(t.has(i.index)||!tt(i))continue;let a=x(b(i));if(!a)continue;let o=r.get(a);if(o&&Qe(o,i,t)){let s=$e(e,o,i,t,n);r.set(a,s);continue}r.set(a,i)}}function Ke(e,t){for(let n of e){if(t.has(n.index)||!Xe(n))continue;let r=x(b(n));if(!r)continue;let i=Ve(e,n.index).filter(e=>!t.has(e.index)&&Ze(n,e,r));for(let n of i.filter(Ye))S(e,n.index,t);let a=i.filter(e=>!Ye(e)),o=new Set(a.map(e=>x(b(e))).filter(e=>!!e));if(!(a.length<2||o.size<2))for(let n of a)S(e,n.index,t)}}function qe(e){return e.hittable===!0&&!y(e)&&!!(e.rect&&v(e.rect))&&b(e).trim().length===0}function Je(e,t,n){let r=[],i=[],a=new Set;for(let o of e){if(n.has(o.index)||!Ye(o)||!Fe(o.rect,t.rect))continue;let e=b(o).trim().replace(/\s+/g,` `),s=x(e);i.push(o.index),!(!e||!s||a.has(s))&&(a.add(s),r.push(e))}return{label:r.join(`, `),removableIndexes:i}}function Ye(e){if(e.hittable===!0||y(e))return!1;let t=(e.type??``).toLowerCase();return t.includes(`text`)||t.includes(`image`)||t.includes(`icon`)}function Xe(e){return e.hittable===!0&&!y(e)&&!!(e.rect&&v(e.rect))&&!!x(b(e))}function Ze(e,t,n){if(!tt(t)||!Fe(t.rect,e.rect))return!1;let r=x(b(t));return!!(r&&n!==r&&n.includes(r))}function Qe(e,t,n){return!n.has(e.index)&&Ie(e.rect,t.rect)&&(ot(e,t)||at(e,t))}function $e(e,t,n,r,i){let a=nt(t,n),o=a.index===t.index?n:t,s=(o.type??``).toLowerCase().includes(`image`)?`has image`:null,c=i.get(a.index)??a,l=i.get(o.index)?.presentationHints??o.presentationHints;return i.set(a.index,{...c,presentationHints:et(c.presentationHints,l,s)}),S(e,o.index,r),i.get(a.index)??a}function et(e,t,n){return[...new Set([...Array.isArray(e)?e:[],...Array.isArray(t)?t:[],...n?[n]:[]])]}function tt(e){if(!e.rect||!v(e.rect)||Le(e)||y(e))return!1;let t=(e.type??``).toLowerCase();return t===`text`||it(t,Ue)}function nt(e,t){let n=rt(e);return rt(t)>n?t:e}function rt(e){let t=(e.type??``).toLowerCase(),n=0;return it(t,He)?n+=100:t.includes(`image`)?n+=30:t.includes(`textview`)||t===`text`?n+=20:t.includes(`view`)&&(n+=10),e.hittable===!0&&(n+=20),e.enabled!==!1&&(n+=5),n}function it(e,t){return t.some(t=>e.includes(t))}function at(e,t){let n=e.parentIndex===t.index?t:t.parentIndex===e.index?e:null,r=n?.index===e.index?t:n?.index===t.index?e:null;return!n||!r?!1:nt(n,r).index===n.index}function ot(e,t){return e.parentIndex===t.parentIndex?Math.abs(e.index-t.index)<=3:e.parentIndex===t.index||t.parentIndex===e.index?!1:Math.abs((e.depth??0)-(t.depth??0))<=1&&Math.abs(e.index-t.index)<=2}function st(e,t,n){if(n.raw||!ct(e))return{nodes:t,filteredCount:0};let r=lt(t);return{nodes:r,filteredCount:t.length-r.length}}function ct(e){let t=e.androidSnapshot;return!t||typeof t!=`object`?!1:t.backend===`android-helper`}function lt(e){if(e.length===0)return e;let t=new Set,n=new Map,r=new Map(e.map(e=>[e.index,e]));return ut(e,t),dt(e,r,t,n),We(e,t,n),Ke(e,t),Ge(e,t,n),e.filter(e=>!t.has(e.index)).map(e=>n.get(e.index)??e)}function ut(e,t){for(let n of e)!n.rect||v(n.rect)||Le(n)||S(e,n.index,t)}function dt(e,t,n,r){for(let i of e){if(n.has(i.index)||i.rect||Le(i))continue;let a=Be(i,t,Re);a&&pt(r,a,ft(i,e)),S(e,i.index,n)}}function ft(e,t){let n=t.filter(t=>t.parentIndex===e.parentIndex&&t.rect&&v(t.rect)).map(e=>e.index);return n.length===0?null:e.index<Math.min(...n)?`above`:e.index>Math.max(...n)?`below`:null}function pt(e,t,n){if(!n)return;let r=e.get(t.index)??t;e.set(t.index,{...r,hiddenContentAbove:r.hiddenContentAbove===!0||n===`above`?!0:void 0,hiddenContentBelow:r.hiddenContentBelow===!0||n===`below`?!0:void 0})}function mt(e){let t=e.trim().replace(/\s+/g,` `).toLowerCase();return!t||ht(t)?null:t}function ht(e){return/\S+@\S+\.\S+/.test(e)}function gt(e){if(e.length<20)return!1;let t=new Map;for(let n of e){let e=(n.type??``).toLowerCase(),r=mt(he(n));if(!r)continue;let i=`${e}|${r}`,a=t.get(i)??[];a.push(n),t.set(i,a)}let n=0;for(let e of t.values())e.length<=1||!_t(e)||(n+=e.length);return n>=8}function _t(e){for(let t=0;t<e.length;t+=1)for(let n=t+1;n<e.length;n+=1)if(vt(e[t]?.rect,e[n]?.rect))return!0;return!1}function vt(e,t){if(!e||!t)return!0;let n=.5;return!(e.x+e.width<=t.x+n||t.x+t.width<=e.x+n||e.y+e.height<=t.y+n||t.y+t.height<=e.y+n)}const yt={application:`application`,navigationbar:`navigation-bar`,tabbar:`tab-bar`,button:`button`,imagebutton:`button`,link:`link`,cell:`cell`,statictext:`text`,checkedtextview:`text`,textbox:`text-field`,textfield:`text-field`,edittext:`text-field`,textarea:`text-view`,switch:`switch`,slider:`slider`,image:`image`,imageview:`image`,webview:`webview`,framelayout:`group`,linearlayout:`group`,relativelayout:`group`,constraintlayout:`group`,viewgroup:`group`,view:`group`,listview:`list`,recyclerview:`list`,collectionview:`collection`,searchfield:`search`,segmentedcontrol:`segmented-control`,group:`group`,window:`window`,checkbox:`checkbox`,radio:`radio`,menuitem:`menu-item`,toolbar:`toolbar`,scrollarea:`scroll-area`,scrollview:`scroll-area`,nestedscrollview:`scroll-area`,table:`table`};function C(e,t={}){let n=[],r=[];for(let i of e){let e=i.depth??0,a=i.label?.trim()||i.value?.trim()||i.identifier?.trim()||``,o=T(i.type??`Element`),s=i.inheritsLabel===!0||i.inheritsIdentifier===!0;if(o===`group`&&!a&&!s)continue;for(;n.length>0&&e<=n[n.length-1];)n.pop();let c=n.length;n.push(e),r.push({node:i,depth:c,type:o,text:bt(i,c,!1,o,t)})}return r}function bt(e,t,n,r,i={}){let a=r??T(e.type??`Element`),o=ce(e,a),s=Tt(e,a,i,o),c=` `.repeat(t),l=e.ref?`@${e.ref}`:``,u=Et(e,a,i,o);!s&&(e.inheritsLabel===!0||e.inheritsIdentifier===!0)&&u.push(`same label as parent`);let d=u.map(e=>` [${e}]`).join(``),f=s?` "${s}"`:``;return n?`${c}${l} [${a}]${d}`.trimEnd():`${c}${l} [${a}]${f}${d}`.trimEnd()}function w(e,t){let n=e.label?.trim();if(n&&Ct(t,n))return``;let r=e.value?.trim();if(St(t)){if(r)return r;if(n)return n}else if(n)return n;if(r)return r;let i=e.identifier?.trim();return!i||wt(i)&&(t===`group`||t===`image`||t===`list`||t===`collection`)?``:i}function T(e){let t=e,n=e.replace(/XCUIElementType/gi,``).toLowerCase(),r=t.includes(`.`)&&(t.startsWith(`android.`)||t.startsWith(`androidx.`)||t.startsWith(`com.`));return n.includes(`.`)&&(n=n.replace(/^android\.widget\./,``).replace(/^android\.view\./,``).replace(/^android\.webkit\./,``).replace(/^androidx\./,``).replace(/^com\.google\.android\./,``).replace(/^com\.android\./,``),r&&n.includes(`.`)&&(n=n.slice(n.lastIndexOf(`.`)+1))),n===`textview`?r?`text`:`text-view`:xt(n)||n||`element`}function xt(e){return Object.prototype.hasOwnProperty.call(yt,e)?yt[e]:void 0}function St(e){return e===`text-field`||e===`text-view`||e===`search`}function Ct(e,t){return e!==`scroll-area`&&e!==`list`&&e!==`collection`&&e!==`table`?!1:te(t)}function wt(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function Tt(e,t,n,r){return!n.summarizeTextSurfaces||!r.shouldSummarize?w(e,t):Dt(e,t,r.text)||w(e,t)}function Et(e,t,n,r){let i=[];return e.enabled===!1&&i.push(`disabled`),i.push(...e.presentationHints??[]),!n.summarizeTextSurfaces||(e.selected===!0&&i.push(`selected`),e.focused===!0&&i.push(`focused`),St(t)&&i.push(`editable`),Ot(e,t)&&i.push(`scrollable`),!r.shouldSummarize)?At(i):(i.push(`preview:"${kt(m(r.text))}"`),i.push(`truncated`),At(i))}function Dt(e,t,n){let r=ee(e.label);if(r&&r!==n)return r;let i=ee(e.identifier);if(i&&!wt(i)&&i!==n)return i;switch(t){case`text`:case`text-view`:return`Text view`;case`text-field`:return`Text field`;case`search`:return`Search field`;default:return``}}function Ot(e,t){if(t===`scroll-area`)return!0;let n=(e.type??``).toLowerCase(),r=`${e.role??``} ${e.subrole??``}`.toLowerCase();return n.includes(`scroll`)||r.includes(`scroll`)}function kt(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function At(e){return[...new Set(e)]}function jt(e){process.stdout.write(`${JSON.stringify(e,null,2)}\n`)}function Mt(e,r={}){let i=e instanceof n?t(e):e;process.stderr.write(`Error (${i.code}): ${i.message}\n`),i.hint&&process.stderr.write(`Hint: ${i.hint}\n`),i.diagnosticId&&process.stderr.write(`Diagnostic ID: ${i.diagnosticId}\n`),i.logPath&&process.stderr.write(`Diagnostics Log: ${i.logPath}\n`),r.showDetails&&i.details&&process.stderr.write(`${JSON.stringify(i.details,null,2)}\n`)}function Nt(t,n={}){let r=t.nodes,a=Array.isArray(r)?r:[],o=i(e(t.backend)?t.backend:void 0),s=st(t,a,n),c=Lt(t),l=dn(t,a,n,s),u=l.length>0?`${l.join(`
|
|
2
|
-
`)}\n`:``,d=
|
|
1
|
+
import{S as e,_ as t,d as n,f as r,g as i,p as a,u as o}from"./sdk-contracts.js";import{C as s,S as c,b as l,p as u,w as d,x as f,y as p}from"./sdk-batch.js";import{A as m,C as h,D as g,F as ee,L as te,M as ne,N as _,O as re,S as ie,T as ae,b as oe,j as se,k as ce,m as le,p as ue,w as de,x as fe,y as pe,z as me}from"./sdk-selectors.js";import{b as v}from"./sdk-batch-runner.js";import{n as he,t as ge}from"./snapshot-quality.js";import{a as _e,i as ve,n as ye,o as be,t as xe}from"./selectors2.js";import{createHash as Se}from"node:crypto";import Ce from"node:path";import{styleText as we}from"node:util";const Te=Ne(`public`),Ee=Ne(`internal`),De=Ne(`local-cli`),Oe={help:`help`},ke=[`pan`,`fling`,`swipe`,`pinch`,`rotate`,`transform`],Ae=`gesture requires one of: ${ke.join(`, `)}`;function je(){return[...Object.values(Te),...Object.values(De)].sort()}function Me(e){return Object.values(Oe).includes(e)||Object.values(Ee).includes(e)?!0:je().includes(e)}function Ne(e){let t={};for(let[n,r]of u(e))t[n]=r;return t}function y(e){return e.width>0&&e.height>0}function Pe(e,t){return!e||!t?!1:e.x>=t.x-2&&e.y>=t.y-2&&e.x+e.width<=t.x+t.width+2&&e.y+e.height<=t.y+t.height+2}function Fe(e,t){if(!e||!t)return!0;let n=e.y+e.height/2,r=t.y+t.height/2;return Math.abs(n-r)<=Math.max(e.height,t.height,1)}function Ie(e){return typeof e.parentIndex!=`number`}function b(e){let t=(e.type??``).toLowerCase(),n=(e.identifier??``).trim().toLowerCase();return t.includes(`edittext`)||t.includes(`textfield`)||n===`composer`}function Le(e){let t=(e.type??``).toLowerCase();return t.includes(`scroll`)||t.includes(`list`)||t.includes(`recyclerview`)}function x(e){let t=me(e);if(!t||t!==e.identifier?.trim()||!Re(t))return t;let n=(e.type??``).toLowerCase();return n.includes(`view`)||n.includes(`layout`)||n.includes(`image`)||n.includes(`list`)||n.includes(`recyclerview`)||n.includes(`collection`)?``:t}function S(e){let t=e.trim().replace(/\s+/g,` `).toLowerCase();return!t||/^(true|false|\d+)$/.test(t)?null:t}function Re(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function ze(e,t,n){let r=e;for(;typeof r.parentIndex==`number`;){let e=t.get(r.parentIndex);if(!e)return null;if(n(e))return e;r=e}return null}function Be(e,t){let n=[],r=[t];for(;r.length>0;){let t=r.pop();for(let i of e)i.parentIndex===t&&(n.push(i),r.push(i.index))}return n}function C(e,t,n){let r=[t];for(;r.length>0;){let t=r.pop();if(!n.has(t)){n.add(t);for(let i of e)i.parentIndex!==t||n.has(i.index)||r.push(i.index)}}}const Ve=[`button`,`switch`,`checkbox`,`radio`],He=[`button`,`image`,`textview`,`view`];function Ue(e,t,n){for(let r of e){if(t.has(r.index)||!Ke(r))continue;let i=qe(Be(e,r.index),r,t);if(i.label){n.set(r.index,{...r,...n.get(r.index),label:i.label});for(let n of i.removableIndexes)C(e,n,t)}}}function We(e,t,n){let r=new Map;for(let i of e){if(t.has(i.index)||!et(i))continue;let a=S(x(i));if(!a)continue;let o=r.get(a);if(o&&Ze(o,i,t)){let s=Qe(e,o,i,t,n);r.set(a,s);continue}r.set(a,i)}}function Ge(e,t){for(let n of e){if(t.has(n.index)||!Ye(n))continue;let r=S(x(n));if(!r)continue;let i=Be(e,n.index).filter(e=>!t.has(e.index)&&Xe(n,e,r));for(let n of i.filter(Je))C(e,n.index,t);let a=i.filter(e=>!Je(e)),o=new Set(a.map(e=>S(x(e))).filter(e=>!!e));if(!(a.length<2||o.size<2))for(let n of a)C(e,n.index,t)}}function Ke(e){return e.hittable===!0&&!b(e)&&!!(e.rect&&y(e.rect))&&x(e).trim().length===0}function qe(e,t,n){let r=[],i=[],a=new Set;for(let o of e){if(n.has(o.index)||!Je(o)||!Pe(o.rect,t.rect))continue;let e=x(o).trim().replace(/\s+/g,` `),s=S(e);i.push(o.index),!(!e||!s||a.has(s))&&(a.add(s),r.push(e))}return{label:r.join(`, `),removableIndexes:i}}function Je(e){if(e.hittable===!0||b(e))return!1;let t=(e.type??``).toLowerCase();return t.includes(`text`)||t.includes(`image`)||t.includes(`icon`)}function Ye(e){return e.hittable===!0&&!b(e)&&!!(e.rect&&y(e.rect))&&!!S(x(e))}function Xe(e,t,n){if(!et(t)||!Pe(t.rect,e.rect))return!1;let r=S(x(t));return!!(r&&n!==r&&n.includes(r))}function Ze(e,t,n){return!n.has(e.index)&&Fe(e.rect,t.rect)&&(at(e,t)||it(e,t))}function Qe(e,t,n,r,i){let a=tt(t,n),o=a.index===t.index?n:t,s=(o.type??``).toLowerCase().includes(`image`)?`has image`:null,c=i.get(a.index)??a,l=i.get(o.index)?.presentationHints??o.presentationHints;return i.set(a.index,{...c,presentationHints:$e(c.presentationHints,l,s)}),C(e,o.index,r),i.get(a.index)??a}function $e(e,t,n){return[...new Set([...Array.isArray(e)?e:[],...Array.isArray(t)?t:[],...n?[n]:[]])]}function et(e){if(!e.rect||!y(e.rect)||Ie(e)||b(e))return!1;let t=(e.type??``).toLowerCase();return t===`text`||rt(t,He)}function tt(e,t){let n=nt(e);return nt(t)>n?t:e}function nt(e){let t=(e.type??``).toLowerCase(),n=0;return rt(t,Ve)?n+=100:t.includes(`image`)?n+=30:t.includes(`textview`)||t===`text`?n+=20:t.includes(`view`)&&(n+=10),e.hittable===!0&&(n+=20),e.enabled!==!1&&(n+=5),n}function rt(e,t){return t.some(t=>e.includes(t))}function it(e,t){let n=e.parentIndex===t.index?t:t.parentIndex===e.index?e:null,r=n?.index===e.index?t:n?.index===t.index?e:null;return!n||!r?!1:tt(n,r).index===n.index}function at(e,t){return e.parentIndex===t.parentIndex?Math.abs(e.index-t.index)<=3:e.parentIndex===t.index||t.parentIndex===e.index?!1:Math.abs((e.depth??0)-(t.depth??0))<=1&&Math.abs(e.index-t.index)<=2}function ot(e,t,n){if(n.raw||!st(e))return{nodes:t,filteredCount:0};let r=ct(t);return{nodes:r,filteredCount:t.length-r.length}}function st(e){let t=e.androidSnapshot;return!t||typeof t!=`object`?!1:t.backend===`android-helper`}function ct(e){if(e.length===0)return e;let t=new Set,n=new Map,r=new Map(e.map(e=>[e.index,e]));return lt(e,t),ut(e,r,t,n),Ue(e,t,n),Ge(e,t),We(e,t,n),e.filter(e=>!t.has(e.index)).map(e=>n.get(e.index)??e)}function lt(e,t){for(let n of e)!n.rect||y(n.rect)||Ie(n)||C(e,n.index,t)}function ut(e,t,n,r){for(let i of e){if(n.has(i.index)||i.rect||Ie(i))continue;let a=ze(i,t,Le);a&&ft(r,a,dt(i,e)),C(e,i.index,n)}}function dt(e,t){let n=t.filter(t=>t.parentIndex===e.parentIndex&&t.rect&&y(t.rect)).map(e=>e.index);return n.length===0?null:e.index<Math.min(...n)?`above`:e.index>Math.max(...n)?`below`:null}function ft(e,t,n){if(!n)return;let r=e.get(t.index)??t;e.set(t.index,{...r,hiddenContentAbove:r.hiddenContentAbove===!0||n===`above`?!0:void 0,hiddenContentBelow:r.hiddenContentBelow===!0||n===`below`?!0:void 0})}function pt(e){let t=e.trim().replace(/\s+/g,` `).toLowerCase();return!t||mt(t)?null:t}function mt(e){return/\S+@\S+\.\S+/.test(e)}function ht(e){if(e.length<20)return!1;let t=new Map;for(let n of e){let e=(n.type??``).toLowerCase(),r=pt(me(n));if(!r)continue;let i=`${e}|${r}`,a=t.get(i)??[];a.push(n),t.set(i,a)}let n=0;for(let e of t.values())e.length<=1||!gt(e)||(n+=e.length);return n>=8}function gt(e){for(let t=0;t<e.length;t+=1)for(let n=t+1;n<e.length;n+=1)if(_t(e[t]?.rect,e[n]?.rect))return!0;return!1}function _t(e,t){if(!e||!t)return!0;let n=.5;return!(e.x+e.width<=t.x+n||t.x+t.width<=e.x+n||e.y+e.height<=t.y+n||t.y+t.height<=e.y+n)}const vt={application:`application`,navigationbar:`navigation-bar`,tabbar:`tab-bar`,button:`button`,imagebutton:`button`,link:`link`,cell:`cell`,statictext:`text`,checkedtextview:`text`,textbox:`text-field`,textfield:`text-field`,edittext:`text-field`,textarea:`text-view`,switch:`switch`,slider:`slider`,image:`image`,imageview:`image`,webview:`webview`,framelayout:`group`,linearlayout:`group`,relativelayout:`group`,constraintlayout:`group`,viewgroup:`group`,view:`group`,listview:`list`,recyclerview:`list`,collectionview:`collection`,searchfield:`search`,segmentedcontrol:`segmented-control`,group:`group`,window:`window`,checkbox:`checkbox`,radio:`radio`,menuitem:`menu-item`,toolbar:`toolbar`,scrollarea:`scroll-area`,scrollview:`scroll-area`,nestedscrollview:`scroll-area`,table:`table`};function w(e,t={}){let n=[],r=[];for(let i of e){let e=i.depth??0,a=i.label?.trim()||i.value?.trim()||i.identifier?.trim()||``,o=E(i.type??`Element`),s=i.inheritsLabel===!0||i.inheritsIdentifier===!0;if(o===`group`&&!a&&!s)continue;for(;n.length>0&&e<=n[n.length-1];)n.pop();let c=n.length;n.push(e),r.push({node:i,depth:c,type:o,text:yt(i,c,!1,o,t)})}return r}function yt(e,t,n,r,i={}){let a=r??E(e.type??`Element`),o=se(e,a),s=wt(e,a,i,o),c=` `.repeat(t),l=e.ref?`@${e.ref}`:``,u=Tt(e,a,i,o);!s&&(e.inheritsLabel===!0||e.inheritsIdentifier===!0)&&u.push(`same label as parent`);let d=u.map(e=>` [${e}]`).join(``),f=s?` "${s}"`:``;return n?`${c}${l} [${a}]${d}`.trimEnd():`${c}${l} [${a}]${f}${d}`.trimEnd()}function T(e,t){let n=e.label?.trim();if(n&&St(t,n))return``;let r=e.value?.trim();if(xt(t)){if(r)return r;if(n)return n}else if(n)return n;if(r)return r;let i=e.identifier?.trim();return!i||Ct(i)&&(t===`group`||t===`image`||t===`list`||t===`collection`)?``:i}function E(e){let t=e,n=e.replace(/XCUIElementType/gi,``).toLowerCase(),r=t.includes(`.`)&&(t.startsWith(`android.`)||t.startsWith(`androidx.`)||t.startsWith(`com.`));return n.includes(`.`)&&(n=n.replace(/^android\.widget\./,``).replace(/^android\.view\./,``).replace(/^android\.webkit\./,``).replace(/^androidx\./,``).replace(/^com\.google\.android\./,``).replace(/^com\.android\./,``),r&&n.includes(`.`)&&(n=n.slice(n.lastIndexOf(`.`)+1))),n===`textview`?r?`text`:`text-view`:bt(n)||n||`element`}function bt(e){return Object.prototype.hasOwnProperty.call(vt,e)?vt[e]:void 0}function xt(e){return e===`text-field`||e===`text-view`||e===`search`}function St(e,t){return e!==`scroll-area`&&e!==`list`&&e!==`collection`&&e!==`table`?!1:te(t)}function Ct(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function wt(e,t,n,r){return!n.summarizeTextSurfaces||!r.shouldSummarize?T(e,t):Et(e,t,r.text)||T(e,t)}function Tt(e,t,n,r){let i=[];return e.enabled===!1&&i.push(`disabled`),i.push(...e.presentationHints??[]),!n.summarizeTextSurfaces||(e.selected===!0&&i.push(`selected`),e.focused===!0&&i.push(`focused`),xt(t)&&i.push(`editable`),Dt(e,t)&&i.push(`scrollable`),!r.shouldSummarize)?kt(i):(i.push(`preview:"${Ot(m(r.text))}"`),i.push(`truncated`),kt(i))}function Et(e,t,n){let r=ee(e.label);if(r&&r!==n)return r;let i=ee(e.identifier);if(i&&!Ct(i)&&i!==n)return i;switch(t){case`text`:case`text-view`:return`Text view`;case`text-field`:return`Text field`;case`search`:return`Search field`;default:return``}}function Dt(e,t){if(t===`scroll-area`)return!0;let n=(e.type??``).toLowerCase(),r=`${e.role??``} ${e.subrole??``}`.toLowerCase();return n.includes(`scroll`)||r.includes(`scroll`)}function Ot(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function kt(e){return[...new Set(e)]}function At(e){process.stdout.write(`${JSON.stringify(e,null,2)}\n`)}function jt(n,r={}){let i=n instanceof t?e(n):n;process.stderr.write(`Error (${i.code}): ${i.message}\n`),i.hint&&process.stderr.write(`Hint: ${i.hint}\n`),i.diagnosticId&&process.stderr.write(`Diagnostic ID: ${i.diagnosticId}\n`),i.logPath&&process.stderr.write(`Diagnostics Log: ${i.logPath}\n`),r.showDetails&&i.details&&process.stderr.write(`${JSON.stringify(i.details,null,2)}\n`)}function Mt(e,t={}){let n=e.nodes,a=Array.isArray(n)?n:[],o=i(r(e.backend)?e.backend:void 0),s=ot(e,a,t),c=It(e),l=un(e,a,t,s),u=l.length>0?`${l.join(`
|
|
2
|
+
`)}\n`:``,d=t.raw?null:Nt(e);if(d)return`${c}${u}${Pt(d)}\n`;let f=t.raw||!o?null:oe(s.nodes),p=!!e.truncated,m=f?.nodes??a,h=t.raw||!o?null:Ht(e,f,m.length,a.length,s.filteredCount),g=Lt(a.length,h,p);return a.length===0?`${c}${g}\n${u}`:t.raw?`${c}${g}\n${u}${Rt(a)}\n`:t.flatten?`${c}${g}\n${u}${zt(m)}${Vt(f)}\n`:`${c}${g}\n${u}${Bt(m)}${Vt(f)}\n`}function Nt(e){let t=e.unchanged;if(!t||typeof t!=`object`)return null;let n=t;return typeof n.ageMs!=`number`||typeof n.nodeCount!=`number`?null:{ageMs:n.ageMs,nodeCount:n.nodeCount,interactiveOnly:n.interactiveOnly===!0?!0:void 0,scope:typeof n.scope==`string`?n.scope:void 0}}function Pt(e){let t=Ft(e.ageMs);return e.scope?[`Scoped snapshot unchanged for scope "${e.scope}" since previous read ${t} ago.`,`Previous refs in this scope remain valid. Use find/get/is for a targeted query, or --force-full to re-emit.`].join(`
|
|
3
3
|
`):e.interactiveOnly?[`Interactive snapshot unchanged since previous read ${t} ago.`,`${e.nodeCount} visible nodes are unchanged. Previous @e refs are still valid. Use find/get/is for a targeted query, or --force-full to re-emit.`].join(`
|
|
4
4
|
`):[`Snapshot unchanged since previous read ${t} ago.`,`Refs from the previous snapshot are still valid. Use --force-full to re-emit the tree, or use find/get/is for a targeted query.`].join(`
|
|
5
|
-
`)}function
|
|
6
|
-
`)}\n`:``}function
|
|
7
|
-
`)}function
|
|
8
|
-
`)}function
|
|
9
|
-
`)}function
|
|
10
|
-
`)}`:``}function
|
|
11
|
-
`)}\n`:``;if(t)return`${c}Baseline initialized (${a} lines).\n`;let l=
|
|
12
|
-
`)}\n`:``;return o?`${c}${u}${[`${
|
|
13
|
-
`)}\n`}function Jt(e,t){if(e.match===!0)return[`${t?k(`✓`,`green`):`✓`} Screenshots match.`];let n=e.dimensionMismatch,r=t?k(`✗`,`red`):`✗`;if(n){let e=n.expected,t=n.actual;return[`${r} Screenshots have different dimensions: expected ${e?.width}x${e?.height}, got ${t?.width}x${t?.height}`]}let i=D(e.differentPixels),a=D(e.mismatchPercentage),o=`${a===0&&i>0?`<0.01`:String(a)}% pixels differ`;return[`${r} ${t?k(o,`red`):o}`]}function Yt(e,t,n){if(t)return[];let r=[];if(e.diffPath){let t=ln(e.diffPath),i=n?k(`Diff image:`,`dim`):`Diff image:`,a=n?k(t,`green`):t;r.push(` ${i} ${a}`)}if(e.currentOverlayPath){let t=ln(e.currentOverlayPath),i=n?k(`Current overlay:`,`dim`):`Current overlay:`,a=n?k(t,`green`):t,o=D(e.currentOverlayRefCount),s=o>0?` (${o} refs)`:``;r.push(` ${i} ${a}${s}`)}return r}function Xt(e,t){let n=D(e.differentPixels),r=D(e.totalPixels);return[` ${t?k(String(n),`red`):String(n)} different / ${r} total pixels`]}function Zt(e,t){let n=rn(e);return n.length===0?[]:[` ${A(`Hints:`,t)}`,...n.map(e=>` - ${e}`)]}function Qt(e,t){let n=Array.isArray(e.regions)?e.regions:[];if(n.length===0)return[];let r=[` ${A(`Changed regions:`,t)}`];for(let e of n.slice(0,5))r.push(...$t(e));return r}function $t(e){let t=e.shareOfDiffPercentage===0&&e.differentPixels>0?`<0.01`:String(e.shareOfDiffPercentage),n=e.rect,r=[` ${e.index}. ${e.location} x=${n.x} y=${n.y} ${n.width}x${n.height}, ${t}% of diff, change=${e.dominantChange}`],i=cn(e);i&&r.push(` ${i}`);let a=e.currentOverlayMatches?.[0];if(a){let e=a.label?` "${a.label}"`:``;r.push(` overlaps @${a.ref}${e}, ${a.regionCoveragePercentage}% of region`)}return r}function en(e,t){let n=e.ocr?.matches??[];if(n.length===0)return[];let r=n.slice(0,8),i=[` ${A(`OCR text deltas (${e.ocr?.provider}; baselineBlocks=${e.ocr?.baselineBlocks} currentBlocks=${e.ocr?.currentBlocks}; showing ${r.length}/${n.length}; px):`,t)}`,` ${A(`item | text | movePx | sizeDeltaPx | bboxBaseline | bboxCurrent | confidence | issueHint`,t)}`];for(let[e,t]of r.entries()){let n=t.delta;i.push(` ${e+1} | ${JSON.stringify(t.text)} | ${E(n.x)},${E(n.y)} | ${E(n.width)},${E(n.height)} | ${nn(t.baselineRect)} | ${nn(t.currentRect)} | ${t.confidence} | ${t.possibleTextMetricMismatch?`ocr-bbox-size-change`:`-`}`)}return i}function tn(e,t){let n=e.nonTextDeltas??[];if(n.length===0)return[];let r=n.slice(0,8),i=[` ${A(`Non-text visual deltas (showing ${r.length}/${n.length}; px):`,t)}`,` ${A(`item | region | slot | kind | bboxCurrent | nearestText`,t)}`];for(let e of r)i.push(` ${e.index} | ${e.regionIndex?`r${e.regionIndex}`:`-`} | ${e.slot} | ${e.likelyKind} | ${nn(e.rect)} | ${e.nearestText?JSON.stringify(e.nearestText):`-`}`);return i}function nn(e){return`x=${e.x},y=${e.y},w=${e.width},h=${e.height}`}function E(e){return e>0?`+${e}`:String(e)}function rn(e){let t=[],n=e.ocr?.movementClusters??[];for(let e of n.slice(0,2))t.push(`text movement cluster: ${sn(e.texts)} dx=${on(e.xRange)}px dy=${on(e.yRange)}px`);let r=(e.nonTextDeltas??[]).filter(e=>[`icon`,`toggle`,`chevron`].includes(e.likelyKind)).slice(0,3);r.length>0&&t.push(`non-text controls: ${r.map(an).join(`; `)}`);let i=(e.nonTextDeltas??[]).filter(e=>e.likelyKind===`separator`).slice(0,2);return i.length>0&&t.push(`non-text boundaries: ${i.map(an).join(`; `)}`),t.slice(0,6)}function an(e){let t=e.nearestText?` near ${JSON.stringify(e.nearestText)}`:``,n=e.regionIndex?` r${e.regionIndex}`:``;return`${e.likelyKind}${t}${n}`}function on(e){return e.min===e.max?E(e.min):`${E(e.min)}..${E(e.max)}`}function sn(e){let t=e.slice(0,4).map(e=>JSON.stringify(e)),n=e.length>t.length?` +${e.length-t.length} more`:``;return`${t.join(`, `)}${n}`}function cn(e){let t=[e.size?`size=${e.size}`:null,e.shape?`shape=${e.shape}`:null,typeof e.densityPercentage==`number`?`density=${e.densityPercentage}%`:null,e.averageBaselineColorHex&&e.averageCurrentColorHex?`avgColor=${e.averageBaselineColorHex}->${e.averageCurrentColorHex}`:null,typeof e.baselineLuminance==`number`&&typeof e.currentLuminance==`number`?`luminance=${e.baselineLuminance}->${e.currentLuminance}`:null].filter(e=>e!==null);return t.length>0?t.join(` `):null}function ln(e){let t=process.cwd(),n=we.relative(t,e);return n===``||!n.startsWith(`..`)&&!we.isAbsolute(n)?n===``?`.`:`.${we.sep}${n}`:e}function D(e){return typeof e==`number`&&Number.isFinite(e)?e:0}function un(e,t){if(e.length===0)return e;let n=e.map((e,t)=>({index:t,kind:e.kind})).filter(e=>e.kind===`added`||e.kind===`removed`).map(e=>e.index);if(n.length===0)return e;let r=Array(e.length).fill(!1);for(let i of n){let n=Math.max(0,i-t),a=Math.min(e.length-1,i+t);for(let e=n;e<=a;e+=1)r[e]=!0}return e.filter((e,t)=>r[t])}function O(e=process.stdout){let t=process.env.FORCE_COLOR;return typeof t==`string`?t!==`0`:typeof process.env.NO_COLOR==`string`?!1:!!e.isTTY}function k(e,t,n){return Te(t,e,n)}function A(e,t){return t?k(e,`dim`):e}function dn(e,t,n,r={nodes:t,filteredCount:0}){let i=hn(e);if(fn(e)){let e=mn(t,n);e&&i.push(e)}!n.raw&&r.filteredCount>0&&i.push(`Collapsed ${r.filteredCount} Android helper node${r.filteredCount===1?``:`s`} from the agent-facing text snapshot; use --raw or --json for the full hierarchy.`);let a=r.filteredCount>0?r.nodes:t;return!n.raw&>(a)&&i.push(`Warning: possible repeated nav subtree detected.`),i}function fn(e){return!e.snapshotQuality&&!pn(e)}function pn(e){let t=e.snapshotDiagnostics;if(!t||typeof t!=`object`)return!1;let n=t.stats;return!!(n&&typeof n==`object`&&n.platform===`web`)}function mn(e,t){if(t.scoped===!0||t.depthLimited===!0||e.length>3)return null;let n=e.length===1?`node`:`nodes`;return`Hint: sparse accessibility snapshot returned ${e.length} ${n}; snapshot state is invalid or unavailable for this screen. Use plain screenshot, not screenshot --overlay-refs, as visual truth. If screenshot shows the Home Screen or another app, run open for this app again first. Then navigate away with coordinates if needed and retry snapshot -i on the next screen.`}function hn(e){let t=e.warnings;return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.length>0):[]}function gn(e){let t=[],n=[],r=new Map(e.map(e=>[e.node.index,e.node])),i=e=>{for(;n.length>0&&(!e||_n(e,n[n.length-1],r));)t.push(...bn(n.pop(),`below`))};for(let r of e)i(r),t.push(r.text),t.push(...bn(r,`above`)),r.node.hiddenContentBelow&&n.push(r);return i(),t}function _n(e,t,n){return vn(e.node,t.node,n)?!1:e.depth<=t.depth}function vn(e,t,n){let r=e;for(;typeof r.parentIndex==`number`;){if(r.parentIndex===t.index)return!0;let e=n.get(r.parentIndex);if(!e)return!1;r=e}return!1}function yn(e){return C(e,{summarizeTextSurfaces:!0}).flatMap(e=>[bt(e.node,0,!1,e.type,{summarizeTextSurfaces:!0}),...bn({...e,depth:0})])}function bn(e,t){let n=xn(e.type);if(!n)return[];let r=[];if(e.node.hiddenContentAbove&&t!==`below`&&r.push(`[content above ${n} hidden]`),e.node.hiddenContentBelow&&t!==`above`&&r.push(`[content below ${n} hidden]`),r.length===0)return[];let i=` `.repeat(e.depth+1);return r.map(e=>`${i}${e}`)}function xn(e){return e===`scroll-area`||e===`list`||e===`collection`||e===`table`?e:null}function Sn(e,t={}){let n=O(process.stderr);if(e===`pass`){let e=t.passFormat??`green`;return n?j(`✓`,e):`✓`}return e===`fail`?n?j(`⨯`,`red`):`⨯`:e===`warn`?n?j(`!`,`yellow`):`!`:n?j(`-`,`dim`):`-`}function j(e,t){return k(e,t,{validateStream:!1})}function Cn(e){return`${Sn(Tn(e.status))} ${En(e)}`}function wn(e){return e.status!==`fail`&&e.status!==`warn`?[]:typeof e.command==`string`?[` run: ${e.command}`]:typeof e.hint==`string`?[` hint: ${e.hint}`]:[]}function Tn(e){return e===`pass`?`pass`:e===`fail`?`fail`:e===`warn`?`warn`:`skip`}function En(e){let t=typeof e.id==`string`&&e.id.length>0?e.id:`check`,n=typeof e.summary==`string`&&e.summary.length>0?e.summary:t;return n===t?t:`${t}: ${n}`}const Dn=3e5,On=[`leaseId`,`tenantId`,`runId`,`clientId`,`deviceKey`];function kn(e){return _({tenantId:e.meta?.tenantId??M(e.flags,`tenant`),runId:e.meta?.runId??M(e.flags,`runId`),leaseId:e.meta?.leaseId??M(e.flags,`leaseId`),leaseTtlMs:e.meta?.leaseTtlMs,leaseBackend:e.meta?.leaseBackend,leaseProvider:e.meta?.leaseProvider??M(e.flags,`leaseProvider`)??M(e.flags,`provider`),deviceKey:e.meta?.deviceKey??M(e.flags,`deviceKey`),clientId:e.meta?.clientId??M(e.flags,`clientId`)})}function An(e){return _({tenantId:e.tenant,runId:e.runId,leaseId:e.leaseId,leaseTtlMs:e.leaseTtlMs??e.ttlMs,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider??e.provider,deviceKey:e.deviceKey,clientId:e.clientId})}function jn(e){return _({tenantId:e.tenantId,runId:e.runId,leaseId:e.leaseId,leaseTtlMs:e.leaseTtlMs,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId})}function Mn(e){return _({tenant:e.tenantId,runId:e.runId,leaseId:e.leaseId,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId})}function Nn(e){return _({tenantId:e.tenantId??``,runId:e.runId??``,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId,ttlMs:e.leaseTtlMs})}function Pn(e){return Bn(e)}function Fn(e){let{ttlMs:t,...n}=Bn(e);return n}function In(e,t,n){let r=_({...n.includeTokenParam?{token:n.token}:{},session:n.session,tenantId:e.tenantId,runId:e.runId,leaseProvider:e.leaseProvider,clientId:e.clientId,deviceKey:e.deviceKey});switch(t){case`lease_allocate`:return{...r,..._({ttlMs:e.leaseTtlMs,backend:e.leaseBackend})};case`lease_heartbeat`:return{...r,..._({leaseId:e.leaseId,ttlMs:e.leaseTtlMs})};case`lease_release`:return{...r,..._({leaseId:e.leaseId})}}}function Ln(e){let t=_({leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId});return Object.keys(t).length>0?t:void 0}function Rn(e){return e.leaseProvider===`proxy`}function zn(e){return Rn(e)?On.filter(t=>!e[t]):[]}function Bn(e){return _({leaseId:e.leaseId??``,tenantId:e.tenantId,runId:e.runId,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId,ttlMs:e.leaseTtlMs})}function M(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function N(e){return e?{message:e}:{}}function P(e,t){return t?{...e,message:t}:e}function Vn(e){return typeof e?.message==`string`&&e.message.length>0?e.message:null}const Hn=[`out`,`overlayRefs`,`screenshotPixelDensity`,`screenshotFullscreen`,`screenshotMaxSize`,`screenshotNoStabilize`,`screenshotNormalizeStatusBar`],Un=[`screenshotPixelDensity`,`screenshotFullscreen`,`screenshotMaxSize`,`screenshotNoStabilize`,`screenshotNormalizeStatusBar`],Wn=[{key:`screenshotPixelDensity`,names:[`--pixel-density`],type:`int`,min:1,usageLabel:`--pixel-density <n>`,usageDescription:`Screenshot: output PNG pixel density in pixels per logical point (currently supported on iOS simulators)`},{key:`screenshotFullscreen`,names:[`--fullscreen`,`--full`,`-f`],type:`boolean`,usageLabel:`--fullscreen, --full, -f`,usageDescription:`Screenshot: on web capture the full page; on macOS app sessions capture the full desktop instead of the app window`},{key:`screenshotMaxSize`,names:[`--max-size`],type:`int`,min:1,usageLabel:`--max-size <px>`,usageDescription:`Screenshot/record: downscale so the longest edge is at most <px>`},{key:`screenshotNoStabilize`,names:[`--no-stabilize`],type:`boolean`,usageLabel:`--no-stabilize`,usageDescription:`Screenshot: skip Android demo-mode/status-bar stabilization and settle delay for low-latency capture loops`},{key:`screenshotNormalizeStatusBar`,names:[`--normalize-status-bar`],type:`boolean`,usageLabel:`--normalize-status-bar`,usageDescription:`Screenshot: on iOS simulators temporarily normalize status-bar chrome for deterministic screenshot diffs`}],Gn=[{tokens:[`--fullscreen`,`--full`,`-f`],key:`screenshotFullscreen`},{tokens:[`--no-stabilize`],key:`screenshotNoStabilize`},{tokens:[`--normalize-status-bar`],key:`screenshotNormalizeStatusBar`}],Kn=[{token:`--pixel-density`,key:`screenshotPixelDensity`,label:`screenshot --pixel-density`},{token:`--max-size`,key:`screenshotMaxSize`,label:`screenshot --max-size`}];function qn(e){return Zn({overlayRefs:e?.overlayRefs,pixelDensity:e?.screenshotPixelDensity,fullscreen:e?.screenshotFullscreen,maxSize:e?.screenshotMaxSize,stabilize:e?.screenshotNoStabilize?!1:void 0,normalizeStatusBar:e?.screenshotNormalizeStatusBar})}function Jn(e={}){return Zn({overlayRefs:e.overlayRefs,screenshotPixelDensity:e.screenshotPixelDensity??e.pixelDensity,screenshotFullscreen:e.screenshotFullscreen??e.fullscreen,screenshotMaxSize:e.screenshotMaxSize??e.maxSize,screenshotNoStabilize:e.screenshotNoStabilize??(e.stabilize===!1?!0:void 0),screenshotNormalizeStatusBar:e.screenshotNormalizeStatusBar??e.normalizeStatusBar})}function Yn(e,t){typeof t?.screenshotPixelDensity==`number`&&e.push(`--pixel-density`,String(t.screenshotPixelDensity)),t?.screenshotFullscreen&&e.push(`--fullscreen`),typeof t?.screenshotMaxSize==`number`&&e.push(`--max-size`,String(t.screenshotMaxSize)),t?.screenshotNoStabilize&&e.push(`--no-stabilize`),t?.screenshotNormalizeStatusBar&&e.push(`--normalize-status-bar`)}function Xn(e){let{args:t,flags:n,index:r}=e,i=t[r];return Qn(i,n,r)??$n({args:t,index:r,flags:n,token:i})??{handled:!1}}function Zn(e){return Object.fromEntries(Object.entries(e).filter(e=>e[1]!==void 0))}function Qn(e,t,n){let r=Gn.find(t=>t.tokens.some(t=>t===e));if(r)return t[r.key]=!0,{handled:!0,nextIndex:n}}function $n(e){let t=Kn.find(t=>t.token===e.token);if(!t)return;let r=e.args[e.index+1],i=r===void 0?NaN:Number(r);if(!Number.isInteger(i)||i<1)throw new n(`INVALID_ARGS`,`${t.label} requires a positive integer`);return e.flags[t.key]=i,{handled:!0,nextIndex:e.index+1}}function er(e){let t=ge(e.quality);return{...e.analysis?{analysis:e.analysis}:{},...e.androidSnapshot?{androidSnapshot:e.androidSnapshot}:{},...e.freshness?{freshness:e.freshness}:{},...t?{quality:t}:{},...e.warnings?{warnings:e.warnings}:{}}}function tr(e){return{...e.androidSnapshot?{androidSnapshot:e.androidSnapshot}:{},...e.quality?{snapshotQuality:e.quality}:{},...e.warnings&&e.warnings.length>0?{warnings:e.warnings}:{}}}function nr(e){let t=rr(e.androidSnapshot),n=Array.isArray(e.warnings)?e.warnings.filter(e=>typeof e==`string`):void 0,r=ge(e.snapshotQuality);return tr({...t?{androidSnapshot:t}:{},...r?{quality:r}:{},...n?{warnings:n}:{}})}function rr(e){return typeof e==`object`&&e?e:void 0}function ir(e){let t=e.appId??e.bundleId??e.packageName;return{session:e.session,appId:t,appBundleId:e.bundleId,package:e.packageName}}function ar(e,t,n){return{deviceId:t,deviceName:n,...e===`android`?{serial:t}:e===`ios`?{udid:t}:{}}}function or(e,t={}){let n=t.includeAndroidSerial??!0;return{platform:e.platform,target:e.target,device:e.name,id:e.id,...e.platform===`ios`?{device_udid:e.ios?.udid??e.id,ios_simulator_device_set:e.ios?.simulatorSetPath??null}:{},...e.platform===`android`&&n?{serial:e.android?.serial??e.id}:{}}}function sr(e){return{name:e.name,...e.sessionStateDir?{sessionStateDir:e.sessionStateDir}:{},...e.runnerLogPath?{runnerLogPath:e.runnerLogPath}:{},...or(e.device,{includeAndroidSerial:!1}),createdAt:e.createdAt}}function cr(e){return{platform:e.platform,...e.appleOs?{appleOs:e.appleOs}:{},id:e.id,name:e.name,kind:e.kind,target:e.target,...typeof e.booted==`boolean`?{booted:e.booted}:{}}}function lr(e){return e.bundleId??e.package??e.app}function ur(e){return P({app:e.app,appPath:e.appPath,platform:e.platform,...e.appId?{appId:e.appId}:{},...e.bundleId?{bundleId:e.bundleId}:{},...e.package?{package:e.package}:{}},`Installed: ${lr(e)}`)}function dr(e){return e.appName??e.bundleId??e.packageName??e.launchTarget}function fr(e){return P({launchTarget:e.launchTarget,...e.appName?{appName:e.appName}:{},...e.appId?{appId:e.appId}:{},...e.bundleId?{bundleId:e.bundleId}:{},...e.packageName?{package:e.packageName}:{},...e.installablePath?{installablePath:e.installablePath}:{},...e.archivePath?{archivePath:e.archivePath}:{},...e.materializationId?{materializationId:e.materializationId}:{},...e.materializationExpiresAt?{materializationExpiresAt:e.materializationExpiresAt}:{}},`Installed: ${dr(e)}`)}function pr(e){let t=e.appName??e.appBundleId??e.session;return P({session:e.session,...e.sessionStateDir?{sessionStateDir:e.sessionStateDir}:{},...e.runnerLogPath?{runnerLogPath:e.runnerLogPath}:{},...e.requestLogPath?{requestLogPath:e.requestLogPath}:{},...e.eventLogPath?{eventLogPath:e.eventLogPath}:{},...e.appName?{appName:e.appName}:{},...e.appBundleId?{appBundleId:e.appBundleId}:{},...e.startup?{startup:e.startup}:{},...e.runtime?{runtime:e.runtime}:{},...e.device?or(e.device):{}},t?`Opened: ${t}`:`Opened`)}function mr(e){return{session:e.session,...e.shutdown?{shutdown:e.shutdown}:{},...`provider`in e&&e.provider?{provider:e.provider}:{},...N(e.session?`Closed: ${e.session}`:`Closed`)}}function hr(e){return{nodes:e.nodes,truncated:e.truncated,...e.appName?{appName:e.appName}:{},...e.appBundleId?{appBundleId:e.appBundleId}:{},...e.visibility?{visibility:e.visibility}:{},...tr(gr(e)),...e.unchanged?{unchanged:e.unchanged}:{},...e.snapshotDiagnostics?{snapshotDiagnostics:e.snapshotDiagnostics}:{}}}function gr(e){return{...e,...e.snapshotQuality?{quality:e.snapshotQuality}:{}}}function _r(e,t){return e.includes(t)}function vr(e,t,r={}){let i=t===void 0?void 0:r.normalize?.(t)??t;if(i!==void 0&&_r(e,i))return i;throw new n(`INVALID_ARGS`,(typeof r.message==`function`?r.message(t):r.message)??`Invalid value: ${t}. Use ${e.join(`|`)}.`)}function F(e,t={}){return{values:e,is:t=>_r(e,t),parse:n=>vr(e,n,t)}}const yr=[`app`,`frontmost-app`,`desktop`,`menubar`],br=F(yr,{normalize:e=>e.trim().toLowerCase(),message:e=>`Invalid surface: ${e}. Use ${yr.join(`|`)}.`});function xr(e){return br.parse(e)}const Sr=[`app`,`device`,`system`];function Cr(e){return e===`device`||e===`system`}const wr=[`metrics`,`frames`,`memory`,`cpu`,`trace`],Tr=[`sample`,`snapshot`,`start`,`stop`,`report`],Er=[`profile`],Dr=[`xctrace`,`simpleperf`,`perfetto`,`android-hprof`,`memgraph`],Or=[`android-hprof`,`memgraph`],kr=F(wr),Ar=F(Tr),jr=F(Er),Mr=F(Dr),Nr=F(Or),Pr=`perf area must be metrics, frames, memory, cpu, or trace`,Fr=`perf action must be sample, snapshot, start, stop, or report`,Ir=`perf cpu requires profile`,Lr=`perf --kind must be xctrace, simpleperf, perfetto, android-hprof, or memgraph`,Rr=`perf memory snapshot --kind must be android-hprof or memgraph`,zr=kr.is,Br=Ar.is,Vr=jr.is,Hr=Mr.is,Ur=Nr.is,Wr=[`app launch with Apple-platform launch arguments and Android/iOS simulator clearState`,`runFlow file/inline with when.platform, when.visible, when.notVisible, and limited when.true boolean/platform expressions`,`onFlowStart and onFlowComplete hooks`,`deterministic repeat.times`,`tapOn including optional, index, childOf, label, and absolute/percentage point taps`,`doubleTapOn and longPressOn`,`inputText, focused-field eraseText, and pasteText`,`openLink`,`visibility assertions and extendedWaitUntil`,`scroll and scrollUntilVisible`,`absolute/percentage swipe and swipe.label`,`screenshots`,`keyboard dismiss`,`basic pressKey, back, animation waits, and stopApp`,`ordered trusted runScript file/env scripts with http.post, json, and output variables`],Gr=`https://github.com/callstack/agent-device/issues/558`,Kr=`https://github.com/callstack/agent-device/issues/new`;function qr(){return`Supported subset: ${Jr(Wr)}.`}function Jr(e){return e.length>1?`${e.slice(0,-1).join(`, `)}, and ${e.at(-1)}`:e[0]??``}const Yr=1e4,Xr=2e3,Zr=[`get`,`accept`,`dismiss`,`wait`],Qr=`<wifi|airplane|location> <on|off>`,$r=`location set <lat> <lon>`,ei=`animations <on|off>`,ti=`appearance <light|dark|toggle>`,ni=`faceid <match|nonmatch|enroll|unenroll>`,ri=`touchid <match|nonmatch|enroll|unenroll>`,ii=`fingerprint <match|nonmatch>`,ai=`clear-app-state [app-id]`,oi=`permission <grant|deny|reset> <camera|microphone|photos|contacts|contacts-limited|notifications|calendar|location|location-always|media-library|motion|reminders|siri> [full|limited]`,si=`permission <grant|reset> <accessibility|screen-recording|input-monitoring>`,ci=`macOS supports only settings ${ti} and settings ${si}. wifi|airplane|location|animations remain unsupported on macOS.`,li=[`settings ${Qr}`,`settings ${$r}`,`settings ${ei}`,`settings ${ti}`,`settings ${ni}`,`settings ${ri}`,`settings ${ii}`,`settings ${ai}`,`settings ${oi}`,`settings ${si}`].join(` | `),ui=`settings requires ${Qr}, ${$r}, ${ei}, ${ti}, ${ni}, ${ri}, ${ii}, ${ai}, ${oi}, or ${si}`;function di(e){let t=e.trim().toLowerCase();return t===`appearance`||t===`permission`}function fi(e){return`Unsupported macOS setting: ${e}. ${ci}`}function pi(e,t){if(e===void 0||e.trim()===``)throw new n(`INVALID_ARGS`,`settings location set requires ${t}`);return hi(Number(e),t)}function mi(e){return{latitude:hi(e?.latitude,`latitude`),longitude:hi(e?.longitude,`longitude`)}}function hi(e,t){let r=t===`latitude`?-90:-180,i=t===`latitude`?90:180;if(typeof e!=`number`||!Number.isFinite(e)||e<r||e>i)throw new n(`INVALID_ARGS`,`${t} must be a number from ${r} to ${i}`);return e}const gi=[`primary`,`secondary`,`middle`];function _i(e){return e?.clickButton??`primary`}function vi(e){return e.button===`primary`?null:e.commandLabel===`click`?e.platform!==`macos`&&e.platform!==`linux`?new n(`UNSUPPORTED_OPERATION`,`click --button ${e.button} is supported only on macOS and Linux`):e.platform===`macos`&&e.button===`middle`?new n(`UNSUPPORTED_OPERATION`,`click --button middle is not supported by the macOS runner yet`):typeof e.count==`number`||typeof e.intervalMs==`number`||typeof e.holdMs==`number`||typeof e.jitterPx==`number`||e.doubleTap===!0?new n(`INVALID_ARGS`,`click --button ${e.button} does not support repeat or gesture modifier flags`):null:new n(`INVALID_ARGS`,`--button is supported only for click`)}function yi(e){return e===`primary`?{}:{button:e}}const bi=1e4;function xi(e,t=`scroll accepts either a relative amount or --pixels, not both`){if(e.amount!==void 0&&e.pixels!==void 0)throw new n(`INVALID_ARGS`,t)}function Si(e,t={}){if(e===void 0)return;let r=t.field??`scroll durationMs`,i=t.max??1e4,a=t.invalidMessage??`${r} must be a non-negative integer`;if(!Number.isFinite(e)||!Number.isInteger(e)||e<0)throw new n(`INVALID_ARGS`,a);if(e>i)throw new n(`INVALID_ARGS`,`${r} must be a non-negative integer at most ${i}`);return e}function Ci(e){return typeof e?.durationMs==`number`?e.durationMs:void 0}const wi=[`up`,`down`,`left`,`right`],Ti=[`left`,`right`,`left-edge`,`right-edge`],Ei=[`one-way`,`ping-pong`],Di=F(Ti,{message:`gesture swipe requires left, right, left-edge, or right-edge`}),Oi=F(wi,{message:e=>`Unknown direction: ${e}`});function ki(e){let t=e.direction,n=t===`up`||t===`down`?e.referenceHeight:e.referenceWidth,r=Hi(e.amount),i=e.pixels===void 0?Math.round(n*r):Ui(e.pixels),a=Math.max(1,Math.round(n*.05)),o=Math.max(1,n-a*2),s=Math.max(1,Math.min(i,o)),c=Math.round(s/2),l=Math.round(e.referenceWidth/2),u=Math.round(e.referenceHeight/2),d=(n,r,i,a)=>({direction:t,x1:n,y1:r,x2:i,y2:a,referenceWidth:e.referenceWidth,referenceHeight:e.referenceHeight,amount:e.amount,pixels:s});switch(t){case`up`:return d(l,u-c,l,u+c);case`down`:return d(l,u+c,l,u-c);case`left`:return d(l-c,u,l+c,u);case`right`:return d(l+c,u,l-c,u)}}function Ai(e){Hi(e.amount),e.pixels!==void 0&&Ui(e.pixels)}function ji(e){return{...ki({...e,direction:Ri(e.direction)}),direction:e.direction}}function Mi(e,t,n={}){let r=n.marginPx??8,[i,a,o]=e===`left`?[85,15,50]:e===`right`?[15,85,50]:e===`left-edge`?[99,15,50]:[1,85,50],s=Fi(t,i,o,{marginPx:r}),c=Fi(t,a,o,{marginPx:r});return{preset:e,x1:s.x,y1:s.y,x2:c.x,y2:c.y,referenceWidth:t.referenceWidth,referenceHeight:t.referenceHeight}}function Ni(e){return Di.parse(e)}function Pi(e){let t=zi(e);if(t)return{referenceWidth:t.width,referenceHeight:t.height}}function Fi(e,t,n,r={}){let i={x:Math.round(e.referenceWidth*t/100),y:Math.round(e.referenceHeight*n/100)};return r.marginPx===void 0?i:Ii(i,e,r.marginPx)}function Ii(e,t,n){return{x:Wi(e.x,n,t.referenceWidth),y:Wi(e.y,n,t.referenceHeight)}}function Li(e){return Oi.parse(e)}function Ri(e){switch(e){case`up`:return`down`;case`down`:return`up`;case`left`:return`right`;case`right`:return`left`}}function zi(e){let t=e.filter(e=>Bi(e.type)&&Vi(e.rect)).map(e=>e.rect).sort((e,t)=>(t?.width??0)*(t?.height??0)-(e?.width??0)*(e?.height??0))[0];if(t)return t;let n=e.map(e=>e.rect).filter(Vi);if(n.length===0)return;let r=Math.max(...n.map(e=>e.x+e.width)),i=Math.max(...n.map(e=>e.y+e.height));if(!(r<=0||i<=0))return{x:0,y:0,width:r,height:i}}function Bi(e){if(!e)return!1;let t=e.toLowerCase();return t.includes(`application`)||t.includes(`window`)}function Vi(e){return!!e&&e.width>0&&e.height>0}function Hi(e){if(e===void 0)return .6;if(!Number.isFinite(e)||e<=0)throw new n(`INVALID_ARGS`,`scroll amount must be a positive number`);return e}function Ui(e){if(!Number.isFinite(e)||e<=0)throw new n(`INVALID_ARGS`,`scroll pixels must be a positive integer`);return Math.max(1,Math.round(e))}function Wi(e,t,n){let r=t;return Gi(e,r,Math.max(r,n-t))}function Gi(e,t,n){return Math.min(Math.round(n),Math.max(Math.round(t),Math.round(e)))}function I(e,t,r,i){if(!Number.isFinite(e)||!Number.isInteger(e)||e<r||e>i)throw new n(`INVALID_ARGS`,`${t} must be an integer between ${r} and ${i}`);return e}function Ki(e,t,n={}){let r=Zi(e??[]);if(r.length===0)return{canScroll:!1,emptySnapshot:!0,signature:``};let i=pe(r),a=Qi(r,i,t,n),o=aa(a?ea(r,a.index):r);return a?{canScroll:na(a,i.get(a.index),t),emptySnapshot:!1,signature:o,scope:ra(a)}:{canScroll:!1,emptySnapshot:!1,signature:o}}async function qi(e){let{edge:t,target:n={},scope:r,captureNodes:i}=e;try{let e=Ki(await i(r),t,n);return r&&e.emptySnapshot?await qi({edge:t,target:n,captureNodes:i}):e}catch(e){throw Xi(t,r,e)}}async function Ji(e){let{edge:t,captureState:r,scroll:i}=e,a=await r();a.scope&&(a=await r(a.scope));let o=0,s;for(;a.canScroll;){if(o>=40)throw new n(`COMMAND_FAILED`,`scroll ${t} reached the safety limit before the snapshot showed the edge`,{hint:`The scoped scroll container still reports hidden content. Use a smaller manual scroll + snapshot loop to inspect the current state.`});s=await i(),o+=1,a=await r(a.scope)}return{passes:o,result:s}}function Yi(e,t,n,r,i){return t&&n===0?`Already at ${t}; no hidden content ${t===`bottom`?`below`:`above`} detected`:t?`Scrolled to ${t} with ${n} ${e} passes`:i===void 0?r===void 0?`Scrolled ${e}`:`Scrolled ${e} by ${r}`:`Scrolled ${e} by ${i}px`}function Xi(e,t,r){return t?new n(`COMMAND_FAILED`,`Failed to verify scroll ${e} state for scoped container`,{scope:t,hint:`scroll ${e} could not verify the scoped scroll container. Run snapshot -i for the current screen and retry with a visible scroll target.`},r):new n(`COMMAND_FAILED`,`Failed to verify scroll ${e} state`,{hint:`scroll ${e} needs a snapshot showing hidden content ${e===`bottom`?`below`:`above`} before it will move.`},r)}function Zi(e){return e.map((e,t)=>({...e,ref:`ref`in e&&e.ref?e.ref:`e${t+1}`}))}function Qi(e,t,n,r){let i=new Map(e.map(e=>[e.index,e])),a=e.filter(e=>oe(e)&&la(e.rect));if(a.length===0)return null;let o=$i(r.nodeIndex,i);if(o)return o;let s=r.point;if(s){let e=a.filter(e=>e.rect&&ca(e.rect,s)).sort(oa);if(e.length>0)return e.find(e=>na(e,t.get(e.index),n))??e[0]??null}let c=a.filter(e=>na(e,t.get(e.index),n)).sort(sa);return c.length>0?c[0]??null:a.filter(t=>ae(t,e)).sort(sa)[0]??a.sort(sa)[0]??null}function $i(e,t){if(e===void 0)return null;let n=t.get(e);for(;n;){if(oe(n)&&la(n.rect))return n;n=n.parentIndex===void 0?void 0:t.get(n.parentIndex)}return null}function ea(e,t){let n=new Map(e.map(e=>[e.index,e]));return e.filter(e=>e.index===t||ta(e,t,n))}function ta(e,t,n){let r=e.parentIndex===void 0?void 0:n.get(e.parentIndex);for(;r;){if(r.index===t)return!0;r=r.parentIndex===void 0?void 0:n.get(r.parentIndex)}return!1}function na(e,t,n){return n===`bottom`?e.hiddenContentBelow===!0||t?.hiddenContentBelow===!0:e.hiddenContentAbove===!0||t?.hiddenContentAbove===!0}function ra(e){return[e.identifier,e.label,e.value].map(e=>typeof e==`string`?e.trim():``).find(ia)}function ia(e){return e.length>0&&e.length<=80&&!/^(true|false)$/i.test(e)&&!/^\d+$/.test(e)&&!/^\d+%$/.test(e)}function aa(e){return e.map(e=>{let t=e.rect?[`x`,`y`,`width`,`height`].map(t=>ua(e.rect?.[t])).join(`,`):``;return[String(e.index??``),String(e.parentIndex??``),String(e.type??``),String(e.label??``),String(e.value??``),t].join(`|`)}).join(`
|
|
14
|
-
`)}function oa(e,t){return L(e.rect)-L(t.rect)}function sa(e,t){return L(t.rect)-L(e.rect)}function L(e){return e?e.width*e.height:0}function ca(e,t){return t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height}function la(e){return!!(e&&e.width>0&&e.height>0)}function ua(e){return typeof e==`number`&&Number.isFinite(e)?e.toFixed(1):``}function R(e,t){return{session:t.session,requestId:t.requestId,signal:t.signal??e.signal,metadata:t.metadata}}function z(e){return e.clock?.now()??Date.now()}async function da(e,t){e.clock?await e.clock.sleep(t):await new Promise(e=>setTimeout(e,t))}function B(e){return e&&typeof e==`object`?e:void 0}const fa=[`x`,`y`,`width`,`height`];function V(e){let t=H(e);if(!t)return null;let n=r(t);return!Number.isFinite(n.x)||!Number.isFinite(n.y)?null:n}function H(e){if(!e)return null;let t=Number(e.x),n=Number(e.y),r=Number(e.width),i=Number(e.height);return!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)||r<0||i<0?null:{x:t,y:n,width:r,height:i}}function U(e,t){return!e||!t?!1:fa.every(n=>Math.abs(e[n]-t[n])<=.5)}function pa(e){return{x:ma(e.x,e.width),y:ma(e.y,e.height)}}function ma(e,t){if(t<=1)return Math.floor(e);let n=Math.ceil(e),r=Math.floor(e+t-1);return Math.round(Math.min(r,Math.max(n,e+t/2)))}const ha=[`tabbar`,`toolbar`,`navigationbar`,`bottomnavigation`,`bottomnavigationview`,`sheet`,`dialog`,`alert`,`popover`,`menu`],ga=[`button`,`link`,`menuitem`,`tabitem`,`textfield`,`searchfield`,`edittext`,`checkbox`,`radio`,`switch`,`cell`];function _a(e,t={}){if(e.length<2)return e;let n=[...e],r=new Map(n.map(e=>[e.index,e])),i={nodes:n,byIndex:r,overlayPositions:n.flatMap((e,n)=>Sa(e,r,t)?[n]:[])},a=!1;for(let[e,r]of n.entries()){if(!xa(r)||!va(i,e,r,t))continue;a=!0;let o={...r,hittable:!1,interactionBlocked:`covered`,presentationHints:Ma(r.presentationHints)};n[e]=o,i.byIndex.set(o.index,o)}return a?n:e}function W(e){return e.interactionBlocked!==void 0}function va(e,t,n,i){let a=G(n.rect);if(!a)return null;let o=r(a);for(let r of e.overlayPositions){if(r<=t)continue;let s=e.nodes[r];if(s&&ya(e,r,n,a,o,i))return s}return null}function ya(e,t,n,r,i,a){if(!e.nodes[t])return!1;let o=ba(e,t,n,r,a);return!!(o&&g(o,i.x,i.y))}function ba(e,t,n,r,i){let a=e.nodes[t];if(!a||!Sa(a,e.byIndex,i)||Aa(n,a,e.byIndex))return null;let o=G(a.rect);return!o||U(r,o)||va(e,t,a,i)?null:o}function xa(e){return G(e.rect)?e.hittable===!0||Ea(e)?!0:!!(e.label?.trim()||e.value?.trim()||e.identifier?.trim()):!1}function Sa(e,t,n){return!G(e.rect)||ka(e)?!1:Da(e,ha)||Ca(e,t,n)}function Ca(e,t,n){return n.isAdditionalOverlayNode?.(e)===!0?!wa(e,t,n):!1}function wa(e,t,n){let r=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);){if(Ta(r,n))return!0;i.add(r.index),r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0}return!1}function Ta(e,t){return t.isAdditionalOverlayNode?.(e)===!0&&G(e.rect)!==null&&!ka(e)}function Ea(e){return Da(e,ga)}function Da(e,t){let n=Oa(e);return t.some(e=>n.includes(e))}function Oa(e){return[e.type,e.role,e.subrole].map(e=>re(e??``)).join(` `)}function ka(e){let t=Oa(e);return t.includes(`application`)||t.includes(`window`)}function Aa(e,t,n){return ja(e,t,n)||ja(t,e,n)}function ja(e,t,n){let r=typeof t.parentIndex==`number`?n.get(t.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);){if(r.index===e.index)return!0;i.add(r.index),r=typeof r.parentIndex==`number`?n.get(r.parentIndex):void 0}return!1}function G(e){let t=H(e);return t&&t.width>0&&t.height>0?t:null}function Ma(e){return Array.from(new Set([...e??[],`covered`]))}function Na(e){return e}function Pa(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x+a.width),i=Math.max(i,a.y+a.height);return{x:t,y:n,width:r-t,height:i-n}}function Fa(e,t){return{x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}}function Ia(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.width,t.x+t.width),a=Math.min(e.y+e.height,t.y+t.height);return i<=n||a<=r?0:(i-n)*(a-r)}function La(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function Ra(e,t){return(e.x-t.x)**2+(e.y-t.y)**2}function za(e,t,n){return Math.min(Math.max(e,t),n)}const Ba=[`button`,`link`,`menuitem`,`tabitem`,`textfield`,`searchfield`,`securetextfield`,`checkbox`,`radio`,`switch`,`cell`];function Va(e,t){return Ha(e,t).node}function Ha(e,t){if(W(t))return{node:t,reason:`covered`};let n=Ua(e,t);if(n?.rect&&V(n.rect))return{node:n,reason:`same-rect-descendant`};if(Wa(t)&&t.rect&&V(t.rect))return{node:t,reason:`semantic-target`};let r=de(e,t);return r?.rect&&!W(r)&&V(r.rect)?Ka(t,r,e)?{node:t,reason:`overly-broad-ancestor`}:{node:r,reason:`hittable-ancestor`}:{node:t,reason:`original`}}function Ua(e,t){let n=H(t.rect);if(!n)return null;let r=t,i=new Set;for(;!i.has(r.ref);){i.add(r.ref);let t=e.filter(e=>{if(e.parentIndex!==r.index||!e.hittable||W(e))return!1;let t=H(e.rect);return t?U(t,n):!1});if(t.length!==1)break;r=t[0]}return r===t?null:r}function Wa(e){return[e.type,e.role,e.subrole].map(e=>re(e??``)).some(Ga)}function Ga(e){return e===`tab`||Ba.some(t=>e.includes(t))}function Ka(e,t,n){let r=H(e.rect),i=H(t.rect);if(!r||!i)return!1;let a=qa(n,r);return!a||!Ja(i,a)?!1:!U(r,i)}function qa(e,t){let n=r(t),i=e.filter(e=>{let t=(e.type??``).toLowerCase();return t.includes(`application`)||t.includes(`window`)}).map(e=>H(e.rect)).filter(e=>e!==null);if(i.length===0)return null;let a=i.filter(e=>g(e,n.x,n.y));return ie(a.length>0?a:i)}function Ja(e,t){let n=Ia(e,t),r=e.width*e.height,i=t.width*t.height;if(n<=0||r<=0||i<=0)return!1;let a=n/i,o=n/r;return a>=.9&&o>=.8}async function K(e,t,n){return await J(e,t,n.action),t.target.kind===`point`?await Xa(e,t,t.target,n):t.target.kind===`ref`?await Qa(e,t,t.target,n):await $a(e,t,t.target,n)}async function Ya(e,t,n){let r=t.session??`default`,i=await e.sessions.get(r);if(!i?.snapshot)return;let a={x:n.x,y:n.y,width:0,height:0},o=le(i.snapshot.nodes,a);if(!o)return;let s={x:n.x,y:n.y};if(!g(o,s.x,s.y))return`Coordinates (${s.x}, ${s.y}) are outside the last-known viewport (${o.width}x${o.height}). The tap will be forwarded anyway; take a fresh snapshot if the screen changed.`}async function Xa(e,t,n,r){let i=await Ya(e,t,n);if(!r.captureEvidenceBaseline)return{kind:`point`,point:{x:n.x,y:n.y},...i?{warning:i}:{}};let a=await Za(e,t);return{kind:`point`,point:{x:n.x,y:n.y},...a?{preActionNodes:a}:{},...i?{warning:i}:{}}}async function Za(e,t){try{return(await q(e,t,!0)).snapshot.nodes}catch{return}}async function Qa(e,t,n,r){let i=await co(e,t,n),a=i.resolved,o=r.promoteToHittableAncestor?ro(i.snapshot.nodes,a.node,{action:r.action,label:`Ref ${n.ref}`}):a.node;return io(o,`Ref ${n.ref}`,r.action),mo(o,i.snapshot.nodes,n.ref,r.action),{kind:`ref`,point:uo(o,`Ref ${n.ref} not found or has invalid bounds`),target:{kind:`ref`,ref:`@${a.ref}`},...eo(e,o,i.snapshot.nodes,r.action)}}async function $a(e,t,r,i){let a=s(r.selector),o=await q(e,t,i.requireInteractive),c=ve(no(o.snapshot.nodes),a,{platform:e.backend.platform,requireRect:!0,requireUnique:!0,disambiguateAmbiguous:!0});if((!c||!c.node.rect)&&i.requireInteractive&&(o=await q(e,t,!1),c=ve(no(o.snapshot.nodes),a,{platform:e.backend.platform,requireRect:!0,requireUnique:!0,disambiguateAmbiguous:!0})),!c||!c.node.rect){let t=ve(o.snapshot.nodes,a,{platform:e.backend.platform,requireRect:!0,requireUnique:!1});throw t?.node&&W(t.node)?ao({label:`Selector ${t.selector.raw}`,node:t.node,action:i.action,selector:t.selector.raw}):new n(`COMMAND_FAILED`,ye(a,c?.diagnostics??[],{unique:!0}),{hint:xe(c?.diagnostics??[])})}let l=i.promoteToHittableAncestor?ro(o.snapshot.nodes,c.node,{action:i.action,label:`Selector ${c.selector.raw}`}):c.node;return io(l,`Selector ${c.selector.raw}`,i.action),po(l,o.snapshot.nodes,c.selector.raw,i.action),{kind:`selector`,point:uo(l,`Selector ${c.selector.raw} resolved to invalid bounds`),target:{kind:`selector`,selector:c.selector.raw},...eo(e,l,o.snapshot.nodes,i.action)}}function eo(e,t,n,r){return{node:t,selectorChain:Se(t,e.backend.platform,{action:r===`fill`?`fill`:`click`}),refLabel:me(t,n),...to(t,r),preActionNodes:n}}function to(e,t){return e.hittable===!1?{targetHittable:!1,hint:`The resolved element reports hittable: false, so this ${t} may have had no visible effect. Verify with a snapshot, or prefer a @ref or a longer/more specific selector to target the intended element.`}:{}}function no(e){return e.filter(e=>!W(e))}function ro(e,t,n){let r=Ha(e,t);if(r.reason===`covered`)throw ao({label:n.label,node:t,action:n.action});return r.node}function io(e,t,n){if(W(e))throw ao({label:t,node:e,action:n})}function ao(e){return new n(`COMMAND_FAILED`,`${e.label} is covered by another visible element and cannot ${oo(e.action)} safely`,{hint:`Use a different visible target, scroll it clear of the overlay, or inspect with snapshot/screenshot before retrying.`,...e.selector?{selector:e.selector}:{},ref:`@${e.node.ref}`,interactionBlocked:e.node.interactionBlocked})}function oo(e){switch(e){case`fill`:return`be filled`;case`focus`:return`be focused`;case`longPress`:return`be long-pressed`;default:return`be tapped`}}async function q(e,t,r){if(!e.backend.captureSnapshot)throw new n(`UNSUPPORTED_OPERATION`,`snapshot is not supported by this backend`);let i=t.session??`default`,a=await e.sessions.get(i);if(!a)throw new n(`SESSION_NOT_FOUND`,`No active session. Run open first.`);let o=await e.backend.captureSnapshot(R(e,t),{interactiveOnly:r,includeRects:!0}),s=o.snapshot??{nodes:o.nodes??[],truncated:o.truncated,backend:o.backend,createdAt:z(e)};return await e.sessions.set({...a,snapshot:s}),{snapshot:s}}async function J(e,t,r){if(e.backend.platform!==`macos`)return;let i=await so(e,t);if(!(i!==`desktop`&&i!==`menubar`)&&!(i===`menubar`&&(r===`click`||r===`press`)))throw new n(`UNSUPPORTED_OPERATION`,`${r} is not supported on macOS ${i} sessions yet. Open an app session to act, or use the ${i} surface to inspect.`)}async function so(e,t){return(await e.sessions.get(t.session??`default`))?.metadata?.surface}async function co(e,t,r){let i=t.session??`default`,a=await e.sessions.get(i);if(!a)throw new n(`SESSION_NOT_FOUND`,`No active session. Run open first.`);if(!a.snapshot)throw new n(`INVALID_ARGS`,`No snapshot in session. Run snapshot first.`);let o=r.fallbackLabel??``,s=lo(a.snapshot.nodes,r.ref,{fallbackLabel:o});if(s)return{snapshot:a.snapshot,resolved:s};let c=await q(e,t,!0),l=lo(c.snapshot.nodes,r.ref,{fallbackLabel:o});if(!l)throw new n(`COMMAND_FAILED`,`Ref ${r.ref} not found or has no bounds`,{hint:be});return{...c,resolved:l}}function lo(e,t,r){let i=a(t);if(!i)throw new n(`INVALID_ARGS`,`Invalid ref: ${t}`);let s=o(e,i);if(fo(s))return{ref:i,node:s};let c=r.fallbackLabel.length>0?ue(e,r.fallbackLabel):null;return fo(c)?{ref:i,node:c}:null}function uo(e,t){let r=V(e.rect);if(!r)throw new n(`COMMAND_FAILED`,t);return r}function fo(e){return e?V(e.rect)!==null:!1}function po(e,t,n,r){go(e,t,{message:`Selector ${n} resolved to an off-screen element and is not safe to ${r}`,details:{reason:`offscreen_selector`,selector:n},hint:`The element is outside the visible viewport — likely inside a closed drawer, another tab, or scrolled content. Scroll toward it or open its container, take a fresh snapshot, then retry ${r}.`})}function mo(e,t,n,r){go(e,t,{message:`Ref ${n} is off-screen and not safe to ${r}`,details:{reason:`offscreen_ref`,ref:a(n)},hint:`Use scroll with the direction from the off-screen summary, take a fresh snapshot, then retry ${r} with the new ref or a selector.`})}async function ho(e,t,n,r){let i=(await e.sessions.get(t.session??`default`))?.snapshot?.nodes;if(!i||a(n.ref)===null)return{};let o=lo(i,n.ref,{fallbackLabel:n.fallbackLabel??``});return o?(io(o.node,`Ref ${n.ref}`,r),mo(o.node,i,n.ref,r),to(o.node,r)):{}}function go(e,t,r){let i=e.rect?fe(e,t):null;if(!(!e.rect||!i||h(e,t)))throw new n(`COMMAND_FAILED`,r.message,{...r.details,rect:e.rect,viewport:i,hint:r.hint})}function _o(e){let t=Buffer.alloc(16);for(let n of e)yo(t,vo(n));return{digest:`ax1:${Ce(`sha256`).update(t).update(`\0`).update(String(e.length)).digest(`hex`).slice(0,16)}`,nodeCount:e.length}}function vo(e){return Ce(`sha256`).update(e.type??``).update(`\0`).update(e.label??``).update(`\0`).update(e.identifier??``).digest().subarray(0,16)}function yo(e,t){for(let n=0;n<e.length;n+=1)e[n]=(e[n]??0)^(t[n]??0)}function Y(e){let{digest:t,nodeCount:n}=_o(e),r=e.reduce((e,t)=>t.hittable===!1?e:e+1,0),i=bo(e);return{digest:t,nodeCount:n,interactiveNodeCount:r,...i?{foregroundApp:i}:{}}}function bo(e){for(let t of e)if(t.bundleId)return t.bundleId;for(let t of e)if(t.appName)return t.appName}function xo(e,t){let n=T(e.type??`Element`),r=w(e,n),i=e.enabled===!1?`disabled`:`enabled`,a=e.selected===!0?`selected`:`unselected`,o=e.hittable===!0?`hittable`:`not-hittable`;return[String(t??e.depth??0),n,r,i,a,o].join(`|`)}function So(e,t,n={}){let r=To(wo(e,n),wo(t,n)),i={additions:0,removals:0,unchanged:0};for(let e of r)e.kind===`added`&&(i.additions+=1),e.kind===`removed`&&(i.removals+=1),e.kind===`unchanged`&&(i.unchanged+=1);return{summary:i,lines:r}}function Co(e,t={}){return wo(e,t).length}function wo(e,t){return t.flatten?e.map(e=>({text:bt(e,0,!1),comparable:xo(e,0),...t.withRefs&&e.ref?{ref:e.ref}:{}})):C(e).map(e=>({text:e.text,comparable:xo(e.node,e.depth),...t.withRefs&&e.node.ref?{ref:e.node.ref}:{}}))}function To(e,t){let n=e.length,r=t.length,i=n+r,a=new Map,o=[];a.set(1,0);for(let s=0;s<=i;s+=1){o.push(new Map(a));for(let i=-s;i<=s;i+=2){let c=Do(a,i,s)?X(a,i+1):X(a,i-1)+1,l=c-i;for(;c<n&&l<r&&e[c].comparable===t[l].comparable;)c+=1,l+=1;if(a.set(i,c),c>=n&&l>=r)return Eo(o,e,t,n,r)}}return[]}function Eo(e,t,n,r,i){let a=[],o=r,s=i;for(let r=e.length-1;r>=0;--r){let i=e[r],c=o-s,l=Do(i,c,r)?c+1:c-1,u=X(i,l),d=u-l;for(;o>u&&s>d;)a.push({kind:`unchanged`,text:n[s-1].text}),--o,--s;if(r===0)break;if(o===u){let e=n[d];a.push({kind:`added`,text:e.text,...e.ref?{ref:e.ref}:{}}),s=d}else a.push({kind:`removed`,text:t[u].text}),o=u}return a.reverse(),a}function Do(e,t,n){return t===-n||t!==n&&X(e,t-1)<X(e,t+1)}function X(e,t){return e.get(t)??0}function Oo(e){return e===`text`||e===`label`||e===`any`}async function ko(e,t){let r=t??`default`,i=await e.sessions.get(r);if(!i)throw new n(`SESSION_NOT_FOUND`,`No active session. Run open first.`);if(!i.snapshot)throw new n(`INVALID_ARGS`,`No snapshot in session. Run snapshot first.`);return{sessionName:r,session:i,snapshot:i.snapshot}}async function Ao(e,t,r={updateSession:!0}){let i=e.backend.captureSnapshot;if(!i)throw new n(`UNSUPPORTED_OPERATION`,`snapshot is not supported by this backend`);let a=t.session??`default`,o=await e.sessions.get(a),s=await i(R(e,t),{interactiveOnly:r.interactiveOnly??!1,depth:t.depth,scope:r.scope??t.scope,raw:t.raw,includeRects:r.includeRects}),c=s.snapshot??{nodes:s.nodes??[],truncated:s.truncated,backend:s.backend,...s.quality?{snapshotQuality:s.quality}:{},createdAt:z(e)};return r.updateSession&&o&&!_e(c.snapshotQuality)&&await e.sessions.set({...o,snapshot:c}),{sessionName:a,session:o,snapshot:c}}async function jo(e,t,n){if(e.backend.readText){let r=await e.backend.readText(R(e,{session:t.sessionName}),n);if(r.text.trim())return r.text}return ne(n)}function Mo(e,t,r){let i=a(t);if(!i)throw new n(`INVALID_ARGS`,r.invalidRefMessage);let s=o(e,i)??(r.fallbackLabel.length>0?ue(e,r.fallbackLabel):null);if(!s)throw new n(`COMMAND_FAILED`,r.notFoundMessage);return{ref:i,node:s}}const No=`Settled on a nearly-empty tree — the app may still be loading. Wait for specific content (wait text ...) before interacting.`;async function Po(e,t,n){let{quietMs:r,timeoutMs:i}=n,a=z(e),o=a+i,s=!1,c=Math.min(300,Math.max(25,r)),l=0,u,d=0,f,p=a;for(;z(e)<o;){let m=await Io(e,t,o-z(e));if(!m)return{settled:!1,stalled:!0,waitedMs:z(e)-a,captures:l,nodeCount:d,lastCapture:f};l+=1,f=m;let h=Lo(m.snapshot.nodes),g=z(e);if(n.resetBudgetOnPrivateAxRecovery===!0&&!s&&Fo(m.snapshot.snapshotQuality)){s=!0,o=Math.max(o,g+i),p=g,u=h,d=m.snapshot.nodes.length,await da(e,c);continue}if(h!==u)u=h,d=m.snapshot.nodes.length,p=g;else if(l>=2&&g-p>=r)return{settled:!0,stalled:!1,waitedMs:g-a,captures:l,nodeCount:d,lastCapture:f};await da(e,c)}return{settled:!1,stalled:!1,waitedMs:z(e)-a,captures:l,nodeCount:d,lastCapture:f}}function Fo(e){return e?.state===`recovered`&&e.backend===`private-ax`}async function Io(e,t,n){let r=Ao(e,t,{updateSession:!1,interactiveOnly:!0}),i;try{let e=await Promise.race([r,new Promise(e=>{i=setTimeout(()=>e(void 0),n)})]);return e===void 0&&r.catch(()=>{}),e}finally{i!==void 0&&clearTimeout(i)}}function Lo(e){return e.map(Ro).join(`|`)}function Ro(e){let t=e.rect?`${Math.round(e.rect.x)},${Math.round(e.rect.y)},${Math.round(e.rect.width)},${Math.round(e.rect.height)}`:``;return`${e.type??``}#${e.label??``}#${e.identifier??``}#${t}`}const zo=`The UI kept changing for the whole settle budget (animation, carousel, or ticker?), so no settled diff is shown. Raise --timeout, wait for specific content, or take a fresh snapshot.`,Bo=`A snapshot capture stalled past the settle budget, so no settled diff is shown. The action itself succeeded; observe with wait stable or snapshot.`;async function Vo(e,t,n){let r=n.quietMs??500,i=n.timeoutMs??1e4,a={settled:!1,waitedMs:0,captures:0,quietMs:r,timeoutMs:i};try{let o=await Po(e,t,{quietMs:r,timeoutMs:i,resetBudgetOnPrivateAxRecovery:!0}),s={...a,settled:o.settled,waitedMs:o.waitedMs,captures:o.captures};if(!o.lastCapture)return{observation:{...s,hint:o.stalled?Bo:zo}};let c=await Zo(e,t,o.lastCapture),l=o.lastCapture.snapshot.nodes;return{observation:{...s,...o.settled&&c?Go(Uo(n.resolved),l):{},...Xo(o,c,l.length)},settledNodes:l}}catch(e){return{observation:{...a,hint:`Settle observation unavailable (${e instanceof Error?e.message:String(e)}). The action itself succeeded; take a snapshot to observe the result.`}}}}function Ho(e,t){if(!e)return;let n=Y(e),r=t!==void 0&&n.digest!==Y(t).digest;return{...n,changedFromBefore:r}}function Uo(e){return`preActionNodes`in e&&e.preActionNodes?e.preActionNodes:[]}function Wo(e,t){let n=So(Jo(e),Jo(t),{flatten:!0,withRefs:!0}),r=n.lines.filter(e=>e.kind!==`unchanged`),i=Yo(r).map(e=>({kind:e.kind,text:e.text,...e.ref?{ref:e.ref}:{}}));return{summary:n.summary,lines:i,...r.length>i.length?{truncated:!0}:{}}}function Go(e,t){let n=Wo(e,t);return{diff:n,...Ko(n,t)}}function Ko(e,t){let n=new Set(e.lines.filter(e=>e.kind===`added`&&e.ref).map(e=>e.ref));return n.size>0?{}:qo(t,n)}function qo(e,t){let n=e.filter(e=>e.ref&&e.hittable===!0&&e.interactionBlocked!==`covered`&&!t.has(e.ref));if(n.length===0)return{};let r=n.slice(0,20).map(e=>{let t=T(e.type??`Element`),n=w(e,t);return{ref:e.ref,role:t,...n?{label:n}:{}}});return{tail:r,...n.length>r.length?{tailTruncated:!0}:{}}}function Jo(e){return e.filter(e=>e.type!==`Key`)}function Yo(e){if(e.length<=80)return e;let t=e.filter(e=>e.kind===`added`),n=new Set(t.slice(0,80)),r=80-n.size,i=[];for(let t of e)n.has(t)?i.push(t):t.kind===`removed`&&r>0&&(i.push(t),--r);return i}function Xo(e,t,n){return e.stalled?{hint:Bo}:e.settled?t?n<5?{hint:No}:{}:{hint:`Settled on a sparse, unreadable tree — the diff is omitted. Use screenshot as visual truth before interacting further.`}:{hint:zo}}async function Zo(e,t,n){if(_e(n.snapshot.snapshotQuality))return!1;let r=await e.sessions.get(t.session??`default`);return r?(await e.sessions.set({...r,snapshot:n.snapshot}),!0):!1}function Qo(e){let t=e.verify===!0;return{verify:t,needsPreActionBaseline:t||e.settle!==void 0,...e.settle===void 0?{}:{settle:e.settle}}}async function $o(e,t,n,r,i){let a=await es(e,t,n,i);return ns({...r,...a})}async function es(e,t,n,r){if(r.settle!==void 0){let i=await Vo(e,t,{...r.settle,resolved:n}),a=r.verify?Ho(i.settledNodes,`preActionNodes`in n?n.preActionNodes:void 0):void 0;return{settle:i.observation,...a?{evidence:a}:{}}}if(!r.verify)return{};let i=await ts(e,t,n);return i?{evidence:i}:{}}async function ts(e,t,n){let r=`preActionNodes`in n?n.preActionNodes:void 0;try{let n=Y((await q(e,t,!0)).snapshot.nodes),i=r!==void 0&&n.digest!==Y(r).digest;return{...n,changedFromBefore:i}}catch{return}}function ns(e){let t=e;if(t.targetHittable!==!1||!rs(t)||t.hint===void 0)return e;let{hint:n,...r}=t;return r}function rs(e){if(e.evidence?.changedFromBefore===!0)return!0;let t=e.settle?.diff?.summary;return!!t&&(t.additions>0||t.removals>0)}const is=[`up`,`down`,`left`,`right`,`top`,`bottom`],as=async(e,t)=>{let r=await K(e,t,{action:`focus`,requireInteractive:!0,promoteToHittableAncestor:!1});if(!e.backend.focus)throw new n(`UNSUPPORTED_OPERATION`,`focus is not supported by this backend`);let i=Z(r),a=B(await e.backend.focus(R(e,t),i));return{...r,...a?{backendResult:a}:{},...N(`Focused (${i.x}, ${i.y})`)}},os=async(e,t)=>{let r=Qo(t),i=await K(e,t,{action:`longPress`,requireInteractive:!0,promoteToHittableAncestor:!0,captureEvidenceBaseline:r.needsPreActionBaseline});if(!e.backend.longPress)throw new n(`UNSUPPORTED_OPERATION`,`longPress is not supported by this backend`);let a=t.durationMs===void 0?void 0:I(t.durationMs,`durationMs`,0,12e4),o=Z(i),s=B(await e.backend.longPress(R(e,t),o,{durationMs:a}));return await $o(e,t,i,{...i,...a===void 0?{}:{durationMs:a},...s?{backendResult:s}:{},...N(`Long pressed (${o.x}, ${o.y})`)},r)},ss=async(e,t)=>{if(!e.backend.scroll)throw new n(`UNSUPPORTED_OPERATION`,`scroll is not supported by this backend`);let r=ms(t.direction),i=bs(t.amount,`scroll amount`),a=Ss(t.pixels,`scroll pixels`),o=Si(t.durationMs);xi({amount:i,pixels:a},`scroll accepts either amount or pixels, not both`);let s=await ds(e,t),c=s.kind===`viewport`?{kind:`viewport`}:{kind:`point`,point:Z(s)},l=e.backend.scroll,u=async()=>await l(R(e,t),c,{direction:r.direction,...i===void 0?{}:{amount:i},...a===void 0?{}:{pixels:a},...o===void 0?{}:{durationMs:o}}),d,f=0;if(r.edge){let n=r.edge,i=hs(s),a=await Ji({edge:n,captureState:async r=>await gs(e,t,n,i,r),scroll:u});d=a.result,f=a.passes}else d=await u(),f=1;let p=B(d),m=Ci(p);return{...s,direction:r.direction,...r.edge?{edge:r.edge,passes:f}:{},...i===void 0?{}:{amount:i},...a===void 0?{}:{pixels:a},...m===void 0?{}:{durationMs:m},...p?{backendResult:p}:{},...N(Yi(r.direction,r.edge,f,i,a))}},cs=async(e,t)=>{if(!e.backend.swipe)throw new n(`UNSUPPORTED_OPERATION`,`swipe is not supported by this backend`);if(t.preset)return await ls(e,t,e.backend.swipe);let r=await fs(e,t),i=ps(r.point,t),a=t.durationMs===void 0?void 0:I(t.durationMs,`durationMs`,16,1e4),o=B(await e.backend.swipe(R(e,t),r.point,i.point,{durationMs:a}));return{kind:`swipe`,from:r.point,to:i.point,...i.direction?{direction:i.direction}:{},...i.distance===void 0?{}:{distance:i.distance},...a===void 0?{}:{durationMs:a},...r.target?{fromTarget:r.target}:{},...o?{backendResult:o}:{},...N(`Swiped`)}};async function ls(e,t,r){if(t.from||t.to||t.direction||t.distance!==void 0)throw new n(`INVALID_ARGS`,`gesture swipe preset cannot be combined with from, to, direction, or distance`);let i=Ni(t.preset);await J(e,t,`swipe`);let a=Mi(i,ws((await q(e,t,!1)).snapshot.nodes),{platform:e.backend.platform}),o=t.durationMs===void 0?void 0:I(t.durationMs,`durationMs`,16,1e4),s={x:a.x1,y:a.y1},c={x:a.x2,y:a.y2},l=B(await r(R(e,t),s,c,{durationMs:o}));return{kind:`swipe`,from:s,to:c,preset:i,...o===void 0?{}:{durationMs:o},fromTarget:{kind:`viewport`},...l?{backendResult:l}:{},...N(`Swiped ${i}`)}}const us=async(e,t)=>{if(!e.backend.pinch)throw new n(`UNSUPPORTED_OPERATION`,`pinch is not supported by this backend`);await J(e,t,`pinch`);let r=xs(t.scale,`pinch scale`),i=t.center?await K(e,{...t,target:t.center},{action:`pinch`,requireInteractive:!1,promoteToHittableAncestor:!1}):void 0,a=B(await e.backend.pinch(R(e,t),{scale:r,...i?{center:i.point}:{}}));return{kind:`pinch`,scale:r,...i?{center:i.point,centerTarget:i}:{},...a?{backendResult:a}:{},...N(`Pinched to scale ${r}`)}};async function ds(e,t){let n=t.target??{kind:`viewport`};return n.kind===`viewport`?(await J(e,t,`scroll`),{kind:`viewport`}):await K(e,{...t,target:n},{action:`scroll`,requireInteractive:!1,promoteToHittableAncestor:!1})}async function fs(e,t){if(t.from){if(ys(t.from))return await J(e,t,`swipe`),{point:vs(t.from,`from`)};let n=await K(e,{...t,target:t.from},{action:`swipe`,requireInteractive:!1,promoteToHittableAncestor:!1});return{point:Z(n),target:n}}if(!t.direction)throw new n(`INVALID_ARGS`,`swipe requires from+to or a direction`);return await J(e,t,`swipe`),{point:r(Cs((await q(e,t,!1)).snapshot.nodes)),target:{kind:`viewport`}}}function ps(e,t){if(t.to)return{point:vs(t.to,`to`)};let n=_s(t.direction,`swipe direction`),r=xs(t.distance??200,`swipe distance`);switch(n){case`up`:return{point:{x:e.x,y:e.y-r},direction:n,distance:r};case`down`:return{point:{x:e.x,y:e.y+r},direction:n,distance:r};case`left`:return{point:{x:e.x-r,y:e.y},direction:n,distance:r};case`right`:return{point:{x:e.x+r,y:e.y},direction:n,distance:r}}}function ms(e){return e===`bottom`?{direction:`down`,edge:`bottom`}:e===`top`?{direction:`up`,edge:`top`}:{direction:_s(e,`scroll direction`)}}function hs(e){return e.kind===`viewport`?{}:{point:e.point,nodeIndex:`node`in e?e.node?.index:void 0}}function Z(e){if(!e.point)throw new n(`COMMAND_FAILED`,`Interaction target resolved without coordinates`);return e.point}async function gs(e,t,r,i,a){if(!e.backend.captureSnapshot)throw new n(`UNSUPPORTED_OPERATION`,`scroll ${r} requires snapshot support to verify hidden content before scrolling`);let{captureSnapshot:o}=e.backend;return await qi({edge:r,target:i,scope:a,captureNodes:async n=>{let r=await o(R(e,t),{scope:n});return r.snapshot?.nodes??r.nodes??[]}})}function _s(e,t){switch(e){case`up`:case`down`:case`left`:case`right`:return e;default:throw new n(`INVALID_ARGS`,`${t} must be up, down, left, or right`)}}function vs(e,t){let r=Number(e.x),i=Number(e.y);if(!Number.isFinite(r)||!Number.isFinite(i))throw new n(`INVALID_ARGS`,`${t} point requires finite x and y`);return{x:r,y:i}}function ys(e){return`x`in e&&`y`in e}function bs(e,t){return e===void 0?void 0:xs(e,t)}function xs(e,t){if(!Number.isFinite(e)||e<=0)throw new n(`INVALID_ARGS`,`${t} must be a positive number`);return e}function Ss(e,t){if(e!==void 0){if(!Number.isFinite(e)||!Number.isInteger(e)||e<=0)throw new n(`INVALID_ARGS`,`${t} must be a positive integer`);return e}}function Cs(e){let t=e.filter(t=>ae(t,e)).map(e=>e.rect).filter(Ts),r=t.length>0?t:e.map(e=>e.rect).filter(Ts);if(r.length===0)throw new n(`COMMAND_FAILED`,`Cannot infer viewport for directional swipe`);let i=Math.min(...r.map(e=>e.x)),a=Math.min(...r.map(e=>e.y)),o=Math.max(...r.map(e=>e.x+e.width)),s=Math.max(...r.map(e=>e.y+e.height));return{x:i,y:a,width:o-i,height:s-a}}function ws(e){let t=Cs(e);return{referenceWidth:t.width,referenceHeight:t.height}}function Ts(e){return!!(e&&e.width>0&&e.height>0)}const Es=/^e\d+$/;function Ds(e){if(e[0]?.startsWith(`@`)){let t=Fs(e.slice(1));return{ref:e[0],...t===void 0?{}:{label:t}}}if(Es.test(e[0]??``))throw new n(`INVALID_ARGS`,`Did you mean "@${e[0]}"? Snapshot refs need the @ prefix.`);let t=d(e);if(t){if(t.rest.length>0)throw new n(`INVALID_ARGS`,Ns(e,t));return{selector:t.selectorExpression}}return ks(e)}function Os(e){let t=e[0];if(t?.startsWith(`@`)){let n=e.length>=3?e.slice(2).join(` `):e.slice(1).join(` `);return{kind:`ref`,target:{ref:t,label:e.length>=3?Fs(e.slice(1,2)):void 0},text:n}}if(Es.test(t??``))throw new n(`INVALID_ARGS`,`Did you mean "@${t}"? Snapshot refs need the @ prefix.`);let r=d(e,{preferTrailingValue:!0});return r?{kind:`selector`,target:{selector:r.selectorExpression},text:r.rest.join(` `)}:{kind:`point`,target:ks(e.slice(0,2)),text:e.slice(2).join(` `)}}function ks(e){let t=e[0]??``,r=l(t);if(r){let i=As(t)?r.value:[r.value,...e.slice(1)].join(` `).trim();throw new n(`INVALID_ARGS`,js({key:r.key,value:i}))}let i=Number(e[0]),a=Number(e[1]);if(Number.isFinite(i)&&Number.isFinite(a))return{x:i,y:a};throw new n(`INVALID_ARGS`,Ms(e))}function As(e){let t=e.slice(e.indexOf(`=`)+1).trim();if(t.length<2)return!1;let n=t[0];return(n===`"`||n===`'`)&&t.endsWith(n)}function js(e){let{key:t,value:n}=e;return`Unknown selector key "${t}". Supported: ${p.join(`, `)}. ${f(t)?`Did you mean role=${t} label=${Q(n)}?`:`Did you mean label=${Q(n)}?`}`}function Ms(e){let t=e.filter(e=>e!==void 0).join(` `);if(!t.trim())return`Missing target. Pass an @ref from snapshot, a selector like text="Sign in", or "x y" coordinates.`;let n=`Target "${t}" is not a @ref, selector, or "x y" point.`;return e.some(e=>c(e??``))?`${n} Selector values with spaces need quotes, e.g. text="Sign in".`:`${n} To match by visible text, use text=${Q(t)} (or label=/id=/role=), or pass an @ref from snapshot.`}function Ns(e,t){return`${`Selector ${t.selectorExpression} is followed by unexpected extra arguments: "${t.rest.join(` `)}".`} Selector values with spaces need quotes, e.g. ${Ps(e,t)??`text="Sign in"`}.`}function Ps(e,t){let n=e.length-t.rest.length,r=e[n-1];if(r===void 0)return;let i=r.indexOf(`=`);if(i<=0)return;let a=[r.slice(i+1),...t.rest].join(` `),o=`${r.slice(0,i+1)}${Q(a)}`;return[...e.slice(0,n-1),o].join(` `)}function Q(e){return`"${e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`)}"`}function Fs(e){return e.join(` `).trim()||void 0}function Is(e,t){let r=e===void 0?NaN:Number(e);if(!Number.isInteger(r)||r<1)throw new n(`INVALID_ARGS`,`viewport ${t} must be a positive integer`);return r}const Ls=[`path`,`start`,`stop`,`doctor`,`mark`,`clear`],Rs=[`medium`,`high`],zs=`medium`;function Bs(e){return Rs.includes(e)}function Vs(e){let t=typeof e==`number`?e:Hs(e);return t!==void 0&&Number.isInteger(t)&&t>=5&&t<=10?t:void 0}function Hs(e){return typeof e==`string`&&/^\d+$/.test(e)?Number(e):void 0}function Us(e){if(Bs(e))return e;let t=Vs(e);if(t!==void 0)return t<=7?`medium`:`high`}const Ws=[`portrait`,`portrait-upside-down`,`landscape-left`,`landscape-right`];function Gs(e){if(e===void 0)throw new n(`INVALID_ARGS`,`rotate requires an orientation argument. Use portrait|portrait-upside-down|landscape-left|landscape-right.`);switch(e?.trim().toLowerCase()){case`portrait`:return`portrait`;case`portrait-upside-down`:case`upside-down`:return`portrait-upside-down`;case`landscape-left`:case`left`:return`landscape-left`;case`landscape-right`:case`right`:return`landscape-right`;default:throw new n(`INVALID_ARGS`,`Invalid rotation: ${e}. Use portrait|portrait-upside-down|landscape-left|landscape-right.`)}}const Ks={android:`longpress`,apple:`exact`},qs={up:{aliases:[],androidKeyevent:`KEYCODE_DPAD_UP`,appleRemoteButton:`up`},down:{aliases:[],androidKeyevent:`KEYCODE_DPAD_DOWN`,appleRemoteButton:`down`},left:{aliases:[],androidKeyevent:`KEYCODE_DPAD_LEFT`,appleRemoteButton:`left`},right:{aliases:[],androidKeyevent:`KEYCODE_DPAD_RIGHT`,appleRemoteButton:`right`},select:{aliases:[`ok`,`center`,`enter`],androidKeyevent:`KEYCODE_DPAD_CENTER`,appleRemoteButton:`select`},menu:{aliases:[],androidKeyevent:`KEYCODE_MENU`,appleRemoteButton:`menu`},home:{aliases:[],androidKeyevent:`KEYCODE_HOME`,appleRemoteButton:`home`},back:{aliases:[],androidKeyevent:`KEYCODE_BACK`,appleRemoteButton:`menu`}},$=Object.keys(qs),Js=`<${$.join(`|`)}>`;function Ys(e){let t=e?.toLowerCase();if(Xs(t))return t;let r=t?ec.get(t):void 0;if(r)return r;throw new n(`INVALID_ARGS`,`tv-remote button must be one of: ${$.join(`, `)}.`)}function Xs(e){return typeof e==`string`&&$.includes(e)}function Zs(e){return qs[e].appleRemoteButton}function Qs(e){return qs[e].androidKeyevent}function $s(e){return Ks[e]}const ec=new Map($.flatMap(e=>qs[e].aliases.map(t=>[t,e])));export{qi as $,Ne as $n,xr as $t,Oo as A,kn as An,Zr as At,Na as B,Sn as Bn,Lr as Bt,Qo as C,Vn as Cn,_i as Ct,jo as D,zn as Dn,li as Dt,Ao as E,Dn as En,ui as Et,Va as F,In as Fn,qr as Ft,W as G,Mt as Gn,Br as Gt,Ra as H,qt as Hn,Rr as Ht,Ha as I,Fn as In,Fr as It,V as J,C as Jn,Ur as Jt,U as K,jt as Kn,zr as Kt,za as L,jn as Ln,Tr as Lt,Co as M,Mn,Yr as Mt,ho as N,Ln as Nn,Gr as Nt,ko as O,Rn as On,fi as Ot,K as P,Pn,Kr as Pt,R as Q,Ee as Qn,yr as Qt,Fa as R,wn as Rn,Pr as Rt,$o as S,qn as Sn,vi as St,Po as T,P as Tn,mi as Tt,Pa as U,Kt as Un,Ir as Ut,La as V,k as Vn,Dr as Vt,_a as W,Nt as Wn,Er as Wt,z as X,je as Xn,Sr as Xt,B as Y,Ae as Yn,Vr as Yt,da as Z,De as Zn,Cr as Zt,as as _,Hn as _n,xi as _t,Zs as a,dr as an,Ti as at,ss as b,Xn as bn,gi as bt,Gs as c,cr as cn,ji as ct,Us as d,sr as dn,Gi as dt,_r as en,Me as er,Yi as et,Ls as f,hr as fn,Pi as ft,is as g,Un as gn,bi as gt,Ds as h,er as hn,Fi as ht,Qs as i,lr as in,Ei as it,So as j,Nn as jn,Xr as jt,Mo as k,An as kn,di as kt,zs as l,fr as ln,Mi as lt,Os as m,nr as mn,Ni as mt,Js as n,ir as nn,I as nt,$s as o,mr as on,Ai as ot,Is as p,tr as pn,Li as pt,pa as q,O as qn,Hr as qt,Ys as r,ar as rn,wi as rt,Ws as s,ur as sn,ki as st,$ as t,vr as tn,Ji as tt,Rs as u,pr as un,Ii as ut,os as v,Wn as vn,Ci as vt,No as w,N as wn,pi as wt,cs as x,Jn as xn,yi as xt,us as y,Yn as yn,Si as yt,Ia as z,Cn as zn,wr as zt};
|
|
5
|
+
`)}function Ft(e){if(e<1e3)return`${Math.round(e)}ms`;if(e<6e4)return`${(Math.round(e/100)/10).toFixed(1)}s`;let t=e/6e4;if(t<60)return`${(Math.round(t*10)/10).toFixed(1)}m`;let n=t/60;return`${(Math.round(n*10)/10).toFixed(1)}h`}function It(e){let t=typeof e.appName==`string`?e.appName:void 0,n=typeof e.appBundleId==`string`?e.appBundleId:void 0,r=[];return t&&r.push(`Page: ${t}`),n&&r.push(`App: ${n}`),r.length>0?`${r.join(`
|
|
6
|
+
`)}\n`:``}function Lt(e,t,n){let r=n?` (truncated)`:``;return t?.partial?t.totalNodeCount>t.visibleNodeCount?`Snapshot: ${t.visibleNodeCount} visible nodes (${t.totalNodeCount} total)${r}`:`Snapshot: ${t.visibleNodeCount} visible nodes${r}`:`Snapshot: ${e} nodes${r}`}function Rt(e){return e.map(e=>JSON.stringify(e)).join(`
|
|
7
|
+
`)}function zt(e){return vn(e).join(`
|
|
8
|
+
`)}function Bt(e){return hn(w(e,{summarizeTextSurfaces:!0})).join(`
|
|
9
|
+
`)}function Vt(e){return e&&e.summaryLines.length>0?`\n${e.summaryLines.join(`
|
|
10
|
+
`)}`:``}function Ht(e,t,n,r,i=0){let a=Ut(e);if(i===0&&a)return a;let o=(t?.hiddenCount??0)+i,s=t?t.nodes.some(e=>e.hiddenContentAbove||e.hiddenContentBelow):!1;return o>0?{partial:!0,visibleNodeCount:n,totalNodeCount:Math.max(r,a?.totalNodeCount??r),reasons:Wt([...a?.reasons??[],`offscreen-nodes`])}:a||(s?{partial:!0,visibleNodeCount:n,totalNodeCount:n,reasons:[]}:null)}function Ut(e){let t=e.visibility;if(!t||typeof t!=`object`)return null;let n=t;return typeof n.partial!=`boolean`||typeof n.visibleNodeCount!=`number`||typeof n.totalNodeCount!=`number`||!Array.isArray(n.reasons)?null:{partial:n.partial,visibleNodeCount:n.visibleNodeCount,totalNodeCount:n.totalNodeCount,reasons:n.reasons.filter(e=>typeof e==`string`)}}function Wt(e){return[...new Set(e)]}function Gt(e){let t=e.baselineInitialized===!0,n=e.summary??{},r=O(n.additions),i=O(n.removals),a=O(n.unchanged),o=k(),s=mn(e),c=s.length>0?`${s.join(`
|
|
11
|
+
`)}\n`:``;if(t)return`${c}Baseline initialized (${a} lines).\n`;let l=ln(Array.isArray(e.lines)?e.lines:[],1).map(e=>{let t=typeof e.text==`string`?e.text:``;if(e.kind===`added`){let e=t.startsWith(` `)?`+${t}`:`+ ${t}`;return o?A(e,`green`):e}if(e.kind===`removed`){let e=t.startsWith(` `)?`-${t}`:`- ${t}`;return o?A(e,`red`):e}return o?A(t,`dim`):t}),u=l.length>0?`${l.join(`
|
|
12
|
+
`)}\n`:``;return o?`${c}${u}${[`${A(String(r),`green`)} additions`,`${A(String(i),`red`)} removals`,`${A(String(a),`dim`)} unchanged`].join(`, `)}\n`:`${c}${u}${r} additions, ${i} removals, ${a} unchanged\n`}function Kt(e){let t=k(),n=e.match===!0,r=e.dimensionMismatch,i=[];return i.push(...qt(e,t)),i.push(...Jt(e,n,t)),!n&&!r&&(i.push(...Yt(e,t)),i.push(...Xt(e,t)),i.push(...Zt(e,t)),i.push(...$t(e,t)),i.push(...en(e,t))),`${i.join(`
|
|
13
|
+
`)}\n`}function qt(e,t){if(e.match===!0)return[`${t?A(`✓`,`green`):`✓`} Screenshots match.`];let n=e.dimensionMismatch,r=t?A(`✗`,`red`):`✗`;if(n){let e=n.expected,t=n.actual;return[`${r} Screenshots have different dimensions: expected ${e?.width}x${e?.height}, got ${t?.width}x${t?.height}`]}let i=O(e.differentPixels),a=O(e.mismatchPercentage),o=`${a===0&&i>0?`<0.01`:String(a)}% pixels differ`;return[`${r} ${t?A(o,`red`):o}`]}function Jt(e,t,n){if(t)return[];let r=[];if(e.diffPath){let t=cn(e.diffPath),i=n?A(`Diff image:`,`dim`):`Diff image:`,a=n?A(t,`green`):t;r.push(` ${i} ${a}`)}if(e.currentOverlayPath){let t=cn(e.currentOverlayPath),i=n?A(`Current overlay:`,`dim`):`Current overlay:`,a=n?A(t,`green`):t,o=O(e.currentOverlayRefCount),s=o>0?` (${o} refs)`:``;r.push(` ${i} ${a}${s}`)}return r}function Yt(e,t){let n=O(e.differentPixels),r=O(e.totalPixels);return[` ${t?A(String(n),`red`):String(n)} different / ${r} total pixels`]}function Xt(e,t){let n=nn(e);return n.length===0?[]:[` ${j(`Hints:`,t)}`,...n.map(e=>` - ${e}`)]}function Zt(e,t){let n=Array.isArray(e.regions)?e.regions:[];if(n.length===0)return[];let r=[` ${j(`Changed regions:`,t)}`];for(let e of n.slice(0,5))r.push(...Qt(e));return r}function Qt(e){let t=e.shareOfDiffPercentage===0&&e.differentPixels>0?`<0.01`:String(e.shareOfDiffPercentage),n=e.rect,r=[` ${e.index}. ${e.location} x=${n.x} y=${n.y} ${n.width}x${n.height}, ${t}% of diff, change=${e.dominantChange}`],i=sn(e);i&&r.push(` ${i}`);let a=e.currentOverlayMatches?.[0];if(a){let e=a.label?` "${a.label}"`:``;r.push(` overlaps @${a.ref}${e}, ${a.regionCoveragePercentage}% of region`)}return r}function $t(e,t){let n=e.ocr?.matches??[];if(n.length===0)return[];let r=n.slice(0,8),i=[` ${j(`OCR text deltas (${e.ocr?.provider}; baselineBlocks=${e.ocr?.baselineBlocks} currentBlocks=${e.ocr?.currentBlocks}; showing ${r.length}/${n.length}; px):`,t)}`,` ${j(`item | text | movePx | sizeDeltaPx | bboxBaseline | bboxCurrent | confidence | issueHint`,t)}`];for(let[e,t]of r.entries()){let n=t.delta;i.push(` ${e+1} | ${JSON.stringify(t.text)} | ${D(n.x)},${D(n.y)} | ${D(n.width)},${D(n.height)} | ${tn(t.baselineRect)} | ${tn(t.currentRect)} | ${t.confidence} | ${t.possibleTextMetricMismatch?`ocr-bbox-size-change`:`-`}`)}return i}function en(e,t){let n=e.nonTextDeltas??[];if(n.length===0)return[];let r=n.slice(0,8),i=[` ${j(`Non-text visual deltas (showing ${r.length}/${n.length}; px):`,t)}`,` ${j(`item | region | slot | kind | bboxCurrent | nearestText`,t)}`];for(let e of r)i.push(` ${e.index} | ${e.regionIndex?`r${e.regionIndex}`:`-`} | ${e.slot} | ${e.likelyKind} | ${tn(e.rect)} | ${e.nearestText?JSON.stringify(e.nearestText):`-`}`);return i}function tn(e){return`x=${e.x},y=${e.y},w=${e.width},h=${e.height}`}function D(e){return e>0?`+${e}`:String(e)}function nn(e){let t=[],n=e.ocr?.movementClusters??[];for(let e of n.slice(0,2))t.push(`text movement cluster: ${on(e.texts)} dx=${an(e.xRange)}px dy=${an(e.yRange)}px`);let r=(e.nonTextDeltas??[]).filter(e=>[`icon`,`toggle`,`chevron`].includes(e.likelyKind)).slice(0,3);r.length>0&&t.push(`non-text controls: ${r.map(rn).join(`; `)}`);let i=(e.nonTextDeltas??[]).filter(e=>e.likelyKind===`separator`).slice(0,2);return i.length>0&&t.push(`non-text boundaries: ${i.map(rn).join(`; `)}`),t.slice(0,6)}function rn(e){let t=e.nearestText?` near ${JSON.stringify(e.nearestText)}`:``,n=e.regionIndex?` r${e.regionIndex}`:``;return`${e.likelyKind}${t}${n}`}function an(e){return e.min===e.max?D(e.min):`${D(e.min)}..${D(e.max)}`}function on(e){let t=e.slice(0,4).map(e=>JSON.stringify(e)),n=e.length>t.length?` +${e.length-t.length} more`:``;return`${t.join(`, `)}${n}`}function sn(e){let t=[e.size?`size=${e.size}`:null,e.shape?`shape=${e.shape}`:null,typeof e.densityPercentage==`number`?`density=${e.densityPercentage}%`:null,e.averageBaselineColorHex&&e.averageCurrentColorHex?`avgColor=${e.averageBaselineColorHex}->${e.averageCurrentColorHex}`:null,typeof e.baselineLuminance==`number`&&typeof e.currentLuminance==`number`?`luminance=${e.baselineLuminance}->${e.currentLuminance}`:null].filter(e=>e!==null);return t.length>0?t.join(` `):null}function cn(e){let t=process.cwd(),n=Ce.relative(t,e);return n===``||!n.startsWith(`..`)&&!Ce.isAbsolute(n)?n===``?`.`:`.${Ce.sep}${n}`:e}function O(e){return typeof e==`number`&&Number.isFinite(e)?e:0}function ln(e,t){if(e.length===0)return e;let n=e.map((e,t)=>({index:t,kind:e.kind})).filter(e=>e.kind===`added`||e.kind===`removed`).map(e=>e.index);if(n.length===0)return e;let r=Array(e.length).fill(!1);for(let i of n){let n=Math.max(0,i-t),a=Math.min(e.length-1,i+t);for(let e=n;e<=a;e+=1)r[e]=!0}return e.filter((e,t)=>r[t])}function k(e=process.stdout){let t=process.env.FORCE_COLOR;return typeof t==`string`?t!==`0`:typeof process.env.NO_COLOR==`string`?!1:!!e.isTTY}function A(e,t,n){return we(t,e,n)}function j(e,t){return t?A(e,`dim`):e}function un(e,t,n,r={nodes:t,filteredCount:0}){let i=mn(e);if(dn(e)){let e=pn(t,n);e&&i.push(e)}!n.raw&&r.filteredCount>0&&i.push(`Collapsed ${r.filteredCount} Android helper node${r.filteredCount===1?``:`s`} from the agent-facing text snapshot; use --raw or --json for the full hierarchy.`);let a=r.filteredCount>0?r.nodes:t;return!n.raw&&ht(a)&&i.push(`Warning: possible repeated nav subtree detected.`),i}function dn(e){return!e.snapshotQuality&&!fn(e)}function fn(e){let t=e.snapshotDiagnostics;if(!t||typeof t!=`object`)return!1;let n=t.stats;return!!(n&&typeof n==`object`&&n.platform===`web`)}function pn(e,t){if(t.scoped===!0||t.depthLimited===!0||e.length>3)return null;let n=e.length===1?`node`:`nodes`;return`Hint: sparse accessibility snapshot returned ${e.length} ${n}; snapshot state is invalid or unavailable for this screen. Use plain screenshot, not screenshot --overlay-refs, as visual truth. If screenshot shows the Home Screen or another app, run open for this app again first. Then navigate away with coordinates if needed and retry snapshot -i on the next screen.`}function mn(e){let t=e.warnings;return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.length>0):[]}function hn(e){let t=[],n=[],r=new Map(e.map(e=>[e.node.index,e.node])),i=e=>{for(;n.length>0&&(!e||gn(e,n[n.length-1],r));)t.push(...yn(n.pop(),`below`))};for(let r of e)i(r),t.push(r.text),t.push(...yn(r,`above`)),r.node.hiddenContentBelow&&n.push(r);return i(),t}function gn(e,t,n){return _n(e.node,t.node,n)?!1:e.depth<=t.depth}function _n(e,t,n){let r=e;for(;typeof r.parentIndex==`number`;){if(r.parentIndex===t.index)return!0;let e=n.get(r.parentIndex);if(!e)return!1;r=e}return!1}function vn(e){return w(e,{summarizeTextSurfaces:!0}).flatMap(e=>[yt(e.node,0,!1,e.type,{summarizeTextSurfaces:!0}),...yn({...e,depth:0})])}function yn(e,t){let n=bn(e.type);if(!n)return[];let r=[];if(e.node.hiddenContentAbove&&t!==`below`&&r.push(`[content above ${n} hidden]`),e.node.hiddenContentBelow&&t!==`above`&&r.push(`[content below ${n} hidden]`),r.length===0)return[];let i=` `.repeat(e.depth+1);return r.map(e=>`${i}${e}`)}function bn(e){return e===`scroll-area`||e===`list`||e===`collection`||e===`table`?e:null}function xn(e,t={}){let n=k(process.stderr);if(e===`pass`){let e=t.passFormat??`green`;return n?M(`✓`,e):`✓`}return e===`fail`?n?M(`⨯`,`red`):`⨯`:e===`warn`?n?M(`!`,`yellow`):`!`:n?M(`-`,`dim`):`-`}function M(e,t){return A(e,t,{validateStream:!1})}function Sn(e){return`${xn(wn(e.status))} ${Tn(e)}`}function Cn(e){return e.status!==`fail`&&e.status!==`warn`?[]:typeof e.command==`string`?[` run: ${e.command}`]:typeof e.hint==`string`?[` hint: ${e.hint}`]:[]}function wn(e){return e===`pass`?`pass`:e===`fail`?`fail`:e===`warn`?`warn`:`skip`}function Tn(e){let t=typeof e.id==`string`&&e.id.length>0?e.id:`check`,n=typeof e.summary==`string`&&e.summary.length>0?e.summary:t;return n===t?t:`${t}: ${n}`}const En=3e5,Dn=[`leaseId`,`tenantId`,`runId`,`clientId`,`deviceKey`];function On(e){return v({tenantId:e.meta?.tenantId??N(e.flags,`tenant`),runId:e.meta?.runId??N(e.flags,`runId`),leaseId:e.meta?.leaseId??N(e.flags,`leaseId`),leaseTtlMs:e.meta?.leaseTtlMs,leaseBackend:e.meta?.leaseBackend,leaseProvider:e.meta?.leaseProvider??N(e.flags,`leaseProvider`)??N(e.flags,`provider`),deviceKey:e.meta?.deviceKey??N(e.flags,`deviceKey`),clientId:e.meta?.clientId??N(e.flags,`clientId`)})}function kn(e){return v({tenantId:e.tenant,runId:e.runId,leaseId:e.leaseId,leaseTtlMs:e.leaseTtlMs??e.ttlMs,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider??e.provider,deviceKey:e.deviceKey,clientId:e.clientId})}function An(e){return v({tenantId:e.tenantId,runId:e.runId,leaseId:e.leaseId,leaseTtlMs:e.leaseTtlMs,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId})}function jn(e){return v({tenant:e.tenantId,runId:e.runId,leaseId:e.leaseId,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId})}function Mn(e){return v({tenantId:e.tenantId??``,runId:e.runId??``,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId,ttlMs:e.leaseTtlMs})}function Nn(e){return zn(e)}function Pn(e){let{ttlMs:t,...n}=zn(e);return n}function Fn(e,t,n){let r=v({...n.includeTokenParam?{token:n.token}:{},session:n.session,tenantId:e.tenantId,runId:e.runId,leaseProvider:e.leaseProvider,clientId:e.clientId,deviceKey:e.deviceKey});switch(t){case`lease_allocate`:return{...r,...v({ttlMs:e.leaseTtlMs,backend:e.leaseBackend})};case`lease_heartbeat`:return{...r,...v({leaseId:e.leaseId,ttlMs:e.leaseTtlMs})};case`lease_release`:return{...r,...v({leaseId:e.leaseId})}}}function In(e){let t=v({leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId});return Object.keys(t).length>0?t:void 0}function Ln(e){return e.leaseProvider===`proxy`}function Rn(e){return Ln(e)?Dn.filter(t=>!e[t]):[]}function zn(e){return v({leaseId:e.leaseId??``,tenantId:e.tenantId,runId:e.runId,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId,ttlMs:e.leaseTtlMs})}function N(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function P(e){return e?{message:e}:{}}function Bn(e,t){return t?{...e,message:t}:e}function Vn(e){return typeof e?.message==`string`&&e.message.length>0?e.message:null}const Hn=[`out`,`overlayRefs`,`screenshotPixelDensity`,`screenshotFullscreen`,`screenshotMaxSize`,`screenshotNoStabilize`,`screenshotNormalizeStatusBar`],Un=[`screenshotPixelDensity`,`screenshotFullscreen`,`screenshotMaxSize`,`screenshotNoStabilize`,`screenshotNormalizeStatusBar`],Wn=[{key:`screenshotPixelDensity`,names:[`--pixel-density`],type:`int`,min:1,usageLabel:`--pixel-density <n>`,usageDescription:`Screenshot: output PNG pixel density in pixels per logical point (currently supported on iOS simulators)`},{key:`screenshotFullscreen`,names:[`--fullscreen`,`--full`,`-f`],type:`boolean`,usageLabel:`--fullscreen, --full, -f`,usageDescription:`Screenshot: on web capture the full page; on macOS app sessions capture the full desktop instead of the app window`},{key:`screenshotMaxSize`,names:[`--max-size`],type:`int`,min:1,usageLabel:`--max-size <px>`,usageDescription:`Screenshot/record: downscale so the longest edge is at most <px>`},{key:`screenshotNoStabilize`,names:[`--no-stabilize`],type:`boolean`,usageLabel:`--no-stabilize`,usageDescription:`Screenshot: skip Android demo-mode/status-bar stabilization and settle delay for low-latency capture loops`},{key:`screenshotNormalizeStatusBar`,names:[`--normalize-status-bar`],type:`boolean`,usageLabel:`--normalize-status-bar`,usageDescription:`Screenshot: on iOS simulators temporarily normalize status-bar chrome for deterministic screenshot diffs`}],Gn=[{tokens:[`--fullscreen`,`--full`,`-f`],key:`screenshotFullscreen`},{tokens:[`--no-stabilize`],key:`screenshotNoStabilize`},{tokens:[`--normalize-status-bar`],key:`screenshotNormalizeStatusBar`}],Kn=[{token:`--pixel-density`,key:`screenshotPixelDensity`,label:`screenshot --pixel-density`},{token:`--max-size`,key:`screenshotMaxSize`,label:`screenshot --max-size`}];function qn(e){return Zn({overlayRefs:e?.overlayRefs,pixelDensity:e?.screenshotPixelDensity,fullscreen:e?.screenshotFullscreen,maxSize:e?.screenshotMaxSize,stabilize:e?.screenshotNoStabilize?!1:void 0,normalizeStatusBar:e?.screenshotNormalizeStatusBar})}function Jn(e={}){return Zn({overlayRefs:e.overlayRefs,screenshotPixelDensity:e.screenshotPixelDensity??e.pixelDensity,screenshotFullscreen:e.screenshotFullscreen??e.fullscreen,screenshotMaxSize:e.screenshotMaxSize??e.maxSize,screenshotNoStabilize:e.screenshotNoStabilize??(e.stabilize===!1?!0:void 0),screenshotNormalizeStatusBar:e.screenshotNormalizeStatusBar??e.normalizeStatusBar})}function Yn(e,t){typeof t?.screenshotPixelDensity==`number`&&e.push(`--pixel-density`,String(t.screenshotPixelDensity)),t?.screenshotFullscreen&&e.push(`--fullscreen`),typeof t?.screenshotMaxSize==`number`&&e.push(`--max-size`,String(t.screenshotMaxSize)),t?.screenshotNoStabilize&&e.push(`--no-stabilize`),t?.screenshotNormalizeStatusBar&&e.push(`--normalize-status-bar`)}function Xn(e){let{args:t,flags:n,index:r}=e,i=t[r];return Qn(i,n,r)??$n({args:t,index:r,flags:n,token:i})??{handled:!1}}function Zn(e){return Object.fromEntries(Object.entries(e).filter(e=>e[1]!==void 0))}function Qn(e,t,n){let r=Gn.find(t=>t.tokens.some(t=>t===e));if(r)return t[r.key]=!0,{handled:!0,nextIndex:n}}function $n(e){let n=Kn.find(t=>t.token===e.token);if(!n)return;let r=e.args[e.index+1],i=r===void 0?NaN:Number(r);if(!Number.isInteger(i)||i<1)throw new t(`INVALID_ARGS`,`${n.label} requires a positive integer`);return e.flags[n.key]=i,{handled:!0,nextIndex:e.index+1}}function er(e){let t=he(e.quality);return{...e.analysis?{analysis:e.analysis}:{},...e.androidSnapshot?{androidSnapshot:e.androidSnapshot}:{},...e.freshness?{freshness:e.freshness}:{},...t?{quality:t}:{},...e.warnings?{warnings:e.warnings}:{}}}function tr(e){return{...e.androidSnapshot?{androidSnapshot:e.androidSnapshot}:{},...e.quality?{snapshotQuality:e.quality}:{},...e.warnings&&e.warnings.length>0?{warnings:e.warnings}:{}}}function nr(e){let t=rr(e.androidSnapshot),n=Array.isArray(e.warnings)?e.warnings.filter(e=>typeof e==`string`):void 0,r=he(e.snapshotQuality);return tr({...t?{androidSnapshot:t}:{},...r?{quality:r}:{},...n?{warnings:n}:{}})}function rr(e){return typeof e==`object`&&e?e:void 0}function ir(e){let t=e.appId??e.bundleId??e.packageName;return{session:e.session,appId:t,appBundleId:e.bundleId,package:e.packageName}}function ar(e,t,n){return{deviceId:t,deviceName:n,...e===`android`?{serial:t}:e===`ios`?{udid:t}:{}}}function or(e,t={}){let n=t.includeAndroidSerial??!0;return{platform:e.platform,target:e.target,device:e.name,id:e.id,...e.platform===`ios`?{device_udid:e.ios?.udid??e.id,ios_simulator_device_set:e.ios?.simulatorSetPath??null}:{},...e.platform===`android`&&n?{serial:e.android?.serial??e.id}:{}}}function sr(e){return{name:e.name,...e.sessionStateDir?{sessionStateDir:e.sessionStateDir}:{},...e.runnerLogPath?{runnerLogPath:e.runnerLogPath}:{},...or(e.device,{includeAndroidSerial:!1}),createdAt:e.createdAt}}function cr(e){return{platform:e.platform,...e.appleOs?{appleOs:e.appleOs}:{},id:e.id,name:e.name,kind:e.kind,target:e.target,...typeof e.booted==`boolean`?{booted:e.booted}:{}}}function lr(e){return e.bundleId??e.package??e.app}function ur(e){return Bn({app:e.app,appPath:e.appPath,platform:e.platform,...e.appId?{appId:e.appId}:{},...e.bundleId?{bundleId:e.bundleId}:{},...e.package?{package:e.package}:{}},`Installed: ${lr(e)}`)}function dr(e){return e.appName??e.bundleId??e.packageName??e.launchTarget}function fr(e){return Bn({launchTarget:e.launchTarget,...e.appName?{appName:e.appName}:{},...e.appId?{appId:e.appId}:{},...e.bundleId?{bundleId:e.bundleId}:{},...e.packageName?{package:e.packageName}:{},...e.installablePath?{installablePath:e.installablePath}:{},...e.archivePath?{archivePath:e.archivePath}:{},...e.materializationId?{materializationId:e.materializationId}:{},...e.materializationExpiresAt?{materializationExpiresAt:e.materializationExpiresAt}:{}},`Installed: ${dr(e)}`)}function pr(e){let t=e.appName??e.appBundleId??e.session;return Bn({session:e.session,...e.sessionStateDir?{sessionStateDir:e.sessionStateDir}:{},...e.runnerLogPath?{runnerLogPath:e.runnerLogPath}:{},...e.requestLogPath?{requestLogPath:e.requestLogPath}:{},...e.eventLogPath?{eventLogPath:e.eventLogPath}:{},...e.appName?{appName:e.appName}:{},...e.appBundleId?{appBundleId:e.appBundleId}:{},...e.startup?{startup:e.startup}:{},...e.runtime?{runtime:e.runtime}:{},...e.device?or(e.device):{}},t?`Opened: ${t}`:`Opened`)}function mr(e){return{session:e.session,...e.shutdown?{shutdown:e.shutdown}:{},...`provider`in e&&e.provider?{provider:e.provider}:{},...P(e.session?`Closed: ${e.session}`:`Closed`)}}function hr(e){return{nodes:e.nodes,truncated:e.truncated,...e.appName?{appName:e.appName}:{},...e.appBundleId?{appBundleId:e.appBundleId}:{},...e.visibility?{visibility:e.visibility}:{},...tr(gr(e)),...e.unchanged?{unchanged:e.unchanged}:{},...e.snapshotDiagnostics?{snapshotDiagnostics:e.snapshotDiagnostics}:{}}}function gr(e){return{...e,...e.snapshotQuality?{quality:e.snapshotQuality}:{}}}function _r(e,t){return e.includes(t)}function vr(e,n,r={}){let i=n===void 0?void 0:r.normalize?.(n)??n;if(i!==void 0&&_r(e,i))return i;throw new t(`INVALID_ARGS`,(typeof r.message==`function`?r.message(n):r.message)??`Invalid value: ${n}. Use ${e.join(`|`)}.`)}function F(e,t={}){return{values:e,is:t=>_r(e,t),parse:n=>vr(e,n,t)}}const yr=[`app`,`frontmost-app`,`desktop`,`menubar`],br=F(yr,{normalize:e=>e.trim().toLowerCase(),message:e=>`Invalid surface: ${e}. Use ${yr.join(`|`)}.`});function xr(e){return br.parse(e)}const Sr=[`app`,`device`,`system`];function Cr(e){return e===`device`||e===`system`}const wr=[`metrics`,`frames`,`memory`,`cpu`,`trace`],Tr=[`sample`,`snapshot`,`start`,`stop`,`report`],Er=[`profile`],Dr=[`xctrace`,`simpleperf`,`perfetto`,`android-hprof`,`memgraph`],Or=[`android-hprof`,`memgraph`],kr=F(wr),Ar=F(Tr),jr=F(Er),Mr=F(Dr),Nr=F(Or),Pr=`perf area must be metrics, frames, memory, cpu, or trace`,Fr=`perf action must be sample, snapshot, start, stop, or report`,Ir=`perf cpu requires profile`,Lr=`perf --kind must be xctrace, simpleperf, perfetto, android-hprof, or memgraph`,Rr=`perf memory snapshot --kind must be android-hprof or memgraph`,zr=kr.is,Br=Ar.is,Vr=jr.is,Hr=Mr.is,Ur=Nr.is,Wr=[`app launch with Apple-platform launch arguments and Android/iOS simulator clearState`,`runFlow file/inline with when.platform, when.visible, when.notVisible, and limited when.true boolean/platform expressions`,`onFlowStart and onFlowComplete hooks`,`deterministic repeat.times`,`tapOn including optional, index, childOf, label, and absolute/percentage point taps`,`doubleTapOn and longPressOn`,`inputText, focused-field eraseText, and pasteText`,`openLink`,`visibility assertions and extendedWaitUntil`,`scroll and scrollUntilVisible`,`absolute/percentage swipe and swipe.label`,`screenshots`,`keyboard dismiss`,`basic pressKey, back, animation waits, and stopApp`,`ordered trusted runScript file/env scripts with http.post, json, and output variables`],Gr=`https://github.com/callstack/agent-device/issues/558`,Kr=`https://github.com/callstack/agent-device/issues/new`;function qr(){return`Supported subset: ${Jr(Wr)}.`}function Jr(e){return e.length>1?`${e.slice(0,-1).join(`, `)}, and ${e.at(-1)}`:e[0]??``}const Yr=1e4,Xr=2e3,Zr=[`get`,`accept`,`dismiss`,`wait`],Qr=`<wifi|airplane|location> <on|off>`,$r=`location set <lat> <lon>`,ei=`animations <on|off>`,ti=`appearance <light|dark|toggle>`,ni=`faceid <match|nonmatch|enroll|unenroll>`,ri=`touchid <match|nonmatch|enroll|unenroll>`,ii=`fingerprint <match|nonmatch>`,ai=`clear-app-state [app-id]`,oi=`permission <grant|deny|reset> <camera|microphone|photos|contacts|contacts-limited|notifications|calendar|location|location-always|media-library|motion|reminders|siri> [full|limited]`,si=`permission <grant|reset> <accessibility|screen-recording|input-monitoring>`,ci=`macOS supports only settings ${ti} and settings ${si}. wifi|airplane|location|animations remain unsupported on macOS.`,li=[`settings ${Qr}`,`settings ${$r}`,`settings ${ei}`,`settings ${ti}`,`settings ${ni}`,`settings ${ri}`,`settings ${ii}`,`settings ${ai}`,`settings ${oi}`,`settings ${si}`].join(` | `),ui=`settings requires ${Qr}, ${$r}, ${ei}, ${ti}, ${ni}, ${ri}, ${ii}, ${ai}, ${oi}, or ${si}`;function di(e){let t=e.trim().toLowerCase();return t===`appearance`||t===`permission`}function fi(e){return`Unsupported macOS setting: ${e}. ${ci}`}function pi(e,n){if(e===void 0||e.trim()===``)throw new t(`INVALID_ARGS`,`settings location set requires ${n}`);return hi(Number(e),n)}function mi(e){return{latitude:hi(e?.latitude,`latitude`),longitude:hi(e?.longitude,`longitude`)}}function hi(e,n){let r=n===`latitude`?-90:-180,i=n===`latitude`?90:180;if(typeof e!=`number`||!Number.isFinite(e)||e<r||e>i)throw new t(`INVALID_ARGS`,`${n} must be a number from ${r} to ${i}`);return e}const gi=[`primary`,`secondary`,`middle`];function _i(e){return e?.clickButton??`primary`}function vi(e){return e.button===`primary`?null:e.commandLabel===`click`?e.platform!==`macos`&&e.platform!==`linux`?new t(`UNSUPPORTED_OPERATION`,`click --button ${e.button} is supported only on macOS and Linux`):e.platform===`macos`&&e.button===`middle`?new t(`UNSUPPORTED_OPERATION`,`click --button middle is not supported by the macOS runner yet`):typeof e.count==`number`||typeof e.intervalMs==`number`||typeof e.holdMs==`number`||typeof e.jitterPx==`number`||e.doubleTap===!0?new t(`INVALID_ARGS`,`click --button ${e.button} does not support repeat or gesture modifier flags`):null:new t(`INVALID_ARGS`,`--button is supported only for click`)}function yi(e){return e===`primary`?{}:{button:e}}const bi=1e4;function xi(e,n=`scroll accepts either a relative amount or --pixels, not both`){if(e.amount!==void 0&&e.pixels!==void 0)throw new t(`INVALID_ARGS`,n)}function Si(e,n={}){if(e===void 0)return;let r=n.field??`scroll durationMs`,i=n.max??1e4,a=n.invalidMessage??`${r} must be a non-negative integer`;if(!Number.isFinite(e)||!Number.isInteger(e)||e<0)throw new t(`INVALID_ARGS`,a);if(e>i)throw new t(`INVALID_ARGS`,`${r} must be a non-negative integer at most ${i}`);return e}function Ci(e){return typeof e?.durationMs==`number`?e.durationMs:void 0}const wi=[`up`,`down`,`left`,`right`],Ti=[`left`,`right`,`left-edge`,`right-edge`],Ei=[`one-way`,`ping-pong`],Di=F(Ti,{message:`gesture swipe requires left, right, left-edge, or right-edge`}),Oi=F(wi,{message:e=>`Unknown direction: ${e}`});function ki(e){let t=e.direction,n=t===`up`||t===`down`?e.referenceHeight:e.referenceWidth,r=Vi(e.amount),i=e.pixels===void 0?Math.round(n*r):Hi(e.pixels),a=Math.max(1,Math.round(n*.05)),o=Math.max(1,n-a*2),s=Math.max(1,Math.min(i,o)),c=Math.round(s/2),l=Math.round(e.referenceWidth/2),u=Math.round(e.referenceHeight/2),d=(n,r,i,a)=>({direction:t,x1:n,y1:r,x2:i,y2:a,referenceWidth:e.referenceWidth,referenceHeight:e.referenceHeight,amount:e.amount,pixels:s});switch(t){case`up`:return d(l,u-c,l,u+c);case`down`:return d(l,u+c,l,u-c);case`left`:return d(l-c,u,l+c,u);case`right`:return d(l+c,u,l-c,u)}}function Ai(e){Vi(e.amount),e.pixels!==void 0&&Hi(e.pixels)}function ji(e,t){let[n,r,i]=e===`left`?[85,15,50]:e===`right`?[15,85,50]:e===`left-edge`?[99,15,50]:[1,85,50],a=Ii(Pi(t,n,i),t,8),o=Ii(Pi(t,r,i),t,8);return{preset:e,x1:a.x,y1:a.y,x2:o.x,y2:o.y,referenceWidth:t.referenceWidth,referenceHeight:t.referenceHeight}}function Mi(e){return Di.parse(e)}function Ni(e){let t=Ri(e);if(t)return{referenceWidth:t.width,referenceHeight:t.height}}function Pi(e,t,n){return{x:Math.round(e.referenceWidth*t/100),y:Math.round(e.referenceHeight*n/100)}}function Fi(e,t,n){let r=Pi(e,t,n);return{x:I(r.x,0,Math.max(0,Math.round(e.referenceWidth)-1)),y:I(r.y,0,Math.max(0,Math.round(e.referenceHeight)-1))}}function Ii(e,t,n){return{x:Ui(e.x,n,t.referenceWidth),y:Ui(e.y,n,t.referenceHeight)}}function Li(e){return Oi.parse(e)}function Ri(e){let t=e.filter(e=>zi(e.type)&&Bi(e.rect)).map(e=>e.rect).sort((e,t)=>(t?.width??0)*(t?.height??0)-(e?.width??0)*(e?.height??0))[0];if(t)return t;let n=e.map(e=>e.rect).filter(Bi);if(n.length===0)return;let r=Math.max(...n.map(e=>e.x+e.width)),i=Math.max(...n.map(e=>e.y+e.height));if(!(r<=0||i<=0))return{x:0,y:0,width:r,height:i}}function zi(e){if(!e)return!1;let t=e.toLowerCase();return t.includes(`application`)||t.includes(`window`)}function Bi(e){return!!e&&e.width>0&&e.height>0}function Vi(e){if(e===void 0)return .6;if(!Number.isFinite(e)||e<=0)throw new t(`INVALID_ARGS`,`scroll amount must be a positive number`);return e}function Hi(e){if(!Number.isFinite(e)||e<=0)throw new t(`INVALID_ARGS`,`scroll pixels must be a positive integer`);return Math.max(1,Math.round(e))}function Ui(e,t,n){let r=t;return I(e,r,Math.max(r,n-t))}function I(e,t,n){return Math.min(Math.round(n),Math.max(Math.round(t),Math.round(e)))}function L(e,n,r,i){if(!Number.isFinite(e)||!Number.isInteger(e)||e<r||e>i)throw new t(`INVALID_ARGS`,`${n} must be an integer between ${r} and ${i}`);return e}function Wi(e,t,n={}){let r=Yi(e??[]);if(r.length===0)return{canScroll:!1,emptySnapshot:!0,signature:``};let i=fe(r),a=Xi(r,i,t,n),o=ra(a?Qi(r,a.index):r);return a?{canScroll:ea(a,i.get(a.index),t),emptySnapshot:!1,signature:o,scope:ta(a)}:{canScroll:!1,emptySnapshot:!1,signature:o}}async function Gi(e){let{edge:t,target:n={},scope:r,captureNodes:i}=e;try{let e=Wi(await i(r),t,n);return r&&e.emptySnapshot?await Gi({edge:t,target:n,captureNodes:i}):e}catch(e){throw Ji(t,r,e)}}async function Ki(e){let{edge:n,captureState:r,scroll:i}=e,a=await r();a.scope&&(a=await r(a.scope));let o=0,s;for(;a.canScroll;){if(o>=40)throw new t(`COMMAND_FAILED`,`scroll ${n} reached the safety limit before the snapshot showed the edge`,{hint:`The scoped scroll container still reports hidden content. Use a smaller manual scroll + snapshot loop to inspect the current state.`});s=await i(),o+=1,a=await r(a.scope)}return{passes:o,result:s}}function qi(e,t,n,r,i){return t&&n===0?`Already at ${t}; no hidden content ${t===`bottom`?`below`:`above`} detected`:t?`Scrolled to ${t} with ${n} ${e} passes`:i===void 0?r===void 0?`Scrolled ${e}`:`Scrolled ${e} by ${r}`:`Scrolled ${e} by ${i}px`}function Ji(e,n,r){return n?new t(`COMMAND_FAILED`,`Failed to verify scroll ${e} state for scoped container`,{scope:n,hint:`scroll ${e} could not verify the scoped scroll container. Run snapshot -i for the current screen and retry with a visible scroll target.`},r):new t(`COMMAND_FAILED`,`Failed to verify scroll ${e} state`,{hint:`scroll ${e} needs a snapshot showing hidden content ${e===`bottom`?`below`:`above`} before it will move.`},r)}function Yi(e){return e.map((e,t)=>({...e,ref:`ref`in e&&e.ref?e.ref:`e${t+1}`}))}function Xi(e,t,n,r){let i=new Map(e.map(e=>[e.index,e])),a=e.filter(e=>ae(e)&&sa(e.rect));if(a.length===0)return null;let o=Zi(r.nodeIndex,i);if(o)return o;let s=r.point;if(s){let e=a.filter(e=>e.rect&&oa(e.rect,s)).sort(ia);if(e.length>0)return e.find(e=>ea(e,t.get(e.index),n))??e[0]??null}let c=a.filter(e=>ea(e,t.get(e.index),n)).sort(aa);return c.length>0?c[0]??null:a.filter(t=>ie(t,e)).sort(aa)[0]??a.sort(aa)[0]??null}function Zi(e,t){if(e===void 0)return null;let n=t.get(e);for(;n;){if(ae(n)&&sa(n.rect))return n;n=n.parentIndex===void 0?void 0:t.get(n.parentIndex)}return null}function Qi(e,t){let n=new Map(e.map(e=>[e.index,e]));return e.filter(e=>e.index===t||$i(e,t,n))}function $i(e,t,n){let r=e.parentIndex===void 0?void 0:n.get(e.parentIndex);for(;r;){if(r.index===t)return!0;r=r.parentIndex===void 0?void 0:n.get(r.parentIndex)}return!1}function ea(e,t,n){return n===`bottom`?e.hiddenContentBelow===!0||t?.hiddenContentBelow===!0:e.hiddenContentAbove===!0||t?.hiddenContentAbove===!0}function ta(e){return[e.identifier,e.label,e.value].map(e=>typeof e==`string`?e.trim():``).find(na)}function na(e){return e.length>0&&e.length<=80&&!/^(true|false)$/i.test(e)&&!/^\d+$/.test(e)&&!/^\d+%$/.test(e)}function ra(e){return e.map(e=>{let t=e.rect?[`x`,`y`,`width`,`height`].map(t=>ca(e.rect?.[t])).join(`,`):``;return[String(e.index??``),String(e.parentIndex??``),String(e.type??``),String(e.label??``),String(e.value??``),t].join(`|`)}).join(`
|
|
14
|
+
`)}function ia(e,t){return R(e.rect)-R(t.rect)}function aa(e,t){return R(t.rect)-R(e.rect)}function R(e){return e?e.width*e.height:0}function oa(e,t){return t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height}function sa(e){return!!(e&&e.width>0&&e.height>0)}function ca(e){return typeof e==`number`&&Number.isFinite(e)?e.toFixed(1):``}function z(e,t){return{session:t.session,requestId:t.requestId,signal:t.signal??e.signal,metadata:t.metadata}}function B(e){return e.clock?.now()??Date.now()}async function la(e,t){e.clock?await e.clock.sleep(t):await new Promise(e=>setTimeout(e,t))}function V(e){return e&&typeof e==`object`?e:void 0}const ua=[`x`,`y`,`width`,`height`];function H(e){let t=U(e);if(!t)return null;let n=o(t);return!Number.isFinite(n.x)||!Number.isFinite(n.y)?null:n}function U(e){if(!e)return null;let t=Number(e.x),n=Number(e.y),r=Number(e.width),i=Number(e.height);return!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)||r<0||i<0?null:{x:t,y:n,width:r,height:i}}function W(e,t){return!e||!t?!1:ua.every(n=>Math.abs(e[n]-t[n])<=.5)}function da(e){return{x:fa(e.x,e.width),y:fa(e.y,e.height)}}function fa(e,t){if(t<=1)return Math.floor(e);let n=Math.ceil(e),r=Math.floor(e+t-1);return Math.round(Math.min(r,Math.max(n,e+t/2)))}const pa=[`tabbar`,`toolbar`,`navigationbar`,`bottomnavigation`,`bottomnavigationview`,`sheet`,`dialog`,`alert`,`popover`,`menu`],ma=[`button`,`link`,`menuitem`,`tabitem`,`textfield`,`searchfield`,`edittext`,`checkbox`,`radio`,`switch`,`cell`];function ha(e,t={}){if(e.length<2)return e;let n=[...e],r=new Map(n.map(e=>[e.index,e])),i={nodes:n,byIndex:r,overlayPositions:n.flatMap((e,n)=>ba(e,r,t)?[n]:[])},a=!1;for(let[e,r]of n.entries()){if(!ya(r)||!ga(i,e,r,t))continue;a=!0;let o={...r,hittable:!1,interactionBlocked:`covered`,presentationHints:Aa(r.presentationHints)};n[e]=o,i.byIndex.set(o.index,o)}return a?n:e}function G(e){return e.interactionBlocked!==void 0}function ga(e,t,n,r){let i=K(n.rect);if(!i)return null;let a=o(i);for(let o of e.overlayPositions){if(o<=t)continue;let s=e.nodes[o];if(s&&_a(e,o,n,i,a,r))return s}return null}function _a(e,t,n,r,i,a){if(!e.nodes[t])return!1;let o=va(e,t,n,r,a);return!!(o&&g(o,i.x,i.y))}function va(e,t,n,r,i){let a=e.nodes[t];if(!a||!ba(a,e.byIndex,i)||Oa(n,a,e.byIndex))return null;let o=K(a.rect);return!o||W(r,o)||ga(e,t,a,i)?null:o}function ya(e){return K(e.rect)?e.hittable===!0||wa(e)?!0:!!(e.label?.trim()||e.value?.trim()||e.identifier?.trim()):!1}function ba(e,t,n){return!K(e.rect)||Da(e)?!1:Ta(e,pa)||xa(e,t,n)}function xa(e,t,n){return n.isAdditionalOverlayNode?.(e)===!0?!Sa(e,t,n):!1}function Sa(e,t,n){let r=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);){if(Ca(r,n))return!0;i.add(r.index),r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0}return!1}function Ca(e,t){return t.isAdditionalOverlayNode?.(e)===!0&&K(e.rect)!==null&&!Da(e)}function wa(e){return Ta(e,ma)}function Ta(e,t){let n=Ea(e);return t.some(e=>n.includes(e))}function Ea(e){return[e.type,e.role,e.subrole].map(e=>_(e??``)).join(` `)}function Da(e){let t=Ea(e);return t.includes(`application`)||t.includes(`window`)}function Oa(e,t,n){return ka(e,t,n)||ka(t,e,n)}function ka(e,t,n){let r=typeof t.parentIndex==`number`?n.get(t.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);){if(r.index===e.index)return!0;i.add(r.index),r=typeof r.parentIndex==`number`?n.get(r.parentIndex):void 0}return!1}function K(e){let t=U(e);return t&&t.width>0&&t.height>0?t:null}function Aa(e){return Array.from(new Set([...e??[],`covered`]))}function ja(e){return e}function Ma(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x+a.width),i=Math.max(i,a.y+a.height);return{x:t,y:n,width:r-t,height:i-n}}function Na(e,t){return{x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}}function Pa(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.width,t.x+t.width),a=Math.min(e.y+e.height,t.y+t.height);return i<=n||a<=r?0:(i-n)*(a-r)}function Fa(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function Ia(e,t){return(e.x-t.x)**2+(e.y-t.y)**2}function La(e,t,n){return Math.min(Math.max(e,t),n)}const Ra=[`button`,`link`,`menuitem`,`tabitem`,`textfield`,`searchfield`,`securetextfield`,`checkbox`,`radio`,`switch`,`cell`];function za(e,t){return Ba(e,t).node}function Ba(e,t){if(G(t))return{node:t,reason:`covered`};let n=Va(e,t);if(n?.rect&&H(n.rect))return{node:n,reason:`same-rect-descendant`};if(Ha(t)&&t.rect&&H(t.rect))return{node:t,reason:`semantic-target`};let r=ue(e,t);return r?.rect&&!G(r)&&H(r.rect)?Wa(t,r,e)?{node:t,reason:`overly-broad-ancestor`}:{node:r,reason:`hittable-ancestor`}:{node:t,reason:`original`}}function Va(e,t){let n=U(t.rect);if(!n)return null;let r=t,i=new Set;for(;!i.has(r.ref);){i.add(r.ref);let t=e.filter(e=>{if(e.parentIndex!==r.index||!e.hittable||G(e))return!1;let t=U(e.rect);return t?W(t,n):!1});if(t.length!==1)break;r=t[0]}return r===t?null:r}function Ha(e){return[e.type,e.role,e.subrole].map(e=>_(e??``)).some(Ua)}function Ua(e){return e===`tab`||Ra.some(t=>e.includes(t))}function Wa(e,t,n){let r=U(e.rect),i=U(t.rect);if(!r||!i)return!1;let a=Ga(n,r);return!a||!Ka(i,a)?!1:!W(r,i)}function Ga(e,t){let n=o(t),r=e.filter(e=>{let t=(e.type??``).toLowerCase();return t.includes(`application`)||t.includes(`window`)}).map(e=>U(e.rect)).filter(e=>e!==null);if(r.length===0)return null;let i=r.filter(e=>g(e,n.x,n.y));return re(i.length>0?i:r)}function Ka(e,t){let n=Pa(e,t),r=e.width*e.height,i=t.width*t.height;if(n<=0||r<=0||i<=0)return!1;let a=n/i,o=n/r;return a>=.9&&o>=.8}async function q(e,t,n){return await Y(e,t,n.action),t.target.kind===`point`?await Ja(e,t,t.target,n):t.target.kind===`ref`?await Xa(e,t,t.target,n):await Za(e,t,t.target,n)}async function qa(e,t,n){let r=t.session??`default`,i=await e.sessions.get(r);if(!i?.snapshot)return;let a={x:n.x,y:n.y,width:0,height:0},o=ce(i.snapshot.nodes,a);if(!o)return;let s={x:n.x,y:n.y};if(!g(o,s.x,s.y))return`Coordinates (${s.x}, ${s.y}) are outside the last-known viewport (${o.width}x${o.height}). The tap will be forwarded anyway; take a fresh snapshot if the screen changed.`}async function Ja(e,t,n,r){let i=await qa(e,t,n);if(!r.captureEvidenceBaseline)return{kind:`point`,point:{x:n.x,y:n.y},...i?{warning:i}:{}};let a=await Ya(e,t);return{kind:`point`,point:{x:n.x,y:n.y},...a?{preActionNodes:a}:{},...i?{warning:i}:{}}}async function Ya(e,t){try{return(await J(e,t,!0)).snapshot.nodes}catch{return}}async function Xa(e,t,n,r){let i=await oo(e,t,n),a=i.resolved,o=r.promoteToHittableAncestor?to(i.snapshot.nodes,a.node,{action:r.action,label:`Ref ${n.ref}`}):a.node;return no(o,`Ref ${n.ref}`,r.action),fo(o,i.snapshot.nodes,n.ref,r.action),{kind:`ref`,point:co(o,`Ref ${n.ref} not found or has invalid bounds`),target:{kind:`ref`,ref:`@${a.ref}`},...Qa(e,o,i.snapshot.nodes,r.action)}}async function Za(e,n,r,i){let a=s(r.selector),o=await J(e,n,i.requireInteractive),c=_e(eo(o.snapshot.nodes),a,{platform:e.backend.platform,requireRect:!0,requireUnique:!0,disambiguateAmbiguous:!0});if((!c||!c.node.rect)&&i.requireInteractive&&(o=await J(e,n,!1),c=_e(eo(o.snapshot.nodes),a,{platform:e.backend.platform,requireRect:!0,requireUnique:!0,disambiguateAmbiguous:!0})),!c||!c.node.rect){let n=_e(o.snapshot.nodes,a,{platform:e.backend.platform,requireRect:!0,requireUnique:!1});throw n?.node&&G(n.node)?ro({label:`Selector ${n.selector.raw}`,node:n.node,action:i.action,selector:n.selector.raw}):new t(`COMMAND_FAILED`,ve(a,c?.diagnostics??[],{unique:!0}),{hint:be(c?.diagnostics??[])})}let l=i.promoteToHittableAncestor?to(o.snapshot.nodes,c.node,{action:i.action,label:`Selector ${c.selector.raw}`}):c.node;return no(l,`Selector ${c.selector.raw}`,i.action),uo(l,o.snapshot.nodes,c.selector.raw,i.action),{kind:`selector`,point:co(l,`Selector ${c.selector.raw} resolved to invalid bounds`),target:{kind:`selector`,selector:c.selector.raw},...Qa(e,l,o.snapshot.nodes,i.action)}}function Qa(e,t,n,r){return{node:t,selectorChain:xe(t,e.backend.platform,{action:r===`fill`?`fill`:`click`}),refLabel:pe(t,n),...$a(t,r),preActionNodes:n}}function $a(e,t){return e.hittable===!1?{targetHittable:!1,hint:`The resolved element reports hittable: false, so this ${t} may have had no visible effect. Verify with a snapshot, or prefer a @ref or a longer/more specific selector to target the intended element.`}:{}}function eo(e){return e.filter(e=>!G(e))}function to(e,t,n){let r=Ba(e,t);if(r.reason===`covered`)throw ro({label:n.label,node:t,action:n.action});return r.node}function no(e,t,n){if(G(e))throw ro({label:t,node:e,action:n})}function ro(e){return new t(`COMMAND_FAILED`,`${e.label} is covered by another visible element and cannot ${io(e.action)} safely`,{hint:`Use a different visible target, scroll it clear of the overlay, or inspect with snapshot/screenshot before retrying.`,...e.selector?{selector:e.selector}:{},ref:`@${e.node.ref}`,interactionBlocked:e.node.interactionBlocked})}function io(e){switch(e){case`fill`:return`be filled`;case`focus`:return`be focused`;case`longPress`:return`be long-pressed`;default:return`be tapped`}}async function J(e,n,r){if(!e.backend.captureSnapshot)throw new t(`UNSUPPORTED_OPERATION`,`snapshot is not supported by this backend`);let i=n.session??`default`,a=await e.sessions.get(i);if(!a)throw new t(`SESSION_NOT_FOUND`,`No active session. Run open first.`);let o=await e.backend.captureSnapshot(z(e,n),{interactiveOnly:r,includeRects:!0}),s=o.snapshot??{nodes:o.nodes??[],truncated:o.truncated,backend:o.backend,createdAt:B(e)};return await e.sessions.set({...a,snapshot:s}),{snapshot:s}}async function Y(e,n,r){if(e.backend.platform!==`macos`)return;let i=await ao(e,n);if(!(i!==`desktop`&&i!==`menubar`)&&!(i===`menubar`&&(r===`click`||r===`press`)))throw new t(`UNSUPPORTED_OPERATION`,`${r} is not supported on macOS ${i} sessions yet. Open an app session to act, or use the ${i} surface to inspect.`)}async function ao(e,t){return(await e.sessions.get(t.session??`default`))?.metadata?.surface}async function oo(e,n,r){let i=n.session??`default`,a=await e.sessions.get(i);if(!a)throw new t(`SESSION_NOT_FOUND`,`No active session. Run open first.`);if(!a.snapshot)throw new t(`INVALID_ARGS`,`No snapshot in session. Run snapshot first.`);let o=r.fallbackLabel??``,s=so(a.snapshot.nodes,r.ref,{fallbackLabel:o});if(s)return{snapshot:a.snapshot,resolved:s};let c=await J(e,n,!0),l=so(c.snapshot.nodes,r.ref,{fallbackLabel:o});if(!l)throw new t(`COMMAND_FAILED`,`Ref ${r.ref} not found or has no bounds`,{hint:ye});return{...c,resolved:l}}function so(e,r,i){let o=a(r);if(!o)throw new t(`INVALID_ARGS`,`Invalid ref: ${r}`);let s=n(e,o);if(lo(s))return{ref:o,node:s};let c=i.fallbackLabel.length>0?le(e,i.fallbackLabel):null;return lo(c)?{ref:o,node:c}:null}function co(e,n){let r=H(e.rect);if(!r)throw new t(`COMMAND_FAILED`,n);return r}function lo(e){return e?H(e.rect)!==null:!1}function uo(e,t,n,r){mo(e,t,{message:`Selector ${n} resolved to an off-screen element and is not safe to ${r}`,details:{reason:`offscreen_selector`,selector:n},hint:`The element is outside the visible viewport — likely inside a closed drawer, another tab, or scrolled content. Scroll toward it or open its container, take a fresh snapshot, then retry ${r}.`})}function fo(e,t,n,r){mo(e,t,{message:`Ref ${n} is off-screen and not safe to ${r}`,details:{reason:`offscreen_ref`,ref:a(n)},hint:`Use scroll with the direction from the off-screen summary, take a fresh snapshot, then retry ${r} with the new ref or a selector.`})}async function po(e,t,n,r){let i=(await e.sessions.get(t.session??`default`))?.snapshot?.nodes;if(!i||a(n.ref)===null)return{};let o=so(i,n.ref,{fallbackLabel:n.fallbackLabel??``});return o?(no(o.node,`Ref ${n.ref}`,r),fo(o.node,i,n.ref,r),$a(o.node,r)):{}}function mo(e,n,r){let i=e.rect?de(e,n):null;if(!(!e.rect||!i||h(e,n)))throw new t(`COMMAND_FAILED`,r.message,{...r.details,rect:e.rect,viewport:i,hint:r.hint})}function ho(e){let t=Buffer.alloc(16);for(let n of e)_o(t,go(n));return{digest:`ax1:${Se(`sha256`).update(t).update(`\0`).update(String(e.length)).digest(`hex`).slice(0,16)}`,nodeCount:e.length}}function go(e){return Se(`sha256`).update(e.type??``).update(`\0`).update(e.label??``).update(`\0`).update(e.identifier??``).digest().subarray(0,16)}function _o(e,t){for(let n=0;n<e.length;n+=1)e[n]=(e[n]??0)^(t[n]??0)}function X(e){let{digest:t,nodeCount:n}=ho(e),r=e.reduce((e,t)=>t.hittable===!1?e:e+1,0),i=vo(e);return{digest:t,nodeCount:n,interactiveNodeCount:r,...i?{foregroundApp:i}:{}}}function vo(e){for(let t of e)if(t.bundleId)return t.bundleId;for(let t of e)if(t.appName)return t.appName}function yo(e,t){let n=E(e.type??`Element`),r=T(e,n),i=e.enabled===!1?`disabled`:`enabled`,a=e.selected===!0?`selected`:`unselected`,o=e.hittable===!0?`hittable`:`not-hittable`;return[String(t??e.depth??0),n,r,i,a,o].join(`|`)}function bo(e,t,n={}){let r=Co(So(e,n),So(t,n)),i={additions:0,removals:0,unchanged:0};for(let e of r)e.kind===`added`&&(i.additions+=1),e.kind===`removed`&&(i.removals+=1),e.kind===`unchanged`&&(i.unchanged+=1);return{summary:i,lines:r}}function xo(e,t={}){return So(e,t).length}function So(e,t){return t.flatten?e.map(e=>({text:yt(e,0,!1),comparable:yo(e,0),...t.withRefs&&e.ref?{ref:e.ref}:{}})):w(e).map(e=>({text:e.text,comparable:yo(e.node,e.depth),...t.withRefs&&e.node.ref?{ref:e.node.ref}:{}}))}function Co(e,t){let n=e.length,r=t.length,i=n+r,a=new Map,o=[];a.set(1,0);for(let s=0;s<=i;s+=1){o.push(new Map(a));for(let i=-s;i<=s;i+=2){let c=To(a,i,s)?Z(a,i+1):Z(a,i-1)+1,l=c-i;for(;c<n&&l<r&&e[c].comparable===t[l].comparable;)c+=1,l+=1;if(a.set(i,c),c>=n&&l>=r)return wo(o,e,t,n,r)}}return[]}function wo(e,t,n,r,i){let a=[],o=r,s=i;for(let r=e.length-1;r>=0;--r){let i=e[r],c=o-s,l=To(i,c,r)?c+1:c-1,u=Z(i,l),d=u-l;for(;o>u&&s>d;)a.push({kind:`unchanged`,text:n[s-1].text}),--o,--s;if(r===0)break;if(o===u){let e=n[d];a.push({kind:`added`,text:e.text,...e.ref?{ref:e.ref}:{}}),s=d}else a.push({kind:`removed`,text:t[u].text}),o=u}return a.reverse(),a}function To(e,t,n){return t===-n||t!==n&&Z(e,t-1)<Z(e,t+1)}function Z(e,t){return e.get(t)??0}function Eo(e){return e===`text`||e===`label`||e===`any`}async function Do(e,n){let r=n??`default`,i=await e.sessions.get(r);if(!i)throw new t(`SESSION_NOT_FOUND`,`No active session. Run open first.`);if(!i.snapshot)throw new t(`INVALID_ARGS`,`No snapshot in session. Run snapshot first.`);return{sessionName:r,session:i,snapshot:i.snapshot}}async function Oo(e,n,r={updateSession:!0}){let i=e.backend.captureSnapshot;if(!i)throw new t(`UNSUPPORTED_OPERATION`,`snapshot is not supported by this backend`);let a=n.session??`default`,o=await e.sessions.get(a),s=await i(z(e,n),{interactiveOnly:r.interactiveOnly??!1,depth:n.depth,scope:r.scope??n.scope,raw:n.raw,includeRects:r.includeRects}),c=s.snapshot??{nodes:s.nodes??[],truncated:s.truncated,backend:s.backend,...s.quality?{snapshotQuality:s.quality}:{},createdAt:B(e)};return r.updateSession&&o&&!ge(c.snapshotQuality)&&await e.sessions.set({...o,snapshot:c}),{sessionName:a,session:o,snapshot:c}}async function ko(e,t,n){if(e.backend.readText){let r=await e.backend.readText(z(e,{session:t.sessionName}),n);if(r.text.trim())return r.text}return ne(n)}function Ao(e,r,i){let o=a(r);if(!o)throw new t(`INVALID_ARGS`,i.invalidRefMessage);let s=n(e,o)??(i.fallbackLabel.length>0?le(e,i.fallbackLabel):null);if(!s)throw new t(`COMMAND_FAILED`,i.notFoundMessage);return{ref:o,node:s}}const jo=`Settled on a nearly-empty tree — the app may still be loading. Wait for specific content (wait text ...) before interacting.`;async function Mo(e,t,n){let{quietMs:r,timeoutMs:i}=n,a=B(e),o=a+i,s=!1,c=Math.min(300,Math.max(25,r)),l=0,u,d=0,f,p=a;for(;B(e)<o;){let m=await Po(e,t,o-B(e));if(!m)return{settled:!1,stalled:!0,waitedMs:B(e)-a,captures:l,nodeCount:d,lastCapture:f};l+=1,f=m;let h=Fo(m.snapshot.nodes),g=B(e);if(n.resetBudgetOnPrivateAxRecovery===!0&&!s&&No(m.snapshot.snapshotQuality)){s=!0,o=Math.max(o,g+i),p=g,u=h,d=m.snapshot.nodes.length,await la(e,c);continue}if(h!==u)u=h,d=m.snapshot.nodes.length,p=g;else if(l>=2&&g-p>=r)return{settled:!0,stalled:!1,waitedMs:g-a,captures:l,nodeCount:d,lastCapture:f};await la(e,c)}return{settled:!1,stalled:!1,waitedMs:B(e)-a,captures:l,nodeCount:d,lastCapture:f}}function No(e){return e?.state===`recovered`&&e.backend===`private-ax`}async function Po(e,t,n){let r=Oo(e,t,{updateSession:!1,interactiveOnly:!0}),i;try{let e=await Promise.race([r,new Promise(e=>{i=setTimeout(()=>e(void 0),n)})]);return e===void 0&&r.catch(()=>{}),e}finally{i!==void 0&&clearTimeout(i)}}function Fo(e){return e.map(Io).join(`|`)}function Io(e){let t=e.rect?`${Math.round(e.rect.x)},${Math.round(e.rect.y)},${Math.round(e.rect.width)},${Math.round(e.rect.height)}`:``;return`${e.type??``}#${e.label??``}#${e.identifier??``}#${t}`}const Lo=`The UI kept changing for the whole settle budget (animation, carousel, or ticker?), so no settled diff is shown. Raise --timeout, wait for specific content, or take a fresh snapshot.`,Ro=`A snapshot capture stalled past the settle budget, so no settled diff is shown. The action itself succeeded; observe with wait stable or snapshot.`;async function zo(e,t,n){let r=n.quietMs??500,i=n.timeoutMs??1e4,a={settled:!1,waitedMs:0,captures:0,quietMs:r,timeoutMs:i};try{let o=await Mo(e,t,{quietMs:r,timeoutMs:i,resetBudgetOnPrivateAxRecovery:!0}),s={...a,settled:o.settled,waitedMs:o.waitedMs,captures:o.captures};if(!o.lastCapture)return{observation:{...s,hint:o.stalled?Ro:Lo}};let c=await as(e,t,o.lastCapture),l=o.lastCapture.snapshot.nodes;return{observation:{...s,...o.settled&&c?Uo(Vo(n.resolved),l,n.resolved.point):{},...is(o,c,l.length)},settledNodes:l}}catch(e){return{observation:{...a,hint:`Settle observation unavailable (${e instanceof Error?e.message:String(e)}). The action itself succeeded; take a snapshot to observe the result.`}}}}function Bo(e,t){if(!e)return;let n=X(e),r=t!==void 0&&n.digest!==X(t).digest;return{...n,changedFromBefore:r}}function Vo(e){return`preActionNodes`in e&&e.preActionNodes?e.preActionNodes:[]}function Ho(e,t){let n=bo(Qo(e),Qo(t),{flatten:!0,withRefs:!0}),r=n.lines.filter(e=>e.kind!==`unchanged`),i=rs(r).map(e=>({kind:e.kind,text:e.text,...e.ref?{ref:e.ref}:{}}));return{summary:n.summary,lines:i,...r.length>i.length?{truncated:!0}:{}}}function Uo(e,t,n){let r=Ho(e,t);return{diff:r,...Wo(r,t,n)}}function Wo(e,t,n){let r=new Set(e.lines.filter(e=>e.kind===`added`&&e.ref).map(e=>e.ref)),i=$o(t),a=new Map(t.filter(e=>e.ref).map(e=>[e.ref,e]));return[...r].some(e=>e!==void 0&&!i.has(e)&&!Go(a.get(e),n))?{}:qo(t,r)}function Go(e,t){if(!e?.rect||!t)return!1;let{x:n,y:r,width:i,height:a}=e.rect;return t.x>=n&&t.x<=n+i&&t.y>=r&&t.y<=r+a}const Ko=new Set([`application`,`window`]);function qo(e,t){let n=$o(e),r=e.filter(e=>e.ref&&e.interactionBlocked!==`covered`&&!t.has(e.ref)&&!n.has(e.ref)&&!Ko.has(E(e.type??`Element`)));if(r.length===0)return{};let i=r.slice(0,20).map(e=>{let t=E(e.type??`Element`),n=T(e,t);return{ref:e.ref,role:t,...n?{label:n}:{}}});return{tail:i,...r.length>i.length?{tailTruncated:!0}:{}}}const Jo=new Set([`textfield`,`securetextfield`,`textview`,`textarea`,`searchfield`,`edittext`]),Yo={strippedIndexes:new Set,refs:new Set};function Xo(e){let t=new Set(e.filter(e=>_(e.type??``)===`keyboard`).map(e=>e.index));if(t.size===0)return Yo;let n=new Map(e.map(e=>[e.index,e])),r=Zo(e,n,t),i=es(e,n,r);for(let t of Zo(e,n,i))r.add(t);let a=new Set(e.filter(e=>e.ref&&r.has(e.index)).map(e=>e.ref));return{strippedIndexes:new Set([...r].filter(e=>!t.has(e))),refs:a}}function Zo(e,t,n){let r=new Set(n);if(n.size===0)return r;for(let i of e)ns(i,t,n)&&r.add(i.index);return r}function Qo(e){let{strippedIndexes:t}=Xo(e);return t.size===0?e:e.filter(e=>!t.has(e.index))}function $o(e){return Xo(e).refs}function es(e,t,n){let r=new Set;for(let e of n){let n=t.get(e);if(!n||_(n.type??``)!==`keyboard`)continue;let i=ts(n,t);i!==void 0&&r.add(i)}for(let i of r){let a=new Set([i]);e.some(e=>Jo.has(_(e.type??``))&&!n.has(e.index)&&ns(e,t,a))&&r.delete(i)}return r}function ts(e,t){let n=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0;for(;n;){if(_(n.type??``)===`window`)return n.index;n=typeof n.parentIndex==`number`?t.get(n.parentIndex):void 0}}function ns(e,t,n){let r=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0;for(;r;){if(n.has(r.index))return!0;r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0}return!1}function rs(e){if(e.length<=80)return e;let t=e.filter(e=>e.kind===`added`),n=new Set(t.slice(0,80)),r=80-n.size,i=[];for(let t of e)n.has(t)?i.push(t):t.kind===`removed`&&r>0&&(i.push(t),--r);return i}function is(e,t,n){return e.stalled?{hint:Ro}:e.settled?t?n<5?{hint:jo}:{}:{hint:`Settled on a sparse, unreadable tree — the diff is omitted. Use screenshot as visual truth before interacting further.`}:{hint:Lo}}async function as(e,t,n){if(ge(n.snapshot.snapshotQuality))return!1;let r=await e.sessions.get(t.session??`default`);return r?(await e.sessions.set({...r,snapshot:n.snapshot}),!0):!1}function os(e){let t=e.verify===!0;return{verify:t,needsPreActionBaseline:t||e.settle!==void 0,...e.settle===void 0?{}:{settle:e.settle}}}async function ss(e,t,n,r,i){let a=await cs(e,t,n,i);return us({...r,...a})}async function cs(e,t,n,r){if(r.settle!==void 0){let i=await zo(e,t,{...r.settle,resolved:n}),a=r.verify?Bo(i.settledNodes,`preActionNodes`in n?n.preActionNodes:void 0):void 0;return{settle:i.observation,...a?{evidence:a}:{}}}if(!r.verify)return{};let i=await ls(e,t,n);return i?{evidence:i}:{}}async function ls(e,t,n){let r=`preActionNodes`in n?n.preActionNodes:void 0;try{let n=X((await J(e,t,!0)).snapshot.nodes),i=r!==void 0&&n.digest!==X(r).digest;return{...n,changedFromBefore:i}}catch{return}}function us(e){let t=e;if(t.targetHittable!==!1||!ds(t)||t.hint===void 0)return e;let{hint:n,...r}=t;return r}function ds(e){if(e.evidence?.changedFromBefore===!0)return!0;let t=e.settle?.diff?.summary;return!!t&&(t.additions>0||t.removals>0)}const fs=[`up`,`down`,`left`,`right`,`top`,`bottom`],ps=async(e,n)=>{let r=await q(e,n,{action:`focus`,requireInteractive:!0,promoteToHittableAncestor:!1});if(!e.backend.focus)throw new t(`UNSUPPORTED_OPERATION`,`focus is not supported by this backend`);let i=ws(r),a=V(await e.backend.focus(z(e,n),i));return{...r,...a?{backendResult:a}:{},...P(`Focused (${i.x}, ${i.y})`)}},ms=async(e,n)=>{let r=os(n),i=await q(e,n,{action:`longPress`,requireInteractive:!0,promoteToHittableAncestor:!0,captureEvidenceBaseline:r.needsPreActionBaseline});if(!e.backend.longPress)throw new t(`UNSUPPORTED_OPERATION`,`longPress is not supported by this backend`);let a=n.durationMs===void 0?void 0:L(n.durationMs,`durationMs`,0,12e4),o=ws(i),s=V(await e.backend.longPress(z(e,n),o,{durationMs:a}));return await ss(e,n,i,{...i,...a===void 0?{}:{durationMs:a},...s?{backendResult:s}:{},...P(`Long pressed (${o.x}, ${o.y})`)},r)},hs=async(e,n)=>{if(!e.backend.scroll)throw new t(`UNSUPPORTED_OPERATION`,`scroll is not supported by this backend`);let r=Ss(n.direction),i=ks(n.amount,`scroll amount`),a=js(n.pixels,`scroll pixels`),o=Si(n.durationMs);xi({amount:i,pixels:a},`scroll accepts either amount or pixels, not both`);let s=await ys(e,n),c=s.kind===`viewport`?{kind:`viewport`}:{kind:`point`,point:ws(s)},l=e.backend.scroll,u=async()=>await l(z(e,n),c,{direction:r.direction,...i===void 0?{}:{amount:i},...a===void 0?{}:{pixels:a},...o===void 0?{}:{durationMs:o}}),d,f=0;if(r.edge){let t=r.edge,i=Cs(s),a=await Ki({edge:t,captureState:async r=>await Ts(e,n,t,i,r),scroll:u});d=a.result,f=a.passes}else d=await u(),f=1;let p=V(d),m=Ci(p);return{...s,direction:r.direction,...r.edge?{edge:r.edge,passes:f}:{},...i===void 0?{}:{amount:i},...a===void 0?{}:{pixels:a},...m===void 0?{}:{durationMs:m},...p?{backendResult:p}:{},...P(qi(r.direction,r.edge,f,i,a))}},gs=async(e,n)=>{if(!e.backend.swipe)throw new t(`UNSUPPORTED_OPERATION`,`swipe is not supported by this backend`);if(n.preset)return await _s(e,n,e.backend.swipe);let r=await bs(e,n),i=xs(r.point,n),a=n.durationMs===void 0?void 0:L(n.durationMs,`durationMs`,16,1e4),o=V(await e.backend.swipe(z(e,n),r.point,i.point,{durationMs:a}));return{kind:`swipe`,from:r.point,to:i.point,...i.direction?{direction:i.direction}:{},...i.distance===void 0?{}:{distance:i.distance},...a===void 0?{}:{durationMs:a},...r.target?{fromTarget:r.target}:{},...o?{backendResult:o}:{},...P(`Swiped`)}};async function _s(e,n,r){if(n.from||n.to||n.direction||n.distance!==void 0)throw new t(`INVALID_ARGS`,`gesture swipe preset cannot be combined with from, to, direction, or distance`);let i=Mi(n.preset);await Y(e,n,`swipe`);let a=ji(i,Ns((await J(e,n,!1)).snapshot.nodes)),o=n.durationMs===void 0?void 0:L(n.durationMs,`durationMs`,16,1e4),s={x:a.x1,y:a.y1},c={x:a.x2,y:a.y2},l=V(await r(z(e,n),s,c,{durationMs:o}));return{kind:`swipe`,from:s,to:c,preset:i,...o===void 0?{}:{durationMs:o},fromTarget:{kind:`viewport`},...l?{backendResult:l}:{},...P(`Swiped ${i}`)}}const vs=async(e,n)=>{if(!e.backend.pinch)throw new t(`UNSUPPORTED_OPERATION`,`pinch is not supported by this backend`);await Y(e,n,`pinch`);let r=As(n.scale,`pinch scale`),i=n.center?await q(e,{...n,target:n.center},{action:`pinch`,requireInteractive:!1,promoteToHittableAncestor:!1}):void 0,a=V(await e.backend.pinch(z(e,n),{scale:r,...i?{center:i.point}:{}}));return{kind:`pinch`,scale:r,...i?{center:i.point,centerTarget:i}:{},...a?{backendResult:a}:{},...P(`Pinched to scale ${r}`)}};async function ys(e,t){let n=t.target??{kind:`viewport`};return n.kind===`viewport`?(await Y(e,t,`scroll`),{kind:`viewport`}):await q(e,{...t,target:n},{action:`scroll`,requireInteractive:!1,promoteToHittableAncestor:!1})}async function bs(e,n){if(n.from){if(Os(n.from))return await Y(e,n,`swipe`),{point:Ds(n.from,`from`)};let t=await q(e,{...n,target:n.from},{action:`swipe`,requireInteractive:!1,promoteToHittableAncestor:!1});return{point:ws(t),target:t}}if(!n.direction)throw new t(`INVALID_ARGS`,`swipe requires from+to or a direction`);return await Y(e,n,`swipe`),{point:o(Ms((await J(e,n,!1)).snapshot.nodes)),target:{kind:`viewport`}}}function xs(e,t){if(t.to)return{point:Ds(t.to,`to`)};let n=Es(t.direction,`swipe direction`),r=As(t.distance??200,`swipe distance`);switch(n){case`up`:return{point:{x:e.x,y:e.y-r},direction:n,distance:r};case`down`:return{point:{x:e.x,y:e.y+r},direction:n,distance:r};case`left`:return{point:{x:e.x-r,y:e.y},direction:n,distance:r};case`right`:return{point:{x:e.x+r,y:e.y},direction:n,distance:r}}}function Ss(e){return e===`bottom`?{direction:`down`,edge:`bottom`}:e===`top`?{direction:`up`,edge:`top`}:{direction:Es(e,`scroll direction`)}}function Cs(e){return e.kind===`viewport`?{}:{point:e.point,nodeIndex:`node`in e?e.node?.index:void 0}}function ws(e){if(!e.point)throw new t(`COMMAND_FAILED`,`Interaction target resolved without coordinates`);return e.point}async function Ts(e,n,r,i,a){if(!e.backend.captureSnapshot)throw new t(`UNSUPPORTED_OPERATION`,`scroll ${r} requires snapshot support to verify hidden content before scrolling`);let{captureSnapshot:o}=e.backend;return await Gi({edge:r,target:i,scope:a,captureNodes:async t=>{let r=await o(z(e,n),{scope:t});return r.snapshot?.nodes??r.nodes??[]}})}function Es(e,n){switch(e){case`up`:case`down`:case`left`:case`right`:return e;default:throw new t(`INVALID_ARGS`,`${n} must be up, down, left, or right`)}}function Ds(e,n){let r=Number(e.x),i=Number(e.y);if(!Number.isFinite(r)||!Number.isFinite(i))throw new t(`INVALID_ARGS`,`${n} point requires finite x and y`);return{x:r,y:i}}function Os(e){return`x`in e&&`y`in e}function ks(e,t){return e===void 0?void 0:As(e,t)}function As(e,n){if(!Number.isFinite(e)||e<=0)throw new t(`INVALID_ARGS`,`${n} must be a positive number`);return e}function js(e,n){if(e!==void 0){if(!Number.isFinite(e)||!Number.isInteger(e)||e<=0)throw new t(`INVALID_ARGS`,`${n} must be a positive integer`);return e}}function Ms(e){let n=e.filter(t=>ie(t,e)).map(e=>e.rect).filter(Ps),r=n.length>0?n:e.map(e=>e.rect).filter(Ps);if(r.length===0)throw new t(`COMMAND_FAILED`,`Cannot infer viewport for directional swipe`);let i=Math.min(...r.map(e=>e.x)),a=Math.min(...r.map(e=>e.y)),o=Math.max(...r.map(e=>e.x+e.width)),s=Math.max(...r.map(e=>e.y+e.height));return{x:i,y:a,width:o-i,height:s-a}}function Ns(e){let t=Ms(e);return{referenceWidth:t.width,referenceHeight:t.height}}function Ps(e){return!!(e&&e.width>0&&e.height>0)}const Fs=/^e\d+$/;function Is(e){if(e[0]?.startsWith(`@`)){let t=Gs(e.slice(1));return{ref:e[0],...t===void 0?{}:{label:t}}}if(Fs.test(e[0]??``))throw new t(`INVALID_ARGS`,`Did you mean "@${e[0]}"? Snapshot refs need the @ prefix.`);let n=d(e);if(n){if(n.rest.length>0)throw new t(`INVALID_ARGS`,Hs(e,n));return{selector:n.selectorExpression}}return Rs(e)}function Ls(e){let n=e[0];if(n?.startsWith(`@`)){let t=e.length>=3?e.slice(2).join(` `):e.slice(1).join(` `);return{kind:`ref`,target:{ref:n,label:e.length>=3?Gs(e.slice(1,2)):void 0},text:t}}if(Fs.test(n??``))throw new t(`INVALID_ARGS`,`Did you mean "@${n}"? Snapshot refs need the @ prefix.`);let r=d(e,{preferTrailingValue:!0});return r?{kind:`selector`,target:{selector:r.selectorExpression},text:r.rest.join(` `)}:{kind:`point`,target:Rs(e.slice(0,2)),text:e.slice(2).join(` `)}}function Rs(e){let n=e[0]??``,r=l(n);if(r){let i=zs(n)?r.value:[r.value,...e.slice(1)].join(` `).trim();throw new t(`INVALID_ARGS`,Bs({key:r.key,value:i}))}let i=Number(e[0]),a=Number(e[1]);if(Number.isFinite(i)&&Number.isFinite(a))return{x:i,y:a};throw new t(`INVALID_ARGS`,Vs(e))}function zs(e){let t=e.slice(e.indexOf(`=`)+1).trim();if(t.length<2)return!1;let n=t[0];return(n===`"`||n===`'`)&&t.endsWith(n)}function Bs(e){let{key:t,value:n}=e;return`Unknown selector key "${t}". Supported: ${p.join(`, `)}. ${f(t)?`Did you mean role=${t} label=${Ws(n)}?`:`Did you mean label=${Ws(n)}?`}`}function Vs(e){let t=e.filter(e=>e!==void 0).join(` `);if(!t.trim())return`Missing target. Pass an @ref from snapshot, a selector like text="Sign in", or "x y" coordinates.`;let n=`Target "${t}" is not a @ref, selector, or "x y" point.`;return e.some(e=>c(e??``))?`${n} Selector values with spaces need quotes, e.g. text="Sign in".`:`${n} To match by visible text, use text=${Ws(t)} (or label=/id=/role=), or pass an @ref from snapshot.`}function Hs(e,t){return`${`Selector ${t.selectorExpression} is followed by unexpected extra arguments: "${t.rest.join(` `)}".`} Selector values with spaces need quotes, e.g. ${Us(e,t)??`text="Sign in"`}.`}function Us(e,t){let n=e.length-t.rest.length,r=e[n-1];if(r===void 0)return;let i=r.indexOf(`=`);if(i<=0)return;let a=[r.slice(i+1),...t.rest].join(` `),o=`${r.slice(0,i+1)}${Ws(a)}`;return[...e.slice(0,n-1),o].join(` `)}function Ws(e){return`"${e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`)}"`}function Gs(e){return e.join(` `).trim()||void 0}function Ks(e,n){let r=e===void 0?NaN:Number(e);if(!Number.isInteger(r)||r<1)throw new t(`INVALID_ARGS`,`viewport ${n} must be a positive integer`);return r}const qs=[`path`,`start`,`stop`,`doctor`,`mark`,`clear`],Js=[`medium`,`high`],Ys=`medium`;function Xs(e){return Js.includes(e)}function Zs(e){let t=typeof e==`number`?e:Qs(e);return t!==void 0&&Number.isInteger(t)&&t>=5&&t<=10?t:void 0}function Qs(e){return typeof e==`string`&&/^\d+$/.test(e)?Number(e):void 0}function $s(e){if(Xs(e))return e;let t=Zs(e);if(t!==void 0)return t<=7?`medium`:`high`}const ec=[`portrait`,`portrait-upside-down`,`landscape-left`,`landscape-right`];function tc(e){if(e===void 0)throw new t(`INVALID_ARGS`,`rotate requires an orientation argument. Use portrait|portrait-upside-down|landscape-left|landscape-right.`);switch(e?.trim().toLowerCase()){case`portrait`:return`portrait`;case`portrait-upside-down`:case`upside-down`:return`portrait-upside-down`;case`landscape-left`:case`left`:return`landscape-left`;case`landscape-right`:case`right`:return`landscape-right`;default:throw new t(`INVALID_ARGS`,`Invalid rotation: ${e}. Use portrait|portrait-upside-down|landscape-left|landscape-right.`)}}const nc={android:`longpress`,apple:`exact`},Q={up:{aliases:[],androidKeyevent:`KEYCODE_DPAD_UP`,appleRemoteButton:`up`},down:{aliases:[],androidKeyevent:`KEYCODE_DPAD_DOWN`,appleRemoteButton:`down`},left:{aliases:[],androidKeyevent:`KEYCODE_DPAD_LEFT`,appleRemoteButton:`left`},right:{aliases:[],androidKeyevent:`KEYCODE_DPAD_RIGHT`,appleRemoteButton:`right`},select:{aliases:[`ok`,`center`,`enter`],androidKeyevent:`KEYCODE_DPAD_CENTER`,appleRemoteButton:`select`},menu:{aliases:[],androidKeyevent:`KEYCODE_MENU`,appleRemoteButton:`menu`},home:{aliases:[],androidKeyevent:`KEYCODE_HOME`,appleRemoteButton:`home`},back:{aliases:[],androidKeyevent:`KEYCODE_BACK`,appleRemoteButton:`menu`}},$=Object.keys(Q),rc=`<${$.join(`|`)}>`;function ic(e){let n=e?.toLowerCase();if(ac(n))return n;let r=n?lc.get(n):void 0;if(r)return r;throw new t(`INVALID_ARGS`,`tv-remote button must be one of: ${$.join(`, `)}.`)}function ac(e){return typeof e==`string`&&$.includes(e)}function oc(e){return Q[e].appleRemoteButton}function sc(e){return Q[e].androidKeyevent}function cc(e){return nc[e]}const lc=new Map($.flatMap(e=>Q[e].aliases.map(t=>[t,e])));export{Gi as $,vr as $t,Eo as A,jn as An,Yr as At,ja as B,Kt as Bn,Rr as Bt,os as C,Bn as Cn,mi as Ct,ko as D,kn as Dn,di as Dt,Oo as E,Ln as En,fi as Et,za as F,An as Fn,Tr as Ft,G,k as Gn,Hr as Gt,Ia as H,Mt as Hn,Er as Ht,Ba as I,Cn as In,Pr as It,H as J,Ae as Jn,Sr as Jt,W as K,w as Kn,Ur as Kt,La as L,Sn as Ln,wr as Lt,xo as M,Nn as Mn,Kr as Mt,po as N,Fn as Nn,qr as Nt,Do as O,On,Zr as Ot,q as P,Pn,Fr as Pt,z as Q,je as Qn,_r as Qt,Na as R,xn as Rn,Lr as Rt,ss as S,P as Sn,pi as St,Mo as T,Rn as Tn,li as Tt,Ma as U,jt as Un,Br as Ut,Fa as V,Gt as Vn,Ir as Vt,ha as W,At as Wn,zr as Wt,B as X,Te as Xn,yr as Xt,V as Y,Ee as Yn,Cr as Yt,la as Z,Me as Zn,xr as Zt,ps as _,Yn as _n,Si as _t,oc as a,ur as an,Ti as at,hs as b,qn as bn,vi as bt,tc as c,pr as cn,ji as ct,$s as d,tr as dn,Li as dt,ir as en,qi as et,qs as f,nr as fn,Mi as ft,fs as g,Wn as gn,Ci as gt,Is as h,Hn as hn,xi as ht,sc as i,mr as in,Ei as it,bo as j,In as jn,Gr as jt,Ao as k,Mn as kn,Xr as kt,Ys as l,sr as ln,I as lt,Ls as m,Un as mn,bi as mt,rc as n,lr as nn,L as nt,cc as o,cr as on,Ai as ot,Ks as p,er as pn,Fi as pt,da as q,ke as qn,Vr as qt,ic as r,dr as rn,wi as rt,ec as s,fr as sn,ki as st,$ as t,ar as tn,Ki as tt,Js as u,hr as un,Ni as ut,ms as v,Xn as vn,gi as vt,jo as w,En as wn,ui as wt,gs as x,Vn as xn,_i as xt,vs as y,Jn as yn,yi as yt,Pa as z,A as zn,Dr as zt};
|
package/dist/src/web.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";import{F as t}from"./sdk-android-adb.js";import{n}from"./provider.js";function r(){let e=()=>n();return{open:(t,n)=>e().open(n?.url??t,{url:n?.url}),openDevice:()=>e().open(`about:blank`),close:t=>e().close(t),tap:(t,n)=>e().click(t,n),doubleTap:()=>i(`doubleTap`),swipe:()=>i(`swipe`),pan:()=>i(`pan`),fling:()=>i(`fling`),longPress:()=>i(`longPress`),focus:(t,n)=>e().click(t,n),type:(t,n)=>e().typeText(t,{delayMs:n}),fill:(t,n,r,i)=>e().fill(t,n,r,{delayMs:i}),scroll:(t,n)=>e().scroll(t,n),pinch:()=>i(`pinch`),screenshot:(t,n)=>e().screenshot(t,n),setViewport:(t,n)=>e().setViewport(t,n),snapshot:async n=>{let r=await t(`snapshot_capture`,async()=>await e().snapshot(n),{backend:`web`});return{nodes:r.nodes,truncated:r.truncated??!1,backend:`web`}},back:()=>i(`back`),home:()=>i(`home`),rotate:()=>i(`rotate`),rotateGesture:()=>i(`rotateGesture`),transformGesture:()=>i(`transformGesture`),appSwitcher:()=>i(`appSwitcher`),tvRemote:()=>i(`tvRemote`),readClipboard:()=>i(`readClipboard`),writeClipboard:()=>i(`writeClipboard`),setSetting:()=>i(`setSetting`)}}async function i(t){throw new e(`UNSUPPORTED_OPERATION`,`${t} is not supported on web`)}export{r as createWebInteractor};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-device",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.3",
|
|
4
4
|
"description": "Agent-native CLI for AI app automation across iOS, Android, tvOS, Android TV, macOS, Linux, and web.",
|
|
5
5
|
"mcpName": "io.github.callstackincubator/agent-device",
|
|
6
6
|
"license": "MIT",
|
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
"build": "tsdown",
|
|
74
74
|
"clean:daemon": "node --experimental-strip-types scripts/clean-daemon.ts",
|
|
75
75
|
"daemon:state-dir": "node --experimental-strip-types scripts/print-daemon-state-dir.ts",
|
|
76
|
+
"explain:command": "node --experimental-strip-types scripts/explain-command.ts",
|
|
76
77
|
"clean:xcuitest": "node scripts/clean-xcuitest-derived.mjs",
|
|
77
78
|
"clean:xcuitest:ios": "node scripts/clean-xcuitest-derived.mjs ios",
|
|
78
79
|
"clean:xcuitest:macos": "node scripts/clean-xcuitest-derived.mjs macos",
|
|
@@ -94,6 +95,7 @@
|
|
|
94
95
|
"build:android-multitouch-helper": "sh ./scripts/build-android-multitouch-helper.sh $(node -p \"require('./package.json').version\") .tmp/android-multitouch-helper",
|
|
95
96
|
"package:android-multitouch-helper": "sh ./scripts/package-android-multitouch-helper.sh $(node -p \"require('./package.json').version\") .tmp/android-multitouch-helper",
|
|
96
97
|
"package:android-multitouch-helper:npm": "rm -rf android-multitouch-helper/dist && sh ./scripts/package-android-multitouch-helper.sh $(node -p \"require('./package.json').version\") android-multitouch-helper/dist",
|
|
98
|
+
"build:android": "pnpm package:android-snapshot-helper:npm && pnpm package:android-multitouch-helper:npm",
|
|
97
99
|
"build:macos-helper": "swift build -c release --package-path macos-helper",
|
|
98
100
|
"build:all": "pnpm build:node && pnpm build:xcuitest",
|
|
99
101
|
"ad": "node bin/agent-device.mjs",
|
|
@@ -110,12 +112,17 @@
|
|
|
110
112
|
"fallow:all": "fallow --summary",
|
|
111
113
|
"fallow:baseline": "(fallow dead-code --save-baseline fallow-baselines/dead-code.json --summary || true) && (fallow health --save-baseline fallow-baselines/health.json --summary || true)",
|
|
112
114
|
"check:fallow": "fallow audit",
|
|
113
|
-
"check:
|
|
115
|
+
"check:affected": "node --experimental-strip-types scripts/check-affected/run.ts",
|
|
116
|
+
"check:affected:test": "node --experimental-strip-types --test scripts/check-affected/model.test.ts scripts/check-affected/run.test.ts",
|
|
117
|
+
"check:layering": "node --experimental-strip-types --test scripts/layering/model.test.ts && node --experimental-strip-types scripts/layering/check.ts",
|
|
118
|
+
"check:layering:baseline": "node --experimental-strip-types scripts/layering/check.ts --update-baseline",
|
|
119
|
+
"check:production-exports": "fallow dead-code --config fallow-production-exports.json --production --unused-exports --baseline fallow-baselines/production-unused-exports.json --fail-on-issues",
|
|
120
|
+
"check:production-exports:baseline": "fallow dead-code --config fallow-production-exports.json --production --unused-exports --save-baseline fallow-baselines/production-unused-exports.json --summary",
|
|
114
121
|
"check:quick": "pnpm lint && pnpm typecheck",
|
|
115
122
|
"sync:mcp-metadata": "node scripts/sync-mcp-metadata.mjs",
|
|
116
123
|
"check:mcp-metadata": "node scripts/sync-mcp-metadata.mjs --check",
|
|
117
124
|
"version": "node scripts/sync-mcp-metadata.mjs && git add server.json",
|
|
118
|
-
"check:tooling": "pnpm lint && pnpm typecheck && pnpm check:layering && pnpm check:mcp-metadata && pnpm build",
|
|
125
|
+
"check:tooling": "pnpm lint && pnpm typecheck && pnpm check:layering && pnpm check:production-exports && pnpm check:mcp-metadata && pnpm build",
|
|
119
126
|
"check:unit": "pnpm test:unit && pnpm test:smoke",
|
|
120
127
|
"check": "pnpm check:tooling && pnpm check:fallow && pnpm check:unit",
|
|
121
128
|
"prepack": "pnpm check:mcp-metadata && pnpm build:all && pnpm package:apple-runner:npm && pnpm package:android-snapshot-helper:npm && pnpm package:android-multitouch-helper:npm",
|
|
@@ -136,6 +143,7 @@
|
|
|
136
143
|
"test:integration:provider": "vitest run --project provider-integration",
|
|
137
144
|
"test:integration:progress": "node --experimental-strip-types scripts/integration-progress.ts",
|
|
138
145
|
"test:integration:progress:check": "node --experimental-strip-types scripts/integration-progress.ts --check",
|
|
146
|
+
"test:output-economy": "vitest run --project output-economy",
|
|
139
147
|
"test:smoke:web": "pnpm build && node --test test/integration/smoke-web-platform.test.ts",
|
|
140
148
|
"test:skillgym": "node test/skillgym/runner-environment.ts && pnpm build && skillgym run ./test/skillgym/suites/agent-device-smoke-suite.ts --config ./test/skillgym/skillgym.config.ts",
|
|
141
149
|
"test:skillgym:case": "node test/skillgym/runner-environment.ts && pnpm build && skillgym run ./test/skillgym/suites/agent-device-smoke-suite.ts --config ./test/skillgym/skillgym.config.ts --case",
|
package/server.json
CHANGED
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
"url": "https://github.com/callstack/agent-device",
|
|
8
8
|
"source": "github"
|
|
9
9
|
},
|
|
10
|
-
"version": "0.19.
|
|
10
|
+
"version": "0.19.3",
|
|
11
11
|
"packages": [
|
|
12
12
|
{
|
|
13
13
|
"registryType": "npm",
|
|
14
14
|
"identifier": "agent-device",
|
|
15
|
-
"version": "0.19.
|
|
15
|
+
"version": "0.19.3",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
}
|
package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.2.apk.sha256
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
549ac62f2086d5e94cf74441cc45b33aa008986bcdb7b586d44dfcab8173a81d agent-device-android-multitouch-helper-0.19.2.apk
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
60d183feab3155104cd6e8f9eb3a6193f89483e207497097361856ca53e2dae7 agent-device-android-snapshot-helper-0.19.2.apk
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{F as e}from"./sdk-contracts.js";import{j as t,n,o as r,p as i}from"./sdk-android-adb.js";import{z as a}from"./tv-remote.js";import{E as o}from"./sdk-selectors.js";import s from"node:crypto";import c from"node:fs";import"node:os";import"node:path";import"node:fs/promises";import l from"node:net";function u(e){if(!e)return;let t=/\[(-?\d+),(-?\d+)\]\[(-?\d+),(-?\d+)\]/.exec(e);if(!t)return;let n=Number(t[1]),r=Number(t[2]),i=Number(t[3]),a=Number(t[4]);return{x:n,y:r,width:Math.max(0,i-n),height:Math.max(0,a-r)}}function*d(e){let t=/<node\b[^>]*>/g,n=t.exec(e);for(;n;)yield f(n[0]),n=t.exec(e)}function f(e){let t=ie(e),n=u(t.bounds);return{...t,...n?{rect:n}:{}}}function ee(e,t,n){let{sourceNodes:r,...i}=te(g(e),t,n);return i}function te(e,t,n){let r={nodes:[],sourceNodes:[],...t===void 0?{}:{maxNodes:t},maxDepth:n.depth??1/0,options:n,analysis:Ie(e),interactiveDescendantMemo:new Map,truncated:!1},i=n.scope?Fe(e,n.scope):null,a=i?[i]:e.children;for(let e of a)if(ne(r,e,0),r.truncated)break;let o={nodes:r.nodes,sourceNodes:r.sourceNodes,analysis:r.analysis};return r.truncated?{...o,truncated:!0}:o}function ne(e,t,n,r,i=!1,a=!1){if(e.maxNodes!==void 0&&e.nodes.length>=e.maxNodes){e.truncated=!0;return}if(n>e.maxDepth)return;let o=e.options.raw||De(t,e.options,i,p(e,t),a)?re(e,t,n,r):r,s=i||!!t.hittable,c=a||Ne(t.type);for(let r of t.children)if(ne(e,r,n+1,o,s,c),e.truncated)return}function re(e,t,n,r){let i=e.nodes.length;return e.sourceNodes.push(t),e.nodes.push({index:i,type:t.type??void 0,label:t.label??void 0,value:t.value??void 0,identifier:t.identifier??void 0,bundleId:t.packageName??void 0,rect:t.rect,enabled:t.enabled,focused:t.focused,visibleToUser:t.visibleToUser,hittable:t.hittable,depth:n,parentIndex:r,...t.hiddenContentAbove?{hiddenContentAbove:!0}:{},...t.hiddenContentBelow?{hiddenContentBelow:!0}:{}}),i}function p(e,t){let n=e.interactiveDescendantMemo.get(t);if(n!==void 0)return n;for(let n of t.children)if(n.visibleToUser!==!1&&(n.hittable||p(e,n)))return e.interactiveDescendantMemo.set(t,!0),!0;return e.interactiveDescendantMemo.set(t,!1),!1}function ie(e){let t=ae(e),n=e=>he(t,e),r=e=>{let t=n(e);if(t!==null)return t===`true`},i=e=>{let t=n(e);if(t===null||t.trim()===``)return;let r=Number(t);return Number.isFinite(r)?r:void 0},a=(e,t)=>{let n=i(t);return n===void 0?{}:{[e]:n}},o=(e,t)=>{let r=u(n(t));return r===void 0?{}:{[e]:r}},s=(e,t)=>{let n=r(t);return n===void 0?{}:{[e]:n}};return{text:n(`text`),desc:n(`content-desc`),resourceId:n(`resource-id`),packageName:n(`package`),className:n(`class`),bounds:n(`bounds`),clickable:r(`clickable`),enabled:r(`enabled`),focusable:r(`focusable`),focused:r(`focused`),password:r(`password`),...s(`visibleToUser`,`visible-to-user`),...a(`drawingOrder`,`drawing-order`),...s(`scrollable`,`scrollable`),...s(`canScrollForward`,`can-scroll-forward`),...s(`canScrollBackward`,`can-scroll-backward`),...a(`windowIndex`,`window-index`),...a(`windowType`,`window-type`),...a(`windowLayer`,`window-layer`),...s(`windowActive`,`window-active`),...s(`windowFocused`,`window-focused`),...o(`windowRect`,`window-bounds`)}}function ae(e){let t=new Map,n=e.indexOf(` `),r=e.lastIndexOf(`>`);if(n<0||r<=n)return t;let i=n;for(;i<r;){let n=oe(e,i,r);if(!n)break;t.set(n.name,n.value),i=n.nextCursor}return t}function oe(e,t,n){if(t=m(e,t,n),t>=n||ce(e[t]))return;let r=t;t=se(e,t,n);let i=e.slice(r,t);if(t=m(e,t,n),!i||e[t]!==`=`)return;t=m(e,t+1,n);let a=e[t];if(!le(a))return;let o=t+1,s=e.indexOf(a,o);if(!(s<0||s>=n))return{name:i,value:de(e.slice(o,s)),nextCursor:s+1}}function se(e,t,n){for(;t<n&&!ue(e[t]??``);)t+=1;return t}function m(e,t,n){for(;t<n&&h(e[t]??``);)t+=1;return t}function ce(e){return e===`/`||e===`>`}function le(e){return e===`"`||e===`'`}function h(e){return e===` `||e===`
|
|
2
|
-
`||e===`\r`||e===` `}function ue(e){return e===`=`||e===`/`||e===`>`||h(e)}function de(e){let t=``,n=0;for(;n<e.length;){let r=e.indexOf(`&`,n);if(r<0){t+=e.slice(n);break}t+=e.slice(n,r);let i=e.indexOf(`;`,r+1);if(i<0){t+=e.slice(r);break}let a=e.slice(r+1,i);t+=fe(a)??e.slice(r,i+1),n=i+1}return t}function fe(e){switch(e){case`amp`:return`&`;case`lt`:return`<`;case`gt`:return`>`;case`quot`:return`"`;case`apos`:return`'`;default:return pe(e)}}function pe(e){if(!e.startsWith(`#`))return;let t=e[1]?.toLowerCase()===`x`?16:10,n=t===16?e.slice(2):e.slice(1);if(!n||!me(n,t))return;let r=Number.parseInt(n,t);if(Number.isFinite(r))try{return String.fromCodePoint(r)}catch{return}}function me(e,t){for(let n of e){let e=n.charCodeAt(0),r=e>=48&&e<=57;if(t===10){if(!r)return!1;continue}if(!r&&!(e>=65&&e<=70)&&!(e>=97&&e<=102))return!1}return!0}function he(e,t){return e.get(t)??null}function g(e){let t={type:null,label:null,value:null,identifier:null,packageName:null,depth:-1,children:[]},n=[t],r=/<node\b[^>]*>|<\/node>/g,i=r.exec(e);for(;i;){let t=i[0];if(t.startsWith(`</node`)){n.length>1&&n.pop(),i=r.exec(e);continue}let a=f(t),o=n[n.length-1],s={type:a.className,label:a.text||a.desc,value:a.text,identifier:a.resourceId,packageName:a.packageName,rect:a.rect,enabled:a.enabled,focused:a.focused,visibleToUser:a.visibleToUser,drawingOrder:a.drawingOrder,hittable:a.clickable??a.focusable,scrollable:a.scrollable,canScrollForward:a.canScrollForward,canScrollBackward:a.canScrollBackward,windowIndex:a.windowIndex,windowType:a.windowType,windowLayer:a.windowLayer,windowActive:a.windowActive,windowFocused:a.windowFocused,windowRect:a.windowRect,depth:o.depth+1,parentIndex:void 0,children:[]};o.children.push(s),t.endsWith(`/>`)||n.push(s),i=r.exec(e)}return _(t),Se(t),v(t,{actionableContentMemo:new WeakMap}),xe(t),t}function _(e){let t=0;for(let n of e.children)n.visibleToUser!==!1&&(_(n),e.children[t]=n,t+=1);t<e.children.length&&(e.children.length=t)}function v(e,t){for(let n of e.children)v(n,t);if(e.children.length<2)return;let n=e.children,r=n.filter(e=>_e(e,t));r.length!==0&&(e.children=n.filter(e=>!ge(e,r)))}function ge(e,t){if(e.visibleToUser===!1||e.drawingOrder===void 0||!ye(e))return!1;for(let n of t)if(!(n===e||n.drawingOrder<=e.drawingOrder)&&be(n.rect,e.rect)>=.9)return!0;return!1}function _e(e,t){return e.visibleToUser!==!1&&e.drawingOrder!==void 0&&ye(e)&&(ve(e)||y(e,t))}function ve(e){if(e.visibleToUser===!1)return!1;if(e.hittable)return!0;let t=e.label?.trim()??``;if(t&&!C(t))return!0;let n=e.identifier?.trim()??``;return!!(n&&!C(n))}function y(e,t){let n=t.actionableContentMemo.get(e);if(n!==void 0)return n;let r=e.children.some(e=>e.visibleToUser!==!1&&(!!e.hittable||y(e,t)));return t.actionableContentMemo.set(e,r),r}function ye(e){return!!(e.rect&&e.rect.width>0&&e.rect.height>0)}function be(e,t){let n=t.width*t.height;return n<=0?0:a(e,t)/n}function xe(e){let t=[...e.children];for(;t.length>0;){let e=t.pop();t.push(...e.children),Te(e)&&(e.canScrollBackward&&(e.hiddenContentAbove=!0),e.canScrollForward&&(e.hiddenContentBelow=!0))}}function Se(e){let t=e.children.filter(we);if(t.length<2)return;let n=t.filter(e=>b(e)&&x(e));if(n.length===0)return;let r=Ce(n);e.children=e.children.filter(e=>b(e)?x(e)?r===void 0||e.windowLayer===r:!1:!0)}function Ce(e){let t=e.map(e=>e.windowLayer).filter(e=>e!==void 0);return t.length>0?Math.max(...t):void 0}function we(e){return e.windowIndex!==void 0||e.windowType!==void 0}function b(e){return e.windowType===1}function x(e){return e.windowActive===!0||e.windowFocused===!0}function Te(e){if(!e.scrollable||!o(e.type)||`${e.type??``}`.toLowerCase().includes(`horizontalscrollview`))return!1;let t=Ee(e);return!(t&&t.horizontal>t.vertical&&t.horizontal>16)}function Ee(e){if(!e.rect||e.children.length===0)return null;let t=e.children.map(e=>e.rect).filter(e=>e!==void 0);if(t.length===0)return null;let n=Math.min(...t.map(e=>e.x)),r=Math.max(...t.map(e=>e.x+e.width)),i=Math.min(...t.map(e=>e.y)),a=Math.max(...t.map(e=>e.y+e.height));return{horizontal:Math.max(0,r-n-e.rect.width),vertical:Math.max(0,a-i-e.rect.height)}}function De(e,t,n,r,i){if(e.visibleToUser===!1)return!1;let a=Oe(e);return t.interactiveOnly?ke(e,a,n,r,i):a.isStructural||a.isVisual?Me(e,a,r):!0}function Oe(e){let t=S(e.type),n=!!(e.label&&e.label.trim().length>0),r=!!(e.identifier&&e.identifier.trim().length>0);return{type:t,hasMeaningfulText:n&&!C(e.label??``),hasMeaningfulId:r&&!C(e.identifier??``),isStructural:Pe(t),isVisual:t===`imageview`||t===`imagebutton`}}function ke(e,t,n,r,i){return je(e)?!1:e.focused||e.hittable||o(t.type)&&r?!0:Ae(t,n,r,i)}function Ae(e,t,n,r){return!e.hasMeaningfulText&&!e.hasMeaningfulId||e.isVisual||e.isStructural&&!r?!1:t||n||r}function je(e){return!!(e.rect&&(e.rect.width<=0||e.rect.height<=0))}function Me(e,t,n){return e.hittable||t.hasMeaningfulText||t.hasMeaningfulId?!0:n}function Ne(e){if(!e)return!1;let t=S(e);return t.includes(`recyclerview`)||t.includes(`listview`)||t.includes(`gridview`)}function S(e){return e?e.toLowerCase():``}function Pe(e){let t=e.split(`.`).pop()??e;return t.includes(`layout`)||t===`viewgroup`||t===`view`}function C(e){let t=e.trim();return t?/^[\w.]+:id\/[\w.-]+$/i.test(t):!1}function Fe(e,t){let n=t.toLowerCase(),r=[...e.children],i=0;for(;i<r.length;){let e=r[i++],t=e.label?.toLowerCase()??``,a=e.value?.toLowerCase()??``,o=e.identifier?.toLowerCase()??``;if(t.includes(n)||a.includes(n)||o.includes(n))return e;r.push(...e.children)}return null}function Ie(e){let t=0,n=0,r=[...e.children];for(;r.length>0;){let e=r.pop();t+=1,n=Math.max(n,e.depth),r.push(...e.children)}return{rawNodeCount:t,maxDepth:n}}function w(e){let t={status:[],results:[],currentStatus:null,currentResult:null};for(let n of e.split(/\r?\n/))Le(n,t);return Re(t),{status:t.status,results:t.results}}function Le(e,t){if(e.startsWith(`INSTRUMENTATION_STATUS: `)){t.currentStatus??={},E(e.slice(24),t.currentStatus);return}if(e.startsWith(`INSTRUMENTATION_STATUS_CODE: `)){ze(t);return}if(e.startsWith(`INSTRUMENTATION_RESULT: `)){t.currentResult??={},E(e.slice(24),t.currentResult);return}e.startsWith(`INSTRUMENTATION_CODE: `)&&T(t)}function Re(e){ze(e),T(e)}function ze(e){e.currentStatus&&=(e.status.push(e.currentStatus),null)}function T(e){e.currentResult&&=(e.results.push(e.currentResult),null)}function E(e,t){let n=e.indexOf(`=`);n<0||(t[e.slice(0,n)]=e.slice(n+1))}function D(e){if(e===void 0)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function O(e){if(e===`true`)return!0;if(e===`false`)return!1}function k(t,n,r){if(typeof t!=`number`||!Number.isInteger(t))throw new e(`INVALID_ARGS`,`Android ${r} manifest ${n} must be an integer.`);return t}function A(t,n,r,i){if(t!==r)throw new e(`INVALID_ARGS`,`Android ${i} manifest ${n} must be "${r}".`);return r}const j=`android-snapshot-helper-v1`,M=`uiautomator-xml`,N={"-r":`replace`,"-t":`allowTestPackages`,"-d":`allowDowngrade`,"-g":`grantPermissions`};async function Be(t){let n=await Ge(t.apkPath);if(n!==t.manifest.sha256)throw new e(`COMMAND_FAILED`,`Android snapshot helper APK checksum mismatch`,{apkPath:t.apkPath,expectedSha256:t.manifest.sha256,actualSha256:n})}function Ve(t){if(!t||typeof t!=`object`||Array.isArray(t))throw new e(`INVALID_ARGS`,`Android snapshot helper manifest must be an object.`);let n=t;return{name:F(n.name,`name`,`android-snapshot-helper`),version:L(n.version,`version`),releaseTag:R(n.releaseTag),assetName:R(n.assetName),apkUrl:Ke(n.apkUrl,`apkUrl`),sha256:We(n.sha256),checksumName:R(n.checksumName),packageName:L(n.packageName,`packageName`),versionCode:P(n.versionCode,`versionCode`),instrumentationRunner:L(n.instrumentationRunner,`instrumentationRunner`),minSdk:P(n.minSdk,`minSdk`),targetSdk:n.targetSdk===void 0?void 0:P(n.targetSdk,`targetSdk`),outputFormat:F(n.outputFormat,`outputFormat`,M),statusProtocol:F(n.statusProtocol,`statusProtocol`,j),installArgs:I(n.installArgs)}}function P(e,t){return k(e,t,`snapshot helper`)}function F(e,t,n){return A(e,t,n,`snapshot helper`)}function He(e){return Ue(I(e.installArgs))}function I(t){let n=qe(t,`installArgs`);if(n[0]!==`install`)throw new e(`INVALID_ARGS`,`Android snapshot helper manifest installArgs must start with "install".`);if(n.some(e=>e.includes(`\0`)))throw new e(`INVALID_ARGS`,`Android snapshot helper manifest installArgs must not contain null bytes.`);let r=n.slice(1).find(e=>!Je(e));if(r)throw new e(`INVALID_ARGS`,`Android snapshot helper manifest installArgs contains unsupported install flag "${r}".`);return n}function Ue(t){let n={};for(let r of t.slice(1)){let t=z(r);if(!t)throw new e(`INVALID_ARGS`,`Android snapshot helper manifest installArgs contains unsupported install flag "${r}".`);n[t]=!0}return n}function We(t){let n=L(t,`sha256`).trim().toLowerCase();if(n.length!==64||!Ye(n))throw new e(`INVALID_ARGS`,`Android snapshot helper manifest sha256 must be a 64-character hex string.`);return n}async function Ge(e){return await new Promise((t,n)=>{let r=s.createHash(`sha256`),i=c.createReadStream(e);i.on(`error`,n),i.on(`data`,e=>r.update(e)),i.on(`end`,()=>t(r.digest(`hex`)))})}function L(t,n){if(typeof t!=`string`||t.trim().length===0)throw new e(`INVALID_ARGS`,`Android snapshot helper manifest ${n} is required.`);return t}function R(e){return typeof e==`string`&&e.trim().length>0?e:void 0}function Ke(e,t){return e===null?null:L(e,t)}function qe(t,n){if(!Array.isArray(t)||!t.every(e=>typeof e==`string`))throw new e(`INVALID_ARGS`,`Android snapshot helper manifest ${n} must be a string array.`);return t}function Je(e){return z(e)!==void 0}function z(e){if(Object.hasOwn(N,e))return N[e]}function Ye(e){for(let t of e){let e=t.charCodeAt(0);if(!(e>=48&&e<=57)&&!(e>=97&&e<=102))return!1}return!0}async function Xe(t){let n=B(t),r=await t.adb(H(n),{allowFailure:!0,timeoutMs:n.commandTimeoutMs}),{output:a,cleanupDone:o}=await Ze(t,n,r);if(n.outputPath&&!o&&await it(t.adb,n.outputPath),r.exitCode!==0)throw new e(`COMMAND_FAILED`,`Android snapshot helper failed`,i(r,{helper:a.metadata}));return a}function B(e){let t=V(e.timeoutMs,8e3),n=V(e.packageName,`com.callstack.agentdevice.snapshothelper`);return{waitForIdleTimeoutMs:V(e.waitForIdleTimeoutMs,500),waitForIdleQuietMs:V(e.waitForIdleQuietMs,100),timeoutMs:t,commandTimeoutMs:V(e.commandTimeoutMs,t+5e3),maxDepth:V(e.maxDepth,128),maxNodes:V(e.maxNodes,5e3),packageName:n,runner:V(e.instrumentationRunner,`${n}/.SnapshotInstrumentation`),...e.outputPath?{outputPath:e.outputPath}:{},...e.emitChunks===void 0?{}:{emitChunks:e.emitChunks}}}function V(e,t){return e===void 0?t:e}function H(e){return[`shell`,`am`,`instrument`,`-w`,`-e`,`waitForIdleTimeoutMs`,String(e.waitForIdleTimeoutMs),`-e`,`waitForIdleQuietMs`,String(e.waitForIdleQuietMs),`-e`,`timeoutMs`,String(e.timeoutMs),`-e`,`maxDepth`,String(e.maxDepth),`-e`,`maxNodes`,String(e.maxNodes),...e.outputPath?[`-e`,`outputPath`,e.outputPath]:[],...e.emitChunks===void 0?[]:[`-e`,`emitChunks`,String(e.emitChunks)],e.runner]}async function Ze(e,t,n){try{return{output:at(`${n.stdout}\n${n.stderr}`),cleanupDone:!1}}catch(r){return await Qe(e,t,n,r)}}async function Qe(t,n,r,i){if(i instanceof e&&r.exitCode!==0&&i.details?.helper)throw i;let a=await $e(t,n,r);if(a)return{output:a,cleanupDone:!0};throw new e(`COMMAND_FAILED`,r.exitCode===0?`Android snapshot helper output could not be parsed`:`Android snapshot helper failed before returning parseable output`,{stdout:r.stdout,stderr:r.stderr,exitCode:r.exitCode},i)}async function $e(e,t,n){if(!(n.exitCode!==0||!t.outputPath))return await tt(e.adb,t.outputPath,rt(`${n.stdout}\n${n.stderr}`)??et(t))}function et(e){return{outputFormat:M,waitForIdleTimeoutMs:e.waitForIdleTimeoutMs,waitForIdleQuietMs:e.waitForIdleQuietMs,timeoutMs:e.timeoutMs,maxDepth:e.maxDepth,maxNodes:e.maxNodes,transport:`instrumentation`}}async function tt(e,t,n){let r;try{r=await e(nt(t),{allowFailure:!0,timeoutMs:5e3})}catch{return}if(r.exitCode!==0)return;let i=r.stdout.trim();if(!(!i.includes(`<hierarchy`)||!i.includes(`</hierarchy>`)))return{xml:i,metadata:n}}function nt(e){return[`shell`,`sh`,`-c`,`cat "$1"; status=$?; rm -f "$1"; exit "$status"`,`agent-device-snapshot-helper-output`,e]}function rt(e){try{return W(U(w(e).results))}catch{return null}}async function it(e,t){try{await e([`shell`,`rm`,`-f`,t],{allowFailure:!0,timeoutMs:5e3})}catch{}}function at(e){let t=w(e),n=U(t.results);return{xml:ct(ot(t.status),n),metadata:{...W(n),transport:`instrumentation`}}}function ot(e){let t=[];for(let n of e){if(n.agentDeviceProtocol!==`android-snapshot-helper-v1`||n.outputFormat!==`uiautomator-xml`)continue;let{payloadBase64:e}=n;e!==void 0&&t.push({index:G(n.chunkIndex),count:G(n.chunkCount),payloadBase64:e})}return t}function U(t){let n=t.find(e=>e.agentDeviceProtocol===j);if(!n)throw new e(`COMMAND_FAILED`,`Android snapshot helper did not return a final result`);if(n.ok!==`true`)throw new e(`COMMAND_FAILED`,st(n),{errorType:n.errorType,helper:n});return n}function st(e){return e.message&&e.message!==`null`?e.message:e.errorType||`Android snapshot helper returned an error`}function ct(t,n){if(t.length===0)throw new e(`COMMAND_FAILED`,`Android snapshot helper did not return XML chunks`,{helper:n});let r=lt(t),i=Buffer.concat(dt(ut(t,r),r)).toString(`utf8`);if(!i.includes(`<hierarchy`)||!i.includes(`</hierarchy>`))throw new e(`COMMAND_FAILED`,`Android snapshot helper output did not contain XML`,{xml:i});return i}function lt(t){let n=t[0]?.count??t.length;if(n<1||t.length!==n||t.some(e=>e.count!==n))throw new e(`COMMAND_FAILED`,`Android snapshot helper returned incomplete XML chunks`,{expectedChunks:n,actualChunks:t.length});return n}function ut(t,n){let r=new Map;for(let i of t){if(i.index===void 0||i.index<0||i.index>=n)throw new e(`COMMAND_FAILED`,`Android snapshot helper returned invalid chunk index`,{chunkIndex:i.index,expectedChunks:n});if(r.has(i.index))throw new e(`COMMAND_FAILED`,`Android snapshot helper returned duplicate XML chunks`,{chunkIndex:i.index});r.set(i.index,i.payloadBase64)}return r}function dt(t,n){let r=[];for(let i=0;i<n;i+=1){let a=t.get(i);if(a===void 0)throw new e(`COMMAND_FAILED`,`Android snapshot helper returned incomplete XML chunks`,{missingChunkIndex:i,expectedChunks:n});r.push(Buffer.from(a,`base64`))}return r}function W(e){return{helperApiVersion:e.helperApiVersion,outputFormat:M,waitForIdleTimeoutMs:G(e.waitForIdleTimeoutMs),waitForIdleQuietMs:G(e.waitForIdleQuietMs),timeoutMs:G(e.timeoutMs),maxDepth:G(e.maxDepth),maxNodes:G(e.maxNodes),rootPresent:K(e.rootPresent),captureMode:ft(e.captureMode),windowCount:G(e.windowCount),nodeCount:G(e.nodeCount),truncated:K(e.truncated),elapsedMs:G(e.elapsedMs)}}function ft(e){return e===`interactive-windows`||e===`active-window`?e:void 0}const G=D,K=O,q=2e3,J=5e3,Y=new Map,X=new Map;async function pt(e){if(!jt()||!e.adbProvider?.spawn)return;let n=B(e),r=e.deviceKey??`android:default`,i=At(r,n,e);if(X.get(r)===i)return;let a=Y.get(r);if(a&&a.identity!==i&&(await Z(r),a=void 0),!a)try{a=await _t({deviceKey:r,identity:i,options:e,resolved:n})}catch(e){X.set(r,i),t({level:`warn`,phase:`android_snapshot_helper_session_disabled`,data:{deviceKey:r,reason:e instanceof Error?e.message:String(e)}});return}try{let e=a.capturedCount>0,t=await bt(a,n);return a.capturedCount+=1,{xml:t.xml,metadata:{...t.metadata,transport:`persistent-session`,sessionReused:e}}}catch(e){throw await Z(r),e}}async function Z(e){let n=Y.get(e);if(n){Y.delete(e);try{await xt(n,`quit ${Date.now()}`,1e3)}catch{}try{await n.process.kill(`SIGTERM`)}catch{}await vt(n.process,q);try{await Ot(n)}catch{}t({phase:`android_snapshot_helper_session_stop`,data:{deviceKey:e,port:n.port,capturedCount:n.capturedCount,lifetimeMs:Date.now()-n.startedAtMs}})}}async function mt(e){await Z(ht(e))}function ht(e){return`${e.platform}:${e.id}`}function gt(e){return Math.min(e.commandTimeoutMs,Math.max(e.timeoutMs+1e4,3e3))}async function _t(n){let r=await Mt();await n.options.adb([`forward`,`tcp:${r}`,`tcp:${r}`],{allowFailure:!1,timeoutMs:J});let i=H({...n.resolved,outputPath:void 0,emitChunks:!1}),a=i[i.length-1];if(!a)throw new e(`INVALID_ARGS`,`Android snapshot helper runner was not resolved`);let o=[...i.slice(0,-1),`-e`,`sessionPort`,String(r),a],s=n.options.adbProvider.spawn(o,{allowFailure:!0,captureOutput:!1}),c={identity:n.identity,deviceKey:n.deviceKey,port:r,adb:n.options.adb,process:s,startedAtMs:Date.now(),capturedCount:0};try{return await yt(s,1e4),Y.set(n.deviceKey,c),t({phase:`android_snapshot_helper_session_ready`,data:{deviceKey:n.deviceKey,port:r,packageName:n.resolved.packageName,runner:n.resolved.runner}}),c}catch(e){await Ot(c);try{s.kill(`SIGTERM`)}catch{}throw await vt(s,q),e}}function vt(e,t){return new Promise(n=>{let r=setTimeout(n,t);e.once(`close`,()=>{clearTimeout(r),n()}),e.once(`exit`,()=>{clearTimeout(r),n()})})}function yt(t,n){return new Promise((r,i)=>{let a=``,o=setTimeout(()=>{i(new e(`COMMAND_FAILED`,`Android snapshot helper session did not become ready`,{output:a,timeoutMs:n}))},n),s=e=>{a+=e.toString(),a.includes(`agentDeviceProtocol=android-snapshot-helper-v1`)&&a.includes(`sessionReady=true`)&&(clearTimeout(o),r())};t.stdout?.on(`data`,s),t.stderr?.on(`data`,s),t.once(`exit`,(t,n)=>{clearTimeout(o),i(new e(`COMMAND_FAILED`,`Android snapshot helper session exited before ready`,{output:a,exitCode:t,signal:n}))}),t.on(`error`,e=>{clearTimeout(o),i(e)})})}async function bt(e,t){let n=`snapshot-${Date.now()}-${Math.random().toString(16).slice(2)}`,r=gt(t);return St(await xt(e,`snapshot ${n}`,r),n)}function xt(t,n,r){return new Promise((i,a)=>{let o=l.connect({host:`127.0.0.1`,port:t.port}),s=[],c=setTimeout(()=>{o.destroy(),a(new e(`COMMAND_FAILED`,`Android snapshot helper session request timed out`,{command:n,timeoutMs:r,port:t.port}))},r);o.on(`connect`,()=>{o.write(`${n}\n`)}),o.on(`data`,e=>{s.push(Buffer.from(e))}),o.on(`error`,e=>{clearTimeout(c),a(e)}),o.on(`close`,()=>{clearTimeout(c),i(Buffer.concat(s).toString(`utf8`))})})}function St(e,t){let{headers:n,xml:r}=Ct(e);return wt(n,t),Tt(n,r),{xml:r,metadata:Dt(n)}}function Ct(t){let n=t.indexOf(`
|
|
3
|
-
|
|
4
|
-
`);if(n<0)throw new e(`COMMAND_FAILED`,`Android snapshot helper session returned malformed output`,{response:t});return{headers:Et(t.slice(0,n)),xml:t.slice(n+2)}}function wt(t,n){if(t.agentDeviceProtocol!==`android-snapshot-helper-v1`)throw new e(`COMMAND_FAILED`,`Android snapshot helper session returned wrong protocol`,{headers:t});if(t.outputFormat!==`uiautomator-xml`)throw new e(`COMMAND_FAILED`,`Android snapshot helper session returned wrong output format`,{headers:t});if(t.requestId!==n)throw new e(`COMMAND_FAILED`,`Android snapshot helper session returned stale output`,{headers:t,requestId:n});if(t.ok!==`true`)throw new e(`COMMAND_FAILED`,t.message||t.errorType||`Android snapshot helper session returned an error`,{helper:t})}function Tt(t,n){let r=D(t.byteLength);if(r!==void 0&&Buffer.byteLength(n,`utf8`)!==r)throw new e(`COMMAND_FAILED`,`Android snapshot helper session returned truncated XML`,{headers:t,actualByteLength:Buffer.byteLength(n,`utf8`)});if(!n.includes(`<hierarchy`)||!n.includes(`</hierarchy>`))throw new e(`COMMAND_FAILED`,`Android snapshot helper session did not return XML`,{headers:t,xml:n})}function Et(e){let t={};for(let n of e.split(/\r?\n/)){let e=n.indexOf(`=`);e<0||(t[n.slice(0,e)]=n.slice(e+1))}return t}function Dt(e){return{helperApiVersion:e.helperApiVersion,outputFormat:M,waitForIdleTimeoutMs:D(e.waitForIdleTimeoutMs),waitForIdleQuietMs:D(e.waitForIdleQuietMs),timeoutMs:D(e.timeoutMs),maxDepth:D(e.maxDepth),maxNodes:D(e.maxNodes),rootPresent:O(e.rootPresent),captureMode:e.captureMode===`interactive-windows`||e.captureMode===`active-window`?e.captureMode:void 0,windowCount:D(e.windowCount),nodeCount:D(e.nodeCount),truncated:O(e.truncated),elapsedMs:D(e.elapsedMs)}}async function Ot(e){await e.process.stdin?.end(),await e.process.stdout?.destroy(),await e.process.stderr?.destroy(),await kt(e)}async function kt(e){await e.adb([`forward`,`--remove`,`tcp:${e.port}`],{allowFailure:!0,timeoutMs:J})}function At(e,t,n){return JSON.stringify({deviceKey:e,packageName:t.packageName,runner:t.runner,helperVersion:n.helperVersion,helperVersionCode:n.helperVersionCode,waitForIdleTimeoutMs:t.waitForIdleTimeoutMs,waitForIdleQuietMs:t.waitForIdleQuietMs,timeoutMs:t.timeoutMs,maxDepth:t.maxDepth,maxNodes:t.maxNodes})}function jt(){let e=process.env.AGENT_DEVICE_ANDROID_SNAPSHOT_HELPER_SESSION;return e===void 0||!/^(0|false|no|off)$/i.test(e)}function Mt(){return new Promise((e,t)=>{let n=l.createServer();n.unref(),n.on(`error`,t),n.listen(0,`127.0.0.1`,()=>{let r=n.address();if(!r||typeof r==`string`){n.close(()=>t(Error(`Failed to allocate a local TCP port`)));return}let i=r.port;n.close(()=>e(i))})})}const Q=new Map;function Nt(e){$(Pt(e.deviceKey,e.packageName,e.versionCode))}function Pt(e,t,n){return e?`${e}\0${t}\0${n}`:void 0}function Ft(e,t){e&&Q.set(e,t)}function $(e){e&&Q.delete(e)}async function It(e){let{adb:t,artifact:r}=e,i=e.installPolicy??`missing-or-outdated`,a=r.manifest.packageName,o=r.manifest.versionCode;if(i===`never`)return{packageName:a,versionCode:o,installed:!1,reason:`skipped`};let s=Pt(e.deviceKey,a,o),c=s?Q.get(s):void 0;if(s&&i!==`always`&&c!==void 0)return{packageName:a,versionCode:o,installedVersionCode:c,installed:!1,reason:`current`};let l=await Lt(t,a,e.timeoutMs),u=Vt(i,l,o);if(u===`current`){if(l===void 0)throw Error(`Expected installed versionCode for current Android snapshot helper`);return Ft(s,l),{packageName:a,versionCode:o,installedVersionCode:l,installed:!1,reason:u}}await Be(r);let d=await Rt(t,e.adbProvider??t,r.apkPath,He(r.manifest),{packageName:a,timeoutMs:e.timeoutMs});if(d.exitCode!==0)throw $(s),n(`Failed to install Android snapshot helper`,d,{packageName:a,versionCode:o});return Ft(s,o),{packageName:a,versionCode:o,installedVersionCode:l,installed:!0,reason:u}}async function Lt(e,t,n){let r=await e([`shell`,`cmd`,`package`,`list`,`packages`,`--show-versioncode`,t],{allowFailure:!0,timeoutMs:n});if(r.exitCode===0)return zt(`${r.stdout}\n${r.stderr}`,t)}async function Rt(e,t,n,i,a){let o=async()=>await r(n,{allowFailure:!0,provider:t,...i,timeoutMs:a.timeoutMs}),s=await o();if(s.exitCode===0||!Bt(s))return s;let c=await e([`uninstall`,a.packageName],{allowFailure:!0,timeoutMs:a.timeoutMs}),l=await o();return l.exitCode===0?l:{...l,stderr:[l.stderr,c.stderr?`Previous uninstall stderr after INSTALL_FAILED_UPDATE_INCOMPATIBLE: ${c.stderr}`:``].filter(Boolean).join(`
|
|
5
|
-
`)}}function zt(e,t){let n=`package:${t}`;for(let t of e.split(/\r?\n/)){if(!t.startsWith(n)||t.length>n.length&&!/\s/.test(t[n.length]??``))continue;let e=/(?:^|\s)versionCode:(\d+)(?:\s|$)/.exec(t);if(e)return Number(e[1])}}function Bt(e){return`${e.stdout}\n${e.stderr}`.includes(`INSTALL_FAILED_UPDATE_INCOMPATIBLE`)}function Vt(e,t,n){return e===`never`?`skipped`:e===`always`?`forced`:t===void 0?`missing`:t<n?`outdated`:`current`}export{u as _,Z as a,Ve as c,A as d,D as f,g,ee as h,ht as i,w as l,te as m,Nt as n,mt as o,d as p,pt as r,Xe as s,It as t,k as u};
|