agent-device 0.4.2 → 0.5.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 +2 -9
- package/dist/src/797.js +1 -1
- package/dist/src/bin.js +5 -5
- package/dist/src/daemon.js +16 -20
- package/package.json +7 -9
- package/skills/agent-device/SKILL.md +3 -6
- package/skills/agent-device/references/permissions.md +3 -15
- package/skills/agent-device/references/snapshot-refs.md +1 -4
- package/dist/bin/axsnapshot +0 -0
- package/ios-runner/AXSnapshot/Package.swift +0 -18
- package/ios-runner/AXSnapshot/Sources/AXSnapshot/main.swift +0 -444
- package/src/__tests__/cli-close.test.ts +0 -155
- package/src/__tests__/cli-help.test.ts +0 -102
- package/src/bin.ts +0 -3
- package/src/cli.ts +0 -305
- package/src/core/__tests__/capabilities.test.ts +0 -75
- package/src/core/__tests__/dispatch-open.test.ts +0 -25
- package/src/core/__tests__/open-target.test.ts +0 -55
- package/src/core/capabilities.ts +0 -57
- package/src/core/dispatch.ts +0 -382
- package/src/core/open-target.ts +0 -27
- package/src/daemon/__tests__/device-ready.test.ts +0 -52
- package/src/daemon/__tests__/is-predicates.test.ts +0 -68
- package/src/daemon/__tests__/selectors.test.ts +0 -261
- package/src/daemon/__tests__/session-routing.test.ts +0 -108
- package/src/daemon/__tests__/session-selector.test.ts +0 -64
- package/src/daemon/__tests__/session-store.test.ts +0 -142
- package/src/daemon/__tests__/snapshot-processing.test.ts +0 -47
- package/src/daemon/action-utils.ts +0 -29
- package/src/daemon/context.ts +0 -48
- package/src/daemon/device-ready.ts +0 -155
- package/src/daemon/handlers/__tests__/find.test.ts +0 -99
- package/src/daemon/handlers/__tests__/interaction.test.ts +0 -22
- package/src/daemon/handlers/__tests__/replay-heal.test.ts +0 -509
- package/src/daemon/handlers/__tests__/session-reinstall.test.ts +0 -219
- package/src/daemon/handlers/__tests__/session.test.ts +0 -820
- package/src/daemon/handlers/__tests__/snapshot-handler.test.ts +0 -92
- package/src/daemon/handlers/__tests__/snapshot.test.ts +0 -128
- package/src/daemon/handlers/find.ts +0 -324
- package/src/daemon/handlers/interaction.ts +0 -550
- package/src/daemon/handlers/parse-utils.ts +0 -8
- package/src/daemon/handlers/record-trace.ts +0 -154
- package/src/daemon/handlers/session.ts +0 -1137
- package/src/daemon/handlers/snapshot.ts +0 -439
- package/src/daemon/is-predicates.ts +0 -46
- package/src/daemon/selectors.ts +0 -540
- package/src/daemon/session-routing.ts +0 -22
- package/src/daemon/session-selector.ts +0 -39
- package/src/daemon/session-store.ts +0 -296
- package/src/daemon/snapshot-processing.ts +0 -131
- package/src/daemon/types.ts +0 -56
- package/src/daemon-client.ts +0 -272
- package/src/daemon.ts +0 -295
- package/src/platforms/__tests__/boot-diagnostics.test.ts +0 -59
- package/src/platforms/android/__tests__/index.test.ts +0 -274
- package/src/platforms/android/devices.ts +0 -196
- package/src/platforms/android/index.ts +0 -784
- package/src/platforms/android/ui-hierarchy.ts +0 -312
- package/src/platforms/boot-diagnostics.ts +0 -128
- package/src/platforms/ios/__tests__/index.test.ts +0 -312
- package/src/platforms/ios/__tests__/runner-client.test.ts +0 -155
- package/src/platforms/ios/apps.ts +0 -358
- package/src/platforms/ios/ax-snapshot.ts +0 -207
- package/src/platforms/ios/config.ts +0 -28
- package/src/platforms/ios/devicectl.ts +0 -134
- package/src/platforms/ios/devices.ts +0 -100
- package/src/platforms/ios/index.ts +0 -20
- package/src/platforms/ios/runner-client.ts +0 -994
- package/src/platforms/ios/simulator.ts +0 -164
- package/src/utils/__tests__/args.test.ts +0 -239
- package/src/utils/__tests__/daemon-client.test.ts +0 -95
- package/src/utils/__tests__/exec.test.ts +0 -16
- package/src/utils/__tests__/finders.test.ts +0 -34
- package/src/utils/__tests__/keyed-lock.test.ts +0 -55
- package/src/utils/__tests__/process-identity.test.ts +0 -33
- package/src/utils/__tests__/retry.test.ts +0 -44
- package/src/utils/args.ts +0 -239
- package/src/utils/command-schema.ts +0 -622
- package/src/utils/device.ts +0 -84
- package/src/utils/errors.ts +0 -35
- package/src/utils/exec.ts +0 -339
- package/src/utils/finders.ts +0 -101
- package/src/utils/interactive.ts +0 -4
- package/src/utils/interactors.ts +0 -173
- package/src/utils/keyed-lock.ts +0 -14
- package/src/utils/output.ts +0 -204
- package/src/utils/process-identity.ts +0 -100
- package/src/utils/retry.ts +0 -180
- package/src/utils/snapshot.ts +0 -64
- package/src/utils/timeouts.ts +0 -9
- package/src/utils/version.ts +0 -26
|
@@ -1,550 +0,0 @@
|
|
|
1
|
-
import { dispatchCommand, type CommandFlags } from '../../core/dispatch.ts';
|
|
2
|
-
import { isCommandSupportedOnDevice } from '../../core/capabilities.ts';
|
|
3
|
-
import { attachRefs, centerOfRect, findNodeByRef, normalizeRef, type RawSnapshotNode } from '../../utils/snapshot.ts';
|
|
4
|
-
import type { DaemonCommandContext } from '../context.ts';
|
|
5
|
-
import type { DaemonRequest, DaemonResponse, SessionState } from '../types.ts';
|
|
6
|
-
import { SessionStore } from '../session-store.ts';
|
|
7
|
-
import { evaluateIsPredicate, isSupportedPredicate } from '../is-predicates.ts';
|
|
8
|
-
import { extractNodeText, findNodeByLabel, isFillableType, pruneGroupNodes, resolveRefLabel } from '../snapshot-processing.ts';
|
|
9
|
-
import {
|
|
10
|
-
buildSelectorChainForNode,
|
|
11
|
-
findSelectorChainMatch,
|
|
12
|
-
formatSelectorFailure,
|
|
13
|
-
parseSelectorChain,
|
|
14
|
-
resolveSelectorChain,
|
|
15
|
-
splitIsSelectorArgs,
|
|
16
|
-
splitSelectorFromArgs,
|
|
17
|
-
} from '../selectors.ts';
|
|
18
|
-
|
|
19
|
-
type ContextFromFlags = (
|
|
20
|
-
flags: CommandFlags | undefined,
|
|
21
|
-
appBundleId?: string,
|
|
22
|
-
traceLogPath?: string,
|
|
23
|
-
) => DaemonCommandContext;
|
|
24
|
-
|
|
25
|
-
export async function handleInteractionCommands(params: {
|
|
26
|
-
req: DaemonRequest;
|
|
27
|
-
sessionName: string;
|
|
28
|
-
sessionStore: SessionStore;
|
|
29
|
-
contextFromFlags: ContextFromFlags;
|
|
30
|
-
}): Promise<DaemonResponse | null> {
|
|
31
|
-
const { req, sessionName, sessionStore, contextFromFlags } = params;
|
|
32
|
-
const command = req.command;
|
|
33
|
-
|
|
34
|
-
if (command === 'click') {
|
|
35
|
-
const session = sessionStore.get(sessionName);
|
|
36
|
-
if (!session) {
|
|
37
|
-
return {
|
|
38
|
-
ok: false,
|
|
39
|
-
error: { code: 'SESSION_NOT_FOUND', message: 'No active session. Run open first.' },
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
const refInput = req.positionals?.[0] ?? '';
|
|
43
|
-
if (refInput.startsWith('@')) {
|
|
44
|
-
const invalidRefFlagsResponse = refSnapshotFlagGuardResponse('click', req.flags);
|
|
45
|
-
if (invalidRefFlagsResponse) return invalidRefFlagsResponse;
|
|
46
|
-
if (!session.snapshot) {
|
|
47
|
-
return { ok: false, error: { code: 'INVALID_ARGS', message: 'No snapshot in session. Run snapshot first.' } };
|
|
48
|
-
}
|
|
49
|
-
const ref = normalizeRef(refInput);
|
|
50
|
-
if (!ref) {
|
|
51
|
-
return { ok: false, error: { code: 'INVALID_ARGS', message: 'click requires a ref like @e2' } };
|
|
52
|
-
}
|
|
53
|
-
let node = findNodeByRef(session.snapshot.nodes, ref);
|
|
54
|
-
if (!node?.rect && req.positionals.length > 1) {
|
|
55
|
-
const fallbackLabel = req.positionals.slice(1).join(' ').trim();
|
|
56
|
-
if (fallbackLabel.length > 0) {
|
|
57
|
-
node = findNodeByLabel(session.snapshot.nodes, fallbackLabel);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (!node?.rect) {
|
|
61
|
-
return {
|
|
62
|
-
ok: false,
|
|
63
|
-
error: { code: 'COMMAND_FAILED', message: `Ref ${refInput} not found or has no bounds` },
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
const refLabel = resolveRefLabel(node, session.snapshot.nodes);
|
|
67
|
-
const selectorChain = buildSelectorChainForNode(node, session.device.platform, { action: 'click' });
|
|
68
|
-
const { x, y } = centerOfRect(node.rect);
|
|
69
|
-
await dispatchCommand(session.device, 'press', [String(x), String(y)], req.flags?.out, {
|
|
70
|
-
...contextFromFlags(req.flags, session.appBundleId, session.trace?.outPath),
|
|
71
|
-
});
|
|
72
|
-
sessionStore.recordAction(session, {
|
|
73
|
-
command,
|
|
74
|
-
positionals: req.positionals ?? [],
|
|
75
|
-
flags: req.flags ?? {},
|
|
76
|
-
result: { ref, x, y, refLabel, selectorChain },
|
|
77
|
-
});
|
|
78
|
-
return { ok: true, data: { ref, x, y } };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const selectorExpression = (req.positionals ?? []).join(' ').trim();
|
|
82
|
-
if (!selectorExpression) {
|
|
83
|
-
return {
|
|
84
|
-
ok: false,
|
|
85
|
-
error: { code: 'INVALID_ARGS', message: 'click requires @ref or selector expression' },
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
const chain = parseSelectorChain(selectorExpression);
|
|
89
|
-
const snapshot = await captureSnapshotForSession(session, req.flags, sessionStore, contextFromFlags, {
|
|
90
|
-
interactiveOnly: true,
|
|
91
|
-
});
|
|
92
|
-
const resolved = resolveSelectorChain(snapshot.nodes, chain, {
|
|
93
|
-
platform: session.device.platform,
|
|
94
|
-
requireRect: true,
|
|
95
|
-
requireUnique: true,
|
|
96
|
-
disambiguateAmbiguous: true,
|
|
97
|
-
});
|
|
98
|
-
if (!resolved || !resolved.node.rect) {
|
|
99
|
-
return {
|
|
100
|
-
ok: false,
|
|
101
|
-
error: {
|
|
102
|
-
code: 'COMMAND_FAILED',
|
|
103
|
-
message: formatSelectorFailure(chain, resolved?.diagnostics ?? [], { unique: true }),
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
const { x, y } = centerOfRect(resolved.node.rect);
|
|
108
|
-
await dispatchCommand(session.device, 'press', [String(x), String(y)], req.flags?.out, {
|
|
109
|
-
...contextFromFlags(req.flags, session.appBundleId, session.trace?.outPath),
|
|
110
|
-
});
|
|
111
|
-
const selectorChain = buildSelectorChainForNode(resolved.node, session.device.platform, { action: 'click' });
|
|
112
|
-
const refLabel = resolveRefLabel(resolved.node, snapshot.nodes);
|
|
113
|
-
sessionStore.recordAction(session, {
|
|
114
|
-
command,
|
|
115
|
-
positionals: req.positionals ?? [],
|
|
116
|
-
flags: req.flags ?? {},
|
|
117
|
-
result: {
|
|
118
|
-
x,
|
|
119
|
-
y,
|
|
120
|
-
selector: resolved.selector.raw,
|
|
121
|
-
selectorChain,
|
|
122
|
-
refLabel,
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
return { ok: true, data: { selector: resolved.selector.raw, x, y } };
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (command === 'fill') {
|
|
129
|
-
const session = sessionStore.get(sessionName);
|
|
130
|
-
if (req.positionals?.[0]?.startsWith('@')) {
|
|
131
|
-
const invalidRefFlagsResponse = refSnapshotFlagGuardResponse('fill', req.flags);
|
|
132
|
-
if (invalidRefFlagsResponse) return invalidRefFlagsResponse;
|
|
133
|
-
if (!session?.snapshot) {
|
|
134
|
-
return { ok: false, error: { code: 'INVALID_ARGS', message: 'No snapshot in session. Run snapshot first.' } };
|
|
135
|
-
}
|
|
136
|
-
const ref = normalizeRef(req.positionals[0]);
|
|
137
|
-
if (!ref) {
|
|
138
|
-
return { ok: false, error: { code: 'INVALID_ARGS', message: 'fill requires a ref like @e2' } };
|
|
139
|
-
}
|
|
140
|
-
const labelCandidate = req.positionals.length >= 3 ? req.positionals[1] : '';
|
|
141
|
-
const text = req.positionals.length >= 3 ? req.positionals.slice(2).join(' ') : req.positionals.slice(1).join(' ');
|
|
142
|
-
if (!text) {
|
|
143
|
-
return { ok: false, error: { code: 'INVALID_ARGS', message: 'fill requires text after ref' } };
|
|
144
|
-
}
|
|
145
|
-
let node = findNodeByRef(session.snapshot.nodes, ref);
|
|
146
|
-
if (!node?.rect && labelCandidate) {
|
|
147
|
-
node = findNodeByLabel(session.snapshot.nodes, labelCandidate);
|
|
148
|
-
}
|
|
149
|
-
if (!node?.rect) {
|
|
150
|
-
return { ok: false, error: { code: 'COMMAND_FAILED', message: `Ref ${req.positionals[0]} not found or has no bounds` } };
|
|
151
|
-
}
|
|
152
|
-
const nodeType = node.type ?? '';
|
|
153
|
-
const fillWarning =
|
|
154
|
-
nodeType && !isFillableType(nodeType, session.device.platform)
|
|
155
|
-
? `fill target ${req.positionals[0]} resolved to "${nodeType}", attempting fill anyway.`
|
|
156
|
-
: undefined;
|
|
157
|
-
const refLabel = resolveRefLabel(node, session.snapshot.nodes);
|
|
158
|
-
const selectorChain = buildSelectorChainForNode(node, session.device.platform, { action: 'fill' });
|
|
159
|
-
const { x, y } = centerOfRect(node.rect);
|
|
160
|
-
const data = await dispatchCommand(
|
|
161
|
-
session.device,
|
|
162
|
-
'fill',
|
|
163
|
-
[String(x), String(y), text],
|
|
164
|
-
req.flags?.out,
|
|
165
|
-
{
|
|
166
|
-
...contextFromFlags(req.flags, session.appBundleId, session.trace?.outPath),
|
|
167
|
-
},
|
|
168
|
-
);
|
|
169
|
-
const resultPayload: Record<string, unknown> = {
|
|
170
|
-
...(data ?? { ref, x, y }),
|
|
171
|
-
};
|
|
172
|
-
if (fillWarning) {
|
|
173
|
-
resultPayload.warning = fillWarning;
|
|
174
|
-
}
|
|
175
|
-
sessionStore.recordAction(session, {
|
|
176
|
-
command,
|
|
177
|
-
positionals: req.positionals ?? [],
|
|
178
|
-
flags: req.flags ?? {},
|
|
179
|
-
result: { ...resultPayload, refLabel, selectorChain },
|
|
180
|
-
});
|
|
181
|
-
return { ok: true, data: resultPayload };
|
|
182
|
-
}
|
|
183
|
-
if (!session) {
|
|
184
|
-
return {
|
|
185
|
-
ok: false,
|
|
186
|
-
error: { code: 'SESSION_NOT_FOUND', message: 'No active session. Run open first.' },
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
const selectorArgs = splitSelectorFromArgs(req.positionals ?? [], { preferTrailingValue: true });
|
|
190
|
-
if (selectorArgs) {
|
|
191
|
-
if (selectorArgs.rest.length === 0) {
|
|
192
|
-
return { ok: false, error: { code: 'INVALID_ARGS', message: 'fill requires text after selector' } };
|
|
193
|
-
}
|
|
194
|
-
const text = selectorArgs.rest.join(' ').trim();
|
|
195
|
-
if (!text) {
|
|
196
|
-
return { ok: false, error: { code: 'INVALID_ARGS', message: 'fill requires text after selector' } };
|
|
197
|
-
}
|
|
198
|
-
const chain = parseSelectorChain(selectorArgs.selectorExpression);
|
|
199
|
-
const snapshot = await captureSnapshotForSession(session, req.flags, sessionStore, contextFromFlags, {
|
|
200
|
-
interactiveOnly: true,
|
|
201
|
-
});
|
|
202
|
-
const resolved = resolveSelectorChain(snapshot.nodes, chain, {
|
|
203
|
-
platform: session.device.platform,
|
|
204
|
-
requireRect: true,
|
|
205
|
-
requireUnique: true,
|
|
206
|
-
disambiguateAmbiguous: true,
|
|
207
|
-
});
|
|
208
|
-
if (!resolved || !resolved.node.rect) {
|
|
209
|
-
return {
|
|
210
|
-
ok: false,
|
|
211
|
-
error: {
|
|
212
|
-
code: 'COMMAND_FAILED',
|
|
213
|
-
message: formatSelectorFailure(chain, resolved?.diagnostics ?? [], { unique: true }),
|
|
214
|
-
},
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
const node = resolved.node;
|
|
218
|
-
const nodeType = node.type ?? '';
|
|
219
|
-
const fillWarning =
|
|
220
|
-
nodeType && !isFillableType(nodeType, session.device.platform)
|
|
221
|
-
? `fill target ${resolved.selector.raw} resolved to "${nodeType}", attempting fill anyway.`
|
|
222
|
-
: undefined;
|
|
223
|
-
const { x, y } = centerOfRect(resolved.node.rect);
|
|
224
|
-
const data = await dispatchCommand(session.device, 'fill', [String(x), String(y), text], req.flags?.out, {
|
|
225
|
-
...contextFromFlags(req.flags, session.appBundleId, session.trace?.outPath),
|
|
226
|
-
});
|
|
227
|
-
const selectorChain = buildSelectorChainForNode(node, session.device.platform, { action: 'fill' });
|
|
228
|
-
const resultPayload: Record<string, unknown> = {
|
|
229
|
-
...(data ?? { x, y, text }),
|
|
230
|
-
selector: resolved.selector.raw,
|
|
231
|
-
selectorChain,
|
|
232
|
-
refLabel: resolveRefLabel(node, snapshot.nodes),
|
|
233
|
-
};
|
|
234
|
-
if (fillWarning) {
|
|
235
|
-
resultPayload.warning = fillWarning;
|
|
236
|
-
}
|
|
237
|
-
sessionStore.recordAction(session, {
|
|
238
|
-
command,
|
|
239
|
-
positionals: req.positionals ?? [],
|
|
240
|
-
flags: req.flags ?? {},
|
|
241
|
-
result: resultPayload,
|
|
242
|
-
});
|
|
243
|
-
return { ok: true, data: resultPayload };
|
|
244
|
-
}
|
|
245
|
-
return {
|
|
246
|
-
ok: false,
|
|
247
|
-
error: { code: 'INVALID_ARGS', message: 'fill requires x y text, @ref text, or selector text' },
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (command === 'get') {
|
|
252
|
-
const sub = req.positionals?.[0];
|
|
253
|
-
if (sub !== 'text' && sub !== 'attrs') {
|
|
254
|
-
return { ok: false, error: { code: 'INVALID_ARGS', message: 'get only supports text or attrs' } };
|
|
255
|
-
}
|
|
256
|
-
const session = sessionStore.get(sessionName);
|
|
257
|
-
if (!session) {
|
|
258
|
-
return {
|
|
259
|
-
ok: false,
|
|
260
|
-
error: { code: 'SESSION_NOT_FOUND', message: 'No active session. Run open first.' },
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
const refInput = req.positionals?.[1] ?? '';
|
|
264
|
-
if (refInput.startsWith('@')) {
|
|
265
|
-
const invalidRefFlagsResponse = refSnapshotFlagGuardResponse('get', req.flags);
|
|
266
|
-
if (invalidRefFlagsResponse) return invalidRefFlagsResponse;
|
|
267
|
-
if (!session.snapshot) {
|
|
268
|
-
return { ok: false, error: { code: 'INVALID_ARGS', message: 'No snapshot in session. Run snapshot first.' } };
|
|
269
|
-
}
|
|
270
|
-
const ref = normalizeRef(refInput ?? '');
|
|
271
|
-
if (!ref) {
|
|
272
|
-
return { ok: false, error: { code: 'INVALID_ARGS', message: 'get text requires a ref like @e2' } };
|
|
273
|
-
}
|
|
274
|
-
let node = findNodeByRef(session.snapshot.nodes, ref);
|
|
275
|
-
if (!node && req.positionals.length > 2) {
|
|
276
|
-
const labelCandidate = req.positionals.slice(2).join(' ').trim();
|
|
277
|
-
if (labelCandidate.length > 0) {
|
|
278
|
-
node = findNodeByLabel(session.snapshot.nodes, labelCandidate);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
if (!node) {
|
|
282
|
-
return { ok: false, error: { code: 'COMMAND_FAILED', message: `Ref ${refInput} not found` } };
|
|
283
|
-
}
|
|
284
|
-
const selectorChain = buildSelectorChainForNode(node, session.device.platform, { action: 'get' });
|
|
285
|
-
if (sub === 'attrs') {
|
|
286
|
-
sessionStore.recordAction(session, {
|
|
287
|
-
command,
|
|
288
|
-
positionals: req.positionals ?? [],
|
|
289
|
-
flags: req.flags ?? {},
|
|
290
|
-
result: { ref, selectorChain },
|
|
291
|
-
});
|
|
292
|
-
return { ok: true, data: { ref, node } };
|
|
293
|
-
}
|
|
294
|
-
const text = extractNodeText(node);
|
|
295
|
-
sessionStore.recordAction(session, {
|
|
296
|
-
command,
|
|
297
|
-
positionals: req.positionals ?? [],
|
|
298
|
-
flags: req.flags ?? {},
|
|
299
|
-
result: { ref, text, refLabel: text || undefined, selectorChain },
|
|
300
|
-
});
|
|
301
|
-
return { ok: true, data: { ref, text, node } };
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const selectorExpression = req.positionals.slice(1).join(' ').trim();
|
|
305
|
-
if (!selectorExpression) {
|
|
306
|
-
return {
|
|
307
|
-
ok: false,
|
|
308
|
-
error: { code: 'INVALID_ARGS', message: 'get requires @ref or selector expression' },
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
const chain = parseSelectorChain(selectorExpression);
|
|
312
|
-
const snapshot = await captureSnapshotForSession(session, req.flags, sessionStore, contextFromFlags, {
|
|
313
|
-
interactiveOnly: false,
|
|
314
|
-
});
|
|
315
|
-
const resolved = resolveSelectorChain(snapshot.nodes, chain, {
|
|
316
|
-
platform: session.device.platform,
|
|
317
|
-
requireRect: false,
|
|
318
|
-
requireUnique: true,
|
|
319
|
-
disambiguateAmbiguous: sub === 'text',
|
|
320
|
-
});
|
|
321
|
-
if (!resolved) {
|
|
322
|
-
return {
|
|
323
|
-
ok: false,
|
|
324
|
-
error: {
|
|
325
|
-
code: 'COMMAND_FAILED',
|
|
326
|
-
message: formatSelectorFailure(chain, [], { unique: true }),
|
|
327
|
-
},
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
const node = resolved.node;
|
|
331
|
-
const selectorChain = buildSelectorChainForNode(node, session.device.platform, { action: 'get' });
|
|
332
|
-
if (sub === 'attrs') {
|
|
333
|
-
sessionStore.recordAction(session, {
|
|
334
|
-
command,
|
|
335
|
-
positionals: req.positionals ?? [],
|
|
336
|
-
flags: req.flags ?? {},
|
|
337
|
-
result: { selector: resolved.selector.raw, selectorChain },
|
|
338
|
-
});
|
|
339
|
-
return { ok: true, data: { selector: resolved.selector.raw, node } };
|
|
340
|
-
}
|
|
341
|
-
const text = extractNodeText(node);
|
|
342
|
-
sessionStore.recordAction(session, {
|
|
343
|
-
command,
|
|
344
|
-
positionals: req.positionals ?? [],
|
|
345
|
-
flags: req.flags ?? {},
|
|
346
|
-
result: {
|
|
347
|
-
text,
|
|
348
|
-
refLabel: text || undefined,
|
|
349
|
-
selector: resolved.selector.raw,
|
|
350
|
-
selectorChain,
|
|
351
|
-
},
|
|
352
|
-
});
|
|
353
|
-
return { ok: true, data: { selector: resolved.selector.raw, text, node } };
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
if (command === 'is') {
|
|
357
|
-
const predicate = (req.positionals?.[0] ?? '').toLowerCase();
|
|
358
|
-
if (!isSupportedPredicate(predicate)) {
|
|
359
|
-
return {
|
|
360
|
-
ok: false,
|
|
361
|
-
error: {
|
|
362
|
-
code: 'INVALID_ARGS',
|
|
363
|
-
message: 'is requires predicate: visible|hidden|exists|editable|selected|text',
|
|
364
|
-
},
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
const session = sessionStore.get(sessionName);
|
|
368
|
-
if (!session) {
|
|
369
|
-
return {
|
|
370
|
-
ok: false,
|
|
371
|
-
error: { code: 'SESSION_NOT_FOUND', message: 'No active session. Run open first.' },
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
if (!isCommandSupportedOnDevice('is', session.device)) {
|
|
375
|
-
return {
|
|
376
|
-
ok: false,
|
|
377
|
-
error: { code: 'UNSUPPORTED_OPERATION', message: 'is is not supported on this device' },
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
const { split } = splitIsSelectorArgs(req.positionals);
|
|
381
|
-
if (!split) {
|
|
382
|
-
return {
|
|
383
|
-
ok: false,
|
|
384
|
-
error: {
|
|
385
|
-
code: 'INVALID_ARGS',
|
|
386
|
-
message: 'is requires a selector expression',
|
|
387
|
-
},
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
const expectedText = split.rest.join(' ').trim();
|
|
391
|
-
if (predicate === 'text' && !expectedText) {
|
|
392
|
-
return {
|
|
393
|
-
ok: false,
|
|
394
|
-
error: {
|
|
395
|
-
code: 'INVALID_ARGS',
|
|
396
|
-
message: 'is text requires expected text value',
|
|
397
|
-
},
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
if (predicate !== 'text' && split.rest.length > 0) {
|
|
401
|
-
return {
|
|
402
|
-
ok: false,
|
|
403
|
-
error: {
|
|
404
|
-
code: 'INVALID_ARGS',
|
|
405
|
-
message: `is ${predicate} does not accept trailing values`,
|
|
406
|
-
},
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
const chain = parseSelectorChain(split.selectorExpression);
|
|
410
|
-
const snapshot = await captureSnapshotForSession(session, req.flags, sessionStore, contextFromFlags, {
|
|
411
|
-
interactiveOnly: false,
|
|
412
|
-
});
|
|
413
|
-
if (predicate === 'exists') {
|
|
414
|
-
const matched = findSelectorChainMatch(snapshot.nodes, chain, {
|
|
415
|
-
platform: session.device.platform,
|
|
416
|
-
});
|
|
417
|
-
if (!matched) {
|
|
418
|
-
return {
|
|
419
|
-
ok: false,
|
|
420
|
-
error: {
|
|
421
|
-
code: 'COMMAND_FAILED',
|
|
422
|
-
message: formatSelectorFailure(chain, [], { unique: false }),
|
|
423
|
-
},
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
sessionStore.recordAction(session, {
|
|
427
|
-
command,
|
|
428
|
-
positionals: req.positionals ?? [],
|
|
429
|
-
flags: req.flags ?? {},
|
|
430
|
-
result: {
|
|
431
|
-
predicate,
|
|
432
|
-
selector: matched.selector.raw,
|
|
433
|
-
selectorChain: chain.selectors.map((entry) => entry.raw),
|
|
434
|
-
pass: true,
|
|
435
|
-
matches: matched.matches,
|
|
436
|
-
},
|
|
437
|
-
});
|
|
438
|
-
return { ok: true, data: { predicate, pass: true, selector: matched.selector.raw, matches: matched.matches } };
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
const resolved = resolveSelectorChain(snapshot.nodes, chain, {
|
|
442
|
-
platform: session.device.platform,
|
|
443
|
-
requireUnique: true,
|
|
444
|
-
});
|
|
445
|
-
if (!resolved) {
|
|
446
|
-
return {
|
|
447
|
-
ok: false,
|
|
448
|
-
error: {
|
|
449
|
-
code: 'COMMAND_FAILED',
|
|
450
|
-
message: formatSelectorFailure(chain, [], { unique: true }),
|
|
451
|
-
},
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
const result = evaluateIsPredicate({
|
|
455
|
-
predicate,
|
|
456
|
-
node: resolved.node,
|
|
457
|
-
expectedText,
|
|
458
|
-
platform: session.device.platform,
|
|
459
|
-
});
|
|
460
|
-
if (!result.pass) {
|
|
461
|
-
return {
|
|
462
|
-
ok: false,
|
|
463
|
-
error: {
|
|
464
|
-
code: 'COMMAND_FAILED',
|
|
465
|
-
message: `is ${predicate} failed for selector ${resolved.selector.raw}: ${result.details}`,
|
|
466
|
-
},
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
sessionStore.recordAction(session, {
|
|
470
|
-
command,
|
|
471
|
-
positionals: req.positionals ?? [],
|
|
472
|
-
flags: req.flags ?? {},
|
|
473
|
-
result: {
|
|
474
|
-
predicate,
|
|
475
|
-
selector: resolved.selector.raw,
|
|
476
|
-
selectorChain: chain.selectors.map((entry) => entry.raw),
|
|
477
|
-
pass: true,
|
|
478
|
-
text: predicate === 'text' ? result.actualText : undefined,
|
|
479
|
-
},
|
|
480
|
-
});
|
|
481
|
-
return { ok: true, data: { predicate, pass: true, selector: resolved.selector.raw } };
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
return null;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
async function captureSnapshotForSession(
|
|
488
|
-
session: SessionState,
|
|
489
|
-
flags: CommandFlags | undefined,
|
|
490
|
-
sessionStore: SessionStore,
|
|
491
|
-
contextFromFlags: ContextFromFlags,
|
|
492
|
-
options: { interactiveOnly: boolean },
|
|
493
|
-
) {
|
|
494
|
-
const data = (await dispatchCommand(session.device, 'snapshot', [], flags?.out, {
|
|
495
|
-
...contextFromFlags(
|
|
496
|
-
{
|
|
497
|
-
...(flags ?? {}),
|
|
498
|
-
snapshotInteractiveOnly: options.interactiveOnly,
|
|
499
|
-
snapshotCompact: options.interactiveOnly,
|
|
500
|
-
},
|
|
501
|
-
session.appBundleId,
|
|
502
|
-
session.trace?.outPath,
|
|
503
|
-
),
|
|
504
|
-
})) as {
|
|
505
|
-
nodes?: RawSnapshotNode[];
|
|
506
|
-
truncated?: boolean;
|
|
507
|
-
backend?: 'ax' | 'xctest' | 'android';
|
|
508
|
-
};
|
|
509
|
-
const rawNodes = data?.nodes ?? [];
|
|
510
|
-
const nodes = attachRefs(flags?.snapshotRaw ? rawNodes : pruneGroupNodes(rawNodes));
|
|
511
|
-
session.snapshot = {
|
|
512
|
-
nodes,
|
|
513
|
-
truncated: data?.truncated,
|
|
514
|
-
createdAt: Date.now(),
|
|
515
|
-
backend: data?.backend,
|
|
516
|
-
};
|
|
517
|
-
sessionStore.set(session.name, session);
|
|
518
|
-
return session.snapshot;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
const REF_UNSUPPORTED_FLAG_MAP: ReadonlyArray<[keyof CommandFlags, string]> = [
|
|
522
|
-
['snapshotDepth', '--depth'],
|
|
523
|
-
['snapshotScope', '--scope'],
|
|
524
|
-
['snapshotRaw', '--raw'],
|
|
525
|
-
['snapshotBackend', '--backend'],
|
|
526
|
-
];
|
|
527
|
-
|
|
528
|
-
function refSnapshotFlagGuardResponse(
|
|
529
|
-
command: 'click' | 'fill' | 'get',
|
|
530
|
-
flags: CommandFlags | undefined,
|
|
531
|
-
): DaemonResponse | null {
|
|
532
|
-
const unsupported = unsupportedRefSnapshotFlags(flags);
|
|
533
|
-
if (unsupported.length === 0) return null;
|
|
534
|
-
return {
|
|
535
|
-
ok: false,
|
|
536
|
-
error: {
|
|
537
|
-
code: 'INVALID_ARGS',
|
|
538
|
-
message: `${command} @ref does not support ${unsupported.join(', ')}.`,
|
|
539
|
-
},
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
export function unsupportedRefSnapshotFlags(flags: CommandFlags | undefined): string[] {
|
|
544
|
-
if (!flags) return [];
|
|
545
|
-
const unsupported: string[] = [];
|
|
546
|
-
for (const [key, label] of REF_UNSUPPORTED_FLAG_MAP) {
|
|
547
|
-
if (flags[key] !== undefined) unsupported.push(label);
|
|
548
|
-
}
|
|
549
|
-
return unsupported;
|
|
550
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export const POLL_INTERVAL_MS = 300;
|
|
2
|
-
export const DEFAULT_TIMEOUT_MS = 10_000;
|
|
3
|
-
|
|
4
|
-
export function parseTimeout(value: string | undefined): number | null {
|
|
5
|
-
if (!value) return null;
|
|
6
|
-
const parsed = Number(value);
|
|
7
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
8
|
-
}
|