@contentful/experience-design-system-cli 2.37.1-dev-build-f0533497.0 → 2.37.1-dev-build-1c5cd11a.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
@@ -32,31 +32,6 @@ var init_package_root = __esm({
32
32
  }
33
33
  });
34
34
 
35
- // packages/experience-design-system-cli/src/legacy/legacy-cli-path.ts
36
- import { existsSync as existsSync2 } from "node:fs";
37
- import { join as join2 } from "node:path";
38
- function findLegacyCliPath() {
39
- const root = findPackageRoot(import.meta.url, PACKAGE_NAME);
40
- const candidates = [
41
- join2(root, "legacy", "bin", "cli.js"),
42
- join2(root, "..", "experience-design-system-cli-legacy", "bin", "cli.js")
43
- ];
44
- const found = candidates.find((candidate) => existsSync2(candidate));
45
- if (!found) {
46
- throw new Error(`Legacy CLI not found. Looked in:
47
- ${candidates.join("\n")}`);
48
- }
49
- return found;
50
- }
51
- var PACKAGE_NAME;
52
- var init_legacy_cli_path = __esm({
53
- "packages/experience-design-system-cli/src/legacy/legacy-cli-path.ts"() {
54
- "use strict";
55
- init_package_root();
56
- PACKAGE_NAME = "@contentful/experience-design-system-cli";
57
- }
58
- });
59
-
60
35
  // packages/experience-design-system-cli/src/tui/home/home.theme.ts
