agent-device 0.10.2 → 0.10.3

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.
Files changed (195) hide show
  1. package/dist/src/376.js +3 -0
  2. package/dist/src/bin.js +74 -73
  3. package/dist/src/daemon.js +37 -37
  4. package/dist/src/index.d.ts +559 -5
  5. package/dist/src/index.js +3 -1
  6. package/package.json +2 -1
  7. package/skills/agent-device/SKILL.md +35 -12
  8. package/skills/agent-device/references/bootstrap-install.md +55 -15
  9. package/skills/agent-device/references/exploration.md +49 -7
  10. package/skills/agent-device/references/macos-desktop.md +1 -2
  11. package/skills/agent-device/references/remote-tenancy.md +15 -2
  12. package/skills/agent-device/references/verification.md +2 -3
  13. package/dist/src/224.js +0 -2
  14. package/dist/src/331.js +0 -3
  15. package/dist/src/425.js +0 -1
  16. package/dist/src/bin.d.ts +0 -1
  17. package/dist/src/cli-client-commands.d.ts +0 -8
  18. package/dist/src/cli.d.ts +0 -6
  19. package/dist/src/client-metro.d.ts +0 -64
  20. package/dist/src/client-normalizers.d.ts +0 -20
  21. package/dist/src/client-shared.d.ts +0 -20
  22. package/dist/src/client-types.d.ts +0 -269
  23. package/dist/src/client.d.ts +0 -5
  24. package/dist/src/core/app-events.d.ts +0 -8
  25. package/dist/src/core/batch.d.ts +0 -17
  26. package/dist/src/core/capabilities.d.ts +0 -3
  27. package/dist/src/core/click-button.d.ts +0 -20
  28. package/dist/src/core/dispatch-payload.d.ts +0 -1
  29. package/dist/src/core/dispatch-resolve.d.ts +0 -29
  30. package/dist/src/core/dispatch-series.d.ts +0 -7
  31. package/dist/src/core/dispatch.d.ts +0 -37
  32. package/dist/src/core/open-target.d.ts +0 -4
  33. package/dist/src/core/session-surface.d.ts +0 -3
  34. package/dist/src/core/settings-contract.d.ts +0 -9
  35. package/dist/src/daemon/action-utils.d.ts +0 -3
  36. package/dist/src/daemon/android-system-dialog.d.ts +0 -11
  37. package/dist/src/daemon/app-log-android.d.ts +0 -4
  38. package/dist/src/daemon/app-log-ios.d.ts +0 -7
  39. package/dist/src/daemon/app-log-process.d.ts +0 -15
  40. package/dist/src/daemon/app-log-stream.d.ts +0 -19
  41. package/dist/src/daemon/app-log.d.ts +0 -28
  42. package/dist/src/daemon/artifact-archive.d.ts +0 -12
  43. package/dist/src/daemon/artifact-download.d.ts +0 -12
  44. package/dist/src/daemon/artifact-materialization.d.ts +0 -17
  45. package/dist/src/daemon/artifact-registry.d.ts +0 -12
  46. package/dist/src/daemon/config.d.ts +0 -16
  47. package/dist/src/daemon/context.d.ts +0 -25
  48. package/dist/src/daemon/device-ready.d.ts +0 -6
  49. package/dist/src/daemon/handlers/find.d.ts +0 -40
  50. package/dist/src/daemon/handlers/install-source.d.ts +0 -44
  51. package/dist/src/daemon/handlers/interaction-common.d.ts +0 -41
  52. package/dist/src/daemon/handlers/interaction-flags.d.ts +0 -4
  53. package/dist/src/daemon/handlers/interaction-get.d.ts +0 -3
  54. package/dist/src/daemon/handlers/interaction-is.d.ts +0 -3
  55. package/dist/src/daemon/handlers/interaction-read.d.ts +0 -14
  56. package/dist/src/daemon/handlers/interaction-scroll.d.ts +0 -3
  57. package/dist/src/daemon/handlers/interaction-selector.d.ts +0 -27
  58. package/dist/src/daemon/handlers/interaction-snapshot.d.ts +0 -8
  59. package/dist/src/daemon/handlers/interaction-targeting.d.ts +0 -28
  60. package/dist/src/daemon/handlers/interaction-touch.d.ts +0 -45
  61. package/dist/src/daemon/handlers/interaction.d.ts +0 -9
  62. package/dist/src/daemon/handlers/lease.d.ts +0 -8
  63. package/dist/src/daemon/handlers/parse-utils.d.ts +0 -3
  64. package/dist/src/daemon/handlers/record-trace-android.d.ts +0 -18
  65. package/dist/src/daemon/handlers/record-trace-ios.d.ts +0 -52
  66. package/dist/src/daemon/handlers/record-trace-recording.d.ts +0 -32
  67. package/dist/src/daemon/handlers/record-trace.d.ts +0 -10
  68. package/dist/src/daemon/handlers/session-batch.d.ts +0 -2
  69. package/dist/src/daemon/handlers/session-close.d.ts +0 -31
  70. package/dist/src/daemon/handlers/session-deploy.d.ts +0 -37
  71. package/dist/src/daemon/handlers/session-device-utils.d.ts +0 -26
  72. package/dist/src/daemon/handlers/session-open-target.d.ts +0 -3
  73. package/dist/src/daemon/handlers/session-open.d.ts +0 -22
  74. package/dist/src/daemon/handlers/session-perf.d.ts +0 -2
  75. package/dist/src/daemon/handlers/session-replay-heal.d.ts +0 -8
  76. package/dist/src/daemon/handlers/session-replay-script.d.ts +0 -3
  77. package/dist/src/daemon/handlers/session-runtime-command.d.ts +0 -9
  78. package/dist/src/daemon/handlers/session-runtime.d.ts +0 -36
  79. package/dist/src/daemon/handlers/session-startup-metrics.d.ts +0 -11
  80. package/dist/src/daemon/handlers/session.d.ts +0 -50
  81. package/dist/src/daemon/handlers/snapshot-alert.d.ts +0 -13
  82. package/dist/src/daemon/handlers/snapshot-capture.d.ts +0 -34
  83. package/dist/src/daemon/handlers/snapshot-session.d.ts +0 -15
  84. package/dist/src/daemon/handlers/snapshot-settings.d.ts +0 -24
  85. package/dist/src/daemon/handlers/snapshot-wait.d.ts +0 -37
  86. package/dist/src/daemon/handlers/snapshot.d.ts +0 -16
  87. package/dist/src/daemon/http-server.d.ts +0 -26
  88. package/dist/src/daemon/install-source-resolution.d.ts +0 -5
  89. package/dist/src/daemon/is-predicates.d.ts +0 -15
  90. package/dist/src/daemon/lease-context.d.ts +0 -9
  91. package/dist/src/daemon/lease-registry.d.ts +0 -63
  92. package/dist/src/daemon/materialized-path-registry.d.ts +0 -15
  93. package/dist/src/daemon/network-log.d.ts +0 -32
  94. package/dist/src/daemon/record-trace-errors.d.ts +0 -6
  95. package/dist/src/daemon/recording-gestures.d.ts +0 -3
  96. package/dist/src/daemon/recording-telemetry.d.ts +0 -20
  97. package/dist/src/daemon/recording-timing.d.ts +0 -24
  98. package/dist/src/daemon/request-cancel.d.ts +0 -9
  99. package/dist/src/daemon/request-lock-policy.d.ts +0 -2
  100. package/dist/src/daemon/request-router.d.ts +0 -23
  101. package/dist/src/daemon/runtime-hints.d.ts +0 -19
  102. package/dist/src/daemon/script-utils.d.ts +0 -28
  103. package/dist/src/daemon/scroll-planner.d.ts +0 -12
  104. package/dist/src/daemon/selectors-build.d.ts +0 -5
  105. package/dist/src/daemon/selectors-match.d.ts +0 -6
  106. package/dist/src/daemon/selectors-parse.d.ts +0 -29
  107. package/dist/src/daemon/selectors-resolve.d.ts +0 -33
  108. package/dist/src/daemon/selectors.d.ts +0 -5
  109. package/dist/src/daemon/server-lifecycle.d.ts +0 -23
  110. package/dist/src/daemon/session-open-script.d.ts +0 -7
  111. package/dist/src/daemon/session-routing.d.ts +0 -3
  112. package/dist/src/daemon/session-selector.d.ts +0 -10
  113. package/dist/src/daemon/session-store.d.ts +0 -33
  114. package/dist/src/daemon/snapshot-diff.d.ts +0 -20
  115. package/dist/src/daemon/snapshot-processing.d.ts +0 -10
  116. package/dist/src/daemon/touch-reference-frame.d.ts +0 -7
  117. package/dist/src/daemon/transport.d.ts +0 -6
  118. package/dist/src/daemon/types.d.ts +0 -173
  119. package/dist/src/daemon/upload-registry.d.ts +0 -7
  120. package/dist/src/daemon/upload.d.ts +0 -5
  121. package/dist/src/daemon-client.d.ts +0 -40
  122. package/dist/src/daemon.d.ts +0 -1
  123. package/dist/src/platforms/android/adb.d.ts +0 -5
  124. package/dist/src/platforms/android/app-lifecycle.d.ts +0 -31
  125. package/dist/src/platforms/android/device-input-state.d.ts +0 -19
  126. package/dist/src/platforms/android/devices.d.ts +0 -26
  127. package/dist/src/platforms/android/index.d.ts +0 -8
  128. package/dist/src/platforms/android/input-actions.d.ts +0 -17
  129. package/dist/src/platforms/android/install-artifact.d.ts +0 -11
  130. package/dist/src/platforms/android/manifest.d.ts +0 -1
  131. package/dist/src/platforms/android/notifications.d.ts +0 -11
  132. package/dist/src/platforms/android/open-target.d.ts +0 -4
  133. package/dist/src/platforms/android/screenshot.d.ts +0 -16
  134. package/dist/src/platforms/android/sdk.d.ts +0 -2
  135. package/dist/src/platforms/android/settings.d.ts +0 -3
  136. package/dist/src/platforms/android/snapshot.d.ts +0 -7
  137. package/dist/src/platforms/android/ui-hierarchy.d.ts +0 -21
  138. package/dist/src/platforms/appearance.d.ts +0 -2
  139. package/dist/src/platforms/boot-diagnostics.d.ts +0 -14
  140. package/dist/src/platforms/install-source.d.ts +0 -29
  141. package/dist/src/platforms/ios/app-filter.d.ts +0 -2
  142. package/dist/src/platforms/ios/apps.d.ts +0 -34
  143. package/dist/src/platforms/ios/config.d.ts +0 -10
  144. package/dist/src/platforms/ios/devicectl.d.ts +0 -13
  145. package/dist/src/platforms/ios/devices.d.ts +0 -40
  146. package/dist/src/platforms/ios/ensure-simulator.d.ts +0 -18
  147. package/dist/src/platforms/ios/index.d.ts +0 -3
  148. package/dist/src/platforms/ios/install-artifact.d.ts +0 -18
  149. package/dist/src/platforms/ios/launch-diagnostics.d.ts +0 -11
  150. package/dist/src/platforms/ios/macos-apps.d.ts +0 -12
  151. package/dist/src/platforms/ios/macos-helper.d.ts +0 -69
  152. package/dist/src/platforms/ios/plist.d.ts +0 -1
  153. package/dist/src/platforms/ios/runner-client.d.ts +0 -38
  154. package/dist/src/platforms/ios/runner-errors.d.ts +0 -20
  155. package/dist/src/platforms/ios/runner-macos-products.d.ts +0 -3
  156. package/dist/src/platforms/ios/runner-session.d.ts +0 -30
  157. package/dist/src/platforms/ios/runner-transport.d.ts +0 -10
  158. package/dist/src/platforms/ios/runner-xctestrun-products.d.ts +0 -2
  159. package/dist/src/platforms/ios/runner-xctestrun.d.ts +0 -38
  160. package/dist/src/platforms/ios/screenshot-status-bar.d.ts +0 -2
  161. package/dist/src/platforms/ios/screenshot.d.ts +0 -14
  162. package/dist/src/platforms/ios/simctl.d.ts +0 -7
  163. package/dist/src/platforms/ios/simulator.d.ts +0 -11
  164. package/dist/src/platforms/permission-utils.d.ts +0 -9
  165. package/dist/src/recording/overlay.d.ts +0 -10
  166. package/dist/src/upload-client.d.ts +0 -7
  167. package/dist/src/utils/args.d.ts +0 -27
  168. package/dist/src/utils/cli-config.d.ts +0 -10
  169. package/dist/src/utils/cli-option-schema.d.ts +0 -19
  170. package/dist/src/utils/cli-options.d.ts +0 -13
  171. package/dist/src/utils/command-schema.d.ts +0 -123
  172. package/dist/src/utils/device-isolation.d.ts +0 -3
  173. package/dist/src/utils/device.d.ts +0 -35
  174. package/dist/src/utils/diagnostics.d.ts +0 -30
  175. package/dist/src/utils/errors.d.ts +0 -26
  176. package/dist/src/utils/exec.d.ts +0 -32
  177. package/dist/src/utils/finders.d.ts +0 -12
  178. package/dist/src/utils/interactors.d.ts +0 -38
  179. package/dist/src/utils/json-input.d.ts +0 -1
  180. package/dist/src/utils/keyed-lock.d.ts +0 -1
  181. package/dist/src/utils/output.d.ts +0 -27
  182. package/dist/src/utils/path-resolution.d.ts +0 -8
  183. package/dist/src/utils/payload-input.d.ts +0 -12
  184. package/dist/src/utils/process-identity.d.ts +0 -11
  185. package/dist/src/utils/remote-config.d.ts +0 -15
  186. package/dist/src/utils/remote-open.d.ts +0 -9
  187. package/dist/src/utils/retry.d.ts +0 -54
  188. package/dist/src/utils/screenshot-diff.d.ts +0 -23
  189. package/dist/src/utils/session-binding.d.ts +0 -18
  190. package/dist/src/utils/snapshot-lines.d.ts +0 -15
  191. package/dist/src/utils/snapshot.d.ts +0 -49
  192. package/dist/src/utils/text-surface.d.ts +0 -19
  193. package/dist/src/utils/timeouts.d.ts +0 -3
  194. package/dist/src/utils/version.d.ts +0 -2
  195. package/dist/src/utils/video.d.ts +0 -9
