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

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 +11615 -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 +217 -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 +72 -0
  58. package/dist/shared/proxy-parse.js +294 -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,170 @@
1
+ import { formatHostPort, parseProxyLine } from "../shared/proxy-parse.js";
2
+ import { unwrap } from "../api/index.js";
3
+ import { CliError, UsageError } from "../errors.js";
4
+ import { flatten, keyValues, table } from "../format.js";
5
+ import { inventoryRead, projectProxyList } from "../inventory.js";
6
+ function checkSummary(c) {
7
+ if (!c)
8
+ return null;
9
+ if (!c.ok)
10
+ return `fail${c.error ? `: ${c.error}` : ""}`;
11
+ return ["ok", c.ip, c.country, c.latency_ms !== null ? `${c.latency_ms}ms` : null]
12
+ .filter((v) => typeof v === "string")
13
+ .join(" ");
14
+ }
15
+ function proxyRows(items) {
16
+ return items.map((p) => [
17
+ p.id,
18
+ p.name,
19
+ p.type,
20
+ formatHostPort(p.host, p.port),
21
+ p.username,
22
+ p.provider,
23
+ p.tags.length ? p.tags.join(",") : null,
24
+ checkSummary(p.last_check),
25
+ ]);
26
+ }
27
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
28
+ /**
29
+ * The UUID for a `<ref>`: a UUID passes through untouched; anything else must be the exact name
30
+ * of one proxy. Errors mirror the daemon's profile resolution codes: `proxy.not_found` (exit 1)
31
+ * and `proxy.ambiguous_name` listing the candidate ids.
32
+ */
33
+ export async function resolveProxyId(ctx, ref) {
34
+ if (UUID_RE.test(ref))
35
+ return ref;
36
+ const data = unwrap(await ctx.client().GET("/v1/proxies", { params: { query: { q: ref } } }));
37
+ const matches = data.items.filter((p) => p.name === ref);
38
+ if (matches.length === 1)
39
+ return matches[0].id;
40
+ if (matches.length === 0) {
41
+ throw new CliError(`proxy.not_found: no proxy named ${JSON.stringify(ref)}`);
42
+ }
43
+ throw new CliError(`proxy.ambiguous_name: ${matches.length} proxies are named ${JSON.stringify(ref)}; use the id: ` +
44
+ matches.map((p) => p.id).join(", "));
45
+ }
46
+ export function parseProxyArg(value, name) {
47
+ let parsed;
48
+ try {
49
+ parsed = parseProxyLine(value);
50
+ }
51
+ catch (err) {
52
+ throw new UsageError(`invalid proxy: ${err.message}`);
53
+ }
54
+ const body = { type: parsed.type, host: parsed.host, port: parsed.port };
55
+ body.name = name ?? parsed.name;
56
+ if (parsed.username !== undefined)
57
+ body.username = parsed.username;
58
+ if (parsed.password !== undefined)
59
+ body.password = parsed.password;
60
+ if (parsed.change_ip_url !== undefined)
61
+ body.change_ip_url = parsed.change_ip_url;
62
+ if (parsed.session_pattern !== undefined)
63
+ body.session_pattern = parsed.session_pattern;
64
+ if (parsed.provider !== undefined)
65
+ body.provider = parsed.provider;
66
+ if (parsed.udp !== undefined)
67
+ body.udp = parsed.udp;
68
+ if (parsed.tags !== undefined)
69
+ body.tags = parsed.tags;
70
+ if (parsed.notes !== undefined)
71
+ body.notes = parsed.notes;
72
+ return body;
73
+ }
74
+ export function registerProxies(program, ctx) {
75
+ const proxies = program.command("proxies").description("Shared proxy objects");
76
+ proxies
77
+ .command("ls")
78
+ .description("List proxies")
79
+ .option("-q, --query <text>", "filter by name/host substring")
80
+ .option("--tag <tag>", "filter by tag")
81
+ .option("--limit <n>", "inventory page size in credential-file mode", (v) => Number(v), 100)
82
+ .option("--offset <n>", "inventory page offset in credential-file mode", (v) => Number(v), 0)
83
+ .action(async (opts) => {
84
+ if (ctx.keyMode()) {
85
+ if (opts.query !== undefined || opts.tag !== undefined)
86
+ throw new UsageError("key proxy inventory does not support name or tag filters");
87
+ if (!Number.isInteger(opts.limit) ||
88
+ opts.limit < 1 ||
89
+ opts.limit > 100 ||
90
+ !Number.isSafeInteger(opts.offset) ||
91
+ opts.offset < 0)
92
+ throw new UsageError("inventory requires limit 1–100 and non-negative offset");
93
+ const client = ctx.client();
94
+ const data = await inventoryRead(async () => projectProxyList(unwrap(await client.GET("/v1/inventory/proxies", {
95
+ params: { query: { limit: opts.limit, offset: opts.offset } },
96
+ })), opts.limit, opts.offset));
97
+ ctx.emit(data, () => table(["id", "type", "ok", "country", "latency_ms"], data.items.map((p) => [
98
+ p.id,
99
+ p.type,
100
+ p.last_check?.ok,
101
+ p.last_check?.country,
102
+ p.last_check?.latency_ms,
103
+ ])));
104
+ return;
105
+ }
106
+ const data = unwrap(await ctx.client().GET("/v1/proxies", {
107
+ params: {
108
+ query: {
109
+ ...(opts.query !== undefined ? { q: opts.query } : {}),
110
+ ...(opts.tag !== undefined ? { tag: opts.tag } : {}),
111
+ },
112
+ },
113
+ }));
114
+ ctx.emit(data, () => table(["id", "name", "type", "host", "user", "provider", "tags", "last check"], proxyRows(data.items)));
115
+ });
116
+ proxies
117
+ .command("add <proxy>")
118
+ .description("Add a proxy from scheme://user:pass@host:port or host:port:user:pass")
119
+ .option("--name <name>", "display name (default host:port)")
120
+ .action(async (value, opts) => {
121
+ const body = parseProxyArg(value, opts.name);
122
+ const created = unwrap(await ctx.client().POST("/v1/proxies", { body }));
123
+ ctx.emit(created, () => keyValues(flatten(created)));
124
+ });
125
+ proxies
126
+ .command("show <ref>")
127
+ .description("Show one proxy (UUID or exact name)")
128
+ .action(async (ref) => {
129
+ const id = await resolveProxyId(ctx, ref);
130
+ const proxy = unwrap(await ctx.client().GET("/v1/proxies/{id}", { params: { path: { id } } }));
131
+ ctx.emit(proxy, () => keyValues(flatten(proxy)));
132
+ });
133
+ proxies
134
+ .command("check <ref>")
135
+ .description("Connect through the proxy and report exit IP, country and latency")
136
+ .action(async (ref) => {
137
+ const id = await resolveProxyId(ctx, ref);
138
+ const result = unwrap(await ctx.client().POST("/v1/proxies/{id}/check", { params: { path: { id } } }));
139
+ ctx.emit(result, () => result
140
+ ? keyValues([
141
+ ["ok", result.ok],
142
+ ["ip", result.ip],
143
+ ["country", result.country],
144
+ ["timezone", result.timezone],
145
+ ["latency_ms", result.latency_ms],
146
+ ["error", result.error],
147
+ ["at", result.at],
148
+ ])
149
+ : "no result");
150
+ if (!result || !result.ok)
151
+ throw new CliError("proxy check failed", 1);
152
+ });
153
+ proxies
154
+ .command("change-ip <ref>")
155
+ .description("Ask the provider for a new exit IP (GETs the proxy's change_ip_url)")
156
+ .action(async (ref) => {
157
+ const id = await resolveProxyId(ctx, ref);
158
+ const result = unwrap(await ctx.client().POST("/v1/proxies/{id}/change-ip", { params: { path: { id } } }));
159
+ ctx.emit(result, () => `provider answered HTTP ${result.status}`);
160
+ });
161
+ proxies
162
+ .command("rm <ref>")
163
+ .description("Delete a proxy (refused while a profile references it)")
164
+ .action(async (ref) => {
165
+ const id = await resolveProxyId(ctx, ref);
166
+ unwrap(await ctx.client().DELETE("/v1/proxies/{id}", { params: { path: { id } } }));
167
+ ctx.emit(undefined, () => `removed ${id}`);
168
+ });
169
+ }
170
+ //# sourceMappingURL=proxies.js.map
@@ -0,0 +1,4 @@
1
+ import { type Command } from "commander";
2
+ import type { Context } from "../context.js";
3
+ export declare function registerSync(program: Command, ctx: Context): void;
4
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1,435 @@
1
+ /** Sync commands over the daemon's authenticated loopback API. */
2
+ import { unwrap } from "../api/index.js";
3
+ import { formatRecoveryCode, parseRecoveryCode } from "../shared/recovery-code.js";
4
+ import { InvalidArgumentError } from "commander";
5
+ import { timingSafeEqual } from "node:crypto";
6
+ import { UsageError } from "../errors.js";
7
+ import { keyValues, table } from "../format.js";
8
+ import { printActiveWorkspace } from "./workspace.js";
9
+ function parsePositiveInteger(value) {
10
+ const parsed = Number(value);
11
+ if (!Number.isSafeInteger(parsed) || parsed < 1) {
12
+ throw new InvalidArgumentError("expected a positive integer");
13
+ }
14
+ return parsed;
15
+ }
16
+ function parseConflictAction(value) {
17
+ if (value === "rebase" || value === "keep_both" || value === "discard")
18
+ return value;
19
+ throw new InvalidArgumentError("expected rebase, keep_both or discard");
20
+ }
21
+ function withCursor(text, cursor) {
22
+ return cursor === null ? text : `${text}\nnext cursor: ${cursor}`;
23
+ }
24
+ function mappingRows(items) {
25
+ return items.map((mapping) => [
26
+ mapping.local_profile_id,
27
+ mapping.profile_id,
28
+ mapping.state,
29
+ mapping.dirty,
30
+ mapping.head_revision_no,
31
+ mapping.key_version,
32
+ mapping.folder_id,
33
+ mapping.last_error_code,
34
+ ]);
35
+ }
36
+ function mappingTable(items) {
37
+ return table(["local", "remote", "state", "dirty", "revision", "key", "folder", "error"], mappingRows(items));
38
+ }
39
+ function mappingText(mapping) {
40
+ return keyValues([
41
+ ["local profile", mapping.local_profile_id],
42
+ ["remote profile", mapping.profile_id],
43
+ ["workspace", mapping.workspace_id],
44
+ ["folder", mapping.folder_id],
45
+ ["state", mapping.state],
46
+ ["dirty", mapping.dirty],
47
+ ["head revision", mapping.head_revision_id],
48
+ ["revision number", mapping.head_revision_no],
49
+ ["key version", mapping.key_version],
50
+ ["change sequence", mapping.change_seq],
51
+ ["synced sequence", mapping.synced_change_seq],
52
+ ["last error", mapping.last_error_code],
53
+ ]);
54
+ }
55
+ function keyText(key) {
56
+ return keyValues([
57
+ ["workspace", key.workspace_id],
58
+ ["state", key.state],
59
+ ["active key version", key.active_key_version],
60
+ ["missing versions", key.missing_versions.length ? key.missing_versions.join(",") : null],
61
+ [
62
+ "unconfirmed versions",
63
+ key.unconfirmed_versions.length ? key.unconfirmed_versions.join(",") : null,
64
+ ],
65
+ ]);
66
+ }
67
+ function statusText(status) {
68
+ const summary = keyValues([
69
+ ["workspace", status.workspace_id],
70
+ ["mode", status.mode],
71
+ ["key state", status.key.state],
72
+ ["active key version", status.key.active_key_version],
73
+ ["profiles", status.profiles.length],
74
+ ]);
75
+ return `${summary}\n\n${mappingTable(status.profiles)}`;
76
+ }
77
+ function remoteRows(items) {
78
+ return items.map((profile) => [
79
+ profile.profile_id,
80
+ profile.name,
81
+ profile.folder_id,
82
+ profile.metadata_version,
83
+ profile.current_revision?.revision_no ?? null,
84
+ profile.current_revision?.key_version ?? null,
85
+ profile.lease?.device_label ?? null,
86
+ ]);
87
+ }
88
+ const HEADLESS_VAULT_WARNING = "Warning: standalone/headless sync protects its vault key with a mode-0600 file, not the OS keychain.";
89
+ async function readRecoveryCode(terminal, question) {
90
+ const input = await terminal.readSecret(question);
91
+ try {
92
+ return parseRecoveryCode(input.toString("ascii"));
93
+ }
94
+ catch (error) {
95
+ throw new UsageError(error.message);
96
+ }
97
+ finally {
98
+ input.fill(0);
99
+ }
100
+ }
101
+ async function readConfirmedRecoveryCode(terminal, firstQuestion, confirmationQuestion) {
102
+ const first = await readRecoveryCode(terminal, firstQuestion);
103
+ try {
104
+ const confirmation = await readRecoveryCode(terminal, confirmationQuestion);
105
+ try {
106
+ if (!timingSafeEqual(first, confirmation)) {
107
+ throw new UsageError("recovery code confirmation does not match");
108
+ }
109
+ return first;
110
+ }
111
+ finally {
112
+ confirmation.fill(0);
113
+ }
114
+ }
115
+ catch (error) {
116
+ first.fill(0);
117
+ throw error;
118
+ }
119
+ }
120
+ function rejectSecretArgv(command) {
121
+ if (command.args.length > 0) {
122
+ throw new UsageError("secret values cannot be supplied on argv; use the hidden terminal prompt");
123
+ }
124
+ }
125
+ export function registerSync(program, ctx) {
126
+ const sync = program.command("sync").description("Encrypted profile sync and transfers");
127
+ sync.hook("preAction", async () => printActiveWorkspace(ctx));
128
+ sync
129
+ .command("status")
130
+ .description("Show local sync, key and profile state")
131
+ .action(async () => {
132
+ const result = unwrap(await ctx.client().GET("/v1/sync/status"));
133
+ ctx.emit(result, () => statusText(result));
134
+ });
135
+ const remote = sync.command("remote").description("Cloud profiles visible to this device");
136
+ remote
137
+ .command("list")
138
+ .alias("ls")
139
+ .description("List remote profiles")
140
+ .option("--cursor <cursor>", "continue an earlier listing")
141
+ .action(async (opts) => {
142
+ const result = unwrap(await ctx.client().GET("/v1/sync/profiles/remote", {
143
+ params: { query: opts.cursor === undefined ? {} : { cursor: opts.cursor } },
144
+ }));
145
+ ctx.emit(result, () => withCursor(table(["id", "name", "folder", "metadata", "revision", "key", "lease device"], remoteRows(result.items)), result.next_cursor));
146
+ });
147
+ remote
148
+ .command("materialize <profile>")
149
+ .description("Download a cloud-only profile into a new local profile")
150
+ .requiredOption("--revision <id>", "expected cloud revision UUID")
151
+ .option("--name <name>", "local profile name override")
152
+ .action(async (profile, opts) => {
153
+ const result = unwrap(await ctx.client().POST("/v1/sync/profiles/remote/{profile}/materialize", {
154
+ params: { path: { profile } },
155
+ body: {
156
+ expected_revision_id: opts.revision,
157
+ ...(opts.name === undefined ? {} : { local_name: opts.name }),
158
+ },
159
+ }));
160
+ ctx.emit(result, () => mappingText(result.mapping));
161
+ });
162
+ sync
163
+ .command("enroll <local>")
164
+ .description("Enroll a stopped local profile in workspace sync")
165
+ .option("--folder <id>", "destination team folder UUID")
166
+ .option("--indexeddb", "include IndexedDB in encrypted bundles")
167
+ .action(async (local, opts) => {
168
+ const result = unwrap(await ctx.client().POST("/v1/sync/profiles/{local}/enroll", {
169
+ params: { path: { local } },
170
+ body: { folder_id: opts.folder ?? null, sync_indexeddb: opts.indexeddb === true },
171
+ }));
172
+ ctx.emit(result, () => mappingText(result.mapping));
173
+ });
174
+ sync
175
+ .command("pull <local>")
176
+ .description("Pull the current remote revision without overwriting dirty state")
177
+ .option("--replace-held", "replace a stopped profile whose cookies are held, including its local changes, with the cloud copy")
178
+ .action(async (local, opts) => {
179
+ const result = unwrap(await ctx.client().POST("/v1/sync/profiles/{local}/pull", {
180
+ params: { path: { local } },
181
+ body: opts.replaceHeld ? { force: false, replace_held: true } : { force: false },
182
+ }));
183
+ ctx.emit(result, () => mappingText(result.mapping));
184
+ });
185
+ sync
186
+ .command("push <local>")
187
+ .description("Capture a stopped profile and queue an encrypted upload")
188
+ .option("--allow-empty-cookies", "upload even if the profile has no cookies but had some at the last sync")
189
+ .action(async (local, opts) => {
190
+ const result = unwrap(await ctx.client().POST("/v1/sync/profiles/{local}/push", {
191
+ params: { path: { local } },
192
+ body: opts.allowEmptyCookies ? { allow_cookie_drop: true } : {},
193
+ }));
194
+ ctx.emit(result, () => `${keyValues([
195
+ ["queue", result.queue_id],
196
+ ["captured sequence", result.captured_change_seq],
197
+ ])}\n${mappingText(result.mapping)}`);
198
+ });
199
+ sync
200
+ .command("disable <local>")
201
+ .description("Stop syncing locally, or permanently delete the remote profile")
202
+ .option("--permanent", "delete remote sync state and release its cloud claim")
203
+ .option("--metadata-version <n>", "expected metadata version (required with --permanent)", parsePositiveInteger)
204
+ .option("-y, --yes", "do not ask before permanent remote deletion")
205
+ .action(async (local, opts) => {
206
+ if (opts.permanent && opts.metadataVersion === undefined) {
207
+ throw new UsageError("--permanent requires --metadata-version <n>");
208
+ }
209
+ if (!opts.permanent && opts.metadataVersion !== undefined) {
210
+ throw new UsageError("--metadata-version is only valid with --permanent");
211
+ }
212
+ if (opts.permanent) {
213
+ await ctx.confirm(`permanently delete remote sync state for ${local}?`, opts.yes);
214
+ }
215
+ const result = unwrap(await ctx.client().POST("/v1/sync/profiles/{local}/disable", {
216
+ params: { path: { local } },
217
+ body: {
218
+ mode: opts.permanent ? "permanent_remote" : "local_only",
219
+ expected_metadata_version: opts.metadataVersion ?? null,
220
+ },
221
+ }));
222
+ ctx.emit(result, () => result.mapping === null ? `disabled sync for ${local}` : mappingText(result.mapping));
223
+ });
224
+ const conflicts = sync.command("conflicts").description("Preserved offline and CAS conflicts");
225
+ conflicts
226
+ .command("list")
227
+ .alias("ls")
228
+ .description("List unresolved local conflict copies")
229
+ .option("--cursor <cursor>", "continue an earlier listing")
230
+ .action(async (opts) => {
231
+ const result = unwrap(await ctx.client().GET("/v1/sync/conflicts", {
232
+ params: { query: opts.cursor === undefined ? {} : { cursor: opts.cursor } },
233
+ }));
234
+ ctx.emit(result, () => withCursor(table(["local", "source", "revision", "reason", "pending claim"], result.items.map((conflict) => [
235
+ conflict.local_profile_id,
236
+ conflict.source_profile_id,
237
+ conflict.source_revision_id,
238
+ conflict.reason,
239
+ conflict.pending_claim,
240
+ ])), result.next_cursor));
241
+ });
242
+ conflicts
243
+ .command("resolve")
244
+ .description("Resolve with rebase, keep_both or discard")
245
+ .argument("<local>", "local conflict profile UUID")
246
+ .argument("<action>", "rebase, keep_both or discard", parseConflictAction)
247
+ .option("--name <name>", "destination name for keep_both")
248
+ .option("-y, --yes", "do not ask before discard")
249
+ .action(async (local, action, opts) => {
250
+ if (action === "discard")
251
+ await ctx.confirm(`discard conflict copy ${local}?`, opts.yes);
252
+ if (action !== "keep_both" && opts.name !== undefined) {
253
+ throw new UsageError("--name is only valid with keep_both");
254
+ }
255
+ const result = unwrap(await ctx.client().POST("/v1/sync/conflicts/{local}/resolve", {
256
+ params: { path: { local } },
257
+ body: {
258
+ action,
259
+ ...(opts.name === undefined ? {} : { destination_name: opts.name }),
260
+ },
261
+ }));
262
+ ctx.emit(result, () => result.mapping === null
263
+ ? keyValues([
264
+ ["state", result.state],
265
+ ["mapping", null],
266
+ ])
267
+ : `${keyValues([["state", result.state]])}\n${mappingText(result.mapping)}`);
268
+ });
269
+ const recipients = sync.command("recipients").description("Workspace-key device recipients");
270
+ recipients
271
+ .command("list")
272
+ .alias("ls")
273
+ .description("List devices and key enrollment state")
274
+ .option("--cursor <cursor>", "continue an earlier listing")
275
+ .action(async (opts) => {
276
+ const result = unwrap(await ctx.client().GET("/v1/sync/keys/recipients", {
277
+ params: { query: opts.cursor === undefined ? {} : { cursor: opts.cursor } },
278
+ }));
279
+ ctx.emit(result, () => withCursor(table(["device", "state", "fingerprint"], result.items.map((recipient) => [
280
+ recipient.device_id,
281
+ recipient.key_state,
282
+ recipient.recipient_kx_fingerprint,
283
+ ])), result.next_cursor));
284
+ });
285
+ recipients
286
+ .command("enroll <device>")
287
+ .description("Seal all readable workspace keys to a pending device")
288
+ .action(async (device) => {
289
+ const result = unwrap(await ctx.client().POST("/v1/sync/keys/enroll", { body: { device_id: device } }));
290
+ ctx.emit(result, () => `key state: ${result.key_state}`);
291
+ });
292
+ recipients
293
+ .command("confirm")
294
+ .description("Unwrap and confirm this device's pending key envelopes")
295
+ .action(async () => {
296
+ const result = unwrap(await ctx.client().POST("/v1/sync/keys/confirm", { body: {} }));
297
+ ctx.emit(result, () => keyText(result.key));
298
+ });
299
+ const keys = sync.command("keys").description("CLI-only workspace recovery-key operations");
300
+ keys
301
+ .command("setup")
302
+ .description("Set up sync keys with a securely pre-saved recovery code")
303
+ .allowExcessArguments()
304
+ .action(async (_opts, command) => {
305
+ rejectSecretArgv(command);
306
+ const result = await ctx.withNativeTerminal("sync key setup", async (terminal) => {
307
+ terminal.writeLine(HEADLESS_VAULT_WARNING);
308
+ terminal.writeLine("Enter a recovery code that you have already stored securely.");
309
+ const raw = await readConfirmedRecoveryCode(terminal, "Recovery code: ", "Confirm recovery code: ");
310
+ try {
311
+ return unwrap(await ctx.client().POST("/v1/sync/keys/setup", {
312
+ body: { recovery_code: formatRecoveryCode(raw) },
313
+ }));
314
+ }
315
+ finally {
316
+ raw.fill(0);
317
+ }
318
+ });
319
+ ctx.emit(result, () => keyText(result.key));
320
+ });
321
+ keys
322
+ .command("recover")
323
+ .description("Recover sync keys using a securely pre-saved replacement code")
324
+ .allowExcessArguments()
325
+ .action(async (_opts, command) => {
326
+ rejectSecretArgv(command);
327
+ const result = await ctx.withNativeTerminal("sync key recovery", async (terminal) => {
328
+ terminal.writeLine(HEADLESS_VAULT_WARNING);
329
+ terminal.writeLine("Enter a replacement code that you have already stored securely.");
330
+ const current = await readRecoveryCode(terminal, "Current recovery code: ");
331
+ let replacement;
332
+ try {
333
+ replacement = await readConfirmedRecoveryCode(terminal, "Replacement recovery code: ", "Confirm replacement recovery code: ");
334
+ if (timingSafeEqual(current, replacement)) {
335
+ throw new UsageError("replacement recovery code must differ from the current code");
336
+ }
337
+ return unwrap(await ctx.client().POST("/v1/sync/keys/recover", {
338
+ body: {
339
+ recovery_code: formatRecoveryCode(current),
340
+ replacement_recovery_code: formatRecoveryCode(replacement),
341
+ },
342
+ }));
343
+ }
344
+ finally {
345
+ current.fill(0);
346
+ replacement?.fill(0);
347
+ }
348
+ });
349
+ ctx.emit(result, () => keyText(result.key));
350
+ });
351
+ keys
352
+ .command("lock")
353
+ .description("Zeroize and lock workspace keys held by the daemon")
354
+ .action(async () => {
355
+ unwrap(await ctx.client().POST("/v1/sync/keys/lock", { body: {} }));
356
+ ctx.emit(undefined, () => "sync keys locked");
357
+ });
358
+ const transfer = sync.command("transfer").description("Cross-workspace profile transfer");
359
+ transfer
360
+ .command("list")
361
+ .alias("ls")
362
+ .description("List authorized cross-workspace profile transfers")
363
+ .option("--cursor <cursor>", "continue an earlier listing")
364
+ .action(async (opts) => {
365
+ const result = unwrap(await ctx.client().GET("/v1/sync/transfers", {
366
+ params: { query: opts.cursor === undefined ? {} : { cursor: opts.cursor } },
367
+ }));
368
+ ctx.emit(result, () => withCursor(table(["id", "direction", "state", "source", "destination", "profile", "name", "expires"], result.items.map((item) => [
369
+ item.transfer_id,
370
+ item.direction,
371
+ item.state,
372
+ item.source_workspace_id,
373
+ item.destination_workspace_id,
374
+ item.source_profile_id,
375
+ item.destination_name,
376
+ item.expires_at,
377
+ ])), result.next_cursor));
378
+ });
379
+ transfer
380
+ .command("start <local> <workspace> <name>")
381
+ .description("Start an encrypted transfer of a local synced profile")
382
+ .option("--folder <id>", "destination folder UUID")
383
+ .action(async (local, workspace, name, opts) => {
384
+ const result = unwrap(await ctx.client().POST("/v1/sync/transfers", {
385
+ body: {
386
+ local_profile_id: local,
387
+ destination_workspace_id: workspace,
388
+ destination_folder_id: opts.folder ?? null,
389
+ destination_name: name,
390
+ },
391
+ }));
392
+ ctx.emit(result, () => keyValues([
393
+ ["transfer", result.transfer_id],
394
+ ["state", result.state],
395
+ ]));
396
+ });
397
+ transfer
398
+ .command("status <transfer>")
399
+ .description("Show durable profile-transfer state")
400
+ .action(async (transferId) => {
401
+ const result = unwrap(await ctx.client().GET("/v1/sync/transfers/{transfer}", {
402
+ params: { path: { transfer: transferId } },
403
+ }));
404
+ ctx.emit(result, () => keyValues([
405
+ ["transfer", result.transfer_id],
406
+ ["state", result.state],
407
+ ["error", result.error_code],
408
+ ]));
409
+ });
410
+ transfer
411
+ .command("accept <transfer>")
412
+ .description("Move a ready profile into its destination workspace")
413
+ .option("-y, --yes", "confirm the move and source deletion")
414
+ .action(async (transferId, opts) => {
415
+ await ctx.confirm(`accept profile transfer ${transferId}? This moves the profile and deletes its source cloud copy`, opts.yes);
416
+ const result = unwrap(await ctx.client().POST("/v1/sync/transfers/{transfer}/accept", {
417
+ params: { path: { transfer: transferId } },
418
+ body: {},
419
+ }));
420
+ ctx.emit(result, () => mappingText(result.mapping));
421
+ });
422
+ transfer
423
+ .command("abort <transfer>")
424
+ .description("Abort a pending or ready profile transfer")
425
+ .option("-y, --yes", "do not ask for confirmation")
426
+ .action(async (transferId, opts) => {
427
+ await ctx.confirm(`abort profile transfer ${transferId}?`, opts.yes);
428
+ unwrap(await ctx.client().POST("/v1/sync/transfers/{transfer}/abort", {
429
+ params: { path: { transfer: transferId } },
430
+ body: {},
431
+ }));
432
+ ctx.emit(undefined, () => `aborted transfer ${transferId}`);
433
+ });
434
+ }
435
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1,7 @@
1
+ import { type Command } from "commander";
2
+ import type { Context } from "../context.js";
3
+ export declare function parseIdempotencyKey(value: string): string;
4
+ /** Stable UUID with the same RFC 4122 version/variant normalization as daemon operation IDs. */
5
+ export declare function deriveOwnershipAcceptanceIdempotencyKey(token: Uint8Array): string;
6
+ export declare function registerTeam(program: Command, ctx: Context): void;
7
+ //# sourceMappingURL=team.d.ts.map