@astryxdesign/cli 0.6.5-canary.c3016f8 → 0.6.5-canary.c8d8a1d

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.
Files changed (167) hide show
  1. package/README.md +14 -13
  2. package/api/build/_adapter.d.mts +36 -2
  3. package/api/build/_adapter.mjs +41 -10
  4. package/api/build/build.doc.mjs +2 -2
  5. package/api/build/build.test.mjs +38 -2
  6. package/api/build/kit/kit.mjs +65 -21
  7. package/api/build/kit/rank.d.mts +24 -8
  8. package/api/build/kit/rank.mjs +277 -97
  9. package/api/build/kit/rank.test.mjs +231 -48
  10. package/api/docs/docs.test.mjs +279 -0
  11. package/api/docs/integration-tree.test.mjs +572 -0
  12. package/api/docs/integrationDocs.test.mjs +336 -0
  13. package/api/error.d.mts +22 -0
  14. package/api/error.mjs +42 -0
  15. package/api/integration/add-contribution.d.mts +2 -1
  16. package/api/integration/add-contribution.mjs +7 -3
  17. package/api/integration/add-contribution.test.mjs +3 -3
  18. package/api/integration/add-theme.mjs +246 -24
  19. package/api/integration/add-theme.test.mjs +214 -1
  20. package/api/integration/authoring-checks.mjs +10 -7
  21. package/api/integration/authoring-checks.type.d.mts +8 -0
  22. package/api/integration/authoring-checks.type.mjs +7 -3
  23. package/api/integration/integration-authoring.type.d.mts +4 -1
  24. package/api/integration/integration-authoring.type.mjs +6 -1
  25. package/api/integration/integrationAdd.doc.mjs +6 -0
  26. package/api/integration/integrationAddTheme.doc.mjs +10 -0
  27. package/api/integration/integrationComponentConflicts.doc.mjs +1 -1
  28. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  29. package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
  30. package/api/integration/pack-check.mjs +12 -3
  31. package/api/integration/pack-check.test.mjs +52 -3
  32. package/api/integration/validate-integration.d.mts +4 -2
  33. package/api/integration/validate-integration.mjs +7 -2
  34. package/api/integration/validate-integration.test.mjs +55 -0
  35. package/api/integration/validate-integration.type.d.mts +5 -0
  36. package/api/integration/validate-integration.type.mjs +5 -1
  37. package/api/integration/validateIntegration.doc.mjs +1 -1
  38. package/api/layout/expand/expand.mjs +12 -7
  39. package/api/layout/expand/expand.receipt.test.mjs +74 -0
  40. package/api/layout/layout.type.d.mts +1 -0
  41. package/api/layout/layout.type.mjs +1 -0
  42. package/api/layout/layoutExpand.doc.mjs +1 -1
  43. package/api/search/search.d.mts +24 -0
  44. package/api/search/search.mjs +71 -1
  45. package/api/search/search.test.mjs +710 -0
  46. package/api/swizzle/copy/copy.mjs +66 -3
  47. package/api/swizzle/swizzle.doc.mjs +4 -0
  48. package/api/template/copy/copy.mjs +14 -8
  49. package/api/template/copy/copy.receipt.test.mjs +77 -0
  50. package/api/template/show/show.mjs +15 -4
  51. package/api/template/show/show.test.mjs +76 -0
  52. package/api/template/template-integration.test.mjs +14 -0
  53. package/api/template/template.d.mts +1 -1
  54. package/api/template/template.doc.mjs +6 -2
  55. package/api/template/template.mjs +1 -0
  56. package/api/template/template.type.d.mts +2 -0
  57. package/api/template/template.type.mjs +2 -0
  58. package/api/theme/build/build.d.mts +24 -0
  59. package/api/theme/build/build.mjs +235 -8
  60. package/api/theme/build/build.project-core.test.mjs +165 -0
  61. package/api/upgrade/run/run.mjs +20 -3
  62. package/api/upgrade/run/run.test.mjs +45 -1
  63. package/api/upgrade/upgrade.doc.mjs +1 -1
  64. package/api/upgrade/upgrade.type.d.mts +1 -0
  65. package/api/upgrade/upgrade.type.mjs +1 -0
  66. package/assets/docs/icons.doc.mjs +1 -0
  67. package/assets/docs/theme.doc.mjs +1 -1
  68. package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
  69. package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
  70. package/assets/docs/tree/checks.doc.mjs +1 -1
  71. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  72. package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
  73. package/assets/docs/tree/template-doc-overview.doc.mjs +13 -1
  74. package/assets/docs/tree/troubleshooting.doc.mjs +9 -5
  75. package/assets/docs/tree/versioning.doc.mjs +7 -6
  76. package/assets/templates/pages/ai-chat/template.doc.mjs +16 -1
  77. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +9 -1
  78. package/assets/templates/pages/blank/template.doc.mjs +3 -1
  79. package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -1
  80. package/assets/templates/pages/centered-hero/template.doc.mjs +3 -1
  81. package/assets/templates/pages/checkout-wizard/template.doc.mjs +1 -0
  82. package/assets/templates/pages/classic-gallery/template.doc.mjs +3 -1
  83. package/assets/templates/pages/contact-form/template.doc.mjs +16 -1
  84. package/assets/templates/pages/dashboard/template.doc.mjs +15 -1
  85. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +23 -1
  86. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +10 -1
  87. package/assets/templates/pages/dashboard-comparison/template.doc.mjs +9 -1
  88. package/assets/templates/pages/dashboard-composition/template.doc.mjs +10 -1
  89. package/assets/templates/pages/dashboard-progress/template.doc.mjs +17 -1
  90. package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -1
  91. package/assets/templates/pages/detail-page/template.doc.mjs +8 -0
  92. package/assets/templates/pages/documentation/template.doc.mjs +10 -1
  93. package/assets/templates/pages/documentation-design/template.doc.mjs +10 -1
  94. package/assets/templates/pages/documentation-technical/template.doc.mjs +10 -1
  95. package/assets/templates/pages/editor/template.doc.mjs +9 -1
  96. package/assets/templates/pages/file-explorer/template.doc.mjs +3 -1
  97. package/assets/templates/pages/form-two-column/template.doc.mjs +17 -1
  98. package/assets/templates/pages/form-wizard/template.doc.mjs +14 -1
  99. package/assets/templates/pages/form-wizard-dialog/template.doc.mjs +1 -0
  100. package/assets/templates/pages/gallery-hero/template.doc.mjs +10 -1
  101. package/assets/templates/pages/ide/template.doc.mjs +9 -1
  102. package/assets/templates/pages/incident-console/template.doc.mjs +10 -1
  103. package/assets/templates/pages/kanban-board/template.doc.mjs +11 -1
  104. package/assets/templates/pages/library/template.doc.mjs +15 -1
  105. package/assets/templates/pages/login/template.doc.mjs +10 -1
  106. package/assets/templates/pages/login-card/template.doc.mjs +11 -1
  107. package/assets/templates/pages/login-split/template.doc.mjs +10 -1
  108. package/assets/templates/pages/login-sso/template.doc.mjs +10 -1
  109. package/assets/templates/pages/messaging-shell/template.doc.mjs +11 -1
  110. package/assets/templates/pages/mixed-gallery/template.doc.mjs +10 -1
  111. package/assets/templates/pages/payment-form/template.doc.mjs +3 -1
  112. package/assets/templates/pages/product-detail/template.doc.mjs +9 -1
  113. package/assets/templates/pages/product-gallery/template.doc.mjs +10 -1
  114. package/assets/templates/pages/settings/template.doc.mjs +3 -1
  115. package/assets/templates/pages/settings-dialog/template.doc.mjs +9 -1
  116. package/assets/templates/pages/settings-sidebar/template.doc.mjs +9 -1
  117. package/assets/templates/pages/shell-nav/template.doc.mjs +10 -1
  118. package/assets/templates/pages/shell-side-nav/template.doc.mjs +14 -1
  119. package/assets/templates/pages/shell-top-nav/template.doc.mjs +11 -1
  120. package/assets/templates/pages/side-gallery/template.doc.mjs +3 -1
  121. package/assets/templates/pages/table/template.doc.mjs +11 -1
  122. package/assets/templates/pages/table-filter/template.doc.mjs +21 -1
  123. package/assets/templates/pages/table-grouped/template.doc.mjs +15 -1
  124. package/assets/templates/pages/table-inbox/template.doc.mjs +18 -6
  125. package/assets/templates/pages/table-page/template.doc.mjs +20 -1
  126. package/assets/templates/pages/table-tree/template.doc.mjs +14 -1
  127. package/assets/templates/pages/theme-showcase/template.doc.mjs +10 -1
  128. package/assets/templates/pages/work-item-detail/template.doc.mjs +10 -0
  129. package/assets/templates/themes/butter/icons.tsx +2 -0
  130. package/assets/templates/themes/chocolate/icons.tsx +2 -0
  131. package/assets/templates/themes/gothic/icons.tsx +2 -0
  132. package/assets/templates/themes/matcha/icons.tsx +2 -0
  133. package/assets/templates/themes/neutral/icons.tsx +2 -0
  134. package/assets/templates/themes/stone/icons.tsx +2 -0
  135. package/assets/templates/themes/y2k/icons.tsx +2 -0
  136. package/authoring/doctypes/template/parse.d.mts +2 -0
  137. package/authoring/doctypes/template/parse.mjs +1 -0
  138. package/authoring/doctypes/template/parse.test.mjs +21 -0
  139. package/authoring/doctypes/template/template.doc.mjs +6 -0
  140. package/authoring/doctypes/template/type.ts +10 -0
  141. package/clients/cli/commands/docs.test.mjs +383 -0
  142. package/clients/cli/commands/doctor.mjs +4 -4
  143. package/clients/cli/commands/integration-add.doc.mjs +10 -0
  144. package/clients/cli/commands/integration-authoring.test.mjs +12 -2
  145. package/clients/cli/commands/integration.mjs +3 -1
  146. package/clients/cli/commands/layout-expand.doc.mjs +3 -1
  147. package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
  148. package/clients/cli/commands/layout.mjs +16 -0
  149. package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
  150. package/clients/cli/commands/template.mjs +19 -5
  151. package/clients/cli/commands/template.show-media.test.mjs +62 -0
  152. package/clients/cli/commands/upgrade.ascii-output.test.mjs +14 -0
  153. package/clients/cli/commands/write-failure.test.mjs +175 -0
  154. package/clients/cli/lib/manifest.mjs +44 -165
  155. package/clients/cli/lib/manifest.test.mjs +98 -7
  156. package/foundation/agent-docs/agent-docs.test.mjs +1160 -0
  157. package/foundation/discovery/template-adapter.d.mts +14 -0
  158. package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
  159. package/foundation/discovery/template-adapter.mjs +21 -1
  160. package/foundation/doc-compiler/doc-loads.test.mjs +2 -2
  161. package/foundation/doc-compiler/tree.test.mjs +649 -0
  162. package/foundation/integrations/cli-requirement.d.mts +57 -13
  163. package/foundation/integrations/cli-requirement.mjs +84 -22
  164. package/foundation/integrations/cli-requirement.test.mjs +135 -8
  165. package/foundation/response/response-types.doc.d.mts +5 -5
  166. package/foundation/response/response-types.doc.mjs +13 -13
  167. package/package.json +9 -9
