@ant0/cli 0.0.0-stage → 0.3.22-beta.3

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.
Files changed (67) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +97 -2
  3. package/dist/api/generated/schema.d.ts +11600 -0
  4. package/dist/api/generated/schema.js +6 -0
  5. package/dist/api/index.d.ts +219 -0
  6. package/dist/api/index.js +342 -0
  7. package/dist/bin.d.ts +3 -0
  8. package/dist/bin.js +12 -0
  9. package/dist/bulk.d.ts +38 -0
  10. package/dist/bulk.js +66 -0
  11. package/dist/commands/account.d.ts +48 -0
  12. package/dist/commands/account.js +337 -0
  13. package/dist/commands/api-keys.d.ts +5 -0
  14. package/dist/commands/api-keys.js +310 -0
  15. package/dist/commands/browsers.d.ts +4 -0
  16. package/dist/commands/browsers.js +165 -0
  17. package/dist/commands/daemon.d.ts +15 -0
  18. package/dist/commands/daemon.js +202 -0
  19. package/dist/commands/events.d.ts +8 -0
  20. package/dist/commands/events.js +81 -0
  21. package/dist/commands/extensions.d.ts +4 -0
  22. package/dist/commands/extensions.js +74 -0
  23. package/dist/commands/profiles.d.ts +36 -0
  24. package/dist/commands/profiles.js +552 -0
  25. package/dist/commands/proxies.d.ts +23 -0
  26. package/dist/commands/proxies.js +170 -0
  27. package/dist/commands/sync.d.ts +4 -0
  28. package/dist/commands/sync.js +435 -0
  29. package/dist/commands/team.d.ts +7 -0
  30. package/dist/commands/team.js +403 -0
  31. package/dist/commands/trash.d.ts +10 -0
  32. package/dist/commands/trash.js +54 -0
  33. package/dist/commands/workspace.d.ts +10 -0
  34. package/dist/commands/workspace.js +56 -0
  35. package/dist/context.d.ts +111 -0
  36. package/dist/context.js +300 -0
  37. package/dist/errors.d.ts +27 -0
  38. package/dist/errors.js +96 -0
  39. package/dist/format.d.ts +23 -0
  40. package/dist/format.js +85 -0
  41. package/dist/index.d.ts +19 -0
  42. package/dist/index.js +35 -0
  43. package/dist/inventory.d.ts +50 -0
  44. package/dist/inventory.js +202 -0
  45. package/dist/management-transport.d.ts +3 -0
  46. package/dist/management-transport.js +90 -0
  47. package/dist/native-terminal.d.ts +50 -0
  48. package/dist/native-terminal.js +228 -0
  49. package/dist/program.d.ts +10 -0
  50. package/dist/program.js +185 -0
  51. package/dist/runtime-types.d.ts +20 -0
  52. package/dist/runtime-types.js +2 -0
  53. package/dist/set.d.ts +15 -0
  54. package/dist/set.js +87 -0
  55. package/dist/shared/parse-error.d.ts +6 -0
  56. package/dist/shared/parse-error.js +8 -0
  57. package/dist/shared/proxy-parse.d.ts +42 -0
  58. package/dist/shared/proxy-parse.js +238 -0
  59. package/dist/shared/proxy-types.d.ts +21 -0
  60. package/dist/shared/proxy-types.js +2 -0
  61. package/dist/shared/recovery-code.d.ts +7 -0
  62. package/dist/shared/recovery-code.js +53 -0
  63. package/dist/version.d.ts +8 -0
  64. package/dist/version.js +18 -0
  65. package/licenses/README.md +5 -0
  66. package/licenses/THIRD_PARTY_NOTICES +96 -0
  67. package/package.json +63 -4
