agent-device 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -16
- package/dist/src/bin.js +35 -96
- package/dist/src/daemon.js +16 -15
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +24 -0
- package/ios-runner/README.md +1 -1
- package/package.json +1 -1
- package/skills/agent-device/SKILL.md +32 -14
- package/skills/agent-device/references/permissions.md +15 -1
- package/skills/agent-device/references/session-management.md +2 -0
- package/skills/agent-device/references/snapshot-refs.md +2 -0
- package/skills/agent-device/references/video-recording.md +2 -0
- package/src/cli.ts +7 -3
- package/src/core/__tests__/capabilities.test.ts +11 -6
- package/src/core/__tests__/open-target.test.ts +16 -0
- package/src/core/capabilities.ts +26 -20
- package/src/core/dispatch.ts +110 -31
- package/src/core/open-target.ts +13 -0
- package/src/daemon/__tests__/app-state.test.ts +138 -0
- package/src/daemon/__tests__/session-store.test.ts +24 -0
- package/src/daemon/app-state.ts +37 -38
- package/src/daemon/context.ts +12 -0
- package/src/daemon/handlers/__tests__/interaction.test.ts +22 -0
- package/src/daemon/handlers/__tests__/session.test.ts +226 -5
- package/src/daemon/handlers/__tests__/snapshot-handler.test.ts +92 -0
- package/src/daemon/handlers/interaction.ts +37 -0
- package/src/daemon/handlers/record-trace.ts +1 -1
- package/src/daemon/handlers/session.ts +96 -26
- package/src/daemon/handlers/snapshot.ts +21 -3
- package/src/daemon/session-store.ts +11 -0
- package/src/daemon-client.ts +14 -6
- package/src/daemon.ts +1 -1
- package/src/platforms/android/__tests__/index.test.ts +67 -1
- package/src/platforms/android/index.ts +41 -0
- package/src/platforms/ios/__tests__/index.test.ts +24 -0
- package/src/platforms/ios/__tests__/runner-client.test.ts +113 -0
- package/src/platforms/ios/devices.ts +40 -18
- package/src/platforms/ios/index.ts +70 -5
- package/src/platforms/ios/runner-client.ts +329 -42
- package/src/utils/__tests__/args.test.ts +175 -0
- package/src/utils/args.ts +174 -212
- package/src/utils/command-schema.ts +591 -0
- package/src/utils/interactors.ts +13 -3
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
export type CliFlags = {
|
|
2
|
+
json: boolean;
|
|
3
|
+
platform?: 'ios' | 'android';
|
|
4
|
+
device?: string;
|
|
5
|
+
udid?: string;
|
|
6
|
+
serial?: string;
|
|
7
|
+
out?: string;
|
|
8
|
+
session?: string;
|
|
9
|
+
verbose?: boolean;
|
|
10
|
+
snapshotInteractiveOnly?: boolean;
|
|
11
|
+
snapshotCompact?: boolean;
|
|
12
|
+
snapshotDepth?: number;
|
|
13
|
+
snapshotScope?: string;
|
|
14
|
+
snapshotRaw?: boolean;
|
|
15
|
+
snapshotBackend?: 'ax' | 'xctest';
|
|
16
|
+
appsFilter?: 'launchable' | 'user-installed' | 'all';
|
|
17
|
+
appsMetadata?: boolean;
|
|
18
|
+
count?: number;
|
|
19
|
+
intervalMs?: number;
|
|
20
|
+
holdMs?: number;
|
|
21
|
+
jitterPx?: number;
|
|
22
|
+
pauseMs?: number;
|
|
23
|
+
pattern?: 'one-way' | 'ping-pong';
|
|
24
|
+
activity?: string;
|
|
25
|
+
saveScript?: boolean;
|
|
26
|
+
relaunch?: boolean;
|
|
27
|
+
noRecord?: boolean;
|
|
28
|
+
replayUpdate?: boolean;
|
|
29
|
+
help: boolean;
|
|
30
|
+
version: boolean;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type FlagKey = keyof CliFlags;
|
|
34
|
+
export type FlagType = 'boolean' | 'int' | 'enum' | 'string';
|
|
35
|
+
|
|
36
|
+
export type FlagDefinition = {
|
|
37
|
+
key: FlagKey;
|
|
38
|
+
names: readonly string[];
|
|
39
|
+
type: FlagType;
|
|
40
|
+
enumValues?: readonly string[];
|
|
41
|
+
min?: number;
|
|
42
|
+
max?: number;
|
|
43
|
+
setValue?: CliFlags[FlagKey];
|
|
44
|
+
usageLabel?: string;
|
|
45
|
+
usageDescription?: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type CommandSchema = {
|
|
49
|
+
description: string;
|
|
50
|
+
positionalArgs: readonly string[];
|
|
51
|
+
allowsExtraPositionals?: boolean;
|
|
52
|
+
allowedFlags: readonly FlagKey[];
|
|
53
|
+
defaults?: Partial<CliFlags>;
|
|
54
|
+
skipCapabilityCheck?: boolean;
|
|
55
|
+
usageOverride?: string;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const SNAPSHOT_FLAGS = [
|
|
59
|
+
'snapshotInteractiveOnly',
|
|
60
|
+
'snapshotCompact',
|
|
61
|
+
'snapshotDepth',
|
|
62
|
+
'snapshotScope',
|
|
63
|
+
'snapshotRaw',
|
|
64
|
+
'snapshotBackend',
|
|
65
|
+
] as const satisfies readonly FlagKey[];
|
|
66
|
+
|
|
67
|
+
const SELECTOR_SNAPSHOT_FLAGS = [
|
|
68
|
+
'snapshotDepth',
|
|
69
|
+
'snapshotScope',
|
|
70
|
+
'snapshotRaw',
|
|
71
|
+
'snapshotBackend',
|
|
72
|
+
] as const satisfies readonly FlagKey[];
|
|
73
|
+
|
|
74
|
+
const FIND_SNAPSHOT_FLAGS = ['snapshotDepth', 'snapshotRaw', 'snapshotBackend'] as const satisfies readonly FlagKey[];
|
|
75
|
+
|
|
76
|
+
export const FLAG_DEFINITIONS: readonly FlagDefinition[] = [
|
|
77
|
+
{
|
|
78
|
+
key: 'platform',
|
|
79
|
+
names: ['--platform'],
|
|
80
|
+
type: 'enum',
|
|
81
|
+
enumValues: ['ios', 'android'],
|
|
82
|
+
usageLabel: '--platform ios|android',
|
|
83
|
+
usageDescription: 'Platform to target',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
key: 'device',
|
|
87
|
+
names: ['--device'],
|
|
88
|
+
type: 'string',
|
|
89
|
+
usageLabel: '--device <name>',
|
|
90
|
+
usageDescription: 'Device name to target',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: 'udid',
|
|
94
|
+
names: ['--udid'],
|
|
95
|
+
type: 'string',
|
|
96
|
+
usageLabel: '--udid <udid>',
|
|
97
|
+
usageDescription: 'iOS device UDID',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
key: 'serial',
|
|
101
|
+
names: ['--serial'],
|
|
102
|
+
type: 'string',
|
|
103
|
+
usageLabel: '--serial <serial>',
|
|
104
|
+
usageDescription: 'Android device serial',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
key: 'activity',
|
|
108
|
+
names: ['--activity'],
|
|
109
|
+
type: 'string',
|
|
110
|
+
usageLabel: '--activity <component>',
|
|
111
|
+
usageDescription: 'Android app launch activity (package/Activity); not for URL opens',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
key: 'session',
|
|
115
|
+
names: ['--session'],
|
|
116
|
+
type: 'string',
|
|
117
|
+
usageLabel: '--session <name>',
|
|
118
|
+
usageDescription: 'Named session',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
key: 'count',
|
|
122
|
+
names: ['--count'],
|
|
123
|
+
type: 'int',
|
|
124
|
+
min: 1,
|
|
125
|
+
max: 200,
|
|
126
|
+
usageLabel: '--count <n>',
|
|
127
|
+
usageDescription: 'Repeat count for press/swipe series',
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
key: 'intervalMs',
|
|
131
|
+
names: ['--interval-ms'],
|
|
132
|
+
type: 'int',
|
|
133
|
+
min: 0,
|
|
134
|
+
max: 10_000,
|
|
135
|
+
usageLabel: '--interval-ms <ms>',
|
|
136
|
+
usageDescription: 'Delay between press iterations',
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
key: 'holdMs',
|
|
140
|
+
names: ['--hold-ms'],
|
|
141
|
+
type: 'int',
|
|
142
|
+
min: 0,
|
|
143
|
+
max: 10_000,
|
|
144
|
+
usageLabel: '--hold-ms <ms>',
|
|
145
|
+
usageDescription: 'Press hold duration for each iteration',
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
key: 'jitterPx',
|
|
149
|
+
names: ['--jitter-px'],
|
|
150
|
+
type: 'int',
|
|
151
|
+
min: 0,
|
|
152
|
+
max: 100,
|
|
153
|
+
usageLabel: '--jitter-px <n>',
|
|
154
|
+
usageDescription: 'Deterministic coordinate jitter radius for press',
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
key: 'pauseMs',
|
|
158
|
+
names: ['--pause-ms'],
|
|
159
|
+
type: 'int',
|
|
160
|
+
min: 0,
|
|
161
|
+
max: 10_000,
|
|
162
|
+
usageLabel: '--pause-ms <ms>',
|
|
163
|
+
usageDescription: 'Delay between swipe iterations',
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
key: 'pattern',
|
|
167
|
+
names: ['--pattern'],
|
|
168
|
+
type: 'enum',
|
|
169
|
+
enumValues: ['one-way', 'ping-pong'],
|
|
170
|
+
usageLabel: '--pattern one-way|ping-pong',
|
|
171
|
+
usageDescription: 'Swipe repeat pattern',
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
key: 'verbose',
|
|
175
|
+
names: ['--verbose', '-v'],
|
|
176
|
+
type: 'boolean',
|
|
177
|
+
usageLabel: '--verbose',
|
|
178
|
+
usageDescription: 'Stream daemon/runner logs',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
key: 'json',
|
|
182
|
+
names: ['--json'],
|
|
183
|
+
type: 'boolean',
|
|
184
|
+
usageLabel: '--json',
|
|
185
|
+
usageDescription: 'JSON output',
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
key: 'help',
|
|
189
|
+
names: ['--help', '-h'],
|
|
190
|
+
type: 'boolean',
|
|
191
|
+
usageLabel: '--help, -h',
|
|
192
|
+
usageDescription: 'Print help and exit',
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
key: 'version',
|
|
196
|
+
names: ['--version', '-V'],
|
|
197
|
+
type: 'boolean',
|
|
198
|
+
usageLabel: '--version, -V',
|
|
199
|
+
usageDescription: 'Print version and exit',
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
key: 'saveScript',
|
|
203
|
+
names: ['--save-script'],
|
|
204
|
+
type: 'boolean',
|
|
205
|
+
usageLabel: '--save-script',
|
|
206
|
+
usageDescription: 'Save session script (.ad) on close',
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
key: 'relaunch',
|
|
210
|
+
names: ['--relaunch'],
|
|
211
|
+
type: 'boolean',
|
|
212
|
+
usageLabel: '--relaunch',
|
|
213
|
+
usageDescription: 'open: terminate app process before launching it',
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
key: 'noRecord',
|
|
217
|
+
names: ['--no-record'],
|
|
218
|
+
type: 'boolean',
|
|
219
|
+
usageLabel: '--no-record',
|
|
220
|
+
usageDescription: 'Do not record this action',
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
key: 'replayUpdate',
|
|
224
|
+
names: ['--update', '-u'],
|
|
225
|
+
type: 'boolean',
|
|
226
|
+
usageLabel: '--update, -u',
|
|
227
|
+
usageDescription: 'Replay: update selectors and rewrite replay file in place',
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
key: 'appsFilter',
|
|
231
|
+
names: ['--user-installed'],
|
|
232
|
+
type: 'enum',
|
|
233
|
+
setValue: 'user-installed',
|
|
234
|
+
usageLabel: '--user-installed',
|
|
235
|
+
usageDescription: 'Apps: list user-installed packages (Android only)',
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
key: 'appsFilter',
|
|
239
|
+
names: ['--all'],
|
|
240
|
+
type: 'enum',
|
|
241
|
+
setValue: 'all',
|
|
242
|
+
usageLabel: '--all',
|
|
243
|
+
usageDescription: 'Apps: list all packages (Android only)',
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
key: 'appsMetadata',
|
|
247
|
+
names: ['--metadata'],
|
|
248
|
+
type: 'boolean',
|
|
249
|
+
usageLabel: '--metadata',
|
|
250
|
+
usageDescription: 'Apps: return metadata objects',
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
key: 'snapshotInteractiveOnly',
|
|
254
|
+
names: ['-i'],
|
|
255
|
+
type: 'boolean',
|
|
256
|
+
usageLabel: '-i',
|
|
257
|
+
usageDescription: 'Snapshot: interactive elements only',
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
key: 'snapshotCompact',
|
|
261
|
+
names: ['-c'],
|
|
262
|
+
type: 'boolean',
|
|
263
|
+
usageLabel: '-c',
|
|
264
|
+
usageDescription: 'Snapshot: compact output (drop empty structure)',
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
key: 'snapshotDepth',
|
|
268
|
+
names: ['--depth', '-d'],
|
|
269
|
+
type: 'int',
|
|
270
|
+
min: 0,
|
|
271
|
+
usageLabel: '--depth, -d <depth>',
|
|
272
|
+
usageDescription: 'Snapshot: limit snapshot depth',
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
key: 'snapshotScope',
|
|
276
|
+
names: ['--scope', '-s'],
|
|
277
|
+
type: 'string',
|
|
278
|
+
usageLabel: '--scope, -s <scope>',
|
|
279
|
+
usageDescription: 'Snapshot: scope snapshot to label/identifier',
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
key: 'snapshotRaw',
|
|
283
|
+
names: ['--raw'],
|
|
284
|
+
type: 'boolean',
|
|
285
|
+
usageLabel: '--raw',
|
|
286
|
+
usageDescription: 'Snapshot: raw node output',
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
key: 'snapshotBackend',
|
|
290
|
+
names: ['--backend'],
|
|
291
|
+
type: 'enum',
|
|
292
|
+
enumValues: ['ax', 'xctest'],
|
|
293
|
+
usageLabel: '--backend ax|xctest',
|
|
294
|
+
usageDescription: 'Snapshot backend (iOS): ax or xctest',
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
key: 'out',
|
|
298
|
+
names: ['--out'],
|
|
299
|
+
type: 'string',
|
|
300
|
+
usageLabel: '--out <path>',
|
|
301
|
+
usageDescription: 'Output path',
|
|
302
|
+
},
|
|
303
|
+
];
|
|
304
|
+
|
|
305
|
+
export const GLOBAL_FLAG_KEYS = new Set<FlagKey>([
|
|
306
|
+
'json',
|
|
307
|
+
'help',
|
|
308
|
+
'version',
|
|
309
|
+
'verbose',
|
|
310
|
+
'platform',
|
|
311
|
+
'device',
|
|
312
|
+
'udid',
|
|
313
|
+
'serial',
|
|
314
|
+
'session',
|
|
315
|
+
'noRecord',
|
|
316
|
+
]);
|
|
317
|
+
|
|
318
|
+
export const COMMAND_SCHEMAS: Record<string, CommandSchema> = {
|
|
319
|
+
boot: {
|
|
320
|
+
description: 'Ensure target device/simulator is booted and ready',
|
|
321
|
+
positionalArgs: [],
|
|
322
|
+
allowedFlags: [],
|
|
323
|
+
},
|
|
324
|
+
open: {
|
|
325
|
+
description: 'Boot device/simulator; optionally launch app or deep link URL',
|
|
326
|
+
positionalArgs: ['appOrUrl?'],
|
|
327
|
+
allowedFlags: ['activity', 'saveScript', 'relaunch'],
|
|
328
|
+
},
|
|
329
|
+
close: {
|
|
330
|
+
description: 'Close app or just end session',
|
|
331
|
+
positionalArgs: ['app?'],
|
|
332
|
+
allowedFlags: ['saveScript'],
|
|
333
|
+
},
|
|
334
|
+
reinstall: {
|
|
335
|
+
description: 'Uninstall + install app from binary path',
|
|
336
|
+
positionalArgs: ['app', 'path'],
|
|
337
|
+
allowedFlags: [],
|
|
338
|
+
},
|
|
339
|
+
snapshot: {
|
|
340
|
+
description: 'Capture accessibility tree',
|
|
341
|
+
positionalArgs: [],
|
|
342
|
+
allowedFlags: [...SNAPSHOT_FLAGS],
|
|
343
|
+
},
|
|
344
|
+
devices: {
|
|
345
|
+
description: 'List available devices',
|
|
346
|
+
positionalArgs: [],
|
|
347
|
+
allowedFlags: [],
|
|
348
|
+
skipCapabilityCheck: true,
|
|
349
|
+
},
|
|
350
|
+
apps: {
|
|
351
|
+
description: 'List installed apps (Android launchable by default, iOS simulator)',
|
|
352
|
+
positionalArgs: [],
|
|
353
|
+
allowedFlags: ['appsFilter', 'appsMetadata'],
|
|
354
|
+
},
|
|
355
|
+
appstate: {
|
|
356
|
+
description: 'Show foreground app/activity',
|
|
357
|
+
positionalArgs: [],
|
|
358
|
+
allowedFlags: [],
|
|
359
|
+
skipCapabilityCheck: true,
|
|
360
|
+
},
|
|
361
|
+
back: {
|
|
362
|
+
description: 'Navigate back (where supported)',
|
|
363
|
+
positionalArgs: [],
|
|
364
|
+
allowedFlags: [],
|
|
365
|
+
},
|
|
366
|
+
home: {
|
|
367
|
+
description: 'Go to home screen (where supported)',
|
|
368
|
+
positionalArgs: [],
|
|
369
|
+
allowedFlags: [],
|
|
370
|
+
},
|
|
371
|
+
'app-switcher': {
|
|
372
|
+
description: 'Open app switcher (where supported)',
|
|
373
|
+
positionalArgs: [],
|
|
374
|
+
allowedFlags: [],
|
|
375
|
+
},
|
|
376
|
+
wait: {
|
|
377
|
+
usageOverride: 'wait <ms>|text <text>|@ref|<selector> [timeoutMs]',
|
|
378
|
+
description: 'Wait for duration, text, ref, or selector to appear',
|
|
379
|
+
positionalArgs: ['durationOrSelector', 'timeoutMs?'],
|
|
380
|
+
allowsExtraPositionals: true,
|
|
381
|
+
allowedFlags: [...SELECTOR_SNAPSHOT_FLAGS],
|
|
382
|
+
},
|
|
383
|
+
alert: {
|
|
384
|
+
usageOverride: 'alert [get|accept|dismiss|wait] [timeout]',
|
|
385
|
+
description: 'Inspect or handle alert (iOS simulator)',
|
|
386
|
+
positionalArgs: ['action?', 'timeout?'],
|
|
387
|
+
allowedFlags: [],
|
|
388
|
+
},
|
|
389
|
+
click: {
|
|
390
|
+
usageOverride: 'click <@ref|selector>',
|
|
391
|
+
description: 'Click element by snapshot ref or selector',
|
|
392
|
+
positionalArgs: ['target'],
|
|
393
|
+
allowedFlags: [...SELECTOR_SNAPSHOT_FLAGS],
|
|
394
|
+
},
|
|
395
|
+
get: {
|
|
396
|
+
usageOverride: 'get text|attrs <@ref|selector>',
|
|
397
|
+
description: 'Return element text/attributes by ref or selector',
|
|
398
|
+
positionalArgs: ['subcommand', 'target'],
|
|
399
|
+
allowedFlags: [...SELECTOR_SNAPSHOT_FLAGS],
|
|
400
|
+
},
|
|
401
|
+
replay: {
|
|
402
|
+
description: 'Replay a recorded session',
|
|
403
|
+
positionalArgs: ['path'],
|
|
404
|
+
allowedFlags: ['replayUpdate'],
|
|
405
|
+
skipCapabilityCheck: true,
|
|
406
|
+
},
|
|
407
|
+
press: {
|
|
408
|
+
description: 'Tap/press at coordinates (supports repeated gesture series)',
|
|
409
|
+
positionalArgs: ['x', 'y'],
|
|
410
|
+
allowedFlags: ['count', 'intervalMs', 'holdMs', 'jitterPx'],
|
|
411
|
+
},
|
|
412
|
+
'long-press': {
|
|
413
|
+
description: 'Long press (where supported)',
|
|
414
|
+
positionalArgs: ['x', 'y', 'durationMs?'],
|
|
415
|
+
allowedFlags: [],
|
|
416
|
+
},
|
|
417
|
+
swipe: {
|
|
418
|
+
description: 'Swipe coordinates with optional repeat pattern',
|
|
419
|
+
positionalArgs: ['x1', 'y1', 'x2', 'y2', 'durationMs?'],
|
|
420
|
+
allowedFlags: ['count', 'pauseMs', 'pattern'],
|
|
421
|
+
},
|
|
422
|
+
focus: {
|
|
423
|
+
description: 'Focus input at coordinates',
|
|
424
|
+
positionalArgs: ['x', 'y'],
|
|
425
|
+
allowedFlags: [],
|
|
426
|
+
},
|
|
427
|
+
type: {
|
|
428
|
+
description: 'Type text in focused field',
|
|
429
|
+
positionalArgs: ['text'],
|
|
430
|
+
allowsExtraPositionals: true,
|
|
431
|
+
allowedFlags: [],
|
|
432
|
+
},
|
|
433
|
+
fill: {
|
|
434
|
+
usageOverride: 'fill <x> <y> <text> | fill <@ref|selector> <text>',
|
|
435
|
+
description: 'Tap then type',
|
|
436
|
+
positionalArgs: ['targetOrX', 'yOrText', 'text?'],
|
|
437
|
+
allowsExtraPositionals: true,
|
|
438
|
+
allowedFlags: [...SELECTOR_SNAPSHOT_FLAGS],
|
|
439
|
+
},
|
|
440
|
+
scroll: {
|
|
441
|
+
description: 'Scroll in direction (0-1 amount)',
|
|
442
|
+
positionalArgs: ['direction', 'amount?'],
|
|
443
|
+
allowedFlags: [],
|
|
444
|
+
},
|
|
445
|
+
scrollintoview: {
|
|
446
|
+
description: 'Scroll until text appears',
|
|
447
|
+
positionalArgs: ['text'],
|
|
448
|
+
allowedFlags: [],
|
|
449
|
+
},
|
|
450
|
+
pinch: {
|
|
451
|
+
description: 'Pinch/zoom gesture (iOS simulator)',
|
|
452
|
+
positionalArgs: ['scale', 'x?', 'y?'],
|
|
453
|
+
allowedFlags: [],
|
|
454
|
+
},
|
|
455
|
+
screenshot: {
|
|
456
|
+
description: 'Capture screenshot',
|
|
457
|
+
positionalArgs: ['path?'],
|
|
458
|
+
allowedFlags: ['out'],
|
|
459
|
+
},
|
|
460
|
+
record: {
|
|
461
|
+
usageOverride: 'record start [path] | record stop',
|
|
462
|
+
description: 'Start/stop screen recording',
|
|
463
|
+
positionalArgs: ['start|stop', 'path?'],
|
|
464
|
+
allowedFlags: [],
|
|
465
|
+
},
|
|
466
|
+
trace: {
|
|
467
|
+
usageOverride: 'trace start [path] | trace stop [path]',
|
|
468
|
+
description: 'Start/stop trace log capture',
|
|
469
|
+
positionalArgs: ['start|stop', 'path?'],
|
|
470
|
+
allowedFlags: [],
|
|
471
|
+
skipCapabilityCheck: true,
|
|
472
|
+
},
|
|
473
|
+
find: {
|
|
474
|
+
usageOverride: 'find <locator|text> <action> [value]',
|
|
475
|
+
description: 'Find by text/label/value/role/id and run action',
|
|
476
|
+
positionalArgs: ['query', 'action', 'value?'],
|
|
477
|
+
allowsExtraPositionals: true,
|
|
478
|
+
allowedFlags: [...FIND_SNAPSHOT_FLAGS],
|
|
479
|
+
},
|
|
480
|
+
is: {
|
|
481
|
+
description: 'Assert UI state (visible|hidden|exists|editable|selected|text)',
|
|
482
|
+
positionalArgs: ['predicate', 'selector', 'value?'],
|
|
483
|
+
allowsExtraPositionals: true,
|
|
484
|
+
allowedFlags: [...SELECTOR_SNAPSHOT_FLAGS],
|
|
485
|
+
},
|
|
486
|
+
settings: {
|
|
487
|
+
description: 'Toggle OS settings (simulators)',
|
|
488
|
+
positionalArgs: ['setting', 'state'],
|
|
489
|
+
allowedFlags: [],
|
|
490
|
+
},
|
|
491
|
+
session: {
|
|
492
|
+
usageOverride: 'session list',
|
|
493
|
+
description: 'List active sessions',
|
|
494
|
+
positionalArgs: ['list?'],
|
|
495
|
+
allowedFlags: [],
|
|
496
|
+
skipCapabilityCheck: true,
|
|
497
|
+
},
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
const flagDefinitionByName = new Map<string, FlagDefinition>();
|
|
501
|
+
const flagDefinitionsByKey = new Map<FlagKey, FlagDefinition[]>();
|
|
502
|
+
for (const definition of FLAG_DEFINITIONS) {
|
|
503
|
+
for (const name of definition.names) {
|
|
504
|
+
flagDefinitionByName.set(name, definition);
|
|
505
|
+
}
|
|
506
|
+
const list = flagDefinitionsByKey.get(definition.key);
|
|
507
|
+
if (list) list.push(definition);
|
|
508
|
+
else flagDefinitionsByKey.set(definition.key, [definition]);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export function getFlagDefinition(token: string): FlagDefinition | undefined {
|
|
512
|
+
return flagDefinitionByName.get(token);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export function getCommandSchema(command: string | null): CommandSchema | undefined {
|
|
516
|
+
if (!command) return undefined;
|
|
517
|
+
return COMMAND_SCHEMAS[command];
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
export function getCliCommandNames(): string[] {
|
|
521
|
+
return Object.keys(COMMAND_SCHEMAS);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export function getSchemaCapabilityKeys(): string[] {
|
|
525
|
+
return Object.entries(COMMAND_SCHEMAS)
|
|
526
|
+
.filter(([, schema]) => !schema.skipCapabilityCheck)
|
|
527
|
+
.map(([name]) => name)
|
|
528
|
+
.sort();
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
export function isStrictFlagModeEnabled(value: string | undefined): boolean {
|
|
532
|
+
if (!value) return false;
|
|
533
|
+
const normalized = value.trim().toLowerCase();
|
|
534
|
+
return normalized === '1' || normalized === 'true' || normalized === 'yes' || normalized === 'on';
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
function formatPositionalArg(arg: string): string {
|
|
538
|
+
const optional = arg.endsWith('?');
|
|
539
|
+
const name = optional ? arg.slice(0, -1) : arg;
|
|
540
|
+
return optional ? `[${name}]` : `<${name}>`;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function buildCommandUsage(commandName: string, schema: CommandSchema): string {
|
|
544
|
+
if (schema.usageOverride) return schema.usageOverride;
|
|
545
|
+
const positionals = schema.positionalArgs.map(formatPositionalArg);
|
|
546
|
+
const flagLabels = schema.allowedFlags.flatMap((key) =>
|
|
547
|
+
(flagDefinitionsByKey.get(key) ?? []).map((definition) => definition.usageLabel ?? definition.names[0]),
|
|
548
|
+
);
|
|
549
|
+
const optionalFlags = flagLabels.map((label) => `[${label}]`);
|
|
550
|
+
return [commandName, ...positionals, ...optionalFlags].join(' ');
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function renderUsageText(): string {
|
|
554
|
+
const header = `agent-device <command> [args] [--json]
|
|
555
|
+
|
|
556
|
+
CLI to control iOS and Android devices for AI agents.
|
|
557
|
+
`;
|
|
558
|
+
|
|
559
|
+
const commands = getCliCommandNames().map((name) => {
|
|
560
|
+
const schema = COMMAND_SCHEMAS[name];
|
|
561
|
+
if (!schema) throw new Error(`Missing command schema for ${name}`);
|
|
562
|
+
return { name, schema, usage: buildCommandUsage(name, schema) };
|
|
563
|
+
});
|
|
564
|
+
const maxUsage = Math.max(...commands.map((command) => command.usage.length)) + 2;
|
|
565
|
+
const commandLines: string[] = ['Commands:'];
|
|
566
|
+
for (const command of commands) {
|
|
567
|
+
commandLines.push(` ${command.usage.padEnd(maxUsage)}${command.schema.description}`);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const helpFlags = FLAG_DEFINITIONS
|
|
571
|
+
.filter((definition) => definition.usageLabel && definition.usageDescription);
|
|
572
|
+
const maxFlagLabel = Math.max(...helpFlags.map((flag) => (flag.usageLabel ?? '').length)) + 2;
|
|
573
|
+
const flagLines: string[] = ['Flags:'];
|
|
574
|
+
for (const flag of helpFlags) {
|
|
575
|
+
flagLines.push(
|
|
576
|
+
` ${(flag.usageLabel ?? '').padEnd(maxFlagLabel)}${flag.usageDescription ?? ''}`,
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
return `${header}
|
|
581
|
+
${commandLines.join('\n')}
|
|
582
|
+
|
|
583
|
+
${flagLines.join('\n')}
|
|
584
|
+
`;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const USAGE_TEXT = renderUsageText();
|
|
588
|
+
|
|
589
|
+
export function buildUsageText(): string {
|
|
590
|
+
return USAGE_TEXT;
|
|
591
|
+
}
|
package/src/utils/interactors.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
openAndroidApp,
|
|
9
9
|
openAndroidDevice,
|
|
10
10
|
pressAndroid,
|
|
11
|
+
swipeAndroid,
|
|
11
12
|
scrollAndroid,
|
|
12
13
|
scrollIntoViewAndroid,
|
|
13
14
|
screenshotAndroid,
|
|
@@ -29,10 +30,11 @@ export type RunnerContext = {
|
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
export type Interactor = {
|
|
32
|
-
open(app: string, options?: { activity?: string }): Promise<void>;
|
|
33
|
+
open(app: string, options?: { activity?: string; appBundleId?: string }): Promise<void>;
|
|
33
34
|
openDevice(): Promise<void>;
|
|
34
35
|
close(app: string): Promise<void>;
|
|
35
36
|
tap(x: number, y: number): Promise<void>;
|
|
37
|
+
swipe(x1: number, y1: number, x2: number, y2: number, durationMs?: number): Promise<void>;
|
|
36
38
|
longPress(x: number, y: number, durationMs?: number): Promise<void>;
|
|
37
39
|
focus(x: number, y: number): Promise<void>;
|
|
38
40
|
type(text: string): Promise<void>;
|
|
@@ -50,6 +52,7 @@ export function getInteractor(device: DeviceInfo, runnerContext: RunnerContext):
|
|
|
50
52
|
openDevice: () => openAndroidDevice(device),
|
|
51
53
|
close: (app) => closeAndroidApp(device, app),
|
|
52
54
|
tap: (x, y) => pressAndroid(device, x, y),
|
|
55
|
+
swipe: (x1, y1, x2, y2, durationMs) => swipeAndroid(device, x1, y1, x2, y2, durationMs),
|
|
53
56
|
longPress: (x, y, durationMs) => longPressAndroid(device, x, y, durationMs),
|
|
54
57
|
focus: (x, y) => focusAndroid(device, x, y),
|
|
55
58
|
type: (text) => typeAndroid(device, text),
|
|
@@ -60,7 +63,7 @@ export function getInteractor(device: DeviceInfo, runnerContext: RunnerContext):
|
|
|
60
63
|
};
|
|
61
64
|
case 'ios':
|
|
62
65
|
return {
|
|
63
|
-
open: (app) => openIosApp(device, app),
|
|
66
|
+
open: (app, options) => openIosApp(device, app, { appBundleId: options?.appBundleId }),
|
|
64
67
|
openDevice: () => openIosDevice(device),
|
|
65
68
|
close: (app) => closeIosApp(device, app),
|
|
66
69
|
screenshot: (outPath) => screenshotIos(device, outPath),
|
|
@@ -71,7 +74,7 @@ export function getInteractor(device: DeviceInfo, runnerContext: RunnerContext):
|
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
type IoRunnerOverrides = Pick<Interactor, 'tap' | 'longPress' | 'focus' | 'type' | 'fill' | 'scroll' | 'scrollIntoView'>;
|
|
77
|
+
type IoRunnerOverrides = Pick<Interactor, 'tap' | 'swipe' | 'longPress' | 'focus' | 'type' | 'fill' | 'scroll' | 'scrollIntoView'>;
|
|
75
78
|
|
|
76
79
|
function iosRunnerOverrides(device: DeviceInfo, ctx: RunnerContext): IoRunnerOverrides {
|
|
77
80
|
const runnerOpts = { verbose: ctx.verbose, logPath: ctx.logPath, traceLogPath: ctx.traceLogPath };
|
|
@@ -84,6 +87,13 @@ function iosRunnerOverrides(device: DeviceInfo, ctx: RunnerContext): IoRunnerOve
|
|
|
84
87
|
runnerOpts,
|
|
85
88
|
);
|
|
86
89
|
},
|
|
90
|
+
swipe: async (x1, y1, x2, y2, durationMs) => {
|
|
91
|
+
await runIosRunnerCommand(
|
|
92
|
+
device,
|
|
93
|
+
{ command: 'drag', x: x1, y: y1, x2, y2, durationMs, appBundleId: ctx.appBundleId },
|
|
94
|
+
runnerOpts,
|
|
95
|
+
);
|
|
96
|
+
},
|
|
87
97
|
longPress: async (x, y, durationMs) => {
|
|
88
98
|
await runIosRunnerCommand(
|
|
89
99
|
device,
|