@contentful/experience-design-system-cli 2.37.1-dev-build-3c845a01.0 → 2.37.1-dev-build-c3291210.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/app.js CHANGED
@@ -8,71 +8,6 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
 
11
- // packages/experience-design-system-cli/src/tui/package-root.ts
12
- import { existsSync, readFileSync } from "node:fs";
13
- import { dirname, join } from "node:path";
14
- import { fileURLToPath } from "node:url";
15
- function findPackageRoot(startUrl, packageName) {
16
- let dir = dirname(fileURLToPath(startUrl));
17
- let found;
18
- while (true) {
19
- const manifestPath = join(dir, "package.json");
20
- if (existsSync(manifestPath)) {
21
- const pkg = JSON.parse(readFileSync(manifestPath, "utf8"));
22
- if (pkg.name === packageName) found = dir;
23
- }
24
- const parent = dirname(dir);
25
- if (parent === dir) return found ?? dir;
26
- dir = parent;
27
- }
28
- }
29
- var init_package_root = __esm({
30
- "packages/experience-design-system-cli/src/tui/package-root.ts"() {
31
- "use strict";
32
- }
33
- });
34
-
35
- // packages/experience-design-system-cli/src/tui/upgrade/version.ts
36
- import { readFileSync as readFileSync2 } from "node:fs";
37
- import { join as join2 } from "node:path";
38
- import semver from "semver";
39
- function readPackageVersion() {
40
- const root = findPackageRoot(import.meta.url, PACKAGE_NAME);
41
- const pkg = JSON.parse(readFileSync2(join2(root, "package.json"), "utf8"));
42
- return pkg.version ?? "unknown";
43
- }
44
- function parseVersionTag(tag) {
45
- const match2 = /^v(\d+\.\d+\.\d+)$/.exec(tag);
46
- return match2 ? match2[1] : void 0;
47
- }
48
- async function checkForUpgrade() {
49
- const current = readPackageVersion();
50
- try {
51
- const response = await fetch(TAGS_URL);
52
- if (!response.ok) return { status: "error" };
53
- const tags = await response.json();
54
- const versions = tags.map((tag) => tag.name ? parseVersionTag(tag.name) : void 0).filter((v) => v !== void 0);
55
- if (versions.length === 0) return { status: "error" };
56
- const latest = versions.reduce((best, v) => semver.gt(v, best) ? v : best);
57
- if (!semver.valid(current)) return { status: "error" };
58
- if (semver.gt(latest, current)) {
59
- return { status: "update-available", current, latest };
60
- }
61
- return { status: "up-to-date", current };
62
- } catch {
63
- return { status: "error" };
64
- }
65
- }
66
- var PACKAGE_NAME, TAGS_URL;
67
- var init_version = __esm({
68
- "packages/experience-design-system-cli/src/tui/upgrade/version.ts"() {
69
- "use strict";
70
- init_package_root();
71
- PACKAGE_NAME = "@contentful/experience-design-system-cli";
72
- TAGS_URL = "https://api.github.com/repos/contentful/experience-design-system-sdk-public/tags?per_page=10";
73
- }
74
- });
75
-
76
11
  // packages/experience-design-system-backend-pipeline/dist/src/agents/types/agent-name.js
77
12
  var AGENT_NAMES;
