@contentful/experience-design-system-cli 2.37.1-dev-build-8757f66c.0 → 2.37.1-dev-build-7d013617.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -57,6 +57,27 @@ var init_legacy_cli_path = __esm({
57
57
  }
58
58
  });
59
59
 
60
+ // packages/experience-design-system-cli/src/commands/import-options.ts
61
+ function toImportOptions(raw) {
62
+ return {
63
+ ...raw.agent ? { agent: raw.agent } : {},
64
+ prompt: raw.prompt ?? [],
65
+ cache: raw.cache !== false
66
+ };
67
+ }
68
+ function importOptionArgs(options) {
69
+ return [
70
+ ...options.agent ? ["--agent", options.agent] : [],
71
+ ...options.prompt.flatMap((value) => ["--prompt", value]),
72
+ ...options.cache ? [] : ["--no-cache"]
73
+ ];
74
+ }
75
+ var init_import_options = __esm({
76
+ "packages/experience-design-system-cli/src/commands/import-options.ts"() {
77
+ "use strict";
78
+ }
79
+ });
80
+
60
81
  // packages/experience-design-system-cli/src/tui/home/home.theme.ts
61
82
  function brandBar(width, ramp = BRAND_RAMP) {
62
83
  if (width <= 0 || ramp.length === 0) return [];
@@ -2875,15 +2896,15 @@ import { statSync as statSync2 } from "node:fs";
2875
2896
  import path4 from "node:path";
2876
2897
  function collectFiles(root, options = {}) {
2877
2898
  const resolved = path4.resolve(root);
2878
- let stat;
2899
+ let stat2;
2879
2900
  try {
2880
- stat = statSync2(resolved);
2901
+ stat2 = statSync2(resolved);
2881
2902
  } catch (err) {
2882
2903
  return { ok: false, failure: classifyStatError(err.code), rootPath: resolved };
2883
2904
  }
2884
- if (stat.isFile())
2905
+ if (stat2.isFile())
2885
2906
  return { ok: false, failure: "is-file", rootPath: resolved };
2886
- if (!stat.isDirectory())
2907
+ if (!stat2.isDirectory())
2887
2908
  return { ok: false, failure: "not-directory", rootPath: resolved };
2888
2909
  const result = {
2889
2910
  filePaths: [],
@@ -3202,11 +3223,9 @@ var init_resolve_session_id = __esm({
3202
3223
  });
3203
3224
 
3204
3225
  // packages/experience-design-system-backend-pipeline/dist/src/persistence/src/credentials/helpers/host-utils.js
3205
- var DEFAULT_CONFIGURED_HOST;
3206
3226
  var init_host_utils = __esm({
3207
3227
  "packages/experience-design-system-backend-pipeline/dist/src/persistence/src/credentials/helpers/host-utils.js"() {
3208
3228
  "use strict";
3209
- DEFAULT_CONFIGURED_HOST = "api.contentful.com";
3210
3229
  }
3211
3230
  });
3212
3231
 
@@ -3681,9 +3700,9 @@ var init_utils_gen = __esm({
3681
3700
  config.headers = mergeHeaders(a.headers, b.headers);
3682
3701
  return config;
3683
3702
  };
3684
- mergeHeaders = (...headers) => {
3703
+ mergeHeaders = (...headers2) => {
3685
3704
  const mergedHeaders = new Headers();
3686
- for (const header of headers) {
3705
+ for (const header of headers2) {
3687
3706
  if (!header || typeof header !== "object") {
3688
3707
  continue;
3689
3708
  }
@@ -3930,37 +3949,10 @@ var init_client_gen2 = __esm({
3930
3949
  });
3931
3950
 
3932
3951
  // packages/experience-design-system-client/dist/src/generated/sdk.gen.js
3933
- var designSystemImportSourcelessPreview, designSystemImportApply, designSystemImportGetOperation;
3934
3952
  var init_sdk_gen = __esm({
3935
3953
  "packages/experience-design-system-client/dist/src/generated/sdk.gen.js"() {
3936
3954
  "use strict";
3937
3955
  init_client_gen2();
3938
- designSystemImportSourcelessPreview = (options) => {
3939
- return (options.client ?? client).post({
3940
- url: "/spaces/{spaceId}/environments/{environmentId}/design_systems/imports/preview",
3941
- ...options,
3942
- headers: {
3943
- "Content-Type": "application/json",
3944
- ...options.headers
3945
- }
3946
- });
3947
- };
3948
- designSystemImportApply = (options) => {
3949
- return (options.client ?? client).post({
3950
- url: "/spaces/{spaceId}/environments/{environmentId}/design_systems/imports/apply",
3951
- ...options,
3952
- headers: {
3953
- "Content-Type": "application/json",
3954
- ...options.headers
3955
- }
3956
- });
3957
- };
3958
- designSystemImportGetOperation = (options) => {
3959
- return (options.client ?? client).get({
3960
- url: "/spaces/{spaceId}/environments/{environmentId}/design_systems/imports/apply/{operationId}",
3961
- ...options
3962
- });
3963
- };
3964
3956
  }
3965
3957
  });
3966
3958
 
@@ -3983,13 +3975,9 @@ var init_src2 = __esm({
3983
3975
  });
3984
3976
 
3985
3977
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/constants/api.js
3986
- var PREVIEW_ERROR_PREFIX, APPLY_ERROR_PREFIX, USER_AGENT;
3987
3978
  var init_api = __esm({
3988
3979
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/constants/api.js"() {
3989
3980
  "use strict";
3990
- PREVIEW_ERROR_PREFIX = "preview failed:";
3991
- APPLY_ERROR_PREFIX = "apply failed:";
3992
- USER_AGENT = "experience-design-system-backend-pipeline";
3993
3981
  }
3994
3982
  });
3995
3983
 
@@ -4002,153 +3990,34 @@ var init_constants5 = __esm({
4002
3990
  });
4003
3991
 
4004
3992
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/http-utils.js
4005
- function isTransientStatus(status) {
4006
- return status >= 500 && status <= 599;
4007
- }
4008
- function retryAfterMs(response) {
4009
- const value = response.headers?.get("retry-after")?.trim();
4010
- if (!value)
4011
- return void 0;
4012
- const seconds = Number(value);
4013
- const delayMs = Number.isFinite(seconds) ? seconds * 1e3 : Date.parse(value) - Date.now();
4014
- if (!Number.isFinite(delayMs) || delayMs < 0 || delayMs > MAX_RETRY_AFTER_MS)
4015
- return void 0;
4016
- return Math.round(delayMs);
4017
- }
4018
- function isApsDenialBody(body) {
4019
- if (!body)
4020
- return false;
4021
- try {
4022
- const parsed = JSON.parse(body);
4023
- const id = parsed?.sys?.id;
4024
- return id === "NotFound" || id === "AccessDenied";
4025
- } catch {
4026
- return false;
4027
- }
4028
- }
4029
- function stringifyError(error) {
4030
- return typeof error === "string" ? error : JSON.stringify(error ?? {});
4031
- }
4032
- function errorMessage(error) {
4033
- return error instanceof Error && error.message ? error.message : String(error);
4034
- }
4035
- function defaultSleep(delayMs) {
4036
- return new Promise((resolve2) => setTimeout(resolve2, delayMs));
4037
- }
4038
- var MAX_RETRY_AFTER_MS;
4039
3993
  var init_http_utils = __esm({
4040
3994
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/http-utils.js"() {
4041
3995
  "use strict";
4042
- MAX_RETRY_AFTER_MS = 6e4;
4043
3996
  }
4044
3997
  });
4045
3998
 
4046
3999
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/sanitize-preview.js
4047
- function sanitizeBreakingChanges(raw) {
4048
- if (!Array.isArray(raw))
4049
- return [];
4050
- const out = [];
4051
- for (const bc of raw) {
4052
- if (typeof bc !== "object" || bc === null)
4053
- continue;
4054
- const reason = bc.reason;
4055
- if (typeof reason !== "string")
4056
- continue;
4057
- if ("propertyId" in bc && typeof bc.propertyId === "string") {
4058
- if (PROPERTY_BREAKING_REASONS.has(reason))
4059
- out.push(bc);
4060
- continue;
4061
- }
4062
- if ("slotId" in bc && typeof bc.slotId === "string") {
4063
- if (SLOT_BREAKING_REASONS.has(reason))
4064
- out.push(bc);
4065
- continue;
4066
- }
4067
- }
4068
- return out;
4069
- }
4070
- function sanitizePreviewResponse(res) {
4071
- for (const item of res.components?.changed ?? []) {
4072
- const cc = item.changeClassification;
4073
- if (cc && Array.isArray(cc.breakingChanges)) {
4074
- cc.breakingChanges = sanitizeBreakingChanges(cc.breakingChanges);
4075
- }
4076
- }
4077
- return res;
4078
- }
4079
- var PROPERTY_BREAKING_REASONS, SLOT_BREAKING_REASONS;
4080
4000
  var init_sanitize_preview = __esm({
4081
4001
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/sanitize-preview.js"() {
4082
4002
  "use strict";
4083
- PROPERTY_BREAKING_REASONS = /* @__PURE__ */ new Set([
4084
- "removed",
4085
- "added_required_no_default",
4086
- "type_changed",
4087
- "validation_narrowed"
4088
- ]);
4089
- SLOT_BREAKING_REASONS = /* @__PURE__ */ new Set(["slot_removed", "slot_allowed_components_narrowed"]);
4090
4003
  }
4091
4004
  });
4092
4005
 
4093
4006
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/host-utils.js
4094
- function trimTrailingSlashes(value) {
4095
- return value.replace(/\/+$/, "");
4096
- }
4097
- function normalizeHostInput(host) {
4098
- const value = host?.trim();
4099
- if (!value)
4100
- return void 0;
4101
- return trimTrailingSlashes(value);
4102
- }
4103
- function toConfiguredHost2(host) {
4104
- const normalized = normalizeHostInput(host);
4105
- if (!normalized)
4106
- return void 0;
4107
- return normalized.replace(/^https:\/\//i, "");
4108
- }
4109
- function toApiHost2(host) {
4110
- const normalized = normalizeHostInput(host);
4111
- if (!normalized)
4112
- return DEFAULT_API_HOST;
4113
- if (/^[a-z][a-z\d+\-.]*:\/\//i.test(normalized))
4114
- return normalized;
4115
- return `https://${normalized}`;
4116
- }
4117
- var DEFAULT_API_HOST;
4118
4007
  var init_host_utils2 = __esm({
4119
4008
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/host-utils.js"() {
4120
4009
  "use strict";
4121
- DEFAULT_API_HOST = "https://api.contentful.com";
4122
4010
  }
4123
4011
  });
4124
4012
 
4125
4013
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/types/api-error.js
4126
- var ERROR_BODY_LOG_CAP, ApiError;
4127
4014
  var init_api_error = __esm({
4128
4015
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/types/api-error.js"() {
4129
4016
  "use strict";
4130
- ERROR_BODY_LOG_CAP = 16384;
4131
- ApiError = class extends Error {
4132
- status;
4133
- body;
4134
- guidance;
4135
- constructor(message, status, body, guidance) {
4136
- super(message);
4137
- this.status = status;
4138
- this.body = body;
4139
- this.guidance = guidance;
4140
- if (body) {
4141
- const trimmed = body.length > ERROR_BODY_LOG_CAP ? body.slice(0, ERROR_BODY_LOG_CAP) + "\u2026" : body;
4142
- this.message = `${message}
4143
- ${trimmed}`;
4144
- }
4145
- }
4146
- };
4147
4017
  }
4148
4018
  });
4149
4019
 
4150
4020
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/api-client/api-client.js
4151
- var ApiClient;
4152
4021
  var init_api_client = __esm({
4153
4022
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/api-client/api-client.js"() {
4154
4023
  "use strict";
@@ -4158,161 +4027,6 @@ var init_api_client = __esm({
4158
4027
  init_sanitize_preview();
4159
4028
  init_host_utils2();
4160
4029
  init_api_error();
4161
- ApiClient = class {
4162
- host;
4163
- token;
4164
- spaceId;
4165
- environmentId;
4166
- retry;
4167
- lastRequestId;
4168
- constructor(opts) {
4169
- this.host = toApiHost2(opts.host);
4170
- this.token = opts.cmaToken;
4171
- this.spaceId = opts.spaceId;
4172
- this.environmentId = opts.environmentId;
4173
- const initialDelayMs = Math.max(0, opts.retry?.initialDelayMs ?? 250);
4174
- this.retry = {
4175
- maxAttempts: Math.max(1, Math.floor(opts.retry?.maxAttempts ?? 3)),
4176
- initialDelayMs,
4177
- maxDelayMs: Math.max(initialDelayMs, opts.retry?.maxDelayMs ?? 2e3),
4178
- sleep: opts.retry?.sleep ?? defaultSleep
4179
- };
4180
- }
4181
- getLastRequestId() {
4182
- return this.lastRequestId;
4183
- }
4184
- noteRequestId(response) {
4185
- const id = response.headers.get("x-contentful-request-id");
4186
- if (id)
4187
- this.lastRequestId = id;
4188
- }
4189
- headers() {
4190
- return {
4191
- Authorization: `Bearer ${this.token}`,
4192
- "Content-Type": "application/json",
4193
- "X-Contentful-User-Agent": USER_AGENT
4194
- };
4195
- }
4196
- async requestWithRetry(phase, errorPrefix, makeCall) {
4197
- for (let attempt = 1; attempt <= this.retry.maxAttempts; attempt++) {
4198
- let result;
4199
- try {
4200
- result = await makeCall();
4201
- } catch (error) {
4202
- if (attempt === this.retry.maxAttempts) {
4203
- const body = `The request failed after ${attempt} attempts because of a network error: ${errorMessage(error)}. Check your connection and try again.`;
4204
- throw new ApiError(`${errorPrefix} 0`, 0, body);
4205
- }
4206
- await this.retry.sleep(Math.min(this.retry.initialDelayMs * 2 ** (attempt - 1), this.retry.maxDelayMs));
4207
- continue;
4208
- }
4209
- if (!isTransientStatus(result.response.status)) {
4210
- this.noteRequestId(result.response);
4211
- return result;
4212
- }
4213
- if (attempt === this.retry.maxAttempts) {
4214
- const body = stringifyError(result.error);
4215
- const guidance = `The ${phase} request failed after ${attempt} attempts because the service remained unavailable. Wait a moment and try again.`;
4216
- throw new ApiError(`${errorPrefix} ${result.response.status}`, result.response.status, body, guidance);
4217
- }
4218
- const backoffMs = Math.min(this.retry.initialDelayMs * 2 ** (attempt - 1), this.retry.maxDelayMs);
4219
- await this.retry.sleep(retryAfterMs(result.response) ?? backoffMs);
4220
- }
4221
- throw new Error("Retry attempts exhausted");
4222
- }
4223
- async validateToken() {
4224
- const res = await fetch(`${this.host}/users/me`, { headers: this.headers() });
4225
- this.noteRequestId(res);
4226
- if (res.status === 401) {
4227
- throw new ApiError("CMA token is invalid or revoked", res.status, await res.text());
4228
- }
4229
- if (!res.ok) {
4230
- throw new ApiError(`unexpected error validating token: ${res.status}`, res.status, await res.text());
4231
- }
4232
- await this.checkPreflight();
4233
- }
4234
- async checkPreflight() {
4235
- const url = `${this.host}/spaces/${this.spaceId}/environments/${this.environmentId}/design_systems/preflight`;
4236
- let res;
4237
- try {
4238
- res = await fetch(url, { headers: this.headers() });
4239
- } catch {
4240
- return;
4241
- }
4242
- this.noteRequestId(res);
4243
- if (res.ok)
4244
- return;
4245
- if (res.status >= 500)
4246
- return;
4247
- const body = await res.text();
4248
- if (res.status === 404 && !isApsDenialBody(body))
4249
- return;
4250
- throw new ApiError(`preflight failed: ${res.status}`, res.status, body);
4251
- }
4252
- async previewImport(cdf) {
4253
- const result = await this.requestWithRetry("preview", PREVIEW_ERROR_PREFIX, () => designSystemImportSourcelessPreview({
4254
- baseUrl: this.host,
4255
- headers: this.headers(),
4256
- path: { spaceId: this.spaceId, environmentId: this.environmentId },
4257
- body: cdf,
4258
- parseAs: "json"
4259
- }));
4260
- if (!result.response.ok) {
4261
- throw new ApiError(`${PREVIEW_ERROR_PREFIX} ${result.response.status}`, result.response.status, stringifyError(result.error));
4262
- }
4263
- return sanitizePreviewResponse(result.data);
4264
- }
4265
- async applyImport(cdf, opts) {
4266
- let result;
4267
- try {
4268
- result = await designSystemImportApply({
4269
- baseUrl: this.host,
4270
- headers: this.headers(),
4271
- path: { spaceId: this.spaceId, environmentId: this.environmentId },
4272
- body: { ...cdf, acknowledgeBreakingChanges: opts.acknowledgeBreakingChanges },
4273
- parseAs: "json"
4274
- });
4275
- } catch (error) {
4276
- const body = `The apply request was not retried because its outcome is unknown and retrying could start a duplicate operation. Cause: ${errorMessage(error)}`;
4277
- throw new ApiError(`${APPLY_ERROR_PREFIX} 0`, 0, body);
4278
- }
4279
- if (!result.response.ok) {
4280
- const body = stringifyError(result.error);
4281
- const guidance = isTransientStatus(result.response.status) ? "The apply request was not retried because the server may already have started an operation and retrying could create a duplicate." : void 0;
4282
- throw new ApiError(`${APPLY_ERROR_PREFIX} ${result.response.status}`, result.response.status, body, guidance);
4283
- }
4284
- this.noteRequestId(result.response);
4285
- return result.data;
4286
- }
4287
- async pollOperation(operationId, opts = {}) {
4288
- const intervalMs = opts.intervalMs ?? 2e3;
4289
- const maxIntervalMs = opts.maxIntervalMs ?? Math.round(intervalMs * 2.5);
4290
- const maxAttempts = opts.maxAttempts ?? 150;
4291
- const terminalStatuses = /* @__PURE__ */ new Set(["succeeded", "partial", "failed"]);
4292
- for (let attempt = 0; attempt < maxAttempts; attempt++) {
4293
- const result = await this.requestWithRetry("poll", "poll failed:", () => designSystemImportGetOperation({
4294
- baseUrl: this.host,
4295
- headers: this.headers(),
4296
- path: { spaceId: this.spaceId, environmentId: this.environmentId, operationId },
4297
- parseAs: "json"
4298
- }));
4299
- if (!result.response.ok) {
4300
- throw new ApiError(`poll failed: ${result.response.status}`, result.response.status, stringifyError(result.error));
4301
- }
4302
- const op = result.data;
4303
- opts.onProgress?.(op);
4304
- if (terminalStatuses.has(op.sys.status))
4305
- return op;
4306
- if (attempt < maxAttempts - 1) {
4307
- const progress = maxAttempts > 1 ? attempt / (maxAttempts - 1) : 0;
4308
- const baseDelay = intervalMs + (maxIntervalMs - intervalMs) * progress;
4309
- const jitter = Math.random() * baseDelay * 0.15;
4310
- await new Promise((resolve2) => setTimeout(resolve2, baseDelay + jitter));
4311
- }
4312
- }
4313
- throw new Error(`Operation ${operationId} timed out after ${maxAttempts} attempts`);
4314
- }
4315
- };
4316
4030
  }
4317
4031
  });
4318
4032
 
@@ -4515,25 +4229,6 @@ var init_annotate_preview2 = __esm({
4515
4229
  });
4516
4230
 
4517
4231
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/parse-binding-diagnostics.js
4518
- function parseBindingDiagnostics(body) {
4519
- if (!/binding configurations are invalid|Pointer path does not exist/i.test(body))
4520
- return null;
4521
- const locationMatches = [...body.matchAll(/(?:^|\.\s)([A-Za-z0-9_$-]+(?:\s*›\s*[A-Za-z0-9_$-]+){2,})/g)];
4522
- const location = locationMatches.at(-1)?.[1];
4523
- const pointerMessage = body.match(/Pointer path does not exist for '\[object Object\]':\s*(.+?)(?=\.\s*Default\s*›|$)/i)?.[1];
4524
- const graphQlMessage = body.match(/return GraphQL validation error:\s*(.+?)(?=\.\s*Default\s*›|$)/i)?.[1];
4525
- const heading = body.match(/^(.*?)(?=\.?\s*Pointer path does not exist|\.?\s*Default\s*›)/i)?.[1]?.trim();
4526
- const diagnostics = [];
4527
- if (pointerMessage)
4528
- diagnostics.push({ message: pointerMessage.trim(), ...location ? { path: location } : {} });
4529
- if (graphQlMessage)
4530
- diagnostics.push({ message: graphQlMessage.trim(), ...location ? { path: location } : {} });
4531
- return {
4532
- code: "BindingValidationFailed",
4533
- message: heading || "One or more binding configurations are invalid.",
4534
- ...diagnostics.length > 0 ? { diagnostics } : {}
4535
- };
4536
- }
4537
4232
  var init_parse_binding_diagnostics = __esm({
4538
4233
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/parse-binding-diagnostics.js"() {
4539
4234
  "use strict";
@@ -4541,76 +4236,6 @@ var init_parse_binding_diagnostics = __esm({
4541
4236
  });
4542
4237
 
4543
4238
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/helpers.js
4544
- function asRecord(value) {
4545
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
4546
- }
4547
- function displayValue(value) {
4548
- if (typeof value === "string")
4549
- return value;
4550
- if (typeof value === "number" || typeof value === "boolean")
4551
- return String(value);
4552
- if (value === null || value === void 0)
4553
- return null;
4554
- try {
4555
- return JSON.stringify(value);
4556
- } catch {
4557
- return null;
4558
- }
4559
- }
4560
- function isPathSegment(value) {
4561
- return typeof value === "string" || typeof value === "number" && Number.isFinite(value);
4562
- }
4563
- function formatPath(value) {
4564
- if (isPathSegment(value))
4565
- return String(value) ? { path: String(value) } : { path: null };
4566
- if (Array.isArray(value)) {
4567
- const parts = value.filter(isPathSegment);
4568
- return parts.length > 0 ? { path: parts.join(" \u203A ") } : { path: null };
4569
- }
4570
- return {};
4571
- }
4572
- function componentFromPath(path5) {
4573
- if (!path5)
4574
- return void 0;
4575
- const manifestMatch = path5.match(/manifest:components\/([^/›]+)/);
4576
- if (manifestMatch?.[1])
4577
- return manifestMatch[1];
4578
- const parts = path5.split(/[›/]/).map((part) => part.trim()).filter(Boolean);
4579
- const componentsIndex = parts.findIndex((part) => part === "components");
4580
- return componentsIndex === -1 ? void 0 : parts[componentsIndex + 1];
4581
- }
4582
- function diagnosticMessage(error) {
4583
- const candidates = [
4584
- ["message", error.message],
4585
- ["details", error.details],
4586
- ["error", error.error],
4587
- ["name", error.name]
4588
- ];
4589
- for (const [messageSource, value] of candidates) {
4590
- const message = displayValue(value);
4591
- if (message !== null)
4592
- return { message, messageSource };
4593
- }
4594
- return { message: "Validation failed" };
4595
- }
4596
- function parseObjectLiteralTail(body) {
4597
- const braceStart = body.lastIndexOf("{");
4598
- if (braceStart === -1)
4599
- return null;
4600
- const tail = body.slice(braceStart);
4601
- const codeMatch = tail.match(/code:\s*['"]([^'"]+)['"]/);
4602
- const cycleMatch = tail.match(/cycle:\s*\[\s*([^\]]*)\s*\]/);
4603
- if (!codeMatch && !cycleMatch)
4604
- return null;
4605
- const code = codeMatch ? codeMatch[1] : null;
4606
- let cycle = null;
4607
- if (cycleMatch) {
4608
- cycle = cycleMatch[1].split(",").map((s) => s.trim().replace(/^['"]|['"]$/g, "")).filter((s) => s.length > 0);
4609
- if (cycle.length === 0)
4610
- cycle = null;
4611
- }
4612
- return { code, cycle };
4613
- }
4614
4239
  var init_helpers3 = __esm({
4615
4240
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/helpers.js"() {
4616
4241
  "use strict";
@@ -4618,50 +4243,6 @@ var init_helpers3 = __esm({
4618
4243
  });
4619
4244
 
4620
4245
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/parse-json-body.js
4621
- function parseValidationDiagnostics(details) {
4622
- if (!Array.isArray(details.errors))
4623
- return [];
4624
- const diagnostics = [];
4625
- for (const rawError of details.errors) {
4626
- const error = asRecord(rawError);
4627
- if (!error)
4628
- continue;
4629
- const location = formatPath(error.path);
4630
- const component = displayValue(error.component ?? error.componentName ?? error.componentId) ?? componentFromPath(location.path);
4631
- diagnostics.push({ ...diagnosticMessage(error), ...location, ...component ? { component } : {} });
4632
- }
4633
- return diagnostics;
4634
- }
4635
- function parseJsonBody(body) {
4636
- let parsed;
4637
- try {
4638
- parsed = JSON.parse(body);
4639
- } catch {
4640
- return null;
4641
- }
4642
- const p = asRecord(parsed);
4643
- if (!p)
4644
- return null;
4645
- const details = asRecord(p.details) ?? {};
4646
- const pick = (k) => p[k] !== void 0 ? p[k] : details[k];
4647
- const codeRaw = pick("code") ?? asRecord(p.sys)?.id;
4648
- const messageRaw = pick("message");
4649
- const cycleRaw = pick("cycle");
4650
- const out = {};
4651
- if (typeof codeRaw === "string")
4652
- out.code = codeRaw;
4653
- if (typeof messageRaw === "string")
4654
- out.message = messageRaw;
4655
- if (Array.isArray(cycleRaw)) {
4656
- const strs = cycleRaw.filter((x) => typeof x === "string");
4657
- if (strs.length > 0)
4658
- out.cycle = strs;
4659
- }
4660
- const diagnostics = parseValidationDiagnostics(details);
4661
- if (diagnostics.length > 0)
4662
- out.diagnostics = diagnostics;
4663
- return out;
4664
- }
4665
4246
  var init_parse_json_body = __esm({
4666
4247
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/parse-json-body.js"() {
4667
4248
  "use strict";
@@ -4670,72 +4251,13 @@ var init_parse_json_body = __esm({
4670
4251
  });
4671
4252
 
4672
4253
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/strip-lambda-log-prefix.js
4673
- function stripLambdaLogPrefix(body) {
4674
- return body.replace(LAMBDA_LOG_PREFIX_RE, "").replace(DD_TAG_RE, "").trim();
4675
- }
4676
- var LAMBDA_LOG_PREFIX_RE, DD_TAG_RE;
4677
4254
  var init_strip_lambda_log_prefix = __esm({
4678
4255
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/strip-lambda-log-prefix.js"() {
4679
4256
  "use strict";
4680
- LAMBDA_LOG_PREFIX_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\s+[0-9a-f-]+\s+ERROR\s+(?:\[dd\.[^\]]*\]\s*)?/;
4681
- DD_TAG_RE = /\[dd\.(?:trace_id|span_id)=[^\]]*\]\s*/g;
4682
4257
  }
4683
4258
  });
4684
4259
 
4685
4260
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/parse-edsi-error.js
4686
- function parseEdsiError(rawInput) {
4687
- if (!rawInput)
4688
- return { code: null, message: "", cycle: null, raw: true };
4689
- const { body, prefix } = splitPhasePrefix(rawInput);
4690
- const cleaned = stripLambdaLogPrefix(body);
4691
- const json = parseJsonBody(cleaned) ?? parseJsonBody(body);
4692
- const bindingFromJson = typeof json?.message === "string" ? parseBindingDiagnostics(json.message) : null;
4693
- if (bindingFromJson) {
4694
- return {
4695
- code: bindingFromJson.code ?? json?.code ?? null,
4696
- message: bindingFromJson.message ?? cleaned,
4697
- cycle: null,
4698
- raw: false,
4699
- ...bindingFromJson.diagnostics ? { diagnostics: bindingFromJson.diagnostics } : {}
4700
- };
4701
- }
4702
- if (json && (json.code || json.message || json.cycle)) {
4703
- return {
4704
- code: json.code ?? null,
4705
- message: json.message ?? (cleaned || prefix),
4706
- cycle: json.cycle ?? null,
4707
- raw: false,
4708
- ...json.diagnostics ? { diagnostics: json.diagnostics } : {}
4709
- };
4710
- }
4711
- const binding = parseBindingDiagnostics(cleaned);
4712
- if (binding) {
4713
- return {
4714
- code: binding.code ?? null,
4715
- message: binding.message ?? cleaned,
4716
- cycle: null,
4717
- raw: false,
4718
- ...binding.diagnostics ? { diagnostics: binding.diagnostics } : {}
4719
- };
4720
- }
4721
- const literal2 = parseObjectLiteralTail(cleaned);
4722
- if (literal2 && (literal2.code || literal2.cycle)) {
4723
- const braceStart = cleaned.lastIndexOf("{");
4724
- const head = braceStart === -1 ? cleaned : cleaned.slice(0, braceStart).trim();
4725
- return { code: literal2.code ?? null, message: head || cleaned, cycle: literal2.cycle ?? null, raw: false };
4726
- }
4727
- return { code: null, message: cleaned || prefix || rawInput, cycle: null, raw: true };
4728
- }
4729
- function splitPhasePrefix(input) {
4730
- const nlIndex = input.indexOf("\n");
4731
- if (nlIndex === -1)
4732
- return { body: input, prefix: "" };
4733
- const firstLine = input.slice(0, nlIndex);
4734
- if (!API_ERROR_PREFIX_RE.test(firstLine))
4735
- return { body: input, prefix: "" };
4736
- return { body: input.slice(nlIndex + 1), prefix: firstLine };
4737
- }
4738
- var API_ERROR_PREFIX_RE;
4739
4261
  var init_parse_edsi_error = __esm({
4740
4262
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/parse-edsi-error.js"() {
4741
4263
  "use strict";
@@ -4743,51 +4265,10 @@ var init_parse_edsi_error = __esm({
4743
4265
  init_parse_json_body();
4744
4266
  init_helpers3();
4745
4267
  init_strip_lambda_log_prefix();
4746
- API_ERROR_PREFIX_RE = /^(?:apply|preview|poll) failed: \d+$/;
4747
4268
  }
4748
4269
  });
4749
4270
 
4750
4271
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/format-parsed-edsi-error.js
4751
- function formatParsedEdsiError(parsed, opts = {}) {
4752
- const lines = [];
4753
- if (parsed.code)
4754
- lines.push(`[${parsed.code}]`);
4755
- if (parsed.message)
4756
- lines.push(parsed.message);
4757
- for (const diagnostic of parsed.diagnostics ?? []) {
4758
- const context = [
4759
- diagnostic.component ? `Component: ${diagnostic.component}` : null,
4760
- diagnostic.path ? `Path: ${diagnostic.path}` : null
4761
- ].filter(Boolean);
4762
- lines.push(`- ${diagnostic.message}${context.length > 0 ? ` (${context.join("; ")})` : ""}`);
4763
- if (diagnostic.path === null) {
4764
- lines.push(" Location: not provided by the server. Review the submitted CDF file; no component or field was identified.");
4765
- }
4766
- if (opts.verbose && diagnostic.messageSource) {
4767
- lines.push(` Message field: ${diagnostic.messageSource}`);
4768
- }
4769
- }
4770
- if (parsed.code === "BindingValidationFailed") {
4771
- const location = parsed.diagnostics?.find((d) => d.path)?.path;
4772
- lines.push(location ? `Next action: review the binding at ${location} and correct its pointer or GraphQL selection.` : "Next action: review the binding pointer and GraphQL selection.");
4773
- }
4774
- if (parsed.code === "AccessDenied") {
4775
- lines.push("Next action: this operation requires DesignToken and Component permissions in this environment. Ask a Contentful admin to grant both on your role.");
4776
- }
4777
- if (parsed.code === "NotFound") {
4778
- lines.push("Next action: verify the resource id is correct. If it should exist, your role may lack read permission on DesignToken or Component.");
4779
- }
4780
- if (parsed.cycle && parsed.cycle.length > 0) {
4781
- lines.push(`Cycle: ${parsed.cycle.join(" \u2192 ")} \u2192 ${parsed.cycle[0]}`);
4782
- lines.push("Break the cycle by removing at least one $allowedComponents entry.");
4783
- }
4784
- if (opts.verbose && opts.raw) {
4785
- lines.push("");
4786
- lines.push("--- raw ---");
4787
- lines.push(opts.raw);
4788
- }
4789
- return lines.filter(Boolean).join("\n");
4790
- }
4791
4272
  var init_format_parsed_edsi_error = __esm({
4792
4273
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/format-parsed-edsi-error.js"() {
4793
4274
  "use strict";
@@ -4795,12 +4276,6 @@ var init_format_parsed_edsi_error = __esm({
4795
4276
  });
4796
4277
 
4797
4278
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/format-edsi-error.js
4798
- function formatEdsiError(raw, opts = {}) {
4799
- const input = typeof raw === "string" ? raw : displayValue(raw);
4800
- if (!input)
4801
- return "";
4802
- return formatParsedEdsiError(parseEdsiError(input), { ...opts, raw: opts.raw ?? input });
4803
- }
4804
4279
  var init_format_edsi_error = __esm({
4805
4280
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/format-edsi-error.js"() {
4806
4281
  "use strict";
@@ -4811,14 +4286,6 @@ var init_format_edsi_error = __esm({
4811
4286
  });
4812
4287
 
4813
4288
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/format-api-error.js
4814
- function formatApiError(error, verbose = false) {
4815
- const formatted = formatEdsiError(error.body || error.message, { verbose, raw: error.body }) || error.message;
4816
- const phase = error.message.split("\n", 1)[0];
4817
- const withPhase = /^(?:apply|preview|poll) failed: \d+$/.test(phase) && formatted !== phase ? `${phase}
4818
- ${formatted}` : formatted;
4819
- return error.guidance ? `${withPhase}
4820
- ${error.guidance}` : withPhase;
4821
- }
4822
4289
  var init_format_api_error = __esm({
4823
4290
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/edsi-errors/format-api-error.js"() {
4824
4291
  "use strict";
@@ -4855,9 +4322,6 @@ var init_format_edsi_error2 = __esm({
4855
4322
  });
4856
4323
 
4857
4324
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/controller/errors/format-api-error.js
4858
- function formatApiError2(request) {
4859
- return formatApiError(request.error, request.verbose ?? false);
4860
- }
4861
4325
  var init_format_api_error2 = __esm({
4862
4326
  "packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/controller/errors/format-api-error.js"() {
4863
4327
  "use strict";
@@ -5367,12 +4831,21 @@ function keyAction2(input, key) {
5367
4831
  function nextField(field) {
5368
4832
  return FIELDS[(FIELDS.indexOf(field) + 1) % FIELDS.length];
5369
4833
  }
4834
+ function toConfiguredHost3(host) {
4835
+ const value = (host ?? "").trim().replace(/\/+$/, "");
4836
+ return value === "" ? DEFAULT_HOST : value.replace(/^https:\/\//i, "");
4837
+ }
4838
+ function toApiHost3(host) {
4839
+ const value = host.trim().replace(/\/+$/, "");
4840
+ if (value === "") return `https://${DEFAULT_HOST}`;
4841
+ return /^[a-z][a-z\d+\-.]*:\/\//i.test(value) ? value : `https://${value}`;
4842
+ }
5370
4843
  function normalize(values) {
5371
4844
  return {
5372
4845
  spaceId: values.spaceId.trim(),
5373
4846
  environmentId: values.environmentId.trim(),
5374
4847
  cmaToken: values.cmaToken.trim(),
5375
- host: toConfiguredHost2(values.host) ?? DEFAULT_CONFIGURED_HOST
4848
+ host: toConfiguredHost3(values.host)
5376
4849
  };
5377
4850
  }
5378
4851
  function missingField(values) {
@@ -5381,12 +4854,12 @@ function missingField(values) {
5381
4854
  function isUnchanged(current, initial) {
5382
4855
  return FIELDS.every((field) => current[field] === initial[field]);
5383
4856
  }
5384
- var FIELDS;
4857
+ var FIELDS, DEFAULT_HOST;
5385
4858
  var init_logic4 = __esm({
5386
4859
  "packages/experience-design-system-cli/src/tui/import/steps/04-credentials/logic.ts"() {
5387
4860
  "use strict";
5388
- init_src3();
5389
4861
  FIELDS = ["spaceId", "environmentId", "cmaToken", "host"];
4862
+ DEFAULT_HOST = "api.contentful.com";
5390
4863
  }
5391
4864
  });
5392
4865
 
@@ -5416,35 +4889,65 @@ var init_controls4 = __esm({
5416
4889
  });
5417
4890
 
5418
4891
  // packages/experience-design-system-cli/src/tui/import/steps/04-credentials/validate.ts
4892
+ function headers(token) {
4893
+ return { Authorization: `Bearer ${token}`, "X-Contentful-User-Agent": USER_AGENT2 };
4894
+ }
4895
+ function isApsDenial(body) {
4896
+ try {
4897
+ const id = JSON.parse(body).sys?.id;
4898
+ return id === "NotFound" || id === "AccessDenied";
4899
+ } catch {
4900
+ return false;
4901
+ }
4902
+ }
4903
+ function messageFrom(body) {
4904
+ try {
4905
+ const message = JSON.parse(body).message;
4906
+ return typeof message === "string" && message !== "" ? message : void 0;
4907
+ } catch {
4908
+ return void 0;
4909
+ }
4910
+ }
5419
4911
  async function validateCredentials(values) {
5420
- const host = toApiHost2(values.host);
5421
- const client2 = new ApiClient({
5422
- host,
5423
- spaceId: values.spaceId,
5424
- environmentId: values.environmentId,
5425
- cmaToken: values.cmaToken
5426
- });
4912
+ const base = toApiHost3(values.host);
4913
+ let me;
5427
4914
  try {
5428
- await client2.validateToken();
5429
- return { ok: true };
4915
+ me = await fetch(`${base}/users/me`, { headers: headers(values.cmaToken) });
5430
4916
  } catch (error) {
5431
- return { ok: false, error: toUserError(error, host) };
4917
+ return { ok: false, error: `Could not reach ${base}: ${error instanceof Error ? error.message : String(error)}` };
5432
4918
  }
5433
- }
5434
- function toUserError(error, host) {
5435
- if (error instanceof ApiError) {
5436
- if (error.status === 404 && error.message.startsWith("preflight failed:")) {
5437
- return "Not found. Check the space ID, environment and API host.";
5438
- }
5439
- return formatApiError2({ error });
4919
+ if (me.status === 401) return { ok: false, error: "CMA token is invalid or revoked." };
4920
+ if (!me.ok) return { ok: false, error: `Unexpected error validating the token (${me.status}).` };
4921
+ let preflight;
4922
+ try {
4923
+ preflight = await fetch(
4924
+ `${base}/spaces/${values.spaceId}/environments/${values.environmentId}/design_systems/preflight`,
4925
+ { headers: headers(values.cmaToken) }
4926
+ );
4927
+ } catch {
4928
+ return { ok: true };
4929
+ }
4930
+ if (preflight.ok || preflight.status >= 500) return { ok: true };
4931
+ const body = await preflight.text();
4932
+ if (preflight.status === 404 && !isApsDenial(body)) return { ok: true };
4933
+ const detail = messageFrom(body);
4934
+ if (preflight.status === 403) {
4935
+ return { ok: false, error: `Access denied. ${detail ?? "Your token cannot write design system components here."}` };
4936
+ }
4937
+ if (preflight.status === 404) {
4938
+ return {
4939
+ ok: false,
4940
+ error: `Not found. Check the space ID, environment and API host.${detail ? ` (${detail})` : ""}`
4941
+ };
5440
4942
  }
5441
- if (error instanceof Error) return `Could not reach ${host}: ${error.message}`;
5442
- return String(error);
4943
+ return { ok: false, error: `Credential check failed (${preflight.status}).${detail ? ` ${detail}` : ""}` };
5443
4944
  }
4945
+ var USER_AGENT2;
5444
4946
  var init_validate4 = __esm({
5445
4947
  "packages/experience-design-system-cli/src/tui/import/steps/04-credentials/validate.ts"() {
5446
4948
  "use strict";
5447
- init_src3();
4949
+ init_logic4();
4950
+ USER_AGENT2 = "app contentful.experience-design-system-cli";
5448
4951
  }
5449
4952
  });
5450
4953
 
@@ -5519,7 +5022,7 @@ function CredentialsScreen({
5519
5022
  value: values[field],
5520
5023
  focus: active === field && !validating,
5521
5024
  mask: field === "cmaToken" ? "\u2022" : void 0,
5522
- placeholder: field === "host" ? DEFAULT_CONFIGURED_HOST : void 0,
5025
+ placeholder: field === "host" ? DEFAULT_HOST : void 0,
5523
5026
  onChange: change(field),
5524
5027
  onSubmit: () => void submit(field)
5525
5028
  }
@@ -5546,7 +5049,6 @@ var init_screen4 = __esm({
5546
5049
  "use strict";
5547
5050
  init_home_theme();
5548
5051
  init_controls4();
5549
- init_src3();
5550
5052
  init_logic4();
5551
5053
  init_validate4();
5552
5054
  LABELS = {
@@ -5558,6 +5060,234 @@ var init_screen4 = __esm({
5558
5060
  }
5559
5061
  });
5560
5062
 
5063
+ // packages/experience-design-system-cli/src/tui/import/shared/error-step/logic.ts
5064
+ var init_logic5 = __esm({
5065
+ "packages/experience-design-system-cli/src/tui/import/shared/error-step/logic.ts"() {
5066
+ "use strict";
5067
+ }
5068
+ });
5069
+
5070
+ // packages/experience-design-system-cli/src/tui/import/shared/error-step/controls.ts
5071
+ import { useInput as useInput7 } from "ink";
5072
+ var init_controls5 = __esm({
5073
+ "packages/experience-design-system-cli/src/tui/import/shared/error-step/controls.ts"() {
5074
+ "use strict";
5075
+ init_logic5();
5076
+ }
5077
+ });
5078
+
5079
+ // packages/experience-design-system-cli/src/tui/import/shared/error-step/error-step.tsx
5080
+ import { Box as Box7, Text as Text8 } from "ink";
5081
+ import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
5082
+ var init_error_step = __esm({
5083
+ "packages/experience-design-system-cli/src/tui/import/shared/error-step/error-step.tsx"() {
5084
+ "use strict";
5085
+ init_home_theme();
5086
+ init_controls5();
5087
+ init_logic5();
5088
+ }
5089
+ });
5090
+
5091
+ // packages/experience-design-system-cli/src/tui/import/shared/gate-step/logic.ts
5092
+ function gateAction(input, key, canSkip) {
5093
+ if (key.return) return "continue";
5094
+ if (input === "a" && canSkip) return "skip";
5095
+ if (key.escape) return "quit";
5096
+ return null;
5097
+ }
5098
+ function gateControls(continueLabel, skipLabel, canSkip) {
5099
+ return [
5100
+ { keys: "Enter", label: continueLabel },
5101
+ ...canSkip ? [{ keys: "a", label: skipLabel }] : [],
5102
+ { keys: "Esc", label: "Quit" }
5103
+ ];
5104
+ }
5105
+ var init_logic6 = __esm({
5106
+ "packages/experience-design-system-cli/src/tui/import/shared/gate-step/logic.ts"() {
5107
+ "use strict";
5108
+ }
5109
+ });
5110
+
5111
+ // packages/experience-design-system-cli/src/tui/import/shared/gate-step/controls.ts
5112
+ import { useInput as useInput8 } from "ink";
5113
+ function useGateControls(handlers) {
5114
+ useInput8((input, key) => {
5115
+ const action = gateAction(input, key, handlers.canSkip);
5116
+ if (action === "continue") handlers.onContinue();
5117
+ else if (action === "skip") handlers.onSkip();
5118
+ else if (action === "quit") handlers.onQuit();
5119
+ });
5120
+ }
5121
+ var init_controls6 = __esm({
5122
+ "packages/experience-design-system-cli/src/tui/import/shared/gate-step/controls.ts"() {
5123
+ "use strict";
5124
+ init_logic6();
5125
+ }
5126
+ });
5127
+
5128
+ // packages/experience-design-system-cli/src/tui/import/shared/gate-step/gate-step.tsx
5129
+ import { Box as Box8, Text as Text9 } from "ink";
5130
+ import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
5131
+ function GateStep({
5132
+ message,
5133
+ onContinue,
5134
+ onQuit,
5135
+ summary,
5136
+ context,
5137
+ continueLabel = "Continue",
5138
+ skipLabel = "Approve all and skip",
5139
+ onSkip,
5140
+ intent = "success"
5141
+ }) {
5142
+ useGateControls({ canSkip: onSkip !== void 0, onContinue, onSkip: onSkip ?? (() => {
5143
+ }), onQuit });
5144
+ const color = intent === "error" ? PALETTE.error : PALETTE.success;
5145
+ const icon = intent === "error" ? "\u2717" : "\u2713";
5146
+ return /* @__PURE__ */ jsxs8(Box8, { flexDirection: "column", gap: 1, paddingX: 2, paddingY: 1, children: [
5147
+ /* @__PURE__ */ jsxs8(Text9, { color, children: [
5148
+ icon,
5149
+ " ",
5150
+ message
5151
+ ] }),
5152
+ summary && /* @__PURE__ */ jsx9(Text9, { color: PALETTE.muted, children: summary }),
5153
+ context && /* @__PURE__ */ jsx9(Box8, { marginTop: 1, children: /* @__PURE__ */ jsx9(Text9, { children: context }) }),
5154
+ /* @__PURE__ */ jsx9(Box8, { marginTop: 1, gap: 3, children: gateControls(continueLabel, skipLabel, onSkip !== void 0).map((control) => /* @__PURE__ */ jsxs8(Text9, { dimColor: true, children: [
5155
+ "[",
5156
+ control.keys,
5157
+ "] ",
5158
+ control.label
5159
+ ] }, control.keys)) })
5160
+ ] });
5161
+ }
5162
+ var init_gate_step = __esm({
5163
+ "packages/experience-design-system-cli/src/tui/import/shared/gate-step/gate-step.tsx"() {
5164
+ "use strict";
5165
+ init_home_theme();
5166
+ init_controls6();
5167
+ init_logic6();
5168
+ }
5169
+ });
5170
+
5171
+ // packages/experience-design-system-cli/src/tui/import/shared/running-step/logic.ts
5172
+ var init_logic7 = __esm({
5173
+ "packages/experience-design-system-cli/src/tui/import/shared/running-step/logic.ts"() {
5174
+ "use strict";
5175
+ }
5176
+ });
5177
+
5178
+ // packages/experience-design-system-cli/src/tui/import/shared/running-step/theme.ts
5179
+ import { defaultTheme, extendTheme } from "@inkjs/ui";
5180
+ var PROGRESS_THEME;
5181
+ var init_theme = __esm({
5182
+ "packages/experience-design-system-cli/src/tui/import/shared/running-step/theme.ts"() {
5183
+ "use strict";
5184
+ PROGRESS_THEME = extendTheme(defaultTheme, {
5185
+ components: {
5186
+ ProgressBar: {
5187
+ styles: {
5188
+ completed: () => ({ color: "blue" })
5189
+ }
5190
+ }
5191
+ }
5192
+ });
5193
+ }
5194
+ });
5195
+
5196
+ // packages/experience-design-system-cli/src/tui/import/shared/running-step/use-elapsed.ts
5197
+ import { useEffect as useEffect4, useState as useState7 } from "react";
5198
+ var init_use_elapsed = __esm({
5199
+ "packages/experience-design-system-cli/src/tui/import/shared/running-step/use-elapsed.ts"() {
5200
+ "use strict";
5201
+ init_logic7();
5202
+ }
5203
+ });
5204
+
5205
+ // packages/experience-design-system-cli/src/tui/import/shared/running-step/running-step.tsx
5206
+ import { Box as Box9, Text as Text10 } from "ink";
5207
+ import { ProgressBar, Spinner, ThemeProvider } from "@inkjs/ui";
5208
+ import { jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
5209
+ var RULE2;
5210
+ var init_running_step = __esm({
5211
+ "packages/experience-design-system-cli/src/tui/import/shared/running-step/running-step.tsx"() {
5212
+ "use strict";
5213
+ init_home_theme();
5214
+ init_logic7();
5215
+ init_theme();
5216
+ init_use_elapsed();
5217
+ RULE2 = "\u2500".repeat(40);
5218
+ }
5219
+ });
5220
+
5221
+ // packages/experience-design-system-cli/src/tui/import/shared/index.ts
5222
+ var init_shared2 = __esm({
5223
+ "packages/experience-design-system-cli/src/tui/import/shared/index.ts"() {
5224
+ "use strict";
5225
+ init_error_step();
5226
+ init_gate_step();
5227
+ init_running_step();
5228
+ }
5229
+ });
5230
+
5231
+ // packages/experience-design-system-cli/src/tui/import/steps/05-token-reuse/logic.ts
5232
+ import { access, stat } from "node:fs/promises";
5233
+ import { join as join5 } from "node:path";
5234
+ async function inspectTokens({ rawTokensPath, outDir, cache }) {
5235
+ if (!cache) return { kind: "none" };
5236
+ const tokensPath = join5(outDir, "tokens.json");
5237
+ try {
5238
+ await access(tokensPath);
5239
+ } catch {
5240
+ return { kind: "none" };
5241
+ }
5242
+ const [generated, source] = await Promise.all([stat(tokensPath), stat(rawTokensPath).catch(() => null)]);
5243
+ return { kind: "cached", tokensPath, sourceChanged: source ? source.mtimeMs > generated.mtimeMs : false };
5244
+ }
5245
+ function gateText({ tokensPath, sourceChanged }) {
5246
+ const summary = sourceChanged ? `Source file has been modified since tokens were last generated.
5247
+
5248
+ Tokens Path: ${tokensPath}` : `Source file has not changed since tokens were last generated.
5249
+
5250
+ Tokens Path: ${tokensPath}`;
5251
+ return sourceChanged ? { summary, context: "The source tokens file changed \u2014 regenerating is recommended." } : { summary };
5252
+ }
5253
+ var init_logic8 = __esm({
5254
+ "packages/experience-design-system-cli/src/tui/import/steps/05-token-reuse/logic.ts"() {
5255
+ "use strict";
5256
+ }
5257
+ });
5258
+
5259
+ // packages/experience-design-system-cli/src/tui/import/steps/05-token-reuse/screen.tsx
5260
+ import { jsx as jsx11 } from "react/jsx-runtime";
5261
+ function TokenReuseScreen({
5262
+ tokensPath,
5263
+ sourceChanged,
5264
+ onReuse,
5265
+ onRegenerate,
5266
+ onQuit
5267
+ }) {
5268
+ const { summary, context } = gateText({ tokensPath, sourceChanged });
5269
+ return /* @__PURE__ */ jsx11(
5270
+ GateStep,
5271
+ {
5272
+ message: "Existing tokens.json found",
5273
+ summary,
5274
+ context,
5275
+ continueLabel: "Reuse existing tokens",
5276
+ skipLabel: "Regenerate tokens",
5277
+ onContinue: onReuse,
5278
+ onSkip: onRegenerate,
5279
+ onQuit
5280
+ }
5281
+ );
5282
+ }
5283
+ var init_screen5 = __esm({
5284
+ "packages/experience-design-system-cli/src/tui/import/steps/05-token-reuse/screen.tsx"() {
5285
+ "use strict";
5286
+ init_shared2();
5287
+ init_logic8();
5288
+ }
5289
+ });
5290
+
5561
5291
  // packages/experience-design-system-cli/src/tui/import/steps/index.ts
5562
5292
  var init_steps = __esm({
5563
5293
  "packages/experience-design-system-cli/src/tui/import/steps/index.ts"() {
@@ -5566,6 +5296,7 @@ var init_steps = __esm({
5566
5296
  init_screen2();
5567
5297
  init_screen3();
5568
5298
  init_screen4();
5299
+ init_screen5();
5569
5300
  }
5570
5301
  });
5571
5302
 
@@ -5579,15 +5310,23 @@ function buildArgs2(options) {
5579
5310
  if (options.tokens) {
5580
5311
  args.push("--tokens", options.tokens);
5581
5312
  }
5313
+ args.push(...importOptionArgs({ agent: options.agent, prompt: options.prompt ?? [], cache: options.cache ?? true }));
5582
5314
  return args;
5583
5315
  }
5316
+ function buildEnv(options, base = process.env) {
5317
+ return {
5318
+ ...base,
5319
+ ...options.skipCredentials ? { EDS_IMPORT_SKIP_CREDENTIALS: "1" } : {},
5320
+ ...options.tokenStrategy ? { EDS_IMPORT_TOKENS: options.tokenStrategy } : {}
5321
+ };
5322
+ }
5584
5323
  async function spawnV1Import(options = {}) {
5585
5324
  const cliPath = findLegacyCliPath();
5586
5325
  const args = buildArgs2(options);
5587
5326
  return new Promise((resolvePromise) => {
5588
5327
  const child = spawn3("node", [cliPath, ...args], {
5589
5328
  stdio: "inherit",
5590
- env: options.skipCredentials ? { ...process.env, EDS_IMPORT_SKIP_CREDENTIALS: "1" } : process.env
5329
+ env: buildEnv(options)
5591
5330
  });
5592
5331
  child.on("close", (code) => {
5593
5332
  resolvePromise({ exitCode: code ?? 1, result: void 0, stdout: "", stderr: "" });
@@ -5601,6 +5340,7 @@ var init_spawn_v1_import = __esm({
5601
5340
  "packages/experience-design-system-cli/src/tui/import/spawn-v1-import.ts"() {
5602
5341
  "use strict";
5603
5342
  init_legacy_cli_path();
5343
+ init_import_options();
5604
5344
  }
5605
5345
  });
5606
5346
 
@@ -5631,9 +5371,9 @@ var init_terminal_input = __esm({
5631
5371
  import { randomBytes } from "node:crypto";
5632
5372
  import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
5633
5373
  import { homedir as homedir2 } from "node:os";
5634
- import { dirname as dirname2, join as join5 } from "node:path";
5374
+ import { dirname as dirname2, join as join6 } from "node:path";
5635
5375
  function configRoot2() {
5636
- return process.env["EDS_HOME"] || join5(homedir2(), ".contentful", "experience-design-system-cli");
5376
+ return process.env["EDS_HOME"] || join6(homedir2(), ".contentful", "experience-design-system-cli");
5637
5377
  }
5638
5378
  async function readSettings2() {
5639
5379
  try {
@@ -5657,10 +5397,10 @@ var configFilePath2, runsFilePath2, debugSessionsDir2, oldConfigDir2;
5657
5397
  var init_config = __esm({
5658
5398
  "packages/experience-design-system-types/dist/src/config/index.js"() {
5659
5399
  "use strict";
5660
- configFilePath2 = () => join5(configRoot2(), "config.json");
5661
- runsFilePath2 = () => join5(configRoot2(), "state", "runs.json");
5662
- debugSessionsDir2 = () => join5(configRoot2(), "debug", "sessions");
5663
- oldConfigDir2 = () => join5(homedir2(), ".config", "experiences");
5400
+ configFilePath2 = () => join6(configRoot2(), "config.json");
5401
+ runsFilePath2 = () => join6(configRoot2(), "state", "runs.json");
5402
+ debugSessionsDir2 = () => join6(configRoot2(), "debug", "sessions");
5403
+ oldConfigDir2 = () => join6(homedir2(), ".config", "experiences");
5664
5404
  }
5665
5405
  });
5666
5406
 
@@ -5686,7 +5426,7 @@ var init_debug_mode_store = __esm({
5686
5426
  // packages/experience-design-system-cli/src/tui/debug-store.ts
5687
5427
  import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
5688
5428
  import { existsSync as existsSync4, readdirSync as readdirSync2 } from "node:fs";
5689
- import { join as join6 } from "node:path";
5429
+ import { join as join7 } from "node:path";
5690
5430
  function generateRunId() {
5691
5431
  const now = /* @__PURE__ */ new Date();
5692
5432
  const pad = (n) => String(n).padStart(2, "0");
@@ -5711,7 +5451,7 @@ function generateSessionId3() {
5711
5451
  return `${today}-session-${maxSeq + 1}`;
5712
5452
  }
5713
5453
  function sessionDebugDir() {
5714
- return join6(debugSessionsDir2(), SESSION_ID);
5454
+ return join7(debugSessionsDir2(), SESSION_ID);
5715
5455
  }
5716
5456
  function currentDebugSessionDir() {
5717
5457
  return sessionDebugDir();
@@ -5756,10 +5496,10 @@ async function finishDebugRun({
5756
5496
  const durationMs = Date.now() - run.startedAt;
5757
5497
  const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
5758
5498
  const flowSegments = run.flow.split("/");
5759
- const dir = join6(sessionDebugDir(), ...flowSegments);
5499
+ const dir = join7(sessionDebugDir(), ...flowSegments);
5760
5500
  await mkdir2(dir, { recursive: true });
5761
5501
  const filename = nextAttemptFilename(dir, run.menuOption);
5762
- await writeFile2(join6(dir, filename), content, { mode: 384 });
5502
+ await writeFile2(join7(dir, filename), content, { mode: 384 });
5763
5503
  }
5764
5504
  function nextAttemptFilename(dir, menuOption) {
5765
5505
  const today = datePrefix();
@@ -5774,13 +5514,13 @@ function nextAttemptFilename(dir, menuOption) {
5774
5514
  }
5775
5515
  function renderMarkdown(run, finish) {
5776
5516
  const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
5777
- const stepLabel = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
5517
+ const stepLabel2 = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
5778
5518
  const flowSlug = run.flow.split("/").join("-");
5779
5519
  return `# Debug Log
5780
5520
 
5781
5521
  - Run ID: ${run.runId}
5782
5522
  - Flow: ${flowSlug}
5783
- - Step: ${stepLabel}
5523
+ - Step: ${stepLabel2}
5784
5524
  - Menu option: ${run.menuOption}
5785
5525
  - Date: ${(/* @__PURE__ */ new Date()).toISOString()}
5786
5526
  - CLI version: ${readPackageVersion()}
@@ -5865,21 +5605,21 @@ var init_help_info = __esm({
5865
5605
  });
5866
5606
 
5867
5607
  // packages/experience-design-system-cli/src/tui/help/PageContainer.tsx
5868
- import { useEffect as useEffect4, useState as useState7 } from "react";
5869
- import { Box as Box7, Text as Text8, useInput as useInput7 } from "ink";
5870
- import { Fragment as Fragment2, jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
5608
+ import { useEffect as useEffect5, useState as useState8 } from "react";
5609
+ import { Box as Box10, Text as Text11, useInput as useInput9 } from "ink";
5610
+ import { Fragment as Fragment2, jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
5871
5611
  function Section({ title, rows }) {
5872
- return /* @__PURE__ */ jsxs7(Box7, { flexDirection: "column", children: [
5873
- /* @__PURE__ */ jsx8(Text8, { bold: true, color: PALETTE.accent, children: title }),
5874
- rows.map((row) => /* @__PURE__ */ jsxs7(Box7, { gap: 1, children: [
5875
- /* @__PURE__ */ jsx8(Box7, { width: 14, flexShrink: 0, children: /* @__PURE__ */ jsx8(Text8, { color: PALETTE.muted, children: row.label }) }),
5876
- /* @__PURE__ */ jsx8(Text8, { children: row.value })
5612
+ return /* @__PURE__ */ jsxs10(Box10, { flexDirection: "column", children: [
5613
+ /* @__PURE__ */ jsx12(Text11, { bold: true, color: PALETTE.accent, children: title }),
5614
+ rows.map((row) => /* @__PURE__ */ jsxs10(Box10, { gap: 1, children: [
5615
+ /* @__PURE__ */ jsx12(Box10, { width: 14, flexShrink: 0, children: /* @__PURE__ */ jsx12(Text11, { color: PALETTE.muted, children: row.label }) }),
5616
+ /* @__PURE__ */ jsx12(Text11, { children: row.value })
5877
5617
  ] }, row.label))
5878
5618
  ] });
5879
5619
  }
5880
5620
  function HelpScreen({ onDone }) {
5881
- const [info, setInfo] = useState7();
5882
- useEffect4(() => {
5621
+ const [info, setInfo] = useState8();
5622
+ useEffect5(() => {
5883
5623
  startDebugRun({ flow: "help", step: "01-help", menuOption: "Help", inputs: {} });
5884
5624
  void readHelpInfo().then(setInfo);
5885
5625
  }, []);
@@ -5887,7 +5627,7 @@ function HelpScreen({ onDone }) {
5887
5627
  void finishDebugRun({ outputs: {}, status: "success", exitMethod });
5888
5628
  onDone();
5889
5629
  };
5890
- useInput7((input, key) => {
5630
+ useInput9((input, key) => {
5891
5631
  if (key.return) {
5892
5632
  leave("saved");
5893
5633
  return;
@@ -5897,14 +5637,14 @@ function HelpScreen({ onDone }) {
5897
5637
  return;
5898
5638
  }
5899
5639
  });
5900
- return /* @__PURE__ */ jsxs7(Box7, { flexDirection: "column", paddingX: 2, paddingY: 1, gap: 1, children: [
5901
- /* @__PURE__ */ jsx8(Text8, { bold: true, children: "Help" }),
5902
- info ? /* @__PURE__ */ jsxs7(Fragment2, { children: [
5903
- /* @__PURE__ */ jsx8(Section, { title: "Where things are stored", rows: info.storage }),
5904
- /* @__PURE__ */ jsx8(Section, { title: "Troubleshooting", rows: info.troubleshooting }),
5905
- /* @__PURE__ */ jsx8(Text8, { color: PALETTE.muted, children: "Hit a problem? Turn on Debug Mode in Settings, reproduce it, then share the session folder above. The CMA token is redacted from those logs." })
5906
- ] }) : /* @__PURE__ */ jsx8(Text8, { color: PALETTE.accent, children: "Loading..." }),
5907
- /* @__PURE__ */ jsx8(
5640
+ return /* @__PURE__ */ jsxs10(Box10, { flexDirection: "column", paddingX: 2, paddingY: 1, gap: 1, children: [
5641
+ /* @__PURE__ */ jsx12(Text11, { bold: true, children: "Help" }),
5642
+ info ? /* @__PURE__ */ jsxs10(Fragment2, { children: [
5643
+ /* @__PURE__ */ jsx12(Section, { title: "Where things are stored", rows: info.storage }),
5644
+ /* @__PURE__ */ jsx12(Section, { title: "Troubleshooting", rows: info.troubleshooting }),
5645
+ /* @__PURE__ */ jsx12(Text11, { color: PALETTE.muted, children: "Hit a problem? Turn on Debug Mode in Settings, reproduce it, then share the session folder above. The CMA token is redacted from those logs." })
5646
+ ] }) : /* @__PURE__ */ jsx12(Text11, { color: PALETTE.accent, children: "Loading..." }),
5647
+ /* @__PURE__ */ jsx12(
5908
5648
  ControlHints,
5909
5649
  {
5910
5650
  hints: [
@@ -5926,20 +5666,20 @@ var init_PageContainer2 = __esm({
5926
5666
  });
5927
5667
 
5928
5668
  // packages/experience-design-system-cli/src/tui/settings/PageContainer.tsx
5929
- import { useState as useState8 } from "react";
5930
- import { Box as Box8, Text as Text9, useInput as useInput8 } from "ink";
5931
- import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
5669
+ import { useState as useState9 } from "react";
5670
+ import { Box as Box11, Text as Text12, useInput as useInput10 } from "ink";
5671
+ import { jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
5932
5672
  function SettingsScreen({
5933
5673
  onNavigate,
5934
5674
  onBack
5935
5675
  }) {
5936
- const [focusIdx, setFocusIdx] = useState8(0);
5676
+ const [focusIdx, setFocusIdx] = useState9(0);
5937
5677
  const items = [
5938
5678
  { label: "Configuration", screen: "settings-configuration" },
5939
5679
  { label: "Opt-in Analytics", screen: "settings-opt-in-analytics" },
5940
5680
  { label: "Debug Mode", screen: "settings-debug-mode" }
5941
5681
  ];
5942
- useInput8((input, key) => {
5682
+ useInput10((input, key) => {
5943
5683
  if (key.upArrow) {
5944
5684
  setFocusIdx((i) => (i - 1 + items.length) % items.length);
5945
5685
  return;
@@ -5959,15 +5699,15 @@ function SettingsScreen({
5959
5699
  onBack();
5960
5700
  }
5961
5701
  });
5962
- return /* @__PURE__ */ jsxs8(Box8, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [
5963
- /* @__PURE__ */ jsx9(Text9, { bold: true, children: "Settings" }),
5964
- /* @__PURE__ */ jsx9(Text9, { children: " " }),
5965
- items.map((item, i) => /* @__PURE__ */ jsxs8(Text9, { color: i === focusIdx ? "cyan" : void 0, children: [
5702
+ return /* @__PURE__ */ jsxs11(Box11, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [
5703
+ /* @__PURE__ */ jsx13(Text12, { bold: true, children: "Settings" }),
5704
+ /* @__PURE__ */ jsx13(Text12, { children: " " }),
5705
+ items.map((item, i) => /* @__PURE__ */ jsxs11(Text12, { color: i === focusIdx ? "cyan" : void 0, children: [
5966
5706
  i === focusIdx ? "> " : " ",
5967
5707
  item.label
5968
5708
  ] }, item.label)),
5969
- /* @__PURE__ */ jsx9(Text9, { children: " " }),
5970
- /* @__PURE__ */ jsx9(
5709
+ /* @__PURE__ */ jsx13(Text12, { children: " " }),
5710
+ /* @__PURE__ */ jsx13(
5971
5711
  ControlHints,
5972
5712
  {
5973
5713
  hints: [
@@ -6028,10 +5768,10 @@ var init_config_store = __esm({
6028
5768
  });
6029
5769
 
6030
5770
  // packages/experience-design-system-cli/src/tui/settings/contentful-configuration/ContentfulConfigScreen.tsx
6031
- import { useEffect as useEffect5, useState as useState9 } from "react";
6032
- import { Box as Box9, Text as Text10, useInput as useInput9 } from "ink";
5771
+ import { useEffect as useEffect6, useState as useState10 } from "react";
5772
+ import { Box as Box12, Text as Text13, useInput as useInput11 } from "ink";
6033
5773
  import TextInput4 from "ink-text-input";
6034
- import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
5774
+ import { Fragment as Fragment3, jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
6035
5775
  function debugFields(config) {
6036
5776
  return {
6037
5777
  space_id: config?.spaceId ?? "",
@@ -6043,14 +5783,14 @@ function debugFields(config) {
6043
5783
  };
6044
5784
  }
6045
5785
  function ConfigurationScreen({ onDone }) {
6046
- const [stage, setStage] = useState9("loading");
6047
- const [config, setConfig] = useState9(null);
6048
- const [activeField, setActiveField] = useState9("spaceId");
6049
- const [notice, setNotice] = useState9(null);
6050
- const [lastSaved, setLastSaved] = useState9(null);
6051
- const [editing, setEditing] = useState9(false);
6052
- const [valueBeforeEdit, setValueBeforeEdit] = useState9("");
6053
- useEffect5(() => {
5786
+ const [stage, setStage] = useState10("loading");
5787
+ const [config, setConfig] = useState10(null);
5788
+ const [activeField, setActiveField] = useState10("spaceId");
5789
+ const [notice, setNotice] = useState10(null);
5790
+ const [lastSaved, setLastSaved] = useState10(null);
5791
+ const [editing, setEditing] = useState10(false);
5792
+ const [valueBeforeEdit, setValueBeforeEdit] = useState10("");
5793
+ useEffect6(() => {
6054
5794
  readCredentials().then((cfg) => {
6055
5795
  setConfig(cfg);
6056
5796
  setStage("form");
@@ -6090,7 +5830,7 @@ function ConfigurationScreen({ onDone }) {
6090
5830
  );
6091
5831
  onDone();
6092
5832
  }
6093
- useInput9((input, key) => {
5833
+ useInput11((input, key) => {
6094
5834
  if (stage === "loading" || stage === "saving") return;
6095
5835
  if (editing) {
6096
5836
  if (key.escape) {
@@ -6127,26 +5867,26 @@ function ConfigurationScreen({ onDone }) {
6127
5867
  }
6128
5868
  });
6129
5869
  if (stage === "loading") {
6130
- return /* @__PURE__ */ jsxs9(Box9, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [
6131
- /* @__PURE__ */ jsx10(Text10, { bold: true, children: "Configuration" }),
6132
- /* @__PURE__ */ jsx10(Text10, { children: " " }),
6133
- /* @__PURE__ */ jsx10(Text10, { color: PALETTE.accent, children: "Loading..." })
5870
+ return /* @__PURE__ */ jsxs12(Box12, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [
5871
+ /* @__PURE__ */ jsx14(Text13, { bold: true, children: "Configuration" }),
5872
+ /* @__PURE__ */ jsx14(Text13, { children: " " }),
5873
+ /* @__PURE__ */ jsx14(Text13, { color: PALETTE.accent, children: "Loading..." })
6134
5874
  ] });
6135
5875
  }
6136
- return /* @__PURE__ */ jsxs9(Box9, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [
6137
- /* @__PURE__ */ jsx10(Text10, { bold: true, children: "Configuration" }),
6138
- /* @__PURE__ */ jsx10(Text10, { children: " " }),
6139
- /* @__PURE__ */ jsx10(Box9, { flexDirection: "column", children: FIELD_ORDER.map((field) => {
5876
+ return /* @__PURE__ */ jsxs12(Box12, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [
5877
+ /* @__PURE__ */ jsx14(Text13, { bold: true, children: "Configuration" }),
5878
+ /* @__PURE__ */ jsx14(Text13, { children: " " }),
5879
+ /* @__PURE__ */ jsx14(Box12, { flexDirection: "column", children: FIELD_ORDER.map((field) => {
6140
5880
  const isActive = activeField === field;
6141
5881
  const value = fieldValue(field);
6142
5882
  const display = field === "cmaToken" ? "\u2022".repeat(value.length) : value;
6143
- return /* @__PURE__ */ jsxs9(Box9, { gap: 1, children: [
6144
- /* @__PURE__ */ jsx10(Text10, { color: isActive ? PALETTE.accent : void 0, children: isActive ? "\u276F" : " " }),
6145
- /* @__PURE__ */ jsxs9(Text10, { bold: isActive, children: [
5883
+ return /* @__PURE__ */ jsxs12(Box12, { gap: 1, children: [
5884
+ /* @__PURE__ */ jsx14(Text13, { color: isActive ? PALETTE.accent : void 0, children: isActive ? "\u276F" : " " }),
5885
+ /* @__PURE__ */ jsxs12(Text13, { bold: isActive, children: [
6146
5886
  FIELD_LABELS[field],
6147
5887
  ":"
6148
5888
  ] }),
6149
- isActive && editing ? /* @__PURE__ */ jsx10(
5889
+ isActive && editing ? /* @__PURE__ */ jsx14(
6150
5890
  TextInput4,
6151
5891
  {
6152
5892
  value,
@@ -6154,19 +5894,19 @@ function ConfigurationScreen({ onDone }) {
6154
5894
  onSubmit: () => setEditing(false),
6155
5895
  mask: field === "cmaToken" ? "\u2022" : void 0
6156
5896
  }
6157
- ) : /* @__PURE__ */ jsx10(Text10, { children: display || /* @__PURE__ */ jsx10(Text10, { color: PALETTE.muted, children: "(empty)" }) })
5897
+ ) : /* @__PURE__ */ jsx14(Text13, { children: display || /* @__PURE__ */ jsx14(Text13, { color: PALETTE.muted, children: "(empty)" }) })
6158
5898
  ] }, field);
6159
5899
  }) }),
6160
- notice && /* @__PURE__ */ jsxs9(Fragment3, { children: [
6161
- /* @__PURE__ */ jsx10(Text10, { children: " " }),
6162
- /* @__PURE__ */ jsxs9(Text10, { color: notice.kind === "success" ? PALETTE.success : PALETTE.error, children: [
5900
+ notice && /* @__PURE__ */ jsxs12(Fragment3, { children: [
5901
+ /* @__PURE__ */ jsx14(Text13, { children: " " }),
5902
+ /* @__PURE__ */ jsxs12(Text13, { color: notice.kind === "success" ? PALETTE.success : PALETTE.error, children: [
6163
5903
  notice.kind === "success" ? "\u2713" : "\u2717",
6164
5904
  " ",
6165
5905
  notice.text
6166
5906
  ] })
6167
5907
  ] }),
6168
- /* @__PURE__ */ jsx10(Text10, { children: " " }),
6169
- /* @__PURE__ */ jsx10(
5908
+ /* @__PURE__ */ jsx14(Text13, { children: " " }),
5909
+ /* @__PURE__ */ jsx14(
6170
5910
  ControlHints,
6171
5911
  {
6172
5912
  hints: editing ? [
@@ -6234,13 +5974,13 @@ var init_analytics_store = __esm({
6234
5974
  });
6235
5975
 
6236
5976
  // packages/experience-design-system-cli/src/tui/settings/opt-in-analytics/screen.tsx
6237
- import { useEffect as useEffect6, useState as useState10 } from "react";
6238
- import { Box as Box10, Text as Text11, useInput as useInput10 } from "ink";
6239
- import { Fragment as Fragment4, jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
5977
+ import { useEffect as useEffect7, useState as useState11 } from "react";
5978
+ import { Box as Box13, Text as Text14, useInput as useInput12 } from "ink";
5979
+ import { Fragment as Fragment4, jsx as jsx15, jsxs as jsxs13 } from "react/jsx-runtime";
6240
5980
  function OptInAnalyticsScreen({ onDone }) {
6241
- const [loading, setLoading] = useState10(true);
6242
- const [enabled, setEnabled] = useState10(true);
6243
- useEffect6(() => {
5981
+ const [loading, setLoading] = useState11(true);
5982
+ const [enabled, setEnabled] = useState11(true);
5983
+ useEffect7(() => {
6244
5984
  readAnalyticsSetting().then((setting) => {
6245
5985
  setEnabled(setting.enabled);
6246
5986
  setLoading(false);
@@ -6252,7 +5992,7 @@ function OptInAnalyticsScreen({ onDone }) {
6252
5992
  });
6253
5993
  });
6254
5994
  }, []);
6255
- useInput10((input, key) => {
5995
+ useInput12((input, key) => {
6256
5996
  if (loading) return;
6257
5997
  if (key.return || input === " ") {
6258
5998
  setEnabled((current) => {
@@ -6267,21 +6007,21 @@ function OptInAnalyticsScreen({ onDone }) {
6267
6007
  onDone();
6268
6008
  }
6269
6009
  });
6270
- return /* @__PURE__ */ jsxs10(Box10, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [
6271
- /* @__PURE__ */ jsx11(Text11, { bold: true, children: "Settings \u203A Opt-in Analytics" }),
6272
- /* @__PURE__ */ jsx11(Text11, { children: " " }),
6273
- loading ? /* @__PURE__ */ jsx11(Text11, { color: PALETTE.muted, children: "Loading\u2026" }) : /* @__PURE__ */ jsxs10(Fragment4, { children: [
6274
- /* @__PURE__ */ jsxs10(Text11, { children: [
6010
+ return /* @__PURE__ */ jsxs13(Box13, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [
6011
+ /* @__PURE__ */ jsx15(Text14, { bold: true, children: "Settings \u203A Opt-in Analytics" }),
6012
+ /* @__PURE__ */ jsx15(Text14, { children: " " }),
6013
+ loading ? /* @__PURE__ */ jsx15(Text14, { color: PALETTE.muted, children: "Loading\u2026" }) : /* @__PURE__ */ jsxs13(Fragment4, { children: [
6014
+ /* @__PURE__ */ jsxs13(Text14, { children: [
6275
6015
  "Share anonymous usage data:",
6276
6016
  " ",
6277
- /* @__PURE__ */ jsx11(Text11, { bold: true, color: enabled ? PALETTE.success : PALETTE.muted, children: enabled ? "On" : "Off" })
6017
+ /* @__PURE__ */ jsx15(Text14, { bold: true, color: enabled ? PALETTE.success : PALETTE.muted, children: enabled ? "On" : "Off" })
6278
6018
  ] }),
6279
- /* @__PURE__ */ jsx11(Text11, { children: " " }),
6280
- /* @__PURE__ */ jsx11(Text11, { color: PALETTE.muted, children: "Shares which CLI commands are used and where imports succeed or fail." }),
6281
- /* @__PURE__ */ jsx11(Text11, { color: PALETTE.muted, children: "Never includes source code, file paths, credentials, or authored content." })
6019
+ /* @__PURE__ */ jsx15(Text14, { children: " " }),
6020
+ /* @__PURE__ */ jsx15(Text14, { color: PALETTE.muted, children: "Shares which CLI commands are used and where imports succeed or fail." }),
6021
+ /* @__PURE__ */ jsx15(Text14, { color: PALETTE.muted, children: "Never includes source code, file paths, credentials, or authored content." })
6282
6022
  ] }),
6283
- /* @__PURE__ */ jsx11(Text11, { children: " " }),
6284
- /* @__PURE__ */ jsx11(
6023
+ /* @__PURE__ */ jsx15(Text14, { children: " " }),
6024
+ /* @__PURE__ */ jsx15(
6285
6025
  ControlHints,
6286
6026
  {
6287
6027
  hints: [
@@ -6292,7 +6032,7 @@ function OptInAnalyticsScreen({ onDone }) {
6292
6032
  )
6293
6033
  ] });
6294
6034
  }
6295
- var init_screen5 = __esm({
6035
+ var init_screen6 = __esm({
6296
6036
  "packages/experience-design-system-cli/src/tui/settings/opt-in-analytics/screen.tsx"() {
6297
6037
  "use strict";
6298
6038
  init_home_theme();
@@ -6303,12 +6043,12 @@ var init_screen5 = __esm({
6303
6043
  });
6304
6044
 
6305
6045
  // packages/experience-design-system-cli/src/tui/upgrade/PageContainer.tsx
6306
- import { useEffect as useEffect7, useState as useState11 } from "react";
6307
- import { Box as Box11, Text as Text12, useInput as useInput11 } from "ink";
6308
- import { jsx as jsx12, jsxs as jsxs11 } from "react/jsx-runtime";
6046
+ import { useEffect as useEffect8, useState as useState12 } from "react";
6047
+ import { Box as Box14, Text as Text15, useInput as useInput13 } from "ink";
6048
+ import { jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
6309
6049
  function UpgradeScreen({ onDone }) {
6310
- const [upgradeCheck, setUpgradeCheck] = useState11();
6311
- useEffect7(() => {
6050
+ const [upgradeCheck, setUpgradeCheck] = useState12();
6051
+ useEffect8(() => {
6312
6052
  startDebugRun({
6313
6053
  flow: "upgrade",
6314
6054
  step: "01-upgrade",
@@ -6317,7 +6057,7 @@ function UpgradeScreen({ onDone }) {
6317
6057
  });
6318
6058
  checkForUpgrade().then(setUpgradeCheck).catch(() => setUpgradeCheck({ status: "error" }));
6319
6059
  }, []);
6320
- useInput11((_input, key) => {
6060
+ useInput13((_input, key) => {
6321
6061
  if (key.return) {
6322
6062
  void finishDebugRun({
6323
6063
  outputs: upgradeCheck ?? {},
@@ -6328,12 +6068,12 @@ function UpgradeScreen({ onDone }) {
6328
6068
  return;
6329
6069
  }
6330
6070
  });
6331
- return /* @__PURE__ */ jsxs11(Box11, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [
6332
- /* @__PURE__ */ jsx12(Text12, { bold: true, children: "Upgrade" }),
6333
- /* @__PURE__ */ jsx12(Text12, { children: " " }),
6071
+ return /* @__PURE__ */ jsxs14(Box14, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [
6072
+ /* @__PURE__ */ jsx16(Text15, { bold: true, children: "Upgrade" }),
6073
+ /* @__PURE__ */ jsx16(Text15, { children: " " }),
6334
6074
  renderBody(upgradeCheck),
6335
- /* @__PURE__ */ jsx12(Text12, { children: " " }),
6336
- /* @__PURE__ */ jsxs11(Text12, { bold: true, color: PALETTE.accent, children: [
6075
+ /* @__PURE__ */ jsx16(Text15, { children: " " }),
6076
+ /* @__PURE__ */ jsxs14(Text15, { bold: true, color: PALETTE.accent, children: [
6337
6077
  FOCUS_MARKER,
6338
6078
  " Go Back"
6339
6079
  ] })
@@ -6341,34 +6081,34 @@ function UpgradeScreen({ onDone }) {
6341
6081
  }
6342
6082
  function renderBody(upgradeCheck) {
6343
6083
  if (!upgradeCheck) {
6344
- return /* @__PURE__ */ jsx12(Text12, { color: PALETTE.muted, children: "Checking for updates\u2026" });
6084
+ return /* @__PURE__ */ jsx16(Text15, { color: PALETTE.muted, children: "Checking for updates\u2026" });
6345
6085
  }
6346
6086
  if (upgradeCheck.status === "error") {
6347
- return /* @__PURE__ */ jsx12(Text12, { color: PALETTE.warning, children: "Couldn't check for updates \u2014 check your network connection and try again." });
6087
+ return /* @__PURE__ */ jsx16(Text15, { color: PALETTE.warning, children: "Couldn't check for updates \u2014 check your network connection and try again." });
6348
6088
  }
6349
6089
  if (upgradeCheck.status === "up-to-date") {
6350
- return /* @__PURE__ */ jsxs11(Text12, { color: PALETTE.success, children: [
6090
+ return /* @__PURE__ */ jsxs14(Text15, { color: PALETTE.success, children: [
6351
6091
  "You're already on the latest version (v",
6352
6092
  upgradeCheck.current,
6353
6093
  ")."
6354
6094
  ] });
6355
6095
  }
6356
- return /* @__PURE__ */ jsxs11(Box11, { flexDirection: "column", children: [
6357
- /* @__PURE__ */ jsxs11(Text12, { color: PALETTE.muted, children: [
6358
- /* @__PURE__ */ jsxs11(Text12, { bold: true, color: PALETTE.success, children: [
6096
+ return /* @__PURE__ */ jsxs14(Box14, { flexDirection: "column", children: [
6097
+ /* @__PURE__ */ jsxs14(Text15, { color: PALETTE.muted, children: [
6098
+ /* @__PURE__ */ jsxs14(Text15, { bold: true, color: PALETTE.success, children: [
6359
6099
  "v",
6360
6100
  upgradeCheck.latest
6361
6101
  ] }),
6362
6102
  " ",
6363
6103
  "is available (you're on ",
6364
- /* @__PURE__ */ jsxs11(Text12, { bold: true, children: [
6104
+ /* @__PURE__ */ jsxs14(Text15, { bold: true, children: [
6365
6105
  "v",
6366
6106
  upgradeCheck.current
6367
6107
  ] }),
6368
6108
  "). Exit this program, cd into the root of your local clone of contentful/experience-design-system-sdk-public, then run:"
6369
6109
  ] }),
6370
- /* @__PURE__ */ jsx12(Text12, { children: " " }),
6371
- /* @__PURE__ */ jsx12(Box11, { flexDirection: "column", borderStyle: "round", borderColor: PALETTE.border, paddingX: 1, children: UPGRADE_COMMANDS.map((cmd) => /* @__PURE__ */ jsx12(Text12, { bold: true, children: cmd }, cmd)) })
6110
+ /* @__PURE__ */ jsx16(Text15, { children: " " }),
6111
+ /* @__PURE__ */ jsx16(Box14, { flexDirection: "column", borderStyle: "round", borderColor: PALETTE.border, paddingX: 1, children: UPGRADE_COMMANDS.map((cmd) => /* @__PURE__ */ jsx16(Text15, { bold: true, children: cmd }, cmd)) })
6372
6112
  ] });
6373
6113
  }
6374
6114
  var UPGRADE_COMMANDS;
@@ -6383,13 +6123,13 @@ var init_PageContainer4 = __esm({
6383
6123
  });
6384
6124
 
6385
6125
  // packages/experience-design-system-cli/src/tui/settings/debug-mode/screen.tsx
6386
- import { useEffect as useEffect8, useState as useState12 } from "react";
6387
- import { Box as Box12, Text as Text13, useInput as useInput12 } from "ink";
6388
- import { jsx as jsx13, jsxs as jsxs12 } from "react/jsx-runtime";
6126
+ import { useEffect as useEffect9, useState as useState13 } from "react";
6127
+ import { Box as Box15, Text as Text16, useInput as useInput14 } from "ink";
6128
+ import { jsx as jsx17, jsxs as jsxs15 } from "react/jsx-runtime";
6389
6129
  function DebugModeScreen({ onDone }) {
6390
- const [loading, setLoading] = useState12(true);
6391
- const [enabled, setEnabled] = useState12(true);
6392
- useEffect8(() => {
6130
+ const [loading, setLoading] = useState13(true);
6131
+ const [enabled, setEnabled] = useState13(true);
6132
+ useEffect9(() => {
6393
6133
  readDebugModeSetting().then((setting) => {
6394
6134
  setEnabled(setting.enabled);
6395
6135
  setLoading(false);
@@ -6401,7 +6141,7 @@ function DebugModeScreen({ onDone }) {
6401
6141
  });
6402
6142
  });
6403
6143
  }, []);
6404
- useInput12((input, key) => {
6144
+ useInput14((input, key) => {
6405
6145
  if (loading) return;
6406
6146
  if (key.return || input === " ") {
6407
6147
  setEnabled((current) => {
@@ -6416,16 +6156,16 @@ function DebugModeScreen({ onDone }) {
6416
6156
  onDone();
6417
6157
  }
6418
6158
  });
6419
- return /* @__PURE__ */ jsxs12(Box12, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [
6420
- /* @__PURE__ */ jsx13(Text13, { bold: true, children: "Settings \u203A Debug Mode" }),
6421
- /* @__PURE__ */ jsx13(Text13, { children: " " }),
6422
- loading ? /* @__PURE__ */ jsx13(Text13, { color: PALETTE.muted, children: "Loading\u2026" }) : /* @__PURE__ */ jsxs12(Text13, { children: [
6159
+ return /* @__PURE__ */ jsxs15(Box15, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [
6160
+ /* @__PURE__ */ jsx17(Text16, { bold: true, children: "Settings \u203A Debug Mode" }),
6161
+ /* @__PURE__ */ jsx17(Text16, { children: " " }),
6162
+ loading ? /* @__PURE__ */ jsx17(Text16, { color: PALETTE.muted, children: "Loading\u2026" }) : /* @__PURE__ */ jsxs15(Text16, { children: [
6423
6163
  "Debug logging:",
6424
6164
  " ",
6425
- /* @__PURE__ */ jsx13(Text13, { bold: true, color: enabled ? PALETTE.success : PALETTE.muted, children: enabled ? "On" : "Off" })
6165
+ /* @__PURE__ */ jsx17(Text16, { bold: true, color: enabled ? PALETTE.success : PALETTE.muted, children: enabled ? "On" : "Off" })
6426
6166
  ] }),
6427
- /* @__PURE__ */ jsx13(Text13, { children: " " }),
6428
- /* @__PURE__ */ jsx13(
6167
+ /* @__PURE__ */ jsx17(Text16, { children: " " }),
6168
+ /* @__PURE__ */ jsx17(
6429
6169
  ControlHints,
6430
6170
  {
6431
6171
  hints: [
@@ -6436,7 +6176,7 @@ function DebugModeScreen({ onDone }) {
6436
6176
  )
6437
6177
  ] });
6438
6178
  }
6439
- var init_screen6 = __esm({
6179
+ var init_screen7 = __esm({
6440
6180
  "packages/experience-design-system-cli/src/tui/settings/debug-mode/screen.tsx"() {
6441
6181
  "use strict";
6442
6182
  init_home_theme();
@@ -6451,17 +6191,19 @@ var app_exports = {};
6451
6191
  __export(app_exports, {
6452
6192
  runApp: () => runApp
6453
6193
  });
6454
- import { useEffect as useEffect9, useState as useState13 } from "react";
6455
- import { Fragment as Fragment5, jsx as jsx14 } from "react/jsx-runtime";
6456
- function App({ onLaunchImport, importExitCode }) {
6194
+ import { join as join8 } from "node:path";
6195
+ import { useEffect as useEffect10, useState as useState14 } from "react";
6196
+ import { Fragment as Fragment5, jsx as jsx18 } from "react/jsx-runtime";
6197
+ function App({ importOptions, onLaunchImport, importExitCode }) {
6457
6198
  const returnedFromImport = importExitCode !== void 0;
6458
- const [screen, setScreen] = useState13(returnedFromImport ? "import" : "start");
6459
- const [showImportResult, setShowImportResult] = useState13(returnedFromImport);
6460
- const [projectPath, setProjectPath] = useState13();
6461
- const [tokensPath, setTokensPath] = useState13();
6462
- const [scannedFiles, setScannedFiles] = useState13();
6463
- const [importDefaults, setImportDefaults] = useState13();
6464
- useEffect9(() => {
6199
+ const [screen, setScreen] = useState14(returnedFromImport ? "import" : "start");
6200
+ const [showImportResult, setShowImportResult] = useState14(returnedFromImport);
6201
+ const [projectPath, setProjectPath] = useState14();
6202
+ const [tokensPath, setTokensPath] = useState14();
6203
+ const [scannedFiles, setScannedFiles] = useState14();
6204
+ const [pendingLaunch, setPendingLaunch] = useState14();
6205
+ const [importDefaults, setImportDefaults] = useState14();
6206
+ useEffect10(() => {
6465
6207
  if (screen !== "import") {
6466
6208
  setImportDefaults(void 0);
6467
6209
  return;
@@ -6476,7 +6218,27 @@ function App({ onLaunchImport, importExitCode }) {
6476
6218
  }, [screen]);
6477
6219
  const finishCredentials = async (result, projectPath2, tokens, filePaths) => {
6478
6220
  if (!result.skipped) await writeCredentials({ ...result.credentials });
6479
- onLaunchImport?.({ projectPath: projectPath2, tokens, filePaths, skipCredentials: result.skipped });
6221
+ const launch = {
6222
+ projectPath: projectPath2,
6223
+ tokens,
6224
+ filePaths,
6225
+ skipCredentials: result.skipped,
6226
+ ...importOptions
6227
+ };
6228
+ const state = await inspectTokens({
6229
+ rawTokensPath: tokens,
6230
+ outDir: join8(resolveUserPath(projectPath2), ".contentful"),
6231
+ cache: importOptions.cache
6232
+ });
6233
+ if (state.kind === "cached") {
6234
+ setPendingLaunch({ launch, cached: { tokensPath: state.tokensPath, sourceChanged: state.sourceChanged } });
6235
+ return;
6236
+ }
6237
+ onLaunchImport?.({ ...launch, tokenStrategy: "generate" });
6238
+ };
6239
+ const chooseTokenStrategy = (pending, tokenStrategy) => {
6240
+ setPendingLaunch(void 0);
6241
+ onLaunchImport?.({ ...pending.launch, tokenStrategy });
6480
6242
  };
6481
6243
  const goToStart = () => setScreen("start");
6482
6244
  const goToSettings = () => setScreen("settings");
@@ -6484,6 +6246,7 @@ function App({ onLaunchImport, importExitCode }) {
6484
6246
  setProjectPath(void 0);
6485
6247
  setTokensPath(void 0);
6486
6248
  setScannedFiles(void 0);
6249
+ setPendingLaunch(void 0);
6487
6250
  };
6488
6251
  const finishImportResult = () => {
6489
6252
  setShowImportResult(false);
@@ -6496,13 +6259,13 @@ function App({ onLaunchImport, importExitCode }) {
6496
6259
  };
6497
6260
  switch (screen) {
6498
6261
  case "import":
6499
- if (showImportResult) return /* @__PURE__ */ jsx14(ImportScreen, { exitCode: importExitCode, onDone: finishImportResult });
6500
- if (importDefaults === void 0) return /* @__PURE__ */ jsx14(Fragment5, {});
6262
+ if (showImportResult) return /* @__PURE__ */ jsx18(ImportScreen, { exitCode: importExitCode, onDone: finishImportResult });
6263
+ if (importDefaults === void 0) return /* @__PURE__ */ jsx18(Fragment5, {});
6501
6264
  if (projectPath === void 0) {
6502
- return /* @__PURE__ */ jsx14(WelcomeScreen, { onContinue: setProjectPath, onQuit: leaveImport, initialPath: importDefaults.componentDir });
6265
+ return /* @__PURE__ */ jsx18(WelcomeScreen, { onContinue: setProjectPath, onQuit: leaveImport, initialPath: importDefaults.componentDir });
6503
6266
  }
6504
6267
  if (tokensPath === void 0) {
6505
- return /* @__PURE__ */ jsx14(
6268
+ return /* @__PURE__ */ jsx18(
6506
6269
  TokenInputScreen,
6507
6270
  {
6508
6271
  initialPath: importDefaults.tokenFile,
@@ -6512,7 +6275,7 @@ function App({ onLaunchImport, importExitCode }) {
6512
6275
  );
6513
6276
  }
6514
6277
  if (scannedFiles === void 0) {
6515
- return /* @__PURE__ */ jsx14(
6278
+ return /* @__PURE__ */ jsx18(
6516
6279
  PathValidationScreen,
6517
6280
  {
6518
6281
  projectPath,
@@ -6522,7 +6285,19 @@ function App({ onLaunchImport, importExitCode }) {
6522
6285
  }
6523
6286
  );
6524
6287
  }
6525
- return /* @__PURE__ */ jsx14(
6288
+ if (pendingLaunch?.cached) {
6289
+ return /* @__PURE__ */ jsx18(
6290
+ TokenReuseScreen,
6291
+ {
6292
+ tokensPath: pendingLaunch.cached.tokensPath,
6293
+ sourceChanged: pendingLaunch.cached.sourceChanged,
6294
+ onReuse: () => chooseTokenStrategy(pendingLaunch, "reuse"),
6295
+ onRegenerate: () => chooseTokenStrategy(pendingLaunch, "regenerate"),
6296
+ onQuit: leaveImport
6297
+ }
6298
+ );
6299
+ }
6300
+ return /* @__PURE__ */ jsx18(
6526
6301
  CredentialsScreen,
6527
6302
  {
6528
6303
  initial: importDefaults.credentials,
@@ -6531,27 +6306,28 @@ function App({ onLaunchImport, importExitCode }) {
6531
6306
  }
6532
6307
  );
6533
6308
  case "help":
6534
- return /* @__PURE__ */ jsx14(HelpScreen, { onDone: goToStart });
6309
+ return /* @__PURE__ */ jsx18(HelpScreen, { onDone: goToStart });
6535
6310
  case "upgrade":
6536
- return /* @__PURE__ */ jsx14(UpgradeScreen, { onDone: goToStart });
6311
+ return /* @__PURE__ */ jsx18(UpgradeScreen, { onDone: goToStart });
6537
6312
  case "settings":
6538
- return /* @__PURE__ */ jsx14(SettingsScreen, { onNavigate: setScreen, onBack: goToStart });
6313
+ return /* @__PURE__ */ jsx18(SettingsScreen, { onNavigate: setScreen, onBack: goToStart });
6539
6314
  case "settings-configuration":
6540
- return /* @__PURE__ */ jsx14(ConfigurationScreen, { onDone: goToSettings });
6315
+ return /* @__PURE__ */ jsx18(ConfigurationScreen, { onDone: goToSettings });
6541
6316
  case "settings-opt-in-analytics":
6542
- return /* @__PURE__ */ jsx14(OptInAnalyticsScreen, { onDone: goToSettings });
6317
+ return /* @__PURE__ */ jsx18(OptInAnalyticsScreen, { onDone: goToSettings });
6543
6318
  case "settings-debug-mode":
6544
- return /* @__PURE__ */ jsx14(DebugModeScreen, { onDone: goToSettings });
6319
+ return /* @__PURE__ */ jsx18(DebugModeScreen, { onDone: goToSettings });
6545
6320
  case "start":
6546
- return /* @__PURE__ */ jsx14(HomeScreen, { onNavigate: setScreen });
6321
+ return /* @__PURE__ */ jsx18(HomeScreen, { onNavigate: setScreen });
6547
6322
  }
6548
6323
  }
6549
- async function renderUntilImportRequestedOrExit(renderApp, importExitCode) {
6324
+ async function renderUntilImportRequestedOrExit(renderApp, importOptions, importExitCode) {
6550
6325
  let requestedImport;
6551
6326
  const instance = renderApp(
6552
- /* @__PURE__ */ jsx14(
6327
+ /* @__PURE__ */ jsx18(
6553
6328
  App,
6554
6329
  {
6330
+ importOptions,
6555
6331
  importExitCode,
6556
6332
  onLaunchImport: (options) => {
6557
6333
  requestedImport = options;
@@ -6567,13 +6343,13 @@ async function renderUntilImportRequestedOrExit(renderApp, importExitCode) {
6567
6343
  }
6568
6344
  return requestedImport;
6569
6345
  }
6570
- async function runApp(renderApp) {
6346
+ async function runApp(renderApp, importOptions) {
6571
6347
  let importExitCode;
6572
- let requestedImport = await renderUntilImportRequestedOrExit(renderApp, importExitCode);
6348
+ let requestedImport = await renderUntilImportRequestedOrExit(renderApp, importOptions, importExitCode);
6573
6349
  while (requestedImport !== void 0) {
6574
6350
  importExitCode = (await spawnV1Import(requestedImport)).exitCode;
6575
6351
  startReadingTerminal();
6576
- requestedImport = await renderUntilImportRequestedOrExit(renderApp, importExitCode);
6352
+ requestedImport = await renderUntilImportRequestedOrExit(renderApp, importOptions, importExitCode);
6577
6353
  }
6578
6354
  }
6579
6355
  var CLEAR_SCREEN;
@@ -6583,14 +6359,16 @@ var init_app = __esm({
6583
6359
  init_home();
6584
6360
  init_PageContainer();
6585
6361
  init_steps();
6362
+ init_logic8();
6363
+ init_resolve_user_path();
6586
6364
  init_spawn_v1_import();
6587
6365
  init_terminal_input();
6588
6366
  init_PageContainer2();
6589
6367
  init_PageContainer3();
6590
6368
  init_ContentfulConfigScreen();
6591
- init_screen5();
6592
- init_PageContainer4();
6593
6369
  init_screen6();
6370
+ init_PageContainer4();
6371
+ init_screen7();
6594
6372
  init_config_store();
6595
6373
  CLEAR_SCREEN = "\x1B[2J\x1B[H";
6596
6374
  }
@@ -6598,7 +6376,7 @@ var init_app = __esm({
6598
6376
 
6599
6377
  // packages/experience-design-system-cli/program.ts
6600
6378
  import { readFileSync as readFileSync4 } from "node:fs";
6601
- import { join as join7 } from "node:path";
6379
+ import { join as join9 } from "node:path";
6602
6380
  import { Command } from "commander";
6603
6381
 
6604
6382
  // packages/experience-design-system-cli/src/legacy/run-legacy.ts
@@ -6657,6 +6435,9 @@ function forwardedImportArgs(argv) {
6657
6435
  return argv[0] === "import" ? argv.slice(1) : argv;
6658
6436
  }
6659
6437
 
6438
+ // packages/experience-design-system-cli/src/commands/import.ts
6439
+ init_import_options();
6440
+
6660
6441
  // packages/experience-design-system-cli/src/commands/watch.ts
6661
6442
  init_package_root();
6662
6443
  import { spawn as spawn2 } from "node:child_process";
@@ -6687,12 +6468,17 @@ function runDevWatch(args) {
6687
6468
 
6688
6469
  // packages/experience-design-system-cli/src/commands/import.ts
6689
6470
  function registerImportCommand(program, openTui) {
6690
- program.command("import", { isDefault: true }).description("Launch the Experiences CLI").allowUnknownOption().allowExcessArguments().helpOption(false).argument("[args...]").action(async () => {
6471
+ program.command("import", { isDefault: true }).description("Launch the Experiences CLI").allowUnknownOption().allowExcessArguments().helpOption(false).argument("[args...]").option("--agent <name>", "Agent (or agent:model) the import runs its steps with").option(
6472
+ "--prompt <stage=value>",
6473
+ "Override a stage prompt (repeatable): a file path or literal text, e.g. --prompt select=./p.md",
6474
+ (value, previous) => [...previous, value],
6475
+ []
6476
+ ).option("--no-cache", "Re-run every step even if its output already exists").action(async (_args, raw) => {
6691
6477
  const { watch, rest: forwarded } = extractWatchFlag(forwardedImportArgs(process.argv.slice(2)));
6692
6478
  if (watch) {
6693
6479
  process.exit(await runDevWatch(forwarded));
6694
6480
  }
6695
- await openTui();
6481
+ await openTui(toImportOptions(raw));
6696
6482
  });
6697
6483
  }
6698
6484
 
@@ -6700,16 +6486,16 @@ function registerImportCommand(program, openTui) {
6700
6486
  init_package_root();
6701
6487
  var pkg = JSON.parse(
6702
6488
  readFileSync4(
6703
- join7(findPackageRoot(import.meta.url, "@contentful/experience-design-system-cli"), "package.json"),
6489
+ join9(findPackageRoot(import.meta.url, "@contentful/experience-design-system-cli"), "package.json"),
6704
6490
  "utf8"
6705
6491
  )
6706
6492
  );
6707
6493
  function createProgram() {
6708
6494
  const program = new Command().name("experiences").description("Contentful Experiences design system import CLI").version(pkg.version, "--version", "Print version number");
6709
- registerImportCommand(program, async () => {
6495
+ registerImportCommand(program, async (options) => {
6710
6496
  const { render } = await import("ink");
6711
6497
  const { runApp: runApp2 } = await Promise.resolve().then(() => (init_app(), app_exports));
6712
- await runApp2(render);
6498
+ await runApp2(render, options);
6713
6499
  });
6714
6500
  registerForwardedCommands(program);
6715
6501
  return program;
@@ -6720,7 +6506,7 @@ init_config();
6720
6506
  init_package_root();
6721
6507
  import { existsSync as existsSync5 } from "node:fs";
6722
6508
  import { mkdir as mkdir3, readFile as readFile2, rename as rename2, rmdir, unlink } from "node:fs/promises";
6723
- import { dirname as dirname3, join as join8 } from "node:path";
6509
+ import { dirname as dirname3, join as join10 } from "node:path";
6724
6510
  var PACKAGE_NAME4 = "@contentful/experience-design-system-cli";
6725
6511
  async function readJson(path5) {
6726
6512
  try {
@@ -6731,9 +6517,9 @@ async function readJson(path5) {
6731
6517
  }
6732
6518
  async function migrateOldConfig() {
6733
6519
  try {
6734
- const oldCredentials = join8(oldConfigDir2(), "credentials.json");
6735
- const oldRuns = join8(oldConfigDir2(), "runs.json");
6736
- const oldDebugMode = join8(
6520
+ const oldCredentials = join10(oldConfigDir2(), "credentials.json");
6521
+ const oldRuns = join10(oldConfigDir2(), "runs.json");
6522
+ const oldDebugMode = join10(
6737
6523
  findPackageRoot(import.meta.url, PACKAGE_NAME4),
6738
6524
  ".contentful",
6739
6525
  "config",