@@ -5,35 +5,58 @@ description: Automates interactions for Apple-platform apps (iOS, tvOS, macOS) a
5
5
 
6
6
  # agent-device
7
7
 
8
- Use this skill as a router.
8
+ Use this skill as a router with mandatory defaults. Read this file first. For normal device tasks, always load `references/bootstrap-install.md` and `references/exploration.md` before acting. Use bootstrap to confirm or establish deterministic setup. Use exploration for UI inspection, interaction, and verification once the app session is open.
9
+
10
+ ## Default operating rules
11
+
12
+ - Start conservative. Prefer read-only inspection before mutating the UI.
13
+ - Use plain `snapshot` when the task is to verify what text or structure is currently visible on screen.
14
+ - Use `snapshot -i` only when you need interactive refs such as `@e3` for a requested action or targeted query.
15
+ - Avoid speculative mutations. You may take the smallest reversible UI action needed to unblock inspection or complete the requested task, such as dismissing a popup, closing an alert, or clearing an unintended surface.
16
+ - Do not browse the web or use external sources unless the user explicitly asks.
17
+ - Re-snapshot after meaningful UI changes instead of reusing stale refs.
18
+ - Prefer `@ref` or selector targeting over raw coordinates.
19
+ - Ensure the correct target is pinned and an app session is open before interacting.
20
+ - Keep the loop short: `open` -> inspect/act -> verify if needed -> `close`.
21
+
22
+ ## Default flow
23
+
24
+ 1. Load [references/bootstrap-install.md](references/bootstrap-install.md) and [references/exploration.md](references/exploration.md) before acting on a normal device task.
25
+ 2. Use bootstrap first to confirm or establish the correct target, app install, and open app session.
26
+ 3. Once the app session is open and stable, use exploration for inspection, interaction, and verification.
27
+ 4. Start with plain `snapshot` if the goal is to read or verify what is visible.
28
+ 5. Escalate to `snapshot -i` only if you need refs for interactive exploration or a requested action.
29
+ 6. Use `get`, `is`, or `find` before mutating the UI when a read-only command can answer the question.
30
+ 7. End by capturing proof if needed, then `close`.
9
31
 
10
32
  ## QA modes
11
33
 
12
34
  - Open-ended bug hunt with reporting: use [../dogfood/SKILL.md](../dogfood/SKILL.md).
13
35
  - Pass/fail QA from acceptance criteria: stay in this skill, start with [references/bootstrap-install.md](references/bootstrap-install.md), then use the QA loop in [references/exploration.md](references/exploration.md).
14
36
 
15
- ## Mental model
37
+ ## Required references
16
38
 
17
- - First choose the correct target and open the app or session you want to work on.
18
- - Then inspect the current UI with `snapshot -i` and pick targets from the actual UI state.
19
- - Act with `press`, `fill`, `get`, `is`, `wait`, or `find`.
20
- - Re-snapshot after meaningful UI changes instead of reusing stale refs.
21
- - End by capturing proof if needed, then `close`.
39
+ - For every normal device task, after reading this file, load [references/bootstrap-install.md](references/bootstrap-install.md) first, then [references/exploration.md](references/exploration.md), before acting.
40
+ - Use bootstrap to confirm or establish deterministic setup, especially in sandbox or cloud environments.
41
+ - Use exploration once the app session is open and stable.
42
+ - Load additional references only when their scope is needed.
22
43
 
23
44
  ## Decision rules
24
45
 
25
46
  - Use plain `snapshot` when you need to verify whether text is visible.
26
47
  - Use `snapshot -i` mainly for interactive exploration and choosing refs.
48
+ - Use `get`, `is`, or `find` when they can answer the question without changing UI state.
27
49
  - Use `fill` to replace text.
28
50
  - Use `type` to append text.
51
+ - If there is no simulator, no app install, or no open app session yet, switch to `bootstrap-install.md` instead of improvising setup steps.
52
+ - Use the smallest unblock action first when transient UI blocks inspection, but do not navigate, search, or enter new text just to make the UI reveal data unless the user asked for that interaction.
53
+ - Do not use external lookups to compensate for missing on-screen data unless the user asked for them.
54
+ - If the needed information is not exposed on screen, say that plainly instead of compensating with extra navigation, text entry, or web search.
29
55
  - Prefer `@ref` or selector targeting over raw coordinates.
30
- - Keep the default loop short: `open` -> explore/act -> optional debug or verify -> `close`.
31
56
 
32
- ## Choose a reference
57
+ ## Additional references
33
58
 
34
- - Pick target device, install, open, or manage sessions: [references/bootstrap-install.md](references/bootstrap-install.md)
35
- - Need to discover UI, pick refs, wait, query, or interact: [references/exploration.md](references/exploration.md)
36
59
  - Need logs, network, alerts, permissions, or failure triage: [references/debugging.md](references/debugging.md)
37
60
  - Need screenshots, diff, recording, replay maintenance, or perf data: [references/verification.md](references/verification.md)
38
61
  - Need desktop surfaces, menu bar behavior, or macOS-specific interaction rules: [references/macos-desktop.md](references/macos-desktop.md)
39
- - Need to connect to a remote `agent-device` daemon over HTTP or use tenant leases: [references/remote-tenancy.md](references/remote-tenancy.md)
62
+ - Need remote HTTP transport, `--remote-config` launches, or tenant leases on a remote macOS host: [references/remote-tenancy.md](references/remote-tenancy.md)
@@ -2,37 +2,79 @@
2
2
 
3
3
  ## When to open this file
4
4
 
5
- Open this file when you still need to choose the right target, start the right session, install or relaunch the app, or pin automation to one device before interacting.
5
+ Open this file when you still need to choose the right target, start the right session, install or relaunch the app, or pin automation to one device before interacting. This is the deterministic setup layer for sandbox, cloud, or other environments where install paths, device state, or app readiness may be uncertain.
6
6
 
7
- ## Main commands to reach for first
7
+ ## Open-first path
8
8
 
9
9
  - `devices`
10
+ - `apps`
10
11
  - `ensure-simulator`
11
12
  - `open`
12
- - `install` or `reinstall`
13
- - `close`
14
13
  - `session list`
15
14
 
15
+ ## Install path
16
+
17
+ - `install` or `reinstall`
18
+
16
19
  ## Most common mistake to avoid
17
20
 
18
21
  Do not start acting before you have pinned the correct target and opened an `app` session. In mixed-device environments, always pass `--device`, `--udid`, or `--serial`.
19
22
 
20
- ## Canonical loop
23
+ ## Deterministic setup rule
24
+
25
+ If there is no simulator, no app install, no open app session, or any uncertainty about where the app should come from, stay in this file and use deterministic setup commands or bootstrap scripts first. Do not improvise install paths or app-launch flows while exploring.
26
+
27
+ After setup is confirmed or completed, move to `exploration.md` before doing UI inspection or interaction.
28
+
29
+ ## Open-first rule
30
+
31
+ - If the user asks to test an app and does not provide an install artifact or explicit install instruction, try `open <app>` first.
32
+ - If `open <app>` fails, run `agent-device apps` and retry with a discovered app name before considering install steps.
33
+ - Do not install or reinstall on the first attempt unless the user explicitly asks for installation or provides a concrete artifact path or URL.
34
+ - When installation is required from a known location, prefer a checked-in shell script or other deterministic bootstrap command over ad hoc path guessing.
35
+
36
+ - If `open <app>` fails, or you are not sure which app name is available on the target, run `agent-device apps` first and choose from the discovered app list instead of guessing.
37
+ - Use `apps --platform <platform>` together with `--device`, `--udid`, or `--serial` when target selection matters.
38
+ - Once you have the correct app name, retry `open` with that exact discovered value.
39
+
40
+ ## Common starting points
41
+
42
+ These are examples, not required exact sequences. Use the smallest setup flow that matches the task.
43
+
44
+ ### Boot a simulator and open an app
21
45
 
22
46
  ```bash
23
47
  agent-device ensure-simulator --platform ios --device "iPhone 17 Pro" --boot
24
48
  agent-device open MyApp --platform ios --device "iPhone 17 Pro" --relaunch
25
- agent-device snapshot -i
26
- agent-device close
27
49
  ```
28
50
 
51
+ ### Install an app artifact
52
+
53
+ ```bash
54
+ agent-device install com.example.app ./build/app.apk --platform android --serial emulator-5554
55
+ ```
56
+
57
+ ```bash
58
+ agent-device install com.example.app ./build/MyApp.app --platform ios --device "iPhone 17 Pro"
59
+ ```
60
+
61
+ ## Install guidance
62
+
63
+ - Use `install <app> <path>` when the app may already be installed and you do not need a fresh-state reset.
64
+ - Use `reinstall <app> <path>` when you explicitly need uninstall plus install as one deterministic step.
65
+ - Keep install and open as separate phases. Do not turn them into one default command flow.
66
+ - Supported binary formats:
67
+ - Android: `.apk` and `.aab`
68
+ - iOS: `.app` and `.ipa`
69
+ - For iOS `.ipa` files, `<app>` is used as the bundle id or bundle name hint when the archive contains multiple app bundles.
70
+ - After install or reinstall, later use `open <app>` with the exact discovered or known package/bundle identifier, not the artifact path.
71
+
29
72
  ## Choose the right starting point
30
73
 
31
74
  - iOS local QA: prefer simulators unless the task explicitly requires physical hardware.
32
75
  - iOS in mixed simulator and device environments: run `ensure-simulator` first, then keep using `--device` or `--udid`.
33
76
  - TV targets: use `--target tv` together with `--platform` when the task is for tvOS or Android TV rather than phone or tablet surfaces.
34
77
  - Android binary flow: use `install` or `reinstall` for `.apk` or `.aab`, then open by installed package name.
35
- - Android React Native plus Metro flow: `reinstall <app> <apk>` first, then `open <package> --remote-config <path> --relaunch`.
36
78
  - macOS desktop app flow: use `open <app> --platform macos`. Only load [macos-desktop.md](macos-desktop.md) if a desktop surface or macOS-specific behavior matters.
37
79
 
38
80
  TV example:
@@ -95,8 +137,6 @@ export AGENT_DEVICE_PLATFORM=ios
95
137
  export AGENT_DEVICE_SESSION_LOCK=strip
96
138
 
97
139
  agent-device open MyApp --relaunch
98
- agent-device snapshot -i
99
- agent-device close
100
140
  ```
101
141
 
102
142
  - `AGENT_DEVICE_SESSION` plus `AGENT_DEVICE_PLATFORM` provides the default binding.
@@ -111,10 +151,7 @@ Android emulator variant:
111
151
  export AGENT_DEVICE_SESSION=qa-android
112
152
  export AGENT_DEVICE_PLATFORM=android
113
153
 
114
- agent-device reinstall MyApp /path/to/app-debug.apk --serial emulator-5554
115
154
  agent-device --session-lock reject open com.example.myapp --relaunch
116
- agent-device snapshot -i
117
- agent-device close --shutdown
118
155
  ```
119
156
 
120
157
  ## Scoped discovery
@@ -151,11 +188,14 @@ agent-device replay -u ./session.ad --session auth
151
188
  - Once the correct target and session are pinned, move to [exploration.md](exploration.md).
152
189
  - If opening, startup, permissions, or logs become the blocker, switch to [debugging.md](debugging.md).
153
190
 
154
- ## Install and open examples
191
+ ## Install examples
155
192
 
156
193
  ```bash
157
194
  agent-device reinstall MyApp /path/to/app-debug.apk --platform android --serial emulator-5554
158
- agent-device open com.example.myapp --remote-config ./agent-device.remote.json --relaunch
195
+ ```
196
+
197
+ ```bash
198
+ agent-device install com.example.app ./build/MyApp.ipa --platform ios --device "iPhone 17 Pro"
159
199
  ```
160
200
 
161
201
  Do not use `open <apk|aab> --relaunch` on Android.
@@ -4,22 +4,48 @@
4
4
 
5
5
  Open this file when the app or screen is already running and you need to discover the UI, choose targets, read state, wait for conditions, or perform normal interactions.
6
6
 
7
- ## Main commands to reach for first
7
+ ## Read-only first
8
+
9
+ - If the question is what text, labels, or structure is visible on screen, start with plain `snapshot`.
10
+ - Escalate to `snapshot -i` only when you need refs such as `@e3` for interactive exploration or a requested action.
11
+ - If you intend to `press`, `fill`, or otherwise interact, start with `snapshot -i` and fall back to plain `snapshot` only if interactive refs are unavailable.
12
+ - Prefer `get`, `is`, or `find` before mutating the UI when a read-only command can answer the question.
13
+ - You may take the smallest reversible UI action needed to unblock inspection, such as dismissing a popup, closing an alert, or backing out of an unintended surface.
14
+ - Do not type or fill text just to make hidden information easier to access unless the user asked for that interaction.
15
+ - Do not use external sources to infer missing UI state unless the user explicitly asked.
16
+ - If the answer is not visible or exposed in the UI, report that gap instead of compensating with search, navigation, or text entry.
17
+
18
+ ## Decision shortcut
19
+
20
+ - User asks what is visible on screen: `snapshot`
21
+ - User asks for exact text from a known target: `get text`
22
+ - User asks you to tap, type, or choose an element: `snapshot -i`, then act
23
+ - UI does not expose the answer: say so plainly; do not browse or force the app into a new state unless asked
24
+
25
+ ## Read-only commands
8
26
 
