agent-device 0.19.3 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -70
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.0.apk +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.0.apk.sha256 +1 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.0.manifest.json +10 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.0.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.0.apk.sha256 +1 -0
- package/{android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.19.3.manifest.json → android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.0.manifest.json} +6 -6
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.h +2 -0
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.m +5 -0
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.h +5 -10
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +74 -174
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +113 -19
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+BlockingSystemModalResolution.swift +82 -0
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +272 -118
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +2 -2
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +134 -101
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +56 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+LifecycleCacheTests.swift +73 -0
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +44 -24
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollGesture.swift +2 -2
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SequenceExecution.swift +2 -107
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +126 -11
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +51 -8
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTraversalIdentityTests.swift +24 -0
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +1 -1
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +43 -35
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +14 -0
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/agent-device-client.js +3 -0
- package/dist/src/android-adb.d.ts +1 -1
- package/dist/src/android-adb.js +1 -1
- package/dist/src/android-input-method-overlays.js +1 -0
- package/dist/src/android-input-ownership.js +1 -6
- package/dist/src/android-system-chrome.js +1 -0
- package/dist/src/android.js +1 -1
- package/dist/src/app-lifecycle.js +5 -5
- package/dist/src/app-log-request-scope.js +1 -0
- package/dist/src/app-resolution.js +1 -0
- package/dist/src/apple-multitouch-support.js +1 -0
- package/dist/src/apps.js +5 -5
- package/dist/src/boot-diagnostics.js +2 -0
- package/dist/src/cli-config.js +1 -0
- package/dist/src/cli-help.js +61 -27
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +15 -11
- package/dist/src/command-schema.js +3 -3
- package/dist/src/config.js +1 -0
- package/dist/src/context.js +1 -0
- package/dist/src/contracts.d.ts +1 -1
- package/dist/src/daemon-shutdown-report.js +1 -0
- 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/finders.js +1 -1
- package/dist/src/generic.js +1 -1
- package/dist/src/helper.js +1 -1
- package/dist/src/index.d.ts +412 -293
- package/dist/src/index.js +1 -1
- package/dist/src/input-actions.js +4 -3
- package/dist/src/install-artifact.js +1 -0
- package/dist/src/install-source.d.ts +5 -1
- package/dist/src/install-source.js +1 -1
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-snapshot.js +1 -1
- package/dist/src/interaction.d.ts +230 -0
- 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 +42 -20
- package/dist/src/internal/png-worker.d.ts +22 -0
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/launch-console.js +1 -0
- package/dist/src/lease-context.js +1 -0
- package/dist/src/lease.js +1 -1
- package/dist/src/linux.js +1 -1
- package/dist/src/logcat.js +5 -0
- package/dist/src/metro.d.ts +2 -2
- package/dist/src/notifications.js +1 -1
- package/dist/src/png-worker-contract.js +1 -1
- package/dist/src/process-lock.js +1 -0
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-trace.js +1 -1
- package/dist/src/register-builtins.js +1 -0
- package/dist/src/registry.js +24 -24
- package/dist/src/reporting.js +8 -7
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-disposal.js +2 -0
- package/dist/src/runner-lease.js +1 -0
- package/dist/src/runner-sequence.js +1 -1
- package/dist/src/runtime.js +3 -3
- package/dist/src/runtime2.js +1 -0
- package/dist/src/sdk-android-adb.d.ts +119 -33
- package/dist/src/sdk-android-adb.js +2 -2
- package/dist/src/sdk-batch-runner.d.ts +2 -1
- package/dist/src/sdk-batch-runner.js +2 -2
- package/dist/src/sdk-batch.js +2 -2
- package/dist/src/sdk-contracts.d.ts +105 -98
- package/dist/src/sdk-contracts.js +1 -1
- package/dist/src/sdk-device.js +1 -1
- package/dist/src/sdk-finders.d.ts +3 -3
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-io.d.ts +1 -1
- package/dist/src/sdk-remote-config.d.ts +9 -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/selector-vocabulary.js +1 -0
- package/dist/src/selectors.d.ts +12 -3
- package/dist/src/selectors.js +1 -1
- package/dist/src/server.js +3 -3
- package/dist/src/session-target-evidence.js +1 -0
- package/dist/src/session.js +8 -10
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-diagnostics.js +5 -2
- package/dist/src/snapshot.js +1 -1
- package/dist/src/snapshot2.js +1 -2
- package/dist/src/tv-remote.js +13 -12
- package/dist/src/url.js +1 -1
- package/dist/src/web.js +1 -1
- package/package.json +28 -23
- package/server.json +2 -2
- package/android-multitouch-helper/dist/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 +0 -1
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.3.manifest.json +0 -10
- package/android-snapshot-helper/dist/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 +0 -1
- package/dist/src/apple-runner-options.js +0 -1
- package/dist/src/cli-output.js +0 -1
- package/dist/src/client.js +0 -3
- package/dist/src/handler-utils.js +0 -1
- package/dist/src/output-path.js +0 -1
- package/dist/src/points.js +0 -4
- package/dist/src/provider.js +0 -1
- package/dist/src/providers.js +0 -1
- package/dist/src/record-trace-recording.js +0 -23
- package/dist/src/recording-provider.js +0 -1
- package/dist/src/selectors2.js +0 -1
- package/dist/src/simctl.js +0 -1
- package/dist/src/ttl-memo.js +0 -1
- package/dist/src/xml.js +0 -2
- /package/{macos-helper → apple/macos-helper}/Package.swift +0 -0
- /package/{macos-helper → apple/macos-helper}/Sources/AgentDeviceMacOSHelper/AudioProbe.swift +0 -0
- /package/{macos-helper → apple/macos-helper}/Sources/AgentDeviceMacOSHelper/SnapshotTraversal.swift +0 -0
- /package/{macos-helper → apple/macos-helper}/Sources/AgentDeviceMacOSHelper/main.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/project.pbxproj +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/xcshareddata/xcschemes/AgentDeviceRunner.xcscheme +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/AgentDeviceRunnerUITests-Bridging-Header.h +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/AgentDeviceRunnerUITests.entitlements +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerObjCExceptionCatcher.h +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerObjCExceptionCatcher.m +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTapPointPolicy.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Environment.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Exceptions.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+FlatSnapshotFiltering.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScreenRecorder.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Transport.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests.xctestplan +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/RecordingScripts/recording-overlay.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/RecordingScripts/recording-resize.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/RecordingScripts/recording-trim.swift +0 -0
- /package/{src/platforms/linux → linux}/atspi-dump.py +0 -0
package/dist/src/tv-remote.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
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
|
-
`)}
|
|
1
|
+
import{S as e,T as t,_ as n,d as r,f as i,g as a,p as o,u as s}from"./sdk-contracts.js";import{A as c,M as l,N as u,O as d,j as f,k as p,p as m}from"./sdk-batch.js";import{$ as h,A as g,B as ee,G as te,H as ne,J as re,K as ie,P as ae,R as oe,U as se,V as ce,X as le,Y as ue,Z as _,a as de,f as fe,h as pe,i as me,k as he,l as ge,m as _e,n as ve,o as v,q as ye,r as be,rt as xe,s as Se,t as Ce,tt as we,u as Te,z as Ee}from"./sdk-selectors.js";import{x as y}from"./sdk-batch-runner.js";import{n as De,t as Oe}from"./snapshot-quality.js";import{a as b,i as ke,r as x,s as S,t as Ae}from"./android-input-method-overlays.js";import{n as je}from"./android-system-chrome.js";import{createHash as Me}from"node:crypto";import Ne from"node:path";import{styleText as Pe}from"node:util";const Fe=Ve(`public`),Ie=Ve(`internal`),Le=Ve(`local-cli`),Re={help:`help`};function ze(){return[...Object.values(Fe),...Object.values(Le)].sort()}function Be(e){return Object.values(Re).includes(e)||Object.values(Ie).includes(e)?!0:ze().includes(e)}function Ve(e){let t={};for(let[n,r]of m(e))t[n]=r;return t}const He=[`out`,`overlayRefs`,`screenshotPixelDensity`,`screenshotFullscreen`,`screenshotMaxSize`,`screenshotNoStabilize`,`screenshotNormalizeStatusBar`],Ue=[`screenshotPixelDensity`,`screenshotFullscreen`,`screenshotMaxSize`,`screenshotNoStabilize`,`screenshotNormalizeStatusBar`],We=[{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`}],Ge=[{tokens:[`--fullscreen`,`--full`,`-f`],key:`screenshotFullscreen`},{tokens:[`--no-stabilize`],key:`screenshotNoStabilize`},{tokens:[`--normalize-status-bar`],key:`screenshotNormalizeStatusBar`}],Ke=[{token:`--pixel-density`,key:`screenshotPixelDensity`,label:`screenshot --pixel-density`},{token:`--max-size`,key:`screenshotMaxSize`,label:`screenshot --max-size`}];function qe(e){return Ze({overlayRefs:e?.overlayRefs,pixelDensity:e?.screenshotPixelDensity,fullscreen:e?.screenshotFullscreen,maxSize:e?.screenshotMaxSize,stabilize:e?.screenshotNoStabilize?!1:void 0,normalizeStatusBar:e?.screenshotNormalizeStatusBar})}function Je(e={}){return Ze({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 Ye(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 Xe(e){let{args:t,flags:n,index:r}=e,i=t[r];return Qe(i,n,r)??$e({args:t,index:r,flags:n,token:i})??{handled:!1}}function Ze(e){return Object.fromEntries(Object.entries(e).filter(e=>e[1]!==void 0))}function Qe(e,t,n){let r=Ge.find(t=>t.tokens.some(t=>t===e));if(r)return t[r.key]=!0,{handled:!0,nextIndex:n}}function $e(e){let t=Ke.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 C(e){return e?{message:e}:{}}function et(e,t){return t?{...e,message:t}:e}function tt(e){return typeof e?.message==`string`&&e.message.length>0?e.message:null}function w(e){return e.width>0&&e.height>0}function nt(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 rt(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 it(e){return typeof e.parentIndex!=`number`}function T(e){let t=(e.type??``).toLowerCase(),n=(e.identifier??``).trim().toLowerCase();return t.includes(`edittext`)||t.includes(`textfield`)||n===`composer`}function at(e){let t=(e.type??``).toLowerCase();return t.includes(`scroll`)||t.includes(`list`)||t.includes(`recyclerview`)}function E(e){let t=xe(e);if(!t||t!==e.identifier?.trim()||!ot(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 D(e){let t=e.trim().replace(/\s+/g,` `).toLowerCase();return!t||/^(true|false|\d+)$/.test(t)?null:t}function ot(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function st(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 ct(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 O(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 lt=[`button`,`switch`,`checkbox`,`radio`],ut=[`button`,`image`,`textview`,`view`];function dt(e,t,n){for(let r of e){if(t.has(r.index)||!mt(r))continue;let i=ht(ct(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)O(e,n,t)}}}function ft(e,t,n){let r=new Map;for(let i of e){if(t.has(i.index)||!St(i))continue;let a=D(E(i));if(!a)continue;let o=r.get(a);if(o&&yt(o,i,t)){let s=bt(e,o,i,t,n);r.set(a,s);continue}r.set(a,i)}}function pt(e,t){for(let n of e){if(t.has(n.index)||!_t(n))continue;let r=D(E(n));if(!r)continue;let i=ct(e,n.index).filter(e=>!t.has(e.index)&&vt(n,e,r));for(let n of i.filter(gt))O(e,n.index,t);let a=i.filter(e=>!gt(e)),o=new Set(a.map(e=>D(E(e))).filter(e=>!!e));if(!(a.length<2||o.size<2))for(let n of a)O(e,n.index,t)}}function mt(e){return e.hittable===!0&&!T(e)&&!!(e.rect&&w(e.rect))&&E(e).trim().length===0}function ht(e,t,n){let r=[],i=[],a=new Set;for(let o of e){if(n.has(o.index)||!gt(o)||!nt(o.rect,t.rect))continue;let e=E(o).trim().replace(/\s+/g,` `),s=D(e);i.push(o.index),!(!e||!s||a.has(s))&&(a.add(s),r.push(e))}return{label:r.join(`, `),removableIndexes:i}}function gt(e){if(e.hittable===!0||T(e))return!1;let t=(e.type??``).toLowerCase();return t.includes(`text`)||t.includes(`image`)||t.includes(`icon`)}function _t(e){return e.hittable===!0&&!T(e)&&!!(e.rect&&w(e.rect))&&!!D(E(e))}function vt(e,t,n){if(!St(t)||!nt(t.rect,e.rect))return!1;let r=D(E(t));return!!(r&&n!==r&&n.includes(r))}function yt(e,t,n){return!n.has(e.index)&&rt(e.rect,t.rect)&&(Dt(e,t)||Et(e,t))}function bt(e,t,n,r,i){let a=Ct(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:xt(c.presentationHints,l,s)}),O(e,o.index,r),i.get(a.index)??a}function xt(e,t,n){return[...new Set([...Array.isArray(e)?e:[],...Array.isArray(t)?t:[],...n?[n]:[]])]}function St(e){if(!e.rect||!w(e.rect)||it(e)||T(e))return!1;let t=(e.type??``).toLowerCase();return t===`text`||Tt(t,ut)}function Ct(e,t){let n=wt(e);return wt(t)>n?t:e}function wt(e){let t=(e.type??``).toLowerCase(),n=0;return Tt(t,lt)?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 Tt(e,t){return t.some(t=>e.includes(t))}function Et(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:Ct(n,r).index===n.index}function Dt(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||!kt(e))return{nodes:t,filteredCount:0};let r=At(t);return{nodes:r,filteredCount:t.length-r.length}}function kt(e){let t=e.androidSnapshot;return!t||typeof t!=`object`?!1:t.backend===`android-helper`}function At(e){if(e.length===0)return e;let t=new Set,n=new Map,r=new Map(e.map(e=>[e.index,e]));return jt(e,t),Mt(e,r,t,n),dt(e,t,n),pt(e,t),ft(e,t,n),e.filter(e=>!t.has(e.index)).map(e=>n.get(e.index)??e)}function jt(e,t){for(let n of e)!n.rect||w(n.rect)||it(n)||O(e,n.index,t)}function Mt(e,t,n,r){for(let i of e){if(n.has(i.index)||i.rect||it(i))continue;let a=st(i,t,at);a&&Pt(r,a,Nt(i,e)),O(e,i.index,n)}}function Nt(e,t){let n=t.filter(t=>t.parentIndex===e.parentIndex&&t.rect&&w(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 Ft(e){let t=e.trim().replace(/\s+/g,` `).toLowerCase();return!t||It(t)?null:t}function It(e){return/\S+@\S+\.\S+/.test(e)}function Lt(e){if(e.length<20)return!1;let t=new Map;for(let n of e){let e=(n.type??``).toLowerCase(),r=Ft(xe(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||!Rt(e)||(n+=e.length);return n>=8}function Rt(e){for(let t=0;t<e.length;t+=1)for(let n=t+1;n<e.length;n+=1)if(zt(e[t]?.rect,e[n]?.rect))return!0;return!1}function zt(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 Bt={digest:8*1024,default:24*1024,full:64*1024};function Vt(e){return e===`digest`||e===`full`?e:`default`}function Ht(e,t=256){let n=Buffer.from(e,`utf8`);if(n.length<=t)return e;let r=`…<truncated>`,i=Buffer.byteLength(r,`utf8`),a=Math.max(0,t-i);for(;a>0&&(n[a]&192)==128;)--a;return`${n.subarray(0,a).toString(`utf8`)}${r}`}function k(e,n=256){return Ht(t(e),n)}function Ut(e,t){let n=e;for(let e of t)e.value&&(n=n.split(e.value).join(`<var:${e.name}>`));return n}function Wt(e){return(t,n)=>k(Ut(t,e),n)}function Gt(e,t){return e.state!==`available`||e.refs.length<=t?e:{...e,refs:e.refs.slice(0,t),truncated:!0}}function Kt(e,t){let n=Vt(t),r=n===`digest`?8:20,i=Gt(e.screen,r),a=n===`digest`?[]:e.suggestions.slice(0,5);return{...e,screen:i,suggestions:a}}function qt(e){return Buffer.byteLength(JSON.stringify(e),`utf8`)}function Jt(e){let{divergence:t,level:n,writeOverflowArtifact:r}=e,i=Vt(n),a=Bt[i],o=Kt(t,n),s=qt(o);if(s<=a)return o;let c=s-a,l=r(Kt(t,`full`)),u=Yt(o);return`artifactPath`in l?{...u,overflow:{omittedBytes:c,artifactPath:l.artifactPath}}:{...u,artifactUnavailable:!0}}function Yt(e){return{version:e.version,kind:e.kind,step:{index:e.step.index,source:{path:k(e.step.source.path),line:e.step.source.line}},action:k(e.action),cause:{code:e.cause.code,message:k(e.cause.message),...e.cause.hint?{hint:k(e.cause.hint)}:{}},screen:{state:`unavailable`,reason:`omitted-for-size`,hint:`The screen digest and suggestions were omitted to stay within the response byte budget. See overflow.artifactPath (or retry at --level full) for the complete report.`},suggestions:[],suggestionCount:e.suggestionCount,resume:e.resume,repairHint:e.repairHint,...e.targetBinding?{targetBinding:e.targetBinding}:{}}}function Xt(e){let t=e?.divergence;if(!t||typeof t!=`object`)return null;let n=t,r=[...ln(n.step),...an(n.kind,n.targetBinding),...Zt(n.repairHint,n.resume),...un(n.screen),...mn(n.suggestions,n.suggestionCount),...gn(n.overflow,n.artifactUnavailable)];return r.length>0?r.join(`
|
|
2
|
+
`):null}function Zt(e,t){if(typeof e!=`string`)return[];let n=en(e,t);return[`Repair hint: ${e}${n?` — ${n}`:``}`]}function Qt(e){let t=e;if(!t||typeof t.allowed!=`boolean`)return;if(!t.allowed)return{allowed:!1,reason:typeof t.reason==`string`?t.reason:void 0};let{from:n,planDigest:r,alternateFrom:i}=t;if(!(typeof n!=`number`||typeof r!=`string`||r.length===0))return{allowed:!0,from:n,planDigest:r,alternateFrom:typeof i==`number`?i:void 0}}function A(e,t){return`replay --from ${e} --plan-digest ${t}`}function $t(e){return e?.repairSessionHeld===!0}function en(e,t){let n=tn(e,Qt(t));if(n!==void 0)return $t(t)?`${n} Read-only inspection while armed (snapshot -i, get attrs, find, is) is excluded from the healed script by default — no --no-record needed. If the step you are repairing is itself a read, add --record to that command so it lands in the heal.`:n}function tn(e,t){switch(e){case`record-and-heal`:return t?.allowed?`press the correct control via a blessed @ref from screen.refs (recorded), then ${A(t.from,t.planDigest)}.`:`press the correct control via a blessed @ref from screen.refs (recorded). ${rn(t)}`;case`state-repair`:return t?.allowed?`fix app state with --no-record actions, then ${A(t.from,t.planDigest)} to re-run it.`:`fix app state with --no-record actions. ${rn(t)}`;case`caution`:return nn({lead:`something already matches the recorded selector; a blind re-press may repeat the mistake.`,guidance:t});case`manual`:return nn({lead:`no safe automated repair could be proven; inspect the screen and repair by hand.`,guidance:t});default:return}}function nn(e){let{lead:t,guidance:n}=e;if(!n?.allowed)return`${t} ${rn(n)}`;let r=`if you fixed app state with --no-record actions: ${A(n.from,n.planDigest)}`;return n.alternateFrom===void 0?`${t} ${r}.`:`${t} ${r}; ${`if you performed the step's intent as a recorded action: ${A(n.alternateFrom,n.planDigest)}`}.`}function rn(e){return e&&!e.allowed&&e.reason?`This step cannot currently be resumed automatically (${e.reason}) — run a fresh full replay instead.`:`This step cannot currently be resumed automatically — run a fresh full replay instead.`}function an(e,t){if(typeof e!=`string`||e===`action-failure`)return[];let n=t;return n?[on(e,n.matchCount),...sn(n.mismatches),...cn(n.candidates)]:[]}function on(e,t){return`Target binding: ${e}${typeof t==`number`?` (matchCount ${t})`:``} — recorded target evidence did not verify.`}function sn(e){return!Array.isArray(e)||e.length===0?[]:[` mismatches: ${e.slice(0,5).join(`; `)}`]}function cn(e){return!Array.isArray(e)||e.length===0?[]:[` ${e.length} candidate(s) shared the recorded identity:`,...e.slice(0,5).map(e=>` ${pn(e)}`)]}function ln(e){let t=e;if(typeof t?.index!=`number`)return[];let n=t.source,r=typeof n?.path==`string`&&typeof n.line==`number`?` (${n.path}:${n.line})`:``;return[`Divergence at step ${t.index}${r}`]}function un(e){let t=e;return t?.state===`available`&&Array.isArray(t.refs)?dn(t.refs,t.refsGeneration):t?.state===`unavailable`?[fn(t)]:[]}function dn(e,t){let n=e.slice(0,8).map(pn),r=e.length-n.length;return[`Screen: ${e.length} actionable ref(s) captured (refsGeneration ${t}).`,...n,...r>0?[` ... ${r} more`]:[]]}function fn(e){let t=typeof e.hint==`string`&&e.hint.length>0?` ${e.hint}`:``;return`Screen: unavailable (${String(e.reason??`unknown`)}).${t}`}function pn(e){let t=e,n=typeof t.label==`string`?` "${t.label}"`:``;return` @${String(t.ref)} [${String(t.role)}]${n}`}function mn(e,t){return Array.isArray(e)&&e.length>0?[`Suggestions:`,...e.slice(0,5).map(hn)]:typeof t==`number`&&t>0?[`Suggestions: ${t} available (omitted at this response level; rerun with --json for the full report).`]:[]}function hn(e){let t=e,n=typeof t.label==`string`?` "${t.label}"`:``;return` - [${String(t.basis)}]${n} ${String(t.selector)}`}function gn(e,t){return e&&typeof e==`object`?[`Full report written to ${String(e.artifactPath)}.`]:t===!0?[`Full report exceeded the response budget and the overflow artifact could not be written.`]:[]}const _n={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 vn(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=M(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:yn(i,c,!1,o,t)})}return r}function yn(e,t,n,r,i={}){let a=r??M(e.type??`Element`),o=ue(e,a),s=wn(e,a,i,o),c=` `.repeat(t),l=e.ref?`@${e.ref}`:``,u=Tn(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 j(e,t){let n=e.label?.trim();if(n&&Sn(t,n))return``;let r=e.value?.trim();if(xn(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||Cn(i)&&(t===`group`||t===`image`||t===`list`||t===`collection`)?``:i}function M(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`:bn(n)||n||`element`}function bn(e){return Object.prototype.hasOwnProperty.call(_n,e)?_n[e]:void 0}function xn(e){return e===`text-field`||e===`text-view`||e===`search`}function Sn(e,t){return e!==`scroll-area`&&e!==`list`&&e!==`collection`&&e!==`table`?!1:we(t)}function Cn(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function wn(e,t,n,r){return!n.summarizeTextSurfaces||!r.shouldSummarize?j(e,t):En(e,t,r.text)||j(e,t)}function Tn(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`),xn(t)&&i.push(`editable`),Dn(e,t)&&i.push(`scrollable`),!r.shouldSummarize)?kn(i):(i.push(`preview:"${On(re(r.text))}"`),i.push(`truncated`),kn(i))}function En(e,t,n){let r=h(e.label);if(r&&r!==n)return r;let i=h(e.identifier);if(i&&!Cn(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 Dn(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 On(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function kn(e){return[...new Set(e)]}function An(e){process.stdout.write(`${JSON.stringify(e,null,2)}\n`)}function jn(t,r={}){let i=t instanceof n?e(t):t;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`);let a=Xt(i.details);a&&process.stderr.write(`${a}\n`),r.showDetails&&i.details&&process.stderr.write(`${JSON.stringify(i.details,null,2)}\n`)}function Mn(e,t={}){let n=e.nodes,r=Array.isArray(n)?n:[],o=a(i(e.backend)?e.backend:void 0),s=Ot(e,r,t),c=In(e),l=ur(e,r,t,s),u=l.length>0?`${l.join(`
|
|
3
|
+
`)}\n`:``,d=t.raw?null:Nn(e);if(d)return`${c}${u}${Pn(d)}\n`;let f=t.raw||!o?null:oe(s.nodes),p=!!e.truncated,m=f?.nodes??r,h=t.raw||!o?null:Hn(e,f,m.length,r.length,s.filteredCount),g=Ln(r.length,h,p);return r.length===0?`${c}${g}\n${u}`:t.raw?`${c}${g}\n${u}${Rn(r)}\n`:t.flatten?`${c}${g}\n${u}${zn(m)}${Vn(f)}\n`:`${c}${g}\n${u}${Bn(m)}${Vn(f)}\n`}function Nn(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 Pn(e){let t=Fn(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
4
|
`):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
5
|
`):[`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 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};
|
|
6
|
+
`)}function Fn(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 In(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(`
|
|
7
|
+
`)}\n`:``}function Ln(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 Rn(e){return e.map(e=>JSON.stringify(e)).join(`
|
|
8
|
+
`)}function zn(e){return vr(e).join(`
|
|
9
|
+
`)}function Bn(e){return hr(vn(e,{summarizeTextSurfaces:!0})).join(`
|
|
10
|
+
`)}function Vn(e){return e&&e.summaryLines.length>0?`\n${e.summaryLines.join(`
|
|
11
|
+
`)}`:``}function Hn(e,t,n,r,i=0){let a=Un(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:Wn([...a?.reasons??[],`offscreen-nodes`])}:a||(s?{partial:!0,visibleNodeCount:n,totalNodeCount:n,reasons:[]}:null)}function Un(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 Wn(e){return[...new Set(e)]}function Gn(e){let t=e.baselineInitialized===!0,n=e.summary??{},r=P(n.additions),i=P(n.removals),a=P(n.unchanged),o=lr(),s=mr(e),c=s.length>0?`${s.join(`
|
|
12
|
+
`)}\n`:``;if(t)return`${c}Baseline initialized (${a} lines).\n`;let l=cr(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?F(e,`green`):e}if(e.kind===`removed`){let e=t.startsWith(` `)?`-${t}`:`- ${t}`;return o?F(e,`red`):e}return o?F(t,`dim`):t}),u=l.length>0?`${l.join(`
|
|
13
|
+
`)}\n`:``;return o?`${c}${u}${[`${F(String(r),`green`)} additions`,`${F(String(i),`red`)} removals`,`${F(String(a),`dim`)} unchanged`].join(`, `)}\n`:`${c}${u}${r} additions, ${i} removals, ${a} unchanged\n`}function Kn(e){let t=lr(),n=e.match===!0,r=e.dimensionMismatch,i=[];return i.push(...qn(e,t)),i.push(...Jn(e,n,t)),!n&&!r&&(i.push(...Yn(e,t)),i.push(...Xn(e,t)),i.push(...Zn(e,t)),i.push(...$n(e,t)),i.push(...er(e,t))),`${i.join(`
|
|
14
|
+
`)}\n`}function qn(e,t){if(e.match===!0)return[`${t?F(`✓`,`green`):`✓`} Screenshots match.`];let n=e.dimensionMismatch,r=t?F(`✗`,`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=P(e.differentPixels),a=P(e.mismatchPercentage),o=`${a===0&&i>0?`<0.01`:String(a)}% pixels differ`;return[`${r} ${t?F(o,`red`):o}`]}function Jn(e,t,n){if(t)return[];let r=[];if(e.diffPath){let t=sr(e.diffPath),i=n?F(`Diff image:`,`dim`):`Diff image:`,a=n?F(t,`green`):t;r.push(` ${i} ${a}`)}if(e.currentOverlayPath){let t=sr(e.currentOverlayPath),i=n?F(`Current overlay:`,`dim`):`Current overlay:`,a=n?F(t,`green`):t,o=P(e.currentOverlayRefCount),s=o>0?` (${o} refs)`:``;r.push(` ${i} ${a}${s}`)}return r}function Yn(e,t){let n=P(e.differentPixels),r=P(e.totalPixels);return[` ${t?F(String(n),`red`):String(n)} different / ${r} total pixels`]}function Xn(e,t){let n=nr(e);return n.length===0?[]:[` ${I(`Hints:`,t)}`,...n.map(e=>` - ${e}`)]}function Zn(e,t){let n=Array.isArray(e.regions)?e.regions:[];if(n.length===0)return[];let r=[` ${I(`Changed regions:`,t)}`];for(let e of n.slice(0,5))r.push(...Qn(e));return r}function Qn(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=or(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 $n(e,t){let n=e.ocr?.matches??[];if(n.length===0)return[];let r=n.slice(0,8),i=[` ${I(`OCR text deltas (${e.ocr?.provider}; baselineBlocks=${e.ocr?.baselineBlocks} currentBlocks=${e.ocr?.currentBlocks}; showing ${r.length}/${n.length}; px):`,t)}`,` ${I(`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)} | ${N(n.x)},${N(n.y)} | ${N(n.width)},${N(n.height)} | ${tr(t.baselineRect)} | ${tr(t.currentRect)} | ${t.confidence} | ${t.possibleTextMetricMismatch?`ocr-bbox-size-change`:`-`}`)}return i}function er(e,t){let n=e.nonTextDeltas??[];if(n.length===0)return[];let r=n.slice(0,8),i=[` ${I(`Non-text visual deltas (showing ${r.length}/${n.length}; px):`,t)}`,` ${I(`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} | ${tr(e.rect)} | ${e.nearestText?JSON.stringify(e.nearestText):`-`}`);return i}function tr(e){return`x=${e.x},y=${e.y},w=${e.width},h=${e.height}`}function N(e){return e>0?`+${e}`:String(e)}function nr(e){let t=[],n=e.ocr?.movementClusters??[];for(let e of n.slice(0,2))t.push(`text movement cluster: ${ar(e.texts)} dx=${ir(e.xRange)}px dy=${ir(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(rr).join(`; `)}`);let i=(e.nonTextDeltas??[]).filter(e=>e.likelyKind===`separator`).slice(0,2);return i.length>0&&t.push(`non-text boundaries: ${i.map(rr).join(`; `)}`),t.slice(0,6)}function rr(e){let t=e.nearestText?` near ${JSON.stringify(e.nearestText)}`:``,n=e.regionIndex?` r${e.regionIndex}`:``;return`${e.likelyKind}${t}${n}`}function ir(e){return e.min===e.max?N(e.min):`${N(e.min)}..${N(e.max)}`}function ar(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 or(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 sr(e){let t=process.cwd(),n=Ne.relative(t,e);return n===``||!n.startsWith(`..`)&&!Ne.isAbsolute(n)?n===``?`.`:`.${Ne.sep}${n}`:e}function P(e){return typeof e==`number`&&Number.isFinite(e)?e:0}function cr(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 lr(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 F(e,t,n){return Pe(t,e,n)}function I(e,t){return t?F(e,`dim`):e}function ur(e,t,n,r={nodes:t,filteredCount:0}){let i=mr(e);if(dr(e)){let e=pr(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&&Lt(a)&&i.push(`Warning: possible repeated nav subtree detected.`),i}function dr(e){return!e.snapshotQuality&&!fr(e)}function fr(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 pr(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 mr(e){let t=e.warnings;return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.length>0):[]}function hr(e){let t=[],n=[],r=new Map(e.map(e=>[e.node.index,e.node])),i=e=>{for(;n.length>0&&(!e||gr(e,n[n.length-1],r));)t.push(...yr(n.pop(),`below`))};for(let r of e)i(r),t.push(r.text),t.push(...yr(r,`above`)),r.node.hiddenContentBelow&&n.push(r);return i(),t}function gr(e,t,n){return _r(e.node,t.node,n)?!1:e.depth<=t.depth}function _r(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 vr(e){return vn(e,{summarizeTextSurfaces:!0}).flatMap(e=>[yn(e.node,0,!1,e.type,{summarizeTextSurfaces:!0}),...yr({...e,depth:0})])}function yr(e,t){let n=br(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 br(e){return e===`scroll-area`||e===`list`||e===`collection`||e===`table`?e:null}function xr(e,t={}){let n=lr(process.stderr);if(e===`pass`){let e=t.passFormat??`green`;return n?L(`✓`,e):`✓`}return e===`fail`?n?L(`⨯`,`red`):`⨯`:e===`warn`?n?L(`!`,`yellow`):`!`:n?L(`-`,`dim`):`-`}function L(e,t){return F(e,t,{validateStream:!1})}function Sr(e){return`${xr(wr(e.status))} ${Tr(e)}`}function Cr(e){return e.status!==`fail`&&e.status!==`warn`?[]:typeof e.command==`string`?[` run: ${e.command}`]:typeof e.hint==`string`?[` hint: ${e.hint}`]:[]}function wr(e){return e===`pass`?`pass`:e===`fail`?`fail`:e===`warn`?`warn`:`skip`}function Tr(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 Er=3e5,Dr=[`leaseId`,`tenantId`,`runId`,`clientId`,`deviceKey`];function Or(e){return y({tenantId:e.meta?.tenantId??R(e.flags,`tenant`),runId:e.meta?.runId??R(e.flags,`runId`),leaseId:e.meta?.leaseId??R(e.flags,`leaseId`),leaseTtlMs:e.meta?.leaseTtlMs,leaseBackend:e.meta?.leaseBackend,leaseProvider:e.meta?.leaseProvider??R(e.flags,`leaseProvider`)??R(e.flags,`provider`),deviceKey:e.meta?.deviceKey??R(e.flags,`deviceKey`),clientId:e.meta?.clientId??R(e.flags,`clientId`)})}function kr(e){return y({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 Ar(e){return y({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 jr(e){return y({tenant:e.tenantId,runId:e.runId,leaseId:e.leaseId,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId})}function Mr(e){return y({tenantId:e.tenantId??``,runId:e.runId??``,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId,ttlMs:e.leaseTtlMs})}function Nr(e){return zr(e)}function Pr(e){let{ttlMs:t,...n}=zr(e);return n}function Fr(e,t,n){let r=y({...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,...y({ttlMs:e.leaseTtlMs,backend:e.leaseBackend})};case`lease_heartbeat`:return{...r,...y({leaseId:e.leaseId,ttlMs:e.leaseTtlMs})};case`lease_release`:return{...r,...y({leaseId:e.leaseId})}}}function Ir(e){let t=y({leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId});return Object.keys(t).length>0?t:void 0}function Lr(e){return e.leaseProvider===`proxy`}function Rr(e){return Lr(e)?Dr.filter(t=>!e[t]):[]}function zr(e){return y({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 R(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function z(e,t,r={}){let i=e[t];if(i===void 0)return;if(!Number.isInteger(i))throw new n(`INVALID_ARGS`,`Expected ${t} to be an integer.`);let a=i;if(r.min!==void 0&&a<r.min)throw new n(`INVALID_ARGS`,`Expected ${t} to be at least ${r.min}.`);if(r.max!==void 0&&a>r.max)throw new n(`INVALID_ARGS`,`Expected ${t} to be at most ${r.max}.`);return a}const Br=[`app`,`device`,`system`];function Vr(e){return e===`device`||e===`system`}function Hr(e,t){return e.includes(t)}function Ur(e,t,r={}){let i=t===void 0?void 0:r.normalize?.(t)??t;if(i!==void 0&&Hr(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 B(e,t={}){return{values:e,is:t=>Hr(e,t),parse:n=>Ur(e,n,t)}}const Wr=[`app`,`frontmost-app`,`desktop`,`menubar`],Gr=B(Wr,{normalize:e=>e.trim().toLowerCase(),message:e=>`Invalid surface: ${e}. Use ${Wr.join(`|`)}.`});function Kr(e){return Gr.parse(e)}const qr=[`metrics`,`frames`,`memory`,`cpu`,`trace`],Jr=[`sample`,`snapshot`,`start`,`stop`,`report`],Yr=[`profile`],Xr=[`xctrace`,`simpleperf`,`perfetto`,`android-hprof`,`memgraph`],Zr=[`android-hprof`,`memgraph`],Qr=B(qr),$r=B(Jr),ei=B(Yr),ti=B(Xr),ni=B(Zr),ri=`perf area must be metrics, frames, memory, cpu, or trace`,ii=`perf action must be sample, snapshot, start, stop, or report`,ai=`perf cpu requires profile`,oi=`perf --kind must be xctrace, simpleperf, perfetto, android-hprof, or memgraph`,si=`perf memory snapshot --kind must be android-hprof or memgraph`,ci=Qr.is,li=$r.is,ui=ei.is,di=ti.is,fi=ni.is,pi=1e4,mi=2e3,hi=[`get`,`accept`,`dismiss`,`wait`],gi=`<wifi|airplane|location> <on|off>`,_i=`location set <lat> <lon>`,vi=`animations <on|off>`,yi=`appearance <light|dark|toggle>`,bi=`faceid <match|nonmatch|enroll|unenroll>`,xi=`touchid <match|nonmatch|enroll|unenroll>`,Si=`fingerprint <match|nonmatch>`,Ci=`clear-app-state [app-id]`,wi=`permission <grant|deny|reset> <camera|microphone|photos|contacts|contacts-limited|notifications|calendar|location|location-always|media-library|motion|reminders|siri> [full|limited]`,Ti=`permission <grant|reset> <accessibility|screen-recording|input-monitoring>`,Ei=`macOS supports only settings ${yi} and settings ${Ti}. wifi|airplane|location|animations remain unsupported on macOS.`,Di=[`settings ${gi}`,`settings ${_i}`,`settings ${vi}`,`settings ${yi}`,`settings ${bi}`,`settings ${xi}`,`settings ${Si}`,`settings ${Ci}`,`settings ${wi}`,`settings ${Ti}`].join(` | `),Oi=`settings requires ${gi}, ${_i}, ${vi}, ${yi}, ${bi}, ${xi}, ${Si}, ${Ci}, ${wi}, or ${Ti}`;function ki(e){let t=e.trim().toLowerCase();return t===`appearance`||t===`permission`}function Ai(e){return`Unsupported macOS setting: ${e}. ${Ei}`}function ji(e,t){if(e===void 0||e.trim()===``)throw new n(`INVALID_ARGS`,`settings location set requires ${t}`);return Ni(Number(e),t)}function Mi(e){return{latitude:Ni(e?.latitude,`latitude`),longitude:Ni(e?.longitude,`longitude`)}}function Ni(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}function Pi(e){let t=De(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 Fi(e){return{...e.androidSnapshot?{androidSnapshot:e.androidSnapshot}:{},...e.quality?{snapshotQuality:e.quality}:{},...e.warnings&&e.warnings.length>0?{warnings:e.warnings}:{}}}function Ii(e){let t=Li(e.androidSnapshot),n=Array.isArray(e.warnings)?e.warnings.filter(e=>typeof e==`string`):void 0,r=De(e.snapshotQuality);return Fi({...t?{androidSnapshot:t}:{},...r?{quality:r}:{},...n?{warnings:n}:{}})}function Li(e){return typeof e==`object`&&e?e:void 0}function Ri(e){let t=e.appId??e.bundleId??e.packageName;return{session:e.session,appId:t,appBundleId:e.bundleId,package:e.packageName}}function zi(e,t,n){return{deviceId:t,deviceName:n,...e===`android`?{serial:t}:e===`ios`?{udid:t}:{}}}function Bi(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 Vi(e){return{name:e.name,...e.sessionStateDir?{sessionStateDir:e.sessionStateDir}:{},...e.runnerLogPath?{runnerLogPath:e.runnerLogPath}:{},...Bi(e.device,{includeAndroidSerial:!1}),createdAt:e.createdAt}}function Hi(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 Ui(e){return e.bundleId??e.package??e.app}function Wi(e){return et({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: ${Ui(e)}`)}function Gi(e){return e.appName??e.bundleId??e.packageName??e.launchTarget}function Ki(e){return et({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: ${Gi(e)}`)}function qi(e){let t=e.appName??e.appBundleId??e.session;return et({session:e.session,...e.warnings?.length?{warnings:e.warnings}:{},...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?Bi(e.device):{}},t?`Opened: ${t}`:`Opened`)}function Ji(e){return{session:e.session,...e.shutdown?{shutdown:e.shutdown}:{},...`provider`in e&&e.provider?{provider:e.provider}:{},...C(e.session?`Closed: ${e.session}`:`Closed`)}}function Yi(e){return{nodes:e.nodes,truncated:e.truncated,...e.appName?{appName:e.appName}:{},...e.appBundleId?{appBundleId:e.appBundleId}:{},...e.visibility?{visibility:e.visibility}:{},...Fi(Xi(e)),...e.unchanged?{unchanged:e.unchanged}:{},...e.snapshotDiagnostics?{snapshotDiagnostics:e.snapshotDiagnostics}:{},...e.refsGeneration===void 0?{}:{refsGeneration:e.refsGeneration}}}function Xi(e){return{...e,...e.snapshotQuality?{quality:e.snapshotQuality}:{}}}const Zi=[`primary`,`secondary`,`middle`];function Qi(e){return e?.clickButton??`primary`}function $i(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 ea(e){return e===`primary`?{}:{button:e}}const ta=1e4;function na(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 ra(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 ia(e){return typeof e?.durationMs==`number`?e.durationMs:void 0}const aa=[`up`,`down`,`left`,`right`],oa=[`left`,`right`,`left-edge`,`right-edge`],sa=[`one-way`,`ping-pong`],ca=1e4,la=6e4,ua=B(aa,{message:e=>`Unknown direction: ${e}`});function da(e){let t=e.direction,n=t===`up`||t===`down`?e.referenceHeight:e.referenceWidth,r=xa(e.amount),i=e.pixels===void 0?Math.round(n*r):Sa(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 fa(e){xa(e.amount),e.pixels!==void 0&&Sa(e.pixels)}function pa(e,t){if(e===`left`||e===`right`){let n=ha(e,t);return{preset:e,x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2,referenceWidth:n.referenceWidth,referenceHeight:n.referenceHeight}}let[n,r]=e===`left-edge`?[99,15]:[1,85],i=H(V(t,n,50),t,8),a=H(V(t,r,50),t,8);return{preset:e,x1:i.x,y1:i.y,x2:a.x,y2:a.y,referenceWidth:t.referenceWidth,referenceHeight:t.referenceHeight}}function ma(e,t){switch(e){case`up`:return{x:0,y:-t};case`down`:return{x:0,y:t};case`left`:return{x:-t,y:0};case`right`:return{x:t,y:0}}}function ha(e,t){let n=e===`left`||e===`up`,r=n?85:15,i=n?15:85,a=e===`up`||e===`down`,o=H(V(t,a?50:r,a?r:50),t,8),s=H(V(t,a?50:i,a?i:50),t,8);return{direction:e,x1:o.x,y1:o.y,x2:s.x,y2:s.y,referenceWidth:t.referenceWidth,referenceHeight:t.referenceHeight}}function ga(e){let t=va(e);if(t)return{referenceWidth:t.width,referenceHeight:t.height}}function V(e,t,n){let r=Math.trunc(e.referenceWidth*t/100),i=Math.trunc(e.referenceHeight*n/100);return{x:Number.isFinite(r)?r:0,y:Number.isFinite(i)?i:0}}function H(e,t,n){return{x:Ca(e.x,n,t.referenceWidth),y:Ca(e.y,n,t.referenceHeight)}}function _a(e){return ua.parse(e)}function va(e){let t=e.filter(e=>ya(e.type)&&ba(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(ba);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 ya(e){if(!e)return!1;let t=e.toLowerCase();return t.includes(`application`)||t.includes(`window`)}function ba(e){return!!e&&e.width>0&&e.height>0}function xa(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 Sa(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 Ca(e,t,n){let r=Math.round(t);if(!Number.isFinite(r))return 0;let i=Math.max(r,Math.round(n-t));return!Number.isFinite(i)||!Number.isFinite(e)?r:Math.min(i,Math.max(r,Math.round(e)))}function wa(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 Ta(e,t,n={}){let r=Aa(e??[]);if(r.length===0)return{canScroll:!1,emptySnapshot:!0,signature:``};let i=Ee(r),a=ja(r,i,t,n),o=Ra(a?Na(r,a.index):r);return a?{canScroll:Fa(a,i.get(a.index),t),emptySnapshot:!1,signature:o,scope:Ia(a)}:{canScroll:!1,emptySnapshot:!1,signature:o}}async function Ea(e){let{edge:t,target:n={},scope:r,captureNodes:i}=e;try{let e=Ta(await i(r),t,n);return r&&e.emptySnapshot?await Ea({edge:t,target:n,captureNodes:i}):e}catch(e){throw ka(t,r,e)}}async function Da(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 Oa(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 ka(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 Aa(e){return e.map((e,t)=>({...e,ref:`ref`in e&&e.ref?e.ref:`e${t+1}`}))}function ja(e,t,n,r){let i=new Map(e.map(e=>[e.index,e])),a=e.filter(e=>se(e)&&Ha(e.rect));if(a.length===0)return null;let o=Ma(r.nodeIndex,i);if(o)return o;let s=r.point;if(s){let e=a.filter(e=>e.rect&&Va(e.rect,s)).sort(za);if(e.length>0)return e.find(e=>Fa(e,t.get(e.index),n))??e[0]??null}let c=a.filter(e=>Fa(e,t.get(e.index),n)).sort(Ba);return c.length>0?c[0]??null:a.filter(t=>ee(t,e)).sort(Ba)[0]??a.sort(Ba)[0]??null}function Ma(e,t){if(e===void 0)return null;let n=t.get(e);for(;n;){if(se(n)&&Ha(n.rect))return n;n=n.parentIndex===void 0?void 0:t.get(n.parentIndex)}return null}function Na(e,t){let n=new Map(e.map(e=>[e.index,e]));return e.filter(e=>e.index===t||Pa(e,t,n))}function Pa(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 Fa(e,t,n){return n===`bottom`?e.hiddenContentBelow===!0||t?.hiddenContentBelow===!0:e.hiddenContentAbove===!0||t?.hiddenContentAbove===!0}function Ia(e){return[e.identifier,e.label,e.value].map(e=>typeof e==`string`?e.trim():``).find(La)}function La(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=>Ua(e.rect?.[t])).join(`,`):``;return[String(e.index??``),String(e.parentIndex??``),String(e.type??``),String(e.label??``),String(e.value??``),t].join(`|`)}).join(`
|
|
15
|
+
`)}function za(e,t){return U(e.rect)-U(t.rect)}function Ba(e,t){return U(t.rect)-U(e.rect)}function U(e){return e?e.width*e.height:0}function Va(e,t){return t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height}function Ha(e){return!!(e&&e.width>0&&e.height>0)}function Ua(e){return typeof e==`number`&&Number.isFinite(e)?e.toFixed(1):``}function W(e,t){return{session:t.session,requestId:t.requestId,signal:t.signal??e.signal,metadata:t.metadata}}function G(e){return e.clock?.now()??Date.now()}async function Wa(e,t){e.clock?await e.clock.sleep(t):await new Promise(e=>setTimeout(e,t))}function Ga(e){return e&&typeof e==`object`?e:void 0}function Ka(e){return e}function qa(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 Ja(e,t){return{x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}}function Ya(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 Xa(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function Za(e,t){return(e.x-t.x)**2+(e.y-t.y)**2}function Qa(e,t,n){return Math.min(Math.max(e,t),n)}const $a=[`button`,`link`,`menuitem`,`tabitem`,`textfield`,`searchfield`,`securetextfield`,`checkbox`,`radio`,`switch`,`cell`];function eo(e,t){return to(e,t).node}function to(e,t){if(x(t))return{node:t,reason:`covered`};let n=no(e,t);if(n?.rect&&S(n.rect))return{node:n,reason:`same-rect-descendant`};if(ro(t)&&t.rect&&S(t.rect))return{node:t,reason:`semantic-target`};let r=he(e,t);return r?.rect&&!x(r)&&S(r.rect)?ao(t,r,e)?{node:t,reason:`overly-broad-ancestor`}:{node:r,reason:`hittable-ancestor`}:{node:t,reason:`original`}}function no(e,t){let n=b(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||x(e))return!1;let t=b(e.rect);return t?ke(t,n):!1});if(t.length!==1)break;r=t[0]}return r===t?null:r}function ro(e){return[e.type,e.role,e.subrole].map(e=>_(e??``)).some(io)}function io(e){return e===`tab`||$a.some(t=>e.includes(t))}function ao(e,t,n){let r=b(e.rect),i=b(t.rect);if(!r||!i)return!1;let a=oo(n,r);return!a||!so(i,a)?!1:!ke(r,i)}function oo(e,t){let n=s(t),r=e.filter(e=>{let t=(e.type??``).toLowerCase();return t.includes(`application`)||t.includes(`window`)}).map(e=>b(e.rect)).filter(e=>e!==null);if(r.length===0)return null;let i=r.filter(e=>te(e,n.x,n.y));return ie(i.length>0?i:r)}function so(e,t){let n=Ya(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}function co(e){return e.hittable===!0||ro(e)}function lo(e,t){let n=me(v(e),t);return n.id!==void 0||n.label!==void 0?!1:ve(e.value)===null}function uo(e){let t=new Map;for(let n of e)t.set(n.index,n);return t}function fo(e,t,n){let r=new Set,i=e;for(;typeof i.parentIndex==`number`;){if(r.has(i.index))return!1;if(r.add(i.index),i.parentIndex===t.index)return!0;let e=n.get(i.parentIndex);if(!e)return!1;i=e}return!1}function po(e,t){let n=uo(t);return t.filter(t=>t.index!==e.index&&fo(t,e,n)).sort((e,t)=>e.index-t.index)}function mo(e,t){let n=S(e.rect);return!n||!t.rect?!1:te(t.rect,n.x,n.y)}function ho(e,t){if(!lo(e,t))return e;let n=po(e,t);if(n.some(co))return e;let r=n.find(e=>v(e).label!==void 0);return!r||!mo(r,e)?e:r}function go(e,t){if(Buffer.byteLength(e,`utf8`)<=t)return e;let n=Buffer.byteLength(`…`,`utf8`),r=Math.max(0,t-n),i=Buffer.from(e,`utf8`),a=Math.min(r,i.length);for(;a>0&&(i[a]&192)==128;)--a;return i.subarray(0,a).toString(`utf8`)+`…`}function _o(e,t,r,i){if(!r)return;let a=v(e),o=Se(e,t);if(!(de(a,r.identity)&&ge(o,r.structural)))throw new n(`COMMAND_FAILED`,`${i} resolved to a different element than replay verification isolated; the action was not sent`,{reason:be,observed:a,observedStructural:o,expected:r.identity,expectedStructural:r.structural})}async function vo(e,t,n){return await Lo(e,t,n.action),t.target.kind===`point`?await bo(e,t,t.target,n):t.target.kind===`ref`?await So(e,t,t.target,n):await Co(e,t,t.target,n)}async function yo(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=ye(i.snapshot.nodes,a);if(!o)return;let s={x:n.x,y:n.y};if(!te(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 bo(e,t,n,r){let i=await yo(e,t,n);if(!r.captureEvidenceBaseline)return{kind:`point`,point:{x:n.x,y:n.y},...i?{warning:i}:{}};let a=await xo(e,t);return{kind:`point`,point:{x:n.x,y:n.y},...a?{preActionNodes:a}:{},...i?{warning:i}:{}}}async function xo(e,t){try{return(await K(e,t,!0)).snapshot.nodes}catch{return}}async function So(e,t,n,r){let i=await zo(e,t,n),a=i.resolved;_o(a.node,i.snapshot.nodes,r.expectedResolvedTarget,r.action);let o=r.promoteToHittableAncestor?No(i.snapshot.nodes,a.node,{action:r.action,label:`Ref ${n.ref}`}):a.node;return Po(o,`Ref ${n.ref}`,r.action),Go(o,i.snapshot.nodes,n.ref,r.action),{kind:`ref`,point:Ho(o,`Ref ${n.ref} not found or has invalid bounds`),target:{kind:`ref`,ref:`@${a.ref}`},...ko(e,o,i.snapshot.nodes,r.action,a.resolution)}}async function Co(e,t,r,i){let a=l(r.selector),o=await K(e,t,i.requireInteractive),s=_e(Mo(o.snapshot.nodes),a,{platform:e.backend.platform,requireRect:!0,requireUnique:!0,disambiguateAmbiguous:!0});if((!s||!s.node.rect)&&i.requireInteractive&&(o=await K(e,t,!1),s=_e(Mo(o.snapshot.nodes),a,{platform:e.backend.platform,requireRect:!0,requireUnique:!0,disambiguateAmbiguous:!0})),!s||!s.node.rect){let t=_e(o.snapshot.nodes,a,{platform:e.backend.platform,requireRect:!0,requireUnique:!1});throw t?.node&&x(t.node)?Fo({label:`Selector ${t.selector.raw}`,node:t.node,action:i.action,selector:t.selector.raw}):new n(`COMMAND_FAILED`,fe(a,s?.diagnostics??[],{unique:!0}),{hint:pe(s?.diagnostics??[])})}_o(s.node,o.snapshot.nodes,i.expectedResolvedTarget,i.action);let c=i.promoteToHittableAncestor?No(o.snapshot.nodes,s.node,{action:i.action,label:`Selector ${s.selector.raw}`}):s.node;return Po(c,`Selector ${s.selector.raw}`,i.action),Wo(c,o.snapshot.nodes,s.selector.raw,i.action),{kind:`selector`,point:Ho(c,`Selector ${s.selector.raw} resolved to invalid bounds`),target:{kind:`selector`,selector:s.selector.raw},...ko(e,c,o.snapshot.nodes,i.action,Do(s,o.snapshot.nodes))}}const wo={source:`ref`,phase:`pre-action`,kind:`exact`},To={source:`ref`,phase:`pre-action`,kind:`label-fallback`},Eo={source:`runtime`,phase:`pre-action`,kind:`unique`};function Do(e,t){return e.disambiguation?{source:`runtime`,phase:`pre-action`,kind:`disambiguated`,matchCount:e.disambiguation.matchCount,winnerDiagnostic:Oo(e.node,t),tiebreak:e.disambiguation.tiebreak,alternatives:e.disambiguation.alternatives.slice(0,5).map(e=>Oo(e,t))}:Eo}function Oo(e,t){let n=_(e.type??``),r=ae(e,t);return{diagnosticRef:`diag-${e.ref}`,...n?{role:go(n,256)}:{},...r===void 0?{}:{label:go(r,256)}}}function ko(e,t,n,r,i){return{node:t,selectorChain:Ce(t,e.backend.platform,{action:r===`fill`?`fill`:`click`,nodes:n}),refLabel:ae(t,n),...jo(t,r),preActionNodes:n,resolution:i,...Ao(e,t,n,r)}}function Ao(e,t,n,r){if(r!==`click`&&r!==`press`)return{};let i=ho(t,n);return i===t?{}:{recordingTarget:{node:i,selectorChain:Ce(i,e.backend.platform,{action:`click`,nodes:n}),refLabel:ae(i,n)}}}function jo(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 Mo(e){return e.filter(e=>!x(e))}function No(e,t,n){let r=to(e,t);if(r.reason===`covered`)throw Fo({label:n.label,node:t,action:n.action});return r.node}function Po(e,t,n){if(x(e))throw Fo({label:t,node:e,action:n})}function Fo(e){return new n(`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 K(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(W(e,t),{interactiveOnly:r,includeRects:!0}),s=o.snapshot??{nodes:o.nodes??[],truncated:o.truncated,backend:o.backend,createdAt:G(e)};return await e.sessions.set({...a,snapshot:s}),{snapshot:s}}async function Lo(e,t,r){if(e.backend.platform!==`macos`)return;let i=await Ro(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 Ro(e,t){return(await e.sessions.get(t.session??`default`))?.metadata?.surface}async function zo(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.`);let o=a.refFrameSnapshot??a.snapshot;if(!o)throw new n(`INVALID_ARGS`,`No snapshot in session. Run snapshot first.`);let s=r.fallbackLabel??``,c=Vo(o.nodes,r.ref,{fallbackLabel:s});if(!c)throw new n(`COMMAND_FAILED`,`Ref ${r.ref} not found or has no bounds`,{hint:Te});return Bo({session:a,frameTree:o,target:r,fallbackLabel:s,authorized:c})}function Bo(e){let{session:t,frameTree:n,target:r,fallbackLabel:i,authorized:a}=e,o=t.snapshot;if(!o||o===n)return{snapshot:n,resolved:a};let s=Vo(o.nodes,r.ref,{fallbackLabel:i});return s&&de(v(a.node),v(s.node))?{snapshot:o,resolved:s}:{snapshot:n,resolved:a}}function Vo(e,t,i){let a=o(t);if(!a)throw new n(`INVALID_ARGS`,`Invalid ref: ${t}`);let s=r(e,a);if(Uo(s))return{ref:a,node:s,resolution:wo};let c=i.fallbackLabel.length>0?g(e,i.fallbackLabel):null;return Uo(c)?{ref:a,node:c,resolution:To}:null}function Ho(e,t){let r=S(e.rect);if(!r)throw new n(`COMMAND_FAILED`,t);return r}function Uo(e){return e?S(e.rect)!==null:!1}function Wo(e,t,n,r){qo(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 Go(e,t,n,r){qo(e,t,{message:`Ref ${n} is off-screen and not safe to ${r}`,details:{reason:`offscreen_ref`,ref:o(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 Ko(e,t,n,r){let i=(await e.sessions.get(t.session??`default`))?.snapshot?.nodes;if(!i||o(n.ref)===null)return{};let a=Vo(i,n.ref,{fallbackLabel:n.fallbackLabel??``});return a?(Po(a.node,`Ref ${n.ref}`,r),Go(a.node,i,n.ref,r),{...jo(a.node,r),node:a.node,preActionNodes:i}):{}}function qo(e,t,r){let i=e.rect?ne(e,t):null;if(!(!e.rect||!i||ce(e,t)))throw new n(`COMMAND_FAILED`,r.message,{...r.details,rect:e.rect,viewport:i,hint:r.hint})}function Jo(e){let t=Buffer.alloc(16);for(let n of e)Xo(t,Yo(n));return{digest:`ax1:${Me(`sha256`).update(t).update(`\0`).update(String(e.length)).digest(`hex`).slice(0,16)}`,nodeCount:e.length}}function Yo(e){return Me(`sha256`).update(e.type??``).update(`\0`).update(e.label??``).update(`\0`).update(e.identifier??``).digest().subarray(0,16)}function Xo(e,t){for(let n=0;n<e.length;n+=1)e[n]=(e[n]??0)^(t[n]??0)}function Zo(e){let{digest:t,nodeCount:n}=Jo(e),r=e.reduce((e,t)=>t.hittable===!1?e:e+1,0),i=Qo(e);return{digest:t,nodeCount:n,interactiveNodeCount:r,...i?{foregroundApp:i}:{}}}function Qo(e){for(let t of e)if(t.bundleId)return t.bundleId;for(let t of e)if(t.appName)return t.appName}function $o(e,t){let n=M(e.type??`Element`),r=j(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 es(e,t,n={}){let r=rs(ns(e,n),ns(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 ts(e,t={}){return ns(e,t).length}function ns(e,t){return t.flatten?e.map(e=>({text:yn(e,0,!1),comparable:$o(e,0),...t.withRefs&&e.ref?{ref:e.ref}:{}})):vn(e).map(e=>({text:e.text,comparable:$o(e.node,e.depth),...t.withRefs&&e.node.ref?{ref:e.node.ref}:{}}))}function rs(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=as(a,i,s)?q(a,i+1):q(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 is(o,e,t,n,r)}}return[]}function is(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=as(i,c,r)?c+1:c-1,u=q(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 as(e,t,n){return t===-n||t!==n&&q(e,t-1)<q(e,t+1)}function q(e,t){return e.get(t)??0}const os=new Set([`textfield`,`securetextfield`,`textview`,`textarea`,`searchfield`,`edittext`]),ss={strippedIndexes:new Set,refs:new Set};function cs(e){let t=new Set(e.filter(e=>_(e.type??``)===`keyboard`).map(e=>e.index));if(t.size===0)return ss;let n=new Map(e.map(e=>[e.index,e])),r=ps(e,n,t),i=new Set(r),a=bs(e,n,r);for(let t of ps(e,n,a))i.add(t);for(let o of ls(e,n,a,t,r))i.delete(o);let o=new Set(e.filter(e=>e.ref&&i.has(e.index)).map(e=>e.ref));return{strippedIndexes:new Set([...i].filter(e=>!t.has(e))),refs:o}}function ls(e,t,n,r,i){let a=new Set;if(n.size===0)return a;let o=ds(t,n,r);if(o.size===0)return a;let s=fs(t,r);for(let n of e)!i.has(n.index)&&!s.has(n.index)&&n.rect&&us(n,t,o)&&a.add(n.index);return a}function us(e,t,n){if(!e.rect)return!1;let r=xs(e,t);if(r===void 0)return!1;let i=n.get(r);return i!==void 0&&e.rect.y+e.rect.height/2<i}function ds(e,t,n){let r=new Map;for(let i of n){let n=e.get(i);if(!n?.rect)continue;let a=xs(n,e);if(a===void 0||!t.has(a))continue;let o=r.get(a);(o===void 0||n.rect.y<o)&&r.set(a,n.rect.y)}return r}function fs(e,t){let n=new Set;for(let r of t){let t=e.get(r),i=t&&typeof t.parentIndex==`number`?e.get(t.parentIndex):void 0;for(;i;)n.add(i.index),i=typeof i.parentIndex==`number`?e.get(i.parentIndex):void 0}return n}function ps(e,t,n){let r=new Set(n);if(n.size===0)return r;for(let i of e)Ss(i,t,n)&&r.add(i.index);return r}function ms(e){return je(e.identifier??``)}function hs(e,t){let n=new Map(e.map(e=>[e.index,e])),r=new Set(e.filter(e=>Ae(e)).map(e=>e.index)),i=new Set([...r].filter(e=>{let t=n.get(e)?.parentIndex,i=t===void 0?void 0:n.get(t);return!i||!r.has(i.index)})),a=t===`com.android.systemui`?new Set:gs(e,n,r),o=new Set([...r].filter(e=>!i.has(e)));for(let e of a)o.add(e);let s=new Set(e.filter(e=>e.ref&&(r.has(e.index)||a.has(e.index))).map(e=>e.ref));return o.size===0&&s.size===0?ss:{strippedIndexes:o,refs:s}}function gs(e,t,n){let r=new Set(e.filter(e=>e.bundleId===`com.android.systemui`&&!n.has(e.index)).map(e=>e.index));if(r.size===0)return new Set;let i=new Map,a=e=>{let n=i.get(e);if(n!==void 0)return n;let o=t.get(e)?.parentIndex,s=o!==void 0&&r.has(o)?a(o):e;return i.set(e,s),s},o=new Set([...r].filter(e=>{let n=t.get(e);return n!==void 0&&ms(n)}).map(e=>a(e)));return new Set([...r].filter(e=>o.has(a(e))))}function _s(e,t){let n=cs(e),r=hs(e,t);return n.strippedIndexes.size===0&&n.refs.size===0?r:r.strippedIndexes.size===0&&r.refs.size===0?n:{strippedIndexes:new Set([...n.strippedIndexes,...r.strippedIndexes]),refs:new Set([...n.refs,...r.refs])}}function vs(e,t){let{strippedIndexes:n}=_s(e,t);return n.size===0?e:e.filter(e=>!n.has(e.index))}function ys(e,t){return _s(e,t).refs}function bs(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=xs(n,t);i!==void 0&&r.add(i)}for(let i of r){let a=new Set([i]);e.some(e=>os.has(_(e.type??``))&&!n.has(e.index)&&Ss(e,t,a))&&r.delete(i)}return r}function xs(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 Ss(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 Cs(e){return e===`text`||e===`label`||e===`any`}async function ws(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.`);let a=i.refFrameSnapshot??i.snapshot;if(!a)throw new n(`INVALID_ARGS`,`No snapshot in session. Run snapshot first.`);return{sessionName:r,session:i,snapshot:a}}async function Ts(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(W(e,t),{interactiveOnly:r.interactiveOnly??!1,depth:t.depth,scope:r.scope??t.scope,raw:t.raw,includeRects:r.includeRects,...r.includeHiddenContentHints===void 0?{}:{includeHiddenContentHints:r.includeHiddenContentHints}}),c=s.snapshot??{nodes:s.nodes??[],truncated:s.truncated,backend:s.backend,...s.quality?{snapshotQuality:s.quality}:{},createdAt:G(e)};return r.updateSession&&o&&!Oe(c.snapshotQuality)&&await e.sessions.set({...o,snapshot:c}),{sessionName:a,session:o,snapshot:c}}async function Es(e,t,n){if(e.backend.readText){let r=await e.backend.readText(W(e,{session:t.sessionName}),n);if(r.text.trim())return r.text}return le(n)}function Ds(e,t,i){let a=o(t);if(!a)throw new n(`INVALID_ARGS`,i.invalidRefMessage);let s=r(e,a)??(i.fallbackLabel.length>0?g(e,i.fallbackLabel):null);if(!s)throw new n(`COMMAND_FAILED`,i.notFoundMessage);return{ref:a,node:s}}const Os=`Settled on a nearly-empty tree — the app may still be loading. Wait for specific content (wait text ...) before interacting.`;async function ks(e,t,n){let{quietMs:r,timeoutMs:i}=n,a=G(e),o=a+i,s=!1,c=Math.min(300,Math.max(25,r)),l=0,u,d=0,f,p=a;for(;G(e)<o;){let m=await Ms(e,t,o-G(e));if(!m)return{settled:!1,stalled:!0,waitedMs:G(e)-a,captures:l,nodeCount:d,lastCapture:f};l+=1,f=m;let h=Ns(m.snapshot.nodes),g=G(e);if(n.resetBudgetOnPrivateAxRecovery===!0&&!s&&As(m.snapshot.snapshotQuality)){s=!0,o=Math.max(o,g+i),p=g,u=h,d=m.snapshot.nodes.length;let t=js({nowMs:g,quietSinceMs:p,quietMs:r,pollMs:c,deadlineMs:o});if(t<=0)break;await Wa(e,t);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};let ee=js({nowMs:g,quietSinceMs:p,quietMs:r,pollMs:c,deadlineMs:o});if(ee<=0)break;await Wa(e,ee)}return{settled:!1,stalled:!1,waitedMs:G(e)-a,captures:l,nodeCount:d,lastCapture:f}}function As(e){return e?.state===`recovered`&&e.backend===`private-ax`}function js(e){let t=e.quietSinceMs+e.quietMs-e.nowMs,n=t>e.pollMs?e.pollMs:Math.max(25,t+2),r=e.deadlineMs-e.nowMs,i=r-1;return i<2?r>=2?r:0:Math.min(n,i)}async function Ms(e,t,n){let r=Ts(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 Ns(e){return e.map(Ps).join(`|`)}function Ps(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 Fs=`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.`,Is=`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 Ls(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 ks(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?Is:Fs}};let{stored:c,session:l}=await Js(e,t,o.lastCapture),u=o.lastCapture.snapshot.nodes;return{observation:{...s,...o.settled&&c?Vs(zs(n.resolved),u,n.resolved.point,l?.appBundleId):{},...qs(o,c,u.length)},settledNodes:u}}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 Rs(e,t){if(!e)return;let n=Zo(e),r=t!==void 0&&n.digest!==Zo(t).digest;return{...n,changedFromBefore:r}}function zs(e){return`preActionNodes`in e&&e.preActionNodes?e.preActionNodes:[]}function Bs(e,t,n){let r=es(vs(e,n),vs(t,n),{flatten:!0,withRefs:!0}),i=r.lines.filter(e=>e.kind!==`unchanged`),a=Ks(i).map(e=>({kind:e.kind,text:e.text,...e.ref?{ref:e.ref}:{}}));return{summary:r.summary,lines:a,...i.length>a.length?{truncated:!0}:{}}}function Vs(e,t,n,r){let i=Bs(e,t,r);return{diff:i,...Hs(i,t,n,r)}}function Hs(e,t,n,r){let i=new Set(e.lines.filter(e=>e.kind===`added`&&e.ref).map(e=>e.ref)),a=ys(t,r),o=new Map(t.filter(e=>e.ref).map(e=>[e.ref,e]));return[...i].some(e=>e!==void 0&&!a.has(e)&&!Us(o.get(e),n))?{}:Gs(t,i,r)}function Us(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 Ws=new Set([`application`,`window`]);function Gs(e,t,n){let r=ys(e,n),i=e.filter(e=>e.ref&&e.interactionBlocked!==`covered`&&!t.has(e.ref)&&!r.has(e.ref)&&!Ws.has(M(e.type??`Element`)));if(i.length===0)return{};let a=i.slice(0,20).map(e=>{let t=M(e.type??`Element`),n=j(e,t);return{ref:e.ref,role:t,...n?{label:n}:{}}});return{tail:a,...i.length>a.length?{tailTruncated:!0}:{}}}function Ks(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 qs(e,t,n){return e.stalled?{hint:Is}:e.settled?t?n<5?{hint:Os}:{}:{hint:`Settled on a sparse, unreadable tree — the diff is omitted. Use screenshot as visual truth before interacting further.`}:{hint:Fs}}async function Js(e,t,n){if(Oe(n.snapshot.snapshotQuality))return{stored:!1};let r=await e.sessions.get(t.session??`default`);return r?(await e.sessions.set({...r,snapshot:n.snapshot}),{stored:!0,session:r}):{stored:!1}}function Ys(e){let t=e.verify===!0;return{verify:t,needsPreActionBaseline:t||e.settle!==void 0,...e.settle===void 0?{}:{settle:e.settle}}}async function Xs(e,t,n,r,i){let a=await Zs(e,t,n,i);return $s({...r,...a})}async function Zs(e,t,n,r){if(r.settle!==void 0){let i=await Ls(e,t,{...r.settle,resolved:n}),a=r.verify?Rs(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 Qs(e,t,n);return i?{evidence:i}:{}}async function Qs(e,t,n){let r=`preActionNodes`in n?n.preActionNodes:void 0;try{let n=Zo((await K(e,t,!0)).snapshot.nodes),i=r!==void 0&&n.digest!==Zo(r).digest;return{...n,changedFromBefore:i}}catch{return}}function $s(e){let t=e;if(t.targetHittable!==!1||!ec(t)||t.hint===void 0)return e;let{hint:n,...r}=t;return r}function ec(e){if(e.evidence?.changedFromBefore===!0)return!0;let t=e.settle?.diff?.summary;return!!t&&(t.additions>0||t.removals>0)}const tc=[`up`,`down`,`left`,`right`,`top`,`bottom`],nc=async(e,t)=>{let r=await vo(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=cc(r),a=Ga(await e.backend.focus(W(e,t),i));return{...r,...a?{backendResult:a}:{},...C(`Focused (${i.x}, ${i.y})`)}},rc=async(e,t)=>{let r=Ys(t),i=await vo(e,t,{action:`longPress`,requireInteractive:!0,promoteToHittableAncestor:!0,captureEvidenceBaseline:r.needsPreActionBaseline,expectedResolvedTarget:t.expectedResolvedTarget});if(!e.backend.longPress)throw new n(`UNSUPPORTED_OPERATION`,`longPress is not supported by this backend`);let a=t.durationMs===void 0?void 0:wa(t.durationMs,`durationMs`,0,12e4),o=cc(i),s=Ga(await e.backend.longPress(W(e,t),o,{durationMs:a}));return await Xs(e,t,i,{...i,...a===void 0?{}:{durationMs:a},...s?{backendResult:s}:{},...C(`Long pressed (${o.x}, ${o.y})`)},r)},ic=async(e,t)=>{if(!e.backend.scroll)throw new n(`UNSUPPORTED_OPERATION`,`scroll is not supported by this backend`);let r=oc(t.direction),i=dc(t.amount,`scroll amount`),a=pc(t.pixels,`scroll pixels`),o=ra(t.durationMs);na({amount:i,pixels:a},`scroll accepts either amount or pixels, not both`);let s=await ac(e,t),c=s.kind===`viewport`?{kind:`viewport`}:{kind:`point`,point:cc(s)},l=e.backend.scroll,u=async()=>await l(W(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=sc(s),a=await Da({edge:n,captureState:async r=>await lc(e,t,n,i,r),scroll:u});d=a.result,f=a.passes}else d=await u(),f=1;let p=Ga(d),m=ia(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}:{},...C(Oa(r.direction,r.edge,f,i,a))}};async function ac(e,t){let n=t.target??{kind:`viewport`};return n.kind===`viewport`?(await Lo(e,t,`scroll`),{kind:`viewport`}):await vo(e,{...t,target:n},{action:`scroll`,requireInteractive:!1,promoteToHittableAncestor:!1})}function oc(e){return e===`bottom`?{direction:`down`,edge:`bottom`}:e===`top`?{direction:`up`,edge:`top`}:{direction:uc(e,`scroll direction`)}}function sc(e){return e.kind===`viewport`?{}:{point:e.point,nodeIndex:`node`in e?e.node?.index:void 0}}function cc(e){if(!e.point)throw new n(`COMMAND_FAILED`,`Interaction target resolved without coordinates`);return e.point}async function lc(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 Ea({edge:r,target:i,scope:a,captureNodes:async n=>{let r=await o(W(e,t),{scope:n});return r.snapshot?.nodes??r.nodes??[]}})}function uc(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 dc(e,t){return e===void 0?void 0:fc(e,t)}function fc(e,t){if(!Number.isFinite(e)||e<=0)throw new n(`INVALID_ARGS`,`${t} must be a positive number`);return e}function pc(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}}const mc=1e4,hc=[`pan`,`fling`,`swipe`,`pinch`,`rotate`,`transform`];function J(e){let t=_c(e),r=yc(t,`kind`,hc);if(r===`pan`)return{kind:r,origin:Y(t,`origin`),delta:Y(t,`delta`),pointerCount:z(t,`pointerCount`,{min:1,max:2}),durationMs:gc(t)};if(t.pointerCount!==void 0)throw new n(`INVALID_ARGS`,`pointerCount is supported only for gesture pan`);if(r===`fling`){if(t.durationMs!==void 0)throw new n(`INVALID_ARGS`,`gesture fling does not accept durationMs; use gesture pan for timed movement`);return{kind:r,direction:yc(t,`direction`,aa),origin:Y(t,`origin`),distance:z(t,`distance`,{min:0})}}if(r===`swipe`){if(t.durationMs!==void 0)throw new n(`INVALID_ARGS`,`gesture swipe does not accept durationMs; use gesture pan for timed movement`);return{kind:r,preset:yc(t,`preset`,oa)}}if(r===`pinch`)return{kind:r,scale:X(t,`scale`),origin:vc(t,`origin`)};if(r===`rotate`){if(t.velocity!==void 0)throw new n(`INVALID_ARGS`,`gesture rotate does not accept velocity; rotation pacing derives from degrees`);return{kind:r,degrees:X(t,`degrees`),origin:vc(t,`origin`)}}return{kind:r,origin:Y(t,`origin`),delta:Y(t,`delta`),scale:X(t,`scale`),degrees:X(t,`degrees`),durationMs:gc(t)}}function gc(e){let t=z(e,`durationMs`);if(t!==void 0){if(t<16||t>1e4)throw new n(`INVALID_ARGS`,`Expected durationMs to be an integer between 16 and ${mc}.`);return t}}function _c(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new n(`INVALID_ARGS`,`gesture requires structured object input`);return e}function Y(e,t){let n=_c(e[t]);return{x:X(n,`x`),y:X(n,`y`)}}function vc(e,t){return e[t]===void 0?void 0:Y(e,t)}function X(e,t){let r=e[t];if(typeof r!=`number`||!Number.isFinite(r))throw new n(`INVALID_ARGS`,`Expected ${t} to be a finite number.`);return r}function yc(e,t,r){let i=e[t];if(typeof i!=`string`||!r.includes(i))throw new n(`INVALID_ARGS`,`Expected ${t} to be one of: ${r.join(`, `)}.`);return i}function Z(e,t,r){if(e.length>t)throw new n(`INVALID_ARGS`,r)}function bc(e){return{origin:{x:Number(e[0]),y:Number(e[1])},delta:{x:Number(e[2]),y:Number(e[3])}}}function xc(e,t){let n=e[0],r=e.slice(1);switch(n){case`pan`:{Z(r,5,`gesture pan accepts at most 5 arguments: x y dx dy [durationMs]`);let{origin:e,delta:i}=bc(r);return J({kind:n,origin:e,delta:i,pointerCount:t,durationMs:Ec(r[4])})}case`fling`:return Z(r,4,`gesture fling accepts at most 4 arguments: direction x y [distance]; for timed movement use gesture pan`),J({kind:n,direction:r[0],origin:{x:Number(r[1]),y:Number(r[2])},distance:Ec(r[3])});case`swipe`:return Z(r,1,`gesture swipe accepts 1 argument: preset; for timed movement use gesture pan`),J({kind:n,preset:r[0]});case`pinch`:return Z(r,3,`gesture pinch accepts at most 3 arguments: scale [x] [y]`),J({kind:n,scale:Number(r[0]),origin:Dc(r[1],r[2])});case`rotate`:return Z(r,3,`gesture rotate accepts at most 3 arguments: degrees [x] [y]`),J({kind:n,degrees:Number(r[0]),origin:Dc(r[1],r[2])});case`transform`:{Z(r,7,`gesture transform accepts at most 7 arguments: x y dx dy scale degrees [durationMs]`);let{origin:e,delta:t}=bc(r);return J({kind:n,origin:e,delta:t,scale:Number(r[4]),degrees:Number(r[5]),durationMs:Ec(r[6])})}default:return J({kind:n})}}function Sc(e){switch(e.kind){case`pan`:return Q([e.kind,e.origin.x,e.origin.y,e.delta.x,e.delta.y,e.durationMs]);case`fling`:return Q([e.kind,e.direction,e.origin.x,e.origin.y,e.distance]);case`swipe`:return[e.kind,e.preset];case`pinch`:return Q([e.kind,e.scale,e.origin?.x,e.origin?.y]);case`rotate`:return e.origin?Q([e.kind,e.degrees,e.origin.x,e.origin.y]):[e.kind,String(e.degrees)];case`transform`:return Q([e.kind,e.origin.x,e.origin.y,e.delta.x,e.delta.y,e.scale,e.degrees,e.durationMs])}}function Cc(e,t={}){if(e.length>4)throw new n(`INVALID_ARGS`,`swipe accepts 4 arguments: x1 y1 x2 y2; for timed movement use gesture pan`);return{from:{x:Number(e[0]),y:Number(e[1])},to:{x:Number(e[2]),y:Number(e[3])},...t.count===void 0?{}:{count:t.count},...t.pauseMs===void 0?{}:{pauseMs:t.pauseMs},...t.pattern===void 0?{}:{pattern:t.pattern}}}function wc(e){switch(e.kind){case`pan`:return{gesture:{intent:`pan`,origin:e.origin,delta:e.delta,pointerCount:e.pointerCount,durationMs:e.durationMs}};case`fling`:return{gesture:{intent:`fling`,direction:e.direction,origin:e.origin,distance:e.distance}};case`swipe`:return{gesture:{intent:`fling`,preset:e.preset}};case`pinch`:return{gesture:{intent:`pinch`,origin:e.origin,scale:e.scale}};case`rotate`:return{gesture:{intent:`rotate`,origin:e.origin,degrees:e.degrees}};case`transform`:return{gesture:{intent:`transform`,origin:e.origin,delta:e.delta,scale:e.scale,degrees:e.degrees,durationMs:e.durationMs}}}}function Tc(e){return{gesture:{intent:`fling`,from:e.from,to:e.to}}}function Ec(e){return e===void 0?void 0:Number(e)}function Dc(e,t){if(e===void 0!=(t===void 0))throw new n(`INVALID_ARGS`,`gesture origin requires both x and y coordinates`);return e===void 0?void 0:{x:Number(e),y:Number(t)}}function Q(e){return e.filter(e=>e!==void 0).map(String)}const Oc=/^e\d+$/;function kc(e){if(e[0]?.startsWith(`@`)){let t=Rc(e.slice(1));return{ref:e[0],...t===void 0?{}:{label:t}}}if(Oc.test(e[0]??``))throw new n(`INVALID_ARGS`,`Did you mean "@${e[0]}"? Snapshot refs need the @ prefix.`);let t=u(e);if(t){if(t.rest.length>0)throw new n(`INVALID_ARGS`,Fc(e,t));return{selector:t.selectorExpression}}return jc(e)}function Ac(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?Rc(e.slice(1,2)):void 0},text:n}}if(Oc.test(t??``))throw new n(`INVALID_ARGS`,`Did you mean "@${t}"? Snapshot refs need the @ prefix.`);let r=u(e,{preferTrailingValue:!0});return r?{kind:`selector`,target:{selector:r.selectorExpression},text:r.rest.join(` `)}:{kind:`point`,target:jc(e.slice(0,2)),text:e.slice(2).join(` `)}}function jc(e){let t=e[0]??``,r=p(t);if(r){let i=Mc(t)?r.value:[r.value,...e.slice(1)].join(` `).trim();throw new n(`INVALID_ARGS`,Nc({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`,Pc(e))}function Mc(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 Nc(e){let{key:t,value:n}=e;return`Unknown selector key "${t}". Supported: ${d.join(`, `)}. ${c(t)?`Did you mean role=${t} label=${Lc(n)}?`:`Did you mean label=${Lc(n)}?`}`}function Pc(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=>f(e??``))?`${n} Selector values with spaces need quotes, e.g. text="Sign in".`:`${n} To match by visible text, use text=${Lc(t)} (or label=/id=/role=), or pass an @ref from snapshot.`}function Fc(e,t){return`${`Selector ${t.selectorExpression} is followed by unexpected extra arguments: "${t.rest.join(` `)}".`} Selector values with spaces need quotes, e.g. ${Ic(e,t)??`text="Sign in"`}.`}function Ic(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)}${Lc(a)}`;return[...e.slice(0,n-1),o].join(` `)}function Lc(e){return`"${e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`)}"`}function Rc(e){return e.join(` `).trim()||void 0}function zc(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 Bc=[`path`,`start`,`stop`,`doctor`,`mark`,`clear`],Vc=[`medium`,`high`],Hc=`medium`;function Uc(e){return Vc.includes(e)}function Wc(e){let t=typeof e==`number`?e:Gc(e);return t!==void 0&&Number.isInteger(t)&&t>=5&&t<=10?t:void 0}function Gc(e){return typeof e==`string`&&/^\d+$/.test(e)?Number(e):void 0}function Kc(e){if(Uc(e))return e;let t=Wc(e);if(t!==void 0)return t<=7?`medium`:`high`}const qc=[`portrait`,`portrait-upside-down`,`landscape-left`,`landscape-right`];function Jc(e){if(e===void 0)throw new n(`INVALID_ARGS`,`orientation 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 Yc={android:`longpress`,apple:`exact`},Xc={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(Xc),Zc=`<${$.join(`|`)}>`;function Qc(e){let t=e?.toLowerCase();if($c(t))return t;let r=t?rl.get(t):void 0;if(r)return r;throw new n(`INVALID_ARGS`,`tv-remote button must be one of: ${$.join(`, `)}.`)}function $c(e){return typeof e==`string`&&$.includes(e)}function el(e){return Xc[e].appleRemoteButton}function tl(e){return Xc[e].androidKeyevent}function nl(e){return Yc[e]}const rl=new Map($.flatMap(e=>Xc[e].aliases.map(t=>[t,e])));export{Za as $,Xe as $n,Jr as $t,Os as A,Cr as An,zi as At,wo as B,j as Bn,Fi as Bt,mc as C,Mr as Cn,ia as Ct,ic as D,Fr as Dn,$i as Dt,rc as E,Nr as En,ea as Et,Ds as F,Gn as Fn,Hi as Ft,vo as G,Ut as Gn,Oi as Gt,Lo as H,Jt as Hn,Pi as Ht,Cs as I,Mn as In,Ki as It,Qa as J,et as Jn,ki as Jt,eo as K,tt as Kn,Di as Kt,ys as L,jn as Ln,qi as Lt,Ts as M,xr as Mn,Gi as Mt,Es as N,F as Nn,Ji as Nt,Xs as O,Pr as On,Qi as Ot,ws as P,Kn as Pn,Wi as Pt,Xa as Q,Ye as Qn,ii as Qt,es as R,An as Rn,Vi as Rt,J as S,Or as Sn,na as St,nc as T,Ir as Tn,Zi as Tt,K as U,Wt as Un,ji as Ut,_o as V,M as Vn,Ii as Vt,Ko as W,Xt as Wn,Mi as Wt,Ya as X,He as Xn,mi as Xt,Ja as Y,Ue as Yn,hi as Yt,Ka as Z,We as Zn,pi as Zt,Sc as _,z as _n,pa as _t,el as a,ai as an,ze as ar,Ea as at,Cc as b,Lr as bn,_a as bt,Jc as c,ci as cn,wa as ct,Kc as d,ui as dn,ca as dt,ri as en,Je as er,qa as et,Bc as f,Wr as fn,oa as ft,xc as g,Vr as gn,da as gt,kc as h,Br as hn,ha as ht,tl as i,si as in,Be as ir,W as it,ks as j,Sr as jn,Ui as jt,Ys as k,Ar as kn,Ri as kt,Hc as l,di as ln,aa as lt,Ac as m,Ur as mn,fa as mt,Zc as n,oi as nn,Ie as nr,G as nt,nl as o,Yr as on,Oa as ot,zc as p,Kr as pn,la as pt,to as q,C as qn,Ai as qt,Qc as r,Xr as rn,Fe as rr,Wa as rt,qc as s,li as sn,Da as st,$ as t,qr as tn,qe as tr,Ga as tt,Vc as u,fi as un,sa as ut,wc as v,Er as vn,ma as vt,tc as w,jr as wn,ra as wt,hc as x,kr as xn,ta as xt,Tc as y,Rr as yn,ga as yt,ts as z,lr as zn,Yi as zt};
|
package/dist/src/url.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=`--agent-device-run-metro-companion`,t=`--agent-device-run-react-devtools-companion`,n=1e3,r=`AGENT_DEVICE_COMPANION_TUNNEL_SERVER_BASE_URL`,i=`AGENT_DEVICE_COMPANION_TUNNEL_BEARER_TOKEN`,a=`AGENT_DEVICE_COMPANION_TUNNEL_LOCAL_BASE_URL`,o=`AGENT_DEVICE_COMPANION_TUNNEL_LAUNCH_URL`,s=`AGENT_DEVICE_COMPANION_TUNNEL_STATE_PATH`,c=`AGENT_DEVICE_COMPANION_TUNNEL_SCOPE_TENANT_ID`,l=`AGENT_DEVICE_COMPANION_TUNNEL_SCOPE_RUN_ID`,u=`AGENT_DEVICE_COMPANION_TUNNEL_SCOPE_LEASE_ID`,d=`AGENT_DEVICE_COMPANION_TUNNEL_REGISTER_PATH`,f=`AGENT_DEVICE_COMPANION_TUNNEL_UNREGISTER_PATH`,p=`AGENT_DEVICE_COMPANION_TUNNEL_DEVICE_PORT`,m=`AGENT_DEVICE_COMPANION_TUNNEL_SESSION`;var h=class extends Error{name=`MissingCompanionEnvError`};function g(e){let t=e.length;for(;t>0&&e.charCodeAt(t-1)===47;)--t;return t===e.length?e:e.slice(0,t)}function _(e,t){let
|
|
1
|
+
const e=`--agent-device-run-metro-companion`,t=`--agent-device-run-react-devtools-companion`,n=1e3,r=`AGENT_DEVICE_COMPANION_TUNNEL_SERVER_BASE_URL`,i=`AGENT_DEVICE_COMPANION_TUNNEL_BEARER_TOKEN`,a=`AGENT_DEVICE_COMPANION_TUNNEL_LOCAL_BASE_URL`,o=`AGENT_DEVICE_COMPANION_TUNNEL_LAUNCH_URL`,s=`AGENT_DEVICE_COMPANION_TUNNEL_STATE_PATH`,c=`AGENT_DEVICE_COMPANION_TUNNEL_SCOPE_TENANT_ID`,l=`AGENT_DEVICE_COMPANION_TUNNEL_SCOPE_RUN_ID`,u=`AGENT_DEVICE_COMPANION_TUNNEL_SCOPE_LEASE_ID`,d=`AGENT_DEVICE_COMPANION_TUNNEL_REGISTER_PATH`,f=`AGENT_DEVICE_COMPANION_TUNNEL_UNREGISTER_PATH`,p=`AGENT_DEVICE_COMPANION_TUNNEL_DEVICE_PORT`,m=`AGENT_DEVICE_COMPANION_TUNNEL_SESSION`;var h=class extends Error{name=`MissingCompanionEnvError`};function g(e){let t=e.length;for(;t>0&&e.charCodeAt(t-1)===47;)--t;return t===e.length?e:e.slice(0,t)}function _(e,t,n=`index.bundle`){let r=new URL(`${g(e)}/${n}`);return r.searchParams.set(`platform`,t),r.searchParams.set(`dev`,`true`),r.searchParams.set(`minify`,`false`),r.toString()}export{h as _,p as a,d as c,c as d,r as f,e as g,f as h,i,u as l,s as m,g as n,o,m as p,n as r,a as s,_ as t,l as u,t as v};
|
package/dist/src/web.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e}from"./sdk-contracts.js";import{F as t}from"./sdk-android-adb.js";import{n}from"./
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";import{F as t}from"./sdk-android-adb.js";import{m as n}from"./internal/daemon.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`),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),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`),setOrientation:()=>i(`orientation`),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.
|
|
3
|
+
"version": "0.20.0",
|
|
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",
|
|
@@ -90,16 +90,19 @@
|
|
|
90
90
|
"build:xcuitest:visionos:clean": "pnpm clean:xcuitest:visionos && pnpm build:xcuitest:visionos",
|
|
91
91
|
"build:android-snapshot-helper": "sh ./scripts/build-android-snapshot-helper.sh $(node -p \"require('./package.json').version\") .tmp/android-snapshot-helper",
|
|
92
92
|
"package:android-snapshot-helper": "sh ./scripts/package-android-snapshot-helper.sh $(node -p \"require('./package.json').version\") v$(node -p \"require('./package.json').version\") .tmp/android-snapshot-helper",
|
|
93
|
-
"package:android-snapshot-helper:npm": "rm -rf android
|
|
93
|
+
"package:android-snapshot-helper:npm": "rm -rf android/snapshot-helper/dist && sh ./scripts/package-android-snapshot-helper.sh $(node -p \"require('./package.json').version\") v$(node -p \"require('./package.json').version\") android/snapshot-helper/dist",
|
|
94
94
|
"package:apple-runner:npm": "node scripts/package-apple-runner-source.mjs",
|
|
95
|
-
"build:android
|
|
96
|
-
"
|
|
97
|
-
"package:android-
|
|
98
|
-
"
|
|
99
|
-
"build:macos-helper": "swift build -c release --package-path macos-helper",
|
|
95
|
+
"build:android": "pnpm package:android-snapshot-helper:npm && pnpm package:android-ime-helper:npm",
|
|
96
|
+
"build:android-ime-helper": "sh ./scripts/build-android-ime-helper.sh $(node -p \"require('./package.json').version\") .tmp/android-ime-helper",
|
|
97
|
+
"package:android-ime-helper": "sh ./scripts/package-android-ime-helper.sh $(node -p \"require('./package.json').version\") .tmp/android-ime-helper",
|
|
98
|
+
"package:android-ime-helper:npm": "rm -rf android/ime-helper/dist && sh ./scripts/package-android-ime-helper.sh $(node -p \"require('./package.json').version\") android/ime-helper/dist",
|
|
99
|
+
"build:macos-helper": "swift build -c release --package-path apple/macos-helper",
|
|
100
100
|
"build:all": "pnpm build:node && pnpm build:xcuitest",
|
|
101
101
|
"ad": "node bin/agent-device.mjs",
|
|
102
102
|
"bench:help-conformance": "node scripts/help-conformance-bench.mjs",
|
|
103
|
+
"maestro:conformance": "node --experimental-strip-types --test scripts/maestro-conformance/verify.test.ts scripts/maestro-conformance/differential/run.test.ts scripts/maestro-conformance/differential/invariants.test.ts",
|
|
104
|
+
"maestro:conformance:regenerate": "node scripts/maestro-conformance/regenerate.mjs",
|
|
105
|
+
"maestro:conformance:differential": "node --experimental-strip-types scripts/maestro-conformance/differential/run.ts",
|
|
103
106
|
"size": "node scripts/size-report.mjs",
|
|
104
107
|
"size:markdown": "node scripts/size-report.mjs --json .tmp/size-report.json --markdown .tmp/size-report.md",
|
|
105
108
|
"perf": "node --experimental-strip-types scripts/perf/run.ts",
|
|
@@ -115,19 +118,19 @@
|
|
|
115
118
|
"check:affected": "node --experimental-strip-types scripts/check-affected/run.ts",
|
|
116
119
|
"check:affected:test": "node --experimental-strip-types --test scripts/check-affected/model.test.ts scripts/check-affected/run.test.ts",
|
|
117
120
|
"check:layering": "node --experimental-strip-types --test scripts/layering/model.test.ts && node --experimental-strip-types scripts/layering/check.ts",
|
|
118
|
-
"check:
|
|
119
|
-
"check:
|
|
120
|
-
"check:
|
|
121
|
+
"check:production-exports": "fallow dead-code --config fallow-production-exports.json --production --unused-exports --fail-on-issues",
|
|
122
|
+
"check:bundle-owner-files": "node --experimental-strip-types scripts/check-bundle-owner-files.ts",
|
|
123
|
+
"check:freerange": "fr",
|
|
121
124
|
"check:quick": "pnpm lint && pnpm typecheck",
|
|
122
125
|
"sync:mcp-metadata": "node scripts/sync-mcp-metadata.mjs",
|
|
123
126
|
"check:mcp-metadata": "node scripts/sync-mcp-metadata.mjs --check",
|
|
124
127
|
"version": "node scripts/sync-mcp-metadata.mjs && git add server.json",
|
|
125
|
-
"check:tooling": "pnpm lint && pnpm typecheck && pnpm check:layering && pnpm check:production-exports && pnpm check:mcp-metadata && pnpm build",
|
|
128
|
+
"check:tooling": "pnpm lint && pnpm typecheck && pnpm check:layering && pnpm check:production-exports && pnpm check:mcp-metadata && pnpm build && pnpm check:bundle-owner-files",
|
|
126
129
|
"check:unit": "pnpm test:unit && pnpm test:smoke",
|
|
127
130
|
"check": "pnpm check:tooling && pnpm check:fallow && pnpm check:unit",
|
|
128
|
-
"prepack": "pnpm check:mcp-metadata && pnpm build:all && pnpm package:apple-runner:npm && pnpm package:android-snapshot-helper:npm && pnpm package:android-
|
|
131
|
+
"prepack": "pnpm check:mcp-metadata && pnpm build:all && pnpm package:apple-runner:npm && pnpm package:android-snapshot-helper:npm && pnpm package:android-ime-helper:npm",
|
|
129
132
|
"typecheck": "tsc -p tsconfig.json",
|
|
130
|
-
"test-app:install": "pnpm install --dir examples/test-app
|
|
133
|
+
"test-app:install": "pnpm install --dir examples/test-app",
|
|
131
134
|
"test-app:start": "pnpm --dir examples/test-app start",
|
|
132
135
|
"test-app:ios": "pnpm --dir examples/test-app ios",
|
|
133
136
|
"test-app:android": "pnpm --dir examples/test-app android",
|
|
@@ -159,15 +162,15 @@
|
|
|
159
162
|
"files": [
|
|
160
163
|
"bin",
|
|
161
164
|
"dist",
|
|
162
|
-
"macos-helper",
|
|
163
|
-
"!macos-helper/**/.build",
|
|
164
|
-
"android
|
|
165
|
-
"!android
|
|
166
|
-
"!android
|
|
167
|
-
"android-
|
|
168
|
-
"!android-
|
|
169
|
-
"!android-
|
|
170
|
-
"
|
|
165
|
+
"apple/macos-helper",
|
|
166
|
+
"!apple/macos-helper/**/.build",
|
|
167
|
+
"android/snapshot-helper/dist",
|
|
168
|
+
"!android/snapshot-helper/dist/*.idsig",
|
|
169
|
+
"!android/snapshot-helper/README.md",
|
|
170
|
+
"android/ime-helper/dist",
|
|
171
|
+
"!android/ime-helper/dist/*.idsig",
|
|
172
|
+
"!android/ime-helper/README.md",
|
|
173
|
+
"linux/atspi-dump.py",
|
|
171
174
|
"skills",
|
|
172
175
|
"server.json",
|
|
173
176
|
"smithery.yaml",
|
|
@@ -218,11 +221,12 @@
|
|
|
218
221
|
"detox"
|
|
219
222
|
],
|
|
220
223
|
"dependencies": {
|
|
224
|
+
"@limrun/api": "^0.24.5",
|
|
221
225
|
"yaml": "^2.9.0"
|
|
222
226
|
},
|
|
223
227
|
"devDependencies": {
|
|
228
|
+
"@chenglou/freerange": "^0.0.1",
|
|
224
229
|
"@types/node": "^22.19.21",
|
|
225
|
-
"typescript": "^7.0.2",
|
|
226
230
|
"@vitest/coverage-v8": "4.1.8",
|
|
227
231
|
"fallow": "^2.95.0",
|
|
228
232
|
"oxc-parser": "^0.138.0",
|
|
@@ -230,6 +234,7 @@
|
|
|
230
234
|
"oxlint": "^1.69.0",
|
|
231
235
|
"skillgym": "^0.9.1",
|
|
232
236
|
"tsdown": "^0.22.4",
|
|
237
|
+
"typescript": "^7.0.2",
|
|
233
238
|
"vite": "^8.0.16",
|
|
234
239
|
"vitest": "^4.1.8"
|
|
235
240
|
}
|
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.
|
|
10
|
+
"version": "0.20.0",
|
|
11
11
|
"packages": [
|
|
12
12
|
{
|
|
13
13
|
"registryType": "npm",
|
|
14
14
|
"identifier": "agent-device",
|
|
15
|
-
"version": "0.
|
|
15
|
+
"version": "0.20.0",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
}
|
|
Binary file
|
package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.3.apk.sha256
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
38e24a9ed16d41ac68b810c664e7bfc5c21d7a59be83d9789ea759e46c81eb7e agent-device-android-multitouch-helper-0.19.3.apk
|
package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.3.manifest.json
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "android-multitouch-helper",
|
|
3
|
-
"version": "0.19.3",
|
|
4
|
-
"assetName": "agent-device-android-multitouch-helper-0.19.3.apk",
|
|
5
|
-
"sha256": "38e24a9ed16d41ac68b810c664e7bfc5c21d7a59be83d9789ea759e46c81eb7e",
|
|
6
|
-
"packageName": "com.callstack.agentdevice.multitouchhelper",
|
|
7
|
-
"versionCode": 19003,
|
|
8
|
-
"instrumentationRunner": "com.callstack.agentdevice.multitouchhelper/.MultiTouchInstrumentation",
|
|
9
|
-
"statusProtocol": "android-multitouch-helper-v1"
|
|
10
|
-
}
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
a03f6bc81224ce0a16a141ef88b969f988ad7da52e0f4f1dfda34abaa81ac868 agent-device-android-snapshot-helper-0.19.3.apk
|