@contentful/experience-design-system-cli 2.37.1-dev-build-5bd13138.0 → 2.37.1-dev-build-cffd984a.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
@@ -2121,7 +2121,7 @@ async function runAgent(options) {
2121
2121
  promptLen: prompt.length,
2122
2122
  promptHead: prompt.slice(0, 500)
2123
2123
  });
2124
- return new Promise((resolve26) => {
2124
+ return new Promise((resolve27) => {
2125
2125
  const bedrockEnv = bedrock ? BEDROCK_ENV_BY_AGENT[agent] : void 0;
2126
2126
  const child = spawn3(binary, args, {
2127
2127
  stdio: ["pipe", "pipe", "pipe"],
@@ -2170,7 +2170,7 @@ async function runAgent(options) {
2170
2170
  stderrLen: stderr.length,
2171
2171
  stderrTail: stderr.slice(-1e3)
2172
2172
  });
2173
- resolve26(result);
2173
+ resolve27(result);
2174
2174
  });
2175
2175
  });
2176
2176
  }
@@ -2192,7 +2192,7 @@ async function checkAgentAuth(agent) {
2192
2192
  return "not-found";
2193
2193
  if (agent !== "claude")
2194
2194
  return "ok";
2195
- return new Promise((resolve26) => {
2195
+ return new Promise((resolve27) => {
2196
2196
  const child = spawn4(binary, ["auth", "status", "--json"], { stdio: ["ignore", "pipe", "pipe"] });
2197
2197
  let stdout = "";
2198
2198
  let done = false;
@@ -2201,7 +2201,7 @@ async function checkAgentAuth(agent) {
2201
2201
  return;
2202
2202
  done = true;
2203
2203
  child.kill("SIGTERM");
2204
- resolve26("unauthenticated");
2204
+ resolve27("unauthenticated");
2205
2205
  }, 5e3);
2206
2206
  child.stdout?.on("data", (chunk) => {
2207
2207
  stdout += chunk.toString();
@@ -2212,14 +2212,14 @@ async function checkAgentAuth(agent) {
2212
2212
  done = true;
2213
2213
  clearTimeout(timer);
2214
2214
  if (code !== 0) {
2215
- resolve26("unauthenticated");
2215
+ resolve27("unauthenticated");
2216
2216
  return;
2217
2217
  }
2218
2218
  try {
2219
2219
  const status = JSON.parse(stdout);
2220
- resolve26(status.loggedIn ? "ok" : "unauthenticated");
2220
+ resolve27(status.loggedIn ? "ok" : "unauthenticated");
2221
2221
  } catch {
2222
- resolve26("unauthenticated");
2222
+ resolve27("unauthenticated");
2223
2223
  }
2224
2224
  });
2225
2225
  });
@@ -2229,9 +2229,9 @@ async function binaryIsOnPath(binary) {
2229
2229
  const fs = await import("node:fs/promises");
2230
2230
  return fs.access(binary).then(() => true, () => false);
2231
2231
  }
2232
- return new Promise((resolve26) => {
2232
+ return new Promise((resolve27) => {
2233
2233
  const child = spawn4(process.platform === "win32" ? "where" : "which", [binary], { stdio: "ignore" });
2234
- child.on("close", (code) => resolve26(code === 0));
2234
+ child.on("close", (code) => resolve27(code === 0));
2235
2235
  });
2236
2236
  }
2237
2237
  var init_check_agent_auth = __esm({
@@ -5197,7 +5197,7 @@ function getTsxExtractionContext(filePaths, componentFilePattern) {
5197
5197
  project: createTsxProject(getTsxProjectFiles(filePaths))
5198
5198
  };
5199
5199
  }
5200
- function extractTsxComponents(filePaths, componentFilePattern, extract2) {
5200
+ function extractTsxComponents(filePaths, componentFilePattern, extract) {
5201
5201
  const extractionContext = getTsxExtractionContext(filePaths, componentFilePattern);
5202
5202
  if (!extractionContext) {
5203
5203
  return { components: [], warnings: [], exclusions: [] };
@@ -5211,7 +5211,7 @@ function extractTsxComponents(filePaths, componentFilePattern, extract2) {
5211
5211
  const sourceFile = project.getSourceFile(filePath);
5212
5212
  if (!sourceFile)
5213
5213
  continue;
5214
- components.push(...extract2(sourceFile, exclusions));
5214
+ components.push(...extract(sourceFile, exclusions));
5215
5215
  } catch (e) {
5216
5216
  warnings.push(`Failed to extract from ${filePath}: ${e instanceof Error ? e.message : String(e)}`);
5217
5217
  }
@@ -14901,7 +14901,7 @@ function errorMessage(error) {
14901
14901
  return error instanceof Error && error.message ? error.message : String(error);
14902
14902
  }
14903
14903
  function defaultSleep(delayMs) {
14904
- return new Promise((resolve26) => setTimeout(resolve26, delayMs));
14904
+ return new Promise((resolve27) => setTimeout(resolve27, delayMs));
14905
14905
  }
14906
14906
  var MAX_RETRY_AFTER_MS;
14907
14907
  var init_http_utils = __esm({
@@ -15177,7 +15177,7 @@ var init_api_client = __esm({
15177
15177
  const progress = maxAttempts > 1 ? attempt / (maxAttempts - 1) : 0;
15178
15178
  const baseDelay = intervalMs + (maxIntervalMs - intervalMs) * progress;
15179
15179
  const jitter = Math.random() * baseDelay * 0.15;
15180
- await new Promise((resolve26) => setTimeout(resolve26, baseDelay + jitter));
15180
+ await new Promise((resolve27) => setTimeout(resolve27, baseDelay + jitter));
15181
15181
  }
15182
15182
  }
15183
15183
  throw new Error(`Operation ${operationId} timed out after ${maxAttempts} attempts`);
@@ -18734,7 +18734,7 @@ async function retryDatabaseWrite(operation, attempts = 8) {
18734
18734
  const message = error instanceof Error ? error.message : String(error);
18735
18735
  if (!/database is locked|database is busy/i.test(message) || attempt >= attempts)
18736
18736
  throw error;
18737
- await new Promise((resolve26) => setTimeout(resolve26, Math.min(250 * attempt, 2e3)));
18737
+ await new Promise((resolve27) => setTimeout(resolve27, Math.min(250 * attempt, 2e3)));
18738
18738
  }
18739
18739
  }
18740
18740
  }
@@ -20527,228 +20527,17 @@ var init_config = __esm({
20527
20527
  }
20528
20528
  });
20529
20529
 
20530
- // packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts
20531
- async function readDebugModeSetting() {
20532
- const { debugMode } = await readSettings2();
20533
- return { ...DEFAULT_DEBUG_MODE_SETTING, ...debugMode };
20534
- }
20535
- async function writeDebugModeSetting(setting) {
20536
- await updateSettings2({ debugMode: setting });
20537
- }
20538
- var DEFAULT_DEBUG_MODE_SETTING;
20539
- var init_debug_mode_store = __esm({
20540
- "packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts"() {
20541
- "use strict";
20542
- init_config();
20543
- DEFAULT_DEBUG_MODE_SETTING = {
20544
- enabled: true
20545
- };
20546
- }
20547
- });
20548
-
20549
- // packages/experience-design-system-cli/src/tui/debug-store.ts
20550
- var debug_store_exports = {};
20551
- __export(debug_store_exports, {
20552
- currentDebugSessionDir: () => currentDebugSessionDir,
20553
- finishDebugRun: () => finishDebugRun,
20554
- setDebugOutDir: () => setDebugOutDir,
20555
- startDebugRun: () => startDebugRun
20556
- });
20557
- import { cp, mkdir as mkdir7, rename as rename3, rm, writeFile as writeFile7 } from "node:fs/promises";
20558
- import { existsSync as existsSync10, readdirSync as readdirSync3 } from "node:fs";
20559
- import { join as join20, resolve as resolve20 } from "node:path";
20560
- function generateRunId() {
20561
- const now = /* @__PURE__ */ new Date();
20562
- const pad = (n) => String(n).padStart(2, "0");
20563
- return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
20564
- }
20565
- function datePrefix(now = /* @__PURE__ */ new Date()) {
20566
- const pad = (n) => String(n).padStart(2, "0");
20567
- return `${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}`;
20568
- }
20569
- function slugify(value) {
20570
- return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
20571
- }
20572
- function generateSessionId3() {
20573
- const today = datePrefix();
20574
- const root = debugSessionsDir2();
20575
- const existing = existsSync10(root) ? readdirSync3(root) : [];
20576
- const seqPattern = new RegExp(`^${today}-session-(\\d+)$`);
20577
- const maxSeq = existing.reduce((max, entry) => {
20578
- const match2 = seqPattern.exec(entry);
20579
- return match2 ? Math.max(max, Number(match2[1])) : max;
20580
- }, 0);
20581
- return `${today}-session-${maxSeq + 1}`;
20582
- }
20583
- function sessionDebugDir() {
20584
- return join20(projectSessionsRoot ?? debugSessionsDir2(), SESSION_ID);
20585
- }
20586
- function currentDebugSessionDir() {
20587
- return sessionDebugDir();
20588
- }
20589
- async function setDebugOutDir(outDir) {
20590
- if (!await isDebugModeEnabled()) return;
20591
- const nextRoot = join20(resolve20(outDir), "debug", "sessions");
20592
- const from = sessionDebugDir();
20593
- const to = join20(nextRoot, SESSION_ID);
20594
- if (from === to) return;
20595
- try {
20596
- await mkdir7(nextRoot, { recursive: true });
20597
- if (existsSync10(from)) {
20598
- try {
20599
- await rename3(from, to);
20600
- } catch {
20601
- await cp(from, to, { recursive: true });
20602
- await rm(from, { recursive: true, force: true });
20603
- }
20604
- } else {
20605
- await mkdir7(to, { recursive: true });
20606
- }
20607
- projectSessionsRoot = nextRoot;
20608
- } catch {
20609
- }
20610
- }
20611
- async function isDebugModeEnabled() {
20612
- try {
20613
- return (await readDebugModeSetting()).enabled;
20614
- } catch {
20615
- return true;
20616
- }
20617
- }
20618
- function redact(value) {
20619
- const clone = { ...value };
20620
- if ("cma_token" in clone) {
20621
- const raw = clone.cma_token;
20622
- clone.cma_token = typeof raw === "string" && raw.length > 0 ? `[present, ${raw.length} chars]` : "[not set]";
20623
- }
20624
- return clone;
20625
- }
20626
- function startDebugRun({
20627
- flow,
20628
- step,
20629
- menuOption,
20630
- inputs
20631
- }) {
20632
- const runId = generateRunId();
20633
- const startedAt = Date.now();
20634
- const redactedInputs = redact(inputs);
20635
- isDebugModeEnabled().then((enabled) => {
20636
- if (!enabled) return;
20637
- pendingRun = { flow, step, runId, menuOption, inputs: redactedInputs, startedAt };
20638
- });
20639
- }
20640
- async function finishDebugRun({
20641
- outputs,
20642
- status,
20643
- exitMethod
20644
- }) {
20645
- const run = pendingRun;
20646
- if (!run) return;
20647
- pendingRun = void 0;
20648
- const durationMs = Date.now() - run.startedAt;
20649
- const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
20650
- const flowSegments = run.flow.split("/");
20651
- const dir = join20(sessionDebugDir(), ...flowSegments);
20652
- await mkdir7(dir, { recursive: true });
20653
- const filename = nextAttemptFilename(dir, run.menuOption);
20654
- await writeFile7(join20(dir, filename), content, { mode: 384 });
20655
- }
20656
- function nextAttemptFilename(dir, menuOption) {
20657
- const today = datePrefix();
20658
- const optionSlug = slugify(menuOption);
20659
- const existing = existsSync10(dir) ? readdirSync3(dir) : [];
20660
- const attemptPattern = new RegExp(`^${today}-${optionSlug}-attempt-(\\d+)\\.md$`);
20661
- const maxAttempt = existing.reduce((max, entry) => {
20662
- const match2 = attemptPattern.exec(entry);
20663
- return match2 ? Math.max(max, Number(match2[1])) : max;
20664
- }, 0);
20665
- return `${today}-${optionSlug}-attempt-${maxAttempt + 1}.md`;
20666
- }
20667
- function renderMarkdown(run, finish) {
20668
- const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
20669
- const stepLabel2 = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
20670
- const flowSlug = run.flow.split("/").join("-");
20671
- return `# Debug Log
20672
-
20673
- - Run ID: ${run.runId}
20674
- - Flow: ${flowSlug}
20675
- - Step: ${stepLabel2}
20676
- - Menu option: ${run.menuOption}
20677
- - Date: ${(/* @__PURE__ */ new Date()).toISOString()}
20678
- - CLI version: ${readPackageVersion()}
20679
- - Platform: ${process.platform} / Node ${process.version}
20680
- - Duration on screen: ${finish.durationMs}ms
20681
- - Status: ${finish.status}
20682
- - Exit method: ${finish.exitMethod}
20683
-
20684
- ## Inputs
20685
- \`\`\`json
20686
- ${JSON.stringify(run.inputs, null, 2)}
20687
- \`\`\`
20688
-
20689
- ## Outputs
20690
- \`\`\`json
20691
- ${JSON.stringify(finish.outputs, null, 2)}
20692
- \`\`\`
20693
- `;
20694
- }
20695
- function handleCrash() {
20696
- return finishDebugRun({ outputs: {}, status: "error", exitMethod: "crashed" });
20697
- }
20698
- var pendingRun, SESSION_ID, projectSessionsRoot;
20699
- var init_debug_store = __esm({
20700
- "packages/experience-design-system-cli/src/tui/debug-store.ts"() {
20701
- "use strict";
20702
- init_config();
20703
- init_version();
20704
- init_debug_mode_store();
20705
- SESSION_ID = generateSessionId3();
20706
- void isDebugModeEnabled().then((enabled) => {
20707
- if (!enabled) return void 0;
20708
- return mkdir7(sessionDebugDir(), { recursive: true });
20709
- });
20710
- process.once("uncaughtException", (err) => {
20711
- void handleCrash().finally(() => {
20712
- throw err;
20713
- });
20714
- });
20715
- process.once("unhandledRejection", (reason) => {
20716
- void handleCrash().finally(() => {
20717
- throw reason;
20718
- });
20719
- });
20720
- process.once("SIGINT", () => {
20721
- void handleCrash().finally(() => {
20722
- process.exit(130);
20723
- });
20724
- });
20725
- }
20726
- });
20727
-
20728
- // packages/experience-design-system-cli/src/tui/import/debug-hooks.ts
20729
- var realDebugHooks;
20730
- var init_debug_hooks = __esm({
20731
- "packages/experience-design-system-cli/src/tui/import/debug-hooks.ts"() {
20732
- "use strict";
20733
- realDebugHooks = {
20734
- setOutDir: async (outDir) => (await Promise.resolve().then(() => (init_debug_store(), debug_store_exports))).setDebugOutDir(outDir),
20735
- start: (run) => void Promise.resolve().then(() => (init_debug_store(), debug_store_exports)).then((m) => m.startDebugRun(run)),
20736
- finish: async (run) => (await Promise.resolve().then(() => (init_debug_store(), debug_store_exports))).finishDebugRun(run)
20737
- };
20738
- }
20739
- });
20740
-
20741
20530
  // packages/experience-design-system-cli/src/tui/import/steps/06-extraction/find-skill-path.ts
20742
- import { existsSync as existsSync11 } from "node:fs";
20743
- import { dirname as dirname14, join as join21, resolve as resolve21 } from "node:path";
20531
+ import { existsSync as existsSync10 } from "node:fs";
20532
+ import { dirname as dirname14, join as join20, resolve as resolve20 } from "node:path";
20744
20533
  import { fileURLToPath as fileURLToPath4 } from "node:url";
20745
20534
  function findSkillPath(fileName) {
20746
20535
  const thisDir = dirname14(fileURLToPath4(import.meta.url));
20747
20536
  let dir = thisDir;
20748
20537
  for (; ; ) {
20749
- const candidate = join21(dir, "skills", fileName);
20750
- if (existsSync11(candidate)) return candidate;
20751
- const parent = resolve21(dir, "..");
20538
+ const candidate = join20(dir, "skills", fileName);
20539
+ if (existsSync10(candidate)) return candidate;
20540
+ const parent = resolve20(dir, "..");
20752
20541
  if (parent === dir) {
20753
20542
  throw new Error(`skill file not found (looked for skills/${fileName} from ${thisDir})`);
20754
20543
  }
@@ -20762,9 +20551,9 @@ var init_find_skill_path = __esm({
20762
20551
  });
20763
20552
 
20764
20553
  // packages/experience-design-system-cli/src/tui/import/steps/06-extraction/selection.ts
20765
- import { resolve as resolve22 } from "node:path";
20554
+ import { resolve as resolve21 } from "node:path";
20766
20555
  async function hashSelectPrompt(options) {
20767
- const promptHash = options.promptText ? hashContent(options.promptText) : options.promptPath ? await hashFile(resolve22(options.promptPath)) : await hashFile(SELECT_SKILL_PATH);
20556
+ const promptHash = options.promptText ? hashContent(options.promptText) : options.promptPath ? await hashFile(resolve21(options.promptPath)) : await hashFile(SELECT_SKILL_PATH);
20768
20557
  return hashContent(`${promptHash}|${options.agent}|${options.model ?? ""}`);
20769
20558
  }
20770
20559
  async function runSelection(options) {
@@ -20858,29 +20647,10 @@ var init_selection2 = __esm({
20858
20647
  });
20859
20648
 
20860
20649
  // packages/experience-design-system-cli/src/tui/import/steps/06-extraction/run.ts
20861
- import { mkdir as mkdir8 } from "node:fs/promises";
20862
- import { join as join22, resolve as resolve23 } from "node:path";
20650
+ import { mkdir as mkdir7 } from "node:fs/promises";
20651
+ import { join as join21, resolve as resolve22 } from "node:path";
20863
20652
  async function runExtraction(input, onProgress, deps = realDeps) {
20864
- const outDir = join22(resolve23(input.projectPath), ".contentful");
20865
- await deps.debug?.setOutDir(outDir);
20866
- deps.debug?.start({
20867
- flow: "import",
20868
- step: "06-extraction",
20869
- menuOption: "Import",
20870
- inputs: {
20871
- projectPath: input.projectPath,
20872
- agent: input.agent,
20873
- files: input.filePaths.length,
20874
- noCache: input.noCache
20875
- }
20876
- });
20877
- const result = await extract(input, outDir, onProgress, deps);
20878
- await deps.debug?.finish(
20879
- result.ok ? { outputs: { sessionId: result.extraction.sessionId, outDir }, status: "success", exitMethod: "saved" } : { outputs: { step: result.step, message: result.message }, status: "error", exitMethod: "discarded" }
20880
- );
20881
- return result;
20882
- }
20883
- async function extract(input, outDir, onProgress, deps) {
20653
+ const outDir = join21(resolve22(input.projectPath), ".contentful");
20884
20654
  let progress = initialProgress({
20885
20655
  hasCredentials: input.credentials !== null,
20886
20656
  hasRawTokens: input.rawTokensPath !== "",
@@ -20975,7 +20745,7 @@ async function extract(input, outDir, onProgress, deps) {
20975
20745
  const extraction = {
20976
20746
  sessionId: extracted.sessionId,
20977
20747
  outDir,
20978
- tokensPath: tokens?.ok ? tokens.tokensPath : hasTokenSource ? join22(outDir, "tokens.json") : "",
20748
+ tokensPath: tokens?.ok ? tokens.tokensPath : hasTokenSource ? join21(outDir, "tokens.json") : "",
20979
20749
  tokenSessionId: tokens?.ok ? tokens.tokenSessionId : null,
20980
20750
  tokenCount: tokens?.ok ? tokens.tokenCount : 0,
20981
20751
  existingEntitiesPath,
@@ -20986,7 +20756,7 @@ async function extract(input, outDir, onProgress, deps) {
20986
20756
  }
20987
20757
  async function fetchEntities(credentials, outDir) {
20988
20758
  try {
20989
- await mkdir8(outDir, { recursive: true });
20759
+ await mkdir7(outDir, { recursive: true });
20990
20760
  const result = await fetchAndPersistExistingContentfulEntities({
20991
20761
  spaceId: credentials.spaceId,
20992
20762
  environmentId: credentials.environmentId,
@@ -21006,7 +20776,7 @@ async function resolveSelectionPrompt(overrides) {
21006
20776
  if (select?.kind === "text") return { promptText: select.value };
21007
20777
  if (select?.kind === "path") {
21008
20778
  await resolvePromptOverride(select);
21009
- return { promptPath: resolve23(select.value) };
20779
+ return { promptPath: resolve22(select.value) };
21010
20780
  }
21011
20781
  return {};
21012
20782
  }
@@ -21015,7 +20785,6 @@ var init_run = __esm({
21015
20785
  "packages/experience-design-system-cli/src/tui/import/steps/06-extraction/run.ts"() {
21016
20786
  "use strict";
21017
20787
  init_src4();
21018
- init_debug_hooks();
21019
20788
  init_find_skill_path();
21020
20789
  init_logic9();
21021
20790
  init_selection2();
@@ -21025,15 +20794,213 @@ var init_run = __esm({
21025
20794
  fetchEntities,
21026
20795
  runExtractAndComposeSession,
21027
20796
  runGenerateTokensSession,
21028
- runSelection,
21029
- debug: realDebugHooks
20797
+ runSelection
21030
20798
  };
21031
20799
  fail = (step, message) => ({ ok: false, step, message });
21032
20800
  errorMessage2 = (error) => error instanceof Error ? error.message : String(error);
21033
20801
  }
21034
20802
  });
21035
20803
 
20804
+ // packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts
20805
+ async function readDebugModeSetting() {
20806
+ const { debugMode } = await readSettings2();
20807
+ return { ...DEFAULT_DEBUG_MODE_SETTING, ...debugMode };
20808
+ }
20809
+ async function writeDebugModeSetting(setting) {
20810
+ await updateSettings2({ debugMode: setting });
20811
+ }
20812
+ var DEFAULT_DEBUG_MODE_SETTING;
20813
+ var init_debug_mode_store = __esm({
20814
+ "packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts"() {
20815
+ "use strict";
20816
+ init_config();
20817
+ DEFAULT_DEBUG_MODE_SETTING = {
20818
+ enabled: true
20819
+ };
20820
+ }
20821
+ });
20822
+
20823
+ // packages/experience-design-system-cli/src/tui/debug-store.ts
20824
+ var debug_store_exports = {};
20825
+ __export(debug_store_exports, {
20826
+ currentDebugSessionDir: () => currentDebugSessionDir,
20827
+ finishDebugRun: () => finishDebugRun,
20828
+ setDebugOutDir: () => setDebugOutDir,
20829
+ startDebugRun: () => startDebugRun
20830
+ });
20831
+ import { cp, mkdir as mkdir8, rename as rename3, rm, writeFile as writeFile7 } from "node:fs/promises";
20832
+ import { existsSync as existsSync11, readdirSync as readdirSync3 } from "node:fs";
20833
+ import { join as join22, resolve as resolve23 } from "node:path";
20834
+ function generateRunId() {
20835
+ const now = /* @__PURE__ */ new Date();
20836
+ const pad = (n) => String(n).padStart(2, "0");
20837
+ return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
20838
+ }
20839
+ function datePrefix(now = /* @__PURE__ */ new Date()) {
20840
+ const pad = (n) => String(n).padStart(2, "0");
20841
+ return `${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}`;
20842
+ }
20843
+ function slugify(value) {
20844
+ return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
20845
+ }
20846
+ function generateSessionId3() {
20847
+ const today = datePrefix();
20848
+ const root = debugSessionsDir2();
20849
+ const existing = existsSync11(root) ? readdirSync3(root) : [];
20850
+ const seqPattern = new RegExp(`^${today}-session-(\\d+)$`);
20851
+ const maxSeq = existing.reduce((max, entry) => {
20852
+ const match2 = seqPattern.exec(entry);
20853
+ return match2 ? Math.max(max, Number(match2[1])) : max;
20854
+ }, 0);
20855
+ return `${today}-session-${maxSeq + 1}`;
20856
+ }
20857
+ function sessionDebugDir() {
20858
+ return join22(projectSessionsRoot ?? debugSessionsDir2(), SESSION_ID);
20859
+ }
20860
+ function currentDebugSessionDir() {
20861
+ return sessionDebugDir();
20862
+ }
20863
+ async function setDebugOutDir(outDir) {
20864
+ if (!await isDebugModeEnabled()) return;
20865
+ const nextRoot = join22(resolve23(outDir), "debug", "sessions");
20866
+ const from = sessionDebugDir();
20867
+ const to = join22(nextRoot, SESSION_ID);
20868
+ if (from === to) return;
20869
+ try {
20870
+ await mkdir8(nextRoot, { recursive: true });
20871
+ if (existsSync11(from)) {
20872
+ try {
20873
+ await rename3(from, to);
20874
+ } catch {
20875
+ await cp(from, to, { recursive: true });
20876
+ await rm(from, { recursive: true, force: true });
20877
+ }
20878
+ } else {
20879
+ await mkdir8(to, { recursive: true });
20880
+ }
20881
+ projectSessionsRoot = nextRoot;
20882
+ } catch {
20883
+ }
20884
+ }
20885
+ async function isDebugModeEnabled() {
20886
+ try {
20887
+ return (await readDebugModeSetting()).enabled;
20888
+ } catch {
20889
+ return true;
20890
+ }
20891
+ }
20892
+ function redact(value) {
20893
+ const clone = { ...value };
20894
+ if ("cma_token" in clone) {
20895
+ const raw = clone.cma_token;
20896
+ clone.cma_token = typeof raw === "string" && raw.length > 0 ? `[present, ${raw.length} chars]` : "[not set]";
20897
+ }
20898
+ return clone;
20899
+ }
20900
+ function startDebugRun({
20901
+ flow,
20902
+ step,
20903
+ menuOption,
20904
+ inputs
20905
+ }) {
20906
+ const runId = generateRunId();
20907
+ const startedAt = Date.now();
20908
+ const redactedInputs = redact(inputs);
20909
+ isDebugModeEnabled().then((enabled) => {
20910
+ if (!enabled) return;
20911
+ pendingRun = { flow, step, runId, menuOption, inputs: redactedInputs, startedAt };
20912
+ });
20913
+ }
20914
+ async function finishDebugRun({
20915
+ outputs,
20916
+ status,
20917
+ exitMethod
20918
+ }) {
20919
+ const run = pendingRun;
20920
+ if (!run) return;
20921
+ pendingRun = void 0;
20922
+ const durationMs = Date.now() - run.startedAt;
20923
+ const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
20924
+ const flowSegments = run.flow.split("/");
20925
+ const dir = join22(sessionDebugDir(), ...flowSegments);
20926
+ await mkdir8(dir, { recursive: true });
20927
+ const filename = nextAttemptFilename(dir, run.menuOption);
20928
+ await writeFile7(join22(dir, filename), content, { mode: 384 });
20929
+ }
20930
+ function nextAttemptFilename(dir, menuOption) {
20931
+ const today = datePrefix();
20932
+ const optionSlug = slugify(menuOption);
20933
+ const existing = existsSync11(dir) ? readdirSync3(dir) : [];
20934
+ const attemptPattern = new RegExp(`^${today}-${optionSlug}-attempt-(\\d+)\\.md$`);
20935
+ const maxAttempt = existing.reduce((max, entry) => {
20936
+ const match2 = attemptPattern.exec(entry);
20937
+ return match2 ? Math.max(max, Number(match2[1])) : max;
20938
+ }, 0);
20939
+ return `${today}-${optionSlug}-attempt-${maxAttempt + 1}.md`;
20940
+ }
20941
+ function renderMarkdown(run, finish) {
20942
+ const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
20943
+ const stepLabel2 = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
20944
+ const flowSlug = run.flow.split("/").join("-");
20945
+ return `# Debug Log
20946
+
20947
+ - Run ID: ${run.runId}
20948
+ - Flow: ${flowSlug}
20949
+ - Step: ${stepLabel2}
20950
+ - Menu option: ${run.menuOption}
20951
+ - Date: ${(/* @__PURE__ */ new Date()).toISOString()}
20952
+ - CLI version: ${readPackageVersion()}
20953
+ - Platform: ${process.platform} / Node ${process.version}
20954
+ - Duration on screen: ${finish.durationMs}ms
20955
+ - Status: ${finish.status}
20956
+ - Exit method: ${finish.exitMethod}
20957
+
20958
+ ## Inputs
20959
+ \`\`\`json
20960
+ ${JSON.stringify(run.inputs, null, 2)}
20961
+ \`\`\`
20962
+
20963
+ ## Outputs
20964
+ \`\`\`json
20965
+ ${JSON.stringify(finish.outputs, null, 2)}
20966
+ \`\`\`
20967
+ `;
20968
+ }
20969
+ function handleCrash() {
20970
+ return finishDebugRun({ outputs: {}, status: "error", exitMethod: "crashed" });
20971
+ }
20972
+ var pendingRun, SESSION_ID, projectSessionsRoot;
20973
+ var init_debug_store = __esm({
20974
+ "packages/experience-design-system-cli/src/tui/debug-store.ts"() {
20975
+ "use strict";
20976
+ init_config();
20977
+ init_version();
20978
+ init_debug_mode_store();
20979
+ SESSION_ID = generateSessionId3();
20980
+ void isDebugModeEnabled().then((enabled) => {
20981
+ if (!enabled) return void 0;
20982
+ return mkdir8(sessionDebugDir(), { recursive: true });
20983
+ });
20984
+ process.once("uncaughtException", (err) => {
20985
+ void handleCrash().finally(() => {
20986
+ throw err;
20987
+ });
20988
+ });
20989
+ process.once("unhandledRejection", (reason) => {
20990
+ void handleCrash().finally(() => {
20991
+ throw reason;
20992
+ });
20993
+ });
20994
+ process.once("SIGINT", () => {
20995
+ void handleCrash().finally(() => {
20996
+ process.exit(130);
20997
+ });
20998
+ });
20999
+ }
21000
+ });
21001
+
21036
21002
  // packages/experience-design-system-cli/src/tui/import/steps/06-extraction/use-extraction.ts
21003
+ import { join as join23, resolve as resolve24 } from "node:path";
21037
21004
  import { useEffect as useEffect5, useRef as useRef2, useState as useState8 } from "react";
21038
21005
  function useExtraction(input) {
21039
21006
  const [state, setState] = useState8();
@@ -21052,6 +21019,9 @@ function useExtraction(input) {
21052
21019
  reuseTokens: input.tokenStrategy === "reuse"
21053
21020
  })
21054
21021
  });
21022
+ void Promise.resolve().then(() => (init_debug_store(), debug_store_exports)).then(
21023
+ (store) => store.setDebugOutDir(join23(resolve24(input.projectPath), ".contentful"))
21024
+ );
21055
21025
  void runExtraction(input, (progress) => {
21056
21026
  if (current.current === input) setState({ status: "running", progress });
21057
21027
  }).then((result) => {
@@ -24273,7 +24243,7 @@ var init_save_decisions = __esm({
24273
24243
  });
24274
24244
 
24275
24245
  // packages/experience-design-system-cli/src/tui/import/steps/08-generation/run.ts
24276
- import { resolve as resolve24 } from "node:path";
24246
+ import { resolve as resolve25 } from "node:path";
24277
24247
  async function runGeneration(input, onProgress, deps = realDeps3) {
24278
24248
  let progress = { components: null, mapTokens: "idle", mapTokensEligible: null };
24279
24249
  const update = (change) => {
@@ -24359,7 +24329,7 @@ async function buildMapTokensOptions(input) {
24359
24329
  if (mapOverride?.kind === "text") prompt.skillContentOverride = mapOverride.value;
24360
24330
  if (mapOverride?.kind === "path") {
24361
24331
  await resolvePromptOverride(mapOverride);
24362
- prompt.skillPathOverride = resolve24(mapOverride.value);
24332
+ prompt.skillPathOverride = resolve25(mapOverride.value);
24363
24333
  }
24364
24334
  if (input.existingEntitiesPath) {
24365
24335
  const entities = await readExistingContentfulEntitiesFromSession({ path: input.existingEntitiesPath });
@@ -24437,7 +24407,7 @@ var init_use_generation = __esm({
24437
24407
  });
24438
24408
 
24439
24409
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/build-flow-start.ts
24440
- import { join as join23 } from "node:path";
24410
+ import { join as join24 } from "node:path";
24441
24411
  function buildFlowStart(input) {
24442
24412
  const { extraction, handoff, saved, generatePromptPath } = input;
24443
24413
  const credentials = extraction.credentials ?? {
@@ -24450,7 +24420,7 @@ function buildFlowStart(input) {
24450
24420
  handoff,
24451
24421
  agent: extraction.agent,
24452
24422
  projectPath: extraction.projectPath,
24453
- outDir: extraction.projectPath ? join23(extraction.projectPath, ".contentful") : "",
24423
+ outDir: extraction.projectPath ? join24(extraction.projectPath, ".contentful") : "",
24454
24424
  rawTokensPath: extraction.rawTokensPath,
24455
24425
  credentials: {
24456
24426
  spaceId: credentials.spaceId,
@@ -30646,7 +30616,7 @@ var init_DoneStep = __esm({
30646
30616
  });
30647
30617
 
30648
30618
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/support/path-utils.ts
30649
- import { resolve as resolve25 } from "node:path";
30619
+ import { resolve as resolve26 } from "node:path";
30650
30620
  import { homedir as homedir4 } from "node:os";
30651
30621
  function expandTilde(input) {
30652
30622
  if (input === "~" || input.startsWith("~/") || input.startsWith("~\\")) {
@@ -30660,7 +30630,7 @@ function normalizePath(input) {
30660
30630
  p = p.slice(1, -1);
30661
30631
  }
30662
30632
  p = expandTilde(p);
30663
- return resolve25(p);
30633
+ return resolve26(p);
30664
30634
  }
30665
30635
  var init_path_utils = __esm({
30666
30636
  "packages/experience-design-system-cli/src/tui/import/steps/10-flow/support/path-utils.ts"() {
@@ -30688,7 +30658,7 @@ var init_use_blinking_cursor = __esm({
30688
30658
  import { useState as useState24 } from "react";
30689
30659
  import { Box as Box37, Text as Text40 } from "ink";
30690
30660
  import { readdirSync as readdirSync4 } from "node:fs";
30691
- import { dirname as dirname15, basename as basename6, join as join24 } from "node:path";
30661
+ import { dirname as dirname15, basename as basename6, join as join25 } from "node:path";
30692
30662
  import { jsx as jsx47, jsxs as jsxs38 } from "react/jsx-runtime";
30693
30663
  function autocomplete(partial) {
30694
30664
  if (!partial) return null;
@@ -30703,13 +30673,13 @@ function autocomplete(partial) {
30703
30673
  }
30704
30674
  const matches = entries.filter((e) => e.startsWith(base));
30705
30675
  if (matches.length === 0) return null;
30706
- if (matches.length === 1) return join24(dir, matches[0]);
30676
+ if (matches.length === 1) return join25(dir, matches[0]);
30707
30677
  let prefix = matches[0];
30708
30678
  for (const m of matches) {
30709
30679
  while (!m.startsWith(prefix)) prefix = prefix.slice(0, -1);
30710
30680
  if (!prefix) break;
30711
30681
  }
30712
- return prefix.length > base.length ? join24(dir, prefix) : null;
30682
+ return prefix.length > base.length ? join25(dir, prefix) : null;
30713
30683
  }
30714
30684
  function PathPrompt({
30715
30685
  defaultPath,
@@ -31913,7 +31883,7 @@ var init_run_print_files_helpers = __esm({
31913
31883
 
31914
31884
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/save.ts
31915
31885
  import { writeFile as writeFile8 } from "node:fs/promises";
31916
- import { join as join25 } from "node:path";
31886
+ import { join as join26 } from "node:path";
31917
31887
  function buildSavedCDF(components, tokens, opts = {}) {
31918
31888
  const cdf = buildCDF2(components, toCdfTokens(tokens), opts);
31919
31889
  if (!cdf) throw new Error("nothing to save \u2014 no components or tokens resolved");
@@ -31925,7 +31895,7 @@ function buildSavedCDF(components, tokens, opts = {}) {
31925
31895
  }
31926
31896
  async function runPrintFiles(input, deps, onPatch) {
31927
31897
  onPatch({ step: "printing" });
31928
- const componentsPath = join25(input.outDir, "components.json");
31898
+ const componentsPath = join26(input.outDir, "components.json");
31929
31899
  try {
31930
31900
  const db = deps.openDb();
31931
31901
  let components = [];
@@ -32012,7 +31982,7 @@ var init_save = __esm({
32012
31982
  writeFile: (path5, contents) => writeFile8(path5, contents),
32013
31983
  appendRun,
32014
31984
  buildSourceFingerprint,
32015
- sleep: (ms) => new Promise((resolve26) => setTimeout(resolve26, ms)),
31985
+ sleep: (ms) => new Promise((resolve27) => setTimeout(resolve27, ms)),
32016
31986
  warn: (message) => process.stderr.write(message)
32017
31987
  });
32018
31988
  }
@@ -32034,7 +32004,7 @@ var init_types9 = __esm({
32034
32004
  import { appendFileSync, writeFileSync } from "node:fs";
32035
32005
  import { mkdir as mkdir9 } from "node:fs/promises";
32036
32006
  import { tmpdir } from "node:os";
32037
- import { join as join26 } from "node:path";
32007
+ import { join as join27 } from "node:path";
32038
32008
  function appendWizardLog(entry) {
32039
32009
  appendFileSync(WIZARD_LOG, JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), ...entry }) + "\n");
32040
32010
  }
@@ -32063,8 +32033,7 @@ function realFlowDeps() {
32063
32033
  buildTimestampedSubdir,
32064
32034
  rejectComponentsByName,
32065
32035
  log,
32066
- stderr: (text) => process.stderr.write(text),
32067
- debug: realDebugHooks
32036
+ stderr: (text) => process.stderr.write(text)
32068
32037
  };
32069
32038
  }
32070
32039
  function initialFlowState(start) {
@@ -32208,13 +32177,6 @@ function createFlowController(start, deps) {
32208
32177
  };
32209
32178
  const proceedToWrite = async (path5) => {
32210
32179
  update({ outDir: path5 });
32211
- await deps.debug?.setOutDir(path5);
32212
- deps.debug?.start({
32213
- flow: "import",
32214
- step: "10-flow",
32215
- menuOption: "Save",
32216
- inputs: { outDir: path5, extractSessionId: state.extractSessionId, andPush: !!pendingSave.andPush }
32217
- });
32218
32180
  const { skipGate, andPush } = pendingSave;
32219
32181
  const written = await runPrintFiles(
32220
32182
  {
@@ -32229,9 +32191,6 @@ function createFlowController(start, deps) {
32229
32191
  update
32230
32192
  );
32231
32193
  update(written.patch);
32232
- await deps.debug?.finish(
32233
- written.ok ? { outputs: { componentsPath: join26(path5, "components.json") }, status: "success", exitMethod: "saved" } : { outputs: { error: written.patch.errorMessage ?? "unknown" }, status: "error", exitMethod: "discarded" }
32234
- );
32235
32194
  if (!written.ok) return;
32236
32195
  const runId = await recordRun({ state, savePath: path5 }, deps.save);
32237
32196
  if (runId) update({ lastRunId: runId });
@@ -32315,12 +32274,11 @@ var init_controller = __esm({
32315
32274
  init_slot_graph();
32316
32275
  init_cycle_detection();
32317
32276
  init_wizard_state_transitions();
32318
- init_debug_hooks();
32319
32277
  init_preview2();
32320
32278
  init_push();
32321
32279
  init_save();
32322
32280
  init_types9();
32323
- WIZARD_LOG = join26(tmpdir(), "experiences-import-wizard.log");
32281
+ WIZARD_LOG = join27(tmpdir(), "experiences-import-wizard.log");
32324
32282
  }
32325
32283
  });
32326
32284
 
@@ -32359,8 +32317,7 @@ async function readHelpInfo() {
32359
32317
  storage: [
32360
32318
  { label: "Config folder", value: configRoot2() },
32361
32319
  { label: "Settings file", value: configFilePath2() },
32362
- { label: "Debug logs", value: "<project>/.contentful/debug/sessions, next to components.json" },
32363
- { label: "No project", value: `${debugSessionsDir2()} (sessions that never pick a project)` }
32320
+ { label: "Debug logs", value: "<project>/.contentful/debug/sessions, next to components.json" }
32364
32321
  ],
32365
32322
  troubleshooting: [
32366
32323
  { label: "CLI version", value: readPackageVersion() },
@@ -32971,7 +32928,7 @@ var app_exports = {};
32971
32928
  __export(app_exports, {
32972
32929
  runApp: () => runApp
32973
32930
  });
32974
- import { join as join27 } from "node:path";
32931
+ import { join as join28 } from "node:path";
32975
32932
  import { useEffect as useEffect27, useState as useState33 } from "react";
32976
32933
  import { Fragment as Fragment19, jsx as jsx59 } from "react/jsx-runtime";
32977
32934
  function App({ importOptions, inkClear }) {
@@ -33022,7 +32979,7 @@ function App({ importOptions, inkClear }) {
33022
32979
  const launch = { projectPath: projectPath2, tokens, filePaths, ...importOptions };
33023
32980
  const state = await inspectTokens({
33024
32981
  rawTokensPath: tokens,
33025
- outDir: join27(resolveUserPath(projectPath2), ".contentful"),
32982
+ outDir: join28(resolveUserPath(projectPath2), ".contentful"),
33026
32983
  cache: importOptions.cache
33027
32984
  });
33028
32985
  if (state.kind === "cached") {
@@ -33294,7 +33251,7 @@ var init_app = __esm({
33294
33251
 
33295
33252
  // packages/experience-design-system-cli/program.ts
33296
33253
  import { readFileSync as readFileSync9 } from "node:fs";
33297
- import { join as join28 } from "node:path";
33254
+ import { join as join29 } from "node:path";
33298
33255
  import { Command } from "commander";
33299
33256
 
33300
33257
  // packages/experience-design-system-cli/src/legacy/run-legacy.ts
@@ -33398,14 +33355,14 @@ function runDevWatch(args) {
33398
33355
  process.stderr.write("--watch only works from a checkout of the repo (scripts/dev.mjs is not in the package).\n");
33399
33356
  return Promise.resolve(1);
33400
33357
  }
33401
- return new Promise((resolve26) => {
33358
+ return new Promise((resolve27) => {
33402
33359
  const child = spawn2(process.execPath, [script, ...args], { stdio: "inherit" });
33403
33360
  process.on("SIGINT", () => void 0);
33404
- child.on("exit", (code) => resolve26(code ?? 0));
33361
+ child.on("exit", (code) => resolve27(code ?? 0));
33405
33362
  child.on("error", (err) => {
33406
33363
  process.stderr.write(`${err.message}
33407
33364
  `);
33408
- resolve26(1);
33365
+ resolve27(1);
33409
33366
  });
33410
33367
  });
33411
33368
  }
@@ -33430,7 +33387,7 @@ function registerImportCommand(program, openTui) {
33430
33387
  init_package_root();
33431
33388
  var pkg = JSON.parse(
33432
33389
  readFileSync9(
33433
- join28(findPackageRoot(import.meta.url, "@contentful/experience-design-system-cli"), "package.json"),
33390
+ join29(findPackageRoot(import.meta.url, "@contentful/experience-design-system-cli"), "package.json"),
33434
33391
  "utf8"
33435
33392
  )
33436
33393
  );
@@ -33450,7 +33407,7 @@ init_config();
33450
33407
  init_package_root();
33451
33408
  import { existsSync as existsSync12 } from "node:fs";
33452
33409
  import { mkdir as mkdir10, readFile as readFile19, rename as rename4, rmdir, unlink } from "node:fs/promises";
33453
- import { dirname as dirname16, join as join29 } from "node:path";
33410
+ import { dirname as dirname16, join as join30 } from "node:path";
33454
33411
  var PACKAGE_NAME4 = "@contentful/experience-design-system-cli";
33455
33412
  async function readJson(path5) {
33456
33413
  try {
@@ -33461,9 +33418,9 @@ async function readJson(path5) {
33461
33418
  }
33462
33419
  async function migrateOldConfig() {
33463
33420
  try {
33464
- const oldCredentials = join29(oldConfigDir2(), "credentials.json");
33465
- const oldRuns = join29(oldConfigDir2(), "runs.json");
33466
- const oldDebugMode = join29(
33421
+ const oldCredentials = join30(oldConfigDir2(), "credentials.json");
33422
+ const oldRuns = join30(oldConfigDir2(), "runs.json");
33423
+ const oldDebugMode = join30(
33467
33424
  findPackageRoot(import.meta.url, PACKAGE_NAME4),
33468
33425
  ".contentful",
33469
33426
  "config",