@astryxdesign/cli 0.6.4-canary.10dd683 → 0.6.4-canary.18d2bcb

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 (233) hide show
  1. package/README.md +97 -91
  2. package/api/build/build.doc.mjs +6 -1
  3. package/api/build/build.test.mjs +22 -0
  4. package/api/build/kit/kit.mjs +44 -5
  5. package/api/component/_adapter.d.mts +25 -0
  6. package/api/component/_adapter.mjs +59 -5
  7. package/api/component/component.d.mts +6 -3
  8. package/api/component/component.doc.mjs +37 -17
  9. package/api/component/component.mjs +249 -9
  10. package/api/component/component.type.d.mts +25 -0
  11. package/api/component/component.type.mjs +44 -0
  12. package/api/docs/_adapter.d.mts +8 -3
  13. package/api/docs/_adapter.mjs +14 -6
  14. package/api/docs/docOverlays.test.mjs +27 -1
  15. package/api/docs/docs.doc.mjs +2 -2
  16. package/api/doctor/doctor.d.mts +8 -3
  17. package/api/doctor/doctor.doc.mjs +17 -8
  18. package/api/doctor/doctor.mjs +90 -9
  19. package/api/doctor/doctor.test.mjs +122 -10
  20. package/api/doctor/doctor.type.d.mts +1 -1
  21. package/api/doctor/doctor.type.mjs +1 -1
  22. package/api/gap-report/gap-report.doc.mjs +19 -10
  23. package/api/hook/hook.doc.mjs +6 -3
  24. package/api/index.d.mts +1 -0
  25. package/api/index.mjs +5 -3
  26. package/api/init/init.doc.mjs +17 -12
  27. package/api/integration/add-theme.mjs +22 -1
  28. package/api/integration/add-theme.test.mjs +34 -0
  29. package/api/integration/authoring-checks.mjs +2 -2
  30. package/api/integration/integrationPackCheck.doc.mjs +3 -3
  31. package/api/integration/pack-check.lifecycle-output.test.mjs +107 -0
  32. package/api/integration/pack-check.mjs +82 -9
  33. package/api/integration/pack-check.test.mjs +90 -0
  34. package/api/integration/pack-check.type.mjs +1 -1
  35. package/api/json/assertResponse.doc.mjs +1 -1
  36. package/api/json/isError.doc.mjs +1 -1
  37. package/api/search/search.d.mts +27 -1
  38. package/api/search/search.doc.mjs +2 -2
  39. package/api/search/search.mjs +228 -16
  40. package/api/swizzle/swizzle.doc.mjs +7 -5
  41. package/api/template/copy/copy.mjs +1 -1
  42. package/api/template/copy/copy.test.mjs +9 -0
  43. package/api/template/template.doc.mjs +2 -1
  44. package/api/theme/generateTonalPalette.doc.mjs +1 -2
  45. package/api/theme/listThemes.doc.mjs +1 -1
  46. package/api/theme/themeAdd.doc.mjs +9 -10
  47. package/api/theme/themeBuild.doc.mjs +13 -13
  48. package/api/theme/themeList.doc.mjs +1 -1
  49. package/api/theme/themeListAvailable.doc.mjs +2 -1
  50. package/api/theme/themePaletteGenerate.doc.mjs +15 -8
  51. package/api/theme/themeTargets.doc.mjs +3 -2
  52. package/api/theme/themeTemplate.doc.mjs +2 -1
  53. package/api/upgrade/run/files-changed.test.mjs +111 -0
  54. package/api/upgrade/run/run.mjs +5 -3
  55. package/api/upgrade/upgrade.doc.mjs +24 -22
  56. package/api/upgrade/upgrade.type.mjs +2 -2
  57. package/assets/codemods/__tests__/runner.test.mjs +3 -1
  58. package/assets/codemods/file-count.test.mjs +163 -0
  59. package/assets/codemods/integration-runner.mjs +3 -3
  60. package/assets/codemods/runner.mjs +5 -4
  61. package/assets/docs/README.md +4 -2
  62. package/assets/docs/browser-support.doc.mjs +11 -11
  63. package/assets/docs/color.doc.mjs +8 -2
  64. package/assets/docs/elevation.doc.mjs +6 -4
  65. package/assets/docs/getting-started.doc.mjs +5 -16
  66. package/assets/docs/icons.doc.mjs +2 -21
  67. package/assets/docs/illustrations.doc.mjs +7 -15
  68. package/assets/docs/layout.doc.dense.mjs +130 -82
  69. package/assets/docs/layout.doc.mjs +133 -77
  70. package/assets/docs/migration.doc.mjs +19 -21
  71. package/assets/docs/motion.doc.mjs +16 -3
  72. package/assets/docs/principles.doc.dense.mjs +5 -5
  73. package/assets/docs/principles.doc.mjs +8 -0
  74. package/assets/docs/principles.doc.zh.mjs +6 -6
  75. package/assets/docs/shape.doc.mjs +8 -3
  76. package/assets/docs/spacing.doc.mjs +7 -2
  77. package/assets/docs/styling-libraries.doc.mjs +6 -2
  78. package/assets/docs/styling.doc.mjs +19 -23
  79. package/assets/docs/theme.doc.dense.mjs +58 -18
  80. package/assets/docs/theme.doc.mjs +56 -46
  81. package/assets/docs/theme.doc.zh.mjs +9 -8
  82. package/assets/docs/tokens.doc.dense.mjs +2 -2
  83. package/assets/docs/tokens.doc.mjs +389 -8
  84. package/assets/docs/tokens.doc.zh.mjs +2 -2
  85. package/assets/docs/tree/add-a-component.doc.mjs +75 -0
  86. package/assets/docs/tree/add-a-theme.doc.mjs +85 -0
  87. package/assets/docs/tree/add-a-topic.doc.mjs +144 -0
  88. package/assets/docs/tree/agent-guidance.doc.mjs +138 -0
  89. package/assets/docs/tree/block-template.doc.mjs +130 -0
  90. package/assets/docs/tree/build-the-template.doc.mjs +28 -0
  91. package/assets/docs/tree/building-blocks.doc.mjs +46 -0
  92. package/assets/docs/tree/check-your-docs.doc.mjs +137 -0
  93. package/assets/docs/tree/checks.doc.mjs +119 -0
  94. package/assets/docs/tree/codemods.doc.mjs +147 -0
  95. package/assets/docs/tree/component-family.doc.mjs +113 -0
  96. package/assets/docs/tree/component-imports.doc.mjs +69 -0
  97. package/assets/docs/tree/component-lookups.doc.mjs +149 -0
  98. package/assets/docs/tree/components.doc.mjs +23 -0
  99. package/assets/docs/tree/configuration.doc.mjs +23 -0
  100. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +182 -0
  101. package/assets/docs/tree/define-the-theme.doc.mjs +118 -0
  102. package/assets/docs/tree/describe-the-component.doc.mjs +57 -0
  103. package/assets/docs/tree/docs.doc.mjs +21 -0
  104. package/assets/docs/tree/document-the-template.doc.mjs +28 -0
  105. package/assets/docs/tree/document-the-theme.doc.mjs +68 -0
  106. package/assets/docs/tree/export-template-assets.doc.mjs +147 -0
  107. package/assets/docs/tree/extend-or-replace.doc.mjs +103 -0
  108. package/assets/docs/tree/fonts-and-assets.doc.mjs +106 -0
  109. package/assets/docs/tree/generate-a-palette.doc.mjs +66 -0
  110. package/assets/docs/tree/grade-template-with-agent.doc.mjs +105 -0
  111. package/assets/docs/tree/help.doc.mjs +16 -0
  112. package/assets/docs/tree/integrations.doc.mjs +25 -470
  113. package/assets/docs/tree/links.doc.mjs +98 -0
  114. package/assets/docs/tree/package-and-test.doc.mjs +32 -0
  115. package/assets/docs/tree/page-template.doc.mjs +71 -0
  116. package/assets/docs/tree/publishing.doc.mjs +111 -0
  117. package/assets/docs/tree/quick-start.doc.mjs +272 -0
  118. package/assets/docs/tree/replace-a-core-component.doc.mjs +104 -0
  119. package/assets/docs/tree/replace-a-core-template.doc.mjs +172 -0
  120. package/assets/docs/tree/sections-and-placement.doc.mjs +108 -0
  121. package/assets/docs/tree/see-it-in-an-app.doc.mjs +59 -0
  122. package/assets/docs/tree/ship.doc.mjs +16 -0
  123. package/assets/docs/tree/short-and-findable.doc.mjs +108 -0
  124. package/assets/docs/tree/single-component.doc.mjs +165 -0
  125. package/assets/docs/tree/start-a-template.doc.mjs +143 -0
  126. package/assets/docs/tree/subcomponent.doc.mjs +115 -0
  127. package/assets/docs/tree/template-assets.doc.mjs +64 -0
  128. package/assets/docs/tree/template-doc-overview.doc.mjs +109 -0
  129. package/assets/docs/tree/template-fonts.doc.mjs +102 -0
  130. package/assets/docs/tree/template-grading-rubric.doc.mjs +452 -0
  131. package/assets/docs/tree/template-icons.doc.mjs +97 -0
  132. package/assets/docs/tree/template-images-media.doc.mjs +127 -0
  133. package/assets/docs/tree/template-styles.doc.mjs +93 -0
  134. package/assets/docs/tree/templates.doc.mjs +34 -0
  135. package/assets/docs/tree/test-in-an-app.doc.mjs +115 -0
  136. package/assets/docs/tree/test-template-in-app.doc.mjs +128 -0
  137. package/assets/docs/tree/themes.doc.mjs +39 -0
  138. package/assets/docs/tree/troubleshooting.doc.mjs +149 -0
  139. package/assets/docs/tree/upgrading.doc.mjs +103 -0
  140. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +51 -0
  141. package/assets/docs/tree/verify-packed-template.doc.mjs +77 -0
  142. package/assets/docs/tree/versioning.doc.mjs +161 -0
  143. package/assets/docs/tree/write-good-templates.doc.mjs +64 -0
  144. package/assets/docs/tree/write-the-template-file.doc.mjs +154 -0
  145. package/assets/docs/typography.doc.mjs +24 -4
  146. package/assets/docs/working-with-ai.doc.mjs +30 -22
  147. package/authoring/config/config.doc.mjs +1 -1
  148. package/authoring/doctypes/_schema.d.mts +3 -2
  149. package/authoring/doctypes/_schema.mjs +6 -0
  150. package/authoring/doctypes/base/graph-fields.doc.mjs +3 -3
  151. package/authoring/doctypes/base/type.ts +4 -2
  152. package/authoring/doctypes/component/component.doc.mjs +6 -0
  153. package/authoring/doctypes/component/type.ts +8 -0
  154. package/authoring/doctypes/reference/reference.doc.mjs +7 -0
  155. package/authoring/doctypes/reference/type.ts +5 -0
  156. package/authoring/doctypes/schema/schema.doc.mjs +2 -2
  157. package/authoring/doctypes/template/template.doc.mjs +1 -1
  158. package/authoring/doctypes/template/type.ts +2 -2
  159. package/authoring/integration/integration.doc.mjs +12 -10
  160. package/clients/cli/commands/component/index.mjs +152 -55
  161. package/clients/cli/commands/component-batch.test.mjs +341 -0
  162. package/clients/cli/commands/component-ownership.test.mjs +89 -0
  163. package/clients/cli/commands/component.doc.mjs +27 -9
  164. package/clients/cli/commands/docs.doc.mjs +1 -1
  165. package/clients/cli/commands/docs.mjs +60 -17
  166. package/clients/cli/commands/doctor-integration-docs.doc.mjs +3 -2
  167. package/clients/cli/commands/doctor-integration.test.mjs +53 -0
  168. package/clients/cli/commands/doctor.doc.mjs +3 -1
  169. package/clients/cli/commands/doctor.mjs +49 -5
  170. package/clients/cli/commands/gap-report.doc.mjs +10 -9
  171. package/clients/cli/commands/init.doc.mjs +9 -6
  172. package/clients/cli/commands/integration-add.doc.mjs +9 -9
  173. package/clients/cli/commands/integration-authoring.test.mjs +61 -10
  174. package/clients/cli/commands/integration-pack.doc.mjs +5 -9
  175. package/clients/cli/commands/integration-real-world.test.mjs +1 -1
  176. package/clients/cli/commands/integration-verify.doc.mjs +22 -0
  177. package/clients/cli/commands/integration.doc.mjs +4 -4
  178. package/clients/cli/commands/integration.mjs +74 -43
  179. package/clients/cli/commands/manifest.doc.mjs +1 -1
  180. package/clients/cli/commands/search.doc.mjs +10 -3
  181. package/clients/cli/commands/search.mjs +21 -2
  182. package/clients/cli/commands/search.test.mjs +21 -4
  183. package/clients/cli/commands/swizzle.doc.mjs +1 -1
  184. package/clients/cli/commands/template.doc.mjs +1 -1
  185. package/clients/cli/commands/text-json-parity.test.mjs +7 -1
  186. package/clients/cli/commands/theme-add.doc.mjs +1 -1
  187. package/clients/cli/commands/theme-palette-generate.doc.mjs +3 -2
  188. package/clients/cli/commands/theme-palette.doc.mjs +1 -2
  189. package/clients/cli/commands/theme-targets.doc.mjs +2 -2
  190. package/clients/cli/commands/theme.doc.mjs +2 -1
  191. package/clients/cli/commands/upgrade.doc.mjs +62 -3
  192. package/clients/cli/index.mjs +28 -6
  193. package/clients/cli/lib/define-command.mjs +28 -4
  194. package/clients/cli/lib/define-command.test.mjs +54 -0
  195. package/clients/cli/lib/exit-codes.test.mjs +17 -1
  196. package/clients/cli/lib/json-shim.mjs +24 -14
  197. package/clients/cli/lib/manifest.mjs +17 -5
  198. package/clients/cli/lib/manifest.test.mjs +5 -2
  199. package/clients/cli/lib/parse-error-format.test.mjs +81 -0
  200. package/foundation/agent-docs/agent-docs.mjs +1 -1
  201. package/foundation/discovery/authoring-self-docs.test.mjs +6 -2
  202. package/foundation/discovery/cli-self-docs.mjs +16 -2
  203. package/foundation/discovery/cli-self-docs.test.mjs +20 -0
  204. package/foundation/discovery/docs-discovery.mjs +5 -1
  205. package/foundation/discovery/docs-discovery.test.mjs +21 -0
  206. package/foundation/discovery/docs-section-key.d.mts +1 -1
  207. package/foundation/discovery/docs-section-key.mjs +1 -1
  208. package/foundation/doc-compiler/doc-loads.test.mjs +3 -2
  209. package/foundation/doc-compiler/inputs.test.mjs +0 -1
  210. package/foundation/doc-compiler/tree.d.mts +4 -0
  211. package/foundation/doc-compiler/tree.mjs +6 -1
  212. package/foundation/integrations/cli-requirement.d.mts +26 -6
  213. package/foundation/integrations/cli-requirement.mjs +46 -11
  214. package/foundation/integrations/cli-requirement.test.mjs +7 -2
  215. package/foundation/integrations/contribution-inventory.mjs +1 -1
  216. package/foundation/response/batch.type.d.mts +33 -0
  217. package/foundation/response/batch.type.mjs +34 -0
  218. package/foundation/response/error-codes.doc.mjs +6 -8
  219. package/foundation/response/error-codes.test.mjs +30 -5
  220. package/foundation/response/response-types.doc.d.mts +4 -3
  221. package/foundation/response/response-types.doc.mjs +30 -6
  222. package/foundation/response/response-types.doc.test.mjs +23 -0
  223. package/foundation/response/response.doc.mjs +11 -10
  224. package/package.json +9 -9
  225. package/api/docs/docs.test.mjs +0 -243
  226. package/api/docs/integration-tree.test.mjs +0 -555
  227. package/api/docs/integrationDocs.test.mjs +0 -314
  228. package/api/search/search.test.mjs +0 -512
  229. package/assets/docs/tree/integrations.test.mjs +0 -62
  230. package/assets/docs/tree/writing-docs.doc.mjs +0 -286
  231. package/clients/cli/commands/docs.test.mjs +0 -294
  232. package/foundation/agent-docs/agent-docs.test.mjs +0 -1159
  233. package/foundation/doc-compiler/tree.test.mjs +0 -598