@@ -4,6 +4,9 @@
4
4
  * @file `astryx integration add theme` — scaffold one strongly typed,
5
5
  * same-stem source/descriptor pair into an integration package and declare the
6
6
  * themes root on first use.
7
+ *
8
+ * `--from <base>` forks an existing theme's source files as the starting point
9
+ * instead of writing a blank `defineTheme` skeleton.
7
10
  */
8
11
 
9
12
  import * as fs from 'node:fs';
@@ -15,7 +18,10 @@ import {
15
18
  PathSafetyError,
16
19
  sanitizeName,
17
20
  } from '../../foundation/fs/path-safety.mjs';
18
- import {discoverThemeDirectory} from '../../foundation/discovery/theme-discovery.mjs';
21
+ import {
22
+ discoverBundledThemes,
23
+ discoverThemeDirectory,
24
+ } from '../../foundation/discovery/theme-discovery.mjs';
19
25
  import {
20
26
  findLocalIntegrationManifestOrNull,
21
27
  IntegrationRootConflictError,
@@ -25,9 +31,11 @@ import {loadManifestObject} from '../../foundation/integrations/integrations.mjs
25
31
  import {themeDescriptorSource} from '../../foundation/integrations/theme-descriptor.mjs';
26
32
  import {assertContributionVisible} from '../../foundation/integrations/contribution-inventory.mjs';
27
33
  import {
34
+ THEMES_CLI,
28
35
  themesCliProblem,
29
- withDocsTreeCli,
36
+ withCliPeer,
30
37
  } from '../../foundation/integrations/cli-requirement.mjs';
38
+ import {stripCopyrightHeader} from '../../foundation/text/copyright-header.mjs';
31
39
  import {
32
40
  applyWrites,
33
41
  findPackageDir,
@@ -69,6 +77,7 @@ function themeIdentity(slug) {
69
77
  .join(' ');
70
78
  return {
71
79
  slug,
80
+ identifier,
72
81
  displayName,
73
82
  exportName: `${identifier}Theme`,
74
83
  entry: `${identifier}Theme.ts`,
@@ -92,6 +101,182 @@ function themeDescriptor(identity) {
92
101
  });
93
102
  }
94
103
 
104
+ // ── --from: resolve and fork a base theme ───────────────────────────
105
+
106
+ /**
107
+ * Resolve a theme slug to its discovered record, searching the bundled themes
108
+ * and the package's own themes root (when it has one).
109
+ * @param {string} slug
110
+ * @param {string} packageDir
111
+ * @param {string} owner
112
+ * @param {string | undefined} themesRoot resolved absolute themes root, if any
113
+ * @returns {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme}
114
+ */
115
+ function resolveBaseTheme(slug, packageDir, owner, themesRoot) {
116
+ const normalized = slug.toLowerCase();
117
+
118
+ /** @type {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme[]} */
119
+ let candidates = [];
120
+ try {
121
+ candidates = discoverBundledThemes();
122
+ } catch {
123
+ // Bundled themes unavailable — not fatal, package themes may suffice.
124
+ }
125
+
126
+ // Also check the package's own themes root.
127
+ if (themesRoot && fs.existsSync(themesRoot)) {
128
+ try {
129
+ candidates = [...candidates, ...discoverThemeDirectory(themesRoot, owner)];
130
+ } catch {
131
+ // A broken local root is not the caller's problem here.
132
+ }
133
+ }
134
+
135
+ const match = candidates.find(t => t.slug.toLowerCase() === normalized);
136
+ if (!match) {
137
+ throw new AstryxError(
138
+ `Unknown base theme "${slug}". Available themes: ${candidates.map(t => t.slug).join(', ') || '(none)'}.`,
139
+ candidates.map(t => ({
140
+ name: t.slug,
141
+ reason: t.bundled ? 'bundled theme' : `provided by ${t.package}`,
142
+ })),
143
+ ERROR_CODES.ERR_UNKNOWN_THEME,
144
+ );
145
+ }
146
+ return match;
147
+ }
148
+
149
+ /**
150
+ * Rename a file from the base theme's namespace to the new theme's namespace.
151
+ * Files whose name starts with the base identifier get the new identifier;
152
+ * others keep their name as-is.
153
+ * @param {string} file POSIX relative path inside the theme directory
154
+ * @param {string} baseIdentifier
155
+ * @param {string} newIdentifier
156
+ * @returns {string}
157
+ */
158
+ function renameThemeFile(file, baseIdentifier, newIdentifier) {
159
+ const basename = path.posix.basename(file);
160
+ const dir = path.posix.dirname(file);
161
+ if (!basename.startsWith(baseIdentifier)) return file;
162
+ const renamed = newIdentifier + basename.slice(baseIdentifier.length);
163
+ return dir === '.' ? renamed : `${dir}/${renamed}`;
164
+ }
165
+
166
+ /**
167
+ * Rewrite a source file's contents from the base theme's names to the new
168
+ * theme's names. This replaces:
169
+ * 1. Identifier prefixes (camelCase variables, import paths): baseIdentifier
170
+ * followed by an uppercase letter.
171
+ * 2. The theme slug in string literals: 'baseSlug' → 'newSlug' and
172
+ * 'astryx-baseSlug' → 'astryx-newSlug'.
173
+ * 3. CSS custom properties scoped to the theme: --astryx-theme-baseSlug-.
174
+ * @param {string} source
175
+ * @param {string} baseSlug
176
+ * @param {string} baseIdentifier
177
+ * @param {string} newSlug
178
+ * @param {string} newIdentifier
179
+ * @returns {string}
180
+ */
181
+ function rewriteThemeSource(
182
+ source,
183
+ baseSlug,
184
+ baseIdentifier,
185
+ newSlug,
186
+ newIdentifier,
187
+ ) {
188
+ let result = source;
189
+ // 1. Identifier prefixes: neutralPalettes → oceanPalettes, neutralTheme → oceanTheme
190
+ const identRe = new RegExp(`${escapeRegExp(baseIdentifier)}(?=[A-Z])`, 'gu');
191
+ result = result.replace(identRe, newIdentifier);
192
+ // 2. String-literal theme names
193
+ result = result.replace(
194
+ new RegExp(`'astryx-${escapeRegExp(baseSlug)}'`, 'gu'),
195
+ `'astryx-${newSlug}'`,
196
+ );
197
+ result = result.replace(
198
+ new RegExp(`'${escapeRegExp(baseSlug)}'`, 'gu'),
199
+ `'${newSlug}'`,
200
+ );
201
+ // 3. CSS custom properties scoped to the base theme
202
+ result = result.replace(
203
+ new RegExp(
204
+ `--astryx-theme-${escapeRegExp(baseSlug)}-`,
205
+ 'gu',
206
+ ),
207
+ `--astryx-theme-${newSlug}-`,
208
+ );
209
+ return result;
210
+ }
211
+
212
+ /** @param {string} s */
213
+ function escapeRegExp(s) {
214
+ return s.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
215
+ }
216
+
217
+ /**
218
+ * Build the write plans for a forked theme.
219
+ * @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} base
220
+ * @param {ReturnType<typeof themeIdentity>} identity new theme identity
221
+ * @param {string} themeDir absolute target directory
222
+ * @returns {import('./add-helpers.mjs').WritePlan[]}
223
+ */
224
+ function forkThemePlans(base, identity, themeDir) {
225
+ const baseIdentity = themeIdentity(base.slug);
226
+ /** @type {import('./add-helpers.mjs').WritePlan[]} */
227
+ const plans = [];
228
+
229
+ // Copy every file the base theme ships (entry first, then the rest), except
230
+ // the descriptor — we write a fresh one.
231
+ const filesToCopy = base.files.filter(
232
+ file => path.posix.basename(file) !== `${baseIdentity.exportName}.doc.mjs`,
233
+ );
234
+
235
+ for (const file of filesToCopy) {
236
+ const srcPath = path.join(base.sourceDir, file);
237
+ const newFileName = renameThemeFile(
238
+ file,
239
+ baseIdentity.identifier,
240
+ identity.identifier,
241
+ );
242
+ const destPath = assertWithin(newFileName, themeDir, {
243
+ label: `forked theme file "${newFileName}"`,
244
+ });
245
+
246
+ // Read source bytes; for text, strip copyright and rewrite identifiers.
247
+ const bytes = fs.readFileSync(srcPath);
248
+ const text = bytes.toString('utf-8');
249
+ const isText = Buffer.from(text, 'utf-8').equals(bytes);
250
+
251
+ /** @type {string | Buffer} */
252
+ let contents;
253
+ if (isText) {
254
+ contents = rewriteThemeSource(
255
+ stripCopyrightHeader(text),
256
+ base.slug,
257
+ baseIdentity.identifier,
258
+ identity.slug,
259
+ identity.identifier,
260
+ );
261
+ } else {
262
+ contents = bytes;
263
+ }
264
+ plans.push({path: destPath, contents, createOnly: true});
265
+ }
266
+
267
+ // Write a fresh descriptor — the fork is a new theme, not a derivative.
268
+ const descriptorPath = assertWithin(identity.descriptor, themeDir, {
269
+ label: 'theme descriptor file',
270
+ });
271
+ plans.push({
272
+ path: descriptorPath,
273
+ contents: themeDescriptor(identity),
274
+ createOnly: true,
275
+ });
276
+
277
+ return plans;
278
+ }
279
+
95
280
  /**
96
281
  * Read bytes back through the same discovery seam Project uses. A write is not
97
282
  * successful until the requested slug resolves.
@@ -129,7 +314,7 @@ async function verifyThemeContribution(packageDir, manifestFile, owner, slug) {
129
314
  * @returns {Promise<import('./integration-authoring.type.mjs').IntegrationAddResponse>}
130
315
  */
131
316
  export async function integrationAddTheme(name, options = {}) {
132
- const {cwd = process.cwd(), dryRun = false} = options;
317
+ const {cwd = process.cwd(), dryRun = false, from} = options;
133
318
  const packageDir = findPackageDir(cwd);
134
319
  const packageFile = path.join(packageDir, 'package.json');
135
320
  let pkg;
@@ -211,32 +396,64 @@ export async function integrationAddTheme(name, options = {}) {
211
396
  const themeDir = assertWithin(identity.slug, root, {
212
397
  label: 'theme directory',
213
398
  });
214
- const sourceFile = assertWithin(identity.entry, themeDir, {
215
- label: 'theme source file',
216
- });
217
- const descriptorFile = assertWithin(identity.descriptor, themeDir, {
218
- label: 'theme descriptor file',
219
- });
220
- // An existing folder is filled; only a file this would write is refused.
221
- for (const file of [sourceFile, descriptorFile]) {
222
- if (fs.existsSync(file)) {
399
+
400
+ // Resolve the base theme when --from is given, before writing anything.
401
+ /** @type {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme | undefined} */
402
+ let baseTheme;
403
+ if (from != null) {
404
+ if (from === name) {
223
405
  throw new AstryxError(
224
- `Refusing to overwrite existing file ${projectPath(path.relative(packageDir, file))}.`,
406
+ `Cannot fork theme "${from}" into itself.`,
225
407
  undefined,
226
- ERROR_CODES.ERR_FILE_EXISTS,
408
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
227
409
  );
228
410
  }
411
+ baseTheme = resolveBaseTheme(from, packageDir, owner, root);
229
412
  }
230
413
 
231
414
  /** @type {import('./add-helpers.mjs').WritePlan[]} */
232
- const plans = [
233
- {path: sourceFile, contents: themeSource(identity), createOnly: true},
234
- {
235
- path: descriptorFile,
236
- contents: themeDescriptor(identity),
237
- createOnly: true,
238
- },
239
- ];
415
+ let plans;
416
+
417
+ if (baseTheme) {
418
+ // Fork: copy the base theme's files, renamed and rewritten.
419
+ plans = forkThemePlans(baseTheme, identity, themeDir);
420
+ // Check that no target file already exists.
421
+ for (const plan of plans) {
422
+ if (fs.existsSync(plan.path)) {
423
+ throw new AstryxError(
424
+ `Refusing to overwrite existing file ${projectPath(path.relative(packageDir, plan.path))}.`,
425
+ undefined,
426
+ ERROR_CODES.ERR_FILE_EXISTS,
427
+ );
428
+ }
429
+ }
430
+ } else {
431
+ // Blank scaffold.
432
+ const sourceFile = assertWithin(identity.entry, themeDir, {
433
+ label: 'theme source file',
434
+ });
435
+ const descriptorFile = assertWithin(identity.descriptor, themeDir, {
436
+ label: 'theme descriptor file',
437
+ });
438
+ for (const file of [sourceFile, descriptorFile]) {
439
+ if (fs.existsSync(file)) {
440
+ throw new AstryxError(
441
+ `Refusing to overwrite existing file ${projectPath(path.relative(packageDir, file))}.`,
442
+ undefined,
443
+ ERROR_CODES.ERR_FILE_EXISTS,
444
+ );
445
+ }
446
+ }
447
+ plans = [
448
+ {path: sourceFile, contents: themeSource(identity), createOnly: true},
449
+ {
450
+ path: descriptorFile,
451
+ contents: themeDescriptor(identity),
452
+ createOnly: true,
453
+ },
454
+ ];
455
+ }
456
+
240
457
  let packageUpdate = packageJsonUpdate(
241
458
  packageFile,
242
459
  rootPath,
@@ -253,7 +470,7 @@ export async function integrationAddTheme(name, options = {}) {
253
470
  if (themesCliProblem(current) != null) {
254
471
  packageUpdate = {
255
472
  contents:
256
- JSON.stringify(withDocsTreeCli(current), null, 2) +
473
+ JSON.stringify(withCliPeer(current, THEMES_CLI), null, 2) +
257
474
  (text.endsWith('\n') ? '\n' : ''),
258
475
  expectedOriginal,
259
476
  };
@@ -308,7 +525,8 @@ export async function integrationAddTheme(name, options = {}) {
308
525
  writtenFiles.push(manifestPath);
309
526
  }
310
527
 
311
- return {
528
+ /** @type {import('./integration-authoring.type.mjs').IntegrationAddResponse} */
529
+ const response = {
312
530
  type: 'integration.add',
313
531
  data: {
314
532
  kind: 'theme',
@@ -320,4 +538,8 @@ export async function integrationAddTheme(name, options = {}) {
320
538
  dryRun,
321
539
  },
322
540
  };
541
+ if (from != null) {
542
+ response.data.from = from;
543
+ }
544
+ return response;
323
545
  }
@@ -84,7 +84,7 @@ describe('integrationAddTheme', () => {
84
84
  const pkg = JSON.parse(
85
85
  fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
86
86
  );
87
- expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': '>=0.7.0'});
87
+ expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': '>=0.6.4'});
88
88
  expect(pkg.peerDependenciesMeta).toEqual({
89
89
  '@astryxdesign/cli': {optional: true},
90
90
  });
@@ -310,3 +310,216 @@ describe('integrationAddTheme', () => {
310
310
  );
311
311
  });
312
312
  });
313
+
314
+ describe('integrationAddTheme --from', () => {
315
+ it('forks a bundled theme into the integration package', async () => {
316
+ setup();
317
+ const result = await integrationAddTheme('ocean', {
318
+ cwd: tmpDir,
319
+ from: 'neutral',
320
+ });
321
+
322
+ expect(result.type).toBe('integration.add');
323
+ expect(result.data.kind).toBe('theme');
324
+ expect(result.data.name).toBe('ocean');
325
+ expect(result.data.from).toBe('neutral');
326
+ expect(result.data.written).toBe(true);
327
+ expect(result.data.dryRun).toBe(false);
328
+ expect(result.data.root).toEqual({path: './themes', created: true});
329
+
330
+ // The entry file must exist with the new export name.
331
+ const entry = fs.readFileSync(
332
+ path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
333
+ 'utf-8',
334
+ );
335
+ expect(entry).toContain('oceanTheme');
336
+ expect(entry).toContain("name: 'ocean'");
337
+ // It must NOT contain the original theme identifier as a prefix.
338
+ expect(entry).not.toMatch(/\bneutralTheme\b/);
339
+ expect(entry).not.toMatch(/\bneutralPalettes\b/);
340
+ expect(entry).not.toMatch(/\bneutralSyntax\b/);
341
+ expect(entry).toContain('defineTheme');
342
+
343
+ // A fresh descriptor, not copied from the base.
344
+ const descriptor = fs.readFileSync(
345
+ path.join(tmpDir, 'themes/ocean/oceanTheme.doc.mjs'),
346
+ 'utf-8',
347
+ );
348
+ expect(descriptor).toContain("name: 'ocean'");
349
+ expect(descriptor).toContain("@astryxdesign/cli/authoring').ThemeDoc");
350
+ expect(descriptor).toContain('maintained: true');
351
+
352
+ // The theme must validate.
353
+ expect((await validateLocalIntegration(tmpDir)).issues).toEqual([]);
354
+ });
355
+
356
+ it('renames palette and support files from the base theme', async () => {
357
+ setup();
358
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
359
+
360
+ const themeDir = path.join(tmpDir, 'themes/ocean');
361
+ const files = fs.readdirSync(themeDir).sort();
362
+ // neutralPalettes.ts → oceanPalettes.ts, etc.
363
+ expect(files).toContain('oceanTheme.ts');
364
+ expect(files).toContain('oceanTheme.doc.mjs');
365
+ expect(files).toContain('oceanPalettes.ts');
366
+ expect(files).toContain('oceanPaletteRefs.generated.ts');
367
+ expect(files).toContain('icons.tsx');
368
+ // Must not contain any file starting with 'neutral'.
369
+ expect(files.filter(f => f.startsWith('neutral'))).toEqual([]);
370
+ });
371
+
372
+ it('rewrites import paths inside forked files', async () => {
373
+ setup();
374
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
375
+
376
+ const entry = fs.readFileSync(
377
+ path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
378
+ 'utf-8',
379
+ );
380
+ // Import references must use the new identifier.
381
+ expect(entry).toContain('./oceanPaletteRefs.generated');
382
+ expect(entry).not.toContain('./neutralPaletteRefs.generated');
383
+ // The icon registry import must also be renamed.
384
+ expect(entry).toContain('oceanIconRegistry');
385
+ expect(entry).not.toContain('neutralIconRegistry');
386
+ });
387
+
388
+ it('rewrites CSS custom properties scoped to the base theme', async () => {
389
+ setup();
390
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
391
+
392
+ const entry = fs.readFileSync(
393
+ path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
394
+ 'utf-8',
395
+ );
396
+ expect(entry).toContain('--astryx-theme-ocean-');
397
+ expect(entry).not.toContain('--astryx-theme-neutral-');
398
+ });
399
+
400
+ it('rewrites the syntax theme name', async () => {
401
+ setup();
402
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
403
+
404
+ const entry = fs.readFileSync(
405
+ path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
406
+ 'utf-8',
407
+ );
408
+ expect(entry).toContain("'astryx-ocean'");
409
+ expect(entry).not.toContain("'astryx-neutral'");
410
+ });
411
+
412
+ it('strips the copyright header from forked files', async () => {
413
+ setup();
414
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
415
+
416
+ const entry = fs.readFileSync(
417
+ path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
418
+ 'utf-8',
419
+ );
420
+ expect(entry).not.toContain('Copyright (c) Meta Platforms');
421
+ });
422
+
423
+ it('includes data.from in the receipt only when --from is used', async () => {
424
+ setup();
425
+ const blank = await integrationAddTheme('plain', {cwd: tmpDir});
426
+ expect(blank.data).not.toHaveProperty('from');
427
+
428
+ const forked = await integrationAddTheme('ocean', {
429
+ cwd: tmpDir,
430
+ from: 'neutral',
431
+ });
432
+ expect(forked.data.from).toBe('neutral');
433
+ });
434
+
435
+ it('refuses to fork a theme into itself', async () => {
436
+ setup();
437
+ await expect(
438
+ integrationAddTheme('neutral', {cwd: tmpDir, from: 'neutral'}),
439
+ ).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
440
+ });
441
+
442
+ it('refuses an unknown base theme with a helpful suggestion list', async () => {
443
+ setup();
444
+ await expect(
445
+ integrationAddTheme('ocean', {cwd: tmpDir, from: 'nonexistent'}),
446
+ ).rejects.toMatchObject({
447
+ code: 'ERR_UNKNOWN_THEME',
448
+ message: expect.stringContaining('nonexistent'),
449
+ });
450
+ });
451
+
452
+ it('dry-runs with --from without writing anything', async () => {
453
+ setup();
454
+ const result = await integrationAddTheme('ocean', {
455
+ cwd: tmpDir,
456
+ from: 'neutral',
457
+ dryRun: true,
458
+ });
459
+
460
+ expect(result.data.written).toBe(false);
461
+ expect(result.data.dryRun).toBe(true);
462
+ expect(result.data.from).toBe('neutral');
463
+ expect(result.data.files).toContain('themes/ocean/oceanTheme.ts');
464
+ expect(result.data.files).toContain('themes/ocean/oceanTheme.doc.mjs');
465
+ expect(fs.existsSync(path.join(tmpDir, 'themes'))).toBe(false);
466
+ });
467
+
468
+ it('refuses to overwrite when the target already exists', async () => {
469
+ setup();
470
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
471
+ await expect(
472
+ integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'}),
473
+ ).rejects.toMatchObject({code: 'ERR_FILE_EXISTS'});
474
+ });
475
+
476
+ it('works with different bundled themes', async () => {
477
+ setup();
478
+ const result = await integrationAddTheme('dusk', {
479
+ cwd: tmpDir,
480
+ from: 'gothic',
481
+ });
482
+
483
+ expect(result.data.from).toBe('gothic');
484
+ const entry = fs.readFileSync(
485
+ path.join(tmpDir, 'themes/dusk/duskTheme.ts'),
486
+ 'utf-8',
487
+ );
488
+ expect(entry).toContain('duskTheme');
489
+ expect(entry).toContain("name: 'dusk'");
490
+ expect(entry).not.toMatch(/\bgothicTheme\b/);
491
+ expect((await validateLocalIntegration(tmpDir)).issues).toEqual([]);
492
+ });
493
+
494
+ it('forks from a theme the package already owns', async () => {
495
+ setup();
496
+ // First, add a blank theme.
497
+ await integrationAddTheme('base', {cwd: tmpDir});
498
+ // Then fork it.
499
+ const result = await integrationAddTheme('variant', {
500
+ cwd: tmpDir,
501
+ from: 'base',
502
+ });
503
+
504
+ expect(result.data.from).toBe('base');
505
+ const entry = fs.readFileSync(
506
+ path.join(tmpDir, 'themes/variant/variantTheme.ts'),
507
+ 'utf-8',
508
+ );
509
+ expect(entry).toContain('variantTheme');
510
+ expect(entry).toContain("name: 'variant'");
511
+ expect((await validateLocalIntegration(tmpDir)).issues).toEqual([]);
512
+ });
513
+
514
+ it('declares the optional CLI peer that reads typed theme descriptors', async () => {
515
+ setup({includeFiles: false});
516
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
517
+ const pkg = JSON.parse(
518
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
519
+ );
520
+ expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': '>=0.6.4'});
521
+ expect(pkg.peerDependenciesMeta).toEqual({
522
+ '@astryxdesign/cli': {optional: true},
523
+ });
524
+ });
525
+ });
@@ -92,6 +92,7 @@ function addErrors(issues, errors, code) {
92
92
  export async function integrationTemplateConflicts(pkg, options = {}) {
93
93
  const {cwd = process.cwd()} = options;
94
94
  const resolved = await resolveIntegration(pkg, cwd);
95
+ const validated = resolved.found;
95
96
  const name = resolved.found ? (resolved.name ?? null) : null;
96
97
  const version = resolved.found ? (resolved.version ?? null) : null;
97
98
  const issues = [...resolved.issues];
@@ -99,7 +100,7 @@ export async function integrationTemplateConflicts(pkg, options = {}) {
99
100
  if (!resolved.integration || name == null) {
100
101
  return {
101
102
  type: 'integration.template-conflicts',
102
- data: {name, version, conflicts: [], issues},
103
+ data: {validated, name, version, conflicts: [], issues},
103
104
  };
104
105
  }
105
106
 
@@ -215,7 +216,7 @@ export async function integrationTemplateConflicts(pkg, options = {}) {
215
216
 
216
217
  return {
217
218
  type: 'integration.template-conflicts',
218
- data: {name, version, conflicts, issues},
219
+ data: {validated, name, version, conflicts, issues},
219
220
  };
220
221
  }
221
222
 
@@ -228,6 +229,7 @@ export async function integrationTemplateConflicts(pkg, options = {}) {
228
229
  export async function integrationComponentConflicts(pkg, options = {}) {
229
230
  const {cwd = process.cwd()} = options;
230
231
  const resolved = await resolveIntegration(pkg, cwd);
232
+ const validated = resolved.found;
231
233
  const name = resolved.found ? (resolved.name ?? null) : null;
232
234
  const version = resolved.found ? (resolved.version ?? null) : null;
233
235
  const issues = [...resolved.issues];
@@ -235,7 +237,7 @@ export async function integrationComponentConflicts(pkg, options = {}) {
235
237
  if (!resolved.integration?.components || name == null) {
236
238
  return {
237
239
  type: 'integration.component-conflicts',
238
- data: {name, version, conflicts: [], issues},
240
+ data: {validated, name, version, conflicts: [], issues},
239
241
  };
240
242
  }
241
243
 
@@ -249,7 +251,7 @@ export async function integrationComponentConflicts(pkg, options = {}) {
249
251
  });
250
252
  return {
251
253
  type: 'integration.component-conflicts',
252
- data: {name, version, conflicts: [], issues},
254
+ data: {validated, name, version, conflicts: [], issues},
253
255
  };
254
256
  }
255
257
 
@@ -274,7 +276,7 @@ export async function integrationComponentConflicts(pkg, options = {}) {
274
276
 
275
277
  return {
276
278
  type: 'integration.component-conflicts',
277
- data: {name, version, conflicts, issues},
279
+ data: {validated, name, version, conflicts, issues},
278
280
  };
279
281
  }
280
282
 
@@ -287,6 +289,7 @@ export async function integrationComponentConflicts(pkg, options = {}) {
287
289
  export async function integrationDocConflicts(pkg, options = {}) {
288
290
  const {cwd = process.cwd()} = options;
289
291
  const resolved = await resolveIntegration(pkg, cwd);
292
+ const validated = resolved.found;
290
293
  const name = resolved.found ? (resolved.name ?? null) : null;
291
294
  const version = resolved.found ? (resolved.version ?? null) : null;
292
295
  const issues = [...resolved.issues];
@@ -294,7 +297,7 @@ export async function integrationDocConflicts(pkg, options = {}) {
294
297
  if (!resolved.integration?.docs || name == null) {
295
298
  return {
296
299
  type: 'integration.doc-conflicts',
297
- data: {name, version, findings: [], issues},
300
+ data: {validated, name, version, findings: [], issues},
298
301
  };
299
302
  }
300
303
 
@@ -388,6 +391,6 @@ export async function integrationDocConflicts(pkg, options = {}) {
388
391
 
389
392
  return {
390
393
  type: 'integration.doc-conflicts',
391
- data: {name, version, findings, issues},
394
+ data: {validated, name, version, findings, issues},
392
395
  };
393
396
  }
@@ -32,9 +32,15 @@ export type IntegrationDocFinding = {
32
32
  coreTopic: string;
33
33
  message: string;
34
34
  };
35
+ /**
36
+ * Each of the three authoring checks reports `validated`: false means no
37
+ * integration manifest was found, so nothing was inspected and the empty
38
+ * conflicts/findings list carries no information about the package.
39
+ */
35
40
  export type IntegrationTemplateConflictResponse = {
36
41
  type: "integration.template-conflicts";
37
42
  data: {
43
+ validated: boolean;
38
44
  name: string | null;
39
45
  version: string | null;
40
46
  conflicts: IntegrationTemplateConflict[];
@@ -44,6 +50,7 @@ export type IntegrationTemplateConflictResponse = {
44
50
  export type IntegrationComponentConflictResponse = {
45
51
  type: "integration.component-conflicts";
46
52
  data: {
53
+ validated: boolean;
47
54
  name: string | null;
48
55
  version: string | null;
49
56
  conflicts: IntegrationComponentConflict[];
@@ -53,6 +60,7 @@ export type IntegrationComponentConflictResponse = {
53
60
  export type IntegrationDocConflictResponse = {
54
61
  type: "integration.doc-conflicts";
55
62
  data: {
63
+ validated: boolean;
56
64
  name: string | null;
57
65
  version: string | null;
58
66
  findings: IntegrationDocFinding[];