@anythingai/cli 0.1.3 → 0.1.5

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/dist/js/bin.mjs CHANGED
@@ -3068,83 +3068,423 @@ function errorCodeFromHttpStatus(status) {
3068
3068
  }
3069
3069
 
3070
3070
  //#endregion
3071
- //#region package.json
3072
- var version = "0.1.3";
3071
+ //#region src/output.ts
3072
+ function printJson(data) {
3073
+ console.log(JSON.stringify(data, null, 2));
3074
+ }
3075
+ function buildLogsToLines(buildLogs) {
3076
+ const lines = buildLogs.split("\n");
3077
+ if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
3078
+ return lines;
3079
+ }
3080
+ function printSuccess(message) {
3081
+ console.log(styleText("green", message));
3082
+ }
3083
+ function printError(message) {
3084
+ console.error(styleText("red", message));
3085
+ }
3086
+ function printLabel(label, value) {
3087
+ const displayValue = value ?? styleText("dim", "(none)");
3088
+ console.log(` ${styleText("bold", label)}: ${displayValue}`);
3089
+ }
3090
+ function formatDeploymentSummary(deployment) {
3091
+ return `${deployment.status}${deployment.url ? ` — ${deployment.url}` : ""}`;
3092
+ }
3093
+ function printTable({ headers, rows }) {
3094
+ const widths = headers.map((h, i) => Math.max(h.length, ...rows.map((r) => (r[i] ?? "").length)));
3095
+ const headerLine = headers.map((h, i) => h.padEnd(widths[i] ?? 0)).join(" ");
3096
+ console.log(styleText("bold", headerLine));
3097
+ console.log(widths.map((w) => "─".repeat(w)).join("──"));
3098
+ for (const row of rows) console.log(row.map((cell, i) => cell.padEnd(widths[i] ?? 0)).join(" "));
3099
+ }
3100
+ const DetailsWithErrorSchema = z.object({ error: z.string() });
3101
+ const DetailsWithErrorsSchema = z.object({ errors: z.array(z.union([z.string(), z.object({ message: z.string() })])) });
3102
+ function printApiError(error) {
3103
+ printError(error.message);
3104
+ const withError = DetailsWithErrorSchema.safeParse(error.details);
3105
+ if (withError.success && withError.data.error !== error.message) console.error(` ${withError.data.error}`);
3106
+ const withErrors = DetailsWithErrorsSchema.safeParse(error.details);
3107
+ if (withErrors.success) for (const e of withErrors.data.errors) console.error(` ${typeof e === "string" ? e : e.message}`);
3108
+ }
3109
+ function outputSuccess({ argv, command, data, primaryId, startTime }) {
3110
+ if (argv.json) {
3111
+ const envelope = {
3112
+ ok: true,
3113
+ command,
3114
+ data
3115
+ };
3116
+ if (startTime !== void 0) envelope["meta"] = { duration_ms: Math.round(performance.now() - startTime) };
3117
+ console.log(JSON.stringify(envelope, null, 2));
3118
+ return true;
3119
+ }
3120
+ if (argv.quiet) {
3121
+ if (primaryId) console.log(primaryId);
3122
+ return true;
3123
+ }
3124
+ return false;
3125
+ }
3126
+ const DetailsWithCodeSchema = z.object({ code: z.string() });
3127
+ function extractErrorCode(details) {
3128
+ const parsed = DetailsWithCodeSchema.safeParse(details);
3129
+ return parsed.success ? parsed.data.code : null;
3130
+ }
3131
+ function resolveErrorCode({ error, exitCode, codeOverride }) {
3132
+ const status = "status" in error ? error.status ?? null : null;
3133
+ const details = "details" in error ? error.details : void 0;
3134
+ return codeOverride ?? extractErrorCode(details) ?? (status === null && exitCode !== void 0 ? errorCodeFromExitCode(exitCode) : errorCodeFromHttpStatus(status));
3135
+ }
3136
+ function outputStreamError({ argv, command, error, hint, exitCode, buildLogs, code: codeOverride }) {
3137
+ if (!argv.json && !argv.quiet) {
3138
+ outputError({
3139
+ argv,
3140
+ command,
3141
+ error,
3142
+ hint,
3143
+ exitCode,
3144
+ buildLogs,
3145
+ code: codeOverride
3146
+ });
3147
+ return;
3148
+ }
3149
+ const status = "status" in error ? error.status ?? null : null;
3150
+ process.exitCode = exitCode ?? exitCodeFromHttpStatus(status);
3151
+ const code = resolveErrorCode({
3152
+ error,
3153
+ exitCode,
3154
+ codeOverride
3155
+ });
3156
+ const retryAfter = "retryAfter" in error && typeof error.retryAfter === "number" ? error.retryAfter : null;
3157
+ const resolvedHint = hint ?? ("hint" in error && typeof error.hint === "string" ? error.hint : void 0);
3158
+ printNdjson({
3159
+ type: "result",
3160
+ ok: false,
3161
+ error: {
3162
+ code,
3163
+ message: error.message,
3164
+ ...resolvedHint ? { hint: resolvedHint } : {},
3165
+ ...retryAfter !== null ? { retry_after_seconds: retryAfter } : {},
3166
+ ...buildLogs ? { buildLogs: buildLogsToLines(buildLogs) } : {}
3167
+ }
3168
+ });
3169
+ }
3170
+ function outputError({ argv, command, error, hint, exitCode, buildLogs, code: codeOverride }) {
3171
+ const status = "status" in error ? error.status ?? null : null;
3172
+ const details = "details" in error ? error.details : void 0;
3173
+ const retryAfter = "retryAfter" in error && typeof error.retryAfter === "number" ? error.retryAfter : null;
3174
+ const resolvedHint = hint ?? ("hint" in error && typeof error.hint === "string" ? error.hint : void 0);
3175
+ process.exitCode = exitCode ?? exitCodeFromHttpStatus(status);
3176
+ const code = resolveErrorCode({
3177
+ error,
3178
+ exitCode,
3179
+ codeOverride
3180
+ });
3181
+ if (argv.json || argv.quiet) {
3182
+ console.log(JSON.stringify({
3183
+ ok: false,
3184
+ command,
3185
+ error: {
3186
+ code,
3187
+ message: error.message,
3188
+ ...resolvedHint ? { hint: resolvedHint } : {},
3189
+ ...retryAfter !== null ? { retry_after_seconds: retryAfter } : {},
3190
+ ...buildLogs ? { buildLogs: buildLogsToLines(buildLogs) } : {}
3191
+ }
3192
+ }, null, 2));
3193
+ return;
3194
+ }
3195
+ printApiError({
3196
+ message: error.message,
3197
+ status: error.status,
3198
+ details
3199
+ });
3200
+ if (retryAfter !== null) console.error(` ${styleText("dim", `Retry after ${retryAfter}s`)}`);
3201
+ if (resolvedHint) console.error(` ${styleText("dim", resolvedHint)}`);
3202
+ if (buildLogs) console.error(`\n${styleText("dim", "Build logs:")}\n${buildLogs}`);
3203
+ }
3204
+ function outputValidationError({ argv, command, message, hint }) {
3205
+ outputError({
3206
+ argv,
3207
+ command,
3208
+ error: {
3209
+ message,
3210
+ status: 400
3211
+ },
3212
+ hint,
3213
+ exitCode: 2
3214
+ });
3215
+ }
3216
+ function outputDryRun({ argv, command, plannedActions }) {
3217
+ if (argv.json) {
3218
+ console.log(JSON.stringify({
3219
+ ok: true,
3220
+ command,
3221
+ dry_run: true,
3222
+ planned_actions: plannedActions
3223
+ }, null, 2));
3224
+ return;
3225
+ }
3226
+ if (argv.quiet) return;
3227
+ printSuccess("Dry run — no changes made.");
3228
+ for (const action of plannedActions) {
3229
+ printLabel("Action", action.action);
3230
+ for (const [key, value] of Object.entries(action)) {
3231
+ if (key === "action") continue;
3232
+ printLabel(` ${key}`, String(value));
3233
+ }
3234
+ }
3235
+ }
3236
+ function printNdjson(event) {
3237
+ console.log(JSON.stringify(event));
3238
+ }
3239
+ function printStreamMarker(marker, message) {
3240
+ console.log(`[${marker}] ${message}`);
3241
+ }
3242
+ function emitActionRequired({ command, message, requiredInput }) {
3243
+ console.error(JSON.stringify({
3244
+ type: "ActionRequired",
3245
+ command,
3246
+ message,
3247
+ requiredInput
3248
+ }));
3249
+ }
3073
3250
 
3074
3251
  //#endregion
