agent-device 0.21.37 → 0.21.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.37.apk → agent-device-android-ime-helper-0.21.38.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.38.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.37.manifest.json → agent-device-android-ime-helper-0.21.38.manifest.json} +4 -4
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.37.apk → agent-device-android-snapshot-helper-0.21.38.apk} +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.38.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.37.manifest.json → agent-device-android-snapshot-helper-0.21.38.manifest.json} +7 -7
- package/apple/fold-helper/Fold.m +8 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerKeyboardReturnKey.swift +53 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +42 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +26 -18
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +42 -11
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift +123 -22
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +7 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +570 -53
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +41 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerXCTestEventBridge.h +7 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerXCTestEventBridge.m +17 -1
- package/dist/src/THIRD_PARTY_NOTICES.txt +2 -2
- package/dist/src/absence-observation-errors.js +1 -1
- package/dist/src/absence-observation.js +1 -1
- package/dist/src/adapter.js +1 -1
- package/dist/src/adb-executor.js +1 -1
- package/dist/src/adb-failure.js +2 -2
- package/dist/src/adb-transport.js +1 -1
- package/dist/src/agent-browser-lifecycle.js +1 -1
- package/dist/src/agent-browser-process-record.js +1 -1
- package/dist/src/agent-browser-provider.js +1 -1
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/ai-sdk.d.ts +1 -1
- package/dist/src/ai-sdk.js +1 -1
- package/dist/src/alert-contract.js +1 -1
- package/dist/src/alert-tree-driver.js +1 -1
- package/dist/src/alert.js +1 -1
- package/dist/src/android-adb.d.ts +1 -1
- package/dist/src/android.js +1 -1
- package/dist/src/android2.js +1 -1
- package/dist/src/app-backend.js +1 -1
- package/dist/src/app-catalog.js +1 -1
- package/dist/src/app-deployment-resolution.js +1 -1
- package/dist/src/app-inventory.js +1 -1
- package/dist/src/app-launch.js +1 -1
- package/dist/src/app-lifecycle.js +4 -4
- package/dist/src/app-lifecycle2.js +2 -2
- package/dist/src/app-log-files.js +1 -1
- package/dist/src/app-log-runtime2.js +2 -2
- package/dist/src/app-log-session-resource.js +1 -1
- package/dist/src/app-resolution.js +1 -1
- package/dist/src/app-state-read.js +1 -1
- package/dist/src/app-state-runtime.d.ts +1 -1
- package/dist/src/application-lifecycle-interaction.js +1 -1
- package/dist/src/archive.js +1 -1
- package/dist/src/args.js +1 -1
- package/dist/src/artifact-download.js +1 -1
- package/dist/src/artifact-tracking.js +1 -1
- package/dist/src/auth-session.js +1 -1
- package/dist/src/auth.js +1 -1
- package/dist/src/automation-helper-artifact.js +1 -1
- package/dist/src/automation-helper.js +1 -1
- package/dist/src/await-with-signal.js +1 -1
- package/dist/src/backend-snapshot-options.js +1 -1
- package/dist/src/boot-diagnostics.js +1 -1
- package/dist/src/bridge-source.js +1 -1
- package/dist/src/browser-launch.js +1 -1
- package/dist/src/browserstack-device-features.js +1 -1
- package/dist/src/browserstack.js +1 -1
- package/dist/src/cache.js +1 -1
- package/dist/src/capture-disclosure.js +1 -1
- package/dist/src/capture-lifecycle.js +1 -1
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +19 -16
- package/dist/src/cli-output.js +11 -11
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +2 -2
- package/dist/src/click-button.js +1 -1
- package/dist/src/client-metro-companion.js +1 -1
- package/dist/src/client-metro.js +1 -1
- package/dist/src/client-options.js +1 -1
- package/dist/src/client-port.d.ts +246 -208
- package/dist/src/clipboard-shell-response.js +1 -1
- package/dist/src/cloud-artifacts.d.ts +7 -2
- package/dist/src/code-signature-cache.js +1 -1
- package/dist/src/command-schema.js +6 -4
- package/dist/src/command-tools.js +3 -3
- package/dist/src/command.js +1 -1
- package/dist/src/composed-inventory-gateways.js +1 -1
- package/dist/src/composite-resource-admission.js +1 -1
- package/dist/src/config.js +1 -1
- package/dist/src/connection-lease-transaction.js +1 -1
- package/dist/src/connection-metro-runtime.js +1 -1
- package/dist/src/connection-runtime.js +1 -1
- package/dist/src/connection-verification.js +1 -1
- package/dist/src/connection.js +3 -3
- package/dist/src/context.js +1 -1
- package/dist/src/contract.d.ts +2 -1
- package/dist/src/contracts.d.ts +1 -1
- package/dist/src/contracts.js +1 -1
- package/dist/src/daemon-client-attach.js +1 -1
- package/dist/src/daemon-client-dispatch-disclosure.js +1 -1
- package/dist/src/daemon-client-ensure.js +1 -1
- package/dist/src/daemon-client-ensuring.js +1 -1
- package/dist/src/daemon-client-lease-beat.js +1 -1
- package/dist/src/daemon-client-lifecycle.js +1 -1
- package/dist/src/daemon-client-liveness-probe.js +1 -1
- package/dist/src/daemon-client-remote-health-cache.js +1 -0
- package/dist/src/daemon-client-remote-health-recovery.js +1 -0
- package/dist/src/daemon-client-transport.js +1 -1
- package/dist/src/daemon-command-registry.js +1 -1
- package/dist/src/daemon-composition.js +1 -1
- package/dist/src/daemon-diagnostics-scope.js +1 -1
- package/dist/src/daemon-http.js +1 -1
- package/dist/src/daemon-launch-spec.js +1 -1
- package/dist/src/daemon-lifecycle-errors.js +1 -1
- package/dist/src/daemon-policy-file.js +1 -1
- package/dist/src/daemon-registration-owner.js +3 -3
- package/dist/src/daemon-registration.js +1 -1
- package/dist/src/daemon-resolution.js +1 -1
- package/dist/src/daemon-startup-diagnostics.js +1 -1
- package/dist/src/daemon-stop.js +1 -1
- package/dist/src/daemon.js +1 -1
- package/dist/src/debug-symbols-facade.js +3 -3
- package/dist/src/device-claim-admission.js +1 -0
- package/dist/src/device-claim-reconciliation.js +1 -0
- package/dist/src/device-claim-recovery.js +1 -1
- package/dist/src/device-claim-rule.js +1 -1
- package/dist/src/device-claims.js +1 -1
- package/dist/src/device-input-state.d.ts +1 -1
- package/dist/src/device-inventory-context.js +1 -1
- package/dist/src/device-selection-resolver.js +1 -1
- package/dist/src/device-session.js +1 -1
- package/dist/src/device-shell.js +1 -1
- package/dist/src/device.js +1 -1
- package/dist/src/device3.js +3 -3
- package/dist/src/devicectl.js +1 -1
- package/dist/src/diagnostics.js +1 -1
- package/dist/src/discovery.js +1 -1
- package/dist/src/dispatch-resolve.js +1 -1
- package/dist/src/display-inventory.js +1 -1
- package/dist/src/doctor-facade.js +1 -1
- package/dist/src/doctor2.js +1 -1
- package/dist/src/durable-capture-resource.js +1 -1
- package/dist/src/durable-capture.js +1 -1
- package/dist/src/durable-resource.js +1 -1
- package/dist/src/ended-lease.js +1 -1
- package/dist/src/engine-eval-script.js +1 -1
- package/dist/src/error.js +2 -2
- package/dist/src/errors.js +1 -1
- package/dist/src/explicit-session-resolution.js +1 -1
- package/dist/src/expo-dev-client-launch.js +1 -1
- package/dist/src/failure-output.js +1 -1
- package/dist/src/file.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/finders.js +1 -1
- package/dist/src/flag-registry.js +1 -1
- package/dist/src/focus-runtime.js +1 -1
- package/dist/src/fold-helper.js +1 -1
- package/dist/src/generic-settle.js +1 -1
- package/dist/src/generic.js +1 -1
- package/dist/src/gesture-admission.js +1 -1
- package/dist/src/gesture-plan-types.d.ts +1 -1
- package/dist/src/gesture-plan.js +1 -1
- package/dist/src/gesture-runtime.js +1 -1
- package/dist/src/hdc.js +1 -1
- package/dist/src/helper-artifacts.js +1 -1
- package/dist/src/helper.js +2 -2
- package/dist/src/host-file.js +1 -1
- package/dist/src/host.js +1 -1
- package/dist/src/host2.js +1 -1
- package/dist/src/host3.js +1 -1
- package/dist/src/host4.js +1 -1
- package/dist/src/host5.js +1 -1
- package/dist/src/host6.js +1 -1
- package/dist/src/human-control-contract.js +1 -1
- package/dist/src/human-control.js +1 -1
- package/dist/src/ime-rebind.js +1 -1
- package/dist/src/ime-settings-record.js +1 -1
- package/dist/src/ime-state.js +1 -1
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.js +1 -1
- package/dist/src/input-actions.js +1 -1
- package/dist/src/input-actions2.js +1 -1
- package/dist/src/install-artifact-facade.js +1 -1
- package/dist/src/install-source-network-transport.js +1 -1
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-error.js +1 -1
- package/dist/src/interaction-positionals.js +1 -1
- package/dist/src/interaction-ref-policy.js +1 -1
- package/dist/src/interaction2.js +1 -1
- package/dist/src/interactor-operation-binding.js +1 -1
- package/dist/src/interactor.js +5 -5
- package/dist/src/interactor2.js +1 -1
- package/dist/src/interactor3.js +1 -1
- package/dist/src/interactor4.js +1 -1
- package/dist/src/interactor5.js +1 -1
- package/dist/src/interactors.js +1 -1
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/companion-tunnel.js +1 -1
- package/dist/src/internal/daemon.js +1 -1
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/internal/run-script-child.js +1 -1
- package/dist/src/inventory.js +1 -1
- package/dist/src/inventory2.js +1 -1
- package/dist/src/inventory3.js +1 -1
- package/dist/src/inventory5.js +1 -1
- package/dist/src/ios-node-interpretation.js +1 -1
- package/dist/src/ios-simulator-accessibility.js +1 -1
- package/dist/src/ios-snapshot-acquisition.js +1 -1
- package/dist/src/ios-snapshot-engine.js +1 -1
- package/dist/src/ios-snapshot-runtime.js +1 -1
- package/dist/src/launch-confirmation.js +1 -1
- package/dist/src/launch-services-registration.js +1 -1
- package/dist/src/lease-context.js +1 -1
- package/dist/src/lease-registry-scope.js +1 -1
- package/dist/src/lease-release2.js +1 -1
- package/dist/src/lease-scope.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/leased-recording-retention.js +1 -1
- package/dist/src/legacy.js +1 -1
- package/dist/src/limrun-download-file.js +1 -1
- package/dist/src/limrun-ios-files.js +1 -1
- package/dist/src/limrun-ios-runner.js +2 -2
- package/dist/src/limrun-runtime-dependencies.js +1 -1
- package/dist/src/limrun.d.ts +1 -1
- package/dist/src/local-interactor-operation-set.js +1 -1
- package/dist/src/local-simulator-apps.js +1 -1
- package/dist/src/local-simulator-files.js +1 -1
- package/dist/src/location-coordinates.js +1 -1
- package/dist/src/manifest.js +1 -1
- package/dist/src/mechanics.js +12 -12
- package/dist/src/merge-flags.js +1 -1
- package/dist/src/metro-reload-endpoints.js +1 -1
- package/dist/src/metro-session-hints.js +1 -1
- package/dist/src/metro.d.ts +1 -1
- package/dist/src/mobile-snapshot-semantics.js +1 -1
- package/dist/src/network-traffic.js +1 -1
- package/dist/src/node-http.js +1 -1
- package/dist/src/node-touch-point.js +1 -1
- package/dist/src/observation.js +1 -1
- package/dist/src/open-script.js +1 -1
- package/dist/src/open-target-device-resolution.js +1 -1
- package/dist/src/orientation.js +1 -1
- package/dist/src/parameterized-recorded-fill.js +1 -1
- package/dist/src/perf-facade.js +1 -1
- package/dist/src/perf-runtime-operation-builder.js +1 -1
- package/dist/src/perf-runtime-plan.js +1 -1
- package/dist/src/perf-target.js +2 -2
- package/dist/src/perf.js +1 -1
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/platform-runtime-android-adb-host.js +1 -1
- package/dist/src/platform-runtime-app-log-process.js +1 -1
- package/dist/src/platform-runtime-apple-application-tools.js +1 -1
- package/dist/src/platform-runtime-claim-recovery.js +1 -1
- package/dist/src/platform-runtime-host.js +1 -1
- package/dist/src/platform-runtime-open-target.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +3 -3
- package/dist/src/platform-runtime-runtime-hints.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-finalizer-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-process-host.js +1 -1
- package/dist/src/platform-runtime-shutdown-error.js +1 -1
- package/dist/src/platform-runtime-unavailable.js +1 -1
- 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/plugins2.js +1 -1
- package/dist/src/png-crop-bytes.js +1 -1
- package/dist/src/png-resize.js +1 -1
- package/dist/src/png-size.js +1 -1
- package/dist/src/png-worker-client.js +1 -1
- package/dist/src/png.js +1 -1
- package/dist/src/post-gesture-stability.js +1 -1
- package/dist/src/process-executable-path.js +1 -0
- package/dist/src/process-exit.js +1 -1
- package/dist/src/provider-device-runtime.d.ts +2 -2
- package/dist/src/provider-limrun-credentials.js +1 -1
- package/dist/src/provider-plugin.d.ts +1 -1
- package/dist/src/provider-profile-fields.js +1 -1
- package/dist/src/provider-webdriver.js +1 -1
- package/dist/src/provider.js +1 -1
- package/dist/src/proxy.js +2 -2
- package/dist/src/react-devtools-connection.js +1 -1
- package/dist/src/react-devtools-inspect-command.js +1 -1
- package/dist/src/react-native-overlay2.js +2 -2
- package/dist/src/react-native.js +1 -1
- package/dist/src/react-profile-command.js +1 -1
- package/dist/src/record-runtime.js +1 -1
- package/dist/src/record-trace.js +1 -1
- package/dist/src/recording-gestures.js +1 -1
- package/dist/src/recording.js +1 -1
- package/dist/src/rect-center.js +1 -1
- package/dist/src/register-builtins.js +1 -1
- package/dist/src/registry.js +1 -1
- package/dist/src/remote-config-core.js +1 -1
- package/dist/src/remote-config-flags.js +1 -1
- package/dist/src/remote-connection-state.js +1 -1
- package/dist/src/replay-backend-host.js +1 -1
- package/dist/src/replay-divergence.js +1 -1
- package/dist/src/replay-maestro-backend.js +2 -2
- package/dist/src/replay.d.ts +1 -1
- package/dist/src/replay2.js +1 -1
- package/dist/src/reporting.js +1 -1
- package/dist/src/request-dispatch-disclosure.js +1 -1
- package/dist/src/request-ended-leases.js +1 -1
- package/dist/src/request-providers.js +1 -1
- package/dist/src/request-runtime-binding.js +1 -1
- package/dist/src/request.js +1 -1
- package/dist/src/result-serialization.js +2 -2
- package/dist/src/retry.js +1 -1
- package/dist/src/run-script-execution.js +6 -8
- package/dist/src/run-script-http.js +1 -1
- package/dist/src/runner-cache-metadata.js +1 -1
- package/dist/src/runner-cache-retention.js +1 -1
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-contract.js +1 -1
- package/dist/src/runner-dev-tools-security.js +1 -1
- package/dist/src/runner-device-readiness.js +1 -1
- package/dist/src/runner-device-set.js +1 -1
- package/dist/src/runner-disposal.js +1 -1
- package/dist/src/runner-error-classification.js +2 -2
- package/dist/src/runner-exchange.js +1 -1
- package/dist/src/runner-io.js +1 -1
- package/dist/src/runner-launched-session.js +1 -1
- package/dist/src/runner-lease.js +1 -1
- package/dist/src/runner-lifecycle.js +1 -1
- package/dist/src/runner-operations-facade.js +1 -1
- package/dist/src/runner-panel.js +1 -1
- package/dist/src/runner-retention.js +1 -1
- package/dist/src/runner-runtime.js +1 -1
- package/dist/src/runner-selector-query.js +1 -1
- package/dist/src/runner-sequence.js +1 -1
- package/dist/src/runner-start-budget.js +1 -1
- package/dist/src/runner-startup-transport.js +1 -1
- package/dist/src/runner-toolchain-identity.js +1 -1
- package/dist/src/runtime-admission.js +1 -1
- package/dist/src/runtime-deployment.js +1 -1
- package/dist/src/runtime-factory.js +1 -1
- package/dist/src/runtime-session.js +1 -1
- package/dist/src/runtime-transport-hints.js +1 -1
- package/dist/src/runtime.js +2 -2
- package/dist/src/runtime10.js +1 -1
- package/dist/src/runtime11.js +1 -1
- package/dist/src/runtime12.js +1 -1
- package/dist/src/runtime13.js +2 -2
- package/dist/src/runtime2.js +2 -2
- package/dist/src/runtime4.js +3 -3
- package/dist/src/runtime5.js +1 -1
- package/dist/src/runtime6.js +1 -1
- package/dist/src/runtime7.js +2 -2
- package/dist/src/runtime8.js +1 -1
- package/dist/src/runtime9.js +1 -1
- package/dist/src/screen-recording-admission-ledger.js +1 -0
- package/dist/src/screen-recording-completion.js +1 -1
- package/dist/src/screen-recording-options.js +1 -1
- package/dist/src/screen-recording-resource-recovery.js +1 -1
- package/dist/src/screen-recording-stop-recovery.js +1 -1
- package/dist/src/screen-recording-transport.js +1 -1
- package/dist/src/screenshot-density.js +1 -1
- package/dist/src/screenshot-image-size.js +1 -1
- package/dist/src/screenshot-image.js +1 -1
- package/dist/src/screenshot-runtime.js +1 -1
- package/dist/src/screenshot-runtime2.js +1 -1
- package/dist/src/screenshot.js +1 -1
- package/dist/src/screenshot2.js +1 -1
- package/dist/src/screenshot4.js +1 -1
- package/dist/src/script-source.js +1 -1
- package/dist/src/script.js +1 -1
- package/dist/src/scroll-command.js +1 -1
- package/dist/src/scroll-gesture.js +1 -1
- package/dist/src/sdk-batch-runner.d.ts +1 -1
- package/dist/src/sdk-batch-runner.js +2 -2
- package/dist/src/sdk-batch.js +2 -2
- package/dist/src/sdk-contracts.d.ts +26 -2
- 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 +5 -5
- 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 +9 -6
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/selection.js +0 -0
- package/dist/src/selector-pipeline-policy.js +1 -1
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/server-shutdown.js +1 -1
- package/dist/src/server-startup.js +2 -2
- package/dist/src/server.js +4 -4
- package/dist/src/session-allocation.js +1 -1
- package/dist/src/session-artifact-paths.js +1 -1
- package/dist/src/session-capture-binding.js +1 -1
- package/dist/src/session-device-resolution.js +1 -1
- package/dist/src/session-event-action.js +1 -1
- package/dist/src/session-open.js +1 -1
- package/dist/src/session-repair-tombstone.js +1 -1
- package/dist/src/session-replay-vars.js +1 -1
- package/dist/src/session-routing.js +1 -1
- package/dist/src/session-runtime-admission.js +1 -1
- package/dist/src/session-runtime.js +1 -1
- package/dist/src/session-script-destination.js +1 -0
- package/dist/src/session-selector.js +1 -1
- package/dist/src/session-store.js +3 -3
- package/dist/src/session-teardown.js +1 -1
- package/dist/src/session-tenant-scope.js +1 -1
- package/dist/src/session2.js +5 -5
- package/dist/src/settings-bluetooth.js +1 -1
- package/dist/src/settings-global-toggle.js +1 -1
- package/dist/src/settings.js +1 -1
- package/dist/src/settings2.js +1 -1
- package/dist/src/settle-observation-capture.js +1 -1
- package/dist/src/simctl-execution.js +1 -1
- package/dist/src/simctl-facade.js +1 -1
- package/dist/src/simctl.js +1 -1
- package/dist/src/simulator-app-budget.js +1 -1
- package/dist/src/simulator-boot.js +1 -1
- package/dist/src/simulator-facade.js +1 -1
- package/dist/src/simulator-state.js +1 -1
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-baseline.js +1 -1
- package/dist/src/snapshot-chrome.js +1 -1
- package/dist/src/snapshot-desktop-projection.js +1 -1
- package/dist/src/snapshot-diagnostics.js +1 -1
- package/dist/src/snapshot-helper-install.js +3 -3
- package/dist/src/snapshot-helper-session.js +1 -1
- package/dist/src/snapshot-lines.js +1 -1
- package/dist/src/snapshot-node-lookup.js +1 -1
- package/dist/src/snapshot-occlusion.js +1 -1
- package/dist/src/snapshot-private-evidence.js +1 -1
- package/dist/src/snapshot-runtime-binding.js +1 -1
- package/dist/src/snapshot-runtime-capture-input.js +1 -1
- package/dist/src/snapshot-runtime.js +1 -1
- package/dist/src/snapshot-state.js +1 -1
- package/dist/src/snapshot.js +1 -1
- package/dist/src/snapshot2.js +1 -1
- package/dist/src/snapshot3.js +2 -2
- package/dist/src/snapshot4.js +1 -1
- package/dist/src/source-channel.js +1 -1
- package/dist/src/src.js +1 -1
- package/dist/src/src10.js +1 -1
- package/dist/src/src11.js +1 -1
- package/dist/src/src2.js +1 -1
- package/dist/src/src3.js +5 -5
- package/dist/src/src4.js +2 -2
- package/dist/src/src5.js +1 -1
- package/dist/src/src6.js +1 -1
- package/dist/src/src8.js +1 -1
- package/dist/src/store-legacy.js +1 -1
- package/dist/src/store.js +1 -1
- package/dist/src/string-enum.js +1 -1
- package/dist/src/surface-snapshot.js +1 -1
- package/dist/src/surface-snapshot2.js +1 -1
- package/dist/src/sync-cache.js +1 -1
- package/dist/src/system-surface-foreground.js +2 -2
- package/dist/src/takeover.js +1 -1
- package/dist/src/tap-keyboard-occlusion.js +1 -1
- package/dist/src/target-evidence-tree.js +1 -1
- package/dist/src/target-evidence.js +1 -1
- package/dist/src/telephony-runtime.js +1 -1
- package/dist/src/tool-provider-facade.js +1 -1
- package/dist/src/tool-provider.js +3 -3
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/tool-provider3.js +1 -1
- package/dist/src/toolchain-probe.js +1 -1
- package/dist/src/touch-runtime.js +1 -1
- package/dist/src/touch-runtime2.js +1 -1
- package/dist/src/transport.js +2 -2
- package/dist/src/tree.js +1 -1
- package/dist/src/tv-remote-runtime.js +1 -1
- package/dist/src/tv-remote.js +1 -1
- package/dist/src/type-text-runtime.js +1 -1
- package/dist/src/unsupported-interactor.js +1 -1
- package/dist/src/update-check.js +1 -1
- package/dist/src/validation.js +1 -1
- package/dist/src/vars.js +1 -1
- package/dist/src/vega-executable.js +1 -1
- package/dist/src/verified-file.js +1 -1
- package/dist/src/video.js +2 -2
- package/dist/src/viewport.js +1 -1
- package/dist/src/web.js +1 -1
- package/dist/src/webdriver-source.js +1 -1
- package/package.json +2 -2
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.37.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.37.apk.sha256 +0 -1
- package/dist/src/capture-output-ownership.js +0 -1
package/dist/src/runtime4.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`,String.raw`\n`)}const mt=Object.freeze({available:!0}),ht=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`telephony simulates calls and SMS through the Android emulator console; a physical device has no console, so place a real call or send a real message to it instead.`});function gt(e){return e.kind===`emulator`?mt:ht}function _t(e){return Object.freeze({sendTelephonyEvent:gt(e)})}function vt(
|
|
1
|
+
import{Mn as e,jn as t,wn as n}from"./sdk-batch.js";import{_ as r,z as i}from"./sdk-contracts.js";import{a}from"./sdk-batch-runner.js";import{St as o,q as s}from"./sdk-io.js";import"./diagnostics.js";import{J as c}from"./sdk-device.js";import{i as l,n as u}from"./recording-stop-observation.js";import{n as d,t as f}from"./android-snapshot-quality.js";import{n as p}from"./device-shell.js";import{n as m}from"./adb-failure.js";import"./retry.js";import{i as h,o as g}from"./adb.js";import{a as ee,r as te}from"./durable-resource.js";import{n as ne}from"./screen-recording-runtime.js";import{n as _,r as v,t as y}from"./application-lifecycle-runtime.js";import{n as re}from"./async-lifecycle.js";import{i as ie}from"./touch-runtime.js";import{t as b}from"./mp4-duration.js";import{r as x,t as S}from"./gesture-admission.js";import{readAndroidAppStateWithExecutor as ae}from"./app-state.js";import{ANDROID_CLIPBOARD_SHELL_COMMAND_UNAVAILABLE_HINT as oe}from"./clipboard-shell-response.js";import{androidAppDeploymentFacts as se,createAndroidAppDeploymentOperations as ce,t as C}from"./runtime2.js";import{createAndroidPerfOperations as le}from"./runtime3.js";import{C as ue,D as de,F as fe,M as pe,O as me,R as he,V as ge,W as _e,_ as ve,h as ye,j as be,l as xe,o as Se,p as Ce,r as we,v as Te,x as Ee}from"./tv-remote-runtime.js";import{n as De}from"./audio-probe-runtime.js";import{n as Oe}from"./perf-runtime.js";import{a as ke,i as Ae}from"./screenshot-runtime2.js";import{t as je}from"./viewport-runtime.js";import{a as Me,n as Ne,o as Pe,s as Fe,u as Ie}from"./application-lifecycle-interaction.js";import{t as Le}from"./local-interactor-operation-set.js";import{n as Re,t as ze}from"./network-traffic.js";import{a as Be,n as Ve,t as He}from"./src10.js";import{n as Ue}from"./screen-recording-completion.js";import{a as We,i as w,o as Ge,s as Ke,t as qe}from"./stop-sequence.js";import{t as Je}from"./fold-runtime.js";import{t as Ye}from"./app-log-runtime.js";import T from"node:path";async function E(e,t,n){let r=await h(e,[`emu`,...t],{signal:n,allowFailure:!0,timeoutMs:1e4});if(r.exitCode!==0)throw m(`adb emu ${t.slice(0,2).join(` `)} exited with code ${r.exitCode}`,r,{deviceId:e.id});let i=/^KO\b:?[ \t]*(.*)$/m.exec(r.stdout);return i?{stdout:r.stdout,refusal:i[1].trim()}:{stdout:r.stdout}}const D=Object.freeze({closed:{id:`1`,state:`CLOSED`},"half-open":{id:`2`,state:`HALF_OPENED`},open:{id:`3`,state:`OPENED`}});async function Xe(e,t,n={}){let{signal:r}=n;r?.throwIfAborted();let i=Qe(e,t),a=await $e(e,r),s=D[i],c=Ze(e,i,a),l=i===`closed`&&await it(e,r);return await et(e,i,s.id,r),o({level:`info`,phase:`android_fold_pose_dispatched`,data:{deviceId:e.id,pose:i}}),await tt(e,i,c,a,r),i===`closed`&&!l&&await rt(e,r),{pose:i,hingeAngleDegrees:await at(e,r)}}function Ze(e,t,n){let i=D[t],a=n.get(i.state);if(a!==void 0)return a;let o=Object.keys(D).filter(e=>n.has(D[e].state)),s=o.map(e=>D[e].state);throw s.length===0?new r(`UNSUPPORTED_OPERATION`,`${e.name} is not a foldable emulator: it lists no CLOSED, HALF_OPENED, or OPENED device state`,{deviceId:e.id,reason:`single-panel-device`,hint:`fold poses the hinge of a foldable emulator such as the Pixel 9 Pro Fold; this emulator lists no CLOSED, HALF_OPENED, or OPENED device state, so it has no hinge to pose.`}):new r(`UNSUPPORTED_OPERATION`,`${e.name} has no ${i.state} device state to commit for the ${t} pose; it lists ${s.join(`, `)}`,{deviceId:e.id,reason:`fold-posture-unsupported`,requestedPose:t,supportedPoses:o,deviceStates:s,hint:`This profile poses only ${o.join(` and `)}; request one of those.`})}function Qe(e,t){if(t.pose===void 0)throw new r(`UNSUPPORTED_OPERATION`,`fold keyframes are not supported on Android`,{deviceId:e.id,reason:`fold-keyframes-unsupported`,hint:`The emulator console poses the hinge at fixed angles only; request closed, half-open, or open.`});return t.pose}async function $e(e,t){let{stdout:n}=await O(e,[`cmd`,`device_state`,`print-states`],t),r=new Map;for(let e of n.matchAll(/identifier=(\d+), name='([A-Z_]+)'/g))r.set(e[2],e[1]);return r}async function et(e,t,n,i){let a=await E(e,[`posture`,n],i);if(a.refusal!==void 0)throw new r(`COMMAND_FAILED`,`Unable to set the emulator posture for ${t}`,{deviceId:e.id,reason:`fold-posture-dispatch-failed`,stdout:a.stdout.trim(),hint:`The emulator console refused the posture. Check that the AVD is a foldable profile (hw.sensor.hinge=yes), then retry.`})}async function tt(e,t,n,i,a){let o;for(let t=1;t<=60;t+=1)if(a?.throwIfAborted(),t>1&&await s(250,a),o=await nt(e,a),o===n)return;let c=[...i].find(([,e])=>e===o)?.[0];throw new r(`COMMAND_FAILED`,`${e.name} did not reach the ${t} pose: the emulator still reports device state ${c??o}`,{deviceId:e.id,requestedPose:t,observedDeviceState:c??o,reason:`fold-pose-unverified`,hint:"The emulator console accepted the posture, but the guest did not commit the matching device state. Read it directly with `adb shell cmd device_state print-state` to see which state the emulator holds."})}async function nt(e,t){let{stdout:n}=await O(e,[`cmd`,`device_state`,`print-state`],t);return/\d+/.exec(n)?.[0]}async function rt(e,t){let n=0,i=!1;for(let r=1;r<=60;r+=1)if(await s(250,t),await it(e,t))n=0,i=!0,await O(e,[`wm`,`dismiss-keyguard`],t);else if(n+=1,n>=3)break;if(n<3)throw new r(`COMMAND_FAILED`,`${e.name} stays locked after the fold`,{deviceId:e.id,reason:`fold-lock-screen-persists`,hint:"The fold lit a panel Android keeps locked and `wm dismiss-keyguard` did not clear it; a keyguard with a PIN or password has to be unlocked by hand."});i&&o({level:`info`,phase:`android_fold_lock_screen_dismissed`,data:{deviceId:e.id}})}async function it(e,t){let{stdout:n}=await O(e,[`dumpsys`,`window`],t);return n.includes(`isKeyguardShowing=true`)}async function at(e,t){let{stdout:n}=await E(e,[`sensor`,`get`,`hinge-angle0`],t),i=/hinge-angle0\s*=\s*(-?\d+(?:\.\d+)?)/.exec(n);if(!i)throw new r(`COMMAND_FAILED`,`${e.name} reports no hinge angle`,{deviceId:e.id,reason:`fold-hinge-angle-unreadable`,stdout:n.trim(),hint:"The emulator console answered the posture but exposes no hinge-angle0 sensor to read back; check that the AVD is a foldable profile (hw.sensor.hinge=yes) and that the emulator build supports `sensor get hinge-angle0`."});return Number(i[1])}async function O(e,t,n){let r=await g(e,t,{signal:n,allowFailure:!0});if(r.exitCode!==0)throw m(`adb shell ${t.join(` `)} exited with code ${r.exitCode}`,r,{deviceId:e.id});return r}const ot=Object.freeze({available:!0}),st=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`fold poses the hinge of a foldable Android emulator through the emulator console; a physical device is folded by hand.`});function ct(e){return e.kind===`emulator`?ot:st}function lt(e){return Je({fold:ct(e)})}function ut(t){let{device:n,signal:r}=t;return e(lt(n).setFoldPose,()=>({setFoldPose:async e=>(r.throwIfAborted(),await Xe(n,e,{signal:r}))}))}async function dt(e,t,n){let i=await E(e,ft(t),n);if(i.refusal!==void 0)throw new r(`COMMAND_FAILED`,`The emulator console refused telephony ${t.action}`,{deviceId:e.id,reason:`telephony-console-refused`,stdout:i.stdout.trim(),...i.refusal?{consoleReason:i.refusal}:{},hint:`The emulator console refused the event. accept needs a call from that same number (start one with telephony call <number>), and an emulator image without a modem has no telephony to simulate.`})}function ft(e){switch(e.action){case`call`:case`accept`:case`cancel`:return[`gsm`,e.action,e.number];case`sms`:return[`sms`,`send`,e.number,pt(e.text)]}}function pt(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`
|
|
2
|
+
`,String.raw`\n`)}const mt=Object.freeze({available:!0}),ht=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`telephony simulates calls and SMS through the Android emulator console; a physical device has no console, so place a real call or send a real message to it instead.`});function gt(e){return e.kind===`emulator`?mt:ht}function _t(e){return Object.freeze({sendTelephonyEvent:gt(e)})}function vt(t){let{device:n,signal:r}=t;return e(_t(n).sendTelephonyEvent,()=>({sendTelephonyEvent:async e=>{r.throwIfAborted(),await dt(n,e,r)}}))}function yt(e){return We(e)?Object.freeze({available:!0}):e.kind===`emulator`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`audio probe capture requires a macOS host.`}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`audio probe capture is supported for Android emulators on macOS hosts.`})}function bt(e){if(!/^[a-zA-Z0-9._:-]+$/.test(e))throw new r(`INVALID_ARGS`,`Invalid Android package name for logs: ${e}`)}const k=Object.freeze({resourceKind:Ye,version:1,encode:e=>({...e}),decode:e=>e.transport!==`android-logcat-local`&&e.transport!==`android-logcat-transport-composed`||!St(e.outputPath)||!St(e.pidPath)?{status:`invalid`,message:`Invalid Android app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:e.transport,outputPath:e.outputPath,pidPath:e.pidPath})}});function xt(e){let t=k.decode(e.descriptor);if(t.status!==`decoded`)throw TypeError(t.message);return te({resourceKind:Ye,sessionId:e.sessionId,device:{id:e.device.id,family:`android`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:ee(k,t.descriptor)})}function St(e){return typeof e==`string`&&e.trim().length>0}function Ct(e){return He(e,{family:`android`,backend:`android`,label:`Android`,codec:k,startUnavailableHint:`The selected Android transport cannot start a background adb logcat stream.`,cleanupFailureMessage:`Android app-log cleanup did not settle every owned resource`,doctor:async({host:e,device:t,signal:n},r)=>await wt(e,t.id,r,n),validateStart:({input:e})=>bt(e.appBundleId),process:async({host:e,device:t,input:n})=>({resolvePid:async r=>await Ve(e,Tt(t.id,n.appBundleId),r),command:e=>({kind:`android-adb`,serial:t.id,args:[`logcat`,`-v`,`time`,`--pid`,e],options:{allowFailure:!0}})}),descriptor:({artifacts:e,transport:t})=>({transport:t.mode===`transport-composed`?`android-logcat-transport-composed`:`android-logcat-local`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>xt({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function wt(e,t,n,r){let i={};return i.adbAvailable=await Ke(async()=>Ge(await e.commands.run({executable:`adb`,args:p(`adb`,`shell`,[`echo`,`ok`],[`-s`,t]),allowFailure:!0,timeoutMs:1e3},r)),r),n&&(i.androidPidVisible=await Ke(async()=>!!await Ve(e,Tt(t,n),r),r)),{backend:`android`,checks:i,notes:n?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}}function Tt(e,t){return{executable:`adb`,args:p(`adb`,`shell`,[`pidof`,t],[`-s`,e]),allowFailure:!0,timeoutMs:5e3}}async function Et(e,t,n,r){let i=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),a=Re(i.text,{...n,path:i.path,exists:i.exists,lineNumberOffset:i.skippedLines,backend:`android`}),o=[],s=await Ot(e,t,n,r);if(s&&n.appBundleId){bt(n.appBundleId);let c=await At(e,t,n.appBundleId,r);if(c){let e=Re(c.text,{...n,path:`${i.path} (adb logcat recovery)`,exists:!0,backend:`android`});e.dump.entries.length>0&&(a=ze(e,a,n.maxEntries),o.push(s.reason===`stale-active`?`Session app log stream was still bound to prior Android PID ${s.trackedPid}. Recovered recent Android HTTP entries from adb logcat for PID set ${c.pids.join(`, `)}.`:`Session app log stream was inactive. Recovered recent Android HTTP entries from adb logcat for PID set ${c.pids.join(`, `)}.`))}}return n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&o.length===0&&o.push(`Session app log stream is inactive. Run logs clear --restart, reproduce the request window again, then rerun network dump.`):o.push(`Capture uses the session app log file. For fresh traffic, run logs clear --restart before reproducing requests.`),a.dump.entries.length===0&&o.push(`No HTTP(s) entries were found in recent session app logs.`),Object.freeze({source:`app-log`,backend:`android`,dump:a.dump,notes:Object.freeze(o)})}async function Dt(e,t,n){n.throwIfAborted();try{let r=await e.commands.run(t,n);return n.throwIfAborted(),r}catch{n.throwIfAborted();return}}async function Ot(e,t,n,r){if(!n.appBundleId||n.appLogSnapshot?.state===void 0)return;if(n.appLogSnapshot.state!==`active`)return{reason:`inactive`};let i=kt(await e.appLogs.readProcessMarker(n.sessionId));if(!i)return;let a=await jt(e,t.id,n.appBundleId,r);if(!(!a||a===i))return{reason:`stale-active`,trackedPid:i}}function kt(e){if(e.status===`decoded`)return/(?:^|\s)--pid\s+(\d+)(?:\s|$)/.exec(e.marker.command)?.[1]}async function At(e,t,n,r){let i=await jt(e,t.id,n,r),a=await Dt(e,{executable:`adb`,args:[`-s`,t.id,`logcat`,`-d`,`-v`,`time`,`-t`,`4000`],allowFailure:!0,timeoutMs:3e3},r);if(!a||a.exitCode!==0||!a.stdout.trim())return;let o=Mt(a.stdout,n,i);if(o.length===0)return;let s=new Set(o),c=a.stdout.split(`
|
|
3
3
|
`).filter(e=>{if(!e.trim())return!1;if(e.includes(n))return!0;let t=/\(\s*(\d+)\)\s*:/.exec(e)?.[1];return!!(t&&s.has(t))}).join(`
|
|
4
4
|
`);return c.trim()?{text:c,pids:o}:void 0}async function jt(e,t,n,r){let i=await Dt(e,{executable:`adb`,args:p(`adb`,`shell`,[`pidof`,n],[`-s`,t]),allowFailure:!0},r);if(!i)return;let a=i.stdout.trim().split(/\s+/)[0];return a&&/^\d+$/.test(a)?a:void 0}function Mt(e,t,n){let r=new Set(n?[n]:[]),i=t.replaceAll(/[.*+?^${}()|[\]\\]/g,String.raw`\$&`),a=[RegExp(`\\bStart proc\\s+(\\d+):${i}(?:\\b|/)`,`i`),RegExp(`\\b(\\d+):${i}(?:\\b|/)`,`i`),RegExp(`${i}.*?\\bpid\\s*[=:]?\\s*(\\d+)\\b`,`i`),RegExp(`\\bpid\\s*[=:]?\\s*(\\d+)\\b.*${i}`,`i`)];for(let n of e.split(`
|
|
5
|
-
`))if(n.includes(t))for(let e of a){let t=e.exec(n)?.[1];t&&/^\d+$/.test(t)&&r.add(t)}return Object.freeze([...r])}function A(e,t){if(t===1)return e;let n=T.parse(e);return T.join(n.dir,`${n.name}.part-${String(t).padStart(3,`0`)}${n.ext||`.mp4`}`)}const Nt=/^(?:\/sdcard|\/data\/local\/tmp)\/agent-device-recording-\d{1,20}\.mp4$/,Pt=/^(?:\/sdcard|\/data\/local\/tmp)\/agent-device-recording-active\.json$/;function Ft(e){return Rt(e)&&zt(e)&&Bt(e)}function It(e){if(!j(e))return!1;let t=e;return Vt(t)&&Ht(t)&&Ut(t)&&Wt(t)&&(t.completion===void 0||Zt(t))}function Lt(e,t){return Qt(e,t)&&$t(e,t.outputPath,t.clientOutputPath)}function Rt(e){return e.backend===`adb-screenrecord`&&typeof e.manifestPath==`string`&&Pt.test(e.manifestPath)&&typeof e.outputPath==`string`}function zt(e){return tn(e.clientOutputPath)&&w(e)}function Bt(e){return en(e.transportMode)}function Vt(e){return e.version===1&&e.resourceKind===`screen-recording`&&typeof e.fenceToken==`string`&&Number.isInteger(e.fenceGeneration)&&typeof e.sessionId==`string`&&typeof e.deviceId==`string`&&Number.isFinite(e.startedAt)}function Ht(e){return typeof e.outputPath==`string`&&tn(e.clientOutputPath)&&w(e)}function Ut(e){return en(e.transportMode)&&(e.pendingRemotePath===void 0||nn(e.pendingRemotePath))}function Wt(e){return Array.isArray(e.chunks)&&e.chunks.every(Gt)&&(e.chunks.length>0||e.pendingRemotePath!==void 0)&&(e.completion===void 0||Kt(e.completion))}function Gt(e,t){if(!j(e))return!1;let n=e;return n.index===t+1&&nn(n.remotePath)&&rn(n.remotePid)&&rn(n.remoteStartTime)}function Kt(e){if(!j(e))return!1;let t=e;return Jt(t)&&Yt(t)&&qt(t)&&(t.chunks===void 0||t.chunks.every(Xt))}function qt(e){return(e.stopObservation===void 0||u(e.stopObservation))&&(e.nativePathDisposition===void 0||l(e.nativePathDisposition))}function Jt(e){return typeof e.backend==`string`&&typeof e.outPath==`string`&&(e.clientOutPath===void 0||typeof e.clientOutPath==`string`)&&Number.isFinite(e.startedAt)&&Number.isFinite(e.completedAt)&&(e.capturedDurationMs===void 0||Number.isFinite(e.capturedDurationMs))}function Yt(e){return w(e)}function Xt(e,t){return e.index===t+1&&typeof e.path==`string`&&(e.clientOutPath===void 0||typeof e.clientOutPath==`string`)}function Zt(e){let t=e.completion;return t!==void 0&&Qt(t,e)&&t.startedAt===e.startedAt&&$t(t,e.outputPath,e.clientOutputPath,e.chunks.length)}function Qt(e,t){return e.backend===`adb screenrecord`&&e.outPath===t.outputPath&&e.clientOutPath===t.clientOutputPath&&e.scope===t.scope&&e.showTouches===t.showTouches&&e.recordOnlySession===t.recordOnlySession&&an(e.activeSessionApp,t.activeSessionApp)}function $t(e,t,n,r=e.chunks===void 0?1:e.chunks.length){return r===1?e.chunks===void 0:e.chunks?.length===r&&e.chunks.every((e,r)=>e.path===A(t,r+1)&&e.clientOutPath===(n===void 0?void 0:A(n,r+1)))}function j(e){return typeof e==`object`&&!!e}function en(e){return e===`local`||e===`transport-composed`}function tn(e){return e===void 0||typeof e==`string`}function nn(e){return typeof e==`string`&&Nt.test(e)}function rn(e){return typeof e==`string`&&/^\d+$/.test(e)}function an(e,t){return JSON.stringify(e)===JSON.stringify(t)}const M=Object.freeze({resourceKind:ne,version:1,encode:e=>({...e}),decode:e=>Ft(e)?{status:`decoded`,descriptor:Object.freeze({backend:`adb-screenrecord`,manifestPath:e.manifestPath,outputPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutputPath:e.clientOutputPath},scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,transportMode:e.transportMode,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},...e.fps===void 0?{}:{fps:e.fps}})}:{status:`invalid`,message:`Invalid Android screen-recording descriptor`}});function on(e){return{outputPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutputPath:e.clientOutputPath},scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},...e.fps===void 0?{}:{fps:e.fps}}}function N(e,t,n,r,i,a=`local`){return Object.freeze({version:1,resourceKind:`screen-recording`,fenceToken:t.fence.token,fenceGeneration:t.fence.generation,sessionId:t.sessionId,deviceId:e.id,startedAt:n,...on(t),chunks:r,...i===void 0?{}:{pendingRemotePath:i},transportMode:a})}function sn(e,t){return Object.freeze({...e,completion:t})}function P(e){try{let t=e&&JSON.parse(e);return It(t)?t:void 0}catch{return}}function cn(e,t,n){return e.deviceId===t.id&&e.deviceId===n.device.id&&e.fenceToken===n.fence.token&&e.fenceGeneration===n.fence.generation&&e.sessionId===n.sessionId}function ln(e,t){return e.outputPath===t.outputPath&&e.clientOutputPath===t.clientOutputPath&&e.scope===t.scope&&e.showTouches===t.showTouches&&e.recordOnlySession===t.recordOnlySession&&JSON.stringify(e.activeSessionApp)===JSON.stringify(t.activeSessionApp)&&e.exportQuality===t.exportQuality&&e.fps===t.fps&&e.transportMode===t.transportMode&&(e.completion===void 0||Lt(e.completion,t))}function F(e){switch(e){case`missing`:case`ownership-lost`:case`foreign-writer`:return!0;case`owned-alive`:case`uncertain`:return!1}}function un(e){switch(e){case`missing`:case`ownership-lost`:return!0;case`foreign-writer`:case`owned-alive`:case`uncertain`:return!1}}const dn=1e4,fn=1e3;var I=class extends Error{constructor(e){super(`Android screenrecord launch rollback could not be confirmed`,{cause:e})}},L=class extends Error{constructor(){super(`Android screenrecord rotation refused: the recording stop was already claimed`)}};function R(e,t=Date.now()){return[...new Set(e?[e,`/sdcard`,`/data/local/tmp`]:[`/sdcard`,`/data/local/tmp`])].map(e=>`${e}/agent-device-recording-${t}.mp4`)}async function pn(e,t,n,r){let i;try{if(i=(await e.start({remotePath:t,quality:n.exportQuality??`medium`},r)).process,!/^\d+$/.test(i.pid)||!/^\d+$/.test(i.startTime)||i.remotePath!==t)throw Error(`Android screenrecord returned an invalid process identity`);if(!await vn(e,t,i,r))throw Error(`Android screenrecord did not begin producing frames`);return{index:1,remotePath:t,remotePid:i.pid,remoteStartTime:i.startTime}}catch(t){throw i&&mn(i)&&!await yn(e,i)?new I(t):r?.aborted?r.reason:t}}function mn(e){return/^\d+$/.test(e.pid)&&/^\d+$/.test(e.startTime)&&e.remotePath.length>0}async function z(e,t){let n=t.at(-1),r=!1,i;for(let a of[...t].reverse())try{let t=await H(e,a);a===n&&(r=t)}catch(e){i??=e}if(i)throw i;return r}async function hn(e,t){for(let n of t){let t;for(let r=0;r<3;r+=1){let i=await e.size(n.remotePath);if(typeof i==`number`&&i>0&&i===t)break;if(t=typeof i==`number`&&i>0?i:void 0,r===2)throw Error(`Android recording artifact is not stable: ${n.remotePath}`);await new Promise(e=>setTimeout(e,250))}}}async function gn(e,t,n){for(let[r,i]of t.entries())await bn(e,i.remotePath,A(n,r+1))}async function B(e,t){let n;for(let r of t)try{if(!await e.remove(r.remotePath))throw Error(`failed to remove Android recording artifact: ${r.remotePath}`)}catch(e){n??=e}if(n)throw n}async function _n(e,t){for(let n of t)if(await e.exists(n.remotePath)!==!1)return`retirable`;return`retired`}async function V(e,t){try{await z(e,t)}finally{await B(e,t)}}async function vn(e,t,n,r){for(let i=0;i<3;i+=1){if(r?.throwIfAborted(),await e.exists(t,r)===!0)return!0;if(await e.inspect(n,r)!==`owned-alive`)return!1;i<2&&await new Promise(e=>setTimeout(e,250))}return!0}async function yn(e,t){try{let n=await e.stop(t,{force:!0});return(n===`stopped`||n===`already-missing`)&&await e.remove(t.remotePath)}catch{return!1}}async function H(e,t){if(!t)return!1;let n={pid:t.remotePid,remotePath:t.remotePath,startTime:t.remoteStartTime},r=await e.stop(n);if(r===`already-missing`)return!0;if(r===`ownership-lost`)throw Error(`Android screenrecord ownership could not be confirmed for pid ${t.remotePid}`);if(await xn(e,n))return!1;let i=await e.stop(n,{force:!0});if(i===`stopped`||i===`already-missing`)return!1;throw Error(`failed to stop Android screenrecord pid ${t.remotePid}`)}async function bn(e,t,n){for(let r=0;r<3;r+=1){let i=await e.pullPlayable({remotePath:t,outputPath:n});if(i.exitCode===0&&i.playable)return;r+1<3&&await Sn(1e3)}throw Error(`failed to retrieve playable Android recording`)}async function xn(e,t){for(let n=0;n<=dn;n+=fn){let r=await e.inspect(t);if(r===`missing`)return!0;if(F(r))throw Error(`Android screenrecord ownership could not be confirmed for pid ${t.pid}`);n<dn&&await Sn(fn)}return!1}function Sn(e){return new Promise(t=>setTimeout(t,e))}async function U(e,t,n,r){await e.writeManifest({manifestPath:t,contents:JSON.stringify(n)},r)}async function W(e,t){if(!await e.removeManifest(t))throw Error(`failed to remove Android recording manifest: ${t}`)}async function Cn(e,t){return await Promise.all(t.map(async t=>({chunk:t,state:await e.inspect({pid:t.remotePid,remotePath:t.remotePath,startTime:t.remoteStartTime})})))}async function wn(e,t){let n=(await Tn(e)).flatMap(n=>En(n,t,e.mode));for(let t of n)await On(e,t.evidence,t.manifestPath)}async function Tn(e){return await Promise.all(R(void 0).map(async t=>{let n=e.manifestPathFor(t);return{manifestPath:n,read:await e.readManifest(n)}}))}function En(e,t,n){if(e.read.status===`missing`)return[];if(e.read.status!==`read`)throw jn(e.manifestPath,e.read.message);let r=P(e.read.contents);if(r===void 0)throw Mn(e.manifestPath);if(r.transportMode!==n)throw Nn(e.manifestPath,r,n);if(!Dn(r,t))throw Pn(e.manifestPath,r,t);return[{manifestPath:e.manifestPath,evidence:r}]}function Dn(e,t){return e.completion!==void 0||e.deviceId!==t.id}async function On(e,t,n){if(await kn(e,t),await B(e,t.chunks),await An(e,t),await W(e,n),(await e.readManifest(n)).status!==`missing`)throw Ln(n)}async function kn(e,t){for(let{chunk:n,state:r}of await Cn(e,t.chunks))if(!un(r))throw r===`uncertain`?Rn(n.remotePath):Fn(n.remotePath,r===`owned-alive`?`named-recorder`:`other-recorder`);let n=t.pendingRemotePath;if(n===void 0)return;let r=await e.probeRunningWriters(n);if(r.writers.length>0)throw Fn(n,`other-recorder`);if(!r.conclusive)throw Rn(n)}async function An(e,t){let n=t.pendingRemotePath;if(n!==void 0&&!await e.remove(n))throw In(n)}function jn(t,n){return new e(`COMMAND_FAILED`,`Android screenrecord native recovery evidence is unavailable: ${t}`,{reason:`native_recovery_evidence_unavailable`,manifestPath:t,hint:`Confirm the device is online and its storage readable, then run record start again.`},Error(n))}function Mn(t){return new e(`COMMAND_FAILED`,`Android screenrecord native recovery evidence is unreadable: ${t}`,{reason:`native_recovery_evidence_unreadable`,manifestPath:t,hint:G(t)})}function Nn(t,n,r){return new e(`COMMAND_FAILED`,`Android screenrecord native recovery evidence was written by the ${n.transportMode} transport, not this ${r} one: ${t}`,{reason:`native_recovery_evidence_transport_mismatch`,manifestPath:t,evidenceTransportMode:n.transportMode,hint:G(t)})}function Pn(t,n,r){return new e(`DEVICE_IN_USE`,`Android screenrecord native recovery evidence already exists: ${t} (open recording of session "${n.sessionId}" on ${r.id})`,{reason:`native_recovery_evidence_open`,manifestPath:t,sessionId:n.sessionId,retriable:!1,hint:`Run record stop --session ${n.sessionId} to retire it, or close that session. If it is already closed, ${G(t)}`})}function Fn(t,n){let r=n===`named-recorder`;return new e(`DEVICE_IN_USE`,`Android screenrecord recovery evidence is retained: ${r?`its recorder`:`another recorder`} is writing ${t}`,{reason:`native_recording_artifact_claimed`,remotePath:t,writer:n,...r?{retriable:!1}:{},hint:r?`Run record stop for the session that owns that recording before starting another.`:`Android ends any recorder after 180 seconds. Run record start again once that recorder has stopped.`})}function In(t){return new e(`COMMAND_FAILED`,`Android screenrecord recovery evidence could not remove ${t}`,{reason:`native_recording_artifact_removal_failed`,remotePath:t,hint:`Confirm the device is online and run record start again.`})}function Ln(t){return new e(`COMMAND_FAILED`,`Android screenrecord recovery evidence removal could not be confirmed: ${t}`,{reason:`native_recovery_evidence_retirement_unconfirmed`,manifestPath:t,hint:`Run record start again; the marker is retired from the beginning.`})}function Rn(t){return new e(`COMMAND_FAILED`,`Android screenrecord recovery evidence cannot be safely retired: ${t}`,{reason:`native_recording_recorder_unproven`,remotePath:t,hint:`Confirm the device is online and run record start again.`})}function G(e){return`no recording session can retire this marker; remove it on the device with \`adb shell rm -f ${e}\`.`}async function zn(e){let{transport:t,device:n,input:r,startedAt:i,signal:a,prepareOutput:o}=e;await wn(t,n),await o();let s;for(let e of R(void 0)){let o=t.manifestPathFor(e);await U(t,o,N(n,r,i,[],e,t.mode),a);let c,l;try{l=Date.now(),c=await pn(t,e,r,a)}catch(e){if(a.aborted)throw await Bn(t,o,e),a.reason;await Un(t,o,e),s=e;continue}try{await U(t,o,N(n,r,i,[c],void 0,t.mode),a)}catch(e){throw await Vn(t,o,c),e}return{chunk:c,manifestPath:o,startedAtMs:l}}throw s??Error(`Android screenrecord did not begin producing frames`)}async function Bn(e,t,n){n instanceof I||await W(e,t).catch(()=>{})}async function Vn(e,t,n){try{await V(e,[n])}catch{return}await W(e,t).catch(()=>{})}async function Hn(e){let{transport:t,device:n,input:r,startedAt:i,chunks:a,manifestPath:o,preferredDir:s,launchAdmission:c}=e,l;for(let e of R(s)){if(c.aborted)throw new L;await U(t,o,N(n,r,i,a,e,t.mode));try{if(c.aborted)throw new L;return await pn(t,e,r)}catch(e){if(e instanceof I)throw e;try{await U(t,o,N(n,r,i,a,void 0,t.mode))}catch{throw new I(e)}l=e}}throw l??Error(`failed to start next Android recording chunk`)}async function Un(e,t,n){if(n instanceof I)throw n;try{await W(e,t)}catch{throw new I(n)}}function Wn(e,t){return Object.freeze({backend:`adb screenrecord`,outPath:e.outputPath,...e.clientOutputPath?{clientOutPath:e.clientOutputPath}:{},startedAt:t,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp?{activeSessionApp:e.activeSessionApp}:{},...e.exportQuality?{exportQuality:e.exportQuality}:{},...e.fps===void 0?{}:{fps:e.fps},gestureEvents:[]})}function Gn(e){let t=Kn(e.chunkPaths);if(t===void 0)return{};let n=e.stoppedAtMs-e.startedAtMs;return n-t<2e3?{capturedDurationMs:t}:{capturedDurationMs:t,idleTailWarning:`Android screenrecord encodes a frame only when the screen changes, so this video ends at the last frame it encoded: it covers ${qn(t)}s of the ${qn(n)}s recording window.`}}function Kn(e){let t=0;for(let n of e){let e=b(n);if(e===void 0)return;t+=e}return t}function qn(e){return(e/1e3).toFixed(1)}async function Jn(e){let{host:t,transport:n,evidence:r,recording:i,startedAtMs:a,progress:o}=e,s=e.reachedLimit===!0;return await $n(e,await qe({snapshot:i,progress:o,steps:{stop:async()=>(s=await z(n,r.chunks)&&e.activeRecorderRetired!==!0||s,await hn(n,r.chunks),{observation:{recorder:`confirmed`},...s?{warning:`Android adb screenrecord stopped before record stop, likely after reaching the 180s platform limit. The MP4 may be truncated; final interactions after the limit are not in the video.`}:{}}),collect:e=>gn(n,r.chunks,e),finalize:({collectedPath:e,exportPath:n,stoppedAtMs:o})=>Yn({host:t,evidence:r,recording:i,startedAtMs:a,stoppedAtMs:o,collectedPath:e,exportPath:n}),discard:e=>Zn(t,e,r.chunks.length)}}))}async function Yn(e){let{host:t,evidence:n,recording:r,collectedPath:i,exportPath:a}=e,o=er({collectedPath:i,exportPath:a,exportClientPath:r.clientOutPath,count:n.chunks.length}),s=o.length>1,c;try{await Xn(t,o),c=await t.screenRecording.finalize.complete({outputPath:a,showTouches:!s&&r.showTouches,gestureEvents:r.gestureEvents,exportQuality:r.exportQuality??`medium`,...r.fps===void 0?{}:{fps:r.fps},targetLabel:`Android recording`})}catch(e){for(let{served:e}of o)await t.screenRecording.outputs.remove(e.path);throw e}let l=Gn({chunkPaths:o.map(({collected:e})=>e.path),startedAtMs:e.startedAtMs,stoppedAtMs:e.stoppedAtMs});return Qn({finalization:c,captured:l,recording:r,chunked:s,files:o})}async function Xn(e,t){for(let{collected:n,served:r}of t)await e.screenRecording.outputs.copy({from:n.path,to:r.path})}async function Zn(e,t,n){for(let r=1;r<=n;r+=1)await e.screenRecording.outputs.remove(A(t,r))}function Qn(e){let{finalization:t,captured:n,recording:r,chunked:i,files:a}=e,o=[t.warning,...i?[`Android adb screenrecord is capped at 180s, so this recording was split into multiple MP4 chunks.`]:[],n.idleTailWarning].filter(e=>e!==void 0&&e.length>0);return{...t.telemetryPath===void 0?{}:{telemetryPath:t.telemetryPath},...o.length===0?{}:{warning:o.join(` `)},...i&&r.showTouches&&r.gestureEvents.length>0?{overlayWarning:`touch overlay burn-in is skipped for chunked Android recordings; returning raw chunks plus gesture telemetry`}:{},...n.capturedDurationMs===void 0?{}:{capturedDurationMs:n.capturedDurationMs},...i?{chunks:a.map(e=>e.served)}:{},nativePathDisposition:`retirable`}}async function $n(e,t){let{transport:n,evidence:r,manifestPath:i}=e;return await U(n,i,sn(r,t.result)),await B(n,r.chunks),{status:`completed`,result:{...t.result,nativePathDisposition:await _n(n,r.chunks)}}}function er(e){return Object.freeze(Array.from({length:e.count},(t,n)=>({collected:Object.freeze({index:n+1,path:A(e.collectedPath,n+1)}),served:Object.freeze({index:n+1,path:A(e.exportPath,n+1),...e.exportClientPath===void 0?{}:{clientOutPath:A(e.exportClientPath,n+1)}})})))}async function tr(e,t,n){try{let r=t.pendingRemotePath,i=await nr(e,t.chunks);if(await z(e,[...i.stoppable,...await ir(e,t)]),await rr(e,i.retired),await B(e,t.chunks),r!==void 0&&!await e.remove(r))throw Error(`failed to remove Android recording artifact: ${r}`);return await W(e,n),{status:`cleaned`}}catch(e){return sr(e)}}async function nr(e,t){let n=[],r=[];for(let i of t){let[t]=await Cn(e,[i]).catch(()=>[]),a=t?.state;a===`ownership-lost`||a===`foreign-writer`?r.push(i):n.push(i)}return{stoppable:n,retired:r}}async function rr(e,t){let n;for(let r of t)try{await ar(e,r)}catch(e){n??=e instanceof Error?e:Error(String(e))}if(n)throw n}async function ir(e,t){let n=t.pendingRemotePath;if(n===void 0)return[];let r=await e.probeRunningWriters(n);if(!r.conclusive)throw or(n);return r.writers.map((e,r)=>({index:t.chunks.length+1+r,remotePath:n,remotePid:e.pid,remoteStartTime:e.startTime}))}async function ar(e,t){let n=await e.probeRunningWriters(t.remotePath);if(!n.conclusive)throw or(t.remotePath);let r=n.writers.at(0);if(r)throw Error(`Android artifact is still written by pid ${r.pid}: ${t.remotePath}`)}function or(e){return Error(`cannot list every recorder writing Android artifact: ${e}`)}function sr(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:String(e)}}async function cr(e){let{transport:t,device:n,envelope:r,descriptor:i}=e;if(i.transportMode!==t.mode)return{status:`transport-unavailable`};let a=await t.readManifest(i.manifestPath);if(a.status===`unavailable`)return{status:`transport-unavailable`};let o=a.status===`read`?P(a.contents):void 0;return o&&cn(o,n,r)&&ln(o,i)?{status:`matched`,evidence:o}:{status:`ownership-lost`}}async function lr(e){let t=await e.transport.readManifest(e.manifestPath);if(t.status!==`read`)return;let n=P(t.contents);return n&&ur(n,e)?n:void 0}function ur(e,t){return e.deviceId===t.deviceId&&e.sessionId===t.sessionId&&e.fenceToken===t.fence.token&&e.fenceGeneration===t.fence.generation}async function dr(e){let{host:t,transport:n,device:r,input:i}=e,a=M.decode(i.envelope.descriptor.body);if(a.status!==`decoded`)return K(`descriptor-invalid`);let o=await cr({transport:n,device:r,envelope:i.envelope,descriptor:a.descriptor});return o.status===`matched`?await pr({host:t,transport:n,device:r,input:i,descriptor:a.descriptor,evidence:o.evidence}):K(o.status===`transport-unavailable`?`transport-not-reattachable`:`ownership-fence-lost`)}async function fr(e){let t=M.decode(e.input.envelope.descriptor.body);if(t.status!==`decoded`)return{status:`cleanup-pending`,reason:`manual-recovery-required`};let n=await cr({transport:e.transport,device:e.device,envelope:e.input.envelope,descriptor:t.descriptor});return n.status===`matched`?await tr(e.transport,n.evidence,t.descriptor.manifestPath):n.status===`transport-unavailable`?{status:`cleanup-pending`,reason:`owner-unavailable`}:{status:`cleanup-pending`,reason:`ownership-fence-lost`}}async function pr(e){let{host:t,transport:n,device:r,input:i,descriptor:a,evidence:o}=e;if(o.completion!==void 0){let e=await mr(n,o);return e.status===`terminal`?{status:`completed`,result:{...o.completion,nativePathDisposition:e.nativePathDisposition}}:K(`ownership-fence-lost`,`Android recording completed evidence still names a live or unverifiable recorder.`)}if(o.pendingRemotePath!==void 0)return K(`transport-not-reattachable`,`Android recording launch was interrupted before its process identity was committed.`);let s=o.chunks.at(-1);if(!s)return{status:`missing`};let c=await n.inspect({pid:s.remotePid,remotePath:s.remotePath,startTime:s.remoteStartTime});if(c!==`owned-alive`&&await n.exists(s.remotePath)===!1)return K(`transport-not-reattachable`,`Android recording process ended before its artifact could be recovered.`);let l=hr(i.envelope.sessionId,i.envelope.fence,a),u=!1;return{status:`active`,handle:Ue(Wn(l,o.startedAt),{finish:async(e,r)=>{let i=await Jn({host:t,transport:n,evidence:o,manifestPath:a.manifestPath,recording:e,startedAtMs:o.startedAt,reachedLimit:F(c),progress:r});return u=!0,i},forceCleanup:async()=>u?{status:`cleaned`}:await fr({transport:n,device:r,input:i})})}}async function mr(e,t){try{for(let n of t.chunks)if(!F(await e.inspect({pid:n.remotePid,remotePath:n.remotePath,startTime:n.remoteStartTime})))return{status:`retained`};return{status:`terminal`,nativePathDisposition:await _n(e,t.chunks)}}catch{return{status:`retained`}}}function hr(e,t,n){return{sessionId:e,outputPath:n.outputPath,...n.clientOutputPath===void 0?{}:{clientOutputPath:n.clientOutputPath},scope:n.scope,showTouches:n.showTouches,hideTouchesRequested:!1,recordOnlySession:n.recordOnlySession,...n.activeSessionApp===void 0?{}:{activeSessionApp:n.activeSessionApp},...n.exportQuality===void 0?{}:{exportQuality:n.exportQuality},...n.fps===void 0?{}:{fps:n.fps},fence:t}}function K(e,t){return{status:`unreattachable`,reason:e,...t===void 0?{}:{message:t}}}async function gr(e){let{host:t,device:n,owner:r,signal:i}=e,a=await t.screenRecording.android.resolve(n);return Object.freeze({screenRecordingStart:async e=>await _r({host:t,transport:a,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>await dr({host:t,transport:a,device:n,input:e}),screenRecordingCleanup:async e=>await fr({transport:a,device:n,input:e})})}async function _r(e){let{host:t,transport:n,device:r,owner:i,input:o,signal:s}=e;s.throwIfAborted();let c=Date.now(),l=await zn({transport:n,device:r,input:o,startedAt:c,signal:s,prepareOutput:async()=>await t.screenRecording.outputs.prepare(o.outputPath)}),u=l.manifestPath,d=[l.chunk],f,p,m,h=`recording`,g=!1,_=new AbortController,v=()=>{f&&clearTimeout(f),_.abort(),h===`recording`&&(h=`stopping`)},y=()=>h===`recording`,ie=()=>{h=`finished`},b=()=>{y()&&(f=setTimeout(()=>{p=ce().catch(e=>{m=e})},17e4),f.unref?.())},x=(e,t)=>N(r,o,c,e,t,n.mode),S=async e=>await Hn({transport:n,device:r,input:o,startedAt:c,chunks:d,manifestPath:u,preferredDir:T.posix.dirname(e.remotePath),launchAdmission:_.signal}),ae=async e=>{try{return{chunk:await S(e),previousStopped:!1}}catch(t){if(t instanceof L)throw t;if(_.signal.aborted)throw new L;await H(n,e)||(g=!0);try{return{chunk:await S(e),previousStopped:!0}}catch(e){throw e instanceof Error?e:t}}},oe=async e=>{await V(n,[e]),await U(n,u,x(d)).catch(()=>{})},se=async(e,t,r)=>{if(await V(n,[e]).then(()=>!1,()=>!0)||r){await U(n,u,x(d,e.remotePath)).catch(()=>{});return}try{await U(n,u,x(d))}catch{await H(n,t).catch(()=>{}),await U(n,u,x(d,e.remotePath)).catch(()=>{})}},ce=async()=>{let e=d.at(-1);if(!e)throw Error(`Android recording has no active chunk`);let t,r;try{({chunk:t,previousStopped:r}=await ae(e))}catch(e){if(e instanceof L)return;throw e}if(!y()){await oe(t);return}let i=[...d,{...t,index:d.length+1}];try{await U(n,u,x(i))}catch(n){throw await se(t,e,r),n}d=i,g=!1,r||await H(n,e),b()};b();let C=Ue(Wn(o,c),{finish:async(e,r)=>{if(v(),await p,m)throw m;let i=await Jn({host:t,transport:n,evidence:x(d),manifestPath:u,recording:e,startedAtMs:l.startedAtMs,progress:r,activeRecorderRetired:g});return ie(),i},forceCleanup:async()=>{if(v(),h===`finished`)return{status:`cleaned`};try{await p}catch(e){m=e}let e=await lr({transport:n,deviceId:r.id,sessionId:o.sessionId,fence:o.fence,manifestPath:u});return e?await tr(n,e,u):{status:`cleanup-pending`,reason:`ownership-fence-lost`}}});return Object.freeze({pendingHandle:new re(C),envelope:te({resourceKind:ne,sessionId:o.sessionId,device:a(r),owner:i,fence:o.fence,lifecycle:`open`,descriptor:ee(M,{backend:`adb-screenrecord`,manifestPath:u,...on(o),transportMode:n.mode})})})}async function vr(e,t,n){try{let r=await e.snapshot({appBundleId:t,signal:n,transient:{settleBy:Date.now()+6e3}});return{observation:`androidSnapshot`in r&&r.androidSnapshot?.systemSurfaceOnly===!0?`unobservable`:`observable`}}catch(e){return n.throwIfAborted(),f(e)?{observation:`unobservable`}:{observation:`probe-failed`,failure:yr(e)}}}function yr(e){let n=t(e),r=d(n)??n.details?.reason,{code:i}=n;return typeof r==`string`?{source:`capture`,code:i,reason:r}:{source:`capture`,code:i}}function br(t){let{host:n,device:r,signal:i}=t,a=Ne({device:r,signal:i,resolveInteractor:n.localInteractors.resolve});return Object.freeze({resolveOpenTarget:async e=>await n.androidApplications.resolveOpenTarget(r,e),prepareApplicationOpen:async e=>{await C(n,r,{headless:!1,deadlineAtMs:e.execution.startupDeadlineAtMs},i)},openApplication:async e=>await xr(n,a,e),applyRuntimeHints:async e=>await n.androidApplications.applyRuntimeHints(r,e),clearRuntimeHints:async e=>await n.androidApplications.clearRuntimeHints(r,e),closeApplication:async t=>{if(t.ensureReady&&await C(n,r,{headless:!1},i),t.mode===`kill`){let[n]=t.positionals;if(!n)throw new e(`INVALID_ARGS`,`Kill requires an app target`);let{killAndroidApp:i}=await import(`./app-lifecycle.js`).then(e=>e.n);await i(r,n);return}await Pe({device:r,interactor:await a.resolveInteractor(t.execution,t.appBundleId),positionals:t.positionals})},finalizeApplicationClose:async e=>{await n.androidApplications.restoreTestIme(r,{stateDir:e.stateDir,shutdownTarget:e.shutdownTarget===!0&&r.kind===`emulator`,signal:i});let t=e.shutdownTarget&&r.kind===`emulator`?await n.deviceShutdown.android.shutdownTarget(r,i):void 0;return t===void 0?{}:{shutdown:t}},prepareAppleRunner:Cr,configureProviderPortReverse:Cr})}async function xr(t,n,r){let i={},a=r.relaunch&&!!r.target,o=a?r.appBundleId:void 0;if(o){let e=Date.now();await Pe({device:n.device,interactor:await n.resolveInteractor(r.execution,o),positionals:[o]}),i.relaunchCloseDurationMs=q(e)}if(v(r.runtimeHints)){if(!r.applyRuntimeHints)throw new e(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});let t=Date.now();await r.applyRuntimeHints({appId:r.appBundleId,values:r.runtimeHints}),i.runtimeHintsDurationMs=q(t)}let s=Date.now(),c=await Fe({device:n.device,interactor:await n.resolveInteractor(r.execution,r.appBundleId),positionals:r.positionals,appBundleId:r.appBundleId,execution:r.execution,terminateRunningApp:a&&!o});i.openDispatchDurationMs=q(s),r.enableTestIme&&await t.androidApplications.activateTestIme(n.device,{stateDir:r.stateDir});let l=Me(r);if(l){let e=Date.now();await Fe({device:n.device,interactor:await n.resolveInteractor({...r.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0},r.appBundleId),positionals:[l],appBundleId:r.appBundleId,execution:{...r.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0}}),i.launchUrlDurationMs=q(e)}else i.launchUrlDurationMs=0;let u=await t.androidApplications.inferOpenedAppBundleId(n.device,r.target,r.appBundleId,c?.launchedAppBundleId);u&&await t.androidApplications.resetFramePerfStats(n.device,u);let d=Date.now();return Object.assign(i,await Sr(n,r,u)),i.postOpenSettleDurationMs=q(d),{appBundleId:u,timing:i}}async function Sr(e,t,r){if(!t.target||n(t.target))return{};if(!r)return{postOpenObservation:`app-unidentified`};let i=await vr(await e.resolveInteractor(t.execution,r),r,e.signal);return i.observation===`probe-failed`?{postOpenObservation:`probe-failed`,postOpenObservationFailure:i.failure}:{postOpenObservation:i.observation}}function q(e){return Math.max(0,Date.now()-e)}async function Cr(){throw new e(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Android.`)}const J=c(`android`),Y=Object.freeze({available:!0}),wr=o(`unsupported-device-kind`),Tr=o(`unsupported-platform-leaf`,"Run `agent-device settings --help` for the settings each target serves."),Er=o(`unsupported-device-kind`,`focus is supported on Android emulators and physical devices.`),Dr=o(`unsupported-device-kind`,`keyboard actions are supported on Android emulators and physical devices.`),Or=o(`unsupported-platform-leaf`),kr=o(`unsupported-platform-leaf`,`Android has no key event for this system button.`),Ar=o(`unsupported-device-kind`,`Headless boot is supported only for Android emulators.`),jr=o(`unsupported-device-kind`,`Android appstate is supported only for Android emulators and devices.`),Mr=o(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),Nr=o(`unsupported-device-kind`,`open is supported only for Android emulators and devices.`),Pr=o(`unsupported-device-kind`,`close is supported only for Android emulators and devices.`),Fr=o(`unsupported-device-kind`,`Runtime hints are supported only for Android emulators and devices.`),Ir=o(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),Lr=o(`unsupported-device-kind`,`shutdown is supported only for Apple simulators and Android emulators.`),Rr=o(`unsupported-device-kind`,`screenshot is supported only for Android emulators and devices.`),X=o(`unsupported-device-kind`,`snapshot is supported only for Android emulators and devices.`),zr=o(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),Br=o(`unsupported-platform-leaf`,`viewport resizes web targets only (--platform web).`),Vr=o(`unsupported-platform-leaf`,`the stateless audio page probe is a web-session operation; Android targets use the host capture.`);function Hr(e){let t=Ur(e),n=Wr(e),r=Gr(e);return y({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:r,clearRuntimeHints:r,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Mr,configureProviderPortReverse:Ir})}function Ur(e){return e.kind===`emulator`||e.kind===`device`?Y:Nr}function Wr(e){return e.kind===`emulator`||e.kind===`device`?Y:Pr}function Gr(e){return e.kind===`emulator`||e.kind===`device`?Y:Fr}const Z=o(`unsupported-device-kind`,`Gestures are supported on Android emulators and physical devices.`),Kr=o(`unsupported-platform-leaf`,S),qr=o(`unsupported-platform-leaf`,x);function Jr(e,t){return e.kind===`simulator`?Z:e.target===`tv`?t:Y}function Q(e){return e.kind===`simulator`?Z:Y}function $(e){return e.kind===`simulator`?Er:Y}const Yr=o(`owner-capability-missing`,oe),Xr=o(`owner-capability-missing`,`Could not determine whether this Android build supports a shell clipboard: the adb probe did not complete. Retry once the device is reachable.`);async function Zr(e,t){let n=e.androidTools?.probeClipboardShellSupport;return n?await n.call(e.androidTools,t):`probe-failed`}const Qr=o(`unsupported-device-kind`,`tv-remote is supported only on Android TV targets.`);function $r(e){return e.kind!==`simulator`&&e.target===`tv`?Y:Qr}function ei(e){let t=Ct(e),n=new Map,r=async t=>{if(t.kind===`simulator`)return Yr;let r=n.get(t.id)??await Zr(e,t);return r!==`probe-failed`&&n.set(t.id,r),r===`supported`?Y:r===`unsupported`?Yr:Xr},i=async e=>{let n=await t.inspectFacts(e),i=se(e),a=await r(e);return Object.freeze({device:n.device,operations:{...n.operations,...i,appState:e.kind===`simulator`?jr:Y,networkDump:Y,screenRecordingStart:Y,screenRecordingReattach:Y,screenRecordingCleanup:Y,...be({capture:e.kind===`simulator`?X:Y,customActions:zr,withoutActiveApp:e.kind===`simulator`?X:Y}),...ke({capture:e.kind===`simulator`?Rr:Y}),...pe({findText:X,querySelector:X}),...je({setViewport:Br}),...ge({focus:$(e)}),...he({unsupported:Z,plan:Q(e),directionalFling:Q(e),multiTouch:Jr(e,Kr),targetAuthoredDrag:Jr(e,qr),viewport:Q(e)}),...fe({scroll:Q(e)}),...de({type:$(e)}),...ie({unsupported:Er,tap:$(e),longPress:$(e),hover:Or,fill:$(e)}),..._e({readTextAtPoint:e.kind===`simulator`?wr:Y}),...ue({back:$(e)}),...ve({unsupported:kr,home:$(e),appSwitcher:$(e),...ye(e)}),...lt(e),..._t(e),...Te({triggerAppEvent:$(e)}),...Ie({target:$(e),unsupported:Tr,write:{wifi:Y,bluetooth:Y,airplane:Y,"mobile-data":Y,location:Y,animations:Y,appearance:Y,"text-size":Y,fingerprint:Y,"clear-app-state":Y,permission:Y},read:{"text-size":Y}}),...Ee({read:$(e),wait:$(e),accept:$(e),dismiss:$(e)}),...Se({orientation:$(e),unlock:$(e)}),...we({tvRemote:$r(e)}),...xe({unsupported:Dr,status:$(e),dismiss:$(e),enter:$(e)}),...Ce({unsupported:a.available?Yr:a,read:a,write:a}),...De({capture:yt(e),query:Vr}),...Oe({frames:$(e),memorySample:$(e),memorySnapshot:$(e),nativeCapture:$(e),profileReport:$(e)}),ensureReady:Y,bootTarget:Y,bootTargetHeadless:e.kind===`emulator`?Y:Ar,listApps:Y,...Hr(e),shutdownTarget:e.kind===`emulator`?Y:Lr}})};return Object.freeze({owner:J,ownsDevice:e=>e.platform===`android`,inspectFacts:i,bind:async n=>{let r=await t.bind(n),a=await i(n.device),o=await gr({host:e,device:n.device,owner:J,signal:n.scope.signal});return Object.freeze({device:r.device,owner:J,facts:a,operations:Object.freeze({...r.operations,...ce({host:e,device:n.device,signal:n.scope.signal}),...a.operations.appState.available?{appState:async()=>{n.scope.signal.throwIfAborted();let{runAndroidAdb:e}=await import(`./adb.js`).then(e=>e.t);return await ae(async(t,r)=>await e(n.device,t,{...r,signal:n.scope.signal}),n.scope.signal)}}:{},networkDump:async t=>await Et(e,n.device,t,n.scope.signal),...o,...s(a.operations.audioProbeStart,()=>Be({host:e.audioProbe.hostCapture,device:n.device,owner:J})),...s(a.operations.perfFrames,()=>le({resolveHost:()=>e.perf.android,device:n.device,owner:J})),...ti(e,n,a),...ut({device:n.device,signal:n.scope.signal}),...vt({device:n.device,signal:n.scope.signal}),ensureReady:async t=>await C(e,n.device,{...t,headless:!1},n.scope.signal),bootTarget:async t=>await C(e,n.device,{...t,headless:!1},n.scope.signal),...a.operations.bootTargetHeadless.available?{bootTargetHeadless:async t=>await C(e,n.device,{...t,headless:!0},n.scope.signal)}:{},listApps:async e=>{n.scope.signal.throwIfAborted();let{listAndroidApps:t}=await import(`./app-lifecycle.js`).then(e=>e.n);return(await t(e.device,e.filter)).map(e=>({id:e.package,name:e.name}))},..._(br({host:e,device:n.device,signal:n.scope.signal}),a.operations),...a.operations.shutdownTarget.available?{shutdownTarget:async()=>await e.deviceShutdown.android.shutdownTarget(n.device,n.scope.signal)}:{}}),[Symbol.asyncDispose]:async()=>await r[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}function ti(e,t,n){let r={device:t.device,signal:t.scope.signal,resolveInteractor:e.localInteractors.resolve};return{...n.operations.captureSnapshot.available?me(r):{},...Le({...r,facts:n.operations,captureCapabilities:Ae(`an Android device captures through adb`),pause:async n=>await e.clock.sleep(n,t.scope.signal)})}}export{ei as createAndroidPlatformRuntime};
|
|
5
|
+
`))if(n.includes(t))for(let e of a){let t=e.exec(n)?.[1];t&&/^\d+$/.test(t)&&r.add(t)}return Object.freeze([...r])}function A(e,t){if(t===1)return e;let n=T.parse(e);return T.join(n.dir,`${n.name}.part-${String(t).padStart(3,`0`)}${n.ext||`.mp4`}`)}const Nt=/^(?:\/sdcard|\/data\/local\/tmp)\/agent-device-recording-\d{1,20}\.mp4$/,Pt=/^(?:\/sdcard|\/data\/local\/tmp)\/agent-device-recording-active\.json$/;function Ft(e){return Rt(e)&&zt(e)&&Bt(e)}function It(e){if(!j(e))return!1;let t=e;return Vt(t)&&Ht(t)&&Ut(t)&&Wt(t)&&(t.completion===void 0||Zt(t))}function Lt(e,t){return Qt(e,t)&&$t(e,t.outputPath,t.clientOutputPath)}function Rt(e){return e.backend===`adb-screenrecord`&&typeof e.manifestPath==`string`&&Pt.test(e.manifestPath)&&typeof e.outputPath==`string`}function zt(e){return tn(e.clientOutputPath)&&w(e)}function Bt(e){return en(e.transportMode)}function Vt(e){return e.version===1&&e.resourceKind===`screen-recording`&&typeof e.fenceToken==`string`&&Number.isInteger(e.fenceGeneration)&&typeof e.sessionId==`string`&&typeof e.deviceId==`string`&&Number.isFinite(e.startedAt)}function Ht(e){return typeof e.outputPath==`string`&&tn(e.clientOutputPath)&&w(e)}function Ut(e){return en(e.transportMode)&&(e.pendingRemotePath===void 0||nn(e.pendingRemotePath))}function Wt(e){return Array.isArray(e.chunks)&&e.chunks.every(Gt)&&(e.chunks.length>0||e.pendingRemotePath!==void 0)&&(e.completion===void 0||Kt(e.completion))}function Gt(e,t){if(!j(e))return!1;let n=e;return n.index===t+1&&nn(n.remotePath)&&rn(n.remotePid)&&rn(n.remoteStartTime)}function Kt(e){if(!j(e))return!1;let t=e;return Jt(t)&&Yt(t)&&qt(t)&&(t.chunks===void 0||t.chunks.every(Xt))}function qt(e){return(e.stopObservation===void 0||u(e.stopObservation))&&(e.nativePathDisposition===void 0||l(e.nativePathDisposition))}function Jt(e){return typeof e.backend==`string`&&typeof e.outPath==`string`&&(e.clientOutPath===void 0||typeof e.clientOutPath==`string`)&&Number.isFinite(e.startedAt)&&Number.isFinite(e.completedAt)&&(e.capturedDurationMs===void 0||Number.isFinite(e.capturedDurationMs))}function Yt(e){return w(e)}function Xt(e,t){return e.index===t+1&&typeof e.path==`string`&&(e.clientOutPath===void 0||typeof e.clientOutPath==`string`)}function Zt(e){let t=e.completion;return t!==void 0&&Qt(t,e)&&t.startedAt===e.startedAt&&$t(t,e.outputPath,e.clientOutputPath,e.chunks.length)}function Qt(e,t){return e.backend===`adb screenrecord`&&e.outPath===t.outputPath&&e.clientOutPath===t.clientOutputPath&&e.scope===t.scope&&e.showTouches===t.showTouches&&e.recordOnlySession===t.recordOnlySession&&an(e.activeSessionApp,t.activeSessionApp)}function $t(e,t,n,r=e.chunks===void 0?1:e.chunks.length){return r===1?e.chunks===void 0:e.chunks?.length===r&&e.chunks.every((e,r)=>e.path===A(t,r+1)&&e.clientOutPath===(n===void 0?void 0:A(n,r+1)))}function j(e){return typeof e==`object`&&!!e}function en(e){return e===`local`||e===`transport-composed`}function tn(e){return e===void 0||typeof e==`string`}function nn(e){return typeof e==`string`&&Nt.test(e)}function rn(e){return typeof e==`string`&&/^\d+$/.test(e)}function an(e,t){return JSON.stringify(e)===JSON.stringify(t)}const M=Object.freeze({resourceKind:ne,version:1,encode:e=>({...e}),decode:e=>Ft(e)?{status:`decoded`,descriptor:Object.freeze({backend:`adb-screenrecord`,manifestPath:e.manifestPath,outputPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutputPath:e.clientOutputPath},scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,transportMode:e.transportMode,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},...e.fps===void 0?{}:{fps:e.fps}})}:{status:`invalid`,message:`Invalid Android screen-recording descriptor`}});function on(e){return{outputPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutputPath:e.clientOutputPath},scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},...e.fps===void 0?{}:{fps:e.fps}}}function N(e,t,n,r,i,a=`local`){return Object.freeze({version:1,resourceKind:`screen-recording`,fenceToken:t.fence.token,fenceGeneration:t.fence.generation,sessionId:t.sessionId,deviceId:e.id,startedAt:n,...on(t),chunks:r,...i===void 0?{}:{pendingRemotePath:i},transportMode:a})}function sn(e,t){return Object.freeze({...e,completion:t})}function P(e){try{let t=e&&JSON.parse(e);return It(t)?t:void 0}catch{return}}function cn(e,t,n){return e.deviceId===t.id&&e.deviceId===n.device.id&&e.fenceToken===n.fence.token&&e.fenceGeneration===n.fence.generation&&e.sessionId===n.sessionId}function ln(e,t){return e.outputPath===t.outputPath&&e.clientOutputPath===t.clientOutputPath&&e.scope===t.scope&&e.showTouches===t.showTouches&&e.recordOnlySession===t.recordOnlySession&&JSON.stringify(e.activeSessionApp)===JSON.stringify(t.activeSessionApp)&&e.exportQuality===t.exportQuality&&e.fps===t.fps&&e.transportMode===t.transportMode&&(e.completion===void 0||Lt(e.completion,t))}function F(e){switch(e){case`missing`:case`ownership-lost`:case`foreign-writer`:return!0;case`owned-alive`:case`uncertain`:return!1}}function un(e){switch(e){case`missing`:case`ownership-lost`:return!0;case`foreign-writer`:case`owned-alive`:case`uncertain`:return!1}}const dn=1e4,fn=1e3;var I=class extends Error{constructor(e){super(`Android screenrecord launch rollback could not be confirmed`,{cause:e})}},L=class extends Error{constructor(){super(`Android screenrecord rotation refused: the recording stop was already claimed`)}};function R(e,t=Date.now()){return[...new Set(e?[e,`/sdcard`,`/data/local/tmp`]:[`/sdcard`,`/data/local/tmp`])].map(e=>`${e}/agent-device-recording-${t}.mp4`)}async function pn(e,t,n,r){let i;try{if(i=(await e.start({remotePath:t,quality:n.exportQuality??`medium`},r)).process,!/^\d+$/.test(i.pid)||!/^\d+$/.test(i.startTime)||i.remotePath!==t)throw Error(`Android screenrecord returned an invalid process identity`);if(!await vn(e,t,i,r))throw Error(`Android screenrecord did not begin producing frames`);return{index:1,remotePath:t,remotePid:i.pid,remoteStartTime:i.startTime}}catch(t){throw i&&mn(i)&&!await yn(e,i)?new I(t):r?.aborted?r.reason:t}}function mn(e){return/^\d+$/.test(e.pid)&&/^\d+$/.test(e.startTime)&&e.remotePath.length>0}async function z(e,t){let n=t.at(-1),r=!1,i;for(let a of[...t].reverse())try{let t=await H(e,a);a===n&&(r=t)}catch(e){i??=e}if(i)throw i;return r}async function hn(e,t){for(let n of t){let t;for(let r=0;r<3;r+=1){let i=await e.size(n.remotePath);if(typeof i==`number`&&i>0&&i===t)break;if(t=typeof i==`number`&&i>0?i:void 0,r===2)throw Error(`Android recording artifact is not stable: ${n.remotePath}`);await new Promise(e=>setTimeout(e,250))}}}async function gn(e,t,n){for(let[r,i]of t.entries())await bn(e,i.remotePath,A(n,r+1))}async function B(e,t){let n;for(let r of t)try{if(!await e.remove(r.remotePath))throw Error(`failed to remove Android recording artifact: ${r.remotePath}`)}catch(e){n??=e}if(n)throw n}async function _n(e,t){for(let n of t)if(await e.exists(n.remotePath)!==!1)return`retirable`;return`retired`}async function V(e,t){try{await z(e,t)}finally{await B(e,t)}}async function vn(e,t,n,r){for(let i=0;i<3;i+=1){r?.throwIfAborted();let a=await e.size(t,r);if(typeof a==`number`&&a>0)return!0;if(await e.inspect(n,r)!==`owned-alive`)return!1;i<2&&await new Promise(e=>setTimeout(e,250))}return!0}async function yn(e,t){try{let n=await e.stop(t,{force:!0});return(n===`stopped`||n===`already-missing`)&&await e.remove(t.remotePath)}catch{return!1}}async function H(e,t){if(!t)return!1;let n={pid:t.remotePid,remotePath:t.remotePath,startTime:t.remoteStartTime},r=await e.stop(n);if(r===`already-missing`)return!0;if(r===`ownership-lost`)throw Error(`Android screenrecord ownership could not be confirmed for pid ${t.remotePid}`);if(await xn(e,n))return!1;let i=await e.stop(n,{force:!0});if(i===`stopped`||i===`already-missing`)return!1;throw Error(`failed to stop Android screenrecord pid ${t.remotePid}`)}async function bn(e,t,n){for(let r=0;r<3;r+=1){let i=await e.pullPlayable({remotePath:t,outputPath:n});if(i.exitCode===0&&i.playable)return;r+1<3&&await Sn(1e3)}throw Error(`failed to retrieve playable Android recording`)}async function xn(e,t){for(let n=0;n<=dn;n+=fn){let r=await e.inspect(t);if(r===`missing`)return!0;if(F(r))throw Error(`Android screenrecord ownership could not be confirmed for pid ${t.pid}`);n<dn&&await Sn(fn)}return!1}function Sn(e){return new Promise(t=>setTimeout(t,e))}async function U(e,t,n,r){await e.writeManifest({manifestPath:t,contents:JSON.stringify(n)},r)}async function W(e,t){if(!await e.removeManifest(t))throw Error(`failed to remove Android recording manifest: ${t}`)}async function Cn(e,t){return await Promise.all(t.map(async t=>({chunk:t,state:await e.inspect({pid:t.remotePid,remotePath:t.remotePath,startTime:t.remoteStartTime})})))}async function wn(e,t){let n=(await Tn(e)).flatMap(n=>En(n,t,e.mode));for(let t of n)await On(e,t.evidence,t.manifestPath)}async function Tn(e){return await Promise.all(R(void 0).map(async t=>{let n=e.manifestPathFor(t);return{manifestPath:n,read:await e.readManifest(n)}}))}function En(e,t,n){if(e.read.status===`missing`)return[];if(e.read.status!==`read`)throw jn(e.manifestPath,e.read.message);let r=P(e.read.contents);if(r===void 0)throw Mn(e.manifestPath);if(r.transportMode!==n)throw Nn(e.manifestPath,r,n);if(!Dn(r,t))throw Pn(e.manifestPath,r,t);return[{manifestPath:e.manifestPath,evidence:r}]}function Dn(e,t){return e.completion!==void 0||e.deviceId!==t.id}async function On(e,t,n){if(await kn(e,t),await B(e,t.chunks),await An(e,t),await W(e,n),(await e.readManifest(n)).status!==`missing`)throw Ln(n)}async function kn(e,t){for(let{chunk:n,state:r}of await Cn(e,t.chunks))if(!un(r))throw r===`uncertain`?Rn(n.remotePath):Fn(n.remotePath,r===`owned-alive`?`named-recorder`:`other-recorder`);let n=t.pendingRemotePath;if(n===void 0)return;let r=await e.probeRunningWriters(n);if(r.writers.length>0)throw Fn(n,`other-recorder`);if(!r.conclusive)throw Rn(n)}async function An(e,t){let n=t.pendingRemotePath;if(n!==void 0&&!await e.remove(n))throw In(n)}function jn(e,t){return new r(`COMMAND_FAILED`,`Android screenrecord native recovery evidence is unavailable: ${e}`,{reason:`native_recovery_evidence_unavailable`,manifestPath:e,hint:`Confirm the device is online and its storage readable, then run record start again.`},Error(t))}function Mn(e){return new r(`COMMAND_FAILED`,`Android screenrecord native recovery evidence is unreadable: ${e}`,{reason:`native_recovery_evidence_unreadable`,manifestPath:e,hint:G(e)})}function Nn(e,t,n){return new r(`COMMAND_FAILED`,`Android screenrecord native recovery evidence was written by the ${t.transportMode} transport, not this ${n} one: ${e}`,{reason:`native_recovery_evidence_transport_mismatch`,manifestPath:e,evidenceTransportMode:t.transportMode,hint:G(e)})}function Pn(e,t,n){return new r(`DEVICE_IN_USE`,`Android screenrecord native recovery evidence already exists: ${e} (open recording of session "${t.sessionId}" on ${n.id})`,{reason:`native_recovery_evidence_open`,manifestPath:e,sessionId:t.sessionId,retriable:!1,hint:`Run record stop --session ${t.sessionId} to retire it, or close that session. If it is already closed, ${G(e)}`})}function Fn(e,t){let n=t===`named-recorder`;return new r(`DEVICE_IN_USE`,`Android screenrecord recovery evidence is retained: ${n?`its recorder`:`another recorder`} is writing ${e}`,{reason:`native_recording_artifact_claimed`,remotePath:e,writer:t,...n?{retriable:!1}:{},hint:n?`Run record stop for the session that owns that recording before starting another.`:`Android ends any recorder after 180 seconds. Run record start again once that recorder has stopped.`})}function In(e){return new r(`COMMAND_FAILED`,`Android screenrecord recovery evidence could not remove ${e}`,{reason:`native_recording_artifact_removal_failed`,remotePath:e,hint:`Confirm the device is online and run record start again.`})}function Ln(e){return new r(`COMMAND_FAILED`,`Android screenrecord recovery evidence removal could not be confirmed: ${e}`,{reason:`native_recovery_evidence_retirement_unconfirmed`,manifestPath:e,hint:`Run record start again; the marker is retired from the beginning.`})}function Rn(e){return new r(`COMMAND_FAILED`,`Android screenrecord recovery evidence cannot be safely retired: ${e}`,{reason:`native_recording_recorder_unproven`,remotePath:e,hint:`Confirm the device is online and run record start again.`})}function G(e){return`no recording session can retire this marker; remove it on the device with \`adb shell rm -f ${e}\`.`}async function zn(e){let{transport:t,device:n,input:r,startedAt:i,signal:a,prepareOutput:o}=e;await wn(t,n),await o();let s;for(let e of R(void 0)){let o=t.manifestPathFor(e);await U(t,o,N(n,r,i,[],e,t.mode),a);let c,l;try{l=Date.now(),c=await pn(t,e,r,a)}catch(e){if(a.aborted)throw await Bn(t,o,e),a.reason;await Un(t,o,e),s=e;continue}try{await U(t,o,N(n,r,i,[c],void 0,t.mode),a)}catch(e){throw await Vn(t,o,c),e}return{chunk:c,manifestPath:o,startedAtMs:l}}throw s??Error(`Android screenrecord did not begin producing frames`)}async function Bn(e,t,n){n instanceof I||await W(e,t).catch(()=>{})}async function Vn(e,t,n){try{await V(e,[n])}catch{return}await W(e,t).catch(()=>{})}async function Hn(e){let{transport:t,device:n,input:r,startedAt:i,chunks:a,manifestPath:o,preferredDir:s,launchAdmission:c}=e,l;for(let e of R(s)){if(c.aborted)throw new L;await U(t,o,N(n,r,i,a,e,t.mode));try{if(c.aborted)throw new L;return await pn(t,e,r)}catch(e){if(e instanceof I)throw e;try{await U(t,o,N(n,r,i,a,void 0,t.mode))}catch{throw new I(e)}l=e}}throw l??Error(`failed to start next Android recording chunk`)}async function Un(e,t,n){if(n instanceof I)throw n;try{await W(e,t)}catch{throw new I(n)}}function Wn(e,t){return Object.freeze({backend:`adb screenrecord`,outPath:e.outputPath,...e.clientOutputPath?{clientOutPath:e.clientOutputPath}:{},startedAt:t,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp?{activeSessionApp:e.activeSessionApp}:{},...e.exportQuality?{exportQuality:e.exportQuality}:{},...e.fps===void 0?{}:{fps:e.fps},gestureEvents:[]})}function Gn(e){let t=Kn(e.chunkPaths);if(t===void 0)return{};let n=e.stoppedAtMs-e.startedAtMs;return n-t<2e3?{capturedDurationMs:t}:{capturedDurationMs:t,idleTailWarning:`Android screenrecord encodes a frame only when the screen changes, so this video ends at the last frame it encoded: it covers ${qn(t)}s of the ${qn(n)}s recording window.`}}function Kn(e){let t=0;for(let n of e){let e=b(n);if(e===void 0)return;t+=e}return t}function qn(e){return(e/1e3).toFixed(1)}async function Jn(e){let{host:t,transport:n,evidence:r,recording:i,startedAtMs:a,progress:o}=e,s=e.reachedLimit===!0;return await $n(e,await qe({snapshot:i,progress:o,steps:{stop:async()=>(s=await z(n,r.chunks)&&e.activeRecorderRetired!==!0||s,await hn(n,r.chunks),{observation:{recorder:`confirmed`},...s?{warning:`Android adb screenrecord stopped before record stop, likely after reaching the 180s platform limit. The MP4 may be truncated; final interactions after the limit are not in the video.`}:{}}),collect:e=>gn(n,r.chunks,e),finalize:({collectedPath:e,exportPath:n,stoppedAtMs:o})=>Yn({host:t,evidence:r,recording:i,startedAtMs:a,stoppedAtMs:o,collectedPath:e,exportPath:n}),discard:e=>Zn(t,e,r.chunks.length)}}))}async function Yn(e){let{host:t,evidence:n,recording:r,collectedPath:i,exportPath:a}=e,o=er({collectedPath:i,exportPath:a,exportClientPath:r.clientOutPath,count:n.chunks.length}),s=o.length>1,c;try{await Xn(t,o),c=await t.screenRecording.finalize.complete({outputPath:a,showTouches:!s&&r.showTouches,gestureEvents:r.gestureEvents,exportQuality:r.exportQuality??`medium`,...r.fps===void 0?{}:{fps:r.fps},targetLabel:`Android recording`})}catch(e){for(let{served:e}of o)await t.screenRecording.outputs.remove(e.path);throw e}let l=Gn({chunkPaths:o.map(({collected:e})=>e.path),startedAtMs:e.startedAtMs,stoppedAtMs:e.stoppedAtMs});return Qn({finalization:c,captured:l,recording:r,chunked:s,files:o})}async function Xn(e,t){for(let{collected:n,served:r}of t)await e.screenRecording.outputs.copy({from:n.path,to:r.path})}async function Zn(e,t,n){for(let r=1;r<=n;r+=1)await e.screenRecording.outputs.remove(A(t,r))}function Qn(e){let{finalization:t,captured:n,recording:r,chunked:i,files:a}=e,o=[t.warning,...i?[`Android adb screenrecord is capped at 180s, so this recording was split into multiple MP4 chunks.`]:[],n.idleTailWarning].filter(e=>e!==void 0&&e.length>0);return{...t.telemetryPath===void 0?{}:{telemetryPath:t.telemetryPath},...o.length===0?{}:{warning:o.join(` `)},...i&&r.showTouches&&r.gestureEvents.length>0?{overlayWarning:`touch overlay burn-in is skipped for chunked Android recordings; returning raw chunks plus gesture telemetry`}:{},...n.capturedDurationMs===void 0?{}:{capturedDurationMs:n.capturedDurationMs},...i?{chunks:a.map(e=>e.served)}:{},nativePathDisposition:`retirable`}}async function $n(e,t){let{transport:n,evidence:r,manifestPath:i}=e;return await U(n,i,sn(r,t.result)),await B(n,r.chunks),{status:`completed`,result:{...t.result,nativePathDisposition:await _n(n,r.chunks)}}}function er(e){return Object.freeze(Array.from({length:e.count},(t,n)=>({collected:Object.freeze({index:n+1,path:A(e.collectedPath,n+1)}),served:Object.freeze({index:n+1,path:A(e.exportPath,n+1),...e.exportClientPath===void 0?{}:{clientOutPath:A(e.exportClientPath,n+1)}})})))}async function tr(e,t,n){try{let r=t.pendingRemotePath,i=await nr(e,t.chunks);if(await z(e,[...i.stoppable,...await ir(e,t)]),await rr(e,i.retired),await B(e,t.chunks),r!==void 0&&!await e.remove(r))throw Error(`failed to remove Android recording artifact: ${r}`);return await W(e,n),{status:`cleaned`}}catch(e){return sr(e)}}async function nr(e,t){let n=[],r=[];for(let i of t){let[t]=await Cn(e,[i]).catch(()=>[]),a=t?.state;a===`ownership-lost`||a===`foreign-writer`?r.push(i):n.push(i)}return{stoppable:n,retired:r}}async function rr(e,t){let n;for(let r of t)try{await ar(e,r)}catch(e){n??=e instanceof Error?e:Error(String(e))}if(n)throw n}async function ir(e,t){let n=t.pendingRemotePath;if(n===void 0)return[];let r=await e.probeRunningWriters(n);if(!r.conclusive)throw or(n);return r.writers.map((e,r)=>({index:t.chunks.length+1+r,remotePath:n,remotePid:e.pid,remoteStartTime:e.startTime}))}async function ar(e,t){let n=await e.probeRunningWriters(t.remotePath);if(!n.conclusive)throw or(t.remotePath);let r=n.writers.at(0);if(r)throw Error(`Android artifact is still written by pid ${r.pid}: ${t.remotePath}`)}function or(e){return Error(`cannot list every recorder writing Android artifact: ${e}`)}function sr(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:String(e)}}async function cr(e){let{transport:t,device:n,envelope:r,descriptor:i}=e;if(i.transportMode!==t.mode)return{status:`transport-unavailable`};let a=await t.readManifest(i.manifestPath);if(a.status===`unavailable`)return{status:`transport-unavailable`};let o=a.status===`read`?P(a.contents):void 0;return o&&cn(o,n,r)&&ln(o,i)?{status:`matched`,evidence:o}:{status:`ownership-lost`}}async function lr(e){let t=await e.transport.readManifest(e.manifestPath);if(t.status!==`read`)return;let n=P(t.contents);return n&&ur(n,e)?n:void 0}function ur(e,t){return e.deviceId===t.deviceId&&e.sessionId===t.sessionId&&e.fenceToken===t.fence.token&&e.fenceGeneration===t.fence.generation}async function dr(e){let{host:t,transport:n,device:r,input:i}=e,a=M.decode(i.envelope.descriptor.body);if(a.status!==`decoded`)return K(`descriptor-invalid`);let o=await cr({transport:n,device:r,envelope:i.envelope,descriptor:a.descriptor});return o.status===`matched`?await pr({host:t,transport:n,device:r,input:i,descriptor:a.descriptor,evidence:o.evidence}):K(o.status===`transport-unavailable`?`transport-not-reattachable`:`ownership-fence-lost`)}async function fr(e){let t=M.decode(e.input.envelope.descriptor.body);if(t.status!==`decoded`)return{status:`cleanup-pending`,reason:`manual-recovery-required`};let n=await cr({transport:e.transport,device:e.device,envelope:e.input.envelope,descriptor:t.descriptor});return n.status===`matched`?await tr(e.transport,n.evidence,t.descriptor.manifestPath):n.status===`transport-unavailable`?{status:`cleanup-pending`,reason:`owner-unavailable`}:{status:`cleanup-pending`,reason:`ownership-fence-lost`}}async function pr(e){let{host:t,transport:n,device:r,input:i,descriptor:a,evidence:o}=e;if(o.completion!==void 0){let e=await mr(n,o);return e.status===`terminal`?{status:`completed`,result:{...o.completion,nativePathDisposition:e.nativePathDisposition}}:K(`ownership-fence-lost`,`Android recording completed evidence still names a live or unverifiable recorder.`)}if(o.pendingRemotePath!==void 0)return K(`transport-not-reattachable`,`Android recording launch was interrupted before its process identity was committed.`);let s=o.chunks.at(-1);if(!s)return{status:`missing`};let c=await n.inspect({pid:s.remotePid,remotePath:s.remotePath,startTime:s.remoteStartTime});if(c!==`owned-alive`&&await n.exists(s.remotePath)===!1)return K(`transport-not-reattachable`,`Android recording process ended before its artifact could be recovered.`);let l=hr(i.envelope.sessionId,i.envelope.fence,a),u=!1;return{status:`active`,handle:Ue(Wn(l,o.startedAt),{finish:async(e,r)=>{let i=await Jn({host:t,transport:n,evidence:o,manifestPath:a.manifestPath,recording:e,startedAtMs:o.startedAt,reachedLimit:F(c),progress:r});return u=!0,i},forceCleanup:async()=>u?{status:`cleaned`}:await fr({transport:n,device:r,input:i})})}}async function mr(e,t){try{for(let n of t.chunks)if(!F(await e.inspect({pid:n.remotePid,remotePath:n.remotePath,startTime:n.remoteStartTime})))return{status:`retained`};return{status:`terminal`,nativePathDisposition:await _n(e,t.chunks)}}catch{return{status:`retained`}}}function hr(e,t,n){return{sessionId:e,outputPath:n.outputPath,...n.clientOutputPath===void 0?{}:{clientOutputPath:n.clientOutputPath},scope:n.scope,showTouches:n.showTouches,hideTouchesRequested:!1,recordOnlySession:n.recordOnlySession,...n.activeSessionApp===void 0?{}:{activeSessionApp:n.activeSessionApp},...n.exportQuality===void 0?{}:{exportQuality:n.exportQuality},...n.fps===void 0?{}:{fps:n.fps},fence:t}}function K(e,t){return{status:`unreattachable`,reason:e,...t===void 0?{}:{message:t}}}async function gr(e){let{host:t,device:n,owner:r,signal:i}=e,a=await t.screenRecording.android.resolve(n);return Object.freeze({screenRecordingStart:async e=>await _r({host:t,transport:a,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>await dr({host:t,transport:a,device:n,input:e}),screenRecordingCleanup:async e=>await fr({transport:a,device:n,input:e})})}async function _r(e){let{host:t,transport:n,device:r,owner:i,input:a,signal:o}=e;o.throwIfAborted();let s=Date.now(),l=await zn({transport:n,device:r,input:a,startedAt:s,signal:o,prepareOutput:async()=>await t.screenRecording.outputs.prepare(a.outputPath)}),u=l.manifestPath,d=[l.chunk],f,p,m,h=`recording`,g=!1,_=new AbortController,v=()=>{f&&clearTimeout(f),_.abort(),h===`recording`&&(h=`stopping`)},y=()=>h===`recording`,ie=()=>{h=`finished`},b=()=>{y()&&(f=setTimeout(()=>{p=ce().catch(e=>{m=e})},17e4),f.unref?.())},x=(e,t)=>N(r,a,s,e,t,n.mode),S=async e=>await Hn({transport:n,device:r,input:a,startedAt:s,chunks:d,manifestPath:u,preferredDir:T.posix.dirname(e.remotePath),launchAdmission:_.signal}),ae=async e=>{try{return{chunk:await S(e),previousStopped:!1}}catch(t){if(t instanceof L)throw t;if(_.signal.aborted)throw new L;await H(n,e)||(g=!0);try{return{chunk:await S(e),previousStopped:!0}}catch(e){throw e instanceof Error?e:t}}},oe=async e=>{await V(n,[e]),await U(n,u,x(d)).catch(()=>{})},se=async(e,t,r)=>{if(await V(n,[e]).then(()=>!1,()=>!0)||r){await U(n,u,x(d,e.remotePath)).catch(()=>{});return}try{await U(n,u,x(d))}catch{await H(n,t).catch(()=>{}),await U(n,u,x(d,e.remotePath)).catch(()=>{})}},ce=async()=>{let e=d.at(-1);if(!e)throw Error(`Android recording has no active chunk`);let t,r;try{({chunk:t,previousStopped:r}=await ae(e))}catch(e){if(e instanceof L)return;throw e}if(!y()){await oe(t);return}let i=[...d,{...t,index:d.length+1}];try{await U(n,u,x(i))}catch(n){throw await se(t,e,r),n}d=i,g=!1,r||await H(n,e),b()};b();let C=Ue(Wn(a,s),{finish:async(e,r)=>{if(v(),await p,m)throw m;let i=await Jn({host:t,transport:n,evidence:x(d),manifestPath:u,recording:e,startedAtMs:l.startedAtMs,progress:r,activeRecorderRetired:g});return ie(),i},forceCleanup:async()=>{if(v(),h===`finished`)return{status:`cleaned`};try{await p}catch(e){m=e}let e=await lr({transport:n,deviceId:r.id,sessionId:a.sessionId,fence:a.fence,manifestPath:u});return e?await tr(n,e,u):{status:`cleanup-pending`,reason:`ownership-fence-lost`}}});return Object.freeze({pendingHandle:new re(C),envelope:te({resourceKind:ne,sessionId:a.sessionId,device:c(r),owner:i,fence:a.fence,lifecycle:`open`,descriptor:ee(M,{backend:`adb-screenrecord`,manifestPath:u,...on(a),transportMode:n.mode})})})}async function vr(e,t,n){try{let r=await e.snapshot({appBundleId:t,signal:n,transient:{settleBy:Date.now()+6e3}});return{observation:`androidSnapshot`in r&&r.androidSnapshot?.systemSurfaceOnly===!0?`unobservable`:`observable`}}catch(e){return n.throwIfAborted(),f(e)?{observation:`unobservable`}:{observation:`probe-failed`,failure:yr(e)}}}function yr(e){let t=i(e),n=d(t)??t.details?.reason,{code:r}=t;return typeof n==`string`?{source:`capture`,code:r,reason:n}:{source:`capture`,code:r}}function br(e){let{host:t,device:n,signal:i}=e,a=Ne({device:n,signal:i,resolveInteractor:t.localInteractors.resolve});return Object.freeze({resolveOpenTarget:async e=>await t.androidApplications.resolveOpenTarget(n,e),prepareApplicationOpen:async e=>{await C(t,n,{headless:!1,deadlineAtMs:e.execution.startupDeadlineAtMs},i)},openApplication:async e=>await xr(t,a,e),applyRuntimeHints:async e=>await t.androidApplications.applyRuntimeHints(n,e),clearRuntimeHints:async e=>await t.androidApplications.clearRuntimeHints(n,e),closeApplication:async e=>{if(e.ensureReady&&await C(t,n,{headless:!1},i),e.mode===`kill`){let[t]=e.positionals;if(!t)throw new r(`INVALID_ARGS`,`Kill requires an app target`);let{killAndroidApp:i}=await import(`./app-lifecycle.js`).then(e=>e.n);await i(n,t);return}await Pe({device:n,interactor:await a.resolveInteractor(e.execution,e.appBundleId),positionals:e.positionals})},finalizeApplicationClose:async e=>{await t.androidApplications.restoreTestIme(n,{stateDir:e.stateDir,shutdownTarget:e.shutdownTarget===!0&&n.kind===`emulator`,signal:i});let r=e.shutdownTarget&&n.kind===`emulator`?await t.deviceShutdown.android.shutdownTarget(n,i):void 0;return r===void 0?{}:{shutdown:r}},prepareAppleRunner:Cr,configureProviderPortReverse:Cr})}async function xr(e,t,n){let i={},a=n.relaunch&&!!n.target,o=a?n.appBundleId:void 0;if(o){let e=Date.now();await Pe({device:t.device,interactor:await t.resolveInteractor(n.execution,o),positionals:[o]}).catch(async e=>{let{passedAndroidRelaunchStopFences:t}=await import(`./app-lifecycle.js`).then(e=>e.n);if(!t(e))throw e}),i.relaunchCloseDurationMs=q(e)}if(v(n.runtimeHints)){if(!n.applyRuntimeHints)throw new r(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});let e=Date.now();await n.applyRuntimeHints({appId:n.appBundleId,values:n.runtimeHints}),i.runtimeHintsDurationMs=q(e)}let s=Date.now(),c=await Fe({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:n.positionals,appBundleId:n.appBundleId,execution:n.execution,terminateRunningApp:a&&!o});i.openDispatchDurationMs=q(s),n.enableTestIme&&await e.androidApplications.activateTestIme(t.device,{stateDir:n.stateDir});let l=Me(n);if(l){let e=Date.now();await Fe({device:t.device,interactor:await t.resolveInteractor({...n.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0},n.appBundleId),positionals:[l],appBundleId:n.appBundleId,execution:{...n.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0}}),i.launchUrlDurationMs=q(e)}else i.launchUrlDurationMs=0;let u=await e.androidApplications.inferOpenedAppBundleId(t.device,n.target,n.appBundleId,c?.launchedAppBundleId);u&&await e.androidApplications.resetFramePerfStats(t.device,u);let d=Date.now();return Object.assign(i,await Sr(t,n,u)),i.postOpenSettleDurationMs=q(d),{appBundleId:u,timing:i}}async function Sr(e,t,n){if(!t.target||a(t.target))return{};if(!n)return{postOpenObservation:`app-unidentified`};let r=await vr(await e.resolveInteractor(t.execution,n),n,e.signal);return r.observation===`probe-failed`?{postOpenObservation:`probe-failed`,postOpenObservationFailure:r.failure}:{postOpenObservation:r.observation}}function q(e){return Math.max(0,Date.now()-e)}async function Cr(){throw new r(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Android.`)}const J=n(`android`),Y=Object.freeze({available:!0}),wr=t(`unsupported-device-kind`),Tr=t(`unsupported-platform-leaf`,"Run `agent-device settings --help` for the settings each target serves."),Er=t(`unsupported-device-kind`,`focus is supported on Android emulators and physical devices.`),Dr=t(`unsupported-device-kind`,`keyboard actions are supported on Android emulators and physical devices.`),Or=t(`unsupported-platform-leaf`),kr=t(`unsupported-platform-leaf`,`Android has no key event for this system button.`),Ar=t(`unsupported-device-kind`,`Headless boot is supported only for Android emulators.`),jr=t(`unsupported-device-kind`,`Android appstate is supported only for Android emulators and devices.`),Mr=t(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),Nr=t(`unsupported-device-kind`,`open is supported only for Android emulators and devices.`),Pr=t(`unsupported-device-kind`,`close is supported only for Android emulators and devices.`),Fr=t(`unsupported-device-kind`,`Runtime hints are supported only for Android emulators and devices.`),Ir=t(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),Lr=t(`unsupported-device-kind`,`shutdown is supported only for Apple simulators and Android emulators.`),Rr=t(`unsupported-device-kind`,`screenshot is supported only for Android emulators and devices.`),X=t(`unsupported-device-kind`,`snapshot is supported only for Android emulators and devices.`),zr=t(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),Br=t(`unsupported-platform-leaf`,`viewport resizes web targets only (--platform web).`),Vr=t(`unsupported-platform-leaf`,`the stateless audio page probe is a web-session operation; Android targets use the host capture.`);function Hr(e){let t=Ur(e),n=Wr(e),r=Gr(e);return y({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:r,clearRuntimeHints:r,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Mr,configureProviderPortReverse:Ir})}function Ur(e){return e.kind===`emulator`||e.kind===`device`?Y:Nr}function Wr(e){return e.kind===`emulator`||e.kind===`device`?Y:Pr}function Gr(e){return e.kind===`emulator`||e.kind===`device`?Y:Fr}const Z=t(`unsupported-device-kind`,`Gestures are supported on Android emulators and physical devices.`),Kr=t(`unsupported-platform-leaf`,S),qr=t(`unsupported-platform-leaf`,x);function Jr(e,t){return e.kind===`simulator`?Z:e.target===`tv`?t:Y}function Q(e){return e.kind===`simulator`?Z:Y}function $(e){return e.kind===`simulator`?Er:Y}const Yr=t(`owner-capability-missing`,oe),Xr=t(`owner-capability-missing`,`Could not determine whether this Android build supports a shell clipboard: the adb probe did not complete. Retry once the device is reachable.`);async function Zr(e,t){let n=e.androidTools?.probeClipboardShellSupport;return n?await n.call(e.androidTools,t):`probe-failed`}const Qr=t(`unsupported-device-kind`,`tv-remote is supported only on Android TV targets.`);function $r(e){return e.kind!==`simulator`&&e.target===`tv`?Y:Qr}function ei(t){let n=Ct(t),r=new Map,i=async e=>{if(e.kind===`simulator`)return Yr;let n=r.get(e.id)??await Zr(t,e);return n!==`probe-failed`&&r.set(e.id,n),n===`supported`?Y:n===`unsupported`?Yr:Xr},a=async e=>{let t=await n.inspectFacts(e),r=se(e),a=await i(e);return Object.freeze({device:t.device,operations:{...t.operations,...r,appState:e.kind===`simulator`?jr:Y,networkDump:Y,screenRecordingStart:Y,screenRecordingReattach:Y,screenRecordingCleanup:Y,...be({capture:e.kind===`simulator`?X:Y,customActions:zr,withoutActiveApp:e.kind===`simulator`?X:Y}),...ke({capture:e.kind===`simulator`?Rr:Y}),...pe({findText:X,querySelector:X}),...je({setViewport:Br}),...ge({focus:$(e)}),...he({unsupported:Z,plan:Q(e),directionalFling:Q(e),multiTouch:Jr(e,Kr),targetAuthoredDrag:Jr(e,qr),viewport:Q(e)}),...fe({scroll:Q(e)}),...de({type:$(e)}),...ie({unsupported:Er,tap:$(e),longPress:$(e),hover:Or,fill:$(e)}),..._e({readTextAtPoint:e.kind===`simulator`?wr:Y}),...ue({back:$(e)}),...ve({unsupported:kr,home:$(e),appSwitcher:$(e),...ye(e)}),...lt(e),..._t(e),...Te({triggerAppEvent:$(e)}),...Ie({target:$(e),unsupported:Tr,write:{wifi:Y,bluetooth:Y,airplane:Y,"mobile-data":Y,location:Y,animations:Y,appearance:Y,"text-size":Y,fingerprint:Y,"clear-app-state":Y,permission:Y},read:{"text-size":Y}}),...Ee({read:$(e),wait:$(e),accept:$(e),dismiss:$(e)}),...Se({orientation:$(e),unlock:$(e)}),...we({tvRemote:$r(e)}),...xe({unsupported:Dr,status:$(e),dismiss:$(e),enter:$(e)}),...Ce({unsupported:a.available?Yr:a,read:a,write:a}),...De({capture:yt(e),query:Vr}),...Oe({frames:$(e),memorySample:$(e),memorySnapshot:$(e),nativeCapture:$(e),profileReport:$(e)}),ensureReady:Y,bootTarget:Y,bootTargetHeadless:e.kind===`emulator`?Y:Ar,listApps:Y,...Hr(e),shutdownTarget:e.kind===`emulator`?Y:Lr}})};return Object.freeze({owner:J,ownsDevice:e=>e.platform===`android`,inspectFacts:a,bind:async r=>{let i=await n.bind(r),o=await a(r.device),s=await gr({host:t,device:r.device,owner:J,signal:r.scope.signal});return Object.freeze({device:i.device,owner:J,facts:o,operations:Object.freeze({...i.operations,...ce({host:t,device:r.device,signal:r.scope.signal}),...o.operations.appState.available?{appState:async()=>{r.scope.signal.throwIfAborted();let{runAndroidAdb:e}=await import(`./adb.js`).then(e=>e.t);return await ae(async(t,n)=>await e(r.device,t,{...n,signal:r.scope.signal}),r.scope.signal)}}:{},networkDump:async e=>await Et(t,r.device,e,r.scope.signal),...s,...e(o.operations.audioProbeStart,()=>Be({host:t.audioProbe.hostCapture,device:r.device,owner:J})),...e(o.operations.perfFrames,()=>le({resolveHost:()=>t.perf.android,device:r.device,owner:J})),...ti(t,r,o),...ut({device:r.device,signal:r.scope.signal}),...vt({device:r.device,signal:r.scope.signal}),ensureReady:async e=>await C(t,r.device,{...e,headless:!1},r.scope.signal),bootTarget:async e=>await C(t,r.device,{...e,headless:!1},r.scope.signal),...o.operations.bootTargetHeadless.available?{bootTargetHeadless:async e=>await C(t,r.device,{...e,headless:!0},r.scope.signal)}:{},listApps:async e=>{r.scope.signal.throwIfAborted();let{listAndroidApps:t}=await import(`./app-lifecycle.js`).then(e=>e.n);return(await t(e.device,e.filter)).map(e=>({id:e.package,name:e.name}))},..._(br({host:t,device:r.device,signal:r.scope.signal}),o.operations),...o.operations.shutdownTarget.available?{shutdownTarget:async()=>await t.deviceShutdown.android.shutdownTarget(r.device,r.scope.signal)}:{}}),[Symbol.asyncDispose]:async()=>await i[Symbol.asyncDispose]()})},shutdown:async()=>await n.shutdown()})}function ti(e,t,n){let r={device:t.device,signal:t.scope.signal,resolveInteractor:e.localInteractors.resolve};return{...n.operations.captureSnapshot.available?me(r):{},...Le({...r,facts:n.operations,captureCapabilities:Ae(`an Android device captures through adb`),pause:async n=>await e.clock.sleep(n,t.scope.signal)})}}export{ei as createAndroidPlatformRuntime};
|
package/dist/src/runtime5.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{z as e}from"./sdk-contracts.js";import{n as t}from"./ime-state.js";function n(e){return Object.freeze({canShutdownTarget:r,shutdownTarget:async(t,n)=>await i(e.commands,t,n)})}function r(e){return e.platform===`android`&&e.kind===`emulator`}async function i(n,r,i){if(r.booted===!1)return a();i.throwIfAborted(),await t(r.id,i),i.throwIfAborted();try{let e=await n.run({executable:`adb`,args:[`-s`,r.id,`emu`,`kill`],allowFailure:!0,timeoutMs:15e3},i);i.throwIfAborted();let t=e.exitCode??-1;return{success:t===0,exitCode:t,stdout:e.stdout,stderr:e.stderr}}catch(t){i.throwIfAborted();let n=e(t);return{success:!1,exitCode:-1,stdout:``,stderr:n.message,error:n}}}function a(){return{success:!0,exitCode:0,stdout:``,stderr:``}}export{n as createAndroidShutdownRuntime};
|
package/dist/src/runtime6.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Mn as e}from"./sdk-batch.js";import{_ as t}from"./sdk-contracts.js";import{St as n}from"./sdk-io.js";import"./diagnostics.js";import{V as r}from"./sdk-device.js";import{f as i,x as a}from"./device.js";import{t as o}from"./fold-runtime.js";import{c as s,s as c}from"./config.js";import{i as l}from"./simulator.js";import{o as u}from"./display-inventory.js";import{n as d}from"./fold-helper.js";async function f(e,t,r={}){r.signal?.throwIfAborted(),l(e,`fold`);let i=t,o=i.keyframes?.at(-1)?.angle,s=i.pose??a(o),c=d(e);h(e,await u(e,{signal:r.signal,foldHelper:c})),await c.setPose(i.keyframes??s,r.signal),n({level:`info`,phase:`apple_fold_pose_dispatched`,data:{deviceId:e.id,pose:s}});let f=await g(e,c,s,r.signal,o),p=await T(e,c,r.signal);return{pose:a(f),hingeAngleDegrees:f,...p?{screen:E(p)}:{}}}function p(e){return e instanceof t&&e.details?.reason===`fold-hinge-angle-no-sample`}async function m(e,n,r,i,a,o){let s=await T(e,n,i);return new t(`COMMAND_FAILED`,`${e.name} received the ${r} pose request, but the first hinge-angle read returned no sample to verify it`,{deviceId:e.id,requestedPose:r,...a===void 0?{}:{targetAngleDegrees:a},reason:`fold-pose-dispatched-unverified`,...s?{screen:E(s)}:{},...o instanceof t?{hingeReadFailure:o.details}:{},hint:`The pose request was sent and the device may have followed it, but the first hinge-angle read returned no sample, so fold cannot confirm it. Take a screenshot or snapshot to see which panel is lit; hingeReadFailure names why the read failed.`},o)}function h(e,n){if(n.unresolved)throw new t(`COMMAND_FAILED`,`The simulator reported no panel table`,{deviceId:e.id,hint:`fold needs the simulator's integrated displays to identify a foldable: the default set uses CoreDevice and a scoped set uses the fold helper. The apple_display_inventory_unresolved diagnostic names why the read failed.`});if(!n.multiScreen)throw new t(`UNSUPPORTED_OPERATION`,`${e.name} is not a foldable simulator: fold requires more than one integrated panel`,{deviceId:e.id,reason:`single-panel-device`,hint:`fold sets the hinge angle of a foldable simulator such as iPhone Duo; this simulator reports one integrated panel, so it has no hinge to pose.`})}async function g(e,t,n,r,i){let a,o;for(let s=1;s<=8;s+=1){r?.throwIfAborted(),o=a;try{a=await t.readHingeAngle({signal:r,windowMs:s>1?c:0})}catch(o){throw a!==void 0||!p(o)?o:await m(e,t,n,r,i,o)}if(_(a,o,n,i))return a}throw b(e,n,a,o,i)}function _(e,t,n,r){return r===void 0?a(e)===n?n!==`half-open`||t!==void 0&&x(e,t):!1:v(e,t,r)}function v(e,t,n){return y(e,n)?n===0||n===180||t!==void 0&&y(t,n)&&Math.abs(e-t)<=.5:!1}function y(e,t){return t===void 0||e!==void 0&&Math.abs(e-t)<=.5}function b(e,n,r,i,o){return y(r,o)?o!==void 0&&r!==void 0?w(e,a(r),r,i):r!==void 0&&n===`half-open`&&a(r)===n?w(e,n,r,i):C(e,n,r):new t(`COMMAND_FAILED`,`The hinge did not reach the final keyframe angle`,{reason:`fold-angle-unverified`,targetAngleDegrees:o,hingeAngleDegrees:r,deviceId:e.id})}function x(e,t){return a(e)===`half-open`&&a(t)===`half-open`&&Math.abs(e-t)<=.5}function S(e,t,n){return{deviceId:e.id,requestedPose:t,observedPose:n===void 0?void 0:a(n),hingeAngleDegrees:n}}function C(e,n,r){return new t(`COMMAND_FAILED`,`${e.name} did not reach the ${n} pose: the simulator still reports a hinge angle of ${r}°`,{...S(e,n,r),reason:`fold-pose-unverified`,hint:`The simulator HID command completed, but the hinge did not follow. Verify that the selected Xcode and simulator runtime support foldable HID control, then retry.`})}function w(e,n,r,i){return new t(`COMMAND_FAILED`,`${e.name} was observed ${n} at ${r}° but did not settle: 8 hinge reads never held two consecutive angles within ${s}° of each other`,{...S(e,n,r),reason:`fold-pose-unsettled`,...i===void 0?{}:{previousHingeAngleDegrees:i},hint:`The hinge reached the requested pose and was still moving when the read budget ended. Retry the fold to see whether the simulator holds the pose.`})}async function T(e,t,n){let r=await u(e,{signal:n,source:`guest`,foldHelper:t});if(!(r.unresolved||r.ambiguous))return r.activeDisplay}function E(e){return{display:e.name,coordinateSpace:i,widthPt:Math.round(e.widthPx/e.pointScale),heightPt:Math.round(e.heightPx/e.pointScale)}}const D=Object.freeze({available:!0}),O=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`fold is supported on foldable iPhone simulators controlled through simulator HID; a physical device is folded by hand.`}),k=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`fold poses the hinge of a foldable iPhone; tvOS, macOS, watchOS and visionOS simulators have no hinge.`});function A(e){if(e.kind!==`simulator`)return O;let t=r(e);return t!==`ios`&&t!==`ipados`?k:D}function j(e){return o({fold:A(e)})}function M(t){let{device:n,signal:r}=t;return e(j(n).setFoldPose,()=>({setFoldPose:async e=>(r.throwIfAborted(),await f(n,e,{signal:r}))}))}export{M as n,j as t};
|
package/dist/src/runtime7.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{P as e,R as t}from"./sdk-contracts.js";import{y as n}from"./sdk-batch-runner.js";import{J as r}from"./sdk-io.js";import{B as i,T as a,q as o,w as s}from"./sdk-device.js";import{Dn as c,On as l,kn as u,xn as d}from"./sdk-batch.js";import{r as f}from"./session.js";import"./command.js";import{a as p,r as m}from"./durable-resource.js";import{n as ee}from"./screen-recording-runtime.js";import{n as te,t as ne}from"./application-lifecycle-runtime.js";import{n as re,t as ie}from"./async-lifecycle.js";import{t as ae}from"./touch-runtime.js";import{n as oe}from"./artifact-paths.js";import{a as se,i as h,n as g,r as ce,t as le}from"./perf-runtime-operation-builder.js";import{C as ue,H as de,I as fe,N as pe,R as me,T as he,z as ge}from"./tv-remote-runtime.js";import{n as _e}from"./audio-probe-runtime.js";import{n as ve}from"./perf-runtime.js";import{a as ye,n as be}from"./screenshot-runtime2.js";import{t as xe}from"./viewport-runtime.js";import{a as Se,i as Ce,n as _,o as we,r as v,s as Te,t as Ee}from"./network-traffic.js";import{a as De,i as Oe,r as ke}from"./src10.js";import{n as y,t as Ae}from"./screen-recording-completion.js";import{a as je,i as Me,n as Ne,o as b,r as Pe,s as x,t as S}from"./stop-sequence.js";import{t as C}from"./app-log-runtime.js";import{n as Fe,o as Ie,s as Le}from"./simctl.js";import{n as Re,t as ze}from"./runtime6.js";import{i as Be,t as Ve}from"./app-backend.js";import{_ as He,a as Ue,c as We,d as Ge,g as Ke,h as qe,i as Je,l as Ye,m as Xe,n as Ze,o as Qe,p as $e,r as et,s as tt,t as nt,u as rt,v as it,y as at}from"./system-surface-foreground.js";import ot from"node:path";function st(e){return e.hostApp?Object.freeze({available:!1,reason:`unsupported-device-scope`,hint:`This session holds one app of the Mac. Use a --surface desktop session for audio probe.`}):je(e)?Object.freeze({available:!0}):a(e)||s(e)&&e.kind===`simulator`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`audio probe capture requires a macOS host.`}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`audio is supported for macOS sessions and iOS simulators on macOS hosts; physical iOS devices expose no host audio tap.`})}function ct(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...le({platform:`Apple`,expectedProfileKind:`xctrace`,start:async e=>await t().start(n,r,e),reattach:async e=>await t().reattach(n,e),cleanup:async e=>await t().cleanup(n,e),writeProfileReport:async e=>await t().writeProfileReport(e)}),perfFrames:async({appId:e})=>({metric:e?await h(t().sampleFrames(n,e)):g(`Apple`,`bundle ID`),sampling:await t().frameSampling(n)}),perfMemorySample:async({appId:e})=>({metric:e?await h(t().sampleMemory(n,e)):g(`Apple`,`bundle ID`),sampling:await t().memorySampling(n)}),perfMemorySnapshot:async({appId:e,kind:r,outPath:i,artifactsDir:a})=>{let o=r??`memgraph`,s={...await t().memorySnapshotSupport(n),androidHprof:!1,heapprofd:!1};if(o!==`memgraph`)return se(`Apple`,o,s,`Use perf memory snapshot --kind memgraph for supported Apple app sessions.`);if(!e)throw ce();let c=i??ot.join(a,`memory-memgraph-${lt()}.memgraph`);return{artifact:await t().captureMemorySnapshot(n,e,c),support:s,sampling:{method:`xcrun memgraph`,description:`Native Apple memory graph captured for offline inspection.`,defaultKind:`memgraph`,artifactOnly:!0}}}})}function lt(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}const w=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function T(e){return a(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const ut=Object.freeze({resourceKind:C,version:1,encode:e=>({...e}),decode:e=>!ft(e.transport)||!pt(e.backend)||!_t(e.outputPath)||!ht(e.pidPath)||!mt(e.transport,e.backend)?dt():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function dt(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function ft(e){return e===`apple-log-stream`||e===`coredevice-console`}function pt(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function mt(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function ht(e){return e===void 0||_t(e)}function gt(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return m({resourceKind:C,sessionId:e.sessionId,device:{id:e.device.id,family:`apple`,appleOs:e.device.appleOs,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target},...e.device.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.device.iosPhysicalDeviceBackend}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:p(ut,e.descriptor)})}function _t(e){return typeof e==`string`&&e.trim().length>0}const vt={message:`iOS physical-device app console capture is not supported by the installed devicectl.`,hint:`This devicectl does not expose process launch --console. Markers can still be written to app.log, but app output is not being captured. Use an iOS simulator for agent-device app logs or inspect physical-device logs in Console.app/Xcode until this Xcode toolchain exposes scriptable console capture.`},E={message:`Could not verify iOS physical-device app console capture support.`,hint:`Retry logs clear --restart. If the probe keeps failing, run logs doctor and inspect the request diagnostics for the devicectl help command.`};async function D(e,t){try{let n=await e.appleTools.run({tool:`devicectl`,args:[`device`,`process`,`launch`,`--help`],allowFailure:!0,timeoutMs:5e3},t),r=n.stderr.trim()||void 0;if(n.exitCode!==0)return{supported:!1,reason:`probe-failed`,stderr:r};let i=`${n.stdout}\n${n.stderr}`;return/\bUSAGE:\s+devicectl device process launch\b/i.test(i)&&/--console\b/.test(i)&&/--terminate-existing\b/.test(i)?{supported:!0,...r?{stderr:r}:{}}:{supported:!1,reason:`unsupported`,...r?{stderr:r}:{}}}catch(e){if(t?.aborted)throw t.reason;return{supported:!1,reason:`probe-failed`,...e instanceof Error?{stderr:e.message}:{}}}}async function yt(e,t,n,r){let i={},o=n?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`];if(a(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await x(async()=>b(await e.appleTools.run({tool:`simctl`,args:Le(),allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,o.push(w);else{i.devicectlAvailable=await x(async()=>b(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await D(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?vt:E;o.push(`${e.message} ${e.hint}`)}}return{backend:T(t),checks:i,notes:o}}function O(e,t){let n=k(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=k(t);r.push(`process == "${e}"`,`processImagePath ENDSWITH[c] "/${e}"`,`senderImagePath ENDSWITH[c] "/${e}"`,`processImagePath CONTAINS[c] "/${e}.app/"`,`senderImagePath CONTAINS[c] "/${e}.app/"`)}return r.join(` OR `)}function bt(e,t){return Fe(e,[`spawn`,e.id,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,O(t.appBundleId,t.executableName)])}function xt(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function k(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}const A=1e4;async function St(e,t,n,r,i){Ct(t),Ce(e,n);let a=T(t),o=await Tt(e,t,n.appBundleId,i),s=new ie,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=Dt(l),d=await wt(e,t,o,u.sink,n.pidPath,i);s.defer(async()=>{c||await d[Symbol.asyncDispose]()}),t.kind===`simulator`&&await Ot(e,u.written,d.wait,i);let f=kt(e,d,l,a,n.outputPath),p={transport:a===`ios-device`?`coredevice-console`:`apple-log-stream`,backend:a,outputPath:n.outputPath,...n.pidPath===void 0?{}:{pidPath:n.pidPath}},m=Te(f,gt({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:p}));return c=!0,m}finally{await s[Symbol.asyncDispose]()}}function Ct(t){if(t.appleOs===`watchos`)throw new e(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(s(t)&&t.kind===`device`&&t.iosPhysicalDeviceBackend===`xctest`)throw new e(`UNSUPPORTED_OPERATION`,w,{hint:w})}async function wt(t,n,r,i,a,o){if(s(n)&&n.kind===`device`){let n=await D(t,o);if(!n.supported){let t=n.reason===`unsupported`?vt:E;throw new e(n.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,t.message,{backend:`ios-device`,hint:t.hint,stderr:n.stderr})}}return o?.throwIfAborted(),await t.processes.start({command:{kind:`host`,request:r},output:i,...a?{markerPath:a}:{}})}async function Tt(e,t,n,r){return a(t)?{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,O(n)],allowFailure:!0}:t.kind===`device`?{executable:`xcrun`,args:xt(t.id,n),allowFailure:!0}:{executable:`xcrun`,args:bt(t,{appBundleId:n,executableName:await Et(e,t,n,r)}),allowFailure:!0}}async function Et(e,t,n,r){let i=await e.appleTools.run({tool:`simctl`,args:Ie(t,[`get_app_container`,t.id,n,`app`]),allowFailure:!0,timeoutMs:4e3},r),a=i.exitCode===0?i.stdout.trim():``;if(!a)return;let o=await e.commands.run({executable:`plutil`,args:[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,ot.join(a,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return o.exitCode===0&&o.stdout.trim()||void 0}function Dt(e){let t=j,n=new Promise(e=>{t=e});return{sink:{write:async n=>{t(),await e.write(n)},[Symbol.asyncDispose]:async()=>await e[Symbol.asyncDispose]()},written:n}}async function Ot(t,n,r,i){i?.throwIfAborted();let a=j,o=new Promise((e,t)=>{a=()=>t(i?.reason),i?.addEventListener(`abort`,a,{once:!0})}),s=new AbortController,c=t.clock.sleep(A,s.signal).then(()=>`timed-out`);c.catch(j);try{let t=Promise.race([n,r.then(j,j)]).then(()=>`launched`);if(await Promise.race([t,c,o])===`timed-out`)throw new e(`COMMAND_FAILED`,`Simulator log stream did not start within ${A}ms`,{reason:`simulator-log-stream-launch-timeout`,timeoutMs:A,hint:`Check that the simulator finished booting, then retry logs start.`})}finally{s.abort(),i?.removeEventListener(`abort`,a)}}function j(){}function kt(e,t,n,r,i){let a=e.clock.now(),o=`active`;t.wait.then(e=>{o=e.exitCode===0?`ended`:`failed`},()=>{o=`failed`});let s=new Set([async()=>await t.terminate(),async()=>await t.wait.then(()=>void 0),async()=>await t[Symbol.asyncDispose](),async()=>await n[Symbol.asyncDispose]()]),c;return Se({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>c??=(async()=>(await At(s)).length>0?(c=void 0,o=`failed`,{status:`cleanup-pending`,reason:`transport-failed`,message:`Apple app-log cleanup did not settle every owned resource`}):(o=`ended`,{status:`completed`,result:{backend:r,outputPath:i,completedAt:e.clock.now()}}))()})}async function At(e){let t=[];for(let n of e)try{await n(),e.delete(n)}catch(e){t.push(e)}return t}const M=d(`apple`),N=Object.freeze({available:!0});function jt(t){return Object.freeze({owner:M,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>P(e),bind:async n=>{if(n.intent.kind===`exact-owner`&&!c(n.intent.owner,M))throw new e(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return Mt(t,n.device,n.scope.signal)},shutdown:async()=>void 0})}function Mt(t,n,r){if(n.platform!==`apple`)throw new e(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${n.platform}`);let i=we({codec:ut,reattach:async(e,r)=>e.backend!==T(n)||!v(t,r.sessionId,e)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await Oe(t,e.pidPath),cleanup:async(e,r)=>e.backend===T(n)&&v(t,r.sessionId,e)?await ke(t,e.pidPath):{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`Apple app-log descriptor does not match the bound device or owning session`}}),a=Object.freeze({appLogInspect:async()=>({backend:T(n)}),appLogDoctor:async({appBundleId:e})=>await yt(t,n,e,r),appLogStart:async e=>await St(t,n,e,M,r),...i});return Object.freeze({device:n,owner:M,facts:P(n),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function P(e){if(e.appleOs===`watchos`)return Nt(e);let t=s(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:w}:N;return Object.freeze({device:{family:`apple`,appleOs:e.appleOs,kind:e.kind,...e.target===void 0?{}:{target:e.target},...e.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.iosPhysicalDeviceBackend},providerMode:`local`},operations:{appLogInspect:t,appLogDoctor:t,appLogStart:t,appLogReattach:N,appLogCleanup:N}})}function Nt(e){let t=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS app logs are not supported.`});return Object.freeze({device:{family:`apple`,appleOs:`watchos`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:`local`},operations:{appLogInspect:t,appLogDoctor:t,appLogStart:t,appLogReattach:t,appLogCleanup:t}})}async function Pt(e,t,n,r){let i=T(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=_(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(It(t,n,o.dump)){let i=await Lt(e,t,n,a.path,r);i&&(o=Ft(s,o,i,n.maxEntries))}return Bt(s,t,n),zt(s,o.dump),o.dump.entries.length===0&&s.push(Vt(t)),Object.freeze({source:`app-log`,backend:i,dump:o.dump,notes:Object.freeze(s)})}function Ft(e,t,n,r){let i=n.scan.dump.entries.length;return i===0&&(n.scan.dump.unnamedRequests??0)===0?(n.lineCount>0&&e.push(`Recovered ${n.lineCount} recent iOS simulator app log lines from simctl log show, but none looked like HTTP traffic. This app may not emit request URLs, status, or timing into Unified Logging for this repro window.`),t):(i>0&&e.push(`Recovered ${i} iOS simulator HTTP entr${i===1?`y`:`ies`} from simctl log show (${n.lineCount} app log lines scanned).`),Ee(n.scan,t,r))}function It(e,t,n){return s(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function Lt(e,t,n,r,i){let a=n.appLogSnapshot?.startedAt,o=Ie(t,[`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,Rt(n.appBundleId),...typeof a==`number`&&Number.isFinite(a)&&a>0?[`--start`,`@${Math.floor(a/1e3)}`]:[`--last`,`5m`]]),s=await e.appleTools.run({tool:`simctl`,args:o,allowFailure:!0,timeoutMs:4e3},i);if(s.exitCode!==0||!s.stdout.trim())return;let c=s.stdout.split(`
|
|
1
|
+
import{An as e,Mn as t,jn as n,wn as r}from"./sdk-batch.js";import{_ as i,x as a}from"./sdk-contracts.js";import{y as o}from"./sdk-batch-runner.js";import{Z as s}from"./sdk-io.js";import{J as c,T as l,V as u,w as d}from"./sdk-device.js";import{r as f}from"./session.js";import"./command.js";import{a as p,r as m}from"./durable-resource.js";import{n as ee}from"./screen-recording-runtime.js";import{n as te,t as ne}from"./application-lifecycle-runtime.js";import{n as re,t as ie}from"./async-lifecycle.js";import{t as ae}from"./touch-runtime.js";import{n as oe}from"./artifact-paths.js";import{a as se,i as h,n as g,r as ce,t as le}from"./perf-runtime-operation-builder.js";import{C as ue,H as de,I as fe,N as pe,R as me,T as he,z as ge}from"./tv-remote-runtime.js";import{n as _e}from"./audio-probe-runtime.js";import{n as ve}from"./perf-runtime.js";import{a as ye,n as be}from"./screenshot-runtime2.js";import{t as xe}from"./viewport-runtime.js";import{a as Se,i as Ce,n as _,o as we,r as v,s as Te,t as Ee}from"./network-traffic.js";import{a as De,i as Oe,r as ke}from"./src10.js";import{n as y,t as Ae}from"./screen-recording-completion.js";import{a as je,i as Me,n as Ne,o as b,r as Pe,s as x,t as S}from"./stop-sequence.js";import{t as C}from"./app-log-runtime.js";import{c as Fe,r as Ie,s as Le}from"./simctl.js";import{n as Re,t as ze}from"./runtime6.js";import{i as Be,t as Ve}from"./app-backend.js";import{_ as He,a as Ue,c as We,d as Ge,g as Ke,h as qe,i as Je,l as Ye,m as Xe,n as Ze,o as Qe,p as $e,r as et,s as tt,t as nt,u as rt,v as it,y as at}from"./system-surface-foreground.js";import ot from"node:path";function st(e){return e.hostApp?Object.freeze({available:!1,reason:`unsupported-device-scope`,hint:`This session holds one app of the Mac. Use a --surface desktop session for audio probe.`}):je(e)?Object.freeze({available:!0}):l(e)||d(e)&&e.kind===`simulator`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`audio probe capture requires a macOS host.`}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`audio is supported for macOS sessions and iOS simulators on macOS hosts; physical iOS devices expose no host audio tap.`})}function ct(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...le({platform:`Apple`,expectedProfileKind:`xctrace`,start:async e=>await t().start(n,r,e),reattach:async e=>await t().reattach(n,e),cleanup:async e=>await t().cleanup(n,e),writeProfileReport:async e=>await t().writeProfileReport(e)}),perfFrames:async({appId:e})=>({metric:e?await h(t().sampleFrames(n,e)):g(`Apple`,`bundle ID`),sampling:await t().frameSampling(n)}),perfMemorySample:async({appId:e})=>({metric:e?await h(t().sampleMemory(n,e)):g(`Apple`,`bundle ID`),sampling:await t().memorySampling(n)}),perfMemorySnapshot:async({appId:e,kind:r,outPath:i,artifactsDir:a})=>{let o=r??`memgraph`,s={...await t().memorySnapshotSupport(n),androidHprof:!1,heapprofd:!1};if(o!==`memgraph`)return se(`Apple`,o,s,`Use perf memory snapshot --kind memgraph for supported Apple app sessions.`);if(!e)throw ce();let c=i??ot.join(a,`memory-memgraph-${lt()}.memgraph`);return{artifact:await t().captureMemorySnapshot(n,e,c),support:s,sampling:{method:`xcrun memgraph`,description:`Native Apple memory graph captured for offline inspection.`,defaultKind:`memgraph`,artifactOnly:!0}}}})}function lt(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}const w=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function T(e){return l(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const ut=Object.freeze({resourceKind:C,version:1,encode:e=>({...e}),decode:e=>!ft(e.transport)||!pt(e.backend)||!_t(e.outputPath)||!ht(e.pidPath)||!mt(e.transport,e.backend)?dt():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function dt(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function ft(e){return e===`apple-log-stream`||e===`coredevice-console`}function pt(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function mt(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function ht(e){return e===void 0||_t(e)}function gt(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return m({resourceKind:C,sessionId:e.sessionId,device:{id:e.device.id,family:`apple`,appleOs:e.device.appleOs,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target},...e.device.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.device.iosPhysicalDeviceBackend}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:p(ut,e.descriptor)})}function _t(e){return typeof e==`string`&&e.trim().length>0}const vt={message:`iOS physical-device app console capture is not supported by the installed devicectl.`,hint:`This devicectl does not expose process launch --console. Markers can still be written to app.log, but app output is not being captured. Use an iOS simulator for agent-device app logs or inspect physical-device logs in Console.app/Xcode until this Xcode toolchain exposes scriptable console capture.`},E={message:`Could not verify iOS physical-device app console capture support.`,hint:`Retry logs clear --restart. If the probe keeps failing, run logs doctor and inspect the request diagnostics for the devicectl help command.`};async function D(e,t){try{let n=await e.appleTools.run({tool:`devicectl`,args:[`device`,`process`,`launch`,`--help`],allowFailure:!0,timeoutMs:5e3},t),r=n.stderr.trim()||void 0;if(n.exitCode!==0)return{supported:!1,reason:`probe-failed`,stderr:r};let i=`${n.stdout}\n${n.stderr}`;return/\bUSAGE:\s+devicectl device process launch\b/i.test(i)&&/--console\b/.test(i)&&/--terminate-existing\b/.test(i)?{supported:!0,...r?{stderr:r}:{}}:{supported:!1,reason:`unsupported`,...r?{stderr:r}:{}}}catch(e){if(t?.aborted)throw t.reason;return{supported:!1,reason:`probe-failed`,...e instanceof Error?{stderr:e.message}:{}}}}async function yt(e,t,n,r){let i={},a=n?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`];if(l(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await x(async()=>b(await e.appleTools.run({tool:`simctl`,args:Fe(),allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,a.push(w);else{i.devicectlAvailable=await x(async()=>b(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await D(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?vt:E;a.push(`${e.message} ${e.hint}`)}}return{backend:T(t),checks:i,notes:a}}function O(e,t){let n=k(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=k(t);r.push(`process == "${e}"`,`processImagePath ENDSWITH[c] "/${e}"`,`senderImagePath ENDSWITH[c] "/${e}"`,`processImagePath CONTAINS[c] "/${e}.app/"`,`senderImagePath CONTAINS[c] "/${e}.app/"`)}return r.join(` OR `)}function bt(e,t){return Ie(e,[`spawn`,e.id,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,O(t.appBundleId,t.executableName)])}function xt(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function k(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}const A=1e4;async function St(e,t,n,r,i){Ct(t),Ce(e,n);let a=T(t),o=await Tt(e,t,n.appBundleId,i),s=new ie,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=Dt(l),d=await wt(e,t,o,u.sink,n.pidPath,i);s.defer(async()=>{c||await d[Symbol.asyncDispose]()}),t.kind===`simulator`&&await Ot(e,u.written,d.wait,i);let f=kt(e,d,l,a,n.outputPath),p={transport:a===`ios-device`?`coredevice-console`:`apple-log-stream`,backend:a,outputPath:n.outputPath,...n.pidPath===void 0?{}:{pidPath:n.pidPath}},m=Te(f,gt({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:p}));return c=!0,m}finally{await s[Symbol.asyncDispose]()}}function Ct(e){if(e.appleOs===`watchos`)throw new i(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(d(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`)throw new i(`UNSUPPORTED_OPERATION`,w,{hint:w})}async function wt(e,t,n,r,a,o){if(d(t)&&t.kind===`device`){let t=await D(e,o);if(!t.supported){let e=t.reason===`unsupported`?vt:E;throw new i(t.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,e.message,{backend:`ios-device`,hint:e.hint,stderr:t.stderr})}}return o?.throwIfAborted(),await e.processes.start({command:{kind:`host`,request:n},output:r,...a?{markerPath:a}:{}})}async function Tt(e,t,n,r){return l(t)?{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,O(n)],allowFailure:!0}:t.kind===`device`?{executable:`xcrun`,args:xt(t.id,n),allowFailure:!0}:{executable:`xcrun`,args:bt(t,{appBundleId:n,executableName:await Et(e,t,n,r)}),allowFailure:!0}}async function Et(e,t,n,r){let i=await e.appleTools.run({tool:`simctl`,args:Le(t,[`get_app_container`,t.id,n,`app`]),allowFailure:!0,timeoutMs:4e3},r),a=i.exitCode===0?i.stdout.trim():``;if(!a)return;let o=await e.commands.run({executable:`plutil`,args:[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,ot.join(a,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return o.exitCode===0&&o.stdout.trim()||void 0}function Dt(e){let t=j,n=new Promise(e=>{t=e});return{sink:{write:async n=>{t(),await e.write(n)},[Symbol.asyncDispose]:async()=>await e[Symbol.asyncDispose]()},written:n}}async function Ot(e,t,n,r){r?.throwIfAborted();let a=j,o=new Promise((e,t)=>{a=()=>t(r?.reason),r?.addEventListener(`abort`,a,{once:!0})}),s=new AbortController,c=e.clock.sleep(A,s.signal).then(()=>`timed-out`);c.catch(j);try{let e=Promise.race([t,n.then(j,j)]).then(()=>`launched`);if(await Promise.race([e,c,o])===`timed-out`)throw new i(`COMMAND_FAILED`,`Simulator log stream did not start within ${A}ms`,{reason:`simulator-log-stream-launch-timeout`,timeoutMs:A,hint:`Check that the simulator finished booting, then retry logs start.`})}finally{s.abort(),r?.removeEventListener(`abort`,a)}}function j(){}function kt(e,t,n,r,i){let a=e.clock.now(),o=`active`;t.wait.then(e=>{o=e.exitCode===0?`ended`:`failed`},()=>{o=`failed`});let s=new Set([async()=>await t.terminate(),async()=>await t.wait.then(()=>void 0),async()=>await t[Symbol.asyncDispose](),async()=>await n[Symbol.asyncDispose]()]),c;return Se({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>c??=(async()=>(await At(s)).length>0?(c=void 0,o=`failed`,{status:`cleanup-pending`,reason:`transport-failed`,message:`Apple app-log cleanup did not settle every owned resource`}):(o=`ended`,{status:`completed`,result:{backend:r,outputPath:i,completedAt:e.clock.now()}}))()})}async function At(e){let t=[];for(let n of e)try{await n(),e.delete(n)}catch(e){t.push(e)}return t}const M=r(`apple`),N=Object.freeze({available:!0});function jt(t){return Object.freeze({owner:M,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>P(e),bind:async n=>{if(n.intent.kind===`exact-owner`&&!e(n.intent.owner,M))throw new i(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return Mt(t,n.device,n.scope.signal)},shutdown:async()=>void 0})}function Mt(e,t,n){if(t.platform!==`apple`)throw new i(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${t.platform}`);let r=we({codec:ut,reattach:async(n,r)=>n.backend!==T(t)||!v(e,r.sessionId,n)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await Oe(e,n.pidPath),cleanup:async(n,r)=>n.backend===T(t)&&v(e,r.sessionId,n)?await ke(e,n.pidPath):{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`Apple app-log descriptor does not match the bound device or owning session`}}),a=Object.freeze({appLogInspect:async()=>({backend:T(t)}),appLogDoctor:async({appBundleId:r})=>await yt(e,t,r,n),appLogStart:async r=>await St(e,t,r,M,n),...r});return Object.freeze({device:t,owner:M,facts:P(t),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function P(e){if(e.appleOs===`watchos`)return Nt(e);let t=d(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:w}:N;return Object.freeze({device:{family:`apple`,appleOs:e.appleOs,kind:e.kind,...e.target===void 0?{}:{target:e.target},...e.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.iosPhysicalDeviceBackend},providerMode:`local`},operations:{appLogInspect:t,appLogDoctor:t,appLogStart:t,appLogReattach:N,appLogCleanup:N}})}function Nt(e){let t=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS app logs are not supported.`});return Object.freeze({device:{family:`apple`,appleOs:`watchos`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:`local`},operations:{appLogInspect:t,appLogDoctor:t,appLogStart:t,appLogReattach:t,appLogCleanup:t}})}async function Pt(e,t,n,r){let i=T(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=_(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(It(t,n,o.dump)){let i=await Lt(e,t,n,a.path,r);i&&(o=Ft(s,o,i,n.maxEntries))}return Bt(s,t,n),zt(s,o.dump),o.dump.entries.length===0&&s.push(Vt(t)),Object.freeze({source:`app-log`,backend:i,dump:o.dump,notes:Object.freeze(s)})}function Ft(e,t,n,r){let i=n.scan.dump.entries.length;return i===0&&(n.scan.dump.unnamedRequests??0)===0?(n.lineCount>0&&e.push(`Recovered ${n.lineCount} recent iOS simulator app log lines from simctl log show, but none looked like HTTP traffic. This app may not emit request URLs, status, or timing into Unified Logging for this repro window.`),t):(i>0&&e.push(`Recovered ${i} iOS simulator HTTP entr${i===1?`y`:`ies`} from simctl log show (${n.lineCount} app log lines scanned).`),Ee(n.scan,t,r))}function It(e,t,n){return d(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function Lt(e,t,n,r,i){let a=n.appLogSnapshot?.startedAt,o=Le(t,[`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,Rt(n.appBundleId),...typeof a==`number`&&Number.isFinite(a)&&a>0?[`--start`,`@${Math.floor(a/1e3)}`]:[`--last`,`5m`]]),s=await e.appleTools.run({tool:`simctl`,args:o,allowFailure:!0,timeoutMs:4e3},i);if(s.exitCode!==0||!s.stdout.trim())return;let c=s.stdout.split(`
|
|
2
2
|
`).map(e=>e.trimEnd()).filter(e=>e.trim()&&!e.trim().startsWith(`Timestamp Ty Process[PID:TID]`));if(c.length!==0)return{scan:_(`${c.join(`
|
|
3
|
-
`)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function Rt(e){let t=e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`);return[`subsystem == "${t}"`,`subsystem CONTAINS "${t}"`,`processImagePath ENDSWITH[c] "/${t}"`,`senderImagePath ENDSWITH[c] "/${t}"`].join(` OR `)}function zt(e,t){let n=t.entries.filter(e=>e.pathUnavailable).length,r=t.unnamedRequests??0,i=n+r;if(i===0)return;let a=[`${i} request${i===1?``:`s`} reused a keep-alive connection, so CFNetwork logged no request URL.`];n>0&&a.push(`${n} listed against the origin the connection was opened for, without a path.`),r>0&&a.push(`${r} opened before this scan window and are missing from the entries entirely; scan more lines, or run logs clear --restart before the repro.`),a.push(`Absence of an endpoint in this dump does not prove it was not called.`),e.push(a.join(` `))}function Bt(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(s(t)&&t.kind===`simulator`?`Session app log stream is inactive. The iOS simulator recovery path scanned recent simctl log history, but a fresh logs clear --restart window is still the most reliable repro loop.`:`Session app log stream is inactive. Run logs clear --restart, reproduce the request window again, then rerun network dump.`):e.push(`Capture uses the session app log file. For fresh traffic, run logs clear --restart before reproducing requests.`)}function Vt(e){return s(e)&&e.kind===`simulator`?`No HTTP(s) entries were found in recent iOS simulator app logs. If the app only emits non-HTTP diagnostics, inspect logs path or add app-side URLSession/network logging for per-request timing and payload details.`:s(e)?`No HTTP(s) entries were found in recent iOS device app logs. iOS network dump only sees what the app emits into Unified Logging for this process.`:`No HTTP(s) entries were found in recent session app logs.`}async function Ht(e){let{host:n,snapshot:r,targetLabel:i,recorderWarning:a,nativePathDisposition:o}=e,s=r.invalidatedReason?{recorder:`lost`,why:`owner-session-lost`}:e.stopObservation;if(r.invalidatedReason&&!r.showTouches)throw Error(`recording invalidated: ${r.invalidatedReason}`);let c;try{c=await n.screenRecording.finalize.complete({outputPath:r.outPath,showTouches:!r.invalidatedReason&&r.showTouches,gestureEvents:r.gestureEvents,exportQuality:r.exportQuality??`medium`,...r.fps===void 0?{}:{fps:r.fps},targetLabel:i})}catch(e){throw t(e,`COMMAND_FAILED`)}let l=[...c.warning?[c.warning]:[],...a?[a]:[]];return Ae(r,{...c,...l.length>0?{warning:l.join(` `)}:{},...r.invalidatedReason?{overlayWarning:`overlay unavailable: ${r.invalidatedReason}`}:{}},{stopObservation:s,...o===void 0?{}:{nativePathDisposition:o}})}async function F(e){let{host:t,snapshot:n,targetLabel:r,collectedPath:i,exportPath:a,nativePath:o}=e;if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let s=e.overlayUnavailable??n.invalidatedReason,c;try{await t.screenRecording.outputs.copy({from:i,to:a}),c=await Ut(()=>t.screenRecording.finalize.complete({outputPath:a,showTouches:s===void 0&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.fps===void 0?{}:{fps:n.fps},targetLabel:r}))}catch(e){throw await t.screenRecording.outputs.remove(a),e}return{...c,...s===void 0?{}:{overlayWarning:`overlay unavailable: ${s}`},nativePathDisposition:await t.screenRecording.outputs.remove(o)===`removed`?`retired`:`retirable`}}async function Ut(e){try{return await e()}catch(e){throw t(e,`COMMAND_FAILED`)}}const Wt=[`outPath`,`startedAt`,`clientOutPath`,...Pe],I=Object.freeze({resourceKind:ee,version:1,encode:e=>e.backend===`simctl`?{backend:e.backend,outputPath:e.outputPath,processes:e.processes.map(e=>({...e})),...e.recording===void 0?{}:{recording:{...e.recording}}}:{backend:e.backend,outputPath:e.outputPath,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}},decode:e=>en(e)});function Gt(e){let{device:t,owner:n,input:r,descriptor:i}=e;return m({resourceKind:ee,sessionId:r.sessionId,device:o(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:p(I,i)})}function Kt(e){let t={};for(let n of Wt)e[n]!==void 0&&Object.assign(t,{[n]:e[n]});return t}async function qt(e,t,n,r){let i=I.decode(n);return i.status!==`decoded`||!H(t,i.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:i.descriptor.backend===`simctl`?await L(e,i.descriptor.processes,r):await Jt(e,t,i.descriptor)}async function L(e,t,n){let r=await Promise.all(t.map(async t=>await e.screenRecording.apple.inspectProcess(t)));if(r.includes(`ownership-lost`))return{status:`cleanup-pending`,reason:`ownership-fence-lost`};if(r.every(e=>e===`missing`))return n!==void 0&&e.screenRecording.ownedProcesses.clear(R(n)),{status:`already-missing`};let i=await Promise.all(t.flatMap((t,n)=>r[n]===`owned-alive`?[e.screenRecording.apple.terminateProcess(t)]:[]));return i.includes(`ownership-lost`)?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:(n!==void 0&&e.screenRecording.ownedProcesses.clear(R(n)),i.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`})}function R(e){return{kind:`session`,sessionId:e}}async function Jt(e,t,n){try{let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`already-missing`}:r===`ownership-lost`?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:(await e.screenRecording.apple.runRunner(t,{kind:`stop`,appBundleId:n.appBundleId,runnerSessionId:n.runnerSessionId,runnerAuthority:n.runnerAuthority}),{status:`cleaned`})}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple recording cleanup failed`}}}async function Yt(e){let{host:t,device:n,envelope:r}=e,i=I.decode(r.descriptor.body);return i.status===`decoded`?H(n,i.descriptor)?i.descriptor.backend===`simctl`?await Xt(e,i.descriptor):await Qt(t,n,i.descriptor):z(`descriptor-invalid`,`Apple screen-recording descriptor does not match the bound device.`):z(`descriptor-invalid`,i.message)}async function Xt(e,t){let n=await Promise.all(t.processes.map(async t=>await e.host.screenRecording.apple.inspectProcess(t)));if(!n.every(e=>e===`missing`))return z(`transport-not-reattachable`,n.includes(`ownership-lost`)?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`);let{recording:r}=t,i=Zt(Ne(e.envelope.metadata),t.outputPath);return r===void 0||i!==void 0&&!await $t(e.host,i)?{status:`missing`}:{status:`restore-export`,recording:r,nativePath:t.outputPath,cleanup:async()=>await L(e.host,t.processes,e.envelope.sessionId)}}function Zt(e,t){if(e.finalization===void 0)return e.collectedPath??t}async function Qt(e,t,n){let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`missing`}:z(`transport-not-reattachable`,r===`ownership-lost`?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`)}async function $t(e,t){try{return await e.screenRecording.finalize.sniff({outputPath:t}),!0}catch{return!1}}function z(e,t){return{status:`unreattachable`,reason:e,message:t}}function en(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?U():e.backend===`simctl`?tn(e,e.outputPath):e.backend===`runner`?an(e,e.outputPath):U()}function tn(e,t){let n=un(e.processes),r=nn(e.recording);return!n||r===`invalid`?U():{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n,...r===void 0?{}:{recording:r}})}}function nn(e){if(e!==void 0)return n(e)&&rn(e)?Object.freeze(e):`invalid`}function rn(e){return B(e.outPath)&&sn(e.startedAt)&&on(e.clientOutPath)&&Me(e)}function an(e,t){return!B(e.appBundleId)||!B(e.runnerSessionId)||!cn(e.runnerAuthority)||!ln(e.remotePath)?U():{status:`decoded`,descriptor:Object.freeze({backend:`runner`,outputPath:t,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}})}}function B(e){return typeof e==`string`&&e.length>0}function on(e){return e===void 0||B(e)}function sn(e){return typeof e==`number`&&Number.isFinite(e)}function cn(e){return e===`local-lease`||e===`scoped-provider`}function ln(e){return e===void 0||V(e)}function V(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function H(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:s(e)?t.remotePath!==void 0&&V(t.remotePath):t.remotePath===void 0:!1}function un(e){if(!Array.isArray(e)||e.length===0)return;let t=e.filter(e=>typeof e==`object`&&!!e&&Number.isInteger(e.pid)&&(e.pid??0)>0&&typeof e.startTime==`string`&&e.startTime.length>0&&typeof e.command==`string`&&e.command.length>0);return t.length===e.length?Object.freeze([...t]):void 0}function U(){return{status:`invalid`,message:`Invalid Apple screen-recording descriptor`}}async function dn(e,t,n){if(e.kind!==`simulator`||t.scope!==`app`)return;let r=t.activeSessionApp?.bundleId;if(!r)throw TypeError(`App-scoped recording requires an active app session; open the app under test before recording.`);if(await n(r))throw TypeError(`App-scoped recording requires a real application session; open the app under test before recording.`)}const W=`iOS recording`,G=`simctl recordVideo`;function fn(e){return e.appleOs===`watchos`?l(`unsupported-platform-leaf`,`watchOS recording is not supported.`):s(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?l(`unsupported-device-backend`,`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`):Object.freeze({available:!0})}function pn(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await mn({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>{let r=await Yt({host:t,device:n,envelope:e.envelope});return r.status===`restore-export`?{status:`active`,handle:gn({host:t,restored:r})}:r},screenRecordingCleanup:async e=>await qt(t,n,e.envelope.descriptor.body,e.envelope.sessionId)})}async function mn(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await hn(e):await _n(e)}async function hn(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await dn(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a,i.requestId):void 0,s=oe(i.outputPath);await t.screenRecording.outputs.prepare(s);let c=await t.screenRecording.apple.startSimulator(n,s,a),l=c.markers;if(!l||l.length===0)throw await J(c).catch(()=>{}),Error(`simctl recordVideo did not expose durable process identity`);try{a.throwIfAborted(),t.screenRecording.ownedProcesses.replace({kind:`session`,sessionId:i.sessionId},l.map(e=>({...e,purpose:`simctl-screen-recording`})))}catch(e){try{t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId})}catch{}throw await J(c).catch(()=>{}),e}let u,d,f=async()=>{await c.terminate();let e=await c.wait;return d=e,u=yn(e),t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),{observation:{recorder:`confirmed`},...u===void 0?{}:{warning:`${u} before record stop; the video covers only what the recorder wrote before it stopped.`}}},p=Cn(i,G,{},o);return Sn({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:s,processes:l,recording:Kt(p)},snapshot:p,finish:(e,n)=>S({snapshot:e,progress:n,steps:{stop:f,collect:async e=>{try{await K(t,s,e)}catch(e){throw q(e,u,d)}},finalize:async({collectedPath:n,exportPath:r})=>{try{return await F({host:t,snapshot:e,targetLabel:W,collectedPath:n,exportPath:r,nativePath:s})}catch(e){throw q(e,u,d)}},discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),cleanup:async()=>{let e=await xn(c);return(e.status===`cleaned`||e.status===`already-missing`)&&t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),e}})}function gn(e){let{host:t,restored:{recording:n,nativePath:r,cleanup:i}}=e,a=Object.freeze({...n,backend:G,gestureEvents:[]});return y(a,{finish:(e,i)=>S({snapshot:e,progress:i,steps:{stop:async()=>({observation:{recorder:`confirmed`},warning:`simctl recordVideo had already ended when record stop reattached to it; the video covers only what the recorder wrote before it stopped.`}),collect:async e=>{await K(t,r,e)},finalize:async({collectedPath:i,exportPath:a})=>await F({host:t,snapshot:e,targetLabel:W,collectedPath:i,exportPath:a,nativePath:r,...n.showTouches?{overlayUnavailable:`the daemon that held the touch events ended before record stop`}:{}}),discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),forceCleanup:async()=>await i()})}async function K(e,t,n){await e.screenRecording.outputs.copy({from:t,to:n}),await e.screenRecording.finalize.sniff({outputPath:n})}async function _n(e){let{host:t,device:n,owner:r,input:i,signal:a}=e,o=i.activeSessionApp?.bundleId;if(!o)throw TypeError(`Apple runner recording requires an active app session identity`);await t.screenRecording.outputs.prepare(i.outputPath);let s=await t.screenRecording.apple.runRunner(n,{kind:`start`,appBundleId:o,outputPath:i.outputPath,...i.fps===void 0?{}:{fps:i.fps}},a);if(!s.runnerSessionId||!s.runnerAuthority)throw Error(`Apple runner recording did not expose durable session ownership`);let c={runnerSessionId:s.runnerSessionId,runnerAuthority:s.runnerAuthority},l,u=()=>(l??=vn(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0)).catch(e=>{throw l=void 0,e}),l);if(!bn(n,s.remotePath))throw await u().catch(()=>{}),Error(`Apple runner recording did not expose coherent durable media ownership`);try{a.throwIfAborted()}catch(e){throw await u().catch(()=>{}),e}return Sn({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:Cn(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await Ht({host:t,snapshot:e,targetLabel:n.appleOs===`macos`?`macOS recording`:`iOS recording`,stopObservation:{recorder:`confirmed`},...s.remotePath===void 0?{}:{nativePathDisposition:`retirable`}})),cleanup:async()=>(await u(),{status:`cleaned`})})}async function vn(e){try{return await e()}catch(e){throw t(e,`COMMAND_FAILED`)}}function yn(e){if(e.exitCode!==0)return e.signal?`simctl recordVideo was killed by ${e.signal}`:`simctl recordVideo exited with code ${e.exitCode}`}function q(n,i,a){let o=t(n,`COMMAND_FAILED`);return i===void 0||a===void 0||o.details?.reason!==`recording-output-unplayable`?n:new e(o.code,`${o.message}; ${i}`,r(a,{...o.details??{},...a.signal===void 0?{}:{signal:a.signal},retriable:!1,hint:`The recorder exited before record stop, so the next record stop reads the same file. Close this session to release the device, then record again.`}))}function bn(e,t){return e.appleOs===`macos`||!s(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function J(e){return await e.terminate(),await e.wait}async function xn(e){try{return await J(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function Sn(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:s}=e,c=y(a,{finish:o,forceCleanup:s});return Object.freeze({pendingHandle:new re(c),envelope:Gt({device:t,owner:n,input:r,descriptor:i})})}function Cn(e,t,n={},r){let i=Date.now();return Object.freeze({backend:t,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:i,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},...e.fps===void 0?{}:{fps:e.fps},gestureEvents:[],...r===void 0?{}:{gestureClockOriginAtMs:r.wallClockAtMs,gestureClockOriginUptimeMs:r.uptimeMs},...n.recorderStartUptimeMs===void 0?{}:{gestureClockOriginAtMs:i,gestureClockOriginUptimeMs:n.recorderStartUptimeMs,runnerStartedAtUptimeMs:n.recorderStartUptimeMs},...n.runnerSessionId===void 0?{}:{runnerSessionId:n.runnerSessionId}})}const Y=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`The native macOS app backend never starts the XCTest runner, which this command needs. Unset AGENT_DEVICE_MACOS_APP_BACKEND to use XCTest.`});function wn(e,t){return!a(e)||t!==`native`?{}:Object.freeze({screenRecordingStart:Y,screenRecordingReattach:Y,prepareAppleRunner:Y,longPressPoint:Y,...ue({back:Y}),...me({unsupported:Y})})}function Tn(e){let t,n=!1,r=async()=>(t??=import(`./host4.js`).then(e=>e.t).then(({createSnapshotSourceHost:t})=>import(`./adapter.js`).then(({createSimulatorSnapshotSource:n})=>n({host:t(e)}))),await t);return{acquire:async e=>n?{stage:`failed`,failure:{kind:`unsupported`,code:`source-closed`}}:await(await r()).acquire(e),close:async()=>{n=!0,t&&await(await t).close()}}}function En(e,t={}){let n=t.source??Tn(e.hostEnvironment),r=t.targets??qe(),i=Ze(async(t,n)=>await e.snapshot.presentIosAcquisition(t,n),{source:n,servesDevice:Xe,resolveTarget:r.resolveTarget,refreshTarget:r.refreshTarget,resolutionVerifiesIdentity:!0,awaitsDiscovery:async(t,n,r)=>Ke(t)&&!await e.appleApplications.hasLiveRunnerSession(n,r),observeOnlySupported:!0,circuit:{scope:`route`}},t.systemSurfaceForeground??nt()),a=$e({source:n,resolveTarget:r.resolveTarget,clock:e.clock,isBridgeDisabled:i.isBridgeDisabled});return Object.freeze({awaitObservable:a.awaitObservable,capture:i.capture,shutdown:i.shutdown})}const X=d(`apple`),Z=Object.freeze({available:!0}),Q=l(`unsupported-platform-leaf`),Dn=l(`unsupported-platform-leaf`,`viewport resizes web targets only (--platform web). Apple screen geometry is fixed by the selected simulator or device type — open a different simulator to test another screen size.`),On=l(`unsupported-platform-leaf`,`the stateless audio page probe is a web-session operation; Apple targets use the host capture.`),kn=l(`unsupported-device-backend`,`perf requires an Apple simulator, macOS device, or CoreDevice-backed physical Apple device.`),An=l(`unsupported-platform-leaf`,`telephony simulates calls and SMS through the Android emulator console; Apple simulators and devices expose no host control that injects a call or text message.`),jn=l(`unsupported-provider-mode`,`Headless boot is supported only for local Android emulators.`),Mn=l(`unsupported-platform-leaf`,`watchOS open is not supported because XCUITest cannot drive watchOS UI.`),Nn=l(`unsupported-platform-leaf`,`watchOS close is not supported because XCUITest cannot drive watchOS UI.`),Pn=l(`unsupported-device-kind`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),Fn=$(`open is supported only for Apple simulators and devices.`),In=$(`close is supported only for Apple simulators and devices.`),Ln=l(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),Rn=l(`unsupported-device-kind`,`shutdown is supported only for Apple simulators and Android emulators.`),zn=l(`unsupported-platform-leaf`,`screenshot is not supported on watchOS because XCUITest cannot drive watchOS UI.`),Bn=$(`screenshot is supported only for Apple simulators and devices.`);function $(e){return l(`unsupported-device-kind`,e)}function Vn(e){return!s(e)||e.appleOs===`watchos`?Q:e.kind===`simulator`?Z:Rn}function Hn(e){let t=Un(e),n=tt(e),r=Wn(e),i=Gn(e);return ne({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:Ln})}function Un(e){return i(e)===`watchos`?Mn:e.kind===`simulator`||e.kind===`device`?Z:Fn}function Wn(e){return i(e)===`watchos`?Nn:e.kind===`simulator`||e.kind===`device`?Z:In}function Gn(e){return i(e)!==`watchos`&&s(e)&&e.kind===`simulator`?Z:Pn}function Kn(e){return e.appleOs===`watchos`?l(`unsupported-platform-leaf`,`watchOS app inventory is not supported.`):e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?l(`unsupported-device-backend`,`App inventory is available only on CoreDevice-backed physical iOS devices.`):Z}function qn(e){let t=jt(e),n=En(e),r,i=t=>a(t)?r??=Ve(e.hostEnvironment.env):`xctest`,o=async n=>{let r=await t.inspectFacts(n),o=He(n),s=fn(n),c=s.available?await e.screenRecording.apple.availability(n):void 0,u=s.available&&c?.available===!1?l(`unsupported-provider-mode`,c.hint):s,d=n.appleOs===`watchos`?Q:Z,f=a(n)||n.appleOs===`watchos`?Q:Z,p=Kn(n);return Object.freeze({device:r.device,operations:{...r.operations,...o,networkDump:Z,screenRecordingStart:u,screenRecordingReattach:u,screenRecordingCleanup:u,...We(n),...ye({capture:Yn(n)}),...xe({setViewport:Dn}),...ze(n),sendTelephonyEvent:An,..._e({capture:st(n),query:On}),...ve(Jn(n)),ensureReady:d,bootTarget:f,bootTargetHeadless:jn,listApps:p,...Hn(n),shutdownTarget:Vn(n),...wn(n,i(n))}})};return Object.freeze({owner:X,ownsDevice:e=>e.platform===`apple`,inspectFacts:o,bind:async r=>{let s=await t.bind(r),c=await o(r.device),l=c.operations.screenRecordingStart,d=u(c.operations.appState,()=>Qe(e,{device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),p=u(c.operations.querySelector,()=>et({device:r.device,signal:r.scope.signal})),m={...d,...p,...s.operations,...it({host:e,device:r.device,signal:r.scope.signal}),networkDump:async t=>await Pt(e,r.device,t,r.scope.signal),...u(l,()=>pn({host:e,device:r.device,owner:X,signal:r.scope.signal})),...u(c.operations.audioProbeStart,()=>De({host:e.audioProbe.hostCapture,device:r.device,owner:X})),...u(c.operations.perfFrames,()=>ct({resolveHost:()=>e.perf.apple,device:r.device,owner:X})),...u(c.operations.captureSnapshot,()=>Ue(e,{device:r.device,signal:r.scope.signal,appBackend:i(r.device)},n)),...u(c.operations.captureScreenshot,()=>be({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve,captureCapabilities:e=>Be(r.device,e,a(r.device)?f(e.surface,i(r.device)):void 0)})),...u(c.operations.focusPoint,()=>ge({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...fe({device:r.device,signal:r.scope.signal,facts:c.operations,resolveInteractor:e.localInteractors.resolve}),...u(c.operations.scrollDirection,()=>pe({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...u(c.operations.typeText,()=>he({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...u(c.operations.tapPoint,()=>ae({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:c.operations,pause:async t=>await e.clock.sleep(t,r.scope.signal)})),...u(c.operations.readTextAtPoint,()=>de({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...u(c.operations.findText,()=>Je(e,{device:r.device,signal:r.scope.signal,appBackend:i(r.device)})),...rt({host:e,device:r.device,signal:r.scope.signal,admitted:c.operations}),...Ye({host:e,device:r.device,signal:r.scope.signal}),...Re({device:r.device,signal:r.scope.signal}),...u(c.operations.ensureReady,()=>({ensureReady:async()=>await at(e,r.device,r.scope.signal)})),...u(c.operations.bootTarget,()=>({bootTarget:async t=>await at(e,r.device,r.scope.signal,{deadlineAtMs:t.deadlineAtMs})})),...u(c.operations.listApps,()=>({listApps:async e=>{r.scope.signal.throwIfAborted();let{listIosApps:t}=await import(`./app-resolution.js`).then(e=>e.t);return(await t(e.device,e.filter)).map(e=>({id:e.bundleId,name:e.name}))}})),...te(Ge({host:e,device:r.device,signal:r.scope.signal,observation:n}),c.operations),...u(c.operations.shutdownTarget,()=>({shutdownTarget:async()=>await e.deviceShutdown.apple.shutdownTarget(r.device,r.scope.signal)}))};return Object.freeze({device:s.device,owner:X,facts:c,operations:Object.freeze(m),[Symbol.asyncDispose]:async()=>await s[Symbol.asyncDispose]()})},shutdown:async()=>{await Promise.all([t.shutdown(),n.shutdown()])}})}function Jn(e){let t=e.iosPhysicalDeviceBackend!==`xctest`&&i(e)!==`watchos`?Z:kn;return{frames:t,memorySample:t,memorySnapshot:t,nativeCapture:t,profileReport:t}}function Yn(e){return i(e)===`watchos`?zn:e.kind===`simulator`||e.kind===`device`?Z:Bn}export{qn as createApplePlatformRuntime};
|
|
3
|
+
`)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function Rt(e){let t=e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`);return[`subsystem == "${t}"`,`subsystem CONTAINS "${t}"`,`processImagePath ENDSWITH[c] "/${t}"`,`senderImagePath ENDSWITH[c] "/${t}"`].join(` OR `)}function zt(e,t){let n=t.entries.filter(e=>e.pathUnavailable).length,r=t.unnamedRequests??0,i=n+r;if(i===0)return;let a=[`${i} request${i===1?``:`s`} reused a keep-alive connection, so CFNetwork logged no request URL.`];n>0&&a.push(`${n} listed against the origin the connection was opened for, without a path.`),r>0&&a.push(`${r} opened before this scan window and are missing from the entries entirely; scan more lines, or run logs clear --restart before the repro.`),a.push(`Absence of an endpoint in this dump does not prove it was not called.`),e.push(a.join(` `))}function Bt(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(d(t)&&t.kind===`simulator`?`Session app log stream is inactive. The iOS simulator recovery path scanned recent simctl log history, but a fresh logs clear --restart window is still the most reliable repro loop.`:`Session app log stream is inactive. Run logs clear --restart, reproduce the request window again, then rerun network dump.`):e.push(`Capture uses the session app log file. For fresh traffic, run logs clear --restart before reproducing requests.`)}function Vt(e){return d(e)&&e.kind===`simulator`?`No HTTP(s) entries were found in recent iOS simulator app logs. If the app only emits non-HTTP diagnostics, inspect logs path or add app-side URLSession/network logging for per-request timing and payload details.`:d(e)?`No HTTP(s) entries were found in recent iOS device app logs. iOS network dump only sees what the app emits into Unified Logging for this process.`:`No HTTP(s) entries were found in recent session app logs.`}async function Ht(e){let{host:t,snapshot:n,targetLabel:r,recorderWarning:i,nativePathDisposition:o}=e,s=n.invalidatedReason?{recorder:`lost`,why:`owner-session-lost`}:e.stopObservation;if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let c;try{c=await t.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!n.invalidatedReason&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.fps===void 0?{}:{fps:n.fps},targetLabel:r})}catch(e){throw a(e,`COMMAND_FAILED`)}let l=[...c.warning?[c.warning]:[],...i?[i]:[]];return Ae(n,{...c,...l.length>0?{warning:l.join(` `)}:{},...n.invalidatedReason?{overlayWarning:`overlay unavailable: ${n.invalidatedReason}`}:{}},{stopObservation:s,...o===void 0?{}:{nativePathDisposition:o}})}async function F(e){let{host:t,snapshot:n,targetLabel:r,collectedPath:i,exportPath:a,nativePath:o}=e;if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let s=e.overlayUnavailable??n.invalidatedReason,c;try{await t.screenRecording.outputs.copy({from:i,to:a}),c=await Ut(()=>t.screenRecording.finalize.complete({outputPath:a,showTouches:s===void 0&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.fps===void 0?{}:{fps:n.fps},targetLabel:r}))}catch(e){throw await t.screenRecording.outputs.remove(a),e}return{...c,...s===void 0?{}:{overlayWarning:`overlay unavailable: ${s}`},nativePathDisposition:await t.screenRecording.outputs.remove(o)===`removed`?`retired`:`retirable`}}async function Ut(e){try{return await e()}catch(e){throw a(e,`COMMAND_FAILED`)}}const Wt=[`outPath`,`startedAt`,`clientOutPath`,...Pe],I=Object.freeze({resourceKind:ee,version:1,encode:e=>e.backend===`simctl`?{backend:e.backend,outputPath:e.outputPath,processes:e.processes.map(e=>({...e})),...e.recording===void 0?{}:{recording:{...e.recording}}}:{backend:e.backend,outputPath:e.outputPath,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}},decode:e=>en(e)});function Gt(e){let{device:t,owner:n,input:r,descriptor:i}=e;return m({resourceKind:ee,sessionId:r.sessionId,device:c(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:p(I,i)})}function Kt(e){let t={};for(let n of Wt)e[n]!==void 0&&Object.assign(t,{[n]:e[n]});return t}async function qt(e,t,n,r){let i=I.decode(n);return i.status!==`decoded`||!H(t,i.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:i.descriptor.backend===`simctl`?await L(e,i.descriptor.processes,r):await Jt(e,t,i.descriptor)}async function L(e,t,n){let r=await Promise.all(t.map(async t=>await e.screenRecording.apple.inspectProcess(t)));if(r.includes(`ownership-lost`))return{status:`cleanup-pending`,reason:`ownership-fence-lost`};if(r.every(e=>e===`missing`))return n!==void 0&&e.screenRecording.ownedProcesses.clear(R(n)),{status:`already-missing`};let i=await Promise.all(t.flatMap((t,n)=>r[n]===`owned-alive`?[e.screenRecording.apple.terminateProcess(t)]:[]));return i.includes(`ownership-lost`)?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:(n!==void 0&&e.screenRecording.ownedProcesses.clear(R(n)),i.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`})}function R(e){return{kind:`session`,sessionId:e}}async function Jt(e,t,n){try{let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`already-missing`}:r===`ownership-lost`?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:(await e.screenRecording.apple.runRunner(t,{kind:`stop`,appBundleId:n.appBundleId,runnerSessionId:n.runnerSessionId,runnerAuthority:n.runnerAuthority}),{status:`cleaned`})}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple recording cleanup failed`}}}async function Yt(e){let{host:t,device:n,envelope:r}=e,i=I.decode(r.descriptor.body);return i.status===`decoded`?H(n,i.descriptor)?i.descriptor.backend===`simctl`?await Xt(e,i.descriptor):await Qt(t,n,i.descriptor):z(`descriptor-invalid`,`Apple screen-recording descriptor does not match the bound device.`):z(`descriptor-invalid`,i.message)}async function Xt(e,t){let n=await Promise.all(t.processes.map(async t=>await e.host.screenRecording.apple.inspectProcess(t)));if(!n.every(e=>e===`missing`))return z(`transport-not-reattachable`,n.includes(`ownership-lost`)?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`);let{recording:r}=t,i=Zt(Ne(e.envelope.metadata),t.outputPath);return r===void 0||i!==void 0&&!await $t(e.host,i)?{status:`missing`}:{status:`restore-export`,recording:r,nativePath:t.outputPath,cleanup:async()=>await L(e.host,t.processes,e.envelope.sessionId)}}function Zt(e,t){if(e.finalization===void 0)return e.collectedPath??t}async function Qt(e,t,n){let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`missing`}:z(`transport-not-reattachable`,r===`ownership-lost`?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`)}async function $t(e,t){try{return await e.screenRecording.finalize.sniff({outputPath:t}),!0}catch{return!1}}function z(e,t){return{status:`unreattachable`,reason:e,message:t}}function en(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?U():e.backend===`simctl`?tn(e,e.outputPath):e.backend===`runner`?an(e,e.outputPath):U()}function tn(e,t){let n=un(e.processes),r=nn(e.recording);return!n||r===`invalid`?U():{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n,...r===void 0?{}:{recording:r}})}}function nn(e){if(e!==void 0)return o(e)&&rn(e)?Object.freeze(e):`invalid`}function rn(e){return B(e.outPath)&&sn(e.startedAt)&&on(e.clientOutPath)&&Me(e)}function an(e,t){return!B(e.appBundleId)||!B(e.runnerSessionId)||!cn(e.runnerAuthority)||!ln(e.remotePath)?U():{status:`decoded`,descriptor:Object.freeze({backend:`runner`,outputPath:t,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}})}}function B(e){return typeof e==`string`&&e.length>0}function on(e){return e===void 0||B(e)}function sn(e){return typeof e==`number`&&Number.isFinite(e)}function cn(e){return e===`local-lease`||e===`scoped-provider`}function ln(e){return e===void 0||V(e)}function V(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function H(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:d(e)?t.remotePath!==void 0&&V(t.remotePath):t.remotePath===void 0:!1}function un(e){if(!Array.isArray(e)||e.length===0)return;let t=e.filter(e=>typeof e==`object`&&!!e&&Number.isInteger(e.pid)&&(e.pid??0)>0&&typeof e.startTime==`string`&&e.startTime.length>0&&typeof e.command==`string`&&e.command.length>0);return t.length===e.length?Object.freeze([...t]):void 0}function U(){return{status:`invalid`,message:`Invalid Apple screen-recording descriptor`}}async function dn(e,t,n){if(e.kind!==`simulator`||t.scope!==`app`)return;let r=t.activeSessionApp?.bundleId;if(!r)throw TypeError(`App-scoped recording requires an active app session; open the app under test before recording.`);if(await n(r))throw TypeError(`App-scoped recording requires a real application session; open the app under test before recording.`)}const W=`iOS recording`,G=`simctl recordVideo`;function fn(e){return e.appleOs===`watchos`?n(`unsupported-platform-leaf`,`watchOS recording is not supported.`):d(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?n(`unsupported-device-backend`,`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`):Object.freeze({available:!0})}function pn(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await mn({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>{let r=await Yt({host:t,device:n,envelope:e.envelope});return r.status===`restore-export`?{status:`active`,handle:gn({host:t,restored:r})}:r},screenRecordingCleanup:async e=>await qt(t,n,e.envelope.descriptor.body,e.envelope.sessionId)})}async function mn(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await hn(e):await _n(e)}async function hn(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await dn(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a,i.requestId):void 0,s=oe(i.outputPath);await t.screenRecording.outputs.prepare(s);let c=await t.screenRecording.apple.startSimulator(n,s,a),l=c.markers;if(!l||l.length===0)throw await J(c).catch(()=>{}),Error(`simctl recordVideo did not expose durable process identity`);try{a.throwIfAborted(),t.screenRecording.ownedProcesses.replace({kind:`session`,sessionId:i.sessionId},l.map(e=>({...e,purpose:`simctl-screen-recording`})))}catch(e){try{t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId})}catch{}throw await J(c).catch(()=>{}),e}let u,d,f=async()=>{await c.terminate();let e=await c.wait;return d=e,u=yn(e),t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),{observation:{recorder:`confirmed`},...u===void 0?{}:{warning:`${u} before record stop; the video covers only what the recorder wrote before it stopped.`}}},p=Cn(i,G,{},o);return Sn({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:s,processes:l,recording:Kt(p)},snapshot:p,finish:(e,n)=>S({snapshot:e,progress:n,steps:{stop:f,collect:async e=>{try{await K(t,s,e)}catch(e){throw q(e,u,d)}},finalize:async({collectedPath:n,exportPath:r})=>{try{return await F({host:t,snapshot:e,targetLabel:W,collectedPath:n,exportPath:r,nativePath:s})}catch(e){throw q(e,u,d)}},discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),cleanup:async()=>{let e=await xn(c);return(e.status===`cleaned`||e.status===`already-missing`)&&t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),e}})}function gn(e){let{host:t,restored:{recording:n,nativePath:r,cleanup:i}}=e,a=Object.freeze({...n,backend:G,gestureEvents:[]});return y(a,{finish:(e,i)=>S({snapshot:e,progress:i,steps:{stop:async()=>({observation:{recorder:`confirmed`},warning:`simctl recordVideo had already ended when record stop reattached to it; the video covers only what the recorder wrote before it stopped.`}),collect:async e=>{await K(t,r,e)},finalize:async({collectedPath:i,exportPath:a})=>await F({host:t,snapshot:e,targetLabel:W,collectedPath:i,exportPath:a,nativePath:r,...n.showTouches?{overlayUnavailable:`the daemon that held the touch events ended before record stop`}:{}}),discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),forceCleanup:async()=>await i()})}async function K(e,t,n){await e.screenRecording.outputs.copy({from:t,to:n}),await e.screenRecording.finalize.sniff({outputPath:n})}async function _n(e){let{host:t,device:n,owner:r,input:i,signal:a}=e,o=i.activeSessionApp?.bundleId;if(!o)throw TypeError(`Apple runner recording requires an active app session identity`);await t.screenRecording.outputs.prepare(i.outputPath);let s=await t.screenRecording.apple.runRunner(n,{kind:`start`,appBundleId:o,outputPath:i.outputPath,...i.fps===void 0?{}:{fps:i.fps}},a);if(!s.runnerSessionId||!s.runnerAuthority)throw Error(`Apple runner recording did not expose durable session ownership`);let c={runnerSessionId:s.runnerSessionId,runnerAuthority:s.runnerAuthority},l,u=()=>(l??=vn(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0)).catch(e=>{throw l=void 0,e}),l);if(!bn(n,s.remotePath))throw await u().catch(()=>{}),Error(`Apple runner recording did not expose coherent durable media ownership`);try{a.throwIfAborted()}catch(e){throw await u().catch(()=>{}),e}return Sn({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:Cn(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await Ht({host:t,snapshot:e,targetLabel:n.appleOs===`macos`?`macOS recording`:`iOS recording`,stopObservation:{recorder:`confirmed`},...s.remotePath===void 0?{}:{nativePathDisposition:`retirable`}})),cleanup:async()=>(await u(),{status:`cleaned`})})}async function vn(e){try{return await e()}catch(e){throw a(e,`COMMAND_FAILED`)}}function yn(e){if(e.exitCode!==0)return e.signal?`simctl recordVideo was killed by ${e.signal}`:`simctl recordVideo exited with code ${e.exitCode}`}function q(e,t,n){let r=a(e,`COMMAND_FAILED`);return t===void 0||n===void 0||r.details?.reason!==`recording-output-unplayable`?e:new i(r.code,`${r.message}; ${t}`,s(n,{...r.details??{},...n.signal===void 0?{}:{signal:n.signal},retriable:!1,hint:`The recorder exited before record stop, so the next record stop reads the same file. Close this session to release the device, then record again.`}))}function bn(e,t){return e.appleOs===`macos`||!d(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function J(e){return await e.terminate(),await e.wait}async function xn(e){try{return await J(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function Sn(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:s}=e,c=y(a,{finish:o,forceCleanup:s});return Object.freeze({pendingHandle:new re(c),envelope:Gt({device:t,owner:n,input:r,descriptor:i})})}function Cn(e,t,n={},r){let i=Date.now();return Object.freeze({backend:t,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:i,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},...e.fps===void 0?{}:{fps:e.fps},gestureEvents:[],...r===void 0?{}:{gestureClockOriginAtMs:r.wallClockAtMs,gestureClockOriginUptimeMs:r.uptimeMs},...n.recorderStartUptimeMs===void 0?{}:{gestureClockOriginAtMs:i,gestureClockOriginUptimeMs:n.recorderStartUptimeMs,runnerStartedAtUptimeMs:n.recorderStartUptimeMs},...n.runnerSessionId===void 0?{}:{runnerSessionId:n.runnerSessionId}})}const Y=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`The native macOS app backend never starts the XCTest runner, which this command needs. Unset AGENT_DEVICE_MACOS_APP_BACKEND to use XCTest.`});function wn(e,t){return!l(e)||t!==`native`?{}:Object.freeze({screenRecordingStart:Y,screenRecordingReattach:Y,prepareAppleRunner:Y,longPressPoint:Y,...ue({back:Y}),...me({unsupported:Y})})}function Tn(e){let t,n=!1,r=async()=>(t??=import(`./host4.js`).then(e=>e.t).then(({createSnapshotSourceHost:t})=>import(`./adapter.js`).then(({createSimulatorSnapshotSource:n})=>n({host:t(e)}))),await t);return{acquire:async e=>n?{stage:`failed`,failure:{kind:`unsupported`,code:`source-closed`}}:await(await r()).acquire(e),close:async()=>{n=!0,t&&await(await t).close()}}}function En(e,t={}){let n=t.source??Tn(e.hostEnvironment),r=t.targets??qe(),i=Ze(async(t,n)=>await e.snapshot.presentIosAcquisition(t,n),{source:n,servesDevice:Xe,resolveTarget:r.resolveTarget,refreshTarget:r.refreshTarget,resolutionVerifiesIdentity:!0,awaitsDiscovery:async(t,n,r)=>Ke(t)&&!await e.appleApplications.hasLiveRunnerSession(n,r),observeOnlySupported:!0,circuit:{scope:`route`}},t.systemSurfaceForeground??nt()),a=$e({source:n,resolveTarget:r.resolveTarget,clock:e.clock,isBridgeDisabled:i.isBridgeDisabled});return Object.freeze({awaitObservable:a.awaitObservable,capture:i.capture,shutdown:i.shutdown})}const X=r(`apple`),Z=Object.freeze({available:!0}),Q=n(`unsupported-platform-leaf`),Dn=n(`unsupported-platform-leaf`,`viewport resizes web targets only (--platform web). Apple screen geometry is fixed by the selected simulator or device type — open a different simulator to test another screen size.`),On=n(`unsupported-platform-leaf`,`the stateless audio page probe is a web-session operation; Apple targets use the host capture.`),kn=n(`unsupported-device-backend`,`perf requires an Apple simulator, macOS device, or CoreDevice-backed physical Apple device.`),An=n(`unsupported-platform-leaf`,`telephony simulates calls and SMS through the Android emulator console; Apple simulators and devices expose no host control that injects a call or text message.`),jn=n(`unsupported-provider-mode`,`Headless boot is supported only for local Android emulators.`),Mn=n(`unsupported-platform-leaf`,`watchOS open is not supported because XCUITest cannot drive watchOS UI.`),Nn=n(`unsupported-platform-leaf`,`watchOS close is not supported because XCUITest cannot drive watchOS UI.`),Pn=n(`unsupported-device-kind`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),Fn=$(`open is supported only for Apple simulators and devices.`),In=$(`close is supported only for Apple simulators and devices.`),Ln=n(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),Rn=n(`unsupported-device-kind`,`shutdown is supported only for Apple simulators and Android emulators.`),zn=n(`unsupported-platform-leaf`,`screenshot is not supported on watchOS because XCUITest cannot drive watchOS UI.`),Bn=$(`screenshot is supported only for Apple simulators and devices.`);function $(e){return n(`unsupported-device-kind`,e)}function Vn(e){return!d(e)||e.appleOs===`watchos`?Q:e.kind===`simulator`?Z:Rn}function Hn(e){let t=Un(e),n=tt(e),r=Wn(e),i=Gn(e);return ne({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:Ln})}function Un(e){return u(e)===`watchos`?Mn:e.kind===`simulator`||e.kind===`device`?Z:Fn}function Wn(e){return u(e)===`watchos`?Nn:e.kind===`simulator`||e.kind===`device`?Z:In}function Gn(e){return u(e)!==`watchos`&&d(e)&&e.kind===`simulator`?Z:Pn}function Kn(e){return e.appleOs===`watchos`?n(`unsupported-platform-leaf`,`watchOS app inventory is not supported.`):e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?n(`unsupported-device-backend`,`App inventory is available only on CoreDevice-backed physical iOS devices.`):Z}function qn(e){let r=jt(e),i=En(e),a,o=t=>l(t)?a??=Ve(e.hostEnvironment.env):`xctest`,s=async t=>{let i=await r.inspectFacts(t),a=He(t),s=fn(t),c=s.available?await e.screenRecording.apple.availability(t):void 0,u=s.available&&c?.available===!1?n(`unsupported-provider-mode`,c.hint):s,d=t.appleOs===`watchos`?Q:Z,f=l(t)||t.appleOs===`watchos`?Q:Z,p=Kn(t);return Object.freeze({device:i.device,operations:{...i.operations,...a,networkDump:Z,screenRecordingStart:u,screenRecordingReattach:u,screenRecordingCleanup:u,...We(t),...ye({capture:Yn(t)}),...xe({setViewport:Dn}),...ze(t),sendTelephonyEvent:An,..._e({capture:st(t),query:On}),...ve(Jn(t)),ensureReady:d,bootTarget:f,bootTargetHeadless:jn,listApps:p,...Hn(t),shutdownTarget:Vn(t),...wn(t,o(t))}})};return Object.freeze({owner:X,ownsDevice:e=>e.platform===`apple`,inspectFacts:s,bind:async n=>{let a=await r.bind(n),c=await s(n.device),u=c.operations.screenRecordingStart,d=t(c.operations.appState,()=>Qe(e,{device:n.device,signal:n.scope.signal,resolveInteractor:e.localInteractors.resolve})),p=t(c.operations.querySelector,()=>et({device:n.device,signal:n.scope.signal})),m={...d,...p,...a.operations,...it({host:e,device:n.device,signal:n.scope.signal}),networkDump:async t=>await Pt(e,n.device,t,n.scope.signal),...t(u,()=>pn({host:e,device:n.device,owner:X,signal:n.scope.signal})),...t(c.operations.audioProbeStart,()=>De({host:e.audioProbe.hostCapture,device:n.device,owner:X})),...t(c.operations.perfFrames,()=>ct({resolveHost:()=>e.perf.apple,device:n.device,owner:X})),...t(c.operations.captureSnapshot,()=>Ue(e,{device:n.device,signal:n.scope.signal,appBackend:o(n.device)},i)),...t(c.operations.captureScreenshot,()=>be({device:n.device,signal:n.scope.signal,resolveInteractor:e.localInteractors.resolve,captureCapabilities:e=>Be(n.device,e,l(n.device)?f(e.surface,o(n.device)):void 0)})),...t(c.operations.focusPoint,()=>ge({device:n.device,signal:n.scope.signal,resolveInteractor:e.localInteractors.resolve})),...fe({device:n.device,signal:n.scope.signal,facts:c.operations,resolveInteractor:e.localInteractors.resolve}),...t(c.operations.scrollDirection,()=>pe({device:n.device,signal:n.scope.signal,resolveInteractor:e.localInteractors.resolve})),...t(c.operations.typeText,()=>he({device:n.device,signal:n.scope.signal,resolveInteractor:e.localInteractors.resolve})),...t(c.operations.tapPoint,()=>ae({device:n.device,signal:n.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:c.operations,pause:async t=>await e.clock.sleep(t,n.scope.signal)})),...t(c.operations.readTextAtPoint,()=>de({device:n.device,signal:n.scope.signal,resolveInteractor:e.localInteractors.resolve})),...t(c.operations.findText,()=>Je(e,{device:n.device,signal:n.scope.signal,appBackend:o(n.device)})),...rt({host:e,device:n.device,signal:n.scope.signal,admitted:c.operations}),...Ye({host:e,device:n.device,signal:n.scope.signal}),...Re({device:n.device,signal:n.scope.signal}),...t(c.operations.ensureReady,()=>({ensureReady:async()=>await at(e,n.device,n.scope.signal)})),...t(c.operations.bootTarget,()=>({bootTarget:async t=>await at(e,n.device,n.scope.signal,{deadlineAtMs:t.deadlineAtMs})})),...t(c.operations.listApps,()=>({listApps:async e=>{n.scope.signal.throwIfAborted();let{listIosApps:t}=await import(`./app-resolution.js`).then(e=>e.t);return(await t(e.device,e.filter)).map(e=>({id:e.bundleId,name:e.name}))}})),...te(Ge({host:e,device:n.device,signal:n.scope.signal,observation:i}),c.operations),...t(c.operations.shutdownTarget,()=>({shutdownTarget:async()=>await e.deviceShutdown.apple.shutdownTarget(n.device,n.scope.signal)}))};return Object.freeze({device:a.device,owner:X,facts:c,operations:Object.freeze(m),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>{await Promise.all([r.shutdown(),i.shutdown()])}})}function Jn(e){let t=e.iosPhysicalDeviceBackend!==`xctest`&&u(e)!==`watchos`?Z:kn;return{frames:t,memorySample:t,memorySnapshot:t,nativeCapture:t,profileReport:t}}function Yn(e){return u(e)===`watchos`?zn:e.kind===`simulator`||e.kind===`device`?Z:Bn}export{qn as createApplePlatformRuntime};
|
package/dist/src/runtime8.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{z as e}from"./sdk-contracts.js";import{w as t}from"./sdk-device.js";import{s as n}from"./simctl.js";import{t as r}from"./simulator-state.js";const i=15e3;function a(e){return Object.freeze({canShutdownTarget:o,shutdownTarget:async(t,n)=>await s(e.appleTools,t,n)})}function o(e){return t(e)&&e.appleOs!==`watchos`&&e.kind===`simulator`}async function s(t,r,a){a.throwIfAborted();try{let e=await t.run({tool:`simctl`,args:n(r,[`shutdown`,r.id]),allowFailure:!0,timeoutMs:i},a);a.throwIfAborted();let o=l(e);return o.success?o:await c(t,r,a)===`Shutdown`?{...o,success:!0,exitCode:0}:o}catch(t){a.throwIfAborted();let n=e(t);return{success:!1,exitCode:-1,stdout:``,stderr:n.message,error:n}}}async function c(e,t,n){try{return await r(e,t,n,i)}catch{return n.throwIfAborted(),null}}function l(e){let t=e.exitCode??-1;return{success:t===0,exitCode:t,stdout:e.stdout,stderr:e.stderr}}export{a as createAppleShutdownRuntime};
|
package/dist/src/runtime9.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{P as e}from"./sdk-contracts.js";import{q as t}from"./sdk-device.js";import{On as n,kn as r,xn as i}from"./sdk-batch.js";import{n as a}from"./device-shell.js";import{a as o,r as s}from"./durable-resource.js";import{n as c}from"./screen-recording-runtime.js";import{n as l,t as u}from"./application-lifecycle-runtime.js";import{n as d}from"./async-lifecycle.js";import{i as f}from"./touch-runtime.js";import{r as p}from"./gesture-admission.js";import{i as m,n as h}from"./perf-runtime-operation-builder.js";import{C as g,D as _,F as ee,M as te,O as ne,R as re,V as ie,W as ae,_ as oe,j as se,l as ce,o as le,p as ue,r as de,v as fe,x as pe}from"./tv-remote-runtime.js";import{n as me}from"./audio-probe-runtime.js";import{n as he}from"./perf-runtime.js";import{a as ge,i as _e}from"./screenshot-runtime2.js";import{t as ve}from"./viewport-runtime.js";import{r as ye,u as v}from"./application-lifecycle-interaction.js";import{t as y}from"./local-interactor-operation-set.js";import{n as b,t as x}from"./src10.js";import{n as S,t as C}from"./screen-recording-completion.js";import{t as w}from"./screen-recording-options.js";import{t as T}from"./app-log-runtime.js";import{randomUUID as E}from"node:crypto";import{setTimeout as D}from"node:timers/promises";const O=Object.freeze({resourceKind:T,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!A(e.outputPath)||!A(e.pidPath)?{status:`invalid`,message:`Invalid HarmonyOS app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:`harmony-hilog`,outputPath:e.outputPath,pidPath:e.pidPath})}});function k(e){return s({resourceKind:T,sessionId:e.sessionId,device:{id:e.device.id,family:`harmonyos`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:o(O,e.descriptor)})}function A(e){return typeof e==`string`&&e.trim().length>0}function j(e){return x(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:O,startUnavailableHint:`The selected HarmonyOS transport cannot start a background hilog stream.`,cleanupFailureMessage:`HarmonyOS app-log cleanup did not settle every owned resource`,doctor:async(e,t)=>({backend:`harmonyos`,checks:{},notes:t?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}),process:async({host:e,device:t,input:n,signal:r})=>{let i=await M(e,r);return{resolvePid:async r=>await b(e,{executable:i,args:a(`hdc`,`shell`,[`pidof`,n.appBundleId],[`-t`,t.id]),allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:i,args:a(`hdc`,`shell`,[`hilog`,`-P`,e],[`-t`,t.id]),allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>k({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function M(t,n){n.throwIfAborted(),await N(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await N(async()=>await t.commands.which(`hdc`),n);if(n.throwIfAborted(),!r)throw new e(`TOOL_MISSING`,`hdc not found in PATH`,{hint:`Install HarmonyOS Command Line Tools, then add its sdk/default/openharmony/toolchains directory to PATH.`});return r}async function N(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}function P(e){let{resolveHost:t,device:n}=e,r={available:!1,reason:`Dropped-frame sampling is currently available only on Android app sessions and connected iOS device app sessions.`};return Object.freeze({perfFrames:async()=>({metric:r,sampling:r}),perfMemorySample:async({appId:e})=>({metric:e?await m(t().sampleMemory(n,e)):h(`HarmonyOS`,`bundle`),sampling:{method:`hdc-shell-proc-status`,description:`Resident memory snapshot from HarmonyOS /proc/<pid>/status. Values are reported in kilobytes.`,unit:`kB`,topConsumerLimit:1}}),perfMemorySnapshot:async({kind:e})=>({artifact:{available:!1,kind:e??`memgraph`,reason:`Memory snapshot artifacts are not supported on harmonyos.`,hint:`Use perf memory sample where supported, or run the snapshot against Android, iOS simulator, or macOS.`,support:{platform:`harmonyos`,defaultKind:`memgraph`,androidHprof:!1,memgraph:!1,heapprofd:!1}},sampling:{method:`unsupported`,description:`HarmonyOS memory snapshot capture is not available through HDC.`,artifactOnly:!0}})})}const F=Object.freeze({resourceKind:c,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&Se(e.fileName)&&e.remotePath===`/data/local/tmp/${e.fileName}`?{status:`decoded`,descriptor:Object.freeze({backend:`harmony-screen-recorder`,fileName:e.fileName,remotePath:e.remotePath})}:{status:`invalid`,message:`Invalid HarmonyOS screen-recording descriptor`}});function be(e){let{device:n,owner:r,input:i,descriptor:a}=e;return s({resourceKind:c,sessionId:i.sessionId,device:t(n),owner:r,fence:i.fence,lifecycle:`open`,descriptor:o(F,a)})}function xe(e){return F.decode(e).status===`decoded`?{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`HarmonyOS recorder ownership cannot be proven after daemon restart; no recorder was stopped.`}:{status:`cleanup-pending`,reason:`manual-recovery-required`}}function Se(e){return/^agent-device-recording-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.mp4$/i.test(e)}function Ce(e){return e.kind===`device`?Object.freeze({available:!0}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS recording is supported on physical devices only.`})}function we(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await Te({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async()=>({status:`unreattachable`,reason:`transport-not-reattachable`,message:`HarmonyOS recordings cannot be reattached after daemon restart.`}),screenRecordingCleanup:async e=>xe(e.envelope.descriptor.body)})}async function Te(t){let{host:n,device:r,owner:i,input:a,signal:o}=t;if(a.scope===`app`)throw new e(`INVALID_ARGS`,`HarmonyOS recording captures the whole physical-device screen; use --scope device or --scope system`);w(a,{scopes:[`device`,`system`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`HarmonyOS recordings do not support ${e.join(`, `)}`),o.throwIfAborted(),await n.screenRecording.outputs.prepare(a.outputPath);let s=`agent-device-recording-${E()}.mp4`,c={backend:`harmony-screen-recorder`,fileName:s,remotePath:`/data/local/tmp/${s}`},l;try{l=await n.screenRecording.harmony.start(r,s,o),o.throwIfAborted()}catch(e){throw o.aborted?(await L(n,r,c).catch(()=>{}),o.reason):e}z(l,`start`);try{o.throwIfAborted()}catch(e){throw await L(n,r,c).catch(()=>{}),e}let u=Ee(a),f=!1,p=async()=>{f||=(z(await n.screenRecording.harmony.stop(r),`stop`),!0)},m=S(u,{finish:async e=>await De(n,r,e,c,p),forceCleanup:async()=>await L(n,r,c,p)});return Object.freeze({pendingHandle:new d(m),envelope:be({device:r,owner:i,input:a,descriptor:c})})}function Ee(e){return Object.freeze({backend:`HarmonyOS ScreenRecorder`,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:Date.now(),scope:e.scope,showTouches:!1,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},gestureEvents:[]})}async function De(e,t,n,r,i){await i();let a=await e.screenRecording.harmony.findMedia(t,r.fileName);if(!a)throw Error(`failed to find finalized HarmonyOS recording '${r.fileName}'`);if(!await Ae(e,t,r,a))throw Error(`failed to finalize HarmonyOS recording: ${r.fileName} did not produce a non-empty media file`);try{if((await e.screenRecording.harmony.pull(t,{remotePath:r.remotePath,outputPath:n.outPath})).exitCode!==0)throw Error(`failed to retrieve HarmonyOS recording`);let i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!1,gestureEvents:n.gestureEvents,targetLabel:`HarmonyOS recording`}),o=await Oe(e,t,r,a);return C(n,{...i,...ke(i.warning,o)},{stopObservation:{recorder:`confirmed`},nativePathDisposition:o===void 0?`retired`:`retirable`,showTouches:!1})}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function Oe(e,t,n,r){let i=[];return await I(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await I(()=>e.screenRecording.harmony.removeMedia(t,r))||i.push(`media-library artifact`),i.length===0?void 0:`HarmonyOS recording completed, but cleanup was not confirmed for the ${i.join(` and `)}.`}async function I(e){try{return await e()}catch{return!1}}function ke(e,t){let n=[e,t].filter(e=>e!==void 0).join(` `);return n.length===0?{}:{warning:n}}async function Ae(e,t,n,r){let i;for(let a=0;a<40;a+=1){if(await e.screenRecording.harmony.remove(t,n.remotePath).catch(()=>{}),await e.screenRecording.harmony.stageMedia(t,{mediaUri:r,remotePath:n.remotePath})){let r=await e.screenRecording.harmony.stagedFileSize(t,n.remotePath);if(r!==void 0&&r>0&&r===i)return!0;i=r!==void 0&&r>0?r:void 0}else i=void 0;a<39&&await e.clock.sleep(250)}return!1}async function L(e,t,n,r=async()=>{z(await e.screenRecording.harmony.stop(t),`stop`)}){let i=[await R(r),await R(async()=>{if(!await e.screenRecording.harmony.remove(t,n.remotePath))throw Error(`HarmonyOS recording staging artifact removal was not confirmed`)}),await R(async()=>await je(e,t,n.fileName))].find(e=>e!==void 0);return i===void 0?{status:`cleaned`}:{status:`cleanup-pending`,reason:`transport-failed`,message:i instanceof Error?i.message:`HarmonyOS recording cleanup failed`}}async function je(e,t,n){let r=await e.screenRecording.harmony.findMedia(t,n);if(r&&!await e.screenRecording.harmony.removeMedia(t,r))throw Error(`HarmonyOS recording media removal was not confirmed`)}async function R(e){try{await e();return}catch(e){return e}}function z(e,t){if(e.exitCode===0&&e.stdout.includes(`start ability successfully`))return;let n=e.stdout.trim()||e.stderr.trim()||`hdc exit ${e.exitCode}`;throw Error(`failed to ${t} HarmonyOS screen recording: ${n}`)}async function Me(t,n){n.throwIfAborted();let{runHarmonyShell:r}=await import(`./hdc.js`),i=await r(t,[`aa`,`dump`,`-l`],{timeoutMs:15e3,signal:n});n.throwIfAborted();let a=Ne(i.stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine the foreground HarmonyOS app`,{hint:`Open an app on the target, then retry appstate.`});return a}function Ne(e){let t=e.split(/(?=^\s*Mission ID #)/m);for(let e of t){if(!/\bstate #FOREGROUND\b/.test(e))continue;let t=e.match(/mission name #\[#([^:]+):[^:]*:([^\]]+)]/);if(!t)continue;let[,n,r]=t;if(!(!n||!r))return{package:n,activity:r}}}const Pe=Object.freeze({available:!0}),Fe=Object.freeze({available:!1,reason:`unsupported-device-kind`}),B=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function V(e){let t=e.kind===`emulator`||e.kind===`device`?Pe:Fe;return Object.freeze({deployApp:t,materializeAppSource:B,deployMaterializedApp:B,sendPushNotification:B,uninstallApp:B})}function Ie(e){return V(e.device).deployApp.available?Object.freeze({deployApp:async t=>await Le(e.commands,e.device,t,e.signal)}):Object.freeze({})}async function Le(t,n,r,i){let a=await Re(t,r.appPath,i)??r.app.trim();if(!a)throw new e(`INVALID_ARGS`,`Could not determine the bundle name from the HAP archive`,{hint:`Pass the HarmonyOS bundle name before the HAP path, or provide a valid HAP containing module.json.`});return await Ve(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await D(1e3,void 0,{signal:i}),await ze(t,n,a,i)),{packageName:a,launchTarget:a}}async function Re(e,t,n){let r=await e.run({executable:`unzip`,args:[`-p`,t,`module.json`],allowFailure:!0,timeoutMs:15e3},n);if(r.exitCode===0&&r.stdout.trim().length!==0)try{return JSON.parse(r.stdout).app?.bundleName?.trim()||void 0}catch{return}}async function ze(t,n,r,i){let a=Be((await H(t,n,[`bm`,`dump`,`-n`,r],i)).stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine a launchable ability for ${r}`,{hint:`Check that the HarmonyOS bundle exposes a main ability.`});await H(t,n,[`aa`,`start`,`-b`,r,...a.module?[`-m`,a.module]:[],`-a`,a.ability],i)}function Be(e){let t=e.indexOf(`{`);if(t!==-1)try{let n=JSON.parse(e.slice(t)).hapModuleInfos?.find(e=>e.mainElementName);return n?.mainElementName?{ability:n.mainElementName,...n.moduleName?{module:n.moduleName}:{}}:void 0}catch{return}}async function Ve(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}async function H(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:a(`hdc`,`shell`,n,[`-t`,t.id]),timeoutMs:i},r)}const U=i(`harmonyos`),He=n(`unsupported-platform-leaf`,`HarmonyOS reads element text from the captured tree only.`),Ue=n(`unsupported-device-kind`,`focus is supported on HarmonyOS emulators and physical devices.`),W=Object.freeze({available:!0}),G=n(`unsupported-platform-leaf`),We=n(`unsupported-device-kind`,`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`),Ge=n(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),K=Object.freeze({available:!0}),Ke=n(`unsupported-device-kind`,`open is supported only for HarmonyOS emulators and devices.`),qe=n(`unsupported-device-kind`,`close is supported only for HarmonyOS emulators and devices.`),Je=n(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),q=n(`unsupported-device-kind`,`snapshot is supported only for HarmonyOS emulators and devices.`),Ye=n(`unsupported-device-kind`,`screenshot is supported only for HarmonyOS emulators and devices.`),Xe=n(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),Ze=n(`unsupported-platform-leaf`,`viewport resizes web targets only (--platform web).`);function Qe(e){let t=$e(e),n=J(e);return u({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:G,clearRuntimeHints:G,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Ge,configureProviderPortReverse:Je})}function $e(e){return e.kind===`emulator`||e.kind===`device`?K:Ke}function J(e){return e.kind===`emulator`||e.kind===`device`?K:qe}const Y=n(`unsupported-device-kind`,`Gestures are supported on HarmonyOS emulators and physical devices.`),et=n(`unsupported-platform-leaf`),tt=n(`unsupported-platform-leaf`,p);function X(e){return e.kind===`emulator`||e.kind===`device`?W:Y}function Z(e){return e.kind===`emulator`||e.kind===`device`?W:Ue}const Q=n(`unsupported-platform-leaf`),nt=n(`unsupported-platform-leaf`,`HarmonyOS supports settings clear-app-state only.`),rt=n(`unsupported-platform-leaf`,`keyboard status/get is not available through the public HarmonyOS HDC API; use keyboard dismiss or enter`),$=n(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function it(e){let t=j(e),n=async e=>{let n=await t.inspectFacts(e),r=V(e),i=Ce(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?We:W,networkDump:G,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,...se({capture:e.kind===`emulator`||e.kind===`device`?W:q,customActions:Xe,withoutActiveApp:e.kind===`emulator`||e.kind===`device`?W:q}),...ge({capture:e.kind===`emulator`||e.kind===`device`?W:Ye}),...te({findText:q,querySelector:q}),...ve({setViewport:Ze}),...ie({focus:Z(e)}),...re({unsupported:Y,plan:X(e),directionalFling:X(e),multiTouch:et,targetAuthoredDrag:tt,viewport:X(e)}),...ee({scroll:X(e)}),..._({type:Z(e)}),...f({unsupported:G,tap:Z(e),longPress:Z(e),fill:Z(e)}),...ae({readTextAtPoint:He}),...g({back:Z(e)}),...oe({unsupported:Q,home:Z(e),appSwitcher:Z(e)}),setFoldPose:Q,sendTelephonyEvent:Q,...fe({triggerAppEvent:Q}),...v({target:Z(e),unsupported:nt,write:{"clear-app-state":W}}),...pe({read:Q,wait:Q,accept:Q,dismiss:Q}),...le({orientation:Q}),...de({tvRemote:Q}),...ce({unsupported:Q,status:rt,dismiss:Z(e),enter:Z(e)}),...ue({unsupported:Q}),...me({capture:$,query:$}),...he({frames:Z(e),memorySample:Z(e),memorySnapshot:Z(e),nativeCapture:Q,profileReport:Q}),ensureReady:W,bootTarget:G,bootTargetHeadless:G,listApps:W,...Qe(e),shutdownTarget:G}})};return Object.freeze({owner:U,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:n,bind:async i=>{let a=await t.bind(i),o=await n(i.device),s=o.operations.screenRecordingStart;return Object.freeze({device:a.device,owner:U,facts:o,operations:Object.freeze({...a.operations,...Ie({commands:e.commands,device:i.device,signal:i.scope.signal}),...o.operations.appState.available?{appState:async()=>await Me(i.device,i.scope.signal)}:{},ensureReady:async()=>({...i.device,booted:!0}),...s.available?we({host:e,device:i.device,owner:U,signal:i.scope.signal}):{},...o.operations.captureSnapshot.available?ne({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...y({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:o.operations,captureCapabilities:_e(`a HarmonyOS device captures through hdc`),pause:async t=>await e.clock.sleep(t,i.scope.signal)}),...r(o.operations.perfFrames,()=>P({resolveHost:()=>e.perf.harmony,device:i.device})),listApps:async e=>{i.scope.signal.throwIfAborted();let{listHarmonyApps:t}=await import(`./app-lifecycle2.js`);return(await t(e.device,e.filter,{signal:i.scope.signal})).map(e=>({id:e.package,name:e.name}))},...l(ye({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,host:e.localInteractors,device:i.device,signal:i.scope.signal}),o.operations)}),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{it as createHarmonyPlatformRuntime};
|
|
1
|
+
import{Mn as e,jn as t,wn as n}from"./sdk-batch.js";import{_ as r}from"./sdk-contracts.js";import{Z as i}from"./sdk-io.js";import{J as a}from"./sdk-device.js";import"./command.js";import{n as o}from"./device-shell.js";import{a as s,r as c}from"./durable-resource.js";import{n as l}from"./screen-recording-runtime.js";import{n as u,t as d}from"./application-lifecycle-runtime.js";import{n as f}from"./async-lifecycle.js";import{i as p}from"./touch-runtime.js";import{r as m}from"./gesture-admission.js";import{i as h,n as g}from"./perf-runtime-operation-builder.js";import{C as ee,D as te,F as ne,M as re,O as ie,R as ae,V as oe,W as se,_ as ce,j as le,l as ue,o as de,p as fe,r as pe,v as me,x as he}from"./tv-remote-runtime.js";import{n as ge}from"./audio-probe-runtime.js";import{n as _e}from"./perf-runtime.js";import{a as ve,i as ye}from"./screenshot-runtime2.js";import{t as be}from"./viewport-runtime.js";import{r as xe,u as _}from"./application-lifecycle-interaction.js";import{t as v}from"./local-interactor-operation-set.js";import{n as y,t as b}from"./src10.js";import{n as x,t as S}from"./screen-recording-completion.js";import{t as C}from"./screen-recording-options.js";import{t as w}from"./app-log-runtime.js";import{n as T,r as E}from"./app-lifecycle2.js";import{randomUUID as D}from"node:crypto";import{setTimeout as O}from"node:timers/promises";const k=Object.freeze({resourceKind:w,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!j(e.outputPath)||!j(e.pidPath)?{status:`invalid`,message:`Invalid HarmonyOS app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:`harmony-hilog`,outputPath:e.outputPath,pidPath:e.pidPath})}});function A(e){return c({resourceKind:w,sessionId:e.sessionId,device:{id:e.device.id,family:`harmonyos`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:s(k,e.descriptor)})}function j(e){return typeof e==`string`&&e.trim().length>0}function M(e){return b(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:k,startUnavailableHint:`The selected HarmonyOS transport cannot start a background hilog stream.`,cleanupFailureMessage:`HarmonyOS app-log cleanup did not settle every owned resource`,doctor:async(e,t)=>({backend:`harmonyos`,checks:{},notes:t?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}),process:async({host:e,device:t,input:n,signal:r})=>{let i=await Se(e,r);return{resolvePid:async r=>await y(e,{executable:i,args:o(`hdc`,`shell`,[`pidof`,n.appBundleId],[`-t`,t.id]),allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:i,args:o(`hdc`,`shell`,[`hilog`,`-P`,e],[`-t`,t.id]),allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>A({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function Se(e,t){t.throwIfAborted(),await N(async()=>await e.toolchains.prepare(`harmonyos`),t),t.throwIfAborted();let n=await N(async()=>await e.commands.which(`hdc`),t);if(t.throwIfAborted(),!n)throw new r(`TOOL_MISSING`,`hdc not found in PATH`,{hint:`Install HarmonyOS Command Line Tools, then add its sdk/default/openharmony/toolchains directory to PATH.`});return n}async function N(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}function Ce(e){let{resolveHost:t,device:n}=e,r={available:!1,reason:`Dropped-frame sampling is currently available only on Android app sessions and connected iOS device app sessions.`};return Object.freeze({perfFrames:async()=>({metric:r,sampling:r}),perfMemorySample:async({appId:e})=>({metric:e?await h(t().sampleMemory(n,e)):g(`HarmonyOS`,`bundle`),sampling:{method:`hdc-shell-proc-status`,description:`Resident memory snapshot from HarmonyOS /proc/<pid>/status. Values are reported in kilobytes.`,unit:`kB`,topConsumerLimit:1}}),perfMemorySnapshot:async({kind:e})=>({artifact:{available:!1,kind:e??`memgraph`,reason:`Memory snapshot artifacts are not supported on harmonyos.`,hint:`Use perf memory sample where supported, or run the snapshot against Android, iOS simulator, or macOS.`,support:{platform:`harmonyos`,defaultKind:`memgraph`,androidHprof:!1,memgraph:!1,heapprofd:!1}},sampling:{method:`unsupported`,description:`HarmonyOS memory snapshot capture is not available through HDC.`,artifactOnly:!0}})})}const P=Object.freeze({resourceKind:l,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&Ee(e.fileName)&&e.remotePath===`/data/local/tmp/${e.fileName}`?{status:`decoded`,descriptor:Object.freeze({backend:`harmony-screen-recorder`,fileName:e.fileName,remotePath:e.remotePath})}:{status:`invalid`,message:`Invalid HarmonyOS screen-recording descriptor`}});function we(e){let{device:t,owner:n,input:r,descriptor:i}=e;return c({resourceKind:l,sessionId:r.sessionId,device:a(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:s(P,i)})}function Te(e){return P.decode(e).status===`decoded`?{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`HarmonyOS recorder ownership cannot be proven after daemon restart; no recorder was stopped.`}:{status:`cleanup-pending`,reason:`manual-recovery-required`}}function Ee(e){return/^agent-device-recording-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.mp4$/i.test(e)}function De(e){return e.kind===`device`?Object.freeze({available:!0}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS recording is supported on physical devices only.`})}function Oe(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await ke({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async()=>({status:`unreattachable`,reason:`transport-not-reattachable`,message:`HarmonyOS recordings cannot be reattached after daemon restart.`}),screenRecordingCleanup:async e=>Te(e.envelope.descriptor.body)})}async function ke(e){let{host:t,device:n,owner:i,input:a,signal:o}=e;if(a.scope===`app`)throw new r(`INVALID_ARGS`,`HarmonyOS recording captures the whole physical-device screen; use --scope device or --scope system`);C(a,{scopes:[`device`,`system`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`HarmonyOS recordings do not support ${e.join(`, `)}`),o.throwIfAborted(),await t.screenRecording.outputs.prepare(a.outputPath);let s=`agent-device-recording-${D()}.mp4`,c={backend:`harmony-screen-recorder`,fileName:s,remotePath:`/data/local/tmp/${s}`},l;try{l=await t.screenRecording.harmony.start(n,s,o),o.throwIfAborted()}catch(e){throw o.aborted?(await I(t,n,c).catch(()=>{}),o.reason):e}R(l,`start`);try{o.throwIfAborted()}catch(e){throw await I(t,n,c).catch(()=>{}),e}let u=Ae(a),d=!1,p=async()=>{d||=(R(await t.screenRecording.harmony.stop(n),`stop`),!0)},m=x(u,{finish:async e=>await je(t,n,e,c,p),forceCleanup:async()=>await I(t,n,c,p)});return Object.freeze({pendingHandle:new f(m),envelope:we({device:n,owner:i,input:a,descriptor:c})})}function Ae(e){return Object.freeze({backend:`HarmonyOS ScreenRecorder`,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:Date.now(),scope:e.scope,showTouches:!1,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},gestureEvents:[]})}async function je(e,t,n,r,i){await i();let a=await e.screenRecording.harmony.findMedia(t,r.fileName);if(!a)throw Error(`failed to find finalized HarmonyOS recording '${r.fileName}'`);if(!await Pe(e,t,r,a))throw Error(`failed to finalize HarmonyOS recording: ${r.fileName} did not produce a non-empty media file`);try{if((await e.screenRecording.harmony.pull(t,{remotePath:r.remotePath,outputPath:n.outPath})).exitCode!==0)throw Error(`failed to retrieve HarmonyOS recording`);let i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!1,gestureEvents:n.gestureEvents,targetLabel:`HarmonyOS recording`}),o=await Me(e,t,r,a);return S(n,{...i,...Ne(i.warning,o)},{stopObservation:{recorder:`confirmed`},nativePathDisposition:o===void 0?`retired`:`retirable`,showTouches:!1})}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function Me(e,t,n,r){let i=[];return await F(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await F(()=>e.screenRecording.harmony.removeMedia(t,r))||i.push(`media-library artifact`),i.length===0?void 0:`HarmonyOS recording completed, but cleanup was not confirmed for the ${i.join(` and `)}.`}async function F(e){try{return await e()}catch{return!1}}function Ne(e,t){let n=[e,t].filter(e=>e!==void 0).join(` `);return n.length===0?{}:{warning:n}}async function Pe(e,t,n,r){let i;for(let a=0;a<40;a+=1){if(await e.screenRecording.harmony.remove(t,n.remotePath).catch(()=>{}),await e.screenRecording.harmony.stageMedia(t,{mediaUri:r,remotePath:n.remotePath})){let r=await e.screenRecording.harmony.stagedFileSize(t,n.remotePath);if(r!==void 0&&r>0&&r===i)return!0;i=r!==void 0&&r>0?r:void 0}else i=void 0;a<39&&await e.clock.sleep(250)}return!1}async function I(e,t,n,r=async()=>{R(await e.screenRecording.harmony.stop(t),`stop`)}){let i=[await L(r),await L(async()=>{if(!await e.screenRecording.harmony.remove(t,n.remotePath))throw Error(`HarmonyOS recording staging artifact removal was not confirmed`)}),await L(async()=>await Fe(e,t,n.fileName))].find(e=>e!==void 0);return i===void 0?{status:`cleaned`}:{status:`cleanup-pending`,reason:`transport-failed`,message:i instanceof Error?i.message:`HarmonyOS recording cleanup failed`}}async function Fe(e,t,n){let r=await e.screenRecording.harmony.findMedia(t,n);if(r&&!await e.screenRecording.harmony.removeMedia(t,r))throw Error(`HarmonyOS recording media removal was not confirmed`)}async function L(e){try{await e();return}catch(e){return e}}function R(e,t){if(e.exitCode===0&&e.stdout.includes(`start ability successfully`))return;let n=e.stdout.trim()||e.stderr.trim()||`hdc exit ${e.exitCode}`;throw Error(`failed to ${t} HarmonyOS screen recording: ${n}`)}async function Ie(e,t){t.throwIfAborted();let{runHarmonyShell:n}=await import(`./hdc.js`).then(e=>e.t),i=await n(e,[`aa`,`dump`,`-l`],{timeoutMs:15e3,signal:t});t.throwIfAborted();let a=Le(i.stdout);if(!a)throw new r(`COMMAND_FAILED`,`Could not determine the foreground HarmonyOS app`,{hint:`Open an app on the target, then retry appstate.`});return a}function Le(e){let t=e.split(/(?=^\s*Mission ID #)/m);for(let e of t){if(!/\bstate #FOREGROUND\b/.test(e))continue;let t=e.match(/mission name #\[#([^:]+):[^:]*:([^\]]+)]/);if(!t)continue;let[,n,r]=t;if(!(!n||!r))return{package:n,activity:r}}}const Re=Object.freeze({available:!0}),ze=Object.freeze({available:!1,reason:`unsupported-device-kind`}),z=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function B(e){let t=e.kind===`emulator`||e.kind===`device`?Re:ze;return Object.freeze({deployApp:t,materializeAppSource:z,deployMaterializedApp:z,sendPushNotification:z,uninstallApp:t})}function Be(e){let t=B(e.device);return Object.freeze({...t.deployApp.available?{deployApp:async t=>await He(e.commands,e.device,t,e.signal)}:{},...t.uninstallApp.available?{uninstallApp:async t=>await Ve(e.commands,e.device,t,e.signal)}:{}})}async function Ve(e,t,n,i){let a=n.app.trim();if(!a)throw new r(`INVALID_ARGS`,`Uninstall requires a HarmonyOS bundle name`,{hint:`Pass the bundle name reported by bm dump, such as com.example.app.`});if(!(await V(e,t,i)).includes(a))return{wasInstalled:!1};let o=await H(e,t,[`bm`,`uninstall`,`-n`,a],i);if((await V(e,t,i)).includes(a))throw new r(`COMMAND_FAILED`,`${a} is still installed after bm uninstall`,{exitCode:o.exitCode,stdout:o.stdout,stderr:o.stderr,hint:`Read the bm uninstall output above for the bm reason; system and shared bundles refuse removal.`});return{wasInstalled:!0,packageName:a}}async function V(e,t,n){let a=await H(e,t,[`bm`,`dump`,`-a`],n,{allowFailure:!0,timeoutMs:15e3});if(a.exitCode!==0)throw new r(`COMMAND_FAILED`,`Could not read the installed bundle inventory`,i(a));let o=T(a.stdout);if(o.length===0)throw new r(`COMMAND_FAILED`,`Could not read the installed bundle inventory`,{exitCode:a.exitCode,stdout:a.stdout,stderr:a.stderr,hint:`Confirm the device connection, then check bm dump -a output on the device.`});return o}async function He(e,t,n,i){let a=await Ue(e,n.appPath,i)??n.app.trim();if(!a)throw new r(`INVALID_ARGS`,`Could not determine the bundle name from the HAP archive`,{hint:`Pass the HarmonyOS bundle name before the HAP path, or provide a valid HAP containing module.json.`});return await Ge(e,t,[`install`,`-r`,n.appPath],i,18e4),n.replaceExisting&&(await O(1e3,void 0,{signal:i}),await We(e,t,a,i)),{packageName:a,launchTarget:a}}async function Ue(e,t,n){let r=await e.run({executable:`unzip`,args:[`-p`,t,`module.json`],allowFailure:!0,timeoutMs:15e3},n);if(r.exitCode===0&&r.stdout.trim().length!==0)try{return JSON.parse(r.stdout).app?.bundleName?.trim()||void 0}catch{return}}async function We(e,t,n,i){let a=await H(e,t,[`bm`,`dump`,`-n`,n],i),o=E(a.stdout);if(!o)throw new r(`COMMAND_FAILED`,`Could not determine a launchable ability for ${n}`,{hint:`Check that the HarmonyOS bundle exposes a main ability.`});await H(e,t,[`aa`,`start`,`-b`,n,...o.module?[`-m`,o.module]:[],`-a`,o.ability],i)}async function Ge(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}async function H(e,t,n,r,i={}){return await e.run({executable:`hdc`,args:o(`hdc`,`shell`,n,[`-t`,t.id]),timeoutMs:i.timeoutMs??15e3,allowFailure:i.allowFailure},r)}const U=n(`harmonyos`),Ke=t(`unsupported-platform-leaf`,`HarmonyOS reads element text from the captured tree only.`),qe=t(`unsupported-device-kind`,`focus is supported on HarmonyOS emulators and physical devices.`),W=Object.freeze({available:!0}),G=t(`unsupported-platform-leaf`),Je=t(`unsupported-device-kind`,`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`),Ye=t(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),K=Object.freeze({available:!0}),Xe=t(`unsupported-device-kind`,`open is supported only for HarmonyOS emulators and devices.`),Ze=t(`unsupported-device-kind`,`close is supported only for HarmonyOS emulators and devices.`),Qe=t(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),q=t(`unsupported-device-kind`,`snapshot is supported only for HarmonyOS emulators and devices.`),$e=t(`unsupported-device-kind`,`screenshot is supported only for HarmonyOS emulators and devices.`),J=t(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),et=t(`unsupported-platform-leaf`,`viewport resizes web targets only (--platform web).`);function tt(e){let t=nt(e),n=rt(e);return d({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:G,clearRuntimeHints:G,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Ye,configureProviderPortReverse:Qe})}function nt(e){return e.kind===`emulator`||e.kind===`device`?K:Xe}function rt(e){return e.kind===`emulator`||e.kind===`device`?K:Ze}const Y=t(`unsupported-device-kind`,`Gestures are supported on HarmonyOS emulators and physical devices.`),it=t(`unsupported-platform-leaf`),at=t(`unsupported-platform-leaf`,m);function X(e){return e.kind===`emulator`||e.kind===`device`?W:Y}function Z(e){return e.kind===`emulator`||e.kind===`device`?W:qe}const Q=t(`unsupported-platform-leaf`),ot=t(`unsupported-platform-leaf`,`HarmonyOS supports settings clear-app-state only.`),st=t(`unsupported-platform-leaf`,`keyboard status/get is not available through the public HarmonyOS HDC API; use keyboard dismiss or enter`),$=t(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function ct(t){let n=M(t),r=async e=>{let t=await n.inspectFacts(e),r=B(e),i=De(e);return Object.freeze({device:t.device,operations:{...t.operations,...r,appState:e.kind===`simulator`?Je:W,networkDump:G,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,...le({capture:e.kind===`emulator`||e.kind===`device`?W:q,customActions:J,withoutActiveApp:e.kind===`emulator`||e.kind===`device`?W:q}),...ve({capture:e.kind===`emulator`||e.kind===`device`?W:$e}),...re({findText:q,querySelector:q}),...be({setViewport:et}),...oe({focus:Z(e)}),...ae({unsupported:Y,plan:X(e),directionalFling:X(e),multiTouch:it,targetAuthoredDrag:at,viewport:X(e)}),...ne({scroll:X(e)}),...te({type:Z(e)}),...p({unsupported:G,tap:Z(e),longPress:Z(e),fill:Z(e)}),...se({readTextAtPoint:Ke}),...ee({back:Z(e)}),...ce({unsupported:Q,home:Z(e),appSwitcher:Z(e)}),setFoldPose:Q,sendTelephonyEvent:Q,...me({triggerAppEvent:Q}),..._({target:Z(e),unsupported:ot,write:{"clear-app-state":W}}),...he({read:Q,wait:Q,accept:Q,dismiss:Q}),...de({orientation:Q}),...pe({tvRemote:Q}),...ue({unsupported:Q,status:st,dismiss:Z(e),enter:Z(e)}),...fe({unsupported:Q}),...ge({capture:$,query:$}),..._e({frames:Z(e),memorySample:Z(e),memorySnapshot:Z(e),nativeCapture:Q,profileReport:Q}),ensureReady:W,bootTarget:G,bootTargetHeadless:G,listApps:W,...tt(e),shutdownTarget:G}})};return Object.freeze({owner:U,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:r,bind:async i=>{let a=await n.bind(i),o=await r(i.device),s=o.operations.screenRecordingStart;return Object.freeze({device:a.device,owner:U,facts:o,operations:Object.freeze({...a.operations,...Be({commands:t.commands,device:i.device,signal:i.scope.signal}),...o.operations.appState.available?{appState:async()=>await Ie(i.device,i.scope.signal)}:{},ensureReady:async()=>({...i.device,booted:!0}),...s.available?Oe({host:t,device:i.device,owner:U,signal:i.scope.signal}):{},...o.operations.captureSnapshot.available?ie({device:i.device,signal:i.scope.signal,resolveInteractor:t.localInteractors.resolve}):{},...v({device:i.device,signal:i.scope.signal,resolveInteractor:t.localInteractors.resolve,facts:o.operations,captureCapabilities:ye(`a HarmonyOS device captures through hdc`),pause:async e=>await t.clock.sleep(e,i.scope.signal)}),...e(o.operations.perfFrames,()=>Ce({resolveHost:()=>t.perf.harmony,device:i.device})),listApps:async e=>{i.scope.signal.throwIfAborted();let{listHarmonyApps:t}=await import(`./app-lifecycle2.js`).then(e=>e.t);return(await t(e.device,e.filter,{signal:i.scope.signal})).map(e=>({id:e.package,name:e.name}))},...u(xe({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,host:t.localInteractors,device:i.device,signal:i.scope.signal}),o.operations)}),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>await n.shutdown()})}export{ct as createHarmonyPlatformRuntime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";import{J as t,Y as n}from"./sdk-device.js";function r(r){let i=r.now??Date.now,a=r.undurableCleanupTtlMs??3e5,o=new Map;return Object.freeze({blockUndurableCleanup(e,r){let s=t(e);o.set(n(s),{device:s,reason:r,expiresAt:i()+a})},clearUndurableCleanup(e){o.delete(n(t(e)))},assertStartAllowed(a){let s=n(t(a)),c=o.get(s);if(c){if(i()>c.expiresAt){o.delete(s),r.onUndurableCleanupExpired?.({device:c.device,reason:c.reason});return}throw new e(`COMMAND_FAILED`,`The existing ${r.displayName.toLowerCase()} resource has process-local unconfirmed ownership`,{reason:`cleanup-unconfirmed`,hint:`Do not start a replacement in this daemon process: ${c.reason}`})}}})}function i(){return r({displayName:`screen recording`})}export{r as n,i as t};
|