agent-device 0.14.7 → 0.14.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -9
- package/android-snapshot-helper/README.md +4 -2
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.14.7.apk → agent-device-android-snapshot-helper-0.14.9.apk} +0 -0
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.14.9.apk.sha256 +1 -0
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.14.7.manifest.json → agent-device-android-snapshot-helper-0.14.9.manifest.json} +6 -6
- package/dist/src/180.js +1 -1
- package/dist/src/208.js +1 -0
- package/dist/src/221.js +3 -3
- package/dist/src/6108.js +26 -0
- package/dist/src/7462.js +1 -0
- package/dist/src/7719.js +1 -0
- package/dist/src/9542.js +2 -2
- package/dist/src/9639.js +2 -2
- package/dist/src/9671.js +1 -0
- package/dist/src/9818.js +1 -1
- package/dist/src/android-adb.d.ts +11 -2
- package/dist/src/android-snapshot-helper.d.ts +12 -2
- package/dist/src/cli.js +82 -0
- package/dist/src/command-schema.js +382 -0
- package/dist/src/contracts.d.ts +1 -0
- package/dist/src/finders.d.ts +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.js +1 -1
- package/dist/src/internal/bin.js +2 -461
- package/dist/src/internal/daemon.js +20 -20
- package/dist/src/io.js +1 -1
- package/dist/src/remote-config.js +1 -1
- package/dist/src/selectors.d.ts +1 -0
- package/dist/src/server.js +20 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +86 -13
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +160 -93
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +1 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +3 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +15 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +1 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift +185 -0
- package/package.json +33 -6
- package/server.json +21 -0
- package/skills/agent-device/SKILL.md +11 -1
- package/skills/dogfood/SKILL.md +3 -1
- package/smithery.yaml +1 -0
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.14.7.apk.sha256 +0 -1
- package/dist/src/2007.js +0 -26
- package/skills/react-devtools/SKILL.md +0 -48
package/README.md
CHANGED
|
@@ -16,23 +16,33 @@ Device automation CLI for AI agents. Mobile, TV, and desktop apps.
|
|
|
16
16
|
|
|
17
17
|
`agent-device` lets coding agents run real apps, inspect UI state, interact with visible elements, and collect debugging evidence through one CLI.
|
|
18
18
|
|
|
19
|
-
It is built around token-efficient accessibility snapshots, not pixel-first screenshots. Agents read compact UI trees, locate elements through refs like `@e3`, perform touch and text actions, and capture screenshots, video, logs, network, perf, and React profiles only when evidence is needed.
|
|
19
|
+
It is built around token-efficient accessibility snapshots, not pixel-first screenshots. Agents read compact UI trees, locate elements through refs like `@e3`, perform touch and text actions, and capture screenshots, video, logs, network, CPU/memory/perf, crash-related logs, and React profiles only when evidence is needed.
|
|
20
|
+
|
|
21
|
+
Agents can ingest the current docs from [llms-full.txt](https://incubator.callstack.com/agent-device/llms-full.txt). The installed CLI help remains authoritative for exact command syntax.
|
|
20
22
|
|
|
21
23
|
## Agentic QA And Development
|
|
22
24
|
|
|
23
|
-
- **Quality Assurance**: dogfood flows, validate PR builds, check accessibility coverage,
|
|
24
|
-
- **Development**: build from specs,
|
|
25
|
+
- **Quality Assurance**: dogfood flows, validate PR builds, check accessibility coverage, and turn stable explorations into `.ad` e2e tests.
|
|
26
|
+
- **Development**: build from specs, inspect real runtime behavior, and iterate until the UI matches the work.
|
|
27
|
+
|
|
28
|
+
`agent-device` closes the agentic development loop: agents can write code, run the real app, verify the UI end-to-end, collect screenshots/videos/logs/perf evidence, and feed bugs, crashes, or performance findings back into the next fix iteration before a human reviews the PR.
|
|
29
|
+
|
|
30
|
+

|
|
25
31
|
|
|
26
32
|
If you know Vercel's [agent-browser](https://github.com/vercel-labs/agent-browser), this is the same idea for apps and devices.
|
|
27
33
|
|
|
28
|
-
|
|
34
|
+
Use it for AI mobile testing, AI QA for React Native and Expo apps, iOS Simulator automation, Android Emulator automation, tvOS/Android TV checks, and desktop app verification from coding agents. Humans install and configure `agent-device`; agents run the workflows.
|
|
35
|
+
|
|
36
|
+

|
|
37
|
+
|
|
38
|
+
Demo: Codex uses `agent-device` to inspect iOS Contacts through accessibility snapshots, interact with visible UI, and create a contact from a simple prompt.
|
|
29
39
|
|
|
30
40
|
## Quick Start
|
|
31
41
|
|
|
32
42
|
Install the CLI first:
|
|
33
43
|
|
|
34
44
|
```bash
|
|
35
|
-
npm install -g agent-device
|
|
45
|
+
npm install -g agent-device@latest
|
|
36
46
|
agent-device --version
|
|
37
47
|
agent-device help workflow
|
|
38
48
|
```
|
|
@@ -41,6 +51,54 @@ The CLI help is the source of truth for agents and is shipped with the installed
|
|
|
41
51
|
|
|
42
52
|
If you install skills separately, keep the CLI on `agent-device >= 0.14.0`. Older CLIs do not include the workflow help topics that the router skills expect.
|
|
43
53
|
|
|
54
|
+
### AI Agent Entry Points
|
|
55
|
+
|
|
56
|
+
- **Agent + terminal**: in Cursor, Codex, Claude Code, Windsurf, and similar clients, run `agent-device` in the integrated terminal. Start planning with `agent-device help workflow`; CLI help is authoritative.
|
|
57
|
+
- **Skills or rules**: install the skill with `npx skills add callstackincubator/agent-device`, use the bundled [agent-device skill](skills/agent-device/SKILL.md), or mirror it as a thin project rule, so the agent checks the installed version and reads `agent-device help workflow` before acting.
|
|
58
|
+
- **MCP router**: use `agent-device mcp` when an MCP-aware client needs install, status, and version-matched help discovery. MCP is intentionally a thin router; device automation still runs through CLI commands.
|
|
59
|
+
|
|
60
|
+
For client-specific setup, see [AI Agent Setup](https://incubator.callstack.com/agent-device/docs/agent-setup). For agent-readable docs, use [llms-full.txt](https://incubator.callstack.com/agent-device/llms-full.txt).
|
|
61
|
+
|
|
62
|
+
### MCP Router
|
|
63
|
+
|
|
64
|
+
`agent-device` ships an official stdio MCP router for discovery-oriented clients. It exposes only `status`, `install`, and `help` tools plus workflow prompts/resources; it does not expose device automation or generic shell execution over MCP.
|
|
65
|
+
|
|
66
|
+
Paste one of these into clients that accept `mcpServers`, such as Cursor project `.cursor/mcp.json` or user-level MCP settings.
|
|
67
|
+
|
|
68
|
+
<details>
|
|
69
|
+
<summary>Global install MCP config</summary>
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"mcpServers": {
|
|
74
|
+
"agent-device": {
|
|
75
|
+
"command": "agent-device",
|
|
76
|
+
"args": ["mcp"]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
</details>
|
|
83
|
+
|
|
84
|
+
<details>
|
|
85
|
+
<summary>No global install MCP config</summary>
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"mcpServers": {
|
|
90
|
+
"agent-device": {
|
|
91
|
+
"command": "npx",
|
|
92
|
+
"args": ["-y", "agent-device@<reviewed-version>", "mcp"]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
</details>
|
|
99
|
+
|
|
100
|
+
Registry metadata uses MCP name `io.github.callstackincubator/agent-device`, npm package `agent-device`, stdio transport, `mcpName` package verification, `server.json`, and `smithery.yaml`.
|
|
101
|
+
|
|
44
102
|
```bash
|
|
45
103
|
npm install -g agent-device@latest
|
|
46
104
|
agent-device --version
|
|
@@ -74,20 +132,69 @@ agent-device close
|
|
|
74
132
|
|
|
75
133
|
Snapshots assign refs like `@e1`, `@e2`, and `@e3` to current-screen elements. Refs from the default snapshot are immediately actionable; for hidden content, scroll and re-snapshot.
|
|
76
134
|
|
|
135
|
+
### First 5 Minutes: Expo Test App
|
|
136
|
+
|
|
137
|
+
Use the bundled Expo fixture when you want a concrete first agent run with setup checks, screenshots, replay, and performance evidence. This path requires a repo checkout because `examples/test-app` and the `pnpm test-app:*` scripts are not included in the published npm package.
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
git clone https://github.com/callstackincubator/agent-device.git
|
|
141
|
+
cd agent-device
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
First terminal:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
pnpm test-app:install
|
|
148
|
+
cd examples/test-app
|
|
149
|
+
npx expo-doctor@latest
|
|
150
|
+
cd ../..
|
|
151
|
+
pnpm test-app:ios
|
|
152
|
+
# or: pnpm test-app:android
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Then give your agent this prompt:
|
|
156
|
+
|
|
157
|
+
```text
|
|
158
|
+
Use agent-device to dogfood the bundled Expo app and produce an evidence-backed report.
|
|
159
|
+
|
|
160
|
+
Setup:
|
|
161
|
+
- Read `agent-device help workflow`, `agent-device help dogfood`, `agent-device help debugging`, and `agent-device help react-devtools` before planning commands.
|
|
162
|
+
- Confirm the test app setup commands were run: `pnpm test-app:install`, `cd examples/test-app && npx expo-doctor@latest`, then `pnpm test-app:ios` or `pnpm test-app:android`.
|
|
163
|
+
- If Metro prints an Expo URL, prefer opening the shell with that URL. On iOS use `agent-device open "Expo Go" <url> --platform ios`; on Android use the visible Expo/dev-client target or URL. Confirm the app UI with `snapshot -i`.
|
|
164
|
+
|
|
165
|
+
Run:
|
|
166
|
+
- Create `./dogfood-output/screenshots`, `./dogfood-output/videos`, `./dogfood-output/traces`, `./dogfood-output/perf`, and `./dogfood-output/replays`.
|
|
167
|
+
- Open a named session `expo-qa` and save a replay script to `./dogfood-output/replays/expo-test.ad`.
|
|
168
|
+
- Use command shapes like `agent-device --session expo-qa open "Expo Go" <url> --platform ios --save-script ./dogfood-output/replays/expo-test.ad`, `agent-device --session expo-qa screenshot ./dogfood-output/screenshots/home.png`, `agent-device --session expo-qa perf --json > ./dogfood-output/perf/baseline.json`, and `agent-device --session expo-qa record start ./dogfood-output/videos/checkout.mp4`.
|
|
169
|
+
- Capture a baseline `snapshot -i`, screenshot, and `perf --json` sample.
|
|
170
|
+
- Exercise Home, Catalog, product detail, Checkout, and Settings. Re-snapshot after each mutation and use refs/selectors from fresh snapshots.
|
|
171
|
+
- Capture at least one overlay-ref screenshot, one normal screenshot, one short video recording for a meaningful flow, logs marks around any issue, and trace output if a runtime symptom needs diagnostics.
|
|
172
|
+
- Run focused performance checks: compare `perf --json` before and after a navigation or form flow; if React DevTools connects, capture profile slow/rerender output. If it cannot connect, include the status and continue.
|
|
173
|
+
- Close the session so the `.ad` replay is written.
|
|
174
|
+
|
|
175
|
+
Report:
|
|
176
|
+
- Write `./dogfood-output/report.md`.
|
|
177
|
+
- Link every screenshot, video, trace, log path, replay file, and performance artifact you used.
|
|
178
|
+
- Include setup results, platform/device, Expo doctor outcome, coverage, severity counts, findings with repro commands, and a short performance section summarizing startup/CPU/memory/frame-health or React profile findings.
|
|
179
|
+
- If no issues are found, report covered flows and residual risk instead of claiming the app is bug-free.
|
|
180
|
+
```
|
|
181
|
+
|
|
77
182
|
## Where To Run agent-device
|
|
78
183
|
|
|
79
184
|
| Path | Best for | Start with |
|
|
80
185
|
| --- | --- | --- |
|
|
81
186
|
| Local | Exploration, debugging, and development loops on simulators, emulators, physical devices, macOS apps, and Linux desktop targets. | Follow the Quick Start. |
|
|
82
187
|
| CI/CD | Automated PR and merge validation with replay scripts and captured artifacts. | Start with the [EAS workflow template](https://github.com/callstackincubator/eas-agent-device/blob/main/.eas/workflows/agent-qa-mobile.yml). GitHub Actions template coming soon. |
|
|
83
|
-
| Cloud | Linux runners, managed devices, and remote execution. | Use [Agent Device Cloud](https://agent-device.dev/cloud) or [contact Callstack](mailto:hello@callstack.com) for team-scale QA. |
|
|
188
|
+
| Cloud / remote execution | Linux runners, managed devices, and remote execution. | Use [Agent Device Cloud](https://agent-device.dev/cloud), see [Commands](https://incubator.callstack.com/agent-device/docs/commands) for remote profiles, or [contact Callstack](mailto:hello@callstack.com) for team-scale QA. |
|
|
84
189
|
|
|
85
190
|
## Capabilities
|
|
86
191
|
|
|
87
192
|
- **Platforms**: iOS, Android, tvOS, Android TV, macOS, and Linux. Real devices and simulators are supported.
|
|
88
|
-
- **
|
|
193
|
+
- **Agent-native UI model**: token-efficient accessibility snapshots, current-screen refs for exploration, selectors for durable replay, and skill-tested workflow guidance.
|
|
194
|
+
- **Capture and debug**: screenshots, video, logs, network traffic, CPU/memory/performance data, crash-related logs, accessibility snapshots, and React render profiles.
|
|
89
195
|
- **Produce**: replayable `.ad` scripts (recorded replay files that run locally or in CI), e2e test runs, snapshot and screenshot diffs, and debugging artifacts.
|
|
90
196
|
- **React Native and Expo**: component tree inspection, props/state/hooks, and render profiling.
|
|
197
|
+
- **MCP boundary**: discovery and help over MCP; app/device control through the CLI for explicit, auditable commands.
|
|
91
198
|
- **License**: MIT. Free to use.
|
|
92
199
|
|
|
93
200
|
## How It Works
|
|
@@ -103,16 +210,19 @@ Used by teams and developers at Callstack, Expensify, Shopify, Kindred, Total Wi
|
|
|
103
210
|
## Documentation
|
|
104
211
|
|
|
105
212
|
- [Installation](https://incubator.callstack.com/agent-device/docs/installation)
|
|
213
|
+
- [AI Agent Setup](https://incubator.callstack.com/agent-device/docs/agent-setup)
|
|
106
214
|
- [Typed Client](https://incubator.callstack.com/agent-device/docs/client-api)
|
|
107
215
|
- [Commands](https://incubator.callstack.com/agent-device/docs/commands)
|
|
108
216
|
- [Replay & E2E](https://incubator.callstack.com/agent-device/docs/replay-e2e)
|
|
217
|
+
- [Security & Trust](https://incubator.callstack.com/agent-device/docs/security-trust)
|
|
109
218
|
- [Known limitations](https://incubator.callstack.com/agent-device/docs/known-limitations)
|
|
219
|
+
- [llms-full.txt](https://incubator.callstack.com/agent-device/llms-full.txt)
|
|
110
220
|
|
|
111
221
|
Agent integration:
|
|
112
222
|
|
|
113
223
|
- [agent-device skill](skills/agent-device/SKILL.md)
|
|
114
|
-
- [react-devtools skill](skills/react-devtools/SKILL.md)
|
|
115
224
|
- [dogfood skill](skills/dogfood/SKILL.md)
|
|
225
|
+
- MCP router: `agent-device mcp`
|
|
116
226
|
- [agent-device skill on ClawHub](https://clawhub.ai/okwasniewski/agent-device)
|
|
117
227
|
|
|
118
228
|
## Contributing
|
|
@@ -121,4 +231,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
|
121
231
|
|
|
122
232
|
## Made at Callstack
|
|
123
233
|
|
|
124
|
-
agent-device is open source and MIT licensed.
|
|
234
|
+
agent-device is open source and MIT licensed. Visit [agent-device.dev](https://agent-device.dev/), try the [EAS workflow template](https://github.com/callstackincubator/eas-agent-device/blob/main/.eas/workflows/agent-qa-mobile.yml), read the [incubator docs](https://incubator.callstack.com/agent-device/), or contact us at hello@callstack.com.
|
|
@@ -14,7 +14,8 @@ requires a stable signing certificate for `adb install -r` upgrades.
|
|
|
14
14
|
## Build
|
|
15
15
|
|
|
16
16
|
```sh
|
|
17
|
-
|
|
17
|
+
VERSION="$(node -p 'require("./package.json").version')"
|
|
18
|
+
sh ./scripts/build-android-snapshot-helper.sh "$VERSION" .tmp/android-snapshot-helper
|
|
18
19
|
```
|
|
19
20
|
|
|
20
21
|
The build uses Android SDK command-line tools directly. It expects `ANDROID_HOME` or
|
|
@@ -26,7 +27,8 @@ missing or outdated.
|
|
|
26
27
|
## Run
|
|
27
28
|
|
|
28
29
|
```sh
|
|
29
|
-
|
|
30
|
+
VERSION="$(node -p 'require("./package.json").version')"
|
|
31
|
+
adb install -r -t ".tmp/android-snapshot-helper/agent-device-android-snapshot-helper-$VERSION.apk"
|
|
30
32
|
adb shell am instrument -w \
|
|
31
33
|
-e waitForIdleTimeoutMs 500 \
|
|
32
34
|
-e timeoutMs 8000 \
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
6dfb064793721b49e6111162a428f312bc9365dfc06e05adb648c434105fdf4e agent-device-android-snapshot-helper-0.14.9.apk
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "android-snapshot-helper",
|
|
3
|
-
"version": "0.14.
|
|
4
|
-
"releaseTag": "v0.14.
|
|
5
|
-
"assetName": "agent-device-android-snapshot-helper-0.14.
|
|
3
|
+
"version": "0.14.9",
|
|
4
|
+
"releaseTag": "v0.14.9",
|
|
5
|
+
"assetName": "agent-device-android-snapshot-helper-0.14.9.apk",
|
|
6
6
|
"apkUrl": null,
|
|
7
|
-
"sha256": "
|
|
8
|
-
"checksumName": "agent-device-android-snapshot-helper-0.14.
|
|
7
|
+
"sha256": "6dfb064793721b49e6111162a428f312bc9365dfc06e05adb648c434105fdf4e",
|
|
8
|
+
"checksumName": "agent-device-android-snapshot-helper-0.14.9.apk.sha256",
|
|
9
9
|
"packageName": "com.callstack.agentdevice.snapshothelper",
|
|
10
|
-
"versionCode":
|
|
10
|
+
"versionCode": 14009,
|
|
11
11
|
"instrumentationRunner": "com.callstack.agentdevice.snapshothelper/.SnapshotInstrumentation",
|
|
12
12
|
"minSdk": 23,
|
|
13
13
|
"targetSdk": 36,
|
package/dist/src/180.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"node:
|
|
1
|
+
import e from"node:path";import t from"node:crypto";import n from"node:fs";import{resolveUserPath as a,expandUserHomePath as i}from"./3267.js";import{findProjectRoot as r}from"./9671.js";function o(t){let n,r=(n=(t??"").trim())?a(n):e.join(i("~"),".agent-device");return{baseDir:r,infoPath:e.join(r,"daemon.json"),lockPath:e.join(r,"daemon.lock"),logPath:e.join(r,"daemon.log"),sessionsDir:e.join(r,"sessions")}}function s(e){let t=(e??"").trim().toLowerCase();return"http"===t?"http":"dual"===t?"dual":"socket"}function l(e){let t=(e??"").trim().toLowerCase();return"auto"===t?"auto":"socket"===t?"socket":"http"===t?"http":"auto"}function d(e){return"tenant"===(e??"").trim().toLowerCase()?"tenant":"none"}function u(e){if(!e)return;let t=e.trim();if(t&&/^[a-zA-Z0-9._-]{1,128}$/.test(t))return t}let p=/(?:^|[^\w$.])(?:import|export)\s+(?:type\s+)?(?:[^'"`]*?\s+from\s+)?['"]([^'"]+)['"]/gm,c=/import\(\s*['"]([^'"]+)['"]\s*\)/gm,m=[".ts",".tsx",".js",".jsx",".mjs",".cjs"];function f(){let e=process.argv[1];return e?h(e):"unknown"}function h(a,i=r()){try{let r=e.resolve(i),o=[e.resolve(a)],s=new Set,l=[];for(;o.length>0;){let t=o.pop();if(!t||s.has(t))continue;s.add(t);let a=n.statSync(t);if(!a.isFile())continue;let i=e.relative(r,t)||t;l.push(`${i}:${a.size}:${Math.trunc(a.mtimeMs)}`);let d=n.readFileSync(t,"utf8");for(let n of function(e){let t=new Set;return g(e,p,t),g(e,c,t),[...t]}(d)){let a=function(t,n){let a=e.resolve(e.dirname(t),n),i=I(a);if(i)return i;for(let e of m){let t=I(`${a}${e}`);if(t)return t}for(let t of m){let n=I(e.join(a,`index${t}`));if(n)return n}return null}(t,n);a&&o.push(a)}}let d=l.sort().join("|"),u=t.createHash("sha1").update(d).digest("hex");return`graph:${l.length}:${u}`}catch{return"unknown"}}function g(e,t,n){t.lastIndex=0;let a=null;for(;null!==(a=t.exec(e));){let e=a[1]?.trim();e?.startsWith(".")&&n.add(e)}}function I(e){try{return n.statSync(e).isFile()?e:null}catch{return null}}function v(e){return e?{message:e}:{}}function S(e,t){return t?{...e,message:t}:e}function b(e){return"string"==typeof e?.message&&e.message.length>0?e.message:null}function k(e){let t=e.appId??e.bundleId??e.packageName;return{session:e.session,appId:t,appBundleId:e.bundleId,package:e.packageName}}function N(e,t,n){return{deviceId:t,deviceName:n,..."android"===e?{serial:t}:"ios"===e?{udid:t}:{}}}function $(e,t={}){let n=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&&n?{serial:e.android?.serial??e.id}:{}}}function _(e){return{name:e.name,...$(e.device,{includeAndroidSerial:!1}),createdAt:e.createdAt}}function z(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 w(e){let t=e.created?"Created":"Reused",n=e.booted?" (booted)":"";return S({udid:e.udid,device:e.device,runtime:e.runtime,ios_simulator_device_set:e.iosSimulatorDeviceSet??null,created:e.created,booted:e.booted},`${t}: ${e.device} ${e.udid}${n}`)}function P(e){return e.bundleId??e.package??e.app}function y(e){return S({app:e.app,appPath:e.appPath,platform:e.platform,...e.appId?{appId:e.appId}:{},...e.bundleId?{bundleId:e.bundleId}:{},...e.package?{package:e.package}:{}},`Installed: ${P(e)}`)}function C(e){return e.appName??e.bundleId??e.packageName??e.launchTarget}function x(e){return S({launchTarget:e.launchTarget,...e.appName?{appName:e.appName}:{},...e.appId?{appId:e.appId}:{},...e.bundleId?{bundleId:e.bundleId}:{},...e.packageName?{package:e.packageName}:{},...e.installablePath?{installablePath:e.installablePath}:{},...e.archivePath?{archivePath:e.archivePath}:{},...e.materializationId?{materializationId:e.materializationId}:{},...e.materializationExpiresAt?{materializationExpiresAt:e.materializationExpiresAt}:{}},`Installed: ${C(e)}`)}function j(e){let t=e.appName??e.appBundleId??e.session;return S({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?$(e.device):{}},t?`Opened: ${t}`:"Opened")}function A(e){return{session:e.session,...e.shutdown?{shutdown:e.shutdown}:{},...v(e.session?`Closed: ${e.session}`:"Closed")}}function D(e){return{nodes:e.nodes,truncated:e.truncated,...e.appName?{appName:e.appName}:{},...e.appBundleId?{appBundleId:e.appBundleId}:{},...e.visibility?{visibility:e.visibility}:{},...e.androidSnapshot?{androidSnapshot:e.androidSnapshot}:{},...e.warnings&&e.warnings.length>0?{warnings:e.warnings}:{}}}export{k as buildAppIdentifiers,N as buildDeviceIdentifiers,h as computeDaemonCodeSignature,u as normalizeTenantId,b as readCommandMessage,f as resolveDaemonCodeSignature,o as resolveDaemonPaths,s as resolveDaemonServerMode,l as resolveDaemonTransportPreference,P as resolveDeployResultTarget,C as resolveInstallFromSourceResultTarget,d as resolveSessionIsolationMode,A as serializeCloseResult,y as serializeDeployResult,z as serializeDevice,w as serializeEnsureSimulatorResult,x as serializeInstallFromSourceResult,j as serializeOpenResult,_ as serializeSessionListEntry,D as serializeSnapshotResult,v as successText,S as withSuccessText};
|
package/dist/src/208.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"node:fs";import t from"node:path";import{AppError as n}from"./9152.js";import{resolveUserPath as r}from"./3267.js";let o=new Set(["1","true","yes","on"]),i=new Set(["0","false","no","off"]);function a(e){return`AGENT_DEVICE_${e.replace(/([A-Z])/g,"_$1").replace(/[^A-Za-z0-9_]/g,"_").toUpperCase()}`}function s(e,t,r,o){if(e.multiple)return(Array.isArray(t)?t:[t]).map(t=>s({...e,multiple:!1},t,r,o));if("boolean"===e.type){var i=t,a=r,u=o;if("boolean"==typeof i)return i;if("string"==typeof i){let e=l(i);if(void 0!==e)return e}throw new n("INVALID_ARGS",`Invalid value for "${u}" in ${a}. Expected boolean.`)}if("booleanOrString"===e.type){if("boolean"==typeof t)return t;if("string"==typeof t&&void 0!==l(t))return l(t);if("string"==typeof t&&t.trim().length>0)return t;throw new n("INVALID_ARGS",`Invalid value for "${o}" in ${r}. Expected boolean or non-empty string.`)}if("string"===e.type){if("string"==typeof t&&t.trim().length>0)return t;throw new n("INVALID_ARGS",`Invalid value for "${o}" in ${r}. Expected non-empty string.`)}if("enum"===e.type){if(void 0!==e.setValue){var y=e,f=t,m=r,p=o;let i=y.setValue;if(f===i)return i;if("string"==typeof f){let e=f.trim();if(""===e||"true"===e||"1"===e)return i;if("false"===e||"0"===e)return}if(!0===f)return i;if(!1!==f)throw new n("INVALID_ARGS",`Invalid value for "${p}" in ${m}. Expected boolean-like value for enum flag.`);return}if("string"!=typeof t||!e.enumValues?.includes(t))throw new n("INVALID_ARGS",`Invalid value for "${o}" in ${r}. Expected one of: ${e.enumValues?.join(", ")}.`);return t}let c="number"==typeof t?t:"string"==typeof t?Number(t):NaN;if(!Number.isFinite(c)||!Number.isInteger(c))throw new n("INVALID_ARGS",`Invalid value for "${o}" in ${r}. Expected integer.`);if("number"==typeof e.min&&c<e.min)throw new n("INVALID_ARGS",`Invalid value for "${o}" in ${r}. Must be >= ${e.min}.`);if("number"==typeof e.max&&c>e.max)throw new n("INVALID_ARGS",`Invalid value for "${o}" in ${r}. Must be <= ${e.max}.`);return c}function l(e){let t=e.trim().toLowerCase();return!!o.has(t)||!i.has(t)&&void 0}let u=[{key:"stateDir",type:"string",path:!0},{key:"daemonBaseUrl",type:"string"},{key:"daemonAuthToken",type:"string"},{key:"daemonTransport",type:"enum",enumValues:["auto","socket","http"]},{key:"daemonServerMode",type:"enum",enumValues:["socket","http","dual"]},{key:"tenant",type:"string"},{key:"sessionIsolation",type:"enum",enumValues:["none","tenant"]},{key:"runId",type:"string"},{key:"leaseId",type:"string"},{key:"leaseBackend",type:"enum",enumValues:["ios-simulator","ios-instance","android-instance"]},{key:"platform",type:"enum",enumValues:["ios","macos","android","linux","apple"]},{key:"target",type:"enum",enumValues:["mobile","tv","desktop"]},{key:"device",type:"string"},{key:"udid",type:"string"},{key:"serial",type:"string"},{key:"iosSimulatorDeviceSet",type:"string",path:!0,legacyEnvNames:["IOS_SIMULATOR_DEVICE_SET"]},{key:"androidDeviceAllowlist",type:"string",legacyEnvNames:["ANDROID_DEVICE_ALLOWLIST"]},{key:"session",type:"string"},{key:"metroProjectRoot",type:"string",path:!0},{key:"metroKind",type:"enum",enumValues:["auto","react-native","expo"]},{key:"metroPublicBaseUrl",type:"string"},{key:"metroProxyBaseUrl",type:"string"},{key:"metroBearerToken",type:"string",legacyEnvNames:["AGENT_DEVICE_PROXY_TOKEN"]},{key:"metroPreparePort",type:"int",min:1,max:65535},{key:"metroListenHost",type:"string"},{key:"metroStatusHost",type:"string"},{key:"metroStartupTimeoutMs",type:"int",min:1},{key:"metroProbeTimeoutMs",type:"int",min:1},{key:"metroRuntimeFile",type:"string",path:!0},{key:"metroNoReuseExisting",type:"boolean"},{key:"metroNoInstallDeps",type:"boolean"}],y=new Map(u.map(e=>[e.key,e]));function f(e){let t=e.env??process.env;return r(e.configPath,{cwd:e.cwd,env:t})}function m(o){let i=function(o){let i,a,l=o.env??process.env,u=f(o);if(!e.existsSync(u))throw new n("INVALID_ARGS",`Remote config file not found: ${u}`);try{i=e.readFileSync(u,"utf8")}catch(e){throw new n("INVALID_ARGS",`Failed to read remote config file: ${u}`,{cause:e instanceof Error?e.message:String(e)})}try{a=JSON.parse(i)}catch(e){throw new n("INVALID_ARGS",`Invalid JSON in remote config file: ${u}`,{cause:e instanceof Error?e.message:String(e)})}if(!a||"object"!=typeof a||Array.isArray(a))throw new n("INVALID_ARGS",`Remote config file must contain a JSON object: ${u}`);let m={},p=a,c=t.dirname(u);for(let[e,t]of Object.entries(p)){let o=y.get(e);if(!o)throw new n("INVALID_ARGS",`Unsupported remote config key "${e}" in remote config file ${u}.`);let i=s(o,t,`remote config file ${u}`,e);m[o.key]="string"==typeof i&&"path"in o&&o.path?r(i,{cwd:c,env:l}):i}return{resolvedPath:u,profile:m}}(o);return{resolvedPath:i.resolvedPath,profile:function(...e){let t={};for(let n of e)if(n)for(let e of u){let r=n[e.key];void 0!==r&&(t[e.key]=r)}return t}(function(e=process.env){let t={};for(let n of u){let r=(function(e){let t=y.get(e);return[a(e),...t?.legacyEnvNames??[]]})(n.key).map(t=>({name:t,value:e[t]})).find(e=>"string"==typeof e.value&&e.value.trim().length>0);r&&(t[n.key]=s(n,r.value,`environment variable ${r.name}`,r.name))}return t}(o.env),i.profile)}}export{u as REMOTE_CONFIG_FIELD_SPECS,a as buildPrimaryEnvVarName,s as parseSourceValue,f as resolveRemoteConfigPath,m as resolveRemoteConfigProfile};
|
package/dist/src/221.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e from"node:crypto";import t from"node:fs";import n from"node:fs/promises";import r from"node:os";import i from"node:path";import{AppError as o}from"./9152.js";import{installAndroidAdbPackage as a}from"./9639.js";let s="android-snapshot-helper",l="com.callstack.agentdevice.snapshothelper",u="com.callstack.agentdevice.snapshothelper/.SnapshotInstrumentation",d="android-snapshot-helper-v1",c="uiautomator-xml",f={"-r":"replace","-t":"allowTestPackages","-d":"allowDowngrade","-g":"grantPermissions"};async function h(e){let t=await g(e.apkPath);if(t!==e.manifest.sha256)throw new o("COMMAND_FAILED","Android snapshot helper APK checksum mismatch",{apkPath:e.apkPath,expectedSha256:e.manifest.sha256,actualSha256:t})}async function p(e){let t=e.fetch??fetch,a=await t(e.manifestUrl);if(!a.ok)throw new o("COMMAND_FAILED","Failed to download Android snapshot helper manifest",{manifestUrl:e.manifestUrl,status:a.status,statusText:a.statusText});let s=m(JSON.parse((await A(a,65536,"Android snapshot helper manifest")).toString("utf8")));if(!s.apkUrl)throw new o("COMMAND_FAILED","Android snapshot helper manifest does not include apkUrl",{manifestUrl:e.manifestUrl});let l=e.cacheDir??i.join(r.tmpdir(),`agent-device-android-snapshot-helper-${s.version}`),u=!e.cacheDir;await n.mkdir(l,{recursive:!0});let d=s.assetName??`agent-device-android-snapshot-helper-${s.version}.apk`,c=i.join(l,d),f=await t(s.apkUrl);if(!f.ok)throw new o("COMMAND_FAILED","Failed to download Android snapshot helper APK",{apkUrl:s.apkUrl,status:f.status,statusText:f.statusText});await n.writeFile(c,await A(f,0x1400000,"Android snapshot helper APK"));let p={apkPath:c,manifest:s};return await h(p),{...p,cleanup:async()=>{await n.rm(u?l:c,{recursive:u,force:!0})}}}function m(e){var t,n;if(!e||"object"!=typeof e||Array.isArray(e))throw new o("INVALID_ARGS","Android snapshot helper manifest must be an object.");return{name:b(e.name,"name",s),version:N(e.version,"version"),releaseTag:M(e.releaseTag),assetName:M(e.assetName),apkUrl:(t=e.apkUrl,n="apkUrl",null===t?null:N(t,n)),sha256:function(e){let t=N(e,"sha256").trim().toLowerCase();if(64!==t.length||!function(e){for(let t of e){let e=t.charCodeAt(0),n=e>=48&&e<=57,r=e>=97&&e<=102;if(!n&&!r)return!1}return!0}(t))throw new o("INVALID_ARGS","Android snapshot helper manifest sha256 must be a 64-character hex string.");return t}(e.sha256),checksumName:M(e.checksumName),packageName:N(e.packageName,"packageName"),versionCode:v(e.versionCode,"versionCode"),instrumentationRunner:N(e.instrumentationRunner,"instrumentationRunner"),minSdk:v(e.minSdk,"minSdk"),targetSdk:void 0===e.targetSdk?void 0:v(e.targetSdk,"targetSdk"),outputFormat:b(e.outputFormat,"outputFormat",c),statusProtocol:b(e.statusProtocol,"statusProtocol",d),installArgs:w(e.installArgs)}}async function A(e,t,n){let r=e.headers.get("content-length");if(null!==r){let e=Number(r);if(Number.isFinite(e)&&e>t)throw new o("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:e,maxBytes:t})}if(!e.body){let r=Buffer.from(await e.arrayBuffer());if(r.length>t)throw new o("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:r.length,maxBytes:t});return r}let i=e.body.getReader(),a=[],s=0;try{for(;;){let{done:e,value:r}=await i.read();if(e)break;if((s+=r.byteLength)>t)throw new o("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:s,maxBytes:t});a.push(Buffer.from(r))}}finally{i.releaseLock()}return Buffer.concat(a,s)}function w(e){let t=function(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new o("INVALID_ARGS",`Android snapshot helper manifest ${t} must be a string array.`);return e}(e,"installArgs");if("install"!==t[0])throw new o("INVALID_ARGS",'Android snapshot helper manifest installArgs must start with "install".');if(t.some(e=>e.includes("\0")))throw new o("INVALID_ARGS","Android snapshot helper manifest installArgs must not contain null bytes.");let n=t.slice(1).find(e=>void 0===I(e));if(n)throw new o("INVALID_ARGS",`Android snapshot helper manifest installArgs contains unsupported install flag "${n}".`);return t}async function g(n){return await new Promise((r,i)=>{let o=e.createHash("sha256"),a=t.createReadStream(n);a.on("error",i),a.on("data",e=>o.update(e)),a.on("end",()=>r(o.digest("hex")))})}function N(e,t){if("string"!=typeof e||0===e.trim().length)throw new o("INVALID_ARGS",`Android snapshot helper manifest ${t} is required.`);return e}function M(e){return"string"==typeof e&&e.trim().length>0?e:void 0}function v(e,t){if("number"!=typeof e||!Number.isInteger(e))throw new o("INVALID_ARGS",`Android snapshot helper manifest ${t} must be an integer.`);return e}function b(e,t,n){if(e!==n)throw new o("INVALID_ARGS",`Android snapshot helper manifest ${t} must be "${n}".`);return n}function I(e){if(Object.hasOwn(f,e))return f[e]}function x(e){let t=`${e??""}`.toLowerCase();return t.includes("scroll")||t.includes("recyclerview")||t.includes("listview")||t.includes("gridview")||t.includes("collectionview")||"table"===t}function D(e){return!!x(e.type)||`${e.role??""} ${e.subrole??""}`.toLowerCase().includes("scroll")}function S(e,t,n){let{sourceNodes:r,...i}=C(O(e),t,n);return i}function C(e,t,n){let r={nodes:[],sourceNodes:[],maxNodes:t,maxDepth:n.depth??1/0,options:n,analysis:function(e){let t=0,n=0,r=[...e.children];for(;r.length>0;){let e=r.pop();t+=1,n=Math.max(n,e.depth),r.push(...e.children)}return{rawNodeCount:t,maxDepth:n}}(e),interactiveDescendantMemo:new Map,truncated:!1},i=n.scope?function(e,t){let n=t.toLowerCase(),r=[...e.children],i=0;for(;i<r.length;){let e=r[i++],t=e.label?.toLowerCase()??"",o=e.value?.toLowerCase()??"",a=e.identifier?.toLowerCase()??"";if(t.includes(n)||o.includes(n)||a.includes(n))return e;r.push(...e.children)}return null}(e,n.scope):null;for(let t of i?[i]:e.children)if(function e(t,n,r,i,o=!1,a=!1){if(t.nodes.length>=t.maxNodes){t.truncated=!0;return}if(r>t.maxDepth)return;let s=t.options.raw||function(e,t,n,r,i){var o,a,s;let l=function(e){let t=E(e.type),n=!!(e.label&&e.label.trim().length>0),r=!!(e.identifier&&e.identifier.trim().length>0);return{type:t,hasMeaningfulText:n&&!F(e.label??""),hasMeaningfulId:r&&!F(e.identifier??""),isStructural:function(e){let t=e.split(".").pop()??e;return t.includes("layout")||"viewgroup"===t||"view"===t}(t),isVisual:"imageview"===t||"imagebutton"===t}}(e);return t.interactiveOnly?function(e,t,n,r,i){var o,a,s,l;return!!(e.hittable||x(t.type)&&r)||(o=t,a=n,s=r,l=i,(!!o.hasMeaningfulText||!!o.hasMeaningfulId)&&!o.isVisual&&(!o.isStructural||!!l)&&(a||s||l))}(e,l,n,r,i):t.compact?l.hasMeaningfulText||l.hasMeaningfulId||!!e.hittable:!l.isStructural&&!l.isVisual||(o=e,a=l,s=r,!!o.hittable||!!a.hasMeaningfulText||!!a.hasMeaningfulId&&!!s||s)}(n,t.options,o,function e(t,n){let r=t.interactiveDescendantMemo.get(n);if(void 0!==r)return r;for(let r of n.children)if(r.hittable||e(t,r))return t.interactiveDescendantMemo.set(n,!0),!0;return t.interactiveDescendantMemo.set(n,!1),!1}(t,n),a)?function(e,t,n,r){let i=e.nodes.length;return e.sourceNodes.push(t),e.nodes.push({index:i,type:t.type??void 0,label:t.label??void 0,value:t.value??void 0,identifier:t.identifier??void 0,rect:t.rect,enabled:t.enabled,hittable:t.hittable,depth:n,parentIndex:r,...t.hiddenContentAbove?{hiddenContentAbove:!0}:{},...t.hiddenContentBelow?{hiddenContentBelow:!0}:{}}),i}(t,n,r,i):i,l=o||!!n.hittable,u=a||function(e){if(!e)return!1;let t=E(e);return t.includes("recyclerview")||t.includes("listview")||t.includes("gridview")}(n.type);for(let i of n.children)if(e(t,i,r+1,s,l,u),t.truncated)return}(r,t,0),r.truncated)break;let o={nodes:r.nodes,sourceNodes:r.sourceNodes,analysis:r.analysis};return r.truncated?{...o,truncated:!0}:o}function k(e){let t=function(e){let t=new Map,n=e.indexOf(" "),r=e.lastIndexOf(">");if(n<0||r<=n)return t;let i=n;for(;i<r&&!((i=y(e,i,r))>=r);){var o;let n=e[i];if("/"===n||">"===n)break;let a=i;for(;i<r&&!("="===(o=e[i]??"")||"/"===o||">"===o||_(o));)i+=1;let s=e.slice(a,i);if(i=y(e,i,r),!s||"="!==e[i])break;i=y(e,i+1,r);let l=e[i];if('"'!==l&&"'"!==l)break;let u=i+=1;for(;i<r&&e[i]!==l;)i+=1;if(i>=r)break;t.set(s,function(e){let t="",n=0;for(;n<e.length;){let r=e.indexOf("&",n);if(r<0){t+=e.slice(n);break}t+=e.slice(n,r);let i=e.indexOf(";",r+1);if(i<0){t+=e.slice(r);break}t+=function(e){switch(e){case"amp":return"&";case"lt":return"<";case"gt":return">";case"quot":return'"';case"apos":return"'";default:return function(e){if(!e.startsWith("#"))return;let t=e[1]?.toLowerCase()==="x"?16:10,n=16===t?e.slice(2):e.slice(1);if(!n||!function(e,t){for(let n of e){let e=n.charCodeAt(0),r=e>=48&&e<=57;if(10===t){if(!r)return!1;continue}let i=e>=65&&e<=70,o=e>=97&&e<=102;if(!r&&!i&&!o)return!1}return!0}(n,t))return;let r=Number.parseInt(n,t);if(Number.isFinite(r))try{return String.fromCodePoint(r)}catch{return}}(e)}}(e.slice(r+1,i))??e.slice(r,i+1),n=i+1}return t}(e.slice(u,i))),i+=1}return t}(e),n=e=>{let n=L(t,e);if(null!==n)return"true"===n};return{text:L(t,"text"),desc:L(t,"content-desc"),resourceId:L(t,"resource-id"),className:L(t,"class"),bounds:L(t,"bounds"),clickable:n("clickable"),enabled:n("enabled"),focusable:n("focusable"),focused:n("focused")}}function y(e,t,n){for(;t<n&&_(e[t]??"");)t+=1;return t}function _(e){return" "===e||"\n"===e||"\r"===e||" "===e}function L(e,t){return e.get(t)??null}function T(e){if(!e)return;let t=/\[(\d+),(\d+)\]\[(\d+),(\d+)\]/.exec(e);if(!t)return;let n=Number(t[1]),r=Number(t[2]);return{x:n,y:r,width:Math.max(0,Number(t[3])-n),height:Math.max(0,Number(t[4])-r)}}function O(e){let t={type:null,label:null,value:null,identifier:null,depth:-1,children:[]},n=[t],r=/<node\b[^>]*>|<\/node>/g,i=r.exec(e);for(;i;){let t=i[0];if(t.startsWith("</node")){n.length>1&&n.pop(),i=r.exec(e);continue}let o=k(t),a=T(o.bounds),s=n[n.length-1],l={type:o.className,label:o.text||o.desc,value:o.text,identifier:o.resourceId,rect:a,enabled:o.enabled,hittable:o.clickable??o.focusable,depth:s.depth+1,parentIndex:void 0,children:[]};s.children.push(l),t.endsWith("/>")||n.push(l),i=r.exec(e)}return t}function E(e){return e?e.toLowerCase():""}function F(e){let t=e.trim();return!!t&&/^[\w.]+:id\/[\w.-]+$/i.test(t)}async function R(e){let t,n=e.waitForIdleTimeoutMs??500,r=e.timeoutMs??8e3,i=e.commandTimeoutMs??r+5e3,a=e.maxDepth??128,s=e.maxNodes??5e3,u=e.packageName??l,d=e.instrumentationRunner??`${u}/.SnapshotInstrumentation`,c=["shell","am","instrument","-w","-e","waitForIdleTimeoutMs",String(n),"-e","timeoutMs",String(r),"-e","maxDepth",String(a),"-e","maxNodes",String(s),d],f=await e.adb(c,{allowFailure:!0,timeoutMs:i});try{t=P(`${f.stdout}
|
|
2
|
-
${f.stderr}`)}catch(e){throw new o("COMMAND_FAILED",0===f.exitCode?"Android snapshot helper output could not be parsed":"Android snapshot helper failed before returning parseable output",{stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode},e)}if(0!==f.exitCode)throw new o("COMMAND_FAILED","Android snapshot helper failed",{stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,helper:t.metadata});return t}function P(e){var t,n;let r=function(e){var t;let n={status:[],results:[],currentStatus:null,currentResult:null};for(let t of e.split(/\r?\n/))!function(e,t){if(e.startsWith("INSTRUMENTATION_STATUS: ")){t.currentStatus??={},
|
|
1
|
+
import e from"node:crypto";import t from"node:fs";import n from"node:fs/promises";import r from"node:os";import i from"node:path";import{AppError as o}from"./9152.js";import{installAndroidAdbPackage as a}from"./9639.js";let s="android-snapshot-helper",l="com.callstack.agentdevice.snapshothelper",u="com.callstack.agentdevice.snapshothelper/.SnapshotInstrumentation",d="android-snapshot-helper-v1",c="uiautomator-xml",f={"-r":"replace","-t":"allowTestPackages","-d":"allowDowngrade","-g":"grantPermissions"};async function h(e){let t=await g(e.apkPath);if(t!==e.manifest.sha256)throw new o("COMMAND_FAILED","Android snapshot helper APK checksum mismatch",{apkPath:e.apkPath,expectedSha256:e.manifest.sha256,actualSha256:t})}async function p(e){let t=e.fetch??fetch,a=await t(e.manifestUrl);if(!a.ok)throw new o("COMMAND_FAILED","Failed to download Android snapshot helper manifest",{manifestUrl:e.manifestUrl,status:a.status,statusText:a.statusText});let s=m(JSON.parse((await A(a,65536,"Android snapshot helper manifest")).toString("utf8")));if(!s.apkUrl)throw new o("COMMAND_FAILED","Android snapshot helper manifest does not include apkUrl",{manifestUrl:e.manifestUrl});let l=e.cacheDir??i.join(r.tmpdir(),`agent-device-android-snapshot-helper-${s.version}`),u=!e.cacheDir;await n.mkdir(l,{recursive:!0});let d=s.assetName??`agent-device-android-snapshot-helper-${s.version}.apk`,c=i.join(l,d),f=await t(s.apkUrl);if(!f.ok)throw new o("COMMAND_FAILED","Failed to download Android snapshot helper APK",{apkUrl:s.apkUrl,status:f.status,statusText:f.statusText});await n.writeFile(c,await A(f,0x1400000,"Android snapshot helper APK"));let p={apkPath:c,manifest:s};return await h(p),{...p,cleanup:async()=>{await n.rm(u?l:c,{recursive:u,force:!0})}}}function m(e){var t,n;if(!e||"object"!=typeof e||Array.isArray(e))throw new o("INVALID_ARGS","Android snapshot helper manifest must be an object.");return{name:x(e.name,"name",s),version:N(e.version,"version"),releaseTag:M(e.releaseTag),assetName:M(e.assetName),apkUrl:(t=e.apkUrl,n="apkUrl",null===t?null:N(t,n)),sha256:function(e){let t=N(e,"sha256").trim().toLowerCase();if(64!==t.length||!function(e){for(let t of e){let e=t.charCodeAt(0),n=e>=48&&e<=57,r=e>=97&&e<=102;if(!n&&!r)return!1}return!0}(t))throw new o("INVALID_ARGS","Android snapshot helper manifest sha256 must be a 64-character hex string.");return t}(e.sha256),checksumName:M(e.checksumName),packageName:N(e.packageName,"packageName"),versionCode:v(e.versionCode,"versionCode"),instrumentationRunner:N(e.instrumentationRunner,"instrumentationRunner"),minSdk:v(e.minSdk,"minSdk"),targetSdk:void 0===e.targetSdk?void 0:v(e.targetSdk,"targetSdk"),outputFormat:x(e.outputFormat,"outputFormat",c),statusProtocol:x(e.statusProtocol,"statusProtocol",d),installArgs:w(e.installArgs)}}async function A(e,t,n){let r=e.headers.get("content-length");if(null!==r){let e=Number(r);if(Number.isFinite(e)&&e>t)throw new o("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:e,maxBytes:t})}if(!e.body){let r=Buffer.from(await e.arrayBuffer());if(r.length>t)throw new o("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:r.length,maxBytes:t});return r}let i=e.body.getReader(),a=[],s=0;try{for(;;){let{done:e,value:r}=await i.read();if(e)break;if((s+=r.byteLength)>t)throw new o("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:s,maxBytes:t});a.push(Buffer.from(r))}}finally{i.releaseLock()}return Buffer.concat(a,s)}function w(e){let t=function(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new o("INVALID_ARGS",`Android snapshot helper manifest ${t} must be a string array.`);return e}(e,"installArgs");if("install"!==t[0])throw new o("INVALID_ARGS",'Android snapshot helper manifest installArgs must start with "install".');if(t.some(e=>e.includes("\0")))throw new o("INVALID_ARGS","Android snapshot helper manifest installArgs must not contain null bytes.");let n=t.slice(1).find(e=>void 0===b(e));if(n)throw new o("INVALID_ARGS",`Android snapshot helper manifest installArgs contains unsupported install flag "${n}".`);return t}async function g(n){return await new Promise((r,i)=>{let o=e.createHash("sha256"),a=t.createReadStream(n);a.on("error",i),a.on("data",e=>o.update(e)),a.on("end",()=>r(o.digest("hex")))})}function N(e,t){if("string"!=typeof e||0===e.trim().length)throw new o("INVALID_ARGS",`Android snapshot helper manifest ${t} is required.`);return e}function M(e){return"string"==typeof e&&e.trim().length>0?e:void 0}function v(e,t){if("number"!=typeof e||!Number.isInteger(e))throw new o("INVALID_ARGS",`Android snapshot helper manifest ${t} must be an integer.`);return e}function x(e,t,n){if(e!==n)throw new o("INVALID_ARGS",`Android snapshot helper manifest ${t} must be "${n}".`);return n}function b(e){if(Object.hasOwn(f,e))return f[e]}function I(e){let t=`${e??""}`.toLowerCase();return t.includes("scroll")||t.includes("recyclerview")||t.includes("listview")||t.includes("gridview")||t.includes("collectionview")||"table"===t}function D(e){return!!I(e.type)||`${e.role??""} ${e.subrole??""}`.toLowerCase().includes("scroll")}function*S(e){let t=/<node\b[^>]*>/g,n=t.exec(e);for(;n;)yield C(n[0]),n=t.exec(e)}function C(e){let t,n,r=(t=function(e){let t=new Map,n=e.indexOf(" "),r=e.lastIndexOf(">");if(n<0||r<=n)return t;let i=n;for(;i<r&&!((i=_(e,i,r))>=r);){var o;let n=e[i];if("/"===n||">"===n)break;let a=i;for(;i<r&&!("="===(o=e[i]??"")||"/"===o||">"===o||L(o));)i+=1;let s=e.slice(a,i);if(i=_(e,i,r),!s||"="!==e[i])break;i=_(e,i+1,r);let l=e[i];if('"'!==l&&"'"!==l)break;let u=i+=1;for(;i<r&&e[i]!==l;)i+=1;if(i>=r)break;t.set(s,function(e){let t="",n=0;for(;n<e.length;){let r=e.indexOf("&",n);if(r<0){t+=e.slice(n);break}t+=e.slice(n,r);let i=e.indexOf(";",r+1);if(i<0){t+=e.slice(r);break}t+=function(e){switch(e){case"amp":return"&";case"lt":return"<";case"gt":return">";case"quot":return'"';case"apos":return"'";default:return function(e){if(!e.startsWith("#"))return;let t=e[1]?.toLowerCase()==="x"?16:10,n=16===t?e.slice(2):e.slice(1);if(!n||!function(e,t){for(let n of e){let e=n.charCodeAt(0),r=e>=48&&e<=57;if(10===t){if(!r)return!1;continue}let i=e>=65&&e<=70,o=e>=97&&e<=102;if(!r&&!i&&!o)return!1}return!0}(n,t))return;let r=Number.parseInt(n,t);if(Number.isFinite(r))try{return String.fromCodePoint(r)}catch{return}}(e)}}(e.slice(r+1,i))??e.slice(r,i+1),n=i+1}return t}(e.slice(u,i))),i+=1}return t}(e),n=e=>{let n=T(t,e);if(null!==n)return"true"===n},{text:T(t,"text"),desc:T(t,"content-desc"),resourceId:T(t,"resource-id"),packageName:T(t,"package"),className:T(t,"class"),bounds:T(t,"bounds"),clickable:n("clickable"),enabled:n("enabled"),focusable:n("focusable"),focused:n("focused"),password:n("password")}),i=function(e){if(!e)return;let t=/\[(\d+),(\d+)\]\[(\d+),(\d+)\]/.exec(e);if(!t)return;let n=Number(t[1]),r=Number(t[2]);return{x:n,y:r,width:Math.max(0,Number(t[3])-n),height:Math.max(0,Number(t[4])-r)}}(r.bounds);return{...r,...i?{rect:i}:{}}}function k(e,t,n){let{sourceNodes:r,...i}=y(O(e),t,n);return i}function y(e,t,n){let r={nodes:[],sourceNodes:[],maxNodes:t,maxDepth:n.depth??1/0,options:n,analysis:function(e){let t=0,n=0,r=[...e.children];for(;r.length>0;){let e=r.pop();t+=1,n=Math.max(n,e.depth),r.push(...e.children)}return{rawNodeCount:t,maxDepth:n}}(e),interactiveDescendantMemo:new Map,truncated:!1},i=n.scope?function(e,t){let n=t.toLowerCase(),r=[...e.children],i=0;for(;i<r.length;){let e=r[i++],t=e.label?.toLowerCase()??"",o=e.value?.toLowerCase()??"",a=e.identifier?.toLowerCase()??"";if(t.includes(n)||o.includes(n)||a.includes(n))return e;r.push(...e.children)}return null}(e,n.scope):null;for(let t of i?[i]:e.children)if(function e(t,n,r,i,o=!1,a=!1){if(t.nodes.length>=t.maxNodes){t.truncated=!0;return}if(r>t.maxDepth)return;let s=t.options.raw||function(e,t,n,r,i){var o,a,s;let l=function(e){let t=E(e.type),n=!!(e.label&&e.label.trim().length>0),r=!!(e.identifier&&e.identifier.trim().length>0);return{type:t,hasMeaningfulText:n&&!F(e.label??""),hasMeaningfulId:r&&!F(e.identifier??""),isStructural:function(e){let t=e.split(".").pop()??e;return t.includes("layout")||"viewgroup"===t||"view"===t}(t),isVisual:"imageview"===t||"imagebutton"===t}}(e);return t.interactiveOnly?function(e,t,n,r,i){var o,a,s,l;return!!(e.hittable||I(t.type)&&r)||(o=t,a=n,s=r,l=i,(!!o.hasMeaningfulText||!!o.hasMeaningfulId)&&!o.isVisual&&(!o.isStructural||!!l)&&(a||s||l))}(e,l,n,r,i):t.compact?l.hasMeaningfulText||l.hasMeaningfulId||!!e.hittable:!l.isStructural&&!l.isVisual||(o=e,a=l,s=r,!!o.hittable||!!a.hasMeaningfulText||!!a.hasMeaningfulId&&!!s||s)}(n,t.options,o,function e(t,n){let r=t.interactiveDescendantMemo.get(n);if(void 0!==r)return r;for(let r of n.children)if(r.hittable||e(t,r))return t.interactiveDescendantMemo.set(n,!0),!0;return t.interactiveDescendantMemo.set(n,!1),!1}(t,n),a)?function(e,t,n,r){let i=e.nodes.length;return e.sourceNodes.push(t),e.nodes.push({index:i,type:t.type??void 0,label:t.label??void 0,value:t.value??void 0,identifier:t.identifier??void 0,rect:t.rect,enabled:t.enabled,hittable:t.hittable,depth:n,parentIndex:r,...t.hiddenContentAbove?{hiddenContentAbove:!0}:{},...t.hiddenContentBelow?{hiddenContentBelow:!0}:{}}),i}(t,n,r,i):i,l=o||!!n.hittable,u=a||function(e){if(!e)return!1;let t=E(e);return t.includes("recyclerview")||t.includes("listview")||t.includes("gridview")}(n.type);for(let i of n.children)if(e(t,i,r+1,s,l,u),t.truncated)return}(r,t,0),r.truncated)break;let o={nodes:r.nodes,sourceNodes:r.sourceNodes,analysis:r.analysis};return r.truncated?{...o,truncated:!0}:o}function _(e,t,n){for(;t<n&&L(e[t]??"");)t+=1;return t}function L(e){return" "===e||"\n"===e||"\r"===e||" "===e}function T(e,t){return e.get(t)??null}function O(e){let t={type:null,label:null,value:null,identifier:null,depth:-1,children:[]},n=[t],r=/<node\b[^>]*>|<\/node>/g,i=r.exec(e);for(;i;){let t=i[0];if(t.startsWith("</node")){n.length>1&&n.pop(),i=r.exec(e);continue}let o=C(t),a=n[n.length-1],s={type:o.className,label:o.text||o.desc,value:o.text,identifier:o.resourceId,rect:o.rect,enabled:o.enabled,hittable:o.clickable??o.focusable,depth:a.depth+1,parentIndex:void 0,children:[]};a.children.push(s),t.endsWith("/>")||n.push(s),i=r.exec(e)}return t}function E(e){return e?e.toLowerCase():""}function F(e){let t=e.trim();return!!t&&/^[\w.]+:id\/[\w.-]+$/i.test(t)}async function R(e){let t,n=e.waitForIdleTimeoutMs??500,r=e.timeoutMs??8e3,i=e.commandTimeoutMs??r+5e3,a=e.maxDepth??128,s=e.maxNodes??5e3,u=e.packageName??l,d=e.instrumentationRunner??`${u}/.SnapshotInstrumentation`,c=["shell","am","instrument","-w","-e","waitForIdleTimeoutMs",String(n),"-e","timeoutMs",String(r),"-e","maxDepth",String(a),"-e","maxNodes",String(s),d],f=await e.adb(c,{allowFailure:!0,timeoutMs:i});try{t=P(`${f.stdout}
|
|
2
|
+
${f.stderr}`)}catch(e){throw new o("COMMAND_FAILED",0===f.exitCode?"Android snapshot helper output could not be parsed":"Android snapshot helper failed before returning parseable output",{stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode},e)}if(0!==f.exitCode)throw new o("COMMAND_FAILED","Android snapshot helper failed",{stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,helper:t.metadata});return t}function P(e){var t,n;let r=function(e){var t;let n={status:[],results:[],currentStatus:null,currentResult:null};for(let t of e.split(/\r?\n/))!function(e,t){if(e.startsWith("INSTRUMENTATION_STATUS: ")){t.currentStatus??={},V(e.slice(24),t.currentStatus);return}if(e.startsWith("INSTRUMENTATION_STATUS_CODE: "))return $(t);if(e.startsWith("INSTRUMENTATION_RESULT: ")){t.currentResult??={},V(e.slice(24),t.currentResult);return}e.startsWith("INSTRUMENTATION_CODE: ")&&H(t)}(t,n);return $(t=n),H(t),{status:n.status,results:n.results}}(e),i=function(e){let t=e.find(e=>e.agentDeviceProtocol===d);if(!t)throw new o("COMMAND_FAILED","Android snapshot helper did not return a final result");if("true"!==t.ok){var n;throw new o("COMMAND_FAILED",(n=t).message&&"null"!==n.message?n.message:n.errorType||"Android snapshot helper returned an error",{errorType:t.errorType,helper:t})}return t}(r.results);return{xml:function(e,t){if(0===e.length)throw new o("COMMAND_FAILED","Android snapshot helper did not return XML chunks",{helper:t});let n=function(e){let t=e[0]?.count??e.length;if(t<1||e.length!==t||e.some(e=>e.count!==t))throw new o("COMMAND_FAILED","Android snapshot helper returned incomplete XML chunks",{expectedChunks:t,actualChunks:e.length});return t}(e),r=Buffer.concat(function(e,t){let n=[];for(let r=0;r<t;r+=1){let i=e.get(r);if(void 0===i)throw new o("COMMAND_FAILED","Android snapshot helper returned incomplete XML chunks",{missingChunkIndex:r,expectedChunks:t});n.push(Buffer.from(i,"base64"))}return n}(function(e,t){let n=new Map;for(let r of e){if(void 0===r.index||r.index<0||r.index>=t)throw new o("COMMAND_FAILED","Android snapshot helper returned invalid chunk index",{chunkIndex:r.index,expectedChunks:t});if(n.has(r.index))throw new o("COMMAND_FAILED","Android snapshot helper returned duplicate XML chunks",{chunkIndex:r.index});n.set(r.index,r.payloadBase64)}return n}(e,n),n)).toString("utf8");if(!r.includes("<hierarchy")||!r.includes("</hierarchy>"))throw new o("COMMAND_FAILED","Android snapshot helper output did not contain XML",{xml:r});return r}(r.status.filter(e=>e.agentDeviceProtocol===d&&e.outputFormat===c&&"string"==typeof e.payloadBase64).map(e=>({index:B(e.chunkIndex),count:B(e.chunkCount),payloadBase64:e.payloadBase64})),i),metadata:{helperApiVersion:(t=i).helperApiVersion,outputFormat:c,waitForIdleTimeoutMs:B(t.waitForIdleTimeoutMs),timeoutMs:B(t.timeoutMs),maxDepth:B(t.maxDepth),maxNodes:B(t.maxNodes),rootPresent:G(t.rootPresent),captureMode:"interactive-windows"===(n=t.captureMode)||"active-window"===n?n:void 0,windowCount:B(t.windowCount),nodeCount:B(t.nodeCount),truncated:G(t.truncated),elapsedMs:B(t.elapsedMs)}}}function U(e,t={outputFormat:c},n={},r=800){return{...k(e,r,n),metadata:t}}function $(e){e.currentStatus&&(e.status.push(e.currentStatus),e.currentStatus=null)}function H(e){e.currentResult&&(e.results.push(e.currentResult),e.currentResult=null)}function V(e,t){let n=e.indexOf("=");n<0||(t[e.slice(0,n)]=e.slice(n+1))}function B(e){if(void 0===e)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function G(e){return"true"===e||"false"!==e&&void 0}let K=new Map;function W(e){X(j(e.deviceKey,e.packageName,e.versionCode))}function j(e,t,n){return e?`${e}\0${t}\0${n}`:void 0}function X(e){e&&K.delete(e)}async function z(e){var t,n,r;let{adb:i,artifact:a}=e,s=e.installPolicy??"missing-or-outdated",l=a.manifest.packageName,u=a.manifest.versionCode;if("never"===s)return{packageName:l,versionCode:u,installed:!1,reason:"skipped"};let d=j(e.deviceKey,l,u),c=d?K.get(d):void 0;if(d&&"always"!==s&&void 0!==c)return{packageName:l,versionCode:u,installedVersionCode:c,installed:!1,reason:"current"};let f=await q(i,l,e.timeoutMs),p=(t=s,n=f,r=u,"never"===t?"skipped":"always"===t?"forced":void 0===n?"missing":n<r?"outdated":"current");if("current"===p){if(void 0===f)throw Error("Expected installed versionCode for current Android snapshot helper");return d&&K.set(d,f),{packageName:l,versionCode:u,installedVersionCode:f,installed:!1,reason:p}}await h(a);let m=await J(i,e.adbProvider??i,a.apkPath,function(e){let t={};for(let n of e.slice(1)){let e=b(n);if(!e)throw new o("INVALID_ARGS",`Android snapshot helper manifest installArgs contains unsupported install flag "${n}".`);t[e]=!0}return t}(w(a.manifest.installArgs)),{packageName:l,timeoutMs:e.timeoutMs});if(0!==m.exitCode)throw X(d),new o("COMMAND_FAILED","Failed to install Android snapshot helper",{packageName:l,versionCode:u,stdout:m.stdout,stderr:m.stderr,exitCode:m.exitCode});return d&&K.set(d,u),{packageName:l,versionCode:u,installedVersionCode:f,installed:!0,reason:p}}async function q(e,t,n){let r=await e(["shell","cmd","package","list","packages","--show-versioncode",t],{allowFailure:!0,timeoutMs:n});if(0===r.exitCode){var i=`${r.stdout}
|
|
3
3
|
${r.stderr}`,o=t;let e=`package:${o}`;for(let t of i.split(/\r?\n/)){if(!t.startsWith(e)||t.length>e.length&&!/\s/.test(t[e.length]??""))continue;let n=/(?:^|\s)versionCode:(\d+)(?:\s|$)/.exec(t);if(n)return Number(n[1])}return}}async function J(e,t,n,r,i){var o;let s=async()=>await a(n,{allowFailure:!0,provider:t,...r,timeoutMs:i.timeoutMs}),l=await s();if(0===l.exitCode||(o=l,!`${o.stdout}
|
|
4
|
-
${o.stderr}`.includes("INSTALL_FAILED_UPDATE_INCOMPATIBLE")))return l;let u=await e(["uninstall",i.packageName],{allowFailure:!0,timeoutMs:i.timeoutMs}),d=await s();return 0===d.exitCode?d:{...d,stderr:[d.stderr,u.stderr?`Previous uninstall stderr after INSTALL_FAILED_UPDATE_INCOMPATIBLE: ${u.stderr}`:""].filter(Boolean).join("\n")}}export{s as ANDROID_SNAPSHOT_HELPER_NAME,c as ANDROID_SNAPSHOT_HELPER_OUTPUT_FORMAT,l as ANDROID_SNAPSHOT_HELPER_PACKAGE,d as ANDROID_SNAPSHOT_HELPER_PROTOCOL,u as ANDROID_SNAPSHOT_HELPER_RUNNER,
|
|
4
|
+
${o.stderr}`.includes("INSTALL_FAILED_UPDATE_INCOMPATIBLE")))return l;let u=await e(["uninstall",i.packageName],{allowFailure:!0,timeoutMs:i.timeoutMs}),d=await s();return 0===d.exitCode?d:{...d,stderr:[d.stderr,u.stderr?`Previous uninstall stderr after INSTALL_FAILED_UPDATE_INCOMPATIBLE: ${u.stderr}`:""].filter(Boolean).join("\n")}}export{s as ANDROID_SNAPSHOT_HELPER_NAME,c as ANDROID_SNAPSHOT_HELPER_OUTPUT_FORMAT,l as ANDROID_SNAPSHOT_HELPER_PACKAGE,d as ANDROID_SNAPSHOT_HELPER_PROTOCOL,u as ANDROID_SNAPSHOT_HELPER_RUNNER,S as androidUiNodes,y as buildUiHierarchySnapshot,R as captureAndroidSnapshotWithHelper,z as ensureAndroidSnapshotHelper,W as forgetAndroidSnapshotHelperInstall,D as isScrollableNodeLike,I as isScrollableType,m as parseAndroidSnapshotHelperManifest,P as parseAndroidSnapshotHelperOutput,U as parseAndroidSnapshotHelperXml,k as parseUiHierarchy,O as parseUiHierarchyTree,p as prepareAndroidSnapshotHelperArtifactFromManifestUrl,h as verifyAndroidSnapshotHelperArtifact};
|