78
13
  var init_agent_name = __esm({
@@ -837,7 +772,7 @@ async function runAgent(options) {
837
772
  promptLen: prompt.length,
838
773
  promptHead: prompt.slice(0, 500)
839
774
  });
840
- return new Promise((resolve26) => {
775
+ return new Promise((resolve25) => {
841
776
  const bedrockEnv = bedrock ? BEDROCK_ENV_BY_AGENT[agent] : void 0;
842
777
  const child = spawn(binary, args, {
843
778
  stdio: ["pipe", "pipe", "pipe"],
@@ -886,7 +821,7 @@ async function runAgent(options) {
886
821
  stderrLen: stderr.length,
887
822
  stderrTail: stderr.slice(-1e3)
888
823
  });
889
- resolve26(result);
824
+ resolve25(result);
890
825
  });
891
826
  });
892
827
  }
@@ -908,7 +843,7 @@ async function checkAgentAuth(agent) {
908
843
  return "not-found";
909
844
  if (agent !== "claude")
910
845
  return "ok";
911
- return new Promise((resolve26) => {
846
+ return new Promise((resolve25) => {
912
847
  const child = spawn2(binary, ["auth", "status", "--json"], { stdio: ["ignore", "pipe", "pipe"] });
913
848
  let stdout = "";
914
849
  let done = false;
@@ -917,7 +852,7 @@ async function checkAgentAuth(agent) {
917
852
  return;
918
853
  done = true;
919
854
  child.kill("SIGTERM");
920
- resolve26("unauthenticated");
855
+ resolve25("unauthenticated");
921
856
  }, 5e3);
922
857
  child.stdout?.on("data", (chunk) => {
923
858
  stdout += chunk.toString();
@@ -928,14 +863,14 @@ async function checkAgentAuth(agent) {
928
863
  done = true;
929
864
  clearTimeout(timer);
930
865
  if (code !== 0) {
931
- resolve26("unauthenticated");
866
+ resolve25("unauthenticated");
932
867
  return;
933
868
  }
934
869
  try {
935
870
  const status = JSON.parse(stdout);
936
- resolve26(status.loggedIn ? "ok" : "unauthenticated");
871
+ resolve25(status.loggedIn ? "ok" : "unauthenticated");
937
872
  } catch {
938
- resolve26("unauthenticated");
873
+ resolve25("unauthenticated");
939
874
  }
940
875
  });
941
876
  });
@@ -945,9 +880,9 @@ async function binaryIsOnPath(binary) {
945
880
  const fs = await import("node:fs/promises");
946
881
  return fs.access(binary).then(() => true, () => false);
947
882
  }
948
- return new Promise((resolve26) => {
883
+ return new Promise((resolve25) => {
949
884
  const child = spawn2(process.platform === "win32" ? "where" : "which", [binary], { stdio: "ignore" });
950
- child.on("close", (code) => resolve26(code === 0));
885
+ child.on("close", (code) => resolve25(code === 0));
951
886
  });
952
887
  }
953
888
  var init_check_agent_auth = __esm({
@@ -2081,240 +2016,9 @@ var init_cache_keys = __esm({
2081
2016
  }
2082
2017
  });
2083
2018
 
2084
- // packages/experience-design-system-types/dist/src/config/index.js
2085
- import { randomBytes as randomBytes3 } from "node:crypto";
2086
- import { mkdir as mkdir6, readFile as readFile18, rename as rename2, writeFile as writeFile6 } from "node:fs/promises";
2087
- import { homedir as homedir3 } from "node:os";
2088
- import { dirname as dirname13, join as join17 } from "node:path";
2089
- function configRoot2() {
2090
- return process.env["EDS_HOME"] || join17(homedir3(), ".contentful", "experience-design-system-cli");
2091
- }
2092
- async function readSettings2() {
2093
- try {
2094
- return JSON.parse(await readFile18(configFilePath2(), "utf8"));
2095
- } catch {
2096
- return {};
2097
- }
2098
- }
2099
- async function writeSettings2(settings) {
2100
- const path5 = configFilePath2();
2101
- await mkdir6(dirname13(path5), { recursive: true });
2102
- const tmp = `${path5}.${process.pid}.${randomBytes3(4).toString("hex")}.tmp`;
2103
- await writeFile6(tmp, `${JSON.stringify(settings, null, 2)}
2104
- `, { mode: 384 });
2105
- await rename2(tmp, path5);
2106
- }
2107
- async function updateSettings2(patch) {
2108
- await writeSettings2({ ...await readSettings2(), ...patch });
2109
- }
2110
- var configFilePath2;
2111
- var init_config = __esm({
2112
- "packages/experience-design-system-types/dist/src/config/index.js"() {
2113
- "use strict";
2114
- configFilePath2 = () => join17(configRoot2(), "config.json");
2115
- }
2116
- });
2117
-
2118
- // packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts
2119
- async function readDebugModeSetting() {
2120
- const { debugMode } = await readSettings2();
2121
- return { ...DEFAULT_DEBUG_MODE_SETTING, ...debugMode };
2122
- }
2123
- async function writeDebugModeSetting(setting) {
2124
- await updateSettings2({ debugMode: setting });
2125
- }
2126
- var DEFAULT_DEBUG_MODE_SETTING;
2127
- var init_debug_mode_store = __esm({
2128
- "packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts"() {
2129
- "use strict";
2130
- init_config();
2131
- DEFAULT_DEBUG_MODE_SETTING = {
2132
- enabled: true
2133
- };
2134
- }
2135
- });
2136
-
2137
- // packages/experience-design-system-cli/src/tui/debug-store.ts
2138
- var debug_store_exports = {};
2139
- __export(debug_store_exports, {
2140
- currentDebugSessionDir: () => currentDebugSessionDir,
2141
- currentSessionDir: () => currentSessionDir,
2142
- finishDebugRun: () => finishDebugRun,
2143
- startDebugRun: () => startDebugRun,
2144
- startDebugSessionIn: () => startDebugSessionIn
2145
- });
2146
- import { mkdir as mkdir8, writeFile as writeFile7 } from "node:fs/promises";
2147
- import { existsSync as existsSync9, readdirSync as readdirSync3 } from "node:fs";
2148
- import { join as join20, resolve as resolve23 } from "node:path";
2149
- function generateRunId() {
2150
- const now = /* @__PURE__ */ new Date();
2151
- const pad = (n) => String(n).padStart(2, "0");
2152
- return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
2153
- }
2154
- function datePrefix(now = /* @__PURE__ */ new Date()) {
2155
- const pad = (n) => String(n).padStart(2, "0");
2156
- return `${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}`;
2157
- }
2158
- function slugify(value) {
2159
- return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
2160
- }
2161
- async function readBaseDir() {
2162
- try {
2163
- const dir = (await readSettings2())["contentfulBaseDir"];
2164
- return typeof dir === "string" && dir !== "" ? resolve23(dir) : void 0;
2165
- } catch {
2166
- return void 0;
2167
- }
2168
- }
2169
- function nextSessionId(contentfulDir) {
2170
- const today = datePrefix();
2171
- const existing = existsSync9(contentfulDir) ? readdirSync3(contentfulDir) : [];
2172
- const seqPattern = new RegExp(`^${today}-session-(\\d+)$`);
2173
- const maxSeq = existing.reduce((max, entry) => {
2174
- const match2 = seqPattern.exec(entry);
2175
- return match2 ? Math.max(max, Number(match2[1])) : max;
2176
- }, 0);
2177
- return `${today}-session-${maxSeq + 1}`;
2178
- }
2179
- function startSession(base, { replace }) {
2180
- const contentfulDir = join20(base, ".contentful");
2181
- if (replace || !sessionDir) sessionDir = join20(contentfulDir, nextSessionId(contentfulDir));
2182
- return sessionDir;
2183
- }
2184
- function currentDebugSessionDir() {
2185
- return sessionDir && join20(sessionDir, "debug");
2186
- }
2187
- function currentSessionDir() {
2188
- return sessionDir;
2189
- }
2190
- async function startDebugSessionIn(base, { replace = false } = {}) {
2191
- try {
2192
- if (!await isDebugModeEnabled()) return;
2193
- await mkdir8(join20(startSession(resolve23(base), { replace }), "debug"), { recursive: true });
2194
- } catch {
2195
- }
2196
- }
2197
- async function isDebugModeEnabled() {
2198
- try {
2199
- return (await readDebugModeSetting()).enabled;
2200
- } catch {
2201
- return true;
2202
- }
2203
- }
2204
- function redact(value) {
2205
- const clone = { ...value };
2206
- if ("cma_token" in clone) {
2207
- const raw = clone.cma_token;
2208
- clone.cma_token = typeof raw === "string" && raw.length > 0 ? `[present, ${raw.length} chars]` : "[not set]";
2209
- }
2210
- return clone;
2211
- }
2212
- function startDebugRun({
2213
- flow,
2214
- step,
2215
- menuOption,
2216
- inputs
2217
- }) {
2218
- const runId = generateRunId();
2219
- const startedAt = Date.now();
2220
- const redactedInputs = redact(inputs);
2221
- isDebugModeEnabled().then((enabled) => {
2222
- if (!enabled) return;
2223
- pendingRun = { flow, step, runId, menuOption, inputs: redactedInputs, startedAt };
2224
- });
2225
- }
2226
- async function finishDebugRun({
2227
- outputs,
2228
- status,
2229
- exitMethod
2230
- }) {
2231
- const run = pendingRun;
2232
- if (!run) return;
2233
- pendingRun = void 0;
2234
- const durationMs = Date.now() - run.startedAt;
2235
- const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
2236
- const root = currentDebugSessionDir();
2237
- if (!root) return;
2238
- const flowSegments = run.flow.split("/");
2239
- const dir = join20(root, ...flowSegments);
2240
- await mkdir8(dir, { recursive: true });
2241
- const filename = nextAttemptFilename(dir, run.menuOption);
2242
- await writeFile7(join20(dir, filename), content, { mode: 384 });
2243
- }
2244
- function nextAttemptFilename(dir, menuOption) {
2245
- const today = datePrefix();
2246
- const optionSlug = slugify(menuOption);
2247
- const existing = existsSync9(dir) ? readdirSync3(dir) : [];
2248
- const attemptPattern = new RegExp(`^${today}-${optionSlug}-attempt-(\\d+)\\.md$`);
2249
- const maxAttempt = existing.reduce((max, entry) => {
2250
- const match2 = attemptPattern.exec(entry);
2251
- return match2 ? Math.max(max, Number(match2[1])) : max;
2252
- }, 0);
2253
- return `${today}-${optionSlug}-attempt-${maxAttempt + 1}.md`;
2254
- }
2255
- function renderMarkdown(run, finish) {
2256
- const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
2257
- const stepLabel2 = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
2258
- const flowSlug = run.flow.split("/").join("-");
2259
- return `# Debug Log
2260
-
2261
- - Run ID: ${run.runId}
2262
- - Flow: ${flowSlug}
2263
- - Step: ${stepLabel2}
2264
- - Menu option: ${run.menuOption}
2265
- - Date: ${(/* @__PURE__ */ new Date()).toISOString()}
2266
- - CLI version: ${readPackageVersion()}
2267
- - Platform: ${process.platform} / Node ${process.version}
2268
- - Duration on screen: ${finish.durationMs}ms
2269
- - Status: ${finish.status}
2270
- - Exit method: ${finish.exitMethod}
2271
-
2272
- ## Inputs
2273
- \`\`\`json
2274
- ${JSON.stringify(run.inputs, null, 2)}
2275
- \`\`\`
2276
-
2277
- ## Outputs
2278
- \`\`\`json
2279
- ${JSON.stringify(finish.outputs, null, 2)}
2280
- \`\`\`
2281
- `;
2282
- }
2283
- function handleCrash() {
2284
- return finishDebugRun({ outputs: {}, status: "error", exitMethod: "crashed" });
2285
- }
2286
- var pendingRun, sessionDir;
2287
- var init_debug_store = __esm({
2288
- "packages/experience-design-system-cli/src/tui/debug-store.ts"() {
2289
- "use strict";
2290
- init_config();
2291
- init_version();
2292
- init_debug_mode_store();
2293
- void Promise.all([isDebugModeEnabled(), readBaseDir()]).then(([enabled, base]) => {
2294
- if (!enabled || !base) return void 0;
2295
- return mkdir8(join20(startSession(base, { replace: false }), "debug"), { recursive: true });
2296
- });
2297
- process.once("uncaughtException", (err) => {
2298
- void handleCrash().finally(() => {
2299
- throw err;
2300
- });
2301
- });
2302
- process.once("unhandledRejection", (reason) => {
2303
- void handleCrash().finally(() => {
2304
- throw reason;
2305
- });
2306
- });
2307
- process.once("SIGINT", () => {
2308
- void handleCrash().finally(() => {
2309
- process.exit(130);
2310
- });
2311
- });
2312
- }
2313
- });
2314
-
2315
2019
  // packages/experience-design-system-cli/app.tsx
2316
2020
  import { join as join25 } from "node:path";
2317
- import { useEffect as useEffect27, useState as useState33 } from "react";
2021
+ import { useEffect as useEffect28, useState as useState33 } from "react";
2318
2022
 
2319
2023
  // packages/experience-design-system-cli/src/tui/home/home.tsx
2320
2024
  import { useEffect as useEffect2, useState as useState2 } from "react";
@@ -2349,10 +2053,62 @@ function brandBar(width, ramp = BRAND_RAMP) {
2349
2053
  color
2350
2054
  })).filter((segment) => segment.text.length > 0);
2351
2055
  }
2352
- var FOCUS_MARKER = "\u276F";
2353
-
2354
- // packages/experience-design-system-cli/src/tui/home/home.tsx
2355
- init_version();
2056
+ var FOCUS_MARKER = "\u276F";
2057
+
2058
+ // packages/experience-design-system-cli/src/tui/upgrade/version.ts
2059
+ import { readFileSync as readFileSync2 } from "node:fs";
2060
+ import { join as join2 } from "node:path";
2061
+ import semver from "semver";
2062
+
2063
+ // packages/experience-design-system-cli/src/tui/package-root.ts
2064
+ import { existsSync, readFileSync } from "node:fs";
2065
+ import { dirname, join } from "node:path";
2066
+ import { fileURLToPath } from "node:url";
2067
+ function findPackageRoot(startUrl, packageName) {
2068
+ let dir = dirname(fileURLToPath(startUrl));
2069
+ let found;
2070
+ while (true) {
2071
+ const manifestPath = join(dir, "package.json");
2072
+ if (existsSync(manifestPath)) {
2073
+ const pkg = JSON.parse(readFileSync(manifestPath, "utf8"));
2074
+ if (pkg.name === packageName) found = dir;
2075
+ }
2076
+ const parent = dirname(dir);
2077
+ if (parent === dir) return found ?? dir;
2078
+ dir = parent;
2079
+ }
2080
+ }
2081
+
2082
+ // packages/experience-design-system-cli/src/tui/upgrade/version.ts
2083
+ var PACKAGE_NAME = "@contentful/experience-design-system-cli";
2084
+ var TAGS_URL = "https://api.github.com/repos/contentful/experience-design-system-sdk-public/tags?per_page=10";
2085
+ function readPackageVersion() {
2086
+ const root = findPackageRoot(import.meta.url, PACKAGE_NAME);
2087
+ const pkg = JSON.parse(readFileSync2(join2(root, "package.json"), "utf8"));
2088
+ return pkg.version ?? "unknown";
2089
+ }
2090
+ function parseVersionTag(tag) {
2091
+ const match2 = /^v(\d+\.\d+\.\d+)$/.exec(tag);
2092
+ return match2 ? match2[1] : void 0;
2093
+ }
2094
+ async function checkForUpgrade() {
2095
+ const current = readPackageVersion();
2096
+ try {
2097
+ const response = await fetch(TAGS_URL);
2098
+ if (!response.ok) return { status: "error" };
2099
+ const tags = await response.json();
2100
+ const versions = tags.map((tag) => tag.name ? parseVersionTag(tag.name) : void 0).filter((v) => v !== void 0);
2101
+ if (versions.length === 0) return { status: "error" };
2102
+ const latest = versions.reduce((best, v) => semver.gt(v, best) ? v : best);
2103
+ if (!semver.valid(current)) return { status: "error" };
2104
+ if (semver.gt(latest, current)) {
2105
+ return { status: "update-available", current, latest };
2106
+ }
2107
+ return { status: "up-to-date", current };
2108
+ } catch {
2109
+ return { status: "error" };
2110
+ }
2111
+ }
2356
2112
 
2357
2113
  // packages/experience-design-system-cli/src/tui/use-terminal-width.ts
2358
2114
  import { useEffect, useState } from "react";
@@ -2484,9 +2240,14 @@ function HomeScreen({ onNavigate }) {
2484
2240
  }
2485
2241
 
2486
2242
  // packages/experience-design-system-cli/src/tui/import/PageContainer.tsx
2487
- import { Box as Box2, Text as Text3, useInput as useInput2 } from "ink";
2243
+ import { useEffect as useEffect3 } from "react";
2244
+ import { Box as Box2, Text as Text3, useInput as useInput2, useStdout as useStdout2 } from "ink";
2488
2245
  import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
2489
2246
  function ImportScreen({ exitCode, onDone }) {
2247
+ const { stdout } = useStdout2();
2248
+ useEffect3(() => {
2249
+ stdout.write("\x1B[H\x1B[0J");
2250
+ }, [stdout]);
2490
2251
  useInput2((input, key) => {
2491
2252
  if (key.return || key.escape || input === "q") {
2492
2253
  onDone();
@@ -2694,7 +2455,7 @@ function TokenInputScreen({ onConfirm, onBack, initialPath = "" }) {
2694
2455
  }
2695
2456
 
2696
2457
  // packages/experience-design-system-cli/src/tui/import/steps/03-path-validation/screen.tsx
2697
- import { useEffect as useEffect3, useMemo, useState as useState5 } from "react";
2458
+ import { useEffect as useEffect4, useMemo, useState as useState5 } from "react";
2698
2459
  import { Box as Box5, Text as Text6 } from "ink";
2699
2460
 
2700
2461
  // packages/experience-design-system-cli/src/tui/import/steps/03-path-validation/controls.ts
@@ -12551,11 +12312,11 @@ import { access as access2, mkdir, readFile as readFile7, writeFile } from "node
12551
12312
  // packages/experience-design-system-backend-pipeline/dist/src/persistence/src/review-session/repositories/review-session-paths.js
12552
12313
  import { resolve as resolve15 } from "node:path";
12553
12314
  async function getRefineSessionPaths(sessionId, artifactsRoot) {
12554
- const sessionDir2 = resolve15(artifactsRoot, sessionId);
12315
+ const sessionDir = resolve15(artifactsRoot, sessionId);
12555
12316
  return {
12556
- sessionDir: sessionDir2,
12557
- eventsPath: resolve15(sessionDir2, "events.jsonl"),
12558
- statePath: resolve15(sessionDir2, "current-review-state.json")
12317
+ sessionDir,
12318
+ eventsPath: resolve15(sessionDir, "events.jsonl"),
12319
+ statePath: resolve15(sessionDir, "current-review-state.json")
12559
12320
  };
12560
12321
  }
12561
12322
 
@@ -13754,7 +13515,7 @@ function errorMessage(error) {
13754
13515
  return error instanceof Error && error.message ? error.message : String(error);
13755
13516
  }
13756
13517
  function defaultSleep(delayMs) {
13757
- return new Promise((resolve26) => setTimeout(resolve26, delayMs));
13518
+ return new Promise((resolve25) => setTimeout(resolve25, delayMs));
13758
13519
  }
13759
13520
 
13760
13521
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/sanitize-preview.js
@@ -13995,7 +13756,7 @@ var ApiClient = class {
13995
13756
  const progress = maxAttempts > 1 ? attempt / (maxAttempts - 1) : 0;
13996
13757
  const baseDelay = intervalMs + (maxIntervalMs - intervalMs) * progress;
13997
13758
  const jitter = Math.random() * baseDelay * 0.15;
13998
- await new Promise((resolve26) => setTimeout(resolve26, baseDelay + jitter));
13759
+ await new Promise((resolve25) => setTimeout(resolve25, baseDelay + jitter));
13999
13760
  }
14000
13761
  }
14001
13762
  throw new Error(`Operation ${operationId} timed out after ${maxAttempts} attempts`);
@@ -16108,7 +15869,7 @@ async function retryDatabaseWrite(operation, attempts = 8) {
16108
15869
  const message = error instanceof Error ? error.message : String(error);
16109
15870
  if (!/database is locked|database is busy/i.test(message) || attempt >= attempts)
16110
15871
  throw error;
16111
- await new Promise((resolve26) => setTimeout(resolve26, Math.min(250 * attempt, 2e3)));
15872
+ await new Promise((resolve25) => setTimeout(resolve25, Math.min(250 * attempt, 2e3)));
16112
15873
  }
16113
15874
  }
16114
15875
  }
@@ -16855,7 +16616,7 @@ function PathValidationScreen({
16855
16616
  }) {
16856
16617
  const resolvedPath = useMemo(() => resolveUserPath(projectPath), [projectPath]);
16857
16618
  const [scan, setScan] = useState5();
16858
- useEffect3(() => {
16619
+ useEffect4(() => {
16859
16620
  setScan(scanFiles(resolvedPath));
16860
16621
  }, [resolvedPath]);
16861
16622
  const phase = phaseOf(scan);
@@ -16935,7 +16696,6 @@ function useCredentialsControls(handlers) {
16935
16696
  }
16936
16697
 
16937
16698
  // packages/experience-design-system-cli/src/tui/user-agent.ts
16938
- init_version();
16939
16699
  function cliUserAgent() {
16940
16700
  return buildUserAgent(readPackageVersion());
16941
16701
  }
@@ -17224,10 +16984,10 @@ var PROGRESS_THEME = extendTheme(defaultTheme, {
17224
16984
  });
17225
16985
 
17226
16986
  // packages/experience-design-system-cli/src/tui/import/shared/running-step/use-elapsed.ts
17227
- import { useEffect as useEffect4, useState as useState7 } from "react";
16987
+ import { useEffect as useEffect5, useState as useState7 } from "react";
17228
16988
  function useElapsed() {
17229
16989
  const [seconds, setSeconds] = useState7(0);
17230
- useEffect4(() => {
16990
+ useEffect5(() => {
17231
16991
  const timer = setInterval(() => setSeconds((current) => current + 1), 1e3);
17232
16992
  return () => clearInterval(timer);
17233
16993
  }, []);
@@ -17435,11 +17195,37 @@ function ExtractionScreen({
17435
17195
  );
17436
17196
  }
17437
17197
 
17438
- // packages/experience-design-system-cli/app.tsx
17439
- init_config();
17198
+ // packages/experience-design-system-types/dist/src/config/index.js
17199
+ import { randomBytes as randomBytes3 } from "node:crypto";
17200
+ import { mkdir as mkdir6, readFile as readFile18, rename as rename2, writeFile as writeFile6 } from "node:fs/promises";
17201
+ import { homedir as homedir3 } from "node:os";
17202
+ import { dirname as dirname13, join as join17 } from "node:path";
17203
+ function configRoot2() {
17204
+ return process.env["EDS_HOME"] || join17(homedir3(), ".contentful", "experience-design-system-cli");
17205
+ }
17206
+ var configFilePath2 = () => join17(configRoot2(), "config.json");
17207
+ var debugSessionsDir2 = () => join17(configRoot2(), "debug", "sessions");
17208
+ async function readSettings2() {
17209
+ try {
17210
+ return JSON.parse(await readFile18(configFilePath2(), "utf8"));
17211
+ } catch {
17212
+ return {};
17213
+ }
17214
+ }
17215
+ async function writeSettings2(settings) {
17216
+ const path5 = configFilePath2();
17217
+ await mkdir6(dirname13(path5), { recursive: true });
17218
+ const tmp = `${path5}.${process.pid}.${randomBytes3(4).toString("hex")}.tmp`;
17219
+ await writeFile6(tmp, `${JSON.stringify(settings, null, 2)}
17220
+ `, { mode: 384 });
17221
+ await rename2(tmp, path5);
17222
+ }
17223
+ async function updateSettings2(patch) {
17224
+ await writeSettings2({ ...await readSettings2(), ...patch });
17225
+ }
17440
17226
 
17441
17227
  // packages/experience-design-system-cli/src/tui/import/steps/06-extraction/use-extraction.ts
17442
- import { useEffect as useEffect5, useRef as useRef2, useState as useState8 } from "react";
17228
+ import { useEffect as useEffect6, useRef as useRef2, useState as useState8 } from "react";
17443
17229
 
17444
17230
  // packages/experience-design-system-cli/src/tui/import/steps/06-extraction/run.ts
17445
17231
  import { mkdir as mkdir7 } from "node:fs/promises";
@@ -17698,7 +17484,7 @@ async function resolveSelectionPrompt(overrides) {
17698
17484
  function useExtraction(input) {
17699
17485
  const [state, setState] = useState8();
17700
17486
  const current = useRef2();
17701
- useEffect5(() => {
17487
+ useEffect6(() => {
17702
17488
  current.current = input;
17703
17489
  if (!input) {
17704
17490
  setState(void 0);
@@ -17712,7 +17498,6 @@ function useExtraction(input) {
17712
17498
  reuseTokens: input.tokenStrategy === "reuse"
17713
17499
  })
17714
17500
  });
17715
- void Promise.resolve().then(() => (init_debug_store(), debug_store_exports)).then((store) => store.startDebugSessionIn(input.projectPath));
17716
17501
  void runExtraction(input, (progress) => {
17717
17502
  if (current.current === input) setState({ status: "running", progress });
17718
17503
  }).then((result) => {
@@ -17729,7 +17514,7 @@ function useExtraction(input) {
17729
17514
  import { Box as Box20, Text as Text22 } from "ink";
17730
17515
 
17731
17516
  // packages/experience-design-system-cli/src/tui/import/steps/07-scope-gate/panels/added-column.tsx
17732
- import React6 from "react";
17517
+ import React7 from "react";
17733
17518
  import { Box as Box11, Text as Text12 } from "ink";
17734
17519
  import figures from "figures";
17735
17520
 
@@ -17930,7 +17715,7 @@ function AddedColumn(props) {
17930
17715
  const aiFlagged = aiFlaggedByKey?.get(entry.name) === true;
17931
17716
  const showSeparator = firstNonCycleIdx > 0 && i === firstNonCycleIdx;
17932
17717
  const style = sideColumnLabelStyle({ isCycle: entry.isCycle, isSelected, focused });
17933
- return /* @__PURE__ */ jsxs11(React6.Fragment, { children: [
17718
+ return /* @__PURE__ */ jsxs11(React7.Fragment, { children: [
17934
17719
  showSeparator && /* @__PURE__ */ jsx14(Text12, { dimColor: true, children: "\u2500".repeat(Math.max(0, width - 2)) }),
17935
17720
  /* @__PURE__ */ jsxs11(Box11, { children: [
17936
17721
  isCursor ? /* @__PURE__ */ jsx14(Text12, { color: PALETTE2.info, bold: true, children: figures.pointer }) : /* @__PURE__ */ jsx14(Text12, { children: " " }),
@@ -18963,7 +18748,7 @@ function GroupedSidebar(props) {
18963
18748
  }
18964
18749
 
18965
18750
  // packages/experience-design-system-cli/src/tui/import/steps/07-scope-gate/sidebar/components/HelpOverlay.tsx
18966
- import React7 from "react";
18751
+ import React8 from "react";
18967
18752
  import { Box as Box18, Text as Text20 } from "ink";
18968
18753
 
18969
18754
  // packages/experience-design-system-cli/src/tui/import/steps/07-scope-gate/sidebar/hooks/useImmediateInput.ts
@@ -19040,8 +18825,8 @@ function useImmediateInput(handler, enabled = true) {
19040
18825
  }
19041
18826
 
19042
18827
  // packages/experience-design-system-cli/src/tui/import/steps/07-scope-gate/sidebar/hooks/use-terminal-size.ts
19043
- import { useStdout as useStdout2 } from "ink";
19044
- import { useEffect as useEffect6, useState as useState9 } from "react";
18828
+ import { useStdout as useStdout3 } from "ink";
18829
+ import { useEffect as useEffect7, useState as useState9 } from "react";
19045
18830
  function readTerminalSize(stdout) {
19046
18831
  return {
19047
18832
  columns: stdout?.columns ?? 80,
@@ -19049,9 +18834,9 @@ function readTerminalSize(stdout) {
19049
18834
  };
19050
18835
  }
19051
18836
  function useTerminalSize() {
19052
- const { stdout } = useStdout2();
18837
+ const { stdout } = useStdout3();
19053
18838
  const [size, setSize] = useState9(() => readTerminalSize(stdout));
19054
- useEffect6(() => {
18839
+ useEffect7(() => {
19055
18840
  const updateSize = () => setSize(readTerminalSize(stdout));
19056
18841
  stdout?.on("resize", updateSize);
19057
18842
  updateSize();
@@ -19085,7 +18870,7 @@ function HelpOverlay(props) {
19085
18870
  overflowY: "hidden",
19086
18871
  children: [
19087
18872
  /* @__PURE__ */ jsx22(Text20, { bold: true, children: "\u2500".repeat(titleRule) + " Help " + "\u2500".repeat(titleRule) }),
19088
- props.sections.map((section) => /* @__PURE__ */ jsxs19(React7.Fragment, { children: [
18873
+ props.sections.map((section) => /* @__PURE__ */ jsxs19(React8.Fragment, { children: [
19089
18874
  /* @__PURE__ */ jsx22(Text20, { children: " " }),
19090
18875
  /* @__PURE__ */ jsx22(Text20, { bold: true, children: section.title }),
19091
18876
  section.entries.map((entry) => /* @__PURE__ */ jsx22(Text20, { children: entry.keys ? " " + entry.keys.padEnd(16) + " " + entry.label : " " + entry.label }, entry.keys + entry.label))
@@ -19234,7 +19019,7 @@ function createSidebarViewsHelpSection(includeBreaking) {
19234
19019
  }
19235
19020
 
19236
19021
  // packages/experience-design-system-cli/src/tui/import/steps/07-scope-gate/use-scope-gate.ts
19237
- import { useEffect as useEffect7, useMemo as useMemo2, useRef as useRef4, useState as useState12 } from "react";
19022
+ import { useEffect as useEffect8, useMemo as useMemo2, useRef as useRef4, useState as useState12 } from "react";
19238
19023
 
19239
19024
  // packages/experience-design-system-cli/src/tui/import/steps/07-scope-gate/graph/search-neighborhood.ts
19240
19025
  function computeDirectNeighborhood(matches, graph) {
@@ -19918,7 +19703,7 @@ function useScopeGate({ components, onConfirm, onQuit }) {
19918
19703
  return seed;
19919
19704
  });
19920
19705
  const seededGroupsRef = useRef4(closures.size > 0 || cycleParticipants.size > 0);
19921
- useEffect7(() => {
19706
+ useEffect8(() => {
19922
19707
  if (seededGroupsRef.current) return;
19923
19708
  if (closures.size === 0 && cycleParticipants.size === 0) return;
19924
19709
  seededGroupsRef.current = true;
@@ -20008,7 +19793,7 @@ function useScopeGate({ components, onConfirm, onQuit }) {
20008
19793
  entryCount: 0
20009
19794
  });
20010
19795
  const panelLayout = useMemo2(() => computePanelLayout(visibleCount), [visibleCount]);
20011
- useEffect7(() => {
19796
+ useEffect8(() => {
20012
19797
  setNav((prev) => {
20013
19798
  const maxIdx = Math.max(0, visibleRows.length - 1);
20014
19799
  const nextCursor = Math.min(prev.cursor, maxIdx);
@@ -20476,7 +20261,7 @@ function ScopeGateView({ components, onConfirm, onQuit }) {
20476
20261
  }
20477
20262
 
20478
20263
  // packages/experience-design-system-cli/src/tui/import/steps/07-scope-gate/use-scope-gate-flow.ts
20479
- import { useEffect as useEffect8, useMemo as useMemo3, useRef as useRef5, useState as useState13 } from "react";
20264
+ import { useEffect as useEffect9, useMemo as useMemo3, useRef as useRef5, useState as useState13 } from "react";
20480
20265
 
20481
20266
  // packages/experience-design-system-cli/src/tui/import/steps/07-scope-gate/cache-check.ts
20482
20267
  async function checkGenerationCache(input) {
@@ -20525,7 +20310,7 @@ function useScopeGateFlow(input, deps = realDeps2) {
20525
20310
  const loaded = useMemo3(() => sessionId ? deps.load(sessionId) : void 0, [sessionId]);
20526
20311
  const cacheCheck = useRef5(void 0);
20527
20312
  const [confirmed, setConfirmed] = useState13();
20528
- useEffect8(() => {
20313
+ useEffect9(() => {
20529
20314
  if (!input || !loaded?.ok || cacheCheck.current) return;
20530
20315
  cacheCheck.current = deps.checkCache(input.cache);
20531
20316
  }, [input, loaded]);
@@ -20596,10 +20381,10 @@ function GenerationScreen({
20596
20381
  }
20597
20382
 
20598
20383
  // packages/experience-design-system-cli/src/tui/import/steps/08-generation/use-generation.ts
20599
- import { useEffect as useEffect9, useRef as useRef6, useState as useState14 } from "react";
20384
+ import { useEffect as useEffect10, useRef as useRef6, useState as useState14 } from "react";
20600
20385
 
20601
20386
  // packages/experience-design-system-cli/src/tui/import/steps/08-generation/run.ts
20602
- import { resolve as resolve24 } from "node:path";
20387
+ import { resolve as resolve23 } from "node:path";
20603
20388
 
20604
20389
  // packages/experience-design-system-cli/src/tui/import/steps/08-generation/map-tokens.ts
20605
20390
  async function prepareMapTokens(input, generatedSessionId) {
@@ -20734,7 +20519,7 @@ async function buildMapTokensOptions(input) {
20734
20519
  if (mapOverride?.kind === "text") prompt.skillContentOverride = mapOverride.value;
20735
20520
  if (mapOverride?.kind === "path") {
20736
20521
  await resolvePromptOverride(mapOverride);
20737
- prompt.skillPathOverride = resolve24(mapOverride.value);
20522
+ prompt.skillPathOverride = resolve23(mapOverride.value);
20738
20523
  }
20739
20524
  if (input.existingEntitiesPath) {
20740
20525
  const entities = await readExistingContentfulEntitiesFromSession({ path: input.existingEntitiesPath });
@@ -20762,7 +20547,7 @@ function applyProgressEvent2(event, previous, total) {
20762
20547
  function useGeneration(input) {
20763
20548
  const [state, setState] = useState14();
20764
20549
  const current = useRef6();
20765
- useEffect9(() => {
20550
+ useEffect10(() => {
20766
20551
  current.current = input;
20767
20552
  if (!input) {
20768
20553
  setState(void 0);
@@ -20782,7 +20567,7 @@ function useGeneration(input) {
20782
20567
  }
20783
20568
 
20784
20569
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/build-flow-start.ts
20785
- import { join as join21 } from "node:path";
20570
+ import { join as join20 } from "node:path";
20786
20571
  function buildFlowStart(input) {
20787
20572
  const { extraction, handoff, saved, generatePromptPath } = input;
20788
20573
  const credentials = extraction.credentials ?? {
@@ -20795,7 +20580,7 @@ function buildFlowStart(input) {
20795
20580
  handoff,
20796
20581
  agent: extraction.agent,
20797
20582
  projectPath: extraction.projectPath,
20798
- outDir: extraction.projectPath ? join21(extraction.projectPath, ".contentful") : "",
20583
+ outDir: extraction.projectPath ? join20(extraction.projectPath, ".contentful") : "",
20799
20584
  rawTokensPath: extraction.rawTokensPath,
20800
20585
  credentials: {
20801
20586
  spaceId: credentials.spaceId,
@@ -20808,7 +20593,7 @@ function buildFlowStart(input) {
20808
20593
  }
20809
20594
 
20810
20595
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/screen.tsx
20811
- import { useEffect as useEffect20, useRef as useRef12 } from "react";
20596
+ import { useEffect as useEffect21, useRef as useRef12 } from "react";
20812
20597
  import { Box as Box41 } from "ink";
20813
20598
 
20814
20599
  // packages/experience-design-system-types/dist/src/cdf/validate.js
@@ -21155,7 +20940,7 @@ function PreviewValidationErrorScreen({
21155
20940
  }
21156
20941
 
21157
20942
  // packages/experience-design-system-cli/src/tui/import/steps/09-review/generate-review-step.tsx
21158
- import { useCallback as useCallback5, useEffect as useEffect16, useMemo as useMemo4, useRef as useRef11, useState as useState22 } from "react";
20943
+ import { useCallback as useCallback5, useEffect as useEffect17, useMemo as useMemo4, useRef as useRef11, useState as useState22 } from "react";
21159
20944
  import figures7 from "figures";
21160
20945
 
21161
20946
  // packages/experience-design-system-cli/src/tui/import/steps/09-review/theme.ts
@@ -21427,7 +21212,7 @@ function enumerateCycleBreaks(cycle, components) {
21427
21212
  import { Box as Box27, Text as Text30 } from "ink";
21428
21213
 
21429
21214
  // packages/experience-design-system-cli/src/tui/import/steps/09-review/components/FieldEditor.tsx
21430
- import React8, { useEffect as useEffect10, useLayoutEffect as useLayoutEffect2, useState as useState15 } from "react";
21215
+ import React9, { useEffect as useEffect11, useLayoutEffect as useLayoutEffect2, useState as useState15 } from "react";
21431
21216
  import figures5 from "figures";
21432
21217
  import { Box as Box21, measureElement, Text as Text23 } from "ink";
21433
21218
 
@@ -22138,9 +21923,9 @@ function FieldEditor({
22138
21923
  const [editorState, setEditorState] = useState15(initialState);
22139
21924
  const [parseErr] = useState15(parseError);
22140
21925
  const [listScrollStart, setListScrollStart] = useState15(0);
22141
- const initialFocusScrollApplied = React8.useRef(false);
21926
+ const initialFocusScrollApplied = React9.useRef(false);
22142
21927
  const [rowHeights, setRowHeights] = useState15({});
22143
- const rowMeasureRefs = React8.useRef(/* @__PURE__ */ new Map());
21928
+ const rowMeasureRefs = React9.useRef(/* @__PURE__ */ new Map());
22144
21929
  const initialFocus = (() => {
22145
21930
  if (initialFocusTarget?.kind === "description") {
22146
21931
  return {
@@ -22227,23 +22012,23 @@ function FieldEditor({
22227
22012
  const [showHelp, setShowHelp] = useState15(false);
22228
22013
  const props = editorState.props;
22229
22014
  const slots = editorState.slots;
22230
- const contentPropIndexes = React8.useMemo(
22015
+ const contentPropIndexes = React9.useMemo(
22231
22016
  () => props.flatMap((prop, index) => prop.category === "content" ? [index] : []),
22232
22017
  [props]
22233
22018
  );
22234
- const designPropIndexes = React8.useMemo(
22019
+ const designPropIndexes = React9.useMemo(
22235
22020
  () => props.flatMap((prop, index) => prop.category === "design" ? [index] : []),
22236
22021
  [props]
22237
22022
  );
22238
- const hiddenPropIndexes = React8.useMemo(
22023
+ const hiddenPropIndexes = React9.useMemo(
22239
22024
  () => showHiddenProps ? props.flatMap((prop, index) => prop.category === "state" || prop.category === "unattached" ? [index] : []) : [],
22240
22025
  [props, showHiddenProps]
22241
22026
  );
22242
- const visiblePropIndexes = React8.useMemo(
22027
+ const visiblePropIndexes = React9.useMemo(
22243
22028
  () => [...contentPropIndexes, ...designPropIndexes, ...hiddenPropIndexes],
22244
22029
  [contentPropIndexes, designPropIndexes, hiddenPropIndexes]
22245
22030
  );
22246
- const propGroups = React8.useMemo(
22031
+ const propGroups = React9.useMemo(
22247
22032
  () => [
22248
22033
  {
22249
22034
  kind: "content",
@@ -22263,7 +22048,7 @@ function FieldEditor({
22263
22048
  ],
22264
22049
  [contentPropIndexes, designPropIndexes, hiddenPropIndexes]
22265
22050
  );
22266
- const selectableRows = React8.useMemo(
22051
+ const selectableRows = React9.useMemo(
22267
22052
  () => [
22268
22053
  ...contentPropIndexes.map((idx) => ({ kind: "prop", idx })),
22269
22054
  ...designPropIndexes.map((idx) => ({ kind: "prop", idx })),
@@ -22273,7 +22058,7 @@ function FieldEditor({
22273
22058
  [contentPropIndexes, designPropIndexes, hiddenPropIndexes, slots]
22274
22059
  );
22275
22060
  const visiblePropPosition = visiblePropIndexes.indexOf(propIdx);
22276
- const selectedSelectableIndex = React8.useMemo(
22061
+ const selectedSelectableIndex = React9.useMemo(
22277
22062
  () => selectableRows.findIndex(
22278
22063
  (row) => inSlots ? row.kind === "slot" && row.idx === slotIdx : row.kind === "prop" && row.idx === propIdx
22279
22064
  ),
@@ -22292,12 +22077,12 @@ function FieldEditor({
22292
22077
  }
22293
22078
  };
22294
22079
  const textEntryActive = focusLevel === "field" && editingField && activeField === "description" || focusLevel === "field" && editingField && activeField === "default" && (editorState.props[propIdx]?.type === "string" || editorState.props[propIdx]?.type === "token") || editingValue != null;
22295
- React8.useEffect(() => {
22080
+ React9.useEffect(() => {
22296
22081
  onTextEntryActiveChange?.(textEntryActive);
22297
22082
  }, [textEntryActive, onTextEntryActiveChange]);
22298
22083
  const currentProp = props[propIdx] ?? null;
22299
22084
  const currentSlot = slots[slotIdx] ?? null;
22300
- React8.useEffect(() => {
22085
+ React9.useEffect(() => {
22301
22086
  if (showHiddenProps || inSlots || inComponentDesc || visiblePropPosition >= 0) return;
22302
22087
  if (visiblePropIndexes.length > 0) {
22303
22088
  setPropIdx(visiblePropIndexes[0]);
@@ -22316,22 +22101,22 @@ function FieldEditor({
22316
22101
  setEditorState(next);
22317
22102
  onChange(serializeState(next, value));
22318
22103
  };
22319
- const canonicalize = React8.useCallback((json) => {
22104
+ const canonicalize = React9.useCallback((json) => {
22320
22105
  try {
22321
22106
  return JSON.stringify(JSON.parse(json));
22322
22107
  } catch {
22323
22108
  return `__unparseable__:${json}`;
22324
22109
  }
22325
22110
  }, []);
22326
- const initialStateRef = React8.useRef(initialState);
22111
+ const initialStateRef = React9.useRef(initialState);
22327
22112
  const baselineCanonical = canonicalize(serializeState(initialStateRef.current, value));
22328
22113
  const currentCanonical = canonicalize(serializeState(editorState, value));
22329
22114
  const isDirty = currentCanonical !== baselineCanonical;
22330
- React8.useEffect(() => {
22115
+ React9.useEffect(() => {
22331
22116
  onDirtyChange?.(isDirty);
22332
22117
  }, [isDirty, onDirtyChange]);
22333
- const lastDiscardTriggerRef = React8.useRef(discardTrigger);
22334
- React8.useEffect(() => {
22118
+ const lastDiscardTriggerRef = React9.useRef(discardTrigger);
22119
+ React9.useEffect(() => {
22335
22120
  if (discardTrigger === void 0) return;
22336
22121
  if (discardTrigger === lastDiscardTriggerRef.current) return;
22337
22122
  lastDiscardTriggerRef.current = discardTrigger;
@@ -22930,7 +22715,7 @@ function FieldEditor({
22930
22715
  }
22931
22716
  return Math.max(start + 1, end2);
22932
22717
  };
22933
- useEffect10(() => {
22718
+ useEffect11(() => {
22934
22719
  if (focusLevel === "field" || selectedRowIdx < 0) return;
22935
22720
  setListScrollStart((previous) => {
22936
22721
  if (initialFocusTarget && !initialFocusScrollApplied.current) {
@@ -23988,7 +23773,7 @@ function finalizeReviewSession(extractSessionId, components) {
23988
23773
  }
23989
23774
 
23990
23775
  // packages/experience-design-system-cli/src/tui/import/steps/09-review/use-review-session.ts
23991
- import { useCallback as useCallback2, useEffect as useEffect12, useRef as useRef8, useState as useState17 } from "react";
23776
+ import { useCallback as useCallback2, useEffect as useEffect13, useRef as useRef8, useState as useState17 } from "react";
23992
23777
 
23993
23778
  // packages/experience-design-system-cli/src/tui/import/steps/09-review/history.ts
23994
23779
  var DEFAULT_MAX_DEPTH = 50;
@@ -24044,7 +23829,7 @@ function createHistoryStack(seed, maxDepth = DEFAULT_MAX_DEPTH) {
24044
23829
  }
24045
23830
 
24046
23831
  // packages/experience-design-system-cli/src/tui/import/steps/09-review/use-finalize-preview.ts
24047
- import { useEffect as useEffect11, useRef as useRef7, useState as useState16 } from "react";
23832
+ import { useEffect as useEffect12, useRef as useRef7, useState as useState16 } from "react";
24048
23833
 
24049
23834
  // packages/experience-design-system-cli/src/tui/import/steps/09-review/run-live-preview.ts
24050
23835
  var TimeoutError = class extends Error {
@@ -24196,7 +23981,7 @@ function useFinalizePreview(opts) {
24196
23981
  const [scrollOffset, setScrollOffset] = useState16(0);
24197
23982
  const generationRef = useRef7(0);
24198
23983
  const acceptedKey = [...acceptedKeys].sort().join("\0");
24199
- useEffect11(() => {
23984
+ useEffect12(() => {
24200
23985
  if (!open) {
24201
23986
  setStatus("idle");
24202
23987
  setRemoved([]);
@@ -24259,7 +24044,7 @@ function useReviewSession({
24259
24044
  }));
24260
24045
  return { result, catalog };
24261
24046
  }, [loadSession, tokensPath]);
24262
- useEffect12(() => {
24047
+ useEffect13(() => {
24263
24048
  let disposed = false;
24264
24049
  void (async () => {
24265
24050
  try {
@@ -24312,7 +24097,7 @@ function useReviewSession({
24312
24097
  function useReviewMetadata({ components, selectedIdx, extractSessionId }) {
24313
24098
  const [reviewMetadata, setReviewMetadata] = useState17(null);
24314
24099
  const [componentRationale, setComponentRationale] = useState17(null);
24315
- useEffect12(() => {
24100
+ useEffect13(() => {
24316
24101
  const current = components[selectedIdx];
24317
24102
  if (!current) {
24318
24103
  setReviewMetadata(null);
@@ -24344,7 +24129,7 @@ function useReviewMetadata({ components, selectedIdx, extractSessionId }) {
24344
24129
  function useReviewHistory({ loading, components, createSnapshot, applySnapshot }) {
24345
24130
  const historyRef = useRef8(null);
24346
24131
  const historySeededRef = useRef8(false);
24347
- useEffect12(() => {
24132
+ useEffect13(() => {
24348
24133
  if (loading || historySeededRef.current) return;
24349
24134
  historySeededRef.current = true;
24350
24135
  historyRef.current = createHistoryStack(createSnapshot(components));
@@ -24395,7 +24180,7 @@ function useReviewFinalize({
24395
24180
  }
24396
24181
 
24397
24182
  // packages/experience-design-system-cli/src/tui/import/steps/09-review/use-review-editor.ts
24398
- import { useEffect as useEffect13, useRef as useRef9, useState as useState18 } from "react";
24183
+ import { useEffect as useEffect14, useRef as useRef9, useState as useState18 } from "react";
24399
24184
 
24400
24185
  // packages/experience-design-system-cli/src/tui/import/steps/09-review/token-suggestions.ts
24401
24186
  function collectTokenSuggestions(entry, availableTokens = []) {
@@ -24448,7 +24233,7 @@ function useReviewEditor({
24448
24233
  const [tokenReviewEditSelection, setTokenReviewEditSelection] = useState18(/* @__PURE__ */ new Set());
24449
24234
  const tokenReviewSuggestedRef = useRef9(/* @__PURE__ */ new Map());
24450
24235
  const pendingGRef = useRef9(false);
24451
- useEffect13(() => {
24236
+ useEffect14(() => {
24452
24237
  setTokenReviewRow(0);
24453
24238
  setTokenReviewEditing(false);
24454
24239
  setTokenReviewEditCursor(0);
@@ -24852,7 +24637,7 @@ function handleJsonPanelInput(input, key, state) {
24852
24637
  }
24853
24638
 
24854
24639
  // packages/experience-design-system-cli/src/tui/import/steps/09-review/use-review-preview.ts
24855
- import { useCallback as useCallback4, useEffect as useEffect15, useState as useState21 } from "react";
24640
+ import { useCallback as useCallback4, useEffect as useEffect16, useState as useState21 } from "react";
24856
24641
 
24857
24642
  // packages/experience-design-system-cli/src/tui/import/steps/09-review/preview-annotations.ts
24858
24643
  function applyPreviewAnnotations(preview, localNames) {
@@ -24887,7 +24672,7 @@ function applyPreviewAnnotations(preview, localNames) {
24887
24672
  }
24888
24673
 
24889
24674
  // packages/experience-design-system-cli/src/tui/import/steps/09-review/use-live-preview.ts
24890
- import { useCallback as useCallback3, useEffect as useEffect14, useRef as useRef10, useState as useState20 } from "react";
24675
+ import { useCallback as useCallback3, useEffect as useEffect15, useRef as useRef10, useState as useState20 } from "react";
24891
24676
  var DEFAULT_DEBOUNCE_MS = 500;
24892
24677
  function useLivePreview(opts) {
24893
24678
  const debounceMs = opts.debounceMs ?? DEFAULT_DEBOUNCE_MS;
@@ -24898,14 +24683,14 @@ function useLivePreview(opts) {
24898
24683
  const latestRef = useRef10(0);
24899
24684
  const inflightRef = useRef10(0);
24900
24685
  const optsRef = useRef10(opts);
24901
- useEffect14(() => {
24686
+ useEffect15(() => {
24902
24687
  optsRef.current = opts;
24903
24688
  });
24904
24689
  const disabledRef = useRef10(disabled);
24905
- useEffect14(() => {
24690
+ useEffect15(() => {
24906
24691
  disabledRef.current = disabled;
24907
24692
  }, [disabled]);
24908
- useEffect14(() => {
24693
+ useEffect15(() => {
24909
24694
  return () => {
24910
24695
  if (timerRef.current) {
24911
24696
  clearTimeout(timerRef.current);
@@ -25019,13 +24804,13 @@ function useReviewPreview({
25019
24804
  deleteAllComponents
25020
24805
  });
25021
24806
  const [spinnerTick, setSpinnerTick] = useState21(0);
25022
- useEffect15(() => {
24807
+ useEffect16(() => {
25023
24808
  if (livePreviewHook.status !== "running") return;
25024
24809
  const id = setInterval(() => setSpinnerTick((tick) => tick + 1), 80);
25025
24810
  return () => clearInterval(id);
25026
24811
  }, [livePreviewHook.status]);
25027
24812
  const livePreviewSpinner = SPINNER_FRAMES[spinnerTick % SPINNER_FRAMES.length];
25028
- useEffect15(() => {
24813
+ useEffect16(() => {
25029
24814
  if (loading) return;
25030
24815
  if (!livePreview) return;
25031
24816
  if (components.length === 0) return;
@@ -25445,7 +25230,7 @@ function GenerateReviewStepView({
25445
25230
  [components]
25446
25231
  );
25447
25232
  const closures = useMemo4(() => computeAllClosures(componentGraph), [componentGraph]);
25448
- useEffect16(() => {
25233
+ useEffect17(() => {
25449
25234
  if (seededGroupsRef.current) return;
25450
25235
  if (closures.size === 0 && slotCycles.length === 0) return;
25451
25236
  seededGroupsRef.current = true;
@@ -25472,7 +25257,7 @@ function GenerateReviewStepView({
25472
25257
  suggestedBreak: cycle.edges.length > 0 ? suggestCycleBreakEdge2(cycle, cycleView.pushBlocking) : null
25473
25258
  }));
25474
25259
  }, [slotCycles, cycleView]);
25475
- useEffect16(() => {
25260
+ useEffect17(() => {
25476
25261
  const decision = computeAutoRejectDecision({
25477
25262
  loading,
25478
25263
  autoRejectFired: autoRejectFiredRef.current,
@@ -25516,7 +25301,7 @@ function GenerateReviewStepView({
25516
25301
  applySnapshot: applyHistorySnapshot
25517
25302
  });
25518
25303
  const autoRejectPushedRef = useRef11(false);
25519
- useEffect16(() => {
25304
+ useEffect17(() => {
25520
25305
  if (loading) return;
25521
25306
  if (!historySeededRef.current) return;
25522
25307
  if (!autoRejectFiredRef.current) return;
@@ -25600,7 +25385,7 @@ function GenerateReviewStepView({
25600
25385
  const panelHeight = leftPanelHeight + 2;
25601
25386
  const panelContentHeight = Math.max(1, panelHeight - 3);
25602
25387
  const cycleViewportHeight = Math.max(1, panelHeight - 4);
25603
- useEffect16(() => {
25388
+ useEffect17(() => {
25604
25389
  if (selectableRowPositions.length === 0) return;
25605
25390
  const cursorInRange = selectableRowPositions.includes(cursorRowIdx);
25606
25391
  const maxScroll = Math.max(0, visibleRowsMemo.length - visibleCount);
@@ -26538,11 +26323,11 @@ function DoneStep({
26538
26323
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/screens/PathPrompt.tsx
26539
26324
  import { useState as useState24 } from "react";
26540
26325
  import { Box as Box37, Text as Text40 } from "ink";
26541
- import { readdirSync as readdirSync4 } from "node:fs";
26542
- import { dirname as dirname15, basename as basename6, join as join22 } from "node:path";
26326
+ import { readdirSync as readdirSync3 } from "node:fs";
26327
+ import { dirname as dirname15, basename as basename6, join as join21 } from "node:path";
26543
26328
 
26544
26329
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/support/path-utils.ts
26545
- import { resolve as resolve25 } from "node:path";
26330
+ import { resolve as resolve24 } from "node:path";
26546
26331
  import { homedir as homedir4 } from "node:os";
26547
26332
  function expandTilde(input) {
26548
26333
  if (input === "~" || input.startsWith("~/") || input.startsWith("~\\")) {
@@ -26556,14 +26341,14 @@ function normalizePath(input) {
26556
26341
  p = p.slice(1, -1);
26557
26342
  }
26558
26343
  p = expandTilde(p);
26559
- return resolve25(p);
26344
+ return resolve24(p);
26560
26345
  }
26561
26346
 
26562
26347
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/support/use-blinking-cursor.ts
26563
- import { useEffect as useEffect17, useState as useState23 } from "react";
26348
+ import { useEffect as useEffect18, useState as useState23 } from "react";
26564
26349
  function useBlinkingCursor() {
26565
26350
  const [visible, setVisible] = useState23(true);
26566
- useEffect17(() => {
26351
+ useEffect18(() => {
26567
26352
  const interval = setInterval(() => setVisible((current) => !current), 500);
26568
26353
  return () => clearInterval(interval);
26569
26354
  }, []);
@@ -26579,19 +26364,19 @@ function autocomplete(partial) {
26579
26364
  const base = basename6(normalized);
26580
26365
  let entries;
26581
26366
  try {
26582
- entries = readdirSync4(dir);
26367
+ entries = readdirSync3(dir);
26583
26368
  } catch {
26584
26369
  return null;
26585
26370
  }
26586
26371
  const matches = entries.filter((e) => e.startsWith(base));
26587
26372
  if (matches.length === 0) return null;
26588
- if (matches.length === 1) return join22(dir, matches[0]);
26373
+ if (matches.length === 1) return join21(dir, matches[0]);
26589
26374
  let prefix = matches[0];
26590
26375
  for (const m of matches) {
26591
26376
  while (!m.startsWith(prefix)) prefix = prefix.slice(0, -1);
26592
26377
  if (!prefix) break;
26593
26378
  }
26594
- return prefix.length > base.length ? join22(dir, prefix) : null;
26379
+ return prefix.length > base.length ? join21(dir, prefix) : null;
26595
26380
  }
26596
26381
  function PathPrompt({
26597
26382
  defaultPath,
@@ -26671,12 +26456,12 @@ function StepHeader({ stepNumber, totalSteps, title }) {
26671
26456
  }
26672
26457
 
26673
26458
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/support/use-timed-spinner.tsx
26674
- import { useEffect as useEffect18, useState as useState25 } from "react";
26459
+ import { useEffect as useEffect19, useState as useState25 } from "react";
26675
26460
  import { Spinner as Spinner2 } from "@inkjs/ui";
26676
26461
  import { jsx as jsx49 } from "react/jsx-runtime";
26677
26462
  function useTimedSpinner() {
26678
26463
  const [elapsedSeconds, setElapsedSeconds] = useState25(0);
26679
- useEffect18(() => {
26464
+ useEffect19(() => {
26680
26465
  const timer = setInterval(() => setElapsedSeconds((current) => current + 1), 1e3);
26681
26466
  return () => {
26682
26467
  clearInterval(timer);
@@ -26725,7 +26510,7 @@ function PushingStep({ stepNumber, totalSteps, progress }) {
26725
26510
  }
26726
26511
 
26727
26512
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/screens/WizardPreviewStep.tsx
26728
- import { useEffect as useEffect19, useState as useState26, useMemo as useMemo5 } from "react";
26513
+ import { useEffect as useEffect20, useState as useState26, useMemo as useMemo5 } from "react";
26729
26514
  import { Box as Box40, Text as Text43 } from "ink";
26730
26515
 
26731
26516
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/support/preview-diff.ts
@@ -27110,7 +26895,7 @@ function WizardPreviewStep({
27110
26895
  const activeLines = diffExpanded ? diffLines : summaryLines;
27111
26896
  const maxScroll = Math.max(0, activeLines.length - viewportHeight);
27112
26897
  const boundedScrollOffset = Math.min(scrollOffset, maxScroll);
27113
- useEffect19(() => {
26898
+ useEffect20(() => {
27114
26899
  setScrollOffset((previous) => Math.min(previous, maxScroll));
27115
26900
  }, [maxScroll]);
27116
26901
  useImmediateInput((input, key) => {
@@ -27215,7 +27000,7 @@ function FlowScreen({
27215
27000
  const totalSteps = totalStepsFor(state);
27216
27001
  const quit = () => onExit(0);
27217
27002
  const previousStep = useRef12(state.step);
27218
- useEffect20(() => {
27003
+ useEffect21(() => {
27219
27004
  if (previousStep.current !== state.step) {
27220
27005
  onStepChange?.();
27221
27006
  previousStep.current = state.step;
@@ -27346,13 +27131,13 @@ function FlowScreen({
27346
27131
  }
27347
27132
 
27348
27133
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/use-flow.ts
27349
- import { useEffect as useEffect21, useRef as useRef13, useSyncExternalStore } from "react";
27134
+ import { useEffect as useEffect22, useRef as useRef13, useSyncExternalStore } from "react";
27350
27135
 
27351
27136
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/controller.ts
27352
27137
  import { appendFileSync, writeFileSync } from "node:fs";
27353
- import { mkdir as mkdir9 } from "node:fs/promises";
27138
+ import { mkdir as mkdir8 } from "node:fs/promises";
27354
27139
  import { tmpdir } from "node:os";
27355
- import { join as join24 } from "node:path";
27140
+ import { join as join23 } from "node:path";
27356
27141
 
27357
27142
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/support/wizard-state-transitions.ts
27358
27143
  function shouldBypassPreview(state) {
@@ -27696,8 +27481,8 @@ function pushFailure(e, deps) {
27696
27481
  }
27697
27482
 
27698
27483
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/save.ts
27699
- import { writeFile as writeFile8 } from "node:fs/promises";
27700
- import { join as join23 } from "node:path";
27484
+ import { writeFile as writeFile7 } from "node:fs/promises";
27485
+ import { join as join22 } from "node:path";
27701
27486
 
27702
27487
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/support/run-print-files-helpers.ts
27703
27488
  function nextStateAfterPrint(opts) {
@@ -27720,15 +27505,15 @@ function buildSavedCDF(components, tokens, opts = {}) {
27720
27505
  var realSaveDeps = () => ({
27721
27506
  openDb: openPipelineDb,
27722
27507
  readTokens: (path5) => readTokensFromPath2({ flag: "tokens", path: path5 }),
27723
- writeFile: (path5, contents) => writeFile8(path5, contents),
27508
+ writeFile: (path5, contents) => writeFile7(path5, contents),
27724
27509
  appendRun,
27725
27510
  buildSourceFingerprint,
27726
- sleep: (ms) => new Promise((resolve26) => setTimeout(resolve26, ms)),
27511
+ sleep: (ms) => new Promise((resolve25) => setTimeout(resolve25, ms)),
27727
27512
  warn: (message) => process.stderr.write(message)
27728
27513
  });
27729
27514
  async function runPrintFiles(input, deps, onPatch) {
27730
27515
  onPatch({ step: "printing" });
27731
- const componentsPath = join23(input.outDir, "components.json");
27516
+ const componentsPath = join22(input.outDir, "components.json");
27732
27517
  try {
27733
27518
  const db = deps.openDb();
27734
27519
  let components = [];
@@ -27809,7 +27594,7 @@ var EMPTY_PUSH_RESULT = {
27809
27594
  };
27810
27595
 
27811
27596
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/controller.ts
27812
- var WIZARD_LOG = join24(tmpdir(), "experiences-import-wizard.log");
27597
+ var WIZARD_LOG = join23(tmpdir(), "experiences-import-wizard.log");
27813
27598
  function appendWizardLog(entry) {
27814
27599
  appendFileSync(WIZARD_LOG, JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), ...entry }) + "\n");
27815
27600
  }
@@ -27817,9 +27602,6 @@ function startWizardLog() {
27817
27602
  writeFileSync(WIZARD_LOG, `--- experiences import session ${(/* @__PURE__ */ new Date()).toISOString()} ---
27818
27603
  `);
27819
27604
  }
27820
- async function realSessionDir() {
27821
- return (await Promise.resolve().then(() => (init_debug_store(), debug_store_exports))).currentSessionDir();
27822
- }
27823
27605
  function realFlowDeps() {
27824
27606
  const log = (entry) => appendWizardLog(entry);
27825
27607
  return {
@@ -27835,14 +27617,13 @@ function realFlowDeps() {
27835
27617
  }
27836
27618
  },
27837
27619
  mkdir: async (path5) => {
27838
- await mkdir9(path5, { recursive: true });
27620
+ await mkdir8(path5, { recursive: true });
27839
27621
  },
27840
27622
  detectSaveConflict,
27841
27623
  buildTimestampedSubdir,
27842
27624
  rejectComponentsByName,
27843
27625
  log,
27844
- stderr: (text) => process.stderr.write(text),
27845
- sessionDir: realSessionDir
27626
+ stderr: (text) => process.stderr.write(text)
27846
27627
  };
27847
27628
  }
27848
27629
  function initialFlowState(start) {
@@ -27983,9 +27764,6 @@ function createFlowController(start, deps) {
27983
27764
  const startSave = (opts, patch = {}) => {
27984
27765
  pendingSave = opts;
27985
27766
  update({ ...patch, step: "path-prompt" });
27986
- void deps.sessionDir?.().then((session) => {
27987
- if (session && state.step === "path-prompt") update({ outDir: join24(session, "dsi-import") });
27988
- });
27989
27767
  };
27990
27768
  const proceedToWrite = async (path5) => {
27991
27769
  update({ outDir: path5 });
@@ -28094,28 +27872,180 @@ function useFlow(start, deps = realFlowDeps) {
28094
27872
  (listener) => current?.subscribe(listener) ?? (() => void 0),
28095
27873
  () => current?.getState()
28096
27874
  );
28097
- useEffect21(() => {
27875
+ useEffect22(() => {
28098
27876
  if (!start) controller.current = void 0;
28099
27877
  }, [start]);
28100
27878
  return current && state ? { controller: current, state } : void 0;
28101
27879
  }
28102
27880
 
28103
27881
  // packages/experience-design-system-cli/src/tui/help/PageContainer.tsx
28104
- import { useEffect as useEffect22, useState as useState27 } from "react";
27882
+ import { useEffect as useEffect23, useState as useState27 } from "react";
28105
27883
  import { Box as Box42, Text as Text44, useInput as useInput9 } from "ink";
28106
- init_debug_store();
27884
+
27885
+ // packages/experience-design-system-cli/src/tui/debug-store.ts
27886
+ import { mkdir as mkdir9, writeFile as writeFile8 } from "node:fs/promises";
27887
+ import { existsSync as existsSync9, readdirSync as readdirSync4 } from "node:fs";
27888
+ import { join as join24 } from "node:path";
27889
+
27890
+ // packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts
27891
+ var DEFAULT_DEBUG_MODE_SETTING = {
27892
+ enabled: true
27893
+ };
27894
+ async function readDebugModeSetting() {
27895
+ const { debugMode } = await readSettings2();
27896
+ return { ...DEFAULT_DEBUG_MODE_SETTING, ...debugMode };
27897
+ }
27898
+ async function writeDebugModeSetting(setting) {
27899
+ await updateSettings2({ debugMode: setting });
27900
+ }
27901
+
27902
+ // packages/experience-design-system-cli/src/tui/debug-store.ts
27903
+ var pendingRun;
27904
+ function generateRunId() {
27905
+ const now = /* @__PURE__ */ new Date();
27906
+ const pad = (n) => String(n).padStart(2, "0");
27907
+ return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
27908
+ }
27909
+ function datePrefix(now = /* @__PURE__ */ new Date()) {
27910
+ const pad = (n) => String(n).padStart(2, "0");
27911
+ return `${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}`;
27912
+ }
27913
+ function slugify(value) {
27914
+ return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
27915
+ }
27916
+ function generateSessionId3() {
27917
+ const today = datePrefix();
27918
+ const root = debugSessionsDir2();
27919
+ const existing = existsSync9(root) ? readdirSync4(root) : [];
27920
+ const seqPattern = new RegExp(`^${today}-session-(\\d+)$`);
27921
+ const maxSeq = existing.reduce((max, entry) => {
27922
+ const match2 = seqPattern.exec(entry);
27923
+ return match2 ? Math.max(max, Number(match2[1])) : max;
27924
+ }, 0);
27925
+ return `${today}-session-${maxSeq + 1}`;
27926
+ }
27927
+ var SESSION_ID = generateSessionId3();
27928
+ function sessionDebugDir() {
27929
+ return join24(debugSessionsDir2(), SESSION_ID);
27930
+ }
27931
+ function currentDebugSessionDir() {
27932
+ return sessionDebugDir();
27933
+ }
27934
+ void isDebugModeEnabled().then((enabled) => {
27935
+ if (!enabled) return void 0;
27936
+ return mkdir9(sessionDebugDir(), { recursive: true });
27937
+ });
27938
+ async function isDebugModeEnabled() {
27939
+ try {
27940
+ return (await readDebugModeSetting()).enabled;
27941
+ } catch {
27942
+ return true;
27943
+ }
27944
+ }
27945
+ function redact(value) {
27946
+ const clone = { ...value };
27947
+ if ("cma_token" in clone) {
27948
+ const raw = clone.cma_token;
27949
+ clone.cma_token = typeof raw === "string" && raw.length > 0 ? `[present, ${raw.length} chars]` : "[not set]";
27950
+ }
27951
+ return clone;
27952
+ }
27953
+ function startDebugRun({
27954
+ flow,
27955
+ step,
27956
+ menuOption,
27957
+ inputs
27958
+ }) {
27959
+ const runId = generateRunId();
27960
+ const startedAt = Date.now();
27961
+ const redactedInputs = redact(inputs);
27962
+ isDebugModeEnabled().then((enabled) => {
27963
+ if (!enabled) return;
27964
+ pendingRun = { flow, step, runId, menuOption, inputs: redactedInputs, startedAt };
27965
+ });
27966
+ }
27967
+ async function finishDebugRun({
27968
+ outputs,
27969
+ status,
27970
+ exitMethod
27971
+ }) {
27972
+ const run = pendingRun;
27973
+ if (!run) return;
27974
+ pendingRun = void 0;
27975
+ const durationMs = Date.now() - run.startedAt;
27976
+ const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
27977
+ const flowSegments = run.flow.split("/");
27978
+ const dir = join24(sessionDebugDir(), ...flowSegments);
27979
+ await mkdir9(dir, { recursive: true });
27980
+ const filename = nextAttemptFilename(dir, run.menuOption);
27981
+ await writeFile8(join24(dir, filename), content, { mode: 384 });
27982
+ }
27983
+ function nextAttemptFilename(dir, menuOption) {
27984
+ const today = datePrefix();
27985
+ const optionSlug = slugify(menuOption);
27986
+ const existing = existsSync9(dir) ? readdirSync4(dir) : [];
27987
+ const attemptPattern = new RegExp(`^${today}-${optionSlug}-attempt-(\\d+)\\.md$`);
27988
+ const maxAttempt = existing.reduce((max, entry) => {
27989
+ const match2 = attemptPattern.exec(entry);
27990
+ return match2 ? Math.max(max, Number(match2[1])) : max;
27991
+ }, 0);
27992
+ return `${today}-${optionSlug}-attempt-${maxAttempt + 1}.md`;
27993
+ }
27994
+ function renderMarkdown(run, finish) {
27995
+ const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
27996
+ const stepLabel2 = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
27997
+ const flowSlug = run.flow.split("/").join("-");
27998
+ return `# Debug Log
27999
+
28000
+ - Run ID: ${run.runId}
28001
+ - Flow: ${flowSlug}
28002
+ - Step: ${stepLabel2}
28003
+ - Menu option: ${run.menuOption}
28004
+ - Date: ${(/* @__PURE__ */ new Date()).toISOString()}
28005
+ - CLI version: ${readPackageVersion()}
28006
+ - Platform: ${process.platform} / Node ${process.version}
28007
+ - Duration on screen: ${finish.durationMs}ms
28008
+ - Status: ${finish.status}
28009
+ - Exit method: ${finish.exitMethod}
28010
+
28011
+ ## Inputs
28012
+ \`\`\`json
28013
+ ${JSON.stringify(run.inputs, null, 2)}
28014
+ \`\`\`
28015
+
28016
+ ## Outputs
28017
+ \`\`\`json
28018
+ ${JSON.stringify(finish.outputs, null, 2)}
28019
+ \`\`\`
28020
+ `;
28021
+ }
28022
+ function handleCrash() {
28023
+ return finishDebugRun({ outputs: {}, status: "error", exitMethod: "crashed" });
28024
+ }
28025
+ process.once("uncaughtException", (err) => {
28026
+ void handleCrash().finally(() => {
28027
+ throw err;
28028
+ });
28029
+ });
28030
+ process.once("unhandledRejection", (reason) => {
28031
+ void handleCrash().finally(() => {
28032
+ throw reason;
28033
+ });
28034
+ });
28035
+ process.once("SIGINT", () => {
28036
+ void handleCrash().finally(() => {
28037
+ process.exit(130);
28038
+ });
28039
+ });
28107
28040
 
28108
28041
  // packages/experience-design-system-cli/src/tui/help/help-info.ts
28109
- init_config();
28110
- init_debug_store();
28111
- init_debug_mode_store();
28112
- init_version();
28113
28042
  async function readHelpInfo() {
28114
28043
  const debugMode = await readDebugModeSetting();
28115
28044
  return {
28116
28045
  storage: [
28117
28046
  { label: "Config folder", value: configRoot2() },
28118
- { label: "Settings file", value: configFilePath2() }
28047
+ { label: "Settings file", value: configFilePath2() },
28048
+ { label: "Debug logs", value: debugSessionsDir2() }
28119
28049
  ],
28120
28050
  troubleshooting: [
28121
28051
  { label: "CLI version", value: readPackageVersion() },
@@ -28124,7 +28054,7 @@ async function readHelpInfo() {
28124
28054
  { label: "Debug Mode", value: debugMode.enabled ? "on" : "off" },
28125
28055
  {
28126
28056
  label: "This session",
28127
- value: !debugMode.enabled ? "no logs written while Debug Mode is off" : currentDebugSessionDir() ?? "not started: set the Root Project Directory in Settings, or start an import"
28057
+ value: debugMode.enabled ? currentDebugSessionDir() : "no logs written while Debug Mode is off"
28128
28058
  }
28129
28059
  ]
28130
28060
  };
@@ -28143,7 +28073,7 @@ function Section({ title, rows }) {
28143
28073
  }
28144
28074
  function HelpScreen({ onDone }) {
28145
28075
  const [info, setInfo] = useState27();
28146
- useEffect22(() => {
28076
+ useEffect23(() => {
28147
28077
  startDebugRun({ flow: "help", step: "01-help", menuOption: "Help", inputs: {} });
28148
28078
  void readHelpInfo().then(setInfo);
28149
28079
  }, []);
@@ -28236,12 +28166,11 @@ function SettingsScreen({
28236
28166
  }
28237
28167
 
28238
28168
  // packages/experience-design-system-cli/src/tui/settings/contentful-configuration/ContentfulConfigScreen.tsx
28239
- import { useEffect as useEffect23, useState as useState29 } from "react";
28169
+ import { useEffect as useEffect24, useState as useState29 } from "react";
28240
28170
  import { Box as Box44, Text as Text46, useInput as useInput11 } from "ink";
28241
28171
  import TextInput4 from "ink-text-input";
28242
28172
 
28243
28173
  // packages/experience-design-system-cli/src/tui/settings/utils/v1-store.ts
28244
- init_config();
28245
28174
  var readV1Store = readSettings2;
28246
28175
  var writeV1Store = writeSettings2;
28247
28176
 
@@ -28254,8 +28183,7 @@ async function readCredentials() {
28254
28183
  cmaToken: store.cmaToken || "",
28255
28184
  host: store.host || "",
28256
28185
  defaultComponentDir: store.defaultComponentDir || "",
28257
- defaultTokenFile: store.defaultTokenFile || "",
28258
- contentfulBaseDir: store.contentfulBaseDir || ""
28186
+ defaultTokenFile: store.defaultTokenFile || ""
28259
28187
  };
28260
28188
  }
28261
28189
  async function writeCredentials(config) {
@@ -28271,7 +28199,6 @@ async function writeCredentials(config) {
28271
28199
  }
28272
28200
 
28273
28201
  // packages/experience-design-system-cli/src/tui/settings/contentful-configuration/ContentfulConfigScreen.tsx
28274
- init_debug_store();
28275
28202
  import { Fragment as Fragment17, jsx as jsx55, jsxs as jsxs45 } from "react/jsx-runtime";
28276
28203
  var FIELD_ORDER = [
28277
28204
  "spaceId",
@@ -28279,8 +28206,7 @@ var FIELD_ORDER = [
28279
28206
  "cmaToken",
28280
28207
  "host",
28281
28208
  "defaultComponentDir",
28282
- "defaultTokenFile",
28283
- "contentfulBaseDir"
28209
+ "defaultTokenFile"
28284
28210
  ];
28285
28211
  function debugFields(config) {
28286
28212
  return {
@@ -28289,23 +28215,17 @@ function debugFields(config) {
28289
28215
  cma_token: config?.cmaToken ?? "",
28290
28216
  host: config?.host ?? "",
28291
28217
  default_component_dir: config?.defaultComponentDir ?? "",
28292
- default_token_file: config?.defaultTokenFile ?? "",
28293
- contentful_base_dir: config?.contentfulBaseDir ?? ""
28218
+ default_token_file: config?.defaultTokenFile ?? ""
28294
28219
  };
28295
28220
  }
28296
28221
  var FIELD_LABELS = {
28297
28222
  spaceId: "Space ID",
28298
28223
  environmentId: "Environment ID",
28299
28224
  cmaToken: "CMA Token",
28300
- host: "API Host",
28301
- defaultComponentDir: "Default component directory",
28302
- defaultTokenFile: "Default token file",
28303
- contentfulBaseDir: "Root Project Directory"
28304
- };
28305
- var FIELD_HINTS = {
28306
- contentfulBaseDir: "(where .contentful goes)"
28225
+ host: "API Host (optional)",
28226
+ defaultComponentDir: "Default component directory (optional)",
28227
+ defaultTokenFile: "Default token file (optional)"
28307
28228
  };
28308
- var LABEL_WIDTH = Math.max(...Object.values(FIELD_LABELS).map((label) => label.length));
28309
28229
  function ConfigurationScreen({ onDone }) {
28310
28230
  const [stage, setStage] = useState29("loading");
28311
28231
  const [config, setConfig] = useState29(null);
@@ -28314,7 +28234,7 @@ function ConfigurationScreen({ onDone }) {
28314
28234
  const [lastSaved, setLastSaved] = useState29(null);
28315
28235
  const [editing, setEditing] = useState29(false);
28316
28236
  const [valueBeforeEdit, setValueBeforeEdit] = useState29("");
28317
- useEffect23(() => {
28237
+ useEffect24(() => {
28318
28238
  readCredentials().then((cfg) => {
28319
28239
  setConfig(cfg);
28320
28240
  setStage("form");
@@ -28341,7 +28261,6 @@ function ConfigurationScreen({ onDone }) {
28341
28261
  setNotice(null);
28342
28262
  writeCredentials(config).then(() => {
28343
28263
  setLastSaved(config);
28344
- if (config.contentfulBaseDir) void startDebugSessionIn(config.contentfulBaseDir, { replace: true });
28345
28264
  setNotice({ kind: "success", text: "Configuration saved" });
28346
28265
  setStage("form");
28347
28266
  }).catch((err) => {
@@ -28407,7 +28326,10 @@ function ConfigurationScreen({ onDone }) {
28407
28326
  const display = field === "cmaToken" ? "\u2022".repeat(value.length) : value;
28408
28327
  return /* @__PURE__ */ jsxs45(Box44, { gap: 1, children: [
28409
28328
  /* @__PURE__ */ jsx55(Text46, { color: isActive ? PALETTE.accent : void 0, children: isActive ? "\u276F" : " " }),
28410
- /* @__PURE__ */ jsx55(Box44, { width: LABEL_WIDTH, flexShrink: 0, children: /* @__PURE__ */ jsx55(Text46, { bold: isActive, color: isActive ? PALETTE.accent : PALETTE.muted, children: FIELD_LABELS[field] }) }),
28329
+ /* @__PURE__ */ jsxs45(Text46, { bold: isActive, children: [
28330
+ FIELD_LABELS[field],
28331
+ ":"
28332
+ ] }),
28411
28333
  isActive && editing ? /* @__PURE__ */ jsx55(
28412
28334
  TextInput4,
28413
28335
  {
@@ -28416,8 +28338,7 @@ function ConfigurationScreen({ onDone }) {
28416
28338
  onSubmit: () => setEditing(false),
28417
28339
  mask: field === "cmaToken" ? "\u2022" : void 0
28418
28340
  }
28419
- ) : /* @__PURE__ */ jsx55(Text46, { bold: !!display, children: display || (FIELD_HINTS[field] ? "" : /* @__PURE__ */ jsx55(Text46, { color: PALETTE.muted, children: "(empty)" })) }),
28420
- FIELD_HINTS[field] && /* @__PURE__ */ jsx55(Text46, { color: PALETTE.muted, children: FIELD_HINTS[field] })
28341
+ ) : /* @__PURE__ */ jsx55(Text46, { children: display || /* @__PURE__ */ jsx55(Text46, { color: PALETTE.muted, children: "(empty)" }) })
28421
28342
  ] }, field);
28422
28343
  }) }),
28423
28344
  notice && /* @__PURE__ */ jsxs45(Fragment17, { children: [
@@ -28450,7 +28371,7 @@ function ConfigurationScreen({ onDone }) {
28450
28371
  }
28451
28372
 
28452
28373
  // packages/experience-design-system-cli/src/tui/settings/opt-in-analytics/screen.tsx
28453
- import { useEffect as useEffect24, useState as useState30 } from "react";
28374
+ import { useEffect as useEffect25, useState as useState30 } from "react";
28454
28375
  import { Box as Box45, Text as Text47, useInput as useInput12 } from "ink";
28455
28376
 
28456
28377
  // packages/experience-design-system-cli/src/tui/settings/opt-in-analytics/analytics-store.ts
@@ -28469,12 +28390,11 @@ async function writeAnalyticsSetting(setting) {
28469
28390
  }
28470
28391
 
28471
28392
  // packages/experience-design-system-cli/src/tui/settings/opt-in-analytics/screen.tsx
28472
- init_debug_store();
28473
28393
  import { Fragment as Fragment18, jsx as jsx56, jsxs as jsxs46 } from "react/jsx-runtime";
28474
28394
  function OptInAnalyticsScreen({ onDone }) {
28475
28395
  const [loading, setLoading] = useState30(true);
28476
28396
  const [enabled, setEnabled] = useState30(true);
28477
- useEffect24(() => {
28397
+ useEffect25(() => {
28478
28398
  readAnalyticsSetting().then((setting) => {
28479
28399
  setEnabled(setting.enabled);
28480
28400
  setLoading(false);
@@ -28528,15 +28448,13 @@ function OptInAnalyticsScreen({ onDone }) {
28528
28448
  }
28529
28449
 
28530
28450
  // packages/experience-design-system-cli/src/tui/upgrade/PageContainer.tsx
28531
- import { useEffect as useEffect25, useState as useState31 } from "react";
28451
+ import { useEffect as useEffect26, useState as useState31 } from "react";
28532
28452
  import { Box as Box46, Text as Text48, useInput as useInput13 } from "ink";
28533
- init_version();
28534
- init_debug_store();
28535
28453
  import { jsx as jsx57, jsxs as jsxs47 } from "react/jsx-runtime";
28536
28454
  var UPGRADE_COMMANDS = ["git pull", "pnpm install", "pnpm build"];
28537
28455
  function UpgradeScreen({ onDone }) {
28538
28456
  const [upgradeCheck, setUpgradeCheck] = useState31();
28539
- useEffect25(() => {
28457
+ useEffect26(() => {
28540
28458
  startDebugRun({
28541
28459
  flow: "upgrade",
28542
28460
  step: "01-upgrade",
@@ -28601,15 +28519,13 @@ function renderBody(upgradeCheck) {
28601
28519
  }
28602
28520
 
28603
28521
  // packages/experience-design-system-cli/src/tui/settings/debug-mode/screen.tsx
28604
- import { useEffect as useEffect26, useState as useState32 } from "react";
28522
+ import { useEffect as useEffect27, useState as useState32 } from "react";
28605
28523
  import { Box as Box47, Text as Text49, useInput as useInput14 } from "ink";
28606
- init_debug_mode_store();
28607
- init_debug_store();
28608
28524
  import { jsx as jsx58, jsxs as jsxs48 } from "react/jsx-runtime";
28609
28525
  function DebugModeScreen({ onDone }) {
28610
28526
  const [loading, setLoading] = useState32(true);
28611
28527
  const [enabled, setEnabled] = useState32(true);
28612
- useEffect26(() => {
28528
+ useEffect27(() => {
28613
28529
  readDebugModeSetting().then((setting) => {
28614
28530
  setEnabled(setting.enabled);
28615
28531
  setLoading(false);
@@ -28689,7 +28605,7 @@ function App({ importOptions, inkClear }) {
28689
28605
  const [flowStart, setFlowStart] = useState33();
28690
28606
  const flow = useFlow(flowStart);
28691
28607
  const [importDefaults, setImportDefaults] = useState33();
28692
- useEffect27(() => {
28608
+ useEffect28(() => {
28693
28609
  if (screen !== "import") {
28694
28610
  setImportDefaults(void 0);
28695
28611
  return;
@@ -28747,12 +28663,12 @@ function App({ importOptions, inkClear }) {
28747
28663
  }
28748
28664
  });
28749
28665
  };
28750
- useEffect27(() => {
28666
+ useEffect28(() => {
28751
28667
  if (!extractionRun || extraction?.status !== "done" || !extraction.result.ok) return;
28752
28668
  setExtractionRun(void 0);
28753
28669
  setScopeRun({ ...extractionRun, extraction: extraction.result.extraction });
28754
28670
  }, [extraction, extractionRun]);
28755
- useEffect27(() => {
28671
+ useEffect28(() => {
28756
28672
  if (!scopeRun || scopeFlow?.status !== "confirmed" || generationInput) return;
28757
28673
  const { extraction: produced, input, generatePromptPath } = scopeRun;
28758
28674
  setGenerationInput({
@@ -28770,7 +28686,7 @@ function App({ importOptions, inkClear }) {
28770
28686
  ...generatePromptPath ? { generatePromptPath } : {}
28771
28687
  });
28772
28688
  }, [scopeFlow, scopeRun, generationInput]);
28773
- useEffect27(() => {
28689
+ useEffect28(() => {
28774
28690
  if (!scopeRun || generation?.status !== "done" || !generation.result.ok) return;
28775
28691
  const { credentialsSkipped, tokenStrategy, extraction: produced, input, generatePromptPath } = scopeRun;
28776
28692
  inkClear();
@@ -28821,7 +28737,10 @@ function App({ importOptions, inkClear }) {
28821
28737
  state: flow.state,
28822
28738
  controller: flow.controller,
28823
28739
  generatePromptPath: flowStart.generatePromptPath,
28824
- onExit: setImportExitCode,
28740
+ onExit: (code) => {
28741
+ inkClear();
28742
+ setImportExitCode(code);
28743
+ },
28825
28744
  onStepChange: inkClear
28826
28745
  }
28827
28746
  );