@astryxdesign/cli 0.6.4-canary.06c8fa3 → 0.6.4-canary.0e1fbdb

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 (254) hide show
  1. package/README.md +49 -40
  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/component.doc.mjs +14 -7
  6. package/api/docs/_adapter.d.mts +8 -3
  7. package/api/docs/_adapter.mjs +14 -6
  8. package/api/docs/docOverlays.test.mjs +27 -1
  9. package/api/docs/docs.doc.mjs +2 -2
  10. package/api/doctor/doctor.doc.mjs +17 -8
  11. package/api/doctor/doctor.type.d.mts +1 -1
  12. package/api/doctor/doctor.type.mjs +1 -1
  13. package/api/gap-report/gap-report.doc.mjs +19 -10
  14. package/api/hook/hook.doc.mjs +6 -3
  15. package/api/index.d.mts +2 -0
  16. package/api/index.mjs +3 -1
  17. package/api/init/init.doc.mjs +17 -12
  18. package/api/integration/add-theme.mjs +22 -1
  19. package/api/integration/add-theme.test.mjs +34 -0
  20. package/api/integration/authoring-checks.mjs +2 -2
  21. package/api/integration/integrationPackCheck.doc.mjs +3 -3
  22. package/api/integration/pack-check.lifecycle-output.test.mjs +2 -0
  23. package/api/integration/pack-check.mjs +54 -6
  24. package/api/integration/pack-check.test.mjs +90 -0
  25. package/api/integration/pack-check.type.mjs +1 -1
  26. package/api/json/assertResponse.doc.mjs +1 -1
  27. package/api/json/index.ts +1 -0
  28. package/api/json/isError.doc.mjs +1 -1
  29. package/api/layout/_adapter.d.mts +34 -0
  30. package/api/layout/_adapter.mjs +148 -0
  31. package/api/layout/check/check.d.mts +16 -0
  32. package/api/layout/check/check.mjs +40 -0
  33. package/api/layout/expand/expand.d.mts +22 -0
  34. package/api/layout/expand/expand.mjs +155 -0
  35. package/api/layout/expand/expand.path-safety.test.mjs +53 -0
  36. package/api/layout/grammar/grammar.d.mts +13 -0
  37. package/api/layout/grammar/grammar.mjs +87 -0
  38. package/api/layout/layout.d.mts +6 -0
  39. package/api/layout/layout.mjs +17 -0
  40. package/api/layout/layout.test.mjs +297 -0
  41. package/api/layout/layout.type.d.mts +89 -0
  42. package/api/layout/layout.type.mjs +103 -0
  43. package/api/layout/layoutCheck.doc.d.mts +11 -0
  44. package/api/layout/layoutCheck.doc.mjs +85 -0
  45. package/api/layout/layoutExpand.doc.d.mts +11 -0
  46. package/api/layout/layoutExpand.doc.mjs +107 -0
  47. package/api/layout/layoutGrammar.doc.d.mts +11 -0
  48. package/api/layout/layoutGrammar.doc.mjs +57 -0
  49. package/api/search/search.d.mts +27 -1
  50. package/api/search/search.doc.mjs +2 -2
  51. package/api/search/search.mjs +228 -16
  52. package/api/swizzle/swizzle.doc.mjs +7 -5
  53. package/api/template/copy/copy.mjs +1 -1
  54. package/api/template/copy/copy.test.mjs +9 -0
  55. package/api/template/template-integration.test.mjs +65 -1
  56. package/api/template/template.doc.mjs +2 -1
  57. package/api/template/template.mjs +1 -1
  58. package/api/theme/generateTonalPalette.doc.mjs +1 -2
  59. package/api/theme/listThemes.doc.mjs +1 -1
  60. package/api/theme/themeAdd.doc.mjs +9 -10
  61. package/api/theme/themeBuild.doc.mjs +13 -13
  62. package/api/theme/themeList.doc.mjs +1 -1
  63. package/api/theme/themeListAvailable.doc.mjs +2 -1
  64. package/api/theme/themePaletteGenerate.doc.mjs +15 -8
  65. package/api/theme/themeTargets.doc.mjs +3 -2
  66. package/api/theme/themeTemplate.doc.mjs +2 -1
  67. package/api/upgrade/run/run.mjs +1 -1
  68. package/api/upgrade/upgrade.doc.mjs +24 -22
  69. package/assets/docs/README.md +4 -2
  70. package/assets/docs/browser-support.doc.mjs +11 -11
  71. package/assets/docs/color.doc.mjs +8 -2
  72. package/assets/docs/elevation.doc.mjs +6 -4
  73. package/assets/docs/getting-started.doc.mjs +5 -16
  74. package/assets/docs/icons.doc.mjs +2 -21
  75. package/assets/docs/illustrations.doc.mjs +7 -15
  76. package/assets/docs/layout.doc.dense.mjs +130 -82
  77. package/assets/docs/layout.doc.mjs +133 -77
  78. package/assets/docs/migration.doc.mjs +19 -21
  79. package/assets/docs/motion.doc.mjs +16 -3
  80. package/assets/docs/principles.doc.dense.mjs +5 -5
  81. package/assets/docs/principles.doc.mjs +8 -0
  82. package/assets/docs/principles.doc.zh.mjs +6 -6
  83. package/assets/docs/shape.doc.mjs +8 -3
  84. package/assets/docs/spacing.doc.mjs +7 -2
  85. package/assets/docs/styling-libraries.doc.mjs +6 -2
  86. package/assets/docs/styling.doc.mjs +19 -23
  87. package/assets/docs/theme.doc.dense.mjs +58 -18
  88. package/assets/docs/theme.doc.mjs +56 -46
  89. package/assets/docs/theme.doc.zh.mjs +9 -8
  90. package/assets/docs/tokens.doc.dense.mjs +2 -2
  91. package/assets/docs/tokens.doc.mjs +389 -8
  92. package/assets/docs/tokens.doc.zh.mjs +2 -2
  93. package/assets/docs/tree/add-a-component.doc.mjs +75 -0
  94. package/assets/docs/tree/add-a-theme.doc.mjs +85 -0
  95. package/assets/docs/tree/add-a-topic.doc.mjs +144 -0
  96. package/assets/docs/tree/agent-guidance.doc.mjs +138 -0
  97. package/assets/docs/tree/block-template.doc.mjs +130 -0
  98. package/assets/docs/tree/build-the-template.doc.mjs +28 -0
  99. package/assets/docs/tree/building-blocks.doc.mjs +46 -0
  100. package/assets/docs/tree/check-your-docs.doc.mjs +137 -0
  101. package/assets/docs/tree/checks.doc.mjs +119 -0
  102. package/assets/docs/tree/codemods.doc.mjs +147 -0
  103. package/assets/docs/tree/component-family.doc.mjs +113 -0
  104. package/assets/docs/tree/component-imports.doc.mjs +69 -0
  105. package/assets/docs/tree/components.doc.mjs +23 -0
  106. package/assets/docs/tree/configuration.doc.mjs +23 -0
  107. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +182 -0
  108. package/assets/docs/tree/define-the-theme.doc.mjs +118 -0
  109. package/assets/docs/tree/describe-the-component.doc.mjs +57 -0
  110. package/assets/docs/tree/docs.doc.mjs +21 -0
  111. package/assets/docs/tree/document-the-template.doc.mjs +28 -0
  112. package/assets/docs/tree/document-the-theme.doc.mjs +68 -0
  113. package/assets/docs/tree/export-template-assets.doc.mjs +147 -0
  114. package/assets/docs/tree/extend-or-replace.doc.mjs +103 -0
  115. package/assets/docs/tree/fonts-and-assets.doc.mjs +106 -0
  116. package/assets/docs/tree/generate-a-palette.doc.mjs +66 -0
  117. package/assets/docs/tree/grade-template-with-agent.doc.mjs +105 -0
  118. package/assets/docs/tree/help.doc.mjs +16 -0
  119. package/assets/docs/tree/integrations.doc.mjs +25 -470
  120. package/assets/docs/tree/links.doc.mjs +98 -0
  121. package/assets/docs/tree/package-and-test.doc.mjs +32 -0
  122. package/assets/docs/tree/page-template.doc.mjs +71 -0
  123. package/assets/docs/tree/publishing.doc.mjs +111 -0
  124. package/assets/docs/tree/quick-start.doc.mjs +272 -0
  125. package/assets/docs/tree/replace-a-core-component.doc.mjs +104 -0
  126. package/assets/docs/tree/replace-a-core-template.doc.mjs +172 -0
  127. package/assets/docs/tree/sections-and-placement.doc.mjs +108 -0
  128. package/assets/docs/tree/see-it-in-an-app.doc.mjs +59 -0
  129. package/assets/docs/tree/ship.doc.mjs +16 -0
  130. package/assets/docs/tree/short-and-findable.doc.mjs +108 -0
  131. package/assets/docs/tree/single-component.doc.mjs +165 -0
  132. package/assets/docs/tree/start-a-template.doc.mjs +143 -0
  133. package/assets/docs/tree/subcomponent.doc.mjs +115 -0
  134. package/assets/docs/tree/template-assets.doc.mjs +64 -0
  135. package/assets/docs/tree/template-doc-overview.doc.mjs +109 -0
  136. package/assets/docs/tree/template-fonts.doc.mjs +102 -0
  137. package/assets/docs/tree/template-grading-rubric.doc.mjs +452 -0
  138. package/assets/docs/tree/template-icons.doc.mjs +97 -0
  139. package/assets/docs/tree/template-images-media.doc.mjs +127 -0
  140. package/assets/docs/tree/template-styles.doc.mjs +93 -0
  141. package/assets/docs/tree/templates.doc.mjs +34 -0
  142. package/assets/docs/tree/test-in-an-app.doc.mjs +115 -0
  143. package/assets/docs/tree/test-template-in-app.doc.mjs +128 -0
  144. package/assets/docs/tree/themes.doc.mjs +39 -0
  145. package/assets/docs/tree/troubleshooting.doc.mjs +149 -0
  146. package/assets/docs/tree/upgrading.doc.mjs +103 -0
  147. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +51 -0
  148. package/assets/docs/tree/verify-packed-template.doc.mjs +77 -0
  149. package/assets/docs/tree/versioning.doc.mjs +161 -0
  150. package/assets/docs/tree/write-good-templates.doc.mjs +64 -0
  151. package/assets/docs/tree/write-the-template-file.doc.mjs +154 -0
  152. package/assets/docs/typography.doc.mjs +24 -4
  153. package/assets/docs/working-with-ai.doc.mjs +30 -22
  154. package/authoring/config/config.doc.mjs +2 -2
  155. package/authoring/config/type.ts +2 -2
  156. package/authoring/doctypes/_schema.d.mts +3 -2
  157. package/authoring/doctypes/_schema.mjs +6 -0
  158. package/authoring/doctypes/base/graph-fields.doc.mjs +3 -3
  159. package/authoring/doctypes/base/type.ts +4 -2
  160. package/authoring/doctypes/command/command.doc.mjs +1 -1
  161. package/authoring/doctypes/command/type.ts +1 -1
  162. package/authoring/doctypes/component/component.doc.mjs +6 -0
  163. package/authoring/doctypes/component/type.ts +8 -0
  164. package/authoring/doctypes/reference/reference.doc.mjs +7 -0
  165. package/authoring/doctypes/reference/type.ts +5 -0
  166. package/authoring/doctypes/schema/schema.doc.mjs +2 -2
  167. package/authoring/doctypes/template/template.doc.mjs +1 -1
  168. package/authoring/doctypes/template/type.ts +2 -2
  169. package/authoring/integration/integration.doc.mjs +12 -10
  170. package/clients/cli/command-result-coverage.test.mjs +7 -7
  171. package/clients/cli/commands/component.doc.mjs +4 -3
  172. package/clients/cli/commands/debug-result-summary.test.mjs +2 -2
  173. package/clients/cli/commands/docs.doc.mjs +1 -1
  174. package/clients/cli/commands/docs.mjs +60 -17
  175. package/clients/cli/commands/doctor-integration-docs.doc.mjs +3 -2
  176. package/clients/cli/commands/doctor-integration.test.mjs +53 -0
  177. package/clients/cli/commands/doctor.doc.mjs +3 -1
  178. package/clients/cli/commands/doctor.mjs +49 -5
  179. package/clients/cli/commands/gap-report.doc.mjs +10 -9
  180. package/clients/cli/commands/init.doc.mjs +9 -6
  181. package/clients/cli/commands/integration-add.doc.mjs +9 -9
  182. package/clients/cli/commands/integration-authoring.test.mjs +61 -10
  183. package/clients/cli/commands/integration-pack.doc.mjs +5 -9
  184. package/clients/cli/commands/integration-real-world.test.mjs +1 -1
  185. package/clients/cli/commands/integration-verify.doc.mjs +22 -0
  186. package/clients/cli/commands/integration.doc.mjs +4 -4
  187. package/clients/cli/commands/integration.mjs +74 -43
  188. package/clients/cli/commands/layout-check.doc.mjs +65 -0
  189. package/clients/cli/commands/layout-expand.doc.mjs +83 -0
  190. package/clients/cli/commands/layout-grammar.doc.mjs +30 -0
  191. package/clients/cli/commands/layout.doc.mjs +34 -0
  192. package/clients/cli/commands/layout.error-codes.test.mjs +66 -0
  193. package/clients/cli/commands/layout.exit-parity.test.mjs +41 -0
  194. package/clients/cli/commands/layout.mjs +275 -0
  195. package/clients/cli/commands/layout.path-help.test.mjs +33 -0
  196. package/clients/cli/commands/layout.stdin-cap.test.mjs +47 -0
  197. package/clients/cli/commands/layout.text-fields.test.mjs +39 -0
  198. package/clients/cli/commands/manifest.doc.mjs +1 -1
  199. package/clients/cli/commands/search.doc.mjs +10 -3
  200. package/clients/cli/commands/search.mjs +21 -2
  201. package/clients/cli/commands/search.test.mjs +21 -4
  202. package/clients/cli/commands/swizzle.doc.mjs +1 -1
  203. package/clients/cli/commands/template.doc.mjs +1 -1
  204. package/clients/cli/commands/text-json-parity.test.mjs +24 -1
  205. package/clients/cli/commands/theme-add.doc.mjs +1 -1
  206. package/clients/cli/commands/theme-palette-generate.doc.mjs +3 -2
  207. package/clients/cli/commands/theme-palette.doc.mjs +1 -2
  208. package/clients/cli/commands/theme-targets.doc.mjs +2 -2
  209. package/clients/cli/commands/theme.doc.mjs +2 -1
  210. package/clients/cli/commands/upgrade.doc.mjs +62 -3
  211. package/clients/cli/index.mjs +32 -6
  212. package/clients/cli/lib/define-command.mjs +28 -4
  213. package/clients/cli/lib/define-command.test.mjs +54 -0
  214. package/clients/cli/lib/exit-codes.test.mjs +25 -2
  215. package/clients/cli/lib/json-shim.test.mjs +20 -6
  216. package/clients/cli/lib/manifest.mjs +23 -5
  217. package/foundation/agent-docs/agent-docs.mjs +1 -1
  218. package/foundation/discovery/authoring-self-docs.test.mjs +6 -2
  219. package/foundation/discovery/cli-self-docs.mjs +16 -2
  220. package/foundation/discovery/cli-self-docs.test.mjs +20 -0
  221. package/foundation/discovery/docs-discovery.mjs +5 -1
  222. package/foundation/discovery/docs-discovery.test.mjs +21 -0
  223. package/foundation/discovery/docs-section-key.d.mts +1 -1
  224. package/foundation/discovery/docs-section-key.mjs +1 -1
  225. package/foundation/discovery/template-adapter.mjs +1 -1
  226. package/foundation/doc-compiler/doc-loads.test.mjs +15 -2
  227. package/foundation/doc-compiler/inputs.test.mjs +0 -1
  228. package/foundation/doc-compiler/tree.d.mts +4 -0
  229. package/foundation/doc-compiler/tree.mjs +6 -1
  230. package/foundation/integrations/cli-requirement.d.mts +26 -6
  231. package/foundation/integrations/cli-requirement.mjs +46 -11
  232. package/foundation/integrations/cli-requirement.test.mjs +7 -2
  233. package/foundation/integrations/contribution-inventory.mjs +1 -1
  234. package/foundation/response/error-codes.doc.mjs +6 -8
  235. package/foundation/response/error-codes.test.mjs +30 -5
  236. package/foundation/response/response-types.doc.d.mts +4 -3
  237. package/foundation/response/response-types.doc.mjs +42 -6
  238. package/foundation/response/response.doc.mjs +11 -10
  239. package/foundation/xle/browser.d.mts +3 -3
  240. package/foundation/xle/browser.mjs +3 -3
  241. package/foundation/xle/expand.mjs +2 -2
  242. package/foundation/xle/parse.mjs +1 -1
  243. package/foundation/xle/print.mjs +2 -2
  244. package/foundation/xle/splice.mjs +1 -1
  245. package/package.json +9 -9
  246. package/api/docs/docs.test.mjs +0 -245
  247. package/api/docs/integration-tree.test.mjs +0 -555
  248. package/api/docs/integrationDocs.test.mjs +0 -314
  249. package/api/search/search.test.mjs +0 -530
  250. package/assets/docs/tree/integrations.test.mjs +0 -62
  251. package/assets/docs/tree/writing-docs.doc.mjs +0 -286
  252. package/clients/cli/commands/docs.test.mjs +0 -323
  253. package/foundation/agent-docs/agent-docs.test.mjs +0 -1159
  254. package/foundation/doc-compiler/tree.test.mjs +0 -606