3075
- //#region generated/core/bodySerializer.gen.ts
3076
- const serializeFormDataPair = (data, key, value) => {
3077
- if (typeof value === "string" || value instanceof Blob) data.append(key, value);
3078
- else if (value instanceof Date) data.append(key, value.toISOString());
3079
- else data.append(key, JSON.stringify(value));
3252
+ //#region src/commands/dev.ts
3253
+ const COMMAND$27 = "dev";
3254
+ const devCommand = {
3255
+ command: "dev [state]",
3256
+ describe: "Toggle local dev mode so commands target your local dev stack",
3257
+ builder: (yargs) => yargs.positional("state", {
3258
+ choices: [
3259
+ "on",
3260
+ "off",
3261
+ "status"
3262
+ ],
3263
+ default: "status",
3264
+ describe: "Turn dev mode on/off, or show the current state"
3265
+ }).example("anything dev on", "Point every command at your local dev stack").example("anything dev off", "Switch back to production").example("anything dev", "Show whether dev mode is on"),
3266
+ handler: (argv) => {
3267
+ if (argv.state === "on") setDevMode(true);
3268
+ else if (argv.state === "off") setDevMode(false);
3269
+ const enabled = getDevMode();
3270
+ const apiUrl = resolveApiUrl({ apiUrl: argv.apiUrl });
3271
+ if (outputSuccess({
3272
+ argv,
3273
+ command: COMMAND$27,
3274
+ data: {
3275
+ devMode: enabled,
3276
+ apiUrl
3277
+ }
3278
+ })) return;
3279
+ printSuccess(`Dev mode ${enabled ? "ON" : "OFF"}`);
3280
+ printLabel("API URL", apiUrl);
3281
+ if (enabled) printLabel("Note", "Dev mode uses a separate login — run `anything auth login` to authenticate against local dev.");
3282
+ }
3080
3283
  };
3081
- const formDataBodySerializer = { bodySerializer: (body) => {
3082
- const data = new FormData();
3083
- Object.entries(body).forEach(([key, value]) => {
3084
- if (value === void 0 || value === null) return;
3085
- if (Array.isArray(value)) value.forEach((v) => serializeFormDataPair(data, key, v));
3086
- else serializeFormDataPair(data, key, value);
3087
- });
3088
- return data;
3089
- } };
3090
- const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
3091
3284
 
3092
3285
  //#endregion
3093
- //#region generated/core/params.gen.ts
3094
- const extraPrefixes = Object.entries({
3095
- $body_: "body",
3096
- $headers_: "headers",
3097
- $path_: "path",
3098
- $query_: "query"
3099
- });
3286
+ //#region package.json
3287
+ var version = "0.1.5";
3100
3288
 
3101
3289
  //#endregion
3102
- //#region generated/core/serverSentEvents.gen.ts
3103
- const createSseClient = ({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) => {
3104
- let lastEventId;
3105
- const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
3106
- const createStream = async function* () {
3107
- let retryDelay = sseDefaultRetryDelay ?? 3e3;
3108
- let attempt = 0;
3109
- const signal = options.signal ?? new AbortController().signal;
3110
- while (true) {
3111
- if (signal.aborted) break;
3112
- attempt++;
3113
- const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
3114
- if (lastEventId !== void 0) headers.set("Last-Event-ID", lastEventId);
3115
- try {
3116
- const requestInit = {
3117
- redirect: "follow",
3118
- ...options,
3119
- body: options.serializedBody,
3120
- headers,
3121
- signal
3122
- };
3123
- let request = new Request(url, requestInit);
3124
- if (onRequest) request = await onRequest(url, requestInit);
3125
- const response = await (options.fetch ?? globalThis.fetch)(request);
3126
- if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
3127
- if (!response.body) throw new Error("No body in SSE response");
3128
- const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
3129
- let buffer = "";
3130
- const abortHandler = () => {
3131
- try {
3132
- reader.cancel();
3133
- } catch {}
3134
- };
3135
- signal.addEventListener("abort", abortHandler);
3136
- try {
3137
- while (true) {
3138
- const { done, value } = await reader.read();
3139
- if (done) break;
3140
- buffer += value;
3141
- const chunks = buffer.split("\n\n");
3142
- buffer = chunks.pop() ?? "";
3143
- for (const chunk of chunks) {
3144
- const lines = chunk.split("\n");
3145
- const dataLines = [];
3146
- let eventName;
3147
- for (const line of lines) if (line.startsWith("data:")) dataLines.push(line.replace(/^data:\s*/, ""));
3290
+ //#region src/version.ts
3291
+ const CLI_VERSION = version;
3292
+
3293
+ //#endregion
3294
+ //#region src/types.ts
3295
+ function isNonInteractive(argv) {
3296
+ if (argv["non-interactive"]) return true;
3297
+ const env = process.env;
3298
+ return !!(env["CLAUDECODE"] || env["CODEX"] || env["CI"] || env["OPENCLAW"]);
3299
+ }
3300
+
3301
+ //#endregion
3302
+ //#region src/update-check.ts
3303
+ const PACKAGE_NAME = "@anythingai/cli";
3304
+ const REGISTRY_BASE_URL = `https://registry.npmjs.org/${PACKAGE_NAME}`;
3305
+ const REGISTRY_URL = `${REGISTRY_BASE_URL}/latest`;
3306
+ const INTERNAL_UPDATE_CHECK_ARG = "__update-check";
3307
+ const CHECK_INTERVAL_MS = 10800 * 1e3;
3308
+ const REFRESH_FETCH_TIMEOUT_MS = 1e4;
3309
+ const latestManifestSchema = z.object({ version: z.string() });
3310
+ function isNewerVersion(candidate, current) {
3311
+ const core = (v) => (v.split("-")[0] ?? "").split(".").map((part) => Number.parseInt(part, 10));
3312
+ const a = core(candidate);
3313
+ const b = core(current);
3314
+ if ([...a, ...b].some(Number.isNaN)) return false;
3315
+ for (let i = 0; i < 3; i++) {
3316
+ const left = a[i] ?? 0;
3317
+ const right = b[i] ?? 0;
3318
+ if (left !== right) return left > right;
3319
+ }
3320
+ return false;
3321
+ }
3322
+ async function fetchLatestVersion({ timeoutMs }) {
3323
+ try {
3324
+ const response = await fetch(REGISTRY_URL, {
3325
+ signal: AbortSignal.timeout(timeoutMs),
3326
+ headers: { accept: "application/json" }
3327
+ });
3328
+ if (!response.ok) return null;
3329
+ const parsed = latestManifestSchema.safeParse(await response.json());
3330
+ return parsed.success ? parsed.data.version : null;
3331
+ } catch {
3332
+ return null;
3333
+ }
3334
+ }
3335
+ async function lookupVersion({ version, timeoutMs }) {
3336
+ try {
3337
+ const response = await fetch(`${REGISTRY_BASE_URL}/${encodeURIComponent(version)}`, {
3338
+ signal: AbortSignal.timeout(timeoutMs),
3339
+ headers: { accept: "application/json" }
3340
+ });
3341
+ if (response.status === 404) return { status: "not-found" };
3342
+ if (!response.ok) return { status: "unreachable" };
3343
+ return latestManifestSchema.safeParse(await response.json()).success ? { status: "exists" } : { status: "not-found" };
3344
+ } catch {
3345
+ return { status: "unreachable" };
3346
+ }
3347
+ }
3348
+ function printUpdateNotice({ current, latest }) {
3349
+ console.error([
3350
+ "",
3351
+ styleText("yellow", `Update available for ${PACKAGE_NAME}: ${current} → ${latest}`),
3352
+ styleText("dim", "Run `anything update` to update."),
3353
+ ""
3354
+ ].join("\n"));
3355
+ }
3356
+ function spawnBackgroundRefresh() {
3357
+ const entry = process.argv[1];
3358
+ if (!entry) return;
3359
+ try {
3360
+ spawn(process.execPath, [entry, INTERNAL_UPDATE_CHECK_ARG], {
3361
+ detached: true,
3362
+ stdio: "ignore",
3363
+ windowsHide: true,
3364
+ env: backgroundRefreshEnv()
3365
+ }).unref();
3366
+ } catch {}
3367
+ }
3368
+ function backgroundRefreshEnv() {
3369
+ const allowed = [
3370
+ "PATH",
3371
+ "HOME",
3372
+ "XDG_CONFIG_HOME",
3373
+ "APPDATA",
3374
+ "LOCALAPPDATA",
3375
+ "SystemRoot"
3376
+ ];
3377
+ const env = {};
3378
+ for (const key of allowed) {
3379
+ const value = process.env[key];
3380
+ if (value !== void 0) env[key] = value;
3381
+ }
3382
+ return env;
3383
+ }
3384
+ async function refreshUpdateCheckCache(now) {
3385
+ recordUpdateCheck({
3386
+ checkedAt: now,
3387
+ latestVersion: await fetchLatestVersion({ timeoutMs: REFRESH_FETCH_TIMEOUT_MS })
3388
+ });
3389
+ }
3390
+ function notifyIfUpdateAvailable(now) {
3391
+ const state = getUpdateCheckState();
3392
+ const latest = state.latestKnownVersion;
3393
+ if (latest && isNewerVersion(latest, CLI_VERSION) && state.notifiedVersion !== latest) {
3394
+ printUpdateNotice({
3395
+ current: CLI_VERSION,
3396
+ latest
3397
+ });
3398
+ recordUpdateNotified(latest);
3399
+ }
3400
+ if (!(state.checkedAt === null || now - state.checkedAt >= CHECK_INTERVAL_MS)) return;
3401
+ recordUpdateCheck({
3402
+ checkedAt: now,
3403
+ latestVersion: null
3404
+ });
3405
+ spawnBackgroundRefresh();
3406
+ }
3407
+ function maybeNotifyUpdate(argv, now) {
3408
+ if (argv.json || argv.quiet) return;
3409
+ if (isNonInteractive(argv)) return;
3410
+ if (!process.stderr.isTTY) return;
3411
+ notifyIfUpdateAvailable(now);
3412
+ }
3413
+
3414
+ //#endregion
3415
+ //#region generated/core/bodySerializer.gen.ts
3416
+ const serializeFormDataPair = (data, key, value) => {
3417
+ if (typeof value === "string" || value instanceof Blob) data.append(key, value);
3418
+ else if (value instanceof Date) data.append(key, value.toISOString());
3419
+ else data.append(key, JSON.stringify(value));
3420
+ };
3421
+ const formDataBodySerializer = { bodySerializer: (body) => {
3422
+ const data = new FormData();
3423
+ Object.entries(body).forEach(([key, value]) => {
3424
+ if (value === void 0 || value === null) return;
3425
+ if (Array.isArray(value)) value.forEach((v) => serializeFormDataPair(data, key, v));
3426
+ else serializeFormDataPair(data, key, value);
3427
+ });
3428
+ return data;
3429
+ } };
3430
+ const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
3431
+
3432
+ //#endregion
3433
+ //#region generated/core/params.gen.ts
3434
+ const extraPrefixes = Object.entries({
3435
+ $body_: "body",
3436
+ $headers_: "headers",
3437
+ $path_: "path",
3438
+ $query_: "query"
3439
+ });
3440
+
3441
+ //#endregion
3442
+ //#region generated/core/serverSentEvents.gen.ts
3443
+ const createSseClient = ({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) => {
3444
+ let lastEventId;
3445
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
3446
+ const createStream = async function* () {
3447
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
3448
+ let attempt = 0;
3449
+ const signal = options.signal ?? new AbortController().signal;
3450
+ while (true) {
3451
+ if (signal.aborted) break;
3452
+ attempt++;
3453
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
3454
+ if (lastEventId !== void 0) headers.set("Last-Event-ID", lastEventId);
3455
+ try {
3456
+ const requestInit = {
3457
+ redirect: "follow",
3458
+ ...options,
3459
+ body: options.serializedBody,
3460
+ headers,
3461
+ signal
3462
+ };
3463
+ let request = new Request(url, requestInit);
3464
+ if (onRequest) request = await onRequest(url, requestInit);
3465
+ const response = await (options.fetch ?? globalThis.fetch)(request);
3466
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
3467
+ if (!response.body) throw new Error("No body in SSE response");
3468
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
3469
+ let buffer = "";
3470
+ const abortHandler = () => {
3471
+ try {
3472
+ reader.cancel();
3473
+ } catch {}
3474
+ };
3475
+ signal.addEventListener("abort", abortHandler);
3476
+ try {
3477
+ while (true) {
3478
+ const { done, value } = await reader.read();
3479
+ if (done) break;
3480
+ buffer += value;
3481
+ const chunks = buffer.split("\n\n");
3482
+ buffer = chunks.pop() ?? "";
3483
+ for (const chunk of chunks) {
3484
+ const lines = chunk.split("\n");
3485
+ const dataLines = [];
3486
+ let eventName;
3487
+ for (const line of lines) if (line.startsWith("data:")) dataLines.push(line.replace(/^data:\s*/, ""));
3148
3488
  else if (line.startsWith("event:")) eventName = line.replace(/^event:\s*/, "");
3149
3489
  else if (line.startsWith("id:")) lastEventId = line.replace(/^id:\s*/, "");
3150
3490
  else if (line.startsWith("retry:")) {
@@ -4576,13 +4916,19 @@ var AnythingApiClient = class {
4576
4916
  }));
4577
4917
  }
4578
4918
  async listProjectFiles({ projectGroupId }) {
4579
- return this.toResult(await getV0ApiProjectsByProjectGroupIdFiles({
4580
- client: this.client,
4581
- path: { projectGroupId }
4582
- })).andThen((data) => "files" in data ? ok(data) : err({
4583
- message: "Unexpected API response format",
4584
- status: 200
4585
- }));
4919
+ const fetchOnce = async () => {
4920
+ return this.toResult(await getV0ApiProjectsByProjectGroupIdFiles({
4921
+ client: this.client,
4922
+ path: { projectGroupId }
4923
+ })).andThen((data) => "files" in data ? ok({ files: data.files ?? [] }) : err({
4924
+ message: "Unexpected API response format",
4925
+ status: 200
4926
+ }));
4927
+ };
4928
+ const first = await fetchOnce();
4929
+ if (first.isErr() || first.value.files.length > 0) return first;
4930
+ await new Promise((resolve) => setTimeout(resolve, 750));
4931
+ return fetchOnce();
4586
4932
  }
4587
4933
  async getProjectFile({ projectGroupId, path }) {
4588
4934
  return this.toResult(await getV0ApiProjectsByProjectGroupIdFiles({
@@ -4847,141 +5193,6 @@ var AnythingApiClient = class {
4847
5193
  }
4848
5194
  };
4849
5195
 
4850
- //#endregion
4851
- //#region src/output.ts
4852
- function printJson(data) {
4853
- console.log(JSON.stringify(data, null, 2));
4854
- }
4855
- function buildLogsToLines(buildLogs) {
4856
- const lines = buildLogs.split("\n");
4857
- if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
4858
- return lines;
4859
- }
4860
- function printSuccess(message) {
4861
- console.log(styleText("green", message));
4862
- }
4863
- function printError(message) {
4864
- console.error(styleText("red", message));
4865
- }
4866
- function printLabel(label, value) {
4867
- const displayValue = value ?? styleText("dim", "(none)");
4868
- console.log(` ${styleText("bold", label)}: ${displayValue}`);
4869
- }
4870
- function printTable({ headers, rows }) {
4871
- const widths = headers.map((h, i) => Math.max(h.length, ...rows.map((r) => (r[i] ?? "").length)));
4872
- const headerLine = headers.map((h, i) => h.padEnd(widths[i] ?? 0)).join(" ");
4873
- console.log(styleText("bold", headerLine));
4874
- console.log(widths.map((w) => "─".repeat(w)).join("──"));
4875
- for (const row of rows) console.log(row.map((cell, i) => cell.padEnd(widths[i] ?? 0)).join(" "));
4876
- }
4877
- const DetailsWithErrorSchema = z.object({ error: z.string() });
4878
- const DetailsWithErrorsSchema = z.object({ errors: z.array(z.union([z.string(), z.object({ message: z.string() })])) });
4879
- function printApiError(error) {
4880
- printError(error.message);
4881
- const withError = DetailsWithErrorSchema.safeParse(error.details);
4882
- if (withError.success && withError.data.error !== error.message) console.error(` ${withError.data.error}`);
4883
- const withErrors = DetailsWithErrorsSchema.safeParse(error.details);
4884
- if (withErrors.success) for (const e of withErrors.data.errors) console.error(` ${typeof e === "string" ? e : e.message}`);
4885
- }
4886
- function outputSuccess({ argv, command, data, primaryId, startTime }) {
4887
- if (argv.json) {
4888
- const envelope = {
4889
- ok: true,
4890
- command,
4891
- data
4892
- };
4893
- if (startTime !== void 0) envelope["meta"] = { duration_ms: Math.round(performance.now() - startTime) };
4894
- console.log(JSON.stringify(envelope, null, 2));
4895
- return true;
4896
- }
4897
- if (argv.quiet) {
4898
- if (primaryId) console.log(primaryId);
4899
- return true;
4900
- }
4901
- return false;
4902
- }
4903
- const DetailsWithCodeSchema = z.object({ code: z.string() });
4904
- function extractErrorCode(details) {
4905
- const parsed = DetailsWithCodeSchema.safeParse(details);
4906
- return parsed.success ? parsed.data.code : null;
4907
- }
4908
- function outputError({ argv, command, error, hint, exitCode, buildLogs, code: codeOverride }) {
4909
- const status = "status" in error ? error.status ?? null : null;
4910
- const details = "details" in error ? error.details : void 0;
4911
- const retryAfter = "retryAfter" in error && typeof error.retryAfter === "number" ? error.retryAfter : null;
4912
- const resolvedHint = hint ?? ("hint" in error && typeof error.hint === "string" ? error.hint : void 0);
4913
- process.exitCode = exitCode ?? exitCodeFromHttpStatus(status);
4914
- const code = codeOverride ?? extractErrorCode(details) ?? (status === null && exitCode !== void 0 ? errorCodeFromExitCode(exitCode) : errorCodeFromHttpStatus(status));
4915
- if (argv.json || argv.quiet) {
4916
- console.log(JSON.stringify({
4917
- ok: false,
4918
- command,
4919
- error: {
4920
- code,
4921
- message: error.message,
4922
- ...resolvedHint ? { hint: resolvedHint } : {},
4923
- ...retryAfter !== null ? { retry_after_seconds: retryAfter } : {},
4924
- ...buildLogs ? { buildLogs: buildLogsToLines(buildLogs) } : {}
4925
- }
4926
- }, null, 2));
4927
- return;
4928
- }
4929
- printApiError({
4930
- message: error.message,
4931
- status: error.status,
4932
- details
4933
- });
4934
- if (retryAfter !== null) console.error(` ${styleText("dim", `Retry after ${retryAfter}s`)}`);
4935
- if (resolvedHint) console.error(` ${styleText("dim", resolvedHint)}`);
4936
- if (buildLogs) console.error(`\n${styleText("dim", "Build logs:")}\n${buildLogs}`);
4937
- }
4938
- function outputValidationError({ argv, command, message, hint }) {
4939
- outputError({
4940
- argv,
4941
- command,
4942
- error: {
4943
- message,
4944
- status: 400
4945
- },
4946
- hint,
4947
- exitCode: 2
4948
- });
4949
- }
4950
- function outputDryRun({ argv, command, plannedActions }) {
4951
- if (argv.json) {
4952
- console.log(JSON.stringify({
4953
- ok: true,
4954
- command,
4955
- dry_run: true,
4956
- planned_actions: plannedActions
4957
- }, null, 2));
4958
- return;
4959
- }
4960
- if (argv.quiet) return;
4961
- printSuccess("Dry run — no changes made.");
4962
- for (const action of plannedActions) {
4963
- printLabel("Action", action.action);
4964
- for (const [key, value] of Object.entries(action)) {
4965
- if (key === "action") continue;
4966
- printLabel(` ${key}`, String(value));
4967
- }
4968
- }
4969
- }
4970
- function printNdjson(event) {
4971
- console.log(JSON.stringify(event));
4972
- }
4973
- function printStreamMarker(marker, message) {
4974
- console.log(`[${marker}] ${message}`);
4975
- }
4976
- function emitActionRequired({ command, message, requiredInput }) {
4977
- console.error(JSON.stringify({
4978
- type: "ActionRequired",
4979
- command,
4980
- message,
4981
- requiredInput
4982
- }));
4983
- }
4984
-
4985
5196
  //#endregion
4986
5197
  //#region src/commands/assets.ts
4987
5198
  const ALLOWED_EXTENSIONS = new Set([
@@ -5243,40 +5454,6 @@ const assetsCommand = {
5243
5454
  handler: () => {}
5244
5455
  };
5245
5456
 
5246
- //#endregion
5247
- //#region src/commands/dev.ts
5248
- const COMMAND$27 = "dev";
5249
- const devCommand = {
5250
- command: "dev [state]",
5251
- describe: "Toggle local dev mode so commands target your local dev stack",
5252
- builder: (yargs) => yargs.positional("state", {
5253
- choices: [
5254
- "on",
5255
- "off",
5256
- "status"
5257
- ],
5258
- default: "status",
5259
- describe: "Turn dev mode on/off, or show the current state"
5260
- }).example("anything dev on", "Point every command at your local dev stack").example("anything dev off", "Switch back to production").example("anything dev", "Show whether dev mode is on"),
5261
- handler: (argv) => {
5262
- if (argv.state === "on") setDevMode(true);
5263
- else if (argv.state === "off") setDevMode(false);
5264
- const enabled = getDevMode();
5265
- const apiUrl = resolveApiUrl({ apiUrl: argv.apiUrl });
5266
- if (outputSuccess({
5267
- argv,
5268
- command: COMMAND$27,
5269
- data: {
5270
- devMode: enabled,
5271
- apiUrl
5272
- }
5273
- })) return;
5274
- printSuccess(`Dev mode ${enabled ? "ON" : "OFF"}`);
5275
- printLabel("API URL", apiUrl);
5276
- if (enabled) printLabel("Note", "Dev mode uses a separate login — run `anything auth login` to authenticate against local dev.");
5277
- }
5278
- };
5279
-
5280
5457
  //#endregion
5281
5458
  //#region src/input.ts
5282
5459
  async function readStdin() {
@@ -5323,14 +5500,6 @@ async function promptChoice({ message, choices, nonInteractive }) {
5323
5500
  return choices[index] ?? null;
5324
5501
  }
5325
5502
 
5326
- //#endregion
5327
- //#region src/types.ts
5328
- function isNonInteractive(argv) {
5329
- if (argv["non-interactive"]) return true;
5330
- const env = process.env;
5331
- return !!(env["CLAUDECODE"] || env["CODEX"] || env["CI"] || env["OPENCLAW"]);
5332
- }
5333
-
5334
5503
  //#endregion
5335
5504
  //#region src/commands/auth.ts
5336
5505
  const POLL_INTERVAL_MS$2 = 2e3;
@@ -5378,7 +5547,7 @@ async function selectAndSetOrg({ config, json, nonInteractive }) {
5378
5547
  return choice;
5379
5548
  }
5380
5549
  }
5381
- const recommended = orgs.find((org) => BigInt(org.creditBalance) > 0n) ?? orgs[0];
5550
+ const recommended = orgs.find((org) => org.creditsBalance > 0) ?? orgs[0];
5382
5551
  if (!recommended) return null;
5383
5552
  if (!json) {
5384
5553
  console.log();
@@ -6756,1400 +6925,223 @@ const domainAddCommand = {
6756
6925
  argv,
6757
6926
  command: COMMAND$19,
6758
6927
  data: toPublicDomain(result.value.domain),
6759
- primaryId: result.value.domain.domain
6760
- })) return;
6761
- printSuccess(`Domain added: ${result.value.domain.domain}`);
6762
- printLabel("ID", result.value.domain.id);
6763
- printLabel("Verified", String(result.value.domain.vercelVerified));
6764
- }
6765
- };
6766
-
6767
- //#endregion
6768
- //#region src/commands/domain-remove.ts
6769
- const COMMAND$18 = "domains remove";
6770
- const domainRemoveCommand = {
6771
- command: "remove <domainId>",
6772
- describe: "Remove a custom domain",
6773
- builder: (yargs) => yargs.positional("domainId", {
6774
- type: "string",
6775
- demandOption: true,
6776
- describe: "The domain ID to remove"
6777
- }).option("yes", {
6778
- type: "boolean",
6779
- default: false,
6780
- describe: "Skip confirmation"
6781
- }).example("anything domains remove dom_123 --yes", "Remove a domain"),
6782
- handler: async (argv) => {
6783
- const config = resolveConfig({
6784
- dev: argv.dev,
6785
- apiUrl: argv.apiUrl
6786
- });
6787
- if (config.isErr()) {
6788
- outputError({
6789
- argv,
6790
- command: COMMAND$18,
6791
- error: {
6792
- message: config.error.message,
6793
- status: null
6794
- },
6795
- exitCode: 4
6796
- });
6797
- return;
6798
- }
6799
- if (argv["dry-run"]) {
6800
- outputDryRun({
6801
- argv,
6802
- command: COMMAND$18,
6803
- plannedActions: [{
6804
- action: "remove_domain",
6805
- domainId: argv.domainId
6806
- }]
6807
- });
6808
- return;
6809
- }
6810
- if (!argv.yes) {
6811
- outputError({
6812
- argv,
6813
- command: COMMAND$18,
6814
- error: {
6815
- message: "Domain removal is destructive. Pass --yes to confirm.",
6816
- status: null
6817
- },
6818
- exitCode: 2,
6819
- code: "CONFIRMATION_REQUIRED"
6820
- });
6821
- return;
6822
- }
6823
- const result = await new AnythingApiClient(config.value).removeDomain({ domainId: argv.domainId });
6824
- if (result.isErr()) {
6825
- outputError({
6826
- argv,
6827
- command: COMMAND$18,
6828
- error: result.error
6829
- });
6830
- return;
6831
- }
6832
- if (outputSuccess({
6833
- argv,
6834
- command: COMMAND$18,
6835
- data: {
6836
- removed: true,
6837
- domainId: argv.domainId
6838
- }
6839
- })) return;
6840
- printSuccess(`Domain ${argv.domainId} removed.`);
6841
- }
6842
- };
6843
-
6844
- //#endregion
6845
- //#region src/commands/domain-verify.ts
6846
- const COMMAND$17 = "domains verify";
6847
- const domainVerifyCommand = {
6848
- command: "verify <domainId>",
6849
- describe: "Check DNS configuration for a custom domain",
6850
- builder: (yargs) => yargs.positional("domainId", {
6851
- type: "string",
6852
- demandOption: true,
6853
- describe: "The domain ID to verify"
6854
- }).example("anything domains verify dom_123", "Check DNS configuration status"),
6855
- handler: async (argv) => {
6856
- const config = resolveConfig({
6857
- dev: argv.dev,
6858
- apiUrl: argv.apiUrl
6859
- });
6860
- if (config.isErr()) {
6861
- outputError({
6862
- argv,
6863
- command: COMMAND$17,
6864
- error: {
6865
- message: config.error.message,
6866
- status: null
6867
- },
6868
- exitCode: 4
6869
- });
6870
- return;
6871
- }
6872
- const result = await new AnythingApiClient(config.value).verifyDomain({ domainId: argv.domainId });
6873
- if (result.isErr()) {
6874
- outputError({
6875
- argv,
6876
- command: COMMAND$17,
6877
- error: result.error
6878
- });
6879
- return;
6880
- }
6881
- if (outputSuccess({
6882
- argv,
6883
- command: COMMAND$17,
6884
- data: result.value,
6885
- primaryId: String(result.value.verified)
6886
- })) return;
6887
- if (result.value.verified) printSuccess(`Domain ${result.value.domain} is verified.`);
6888
- else {
6889
- printLabel("Domain", result.value.domain);
6890
- printLabel("Verified", "false");
6891
- console.log("\n DNS not yet configured. Check your DNS settings and try again.");
6892
- }
6893
- }
6894
- };
6895
-
6896
- //#endregion
6897
- //#region src/commands/domains.ts
6898
- function formatStatus(domain) {
6899
- const challenges = Array.isArray(domain.vercelVerification) ? domain.vercelVerification : [];
6900
- if (!domain.vercelVerified && challenges.length > 0) return "Needs verification";
6901
- if (domain.projectGroup) return "Connected";
6902
- return "Not connected";
6903
- }
6904
- const domainsListCommand = {
6905
- command: "list <organizationId>",
6906
- describe: "List domains for an organization",
6907
- builder: (yargs) => yargs.positional("organizationId", {
6908
- type: "string",
6909
- demandOption: true,
6910
- describe: "The organization ID"
6911
- }).example("anything domains list org_123", "List domains for one organization").example("anything domains list org_123 --json", "Return domains as JSON"),
6912
- handler: async (argv) => {
6913
- const command = "domains list";
6914
- const config = resolveConfig({
6915
- dev: argv.dev,
6916
- apiUrl: argv.apiUrl
6917
- });
6918
- if (config.isErr()) {
6919
- outputError({
6920
- argv,
6921
- command,
6922
- error: {
6923
- message: config.error.message,
6924
- status: null
6925
- },
6926
- exitCode: 4
6927
- });
6928
- return;
6929
- }
6930
- const result = await new AnythingApiClient(config.value).listDomains({ organizationId: argv.organizationId });
6931
- if (result.isErr()) {
6932
- outputError({
6933
- argv,
6934
- command,
6935
- error: result.error
6936
- });
6937
- return;
6938
- }
6939
- const jsonData = { domains: result.value.domains.map(toPublicDomain) };
6940
- if (argv.json && outputSuccess({
6941
- argv,
6942
- command,
6943
- data: jsonData
6944
- })) return;
6945
- if (argv.quiet) {
6946
- for (const domain of result.value.domains) console.log(domain.domain);
6947
- return;
6948
- }
6949
- if (result.value.domains.length === 0) {
6950
- console.log("No domains found.");
6951
- return;
6952
- }
6953
- printTable({
6954
- headers: [
6955
- "Domain",
6956
- "Status",
6957
- "Linked Project"
6958
- ],
6959
- rows: result.value.domains.map((domain) => [
6960
- domain.domain,
6961
- formatStatus(domain),
6962
- domain.projectGroup?.name ?? "-"
6963
- ])
6964
- });
6965
- }
6966
- };
6967
- const domainsCommand = {
6968
- command: "domains",
6969
- describe: "Manage custom domains",
6970
- builder: (yargs) => yargs.command(domainsListCommand).command(domainAddCommand).command(domainRemoveCommand).command(domainVerifyCommand).demandCommand(1, "Specify a domains subcommand. Run `anything domains --help` for usage."),
6971
- handler: () => {}
6972
- };
6973
-
6974
- //#endregion
6975
- //#region src/commands/submit.ts
6976
- const POLL_INTERVAL_MS$1 = 2e3;
6977
- const POLL_TIMEOUT_MS = 6e4;
6978
- const STORE_CHOICES = ["app-store", "play-store"];
6979
- async function waitForSubmission({ client, projectGroupId, submission }) {
6980
- const deadline = Date.now() + POLL_TIMEOUT_MS;
6981
- let current = submission;
6982
- while (current.status === "PENDING" && Date.now() < deadline) {
6983
- const latestResult = await client.getProjectSubmission({
6984
- projectGroupId,
6985
- submissionId: current.id
6986
- });
6987
- if (latestResult.isErr()) return latestResult.map((value) => value.submission);
6988
- current = latestResult.value.submission;
6989
- if (current.status !== "PENDING") return latestResult.map((value) => value.submission);
6990
- await setTimeout$1(POLL_INTERVAL_MS$1);
6991
- }
6992
- return ok(current);
6993
- }
6994
- function printSubmissionResult({ argv, command, pendingMessage, submission }) {
6995
- const { projectGroupId: projectId, ...submissionRest } = submission;
6996
- const submissionOut = {
6997
- projectId,
6998
- ...submissionRest
6999
- };
7000
- if (submission.status === "FAILED") {
7001
- printError(submission.errorMessage ?? "Submission failed.");
7002
- process.exitCode = 1;
7003
- return;
7004
- }
7005
- if (submission.status === "CREATED") {
7006
- if (outputSuccess({
7007
- argv,
7008
- command,
7009
- data: {
7010
- success: true,
7011
- submission: submissionOut
7012
- },
7013
- primaryId: submission.id
7014
- })) return;
7015
- printSuccess("App Store submission is ready.");
7016
- printLabel("Submission ID", submission.id);
7017
- printLabel("Launch URL", submission.launchUrl);
7018
- printLabel("Auth URL", submission.authUrl);
7019
- printLabel("Expires At", submission.expiresAt);
7020
- return;
7021
- }
7022
- if (outputSuccess({
7023
- argv,
7024
- command,
7025
- data: {
7026
- success: true,
7027
- submission
7028
- },
7029
- primaryId: submission.id
7030
- })) return;
7031
- printSuccess(pendingMessage);
7032
- printLabel("Submission ID", submission.id);
7033
- printLabel("Status", submission.status);
7034
- printLabel("Next step", "Expo is still preparing the launch flow. Run the command again in a moment.");
7035
- }
7036
- const submitStatusCommand = {
7037
- command: "status <projectId> <submissionId>",
7038
- describe: "Check the status of an App Store submission",
7039
- builder: (yargs) => yargs.positional("projectId", {
7040
- type: "string",
7041
- demandOption: true,
7042
- describe: "The project ID"
7043
- }).positional("submissionId", {
7044
- type: "string",
7045
- demandOption: true,
7046
- describe: "The submission ID"
7047
- }).example("anything projects submit status <project-id> <submission-id>", "Check a submission later").example("anything projects submit status <project-id> <submission-id> --json", "Return the submission status in JSON"),
7048
- handler: async (argv) => {
7049
- const command = "projects submit status";
7050
- const config = resolveConfig({
7051
- dev: argv.dev,
7052
- apiUrl: argv.apiUrl
7053
- });
7054
- if (config.isErr()) {
7055
- outputError({
7056
- argv,
7057
- command,
7058
- error: {
7059
- message: config.error.message,
7060
- status: null
7061
- },
7062
- exitCode: 4
7063
- });
7064
- return;
7065
- }
7066
- const result = await new AnythingApiClient(config.value).getProjectSubmission({
7067
- projectGroupId: argv.projectId,
7068
- submissionId: argv.submissionId
7069
- });
7070
- if (result.isErr()) {
7071
- outputError({
7072
- argv,
7073
- command,
7074
- error: result.error
7075
- });
7076
- return;
7077
- }
7078
- printSubmissionResult({
7079
- argv,
7080
- command,
7081
- pendingMessage: "Submission is still preparing.",
7082
- submission: result.value.submission
7083
- });
7084
- }
7085
- };
7086
- const submitCommand = {
7087
- command: "submit <projectId>",
7088
- describe: "Start an App Store submission for an app",
7089
- builder: (yargs) => yargs.command(submitStatusCommand).positional("projectId", {
7090
- type: "string",
7091
- demandOption: true,
7092
- describe: "The project ID"
7093
- }).option("store", {
7094
- type: "string",
7095
- choices: STORE_CHOICES,
7096
- describe: "Submission target store"
7097
- }).example("anything projects submit <project-id> --store app-store", "Start an App Store submission").example("anything projects submit <project-id> --store play-store", "Start a Play Store submission").example("anything projects submit <project-id> --store app-store --json", "Return the submission session in JSON").example("anything projects submit status <project-id> <submission-id>", "Check a submission later"),
7098
- handler: async (argv) => {
7099
- const command = "projects submit";
7100
- if (argv.store === void 0) {
7101
- outputError({
7102
- argv,
7103
- command,
7104
- error: {
7105
- message: "Missing required argument: store",
7106
- status: null
7107
- },
7108
- exitCode: 2
7109
- });
7110
- return;
7111
- }
7112
- const store = STORE_CHOICES.find((s) => s === argv.store);
7113
- if (!store) {
7114
- outputError({
7115
- argv,
7116
- command,
7117
- error: {
7118
- message: `Unsupported store: ${argv.store}`,
7119
- status: null
7120
- },
7121
- exitCode: 2
7122
- });
7123
- return;
7124
- }
7125
- if (argv["dry-run"]) {
7126
- outputDryRun({
7127
- argv,
7128
- command,
7129
- plannedActions: [{
7130
- action: "submit_project",
7131
- projectGroupId: argv.projectId,
7132
- store
7133
- }]
7134
- });
7135
- return;
7136
- }
7137
- const config = resolveConfig({
7138
- dev: argv.dev,
7139
- apiUrl: argv.apiUrl
7140
- });
7141
- if (config.isErr()) {
7142
- outputError({
7143
- argv,
7144
- command,
7145
- error: {
7146
- message: config.error.message,
7147
- status: null
7148
- },
7149
- exitCode: 4
7150
- });
7151
- return;
7152
- }
7153
- const client = new AnythingApiClient(config.value);
7154
- const startResult = await client.submitProject({
7155
- projectGroupId: argv.projectId,
7156
- store
7157
- });
7158
- if (startResult.isErr()) {
7159
- outputError({
7160
- argv,
7161
- command,
7162
- error: startResult.error
7163
- });
7164
- return;
7165
- }
7166
- const finalResult = await waitForSubmission({
7167
- client,
7168
- projectGroupId: argv.projectId,
7169
- submission: startResult.value.submission
7170
- });
7171
- if (finalResult.isErr()) {
7172
- outputError({
7173
- argv,
7174
- command,
7175
- error: finalResult.error
7176
- });
7177
- return;
7178
- }
7179
- printSubmissionResult({
7180
- argv,
7181
- command,
7182
- pendingMessage: "Submission started.",
7183
- submission: finalResult.value
7184
- });
7185
- }
7186
- };
7187
-
7188
- //#endregion
7189
- //#region src/commands/introspect.ts
7190
- const commandTree = [
7191
- {
7192
- name: "auth login",
7193
- flags: [{
7194
- name: "--api-key",
7195
- type: "string",
7196
- required: false
7197
- }, {
7198
- name: "--dev",
7199
- type: "boolean",
7200
- required: false
7201
- }],
7202
- idempotent: true,
7203
- destructive: false
7204
- },
7205
- {
7206
- name: "auth logout",
7207
- flags: [],
7208
- idempotent: true,
7209
- destructive: true
7210
- },
7211
- {
7212
- name: "auth status",
7213
- flags: [],
7214
- idempotent: true,
7215
- destructive: false
7216
- },
7217
- {
7218
- name: "user",
7219
- flags: [{
7220
- name: "--brief",
7221
- type: "boolean",
7222
- required: false
7223
- }],
7224
- idempotent: true,
7225
- destructive: false
7226
- },
7227
- {
7228
- name: "orgs list",
7229
- flags: [],
7230
- idempotent: true,
7231
- destructive: false
7232
- },
7233
- {
7234
- name: "orgs get",
7235
- flags: [{
7236
- name: "<organizationId>",
7237
- type: "string",
7238
- required: true
7239
- }],
7240
- idempotent: true,
7241
- destructive: false
7242
- },
7243
- {
7244
- name: "orgs set",
7245
- flags: [{
7246
- name: "<org-id>",
7247
- type: "string",
7248
- required: true
7249
- }],
7250
- idempotent: true,
7251
- destructive: false
7252
- },
7253
- {
7254
- name: "orgs unset",
7255
- flags: [],
7256
- idempotent: true,
7257
- destructive: false
7258
- },
7259
- {
7260
- name: "orgs members",
7261
- flags: [{
7262
- name: "<organizationId>",
7263
- type: "string",
7264
- required: true
7265
- }],
7266
- idempotent: true,
7267
- destructive: false
7268
- },
7269
- {
7270
- name: "projects list",
7271
- flags: [
7272
- {
7273
- name: "--org",
7274
- type: "string",
7275
- required: false
7276
- },
7277
- {
7278
- name: "--search",
7279
- type: "string",
7280
- required: false
7281
- },
7282
- {
7283
- name: "--limit",
7284
- type: "number",
7285
- required: false
7286
- }
7287
- ],
7288
- idempotent: true,
7289
- destructive: false
7290
- },
7291
- {
7292
- name: "projects create",
7293
- flags: [
7294
- {
7295
- name: "--prompt",
7296
- type: "string",
7297
- required: true
7298
- },
7299
- {
7300
- name: "--org",
7301
- type: "string",
7302
- required: false
7303
- },
7304
- {
7305
- name: "--name",
7306
- type: "string",
7307
- required: false
7308
- },
7309
- {
7310
- name: "--wait",
7311
- type: "boolean",
7312
- required: false
7313
- },
7314
- {
7315
- name: "--no-wait",
7316
- type: "boolean",
7317
- required: false
7318
- }
7319
- ],
7320
- idempotent: false,
7321
- destructive: false
7322
- },
7323
- {
7324
- name: "projects get",
7325
- flags: [{
7326
- name: "<projectId>",
7327
- type: "string",
7328
- required: true
7329
- }],
7330
- idempotent: true,
7331
- destructive: false
7332
- },
7333
- {
7334
- name: "projects generate",
7335
- flags: [
7336
- {
7337
- name: "<projectId>",
7338
- type: "string",
7339
- required: true
7340
- },
7341
- {
7342
- name: "--prompt",
7343
- type: "string",
7344
- required: true
7345
- },
7346
- {
7347
- name: "--thread",
7348
- type: "string",
7349
- required: false
7350
- },
7351
- {
7352
- name: "--new-thread",
7353
- type: "boolean",
7354
- required: false
7355
- },
7356
- {
7357
- name: "--wait",
7358
- type: "boolean",
7359
- required: false
7360
- },
7361
- {
7362
- name: "--no-wait",
7363
- type: "boolean",
7364
- required: false
7365
- }
7366
- ],
7367
- idempotent: false,
7368
- destructive: false
7369
- },
7370
- {
7371
- name: "projects rename",
7372
- flags: [{
7373
- name: "<projectId>",
7374
- type: "string",
7375
- required: true
7376
- }, {
7377
- name: "--name",
7378
- type: "string",
7379
- required: true
7380
- }],
7381
- idempotent: true,
7382
- destructive: false
7383
- },
7384
- {
7385
- name: "projects duplicate",
7386
- flags: [{
7387
- name: "<projectId>",
7388
- type: "string",
7389
- required: true
7390
- }, {
7391
- name: "--name",
7392
- type: "string",
7393
- required: false
7394
- }],
7395
- idempotent: false,
7396
- destructive: false
7397
- },
7398
- {
7399
- name: "projects publish",
7400
- flags: [{
7401
- name: "<projectId>",
7402
- type: "string",
7403
- required: true
7404
- }, {
7405
- name: "--slug",
7406
- type: "string",
7407
- required: false
7408
- }],
7409
- idempotent: true,
7410
- destructive: false
7411
- },
7412
- {
7413
- name: "projects submit",
7414
- flags: [{
7415
- name: "<projectId>",
7416
- type: "string",
7417
- required: true
7418
- }, {
7419
- name: "--store",
7420
- type: "string",
7421
- required: true,
7422
- choices: [...STORE_CHOICES]
7423
- }],
7424
- idempotent: false,
7425
- destructive: false
7426
- },
7427
- {
7428
- name: "projects submit status",
7429
- flags: [{
7430
- name: "<projectId>",
7431
- type: "string",
7432
- required: true
7433
- }, {
7434
- name: "<submissionId>",
7435
- type: "string",
7436
- required: true
7437
- }],
7438
- idempotent: true,
7439
- destructive: false
7440
- },
7441
- {
7442
- name: "projects unpublish",
7443
- flags: [{
7444
- name: "<projectId>",
7445
- type: "string",
7446
- required: true
7447
- }, {
7448
- name: "--yes",
7449
- type: "boolean",
7450
- required: true
7451
- }],
7452
- idempotent: true,
7453
- destructive: true
7454
- },
7455
- {
7456
- name: "projects delete",
7457
- flags: [{
7458
- name: "<projectId>",
7459
- type: "string",
7460
- required: true
7461
- }, {
7462
- name: "--yes",
7463
- type: "boolean",
7464
- required: true
7465
- }],
7466
- idempotent: false,
7467
- destructive: true
7468
- },
7469
- {
7470
- name: "projects messages",
7471
- flags: [
7472
- {
7473
- name: "<projectId>",
7474
- type: "string",
7475
- required: true
7476
- },
7477
- {
7478
- name: "--thread",
7479
- type: "string",
7480
- required: false
7481
- },
7482
- {
7483
- name: "--limit",
7484
- type: "number",
7485
- required: false
7486
- }
7487
- ],
7488
- idempotent: true,
7489
- destructive: false
7490
- },
7491
- {
7492
- name: "projects status",
7493
- flags: [{
7494
- name: "<projectId>",
7495
- type: "string",
7496
- required: true
7497
- }],
7498
- idempotent: true,
7499
- destructive: false
7500
- },
7501
- {
7502
- name: "projects logs",
7503
- flags: [
7504
- {
7505
- name: "<projectId>",
7506
- type: "string",
7507
- required: true
7508
- },
7509
- {
7510
- name: "--level",
7511
- type: "string",
7512
- required: false
7513
- },
7514
- {
7515
- name: "--search",
7516
- type: "string",
7517
- required: false
7518
- },
7519
- {
7520
- name: "--limit",
7521
- type: "number",
7522
- required: false
7523
- },
7524
- {
7525
- name: "--since",
7526
- type: "string",
7527
- required: false
7528
- },
7529
- {
7530
- name: "--follow",
7531
- type: "boolean",
7532
- required: false
7533
- }
7534
- ],
7535
- idempotent: true,
7536
- destructive: false
7537
- },
7538
- {
7539
- name: "projects files list",
7540
- flags: [{
7541
- name: "<projectId>",
7542
- type: "string",
7543
- required: true
7544
- }],
7545
- idempotent: true,
7546
- destructive: false
7547
- },
7548
- {
7549
- name: "projects files get",
7550
- flags: [{
7551
- name: "<projectId>",
7552
- type: "string",
7553
- required: true
7554
- }, {
7555
- name: "<path>",
7556
- type: "string",
7557
- required: true
7558
- }],
7559
- idempotent: true,
7560
- destructive: false
7561
- },
7562
- {
7563
- name: "projects set",
7564
- flags: [{
7565
- name: "<projectId>",
7566
- type: "string",
7567
- required: true
7568
- }],
7569
- idempotent: true,
7570
- destructive: false
7571
- },
7572
- {
7573
- name: "projects unset",
7574
- flags: [],
7575
- idempotent: true,
7576
- destructive: false
7577
- },
7578
- {
7579
- name: "projects auth providers",
7580
- flags: [{
7581
- name: "<projectId>",
7582
- type: "string",
7583
- required: true
7584
- }],
7585
- idempotent: true,
7586
- destructive: false
7587
- },
7588
- {
7589
- name: "projects settings auth get",
7590
- flags: [{
7591
- name: "[projectId]",
7592
- type: "string",
7593
- required: false
7594
- }],
7595
- idempotent: true,
7596
- destructive: false
7597
- },
7598
- {
7599
- name: "projects settings auth set",
7600
- flags: [
7601
- {
7602
- name: "[projectId]",
7603
- type: "string",
7604
- required: false
7605
- },
7606
- {
7607
- name: "--provider",
7608
- type: "string",
7609
- required: true,
7610
- choices: [
7611
- "google",
7612
- "email",
7613
- "facebook",
7614
- "twitter"
7615
- ]
7616
- },
7617
- {
7618
- name: "--enabled",
7619
- type: "boolean",
7620
- required: true
7621
- },
7622
- {
7623
- name: "--secret",
7624
- type: "string",
7625
- required: false
7626
- },
7627
- {
7628
- name: "--env",
7629
- type: "string",
7630
- required: false,
7631
- choices: [
7632
- "development",
7633
- "preview",
7634
- "production"
7635
- ]
7636
- }
7637
- ],
7638
- idempotent: false,
7639
- destructive: false
7640
- },
7641
- {
7642
- name: "projects secrets add",
7643
- flags: [
7644
- {
7645
- name: "<projectId>",
7646
- type: "string",
7647
- required: true
7648
- },
7649
- {
7650
- name: "--name",
7651
- type: "string",
7652
- required: true
7653
- },
7654
- {
7655
- name: "--value",
7656
- type: "string",
7657
- required: false
7658
- },
7659
- {
7660
- name: "--env",
7661
- type: "string",
7662
- required: false,
7663
- choices: [
7664
- "development",
7665
- "preview",
7666
- "production"
7667
- ]
7668
- }
7669
- ],
7670
- idempotent: false,
7671
- destructive: false
7672
- },
7673
- {
7674
- name: "projects secrets list",
7675
- flags: [{
7676
- name: "<projectId>",
7677
- type: "string",
7678
- required: true
7679
- }],
7680
- idempotent: true,
7681
- destructive: false
7682
- },
7683
- {
7684
- name: "projects secrets remove",
7685
- flags: [{
7686
- name: "<projectId>",
7687
- type: "string",
7688
- required: true
7689
- }, {
7690
- name: "<secretId>",
7691
- type: "string",
7692
- required: true
7693
- }],
7694
- idempotent: true,
7695
- destructive: true
7696
- },
7697
- {
7698
- name: "assets upload",
7699
- flags: [
7700
- {
7701
- name: "<projectId>",
7702
- type: "string",
7703
- required: true
7704
- },
7705
- {
7706
- name: "<file>",
7707
- type: "string",
7708
- required: true
7709
- },
7710
- {
7711
- name: "--name",
7712
- type: "string",
7713
- required: false
7714
- }
7715
- ],
7716
- idempotent: false,
7717
- destructive: false
7718
- },
7719
- {
7720
- name: "assets list",
7721
- flags: [{
7722
- name: "<projectId>",
7723
- type: "string",
7724
- required: true
7725
- }, {
7726
- name: "--query",
7727
- type: "string",
7728
- required: false
7729
- }],
7730
- idempotent: true,
7731
- destructive: false
7732
- },
7733
- {
7734
- name: "assets remove",
7735
- flags: [{
7736
- name: "<projectId>",
7737
- type: "string",
7738
- required: true
7739
- }, {
7740
- name: "<assetId>",
7741
- type: "string",
7742
- required: true
7743
- }],
7744
- idempotent: true,
7745
- destructive: true
7746
- },
7747
- {
7748
- name: "databases list",
7749
- flags: [{
7750
- name: "--org",
7751
- type: "string",
7752
- required: true
7753
- }, {
7754
- name: "--limit",
7755
- type: "number",
7756
- required: false
7757
- }],
7758
- idempotent: true,
7759
- destructive: false
7760
- },
7761
- {
7762
- name: "databases get",
7763
- flags: [{
7764
- name: "<databaseId>",
7765
- type: "string",
7766
- required: true
7767
- }],
7768
- idempotent: true,
7769
- destructive: false
7770
- },
7771
- {
7772
- name: "databases create",
7773
- flags: [
7774
- {
7775
- name: "--org",
7776
- type: "string",
7777
- required: false
7778
- },
7779
- {
7780
- name: "--project",
7781
- type: "string",
7782
- required: false
7783
- },
7784
- {
7785
- name: "--name",
7786
- type: "string",
7787
- required: true
7788
- }
7789
- ],
7790
- idempotent: false,
7791
- destructive: false
7792
- },
7793
- {
7794
- name: "databases query",
7795
- flags: [{
7796
- name: "<databaseId>",
7797
- type: "string",
7798
- required: true
7799
- }, {
7800
- name: "<sql>",
7801
- type: "string",
7802
- required: true
7803
- }],
7804
- idempotent: true,
7805
- destructive: false
7806
- },
7807
- {
7808
- name: "databases connect",
7809
- flags: [{
7810
- name: "<databaseId>",
7811
- type: "string",
7812
- required: true
7813
- }, {
7814
- name: "--mask",
7815
- type: "boolean",
7816
- required: false
7817
- }],
7818
- idempotent: true,
7819
- destructive: false
7820
- },
7821
- {
7822
- name: "databases reset",
7823
- flags: [{
7824
- name: "<databaseId>",
7825
- type: "string",
7826
- required: true
7827
- }, {
7828
- name: "--yes",
7829
- type: "boolean",
7830
- required: true
7831
- }],
7832
- idempotent: false,
7833
- destructive: true
7834
- },
7835
- {
7836
- name: "domains list",
7837
- flags: [{
7838
- name: "<organizationId>",
7839
- type: "string",
7840
- required: true
7841
- }],
7842
- idempotent: true,
7843
- destructive: false
7844
- },
7845
- {
7846
- name: "domains add",
7847
- flags: [
7848
- {
7849
- name: "<domain>",
7850
- type: "string",
7851
- required: true
7852
- },
7853
- {
7854
- name: "--org",
7855
- type: "string",
7856
- required: false
7857
- },
7858
- {
7859
- name: "--project",
7860
- type: "string",
7861
- required: false
7862
- }
7863
- ],
7864
- idempotent: false,
7865
- destructive: false
7866
- },
7867
- {
7868
- name: "domains remove",
7869
- flags: [{
7870
- name: "<domainId>",
7871
- type: "string",
7872
- required: true
7873
- }, {
7874
- name: "--yes",
7875
- type: "boolean",
7876
- required: true
7877
- }],
7878
- idempotent: true,
7879
- destructive: true
7880
- },
7881
- {
7882
- name: "domains verify",
7883
- flags: [{
7884
- name: "<domainId>",
7885
- type: "string",
7886
- required: true
7887
- }],
7888
- idempotent: true,
7889
- destructive: false
7890
- },
7891
- {
7892
- name: "deployments list",
7893
- flags: [{
7894
- name: "<projectId>",
7895
- type: "string",
7896
- required: true
7897
- }, {
7898
- name: "--limit",
7899
- type: "number",
7900
- required: false
7901
- }],
7902
- idempotent: true,
7903
- destructive: false
7904
- },
7905
- {
7906
- name: "deployments get",
7907
- flags: [{
7908
- name: "<deploymentId>",
7909
- type: "string",
7910
- required: true
7911
- }],
7912
- idempotent: true,
7913
- destructive: false
7914
- },
7915
- {
7916
- name: "deployments logs",
7917
- flags: [{
7918
- name: "<deploymentId>",
7919
- type: "string",
7920
- required: true
7921
- }],
7922
- idempotent: true,
7923
- destructive: false
7924
- },
7925
- {
7926
- name: "deployments rollback",
7927
- flags: [
7928
- {
7929
- name: "<projectId>",
7930
- type: "string",
7931
- required: true
7932
- },
7933
- {
7934
- name: "[deploymentId]",
7935
- type: "string",
7936
- required: false
7937
- },
7938
- {
7939
- name: "--yes",
7940
- type: "boolean",
7941
- required: true
7942
- }
7943
- ],
7944
- idempotent: false,
7945
- destructive: true
7946
- },
7947
- {
7948
- name: "members list",
7949
- flags: [{
7950
- name: "--org",
7951
- type: "string",
7952
- required: false
7953
- }],
7954
- idempotent: true,
7955
- destructive: false
7956
- },
7957
- {
7958
- name: "members invite",
7959
- flags: [
7960
- {
7961
- name: "<email>",
7962
- type: "string",
7963
- required: true
7964
- },
7965
- {
7966
- name: "--org",
7967
- type: "string",
7968
- required: false
7969
- },
7970
- {
7971
- name: "--role",
7972
- type: "string",
7973
- required: false,
7974
- choices: [
7975
- "owner",
7976
- "admin",
7977
- "editor",
7978
- "viewer"
7979
- ]
7980
- }
7981
- ],
7982
- idempotent: false,
7983
- destructive: false
7984
- },
7985
- {
7986
- name: "members remove",
7987
- flags: [
7988
- {
7989
- name: "<email>",
7990
- type: "string",
7991
- required: true
7992
- },
7993
- {
7994
- name: "--org",
7995
- type: "string",
7996
- required: false
7997
- },
7998
- {
7999
- name: "--yes",
8000
- type: "boolean",
8001
- required: true
8002
- }
8003
- ],
8004
- idempotent: true,
8005
- destructive: true
8006
- },
8007
- {
8008
- name: "members role",
8009
- flags: [
8010
- {
8011
- name: "<email>",
8012
- type: "string",
8013
- required: true
8014
- },
8015
- {
8016
- name: "<role>",
8017
- type: "string",
8018
- required: true,
8019
- choices: [
8020
- "owner",
8021
- "admin",
8022
- "editor",
8023
- "viewer"
8024
- ]
8025
- },
8026
- {
8027
- name: "--org",
8028
- type: "string",
8029
- required: false
8030
- }
8031
- ],
8032
- idempotent: true,
8033
- destructive: false
8034
- },
8035
- {
8036
- name: "status",
8037
- flags: [],
8038
- idempotent: true,
8039
- destructive: false
8040
- },
8041
- {
8042
- name: "switch",
8043
- flags: [],
8044
- idempotent: true,
8045
- destructive: false
8046
- },
8047
- {
8048
- name: "ship",
8049
- flags: [
8050
- {
8051
- name: "--prompt",
8052
- type: "string",
8053
- required: true
8054
- },
8055
- {
8056
- name: "--project",
8057
- type: "string",
8058
- required: false
8059
- },
8060
- {
8061
- name: "--org",
8062
- type: "string",
8063
- required: false
8064
- },
8065
- {
8066
- name: "--skip-publish",
8067
- type: "boolean",
8068
- required: false
8069
- }
8070
- ],
8071
- idempotent: false,
8072
- destructive: false
8073
- },
8074
- {
8075
- name: "link",
8076
- flags: [{
8077
- name: "<projectId>",
8078
- type: "string",
8079
- required: false
8080
- }],
8081
- idempotent: true,
8082
- destructive: false
8083
- },
8084
- {
8085
- name: "unlink",
8086
- flags: [],
8087
- idempotent: true,
8088
- destructive: false
8089
- },
8090
- {
8091
- name: "pull",
8092
- flags: [{
8093
- name: "--files",
8094
- type: "boolean",
8095
- required: false
8096
- }, {
8097
- name: "--env",
8098
- type: "boolean",
8099
- required: false
8100
- }],
8101
- idempotent: true,
8102
- destructive: false
8103
- },
8104
- {
8105
- name: "watch",
8106
- flags: [
8107
- {
8108
- name: "<projectId>",
8109
- type: "string",
8110
- required: true
8111
- },
8112
- {
8113
- name: "--events",
8114
- type: "string",
8115
- required: false
8116
- },
8117
- {
8118
- name: "--interval",
8119
- type: "number",
8120
- required: false
6928
+ primaryId: result.value.domain.domain
6929
+ })) return;
6930
+ printSuccess(`Domain added: ${result.value.domain.domain}`);
6931
+ printLabel("ID", result.value.domain.id);
6932
+ printLabel("Verified", String(result.value.domain.vercelVerified));
6933
+ }
6934
+ };
6935
+
6936
+ //#endregion
6937
+ //#region src/commands/domain-remove.ts
6938
+ const COMMAND$18 = "domains remove";
6939
+ const domainRemoveCommand = {
6940
+ command: "remove <domainId>",
6941
+ describe: "Remove a custom domain",
6942
+ builder: (yargs) => yargs.positional("domainId", {
6943
+ type: "string",
6944
+ demandOption: true,
6945
+ describe: "The domain ID to remove"
6946
+ }).option("yes", {
6947
+ type: "boolean",
6948
+ default: false,
6949
+ describe: "Skip confirmation"
6950
+ }).example("anything domains remove dom_123 --yes", "Remove a domain"),
6951
+ handler: async (argv) => {
6952
+ const config = resolveConfig({
6953
+ dev: argv.dev,
6954
+ apiUrl: argv.apiUrl
6955
+ });
6956
+ if (config.isErr()) {
6957
+ outputError({
6958
+ argv,
6959
+ command: COMMAND$18,
6960
+ error: {
6961
+ message: config.error.message,
6962
+ status: null
6963
+ },
6964
+ exitCode: 4
6965
+ });
6966
+ return;
6967
+ }
6968
+ if (argv["dry-run"]) {
6969
+ outputDryRun({
6970
+ argv,
6971
+ command: COMMAND$18,
6972
+ plannedActions: [{
6973
+ action: "remove_domain",
6974
+ domainId: argv.domainId
6975
+ }]
6976
+ });
6977
+ return;
6978
+ }
6979
+ if (!argv.yes) {
6980
+ outputError({
6981
+ argv,
6982
+ command: COMMAND$18,
6983
+ error: {
6984
+ message: "Domain removal is destructive. Pass --yes to confirm.",
6985
+ status: null
6986
+ },
6987
+ exitCode: 2,
6988
+ code: "CONFIRMATION_REQUIRED"
6989
+ });
6990
+ return;
6991
+ }
6992
+ const result = await new AnythingApiClient(config.value).removeDomain({ domainId: argv.domainId });
6993
+ if (result.isErr()) {
6994
+ outputError({
6995
+ argv,
6996
+ command: COMMAND$18,
6997
+ error: result.error
6998
+ });
6999
+ return;
7000
+ }
7001
+ if (outputSuccess({
7002
+ argv,
7003
+ command: COMMAND$18,
7004
+ data: {
7005
+ removed: true,
7006
+ domainId: argv.domainId
8121
7007
  }
8122
- ],
8123
- idempotent: true,
8124
- destructive: false
8125
- },
8126
- {
8127
- name: "skill",
8128
- flags: [{
8129
- name: "--file",
8130
- type: "string",
8131
- required: false
8132
- }, {
8133
- name: "--path",
8134
- type: "boolean",
8135
- required: false
8136
- }],
8137
- idempotent: true,
8138
- destructive: false
8139
- },
8140
- {
8141
- name: "introspect",
8142
- flags: [],
8143
- idempotent: true,
8144
- destructive: false
8145
- },
8146
- {
8147
- name: "llm-context",
8148
- flags: [],
8149
- idempotent: true,
8150
- destructive: false
7008
+ })) return;
7009
+ printSuccess(`Domain ${argv.domainId} removed.`);
8151
7010
  }
8152
- ];
7011
+ };
7012
+
7013
+ //#endregion
7014
+ //#region src/commands/domain-verify.ts
7015
+ const COMMAND$17 = "domains verify";
7016
+ const domainVerifyCommand = {
7017
+ command: "verify <domainId>",
7018
+ describe: "Check DNS configuration for a custom domain",
7019
+ builder: (yargs) => yargs.positional("domainId", {
7020
+ type: "string",
7021
+ demandOption: true,
7022
+ describe: "The domain ID to verify"
7023
+ }).example("anything domains verify dom_123", "Check DNS configuration status"),
7024
+ handler: async (argv) => {
7025
+ const config = resolveConfig({
7026
+ dev: argv.dev,
7027
+ apiUrl: argv.apiUrl
7028
+ });
7029
+ if (config.isErr()) {
7030
+ outputError({
7031
+ argv,
7032
+ command: COMMAND$17,
7033
+ error: {
7034
+ message: config.error.message,
7035
+ status: null
7036
+ },
7037
+ exitCode: 4
7038
+ });
7039
+ return;
7040
+ }
7041
+ const result = await new AnythingApiClient(config.value).verifyDomain({ domainId: argv.domainId });
7042
+ if (result.isErr()) {
7043
+ outputError({
7044
+ argv,
7045
+ command: COMMAND$17,
7046
+ error: result.error
7047
+ });
7048
+ return;
7049
+ }
7050
+ if (outputSuccess({
7051
+ argv,
7052
+ command: COMMAND$17,
7053
+ data: result.value,
7054
+ primaryId: String(result.value.verified)
7055
+ })) return;
7056
+ if (result.value.verified) printSuccess(`Domain ${result.value.domain} is verified.`);
7057
+ else {
7058
+ printLabel("Domain", result.value.domain);
7059
+ printLabel("Verified", "false");
7060
+ console.log("\n DNS not yet configured. Check your DNS settings and try again.");
7061
+ }
7062
+ }
7063
+ };
7064
+
7065
+ //#endregion
7066
+ //#region src/commands/domains.ts
7067
+ function formatStatus(domain) {
7068
+ const challenges = Array.isArray(domain.vercelVerification) ? domain.vercelVerification : [];
7069
+ if (!domain.vercelVerified && challenges.length > 0) return "Needs verification";
7070
+ if (domain.projectGroup) return "Connected";
7071
+ return "Not connected";
7072
+ }
7073
+ const domainsListCommand = {
7074
+ command: "list <organizationId>",
7075
+ describe: "List domains for an organization",
7076
+ builder: (yargs) => yargs.positional("organizationId", {
7077
+ type: "string",
7078
+ demandOption: true,
7079
+ describe: "The organization ID"
7080
+ }).example("anything domains list org_123", "List domains for one organization").example("anything domains list org_123 --json", "Return domains as JSON"),
7081
+ handler: async (argv) => {
7082
+ const command = "domains list";
7083
+ const config = resolveConfig({
7084
+ dev: argv.dev,
7085
+ apiUrl: argv.apiUrl
7086
+ });
7087
+ if (config.isErr()) {
7088
+ outputError({
7089
+ argv,
7090
+ command,
7091
+ error: {
7092
+ message: config.error.message,
7093
+ status: null
7094
+ },
7095
+ exitCode: 4
7096
+ });
7097
+ return;
7098
+ }
7099
+ const result = await new AnythingApiClient(config.value).listDomains({ organizationId: argv.organizationId });
7100
+ if (result.isErr()) {
7101
+ outputError({
7102
+ argv,
7103
+ command,
7104
+ error: result.error
7105
+ });
7106
+ return;
7107
+ }
7108
+ const jsonData = { domains: result.value.domains.map(toPublicDomain) };
7109
+ if (argv.json && outputSuccess({
7110
+ argv,
7111
+ command,
7112
+ data: jsonData
7113
+ })) return;
7114
+ if (argv.quiet) {
7115
+ for (const domain of result.value.domains) console.log(domain.domain);
7116
+ return;
7117
+ }
7118
+ if (result.value.domains.length === 0) {
7119
+ console.log("No domains found.");
7120
+ return;
7121
+ }
7122
+ printTable({
7123
+ headers: [
7124
+ "Domain",
7125
+ "Status",
7126
+ "Linked Project"
7127
+ ],
7128
+ rows: result.value.domains.map((domain) => [
7129
+ domain.domain,
7130
+ formatStatus(domain),
7131
+ domain.projectGroup?.name ?? "-"
7132
+ ])
7133
+ });
7134
+ }
7135
+ };
7136
+ const domainsCommand = {
7137
+ command: "domains",
7138
+ describe: "Manage custom domains",
7139
+ builder: (yargs) => yargs.command(domainsListCommand).command(domainAddCommand).command(domainRemoveCommand).command(domainVerifyCommand).demandCommand(1, "Specify a domains subcommand. Run `anything domains --help` for usage."),
7140
+ handler: () => {}
7141
+ };
7142
+
7143
+ //#endregion
7144
+ //#region src/commands/introspect.ts
8153
7145
  const globalFlags = [
8154
7146
  {
8155
7147
  name: "--json",
@@ -8187,7 +7179,7 @@ const introspectCommand = {
8187
7179
  describe: "Output the full command tree as JSON for agent discovery",
8188
7180
  handler: (argv) => {
8189
7181
  const data = {
8190
- commands: commandTree,
7182
+ commands: buildCommandTree(),
8191
7183
  globalFlags
8192
7184
  };
8193
7185
  if (outputSuccess({
@@ -8351,10 +7343,6 @@ let UserDatabaseStatus = /* @__PURE__ */ function(UserDatabaseStatus) {
8351
7343
  return UserDatabaseStatus;
8352
7344
  }({});
8353
7345
 
8354
- //#endregion
8355
- //#region src/version.ts
8356
- const CLI_VERSION = version;
8357
-
8358
7346
  //#endregion
8359
7347
  //#region src/commands/llm-context.ts
8360
7348
  const REVISION_TERMINAL_STATUSES = [
@@ -8503,7 +7491,7 @@ const llmContextCommand = {
8503
7491
  id: org.id,
8504
7492
  name: org.name,
8505
7493
  plan: org.plan,
8506
- hasCredits: BigInt(org.creditBalance) > 0n
7494
+ hasCredits: org.creditsBalance > 0
8507
7495
  }))
8508
7496
  };
8509
7497
  } catch {}
@@ -8925,18 +7913,6 @@ const membersCommand = {
8925
7913
  handler: () => {}
8926
7914
  };
8927
7915
 
8928
- //#endregion
8929
- //#region src/format-credits.ts
8930
- const HUMAN_READABLE_FACTOR = 10000000n;
8931
- const formatter = Intl.NumberFormat("en", {
8932
- notation: "compact",
8933
- maximumSignificantDigits: 3
8934
- });
8935
- const humanizeCredits = (credits) => {
8936
- const normalized = BigInt(credits) * 100n / HUMAN_READABLE_FACTOR;
8937
- return formatter.format(Math.ceil(Number(normalized) / 100));
8938
- };
8939
-
8940
7916
  //#endregion
8941
7917
  //#region src/commands/org-members.ts
8942
7918
  const orgMembersCommand = {
@@ -9061,9 +8037,6 @@ async function loadOrganizations(argv, command) {
9061
8037
  }
9062
8038
  return result.value.organizations;
9063
8039
  }
9064
- function formatCredits$1(creditBalance) {
9065
- return `${humanizeCredits(creditBalance)} credits`;
9066
- }
9067
8040
  const getCommand = {
9068
8041
  command: "get <organizationId>",
9069
8042
  describe: "Inspect a single organization",
@@ -9099,7 +8072,7 @@ const getCommand = {
9099
8072
  printLabel("ID", organization.id);
9100
8073
  printLabel("Plan", organization.planDisplayName);
9101
8074
  printLabel("Paid", organization.isPaid ? "yes" : "no");
9102
- printLabel("Credits", formatCredits$1(organization.creditBalance));
8075
+ printLabel("Credits", `${organization.creditsBalance} credits`);
9103
8076
  printLabel("Plan Code", organization.plan);
9104
8077
  }
9105
8078
  };
@@ -9206,8 +8179,13 @@ const orgsCommand = {
9206
8179
  //#endregion
9207
8180
  //#region src/stream.ts
9208
8181
  function resultErrorMessage(error) {
9209
- if (error && typeof error === "object" && "message" in error && typeof error.message === "string") return error.message;
9210
- return "Operation failed";
8182
+ return error?.message ?? "Operation failed";
8183
+ }
8184
+ function printStillBuilding({ projectId, error }) {
8185
+ printStreamMarker("progress", error.message);
8186
+ printLabel("Project ID", projectId);
8187
+ if (error.hint) printLabel("Resume", error.hint);
8188
+ process.exitCode = 1;
9211
8189
  }
9212
8190
  function createEmitter(argv) {
9213
8191
  if (argv.quiet) return (_event) => {};
@@ -9219,20 +8197,28 @@ function createEmitter(argv) {
9219
8197
  printStreamMarker(event.status === "complete" ? "done" : "progress", event.message ?? `${event.step}...`);
9220
8198
  return;
9221
8199
  }
9222
- if (event.type === "result" && !event.ok) printError(`[error] ${resultErrorMessage(event.error)}`);
8200
+ if (event.type === "result" && !event.ok) {
8201
+ printError(`[error] ${resultErrorMessage(event.error)}`);
8202
+ if (event.error?.hint) printError(`[hint] ${event.error.hint}`);
8203
+ }
9223
8204
  };
9224
8205
  }
9225
8206
 
9226
8207
  //#endregion
9227
8208
  //#region src/watch-generation.ts
9228
- const TIMEOUT_MS = 300 * 1e3;
9229
- const POLL_INTERVAL_MS = 3e3;
8209
+ const STALL_MS = 240 * 1e3;
8210
+ const ABSOLUTE_MAX_MS = 1800 * 1e3;
8211
+ const POLL_INTERVAL_MS$1 = 3e3;
8212
+ const WS_FASTPATH_TIMEOUT_MS = 90 * 1e3;
9230
8213
  const TERMINAL_SUCCESS_STATUSES = new Set(["COMPLETED", "VALID"]);
9231
8214
  const TERMINAL_FAILURE_STATUSES = new Set([
9232
8215
  "INVALID",
9233
8216
  "INVALID_PROMPT",
9234
8217
  "FAILED"
9235
8218
  ]);
8219
+ function stillBuildingHint(projectGroupId) {
8220
+ return `Check progress with \`anything projects status ${projectGroupId}\`, then publish with \`anything projects publish ${projectGroupId}\` once status is VALID.`;
8221
+ }
9236
8222
  const REVISIONS_FINISHED_QUERY = `
9237
8223
  subscription ProjectGroupRevisionsFinished($id: ID!) {
9238
8224
  projectGroupRevisionsFinished(id: $id) {
@@ -9292,10 +8278,10 @@ function waitForRevisionFinished({ config, projectGroupId }) {
9292
8278
  ok: false,
9293
8279
  error: {
9294
8280
  code: "timeout",
9295
- message: "Generation timed out waiting for completion"
8281
+ message: "WebSocket fast-path timed out; falling back to polling"
9296
8282
  }
9297
8283
  });
9298
- }, TIMEOUT_MS);
8284
+ }, WS_FASTPATH_TIMEOUT_MS);
9299
8285
  let unsubscribe = null;
9300
8286
  function finish(result) {
9301
8287
  if (settled) return;
@@ -9339,6 +8325,9 @@ async function latestMessageSucceeded({ client, projectGroupId }) {
9339
8325
  function sleep$2(ms) {
9340
8326
  return new Promise((resolve) => setTimeout(resolve, ms));
9341
8327
  }
8328
+ function progressMarker(value) {
8329
+ return `${value.status ?? ""}|${value.latestRevisionId ?? ""}|${value.updatedAt}`;
8330
+ }
9342
8331
  async function pollUntilTerminal({ client, projectGroupId, emit, sleepFn = sleep$2 }) {
9343
8332
  emit({
9344
8333
  type: "progress",
@@ -9346,11 +8335,14 @@ async function pollUntilTerminal({ client, projectGroupId, emit, sleepFn = sleep
9346
8335
  status: "running",
9347
8336
  message: "Streaming unavailable; polling generation status..."
9348
8337
  });
9349
- const deadlineMs = Date.now() + TIMEOUT_MS;
9350
- while (Date.now() < deadlineMs) {
8338
+ const startedAt = Date.now();
8339
+ let lastProgressAt = startedAt;
8340
+ let lastMarker = null;
8341
+ while (Date.now() - startedAt <= ABSOLUTE_MAX_MS) {
9351
8342
  const result = await client.getProjectStatus({ projectGroupId });
9352
8343
  if (result.isErr()) {
9353
- await sleepFn(POLL_INTERVAL_MS);
8344
+ if (Date.now() - lastProgressAt > STALL_MS) break;
8345
+ await sleepFn(POLL_INTERVAL_MS$1);
9354
8346
  continue;
9355
8347
  }
9356
8348
  const { status } = result.value;
@@ -9361,30 +8353,46 @@ async function pollUntilTerminal({ client, projectGroupId, emit, sleepFn = sleep
9361
8353
  status: "complete",
9362
8354
  message: "Generation complete"
9363
8355
  });
9364
- return true;
8356
+ return { ok: true };
9365
8357
  }
9366
8358
  if (status !== null && TERMINAL_FAILURE_STATUSES.has(status)) {
8359
+ const error = {
8360
+ code: "generation_failed",
8361
+ message: `Generation failed with status: ${status}`
8362
+ };
9367
8363
  emit({
9368
8364
  type: "result",
9369
8365
  ok: false,
9370
- error: {
9371
- code: "generation_failed",
9372
- message: `Generation failed with status: ${status}`
9373
- }
8366
+ error
9374
8367
  });
9375
- return false;
8368
+ return {
8369
+ ok: false,
8370
+ error
8371
+ };
8372
+ }
8373
+ const marker = progressMarker(result.value);
8374
+ if (marker !== lastMarker) {
8375
+ lastMarker = marker;
8376
+ lastProgressAt = Date.now();
9376
8377
  }
9377
- await sleepFn(POLL_INTERVAL_MS);
8378
+ if (Date.now() - lastProgressAt > STALL_MS) break;
8379
+ await sleepFn(POLL_INTERVAL_MS$1);
9378
8380
  }
8381
+ const error = {
8382
+ code: "still_building",
8383
+ message: "Generation is still running on the server (the CLI stopped waiting).",
8384
+ projectId: projectGroupId,
8385
+ hint: stillBuildingHint(projectGroupId)
8386
+ };
9379
8387
  emit({
9380
8388
  type: "result",
9381
8389
  ok: false,
9382
- error: {
9383
- code: "timeout",
9384
- message: "Generation timed out waiting for completion"
9385
- }
8390
+ error
9386
8391
  });
9387
- return false;
8392
+ return {
8393
+ ok: false,
8394
+ error
8395
+ };
9388
8396
  }
9389
8397
  async function watchGeneration({ config, client, projectGroupId, emit, waitForFinished = waitForRevisionFinished, sleepFn }) {
9390
8398
  const finished = await waitForFinished({
@@ -9392,7 +8400,7 @@ async function watchGeneration({ config, client, projectGroupId, emit, waitForFi
9392
8400
  projectGroupId
9393
8401
  });
9394
8402
  if (!finished.ok) {
9395
- if (finished.error.code === "websocket_error") return pollUntilTerminal({
8403
+ if (finished.error.code === "websocket_error" || finished.error.code === "timeout") return pollUntilTerminal({
9396
8404
  client,
9397
8405
  projectGroupId,
9398
8406
  emit,
@@ -9403,7 +8411,10 @@ async function watchGeneration({ config, client, projectGroupId, emit, waitForFi
9403
8411
  ok: false,
9404
8412
  error: finished.error
9405
8413
  });
9406
- return false;
8414
+ return {
8415
+ ok: false,
8416
+ error: finished.error
8417
+ };
9407
8418
  }
9408
8419
  const succeeded = await latestMessageSucceeded({
9409
8420
  client,
@@ -9415,7 +8426,10 @@ async function watchGeneration({ config, client, projectGroupId, emit, waitForFi
9415
8426
  status: "complete",
9416
8427
  message: succeeded ? "Generation complete" : "Generation failed"
9417
8428
  });
9418
- return succeeded;
8429
+ return succeeded ? { ok: true } : {
8430
+ ok: false,
8431
+ error: null
8432
+ };
9419
8433
  }
9420
8434
 
9421
8435
  //#endregion
@@ -9513,7 +8527,7 @@ const createCommand = {
9513
8527
  name: argv.name ?? null
9514
8528
  });
9515
8529
  if (result.isErr()) {
9516
- outputError({
8530
+ outputStreamError({
9517
8531
  argv,
9518
8532
  command: COMMAND$16,
9519
8533
  error: result.error
@@ -9528,10 +8542,14 @@ const createCommand = {
9528
8542
  });
9529
8543
  if (!argv.wait) {
9530
8544
  if (argv.json) {
8545
+ const { projectGroupId: projectId, ...rest } = result.value;
9531
8546
  printNdjson({
9532
8547
  type: "result",
9533
8548
  ok: true,
9534
- data: result.value
8549
+ data: {
8550
+ projectId,
8551
+ ...rest
8552
+ }
9535
8553
  });
9536
8554
  return;
9537
8555
  }
@@ -9541,7 +8559,7 @@ const createCommand = {
9541
8559
  }
9542
8560
  printStreamMarker("done", `project ${result.value.projectGroupId} created`);
9543
8561
  printSuccess("App created! Generation enqueued.");
9544
- printLabel("Project Group ID", result.value.projectGroupId);
8562
+ printLabel("Project ID", result.value.projectGroupId);
9545
8563
  printLabel("Revision ID", result.value.revisionId);
9546
8564
  return;
9547
8565
  }
@@ -9551,14 +8569,14 @@ const createCommand = {
9551
8569
  status: "running",
9552
8570
  message: "Generation started..."
9553
8571
  });
9554
- const succeeded = await watchGeneration({
8572
+ const gen = await watchGeneration({
9555
8573
  config: config.value,
9556
8574
  client,
9557
8575
  projectGroupId: result.value.projectGroupId,
9558
8576
  emit
9559
8577
  });
9560
8578
  if (argv.json) {
9561
- if (succeeded === false) {
8579
+ if (!gen.ok) {
9562
8580
  process.exitCode = 1;
9563
8581
  return;
9564
8582
  }
@@ -9575,10 +8593,17 @@ const createCommand = {
9575
8593
  }
9576
8594
  if (argv.quiet) {
9577
8595
  console.log(result.value.projectGroupId);
9578
- if (succeeded === false) process.exitCode = 1;
8596
+ if (!gen.ok) process.exitCode = 1;
9579
8597
  return;
9580
8598
  }
9581
- if (succeeded === false) {
8599
+ if (!gen.ok) {
8600
+ if (gen.error?.code === "still_building") {
8601
+ printStillBuilding({
8602
+ projectId: result.value.projectGroupId,
8603
+ error: gen.error
8604
+ });
8605
+ return;
8606
+ }
9582
8607
  outputError({
9583
8608
  argv,
9584
8609
  command: COMMAND$16,
@@ -9587,7 +8612,7 @@ const createCommand = {
9587
8612
  status: null
9588
8613
  }
9589
8614
  });
9590
- printLabel("Project Group ID", result.value.projectGroupId);
8615
+ printLabel("Project ID", result.value.projectGroupId);
9591
8616
  process.exitCode = 1;
9592
8617
  return;
9593
8618
  }
@@ -9603,13 +8628,25 @@ const createCommand = {
9603
8628
  const DEPLOY_POLL_INTERVAL_MS = 3e3;
9604
8629
  const DEPLOY_POLL_TIMEOUT_MS = 6e5;
9605
8630
  const DEPLOY_JITTER_MS = 500;
8631
+ const MAX_CONSECUTIVE_POLL_ERRORS = 5;
9606
8632
  const TERMINAL_STATUSES = new Set(["SUCCESS", "FAILED"]);
9607
8633
  async function waitForDeployment({ client, deploymentId, emit }) {
9608
8634
  const deadline = Date.now() + DEPLOY_POLL_TIMEOUT_MS;
9609
8635
  let lastStatus = null;
8636
+ let consecutiveErrors = 0;
9610
8637
  while (Date.now() < deadline) {
9611
8638
  const result = await client.getDeployment({ deploymentId });
9612
- if (result.isErr()) return err(result.error);
8639
+ if (result.isErr()) {
8640
+ consecutiveErrors += 1;
8641
+ if (consecutiveErrors >= MAX_CONSECUTIVE_POLL_ERRORS) return ok({
8642
+ outcome: "unconfirmed",
8643
+ deploymentId,
8644
+ reason: `Could not confirm deployment status after ${consecutiveErrors} consecutive polling errors (last: ${result.error.message}).`
8645
+ });
8646
+ await setTimeout$1(DEPLOY_POLL_INTERVAL_MS + Math.random() * DEPLOY_JITTER_MS);
8647
+ continue;
8648
+ }
8649
+ consecutiveErrors = 0;
9613
8650
  const { deployment } = result.value;
9614
8651
  if (deployment.status !== lastStatus) {
9615
8652
  lastStatus = deployment.status;
@@ -9636,10 +8673,12 @@ async function waitForDeployment({ client, deploymentId, emit }) {
9636
8673
  * error info if the deployment did not succeed, or null if it succeeded.
9637
8674
  */
9638
8675
  function getDeploymentError({ result, statusCommand }) {
9639
- if (result.outcome === "timeout") return {
9640
- message: `Deployment timed out. Check status with: ${statusCommand}`,
8676
+ if (result.outcome === "timeout" || result.outcome === "unconfirmed") return {
8677
+ message: `${result.outcome === "timeout" ? "Deployment did not reach a terminal status before the wait timed out" : result.reason} The deploy may still be in progress. Resume with: ${statusCommand}`,
9641
8678
  exitCode: 6,
9642
- buildLogs: null
8679
+ buildLogs: null,
8680
+ deploymentId: result.deploymentId,
8681
+ hint: `Resume with: ${statusCommand}`
9643
8682
  };
9644
8683
  if (result.deployment.status === "FAILED") {
9645
8684
  const reason = result.deployment.failureReason ?? null;
@@ -9647,7 +8686,9 @@ function getDeploymentError({ result, statusCommand }) {
9647
8686
  return {
9648
8687
  message: reason ?? (logs ? "Deployment failed. See build logs for details." : "Deployment failed (no logs available)."),
9649
8688
  exitCode: 1,
9650
- buildLogs: logs
8689
+ buildLogs: logs,
8690
+ deploymentId: result.deployment.id,
8691
+ hint: null
9651
8692
  };
9652
8693
  }
9653
8694
  return null;
@@ -9842,7 +8883,7 @@ const publishCommand = {
9842
8883
  emit
9843
8884
  });
9844
8885
  if (deployResult.isErr()) {
9845
- outputError({
8886
+ outputStreamError({
9846
8887
  argv,
9847
8888
  command: COMMAND$15,
9848
8889
  error: deployResult.error
@@ -9854,15 +8895,16 @@ const publishCommand = {
9854
8895
  statusCommand: `anything projects publish status ${argv.projectId} ${deploymentId}`
9855
8896
  });
9856
8897
  if (deployError) {
9857
- outputError({
8898
+ outputStreamError({
9858
8899
  argv,
9859
8900
  command: COMMAND$15,
9860
8901
  error: {
9861
- message: deployError.message,
8902
+ message: deployError.deploymentId ? `${deployError.message} (deploymentId: ${deployError.deploymentId})` : deployError.message,
9862
8903
  status: null
9863
8904
  },
9864
8905
  exitCode: deployError.exitCode,
9865
- buildLogs: deployError.buildLogs ?? void 0
8906
+ buildLogs: deployError.buildLogs ?? void 0,
8907
+ hint: deployError.hint ?? void 0
9866
8908
  });
9867
8909
  return;
9868
8910
  }
@@ -9993,20 +9035,24 @@ const list$1 = {
9993
9035
  });
9994
9036
  return;
9995
9037
  }
9038
+ const files = result.value.files;
9996
9039
  if (argv.json && outputSuccess({
9997
9040
  argv,
9998
9041
  command,
9999
- data: result.value
9042
+ data: {
9043
+ files,
9044
+ count: files.length
9045
+ }
10000
9046
  })) return;
10001
9047
  if (argv.quiet) {
10002
- for (const file of result.value.files) console.log(file.path);
9048
+ for (const file of files) console.log(file.path);
10003
9049
  return;
10004
9050
  }
10005
- if (result.value.files.length === 0) {
9051
+ if (files.length === 0) {
10006
9052
  console.log("No files found.");
10007
9053
  return;
10008
9054
  }
10009
- for (const file of result.value.files) console.log(file.path);
9055
+ for (const file of files) console.log(file.path);
10010
9056
  }
10011
9057
  };
10012
9058
  const get$1 = {
@@ -10051,13 +9097,17 @@ const get$1 = {
10051
9097
  });
10052
9098
  return;
10053
9099
  }
9100
+ const { path, content } = result.value.file;
10054
9101
  if (outputSuccess({
10055
9102
  argv,
10056
9103
  command,
10057
- data: result.value
9104
+ data: {
9105
+ path,
9106
+ content
9107
+ }
10058
9108
  })) return;
10059
- process.stdout.write(result.value.file.content);
10060
- if (!result.value.file.content.endsWith("\n")) process.stdout.write("\n");
9109
+ process.stdout.write(content);
9110
+ if (!content.endsWith("\n")) process.stdout.write("\n");
10061
9111
  }
10062
9112
  };
10063
9113
  const filesCommand = {
@@ -10151,18 +9201,12 @@ const generateCommand = {
10151
9201
  createNewThread: argv["new-thread"] ?? false
10152
9202
  });
10153
9203
  if (result.isErr()) {
10154
- if (argv.json) printNdjson({
10155
- type: "result",
10156
- ok: false,
10157
- error: { message: result.error.message }
10158
- });
10159
- else outputError({
9204
+ outputStreamError({
10160
9205
  argv,
10161
9206
  command: COMMAND$13,
10162
9207
  error: result.error,
10163
9208
  hint: "Verify the project and thread IDs are correct"
10164
9209
  });
10165
- process.exitCode = 1;
10166
9210
  return;
10167
9211
  }
10168
9212
  if (!argv.wait) {
@@ -10190,13 +9234,18 @@ const generateCommand = {
10190
9234
  status: "running",
10191
9235
  message: "Generation in progress..."
10192
9236
  });
10193
- if (await watchGeneration({
9237
+ const gen = await watchGeneration({
10194
9238
  config: config.value,
10195
9239
  client,
10196
9240
  projectGroupId: argv.projectId,
10197
9241
  emit
10198
- }) === false) {
10199
- process.exitCode = 1;
9242
+ });
9243
+ if (!gen.ok) {
9244
+ if (!argv.json && !argv.quiet && gen.error?.code === "still_building") printStillBuilding({
9245
+ projectId: argv.projectId,
9246
+ error: gen.error
9247
+ });
9248
+ else process.exitCode = 1;
10200
9249
  return;
10201
9250
  }
10202
9251
  if (argv.json) {
@@ -10329,7 +9378,8 @@ const infoCommand = {
10329
9378
  });
10330
9379
  return;
10331
9380
  }
10332
- const result = await new AnythingApiClient(config.value).getProject({ projectGroupId: argv.projectId });
9381
+ const client = new AnythingApiClient(config.value);
9382
+ const [result, statusResult] = await Promise.all([client.getProject({ projectGroupId: argv.projectId }), client.getProjectStatus({ projectGroupId: argv.projectId })]);
10333
9383
  if (result.isErr()) {
10334
9384
  outputError({
10335
9385
  argv,
@@ -10341,12 +9391,18 @@ const infoCommand = {
10341
9391
  }
10342
9392
  const info = result.value;
10343
9393
  const latestPublishedUrl = info.latestPublishedUrl ?? (info.slug ? `https://${info.slug}.created.app` : null);
9394
+ const { status, deployment } = statusResult.isOk() ? statusResult.value : {
9395
+ status: null,
9396
+ deployment: null
9397
+ };
10344
9398
  if (outputSuccess({
10345
9399
  argv,
10346
9400
  command: COMMAND$12,
10347
9401
  data: {
10348
9402
  ...info,
10349
- latestPublishedUrl
9403
+ status,
9404
+ latestPublishedUrl,
9405
+ deployment
10350
9406
  },
10351
9407
  primaryId: result.value.id
10352
9408
  })) return;
@@ -10354,9 +9410,12 @@ const infoCommand = {
10354
9410
  printLabel("Name", info.name);
10355
9411
  printLabel("ID", info.id);
10356
9412
  printLabel("Slug", info.slug);
9413
+ printLabel("Platform", info.platform);
10357
9414
  printLabel("Filesystem", info.filesystemVersion);
9415
+ printLabel("Status", status);
10358
9416
  printLabel("Dev Server", info.devServerUrl);
10359
9417
  printLabel("Published URL", latestPublishedUrl);
9418
+ if (deployment) printLabel("Deployment", formatDeploymentSummary(deployment));
10360
9419
  printLabel("Created", new Date(info.createdAt).toLocaleString());
10361
9420
  printLabel("Updated", new Date(info.updatedAt).toLocaleString());
10362
9421
  for (const url of info.publishedUrls) {
@@ -10858,7 +9917,7 @@ const projectStatusCommand = {
10858
9917
  printLabel("Status", status.status ?? "(no revisions yet)");
10859
9918
  printLabel("Latest Revision", status.latestRevisionId);
10860
9919
  printLabel("Updated", new Date(status.updatedAt).toLocaleString());
10861
- if (status.deployment) printLabel("Latest Deployment", `${status.deployment.status}${status.deployment.url ? ` — ${status.deployment.url}` : ""}`);
9920
+ if (status.deployment) printLabel("Latest Deployment", formatDeploymentSummary(status.deployment));
10862
9921
  else printLabel("Latest Deployment", "(none)");
10863
9922
  }
10864
9923
  };
@@ -10958,7 +10017,11 @@ const secretEnvironmentChoices = [
10958
10017
  "preview",
10959
10018
  "production"
10960
10019
  ];
10961
- const DEFAULT_SECRET_ENVIRONMENT = "DEVELOPMENT";
10020
+ const ALL_SECRET_ENVIRONMENTS = [
10021
+ "DEVELOPMENT",
10022
+ "PREVIEW",
10023
+ "PRODUCTION"
10024
+ ];
10962
10025
  const add = {
10963
10026
  command: "add <projectId>",
10964
10027
  describe: "Add a secret to an app",
@@ -10977,7 +10040,7 @@ const add = {
10977
10040
  type: "string",
10978
10041
  coerce: (value) => value.toLowerCase(),
10979
10042
  choices: secretEnvironmentChoices,
10980
- describe: "Target environment for the secret"
10043
+ describe: "Target a single environment. Omit to add the secret to all environments (development, preview, production) so it reaches the published app."
10981
10044
  }).option("force", {
10982
10045
  type: "boolean",
10983
10046
  default: false,
@@ -10985,16 +10048,17 @@ const add = {
10985
10048
  }).example("anything projects secrets add <id> --name KEY --value \"secret\"", "Add a secret from an inline value").example("cat secret.txt | anything projects secrets add <id> --name KEY", "Read a secret value from stdin"),
10986
10049
  handler: async (argv) => {
10987
10050
  const command = "projects secrets add";
10051
+ const targetEnvironments = argv.env ? [argv.env.toUpperCase()] : [...ALL_SECRET_ENVIRONMENTS];
10988
10052
  if (argv["dry-run"]) {
10989
10053
  outputDryRun({
10990
10054
  argv,
10991
10055
  command,
10992
- plannedActions: [{
10056
+ plannedActions: targetEnvironments.map((environment) => ({
10993
10057
  action: "add_secret",
10994
10058
  projectGroupId: argv.projectId,
10995
10059
  name: argv.name,
10996
- ...argv.env ? { environment: argv.env.toUpperCase() } : {}
10997
- }]
10060
+ environment
10061
+ }))
10998
10062
  });
10999
10063
  return;
11000
10064
  }
@@ -11032,16 +10096,16 @@ const add = {
11032
10096
  return;
11033
10097
  }
11034
10098
  const client = new AnythingApiClient(config.value);
11035
- const targetEnvironment = argv.env ? argv.env.toUpperCase() : DEFAULT_SECRET_ENVIRONMENT;
11036
10099
  if (!argv.force) {
11037
10100
  const existing = await client.listSecrets({ projectGroupId: argv.projectId });
11038
10101
  if (existing.isOk()) {
11039
- if (existing.value.secrets.find((secret) => secret.displayName === argv.name && secret.environment === targetEnvironment)) {
10102
+ const collisions = targetEnvironments.filter((environment) => existing.value.secrets.some((secret) => secret.displayName === argv.name && secret.environment === environment));
10103
+ if (collisions.length > 0) {
11040
10104
  outputError({
11041
10105
  argv,
11042
10106
  command,
11043
10107
  error: {
11044
- message: `A secret named "${argv.name}" already exists in ${targetEnvironment}.`,
10108
+ message: `A secret named "${argv.name}" already exists in ${collisions.join(", ")}.`,
11045
10109
  status: 409
11046
10110
  },
11047
10111
  hint: "Remove the existing secret first, or pass --force to create a suffixed sibling."
@@ -11050,31 +10114,41 @@ const add = {
11050
10114
  }
11051
10115
  }
11052
10116
  }
11053
- const result = await client.addSecret({
11054
- projectGroupId: argv.projectId,
11055
- displayName: argv.name,
11056
- value: valueResult.value,
11057
- environment: targetEnvironment
11058
- });
11059
- if (result.isErr()) {
11060
- outputError({
11061
- argv,
11062
- command,
11063
- error: result.error
10117
+ const added = [];
10118
+ for (const environment of targetEnvironments) {
10119
+ const result = await client.addSecret({
10120
+ projectGroupId: argv.projectId,
10121
+ displayName: argv.name,
10122
+ value: valueResult.value,
10123
+ environment
10124
+ });
10125
+ if (result.isErr()) {
10126
+ outputError({
10127
+ argv,
10128
+ command,
10129
+ error: result.error
10130
+ });
10131
+ return;
10132
+ }
10133
+ added.push({
10134
+ id: result.value.secret.id,
10135
+ envKey: result.value.secret.envKey,
10136
+ environment: result.value.secret.environment
11064
10137
  });
11065
- return;
11066
10138
  }
10139
+ const environments = added.map((s) => s.environment);
11067
10140
  if (outputSuccess({
11068
10141
  argv,
11069
10142
  command,
11070
- data: result.value,
11071
- primaryId: result.value.secret.id
10143
+ data: {
10144
+ secrets: added,
10145
+ environments
10146
+ },
10147
+ primaryId: added[0]?.id
11072
10148
  })) return;
11073
- const s = result.value.secret;
11074
- printSuccess("Secret added.");
11075
- printLabel("ID", s.id);
11076
- printLabel("Env Key", s.envKey);
11077
- printLabel("Environment", s.environment);
10149
+ printSuccess(`Secret added to ${environments.join(", ")}.`);
10150
+ printLabel("Env Key", added[0]?.envKey ?? argv.name);
10151
+ for (const s of added) printLabel(`ID (${s.environment})`, s.id);
11078
10152
  }
11079
10153
  };
11080
10154
  const remove = {
@@ -11400,29 +10474,251 @@ const set = {
11400
10474
  });
11401
10475
  return;
11402
10476
  }
11403
- const secretEnvironment = resolveSecretEnvironment(argv.env);
11404
- if (secretEnvironment === null) {
10477
+ const secretEnvironment = resolveSecretEnvironment(argv.env);
10478
+ if (secretEnvironment === null) {
10479
+ outputError({
10480
+ argv,
10481
+ command,
10482
+ error: {
10483
+ message: `Invalid --env value "${argv.env}".`,
10484
+ status: null
10485
+ },
10486
+ exitCode: 2
10487
+ });
10488
+ return;
10489
+ }
10490
+ const secretsResult = parseSecrets({
10491
+ secretArgs: argv.secret ?? [],
10492
+ environment: secretEnvironment
10493
+ });
10494
+ if (!secretsResult.ok) {
10495
+ outputError({
10496
+ argv,
10497
+ command,
10498
+ error: {
10499
+ message: secretsResult.error,
10500
+ status: null
10501
+ },
10502
+ exitCode: 2
10503
+ });
10504
+ return;
10505
+ }
10506
+ if (argv["dry-run"]) {
10507
+ outputDryRun({
10508
+ argv,
10509
+ command,
10510
+ plannedActions: [{
10511
+ action: "update_auth_settings",
10512
+ projectGroupId,
10513
+ provider: argv.provider,
10514
+ enabled: argv.enabled,
10515
+ environment: secretEnvironment,
10516
+ secretKeys: secretsResult.value.map((secret) => secret.envKey)
10517
+ }]
10518
+ });
10519
+ return;
10520
+ }
10521
+ const config = resolveConfig({
10522
+ dev: argv.dev,
10523
+ apiUrl: argv.apiUrl
10524
+ });
10525
+ if (config.isErr()) {
10526
+ outputError({
10527
+ argv,
10528
+ command,
10529
+ error: {
10530
+ message: config.error.message,
10531
+ status: null
10532
+ },
10533
+ exitCode: 4
10534
+ });
10535
+ return;
10536
+ }
10537
+ const result = await new AnythingApiClient(config.value).updateProjectAuthSettings({
10538
+ projectGroupId,
10539
+ provider: argv.provider,
10540
+ enabled: argv.enabled,
10541
+ secrets: secretsResult.value,
10542
+ enableForAllModules: false
10543
+ });
10544
+ if (result.isErr()) {
10545
+ outputError({
10546
+ argv,
10547
+ command,
10548
+ error: result.error
10549
+ });
10550
+ return;
10551
+ }
10552
+ if (outputSuccess({
10553
+ argv,
10554
+ command,
10555
+ data: result.value
10556
+ })) return;
10557
+ printSuccess("Auth settings updated.");
10558
+ printAuthSettings(result.value);
10559
+ }
10560
+ };
10561
+ const authSettingsCommand = {
10562
+ command: "auth <command>",
10563
+ describe: "Manage auth-related project settings",
10564
+ builder: (yargs) => yargs.command(get).command(set).demandCommand(),
10565
+ handler: () => {}
10566
+ };
10567
+
10568
+ //#endregion
10569
+ //#region src/commands/settings.ts
10570
+ const settingsCommand = {
10571
+ command: "settings <command>",
10572
+ describe: "Inspect and update project settings",
10573
+ builder: (yargs) => yargs.command(authSettingsCommand).example("anything projects settings auth get <project-id>", "Inspect project auth settings").demandCommand(),
10574
+ handler: () => {}
10575
+ };
10576
+
10577
+ //#endregion
10578
+ //#region src/commands/submit.ts
10579
+ const POLL_INTERVAL_MS = 2e3;
10580
+ const POLL_TIMEOUT_MS = 6e4;
10581
+ const STORE_CHOICES = ["app-store", "play-store"];
10582
+ async function waitForSubmission({ client, projectGroupId, submission }) {
10583
+ const deadline = Date.now() + POLL_TIMEOUT_MS;
10584
+ let current = submission;
10585
+ while (current.status === "PENDING" && Date.now() < deadline) {
10586
+ const latestResult = await client.getProjectSubmission({
10587
+ projectGroupId,
10588
+ submissionId: current.id
10589
+ });
10590
+ if (latestResult.isErr()) return latestResult.map((value) => value.submission);
10591
+ current = latestResult.value.submission;
10592
+ if (current.status !== "PENDING") return latestResult.map((value) => value.submission);
10593
+ await setTimeout$1(POLL_INTERVAL_MS);
10594
+ }
10595
+ return ok(current);
10596
+ }
10597
+ function printSubmissionResult({ argv, command, pendingMessage, submission }) {
10598
+ const { projectGroupId: projectId, ...submissionRest } = submission;
10599
+ const submissionOut = {
10600
+ projectId,
10601
+ ...submissionRest
10602
+ };
10603
+ if (submission.status === "FAILED") {
10604
+ printError(submission.errorMessage ?? "Submission failed.");
10605
+ process.exitCode = 1;
10606
+ return;
10607
+ }
10608
+ if (submission.status === "CREATED") {
10609
+ if (outputSuccess({
10610
+ argv,
10611
+ command,
10612
+ data: {
10613
+ success: true,
10614
+ submission: submissionOut
10615
+ },
10616
+ primaryId: submission.id
10617
+ })) return;
10618
+ printSuccess("App Store submission is ready.");
10619
+ printLabel("Submission ID", submission.id);
10620
+ printLabel("Launch URL", submission.launchUrl);
10621
+ printLabel("Auth URL", submission.authUrl);
10622
+ printLabel("Expires At", submission.expiresAt);
10623
+ return;
10624
+ }
10625
+ if (outputSuccess({
10626
+ argv,
10627
+ command,
10628
+ data: {
10629
+ success: true,
10630
+ submission
10631
+ },
10632
+ primaryId: submission.id
10633
+ })) return;
10634
+ printSuccess(pendingMessage);
10635
+ printLabel("Submission ID", submission.id);
10636
+ printLabel("Status", submission.status);
10637
+ printLabel("Next step", "Expo is still preparing the launch flow. Run the command again in a moment.");
10638
+ }
10639
+ const submitStatusCommand = {
10640
+ command: "status <projectId> <submissionId>",
10641
+ describe: "Check the status of an App Store submission",
10642
+ builder: (yargs) => yargs.positional("projectId", {
10643
+ type: "string",
10644
+ demandOption: true,
10645
+ describe: "The project ID"
10646
+ }).positional("submissionId", {
10647
+ type: "string",
10648
+ demandOption: true,
10649
+ describe: "The submission ID"
10650
+ }).example("anything projects submit status <project-id> <submission-id>", "Check a submission later").example("anything projects submit status <project-id> <submission-id> --json", "Return the submission status in JSON"),
10651
+ handler: async (argv) => {
10652
+ const command = "projects submit status";
10653
+ const config = resolveConfig({
10654
+ dev: argv.dev,
10655
+ apiUrl: argv.apiUrl
10656
+ });
10657
+ if (config.isErr()) {
10658
+ outputError({
10659
+ argv,
10660
+ command,
10661
+ error: {
10662
+ message: config.error.message,
10663
+ status: null
10664
+ },
10665
+ exitCode: 4
10666
+ });
10667
+ return;
10668
+ }
10669
+ const result = await new AnythingApiClient(config.value).getProjectSubmission({
10670
+ projectGroupId: argv.projectId,
10671
+ submissionId: argv.submissionId
10672
+ });
10673
+ if (result.isErr()) {
10674
+ outputError({
10675
+ argv,
10676
+ command,
10677
+ error: result.error
10678
+ });
10679
+ return;
10680
+ }
10681
+ printSubmissionResult({
10682
+ argv,
10683
+ command,
10684
+ pendingMessage: "Submission is still preparing.",
10685
+ submission: result.value.submission
10686
+ });
10687
+ }
10688
+ };
10689
+ const submitCommand = {
10690
+ command: "submit <projectId>",
10691
+ describe: "Start an App Store submission for an app",
10692
+ builder: (yargs) => yargs.command(submitStatusCommand).positional("projectId", {
10693
+ type: "string",
10694
+ demandOption: true,
10695
+ describe: "The project ID"
10696
+ }).option("store", {
10697
+ type: "string",
10698
+ choices: STORE_CHOICES,
10699
+ describe: "Submission target store"
10700
+ }).example("anything projects submit <project-id> --store app-store", "Start an App Store submission").example("anything projects submit <project-id> --store play-store", "Start a Play Store submission").example("anything projects submit <project-id> --store app-store --json", "Return the submission session in JSON").example("anything projects submit status <project-id> <submission-id>", "Check a submission later"),
10701
+ handler: async (argv) => {
10702
+ const command = "projects submit";
10703
+ if (argv.store === void 0) {
11405
10704
  outputError({
11406
10705
  argv,
11407
10706
  command,
11408
10707
  error: {
11409
- message: `Invalid --env value "${argv.env}".`,
10708
+ message: "Missing required argument: store",
11410
10709
  status: null
11411
10710
  },
11412
10711
  exitCode: 2
11413
10712
  });
11414
10713
  return;
11415
10714
  }
11416
- const secretsResult = parseSecrets({
11417
- secretArgs: argv.secret ?? [],
11418
- environment: secretEnvironment
11419
- });
11420
- if (!secretsResult.ok) {
10715
+ const store = STORE_CHOICES.find((s) => s === argv.store);
10716
+ if (!store) {
11421
10717
  outputError({
11422
10718
  argv,
11423
10719
  command,
11424
10720
  error: {
11425
- message: secretsResult.error,
10721
+ message: `Unsupported store: ${argv.store}`,
11426
10722
  status: null
11427
10723
  },
11428
10724
  exitCode: 2
@@ -11434,12 +10730,9 @@ const set = {
11434
10730
  argv,
11435
10731
  command,
11436
10732
  plannedActions: [{
11437
- action: "update_auth_settings",
11438
- projectGroupId,
11439
- provider: argv.provider,
11440
- enabled: argv.enabled,
11441
- environment: secretEnvironment,
11442
- secretKeys: secretsResult.value.map((secret) => secret.envKey)
10733
+ action: "submit_project",
10734
+ projectGroupId: argv.projectId,
10735
+ store
11443
10736
  }]
11444
10737
  });
11445
10738
  return;
@@ -11460,45 +10753,40 @@ const set = {
11460
10753
  });
11461
10754
  return;
11462
10755
  }
11463
- const result = await new AnythingApiClient(config.value).updateProjectAuthSettings({
11464
- projectGroupId,
11465
- provider: argv.provider,
11466
- enabled: argv.enabled,
11467
- secrets: secretsResult.value,
11468
- enableForAllModules: false
10756
+ const client = new AnythingApiClient(config.value);
10757
+ const startResult = await client.submitProject({
10758
+ projectGroupId: argv.projectId,
10759
+ store
11469
10760
  });
11470
- if (result.isErr()) {
10761
+ if (startResult.isErr()) {
11471
10762
  outputError({
11472
10763
  argv,
11473
10764
  command,
11474
- error: result.error
10765
+ error: startResult.error
11475
10766
  });
11476
10767
  return;
11477
10768
  }
11478
- if (outputSuccess({
10769
+ const finalResult = await waitForSubmission({
10770
+ client,
10771
+ projectGroupId: argv.projectId,
10772
+ submission: startResult.value.submission
10773
+ });
10774
+ if (finalResult.isErr()) {
10775
+ outputError({
10776
+ argv,
10777
+ command,
10778
+ error: finalResult.error
10779
+ });
10780
+ return;
10781
+ }
10782
+ printSubmissionResult({
11479
10783
  argv,
11480
10784
  command,
11481
- data: result.value
11482
- })) return;
11483
- printSuccess("Auth settings updated.");
11484
- printAuthSettings(result.value);
10785
+ pendingMessage: "Submission started.",
10786
+ submission: finalResult.value
10787
+ });
11485
10788
  }
11486
10789
  };
11487
- const authSettingsCommand = {
11488
- command: "auth <command>",
11489
- describe: "Manage auth-related project settings",
11490
- builder: (yargs) => yargs.command(get).command(set).demandCommand(),
11491
- handler: () => {}
11492
- };
11493
-
11494
- //#endregion
11495
- //#region src/commands/settings.ts
11496
- const settingsCommand = {
11497
- command: "settings <command>",
11498
- describe: "Inspect and update project settings",
11499
- builder: (yargs) => yargs.command(authSettingsCommand).example("anything projects settings auth get <project-id>", "Inspect project auth settings").demandCommand(),
11500
- handler: () => {}
11501
- };
11502
10790
 
11503
10791
  //#endregion
11504
10792
  //#region src/commands/unpublish.ts
@@ -11961,7 +11249,7 @@ const shipCommand = {
11961
11249
  apiUrl: argv.apiUrl
11962
11250
  });
11963
11251
  if (config.isErr()) {
11964
- outputError({
11252
+ outputStreamError({
11965
11253
  argv,
11966
11254
  command: COMMAND$4,
11967
11255
  error: {
@@ -11983,7 +11271,7 @@ const shipCommand = {
11983
11271
  nonInteractive: isNonInteractive(argv)
11984
11272
  });
11985
11273
  if (!orgResult.ok) {
11986
- outputError({
11274
+ outputStreamError({
11987
11275
  argv,
11988
11276
  command: COMMAND$4,
11989
11277
  error: {
@@ -12006,7 +11294,7 @@ const shipCommand = {
12006
11294
  name: argv.name ?? null
12007
11295
  });
12008
11296
  if (createResult.isErr()) {
12009
- outputError({
11297
+ outputStreamError({
12010
11298
  argv,
12011
11299
  command: COMMAND$4,
12012
11300
  error: createResult.error
@@ -12034,7 +11322,7 @@ const shipCommand = {
12034
11322
  createNewThread: false
12035
11323
  });
12036
11324
  if (genResult.isErr()) {
12037
- outputError({
11325
+ outputStreamError({
12038
11326
  argv,
12039
11327
  command: COMMAND$4,
12040
11328
  error: genResult.error
@@ -12054,13 +11342,18 @@ const shipCommand = {
12054
11342
  status: "running",
12055
11343
  message: "Generation in progress..."
12056
11344
  });
12057
- if (await watchGeneration({
11345
+ const gen = await watchGeneration({
12058
11346
  config: config.value,
12059
11347
  client,
12060
11348
  projectGroupId,
12061
11349
  emit
12062
- }) === false) {
11350
+ });
11351
+ if (!gen.ok) {
12063
11352
  if (argv.json || argv.quiet) process.exitCode = 1;
11353
+ else if (gen.error?.code === "still_building") printStillBuilding({
11354
+ projectId: projectGroupId,
11355
+ error: gen.error
11356
+ });
12064
11357
  else outputError({
12065
11358
  argv,
12066
11359
  command: COMMAND$4,
@@ -12098,7 +11391,7 @@ const shipCommand = {
12098
11391
  slug: argv.slug ?? null
12099
11392
  });
12100
11393
  if (publishResult.isErr()) {
12101
- outputError({
11394
+ outputStreamError({
12102
11395
  argv,
12103
11396
  command: COMMAND$4,
12104
11397
  error: publishResult.error
@@ -12113,7 +11406,7 @@ const shipCommand = {
12113
11406
  emit
12114
11407
  });
12115
11408
  if (deployResult.isErr()) {
12116
- outputError({
11409
+ outputStreamError({
12117
11410
  argv,
12118
11411
  command: COMMAND$4,
12119
11412
  error: deployResult.error
@@ -12125,15 +11418,16 @@ const shipCommand = {
12125
11418
  statusCommand: `anything projects publish status ${projectGroupId} ${deploymentId}`
12126
11419
  });
12127
11420
  if (deployError) {
12128
- outputError({
11421
+ outputStreamError({
12129
11422
  argv,
12130
11423
  command: COMMAND$4,
12131
11424
  error: {
12132
- message: deployError.message,
11425
+ message: deployError.deploymentId ? `${deployError.message} (deploymentId: ${deployError.deploymentId})` : deployError.message,
12133
11426
  status: null
12134
11427
  },
12135
11428
  exitCode: deployError.exitCode,
12136
- buildLogs: deployError.buildLogs ?? void 0
11429
+ buildLogs: deployError.buildLogs ?? void 0,
11430
+ hint: deployError.hint ?? void 0
12137
11431
  });
12138
11432
  return;
12139
11433
  }
@@ -12426,119 +11720,6 @@ const switchCommand = {
12426
11720
  }
12427
11721
  };
12428
11722
 
12429
- //#endregion
12430
- //#region src/update-check.ts
12431
- const PACKAGE_NAME = "@anythingai/cli";
12432
- const REGISTRY_BASE_URL = `https://registry.npmjs.org/${PACKAGE_NAME}`;
12433
- const REGISTRY_URL = `${REGISTRY_BASE_URL}/latest`;
12434
- const INTERNAL_UPDATE_CHECK_ARG = "__update-check";
12435
- const CHECK_INTERVAL_MS = 10800 * 1e3;
12436
- const REFRESH_FETCH_TIMEOUT_MS = 1e4;
12437
- const latestManifestSchema = z.object({ version: z.string() });
12438
- function isNewerVersion(candidate, current) {
12439
- const core = (v) => (v.split("-")[0] ?? "").split(".").map((part) => Number.parseInt(part, 10));
12440
- const a = core(candidate);
12441
- const b = core(current);
12442
- if ([...a, ...b].some(Number.isNaN)) return false;
12443
- for (let i = 0; i < 3; i++) {
12444
- const left = a[i] ?? 0;
12445
- const right = b[i] ?? 0;
12446
- if (left !== right) return left > right;
12447
- }
12448
- return false;
12449
- }
12450
- async function fetchLatestVersion({ timeoutMs }) {
12451
- try {
12452
- const response = await fetch(REGISTRY_URL, {
12453
- signal: AbortSignal.timeout(timeoutMs),
12454
- headers: { accept: "application/json" }
12455
- });
12456
- if (!response.ok) return null;
12457
- const parsed = latestManifestSchema.safeParse(await response.json());
12458
- return parsed.success ? parsed.data.version : null;
12459
- } catch {
12460
- return null;
12461
- }
12462
- }
12463
- async function lookupVersion({ version, timeoutMs }) {
12464
- try {
12465
- const response = await fetch(`${REGISTRY_BASE_URL}/${encodeURIComponent(version)}`, {
12466
- signal: AbortSignal.timeout(timeoutMs),
12467
- headers: { accept: "application/json" }
12468
- });
12469
- if (response.status === 404) return { status: "not-found" };
12470
- if (!response.ok) return { status: "unreachable" };
12471
- return latestManifestSchema.safeParse(await response.json()).success ? { status: "exists" } : { status: "not-found" };
12472
- } catch {
12473
- return { status: "unreachable" };
12474
- }
12475
- }
12476
- function printUpdateNotice({ current, latest }) {
12477
- console.error([
12478
- "",
12479
- styleText("yellow", `Update available for ${PACKAGE_NAME}: ${current} → ${latest}`),
12480
- styleText("dim", "Run `anything update` to update."),
12481
- ""
12482
- ].join("\n"));
12483
- }
12484
- function spawnBackgroundRefresh() {
12485
- const entry = process.argv[1];
12486
- if (!entry) return;
12487
- try {
12488
- spawn(process.execPath, [entry, INTERNAL_UPDATE_CHECK_ARG], {
12489
- detached: true,
12490
- stdio: "ignore",
12491
- windowsHide: true,
12492
- env: backgroundRefreshEnv()
12493
- }).unref();
12494
- } catch {}
12495
- }
12496
- function backgroundRefreshEnv() {
12497
- const allowed = [
12498
- "PATH",
12499
- "HOME",
12500
- "XDG_CONFIG_HOME",
12501
- "APPDATA",
12502
- "LOCALAPPDATA",
12503
- "SystemRoot"
12504
- ];
12505
- const env = {};
12506
- for (const key of allowed) {
12507
- const value = process.env[key];
12508
- if (value !== void 0) env[key] = value;
12509
- }
12510
- return env;
12511
- }
12512
- async function refreshUpdateCheckCache(now) {
12513
- recordUpdateCheck({
12514
- checkedAt: now,
12515
- latestVersion: await fetchLatestVersion({ timeoutMs: REFRESH_FETCH_TIMEOUT_MS })
12516
- });
12517
- }
12518
- function notifyIfUpdateAvailable(now) {
12519
- const state = getUpdateCheckState();
12520
- const latest = state.latestKnownVersion;
12521
- if (latest && isNewerVersion(latest, CLI_VERSION) && state.notifiedVersion !== latest) {
12522
- printUpdateNotice({
12523
- current: CLI_VERSION,
12524
- latest
12525
- });
12526
- recordUpdateNotified(latest);
12527
- }
12528
- if (!(state.checkedAt === null || now - state.checkedAt >= CHECK_INTERVAL_MS)) return;
12529
- recordUpdateCheck({
12530
- checkedAt: now,
12531
- latestVersion: null
12532
- });
12533
- spawnBackgroundRefresh();
12534
- }
12535
- function maybeNotifyUpdate(argv, now) {
12536
- if (argv.json || argv.quiet) return;
12537
- if (isNonInteractive(argv)) return;
12538
- if (!process.stderr.isTTY) return;
12539
- notifyIfUpdateAvailable(now);
12540
- }
12541
-
12542
11723
  //#endregion
12543
11724
  //#region src/commands/update.ts
12544
11725
  const COMMAND$1 = "update";
@@ -12799,9 +11980,6 @@ const updateCommand = {
12799
11980
 
12800
11981
  //#endregion
12801
11982
  //#region src/commands/user.ts
12802
- function formatCredits(creditBalance) {
12803
- return `${humanizeCredits(creditBalance)} credits`;
12804
- }
12805
11983
  const COMMAND = "user";
12806
11984
  const userCommand = {
12807
11985
  command: "user",
@@ -12840,14 +12018,14 @@ const userCommand = {
12840
12018
  }
12841
12019
  const activeOrgId = getStoredOrgId();
12842
12020
  const defaultOrganization = result.value.organizations[0] ?? null;
12843
- const organizationWithCredits = result.value.organizations.find((org) => BigInt(org.creditBalance) > 0n) ?? null;
12844
- const recommendedOrganization = defaultOrganization !== null && BigInt(defaultOrganization.creditBalance) > 0n ? defaultOrganization : organizationWithCredits;
12021
+ const organizationWithCredits = result.value.organizations.find((org) => org.creditsBalance > 0) ?? null;
12022
+ const recommendedOrganization = defaultOrganization !== null && defaultOrganization.creditsBalance > 0 ? defaultOrganization : organizationWithCredits;
12845
12023
  const credentialSource = env.ANYTHING_API_KEY ? "env" : configExists() ? "config" : "unknown";
12846
12024
  const checks = {
12847
12025
  hasOrganizations: result.value.organizations.length > 0,
12848
12026
  hasPaidOrganization: result.value.organizations.some((org) => org.isPaid),
12849
12027
  hasCredits: organizationWithCredits !== null,
12850
- defaultOrganizationHasCredits: defaultOrganization !== null ? BigInt(defaultOrganization.creditBalance) > 0n : null
12028
+ defaultOrganizationHasCredits: defaultOrganization !== null ? defaultOrganization.creditsBalance > 0 : null
12851
12029
  };
12852
12030
  const activeOrg = activeOrgId ? result.value.organizations.find((o) => o.id === activeOrgId) ?? null : null;
12853
12031
  if (argv.quiet && !argv.json) {
@@ -12916,7 +12094,7 @@ const userCommand = {
12916
12094
  org.id === activeOrgId ? "*" : "",
12917
12095
  org.name,
12918
12096
  org.planDisplayName,
12919
- formatCredits(org.creditBalance),
12097
+ `${org.creditsBalance} credits`,
12920
12098
  org.id
12921
12099
  ])
12922
12100
  });
@@ -12928,7 +12106,7 @@ const userCommand = {
12928
12106
  if (!activeOrgId && recommendedOrganization !== null) {
12929
12107
  console.log();
12930
12108
  console.log(`No active organization set. Run \`anything orgs set ${recommendedOrganization.id}\` to set one.`);
12931
- } else if (activeOrg !== null && BigInt(activeOrg.creditBalance) === 0n && recommendedOrganization !== null && recommendedOrganization.id !== activeOrg.id) {
12109
+ } else if (activeOrg !== null && activeOrg.creditsBalance === 0 && recommendedOrganization !== null && recommendedOrganization.id !== activeOrg.id) {
12932
12110
  console.log();
12933
12111
  console.log(`Active organization has no credits. Run \`anything orgs set ${recommendedOrganization.id}\` to switch.`);
12934
12112
  }
@@ -13081,17 +12259,192 @@ const watchCommand = {
13081
12259
  };
13082
12260
 
13083
12261
  //#endregion
13084
- //#region src/cli.ts
13085
- const REGISTERED_COMMAND_PATHS = (() => {
12262
+ //#region src/command-tree.ts
12263
+ function getRootCommands() {
12264
+ return [
12265
+ assetsCommand,
12266
+ authCommand,
12267
+ databasesCommand,
12268
+ deploymentsCommand,
12269
+ domainsCommand,
12270
+ introspectCommand,
12271
+ linkCommand,
12272
+ unlinkCommand,
12273
+ llmContextCommand,
12274
+ membersCommand,
12275
+ orgsCommand,
12276
+ projectsCommand,
12277
+ pullCommand,
12278
+ shipCommand,
12279
+ skillCommand,
12280
+ statusCommand,
12281
+ switchCommand,
12282
+ updateCommand,
12283
+ userCommand,
12284
+ watchCommand
12285
+ ];
12286
+ }
12287
+ function firstCommandString(command) {
12288
+ return Array.isArray(command) ? command[0] ?? "" : command;
12289
+ }
12290
+ function commandWord(command) {
12291
+ const word = firstCommandString(command).trim().split(/\s+/)[0];
12292
+ return word && !/^[<[]/.test(word) ? word : null;
12293
+ }
12294
+ function normalizeChoices(choices) {
12295
+ if (!choices) return void 0;
12296
+ return choices.map((choice) => String(choice));
12297
+ }
12298
+ function positionalsFromCommandString(command) {
12299
+ const tokens = firstCommandString(command).trim().split(/\s+/);
12300
+ const out = [];
12301
+ for (const token of tokens) {
12302
+ const match = /^([<[])([^>\]]+)([>\]])$/.exec(token);
12303
+ if (!match) continue;
12304
+ const [, open, key] = match;
12305
+ if (key === void 0) continue;
12306
+ out.push({
12307
+ displayName: token,
12308
+ key,
12309
+ required: open === "<"
12310
+ });
12311
+ }
12312
+ return out;
12313
+ }
12314
+ function inspectBuilder(mod) {
12315
+ const children = [];
12316
+ const positionals = /* @__PURE__ */ new Map();
12317
+ const options = [];
12318
+ for (const positional of positionalsFromCommandString(mod.command ?? "")) positionals.set(positional.key, {
12319
+ name: positional.displayName,
12320
+ type: "string",
12321
+ required: positional.required
12322
+ });
12323
+ const builder = mod.builder;
12324
+ if (typeof builder !== "function") return {
12325
+ children,
12326
+ positionals,
12327
+ options
12328
+ };
12329
+ const proxy = new Proxy({}, { get(_target, key) {
12330
+ if (key === "command") return (child) => {
12331
+ children.push(child);
12332
+ return proxy;
12333
+ };
12334
+ if (key === "positional") return (name, config) => {
12335
+ const existing = positionals.get(name);
12336
+ const choices = normalizeChoices(config.choices);
12337
+ positionals.set(name, {
12338
+ name: existing?.name ?? `<${name}>`,
12339
+ type: config.type ?? "string",
12340
+ required: existing?.required ?? config.demandOption === true,
12341
+ ...choices ? { choices } : {}
12342
+ });
12343
+ return proxy;
12344
+ };
12345
+ if (key === "option") return (name, config) => {
12346
+ const choices = normalizeChoices(config.choices);
12347
+ options.push({
12348
+ name: `--${name}`,
12349
+ type: config.type ?? "string",
12350
+ required: config.demandOption === true,
12351
+ ...choices ? { choices } : {}
12352
+ });
12353
+ if (config.type === "boolean" && config.default === true) options.push({
12354
+ name: `--no-${name}`,
12355
+ type: "boolean",
12356
+ required: false
12357
+ });
12358
+ return proxy;
12359
+ };
12360
+ return () => proxy;
12361
+ } });
12362
+ builder(proxy);
12363
+ return {
12364
+ children,
12365
+ positionals,
12366
+ options
12367
+ };
12368
+ }
12369
+ function inspectionFlags({ positionals, options }) {
12370
+ return [...positionals.values(), ...options];
12371
+ }
12372
+ function leafWord(name) {
12373
+ return name.trim().split(/\s+/).at(-1) ?? "";
12374
+ }
12375
+ function isConfirmationFlag(flagName) {
12376
+ return flagName === "--yes";
12377
+ }
12378
+ const DESTRUCTIVE_VERBS = new Set([
12379
+ "delete",
12380
+ "remove",
12381
+ "reset",
12382
+ "rollback",
12383
+ "unpublish",
12384
+ "logout"
12385
+ ]);
12386
+ const NON_IDEMPOTENT_VERBS = new Set([
12387
+ "create",
12388
+ "generate",
12389
+ "add",
12390
+ "upload",
12391
+ "invite",
12392
+ "duplicate",
12393
+ "submit",
12394
+ "ship",
12395
+ "rollback"
12396
+ ]);
12397
+ const NON_IDEMPOTENT_OVERRIDE = new Set([
12398
+ "databases reset",
12399
+ "databases delete",
12400
+ "projects delete",
12401
+ "projects settings auth set"
12402
+ ]);
12403
+ function isDestructive(name, flags) {
12404
+ if (DESTRUCTIVE_VERBS.has(leafWord(name))) return true;
12405
+ return flags.some((flag) => isConfirmationFlag(flag.name));
12406
+ }
12407
+ function isIdempotent(name) {
12408
+ if (NON_IDEMPOTENT_VERBS.has(leafWord(name))) return false;
12409
+ return !NON_IDEMPOTENT_OVERRIDE.has(name);
12410
+ }
12411
+ function buildCommandTree(roots = getRootCommands()) {
12412
+ const out = [];
12413
+ const visit = (modules, prefix) => {
12414
+ for (const mod of modules) {
12415
+ const word = commandWord(mod.command ?? "");
12416
+ if (!word) continue;
12417
+ const name = prefix ? `${prefix} ${word}` : word;
12418
+ const inspection = inspectBuilder(mod);
12419
+ const flags = inspectionFlags(inspection);
12420
+ out.push({
12421
+ name,
12422
+ flags,
12423
+ idempotent: isIdempotent(name),
12424
+ destructive: isDestructive(name, flags)
12425
+ });
12426
+ visit(inspection.children, name);
12427
+ }
12428
+ };
12429
+ visit(roots, "");
12430
+ return out;
12431
+ }
12432
+ function registeredCommandPaths(roots = getRootCommands()) {
13086
12433
  const paths = /* @__PURE__ */ new Set();
13087
- for (const { name } of commandTree) {
13088
- const words = name.split(" ");
13089
- for (let i = 1; i <= words.length; i++) paths.add(words.slice(0, i).join(" "));
13090
- }
13091
- paths.add("dev");
13092
- paths.add("update");
12434
+ for (const { name } of buildCommandTree(roots)) paths.add(name);
12435
+ return paths;
12436
+ }
12437
+
12438
+ //#endregion
12439
+ //#region src/cli.ts
12440
+ let registeredPathsCache = null;
12441
+ function getRegisteredCommandPaths() {
12442
+ if (registeredPathsCache) return registeredPathsCache;
12443
+ const paths = registeredCommandPaths();
12444
+ if (isDevEnvironment()) paths.add("dev");
12445
+ registeredPathsCache = paths;
13093
12446
  return paths;
13094
- })();
12447
+ }
13095
12448
  var HandledCliError = class extends Error {};
13096
12449
  function commandPathFromArgv(argv) {
13097
12450
  const words = [];
@@ -13101,10 +12454,11 @@ function commandPathFromArgv(argv) {
13101
12454
  }
13102
12455
  const [firstWord] = words;
13103
12456
  if (firstWord === void 0) return null;
12457
+ const registeredPaths = getRegisteredCommandPaths();
13104
12458
  let matched = "";
13105
12459
  for (let i = 0; i < words.length; i++) {
13106
12460
  const candidate = words.slice(0, i + 1).join(" ");
13107
- if (!REGISTERED_COMMAND_PATHS.has(candidate)) break;
12461
+ if (!registeredPaths.has(candidate)) break;
13108
12462
  matched = candidate;
13109
12463
  }
13110
12464
  return matched === "" ? firstWord : matched;
@@ -13148,7 +12502,7 @@ function createCli(argv) {
13148
12502
  "dry-run": args["dry-run"] === true,
13149
12503
  dev: args.dev === true
13150
12504
  }, Date.now());
13151
- }).command(assetsCommand).command(authCommand).command(databasesCommand).command(deploymentsCommand).command(domainsCommand).command(introspectCommand).command(linkCommand).command(llmContextCommand).command(membersCommand).command(orgsCommand).command(projectsCommand).command(pullCommand).command(shipCommand).command(skillCommand).command(statusCommand).command(switchCommand).command(unlinkCommand).command(updateCommand).command(userCommand).command(watchCommand).demandCommand(1, "Specify a command. Run --help for usage.").strict().wrap(null).version(CLI_VERSION).help().fail((msg, err, instance) => {
12505
+ }).demandCommand(1, "Specify a command. Run --help for usage.").strict().wrap(null).version(CLI_VERSION).help().fail((msg, err, instance) => {
13152
12506
  const isJson = argv.includes("--json");
13153
12507
  const message = err ? err.message || String(err) : msg;
13154
12508
  if (err) console.error(message);
@@ -13156,7 +12510,7 @@ function createCli(argv) {
13156
12510
  if (!isJson) instance.showHelp("error");
13157
12511
  console.error(`\n${message}`);
13158
12512
  }
13159
- if (isJson) console.error(JSON.stringify({
12513
+ if (isJson) console.log(JSON.stringify({
13160
12514
  ok: false,
13161
12515
  command: commandPathFromArgv(argv),
13162
12516
  error: {
@@ -13167,6 +12521,7 @@ function createCli(argv) {
13167
12521
  process.exitCode = EXIT_INVALID_ARGS;
13168
12522
  throw new HandledCliError(message);
13169
12523
  }).exitProcess(false);
12524
+ for (const command of getRootCommands()) cli.command(command);
13170
12525
  if (isDevEnvironment()) cli.command(devCommand);
13171
12526
  return cli;
13172
12527
  }