agent-device 0.20.9 → 0.20.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.9.apk → agent-device-android-ime-helper-0.20.10.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.10.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.9.manifest.json → agent-device-android-ime-helper-0.20.10.manifest.json} +4 -4
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.9.apk → agent-device-android-snapshot-helper-0.20.10.apk} +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.10.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.9.manifest.json → agent-device-android-snapshot-helper-0.20.10.manifest.json} +6 -6
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +6 -5
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +4 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+FlatSnapshotFiltering.swift +94 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +22 -23
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +3 -23
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +10 -11
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXPresentation.swift +30 -12
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollGesture.swift +8 -5
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +133 -63
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +13 -12
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotPresentation.swift +183 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotPresentationTests.swift +0 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +20 -18
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputCandidatePolicy.swift +19 -0
- package/dist/src/agent-device-client.js +2 -2
- package/dist/src/ai-sdk.d.ts +61 -0
- package/dist/src/ai-sdk.js +1 -0
- package/dist/src/android-adb.d.ts +1 -1
- package/dist/src/app-lifecycle.js +1 -1
- package/dist/src/app-log-reconnect.js +1 -1
- package/dist/src/app-log-runtime.js +3 -3
- package/dist/src/app-resolution.js +2 -2
- package/dist/src/apps.js +5 -5
- package/dist/src/audio-probe.js +1 -1
- package/dist/src/boot-diagnostics.js +2 -2
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +30 -23
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +7 -7
- package/dist/src/client-metro.js +1 -1
- package/dist/src/client-types.d.ts +1582 -0
- package/dist/src/command-tools.js +2 -0
- package/dist/src/connection-runtime.js +1 -1
- package/dist/src/contracts.d.ts +1 -1
- package/dist/src/contracts.js +1 -1
- package/dist/src/daemon-shutdown-report.js +1 -1
- package/dist/src/daemon.js +1 -1
- package/dist/src/debug-symbols.js +1 -1
- package/dist/src/device-input-state.js +1 -1
- package/dist/src/dispatch.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/finders.js +1 -1
- package/dist/src/generic-settle.js +1 -1
- package/dist/src/generic.js +1 -1
- package/dist/src/helper-package-install.js +1 -1
- package/dist/src/helper.js +1 -1
- package/dist/src/ime-lifecycle.js +1 -1
- package/dist/src/ime-recovery-marker.js +1 -1
- package/dist/src/index.d.ts +2 -1578
- package/dist/src/index.js +1 -1
- package/dist/src/input-actions.js +1 -1
- package/dist/src/input-actions3.js +1 -1
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-common.js +1 -1
- package/dist/src/interaction-runtime.js +1 -1
- package/dist/src/interaction-snapshot.js +1 -1
- package/dist/src/interaction.js +1 -1
- package/dist/src/interaction2.js +1 -1
- package/dist/src/interactor.js +2 -2
- package/dist/src/interactor2.js +1 -1
- package/dist/src/interactors.js +1 -1
- package/dist/src/internal/bin.js +2 -2
- package/dist/src/internal/daemon.js +4 -4
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/lease-context.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/limrun.d.ts +10 -2
- package/dist/src/linux.js +1 -1
- package/dist/src/location-coordinates.js +1 -1
- package/dist/src/{screenshot-geometry.js → mobile-snapshot-semantics.js} +1 -1
- package/dist/src/perf.js +1 -1
- package/dist/src/platform-runtime-open-target.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +4 -4
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/platform-runtime2.js +1 -1
- package/dist/src/png-resize.js +1 -1
- package/dist/src/provider.js +1 -1
- package/dist/src/proxy.js +1 -1
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-runtime.js +1 -1
- package/dist/src/registry.js +27 -27
- package/dist/src/remote-config2.js +1 -1
- package/dist/src/replay.js +2 -2
- package/dist/src/reporting.js +5 -5
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-disposal.js +1 -1
- package/dist/src/runner-sequence.js +1 -1
- package/dist/src/runtime.js +3 -3
- package/dist/src/runtime2.js +4 -4
- package/dist/src/runtime3.js +1 -1
- package/dist/src/runtime4.js +3 -3
- package/dist/src/runtime5.js +1 -1
- package/dist/src/runtime6.js +1 -1
- package/dist/src/runtime7.js +1 -1
- package/dist/src/runtime8.js +1 -1
- package/dist/src/runtime9.js +1 -1
- package/dist/src/screenshot-result.js +4 -4
- package/dist/src/screenshot.js +1 -1
- package/dist/src/script-source-bundle.js +16 -0
- package/dist/src/sdk-android-adb.d.ts +40 -40
- package/dist/src/sdk-android-adb.js +4 -4
- package/dist/src/sdk-batch-runner.js +3 -3
- package/dist/src/sdk-contracts.d.ts +122 -85
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-finders.d.ts +1 -1
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-selectors.d.ts +89 -77
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/server.js +10 -3
- package/dist/src/session-target-evidence.js +1 -1
- package/dist/src/session2.js +7 -8
- package/dist/src/shared.js +1 -1
- package/dist/src/snapshot-runtime.js +1 -1
- package/dist/src/snapshot-scope.js +1 -0
- package/dist/src/snapshot.js +6 -6
- package/dist/src/snapshot2.js +1 -1
- package/dist/src/snapshot3.js +1 -1
- package/dist/src/src.js +1 -1
- package/dist/src/src2.js +1 -1
- package/dist/src/src3.js +1 -1
- package/dist/src/src4.js +1 -0
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/tool-provider3.js +1 -0
- package/dist/src/verified-file.js +1 -1
- package/dist/src/web.js +1 -1
- package/package.json +21 -8
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.9.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.9.apk.sha256 +0 -1
- package/dist/src/cancel.js +0 -1
- package/dist/src/prepare-kind.js +0 -15
- package/dist/src/selector-vocabulary.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-device",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.10",
|
|
4
4
|
"description": "Mobile app automation and verification for AI coding agents. CLI, MCP server, and typed Node.js API for iOS, Android, HarmonyOS, TV, web, macOS, and Linux.",
|
|
5
5
|
"mcpName": "io.github.callstack/agent-device",
|
|
6
6
|
"license": "MIT",
|
|
@@ -65,6 +65,10 @@
|
|
|
65
65
|
"./finders": {
|
|
66
66
|
"types": "./dist/src/finders.d.ts",
|
|
67
67
|
"import": "./dist/src/finders.js"
|
|
68
|
+
},
|
|
69
|
+
"./ai-sdk": {
|
|
70
|
+
"types": "./dist/src/ai-sdk.d.ts",
|
|
71
|
+
"import": "./dist/src/ai-sdk.js"
|
|
68
72
|
}
|
|
69
73
|
},
|
|
70
74
|
"engines": {
|
|
@@ -115,7 +119,6 @@
|
|
|
115
119
|
"size": "node scripts/size-report.mjs",
|
|
116
120
|
"perf": "node --experimental-strip-types scripts/perf/run.ts",
|
|
117
121
|
"mutation:run": "node --experimental-strip-types scripts/mutation/run.ts",
|
|
118
|
-
"mutation:baseline": "node --experimental-strip-types scripts/mutation/run.ts --update",
|
|
119
122
|
"mutation:check": "node --experimental-strip-types scripts/mutation/run.ts --no-run",
|
|
120
123
|
"mutation:affected": "node --experimental-strip-types scripts/mutation/run.ts --affected",
|
|
121
124
|
"mutation:test": "node --experimental-strip-types scripts/node-test-tmpdir.ts --experimental-strip-types --test scripts/mutation/*.test.ts",
|
|
@@ -143,6 +146,7 @@
|
|
|
143
146
|
"check:replay-compat": "node --experimental-strip-types scripts/check-replay-compat-provenance.ts",
|
|
144
147
|
"check:daemon-wire-compat": "node --experimental-strip-types scripts/wire-compat/run.ts",
|
|
145
148
|
"check:daemon-wire-compat:test": "node --experimental-strip-types scripts/node-test-tmpdir.ts --experimental-strip-types --test scripts/wire-compat/model.test.ts",
|
|
149
|
+
"check:xctest-selection": "node --experimental-strip-types scripts/check-xctest-selection.ts",
|
|
146
150
|
"check:tmpdir-leaks": "node --experimental-strip-types scripts/check-tmpdir-leaks.ts",
|
|
147
151
|
"check:tmpdir-leaks:test": "node --experimental-strip-types scripts/node-test-tmpdir.ts --experimental-strip-types --test scripts/check-tmpdir-leaks-model.test.ts scripts/vitest-tmpdir-global-setup.test.ts scripts/node-test-tmpdir.test.ts scripts/swift-toolchain-tmpdir.test.ts",
|
|
148
152
|
"check:freerange": "fr",
|
|
@@ -150,8 +154,8 @@
|
|
|
150
154
|
"sync:mcp-metadata": "node scripts/sync-mcp-metadata.mjs",
|
|
151
155
|
"check:mcp-metadata": "node scripts/sync-mcp-metadata.mjs --check",
|
|
152
156
|
"version": "pnpm sync:mcp-metadata && git add server.json",
|
|
153
|
-
"check:tooling": "pnpm format:check && pnpm lint && pnpm typecheck && pnpm check:layering && pnpm depgraph:test && pnpm check:gate-manifest:test && pnpm check:gate-manifest && pnpm check:production-exports && pnpm check:tmpdir-leaks:test && pnpm check:mcp-metadata && pnpm build && pnpm check:bundle-owner-files && pnpm check:package",
|
|
154
|
-
"check:unit": "pnpm
|
|
157
|
+
"check:tooling": "pnpm format:check && pnpm lint && pnpm typecheck && pnpm check:layering && pnpm depgraph:test && pnpm check:gate-manifest:test && pnpm check:gate-manifest && pnpm check:production-exports && pnpm check:tmpdir-leaks:test && pnpm check:xctest-selection && pnpm check:mcp-metadata && pnpm build && pnpm check:bundle-owner-files && pnpm check:package",
|
|
158
|
+
"check:unit": "pnpm test:unit && pnpm check:tmpdir-leaks && pnpm test:smoke",
|
|
155
159
|
"check": "pnpm check:tooling && pnpm check:fallow && pnpm check:unit",
|
|
156
160
|
"prepack": "pnpm check:mcp-metadata && pnpm package:npm",
|
|
157
161
|
"typecheck": "tsc -b packages/xml packages/kernel packages/contracts packages/capture-kit packages/platform-apple packages/platform-android packages/platform-harmonyos packages/platform-vega packages/platform-linux packages/platform-web packages/ad-script packages/selectors packages/ad-replay packages/maestro packages/replay-test packages/provider-webdriver packages/provider-limrun && tsc -p tsconfig.json && tsc -p examples/sdk/tsconfig.json",
|
|
@@ -169,8 +173,7 @@
|
|
|
169
173
|
"test:unit": "vitest run --project unit-core --project subprocess-stub",
|
|
170
174
|
"test:maestro-compat": "vitest run --project unit-core packages/maestro src/daemon/adapters/maestro src/compat/__tests__/replay-input.test.ts",
|
|
171
175
|
"test:coverage": "vitest run --coverage",
|
|
172
|
-
"test:coverage:ci": "
|
|
173
|
-
"check:contention-retry": "node --experimental-strip-types scripts/node-test-tmpdir.ts --experimental-strip-types --test scripts/lib/contention-retry-policy.test.ts",
|
|
176
|
+
"test:coverage:ci": "vitest run --coverage",
|
|
174
177
|
"test:integration:provider": "vitest run --project provider-integration",
|
|
175
178
|
"test:integration:progress": "node --experimental-strip-types scripts/integration-progress.ts",
|
|
176
179
|
"test:integration:progress:check": "node --experimental-strip-types scripts/integration-progress.ts --check",
|
|
@@ -184,7 +187,7 @@
|
|
|
184
187
|
"test:concurrency-torture": "node --experimental-strip-types scripts/node-test-tmpdir.ts --test test/integration/nightly/concurrency-torture.test.ts",
|
|
185
188
|
"test:replay:ios": "node --experimental-strip-types src/bin.ts test test/integration/replays/ios/simulator",
|
|
186
189
|
"test:replay:ios-device": "node --experimental-strip-types src/bin.ts test test/integration/replays/ios/device",
|
|
187
|
-
"test:replay:android": "node --experimental-strip-types src/bin.ts test test/integration/replays/android",
|
|
190
|
+
"test:replay:android": "node --experimental-strip-types src/bin.ts test test/integration/replays/android/emulator",
|
|
188
191
|
"test:replay:macos": "node --experimental-strip-types src/bin.ts test test/integration/replays/macos",
|
|
189
192
|
"test:replay:linux": "node --experimental-strip-types src/bin.ts test test/integration/replays/linux"
|
|
190
193
|
},
|
|
@@ -256,10 +259,18 @@
|
|
|
256
259
|
"yaml": "^2.9.0",
|
|
257
260
|
"yauzl": "^3.4.0"
|
|
258
261
|
},
|
|
262
|
+
"peerDependencies": {
|
|
263
|
+
"ai": "^6.0.0 || ^7.0.0"
|
|
264
|
+
},
|
|
265
|
+
"peerDependenciesMeta": {
|
|
266
|
+
"ai": {
|
|
267
|
+
"optional": true
|
|
268
|
+
}
|
|
269
|
+
},
|
|
259
270
|
"devDependencies": {
|
|
260
|
-
"@agent-device/capture-kit": "workspace:*",
|
|
261
271
|
"@agent-device/ad-replay": "workspace:*",
|
|
262
272
|
"@agent-device/ad-script": "workspace:*",
|
|
273
|
+
"@agent-device/capture-kit": "workspace:*",
|
|
263
274
|
"@agent-device/contracts": "workspace:*",
|
|
264
275
|
"@agent-device/kernel": "workspace:*",
|
|
265
276
|
"@agent-device/maestro": "workspace:*",
|
|
@@ -278,11 +289,13 @@
|
|
|
278
289
|
"@chenglou/freerange": "^0.0.1",
|
|
279
290
|
"@stryker-mutator/core": "9.6.1",
|
|
280
291
|
"@stryker-mutator/vitest-runner": "9.6.1",
|
|
292
|
+
"@types/json-schema": "^7.0.15",
|
|
281
293
|
"@types/node": "^22.19.21",
|
|
282
294
|
"@types/pngjs": "^6.0.5",
|
|
283
295
|
"@types/tar-stream": "^3.1.4",
|
|
284
296
|
"@types/yauzl": "^2.10.3",
|
|
285
297
|
"@vitest/coverage-v8": "4.1.8",
|
|
298
|
+
"ai": "^7.0.66",
|
|
286
299
|
"fallow": "^2.95.0",
|
|
287
300
|
"fast-check": "^4.9.0",
|
|
288
301
|
"oxc-parser": "^0.138.0",
|
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.20.
|
|
10
|
+
"version": "0.20.10",
|
|
11
11
|
"packages": [
|
|
12
12
|
{
|
|
13
13
|
"registryType": "npm",
|
|
14
14
|
"identifier": "agent-device",
|
|
15
|
-
"version": "0.20.
|
|
15
|
+
"version": "0.20.10",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
f98ded51f104c10268a75b7eb77f2e479461b844e49f238593d44b821d13e294 agent-device-android-ime-helper-0.20.9.apk
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
a5169f62fb38bb1980cf7c7963542f2bc5bbaafd4d9dc7b5b23d3e41ee782725 agent-device-android-snapshot-helper-0.20.9.apk
|
package/dist/src/cancel.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_ as e}from"./sdk-contracts.js";const t=new Set,n=new Map,r=`request_canceled`,i=`request canceled`;function a(e,t){if(typeof e==`string`&&e.length>0)return e;let n=(typeof t==`string`?t:typeof t==`number`&&Number.isFinite(t)?String(t):`generated`).trim().replace(/[^a-zA-Z0-9_-]/g,`_`).slice(0,32)||`generated`,r=Math.random().toString(36).slice(2,10);return`req:${n}:${process.pid}:${Date.now()}:${r}`}const o=5e4,s=1e4;function c(e){if(e.size<=o)return;let t=0;for(let n of e.keys()){if(t>=s)break;e.delete(n),t++}}function l(e){if(e.size<=o)return;let t=0;for(let n of e){if(t>=s)break;e.delete(n),t++}}function u(r){if(!r)return;if(n.has(r))throw new e(`INVALID_ARGS`,`Request ID is already in flight: ${r}`,{requestId:r,reason:`duplicate_request_id`});c(n);let i=new AbortController;return n.set(r,i),t.has(r)&&i.abort(),{requestId:r,controller:i}}function d(e){e&&(l(t),t.add(e),n.get(e)?.abort())}function f(e,r){e&&(r&&(r.requestId!==e||n.get(e)!==r.controller)||(t.delete(e),n.delete(e)))}function p(e){e&&f(e.requestId,e)}function m(e){return e?t.has(e):!1}function h(e){if(e)return n.get(e)?.signal}function g(){return new e(`COMMAND_FAILED`,i,{reason:r,hint:`The request was canceled intentionally (explicit cancel or client disconnect) — no retry is needed unless the cancellation was unintended.`})}function _(e){if(m(e))throw g()}function v(t){return!(t instanceof e)||t.code!==`COMMAND_FAILED`?!1:t.details?.reason===r?!0:t.message===i}export{m as a,u as c,h as i,a as l,f as n,v as o,g as r,d as s,p as t,_ as u};
|
package/dist/src/prepare-kind.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import{C as e,D as t,_ as n,d as r,f as i,g as a,p as o,u as s}from"./sdk-contracts.js";import{m as c}from"./location-coordinates.js";import{$n as l,An as u,Br as d,Dn as f,En as p,Lt as m,Mt as h,On as g,Qn as _,Tn as ee,Xn as te,Yn as ne,Zn as re,_r as ie,an as ae,ar as oe,cn as se,dr as ce,er as le,fr as ue,hr as v,jt as de,lr as y,mr as fe,nn as pe,on as me,or as he,rn as ge,sn as _e,tn as b,ur as ve,vn as ye,wn as be,wr as xe,xn as Se,xr as x,yn as Ce,yr as we}from"./sdk-batch-runner.js";import{p as Te}from"./sdk-device.js";import{b as Ee,d as De,f as Oe,g as ke,t as Ae,u as je}from"./interaction.js";import{a as Me,c as Ne,i as Pe,r as Fe,t as Ie}from"./screenshot-geometry.js";import{n as Le,t as Re}from"./verdict.js";import"./device.js";import ze from"node:path";import{styleText as Be}from"node:util";import{createHash as Ve}from"node:crypto";const He=3e5,Ue=[`leaseId`,`tenantId`,`runId`,`clientId`,`deviceKey`];function We(e){return d({tenantId:e.meta?.tenantId??S(e.flags,`tenant`),runId:e.meta?.runId??S(e.flags,`runId`),leaseId:e.meta?.leaseId??S(e.flags,`leaseId`),leaseTtlMs:e.meta?.leaseTtlMs,leaseBackend:e.meta?.leaseBackend,leaseProvider:e.meta?.leaseProvider??S(e.flags,`leaseProvider`)??S(e.flags,`provider`),deviceKey:e.meta?.deviceKey??S(e.flags,`deviceKey`),clientId:e.meta?.clientId??S(e.flags,`clientId`)})}function Ge(e){return d({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 Ke(e){return d({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 qe(e){return d({tenant:e.tenantId,runId:e.runId,leaseId:e.leaseId,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId})}function Je(e){return d({tenantId:e.tenantId??``,runId:e.runId??``,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId,ttlMs:e.leaseTtlMs})}function Ye(e){return tt(e)}function Xe(e){let{ttlMs:t,...n}=tt(e);return n}function Ze(e,t,n){let r=d({...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,...d({ttlMs:e.leaseTtlMs,backend:e.leaseBackend})};case`lease_heartbeat`:return{...r,...d({leaseId:e.leaseId,ttlMs:e.leaseTtlMs})};case`lease_release`:return{...r,...d({leaseId:e.leaseId})}}}function Qe(e){let t=d({leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId});return Object.keys(t).length>0?t:void 0}function $e(e){return e.leaseProvider===`proxy`}function et(e){return $e(e)?Ue.filter(t=>!e[t]):[]}function tt(e){return d({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 S(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function C(e){return e?{message:e}:{}}function w(e,t){return t?{...e,message:t}:e}function nt(e){return typeof e?.message==`string`&&e.message.length>0?e.message:null}function rt(e){let t=e.appId??e.bundleId??e.packageName;return{session:e.session,appId:t,appBundleId:e.bundleId,package:e.packageName}}function it(e,t,n){return{deviceId:t,deviceName:n,...Te(e)?{serial:t}:e===`ios`?{udid:t}:{}}}function at(e,t={}){let n=t.includeSerial??!0,r=ot(e);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}:{},...n&&r?{serial:r}:{}}}function ot(e){return Te(e.platform)?e.identifiers.serial??e.id:void 0}function st(e){return{name:e.name,...e.sessionStateDir?{sessionStateDir:e.sessionStateDir}:{},...e.runnerLogPath?{runnerLogPath:e.runnerLogPath}:{},...at(e.device,{includeSerial:!1}),createdAt:e.createdAt}}function ct(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 lt(e){return e.bundleId??e.package??e.app}function ut(e){return w({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: ${lt(e)}`)}function dt(e){return e.appName??e.bundleId??e.packageName??e.launchTarget}function ft(e){return w({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: ${dt(e)}`)}function pt(e){let t=e.appName??e.appBundleId??e.session;return w({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?at(e.device):{},...e.snapshot?{snapshot:e.snapshot}:{},...e.initialSnapshotError?{initialSnapshotError:e.initialSnapshotError}:{}},t?`Opened: ${t}`:`Opened`)}function mt(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 ht(e){return{nodes:e.nodes,truncated:e.truncated,...e.appName?{appName:e.appName}:{},...e.appBundleId?{appBundleId:e.appBundleId}:{},...e.visibility?{visibility:e.visibility}:{},...c(gt(e)),...e.unchanged?{unchanged:e.unchanged}:{},...e.snapshotDiagnostics?{snapshotDiagnostics:e.snapshotDiagnostics}:{},...e.fallbackScreenshotPath?{fallbackScreenshotPath:e.fallbackScreenshotPath}:{},...e.refsGeneration===void 0?{}:{refsGeneration:e.refsGeneration}}}function gt(e){return{...e,...e.snapshotQuality?{quality:e.snapshotQuality}:{}}}const _t=[`app`,`device`,`system`];function vt(e){return e===`device`||e===`system`}function T(e){return e.width>0&&e.height>0}function yt(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 bt(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 xt(e){return typeof e.parentIndex!=`number`}function E(e){let t=(e.type??``).toLowerCase(),n=(e.identifier??``).trim().toLowerCase();return t.includes(`edittext`)||t.includes(`textfield`)||n===`composer`}function St(e){let t=(e.type??``).toLowerCase();return t.includes(`scroll`)||t.includes(`list`)||t.includes(`recyclerview`)}function D(e){let t=ue(e);if(!t||t!==e.identifier?.trim()||!Ct(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 O(e){let t=e.trim().replace(/\s+/g,` `).toLowerCase();return!t||/^(true|false|\d+)$/.test(t)?null:t}function Ct(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function wt(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 Tt(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 k(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 Et=[`button`,`switch`,`checkbox`,`radio`],Dt=[`button`,`image`,`textview`,`view`];function Ot(e,t,n){for(let r of e){if(t.has(r.index)||!jt(r))continue;let i=Mt(Tt(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)k(e,n,t)}}}function kt(e,t,n){let r=new Map;for(let i of e){if(t.has(i.index)||!Bt(i))continue;let a=O(D(i));if(!a)continue;let o=r.get(a);if(o&&Lt(o,i,t)){let s=Rt(e,o,i,t,n);r.set(a,s);continue}r.set(a,i)}}function At(e,t){for(let n of e){if(t.has(n.index)||!Ft(n))continue;let r=O(D(n));if(!r)continue;let i=Tt(e,n.index).filter(e=>!t.has(e.index)&&It(n,e,r));for(let n of i.filter(Pt))k(e,n.index,t);let a=i.filter(e=>!Pt(e)),o=new Set(a.map(e=>O(D(e))).filter(e=>!!e));if(!(a.length<2||o.size<2))for(let n of a)k(e,n.index,t)}}function jt(e){return e.hittable===!0&&!E(e)&&!!(e.rect&&T(e.rect))&&D(e).trim().length===0}function Mt(e,t,n){let r=[],i=[],a=new Set;for(let o of e){if(n.has(o.index)||!Nt(o,e)||!yt(o.rect,t.rect))continue;let s=D(o).trim().replace(/\s+/g,` `),c=O(s);i.push(o.index),!(!s||!c||a.has(c))&&(a.add(c),r.push(s))}return{label:r.join(`, `),removableIndexes:i}}function Nt(e,t){if(Pt(e))return!0;let n=(e.type??``).toLowerCase();return e.hittable!==!0&&!E(e)&&n.includes(`view`)&&D(e).trim().length>0&&!t.some(t=>t.parentIndex===e.index)}function Pt(e){if(e.hittable===!0||E(e))return!1;let t=(e.type??``).toLowerCase();return t.includes(`text`)||t.includes(`image`)||t.includes(`icon`)}function Ft(e){return e.hittable===!0&&!E(e)&&!!(e.rect&&T(e.rect))&&!!O(D(e))}function It(e,t,n){if(!Bt(t)||!yt(t.rect,e.rect))return!1;let r=O(D(t));return!!(r&&n!==r&&n.includes(r))}function Lt(e,t,n){return!n.has(e.index)&&bt(e.rect,t.rect)&&(Gt(e,t)||Wt(e,t))}function Rt(e,t,n,r,i){let a=Vt(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:zt(c.presentationHints,l,s)}),k(e,o.index,r),i.get(a.index)??a}function zt(e,t,n){return[...new Set([...Array.isArray(e)?e:[],...Array.isArray(t)?t:[],...n?[n]:[]])]}function Bt(e){if(!e.rect||!T(e.rect)||xt(e)||E(e))return!1;let t=(e.type??``).toLowerCase();return t===`text`||Ut(t,Dt)}function Vt(e,t){let n=Ht(e);return Ht(t)>n?t:e}function Ht(e){let t=(e.type??``).toLowerCase(),n=0;return Ut(t,Et)?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 Ut(e,t){return t.some(t=>e.includes(t))}function Wt(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:Vt(n,r).index===n.index}function Gt(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 Kt(e,t,n){if(n.raw||!qt(e))return{nodes:t,filteredCount:0};let r=Jt(t);return{nodes:r,filteredCount:t.length-r.length}}function qt(e){let t=e.androidSnapshot;return!t||typeof t!=`object`?!1:t.backend===`android-helper`}function Jt(e){if(e.length===0)return e;let t=new Set,n=new Map,r=new Map(e.map(e=>[e.index,e]));return Yt(e,t),Xt(e,r,t,n),Ot(e,t,n),At(e,t),kt(e,t,n),e.filter(e=>!t.has(e.index)).map(e=>n.get(e.index)??e)}function Yt(e,t){for(let n of e)!n.rect||T(n.rect)||xt(n)||k(e,n.index,t)}function Xt(e,t,n,r){for(let i of e){if(n.has(i.index)||i.rect||xt(i))continue;let a=wt(i,t,St);a&&Qt(r,a,Zt(i,e)),k(e,i.index,n)}}function Zt(e,t){let n=t.filter(t=>t.parentIndex===e.parentIndex&&t.rect&&T(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 Qt(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 $t(e){return[...en(e),...rn(e)]}function en(e){let t=an(e?.candidates);if(t.length===0)return[];let n=typeof e?.matches==`number`?e.matches:t.length,r=typeof e?.refsGeneration==`number`?e.refsGeneration:void 0,i=n-t.length;return[`Candidates:`,...t.map(e=>` ${nn(e,r)}`),...i>0?[` +${i} more`]:[]]}function tn(e){return an(e?.candidates).flatMap(e=>{let t=/^@(e\d+)(?:~s\d+)?(?:\s|$)/.exec(e);return t?.[1]?[t[1]]:[]})}function nn(e,t){return t===void 0?e:e.replace(/^@(e\d+)(?=\s|$)/,`@$1~s${t}`)}function rn(e){let t=on(e?.devices);return t.length===0?[]:[`Devices:`,...t.map(e=>` ${e.id} ${e.name}`)]}function an(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function on(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`&&typeof e.name==`string`):[]}function sn(e){if(e.length<20)return!1;let t=new Map;for(let n of e){let e=(n.type??``).toLowerCase(),r=cn(ue(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||!un(e)||(n+=e.length);return n>=8}function cn(e){let t=e.trim().replace(/\s+/g,` `).toLowerCase();return!t||ln(t)?null:t}function ln(e){return/\S+@\S+\.\S+/.test(e)}function un(e){for(let t=0;t<e.length;t+=1)for(let n=t+1;n<e.length;n+=1)if(dn(e[t]?.rect,e[n]?.rect))return!0;return!1}function dn(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 fn={digest:8*1024,default:24*1024,full:64*1024};function pn(e){return e===`digest`||e===`full`?e:`default`}function mn(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 A(e,n=256){return mn(t(e),n)}function hn(e,t){let n=e;for(let e of t)e.value&&(n=n.split(e.value).join(`<var:${e.name}>`));return n}function gn(e){return(t,n)=>A(hn(t,e),n)}function _n(e,t){return e.state!==`available`||e.refs.length<=t?e:{...e,refs:e.refs.slice(0,t),truncated:!0}}function vn(e,t){let n=pn(t),r=n===`digest`?8:20,i=_n(e.screen,r),a=n===`digest`?[]:e.suggestions.slice(0,5);return{...e,screen:i,suggestions:a}}function yn(e){return Buffer.byteLength(JSON.stringify(e),`utf8`)}function bn(e){let{divergence:t,level:n,writeOverflowArtifact:r}=e,i=pn(n),a=fn[i],o=vn(t,n),s=yn(o);if(s<=a)return o;let c=s-a,l=r(vn(t,`full`)),u=xn(o);return`artifactPath`in l?{...u,overflow:{omittedBytes:c,artifactPath:l.artifactPath}}:{...u,artifactUnavailable:!0}}function xn(e){return{version:e.version,kind:e.kind,step:{index:e.step.index,source:{path:A(e.step.source.path),line:e.step.source.line}},action:A(e.action),cause:{code:e.cause.code,message:A(e.cause.message),...e.cause.hint?{hint:A(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 Sn(e){let t=e?.divergence;if(!t||typeof t!=`object`)return null;let n=t,r=[...Pn(n.step),...An(n.kind,n.targetBinding),...Cn(n.repairHint,n.resume),...Fn(n.screen),...zn(n.suggestions,n.suggestionCount),...Vn(n.overflow,n.artifactUnavailable)];return r.length>0?r.join(`
|
|
2
|
-
`):null}function Cn(e,t){if(typeof e!=`string`)return[];let n=En(e,t);return[`Repair hint: ${e}${n?` — ${n}`:``}`]}function wn(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 j(e,t){return`replay --from ${e} --plan-digest ${t}`}function Tn(e){return e?.repairSessionHeld===!0}function En(e,t){let n=Dn(e,wn(t));if(n!==void 0)return Tn(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 Dn(e,t){switch(e){case`record-and-heal`:return t?.allowed?`press the correct control via a blessed @ref from screen.refs (recorded), then ${j(t.from,t.planDigest)}.`:`press the correct control via a blessed @ref from screen.refs (recorded). ${kn(t)}`;case`state-repair`:return t?.allowed?`fix app state with --no-record actions, then ${j(t.from,t.planDigest)} to re-run it.`:`fix app state with --no-record actions. ${kn(t)}`;case`caution`:return On({lead:`something already matches the recorded selector; a blind re-press may repeat the mistake.`,guidance:t});case`manual`:return On({lead:`no safe automated repair could be proven; inspect the screen and repair by hand.`,guidance:t});default:return}}function On(e){let{lead:t,guidance:n}=e;if(!n?.allowed)return`${t} ${kn(n)}`;let r=`if you fixed app state with --no-record actions: ${j(n.from,n.planDigest)}`;return n.alternateFrom===void 0?`${t} ${r}.`:`${t} ${r}; ${`if you performed the step's intent as a recorded action: ${j(n.alternateFrom,n.planDigest)}`}.`}function kn(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?[jn(e,n.matchCount),...Mn(n.mismatches),...Nn(n.candidates)]:[]}function jn(e,t){return`Target binding: ${e}${typeof t==`number`?` (matchCount ${t})`:``} — recorded target evidence did not verify.`}function Mn(e){return!Array.isArray(e)||e.length===0?[]:[` mismatches: ${e.slice(0,5).join(`; `)}`]}function Nn(e){return!Array.isArray(e)||e.length===0?[]:[` ${e.length} candidate(s) shared the recorded identity:`,...e.slice(0,5).map(e=>` ${Rn(e)}`)]}function Pn(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 Fn(e){let t=e;return t?.state===`available`&&Array.isArray(t.refs)?In(t.refs,t.refsGeneration):t?.state===`unavailable`?[Ln(t)]:[]}function In(e,t){let n=e.slice(0,8).map(Rn),r=e.length-n.length;return[`Screen: ${e.length} actionable ref(s) captured (refsGeneration ${t}).`,...n,...r>0?[` ... ${r} more`]:[]]}function Ln(e){let t=typeof e.hint==`string`&&e.hint.length>0?` ${e.hint}`:``;return`Screen: unavailable (${String(e.reason??`unknown`)}).${t}`}function Rn(e){let t=e,n=typeof t.label==`string`?` "${t.label}"`:``;return` @${String(t.ref)} [${String(t.role)}]${n}`}function zn(e,t){return Array.isArray(e)&&e.length>0?[`Suggestions:`,...e.slice(0,5).map(Bn)]:typeof t==`number`&&t>0?[`Suggestions: ${t} available (omitted at this response level; rerun with --json for the full report).`]:[]}function Bn(e){let t=e,n=typeof t.label==`string`?` "${t.label}"`:``;return` - [${String(t.basis)}]${n} ${String(t.selector)}`}function Vn(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.`]:[]}function Hn(e){let t=M(e.label),n=M(e.value),r=M(e.identifier),i=Jn(r)?r:``;return qn(e.type??``)?n||t||i:t||n||i}function Un(e,t){if(t===`text-view`||t===`text-field`||t===`search`)return!0;let n=v(e.type??``),r=`${e.role??``} ${e.subrole??``}`.toLowerCase();return n.includes(`textview`)||n.includes(`textarea`)||n.includes(`textfield`)||n.includes(`securetextfield`)||n.includes(`searchfield`)||n.includes(`edittext`)||r.includes(`text area`)||r.includes(`text field`)}function Wn(e){let t=e.replace(/\s+/g,` `).trim();return t.length<=48?t:`${t.slice(0,45)}...`}function Gn(e,t){let n=Hn(e),r=Un(e,t);return{text:n,isLargeSurface:r,shouldSummarize:r&&Kn(n)}}function Kn(e){return e?e.length>80||/[\r\n]/.test(e):!1}function M(e){return typeof e==`string`?e.trim():``}function qn(e){let t=v(e);return t.includes(`textfield`)||t.includes(`securetextfield`)||t.includes(`searchfield`)||t.includes(`edittext`)||t.includes(`textview`)||t.includes(`textarea`)}function Jn(e){return e?!/^[\w.]+:id\/[\w.-]+$/i.test(e)&&!/^_?NS:\d+$/i.test(e):!1}const Yn={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`,heading:`heading`,activityindicator:`activity-indicator`,progressindicator:`progress-indicator`,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 Xn(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=F(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:N(i,c,!1,o,t)})}return r}function N(e,t,n,r,i={}){let a=r??F(e.type??`Element`),o=Gn(e,a),s=rr(e,a,i,o),c=` `.repeat(t),l=e.ref?`@${e.ref}`:``,u=ir(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}"`:``,p=Zn(e);return n?`${c}${l} [${a}]${d}${p}`.trimEnd():`${c}${l} [${a}]${f}${d}${p}`.trimEnd()}function Zn(e){let t=e.actions?.filter(e=>e.trim().length>0);return!t||t.length===0?``:` actions: [${t.map(e=>`"${sr(Qn(e))}"`).join(`, `)}]`}function Qn(e){return e.replace(/\s+/g,` `).replace(/[\u0000-\u001f\u007f-\u009f]/g,``).trim()}function P(e,t){let n=e.label?.trim();if(n&&tr(t,n))return``;let r=e.value?.trim();if(er(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||nr(i)&&(t===`group`||t===`image`||t===`list`||t===`collection`)?``:i}function F(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`:$n(n)||n||`element`}function $n(e){return Object.prototype.hasOwnProperty.call(Yn,e)?Yn[e]:void 0}function er(e){return e===`text-field`||e===`text-view`||e===`search`}function tr(e,t){return e!==`scroll-area`&&e!==`list`&&e!==`collection`&&e!==`table`?!1:Ne(t)}function nr(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function rr(e,t,n,r){return!n.summarizeTextSurfaces||!r.shouldSummarize?P(e,t):ar(e,t,r.text)||P(e,t)}function ir(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`),er(t)&&i.push(`editable`),or(e,t)&&i.push(`scrollable`),!r.shouldSummarize)?cr(i):(i.push(`preview:"${sr(Wn(r.text))}"`),i.push(`truncated`),cr(i))}function ar(e,t,n){let r=M(e.label);if(r&&r!==n)return r;let i=M(e.identifier);if(i&&!nr(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 or(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 sr(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function cr(e){return[...new Set(e)]}function lr(e){process.stdout.write(`${JSON.stringify(e,null,2)}\n`)}function ur(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`);let a=$t(i.details);a.length>0&&process.stderr.write(`${a.join(`
|
|
3
|
-
`)}\n`),i.diagnosticId&&process.stderr.write(`Diagnostic ID: ${i.diagnosticId}\n`),i.logPath&&process.stderr.write(`Diagnostics Log: ${i.logPath}\n`);let o=Sn(i.details);o&&process.stderr.write(`${o}\n`),r.showDetails&&i.details&&process.stderr.write(`${JSON.stringify(i.details,null,2)}\n`)}function dr(e,t={}){let n=e.nodes,r=Array.isArray(n)?n:[],o=a(i(e.backend)?e.backend:void 0),s=Kt(e,r,t),c=hr(e),l=Fr(e,r,t,s),u=l.length>0?`${l.join(`
|
|
4
|
-
`)}\n`:``,d=t.raw?null:fr(e);if(d)return`${c}${u}${pr(d)}\n`;let f=t.raw||!o?null:Fe(s.nodes),p=!!e.truncated,m=f?.nodes??r,h=t.raw||!o?null:xr(e,f,m.length,r.length,s.filteredCount),g=gr(r.length,h,p);return r.length===0?`${c}${g}\n${u}`:t.raw?`${c}${g}\n${u}${_r(r)}\n`:t.flatten?`${c}${g}\n${u}${vr(m)}${br(f)}\n`:`${c}${g}\n${u}${yr(m)}${br(f)}\n`}function fr(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 pr(e){let t=mr(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(`
|
|
5
|
-
`):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(`
|
|
6
|
-
`):[`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(`
|
|
7
|
-
`)}function mr(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 hr(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(`
|
|
8
|
-
`)}\n`:``}function gr(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 _r(e){return e.map(e=>JSON.stringify(e)).join(`
|
|
9
|
-
`)}function vr(e){return Wr(e).join(`
|
|
10
|
-
`)}function yr(e){return Vr(Xn(e,{summarizeTextSurfaces:!0})).join(`
|
|
11
|
-
`)}function br(e){return e&&e.summaryLines.length>0?`\n${e.summaryLines.join(`
|
|
12
|
-
`)}`:``}function xr(e,t,n,r,i=0){let a=Sr(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:Cr([...a?.reasons??[],`offscreen-nodes`])}:a||(s?{partial:!0,visibleNodeCount:n,totalNodeCount:n,reasons:[]}:null)}function Sr(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 Cr(e){return[...new Set(e)]}function wr(e){let t=e.baselineInitialized===!0,n=e.summary??{},r=I(n.additions),i=I(n.removals),a=I(n.unchanged),o=Nr(),s=Br(e),c=s.length>0?`${s.join(`
|
|
13
|
-
`)}\n`:``;if(t)return`${c}Baseline initialized (${a} lines).\n`;let l=Mr(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?L(e,`green`):e}if(e.kind===`removed`){let e=t.startsWith(` `)?`-${t}`:`- ${t}`;return o?L(e,`red`):e}return o?L(t,`dim`):t}),u=l.length>0?`${l.join(`
|
|
14
|
-
`)}\n`:``;return o?`${c}${u}${[`${L(String(r),`green`)} additions`,`${L(String(i),`red`)} removals`,`${L(String(a),`dim`)} unchanged`].join(`, `)}\n`:`${c}${u}${r} additions, ${i} removals, ${a} unchanged\n`}function Tr(e){let t=Nr(),n=e.match===!0,r=e.dimensionMismatch,i=[];return i.push(...Er(e,t)),i.push(...Dr(e,n,t)),!n&&!r&&(i.push(...Or(e,t)),i.push(...kr(e,t))),`${i.join(`
|
|
15
|
-
`)}\n`}function Er(e,t){if(e.match===!0)return[`${t?L(`✓`,`green`):`✓`} Screenshots match.`];let n=e.dimensionMismatch,r=t?L(`✗`,`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=I(e.differentPixels),a=I(e.mismatchPercentage),o=`${a===0&&i>0?`<0.01`:String(a)}% pixels differ`;return[`${r} ${t?L(o,`red`):o}`]}function Dr(e,t,n){if(t)return[];let r=[];if(e.diffPath){let t=jr(e.diffPath),i=n?L(`Diff image:`,`dim`):`Diff image:`,a=n?L(t,`green`):t;r.push(` ${i} ${a}`)}if(e.currentOverlayPath){let t=jr(e.currentOverlayPath),i=n?L(`Current overlay:`,`dim`):`Current overlay:`,a=n?L(t,`green`):t,o=I(e.currentOverlayRefCount),s=o>0?` (${o} refs)`:``;r.push(` ${i} ${a}${s}`)}return r}function Or(e,t){let n=I(e.differentPixels),r=I(e.totalPixels);return[` ${t?L(String(n),`red`):String(n)} different / ${r} total pixels`]}function kr(e,t){let n=Array.isArray(e.regions)?e.regions:[];if(n.length===0)return[];let r=[` ${Pr(`Changed regions:`,t)}`];for(let e of n.slice(0,5))r.push(...Ar(e));return r}function Ar(e){let t=e.shareOfDiffPercentage===0&&e.differentPixels>0?`<0.01`:String(e.shareOfDiffPercentage),n=e.rect,r=[` ${e.index}. x=${n.x} y=${n.y} ${n.width}x${n.height}, ${t}% of diff`],i=e.currentOverlayMatches?.[0];if(i){let e=i.label?` "${i.label}"`:``;r.push(` overlaps @${i.ref}${e}, ${i.regionCoveragePercentage}% of region`)}return r}function jr(e){let t=process.cwd(),n=ze.relative(t,e);return n===``||!n.startsWith(`..`)&&!ze.isAbsolute(n)?n===``?`.`:`.${ze.sep}${n}`:e}function I(e){return typeof e==`number`&&Number.isFinite(e)?e:0}function Mr(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 Nr(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 L(e,t,n){return Be(t,e,n)}function Pr(e,t){return t?L(e,`dim`):e}function Fr(e,t,n,r={nodes:t,filteredCount:0}){let i=[...Br(e),...Ir(e)];if(Lr(e)){let e=zr(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&&sn(a)&&i.push(`Warning: possible repeated nav subtree detected.`),i}function Ir(e){let t=e.fallbackScreenshotPath;return typeof t==`string`&&t.length>0?[`Captured a screenshot of this screen automatically as visual truth: ${t}`]:[]}function Lr(e){return!e.snapshotQuality&&!Rr(e)}function Rr(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 zr(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 Br(e){let t=e.warnings;return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.length>0):[]}function Vr(e){let t=[],n=[],r=new Map(e.map(e=>[e.node.index,e.node])),i=e=>{for(;n.length>0&&(!e||Hr(e,n[n.length-1],r));)t.push(...Gr(n.pop(),`below`))};for(let r of e)i(r),t.push(r.text),t.push(...Gr(r,`above`)),r.node.hiddenContentBelow&&n.push(r);return i(),t}function Hr(e,t,n){return Ur(e.node,t.node,n)?!1:e.depth<=t.depth}function Ur(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 Wr(e){return Xn(e,{summarizeTextSurfaces:!0}).flatMap(e=>[N(e.node,0,!1,e.type,{summarizeTextSurfaces:!0}),...Gr({...e,depth:0})])}function Gr(e,t){let n=Kr(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 Kr(e){return e===`scroll-area`||e===`list`||e===`collection`||e===`table`?e:null}const qr={defaultTimeoutMs:1e4,intervalMs:300},R={promotedTarget:{resolution:b.act,occlusion:`exclude-and-refuse`,offscreen:`refuse`,promotion:`hittable-ancestor`,poll:`none`},resolvedTarget:{resolution:b.act,occlusion:`exclude-and-refuse`,offscreen:`refuse`,promotion:`none`,poll:`none`},coveredDiagnosis:{resolution:b.actCoveredDiagnosis,occlusion:`refuse`,offscreen:`ignore`,promotion:`none`,poll:`none`},readText:{resolution:b.readText,occlusion:`ignore`,offscreen:`ignore`,promotion:`none`,poll:`none`},readUnique:{resolution:b.readUnique,occlusion:`ignore`,offscreen:`ignore`,promotion:`none`,poll:`none`},readAny:{resolution:b.readAny,occlusion:`ignore`,offscreen:`ignore`,promotion:`none`,poll:`none`},findWait:{resolution:b.readAny,occlusion:`ignore`,offscreen:`ignore`,promotion:`none`,poll:qr},wait:{resolution:b.wait,occlusion:`ignore`,offscreen:`ignore`,promotion:`none`,poll:qr},readList:{resolution:b.readList,occlusion:`ignore`},findAct:{resolution:b.findAct,occlusion:`refuse`,offscreen:`ignore`,promotion:`hittable-ancestor-below-root`,poll:`none`}};function Jr(e,t,n={}){let r=$r(e);if(r.length===0)return{canScroll:!1,emptySnapshot:!0};let i=Me(r),a=ei(r,i,t,n);return a?{canScroll:ni(a,i.get(a.index),t),emptySnapshot:!1,scope:ri(a,r)}:{canScroll:!1,emptySnapshot:!1}}async function Yr(e){let{edge:t,target:n={},scope:r,captureNodes:i}=e;try{let e=Jr(await i(r),t,n);return r&&e.emptySnapshot?await Yr({edge:t,target:n,captureNodes:i}):e}catch(e){throw Qr(t,r,e)}}async function Xr(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 Zr(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 Qr(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 $r(e){return e.map((e,t)=>({...e,ref:`ref`in e&&e.ref?e.ref:`e${t+1}`}))}function ei(e,t,n,r){let i=new Map(e.map(e=>[e.index,e])),a=e.filter(e=>we(e)&&li(e.rect));if(a.length===0)return null;let o=ti(r.nodeIndex,i);if(o)return o;let s=r.point;if(s){let e=a.filter(e=>e.rect&&ci(e.rect,s)).sort(oi);if(e.length>0)return e.find(e=>ni(e,t.get(e.index),n))??e[0]??null}let c=a.filter(e=>ni(e,t.get(e.index),n)).sort(si);return c.length>0?c[0]??null:a.filter(t=>oe(t,e)).sort(si)[0]??a.sort(si)[0]??null}function ti(e,t){if(e===void 0)return null;let n=t.get(e);for(;n;){if(we(n)&&li(n.rect))return n;n=n.parentIndex===void 0?void 0:t.get(n.parentIndex)}return null}function ni(e,t,n){return n===`bottom`?e.hiddenContentBelow===!0||t?.hiddenContentBelow===!0:e.hiddenContentAbove===!0||t?.hiddenContentAbove===!0}function ri(e,t){return[e.identifier,e.label].filter(e=>typeof e==`string`).map(e=>e.trim()).find(n=>ai(n)&&ii(n,e,t))}function ii(e,t,n){let r=e.toLowerCase(),i=n.filter(e=>[e.identifier,e.label,e.value].some(e=>typeof e==`string`&&e.trim().toLowerCase().includes(r)));return i.length===1&&i[0]?.index===t.index}function ai(e){return e.length>0&&e.length<=80&&!/^(true|false)$/i.test(e)&&!/^\d+$/.test(e)&&!/^\d+%$/.test(e)}function oi(e,t){return z(e.rect)-z(t.rect)}function si(e,t){return z(t.rect)-z(e.rect)}function z(e){return e?e.width*e.height:0}function ci(e,t){return t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height}function li(e){return!!(e&&e.width>0&&e.height>0)}function ui(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 B(e,t){return{session:t.session,requestId:t.requestId,signal:t.signal??e.signal,metadata:t.metadata}}function V(e){return e.clock?.now()??Date.now()}async function di(e,t){e.clock?await e.clock.sleep(t):await new Promise(e=>setTimeout(e,t))}function fi(e,t){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,e=>n(t,e)]))}function H(e){return e&&typeof e==`object`?e:void 0}function pi(e){let t=Buffer.alloc(16);for(let n of e)hi(t,mi(n));return{digest:`ax1:${Ve(`sha256`).update(t).update(`\0`).update(String(e.length)).digest(`hex`).slice(0,16)}`,nodeCount:e.length}}function mi(e){return Ve(`sha256`).update(e.type??``).update(`\0`).update(e.label??``).update(`\0`).update(e.identifier??``).digest().subarray(0,16)}function hi(e,t){for(let n=0;n<e.length;n+=1)e[n]=(e[n]??0)^(t[n]??0)}function U(e){let{digest:t,nodeCount:n}=pi(e),r=e.reduce((e,t)=>t.hittable===!1?e:e+1,0),i=gi(e);return{digest:t,nodeCount:n,interactiveNodeCount:r,...i?{foregroundApp:i}:{}}}function gi(e){for(let t of e)if(t.bundleId)return t.bundleId;for(let t of e)if(t.appName)return t.appName}const _i=[`x`,`y`,`width`,`height`];function W(e){let t=G(e);if(!t)return null;let n=s(t);return!Number.isFinite(n.x)||!Number.isFinite(n.y)?null:n}function G(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 K(e,t){return!e||!t?!1:_i.every(n=>Math.abs(e[n]-t[n])<=.5)}function vi(e){return{x:yi(e.x,e.width),y:yi(e.y,e.height)}}function yi(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)))}function bi(e,t,n,r){let i=n.ambiguity,a=me(e,t,{...r,requireRect:n.requireRect});if(!a||a.matchedNodes.length===0)return{kind:`none`};if(i===`first-match`)return Si(a);if(i===`reject-candidates`)return a.matchedNodes.length>1?xi(a):Si(a);let o=_e(e,t,{...r,...pe({ambiguity:i,requireRect:n.requireRect})});return o?{kind:`resolved`,resolution:o,matchedNodes:a.matchedNodes}:xi(a)}function xi(e){return{kind:`ambiguous`,selector:e.selector.raw,selectorIndex:e.selectorIndex,matchedNodes:e.matchedNodes}}function Si(e){let t=e.matchedNodes[0];return t?{kind:`resolved`,matchedNodes:e.matchedNodes,resolution:{node:t,selector:e.selector,selectorIndex:e.selectorIndex,matches:e.matchedNodes.length,diagnostics:[{selector:e.selector.raw,matches:e.matchedNodes.length}]}}:{kind:`none`}}function Ci(e,t,n){let r=me(e,l(t),n);return r?{...r,selector:r.selector.raw}:null}function wi(e,t,n,r){let i=bi(e,l(t),n,r);return i.kind===`resolved`?{...i,resolution:{...i.resolution,selector:i.resolution.selector.raw}}:i}const Ti=[`tabbar`,`toolbar`,`navigationbar`,`bottomnavigation`,`bottomnavigationview`,`sheet`,`dialog`,`alert`,`popover`,`menu`],Ei=[`tabbar`,`toolbar`,`navigationbar`],Di=[`button`,`link`,`menuitem`,`tabitem`,`textfield`,`searchfield`,`edittext`,`checkbox`,`radio`,`switch`,`cell`];function Oi(e,t={}){if(e.length<2)return e;let n=new Map(e.map(e=>[e.index,e])),r={nodes:e,byIndex:n,overlayPositions:e.flatMap((e,r)=>Fi(e,n,t)?[r]:[]),coverCache:new Map},i=[];for(let[n,a]of e.entries())Pi(a)&&ki(r,n,a,t)&&i.push(n);if(i.length===0)return e;let a=[...e];for(let t of i){let n=e[t];a[t]={...n,hittable:!1,interactionBlocked:`covered`,presentationHints:Gi(n.presentationHints)}}return a}function q(e){return e.interactionBlocked!==void 0}function ki(e,t,n,r){let i=e.coverCache.get(t);if(i!==void 0)return i;e.coverCache.set(t,null);let a=J(n.rect);if(!a)return ji(e,t,null);let o=s(a),c=r.isAdditionalOverlayNode?.(n)===!0;for(let i of e.overlayPositions){if(!Ai(e,i,t,c,r))continue;let s=e.nodes[i];if(Mi(e,i,n,a,o,r))return ji(e,t,s)}return ji(e,t,null)}function Ai(e,t,n,r,i){let a=e.nodes[t];return a?t>n?!0:t===n||r?!1:i.isAdditionalOverlayNode?.(a)===!0:!1}function ji(e,t,n){return e.coverCache.set(t,n),n}function Mi(e,t,n,r,i,a){if(!e.nodes[t])return!1;let o=Ni(e,t,n,r,a);return!!(o&&x(o,i.x,i.y))}function Ni(e,t,n,r,i){let a=e.nodes[t];if(!a||!Fi(a,e.byIndex,i)||Ui(n,a,e.byIndex))return null;let o=J(a.rect);return!o||K(r,o)||ki(e,t,a,i)?null:o}function Pi(e){return J(e.rect)?e.hittable===!0||Bi(e)?!0:!!(e.label?.trim()||e.value?.trim()||e.identifier?.trim()):!1}function Fi(e,t,n){return!J(e.rect)||y(e)||Ii(e,t)?!1:Vi(e,Ti)||Li(e,t,n)}function Ii(e,t){if(!Vi(e,Ei))return!1;let n=J(e.rect);if(!n)return!1;let r=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);){if(y(r)){let e=J(r.rect);return!!(e&&K(n,e))}i.add(r.index),r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0}return!1}function Li(e,t,n){return n.isAdditionalOverlayNode?.(e)===!0?!Ri(e,t,n):!1}function Ri(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(zi(r,n))return!0;i.add(r.index),r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0}return!1}function zi(e,t){return t.isAdditionalOverlayNode?.(e)===!0&&J(e.rect)!==null&&!y(e)}function Bi(e){return Vi(e,Di)}function Vi(e,t){let n=Hi(e);return t.some(e=>n.includes(e))}function Hi(e){return[e.type,e.role,e.subrole].map(e=>v(e??``)).join(` `)}function Ui(e,t,n){return Wi(e,t,n)||Wi(t,e,n)}function Wi(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 J(e){let t=G(e);return t&&t.width>0&&t.height>0?t:null}function Gi(e){return Array.from(new Set([...e??[],`covered`]))}const Ki=[`button`,`link`,`menuitem`,`tabitem`,`textfield`,`searchfield`,`securetextfield`,`checkbox`,`radio`,`switch`,`cell`];function qi(e,t){let n=t[0];if(!n||!Ji(t,new Map(e.map(e=>[e.index,e]))))return{kind:`ambiguous`,candidates:t};let r=Y(e,n).node;for(let n of t.slice(1))if(Y(e,n).node.index!==r.index)return{kind:`ambiguous`,candidates:t};return{kind:`equivalent`,node:r}}function Ji(e,t){for(let n=0;n<e.length;n+=1)for(let r=n+1;r<e.length;r+=1){let i=e[n],a=e[r];if(!Yi(i,a,t)&&!Yi(a,i,t))return!1}return!0}function Yi(e,t,n){let r=t,i=new Set;for(;r.parentIndex!==void 0&&!i.has(r.index);){if(i.add(r.index),r.parentIndex===e.index)return!0;let t=n.get(r.parentIndex);if(!t)return!1;r=t}return!1}function Xi(e,t){if(!t?.rect||!e.rect||!y(e))return!1;let n=e.rect,r=t.rect;return n.x===r.x&&n.y===r.y&&n.width===r.width&&n.height===r.height}function Y(e,t){if(q(t))return{node:t,reason:`covered`};let n=Qi(e,t);if(n?.rect&&W(n.rect))return{node:n,reason:`same-rect-descendant`};if($i(t)&&t.rect&&W(t.rect))return{node:t,reason:`semantic-target`};let r=Zi(e,t);return r?.rect&&!q(r)&&W(r.rect)?ta(t,r,e)?{node:t,reason:`overly-broad-ancestor`}:{node:r,reason:`hittable-ancestor`}:{node:t,reason:`original`}}function Zi(e,t){return t.hittable?t:ie(e,t,e=>e.hittable===!0)}function Qi(e,t){let n=G(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||q(e))return!1;let t=G(e.rect);return t?K(t,n):!1});if(t.length!==1)break;r=t[0]}return r===t?null:r}function $i(e){return[e.type,e.role,e.subrole].map(e=>v(e??``)).some(ea)}function ea(e){return e===`tab`||Ki.some(t=>e.includes(t))}function ta(e,t,n){let r=G(e.rect),i=G(t.rect);if(!r||!i)return!1;if(na(t)&&!K(r,i))return!0;let a=ra(n,r);return!a||!ia(i,a)?!1:!K(r,i)}function na(e){let t=v(e.type??``);return t.includes(`scrollview`)||t.includes(`scrollarea`)||t.includes(`listview`)||t.includes(`recyclerview`)||t.includes(`collectionview`)||t===`list`||t===`table`||t===`collection`}function ra(e,t){let n=s(t),r=e.filter(y).map(e=>G(e.rect)).filter(e=>e!==null);if(r.length===0)return null;let i=r.filter(e=>x(e,n.x,n.y));return xe(i.length>0?i:r)}function ia(e,t){let n=Ie(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 aa(e,t,n,r,i={}){let a=wi(ca(e,t),n,e.resolution,r);if(a.kind===`none`)return{kind:`none`};if(a.kind===`ambiguous`)return{kind:`ambiguous`,selector:a.selector,selectorIndex:a.selectorIndex,matchedNodes:a.matchedNodes};let o=a.resolution,s=await sa(e,t,o.node,i);return s.kind===`occluded`?{kind:`occluded`,node:s.node,selector:o.selector}:{kind:`target`,node:s.node,selector:o.selector,selectorIndex:o.selectorIndex,matches:o.matches,matchedNodes:a.matchedNodes}}function oa(e,t,n,r){let i=ca(e,t);return{candidates:i,list:Ci(i,n,{...r,requireRect:e.resolution.requireRect})}}async function sa(e,t,n,r={}){r.onResolved?.(n,t);let i=la(e.promotion,t,n);return e.occlusion!==`ignore`&&(i.covered||q(i.node))?{kind:`occluded`,node:i.node}:{kind:`target`,node:await ua(e,t,i.node,r)}}function ca(e,t){return e.occlusion===`exclude-and-refuse`?t.filter(e=>!q(e)):t}function la(e,t,n){if(e===`none`)return{node:n,covered:!1};let r=Y(t,n);return r.reason===`covered`?{node:r.node,covered:!0}:e===`hittable-ancestor-below-root`&&Xi(r.node,t[0])&&n.rect?{node:n,covered:!1}:{node:r.node,covered:!1}}async function ua(e,t,n,r){if(e.offscreen!==`refuse`)return n;if(!r.offscreen)throw Error(`selector pipeline row declares an off-screen refusal but this route supplies no refusal shape`);return await r.offscreen(n,t)}function da(e){if(e.poll===`none`)throw Error(`selector pipeline row resolves against one capture and declares no poll budget`);return e.poll}function fa(e){let t=new Map;for(let n of e)t.set(n.index,n);return t}function pa(e,t,n){let r=[],i=new Set([e.index]),a=e;for(;r.length<n;){if(typeof a.parentIndex!=`number`)return{chain:r,broken:!1};let e=t.get(a.parentIndex);if(!e||i.has(e.index))return{chain:r,broken:!0};i.add(e.index);let n=f(e);r.push({role:n.role,...n.label===void 0?{}:{label:n.label}}),a=e}return{chain:r,broken:!1}}function ma(e,t,n,r){return e.filter(e=>{if(!p(f(e),n))return!1;let i=pa(e,t,Math.max(r.length,1));return!i.broken&&ee(i.chain,r)})}function ha(e){return e.hittable===!0||$i(e)}function ga(e,t){let n=Se(f(e),t);return n.id!==void 0||n.label!==void 0?!1:Ce(e.value)===null}function _a(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 va(e,t){let n=fa(t);return t.filter(t=>t.index!==e.index&&_a(t,e,n)).sort((e,t)=>e.index-t.index)}function ya(e,t){let n=W(e.rect);return!n||!t.rect?!1:x(t.rect,n.x,n.y)}function ba(e,t){if(!ga(e,t))return e;let n=va(e,t);if(n.some(ha))return e;let r=n.find(e=>f(e).label!==void 0);return!r||!ya(r,e)?e:r}function xa(e,t){let n=t.toLowerCase();return e.find(e=>{let t=(e.label??``).toLowerCase(),r=(e.value??``).toLowerCase(),i=(e.identifier??``).toLowerCase();return t.includes(n)||r.includes(n)||i.includes(n)})??null}function Sa(e,t){let n=ue(e);return n&&fe(n)?n:Ca(e,t)}function Ca(e,t){if(!e.rect)return;let n=e.rect.y+e.rect.height/2,r=null;for(let e of t){if(!e.rect)continue;let t=ue(e);if(!t||!fe(t))continue;let i=e.rect.y+e.rect.height/2,a=Math.abs(i-n);(!r||a<r.distance)&&(r={label:t,distance:a})}return r?.label}function wa(e){return e===`text`||e===`label`||e===`any`}function Ta(e,t,n,r){if(!(r||e===`web`))return wa(t)?n:void 0}function Ea(e){return new n(`COMMAND_FAILED`,`find could not read the current accessibility tree`,{reason:e.reason,hint:`The snapshot quality verdict is sparse. Use screenshot as visual truth, navigate with coordinates if needed, then retry find after reaching a readable screen.`})}async function Da(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 Oa(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(B(e,t),{interactiveOnly:r.interactiveOnly??!1,depth:t.depth,scope:r.scope??t.scope,raw:t.raw,includeRects:r.includeRects,...r.preferredBackend?{preferredBackend:r.preferredBackend}:{},...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:V(e)};return(t.signal??e.signal)?.throwIfAborted(),r.updateSession&&o&&!Re(c.snapshotQuality)&&await e.sessions.set({...o,snapshot:c}),{sessionName:a,session:o,snapshot:c}}async function ka(e,t,n){if(e.backend.readText){let r=await e.backend.readText(B(e,{session:t.sessionName}),n);if(r.text.trim())return r.text}return Hn(n)}function Aa(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?xa(e,i.fallbackLabel):null);if(!s)throw new n(`COMMAND_FAILED`,i.notFoundMessage);return{ref:a,node:s}}function ja(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 Ma(e,t,n={}){let r=G(t.rect),i=W(r??void 0);if(!r||!i)return{kind:`invalid`};let a=Na(e,t,r);if(a.length===0)return{kind:`resolved`,point:i,strategy:`center`};let o=(n.bounds??[]).reduce((e,t)=>e?Fa(e,t):null,r),s=o?Ia(r,o,i,a):null;return s?{kind:`resolved`,point:s,strategy:`parent-owned`}:{kind:`blocked`,competitorRefs:a.map(e=>e.ref)}}function Na(e,t,n){let r=new Map(e.map(e=>[e.index,e]));return e.filter(e=>e.index!==t.index).filter(e=>Pa(e,t,r)).filter($i).flatMap(e=>{let t=G(e.rect);if(!t||K(t,n))return[];let r=Fa(t,n);return r&&r.width>0&&r.height>0?[{ref:e.ref,index:e.index,rect:r}]:[]}).sort((e,t)=>e.index-t.index)}function Pa(e,t,n){let r=new Set,i=e;for(;typeof i.parentIndex==`number`&&!r.has(i.index);){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 Fa(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?null:{x:n,y:r,width:i-n,height:a-r}}function Ia(e,t,n,r){let i=Ha(e),a=Ba(t.x,t.width,n.x,r.flatMap(({rect:e})=>[e.x,e.x+e.width]),i),o=Ba(t.y,t.height,n.y,r.flatMap(({rect:e})=>[e.y,e.y+e.height]),i);return a.flatMap(a=>o.flatMap(o=>{let s={x:Math.round(a),y:Math.round(o)};if(!La(t,s))return[];let c=Ra(s,e,n,r,i);return c?[c]:[]})).sort(za)[0]?.point??null}function La(e,t){return t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height}function Ra(e,t,n,r,i){let a=Va(e,t,r);return a.parentEdge<i||a.competitor<12?null:{point:e,distanceSquared:(e.x-n.x)**2+(e.y-n.y)**2,clearance:Math.min(a.parentEdge,a.competitor)}}function za(e,t){return e.distanceSquared-t.distanceSquared||t.clearance-e.clearance||e.point.y-t.point.y||e.point.x-t.point.x}function Ba(e,t,n,r,i){let a=e+i,o=e+t-i;if(a>o)return[];let s=[...new Set([e,e+t,...r])].sort((e,t)=>e-t),c=new Set([n,a,o]);for(let e of r)c.add(e-12),c.add(e+12);for(let e=1;e<s.length;e+=1)c.add((s[e-1]+s[e])/2);return[...c].filter(e=>e>=a&&e<=o).sort((e,t)=>e-t)}function Va(e,t,n){let r=Math.min(e.x-t.x,t.x+t.width-e.x,e.y-t.y,t.y+t.height-e.y),i=1/0;for(let{rect:t}of n){let n=e.x<t.x?t.x-e.x:Math.max(0,e.x-(t.x+t.width)),r=e.y<t.y?t.y-e.y:Math.max(0,e.y-(t.y+t.height));i=Math.min(i,Math.max(n,r))}return{parentEdge:r,competitor:i}}function Ha(e){let t=Math.min(e.width,e.height);return Math.max(0,Math.min(12,Math.floor(t/2)-1))}const Ua=`replay_target_guard_mismatch`,Wa=Ae.landmarkIdentityMismatch;function Ga(e,t,r,i){let{candidates:a,list:o}=oa(i,e,t,{platform:r}),s=o?.matchedNodes??[];if(!o||s.length===0)return null;let c=[{selector:o.selector,matches:s.length}];if(s.length===1)return{node:s[0],selector:o.selector,selectorIndex:o.selectorIndex,matches:1,diagnostics:c};let l=qi(a,s);if(l.kind===`ambiguous`)throw new n(`AMBIGUOUS_MATCH`,`Selector matched ${l.candidates.length} distinct actionable elements: ${o.selector}`,{selector:o.selector,matches:l.candidates.length,candidates:l.candidates.slice(0,5).map(e=>N(e,0,!1))});return{node:l.node,selector:o.selector,selectorIndex:o.selectorIndex,matches:s.length,diagnostics:c,disambiguation:{matchCount:s.length,tiebreak:`structural-equivalence`,alternatives:s.filter(e=>e.index!==l.node.index)}}}function Ka(e,t,r,i,a){if(!r)return;let o=f(e),s=g(e,t);if(!(be(o,r.identity)&&u(s,r.structural)))throw new n(`COMMAND_FAILED`,`${i} resolved to a different element than replay verification isolated; the action was not sent`,{reason:Ua,observed:o,observedStructural:s,expected:r.identity,expectedStructural:r.structural,...a?{targetRole:a}:{}})}async function X(e,t,n){return await ho(e,t,n.action),t.target.kind===`point`?await Ja(e,t,t.target,n):t.target.kind===`ref`?await Qa(e,t,t.target,n):await $a(e,t,t.target,n)}async function 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(!x(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 Z(e,t,!0)).snapshot.nodes}catch{return}}function Xa(e,t){let r=o(e.ref);if(!r)throw new n(`INVALID_ARGS`,`Invalid ref: ${e.ref}`);let i=o(t.ref),a=t.node.ref?o(t.node.ref):null;if(i!==r||a!==r||!t.nodes.includes(t.node))throw new n(`COMMAND_FAILED`,`Internal find target provenance does not match the interaction ref`);return{nodes:t.nodes,resolved:io(r,t.node,`exact`)}}async function Za(e,t,n){let r=await _o(e,t,n);return{nodes:r.snapshot.nodes,resolved:r.resolved}}async function Qa(e,t,n,r){let{nodes:i,resolved:a}=r.preresolvedTarget?Xa(n,r.preresolvedTarget):await Za(e,t,n),s=await fo({policy:r.pipeline,nodes:i,node:a.node,action:r.action,label:`Ref ${n.ref}`,hooks:{onResolved:(e,t)=>to(e,t,r),offscreen:async(i,a)=>await Co(e,t,i,a,n.ref,r)}});return{kind:`ref`,point:bo(s,i,{invalidMessage:`Ref ${n.ref} not found or has invalid bounds`,blockedTargetLabel:`Ref ${n.ref}`,blockedTargetDetails:{ref:`@${o(n.ref)??s.ref}`}}),target:{kind:`ref`,ref:`@${a.ref}`},...co(e,s,i,r.action,a.resolution)}}async function $a(e,t,n,r){let i=n.selector,a=await Z(e,t,r.requireInteractive),o=Ga(a.snapshot.nodes,i,e.backend.platform,r.pipeline);if((!o||!o.node.rect)&&r.requireInteractive&&(a=await Z(e,t,!1),o=Ga(a.snapshot.nodes,i,e.backend.platform,r.pipeline)),!o||!o.node.rect)throw await eo({runtime:e,nodes:a.snapshot.nodes,selectorExpression:i,action:r.action,resolved:o});let s=o,c=await fo({policy:r.pipeline,nodes:a.snapshot.nodes,node:s.node,action:r.action,label:`Selector ${s.selector}`,hooks:{onResolved:(e,t)=>to(e,t,r),offscreen:async(n,i)=>await So(e,t,n,i,s.selector,r)}});return{kind:`selector`,point:bo(c,a.snapshot.nodes,{invalidMessage:`Selector ${o.selector} resolved to invalid bounds`,blockedTargetLabel:`Selector ${i}`,blockedTargetDetails:{selector:i}}),target:{kind:`selector`,selector:o.selector},...co(e,c,a.snapshot.nodes,r.action,oo(o,a.snapshot.nodes))}}async function eo(e){let{runtime:t,nodes:r,selectorExpression:i,action:a,resolved:o}=e,s=await aa(R.coveredDiagnosis,r,i,{platform:t.backend.platform});if(s.kind===`occluded`)return po({label:`Selector ${s.selector}`,node:s.node,action:a,selector:s.selector});let c=o?.diagnostics??[];return new n(`COMMAND_FAILED`,ae(i,c,{unique:!0}),{hint:se(c)})}function to(e,t,n){Ka(e,t,n.expectedResolvedTarget,n.action,n.replayTargetRole)}const no={source:`ref`,phase:`pre-action`,kind:`exact`},ro={source:`ref`,phase:`pre-action`,kind:`label-fallback`};function io(e,t,n){return{ref:e,node:t,resolution:n===`exact`?no:ro}}const ao={source:`runtime`,phase:`pre-action`,kind:`unique`};function oo(e,t){return e.disambiguation?{source:`runtime`,phase:`pre-action`,kind:`disambiguated`,matchCount:e.disambiguation.matchCount,winnerDiagnostic:so(e.node,t),tiebreak:e.disambiguation.tiebreak,alternatives:e.disambiguation.alternatives.slice(0,5).map(e=>so(e,t))}:ao}function so(e,t){let n=v(e.type??``),r=Sa(e,t);return{diagnosticRef:`diag-${e.ref}`,...n?{role:ja(n,256)}:{},...r===void 0?{}:{label:ja(r,256)}}}function co(e,t,n,r,i){return{node:t,selectorChain:ye(t,e.backend.platform,{action:r===`fill`?`fill`:`click`,nodes:n}),refLabel:Sa(t,n),...uo(t,r),preActionNodes:n,resolution:i,...lo(e,t,n,r)}}function lo(e,t,n,r){if(r!==`click`&&r!==`press`)return{};let i=ba(t,n);return i===t?{}:{recordingTarget:{node:i,selectorChain:ye(i,e.backend.platform,{action:`click`,nodes:n}),refLabel:Sa(i,n)}}}function uo(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.`}:{}}async function fo(e){let t=await sa(e.policy,e.nodes,e.node,e.hooks);if(t.kind===`occluded`)throw po({label:e.label,node:t.node,action:e.action});return t.node}function po(e){return new n(`COMMAND_FAILED`,`${e.label} is covered by another visible element and cannot ${mo(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 mo(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 Z(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(B(e,t),{interactiveOnly:r,includeRects:!0}),s=o.snapshot??{nodes:o.nodes??[],truncated:o.truncated,backend:o.backend,createdAt:V(e)};return await e.sessions.set({...a,snapshot:s}),{snapshot:s}}async function ho(e,t,r){if(e.backend.platform!==`macos`)return;let i=await go(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 go(e,t){return(await e.sessions.get(t.session??`default`))?.metadata?.surface}async function _o(e,t,r){let{session:i,snapshot:a}=await Da(e,t.session),o=r.fallbackLabel??``,s=yo(a.nodes,r.ref,{fallbackLabel:o});if(!s)throw new n(`COMMAND_FAILED`,`Ref ${r.ref} not found or has no bounds`,{hint:ge});return vo({session:i,frameTree:a,target:r,fallbackLabel:o,authorized:s})}function vo(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=yo(o.nodes,r.ref,{fallbackLabel:i});return s&&be(f(a.node),f(s.node))?{snapshot:o,resolved:s}:{snapshot:n,resolved:a}}function yo(e,t,i){let a=o(t);if(!a)throw new n(`INVALID_ARGS`,`Invalid ref: ${t}`);let s=r(e,a);if(xo(s))return io(a,s,`exact`);let c=i.fallbackLabel.length>0?xa(e,i.fallbackLabel):null;return xo(c)?io(a,c,`label-fallback`):null}function bo(e,t,r){let i=Ma(t,e,{bounds:[ve(e,t),e.rect?ce(t,e.rect):null].filter(e=>e!==null)});if(i.kind===`resolved`)return i.point;throw i.kind===`invalid`?new n(`COMMAND_FAILED`,r.invalidMessage):new n(`COMMAND_FAILED`,`${r.blockedTargetLabel} has no parent-owned touch point outside its interactive descendants`,{reason:`covered_by_interactive_descendants`,...r.blockedTargetDetails,competitorRefs:i.competitorRefs.slice(0,5).map(e=>`@${e}`),competitorCount:i.competitorRefs.length,hint:`Tap the specific interactive child you intend, or use a more specific selector. Every safely tappable region of the parent belongs to one of its child controls.`})}function xo(e){return e?W(e.rect)!==null:!1}async function So(e,t,n,r,i,{action:a}){return await Eo(e,t,n,r,{message:`Selector ${i} resolved to an off-screen element and is not safe to ${a}`,details:{reason:`offscreen_selector`,selector:i},hint:e=>`${wo(e)} in small steps, retrying ${a} with the same selector after each (it re-resolves against a fresh snapshot). A single large scroll can overshoot the target; a short bounded gesture pan lands it more reliably. If it is inside a closed drawer or another tab, open that container first.`})}async function Co(e,t,n,r,i,{action:a}){return await Eo(e,t,n,r,{message:`Ref ${i} is off-screen and not safe to ${a}`,details:{reason:`offscreen_ref`,ref:o(i)},hint:e=>`${wo(e)} in small steps (a single large scroll can overshoot; a short bounded gesture pan lands it more reliably), then retry ${a} with a selector (e.g. text=/id=) rather than this @ref — the scroll expires the ref frame, so re-run snapshot -i before reusing any @ref.`})}function wo(e){return e?`Scroll ${e} toward it`:`Scroll toward it`}async function To(e,t,n,r){let i=(await e.sessions.get(t.session??`default`))?.snapshot?.nodes;if(!i||o(n.ref)===null)return{};let a=yo(i,n.ref,{fallbackLabel:n.fallbackLabel??``});if(!a)return{};let s=R.resolvedTarget,c=await fo({policy:s,nodes:i,node:a.node,action:r,label:`Ref ${n.ref}`,hooks:{offscreen:async(i,a)=>await Co(e,t,i,a,n.ref,{action:r,pipeline:s})}});return{...uo(c,r),node:c,preActionNodes:i}}async function Eo(e,t,r,i,a){let o=r.rect?ve(r,i):null;if(!r.rect||!o||he(r,i))return r;let s=ce(i,r.rect),c=await e.backend.confirmOffscreenTargetVisible?.(B(e,t),r,s);if(c)return{...r,rect:c};let l=Pe(r,i);throw new n(`COMMAND_FAILED`,a.message,{...a.details,rect:r.rect,viewport:o,...l?{scrollDirection:l}:{},hint:a.hint(l)})}function Do(e,t){let n=F(e.type??`Element`),r=P(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,e.actions?JSON.stringify(e.actions):``].join(`|`)}function Oo(e,t,n={}){let r=jo(Ao(e,n),Ao(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 ko(e,t={}){return Ao(e,t).length}function Ao(e,t){return t.flatten?e.map(e=>({text:N(e,0,!1),comparable:Do(e,0),...t.withRefs&&e.ref?{ref:e.ref}:{}})):Xn(e).map(e=>({text:e.text,comparable:Do(e.node,e.depth),...t.withRefs&&e.node.ref?{ref:e.node.ref}:{}}))}function jo(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=No(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 Mo(o,e,t,n,r)}}return[]}function Mo(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=No(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 No(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 Po=new Set([`textfield`,`securetextfield`,`textview`,`textarea`,`searchfield`,`edittext`]),Fo={strippedIndexes:new Set,refs:new Set};function Io(e){let t=new Set(e.filter(e=>v(e.type??``)===`keyboard`).map(e=>e.index));if(t.size===0)return Fo;let n=new Map(e.map(e=>[e.index,e])),r=Vo(e,n,t),i=new Set(r),a=Yo(e,n,r);for(let t of Vo(e,n,a))i.add(t);for(let o of Lo(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 Lo(e,t,n,r,i){let a=new Set;if(n.size===0)return a;let o=zo(t,n,r);if(o.size===0)return a;let s=Bo(t,r);for(let n of e)!i.has(n.index)&&!s.has(n.index)&&n.rect&&Ro(n,t,o)&&a.add(n.index);return a}function Ro(e,t,n){if(!e.rect)return!1;let r=Xo(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 zo(e,t,n){let r=new Map;for(let i of n){let n=e.get(i);if(!n?.rect)continue;let a=Xo(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 Bo(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 Vo(e,t,n){let r=new Set(n);if(n.size===0)return r;for(let i of e)Zo(i,t,n)&&r.add(i.index);return r}function Ho(e,t){if(e.bundleId!==`com.android.systemui`)return!1;if(de(e))return!0;let n=new Set,r=e;for(;r?.bundleId===`com.android.systemui`&&!n.has(r.index);){if(h(r.identifier))return!0;n.add(r.index),r=r.parentIndex===void 0?void 0:t.get(r.parentIndex)}return!1}function Uo(e,t){let n=new Map(e.map(e=>[e.index,e])),r=new Set(e.filter(m).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:Wo(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?Fo:{strippedIndexes:o,refs:s}}function Wo(e,t,n){return new Set(e.filter(e=>!n.has(e.index)&&Ho(e,t)).map(e=>e.index))}function Go(e,t){let n=Io(e),r=Uo(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 Ko(e,t){let{strippedIndexes:n}=Go(e,t);return n.size===0?e:e.filter(e=>!n.has(e.index))}function qo(e,t){return Go(e,t).refs}function Jo(e){return Io(e).refs}function Yo(e,t,n){let r=new Set;for(let e of n){let n=t.get(e);if(!n||v(n.type??``)!==`keyboard`)continue;let i=Xo(n,t);i!==void 0&&r.add(i)}for(let i of r){let a=new Set([i]);e.some(e=>Po.has(v(e.type??``))&&!n.has(e.index)&&Zo(e,t,a))&&r.delete(i)}return r}function Xo(e,t){let n=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0;for(;n;){if(v(n.type??``)===`window`)return n.index;n=typeof n.parentIndex==`number`?t.get(n.parentIndex):void 0}}function Zo(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}async function Qo(e,t,n,r){let i=new AbortController,a=[t.signal,e.signal].filter(e=>e!==void 0),o=AbortSignal.any([...a,i.signal]),s=!1,c=setTimeout(()=>{s=!0,i.abort(new DOMException(`Wait deadline exceeded`,`TimeoutError`))},Math.max(0,n));c.unref();try{let e=await r(o);return s&&!a.some(e=>e.aborted)?{timedOut:!0}:(o.throwIfAborted(),{timedOut:!1,value:e})}catch(e){if(s&&!a.some(e=>e.aborted))return{timedOut:!0};throw e}finally{clearTimeout(c)}}function $o(e){let t=e.snapshotQuality?.backend===`private-ax`,n=(t?e.nodes.filter(t=>y(t)||he(t,e.nodes)):e.nodes).map(ts);return n.sort((e,t)=>ns(e).localeCompare(ns(t))),{privateAX:t,nodes:n}}function es(e,t){return!e||e.privateAX!==t.privateAX||e.nodes.length!==t.nodes.length?!1:e.nodes.every((e,n)=>{let r=t.nodes[n];if(!r||e.identity!==r.identity)return!1;if(!e.rect||!r.rect)return e.rect===r.rect;let i=e.rect,a=r.rect;return[`x`,`y`,`width`,`height`].every(e=>Math.abs(Math.round(i[e])-Math.round(a[e]))<=1)})}function ts(e){return{identity:`${e.type??``}#${e.label??``}#${e.identifier??``}`,...e.rect?{rect:{...e.rect}}:{}}}function ns(e){let t=e.rect;return`${e.identity}#${t?`${t.x},${t.y},${t.width},${t.height}`:``}`}const rs=`Settled on a nearly-empty tree — the app may still be loading. Wait for specific content (wait text ...) before interacting.`;async function is(e,t,n){let{quietMs:r,timeoutMs:i}=n,a=V(e),o=a+i,s=!1,c=Le((await e.sessions.get(t.session??`default`))?.snapshot?.snapshotQuality),l=Math.min(300,Math.max(25,r)),u=0,d,f=0,p,m=a;for(;V(e)<o;){let h=await cs(e,t,o-V(e),c);if(!h)return{settled:!1,stalled:!0,waitedMs:V(e)-a,captures:u,nodeCount:f,lastCapture:p};u+=1,p=h;let g=$o(h.snapshot);c??=Le(h.snapshot.snapshotQuality);let _=V(e),ee=os({resetRequested:n.resetBudgetOnPrivateAxRecovery,alreadyReset:s,verdict:h.snapshot.snapshotQuality,nowMs:_,timeoutMs:i,deadlineMs:o});if(ee!==void 0){s=!0,o=ee,m=_,d=g,f=h.snapshot.nodes.length;let t=ss({nowMs:_,quietSinceMs:m,quietMs:r,pollMs:l,deadlineMs:o});if(t<=0)break;await di(e,t);continue}if(!es(d,g))d=g,f=h.snapshot.nodes.length,m=_;else if(u>=2&&_-m>=r)return{settled:!0,stalled:!1,waitedMs:_-a,captures:u,nodeCount:f,lastCapture:p};let te=ss({nowMs:_,quietSinceMs:m,quietMs:r,pollMs:l,deadlineMs:o});if(te<=0)break;await di(e,te)}return{settled:!1,stalled:!1,waitedMs:V(e)-a,captures:u,nodeCount:f,lastCapture:p}}function as(e){return e?.state===`recovered`&&e.backend===`private-ax`&&e.reasonCode!==`deferred`}function os(e){if(!(e.resetRequested!==!0||e.alreadyReset||!as(e.verdict)))return Math.max(e.deadlineMs,e.nowMs+e.timeoutMs)}function ss(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 cs(e,t,n,r){let i=await Qo(e,t,n,async n=>await Oa(e,{...t,signal:n},{updateSession:!1,interactiveOnly:!0,preferredBackend:r}));return i.timedOut?void 0:i.value}const ls=`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.`,us=`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 ds(e,t,n){return await ps(e,t,{...n,baselineNodes:gs(n.resolved),actionPoint:n.resolved.point})}const fs=async(e,t)=>(await ps(e,t,t)).observation;async function ps(e,t,n){let r=n.quietMs??500,i=n.timeoutMs??1e4,a={settled:!1,waitedMs:0,captures:0,quietMs:r,timeoutMs:i};try{return await ms(e,t,n,a,await is(e,t,{quietMs:r,timeoutMs:i,resetBudgetOnPrivateAxRecovery:!0}))}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.`}}}}async function ms(e,t,n,r,i){let a={...r,settled:i.settled,waitedMs:i.waitedMs,captures:i.captures};if(!i.lastCapture)return{observation:{...a,hint:i.stalled?us:ls}};let{stored:o,session:s}=await Ts(e,t,i.lastCapture),c=i.lastCapture.snapshot.nodes;return{observation:{...a,...i.settled&&o?vs(n.baselineNodes,c,n.actionPoint,s?.appBundleId):{},...ws(i,o,c.length)},settledNodes:c}}function hs(e,t){if(!e)return;let n=U(e),r=t!==void 0&&n.digest!==U(t).digest;return{...n,changedFromBefore:r}}function gs(e){return`preActionNodes`in e&&e.preActionNodes?e.preActionNodes:[]}function _s(e,t,n){let r=Oo(Ko(e,n),Ko(t,n),{flatten:!0,withRefs:!0}),i=r.lines.filter(e=>e.kind!==`unchanged`),a=Cs(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=_s(e,t,r);return{diff:i,...ys(i,t,n,r)}}function ys(e,t,n,r){let i=new Set(e.lines.filter(e=>e.kind===`added`&&e.ref).map(e=>e.ref)),a=qo(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)&&!bs(o.get(e),n))?{}:Ss(t,i,r)}function bs(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 xs=new Set([`application`,`window`]);function Ss(e,t,n){let r=qo(e,n),i=e.filter(e=>e.ref&&e.interactionBlocked!==`covered`&&!t.has(e.ref)&&!r.has(e.ref)&&!xs.has(F(e.type??`Element`)));if(i.length===0)return{};let a=i.slice(0,20).map(e=>{let t=F(e.type??`Element`),n=P(e,t);return{ref:e.ref,role:t,...n?{label:n}:{}}});return{tail:a,...i.length>a.length?{tailTruncated:!0}:{}}}function Cs(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 ws(e,t,n){return e.stalled?{hint:us}:e.settled?t?n<5?{hint:rs}:{}:{hint:`Settled on a sparse, unreadable tree — the diff is omitted and its refs/selectors are invalid. Use screenshot as visual truth and coordinate taps; retry snapshot after navigating.`}:{hint:ls}}async function Ts(e,t,n){if(Re(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 Es(e){let t=e.verify===!0;return{verify:t,needsPreActionBaseline:t||e.settle!==void 0,...e.settle===void 0?{}:{settle:e.settle}}}async function Ds(e,t,n,r,i){let a=await Os(e,t,n,i);return As({...r,...a})}async function Os(e,t,n,r){if(r.settle!==void 0){let i=await ds(e,t,{...r.settle,resolved:n}),a=r.verify?hs(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 ks(e,t,n);return i?{evidence:i}:{}}async function ks(e,t,n){let r=`preActionNodes`in n?n.preActionNodes:void 0;try{let n=U((await Z(e,t,!0)).snapshot.nodes),i=r!==void 0&&n.digest!==U(r).digest;return{...n,changedFromBefore:i}}catch{return}}function As(e){let t=e;if(t.targetHittable!==!1||!js(t)||t.hint===void 0)return e;let{hint:n,...r}=t;return r}function js(e){if(e.evidence?.changedFromBefore===!0)return!0;let t=e.settle?.diff?.summary;return!!t&&(t.additions>0||t.removals>0)}function Ms(e,t){let r=e.filter(t=>oe(t,e)).map(e=>e.rect).filter(Ns),i=r.length>0?r:e.map(e=>e.rect).filter(Ns);if(i.length===0)throw new n(`COMMAND_FAILED`,`Cannot infer viewport for ${t}`);let a=Math.min(...i.map(e=>e.x)),o=Math.min(...i.map(e=>e.y)),s=Math.max(...i.map(e=>e.x+e.width)),c=Math.max(...i.map(e=>e.y+e.height));return{x:a,y:o,width:s-a,height:c-o}}function Ns(e){return!!(e&&e.width>0&&e.height>0)}async function Ps(e,t){return await e.backend.resolveGestureViewport?.(B(e,t))||Ms((await Z(e,t,!1)).snapshot.nodes,`gesture`)}const Fs=async(e,t)=>{let r=await X(e,t,{action:`focus`,requireInteractive:!0,pipeline:R.resolvedTarget});if(!e.backend.focus)throw new n(`UNSUPPORTED_OPERATION`,`focus is not supported by this backend`);let i=$(r),a=H(await e.backend.focus(B(e,t),i));return{...r,...a?{backendResult:a}:{},...C(`Focused (${i.x}, ${i.y})`)}},Is=async(e,t)=>{let r=Es(t),i=await X(e,t,{action:`longPress`,requireInteractive:!0,pipeline:R.promotedTarget,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:ui(t.durationMs,`durationMs`,0,12e4),o=$(i),s=H(await e.backend.longPress(B(e,t),o,{durationMs:a}));return await Ds(e,t,i,{...i,...a===void 0?{}:{durationMs:a},...s?{backendResult:s}:{},...C(`Long pressed (${o.x}, ${o.y})`)},r)},Ls=async(e,t)=>{if(!e.backend.performGesture)throw new n(`UNSUPPORTED_OPERATION`,`gesture is not supported by this backend`);await ho(e,t,`drag`);let r=await Ps(e,t),i=await Rs(e,t,`source`),a=await Rs(e,t,`destination`),o=ke({from:$(i),to:$(a),sourceHoldMs:t.gesture.sourceHoldMs,moveMs:t.gesture.moveMs,destinationHoldMs:t.gesture.destinationHoldMs},r),s=H(await e.backend.performGesture(B(e,t),o)),{start:c,end:l}=Ee(o);return{kind:`drag`,durationMs:o.durationMs,pointerCount:1,from:c,to:l,targets:{source:zs(i),destination:zs(a)},recording:Bs(i,a),...s?{backendResult:s}:{},...C(`Dragged ${t.gesture.source} to ${t.gesture.destination}`)}};async function Rs(e,t,n){let r=t.gesture[n];return await X(e,{...t,target:r.startsWith(`@`)?{kind:`ref`,ref:r}:{kind:`selector`,selector:r}},{action:`drag`,requireInteractive:!1,pipeline:R.resolvedTarget,expectedResolvedTarget:t.expectedResolvedTargets?.[n],replayTargetRole:n})}function zs(e){if(e.kind===`point`||!e.resolution)throw new n(`COMMAND_FAILED`,`gesture drag target resolution was not disclosed`);let t=`selectorChain`in e?e.selectorChain:void 0;return{...t?.length?{selectorChain:t}:{},resolution:e.resolution}}function Bs(e,t){let n=Vs(e),r=Vs(t),i=Hs(e),a=Hs(t);return{...n?{sourceSelector:n}:{},...r?{destinationSelector:r}:{},...i?{sourceTarget:i}:{},...a?{destinationTarget:a}:{}}}function Vs(e){return`selectorChain`in e&&e.selectorChain?.length?e.selectorChain.join(` || `):void 0}function Hs(e){if(!(!(`selectorChain`in e)||!e.selectorChain?.length||!e.node||!e.preActionNodes))return{selectorChain:e.selectorChain,node:e.node,preActionNodes:e.preActionNodes}}const Us=async(e,t)=>{if(!e.backend.scroll)throw new n(`UNSUPPORTED_OPERATION`,`scroll is not supported by this backend`);let r=Gs(t.direction),i=Ys(t.amount,`scroll amount`),a=Zs(t.pixels,`scroll pixels`),o=Oe(t.durationMs);je({amount:i,pixels:a},`scroll accepts either amount or pixels, not both`);let s=await Ws(e,t),c=s.kind===`viewport`?{kind:`viewport`}:{kind:`point`,point:$(s)},l=e.backend.scroll,u=async()=>await l(B(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=Ks(s),a=await Xr({edge:n,captureState:async r=>await qs(e,t,n,i,r),scroll:u});d=a.result,f=a.passes}else d=await u(),f=1;let p=H(d),m=De(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(Zr(r.direction,r.edge,f,i,a))}};async function Ws(e,t){let n=t.target??{kind:`viewport`};return n.kind===`viewport`?(await ho(e,t,`scroll`),{kind:`viewport`}):await X(e,{...t,target:n},{action:`scroll`,requireInteractive:!1,pipeline:R.resolvedTarget})}function Gs(e){return e===`bottom`?{direction:`down`,edge:`bottom`}:e===`top`?{direction:`up`,edge:`top`}:{direction:Js(e,`scroll direction`)}}function Ks(e){return e.kind===`viewport`?{}:{point:e.point,nodeIndex:`node`in e?e.node?.index:void 0}}function $(e){if(!e.point)throw new n(`COMMAND_FAILED`,`Interaction target resolved without coordinates`);return e.point}async function qs(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 Yr({edge:r,target:i,scope:a,captureNodes:async n=>{let r=await o(B(e,t),{scope:n});return r.snapshot?.nodes??r.nodes??[]}})}function Js(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 Ys(e,t){return e===void 0?void 0:Xs(e,t)}function Xs(e,t){if(!Number.isFinite(e)||e<=0)throw new n(`INVALID_ARGS`,`${t} must be a positive number`);return e}function Zs(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 Qs=/^e\d+$/;function $s(e){if(e[0]?.startsWith(`@`)){let t=cc(e.slice(1));return{ref:e[0],...t===void 0?{}:{label:t}}}if(Qs.test(e[0]??``))throw new n(`INVALID_ARGS`,`Did you mean "@${e[0]}"? Snapshot refs need the @ prefix.`);let t=le(e);if(t){if(t.rest.length>0)throw new n(`INVALID_ARGS`,ac(e,t));return{selector:t.selectorExpression}}return tc(e)}function ec(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?cc(e.slice(1,2)):void 0},text:n}}if(Qs.test(t??``))throw new n(`INVALID_ARGS`,`Did you mean "@${t}"? Snapshot refs need the @ prefix.`);let r=le(e,{preferTrailingValue:!0});return r?{kind:`selector`,target:{selector:r.selectorExpression},text:r.rest.join(` `)}:{kind:`point`,target:tc(e.slice(0,2)),text:e.slice(2).join(` `)}}function tc(e){let t=e[0]??``,r=te(t);if(r){let i=nc(t)?r.value:[r.value,...e.slice(1)].join(` `).trim();throw new n(`INVALID_ARGS`,rc({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`,ic(e))}function nc(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 rc(e){let{key:t,value:n}=e;return`Unknown selector key "${t}". Supported: ${ne.join(`, `)}. ${re(t)?`Did you mean role=${t} label=${sc(n)}?`:`Did you mean label=${sc(n)}?`}`}function ic(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=>_(e??``))?`${n} Selector values with spaces need quotes, e.g. text="Sign in".`:`${n} To match by visible text, use text=${sc(t)} (or label=/id=/role=), or pass an @ref from snapshot.`}function ac(e,t){return`${`Selector ${t.selectorExpression} is followed by unexpected extra arguments: "${t.rest.join(` `)}".`} Selector values with spaces need quotes, e.g. ${oc(e,t)??`text="Sign in"`}.`}function oc(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)}${sc(a)}`;return[...e.slice(0,n-1),o].join(` `)}function sc(e){return`"${e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`)}"`}function cc(e){return e.join(` `).trim()||void 0}function lc(e,t={}){let n=Nr(process.stderr);if(e===`pass`){let e=t.passFormat??`green`;return n?uc(`✓`,e):`✓`}return e===`fail`?n?uc(`⨯`,`red`):`⨯`:e===`warn`?n?uc(`!`,`yellow`):`!`:n?uc(`-`,`dim`):`-`}function uc(e,t){return L(e,t,{validateStream:!1})}function dc(e){return`${lc(pc(e.status))} ${mc(e)}`}function fc(e){return e.status!==`fail`&&e.status!==`warn`?[]:typeof e.command==`string`?[` run: ${e.command}`]:typeof e.hint==`string`?[` hint: ${e.hint}`]:[]}function pc(e){return e===`pass`?`pass`:e===`fail`?`fail`:e===`warn`?`warn`:`skip`}function mc(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}`}let hc=!1;function gc(){hc=!0}function _c(){let e=hc;return hc=!1,e}function vc(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 yc=[`auto`,`react-native`,`expo`,`repack`];function bc(e){if(e!==void 0){if(yc.includes(e))return e;throw new n(`INVALID_ARGS`,`metro prepare --kind must be auto, react-native, expo, or repack`)}}export{U as $,Xe as $t,Ua as A,it as At,pa as B,nt as Bt,Oo as C,Sn as Ct,ho as D,_t as Dt,Ka as E,tn as Et,Aa as F,ct as Ft,sa as G,$e as Gt,ma as H,w as Ht,Ta as I,ft as It,Y as J,Je as Jt,da as K,Ge as Kt,Ea as L,pt as Lt,Oa as M,dt as Mt,ka as N,mt as Nt,To as O,vt as Ot,Da as P,ut as Pt,W as Q,Ze as Qt,xa as R,st as Rt,qo as S,gn as St,no as T,$t as Tt,oa as U,He as Ut,fa as V,C as Vt,aa as W,et as Wt,K as X,Qe as Xt,Oi as Y,qe as Yt,vi as Z,Ye as Zt,fs as _,F as _t,fc as a,Yr as at,Qo as b,qn as bt,ec as c,R as ct,Fs as d,wr as dt,Ke as en,fi as et,Is as f,dr as ft,Es as g,P as gt,Ds as h,Nr as ht,gc as i,ui as it,Wa as j,lt as jt,X as k,rt as kt,$s as l,L as lt,Us as m,lr as mt,vc as n,V as nt,dc as o,Zr as ot,Ps as p,ur as pt,Xi as q,We as qt,_c as r,B as rt,lc as s,Xr as st,bc as t,H as tt,Ls as u,Tr as ut,rs as v,N as vt,ko as w,hn as wt,Jo as x,bn as xt,is as y,Hn as yt,Sa as z,ht as zt};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e={control:{retryMaxRetries:3},command:{retryTapMaxAttempts:2,targetLookupTimeoutMs:17e3,optionalTargetLookupTimeoutMs:7e3,scrollUntilVisibleTimeoutMs:2e4,waitForAnimationToEndTimeoutMs:15e3,waitForAnimationToEndDifferencePercent:.005,longPressDurationMs:3e3,swipeDurationMs:400,repeatDelayMs:100,scrollUntilVisibleSpeed:40,scrollUntilVisiblePercentage:100,eraseTextMaxCharacters:50},observation:{pollIntervalMs:200,defaultSettleAttempts:10},targetSwipe:{nearEdgeFraction:.1,farEdgeFraction:.9},screenSwipe:{nearEdgeFraction:.1,farEdgeFraction:.9,centerFraction:.5,downStartFraction:.2,upStartFraction:{android:.5,ios:.9}},scrollUntilVisibleSwipe:{nearEdgeFraction:.1,farEdgeFraction:.9}};function t(e){return Math.trunc(1e3*(100-e)/100)+1}const n={assertVisibleTimeoutMs:e.command.targetLookupTimeoutMs,assertNotVisibleTimeoutMs:e.command.targetLookupTimeoutMs,extendedWaitUntilTimeoutMs:e.command.targetLookupTimeoutMs,runFlowConditionTimeoutMs:e.command.optionalTargetLookupTimeoutMs},r=e.observation.pollIntervalMs*e.observation.defaultSettleAttempts,i=[`id`,`text`,`enabled`,`selected`],a=[...i,`label`],o={textKeys:[`id`,`text`,`label`],booleanKeys:[`enabled`,`selected`]};export{e as a,n as i,o as n,r as o,a as r,t as s,i as t};
|