9
27
  - `snapshot`
28
+ - `get`
29
+ - `is`
30
+ - `find`
31
+
32
+ ## Interaction commands
33
+
10
34
  - `snapshot -i`
11
35
  - `press`
12
36
  - `fill`
13
- - `get`
14
- - `is`
37
+ - `type`
15
38
  - `wait`
16
- - `find`
17
39
 
18
40
  ## Most common mistake to avoid
19
41
 
20
42
  Do not treat `@ref` values as durable after navigation or dynamic updates. Re-snapshot after the UI changes, and switch to selectors when the flow must stay stable.
21
43
 
22
- ## Canonical loop
44
+ ## Common example loops
45
+
46
+ These are examples, not required exact sequences. Adapt them to the app, state, and task at hand.
47
+
48
+ ### Interactive exploration loop
23
49
 
24
50
  ```bash
25
51
  agent-device open Settings --platform ios
@@ -30,11 +56,21 @@ agent-device get text 'label="Privacy & Security"'
30
56
  agent-device close
31
57
  ```
32
58
 
59
+ ### Screen verification loop
60
+
61
+ ```bash
62
+ agent-device open MyApp --platform ios
63
+ # perform the necessary actions to reach the state you need to verify
64
+ agent-device snapshot
65
+ # verify whether the expected element or text is present
66
+ agent-device close
67
+ ```
68
+
33
69
  ## Snapshot choices
34
70
 
35
71
  - Use plain `snapshot` when you only need to verify whether visible text or structure is on screen.
36
- - Use `snapshot -i` when you need refs such as `@e3` for interactive exploration.
37
- - Treat large text-surface lines in `snapshot -i` as discovery output. If a node shows preview/truncation metadata, use `get text @ref` to expand the actual text after you choose the surface.
72
+ - Use `snapshot -i` when you need refs such as `@e3` for interactive exploration or for an intended interaction.
73
+ - Treat large text-surface lines in `snapshot -i` as discovery output. If a node shows preview or truncation metadata, use `get text @ref` only after you have already decided that `snapshot -i` is needed for that surface.
38
74
  - Use `snapshot -i -s "Camera"` or `snapshot -i -s @e3` when you want a smaller, scoped result.
39
75
 
40
76
  Example:
@@ -74,6 +110,7 @@ agent-device is visible 'id="camera_settings_anchor"'
74
110
 
75
111
  - Use `fill` to replace text in an editable field.
76
112
  - Use `type` to append text to the current insertion point.
113
+ - Do not use `fill` or `type` just to make the app reveal information that is not currently visible unless the user asked for that interaction.
77
114
 
78
115
  ## Query and sync rules
79
116
 
@@ -109,6 +146,11 @@ Anti-hallucination rules:
109
146
  - Discover them first with `devices`, `open`, `snapshot -i`, `find`, or `session list`.
110
147
  - If refs drift after navigation, re-snapshot or switch to selectors instead of guessing.
111
148
 
149
+ Avoid this escalation path for visible-text questions:
150
+
151
+ - Do not jump from `snapshot -i` to `get text @ref`, then to web search, then to typing into a search box just to force the app to reveal the answer.
152
+ - Start with `snapshot`. If the text is not visible or exposed, report that directly.
153
+
112
154
  Canonical QA loop:
113
155
 
114
156
  ```bash
@@ -21,8 +21,7 @@ Do not treat every macOS surface the same. Use the normal `app` surface when you
21
21
 
22
22
  ```bash
23
23
  agent-device open TextEdit --platform macos
24
- agent-device snapshot -i
25
- agent-device fill @e3 "desktop smoke test"
24
+ agent-device snapshot
26
25
  agent-device close
27
26
  ```
28
27
 
@@ -2,10 +2,11 @@
2
2
 
3
3
  ## When to open this file
4
4
 
5
- Open this file only for remote daemon HTTP flows that require explicit daemon URL setup, authentication, lease allocation, or tenant-scoped command admission.
5
+ Open this file for remote daemon HTTP flows, including `--remote-config` launches, that let an agent running in a Linux sandbox talk to another `agent-device` instance on a remote macOS host in order to control devices that are not available locally. This file covers daemon URL setup, authentication, lease allocation, and tenant-scoped command admission.
6
6
 
7
7
  ## Main commands to reach for first
8
8
 
9
+ - `agent-device open <app> --remote-config <path> --relaunch`
9
10
  - `AGENT_DEVICE_DAEMON_BASE_URL=...`
10
11
  - `AGENT_DEVICE_DAEMON_AUTH_TOKEN=...`
11
12
  - `curl ... agent_device.lease.allocate`
@@ -17,7 +18,19 @@ Open this file only for remote daemon HTTP flows that require explicit daemon UR
17
18
 
18
19
  Do not run a tenant-isolated command without matching `tenant`, `run`, and `lease` scope. Admission checks require all three to line up.
19
20
 
20
- ## Canonical loop
21
+ ## Preferred remote launch path
22
+
23
+ Use this when the agent needs the simplest remote control flow: a Linux sandbox agent talks over HTTP to `agent-device` on a remote macOS host and launches the target app through a checked-in `--remote-config` profile.
24
+
25
+ ```bash
26
+ agent-device open com.example.myapp --remote-config ./agent-device.remote.json --relaunch
27
+ ```
28
+
29
+ - This is the preferred remote launch path for sandbox or cloud agents.
30
+ - For Android React Native relaunch flows, install or reinstall the APK first, then relaunch by installed package name.
31
+ - Do not use `open <apk|aab> --relaunch`; remote runtime hints are applied through the installed app sandbox.
32
+
33
+ ## Lease flow example
21
34
 
22
35
  ```bash
23
36
  export AGENT_DEVICE_DAEMON_BASE_URL=http://mac-host.example:4310
@@ -20,9 +20,8 @@ Do not use verification tools as the first exploration step. First get the app i
20
20
 
21
21
  ```bash
22
22
  agent-device open Settings --platform ios
23
- agent-device snapshot -i
24
- agent-device press @e5
25
- agent-device diff snapshot -i
23
+ # after using exploration to reach the state you want to verify
24
+ agent-device snapshot
26
25
  agent-device screenshot /tmp/settings-proof.png
27
26
  agent-device close
28
27
  ```
