agent-device 0.21.14 → 0.21.16
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.14.apk → agent-device-android-ime-helper-0.21.16.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.16.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.14.manifest.json → agent-device-android-ime-helper-0.21.16.manifest.json} +4 -4
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.16.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.16.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.14.manifest.json → agent-device-android-snapshot-helper-0.21.16.manifest.json} +6 -6
- package/apple/snapshot-bridge/SnapshotBridgeRuntime.m +11 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +84 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.m +4 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerMainOwnedState.swift +27 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedTextEntry.h +10 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedTextEntry.m +21 -5
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSystemSurfaceHostPolicy.swift +0 -9
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +40 -5
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandDispatch.swift +179 -91
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +5 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +1 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+GestureExecution.swift +1 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +36 -49
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+MainThreadWork.swift +11 -15
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +136 -29
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +4 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXPresentation.swift +3 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScreenRecorder.swift +6 -5
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollDragExecution.swift +4 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SequenceExecution.swift +2 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +8 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotAcquisition.swift +56 -14
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +18 -8
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCaptureTarget.swift +9 -7
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotExecution.swift +5 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTiming.swift +2 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +4 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedInteraction.swift +5 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedTextEntry.swift +245 -41
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +47 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift +7 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextTyping.swift +115 -111
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Transport.swift +17 -10
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift +8 -9
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TypeExecution.swift +2 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +12 -11
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotGeometry.swift +7 -4
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotModels.swift +15 -8
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationProjection.swift +1 -0
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFold.swift +26 -9
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFoldProjection.swift +1 -0
- package/dist/src/adapter.js +1 -1
- package/dist/src/adb-executor.js +1 -1
- package/dist/src/adb-failure.js +1 -1
- package/dist/src/adb-transport.js +1 -1
- package/dist/src/agent-browser-provider.js +1 -1
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/agent-device-client.js +2 -2
- package/dist/src/ai-sdk.js +1 -1
- package/dist/src/alert-runtime.js +1 -1
- package/dist/src/android-adb.d.ts +1 -8
- package/dist/src/android-input-ownership.js +1 -1
- package/dist/src/android-snapshot-quality.js +1 -0
- package/dist/src/android-system-chrome.js +1 -1
- package/dist/src/android.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 +1 -1
- package/dist/src/app-lifecycle2.js +1 -1
- package/dist/src/app-log-files.js +1 -1
- package/dist/src/app-log-runtime2.js +1 -1
- package/dist/src/app-resolution.js +2 -2
- package/dist/src/apple-runner-platform.js +1 -1
- package/dist/src/application-lifecycle-interaction.js +1 -1
- package/dist/src/archive.js +1 -1
- package/dist/src/artifact-download.js +1 -1
- package/dist/src/auth-session.js +1 -1
- package/dist/src/auth.js +1 -1
- package/dist/src/backend-snapshot-options.js +1 -1
- package/dist/src/boot-diagnostics.js +1 -1
- package/dist/src/capture-disclosure.js +1 -1
- package/dist/src/capture.js +1 -1
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +3 -2
- package/dist/src/cli.js +4 -4
- package/dist/src/click-button.js +1 -1
- package/dist/src/client-metro.js +1 -1
- package/dist/src/client-types.d.ts +103 -96
- package/dist/src/clipboard-shell-response.js +1 -1
- package/dist/src/command-schema.js +1 -1
- package/dist/src/command-tools.js +3 -3
- package/dist/src/connection-runtime.js +1 -1
- package/dist/src/connection.js +5 -5
- package/dist/src/contracts.d.ts +1 -1
- package/dist/src/contracts.js +1 -1
- package/dist/src/daemon-client-lease-beat.js +1 -0
- package/dist/src/daemon-client-lifecycle.js +1 -1
- package/dist/src/daemon-client-transport.js +1 -0
- package/dist/src/daemon-shutdown-report.js +1 -1
- package/dist/src/daemon.js +1 -1
- package/dist/src/debug-symbols-facade.js +1 -1
- package/dist/src/device-claim-inspection.js +1 -1
- package/dist/src/device-claim-rule.js +2 -2
- package/dist/src/device-input-state.d.ts +15 -2
- package/dist/src/device-inventory-context.js +1 -1
- package/dist/src/device-rotation.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/device2.js +1 -1
- package/dist/src/devicectl.js +1 -1
- package/dist/src/diagnostics.js +1 -1
- package/dist/src/dispatch-resolve.js +1 -1
- package/dist/src/doctor-facade.js +1 -1
- package/dist/src/doctor2.js +1 -1
- package/dist/src/durable-resource.js +1 -1
- package/dist/src/engine-eval-script.js +1 -1
- package/dist/src/error.js +1 -1
- package/dist/src/exec.js +1 -1
- package/dist/src/file.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/format.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/harmonyos.js +1 -1
- package/dist/src/helper.js +2 -2
- package/dist/src/host.js +1 -1
- package/dist/src/human-control-contract.js +1 -1
- package/dist/src/human-control.js +1 -1
- package/dist/src/index.d.ts +7 -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-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 -4
- package/dist/src/interactor2.js +1 -1
- package/dist/src/interactors.js +1 -1
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +2 -2
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/internal/run-script-http-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-snapshot-acquisition.js +1 -1
- package/dist/src/ios-snapshot-engine.js +1 -0
- package/dist/src/ios-snapshot-runtime.js +1 -1
- package/dist/src/lease-context.js +1 -1
- package/dist/src/lease-scope.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/limrun-download-file.js +1 -1
- package/dist/src/limrun-runtime-dependencies.js +1 -1
- package/dist/src/limrun.d.ts +16 -3
- package/dist/src/linux.js +1 -1
- package/dist/src/location-coordinates.js +1 -1
- package/dist/src/managed-device-scope.js +1 -1
- package/dist/src/mechanics.js +17 -17
- package/dist/src/mobile-snapshot-semantics.js +1 -1
- package/dist/src/multitouch-support.js +1 -1
- package/dist/src/native-build-cache.js +1 -1
- package/dist/src/observation.js +1 -1
- package/dist/src/overlay.js +3 -0
- 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 +1 -1
- package/dist/src/perf.js +1 -1
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/platform-request-scope.js +1 -1
- package/dist/src/platform-runtime-managed-owner.js +1 -1
- package/dist/src/platform-runtime-open-target.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +4 -4
- package/dist/src/platform-runtime-runtime-hints.js +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-unavailable.js +1 -1
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/platform-runtime2.js +1 -1
- package/dist/src/png-crop-bytes.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/prepare-kind.js +1 -1
- package/dist/src/provider-session-ownership.js +1 -1
- package/dist/src/provider-webdriver.js +1 -1
- package/dist/src/proxy.js +1 -1
- package/dist/src/quality-warnings.js +1 -1
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-runtime.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 +36 -36
- package/dist/src/remote-config2.js +1 -1
- package/dist/src/replay-divergence.js +1 -1
- package/dist/src/replay.js +1 -1
- package/dist/src/reporting.js +1 -1
- package/dist/src/request-admission.js +1 -1
- package/dist/src/request-cancel.js +1 -1
- package/dist/src/request-runtime-binding.js +1 -1
- package/dist/src/result-serialization.js +1 -1
- package/dist/src/retry.js +1 -1
- package/dist/src/runner-artifact-manifest.js +1 -0
- package/dist/src/runner-cache-metadata.js +3 -2
- package/dist/src/runner-client.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-disposal.js +1 -1
- package/dist/src/runner-error-classification.js +3 -3
- package/dist/src/runner-operations-facade.js +1 -1
- package/dist/src/runner.js +1 -1
- package/dist/src/runtime-transport-hints.js +1 -1
- package/dist/src/runtime.js +1 -3
- package/dist/src/runtime10.js +2 -2
- package/dist/src/runtime2.js +4 -4
- package/dist/src/runtime3.js +1 -1
- package/dist/src/runtime4.js +5 -5
- package/dist/src/runtime5.js +1 -1
- package/dist/src/runtime6.js +1 -1
- package/dist/src/runtime7.js +1 -1
- package/dist/src/runtime8.js +1 -1
- package/dist/src/runtime9.js +1 -1
- package/dist/src/screen-recording-admission-ledger.js +1 -1
- 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-transport.js +1 -1
- package/dist/src/screenshot-density.js +1 -1
- package/dist/src/screenshot-image.js +1 -1
- package/dist/src/screenshot-overlay-draw.js +1 -1
- package/dist/src/screenshot-runtime.js +1 -1
- package/dist/src/screenshot.js +1 -1
- package/dist/src/screenshot3.js +1 -1
- package/dist/src/script.js +1 -1
- package/dist/src/scroll-command.d.ts +13 -6
- package/dist/src/scroll-command.js +1 -1
- package/dist/src/scroll-gesture.js +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 +38 -10
- 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-io.js +1 -1
- package/dist/src/sdk-remote-config.js +1 -1
- package/dist/src/sdk-selectors.d.ts +1 -1
- package/dist/src/selection.js +0 -0
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/server.js +1 -1
- package/dist/src/session-allocation.js +1 -1
- package/dist/src/session-routing.js +1 -1
- package/dist/src/session-runtime-admission.js +1 -1
- package/dist/src/session-snapshot.js +1 -1
- package/dist/src/session-store.js +3 -3
- package/dist/src/session.js +1 -1
- package/dist/src/session2.js +4 -4
- package/dist/src/settings.js +1 -1
- package/dist/src/settings2.js +1 -0
- package/dist/src/simctl.js +1 -1
- package/dist/src/simulator-boot.js +1 -1
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-capture-annotations.js +1 -1
- package/dist/src/snapshot-desktop-projection.js +1 -1
- package/dist/src/snapshot-runtime-binding.js +1 -1
- package/dist/src/snapshot-runtime.js +1 -1
- package/dist/src/snapshot-state.js +1 -1
- package/dist/src/snapshot2.js +1 -1
- package/dist/src/snapshot3.js +1 -1
- package/dist/src/snapshot4.js +1 -1
- package/dist/src/src.js +1 -1
- package/dist/src/src4.js +1 -1
- package/dist/src/src7.js +1 -1
- package/dist/src/src8.js +2 -2
- package/dist/src/stop-sequence.js +1 -1
- package/dist/src/string-enum.js +1 -1
- package/dist/src/surface-snapshot.js +1 -1
- package/dist/src/takeover.js +1 -1
- package/dist/src/text-entry-focus.js +1 -1
- package/dist/src/tool-provider.js +1 -1
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/touch-runtime.js +1 -1
- package/dist/src/transport.js +1 -1
- package/dist/src/tree.js +1 -1
- package/dist/src/tv-remote.js +1 -1
- package/dist/src/type-text-runtime.js +1 -1
- package/dist/src/verified-file.js +1 -1
- package/dist/src/video.js +1 -1
- package/dist/src/viewport.js +1 -1
- package/dist/src/web.js +1 -1
- package/dist/src/web2.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.14.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.14.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.14.apk.sha256 +0 -1
- package/dist/src/absence-observation-errors.js +0 -1
- package/dist/src/runner-presentation.js +0 -1
- package/dist/src/semantic-index.js +0 -1
- package/dist/src/snapshot-scope.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{G as e,O as t}from"./sdk-contracts.js";import{_ as n}from"./sdk-batch-runner.js";import{b as r,i,r as a,t as o}from"./sdk-device.js";import{$n as s,Qn as c,cn as l,on as ee,p as te,x as ne}from"./sdk-batch.js";import{t as re}from"./recording-scope.js";import{a as ie}from"./scroll-gesture.js";import{_ as u,c as ae,d as oe,g as se,h as ce,i as le,l as ue,m as de,o as fe,p as d,s as pe,u as f,y as me}from"./script.js";import{A as p,C as he,D as ge,E as _e,M as ve,N as ye,S as be,T as xe,_ as Se,a as Ce,b as we,g as m,i as Te,k as Ee,l as De,n as Oe,r as ke,s as Ae,t as je,v as Me,w as Ne,x as Pe,y as Fe}from"./parameterized-recorded-fill.js";import{n as h,t as Ie}from"./catalog.js";import{o as Le,t as g}from"./back-mode.js";import{t as Re}from"./session.js";import{r as ze}from"./success-text.js";import{t as Be}from"./click-button.js";import"./device.js";import{r as _,t as v}from"./device-rotation.js";import{a as y,r as b}from"./diagnostics.js";import{D as Ve}from"./owner-identity.js";import"./file.js";import{t as He}from"./tv-remote.js";import"./diagnostics2.js";import{n as Ue,r as We}from"./session-repair-tombstone.js";import{n as Ge,r as x,t as S}from"./session-paths.js";import{t as Ke}from"./keyboard-actions.js";import C from"node:path";import w from"node:fs";import{createHash as qe}from"node:crypto";import{StringDecoder as Je}from"node:string_decoder";function Ye(e,t={}){let n=[e.command];return e.command===`snapshot`?oe(n,e):e.command===`open`?le(n,e):e.command===`runtime`?ae(n,e,{includeAllPositionals:t.runtimeIncludeAllPositionals}):e.command===`record`?pe(n,e):e.command===`screenshot`?ue(n,e):fe(n,e),n.join(` `)}function Xe(e){return e.targetEvidences?[c(e.targetEvidences)]:e.targetEvidence?[s(e.targetEvidence)]:[]}function T(e){return e?.scriptPublication??m}function Ze(e,t){let n=T(e),r=typeof t.saveScript==`string`?S(t.saveScript):n.kind===`repair`?void 0:t.healedSiblingPath;e.scriptPublication=Me(n,{requested:{path:r,force:t.force===!0},boundary:t.firstArm?e.actions.length:0,sourcePath:t.sourcePath})}function Qe(e){e.scriptPublication=we(T(e))}function $e(e){e.scriptPublication=Ne(T(e))}function et(e,t){e.scriptPublication=xe(T(e),t)}function tt(e){e.scriptPublication=Se(T(e))}function nt(e,t){let n=T(e);return n.kind===`repair`&&n.closeReceipt===t}function rt(e){return T(e).kind===`repair`}function it(e){return he(T(e))}function E(e){return _e(T(e))}function at(e){return ge(T(e))}function ot(e,t){if(t.flags?.noRecord||gt(e,t))return;t.flags&&Ae(e,t.flags);let n=ct(t),r=dt(e,lt(t,n));n&&ut(e,n);let i={ts:Date.now(),command:r.command,positionals:r.positionals,runtime:r.runtime,flags:vt(r.flags),result:r.result,...r.targetEvidence?{targetEvidence:r.targetEvidence}:{},...r.targetEvidences?{targetEvidences:r.targetEvidences}:{}};return e.actions.push(i),b({level:`debug`,phase:`record_action`,data:{command:t.command,session:e.name}}),i}function st(e,t,n,r,i,a){t&&e.recordAction(t,{command:r,positionals:a?.positionals??n.positionals??[],flags:a?.flags??n.flags??{},result:i??{}})}function ct(e){if(e.command!==`fill`||typeof e.flags.recordAs!=`string`)return;let t=ye(e.flags.recordAs),n=ve(t);return{literal:p({ts:0,command:e.command,positionals:e.positionals,flags:e.flags}),placeholder:n}}function lt(e,t){if(!t)return e;let{literal:n,placeholder:r}=t;return{...e,positionals:pt(e.positionals,r),result:je(e.result,n,r),targetEvidence:Oe(e.targetEvidence,n,r)}}function ut(e,t){t.literal.trim()&&(e.recordedFillLiterals??=new Map,!e.recordedFillLiterals.has(t.literal)&&e.recordedFillLiterals.set(t.literal,t.placeholder))}function dt(e,t){let n=e.recordedFillLiterals;if(!n||n.size===0)return t;let r=ke(t.result,n),i=(t.targetEvidenceMode??`action`)===`landmark`?ft(t.targetEvidence,n):D(t.targetEvidence,n),a=t.targetEvidences?{source:D(t.targetEvidences.source,n),destination:D(t.targetEvidences.destination,n)}:t.targetEvidences;return{...t,result:r,targetEvidence:i,targetEvidences:a}}function ft(e,t){return e&&(Ce(e,t)?void 0:e)}function D(e,t){return!e||!Ce(e,t)?e:{...Te(e,t),verification:`unverifiable`}}function pt(e,t){let n=e[0];return n?.startsWith(`@`)?e.length>=3?[n,e[1],t]:[n,t]:e.length>=3&&Number.isFinite(Number(e[0]))&&Number.isFinite(Number(e[1]))?[e[0],e[1],t]:n===void 0?[t]:[n,t]}const mt=new Set([`snapshot`,`get`,`is`,`find`]);function ht(e){return e.internal?.replayPlanStep!==!0&&mt.has(e.command)}function gt(e,t){return!t.interactiveObservation||E(e)===void 0?!1:t.flags?.record!==!0}const _t=Le();function vt(e){if(!e)return{};let t={};for(let n of _t){let r=e[n];r!==void 0&&(t[n]=r)}return t}function yt(e){let n=e.flatMap((e,t)=>e.command===`open`?[t]:[]);if(n.length!==1||n[0]!==0)throw new t(`COMMAND_FAILED`,`Cannot publish this session: an open-to-destination script requires exactly one initial recorded open.`,{retriable:!1,hint:`Close this session and start a fresh one with open <app> --save-script[=<path>].`});if(e.some(e=>e.command===`close`))throw new t(`COMMAND_FAILED`,`Cannot publish an active-session script containing close.`,{retriable:!1,hint:`Close this session and record the journey again from a fresh open --save-script session.`});let r=-1;for(let[t,n]of e.entries())ne({command:n.command,positionals:n.positionals,flags:n.flags})===`mutates-app`&&(r=t);if(!e.slice(r+1).some(Tt))throw new t(`COMMAND_FAILED`,`Cannot publish this session without a portable destination guard after the final mutating action.`,{retriable:!0,hint:`Record a selector-targeted wait on a labeled or id-bearing landmark, for example wait 'role="heading" label="Screen X"', so its recorded identity is captured, then retry session save-script.`})}function bt(e){for(let n of e){if(xt(n)){St(n);continue}let e=Et(n),r=e??(n.command===`wait`?n.positionals[0]:void 0);if(r?.startsWith(`@`))throw new t(`COMMAND_FAILED`,`Cannot publish recorded step "${n.command} ${r}": the session-local ref was not converted to a portable selector.`,{retriable:!1,hint:`Close this session and record the journey again using selectors or resolvable refs.`});if(n.command===`find`&&ne(n)===`mutates-app`)throw new t(`COMMAND_FAILED`,`Cannot publish a recorded mutating find step because its target identity is not replay-verifiable.`,{retriable:!1,hint:`Close this session and record the journey again with an explicit selector-targeted click, press, fill, or focus action.`});let i=e;if(!(!i||!l(i)||n.targetEvidence))throw new t(`COMMAND_FAILED`,`Cannot publish recorded step "${n.command} ${i}": recording-time target identity evidence is missing.`,{retriable:!1,hint:`Close this session and record the journey again from open --save-script so target-v1 evidence is captured before each interaction.`})}}function xt(e){return Ct(e)!==void 0}function St(e){let n=Ct(e);if(!n)return;let r=[n.source,n.destination];for(let n of r){if(n?.startsWith(`@`))throw new t(`COMMAND_FAILED`,`Cannot publish recorded drag endpoint "${n}": the session-local ref was not converted to a portable selector.`,{retriable:!1});if(!(!n||!l(n))&&!e.targetEvidences)throw new t(`COMMAND_FAILED`,`Cannot publish recorded drag endpoint "${n}": recording-time target identity evidence is missing.`,{retriable:!1,hint:`Close this session and record the journey again so targets-v1 evidence is captured for both drag endpoints.`})}}function Ct(e){return e.command===`gesture`?me(e.positionals):void 0}function wt(e,n){if(e instanceof t){if(e.details?.reason===`script_target_exists`)return new t(e.code,`A file already exists at ${String(e.details.path)}.`,{...e.details,retriable:!0,hint:`Retry session save-script with another path, or pass --force to replace the existing file. The session remains armed.`});let n=e.details?.retriable===!0;return new t(e.code,e.message,{...e.details,retriable:n,hint:e.details?.hint??(n?`Fix the recorded journey or target, then retry session save-script. The session remains armed.`:`Close this session and start a fresh one with open <app> --save-script[=<path>].`)})}let r=e instanceof Error?e.message:String(e);return new t(`COMMAND_FAILED`,`Failed to publish the active session script${n?` to ${n}`:``}: ${r}`,{retriable:!0,hint:`Check the target path and permissions, then retry session save-script. The session remains armed.`})}function Tt(e){if(e.command!==`wait`)return!1;let t=ee(e.positionals);return t?.kind!==`selector`||!l(t.selectorExpression)?!1:e.targetEvidence?.verification===`verified`}function Et(e){if(e.command===`get`)return e.positionals[1];if(se(e.command)||e.command===`fill`){let[t,n]=e.positionals;return t!==void 0&&n!==void 0&&Dt(t)&&Dt(n)?void 0:t}}function Dt(e){return e.trim().length>0&&Number.isFinite(Number(e))}function Ot(e){let t=e.scriptPublication??m;return t.kind===`repair`?t.status===`committed`||!be(t):!1}function kt(e){return!Pe(e.scriptPublication??m)||Ot(e)}var At=class{sessionsDir;constructor(e){this.sessionsDir=e}write(e,t){let n=rt(e),r=t?.publication===`active`,i;try{if(kt(e))return{written:!1};let a=jt(e,{appendCompleteSentinel:n,activePublication:r});i=this.resolveScriptPath(e);let o=C.dirname(i);return w.existsSync(o)||w.mkdirSync(o,{recursive:!0}),Pt({scriptPath:i,script:a.script,force:t?.force}),n&&(e.scriptPublication=Fe(e.scriptPublication??m)),{written:!0,path:i,actionCount:a.actionCount}}catch(t){return Mt({session:e,error:t,scriptPath:i,repairArmed:n,activePublication:r})}}resolveScriptPath(e){let t=Ee(e.scriptPublication??m);if(t)return S(t);let n=x(e.name),r=new Date(e.createdAt).toISOString().replaceAll(/[:.]/g,`-`);return C.join(this.sessionsDir,`${n}-${r}.ad`)}};function jt(e,t){let n=Ft(e,{strictPortableRefs:t.activePublication});return t.activePublication&&yt(n),{script:Gt(e,n,t.appendCompleteSentinel),actionCount:n.length}}function Mt(e){let{session:n,error:r,scriptPath:i,repairArmed:a,activePublication:o}=e;if(b({level:`warn`,phase:`session_script_write_failed`,data:{session:n.name,path:i,error:r instanceof Error?r.message:String(r)}}),a)return{written:!1,error:Nt(r,i)};if(o)return{written:!1,error:wt(r,i)};if(r instanceof t)throw r;return{written:!1}}function Nt(e,n){if(e instanceof t)return e;let r=e instanceof Error?e.message:String(e);return new t(`COMMAND_FAILED`,`Failed to write the healed script${n?` to ${n}`:``}: ${r}`,{hint:`The repair transaction completed but the healed .ad could not be published; check the target path and permissions, then retry close --save-script.`})}function Pt(e){let{scriptPath:n,script:r,force:i}=e;try{Ve({destination:n,contents:r,publish:i?`replace`:`link-exclusive`})}catch(e){throw e.code===`EEXIST`?new t(`COMMAND_FAILED`,`A file already exists at ${n}; remove it, pass replay --save-script=<other-path>, or pass --force/--overwrite to replace it.`,{reason:`script_target_exists`,path:n}):e}}function Ft(e,t={}){let n=E(e),r=n!==void 0,i=e.actions.slice(n??0),a=[];for(let n of i){if(n.command===`snapshot`)continue;let i=Rt(n);if(i){a.push(i);continue}(r||t.strictPortableRefs)&&It(n);let o=Wt(e,n);o&&a.push(o),a.push(n)}return t.strictPortableRefs&&bt(a),a}function It(e){let n=e.command===`gesture`?me(e.positionals??[]):void 0;if(n){Lt(n);return}if(!O(e.command))return;let r=e.command===`get`?e.positionals?.[1]:e.positionals?.[0];if(r?.startsWith(`@`))throw new t(`COMMAND_FAILED`,`Cannot write recorded step "${e.command} ${r}" to a script: it never resolved to a selector, so the ref would not resolve in a fresh replay session.`)}function Lt(e){let n=[e.source,e.destination].find(e=>e.startsWith(`@`));if(n)throw new t(`COMMAND_FAILED`,`Cannot write recorded drag endpoint "${n}" to a script: it never resolved to a selector, so the ref would not resolve in a fresh replay session.`)}function Rt(e){let t=zt(e);if(!(!t||!O(e.command)))return ce(e.command)||e.command===`hover`?{...e,positionals:[t]}:e.command===`longpress`?Vt(e,t):e.command===`fill`?Bt(e,t):Ht(e,t)}function zt(e){let t=Array.isArray(e.result?.selectorChain)&&e.result.selectorChain.every(e=>typeof e==`string`)?e.result.selectorChain:[];return t.length>0?t.join(` || `):void 0}function O(e){return se(e)||e===`fill`||e===`get`}function Bt(e,t){let n=p(e);return n.length>0?{...e,positionals:[t,n]}:void 0}function Vt(e,t){let n=typeof e.result?.durationMs==`number`?String(e.result.durationMs):Ut(e.positionals??[]);return{...e,positionals:n?[t,n]:[t]}}function Ht(e,t){let n=e.positionals?.[0];return n===`text`||n===`attrs`?{...e,positionals:[n,t]}:void 0}function Ut(e){let t=e.at(-1);if(!(e.length<=1||t===void 0||t.trim()===``))return Number.isFinite(Number(t))?t:void 0}function Wt(e,t){if(!O(t.command))return;let n=t.result?.refLabel;if(typeof n!=`string`||n.trim().length===0)return;let r=n.trim();return{ts:t.ts,command:`snapshot`,positionals:[],flags:{platform:e.device.platform,snapshotInteractiveOnly:!0,snapshotScope:r},result:{scope:r}}}function Gt(e,t,n){let i=[],a=e.device.kind?` kind=${e.device.kind}`:``;i.push(`context platform=${r(e.device)} device=${de(e.device.name)}${a} theme=unknown`);for(let e of t)e.flags?.noRecord||(i.push(...Xe(e)),i.push(Kt(e)));return n&&i.push(`# agent-device:heal-complete`),`${i.join(`
|
|
2
|
-
`)}\n`}function Kt(e){return qt([e.command],e)||Ye(e)}function qt(e,t){if(ce(t.command))return Jt(e,t);if(t.command===`fill`)return Yt(e,t);if(t.command===`get`)return Xt(e,t)}function Jt(e,t){let n=t.positionals?.[0];if(n){if(n.startsWith(`@`))return e.push(d(u(n))),k(e,t),f(e,t),e.join(` `);if(t.positionals.length===1)return e.push(d(n)),f(e,t),e.join(` `)}}function Yt(e,t){let n=t.positionals?.[0];if(!n?.startsWith(`@`))return;e.push(d(u(n))),k(e,t);let r=t.positionals.slice(1).join(` `);return t.positionals.length>1&&e.push(d(r)),f(e,t),e.join(` `)}function Xt(e,t){let n=t.positionals?.[0],r=t.positionals?.[1];if(!(!n||!r))return e.push(d(n)),e.push(d(u(r))),r.startsWith(`@`)&&k(e,t),e.join(` `)}function k(e,t){let n=t.result?.refLabel;typeof n==`string`&&n.trim().length>0&&e.push(d(n))}const Zt=[`id`,`deviceId`,`device_id`,`serial`,`udid`,`device_udid`,`identifier`],Qt={ios:`iOS`,ipados:`iPadOS`,tvos:`tvOS`,watchos:`watchOS`,visionos:`visionOS`,macos:`macOS`,apple:`Apple`,android:`Android`,linux:`Linux`,web:`Web`};function $t(e,t){let n=t??{};switch(e.command){case h.devices:return en(n.devices);case h.apps:return tn(n.apps,e.flags?.appsFilter);case h.boot:return nn(`Booted`,n,!0);case h.shutdown:return nn(`Shut down`,n,!1);case h.install:return rn(`Installed`,n);case h.reinstall:return rn(`Reinstalled`,n);case h.screenshot:return an(e,n);default:return{}}}function en(e){if(!Array.isArray(e))return{};let t=e.flatMap(e=>{let t=sn(e);return t?[t]:[]}),n=t.slice(0,5),r=Math.max(0,t.length-n.length),i=t.slice(0,3);return{summary:gn(`Found ${t.length} ${_n(`device`,t.length)}`,i.map(e=>mn(e,!0)),Math.max(0,t.length-i.length)),details:{deviceCount:t.length,devices:n,...r>0?{omittedDeviceCount:r}:{}}}}function tn(e,t){if(!Array.isArray(e))return{};let n=e.flatMap(e=>{let t=M(e);return t?[t]:[]}),r=n.slice(0,5),i=Math.max(0,n.length-r.length),a=n.slice(0,3);return{summary:gn(`Found ${n.length} ${_n(`app`,n.length)}`,a,Math.max(0,n.length-a.length)),details:{appCount:n.length,apps:r,...i>0?{omittedAppCount:i}:{},...t===`all`||t===`user-installed`?{filter:t}:{}}}}function nn(e,t,n){let r=cn(t);if(!r)return{};let i={device:r,...pn(t),booted:n};return{summary:`${e} ${mn(i,!1)}`,details:i}}function rn(e,t){let n=M(t.appName),r=M(t.bundleId),i=A(t,[`packageName`,`package`]),a=M(t.platform),o=M(t.launchTarget),s=A(t,[`bundleId`,`packageName`,`package`,`appId`,`launchTarget`]),c=hn(n,s);if(!c)return{};let l={};return j(l,`appName`,n),j(l,`bundleId`,r),j(l,`packageName`,i),j(l,`platform`,a),o!==s&&j(l,`launchTarget`,o),{summary:`${e} ${c}`,details:l}}function an(e,t){let n=on(e,t);return n?{details:{requestedFileName:n}}:{}}function on(e,t){let n=R(e.meta?.clientArtifactPaths?.path)??R(t.path);if(n)return L(n)}function sn(e){if(!n(e))return;let t=cn(e);if(t)return{name:t,...pn(e)}}function cn(e){let t=A(e,[`name`,`deviceName`,`device`]);return!t||!ln(e,t)?t:dn(e)}function ln(e,t){let n=un(t);return Zt.some(t=>{let r=M(e[t]);return r!==void 0&&un(r)===n})}function un(e){return e.toLowerCase()}function dn(e){let t=M(e.appleOs),n=M(e.platform),r=M(e.kind),i=fn(t,n);return i&&(r===`simulator`||r===`emulator`)?`${i} ${r}`:i?`${i} device`:r===`simulator`?`Simulator`:r===`emulator`?`Emulator`:`Unnamed device`}function fn(e,t){let n=e??t;if(!(!n||!Object.hasOwn(Qt,n)))return Qt[n]}function pn(e){let t=M(e.platform),n=M(e.appleOs),r=M(e.kind),i=M(e.target);return{...t?{platform:t}:{},...n?{appleOs:n}:{},...r?{kind:r}:{},...i?{target:i}:{},...typeof e.booted==`boolean`?{booted:e.booted}:{}}}function mn(e,t){let n=M(e.name)??M(e.device)??`device`,r=M(e.platform),i=M(e.appleOs),a=[r,i===r?void 0:i,M(e.kind),M(e.target),t&&typeof e.booted==`boolean`?e.booted?`booted`:`stopped`:void 0].filter(e=>!!e);return a.length>0?`${n} (${a.join(`, `)})`:n}function hn(e,t){return e&&t&&e!==t?`${e} (${t})`:e??t}function A(e,t){for(let n of t){let t=M(e[n]);if(t)return t}}function j(e,t,n){n&&(e[t]=n)}function gn(e,t,n){let r=[...t,...n>0?[`+${n} more`]:[]];return r.length>0?`${e}: ${r.join(`, `)}`:e}function _n(e,t){return t===1?e:`${e}s`}function M(e){let t=R(e);if(!t)return;let n=t.trim(),r=Array.from(n);return r.length<=120?n:`${r.slice(0,119).join(``)}…`}function N(e){return M(e)}function P(e){return typeof e==`boolean`?e:void 0}function F(e,t){let n=N(e);return n&&t.includes(n)?n:void 0}function I(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function L(e){let t=R(e);return t?M(t.split(/[\\/]/).at(-1)):void 0}function R(e){if(typeof e==`string`)return e.trim().length>0?e:void 0}function z(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}const vn=[`up`,`down`,`left`,`right`],yn=[`top`,`bottom`];function bn(e){return`${e.command===h.reinstall?`Reinstalled`:`Installed`} ${wn(e.result??{})??`app`}`}function xn(e){let t=e.result??{};switch(e.command){case h.scroll:return En(t);case h.screenshot:return kn(t);case h.home:return`Went home`;case h.back:return jn(t);case h.appSwitcher:return`Opened app switcher`;case h.actionButton:return`Pressed Action Button`;case h.orientation:return Nn(t);case h.fold:return Mn(t);case h.viewport:return Pn(t);case h.clipboard:return Fn(t);case h.keyboard:return In(t);case h.tvRemote:return zn(t);case h.gesture:return Bn(t);case h.swipe:return Vn(t);case h.trace:return Un(`trace`,e);case h.record:return Un(`recording`,e);default:return}}function Sn(e){let t=e.result??{};switch(e.command){case h.scroll:return I({direction:F(t.direction,vn),edge:F(t.edge,yn),passes:z(t.passes),amount:z(t.amount),pixels:z(t.pixels),durationMs:z(t.durationMs),x1:z(t.x1),y1:z(t.y1),x2:z(t.x2),y2:z(t.y2)});case h.screenshot:return I({requestedFileName:An(t)});case h.back:return I({mode:F(t.mode,g)});case h.orientation:return I({orientation:F(t.orientation,v)});case h.fold:return I({pose:F(t.pose,_)});case h.viewport:return I({width:z(t.width),height:z(t.height)});case h.clipboard:return I({action:F(t.action,[`read`,`write`])});case h.keyboard:return Rn(t);case h.tvRemote:return I({button:F(t.button,He),durationMs:z(t.durationMs)});case h.gesture:case h.swipe:return Hn(t);case h.trace:case h.record:return I({action:F(t.action,[`start`,`stop`]),fileName:Gn(e),showTouches:P(t.showTouches)});default:return{}}}function Cn(e,t){if(e.command!==h.screenshot)return t;let n=on(e,t);return n?{...t,requestedFileName:n}:t}function wn(e){let t=N(e.appName),n=Kn(e,[`bundleId`,`packageName`,`appBundleId`,`launchTarget`]);return t&&n&&t!==n?`${t} (${n})`:t??n??Tn(e)}function Tn(e){let t=N(e.app);return t&&!t.includes(`/`)&&!t.includes(`\\`)?t:void 0}function En(e){let t=F(e.direction,vn),n=F(e.edge,yn),r=z(e.passes);return n?Dn(n,r):t?On(t,e):`Scrolled`}function Dn(e,t){return t===0?`Already at ${e}`:t===void 0?`Scrolled to ${e}`:`Scrolled to ${e} in ${t} ${t===1?`pass`:`passes`}`}function On(e,t){let n=z(t.pixels);if(n!==void 0)return`Scrolled ${e} by ${n}px`;let r=z(t.amount);return r===void 0?`Scrolled ${e}`:`Scrolled ${e} by ${r}`}function kn(e){let t=An(e);return t?`Captured screenshot ${t}`:`Captured screenshot`}function An(e){return L(e.requestedFileName)??L(e.path)}function jn(e){return F(e.mode,g)===`system`?`Went back using system navigation`:`Went back`}function Mn(e){let t=F(e.pose,_);return t?`Folded to ${t}`:`Changed fold pose`}function Nn(e){let t=F(e.orientation,v);return t?P(e.confirmed)===!1?`Requested ${t} (unconfirmed)`:`Rotated to ${t}`:`Changed orientation`}function Pn(e){let t=z(e.width),n=z(e.height);return t!==void 0&&n!==void 0?`Set viewport to ${t}×${n}`:`Changed viewport`}function Fn(e){let t=F(e.action,[`read`,`write`]);return t===`read`?`Read clipboard`:t===`write`?`Updated clipboard`:`Used clipboard`}function In(e){let t=R(e.action);if(!t||!Ke(t))return`Used keyboard`;if(t===`dismiss`)return Ln(e);if(t===`enter`||t===`return`)return`Pressed keyboard return`;let n=P(e.visible);return n===void 0?`Inspected keyboard`:n?`Keyboard is visible`:`Keyboard is hidden`}function Ln(e){return P(e.dismissed)===!1?`Keyboard was already hidden`:`Dismissed keyboard`}function Rn(e){let t=R(e.action);return I({action:t&&Ke(t)?t:void 0,platform:F(e.platform,[`ios`,`android`]),visible:P(e.visible),wasVisible:P(e.wasVisible),dismissed:P(e.dismissed),attempts:z(e.attempts),mechanism:F(e.mechanism,[`dismissKey`])})}function zn(e){let t=F(e.button,He);return t?`Pressed TV remote ${t}`:`Used TV remote`}function Bn(e){let t=F(e.kind,[`fling`,`pan`,`pinch`,`rotate`,`transform`]);return t?`Ran ${t} gesture`:`Ran gesture`}function Vn(e){let t=z(e.count);return t!==void 0&&t>1?`Swiped ${t} times`:`Swiped`}function Hn(e){return I({kind:F(e.kind,[`fling`,`pan`,`pinch`,`rotate`,`transform`]),durationMs:z(e.durationMs),pointerCount:z(e.pointerCount),x1:z(e.x1),y1:z(e.y1),x2:z(e.x2),y2:z(e.y2),count:z(e.count),pauseMs:z(e.pauseMs),pattern:F(e.pattern,[`one-way`,`ping-pong`]),scale:z(e.scale)})}function Un(e,t){let n=Wn(e,F(t.result?.action,[`start`,`stop`])),r=Gn(t);return r?`${n} ${r}`:n}function Wn(e,t){return t===`start`?e===`trace`?`Started trace`:`Started recording`:t===`stop`?e===`trace`?`Stopped trace`:`Stopped recording`:e===`trace`?`Updated trace`:`Updated recording`}function Gn(e){let t=e.result??{};return L(t.requestedFileName)??L(t.outPath)??L(t.path)??L(e.positionals[1])}function Kn(e,t){for(let n of t){let t=N(e[n]);if(t)return t}}function qn(e){switch(e.command){case h.open:return`Opened ${B(e)??`session`}`;case h.close:return`Closed ${N(e.result?.session)??`session`}`;case h.click:case h.press:return`Tapped ${B(e)??`target`}`;case h.longPress:return`Long pressed ${B(e)??`target`}`;case h.hover:return`Hovered ${B(e)??`target`}`;case h.fill:return`Filled ${B(e)??`target`}`;case h.type:return`Typed text`;case h.install:case h.reinstall:case Ie.installSource:return bn(e);default:return xn(e)??`Ran ${e.command}`}}function Jn(e){return I({command:e.command,positionals:rr(e),flags:hr(e),...Yn(e),...Xn(e),...Zn(e),...Sn(e)})}function Yn(e){if(!Qn(e.command))return{};let t=e.result??{};return I({ref:G(t),targetLabel:B(e),selectorChainLength:dr(t.selectorChain)?.length,x:z(t.x),y:z(t.y),x2:z(t.x2),y2:z(t.y2),durationMs:z(t.durationMs)})}function Xn(e){if(!$n(e.command))return{};let t=e.result??{};return I({platform:F(t.platform,i),target:F(t.target,o),appName:N(t.appName),appBundleId:N(t.appBundleId),bundleId:N(t.bundleId),packageName:N(t.packageName),launchTarget:N(t.launchTarget)})}function Zn(e){let t=e.result??{};return e.command===h.snapshot?Array.isArray(t.nodes)?{nodeCount:t.nodes.length}:{}:e.command!==h.wait&&e.command!==h.find&&e.command!==h.get&&e.command!==h.is?{}:I({waitedMs:z(t.waitedMs),found:P(t.found)})}function Qn(e){return e===h.click||e===h.press||e===h.longPress||e===h.hover||e===h.focus||e===h.fill}function $n(e){return e===h.open||e===h.install||e===h.reinstall||e===Ie.installSource}function B(e){let t=e.result??{};return er(t)??tr(t)??nr(t)??lr(e.positionals[0])}function er(e){let t=G(e);if(t)return t.startsWith(`@`)?t:`@${t}`}function tr(e){let t=z(e.x),n=z(e.y);if(t!==void 0&&n!==void 0)return`(${t}, ${n})`}function nr(e){return N(e.appName)??N(e.appBundleId)??N(e.bundleId)??N(e.packageName)}function rr(e){if(e.positionals.length!==0)return e.command===h.type?[H(`text`)]:e.command===h.fill?ir(e):e.command===h.find?ar(e):e.command===h.clipboard?or(e):e.command===h.push?sr(e,`app`,`payload`):e.command===h.triggerAppEvent?sr(e,`event`,`payload`):e.positionals.map(V)}function ir(e){let t=H(`text`),n=e.result??{},r=G(n);if(r)return[`@${r}`,t];if(N(n.selector))return[H(`target`),t];let i=z(n.x),a=z(n.y);return i!==void 0&&a!==void 0?[String(i),String(a),t]:[t]}function ar(e){let t=+!!ur(e.positionals[0]);if(e.positionals[t]===void 0)return;let n=t+1,r=[...t===1?[String(e.positionals[0])]:[],H(`query`)],i=e.positionals[n];return i?i===`fill`||i===`type`?[...r,i,H(`text`)]:[...r,...e.positionals.slice(n).map(cr)]:r}function or(e){let t=e.positionals[0]?.toLowerCase();return t===`read`?[`read`]:t===`write`?[`write`,H(`text`)]:e.positionals.map(V)}function sr(e,t,n){let[r,i,...a]=e.positionals;return[...r?[H(t)]:[],...i?[H(n)]:[],...a.map(V)]}function cr(e){return e===`click`||e===`focus`||e===`exists`||e===`get`||e===`text`||e===`attrs`||e===`wait`?e:V(e)}function V(e){return lr(e)??H(`arg`)}function lr(e){if(!e)return;let t=e.trim();if(/^@[a-zA-Z0-9:_-]+$/.test(t))return t}function H(e){return`<${e}>`}function ur(e){return e===`text`||e===`label`||e===`value`||e===`role`||e===`id`}function dr(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:void 0}const fr={enums:[{source:`platform`,values:a},{source:`target`,values:o}]},pr={booleans:[{source:`settle`}],numbers:[{source:`settleQuietMs`}]},mr={[h.open]:{booleans:[{source:`relaunch`},{source:`testIme`}],enums:[{source:`surface`,values:Re}]},[h.click]:U(),[h.press]:U(),[h.longPress]:U(),[h.hover]:U(),[h.fill]:_r(),[h.type]:_r(),[h.scroll]:{numbers:[{source:`pixels`},{source:`durationMs`}]},[h.gesture]:vr(),[h.swipe]:vr(),[h.screenshot]:{booleans:[{source:`overlayRefs`},{source:`screenshotFullscreen`,output:`fullscreen`},{source:`screenshotNoStabilize`,output:`noStabilize`},{source:`screenshotNormalizeStatusBar`,output:`normalizeStatusBar`}],numbers:[{source:`screenshotPixelDensity`,output:`pixelDensity`},{source:`screenshotScale`,output:`scale`}]},[h.snapshot]:{booleans:[{source:`snapshotInteractiveOnly`,output:`interactiveOnly`},{source:`snapshotDiff`,output:`diff`},{source:`snapshotRaw`,output:`raw`},{source:`snapshotCustomActions`,output:`actions`},{source:`snapshotForceFull`,output:`forceFull`}],numbers:[{source:`snapshotDepth`,output:`depth`}]},[h.back]:{enums:[{source:`backMode`,output:`mode`,values:g}]},[h.record]:{booleans:[{source:`hideTouches`}],numbers:[{source:`fps`}],enums:[{source:`recordingScope`,output:`scope`,values:re}]},[h.apps]:{enums:[{source:`appsFilter`,output:`filter`,values:[`user-installed`,`all`]}]},[h.boot]:{booleans:[{source:`headless`}]},[h.close]:{booleans:[{source:`shutdown`}]}};function hr(e){let t=e.flags??{},n={},r=Object.hasOwn(mr,e.command)?mr[e.command]:void 0;return W(n,t,fr),W(n,t,r),W(n,t,gr(e.command)),Object.keys(n).length>0?n:void 0}function gr(e){return te(e)?pr:void 0}function U(){return{booleans:[{source:`doubleTap`}],numbers:[{source:`count`},{source:`intervalMs`},{source:`holdMs`},{source:`jitterPx`}],enums:[{source:`clickButton`,values:Be}]}}function _r(){return{numbers:[{source:`delayMs`}]}}function vr(){return{numbers:[{source:`pointerCount`},{source:`count`},{source:`pauseMs`}],enums:[{source:`pattern`,values:ie}]}}function W(e,t,n){n&&(yr(e,t,n.booleans??[]),br(e,t,n.numbers??[]),xr(e,t,n.enums??[]))}function yr(e,t,n){for(let r of n)Sr(e,r.output??r.source,t[r.source])}function br(e,t,n){for(let r of n)Cr(e,r.output??r.source,t[r.source])}function xr(e,t,n){for(let r of n)wr(e,r.output??r.source,t[r.source],r.values)}function G(e){let t=N(e.ref);if(!t)return;let n=t.startsWith(`@`)?t.slice(1):t;return/^[a-zA-Z0-9:_-]+$/.test(n)?n:void 0}function Sr(e,t,n){typeof n==`boolean`&&(e[t]=n)}function Cr(e,t,n){let r=z(n);r!==void 0&&(e[t]=r)}function wr(e,t,n,r){let i=F(n,r);i!==void 0&&(e[t]=i)}const Tr=65536;function Er(e){return qe(`sha256`).update(e,`utf8`).digest(`hex`).slice(0,32)}function K(e,t){let n=Ar(e);if(n===void 0)return!1;try{let e=Or(t),r=Buffer.allocUnsafe(Tr),i=0;do if(i=w.readSync(n,r,0,r.length,null),!e.push(r.subarray(0,i)))return!0;while(i>0);return e.end(),!0}finally{w.closeSync(n)}}async function Dr(e){let t=await jr(e);if(t===void 0)return{lineCount:0,firstLineDigest:void 0};let n={lineCount:0,firstLineDigest:void 0};try{let e=Or(e=>{n.lineCount===0&&(n.firstLineDigest=Er(e)),n.lineCount+=1}),r=Buffer.allocUnsafe(Tr);for(;;){let{bytesRead:n}=await t.read(r,0,r.length,null);if(e.push(r.subarray(0,n)),n===0)break}return e.end(),n}finally{await t.close()}}function q(e){let t;return K(e,e=>(t=Er(e),!1)),t}function Or(e){let t=new Je(`utf8`),n=``,r=!1;return{push(i){if(r)return!1;let a=`${n}${t.write(i)}`,o=0;for(let t=a.indexOf(`
|
|
1
|
+
import{M as e,X as t}from"./sdk-contracts.js";import{_ as n}from"./sdk-batch-runner.js";import{S as r,i,r as a,t as o}from"./sdk-device.js";import{$n as s,Qn as c,cn as l,on as ee,p as te,x as ne}from"./sdk-batch.js";import{t as re}from"./recording-scope.js";import{a as ie}from"./scroll-gesture.js";import{_ as u,c as ae,d as oe,g as se,h as ce,i as le,l as ue,m as de,o as fe,p as d,s as pe,u as f,y as me}from"./script.js";import{A as p,C as he,D as ge,E as _e,M as ve,N as ye,S as be,T as xe,_ as Se,a as Ce,b as we,g as m,i as Te,k as Ee,l as De,n as Oe,r as ke,s as Ae,t as je,v as Me,w as Ne,x as Pe,y as Fe}from"./parameterized-recorded-fill.js";import{n as h,t as Ie}from"./catalog.js";import{o as Le,t as g}from"./back-mode.js";import{t as Re}from"./session.js";import{r as ze}from"./success-text.js";import{t as Be}from"./click-button.js";import"./device.js";import{r as _,t as Ve}from"./device-rotation.js";import{a as v,r as y}from"./diagnostics.js";import{D as He}from"./owner-identity.js";import"./file.js";import{t as Ue}from"./tv-remote.js";import"./diagnostics2.js";import{n as We,r as Ge}from"./session-repair-tombstone.js";import{n as Ke,r as b,t as x}from"./session-paths.js";import{t as qe}from"./keyboard-actions.js";import S from"node:path";import C from"node:fs";import{createHash as Je}from"node:crypto";import{StringDecoder as Ye}from"node:string_decoder";function Xe(e,t={}){let n=[e.command];return e.command===`snapshot`?oe(n,e):e.command===`open`?le(n,e):e.command===`runtime`?ae(n,e,{includeAllPositionals:t.runtimeIncludeAllPositionals}):e.command===`record`?pe(n,e):e.command===`screenshot`?ue(n,e):fe(n,e),n.join(` `)}function Ze(e){return e.targetEvidences?[c(e.targetEvidences)]:e.targetEvidence?[s(e.targetEvidence)]:[]}function w(e){return e?.scriptPublication??m}function Qe(e,t){let n=w(e),r=typeof t.saveScript==`string`?x(t.saveScript):n.kind===`repair`?void 0:t.healedSiblingPath;e.scriptPublication=Me(n,{requested:{path:r,force:t.force===!0},boundary:t.firstArm?e.actions.length:0,sourcePath:t.sourcePath})}function $e(e){e.scriptPublication=we(w(e))}function et(e){e.scriptPublication=Ne(w(e))}function tt(e,t){e.scriptPublication=xe(w(e),t)}function nt(e){e.scriptPublication=Se(w(e))}function rt(e,t){let n=w(e);return n.kind===`repair`&&n.closeReceipt===t}function it(e){return w(e).kind===`repair`}function at(e){return he(w(e))}function T(e){return _e(w(e))}function ot(e){return ge(w(e))}function st(e,t){if(t.flags?.noRecord||_t(e,t))return;t.flags&&Ae(e,t.flags);let n=lt(t),r=ft(e,ut(t,n));n&&dt(e,n);let i={ts:Date.now(),command:r.command,positionals:r.positionals,runtime:r.runtime,flags:yt(r.flags),result:r.result,...r.targetEvidence?{targetEvidence:r.targetEvidence}:{},...r.targetEvidences?{targetEvidences:r.targetEvidences}:{}};return e.actions.push(i),y({level:`debug`,phase:`record_action`,data:{command:t.command,session:e.name}}),i}function ct(e,t,n,r,i,a){t&&e.recordAction(t,{command:r,positionals:a?.positionals??n.positionals??[],flags:a?.flags??n.flags??{},result:i??{}})}function lt(e){if(e.command!==`fill`||typeof e.flags.recordAs!=`string`)return;let t=ye(e.flags.recordAs),n=ve(t);return{literal:p({ts:0,command:e.command,positionals:e.positionals,flags:e.flags}),placeholder:n}}function ut(e,t){if(!t)return e;let{literal:n,placeholder:r}=t;return{...e,positionals:mt(e.positionals,r),result:je(e.result,n,r),targetEvidence:Oe(e.targetEvidence,n,r)}}function dt(e,t){t.literal.trim()&&(e.recordedFillLiterals??=new Map,!e.recordedFillLiterals.has(t.literal)&&e.recordedFillLiterals.set(t.literal,t.placeholder))}function ft(e,t){let n=e.recordedFillLiterals;if(!n||n.size===0)return t;let r=ke(t.result,n),i=(t.targetEvidenceMode??`action`)===`landmark`?pt(t.targetEvidence,n):E(t.targetEvidence,n),a=t.targetEvidences?{source:E(t.targetEvidences.source,n),destination:E(t.targetEvidences.destination,n)}:t.targetEvidences;return{...t,result:r,targetEvidence:i,targetEvidences:a}}function pt(e,t){return e&&(Ce(e,t)?void 0:e)}function E(e,t){return!e||!Ce(e,t)?e:{...Te(e,t),verification:`unverifiable`}}function mt(e,t){let n=e[0];return n?.startsWith(`@`)?e.length>=3?[n,e[1],t]:[n,t]:e.length>=3&&Number.isFinite(Number(e[0]))&&Number.isFinite(Number(e[1]))?[e[0],e[1],t]:n===void 0?[t]:[n,t]}const ht=new Set([`snapshot`,`get`,`is`,`find`]);function gt(e){return e.internal?.replayPlanStep!==!0&&ht.has(e.command)}function _t(e,t){return!t.interactiveObservation||T(e)===void 0?!1:t.flags?.record!==!0}const vt=Le();function yt(e){if(!e)return{};let t={};for(let n of vt){let r=e[n];r!==void 0&&(t[n]=r)}return t}function D(e){return S.join(e,`idle-expiry.json`)}function bt(e){let t;try{t=C.readFileSync(e,`utf8`)}catch{return}let n;try{n=JSON.parse(t)}catch{return}if(!(typeof n?.expiresAt!=`number`||!Number.isFinite(n.expiresAt))&&!(n.expiresAt<=Date.now())&&typeof n.owner==`string`&&!(!xt(n.expiredAtMs)||!xt(n.idleExpiryMs))&&(n.deviceKey===void 0||typeof n.deviceKey==`string`))return n}function xt(e){return typeof e==`number`&&Number.isFinite(e)&&e>=0}function St(t){let n=t.flatMap((e,t)=>e.command===`open`?[t]:[]);if(n.length!==1||n[0]!==0)throw new e(`COMMAND_FAILED`,`Cannot publish this session: an open-to-destination script requires exactly one initial recorded open.`,{retriable:!1,hint:`Close this session and start a fresh one with open <app> --save-script[=<path>].`});if(t.some(e=>e.command===`close`))throw new e(`COMMAND_FAILED`,`Cannot publish an active-session script containing close.`,{retriable:!1,hint:`Close this session and record the journey again from a fresh open --save-script session.`});let r=-1;for(let[e,n]of t.entries())ne({command:n.command,positionals:n.positionals,flags:n.flags})===`mutates-app`&&(r=e);if(!t.slice(r+1).some(Ot))throw new e(`COMMAND_FAILED`,`Cannot publish this session without a portable destination guard after the final mutating action.`,{retriable:!0,hint:`Record a selector-targeted wait on a labeled or id-bearing landmark, for example wait 'role="heading" label="Screen X"', so its recorded identity is captured, then retry session save-script.`})}function Ct(t){for(let n of t){if(wt(n)){Tt(n);continue}let t=kt(n),r=t??(n.command===`wait`?n.positionals[0]:void 0);if(r?.startsWith(`@`))throw new e(`COMMAND_FAILED`,`Cannot publish recorded step "${n.command} ${r}": the session-local ref was not converted to a portable selector.`,{retriable:!1,hint:`Close this session and record the journey again using selectors or resolvable refs.`});if(n.command===`find`&&ne(n)===`mutates-app`)throw new e(`COMMAND_FAILED`,`Cannot publish a recorded mutating find step because its target identity is not replay-verifiable.`,{retriable:!1,hint:`Close this session and record the journey again with an explicit selector-targeted click, press, fill, or focus action.`});let i=t;if(!(!i||!l(i)||n.targetEvidence))throw new e(`COMMAND_FAILED`,`Cannot publish recorded step "${n.command} ${i}": recording-time target identity evidence is missing.`,{retriable:!1,hint:`Close this session and record the journey again from open --save-script so target-v1 evidence is captured before each interaction.`})}}function wt(e){return Et(e)!==void 0}function Tt(t){let n=Et(t);if(!n)return;let r=[n.source,n.destination];for(let n of r){if(n?.startsWith(`@`))throw new e(`COMMAND_FAILED`,`Cannot publish recorded drag endpoint "${n}": the session-local ref was not converted to a portable selector.`,{retriable:!1});if(!(!n||!l(n))&&!t.targetEvidences)throw new e(`COMMAND_FAILED`,`Cannot publish recorded drag endpoint "${n}": recording-time target identity evidence is missing.`,{retriable:!1,hint:`Close this session and record the journey again so targets-v1 evidence is captured for both drag endpoints.`})}}function Et(e){return e.command===`gesture`?me(e.positionals):void 0}function Dt(t,n){if(t instanceof e){if(t.details?.reason===`script_target_exists`)return new e(t.code,`A file already exists at ${String(t.details.path)}.`,{...t.details,retriable:!0,hint:`Retry session save-script with another path, or pass --force to replace the existing file. The session remains armed.`});let n=t.details?.retriable===!0;return new e(t.code,t.message,{...t.details,retriable:n,hint:t.details?.hint??(n?`Fix the recorded journey or target, then retry session save-script. The session remains armed.`:`Close this session and start a fresh one with open <app> --save-script[=<path>].`)})}let r=t instanceof Error?t.message:String(t);return new e(`COMMAND_FAILED`,`Failed to publish the active session script${n?` to ${n}`:``}: ${r}`,{retriable:!0,hint:`Check the target path and permissions, then retry session save-script. The session remains armed.`})}function Ot(e){if(e.command!==`wait`)return!1;let t=ee(e.positionals);return t?.kind!==`selector`||!l(t.selectorExpression)?!1:e.targetEvidence?.verification===`verified`}function kt(e){if(e.command===`get`)return e.positionals[1];if(se(e.command)||e.command===`fill`){let[t,n]=e.positionals;return t!==void 0&&n!==void 0&&At(t)&&At(n)?void 0:t}}function At(e){return e.trim().length>0&&Number.isFinite(Number(e))}function jt(e){let t=e.scriptPublication??m;return t.kind===`repair`?t.status===`committed`||!be(t):!1}function Mt(e){return!Pe(e.scriptPublication??m)||jt(e)}var Nt=class{sessionsDir;constructor(e){this.sessionsDir=e}write(e,t){let n=it(e),r=t?.publication===`active`,i;try{if(Mt(e))return{written:!1};let a=Pt(e,{appendCompleteSentinel:n,activePublication:r});i=this.resolveScriptPath(e);let o=S.dirname(i);return C.existsSync(o)||C.mkdirSync(o,{recursive:!0}),Lt({scriptPath:i,script:a.script,force:t?.force}),n&&(e.scriptPublication=Fe(e.scriptPublication??m)),{written:!0,path:i,actionCount:a.actionCount}}catch(t){return Ft({session:e,error:t,scriptPath:i,repairArmed:n,activePublication:r})}}resolveScriptPath(e){let t=Ee(e.scriptPublication??m);if(t)return x(t);let n=b(e.name),r=new Date(e.createdAt).toISOString().replaceAll(/[:.]/g,`-`);return S.join(this.sessionsDir,`${n}-${r}.ad`)}};function Pt(e,t){let n=Rt(e,{strictPortableRefs:t.activePublication});return t.activePublication&&St(n),{script:Jt(e,n,t.appendCompleteSentinel),actionCount:n.length}}function Ft(t){let{session:n,error:r,scriptPath:i,repairArmed:a,activePublication:o}=t;if(y({level:`warn`,phase:`session_script_write_failed`,data:{session:n.name,path:i,error:r instanceof Error?r.message:String(r)}}),a)return{written:!1,error:It(r,i)};if(o)return{written:!1,error:Dt(r,i)};if(r instanceof e)throw r;return{written:!1}}function It(t,n){if(t instanceof e)return t;let r=t instanceof Error?t.message:String(t);return new e(`COMMAND_FAILED`,`Failed to write the healed script${n?` to ${n}`:``}: ${r}`,{hint:`The repair transaction completed but the healed .ad could not be published; check the target path and permissions, then retry close --save-script.`})}function Lt(t){let{scriptPath:n,script:r,force:i}=t;try{He({destination:n,contents:r,publish:i?`replace`:`link-exclusive`})}catch(t){throw t.code===`EEXIST`?new e(`COMMAND_FAILED`,`A file already exists at ${n}; remove it, pass replay --save-script=<other-path>, or pass --force/--overwrite to replace it.`,{reason:`script_target_exists`,path:n}):t}}function Rt(e,t={}){let n=T(e),r=n!==void 0,i=e.actions.slice(n??0),a=[];for(let n of i){if(n.command===`snapshot`)continue;let i=Vt(n);if(i){a.push(i);continue}(r||t.strictPortableRefs)&&zt(n);let o=qt(e,n);o&&a.push(o),a.push(n)}return t.strictPortableRefs&&Ct(a),a}function zt(t){let n=t.command===`gesture`?me(t.positionals??[]):void 0;if(n){Bt(n);return}if(!O(t.command))return;let r=t.command===`get`?t.positionals?.[1]:t.positionals?.[0];if(r?.startsWith(`@`))throw new e(`COMMAND_FAILED`,`Cannot write recorded step "${t.command} ${r}" to a script: it never resolved to a selector, so the ref would not resolve in a fresh replay session.`)}function Bt(t){let n=[t.source,t.destination].find(e=>e.startsWith(`@`));if(n)throw new e(`COMMAND_FAILED`,`Cannot write recorded drag endpoint "${n}" to a script: it never resolved to a selector, so the ref would not resolve in a fresh replay session.`)}function Vt(e){let t=Ht(e);if(!(!t||!O(e.command)))return ce(e.command)||e.command===`hover`?{...e,positionals:[t]}:e.command===`longpress`?Wt(e,t):e.command===`fill`?Ut(e,t):Gt(e,t)}function Ht(e){let t=Array.isArray(e.result?.selectorChain)&&e.result.selectorChain.every(e=>typeof e==`string`)?e.result.selectorChain:[];return t.length>0?t.join(` || `):void 0}function O(e){return se(e)||e===`fill`||e===`get`}function Ut(e,t){let n=p(e);return n.length>0?{...e,positionals:[t,n]}:void 0}function Wt(e,t){let n=typeof e.result?.durationMs==`number`?String(e.result.durationMs):Kt(e.positionals??[]);return{...e,positionals:n?[t,n]:[t]}}function Gt(e,t){let n=e.positionals?.[0];return n===`text`||n===`attrs`?{...e,positionals:[n,t]}:void 0}function Kt(e){let t=e.at(-1);if(!(e.length<=1||t===void 0||t.trim()===``))return Number.isFinite(Number(t))?t:void 0}function qt(e,t){if(!O(t.command))return;let n=t.result?.refLabel;if(typeof n!=`string`||n.trim().length===0)return;let r=n.trim();return{ts:t.ts,command:`snapshot`,positionals:[],flags:{platform:e.device.platform,snapshotInteractiveOnly:!0,snapshotScope:r},result:{scope:r}}}function Jt(e,t,n){let i=[],a=e.device.kind?` kind=${e.device.kind}`:``;i.push(`context platform=${r(e.device)} device=${de(e.device.name)}${a} theme=unknown`);for(let e of t)e.flags?.noRecord||(i.push(...Ze(e)),i.push(Yt(e)));return n&&i.push(`# agent-device:heal-complete`),`${i.join(`
|
|
2
|
+
`)}\n`}function Yt(e){return Xt([e.command],e)||Xe(e)}function Xt(e,t){if(ce(t.command))return Zt(e,t);if(t.command===`fill`)return Qt(e,t);if(t.command===`get`)return $t(e,t)}function Zt(e,t){let n=t.positionals?.[0];if(n){if(n.startsWith(`@`))return e.push(d(u(n))),k(e,t),f(e,t),e.join(` `);if(t.positionals.length===1)return e.push(d(n)),f(e,t),e.join(` `)}}function Qt(e,t){let n=t.positionals?.[0];if(!n?.startsWith(`@`))return;e.push(d(u(n))),k(e,t);let r=t.positionals.slice(1).join(` `);return t.positionals.length>1&&e.push(d(r)),f(e,t),e.join(` `)}function $t(e,t){let n=t.positionals?.[0],r=t.positionals?.[1];if(!(!n||!r))return e.push(d(n)),e.push(d(u(r))),r.startsWith(`@`)&&k(e,t),e.join(` `)}function k(e,t){let n=t.result?.refLabel;typeof n==`string`&&n.trim().length>0&&e.push(d(n))}const en=[`id`,`deviceId`,`device_id`,`serial`,`udid`,`device_udid`,`identifier`],tn={ios:`iOS`,ipados:`iPadOS`,tvos:`tvOS`,watchos:`watchOS`,visionos:`visionOS`,macos:`macOS`,apple:`Apple`,android:`Android`,linux:`Linux`,web:`Web`};function nn(e,t){let n=t??{};switch(e.command){case h.devices:return rn(n.devices);case h.apps:return an(n.apps,e.flags?.appsFilter);case h.boot:return on(`Booted`,n,!0);case h.shutdown:return on(`Shut down`,n,!1);case h.install:return sn(`Installed`,n);case h.reinstall:return sn(`Reinstalled`,n);case h.screenshot:return cn(e,n);default:return{}}}function rn(e){if(!Array.isArray(e))return{};let t=e.flatMap(e=>{let t=un(e);return t?[t]:[]}),n=t.slice(0,5),r=Math.max(0,t.length-n.length),i=t.slice(0,3);return{summary:yn(`Found ${t.length} ${bn(`device`,t.length)}`,i.map(e=>_n(e,!0)),Math.max(0,t.length-i.length)),details:{deviceCount:t.length,devices:n,...r>0?{omittedDeviceCount:r}:{}}}}function an(e,t){if(!Array.isArray(e))return{};let n=e.flatMap(e=>{let t=M(e);return t?[t]:[]}),r=n.slice(0,5),i=Math.max(0,n.length-r.length),a=n.slice(0,3);return{summary:yn(`Found ${n.length} ${bn(`app`,n.length)}`,a,Math.max(0,n.length-a.length)),details:{appCount:n.length,apps:r,...i>0?{omittedAppCount:i}:{},...t===`all`||t===`user-installed`?{filter:t}:{}}}}function on(e,t,n){let r=dn(t);if(!r)return{};let i={device:r,...gn(t),booted:n};return{summary:`${e} ${_n(i,!1)}`,details:i}}function sn(e,t){let n=M(t.appName),r=M(t.bundleId),i=A(t,[`packageName`,`package`]),a=M(t.platform),o=M(t.launchTarget),s=A(t,[`bundleId`,`packageName`,`package`,`appId`,`launchTarget`]),c=vn(n,s);if(!c)return{};let l={};return j(l,`appName`,n),j(l,`bundleId`,r),j(l,`packageName`,i),j(l,`platform`,a),o!==s&&j(l,`launchTarget`,o),{summary:`${e} ${c}`,details:l}}function cn(e,t){let n=ln(e,t);return n?{details:{requestedFileName:n}}:{}}function ln(e,t){let n=R(e.meta?.clientArtifactPaths?.path)??R(t.path);if(n)return L(n)}function un(e){if(!n(e))return;let t=dn(e);if(t)return{name:t,...gn(e)}}function dn(e){let t=A(e,[`name`,`deviceName`,`device`]);return!t||!fn(e,t)?t:mn(e)}function fn(e,t){let n=pn(t);return en.some(t=>{let r=M(e[t]);return r!==void 0&&pn(r)===n})}function pn(e){return e.toLowerCase()}function mn(e){let t=M(e.appleOs),n=M(e.platform),r=M(e.kind),i=hn(t,n);return i&&(r===`simulator`||r===`emulator`)?`${i} ${r}`:i?`${i} device`:r===`simulator`?`Simulator`:r===`emulator`?`Emulator`:`Unnamed device`}function hn(e,t){let n=e??t;if(!(!n||!Object.hasOwn(tn,n)))return tn[n]}function gn(e){let t=M(e.platform),n=M(e.appleOs),r=M(e.kind),i=M(e.target);return{...t?{platform:t}:{},...n?{appleOs:n}:{},...r?{kind:r}:{},...i?{target:i}:{},...typeof e.booted==`boolean`?{booted:e.booted}:{}}}function _n(e,t){let n=M(e.name)??M(e.device)??`device`,r=M(e.platform),i=M(e.appleOs),a=[r,i===r?void 0:i,M(e.kind),M(e.target),t&&typeof e.booted==`boolean`?e.booted?`booted`:`stopped`:void 0].filter(e=>!!e);return a.length>0?`${n} (${a.join(`, `)})`:n}function vn(e,t){return e&&t&&e!==t?`${e} (${t})`:e??t}function A(e,t){for(let n of t){let t=M(e[n]);if(t)return t}}function j(e,t,n){n&&(e[t]=n)}function yn(e,t,n){let r=[...t,...n>0?[`+${n} more`]:[]];return r.length>0?`${e}: ${r.join(`, `)}`:e}function bn(e,t){return t===1?e:`${e}s`}function M(e){let t=R(e);if(!t)return;let n=t.trim(),r=Array.from(n);return r.length<=120?n:`${r.slice(0,119).join(``)}…`}function N(e){return M(e)}function P(e){return typeof e==`boolean`?e:void 0}function F(e,t){let n=N(e);return n&&t.includes(n)?n:void 0}function I(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function L(e){let t=R(e);return t?M(t.split(/[\\/]/).at(-1)):void 0}function R(e){if(typeof e==`string`)return e.trim().length>0?e:void 0}function z(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}const xn=[`up`,`down`,`left`,`right`],Sn=[`top`,`bottom`];function Cn(e){return`${e.command===h.reinstall?`Reinstalled`:`Installed`} ${Dn(e.result??{})??`app`}`}function wn(e){let t=e.result??{};switch(e.command){case h.scroll:return kn(t);case h.screenshot:return Mn(t);case h.home:return`Went home`;case h.back:return Pn(t);case h.appSwitcher:return`Opened app switcher`;case h.actionButton:return`Pressed Action Button`;case h.orientation:return In(t);case h.fold:return Fn(t);case h.viewport:return Ln(t);case h.clipboard:return Rn(t);case h.keyboard:return zn(t);case h.tvRemote:return Hn(t);case h.gesture:return Un(t);case h.swipe:return Wn(t);case h.trace:return Kn(`trace`,e);case h.record:return Kn(`recording`,e);default:return}}function Tn(e){let t=e.result??{};switch(e.command){case h.scroll:return I({direction:F(t.direction,xn),edge:F(t.edge,Sn),passes:z(t.passes),amount:z(t.amount),pixels:z(t.pixels),durationMs:z(t.durationMs),x1:z(t.x1),y1:z(t.y1),x2:z(t.x2),y2:z(t.y2)});case h.screenshot:return I({requestedFileName:Nn(t)});case h.back:return I({mode:F(t.mode,g)});case h.orientation:return I({orientation:F(t.orientation,Ve)});case h.fold:return I({pose:F(t.pose,_)});case h.viewport:return I({width:z(t.width),height:z(t.height)});case h.clipboard:return I({action:F(t.action,[`read`,`write`])});case h.keyboard:return Vn(t);case h.tvRemote:return I({button:F(t.button,Ue),durationMs:z(t.durationMs)});case h.gesture:case h.swipe:return Gn(t);case h.trace:case h.record:return I({action:F(t.action,[`start`,`stop`]),fileName:Jn(e),showTouches:P(t.showTouches)});default:return{}}}function En(e,t){if(e.command!==h.screenshot)return t;let n=ln(e,t);return n?{...t,requestedFileName:n}:t}function Dn(e){let t=N(e.appName),n=Yn(e,[`bundleId`,`packageName`,`appBundleId`,`launchTarget`]);return t&&n&&t!==n?`${t} (${n})`:t??n??On(e)}function On(e){let t=N(e.app);return t&&!t.includes(`/`)&&!t.includes(`\\`)?t:void 0}function kn(e){let t=F(e.direction,xn),n=F(e.edge,Sn),r=z(e.passes);return n?An(n,r):t?jn(t,e):`Scrolled`}function An(e,t){return t===0?`Already at ${e}`:t===void 0?`Scrolled to ${e}`:`Scrolled to ${e} in ${t} ${t===1?`pass`:`passes`}`}function jn(e,t){let n=z(t.pixels);if(n!==void 0)return`Scrolled ${e} by ${n}px`;let r=z(t.amount);return r===void 0?`Scrolled ${e}`:`Scrolled ${e} by ${r}`}function Mn(e){let t=Nn(e);return t?`Captured screenshot ${t}`:`Captured screenshot`}function Nn(e){return L(e.requestedFileName)??L(e.path)}function Pn(e){return F(e.mode,g)===`system`?`Went back using system navigation`:`Went back`}function Fn(e){let t=F(e.pose,_);return t?`Folded to ${t}`:`Changed fold pose`}function In(e){let t=F(e.orientation,Ve);return t?P(e.confirmed)===!1?`Requested ${t} (unconfirmed)`:`Rotated to ${t}`:`Changed orientation`}function Ln(e){let t=z(e.width),n=z(e.height);return t!==void 0&&n!==void 0?`Set viewport to ${t}×${n}`:`Changed viewport`}function Rn(e){let t=F(e.action,[`read`,`write`]);return t===`read`?`Read clipboard`:t===`write`?`Updated clipboard`:`Used clipboard`}function zn(e){let t=R(e.action);if(!t||!qe(t))return`Used keyboard`;if(t===`dismiss`)return Bn(e);if(t===`enter`||t===`return`)return`Pressed keyboard return`;let n=P(e.visible);return n===void 0?`Inspected keyboard`:n?`Keyboard is visible`:`Keyboard is hidden`}function Bn(e){return P(e.dismissed)===!1?`Keyboard was already hidden`:`Dismissed keyboard`}function Vn(e){let t=R(e.action);return I({action:t&&qe(t)?t:void 0,platform:F(e.platform,[`ios`,`android`]),visible:P(e.visible),wasVisible:P(e.wasVisible),dismissed:P(e.dismissed),attempts:z(e.attempts),mechanism:F(e.mechanism,[`dismissKey`])})}function Hn(e){let t=F(e.button,Ue);return t?`Pressed TV remote ${t}`:`Used TV remote`}function Un(e){let t=F(e.kind,[`fling`,`pan`,`pinch`,`rotate`,`transform`]);return t?`Ran ${t} gesture`:`Ran gesture`}function Wn(e){let t=z(e.count);return t!==void 0&&t>1?`Swiped ${t} times`:`Swiped`}function Gn(e){return I({kind:F(e.kind,[`fling`,`pan`,`pinch`,`rotate`,`transform`]),durationMs:z(e.durationMs),pointerCount:z(e.pointerCount),x1:z(e.x1),y1:z(e.y1),x2:z(e.x2),y2:z(e.y2),count:z(e.count),pauseMs:z(e.pauseMs),pattern:F(e.pattern,[`one-way`,`ping-pong`]),scale:z(e.scale)})}function Kn(e,t){let n=qn(e,F(t.result?.action,[`start`,`stop`])),r=Jn(t);return r?`${n} ${r}`:n}function qn(e,t){return t===`start`?e===`trace`?`Started trace`:`Started recording`:t===`stop`?e===`trace`?`Stopped trace`:`Stopped recording`:e===`trace`?`Updated trace`:`Updated recording`}function Jn(e){let t=e.result??{};return L(t.requestedFileName)??L(t.outPath)??L(t.path)??L(e.positionals[1])}function Yn(e,t){for(let n of t){let t=N(e[n]);if(t)return t}}function Xn(e){switch(e.command){case h.open:return`Opened ${B(e)??`session`}`;case h.close:return`Closed ${N(e.result?.session)??`session`}`;case h.click:case h.press:return`Tapped ${B(e)??`target`}`;case h.longPress:return`Long pressed ${B(e)??`target`}`;case h.hover:return`Hovered ${B(e)??`target`}`;case h.fill:return`Filled ${B(e)??`target`}`;case h.type:return`Typed text`;case h.install:case h.reinstall:case Ie.installSource:return Cn(e);default:return wn(e)??`Ran ${e.command}`}}function Zn(e){return I({command:e.command,positionals:or(e),flags:vr(e),...Qn(e),...$n(e),...er(e),...Tn(e)})}function Qn(e){if(!tr(e.command))return{};let t=e.result??{};return I({ref:G(t),targetLabel:B(e),selectorChainLength:mr(t.selectorChain)?.length,x:z(t.x),y:z(t.y),x2:z(t.x2),y2:z(t.y2),durationMs:z(t.durationMs)})}function $n(e){if(!nr(e.command))return{};let t=e.result??{};return I({platform:F(t.platform,i),target:F(t.target,o),appName:N(t.appName),appBundleId:N(t.appBundleId),bundleId:N(t.bundleId),packageName:N(t.packageName),launchTarget:N(t.launchTarget)})}function er(e){let t=e.result??{};return e.command===h.snapshot?Array.isArray(t.nodes)?{nodeCount:t.nodes.length}:{}:e.command!==h.wait&&e.command!==h.find&&e.command!==h.get&&e.command!==h.is?{}:I({waitedMs:z(t.waitedMs),found:P(t.found)})}function tr(e){return e===h.click||e===h.press||e===h.longPress||e===h.hover||e===h.focus||e===h.fill}function nr(e){return e===h.open||e===h.install||e===h.reinstall||e===Ie.installSource}function B(e){let t=e.result??{};return rr(t)??ir(t)??ar(t)??fr(e.positionals[0])}function rr(e){let t=G(e);if(t)return t.startsWith(`@`)?t:`@${t}`}function ir(e){let t=z(e.x),n=z(e.y);if(t!==void 0&&n!==void 0)return`(${t}, ${n})`}function ar(e){return N(e.appName)??N(e.appBundleId)??N(e.bundleId)??N(e.packageName)}function or(e){if(e.positionals.length!==0)return e.command===h.type?[H(`text`)]:e.command===h.fill?sr(e):e.command===h.find?cr(e):e.command===h.clipboard?lr(e):e.command===h.push?ur(e,`app`,`payload`):e.command===h.triggerAppEvent?ur(e,`event`,`payload`):e.positionals.map(V)}function sr(e){let t=H(`text`),n=e.result??{},r=G(n);if(r)return[`@${r}`,t];if(N(n.selector))return[H(`target`),t];let i=z(n.x),a=z(n.y);return i!==void 0&&a!==void 0?[String(i),String(a),t]:[t]}function cr(e){let t=+!!pr(e.positionals[0]);if(e.positionals[t]===void 0)return;let n=t+1,r=[...t===1?[String(e.positionals[0])]:[],H(`query`)],i=e.positionals[n];return i?i===`fill`||i===`type`?[...r,i,H(`text`)]:[...r,...e.positionals.slice(n).map(dr)]:r}function lr(e){let t=e.positionals[0]?.toLowerCase();return t===`read`?[`read`]:t===`write`?[`write`,H(`text`)]:e.positionals.map(V)}function ur(e,t,n){let[r,i,...a]=e.positionals;return[...r?[H(t)]:[],...i?[H(n)]:[],...a.map(V)]}function dr(e){return e===`click`||e===`focus`||e===`exists`||e===`get`||e===`text`||e===`attrs`||e===`wait`?e:V(e)}function V(e){return fr(e)??H(`arg`)}function fr(e){if(!e)return;let t=e.trim();if(/^@[a-zA-Z0-9:_-]+$/.test(t))return t}function H(e){return`<${e}>`}function pr(e){return e===`text`||e===`label`||e===`value`||e===`role`||e===`id`}function mr(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:void 0}const hr={enums:[{source:`platform`,values:a},{source:`target`,values:o}]},gr={booleans:[{source:`settle`}],numbers:[{source:`settleQuietMs`}]},_r={[h.open]:{booleans:[{source:`relaunch`},{source:`testIme`}],enums:[{source:`surface`,values:Re}]},[h.click]:U(),[h.press]:U(),[h.longPress]:U(),[h.hover]:U(),[h.fill]:br(),[h.type]:br(),[h.scroll]:{numbers:[{source:`pixels`},{source:`durationMs`}]},[h.gesture]:xr(),[h.swipe]:xr(),[h.screenshot]:{booleans:[{source:`overlayRefs`},{source:`screenshotFullscreen`,output:`fullscreen`},{source:`screenshotNoStabilize`,output:`noStabilize`},{source:`screenshotNormalizeStatusBar`,output:`normalizeStatusBar`}],numbers:[{source:`screenshotPixelDensity`,output:`pixelDensity`},{source:`screenshotScale`,output:`scale`}]},[h.snapshot]:{booleans:[{source:`snapshotInteractiveOnly`,output:`interactiveOnly`},{source:`snapshotDiff`,output:`diff`},{source:`snapshotRaw`,output:`raw`},{source:`snapshotCustomActions`,output:`actions`},{source:`snapshotForceFull`,output:`forceFull`}],numbers:[{source:`snapshotDepth`,output:`depth`}]},[h.back]:{enums:[{source:`backMode`,output:`mode`,values:g}]},[h.record]:{booleans:[{source:`hideTouches`}],numbers:[{source:`fps`}],enums:[{source:`recordingScope`,output:`scope`,values:re}]},[h.apps]:{enums:[{source:`appsFilter`,output:`filter`,values:[`user-installed`,`all`]}]},[h.boot]:{booleans:[{source:`headless`}]},[h.close]:{booleans:[{source:`shutdown`}]}};function vr(e){let t=e.flags??{},n={},r=Object.hasOwn(_r,e.command)?_r[e.command]:void 0;return W(n,t,hr),W(n,t,r),W(n,t,yr(e.command)),Object.keys(n).length>0?n:void 0}function yr(e){return te(e)?gr:void 0}function U(){return{booleans:[{source:`doubleTap`}],numbers:[{source:`count`},{source:`intervalMs`},{source:`holdMs`},{source:`jitterPx`}],enums:[{source:`clickButton`,values:Be}]}}function br(){return{numbers:[{source:`delayMs`}]}}function xr(){return{numbers:[{source:`pointerCount`},{source:`count`},{source:`pauseMs`}],enums:[{source:`pattern`,values:ie}]}}function W(e,t,n){n&&(Sr(e,t,n.booleans??[]),Cr(e,t,n.numbers??[]),wr(e,t,n.enums??[]))}function Sr(e,t,n){for(let r of n)Tr(e,r.output??r.source,t[r.source])}function Cr(e,t,n){for(let r of n)Er(e,r.output??r.source,t[r.source])}function wr(e,t,n){for(let r of n)Dr(e,r.output??r.source,t[r.source],r.values)}function G(e){let t=N(e.ref);if(!t)return;let n=t.startsWith(`@`)?t.slice(1):t;return/^[a-zA-Z0-9:_-]+$/.test(n)?n:void 0}function Tr(e,t,n){typeof n==`boolean`&&(e[t]=n)}function Er(e,t,n){let r=z(n);r!==void 0&&(e[t]=r)}function Dr(e,t,n,r){let i=F(n,r);i!==void 0&&(e[t]=i)}const Or=65536;function kr(e){return Je(`sha256`).update(e,`utf8`).digest(`hex`).slice(0,32)}function K(e,t){let n=Nr(e);if(n===void 0)return!1;try{let e=jr(t),r=Buffer.allocUnsafe(Or),i=0;do if(i=C.readSync(n,r,0,r.length,null),!e.push(r.subarray(0,i)))return!0;while(i>0);return e.end(),!0}finally{C.closeSync(n)}}async function Ar(e){let t=await Pr(e);if(t===void 0)return{lineCount:0,firstLineDigest:void 0};let n={lineCount:0,firstLineDigest:void 0};try{let e=jr(e=>{n.lineCount===0&&(n.firstLineDigest=kr(e)),n.lineCount+=1}),r=Buffer.allocUnsafe(Or);for(;;){let{bytesRead:n}=await t.read(r,0,r.length,null);if(e.push(r.subarray(0,n)),n===0)break}return e.end(),n}finally{await t.close()}}function q(e){let t;return K(e,e=>(t=kr(e),!1)),t}function jr(e){let t=new Ye(`utf8`),n=``,r=!1;return{push(i){if(r)return!1;let a=`${n}${t.write(i)}`,o=0;for(let t=a.indexOf(`
|
|
3
3
|
`);t!==-1;t=a.indexOf(`
|
|
4
|
-
`,o)){if(kr(a.slice(o,t),e)===!1)return r=!0,!1;o=t+1}return n=a.slice(o),!0},end(){r||kr(`${n}${t.end()}`,e)}}}function kr(e,t){let n=e.endsWith(`\r`)?e.slice(0,-1):e;if(n.trim().length!==0)return t(n)}function Ar(e){try{return w.openSync(e,`r`)}catch(e){if(e.code===`ENOENT`)return;throw e}}async function jr(e){try{return await w.promises.open(e,`r`)}catch(e){if(e.code===`ENOENT`)return;throw e}}const Mr=5242880;function Nr(e=process.env){let t=e.AGENT_DEVICE_EVENT_LOG_MAX_BYTES?.trim();if(t===void 0||!/^\d+$/.test(t))return Mr;let n=Number(t);return Number.isSafeInteger(n)&&n>0?n:Mr}function J(e){return`${e}.1`}function Y(e){return`${e}.window.json`}function Pr(e){let t;for(let n=0;n<3;n+=1){let n=Z(e);try{let t=Fr(e);if(Z(e)===n)return t}catch(r){if(t=r,Z(e)===n)throw r}}throw t??X(e,`the window did not settle while reading`)}function Fr(e){let t=J(e),n=Hr(e);if(n===`unverifiable`)throw X(e,`window file is invalid`);if(n===void 0)return Ir(e,t);let r=n.at(-1);if(!r)throw X(e,`window file records no generation`);let i=Gr(e),a=Lr(e,r),o=[],s=Rr({eventLogPath:e,rotatedPath:t,sidecar:n,activeStart:a,activeExists:i});return s!==void 0&&o.push({path:t,firstLineIndex:s}),i&&o.push({path:e,firstLineIndex:a}),{files:o,earliestCursor:o[0]?.firstLineIndex??a}}function Ir(e,t){if(q(t)!==void 0)throw X(e,`a rotated event log exists with no window record`);return{files:Gr(e)?[{path:e,firstLineIndex:0}]:[],earliestCursor:0}}function Lr(e,t){let n=q(e);return n!==void 0&&n===t.firstLineDigest?t.firstLineIndex:t.firstLineIndex+t.lineCount}function Rr(e){let{eventLogPath:t,rotatedPath:n,sidecar:r,activeStart:i,activeExists:a}=e,o=q(n);if(o===void 0)return;let s=r.find(e=>e.firstLineDigest===o);if(!s)throw X(t,`the rotated event log matches no window record`);let c=Vr(n);if(c!==s.lineCount)throw X(t,`the rotated event log holds ${c} lines, the window recorded ${s.lineCount}`);if(a&&s.firstLineIndex+s.lineCount!==i)throw X(t,`retained event log generations are not contiguous`);return s.firstLineIndex}async function zr(e,t){let n=Kr(e);if(!n||n.size<t)return!1;let r=Hr(e);if(r===`unverifiable`)return await w.promises.rename(e,J(e)),!0;let i=await Dr(e);if(i.firstLineDigest!==void 0){let t=r??[],n=t.at(-1),a=n&&n.firstLineDigest===i.firstLineDigest?n:{firstLineIndex:n?n.firstLineIndex+n.lineCount:0,lineCount:i.lineCount,firstLineDigest:i.firstLineDigest};await Wr(e,(a===n?t:[...t,a]).slice(-2))}return await w.promises.rename(e,J(e)),!0}function Br(e,n){if(!(e>=n))throw new t(`COMMAND_FAILED`,`events cursor ${e} precedes the retained event log window; events before cursor ${n} were rotated out.`,{reason:`EVENT_LOG_CURSOR_EXPIRED`,cursor:e,earliestCursor:n,hint:`Resume with cursor ${n}, the oldest retained event; earlier events are no longer available.`})}function X(e,n){return new t(`COMMAND_FAILED`,`Session event log window cannot be verified: ${n}.`,{reason:`EVENT_LOG_WINDOW_UNVERIFIED`,path:e,hint:`Cursor positions for this session cannot be resolved. Delete ${e}, ${J(e)}, and ${Y(e)} to restart the timeline, or read the files directly.`})}function Vr(e){let t=0;return K(e,()=>{t+=1}),t}function Z(e){return[Q(Y(e)),Q(e),Q(J(e))].join(`|`)}function Q(e){try{let t=w.lstatSync(e);return`${t.ino}:${t.size}:${t.mtimeMs}`}catch{return`absent`}}function Hr(e){let t;try{t=w.readFileSync(Y(e),`utf8`)}catch(e){return e.code===`ENOENT`?void 0:`unverifiable`}try{let e=JSON.parse(t);if(!n(e)||e.version!==2)return`unverifiable`;let{generations:r}=e;if(!Array.isArray(r)||r.length===0)return`unverifiable`;let i=r.map(Ur);return i.every(e=>e!==void 0)?i:`unverifiable`}catch{return`unverifiable`}}function Ur(e){if(!n(e))return;let{firstLineIndex:t,lineCount:r,firstLineDigest:i}=e;if(!(!Number.isSafeInteger(t)||t<0)&&!(!Number.isSafeInteger(r)||r<0)&&typeof i==`string`&&i.length!==0)return{firstLineIndex:t,lineCount:r,firstLineDigest:i}}async function Wr(e,t){let n=Y(e),r=`${n}.${process.pid}.tmp`;await w.promises.writeFile(r,JSON.stringify({version:2,generations:t}),`utf8`),await w.promises.rename(r,n)}function Gr(e){return Kr(e)!==void 0}function Kr(e){try{let n=w.lstatSync(e);if(n.isSymbolicLink())throw new t(`COMMAND_FAILED`,`Session event log must not be a symbolic link: ${e}`);return n}catch(e){if(e.code===`ENOENT`)return;throw e}}const $=new Map,qr=new Set;function Jr(e){return C.join(e,`events.ndjson`)}function Yr(e){return e.command!==h.events}function Xr(t,n,r){let i=e({version:1,ts:r.ts??new Date().toISOString(),session:n,...r});Qr(t,`${JSON.stringify(i)}\n`)}async function Zr(e){await(e?$.get(e):Promise.all($.values()))}function Qr(e,t){let n=($.get(e)??Promise.resolve()).catch(()=>void 0).then(async()=>{await $r(e),await zr(e,Nr()),await w.promises.appendFile(e,t,`utf8`)}).catch(t=>{b({level:`warn`,phase:`session_event_log_write_failed`,data:{path:e,error:t instanceof Error?t.message:String(t)}})}).finally(()=>{$.get(e)===n&&$.delete(e)});$.set(e,n)}async function $r(e){let t=C.dirname(e);if(!qr.has(t))try{await w.promises.mkdir(t,{recursive:!0}),qr.add(t)}catch(t){throw b({level:`warn`,phase:`session_event_log_dir_failed`,data:{path:e,error:t instanceof Error?t.message:String(t)}}),t}}function ei(e,t,n){Xr(e,t,{kind:`action.recorded`,requestId:y().requestId,command:n.command,summary:qn(n),details:Jn(n)})}function ti(e){let{req:t}=e;return{kind:`request.started`,requestId:t.meta?.requestId??y().requestId,command:t.command,summary:`Started ${t.command}`}}function ni(e){let{req:t,response:n,durationMs:r}=e;if(n.ok){let e=$t(t,n.data);return{kind:`request.finished`,requestId:t.meta?.requestId??y().requestId,command:t.command,status:`ok`,summary:e.summary??`Finished ${t.command}`,details:{durationMs:r,...e.details}}}return{kind:`request.finished`,requestId:t.meta?.requestId??y().requestId,command:t.command,status:`error`,summary:`Failed ${t.command}: ${n.error.code}`,details:{durationMs:r,code:n.error.code,diagnosticId:n.error.diagnosticId}}}function ri(e,t={}){let n=ai(t.cursor),r=oi(t.limit),i=Pr(e);Br(n,i.earliestCursor);let a=ii(i.files,n,r),o=a.lines.flatMap(e=>{let t=si(e);return t?[t]:[]});return{path:e,cursor:String(n),limit:r,events:o,...a.nextCursor===void 0?{}:{nextCursor:String(a.nextCursor)}}}function ii(e,t,n){let r=[],i;for(let a of e){let e=a.firstLineIndex;if(K(a.path,a=>{if(e>=t+n)return i=t+n,!1;e>=t&&r.push(a),e+=1}),i!==void 0)break}return{lines:r,...i===void 0?{}:{nextCursor:i}}}function ai(e){if(e===void 0||e.trim()===``)return 0;let n=Number(e);if(Number.isInteger(n)&&n>=0)return n;throw new t(`INVALID_ARGS`,`events cursor must be a non-negative integer string.`)}function oi(e){if(e===void 0||typeof e==`string`&&e.trim()===``)return 100;let n=typeof e==`string`?Number(e):e;if(Number.isInteger(n)&&n>=1&&n<=500)return n;throw new t(`INVALID_ARGS`,`events limit must be between 1 and 500.`)}function si(e){try{let t=ci(JSON.parse(e));return t?li(t):void 0}catch{return}}function ci(e){if(n(e)&&e.version===1&&typeof e.ts==`string`&&typeof e.session==`string`&&ui(e.kind))return e}function li(e){let t=n(e.details)?e.details:void 0;return{version:1,ts:e.ts,session:e.session,kind:e.kind,...typeof e.requestId==`string`?{requestId:e.requestId}:{},...typeof e.command==`string`?{command:e.command}:{},...di(e.status)?{status:e.status}:{},...typeof e.summary==`string`?{summary:e.summary}:{},...t?{details:t}:{}}}function ui(e){return e===`request.started`||e===`request.finished`||e===`action.recorded`}function di(e){return e===`ok`||e===`error`}const fi=36e5;var pi=class{sessions=new Map;runtimeHints=new Map;sessionsDir;scriptWriter;constructor(e){this.sessionsDir=e,this.scriptWriter=new At(e)}get(e){return this.sessions.get(e)}set(e,t){this.sessions.set(e,t)}delete(e){return this.runtimeHints.delete(e),this.sessions.delete(e)}values(){return this.sessions.values()}toArray(){return Array.from(this.sessions.values())}lookup(e){let t=this.sessions.get(e);return t?{address:e,session:t}:void 0}findByDevice(e){for(let[t,n]of this.sessions)if(n.device.id===e)return{address:t,session:n}}listRefs(){return Array.from(this.sessions,([e,t])=>({address:e,session:t}))}getRuntimeHints(e){return this.runtimeHints.get(e)}setRuntimeHints(e,t){this.runtimeHints.set(e,t)}clearRuntimeHints(e){return this.runtimeHints.delete(e)}recordAction(e,t){let n=ot(e,t);if(n){let t=this.resolveStoredSessionName(e);ei(this.resolveEventLogPath(t),t,n)}}recordEvent(e,t){Xr(this.resolveEventLogPath(e),e,t)}readEvents(e,t={}){return ri(this.resolveEventLogPath(e),t)}async flushEvents(e){await Zr(e?this.resolveEventLogPath(e):void 0)}writeSessionLog(e,t){let n=this.scriptWriter.write(e,t);return n.written&&b({level:`info`,phase:`session_script_written`,data:{session:e.name,path:n.path}}),n}finalizeRepairTeardown(e){this.recordRepairFinalizeCloseIfCommitting(e);let t=this.writeSessionLog(e,{force:De(e,void 0)});it(e)&&(!t.written&&t.error?this.writeRepairTombstone(e,fi,{code:String(t.error.code),message:t.error.message}):this.writeRepairTombstone(e))}recordRepairFinalizeCloseIfCommitting(e){let t=e.scriptPublication??m;be(t)&&this.recordAction(e,{command:`close`,positionals:[],flags:{},result:{session:e.name,...ze(`Closed: ${e.name}`)}})}writeRepairTombstone(e,t=fi,n){try{let r=this.resolveSessionDir(e.name);w.mkdirSync(r,{recursive:!0});let i={owner:e.name,reapedAt:Date.now(),expiresAt:Date.now()+t,...at(e)?{sourcePath:at(e)}:{},...n?{commitFailure:n}:{}};w.writeFileSync(this.repairTombstonePath(e.name),`${JSON.stringify(i)}\n`)}catch(t){b({level:`warn`,phase:`repair_tombstone_write_failed`,data:{session:e.name,error:t instanceof Error?t.message:String(t)}})}}readRepairTombstone(e){return Ue(this.repairTombstonePath(e))}clearRepairTombstone(e){try{w.rmSync(this.repairTombstonePath(e),{force:!0})}catch{}}repairTombstonePath(e){return We(this.resolveSessionDir(e))}defaultTracePath(e){let t=x(e.name),n=new Date().toISOString().replaceAll(/[:.]/g,`-`);return C.join(this.sessionsDir,`${t}-${n}.trace.log`)}resolveSessionDir(e){if(!Ge(e))throw new t(`INVALID_ARGS`,`Invalid session name ${JSON.stringify(e)}: a session name cannot be empty, ".", or "..".`);return C.join(this.sessionsDir,x(e))}resolveDaemonStateDir(){return C.dirname(this.sessionsDir)}ensureSessionDir(e){let t=this.resolveSessionDir(e);return w.mkdirSync(t,{recursive:!0}),t}resolveAppLogPath(e){return C.join(this.resolveSessionDir(e),`app.log`)}resolveAppLogPidPath(e){return C.join(this.resolveSessionDir(e),`app-log.pid`)}resolveEventLogPath(e){return Jr(this.resolveSessionDir(e))}static expandHome(e,t){return S(e,t)}resolveStoredSessionName(e){for(let[t,n]of this.sessions)if(n===e)return t;return e.name}};export{Qe as _,rr as a,st as c,nt as d,rt as f,E as g,et as h,Yr as i,tt as l,$e as m,ni as n,Cn as o,it as p,ti as r,ht as s,pi as t,Ze as u};
|
|
4
|
+
`,o)){if(Mr(a.slice(o,t),e)===!1)return r=!0,!1;o=t+1}return n=a.slice(o),!0},end(){r||Mr(`${n}${t.end()}`,e)}}}function Mr(e,t){let n=e.endsWith(`\r`)?e.slice(0,-1):e;if(n.trim().length!==0)return t(n)}function Nr(e){try{return C.openSync(e,`r`)}catch(e){if(e.code===`ENOENT`)return;throw e}}async function Pr(e){try{return await C.promises.open(e,`r`)}catch(e){if(e.code===`ENOENT`)return;throw e}}const Fr=5242880;function Ir(e=process.env){let t=e.AGENT_DEVICE_EVENT_LOG_MAX_BYTES?.trim();if(t===void 0||!/^\d+$/.test(t))return Fr;let n=Number(t);return Number.isSafeInteger(n)&&n>0?n:Fr}function J(e){return`${e}.1`}function Y(e){return`${e}.window.json`}function Lr(e){let t;for(let n=0;n<3;n+=1){let n=Z(e);try{let t=Rr(e);if(Z(e)===n)return t}catch(r){if(t=r,Z(e)===n)throw r}}throw t??X(e,`the window did not settle while reading`)}function Rr(e){let t=J(e),n=Gr(e);if(n===`unverifiable`)throw X(e,`window file is invalid`);if(n===void 0)return zr(e,t);let r=n.at(-1);if(!r)throw X(e,`window file records no generation`);let i=Jr(e),a=Br(e,r),o=[],s=Vr({eventLogPath:e,rotatedPath:t,sidecar:n,activeStart:a,activeExists:i});return s!==void 0&&o.push({path:t,firstLineIndex:s}),i&&o.push({path:e,firstLineIndex:a}),{files:o,earliestCursor:o[0]?.firstLineIndex??a}}function zr(e,t){if(q(t)!==void 0)throw X(e,`a rotated event log exists with no window record`);return{files:Jr(e)?[{path:e,firstLineIndex:0}]:[],earliestCursor:0}}function Br(e,t){let n=q(e);return n!==void 0&&n===t.firstLineDigest?t.firstLineIndex:t.firstLineIndex+t.lineCount}function Vr(e){let{eventLogPath:t,rotatedPath:n,sidecar:r,activeStart:i,activeExists:a}=e,o=q(n);if(o===void 0)return;let s=r.find(e=>e.firstLineDigest===o);if(!s)throw X(t,`the rotated event log matches no window record`);let c=Wr(n);if(c!==s.lineCount)throw X(t,`the rotated event log holds ${c} lines, the window recorded ${s.lineCount}`);if(a&&s.firstLineIndex+s.lineCount!==i)throw X(t,`retained event log generations are not contiguous`);return s.firstLineIndex}async function Hr(e,t){let n=Yr(e);if(!n||n.size<t)return!1;let r=Gr(e);if(r===`unverifiable`)return await C.promises.rename(e,J(e)),!0;let i=await Ar(e);if(i.firstLineDigest!==void 0){let t=r??[],n=t.at(-1),a=n&&n.firstLineDigest===i.firstLineDigest?n:{firstLineIndex:n?n.firstLineIndex+n.lineCount:0,lineCount:i.lineCount,firstLineDigest:i.firstLineDigest};await qr(e,(a===n?t:[...t,a]).slice(-2))}return await C.promises.rename(e,J(e)),!0}function Ur(t,n){if(!(t>=n))throw new e(`COMMAND_FAILED`,`events cursor ${t} precedes the retained event log window; events before cursor ${n} were rotated out.`,{reason:`EVENT_LOG_CURSOR_EXPIRED`,cursor:t,earliestCursor:n,hint:`Resume with cursor ${n}, the oldest retained event; earlier events are no longer available.`})}function X(t,n){return new e(`COMMAND_FAILED`,`Session event log window cannot be verified: ${n}.`,{reason:`EVENT_LOG_WINDOW_UNVERIFIED`,path:t,hint:`Cursor positions for this session cannot be resolved. Delete ${t}, ${J(t)}, and ${Y(t)} to restart the timeline, or read the files directly.`})}function Wr(e){let t=0;return K(e,()=>{t+=1}),t}function Z(e){return[Q(Y(e)),Q(e),Q(J(e))].join(`|`)}function Q(e){try{let t=C.lstatSync(e);return`${t.ino}:${t.size}:${t.mtimeMs}`}catch{return`absent`}}function Gr(e){let t;try{t=C.readFileSync(Y(e),`utf8`)}catch(e){return e.code===`ENOENT`?void 0:`unverifiable`}try{let e=JSON.parse(t);if(!n(e)||e.version!==2)return`unverifiable`;let{generations:r}=e;if(!Array.isArray(r)||r.length===0)return`unverifiable`;let i=r.map(Kr);return i.every(e=>e!==void 0)?i:`unverifiable`}catch{return`unverifiable`}}function Kr(e){if(!n(e))return;let{firstLineIndex:t,lineCount:r,firstLineDigest:i}=e;if(!(!Number.isSafeInteger(t)||t<0)&&!(!Number.isSafeInteger(r)||r<0)&&typeof i==`string`&&i.length!==0)return{firstLineIndex:t,lineCount:r,firstLineDigest:i}}async function qr(e,t){let n=Y(e),r=`${n}.${process.pid}.tmp`;await C.promises.writeFile(r,JSON.stringify({version:2,generations:t}),`utf8`),await C.promises.rename(r,n)}function Jr(e){return Yr(e)!==void 0}function Yr(t){try{let n=C.lstatSync(t);if(n.isSymbolicLink())throw new e(`COMMAND_FAILED`,`Session event log must not be a symbolic link: ${t}`);return n}catch(e){if(e.code===`ENOENT`)return;throw e}}const $=new Map,Xr=new Set;function Zr(e){return S.join(e,`events.ndjson`)}function Qr(e){return e.command!==h.events}function $r(e,n,r){let i=t({version:1,ts:r.ts??new Date().toISOString(),session:n,...r});ti(e,`${JSON.stringify(i)}\n`)}async function ei(e){await(e?$.get(e):Promise.all($.values()))}function ti(e,t){let n=($.get(e)??Promise.resolve()).catch(()=>void 0).then(async()=>{await ni(e),await Hr(e,Ir()),await C.promises.appendFile(e,t,`utf8`)}).catch(t=>{y({level:`warn`,phase:`session_event_log_write_failed`,data:{path:e,error:t instanceof Error?t.message:String(t)}})}).finally(()=>{$.get(e)===n&&$.delete(e)});$.set(e,n)}async function ni(e){let t=S.dirname(e);if(!Xr.has(t))try{await C.promises.mkdir(t,{recursive:!0}),Xr.add(t)}catch(t){throw y({level:`warn`,phase:`session_event_log_dir_failed`,data:{path:e,error:t instanceof Error?t.message:String(t)}}),t}}function ri(e,t,n){$r(e,t,{kind:`action.recorded`,requestId:v().requestId,command:n.command,summary:Xn(n),details:Zn(n)})}function ii(e){let{req:t}=e;return{kind:`request.started`,requestId:t.meta?.requestId??v().requestId,command:t.command,summary:`Started ${t.command}`}}function ai(e){let{req:t,response:n,durationMs:r}=e;if(n.ok){let e=nn(t,n.data);return{kind:`request.finished`,requestId:t.meta?.requestId??v().requestId,command:t.command,status:`ok`,summary:e.summary??`Finished ${t.command}`,details:{durationMs:r,...e.details}}}return{kind:`request.finished`,requestId:t.meta?.requestId??v().requestId,command:t.command,status:`error`,summary:`Failed ${t.command}: ${n.error.code}`,details:{durationMs:r,code:n.error.code,diagnosticId:n.error.diagnosticId}}}function oi(e,t={}){let n=ci(t.cursor),r=li(t.limit),i=Lr(e);Ur(n,i.earliestCursor);let a=si(i.files,n,r),o=a.lines.flatMap(e=>{let t=ui(e);return t?[t]:[]});return{path:e,cursor:String(n),limit:r,events:o,...a.nextCursor===void 0?{}:{nextCursor:String(a.nextCursor)}}}function si(e,t,n){let r=[],i;for(let a of e){let e=a.firstLineIndex;if(K(a.path,a=>{if(e>=t+n)return i=t+n,!1;e>=t&&r.push(a),e+=1}),i!==void 0)break}return{lines:r,...i===void 0?{}:{nextCursor:i}}}function ci(t){if(t===void 0||t.trim()===``)return 0;let n=Number(t);if(Number.isInteger(n)&&n>=0)return n;throw new e(`INVALID_ARGS`,`events cursor must be a non-negative integer string.`)}function li(t){if(t===void 0||typeof t==`string`&&t.trim()===``)return 100;let n=typeof t==`string`?Number(t):t;if(Number.isInteger(n)&&n>=1&&n<=500)return n;throw new e(`INVALID_ARGS`,`events limit must be between 1 and 500.`)}function ui(e){try{let t=di(JSON.parse(e));return t?fi(t):void 0}catch{return}}function di(e){if(n(e)&&e.version===1&&typeof e.ts==`string`&&typeof e.session==`string`&&pi(e.kind))return e}function fi(e){let t=n(e.details)?e.details:void 0;return{version:1,ts:e.ts,session:e.session,kind:e.kind,...typeof e.requestId==`string`?{requestId:e.requestId}:{},...typeof e.command==`string`?{command:e.command}:{},...mi(e.status)?{status:e.status}:{},...typeof e.summary==`string`?{summary:e.summary}:{},...t?{details:t}:{}}}function pi(e){return e===`request.started`||e===`request.finished`||e===`action.recorded`}function mi(e){return e===`ok`||e===`error`}const hi=36e5;var gi=class{sessions=new Map;runtimeHints=new Map;sessionsDir;scriptWriter;constructor(e){this.sessionsDir=e,this.scriptWriter=new Nt(e)}get(e){return this.sessions.get(e)}set(e,t){let n=this.sessions.has(e);this.sessions.set(e,t),n||this.clearIdleExpiryTombstone(e)}delete(e){return this.runtimeHints.delete(e),this.sessions.delete(e)}values(){return this.sessions.values()}toArray(){return Array.from(this.sessions.values())}lookup(e){let t=this.sessions.get(e);return t?{address:e,session:t}:void 0}findByDevice(e){for(let[t,n]of this.sessions)if(n.device.id===e)return{address:t,session:n}}listRefs(){return Array.from(this.sessions,([e,t])=>({address:e,session:t}))}getRuntimeHints(e){return this.runtimeHints.get(e)}setRuntimeHints(e,t){this.runtimeHints.set(e,t)}clearRuntimeHints(e){return this.runtimeHints.delete(e)}recordAction(e,t){let n=st(e,t);if(n){let t=this.resolveStoredSessionName(e);ri(this.resolveEventLogPath(t),t,n)}}recordEvent(e,t){$r(this.resolveEventLogPath(e),e,t)}readEvents(e,t={}){return oi(this.resolveEventLogPath(e),t)}async flushEvents(e){await ei(e?this.resolveEventLogPath(e):void 0)}writeSessionLog(e,t){let n=this.scriptWriter.write(e,t);return n.written&&y({level:`info`,phase:`session_script_written`,data:{session:e.name,path:n.path}}),n}finalizeRepairTeardown(e){this.recordRepairFinalizeCloseIfCommitting(e);let t=this.writeSessionLog(e,{force:De(e,void 0)});at(e)&&(!t.written&&t.error?this.writeRepairTombstone(e,hi,{code:String(t.error.code),message:t.error.message}):this.writeRepairTombstone(e))}recordRepairFinalizeCloseIfCommitting(e){let t=e.scriptPublication??m;be(t)&&this.recordAction(e,{command:`close`,positionals:[],flags:{},result:{session:e.name,...ze(`Closed: ${e.name}`)}})}writeRepairTombstone(e,t=hi,n){try{let r=this.resolveSessionDir(e.name);C.mkdirSync(r,{recursive:!0});let i={owner:e.name,reapedAt:Date.now(),expiresAt:Date.now()+t,...ot(e)?{sourcePath:ot(e)}:{},...n?{commitFailure:n}:{}};C.writeFileSync(this.repairTombstonePath(e.name),`${JSON.stringify(i)}\n`)}catch(t){y({level:`warn`,phase:`repair_tombstone_write_failed`,data:{session:e.name,error:t instanceof Error?t.message:String(t)}})}}readRepairTombstone(e){return We(this.repairTombstonePath(e))}clearRepairTombstone(e){try{C.rmSync(this.repairTombstonePath(e),{force:!0})}catch{}}noteSessionActivity(e,t=Date.now()){let n=this.sessions.get(e);n&&(n.lastActivityAtMs=t)}writeIdleExpiryTombstone(e,t){try{C.mkdirSync(this.resolveSessionDir(e),{recursive:!0}),C.writeFileSync(D(this.resolveSessionDir(e)),`${JSON.stringify(t)}\n`)}catch(t){y({level:`warn`,phase:`idle_expiry_tombstone_write_failed`,data:{session:e,error:t instanceof Error?t.message:String(t)}})}}readIdleExpiryTombstone(e){if(!Ke(e))return;let t=bt(D(this.resolveSessionDir(e)));return t?.owner===e?t:void 0}clearIdleExpiryTombstone(e){try{C.rmSync(D(this.resolveSessionDir(e)),{force:!0})}catch(t){y({level:`warn`,phase:`idle_expiry_tombstone_clear_failed`,data:{session:e,error:t instanceof Error?t.message:String(t)}})}}repairTombstonePath(e){return Ge(this.resolveSessionDir(e))}defaultTracePath(e){let t=b(e.name),n=new Date().toISOString().replaceAll(/[:.]/g,`-`);return S.join(this.sessionsDir,`${t}-${n}.trace.log`)}resolveSessionDir(t){if(!Ke(t))throw new e(`INVALID_ARGS`,`Invalid session name ${JSON.stringify(t)}: a session name cannot be empty, ".", or "..".`);return S.join(this.sessionsDir,b(t))}resolveDaemonStateDir(){return S.dirname(this.sessionsDir)}ensureSessionDir(e){let t=this.resolveSessionDir(e);return C.mkdirSync(t,{recursive:!0}),t}resolveAppLogPath(e){return S.join(this.resolveSessionDir(e),`app.log`)}resolveAppLogPidPath(e){return S.join(this.resolveSessionDir(e),`app-log.pid`)}resolveEventLogPath(e){return Zr(this.resolveSessionDir(e))}static expandHome(e,t){return x(e,t)}resolveStoredSessionName(e){for(let[t,n]of this.sessions)if(n===e)return t;return e.name}};export{$e as _,or as a,ct as c,rt as d,it as f,T as g,tt as h,Qr as i,nt as l,et as m,ai as n,En as o,at as p,ii as r,gt as s,gi as t,Qe as u};
|
package/dist/src/session.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./string-enum.js";const t=[`app`,`frontmost-app`,`desktop`,`menubar`],n=e(t,{normalize:e=>e.trim().toLowerCase(),message:e=>`Invalid surface: ${e}. Use ${t.join(`|`)}.`});function r(e){return n.parse(e)}export{r as n,t};
|
|
1
|
+
import{t as e}from"./string-enum.js";const t=[`app`,`frontmost-app`,`desktop`,`menubar`],n=e(t,{normalize:e=>e.trim().toLowerCase(),message:e=>`Invalid surface: ${e}. Use ${t.join(`|`)}.`});function r(e){return n.parse(e)}const i={app:`xctest`,"frontmost-app":`macos-helper`,desktop:`macos-helper`,menubar:`macos-helper`};function a(e){return i[e??`app`]}function o(e){return e!==void 0&&a(e)===`macos-helper`?e:void 0}export{r as i,o as n,a as r,t};
|