@@ -0,0 +1,552 @@
1
+ /**
2
+ * `ant0 profiles ...`:
3
+ *
4
+ * ls [--group --tag -q --running --trashed --limit --offset] | create <name> [...]
5
+ * show <id|name> | edit <id> --set key=value...
6
+ * set <ref...> [--group|--no-group] [--tag-add]* [--tag-remove]* [--pin|--no-pin]
7
+ * rm <ref...> [--permanent | --cloud] [--yes] | restore <ref...>
8
+ * run <id|name> [--timeout] [--conflict-profile-id] | start <ref...> [--headless]
9
+ * stop <ref...> [--force] | status <id|name> | identity <id> | promote <id> --folder-id ...
10
+ * cookies import <id> <file> | cookies export <id> [--format] [-o file] | bulk <file.csv>
11
+ *
12
+ * `:id`/`<ref>` parameters accept the UUID or the exact profile name (the daemon resolves both).
13
+ * Commands that take several refs use the daemon's bulk routes when they exist (start, stop,
14
+ * set) and loop otherwise (rm, restore); either way they print one line per failed id and exit 1
15
+ * when anything failed.
16
+ */
17
+ import { readFileSync, writeFileSync } from "node:fs";
18
+ import { parseProxyLine } from "../shared/proxy-parse.js";
19
+ import { isAnt0ApiError, unwrap, } from "../api/index.js";
20
+ import { BULK_MAX_IDS, finishBulk, finishCodedBulk, forEachRef, uniqueRefs } from "../bulk.js";
21
+ import { CliError, UsageError } from "../errors.js";
22
+ import { flatten, keyValues, table } from "../format.js";
23
+ import { parseSetArgs } from "../set.js";
24
+ import { inventoryRead, projectProfileList, projectProfileStatus } from "../inventory.js";
25
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
26
+ function collect(value, previous) {
27
+ return [...previous, value];
28
+ }
29
+ function positiveInt(flag) {
30
+ return (value) => {
31
+ const n = Number(value);
32
+ if (!Number.isInteger(n) || n < 0)
33
+ throw new UsageError(`${flag} expects a non-negative integer`);
34
+ return n;
35
+ };
36
+ }
37
+ function boundedInt(flag, minimum, maximum) {
38
+ return (value) => {
39
+ const n = Number(value);
40
+ if (!Number.isInteger(n) || n < minimum || n > maximum) {
41
+ throw new UsageError(`${flag} expects an integer from ${minimum} to ${maximum}`);
42
+ }
43
+ return n;
44
+ };
45
+ }
46
+ function uuid(flag) {
47
+ return (value) => {
48
+ if (!UUID_RE.test(value))
49
+ throw new UsageError(`${flag} expects a UUID`);
50
+ return value;
51
+ };
52
+ }
53
+ function folderId(value) {
54
+ if (value === "null")
55
+ return null;
56
+ if (!UUID_RE.test(value))
57
+ throw new UsageError("--folder-id expects a UUID or null");
58
+ return value;
59
+ }
60
+ export const SUMMARY_HEADERS = [
61
+ "id",
62
+ "name",
63
+ "group",
64
+ "tags",
65
+ "platform",
66
+ "status",
67
+ "pinned",
68
+ "identity",
69
+ "proxy",
70
+ "browser",
71
+ ];
72
+ export function summaryRows(items) {
73
+ return items.map((p) => [
74
+ p.id,
75
+ p.name,
76
+ p.group,
77
+ p.tags.length ? p.tags.join(",") : null,
78
+ p.platform,
79
+ p.status,
80
+ p.pinned,
81
+ p.identity_mode,
82
+ p.proxy_id,
83
+ p.browser_version,
84
+ ]);
85
+ }
86
+ function refsOrUsage(refs, command) {
87
+ const unique = uniqueRefs(refs);
88
+ if (unique.length > BULK_MAX_IDS) {
89
+ throw new UsageError(`${command} accepts at most ${BULK_MAX_IDS} profiles per call`);
90
+ }
91
+ return unique;
92
+ }
93
+ const WEBRTC_MODES = ["proxy-only", "disabled", "host"];
94
+ /** `profiles set` flags -> `patch` of `POST /profiles/bulk-update`; empty patch is a usage error. */
95
+ export function setPatch(opts) {
96
+ const patch = {};
97
+ if (opts.group === false)
98
+ patch.group = null;
99
+ else if (typeof opts.group === "string")
100
+ patch.group = opts.group;
101
+ if (opts.tagAdd.length > 0)
102
+ patch.tags_add = opts.tagAdd;
103
+ if (opts.tagRemove.length > 0)
104
+ patch.tags_remove = opts.tagRemove;
105
+ if (opts.pin !== undefined)
106
+ patch.pinned = opts.pin;
107
+ if (opts.status === false)
108
+ patch.status = null;
109
+ else if (typeof opts.status === "string")
110
+ patch.status = opts.status;
111
+ if (opts.proxy === false)
112
+ patch.proxy_id = null;
113
+ else if (typeof opts.proxy === "string") {
114
+ if (!UUID_RE.test(opts.proxy)) {
115
+ throw new UsageError("--proxy takes a saved proxy id (see `ant0 proxies ls`)");
116
+ }
117
+ patch.proxy_id = opts.proxy;
118
+ }
119
+ if (opts.webrtc !== undefined) {
120
+ const mode = WEBRTC_MODES.find((m) => m === opts.webrtc);
121
+ if (mode === undefined) {
122
+ throw new UsageError(`--webrtc must be one of ${WEBRTC_MODES.join(", ")}`);
123
+ }
124
+ patch.webrtc = mode;
125
+ }
126
+ if (Object.keys(patch).length === 0) {
127
+ throw new UsageError("set needs at least one of --group, --no-group, --tag-add, --tag-remove, --pin, --no-pin, " +
128
+ "--status, --no-status, --proxy, --no-proxy, --webrtc");
129
+ }
130
+ return patch;
131
+ }
132
+ /** `--proxy <id|url|line>` -> `network` fragment of a create/patch body. */
133
+ export function proxyNetwork(value) {
134
+ if (UUID_RE.test(value))
135
+ return { proxy_id: value };
136
+ try {
137
+ parseProxyLine(value); // early, local validation with a precise message
138
+ }
139
+ catch (err) {
140
+ throw new UsageError(`--proxy: ${err.message}`);
141
+ }
142
+ return /^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(value)
143
+ ? { proxy: { url: value } }
144
+ : { proxy: { line: value } };
145
+ }
146
+ export function createBody(name, opts) {
147
+ const body = { name };
148
+ if (opts.group !== undefined)
149
+ body.group = opts.group;
150
+ if (opts.tag.length > 0)
151
+ body.tags = opts.tag;
152
+ if (opts.notes !== undefined)
153
+ body.notes = opts.notes;
154
+ if (opts.pin)
155
+ body.pinned = true;
156
+ if (opts.startUrl.length > 0 || opts.headless) {
157
+ body.launch = {
158
+ ...(opts.startUrl.length > 0 ? { start_urls: opts.startUrl } : {}),
159
+ ...(opts.headless ? { headless: true } : {}),
160
+ };
161
+ }
162
+ if (opts.proxy !== undefined)
163
+ body.network = proxyNetwork(opts.proxy);
164
+ return body;
165
+ }
166
+ function manifestText(m) {
167
+ return keyValues(flatten(m));
168
+ }
169
+ function sessionText(s) {
170
+ return keyValues([
171
+ ["ws_endpoint", s.ws_endpoint],
172
+ ["debug_port", s.debug_port],
173
+ ["pid", s.pid],
174
+ ["cdp_http", s.cdp_http],
175
+ ["browser_version", s.browser_version],
176
+ ["headless", s.headless],
177
+ ["started_at", s.started_at],
178
+ ]);
179
+ }
180
+ function runResultText(result) {
181
+ return keyValues([
182
+ ["requested_profile_id", result.requested_profile_id],
183
+ ["profile_id", result.profile_id],
184
+ ["redirected", result.redirected],
185
+ ["state", result.lifecycle.state],
186
+ ["started_at", result.lifecycle.started_at],
187
+ ["browser_version", result.lifecycle.browser_version],
188
+ ["headless", result.lifecycle.headless],
189
+ ]);
190
+ }
191
+ /** A run may have spawned before a late delivery failure. Inspect once; never replay it. */
192
+ async function inspectFailedRun(ctx, id, error) {
193
+ if (isAnt0ApiError(error) && !error.message.includes("inspect lifecycle before retrying"))
194
+ return;
195
+ let lifecycle;
196
+ try {
197
+ lifecycle = unwrap(await ctx.client().GET("/v1/profiles/{id}/run", { params: { path: { id } } }));
198
+ }
199
+ catch {
200
+ // The original failure remains authoritative. Do not turn inspection into a retry.
201
+ }
202
+ ctx.err(lifecycle
203
+ ? `run outcome was not confirmed; ${lifecycle.profile_id} is ${lifecycle.state}. Inspect status before retrying`
204
+ : `run outcome was not confirmed; inspect with \`ant0 profiles status ${id}\` before retrying`);
205
+ }
206
+ /** Offer only what the private key actually carries; the daemon and cloud still decide. */
207
+ async function requireCredentialScopes(ctx, ...required) {
208
+ const grant = await ctx.keyGrant();
209
+ if (!grant)
210
+ return;
211
+ const missing = required.filter((scope) => !grant.scopes.includes(scope));
212
+ if (missing.length > 0)
213
+ throw new CliError(`${ctx.globals.credentialFile !== undefined ? "credential file" : "API key"} does not grant ${missing.join(" and ")}`);
214
+ }
215
+ export function registerProfiles(program, ctx) {
216
+ const profiles = program.command("profiles").description("Browser profiles");
217
+ profiles
218
+ .command("ls")
219
+ .description("List profiles")
220
+ .option("-q, --query <text>", "filter by name substring")
221
+ .option("--group <name>", "filter by group")
222
+ .option("--tag <tag>", "filter by tag")
223
+ .option("--running", "only profiles whose browser is running (filtered before pagination)")
224
+ .option("--trashed", "list the trash instead of live profiles (same as `ant0 trash ls`)")
225
+ .option("--limit <n>", "page size", positiveInt("--limit"))
226
+ .option("--offset <n>", "page offset", positiveInt("--offset"))
227
+ .action(async (opts) => {
228
+ const client = ctx.client();
229
+ const data = await inventoryRead(async () => projectProfileList(unwrap(await client.GET("/v1/inventory/profiles", {
230
+ ...(ctx.io.signal ? { signal: ctx.io.signal } : {}),
231
+ params: {
232
+ query: {
233
+ ...(opts.query !== undefined ? { q: opts.query } : {}),
234
+ ...(opts.group !== undefined ? { group: opts.group } : {}),
235
+ ...(opts.tag !== undefined ? { tag: opts.tag } : {}),
236
+ ...(opts.trashed ? { trashed: true } : {}),
237
+ ...(opts.running ? { running: true } : {}),
238
+ ...(opts.limit !== undefined ? { limit: opts.limit } : {}),
239
+ ...(opts.offset !== undefined ? { offset: opts.offset } : {}),
240
+ },
241
+ },
242
+ })), opts.limit, opts.offset, opts.running, ctx.keyMode()));
243
+ ctx.emit(data, () => opts.trashed
244
+ ? table([...SUMMARY_HEADERS, "deleted"], data.items.map((p) => [...summaryRows([p])[0], p.deleted_at]))
245
+ : table(SUMMARY_HEADERS, summaryRows(data.items)));
246
+ });
247
+ profiles
248
+ .command("create <name>")
249
+ .description("Create a profile. Its OS follows this computer: Linux on Linux when a Linux identity " +
250
+ "can be issued (else a Windows profile, logged), Windows otherwise")
251
+ .option("--proxy <id|url|line>", "existing proxy id, or an inline proxy URL / provider line")
252
+ .option("--group <name>", "folder")
253
+ .option("--tag <tag>", "tag (repeatable)", collect, [])
254
+ .option("--start-url <url>", "URL opened at launch (repeatable)", collect, [])
255
+ .option("--pin", "pin the profile")
256
+ .option("--headless", "launch headless by default")
257
+ .option("--notes <text>", "free-form notes")
258
+ .action(async (name, opts) => {
259
+ const created = unwrap(await ctx.client().POST("/v1/profiles", { body: createBody(name, opts) }));
260
+ ctx.emit(created, () => manifestText(created));
261
+ });
262
+ profiles
263
+ .command("show <id>")
264
+ .description("Show a profile (UUID or exact name) and its runtime state")
265
+ .action(async (id) => {
266
+ const data = unwrap(await ctx.client().GET("/v1/profiles/{id}", { params: { path: { id } } }));
267
+ ctx.emit(data, () => manifestText(data));
268
+ });
269
+ profiles
270
+ .command("edit <id>")
271
+ .description("Patch fields: --set network.geo.timezone=Europe/Berlin --set tags=a,b --set pinned=true")
272
+ .requiredOption("--set <key=value>", "field to change (repeatable)", collect, [])
273
+ .action(async (id, opts) => {
274
+ if (opts.set.length === 0)
275
+ throw new UsageError("edit needs at least one --set key=value");
276
+ const body = parseSetArgs(opts.set);
277
+ const updated = unwrap(await ctx.client().PATCH("/v1/profiles/{id}", { params: { path: { id } }, body }));
278
+ ctx.emit(updated, () => manifestText(updated));
279
+ });
280
+ profiles
281
+ .command("set <ref...>")
282
+ .description("Change group, tags, pin, status, proxy or WebRTC on one or more profiles " +
283
+ "(POST /profiles/bulk-update); use `edit --set` for any other field")
284
+ .option("--group <name>", "move into a folder")
285
+ .option("--no-group", "remove from its folder")
286
+ .option("--tag-add <tag>", "add a tag (repeatable)", collect, [])
287
+ .option("--tag-remove <tag>", "remove a tag (repeatable)", collect, [])
288
+ .option("--pin", "pin")
289
+ .option("--no-pin", "unpin")
290
+ .option("--status <text>", "set the status")
291
+ .option("--no-status", "clear the status")
292
+ .option("--proxy <id>", "use this saved proxy (id from `proxies ls`)")
293
+ .option("--no-proxy", "use a direct connection")
294
+ .option("--webrtc <mode>", "WebRTC mode: proxy-only, disabled or host")
295
+ .action(async (refs, opts) => {
296
+ const patch = setPatch(opts);
297
+ const ids = refsOrUsage(refs, "set");
298
+ const result = unwrap(await ctx.client().POST("/v1/profiles/bulk-update", { body: { ids, patch } }));
299
+ finishBulk(ctx, "updated", result);
300
+ });
301
+ profiles
302
+ .command("rm <ref...>")
303
+ .description("Move profiles to the trash (kept for 30 days by default, `profiles restore` brings them back); " +
304
+ "--permanent deletes them for good, data directory included; --cloud also moves the " +
305
+ "cloud copy of Cloud profiles to the cloud Trash. Refused while running")
306
+ .option("--permanent", "delete for good instead of trashing (asks unless --yes)")
307
+ .option("--purge", "alias of --permanent")
308
+ .option("--cloud", "Cloud profiles: also move the cloud copy to the cloud Trash, removing it from your " +
309
+ "other computers (asks unless --yes)")
310
+ .option("-y, --yes", "do not ask for confirmation")
311
+ .action(async (refs, opts) => {
312
+ const ids = refsOrUsage(refs, "rm");
313
+ const permanent = opts.permanent === true || opts.purge === true;
314
+ const cloud = opts.cloud === true;
315
+ if (permanent && cloud)
316
+ throw new UsageError("--cloud cannot be combined with --permanent");
317
+ if (permanent) {
318
+ await ctx.confirm(`permanently delete ${ids.length} profile(s) (${ids.join(", ")}) and their data?`, opts.yes);
319
+ }
320
+ if (cloud) {
321
+ await ctx.confirm(`move ${ids.length} profile(s) (${ids.join(", ")}) to the trash? Cloud profiles are ` +
322
+ "also removed from the cloud and your other computers.", opts.yes);
323
+ }
324
+ const client = ctx.client();
325
+ const call = (id) => client.DELETE("/v1/profiles/{id}", {
326
+ params: {
327
+ path: { id },
328
+ query: permanent ? { permanent: true } : cloud ? { cloud: "trash" } : {},
329
+ },
330
+ });
331
+ if (ids.length === 1) {
332
+ unwrap(await call(ids[0]));
333
+ ctx.emit(undefined, () => permanent
334
+ ? `deleted ${ids[0]} permanently`
335
+ : `moved ${ids[0]} to the trash (undo: ant0 profiles restore ${ids[0]})`);
336
+ return;
337
+ }
338
+ const result = await forEachRef(ids, async (id) => unwrap(await call(id)));
339
+ finishBulk(ctx, permanent ? "deleted" : "trashed", result, permanent || result.updated === 0 ? [] : [" undo: ant0 profiles restore <ref...>"]);
340
+ });
341
+ profiles
342
+ .command("restore <ref...>")
343
+ .description("Bring profiles back from the trash")
344
+ .action(async (refs) => {
345
+ const ids = refsOrUsage(refs, "restore");
346
+ const client = ctx.client();
347
+ const call = async (id) => unwrap(await client.POST("/v1/profiles/{id}/restore", { params: { path: { id } } }));
348
+ if (ids.length === 1) {
349
+ const restored = await call(ids[0]);
350
+ ctx.emit(restored, () => `restored ${ids[0]}`);
351
+ return;
352
+ }
353
+ finishBulk(ctx, "restored", await forEachRef(ids, call));
354
+ });
355
+ profiles
356
+ .command("run <id>")
357
+ .description("Run a profile's saved configuration without requesting a CDP endpoint")
358
+ .option("--timeout <seconds>", "launch timeout (1-600 seconds)", boundedInt("--timeout", 1, 600))
359
+ .option("--conflict-profile-id <uuid>", "explicitly reuse this exact stopped unresolved conflict", uuid("--conflict-profile-id"))
360
+ .action(async (id, opts) => {
361
+ const client = ctx.client();
362
+ await requireCredentialScopes(ctx, "profiles:run");
363
+ try {
364
+ const result = unwrap(await client.POST("/v1/profiles/{id}/run", {
365
+ params: { path: { id } },
366
+ body: {
367
+ ...(opts.timeout !== undefined ? { timeout_s: opts.timeout } : {}),
368
+ ...(opts.conflictProfileId !== undefined
369
+ ? { conflict_profile_id: opts.conflictProfileId }
370
+ : {}),
371
+ },
372
+ }));
373
+ ctx.emit(result, () => runResultText(result));
374
+ }
375
+ catch (error) {
376
+ await inspectFailedRun(ctx, id, error);
377
+ throw error;
378
+ }
379
+ });
380
+ profiles
381
+ .command("start <ref...>")
382
+ .description("Developer launch with CDP details and optional overrides; several refs use the " +
383
+ "endpoint-free bulk run route")
384
+ .option("--headless", "run headless (single profile)")
385
+ .option("--start-url <url>", "override the start URLs (repeatable, single profile)", collect, [])
386
+ .option("--timeout <seconds>", "launch timeout (single profile)", positiveInt("--timeout"))
387
+ .action(async (refs, opts) => {
388
+ const ids = refsOrUsage(refs, "start");
389
+ const client = ctx.client();
390
+ if (ids.length > 1) {
391
+ await requireCredentialScopes(ctx, "profiles:run");
392
+ if (opts.headless || opts.startUrl.length > 0 || opts.timeout !== undefined) {
393
+ throw new UsageError("--headless, --start-url and --timeout apply to a single profile only");
394
+ }
395
+ const result = unwrap(await client.POST("/v1/profiles/bulk-start", { body: { ids } }));
396
+ finishCodedBulk(ctx, "started", result);
397
+ return;
398
+ }
399
+ const id = ids[0];
400
+ await requireCredentialScopes(ctx, "profiles:run", "profiles:cdp");
401
+ try {
402
+ const session = unwrap(await client.POST("/v1/profiles/{id}/start", {
403
+ params: { path: { id } },
404
+ body: {
405
+ ...(opts.headless ? { headless: true } : {}),
406
+ ...(opts.startUrl.length > 0 ? { start_urls: opts.startUrl } : {}),
407
+ ...(opts.timeout !== undefined ? { timeout_s: opts.timeout } : {}),
408
+ },
409
+ }));
410
+ ctx.emit(session, () => sessionText(session));
411
+ }
412
+ catch (error) {
413
+ await inspectFailedRun(ctx, id, error);
414
+ throw error;
415
+ }
416
+ });
417
+ profiles
418
+ .command("stop <ref...>")
419
+ .description("Stop the running browser of one or more profiles (POST /profiles/bulk-stop)")
420
+ .option("--force", "SIGKILL immediately (single profile)")
421
+ .action(async (refs, opts) => {
422
+ const ids = refsOrUsage(refs, "stop");
423
+ const client = ctx.client();
424
+ await requireCredentialScopes(ctx, "profiles:stop");
425
+ if (ids.length > 1) {
426
+ if (opts.force)
427
+ throw new UsageError("--force applies to a single profile only");
428
+ const result = unwrap(await client.POST("/v1/profiles/bulk-stop", { body: { ids } }));
429
+ finishBulk(ctx, "stopped", result);
430
+ return;
431
+ }
432
+ const id = ids[0];
433
+ const stopped = await client.POST("/v1/profiles/{id}/stop", {
434
+ params: { path: { id } },
435
+ body: opts.force ? { force: true } : {},
436
+ });
437
+ unwrap(stopped);
438
+ // The daemon normally sets Ant0-Sync (done, or pending when the upload outlasts 30 s); it may be
439
+ // absent if there is nothing to sync.
440
+ const pending = stopped.response.headers.get("ant0-sync") === "pending";
441
+ ctx.emit(pending ? { sync: "pending" } : undefined, () => pending ? `stopped ${id}; sync still uploading in the background` : `stopped ${id}`);
442
+ });
443
+ profiles
444
+ .command("status <id>")
445
+ .description("Run state and endpoint-free lifecycle metadata of a profile")
446
+ .action(async (id) => {
447
+ const client = ctx.client();
448
+ const data = await inventoryRead(async () => projectProfileStatus(unwrap(await client.GET("/v1/inventory/profiles/{id}", {
449
+ ...(ctx.io.signal ? { signal: ctx.io.signal } : {}),
450
+ params: { path: { id } },
451
+ })), id, ctx.keyMode()));
452
+ ctx.emit(data, () => data.session
453
+ ? keyValues([["state", data.state], ...Object.entries(data.session)])
454
+ : keyValues([["state", data.state]]));
455
+ });
456
+ profiles
457
+ .command("promote <id>")
458
+ .description("Publish an inherited local copy independently in the current workspace")
459
+ .requiredOption("--folder-id <uuid|null>", "destination workspace folder, or null")
460
+ .option("--name <name>", "rename the promoted profile")
461
+ .action(async (id, opts) => {
462
+ const result = unwrap(await ctx.client().POST("/v1/profiles/{id}/promote", {
463
+ params: { path: { id } },
464
+ body: {
465
+ folder_id: folderId(opts.folderId),
466
+ ...(opts.name !== undefined ? { name: opts.name } : {}),
467
+ },
468
+ }));
469
+ ctx.emit(result, () => keyValues(flatten(result.receipt)));
470
+ });
471
+ profiles
472
+ .command("identity <id>")
473
+ .description("Preview the fingerprint persona the profile will launch with")
474
+ .action(async (id) => {
475
+ const data = unwrap(await ctx.client().GET("/v1/profiles/{id}/identity", { params: { path: { id } } }));
476
+ ctx.emit(data, () => {
477
+ const head = keyValues([
478
+ ["mode", data.mode],
479
+ ["source", data.source ? `${data.source.kind} ${data.source.version}` : null],
480
+ ["persisted", data.persisted],
481
+ ["warnings", data.warnings.length === 0 ? "none" : null],
482
+ ]);
483
+ const warnings = data.warnings.map((w) => ` ${JSON.stringify(w)}`).join("\n");
484
+ const persona = data.persona ? keyValues(flatten(data.persona, "persona")) : "";
485
+ return [head, warnings, persona].filter((s) => s.length > 0).join("\n");
486
+ });
487
+ });
488
+ const cookies = profiles.command("cookies").description("Import and export cookies");
489
+ cookies
490
+ .command("import <id> <file>")
491
+ .description("Import cookies (Cookie-Editor JSON, Puppeteer/Playwright arrays, or Netscape cookies.txt)")
492
+ .action(async (id, file) => {
493
+ const data = readFileSync(file, "utf8");
494
+ const result = unwrap(await ctx.client().POST("/v1/profiles/{id}/cookies", {
495
+ params: { path: { id } },
496
+ body: { format: "auto", data },
497
+ }));
498
+ ctx.emit(result, () => keyValues(flatten(result)));
499
+ });
500
+ cookies
501
+ .command("export <id>")
502
+ .description("Export cookies")
503
+ .option("--format <format>", "json or netscape", "json")
504
+ .option("-o, --output <file>", "write to a file instead of stdout")
505
+ .action(async (id, opts) => {
506
+ let text;
507
+ if (opts.format === "netscape") {
508
+ text = unwrap(await ctx.client().GET("/v1/profiles/{id}/cookies", {
509
+ params: { path: { id }, query: { format: "netscape" } },
510
+ parseAs: "text",
511
+ }));
512
+ }
513
+ else if (opts.format === "json") {
514
+ const data = unwrap(await ctx.client().GET("/v1/profiles/{id}/cookies", {
515
+ params: { path: { id }, query: { format: "json" } },
516
+ }));
517
+ text = JSON.stringify(data, null, 2);
518
+ }
519
+ else {
520
+ throw new UsageError(`--format must be json or netscape, got "${opts.format}"`);
521
+ }
522
+ if (opts.output) {
523
+ writeFileSync(opts.output, text.endsWith("\n") ? text : `${text}\n`);
524
+ if (!ctx.json)
525
+ ctx.out(`wrote ${opts.output}`);
526
+ }
527
+ else {
528
+ ctx.out(text);
529
+ }
530
+ });
531
+ profiles
532
+ .command("bulk <file>")
533
+ .description("Create profiles from a CSV file (header row + one profile per row)")
534
+ .action(async (file) => {
535
+ const csv = readFileSync(file, "utf8");
536
+ const result = unwrap(await ctx.client().POST("/v1/profiles/bulk", { body: { csv } }));
537
+ ctx.emit(result, () => {
538
+ const lines = [`created ${result.created.length} profile(s)`];
539
+ for (const id of result.created)
540
+ lines.push(` ${id}`);
541
+ if (result.errors.length > 0)
542
+ lines.push(`errors ${result.errors.length}`);
543
+ for (const e of result.errors)
544
+ lines.push(` row ${e.row}: ${e.message}`);
545
+ return lines.join("\n");
546
+ });
547
+ if (result.created.length === 0 && result.errors.length > 0) {
548
+ throw new CliError("no profiles created", 1);
549
+ }
550
+ });
551
+ }
552
+ //# sourceMappingURL=profiles.js.map
@@ -0,0 +1,23 @@
1
+ /**
2
+ * `ant0 proxies ls [-q --tag] | add <url|line> [--name] | show|check|change-ip|rm <ref>`.
3
+ *
4
+ * `add` parses the argument locally with `@ant0/schemas` (`parseProxyLine` accepts both
5
+ * `scheme://user:pass@host:port` and provider lines such as `host:port:user:pass`) so `--name`
6
+ * can travel in the same request; the password is sent plaintext once and stored as a secret ref.
7
+ *
8
+ * `<ref>` is the proxy UUID or its exact name. The `/v1/proxies/{id}` routes only take UUIDs, so
9
+ * the CLI resolves a name through `GET /v1/proxies` first (`resolveProxyId`), the way the daemon
10
+ * resolves profile names for `ant0 profiles …`: exactly one live proxy must carry the name.
11
+ */
12
+ import type { Command } from "commander";
13
+ import { type ProxyCreate } from "../api/index.js";
14
+ import type { Context } from "../context.js";
15
+ /**
16
+ * The UUID for a `<ref>`: a UUID passes through untouched; anything else must be the exact name
17
+ * of one proxy. Errors mirror the daemon's profile resolution codes: `proxy.not_found` (exit 1)
18
+ * and `proxy.ambiguous_name` listing the candidate ids.
19
+ */
20
+ export declare function resolveProxyId(ctx: Context, ref: string): Promise<string>;
21
+ export declare function parseProxyArg(value: string, name: string | undefined): ProxyCreate;
22
+ export declare function registerProxies(program: Command, ctx: Context): void;
23
+ //# sourceMappingURL=proxies.d.ts.map