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
package/src/utils/args.ts
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { AppError } from './errors.ts';
|
|
2
|
-
import {
|
|
3
|
-
buildCommandUsageText,
|
|
4
|
-
buildUsageText,
|
|
5
|
-
getCommandSchema,
|
|
6
|
-
getFlagDefinition,
|
|
7
|
-
GLOBAL_FLAG_KEYS,
|
|
8
|
-
isStrictFlagModeEnabled,
|
|
9
|
-
type CliFlags,
|
|
10
|
-
type FlagDefinition,
|
|
11
|
-
type FlagKey,
|
|
12
|
-
} from './command-schema.ts';
|
|
13
|
-
|
|
14
|
-
export type ParsedArgs = {
|
|
15
|
-
command: string | null;
|
|
16
|
-
positionals: string[];
|
|
17
|
-
flags: CliFlags;
|
|
18
|
-
warnings: string[];
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
type ParseArgsOptions = {
|
|
22
|
-
strictFlags?: boolean;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
type ParsedFlagRecord = {
|
|
26
|
-
key: FlagKey;
|
|
27
|
-
token: string;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export function parseArgs(argv: string[], options?: ParseArgsOptions): ParsedArgs {
|
|
31
|
-
const strictFlags = options?.strictFlags ?? isStrictFlagModeEnabled(process.env.AGENT_DEVICE_STRICT_FLAGS);
|
|
32
|
-
const flags: CliFlags = { json: false, help: false, version: false };
|
|
33
|
-
let command: string | null = null;
|
|
34
|
-
const positionals: string[] = [];
|
|
35
|
-
const warnings: string[] = [];
|
|
36
|
-
const providedFlags: ParsedFlagRecord[] = [];
|
|
37
|
-
let parseFlags = true;
|
|
38
|
-
|
|
39
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
40
|
-
const arg = argv[i];
|
|
41
|
-
if (parseFlags && arg === '--') {
|
|
42
|
-
parseFlags = false;
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
if (!parseFlags) {
|
|
46
|
-
if (!command) command = arg;
|
|
47
|
-
else positionals.push(arg);
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
const isLongFlag = arg.startsWith('--');
|
|
51
|
-
const isShortFlag = arg.startsWith('-') && arg.length > 1;
|
|
52
|
-
if (!isLongFlag && !isShortFlag) {
|
|
53
|
-
if (!command) command = arg;
|
|
54
|
-
else positionals.push(arg);
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const [token, inlineValue] = isLongFlag ? splitLongFlag(arg) : [arg, undefined];
|
|
59
|
-
const definition = getFlagDefinition(token);
|
|
60
|
-
if (!definition) {
|
|
61
|
-
if (shouldTreatUnknownDashTokenAsPositional(command, positionals, arg)) {
|
|
62
|
-
if (!command) command = arg;
|
|
63
|
-
else positionals.push(arg);
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
throw new AppError('INVALID_ARGS', `Unknown flag: ${token}`);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const parsed = parseFlagValue(definition, token, inlineValue, argv[i + 1]);
|
|
70
|
-
if (parsed.consumeNext) i += 1;
|
|
71
|
-
(flags as Record<string, unknown>)[definition.key] = parsed.value;
|
|
72
|
-
providedFlags.push({ key: definition.key, token });
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const commandSchema = getCommandSchema(command);
|
|
76
|
-
const allowedFlagKeys = new Set<FlagKey>([
|
|
77
|
-
...GLOBAL_FLAG_KEYS,
|
|
78
|
-
...(commandSchema?.allowedFlags ?? []),
|
|
79
|
-
]);
|
|
80
|
-
const disallowed = providedFlags.filter((entry) => !allowedFlagKeys.has(entry.key));
|
|
81
|
-
if (disallowed.length > 0) {
|
|
82
|
-
const unsupported = disallowed.map((entry) => entry.token);
|
|
83
|
-
const message = formatUnsupportedFlagMessage(command, unsupported);
|
|
84
|
-
if (strictFlags) {
|
|
85
|
-
throw new AppError('INVALID_ARGS', message);
|
|
86
|
-
}
|
|
87
|
-
warnings.push(`${message} Enable AGENT_DEVICE_STRICT_FLAGS=1 to fail fast.`);
|
|
88
|
-
for (const entry of disallowed) {
|
|
89
|
-
delete (flags as Record<string, unknown>)[entry.key];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (commandSchema?.defaults) {
|
|
93
|
-
for (const [key, value] of Object.entries(commandSchema.defaults) as Array<[FlagKey, unknown]>) {
|
|
94
|
-
if ((flags as Record<string, unknown>)[key] === undefined) {
|
|
95
|
-
(flags as Record<string, unknown>)[key] = value;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return { command, positionals, flags, warnings };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function splitLongFlag(flag: string): [string, string | undefined] {
|
|
103
|
-
const equals = flag.indexOf('=');
|
|
104
|
-
if (equals === -1) return [flag, undefined];
|
|
105
|
-
return [flag.slice(0, equals), flag.slice(equals + 1)];
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function parseFlagValue(
|
|
109
|
-
definition: FlagDefinition,
|
|
110
|
-
token: string,
|
|
111
|
-
inlineValue: string | undefined,
|
|
112
|
-
nextArg: string | undefined,
|
|
113
|
-
): { value: unknown; consumeNext: boolean } {
|
|
114
|
-
if (definition.setValue !== undefined) {
|
|
115
|
-
if (inlineValue !== undefined) {
|
|
116
|
-
throw new AppError('INVALID_ARGS', `Flag ${token} does not take a value.`);
|
|
117
|
-
}
|
|
118
|
-
return { value: definition.setValue, consumeNext: false };
|
|
119
|
-
}
|
|
120
|
-
if (definition.type === 'boolean') {
|
|
121
|
-
if (inlineValue !== undefined) {
|
|
122
|
-
throw new AppError('INVALID_ARGS', `Flag ${token} does not take a value.`);
|
|
123
|
-
}
|
|
124
|
-
return { value: true, consumeNext: false };
|
|
125
|
-
}
|
|
126
|
-
if (definition.type === 'booleanOrString') {
|
|
127
|
-
if (inlineValue !== undefined) {
|
|
128
|
-
if (inlineValue.trim().length === 0) {
|
|
129
|
-
throw new AppError('INVALID_ARGS', `Flag ${token} requires a non-empty value when provided.`);
|
|
130
|
-
}
|
|
131
|
-
return { value: inlineValue, consumeNext: false };
|
|
132
|
-
}
|
|
133
|
-
if (nextArg === undefined || looksLikeFlagToken(nextArg)) {
|
|
134
|
-
return { value: true, consumeNext: false };
|
|
135
|
-
}
|
|
136
|
-
if (shouldConsumeOptionalPathValue(nextArg)) {
|
|
137
|
-
return { value: nextArg, consumeNext: true };
|
|
138
|
-
}
|
|
139
|
-
return { value: true, consumeNext: false };
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const value = inlineValue ?? nextArg;
|
|
143
|
-
if (value === undefined) {
|
|
144
|
-
throw new AppError('INVALID_ARGS', `Flag ${token} requires a value.`);
|
|
145
|
-
}
|
|
146
|
-
if (inlineValue === undefined && looksLikeFlagToken(value)) {
|
|
147
|
-
throw new AppError('INVALID_ARGS', `Flag ${token} requires a value.`);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (definition.type === 'string') {
|
|
151
|
-
return { value, consumeNext: inlineValue === undefined };
|
|
152
|
-
}
|
|
153
|
-
if (definition.type === 'enum') {
|
|
154
|
-
if (!definition.enumValues?.includes(value)) {
|
|
155
|
-
throw new AppError('INVALID_ARGS', `Invalid ${labelForFlag(token)}: ${value}`);
|
|
156
|
-
}
|
|
157
|
-
return { value, consumeNext: inlineValue === undefined };
|
|
158
|
-
}
|
|
159
|
-
const parsed = Number(value);
|
|
160
|
-
if (!Number.isFinite(parsed)) {
|
|
161
|
-
throw new AppError('INVALID_ARGS', `Invalid ${labelForFlag(token)}: ${value}`);
|
|
162
|
-
}
|
|
163
|
-
if (typeof definition.min === 'number' && parsed < definition.min) {
|
|
164
|
-
throw new AppError('INVALID_ARGS', `Invalid ${labelForFlag(token)}: ${value}`);
|
|
165
|
-
}
|
|
166
|
-
if (typeof definition.max === 'number' && parsed > definition.max) {
|
|
167
|
-
throw new AppError('INVALID_ARGS', `Invalid ${labelForFlag(token)}: ${value}`);
|
|
168
|
-
}
|
|
169
|
-
return { value: Math.floor(parsed), consumeNext: inlineValue === undefined };
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function labelForFlag(token: string): string {
|
|
173
|
-
return token.replace(/^-+/, '');
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function looksLikeFlagToken(value: string): boolean {
|
|
177
|
-
if (!value.startsWith('-') || value === '-') return false;
|
|
178
|
-
const [token] = value.startsWith('--') ? splitLongFlag(value) : [value, undefined];
|
|
179
|
-
return getFlagDefinition(token) !== undefined;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function shouldConsumeOptionalPathValue(value: string): boolean {
|
|
183
|
-
const trimmed = value.trim();
|
|
184
|
-
if (!trimmed) return false;
|
|
185
|
-
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(trimmed)) return false;
|
|
186
|
-
if (trimmed.startsWith('./') || trimmed.startsWith('../') || trimmed.startsWith('~/') || trimmed.startsWith('/')) {
|
|
187
|
-
return true;
|
|
188
|
-
}
|
|
189
|
-
if (trimmed.includes('/') || trimmed.includes('\\')) return true;
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function shouldTreatUnknownDashTokenAsPositional(
|
|
194
|
-
command: string | null,
|
|
195
|
-
positionals: string[],
|
|
196
|
-
arg: string,
|
|
197
|
-
): boolean {
|
|
198
|
-
if (!isNegativeNumericToken(arg)) return false;
|
|
199
|
-
if (!command) return false;
|
|
200
|
-
const schema = getCommandSchema(command);
|
|
201
|
-
if (!schema) return true;
|
|
202
|
-
if (schema.allowsExtraPositionals) return true;
|
|
203
|
-
if (schema.positionalArgs.length === 0) return false;
|
|
204
|
-
if (positionals.length < schema.positionalArgs.length) return true;
|
|
205
|
-
return schema.positionalArgs.some((entry) => entry.includes('?'));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function isNegativeNumericToken(value: string): boolean {
|
|
209
|
-
return /^-\d+(\.\d+)?$/.test(value);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function formatUnsupportedFlagMessage(command: string | null, unsupported: string[]): string {
|
|
213
|
-
if (!command) {
|
|
214
|
-
return unsupported.length === 1
|
|
215
|
-
? `Flag ${unsupported[0]} requires a command that supports it.`
|
|
216
|
-
: `Flags ${unsupported.join(', ')} require a command that supports them.`;
|
|
217
|
-
}
|
|
218
|
-
return unsupported.length === 1
|
|
219
|
-
? `Flag ${unsupported[0]} is not supported for command ${command}.`
|
|
220
|
-
: `Flags ${unsupported.join(', ')} are not supported for command ${command}.`;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export function toDaemonFlags(flags: CliFlags): Omit<CliFlags, 'json' | 'help' | 'version'> {
|
|
224
|
-
const {
|
|
225
|
-
json: _json,
|
|
226
|
-
help: _help,
|
|
227
|
-
version: _version,
|
|
228
|
-
...daemonFlags
|
|
229
|
-
} = flags;
|
|
230
|
-
return daemonFlags;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export function usage(): string {
|
|
234
|
-
return buildUsageText();
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export function usageForCommand(command: string): string | null {
|
|
238
|
-
return buildCommandUsageText(command);
|
|
239
|
-
}
|