agent-device 0.20.6 → 0.20.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.6.apk → agent-device-android-ime-helper-0.20.8.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.8.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.6.manifest.json → agent-device-android-ime-helper-0.20.8.manifest.json} +4 -4
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.6.apk → agent-device-android-snapshot-helper-0.20.8.apk} +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.8.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.6.manifest.json → agent-device-android-snapshot-helper-0.20.8.manifest.json} +6 -6
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +20 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.h +67 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.m +339 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSelectorMatchPolicy.swift +78 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +31 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +34 -8
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CoordinateTextEntryTests.swift +4 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +36 -28
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +7 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+RecordingTests.swift +4 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SelectorMatchPolicyTests.swift +4 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +2 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +100 -12
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +4 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedTextEntry.swift +57 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +1 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextTyping.swift +18 -3
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/agent-device-client.js +2 -2
- package/dist/src/android-adb.js +1 -1
- package/dist/src/android.js +1 -1
- package/dist/src/app-helpers.js +1 -1
- package/dist/src/app-lifecycle.js +7 -7
- package/dist/src/app-lifecycle2.js +2 -0
- package/dist/src/app-log-files.js +1 -0
- package/dist/src/app-log-reconnect.js +1 -0
- package/dist/src/app-log-runtime.js +4 -0
- package/dist/src/app-resolution.js +2 -1
- package/dist/src/apps.js +5 -5
- package/dist/src/audio-probe.js +1 -1
- package/dist/src/auth-session.js +1 -0
- package/dist/src/auth.js +2 -0
- package/dist/src/boot-diagnostics.js +2 -2
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-grammar.js +1 -0
- package/dist/src/cli-help.js +199 -259
- package/dist/src/cli-output.js +1 -0
- package/dist/src/cli-runner.js +1 -2
- package/dist/src/cli.js +6 -16
- package/dist/src/client-metro.js +1 -1
- package/dist/src/cloud-artifacts.d.ts +2 -137
- package/dist/src/command-schema.js +3 -3
- package/dist/src/connection-runtime.js +1 -0
- package/dist/src/connection.js +5 -0
- package/dist/src/daemon-shutdown-report.js +1 -0
- package/dist/src/daemon.js +2 -0
- package/dist/src/debug-symbols.js +1 -1
- package/dist/src/device-claim-inspection.js +1 -0
- package/dist/src/device-input-state.js +2 -2
- package/dist/src/device-ready.js +1 -0
- package/dist/src/device.js +1 -1
- package/dist/src/device2.js +2 -0
- package/dist/src/dispatch.js +1 -0
- 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/handler-utils.js +1 -0
- package/dist/src/harmonyos.js +1 -0
- package/dist/src/hdc.js +1 -0
- package/dist/src/host-process.js +3 -2
- package/dist/src/ime-lifecycle.js +7 -7
- package/dist/src/index.d.ts +52 -21
- package/dist/src/input-actions.js +4 -4
- package/dist/src/input-actions2.js +1 -1
- package/dist/src/input-actions3.js +1 -0
- package/dist/src/install-artifact.js +1 -5
- package/dist/src/install-artifact2.js +1 -1
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-runtime.js +1 -1
- package/dist/src/interaction-snapshot.js +1 -1
- package/dist/src/interaction-touch-reference-frame.js +1 -1
- package/dist/src/interaction.js +1 -1
- package/dist/src/interactor.js +2 -2
- package/dist/src/interactor2.js +1 -1
- package/dist/src/internal/bin.js +2 -2
- package/dist/src/internal/daemon.js +7 -36
- package/dist/src/inventory.js +5 -0
- package/dist/src/inventory2.js +1 -0
- package/dist/src/inventory3.js +2 -0
- package/dist/src/inventory4.js +1 -0
- package/dist/src/inventory5.js +1 -0
- package/dist/src/inventory6.js +1 -0
- package/dist/src/lease-context.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/limrun-runtime-dependencies.js +1 -0
- package/dist/src/limrun.d.ts +10 -125
- package/dist/src/limrun.js +1 -1
- package/dist/src/linux.js +1 -1
- package/dist/src/logcat.js +1 -1
- package/dist/src/manifest.js +1 -1
- package/dist/src/notifications.js +1 -1
- package/dist/src/output-path.js +1 -0
- package/dist/src/owner-identity.js +1 -0
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/platform-runtime-app-log-android-transport.js +1 -0
- package/dist/src/platform-runtime-app-log-process.js +1 -0
- package/dist/src/platform-runtime-host.js +1 -0
- package/dist/src/platform-runtime-network-web-transport.js +1 -0
- package/dist/src/platform-runtime-operation-host.js +5 -0
- package/dist/src/platform-runtime-screen-recording-android-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-apple-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-apple-runner-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-apple-runner-transport.js +1 -0
- package/dist/src/platform-runtime-screen-recording-apple-simulator-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-apple-transport.js +1 -0
- package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-harmony-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-output-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-web-host.js +1 -0
- package/dist/src/platform-runtime-toolchain-host.js +1 -0
- package/dist/src/platform-runtime.js +1 -0
- package/dist/src/prepare-kind.js +15 -0
- package/dist/src/process-entry.js +1 -0
- package/dist/src/process-lock.js +1 -1
- package/dist/src/provider-webdriver.js +1 -0
- package/dist/src/proxy.js +2 -0
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-runtime.js +1 -0
- package/dist/src/record-trace.js +1 -1
- package/dist/src/recording-telemetry.js +1 -0
- package/dist/src/registry.js +24 -24
- package/dist/src/replay.js +3 -0
- package/dist/src/reporting.js +3 -3
- package/dist/src/runner-disposal.js +1 -1
- package/dist/src/runner-lease.js +1 -1
- package/dist/src/runtime.js +3 -3
- package/dist/src/runtime2.js +4 -0
- package/dist/src/runtime3.js +3 -0
- package/dist/src/runtime4.js +1 -0
- package/dist/src/runtime5.js +1 -0
- package/dist/src/runtime6.js +1 -0
- package/dist/src/runtime7.js +1 -0
- package/dist/src/screenshot-result.js +4 -4
- package/dist/src/screenshot.js +1 -0
- 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 +31 -5
- package/dist/src/sdk-contracts.js +1 -1
- package/dist/src/sdk-device.js +1 -1
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-remote-config.js +1 -1
- package/dist/src/sdk-selectors.d.ts +285 -5
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selector-vocabulary.js +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/server.js +3 -3
- package/dist/src/session-target-evidence.js +1 -1
- package/dist/src/session.js +10 -9
- package/dist/src/shared.js +2 -0
- package/dist/src/shell-quote.js +1 -0
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-runtime.js +1 -0
- package/dist/src/snapshot-session.js +1 -0
- package/dist/src/snapshot2.js +1 -1
- package/dist/src/src.js +1 -1
- package/dist/src/src2.js +2 -0
- package/dist/src/src3.js +1 -0
- package/dist/src/text-surface.js +1 -1
- package/dist/src/timing-safe-equal.js +1 -0
- package/dist/src/tool-provider.js +2 -2
- package/dist/src/update-check.js +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/video.js +23 -0
- package/dist/src/web.js +1 -1
- package/package.json +34 -20
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.6.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.6.apk.sha256 +0 -1
- package/dist/src/app-log-request-scope.js +0 -1
- package/dist/src/context.js +0 -1
- package/dist/src/devices.js +0 -1
- package/dist/src/devices2.js +0 -1
- package/dist/src/devices3.js +0 -1
- package/dist/src/devices4.js +0 -1
- package/dist/src/provider-limrun-runtime.js +0 -1
- package/dist/src/register-builtins.js +0 -1
- package/dist/src/runner-client.js +0 -1
- package/dist/src/runner-provider.js +0 -1
- package/dist/src/screenshot-geometry.js +0 -1
- package/dist/src/viewport-dimension.js +0 -15
- package/skills/agent-device/SKILL.md +0 -45
- package/skills/dogfood/SKILL.md +0 -27
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import{E as e,S as t,_ as n,d as r,f as i,g as a,p as o,u as s}from"./sdk-contracts.js";import{A as c,L as l,N as u,O as d,a as f,at as p,c as m,i as h,k as g,l as _,r as ee,t as te,y as ne,yt as re}from"./screenshot-geometry.js";import{$ as ie,Et as ae,F as oe,G as se,It as ce,J as le,K as ue,Kt as de,Lt as fe,Q as pe,Qt as me,R as he,Rt as ge,St as _e,Vt as ve,Xt as v,Z as ye,Zt as be,cn as xe,en as y,et as b,in as Se,ln as Ce,qt as we,rt as Te,sn as Ee,tn as De,tt as Oe,wn as x,wt as ke,y as Ae,z as je,zt as Me}from"./sdk-batch-runner.js";import{d as Ne}from"./sdk-device.js";import{a as Pe,n as Fe,r as Ie,t as Le}from"./text-surface.js";import{b as Re,w as ze,y as Be}from"./device.js";import Ve from"node:path";import{styleText as He}from"node:util";import{createHash as Ue}from"node:crypto";const We=3e5,Ge=[`leaseId`,`tenantId`,`runId`,`clientId`,`deviceKey`];function Ke(e){return x({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 qe(e){return x({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 Je(e){return x({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 Ye(e){return x({tenant:e.tenantId,runId:e.runId,leaseId:e.leaseId,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId})}function Xe(e){return x({tenantId:e.tenantId??``,runId:e.runId??``,leaseBackend:e.leaseBackend,leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId,ttlMs:e.leaseTtlMs})}function Ze(e){return rt(e)}function Qe(e){let{ttlMs:t,...n}=rt(e);return n}function $e(e,t,n){let r=x({...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,...x({ttlMs:e.leaseTtlMs,backend:e.leaseBackend})};case`lease_heartbeat`:return{...r,...x({leaseId:e.leaseId,ttlMs:e.leaseTtlMs})};case`lease_release`:return{...r,...x({leaseId:e.leaseId})}}}function et(e){let t=x({leaseProvider:e.leaseProvider,deviceKey:e.deviceKey,clientId:e.clientId});return Object.keys(t).length>0?t:void 0}function tt(e){return e.leaseProvider===`proxy`}function nt(e){return tt(e)?Ge.filter(t=>!e[t]):[]}function rt(e){return x({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 it(e){return typeof e?.message==`string`&&e.message.length>0?e.message:null}function at(e){let t=e.appId??e.bundleId??e.packageName;return{session:e.session,appId:t,appBundleId:e.bundleId,package:e.packageName}}function ot(e,t,n){return{deviceId:t,deviceName:n,...Ne(e)?{serial:t}:e===`ios`?{udid:t}:{}}}function st(e,t={}){let n=t.includeSerial??!0,r=ct(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 ct(e){return Ne(e.platform)?e.identifiers.serial??e.id:void 0}function lt(e){return{name:e.name,...e.sessionStateDir?{sessionStateDir:e.sessionStateDir}:{},...e.runnerLogPath?{runnerLogPath:e.runnerLogPath}:{},...st(e.device,{includeSerial:!1}),createdAt:e.createdAt}}function ut(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 dt(e){return e.bundleId??e.package??e.app}function ft(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: ${dt(e)}`)}function pt(e){return e.appName??e.bundleId??e.packageName??e.launchTarget}function mt(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: ${pt(e)}`)}function ht(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?st(e.device):{}},t?`Opened: ${t}`:`Opened`)}function gt(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 _t(e){return{nodes:e.nodes,truncated:e.truncated,...e.appName?{appName:e.appName}:{},...e.appBundleId?{appBundleId:e.appBundleId}:{},...e.visibility?{visibility:e.visibility}:{},...re(vt(e)),...e.unchanged?{unchanged:e.unchanged}:{},...e.snapshotDiagnostics?{snapshotDiagnostics:e.snapshotDiagnostics}:{},...e.refsGeneration===void 0?{}:{refsGeneration:e.refsGeneration}}}function vt(e){return{...e,...e.snapshotQuality?{quality:e.snapshotQuality}:{}}}const yt=[`medium`,`high`],bt=`medium`;function xt(e){return yt.includes(e)}function St(e){let t=typeof e==`number`?e:Ct(e);return t!==void 0&&Number.isInteger(t)&&t>=5&&t<=10?t:void 0}function Ct(e){return typeof e==`string`&&/^\d+$/.test(e)?Number(e):void 0}function wt(e){if(xt(e))return e;let t=St(e);if(t!==void 0)return t<=7?`medium`:`high`}const Tt=[`app`,`device`,`system`];function Et(e){return e===`device`||e===`system`}const Dt=Nt(`public`),Ot=Nt(`internal`),kt=Nt(`local-cli`),At={help:`help`};function jt(){return[...Object.values(Dt),...Object.values(kt)].sort()}function Mt(e){return Object.values(At).includes(e)||Object.values(Ot).includes(e)?!0:jt().includes(e)}function Nt(e){let t={};for(let[n,r]of Ae(e))t[n]=r;return t}const Pt=[`app`,`frontmost-app`,`desktop`,`menubar`],Ft=p(Pt,{normalize:e=>e.trim().toLowerCase(),message:e=>`Invalid surface: ${e}. Use ${Pt.join(`|`)}.`});function It(e){return Ft.parse(e)}const Lt=`--launch-console is supported only for iOS simulator app launches`,Rt=`--launch-console requires a direct app launch and cannot be used with URL opens`,zt=[`path`,`start`,`stop`,`doctor`,`mark`,`clear`],Bt=[`metrics`,`frames`,`memory`,`cpu`,`trace`],Vt=[`sample`,`snapshot`,`start`,`stop`,`report`],Ht=[`profile`],Ut=[`xctrace`,`simpleperf`,`perfetto`,`android-hprof`,`memgraph`],Wt=[`android-hprof`,`memgraph`],Gt=p(Bt),Kt=p(Vt),qt=p(Ht),Jt=p(Ut),Yt=p(Wt),Xt=`perf area must be metrics, frames, memory, cpu, or trace`,Zt=`perf action must be sample, snapshot, start, stop, or report`,Qt=`perf cpu requires profile`,$t=`perf --kind must be xctrace, simpleperf, perfetto, android-hprof, or memgraph`,en=`perf memory snapshot --kind must be android-hprof or memgraph`,tn=Gt.is,nn=Kt.is,rn=qt.is,an=Jt.is,on=Yt.is;function T(e){return e.width>0&&e.height>0}function sn(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 cn(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 ln(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 un(e){let t=(e.type??``).toLowerCase();return t.includes(`scroll`)||t.includes(`list`)||t.includes(`recyclerview`)}function D(e){let t=_(e);if(!t||t!==e.identifier?.trim()||!dn(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 dn(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function fn(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 pn(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 mn=[`button`,`switch`,`checkbox`,`radio`],hn=[`button`,`image`,`textview`,`view`];function gn(e,t,n){for(let r of e){if(t.has(r.index)||!yn(r))continue;let i=bn(pn(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 _n(e,t,n){let r=new Map;for(let i of e){if(t.has(i.index)||!Dn(i))continue;let a=O(D(i));if(!a)continue;let o=r.get(a);if(o&&wn(o,i,t)){let s=Tn(e,o,i,t,n);r.set(a,s);continue}r.set(a,i)}}function vn(e,t){for(let n of e){if(t.has(n.index)||!Sn(n))continue;let r=O(D(n));if(!r)continue;let i=pn(e,n.index).filter(e=>!t.has(e.index)&&Cn(n,e,r));for(let n of i.filter(xn))k(e,n.index,t);let a=i.filter(e=>!xn(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 yn(e){return e.hittable===!0&&!E(e)&&!!(e.rect&&T(e.rect))&&D(e).trim().length===0}function bn(e,t,n){let r=[],i=[],a=new Set;for(let o of e){if(n.has(o.index)||!xn(o)||!sn(o.rect,t.rect))continue;let e=D(o).trim().replace(/\s+/g,` `),s=O(e);i.push(o.index),!(!e||!s||a.has(s))&&(a.add(s),r.push(e))}return{label:r.join(`, `),removableIndexes:i}}function xn(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 Sn(e){return e.hittable===!0&&!E(e)&&!!(e.rect&&T(e.rect))&&!!O(D(e))}function Cn(e,t,n){if(!Dn(t)||!sn(t.rect,e.rect))return!1;let r=O(D(t));return!!(r&&n!==r&&n.includes(r))}function wn(e,t,n){return!n.has(e.index)&&cn(e.rect,t.rect)&&(Mn(e,t)||jn(e,t))}function Tn(e,t,n,r,i){let a=On(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:En(c.presentationHints,l,s)}),k(e,o.index,r),i.get(a.index)??a}function En(e,t,n){return[...new Set([...Array.isArray(e)?e:[],...Array.isArray(t)?t:[],...n?[n]:[]])]}function Dn(e){if(!e.rect||!T(e.rect)||ln(e)||E(e))return!1;let t=(e.type??``).toLowerCase();return t===`text`||An(t,hn)}function On(e,t){let n=kn(e);return kn(t)>n?t:e}function kn(e){let t=(e.type??``).toLowerCase(),n=0;return An(t,mn)?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 An(e,t){return t.some(t=>e.includes(t))}function jn(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:On(n,r).index===n.index}function Mn(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 Nn(e,t,n){if(n.raw||!Pn(e))return{nodes:t,filteredCount:0};let r=Fn(t);return{nodes:r,filteredCount:t.length-r.length}}function Pn(e){let t=e.androidSnapshot;return!t||typeof t!=`object`?!1:t.backend===`android-helper`}function Fn(e){if(e.length===0)return e;let t=new Set,n=new Map,r=new Map(e.map(e=>[e.index,e]));return In(e,t),Ln(e,r,t,n),gn(e,t,n),vn(e,t),_n(e,t,n),e.filter(e=>!t.has(e.index)).map(e=>n.get(e.index)??e)}function In(e,t){for(let n of e)!n.rect||T(n.rect)||ln(n)||k(e,n.index,t)}function Ln(e,t,n,r){for(let i of e){if(n.has(i.index)||i.rect||ln(i))continue;let a=fn(i,t,un);a&&zn(r,a,Rn(i,e)),k(e,i.index,n)}}function Rn(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 zn(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 Bn(e){return[...Vn(e),...Hn(e)]}function Vn(e){let t=Un(e?.candidates);if(t.length===0)return[];let n=(typeof e?.matches==`number`?e.matches:t.length)-t.length;return[`Candidates:`,...t.map(e=>` ${e}`),...n>0?[` +${n} more`]:[]]}function Hn(e){let t=Wn(e?.devices);return t.length===0?[]:[`Devices:`,...t.map(e=>` ${e.id} ${e.name}`)]}function Un(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Wn(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`&&typeof e.name==`string`):[]}function Gn(e){let t=e.trim().replace(/\s+/g,` `).toLowerCase();return!t||Kn(t)?null:t}function Kn(e){return/\S+@\S+\.\S+/.test(e)}function qn(e){if(e.length<20)return!1;let t=new Map;for(let n of e){let e=(n.type??``).toLowerCase(),r=Gn(_(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||!Jn(e)||(n+=e.length);return n>=8}function Jn(e){for(let t=0;t<e.length;t+=1)for(let n=t+1;n<e.length;n+=1)if(Yn(e[t]?.rect,e[n]?.rect))return!0;return!1}function Yn(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 Xn={digest:8*1024,default:24*1024,full:64*1024};function Zn(e){return e===`digest`||e===`full`?e:`default`}function Qn(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(t,n=256){return Qn(e(t),n)}function $n(e,t){let n=e;for(let e of t)e.value&&(n=n.split(e.value).join(`<var:${e.name}>`));return n}function er(e){return(t,n)=>A($n(t,e),n)}function tr(e,t){return e.state!==`available`||e.refs.length<=t?e:{...e,refs:e.refs.slice(0,t),truncated:!0}}function nr(e,t){let n=Zn(t),r=n===`digest`?8:20,i=tr(e.screen,r),a=n===`digest`?[]:e.suggestions.slice(0,5);return{...e,screen:i,suggestions:a}}function rr(e){return Buffer.byteLength(JSON.stringify(e),`utf8`)}function ir(e){let{divergence:t,level:n,writeOverflowArtifact:r}=e,i=Zn(n),a=Xn[i],o=nr(t,n),s=rr(o);if(s<=a)return o;let c=s-a,l=r(nr(t,`full`)),u=ar(o);return`artifactPath`in l?{...u,overflow:{omittedBytes:c,artifactPath:l.artifactPath}}:{...u,artifactUnavailable:!0}}function ar(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 or(e){let t=e?.divergence;if(!t||typeof t!=`object`)return null;let n=t,r=[...vr(n.step),...mr(n.kind,n.targetBinding),...sr(n.repairHint,n.resume),...yr(n.screen),...Cr(n.suggestions,n.suggestionCount),...Tr(n.overflow,n.artifactUnavailable)];return r.length>0?r.join(`
|
|
2
|
-
`):null}function sr(e,t){if(typeof e!=`string`)return[];let n=ur(e,t);return[`Repair hint: ${e}${n?` — ${n}`:``}`]}function cr(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 lr(e){return e?.repairSessionHeld===!0}function ur(e,t){let n=dr(e,cr(t));if(n!==void 0)return lr(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 dr(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). ${pr(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. ${pr(t)}`;case`caution`:return fr({lead:`something already matches the recorded selector; a blind re-press may repeat the mistake.`,guidance:t});case`manual`:return fr({lead:`no safe automated repair could be proven; inspect the screen and repair by hand.`,guidance:t});default:return}}function fr(e){let{lead:t,guidance:n}=e;if(!n?.allowed)return`${t} ${pr(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 pr(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 mr(e,t){if(typeof e!=`string`||e===`action-failure`)return[];let n=t;return n?[hr(e,n.matchCount),...gr(n.mismatches),..._r(n.candidates)]:[]}function hr(e,t){return`Target binding: ${e}${typeof t==`number`?` (matchCount ${t})`:``} — recorded target evidence did not verify.`}function gr(e){return!Array.isArray(e)||e.length===0?[]:[` mismatches: ${e.slice(0,5).join(`; `)}`]}function _r(e){return!Array.isArray(e)||e.length===0?[]:[` ${e.length} candidate(s) shared the recorded identity:`,...e.slice(0,5).map(e=>` ${Sr(e)}`)]}function vr(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 yr(e){let t=e;return t?.state===`available`&&Array.isArray(t.refs)?br(t.refs,t.refsGeneration):t?.state===`unavailable`?[xr(t)]:[]}function br(e,t){let n=e.slice(0,8).map(Sr),r=e.length-n.length;return[`Screen: ${e.length} actionable ref(s) captured (refsGeneration ${t}).`,...n,...r>0?[` ... ${r} more`]:[]]}function xr(e){let t=typeof e.hint==`string`&&e.hint.length>0?` ${e.hint}`:``;return`Screen: unavailable (${String(e.reason??`unknown`)}).${t}`}function Sr(e){let t=e,n=typeof t.label==`string`?` "${t.label}"`:``;return` @${String(t.ref)} [${String(t.role)}]${n}`}function Cr(e,t){return Array.isArray(e)&&e.length>0?[`Suggestions:`,...e.slice(0,5).map(wr)]:typeof t==`number`&&t>0?[`Suggestions: ${t} available (omitted at this response level; rerun with --json for the full report).`]:[]}function wr(e){let t=e,n=typeof t.label==`string`?` "${t.label}"`:``;return` - [${String(t.basis)}]${n} ${String(t.selector)}`}function Tr(e,t){return e&&typeof e==`object`?[`Full report written to ${String(e.artifactPath)}.`]:t===!0?[`Full report exceeded the response budget and the overflow artifact could not be written.`]:[]}const Er={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 Dr(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=P(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:M(i,c,!1,o,t)})}return r}function M(e,t,n,r,i={}){let a=r??P(e.type??`Element`),o=Fe(e,a),s=Mr(e,a,i,o),c=` `.repeat(t),l=e.ref?`@${e.ref}`:``,u=Nr(e,a,i,o);!s&&(e.inheritsLabel===!0||e.inheritsIdentifier===!0)&&u.push(`same label as parent`);let d=u.map(e=>` [${e}]`).join(``),f=s?` "${s}"`:``;return n?`${c}${l} [${a}]${d}`.trimEnd():`${c}${l} [${a}]${f}${d}`.trimEnd()}function N(e,t){let n=e.label?.trim();if(n&&Ar(t,n))return``;let r=e.value?.trim();if(kr(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||jr(i)&&(t===`group`||t===`image`||t===`list`||t===`collection`)?``:i}function P(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`:Or(n)||n||`element`}function Or(e){return Object.prototype.hasOwnProperty.call(Er,e)?Er[e]:void 0}function kr(e){return e===`text-field`||e===`text-view`||e===`search`}function Ar(e,t){return e!==`scroll-area`&&e!==`list`&&e!==`collection`&&e!==`table`?!1:m(t)}function jr(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function Mr(e,t,n,r){return!n.summarizeTextSurfaces||!r.shouldSummarize?N(e,t):Pr(e,t,r.text)||N(e,t)}function Nr(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`),kr(t)&&i.push(`editable`),Fr(e,t)&&i.push(`scrollable`),!r.shouldSummarize)?Lr(i):(i.push(`preview:"${Ir(Le(r.text))}"`),i.push(`truncated`),Lr(i))}function Pr(e,t,n){let r=Pe(e.label);if(r&&r!==n)return r;let i=Pe(e.identifier);if(i&&!jr(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 Fr(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 Ir(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function Lr(e){return[...new Set(e)]}function Rr(e){process.stdout.write(`${JSON.stringify(e,null,2)}\n`)}function zr(e,r={}){let i=e instanceof n?t(e):e;process.stderr.write(`Error (${i.code}): ${i.message}\n`),i.hint&&process.stderr.write(`Hint: ${i.hint}\n`);let a=Bn(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=or(i.details);o&&process.stderr.write(`${o}\n`),r.showDetails&&i.details&&process.stderr.write(`${JSON.stringify(i.details,null,2)}\n`)}function Br(e,t={}){let n=e.nodes,r=Array.isArray(n)?n:[],o=a(i(e.backend)?e.backend:void 0),s=Nn(e,r,t),c=Wr(e),l=li(e,r,t,s),u=l.length>0?`${l.join(`
|
|
4
|
-
`)}\n`:``,d=t.raw?null:Vr(e);if(d)return`${c}${u}${Hr(d)}\n`;let f=t.raw||!o?null:ee(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}${Kr(r)}\n`:t.flatten?`${c}${g}\n${u}${qr(m)}${Yr(f)}\n`:`${c}${g}\n${u}${Jr(m)}${Yr(f)}\n`}function Vr(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 Hr(e){let t=Ur(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 Ur(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 Wr(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 Kr(e){return e.map(e=>JSON.stringify(e)).join(`
|
|
9
|
-
`)}function qr(e){return _i(e).join(`
|
|
10
|
-
`)}function Jr(e){return mi(Dr(e,{summarizeTextSurfaces:!0})).join(`
|
|
11
|
-
`)}function Yr(e){return e&&e.summaryLines.length>0?`\n${e.summaryLines.join(`
|
|
12
|
-
`)}`:``}function Xr(e,t,n,r,i=0){let a=Zr(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:Qr([...a?.reasons??[],`offscreen-nodes`])}:a||(s?{partial:!0,visibleNodeCount:n,totalNodeCount:n,reasons:[]}:null)}function Zr(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 Qr(e){return[...new Set(e)]}function $r(e){let t=e.baselineInitialized===!0,n=e.summary??{},r=F(n.additions),i=F(n.removals),a=F(n.unchanged),o=I(),s=pi(e),c=s.length>0?`${s.join(`
|
|
13
|
-
`)}\n`:``;if(t)return`${c}Baseline initialized (${a} lines).\n`;let l=si(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 ei(e){let t=I(),n=e.match===!0,r=e.dimensionMismatch,i=[];return i.push(...ti(e,t)),i.push(...ni(e,n,t)),!n&&!r&&(i.push(...ri(e,t)),i.push(...ii(e,t))),`${i.join(`
|
|
15
|
-
`)}\n`}function ti(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=F(e.differentPixels),a=F(e.mismatchPercentage),o=`${a===0&&i>0?`<0.01`:String(a)}% pixels differ`;return[`${r} ${t?L(o,`red`):o}`]}function ni(e,t,n){if(t)return[];let r=[];if(e.diffPath){let t=oi(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=oi(e.currentOverlayPath),i=n?L(`Current overlay:`,`dim`):`Current overlay:`,a=n?L(t,`green`):t,o=F(e.currentOverlayRefCount),s=o>0?` (${o} refs)`:``;r.push(` ${i} ${a}${s}`)}return r}function ri(e,t){let n=F(e.differentPixels),r=F(e.totalPixels);return[` ${t?L(String(n),`red`):String(n)} different / ${r} total pixels`]}function ii(e,t){let n=Array.isArray(e.regions)?e.regions:[];if(n.length===0)return[];let r=[` ${ci(`Changed regions:`,t)}`];for(let e of n.slice(0,5))r.push(...ai(e));return r}function ai(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 oi(e){let t=process.cwd(),n=Ve.relative(t,e);return n===``||!n.startsWith(`..`)&&!Ve.isAbsolute(n)?n===``?`.`:`.${Ve.sep}${n}`:e}function F(e){return typeof e==`number`&&Number.isFinite(e)?e:0}function si(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 I(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 He(t,e,n)}function ci(e,t){return t?L(e,`dim`):e}function li(e,t,n,r={nodes:t,filteredCount:0}){let i=pi(e);if(ui(e)){let e=fi(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&&qn(a)&&i.push(`Warning: possible repeated nav subtree detected.`),i}function ui(e){return!e.snapshotQuality&&!di(e)}function di(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 fi(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 pi(e){let t=e.warnings;return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.length>0):[]}function mi(e){let t=[],n=[],r=new Map(e.map(e=>[e.node.index,e.node])),i=e=>{for(;n.length>0&&(!e||hi(e,n[n.length-1],r));)t.push(...vi(n.pop(),`below`))};for(let r of e)i(r),t.push(r.text),t.push(...vi(r,`above`)),r.node.hiddenContentBelow&&n.push(r);return i(),t}function hi(e,t,n){return gi(e.node,t.node,n)?!1:e.depth<=t.depth}function gi(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 _i(e){return Dr(e,{summarizeTextSurfaces:!0}).flatMap(e=>[M(e.node,0,!1,e.type,{summarizeTextSurfaces:!0}),...vi({...e,depth:0})])}function vi(e,t){let n=yi(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 yi(e){return e===`scroll-area`||e===`list`||e===`collection`||e===`table`?e:null}function bi(e,t,n={}){let r=Ti(e);if(r.length===0)return{canScroll:!1,emptySnapshot:!0};let i=f(r),a=Ei(r,i,t,n);return a?{canScroll:Oi(a,i.get(a.index),t),emptySnapshot:!1,scope:ki(a,r)}:{canScroll:!1,emptySnapshot:!1}}async function xi(e){let{edge:t,target:n={},scope:r,captureNodes:i}=e;try{let e=bi(await i(r),t,n);return r&&e.emptySnapshot?await xi({edge:t,target:n,captureNodes:i}):e}catch(e){throw wi(t,r,e)}}async function Si(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 Ci(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 wi(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 Ti(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=>Ce(e)&&Fi(e.rect));if(a.length===0)return null;let o=Di(r.nodeIndex,i);if(o)return o;let s=r.point;if(s){let e=a.filter(e=>e.rect&&Pi(e.rect,s)).sort(Mi);if(e.length>0)return e.find(e=>Oi(e,t.get(e.index),n))??e[0]??null}let c=a.filter(e=>Oi(e,t.get(e.index),n)).sort(Ni);return c.length>0?c[0]??null:a.filter(t=>de(t,e)).sort(Ni)[0]??a.sort(Ni)[0]??null}function Di(e,t){if(e===void 0)return null;let n=t.get(e);for(;n;){if(Ce(n)&&Fi(n.rect))return n;n=n.parentIndex===void 0?void 0:t.get(n.parentIndex)}return null}function Oi(e,t,n){return n===`bottom`?e.hiddenContentBelow===!0||t?.hiddenContentBelow===!0:e.hiddenContentAbove===!0||t?.hiddenContentAbove===!0}function ki(e,t){return[e.identifier,e.label].filter(e=>typeof e==`string`).map(e=>e.trim()).find(n=>ji(n)&&Ai(n,e,t))}function Ai(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 ji(e){return e.length>0&&e.length<=80&&!/^(true|false)$/i.test(e)&&!/^\d+$/.test(e)&&!/^\d+%$/.test(e)}function Mi(e,t){return R(e.rect)-R(t.rect)}function Ni(e,t){return R(t.rect)-R(e.rect)}function R(e){return e?e.width*e.height:0}function Pi(e,t){return t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height}function Fi(e){return!!(e&&e.width>0&&e.height>0)}function Ii(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 z(e,t){return{session:t.session,requestId:t.requestId,signal:t.signal??e.signal,metadata:t.metadata}}function B(e){return e.clock?.now()??Date.now()}async function Li(e,t){e.clock?await e.clock.sleep(t):await new Promise(e=>setTimeout(e,t))}function Ri(e,t){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,e=>n(t,e)]))}function V(e){return e&&typeof e==`object`?e:void 0}function zi(e){let t=Buffer.alloc(16);for(let n of e)Vi(t,Bi(n));return{digest:`ax1:${Ue(`sha256`).update(t).update(`\0`).update(String(e.length)).digest(`hex`).slice(0,16)}`,nodeCount:e.length}}function Bi(e){return Ue(`sha256`).update(e.type??``).update(`\0`).update(e.label??``).update(`\0`).update(e.identifier??``).digest().subarray(0,16)}function Vi(e,t){for(let n=0;n<e.length;n+=1)e[n]=(e[n]??0)^(t[n]??0)}function H(e){let{digest:t,nodeCount:n}=zi(e),r=e.reduce((e,t)=>t.hittable===!1?e:e+1,0),i=Hi(e);return{digest:t,nodeCount:n,interactiveNodeCount:r,...i?{foregroundApp:i}:{}}}function Hi(e){for(let t of e)if(t.bundleId)return t.bundleId;for(let t of e)if(t.appName)return t.appName}const Ui=[`x`,`y`,`width`,`height`];function U(e){let t=W(e);if(!t)return null;let n=s(t);return!Number.isFinite(n.x)||!Number.isFinite(n.y)?null:n}function W(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 G(e,t){return!e||!t?!1:Ui.every(n=>Math.abs(e[n]-t[n])<=.5)}function Wi(e){return{x:Gi(e.x,e.width),y:Gi(e.y,e.height)}}function Gi(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 Ki(e){let t=new Map;for(let n of e)t.set(n.index,n);return t}function qi(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=b(e);r.push({role:n.role,...n.label===void 0?{}:{label:n.label}}),a=e}return{chain:r,broken:!1}}function Ji(e,t,n,r){return e.filter(e=>{if(!ie(b(e),n))return!1;let i=qi(e,t,Math.max(r.length,1));return!i.broken&&pe(i.chain,r)})}function Yi(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 K(e,t){let n=[e.label,e.value,e.identifier].map(e=>typeof e==`string`?e.trim():``).find(e=>e&&e.length>0);return n&&q(n)?n:Xi(e,t)??(n&&q(n)?n:void 0)}function q(e){let t=e.trim();return!(!t||/^(true|false)$/i.test(t)||/^\d+$/.test(t))}function Xi(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=[e.label,e.value,e.identifier].map(e=>typeof e==`string`?e.trim():``).find(e=>e&&e.length>0);if(!t||!q(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 Zi(e){let t=[],n=[];for(let r of e){let e=r.depth??0;for(;t.length>0&&e<=t[t.length-1];)t.pop();let i=y(r.type??``),a=[r.label,r.value,r.identifier].map(e=>typeof e==`string`?e.trim():``).find(e=>e&&e.length>0),o=a?q(a):!1;if((i===`group`||i===`ioscontentgroup`)&&!o){t.push(e);continue}let s=Math.max(0,e-t.length);n.push({...r,depth:s})}return n}function Qi(e,t){return t.hittable?t:$i(e,t,e=>e.hittable===!0)}function $i(e,t,n){return xe(e,t,Ee(e),e=>n(e)?e:null)}function ea(e){return Ie(e)}const ta=[`tabbar`,`toolbar`,`navigationbar`,`bottomnavigation`,`bottomnavigationview`,`sheet`,`dialog`,`alert`,`popover`,`menu`],na=[`tabbar`,`toolbar`,`navigationbar`],ra=[`button`,`link`,`menuitem`,`tabitem`,`textfield`,`searchfield`,`edittext`,`checkbox`,`radio`,`switch`,`cell`];function ia(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)=>ua(e,n,t)?[r]:[]),coverCache:new Map},i=[];for(let[n,a]of e.entries())la(a)&&aa(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:ba(n.presentationHints)}}return a}function J(e){return e.interactionBlocked!==void 0}function aa(e,t,n,r){let i=e.coverCache.get(t);if(i!==void 0)return i;e.coverCache.set(t,null);let a=Y(n.rect);if(!a)return oa(e,t,null);let o=s(a);for(let i of e.overlayPositions){if(i<=t)continue;let s=e.nodes[i];if(s&&sa(e,i,n,a,o,r))return oa(e,t,s)}return oa(e,t,null)}function oa(e,t,n){return e.coverCache.set(t,n),n}function sa(e,t,n,r,i,a){if(!e.nodes[t])return!1;let o=ca(e,t,n,r,a);return!!(o&&De(o,i.x,i.y))}function ca(e,t,n,r,i){let a=e.nodes[t];if(!a||!ua(a,e.byIndex,i)||va(n,a,e.byIndex))return null;let o=Y(a.rect);return!o||G(r,o)||aa(e,t,a,i)?null:o}function la(e){return Y(e.rect)?e.hittable===!0||ha(e)?!0:!!(e.label?.trim()||e.value?.trim()||e.identifier?.trim()):!1}function ua(e,t,n){return!Y(e.rect)||v(e)||da(e,t)?!1:ga(e,ta)||fa(e,t,n)}function da(e,t){if(!ga(e,na))return!1;let n=Y(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(v(r)){let e=Y(r.rect);return!!(e&&G(n,e))}i.add(r.index),r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0}return!1}function fa(e,t,n){return n.isAdditionalOverlayNode?.(e)===!0?!pa(e,t,n):!1}function pa(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(ma(r,n))return!0;i.add(r.index),r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0}return!1}function ma(e,t){return t.isAdditionalOverlayNode?.(e)===!0&&Y(e.rect)!==null&&!v(e)}function ha(e){return ga(e,ra)}function ga(e,t){let n=_a(e);return t.some(e=>n.includes(e))}function _a(e){return[e.type,e.role,e.subrole].map(e=>y(e??``)).join(` `)}function va(e,t,n){return ya(e,t,n)||ya(t,e,n)}function ya(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 Y(e){let t=W(e);return t&&t.width>0&&t.height>0?t:null}function ba(e){return Array.from(new Set([...e??[],`covered`]))}const xa=[`button`,`link`,`menuitem`,`tabitem`,`textfield`,`searchfield`,`securetextfield`,`checkbox`,`radio`,`switch`,`cell`];function Sa(e,t){return Ca(e,t).node}function Ca(e,t){if(J(t))return{node:t,reason:`covered`};let n=wa(e,t);if(n?.rect&&U(n.rect))return{node:n,reason:`same-rect-descendant`};if(Ta(t)&&t.rect&&U(t.rect))return{node:t,reason:`semantic-target`};let r=Qi(e,t);return r?.rect&&!J(r)&&U(r.rect)?Da(t,r,e)?{node:t,reason:`overly-broad-ancestor`}:{node:r,reason:`hittable-ancestor`}:{node:t,reason:`original`}}function wa(e,t){let n=W(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||J(e))return!1;let t=W(e.rect);return t?G(t,n):!1});if(t.length!==1)break;r=t[0]}return r===t?null:r}function Ta(e){return[e.type,e.role,e.subrole].map(e=>y(e??``)).some(Ea)}function Ea(e){return e===`tab`||xa.some(t=>e.includes(t))}function Da(e,t,n){let r=W(e.rect),i=W(t.rect);if(!r||!i)return!1;if(Oa(t)&&!G(r,i))return!0;let a=ka(n,r);return!a||!Aa(i,a)?!1:!G(r,i)}function Oa(e){let t=y(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 ka(e,t){let n=s(t),r=e.filter(v).map(e=>W(e.rect)).filter(e=>e!==null);if(r.length===0)return null;let i=r.filter(e=>De(e,n.x,n.y));return Se(i.length>0?i:r)}function Aa(e,t){let n=te(e,t),r=e.width*e.height,i=t.width*t.height;if(n<=0||r<=0||i<=0)return!1;let a=n/i,o=n/r;return a>=.9&&o>=.8}function ja(e){return e.hittable===!0||Ta(e)}function Ma(e,t){let n=le(b(e),t);return n.id!==void 0||n.label!==void 0?!1:ue(e.value)===null}function Na(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 Pa(e,t){let n=Ki(t);return t.filter(t=>t.index!==e.index&&Na(t,e,n)).sort((e,t)=>e.index-t.index)}function Fa(e,t){let n=U(e.rect);return!n||!t.rect?!1:De(t.rect,n.x,n.y)}function Ia(e,t){if(!Ma(e,t))return e;let n=Pa(e,t);if(n.some(ja))return e;let r=n.find(e=>b(e).label!==void 0);return!r||!Fa(r,e)?e:r}const La=new Set([`healthy`,`recovered`,`sparse`]),Ra=new Set([`tree`,`queries`,`private-ax`]),za=new Set([`ax-rejected`,`sparse-tree`,`budget`,`no-nodes`,`capture-failed`,`deferred`]);function Ba(e){if(!e||typeof e!=`object`)return;let t=e;if(!(typeof t.state!=`string`||!La.has(t.state))&&!(typeof t.backend!=`string`||!Ra.has(t.backend)))return{state:t.state,backend:t.backend,reason:typeof t.reason==`string`?t.reason:void 0,reasonCode:typeof t.reasonCode==`string`&&za.has(t.reasonCode)?t.reasonCode:void 0,effectiveDepth:typeof t.effectiveDepth==`number`?t.effectiveDepth:void 0,collapsedLeafIndexes:Array.isArray(t.collapsedLeafIndexes)?t.collapsedLeafIndexes.filter(e=>typeof e==`number`):void 0}}function Va(e){return e?.state===`sparse`}function Ha(e,t){return[...Wa(e),...Ga(e),...Ka(e,t)]}function Ua(e){return`Detected an overly complex or slow accessibility tree. Fell back to the ${e} snapshot backend. It is OK to continue; use --json to inspect snapshotQuality.reason if you need recovery details.`}function Wa(e){return e.state===`recovered`?e.reasonCode===`deferred`?[]:[Ua(e.backend)]:e.state===`sparse`?[`No snapshot backend could read this screen`+(e.reason?` (${e.reason})`:``)+`. Use screenshot as visual truth and coordinate taps; retry snapshot after navigating.`]:[]}function Ga(e){return e.effectiveDepth===void 0?[]:[`Some deeper accessibility nodes were omitted; this tree is capped at depth ${e.effectiveDepth}. Re-run with --depth ${e.effectiveDepth} --scope <container> only if you need deeper content.`]}function Ka(e,t){let n=[];for(let r of e.collapsedLeafIndexes??[]){let e=t.find(e=>e.index===r);if(!e)continue;let i=e.identifier?` (${e.identifier})`:``;n.push(`@${e.ref} [${e.type??`element`}]${i} merges many labels into a single accessibility element. The app likely marks a container as accessible, which hides every descendant from assistive tech and automation — the children cannot be addressed individually. Fix the app's accessibility (mark the rows, not the container); until then use screenshot as visual truth and coordinate taps.`)}return n}const qa=new Set([`empty-helper-output`,`system-window-only`,`content-poor-app-window`]);function Ja(e){if(!e||typeof e!=`object`)return!1;let t=e.details?.androidSnapshotHelperFailureReason;return typeof t==`string`&&qa.has(t)}function Ya(e){return e===`text`||e===`label`||e===`any`}function Xa(e,t,n,r){if(!(r||e===`web`))return Ya(t)?n:void 0}function Za(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 Qa(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 $a(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(z(e,t),{interactiveOnly:r.interactiveOnly??!1,depth:t.depth,scope:r.scope??t.scope,raw:t.raw,includeRects:r.includeRects,...r.includeHiddenContentHints===void 0?{}:{includeHiddenContentHints:r.includeHiddenContentHints}}),c=s.snapshot??{nodes:s.nodes??[],truncated:s.truncated,backend:s.backend,...s.quality?{snapshotQuality:s.quality}:{},createdAt:B(e)};return(t.signal??e.signal)?.throwIfAborted(),r.updateSession&&o&&!Va(c.snapshotQuality)&&await e.sessions.set({...o,snapshot:c}),{sessionName:a,session:o,snapshot:c}}async function eo(e,t,n){if(e.backend.readText){let r=await e.backend.readText(z(e,{session:t.sessionName}),n);if(r.text.trim())return r.text}return Ie(n)}function to(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?Yi(e,i.fallbackLabel):null);if(!s)throw new n(`COMMAND_FAILED`,i.notFoundMessage);return{ref:a,node:s}}function no(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`)+`…`}const ro=`replay_target_guard_mismatch`,io=ne.landmarkIdentityMismatch;function ao(e,t,r,i,a){if(!r)return;let o=b(e),s=Oe(e,t);if(!(ye(o,r.identity)&&Te(s,r.structural)))throw new n(`COMMAND_FAILED`,`${i} resolved to a different element than replay verification isolated; the action was not sent`,{reason:ro,observed:o,observedStructural:s,expected:r.identity,expectedStructural:r.structural,...a?{targetRole:a}:{}})}async function X(e,t,n){return await Eo(e,t,n.action),t.target.kind===`point`?await so(e,t,t.target,n):t.target.kind===`ref`?await lo(e,t,t.target,n):await uo(e,t,t.target,n)}async function oo(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=me(i.snapshot.nodes,a);if(!o)return;let s={x:n.x,y:n.y};if(!De(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 so(e,t,n,r){let i=await oo(e,t,n);if(!r.captureEvidenceBaseline)return{kind:`point`,point:{x:n.x,y:n.y},...i?{warning:i}:{}};let a=await co(e,t);return{kind:`point`,point:{x:n.x,y:n.y},...a?{preActionNodes:a}:{},...i?{warning:i}:{}}}async function co(e,t){try{return(await Z(e,t,!0)).snapshot.nodes}catch{return}}async function lo(e,t,n,r){let i=await Oo(e,t,n),a=i.resolved;fo(a.node,i.snapshot.nodes,r);let o=r.promoteToHittableAncestor?So(i.snapshot.nodes,a.node,{action:r.action,label:`Ref ${n.ref}`}):a.node;Co(o,`Ref ${n.ref}`,r.action);let s=await Po(e,t,o,i.snapshot.nodes,n.ref,r.action);return{kind:`ref`,point:jo(s,`Ref ${n.ref} not found or has invalid bounds`),target:{kind:`ref`,ref:`@${a.ref}`},...vo(e,s,i.snapshot.nodes,r.action,a.resolution)}}async function uo(e,t,r,i){let a=r.selector,o=await Z(e,t,i.requireInteractive),s=oe(xo(o.snapshot.nodes),a,{platform:e.backend.platform,...je(he.act)});if((!s||!s.node.rect)&&i.requireInteractive&&(o=await Z(e,t,!1),s=oe(xo(o.snapshot.nodes),a,{platform:e.backend.platform,...je(he.act)})),!s||!s.node.rect){let t=oe(o.snapshot.nodes,a,{platform:e.backend.platform,...je(he.actCoveredDiagnosis)});throw t?.node&&J(t.node)?wo({label:`Selector ${t.selector}`,node:t.node,action:i.action,selector:t.selector}):new n(`COMMAND_FAILED`,ke(a,s?.diagnostics??[],{unique:!0}),{hint:ae(s?.diagnostics??[])})}fo(s.node,o.snapshot.nodes,i);let c=i.promoteToHittableAncestor?So(o.snapshot.nodes,s.node,{action:i.action,label:`Selector ${s.selector}`}):s.node;Co(c,`Selector ${s.selector}`,i.action);let l=await No(e,t,c,o.snapshot.nodes,s.selector,i.action);return{kind:`selector`,point:jo(l,`Selector ${s.selector} resolved to invalid bounds`),target:{kind:`selector`,selector:s.selector},...vo(e,l,o.snapshot.nodes,i.action,go(s,o.snapshot.nodes))}}function fo(e,t,n){ao(e,t,n.expectedResolvedTarget,n.action,n.replayTargetRole)}const po={source:`ref`,phase:`pre-action`,kind:`exact`},mo={source:`ref`,phase:`pre-action`,kind:`label-fallback`},ho={source:`runtime`,phase:`pre-action`,kind:`unique`};function go(e,t){return e.disambiguation?{source:`runtime`,phase:`pre-action`,kind:`disambiguated`,matchCount:e.disambiguation.matchCount,winnerDiagnostic:_o(e.node,t),tiebreak:e.disambiguation.tiebreak,alternatives:e.disambiguation.alternatives.slice(0,5).map(e=>_o(e,t))}:ho}function _o(e,t){let n=y(e.type??``),r=K(e,t);return{diagnosticRef:`diag-${e.ref}`,...n?{role:no(n,256)}:{},...r===void 0?{}:{label:no(r,256)}}}function vo(e,t,n,r,i){return{node:t,selectorChain:se(t,e.backend.platform,{action:r===`fill`?`fill`:`click`,nodes:n}),refLabel:K(t,n),...bo(t,r),preActionNodes:n,resolution:i,...yo(e,t,n,r)}}function yo(e,t,n,r){if(r!==`click`&&r!==`press`)return{};let i=Ia(t,n);return i===t?{}:{recordingTarget:{node:i,selectorChain:se(i,e.backend.platform,{action:`click`,nodes:n}),refLabel:K(i,n)}}}function bo(e,t){return e.hittable===!1?{targetHittable:!1,hint:`The resolved element reports hittable: false, so this ${t} may have had no visible effect. Verify with a snapshot, or prefer a @ref or a longer/more specific selector to target the intended element.`}:{}}function xo(e){return e.filter(e=>!J(e))}function So(e,t,n){let r=Ca(e,t);if(r.reason===`covered`)throw wo({label:n.label,node:t,action:n.action});return r.node}function Co(e,t,n){if(J(e))throw wo({label:t,node:e,action:n})}function wo(e){return new n(`COMMAND_FAILED`,`${e.label} is covered by another visible element and cannot ${To(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 To(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(z(e,t),{interactiveOnly:r,includeRects:!0}),s=o.snapshot??{nodes:o.nodes??[],truncated:o.truncated,backend:o.backend,createdAt:B(e)};return await e.sessions.set({...a,snapshot:s}),{snapshot:s}}async function Eo(e,t,r){if(e.backend.platform!==`macos`)return;let i=await Do(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 Do(e,t){return(await e.sessions.get(t.session??`default`))?.metadata?.surface}async function Oo(e,t,r){let{session:i,snapshot:a}=await Qa(e,t.session),o=r.fallbackLabel??``,s=Ao(a.nodes,r.ref,{fallbackLabel:o});if(!s)throw new n(`COMMAND_FAILED`,`Ref ${r.ref} not found or has no bounds`,{hint:_e});return ko({session:i,frameTree:a,target:r,fallbackLabel:o,authorized:s})}function ko(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=Ao(o.nodes,r.ref,{fallbackLabel:i});return s&&ye(b(a.node),b(s.node))?{snapshot:o,resolved:s}:{snapshot:n,resolved:a}}function Ao(e,t,i){let a=o(t);if(!a)throw new n(`INVALID_ARGS`,`Invalid ref: ${t}`);let s=r(e,a);if(Mo(s))return{ref:a,node:s,resolution:po};let c=i.fallbackLabel.length>0?Yi(e,i.fallbackLabel):null;return Mo(c)?{ref:a,node:c,resolution:mo}:null}function jo(e,t){let r=U(e.rect);if(!r)throw new n(`COMMAND_FAILED`,t);return r}function Mo(e){return e?U(e.rect)!==null:!1}async function No(e,t,n,r,i,a){return await Lo(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=>`${Fo(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 Po(e,t,n,r,i,a){return await Lo(e,t,n,r,{message:`Ref ${i} is off-screen and not safe to ${a}`,details:{reason:`offscreen_ref`,ref:o(i)},hint:e=>`${Fo(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 Fo(e){return e?`Scroll ${e} toward it`:`Scroll toward it`}async function Io(e,t,n,r){let i=(await e.sessions.get(t.session??`default`))?.snapshot?.nodes;if(!i||o(n.ref)===null)return{};let a=Ao(i,n.ref,{fallbackLabel:n.fallbackLabel??``});if(!a)return{};Co(a.node,`Ref ${n.ref}`,r);let s=await Po(e,t,a.node,i,n.ref,r);return{...bo(s,r),node:s,preActionNodes:i}}async function Lo(e,t,r,i,a){let o=r.rect?be(r,i):null;if(!r.rect||!o||we(r,i))return r;let s=me(i,r.rect),c=await e.backend.confirmOffscreenTargetVisible?.(z(e,t),r,s);if(c)return{...r,rect:c};let l=h(r,i);throw new n(`COMMAND_FAILED`,a.message,{...a.details,rect:r.rect,viewport:o,...l?{scrollDirection:l}:{},hint:a.hint(l)})}function Ro(e,t){let n=P(e.type??`Element`),r=N(e,n),i=e.enabled===!1?`disabled`:`enabled`,a=e.selected===!0?`selected`:`unselected`,o=e.hittable===!0?`hittable`:`not-hittable`;return[String(t??e.depth??0),n,r,i,a,o].join(`|`)}function zo(e,t,n={}){let r=Ho(Vo(e,n),Vo(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 Bo(e,t={}){return Vo(e,t).length}function Vo(e,t){return t.flatten?e.map(e=>({text:M(e,0,!1),comparable:Ro(e,0),...t.withRefs&&e.ref?{ref:e.ref}:{}})):Dr(e).map(e=>({text:e.text,comparable:Ro(e.node,e.depth),...t.withRefs&&e.node.ref?{ref:e.node.ref}:{}}))}function Ho(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=Wo(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 Uo(o,e,t,n,r)}}return[]}function Uo(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=Wo(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 Wo(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}function Go(e){return e?ze({packageName:e.bundleId,resourceId:e.identifier}).inputMethodOwned:!1}const Ko=new Set([`textfield`,`securetextfield`,`textview`,`textarea`,`searchfield`,`edittext`]),qo={strippedIndexes:new Set,refs:new Set};function Jo(e){let t=new Set(e.filter(e=>y(e.type??``)===`keyboard`).map(e=>e.index));if(t.size===0)return qo;let n=new Map(e.map(e=>[e.index,e])),r=$o(e,n,t),i=new Set(r),a=ss(e,n,r);for(let t of $o(e,n,a))i.add(t);for(let o of Yo(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 Yo(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=Qo(t,r);for(let n of e)!i.has(n.index)&&!s.has(n.index)&&n.rect&&Xo(n,t,o)&&a.add(n.index);return a}function Xo(e,t,n){if(!e.rect)return!1;let r=cs(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=cs(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 Qo(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 $o(e,t,n){let r=new Set(n);if(n.size===0)return r;for(let i of e)ls(i,t,n)&&r.add(i.index);return r}function es(e,t){if(e.bundleId!==`com.android.systemui`)return!1;if(Be(e))return!0;let n=new Set,r=e;for(;r?.bundleId===`com.android.systemui`&&!n.has(r.index);){if(Re(r.identifier))return!0;n.add(r.index),r=r.parentIndex===void 0?void 0:t.get(r.parentIndex)}return!1}function ts(e,t){let n=new Map(e.map(e=>[e.index,e])),r=new Set(e.filter(e=>Go(e)).map(e=>e.index)),i=new Set([...r].filter(e=>{let t=n.get(e)?.parentIndex,i=t===void 0?void 0:n.get(t);return!i||!r.has(i.index)})),a=t===`com.android.systemui`?new Set:ns(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?qo:{strippedIndexes:o,refs:s}}function ns(e,t,n){return new Set(e.filter(e=>!n.has(e.index)&&es(e,t)).map(e=>e.index))}function rs(e,t){let n=Jo(e),r=ts(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 is(e,t){let{strippedIndexes:n}=rs(e,t);return n.size===0?e:e.filter(e=>!n.has(e.index))}function as(e,t){return rs(e,t).refs}function os(e){return Jo(e).refs}function ss(e,t,n){let r=new Set;for(let e of n){let n=t.get(e);if(!n||y(n.type??``)!==`keyboard`)continue;let i=cs(n,t);i!==void 0&&r.add(i)}for(let i of r){let a=new Set([i]);e.some(e=>Ko.has(y(e.type??``))&&!n.has(e.index)&&ls(e,t,a))&&r.delete(i)}return r}function cs(e,t){let n=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0;for(;n;){if(y(n.type??``)===`window`)return n.index;n=typeof n.parentIndex==`number`?t.get(n.parentIndex):void 0}}function ls(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 us(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)}}const ds=`Settled on a nearly-empty tree — the app may still be loading. Wait for specific content (wait text ...) before interacting.`;async function fs(e,t,n){let{quietMs:r,timeoutMs:i}=n,a=B(e),o=a+i,s=!1,c=Math.min(300,Math.max(25,r)),l=0,u,d=0,f,p=a;for(;B(e)<o;){let m=await hs(e,t,o-B(e));if(!m)return{settled:!1,stalled:!0,waitedMs:B(e)-a,captures:l,nodeCount:d,lastCapture:f};l+=1,f=m;let h=gs(m.snapshot.nodes),g=B(e);if(n.resetBudgetOnPrivateAxRecovery===!0&&!s&&ps(m.snapshot.snapshotQuality)){s=!0,o=Math.max(o,g+i),p=g,u=h,d=m.snapshot.nodes.length;let t=ms({nowMs:g,quietSinceMs:p,quietMs:r,pollMs:c,deadlineMs:o});if(t<=0)break;await Li(e,t);continue}if(h!==u)u=h,d=m.snapshot.nodes.length,p=g;else if(l>=2&&g-p>=r)return{settled:!0,stalled:!1,waitedMs:g-a,captures:l,nodeCount:d,lastCapture:f};let _=ms({nowMs:g,quietSinceMs:p,quietMs:r,pollMs:c,deadlineMs:o});if(_<=0)break;await Li(e,_)}return{settled:!1,stalled:!1,waitedMs:B(e)-a,captures:l,nodeCount:d,lastCapture:f}}function ps(e){return e?.state===`recovered`&&e.backend===`private-ax`&&e.reasonCode!==`deferred`}function ms(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 hs(e,t,n){let r=await us(e,t,n,async n=>await $a(e,{...t,signal:n},{updateSession:!1,interactiveOnly:!0}));return r.timedOut?void 0:r.value}function gs(e){return e.map(_s).join(`|`)}function _s(e){let t=e.rect?`${Math.round(e.rect.x)},${Math.round(e.rect.y)},${Math.round(e.rect.width)},${Math.round(e.rect.height)}`:``;return`${e.type??``}#${e.label??``}#${e.identifier??``}#${t}`}const vs=`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.`,ys=`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 bs(e,t,n){return await Ss(e,t,{...n,baselineNodes:Ts(n.resolved),actionPoint:n.resolved.point})}const xs=async(e,t)=>(await Ss(e,t,t)).observation;async function Ss(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 Cs(e,t,n,a,await fs(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 Cs(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?ys:vs}};let{stored:o,session:s}=await Ps(e,t,i.lastCapture),c=i.lastCapture.snapshot.nodes;return{observation:{...a,...i.settled&&o?Ds(n.baselineNodes,c,n.actionPoint,s?.appBundleId):{},...Ns(i,o,c.length)},settledNodes:c}}function ws(e,t){if(!e)return;let n=H(e),r=t!==void 0&&n.digest!==H(t).digest;return{...n,changedFromBefore:r}}function Ts(e){return`preActionNodes`in e&&e.preActionNodes?e.preActionNodes:[]}function Es(e,t,n){let r=zo(is(e,n),is(t,n),{flatten:!0,withRefs:!0}),i=r.lines.filter(e=>e.kind!==`unchanged`),a=Ms(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 Ds(e,t,n,r){let i=Es(e,t,r);return{diff:i,...Os(i,t,n,r)}}function Os(e,t,n,r){let i=new Set(e.lines.filter(e=>e.kind===`added`&&e.ref).map(e=>e.ref)),a=as(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)&&!ks(o.get(e),n))?{}:js(t,i,r)}function ks(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 As=new Set([`application`,`window`]);function js(e,t,n){let r=as(e,n),i=e.filter(e=>e.ref&&e.interactionBlocked!==`covered`&&!t.has(e.ref)&&!r.has(e.ref)&&!As.has(P(e.type??`Element`)));if(i.length===0)return{};let a=i.slice(0,20).map(e=>{let t=P(e.type??`Element`),n=N(e,t);return{ref:e.ref,role:t,...n?{label:n}:{}}});return{tail:a,...i.length>a.length?{tailTruncated:!0}:{}}}function Ms(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 Ns(e,t,n){return e.stalled?{hint:ys}:e.settled?t?n<5?{hint:ds}:{}:{hint:`Settled on a sparse, unreadable tree — the diff is omitted. Use screenshot as visual truth before interacting further.`}:{hint:vs}}async function Ps(e,t,n){if(Va(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 Fs(e){let t=e.verify===!0;return{verify:t,needsPreActionBaseline:t||e.settle!==void 0,...e.settle===void 0?{}:{settle:e.settle}}}async function Is(e,t,n,r,i){let a=await Ls(e,t,n,i);return zs({...r,...a})}async function Ls(e,t,n,r){if(r.settle!==void 0){let i=await bs(e,t,{...r.settle,resolved:n}),a=r.verify?ws(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 Rs(e,t,n);return i?{evidence:i}:{}}async function Rs(e,t,n){let r=`preActionNodes`in n?n.preActionNodes:void 0;try{let n=H((await Z(e,t,!0)).snapshot.nodes),i=r!==void 0&&n.digest!==H(r).digest;return{...n,changedFromBefore:i}}catch{return}}function zs(e){let t=e;if(t.targetHittable!==!1||!Bs(t)||t.hint===void 0)return e;let{hint:n,...r}=t;return r}function Bs(e){if(e.evidence?.changedFromBefore===!0)return!0;let t=e.settle?.diff?.summary;return!!t&&(t.additions>0||t.removals>0)}function Vs(e,t){let r=e.filter(t=>de(t,e)).map(e=>e.rect).filter(Hs),i=r.length>0?r:e.map(e=>e.rect).filter(Hs);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 Hs(e){return!!(e&&e.width>0&&e.height>0)}async function Us(e,t){return await e.backend.resolveGestureViewport?.(z(e,t))||Vs((await Z(e,t,!1)).snapshot.nodes,`gesture`)}const Ws=async(e,t)=>{let r=await X(e,t,{action:`focus`,requireInteractive:!0,promoteToHittableAncestor:!1});if(!e.backend.focus)throw new n(`UNSUPPORTED_OPERATION`,`focus is not supported by this backend`);let i=$(r),a=V(await e.backend.focus(z(e,t),i));return{...r,...a?{backendResult:a}:{},...C(`Focused (${i.x}, ${i.y})`)}},Gs=async(e,t)=>{let r=Fs(t),i=await X(e,t,{action:`longPress`,requireInteractive:!0,promoteToHittableAncestor:!0,captureEvidenceBaseline:r.needsPreActionBaseline,expectedResolvedTarget:t.expectedResolvedTarget});if(!e.backend.longPress)throw new n(`UNSUPPORTED_OPERATION`,`longPress is not supported by this backend`);let a=t.durationMs===void 0?void 0:Ii(t.durationMs,`durationMs`,0,12e4),o=$(i),s=V(await e.backend.longPress(z(e,t),o,{durationMs:a}));return await Is(e,t,i,{...i,...a===void 0?{}:{durationMs:a},...s?{backendResult:s}:{},...C(`Long pressed (${o.x}, ${o.y})`)},r)},Ks=async(e,t)=>{if(!e.backend.performGesture)throw new n(`UNSUPPORTED_OPERATION`,`gesture is not supported by this backend`);await Eo(e,t,`drag`);let r=await Us(e,t),i=await qs(e,t,`source`),a=await qs(e,t,`destination`),o=u({from:$(i),to:$(a),sourceHoldMs:t.gesture.sourceHoldMs,moveMs:t.gesture.moveMs,destinationHoldMs:t.gesture.destinationHoldMs},r),s=V(await e.backend.performGesture(z(e,t),o)),{start:c,end:d}=l(o);return{kind:`drag`,durationMs:o.durationMs,pointerCount:1,from:c,to:d,targets:{source:Js(i),destination:Js(a)},recording:Ys(i,a),...s?{backendResult:s}:{},...C(`Dragged ${t.gesture.source} to ${t.gesture.destination}`)}};async function qs(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,promoteToHittableAncestor:!1,expectedResolvedTarget:t.expectedResolvedTargets?.[n],replayTargetRole:n})}function Js(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 Ys(e,t){let n=Xs(e),r=Xs(t),i=Zs(e),a=Zs(t);return{...n?{sourceSelector:n}:{},...r?{destinationSelector:r}:{},...i?{sourceTarget:i}:{},...a?{destinationTarget:a}:{}}}function Xs(e){return`selectorChain`in e&&e.selectorChain?.length?e.selectorChain.join(` || `):void 0}function Zs(e){if(!(!(`selectorChain`in e)||!e.selectorChain?.length||!e.node||!e.preActionNodes))return{selectorChain:e.selectorChain,node:e.node,preActionNodes:e.preActionNodes}}const Qs=async(e,t)=>{if(!e.backend.scroll)throw new n(`UNSUPPORTED_OPERATION`,`scroll is not supported by this backend`);let r=ec(t.direction),i=ic(t.amount,`scroll amount`),a=oc(t.pixels,`scroll pixels`),o=c(t.durationMs);d({amount:i,pixels:a},`scroll accepts either amount or pixels, not both`);let s=await $s(e,t),l=s.kind===`viewport`?{kind:`viewport`}:{kind:`point`,point:$(s)},u=e.backend.scroll,f=async()=>await u(z(e,t),l,{direction:r.direction,...i===void 0?{}:{amount:i},...a===void 0?{}:{pixels:a},...o===void 0?{}:{durationMs:o}}),p,m=0;if(r.edge){let n=r.edge,i=tc(s),a=await Si({edge:n,captureState:async r=>await nc(e,t,n,i,r),scroll:f});p=a.result,m=a.passes}else p=await f(),m=1;let h=V(p),_=g(h);return{...s,direction:r.direction,...r.edge?{edge:r.edge,passes:m}:{},...i===void 0?{}:{amount:i},...a===void 0?{}:{pixels:a},..._===void 0?{}:{durationMs:_},...h?{backendResult:h}:{},...C(Ci(r.direction,r.edge,m,i,a))}};async function $s(e,t){let n=t.target??{kind:`viewport`};return n.kind===`viewport`?(await Eo(e,t,`scroll`),{kind:`viewport`}):await X(e,{...t,target:n},{action:`scroll`,requireInteractive:!1,promoteToHittableAncestor:!1})}function ec(e){return e===`bottom`?{direction:`down`,edge:`bottom`}:e===`top`?{direction:`up`,edge:`top`}:{direction:rc(e,`scroll direction`)}}function tc(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 nc(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 xi({edge:r,target:i,scope:a,captureNodes:async n=>{let r=await o(z(e,t),{scope:n});return r.snapshot?.nodes??r.nodes??[]}})}function rc(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 ic(e,t){return e===void 0?void 0:ac(e,t)}function ac(e,t){if(!Number.isFinite(e)||e<=0)throw new n(`INVALID_ARGS`,`${t} must be a positive number`);return e}function oc(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 sc=/^e\d+$/;function cc(e){if(e[0]?.startsWith(`@`)){let t=_c(e.slice(1));return{ref:e[0],...t===void 0?{}:{label:t}}}if(sc.test(e[0]??``))throw new n(`INVALID_ARGS`,`Did you mean "@${e[0]}"? Snapshot refs need the @ prefix.`);let t=ve(e);if(t){if(t.rest.length>0)throw new n(`INVALID_ARGS`,mc(e,t));return{selector:t.selectorExpression}}return uc(e)}function lc(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?_c(e.slice(1,2)):void 0},text:n}}if(sc.test(t??``))throw new n(`INVALID_ARGS`,`Did you mean "@${t}"? Snapshot refs need the @ prefix.`);let r=ve(e,{preferTrailingValue:!0});return r?{kind:`selector`,target:{selector:r.selectorExpression},text:r.rest.join(` `)}:{kind:`point`,target:uc(e.slice(0,2)),text:e.slice(2).join(` `)}}function uc(e){let t=e[0]??``,r=fe(t);if(r){let i=dc(t)?r.value:[r.value,...e.slice(1)].join(` `).trim();throw new n(`INVALID_ARGS`,fc({key:r.key,value:i}))}let i=Number(e[0]),a=Number(e[1]);if(Number.isFinite(i)&&Number.isFinite(a))return{x:i,y:a};throw new n(`INVALID_ARGS`,pc(e))}function dc(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 fc(e){let{key:t,value:n}=e;return`Unknown selector key "${t}". Supported: ${ce.join(`, `)}. ${ge(t)?`Did you mean role=${t} label=${gc(n)}?`:`Did you mean label=${gc(n)}?`}`}function pc(e){let t=e.filter(e=>e!==void 0).join(` `);if(!t.trim())return`Missing target. Pass an @ref from snapshot, a selector like text="Sign in", or "x y" coordinates.`;let n=`Target "${t}" is not a @ref, selector, or "x y" point.`;return e.some(e=>Me(e??``))?`${n} Selector values with spaces need quotes, e.g. text="Sign in".`:`${n} To match by visible text, use text=${gc(t)} (or label=/id=/role=), or pass an @ref from snapshot.`}function mc(e,t){return`${`Selector ${t.selectorExpression} is followed by unexpected extra arguments: "${t.rest.join(` `)}".`} Selector values with spaces need quotes, e.g. ${hc(e,t)??`text="Sign in"`}.`}function hc(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)}${gc(a)}`;return[...e.slice(0,n-1),o].join(` `)}function gc(e){return`"${e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`)}"`}function _c(e){return e.join(` `).trim()||void 0}function vc(e,t={}){let n=I(process.stderr);if(e===`pass`){let e=t.passFormat??`green`;return n?yc(`✓`,e):`✓`}return e===`fail`?n?yc(`⨯`,`red`):`⨯`:e===`warn`?n?yc(`!`,`yellow`):`!`:n?yc(`-`,`dim`):`-`}function yc(e,t){return L(e,t,{validateStream:!1})}function bc(e){return`${vc(Sc(e.status))} ${Cc(e)}`}function xc(e){return e.status!==`fail`&&e.status!==`warn`?[]:typeof e.command==`string`?[` run: ${e.command}`]:typeof e.hint==`string`?[` hint: ${e.hint}`]:[]}function Sc(e){return e===`pass`?`pass`:e===`fail`?`fail`:e===`warn`?`warn`:`skip`}function Cc(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}`}function wc(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}export{G as $,wt as $t,$a as A,$t as At,Ha as B,zt as Bt,po as C,$e as Cn,or as Ct,X as D,Vt as Dt,Io as E,Zt as Et,Za as F,nn as Ft,ea as G,Ot as Gt,Ca as H,Lt as Ht,Va as I,tn as It,Zi as J,jt as Jt,$i as K,Dt as Kt,Ja as L,an as Lt,Qa as M,en as Mt,to as N,Qt as Nt,ro as O,Xt as Ot,Xa as P,Ht as Pt,Ji as Q,yt as Qt,Ba as R,on as Rt,Bo as S,Ze as Sn,er as St,Eo as T,Je as Tn,Bn as Tt,ia as U,Pt as Ut,Sa as V,Rt as Vt,J as W,It as Wt,qi as X,Et as Xt,K as Y,Tt as Yt,Ki as Z,bt as Zt,us as _,qe as _n,I as _t,lc as a,ft as an,B as at,Go as b,Ye as bn,M as bt,Ws as c,ht as cn,xi as ct,Qs as d,it as dn,L as dt,at as en,Wi as et,Is as f,C as fn,ei as ft,fs as g,tt as gn,Rr as gt,ds as h,nt as hn,zr as ht,vc as i,gt as in,V as it,eo as j,Ut as jt,io as k,Bt as kt,Gs as l,lt as ln,Ci as lt,xs as m,We as mn,Br as mt,xc as n,dt as nn,H as nt,cc as o,ut as on,z as ot,Fs as p,w as pn,$r as pt,Yi as q,Mt as qt,bc as r,pt as rn,Ri as rt,Ks as s,mt as sn,Ii as st,wc as t,ot as tn,U as tt,Us as u,_t as un,Si as ut,os as v,Ke as vn,N as vt,ao as w,Qe as wn,$n as wt,zo as x,et as xn,ir as xt,as as y,Xe as yn,P as yt,Ua as z,rn as zt};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: agent-device
|
|
3
|
-
description: Automates Apple-platform apps (iOS, tvOS, macOS), Android devices, and Amazon Vega OS TV apps in Vega Virtual Devices. Use when navigating apps, taking snapshots/screenshots where supported, driving TV remotes, tapping, typing, scrolling, extracting UI info, collecting evidence, or planning agent-device CLI commands.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# agent-device
|
|
7
|
-
|
|
8
|
-
Router only. Private setup before using this skill:
|
|
9
|
-
|
|
10
|
-
```bash
|
|
11
|
-
agent-device --version
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
If that fails but the user may have installed `agent-device` globally, check the user's configured login/interactive shell and environment before using `npx`. Resolve the command the same way the user would from a normal terminal session, then run the absolute binary path if found. This may require inspecting shell startup behavior or package-manager/global bin locations; do not assume the Codex process `PATH` is the user's `PATH`.
|
|
15
|
-
|
|
16
|
-
Require `agent-device >= 0.20.0`; older CLIs lack the current help topics and Vega OS routing. If older, stop and tell the user to upgrade the trusted install or approve an exact-version npm command. Do not run `npm install -g agent-device@latest` or `npx -y agent-device@latest` autonomously, and do not include version/upgrade commands in final plans.
|
|
17
|
-
|
|
18
|
-
Before your first agent-device command or plan, read the smallest version-matched CLI guide that fits the task:
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
agent-device help manual-qa # scripted/manual QA, acceptance checks, checklist execution
|
|
22
|
-
agent-device help validate # code/runtime validation, stale build or daemon risk
|
|
23
|
-
agent-device help dogfood # exploratory app dogfooding and evidence collection
|
|
24
|
-
agent-device help workflow # fallback reference for general app driving or mixed tasks
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Read additional topics only when relevant:
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
agent-device help debugging
|
|
31
|
-
agent-device help react-native
|
|
32
|
-
agent-device help react-devtools
|
|
33
|
-
agent-device help cdp
|
|
34
|
-
agent-device help remote
|
|
35
|
-
agent-device help macos
|
|
36
|
-
agent-device help dogfood
|
|
37
|
-
agent-device help tv
|
|
38
|
-
agent-device help ios-system-ui # iOS SpringBoard, widgets, and system-UI surfaces
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
Default loop: `open -> snapshot/-i -> get/is/find or press/fill/scroll/wait -> verify -> close`. When target-specific help says capture or selectors are unsupported, use its control-only loop and the device display as visual truth.
|
|
42
|
-
|
|
43
|
-
Use this skill only to route into version-matched CLI help. Let the selected help topic provide exact command shapes, platform limits, and current workflow guidance; use `help workflow` as the full reference when a task-specific topic is too narrow.
|
|
44
|
-
|
|
45
|
-
For precise location workflows, read the installed `settings` help before planning so coordinate support and platform limits come from the active CLI version.
|
package/skills/dogfood/SKILL.md
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: dogfood
|
|
3
|
-
description: Systematically explore and test a mobile app on iOS/Android with agent-device to find bugs, UX issues, and other problems. Use when asked to dogfood, QA, exploratory test, find issues, bug hunt, or test this app on mobile.
|
|
4
|
-
allowed-tools: Bash(agent-device:*), Bash(npx agent-device:*)
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Dogfood
|
|
8
|
-
|
|
9
|
-
Router for exploratory QA. Private setup before using this skill:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
agent-device --version
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
If that fails, stop and tell the user to expose a trusted `agent-device` binary on PATH or approve an exact-version npm command. This skill intentionally keeps allowed tools restricted to `agent-device` and `npx agent-device`.
|
|
16
|
-
|
|
17
|
-
Require `agent-device >= 0.14.0`; older CLIs lack these help topics. If older, stop and tell the user to upgrade the trusted install or approve an exact-version npm command. Do not run `npm install -g agent-device@latest` or `npx -y agent-device@latest` autonomously, and do not include version/upgrade commands in final plans.
|
|
18
|
-
|
|
19
|
-
Read current CLI guidance:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
agent-device help dogfood
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Loop: open app -> snapshot -i + screenshot -> explore flows -> capture evidence per issue -> close.
|
|
26
|
-
|
|
27
|
-
Target app is required; infer platform or ask. Findings must come from runtime behavior, not source reads. Let `help dogfood` provide exact report shape, evidence commands, and current workflow guidance.
|