@contentful/experience-design-system-cli 2.37.1-dev-build-2fb4dadf.0 → 2.37.1-dev-build-36f90a5a.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((resolve25) => {
2124
+ return new Promise((resolve26) => {
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
- resolve25(result);
2173
+ resolve26(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((resolve25) => {
2195
+ return new Promise((resolve26) => {
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
- resolve25("unauthenticated");
2204
+ resolve26("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
- resolve25("unauthenticated");
2215
+ resolve26("unauthenticated");
2216
2216
  return;
2217
2217
  }
2218
2218
  try {
2219
2219
  const status = JSON.parse(stdout);
2220
- resolve25(status.loggedIn ? "ok" : "unauthenticated");
2220
+ resolve26(status.loggedIn ? "ok" : "unauthenticated");
2221
2221
  } catch {
2222
- resolve25("unauthenticated");
2222
+ resolve26("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((resolve25) => {
2232
+ return new Promise((resolve26) => {
2233
2233
  const child = spawn4(process.platform === "win32" ? "where" : "which", [binary], { stdio: "ignore" });
2234
- child.on("close", (code) => resolve25(code === 0));
2234
+ child.on("close", (code) => resolve26(code === 0));
2235
2235
  });
2236
2236
  }
2237
2237
  var init_check_agent_auth = __esm({
@@ -13144,11 +13144,11 @@ var init_load_and_validate_for_review = __esm({
13144
13144
  // packages/experience-design-system-backend-pipeline/dist/src/persistence/src/review-session/repositories/review-session-paths.js
13145
13145
  import { resolve as resolve15 } from "node:path";
13146
13146
  async function getRefineSessionPaths(sessionId, artifactsRoot) {
13147
- const sessionDir = resolve15(artifactsRoot, sessionId);
13147
+ const sessionDir2 = resolve15(artifactsRoot, sessionId);
13148
13148
  return {
13149
- sessionDir,
13150
- eventsPath: resolve15(sessionDir, "events.jsonl"),
13151
- statePath: resolve15(sessionDir, "current-review-state.json")
13149
+ sessionDir: sessionDir2,
13150
+ eventsPath: resolve15(sessionDir2, "events.jsonl"),
13151
+ statePath: resolve15(sessionDir2, "current-review-state.json")
13152
13152
  };
13153
13153
  }
13154
13154
  var init_review_session_paths = __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((resolve25) => setTimeout(resolve25, delayMs));
14904
+ return new Promise((resolve26) => setTimeout(resolve26, 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((resolve25) => setTimeout(resolve25, baseDelay + jitter));
15180
+ await new Promise((resolve26) => setTimeout(resolve26, 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((resolve25) => setTimeout(resolve25, Math.min(250 * attempt, 2e3)));
18737
+ await new Promise((resolve26) => setTimeout(resolve26, Math.min(250 * attempt, 2e3)));
18738
18738
  }
18739
18739
  }
18740
18740
  }
@@ -20520,13 +20520,12 @@ async function writeSettings2(settings) {
20520
20520
  async function updateSettings2(patch) {
20521
20521
  await writeSettings2({ ...await readSettings2(), ...patch });
20522
20522
  }
20523
- var configFilePath2, runsFilePath2, debugSessionsDir2, oldConfigDir2;
20523
+ var configFilePath2, runsFilePath2, oldConfigDir2;
20524
20524
  var init_config = __esm({
20525
20525
  "packages/experience-design-system-types/dist/src/config/index.js"() {
20526
20526
  "use strict";
20527
20527
  configFilePath2 = () => join19(configRoot2(), "config.json");
20528
20528
  runsFilePath2 = () => join19(configRoot2(), "state", "runs.json");
20529
- debugSessionsDir2 = () => join19(configRoot2(), "debug", "sessions");
20530
20529
  oldConfigDir2 = () => join19(homedir3(), ".config", "experiences");
20531
20530
  }
20532
20531
  });
@@ -20805,6 +20804,199 @@ var init_run = __esm({
20805
20804
  }
20806
20805
  });
20807
20806
 
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
+ finishDebugRun: () => finishDebugRun,
20831
+ startDebugRun: () => startDebugRun,
20832
+ startDebugSessionIn: () => startDebugSessionIn
20833
+ });
20834
+ import { mkdir as mkdir8, writeFile as writeFile7 } from "node:fs/promises";
20835
+ import { existsSync as existsSync11, readdirSync as readdirSync3 } from "node:fs";
20836
+ import { join as join22, resolve as resolve23 } from "node:path";
20837
+ function generateRunId() {
20838
+ const now = /* @__PURE__ */ new Date();
20839
+ const pad = (n) => String(n).padStart(2, "0");
20840
+ return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
20841
+ }
20842
+ function datePrefix(now = /* @__PURE__ */ new Date()) {
20843
+ const pad = (n) => String(n).padStart(2, "0");
20844
+ return `${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}`;
20845
+ }
20846
+ function slugify(value) {
20847
+ return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
20848
+ }
20849
+ async function readBaseDir() {
20850
+ try {
20851
+ const dir = (await readSettings2())["contentfulBaseDir"];
20852
+ return typeof dir === "string" && dir !== "" ? resolve23(dir) : void 0;
20853
+ } catch {
20854
+ return void 0;
20855
+ }
20856
+ }
20857
+ function nextSessionId(contentfulDir) {
20858
+ const today = datePrefix();
20859
+ const existing = existsSync11(contentfulDir) ? readdirSync3(contentfulDir) : [];
20860
+ const seqPattern = new RegExp(`^${today}-session-(\\d+)$`);
20861
+ const maxSeq = existing.reduce((max, entry) => {
20862
+ const match2 = seqPattern.exec(entry);
20863
+ return match2 ? Math.max(max, Number(match2[1])) : max;
20864
+ }, 0);
20865
+ return `${today}-session-${maxSeq + 1}`;
20866
+ }
20867
+ function startSession(base) {
20868
+ const contentfulDir = join22(base, ".contentful");
20869
+ sessionDir ??= join22(contentfulDir, nextSessionId(contentfulDir));
20870
+ return sessionDir;
20871
+ }
20872
+ function currentDebugSessionDir() {
20873
+ return sessionDir && join22(sessionDir, "debug");
20874
+ }
20875
+ async function startDebugSessionIn(base) {
20876
+ try {
20877
+ if (!await isDebugModeEnabled()) return;
20878
+ await mkdir8(join22(startSession(resolve23(base)), "debug"), { recursive: true });
20879
+ } catch {
20880
+ }
20881
+ }
20882
+ async function isDebugModeEnabled() {
20883
+ try {
20884
+ return (await readDebugModeSetting()).enabled;
20885
+ } catch {
20886
+ return true;
20887
+ }
20888
+ }
20889
+ function redact(value) {
20890
+ const clone = { ...value };
20891
+ if ("cma_token" in clone) {
20892
+ const raw = clone.cma_token;
20893
+ clone.cma_token = typeof raw === "string" && raw.length > 0 ? `[present, ${raw.length} chars]` : "[not set]";
20894
+ }
20895
+ return clone;
20896
+ }
20897
+ function startDebugRun({
20898
+ flow,
20899
+ step,
20900
+ menuOption,
20901
+ inputs
20902
+ }) {
20903
+ const runId = generateRunId();
20904
+ const startedAt = Date.now();
20905
+ const redactedInputs = redact(inputs);
20906
+ isDebugModeEnabled().then((enabled) => {
20907
+ if (!enabled) return;
20908
+ pendingRun = { flow, step, runId, menuOption, inputs: redactedInputs, startedAt };
20909
+ });
20910
+ }
20911
+ async function finishDebugRun({
20912
+ outputs,
20913
+ status,
20914
+ exitMethod
20915
+ }) {
20916
+ const run = pendingRun;
20917
+ if (!run) return;
20918
+ pendingRun = void 0;
20919
+ const durationMs = Date.now() - run.startedAt;
20920
+ const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
20921
+ const root = currentDebugSessionDir();
20922
+ if (!root) return;
20923
+ const flowSegments = run.flow.split("/");
20924
+ const dir = join22(root, ...flowSegments);
20925
+ await mkdir8(dir, { recursive: true });
20926
+ const filename = nextAttemptFilename(dir, run.menuOption);
20927
+ await writeFile7(join22(dir, filename), content, { mode: 384 });
20928
+ }
20929
+ function nextAttemptFilename(dir, menuOption) {
20930
+ const today = datePrefix();
20931
+ const optionSlug = slugify(menuOption);
20932
+ const existing = existsSync11(dir) ? readdirSync3(dir) : [];
20933
+ const attemptPattern = new RegExp(`^${today}-${optionSlug}-attempt-(\\d+)\\.md$`);
20934
+ const maxAttempt = existing.reduce((max, entry) => {
20935
+ const match2 = attemptPattern.exec(entry);
20936
+ return match2 ? Math.max(max, Number(match2[1])) : max;
20937
+ }, 0);
20938
+ return `${today}-${optionSlug}-attempt-${maxAttempt + 1}.md`;
20939
+ }
20940
+ function renderMarkdown(run, finish) {
20941
+ const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
20942
+ const stepLabel2 = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
20943
+ const flowSlug = run.flow.split("/").join("-");
20944
+ return `# Debug Log
20945
+
20946
+ - Run ID: ${run.runId}
20947
+ - Flow: ${flowSlug}
20948
+ - Step: ${stepLabel2}
20949
+ - Menu option: ${run.menuOption}
20950
+ - Date: ${(/* @__PURE__ */ new Date()).toISOString()}
20951
+ - CLI version: ${readPackageVersion()}
20952
+ - Platform: ${process.platform} / Node ${process.version}
20953
+ - Duration on screen: ${finish.durationMs}ms
20954
+ - Status: ${finish.status}
20955
+ - Exit method: ${finish.exitMethod}
20956
+
20957
+ ## Inputs
20958
+ \`\`\`json
20959
+ ${JSON.stringify(run.inputs, null, 2)}
20960
+ \`\`\`
20961
+
20962
+ ## Outputs
20963
+ \`\`\`json
20964
+ ${JSON.stringify(finish.outputs, null, 2)}
20965
+ \`\`\`
20966
+ `;
20967
+ }
20968
+ function handleCrash() {
20969
+ return finishDebugRun({ outputs: {}, status: "error", exitMethod: "crashed" });
20970
+ }
20971
+ var pendingRun, sessionDir;
20972
+ var init_debug_store = __esm({
20973
+ "packages/experience-design-system-cli/src/tui/debug-store.ts"() {
20974
+ "use strict";
20975
+ init_config();
20976
+ init_version();
20977
+ init_debug_mode_store();
20978
+ void Promise.all([isDebugModeEnabled(), readBaseDir()]).then(([enabled, base]) => {
20979
+ if (!enabled || !base) return void 0;
20980
+ return mkdir8(join22(startSession(base), "debug"), { recursive: true });
20981
+ });
20982
+ process.once("uncaughtException", (err) => {
20983
+ void handleCrash().finally(() => {
20984
+ throw err;
20985
+ });
20986
+ });
20987
+ process.once("unhandledRejection", (reason) => {
20988
+ void handleCrash().finally(() => {
20989
+ throw reason;
20990
+ });
20991
+ });
20992
+ process.once("SIGINT", () => {
20993
+ void handleCrash().finally(() => {
20994
+ process.exit(130);
20995
+ });
20996
+ });
20997
+ }
20998
+ });
20999
+
20808
21000
  // packages/experience-design-system-cli/src/tui/import/steps/06-extraction/use-extraction.ts
20809
21001
  import { useEffect as useEffect5, useRef as useRef2, useState as useState8 } from "react";
20810
21002
  function useExtraction(input) {
@@ -20824,6 +21016,7 @@ function useExtraction(input) {
20824
21016
  reuseTokens: input.tokenStrategy === "reuse"
20825
21017
  })
20826
21018
  });
21019
+ void Promise.resolve().then(() => (init_debug_store(), debug_store_exports)).then((store) => store.startDebugSessionIn(input.projectPath));
20827
21020
  void runExtraction(input, (progress) => {
20828
21021
  if (current.current === input) setState({ status: "running", progress });
20829
21022
  }).then((result) => {
@@ -24045,7 +24238,7 @@ var init_save_decisions = __esm({
24045
24238
  });
24046
24239
 
24047
24240
  // packages/experience-design-system-cli/src/tui/import/steps/08-generation/run.ts
24048
- import { resolve as resolve23 } from "node:path";
24241
+ import { resolve as resolve24 } from "node:path";
24049
24242
  async function runGeneration(input, onProgress, deps = realDeps3) {
24050
24243
  let progress = { components: null, mapTokens: "idle", mapTokensEligible: null };
24051
24244
  const update = (change) => {
@@ -24131,7 +24324,7 @@ async function buildMapTokensOptions(input) {
24131
24324
  if (mapOverride?.kind === "text") prompt.skillContentOverride = mapOverride.value;
24132
24325
  if (mapOverride?.kind === "path") {
24133
24326
  await resolvePromptOverride(mapOverride);
24134
- prompt.skillPathOverride = resolve23(mapOverride.value);
24327
+ prompt.skillPathOverride = resolve24(mapOverride.value);
24135
24328
  }
24136
24329
  if (input.existingEntitiesPath) {
24137
24330
  const entities = await readExistingContentfulEntitiesFromSession({ path: input.existingEntitiesPath });
@@ -24209,7 +24402,7 @@ var init_use_generation = __esm({
24209
24402
  });
24210
24403
 
24211
24404
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/build-flow-start.ts
24212
- import { join as join22 } from "node:path";
24405
+ import { join as join23 } from "node:path";
24213
24406
  function buildFlowStart(input) {
24214
24407
  const { extraction, handoff, saved, generatePromptPath } = input;
24215
24408
  const credentials = extraction.credentials ?? {
@@ -24222,7 +24415,7 @@ function buildFlowStart(input) {
24222
24415
  handoff,
24223
24416
  agent: extraction.agent,
24224
24417
  projectPath: extraction.projectPath,
24225
- outDir: extraction.projectPath ? join22(extraction.projectPath, ".contentful") : "",
24418
+ outDir: extraction.projectPath ? join23(extraction.projectPath, ".contentful") : "",
24226
24419
  rawTokensPath: extraction.rawTokensPath,
24227
24420
  credentials: {
24228
24421
  spaceId: credentials.spaceId,
@@ -30418,7 +30611,7 @@ var init_DoneStep = __esm({
30418
30611
  });
30419
30612
 
30420
30613
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/support/path-utils.ts
30421
- import { resolve as resolve24 } from "node:path";
30614
+ import { resolve as resolve25 } from "node:path";
30422
30615
  import { homedir as homedir4 } from "node:os";
30423
30616
  function expandTilde(input) {
30424
30617
  if (input === "~" || input.startsWith("~/") || input.startsWith("~\\")) {
@@ -30432,7 +30625,7 @@ function normalizePath(input) {
30432
30625
  p = p.slice(1, -1);
30433
30626
  }
30434
30627
  p = expandTilde(p);
30435
- return resolve24(p);
30628
+ return resolve25(p);
30436
30629
  }
30437
30630
  var init_path_utils = __esm({
30438
30631
  "packages/experience-design-system-cli/src/tui/import/steps/10-flow/support/path-utils.ts"() {
@@ -30459,8 +30652,8 @@ var init_use_blinking_cursor = __esm({
30459
30652
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/screens/PathPrompt.tsx
30460
30653
  import { useState as useState24 } from "react";
30461
30654
  import { Box as Box37, Text as Text40 } from "ink";
30462
- import { readdirSync as readdirSync3 } from "node:fs";
30463
- import { dirname as dirname15, basename as basename6, join as join23 } from "node:path";
30655
+ import { readdirSync as readdirSync4 } from "node:fs";
30656
+ import { dirname as dirname15, basename as basename6, join as join24 } from "node:path";
30464
30657
  import { jsx as jsx47, jsxs as jsxs38 } from "react/jsx-runtime";
30465
30658
  function autocomplete(partial) {
30466
30659
  if (!partial) return null;
@@ -30469,19 +30662,19 @@ function autocomplete(partial) {
30469
30662
  const base = basename6(normalized);
30470
30663
  let entries;
30471
30664
  try {
30472
- entries = readdirSync3(dir);
30665
+ entries = readdirSync4(dir);
30473
30666
  } catch {
30474
30667
  return null;
30475
30668
  }
30476
30669
  const matches = entries.filter((e) => e.startsWith(base));
30477
30670
  if (matches.length === 0) return null;
30478
- if (matches.length === 1) return join23(dir, matches[0]);
30671
+ if (matches.length === 1) return join24(dir, matches[0]);
30479
30672
  let prefix = matches[0];
30480
30673
  for (const m of matches) {
30481
30674
  while (!m.startsWith(prefix)) prefix = prefix.slice(0, -1);
30482
30675
  if (!prefix) break;
30483
30676
  }
30484
- return prefix.length > base.length ? join23(dir, prefix) : null;
30677
+ return prefix.length > base.length ? join24(dir, prefix) : null;
30485
30678
  }
30486
30679
  function PathPrompt({
30487
30680
  defaultPath,
@@ -31684,8 +31877,8 @@ var init_run_print_files_helpers = __esm({
31684
31877
  });
31685
31878
 
31686
31879
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/save.ts
31687
- import { writeFile as writeFile7 } from "node:fs/promises";
31688
- import { join as join24 } from "node:path";
31880
+ import { writeFile as writeFile8 } from "node:fs/promises";
31881
+ import { join as join25 } from "node:path";
31689
31882
  function buildSavedCDF(components, tokens, opts = {}) {
31690
31883
  const cdf = buildCDF2(components, toCdfTokens(tokens), opts);
31691
31884
  if (!cdf) throw new Error("nothing to save \u2014 no components or tokens resolved");
@@ -31697,7 +31890,7 @@ function buildSavedCDF(components, tokens, opts = {}) {
31697
31890
  }
31698
31891
  async function runPrintFiles(input, deps, onPatch) {
31699
31892
  onPatch({ step: "printing" });
31700
- const componentsPath = join24(input.outDir, "components.json");
31893
+ const componentsPath = join25(input.outDir, "components.json");
31701
31894
  try {
31702
31895
  const db = deps.openDb();
31703
31896
  let components = [];
@@ -31781,10 +31974,10 @@ var init_save = __esm({
31781
31974
  realSaveDeps = () => ({
31782
31975
  openDb: openPipelineDb,
31783
31976
  readTokens: (path5) => readTokensFromPath2({ flag: "tokens", path: path5 }),
31784
- writeFile: (path5, contents) => writeFile7(path5, contents),
31977
+ writeFile: (path5, contents) => writeFile8(path5, contents),
31785
31978
  appendRun,
31786
31979
  buildSourceFingerprint,
31787
- sleep: (ms) => new Promise((resolve25) => setTimeout(resolve25, ms)),
31980
+ sleep: (ms) => new Promise((resolve26) => setTimeout(resolve26, ms)),
31788
31981
  warn: (message) => process.stderr.write(message)
31789
31982
  });
31790
31983
  }
@@ -31804,9 +31997,9 @@ var init_types9 = __esm({
31804
31997
 
31805
31998
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/controller.ts
31806
31999
  import { appendFileSync, writeFileSync } from "node:fs";
31807
- import { mkdir as mkdir8 } from "node:fs/promises";
32000
+ import { mkdir as mkdir9 } from "node:fs/promises";
31808
32001
  import { tmpdir } from "node:os";
31809
- import { join as join25 } from "node:path";
32002
+ import { join as join26 } from "node:path";
31810
32003
  function appendWizardLog(entry) {
31811
32004
  appendFileSync(WIZARD_LOG, JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), ...entry }) + "\n");
31812
32005
  }
@@ -31829,7 +32022,7 @@ function realFlowDeps() {
31829
32022
  }
31830
32023
  },
31831
32024
  mkdir: async (path5) => {
31832
- await mkdir8(path5, { recursive: true });
32025
+ await mkdir9(path5, { recursive: true });
31833
32026
  },
31834
32027
  detectSaveConflict,
31835
32028
  buildTimestampedSubdir,
@@ -32080,7 +32273,7 @@ var init_controller = __esm({
32080
32273
  init_push();
32081
32274
  init_save();
32082
32275
  init_types9();
32083
- WIZARD_LOG = join25(tmpdir(), "experiences-import-wizard.log");
32276
+ WIZARD_LOG = join26(tmpdir(), "experiences-import-wizard.log");
32084
32277
  }
32085
32278
  });
32086
32279
 
@@ -32112,183 +32305,13 @@ var init_use_flow = __esm({
32112
32305
  }
32113
32306
  });
32114
32307
 
32115
- // packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts
32116
- async function readDebugModeSetting() {
32117
- const { debugMode } = await readSettings2();
32118
- return { ...DEFAULT_DEBUG_MODE_SETTING, ...debugMode };
32119
- }
32120
- async function writeDebugModeSetting(setting) {
32121
- await updateSettings2({ debugMode: setting });
32122
- }
32123
- var DEFAULT_DEBUG_MODE_SETTING;
32124
- var init_debug_mode_store = __esm({
32125
- "packages/experience-design-system-cli/src/tui/settings/debug-mode/debug-mode-store.ts"() {
32126
- "use strict";
32127
- init_config();
32128
- DEFAULT_DEBUG_MODE_SETTING = {
32129
- enabled: true
32130
- };
32131
- }
32132
- });
32133
-
32134
- // packages/experience-design-system-cli/src/tui/debug-store.ts
32135
- import { mkdir as mkdir9, writeFile as writeFile8 } from "node:fs/promises";
32136
- import { existsSync as existsSync11, readdirSync as readdirSync4 } from "node:fs";
32137
- import { join as join26 } from "node:path";
32138
- function generateRunId() {
32139
- const now = /* @__PURE__ */ new Date();
32140
- const pad = (n) => String(n).padStart(2, "0");
32141
- return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
32142
- }
32143
- function datePrefix(now = /* @__PURE__ */ new Date()) {
32144
- const pad = (n) => String(n).padStart(2, "0");
32145
- return `${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${now.getFullYear()}`;
32146
- }
32147
- function slugify(value) {
32148
- return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
32149
- }
32150
- function generateSessionId3() {
32151
- const today = datePrefix();
32152
- const root = debugSessionsDir2();
32153
- const existing = existsSync11(root) ? readdirSync4(root) : [];
32154
- const seqPattern = new RegExp(`^${today}-session-(\\d+)$`);
32155
- const maxSeq = existing.reduce((max, entry) => {
32156
- const match2 = seqPattern.exec(entry);
32157
- return match2 ? Math.max(max, Number(match2[1])) : max;
32158
- }, 0);
32159
- return `${today}-session-${maxSeq + 1}`;
32160
- }
32161
- function sessionDebugDir() {
32162
- return join26(debugSessionsDir2(), SESSION_ID);
32163
- }
32164
- function currentDebugSessionDir() {
32165
- return sessionDebugDir();
32166
- }
32167
- async function isDebugModeEnabled() {
32168
- try {
32169
- return (await readDebugModeSetting()).enabled;
32170
- } catch {
32171
- return true;
32172
- }
32173
- }
32174
- function redact(value) {
32175
- const clone = { ...value };
32176
- if ("cma_token" in clone) {
32177
- const raw = clone.cma_token;
32178
- clone.cma_token = typeof raw === "string" && raw.length > 0 ? `[present, ${raw.length} chars]` : "[not set]";
32179
- }
32180
- return clone;
32181
- }
32182
- function startDebugRun({
32183
- flow,
32184
- step,
32185
- menuOption,
32186
- inputs
32187
- }) {
32188
- const runId = generateRunId();
32189
- const startedAt = Date.now();
32190
- const redactedInputs = redact(inputs);
32191
- isDebugModeEnabled().then((enabled) => {
32192
- if (!enabled) return;
32193
- pendingRun = { flow, step, runId, menuOption, inputs: redactedInputs, startedAt };
32194
- });
32195
- }
32196
- async function finishDebugRun({
32197
- outputs,
32198
- status,
32199
- exitMethod
32200
- }) {
32201
- const run = pendingRun;
32202
- if (!run) return;
32203
- pendingRun = void 0;
32204
- const durationMs = Date.now() - run.startedAt;
32205
- const content = renderMarkdown(run, { outputs: redact(outputs), status, exitMethod, durationMs });
32206
- const flowSegments = run.flow.split("/");
32207
- const dir = join26(sessionDebugDir(), ...flowSegments);
32208
- await mkdir9(dir, { recursive: true });
32209
- const filename = nextAttemptFilename(dir, run.menuOption);
32210
- await writeFile8(join26(dir, filename), content, { mode: 384 });
32211
- }
32212
- function nextAttemptFilename(dir, menuOption) {
32213
- const today = datePrefix();
32214
- const optionSlug = slugify(menuOption);
32215
- const existing = existsSync11(dir) ? readdirSync4(dir) : [];
32216
- const attemptPattern = new RegExp(`^${today}-${optionSlug}-attempt-(\\d+)\\.md$`);
32217
- const maxAttempt = existing.reduce((max, entry) => {
32218
- const match2 = attemptPattern.exec(entry);
32219
- return match2 ? Math.max(max, Number(match2[1])) : max;
32220
- }, 0);
32221
- return `${today}-${optionSlug}-attempt-${maxAttempt + 1}.md`;
32222
- }
32223
- function renderMarkdown(run, finish) {
32224
- const stepMatch = /^(\d+)-(.+)$/.exec(run.step);
32225
- const stepLabel2 = stepMatch ? `${stepMatch[1]} - ${stepMatch[2]}` : run.step;
32226
- const flowSlug = run.flow.split("/").join("-");
32227
- return `# Debug Log
32228
-
32229
- - Run ID: ${run.runId}
32230
- - Flow: ${flowSlug}
32231
- - Step: ${stepLabel2}
32232
- - Menu option: ${run.menuOption}
32233
- - Date: ${(/* @__PURE__ */ new Date()).toISOString()}
32234
- - CLI version: ${readPackageVersion()}
32235
- - Platform: ${process.platform} / Node ${process.version}
32236
- - Duration on screen: ${finish.durationMs}ms
32237
- - Status: ${finish.status}
32238
- - Exit method: ${finish.exitMethod}
32239
-
32240
- ## Inputs
32241
- \`\`\`json
32242
- ${JSON.stringify(run.inputs, null, 2)}
32243
- \`\`\`
32244
-
32245
- ## Outputs
32246
- \`\`\`json
32247
- ${JSON.stringify(finish.outputs, null, 2)}
32248
- \`\`\`
32249
- `;
32250
- }
32251
- function handleCrash() {
32252
- return finishDebugRun({ outputs: {}, status: "error", exitMethod: "crashed" });
32253
- }
32254
- var pendingRun, SESSION_ID;
32255
- var init_debug_store = __esm({
32256
- "packages/experience-design-system-cli/src/tui/debug-store.ts"() {
32257
- "use strict";
32258
- init_config();
32259
- init_version();
32260
- init_debug_mode_store();
32261
- SESSION_ID = generateSessionId3();
32262
- void isDebugModeEnabled().then((enabled) => {
32263
- if (!enabled) return void 0;
32264
- return mkdir9(sessionDebugDir(), { recursive: true });
32265
- });
32266
- process.once("uncaughtException", (err) => {
32267
- void handleCrash().finally(() => {
32268
- throw err;
32269
- });
32270
- });
32271
- process.once("unhandledRejection", (reason) => {
32272
- void handleCrash().finally(() => {
32273
- throw reason;
32274
- });
32275
- });
32276
- process.once("SIGINT", () => {
32277
- void handleCrash().finally(() => {
32278
- process.exit(130);
32279
- });
32280
- });
32281
- }
32282
- });
32283
-
32284
32308
  // packages/experience-design-system-cli/src/tui/help/help-info.ts
32285
32309
  async function readHelpInfo() {
32286
32310
  const debugMode = await readDebugModeSetting();
32287
32311
  return {
32288
32312
  storage: [
32289
32313
  { label: "Config folder", value: configRoot2() },
32290
- { label: "Settings file", value: configFilePath2() },
32291
- { label: "Debug logs", value: debugSessionsDir2() }
32314
+ { label: "Settings file", value: configFilePath2() }
32292
32315
  ],
32293
32316
  troubleshooting: [
32294
32317
  { label: "CLI version", value: readPackageVersion() },
@@ -32297,7 +32320,7 @@ async function readHelpInfo() {
32297
32320
  { label: "Debug Mode", value: debugMode.enabled ? "on" : "off" },
32298
32321
  {
32299
32322
  label: "This session",
32300
- value: debugMode.enabled ? currentDebugSessionDir() : "no logs written while Debug Mode is off"
32323
+ value: !debugMode.enabled ? "no logs written while Debug Mode is off" : currentDebugSessionDir() ?? "not started: set the default project directory in Settings, or start an import"
32301
32324
  }
32302
32325
  ]
32303
32326
  };
@@ -32454,7 +32477,8 @@ async function readCredentials() {
32454
32477
  cmaToken: store.cmaToken || "",
32455
32478
  host: store.host || "",
32456
32479
  defaultComponentDir: store.defaultComponentDir || "",
32457
- defaultTokenFile: store.defaultTokenFile || ""
32480
+ defaultTokenFile: store.defaultTokenFile || "",
32481
+ contentfulBaseDir: store.contentfulBaseDir || ""
32458
32482
  };
32459
32483
  }
32460
32484
  async function writeCredentials(config) {
@@ -32487,7 +32511,8 @@ function debugFields(config) {
32487
32511
  cma_token: config?.cmaToken ?? "",
32488
32512
  host: config?.host ?? "",
32489
32513
  default_component_dir: config?.defaultComponentDir ?? "",
32490
- default_token_file: config?.defaultTokenFile ?? ""
32514
+ default_token_file: config?.defaultTokenFile ?? "",
32515
+ contentful_base_dir: config?.contentfulBaseDir ?? ""
32491
32516
  };
32492
32517
  }
32493
32518
  function ConfigurationScreen({ onDone }) {
@@ -32525,6 +32550,7 @@ function ConfigurationScreen({ onDone }) {
32525
32550
  setNotice(null);
32526
32551
  writeCredentials(config).then(() => {
32527
32552
  setLastSaved(config);
32553
+ if (config.contentfulBaseDir) void startDebugSessionIn(config.contentfulBaseDir);
32528
32554
  setNotice({ kind: "success", text: "Configuration saved" });
32529
32555
  setStage("form");
32530
32556
  }).catch((err) => {
@@ -32647,7 +32673,8 @@ var init_ContentfulConfigScreen = __esm({
32647
32673
  "cmaToken",
32648
32674
  "host",
32649
32675
  "defaultComponentDir",
32650
- "defaultTokenFile"
32676
+ "defaultTokenFile",
32677
+ "contentfulBaseDir"
32651
32678
  ];
32652
32679
  FIELD_LABELS = {
32653
32680
  spaceId: "Space ID",
@@ -32655,7 +32682,8 @@ var init_ContentfulConfigScreen = __esm({
32655
32682
  cmaToken: "CMA Token",
32656
32683
  host: "API Host (optional)",
32657
32684
  defaultComponentDir: "Default component directory (optional)",
32658
- defaultTokenFile: "Default token file (optional)"
32685
+ defaultTokenFile: "Default token file (optional)",
32686
+ contentfulBaseDir: "Default project directory, where .contentful goes (optional)"
32659
32687
  };
32660
32688
  }
32661
32689
  });
@@ -33326,14 +33354,14 @@ function runDevWatch(args) {
33326
33354
  process.stderr.write("--watch only works from a checkout of the repo (scripts/dev.mjs is not in the package).\n");
33327
33355
  return Promise.resolve(1);
33328
33356
  }
33329
- return new Promise((resolve25) => {
33357
+ return new Promise((resolve26) => {
33330
33358
  const child = spawn2(process.execPath, [script, ...args], { stdio: "inherit" });
33331
33359
  process.on("SIGINT", () => void 0);
33332
- child.on("exit", (code) => resolve25(code ?? 0));
33360
+ child.on("exit", (code) => resolve26(code ?? 0));
33333
33361
  child.on("error", (err) => {
33334
33362
  process.stderr.write(`${err.message}
33335
33363
  `);
33336
- resolve25(1);
33364
+ resolve26(1);
33337
33365
  });
33338
33366
  });
33339
33367
  }