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,296 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import type { CommandFlags } from '../core/dispatch.ts';
|
|
5
|
-
import type { SessionAction, SessionState } from './types.ts';
|
|
6
|
-
import { inferFillText } from './action-utils.ts';
|
|
7
|
-
|
|
8
|
-
export class SessionStore {
|
|
9
|
-
private readonly sessions = new Map<string, SessionState>();
|
|
10
|
-
private readonly sessionsDir: string;
|
|
11
|
-
|
|
12
|
-
constructor(sessionsDir: string) {
|
|
13
|
-
this.sessionsDir = sessionsDir;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
get(name: string): SessionState | undefined {
|
|
17
|
-
return this.sessions.get(name);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
has(name: string): boolean {
|
|
21
|
-
return this.sessions.has(name);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
set(name: string, session: SessionState): void {
|
|
25
|
-
this.sessions.set(name, session);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
delete(name: string): boolean {
|
|
29
|
-
return this.sessions.delete(name);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
values(): IterableIterator<SessionState> {
|
|
33
|
-
return this.sessions.values();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
toArray(): SessionState[] {
|
|
37
|
-
return Array.from(this.sessions.values());
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
recordAction(
|
|
41
|
-
session: SessionState,
|
|
42
|
-
entry: {
|
|
43
|
-
command: string;
|
|
44
|
-
positionals: string[];
|
|
45
|
-
flags: CommandFlags;
|
|
46
|
-
result?: Record<string, unknown>;
|
|
47
|
-
},
|
|
48
|
-
): void {
|
|
49
|
-
if (entry.flags?.noRecord) return;
|
|
50
|
-
if (entry.flags?.saveScript) {
|
|
51
|
-
session.recordSession = true;
|
|
52
|
-
if (typeof entry.flags.saveScript === 'string') {
|
|
53
|
-
session.saveScriptPath = SessionStore.expandHome(entry.flags.saveScript);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
session.actions.push({
|
|
57
|
-
ts: Date.now(),
|
|
58
|
-
command: entry.command,
|
|
59
|
-
positionals: entry.positionals,
|
|
60
|
-
flags: sanitizeFlags(entry.flags),
|
|
61
|
-
result: entry.result,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
writeSessionLog(session: SessionState): void {
|
|
66
|
-
try {
|
|
67
|
-
if (!session.recordSession) return;
|
|
68
|
-
const scriptPath = this.resolveScriptPath(session);
|
|
69
|
-
const scriptDir = path.dirname(scriptPath);
|
|
70
|
-
if (!fs.existsSync(scriptDir)) fs.mkdirSync(scriptDir, { recursive: true });
|
|
71
|
-
const script = formatScript(session, this.buildOptimizedActions(session));
|
|
72
|
-
fs.writeFileSync(scriptPath, script);
|
|
73
|
-
} catch {
|
|
74
|
-
// ignore
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
defaultTracePath(session: SessionState): string {
|
|
79
|
-
const safeName = session.name.replace(/[^a-zA-Z0-9._-]/g, '_');
|
|
80
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
81
|
-
return path.join(this.sessionsDir, `${safeName}-${timestamp}.trace.log`);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
static expandHome(filePath: string): string {
|
|
85
|
-
if (filePath.startsWith('~/')) {
|
|
86
|
-
return path.join(os.homedir(), filePath.slice(2));
|
|
87
|
-
}
|
|
88
|
-
return path.resolve(filePath);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private resolveScriptPath(session: SessionState): string {
|
|
92
|
-
if (session.saveScriptPath) {
|
|
93
|
-
return SessionStore.expandHome(session.saveScriptPath);
|
|
94
|
-
}
|
|
95
|
-
if (!fs.existsSync(this.sessionsDir)) fs.mkdirSync(this.sessionsDir, { recursive: true });
|
|
96
|
-
const safeName = session.name.replace(/[^a-zA-Z0-9._-]/g, '_');
|
|
97
|
-
const timestamp = new Date(session.createdAt).toISOString().replace(/[:.]/g, '-');
|
|
98
|
-
return path.join(this.sessionsDir, `${safeName}-${timestamp}.ad`);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
private buildOptimizedActions(session: SessionState): SessionAction[] {
|
|
102
|
-
const optimized: SessionAction[] = [];
|
|
103
|
-
for (const action of session.actions) {
|
|
104
|
-
if (action.command === 'snapshot') {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
const selectorChain =
|
|
108
|
-
Array.isArray(action.result?.selectorChain) &&
|
|
109
|
-
action.result?.selectorChain.every((entry) => typeof entry === 'string')
|
|
110
|
-
? (action.result.selectorChain as string[])
|
|
111
|
-
: [];
|
|
112
|
-
if (selectorChain.length > 0 && (action.command === 'click' || action.command === 'fill' || action.command === 'get')) {
|
|
113
|
-
const selectorExpr = selectorChain.join(' || ');
|
|
114
|
-
if (action.command === 'click') {
|
|
115
|
-
optimized.push({
|
|
116
|
-
...action,
|
|
117
|
-
positionals: [selectorExpr],
|
|
118
|
-
});
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
if (action.command === 'fill') {
|
|
122
|
-
const text = inferFillText(action);
|
|
123
|
-
if (text.length > 0) {
|
|
124
|
-
optimized.push({
|
|
125
|
-
...action,
|
|
126
|
-
positionals: [selectorExpr, text],
|
|
127
|
-
});
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (action.command === 'get') {
|
|
132
|
-
const sub = action.positionals?.[0];
|
|
133
|
-
if (sub === 'text' || sub === 'attrs') {
|
|
134
|
-
optimized.push({
|
|
135
|
-
...action,
|
|
136
|
-
positionals: [sub, selectorExpr],
|
|
137
|
-
});
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (action.command === 'click' || action.command === 'fill' || action.command === 'get') {
|
|
143
|
-
const refLabel = action.result?.refLabel;
|
|
144
|
-
if (typeof refLabel === 'string' && refLabel.trim().length > 0) {
|
|
145
|
-
optimized.push({
|
|
146
|
-
ts: action.ts,
|
|
147
|
-
command: 'snapshot',
|
|
148
|
-
positionals: [],
|
|
149
|
-
flags: {
|
|
150
|
-
platform: session.device.platform,
|
|
151
|
-
snapshotInteractiveOnly: true,
|
|
152
|
-
snapshotCompact: true,
|
|
153
|
-
snapshotScope: refLabel.trim(),
|
|
154
|
-
},
|
|
155
|
-
result: { scope: refLabel.trim() },
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
optimized.push(action);
|
|
160
|
-
}
|
|
161
|
-
return optimized;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function sanitizeFlags(flags: CommandFlags | undefined): SessionAction['flags'] {
|
|
166
|
-
if (!flags) return {};
|
|
167
|
-
const {
|
|
168
|
-
platform,
|
|
169
|
-
device,
|
|
170
|
-
udid,
|
|
171
|
-
serial,
|
|
172
|
-
out,
|
|
173
|
-
verbose,
|
|
174
|
-
snapshotInteractiveOnly,
|
|
175
|
-
snapshotCompact,
|
|
176
|
-
snapshotDepth,
|
|
177
|
-
snapshotScope,
|
|
178
|
-
snapshotRaw,
|
|
179
|
-
snapshotBackend,
|
|
180
|
-
relaunch,
|
|
181
|
-
saveScript,
|
|
182
|
-
noRecord,
|
|
183
|
-
} = flags;
|
|
184
|
-
return {
|
|
185
|
-
platform,
|
|
186
|
-
device,
|
|
187
|
-
udid,
|
|
188
|
-
serial,
|
|
189
|
-
out,
|
|
190
|
-
verbose,
|
|
191
|
-
snapshotInteractiveOnly,
|
|
192
|
-
snapshotCompact,
|
|
193
|
-
snapshotDepth,
|
|
194
|
-
snapshotScope,
|
|
195
|
-
snapshotRaw,
|
|
196
|
-
snapshotBackend,
|
|
197
|
-
relaunch,
|
|
198
|
-
saveScript,
|
|
199
|
-
noRecord,
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function formatScript(session: SessionState, actions: SessionAction[]): string {
|
|
204
|
-
const lines: string[] = [];
|
|
205
|
-
const deviceLabel = session.device.name.replace(/"/g, '\\"');
|
|
206
|
-
const kind = session.device.kind ? ` kind=${session.device.kind}` : '';
|
|
207
|
-
const theme = 'unknown';
|
|
208
|
-
lines.push(`context platform=${session.device.platform} device="${deviceLabel}"${kind} theme=${theme}`);
|
|
209
|
-
for (const action of actions) {
|
|
210
|
-
if (action.flags?.noRecord) continue;
|
|
211
|
-
lines.push(formatActionLine(action));
|
|
212
|
-
}
|
|
213
|
-
return `${lines.join('\n')}\n`;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function formatActionLine(action: SessionAction): string {
|
|
217
|
-
const parts: string[] = [action.command];
|
|
218
|
-
if (action.command === 'click') {
|
|
219
|
-
const ref = action.positionals?.[0];
|
|
220
|
-
if (ref) {
|
|
221
|
-
parts.push(formatArg(ref));
|
|
222
|
-
if (ref.startsWith('@')) {
|
|
223
|
-
const refLabel = action.result?.refLabel;
|
|
224
|
-
if (typeof refLabel === 'string' && refLabel.trim().length > 0) {
|
|
225
|
-
parts.push(formatArg(refLabel));
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return parts.join(' ');
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
if (action.command === 'fill') {
|
|
232
|
-
const ref = action.positionals?.[0];
|
|
233
|
-
if (ref && ref.startsWith('@')) {
|
|
234
|
-
parts.push(formatArg(ref));
|
|
235
|
-
const refLabel = action.result?.refLabel;
|
|
236
|
-
const text = action.positionals.slice(1).join(' ');
|
|
237
|
-
if (typeof refLabel === 'string' && refLabel.trim().length > 0) {
|
|
238
|
-
parts.push(formatArg(refLabel));
|
|
239
|
-
}
|
|
240
|
-
if (text) {
|
|
241
|
-
parts.push(formatArg(text));
|
|
242
|
-
}
|
|
243
|
-
return parts.join(' ');
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
if (action.command === 'get') {
|
|
247
|
-
const sub = action.positionals?.[0];
|
|
248
|
-
const ref = action.positionals?.[1];
|
|
249
|
-
if (sub && ref) {
|
|
250
|
-
parts.push(formatArg(sub));
|
|
251
|
-
parts.push(formatArg(ref));
|
|
252
|
-
if (ref.startsWith('@')) {
|
|
253
|
-
const refLabel = action.result?.refLabel;
|
|
254
|
-
if (typeof refLabel === 'string' && refLabel.trim().length > 0) {
|
|
255
|
-
parts.push(formatArg(refLabel));
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return parts.join(' ');
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
if (action.command === 'snapshot') {
|
|
262
|
-
if (action.flags?.snapshotInteractiveOnly) parts.push('-i');
|
|
263
|
-
if (action.flags?.snapshotCompact) parts.push('-c');
|
|
264
|
-
if (typeof action.flags?.snapshotDepth === 'number') {
|
|
265
|
-
parts.push('-d', String(action.flags.snapshotDepth));
|
|
266
|
-
}
|
|
267
|
-
if (action.flags?.snapshotScope) {
|
|
268
|
-
parts.push('-s', formatArg(action.flags.snapshotScope));
|
|
269
|
-
}
|
|
270
|
-
if (action.flags?.snapshotRaw) parts.push('--raw');
|
|
271
|
-
if (action.flags?.snapshotBackend) {
|
|
272
|
-
parts.push(`--backend`, action.flags.snapshotBackend);
|
|
273
|
-
}
|
|
274
|
-
return parts.join(' ');
|
|
275
|
-
}
|
|
276
|
-
if (action.command === 'open') {
|
|
277
|
-
for (const positional of action.positionals ?? []) {
|
|
278
|
-
parts.push(formatArg(positional));
|
|
279
|
-
}
|
|
280
|
-
if (action.flags?.relaunch) {
|
|
281
|
-
parts.push('--relaunch');
|
|
282
|
-
}
|
|
283
|
-
return parts.join(' ');
|
|
284
|
-
}
|
|
285
|
-
for (const positional of action.positionals ?? []) {
|
|
286
|
-
parts.push(formatArg(positional));
|
|
287
|
-
}
|
|
288
|
-
return parts.join(' ');
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function formatArg(value: string): string {
|
|
292
|
-
const trimmed = value.trim();
|
|
293
|
-
if (trimmed.startsWith('@')) return trimmed;
|
|
294
|
-
if (/^-?\d+(\.\d+)?$/.test(trimmed)) return trimmed;
|
|
295
|
-
return JSON.stringify(trimmed);
|
|
296
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import type { RawSnapshotNode, SnapshotState } from '../utils/snapshot.ts';
|
|
2
|
-
|
|
3
|
-
export function findNodeByLabel(nodes: SnapshotState['nodes'], label: string) {
|
|
4
|
-
const query = label.toLowerCase();
|
|
5
|
-
return (
|
|
6
|
-
nodes.find((node) => {
|
|
7
|
-
const labelValue = (node.label ?? '').toLowerCase();
|
|
8
|
-
const valueValue = (node.value ?? '').toLowerCase();
|
|
9
|
-
const idValue = (node.identifier ?? '').toLowerCase();
|
|
10
|
-
return labelValue.includes(query) || valueValue.includes(query) || idValue.includes(query);
|
|
11
|
-
}) ?? null
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function resolveRefLabel(
|
|
16
|
-
node: SnapshotState['nodes'][number],
|
|
17
|
-
nodes: SnapshotState['nodes'],
|
|
18
|
-
): string | undefined {
|
|
19
|
-
const primary = [node.label, node.value, node.identifier]
|
|
20
|
-
.map((value) => (typeof value === 'string' ? value.trim() : ''))
|
|
21
|
-
.find((value) => value && value.length > 0);
|
|
22
|
-
if (primary && isMeaningfulLabel(primary)) return primary;
|
|
23
|
-
const fallback = findNearestMeaningfulLabel(node, nodes);
|
|
24
|
-
return fallback ?? (primary && isMeaningfulLabel(primary) ? primary : undefined);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function isMeaningfulLabel(value: string): boolean {
|
|
28
|
-
const trimmed = value.trim();
|
|
29
|
-
if (!trimmed) return false;
|
|
30
|
-
if (/^(true|false)$/i.test(trimmed)) return false;
|
|
31
|
-
if (/^\d+$/.test(trimmed)) return false;
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function findNearestMeaningfulLabel(
|
|
36
|
-
target: SnapshotState['nodes'][number],
|
|
37
|
-
nodes: SnapshotState['nodes'],
|
|
38
|
-
): string | undefined {
|
|
39
|
-
if (!target.rect) return undefined;
|
|
40
|
-
const targetY = target.rect.y + target.rect.height / 2;
|
|
41
|
-
let best: { label: string; distance: number } | null = null;
|
|
42
|
-
for (const node of nodes) {
|
|
43
|
-
if (!node.rect) continue;
|
|
44
|
-
const label = [node.label, node.value, node.identifier]
|
|
45
|
-
.map((value) => (typeof value === 'string' ? value.trim() : ''))
|
|
46
|
-
.find((value) => value && value.length > 0);
|
|
47
|
-
if (!label || !isMeaningfulLabel(label)) continue;
|
|
48
|
-
const nodeY = node.rect.y + node.rect.height / 2;
|
|
49
|
-
const distance = Math.abs(nodeY - targetY);
|
|
50
|
-
if (!best || distance < best.distance) {
|
|
51
|
-
best = { label, distance };
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return best?.label;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function pruneGroupNodes(nodes: RawSnapshotNode[]): RawSnapshotNode[] {
|
|
58
|
-
const skippedDepths: number[] = [];
|
|
59
|
-
const result: RawSnapshotNode[] = [];
|
|
60
|
-
for (const node of nodes) {
|
|
61
|
-
const depth = node.depth ?? 0;
|
|
62
|
-
while (skippedDepths.length > 0 && depth <= skippedDepths[skippedDepths.length - 1]) {
|
|
63
|
-
skippedDepths.pop();
|
|
64
|
-
}
|
|
65
|
-
const type = normalizeType(node.type ?? '');
|
|
66
|
-
const labelCandidate = [node.label, node.value, node.identifier]
|
|
67
|
-
.map((value) => (typeof value === 'string' ? value.trim() : ''))
|
|
68
|
-
.find((value) => value && value.length > 0);
|
|
69
|
-
const hasMeaningfulLabel = labelCandidate ? isMeaningfulLabel(labelCandidate) : false;
|
|
70
|
-
if ((type === 'group' || type === 'ioscontentgroup') && !hasMeaningfulLabel) {
|
|
71
|
-
skippedDepths.push(depth);
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
const adjustedDepth = Math.max(0, depth - skippedDepths.length);
|
|
75
|
-
result.push({ ...node, depth: adjustedDepth });
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function normalizeType(type: string): string {
|
|
81
|
-
let value = type.trim().replace(/XCUIElementType/gi, '').toLowerCase();
|
|
82
|
-
if (value.startsWith('ax')) {
|
|
83
|
-
value = value.replace(/^ax/, '');
|
|
84
|
-
}
|
|
85
|
-
const lastSeparator = Math.max(value.lastIndexOf('.'), value.lastIndexOf('/'));
|
|
86
|
-
if (lastSeparator !== -1) {
|
|
87
|
-
value = value.slice(lastSeparator + 1);
|
|
88
|
-
}
|
|
89
|
-
return value;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function isFillableType(type: string, platform: 'ios' | 'android'): boolean {
|
|
93
|
-
const normalized = normalizeType(type);
|
|
94
|
-
if (!normalized) return true;
|
|
95
|
-
if (platform === 'android') {
|
|
96
|
-
return normalized.includes('edittext') || normalized.includes('autocompletetextview');
|
|
97
|
-
}
|
|
98
|
-
return (
|
|
99
|
-
normalized.includes('textfield') ||
|
|
100
|
-
normalized.includes('securetextfield') ||
|
|
101
|
-
normalized.includes('searchfield') ||
|
|
102
|
-
normalized.includes('textview') ||
|
|
103
|
-
normalized.includes('textarea') ||
|
|
104
|
-
normalized === 'search'
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function findNearestHittableAncestor(
|
|
109
|
-
nodes: SnapshotState['nodes'],
|
|
110
|
-
node: SnapshotState['nodes'][number],
|
|
111
|
-
): SnapshotState['nodes'][number] | null {
|
|
112
|
-
if (node.hittable) return node;
|
|
113
|
-
let current = node;
|
|
114
|
-
const visited = new Set<string>();
|
|
115
|
-
while (current.parentIndex !== undefined) {
|
|
116
|
-
if (visited.has(current.ref)) break;
|
|
117
|
-
visited.add(current.ref);
|
|
118
|
-
const parent = nodes[current.parentIndex];
|
|
119
|
-
if (!parent) break;
|
|
120
|
-
if (parent.hittable) return parent;
|
|
121
|
-
current = parent;
|
|
122
|
-
}
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function extractNodeText(node: SnapshotState['nodes'][number]): string {
|
|
127
|
-
const candidates = [node.label, node.value, node.identifier]
|
|
128
|
-
.map((value) => (typeof value === 'string' ? value.trim() : ''))
|
|
129
|
-
.filter((value) => value.length > 0);
|
|
130
|
-
return candidates[0] ?? '';
|
|
131
|
-
}
|
package/src/daemon/types.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { CommandFlags } from '../core/dispatch.ts';
|
|
2
|
-
import type { DeviceInfo } from '../utils/device.ts';
|
|
3
|
-
import type { ExecResult } from '../utils/exec.ts';
|
|
4
|
-
import type { SnapshotState } from '../utils/snapshot.ts';
|
|
5
|
-
|
|
6
|
-
export type DaemonRequest = {
|
|
7
|
-
token: string;
|
|
8
|
-
session: string;
|
|
9
|
-
command: string;
|
|
10
|
-
positionals: string[];
|
|
11
|
-
flags?: CommandFlags;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type DaemonResponse =
|
|
15
|
-
| { ok: true; data?: Record<string, unknown> }
|
|
16
|
-
| { ok: false; error: { code: string; message: string; details?: Record<string, unknown> } };
|
|
17
|
-
|
|
18
|
-
export type SessionState = {
|
|
19
|
-
name: string;
|
|
20
|
-
device: DeviceInfo;
|
|
21
|
-
createdAt: number;
|
|
22
|
-
appBundleId?: string;
|
|
23
|
-
appName?: string;
|
|
24
|
-
snapshot?: SnapshotState;
|
|
25
|
-
trace?: {
|
|
26
|
-
outPath: string;
|
|
27
|
-
startedAt: number;
|
|
28
|
-
};
|
|
29
|
-
recordSession?: boolean;
|
|
30
|
-
saveScriptPath?: string;
|
|
31
|
-
actions: SessionAction[];
|
|
32
|
-
recording?: {
|
|
33
|
-
platform: 'ios' | 'android';
|
|
34
|
-
outPath: string;
|
|
35
|
-
remotePath?: string;
|
|
36
|
-
child: ReturnType<typeof import('node:child_process').spawn>;
|
|
37
|
-
wait: Promise<ExecResult>;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export type SessionAction = {
|
|
42
|
-
ts: number;
|
|
43
|
-
command: string;
|
|
44
|
-
positionals: string[];
|
|
45
|
-
flags: Partial<CommandFlags> & {
|
|
46
|
-
snapshotInteractiveOnly?: boolean;
|
|
47
|
-
snapshotCompact?: boolean;
|
|
48
|
-
snapshotDepth?: number;
|
|
49
|
-
snapshotScope?: string;
|
|
50
|
-
snapshotRaw?: boolean;
|
|
51
|
-
snapshotBackend?: 'ax' | 'xctest';
|
|
52
|
-
saveScript?: boolean | string;
|
|
53
|
-
noRecord?: boolean;
|
|
54
|
-
};
|
|
55
|
-
result?: Record<string, unknown>;
|
|
56
|
-
};
|