agent-device 0.20.9 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.9.apk → agent-device-android-ime-helper-0.21.0.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.0.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.9.manifest.json → agent-device-android-ime-helper-0.21.0.manifest.json} +4 -4
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.0.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.0.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.9.manifest.json → agent-device-android-snapshot-helper-0.21.0.manifest.json} +6 -6
- package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/AudioProbe.swift +35 -33
- package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/main.swift +6 -1
- package/apple/snapshot-bridge/LICENSE.idb +23 -0
- package/apple/snapshot-bridge/README.md +49 -0
- package/apple/snapshot-bridge/SnapshotBridge.m +280 -0
- package/apple/snapshot-bridge/SnapshotBridgeRuntime.h +33 -0
- package/apple/snapshot-bridge/SnapshotBridgeRuntime.m +382 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +58 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/project.pbxproj +19 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAlertVerification.swift +36 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerStringNormalization.swift +8 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.h +12 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +100 -6
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTapPointPolicy.swift +2 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +21 -12
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +21 -88
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift +124 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +110 -107
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +6 -14
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +85 -114
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +13 -6
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +72 -175
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +10 -11
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXElementTypes.swift +12 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXPresentation.swift +78 -64
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScreenRecorder.swift +17 -9
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollGesture.swift +47 -13
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +232 -438
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotBackendCapabilities.swift +98 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +229 -168
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotPresentationInvariant.swift +19 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTiming.swift +110 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedCommitDeadline.swift +206 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedTextEntry.swift +147 -25
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +21 -18
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +24 -307
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift +206 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryReadiness.swift +158 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputCandidatePolicy.swift +19 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextTyping.swift +49 -16
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Transport.swift +2 -11
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift +4 -19
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +16 -20
- package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/RecordingExportSupport.swift +111 -0
- package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/recording-overlay.swift +42 -81
- package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/recording-trim.swift +35 -82
- package/dist/apple/snapshot-presentation/Package.swift +21 -0
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotGeometry.swift +56 -0
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotModels.swift +259 -0
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentation.swift +153 -0
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationFailure.swift +27 -0
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationInvariant.swift +91 -0
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationProjection.swift +161 -0
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotScopePolicy.swift +53 -0
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFold.swift +242 -0
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFoldProjection.swift +97 -0
- package/dist/src/adapter.js +1 -0
- package/dist/src/adb-executor.js +2 -0
- package/dist/src/adb-failure.js +1 -0
- package/dist/src/adb-host.js +1 -0
- package/dist/src/adb.js +1 -0
- package/dist/src/agent-browser-lifecycle.js +1 -0
- package/dist/src/agent-browser-process-record.js +1 -0
- package/dist/src/agent-browser-provider.js +1 -0
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/agent-device-client.js +2 -2
- package/dist/src/ai-sdk.d.ts +61 -0
- package/dist/src/ai-sdk.js +1 -0
- package/dist/src/alert-contract.js +1 -0
- package/dist/src/alert-runtime.js +1 -0
- package/dist/src/android-adb.d.ts +27 -19
- package/dist/src/android-adb.js +1 -1
- package/dist/src/android-input-ownership.js +1 -0
- package/dist/src/android-system-chrome.js +1 -0
- package/dist/src/android.js +1 -1
- package/dist/src/api.js +11 -0
- package/dist/src/app-catalog.js +1 -0
- package/dist/src/app-deployment-resolution.js +2 -0
- package/dist/src/app-helpers.js +1 -1
- package/dist/src/app-inventory-contract.js +1 -0
- package/dist/src/app-inventory.js +1 -0
- package/dist/src/app-launch.js +2 -0
- package/dist/src/app-lifecycle-facade.js +1 -0
- package/dist/src/app-lifecycle.js +3 -6
- package/dist/src/app-lifecycle2.js +2 -2
- package/dist/src/app-lifecycle3.js +1 -0
- package/dist/src/app-log-files.js +1 -1
- package/dist/src/app-log-reconnect.js +1 -1
- package/dist/src/app-log-runtime.js +1 -4
- package/dist/src/app-log-runtime2.js +4 -0
- package/dist/src/app-parsers.js +4 -0
- package/dist/src/app-resolution-cache.js +1 -0
- package/dist/src/app-resolution-facade.js +1 -0
- package/dist/src/app-resolution.js +2 -2
- package/dist/src/app-state.js +1 -2
- package/dist/src/application-lifecycle-interaction.js +1 -0
- package/dist/src/application-lifecycle-runtime.js +1 -0
- package/dist/src/apps-simctl.js +1 -0
- package/dist/src/archive.js +4 -0
- package/dist/src/artifact-download.js +1 -0
- package/dist/src/artifacts.d.ts +6 -2
- package/dist/src/artifacts.js +1 -1
- package/dist/src/async-lifecycle.js +1 -0
- package/dist/src/audio-probe-result.js +1 -0
- package/dist/src/audio-probe-runtime.js +1 -0
- package/dist/src/audio-probe-support.js +1 -0
- package/dist/src/auth-session.js +1 -1
- package/dist/src/auth.js +1 -1
- package/dist/src/back-mode.js +1 -0
- package/dist/src/{url.js → base-url.js} +1 -1
- package/dist/src/boot-diagnostics.js +2 -2
- package/dist/src/byte-limit-stream.js +1 -1
- package/dist/src/capabilities.js +1 -0
- package/dist/src/capture.js +1 -0
- package/dist/src/catalog.js +1 -0
- package/dist/src/cli-command-aliases.js +1 -0
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +77 -51
- package/dist/src/cli-output.js +1 -1
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +5 -7
- package/dist/src/click-button.js +1 -0
- package/dist/src/client-metro-companion.js +1 -0
- package/dist/src/client-metro.js +1 -1
- package/dist/src/client-types.d.ts +1606 -0
- package/dist/src/clipboard.js +1 -0
- package/dist/src/code-signature-cache.js +1 -0
- package/dist/src/code-signature.js +1 -0
- package/dist/src/color.js +1 -0
- package/dist/src/command-metadata.js +1 -1
- package/dist/src/command-schema.js +3 -3
- package/dist/src/command-surface.js +1 -1
- package/dist/src/command-tools.js +2 -0
- package/dist/src/command.js +1 -0
- package/dist/src/{selector-vocabulary.js → compatibility-policy.js} +1 -1
- package/dist/src/config.js +1 -1
- package/dist/src/config2.js +1 -0
- package/dist/src/connection-runtime.js +1 -1
- package/dist/src/connection.js +5 -5
- package/dist/src/contracts.d.ts +1 -1
- package/dist/src/contracts.js +1 -1
- package/dist/src/daemon-client-lifecycle.js +1 -0
- package/dist/src/daemon-process.js +1 -0
- package/dist/src/daemon-registration.js +1 -0
- package/dist/src/daemon-shutdown-report.js +1 -1
- package/dist/src/daemon.js +2 -2
- package/dist/src/debug-symbols-facade.js +5 -0
- package/dist/src/deploy-result-target.js +1 -0
- package/dist/src/device-claim-inspection.js +1 -1
- package/dist/src/device-claim-rule.js +1 -0
- package/dist/src/device-input-state.d.ts +190 -3
- package/dist/src/device-inventory-context.js +1 -0
- package/dist/src/device-isolation.js +1 -0
- package/dist/src/device-release.js +1 -0
- package/dist/src/device-rotation.js +1 -0
- package/dist/src/device-selection-resolver.js +1 -0
- package/dist/src/device-session.js +1 -0
- package/dist/src/device.js +1 -1
- package/dist/src/device2.js +3 -2
- package/dist/src/diagnostics.js +3 -0
- package/dist/src/diagnostics2.js +1 -0
- package/dist/src/dispatch-resolve.js +1 -0
- package/dist/src/doctor-facade.js +1 -0
- package/dist/src/doctor-output.js +1 -0
- package/dist/src/doctor.js +1 -0
- package/dist/src/doctor2.js +1 -0
- package/dist/src/doctor3.js +1 -0
- package/dist/src/durable-resource.js +1 -0
- package/dist/src/entities.js +1 -1
- package/dist/src/error.js +2 -0
- package/dist/src/exec.js +1 -0
- package/dist/src/file.js +1 -0
- package/dist/src/find.js +1 -1
- package/dist/src/finders.js +1 -1
- package/dist/src/format.js +2 -0
- package/dist/src/generic-settle.js +1 -1
- package/dist/src/generic.js +1 -1
- package/dist/src/gesture-admission.js +1 -0
- package/dist/src/gesture-plan-types.js +1 -0
- package/dist/src/gesture-plan.js +1 -0
- package/dist/src/gesture-runtime.js +1 -0
- package/dist/src/harmonyos.js +1 -1
- package/dist/src/hdc.js +1 -1
- package/dist/src/helper.js +2 -2
- package/dist/src/host-file.js +1 -0
- package/dist/src/human-control-contract.js +1 -0
- package/dist/src/human-control.js +1 -0
- package/dist/src/index.d.ts +2 -1578
- package/dist/src/index.js +1 -1
- package/dist/src/input-actions.js +1 -4
- package/dist/src/input-actions2.js +2 -1
- package/dist/src/install-artifact-facade.js +1 -0
- package/dist/src/install-source-network-transport.js +1 -0
- package/dist/src/install-source.d.ts +3 -10
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-positionals.js +1 -0
- package/dist/src/interaction-ref-policy.js +1 -0
- package/dist/src/interaction.js +1 -1
- package/dist/src/interaction2.js +1 -1
- package/dist/src/interactor-operation-catalog.js +1 -0
- package/dist/src/interactor-types.js +1 -0
- package/dist/src/interactor.js +6 -2
- package/dist/src/interactor2.js +1 -1
- package/dist/src/interactors.js +1 -1
- package/dist/src/internal/bin.d.ts +1 -1
- package/dist/src/internal/bin.js +1 -2
- package/dist/src/internal/companion-tunnel.d.ts +1 -1
- package/dist/src/internal/companion-tunnel.js +1 -1
- package/dist/src/internal/daemon.d.ts +1 -1
- package/dist/src/internal/daemon.js +2 -4
- package/dist/src/internal/png-worker.d.ts +4 -4
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/internal/run-script-http-child.d.ts +4 -0
- package/dist/src/internal/run-script-http-child.js +1 -0
- package/dist/src/internal/update-check-entry.d.ts +1 -1
- package/dist/src/inventory.js +4 -4
- package/dist/src/inventory2.js +1 -1
- package/dist/src/inventory3.js +1 -1
- package/dist/src/inventory5.js +1 -1
- package/dist/src/inventory6.js +1 -1
- package/dist/src/ios-client.js +16 -0
- package/dist/src/ios-snapshot-acquisition.js +1 -0
- package/dist/src/ios-snapshot-adapter.js +1 -0
- package/dist/src/ios-snapshot-planning.js +1 -0
- package/dist/src/ios-snapshot-runtime.js +1 -0
- package/dist/src/json.js +1 -0
- package/dist/src/keyboard-actions.js +1 -0
- package/dist/src/launch-console.js +1 -0
- package/dist/src/lease-context.js +1 -1
- package/dist/src/lease-scope.js +1 -0
- package/dist/src/lease.js +1 -1
- package/dist/src/limrun-runtime-dependencies.js +1 -1
- package/dist/src/limrun.d.ts +1618 -7
- package/dist/src/limrun.js +1 -1
- package/dist/src/linux.js +1 -1
- package/dist/src/local-interactor-operation-set.js +1 -0
- package/dist/src/location-coordinates.js +1 -1
- package/dist/src/logcat.js +1 -1
- package/dist/src/macos-facade.js +1 -0
- package/dist/src/managed-device-scope.js +1 -0
- package/dist/src/mechanics.js +19 -0
- package/dist/src/metro.d.ts +4 -2
- package/dist/src/metro.js +1 -1
- package/dist/src/metro2.js +1 -1
- package/dist/src/mobile-snapshot-semantics.js +1 -0
- package/dist/src/multitouch-support.js +1 -0
- package/dist/src/numeric.js +1 -0
- package/dist/src/observability.js +1 -1
- package/dist/src/observation.js +2 -0
- package/dist/src/output-path.js +1 -1
- package/dist/src/owner-identity.js +3 -1
- package/dist/src/parameterized-recorded-fill.js +1 -0
- package/dist/src/parser.js +1 -1
- package/dist/src/perf-facade.js +2 -0
- package/dist/src/perf-runtime-operation-builder.js +1 -0
- package/dist/src/perf-runtime-plan.js +1 -0
- package/dist/src/perf-runtime.js +1 -0
- package/dist/src/perf.js +1 -4
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/physical-device-facade.js +1 -0
- package/dist/src/platform-request-scope.js +1 -0
- package/dist/src/platform-runtime-android-adb-host.js +1 -0
- package/dist/src/platform-runtime-android-mechanics.js +1 -0
- package/dist/src/platform-runtime-app-log-android-transport.js +1 -1
- package/dist/src/platform-runtime-app-log-process.js +1 -1
- package/dist/src/platform-runtime-apple-resources.js +1 -0
- package/dist/src/platform-runtime-host.js +1 -1
- package/dist/src/platform-runtime-managed-owner.js +1 -0
- package/dist/src/platform-runtime-network-web-transport.js +1 -1
- package/dist/src/platform-runtime-open-target.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +4 -4
- package/dist/src/platform-runtime-runtime-hints.js +2 -2
- package/dist/src/platform-runtime-screen-recording-android-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-apple-runner-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-apple-runner-transport.js +1 -1
- package/dist/src/platform-runtime-screen-recording-apple-simulator-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-apple-transport.js +1 -1
- package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-harmony-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-process-host.js +1 -0
- package/dist/src/platform-runtime-screen-recording-web-host.js +1 -1
- package/dist/src/platform-runtime-unavailable.js +1 -0
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/platform-runtime2.js +1 -1
- package/dist/src/plist.js +1 -1
- package/dist/src/png-worker-contract.js +1 -1
- package/dist/src/prepare-kind.js +1 -15
- package/dist/src/process-exit.js +1 -1
- package/dist/src/process.js +1 -0
- package/dist/src/provider-device-runtime.js +1 -0
- package/dist/src/provider-session-ownership.js +2 -0
- package/dist/src/provider-webdriver.js +1 -1
- package/dist/src/provider.js +1 -1
- package/dist/src/providers.js +1 -0
- package/dist/src/proxy.js +2 -2
- package/dist/src/react-native-overlay.js +1 -0
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-runtime.js +1 -1
- package/dist/src/record-trace.js +1 -1
- package/dist/src/rect-center.js +1 -0
- package/dist/src/register-builtins.js +1 -0
- package/dist/src/registry.js +39 -28
- package/dist/src/remote-config2.js +1 -1
- package/dist/src/replay-divergence.js +2 -0
- package/dist/src/replay.js +2 -2
- package/dist/src/reporting.js +8 -8
- package/dist/src/request-admission.js +1 -0
- package/dist/src/request-cancel.js +1 -0
- package/dist/src/request-cancellation.js +1 -0
- package/dist/src/request-progress-protocol.js +1 -0
- package/dist/src/request-providers.js +1 -0
- package/dist/src/request-runtime-binding.js +1 -0
- package/dist/src/request.js +1 -0
- package/dist/src/result-serialization.js +1 -0
- package/dist/src/retry.js +1 -0
- package/dist/src/rolldown-runtime.js +1 -1
- package/dist/src/runner-cache-metadata.js +2 -0
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-disposal.js +1 -1
- package/dist/src/runner-operations-facade.js +1 -0
- package/dist/src/runner-owner-facade.js +1 -0
- package/dist/src/runner-owner-state.js +1 -0
- package/dist/src/runner-presentation.js +1 -0
- package/dist/src/runner-selector-query.js +1 -0
- package/dist/src/runner.js +1 -0
- package/dist/src/{runtime-transport.js → runtime-transport-hints.js} +1 -1
- package/dist/src/runtime.js +3 -3
- package/dist/src/runtime2.js +4 -4
- package/dist/src/runtime3.js +1 -1
- package/dist/src/runtime4.js +4 -3
- package/dist/src/runtime5.js +1 -1
- package/dist/src/runtime6.js +1 -1
- package/dist/src/runtime7.js +1 -1
- package/dist/src/runtime8.js +1 -1
- package/dist/src/runtime9.js +1 -1
- package/dist/src/scoped-provider.js +1 -1
- package/dist/src/screen-recording-completion.js +1 -0
- package/dist/src/screen-recording-live-handle.js +1 -0
- package/dist/src/screen-recording-options.js +1 -0
- package/dist/src/screen-recording-resource-recovery.js +1 -0
- package/dist/src/screen-recording-runtime.js +1 -0
- package/dist/src/screenshot-density.js +1 -1
- package/dist/src/screenshot-result.js +1 -6
- package/dist/src/screenshot-runtime.js +1 -0
- package/dist/src/screenshot.js +1 -1
- package/dist/src/screenshot2.js +1 -0
- package/dist/src/screenshot3.js +5 -0
- package/dist/src/script.js +1 -0
- package/dist/src/scroll-command.js +1 -0
- package/dist/src/scroll-gesture.js +1 -0
- package/dist/src/scroll-indicator.js +1 -0
- package/dist/src/sdk-batch-runner.d.ts +23 -6
- package/dist/src/sdk-batch-runner.js +2 -3
- package/dist/src/sdk-batch.js +2 -0
- package/dist/src/sdk-contracts.d.ts +222 -99
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-device.js +1 -1
- package/dist/src/sdk-finders.d.ts +1 -1
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-io.js +1 -1
- package/dist/src/sdk-remote-config.d.ts +1 -1
- package/dist/src/sdk-remote-config.js +1 -1
- package/dist/src/sdk-selectors.d.ts +539 -199
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/selection.js +1 -0
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/semantic-index.js +1 -0
- package/dist/src/server.js +10 -3
- package/dist/src/session-allocation.js +1 -0
- package/dist/src/session-artifact-paths.js +1 -0
- package/dist/src/session-paths.js +1 -0
- package/dist/src/session-repair-tombstone.js +1 -0
- package/dist/src/session-routing.js +1 -0
- package/dist/src/session-runtime-admission.js +1 -0
- package/dist/src/session-snapshot.js +1 -0
- package/dist/src/session-store.js +4 -0
- package/dist/src/session-target-evidence.js +1 -1
- package/dist/src/session2.js +5 -28
- package/dist/src/settings.js +1 -0
- package/dist/src/shared.js +2 -2
- package/dist/src/simctl-facade.js +1 -0
- package/dist/src/simctl.js +1 -1
- package/dist/src/simulator-facade.js +1 -0
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-capture-annotations.js +1 -0
- package/dist/src/snapshot-desktop-projection.js +1 -0
- package/dist/src/snapshot-diagnostics.js +1 -0
- package/dist/src/snapshot-process.js +1 -0
- package/dist/src/snapshot-quality-backend-capabilities.js +1 -0
- package/dist/src/snapshot-quality-verdict.js +1 -0
- package/dist/src/snapshot-runtime-binding.js +1 -0
- package/dist/src/snapshot-runtime.js +1 -1
- package/dist/src/snapshot-scope.js +1 -0
- package/dist/src/snapshot-state.js +1 -0
- package/dist/src/snapshot.js +1 -8
- package/dist/src/snapshot2.js +1 -1
- package/dist/src/snapshot3.js +1 -1
- package/dist/src/snapshot4.js +1 -0
- package/dist/src/src.js +1 -1
- package/dist/src/src2.js +1 -1
- package/dist/src/src3.js +1 -2
- package/dist/src/src4.js +1 -0
- package/dist/src/src5.js +1 -0
- package/dist/src/src6.js +1 -0
- package/dist/src/src7.js +2 -0
- package/dist/src/src8.js +115 -0
- package/dist/src/startup-recovery-fence.js +1 -0
- package/dist/src/status-markers.js +1 -0
- package/dist/src/string-enum.js +1 -1
- package/dist/src/success-text.js +1 -0
- package/dist/src/surface-snapshot.js +1 -0
- package/dist/src/surface-snapshot2.js +1 -0
- package/dist/src/takeover.js +5 -0
- package/dist/src/tool-provider-facade.js +1 -0
- package/dist/src/tool-provider.js +4 -3
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/tool-provider3.js +1 -0
- package/dist/src/toolchain-probe.js +2 -0
- package/dist/src/touch-runtime.js +1 -0
- package/dist/src/transport.js +3 -0
- package/dist/src/tree.js +1 -0
- package/dist/src/ttl-memo.js +1 -0
- package/dist/src/tv-remote.js +1 -0
- package/dist/src/type-text-runtime.js +1 -0
- package/dist/src/undici.js +99 -0
- package/dist/src/update-check.js +1 -1
- package/dist/src/verified-file.js +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/video.js +2 -2
- package/dist/src/web.js +2 -1
- package/dist/src/web2.js +1 -0
- package/dist/src/webdriver-ios-snapshot.js +1 -0
- package/dist/src/webdriver-source.js +1 -0
- package/linux/atspi-dump.py +54 -9
- package/package.json +73 -38
- package/server.json +9 -3
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.9.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.9.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.9.apk.sha256 +0 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CoordinateTextEntryTests.swift +0 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+FlatSnapshotFiltering.swift +0 -75
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+LifecycleCacheTests.swift +0 -6
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+RecordingTests.swift +0 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SelectorMatchPolicyTests.swift +0 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTraversalIdentityTests.swift +0 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryPolicyTests.swift +0 -4
- package/dist/src/appearance.js +0 -1
- package/dist/src/apps.js +0 -5
- package/dist/src/audio-probe.js +0 -1
- package/dist/src/cancel.js +0 -1
- package/dist/src/cli-grammar.js +0 -1
- package/dist/src/command-catalog.js +0 -1
- package/dist/src/debug-symbols.js +0 -5
- package/dist/src/device-input-state.js +0 -2
- package/dist/src/device-ready.js +0 -1
- package/dist/src/dispatch.js +0 -1
- package/dist/src/handler-utils.js +0 -1
- package/dist/src/helper-package-install.js +0 -1
- package/dist/src/host-process.js +0 -3
- package/dist/src/ime-lifecycle.js +0 -2
- package/dist/src/ime-recovery-marker.js +0 -1
- package/dist/src/input-actions3.js +0 -1
- package/dist/src/install-artifact.js +0 -1
- package/dist/src/install-artifact2.js +0 -1
- package/dist/src/interaction-common.js +0 -1
- package/dist/src/interaction-runtime.js +0 -1
- package/dist/src/interaction-snapshot.js +0 -1
- package/dist/src/manifest.js +0 -1
- package/dist/src/method-scope.js +0 -1
- package/dist/src/png-resize.js +0 -1
- package/dist/src/process-lock.js +0 -1
- package/dist/src/runner-lease.js +0 -1
- package/dist/src/runner-sequence.js +0 -1
- package/dist/src/screenshot-geometry.js +0 -1
- package/dist/src/sdk-android-adb.d.ts +0 -245
- package/dist/src/sdk-android-adb.js +0 -4
- package/dist/src/sdk.js +0 -1
- package/dist/src/setting-state.js +0 -1
- package/dist/src/shell-quote.js +0 -1
- package/dist/src/snapshot-session.js +0 -1
- package/dist/src/timing-safe-equal.js +0 -1
- package/dist/src/unsupported-interactor.js +0 -1
- package/dist/src/verdict.js +0 -1
- /package/dist/src/{recording-telemetry.js → telemetry.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{yn as e}from"./sdk-batch.js";function t(t,n,r){return e(typeof t==`string`?t:t.raw,n,r)}export{t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fr as e,Tr as t,xr as n}from"./sdk-batch.js";import{r}from"./mobile-snapshot-semantics.js";function i(e,t,n={}){let i=a(e);if(i.length===0)return{canScroll:!1,emptySnapshot:!0};let s=r(i),c=o(i,s,t,n);return c?{canScroll:d(c,s.get(c.index),t),emptySnapshot:!1,scope:f(c,i)}:{canScroll:!1,emptySnapshot:!1}}function a(e){return e.map((e,t)=>({...e,ref:`ref`in e&&e.ref?e.ref:`e${t+1}`}))}function o(t,r,i,a){let o=n(t),d=t.filter(t=>e(t)&&v(t.rect));if(d.length===0)return null;let f=u(a.nodeIndex,o.nodeByIndex);if(f)return f;let p=a.point;if(p)return c(d,r,i,p)||s(d,r,i,o);let m=l(t);if(m){let e=c(d,r,i,m);if(e)return e}return s(d,r,i,o)}function s(e,t,n,r){let i=e.filter(e=>d(e,t.get(e.index),n)).sort((e,t)=>h(t,e));return i.length>0?i[0]??null:e.filter(r.isVisibleInEffectiveViewport).sort((e,t)=>h(t,e))[0]??e.sort((e,t)=>h(t,e))[0]??null}function c(e,t,n,r){let i=e.filter(e=>e.rect&&_(e.rect,r)).sort(h);return i.find(e=>d(e,t.get(e.index),n))??i[0]??null}function l(e){let n=e.filter(e=>t(e)&&v(e.rect)).sort((e,t)=>h(t,e))[0]?.rect;if(n)return{x:n.x+n.width/2,y:n.y+n.height/2}}function u(t,n){if(t===void 0)return null;let r=n.get(t);for(;r;){if(e(r)&&v(r.rect))return r;r=r.parentIndex===void 0?void 0:n.get(r.parentIndex)}return null}function d(e,t,n){return n===`bottom`?e.hiddenContentBelow===!0||t?.hiddenContentBelow===!0:e.hiddenContentAbove===!0||t?.hiddenContentAbove===!0}function f(e,t){return[e.identifier,e.label].filter(e=>typeof e==`string`).map(e=>e.trim()).find(n=>m(n)&&p(n,e,t))}function p(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 m(e){return e.length>0&&e.length<=80&&!/^(true|false)$/i.test(e)&&!/^\d+$/.test(e)&&!/^\d+%$/.test(e)}function h(e,t){return g(e.rect)-g(t.rect)}function g(e){return e?e.width*e.height:0}function _(e,t){return t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height}function v(e){return!!(e&&e.width>0&&e.height>0)}export{i as analyzeScrollEdgeState};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,_ as t,h as n,l as r,m as i,s as a,v as o}from"./sdk-contracts.js";import{Gn as s,Hn as c,Jt as l,Pt as u,Un as d,Ut as f,Wn as p,fn as m,hr as ee,mn as te,qn as ne}from"./sdk-batch-runner.js";import{_ as re,c as h,l as ie,s as ae}from"./sdk-device.js";import{Q as oe,R as se,bt as ce,c as g,yt as le}from"./prepare-kind.js";import{t as ue}from"./interaction.js";import{X as _,j as de}from"./screenshot-result.js";import{i as fe}from"./session-target-evidence.js";import{t as pe}from"./verdict.js";import{a as me,t as he}from"./runtime.js";import{A as ge}from"./sdk-android-adb.js";import{r as _e}from"./app-lifecycle.js";import{a as v}from"./snapshot.js";import{i as ve}from"./cancel.js";import{o as y}from"./interactors.js";import{a as b,o as ye,p as be,s as x,t as xe}from"./dispatch.js";import{n as S}from"./runner-client.js";import{At as C,Et as Se,Gt as Ce,Ht as w,Kt as T,Ot as we,Rt as E,kt as D}from"./internal/daemon.js";import{a as Te,i as Ee,r as De}from"./snapshot-session.js";import{t as Oe}from"./device-ready.js";import{t as ke}from"./backend-snapshot-options.js";const Ae=[[`snapshotDepth`,`--depth`],[`snapshotScope`,`--scope`],[`snapshotRaw`,`--raw`]];function O(e,t){let n=je(t);return n.length===0?null:b(`INVALID_ARGS`,`${e} @ref does not support ${n.join(`, `)}.`)}function je(e){if(!e)return[];let t=[];for(let[n,r]of Ae)e[n]!==void 0&&t.push(r);return t}function Me(e,t){if(!t||t.settle===!0)return null;let n=[];return t.settleQuietMs!==void 0&&n.push(`--settle-quiet`),n.length===0?null:b(`INVALID_ARGS`,`${e}: ${n.join(`, `)} require${n.length===1?`s`:``} --settle.`)}function Ne(e){if(e?.settle===!0)return{...e.settleQuietMs===void 0?{}:{quietMs:e.settleQuietMs},...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs}}}function k(e){if(e.length<2)return null;let t=Number(e[0]),n=Number(e[1]);return!Number.isFinite(t)||!Number.isFinite(n)?null:{x:t,y:n}}function A(e){let t=n(e);return t?{ok:!0,ref:t.base,generation:t.generation}:{ok:!1,response:b(`INVALID_ARGS`,`Invalid ref "${e}" — malformed generation suffix.`,{hint:a})}}function j(e,t){let n=k(e);if(n)return{ok:!0,target:{kind:`point`,x:n.x,y:n.y}};let r=e[0]??``;if(r.startsWith(`@`)){let t=A(r);return t.ok?{ok:!0,target:{kind:`ref`,ref:t.ref,fallbackLabel:e.slice(1).join(` `).trim()},refGeneration:t.generation}:{ok:!1,response:t.response}}let i=e.join(` `).trim();return i?{ok:!0,target:{kind:`selector`,selector:i}}:{ok:!1,response:b(`INVALID_ARGS`,`${t} requires @ref, selector expression, or x y coordinates`)}}function Pe(e){let t=k(e);if(t)return{ok:!0,target:{kind:`point`,x:t.x,y:t.y},...Ve(e[2])};let n=Be(e),r=j(n.targetPositionals,`longpress`);return r.ok?{ok:!0,target:r.target,refGeneration:r.refGeneration,...n.duration}:r}function Fe(e){let t=e[0]??``;if(t.startsWith(`@`)){let n=A(t);if(!n.ok)return{ok:!1,response:n.response};let r=g(e).text;return r?{ok:!0,target:{kind:`ref`,ref:n.ref,fallbackLabel:ze(e)},refGeneration:n.generation,text:r}:{ok:!1,response:b(`INVALID_ARGS`,`fill requires text after ref`)}}let n=k(e);if(n){let t=e.slice(2).join(` `);return t?{ok:!0,target:{kind:`point`,x:n.x,y:n.y},text:t}:{ok:!1,response:b(`INVALID_ARGS`,`fill requires text after coordinates`)}}let r=Ie(e);return!r||r.kind!==`selector`?{ok:!1,response:b(`INVALID_ARGS`,`fill requires x y text, @ref text, or selector text`)}:r.text.trim()?{ok:!0,target:{kind:`selector`,selector:r.target.selector},text:r.text}:{ok:!1,response:b(`INVALID_ARGS`,`fill requires text after selector`)}}function Ie(e){try{return g(e)}catch{return null}}function Le(e){let t=`evidence`in e?e.evidence:void 0,n=e.settle;return e.kind===`ref`?{ref:M(e.target?.kind===`ref`?e.target.ref:void 0),refLabel:e.refLabel,selectorChain:e.selectorChain,targetHittable:e.targetHittable,hint:e.hint,evidence:t,settle:n,resolution:e.resolution}:e.kind===`selector`?{selector:e.target?.kind===`selector`?e.target.selector:void 0,selectorChain:e.selectorChain,refLabel:e.refLabel,targetHittable:e.targetHittable,hint:e.hint,evidence:t,settle:n,resolution:e.resolution}:{evidence:t,settle:n}}function Re(e,t){return e.kind===`point`?`coordinate tap`:t.kind===`ref`&&t.target?.kind===`ref`?t.target.ref:t.kind===`selector`&&t.target?.kind===`selector`?t.target.selector:`target`}function M(e){return e?.startsWith(`@`)?e.slice(1):e}function ze(e){return e.length>=3&&e[1]?.trim()||``}function Be(e){let t=e.at(-1);return e.length>1&&He(t)?{targetPositionals:e.slice(0,-1),duration:{durationMs:Number(t)}}:{targetPositionals:e,duration:{}}}function Ve(e){return e===void 0?{}:{durationMs:Number(e)}}function He(e){return e===void 0||e.trim()===``?!1:Number.isFinite(Number(e))}function N(e){let{req:t,logPath:n,traceLogPath:r}=e;return{verbose:t.flags?.verbose,logPath:n,traceLogPath:r,requestId:t.meta?.requestId,iosXctestrunFile:t.flags?.iosXctestrunFile,iosXctestDerivedDataPath:t.flags?.iosXctestDerivedDataPath,iosXctestEnvDir:t.flags?.iosXctestEnvDir}}function P(e,t){return!(!e||!h(e.device)||y(e.device)||t.skipPendingPostGestureStabilization&&w(e))}function F(e){let{session:t,selectorExpression:n}=e;return P(t,{skipPendingPostGestureStabilization:!0})?l(n):null}function Ue(e){let t=e.identifier?.trim();if(t)return{key:`id`,value:t};let n=e.label?.trim();return n?{key:`label`,value:n}:null}function I(e,t={}){let n=o(e);if(n.code===`ELEMENT_NOT_FOUND`)return t.delegateSemanticFailures===!0||t.allowElementNotFound===!0;if(n.code===`AMBIGUOUS_MATCH`)return t.delegateSemanticFailures===!0;if(n.code===`ELEMENT_OFFSCREEN`)return t.delegateSemanticFailures!==!1;if(n.code!==`COMMAND_FAILED`)return!1;let r=n.message.toLowerCase();return r.includes(`fetch failed`)||r.includes(`timed out`)||r.includes(`timeout`)||r.includes(`runner did not accept connection`)||r.includes(`invalid runner response`)}async function We(e,n){let r=await L(e);if(r){if(v(r.foregroundPackage))return`press ${n} opened an Android permission dialog (${r.foregroundPackage}) over ${r.expectedPackage}. ${r.hint}`;throw new t(`COMMAND_FAILED`,`press ${n} left ${e.appBundleId} and foregrounded ${r.foregroundPackage}. The tap likely escaped the app.`,r)}}async function L(e){if(e.device.platform!==`android`||!e.appBundleId)return null;let t=await _e(e.device),n=t.package?.trim();return!n||n===e.appBundleId||!Je(n)?null:{expectedPackage:e.appBundleId,foregroundPackage:n,activity:t.activity,hint:qe(n)}}function Ge(e){return v(e.foregroundPackage)?`Android permission dialog is blocking ${e.expectedPackage}`:`${e.foregroundPackage} is foreground instead of ${e.expectedPackage}`}function Ke(e){return e.code===`COMMAND_FAILED`&&typeof e.details?.expectedPackage==`string`&&typeof e.details?.foregroundPackage==`string`}function qe(e){return v(e)?`Use "alert get" to inspect it, then "alert accept" or "alert dismiss" to respond.`:`Use screenshot as visual truth, then take a fresh snapshot -i before retrying.`}function Je(e){return e===`com.android.settings`||e===`com.android.systemui`||v(e)||e.includes(`launcher`)}function Ye(e,t){if(t===`exists`)return{found:!0};if(t===`wait`)return{found:!0,waitedMs:e.waitedMs};if(t===`list`)return{action:`list`,matches:Array.isArray(e.matches)?e.matches.length:0};let n=typeof e.ref==`string`?e.ref:void 0;return t===`get_attrs`?{ref:n,action:`get attrs`}:{ref:n,action:`get text`,text:typeof e.text==`string`?e.text:``}}function Xe(e){return e.kind===`found`?{found:!0,...typeof e.waitedMs==`number`?{waitedMs:e.waitedMs}:{}}:e.kind===`list`?{matches:e.matches.map(e=>({ref:e.ref,node:u(e.node)}))}:{ref:e.ref,...e.kind===`text`?{text:e.text}:{},node:u(e.node)}}function Ze(e,t){let n=Array.isArray(e.selectorChain)?e.selectorChain:void 0,r=et(e),i=r?.kind===`ref`?H(r.ref):void 0,a=r?.kind===`selector`?r.selector:void 0,o={...i?{ref:i}:{},...a?{selector:a}:{},...n?{selectorChain:n}:{}};if(t===`attrs`)return o;let s=typeof e.text==`string`?e.text:``;return{...o,text:s,refLabel:$e(s)}}function R(e){let{target:t}=e;return{...t.kind===`ref`?{ref:H(t.ref)}:{},...t.kind===`selector`?{selector:t.selector}:{},...typeof e.text==`string`?{text:e.text}:{},node:u(e.node)}}function z(e){let{node:t,preActionNodes:n,...r}=e;return r}function Qe(e){return{waitedMs:e.waitedMs,...typeof e.text==`string`?{text:e.text}:{},...typeof e.selector==`string`?{selector:e.selector}:{},...typeof e.captures==`number`?{captures:e.captures}:{},...typeof e.nodeCount==`number`?{nodeCount:e.nodeCount}:{},...typeof e.hint==`string`?{hint:e.hint}:{}}}function B(e){let{selectorChain:t,...n}=e;return n}function V(e,t,n,r,i,a){let o=e.get(t);if(!o)return;let s=_(o)&&i?fe(i,{mode:a}):void 0;e.recordAction(o,{command:n.command,positionals:n.positionals??[],flags:n.flags??{},result:r,interactiveObservation:de(n),...s?{targetEvidence:s}:{}})}function $e(e){let t=e.trim();if(!(!t||t.length>80||/[\r\n]/.test(t)))return t}function et(e){let t=e.target;if(!t||typeof t!=`object`)return;let n=t;if(n.kind===`ref`&&typeof n.ref==`string`)return{kind:`ref`,ref:n.ref};if(n.kind===`selector`&&typeof n.selector==`string`)return{kind:`selector`,selector:n.selector}}function H(e){return e.startsWith(`@`)?e.slice(1):e}const tt=[`application`,`window`,`tabbar`,`scrollbar`,`image`],nt=new Set([`tab bar`]);async function U(e,t){if(t.ok||!rt(t.error.details?.reason)||t.error.details?.captureStalled===!0||t.error.details?.captureTruncated===!0)return t;let n=await it(e).catch(()=>null);return n?b(t.error.code,`${t.error.message}. Current surface: ${n.summary}.`,{...t.error.details??{},currentSurface:n.details}):t}function rt(e){return e===ue.targetAbsent||e===ue.stableTimeout}async function it(e){let t=[...(await E({device:e.device,session:e.session,flags:{...e.req.flags,snapshotInteractiveOnly:!0},logPath:e.logPath??``})).snapshot.nodes].sort(at),n=W(t,6,{includeIdentifiers:!0});if(n.length===0)return null;let r=W(t.filter(e=>!lt(e)),4,{includeIdentifiers:!1}),i=W(t.filter(ut),4,{includeIdentifiers:!0});return{summary:(r.length>0?r:n.slice(0,4)).join(`, `),details:{labels:n,...i.length>0?{buttons:i}:{}}}}function W(e,t,n){let r=new Set,i=[];for(let a of e){let e=ct(a,n);if(!(!e||r.has(e))&&(r.add(e),i.push(e),i.length>=t))break}return i}function at(e,t){return ot(e)-ot(t)||st(e,t)}function ot(e){let t=!!ct(e,{includeIdentifiers:!1});return(lt(e)?2:0)+ +!t}function st(e,t){return e.rect&&t.rect?e.rect.y-t.rect.y||e.rect.x-t.rect.x:e.rect?-1:t.rect?1:(e.depth??0)-(t.depth??0)||e.index-t.index}function ct(e,t){let n=(t.includeIdentifiers?[e.label,e.value,e.identifier]:[e.label,e.value]).map(e=>typeof e==`string`?e.trim():``).find(e=>e.length>0);return n?n.replace(/\s+/g,` `).slice(0,80):``}function lt(e){let t=ee(`${e.type??``} ${e.role??``} ${e.subrole??``}`),n=`${e.label??``} ${e.value??``}`.trim().toLowerCase();return tt.some(e=>t.includes(e))||nt.has(n)||n.endsWith(`.fill`)}function ut(e){return ee(`${e.type??``} ${e.role??``} ${e.subrole??``}`).includes(`button`)}function G(e,t){let n=me(t);if(!n)return e;if(e.ok){let t=dt(e.data?.warning,n);return{...e,data:{...e.data,warning:t}}}let r=e.error.details??{};return{...e,error:{...e.error,details:{...r,hint:dt(r.hint,n)}}}}function dt(e,t){return typeof e==`string`&&e.trim()!==``?`${e}\n${t}`:t}async function ft(e){let{device:t,node:n,flags:r,appBundleId:i,traceOutPath:a,surface:o,contextFromFlags:s}=e,c=le(n),l=oe(n.rect);if(!l||h(t)&&c&&!ce(n.type??``))return c;try{let e=await xe(t,`read`,[String(l.x),String(l.y)],void 0,{...s(r,i,a),surface:o}),u=e&&typeof e==`object`?e:void 0,d=typeof u?.text==`string`?u.text:``;return d.trim()?d:(ge({level:`warn`,phase:`interaction_read_fallback`,data:{reason:`empty_backend_text`,nodeRef:n.ref,surface:o,platform:t.platform}}),c)}catch(e){return ge({level:`warn`,phase:`interaction_read_fallback`,data:{reason:`backend_read_failed`,nodeRef:n.ref,surface:o,platform:t.platform,error:e instanceof Error?e.message:String(e)}}),c}}function K(e){let{session:t,sessionStore:n,sessionName:r}=e,i=0,a,o,s=t=>(e.consumedSnapshot&&(e.consumedSnapshot.state=t.snapshot),t);return{capture:async c=>{let l=Date.now(),u=St(c,e.req.flags?.out),d=gt({timestamp:l,lastSnapshotAt:i,lastSnapshotResult:a,lastSnapshotCacheKey:o,session:t,request:c,cacheKey:u});if(d)return s(d);let f=_t({session:t,timestamp:l,request:c});if(f)return i=f.createdAt,a={snapshot:f},o=u,s(a);let p=await pt({params:e,request:c});c.signal?.throwIfAborted();let m={snapshot:p};return wt({session:t,sessionStore:n,sessionName:r,snapshot:p}),i=l,a=m,o=u,s(m)}}}async function pt(e){let{params:t,request:n}=e,r=await q(t,n,n.snapshotScope);return n.recovery?.legacyIosSparse&&Tt(r)?await mt({runtimeParams:t,request:n,policy:n.recovery.legacyIosSparse}):n.recovery?.sparseVerdictQueryScope?.shouldScope&&pe(r.snapshotQuality)?await ht({runtimeParams:t,request:n,policy:n.recovery.sparseVerdictQueryScope,snapshot:r}):r}async function mt(e){let{runtimeParams:t,request:n,policy:r}=e;try{return await q(t,n,void 0,!1)}catch(e){if(!r.shouldScope)throw e;return await q(t,n,r.query,!1)}}async function ht(e){let{runtimeParams:t,request:n,policy:r,snapshot:i}=e;try{return await q(t,n,r.query,!1)}catch{return i}}async function q(e,t,n,r=t.flags?.snapshotInteractiveOnly){return(await E({device:e.device,session:e.session,flags:{...t.flags,snapshotInteractiveOnly:r},outPath:t.outPath??e.req.flags?.out,logPath:e.logPath??``,snapshotScope:n,includeRects:t.includeRects,signal:t.signal})).snapshot}function gt(e){let{timestamp:t,lastSnapshotAt:n,lastSnapshotResult:r,lastSnapshotCacheKey:i,session:a,request:o,cacheKey:s}=e;if(o.cache?.forceFresh!==!0&&r&&i===s&&!(t-n>=750)&&!T(a)&&!bt(a,o))return r}function _t(e){let{session:t,timestamp:n,request:r}=e,i=t?.snapshot;if(i&&vt(t,r)&&yt(i,n)&&i.presentationKey===xt(r))return i}function vt(e,t){return!(t.cache?.forceFresh===!0||t.cache?.useSessionSnapshot!==!0||T(e)||bt(e,t))}function yt(e,t){return t-e.createdAt<750}function bt(e,t){return t.cache?.bypassForPostGestureStabilization===!0&&w(e)}function xt(e){return r(i(Ct(e)))}function St(e,t){return JSON.stringify({presentationKey:xt(e),includeRects:e.includeRects===!0,outPath:e.outPath??t??null})}function Ct(e){return e.snapshotScope===void 0?e.flags:{...e.flags,snapshotScope:e.snapshotScope}}function wt(e){let{session:t,sessionStore:n,sessionName:r,snapshot:i}=e;!t||pe(i.snapshotQuality)||(C(t,i),n.set(r,t))}function Tt(e){return e.snapshotQuality||e.backend!==`xctest`||e.nodes.length!==1?!1:e.nodes[0]?.type===`Application`}function Et(e){return he({backend:Dt(e),...Te(`selector commands`,{plural:!0}),sessions:Se({sessionName:e.sessionName,getSession:()=>e.session,recordOptions:{includeSnapshot:!0},setRecord:t=>{!e.session||!t.snapshot||(C(e.session,t.snapshot),e.sessionStore.set(e.sessionName,e.session))}}),signal:e.signal??ve(e.req.meta?.requestId)})}async function J(e,t){e.consumedSnapshot??={};let n=e.sessionStore.get(e.sessionName);if(!n&&t.requireSession)return{ok:!1,response:ye()};let r=n?.device??await be(e.req.flags??{});n||await Oe(r);let i=x(t.capability,r);return i?{ok:!1,response:i}:{ok:!0,runtime:Et({...e,session:n,device:r})}}function Dt(e){let{req:t,session:n,device:r,logPath:i,sessionName:a,sessionStore:o}=e,s=K({device:r,session:n,sessionStore:o,sessionName:a,req:t,consumedSnapshot:e.consumedSnapshot,logPath:i});return{platform:re(r),captureSnapshot:async(e,n)=>{let i={...t.flags,...ke(n)},a=n?.includeRects===!0,o=n?.scope??t.flags?.snapshotScope,c=t.command===`wait`||t.command===`find`||a&&r.platform===`web`;return await s.capture({flags:i,signal:e.signal,snapshotScope:o,includeRects:a,cache:{forceFresh:c,useSessionSnapshot:!0,bypassForPostGestureStabilization:!0}})},readText:async(a,o)=>({text:await ft({device:r,node:o,flags:t.flags,appBundleId:n?.appBundleId,traceOutPath:n?.trace?.outPath,surface:n?.surface,contextFromFlags:e.contextFromFlags??((e,t,n)=>Ce(i??``,e,t,n))})}),findText:async(t,n)=>({found:await Ot(e,n,t.signal)})}}async function Ot(e,t,n){let r=await kt(e,t,n);return r===null?await At(e,t,n)===!0?!0:await Nt(e,t,n):r}async function kt(e,t,n){return!ie(e.device)||!e.session?.surface||e.session.surface===`app`?null:await Nt(e,t,n)}async function At(e,t,n){let r=jt(e);return r?(await S(r.device,{command:`findText`,text:t,appBundleId:r.appBundleId},{...Mt(e,r),signal:n}))?.found===!0:null}function jt(e){return!ae(e.device.platform)||y(e.device)||!e.session?.appBundleId?null:{device:e.device,appBundleId:e.session.appBundleId,traceLogPath:e.session.trace?.outPath}}function Mt(e,t){return N({req:e.req,logPath:e.logPath,traceLogPath:t.traceLogPath})}async function Nt(e,t,n){return!!se((await Pt(e,n)).nodes,t)}async function Pt(e,t){let{snapshot:n}=await K({device:e.device,session:e.session,sessionStore:e.sessionStore,sessionName:e.sessionName,req:e.req,logPath:e.logPath,consumedSnapshot:e.consumedSnapshot}).capture({flags:{...e.req.flags,snapshotInteractiveOnly:!1,snapshotIncludeHiddenContentHints:!1},signal:t,cache:{forceFresh:!0,bypassForPostGestureStabilization:!0}});return n}async function Ft(e){let{req:t}=e;if(t.command!==`find`)return null;let n=m(t.positionals??[],t.flags);if(!n.ok)return b(n.code,n.message);let r=n.parsed,i=r.action;if(!te(i))return null;let a=await J(e,{requireSession:!1,capability:`find`});return a.ok?G(await Q(async()=>{let n=await a.runtime.selectors.find({session:e.sessionName,requestId:t.meta?.requestId,locator:r.locator,query:r.query,action:i,timeoutMs:r.timeoutMs});V(e.sessionStore,e.sessionName,t,Ye(n,i));let o=Xe(n),s=typeof o.ref==`string`?[o.ref]:Array.isArray(o.matches)?o.matches.map(e=>e.ref).filter(e=>typeof e==`string`):[];if(s.length>0){let t=e.sessionStore.get(e.sessionName);if(t&&(we(t,s),e.sessionStore.set(e.sessionName,t),t.snapshotGeneration!==void 0))return{...o,refsGeneration:t.snapshotGeneration}}return o}),Y(e)):a.response}function Y(e){return e.consumedSnapshot?.state??e.sessionStore.get(e.sessionName)?.snapshot}async function It(e){let{req:t}=e;if(t.command!==`get`)return null;let n=d(t.positionals?.[0]);if(!n.ok)return b(n.code,n.message);let r=n.format,i=Yt(t);if(!i.ok)return i.response;if(i.target.kind===`ref`){let e=O(`get`,t.flags);if(e)return e}let a=t.internal?.replayTargetGuard;if(i.target.kind===`selector`&&!a){let t=await Vt(e,r,i.target.selector);if(t)return t}let o=await J(e,{requireSession:!0,capability:`get`});if(!o.ok)return o.response;let s=i.target.kind===`ref`?D({session:e.sessionStore.get(e.sessionName),ref:i.target.ref,mintedGeneration:i.refGeneration}):void 0;return G(await Q(async()=>{let n=await o.runtime.selectors.get({session:e.sessionName,requestId:t.meta?.requestId,property:r,target:i.target,expectedResolvedTarget:a});V(e.sessionStore,e.sessionName,t,Ze(n,r),{node:n.node,preActionNodes:n.preActionNodes});let c=R(n);return s?{...c,warning:s}:c}),Y(e))}async function Lt(e){let{req:t}=e;if(t.command!==`is`)return null;let n=p(t.positionals??[]);if(!n.ok)return b(n.code,n.message,n.hint?{hint:n.hint}:void 0);let{predicate:r,expectedText:i}=n,a={selectorExpression:n.selectorExpression},o=t.internal?.replayTargetGuard,s=_(e.sessionStore.get(e.sessionName));if(!o&&!s){let t=await Ht(e,r,a.selectorExpression,i);if(t)return t}let c=await J(e,{requireSession:!0,capability:`is`});return c.ok?G(await $(e,await Q(async()=>{let n=await c.runtime.selectors.is({session:e.sessionName,requestId:t.meta?.requestId,predicate:r,selector:a.selectorExpression,expectedText:i,expectedResolvedTarget:o}),s=zt(n),l=z(n);return V(e.sessionStore,e.sessionName,t,l,s),B(l)}),`is ${r}`),Y(e)):c.response}async function Rt(e){let{req:t,sessionName:n,sessionStore:r}=e,i=f(t.positionals??[]);if(!i)return b(`INVALID_ARGS`,`wait requires a duration or text`);let{session:a,device:o}=await De(r,n,t.flags);if(i.kind!==`sleep`){let e=x(`wait`,o);if(e)return e}let s=t.internal?.replayLandmarkGuard;if(i.kind===`selector`&&!s&&!_(a)){let t=await Ut({...e,session:a,device:o,selectorExpression:i.selectorExpression,timeoutMs:i.timeoutMs});if(t)return t}let c=i,l;if(i.kind===`ref`){let e=A(i.rawRef);if(!e.ok)return e.response;c={...i,rawRef:e.ref},l=D({session:a,ref:e.ref,mintedGeneration:e.generation})}e.consumedSnapshot??={};let u=async()=>{let i=Et({...e,session:a,device:o}),u=await Q(async()=>{let e=await i.selectors.wait({session:n,requestId:t.meta?.requestId,target:Xt(c,a,s)}),o=zt(e);V(r,n,t,z(e),o,`landmark`);let u=Qe(e);return l?{...u,warning:l}:u});return await $(e,await U({req:t,logPath:e.logPath,session:a,device:o},u),`wait`)};return i.kind===`sleep`?await u():G(await Ee(a,o,u),Y(e))}function zt(e){let t=e.node,n=e.preActionNodes;if(!(!t||typeof t!=`object`||!Array.isArray(n)))return{node:t,preActionNodes:n}}function Bt(e,t,n){if(!e||_(e))return null;let r=F({session:e,selectorExpression:n});return t===`text`&&r?.key!==`id`?null:r}async function Vt(e,t,n){let r=e.sessionStore.get(e.sessionName),i=Bt(r,t,n);if(!r||!i)return null;let a=await X(e,r,i);if(Z(a))return a.response;if(!a)return null;let o=Kt(t,i.raw,a);return o?(V(e.sessionStore,e.sessionName,e.req,Ze(o,t)),{ok:!0,data:R(o)}):null}async function Ht(e,t,n,r){if(t===`hidden`)return null;let i=await Wt(e,n);if(Z(i))return i.response;if(!i?.result.found||!i.result.node)return null;let a=t===`exists`?{predicate:t,pass:!0,selector:i.selector.raw,matches:1,selectorChain:[i.selector.raw]}:qt(t,r,i.selector.raw,i.session,i.result.node);return a?(V(e.sessionStore,e.sessionName,e.req,a),{ok:!0,data:B(a)}):null}async function Ut(e){let t=F({session:e.session,selectorExpression:e.selectorExpression});if(!e.session||!t)return null;let n=Date.now(),r=await X(e,e.session,t);if(Z(r))return r.response;if(!r?.found)return null;let i={kind:`selector`,selector:t.raw,waitedMs:Date.now()-n,selectorChain:[t.raw]};V(e.sessionStore,e.sessionName,e.req,i);let a={ok:!0,data:B(i)};return await U({req:e.req,logPath:e.logPath,session:e.session,device:e.device},a)}async function Wt(e,t){let n=e.sessionStore.get(e.sessionName),r=F({session:n,selectorExpression:t});if(!n||!r)return null;let i=await X(e,n,r);return Z(i)?i:i?{session:n,selector:r,result:i}:null}async function Gt(e,t,n){let r=await S(e.device,{command:`querySelector`,selectorKey:t.key,selectorValue:t.value,appBundleId:e.appBundleId},n),i=r.found===!0,a=Jt(r);return{found:i,...typeof r.text==`string`?{text:r.text}:{},...a?{node:a}:{}}}async function X(t,n,r){try{return await Gt(n,r,N({req:t.req,logPath:t.logPath,traceLogPath:n.trace?.outPath}))}catch(t){return I(t,{allowElementNotFound:!0})?null:{kind:`error`,response:{ok:!1,error:e(t)}}}}function Z(e){return e!==null&&`kind`in e&&e.kind===`error`}function Kt(e,t,n){if(!n.found||!n.node)return null;let r={target:{kind:`selector`,selector:t},node:n.node,selectorChain:[t]};return e===`attrs`?{kind:`attrs`,...r}:typeof n.text==`string`?{kind:`text`,...r,text:n.text}:null}function qt(e,t,n,r,i){let a=ne({predicate:e,node:i,nodes:[i],expectedText:t,platform:r.device.platform});return{predicate:e,pass:a.pass,selector:n,...e===`text`?{text:a.actualText}:{},selectorChain:[n]}}function Jt(e){let t=e.nodes;if(!Array.isArray(t))return;let n=t[0];if(!(!n||typeof n!=`object`))return n}function Yt(e){let t=e.positionals?.[1]??``;if(t.startsWith(`@`)){let n=A(t);return n.ok?{ok:!0,target:{kind:`ref`,ref:n.ref,fallbackLabel:e.positionals.length>2?e.positionals.slice(2).join(` `).trim():``},refGeneration:n.generation}:{ok:!1,response:n.response}}let n=c(e.positionals?.slice(1)??[]);return n.ok?{ok:!0,target:{kind:`selector`,selector:`selector`in n?n.selector:``}}:{ok:!1,response:b(n.code,n.message)}}function Xt(e,n,r){if(e.kind===`sleep`)return{kind:`sleep`,durationMs:e.durationMs};if(e.kind===`selector`)return{kind:`selector`,selector:e.selectorExpression,timeoutMs:e.timeoutMs,...r?{recordedLandmark:r}:{}};if(e.kind===`ref`){if(!n?.snapshot)throw new t(`INVALID_ARGS`,`Ref wait requires an existing snapshot in session.`);return{kind:`ref`,ref:e.rawRef,timeoutMs:e.timeoutMs}}if(e.kind===`stable`)return{kind:`stable`,quietMs:e.quietMs,timeoutMs:e.timeoutMs};let i=s(e.text);if(!i.ok)throw new t(i.code,i.message);return{kind:`text`,text:i.text,timeoutMs:e.timeoutMs}}async function Q(e){try{return{ok:!0,data:await e()}}catch(e){let t=o(e);return b(t.code,t.message,t.details)}}async function $(e,t,n){if(t.ok)return t;let r=e.sessionStore.get(e.sessionName);if(!r)return t;let i;try{i=await L(r)}catch{return t}return i?b(t.error.code,`${n} failed because ${Ge(i)}.`,{...t.error.details??{},...i,blockedBy:`android_foreground_surface`,originalMessage:t.error.message}):t}export{Me as C,O as S,Fe as _,Gt as a,M as b,We as c,I as d,P as f,Le as g,Re as h,Rt as i,Ke as l,N as m,It as n,K as o,F as p,Lt as r,G as s,Ft as t,Ue as u,Pe as v,Ne as x,j as y};
|
|
1
|
+
import{_ as e,b as t,c as n,h as r,u as i,y as a}from"./sdk-contracts.js";import{l as o,v as s}from"./sdk-device.js";import{Dn as c,Pt as l,ar as u,kn as d,or as f,sr as p}from"./sdk-batch.js";import{s as m}from"./session-store.js";import{i as ee,s as te}from"./session-target-evidence.js";import{f as ne}from"./parameterized-recorded-fill.js";import{b as re,t as ie}from"./runtime.js";import{a as h,f as g,p as _,s as v,t as y}from"./app-inventory-contract.js";import{r as ae}from"./diagnostics.js";import"./diagnostics2.js";import{i as oe}from"./rect-center.js";import{a as b}from"./android-system-chrome.js";import{r as se}from"./request-cancel.js";import"./request.js";import{r as ce}from"./provider-device-runtime.js";import{n as le}from"./dispatch-resolve.js";import{a as ue,i as x}from"./request-runtime-binding.js";import{_ as de,b as fe,f as S,i as C,n as pe,o as me,p as he,r as ge,s as _e,x as w}from"./session-snapshot.js";import{t as T}from"./snapshot-quality-verdict.js";import{t as E}from"./backend-snapshot-options.js";import{t as D}from"./snapshot-runtime-binding.js";function O(t){let r=e(t);return r?{ok:!0,ref:r.base,generation:r.generation}:{ok:!1,response:x(`INVALID_ARGS`,`Invalid ref "${t}" — malformed generation suffix.`,{hint:n})}}function k(e,t){if(t===`exists`)return{found:!0};if(t===`wait`)return{found:!0,waitedMs:e.waitedMs};if(t===`list`)return{action:`list`,matches:Array.isArray(e.matches)?e.matches.length:0};let n=typeof e.ref==`string`?e.ref:void 0;return t===`get_attrs`?{ref:n,action:`get attrs`}:{ref:n,action:`get text`,text:typeof e.text==`string`?e.text:``}}function A(e){return e.kind===`found`?{found:!0,...typeof e.waitedMs==`number`?{waitedMs:e.waitedMs}:{}}:e.kind===`list`?{matches:e.matches.map(e=>({ref:e.ref,node:b(e.node)}))}:{ref:e.ref,...e.kind===`text`?{text:e.text}:{},node:b(e.node)}}function j(e,t){let n=Array.isArray(e.selectorChain)?e.selectorChain:void 0,r=ye(e),i=r?.kind===`ref`?L(r.ref):void 0,a=r?.kind===`selector`?r.selector:void 0,o={...i?{ref:i}:{},...a?{selector:a}:{},...n?{selectorChain:n}:{}};if(t===`attrs`)return o;let s=typeof e.text==`string`?e.text:``;return{...o,text:s,refLabel:ve(s)}}function M(e){let{target:t}=e;return{...t.kind===`ref`?{ref:L(t.ref)}:{},...t.kind===`selector`?{selector:t.selector}:{},...typeof e.text==`string`?{text:e.text}:{},node:b(e.node)}}function N(e){let{node:t,preActionNodes:n,...r}=e;return r}function P(e){return{waitedMs:e.waitedMs,...typeof e.text==`string`?{text:e.text}:{},...typeof e.selector==`string`?{selector:e.selector}:{},...typeof e.captures==`number`?{captures:e.captures}:{},...typeof e.nodeCount==`number`?{nodeCount:e.nodeCount}:{},...typeof e.hint==`string`?{hint:e.hint}:{}}}function F(e){let{selectorChain:t,...n}=e;return n}function I(e,t,n,r,i,a){let o=e.get(t);if(!o)return;let s=ne(o)&&i?ee(i,{mode:a}):void 0;e.recordAction(o,{command:n.command,positionals:n.positionals??[],flags:n.flags??{},result:r,interactiveObservation:m(n),...s?{targetEvidence:s,targetEvidenceMode:a??`action`}:{}})}function ve(e){let t=e.trim();if(!(!t||t.length>80||/[\r\n]/.test(t)))return t}function ye(e){let t=e.target;if(!t||typeof t!=`object`)return;let n=t;if(n.kind===`ref`&&typeof n.ref==`string`)return{kind:`ref`,ref:n.ref};if(n.kind===`selector`&&typeof n.selector==`string`)return{kind:`selector`,selector:n.selector}}function L(e){return e.startsWith(`@`)?e.slice(1):e}async function R(e){let t=await D({...e,plan:l({hasActiveApp:e.session?.appBundleId!==void 0,intent:be(e.command)}),...e.session?{}:{readiness:{}}});return t.ok?{ok:!0,operations:{capture:t.capture,...t.readTextAtPoint?{readText:t.readTextAtPoint}:{},...t.findText?{findText:t.findText}:{},...t.findSelector?{findSelector:t.findSelector}:{}}}:t}function be(e){switch(e){case`is`:return`capture-only`;case`find`:case`get`:return`element-text`;case`wait`:return`wait-observation`}}const xe=[[`snapshotDepth`,`--depth`],[`snapshotScope`,`--scope`],[`snapshotRaw`,`--raw`]];function z(e,t){let n=xe.filter(([e])=>t?.[e]!==void 0).map(([,e])=>e);return n.length===0?null:x(`INVALID_ARGS`,`${e} @ref does not support ${n.join(`, `)}.`)}async function B(e,t){if(e.device.platform!==`android`||!e.appBundleId||e.lease?.leaseProvider||ce(e.device))return null;if(!t)throw new a(`INTERNAL_ERROR`,`Android observation was not supplied by root runtime composition`);let n=await t.readAppState(e.device),r=n.package?.trim();if(!r||r===e.appBundleId)return null;let i=await t.isPermissionPackage(r);return!we(r)&&!i?null:{expectedPackage:e.appBundleId,foregroundPackage:r,activity:n.activity,hint:Ce(i),...i?{permissionDialog:!0}:{}}}function Se(e){return e.permissionDialog?`Android permission dialog is blocking ${e.expectedPackage}`:`${e.foregroundPackage} is foreground instead of ${e.expectedPackage}`}function Ce(e){return e?`Use "alert get" to inspect it, then "alert accept" or "alert dismiss" to respond.`:`Use screenshot as visual truth, then take a fresh snapshot -i before retrying.`}function we(e){return e===`com.android.settings`||e===`com.android.systemui`||e.includes(`launcher`)}function V(e,t){let n=re(t);if(!n)return e;if(e.ok){let t=H(e.data?.warning,n);return{...e,data:{...e.data,warning:t}}}let r=e.error.details??{};return{...e,error:{...e.error,details:{...r,hint:H(r.hint,n)}}}}function H(e,t){return typeof e==`string`&&e.trim()!==``?`${e}\n${t}`:t}async function Te(e){let{device:t,node:n,flags:r,appBundleId:i,traceOutPath:a,surface:s,contextFromFlags:c}=e,l=g(n),u=e.readTextAtPoint;if(!u)return l;let d=oe(n.rect);if(!d||o(t)&&l&&!_(n.type??``))return l;let f=c(r,i,a),p=await u({point:d,options:{appBundleId:i,surface:s},execution:he(f)});return p.status===`read`?p.text:(ae({level:`warn`,phase:`interaction_read_fallback`,data:{reason:Ee(p.reason),nodeRef:n.ref,surface:s,platform:t.platform}}),l)}function Ee(e){switch(e){case`no-text-at-point`:return`no_text_at_point`;default:return e}}function U(e){let{session:t,sessionStore:n,sessionName:r}=e,i=0,a,o,s=t=>(e.consumedSnapshot&&(e.consumedSnapshot.state=t.snapshot),t);return{capture:async c=>{let l=Date.now(),u=Pe(c,e.req.flags?.out),d=Ae({timestamp:l,lastSnapshotAt:i,lastSnapshotResult:a,lastSnapshotCacheKey:o,session:t,request:c,cacheKey:u});if(d)return s(d);let f=je({session:t,timestamp:l,request:c});if(f)return i=f.createdAt,a={snapshot:f},o=u,s(a);let p=await De({params:e,request:c});c.signal?.throwIfAborted();let m={snapshot:p};return Ie({session:t,sessionStore:n,sessionName:r,snapshot:p}),i=l,a=m,o=u,s(m)}}}async function De(e){let{params:t,request:n}=e,r=await W(t,n,n.snapshotScope);return n.recovery?.legacyIosSparse&&v(r)?await Oe({runtimeParams:t,request:n,policy:n.recovery.legacyIosSparse}):n.recovery?.sparseVerdictQueryScope?.shouldScope&&T(r.snapshotQuality)?await ke({runtimeParams:t,request:n,policy:n.recovery.sparseVerdictQueryScope,snapshot:r}):r}async function Oe(e){let{runtimeParams:t,request:n,policy:r}=e;try{return await W(t,n,void 0,!1)}catch(e){if(!r.shouldScope)throw e;return await W(t,n,r.query,!1)}}async function ke(e){let{runtimeParams:t,request:n,policy:r,snapshot:i}=e;try{return await W(t,n,r.query,!1)}catch{return i}}async function W(e,t,n,r=t.flags?.snapshotInteractiveOnly){let i={...t.flags,snapshotInteractiveOnly:r},a=e.capture;return(await _e({device:e.device,session:e.session,flags:i,outPath:t.outPath??e.req.flags?.out,logPath:e.logPath??``,snapshotScope:n,includeRects:t.includeRects,signal:t.signal,captureData:async()=>await a(S({flags:i,logPath:e.logPath??``,meta:e.req.meta,session:e.session,snapshotScope:n,includeRects:t.includeRects,signal:t.signal}))})).snapshot}function Ae(e){let{timestamp:t,lastSnapshotAt:n,lastSnapshotResult:r,lastSnapshotCacheKey:i,session:a,request:o,cacheKey:s}=e;if(o.cache?.forceFresh!==!0&&r&&i===s&&!(t-n>=750)&&!w(a)&&!G(a,o))return r}function je(e){let{session:t,timestamp:n,request:r}=e,i=t?.snapshot;if(i&&Me(t,r)&&Ne(i,n)&&i.presentationKey===K(r))return i}function Me(e,t){return!(t.cache?.forceFresh===!0||t.cache?.useSessionSnapshot!==!0||w(e)||G(e,t))}function Ne(e,t){return t-e.createdAt<750}function G(e,t){return t.cache?.bypassForPostGestureStabilization===!0&&de(e)}function K(e){return i(r(Fe(e)))}function Pe(e,t){return JSON.stringify({presentationKey:K(e),includeRects:e.includeRects===!0,outPath:e.outPath??t??null})}function Fe(e){return e.snapshotScope===void 0?e.flags:{...e.flags,snapshotScope:e.snapshotScope}}function Ie(e){let{session:t,sessionStore:n,sessionName:r,snapshot:i}=e;!t||T(i.snapshotQuality)||(C(t,i),n.set(r,t))}function q(e){return ie({backend:Re(e),...te(`selector commands`,{plural:!0}),sessions:me({sessionName:e.sessionName,getSession:()=>e.session,recordOptions:{includeSnapshot:!0},setRecord:t=>{!e.session||!t.snapshot||(C(e.session,t.snapshot),e.sessionStore.set(e.sessionName,e.session))}}),signal:e.signal??se(e.req.meta?.requestId)})}async function Le(e,t){e.consumedSnapshot??={};let n=e.sessionStore.get(e.sessionName);return!n&&t?{ok:!1,response:ue()}:{ok:!0,session:n,device:n?.device??await le(e.req.flags??{})}}async function J(e,t){let n=await Le(e,t.requireSession);if(!n.ok)return n;let r=await R({command:t.command,device:n.device,session:n.session,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice});return r.ok?{ok:!0,runtime:q({...e,session:n.session,device:n.device,bound:r.operations})}:{ok:!1,response:r.response}}function Re(e){let{req:t,session:n,device:r,logPath:i,sessionName:a,sessionStore:o}=e,c=e.contextFromFlags??((e,t,n)=>fe(i??``,e,t,n)),l=e.bound?.readText,u=e.bound?.findText,d=S({flags:t.flags,logPath:i??``,meta:t.meta,session:n,snapshotScope:void 0}).execution,f=e.bound,p=f===void 0?void 0:U({device:r,session:n,sessionStore:o,sessionName:a,req:t,consumedSnapshot:e.consumedSnapshot,logPath:i,capture:f.capture});return{platform:s(r),captureSnapshot:p&&(async(e,n)=>{let i={...t.flags,...E(n)},a=n?.includeRects===!0,o=n?.scope??t.flags?.snapshotScope,s=t.command===`wait`||t.command===`find`||ze(t)||a&&r.platform===`web`;return await p.capture({flags:i,signal:e.signal,snapshotScope:o,includeRects:a,cache:{forceFresh:s,useSessionSnapshot:!0,bypassForPostGestureStabilization:!0}})}),readText:async(e,i)=>({text:await Te({readTextAtPoint:l,device:r,node:i,flags:t.flags,appBundleId:n?.appBundleId,traceOutPath:n?.trace?.outPath,surface:n?.surface,contextFromFlags:c})}),...u?{findText:async(e,t)=>({found:(await u({text:t,options:{appBundleId:n?.appBundleId,surface:n?.surface},execution:d,...e.signal?{signal:e.signal}:{}})).found})}:{}}}function ze(e){if(e.command!==`is`)return!1;let t=p(e.positionals??[]);return t.ok&&t.predicate===`absent`}async function Be(e){let{req:t}=e;if(t.command!==`find`)return null;let n=t.positionals??[],r=c(n,t.flags);if(!r.ok)return x(r.code,r.message);let i=r.parsed,a=i.action;if(!d(a))return null;let o=await J(e,{requireSession:!1,command:`find`});return o.ok?V(await Q(async()=>{let n=await o.runtime.selectors.find({session:e.sessionName,requestId:t.meta?.requestId,locator:i.locator,query:i.query,action:a,timeoutMs:i.timeoutMs});I(e.sessionStore,e.sessionName,t,k(n,a));let r=A(n),s=typeof r.ref==`string`?[r.ref]:Array.isArray(r.matches)?r.matches.map(e=>e.ref).filter(e=>typeof e==`string`):[];if(s.length>0){let t=e.sessionStore.get(e.sessionName);if(t&&(pe(t,s),e.sessionStore.set(e.sessionName,t),t.snapshotGeneration!==void 0))return{...r,refsGeneration:t.snapshotGeneration}}return r}),Y(e)):o.response}function Y(e){return e.consumedSnapshot?.state??e.sessionStore.get(e.sessionName)?.snapshot}async function X(e){let{req:t}=e;if(t.command!==`get`)return null;let n=f(t.positionals?.[0]);if(!n.ok)return x(n.code,n.message);let r=n.format,i=He(t);if(!i.ok)return i.response;if(i.target.kind===`ref`){let e=z(`get`,t.flags);if(e)return e}let a=t.internal?.replayTargetGuard,o=await J(e,{requireSession:!0,command:`get`});if(!o.ok)return o.response;let s=o.runtime,c=i.target.kind===`ref`?ge({session:e.sessionStore.get(e.sessionName),ref:i.target.ref,mintedGeneration:i.refGeneration}):void 0;return V(await Q(async()=>{let n=await s.selectors.get({session:e.sessionName,requestId:t.meta?.requestId,property:r,target:i.target,expectedResolvedTarget:a});I(e.sessionStore,e.sessionName,t,j(n,r),{node:n.node,preActionNodes:n.preActionNodes});let o=M(n);return c?{...o,warning:c}:o}),Y(e))}async function Ve(e){let{req:t}=e;if(t.command!==`is`)return null;let n=p(t.positionals??[]);if(!n.ok)return x(n.code,n.message,n.hint?{hint:n.hint}:void 0);let{predicate:r,selectorExpression:i,expectedText:a}=n;if(r===`absent`){let e=h({depth:t.flags?.snapshotDepth,scope:t.flags?.snapshotScope});if(e){let t=y(e);return x(t.code,t.message,t.details)}}let o=t.internal?.replayTargetGuard,s=await J(e,{requireSession:!0,command:`is`});return s.ok?V(await $(e,await Q(async()=>{let n=await s.runtime.selectors.is({session:e.sessionName,requestId:t.meta?.requestId,predicate:r,selector:i,expectedText:a,expectedResolvedTarget:o}),c=Z(n),l=N(n);return I(e.sessionStore,e.sessionName,t,l,c),F(l)}),`is ${r}`),Y(e)):s.response}function Z(e){let t=e.node,n=e.preActionNodes;if(!(!t||typeof t!=`object`||!Array.isArray(n)))return{node:t,preActionNodes:n}}function He(e){let t=e.positionals?.[1]??``;if(t.startsWith(`@`)){let n=O(t);return n.ok?{ok:!0,target:{kind:`ref`,ref:n.ref,fallbackLabel:e.positionals.length>2?e.positionals.slice(2).join(` `).trim():``},refGeneration:n.generation}:{ok:!1,response:n.response}}let n=u(e.positionals?.slice(1)??[]);return n.ok?{ok:!0,target:{kind:`selector`,selector:`selector`in n?n.selector:``}}:{ok:!1,response:x(n.code,n.message)}}async function Q(e){try{return{ok:!0,data:await e()}}catch(e){let n=t(e);return x(n.code,n.message,n.details)}}async function $(e,t,n){if(t.ok)return t;let r=e.sessionStore.get(e.sessionName);if(!r)return t;let i;try{if(!e.androidObservation)return t;i=await B(r,e.androidObservation)}catch{return t}return i?x(t.error.code,`${n} failed because ${Se(i)}.`,{...t.error.details??{},...i,blockedBy:`android_foreground_surface`,originalMessage:t.error.message}):t}export{P as _,$ as a,q as c,B as d,z as f,F as g,N as h,Ve as i,U as l,I as m,Be as n,Z as o,R as p,X as r,Q as s,Y as t,V as u,O as v};
|
package/dist/src/selectors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{br as e,gr as t,hr as n,vn as r,vr as i,xn as a,yr as o}from"./sdk-batch.js";import{t as s}from"./sdk-selectors.js";export{r as findSelectorChainMatch,s as formatSelectorFailure,o as isNodeEditable,e as isNodeVisible,n as isSelectorToken,t as parseSelectorChain,a as resolveSelectorChain,i as tryParseSelectorChain};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Dr as e,Hr as t,Rr as n,Vr as r,jr as i,zr as a}from"./sdk-batch.js";import{n as o,t as s}from"./scroll-indicator.js";import{a as c,i as l,o as ee,r as u}from"./react-native-overlay.js";import{t as d}from"./rect-center.js";import{a as f,c as te,d as p,f as m,g as ne,h,i as g,l as re,m as _,n as v,o as y,p as b,r as x,s as S,t as C,u as ie}from"./tree.js";function ae(e,t){let n=g(t.sourceNodesByIndex.values());for(let r of e)oe(r,t.sourceNodesByIndex,n)&&b(t.replacements,r,{type:`Cell`})}function oe(e,t,n){return!(i(e.type??``)!==`other`||e.enabled===!1||!e.rect||!le(e.label)||!f(e,t,ce)||!se(e)||re(e.rect,n))}function se(e){return e.rect?e.rect.height>=44&&e.rect.height<=160&&e.rect.width>=120:!1}function ce(e){let t=i(e.type??``);return t===`scrollview`||t===`scrollarea`}function le(e){let t=e?.trim();return!(!t||/^(toolbar|window|application)$/i.test(t)||t.startsWith(`!,`)||/debugger|fast refresh/i.test(t))}function ue(e,t){let n=new Set;for(let r of e)de(t.replacements.get(r.index)??r)&&fe(r,t.sourceNodesByIndex,t,n);pe(e,t,n)}function de(e){let t=e.label?.trim();return!!(t&&o(t))}function fe(e,t,n,r){let i=!p(e.type)||n.isSuppressed(e),a=s(e.label?.trim()??``,e.value),o=a?y(e,t,{includeSelf:!0}):void 0;i&&n.suppressNode(e,o?[o]:[]),o&&a&&j(n,o,e,a)&&r.add(o.index)}function pe(e,t,n){let r=new Map;for(let i of e){let e=r.get(i.parentIndex??-1),a=e?.clip,o=t.replacements.get(i.index)??i,s=k(o.rect,a),c=me(o,a,s),l=w(e,c,o);T(t,i,o,a,s,c,l),r.set(i.index,E(i,o,a,s,l,n))}}function me(e,t,r){return!!(t&&n(e.rect)&&!n(r))}function w(e,t,n){return!!(e?.projectedOut||t&&O(n))}function T(e,t,n,r,i,a,o){o||a?e.suppressNode(t,[]):r&&i&&!A(n.rect,i)&&b(e.replacements,t,{rect:i})}function E(e,t,n,r,i,a){return{projectedOut:i,...D(e,t,n,r,a)?{clip:r}:n?{clip:n}:{}}}function D(e,t,r,i,a){return!!(n(i)&&(a.has(e.index)||r!==void 0&&p(t.type)))}function O(e){return e.type?.trim().toLowerCase()===`cell`||p(e.type)}function k(e,t){if(!e||!t)return e;let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.width,t.x+t.width),a=Math.min(e.y+e.height,t.y+t.height);return{x:n,y:r,width:Math.max(0,i-n),height:Math.max(0,a-r)}}function A(e,t){return!!(e&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height)}function j(e,t,n,r){let i=N((e.replacements.get(t.index)??t).rect,n.rect);return ne(e.replacements,t,e=>({rect:i??e.rect,hiddenContentAbove:M(e.hiddenContentAbove,r.above),hiddenContentBelow:M(e.hiddenContentBelow,r.below)})),!!i}function M(e,t){return e===!0||t?!0:void 0}function N(e,t){if(!(!e||!t)&&!(t.height<=0||t.height>=e.height)&&!(t.y<e.y||t.y>e.y+e.height))return{...e,y:t.y,height:Math.min(t.height,e.y+e.height-t.y)}}function P(e,t){for(let n=0;n<e.length;n+=1){let r=e[n],a=r?.label?.trim();r&&a&&i(r.type??``)===`other`&&t(r,a,n)}}function F(e,t){P(e,(n,r,i)=>{if(!c(r)||!n.rect)return;let a=x(e,i,e=>!!e.rect&&ee(e.label?.trim()??``));if(!a?.rect)return;let o=L(n.rect,a.rect);if(!o)return;let s=I(e,i,o);b(t,n,{rect:s}),S(e,i,e=>{c(e.label?.trim()??``)&&b(t,e,{rect:s})})})}function I(e,n,i){let a=i;return S(e,n,e=>{let n=e.label?.trim()??``;!e.rect||!c(n)||t(i,e.rect)&&r(e.rect)<r(a)&&(a=e.rect)}),a}function L(e,t){let n=e.x+e.width,r=t.x+t.width,i={x:t.x,y:e.y,width:n-t.x,height:e.height};if(t.x>e.x&&d(t,i))return{...e,width:t.x-e.x};let a={x:e.x,y:e.y,width:r-e.x,height:e.height};if(r<n&&d(t,a))return{...e,x:r,width:n-r}}function R(e,t){P(e,(n,r,i)=>{u(n)&&l(n,z(e,i))&&t.suppressNode(n,z(e,i))})}function z(e,t){let n=[];return S(e,t,e=>{n.push(e)}),n}function he(e,t){let n=g(e),r=n?n.y+n.height:null;if(r!==null)for(let n=0;n<e.length;n+=1){let i=e[n];!i||!ge(i,r)||(t.suppressNode(i,[]),_e(i,t,r),S(e,n,e=>{t.suppressNode(e,[])}))}}function ge(e,t){return!e.rect||i(e.type??``)!==`keyboard`?!1:e.rect.y>=t}function _e(e,t,n){let r=typeof e.parentIndex==`number`?t.sourceNodesByIndex.get(e.parentIndex):void 0;for(;r?.rect&&r.rect.y>=n;)t.suppressNode(r,[]),r=typeof r.parentIndex==`number`?t.sourceNodesByIndex.get(r.parentIndex):void 0}function ve(e,t){for(let n=0;n<e.length;n+=1){let r=e[n];if(!r)continue;if(ye(r)){B(e,n,r,t);continue}if(!be(r))continue;let a=x(e,n,e=>i(e.type??``)===`searchfield`&&e.label===`Search`);a&&(t.suppressNode(r,[a]),xe(r,a,t),B(e,n,a,t))}}function ye(e){return i(e.type??``)===`searchfield`&&e.label===`Search`}function be(e){let t=i(e.type??``);return e.label===`Toolbar`&&(t===`toolbar`||t===`searchfield`)}function B(e,t,n,r){S(e,t,e=>{e.index!==n.index&&Se(e)&&r.suppressNode(e,[n])})}function xe(e,t,n){let r=e;for(;typeof r.parentIndex==`number`;){let e=n.sourceNodesByIndex.get(r.parentIndex);if(!e||e.label!==`Toolbar`)return;n.suppressNode(e,[t]),r=e}}function Se(e){let t=i(e.type??``);return t===`button`?!1:t===`image`||e.label===`Search`}function Ce(e,t){for(let n=0;n<e.length;n+=1){let r=e[n],i=r?.label?.trim();!r||t.isSuppressed(r)||!i||we(e,n,r,i,t)}}function we(e,t,n,r,a){let o=i(n.type??``);if(o===`statictext`||o===`link`){V(e,t,r,n,a);return}if(o!==`other`)return;let s=Te(e,t,r);if(s){a.suppressNode(n,[s]);return}V(e,t,r,n,a)}function Te(e,t,n){return x(e,t,e=>{let t=i(e.type??``);return(t===`link`||t===`searchfield`||p(e.type))&&e.label?.trim()===n})}function V(e,t,n,r,i){S(e,t,e=>{!i.semanticRepresentativeIndexes.has(e.index)&&ie(e,n)&&i.suppressNode(e,[r])})}function Ee(e,t){P(e,(n,r,i)=>{let a=x(e,i,e=>m(e)&&e.label?.trim()===r&&(d(e.rect,n.rect)||De(n,e)));a&&t.suppressNode(n,[a])})}function De(e,t){if(t.label?.trim()!==e.label?.trim())return!1;let n=i(t.type??``);return Oe(e,n)||n===`textfield`||ke(e,n,t)}function Oe(e,t){let n=e.label?.trim();return t===`button`&&(n===`Dismiss`||n===`Back`)}function ke(e,t,n){return t!==`button`||!e.rect||!n.rect?!1:e.rect.x===0&&e.rect.y===0&&e.rect.width>=300&&e.rect.height>=600&&n.rect.width<e.rect.width}function Ae(e,t){let n=C(e);for(let r of e)i(r.type??``)===`other`&&(r.hittable===!0||r.label?.trim()||r.value?.trim()||r.identifier?.trim()&&t.suppressNode(r,je(r,n)))}function je(e,t){let n=[],r=new Set([e.index]),i=[...t.get(e.index)??[]];for(;i.length>0;){let e=i.pop();if(!e||r.has(e.index))continue;r.add(e.index),n.push(e);let a=t.get(e.index);a&&i.push(...a)}return n}function Me(e,t){he(e,t),Ae(e,t),ue(e,t),ve(e,t),Ee(e,t),F(e,t.replacements),R(e,t),Ce(e,t)}function Ne(e,t){for(let n=0;n<e.length;n+=1){let r=e[n],i=r?Pe(e,n,r,t):void 0;!r?.rect||!i||Le(e,n,r,i,t)}}function Pe(e,t,n,r){let a=n.label?.trim();if(i(n.type??``)!==`cell`||a&&!Fe(a,n.identifier)&&!o(a))return a;let s=v(e,t).find(Ie),c=s?.label?.trim();return!s||!c?a:(b(r.replacements,n,{label:c}),r.suppressNode(s,[n]),c)}function Fe(e,t){return t?.trim()===e&&/^[A-Z_$][A-Za-z0-9_$]*Cell$/.test(e)}function Ie(e){if(!e.label?.trim())return!1;let t=i(e.type??``);return t===`statictext`||t===`text`||t===`textview`}function Le(e,t,n,r,a){let o=i(n.type??``);if(o===`button`){H(v(e,t),r,a,n);return}if(o!==`cell`)return;let s=v(e,t);Re(s,n,r,a)||ze(s,n,r,a)}function Re(e,t,n,r){let i=e.find(e=>Ve(e,t,n));if(!i)return!1;let a=e.find(e=>U(e,t,n)),o=i.identifier?void 0:a?.identifier??t.identifier;return o&&b(r.replacements,i,{identifier:o}),r.suppressNode(t,[i]),Be(e,t,n,i,r),!0}function ze(e,t,n,r){let i=e.find(e=>U(e,t,n));if(!i){e.some(te)&&H(e,n,r,t);return}!t.identifier&&i.identifier&&b(r.replacements,t,{identifier:i.identifier}),r.suppressNode(i,[t]),H(e.filter(e=>e.index!==i.index),n,r,t)}function Be(e,t,n,r,i){for(let a of e)a.index!==r.index&&(U(a,t,n)||W(a,t)||He(a,r)||h(a,n))&&i.suppressNode(a,[r])}function H(e,t,n,r){for(let i of e)(h(i,t)||r&&W(i,r))&&n.suppressNode(i,r?[r]:[])}function U(e,t,n){if(i(e.type??``)!==`button`)return!1;let r=t.identifier?.trim(),a=e.identifier?.trim();return r&&a&&r===a?!0:e.label?.trim()===n&&d(e.rect,t.rect)}function W(e,t){return i(e.type??``)===`button`&&!e.label?.trim()&&!e.value?.trim()&&d(e.rect,t.rect)}function Ve(e,t,n){if(i(e.type??``)!==`switch`)return!1;let r=t.identifier?.trim(),a=e.identifier?.trim();return r&&a&&r===a?!0:e.label?.trim()===n}function He(e,t){if(i(e.type??``)!==`switch`||e.index===t.index)return!1;let n=e.label?.trim();return n===t.value?.trim()||n===`0`||n===`1`}const G=1.15;function Ue(e,t,n){let r=new Map(e.map((e,t)=>[e.index,t]));for(let[i,o]of e.entries()){let s=We(e,r,t,o,n);if(!s)continue;q(e,i,n);let c=J(s.shelfRect,2);for(let t of s.intermediateSiblings){if($e(t)||!t.rect||!a(t.rect,c))continue;let i=r.get(t.index);i!==void 0&&q(e,i,n)}}}function We(e,t,n,r,i){let a=Ge(r,n,i.sourceNodesByIndex);if(!a)return;let o=Je(e,t,a.siblings,a.position,a.parent);if(!(o<0))return{shelfRect:a.rect,intermediateSiblings:a.siblings.slice(a.position+1,o)}}function Ge(e,t,n){let r=Ye(e,K(t,e.index));if(!r)return;let i=qe(e,n);if(!i||!i.rect)return;let a=K(t,i.index),o=a.findIndex(t=>t.index===e.index);if(Ke(a,o,e,r))return{rect:r.rect,parent:i,siblings:a,position:o}}function K(e,t){return e.get(t)??[]}function Ke(e,t,n,r){if(t<1)return!1;let i=Xe(e,t,n);return i?!r.childActionsPresented||!Ze(i,r.actionButtons):!1}function qe(e,t){return typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0}function Je(e,t,n,r,i){return n.findIndex((n,a)=>a>r&&Qe(e,t.get(n.index),n,i))}function Ye(e,n){if(!p(e.type)||!e.rect)return;let r=e.rect,a=n.filter(e=>i(e.type??``)===`button`&&e.rect);if(a.length===0&&e.hiddenContentBelow===!0)return{rect:r,childActionsPresented:!1,actionButtons:a};if(a.length<3)return;let o=a.map(e=>e.rect.x+e.rect.width/2);if(o.every((e,t)=>t===0||e>o[t-1]))return{rect:r,childActionsPresented:a.some(e=>t(r,e.rect)),actionButtons:a}}function Xe(e,t,n){if(!(!n.rect||t<1))for(let r=t-1;r>=0;--r){let t=e[r];if(!(!t.rect||!m(t))&&t.rect.x+t.rect.width/2<n.rect.x&&et(t.rect,J(n.rect,2)))return t}}function Ze(e,t){if(!e.rect||t.length===0)return!1;let n=Math.max(...t.map(e=>e.rect?.width??0)),r=Math.max(...t.map(e=>e.rect?.height??0));return e.rect.width>n*G||e.rect.height>r*G}function Qe(e,t,n,r){return t!==void 0&&i(n.type??``)===`other`&&d(n.rect,r.rect)&&!!x(e,t,m)}function q(e,t,n){let r=e[t];if(r){n.suppressNode(r,[]);for(let r of v(e,t))n.suppressNode(r,[])}}function $e(e){let t=i(e.type??``);return t===`textfield`||t===`securetextfield`||t===`searchfield`||t===`textview`}function J(e,t){return{x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}}function et(e,t){return Math.max(e.y,t.y)<=Math.min(e.y+e.height,t.y+t.height)}function tt(e,t){let n=C(e);Ue(e,n,t),nt(e,n,t)}function nt(e,t,n){for(let r of e){if(i(r.type??``)!==`navigationbar`||!r.rect)continue;let e=t.get(r.index)??[],a=e.flatMap(t=>rt(t,e,r.rect));if(a.length!==1)continue;let{field:o,title:s,image:c,label:l}=a[0];b(n.replacements,o,{type:`Button`,label:l,enabled:!0,rect:st([c.rect,o.rect,s.rect])}),n.semanticRepresentativeIndexes.add(o.index),n.suppressNode(s,[o]),n.suppressNode(c,[o])}}function rt(t,n,r){let i=e(t);if(!it(t,i))return[];let a=X(n,e=>at(e,i)),o=X(n,Y);return a?.rect&&o?.rect&&ot(o.rect,t.rect,a.rect,r)?[{field:t,title:a,image:o,label:i}]:[]}function it(e,t){return i(e.type??``)===`textfield`&&e.enabled===!1&&!!e.rect&&!!t&&e.value?.trim()===t}function at(e,t){return i(e.type??``)===`statictext`&&e.label?.trim()===t&&!!e.rect}function Y(e){return i(e.type??``)===`image`&&!!e.identifier?.trim()&&!!e.rect}function X(e,t){let n=e.filter(t);return n.length===1?n[0]:void 0}function ot(e,n,r,i){let a=n.x-(e.x+e.width),o=r.x-(n.x+n.width);return t(i,e)&&t(i,n)&&t(i,r)&&a>=0&&a<=12&&o>=0&&o<=12&&Z(e,n)&&Z(n,r)}function Z(e,t){return Math.max(e.y,t.y)<=Math.min(e.y+e.height,t.y+t.height)}function st(e){let t=Math.min(...e.map(e=>e.x)),n=Math.min(...e.map(e=>e.y)),r=Math.max(...e.map(e=>e.x+e.width)),i=Math.max(...e.map(e=>e.y+e.height));return{x:t,y:n,width:r-t,height:i-n}}function ct(e,t){let n=C(e);for(let r of e){if(i(r.type??``)===`element(58)`){b(t.replacements,r,{type:`WebView`});continue}let e=lt(r,t.sourceNodesByIndex,n);if(e?.kind===`suppress`){t.suppressNode(r,[]);continue}e&&(b(t.replacements,r,{type:e.type,...e.type===`Heading`?{value:void 0}:{}}),t.semanticRepresentativeIndexes.add(r.index))}}function lt(e,t,n){if(i(e.type??``)!==`other`)return null;let r=f(e,t,ft),a=e.label?.trim();return!r||!a?null:dt(e,r,a)?{kind:`suppress`}:ut(e,a,n)?{kind:`semantic`,type:Q(e.value)?`Heading`:`StaticText`}:null}function ut(e,t,n){let r=n.get(e.index);if(r?.length!==1)return!1;let a=r[0];return i(a.type??``)===`statictext`&&a.label?.trim()===t&&!n.has(a.index)}function dt(e,t,n){return e.parentIndex===t.index&&t.label?.trim()===n&&!Q(e.value)}function ft(e){let t=i(e.type??``);return t===`webview`||t===`element(58)`}function Q(e){return/^[1-6]$/.test(e?.trim()??``)}const pt=[ct,tt,ae,Ne,Me];function mt(e){if(e.length===0)return{nodes:e,presentedIndexesBySourceIndex:new Map};let t=new Map,n=new Map,r=new Set,i=new Map(e.map(e=>[e.index,e])),a=new Set,o={replacements:t,semanticRepresentativeIndexes:r,sourceNodesByIndex:i,isSuppressed:e=>a.has(e.index),suppressNode(e,t){if(a.add(e.index),t.length===0)return;let r=n.get(e.index)??new Set;for(let e of t)r.add(e.index);n.set(e.index,r)}};for(let t of pt)t(e,o);if(a.size===0&&t.size===0)return{nodes:e,presentedIndexesBySourceIndex:new Map(e.map(e=>[e.index,[e.index]]))};let s=e.filter(e=>!a.has(e.index)).map(e=>t.get(e.index)??e),c=_(s,a,e),l=new Map(s.map((e,t)=>[e.index,c[t].index]));return{nodes:c,presentedIndexesBySourceIndex:new Map(e.map(e=>[e.index,$(e.index,l,n)]))}}function $(e,t,n,r=new Set){let i=t.get(e);if(i!==void 0)return[i];if(r.has(e))return[];r.add(e);let a=new Set;for(let i of n.get(e)??[])for(let e of $(i,t,n,r))a.add(e);return[...a].sort((e,t)=>e-t)}export{mt as t};
|
package/dist/src/server.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import{C as e,_ as t,n,o as r}from"./sdk-contracts.js";import{Dr as i,f as a,p as o,y as s}from"./sdk-batch-runner.js";import{i as c,t as l}from"./sdk-device.js";import{Ct as u,Et as ee,Ft as te,Tt as ne}from"./prepare-kind.js";import{_ as d,g as f,h as re,s as p,v as m}from"./registry.js";import{t as ie}from"./session.js";import{i as ae,n as h,t as oe}from"./command-metadata.js";import{n as se}from"./version.js";import{n as ce,r as le,t as ue}from"./cli-config.js";import{t as de}from"./cli-output.js";const g=[`simulator`,`emulator`,`device`];function _(e){return{type:`number`,...e?{description:e}:{}}}function v(e,t){return{type:`string`,enum:e,...t?{description:t}:{}}}function y(e){return{type:`string`,const:e}}function b(e){return{type:[`string`,`null`],...e?{description:e}:{}}}function x(e,t=[],n){return{type:`object`,...n?{description:n}:{},properties:e,...t.length>0?{required:t}:{}}}const S={type:`array`,items:{type:`string`}},C=x({wallClockMs:_(`Total wall-clock time for the request in milliseconds.`),runnerRoundTrips:_(`Number of real runner round-trips made while serving the request.`),nodeCount:_(`Number of nodes in the original node tree when the response carries one.`)},[`wallClockMs`,`runnerRoundTrips`]),w=x({field:m(),artifactType:m(),path:m(),localPath:m(),fileName:m()},[`field`]);function T(e={}){let t=e.properties??{},n=e.required??[];return x({targetKind:v([`point`,`ref`,`selector`],`Resolved interaction target kind.`),x:_(`Resolved interaction x coordinate when available.`),y:_(`Resolved interaction y coordinate when available.`),referenceWidth:_(`Reference frame width for visualizing the interaction point.`),referenceHeight:_(`Reference frame height for visualizing the interaction point.`),ref:m(`Snapshot ref without the @ prefix when the target was an @ref.`),selector:m(`Selector expression when the target was a selector.`),selectorChain:S,refLabel:m(),targetHittable:f(),hint:m(),warning:m(),message:m(),evidence:E,resolution:pe,cost:C,maestroNonHittableCoordinateFallbackAllowed:f(`Whether the direct iOS Maestro coordinate fallback was allowed for this selector.`),maestroNonHittableCoordinateFallbackUsed:f(`Whether the direct iOS Maestro coordinate fallback was actually used.`),maestroFallbackReason:y(`non-hittable-coordinate`),...t},[`targetKind`,...n])}const fe=x({diagnosticRef:m(`Opaque non-@ diagnostic token. Never a snapshot ref: not issued via refsGeneration and cannot be pinned or reused as an @ref target. UTF-8 truncated to 256 bytes.`),role:m(`UTF-8 truncated to 256 bytes.`),label:m(`UTF-8 truncated to 256 bytes.`)},[`diagnosticRef`]),pe={type:`object`,description:`Pre-action disclosure of how the acting path resolved its target. Absent when resolutionDisclosure is inapplicable for the path.`,oneOf:[x({source:y(`runtime`),phase:y(`pre-action`),kind:y(`unique`)},[`source`,`phase`,`kind`]),x({source:y(`runtime`),phase:y(`pre-action`),kind:y(`disambiguated`),matchCount:_(`Total matches resolveSelectorChain found before disambiguation.`),winnerDiagnostic:fe,tiebreak:v([`visible`,`deepest`,`smallest-area`,`structural-equivalence`],`The comparison that decided the winner.`),alternatives:{type:`array`,description:`At most 5 losing candidates, document order. Present at default/full response levels and omitted in digest. The winner is never included.`,items:fe}},[`source`,`phase`,`kind`,`matchCount`,`winnerDiagnostic`,`tiebreak`]),x({source:y(`ref`),phase:y(`pre-action`),kind:y(`exact`)},[`source`,`phase`,`kind`]),x({source:y(`ref`),phase:y(`pre-action`),kind:y(`label-fallback`)},[`source`,`phase`,`kind`]),x({source:y(`direct-ios`),kind:y(`not-observed`)},[`source`,`kind`])]},E=x({foregroundApp:m(`Foreground app bundle id or name, when the capture carries it.`),nodeCount:_(`Node count in the post-action interactive-only capture.`),interactiveNodeCount:_(`Subset of nodeCount the platform reports as hittable.`),digest:m(`Order-independent digest of the post-action node multiset.`),changedFromBefore:f(`Whether the post-action digest differs from the pre-action capture digest. false is evidence, not failure.`)},[`nodeCount`,`interactiveNodeCount`,`digest`,`changedFromBefore`]),D=x({settled:f(`Whether the UI held the quiet window before the deadline. false is advisory, not failure.`),waitedMs:_(),captures:_(),quietMs:_(),timeoutMs:_(),refsGeneration:_(`Snapshot generation of the stored settled tree; refs on added diff lines were minted from it.`),refs:{type:`array`,items:x({ref:m(`Plain ref body (e12) minted from the stored settled tree.`)},[`ref`])},diff:x({summary:x({additions:_(),removals:_(),unchanged:_()},[`additions`,`removals`,`unchanged`]),lines:{type:`array`,items:x({kind:v([`added`,`removed`]),text:m(),ref:m(`Plain ref body (e12) for added lines.`)},[`kind`,`text`])},truncated:f(`Lines were capped to the response bound.`)},[`summary`,`lines`],`Settled diff vs the pre-action tree (changed lines only).`),tail:{type:`array`,description:`Unchanged interactive refs tail: still-present, actionable elements from the settled tree, attached only when diff carries zero added-line refs (a modal-dismiss/toast-only diff).`,items:x({ref:m(`Plain ref body (e12) minted from the stored settled tree.`),role:m(),label:m()},[`ref`,`role`])},tailTruncated:f(`Present (true) when tail candidates exceeded the response cap.`),hint:m()},[`settled`,`waitedMs`,`captures`,`quietMs`,`timeoutMs`]),O={platform:v(c),target:v(l),device:m(`Human-readable device name.`),id:m(`Stable device id.`),kind:v(g)},me=[`platform`,`target`,`device`,`id`,`kind`],he=x({success:f(),exitCode:_(),stdout:m(),stderr:m(),error:d(`Normalized error detail when shutdown failed.`)},[`success`,`exitCode`,`stdout`,`stderr`]);function ge(e){return{...e,properties:{...e.properties??{},settle:D}}}const _e=T({properties:{evidence:E,settle:D,button:v([`secondary`,`middle`]),count:_(`Number of press/click repetitions.`),intervalMs:_(`Delay between repeated press/click actions.`),holdMs:_(`Hold duration for each action.`),jitterPx:_(`Randomization radius in pixels.`),doubleTap:f(`Whether the command requested a double-tap action.`)}}),k={text:m(`Text submitted to the field.`),delayMs:_(`Delay between typed characters in milliseconds.`),evidence:E,settle:D},ve=x({resourceId:b(`Android resource id of the exact field that changed.`),className:b(`Android class name of the exact field that changed.`),packageName:b(`Android package name that owns the exact field.`),rect:x({x:_(),y:_(),width:_(),height:_()},[`x`,`y`,`width`,`height`],`Screen-space rectangle of the exact field that changed.`)},[`resourceId`,`className`,`packageName`,`rect`],`Target identity captured before fill and matched after fill.`),ye={press:_e,click:_e,fill:{type:`object`,description:`Fill response. Android may return target-bound unconfirmed evidence when the exact app-owned field changed but formatting prevented raw equality.`,oneOf:[{...T({properties:k,required:[`text`]}),not:x({},[`verification`])},T({properties:{...k,verification:y(`unconfirmed`),requested:m(`Literal text requested by the fill command.`),before:b(`Raw target text captured before the fill.`),after:b(`Raw target text captured after the fill.`),target:ve},required:[`text`,`verification`,`requested`,`before`,`after`,`target`]})]},longpress:T({properties:{durationMs:_(),settle:D,gesture:y(`longpress`)}}),find:x({ref:m(`Snapshot ref without the @ prefix when the find action returns one.`),refsGeneration:_(`ADR 0014 ref frame epoch for read-only find actions.`),found:f(`Whether a wait/exists/read-only find satisfied its condition.`),waitedMs:_(`Milliseconds waited for a read-only find condition.`),text:m(`Text value returned by find get_text.`),node:d(`Snapshot node for find get_attrs/get_text.`),matches:{type:`array`,description:`Every match for the read-only find list action (#1625): { ref, node } each.`,items:d(`One listed match with its snapshot ref and node.`)},locator:m(`Locator kind used for the find action.`),query:m(`Query argument used for the find action.`),x:_(`Resolved x coordinate for mutating find actions.`),y:_(`Resolved y coordinate for mutating find actions.`),message:m(`Diagnostic message for mutating find actions.`),settle:D,cost:C},[],`Daemon response data for the find command.`),boot:x({...O,booted:{type:`boolean`,const:!0}},[...me,`booted`]),shutdown:x({...O,shutdown:he},[...me,`shutdown`]),viewport:x({width:_(),height:_(),message:m()},[`width`,`height`,`message`]),...p,back:ge(p.back),wait:x({waitedMs:_(),kind:y(`selector`),text:m(),selector:m(),captures:_(),nodeCount:_(),hint:m(),warning:m()},[`waitedMs`]),prepare:x({action:y(`ios-runner`),platform:v(c),deviceId:m(),deviceName:m(),kind:v(g),durationMs:_(),runner:x({},[]),cache:v([`exact`,`restore-key`,`miss`,`external`]),artifact:v([`valid`,`rebuilt`]),buildMs:_(),connectMs:_(),healthCheckMs:_(),xctestrunPath:m(),recoveryReason:m(),failureReason:m(),timing:x({totalMs:_(),additiveParts:x({buildMs:_(),connectAfterBuildMs:_(),healthCheckMs:_()},[`connectAfterBuildMs`,`healthCheckMs`]),containment:x({connectMs:{type:`array`,items:y(`buildMs`)},healthCheckMs:{type:`array`,items:m()}},[`healthCheckMs`]),note:m()},[`totalMs`,`additiveParts`,`containment`,`note`]),message:m()},[`action`,`platform`,`deviceId`,`deviceName`,`kind`,`durationMs`,`runner`,`connectMs`,`healthCheckMs`,`timing`,`message`]),push:{type:`object`,oneOf:[x({platform:y(`ios`),bundleId:m(),message:m()},[`platform`,`bundleId`,`message`]),x({platform:y(`android`),package:m(),action:m(),extrasCount:_(),message:m()},[`platform`,`package`,`action`,`extrasCount`,`message`])]},"trigger-app-event":x({event:m(),eventUrl:m(),transport:y(`deep-link`),message:m()},[`event`,`eventUrl`,`transport`,`message`]),clipboard:{type:`object`,oneOf:[x({action:y(`read`),text:m()},[`action`,`text`]),x({action:y(`write`),textLength:_(),message:m()},[`action`,`textLength`,`message`])]},appstate:{type:`object`,oneOf:[x({platform:v([`ios`,`macos`]),appName:m(),appBundleId:m(),source:y(`session`),surface:v(ie),device_udid:m(`iOS only — the session device UDID.`),ios_simulator_device_set:{type:[`string`,`null`],description:`iOS only — the simulator set path, or null when unknown.`}},[`platform`,`appName`,`source`,`surface`]),x({platform:y(`android`),package:m(),activity:m()},[`platform`,`package`,`activity`])]},keyboard:x({platform:v([`android`,`ios`]),action:v([`status`,`dismiss`,`enter`]),visible:f(),wasVisible:f(),dismissed:f(),attempts:_(),inputType:m(),type:v([`text`,`number`,`email`,`phone`,`password`,`datetime`,`unknown`]),inputMethodPackage:m(),focusedPackage:m(),focusedResourceId:m(),inputOwner:v([`app`,`ime`,`unknown`]),message:m()},[`platform`,`action`]),doctor:x({status:v([`pass`,`warn`,`fail`,`info`]),summary:m(),kind:v([`auto`,`react-native`,`expo`,`repack`]),platform:m(),target:v(l),targetApp:m(),metro:x({host:m(),port:_()},[`host`,`port`]),checks:{type:`array`,items:x({id:m(),status:v([`pass`,`warn`,`fail`,`info`]),summary:m(),hint:m(),command:m(),evidence:d()},[`id`,`status`,`summary`])}},[`status`,`summary`,`kind`,`checks`]),diff:x({mode:y(`snapshot`),baselineInitialized:f(),summary:x({additions:_(),removals:_(),unchanged:_()},[`additions`,`removals`,`unchanged`]),lines:{type:`array`,items:x({kind:v([`added`,`removed`]),text:m(),ref:m()},[`kind`,`text`])},warnings:S},[`mode`,`baselineInitialized`,`summary`,`lines`]),replay:x({replayed:_(),healed:_(),session:m(),sessionActive:f(`True iff the session is still active — the script had no terminal close.`),artifactPaths:S,snapshotDiagnostics:d(),message:m()},[`replayed`,`healed`,`session`,`sessionActive`,`artifactPaths`,`message`]),test:x({total:_(),executed:_(),passed:_(),failed:_(),skipped:_(),notRun:_(),durationMs:_(),failures:{type:`array`,items:d()},tests:{type:`array`,items:d()},snapshotDiagnostics:d()},[`total`,`executed`,`passed`,`failed`,`skipped`,`notRun`,`durationMs`,`failures`,`tests`]),record:{type:`object`,oneOf:[x({recording:y(`started`),outPath:m(),sessionStateDir:m(),recordingBackend:m(),recordingScope:m(),recordOnlySession:f(),activeSessionApp:d(),showTouches:f()},[`recording`,`outPath`,`sessionStateDir`,`showTouches`]),x({recording:y(`stopped`),outPath:m(),telemetryPath:m(),artifacts:{type:`array`,items:w},recordingBackend:m(),recordingScope:m(),recordOnlySession:f(),activeSessionApp:d(),durationMs:_(),showTouches:f(),warning:m(),overlayWarning:m(),chunks:{type:`array`,items:d()}},[`recording`,`outPath`,`artifacts`,`durationMs`,`showTouches`])]},trace:{type:`object`,oneOf:[x({trace:y(`started`),outPath:m()},[`trace`,`outPath`]),x({trace:y(`stopped`),outPath:m(),artifacts:{type:`array`,items:w}},[`trace`,`outPath`,`artifacts`])]}},be={devices:{type:`object`,properties:{devices:{type:`array`,items:{type:`object`,properties:{platform:{type:`string`,enum:c},target:{type:`string`,enum:l},kind:{type:`string`,enum:g},id:{type:`string`},name:{type:`string`}},required:[`platform`,`target`,`kind`,`id`,`name`]}}},required:[`devices`]},apps:{type:`object`,properties:{apps:{type:`array`,items:{type:`string`}}},required:[`apps`]}},A={...ye,...be};function xe(t){return e(t)}function Se(e){let t=[`Error (${e.code}): ${e.message}`];e.hint&&t.push(`Hint: ${e.hint}`),t.push(...ne(e.details)),e.supportedOn&&t.push(`Supported on: ${e.supportedOn}`);let n=u(e.details);return n&&t.push(n),t.join(`
|
|
2
|
-
`)}function Ce(e,t,n){let r=ue({command:e,cwd:process.cwd(),cliFlags:t}),i={};for(let[t,a]of Object.entries(r))Object.hasOwn(n,t)&&ce(t,e)&&(i[t]=a);return le(i,t)}const we={devices:e=>({devices:e.map(te)}),apps:e=>({apps:e})};function Te(e,t){let n=we[e];return n?n(t):t}function Ee(){let e=new Map;return{pinInput:(t,n,r)=>Be(t,n,je(e,r,n.session)),mergeCommandResult:(t,n,r,i)=>Me(e,t,n,r,i),mergeErrorDetails:(t,n,r)=>{let i=j(n,r);De(e,i,t),Re(e,i,t)}}}function De(e,t,n){let r=n?.refsGeneration;typeof r==`number`&&M(e,t,ee(n),r)}const Oe=new Set([`snapshot`,`find`]),ke=new Set(a.map(e=>e.name).filter(h).filter(e=>o(e))),Ae=new Set([`press`,`click`,`fill`,`longpress`,`get`]);function je(e,t,n){return e.get(j(t,n))}function j(e,t){let n=typeof t==`string`&&t.length>0?t:`default`;return`${e??``}\u0000${n}`}function Me(e,t,n,r,i){let a=j(r,i);if(ke.has(t)){Fe(e,a,Ie(n));return}Oe.has(t)&&(t===`find`?Pe(e,a,n):Ne(e,a,n))}function Ne(e,t,n){let r=n.refsGeneration;if(typeof r!=`number`){e.delete(t);return}let i=[];for(let{ref:e}of n.refs??[])i.push(e);for(let e of n.nodes??[])i.push(e.ref);M(e,t,i,r)}function Pe(e,t,n){let r=n.refsGeneration;if(typeof r!=`number`)return;let i=[];typeof n.ref==`string`&&n.ref.startsWith(`@`)&&i.push(n.ref.slice(1));for(let e of n.matches??[])typeof e.ref==`string`&&e.ref.length>0&&i.push(e.ref.startsWith(`@`)?e.ref.slice(1):e.ref);M(e,t,i,r)}function Fe(e,t,n){n?.refsGeneration!==void 0&&M(e,t,[...n.diff?.lines??[],...n.refs??[],...n.tail??[]].map(e=>e.ref).filter(e=>typeof e==`string`),n.refsGeneration)}function Ie(e){let t=e.settle;return typeof t==`object`&&t?t:void 0}function M(e,t,n,r){if(n.length===0)return;let i=e.get(t)??new Map;e.set(t,i),Le(i,n,r)}function Le(e,t,n){for(let r of t)e.delete(r),e.set(r,n);for(;e.size>1e3;)e.delete(e.keys().next().value)}function Re(e,t,n){let r=i(i(n?.divergence)?.screen);if(r?.state!==`available`)return;let a=r.refsGeneration;if(typeof a!=`number`)return;let o=[];ze(r.refs,o),M(e,t,o,a)}function ze(e,t){if(Array.isArray(e))for(let n of e){let e=i(n)?.ref;typeof e==`string`&&e.length>0&&t.push(e)}}function Be(e,t,n){return n===void 0||n.size===0?t:e===`wait`?Ve(t,n)??t:Ae.has(e)?He(t,n)??t:t}function Ve(e,t){if(typeof e.ref!=`string`)return;let n=N(e.ref,t);return n===e.ref?void 0:{...e,ref:n}}function He(e,t){let n=i(e.target);if(n?.kind!==`ref`||typeof n.ref!=`string`)return;let r=N(n.ref,t);return r===n.ref?void 0:{...e,target:{...n,ref:r}}}function N(e,t){if(!e.startsWith(`@`)||e.includes(`~`))return e;let n=t.get(e.slice(1));return n===void 0?e:`${e}~s${n}`}function Ue(){return ae().map(e=>{let t=e.name in A?A[e.name]:void 0;return{name:e.name,description:re(e),inputSchema:P(e.name,e.inputSchema),...t?{outputSchema:t}:{}}})}function We(e={}){let n=Ee();return{execute:async(r,i)=>{if(!h(r))throw new t(`INVALID_ARGS`,`Unknown command tool: ${r}`);let a=P(r,oe(r).inputSchema).properties,o=Ce(r,i,a),s=Ye(o),c=$e(o),l=n.pinInput(r,c,s.client.stateDir),u=await qe(e,s.client);try{let t=await(e.runCommand??Je)(u,r,l);return n.mergeCommandResult(r,t,s.client.stateDir,c.session),{isError:!1,structuredContent:Te(r,t),content:[{type:`text`,text:et({name:r,input:c,result:t,outputFormat:s.outputFormat,responseLevel:s.client.responseLevel})}]}}catch(e){return Ge(e,n,s.client.stateDir,c.session)}}}}function Ge(e,t,n,r){let i=xe(e);return t.mergeErrorDetails(i.details,n,r),{isError:!0,structuredContent:i,content:[{type:`text`,text:Se(i)}]}}const Ke=We();async function qe(e,t){if(e.createClient)return await e.createClient(t);let{createAgentDeviceClient:n}=await import(`./agent-device-client.js`).then(e=>e.t);return n(t)}async function Je(e,t,n){return await(await import(`./command-surface.js`).then(e=>e.t)).runCommand(e,t,n)}function Ye(e){return{client:Xe(e),outputFormat:Qe(e.mcpOutputFormat)}}function Xe(e){let n=e.stateDir,r=e.includeCost,i=e.responseLevel,a={};if(n!==void 0){if(typeof n!=`string`||n.length===0)throw new t(`INVALID_ARGS`,`Expected stateDir to be a non-empty string.`);a.stateDir=n}if(r!==void 0){if(typeof r!=`boolean`)throw new t(`INVALID_ARGS`,`Expected includeCost to be a boolean.`);r&&(a.cost=!0)}let o=Ze(i);return o!==void 0&&(a.responseLevel=o),a}function Ze(e){if(e===void 0)return;let r=n.find(t=>t===e);if(r===void 0)throw new t(`INVALID_ARGS`,`Expected responseLevel to be one of 'digest', 'default', or 'full'.`);return r}function Qe(e){if(e===void 0)return`optimized`;if(e!==`optimized`&&e!==`json`)throw new t(`INVALID_ARGS`,`Expected mcpOutputFormat to be "optimized" or "json".`);return e}function $e(e){let{stateDir:t,mcpOutputFormat:n,includeCost:r,responseLevel:i,...a}=e;return a}function P(e,t){let n=s(e);return{...t,properties:{...t.properties,...n&&!t.properties?.noRecord?{noRecord:{type:`boolean`,description:`Do not record this action.`}}:{},stateDir:{type:`string`,description:`Agent-device state directory.`},mcpOutputFormat:{type:`string`,enum:[`optimized`,`json`],description:`MCP text content format. Defaults to optimized agent-friendly text; use json for JSON text. Structured content is always returned separately.`},includeCost:{type:`boolean`,description:`Include per-command agent-cost (cost.wallClockMs, …) in structuredContent. Defaults to off; the default response shape is unchanged.`},responseLevel:{type:`string`,enum:[`digest`,`default`,`full`],description:`Response verbosity: token-cheap digest / default (today) / full. Defaults to default; the default response shape is unchanged.`}}}}function et(e){if(e.outputFormat===`json`||e.responseLevel!==void 0&&e.responseLevel!=="default")return F(e.result);let t=de({name:e.name,input:e.input,result:e.result});return typeof t?.text==`string`?t.text:F(t?.data??e.result)}function F(e){return typeof e==`string`?e:JSON.stringify(e,null,2)}const I=`2026-07-28`,L=[I],R=[`2025-11-25`,`2025-06-18`],z=[...L,...R],B=`server/discover`,tt=new Set([`initialize`,`ping`]),V=`io.modelcontextprotocol/protocolVersion`,H=`io.modelcontextprotocol/clientCapabilities`,U=`io.modelcontextprotocol/clientInfo`,W=36e5;var G=class extends Error{requested;constructor(e){super(`Unsupported MCP protocol version: ${e}. Supported: ${z.join(`, `)}.`),this.requested=e}get data(){return{supported:z,requested:this.requested}}};function nt(e,n){let r=X(X(n)._meta),i=ut(r,V);if(i===void 0){if(e===B)throw new t(`INVALID_ARGS`,`Expected _meta["${V}"] on ${B}.`);return`legacy`}if(!z.includes(i))throw new G(i);if(!q(r[H]))throw new t(`INVALID_ARGS`,`Expected _meta["${H}"] to be an object.`);let a=r[U];if(a!==void 0&&!st(a))throw new t(`INVALID_ARGS`,`Expected _meta["${U}"] to be a valid Implementation.`);if(!L.includes(i)){if(e===B)throw new G(i);return`legacy`}return`modern`}function rt(e){let t=ut(X(e),`protocolVersion`);return t!==void 0&&R.includes(t)?t:`2025-11-25`}function it(e,t){return t===`modern`&&tt.has(e)}function K(){return{name:`agent-device`,version:se()}}function at(e,t){return t===`legacy`||typeof e!=`object`||!e?e:{resultType:`complete`,...e,_meta:{...e._meta,"io.modelcontextprotocol/serverInfo":K()}}}function ot(e,t){return e===`modern`?{ttlMs:t,cacheScope:`public`}:void 0}function q(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function st(e){return!q(e)||!Y(e.name)||!Y(e.version)?!1:J(e.title,Y)&&J(e.description,Y)&&J(e.websiteUrl,Y)&&J(e.icons,e=>Array.isArray(e)&&e.every(ct))}function ct(e){return!q(e)||!Y(e.src)?!1:J(e.mimeType,Y)&&J(e.sizes,lt)&&J(e.theme,e=>e===`light`||e===`dark`)}function J(e,t){return e===void 0||t(e)}function Y(e){return typeof e==`string`}function lt(e){return Array.isArray(e)&&e.every(Y)}function X(e){return q(e)?e:{}}function ut(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}async function dt(e){if(e.jsonrpc!==`2.0`||typeof e.method!=`string`)return Z(e.id??null,-32600,`Invalid JSON-RPC request.`);if(e.id===void 0)return null;try{let t=nt(e.method,e.params),n=await ft(e.method,e.params,t);return ht(e.id,at(n,t))}catch(t){return t instanceof G?Z(e.id,-32022,t.message,t.data):t instanceof Q?Z(e.id,-32601,t.message):Z(e.id,-32602,t instanceof Error?t.message:String(t))}}async function ft(e,t,n){if(it(e,n))throw new Q(`${e} was removed in MCP ${I}.`);switch(e){case`server/discover`:return{supportedVersions:z,capabilities:{tools:{}},instructions:`agent-device drives iOS, Android, tvOS, Android TV, macOS, Linux, and web targets. Each tool mirrors the CLI command of the same name; tool descriptions carry the per-command contract.`,ttlMs:W,cacheScope:`public`};case`initialize`:return{protocolVersion:rt(t),capabilities:{tools:{}},serverInfo:K()};case`ping`:return{};case`tools/list`:return{tools:Ue(),...ot(n,W)};case`tools/call`:return await pt(t);default:throw new Q(`Unsupported MCP method: ${e}`)}}async function pt(e){let t=gt(e),n=vt(t,`name`);try{return await Ke.execute(n,_t(t.arguments))}catch(e){return mt(Se(xe(e)),!0)}}function mt(e,t=!1){return{isError:t,content:[{type:`text`,text:e}]}}function ht(e,t){return{jsonrpc:`2.0`,id:e,result:t}}function Z(e,t,n,r){return{jsonrpc:`2.0`,id:e,error:{code:t,message:n,...r?{data:r}:{}}}}function gt(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new t(`INVALID_ARGS`,`Expected object parameters.`);return e}function _t(e){return e===void 0?{}:gt(e)}function vt(e,n){let r=e[n];if(typeof r!=`string`||r.length===0)throw new t(`INVALID_ARGS`,`Expected ${n} to be a non-empty string.`);return r}var Q=class extends Error{};async function yt(){let e=bt(),t=new Et(t=>{e.push(t)});process.stdin.setEncoding(`utf8`),process.stdin.on(`data`,e=>{try{t.push(e)}catch(e){Ot({jsonrpc:`2.0`,id:null,error:{code:-32700,message:e instanceof Error?e.message:String(e)}})}}),await new Promise(e=>{process.stdin.on(`end`,e),process.stdin.on(`close`,e),process.stdin.resume()}),await e.idle()}function bt(e={}){let t=e.handlePayload??xt,n=e.write??Ot,r=Promise.resolve();return{push:e=>{let i=Tt(e);r=r.then(async()=>{let r=await t(e);r&&n(r)}).catch(e=>{n({jsonrpc:`2.0`,id:i,error:{code:-32603,message:e instanceof Error?e.message:String(e)}})})},idle:async()=>{await r}}}function xt(e){return Array.isArray(e)?St(e):Ct(e)}async function St(e){let t=[];for(let n of e)t.push(...Dt(await Ct(n)));return t.length>0?t:null}async function Ct(e){let t;try{t=r.parse(e)}catch{return wt($(e))}return dt(t)}function wt(e){return{jsonrpc:`2.0`,id:e,error:{code:-32600,message:`Invalid JSON-RPC request.`}}}function Tt(e){return Array.isArray(e)?e.length===1?$(e[0]):null:$(e)}function $(e){if(e&&typeof e==`object`&&!Array.isArray(e)){let t=e.id;if(typeof t==`string`||typeof t==`number`||t===null)return t}return null}var Et=class{buffer=``;sink;constructor(e){this.sink=e}push(e){for(this.buffer+=e;;){let e=this.tryReadLineMessage();if(e!==void 0){this.emit(e);continue}break}}tryReadLineMessage(){let e=this.buffer.indexOf(`
|
|
3
|
-
|
|
1
|
+
import{s as e,y as t}from"./sdk-contracts.js";import{g as n}from"./sdk-batch.js";import{i as r}from"./catalog.js";import{r as i}from"./version.js";import{a,i as ee,r as o,t as te}from"./command-tools.js";import{i as s,r as c,t as l}from"./cli-help.js";const u=`agent-device drives iOS, Android, tvOS, Android TV, macOS, Linux, and web apps. Tools mirror CLI commands of the same name; CLI flags are camelCase properties (--settle -> settle: true).
|
|
2
|
+
|
|
3
|
+
Start: known app -> call open {app, foreground: true} at once; do not probe with devices, apps, appstate, snapshot, or screenshot first. open returns the initial interactive snapshot with @refs. Unknown app id: devices, then apps, then open the discovered id; never invent ids. Existing session: continue from its state, do not reopen.
|
|
4
|
+
|
|
5
|
+
Loop: press/click/fill/longpress/hover/scroll/back with settle: true; the response is the settled UI diff, continue from it. snapshot {interactiveOnly: true} only when the diff lacks the next target or did not settle. Verify with wait {kind: "text", text}, wait {selector}, wait {absent: selector}, is, get, or find; a bare screenshot is not verification. End with close.
|
|
6
|
+
|
|
7
|
+
Targets: copy refs byte-for-byte (@e12, @e12~s4; keep @ and any ~sN). Refs go stale after mutations. Prefer refs, then id/label/role selectors; coordinates last. On a sparse/AX-unavailable warning its refs and selectors are invalid: screenshot, read the image, press {x, y}, then snapshot the changed screen.
|
|
8
|
+
|
|
9
|
+
Errors carry hints; follow them instead of re-planning. Call help only for specialized work (gestures, scripting, TV, macOS, web, remote, debugging) or an unclear command shape, never at startup.`;function d(){let e=new Set(n());return r().filter(t=>!e.has(t))}const f={name:`help`,description:`Usage guides. No topic: the full workflow card. topic = one of ${c().join(`, `)} for that guide, or a tool name for its complete flag reference. For specialized work or an unclear command shape only; not a startup step, not needed after an error that carries a hint.`,inputSchema:{type:`object`,properties:{topic:{type:`string`,description:`Guide topic or tool name; omit for the card.`}},additionalProperties:!1}},p=`CLI syntax over MCP: \`agent-device <command> <positionals> --flag\` = tool <command>; positionals are named properties (target, text, direction), flags camelCase (--settle -> settle: true, -i -> interactiveOnly: true). Terminal-only (no MCP tool; run in a shell): ${d().join(`, `)}.\n\n`;function ne(e){let t=e.topic;if(t!==void 0&&typeof t!=`string`)return m(`Expected topic to be a string.`,!0);let n=t?s(t):l();return n===null?m(`Unknown help topic: ${t}. ${f.description}`,!0):m(p+n)}function m(e,t=!1){return{isError:t,content:[{type:`text`,text:e}]}}const h=`2026-07-28`,g=[h],_=[`2025-11-25`,`2025-06-18`],v=[...g,..._],y=`server/discover`,b=new Set([`initialize`,`ping`]),x=`io.modelcontextprotocol/protocolVersion`,S=`io.modelcontextprotocol/clientCapabilities`,C=`io.modelcontextprotocol/clientInfo`,w=36e5;var T=class extends Error{requested;constructor(e){super(`Unsupported MCP protocol version: ${e}. Supported: ${v.join(`, `)}.`),this.requested=e}get data(){return{supported:v,requested:this.requested}}};function E(e,n){let r=I(I(n)._meta),i=L(r,x);if(i===void 0){if(e===y)throw new t(`INVALID_ARGS`,`Expected _meta["${x}"] on ${y}.`);return`legacy`}if(!v.includes(i))throw new T(i);if(!A(r[S]))throw new t(`INVALID_ARGS`,`Expected _meta["${S}"] to be an object.`);let a=r[C];if(a!==void 0&&!j(a))throw new t(`INVALID_ARGS`,`Expected _meta["${C}"] to be a valid Implementation.`);if(!g.includes(i)){if(e===y)throw new T(i);return`legacy`}return`modern`}function D(e){let t=L(I(e),`protocolVersion`);return t!==void 0&&_.includes(t)?t:`2025-11-25`}function O(e,t){return t===`modern`&&b.has(e)}function k(){return{name:`agent-device`,version:i()}}function re(e,t){return t===`legacy`||typeof e!=`object`||!e?e:{resultType:`complete`,...e,_meta:{...e._meta,"io.modelcontextprotocol/serverInfo":k()}}}function ie(e,t){return e===`modern`?{ttlMs:t,cacheScope:`public`}:void 0}function A(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function j(e){return!A(e)||!P(e.name)||!P(e.version)?!1:N(e.title,P)&&N(e.description,P)&&N(e.websiteUrl,P)&&N(e.icons,e=>Array.isArray(e)&&e.every(M))}function M(e){return!A(e)||!P(e.src)?!1:N(e.mimeType,P)&&N(e.sizes,F)&&N(e.theme,e=>e===`light`||e===`dark`)}function N(e,t){return e===void 0||t(e)}function P(e){return typeof e==`string`}function F(e){return Array.isArray(e)&&e.every(P)}function I(e){return A(e)?e:{}}function L(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}async function R(e){if(e.jsonrpc!==`2.0`||typeof e.method!=`string`)return U(e.id??null,-32600,`Invalid JSON-RPC request.`);if(e.id===void 0)return null;try{let t=E(e.method,e.params),n=await z(e.method,e.params,t);return H(e.id,re(n,t))}catch(t){return t instanceof T?U(e.id,-32022,t.message,t.data):t instanceof q?U(e.id,-32601,t.message):U(e.id,-32602,t instanceof Error?t.message:String(t))}}async function z(e,t,n){if(O(e,n))throw new q(`${e} was removed in MCP ${h}.`);switch(e){case`server/discover`:return{supportedVersions:v,capabilities:{tools:{}},instructions:u,ttlMs:w,cacheScope:`public`};case`initialize`:return{protocolVersion:D(t),capabilities:{tools:{}},serverInfo:k(),instructions:u};case`ping`:return{};case`tools/list`:return{tools:[...o(),f],...ie(n,w)};case`tools/call`:return await B(t);default:throw new q(`Unsupported MCP method: ${e}`)}}async function B(e){let t=W(e),n=K(t,`name`);try{return n===`help`?ne(G(t.arguments)):await te.execute(n,G(t.arguments))}catch(e){return V(ee(a(e)),!0)}}function V(e,t=!1){return{isError:t,content:[{type:`text`,text:e}]}}function H(e,t){return{jsonrpc:`2.0`,id:e,result:t}}function U(e,t,n,r){return{jsonrpc:`2.0`,id:e,error:{code:t,message:n,...r?{data:r}:{}}}}function W(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new t(`INVALID_ARGS`,`Expected object parameters.`);return e}function G(e){return e===void 0?{}:W(e)}function K(e,n){let r=e[n];if(typeof r!=`string`||r.length===0)throw new t(`INVALID_ARGS`,`Expected ${n} to be a non-empty string.`);return r}var q=class extends Error{};async function J(){let e=Y(),t=new ce(t=>{e.push(t)});process.stdin.setEncoding(`utf8`),process.stdin.on(`data`,e=>{try{t.push(e)}catch(e){$({jsonrpc:`2.0`,id:null,error:{code:-32700,message:e instanceof Error?e.message:String(e)}})}}),await new Promise(e=>{process.stdin.on(`end`,e),process.stdin.on(`close`,e),process.stdin.resume()}),await e.idle()}function Y(e={}){let t=e.handlePayload??X,n=e.write??$,r=Promise.resolve();return{push:e=>{let i=se(e);r=r.then(async()=>{let r=await t(e);r&&n(r)}).catch(e=>{n({jsonrpc:`2.0`,id:i,error:{code:-32603,message:e instanceof Error?e.message:String(e)}})})},idle:async()=>{await r}}}function X(e){return Array.isArray(e)?ae(e):Z(e)}async function ae(e){let t=[];for(let n of e)t.push(...le(await Z(n)));return t.length>0?t:null}async function Z(t){let n;try{n=e.parse(t)}catch{return oe(Q(t))}return R(n)}function oe(e){return{jsonrpc:`2.0`,id:e,error:{code:-32600,message:`Invalid JSON-RPC request.`}}}function se(e){return Array.isArray(e)?e.length===1?Q(e[0]):null:Q(e)}function Q(e){if(e&&typeof e==`object`&&!Array.isArray(e)){let t=e.id;if(typeof t==`string`||typeof t==`number`||t===null)return t}return null}var ce=class{buffer=``;sink;constructor(e){this.sink=e}push(e){for(this.buffer+=e;;){let e=this.tryReadLineMessage();if(e!==void 0){this.emit(e);continue}break}}tryReadLineMessage(){let e=this.buffer.indexOf(`
|
|
10
|
+
`);if(e===-1)return;let t=this.buffer.slice(0,e).trim();return this.buffer=this.buffer.slice(e+1),t.length>0?t:void 0}emit(e){this.sink(JSON.parse(e))}};function le(e){return e?[e]:[]}function $(e){process.stdout.write(`${JSON.stringify(e)}\n`)}export{Y as createMcpPayloadQueue,X as handleMcpPayload,J as runAgentDeviceMcpServer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{y as e}from"./sdk-contracts.js";import{a as t}from"./request-cancellation.js";import{c as n,r,t as i}from"./device-session.js";import{assertLimrunUploadedAppAccess as a,resolveInstalledAppIdForAsset as o,resolveLimrunAppAsset as s}from"./app-catalog.js";async function c(e,t,n){let r=n?.initialApp,i=typeof r==`string`?r.trim():``;if(i)return a(n?.publicNetworkOnly),await s(e,t,i,n?.signal)}async function l(t,n){let r=await i(t).listApps(`user-installed`),a=o(n.name,r);if(a)return a;throw new e(`COMMAND_FAILED`,`Limrun installed ${n.name}, but its application identifier could not be resolved unambiguously.`,{asset:n.name,installedApps:r.map(e=>e.id)})}async function u(n){let i=await n.limrun.iosInstances.create({wait:!0,metadata:n.metadata,spec:{...n.region?{region:n.region}:{},...n.app?{initialAssets:[{kind:`App`,source:`AssetID`,assetId:n.app.id,launchMode:`RelaunchIfRunning`}]}:{}}});try{if(!i.status.apiUrl)throw new e(`COMMAND_FAILED`,`Limrun iOS instance did not expose apiUrl`);return await r({lease:n.lease,instanceId:i.metadata.id,device:t(`ios`,n.lease,i.metadata.id),apiUrl:i.status.apiUrl,token:i.status.token},n.dependencies)}catch(e){throw await n.limrun.iosInstances.delete(i.metadata.id).catch(()=>{}),e}}async function d(r){let i=await r.limrun.androidInstances.create({wait:!0,metadata:r.metadata,spec:{...r.region?{region:r.region}:{},...r.app?{initialAssets:[{kind:`App`,source:`AssetIDs`,assetIds:[r.app.id]}]}:{}}});try{if(!i.status.apiUrl||!i.status.adbWebSocketUrl)throw new e(`COMMAND_FAILED`,`Limrun Android instance did not expose API and ADB websocket endpoints`);return await n({lease:r.lease,instanceId:i.metadata.id,device:t(`android`,r.lease,i.metadata.id),apiUrl:i.status.apiUrl,token:i.status.token,adbUrl:i.status.adbWebSocketUrl},r.dependencies)}catch(e){throw await r.limrun.androidInstances.delete(i.metadata.id).catch(()=>{}),e}}export{d as allocateLimrunAndroidSession,u as allocateLimrunIosSession,l as resolvePreinstalledAppId,c as resolveRequestedLimrunAppAsset};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./session-paths.js";import t from"node:path";function n(e){return t.join(e,`runner.log`)}function r(n,r){let i=e(r&&r.length>0?r:`unknown`);return t.join(n,`requests`,`${i}.ndjson`)}function i(e){return{path:r(e.sessionDir,e.requestId),ref:{session:e.session,requestId:e.requestId&&e.requestId.length>0?e.requestId:`unknown`}}}function a(n,i){return r(t.join(n,`remote-diagnostics`,e(i.session)),i.requestId)}export{n as i,i as n,r,a as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./path-resolution.js";import"./file.js";function t(e){return e.replaceAll(/[^a-zA-Z0-9._-]/g,`_`)}function n(e){let n=t(e);return n.length>0&&n!==`.`&&n!==`..`}function r(t,n){return e(t,{cwd:n})}export{n,t as r,r as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"node:path";import t from"node:fs";function n(t){return e.join(t,`repair-tombstone.json`)}function r(e){let n;try{n=t.readFileSync(e,`utf8`)}catch{return}let r;try{r=JSON.parse(n)}catch{return}if(!(typeof r?.expiresAt!=`number`||r.expiresAt<=Date.now()))return r}function i(i){let a;try{a=t.readdirSync(i,{withFileTypes:!0})}catch{return}for(let t of a){if(!t.isDirectory())continue;let a=r(n(e.join(i,t.name)));if(a?.commitFailure)return{sessionName:t.name,tombstone:{...a,commitFailure:a.commitFailure}}}}export{r as n,n as r,i as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{y as e}from"./sdk-contracts.js";import"./session-store.js";import t from"node:path";import n from"node:fs";import r from"node:crypto";const i=`default`;function a(e,t){let n=e.session||i;if(d(e))return n;let r=c(e);return r.kind===`cwd`?f(r.id,n):n}function o(e){return e.session||i}function s(e){let t=c(e);return t.kind===`cwd`?t:void 0}function c(t){if(t.meta?.sessionIsolation===`tenant`||t.flags?.sessionIsolation===`tenant`){let n=t.meta?.tenantId;if(!n)throw new e(`INTERNAL_ERROR`,`Tenant-scoped request reached session routing without an admitted tenant id`);return{kind:`tenant`,id:n}}if(d(t)||(t.session||i)!==i)return{kind:`named-local`};let n=m(t.meta?.cwd);return n?{kind:`cwd`,id:p(n)}:{kind:`global-default`}}function l(e,t){let n=e.sessionScope;return n?t.kind===`tenant`?n.kind===`tenant`&&n.id===t.id:n.kind===`tenant`?!1:t.kind!==`cwd`||n.kind===`named-local`||n.kind===`cwd`&&n.id===t.id:!1}function u(e,t){let n=s(e);return!n||t.sessionScope?.kind!==`cwd`?!1:t.sessionScope.id!==n.id}function d(e){if(e.meta?.sessionExplicit===!0)return!0;let t=e.flags?.session;return typeof t==`string`&&t.trim().length>0}function f(e,t){return`cwd:${e}:${t}`}function p(e){return r.createHash(`sha256`).update(e).digest(`hex`).slice(0,16)}function m(e){if(!e||e.trim().length===0)return;let t=h(e);return g(t)??t}function h(e){let r=t.resolve(e);try{return n.realpathSync.native(r)}catch{return r}}function g(e){let r=e;for(;;){if(n.existsSync(t.join(r,`.git`)))return r;let e=t.dirname(r);if(e===r)return;r=e}}export{c as a,o as i,u as n,l as o,a as r,d as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{y as e}from"./sdk-contracts.js";import{i as t}from"./request-runtime-binding.js";function n(e,n){if(!n.available)return t(`UNSUPPORTED_OPERATION`,`${e} is not supported on this device`,{reason:n.reason},n.hint?{hint:n.hint}:void 0)}function r(t){if(t)return t;throw new e(`COMMAND_FAILED`,`Device runtime facts inspection is unavailable.`)}const i=new WeakMap;let a;(class e{static{a=(t,n)=>{let r=new e;return i.set(r,{device:Object.freeze({...t}),plan:n}),Object.freeze(r),r}}#e;constructor(){this.#e=void 0}get admitted(){return this.#e,!0}});function o(t){let n=i.get(t);if(n===void 0)throw new e(`COMMAND_FAILED`,`Runtime plan admission is not one minted by admitRuntimePlan; refusing to bind.`);return n}async function s(e){let t=await r(e.inspectFacts)(e.device);for(let n of e.plan.use.required){let e=t.operations[n];if(!e.available)return{admitted:!1,operation:n,fact:e}}return a(e.device,e.plan)}function c(t){if(t)return t;throw new e(`COMMAND_FAILED`,`Device runtime binding is unavailable.`)}export{o as a,n as i,c as n,r,s as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as e,m as t,y as n}from"./sdk-contracts.js";import{u as r}from"./capture.js";import{r as i}from"./snapshot-capture-annotations.js";import{r as a}from"./snapshot-diagnostics.js";import{f as o}from"./android-input-ownership.js";import{c as s,d as c,v as l}from"./sdk-device.js";import{It as u,St as d,Tr as f,ct as ee,lt as te,ot as ne,pt as re,st as ie,vt as ae,zt as oe}from"./sdk-batch.js";import{C as se,u as ce,w as le}from"./runtime.js";import{n as p}from"./success-text.js";import{i as ue}from"./click-button.js";import{a as de,r as m}from"./diagnostics.js";import{t as h}from"./timeouts.js";import"./diagnostics2.js";import"./retry.js";import{t as fe}from"./snapshot-state.js";import{i as pe}from"./lease-context.js";import{i as g,n as me}from"./request-runtime-binding.js";import{t as he}from"./interactor-types.js";import{randomInt as ge}from"node:crypto";var _=class e{#e;constructor(e){this.#e=e}get state(){return this.#e.state}get scope(){return this.#e.scope}get tree(){return this.#e.tree}get generation(){return this.#e.generation}static expire(t){return t.#e.state===`expired`?t:new e({...t.#e,state:`expired`})}};const _e=new _({state:`active`,scope:`all`,tree:void 0,generation:void 0});function ve(e){return new _({state:`active`,...e})}function ye(e){return _.expire(e)}const be=new WeakMap;function v(e){return e.refFrame??_e}function y(e){return v(e).generation??e.snapshotGeneration}function xe(e){return v(e).tree}function Se(e){Ce(e),e.refFrame=ye(v(e)),e.snapshotScopeSource=void 0}function Ce(e){let t=we(e)+1;return be.set(e,t),t}function we(e){return be.get(e)??0}function Te(e){b(e,`all`)}function Ee(e,t){b(e,t)}function b(e,t){e.refFrame=ve({scope:t,tree:e.snapshot,generation:e.snapshotGeneration})}function x(e){return v(e).state}function S(e){return v(e).scope}function De(e){let t=e.ref.startsWith(`@`)?e.ref.slice(1):e.ref;return{admission:Oe({session:e.session,refBody:t,mintedGeneration:e.mintedGeneration}),scope:S(e.session),currentGeneration:y(e.session)}}function Oe(e){let{session:t,refBody:n,mintedGeneration:r}=e;if(x(t)===`expired`)return{admitted:!1,reason:`ref_frame_expired`};if(r!==void 0&&r!==y(t))return{admitted:!1,reason:`ref_generation_mismatch`};let i=S(t);if(i!==`all`){if(r===void 0)return{admitted:!1,reason:`plain_ref_requires_complete_frame`};if(!i.has(n))return{admitted:!1,reason:`ref_not_issued`}}return{admitted:!0}}const ke=[250,400,600];function C(e){return e===`press`||e===`click`||e===`back`||e===`open`}function w(e){return e.map(e=>[e.depth??0,e.type??``,e.label??``,e.value??``,e.identifier??``,e.enabled===!1?`disabled`:`enabled`,e.hittable===!0?`hittable`:`not-hittable`].join(`|`))}function Ae(e,t){return e<12?!1:t<=Math.floor(e*.2)}function je(e,t,n){return n.interactiveOnly&&e.snapshot.nodes.length===0&&e.rawNodeCount!==void 0&&e.rawNodeCount>=12?`empty-interactive`:n.mode===`ref-refresh`?null:Ae(t.baselineCount,e.snapshot.nodes.length)?Me(e.snapshot)?null:`sharp-drop`:t.routeComparable&&C(t.action)&&Ne(t.baselineSignatures,e.snapshot.nodes)?`stuck-route`:null}function Me(e){return e.nodes.some(e=>e.hittable===!0||!!e.label?.trim()||!!e.value?.trim()||!!e.identifier?.trim())}function Ne(e,t){if(!e||e.length===0)return!1;let n=Math.max(e.length,t.length);if(n<12)return!1;let r=w(t),i=Math.min(e.length,r.length),a=0;for(let t=0;t<i;t+=1)e[t]===r[t]&&(a+=1);let o=Math.max(0,r.length-e.length),s=Math.max(0,e.length-r.length),c=Math.max(3,Math.floor(n*.15));return a>=Math.floor(n*.9)&&o<=c&&s<=c}async function Pe(e){let t=e.window.markedAt+e.retry.retryBudgetMs,n=await e.capture(),r=e.classify(n),a=0;for(let i of e.retry.delaysMs){if(!r)break;let o=t-Date.now();if(o<=0)break;await h(Math.min(i,o)),n=await e.capture(),a+=1,r=e.classify(n)}r||e.onTrustworthyCapture?.();let o=a>0||r?{action:e.window.action,retryCount:a,staleAfterRetries:!!r,reason:r??void 0}:void 0;return{...n,annotations:{...n.annotations,...i({freshness:o})}}}function Fe(e,t,n=e.snapshot){if(e.device.platform!==`android`)return;let r=Ie(e,n),i=r?.comparisonSafe===!0;e.androidSnapshotFreshness={action:t,markedAt:Date.now(),baselineCount:(r??n)?.nodes.length??0,baselineSignatures:i?w(r?.nodes??[]):void 0,routeComparable:i}}function Ie(e,t){if(t?.comparisonSafe===!0)return t;let n=e.lastComparisonSafeSnapshot;return!n||n.comparisonSafe!==!0?t:Date.now()-n.createdAt<=5e3?n:t}function T(e){if(!e||e.device.platform!==`android`)return;let t=e.androidSnapshotFreshness;if(t){if(Date.now()-t.markedAt>2500){delete e.androidSnapshotFreshness;return}return t}}function E(e){!e||e.device.platform!==`android`||delete e.androidSnapshotFreshness}async function Le(e,t){return Pe({capture:e.capture,classify:n=>je({snapshot:n.snapshot,rawNodeCount:n.annotations.analysis?.rawNodeCount},t,{interactiveOnly:e.interactiveOnly,mode:e.androidFreshnessMode}),window:t,retry:{retryBudgetMs:1500,delaysMs:ke},onTrustworthyCapture:()=>E(e.session)})}function Re(e,t){return`${[e,...t].join(` `).trim()} produced no visible change: the tree still matches its pre-gesture state. Either the container is already at its edge, or it ignores synthesized scrolls — a raw drag moves such lists: swipe x1 y1 x2 y2 (start inside the list).`}function ze(e,t){return t?{...e,warnings:[...e.warnings??[],Re(t.action,t.positionals)]}:e}function D(e,t,n,i,a,o){return{requestId:a??de().requestId,appBundleId:n,runnerLeaseContext:pe({meta:o}),activity:t?.activity,launchConsole:t?.launchConsole,launchArgs:t?.launchArgs,clearAppState:t?.clearAppState,verbose:t?.verbose,logPath:e,traceLogPath:i,iosXctestrunFile:t?.iosXctestrunFile,iosXctestDerivedDataPath:t?.iosXctestDerivedDataPath,iosXctestEnvDir:t?.iosXctestEnvDir,screenshotCaptureBackend:t?.maestro?.screenshotCaptureBackend,snapshotInteractiveOnly:t?.snapshotInteractiveOnly,snapshotPreferredBackend:t?.snapshotPreferredBackend,snapshotDepth:t?.snapshotDepth,snapshotScope:t?.snapshotScope,snapshotRaw:t?.snapshotRaw,snapshotCustomActions:t?.snapshotCustomActions,snapshotIncludeHiddenContentHints:t?.snapshotIncludeHiddenContentHints,...r(t),count:t?.count,intervalMs:t?.intervalMs,delayMs:t?.delayMs,durationMs:t?.durationMs,holdMs:t?.holdMs,jitterPx:t?.jitterPx,pixels:t?.pixels,doubleTap:t?.doubleTap,clickButton:ue(t),backMode:t?.backMode,pauseMs:t?.pauseMs,pattern:t?.pattern}}function Be(e){return e?.interactionOutcome?.retryOnNoChange===!0}function Ve(e){let{session:t,command:n,positionals:r,flags:i,preSnapshot:a}=e;if(!Be(i)||!L(t))return;let o=Ye(n);if(!o||!et(r))return;let s=M(a?.nodes??[]);s.length!==0&&(t.pendingInteractionOutcome={action:n,command:o,positionals:r,flags:j(i),markedAt:Date.now(),attemptsRemaining:2,preSignature:s})}function He(e){let t=e?.pendingInteractionOutcome;if(!(!e||!t)){if(!L(e)){O(e);return}if(Date.now()-t.markedAt>3e4){O(e);return}return t}}function O(e){e?.pendingInteractionOutcome&&(e.pendingInteractionOutcome=void 0)}async function k(e){let{pending:t,snapshot:n}=e,r=N(t.preSignature,M(n.nodes));if(r!==`unchanged`||t.attemptsRemaining<=0)return{retried:!1,change:r};let i=e.retryTap,a=i?R(t.positionals):void 0;if(!i||!a)return A(t,i?`unreadable-retry-point`:`device-runtime-unavailable`),{retried:!1,change:r};let o=Date.now();return--t.attemptsRemaining,await Ue(i,e)?(m({level:`info`,phase:`interaction_no_change_retry`,data:{action:t.action,attemptsRemaining:t.attemptsRemaining,durationMs:Date.now()-o}}),{retried:!0,change:r}):(A(t,`retry-tap-unavailable`),{retried:!1,change:r})}async function Ue(e,t){let{session:n,pending:r}=t,i=R(r.positionals);if(!i)return!1;try{return await e({device:n.device,point:i,context:{...D(t.logPath,r.flags,n.appBundleId,n.trace?.outPath),surface:n.surface}})}catch{return!1}}function A(e,t){m({level:`info`,phase:`interaction_no_change_retry_skipped`,data:{action:e.action,attemptsRemaining:e.attemptsRemaining,reason:t}})}function We(e){m({level:e.attempts>0?`info`:`debug`,phase:`interaction_settled`,data:{action:e.pending.action,change:e.change,attempts:e.attempts,durationMs:Date.now()-e.startedAt}})}function Ge(e){m({level:`warn`,phase:`interaction_settle_timeout`,data:{action:e.pending.action,attempts:e.attempts,durationMs:Date.now()-e.startedAt}})}function j(e){if(!e?.interactionOutcome&&!e?.postGestureStabilization)return e;let{interactionOutcome:t,postGestureStabilization:n,...r}=e;return r}function M(e){let t=new Map,n=[],r=le(e);for(let i of e){let e=Xe(i,t,r);e&&n.push(e)}return n}function N(e,t){return e.length===0||t.length===0?`ambiguous`:F(e,t)?`unchanged`:`changed`}function P(e,t){return Math.abs(e.x-t.x)<=1&&Math.abs(e.y-t.y)<=1&&Math.abs(e.width-t.width)<=1&&Math.abs(e.height-t.height)<=1}function F(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(!r||!i||r.key!==i.key||!P(r,i))return!1}return!0}function Ke(e,t){let n=I(e),r=I(t);if(n.size===0||r.size===0)return`ambiguous`;let i=0,a=!1;for(let[e,t]of n){let n=r.get(e);if(!n){a=!0;continue}if(i+=1,!P(t,n))return`changed`}if(i===0)return`ambiguous`;let o=r.size>i;return a&&o?`changed`:`unchanged`}function I(e){let t=new Map;for(let n of e)!n.identity||!n.discriminating||t.has(n.identity)||t.set(n.identity,n);return t}function qe(e,t){let n=e.filter(e=>e.discriminating),r=t.filter(e=>e.discriminating);if(n.length===0||n.length!==r.length)return!1;let i=new Map(r.map(e=>[e.key,e]));for(let e of n){let t=i.get(e.key);if(!t||!P(e,t))return!1}return!0}function Je(e,t){let n=new Map(t.filter(e=>e.discriminating).map(e=>[e.key,e])),r=0,i=0,a=0;for(let t of e){if(!t.discriminating)continue;let e=n.get(t.key);if(!e){r+=1;continue}n.delete(t.key),a+=1,P(t,e)||(i+=1)}return{onlyInBaseline:r,onlyInCurrent:n.size,rectMismatched:i,shared:a}}function L(e){return c(e.device)}function R(e){let t=Number(e[0]),n=Number(e[1]);return Number.isFinite(t)&&Number.isFinite(n)?{x:t,y:n}:void 0}function Ye(e){if(e===`click`||e===`press`)return`press`}function Xe(e,t,n){if(!e.rect||!tt(e.rect)||nt(e))return;let r=$e(e);if(!r)return;let i=t.get(r)??0;t.set(r,i+1);let a=Ze(e);return{key:`${r}|#${i}`,...a?{identity:a}:{},x:Math.round(e.rect.x),y:Math.round(e.rect.y),width:Math.round(e.rect.width),height:Math.round(e.rect.height),discriminating:!Qe(e,n)}}function Ze(e){let t=[e.identifier,e.label,e.value].map(e=>typeof e==`string`?e.trim():``).join(`|`);if(t.replaceAll(`|`,``))return`${t}|${e.type??``}`}function Qe(e,t){return f(e)||e.ref!==void 0&&t.has(e.ref)}function $e(e){let t=[e.identifier,e.label,e.value,e.type,e.role,e.enabled===!1?`disabled`:`enabled`,e.selected===!0?`selected`:`unselected`,e.hittable===!0?`hittable`:`not-hittable`].map(e=>typeof e==`string`?e.trim():``).join(`|`);return t.replaceAll(`|`,``)?t:void 0}function et(e){return e.length===2&&e.every(e=>Number.isFinite(Number(e)))}function tt(e){return[e.x,e.y,e.width,e.height].every(e=>Number.isFinite(e))&&e.width>0&&e.height>0}function nt(e){return`${e.label??``} ${e.identifier??``}`.toLowerCase().includes(`scroll bar`)}const z=3500;function rt(e){let{needsBaselineDistrust:t,baselineSignature:n,quietSignature:r,elapsedMs:i,distrustCapMs:a}=e;return!t||!n?.length||e.classifyBaselineEvidence(n,r)!==`unchanged`?`trust`:i<a?`distrust`:`accept-stale`}async function it(e){let{pending:t,needsBaselineDistrust:n,hooks:r}=e,i=Date.now(),a=1,o=await B(r,e.initial),s=t.baselineSignature,c=t.baselineBackend,l=!1,u=1500;for(;a<2||Date.now()-i<u;){await h(200),a+=1;let e=await B(r);if(r.signaturesStable(o.signature,e.signature)){let d=Date.now()-i;if(s&&c!==e.backend){m({level:`debug`,phase:`post_gesture_snapshot_baseline_rebased`,data:{action:t.action,from:c,to:e.backend,attempts:a}}),s=e.signature,c=e.backend,l=!0,o=e;continue}let f=rt({needsBaselineDistrust:n,baselineSignature:s,quietSignature:e.signature,elapsedMs:d,distrustCapMs:z,classifyBaselineEvidence:r.classifyBaselineEvidence});if(f===`distrust`){u=z,o=e;continue}return at(f,t.action,a,d),ot(f,t,e,r,l)}o=e}return m({level:`warn`,phase:`post_gesture_snapshot_stabilization_timeout`,data:{action:t.action,attempts:a,durationMs:Date.now()-i}}),{value:o.value}}async function B(e,t){let n=t??await e.capture();return{value:n,...e.readSurface(n)}}function at(e,t,n,r){if(e===`accept-stale`){m({level:`warn`,phase:`post_gesture_snapshot_stale_accept`,data:{action:t,attempts:n,durationMs:r,matchedPreGestureBaseline:!0}});return}m({level:n>2?`info`:`debug`,phase:`post_gesture_snapshot_stabilized`,data:{action:t,attempts:n,durationMs:r}})}function ot(e,t,n,r,i){if(e!==`accept-stale`)return{value:n.value};let a=t.baselineSignature;return a!==void 0&&r.surfacesIdentical(a,n.signature)?{value:n.value,gestureNoEffect:{action:t.action,positionals:t.positionals}}:(m({level:`info`,phase:`post_gesture_no_effect_vetoed`,data:{action:t.action,backend:n.backend,...i?{reason:`baseline_rebased`}:{reason:`surface_divergence`,...a===void 0?{}:r.summarizeDivergence(a,n.signature)}}}),{value:n.value})}function st(e){let{session:t,command:n,action:r=n,positionals:i,flags:a,scheduleOutcomeRetry:o=!1,androidFreshnessBaseline:s}=e;o&&Ve({session:t,command:n,positionals:i,flags:a,preSnapshot:t.snapshot}),C(r)&&Fe(t,r,s??t.snapshot),ct(t,r,i,a)}function ct(e,t,n=[],r){if(!K(e.device)||!pt(t,n,r))return;let i=q(e.device)?M(e.snapshot?.nodes??[]):void 0;e.postGestureStabilization={action:t,positionals:n,markedAt:Date.now(),...i?.length?{baselineSignature:i,baselineBackend:G(e.snapshot)}:{}}}function lt(e){e?.postGestureStabilization&&(e.postGestureStabilization=void 0)}function V(e){return!!e?.postGestureStabilization}async function ut(e){let t=He(e.session);if(t&&e.session)return await dt({...e,session:e.session},t);if(c(e.device)&&e.session&&V(e.session))return await ft({...e,session:e.session});let n=T(e.session);if(n&&e.device.platform===`android`){let t=await Le(e,n);return{snapshot:t.snapshot,...t.annotations}}}async function dt(e,t){let n=e.session,r=Date.now(),i=0,a=await H(e,t,await U(e)),o=await k({session:n,pending:t,logPath:e.logPath,snapshot:a.snapshot,retryTap:e.retryTap});for(;o.retried;)i+=1,a=await H(e,t,await U(e)),o=await k({session:n,pending:t,logPath:e.logPath,snapshot:a.snapshot,retryTap:e.retryTap});O(n);let s=await W({session:n,initial:a,capture:async()=>await U(e),readSnapshot:e=>e.snapshot});return a=s.value,o.change!==`ambiguous`&&a.annotations.freshness?.staleAfterRetries!==!0&&E(n),o.change===`unchanged`?Ge({pending:t,attempts:i,startedAt:r}):We({pending:t,change:o.change,attempts:i,startedAt:r}),{snapshot:a.snapshot,...ze(a.annotations,s.gestureNoEffect)}}async function H(e,t,n){let r=n;return N(t.preSignature,M(r.snapshot.nodes))===`unchanged`?(await h(500),r=await U(e),r):r}async function ft(e){let t=await W({session:e.session,capture:async()=>await U(e),readSnapshot:e=>e.snapshot}),n=t.value;return{snapshot:n.snapshot,...ze(n.annotations,t.gestureNoEffect)}}async function U(e){let t=T(e.session);return t&&e.device.platform===`android`?await Le(e,t):await e.capture()}async function W(e){let{session:t,capture:n,readSnapshot:r}=e,i=t?.postGestureStabilization;if(!t||!K(t.device)||!i)return{value:e.initial??await n()};let a=await it({pending:{action:i.action,positionals:i.positionals??[],baselineSignature:i.baselineSignature,baselineBackend:i.baselineBackend},needsBaselineDistrust:q(t.device),initial:e.initial,hooks:{capture:n,readSurface:e=>{let t=r(e);return{signature:M(t.nodes),backend:G(t)}},signaturesStable:F,classifyBaselineEvidence:Ke,surfacesIdentical:qe,summarizeDivergence:Je}});return lt(t),a}function G(e){return e?.comparisonKey??e?.snapshotQuality?.backend}function pt(e,t,n){return n?.postGestureStabilization===!1?!1:n?.postGestureStabilization===!0||e===`swipe`||e===`scroll`||e===`gesture`&&t[0]===`swipe`}function K(e){return c(e)}function q(e){return s(e.platform)}async function J(e){let t=await ht(e.inspectFacts)(e.device);for(let n of e.required){let r=t.operations[n];if(!r.available)return{type:`response`,response:e.unavailableResponse?e.unavailableResponse(r):g(`UNSUPPORTED_OPERATION`,`${e.command} is not supported on this device`,void 0,r.hint?{hint:r.hint}:void 0)}}return{type:`admitted`,bind:gt(e.bindDevice)}}async function Y(e){let t=await J({...e,required:e.use.required});if(t.type===`response`)return t;let n=await t.bind(e.device,e.use);return e.readiness!==void 0&&await me(n,e.readiness),{type:`runtime`,runtime:n}}async function mt(e,t){let n=await Y(e);if(n.type===`response`)return{ok:!1,response:n.response};let r=n.runtime;return{ok:!0,execute:async({dispatchContext:e})=>await t(r,e)}}function ht(e){if(e)return e;throw new n(`COMMAND_FAILED`,`Device runtime facts inspection is unavailable.`,{reason:`runtime-gateway-missing`})}function gt(e){if(e)return e;throw new n(`COMMAND_FAILED`,`Device runtime binding is unavailable.`,{reason:`runtime-gateway-missing`})}function _t(e){let{flags:t,logPath:n,meta:r,session:i,snapshotScope:a}=e,{appBundleId:o,trace:s,surface:c}=i??{},l=e.context??D(n??``,t,o,s?.outPath,r?.requestId,r);return{options:{appBundleId:o,interactiveOnly:t?.snapshotInteractiveOnly,preferredBackend:t?.snapshotPreferredBackend,depth:t?.snapshotDepth,scope:a,raw:t?.snapshotRaw,customActions:t?.snapshotCustomActions,includeHiddenContentHints:t?.snapshotIncludeHiddenContentHints,includeRects:e.includeRects,surface:c},execution:X(l),...e.signal===void 0?{}:{signal:e.signal}}}function X(e){return{requestId:e.requestId,verbose:e.verbose,logPath:e.logPath,traceLogPath:e.traceLogPath,iosXctestrunFile:e.iosXctestrunFile,iosXctestDerivedDataPath:e.iosXctestDerivedDataPath,iosXctestEnvDir:e.iosXctestEnvDir,runnerLeaseContext:e.runnerLeaseContext}}async function vt(e){let{getInteractor:t}=await import(`./interactors.js`),n=await(await t(e.device,e.runnerContext)).snapshot(e.options);if(!(`stage`in n))return n;let{presentIosSnapshotAcquisition:r}=await import(`./ios-snapshot-runtime.js`);return await r(n,e.options)}function yt(e){let t=e?e.textEntryReadiness:void 0,n=wt(t)?{textEntryReadiness:t}:{},r=bt(e);return r?{...n,...r}:n}function bt(e){if(!xt(e))return null;let t=St(e.target);return t?{verification:`unconfirmed`,requested:e.requested,before:e.before,after:e.after,target:t}:null}function xt(e){return!!(e&&e.verification===`unconfirmed`&&typeof e.requested==`string`&&Z(e.before)&&Z(e.after))}function St(e){if(!Et(e)||!Ct(e))return null;let t=Tt(e.rect);return t?{resourceId:e.resourceId,className:e.className,packageName:e.packageName,rect:t}:null}function Ct(e){return Z(e.resourceId)&&Z(e.className)&&Z(e.packageName)}function wt(e){return typeof e==`string`&&he.includes(e)}function Z(e){return e===null||typeof e==`string`}function Tt(e){return!Et(e)||![e.x,e.y,e.width,e.height].every(e=>typeof e==`number`)?null:e}function Et(e){return!!e&&typeof e==`object`}async function Q(e){let t={device:e.device,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice},n=u(e.command,e.requiresCapture),r=await J({command:e.command,required:n.use.required,...e.unavailableResponse?{unavailableResponse:e.unavailableResponse}:{},...t});if(r.type===`response`)return{ok:!1,response:r.response};let i=r.bind;switch(n.kind){case`tap-point`:return{ok:!0,runtime:{kind:`tap`,captured:!1,runtime:await i(e.device,oe)}};case`captured-tap`:return{ok:!0,runtime:{kind:`tap`,captured:!0,runtime:await i(e.device,te)}};case`long-press-point`:return{ok:!0,runtime:{kind:`long-press`,captured:!1,runtime:await i(e.device,d)}};case`captured-long-press`:return{ok:!0,runtime:{kind:`long-press`,captured:!0,runtime:await i(e.device,ee)}};case`hover-point`:return{ok:!0,runtime:{kind:`hover`,captured:!1,runtime:await i(e.device,ae)}};case`captured-hover`:return{ok:!0,runtime:{kind:`hover`,captured:!0,runtime:await i(e.device,ie)}};case`fill-point`:return{ok:!0,runtime:{kind:`fill`,captured:!1,runtime:await i(e.device,re)}};case`captured-fill`:return{ok:!0,runtime:{kind:`fill`,captured:!0,runtime:await i(e.device,ne)}}}}function Dt(e,t){let n={execution:X(t),appBundleId:t.appBundleId},r=e.captured?Nt(e.runtime):void 0;switch(e.kind){case`tap`:return Ot(e,t,n,r);case`long-press`:return kt(e,n,r);case`hover`:return At(e,n,r);case`fill`:return jt(e,t,n,r)}}function Ot(e,t,n,r){let i=e.captured?e.runtime.operations.tapRef:void 0,a=e.captured?e.runtime.operations.tapElementSelector:void 0;return Object.freeze({captureSnapshot:r,tapPoint:async(r,i={})=>{let a=Pt(i,t),o=await e.runtime.operations.tapPoint({point:r,options:a,...n});return{x:r.x,y:r.y,count:a.count,intervalMs:a.intervalMs,holdMs:a.holdMs,jitterPx:a.jitterPx,doubleTap:a.doubleTap,...a.button===`primary`?{}:{button:a.button},...o??{},...p(Lt(r,a.button))}},tapRef:i?async e=>await i({ref:e,...n}):void 0,tapElementSelector:e.captured&&a?async t=>{let r=await e.runtime.operations.tapElementSelector?.({selector:t,...n}),i=r?.maestroNonHittableCoordinateFallbackUsed===!0;return{selector:t.raw,...r??{},...p(i?`tapped via non-hittable coordinate fallback`:`Tapped ${t.raw}`)}}:void 0})}function kt(e,t,n){return Object.freeze({captureSnapshot:n,longPressPoint:async(n,r)=>{let i=await e.runtime.operations.longPressPoint({point:n,durationMs:r,...t});return{x:n.x,y:n.y,durationMs:r,...i??{},...p(`Long pressed (${n.x}, ${n.y})`)}}})}function At(e,t,n){let r=e.captured?e.runtime.operations.hoverRef:void 0;return Object.freeze({captureSnapshot:n,hoverPoint:async n=>{let r=await e.runtime.operations.hoverPoint({point:n,...t});return{x:n.x,y:n.y,...r??{},...p(`Hovered (${n.x}, ${n.y})`)}},hoverRef:r?async e=>await r({ref:e,...t}):void 0})}function jt(e,t,n,r){let i=e.captured?e.runtime.operations.fillRef:void 0,a=e=>se(e??t.delayMs??0,`delay-ms`,0,1e4);return Object.freeze({captureSnapshot:r,fillPoint:async(t,r,i={})=>{let o=a(i.delayMs),s=await e.runtime.operations.fillPoint({point:t,text:r,delayMs:o,allowNonHittableCoordinateFallback:i.allowNonHittableCoordinateFallback===!0,...n});return{x:t.x,y:t.y,text:r,delayMs:o,...Mt(s)?{maestroNonHittableCoordinateFallbackUsed:!0}:{},...yt(s),...p(`Filled ${Array.from(r).length} chars`)}},fillRef:i?async(e,t,r={})=>await i({ref:e,text:t,delayMs:a(r.delayMs),...n}):void 0})}function Mt(e){return typeof e==`object`&&!!e&&`maestroNonHittableCoordinateFallbackUsed`in e&&e.maestroNonHittableCoordinateFallbackUsed===!0}function Nt(e){return async t=>await e.operations.captureSnapshot(t)}function Pt(e,t){let n=Ft(e,t);return It(n),{button:e.button??ue(t),...n,surface:e.surface??t.surface}}function Ft(e,t){return{count:$(e.count,t.count,1,`count`,1,200),intervalMs:$(e.intervalMs,t.intervalMs,0,`interval-ms`,0,1e4),holdMs:$(e.holdMs,t.holdMs,0,`hold-ms`,0,1e4),jitterPx:$(e.jitterPx,t.jitterPx,0,`jitter-px`,0,100),doubleTap:e.doubleTap??t.doubleTap??!1}}function $(e,t,n,r,i,a){return se(e??t??n,r,i,a)}function It(e){if(e.doubleTap&&e.holdMs>0)throw new n(`INVALID_ARGS`,`double-tap cannot be combined with hold-ms`);if(e.doubleTap&&e.jitterPx>0)throw new n(`INVALID_ARGS`,`double-tap cannot be combined with jitter-px`)}function Lt(e,t){return t===`primary`?`Pressed (${e.x}, ${e.y})`:`${t===`secondary`?`Right`:`Middle`} clicked (${e.x}, ${e.y})`}function Rt(e){let{inspectFacts:t,bindDevice:n}=e;if(!t||!n)return;let r=new Map;return async({device:e,point:i,context:a})=>{let o=r.get(e.id);o||(o=Q({device:e,command:`press`,requiresCapture:!1,inspectFacts:t,bindDevice:n}),r.set(e.id,o));let s=await o;if(!s.ok)return!1;let c=Dt(s.runtime,a);return c.tapPoint?(await c.tapPoint(i),!0):!1}}async function zt(e){let t=await ut({session:e.session,device:e.device,logPath:e.logPath,interactiveOnly:e.flags?.snapshotInteractiveOnly===!0,androidFreshnessMode:e.androidFreshnessMode,capture:()=>Vt(e),retryTap:Rt(e)});if(t)return t;let n=await Vt(e);return E(e.session),{snapshot:n.snapshot,...n.annotations}}async function Bt(e){if(e.captureData)return await e.captureData();let{device:t,session:n,logPath:r}=e,i=D(r,Ht(e),n?.appBundleId,n?.trace?.outPath);return await vt({device:t,runnerContext:{requestId:i.requestId,signal:e.signal,appBundleId:i.appBundleId,verbose:i.verbose,logPath:i.logPath,traceLogPath:i.traceLogPath,iosXctestrunFile:i.iosXctestrunFile,iosXctestDerivedDataPath:i.iosXctestDerivedDataPath,iosXctestEnvDir:i.iosXctestEnvDir,runnerLeaseContext:i.runnerLeaseContext},options:{appBundleId:i.appBundleId,signal:e.signal,interactiveOnly:i.snapshotInteractiveOnly,preferredBackend:i.snapshotPreferredBackend,depth:i.snapshotDepth,scope:i.snapshotScope,raw:i.snapshotRaw,customActions:i.snapshotCustomActions,includeRects:e.includeRects,includeHiddenContentHints:i.snapshotIncludeHiddenContentHints,surface:n?.surface}})}async function Vt(e){let t=Date.now(),n=await Bt(e);a(e.session,{durationMs:Date.now()-t,backend:n.backend,platform:l(e.device)});let r=i(n),s=o(n,fe(n,Ht(e)));return r.androidSnapshot?.systemSurfaceOnly===!0&&(s.systemSurfaceOnly=!0),{data:n,snapshot:s,annotations:r}}function Ht(e){return e.snapshotScope===void 0?e.flags:{...e.flags,snapshotScope:e.snapshotScope}}function Ut(n,r){if(!n||!n.trim().startsWith(`@`))return{ok:!0,scope:n};if(!r?.snapshot)return g(`INVALID_ARGS`,`Ref scope requires an existing snapshot in session.`);let i=t(n.trim());if(!i)return g(`INVALID_ARGS`,`Invalid ref scope: ${n}`);let a=[r.snapshot,...r.snapshotScopeSource?[r.snapshotScopeSource]:[]],o;for(let t of a){let n=e(t.nodes,i);if(o=n?ce(n,t.nodes):void 0,o)break}return o?{ok:!0,scope:o}:g(`COMMAND_FAILED`,`Ref ${n} not found or has no label`)}function Wt(e,t,n={}){if(!e)return;let r=xe(e);return{name:t,appBundleId:e.appBundleId,appName:e.appName,...n.includeSnapshot===!0?{snapshot:e.snapshot,...r&&n.omitRefFrameSnapshot!==!0?{refFrameSnapshot:r}:{}}:{},metadata:{surface:e.surface,...n.metadata??{}}}}function Gt(e){return{get:t=>t===e.sessionName?Wt(e.getSession(),e.sessionName,e.recordOptions):void 0,set:t=>{if(t.name!==e.sessionName){m({level:`warn`,phase:`runtime_session_write_skipped`,data:{expected:e.sessionName,received:t.name}});return}e.setRecord(t)}}}function Kt(e,t){e.snapshot!==t&&(e.snapshotGeneration=Jt(e.snapshotGeneration)),e.snapshot=t,e.snapshotScopeSource=void 0,t.comparisonSafe===!0&&(e.lastComparisonSafeSnapshot=t)}function qt(e,t){e.snapshotScopeSource=t.scopeSource,e.snapshotGeneration=t.keptCurrentSnapshot?t.previousGeneration:Jt(t.previousGeneration)}function Jt(e){return e===void 0?ge(1e5,1e6):e+1}function Yt(e){let t=e.startsWith(`@`)?e.slice(1):e,n=t.indexOf(`~`);return n===-1?t:t.slice(0,n)}function Xt(e,t){let n=new Set;for(let e of t){let t=Yt(e);t.length>0&&n.add(t)}n.size!==0&&Ee(e,n)}function Zt(e,t){if(t?.diff)return Xt(e,Qt(t)),e.snapshotGeneration}function Qt(e){let t=[];for(let n of e.diff?.lines??[])n.ref&&t.push(n.ref);for(let n of e.refs??[])t.push(n.ref);for(let n of e.tail??[])t.push(n.ref);return t}function $t(e){return`Ref @${e.ref.startsWith(`@`)?e.ref.slice(1):e.ref} was minted from snapshot s${e.mintedGeneration} but the session's ref frame is now s${e.currentFrameEpoch} — re-run snapshot -i.`}function en(e){let{session:t,ref:n,mintedGeneration:r}=e;if(t&&x(t)===`expired`)return`The UI may have changed since these refs were issued, so they no longer represent current device state. Take a new snapshot before relying on or interacting with them.`;if(r!==void 0){let e=t?y(t)??0:0;if(r!==e)return $t({ref:n,mintedGeneration:r,currentFrameEpoch:e})}}export{Se as C,v as E,Te as S,we as T,V as _,qt as a,D as b,Bt as c,Q as d,_t as f,mt as g,Y as h,Kt as i,Ut as l,J as m,Xt as n,Gt as o,X as p,en as r,zt as s,Zt as t,Dt as u,st as v,De as w,T as x,j as y};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{F as e,y as t}from"./sdk-contracts.js";import{n}from"./capture.js";import{g as r}from"./sdk-batch-runner.js";import{i,r as a,t as o,v as s}from"./sdk-device.js";import{Jn as c,b as l,f as ee,qn as te,rn as u,tn as ne}from"./sdk-batch.js";import{n as re,t as d}from"./back-mode.js";import{r as ie}from"./scroll-gesture.js";import{_ as f,c as ae,d as oe,g as se,h as ce,i as le,l as ue,m as de,o as fe,p,s as pe,u as m,y as me}from"./script.js";import{A as he,C as ge,D as _e,E as ve,M as ye,N as be,O as xe,S as Se,T as Ce,_ as h,a as we,b as Te,c as Ee,i as De,n as Oe,o as ke,r as Ae,t as je,u as Me,v as Ne,w as Pe,x as Fe,y as Ie}from"./parameterized-recorded-fill.js";import{n as g,t as Le}from"./catalog.js";import{t as Re}from"./session.js";import{n as ze}from"./success-text.js";import{t as Be}from"./click-button.js";import"./device.js";import{t as _}from"./device-rotation.js";import{a as v,r as y}from"./diagnostics.js";import{D as Ve}from"./owner-identity.js";import"./file.js";import{t as He}from"./tv-remote.js";import"./diagnostics2.js";import{n as Ue,r as We}from"./session-repair-tombstone.js";import{n as Ge,r as b,t as x}from"./session-paths.js";import{t as Ke}from"./keyboard-actions.js";import S from"node:path";import C from"node:fs";import{createHash as qe}from"node:crypto";import{StringDecoder as Je}from"node:string_decoder";function Ye(e,t={}){let n=[e.command];return e.command===`snapshot`?oe(n,e):e.command===`open`?le(n,e):e.command===`runtime`?ae(n,e,{includeAllPositionals:t.runtimeIncludeAllPositionals}):e.command===`record`?pe(n,e):e.command===`screenshot`?ue(n,e):fe(n,e),n.join(` `)}function Xe(e){return e.targetEvidences?[te(e.targetEvidences)]:e.targetEvidence?[c(e.targetEvidence)]:[]}function w(e){return e?.scriptPublication??h}function Ze(e,t){let n=w(e),r=typeof t.saveScript==`string`?x(t.saveScript):n.kind===`repair`?void 0:t.healedSiblingPath;e.scriptPublication=Ie(n,{requested:{path:r,force:t.force===!0},boundary:t.firstArm?e.actions.length:0,sourcePath:t.sourcePath})}function Qe(e){e.scriptPublication=Fe(w(e))}function $e(e){e.scriptPublication=Ce(w(e))}function et(e,t){e.scriptPublication=ve(w(e),t)}function tt(e){e.scriptPublication=Ne(w(e))}function nt(e,t){let n=w(e);return n.kind===`repair`&&n.closeReceipt===t}function rt(e){return w(e).kind===`repair`}function it(e){return Pe(w(e))}function T(e){return _e(w(e))}function at(e){return xe(w(e))}function ot(e,t){if(t.flags?.noRecord||gt(e,t))return;t.flags&&Ee(e,t.flags);let n=ct(t),r=dt(e,lt(t,n));n&&ut(e,n);let i={ts:Date.now(),command:r.command,positionals:r.positionals,runtime:r.runtime,flags:vt(r.flags),result:r.result,...r.targetEvidence?{targetEvidence:r.targetEvidence}:{},...r.targetEvidences?{targetEvidences:r.targetEvidences}:{}};return e.actions.push(i),y({level:`debug`,phase:`record_action`,data:{command:t.command,session:e.name}}),i}function st(e,t,n,r,i,a){t&&e.recordAction(t,{command:r,positionals:a?.positionals??n.positionals??[],flags:a?.flags??n.flags??{},result:i??{}})}function ct(e){if(e.command!==`fill`||typeof e.flags.recordAs!=`string`)return;let t=be(e.flags.recordAs),n=ye(t);return{literal:ke({ts:0,command:e.command,positionals:e.positionals,flags:e.flags}),placeholder:n}}function lt(e,t){if(!t)return e;let{literal:n,placeholder:r}=t;return{...e,positionals:pt(e.positionals,r),result:je(e.result,n,r),targetEvidence:Oe(e.targetEvidence,n,r)}}function ut(e,t){t.literal.trim()&&(e.recordedFillLiterals??=new Map,!e.recordedFillLiterals.has(t.literal)&&e.recordedFillLiterals.set(t.literal,t.placeholder))}function dt(e,t){let n=e.recordedFillLiterals;if(!n||n.size===0)return t;let r=Ae(t.result,n),i=(t.targetEvidenceMode??`action`)===`landmark`?ft(t.targetEvidence,n):E(t.targetEvidence,n),a=t.targetEvidences?{source:E(t.targetEvidences.source,n),destination:E(t.targetEvidences.destination,n)}:t.targetEvidences;return{...t,result:r,targetEvidence:i,targetEvidences:a}}function ft(e,t){return e&&(we(e,t)?void 0:e)}function E(e,t){return!e||!we(e,t)?e:{...De(e,t),verification:`unverifiable`}}function pt(e,t){let n=e[0];return n?.startsWith(`@`)?e.length>=3?[n,e[1],t]:[n,t]:e.length>=3&&Number.isFinite(Number(e[0]))&&Number.isFinite(Number(e[1]))?[e[0],e[1],t]:n===void 0?[t]:[n,t]}const mt=new Set([`snapshot`,`get`,`is`,`find`]);function ht(e){return e.internal?.replayPlanStep!==!0&&mt.has(e.command)}function gt(e,t){return!t.interactiveObservation||T(e)===void 0?!1:t.flags?.record!==!0}const _t=[`platform`,`device`,`udid`,`serial`,`out`,`verbose`,`metroHost`,`metroPort`,`bundleUrl`,`launchUrl`,`snapshotInteractiveOnly`,`snapshotDepth`,`snapshotScope`,`snapshotRaw`,`snapshotCustomActions`,...n,`relaunch`,`saveScript`,`force`,`noRecord`,`record`,`fps`,`quality`,`hideTouches`,`count`,`pointerCount`,`intervalMs`,`delayMs`,`holdMs`,`jitterPx`,`doubleTap`,`clickButton`,`pauseMs`,`pattern`];function vt(e){if(!e)return{};let t={};for(let n of _t)e[n]!==void 0&&(t[n]=e[n]);return t}function yt(e){let n=e.flatMap((e,t)=>e.command===`open`?[t]:[]);if(n.length!==1||n[0]!==0)throw new t(`COMMAND_FAILED`,`Cannot publish this session: an open-to-destination script requires exactly one initial recorded open.`,{retriable:!1,hint:`Close this session and start a fresh one with open <app> --save-script[=<path>].`});if(e.some(e=>e.command===`close`))throw new t(`COMMAND_FAILED`,`Cannot publish an active-session script containing close.`,{retriable:!1,hint:`Close this session and record the journey again from a fresh open --save-script session.`});let r=-1;for(let[t,n]of e.entries())l({command:n.command,positionals:n.positionals,flags:n.flags})===`mutates-app`&&(r=t);if(!e.slice(r+1).some(Tt))throw new t(`COMMAND_FAILED`,`Cannot publish this session without a portable destination guard after the final mutating action.`,{retriable:!0,hint:`Record a selector-targeted wait on a labeled or id-bearing landmark, for example wait 'role="heading" label="Screen X"', so its recorded identity is captured, then retry session save-script.`})}function bt(e){for(let n of e){if(xt(n)){St(n);continue}let e=Et(n),r=e??(n.command===`wait`?n.positionals[0]:void 0);if(r?.startsWith(`@`))throw new t(`COMMAND_FAILED`,`Cannot publish recorded step "${n.command} ${r}": the session-local ref was not converted to a portable selector.`,{retriable:!1,hint:`Close this session and record the journey again using selectors or resolvable refs.`});if(n.command===`find`&&l(n)===`mutates-app`)throw new t(`COMMAND_FAILED`,`Cannot publish a recorded mutating find step because its target identity is not replay-verifiable.`,{retriable:!1,hint:`Close this session and record the journey again with an explicit selector-targeted click, press, fill, or focus action.`});let i=e;if(!(!i||!u(i)||n.targetEvidence))throw new t(`COMMAND_FAILED`,`Cannot publish recorded step "${n.command} ${i}": recording-time target identity evidence is missing.`,{retriable:!1,hint:`Close this session and record the journey again from open --save-script so target-v1 evidence is captured before each interaction.`})}}function xt(e){return Ct(e)!==void 0}function St(e){let n=Ct(e);if(!n)return;let r=[n.source,n.destination];for(let n of r){if(n?.startsWith(`@`))throw new t(`COMMAND_FAILED`,`Cannot publish recorded drag endpoint "${n}": the session-local ref was not converted to a portable selector.`,{retriable:!1});if(!(!n||!u(n))&&!e.targetEvidences)throw new t(`COMMAND_FAILED`,`Cannot publish recorded drag endpoint "${n}": recording-time target identity evidence is missing.`,{retriable:!1,hint:`Close this session and record the journey again so targets-v1 evidence is captured for both drag endpoints.`})}}function Ct(e){return e.command===`gesture`?me(e.positionals):void 0}function wt(e,n){if(e instanceof t){if(e.details?.reason===`script_target_exists`)return new t(e.code,`A file already exists at ${String(e.details.path)}.`,{...e.details,retriable:!0,hint:`Retry session save-script with another path, or pass --force to replace the existing file. The session remains armed.`});let n=e.details?.retriable===!0;return new t(e.code,e.message,{...e.details,retriable:n,hint:e.details?.hint??(n?`Fix the recorded journey or target, then retry session save-script. The session remains armed.`:`Close this session and start a fresh one with open <app> --save-script[=<path>].`)})}let r=e instanceof Error?e.message:String(e);return new t(`COMMAND_FAILED`,`Failed to publish the active session script${n?` to ${n}`:``}: ${r}`,{retriable:!0,hint:`Check the target path and permissions, then retry session save-script. The session remains armed.`})}function Tt(e){if(e.command!==`wait`)return!1;let t=ne(e.positionals);return t?.kind!==`selector`||!u(t.selectorExpression)?!1:e.targetEvidence?.verification===`verified`}function Et(e){if(e.command===`get`)return e.positionals[1];if(se(e.command)||e.command===`fill`){let[t,n]=e.positionals;return t!==void 0&&n!==void 0&&Dt(t)&&Dt(n)?void 0:t}}function Dt(e){return e.trim().length>0&&Number.isFinite(Number(e))}function Ot(e){let t=e.scriptPublication??h;return t.kind===`repair`?t.status===`committed`||!ge(t):!1}function kt(e){return!Se(e.scriptPublication??h)||Ot(e)}var At=class{sessionsDir;constructor(e){this.sessionsDir=e}write(e,t){let n=rt(e),r=t?.publication===`active`,i;try{if(kt(e))return{written:!1};let a=jt(e,{appendCompleteSentinel:n,activePublication:r});i=this.resolveScriptPath(e);let o=S.dirname(i);return C.existsSync(o)||C.mkdirSync(o,{recursive:!0}),Pt({scriptPath:i,script:a.script,force:t?.force}),n&&(e.scriptPublication=Te(e.scriptPublication??h)),{written:!0,path:i,actionCount:a.actionCount}}catch(t){return Mt({session:e,error:t,scriptPath:i,repairArmed:n,activePublication:r})}}resolveScriptPath(e){let t=he(e.scriptPublication??h);if(t)return x(t);let n=b(e.name),r=new Date(e.createdAt).toISOString().replaceAll(/[:.]/g,`-`);return S.join(this.sessionsDir,`${n}-${r}.ad`)}};function jt(e,t){let n=Ft(e,{strictPortableRefs:t.activePublication});return t.activePublication&&yt(n),{script:Gt(e,n,t.appendCompleteSentinel),actionCount:n.length}}function Mt(e){let{session:n,error:r,scriptPath:i,repairArmed:a,activePublication:o}=e;if(y({level:`warn`,phase:`session_script_write_failed`,data:{session:n.name,path:i,error:r instanceof Error?r.message:String(r)}}),a)return{written:!1,error:Nt(r,i)};if(o)return{written:!1,error:wt(r,i)};if(r instanceof t)throw r;return{written:!1}}function Nt(e,n){if(e instanceof t)return e;let r=e instanceof Error?e.message:String(e);return new t(`COMMAND_FAILED`,`Failed to write the healed script${n?` to ${n}`:``}: ${r}`,{hint:`The repair transaction completed but the healed .ad could not be published; check the target path and permissions, then retry close --save-script.`})}function Pt(e){let{scriptPath:n,script:r,force:i}=e;try{Ve({destination:n,contents:r,publish:i?`replace`:`link-exclusive`})}catch(e){throw e.code===`EEXIST`?new t(`COMMAND_FAILED`,`A file already exists at ${n}; remove it, pass replay --save-script=<other-path>, or pass --force/--overwrite to replace it.`,{reason:`script_target_exists`,path:n}):e}}function Ft(e,t={}){let n=T(e),r=n!==void 0,i=e.actions.slice(n??0),a=[];for(let n of i){if(n.command===`snapshot`)continue;let i=Rt(n);if(i){a.push(i);continue}(r||t.strictPortableRefs)&&It(n);let o=Wt(e,n);o&&a.push(o),a.push(n)}return t.strictPortableRefs&&bt(a),a}function It(e){let n=e.command===`gesture`?me(e.positionals??[]):void 0;if(n){Lt(n);return}if(!D(e.command))return;let r=e.command===`get`?e.positionals?.[1]:e.positionals?.[0];if(r?.startsWith(`@`))throw new t(`COMMAND_FAILED`,`Cannot write recorded step "${e.command} ${r}" to a script: it never resolved to a selector, so the ref would not resolve in a fresh replay session.`)}function Lt(e){let n=[e.source,e.destination].find(e=>e.startsWith(`@`));if(n)throw new t(`COMMAND_FAILED`,`Cannot write recorded drag endpoint "${n}" to a script: it never resolved to a selector, so the ref would not resolve in a fresh replay session.`)}function Rt(e){let t=zt(e);if(!(!t||!D(e.command)))return ce(e.command)||e.command===`hover`?{...e,positionals:[t]}:e.command===`longpress`?Vt(e,t):e.command===`fill`?Bt(e,t):Ht(e,t)}function zt(e){let t=Array.isArray(e.result?.selectorChain)&&e.result.selectorChain.every(e=>typeof e==`string`)?e.result.selectorChain:[];return t.length>0?t.join(` || `):void 0}function D(e){return se(e)||e===`fill`||e===`get`}function Bt(e,t){let n=ke(e);return n.length>0?{...e,positionals:[t,n]}:void 0}function Vt(e,t){let n=typeof e.result?.durationMs==`number`?String(e.result.durationMs):Ut(e.positionals??[]);return{...e,positionals:n?[t,n]:[t]}}function Ht(e,t){let n=e.positionals?.[0];return n===`text`||n===`attrs`?{...e,positionals:[n,t]}:void 0}function Ut(e){let t=e.at(-1);if(!(e.length<=1||t===void 0||t.trim()===``))return Number.isFinite(Number(t))?t:void 0}function Wt(e,t){if(!D(t.command))return;let n=t.result?.refLabel;if(typeof n!=`string`||n.trim().length===0)return;let r=n.trim();return{ts:t.ts,command:`snapshot`,positionals:[],flags:{platform:e.device.platform,snapshotInteractiveOnly:!0,snapshotScope:r},result:{scope:r}}}function Gt(e,t,n){let r=[],i=e.device.kind?` kind=${e.device.kind}`:``;r.push(`context platform=${s(e.device)} device=${de(e.device.name)}${i} theme=unknown`);for(let e of t)e.flags?.noRecord||(r.push(...Xe(e)),r.push(Kt(e)));return n&&r.push(`# agent-device:heal-complete`),`${r.join(`
|
|
2
|
+
`)}\n`}function Kt(e){return qt([e.command],e)||Ye(e)}function qt(e,t){if(ce(t.command))return Jt(e,t);if(t.command===`fill`)return Yt(e,t);if(t.command===`get`)return Xt(e,t)}function Jt(e,t){let n=t.positionals?.[0];if(n){if(n.startsWith(`@`))return e.push(p(f(n))),O(e,t),m(e,t),e.join(` `);if(t.positionals.length===1)return e.push(p(n)),m(e,t),e.join(` `)}}function Yt(e,t){let n=t.positionals?.[0];if(!n?.startsWith(`@`))return;e.push(p(f(n))),O(e,t);let r=t.positionals.slice(1).join(` `);return t.positionals.length>1&&e.push(p(r)),m(e,t),e.join(` `)}function Xt(e,t){let n=t.positionals?.[0],r=t.positionals?.[1];if(!(!n||!r))return e.push(p(n)),e.push(p(f(r))),r.startsWith(`@`)&&O(e,t),e.join(` `)}function O(e,t){let n=t.result?.refLabel;typeof n==`string`&&n.trim().length>0&&e.push(p(n))}const Zt=[`id`,`deviceId`,`device_id`,`serial`,`udid`,`device_udid`,`identifier`],Qt={ios:`iOS`,ipados:`iPadOS`,tvos:`tvOS`,watchos:`watchOS`,visionos:`visionOS`,macos:`macOS`,apple:`Apple`,android:`Android`,linux:`Linux`,web:`Web`};function $t(e,t){let n=t??{};switch(e.command){case g.devices:return en(n.devices);case g.apps:return tn(n.apps,e.flags?.appsFilter);case g.boot:return nn(`Booted`,n,!0);case g.shutdown:return nn(`Shut down`,n,!1);case g.install:return k(`Installed`,n);case g.reinstall:return k(`Reinstalled`,n);case g.screenshot:return rn(e,n);default:return{}}}function en(e){if(!Array.isArray(e))return{};let t=e.flatMap(e=>{let t=on(e);return t?[t]:[]}),n=t.slice(0,5),r=Math.max(0,t.length-n.length),i=t.slice(0,3);return{summary:hn(`Found ${t.length} ${gn(`device`,t.length)}`,i.map(e=>pn(e,!0)),Math.max(0,t.length-i.length)),details:{deviceCount:t.length,devices:n,...r>0?{omittedDeviceCount:r}:{}}}}function tn(e,t){if(!Array.isArray(e))return{};let n=e.flatMap(e=>{let t=M(e);return t?[t]:[]}),r=n.slice(0,5),i=Math.max(0,n.length-r.length),a=n.slice(0,3);return{summary:hn(`Found ${n.length} ${gn(`app`,n.length)}`,a,Math.max(0,n.length-a.length)),details:{appCount:n.length,apps:r,...i>0?{omittedAppCount:i}:{},...t===`all`||t===`user-installed`?{filter:t}:{}}}}function nn(e,t,n){let r=sn(t);if(!r)return{};let i={device:r,...fn(t),booted:n};return{summary:`${e} ${pn(i,!1)}`,details:i}}function k(e,t){let n=M(t.appName),r=M(t.bundleId),i=A(t,[`packageName`,`package`]),a=M(t.platform),o=M(t.launchTarget),s=A(t,[`bundleId`,`packageName`,`package`,`appId`,`launchTarget`]),c=mn(n,s);if(!c)return{};let l={};return j(l,`appName`,n),j(l,`bundleId`,r),j(l,`packageName`,i),j(l,`platform`,a),o!==s&&j(l,`launchTarget`,o),{summary:`${e} ${c}`,details:l}}function rn(e,t){let n=an(e,t);return n?{details:{requestedFileName:n}}:{}}function an(e,t){let n=R(e.meta?.clientArtifactPaths?.path)??R(t.path);if(n)return L(n)}function on(e){if(!r(e))return;let t=sn(e);if(t)return{name:t,...fn(e)}}function sn(e){let t=A(e,[`name`,`deviceName`,`device`]);return!t||!cn(e,t)?t:un(e)}function cn(e,t){let n=ln(t);return Zt.some(t=>{let r=M(e[t]);return r!==void 0&&ln(r)===n})}function ln(e){return e.toLowerCase()}function un(e){let t=M(e.appleOs),n=M(e.platform),r=M(e.kind),i=dn(t,n);return i&&(r===`simulator`||r===`emulator`)?`${i} ${r}`:i?`${i} device`:r===`simulator`?`Simulator`:r===`emulator`?`Emulator`:`Unnamed device`}function dn(e,t){let n=e??t;if(!(!n||!Object.hasOwn(Qt,n)))return Qt[n]}function fn(e){let t=M(e.platform),n=M(e.appleOs),r=M(e.kind),i=M(e.target);return{...t?{platform:t}:{},...n?{appleOs:n}:{},...r?{kind:r}:{},...i?{target:i}:{},...typeof e.booted==`boolean`?{booted:e.booted}:{}}}function pn(e,t){let n=M(e.name)??M(e.device)??`device`,r=M(e.platform),i=M(e.appleOs),a=[r,i===r?void 0:i,M(e.kind),M(e.target),t&&typeof e.booted==`boolean`?e.booted?`booted`:`stopped`:void 0].filter(e=>!!e);return a.length>0?`${n} (${a.join(`, `)})`:n}function mn(e,t){return e&&t&&e!==t?`${e} (${t})`:e??t}function A(e,t){for(let n of t){let t=M(e[n]);if(t)return t}}function j(e,t,n){n&&(e[t]=n)}function hn(e,t,n){let r=[...t,...n>0?[`+${n} more`]:[]];return r.length>0?`${e}: ${r.join(`, `)}`:e}function gn(e,t){return t===1?e:`${e}s`}function M(e){let t=R(e);if(!t)return;let n=t.trim(),r=Array.from(n);return r.length<=120?n:`${r.slice(0,119).join(``)}…`}function N(e){return M(e)}function P(e){return typeof e==`boolean`?e:void 0}function F(e,t){let n=N(e);return n&&t.includes(n)?n:void 0}function I(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function L(e){let t=R(e);return t?M(t.split(/[\\/]/).at(-1)):void 0}function R(e){if(typeof e==`string`)return e.trim().length>0?e:void 0}function z(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}const _n=[`up`,`down`,`left`,`right`],vn=[`top`,`bottom`];function yn(e){return`${e.command===g.reinstall?`Reinstalled`:`Installed`} ${Cn(e.result??{})??`app`}`}function bn(e){let t=e.result??{};switch(e.command){case g.scroll:return Tn(t);case g.screenshot:return On(t);case g.home:return`Went home`;case g.back:return An(t);case g.appSwitcher:return`Opened app switcher`;case g.orientation:return jn(t);case g.viewport:return Mn(t);case g.clipboard:return Nn(t);case g.keyboard:return Pn(t);case g.tvRemote:return Ln(t);case g.gesture:return Rn(t);case g.swipe:return zn(t);case g.trace:return Vn(`trace`,e);case g.record:return Vn(`recording`,e);default:return}}function xn(e){let t=e.result??{};switch(e.command){case g.scroll:return I({direction:F(t.direction,_n),edge:F(t.edge,vn),passes:z(t.passes),amount:z(t.amount),pixels:z(t.pixels),durationMs:z(t.durationMs),x1:z(t.x1),y1:z(t.y1),x2:z(t.x2),y2:z(t.y2)});case g.screenshot:return I({requestedFileName:kn(t)});case g.back:return I({mode:F(t.mode,d)});case g.orientation:return I({orientation:F(t.orientation,_)});case g.viewport:return I({width:z(t.width),height:z(t.height)});case g.clipboard:return I({action:F(t.action,[`read`,`write`])});case g.keyboard:return In(t);case g.tvRemote:return I({button:F(t.button,He),durationMs:z(t.durationMs)});case g.gesture:case g.swipe:return Bn(t);case g.trace:case g.record:return I({action:F(t.action,[`start`,`stop`]),fileName:Un(e),showTouches:P(t.showTouches)});default:return{}}}function Sn(e,t){if(e.command!==g.screenshot)return t;let n=an(e,t);return n?{...t,requestedFileName:n}:t}function Cn(e){let t=N(e.appName),n=Wn(e,[`bundleId`,`packageName`,`appBundleId`,`launchTarget`]);return t&&n&&t!==n?`${t} (${n})`:t??n??wn(e)}function wn(e){let t=N(e.app);return t&&!t.includes(`/`)&&!t.includes(`\\`)?t:void 0}function Tn(e){let t=F(e.direction,_n),n=F(e.edge,vn),r=z(e.passes);return n?En(n,r):t?Dn(t,e):`Scrolled`}function En(e,t){return t===0?`Already at ${e}`:t===void 0?`Scrolled to ${e}`:`Scrolled to ${e} in ${t} ${t===1?`pass`:`passes`}`}function Dn(e,t){let n=z(t.pixels);if(n!==void 0)return`Scrolled ${e} by ${n}px`;let r=z(t.amount);return r===void 0?`Scrolled ${e}`:`Scrolled ${e} by ${r}`}function On(e){let t=kn(e);return t?`Captured screenshot ${t}`:`Captured screenshot`}function kn(e){return L(e.requestedFileName)??L(e.path)}function An(e){return F(e.mode,d)===`system`?`Went back using system navigation`:`Went back`}function jn(e){let t=F(e.orientation,_);return t?`Rotated to ${t}`:`Changed orientation`}function Mn(e){let t=z(e.width),n=z(e.height);return t!==void 0&&n!==void 0?`Set viewport to ${t}×${n}`:`Changed viewport`}function Nn(e){let t=F(e.action,[`read`,`write`]);return t===`read`?`Read clipboard`:t===`write`?`Updated clipboard`:`Used clipboard`}function Pn(e){let t=R(e.action);if(!t||!Ke(t))return`Used keyboard`;if(t===`dismiss`)return Fn(e);if(t===`enter`||t===`return`)return`Pressed keyboard return`;let n=P(e.visible);return n===void 0?`Inspected keyboard`:n?`Keyboard is visible`:`Keyboard is hidden`}function Fn(e){return P(e.dismissed)===!1?`Keyboard was already hidden`:`Dismissed keyboard`}function In(e){let t=R(e.action);return I({action:t&&Ke(t)?t:void 0,platform:F(e.platform,[`ios`,`android`]),visible:P(e.visible),wasVisible:P(e.wasVisible),dismissed:P(e.dismissed),attempts:z(e.attempts),mechanism:F(e.mechanism,[`dismissKey`])})}function Ln(e){let t=F(e.button,He);return t?`Pressed TV remote ${t}`:`Used TV remote`}function Rn(e){let t=F(e.kind,[`fling`,`pan`,`pinch`,`rotate`,`transform`]);return t?`Ran ${t} gesture`:`Ran gesture`}function zn(e){let t=z(e.count);return t!==void 0&&t>1?`Swiped ${t} times`:`Swiped`}function Bn(e){return I({kind:F(e.kind,[`fling`,`pan`,`pinch`,`rotate`,`transform`]),durationMs:z(e.durationMs),pointerCount:z(e.pointerCount),x1:z(e.x1),y1:z(e.y1),x2:z(e.x2),y2:z(e.y2),count:z(e.count),pauseMs:z(e.pauseMs),pattern:F(e.pattern,[`one-way`,`ping-pong`]),scale:z(e.scale)})}function Vn(e,t){let n=Hn(e,F(t.result?.action,[`start`,`stop`])),r=Un(t);return r?`${n} ${r}`:n}function Hn(e,t){return t===`start`?e===`trace`?`Started trace`:`Started recording`:t===`stop`?e===`trace`?`Stopped trace`:`Stopped recording`:e===`trace`?`Updated trace`:`Updated recording`}function Un(e){let t=e.result??{};return L(t.requestedFileName)??L(t.outPath)??L(t.path)??L(e.positionals[1])}function Wn(e,t){for(let n of t){let t=N(e[n]);if(t)return t}}function Gn(e){switch(e.command){case g.open:return`Opened ${B(e)??`session`}`;case g.close:return`Closed ${N(e.result?.session)??`session`}`;case g.click:case g.press:return`Tapped ${B(e)??`target`}`;case g.longPress:return`Long pressed ${B(e)??`target`}`;case g.hover:return`Hovered ${B(e)??`target`}`;case g.fill:return`Filled ${B(e)??`target`}`;case g.type:return`Typed text`;case g.install:case g.reinstall:case Le.installSource:return yn(e);default:return bn(e)??`Ran ${e.command}`}}function Kn(e){return I({command:e.command,positionals:tr(e),flags:pr(e),...qn(e),...Jn(e),...Yn(e),...xn(e)})}function qn(e){if(!Xn(e.command))return{};let t=e.result??{};return I({ref:G(t),targetLabel:B(e),selectorChainLength:lr(t.selectorChain)?.length,x:z(t.x),y:z(t.y),x2:z(t.x2),y2:z(t.y2),durationMs:z(t.durationMs)})}function Jn(e){if(!Zn(e.command))return{};let t=e.result??{};return I({platform:F(t.platform,i),target:F(t.target,o),appName:N(t.appName),appBundleId:N(t.appBundleId),bundleId:N(t.bundleId),packageName:N(t.packageName),launchTarget:N(t.launchTarget)})}function Yn(e){let t=e.result??{};return e.command===g.snapshot?Array.isArray(t.nodes)?{nodeCount:t.nodes.length}:{}:e.command!==g.wait&&e.command!==g.find&&e.command!==g.get&&e.command!==g.is?{}:I({waitedMs:z(t.waitedMs),found:P(t.found)})}function Xn(e){return e===g.click||e===g.press||e===g.longPress||e===g.hover||e===g.focus||e===g.fill}function Zn(e){return e===g.open||e===g.install||e===g.reinstall||e===Le.installSource}function B(e){let t=e.result??{};return Qn(t)??$n(t)??er(t)??sr(e.positionals[0])}function Qn(e){let t=G(e);if(t)return t.startsWith(`@`)?t:`@${t}`}function $n(e){let t=z(e.x),n=z(e.y);if(t!==void 0&&n!==void 0)return`(${t}, ${n})`}function er(e){return N(e.appName)??N(e.appBundleId)??N(e.bundleId)??N(e.packageName)}function tr(e){if(e.positionals.length!==0)return e.command===g.type?[H(`text`)]:e.command===g.fill?nr(e):e.command===g.find?rr(e):e.command===g.clipboard?ir(e):e.command===g.push?ar(e,`app`,`payload`):e.command===g.triggerAppEvent?ar(e,`event`,`payload`):e.positionals.map(V)}function nr(e){let t=H(`text`),n=e.result??{},r=G(n);if(r)return[`@${r}`,t];if(N(n.selector))return[H(`target`),t];let i=z(n.x),a=z(n.y);return i!==void 0&&a!==void 0?[String(i),String(a),t]:[t]}function rr(e){let t=+!!cr(e.positionals[0]);if(e.positionals[t]===void 0)return;let n=t+1,r=[...t===1?[String(e.positionals[0])]:[],H(`query`)],i=e.positionals[n];return i?i===`fill`||i===`type`?[...r,i,H(`text`)]:[...r,...e.positionals.slice(n).map(or)]:r}function ir(e){let t=e.positionals[0]?.toLowerCase();return t===`read`?[`read`]:t===`write`?[`write`,H(`text`)]:e.positionals.map(V)}function ar(e,t,n){let[r,i,...a]=e.positionals;return[...r?[H(t)]:[],...i?[H(n)]:[],...a.map(V)]}function or(e){return e===`click`||e===`focus`||e===`exists`||e===`get`||e===`text`||e===`attrs`||e===`wait`?e:V(e)}function V(e){return sr(e)??H(`arg`)}function sr(e){if(!e)return;let t=e.trim();if(/^@[a-zA-Z0-9:_-]+$/.test(t))return t}function H(e){return`<${e}>`}function cr(e){return e===`text`||e===`label`||e===`value`||e===`role`||e===`id`}function lr(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:void 0}const ur={enums:[{source:`platform`,values:a},{source:`target`,values:o}]},dr={booleans:[{source:`settle`}],numbers:[{source:`settleQuietMs`}]},fr={[g.open]:{booleans:[{source:`relaunch`},{source:`testIme`}],enums:[{source:`surface`,values:Re}]},[g.click]:U(),[g.press]:U(),[g.longPress]:U(),[g.hover]:U(),[g.fill]:hr(),[g.type]:hr(),[g.scroll]:{numbers:[{source:`pixels`},{source:`durationMs`}]},[g.gesture]:gr(),[g.swipe]:gr(),[g.screenshot]:{booleans:[{source:`overlayRefs`},{source:`screenshotFullscreen`,output:`fullscreen`},{source:`screenshotNoStabilize`,output:`noStabilize`},{source:`screenshotNormalizeStatusBar`,output:`normalizeStatusBar`}],numbers:[{source:`screenshotPixelDensity`,output:`pixelDensity`},{source:`screenshotScale`,output:`scale`}]},[g.snapshot]:{booleans:[{source:`snapshotInteractiveOnly`,output:`interactiveOnly`},{source:`snapshotDiff`,output:`diff`},{source:`snapshotRaw`,output:`raw`},{source:`snapshotCustomActions`,output:`actions`},{source:`snapshotForceFull`,output:`forceFull`}],numbers:[{source:`snapshotDepth`,output:`depth`}]},[g.back]:{enums:[{source:`backMode`,output:`mode`,values:d}]},[g.record]:{booleans:[{source:`hideTouches`}],numbers:[{source:`fps`}],enums:[{source:`recordingScope`,output:`scope`,values:re}]},[g.apps]:{enums:[{source:`appsFilter`,output:`filter`,values:[`user-installed`,`all`]}]},[g.boot]:{booleans:[{source:`headless`}]},[g.close]:{booleans:[{source:`shutdown`}]}};function pr(e){let t=e.flags??{},n={},r=Object.hasOwn(fr,e.command)?fr[e.command]:void 0;return W(n,t,ur),W(n,t,r),W(n,t,mr(e.command)),Object.keys(n).length>0?n:void 0}function mr(e){return ee(e)?dr:void 0}function U(){return{booleans:[{source:`doubleTap`}],numbers:[{source:`count`},{source:`intervalMs`},{source:`holdMs`},{source:`jitterPx`}],enums:[{source:`clickButton`,values:Be}]}}function hr(){return{numbers:[{source:`delayMs`}]}}function gr(){return{numbers:[{source:`pointerCount`},{source:`count`},{source:`pauseMs`}],enums:[{source:`pattern`,values:ie}]}}function W(e,t,n){n&&(_r(e,t,n.booleans??[]),vr(e,t,n.numbers??[]),yr(e,t,n.enums??[]))}function _r(e,t,n){for(let r of n)br(e,r.output??r.source,t[r.source])}function vr(e,t,n){for(let r of n)xr(e,r.output??r.source,t[r.source])}function yr(e,t,n){for(let r of n)Sr(e,r.output??r.source,t[r.source],r.values)}function G(e){let t=N(e.ref);if(!t)return;let n=t.startsWith(`@`)?t.slice(1):t;return/^[a-zA-Z0-9:_-]+$/.test(n)?n:void 0}function br(e,t,n){typeof n==`boolean`&&(e[t]=n)}function xr(e,t,n){let r=z(n);r!==void 0&&(e[t]=r)}function Sr(e,t,n,r){let i=F(n,r);i!==void 0&&(e[t]=i)}const Cr=65536;function wr(e){return qe(`sha256`).update(e,`utf8`).digest(`hex`).slice(0,32)}function K(e,t){let n=Or(e);if(n===void 0)return!1;try{let e=Er(t),r=Buffer.allocUnsafe(Cr),i=0;do if(i=C.readSync(n,r,0,r.length,null),!e.push(r.subarray(0,i)))return!0;while(i>0);return e.end(),!0}finally{C.closeSync(n)}}async function Tr(e){let t=await kr(e);if(t===void 0)return{lineCount:0,firstLineDigest:void 0};let n={lineCount:0,firstLineDigest:void 0};try{let e=Er(e=>{n.lineCount===0&&(n.firstLineDigest=wr(e)),n.lineCount+=1}),r=Buffer.allocUnsafe(Cr);for(;;){let{bytesRead:n}=await t.read(r,0,r.length,null);if(e.push(r.subarray(0,n)),n===0)break}return e.end(),n}finally{await t.close()}}function q(e){let t;return K(e,e=>(t=wr(e),!1)),t}function Er(e){let t=new Je(`utf8`),n=``,r=!1;return{push(i){if(r)return!1;let a=`${n}${t.write(i)}`,o=0;for(let t=a.indexOf(`
|
|
3
|
+
`);t!==-1;t=a.indexOf(`
|
|
4
|
+
`,o)){if(Dr(a.slice(o,t),e)===!1)return r=!0,!1;o=t+1}return n=a.slice(o),!0},end(){r||Dr(`${n}${t.end()}`,e)}}}function Dr(e,t){let n=e.endsWith(`\r`)?e.slice(0,-1):e;if(n.trim().length!==0)return t(n)}function Or(e){try{return C.openSync(e,`r`)}catch(e){if(e.code===`ENOENT`)return;throw e}}async function kr(e){try{return await C.promises.open(e,`r`)}catch(e){if(e.code===`ENOENT`)return;throw e}}const Ar=5242880;function jr(e=process.env){let t=e.AGENT_DEVICE_EVENT_LOG_MAX_BYTES?.trim();if(t===void 0||!/^\d+$/.test(t))return Ar;let n=Number(t);return Number.isSafeInteger(n)&&n>0?n:Ar}function J(e){return`${e}.1`}function Y(e){return`${e}.window.json`}function Mr(e){let t;for(let n=0;n<3;n+=1){let n=Z(e);try{let t=Nr(e);if(Z(e)===n)return t}catch(r){if(t=r,Z(e)===n)throw r}}throw t??X(e,`the window did not settle while reading`)}function Nr(e){let t=J(e),n=Br(e);if(n===`unverifiable`)throw X(e,`window file is invalid`);if(n===void 0)return Pr(e,t);let r=n.at(-1);if(!r)throw X(e,`window file records no generation`);let i=Ur(e),a=Fr(e,r),o=[],s=Ir({eventLogPath:e,rotatedPath:t,sidecar:n,activeStart:a,activeExists:i});return s!==void 0&&o.push({path:t,firstLineIndex:s}),i&&o.push({path:e,firstLineIndex:a}),{files:o,earliestCursor:o[0]?.firstLineIndex??a}}function Pr(e,t){if(q(t)!==void 0)throw X(e,`a rotated event log exists with no window record`);return{files:Ur(e)?[{path:e,firstLineIndex:0}]:[],earliestCursor:0}}function Fr(e,t){let n=q(e);return n!==void 0&&n===t.firstLineDigest?t.firstLineIndex:t.firstLineIndex+t.lineCount}function Ir(e){let{eventLogPath:t,rotatedPath:n,sidecar:r,activeStart:i,activeExists:a}=e,o=q(n);if(o===void 0)return;let s=r.find(e=>e.firstLineDigest===o);if(!s)throw X(t,`the rotated event log matches no window record`);let c=zr(n);if(c!==s.lineCount)throw X(t,`the rotated event log holds ${c} lines, the window recorded ${s.lineCount}`);if(a&&s.firstLineIndex+s.lineCount!==i)throw X(t,`retained event log generations are not contiguous`);return s.firstLineIndex}async function Lr(e,t){let n=Wr(e);if(!n||n.size<t)return!1;let r=Br(e);if(r===`unverifiable`)return await C.promises.rename(e,J(e)),!0;let i=await Tr(e);if(i.firstLineDigest!==void 0){let t=r??[],n=t.at(-1),a=n&&n.firstLineDigest===i.firstLineDigest?n:{firstLineIndex:n?n.firstLineIndex+n.lineCount:0,lineCount:i.lineCount,firstLineDigest:i.firstLineDigest};await Hr(e,(a===n?t:[...t,a]).slice(-2))}return await C.promises.rename(e,J(e)),!0}function Rr(e,n){if(!(e>=n))throw new t(`COMMAND_FAILED`,`events cursor ${e} precedes the retained event log window; events before cursor ${n} were rotated out.`,{reason:`EVENT_LOG_CURSOR_EXPIRED`,cursor:e,earliestCursor:n,hint:`Resume with cursor ${n}, the oldest retained event; earlier events are no longer available.`})}function X(e,n){return new t(`COMMAND_FAILED`,`Session event log window cannot be verified: ${n}.`,{reason:`EVENT_LOG_WINDOW_UNVERIFIED`,path:e,hint:`Cursor positions for this session cannot be resolved. Delete ${e}, ${J(e)}, and ${Y(e)} to restart the timeline, or read the files directly.`})}function zr(e){let t=0;return K(e,()=>{t+=1}),t}function Z(e){return[Q(Y(e)),Q(e),Q(J(e))].join(`|`)}function Q(e){try{let t=C.lstatSync(e);return`${t.ino}:${t.size}:${t.mtimeMs}`}catch{return`absent`}}function Br(e){let t;try{t=C.readFileSync(Y(e),`utf8`)}catch(e){return e.code===`ENOENT`?void 0:`unverifiable`}try{let e=JSON.parse(t);if(!r(e)||e.version!==2)return`unverifiable`;let{generations:n}=e;if(!Array.isArray(n)||n.length===0)return`unverifiable`;let i=n.map(Vr);return i.every(e=>e!==void 0)?i:`unverifiable`}catch{return`unverifiable`}}function Vr(e){if(!r(e))return;let{firstLineIndex:t,lineCount:n,firstLineDigest:i}=e;if(!(!Number.isSafeInteger(t)||t<0)&&!(!Number.isSafeInteger(n)||n<0)&&typeof i==`string`&&i.length!==0)return{firstLineIndex:t,lineCount:n,firstLineDigest:i}}async function Hr(e,t){let n=Y(e),r=`${n}.${process.pid}.tmp`;await C.promises.writeFile(r,JSON.stringify({version:2,generations:t}),`utf8`),await C.promises.rename(r,n)}function Ur(e){return Wr(e)!==void 0}function Wr(e){try{let n=C.lstatSync(e);if(n.isSymbolicLink())throw new t(`COMMAND_FAILED`,`Session event log must not be a symbolic link: ${e}`);return n}catch(e){if(e.code===`ENOENT`)return;throw e}}const $=new Map,Gr=new Set;function Kr(e){return S.join(e,`events.ndjson`)}function qr(e){return e.command!==g.events}function Jr(t,n,r){let i=e({version:1,ts:r.ts??new Date().toISOString(),session:n,...r});Xr(t,`${JSON.stringify(i)}\n`)}async function Yr(e){await(e?$.get(e):Promise.all($.values()))}function Xr(e,t){let n=($.get(e)??Promise.resolve()).catch(()=>void 0).then(async()=>{await Zr(e),await Lr(e,jr()),await C.promises.appendFile(e,t,`utf8`)}).catch(t=>{y({level:`warn`,phase:`session_event_log_write_failed`,data:{path:e,error:t instanceof Error?t.message:String(t)}})}).finally(()=>{$.get(e)===n&&$.delete(e)});$.set(e,n)}async function Zr(e){let t=S.dirname(e);if(!Gr.has(t))try{await C.promises.mkdir(t,{recursive:!0}),Gr.add(t)}catch(t){throw y({level:`warn`,phase:`session_event_log_dir_failed`,data:{path:e,error:t instanceof Error?t.message:String(t)}}),t}}function Qr(e,t,n){Jr(e,t,{kind:`action.recorded`,requestId:v().requestId,command:n.command,summary:Gn(n),details:Kn(n)})}function $r(e){let{req:t}=e;return{kind:`request.started`,requestId:t.meta?.requestId??v().requestId,command:t.command,summary:`Started ${t.command}`}}function ei(e){let{req:t,response:n,durationMs:r}=e;if(n.ok){let e=$t(t,n.data);return{kind:`request.finished`,requestId:t.meta?.requestId??v().requestId,command:t.command,status:`ok`,summary:e.summary??`Finished ${t.command}`,details:{durationMs:r,...e.details}}}return{kind:`request.finished`,requestId:t.meta?.requestId??v().requestId,command:t.command,status:`error`,summary:`Failed ${t.command}: ${n.error.code}`,details:{durationMs:r,code:n.error.code,diagnosticId:n.error.diagnosticId}}}function ti(e,t={}){let n=ri(t.cursor),r=ii(t.limit),i=Mr(e);Rr(n,i.earliestCursor);let a=ni(i.files,n,r),o=a.lines.flatMap(e=>{let t=ai(e);return t?[t]:[]});return{path:e,cursor:String(n),limit:r,events:o,...a.nextCursor===void 0?{}:{nextCursor:String(a.nextCursor)}}}function ni(e,t,n){let r=[],i;for(let a of e){let e=a.firstLineIndex;if(K(a.path,a=>{if(e>=t+n)return i=t+n,!1;e>=t&&r.push(a),e+=1}),i!==void 0)break}return{lines:r,...i===void 0?{}:{nextCursor:i}}}function ri(e){if(e===void 0||e.trim()===``)return 0;let n=Number(e);if(Number.isInteger(n)&&n>=0)return n;throw new t(`INVALID_ARGS`,`events cursor must be a non-negative integer string.`)}function ii(e){if(e===void 0||typeof e==`string`&&e.trim()===``)return 100;let n=typeof e==`string`?Number(e):e;if(Number.isInteger(n)&&n>=1&&n<=500)return n;throw new t(`INVALID_ARGS`,`events limit must be between 1 and 500.`)}function ai(e){try{let t=oi(JSON.parse(e));return t?si(t):void 0}catch{return}}function oi(e){if(r(e)&&e.version===1&&typeof e.ts==`string`&&typeof e.session==`string`&&ci(e.kind))return e}function si(e){let t=r(e.details)?e.details:void 0;return{version:1,ts:e.ts,session:e.session,kind:e.kind,...typeof e.requestId==`string`?{requestId:e.requestId}:{},...typeof e.command==`string`?{command:e.command}:{},...li(e.status)?{status:e.status}:{},...typeof e.summary==`string`?{summary:e.summary}:{},...t?{details:t}:{}}}function ci(e){return e===`request.started`||e===`request.finished`||e===`action.recorded`}function li(e){return e===`ok`||e===`error`}const ui=36e5;var di=class{sessions=new Map;runtimeHints=new Map;sessionsDir;scriptWriter;constructor(e){this.sessionsDir=e,this.scriptWriter=new At(e)}get(e){return this.sessions.get(e)}set(e,t){this.sessions.set(e,t)}delete(e){return this.runtimeHints.delete(e),this.sessions.delete(e)}values(){return this.sessions.values()}toArray(){return Array.from(this.sessions.values())}lookup(e){let t=this.sessions.get(e);return t?{address:e,session:t}:void 0}findByDevice(e){for(let[t,n]of this.sessions)if(n.device.id===e)return{address:t,session:n}}listRefs(){return Array.from(this.sessions,([e,t])=>({address:e,session:t}))}getRuntimeHints(e){return this.runtimeHints.get(e)}setRuntimeHints(e,t){this.runtimeHints.set(e,t)}clearRuntimeHints(e){return this.runtimeHints.delete(e)}recordAction(e,t){let n=ot(e,t);if(n){let t=this.resolveStoredSessionName(e);Qr(this.resolveEventLogPath(t),t,n)}}recordEvent(e,t){Jr(this.resolveEventLogPath(e),e,t)}readEvents(e,t={}){return ti(this.resolveEventLogPath(e),t)}async flushEvents(e){await Yr(e?this.resolveEventLogPath(e):void 0)}writeSessionLog(e,t){let n=this.scriptWriter.write(e,t);return n.written&&y({level:`info`,phase:`session_script_written`,data:{session:e.name,path:n.path}}),n}finalizeRepairTeardown(e){this.recordRepairFinalizeCloseIfCommitting(e);let t=this.writeSessionLog(e,{force:Me(e,void 0)});it(e)&&(!t.written&&t.error?this.writeRepairTombstone(e,ui,{code:String(t.error.code),message:t.error.message}):this.writeRepairTombstone(e))}recordRepairFinalizeCloseIfCommitting(e){let t=e.scriptPublication??h;ge(t)&&this.recordAction(e,{command:`close`,positionals:[],flags:{},result:{session:e.name,...ze(`Closed: ${e.name}`)}})}writeRepairTombstone(e,t=ui,n){try{let r=this.resolveSessionDir(e.name);C.mkdirSync(r,{recursive:!0});let i={owner:e.name,reapedAt:Date.now(),expiresAt:Date.now()+t,...at(e)?{sourcePath:at(e)}:{},...n?{commitFailure:n}:{}};C.writeFileSync(this.repairTombstonePath(e.name),`${JSON.stringify(i)}\n`)}catch(t){y({level:`warn`,phase:`repair_tombstone_write_failed`,data:{session:e.name,error:t instanceof Error?t.message:String(t)}})}}readRepairTombstone(e){return Ue(this.repairTombstonePath(e))}clearRepairTombstone(e){try{C.rmSync(this.repairTombstonePath(e),{force:!0})}catch{}}repairTombstonePath(e){return We(this.resolveSessionDir(e))}defaultTracePath(e){let t=b(e.name),n=new Date().toISOString().replaceAll(/[:.]/g,`-`);return S.join(this.sessionsDir,`${t}-${n}.trace.log`)}resolveSessionDir(e){if(!Ge(e))throw new t(`INVALID_ARGS`,`Invalid session name ${JSON.stringify(e)}: a session name cannot be empty, ".", or "..".`);return S.join(this.sessionsDir,b(e))}resolveDaemonStateDir(){return S.dirname(this.sessionsDir)}ensureSessionDir(e){let t=this.resolveSessionDir(e);return C.mkdirSync(t,{recursive:!0}),t}resolveAppLogPath(e){return S.join(this.resolveSessionDir(e),`app.log`)}resolveAppLogPidPath(e){return S.join(this.resolveSessionDir(e),`app-log.pid`)}resolveEventLogPath(e){return Kr(this.resolveSessionDir(e))}static expandHome(e,t){return x(e,t)}resolveStoredSessionName(e){for(let[t,n]of this.sessions)if(n===e)return t;return e.name}};export{Qe as _,tr as a,st as c,nt as d,rt as f,T as g,et as h,qr as i,tt as l,$e as m,ei as n,Sn as o,it as p,$r as r,ht as s,di as t,Ze as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{y as e}from"./sdk-contracts.js";import{$n as t,Hn as n,In as r,Kn as i,Vn as a,Wn as o,Zn as s}from"./sdk-batch.js";import{D as c,O as l,k as u,n as d}from"./runtime.js";import{i as f}from"./rect-center.js";import{o as p}from"./tree.js";function m(e){return e.matchedRefs.length===0?{path:2,outcome:`unverifiable`,reason:`selector-miss`}:e.identitySetRefs.length===0?{path:3,outcome:`unverifiable`,reason:`identity-set-empty`}:e.identitySetRefs.length===1?e.identitySetRefs[0]===e.winnerRef?{path:4,outcome:`verified`}:{path:5,outcome:`unverifiable`,reason:`unique-but-wrong`}:e.siblingMatchRefs.length===1?e.siblingMatchRefs[0]===e.winnerRef?{path:6,outcome:`verified`}:{path:6,outcome:`unverifiable`,reason:`signal-isolated-wrong`}:e.regionMemberRefs!==void 0&&e.regionMemberRefs.length>0&&e.viewportCandidateRef!==void 0?e.viewportCandidateRef===e.winnerRef?{path:6,outcome:`verified`}:{path:6,outcome:`unverifiable`,reason:`signal-isolated-wrong`}:{path:6,outcome:`unverifiable`,reason:`no-signal-isolation`}}function h(t,n={}){let r=n.plural===!0?`do`:`does`;return{resolveInput:async()=>{throw new e(`UNSUPPORTED_OPERATION`,`${t} ${r} not resolve input artifacts`)},reserveOutput:async()=>{throw new e(`UNSUPPORTED_OPERATION`,`${t} ${r} not reserve output artifacts`)},createTempFile:async()=>{throw new e(`UNSUPPORTED_OPERATION`,`${t} ${r} not create temporary files`)}}}function g(e,t={}){return{artifacts:h(e,t),policy:d()}}function _(e,t={}){let n=t.mode??`action`,{node:i,preActionNodes:a}=e;if(typeof i.index!=`number`)return;let o=l(a),s=r(x(i),a);if(n===`landmark`&&s.id===void 0&&s.label===void 0)return;let u=c(i,o,8),d=u.chain,f=S(a,i),p=C(i,o),m=T(i),h=+(d.length>0),g=e=>{let t=d.slice(0,e),n=E({nodes:a,byIndex:o,node:i,identity:s,ancestry:t,sibling:f,scrollRegion:p});return{candidate:{...s,ancestry:t,sibling:f,viewportOrder:n.viewportOrder,...p?{scrollRegion:p}:{},...m?{rect:m}:{},verification:`verified`},domain:n}};for(let e=d.length;e>=h;--e){let{candidate:t,domain:r}=g(e);if(y(t))return t.verification=v({node:i,domain:r,mode:n,brokenWalk:u.broken}),t;if(e===h)return b(t)}}function v(e){return e.brokenWalk?`unverifiable`:e.mode===`landmark`?`verified`:O({node:e.node,domain:e.domain})}function y(e){return t(s({...e,verification:`unverifiable`}))<=i}function b(e){return e.verification=`unverifiable`,t(s(e))>4096&&delete e.rect,e}const x=n;function S(e,t){return o(e,t)}function C(e,t){let n=p(e,t);if(!n)return;let r=x(n);return{role:r.role,...r.id===void 0?r.label===void 0?{}:{label:r.label}:{id:r.id}}}function w(e,t){return!e&&!t?!0:!e||!t?!1:a(e,t)}function T(e){let t=e.rect;if(t)return{x:t.x,y:t.y,width:t.width,height:t.height}}function E(e){let{nodes:t,byIndex:n,node:r,identity:i,ancestry:a,sibling:o,scrollRegion:s}=e,c=u(t,n,i,a),l=c.filter(e=>S(t,e)===o),d=c.length>0?c.filter(e=>w(C(e,n),s)):void 0,f=d?D(d):[];return{identitySet:c,siblingMatches:l,regionMembers:d,orderedRegion:f,viewportOrder:Math.max(f.findIndex(e=>e.index===r.index),0)}}function D(e){return e.map((e,t)=>({node:e,documentOrder:t,center:f(e.rect)})).sort((e,t)=>!e.center&&!t.center?e.documentOrder-t.documentOrder:e.center?t.center?e.center.y===t.center.y?e.center.x===t.center.x?e.documentOrder-t.documentOrder:e.center.x-t.center.x:e.center.y-t.center.y:-1:1).map(e=>e.node)}function O(e){let{node:t,domain:n}=e,r=t.ref,i=n.identitySet.map(e=>e.ref);return m({winnerRef:r,matchedRefs:i,identitySetRefs:i,siblingMatchRefs:n.siblingMatches.map(e=>e.ref),regionMemberRefs:n.regionMembers?.map(e=>e.ref),viewportCandidateRef:n.orderedRegion[n.viewportOrder]?.ref}).outcome}export{D as a,m as c,_ as i,C as n,w as o,S as r,g as s,x as t};
|