@@ -68,6 +68,16 @@ export function requireCoreDir(cwd: string): string;
68
68
  * @returns {Promise<import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]>}
69
69
  */
70
70
  export function loadIntegrationsSafely(cwd: string): Promise<import("../../foundation/integrations/integrations.mjs").LoadedIntegration[]>;
71
+ /**
72
+ * Read the exact installed version available to a package-qualified component
73
+ * selector. Legacy docs packages do not expose a reliable version here, so a
74
+ * version-qualified lookup never falls through to them.
75
+ * @param {string} coreDir
76
+ * @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} loadedIntegrations
77
+ * @param {string} packageName
78
+ * @returns {string|null}
79
+ */
80
+ export function installedComponentPackageVersion(coreDir: string, loadedIntegrations: import("../../foundation/integrations/integrations.mjs").LoadedIntegration[], packageName: string): string | null;
71
81
  /**
72
82
  * Build the set of OWNER packages that provide a component with this name
73
83
  * across core + every loaded integration. This is what lets the CLI
@@ -180,6 +190,20 @@ export function scopeSubComponent(docs: LoadedComponentDoc, dirName: string, cor
180
190
  matchingComponent: any;
181
191
  } | null;
182
192
  export { CORE_PACKAGE };
193
+ /**
194
+ * Internal ambiguity marker. Single-component callers still receive the same
195
+ * AstryxError code, message, and suggestions; batch callers can additionally
196
+ * project every installed candidate without parsing prose.
197
+ */
198
+ export class ComponentAmbiguityError extends AstryxError {
199
+ /**
200
+ * @param {ComponentOwner[]} owners
201
+ * @param {string} dirName
202
+ */
203
+ constructor(owners: ComponentOwner[], dirName: string);
204
+ /** @type {import('./component.type.mjs').ComponentBatchCandidate[]} */
205
+ candidates: import("./component.type.mjs").ComponentBatchCandidate[];
206
+ }
183
207
  /**
184
208
  * A loaded component doc. The shared validated loader accepts stamped and legacy
185
209
  * component docs; this loose view captures the fields the API reads across both.
@@ -258,3 +282,4 @@ export type ResolvedUnscopedDoc = {
258
282
  resolvedSourcePath: string | null;
259
283
  };
260
284
  import { CORE_PACKAGE } from '../../foundation/discovery/component-discovery.mjs';
285
+ import { AstryxError } from '../error.mjs';
@@ -18,6 +18,8 @@
18
18
  * deduped, so each leaf stays a thin projection.
19
19
  */