61
36
  function brandBar(width, ramp = BRAND_RAMP) {
62
37
  if (width <= 0 || ramp.length === 0) return [];
@@ -669,9 +644,83 @@ var init_config_root = __esm({
669
644
  });
670
645
 
671
646
  // packages/experience-design-system-backend-pipeline/dist/src/persistence/src/session/helpers/source-excerpt.js
647
+ function escapeForRegExp(value) {
648
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
649
+ }
650
+ function identifierPattern(name) {
651
+ return new RegExp(`(?<![A-Za-z0-9_$])${escapeForRegExp(name)}(?![A-Za-z0-9_$])`);
652
+ }
653
+ function excerptAroundNames(text, names, maxChars, contextLines = 6) {
654
+ if (text.length <= maxChars)
655
+ return { content: text, usesNotShown: [] };
656
+ const patterns = names.filter((name) => name.length > 0).map((name) => ({ name, pattern: identifierPattern(name) }));
657
+ const lines = text.split("\n");
658
+ const windows = [];
659
+ lines.forEach((line, index) => {
660
+ const mentioned = patterns.filter(({ pattern }) => pattern.test(line)).map(({ name }) => name);
661
+ if (mentioned.length === 0)
662
+ return;
663
+ const start = Math.max(0, index - contextLines);
664
+ const end = Math.min(lines.length - 1, index + contextLines);
665
+ const last = windows[windows.length - 1];
666
+ if (last && start <= last.end + 1) {
667
+ last.end = Math.max(last.end, end);
668
+ for (const name of mentioned)
669
+ last.names.add(name);
670
+ } else {
671
+ windows.push({ start, end, names: new Set(mentioned) });
672
+ }
673
+ });
674
+ if (windows.length === 0) {
675
+ return { content: `${text.slice(0, maxChars)}
676
+ ${TRUNCATED_MARKER}`, usesNotShown: [] };
677
+ }
678
+ const lastWindowFor = /* @__PURE__ */ new Map();
679
+ for (const window of windows)
680
+ for (const name of window.names)
681
+ lastWindowFor.set(name, window);
682
+ const kept = [];
683
+ const cut = /* @__PURE__ */ new Set();
684
+ let used = 0;
685
+ for (const window of [...windows].reverse()) {
686
+ const chunk = lines.slice(window.start, window.end + 1).join("\n");
687
+ const separator = kept.length > 0 ? `
688
+ ${ELLIPSIS_MARKER}
689
+ ` : "";
690
+ if (used + separator.length + chunk.length > maxChars) {
691
+ if (kept.length === 0) {
692
+ const head = chunk.slice(0, maxChars);
693
+ kept.push({ window, text: head });
694
+ used += head.length;
695
+ for (const name of window.names) {
696
+ if (lastWindowFor.get(name) === window && !identifierPattern(name).test(head))
697
+ cut.add(name);
698
+ }
699
+ continue;
700
+ }
701
+ for (const name of window.names) {
702
+ if (lastWindowFor.get(name) === window)
703
+ cut.add(name);
704
+ }
705
+ continue;
706
+ }
707
+ kept.push({ window, text: chunk });
708
+ used += separator.length + chunk.length;
709
+ }
710
+ kept.sort((a, b) => a.window.start - b.window.start);
711
+ const parts = kept.map((entry, index) => (index > 0 ? `
712
+ ${ELLIPSIS_MARKER}
713
+ ` : "") + entry.text);
714
+ const usesNotShown = names.filter((name, index) => cut.has(name) && names.indexOf(name) === index);
715
+ return { content: `${parts.join("")}
716
+ ${TRUNCATED_MARKER}`, usesNotShown };
717
+ }
718
+ var ELLIPSIS_MARKER, TRUNCATED_MARKER;
672
719
  var init_source_excerpt = __esm({
673
720
  "packages/experience-design-system-backend-pipeline/dist/src/persistence/src/session/helpers/source-excerpt.js"() {
674
721
  "use strict";
722
+ ELLIPSIS_MARKER = "/* \u2026 */";
723
+ TRUNCATED_MARKER = "/* truncated */";
675
724
  }
676
725
  });
677
726
 
@@ -752,6 +801,14 @@ function getSessionById(db, sessionId) {
752
801
  const row = db.prepare("SELECT id FROM sessions WHERE id = ?").get(sessionId);
753
802
  return row ?? null;
754
803
  }
804
+ function getLatestCompletedSessionForCommand(db, command) {
805
+ const row = db.prepare(`SELECT s.id FROM sessions s
806
+ JOIN steps st ON st.session_id = s.id
807
+ WHERE st.command = ? AND st.status = 'complete'
808
+ ORDER BY st.started_at DESC, st.id DESC
809
+ LIMIT 1`).get(command);
810
+ return row?.id ?? null;
811
+ }
755
812
  var init_read = __esm({
756
813
  "packages/experience-design-system-backend-pipeline/dist/src/persistence/src/session/repositories/sessions/read.js"() {
757
814
  "use strict";
@@ -1100,6 +1157,13 @@ function getRawTokenNamePaths(db, sessionId) {
1100
1157
  const rows = db.prepare("SELECT raw_name, path FROM raw_token_name_paths WHERE session_id = ? ORDER BY raw_name").all(sessionId);
1101
1158
  return Object.fromEntries(rows.map((row) => [String(row.raw_name), String(row.path)]));
1102
1159
  }
1160
+ function getRawTokenNamePathRows(db, sessionId) {
1161
+ return db.prepare("SELECT raw_name, path, source FROM raw_token_name_paths WHERE session_id = ? ORDER BY raw_name").all(sessionId).map((row) => ({
1162
+ rawName: String(row.raw_name),
1163
+ path: String(row.path),
1164
+ source: String(row.source)
1165
+ }));
1166
+ }
1103
1167
  var init_read3 = __esm({
1104
1168
  "packages/experience-design-system-backend-pipeline/dist/src/persistence/src/session/repositories/tokens/read.js"() {
1105
1169
  "use strict";
@@ -1168,6 +1232,27 @@ function upsertRawTokenGroup(db, sessionId, call) {
1168
1232
  db.prepare(`INSERT INTO raw_token_groups (session_id, path, description) VALUES (?, ?, ?)
1169
1233
  ON CONFLICT(session_id, path) DO UPDATE SET description = excluded.description`).run(sessionId, call.path, call.description ?? null);
1170
1234
  }
1235
+ function updateRawTokenNamePaths(db, sessionId, tokenNamePaths, source) {
1236
+ const entries = Object.entries(tokenNamePaths);
1237
+ const deletePaths = db.prepare("DELETE FROM raw_token_name_paths WHERE session_id = ? AND source = ?");
1238
+ const insertPath = db.prepare("INSERT OR IGNORE INTO raw_token_name_paths (session_id, raw_name, path, source) VALUES (?, ?, ?, ?)");
1239
+ const deleteAutomaticByName = db.prepare("DELETE FROM raw_token_name_paths WHERE session_id = ? AND raw_name = ? AND source = 'automatic'");
1240
+ deletePaths.run(sessionId, source);
1241
+ for (const [rawName, path5] of entries) {
1242
+ if (source === "manual")
1243
+ deleteAutomaticByName.run(sessionId, rawName);
1244
+ insertPath.run(sessionId, rawName, path5, source);
1245
+ }
1246
+ }
1247
+ function updateRawPropTokenPaths(db, sessionId, componentId, propName, paths, source) {
1248
+ db.prepare(`DELETE FROM raw_prop_token_paths
1249
+ WHERE session_id = ? AND component_id = ? AND prop_name = ?`).run(sessionId, componentId, propName);
1250
+ const insertPath = db.prepare(`INSERT INTO raw_prop_token_paths (session_id, component_id, prop_name, source, position, path)
1251
+ VALUES (?, ?, ?, ?, ?, ?)`);
1252
+ paths.forEach((path5, position) => {
1253
+ insertPath.run(sessionId, componentId, propName, source, position, path5);
1254
+ });
1255
+ }
1171
1256
  var init_write3 = __esm({
1172
1257
  "packages/experience-design-system-backend-pipeline/dist/src/persistence/src/session/repositories/tokens/write.js"() {
1173
1258
  "use strict";
@@ -1241,6 +1326,12 @@ var init_apply_tool_calls = __esm({
1241
1326
  });
1242
1327
 
1243
1328
  // packages/experience-design-system-backend-pipeline/dist/src/persistence/src/session/services/tokens/replace-raw-token-name-paths.js
1329
+ function replaceRawTokenNamePaths(db, sessionId, tokenNamePaths, source = "automatic") {
1330
+ withTransaction(db, () => {
1331
+ updateRawTokenNamePaths(db, sessionId, tokenNamePaths, source);
1332
+ updateSessionTimestamp(db, sessionId, (/* @__PURE__ */ new Date()).toISOString());
1333
+ });
1334
+ }
1244
1335
  var init_replace_raw_token_name_paths = __esm({
1245
1336
  "packages/experience-design-system-backend-pipeline/dist/src/persistence/src/session/services/tokens/replace-raw-token-name-paths.js"() {
1246
1337
  "use strict";
@@ -1251,6 +1342,12 @@ var init_replace_raw_token_name_paths = __esm({
1251
1342
  });
1252
1343
 
1253
1344
  // packages/experience-design-system-backend-pipeline/dist/src/persistence/src/session/services/tokens/replace-raw-prop-token-paths.js
1345
+ function replaceRawPropTokenPaths(db, sessionId, componentId, propName, paths, source) {
1346
+ withTransaction(db, () => {
1347
+ updateRawPropTokenPaths(db, sessionId, componentId, propName, paths, source);
1348
+ updateSessionTimestamp(db, sessionId, (/* @__PURE__ */ new Date()).toISOString());
1349
+ });
1350
+ }
1254
1351
  var init_replace_raw_prop_token_paths = __esm({
1255
1352
  "packages/experience-design-system-backend-pipeline/dist/src/persistence/src/session/services/tokens/replace-raw-prop-token-paths.js"() {
1256
1353
  "use strict";
@@ -2024,7 +2121,7 @@ async function runAgent(options) {
2024
2121
  promptLen: prompt.length,
2025
2122
  promptHead: prompt.slice(0, 500)
2026
2123
  });
2027
- return new Promise((resolve22) => {
2124
+ return new Promise((resolve25) => {
2028
2125
  const bedrockEnv = bedrock ? BEDROCK_ENV_BY_AGENT[agent] : void 0;
2029
2126
  const child = spawn3(binary, args, {
2030
2127
  stdio: ["pipe", "pipe", "pipe"],
@@ -2073,7 +2170,7 @@ async function runAgent(options) {
2073
2170
  stderrLen: stderr.length,
2074
2171
  stderrTail: stderr.slice(-1e3)
2075
2172
  });
2076
- resolve22(result);
2173
+ resolve25(result);
2077
2174
  });
2078
2175
  });
2079
2176
  }
@@ -2095,7 +2192,7 @@ async function checkAgentAuth(agent) {
2095
2192
  return "not-found";
2096
2193
  if (agent !== "claude")
2097
2194
  return "ok";
2098
- return new Promise((resolve22) => {
2195
+ return new Promise((resolve25) => {
2099
2196
  const child = spawn4(binary, ["auth", "status", "--json"], { stdio: ["ignore", "pipe", "pipe"] });
2100
2197
  let stdout = "";
2101
2198
  let done = false;
@@ -2104,7 +2201,7 @@ async function checkAgentAuth(agent) {
2104
2201
  return;
2105
2202
  done = true;
2106
2203
  child.kill("SIGTERM");
2107
- resolve22("unauthenticated");
2204
+ resolve25("unauthenticated");
2108
2205
  }, 5e3);
2109
2206
  child.stdout?.on("data", (chunk) => {
2110
2207
  stdout += chunk.toString();
@@ -2115,14 +2212,14 @@ async function checkAgentAuth(agent) {
2115
2212
  done = true;
2116
2213
  clearTimeout(timer);
2117
2214
  if (code !== 0) {
2118
- resolve22("unauthenticated");
2215
+ resolve25("unauthenticated");
2119
2216
  return;
2120
2217
  }
2121
2218
  try {
2122
2219
  const status = JSON.parse(stdout);
2123
- resolve22(status.loggedIn ? "ok" : "unauthenticated");
2220
+ resolve25(status.loggedIn ? "ok" : "unauthenticated");
2124
2221
  } catch {
2125
- resolve22("unauthenticated");
2222
+ resolve25("unauthenticated");
2126
2223
  }
2127
2224
  });
2128
2225
  });
@@ -2132,9 +2229,9 @@ async function binaryIsOnPath(binary) {
2132
2229
  const fs = await import("node:fs/promises");
2133
2230
  return fs.access(binary).then(() => true, () => false);
2134
2231
  }
2135
- return new Promise((resolve22) => {
2232
+ return new Promise((resolve25) => {
2136
2233
  const child = spawn4(process.platform === "win32" ? "where" : "which", [binary], { stdio: "ignore" });
2137
- child.on("close", (code) => resolve22(code === 0));
2234
+ child.on("close", (code) => resolve25(code === 0));
2138
2235
  });
2139
2236
  }
2140
2237
  var init_check_agent_auth = __esm({
@@ -3271,6 +3368,8 @@ var init_cache_keys = __esm({
3271
3368
  // packages/experience-design-system-backend-pipeline/dist/src/persistence/src/session/repositories/db.js
3272
3369
  import { DatabaseSync } from "node:sqlite";
3273
3370
  import { mkdirSync, readFileSync as readFileSync3 } from "node:fs";
3371
+ import { readFile as readFile4 } from "node:fs/promises";
3372
+ import { createHash as createHash5 } from "node:crypto";
3274
3373
  import { dirname as dirname4, resolve as resolve6 } from "node:path";
3275
3374
  function getPipelineDbPath() {
3276
3375
  if (process.env.EDS_PIPELINE_DB_PATH) {
@@ -3588,6 +3687,109 @@ function loadComponentRationale(db, sessionId, componentName) {
3588
3687
  }))
3589
3688
  };
3590
3689
  }
3690
+ function applyToolCalls(db, sessionId, componentId, componentName, calls, incomingWarnings, options = {}) {
3691
+ const now = (/* @__PURE__ */ new Date()).toISOString();
3692
+ const warnings = [...incomingWarnings];
3693
+ let classified = 0;
3694
+ let excluded = 0;
3695
+ let slots = 0;
3696
+ const updateProp = db.prepare(`UPDATE raw_props SET cdf_type = ?, cdf_category = ?, cdf_token_kind = ?, required = ?, description = ?, rationale = ?
3697
+ WHERE session_id = ? AND component_id = ? AND name = ?`);
3698
+ const clearProp = db.prepare(`UPDATE raw_props
3699
+ SET cdf_type = CASE WHEN type = 'boolean' THEN 'boolean' ELSE 'string' END,
3700
+ cdf_category = 'unattached',
3701
+ cdf_token_kind = NULL,
3702
+ required = 0,
3703
+ rationale = ?
3704
+ WHERE session_id = ? AND component_id = ? AND name = ?`);
3705
+ const deleteAllowedValues = db.prepare(`DELETE FROM raw_prop_allowed_values WHERE session_id = ? AND component_id = ? AND prop_name = ?`);
3706
+ const deleteTokenPaths = db.prepare(`DELETE FROM raw_prop_token_paths WHERE session_id = ? AND component_id = ? AND prop_name = ?`);
3707
+ const insertAllowedValue = db.prepare(`INSERT OR IGNORE INTO raw_prop_allowed_values (session_id, component_id, prop_name, value, position)
3708
+ VALUES (?, ?, ?, ?, ?)`);
3709
+ const deleteAllowedComponents = db.prepare(`DELETE FROM raw_slot_allowed_components WHERE session_id = ? AND component_id = ? AND slot_name = ?`);
3710
+ const insertAllowedComponent = db.prepare(`INSERT OR IGNORE INTO raw_slot_allowed_components (session_id, component_id, slot_name, allowed_component, position)
3711
+ VALUES (?, ?, ?, ?, ?)`);
3712
+ const updateSlot = db.prepare(`UPDATE raw_slots SET required = ?, description = ? WHERE session_id = ? AND component_id = ? AND name = ?`);
3713
+ db.exec("BEGIN");
3714
+ try {
3715
+ for (const call of calls) {
3716
+ if (call.tool === "classify_component") {
3717
+ if (call.description !== void 0) {
3718
+ db.prepare("UPDATE raw_components SET description = ? WHERE session_id = ? AND component_id = ?").run(call.description, sessionId, componentId);
3719
+ }
3720
+ if (call.rationale) {
3721
+ if (call.rationale.description !== void 0) {
3722
+ db.prepare("UPDATE raw_components SET component_description_rationale = ? WHERE session_id = ? AND component_id = ?").run(call.rationale.description, sessionId, componentId);
3723
+ }
3724
+ if (call.rationale.props !== void 0) {
3725
+ db.prepare("UPDATE raw_components SET props_rationale = ? WHERE session_id = ? AND component_id = ?").run(call.rationale.props, sessionId, componentId);
3726
+ }
3727
+ if (call.rationale.slots !== void 0) {
3728
+ db.prepare("UPDATE raw_components SET slots_rationale = ? WHERE session_id = ? AND component_id = ?").run(call.rationale.slots, sessionId, componentId);
3729
+ }
3730
+ }
3731
+ } else if (call.tool === "classify_prop") {
3732
+ const changes = updateProp.run(call.cdf_type, call.cdf_category, call.token_kind ?? null, call.required !== void 0 ? call.required ? 1 : 0 : 0, call.description ?? null, call.reason ?? null, sessionId, componentId, call.prop);
3733
+ if (changes.changes === 0) {
3734
+ warnings.push(`${componentName}: classify_prop '${call.prop}' \u2014 prop not found, skipped`);
3735
+ continue;
3736
+ }
3737
+ if (call.cdf_type === "token") {
3738
+ deleteAllowedValues.run(sessionId, componentId, call.prop);
3739
+ if (call.values && call.values.length > 0) {
3740
+ const count = call.values.length;
3741
+ warnings.push(`${componentName}: classify_prop '${call.prop}' \u2014 dropped ${count} value${count === 1 ? "" : "s"} on a token property; its options list is $token.allowed, not $values`);
3742
+ }
3743
+ } else {
3744
+ deleteTokenPaths.run(sessionId, componentId, call.prop);
3745
+ if (call.values && call.values.length > 0) {
3746
+ deleteAllowedValues.run(sessionId, componentId, call.prop);
3747
+ call.values.forEach((v, i) => insertAllowedValue.run(sessionId, componentId, call.prop, v, i));
3748
+ }
3749
+ }
3750
+ if (call.default !== void 0) {
3751
+ const storedDefault = typeof call.default === "boolean" ? String(call.default) : call.default;
3752
+ db.prepare(`UPDATE raw_props SET default_value = ? WHERE session_id = ? AND component_id = ? AND name = ?`).run(storedDefault, sessionId, componentId, call.prop);
3753
+ }
3754
+ classified++;
3755
+ } else if (call.tool === "exclude_prop") {
3756
+ clearProp.run(call.reason || null, sessionId, componentId, call.prop);
3757
+ excluded++;
3758
+ } else if (call.tool === "classify_slot") {
3759
+ const slotRequired = call.required !== void 0 ? call.required ? 1 : 0 : 1;
3760
+ const slotChanges = updateSlot.run(slotRequired, call.description ?? null, sessionId, componentId, call.slot);
3761
+ if (slotChanges.changes === 0) {
3762
+ warnings.push(`${componentName}: classify_slot '${call.slot}' \u2014 slot not found, skipped`);
3763
+ continue;
3764
+ }
3765
+ if (call.rationale !== void 0) {
3766
+ db.prepare("UPDATE raw_slots SET rationale = ? WHERE session_id = ? AND component_id = ? AND name = ?").run(call.rationale, sessionId, componentId, call.slot);
3767
+ }
3768
+ if (call.allowed_components !== void 0) {
3769
+ deleteAllowedComponents.run(sessionId, componentId, call.slot);
3770
+ const allowedComponents = options.allowedComponentNames ? call.allowed_components.filter((allowedComponent) => options.allowedComponentNames.has(allowedComponent)) : call.allowed_components;
3771
+ if (options.allowedComponentNames) {
3772
+ const dropped = [
3773
+ ...new Set(call.allowed_components.filter((ac) => !options.allowedComponentNames.has(ac)))
3774
+ ];
3775
+ for (const allowedComponent of dropped) {
3776
+ warnings.push(`${componentName}: classify_slot '${call.slot}' \u2014 dropped unknown allowed component '${allowedComponent}'`);
3777
+ }
3778
+ }
3779
+ allowedComponents.forEach((ac, i) => insertAllowedComponent.run(sessionId, componentId, call.slot, ac, i));
3780
+ }
3781
+ slots++;
3782
+ }
3783
+ }
3784
+ db.prepare(`UPDATE raw_components SET status = 'generated', extracted_at = ? WHERE session_id = ? AND component_id = ?`).run(now, sessionId, componentId);
3785
+ db.prepare("UPDATE sessions SET updated_at = ? WHERE id = ?").run(now, sessionId);
3786
+ db.exec("COMMIT");
3787
+ } catch (e) {
3788
+ db.exec("ROLLBACK");
3789
+ throw e;
3790
+ }
3791
+ return { classified, excluded, slots, warnings };
3792
+ }
3591
3793
  function getOrCreateSession(db, sessionFlag, sessionName, hints) {
3592
3794
  return getOrCreateSessionForCommand(db, sessionFlag, sessionName, hints);
3593
3795
  }
@@ -3797,6 +3999,176 @@ function loadRawComponents(db, sessionId, allowedNames) {
3797
3999
  })
3798
4000
  }));
3799
4001
  }
4002
+ function rewrittenSourcePaths(basePath) {
4003
+ for (const [emitted, sources] of TS_ESM_EXTENSION_REWRITES) {
4004
+ if (!basePath.endsWith(emitted))
4005
+ continue;
4006
+ const stem = basePath.slice(0, -emitted.length);
4007
+ return sources.map((ext) => `${stem}${ext}`);
4008
+ }
4009
+ return [];
4010
+ }
4011
+ function identifiersIn(propTypes) {
4012
+ const names = /* @__PURE__ */ new Set();
4013
+ for (const propType of propTypes) {
4014
+ for (const match2 of propType.matchAll(IDENTIFIER_PATTERN))
4015
+ names.add(match2[0]);
4016
+ }
4017
+ return [...names];
4018
+ }
4019
+ function declaresAnyType(text, typeNames) {
4020
+ return typeNames.some((name) => new RegExp(`\\b(?:type|interface|enum|const|class)\\s+${escapeForRegExp(name)}\\b`).test(text));
4021
+ }
4022
+ function extractRelativeImportPaths(sourceText) {
4023
+ const specifiers = /* @__PURE__ */ new Set();
4024
+ for (const match2 of sourceText.matchAll(RELATIVE_IMPORT_PATTERN)) {
4025
+ if (match2[1])
4026
+ specifiers.add(match2[1]);
4027
+ }
4028
+ return [...specifiers];
4029
+ }
4030
+ async function resolveRelativeImport(specifier, fromDir) {
4031
+ const basePath = resolve6(fromDir, specifier);
4032
+ const candidates = [
4033
+ basePath,
4034
+ ...rewrittenSourcePaths(basePath),
4035
+ ...SIBLING_FILE_EXTENSIONS.map((ext) => `${basePath}${ext}`),
4036
+ ...SIBLING_FILE_EXTENSIONS.map((ext) => resolve6(basePath, `index${ext}`))
4037
+ ];
4038
+ for (const candidate of candidates) {
4039
+ try {
4040
+ await readFile4(candidate, "utf8");
4041
+ return candidate;
4042
+ } catch {
4043
+ }
4044
+ }
4045
+ return void 0;
4046
+ }
4047
+ async function resolveImportSpecifiers(sourceText, fromDir) {
4048
+ const resolvedPaths = [];
4049
+ for (const specifier of extractRelativeImportPaths(sourceText)) {
4050
+ const resolvedPath = await resolveRelativeImport(specifier, fromDir);
4051
+ if (resolvedPath)
4052
+ resolvedPaths.push(resolvedPath);
4053
+ }
4054
+ return resolvedPaths;
4055
+ }
4056
+ async function loadSiblingFiles(sourceText, sourcePath, propNames, candidateTypeNames = []) {
4057
+ const visited = /* @__PURE__ */ new Set([resolve6(sourcePath)]);
4058
+ const discovered = [];
4059
+ let frontier = [{ text: sourceText, dir: dirname4(sourcePath) }];
4060
+ for (let hop = 0; hop < MAX_SIBLING_DEPTH && discovered.length < MAX_SIBLING_CANDIDATES_EXPLORED; hop++) {
4061
+ const nextFrontier = [];
4062
+ for (const node of frontier) {
4063
+ if (discovered.length >= MAX_SIBLING_CANDIDATES_EXPLORED)
4064
+ break;
4065
+ const resolvedPaths = await resolveImportSpecifiers(node.text, node.dir);
4066
+ for (const resolvedPath of resolvedPaths) {
4067
+ if (visited.has(resolvedPath))
4068
+ continue;
4069
+ visited.add(resolvedPath);
4070
+ if (discovered.length >= MAX_SIBLING_CANDIDATES_EXPLORED)
4071
+ break;
4072
+ let content;
4073
+ try {
4074
+ content = await readFile4(resolvedPath, "utf8");
4075
+ } catch {
4076
+ continue;
4077
+ }
4078
+ discovered.push({ path: resolvedPath, content });
4079
+ nextFrontier.push({ text: content, dir: dirname4(resolvedPath) });
4080
+ }
4081
+ }
4082
+ frontier = nextFrontier;
4083
+ }
4084
+ const inHand = [sourceText, ...discovered.map((d) => d.content)];
4085
+ const declaredTypeNames = candidateTypeNames.filter((name) => inHand.some((text) => declaresAnyType(text, [name])));
4086
+ const usesNotShown = /* @__PURE__ */ new Set();
4087
+ const searchNames = [.../* @__PURE__ */ new Set([...propNames, ...declaredTypeNames])];
4088
+ let enlarged = 0;
4089
+ const siblings = discovered.slice(0, MAX_SIBLING_FILES).map((d) => {
4090
+ const enlarge = enlarged < MAX_ENLARGED_SIBLINGS && declaresAnyType(d.content, declaredTypeNames);
4091
+ if (enlarge)
4092
+ enlarged++;
4093
+ const budget = enlarge ? MAX_TYPE_DECLARING_SIBLING_CHARS : MAX_SIBLING_SNIPPET_CHARS;
4094
+ const excerpt = excerptAroundNames(d.content, searchNames, budget);
4095
+ for (const name of excerpt.usesNotShown)
4096
+ usesNotShown.add(name);
4097
+ return { path: d.path, content: excerpt.content };
4098
+ });
4099
+ const truncatedCount = Math.max(0, discovered.length - MAX_SIBLING_FILES);
4100
+ return {
4101
+ siblings,
4102
+ truncatedCount,
4103
+ usesNotShown: propNames.filter((name) => usesNotShown.has(name)),
4104
+ declaredTypeNames
4105
+ };
4106
+ }
4107
+ async function loadComponentSourceRef(name, sourcePath, propNames = [], propTypes = []) {
4108
+ let content = null;
4109
+ let siblingFiles = [];
4110
+ let truncatedSiblingCount = 0;
4111
+ const usesNotShown = /* @__PURE__ */ new Set();
4112
+ try {
4113
+ const rawText = await readFile4(sourcePath, "utf8");
4114
+ let siblingUsesNotShown;
4115
+ let declaredTypeNames;
4116
+ ({
4117
+ siblings: siblingFiles,
4118
+ truncatedCount: truncatedSiblingCount,
4119
+ usesNotShown: siblingUsesNotShown,
4120
+ declaredTypeNames
4121
+ } = await loadSiblingFiles(rawText, sourcePath, propNames, identifiersIn(propTypes)));
4122
+ const mainExcerpt = excerptAroundNames(rawText, [.../* @__PURE__ */ new Set([...propNames, ...declaredTypeNames])], MAX_COMPONENT_SOURCE_CHARS);
4123
+ content = mainExcerpt.content;
4124
+ for (const name2 of mainExcerpt.usesNotShown)
4125
+ usesNotShown.add(name2);
4126
+ for (const name2 of siblingUsesNotShown)
4127
+ usesNotShown.add(name2);
4128
+ } catch {
4129
+ }
4130
+ const ref = { component: name, sourcePath, content };
4131
+ if (siblingFiles.length > 0)
4132
+ ref.siblingFiles = siblingFiles;
4133
+ if (truncatedSiblingCount > 0)
4134
+ ref.truncatedSiblingCount = truncatedSiblingCount;
4135
+ const notShown = propNames.filter((name2) => usesNotShown.has(name2));
4136
+ if (notShown.length > 0)
4137
+ ref.usesNotShown = notShown;
4138
+ return ref;
4139
+ }
4140
+ async function loadComponentSourceRefs(db, sessionId) {
4141
+ const rows = db.prepare(`SELECT component_id, name, source, source_path FROM raw_components WHERE session_id = ? AND status = 'generated' ORDER BY rowid`).all(sessionId);
4142
+ const propsFor = db.prepare(`SELECT name, type FROM raw_props WHERE session_id = ? AND component_id = ? ORDER BY position`);
4143
+ return Promise.all(rows.map((r) => {
4144
+ const props = propsFor.all(sessionId, r.component_id);
4145
+ return loadComponentSourceRef(r.name, r.source_path ?? r.source, props.map((p) => p.name), props.map((p) => p.type));
4146
+ }));
4147
+ }
4148
+ function renameEmptySlots(db, sessionId, componentId, componentName, slotCount) {
4149
+ const emptySlots = db.prepare(`SELECT name, position FROM raw_slots
4150
+ WHERE session_id = ? AND component_id = ? AND trim(name) = ''
4151
+ ORDER BY position`).all(sessionId, componentId);
4152
+ if (emptySlots.length === 0)
4153
+ return { renames: [], warnings: [] };
4154
+ const renames = [];
4155
+ const warnings = [];
4156
+ const rename4 = db.prepare(`UPDATE raw_slots SET name = ? WHERE session_id = ? AND component_id = ? AND name = ? AND position = ?`);
4157
+ db.exec("BEGIN");
4158
+ try {
4159
+ for (const slot of emptySlots) {
4160
+ const newName = slotCount === 1 ? "children" : `slot_${slot.position}`;
4161
+ rename4.run(newName, sessionId, componentId, slot.name, slot.position);
4162
+ renames.push({ oldName: slot.name, newName });
4163
+ warnings.push(`${componentName}: slot at position ${slot.position} had empty name \u2014 renamed to "${newName}" for classification`);
4164
+ }
4165
+ db.exec("COMMIT");
4166
+ } catch (e) {
4167
+ db.exec("ROLLBACK");
4168
+ throw e;
4169
+ }
4170
+ return { renames, warnings };
4171
+ }
3800
4172
  function parseReviewReasons(raw) {
3801
4173
  try {
3802
4174
  const parsed = JSON.parse(raw ?? "[]");
@@ -4016,6 +4388,9 @@ function applyScopeDecisions(db, sessionId, decisions) {
4016
4388
  }
4017
4389
  db.prepare("UPDATE sessions SET updated_at = ? WHERE id = ?").run(now, sessionId);
4018
4390
  }
4391
+ function findLatestSessionForCommand(db, command) {
4392
+ return getLatestCompletedSessionForCommand(db, command);
4393
+ }
4019
4394
  function seedCDFFromPreviewResponse(db, sessionId, removedItems) {
4020
4395
  if (removedItems.length === 0)
4021
4396
  return 0;
@@ -4083,6 +4458,35 @@ function backfillUnclassifiedProps(db, sessionId) {
4083
4458
  )`).run(sessionId, sessionId);
4084
4459
  return Number(withCategory.changes) + Number(withoutCategory.changes);
4085
4460
  }
4461
+ function computeMapTokensInputHash(db, sessionId, componentSourceRefs = []) {
4462
+ const props = db.prepare(`SELECT rc.name AS component_name, rp.name AS prop_name, rp.cdf_token_kind, rp.default_value
4463
+ FROM raw_props rp
4464
+ JOIN raw_components rc ON rc.session_id = rp.session_id AND rc.component_id = rp.component_id
4465
+ WHERE rp.session_id = ? AND rp.cdf_type = 'token' AND rp.cdf_category = 'design'
4466
+ ORDER BY rc.name, rp.name`).all(sessionId);
4467
+ const tokens = db.prepare(`SELECT path, type FROM raw_tokens WHERE session_id = ? ORDER BY path`).all(sessionId);
4468
+ const defaultMappings = db.prepare("SELECT raw_name, path, source FROM raw_token_name_paths WHERE session_id = ? ORDER BY raw_name").all(sessionId);
4469
+ const payload = {
4470
+ props: props.map((p) => ({
4471
+ component: p.component_name,
4472
+ prop: p.prop_name,
4473
+ tokenKind: p.cdf_token_kind,
4474
+ rawDefault: p.default_value
4475
+ })),
4476
+ tokens,
4477
+ defaultMappings,
4478
+ // The agent's evidence, not just its inputs: a comment or allowlist edit
4479
+ // in a source file (or a sibling it reads) changes the correct answer
4480
+ // without touching props or tokens, so it must invalidate the cache too.
4481
+ sourceRefs: [...componentSourceRefs].sort((a, b) => a.component.localeCompare(b.component)).map((ref) => ({
4482
+ component: ref.component,
4483
+ content: ref.content,
4484
+ siblingFiles: (ref.siblingFiles ?? []).map((s) => ({ path: s.path, content: s.content })).sort((a, b) => a.path.localeCompare(b.path)),
4485
+ usesNotShown: [...ref.usesNotShown ?? []].sort()
4486
+ }))
4487
+ };
4488
+ return createHash5("sha256").update(JSON.stringify(payload)).digest("hex");
4489
+ }
4086
4490
  function lookupCache(db, inputHash, entityType, entityId, promptHash = "") {
4087
4491
  const row = db.prepare(`SELECT input_hash, entity_type, entity_id, source_session_id, human_edited, created_at, updated_at, prompt_hash
4088
4492
  FROM generation_cache
@@ -4100,6 +4504,24 @@ function lookupCache(db, inputHash, entityType, entityId, promptHash = "") {
4100
4504
  updatedAt: row.updated_at
4101
4505
  };
4102
4506
  }
4507
+ function lookupCacheByEntity(db, entityType, entityId) {
4508
+ const row = db.prepare(`SELECT input_hash, entity_type, entity_id, source_session_id, human_edited, created_at, updated_at, prompt_hash
4509
+ FROM generation_cache
4510
+ WHERE entity_type = ? AND entity_id = ?
4511
+ ORDER BY updated_at DESC LIMIT 1`).get(entityType, entityId);
4512
+ if (!row)
4513
+ return null;
4514
+ return {
4515
+ inputHash: row.input_hash,
4516
+ entityType: row.entity_type,
4517
+ entityId: row.entity_id,
4518
+ sourceSessionId: row.source_session_id,
4519
+ humanEdited: row.human_edited === 1,
4520
+ promptHash: row.prompt_hash,
4521
+ createdAt: row.created_at,
4522
+ updatedAt: row.updated_at
4523
+ };
4524
+ }
4103
4525
  function storeCache(db, inputHash, entityType, entityId, sourceSessionId, humanEdited, promptHash = "") {
4104
4526
  storeCaches(db, [{ inputHash, entityType, entityId, sourceSessionId, humanEdited, promptHash }]);
4105
4527
  }
@@ -4162,6 +4584,95 @@ function loadSlotCycles(db, sessionId) {
4162
4584
  suggestedBreak: r.suggested_break_json ? JSON.parse(r.suggested_break_json) : null
4163
4585
  }));
4164
4586
  }
4587
+ function findUnknownSlotAllowedComponents(db, sessionId, allowedComponentNames2, componentId) {
4588
+ const rows = db.prepare(`SELECT a.component_id, c.name AS component_name, a.slot_name, a.allowed_component
4589
+ FROM raw_slot_allowed_components a
4590
+ JOIN raw_components c ON c.session_id = a.session_id AND c.component_id = a.component_id
4591
+ WHERE a.session_id = ? AND (? IS NULL OR a.component_id = ?)
4592
+ ORDER BY a.component_id, a.slot_name, a.position`).all(sessionId, componentId ?? null, componentId ?? null);
4593
+ return rows.filter((row) => !allowedComponentNames2.has(row.allowed_component)).map((row) => ({
4594
+ componentId: row.component_id,
4595
+ componentName: row.component_name,
4596
+ slotName: row.slot_name,
4597
+ allowedComponent: row.allowed_component
4598
+ }));
4599
+ }
4600
+ function filterUnknownSlotAllowedComponents(db, sessionId, allowedComponentNames2) {
4601
+ const unknown5 = findUnknownSlotAllowedComponents(db, sessionId, allowedComponentNames2);
4602
+ if (unknown5.length === 0)
4603
+ return unknown5;
4604
+ db.exec("BEGIN");
4605
+ try {
4606
+ const remove = db.prepare(`DELETE FROM raw_slot_allowed_components
4607
+ WHERE session_id = ? AND component_id = ? AND slot_name = ? AND allowed_component = ?`);
4608
+ for (const row of unknown5) {
4609
+ remove.run(sessionId, row.componentId, row.slotName, row.allowedComponent);
4610
+ }
4611
+ db.exec("COMMIT");
4612
+ } catch (e) {
4613
+ db.exec("ROLLBACK");
4614
+ throw e;
4615
+ }
4616
+ return unknown5;
4617
+ }
4618
+ function copyComponentFromCache(db, sourceSessionId, targetSessionId, componentId, manageTransaction = true, options = {}) {
4619
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4620
+ if (manageTransaction)
4621
+ db.exec("BEGIN");
4622
+ try {
4623
+ const srcComp = db.prepare(`SELECT description, status, component_description_rationale, props_rationale, slots_rationale
4624
+ FROM raw_components WHERE session_id = ? AND component_id = ?`).get(sourceSessionId, componentId);
4625
+ if (srcComp) {
4626
+ db.prepare(`UPDATE raw_components
4627
+ SET description = ?, status = ?, component_description_rationale = ?, props_rationale = ?, slots_rationale = ?, extracted_at = ?
4628
+ WHERE session_id = ? AND component_id = ?`).run(srcComp.description, srcComp.status, srcComp.component_description_rationale, srcComp.props_rationale, srcComp.slots_rationale, now, targetSessionId, componentId);
4629
+ }
4630
+ const srcProps = db.prepare(`SELECT name, cdf_type, cdf_category, cdf_token_kind, required, description, default_value, rationale
4631
+ FROM raw_props WHERE session_id = ? AND component_id = ?`).all(sourceSessionId, componentId);
4632
+ for (const p of srcProps) {
4633
+ db.prepare(`UPDATE raw_props SET cdf_type = ?, cdf_category = ?, cdf_token_kind = ?, required = ?, description = ?, default_value = ?, rationale = ?
4634
+ WHERE session_id = ? AND component_id = ? AND name = ?`).run(p.cdf_type, p.cdf_category, p.cdf_token_kind, p.required, p.description, p.default_value, p.rationale, targetSessionId, componentId, p.name);
4635
+ }
4636
+ db.prepare(`DELETE FROM raw_prop_allowed_values WHERE session_id = ? AND component_id = ?`).run(targetSessionId, componentId);
4637
+ const srcAV = db.prepare(`SELECT prop_name, position, value FROM raw_prop_allowed_values WHERE session_id = ? AND component_id = ?`).all(sourceSessionId, componentId);
4638
+ const insertAV = db.prepare(`INSERT INTO raw_prop_allowed_values (session_id, component_id, prop_name, position, value) VALUES (?, ?, ?, ?, ?)`);
4639
+ for (const av of srcAV) {
4640
+ insertAV.run(targetSessionId, componentId, av.prop_name, av.position, av.value);
4641
+ }
4642
+ const srcSlots = db.prepare(`SELECT name, required, description, rationale FROM raw_slots WHERE session_id = ? AND component_id = ?`).all(sourceSessionId, componentId);
4643
+ for (const s of srcSlots) {
4644
+ db.prepare(`UPDATE raw_slots SET required = ?, description = ?, rationale = ? WHERE session_id = ? AND component_id = ? AND name = ?`).run(s.required, s.description, s.rationale, targetSessionId, componentId, s.name);
4645
+ }
4646
+ db.prepare(`DELETE FROM raw_slot_allowed_components WHERE session_id = ? AND component_id = ?`).run(targetSessionId, componentId);
4647
+ const srcSAC = db.prepare(`SELECT slot_name, position, allowed_component FROM raw_slot_allowed_components WHERE session_id = ? AND component_id = ?`).all(sourceSessionId, componentId);
4648
+ const insertSAC = db.prepare(`INSERT INTO raw_slot_allowed_components (session_id, component_id, slot_name, allowed_component, position) VALUES (?, ?, ?, ?, ?)`);
4649
+ const allowedSAC = options.allowedComponentNames ? srcSAC.filter((sac) => options.allowedComponentNames.has(sac.allowed_component)) : srcSAC;
4650
+ for (const sac of allowedSAC) {
4651
+ insertSAC.run(targetSessionId, componentId, sac.slot_name, sac.allowed_component, sac.position);
4652
+ }
4653
+ db.prepare("UPDATE sessions SET updated_at = ? WHERE id = ?").run(now, targetSessionId);
4654
+ if (manageTransaction)
4655
+ db.exec("COMMIT");
4656
+ } catch (e) {
4657
+ if (manageTransaction)
4658
+ db.exec("ROLLBACK");
4659
+ throw e;
4660
+ }
4661
+ }
4662
+ function copyComponentsFromCache(db, entries, options = {}) {
4663
+ if (entries.length === 0)
4664
+ return;
4665
+ db.exec("BEGIN");
4666
+ try {
4667
+ for (const entry of entries) {
4668
+ copyComponentFromCache(db, entry.sourceSessionId, entry.targetSessionId, entry.componentId, false, options);
4669
+ }
4670
+ db.exec("COMMIT");
4671
+ } catch (e) {
4672
+ db.exec("ROLLBACK");
4673
+ throw e;
4674
+ }
4675
+ }
4165
4676
  function copyTokensFromCache(db, sourceSessionId, targetSessionId) {
4166
4677
  const now = (/* @__PURE__ */ new Date()).toISOString();
4167
4678
  db.exec("BEGIN");
@@ -4179,17 +4690,57 @@ function copyTokensFromCache(db, sourceSessionId, targetSessionId) {
4179
4690
  throw e;
4180
4691
  }
4181
4692
  }
4693
+ function copyMapTokensFromCache(db, sourceSessionId, targetSessionId) {
4694
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4695
+ let copiedCount = 0;
4696
+ db.exec("BEGIN");
4697
+ try {
4698
+ const sourceRows = db.prepare(`SELECT rc.name AS component_name, rptp.prop_name, rptp.source, rptp.position, rptp.path
4699
+ FROM raw_prop_token_paths rptp
4700
+ JOIN raw_components rc ON rc.session_id = rptp.session_id AND rc.component_id = rptp.component_id
4701
+ WHERE rptp.session_id = ?
4702
+ ORDER BY rc.name, rptp.prop_name, rptp.position`).all(sourceSessionId);
4703
+ const targetComponents = db.prepare(`SELECT component_id, name FROM raw_components WHERE session_id = ?`).all(targetSessionId);
4704
+ const targetIdByName = new Map(targetComponents.map((c2) => [c2.name, c2.component_id]));
4705
+ const targetProps = new Set(db.prepare(`SELECT component_id, name FROM raw_props WHERE session_id = ?`).all(targetSessionId).map((p) => `${p.component_id}::${p.name}`));
4706
+ const insertPath = db.prepare(`INSERT INTO raw_prop_token_paths (session_id, component_id, prop_name, source, position, path)
4707
+ VALUES (?, ?, ?, ?, ?, ?)`);
4708
+ const clearedProps = /* @__PURE__ */ new Set();
4709
+ const copiedProps = /* @__PURE__ */ new Set();
4710
+ for (const row of sourceRows) {
4711
+ const targetComponentId = targetIdByName.get(row.component_name);
4712
+ if (!targetComponentId)
4713
+ continue;
4714
+ if (!targetProps.has(`${targetComponentId}::${row.prop_name}`))
4715
+ continue;
4716
+ const propKey = `${targetComponentId}::${row.prop_name}`;
4717
+ if (!clearedProps.has(propKey)) {
4718
+ clearedProps.add(propKey);
4719
+ db.prepare(`DELETE FROM raw_prop_token_paths WHERE session_id = ? AND component_id = ? AND prop_name = ?`).run(targetSessionId, targetComponentId, row.prop_name);
4720
+ }
4721
+ insertPath.run(targetSessionId, targetComponentId, row.prop_name, row.source, row.position, row.path);
4722
+ copiedProps.add(propKey);
4723
+ }
4724
+ copiedCount = copiedProps.size;
4725
+ db.prepare("UPDATE sessions SET updated_at = ? WHERE id = ?").run(now, targetSessionId);
4726
+ db.exec("COMMIT");
4727
+ } catch (e) {
4728
+ db.exec("ROLLBACK");
4729
+ throw e;
4730
+ }
4731
+ return copiedCount;
4732
+ }
4182
4733
  async function getCliCacheVersion() {
4183
4734
  if (_cliCacheVersionCache)
4184
4735
  return _cliCacheVersionCache;
4185
4736
  try {
4186
4737
  const { hashContent: hashContent3 } = await Promise.resolve().then(() => (init_cache_keys(), cache_keys_exports));
4187
- const { resolveSkillPath: resolveSkillPath3 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
4738
+ const { resolveSkillPath: resolveSkillPath2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
4188
4739
  const skills = ["components", "tokens", "select"];
4189
4740
  const parts = [];
4190
4741
  for (const s of skills) {
4191
4742
  try {
4192
- const p = resolveSkillPath3(s);
4743
+ const p = resolveSkillPath2(s);
4193
4744
  parts.push(readFileSync3(p, "utf8"));
4194
4745
  } catch {
4195
4746
  parts.push(`<missing:${s}>`);
@@ -4270,7 +4821,7 @@ function lookupSelectCache(db, componentHash, promptHash, cliVersion) {
4270
4821
  updatedAt: row.updated_at
4271
4822
  };
4272
4823
  }
4273
- var SCHEMA, _cliCacheVersionCache;
4824
+ var SCHEMA, MAX_COMPONENT_SOURCE_CHARS, MAX_SIBLING_FILES, MAX_SIBLING_SNIPPET_CHARS, MAX_TYPE_DECLARING_SIBLING_CHARS, MAX_ENLARGED_SIBLINGS, MAX_SIBLING_DEPTH, MAX_SIBLING_CANDIDATES_EXPLORED, RELATIVE_IMPORT_PATTERN, SIBLING_FILE_EXTENSIONS, TS_ESM_EXTENSION_REWRITES, IDENTIFIER_PATTERN, _cliCacheVersionCache;
4274
4825
  var init_db = __esm({
4275
4826
  "packages/experience-design-system-backend-pipeline/dist/src/persistence/src/session/repositories/db.js"() {
4276
4827
  "use strict";
@@ -4469,6 +5020,22 @@ CREATE INDEX IF NOT EXISTS idx_generation_cache_entity ON generation_cache(enti
4469
5020
  CREATE INDEX IF NOT EXISTS idx_generation_cache_session ON generation_cache(source_session_id);
4470
5021
  CREATE INDEX IF NOT EXISTS idx_scanned_files_session ON scanned_files(session_id);
4471
5022
  `;
5023
+ MAX_COMPONENT_SOURCE_CHARS = 8e3;
5024
+ MAX_SIBLING_FILES = 5;
5025
+ MAX_SIBLING_SNIPPET_CHARS = 1200;
5026
+ MAX_TYPE_DECLARING_SIBLING_CHARS = 4e3;
5027
+ MAX_ENLARGED_SIBLINGS = 2;
5028
+ MAX_SIBLING_DEPTH = 2;
5029
+ MAX_SIBLING_CANDIDATES_EXPLORED = 25;
5030
+ RELATIVE_IMPORT_PATTERN = /from\s+['"](\.[^'"]+)['"]/g;
5031
+ SIBLING_FILE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx"];
5032
+ TS_ESM_EXTENSION_REWRITES = [
5033
+ [".js", [".ts", ".tsx", ".js", ".jsx"]],
5034
+ [".jsx", [".tsx", ".jsx"]],
5035
+ [".mjs", [".mts", ".mjs"]],
5036
+ [".cjs", [".cts", ".cjs"]]
5037
+ ];
5038
+ IDENTIFIER_PATTERN = /[A-Za-z_$][A-Za-z0-9_$]*/g;
4472
5039
  _cliCacheVersionCache = null;
4473
5040
  }
4474
5041
  });
@@ -4953,7 +5520,7 @@ var init_extract_tsx_components = __esm({
4953
5520
  });
4954
5521
 
4955
5522
  // packages/experience-design-system-backend-pipeline/dist/src/steps/extraction/src/framework-adapters/shared/file-extraction-workers.js
4956
- import { readFile as readFile4 } from "node:fs/promises";
5523
+ import { readFile as readFile5 } from "node:fs/promises";
4957
5524
  async function runFileExtractionWorkers(filePaths, concurrency, extractFile, formatError, onProgress, onResult) {
4958
5525
  const warnings = [];
4959
5526
  const items = [];
@@ -4965,7 +5532,7 @@ async function runFileExtractionWorkers(filePaths, concurrency, extractFile, for
4965
5532
  if (!filePath)
4966
5533
  break;
4967
5534
  try {
4968
- const source = await readFile4(filePath, "utf-8");
5535
+ const source = await readFile5(filePath, "utf-8");
4969
5536
  const outcome = await extractFile(filePath, source);
4970
5537
  warnings.push(...outcome.warnings ?? []);
4971
5538
  if (outcome.item)
@@ -8053,7 +8620,7 @@ var init_resolve_type_property = __esm({
8053
8620
  // packages/experience-design-system-backend-pipeline/dist/src/steps/extraction/src/framework-adapters/vue/extract-vue-components.js
8054
8621
  import os from "node:os";
8055
8622
  import { basename, dirname as dirname7, resolve as resolve9, join as join9 } from "node:path";
8056
- import { readFile as readFile5 } from "node:fs/promises";
8623
+ import { readFile as readFile6 } from "node:fs/promises";
8057
8624
  import { existsSync as existsSync7, readFileSync as readFileSync5, readdirSync, statSync as statSync3 } from "node:fs";
8058
8625
  import { parse as parseSFC } from "@vue/compiler-sfc";
8059
8626
  import { Project as Project3, Node as Node6 } from "ts-morph";
@@ -8240,7 +8807,7 @@ async function extractNamedObjectExportProps(importedRef, visitedImports) {
8240
8807
  if (visitedImports.has(visitKey))
8241
8808
  return [];
8242
8809
  visitedImports.add(visitKey);
8243
- const source = await readFile5(importedRef.filePath, "utf-8");
8810
+ const source = await readFile6(importedRef.filePath, "utf-8");
8244
8811
  const project = new Project3({
8245
8812
  compilerOptions: {
8246
8813
  strict: false,
@@ -8469,7 +9036,7 @@ async function extractOptionsProps(filePath, scriptContent, visited = /* @__PURE
8469
9036
  return [];
8470
9037
  }
8471
9038
  async function extractInheritedVueProps(filePath, visited) {
8472
- const source = await readFile5(filePath, "utf-8");
9039
+ const source = await readFile6(filePath, "utf-8");
8473
9040
  const { descriptor } = parseSFC(source);
8474
9041
  if (!descriptor.script) {
8475
9042
  return [];
@@ -11767,9 +12334,9 @@ var init_candidate_files2 = __esm({
11767
12334
  });
11768
12335
 
11769
12336
  // packages/experience-design-system-backend-pipeline/dist/src/steps/composition/src/helpers/candidates/composition-cache-key.js
11770
- import { createHash as createHash5 } from "node:crypto";
12337
+ import { createHash as createHash6 } from "node:crypto";
11771
12338
  function hashContent2(content) {
11772
- return createHash5("sha256").update(content).digest("hex");
12339
+ return createHash6("sha256").update(content).digest("hex");
11773
12340
  }
11774
12341
  function buildCompositionInputHash(input) {
11775
12342
  const fileDigest = input.files.map((f) => `${f.path} ${hashContent2(f.content)}`).sort().join("");
@@ -12480,9 +13047,9 @@ var init_validate3 = __esm({
12480
13047
  });
12481
13048
 
12482
13049
  // packages/experience-design-system-backend-pipeline/dist/src/persistence/src/review-session/helpers/create-component-id.js
12483
- import { createHash as createHash6 } from "node:crypto";
13050
+ import { createHash as createHash7 } from "node:crypto";
12484
13051
  function createComponentId(name, resolvedSourcePath) {
12485
- const sourceHash = createHash6("sha256").update(`${name}:${resolvedSourcePath}`).digest("hex").slice(0, 12);
13052
+ const sourceHash = createHash7("sha256").update(`${name}:${resolvedSourcePath}`).digest("hex").slice(0, 12);
12486
13053
  return `${name}-${sourceHash}`;
12487
13054
  }
12488
13055
  var init_create_component_id = __esm({
@@ -12591,13 +13158,13 @@ var init_review_session_paths = __esm({
12591
13158
  });
12592
13159
 
12593
13160
  // packages/experience-design-system-backend-pipeline/dist/src/persistence/src/review-session/repositories/ensure-review-session.js
12594
- import { access as access2, mkdir, readFile as readFile6, writeFile } from "node:fs/promises";
13161
+ import { access as access2, mkdir, readFile as readFile7, writeFile } from "node:fs/promises";
12595
13162
  async function ensureRefineSession(sessionId, artifactsRoot, initialSnapshot) {
12596
13163
  const paths = await getRefineSessionPaths(sessionId, artifactsRoot);
12597
13164
  await mkdir(paths.sessionDir, { recursive: true });
12598
13165
  try {
12599
13166
  await access2(paths.statePath);
12600
- const savedState = await readFile6(paths.statePath, "utf8");
13167
+ const savedState = await readFile7(paths.statePath, "utf8");
12601
13168
  return JSON.parse(savedState);
12602
13169
  } catch {
12603
13170
  await writeFile(paths.statePath, JSON.stringify(initialSnapshot, null, 2), "utf8");
@@ -12639,14 +13206,14 @@ var init_save_review_state = __esm({
12639
13206
  });
12640
13207
 
12641
13208
  // packages/experience-design-system-backend-pipeline/dist/src/steps/selection/src/controller/review/merge-preview-validation-errors-into-review-session.js
12642
- import { access as access3, readFile as readFile7 } from "node:fs/promises";
13209
+ import { access as access3, readFile as readFile8 } from "node:fs/promises";
12643
13210
  async function mergePreviewValidationErrorsIntoReviewSession(sessionId, errors, opts = {}) {
12644
13211
  const artifactsRoot = opts.artifactsRoot ?? getRefineArtifactsRoot();
12645
13212
  const paths = await getRefineSessionPaths(sessionId, artifactsRoot);
12646
13213
  let snapshot;
12647
13214
  try {
12648
13215
  await access3(paths.statePath);
12649
- snapshot = JSON.parse(await readFile7(paths.statePath, "utf8"));
13216
+ snapshot = JSON.parse(await readFile8(paths.statePath, "utf8"));
12650
13217
  } catch {
12651
13218
  snapshot = await loadAndValidateForReview(sessionId, void 0);
12652
13219
  snapshot = await ensureRefineSession(sessionId, artifactsRoot, snapshot);
@@ -12694,7 +13261,7 @@ var init_merge_preview_validation_errors_into_review_session = __esm({
12694
13261
  });
12695
13262
 
12696
13263
  // packages/experience-design-system-backend-pipeline/dist/src/steps/selection/src/controller/review/reject-components-by-name.js
12697
- import { readFile as readFile8 } from "node:fs/promises";
13264
+ import { readFile as readFile9 } from "node:fs/promises";
12698
13265
  async function rejectComponentsByName(sessionId, names, opts = {}) {
12699
13266
  if (names.length === 0)
12700
13267
  return;
@@ -12710,7 +13277,7 @@ async function rejectComponentsByName(sessionId, names, opts = {}) {
12710
13277
  const nameSet = new Set(names);
12711
13278
  let snapshot;
12712
13279
  try {
12713
- snapshot = JSON.parse(await readFile8(paths.statePath, "utf8"));
13280
+ snapshot = JSON.parse(await readFile9(paths.statePath, "utf8"));
12714
13281
  } catch {
12715
13282
  return;
12716
13283
  }
@@ -13071,10 +13638,10 @@ var init_run_record = __esm({
13071
13638
  });
13072
13639
 
13073
13640
  // packages/experience-design-system-backend-pipeline/dist/src/persistence/src/runs/repositories/read-runs-file.js
13074
- import { readFile as readFile9 } from "node:fs/promises";
13641
+ import { readFile as readFile10 } from "node:fs/promises";
13075
13642
  async function readRunsFileMaybe() {
13076
13643
  try {
13077
- const raw = await readFile9(runsFilePath(), "utf8");
13644
+ const raw = await readFile10(runsFilePath(), "utf8");
13078
13645
  const parsed = JSON.parse(raw);
13079
13646
  if (!READABLE_VERSIONS.has(parsed.version)) {
13080
13647
  throw new Error(`runs.json version mismatch: file is v${parsed.version}, this CLI expects v${RUNS_FILE_VERSION} (also reads: ${[...READABLE_VERSIONS].join(", ")}). Back up and remove the file to start fresh.`);
@@ -13183,9 +13750,9 @@ var init_update_run = __esm({
13183
13750
  });
13184
13751
 
13185
13752
  // packages/experience-design-system-backend-pipeline/dist/src/persistence/src/runs/helpers/sha256-hex.js
13186
- import { createHash as createHash7 } from "node:crypto";
13753
+ import { createHash as createHash8 } from "node:crypto";
13187
13754
  function sha256Hex(buf) {
13188
- return createHash7("sha256").update(buf).digest("hex");
13755
+ return createHash8("sha256").update(buf).digest("hex");
13189
13756
  }
13190
13757
  var init_sha256_hex = __esm({
13191
13758
  "packages/experience-design-system-backend-pipeline/dist/src/persistence/src/runs/helpers/sha256-hex.js"() {
@@ -13194,7 +13761,7 @@ var init_sha256_hex = __esm({
13194
13761
  });
13195
13762
 
13196
13763
  // packages/experience-design-system-backend-pipeline/dist/src/persistence/src/runs/services/build-source-fingerprint.js
13197
- import { readFile as readFile10, stat } from "node:fs/promises";
13764
+ import { readFile as readFile11, stat } from "node:fs/promises";
13198
13765
  import { resolve as resolve17 } from "node:path";
13199
13766
  function rowField(row, key) {
13200
13767
  const v = row[key];
@@ -13229,7 +13796,7 @@ async function buildSourceFingerprint(opts) {
13229
13796
  const abs = resolve17(opts.rawTokensPath);
13230
13797
  rawTokensPath = abs;
13231
13798
  try {
13232
- const [st, buf] = await Promise.all([stat(abs), readFile10(abs)]);
13799
+ const [st, buf] = await Promise.all([stat(abs), readFile11(abs)]);
13233
13800
  rawTokensMtime = st.mtime.toISOString();
13234
13801
  rawTokensContentHash = sha256Hex(buf);
13235
13802
  } catch {
@@ -13394,6 +13961,21 @@ var init_write_scope_decisions_snapshot = __esm({
13394
13961
  });
13395
13962
 
13396
13963
  // packages/experience-design-system-backend-pipeline/dist/src/persistence/src/review-session/repositories/load-accepted-names.js
13964
+ import { readFile as readFile12 } from "node:fs/promises";
13965
+ async function loadAcceptedNames(sessionId) {
13966
+ try {
13967
+ const artifactsRoot = getRefineArtifactsRoot();
13968
+ const paths = await getRefineSessionPaths(sessionId, artifactsRoot);
13969
+ const raw = await readFile12(paths.statePath, "utf8");
13970
+ const snapshot = JSON.parse(raw);
13971
+ const accepted = snapshot.components.filter((c2) => c2.status === "accepted").map((c2) => c2.name);
13972
+ if (accepted.length === 0)
13973
+ return null;
13974
+ return new Set(accepted);
13975
+ } catch {
13976
+ return null;
13977
+ }
13978
+ }
13397
13979
  var init_load_accepted_names = __esm({
13398
13980
  "packages/experience-design-system-backend-pipeline/dist/src/persistence/src/review-session/repositories/load-accepted-names.js"() {
13399
13981
  "use strict";
@@ -14319,7 +14901,7 @@ function errorMessage(error) {
14319
14901
  return error instanceof Error && error.message ? error.message : String(error);
14320
14902
  }
14321
14903
  function defaultSleep(delayMs) {
14322
- return new Promise((resolve22) => setTimeout(resolve22, delayMs));
14904
+ return new Promise((resolve25) => setTimeout(resolve25, delayMs));
14323
14905
  }
14324
14906
  var MAX_RETRY_AFTER_MS;
14325
14907
  var init_http_utils = __esm({
@@ -14595,7 +15177,7 @@ var init_api_client = __esm({
14595
15177
  const progress = maxAttempts > 1 ? attempt / (maxAttempts - 1) : 0;
14596
15178
  const baseDelay = intervalMs + (maxIntervalMs - intervalMs) * progress;
14597
15179
  const jitter = Math.random() * baseDelay * 0.15;
14598
- await new Promise((resolve22) => setTimeout(resolve22, baseDelay + jitter));
15180
+ await new Promise((resolve25) => setTimeout(resolve25, baseDelay + jitter));
14599
15181
  }
14600
15182
  }
14601
15183
  throw new Error(`Operation ${operationId} timed out after ${maxAttempts} attempts`);
@@ -15282,7 +15864,7 @@ var init_collect_json_files = __esm({
15282
15864
  });
15283
15865
 
15284
15866
  // packages/experience-design-system-backend-pipeline/dist/src/steps/apply/src/helpers/tokens/read-tokens-from-path.js
15285
- import { readFile as readFile11, stat as stat3 } from "node:fs/promises";
15867
+ import { readFile as readFile13, stat as stat3 } from "node:fs/promises";
15286
15868
  async function readTokensFromPath(flag, p) {
15287
15869
  let s;
15288
15870
  try {
@@ -15305,7 +15887,7 @@ async function readMergedFromDir(flag, dir) {
15305
15887
  const merged = {};
15306
15888
  for (const file of files.sort()) {
15307
15889
  try {
15308
- const text = await readFile11(file, "utf8");
15890
+ const text = await readFile13(file, "utf8");
15309
15891
  const parsed = JSON.parse(text);
15310
15892
  if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
15311
15893
  Object.assign(merged, parsed);
@@ -15319,7 +15901,7 @@ async function readMergedFromDir(flag, dir) {
15319
15901
  async function readSingleFile(flag, p) {
15320
15902
  let text;
15321
15903
  try {
15322
- text = await readFile11(p, "utf8");
15904
+ text = await readFile13(p, "utf8");
15323
15905
  } catch {
15324
15906
  throw new Error(`file not found: ${p} (from ${flag})`);
15325
15907
  }
@@ -15425,6 +16007,20 @@ var init_fetch_and_persist = __esm({
15425
16007
  });
15426
16008
 
15427
16009
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/controller/existing-entities/read-from-session.js
16010
+ import { readFile as readFile14 } from "node:fs/promises";
16011
+ async function readExistingContentfulEntitiesFromSession(request) {
16012
+ if (!request.path)
16013
+ return void 0;
16014
+ try {
16015
+ const raw = await readFile14(request.path, "utf8");
16016
+ const parsed = JSON.parse(raw);
16017
+ if (!Array.isArray(parsed.components) || !Array.isArray(parsed.tokens))
16018
+ return void 0;
16019
+ return parsed;
16020
+ } catch {
16021
+ return void 0;
16022
+ }
16023
+ }
15428
16024
  var init_read_from_session = __esm({
15429
16025
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/controller/existing-entities/read-from-session.js"() {
15430
16026
  "use strict";
@@ -15432,6 +16028,12 @@ var init_read_from_session = __esm({
15432
16028
  });
15433
16029
 
15434
16030
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/summarizers/summarize-tokens.js
16031
+ function summarizeTokens(tokens) {
16032
+ const kinds = /* @__PURE__ */ new Set();
16033
+ for (const t of tokens)
16034
+ kinds.add(t.type);
16035
+ return { count: tokens.length, kinds: [...kinds].sort() };
16036
+ }
15435
16037
  var init_summarize_tokens = __esm({
15436
16038
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/summarizers/summarize-tokens.js"() {
15437
16039
  "use strict";
@@ -15447,6 +16049,29 @@ var init_summarize_for_select = __esm({
15447
16049
  });
15448
16050
 
15449
16051
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/existing-entities/count-character-edits.js
16052
+ function countCharacterEdits(a, b) {
16053
+ if (a === b)
16054
+ return 0;
16055
+ if (a.length === 0)
16056
+ return b.length;
16057
+ if (b.length === 0)
16058
+ return a.length;
16059
+ if (a.length > b.length)
16060
+ [a, b] = [b, a];
16061
+ let prev = new Array(a.length + 1);
16062
+ let curr = new Array(a.length + 1);
16063
+ for (let i = 0; i <= a.length; i++)
16064
+ prev[i] = i;
16065
+ for (let j = 1; j <= b.length; j++) {
16066
+ curr[0] = j;
16067
+ for (let i = 1; i <= a.length; i++) {
16068
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
16069
+ curr[i] = Math.min(curr[i - 1] + 1, prev[i] + 1, prev[i - 1] + cost);
16070
+ }
16071
+ [prev, curr] = [curr, prev];
16072
+ }
16073
+ return prev[a.length];
16074
+ }
15450
16075
  var init_count_character_edits = __esm({
15451
16076
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/existing-entities/count-character-edits.js"() {
15452
16077
  "use strict";
@@ -15454,6 +16079,10 @@ var init_count_character_edits = __esm({
15454
16079
  });
15455
16080
 
15456
16081
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/existing-entities/simplify-name-for-comparison.js
16082
+ function simplifyNameForComparison(name) {
16083
+ const stripped = name.toLowerCase().replace(/[^a-z0-9]/g, "");
16084
+ return stripped.endsWith("s") && stripped.length > 1 ? stripped.slice(0, -1) : stripped;
16085
+ }
15457
16086
  var init_simplify_name_for_comparison = __esm({
15458
16087
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/existing-entities/simplify-name-for-comparison.js"() {
15459
16088
  "use strict";
@@ -15461,15 +16090,56 @@ var init_simplify_name_for_comparison = __esm({
15461
16090
  });
15462
16091
 
15463
16092
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/existing-entities/find-nearly-matching-component.js
16093
+ function findNearlyMatchingComponent(components, codebaseName) {
16094
+ const target = simplifyNameForComparison(codebaseName);
16095
+ if (!target)
16096
+ return void 0;
16097
+ let best;
16098
+ for (const c2 of components) {
16099
+ const edits = countCharacterEdits(target, simplifyNameForComparison(c2.name));
16100
+ if (edits > MAX_CHARACTER_EDITS_FOR_LIKELY_MATCH)
16101
+ continue;
16102
+ if (!best || edits < best.edits)
16103
+ best = { component: c2, edits };
16104
+ if (edits === 0)
16105
+ break;
16106
+ }
16107
+ return best?.component;
16108
+ }
16109
+ var MAX_CHARACTER_EDITS_FOR_LIKELY_MATCH;
15464
16110
  var init_find_nearly_matching_component = __esm({
15465
16111
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/existing-entities/find-nearly-matching-component.js"() {
15466
16112
  "use strict";
15467
16113
  init_count_character_edits();
15468
16114
  init_simplify_name_for_comparison();
16115
+ MAX_CHARACTER_EDITS_FOR_LIKELY_MATCH = 2;
15469
16116
  }
15470
16117
  });
15471
16118
 
15472
16119
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/controller/existing-entities/summarize-for-generate.js
16120
+ function summarizeForGenerateAgent(entities, codebaseComponentName) {
16121
+ const match2 = findNearlyMatchingComponent(entities.components, codebaseComponentName);
16122
+ const otherComponents = entities.components.filter((c2) => c2.sys.id !== match2?.sys.id).map((c2) => ({ id: c2.sys.id, name: c2.name }));
16123
+ return {
16124
+ likelyMatch: match2 ? {
16125
+ id: match2.sys.id,
16126
+ name: match2.name,
16127
+ designProperties: match2.designProperties.map((p) => ({
16128
+ id: p.id,
16129
+ name: p.name,
16130
+ type: p.type
16131
+ })),
16132
+ contentProperties: match2.contentProperties.map((p) => ({
16133
+ id: p.id,
16134
+ name: p.name,
16135
+ type: p.type
16136
+ })),
16137
+ slots: (match2.slots ?? []).map((s) => ({ id: s.id, name: s.name }))
16138
+ } : void 0,
16139
+ otherComponents,
16140
+ tokens: summarizeTokens(entities.tokens)
16141
+ };
16142
+ }
15473
16143
  var init_summarize_for_generate = __esm({
15474
16144
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/controller/existing-entities/summarize-for-generate.js"() {
15475
16145
  "use strict";
@@ -15479,6 +16149,11 @@ var init_summarize_for_generate = __esm({
15479
16149
  });
15480
16150
 
15481
16151
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/controller/existing-entities/summarize-for-map-tokens.js
16152
+ function summarizeForMapTokens(request) {
16153
+ return {
16154
+ tokens: request.entities.tokens.map((t) => ({ id: t.sys.id, name: t.name, type: t.type }))
16155
+ };
16156
+ }
15482
16157
  var init_summarize_for_map_tokens = __esm({
15483
16158
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/controller/existing-entities/summarize-for-map-tokens.js"() {
15484
16159
  "use strict";
@@ -15486,6 +16161,9 @@ var init_summarize_for_map_tokens = __esm({
15486
16161
  });
15487
16162
 
15488
16163
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/token-defaults/normalize-token-key.js
16164
+ function normalizeTokenKey(key) {
16165
+ return key.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").replace(/[ _]+/g, "-").toLowerCase();
16166
+ }
15489
16167
  var init_normalize_token_key = __esm({
15490
16168
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/token-defaults/normalize-token-key.js"() {
15491
16169
  "use strict";
@@ -15493,6 +16171,11 @@ var init_normalize_token_key = __esm({
15493
16171
  });
15494
16172
 
15495
16173
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/token-defaults/terminal-member.js
16174
+ function terminalMember(reference) {
16175
+ if (!/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/.test(reference))
16176
+ return void 0;
16177
+ return reference.slice(reference.lastIndexOf(".") + 1);
16178
+ }
15496
16179
  var init_terminal_member = __esm({
15497
16180
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/token-defaults/terminal-member.js"() {
15498
16181
  "use strict";
@@ -15500,6 +16183,114 @@ var init_terminal_member = __esm({
15500
16183
  });
15501
16184
 
15502
16185
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/token-defaults/resolve-token-defaults.js
16186
+ function describeType(tokenKind) {
16187
+ return tokenKind === null ? "the property type" : `a ${tokenKind} token`;
16188
+ }
16189
+ function resolveTokenDefaults(defaults, leaves) {
16190
+ const leavesByPath = new Map(leaves.map((leaf) => [leaf.path, leaf]));
16191
+ const leavesByNormalizedKey = buildNormalizedIndex(leaves);
16192
+ const outcomesByRawDefault = /* @__PURE__ */ new Map();
16193
+ const diagnostics = [];
16194
+ const outcomesFor = (rawDefault) => {
16195
+ const outcomes = outcomesByRawDefault.get(rawDefault) ?? { resolvedPaths: [], diagnostics: [] };
16196
+ outcomesByRawDefault.set(rawDefault, outcomes);
16197
+ return outcomes;
16198
+ };
16199
+ const recordResolvedPath = (rawDefault, path5) => {
16200
+ outcomesFor(rawDefault).resolvedPaths.push(path5);
16201
+ };
16202
+ const recordDiagnostic = (d) => {
16203
+ outcomesFor(d.rawDefault).diagnostics.push(d);
16204
+ diagnostics.push(d);
16205
+ };
16206
+ for (const input of defaults) {
16207
+ classifyOneDefault(input, leavesByPath, leavesByNormalizedKey, recordResolvedPath, recordDiagnostic, describeType);
16208
+ }
16209
+ const mappings = finalizeMappings(outcomesByRawDefault, recordDiagnostic);
16210
+ return { mappings, diagnostics };
16211
+ }
16212
+ function buildNormalizedIndex(leaves) {
16213
+ const out = /* @__PURE__ */ new Map();
16214
+ for (const leaf of leaves) {
16215
+ const key = leaf.path.slice(leaf.path.lastIndexOf(".") + 1);
16216
+ const normalizedKey = normalizeTokenKey(key);
16217
+ const matches = out.get(normalizedKey) ?? [];
16218
+ matches.push(leaf);
16219
+ out.set(normalizedKey, matches);
16220
+ }
16221
+ return out;
16222
+ }
16223
+ function classifyOneDefault(input, leavesByPath, leavesByNormalizedKey, recordResolvedPath, recordDiagnostic, describeType2) {
16224
+ const exact = leavesByPath.get(input.rawDefault);
16225
+ if (exact !== void 0) {
16226
+ if (input.tokenKind === null || exact.type === input.tokenKind) {
16227
+ recordResolvedPath(input.rawDefault, exact.path);
16228
+ } else {
16229
+ recordDiagnostic({
16230
+ rawDefault: input.rawDefault,
16231
+ tokenKind: input.tokenKind,
16232
+ reason: "type_mismatch",
16233
+ candidatePaths: [exact.path],
16234
+ message: `Token default '${input.rawDefault}' is a ${exact.type} token, not ${describeType2(input.tokenKind)}.`
16235
+ });
16236
+ }
16237
+ return;
16238
+ }
16239
+ const member = terminalMember(input.rawDefault);
16240
+ const candidates = member === void 0 ? [] : leavesByNormalizedKey.get(normalizeTokenKey(member)) ?? [];
16241
+ const compatible = input.tokenKind === null ? candidates : candidates.filter((c2) => c2.type === input.tokenKind);
16242
+ if (compatible.length === 1) {
16243
+ recordResolvedPath(input.rawDefault, compatible[0].path);
16244
+ return;
16245
+ }
16246
+ if (compatible.length > 1) {
16247
+ recordDiagnostic({
16248
+ rawDefault: input.rawDefault,
16249
+ tokenKind: input.tokenKind,
16250
+ reason: "ambiguous",
16251
+ candidatePaths: compatible.map((c2) => c2.path).sort(),
16252
+ message: `Token default '${input.rawDefault}' matches multiple compatible DTCG leaves: ${compatible.map((c2) => c2.path).sort().join(", ")}.`
16253
+ });
16254
+ return;
16255
+ }
16256
+ if (candidates.length > 0 && input.tokenKind !== null) {
16257
+ recordDiagnostic({
16258
+ rawDefault: input.rawDefault,
16259
+ tokenKind: input.tokenKind,
16260
+ reason: "type_mismatch",
16261
+ candidatePaths: candidates.map((c2) => c2.path).sort(),
16262
+ message: `Token default '${input.rawDefault}' has matching DTCG leaf names, but none is ${describeType2(input.tokenKind)}.`
16263
+ });
16264
+ return;
16265
+ }
16266
+ recordDiagnostic({
16267
+ rawDefault: input.rawDefault,
16268
+ tokenKind: input.tokenKind,
16269
+ reason: "no_match",
16270
+ candidatePaths: [],
16271
+ message: `Token default '${input.rawDefault}' does not match a DTCG token leaf.`
16272
+ });
16273
+ }
16274
+ function finalizeMappings(outcomesByRawDefault, recordDiagnostic) {
16275
+ const mappings = {};
16276
+ for (const [rawDefault, outcomes] of outcomesByRawDefault) {
16277
+ if (outcomes.diagnostics.length > 0)
16278
+ continue;
16279
+ const uniquePaths = [...new Set(outcomes.resolvedPaths)];
16280
+ if (uniquePaths.length === 1) {
16281
+ mappings[rawDefault] = uniquePaths[0];
16282
+ continue;
16283
+ }
16284
+ recordDiagnostic({
16285
+ rawDefault,
16286
+ tokenKind: null,
16287
+ reason: "ambiguous",
16288
+ candidatePaths: uniquePaths.sort(),
16289
+ message: `Token default '${rawDefault}' resolves to different compatible DTCG leaves across properties: ${uniquePaths.sort().join(", ")}.`
16290
+ });
16291
+ }
16292
+ return mappings;
16293
+ }
15503
16294
  var init_resolve_token_defaults = __esm({
15504
16295
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/token-defaults/resolve-token-defaults.js"() {
15505
16296
  "use strict";
@@ -15517,6 +16308,13 @@ var init_resolve_token_defaults2 = __esm({
15517
16308
  });
15518
16309
 
15519
16310
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/components/normalize-component-for-cache.js
16311
+ function normalizeComponentForCache(component) {
16312
+ const slots = component.slots.map((slot, index, allSlots) => ({
16313
+ ...slot,
16314
+ name: slot.name.trim() || (allSlots.length === 1 ? "children" : `slot_${index}`)
16315
+ }));
16316
+ return { ...component, slots };
16317
+ }
15520
16318
  var init_normalize_component_for_cache = __esm({
15521
16319
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/components/normalize-component-for-cache.js"() {
15522
16320
  "use strict";
@@ -15524,6 +16322,15 @@ var init_normalize_component_for_cache = __esm({
15524
16322
  });
15525
16323
 
15526
16324
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/components/lookup-component-cache.js
16325
+ function lookupComponentCache(db, component, promptHash) {
16326
+ const normalized = normalizeComponentForCache(component);
16327
+ const inputHash = hashComponentShape(normalized);
16328
+ const cached = lookupCache(db, inputHash, "component", component.component_id, promptHash);
16329
+ if (cached)
16330
+ return cached;
16331
+ const legacyInputHash = hashComponentShape(component);
16332
+ return legacyInputHash === inputHash ? null : lookupCache(db, legacyInputHash, "component", component.component_id, promptHash);
16333
+ }
15527
16334
  var init_lookup_component_cache = __esm({
15528
16335
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/components/lookup-component-cache.js"() {
15529
16336
  "use strict";
@@ -15533,6 +16340,17 @@ var init_lookup_component_cache = __esm({
15533
16340
  });
15534
16341
 
15535
16342
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/components/resolve-component-cache.js
16343
+ function resolveComponentCache(db, component, promptHash, allowedComponentNames2) {
16344
+ const cached = lookupComponentCache(db, component, promptHash);
16345
+ if (cached && findUnknownSlotAllowedComponents(db, cached.sourceSessionId, allowedComponentNames2, component.component_id).length === 0) {
16346
+ return { entry: cached, humanEdited: cached.humanEdited };
16347
+ }
16348
+ const pinned = lookupCacheByEntity(db, "component", component.component_id);
16349
+ if (pinned?.humanEdited && findUnknownSlotAllowedComponents(db, pinned.sourceSessionId, allowedComponentNames2, component.component_id).length === 0) {
16350
+ return { entry: pinned, humanEdited: true };
16351
+ }
16352
+ return null;
16353
+ }
15536
16354
  var init_resolve_component_cache = __esm({
15537
16355
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/components/resolve-component-cache.js"() {
15538
16356
  "use strict";
@@ -15552,6 +16370,21 @@ var init_resolve_shared_inputs = __esm({
15552
16370
  });
15553
16371
 
15554
16372
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/map-tokens/filter-allowed-paths.js
16373
+ function filterAllowedPaths(args) {
16374
+ const { component, prop, tokenAllowed, tokenTypeByPath, propTokenKind, warnings } = args;
16375
+ const kept = [];
16376
+ for (const path5 of tokenAllowed) {
16377
+ const tokenType = tokenTypeByPath.get(path5);
16378
+ if (tokenType === void 0) {
16379
+ warnings.push(`map_token_prop '${component}.${prop}': dropped unknown token path '${path5}'`);
16380
+ } else if (propTokenKind !== null && tokenType !== propTokenKind) {
16381
+ warnings.push(`map_token_prop '${component}.${prop}': dropped '${path5}' \u2014 it is a ${tokenType} token, but the property's $token.kind is ${propTokenKind}`);
16382
+ } else {
16383
+ kept.push(path5);
16384
+ }
16385
+ }
16386
+ return kept;
16387
+ }
15555
16388
  var init_filter_allowed_paths = __esm({
15556
16389
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/map-tokens/filter-allowed-paths.js"() {
15557
16390
  "use strict";
@@ -15559,6 +16392,12 @@ var init_filter_allowed_paths = __esm({
15559
16392
  });
15560
16393
 
15561
16394
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/map-tokens/is-prop-reviewed.js
16395
+ function isPropReviewed(db, sessionId, componentId, propName) {
16396
+ const row = db.prepare(`SELECT COUNT(*) AS count FROM raw_prop_token_paths
16397
+ WHERE session_id = ? AND component_id = ? AND prop_name = ?
16398
+ AND source = 'review'`).get(sessionId, componentId, propName);
16399
+ return row.count > 0;
16400
+ }
15562
16401
  var init_is_prop_reviewed = __esm({
15563
16402
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/map-tokens/is-prop-reviewed.js"() {
15564
16403
  "use strict";
@@ -15566,6 +16405,10 @@ var init_is_prop_reviewed = __esm({
15566
16405
  });
15567
16406
 
15568
16407
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/map-tokens/load-token-type-by-path.js
16408
+ function loadTokenTypeByPath(db, sessionId) {
16409
+ const rows = db.prepare("SELECT path, type FROM raw_tokens WHERE session_id = ?").all(sessionId);
16410
+ return new Map(rows.map((r) => [r.path, r.type]));
16411
+ }
15569
16412
  var init_load_token_type_by_path = __esm({
15570
16413
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/map-tokens/load-token-type-by-path.js"() {
15571
16414
  "use strict";
@@ -15573,6 +16416,48 @@ var init_load_token_type_by_path = __esm({
15573
16416
  });
15574
16417
 
15575
16418
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/controller/map-tokens/apply-map-token-prop-calls.js
16419
+ function applyMapTokenPropCalls(db, sessionId, calls, incomingWarnings) {
16420
+ const warnings = [...incomingWarnings];
16421
+ let applied = 0;
16422
+ const tokenTypeByPath = loadTokenTypeByPath(db, sessionId);
16423
+ const findComponent = db.prepare("SELECT component_id FROM raw_components WHERE session_id = ? AND name = ?");
16424
+ const findProp = db.prepare("SELECT cdf_type, cdf_category, cdf_token_kind FROM raw_props WHERE session_id = ? AND component_id = ? AND name = ?");
16425
+ for (const call of calls) {
16426
+ const component = findComponent.get(sessionId, call.component);
16427
+ if (!component) {
16428
+ warnings.push(`map_token_prop: unknown component '${call.component}' \u2014 skipped`);
16429
+ continue;
16430
+ }
16431
+ const prop = findProp.get(sessionId, component.component_id, call.prop);
16432
+ if (!prop) {
16433
+ warnings.push(`map_token_prop '${call.component}.${call.prop}': unknown prop \u2014 skipped`);
16434
+ continue;
16435
+ }
16436
+ if (prop.cdf_type !== "token" || prop.cdf_category !== "design") {
16437
+ warnings.push(`map_token_prop '${call.component}.${call.prop}': target is not a design-category token prop \u2014 skipped`);
16438
+ continue;
16439
+ }
16440
+ if (isPropReviewed(db, sessionId, component.component_id, call.prop)) {
16441
+ warnings.push(`map_token_prop '${call.component}.${call.prop}': a reviewer already set this restriction \u2014 skipped`);
16442
+ continue;
16443
+ }
16444
+ const filteredAllowed = filterAllowedPaths({
16445
+ component: call.component,
16446
+ prop: call.prop,
16447
+ tokenAllowed: call.token_allowed,
16448
+ tokenTypeByPath,
16449
+ propTokenKind: prop.cdf_token_kind,
16450
+ warnings
16451
+ });
16452
+ if (filteredAllowed.length === 0) {
16453
+ warnings.push(`map_token_prop '${call.component}.${call.prop}': no valid token_allowed remain \u2014 skipped`);
16454
+ continue;
16455
+ }
16456
+ replaceRawPropTokenPaths(db, sessionId, component.component_id, call.prop, filteredAllowed, "agent");
16457
+ applied++;
16458
+ }
16459
+ return { applied, warnings };
16460
+ }
15576
16461
  var init_apply_map_token_prop_calls = __esm({
15577
16462
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/controller/map-tokens/apply-map-token-prop-calls.js"() {
15578
16463
  "use strict";
@@ -15586,6 +16471,14 @@ var init_apply_map_token_prop_calls = __esm({
15586
16471
  // packages/experience-design-system-backend-pipeline/dist/src/agents/helpers/resolution/binary-exists.js
15587
16472
  import { execFile } from "node:child_process";
15588
16473
  import { promisify } from "node:util";
16474
+ async function binaryExists(name) {
16475
+ try {
16476
+ await execFileAsync(process.platform === "win32" ? "where" : "which", [name]);
16477
+ return true;
16478
+ } catch {
16479
+ return false;
16480
+ }
16481
+ }
15589
16482
  var execFileAsync;
15590
16483
  var init_binary_exists = __esm({
15591
16484
  "packages/experience-design-system-backend-pipeline/dist/src/agents/helpers/resolution/binary-exists.js"() {
@@ -15595,6 +16488,12 @@ var init_binary_exists = __esm({
15595
16488
  });
15596
16489
 
15597
16490
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/map-tokens/count-mappable-props.js
16491
+ function countMappableProps(cdfEntries) {
16492
+ return cdfEntries.reduce((count, { entry }) => {
16493
+ const props = entry.$properties ?? {};
16494
+ return count + Object.values(props).filter((prop) => prop.$type === "token" && prop.$category === "design").length;
16495
+ }, 0);
16496
+ }
15598
16497
  var init_count_mappable_props = __esm({
15599
16498
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/map-tokens/count-mappable-props.js"() {
15600
16499
  "use strict";
@@ -15602,6 +16501,14 @@ var init_count_mappable_props = __esm({
15602
16501
  });
15603
16502
 
15604
16503
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/map-tokens/load-raw-defaults.js
16504
+ function loadRawDefaults(db, sessionId) {
16505
+ return db.prepare(`SELECT rp.default_value AS default_reference, rp.cdf_token_kind
16506
+ FROM raw_props rp
16507
+ JOIN raw_components rc ON rc.session_id = rp.session_id AND rc.component_id = rp.component_id
16508
+ WHERE rp.session_id = ? AND rc.status = 'generated'
16509
+ AND rp.cdf_type = 'token' AND rp.cdf_category = 'design'
16510
+ AND rp.default_value IS NOT NULL`).all(sessionId);
16511
+ }
15605
16512
  var init_load_raw_defaults = __esm({
15606
16513
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/map-tokens/load-raw-defaults.js"() {
15607
16514
  "use strict";
@@ -15609,6 +16516,9 @@ var init_load_raw_defaults = __esm({
15609
16516
  });
15610
16517
 
15611
16518
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/map-tokens/load-token-leaves.js
16519
+ function loadTokenLeaves(db, sessionId) {
16520
+ return db.prepare("SELECT path, type FROM raw_tokens WHERE session_id = ? ORDER BY path").all(sessionId);
16521
+ }
15612
16522
  var init_load_token_leaves = __esm({
15613
16523
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/helpers/map-tokens/load-token-leaves.js"() {
15614
16524
  "use strict";
@@ -15616,7 +16526,114 @@ var init_load_token_leaves = __esm({
15616
16526
  });
15617
16527
 
15618
16528
  // packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/controller/map-tokens/run-map-tokens.js
15619
- var DEFAULT_TIMEOUT_MS2;
16529
+ import { resolve as resolve18 } from "node:path";
16530
+ async function runMapTokens(request) {
16531
+ const timeoutMs = request.agentTimeoutMs ?? DEFAULT_TIMEOUT_MS2;
16532
+ const db = openPipelineDb();
16533
+ try {
16534
+ const sessionId = request.sessionId ?? findLatestSessionForCommand(db, "generate components");
16535
+ if (!sessionId) {
16536
+ throw new MapTokensRunFailure({ type: "no-session" });
16537
+ }
16538
+ const tokenLeaves = loadTokenLeaves(db, sessionId);
16539
+ const knownTokenPaths = new Set(tokenLeaves.map((t) => t.path));
16540
+ if (request.tokenMapInline) {
16541
+ const validMappings = {};
16542
+ for (const [rawName, path5] of Object.entries(request.tokenMapInline)) {
16543
+ if (knownTokenPaths.has(path5))
16544
+ validMappings[rawName] = path5;
16545
+ }
16546
+ replaceRawTokenNamePaths(db, sessionId, validMappings, "manual");
16547
+ }
16548
+ const rawDefaults = loadRawDefaults(db, sessionId);
16549
+ const defaultResolution = resolveTokenDefaults(rawDefaults.map((row) => ({ rawDefault: row.default_reference, tokenKind: row.cdf_token_kind })), tokenLeaves);
16550
+ const manualMappings = new Map(getRawTokenNamePathRows(db, sessionId).filter((row) => row.source === "manual").map((row) => [row.rawName, row.path]));
16551
+ const automaticMappings = {};
16552
+ for (const [rawName, path5] of Object.entries(defaultResolution.mappings)) {
16553
+ if (manualMappings.get(rawName) === void 0)
16554
+ automaticMappings[rawName] = path5;
16555
+ }
16556
+ replaceRawTokenNamePaths(db, sessionId, automaticMappings, "automatic");
16557
+ const cdfEntries = loadCDFComponents(db, sessionId);
16558
+ if (cdfEntries.length === 0) {
16559
+ throw new MapTokensRunFailure({ type: "no-components", sessionId });
16560
+ }
16561
+ const mappablePropCount = countMappableProps(cdfEntries);
16562
+ const { groups, tokens } = getDtcgTokensForSession(db, sessionId);
16563
+ const tokenCount = tokens.length;
16564
+ if (mappablePropCount === 0 || tokenCount === 0) {
16565
+ return { type: "nothing-to-map", sessionId, mappablePropCount, tokenCount };
16566
+ }
16567
+ const generatedCdf = Object.fromEntries(cdfEntries.map((c2) => [c2.key, c2.entry]));
16568
+ const tokenTree = rebuildDTCGTree(groups, tokens);
16569
+ const componentSourceRefs = await loadComponentSourceRefs(db, sessionId);
16570
+ const buildMapPrompt = () => buildPrompt({
16571
+ skill: "map-tokens",
16572
+ mode: "autonomous",
16573
+ generatedCdf,
16574
+ tokenTree,
16575
+ componentSourceRefs,
16576
+ outDir: process.cwd(),
16577
+ existingTokensInline: request.existingEntitiesInline,
16578
+ ...request.skillContentOverride !== void 0 ? { skillContentOverride: request.skillContentOverride } : {},
16579
+ ...request.skillContentOverride === void 0 && request.skillPathOverride ? { skillPathOverride: resolve18(request.skillPathOverride) } : {}
16580
+ });
16581
+ if (request.printPrompt) {
16582
+ const prompt2 = await buildMapPrompt();
16583
+ return { type: "printed-prompt", sessionId, prompt: prompt2 };
16584
+ }
16585
+ if (request.skipAgent) {
16586
+ const stepId2 = createStep(db, sessionId, "map tokens", {
16587
+ agent: request.agent,
16588
+ model: request.model ?? "",
16589
+ skipAgent: "true"
16590
+ });
16591
+ updateStep(db, stepId2, "complete", { applied: "0", skipAgent: "true" });
16592
+ return { type: "skipped", sessionId, stepId: stepId2 };
16593
+ }
16594
+ const agent = request.agent;
16595
+ const noCache = request.cache === false || process.env["EDS_NO_CACHE"] === "1";
16596
+ const promptHash = await hashPromptForSkill("map-tokens", agent, request.model, void 0, request.existingEntitiesInline ? [hashContent(request.existingEntitiesInline)] : [], request.skillContentOverride);
16597
+ const inputHash = computeMapTokensInputHash(db, sessionId, componentSourceRefs);
16598
+ if (!noCache) {
16599
+ const cached = lookupCache(db, inputHash, "token_mapping", "__map_tokens__", promptHash);
16600
+ if (cached) {
16601
+ const applied2 = copyMapTokensFromCache(db, cached.sourceSessionId, sessionId);
16602
+ const stepId2 = createStep(db, sessionId, "map tokens", { agent, model: request.model ?? "" });
16603
+ updateStep(db, stepId2, "complete", { cached: "true", applied: String(applied2) });
16604
+ return { type: "cached", sessionId, applied: applied2, stepId: stepId2 };
16605
+ }
16606
+ }
16607
+ const binary = resolveBinary(agent);
16608
+ if (!await binaryExists(binary)) {
16609
+ throw new MapTokensRunFailure({
16610
+ type: "binary-not-found",
16611
+ agent,
16612
+ binary,
16613
+ skillPath: resolveSkillPath("map-tokens")
16614
+ });
16615
+ }
16616
+ const stepId = createStep(db, sessionId, "map tokens", { agent, model: request.model ?? "" });
16617
+ const prompt = await buildMapPrompt();
16618
+ const invoker = createLocalCliAgentInvoker();
16619
+ const result = await invoker.invoke({ agent, model: request.model, prompt, timeoutMs });
16620
+ if (result.timedOut || result.exitCode !== 0) {
16621
+ const error = result.timedOut ? `timed out after ${timeoutMs / 6e4} minutes` : describeAgentFailure(result);
16622
+ updateStep(db, stepId, "failed", {}, error);
16623
+ throw new MapTokensRunFailure({ type: "agent-failed", sessionId, stepId, error });
16624
+ }
16625
+ const { calls, warnings: parseWarnings } = parseMapTokenPropToolCalls(result.stdout);
16626
+ const { applied, warnings } = applyMapTokenPropCalls(db, sessionId, calls, parseWarnings);
16627
+ if (!noCache) {
16628
+ storeCache(db, inputHash, "token_mapping", "__map_tokens__", sessionId, false, promptHash);
16629
+ }
16630
+ updateStep(db, stepId, "complete", { applied: String(applied), warnings: String(warnings.length) });
16631
+ return { type: "applied", sessionId, applied, warnings, stepId };
16632
+ } finally {
16633
+ db.close();
16634
+ }
16635
+ }
16636
+ var DEFAULT_TIMEOUT_MS2, MapTokensRunFailure;
15620
16637
  var init_run_map_tokens = __esm({
15621
16638
  "packages/experience-design-system-backend-pipeline/dist/src/steps/generation/src/controller/map-tokens/run-map-tokens.js"() {
15622
16639
  "use strict";
@@ -15636,6 +16653,25 @@ var init_run_map_tokens = __esm({
15636
16653
  init_rebuild_dtcg_tree();
15637
16654
  init_resolve_token_defaults();
15638
16655
  DEFAULT_TIMEOUT_MS2 = 5 * 60 * 1e3;
16656
+ MapTokensRunFailure = class _MapTokensRunFailure extends Error {
16657
+ reason;
16658
+ constructor(reason) {
16659
+ super(_MapTokensRunFailure.format(reason));
16660
+ this.reason = reason;
16661
+ }
16662
+ static format(r) {
16663
+ switch (r.type) {
16664
+ case "no-session":
16665
+ return "no completed generate components session found. Run generate components first, or pass sessionId.";
16666
+ case "no-components":
16667
+ return `no generated components in session '${r.sessionId}'. Run generate components first.`;
16668
+ case "binary-not-found":
16669
+ return `agent '${r.agent}' not found in $PATH (looked for binary: ${r.binary}). Install it, choose another agent, or run the mapping manually via: ${r.skillPath}`;
16670
+ case "agent-failed":
16671
+ return `map tokens agent failed \u2014 ${r.error}`;
16672
+ }
16673
+ }
16674
+ };
15639
16675
  }
15640
16676
  });
15641
16677
 
@@ -17303,11 +18339,11 @@ var init_detect_data_wrapper_patterns = __esm({
17303
18339
  });
17304
18340
 
17305
18341
  // packages/experience-design-system-extraction/dist/src/extract/services/quality/helpers/inspection/inspect-component-source.js
17306
- import { readFile as readFile12 } from "node:fs/promises";
18342
+ import { readFile as readFile15 } from "node:fs/promises";
17307
18343
  async function inspectComponentSource(component) {
17308
18344
  let sourceText = "";
17309
18345
  try {
17310
- sourceText = await readFile12(component.source, "utf8");
18346
+ sourceText = await readFile15(component.source, "utf8");
17311
18347
  } catch {
17312
18348
  return {
17313
18349
  wrapperConfidence: 0,
@@ -17698,7 +18734,7 @@ async function retryDatabaseWrite(operation, attempts = 8) {
17698
18734
  const message = error instanceof Error ? error.message : String(error);
17699
18735
  if (!/database is locked|database is busy/i.test(message) || attempt >= attempts)
17700
18736
  throw error;
17701
- await new Promise((resolve22) => setTimeout(resolve22, Math.min(250 * attempt, 2e3)));
18737
+ await new Promise((resolve25) => setTimeout(resolve25, Math.min(250 * attempt, 2e3)));
17702
18738
  }
17703
18739
  }
17704
18740
  }
@@ -17746,7 +18782,7 @@ var init_resolve_composition_agent_name = __esm({
17746
18782
  });
17747
18783
 
17748
18784
  // packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-extract-and-compose-session/helpers/read-candidate-files.js
17749
- import { readFile as readFile13 } from "node:fs/promises";
18785
+ import { readFile as readFile16 } from "node:fs/promises";
17750
18786
  async function readCandidateFiles(components, extraFiles = []) {
17751
18787
  const paths = new Set(extraFiles);
17752
18788
  for (const c2 of components) {
@@ -17756,7 +18792,7 @@ async function readCandidateFiles(components, extraFiles = []) {
17756
18792
  const out = [];
17757
18793
  await Promise.all([...paths].map(async (p) => {
17758
18794
  try {
17759
- const content = await readFile13(p, "utf8");
18795
+ const content = await readFile16(p, "utf8");
17760
18796
  out.push({ path: p, content });
17761
18797
  } catch {
17762
18798
  }
@@ -17989,7 +19025,7 @@ var init_write_tokens_file = __esm({
17989
19025
  });
17990
19026
 
17991
19027
  // packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-tokens-session/run-generate-tokens-session.js
17992
- import { readFile as readFile14 } from "node:fs/promises";
19028
+ import { readFile as readFile17 } from "node:fs/promises";
17993
19029
  import { basename as basename5, resolve as pathResolve } from "node:path";
17994
19030
  async function runGenerateTokensSession(request) {
17995
19031
  const { rawTokensPath, outDir, agent, agentModel, promptOverrides, skillPath, noCache, bedrock = false, onProgress, onSessionCreated } = request;
@@ -17998,7 +19034,7 @@ async function runGenerateTokensSession(request) {
17998
19034
  throw new Error(`Prompt override error(s): ${promptErrors.join("; ")}`);
17999
19035
  const tokensOverride = overridesMap.get("tokens");
18000
19036
  const skillContentOverride = tokensOverride ? await resolvePromptOverride(tokensOverride) : void 0;
18001
- const rawTokensInline = await readFile14(pathResolve(rawTokensPath), "utf8");
19037
+ const rawTokensInline = await readFile17(pathResolve(rawTokensPath), "utf8");
18002
19038
  const tokenInputHash = hashTokenContent(rawTokensInline);
18003
19039
  const db = openPipelineDb();
18004
19040
  try {
@@ -18083,6 +19119,426 @@ var init_run_generate_tokens_session = __esm({
18083
19119
  }
18084
19120
  });
18085
19121
 
19122
+ // packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/helpers/build-empty-session-response.js
19123
+ function buildEmptySessionResponse(sessionId) {
19124
+ return {
19125
+ sessionId,
19126
+ results: [],
19127
+ allOk: true,
19128
+ renamedSlotsCount: 0,
19129
+ duplicateNames: [],
19130
+ droppedAllowedComponents: [],
19131
+ emptySession: true
19132
+ };
19133
+ }
19134
+ var init_build_empty_session_response = __esm({
19135
+ "packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/helpers/build-empty-session-response.js"() {
19136
+ "use strict";
19137
+ }
19138
+ });
19139
+
19140
+ // packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/helpers/collect-duplicate-names.js
19141
+ function collectDuplicateNames(components) {
19142
+ const nameCounts = /* @__PURE__ */ new Map();
19143
+ for (const c2 of components) {
19144
+ const sources = nameCounts.get(c2.name) ?? [];
19145
+ sources.push(c2.source);
19146
+ nameCounts.set(c2.name, sources);
19147
+ }
19148
+ return [...nameCounts.entries()].filter(([, srcs]) => srcs.length > 1).map(([name, sources]) => ({ name, sources }));
19149
+ }
19150
+ var init_collect_duplicate_names = __esm({
19151
+ "packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/helpers/collect-duplicate-names.js"() {
19152
+ "use strict";
19153
+ }
19154
+ });
19155
+
19156
+ // packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/helpers/filter-dropped-allowed-components.js
19157
+ function filterDroppedAllowedComponents(db, sessionId, components, allowedComponentNames2, acceptedNames) {
19158
+ const dropped = filterUnknownSlotAllowedComponents(db, sessionId, allowedComponentNames2);
19159
+ if (dropped.length === 0)
19160
+ return { components, dropped: [] };
19161
+ return { components: loadRawComponents(db, sessionId, acceptedNames), dropped };
19162
+ }
19163
+ var init_filter_dropped_allowed_components = __esm({
19164
+ "packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/helpers/filter-dropped-allowed-components.js"() {
19165
+ "use strict";
19166
+ init_db();
19167
+ }
19168
+ });
19169
+
19170
+ // packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/helpers/read-existing-entities.js
19171
+ async function readExistingEntities(request) {
19172
+ if (request.existingContentfulEntities !== void 0)
19173
+ return request.existingContentfulEntities;
19174
+ if (!request.existingEntitiesPath)
19175
+ return void 0;
19176
+ return readExistingContentfulEntitiesFromSession({ path: request.existingEntitiesPath });
19177
+ }
19178
+ var init_read_existing_entities = __esm({
19179
+ "packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/helpers/read-existing-entities.js"() {
19180
+ "use strict";
19181
+ init_read_from_session();
19182
+ }
19183
+ });
19184
+
19185
+ // packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/helpers/resolve-generate-prompt.js
19186
+ import { resolve as resolve19 } from "node:path";
19187
+ async function resolveGeneratePrompt(overrides) {
19188
+ const { overrides: parsed, errors } = parsePromptOverrides(overrides);
19189
+ if (errors.length > 0)
19190
+ throw new Error(errors.join("; "));
19191
+ const entry = parsed.get("generate");
19192
+ if (!entry)
19193
+ return {};
19194
+ const text = await resolvePromptOverride(entry);
19195
+ if (entry.kind === "text")
19196
+ return { text };
19197
+ return { path: resolve19(entry.value), text };
19198
+ }
19199
+ var init_resolve_generate_prompt = __esm({
19200
+ "packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/helpers/resolve-generate-prompt.js"() {
19201
+ "use strict";
19202
+ init_parse_prompt_overrides();
19203
+ init_resolve_prompt_override();
19204
+ }
19205
+ });
19206
+
19207
+ // packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/helpers/run-one-generate-component.js
19208
+ async function runOneGenerateComponent(options, component, index, total) {
19209
+ const { db, sessionId, invoker, agent, model, tokensInline, tokenMapInline, verbose, noCache, skillPathOverride, skillContentOverride, promptHash, existingContentfulEntities, existingTokensInline, precomputedCachedNames, allowedComponentNames: allowedComponentNames2, onProgress } = options;
19210
+ const { renames } = renameEmptySlots(db, sessionId, component.component_id, component.name, component.slots.length);
19211
+ let effectiveSlots = component.slots;
19212
+ if (renames.length > 0) {
19213
+ const renameMap = new Map(renames.map((r) => [r.oldName, r.newName]));
19214
+ effectiveSlots = component.slots.map((s) => renameMap.has(s.name) ? { ...s, name: renameMap.get(s.name) } : s);
19215
+ for (const rename4 of renames) {
19216
+ onProgress?.({
19217
+ kind: "component:slot-renamed",
19218
+ componentName: component.name,
19219
+ oldName: rename4.oldName,
19220
+ newName: rename4.newName
19221
+ });
19222
+ }
19223
+ }
19224
+ effectiveSlots = effectiveSlots.map((slot) => slot.allowedComponents ? { ...slot, allowedComponents: slot.allowedComponents.filter((name) => allowedComponentNames2.has(name)) } : slot);
19225
+ const cacheComponent = normalizeComponentForCache(component);
19226
+ if (!noCache && precomputedCachedNames.has(component.name)) {
19227
+ onProgress?.({ kind: "component:cached", index, total, name: component.name, pinned: false });
19228
+ return cachedResult(component.name);
19229
+ }
19230
+ if (!noCache) {
19231
+ const resolution = resolveComponentCache(db, component, promptHash, allowedComponentNames2);
19232
+ if (resolution && !resolution.humanEdited) {
19233
+ copyComponentFromCache(db, resolution.entry.sourceSessionId, sessionId, component.component_id, true, {
19234
+ allowedComponentNames: allowedComponentNames2
19235
+ });
19236
+ storeCache(db, hashComponentShape(cacheComponent), "component", component.component_id, resolution.entry.sourceSessionId, resolution.entry.humanEdited, promptHash);
19237
+ onProgress?.({ kind: "component:cached", index, total, name: component.name, pinned: false });
19238
+ return cachedResult(component.name);
19239
+ }
19240
+ if (resolution?.humanEdited) {
19241
+ copyComponentFromCache(db, resolution.entry.sourceSessionId, sessionId, component.component_id, true, {
19242
+ allowedComponentNames: allowedComponentNames2
19243
+ });
19244
+ onProgress?.({ kind: "component:cached", index, total, name: component.name, pinned: true });
19245
+ return cachedResult(component.name, [`${component.name}: source changed but human edits preserved`]);
19246
+ }
19247
+ }
19248
+ const rawComponentsInline = JSON.stringify([
19249
+ {
19250
+ name: component.name,
19251
+ source: component.source,
19252
+ framework: component.framework,
19253
+ props: component.props,
19254
+ slots: effectiveSlots
19255
+ }
19256
+ ], null, 2);
19257
+ const sourceRef = await loadComponentSourceRef(component.name, component.sourcePath ?? component.source, component.props.map((p) => p.name), component.props.map((p) => p.type));
19258
+ const existingComponentsInline = existingContentfulEntities ? JSON.stringify(summarizeForGenerateAgent(existingContentfulEntities, component.name)) : void 0;
19259
+ const prompt = await buildPrompt({
19260
+ skill: "components",
19261
+ mode: "autonomous",
19262
+ rawComponentsInline,
19263
+ tokensInline,
19264
+ tokenMapInline,
19265
+ outDir: process.cwd(),
19266
+ componentName: component.name,
19267
+ componentSourceRefs: [sourceRef],
19268
+ skillPathOverride,
19269
+ skillContentOverride,
19270
+ existingComponentsInline,
19271
+ existingTokensInline,
19272
+ componentAllowlistInline: JSON.stringify([...allowedComponentNames2].sort())
19273
+ });
19274
+ const maxAttempts = 2;
19275
+ let lastError = "";
19276
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
19277
+ if (attempt > 1)
19278
+ await new Promise((res) => setTimeout(res, RETRY_BACKOFF_MS));
19279
+ onProgress?.({ kind: "component:started", index, total, name: component.name, attempt, maxAttempts });
19280
+ const { result } = await invokeAgentWithOutput(invoker, { agent, model, prompt, timeoutMs: DEFAULT_TIMEOUT_MS4 }, verbose);
19281
+ if (result.timedOut) {
19282
+ const error = `timed out after ${DEFAULT_TIMEOUT_MS4 / 6e4} minutes`;
19283
+ onProgress?.({ kind: "component:failed", index, total, name: component.name, error });
19284
+ return failed(component.name, error, renames.length);
19285
+ }
19286
+ if (result.exitCode !== 0) {
19287
+ lastError = describeAgentFailure(result);
19288
+ continue;
19289
+ }
19290
+ const { calls, warnings } = parseToolCalls(result.stdout);
19291
+ if (calls.length === 0) {
19292
+ lastError = describeAgentFailure(result);
19293
+ continue;
19294
+ }
19295
+ const applied = applyToolCalls(db, sessionId, component.component_id, component.name, calls, warnings, {
19296
+ allowedComponentNames: allowedComponentNames2
19297
+ });
19298
+ if (!noCache) {
19299
+ storeCache(db, hashComponentShape(cacheComponent), "component", component.component_id, sessionId, false, promptHash);
19300
+ }
19301
+ onProgress?.({
19302
+ kind: "component:completed",
19303
+ index,
19304
+ total,
19305
+ name: component.name,
19306
+ classified: applied.classified,
19307
+ excluded: applied.excluded,
19308
+ slots: applied.slots,
19309
+ warnings: applied.warnings
19310
+ });
19311
+ return {
19312
+ componentName: component.name,
19313
+ classified: applied.classified,
19314
+ excluded: applied.excluded,
19315
+ slots: applied.slots,
19316
+ warnings: applied.warnings,
19317
+ failed: false,
19318
+ cached: false,
19319
+ renamedSlotsCount: renames.length
19320
+ };
19321
+ }
19322
+ onProgress?.({ kind: "component:failed", index, total, name: component.name, error: lastError });
19323
+ return failed(component.name, lastError, renames.length);
19324
+ }
19325
+ function cachedResult(componentName, warnings = []) {
19326
+ return {
19327
+ componentName,
19328
+ classified: 0,
19329
+ excluded: 0,
19330
+ slots: 0,
19331
+ warnings,
19332
+ failed: false,
19333
+ cached: true,
19334
+ renamedSlotsCount: 0
19335
+ };
19336
+ }
19337
+ function failed(componentName, error, renamedSlotsCount) {
19338
+ return {
19339
+ componentName,
19340
+ classified: 0,
19341
+ excluded: 0,
19342
+ slots: 0,
19343
+ warnings: [],
19344
+ failed: true,
19345
+ error,
19346
+ cached: false,
19347
+ renamedSlotsCount
19348
+ };
19349
+ }
19350
+ var DEFAULT_TIMEOUT_MS4, RETRY_BACKOFF_MS;
19351
+ var init_run_one_generate_component = __esm({
19352
+ "packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/helpers/run-one-generate-component.js"() {
19353
+ "use strict";
19354
+ init_build_prompt();
19355
+ init_describe_agent_failure();
19356
+ init_invoke_agent_with_output();
19357
+ init_parse_tool_calls();
19358
+ init_db();
19359
+ init_normalize_component_for_cache();
19360
+ init_resolve_component_cache();
19361
+ init_summarize_for_generate();
19362
+ DEFAULT_TIMEOUT_MS4 = Number(process.env["EDS_AGENT_TIMEOUT_MS"] ?? 5 * 60 * 1e3);
19363
+ RETRY_BACKOFF_MS = Number(process.env["EDS_RETRY_BACKOFF_MS"] ?? 5e3);
19364
+ }
19365
+ });
19366
+
19367
+ // packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/helpers/run-with-pool.js
19368
+ async function runWithPool(items, concurrency, worker) {
19369
+ const results = new Array(items.length);
19370
+ let next = 0;
19371
+ async function run() {
19372
+ while (next < items.length) {
19373
+ const i = next++;
19374
+ results[i] = await worker(items[i], i);
19375
+ }
19376
+ }
19377
+ await Promise.all(Array.from({ length: concurrency }, run));
19378
+ return results;
19379
+ }
19380
+ var init_run_with_pool = __esm({
19381
+ "packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/helpers/run-with-pool.js"() {
19382
+ "use strict";
19383
+ }
19384
+ });
19385
+
19386
+ // packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/check-generate-components-cache.js
19387
+ async function checkGenerateComponentsCache(request) {
19388
+ if (request.noCache) {
19389
+ return { sessionId: request.sessionId, cachedComponentNames: [], fullyCached: false, cacheDisabled: true };
19390
+ }
19391
+ const existingEntities = await readExistingEntities(request);
19392
+ const existingTokensInline = existingEntities ? JSON.stringify(summarizeForMapTokens({ entities: existingEntities })) : void 0;
19393
+ const prompt = await resolveGeneratePrompt(request.promptOverrides);
19394
+ const agent = request.agent;
19395
+ const promptHash = await hashPromptForSkill("components", agent, request.agentModel, prompt.path, existingTokensInline ? [hashContent(existingTokensInline)] : [], prompt.text);
19396
+ const db = openPipelineDb();
19397
+ try {
19398
+ const acceptedNames = await loadAcceptedNames(request.sessionId);
19399
+ const components = loadRawComponents(db, request.sessionId, acceptedNames ?? void 0);
19400
+ if (components.length === 0) {
19401
+ return { sessionId: request.sessionId, cachedComponentNames: [], fullyCached: false, cacheDisabled: false };
19402
+ }
19403
+ const allowedComponentNames2 = /* @__PURE__ */ new Set([
19404
+ ...components.map((component) => component.name),
19405
+ ...(existingEntities?.components ?? []).map((component) => component.name)
19406
+ ]);
19407
+ const cachedComponents = components.flatMap((component) => {
19408
+ const resolution = resolveComponentCache(db, component, promptHash, allowedComponentNames2);
19409
+ return resolution ? [{ component, resolution }] : [];
19410
+ });
19411
+ if (request.restoreCache)
19412
+ restoreCached(db, request.sessionId, cachedComponents, promptHash, allowedComponentNames2);
19413
+ return {
19414
+ sessionId: request.sessionId,
19415
+ cachedComponentNames: cachedComponents.map(({ component }) => component.name),
19416
+ fullyCached: cachedComponents.length === components.length,
19417
+ cacheDisabled: false
19418
+ };
19419
+ } finally {
19420
+ db.close();
19421
+ }
19422
+ }
19423
+ function restoreCached(db, sessionId, cachedComponents, promptHash, allowedComponentNames2) {
19424
+ const restorations = [];
19425
+ const rekeyed = [];
19426
+ const componentStatus = db.prepare("SELECT status FROM raw_components WHERE session_id = ? AND component_id = ?");
19427
+ for (const { component, resolution } of cachedComponents) {
19428
+ const current = componentStatus.get(sessionId, component.component_id);
19429
+ if (current?.status === "generated")
19430
+ continue;
19431
+ renameEmptySlots(db, sessionId, component.component_id, component.name, component.slots.length);
19432
+ restorations.push({
19433
+ sourceSessionId: resolution.entry.sourceSessionId,
19434
+ targetSessionId: sessionId,
19435
+ componentId: component.component_id
19436
+ });
19437
+ rekeyed.push({ component, cached: resolution.entry });
19438
+ }
19439
+ copyComponentsFromCache(db, restorations, { allowedComponentNames: allowedComponentNames2 });
19440
+ storeCaches(db, rekeyed.map(({ component, cached }) => ({
19441
+ inputHash: hashComponentShape(normalizeComponentForCache(component)),
19442
+ entityType: "component",
19443
+ entityId: component.component_id,
19444
+ sourceSessionId: cached.sourceSessionId,
19445
+ humanEdited: cached.humanEdited,
19446
+ promptHash
19447
+ })));
19448
+ }
19449
+ var init_check_generate_components_cache = __esm({
19450
+ "packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/check-generate-components-cache.js"() {
19451
+ "use strict";
19452
+ init_summarize_for_map_tokens();
19453
+ init_resolve_component_cache();
19454
+ init_normalize_component_for_cache();
19455
+ init_db();
19456
+ init_cache_keys();
19457
+ init_src();
19458
+ init_read_existing_entities();
19459
+ init_resolve_generate_prompt();
19460
+ }
19461
+ });
19462
+
19463
+ // packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/run-generate-components-session.js
19464
+ async function runGenerateComponentsSession(request) {
19465
+ const prompt = await resolveGeneratePrompt(request.promptOverrides);
19466
+ const existingEntities = await readExistingEntities(request);
19467
+ const existingTokensInline = existingEntities ? JSON.stringify(summarizeForMapTokens({ entities: existingEntities })) : void 0;
19468
+ const existingTokensHash = existingTokensInline ? [hashContent(existingTokensInline)] : [];
19469
+ const agent = request.agent;
19470
+ const promptHash = await hashPromptForSkill("components", agent, request.agentModel, prompt.path, existingTokensHash, prompt.text);
19471
+ const db = openPipelineDb();
19472
+ try {
19473
+ const acceptedNames = await loadAcceptedNames(request.sessionId);
19474
+ const acceptedSet = acceptedNames ? new Set(acceptedNames) : void 0;
19475
+ let components = loadRawComponents(db, request.sessionId, acceptedSet ?? void 0);
19476
+ if (components.length === 0)
19477
+ return buildEmptySessionResponse(request.sessionId);
19478
+ const allowedComponentNames2 = /* @__PURE__ */ new Set([
19479
+ ...components.map((c2) => c2.name),
19480
+ ...(existingEntities?.components ?? []).map((c2) => c2.name)
19481
+ ]);
19482
+ const { components: filtered, dropped } = filterDroppedAllowedComponents(db, request.sessionId, components, allowedComponentNames2, acceptedSet);
19483
+ components = filtered;
19484
+ const duplicateNames = collectDuplicateNames(components);
19485
+ const invoker = createLocalCliAgentInvoker({});
19486
+ const concurrency = Math.max(1, Math.min(DEFAULT_COMPONENT_CONCURRENCY, components.length));
19487
+ const results = await runWithPool(components, concurrency, (component, index) => runOneGenerateComponent({
19488
+ db,
19489
+ sessionId: request.sessionId,
19490
+ invoker,
19491
+ agent,
19492
+ model: request.agentModel,
19493
+ tokensInline: request.tokensInline,
19494
+ tokenMapInline: request.tokenMapInline,
19495
+ verbose: request.verbose ?? false,
19496
+ noCache: request.noCache,
19497
+ skillPathOverride: prompt.path,
19498
+ skillContentOverride: prompt.text,
19499
+ promptHash,
19500
+ existingContentfulEntities: existingEntities,
19501
+ existingTokensInline,
19502
+ precomputedCachedNames: request.precomputedCachedNames ?? /* @__PURE__ */ new Set(),
19503
+ allowedComponentNames: allowedComponentNames2,
19504
+ onProgress: request.onProgress
19505
+ }, component, index, components.length));
19506
+ const allOk = results.every((r) => !r.failed);
19507
+ const renamedSlotsCount = results.reduce((sum, r) => sum + r.renamedSlotsCount, 0);
19508
+ return {
19509
+ sessionId: request.sessionId,
19510
+ results,
19511
+ allOk,
19512
+ renamedSlotsCount,
19513
+ duplicateNames,
19514
+ droppedAllowedComponents: dropped,
19515
+ emptySession: false
19516
+ };
19517
+ } finally {
19518
+ db.close();
19519
+ }
19520
+ }
19521
+ var DEFAULT_COMPONENT_CONCURRENCY;
19522
+ var init_run_generate_components_session = __esm({
19523
+ "packages/experience-design-system-backend-pipeline/dist/src/orchestrators/run-generate-components-session/run-generate-components-session.js"() {
19524
+ "use strict";
19525
+ init_create_local_cli_agent_invoker();
19526
+ init_db();
19527
+ init_cache_keys();
19528
+ init_src();
19529
+ init_summarize_for_map_tokens();
19530
+ init_build_empty_session_response();
19531
+ init_collect_duplicate_names();
19532
+ init_filter_dropped_allowed_components();
19533
+ init_read_existing_entities();
19534
+ init_resolve_generate_prompt();
19535
+ init_run_one_generate_component();
19536
+ init_run_with_pool();
19537
+ init_check_generate_components_cache();
19538
+ DEFAULT_COMPONENT_CONCURRENCY = Number(process.env["EDS_GENERATE_CONCURRENCY"] ?? 10);
19539
+ }
19540
+ });
19541
+
18086
19542
  // packages/experience-design-system-backend-pipeline/dist/src/index.js
18087
19543
  var init_src4 = __esm({
18088
19544
  "packages/experience-design-system-backend-pipeline/dist/src/index.js"() {
@@ -18198,6 +19654,7 @@ var init_src4 = __esm({
18198
19654
  init_component();
18199
19655
  init_run_extract_and_compose_session();
18200
19656
  init_run_generate_tokens_session();
19657
+ init_run_generate_components_session();
18201
19658
  }
18202
19659
  });
18203
19660
 
@@ -19006,7 +20463,7 @@ var init_steps = __esm({
19006
20463
 
19007
20464
  // packages/experience-design-system-types/dist/src/config/index.js
19008
20465
  import { randomBytes as randomBytes3 } from "node:crypto";
19009
- import { mkdir as mkdir6, readFile as readFile15, rename as rename2, writeFile as writeFile6 } from "node:fs/promises";
20466
+ import { mkdir as mkdir6, readFile as readFile18, rename as rename2, writeFile as writeFile6 } from "node:fs/promises";
19010
20467
  import { homedir as homedir3 } from "node:os";
19011
20468
  import { dirname as dirname13, join as join19 } from "node:path";
19012
20469
  function configRoot2() {
@@ -19014,7 +20471,7 @@ function configRoot2() {
19014
20471
  }
19015
20472
  async function readSettings2() {
19016
20473
  try {
19017
- return JSON.parse(await readFile15(configFilePath2(), "utf8"));
20474
+ return JSON.parse(await readFile18(configFilePath2(), "utf8"));
19018
20475
  } catch {
19019
20476
  return {};
19020
20477
  }
@@ -19043,7 +20500,7 @@ var init_config = __esm({
19043
20500
 
19044
20501
  // packages/experience-design-system-cli/src/tui/import/steps/06-extraction/find-skill-path.ts
19045
20502
  import { existsSync as existsSync10 } from "node:fs";
19046
- import { dirname as dirname14, join as join20, resolve as resolve18 } from "node:path";
20503
+ import { dirname as dirname14, join as join20, resolve as resolve20 } from "node:path";
19047
20504
  import { fileURLToPath as fileURLToPath4 } from "node:url";
19048
20505
  function findSkillPath(fileName) {
19049
20506
  const thisDir = dirname14(fileURLToPath4(import.meta.url));
@@ -19051,7 +20508,7 @@ function findSkillPath(fileName) {
19051
20508
  for (; ; ) {
19052
20509
  const candidate = join20(dir, "skills", fileName);
19053
20510
  if (existsSync10(candidate)) return candidate;
19054
- const parent = resolve18(dir, "..");
20511
+ const parent = resolve20(dir, "..");
19055
20512
  if (parent === dir) {
19056
20513
  throw new Error(`skill file not found (looked for skills/${fileName} from ${thisDir})`);
19057
20514
  }
@@ -19065,9 +20522,9 @@ var init_find_skill_path = __esm({
19065
20522
  });
19066
20523
 
19067
20524
  // packages/experience-design-system-cli/src/tui/import/steps/06-extraction/selection.ts
19068
- import { resolve as resolve19 } from "node:path";
20525
+ import { resolve as resolve21 } from "node:path";
19069
20526
  async function hashSelectPrompt(options) {
19070
- const promptHash = options.promptText ? hashContent(options.promptText) : options.promptPath ? await hashFile(resolve19(options.promptPath)) : await hashFile(SELECT_SKILL_PATH);
20527
+ const promptHash = options.promptText ? hashContent(options.promptText) : options.promptPath ? await hashFile(resolve21(options.promptPath)) : await hashFile(SELECT_SKILL_PATH);
19071
20528
  return hashContent(`${promptHash}|${options.agent}|${options.model ?? ""}`);
19072
20529
  }
19073
20530
  async function runSelection(options) {
@@ -19101,7 +20558,7 @@ async function runSelection(options) {
19101
20558
  });
19102
20559
  const { result } = await invokeAgentWithOutput(
19103
20560
  invoker,
19104
- { agent: options.agent, model: options.model, prompt, timeoutMs: DEFAULT_TIMEOUT_MS4 },
20561
+ { agent: options.agent, model: options.model, prompt, timeoutMs: DEFAULT_TIMEOUT_MS5 },
19105
20562
  false
19106
20563
  );
19107
20564
  if (result.timedOut) throw new Error("selection agent timed out");
@@ -19149,22 +20606,22 @@ async function runSelection(options) {
19149
20606
  writeDb.close();
19150
20607
  }
19151
20608
  }
19152
- var SELECT_SKILL_PATH, DEFAULT_TIMEOUT_MS4;
20609
+ var SELECT_SKILL_PATH, DEFAULT_TIMEOUT_MS5;
19153
20610
  var init_selection2 = __esm({
19154
20611
  "packages/experience-design-system-cli/src/tui/import/steps/06-extraction/selection.ts"() {
19155
20612
  "use strict";
19156
20613
  init_src4();
19157
20614
  init_find_skill_path();
19158
20615
  SELECT_SKILL_PATH = findSkillPath("select-components.md");
19159
- DEFAULT_TIMEOUT_MS4 = Number(process.env.EDS_AGENT_TIMEOUT_MS ?? 5 * 60 * 1e3);
20616
+ DEFAULT_TIMEOUT_MS5 = Number(process.env.EDS_AGENT_TIMEOUT_MS ?? 5 * 60 * 1e3);
19160
20617
  }
19161
20618
  });
19162
20619
 
19163
20620
  // packages/experience-design-system-cli/src/tui/import/steps/06-extraction/run.ts
19164
20621
  import { mkdir as mkdir7 } from "node:fs/promises";
19165
- import { join as join21, resolve as resolve20 } from "node:path";
20622
+ import { join as join21, resolve as resolve22 } from "node:path";
19166
20623
  async function runExtraction(input, onProgress, deps = realDeps) {
19167
- const outDir = join21(resolve20(input.projectPath), ".contentful");
20624
+ const outDir = join21(resolve22(input.projectPath), ".contentful");
19168
20625
  let progress = initialProgress({
19169
20626
  hasCredentials: input.credentials !== null,
19170
20627
  hasRawTokens: input.rawTokensPath !== "",
@@ -19290,7 +20747,7 @@ async function resolveSelectionPrompt(overrides) {
19290
20747
  if (select?.kind === "text") return { promptText: select.value };
19291
20748
  if (select?.kind === "path") {
19292
20749
  await resolvePromptOverride(select);
19293
- return { promptPath: resolve20(select.value) };
20750
+ return { promptPath: resolve22(select.value) };
19294
20751
  }
19295
20752
  return {};
19296
20753
  }
@@ -22355,47 +23812,27 @@ var init_screen7 = __esm({
22355
23812
  });
22356
23813
 
22357
23814
  // packages/experience-design-system-cli/src/tui/import/steps/07-scope-gate/cache-check.ts
22358
- import { execFile as execFile2 } from "node:child_process";
22359
- function buildCacheCheckArgs(input) {
22360
- const args = ["__generate", "components", "--agent", input.agent, "--session", input.sessionId];
22361
- if (input.tokensPath) args.push("--tokens", input.tokensPath);
22362
- if (input.agentModel) args.push("--model", input.agentModel);
22363
- if (input.noCache) args.push("--no-cache");
22364
- for (const prompt of input.promptOverrides) args.push("--prompt", prompt);
22365
- if (input.existingEntitiesPath) args.push("--existing-entities-path", input.existingEntitiesPath);
22366
- args.push("--cache-status", "--restore-cache");
22367
- return args;
22368
- }
22369
- function parseCacheComponents(stdout) {
22370
- const line = /^cache-components=(.+)$/m.exec(stdout)?.[1];
22371
- if (!line) return [];
22372
- try {
22373
- const names = JSON.parse(line);
22374
- return Array.isArray(names) ? names.filter((name) => typeof name === "string") : [];
22375
- } catch {
22376
- return [];
22377
- }
22378
- }
22379
- async function checkGenerationCache(input, run = runLegacyCli) {
23815
+ async function checkGenerationCache(input) {
22380
23816
  if (input.noCache) return [];
22381
23817
  try {
22382
- const result = await run(buildCacheCheckArgs(input));
22383
- if (result.exitCode !== 0) return [];
22384
- return parseCacheComponents(result.stdout);
23818
+ const result = await checkGenerateComponentsCache({
23819
+ sessionId: input.sessionId,
23820
+ agent: input.agent,
23821
+ ...input.agentModel ? { agentModel: input.agentModel } : {},
23822
+ promptOverrides: input.promptOverrides,
23823
+ existingEntitiesPath: input.existingEntitiesPath,
23824
+ noCache: input.noCache,
23825
+ restoreCache: true
23826
+ });
23827
+ return result.cachedComponentNames;
22385
23828
  } catch {
22386
23829
  return [];
22387
23830
  }
22388
23831
  }
22389
- var runLegacyCli;
22390
23832
  var init_cache_check = __esm({
22391
23833
  "packages/experience-design-system-cli/src/tui/import/steps/07-scope-gate/cache-check.ts"() {
22392
23834
  "use strict";
22393
- init_legacy_cli_path();
22394
- runLegacyCli = (args) => new Promise((resolve22) => {
22395
- execFile2("node", [findLegacyCliPath(), ...args], (error, stdout, stderr) => {
22396
- resolve22({ exitCode: error?.code ? Number(error.code) : 0, stdout, stderr });
22397
- });
22398
- });
23835
+ init_src4();
22399
23836
  }
22400
23837
  });
22401
23838
 
@@ -22457,31 +23894,6 @@ var init_use_scope_gate_flow = __esm({
22457
23894
  function initialProgress2() {
22458
23895
  return { components: null, mapTokens: "idle", mapTokensEligible: null };
22459
23896
  }
22460
- function applyGenerateStderr(chunk, previous) {
22461
- let state = previous;
22462
- for (const line of chunk.split("\n")) {
22463
- const finished = PROGRESS_LINE.exec(line);
22464
- if (finished) {
22465
- state = { done: Number(finished[1]), total: Number(finished[2]), current: finished[3].trim() };
22466
- continue;
22467
- }
22468
- const started = STARTED_LINE.exec(line);
22469
- if (started) {
22470
- state = { done: state?.done ?? 0, total: Number(started[2]), current: started[3].trim() };
22471
- }
22472
- }
22473
- return state;
22474
- }
22475
- function parseGenerateResult(output, fallbackCount) {
22476
- const session = /^session=(.+)$/m.exec(output.stdout);
22477
- const count = /(\d+) components?/.exec(output.stderr);
22478
- const renamed = /^renamed-slots:\s*(\d+)$/m.exec(output.stdout);
22479
- return {
22480
- generateSessionId: session ? session[1].trim() : null,
22481
- generatedCount: count ? Number(count[1]) : fallbackCount,
22482
- renamedSlotsCount: renamed ? Number(renamed[1]) : 0
22483
- };
22484
- }
22485
23897
  function shouldRunMapTokens(counts) {
22486
23898
  return counts.mappablePropCount > 0 && counts.rawTokenCount > 0;
22487
23899
  }
@@ -22513,12 +23925,10 @@ function progressRows2(progress, agent) {
22513
23925
  }
22514
23926
  return rows;
22515
23927
  }
22516
- var PROGRESS_LINE, STARTED_LINE, capitalize;
23928
+ var capitalize;
22517
23929
  var init_logic10 = __esm({
22518
23930
  "packages/experience-design-system-cli/src/tui/import/steps/08-generation/logic.ts"() {
22519
23931
  "use strict";
22520
- PROGRESS_LINE = /^progress=generate:(\d+)\/(\d+):(.+)$/;
22521
- STARTED_LINE = /\[(\d+)\/(\d+)\]\s+(.+)/;
22522
23932
  capitalize = (name) => name.charAt(0).toUpperCase() + name.slice(1);
22523
23933
  }
22524
23934
  });
@@ -22552,33 +23962,242 @@ var init_screen8 = __esm({
22552
23962
  }
22553
23963
  });
22554
23964
 
22555
- // packages/experience-design-system-generation/dist/src/agent-names.js
22556
- var AGENT_BINARIES2;
22557
- var init_agent_names = __esm({
22558
- "packages/experience-design-system-generation/dist/src/agent-names.js"() {
23965
+ // packages/experience-design-system-cli/src/tui/import/steps/08-generation/map-tokens.ts
23966
+ async function prepareMapTokens(input, generatedSessionId) {
23967
+ const db = openPipelineDb();
23968
+ try {
23969
+ if (input.tokenSessionId && input.tokenSessionId !== generatedSessionId) {
23970
+ copyTokensFromCache(db, input.tokenSessionId, generatedSessionId);
23971
+ } else if (!input.tokenSessionId && input.tokensPath) {
23972
+ const tokens = await readTokensFromPath2({ flag: "tokens", path: input.tokensPath });
23973
+ storeDtcgTokens(db, generatedSessionId, [], tokens);
23974
+ }
23975
+ const mappablePropCount = loadCDFComponents(db, generatedSessionId).reduce(
23976
+ (count, { entry }) => count + Object.values(entry.$properties).filter((prop) => prop.$type === "token" && prop.$category === "design").length,
23977
+ 0
23978
+ );
23979
+ const rawTokenCount = getDtcgTokensForSession(db, generatedSessionId).tokens.length;
23980
+ return {
23981
+ eligible: shouldRunMapTokens({ mappablePropCount, rawTokenCount }),
23982
+ mappablePropCount,
23983
+ rawTokenCount
23984
+ };
23985
+ } finally {
23986
+ db.close();
23987
+ }
23988
+ }
23989
+ var init_map_tokens = __esm({
23990
+ "packages/experience-design-system-cli/src/tui/import/steps/08-generation/map-tokens.ts"() {
22559
23991
  "use strict";
22560
- AGENT_BINARIES2 = {
22561
- claude: "claude",
22562
- codex: "codex",
22563
- opencode: "opencode",
22564
- cursor: "cursor-agent",
22565
- copilot: "copilot"
23992
+ init_src4();
23993
+ init_logic10();
23994
+ }
23995
+ });
23996
+
23997
+ // packages/experience-design-system-cli/src/tui/import/steps/08-generation/save-decisions.ts
23998
+ async function saveDecisions(input) {
23999
+ const db = openPipelineDb();
24000
+ try {
24001
+ applyScopeDecisions(db, input.sessionId, input.decisions);
24002
+ await writeScopeDecisionsSnapshot(db, input.sessionId, input.decisions);
24003
+ } finally {
24004
+ db.close();
24005
+ }
24006
+ }
24007
+ var init_save_decisions = __esm({
24008
+ "packages/experience-design-system-cli/src/tui/import/steps/08-generation/save-decisions.ts"() {
24009
+ "use strict";
24010
+ init_src4();
24011
+ }
24012
+ });
24013
+
24014
+ // packages/experience-design-system-cli/src/tui/import/steps/08-generation/run.ts
24015
+ import { resolve as resolve23 } from "node:path";
24016
+ async function runGeneration(input, onProgress, deps = realDeps3) {
24017
+ let progress = { components: null, mapTokens: "idle", mapTokensEligible: null };
24018
+ const update = (change) => {
24019
+ progress = { ...progress, ...change };
24020
+ onProgress(progress);
24021
+ };
24022
+ const accepted = input.decisions.accepted;
24023
+ const handedOverNames = await input.cachedNames.catch(() => []);
24024
+ try {
24025
+ await deps.saveDecisions({ sessionId: input.sessionId, decisions: input.decisions });
24026
+ } catch (error) {
24027
+ return fail2("save decisions", errorMessage3(error));
24028
+ }
24029
+ if (accepted.length === 0) return { ok: true, generation: { route: "push", acceptedCount: 0 } };
24030
+ const auth = await deps.checkAgentAuth(input.agent);
24031
+ if (auth === "not-found" || auth === "unauthenticated") {
24032
+ return fail2(`${input.agent} auth check`, agentAuthMessage(input.agent, auth));
24033
+ }
24034
+ let generated;
24035
+ try {
24036
+ generated = await deps.runGenerate({
24037
+ sessionId: input.sessionId,
24038
+ agent: input.agent,
24039
+ ...input.agentModel ? { agentModel: input.agentModel } : {},
24040
+ promptOverrides: appendGeneratePromptOverride(input),
24041
+ noCache: input.noCache,
24042
+ existingEntitiesPath: input.existingEntitiesPath,
24043
+ precomputedCachedNames: new Set(handedOverNames),
24044
+ onProgress: (event) => update({ components: applyProgressEvent2(event, progress.components, accepted.length) })
24045
+ });
24046
+ } catch (error) {
24047
+ return fail2("generate components", errorMessage3(error));
24048
+ }
24049
+ if (generated.emptySession) return fail2("generate components", "no raw components in session");
24050
+ if (!generated.allOk) {
24051
+ const firstFailure = generated.results.find((r) => r.failed);
24052
+ return fail2("generate components", firstFailure?.error ?? "unknown error");
24053
+ }
24054
+ let plan;
24055
+ try {
24056
+ plan = await deps.prepareMapTokens(input, input.sessionId);
24057
+ } catch (error) {
24058
+ return fail2("map tokens", errorMessage3(error));
24059
+ }
24060
+ update({ mapTokensEligible: plan.eligible });
24061
+ if (plan.eligible) {
24062
+ update({ mapTokens: "running" });
24063
+ try {
24064
+ const mapTokensOptions = await buildMapTokensOptions(input);
24065
+ await deps.runMapTokens({
24066
+ sessionId: input.sessionId,
24067
+ agent: input.agent,
24068
+ ...input.agentModel ? { model: input.agentModel } : {},
24069
+ cache: !input.noCache,
24070
+ ...mapTokensOptions
24071
+ });
24072
+ } catch (error) {
24073
+ const message = error instanceof MapTokensRunFailure ? error.message : error instanceof Error ? error.message : String(error);
24074
+ return fail2("map tokens", message);
24075
+ }
24076
+ }
24077
+ update({ mapTokens: "complete" });
24078
+ const generatedCount = generated.results.filter((r) => !r.failed).length;
24079
+ return {
24080
+ ok: true,
24081
+ generation: {
24082
+ route: "review",
24083
+ sessionId: input.sessionId,
24084
+ acceptedCount: accepted.length,
24085
+ generatedCount,
24086
+ mapTokensEligible: plan.eligible
24087
+ }
24088
+ };
24089
+ }
24090
+ async function buildMapTokensOptions(input) {
24091
+ const { overrides: parsed, errors } = parsePromptOverrides(input.promptOverrides);
24092
+ if (errors.length > 0) throw new Error(errors.join("; "));
24093
+ const mapOverride = parsed.get("map-tokens");
24094
+ const prompt = {};
24095
+ if (mapOverride?.kind === "text") prompt.skillContentOverride = mapOverride.value;
24096
+ if (mapOverride?.kind === "path") {
24097
+ await resolvePromptOverride(mapOverride);
24098
+ prompt.skillPathOverride = resolve23(mapOverride.value);
24099
+ }
24100
+ if (input.existingEntitiesPath) {
24101
+ const entities = await readExistingContentfulEntitiesFromSession({ path: input.existingEntitiesPath });
24102
+ if (entities) return { ...prompt, existingEntitiesInline: JSON.stringify(summarizeForMapTokens({ entities })) };
24103
+ }
24104
+ return prompt;
24105
+ }
24106
+ function appendGeneratePromptOverride(input) {
24107
+ if (!input.generatePromptPath) return input.promptOverrides;
24108
+ const already = input.promptOverrides.some((override) => override.startsWith("generate="));
24109
+ if (already) return input.promptOverrides;
24110
+ return [...input.promptOverrides, `generate=${input.generatePromptPath}`];
24111
+ }
24112
+ function applyProgressEvent2(event, previous, total) {
24113
+ if (event.kind === "component:started") {
24114
+ return { done: previous?.done ?? 0, total: event.total || total, current: event.name };
24115
+ }
24116
+ if (event.kind === "component:completed" || event.kind === "component:failed" || event.kind === "component:cached") {
24117
+ return { done: (previous?.done ?? 0) + 1, total: event.total || total, current: event.name };
24118
+ }
24119
+ return previous;
24120
+ }
24121
+ var realDeps3, fail2, errorMessage3;
24122
+ var init_run2 = __esm({
24123
+ "packages/experience-design-system-cli/src/tui/import/steps/08-generation/run.ts"() {
24124
+ "use strict";
24125
+ init_src4();
24126
+ init_logic9();
24127
+ init_map_tokens();
24128
+ init_save_decisions();
24129
+ realDeps3 = {
24130
+ checkAgentAuth,
24131
+ saveDecisions,
24132
+ runGenerate: runGenerateComponentsSession,
24133
+ runMapTokens,
24134
+ prepareMapTokens
22566
24135
  };
24136
+ fail2 = (step, message) => ({ ok: false, step, message });
24137
+ errorMessage3 = (error) => error instanceof Error ? error.message : String(error);
22567
24138
  }
22568
24139
  });
22569
24140
 
22570
- // packages/experience-design-system-generation/dist/src/controller/helpers/validate-generation-request.js
22571
- var init_validate_generation_request = __esm({
22572
- "packages/experience-design-system-generation/dist/src/controller/helpers/validate-generation-request.js"() {
24141
+ // packages/experience-design-system-cli/src/tui/import/steps/08-generation/use-generation.ts
24142
+ import { useEffect as useEffect9, useRef as useRef6, useState as useState14 } from "react";
24143
+ function useGeneration(input) {
24144
+ const [state, setState] = useState14();
24145
+ const current = useRef6();
24146
+ useEffect9(() => {
24147
+ current.current = input;
24148
+ if (!input) {
24149
+ setState(void 0);
24150
+ return;
24151
+ }
24152
+ setState({ status: "running", progress: initialProgress2() });
24153
+ void runGeneration(input, (progress) => {
24154
+ if (current.current === input) setState({ status: "running", progress });
24155
+ }).then((result) => {
24156
+ if (current.current === input) setState({ status: "done", result });
24157
+ });
24158
+ return () => {
24159
+ if (current.current === input) current.current = void 0;
24160
+ };
24161
+ }, [input]);
24162
+ return state;
24163
+ }
24164
+ var init_use_generation = __esm({
24165
+ "packages/experience-design-system-cli/src/tui/import/steps/08-generation/use-generation.ts"() {
22573
24166
  "use strict";
22574
- init_agent_names();
24167
+ init_logic10();
24168
+ init_run2();
22575
24169
  }
22576
24170
  });
22577
24171
 
22578
- // packages/experience-design-system-generation/dist/src/services/prompts/helpers/resolve-skill-file.js
22579
- var init_resolve_skill_file = __esm({
22580
- "packages/experience-design-system-generation/dist/src/services/prompts/helpers/resolve-skill-file.js"() {
24172
+ // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/build-flow-start.ts
24173
+ import { join as join22 } from "node:path";
24174
+ function buildFlowStart(input) {
24175
+ const { extraction, handoff, saved, generatePromptPath } = input;
24176
+ const credentials = extraction.credentials ?? {
24177
+ spaceId: saved?.spaceId ?? "",
24178
+ environmentId: saved?.environmentId ?? "",
24179
+ cmaToken: saved?.cmaToken ?? "",
24180
+ host: saved?.host ?? ""
24181
+ };
24182
+ return {
24183
+ handoff,
24184
+ agent: extraction.agent,
24185
+ projectPath: extraction.projectPath,
24186
+ outDir: extraction.projectPath ? join22(extraction.projectPath, ".contentful") : "",
24187
+ rawTokensPath: extraction.rawTokensPath,
24188
+ credentials: {
24189
+ spaceId: credentials.spaceId,
24190
+ environmentId: credentials.environmentId || "master",
24191
+ cmaToken: credentials.cmaToken,
24192
+ host: toConfiguredHost2(credentials.host) ?? DEFAULT_CONFIGURED_HOST
24193
+ },
24194
+ ...generatePromptPath ? { generatePromptPath } : {}
24195
+ };
24196
+ }
24197
+ var init_build_flow_start = __esm({
24198
+ "packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/build-flow-start.ts"() {
22581
24199
  "use strict";
24200
+ init_src4();
22582
24201
  }
22583
24202
  });
22584
24203
 
@@ -22876,623 +24495,87 @@ function setAtPath(root, dottedPath, value) {
22876
24495
  const segments = dottedPath.split(".");
22877
24496
  let cursor = root;
22878
24497
  for (let i = 0; i < segments.length - 1; i += 1) {
22879
- const segment = segments[i];
22880
- const next = cursor[segment];
22881
- if (typeof next !== "object" || next === null) {
22882
- cursor[segment] = {};
22883
- }
22884
- cursor = cursor[segment];
22885
- }
22886
- cursor[segments[segments.length - 1]] = value;
22887
- }
22888
- var COLLISION_LEAF_KEY;
22889
- var init_build2 = __esm({
22890
- "packages/experience-design-system-types/dist/src/cdf/build.js"() {
22891
- "use strict";
22892
- init_schema2();
22893
- COLLISION_LEAF_KEY = "default";
22894
- }
22895
- });
22896
-
22897
- // packages/experience-design-system-types/dist/src/cdf/index.js
22898
- var init_cdf2 = __esm({
22899
- "packages/experience-design-system-types/dist/src/cdf/index.js"() {
22900
- "use strict";
22901
- init_validate5();
22902
- init_schema2();
22903
- init_vocabularies2();
22904
- init_types7();
22905
- init_build2();
22906
- }
22907
- });
22908
-
22909
- // packages/experience-design-system-types/dist/src/dtcg/types.js
22910
- import * as z4 from "zod/mini";
22911
- var DTCGTokenSchema2;
22912
- var init_types8 = __esm({
22913
- "packages/experience-design-system-types/dist/src/dtcg/types.js"() {
22914
- "use strict";
22915
- init_token_types2();
22916
- DTCGTokenSchema2 = z4.strictObject({
22917
- path: z4.string(),
22918
- $type: z4.enum(DESIGN_TOKEN_TYPES2),
22919
- $value: z4.unknown(),
22920
- $description: z4.optional(z4.string())
22921
- });
22922
- }
22923
- });
22924
-
22925
- // packages/experience-design-system-types/dist/src/dtcg/utils.js
22926
- var init_utils = __esm({
22927
- "packages/experience-design-system-types/dist/src/dtcg/utils.js"() {
22928
- "use strict";
22929
- }
22930
- });
22931
-
22932
- // packages/experience-design-system-types/dist/src/dtcg/validate.js
22933
- var TOKEN_TYPE_SET4;
22934
- var init_validate6 = __esm({
22935
- "packages/experience-design-system-types/dist/src/dtcg/validate.js"() {
22936
- "use strict";
22937
- init_token_types2();
22938
- init_utils();
22939
- TOKEN_TYPE_SET4 = new Set(DESIGN_TOKEN_TYPES2);
22940
- }
22941
- });
22942
-
22943
- // packages/experience-design-system-types/dist/src/dtcg/index.js
22944
- var init_dtcg2 = __esm({
22945
- "packages/experience-design-system-types/dist/src/dtcg/index.js"() {
22946
- "use strict";
22947
- init_token_types2();
22948
- init_types8();
22949
- init_utils();
22950
- init_validate6();
22951
- }
22952
- });
22953
-
22954
- // packages/experience-design-system-types/dist/src/index.js
22955
- var init_src5 = __esm({
22956
- "packages/experience-design-system-types/dist/src/index.js"() {
22957
- "use strict";
22958
- init_cdf2();
22959
- init_dtcg2();
22960
- }
22961
- });
22962
-
22963
- // packages/experience-design-system-generation/dist/src/services/prompts/helpers/format-token-candidates.js
22964
- var init_format_token_candidates2 = __esm({
22965
- "packages/experience-design-system-generation/dist/src/services/prompts/helpers/format-token-candidates.js"() {
22966
- "use strict";
22967
- init_src5();
22968
- }
22969
- });
22970
-
22971
- // packages/experience-design-system-generation/dist/src/services/prompts/helpers/format-source-refs.js
22972
- var init_format_source_refs = __esm({
22973
- "packages/experience-design-system-generation/dist/src/services/prompts/helpers/format-source-refs.js"() {
22974
- "use strict";
22975
- init_format_token_candidates2();
22976
- }
22977
- });
22978
-
22979
- // packages/experience-design-system-generation/dist/src/services/prompts/helpers/build-skill-preambles.js
22980
- var init_build_skill_preambles = __esm({
22981
- "packages/experience-design-system-generation/dist/src/services/prompts/helpers/build-skill-preambles.js"() {
22982
- "use strict";
22983
- }
22984
- });
22985
-
22986
- // packages/experience-design-system-generation/dist/src/services/prompts/helpers/build-preamble.js
22987
- var init_build_preamble = __esm({
22988
- "packages/experience-design-system-generation/dist/src/services/prompts/helpers/build-preamble.js"() {
22989
- "use strict";
22990
- init_format_token_candidates2();
22991
- init_format_source_refs();
22992
- init_build_skill_preambles();
22993
- }
22994
- });
22995
-
22996
- // packages/experience-design-system-generation/dist/src/services/prompts/build-prompt.js
22997
- var init_build_prompt2 = __esm({
22998
- "packages/experience-design-system-generation/dist/src/services/prompts/build-prompt.js"() {
22999
- "use strict";
23000
- init_resolve_skill_file();
23001
- init_build_preamble();
23002
- init_resolve_skill_file();
23003
- }
23004
- });
23005
-
23006
- // packages/experience-design-system-generation/dist/src/orchestrator/execute-generation-orchestrator.js
23007
- var init_execute_generation_orchestrator = __esm({
23008
- "packages/experience-design-system-generation/dist/src/orchestrator/execute-generation-orchestrator.js"() {
23009
- "use strict";
23010
- init_build_prompt2();
23011
- }
23012
- });
23013
-
23014
- // packages/experience-design-system-generation/dist/src/services/agent/helpers/resolve-agent-binary.js
23015
- function resolveAgentBinary(agent) {
23016
- const envKey = `EDS_AGENT_BINARY_${agent.toUpperCase()}`;
23017
- const override = process.env[envKey];
23018
- if (override && override.trim())
23019
- return override.trim();
23020
- return AGENT_BINARIES2[agent];
23021
- }
23022
- var init_resolve_agent_binary = __esm({
23023
- "packages/experience-design-system-generation/dist/src/services/agent/helpers/resolve-agent-binary.js"() {
23024
- "use strict";
23025
- init_agent_names();
23026
- }
23027
- });
23028
-
23029
- // packages/experience-design-system-generation/dist/src/services/agent/helpers/build-agent-args.js
23030
- var init_build_agent_args2 = __esm({
23031
- "packages/experience-design-system-generation/dist/src/services/agent/helpers/build-agent-args.js"() {
23032
- "use strict";
23033
- }
23034
- });
23035
-
23036
- // packages/experience-design-system-generation/dist/src/services/agent/helpers/describe-agent-failure.js
23037
- var init_describe_agent_failure2 = __esm({
23038
- "packages/experience-design-system-generation/dist/src/services/agent/helpers/describe-agent-failure.js"() {
23039
- "use strict";
23040
- }
23041
- });
23042
-
23043
- // packages/experience-design-system-generation/dist/src/services/agent/helpers/extract-sentinel-output.js
23044
- var init_extract_sentinel_output2 = __esm({
23045
- "packages/experience-design-system-generation/dist/src/services/agent/helpers/extract-sentinel-output.js"() {
23046
- "use strict";
23047
- }
23048
- });
23049
-
23050
- // packages/experience-design-system-generation/dist/src/services/agent/run-agent.js
23051
- var init_run_agent2 = __esm({
23052
- "packages/experience-design-system-generation/dist/src/services/agent/run-agent.js"() {
23053
- "use strict";
23054
- init_resolve_agent_binary();
23055
- init_build_agent_args2();
23056
- init_describe_agent_failure2();
23057
- init_extract_sentinel_output2();
23058
- }
23059
- });
23060
-
23061
- // packages/experience-design-system-generation/dist/src/services/agent/helpers/check-claude-auth.js
23062
- import { spawn as spawn5 } from "node:child_process";
23063
- function checkClaudeAuth(binary) {
23064
- return new Promise((resolve22) => {
23065
- const child = spawn5(binary, ["auth", "status", "--json"], {
23066
- stdio: ["ignore", "pipe", "pipe"]
23067
- });
23068
- let stdout = "";
23069
- let done = false;
23070
- const timer = setTimeout(() => {
23071
- if (!done) {
23072
- done = true;
23073
- child.kill("SIGTERM");
23074
- resolve22("unauthenticated");
23075
- }
23076
- }, 5e3);
23077
- child.stdout?.on("data", (chunk) => {
23078
- stdout += chunk.toString();
23079
- });
23080
- child.on("close", (code) => {
23081
- if (done)
23082
- return;
23083
- done = true;
23084
- clearTimeout(timer);
23085
- if (code !== 0) {
23086
- resolve22("unauthenticated");
23087
- return;
23088
- }
23089
- try {
23090
- const status = JSON.parse(stdout);
23091
- resolve22(status.loggedIn ? "ok" : "unauthenticated");
23092
- } catch {
23093
- resolve22("unauthenticated");
23094
- }
23095
- });
23096
- });
23097
- }
23098
- var init_check_claude_auth = __esm({
23099
- "packages/experience-design-system-generation/dist/src/services/agent/helpers/check-claude-auth.js"() {
23100
- "use strict";
23101
- }
23102
- });
23103
-
23104
- // packages/experience-design-system-generation/dist/src/services/agent/helpers/check-agent-auth.js
23105
- import { spawn as spawn6 } from "node:child_process";
23106
- async function checkAgentAuth2(agent) {
23107
- const binary = resolveAgentBinary(agent);
23108
- const binaryExists2 = await new Promise((resolve22) => {
23109
- if (binary.startsWith("/")) {
23110
- import("node:fs/promises").then((fs) => fs.access(binary).then(() => resolve22(true), () => resolve22(false)));
23111
- return;
23112
- }
23113
- const child = spawn6(process.platform === "win32" ? "where" : "which", [binary], { stdio: "ignore" });
23114
- child.on("close", (code) => resolve22(code === 0));
23115
- });
23116
- if (!binaryExists2)
23117
- return "not-found";
23118
- if (agent !== "claude")
23119
- return "ok";
23120
- return checkClaudeAuth(binary);
23121
- }
23122
- var init_check_agent_auth2 = __esm({
23123
- "packages/experience-design-system-generation/dist/src/services/agent/helpers/check-agent-auth.js"() {
23124
- "use strict";
23125
- init_resolve_agent_binary();
23126
- init_check_claude_auth();
23127
- }
23128
- });
23129
-
23130
- // packages/experience-design-system-generation/dist/src/services/agent/local-cli-agent-invoker.js
23131
- var init_local_cli_agent_invoker = __esm({
23132
- "packages/experience-design-system-generation/dist/src/services/agent/local-cli-agent-invoker.js"() {
23133
- "use strict";
23134
- init_run_agent2();
23135
- init_check_agent_auth2();
23136
- }
23137
- });
23138
-
23139
- // packages/experience-design-system-generation/dist/src/controller/create-generation-endpoint.js
23140
- var init_create_generation_endpoint = __esm({
23141
- "packages/experience-design-system-generation/dist/src/controller/create-generation-endpoint.js"() {
23142
- "use strict";
23143
- init_validate_generation_request();
23144
- init_execute_generation_orchestrator();
23145
- init_local_cli_agent_invoker();
23146
- }
23147
- });
23148
-
23149
- // packages/experience-design-system-generation/dist/src/services/parsing/helpers/read-tool-call-objects.js
23150
- var init_read_tool_call_objects2 = __esm({
23151
- "packages/experience-design-system-generation/dist/src/services/parsing/helpers/read-tool-call-objects.js"() {
23152
- "use strict";
23153
- }
23154
- });
23155
-
23156
- // packages/experience-design-system-generation/dist/src/services/parsing/parse-prop-tool-calls.js
23157
- var init_parse_prop_tool_calls = __esm({
23158
- "packages/experience-design-system-generation/dist/src/services/parsing/parse-prop-tool-calls.js"() {
23159
- "use strict";
23160
- init_read_tool_call_objects2();
23161
- }
23162
- });
23163
-
23164
- // packages/experience-design-system-generation/dist/src/services/parsing/parse-select-tool-calls.js
23165
- var init_parse_select_tool_calls2 = __esm({
23166
- "packages/experience-design-system-generation/dist/src/services/parsing/parse-select-tool-calls.js"() {
23167
- "use strict";
23168
- init_read_tool_call_objects2();
23169
- }
23170
- });
23171
-
23172
- // packages/experience-design-system-generation/dist/src/services/parsing/parse-token-tool-calls.js
23173
- var init_parse_token_tool_calls2 = __esm({
23174
- "packages/experience-design-system-generation/dist/src/services/parsing/parse-token-tool-calls.js"() {
23175
- "use strict";
23176
- init_read_tool_call_objects2();
23177
- }
23178
- });
23179
-
23180
- // packages/experience-design-system-generation/dist/src/services/parsing/parse-map-token-tool-calls.js
23181
- var init_parse_map_token_tool_calls = __esm({
23182
- "packages/experience-design-system-generation/dist/src/services/parsing/parse-map-token-tool-calls.js"() {
23183
- "use strict";
24498
+ const segment = segments[i];
24499
+ const next = cursor[segment];
24500
+ if (typeof next !== "object" || next === null) {
24501
+ cursor[segment] = {};
24502
+ }
24503
+ cursor = cursor[segment];
23184
24504
  }
23185
- });
23186
-
23187
- // packages/experience-design-system-generation/dist/src/progress.js
23188
- var init_progress = __esm({
23189
- "packages/experience-design-system-generation/dist/src/progress.js"() {
24505
+ cursor[segments[segments.length - 1]] = value;
24506
+ }
24507
+ var COLLISION_LEAF_KEY;
24508
+ var init_build2 = __esm({
24509
+ "packages/experience-design-system-types/dist/src/cdf/build.js"() {
23190
24510
  "use strict";
24511
+ init_schema2();
24512
+ COLLISION_LEAF_KEY = "default";
23191
24513
  }
23192
24514
  });
23193
24515
 
23194
- // packages/experience-design-system-generation/dist/src/index.js
23195
- var init_src6 = __esm({
23196
- "packages/experience-design-system-generation/dist/src/index.js"() {
24516
+ // packages/experience-design-system-types/dist/src/cdf/index.js
24517
+ var init_cdf2 = __esm({
24518
+ "packages/experience-design-system-types/dist/src/cdf/index.js"() {
23197
24519
  "use strict";
23198
- init_agent_names();
23199
- init_create_generation_endpoint();
23200
- init_execute_generation_orchestrator();
23201
- init_build_agent_args2();
23202
- init_resolve_agent_binary();
23203
- init_check_agent_auth2();
23204
- init_run_agent2();
23205
- init_parse_prop_tool_calls();
23206
- init_parse_select_tool_calls2();
23207
- init_parse_token_tool_calls2();
23208
- init_parse_map_token_tool_calls();
23209
- init_build_prompt2();
23210
- init_progress();
23211
- init_local_cli_agent_invoker();
24520
+ init_validate5();
24521
+ init_schema2();
24522
+ init_vocabularies2();
24523
+ init_types7();
24524
+ init_build2();
23212
24525
  }
23213
24526
  });
23214
24527
 
23215
- // packages/experience-design-system-cli/src/tui/import/steps/08-generation/map-tokens.ts
23216
- async function prepareMapTokens(input, generatedSessionId) {
23217
- const db = openPipelineDb();
23218
- try {
23219
- if (input.tokenSessionId && input.tokenSessionId !== generatedSessionId) {
23220
- copyTokensFromCache(db, input.tokenSessionId, generatedSessionId);
23221
- } else if (!input.tokenSessionId && input.tokensPath) {
23222
- const tokens = await readTokensFromPath2({ flag: "tokens", path: input.tokensPath });
23223
- storeDtcgTokens(db, generatedSessionId, [], tokens);
23224
- }
23225
- const mappablePropCount = loadCDFComponents(db, generatedSessionId).reduce(
23226
- (count, { entry }) => count + Object.values(entry.$properties).filter((prop) => prop.$type === "token" && prop.$category === "design").length,
23227
- 0
23228
- );
23229
- const rawTokenCount = getDtcgTokensForSession(db, generatedSessionId).tokens.length;
23230
- return {
23231
- eligible: shouldRunMapTokens({ mappablePropCount, rawTokenCount }),
23232
- mappablePropCount,
23233
- rawTokenCount
23234
- };
23235
- } finally {
23236
- db.close();
23237
- }
23238
- }
23239
- var init_map_tokens = __esm({
23240
- "packages/experience-design-system-cli/src/tui/import/steps/08-generation/map-tokens.ts"() {
24528
+ // packages/experience-design-system-types/dist/src/dtcg/types.js
24529
+ import * as z4 from "zod/mini";
24530
+ var DTCGTokenSchema2;
24531
+ var init_types8 = __esm({
24532
+ "packages/experience-design-system-types/dist/src/dtcg/types.js"() {
23241
24533
  "use strict";
23242
- init_src4();
23243
- init_logic10();
23244
- }
23245
- });
23246
-
23247
- // packages/experience-design-system-cli/src/tui/import/steps/08-generation/processes.ts
23248
- import { execFile as execFile3, spawn as spawn7 } from "node:child_process";
23249
- function buildGenerateArgs(cliPath, command) {
23250
- const args = [cliPath, "__generate", "components", "--agent", command.agent, "--session", command.sessionId];
23251
- if (command.tokensPath) args.push("--tokens", command.tokensPath);
23252
- if (command.agentModel) args.push("--model", command.agentModel);
23253
- if (command.noCache) args.push("--no-cache");
23254
- if (command.generatePromptPath) args.push("--generate-prompt-path", command.generatePromptPath);
23255
- for (const prompt of command.promptOverrides) args.push("--prompt", prompt);
23256
- if (command.existingEntitiesPath) args.push("--existing-entities-path", command.existingEntitiesPath);
23257
- if (command.cachedComponents.length > 0) args.push("--cached-components", JSON.stringify(command.cachedComponents));
23258
- return args;
23259
- }
23260
- function buildMapTokensArgs(command) {
23261
- const args = ["map", "tokens", "--session", command.sessionId, "--agent", command.agent];
23262
- if (command.agentModel) args.push("--model", command.agentModel);
23263
- if (command.noCache) args.push("--no-cache");
23264
- for (const prompt of command.promptOverrides) args.push("--prompt", prompt);
23265
- if (command.existingEntitiesPath) args.push("--existing-entities-path", command.existingEntitiesPath);
23266
- return args;
23267
- }
23268
- function spawnGenerate(command, handlers) {
23269
- return new Promise((resolve22) => {
23270
- const child = spawn7("node", buildGenerateArgs(findLegacyCliPath(), command));
23271
- let stdout = "";
23272
- let stderr = "";
23273
- child.stdout.on("data", (data) => {
23274
- stdout += String(data);
23275
- });
23276
- child.stderr.on("data", (data) => {
23277
- const chunk = String(data);
23278
- stderr += chunk;
23279
- handlers.onStderr(chunk);
23280
- });
23281
- child.on("error", (error) => resolve22({ exitCode: 1, stdout, stderr: stderr + error.message }));
23282
- child.on("close", (code) => resolve22({ exitCode: code ?? 0, stdout, stderr }));
23283
- });
23284
- }
23285
- function runMapTokens2(command) {
23286
- return new Promise((resolve22) => {
23287
- execFile3("node", [findLegacyCliPath(), ...buildMapTokensArgs(command)], (error, stdout, stderr) => {
23288
- resolve22({ exitCode: error?.code ? Number(error.code) : 0, stdout, stderr });
24534
+ init_token_types2();
24535
+ DTCGTokenSchema2 = z4.strictObject({
24536
+ path: z4.string(),
24537
+ $type: z4.enum(DESIGN_TOKEN_TYPES2),
24538
+ $value: z4.unknown(),
24539
+ $description: z4.optional(z4.string())
23289
24540
  });
23290
- });
23291
- }
23292
- var init_processes = __esm({
23293
- "packages/experience-design-system-cli/src/tui/import/steps/08-generation/processes.ts"() {
23294
- "use strict";
23295
- init_legacy_cli_path();
23296
24541
  }
23297
24542
  });
23298
24543
 
23299
- // packages/experience-design-system-cli/src/tui/import/steps/08-generation/save-decisions.ts
23300
- async function saveDecisions(input) {
23301
- const db = openPipelineDb();
23302
- try {
23303
- applyScopeDecisions(db, input.sessionId, input.decisions);
23304
- await writeScopeDecisionsSnapshot(db, input.sessionId, input.decisions);
23305
- } finally {
23306
- db.close();
23307
- }
23308
- }
23309
- var init_save_decisions = __esm({
23310
- "packages/experience-design-system-cli/src/tui/import/steps/08-generation/save-decisions.ts"() {
24544
+ // packages/experience-design-system-types/dist/src/dtcg/utils.js
24545
+ var init_utils = __esm({
24546
+ "packages/experience-design-system-types/dist/src/dtcg/utils.js"() {
23311
24547
  "use strict";
23312
- init_src4();
23313
24548
  }
23314
24549
  });
23315
24550
 
23316
- // packages/experience-design-system-cli/src/tui/import/steps/08-generation/run.ts
23317
- async function runGeneration(input, onProgress, deps = realDeps3) {
23318
- let progress = initialProgress2();
23319
- const update = (change) => {
23320
- progress = { ...progress, ...change };
23321
- onProgress(progress);
23322
- };
23323
- const accepted = input.decisions.accepted;
23324
- const handedOverNames = await input.cachedNames.catch(() => []);
23325
- try {
23326
- await deps.saveDecisions({ sessionId: input.sessionId, decisions: input.decisions });
23327
- } catch (error) {
23328
- return fail2("save decisions", errorMessage3(error));
23329
- }
23330
- if (accepted.length === 0) return { ok: true, generation: { route: "push", acceptedCount: 0 } };
23331
- const auth = await deps.checkAgentAuth(input.agent);
23332
- if (auth === "not-found" || auth === "unauthenticated") {
23333
- return fail2(`${input.agent} auth check`, agentAuthMessage(input.agent, auth));
23334
- }
23335
- const acceptedSet = new Set(accepted);
23336
- let cachedNames = handedOverNames;
23337
- let cacheHit = !input.noCache && accepted.length > 0 && accepted.every((name) => cachedNames.includes(name));
23338
- if (!cacheHit && !input.noCache && accepted.length > 0) {
23339
- const fresh = await deps.checkCache(cacheCheckFor(input));
23340
- cachedNames = fresh.filter((name) => acceptedSet.has(name));
23341
- cacheHit = accepted.every((name) => cachedNames.includes(name));
23342
- }
23343
- let generatedSessionId = input.sessionId;
23344
- let generatedCount = accepted.length;
23345
- if (!cacheHit) {
23346
- const result = await deps.spawnGenerate(
23347
- {
23348
- sessionId: input.sessionId,
23349
- tokensPath: input.tokensPath,
23350
- agent: input.agent,
23351
- ...input.agentModel ? { agentModel: input.agentModel } : {},
23352
- promptOverrides: input.promptOverrides,
23353
- ...input.generatePromptPath ? { generatePromptPath: input.generatePromptPath } : {},
23354
- noCache: input.noCache,
23355
- existingEntitiesPath: input.existingEntitiesPath,
23356
- cachedComponents: cachedNames
23357
- },
23358
- {
23359
- onStderr: (chunk) => {
23360
- const components = applyGenerateStderr(chunk, progress.components);
23361
- if (components !== progress.components) update({ components });
23362
- }
23363
- }
23364
- );
23365
- if (result.exitCode !== 0) return fail2("generate components", result.stderr.trim() || "Unknown error");
23366
- const parsed = parseGenerateResult(result, accepted.length);
23367
- generatedSessionId = parsed.generateSessionId ?? input.sessionId;
23368
- generatedCount = parsed.generatedCount;
23369
- }
23370
- let plan;
23371
- try {
23372
- plan = await deps.prepareMapTokens(input, generatedSessionId);
23373
- } catch (error) {
23374
- return fail2("map tokens", errorMessage3(error));
23375
- }
23376
- update({ mapTokensEligible: plan.eligible });
23377
- if (plan.eligible) {
23378
- update({ mapTokens: "running" });
23379
- const mapped = await deps.runMapTokens({
23380
- sessionId: generatedSessionId,
23381
- agent: input.agent,
23382
- ...input.agentModel ? { agentModel: input.agentModel } : {},
23383
- promptOverrides: input.promptOverrides,
23384
- noCache: input.noCache,
23385
- existingEntitiesPath: input.existingEntitiesPath
23386
- });
23387
- if (mapped.exitCode !== 0) return fail2("map tokens", mapped.stderr.trim() || "Unknown error");
23388
- }
23389
- update({ mapTokens: "complete" });
23390
- return {
23391
- ok: true,
23392
- generation: {
23393
- route: "review",
23394
- sessionId: generatedSessionId,
23395
- acceptedCount: accepted.length,
23396
- generatedCount,
23397
- mapTokensEligible: plan.eligible
23398
- }
23399
- };
23400
- }
23401
- function cacheCheckFor(input) {
23402
- return {
23403
- sessionId: input.sessionId,
23404
- tokensPath: input.tokensPath,
23405
- agent: input.agent,
23406
- ...input.agentModel ? { agentModel: input.agentModel } : {},
23407
- promptOverrides: input.promptOverrides,
23408
- existingEntitiesPath: input.existingEntitiesPath,
23409
- noCache: input.noCache
23410
- };
23411
- }
23412
- var realDeps3, fail2, errorMessage3;
23413
- var init_run2 = __esm({
23414
- "packages/experience-design-system-cli/src/tui/import/steps/08-generation/run.ts"() {
24551
+ // packages/experience-design-system-types/dist/src/dtcg/validate.js
24552
+ var TOKEN_TYPE_SET4;
24553
+ var init_validate6 = __esm({
24554
+ "packages/experience-design-system-types/dist/src/dtcg/validate.js"() {
23415
24555
  "use strict";
23416
- init_src6();
23417
- init_logic9();
23418
- init_cache_check();
23419
- init_logic10();
23420
- init_map_tokens();
23421
- init_processes();
23422
- init_save_decisions();
23423
- realDeps3 = {
23424
- checkAgentAuth: checkAgentAuth2,
23425
- saveDecisions,
23426
- checkCache: checkGenerationCache,
23427
- spawnGenerate,
23428
- prepareMapTokens,
23429
- runMapTokens: runMapTokens2
23430
- };
23431
- fail2 = (step, message) => ({ ok: false, step, message });
23432
- errorMessage3 = (error) => error instanceof Error ? error.message : String(error);
24556
+ init_token_types2();
24557
+ init_utils();
24558
+ TOKEN_TYPE_SET4 = new Set(DESIGN_TOKEN_TYPES2);
23433
24559
  }
23434
24560
  });
23435
24561
 
23436
- // packages/experience-design-system-cli/src/tui/import/steps/08-generation/use-generation.ts
23437
- import { useEffect as useEffect9, useRef as useRef6, useState as useState14 } from "react";
23438
- function useGeneration(input) {
23439
- const [state, setState] = useState14();
23440
- const current = useRef6();
23441
- useEffect9(() => {
23442
- current.current = input;
23443
- if (!input) {
23444
- setState(void 0);
23445
- return;
23446
- }
23447
- setState({ status: "running", progress: initialProgress2() });
23448
- void runGeneration(input, (progress) => {
23449
- if (current.current === input) setState({ status: "running", progress });
23450
- }).then((result) => {
23451
- if (current.current === input) setState({ status: "done", result });
23452
- });
23453
- return () => {
23454
- if (current.current === input) current.current = void 0;
23455
- };
23456
- }, [input]);
23457
- return state;
23458
- }
23459
- var init_use_generation = __esm({
23460
- "packages/experience-design-system-cli/src/tui/import/steps/08-generation/use-generation.ts"() {
24562
+ // packages/experience-design-system-types/dist/src/dtcg/index.js
24563
+ var init_dtcg2 = __esm({
24564
+ "packages/experience-design-system-types/dist/src/dtcg/index.js"() {
23461
24565
  "use strict";
23462
- init_logic10();
23463
- init_run2();
24566
+ init_token_types2();
24567
+ init_types8();
24568
+ init_utils();
24569
+ init_validate6();
23464
24570
  }
23465
24571
  });
23466
24572
 
23467
- // packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/build-flow-start.ts
23468
- import { join as join22 } from "node:path";
23469
- function buildFlowStart(input) {
23470
- const { extraction, handoff, saved, generatePromptPath } = input;
23471
- const credentials = extraction.credentials ?? {
23472
- spaceId: saved?.spaceId ?? "",
23473
- environmentId: saved?.environmentId ?? "",
23474
- cmaToken: saved?.cmaToken ?? "",
23475
- host: saved?.host ?? ""
23476
- };
23477
- return {
23478
- handoff,
23479
- agent: extraction.agent,
23480
- projectPath: extraction.projectPath,
23481
- outDir: extraction.projectPath ? join22(extraction.projectPath, ".contentful") : "",
23482
- rawTokensPath: extraction.rawTokensPath,
23483
- credentials: {
23484
- spaceId: credentials.spaceId,
23485
- environmentId: credentials.environmentId || "master",
23486
- cmaToken: credentials.cmaToken,
23487
- host: toConfiguredHost2(credentials.host) ?? DEFAULT_CONFIGURED_HOST
23488
- },
23489
- ...generatePromptPath ? { generatePromptPath } : {}
23490
- };
23491
- }
23492
- var init_build_flow_start = __esm({
23493
- "packages/experience-design-system-cli/src/tui/import/steps/10-flow/flow/build-flow-start.ts"() {
24573
+ // packages/experience-design-system-types/dist/src/index.js
24574
+ var init_src5 = __esm({
24575
+ "packages/experience-design-system-types/dist/src/index.js"() {
23494
24576
  "use strict";
23495
- init_src4();
24577
+ init_cdf2();
24578
+ init_dtcg2();
23496
24579
  }
23497
24580
  });
23498
24581
 
@@ -23521,8 +24604,8 @@ function missingNote(missingNames) {
23521
24604
  Note: ${plural2(missingNames.length, "component name")} from the server (${missingNames.join(", ")}) ${verb} not match anything in this session \u2014 they cannot be edited or skipped from here.`;
23522
24605
  }
23523
24606
  function contextText(errors, missingNames) {
23524
- const failed = failedComponentNames(errors);
23525
- return `${plural2(failed.length, "component")} failed server validation. Edit their definitions in the review TUI, or skip them and retry preview without them.${missingNote(missingNames)}`;
24607
+ const failed2 = failedComponentNames(errors);
24608
+ return `${plural2(failed2.length, "component")} failed server validation. Edit their definitions in the review TUI, or skip them and retry preview without them.${missingNote(missingNames)}`;
23526
24609
  }
23527
24610
  function skipLabel(matchedNames) {
23528
24611
  if (matchedNames.length === 0) return "No matching components to skip";
@@ -26627,7 +27710,7 @@ var init_history = __esm({
26627
27710
  // packages/experience-design-system-cli/src/tui/import/steps/09-review/run-live-preview.ts
26628
27711
  async function runLivePreview(opts) {
26629
27712
  const { sessionId, tokensPath, spaceId, environmentId, cmaToken, host, generation } = opts;
26630
- const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS5;
27713
+ const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS6;
26631
27714
  if (!spaceId || !environmentId || !cmaToken) {
26632
27715
  return { generation, response: null };
26633
27716
  }
@@ -26670,7 +27753,7 @@ async function runLivePreview(opts) {
26670
27753
  if (timeoutHandle) clearTimeout(timeoutHandle);
26671
27754
  }
26672
27755
  }
26673
- var TimeoutError, DEFAULT_TIMEOUT_MS5;
27756
+ var TimeoutError, DEFAULT_TIMEOUT_MS6;
26674
27757
  var init_run_live_preview = __esm({
26675
27758
  "packages/experience-design-system-cli/src/tui/import/steps/09-review/run-live-preview.ts"() {
26676
27759
  "use strict";
@@ -26685,7 +27768,7 @@ var init_run_live_preview = __esm({
26685
27768
  this.name = "TimeoutError";
26686
27769
  }
26687
27770
  };
26688
- DEFAULT_TIMEOUT_MS5 = 15e3;
27771
+ DEFAULT_TIMEOUT_MS6 = 15e3;
26689
27772
  }
26690
27773
  });
26691
27774
 
@@ -29296,7 +30379,7 @@ var init_DoneStep = __esm({
29296
30379
  });
29297
30380
 
29298
30381
  // packages/experience-design-system-cli/src/tui/import/steps/10-flow/support/path-utils.ts
29299
- import { resolve as resolve21 } from "node:path";
30382
+ import { resolve as resolve24 } from "node:path";
29300
30383
  import { homedir as homedir4 } from "node:os";
29301
30384
  function expandTilde(input) {
29302
30385
  if (input === "~" || input.startsWith("~/") || input.startsWith("~\\")) {
@@ -29310,7 +30393,7 @@ function normalizePath(input) {
29310
30393
  p = p.slice(1, -1);
29311
30394
  }
29312
30395
  p = expandTilde(p);
29313
- return resolve21(p);
30396
+ return resolve24(p);
29314
30397
  }
29315
30398
  var init_path_utils = __esm({
29316
30399
  "packages/experience-design-system-cli/src/tui/import/steps/10-flow/support/path-utils.ts"() {
@@ -30463,19 +31546,19 @@ function resultOf(operation, preview) {
30463
31546
  const items = operation.items ?? [];
30464
31547
  if (items.length > 0) {
30465
31548
  const count = (entityType, action) => items.filter((i) => i.entityType === entityType && i.action === action && i.status === "succeeded").length;
30466
- const failed = (entityType) => items.filter((i) => i.entityType === entityType && i.status === "failed").length;
31549
+ const failed2 = (entityType) => items.filter((i) => i.entityType === entityType && i.status === "failed").length;
30467
31550
  return {
30468
31551
  componentTypes: {
30469
31552
  created: count("ComponentType", "create"),
30470
31553
  updated: count("ComponentType", "update"),
30471
31554
  removed: count("ComponentType", "delete"),
30472
- failed: failed("ComponentType")
31555
+ failed: failed2("ComponentType")
30473
31556
  },
30474
31557
  designTokens: {
30475
31558
  created: count("DesignToken", "create"),
30476
31559
  updated: count("DesignToken", "update"),
30477
31560
  removed: count("DesignToken", "delete"),
30478
- failed: failed("DesignToken")
31561
+ failed: failed2("DesignToken")
30479
31562
  },
30480
31563
  summary: operation.summary,
30481
31564
  failures: items.filter((item) => item.status === "failed").map((item) => ({
@@ -30653,7 +31736,7 @@ var init_save = __esm({
30653
31736
  writeFile: (path5, contents) => writeFile7(path5, contents),
30654
31737
  appendRun,
30655
31738
  buildSourceFingerprint,
30656
- sleep: (ms) => new Promise((resolve22) => setTimeout(resolve22, ms)),
31739
+ sleep: (ms) => new Promise((resolve25) => setTimeout(resolve25, ms)),
30657
31740
  warn: (message) => process.stderr.write(message)
30658
31741
  });
30659
31742
  }
@@ -32088,8 +33171,28 @@ import { join as join28 } from "node:path";
32088
33171
  import { Command } from "commander";
32089
33172
 
32090
33173
  // packages/experience-design-system-cli/src/legacy/run-legacy.ts
32091
- init_legacy_cli_path();
32092
33174
  import { spawn } from "node:child_process";
33175
+
33176
+ // packages/experience-design-system-cli/src/legacy/legacy-cli-path.ts
33177
+ init_package_root();
33178
+ import { existsSync as existsSync2 } from "node:fs";
33179
+ import { join as join2 } from "node:path";
33180
+ var PACKAGE_NAME = "@contentful/experience-design-system-cli";
33181
+ function findLegacyCliPath() {
33182
+ const root = findPackageRoot(import.meta.url, PACKAGE_NAME);
33183
+ const candidates = [
33184
+ join2(root, "legacy", "bin", "cli.js"),
33185
+ join2(root, "..", "experience-design-system-cli-legacy", "bin", "cli.js")
33186
+ ];
33187
+ const found = candidates.find((candidate) => existsSync2(candidate));
33188
+ if (!found) {
33189
+ throw new Error(`Legacy CLI not found. Looked in:
33190
+ ${candidates.join("\n")}`);
33191
+ }
33192
+ return found;
33193
+ }
33194
+
33195
+ // packages/experience-design-system-cli/src/legacy/run-legacy.ts
32093
33196
  function runLegacy(args) {
32094
33197
  return new Promise((resolvePromise) => {
32095
33198
  let cliPath;
@@ -32168,14 +33271,14 @@ function runDevWatch(args) {
32168
33271
  process.stderr.write("--watch only works from a checkout of the repo (scripts/dev.mjs is not in the package).\n");
32169
33272
  return Promise.resolve(1);
32170
33273
  }
32171
- return new Promise((resolve22) => {
33274
+ return new Promise((resolve25) => {
32172
33275
  const child = spawn2(process.execPath, [script, ...args], { stdio: "inherit" });
32173
33276
  process.on("SIGINT", () => void 0);
32174
- child.on("exit", (code) => resolve22(code ?? 0));
33277
+ child.on("exit", (code) => resolve25(code ?? 0));
32175
33278
  child.on("error", (err) => {
32176
33279
  process.stderr.write(`${err.message}
32177
33280
  `);
32178
- resolve22(1);
33281
+ resolve25(1);
32179
33282
  });
32180
33283
  });
32181
33284
  }
@@ -32219,12 +33322,12 @@ function createProgram() {
32219
33322
  init_config();
32220
33323
  init_package_root();
32221
33324
  import { existsSync as existsSync12 } from "node:fs";
32222
- import { mkdir as mkdir10, readFile as readFile16, rename as rename3, rmdir, unlink } from "node:fs/promises";
33325
+ import { mkdir as mkdir10, readFile as readFile19, rename as rename3, rmdir, unlink } from "node:fs/promises";
32223
33326
  import { dirname as dirname16, join as join29 } from "node:path";
32224
33327
  var PACKAGE_NAME4 = "@contentful/experience-design-system-cli";
32225
33328
  async function readJson(path5) {
32226
33329
  try {
32227
- return JSON.parse(await readFile16(path5, "utf8"));
33330
+ return JSON.parse(await readFile19(path5, "utf8"));
32228
33331
  } catch {
32229
33332
  return void 0;
32230
33333
  }