@contentful/experience-design-system-cli 2.37.1-dev-build-1e90e088.0 → 2.37.1-dev-build-f57f8147.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({
@@ -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
  }
@@ -20301,11 +20301,34 @@ var init_shared2 = __esm({
20301
20301
  });
20302
20302
 
20303
20303
  // packages/experience-design-system-cli/src/tui/import/steps/05-token-reuse/logic.ts
20304
- import { access as access5, stat as stat4 } from "node:fs/promises";
20304
+ import { access as access5, readdir as readdir2, stat as stat4 } from "node:fs/promises";
20305
20305
  import { join as join18 } from "node:path";
20306
- async function inspectTokens({ rawTokensPath, outDir, cache }) {
20306
+ async function findLatestTokens(contentfulDir) {
20307
+ const candidates = [join18(contentfulDir, "tokens.json")];
20308
+ try {
20309
+ for (const session of await readdir2(contentfulDir, { withFileTypes: true })) {
20310
+ if (!session.isDirectory()) continue;
20311
+ for (const run of await readdir2(join18(contentfulDir, session.name), { withFileTypes: true }).catch(() => [])) {
20312
+ if (run.isDirectory() && /^dsi-import-\d+$/.test(run.name)) {
20313
+ candidates.push(join18(contentfulDir, session.name, run.name, "tokens.json"));
20314
+ }
20315
+ }
20316
+ }
20317
+ } catch {
20318
+ }
20319
+ const found = [];
20320
+ for (const path5 of candidates) {
20321
+ try {
20322
+ found.push({ path: path5, mtimeMs: (await stat4(path5)).mtimeMs });
20323
+ } catch {
20324
+ }
20325
+ }
20326
+ return found.sort((a, b) => b.mtimeMs - a.mtimeMs)[0]?.path ?? null;
20327
+ }
20328
+ async function inspectTokens({ rawTokensPath, contentfulDir, cache }) {
20307
20329
  if (!cache) return { kind: "none" };
20308
- const tokensPath = join18(outDir, "tokens.json");
20330
+ const tokensPath = await findLatestTokens(contentfulDir);
20331
+ if (!tokensPath) return { kind: "none" };
20309
20332
  try {
20310
20333
  await access5(tokensPath);
20311
20334
  } catch {
@@ -20653,7 +20676,7 @@ var init_selection2 = __esm({
20653
20676
  import { mkdir as mkdir7 } from "node:fs/promises";
20654
20677
  import { join as join21, resolve as resolve22 } from "node:path";
20655
20678
  async function runExtraction(input, onProgress, deps = realDeps) {
20656
- const outDir = join21(resolve22(input.projectPath), ".contentful");
20679
+ const outDir = input.outDir ?? join21(resolve22(input.projectPath), ".contentful");
20657
20680
  let progress = initialProgress({
20658
20681
  hasCredentials: input.credentials !== null,
20659
20682
  hasRawTokens: input.rawTokensPath !== "",
@@ -20804,203 +20827,6 @@ var init_run = __esm({
20804
20827
  }
20805
20828
  });
20806
20829
 
20807
- // packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts
20808
- async function readDebugModeSetting() {
20809
- const { debugMode } = await readSettings2();
20810
- return { ...DEFAULT_DEBUG_MODE_SETTING, ...debugMode };
20811
- }
20812
- async function writeDebugModeSetting(setting) {
20813
- await updateSettings2({ debugMode: setting });
20814
- }
20815
- var DEFAULT_DEBUG_MODE_SETTING;
20816
- var init_debug_mode_store = __esm({
20817
- "packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts"() {
20818
- "use strict";
20819
- init_config();
20820
- DEFAULT_DEBUG_MODE_SETTING = {
20821
- enabled: true
20822
- };
20823
- }
20824
- });
20825
-
20826
- // packages/experience-design-system-cli/src/tui/debug-store.ts
20827
- var debug_store_exports = {};
20828
- __export(debug_store_exports, {
20829
- currentDebugSessionDir: () => currentDebugSessionDir,
20830
- currentSessionDir: () => currentSessionDir,
20831
- finishDebugRun: () => finishDebugRun,
20832
- startDebugRun: () => startDebugRun,
20833
- startDebugSessionIn: () => startDebugSessionIn
20834
- });
20835
- import { mkdir as mkdir8, writeFile as writeFile7 } from "node:fs/promises";
20836
- import { existsSync as existsSync11, readdirSync as readdirSync3 } from "node:fs";
20837
- import { join as join22, resolve as resolve23 } from "node:path";
20838
- function generateRunId() {
20839
- const now = /* @__PURE__ */ new Date();
20840
- const pad = (n) => String(n).padStart(2, "0");
20841
- return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
20842
- }
20843
- function datePrefix(now = /* @__PURE__ */ new Date()) {
20844
- const pad = (n) => String(n).padStart(2, "0");
20845
- return `${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}`;
20846
- }
20847
- function slugify(value) {
20848
- return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
20849
- }
20850
- async function readBaseDir() {
20851
- try {
20852
- const dir = (await readSettings2())["contentfulBaseDir"];
20853
- return typeof dir === "string" && dir !== "" ? resolve23(dir) : void 0;
20854
- } catch {
20855
- return void 0;
20856
- }
20857
- }
20858
- function nextSessionId(contentfulDir) {
20859
- const today = datePrefix();
20860
- const existing = existsSync11(contentfulDir) ? readdirSync3(contentfulDir) : [];
20861
- const seqPattern = new RegExp(`^${today}-session-(\\d+)$`);
20862
- const maxSeq = existing.reduce((max, entry) => {
20863
- const match2 = seqPattern.exec(entry);
20864
- return match2 ? Math.max(max, Number(match2[1])) : max;
20865
- }, 0);
20866
- return `${today}-session-${maxSeq + 1}`;
20867
- }
20868
- function startSession(base, { replace }) {
20869
- const contentfulDir = join22(base, ".contentful");
20870
- if (replace || !sessionDir) sessionDir = join22(contentfulDir, nextSessionId(contentfulDir));
20871
- return sessionDir;
20872
- }
20873
- function currentDebugSessionDir() {
20874
- return sessionDir && join22(sessionDir, "debug");
20875
- }
20876
- function currentSessionDir() {
20877
- return sessionDir;
20878
- }
20879
- async function startDebugSessionIn(base, { replace = false } = {}) {
20880
- try {
20881
- if (!await isDebugModeEnabled()) return;
20882
- await mkdir8(join22(startSession(resolve23(base), { replace }), "debug"), { recursive: true });
20883
- } catch {
20884
- }
20885
- }
20886
- async function isDebugModeEnabled() {
20887
- try {
20888
- return (await readDebugModeSetting()).enabled;
20889
- } catch {
20890
- return true;
20891
- }
20892
- }
20893
- function redact(value) {
20894
- const clone = { ...value };
20895
- if ("cma_token" in clone) {
20896
- const raw = clone.cma_token;
20897
- clone.cma_token = typeof raw === "string" && raw.length > 0 ? `[present, ${raw.length} chars]` : "[not set]";
20898
- }
20899
- return clone;
20900
- }
20901
- function startDebugRun({
20902
- flow,
20903
- step,
20904
- menuOption,
20905
- inputs
20906
- }) {
20907
- const runId = generateRunId();
20908
- const startedAt = Date.now();
20909
- const redactedInputs = redact(inputs);
20910
- isDebugModeEnabled().then((enabled) => {
20911
- if (!enabled) return;
20912
- pendingRun = { flow, step, runId, menuOption, inputs: redactedInputs, startedAt };
20913
- });
20914
- }
20915
- async function finishDebugRun({
20916
- outputs,
20917
- status,
20918
- exitMethod
20919
- }) {
20920
- const run = pendingRun;
20921
- if (!run) return;
20922
- pendingRun = void 0;
20923
- const durationMs = Date.now() - run.startedAt;
20924
- const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
20925
- const root = currentDebugSessionDir();
20926
- if (!root) return;
20927
- const flowSegments = run.flow.split("/");
20928
- const dir = join22(root, ...flowSegments);
20929
- await mkdir8(dir, { recursive: true });
20930
- const filename = nextAttemptFilename(dir, run.menuOption);
20931
- await writeFile7(join22(dir, filename), content, { mode: 384 });
20932
- }
20933
- function nextAttemptFilename(dir, menuOption) {
20934
- const today = datePrefix();
20935
- const optionSlug = slugify(menuOption);
20936
- const existing = existsSync11(dir) ? readdirSync3(dir) : [];
20937
- const attemptPattern = new RegExp(`^${today}-${optionSlug}-attempt-(\\d+)\\.md$`);
20938
- const maxAttempt = existing.reduce((max, entry) => {
20939
- const match2 = attemptPattern.exec(entry);
20940
- return match2 ? Math.max(max, Number(match2[1])) : max;
20941
- }, 0);
20942
- return `${today}-${optionSlug}-attempt-${maxAttempt + 1}.md`;
20943
- }
20944
- function renderMarkdown(run, finish) {
20945
- const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
20946
- const stepLabel2 = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
20947
- const flowSlug = run.flow.split("/").join("-");
20948
- return `# Debug Log
20949
-
20950
- - Run ID: ${run.runId}
20951
- - Flow: ${flowSlug}
20952
- - Step: ${stepLabel2}
20953
- - Menu option: ${run.menuOption}
20954
- - Date: ${(/* @__PURE__ */ new Date()).toISOString()}
20955
- - CLI version: ${readPackageVersion()}
20956
- - Platform: ${process.platform} / Node ${process.version}
20957
- - Duration on screen: ${finish.durationMs}ms
20958
- - Status: ${finish.status}
20959
- - Exit method: ${finish.exitMethod}
20960
-
20961
- ## Inputs
20962
- \`\`\`json
20963
- ${JSON.stringify(run.inputs, null, 2)}
20964
- \`\`\`
20965
-
20966
- ## Outputs
20967
- \`\`\`json
20968
- ${JSON.stringify(finish.outputs, null, 2)}
20969
- \`\`\`
20970
- `;
20971
- }
20972
- function handleCrash() {
20973
- return finishDebugRun({ outputs: {}, status: "error", exitMethod: "crashed" });
20974
- }
20975
- var pendingRun, sessionDir;
20976
- var init_debug_store = __esm({
20977
- "packages/experience-design-system-cli/src/tui/debug-store.ts"() {
20978
- "use strict";
20979
- init_config();
20980
- init_version();
20981
- init_debug_mode_store();
20982
- void Promise.all([isDebugModeEnabled(), readBaseDir()]).then(([enabled, base]) => {
20983
- if (!enabled || !base) return void 0;
20984
- return mkdir8(join22(startSession(base, { replace: false }), "debug"), { recursive: true });
20985
- });
20986
- process.once("uncaughtException", (err) => {
20987
- void handleCrash().finally(() => {
20988
- throw err;
20989
- });
20990
- });
20991
- process.once("unhandledRejection", (reason) => {
20992
- void handleCrash().finally(() => {
20993
- throw reason;
20994
- });
20995
- });
20996
- process.once("SIGINT", () => {
20997
- void handleCrash().finally(() => {
20998
- process.exit(130);
20999
- });
21000
- });
21001
- }
21002
- });
21003
-
21004
20830
  // packages/experience-design-system-cli/src/tui/import/steps/06-extraction/use-extraction.ts
21005
20831
  import { useEffect as useEffect5, useRef as useRef2, useState as useState8 } from "react";
21006
20832
  function useExtraction(input) {
@@ -21020,7 +20846,6 @@ function useExtraction(input) {
21020
20846
  reuseTokens: input.tokenStrategy === "reuse"
21021
20847
  })
21022
20848
  });
21023
- void Promise.resolve().then(() => (init_debug_store(), debug_store_exports)).then((store) => store.startDebugSessionIn(input.projectPath));
21024
20849
  void runExtraction(input, (progress) => {
21025
20850
  if (current.current === input) setState({ status: "running", progress });
21026
20851
  }).then((result) => {
@@ -24242,7 +24067,7 @@ var init_save_decisions = __esm({
24242
24067
  });
24243
24068
 
24244
24069
  // packages/experience-design-system-cli/src/tui/import/steps/08-generation/run.ts
24245
- import { resolve as resolve24 } from "node:path";
24070
+ import { resolve as resolve23 } from "node:path";
24246
24071
  async function runGeneration(input, onProgress, deps = realDeps3) {
24247
24072
  let progress = { components: null, mapTokens: "idle", mapTokensEligible: null };
24248
24073
  const update = (change) => {
@@ -24328,7 +24153,7 @@ async function buildMapTokensOptions(input) {
24328
24153
  if (mapOverride?.kind === "text") prompt.skillContentOverride = mapOverride.value;
24329
24154
  if (mapOverride?.kind === "path") {
24330
24155
  await resolvePromptOverride(mapOverride);
24331
- prompt.skillPathOverride = resolve24(mapOverride.value);
24156
+ prompt.skillPathOverride = resolve23(mapOverride.value);
24332
24157
  }
24333
24158
  if (input.existingEntitiesPath) {
24334
24159
  const entities = await readExistingContentfulEntitiesFromSession({ path: input.existingEntitiesPath });
@@ -24406,7 +24231,7 @@ var init_use_generation = __esm({
24406
24231
  });
24407
24232
 
24408
24233
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/build-flow-start.ts
24409
- import { join as join23 } from "node:path";
24234
+ import { join as join22 } from "node:path";
24410
24235
  function buildFlowStart(input) {
24411
24236
  const { extraction, handoff, saved, generatePromptPath } = input;
24412
24237
  const credentials = extraction.credentials ?? {
@@ -24419,7 +24244,7 @@ function buildFlowStart(input) {
24419
24244
  handoff,
24420
24245
  agent: extraction.agent,
24421
24246
  projectPath: extraction.projectPath,
24422
- outDir: extraction.projectPath ? join23(extraction.projectPath, ".contentful") : "",
24247
+ outDir: extraction.projectPath ? join22(extraction.projectPath, ".contentful") : "",
24423
24248
  rawTokensPath: extraction.rawTokensPath,
24424
24249
  credentials: {
24425
24250
  spaceId: credentials.spaceId,
@@ -30615,7 +30440,7 @@ var init_DoneStep = __esm({
30615
30440
  });
30616
30441
 
30617
30442
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/support/path-utils.ts
30618
- import { resolve as resolve25 } from "node:path";
30443
+ import { resolve as resolve24 } from "node:path";
30619
30444
  import { homedir as homedir4 } from "node:os";
30620
30445
  function expandTilde(input) {
30621
30446
  if (input === "~" || input.startsWith("~/") || input.startsWith("~\\")) {
@@ -30629,7 +30454,7 @@ function normalizePath(input) {
30629
30454
  p = p.slice(1, -1);
30630
30455
  }
30631
30456
  p = expandTilde(p);
30632
- return resolve25(p);
30457
+ return resolve24(p);
30633
30458
  }
30634
30459
  var init_path_utils = __esm({
30635
30460
  "packages/experience-design-system-cli/src/tui/import/steps/10-flow/support/path-utils.ts"() {
@@ -30656,8 +30481,8 @@ var init_use_blinking_cursor = __esm({
30656
30481
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/screens/PathPrompt.tsx
30657
30482
  import { useState as useState24 } from "react";
30658
30483
  import { Box as Box37, Text as Text40 } from "ink";
30659
- import { readdirSync as readdirSync4 } from "node:fs";
30660
- import { dirname as dirname15, basename as basename6, join as join24 } from "node:path";
30484
+ import { readdirSync as readdirSync3 } from "node:fs";
30485
+ import { dirname as dirname15, basename as basename6, join as join23 } from "node:path";
30661
30486
  import { jsx as jsx47, jsxs as jsxs38 } from "react/jsx-runtime";
30662
30487
  function autocomplete(partial) {
30663
30488
  if (!partial) return null;
@@ -30666,19 +30491,19 @@ function autocomplete(partial) {
30666
30491
  const base = basename6(normalized);
30667
30492
  let entries;
30668
30493
  try {
30669
- entries = readdirSync4(dir);
30494
+ entries = readdirSync3(dir);
30670
30495
  } catch {
30671
30496
  return null;
30672
30497
  }
30673
30498
  const matches = entries.filter((e) => e.startsWith(base));
30674
30499
  if (matches.length === 0) return null;
30675
- if (matches.length === 1) return join24(dir, matches[0]);
30500
+ if (matches.length === 1) return join23(dir, matches[0]);
30676
30501
  let prefix = matches[0];
30677
30502
  for (const m of matches) {
30678
30503
  while (!m.startsWith(prefix)) prefix = prefix.slice(0, -1);
30679
30504
  if (!prefix) break;
30680
30505
  }
30681
- return prefix.length > base.length ? join24(dir, prefix) : null;
30506
+ return prefix.length > base.length ? join23(dir, prefix) : null;
30682
30507
  }
30683
30508
  function PathPrompt({
30684
30509
  defaultPath,
@@ -31881,8 +31706,8 @@ var init_run_print_files_helpers = __esm({
31881
31706
  });
31882
31707
 
31883
31708
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/save.ts
31884
- import { writeFile as writeFile8 } from "node:fs/promises";
31885
- import { join as join25 } from "node:path";
31709
+ import { writeFile as writeFile7 } from "node:fs/promises";
31710
+ import { join as join24 } from "node:path";
31886
31711
  function buildSavedCDF(components, tokens, opts = {}) {
31887
31712
  const cdf = buildCDF2(components, toCdfTokens(tokens), opts);
31888
31713
  if (!cdf) throw new Error("nothing to save \u2014 no components or tokens resolved");
@@ -31894,7 +31719,7 @@ function buildSavedCDF(components, tokens, opts = {}) {
31894
31719
  }
31895
31720
  async function runPrintFiles(input, deps, onPatch) {
31896
31721
  onPatch({ step: "printing" });
31897
- const componentsPath = join25(input.outDir, "components.json");
31722
+ const componentsPath = join24(input.outDir, "components.json");
31898
31723
  try {
31899
31724
  const db = deps.openDb();
31900
31725
  let components = [];
@@ -31978,10 +31803,10 @@ var init_save = __esm({
31978
31803
  realSaveDeps = () => ({
31979
31804
  openDb: openPipelineDb,
31980
31805
  readTokens: (path5) => readTokensFromPath2({ flag: "tokens", path: path5 }),
31981
- writeFile: (path5, contents) => writeFile8(path5, contents),
31806
+ writeFile: (path5, contents) => writeFile7(path5, contents),
31982
31807
  appendRun,
31983
31808
  buildSourceFingerprint,
31984
- sleep: (ms) => new Promise((resolve26) => setTimeout(resolve26, ms)),
31809
+ sleep: (ms) => new Promise((resolve27) => setTimeout(resolve27, ms)),
31985
31810
  warn: (message) => process.stderr.write(message)
31986
31811
  });
31987
31812
  }
@@ -32001,9 +31826,9 @@ var init_types9 = __esm({
32001
31826
 
32002
31827
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/controller.ts
32003
31828
  import { appendFileSync, writeFileSync } from "node:fs";
32004
- import { mkdir as mkdir9 } from "node:fs/promises";
31829
+ import { mkdir as mkdir8 } from "node:fs/promises";
32005
31830
  import { tmpdir } from "node:os";
32006
- import { join as join26 } from "node:path";
31831
+ import { join as join25, resolve as resolve25 } from "node:path";
32007
31832
  function appendWizardLog(entry) {
32008
31833
  appendFileSync(WIZARD_LOG, JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), ...entry }) + "\n");
32009
31834
  }
@@ -32011,9 +31836,6 @@ function startWizardLog() {
32011
31836
  writeFileSync(WIZARD_LOG, `--- experiences import session ${(/* @__PURE__ */ new Date()).toISOString()} ---
32012
31837
  `);
32013
31838
  }
32014
- async function realSessionDir() {
32015
- return (await Promise.resolve().then(() => (init_debug_store(), debug_store_exports))).currentSessionDir();
32016
- }
32017
31839
  function realFlowDeps() {
32018
31840
  const log = (entry) => appendWizardLog(entry);
32019
31841
  return {
@@ -32029,14 +31851,13 @@ function realFlowDeps() {
32029
31851
  }
32030
31852
  },
32031
31853
  mkdir: async (path5) => {
32032
- await mkdir9(path5, { recursive: true });
31854
+ await mkdir8(path5, { recursive: true });
32033
31855
  },
32034
31856
  detectSaveConflict,
32035
31857
  buildTimestampedSubdir,
32036
31858
  rejectComponentsByName,
32037
31859
  log,
32038
- stderr: (text) => process.stderr.write(text),
32039
- sessionDir: realSessionDir
31860
+ stderr: (text) => process.stderr.write(text)
32040
31861
  };
32041
31862
  }
32042
31863
  function initialFlowState(start) {
@@ -32177,9 +31998,6 @@ function createFlowController(start, deps) {
32177
31998
  const startSave = (opts, patch = {}) => {
32178
31999
  pendingSave = opts;
32179
32000
  update({ ...patch, step: "path-prompt" });
32180
- void deps.sessionDir?.().then((session) => {
32181
- if (session && state.step === "path-prompt") update({ outDir: join26(session, "dsi-import") });
32182
- });
32183
32001
  };
32184
32002
  const proceedToWrite = async (path5) => {
32185
32003
  update({ outDir: path5 });
@@ -32252,7 +32070,7 @@ function createFlowController(start, deps) {
32252
32070
  },
32253
32071
  async submitPath(submitted) {
32254
32072
  await deps.mkdir(submitted);
32255
- if (await deps.detectSaveConflict(submitted)) {
32073
+ if (resolve25(submitted) !== resolve25(state.outDir) && await deps.detectSaveConflict(submitted)) {
32256
32074
  const subdir = deps.buildTimestampedSubdir(submitted);
32257
32075
  await deps.mkdir(subdir);
32258
32076
  await proceedToWrite(subdir);
@@ -32284,7 +32102,7 @@ var init_controller = __esm({
32284
32102
  init_push();
32285
32103
  init_save();
32286
32104
  init_types9();
32287
- WIZARD_LOG = join26(tmpdir(), "experiences-import-wizard.log");
32105
+ WIZARD_LOG = join25(tmpdir(), "experiences-import-wizard.log");
32288
32106
  }
32289
32107
  });
32290
32108
 
@@ -32316,6 +32134,219 @@ var init_use_flow = __esm({
32316
32134
  }
32317
32135
  });
32318
32136
 
32137
+ // packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts
32138
+ async function readDebugModeSetting() {
32139
+ const { debugMode } = await readSettings2();
32140
+ return { ...DEFAULT_DEBUG_MODE_SETTING, ...debugMode };
32141
+ }
32142
+ async function writeDebugModeSetting(setting) {
32143
+ await updateSettings2({ debugMode: setting });
32144
+ }
32145
+ var DEFAULT_DEBUG_MODE_SETTING;
32146
+ var init_debug_mode_store = __esm({
32147
+ "packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts"() {
32148
+ "use strict";
32149
+ init_config();
32150
+ DEFAULT_DEBUG_MODE_SETTING = {
32151
+ enabled: true
32152
+ };
32153
+ }
32154
+ });
32155
+
32156
+ // packages/experience-design-system-cli/src/tui/debug-store.ts
32157
+ var debug_store_exports = {};
32158
+ __export(debug_store_exports, {
32159
+ currentDebugSessionDir: () => currentDebugSessionDir,
32160
+ currentSessionDir: () => currentSessionDir,
32161
+ finishDebugRun: () => finishDebugRun,
32162
+ startDebugRun: () => startDebugRun,
32163
+ startDebugSessionIn: () => startDebugSessionIn,
32164
+ startImportRun: () => startImportRun
32165
+ });
32166
+ import { mkdir as mkdir9, writeFile as writeFile8 } from "node:fs/promises";
32167
+ import { existsSync as existsSync11, readdirSync as readdirSync4 } from "node:fs";
32168
+ import { join as join26, resolve as resolve26 } from "node:path";
32169
+ function generateRunId() {
32170
+ const now = /* @__PURE__ */ new Date();
32171
+ const pad = (n) => String(n).padStart(2, "0");
32172
+ return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
32173
+ }
32174
+ function datePrefix(now = /* @__PURE__ */ new Date()) {
32175
+ const pad = (n) => String(n).padStart(2, "0");
32176
+ return `${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}`;
32177
+ }
32178
+ function slugify(value) {
32179
+ return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
32180
+ }
32181
+ async function readBaseDir() {
32182
+ try {
32183
+ const dir = (await readSettings2())["contentfulBaseDir"];
32184
+ return typeof dir === "string" && dir !== "" ? resolve26(dir) : void 0;
32185
+ } catch {
32186
+ return void 0;
32187
+ }
32188
+ }
32189
+ function nextSessionId(contentfulDir) {
32190
+ const today = datePrefix();
32191
+ const existing = existsSync11(contentfulDir) ? readdirSync4(contentfulDir) : [];
32192
+ const seqPattern = new RegExp(`^${today}-session-(\\d+)$`);
32193
+ const maxSeq = existing.reduce((max, entry) => {
32194
+ const match2 = seqPattern.exec(entry);
32195
+ return match2 ? Math.max(max, Number(match2[1])) : max;
32196
+ }, 0);
32197
+ return `${today}-session-${maxSeq + 1}`;
32198
+ }
32199
+ function startSession(base, { replace }) {
32200
+ const contentfulDir = join26(base, ".contentful");
32201
+ if (replace || !sessionDir) sessionDir = join26(contentfulDir, nextSessionId(contentfulDir));
32202
+ return sessionDir;
32203
+ }
32204
+ function currentDebugSessionDir() {
32205
+ return sessionDir && join26(sessionDir, "debug");
32206
+ }
32207
+ function currentSessionDir() {
32208
+ return sessionDir;
32209
+ }
32210
+ async function startDebugSessionIn(base, { replace = false } = {}) {
32211
+ try {
32212
+ if (!await isDebugModeEnabled()) return;
32213
+ await mkdir9(join26(startSession(resolve26(base), { replace }), "debug"), { recursive: true });
32214
+ } catch {
32215
+ }
32216
+ }
32217
+ function nextImportRunDir(session) {
32218
+ const existing = existsSync11(session) ? readdirSync4(session) : [];
32219
+ const maxRun = existing.reduce((max, entry) => {
32220
+ const match2 = /^dsi-import-(\d+)$/.exec(entry);
32221
+ return match2 ? Math.max(max, Number(match2[1])) : max;
32222
+ }, 0);
32223
+ return join26(session, `dsi-import-${maxRun + 1}`);
32224
+ }
32225
+ async function startImportRun(projectPath) {
32226
+ await startDebugSessionIn(projectPath);
32227
+ if (!sessionDir) return join26(resolve26(projectPath), ".contentful");
32228
+ const dir = nextImportRunDir(sessionDir);
32229
+ await mkdir9(dir, { recursive: true });
32230
+ return dir;
32231
+ }
32232
+ async function isDebugModeEnabled() {
32233
+ try {
32234
+ return (await readDebugModeSetting()).enabled;
32235
+ } catch {
32236
+ return true;
32237
+ }
32238
+ }
32239
+ function redact(value) {
32240
+ const clone = { ...value };
32241
+ if ("cma_token" in clone) {
32242
+ const raw = clone.cma_token;
32243
+ clone.cma_token = typeof raw === "string" && raw.length > 0 ? `[present, ${raw.length} chars]` : "[not set]";
32244
+ }
32245
+ return clone;
32246
+ }
32247
+ function startDebugRun({
32248
+ flow,
32249
+ step,
32250
+ menuOption,
32251
+ inputs
32252
+ }) {
32253
+ const runId = generateRunId();
32254
+ const startedAt = Date.now();
32255
+ const redactedInputs = redact(inputs);
32256
+ isDebugModeEnabled().then((enabled) => {
32257
+ if (!enabled) return;
32258
+ pendingRun = { flow, step, runId, menuOption, inputs: redactedInputs, startedAt };
32259
+ });
32260
+ }
32261
+ async function finishDebugRun({
32262
+ outputs,
32263
+ status,
32264
+ exitMethod
32265
+ }) {
32266
+ const run = pendingRun;
32267
+ if (!run) return;
32268
+ pendingRun = void 0;
32269
+ const durationMs = Date.now() - run.startedAt;
32270
+ const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
32271
+ const root = currentDebugSessionDir();
32272
+ if (!root) return;
32273
+ const flowSegments = run.flow.split("/");
32274
+ const dir = join26(root, ...flowSegments);
32275
+ await mkdir9(dir, { recursive: true });
32276
+ const filename = nextAttemptFilename(dir, run.menuOption);
32277
+ await writeFile8(join26(dir, filename), content, { mode: 384 });
32278
+ }
32279
+ function nextAttemptFilename(dir, menuOption) {
32280
+ const today = datePrefix();
32281
+ const optionSlug = slugify(menuOption);
32282
+ const existing = existsSync11(dir) ? readdirSync4(dir) : [];
32283
+ const attemptPattern = new RegExp(`^${today}-${optionSlug}-attempt-(\\d+)\\.md$`);
32284
+ const maxAttempt = existing.reduce((max, entry) => {
32285
+ const match2 = attemptPattern.exec(entry);
32286
+ return match2 ? Math.max(max, Number(match2[1])) : max;
32287
+ }, 0);
32288
+ return `${today}-${optionSlug}-attempt-${maxAttempt + 1}.md`;
32289
+ }
32290
+ function renderMarkdown(run, finish) {
32291
+ const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
32292
+ const stepLabel2 = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
32293
+ const flowSlug = run.flow.split("/").join("-");
32294
+ return `# Debug Log
32295
+
32296
+ - Run ID: ${run.runId}
32297
+ - Flow: ${flowSlug}
32298
+ - Step: ${stepLabel2}
32299
+ - Menu option: ${run.menuOption}
32300
+ - Date: ${(/* @__PURE__ */ new Date()).toISOString()}
32301
+ - CLI version: ${readPackageVersion()}
32302
+ - Platform: ${process.platform} / Node ${process.version}
32303
+ - Duration on screen: ${finish.durationMs}ms
32304
+ - Status: ${finish.status}
32305
+ - Exit method: ${finish.exitMethod}
32306
+
32307
+ ## Inputs
32308
+ \`\`\`json
32309
+ ${JSON.stringify(run.inputs, null, 2)}
32310
+ \`\`\`
32311
+
32312
+ ## Outputs
32313
+ \`\`\`json
32314
+ ${JSON.stringify(finish.outputs, null, 2)}
32315
+ \`\`\`
32316
+ `;
32317
+ }
32318
+ function handleCrash() {
32319
+ return finishDebugRun({ outputs: {}, status: "error", exitMethod: "crashed" });
32320
+ }
32321
+ var pendingRun, sessionDir;
32322
+ var init_debug_store = __esm({
32323
+ "packages/experience-design-system-cli/src/tui/debug-store.ts"() {
32324
+ "use strict";
32325
+ init_config();
32326
+ init_version();
32327
+ init_debug_mode_store();
32328
+ void Promise.all([isDebugModeEnabled(), readBaseDir()]).then(([enabled, base]) => {
32329
+ if (!enabled || !base) return void 0;
32330
+ return mkdir9(join26(startSession(base, { replace: false }), "debug"), { recursive: true });
32331
+ });
32332
+ process.once("uncaughtException", (err) => {
32333
+ void handleCrash().finally(() => {
32334
+ throw err;
32335
+ });
32336
+ });
32337
+ process.once("unhandledRejection", (reason) => {
32338
+ void handleCrash().finally(() => {
32339
+ throw reason;
32340
+ });
32341
+ });
32342
+ process.once("SIGINT", () => {
32343
+ void handleCrash().finally(() => {
32344
+ process.exit(130);
32345
+ });
32346
+ });
32347
+ }
32348
+ });
32349
+
32319
32350
  // packages/experience-design-system-cli/src/tui/help/help-info.ts
32320
32351
  async function readHelpInfo() {
32321
32352
  const debugMode = await readDebugModeSetting();
@@ -32627,10 +32658,7 @@ function ConfigurationScreen({ onDone }) {
32627
32658
  const display = field === "cmaToken" ? "\u2022".repeat(value.length) : value;
32628
32659
  return /* @__PURE__ */ jsxs45(Box44, { gap: 1, children: [
32629
32660
  /* @__PURE__ */ jsx55(Text46, { color: isActive ? PALETTE.accent : void 0, children: isActive ? "\u276F" : " " }),
32630
- /* @__PURE__ */ jsxs45(Text46, { bold: isActive, children: [
32631
- FIELD_LABELS[field],
32632
- ":"
32633
- ] }),
32661
+ /* @__PURE__ */ jsx55(Box44, { width: LABEL_WIDTH, flexShrink: 0, children: /* @__PURE__ */ jsx55(Text46, { bold: isActive, color: isActive ? PALETTE.accent : PALETTE.muted, children: FIELD_LABELS[field] }) }),
32634
32662
  isActive && editing ? /* @__PURE__ */ jsx55(
32635
32663
  TextInput4,
32636
32664
  {
@@ -32639,7 +32667,8 @@ function ConfigurationScreen({ onDone }) {
32639
32667
  onSubmit: () => setEditing(false),
32640
32668
  mask: field === "cmaToken" ? "\u2022" : void 0
32641
32669
  }
32642
- ) : /* @__PURE__ */ jsx55(Text46, { children: display || /* @__PURE__ */ jsx55(Text46, { color: PALETTE.muted, children: "(empty)" }) })
32670
+ ) : /* @__PURE__ */ jsx55(Text46, { bold: !!display, children: display || (FIELD_HINTS[field] ? "" : /* @__PURE__ */ jsx55(Text46, { color: PALETTE.muted, children: "(empty)" })) }),
32671
+ FIELD_HINTS[field] && /* @__PURE__ */ jsx55(Text46, { color: PALETTE.muted, children: FIELD_HINTS[field] })
32643
32672
  ] }, field);
32644
32673
  }) }),
32645
32674
  notice && /* @__PURE__ */ jsxs45(Fragment17, { children: [
@@ -32670,7 +32699,7 @@ function ConfigurationScreen({ onDone }) {
32670
32699
  )
32671
32700
  ] });
32672
32701
  }
32673
- var FIELD_ORDER, FIELD_LABELS;
32702
+ var FIELD_ORDER, FIELD_LABELS, FIELD_HINTS, LABEL_WIDTH;
32674
32703
  var init_ContentfulConfigScreen = __esm({
32675
32704
  "packages/experience-design-system-cli/src/tui/settings/contentful-configuration/ContentfulConfigScreen.tsx"() {
32676
32705
  "use strict";
@@ -32694,8 +32723,12 @@ var init_ContentfulConfigScreen = __esm({
32694
32723
  host: "API Host",
32695
32724
  defaultComponentDir: "Default component directory",
32696
32725
  defaultTokenFile: "Default token file",
32697
- contentfulBaseDir: "Root Project Directory (where .contentful goes)"
32726
+ contentfulBaseDir: "Root Project Directory"
32727
+ };
32728
+ FIELD_HINTS = {
32729
+ contentfulBaseDir: "(where .contentful goes)"
32698
32730
  };
32731
+ LABEL_WIDTH = Math.max(...Object.values(FIELD_LABELS).map((label) => label.length));
32699
32732
  }
32700
32733
  });
32701
32734
 
@@ -32989,7 +33022,7 @@ function App({ importOptions, inkClear }) {
32989
33022
  const launch = { projectPath: projectPath2, tokens, filePaths, ...importOptions };
32990
33023
  const state = await inspectTokens({
32991
33024
  rawTokensPath: tokens,
32992
- outDir: join27(resolveUserPath(projectPath2), ".contentful"),
33025
+ contentfulDir: join27(resolveUserPath(projectPath2), ".contentful"),
32993
33026
  cache: importOptions.cache
32994
33027
  });
32995
33028
  if (state.kind === "cached") {
@@ -33010,6 +33043,7 @@ function App({ importOptions, inkClear }) {
33010
33043
  const settings = await readSettings2();
33011
33044
  const { agent, agentModel } = resolveAgentChoice(launch.agent, settings);
33012
33045
  const generatePromptPath = typeof settings.generatePromptPath === "string" ? settings.generatePromptPath : void 0;
33046
+ const outDir = await (await Promise.resolve().then(() => (init_debug_store(), debug_store_exports))).startImportRun(resolveUserPath(launch.projectPath ?? ""));
33013
33047
  setExtractionRun({
33014
33048
  ...generatePromptPath ? { generatePromptPath } : {},
33015
33049
  // the later steps get the same agent, so they use what the stage used
@@ -33018,6 +33052,7 @@ function App({ importOptions, inkClear }) {
33018
33052
  tokenStrategy,
33019
33053
  input: {
33020
33054
  projectPath: resolveUserPath(launch.projectPath ?? ""),
33055
+ outDir,
33021
33056
  filePaths: launch.filePaths ?? [],
33022
33057
  rawTokensPath: launch.tokens ?? "",
33023
33058
  tokenStrategy,
@@ -33365,14 +33400,14 @@ function runDevWatch(args) {
33365
33400
  process.stderr.write("--watch only works from a checkout of the repo (scripts/dev.mjs is not in the package).\n");
33366
33401
  return Promise.resolve(1);
33367
33402
  }
33368
- return new Promise((resolve26) => {
33403
+ return new Promise((resolve27) => {
33369
33404
  const child = spawn2(process.execPath, [script, ...args], { stdio: "inherit" });
33370
33405
  process.on("SIGINT", () => void 0);
33371
- child.on("exit", (code) => resolve26(code ?? 0));
33406
+ child.on("exit", (code) => resolve27(code ?? 0));
33372
33407
  child.on("error", (err) => {
33373
33408
  process.stderr.write(`${err.message}
33374
33409
  `);
33375
- resolve26(1);
33410
+ resolve27(1);
33376
33411
  });
33377
33412
  });
33378
33413
  }