package/api/json/index.ts CHANGED
@@ -26,6 +26,7 @@ export type * from '../gap-report/gap-report.type.mjs';
26
26
  export type * from '../upgrade/upgrade.type.mjs';
27
27
  export type * from '../init/init.type.mjs';
28
28
  export type * from '../doctor/doctor.type.mjs';
29
+ export type * from '../layout/layout.type.mjs';
29
30
  export type * from '../integration/validate-integration.type.mjs';
30
31
  export type * from '../integration/authoring-checks.type.mjs';
31
32
  export type * from '../integration/pack-check.type.mjs';
@@ -15,7 +15,7 @@ export const doc = {
15
15
  displayName: 'isError()',
16
16
  summary: 'Did the CLI return an error envelope?',
17
17
  description:
18
- 'Tests a parsed response for an `error` key. Branch on this before touching `data`: ' +
18
+ 'Tests a parsed response for an `error` key. Branch on this before touching `data`, ' +
19
19
  'and prefer the stable `code` field over matching the human-readable message, which is ' +
20
20
  'not a contract. Note this returns a plain boolean, not a TypeScript type predicate, so ' +
21
21
  'it does not narrow on its own: cast to the matching *Response type to get typed access.',
@@ -0,0 +1,34 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /** @param {import('../../foundation/xle/xle-ast').RawIssue} issue */
5
+ export function formatIssue(issue: import("../../foundation/xle/xle-ast").RawIssue): string;
6
+ /**
7
+ * Parse + validate, throwing structured XDSErrors on failure.
8
+ * Returns {doc, registry, blocks, warnings}.
9
+ *
10
+ * @param {string} expression
11
+ * @param {{form?: 'compact'|'outline'|'auto', loose?: boolean, cwd?: string}} [options]
12
+ */
13
+ export function analyze(expression: string, { form, loose, cwd }?: {
14
+ form?: "compact" | "outline" | "auto";
15
+ loose?: boolean;
16
+ cwd?: string;
17
+ }): Promise<{
18
+ doc: import("../../foundation/xle/xle-ast").XLEDoc;
19
+ registry: import("../../foundation/xle/xle-ast").Registry;
20
+ blocks: LayoutBlock[];
21
+ errors: import("../../foundation/xle/xle-ast").RawIssue[];
22
+ warnings: import("../../foundation/xle/xle-ast").RawIssue[];
23
+ }>;
24
+ export type LayoutBlock = {
25
+ dirName: string;
26
+ name: string;
27
+ kind: "template" | "component";
28
+ type?: string | undefined;
29
+ description?: string | undefined;
30
+ category?: string | undefined;
31
+ importPath?: string | undefined;
32
+ filePath?: string | undefined;
33
+ isDefault?: boolean | undefined;
34
+ };
@@ -0,0 +1,148 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Shared analysis layer for the `layout` command's expand/check leaves.
5
+ *
6
+ * Loads the block catalog (template blocks + app-registered components), builds
7
+ * the branch registry, and parses+validates a layout expression into a doc +
8
+ * issues. Both the expand and check leaves sit on `analyze`; neither parses or
9
+ * validates directly. (The grammar leaf needs none of this — it only reads the
10
+ * registry alias table.)
11
+ *
12
+ * @input expression string (+ options)
13
+ * @output analyze() -> {doc, registry, blocks, errors, warnings}; formatIssue()
14
+ * @position api — shared core over lib/xle; leaves in expand/ + check/ project it
15
+ */
16
+
17
+ import {AstryxError} from '../error.mjs';
18
+ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
19
+ import {parse, XLEParseError} from '../../foundation/xle/parse.mjs';
20
+ import {validate} from '../../foundation/xle/validate.mjs';
21
+ import {buildRegistry} from '../../foundation/xle/registry.mjs';
22
+ import {discoverTemplates} from '../template/template.mjs';
23
+ import {Project} from '../../foundation/config/project.mjs';
24
+
25
+ /**
26
+ * @typedef {object} LayoutBlock
27
+ * @property {string} dirName
28
+ * @property {string} name
29
+ * @property {'template'|'component'} kind
30
+ * @property {string} [type]
31
+ * @property {string} [description]
32
+ * @property {string} [category]
33
+ * @property {string} [importPath]
34
+ * @property {string} [filePath]
35
+ * @property {boolean} [isDefault]
36
+ */
37
+
38
+ /**
39
+ * The catalog a `{hint}` can resolve to: template blocks (spliced inline) plus
40
+ * any app-registered local components from astryx.config.mjs
41
+ * `experimental.xle.components` (imported by name). App components are how XLE
42
+ * reaches domain pieces — the KpiCard/chart/drawer set that the
43
+ * @astryxdesign/core registry can't see.
44
+ *
45
+ * @param {string} cwd
46
+ * @returns {Promise<LayoutBlock[]>}
47
+ */
48
+ async function loadBlocks(cwd) {
49
+ /** @type {LayoutBlock[]} */
50
+ const blocks = [];
51
+ try {
52
+ const all = await discoverTemplates(cwd);
53
+ const templates = all.filter(template => template.type === 'block');
54
+ /** @type {Map<string, import('../../foundation/discovery/template-adapter.mjs').DiscoveredTemplate>} */
55
+ const byId = new Map();
56
+ // Exact ids are the fallback. Active replacement aliases override them in a
57
+ // second pass, matching template() regardless of discovery/display order.
58
+ for (const template of templates) byId.set(template.dirName, template);
59
+ for (const template of templates) {
60
+ if (template.replaces != null) byId.set(template.replaces, template);
61
+ }
62
+ for (const [id, template] of byId) {
63
+ blocks.push({...template, dirName: id, kind: 'template'});
64
+ }
65
+ } catch {
66
+ // discovery is best-effort
67
+ }
68
+ try {
69
+ const project = await Project.load(cwd);
70
+ /** @type {Record<string, {from?: string, description?: string, default?: boolean}>} */
71
+ const components = project.config.experimental?.xle?.components ?? {};
72
+ for (const [name, spec] of Object.entries(components)) {
73
+ const importPath = spec.from;
74
+ if (!importPath) continue;
75
+ blocks.push({
76
+ type: 'block',
77
+ kind: 'component',
78
+ dirName: name,
79
+ name,
80
+ description: spec.description ?? '',
81
+ category: 'app',
82
+ importPath,
83
+ isDefault: Boolean(spec.default),
84
+ });
85
+ }
86
+ } catch {
87
+ // config is optional
88
+ }
89
+ return blocks;
90
+ }
91
+
92
+ /** @param {import('../../foundation/xle/xle-ast').RawIssue} issue */
93
+ export function formatIssue(issue) {
94
+ const where = issue.line != null ? `line ${issue.line}: ` : '';
95
+ return `${where}${issue.message}`;
96
+ }
97
+
98
+ /**
99
+ * Parse + validate, throwing structured XDSErrors on failure.
100
+ * Returns {doc, registry, blocks, warnings}.
101
+ *
102
+ * @param {string} expression
103
+ * @param {{form?: 'compact'|'outline'|'auto', loose?: boolean, cwd?: string}} [options]
104
+ */
105
+ export async function analyze(
106
+ expression,
107
+ {form = 'auto', loose = false, cwd = process.cwd()} = {},
108
+ ) {
109
+ // Validate inputs in the API (not just the CLI): an empty expression or an
110
+ // unknown --form must error, not silently parse as an empty/compact layout.
111
+ if (typeof expression !== 'string' || expression.trim() === '') {
112
+ throw new AstryxError(
113
+ 'Layout expression is empty.',
114
+ undefined,
115
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
116
+ );
117
+ }
118
+ if (form !== 'compact' && form !== 'outline' && form !== 'auto') {
119
+ throw new AstryxError(
120
+ `Invalid form "${form}". Must be one of: compact, outline, auto.`,
121
+ undefined,
122
+ ERROR_CODES.ERR_INVALID_OPTION,
123
+ );
124
+ }
125
+ const registry =
126
+ /** @type {import('../../foundation/xle/xle-ast').Registry} */ (
127
+ /** @type {unknown} */ (await buildRegistry({cwd}))
128
+ );
129
+ const blocks = await loadBlocks(cwd);
130
+
131
+ /** @type {import('../../foundation/xle/xle-ast').XLEDoc} */
132
+ let doc;
133
+ try {
134
+ doc = parse(expression, {form});
135
+ } catch (e) {
136
+ if (e instanceof XLEParseError) {
137
+ throw new AstryxError(
138
+ `Layout expression syntax error at line ${e.line}, col ${e.col}: ${e.message}`,
139
+ undefined,
140
+ ERROR_CODES.ERR_LAYOUT_PARSE,
141
+ );
142
+ }
143
+ throw e;
144
+ }
145
+
146
+ const {errors, warnings} = validate(doc, registry, blocks, {loose});
147
+ return {doc, registry, blocks, errors, warnings};
148
+ }
@@ -0,0 +1,16 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * `astryx layout check "<expr>" [--form compact|outline]`
6
+ * Validates without expanding; echoes both canonical surfaces.
7
+ *
8
+ * @param {string} expression
9
+ * @param {{form?: 'compact'|'outline'|'auto', loose?: boolean, cwd?: string}} [options]
10
+ * @returns {Promise<import('../layout.type.mjs').LayoutCheckResponse>}
11
+ */
12
+ export function layoutCheck(expression: string, options?: {
13
+ form?: "compact" | "outline" | "auto";
14
+ loose?: boolean;
15
+ cwd?: string;
16
+ }): Promise<import("../layout.type.mjs").LayoutCheckResponse>;
@@ -0,0 +1,40 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `astryx layout check` leaf — validate a layout expression without
5
+ * expanding, echoing both canonical surfaces (compact + outline). Resolution +
6
+ * validation come from ../_adapter.mjs (analyze); this leaf projects the
7
+ * `layout.check` envelope.
8
+ *
9
+ * @input expression string (+ options)
10
+ * @output {type:'layout.check', data}
11
+ * @position api — leaf over ../_adapter.mjs + lib/xle/print
12
+ */
13
+
14
+ import {toCompact, toOutline} from '../../../foundation/xle/print.mjs';
15
+ import {analyze, formatIssue} from '../_adapter.mjs';
16
+
17
+ /**
18
+ * `astryx layout check "<expr>" [--form compact|outline]`
19
+ * Validates without expanding; echoes both canonical surfaces.
20
+ *
21
+ * @param {string} expression
22
+ * @param {{form?: 'compact'|'outline'|'auto', loose?: boolean, cwd?: string}} [options]
23
+ * @returns {Promise<import('../layout.type.mjs').LayoutCheckResponse>}
24
+ */
25
+ export async function layoutCheck(expression, options = {}) {
26
+ const {form = 'auto', loose = false, cwd = process.cwd()} = options;
27
+ const {doc, errors, warnings} = await analyze(expression, {form, loose, cwd});
28
+
29
+ return {
30
+ type: 'layout.check',
31
+ data: {
32
+ valid: errors.length === 0,
33
+ form: doc.form,
34
+ errors: errors.map(e => ({...e, formatted: formatIssue(e)})),
35
+ warnings: warnings.map(formatIssue),
36
+ compact: toCompact(doc),
37
+ outline: toOutline(doc),
38
+ },
39
+ };
40
+ }
@@ -0,0 +1,22 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * `astryx layout expand "<expr>" [path]`
6
+ *
7
+ * @param {string} expression
8
+ * @param {object} [options]
9
+ * @param {string} [options.targetPath] - write TSX here (validated against cwd)
10
+ * @param {'compact'|'outline'|'auto'} [options.form]
11
+ * @param {boolean} [options.loose] - downgrade unknown {hints} to TODO warnings
12
+ * @param {string} [options.name] - generated component name
13
+ * @param {string} [options.cwd]
14
+ * @returns {Promise<import('../layout.type.mjs').LayoutExpandResponse>}
15
+ */
16
+ export function layoutExpand(expression: string, options?: {
17
+ targetPath?: string | undefined;
18
+ form?: "compact" | "auto" | "outline" | undefined;
19
+ loose?: boolean | undefined;
20
+ name?: string | undefined;
21
+ cwd?: string | undefined;
22
+ }): Promise<import("../layout.type.mjs").LayoutExpandResponse>;
@@ -0,0 +1,155 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `astryx layout expand` leaf — expand a validated layout expression into
5
+ * XDS TSX (optionally written to disk). Resolution + validation come from
6
+ * ../_adapter.mjs (analyze); this leaf owns block-module assembly, code
7
+ * generation, and the path-safe write, and projects the `layout.expand` envelope.
8
+ *
9
+ * @input expression string (+ options)
10
+ * @output {type:'layout.expand', data}
11
+ * @position api — leaf over ../_adapter.mjs + lib/xle/expand
12
+ */
13
+
14
+ import * as fs from 'node:fs';
15
+ import * as path from 'node:path';
16
+ import {AstryxError} from '../../error.mjs';
17
+ import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
18
+ import {assertWithin, isFilePathArg, PathSafetyError} from '../../../foundation/fs/path-safety.mjs';
19
+ import {detectForm} from '../../../foundation/xle/parse.mjs';
20
+ import {expand} from '../../../foundation/xle/expand.mjs';
21
+ import {stripTemplateAssetRefs} from '../../template/template.mjs';
22
+ import {analyze, formatIssue} from '../_adapter.mjs';
23
+
24
+ /** @param {string} name */
25
+ const normKey = (name) => name.toLowerCase().replace(/[^a-z0-9]/g, '');
26
+
27
+ /**
28
+ * Collect the block names referenced by {hints} anywhere in the doc.
29
+ * @param {import('../../../foundation/xle/xle-ast').XLEDoc} doc
30
+ */
31
+ function collectHintNames(doc) {
32
+ /** @type {Set<string>} */
33
+ const names = new Set();
34
+ /** @param {import('../../../foundation/xle/xle-ast').XLEItem} node */
35
+ const visitNode = (node) => {
36
+ if (!node || node.kind === 'group') {
37
+ (node?.children || []).forEach(visit);
38
+ return;
39
+ }
40
+ if (node.hint?.block) names.add(node.hint.block.name);
41
+ for (const slot of node.slots || []) {
42
+ const value = slot.value;
43
+ if (value && typeof value === 'object' && 'hint' in value && value.hint?.block) {
44
+ names.add(value.hint.block.name);
45
+ }
46
+ if (value && typeof value === 'object' && 'subexpr' in value) {
47
+ (value.subexpr || []).forEach(visit);
48
+ }
49
+ }
50
+ (node.children || []).forEach(visit);
51
+ };
52
+ /** @param {import('../../../foundation/xle/xle-ast').XLEItem} item */
53
+ const visit = (item) => (item?.kind === 'group' ? item.children.forEach(visit) : visitNode(item));
54
+ doc.roots.forEach(visit);
55
+ doc.overlays.forEach(visit);
56
+ return names;
57
+ }
58
+
59
+ /**
60
+ * Build the blockModules map expand() needs: import-mode for app components,
61
+ * splice-mode (reading + asset-stripping the block source) for template blocks.
62
+ * Only blocks actually referenced are read.
63
+ *
64
+ * @param {import('../../../foundation/xle/xle-ast').XLEDoc} doc
65
+ * @param {import('../_adapter.mjs').LayoutBlock[]} blocks
66
+ * @returns {Map<string, import('../../../foundation/xle/xle-ast').BlockModule>}
67
+ */
68
+ function buildBlockModules(doc, blocks) {
69
+ const referenced = collectHintNames(doc);
70
+ if (referenced.size === 0) return new Map();
71
+ const byKey = new Map(blocks.map(b => [normKey(b.dirName), b]));
72
+ /** @type {Map<string, import('../../../foundation/xle/xle-ast').BlockModule>} */
73
+ const modules = new Map();
74
+ for (const name of referenced) {
75
+ const block = byKey.get(normKey(name));
76
+ if (!block) continue;
77
+ if (block.kind === 'component') {
78
+ modules.set(name, /** @type {import('../../../foundation/xle/xle-ast').BlockModule} */ (/** @type {unknown} */ ({mode: 'import', componentName: block.name, importPath: block.importPath, isDefault: block.isDefault})));
79
+ } else if (block.filePath && fs.existsSync(block.filePath)) {
80
+ modules.set(name, /** @type {import('../../../foundation/xle/xle-ast').BlockModule} */ ({mode: 'splice', componentName: block.dirName, source: stripTemplateAssetRefs(fs.readFileSync(block.filePath, 'utf-8'))}));
81
+ }
82
+ }
83
+ return modules;
84
+ }
85
+
86
+ /**
87
+ * `astryx layout expand "<expr>" [path]`
88
+ *
89
+ * @param {string} expression
90
+ * @param {object} [options]
91
+ * @param {string} [options.targetPath] - write TSX here (validated against cwd)
92
+ * @param {'compact'|'outline'|'auto'} [options.form]
93
+ * @param {boolean} [options.loose] - downgrade unknown {hints} to TODO warnings
94
+ * @param {string} [options.name] - generated component name
95
+ * @param {string} [options.cwd]
96
+ * @returns {Promise<import('../layout.type.mjs').LayoutExpandResponse>}
97
+ */
98
+ export async function layoutExpand(expression, options = {}) {
99
+ const {targetPath, form = 'auto', loose = false, name, cwd = process.cwd()} = options;
100
+ const {doc, registry, blocks, errors, warnings} = await analyze(expression, {form, loose, cwd});
101
+
102
+ if (errors.length > 0) {
103
+ throw new AstryxError(
104
+ `Layout expression is invalid:\n` + errors.map(e => ` - ${formatIssue(e)}`).join('\n'),
105
+ errors.flatMap(e => (e.suggestions || []).map(s => ({name: s, reason: 'did you mean this?'}))),
106
+ ERROR_CODES.ERR_LAYOUT_INVALID,
107
+ );
108
+ }
109
+
110
+ const componentName = name || 'GeneratedLayout';
111
+ if (!/^[A-Z][A-Za-z0-9]*$/.test(componentName)) {
112
+ throw new AstryxError(
113
+ `--name must be a PascalCase component name, got '${componentName}'`,
114
+ undefined,
115
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
116
+ );
117
+ }
118
+ const blockModules = buildBlockModules(doc, blocks);
119
+ const result = expand(doc, registry, {componentName, blockModules});
120
+
121
+ let written = null;
122
+ if (targetPath) {
123
+ // The guard sees the file that will be written, not only its directory:
124
+ // a symlink at that name would otherwise carry the write outside the root.
125
+ const fileTarget = isFilePathArg(targetPath)
126
+ ? targetPath
127
+ : path.join(targetPath, `${componentName}.tsx`);
128
+ let filePath;
129
+ try {
130
+ filePath = assertWithin(fileTarget, cwd, {label: 'layout target path'});
131
+ } catch (err) {
132
+ if (err instanceof PathSafetyError) {
133
+ throw new AstryxError(err.message, undefined, ERROR_CODES.ERR_PATH_TRAVERSAL);
134
+ }
135
+ throw err;
136
+ }
137
+ fs.mkdirSync(path.dirname(filePath), {recursive: true});
138
+ fs.writeFileSync(filePath, result.code);
139
+ written = path.relative(cwd, filePath);
140
+ }
141
+
142
+ return {
143
+ type: 'layout.expand',
144
+ data: {
145
+ form: form === 'auto' ? detectForm(expression) : form,
146
+ code: result.code,
147
+ componentsUsed: result.componentsUsed,
148
+ states: result.states,
149
+ todos: result.todos,
150
+ blocksReferenced: [...blockModules.entries()].map(([name, m]) => ({name, mode: m.mode})),
151
+ warnings: warnings.map(formatIssue),
152
+ written,
153
+ },
154
+ };
155
+ }
@@ -0,0 +1,53 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Path-safety tests for the `layout.expand` write. The file written, not
5
+ * only the directory it lands in, must stay inside the project root.
6
+ */
7
+
8
+ import {describe, it, expect, beforeAll} from 'vitest';
9
+ import * as fs from 'node:fs';
10
+ import * as os from 'node:os';
11
+ import * as path from 'node:path';
12
+ import {layoutExpand} from '../layout.mjs';
13
+ import {buildRegistry} from '../../../foundation/xle/registry.mjs';
14
+
15
+ const SLOW = 30_000;
16
+
17
+ // The registry imports every component doc on first use; warm it once.
18
+ beforeAll(async () => {
19
+ await buildRegistry();
20
+ }, 120_000);
21
+
22
+ describe('layout.expand — write confinement', () => {
23
+ it('rejects a directory target whose generated file is a symlink leading outside cwd', async () => {
24
+ // Inside the workspace so @astryxdesign/core resolves.
25
+ const cwd = fs.mkdtempSync(path.join(process.cwd(), '.xle-confine-test-'));
26
+ const outside = fs.mkdtempSync(path.join(os.tmpdir(), 'xle-confine-outside-'));
27
+ try {
28
+ const victim = path.join(outside, 'victim.tsx');
29
+ fs.writeFileSync(victim, 'OUTSIDE');
30
+ fs.mkdirSync(path.join(cwd, 'out'));
31
+ fs.symlinkSync(victim, path.join(cwd, 'out', 'GeneratedLayout.tsx'));
32
+
33
+ await expect(
34
+ layoutExpand('V > B', {targetPath: './out', cwd}),
35
+ ).rejects.toMatchObject({code: 'ERR_PATH_TRAVERSAL'});
36
+ expect(fs.readFileSync(victim, 'utf-8')).toBe('OUTSIDE');
37
+ } finally {
38
+ fs.rmSync(cwd, {recursive: true, force: true});
39
+ fs.rmSync(outside, {recursive: true, force: true});
40
+ }
41
+ }, SLOW);
42
+
43
+ it('still writes <Name>.tsx into a plain directory target', async () => {
44
+ const cwd = fs.mkdtempSync(path.join(process.cwd(), '.xle-confine-test-'));
45
+ try {
46
+ const result = await layoutExpand('V > B', {targetPath: './out', name: 'Demo', cwd});
47
+ expect(result.data.written).toBe(path.join('out', 'Demo.tsx'));
48
+ expect(fs.existsSync(path.join(cwd, 'out', 'Demo.tsx'))).toBe(true);
49
+ } finally {
50
+ fs.rmSync(cwd, {recursive: true, force: true});
51
+ }
52
+ }, SLOW);
53
+ });
@@ -0,0 +1,13 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * `astryx layout grammar` — the agent cheatsheet, with the alias table
6
+ * generated from this branch's registry (never hand-maintained).
7
+ *
8
+ * @param {{cwd?: string}} [options]
9
+ * @returns {Promise<import('../layout.type.mjs').LayoutGrammarResponse>}
10
+ */
11
+ export function layoutGrammar(options?: {
12
+ cwd?: string;
13
+ }): Promise<import("../layout.type.mjs").LayoutGrammarResponse>;
@@ -0,0 +1,87 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `astryx layout grammar` leaf — the agent cheatsheet, with the alias
5
+ * table generated from this branch's registry (never hand-maintained). Reads
6
+ * only the registry; shares nothing with expand/check, so it has no adapter.
7
+ *
8
+ * @output {type:'layout.grammar', data}
9
+ * @position api — leaf over lib/xle/registry
10
+ */
11
+
12
+ import {buildRegistry} from '../../../foundation/xle/registry.mjs';
13
+ import {MAX_REPEAT} from '../../../foundation/xle/expand.mjs';
14
+
15
+ /**
16
+ * `astryx layout grammar` — the agent cheatsheet, with the alias table
17
+ * generated from this branch's registry (never hand-maintained).
18
+ *
19
+ * @param {{cwd?: string}} [options]
20
+ * @returns {Promise<import('../layout.type.mjs').LayoutGrammarResponse>}
21
+ */
22
+ export async function layoutGrammar(options = {}) {
23
+ const {cwd = process.cwd()} = options;
24
+ const registry = await buildRegistry({cwd});
25
+
26
+ /** @type {string[]} */
27
+ const aliasLines = [];
28
+ /** @type {Map<string, string[]>} */
29
+ const byTarget = new Map();
30
+ for (const [alias, target] of registry.aliases) {
31
+ if (!byTarget.has(target)) byTarget.set(target, []);
32
+ byTarget.get(target)?.push(alias);
33
+ }
34
+ for (const [target, aliases] of [...byTarget.entries()].sort(([a], [b]) => a.localeCompare(b))) {
35
+ aliasLines.push(`${aliases.join('/')}=${target}`);
36
+ }
37
+
38
+ const text = `XLE/XLO — XDS layout expressions (branch-generated; aliases reflect this install)
39
+
40
+ WORKFLOW
41
+ astryx layout check "<expr>" validate; echoes canonical compact + outline forms
42
+ astryx layout expand "<expr>" [path] emit validated TSX (path optional; --name <Pascal>)
43
+ Errors carry line/col + suggestions. Fix and resubmit; nothing is guessed.
44
+
45
+ TWO SURFACES, ONE LANGUAGE (autodetected; --form to force)
46
+ compact: A[cp6 @topNav=TN] > L > LC > S[p6] > (C{card-callout}*4) + T
47
+ outline: indentation = nesting · same-indent = siblings · "repeat N:" block = (...)*N
48
+ slot lines: topNav: TN (or a block: topNav:\\n TN ...)
49
+
50
+ NODE ANATOMY Name#id.enum"payload"[attrs]{hint}*N > children
51
+ .enum unique enum value of any prop: Bd.success Tx.lg B.primary
52
+ "payload" primary text prop (label/title/heading) or text child: TI"Email" B"Save"
53
+ {hint} kebab-case template/component reference (see TEMPLATE REFERENCING) — NEVER text
54
+ *N / xN repeat, at most ${MAX_REPEAT} copies (use $ for the counter: Tk"item-$"*3)
55
+ trailing ! initial selection for scaffolded state: Tab"Overview"!
56
+
57
+ ATTRS [...] (outline: bare tokens after the name, no brackets)
58
+ fused p6 g4 c4 w240 h2 cp2 mw960 rg2 cg2 (per-component: padding lives on Card/Section/AppShell.cp — p6 on AppShell/Layout/VStack errors with a correction)
59
+ key=value t=email href='/x' c{min:340} dv=[top,bottom] — keys validated per component
60
+ flags req opt dis striped hover divider … (isX/hasX props) · negate: !scroll
61
+ align j= main axis, a= cross axis — expander picks hAlign/vAlign per stack direction
62
+ slots @slotName=Node | @slotName=(sub > expr) | @slotName='text' | @slotName=#id
63
+ trigger opens=#id (a plain attr, no @ — binds an onClick that opens the overlay)
64
+ fill on a stack child → wraps in <StackItem size="fill">
65
+
66
+ TEMPLATE REFERENCING ({hint} pulls in real content — this is how XLE reaches past the @astryxdesign/core shell)
67
+ C{card-callout} splice a template block (astryx template --list --type block):
68
+ the block is co-defined once in the file, referenced, imports merged
69
+ {kpi-card} standalone reference (no wrapper element) — place a component directly
70
+ {kpi-card}*4 repeat a reference; the definition/import is emitted once
71
+ app components register local ones in astryx.config.mjs to import them by name:
72
+ export default {experimental: {xle: {components: {KpiCard: {from: '@/components/KpiCard'}}}}}
73
+ then {kpi-card} → import {KpiCard} + <KpiCard /> (kebab ↔ Pascal)
74
+
75
+ STRUCTURE THE EXPANDER HANDLES
76
+ Layout > LH + LC + LF + LP children auto-route into header/content/footer/start slots
77
+ T > (TR>THC*4) + (TR>TC*4)*6 rows partition into TableHeader/TableBody automatically
78
+ TabList/inputs required value+onChange scaffold typed useState automatically
79
+ overlays compact: tree ;; Dlg#confirm[...] · outline: overlays: section
80
+ trigger: B"Delete"[opens=#confirm]
81
+
82
+ ALIASES (full component names always valid; XDS prefix optional)
83
+ ${aliasLines.join(' ')}
84
+ `;
85
+
86
+ return {type: 'layout.grammar', data: {text, aliases: Object.fromEntries(registry.aliases)}};
87
+ }
@@ -0,0 +1,6 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ export { layoutExpand } from "./expand/expand.mjs";
5
+ export { layoutCheck } from "./check/check.mjs";
6
+ export { layoutGrammar } from "./grammar/grammar.mjs";
@@ -0,0 +1,17 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `layout` command barrel — re-exports the expand/check/grammar leaves so
5
+ * the CLI (cli/commands/layout.mjs) and scripted callers import from one place.
6
+ * Each leaf is also importable directly (e.g. api/layout/expand/expand.mjs). The
7
+ * shared analysis core lives in ./_adapter.mjs. `layout` has real subcommands,
8
+ * so there is no flag-dispatch here — the CLI calls the leaf it wants.
9
+ *
10
+ * @input layout expressions (+ options), per leaf
11
+ * @output {type, data} envelopes: layout.expand / layout.check / layout.grammar
12
+ * @position api — command barrel over the expand/check/grammar leaves
13
+ */
14
+
15
+ export {layoutExpand} from './expand/expand.mjs';
16
+ export {layoutCheck} from './check/check.mjs';
17
+ export {layoutGrammar} from './grammar/grammar.mjs';