package/dist/src/224.js DELETED
@@ -1,2 +0,0 @@
1
- import{createRequestId as e,node_path as t,isAgentDeviceDaemonProcess as r,runCmdDetached as a,readVersion as n,findProjectRoot as o,node_https as i,runCmdSync as s,withDiagnosticTimer as l,resolveDaemonTransportPreference as d,resolveUserPath as u,emitDiagnostic as c,spawn as p,AppError as m,node_fs as h,resolveDaemonPaths as f,node_net as I,resolveDaemonServerMode as g,stopProcessForTakeover as w,node_http as b}from"./331.js";async function y(e){let{localPath:r,baseUrl:a,token:n}=e,o=h.statSync(r).isDirectory(),s=t.basename(r),l=new URL("upload",a.endsWith("/")?a:`${a}/`),d="https:"===l.protocol?i:b,u={"x-artifact-type":o?"app-bundle":"file","x-artifact-filename":s,"transfer-encoding":"chunked"};return n&&(u.authorization=`Bearer ${n}`,u["x-agent-device-token"]=n),new Promise((e,a)=>{let n=d.request({protocol:l.protocol,host:l.hostname,port:l.port,method:"POST",path:l.pathname+l.search,headers:u},t=>{let r="";t.setEncoding("utf8"),t.on("data",e=>{r+=e}),t.on("end",()=>{clearTimeout(i);try{let t=JSON.parse(r);if(!t.ok||!t.uploadId)return void a(new m("COMMAND_FAILED",`Upload failed: ${r}`));e(t.uploadId)}catch{a(new m("COMMAND_FAILED",`Invalid upload response: ${r}`))}})}),i=setTimeout(()=>{n.destroy(),a(new m("COMMAND_FAILED","Artifact upload timed out",{timeoutMs:3e5,hint:"The upload to the remote daemon exceeded the 5-minute timeout."}))},3e5);if(n.on("error",e=>{clearTimeout(i),a(new m("COMMAND_FAILED","Failed to upload artifact to remote daemon",{hint:"Verify the remote daemon is reachable and supports artifact uploads."},e))}),o){let e=p("tar",["cf","-","-C",t.dirname(r),t.basename(r)],{stdio:["ignore","pipe","pipe"]});e.stdout.pipe(n),e.on("error",e=>{n.destroy(),a(new m("COMMAND_FAILED","Failed to create tar archive for app bundle",{},e))}),e.on("close",e=>{0!==e&&(n.destroy(),a(new m("COMMAND_FAILED",`tar failed with exit code ${e}`)))})}else{let e=h.createReadStream(r);e.pipe(n),e.on("error",e=>{n.destroy(),a(new m("COMMAND_FAILED","Failed to read local artifact",{},e))})}})}let v=function(e=process.env.AGENT_DEVICE_DAEMON_TIMEOUT_MS){if(!e)return 9e4;let t=Number(e);return Number.isFinite(t)?Math.max(1e3,Math.floor(t)):9e4}(),A=function(e=process.env.AGENT_DEVICE_DAEMON_STARTUP_TIMEOUT_MS){if(!e)return 15e3;let t=Number(e);return Number.isFinite(t)?Math.max(1e3,Math.floor(t)):15e3}(),D=function(e=process.env.AGENT_DEVICE_DAEMON_STARTUP_ATTEMPTS){if(!e)return 2;let t=Number(e);return Number.isFinite(t)?Math.min(5,Math.max(1,Math.floor(t))):2}(),_=["xcodebuild .*AgentDeviceRunnerUITests/RunnerTests/testCommand","xcodebuild .*AgentDeviceRunner\\.env\\.session-","xcodebuild build-for-testing .*ios-runner/AgentDeviceRunner/AgentDeviceRunner\\.xcodeproj"];async function P(t){let r=t.meta?.requestId??e(),a=!!(t.meta?.debug||t.flags?.verbose),n=function(e){let t=e.flags?.stateDir??process.env.AGENT_DEVICE_STATE_DIR,r=function(e){let t;if(e){try{t=new URL(e)}catch(t){throw new m("INVALID_ARGS","Invalid daemon base URL",{daemonBaseUrl:e},t instanceof Error?t:void 0)}if("http:"!==t.protocol&&"https:"!==t.protocol)throw new m("INVALID_ARGS","Daemon base URL must use http or https",{daemonBaseUrl:e});return t.toString().replace(/\/+$/,"")}}(e.flags?.daemonBaseUrl??process.env.AGENT_DEVICE_DAEMON_BASE_URL),a=e.flags?.daemonAuthToken??process.env.AGENT_DEVICE_DAEMON_AUTH_TOKEN,n=e.flags?.daemonTransport??process.env.AGENT_DEVICE_DAEMON_TRANSPORT,o=d(n);if(r&&"socket"===o)throw new m("INVALID_ARGS","Remote daemon base URL only supports HTTP transport. Remove --daemon-transport socket.",{daemonBaseUrl:r});let i=g(e.flags?.daemonServerMode??process.env.AGENT_DEVICE_DAEMON_SERVER_MODE??("dual"===n?"dual":void 0));return{paths:f(t),transportPreference:o,serverMode:i,remoteBaseUrl:r,remoteAuthToken:a}}(t),o=await l("daemon_startup",async()=>await N(n),{requestId:r,session:t.session}),i=await E(t,o),s={...t,positionals:i.positionals,flags:i.flags,token:o.token,meta:{...t.meta??{},requestId:r,debug:a,cwd:t.meta?.cwd,tenantId:t.meta?.tenantId??t.flags?.tenant,runId:t.meta?.runId??t.flags?.runId,leaseId:t.meta?.leaseId??t.flags?.leaseId,sessionIsolation:t.meta?.sessionIsolation??t.flags?.sessionIsolation,lockPolicy:t.meta?.lockPolicy,lockPlatform:t.meta?.lockPlatform,...i.uploadedArtifactId?{uploadedArtifactId:i.uploadedArtifactId}:{},...i.clientArtifactPaths?{clientArtifactPaths:i.clientArtifactPaths}:{},...i.installSource?{installSource:i.installSource}:{}}};return c({level:"info",phase:"daemon_request_prepare",data:{requestId:r,command:t.command,session:t.session}}),await l("daemon_request",async()=>await j(o,s,n.transportPreference),{requestId:r,command:t.command})}async function E(e,r){let a,n=[...e.positionals??[]],o=e.flags?{...e.flags}:void 0,i=e.meta?.installSource,s={};if(X(r)){let l=function(e,r){if("screenshot"===e.command){let t=M(e,"path",".png");return r[0]?{field:"path",localPath:t,positionalIndex:0,positionalPath:k("screenshot",".png")}:{field:"path",localPath:t,positionalIndex:0,flagPath:k("screenshot",".png")}}if("record"===e.command&&"start"===(r[0]??"").toLowerCase()){let r=M(e,"outPath",".mp4",1);return{field:"outPath",localPath:r,positionalIndex:1,positionalPath:k("recording",t.extname(r)||".mp4")}}return null}(e,n);l&&(void 0!==l.positionalPath&&(n[l.positionalIndex]=l.positionalPath),void 0!==l.flagPath&&((o??={}).out=l.flagPath),s[l.field]=l.localPath);let d=await S(e,r);d&&(i=d.installSource,a=d.uploadedArtifactId??a)}if(!X(r)||"install"!==e.command&&"reinstall"!==e.command||n.length<2)return{positionals:n,flags:o,installSource:i,uploadedArtifactId:a,...Object.keys(s).length>0?{clientArtifactPaths:s}:{}};let l=n[1];if(l.startsWith("remote:"))return n[1]=l.slice(7),{positionals:n,flags:o,...Object.keys(s).length>0?{clientArtifactPaths:s}:{}};let d=t.isAbsolute(l)?l:t.resolve(e.meta?.cwd??process.cwd(),l);return h.existsSync(d)?{positionals:n,flags:o,installSource:i,uploadedArtifactId:a=await y({localPath:d,baseUrl:r.baseUrl,token:r.token}),...Object.keys(s).length>0?{clientArtifactPaths:s}:{}}:{positionals:n,flags:o,...Object.keys(s).length>0?{clientArtifactPaths:s}:{}}}async function S(e,r){let a=e.meta?.installSource;if("install_source"!==e.command||!a||"path"!==a.kind)return null;let n=a.path.trim();if(!n)return{installSource:a};if(n.startsWith("remote:"))return{installSource:{...a,path:n.slice(7)}};let o=t.isAbsolute(n)?n:t.resolve(e.meta?.cwd??process.cwd(),n);if(!h.existsSync(o))return{installSource:{...a,path:o}};let i=await y({localPath:o,baseUrl:r.baseUrl,token:r.token});return{installSource:{...a,path:o},uploadedArtifactId:i}}function M(e,r,a,n=0){let o=e.positionals?.[n]??e.flags?.out,i=`${"path"===r?"screenshot":"recording"}-${Date.now()}${a}`,s=o&&o.trim().length>0?o:i;return t.isAbsolute(s)?s:t.resolve(e.meta?.cwd??process.cwd(),s)}function k(e,r){let a=r.startsWith(".")?r:`.${r}`;return t.posix.join("/tmp",`agent-device-${e}-${Date.now()}-${Math.random().toString(36).slice(2,8)}${a}`)}async function N(e){let a;if(e.remoteBaseUrl){let t={transport:"http",token:e.remoteAuthToken??"",pid:0,baseUrl:e.remoteBaseUrl};if(await q(t,"http"))return t;throw new m("COMMAND_FAILED","Remote daemon is unavailable",{daemonBaseUrl:e.remoteBaseUrl,hint:"Verify AGENT_DEVICE_DAEMON_BASE_URL points to a reachable daemon with GET /health and POST /rpc."})}let i=x(e.paths.infoPath),s=n(),l=function(e,r=o()){try{let a=h.statSync(e),n=t.relative(r,e)||e;return`${n}:${a.size}:${Math.trunc(a.mtimeMs)}`}catch{return"unknown"}}((a=z()).useSrc?a.srcPath:a.distPath,a.root),d=!!i&&await q(i,e.transportPreference);if(i&&i.version===s&&i.codeSignature===l&&d)return i;i&&(i.version!==s||i.codeSignature!==l||!d)&&(await O(i),F(e.paths.infoPath)),function(e){let t=L(e);if(!t.hasLock||t.hasInfo)return;let a=C(e.lockPath);if(!a)return F(e.lockPath);r(a.pid,a.processStartTime)||F(e.lockPath)}(e.paths);let u=0;for(let t=1;t<=D;t+=1){await B(e);let r=await T(A,e);if(r)return r;if(await U(e.paths)){u+=1;continue}let a=L(e.paths);if(!(t<D))break;if(!a.hasInfo&&!a.hasLock){await R(150);continue}}let c=L(e.paths);throw new m("COMMAND_FAILED","Failed to start daemon",{kind:"daemon_startup_failed",infoPath:e.paths.infoPath,lockPath:e.paths.lockPath,startupTimeoutMs:A,startupAttempts:D,lockRecoveryCount:u,metadataState:c,hint:function(e,t=f(process.env.AGENT_DEVICE_STATE_DIR)){return e.hasLock&&!e.hasInfo?`Detected ${t.lockPath} without ${t.infoPath}. If no agent-device daemon process is running, delete ${t.lockPath} and retry.`:e.hasLock&&e.hasInfo?`Daemon metadata may be stale. If no agent-device daemon process is running, delete ${t.infoPath} and ${t.lockPath}, then retry.`:`Daemon metadata is missing or stale. Delete ${t.infoPath} if present and retry.`}(c,e.paths)})}async function T(e,t){let r=Date.now();for(;Date.now()-r<e;){let e=x(t.paths.infoPath);if(e&&await q(e,t.transportPreference))return e;await new Promise(e=>setTimeout(e,100))}return null}async function R(e){await new Promise(t=>setTimeout(t,e))}async function U(e){let t=L(e);if(!t.hasLock||t.hasInfo)return!1;let a=C(e.lockPath);return a&&r(a.pid,a.processStartTime)&&await w(a.pid,{termTimeoutMs:3e3,killTimeoutMs:1e3,expectedStartTime:a.processStartTime}),F(e.lockPath),!0}async function O(e){await w(e.pid,{termTimeoutMs:3e3,killTimeoutMs:1e3,expectedStartTime:e.processStartTime})}function x(e){let t=$(e);if(!t||"object"!=typeof t)return null;let r="string"==typeof t.token&&t.token.length>0?t.token:null;if(!r)return null;let a=Number.isInteger(t.port)&&Number(t.port)>0,n=Number.isInteger(t.httpPort)&&Number(t.httpPort)>0;if(!a&&!n)return null;let o=t.transport,i="string"==typeof t.version?t.version:void 0,s="string"==typeof t.codeSignature?t.codeSignature:void 0,l="string"==typeof t.processStartTime?t.processStartTime:void 0,d=Number.isInteger(t.pid)&&Number(t.pid)>0;return{token:r,port:a?Number(t.port):void 0,httpPort:n?Number(t.httpPort):void 0,transport:"socket"===o||"http"===o||"dual"===o?o:void 0,pid:d?Number(t.pid):0,version:i,codeSignature:s,processStartTime:l}}function C(e){let t=$(e);return t&&"object"==typeof t&&Number.isInteger(t.pid)&&Number(t.pid)>0?{pid:Number(t.pid),processStartTime:"string"==typeof t.processStartTime?t.processStartTime:void 0,startedAt:"number"==typeof t.startedAt?t.startedAt:void 0}:null}function L(e){return{hasInfo:h.existsSync(e.infoPath),hasLock:h.existsSync(e.lockPath)}}function $(e){if(!h.existsSync(e))return null;try{return JSON.parse(h.readFileSync(e,"utf8"))}catch{return null}}function F(e){try{h.existsSync(e)&&h.unlinkSync(e)}catch{}}async function q(e,t){var r;return"http"===G(e,t)?await function(e){let t=e.baseUrl?Y(e.baseUrl,"health"):e.httpPort?`http://127.0.0.1:${e.httpPort}/health`:null;if(!t)return Promise.resolve(!1);let r=new URL(t),a="https:"===r.protocol?i:b,n=e.baseUrl?3e3:500;return new Promise(e=>{let t=a.request({protocol:r.protocol,host:r.hostname,port:r.port,path:r.pathname+r.search,method:"GET",timeout:n},t=>{t.resume(),e((t.statusCode??500)<500)});t.on("timeout",()=>{t.destroy(),e(!1)}),t.on("error",()=>{e(!1)}),t.end()})}(e):await ((r=e.port)?new Promise(e=>{let t=I.createConnection({host:"127.0.0.1",port:r},()=>{t.destroy(),e(!0)});t.on("error",()=>{e(!1)})}):Promise.resolve(!1))}async function B(e){let t=z(),r=t.useSrc?["--experimental-strip-types",t.srcPath]:[t.distPath],n={...process.env,AGENT_DEVICE_STATE_DIR:e.paths.baseDir,AGENT_DEVICE_DAEMON_SERVER_MODE:e.serverMode};a(process.execPath,r,{env:n})}function z(){let e=o(),r=t.join(e,"dist","src","daemon.js"),a=t.join(e,"src","daemon.ts"),n=h.existsSync(r),i=h.existsSync(a);if(!n&&!i)throw new m("COMMAND_FAILED","Daemon entry not found",{distPath:r,srcPath:a});return{root:e,distPath:r,srcPath:a,useSrc:process.execArgv.includes("--experimental-strip-types")?i:!n&&i}}async function j(e,t,r){return"http"===G(e,r)?await J(e,t):await H(e,t)}function G(e,t){if(e.baseUrl){if("socket"===t)throw new m("COMMAND_FAILED","Remote daemon endpoint only supports HTTP transport",{daemonBaseUrl:e.baseUrl});return"http"}if("http"===t||"socket"===t){var r=e,a=t;if(V(r,a))return a;throw new m("COMMAND_FAILED","http"===a?"Daemon HTTP endpoint is unavailable":"Daemon socket endpoint is unavailable")}let n=("socket"===e.transport||"dual"===e.transport?["socket","http"]:["http","socket"]).find(t=>V(e,t));if(n)return n;throw new m("COMMAND_FAILED","Daemon metadata has no reachable transport")}function V(e,t){return"http"===t?!!e.httpPort:!!e.port}async function H(e,t){let r=e.port;if(!r)throw new m("COMMAND_FAILED","Daemon socket endpoint is unavailable");return new Promise((a,n)=>{let o=I.createConnection({host:"127.0.0.1",port:r},()=>{o.write(`${JSON.stringify(t)}
2
- `)}),i=setTimeout(()=>{o.destroy();let r=K(),a=W(e,f(t.flags?.stateDir??process.env.AGENT_DEVICE_STATE_DIR));c({level:"error",phase:"daemon_request_timeout",data:{timeoutMs:v,requestId:t.meta?.requestId,command:t.command,timedOutRunnerPidsTerminated:r.terminated,timedOutRunnerCleanupError:r.error,daemonPidReset:e.pid,daemonPidForceKilled:a.forcedKill}}),n(new m("COMMAND_FAILED","Daemon request timed out",{timeoutMs:v,requestId:t.meta?.requestId,hint:"Retry with --debug and check daemon diagnostics logs. Timed-out iOS runner xcodebuild processes were terminated when detected."}))},v),s="";o.setEncoding("utf8"),o.on("data",e=>{let r=(s+=e).indexOf("\n");if(-1===r)return;let l=s.slice(0,r).trim();if(l)try{let e=JSON.parse(l);o.end(),clearTimeout(i),a(e)}catch(e){clearTimeout(i),n(new m("COMMAND_FAILED","Invalid daemon response",{requestId:t.meta?.requestId,line:l},e instanceof Error?e:void 0))}}),o.on("error",e=>{clearTimeout(i),c({level:"error",phase:"daemon_request_socket_error",data:{requestId:t.meta?.requestId,message:e instanceof Error?e.message:String(e)}}),n(new m("COMMAND_FAILED","Failed to communicate with daemon",{requestId:t.meta?.requestId,hint:"Retry command. If this persists, clean stale daemon metadata and start a fresh session."},e))})})}async function J(t,r){let a=t.baseUrl?new URL(Y(t.baseUrl,"rpc")):t.httpPort?new URL(`http://127.0.0.1:${t.httpPort}/rpc`):null;if(!a)throw new m("COMMAND_FAILED","Daemon HTTP endpoint is unavailable");let n=JSON.stringify({jsonrpc:"2.0",id:r.meta?.requestId??e(),method:"agent_device.command",params:r}),o={"content-type":"application/json","content-length":Buffer.byteLength(n)};return t.baseUrl&&t.token&&(o.authorization=`Bearer ${t.token}`,o["x-agent-device-token"]=t.token),await new Promise((e,s)=>{let l=f(r.flags?.stateDir??process.env.AGENT_DEVICE_STATE_DIR),d=("https:"===a.protocol?i:b).request({protocol:a.protocol,host:a.hostname,port:a.port,method:"POST",path:a.pathname+a.search,headers:o},a=>{let n="";a.setEncoding("utf8"),a.on("data",e=>{n+=e}),a.on("end",()=>{clearTimeout(u);try{let a=JSON.parse(n);if(a.error){let e=a.error.data??{};s(new m(String(e.code??"COMMAND_FAILED"),String(e.message??a.error.message??"Daemon RPC request failed"),{..."object"==typeof e.details&&e.details?e.details:{},hint:"string"==typeof e.hint?e.hint:void 0,diagnosticId:"string"==typeof e.diagnosticId?e.diagnosticId:void 0,logPath:"string"==typeof e.logPath?e.logPath:void 0,requestId:r.meta?.requestId}));return}if(!a.result||"object"!=typeof a.result)return void s(new m("COMMAND_FAILED","Invalid daemon RPC response",{requestId:r.meta?.requestId}));if(t.baseUrl&&a.result.ok)return void Q(t,r,a.result).then(e).catch(s);e(a.result)}catch(e){clearTimeout(u),s(new m("COMMAND_FAILED","Invalid daemon response",{requestId:r.meta?.requestId,line:n},e instanceof Error?e:void 0))}})}),u=setTimeout(()=>{d.destroy();let e=X(t)?{terminated:0}:K(),a=X(t)?{forcedKill:!1}:W(t,l);c({level:"error",phase:"daemon_request_timeout",data:{timeoutMs:v,requestId:r.meta?.requestId,command:r.command,timedOutRunnerPidsTerminated:e.terminated,timedOutRunnerCleanupError:e.error,daemonPidReset:X(t)?void 0:t.pid,daemonPidForceKilled:X(t)?void 0:a.forcedKill,daemonBaseUrl:t.baseUrl}}),s(new m("COMMAND_FAILED","Daemon request timed out",{timeoutMs:v,requestId:r.meta?.requestId,hint:X(t)?"Retry with --debug and verify the remote daemon URL, auth token, and remote host logs.":"Retry with --debug and check daemon diagnostics logs. Timed-out iOS runner xcodebuild processes were terminated when detected."}))},v);d.on("error",e=>{clearTimeout(u),c({level:"error",phase:"daemon_request_socket_error",data:{requestId:r.meta?.requestId,message:e instanceof Error?e.message:String(e)}}),s(new m("COMMAND_FAILED","Failed to communicate with daemon",{requestId:r.meta?.requestId,hint:X(t)?"Retry command. If this persists, verify the remote daemon URL, auth token, and remote host reachability.":"Retry command. If this persists, clean stale daemon metadata and start a fresh session."},e))}),d.write(n),d.end()})}function K(){let e=0;try{for(let t of _){let r=s("pkill",["-f",t],{allowFailure:!0});0===r.exitCode&&(e+=1)}return{terminated:e}}catch(t){return{terminated:e,error:t instanceof Error?t.message:String(t)}}}function W(e,t){let a=!1;try{r(e.pid,e.processStartTime)&&(process.kill(e.pid,"SIGKILL"),a=!0)}catch{w(e.pid,{termTimeoutMs:3e3,killTimeoutMs:1e3,expectedStartTime:e.processStartTime})}finally{F(t.infoPath),F(t.lockPath)}return{forcedKill:a}}function X(e){return"string"==typeof e.baseUrl&&e.baseUrl.length>0}function Y(e,t){return new URL(t,e.endsWith("/")?e:`${e}/`).toString()}async function Q(e,r,a){let n=Array.isArray(a.data?.artifacts)?a.data.artifacts:[];if(0===n.length||!e.baseUrl)return a;let o=a.data?{...a.data}:{},i=[];for(let a of n){if(!a||"object"!=typeof a||"string"!=typeof a.artifactId){i.push(a);continue}let n=function(e,r){if(e.localPath&&e.localPath.trim().length>0)return e.localPath;let a=e.fileName?.trim()||`${e.field}-${Date.now()}`;return t.resolve(r.meta?.cwd??process.cwd(),a)}(a,r);await Z({baseUrl:e.baseUrl,token:e.token,artifactId:a.artifactId,destinationPath:n,requestId:r.meta?.requestId}),o[a.field]=n,i.push({...a,localPath:n})}return o.artifacts=i,{ok:!0,data:o}}async function Z(e){var r,a;let n,o=new URL((r=e.baseUrl,a=e.artifactId,n=r.endsWith("/")?r:`${r}/`,new URL(`upload/${encodeURIComponent(a)}`,n).toString())),s="https:"===o.protocol?i:b;await h.promises.mkdir(t.dirname(e.destinationPath),{recursive:!0}),await new Promise((t,r)=>{let a=!1,n=e.timeoutMs??v,i=n=>{if(!a){if(a=!0,clearTimeout(d),n)return void h.promises.rm(e.destinationPath,{force:!0}).finally(()=>r(n));t()}},l=s.request({protocol:o.protocol,host:o.hostname,port:o.port,method:"GET",path:o.pathname+o.search,headers:e.token?{authorization:`Bearer ${e.token}`,"x-agent-device-token":e.token}:void 0},t=>{if((t.statusCode??500)>=400){let r="";t.setEncoding("utf8"),t.on("data",e=>{r+=e}),t.on("end",()=>{i(new m("COMMAND_FAILED","Failed to download remote artifact",{artifactId:e.artifactId,statusCode:t.statusCode,requestId:e.requestId,body:r}))});return}let r=h.createWriteStream(e.destinationPath);r.on("error",e=>{i(e instanceof Error?e:Error(String(e)))}),t.on("error",e=>{i(e instanceof Error?e:Error(String(e)))}),t.on("aborted",()=>{i(new m("COMMAND_FAILED","Remote artifact download was interrupted",{artifactId:e.artifactId,requestId:e.requestId}))}),r.on("finish",()=>{r.close(()=>i())}),t.pipe(r)}),d=setTimeout(()=>{l.destroy(new m("COMMAND_FAILED","Remote artifact download timed out",{artifactId:e.artifactId,requestId:e.requestId,timeoutMs:n}))},n);l.on("error",t=>{t instanceof m?i(t):i(new m("COMMAND_FAILED","Failed to download remote artifact",{artifactId:e.artifactId,requestId:e.requestId,timeoutMs:n},t instanceof Error?t:void 0))}),l.end()})}function ee(e){return e.replace(/\/+$/,"")}function et(e){return"string"==typeof e&&e.trim()?ee(e.trim()):""}function er(e){return"string"==typeof e&&e.trim()?e.trim():void 0}function ea(e,t,r){return u(e,{env:t,cwd:r})}function en(e){try{return h.accessSync(e,h.constants.F_OK),!0}catch{return!1}}function eo(e,t,r){if(null==e||""===e)return t;let a=Number.parseInt(String(e),10);return Number.isInteger(a)?Math.max(a,r):t}function ei(e,t){let r;return{platform:t,bundleUrl:((r=new URL(`${ee(e)}/index.bundle`)).searchParams.set("platform",t),r.searchParams.set("dev","true"),r.searchParams.set("minify","false"),r.toString())}}function es(e,t){return{platform:t,metroHost:er(e?.metro_host),metroPort:e?.metro_port,bundleUrl:er(e?.metro_bundle_url),launchUrl:er(e?.launch_url)}}function el(e){return`'${e.replace(/'/g,"'\"'\"'")}'`}async function ed(e){await new Promise(t=>setTimeout(t,e))}async function eu(e,t,r={}){try{let a=await fetch(e,{headers:r,signal:AbortSignal.timeout(t)});return{ok:a.ok,status:a.status,body:await a.text()}}catch(r){if(r instanceof Error&&"TimeoutError"===r.name)throw Error(`Timed out fetching ${e} after ${t}ms`);throw r}}async function ec(e,t){try{let r=await eu(e,t);return r.ok&&r.body.includes("packager-status:running")}catch{return!1}}async function ep(e){var t,r,a;let n;try{n=await fetch(`${e.baseUrl}/api/metro/bridge`,{method:"POST",headers:(t=e.baseUrl,r=e.bearerToken,{Authorization:`Bearer ${r}`,"Content-Type":"application/json",...t.includes("ngrok")?{"ngrok-skip-browser-warning":"1"}:{}}),body:JSON.stringify({ios_runtime:e.runtime,timeout_ms:e.timeoutMs}),signal:AbortSignal.timeout(e.timeoutMs)})}catch(t){if(t instanceof Error&&"TimeoutError"===t.name)throw Error(`/api/metro/bridge timed out after ${e.timeoutMs}ms calling ${e.baseUrl}/api/metro/bridge`);throw t}let o=await n.text(),i=o?JSON.parse(o):{};if(!n.ok)throw Error(`/api/metro/bridge failed (${n.status}): ${JSON.stringify(i)}`);return{enabled:(a=i.data??i).enabled,baseUrl:a.base_url,statusUrl:a.status_url,bundleUrl:a.bundle_url,iosRuntime:es(a.ios_runtime,"ios"),androidRuntime:es(a.android_runtime,"android"),upstream:{bundleUrl:a.upstream.bundle_url,host:a.upstream.host,port:a.upstream.port,statusUrl:a.upstream.status_url},probe:{reachable:a.probe.reachable,statusCode:a.probe.status_code,latencyMs:a.probe.latency_ms,detail:a.probe.detail}}}async function em(e,t,r){let a=Date.now()+t;for(;Date.now()<a;){let t=Math.min(r,Math.max(a-Date.now(),1));if(await ec(e,t))return!0;let n=Math.min(500,Math.max(a-Date.now(),0));n>0&&await ed(n)}return!1}async function eh(e={}){let r=e.env??process.env,a=process.cwd(),n=ea(e.projectRoot??a,r,a),o=function(e,r){if("auto"!==r)return r;let a=function(e){let r=t.join(e,"package.json");if(!en(r))throw new m("INVALID_ARGS",`package.json not found at ${r}`);return JSON.parse(h.readFileSync(r,"utf8"))}(e);return"string"==typeof({...a.dependencies??{},...a.devDependencies??{}}).expo?"expo":"react-native"}(n,e.kind??"auto"),i=function(e,t){if(null==e||""===e)return 8081;let r=Number.parseInt(String(e),10);if(!Number.isInteger(r)||r<1||r>65535)throw new m("INVALID_ARGS",`Invalid Metro port: ${String(e)}. Use 1-65535.`);return r}(e.metroPort??8081,0),l=er(e.listenHost)??"0.0.0.0",d=er(e.statusHost)??"127.0.0.1",u=et(e.publicBaseUrl),c=eo(e.startupTimeoutMs,18e4,3e4),p=eo(e.probeTimeoutMs,1e4,1e3),f=e.reuseExisting??!0,I=e.installDependenciesIfNeeded??!0,g=e.runtimeFilePath?ea(e.runtimeFilePath,r,a):null,w=ea(e.logPath??t.join(n,".agent-device","metro.log"),r,a);if(!u)throw new m("INVALID_ARGS","metro prepare requires --public-base-url <url>.");let{proxyEnabled:b,proxyBaseUrl:y,proxyBearerToken:v}=function(e,t){if(e&&!t)throw new m("INVALID_ARGS","metro prepare requires proxy auth when --proxy-base-url is provided. Pass --bearer-token or set AGENT_DEVICE_PROXY_TOKEN.");if(!e&&t)throw new m("INVALID_ARGS","metro prepare requires --proxy-base-url when proxy auth is provided.");return{proxyEnabled:!!(e&&t),proxyBaseUrl:e,proxyBearerToken:t}}(et(e.proxyBaseUrl),er(e.proxyBearerToken)??""),A=I?function(e,r){if(function(e){try{return h.statSync(e).isDirectory()}catch{return!1}}(t.join(e,"node_modules")))return{installed:!1};let a=en(t.join(e,"pnpm-lock.yaml"))?{command:"pnpm",installArgs:["install"]}:en(t.join(e,"yarn.lock"))?{command:"yarn",installArgs:["install"]}:{command:"npm",installArgs:["install"]};return s(a.command,a.installArgs,{cwd:e,env:r}),{installed:!0,packageManager:a.command}}(n,r):{installed:!1},D=`http://${d}:${i}/status`,_=!1,P=!1,E=0;if(f&&await ec(D,p))P=!0;else if(_=!0,E=function(e,r,a,n,o,i){let l="expo"===r?{command:"npx",installArgs:["expo","start","--host","lan","--port",String(a)]}:{command:"npx",installArgs:["react-native","start","--host",n,"--port",String(a)]};h.mkdirSync(t.dirname(o),{recursive:!0});let d=[el(l.command),...l.installArgs.map(el)].join(" "),u=s("/bin/sh",["-c",`nohup ${d} >> ${el(o)} 2>&1 < /dev/null & echo $!`],{cwd:e,env:i}),c=Number.parseInt(u.stdout.trim(),10);if(!Number.isInteger(c)||c<=0)throw Error(`Failed to start Metro. Expected a child PID in stdout, got "${u.stdout.trim()}".`);return{pid:c}}(n,o,i,l,w,r).pid,!await em(D,c,p))throw Error(`Metro did not become ready at ${D} within ${c}ms. Check ${w}.`);let S=ei(u,"ios"),M=ei(u,"android"),k=null,N=null;if(b)try{k=await ep({baseUrl:y,bearerToken:v,runtime:{metro_bundle_url:S.bundleUrl},timeoutMs:p})}catch(e){N=e instanceof Error?e.message:String(e)}if(b&&(!k||!1===k.probe.reachable)){var T,R;let e;throw Error((T=N,R=k,e=[`Metro bridge is required for this run but could not be configured via ${y}/api/metro/bridge.`],T&&e.push(`bridgeError=${T}`),R?.probe.reachable===!1&&e.push(`bridgeProbe=${R.probe.detail||`unreachable (status ${R.probe.statusCode||0})`}`),e.join(" ")))}let U=k?.iosRuntime??S,O=k?.androidRuntime??M,x={projectRoot:n,kind:o,dependenciesInstalled:A.installed,packageManager:A.packageManager??null,started:_,reused:P,pid:E,logPath:w,statusUrl:D,runtimeFilePath:g,iosRuntime:U,androidRuntime:O,bridge:k};return g&&(h.mkdirSync(t.dirname(g),{recursive:!0}),h.writeFileSync(g,JSON.stringify(x,null,2))),x}function ef(e){let t=e.appId??e.bundleId??e.packageName;return{session:e.session,appId:t,appBundleId:e.bundleId,package:e.packageName}}function eI(e,t,r){return{deviceId:t,deviceName:r,..."android"===e?{serial:t}:"ios"===e?{udid:t}:{}}}function eg(e,t={}){let r=t.includeAndroidSerial??!0;return{platform:e.platform,target:e.target,device:e.name,id:e.id,..."ios"===e.platform?{device_udid:e.ios?.udid??e.id,ios_simulator_device_set:e.ios?.simulatorSetPath??null}:{},..."android"===e.platform&&r?{serial:e.android?.serial??e.id}:{}}}function ew(e){return{name:e.name,...eg(e.device,{includeAndroidSerial:!1}),createdAt:e.createdAt}}function eb(e){return{platform:e.platform,id:e.id,name:e.name,kind:e.kind,target:e.target,..."boolean"==typeof e.booted?{booted:e.booted}:{}}}function ey(e){return{udid:e.udid,device:e.device,runtime:e.runtime,ios_simulator_device_set:e.iosSimulatorDeviceSet??null,created:e.created,booted:e.booted}}function ev(e){return{app:e.app,appPath:e.appPath,platform:e.platform,...e.appId?{appId:e.appId}:{},...e.bundleId?{bundleId:e.bundleId}:{},...e.package?{package:e.package}:{}}}function eA(e){return{launchTarget:e.launchTarget,...e.appName?{appName:e.appName}:{},...e.appId?{appId:e.appId}:{},...e.bundleId?{bundleId:e.bundleId}:{},...e.packageName?{package:e.packageName}:{},...e.installablePath?{installablePath:e.installablePath}:{},...e.archivePath?{archivePath:e.archivePath}:{},...e.materializationId?{materializationId:e.materializationId}:{},...e.materializationExpiresAt?{materializationExpiresAt:e.materializationExpiresAt}:{}}}function eD(e){return{session:e.session,...e.appName?{appName:e.appName}:{},...e.appBundleId?{appBundleId:e.appBundleId}:{},...e.startup?{startup:e.startup}:{},...e.runtime?{runtime:e.runtime}:{},...e.device?eg(e.device):{}}}function e_(e){return{session:e.session,...e.shutdown?{shutdown:e.shutdown}:{}}}function eP(e){return{nodes:e.nodes,truncated:e.truncated,...e.appName?{appName:e.appName}:{},...e.appBundleId?{appBundleId:e.appBundleId}:{}}}function eE(e,t){let r=eO(e,"bundleId"),a=eO(e,"package");return{app:eU(e,"app"),appPath:eU(e,"appPath"),platform:ex(e,"platform"),appId:r??a,bundleId:r,package:a,identifiers:ef({session:t,bundleId:r,packageName:a})}}function eS(e){var t;let r=eT(e),a=ex(r,"platform"),n=eU(r,"id"),o=eU(r,"name");return{platform:a,target:eC(r,"target"),kind:eL(r,t="kind",ez,`Daemon response has invalid "${t}".`),id:n,name:o,booted:"boolean"==typeof r.booted?r.booted:void 0,identifiers:eI(a,n,o),ios:"ios"===a?{udid:n}:void 0,android:"android"===a?{serial:n}:void 0}}function eM(e){var t;let r=eT(e),a=ex(r,"platform"),n=eU(r,"id"),o=eU(r,"name"),i=eC(r,"target"),s=eU(r,"device"),l={session:o,...eI(a,n,s)};return{name:o,createdAt:eL(r,t="createdAt",eq,`Daemon response is missing numeric "${t}".`),device:{platform:a,target:i,id:n,name:s,identifiers:l,ios:"ios"===a?{udid:n,simulatorSetPath:e$(r,"ios_simulator_device_set",eF)}:void 0,android:"android"===a?{serial:n}:void 0},identifiers:l}}function ek(e,t){return t??e??"default"}function eN(e){let t={};for(let[r,a]of Object.entries(e))void 0!==a&&(t[r]=a);return t}function eT(e){if(!eR(e))throw new m("COMMAND_FAILED","Daemon returned an unexpected response shape.",{value:e});return e}function eR(e){return"object"==typeof e&&null!==e}function eU(e,t){return eL(e,t,eF,`Daemon response is missing "${t}".`)}function eO(e,t){return eF(e[t])}function ex(e,t){return eL(e,t,eB,`Daemon response has invalid "${t}".`)}function eC(e,t){return ej(e[t])??"mobile"}function eL(e,t,r,a){let n=r(e[t]);if(void 0===n)throw new m("COMMAND_FAILED",a,{response:e});return n}function e$(e,t,r){let a=e[t];return null===a?null:r(a)}function eF(e){return"string"==typeof e&&e.length>0?e:void 0}function eq(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function eB(e){return"ios"===e||"macos"===e||"android"===e?e:void 0}function ez(e){return"simulator"===e||"emulator"===e||"device"===e?e:void 0}function ej(e){return"tv"===e||"mobile"===e||"desktop"===e?e:void 0}function eG(e={},t={}){let r=t.transport??P,a=async(t,a=[],n={})=>{let o={...e,...n},i=await r({session:ek(e.session,n.session),command:t,positionals:a,flags:eN({stateDir:o.stateDir,daemonBaseUrl:o.daemonBaseUrl,daemonAuthToken:o.daemonAuthToken,daemonTransport:o.daemonTransport,daemonServerMode:o.daemonServerMode,tenant:o.tenant,sessionIsolation:o.sessionIsolation,runId:o.runId,leaseId:o.leaseId,platform:o.platform,target:o.target,device:o.device,udid:o.udid,serial:o.serial,iosSimulatorDeviceSet:o.iosSimulatorDeviceSet,androidDeviceAllowlist:o.androidDeviceAllowlist,runtime:o.simulatorRuntimeId,boot:o.boot,reuseExisting:o.reuseExisting,activity:o.activity,relaunch:o.relaunch,shutdown:o.shutdown,saveScript:o.saveScript,noRecord:o.noRecord,metroHost:o.metroHost,metroPort:o.metroPort,bundleUrl:o.bundleUrl,launchUrl:o.launchUrl,snapshotInteractiveOnly:o.interactiveOnly,snapshotCompact:o.compact,snapshotDepth:o.depth,snapshotScope:o.scope,snapshotRaw:o.raw,verbose:o.debug}),runtime:o.runtime,meta:eN({requestId:o.requestId,cwd:o.cwd,debug:o.debug,lockPolicy:o.lockPolicy,lockPlatform:o.lockPlatform,tenantId:o.tenant,runId:o.runId,leaseId:o.leaseId,sessionIsolation:o.sessionIsolation,installSource:o.installSource,retainMaterializedPaths:o.retainMaterializedPaths,materializedPathRetentionMs:o.materializedPathRetentionMs,materializationId:o.materializationId})});if(!i.ok)throw new m(i.error.code,i.error.message,{...i.error.details??{},hint:i.error.hint,diagnosticId:i.error.diagnosticId,logPath:i.error.logPath});return i.data??{}},n=async(e={})=>{let t=await a("session_list",[],e);return(Array.isArray(t.sessions)?t.sessions:[]).map(eM)};return{devices:{list:async(e={})=>{let t=await a("devices",[],e);return(Array.isArray(t.devices)?t.devices:[]).map(eS)}},sessions:{list:async(e={})=>await n(e),close:async(t={})=>{let r=ek(e.session,t.session),n=(await a("close",[],t)).shutdown;return{session:r,shutdown:"object"==typeof n&&null!==n?n:void 0,identifiers:{session:r}}}},simulators:{ensure:async e=>{let{runtime:t,...r}=e,n=await a("ensure-simulator",[],{...r,simulatorRuntimeId:t}),o=eU(n,"udid"),i=eU(n,"device");return{udid:o,device:i,runtime:eU(n,"runtime"),created:!0===n.created,booted:!0===n.booted,iosSimulatorDeviceSet:e$(n,"ios_simulator_device_set",eF),identifiers:{deviceId:o,deviceName:i,udid:o}}}},apps:{install:async t=>eE(await a("install",[t.app,t.appPath],t),ek(e.session,t.session)),reinstall:async t=>eE(await a("reinstall",[t.app,t.appPath],t),ek(e.session,t.session)),installFromSource:async t=>(function(e,t){let r=eO(e,"bundleId"),a=eO(e,"packageName"),n=r??a??eO(e,"appId"),o=eO(e,"launchTarget")??a??r??n;if(!o)throw new m("COMMAND_FAILED",'Daemon response is missing "launchTarget".',{response:e});return{appName:eO(e,"appName"),appId:n,bundleId:r,packageName:a,launchTarget:o,installablePath:eO(e,"installablePath"),archivePath:eO(e,"archivePath"),materializationId:eO(e,"materializationId"),materializationExpiresAt:eO(e,"materializationExpiresAt"),identifiers:ef({session:t,bundleId:r,packageName:a,appId:n})}})(await a("install_source",[],{...t,installSource:t.source,retainMaterializedPaths:t.retainPaths,materializedPathRetentionMs:t.retentionMs}),ek(e.session,t.session)),open:async t=>{let r=ek(e.session,t.session),n=t.url?[t.app,t.url]:[t.app],o=await a("open",n,t),i=function(e){let t=e.platform,r=eO(e,"id"),a=eO(e,"device");if("ios"!==t&&"macos"!==t&&"android"!==t||!r||!a)return;let n=eC(e,"target"),o=eI(t,r,a);return{platform:t,target:n,id:r,name:a,identifiers:o,ios:"ios"===t?{udid:eO(e,"device_udid")??r,simulatorSetPath:e$(e,"ios_simulator_device_set",eF)}:void 0,android:"android"===t?{serial:eO(e,"serial")??r}:void 0}}(o),s=eO(o,"appBundleId");return{session:r,appName:eO(o,"appName"),appBundleId:s,appId:s,startup:function(e){if(eR(e)&&"number"==typeof e.durationMs&&"string"==typeof e.measuredAt&&"string"==typeof e.method)return{durationMs:e.durationMs,measuredAt:e.measuredAt,method:e.method,appTarget:eO(e,"appTarget"),appBundleId:eO(e,"appBundleId")}}(o.startup),runtime:function(e){if(!eR(e))return;let t=e.platform,r=eO(e,"metroHost"),a="number"==typeof e.metroPort?e.metroPort:void 0;return{platform:"ios"===t||"android"===t?t:void 0,metroHost:r,metroPort:a,bundleUrl:eO(e,"bundleUrl"),launchUrl:eO(e,"launchUrl")}}(o.runtime),device:i,identifiers:{session:r,deviceId:i?.id,deviceName:i?.name,udid:i?.ios?.udid,serial:i?.android?.serial,appId:s,appBundleId:s}}},close:async(t={})=>{let r=ek(e.session,t.session),n=(await a("close",t.app?[t.app]:[],t)).shutdown;return{session:r,closedApp:t.app,shutdown:"object"==typeof n&&null!==n?n:void 0,identifiers:{session:r}}}},materializations:{release:async e=>{var t;return{released:!0===(t=await a("release_materialized_paths",[],{...e,materializationId:e.materializationId})).released,materializationId:eU(t,"materializationId"),identifiers:{}}}},metro:{prepare:async t=>await eh({projectRoot:t.projectRoot??e.cwd,kind:t.kind,publicBaseUrl:t.publicBaseUrl,proxyBaseUrl:t.proxyBaseUrl,proxyBearerToken:t.bearerToken,metroPort:t.port,listenHost:t.listenHost,statusHost:t.statusHost,startupTimeoutMs:t.startupTimeoutMs,probeTimeoutMs:t.probeTimeoutMs,reuseExisting:t.reuseExisting,installDependenciesIfNeeded:t.installDependenciesIfNeeded,runtimeFilePath:t.runtimeFilePath,logPath:t.logPath})},capture:{snapshot:async(t={})=>{var r;let n=ek(e.session,t.session),o=await a("snapshot",[],t),i=eO(o,"appBundleId");return{nodes:Array.isArray(r=o.nodes)?r:[],truncated:!0===o.truncated,appName:eO(o,"appName"),appBundleId:i,identifiers:{session:n,appId:i,appBundleId:i}}},screenshot:async(t={})=>{let r=ek(e.session,t.session);return{path:eU(await a("screenshot",t.path?[t.path]:[],t),"path"),identifiers:{session:r}}}}}}export{eG as createAgentDeviceClient,P as sendToDaemon,e_ as serializeCloseResult,ev as serializeDeployResult,eb as serializeDevice,ey as serializeEnsureSimulatorResult,eA as serializeInstallFromSourceResult,eD as serializeOpenResult,ew as serializeSessionListEntry,eP as serializeSnapshotResult};
package/dist/src/331.js DELETED
@@ -1,3 +0,0 @@
1
- import{URL as e,fileURLToPath as t,pathToFileURL as r}from"node:url";import{spawn as n,spawnSync as o}from"node:child_process";import i from"node:os";import s,{existsSync as a,promises as d}from"node:fs";import u from"node:path";import{AsyncLocalStorage as c}from"node:async_hooks";import l,{createHash as f}from"node:crypto";let m=new c,p=/(token|secret|password|authorization|cookie|api[_-]?key|access[_-]?key|private[_-]?key)/i,h=/(bearer\s+[a-z0-9._-]+|(?:api[_-]?key|token|secret|password)\s*[=:]\s*\S+)/i;function g(){return l.randomBytes(8).toString("hex")}async function w(e,t){let r={...e,diagnosticId:`${Date.now().toString(36)}-${l.randomBytes(4).toString("hex")}`,events:[]};return await m.run(r,t)}function S(){let e=m.getStore();return e?{diagnosticId:e.diagnosticId,requestId:e.requestId,session:e.session,command:e.command,debug:e.debug}:{}}function E(e){let t=m.getStore();if(!t)return;let r={ts:new Date().toISOString(),level:e.level??"info",phase:e.phase,session:t.session,requestId:t.requestId,command:t.command,durationMs:e.durationMs,data:e.data?y(e.data):void 0};if(t.events.push(r),!t.debug)return;let n=`[agent-device][diag] ${JSON.stringify(r)}
2
- `;try{t.logPath&&s.appendFile(t.logPath,n,()=>{}),t.traceLogPath&&s.appendFile(t.traceLogPath,n,()=>{}),t.logPath||t.traceLogPath||process.stderr.write(n)}catch{}}async function D(e,t,r){let n=Date.now();try{let o=await t();return E({level:"info",phase:e,durationMs:Date.now()-n,data:r}),o}catch(t){throw E({level:"error",phase:e,durationMs:Date.now()-n,data:{...r??{},error:t instanceof Error?t.message:String(t)}}),t}}function v(e={}){let t=m.getStore();if(!t||!e.force&&!t.debug||0===t.events.length)return null;try{let e=(t.session??"default").replace(/[^a-zA-Z0-9._-]/g,"_"),r=new Date().toISOString().slice(0,10),n=u.join(i.homedir(),".agent-device","logs",e,r);s.mkdirSync(n,{recursive:!0});let o=new Date().toISOString().replace(/[:.]/g,"-"),a=u.join(n,`${o}-${t.diagnosticId}.ndjson`),d=t.events.map(e=>JSON.stringify(y(e)));return s.writeFileSync(a,`${d.join("\n")}
3
- `),t.events=[],a}catch{return null}}function y(e){return function e(t,r,n){if(null==t)return t;if("string"==typeof t){var o=t,i=n;let e=o.trim();if(!e)return o;if(i&&p.test(i)||h.test(e))return"[REDACTED]";let r=function(e){try{let t=new URL(e);return t.search&&(t.search="?REDACTED"),(t.username||t.password)&&(t.username="REDACTED",t.password="REDACTED"),t.toString()}catch{return null}}(e);return r||(e.length>400?`${e.slice(0,200)}...<truncated>`:e)}if("object"!=typeof t)return t;if(r.has(t))return"[Circular]";if(r.add(t),Array.isArray(t))return t.map(t=>e(t,r));let s={};for(let[n,o]of Object.entries(t)){if(p.test(n)){s[n]="[REDACTED]";continue}s[n]=e(o,r,n)}return s}(e,new WeakSet)}class I extends Error{code;details;cause;constructor(e,t,r,n){super(t),this.code=e,this.details=r,this.cause=n}}function M(e){return e instanceof I?e:e instanceof Error?new I("UNKNOWN",e.message,void 0,e):new I("UNKNOWN","Unknown error",{err:e})}function A(e,t={}){let r=M(e),n=r.details?y(r.details):void 0,o=n&&"string"==typeof n.hint?n.hint:void 0,i=(n&&"string"==typeof n.diagnosticId?n.diagnosticId:void 0)??t.diagnosticId,s=(n&&"string"==typeof n.logPath?n.logPath:void 0)??t.logPath,a=o??function(e){switch(e){case"INVALID_ARGS":return"Check command arguments and run --help for usage examples.";case"SESSION_NOT_FOUND":return"Run open first or pass an explicit device selector.";case"TOOL_MISSING":return"Install required platform tooling and ensure it is available in PATH.";case"DEVICE_NOT_FOUND":return"Verify the target device is booted/connected and selectors match.";case"UNSUPPORTED_OPERATION":return"This command is not available for the selected platform/device.";case"COMMAND_FAILED":default:return"Retry with --debug and inspect diagnostics log for details.";case"UNAUTHORIZED":return"Refresh daemon metadata and retry the command."}}(r.code),d=function(e){if(!e)return;let t={...e};return delete t.hint,delete t.diagnosticId,delete t.logPath,Object.keys(t).length>0?t:void 0}(n),u=function(e,t,r){if("COMMAND_FAILED"!==e||r?.processExitError!==!0)return t;let n=function(e){let t=[/^an error was encountered processing the command/i,/^underlying error\b/i,/^simulator device failed to complete the requested operation/i];for(let r of e.split("\n")){let e=r.trim();if(e&&!t.some(t=>t.test(e)))return e.length>200?`${e.slice(0,200)}...`:e}return null}("string"==typeof r?.stderr?r.stderr:"");return n||t}(r.code,r.message,n);return{code:r.code,message:u,hint:a,diagnosticId:i,logPath:s,details:d}}async function N(e,t,r={}){return new Promise((o,i)=>{let s=n(e,t,{cwd:r.cwd,env:r.env,stdio:["pipe","pipe","pipe"],detached:r.detached}),a="",d=r.binaryStdout?Buffer.alloc(0):void 0,u="",c=!1,l=L(r.timeoutMs),f=l?setTimeout(()=>{c=!0,s.kill("SIGKILL")},l):null;r.binaryStdout||s.stdout.setEncoding("utf8"),s.stderr.setEncoding("utf8"),void 0!==r.stdin&&s.stdin.write(r.stdin),s.stdin.end(),s.stdout.on("data",e=>{r.binaryStdout?d=Buffer.concat([d??Buffer.alloc(0),Buffer.isBuffer(e)?e:Buffer.from(e)]):a+=e}),s.stderr.on("data",e=>{u+=e}),s.on("error",r=>{(f&&clearTimeout(f),"ENOENT"===r.code)?i(new I("TOOL_MISSING",`${e} not found in PATH`,{cmd:e},r)):i(new I("COMMAND_FAILED",`Failed to run ${e}`,{cmd:e,args:t},r))}),s.on("close",n=>{f&&clearTimeout(f);let s=n??1;c&&l?i(new I("COMMAND_FAILED",`${e} timed out after ${l}ms`,{cmd:e,args:t,stdout:a,stderr:u,exitCode:s,timeoutMs:l})):0===s||r.allowFailure?o({stdout:a,stderr:u,exitCode:s,stdoutBuffer:d}):i(new I("COMMAND_FAILED",`${e} exited with code ${s}`,{cmd:e,args:t,stdout:a,stderr:u,exitCode:s,processExitError:!0}))})})}async function O(e){try{var t;let{shell:r,args:n}=(t=e,"win32"===process.platform?{shell:"cmd.exe",args:["/c","where",t]}:{shell:"bash",args:["-lc",`command -v ${t}`]}),o=await N(r,n,{allowFailure:!0});return 0===o.exitCode&&o.stdout.trim().length>0}catch{return!1}}function T(e,t,r={}){let n=o(e,t,{cwd:r.cwd,env:r.env,stdio:["pipe","pipe","pipe"],encoding:r.binaryStdout?void 0:"utf8",input:r.stdin,timeout:L(r.timeoutMs)});if(n.error){let o=n.error.code;if("ETIMEDOUT"===o)throw new I("COMMAND_FAILED",`${e} timed out after ${L(r.timeoutMs)}ms`,{cmd:e,args:t,timeoutMs:L(r.timeoutMs)},n.error);if("ENOENT"===o)throw new I("TOOL_MISSING",`${e} not found in PATH`,{cmd:e},n.error);throw new I("COMMAND_FAILED",`Failed to run ${e}`,{cmd:e,args:t},n.error)}let i=r.binaryStdout?Buffer.isBuffer(n.stdout)?n.stdout:Buffer.from(n.stdout??""):void 0,s=r.binaryStdout?"":"string"==typeof n.stdout?n.stdout:(n.stdout??"").toString(),a="string"==typeof n.stderr?n.stderr:(n.stderr??"").toString(),d=n.status??1;if(0!==d&&!r.allowFailure)throw new I("COMMAND_FAILED",`${e} exited with code ${d}`,{cmd:e,args:t,stdout:s,stderr:a,exitCode:d,processExitError:!0});return{stdout:s,stderr:a,exitCode:d,stdoutBuffer:i}}function _(e,t,r={}){n(e,t,{cwd:r.cwd,env:r.env,stdio:"ignore",detached:!0}).unref()}async function P(e,t,r={}){return new Promise((o,i)=>{let s=n(e,t,{cwd:r.cwd,env:r.env,stdio:["pipe","pipe","pipe"],detached:r.detached});r.onSpawn?.(s);let a="",d="",u=r.binaryStdout?Buffer.alloc(0):void 0;r.binaryStdout||s.stdout.setEncoding("utf8"),s.stderr.setEncoding("utf8"),void 0!==r.stdin&&s.stdin.write(r.stdin),s.stdin.end(),s.stdout.on("data",e=>{if(r.binaryStdout){u=Buffer.concat([u??Buffer.alloc(0),Buffer.isBuffer(e)?e:Buffer.from(e)]);return}let t=String(e);a+=t,r.onStdoutChunk?.(t)}),s.stderr.on("data",e=>{let t=String(e);d+=t,r.onStderrChunk?.(t)}),s.on("error",r=>{"ENOENT"===r.code?i(new I("TOOL_MISSING",`${e} not found in PATH`,{cmd:e},r)):i(new I("COMMAND_FAILED",`Failed to run ${e}`,{cmd:e,args:t},r))}),s.on("close",n=>{let s=n??1;0===s||r.allowFailure?o({stdout:a,stderr:d,exitCode:s,stdoutBuffer:u}):i(new I("COMMAND_FAILED",`${e} exited with code ${s}`,{cmd:e,args:t,stdout:a,stderr:d,exitCode:s,processExitError:!0}))})})}function C(e,t,r={}){let o=n(e,t,{cwd:r.cwd,env:r.env,stdio:["ignore","pipe","pipe"],detached:r.detached}),i="",s="";o.stdout.setEncoding("utf8"),o.stderr.setEncoding("utf8"),o.stdout.on("data",e=>{i+=e}),o.stderr.on("data",e=>{s+=e});let a=new Promise((n,a)=>{o.on("error",r=>{"ENOENT"===r.code?a(new I("TOOL_MISSING",`${e} not found in PATH`,{cmd:e},r)):a(new I("COMMAND_FAILED",`Failed to run ${e}`,{cmd:e,args:t},r))}),o.on("close",o=>{let d=o??1;0===d||r.allowFailure?n({stdout:i,stderr:s,exitCode:d}):a(new I("COMMAND_FAILED",`${e} exited with code ${d}`,{cmd:e,args:t,stdout:i,stderr:s,exitCode:d,processExitError:!0}))})});return{child:o,wait:a}}function L(e){if(!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t}function F(){try{let e=$();return JSON.parse(s.readFileSync(u.join(e,"package.json"),"utf8")).version??"0.0.0"}catch{return"0.0.0"}}function $(){let e=u.dirname(t(import.meta.url)),r=e;for(let e=0;e<6;e+=1){let e=u.join(r,"package.json");if(s.existsSync(e))return r;r=u.dirname(r)}return e}let b=[/(^|[\/\s"'=])dist\/src\/daemon\.js($|[\s"'])/,/(^|[\/\s"'=])src\/daemon\.ts($|[\s"'])/];function k(e){if(!Number.isInteger(e)||e<=0)return!1;try{return process.kill(e,0),!0}catch(e){return"EPERM"===e.code}}function x(e){if(!Number.isInteger(e)||e<=0)return null;try{let t=T("ps",["-p",String(e),"-o","lstart="],{allowFailure:!0,timeoutMs:1e3});if(0!==t.exitCode)return null;let r=t.stdout.trim();return r.length>0?r:null}catch{return null}}function R(e){if(!Number.isInteger(e)||e<=0)return null;try{let t=T("ps",["-p",String(e),"-o","command="],{allowFailure:!0,timeoutMs:1e3});if(0!==t.exitCode)return null;let r=t.stdout.trim();return r.length>0?r:null}catch{return null}}function j(e,t){let r;if(!k(e))return!1;if(t){let r=x(e);if(!r||r!==t)return!1}let n=R(e);return!!n&&!!(r=n.toLowerCase().replaceAll("\\","/")).includes("agent-device")&&b.some(e=>e.test(r))}function B(e,t){try{return process.kill(e,t),!0}catch(t){let e=t.code;if("ESRCH"===e||"EPERM"===e)return!1;throw t}}async function U(e,t){if(!k(e))return!0;let r=Date.now();for(;Date.now()-r<t;)if(await new Promise(e=>setTimeout(e,50)),!k(e))return!0;return!k(e)}async function H(e,t){!j(e,t.expectedStartTime)||!B(e,"SIGTERM")||await U(e,t.termTimeoutMs)||B(e,"SIGKILL")&&await U(e,t.killTimeoutMs)}function G(e){return e?.HOME?.trim()||i.homedir()}function q(e,t={}){return"~"===e?G(t.env):e.startsWith("~/")?u.join(G(t.env),e.slice(2)):e}function z(e,t={}){let r=q(e,t);return u.isAbsolute(r)?r:u.resolve(t.cwd??process.cwd(),r)}function K(e){let t,r=(t=(e??"").trim())?z(t):u.join(q("~"),".agent-device");return{baseDir:r,infoPath:u.join(r,"daemon.json"),lockPath:u.join(r,"daemon.lock"),logPath:u.join(r,"daemon.log"),sessionsDir:u.join(r,"sessions")}}function V(e){let t=(e??"").trim().toLowerCase();return"http"===t?"http":"dual"===t?"dual":"socket"}function W(e){let t=(e??"").trim().toLowerCase();return"auto"===t?"auto":"socket"===t?"socket":"http"===t?"http":"auto"}function J(e){return"tenant"===(e??"").trim().toLowerCase()?"tenant":"none"}function Z(e){if(!e)return;let t=e.trim();if(t&&/^[a-zA-Z0-9._-]{1,128}$/.test(t))return t}export{default as node_net}from"node:net";export{default as node_http}from"node:http";export{default as node_https}from"node:https";export{I as AppError,M as asAppError,f as createHash,g as createRequestId,E as emitDiagnostic,a as existsSync,q as expandUserHomePath,e as external_node_url_URL,t as fileURLToPath,$ as findProjectRoot,v as flushDiagnosticsToSessionFile,S as getDiagnosticsMeta,j as isAgentDeviceDaemonProcess,k as isProcessAlive,l as node_crypto,s as node_fs,i as node_os,u as node_path,A as normalizeError,Z as normalizeTenantId,r as pathToFileURL,d as promises,R as readProcessCommand,x as readProcessStartTime,F as readVersion,K as resolveDaemonPaths,V as resolveDaemonServerMode,W as resolveDaemonTransportPreference,J as resolveSessionIsolationMode,z as resolveUserPath,N as runCmd,C as runCmdBackground,_ as runCmdDetached,P as runCmdStreaming,T as runCmdSync,n as spawn,H as stopProcessForTakeover,O as whichCmd,D as withDiagnosticTimer,w as withDiagnosticsScope};
package/dist/src/425.js DELETED
@@ -1 +0,0 @@
1
- import{AppError as e}from"./331.js";let t="<wifi|airplane|location> <on|off>",r="appearance <light|dark|toggle>",i="faceid <match|nonmatch|enroll|unenroll>",a="touchid <match|nonmatch|enroll|unenroll>",n="fingerprint <match|nonmatch>",s="permission <grant|deny|reset> <camera|microphone|photos|contacts|contacts-limited|notifications|calendar|location|location-always|media-library|motion|reminders|siri> [full|limited]",l="permission <grant|reset> <accessibility|screen-recording|input-monitoring>",o=`settings ${t} | settings ${r} | settings ${i} | settings ${a} | settings ${n} | settings ${s} | settings ${l}`,c=`settings requires ${t}, ${r}, ${i}, ${a}, ${n}, ${s}, or ${l}`,u=["app","frontmost-app","desktop","menubar"];function d(t){let r=t?.trim().toLowerCase();if("app"===r||"frontmost-app"===r||"desktop"===r||"menubar"===r)return r;throw new e("INVALID_ARGS",`Invalid surface: ${t}. Use ${u.join("|")}.`)}function p(e){var t;let r,i=f(e.label),a=f(e.value),n=f(e.identifier),s=(t=n)&&!/^[\w.]+:id\/[\w.-]+$/i.test(t)&&!/^_?NS:\d+$/i.test(t)?n:"";return(r=m(e.type??"")).includes("textfield")||r.includes("securetextfield")||r.includes("searchfield")||r.includes("edittext")||r.includes("textview")||r.includes("textarea")?a||i||s:i||a||s}function f(e){return"string"==typeof e?e.trim():""}function m(e){let t=e.trim().replace(/XCUIElementType/gi,"").replace(/^AX/,"").toLowerCase(),r=Math.max(t.lastIndexOf("."),t.lastIndexOf("/"));return -1!==r&&(t=t.slice(r+1)),t}function h(e,t={}){let r=[],i=[];for(let a of e){let e=a.depth??0;for(;r.length>0&&e<=r[r.length-1];)r.pop();let n=a.label?.trim()||a.value?.trim()||a.identifier?.trim()||"",s=x(a.type??"Element"),l="group"===s&&!n;l&&r.push(e);let o=l?e:Math.max(0,e-r.length);i.push({node:a,depth:o,type:s,text:w(a,o,l,s,t)})}return i}function w(e,t,r,i,a={}){var n,s,l,o,c;let u,d,h=i??x(e.type??"Element"),$=(u=p(e),{text:u,isLargeSurface:d=function(e,t){if("text-view"===t||"text-field"===t||"search"===t)return!0;let r=m(e.type??""),i=`${e.role??""} ${e.subrole??""}`.toLowerCase();return r.includes("textview")||r.includes("textarea")||r.includes("textfield")||r.includes("securetextfield")||r.includes("searchfield")||r.includes("edittext")||i.includes("text area")||i.includes("text field")}(e,h),shouldSummarize:d&&!!(n=u)&&(n.length>80||/[\r\n]/.test(n))}),A=(s=e,l=h,o=a,c=$,o.summarizeTextSurfaces&&c.shouldSummarize&&function(e,t,r){let i=f(e.label);if(i&&i!==r)return i;let a=f(e.identifier);if(a&&!S(a)&&a!==r)return a;switch(t){case"text":case"text-view":return"Text view";case"text-field":return"Text field";case"search":return"Search field";default:return""}}(s,l,c.text)||g(s,l)),y=" ".repeat(t),v=e.ref?`@${e.ref}`:"",I=(function(e,t,r,i){let a,n=[];if(!1===e.enabled&&n.push("disabled"),!r.summarizeTextSurfaces||(!0===e.selected&&n.push("selected"),b(t)&&n.push("editable"),function(e,t){if("scroll-area"===t)return!0;let r=(e.type??"").toLowerCase(),i=`${e.role??""} ${e.subrole??""}`.toLowerCase();return r.includes("scroll")||i.includes("scroll")}(e,t)&&n.push("scrollable"),!i.shouldSummarize))return n;return n.push(`preview:"${((a=i.text.replace(/\s+/g," ").trim()).length<=48?a:`${a.slice(0,45)}...`).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`),n.push("truncated"),[...new Set(n)]})(e,h,a,$).map(e=>` [${e}]`).join(""),_=A?` "${A}"`:"";return r?`${y}${v} [${h}]${I}`.trimEnd():`${y}${v} [${h}]${_}${I}`.trimEnd()}function g(e,t){let r=e.label?.trim(),i=e.value?.trim();if(b(t)){if(i)return i;if(r)return r}else if(r)return r;if(i)return i;let a=e.identifier?.trim();return!a||S(a)&&("group"===t||"image"===t||"list"===t||"collection"===t)?"":a}function x(e){let t=e.replace(/XCUIElementType/gi,"").toLowerCase(),r=e.includes(".")&&(e.startsWith("android.")||e.startsWith("androidx.")||e.startsWith("com."));switch(t.includes(".")&&(t=t.replace(/^android\.widget\./,"").replace(/^android\.view\./,"").replace(/^android\.webkit\./,"").replace(/^androidx\./,"").replace(/^com\.google\.android\./,"").replace(/^com\.android\./,"")),t){case"application":return"application";case"navigationbar":return"navigation-bar";case"tabbar":return"tab-bar";case"button":case"imagebutton":return"button";case"link":return"link";case"cell":return"cell";case"statictext":case"checkedtextview":return"text";case"textfield":case"edittext":return"text-field";case"textview":return r?"text":"text-view";case"textarea":return"text-view";case"switch":return"switch";case"slider":return"slider";case"image":case"imageview":return"image";case"webview":return"webview";case"framelayout":case"linearlayout":case"relativelayout":case"constraintlayout":case"viewgroup":case"view":case"group":return"group";case"listview":case"recyclerview":return"list";case"collectionview":return"collection";case"searchfield":return"search";case"segmentedcontrol":return"segmented-control";case"window":return"window";case"checkbox":return"checkbox";case"radio":return"radio";case"menuitem":return"menu-item";case"toolbar":return"toolbar";case"scrollarea":case"scrollview":case"nestedscrollview":return"scroll-area";case"table":return"table";default:return t||"element"}}function b(e){return"text-field"===e||"text-view"===e||"search"===e}function S(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}let $=100,A=new Set(["batch","replay"]);function y(t){let r;try{r=JSON.parse(t)}catch{throw new e("INVALID_ARGS","Batch steps must be valid JSON.")}if(!Array.isArray(r)||0===r.length)throw new e("INVALID_ARGS","Batch steps must be a non-empty JSON array.");return r}function v(t,r){if(!Array.isArray(t)||0===t.length)throw new e("INVALID_ARGS","batch requires a non-empty batchSteps array.");if(t.length>r)throw new e("INVALID_ARGS",`batch has ${t.length} steps; max allowed is ${r}.`);let i=[];for(let r=0;r<t.length;r+=1){let a=t[r];if(!a||"object"!=typeof a)throw new e("INVALID_ARGS",`Invalid batch step at index ${r}.`);let n="string"==typeof a.command?a.command.trim().toLowerCase():"";if(!n)throw new e("INVALID_ARGS",`Batch step ${r+1} requires command.`);if(A.has(n))throw new e("INVALID_ARGS",`Batch step ${r+1} cannot run ${n}.`);if(void 0!==a.positionals&&!Array.isArray(a.positionals))throw new e("INVALID_ARGS",`Batch step ${r+1} positionals must be an array.`);let s=a.positionals??[];if(s.some(e=>"string"!=typeof e))throw new e("INVALID_ARGS",`Batch step ${r+1} positionals must contain only strings.`);if(void 0!==a.flags&&("object"!=typeof a.flags||Array.isArray(a.flags)||!a.flags))throw new e("INVALID_ARGS",`Batch step ${r+1} flags must be an object.`);if(void 0!==a.runtime&&("object"!=typeof a.runtime||Array.isArray(a.runtime)||!a.runtime))throw new e("INVALID_ARGS",`Batch step ${r+1} runtime must be an object.`);i.push({command:n,positionals:s,flags:a.flags??{},runtime:a.runtime})}return i}export{TextDecoder,styleText}from"node:util";export{$ as DEFAULT_BATCH_MAX_STEPS,u as SESSION_SURFACES,c as SETTINGS_INVALID_ARGS_MESSAGE,o as SETTINGS_USAGE_OVERRIDE,h as buildSnapshotDisplayLines,g as displayLabel,p as extractReadableText,x as formatRole,w as formatSnapshotLine,y as parseBatchStepsJson,d as parseSessionSurface,v as validateAndNormalizeBatchSteps};
package/dist/src/bin.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- import type { CliFlags } from './utils/command-schema.ts';
2
- import type { AgentDeviceClient } from './client.ts';
3
- export declare function tryRunClientBackedCommand(params: {
4
- command: string;
5
- positionals: string[];
6
- flags: CliFlags;
7
- client: AgentDeviceClient;
8
- }): Promise<boolean>;
package/dist/src/cli.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { sendToDaemon } from './daemon-client.ts';
2
- type CliDeps = {
3
- sendToDaemon: typeof sendToDaemon;
4
- };
5
- export declare function runCli(argv: string[], deps?: CliDeps): Promise<void>;
6
- export {};
@@ -1,64 +0,0 @@
1
- export type MetroPrepareKind = 'auto' | 'react-native' | 'expo';
2
- type ResolvedMetroKind = Exclude<MetroPrepareKind, 'auto'>;
3
- type EnvSource = NodeJS.ProcessEnv | Record<string, string | undefined>;
4
- export type MetroRuntimeHints = {
5
- platform?: 'ios' | 'android';
6
- metroHost?: string;
7
- metroPort?: number;
8
- bundleUrl?: string;
9
- launchUrl?: string;
10
- };
11
- export type MetroBridgeResult = {
12
- enabled: boolean;
13
- baseUrl: string;
14
- statusUrl: string;
15
- bundleUrl: string;
16
- iosRuntime: MetroRuntimeHints;
17
- androidRuntime: MetroRuntimeHints;
18
- upstream: {
19
- bundleUrl: string;
20
- host: string;
21
- port: number;
22
- statusUrl: string;
23
- };
24
- probe: {
25
- reachable: boolean;
26
- statusCode: number;
27
- latencyMs: number;
28
- detail: string;
29
- };
30
- };
31
- export type PrepareMetroRuntimeOptions = {
32
- projectRoot?: string;
33
- kind?: MetroPrepareKind;
34
- metroPort?: number | string;
35
- listenHost?: string;
36
- statusHost?: string;
37
- publicBaseUrl?: string;
38
- proxyBaseUrl?: string;
39
- proxyBearerToken?: string;
40
- startupTimeoutMs?: number | string;
41
- probeTimeoutMs?: number | string;
42
- reuseExisting?: boolean;
43
- installDependenciesIfNeeded?: boolean;
44
- runtimeFilePath?: string;
45
- logPath?: string;
46
- env?: EnvSource;
47
- };
48
- export type PrepareMetroRuntimeResult = {
49
- projectRoot: string;
50
- kind: ResolvedMetroKind;
51
- dependenciesInstalled: boolean;
52
- packageManager: string | null;
53
- started: boolean;
54
- reused: boolean;
55
- pid: number;
56
- logPath: string;
57
- statusUrl: string;
58
- runtimeFilePath: string | null;
59
- iosRuntime: MetroRuntimeHints;
60
- androidRuntime: MetroRuntimeHints;
61
- bridge: MetroBridgeResult | null;
62
- };
63
- export declare function prepareMetroRuntime(input?: PrepareMetroRuntimeOptions): Promise<PrepareMetroRuntimeResult>;
64
- export {};
@@ -1,20 +0,0 @@
1
- import type { CommandFlags } from './core/dispatch.ts';
2
- import type { DaemonRequest, SessionRuntimeHints } from './daemon/types.ts';
3
- import type { SnapshotNode } from './utils/snapshot.ts';
4
- import type { AgentDeviceDevice, AgentDeviceSession, AgentDeviceSessionDevice, AppDeployResult, AppInstallFromSourceResult, InternalRequestOptions, MaterializationReleaseResult, StartupPerfSample } from './client-types.ts';
5
- export declare const DEFAULT_SESSION_NAME = "default";
6
- export declare function normalizeDeployResult(data: Record<string, unknown>, session?: string): AppDeployResult;
7
- export declare function normalizeInstallFromSourceResult(data: Record<string, unknown>, session?: string): AppInstallFromSourceResult;
8
- export declare function normalizeMaterializationReleaseResult(data: Record<string, unknown>): MaterializationReleaseResult;
9
- export declare function normalizeDevice(value: unknown): AgentDeviceDevice;
10
- export declare function normalizeSession(value: unknown): AgentDeviceSession;
11
- export declare function normalizeRuntimeHints(value: unknown): SessionRuntimeHints | undefined;
12
- export declare function normalizeOpenDevice(value: Record<string, unknown>): AgentDeviceSessionDevice | undefined;
13
- export declare function normalizeStartupSample(value: unknown): StartupPerfSample | undefined;
14
- export declare function readSnapshotNodes(value: unknown): SnapshotNode[];
15
- export declare function buildFlags(options: InternalRequestOptions): CommandFlags;
16
- export declare function buildMeta(options: InternalRequestOptions): DaemonRequest['meta'];
17
- export declare function resolveSessionName(defaultSession: string | undefined, session: string | undefined): string;
18
- export declare function readRequiredString(record: Record<string, unknown>, key: string): string;
19
- export declare function readOptionalString(record: Record<string, unknown>, key: string): string | undefined;
20
- export declare function readNullableString(record: Record<string, unknown>, key: string): string | null | undefined;