20
20
 
21
+ import * as fs from 'node:fs';
22
+ import * as path from 'node:path';
21
23
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
22
24
  import {
23
25
  findCoreDir,
@@ -146,6 +148,34 @@ function findLoadedIntegration(loadedIntegrations, packageName) {
146
148
  return loadedIntegrations.find(i => i.name === packageName) ?? null;
147
149
  }
148
150
 
151
+ /**
152
+ * Read the exact installed version available to a package-qualified component
153
+ * selector. Legacy docs packages do not expose a reliable version here, so a
154
+ * version-qualified lookup never falls through to them.
155
+ * @param {string} coreDir
156
+ * @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} loadedIntegrations
157
+ * @param {string} packageName
158
+ * @returns {string|null}
159
+ */
160
+ export function installedComponentPackageVersion(
161
+ coreDir,
162
+ loadedIntegrations,
163
+ packageName,
164
+ ) {
165
+ if (packageName === CORE_PACKAGE) {
166
+ try {
167
+ const pkg = JSON.parse(
168
+ fs.readFileSync(path.join(coreDir, 'package.json'), 'utf8'),
169
+ );
170
+ return typeof pkg.version === 'string' ? pkg.version : null;
171
+ } catch {
172
+ return null;
173
+ }
174
+ }
175
+ const integration = findLoadedIntegration(loadedIntegrations, packageName);
176
+ return typeof integration?.version === 'string' ? integration.version : null;
177
+ }
178
+
149
179
  /**
150
180
  * Resolve an external package by name from the discovered externals list.
151
181
  * @param {string} packageName - e.g. '@acme/xds-widgets'
@@ -244,6 +274,34 @@ export function classifyScope(
244
274
  return {kind: 'legacy', ext};
245
275
  }
246
276
 
277
+ /**
278
+ * Internal ambiguity marker. Single-component callers still receive the same
279
+ * AstryxError code, message, and suggestions; batch callers can additionally
280
+ * project every installed candidate without parsing prose.
281
+ */
282
+ export class ComponentAmbiguityError extends AstryxError {
283
+ /** @type {import('./component.type.mjs').ComponentBatchCandidate[]} */
284
+ candidates;
285
+
286
+ /**
287
+ * @param {ComponentOwner[]} owners
288
+ * @param {string} dirName
289
+ */
290
+ constructor(owners, dirName) {
291
+ super(
292
+ `Component "${dirName}" is provided by multiple packages. Re-run with --package <pkg> to choose one.`,
293
+ owners.map(o => ({name: o.package, reason: 'provides this component'})),
294
+ ERROR_CODES.ERR_UNKNOWN_COMPONENT,
295
+ );
296
+ this.candidates = owners.map(owner => ({
297
+ package: owner.package,
298
+ component: dirName,
299
+ kind: 'component',
300
+ installed: true,
301
+ }));
302
+ }
303
+ }
304
+
247
305
  /**
248
306
  * Refuse to guess when the name is owned by MORE THAN ONE package (core and/or
249
307
  * integrations) and the caller did not scope with --package. Legacy
@@ -254,11 +312,7 @@ export function classifyScope(
254
312
  */
255
313
  export function assertUnambiguousOwners(owners, dirName) {
256
314
  if (owners.length > 1) {
257
- throw new AstryxError(
258
- `Component "${dirName}" is provided by multiple packages. Re-run with --package <pkg> to choose one.`,
259
- owners.map(o => ({name: o.package, reason: 'provides this component'})),
260
- ERROR_CODES.ERR_UNKNOWN_COMPONENT,
261
- );
315
+ throw new ComponentAmbiguityError(owners, dirName);
262
316
  }
263
317
  }
264
318
 
@@ -2,7 +2,7 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * @param {string} [name]
5
+ * @param {string|string[]} [name]
6
6
  * @param {object} [options]
7
7
  * @param {string} [options.cwd]
8
8
  * @param {boolean} [options.list]
@@ -18,6 +18,7 @@
18
18
  * @param {boolean} [options.dense]
19
19
  * @returns {Promise<(
20
20
  * import('./component.type.mjs').ComponentListResponse
21
+ * | import('./component.type.mjs').ComponentBatchResponse
21
22
  * | import('./component.type.mjs').ComponentDetailResponse
22
23
  * | import('./component.type.mjs').ComponentDetailPropsResponse
23
24
  * | import('./component.type.mjs').ComponentDetailSourceResponse
@@ -25,7 +26,7 @@
25
26
  * | import('./component.type.mjs').ComponentDetailBlocksResponse
26
27
  * )>}
27
28
  */
28
- export function component(name?: string, options?: {
29
+ export function component(name?: string | string[], options?: {
29
30
  cwd?: string | undefined;
30
31
  list?: boolean | undefined;
31
32
  category?: string | undefined;
@@ -38,4 +39,6 @@ export function component(name?: string, options?: {
38
39
  lang?: string | undefined;
39
40
  zh?: boolean | undefined;
40
41
  dense?: boolean | undefined;
41
- }): Promise<(import("./component.type.mjs").ComponentListResponse | import("./component.type.mjs").ComponentDetailResponse | import("./component.type.mjs").ComponentDetailPropsResponse | import("./component.type.mjs").ComponentDetailSourceResponse | import("./component.type.mjs").ComponentDetailShowcaseResponse | import("./component.type.mjs").ComponentDetailBlocksResponse)>;
42
+ }): Promise<(import("./component.type.mjs").ComponentListResponse | import("./component.type.mjs").ComponentBatchResponse | import("./component.type.mjs").ComponentDetailResponse | import("./component.type.mjs").ComponentDetailPropsResponse | import("./component.type.mjs").ComponentDetailSourceResponse | import("./component.type.mjs").ComponentDetailShowcaseResponse | import("./component.type.mjs").ComponentDetailBlocksResponse)>;
43
+ /** Maximum selectors accepted before any component resolution starts. */
44
+ export const COMPONENT_BATCH_SELECTOR_LIMIT: 100;
@@ -15,16 +15,16 @@ export const doc = {
15
15
  namespace: 'cli/api',
16
16
  displayName: 'component()',
17
17
  summary:
18
- 'Resolve a component by name, or list the catalog, with optional focused slices (props, source, showcase, blocks).',
18
+ 'Resolve one or several components by name, or list the catalog, with optional focused slices (props, source, showcase, blocks).',
19
19
  description:
20
- 'Routes on its arguments: a name resolves that component across core and ' +
21
- 'integration packages and returns its authored ComponentDoc plus ownership ' +
22
- 'metadata; no name (or `list`/`category`) returns the catalog grouped by ' +
23
- 'category. Boolean flags narrow a single component to just its props, ' +
24
- 'source, showcase, or example blocks.',
20
+ 'Routes on its arguments: one string resolves that component across core and ' +
21
+ 'integration packages; an array returns one ordered result row per selector at ' +
22
+ 'every array length; and no name returns the catalog grouped by category. ' +
23
+ 'Boolean flags narrow each resolved component to just its props, source, ' +
24
+ 'showcase, or example blocks.',
25
25
  importPath: '@astryxdesign/cli/api',
26
26
  signature:
27
- 'component(name?: string, options?: ComponentOptions): Promise<ComponentListResponse | ComponentDetailResponse | ComponentDetailPropsResponse | ComponentDetailSourceResponse | ComponentDetailShowcaseResponse | ComponentDetailBlocksResponse>',
27
+ 'component(name?: string | string[], options?: ComponentOptions): Promise<ComponentListResponse | ComponentBatchResponse | ComponentDetailResponse | ComponentDetailPropsResponse | ComponentDetailSourceResponse | ComponentDetailShowcaseResponse | ComponentDetailBlocksResponse>',
28
28
  keywords: [
29
29
  'component',
30
30
  'components',
@@ -37,14 +37,15 @@ export const doc = {
37
37
  params: [
38
38
  {
39
39
  name: 'name',
40
- type: 'string',
40
+ type: 'string | string[]',
41
41
  description:
42
- "Component name to resolve (e.g. 'Button'). Omit to list the catalog.",
42
+ "Pass one selector string for the existing single-result response, or an array of at most 100 selectors for an ordered component.batch response. The limit counts duplicates in every projection mode. An array always requests a batch, including [] and ['Button']. Use 'Button', 'widgets/Button', '@acme/widgets/Button', or '@acme/widgets@1.2.3/Button'. A version applies to the package and must match the installed version. Omit the argument to list the catalog.",
43
43
  },
44
44
  {
45
45
  name: 'options.cwd',
46
46
  type: 'string',
47
47
  description: 'Directory to resolve @astryxdesign/core from.',
48
+ default: 'process.cwd()',
48
49
  },
49
50
  {
50
51
  name: 'options.list',
@@ -54,13 +55,14 @@ export const doc = {
54
55
  {
55
56
  name: 'options.category',
56
57
  type: 'string',
57
- description: 'List only components in this category.',
58
+ description:
59
+ "List only the components in this group: a key of the unfiltered list (each component's group field), such as 'Layout' or 'Button'. It is not the category field of a component detail.",
58
60
  },
59
61
  {
60
62
  name: 'options.package',
61
63
  type: 'string',
62
64
  description:
63
- "Scope lookup to a specific external package (e.g. '@acme/xds-widgets').",
65
+ "Scope lookup to a specific external package (e.g. '@acme/widgets').",
64
66
  },
65
67
  {
66
68
  name: 'options.props',
@@ -87,7 +89,8 @@ export const doc = {
87
89
  name: 'options.detail',
88
90
  type: "'full' | 'compact' | 'brief'",
89
91
  description: 'Detail level for list views.',
90
- default: "'full' for a named component, 'brief' for list views",
92
+ default:
93
+ "'full' for a named component; 'brief' for lists (returned as data.detail: 'names')",
91
94
  },
92
95
  {
93
96
  name: 'options.lang',
@@ -110,7 +113,12 @@ export const doc = {
110
113
  {
111
114
  type: 'component.list',
112
115
  description:
113
- "The catalog grouped by category. data.detail is the level ('names' | 'compact' | 'full') and data.components is the grouped map: names entries with name, package, and an optional canonical import for integration and legacy package components; brief entries; or full ComponentDoc entries.",
116
+ "The catalog grouped by component group. data.detail is the level ('names' | 'compact' | 'full') and data.components is the grouped map: names entries with name, package, and an optional canonical import for integration and legacy package components; brief entries; or full ComponentDoc entries.",
117
+ },
118
+ {
119
+ type: 'component.batch',
120
+ description:
121
+ 'An explicit selector array returns one ordered receipt at every array length: count and one results row per selector, including duplicates. ComponentBatchResponse specializes the shared BatchResponse and BatchRow types. Each row carries selector and status (found, not_found, ambiguous, or error); found rows carry the single-selector result, ambiguous rows carry installed candidates ({package, component, kind, installed}), and failed rows carry code, error, and optional suggestions.',
114
122
  },
115
123
  {
116
124
  type: 'component.detail',
@@ -137,6 +145,10 @@ export const doc = {
137
145
  },
138
146
  ],
139
147
  throws: [
148
+ {
149
+ code: 'ERR_INVALID_ARGUMENT',
150
+ when: 'a selector array has more than 100 entries, a package-shaped selector has no component item, or its package conflicts with options.package',
151
+ },
140
152
  {
141
153
  code: 'ERR_INVALID_DETAIL',
142
154
  when: "options.detail is not 'full', 'compact', or 'brief'",
@@ -151,7 +163,7 @@ export const doc = {
151
163
  },
152
164
  {
153
165
  code: 'ERR_UNKNOWN_CATEGORY',
154
- when: 'options.category is not a string or matches no known category',
166
+ when: 'options.category is not a string or matches no component group',
155
167
  },
156
168
  {
157
169
  code: 'ERR_UNKNOWN_COMPONENT',
@@ -159,12 +171,16 @@ export const doc = {
159
171
  },
160
172
  {
161
173
  code: 'ERR_UNKNOWN_PACKAGE',
162
- when: 'options.package names a legacy external package that cannot be found',
174
+ when: 'options.package names a legacy external package that cannot be found, or a package-qualified selector requests a version that is not installed',
163
175
  },
164
176
  {
165
177
  code: 'ERR_NO_DOC',
166
178
  when: 'the resolved component has no .doc.mjs typed doc file',
167
179
  },
180
+ {
181
+ code: 'ERR_INVALID_DOC',
182
+ when: "the resolved component's .doc.mjs fails to load or validate",
183
+ },
168
184
  {
169
185
  code: 'ERR_NO_SOURCE',
170
186
  when: 'options.source is set but the component has no source file',
@@ -179,10 +195,14 @@ export const doc = {
179
195
  label: 'Look up a component',
180
196
  code: "const r = await component('Button');",
181
197
  },
198
+ {
199
+ label: 'Look up several components',
200
+ code: "await component(['Button', 'Badge']);",
201
+ },
182
202
  {label: 'Props only', code: "await component('Button', {props: true});"},
183
203
  {
184
- label: 'Browse a category',
185
- code: "await component(undefined, {category: 'Form', detail: 'compact'});",
204
+ label: 'Browse one group',
205
+ code: "await component(undefined, {category: 'Layout', detail: 'compact'});",
186
206
  },
187
207
  ],
188
208
  command: 'component',
@@ -4,10 +4,10 @@
4
4
  * @file Programmatic API for the component command — DISPATCHER + BARREL.
5
5
  *
6
6
  * Returns the same typed envelope { type, data } that `astryx --json component`
7
- * outputs. `component(name, opts)` parses the (name, options) pair, resolves the
8
- * subject once via `_adapter`, and routes to the correct leaf
9
- * (list · detail · detail.props/source/showcase/blocks), returning that leaf's
10
- * envelope. The CLI command handler is a thin wrapper around this function.
7
+ * outputs. `component(name, opts)` parses one selector or an ordered selector
8
+ * list, resolves each subject through `_adapter`, and routes to the correct leaf
9
+ * (list · detail · detail.props/source/showcase/blocks). The CLI command handler
10
+ * is a thin wrapper around this function.
11
11
  *
12
12
  * Every leaf is also re-exported for direct scripting use.
13
13
  */
@@ -26,6 +26,8 @@ import {
26
26
  resolveUnscopedDoc,
27
27
  loadComponentDoc,
28
28
  scopeSubComponent,
29
+ ComponentAmbiguityError,
30
+ installedComponentPackageVersion,
29
31
  } from './_adapter.mjs';
30
32
  import {componentList} from './list/list.mjs';
31
33
  import {componentDetail} from './detail/detail.mjs';
@@ -34,13 +36,199 @@ import {componentDetailSource} from './detail/source/source.mjs';
34
36
  import {componentDetailShowcase} from './detail/showcase/showcase.mjs';
35
37
  import {componentDetailBlocks} from './detail/blocks/blocks.mjs';
36
38
 
39
+ /** Maximum selectors accepted before any component resolution starts. */
40
+ export const COMPONENT_BATCH_SELECTOR_LIMIT = 100;
41
+
37
42
  /** @type {ReadonlyArray<string>} */
38
43
  const DETAIL_LEVELS = ['full', 'compact', 'brief'];
39
44
  /** @type {ReadonlyArray<string>} */
40
45
  const LANGS = ['en', 'zh', 'dense'];
46
+ /** @type {Set<string>} */
47
+ const NOT_FOUND_CODES = new Set([
48
+ ERROR_CODES.ERR_UNKNOWN_COMPONENT,
49
+ ERROR_CODES.ERR_UNKNOWN_PACKAGE,
50
+ ERROR_CODES.ERR_NOT_FOUND,
51
+ ]);
52
+
53
+ /**
54
+ * Discover-compatible package target grammar. Versions belong to the package
55
+ * head, never the item after the package slash.
56
+ * @param {string} selector
57
+ * @returns {{scoped: boolean, name: string, version?: string, item?: string}}
58
+ */
59
+ function splitSelector(selector) {
60
+ const scoped = selector.startsWith('@');
61
+ const firstSlash = selector.indexOf('/');
62
+ let head = selector;
63
+ /** @type {string | undefined} */
64
+ let rest;
65
+ const split = scoped
66
+ ? firstSlash < 0
67
+ ? -1
68
+ : selector.indexOf('/', firstSlash + 1)
69
+ : firstSlash;
70
+ if (split > 0) {
71
+ head = selector.slice(0, split);
72
+ rest = selector.slice(split + 1) || undefined;
73
+ }
74
+ const at = head.indexOf('@', 1);
75
+ return {
76
+ scoped,
77
+ name: at > 0 ? head.slice(0, at) : head,
78
+ ...(at > 0 && head.slice(at + 1) ? {version: head.slice(at + 1)} : {}),
79
+ ...(rest ? {item: rest} : {}),
80
+ };
81
+ }
82
+
83
+ /**
84
+ * Resolve one component selector into the existing single-component API inputs.
85
+ * @param {unknown} value
86
+ * @param {string|undefined} packageScope
87
+ * @returns {{selector: string, name: string, package?: string, version?: string}}
88
+ */
89
+ function parseComponentSelector(value, packageScope) {
90
+ if (typeof value !== 'string' || value.length === 0) {
91
+ throw new AstryxError(
92
+ `Invalid component selector "${String(value)}"`,
93
+ undefined,
94
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
95
+ );
96
+ }
97
+ const target = splitSelector(value);
98
+ const packageShaped =
99
+ target.scoped || target.item != null || target.version != null;
100
+ if (!packageShaped) {
101
+ return {selector: value, name: target.name, package: packageScope};
102
+ }
103
+ if (!target.item) {
104
+ throw new AstryxError(
105
+ `Component selector "${value}" names a package but no component`,
106
+ undefined,
107
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
108
+ );
109
+ }
110
+ if (packageScope && packageScope !== target.name) {
111
+ throw new AstryxError(
112
+ `Component selector "${value}" conflicts with --package "${packageScope}"`,
113
+ undefined,
114
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
115
+ );
116
+ }
117
+ return {
118
+ selector: value,
119
+ name: target.item,
120
+ package: target.name,
121
+ ...(target.version ? {version: target.version} : {}),
122
+ };
123
+ }
124
+
125
+ /**
126
+ * A version-qualified selector never falls through to another installed
127
+ * version. Its structured suggestion points at the command that can discover
128
+ * the requested package release.
129
+ * @param {{package?: string, version?: string}} target
130
+ * @param {string} coreDir
131
+ * @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} loadedIntegrations
132
+ * @returns {void}
133
+ */
134
+ function requireInstalledSelectorVersion(target, coreDir, loadedIntegrations) {
135
+ if (!target.version) return;
136
+ const packageName = /** @type {string} */ (target.package);
137
+ const installed = installedComponentPackageVersion(
138
+ coreDir,
139
+ loadedIntegrations,
140
+ packageName,
141
+ );
142
+ if (installed === target.version) return;
143
+ const exact = `${packageName}@${target.version}`;
144
+ throw new AstryxError(
145
+ `Package "${exact}" is not installed`,
146
+ [
147
+ {
148
+ name: `astryx discover ${exact}`,
149
+ reason: 'look up this package version',
150
+ },
151
+ ],
152
+ ERROR_CODES.ERR_UNKNOWN_PACKAGE,
153
+ );
154
+ }
155
+
156
+ /**
157
+ * Turn a single-lookup failure into one complete batch row.
158
+ * @param {string} selector
159
+ * @param {unknown} error
160
+ * @returns {import('./component.type.mjs').ComponentBatchResult}
161
+ */
162
+ function batchFailure(selector, error) {
163
+ const err =
164
+ error instanceof AstryxError
165
+ ? error
166
+ : new AstryxError(
167
+ error instanceof Error ? error.message : String(error),
168
+ undefined,
169
+ ERROR_CODES.ERR_UNKNOWN,
170
+ );
171
+ if (err instanceof ComponentAmbiguityError) {
172
+ return {
173
+ selector,
174
+ status: 'ambiguous',
175
+ code: err.code,
176
+ error: err.message,
177
+ candidates: err.candidates,
178
+ };
179
+ }
180
+ return {
181
+ selector,
182
+ status: NOT_FOUND_CODES.has(err.code) ? 'not_found' : 'error',
183
+ code: err.code,
184
+ error: err.message,
185
+ ...(err.suggestions ? {suggestions: err.suggestions} : {}),
186
+ };
187
+ }
41
188
 
42
189
  /**
43
- * @param {string} [name]
190
+ * @param {unknown[]} selectors
191
+ * @param {object} options
192
+ * @param {string} options.cwd
193
+ * @param {string} [options.package]
194
+ * @param {boolean} [options.props]
195
+ * @param {boolean} [options.source]
196
+ * @param {boolean} [options.showcase]
197
+ * @param {boolean} [options.blocks]
198
+ * @param {'full'|'compact'|'brief'} [options.detail]
199
+ * @param {string|null} [options.lang]
200
+ * @param {boolean} [options.zh]
201
+ * @param {boolean} [options.dense]
202
+ * @param {string} coreDir
203
+ * @returns {Promise<import('./component.type.mjs').ComponentBatchResponse>}
204
+ */
205
+ async function componentBatch(selectors, options, coreDir) {
206
+ const loadedIntegrations = await loadIntegrationsSafely(options.cwd);
207
+ /** @type {import('./component.type.mjs').ComponentBatchResult[]} */
208
+ const results = [];
209
+ for (const value of selectors) {
210
+ const selector = typeof value === 'string' ? value : String(value);
211
+ try {
212
+ const target = parseComponentSelector(value, options.package);
213
+ requireInstalledSelectorVersion(target, coreDir, loadedIntegrations);
214
+ const result =
215
+ /** @type {import('./component.type.mjs').ComponentSingleResponse} */ (
216
+ await component(target.name, {
217
+ ...options,
218
+ lang: options.lang ?? undefined,
219
+ package: target.package,
220
+ })
221
+ );
222
+ results.push({selector, status: 'found', result});
223
+ } catch (error) {
224
+ results.push(batchFailure(selector, error));
225
+ }
226
+ }
227
+ return {type: 'component.batch', data: {count: results.length, results}};
228
+ }
229
+
230
+ /**
231
+ * @param {string|string[]} [name]
44
232
  * @param {object} [options]
45
233
  * @param {string} [options.cwd]
46
234
  * @param {boolean} [options.list]
@@ -56,6 +244,7 @@ const LANGS = ['en', 'zh', 'dense'];
56
244
  * @param {boolean} [options.dense]
57
245
  * @returns {Promise<(
58
246
  * import('./component.type.mjs').ComponentListResponse
247
+ * | import('./component.type.mjs').ComponentBatchResponse
59
248
  * | import('./component.type.mjs').ComponentDetailResponse
60
249
  * | import('./component.type.mjs').ComponentDetailPropsResponse
61
250
  * | import('./component.type.mjs').ComponentDetailSourceResponse
@@ -79,11 +268,16 @@ export async function component(name, options = {}) {
79
268
  dense = false,
80
269
  } = options;
81
270
 
271
+ const selectorList = Array.isArray(name) ? name : null;
272
+ const noName = selectorList == null && !name;
273
+
82
274
  // Default detail level mirrors the CLI (see commands/component/index.mjs):
83
275
  // single-component views default to 'full', list-style views (--list,
84
276
  // --category, or no name) default to 'brief' (scannable name lists).
85
- // Keeping this in sync with the CLI is what the API↔CLI parity test checks.
86
- const isListView = list || category != null || !name;
277
+ // An explicit array remains a batch even when it is empty or a caller also
278
+ // passes a list-only option.
279
+ const isListView =
280
+ selectorList == null && (list || category != null || noName);
87
281
  const detail = detailOption ?? (isListView ? 'brief' : 'full');
88
282
 
89
283
  // Same accepted values and codes as the CLI's --detail and --lang, checked
@@ -103,6 +297,14 @@ export async function component(name, options = {}) {
103
297
  );
104
298
  }
105
299
 
300
+ if (selectorList && selectorList.length > COMPONENT_BATCH_SELECTOR_LIMIT) {
301
+ throw new AstryxError(
302
+ `Component batch accepts at most ${COMPONENT_BATCH_SELECTOR_LIMIT} selectors; received ${selectorList.length}`,
303
+ undefined,
304
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
305
+ );
306
+ }
307
+
106
308
  const coreDir = requireCoreDir(cwd);
107
309
 
108
310
  // A public API caller could pass a non-string category; the list leaf does
@@ -116,11 +318,46 @@ export async function component(name, options = {}) {
116
318
  );
117
319
  }
118
320
 
321
+ // ── Explicit batch selector list ─────────────────────────────────
322
+ // Array shape owns cardinality even if a caller also supplies a list-only
323
+ // option. The aggregate limit above is checked before core or integrations
324
+ // are resolved, so an oversized request can never emit a partial receipt.
325
+ if (selectorList) {
326
+ return componentBatch(
327
+ selectorList,
328
+ {
329
+ cwd,
330
+ package: packageScope,
331
+ props,
332
+ source,
333
+ showcase,
334
+ blocks,
335
+ detail,
336
+ lang,
337
+ zh,
338
+ dense,
339
+ },
340
+ coreDir,
341
+ );
342
+ }
343
+
119
344
  // ── List mode ──────────────────────────────────────────────────
120
- if (category || list || !name) {
345
+ if (category || list || noName) {
121
346
  return componentList(coreDir, {cwd, category, detail, zh, dense, lang});
122
347
  }
123
348
 
349
+ if (typeof name === 'string') {
350
+ const target = parseComponentSelector(name, packageScope);
351
+ if (target.version) {
352
+ const loadedIntegrations = await loadIntegrationsSafely(cwd);
353
+ requireInstalledSelectorVersion(target, coreDir, loadedIntegrations);
354
+ }
355
+ if (target.name !== name || target.package !== packageScope) {
356
+ return component(target.name, {...options, package: target.package});
357
+ }
358
+ name = target.name;
359
+ }
360
+
124
361
  // ── Single component ───────────────────────────────────────────
125
362
  if (typeof name !== 'string') {
126
363
  throw new AstryxError(
@@ -186,7 +423,10 @@ export async function component(name, options = {}) {
186
423
  if (extDocPath) {
187
424
  // Legacy packages ship docs, never source.
188
425
  if (source) {
189
- return componentDetailSource(dirName, null, {name, notFoundInPackage: packageScope});
426
+ return componentDetailSource(dirName, null, {
427
+ name,
428
+ notFoundInPackage: packageScope,
429
+ });
190
430
  }
191
431
  if (blocks) {
192
432
  return componentDetailBlocks(dirName, cwd);
@@ -28,6 +28,31 @@ export type ComponentListData = ({
28
28
  detail: "full";
29
29
  components: Record<string, import("@astryxdesign/cli/authoring").ComponentDoc[]>;
30
30
  });
31
+ /**
32
+ * `component(string[])` always returns this type, including empty and one-item
33
+ * arrays. The CLI returns it for two or more positional selectors.
34
+ */
35
+ export type ComponentBatchResponse = import("../../foundation/response/batch.type.mjs").BatchResponse<"component.batch", ComponentSingleResponse, ComponentBatchCandidate>;
36
+ /**
37
+ * One installed component that makes an unqualified selector ambiguous.
38
+ * Keys match a component row in `discover.search` so a caller does not learn a
39
+ * second candidate shape.
40
+ */
41
+ export type ComponentBatchCandidate = {
42
+ package: string;
43
+ component: string;
44
+ kind: "component";
45
+ installed: true;
46
+ };
47
+ /**
48
+ * The response a successful single selector would have returned.
49
+ */
50
+ export type ComponentSingleResponse = (ComponentDetailResponse | ComponentDetailPropsResponse | ComponentDetailSourceResponse | ComponentDetailShowcaseResponse | ComponentDetailBlocksResponse);
51
+ /**
52
+ * One row per requested selector, in argument order. Duplicate selectors keep
53
+ * duplicate rows.
54
+ */
55
+ export type ComponentBatchResult = import("../../foundation/response/batch.type.mjs").BatchRow<ComponentSingleResponse, ComponentBatchCandidate>;
31
56
  /**
32
57
  * A single entry in a `component.list` group at `detail: 'names'`. Pre-1.0 the
33
58
  * list moved from bare strings to package-qualified objects so consumers can