@astryxdesign/cli 0.6.3-canary.d0d49a4 → 0.6.3-canary.dea6813

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 (183) hide show
  1. package/README.md +32 -18
  2. package/api/build/build.doc.mjs +3 -3
  3. package/api/build/build.test.mjs +14 -3
  4. package/api/build/build.type.d.mts +35 -1
  5. package/api/build/build.type.mjs +24 -3
  6. package/api/build/help/help.d.mts +8 -5
  7. package/api/build/help/help.mjs +56 -6
  8. package/api/component/component.doc.mjs +11 -2
  9. package/api/component/component.mjs +29 -0
  10. package/api/component/component.test.mjs +38 -0
  11. package/api/component/component.type.d.mts +11 -1
  12. package/api/component/component.type.mjs +8 -1
  13. package/api/discover/discover.doc.mjs +1 -1
  14. package/api/gap-report/gap-report.doc.mjs +7 -4
  15. package/api/init/init.doc.mjs +4 -0
  16. package/api/init/init.test.mjs +41 -1
  17. package/api/init/remove/remove.mjs +1 -1
  18. package/api/init/run/run.mjs +20 -10
  19. package/api/integration/add-contribution.component-names.test.mjs +120 -0
  20. package/api/integration/add-contribution.mjs +11 -0
  21. package/api/integration/add-contribution.test.mjs +80 -0
  22. package/api/integration/integrationAdd.doc.mjs +7 -4
  23. package/api/integration/integrationAddComponent.doc.mjs +1 -1
  24. package/api/integration/validate-integration.mjs +2 -0
  25. package/api/integration/validate-integration.test.mjs +91 -0
  26. package/api/integration/validateIntegration.doc.mjs +1 -1
  27. package/api/json/envelope-types.test.mjs +76 -0
  28. package/api/json/parseResponse.doc.mjs +2 -2
  29. package/api/layout/expand/expand.mjs +7 -5
  30. package/api/layout/expand/expand.path-safety.test.mjs +53 -0
  31. package/api/layout/grammar/grammar.mjs +2 -1
  32. package/api/layout/layoutExpand.doc.mjs +1 -1
  33. package/api/search/search-return-type.test.mjs +54 -0
  34. package/api/search/search.d.mts +2 -9
  35. package/api/search/search.doc.mjs +5 -1
  36. package/api/search/search.mjs +10 -3
  37. package/api/search/search.test.mjs +34 -0
  38. package/api/swizzle/copy/copy.mjs +28 -11
  39. package/api/swizzle/swizzle.doc.mjs +1 -1
  40. package/api/template/copy/copy.mjs +17 -23
  41. package/api/template/copy/copy.test.mjs +17 -0
  42. package/api/template/template.doc.mjs +2 -1
  43. package/api/theme/add/add.binary.test.mjs +91 -0
  44. package/api/theme/add/add.mjs +20 -3
  45. package/api/theme/add/add.staging.test.mjs +66 -0
  46. package/api/theme/build/build.mjs +114 -37
  47. package/api/theme/build/build.public-component-vars.test.mjs +1 -1
  48. package/api/theme/build/build.receipt-doc.test.mjs +111 -0
  49. package/api/theme/build/font-warning.mjs +3 -3
  50. package/api/theme/build/font-warning.test.mjs +5 -2
  51. package/api/theme/palette/generate/generate.mjs +7 -2
  52. package/api/theme/palette/generate/generate.test.mjs +96 -0
  53. package/api/theme/palette/generate/generator.mjs +8 -1
  54. package/api/theme/palette/generate/generator.test.mjs +10 -0
  55. package/api/theme/template/template.mjs +11 -2
  56. package/api/theme/template/template.test.mjs +15 -0
  57. package/api/theme/themeBuild.doc.mjs +7 -4
  58. package/api/theme/themeTemplate.doc.mjs +4 -1
  59. package/api/upgrade/_adapter.mjs +27 -4
  60. package/api/upgrade/list/list.mjs +2 -1
  61. package/api/upgrade/list/list.test.mjs +73 -0
  62. package/api/upgrade/status/status.mjs +2 -2
  63. package/api/upgrade/upgrade.doc.mjs +2 -1
  64. package/api/upgrade/upgrade.type.d.mts +4 -0
  65. package/api/upgrade/upgrade.type.mjs +1 -0
  66. package/assets/codemods/term-log.mjs +32 -8
  67. package/assets/codemods/term-log.test.mjs +19 -1
  68. package/assets/codemods/transforms/v0.6.0/__tests__/next-codemods.test.mjs +47 -0
  69. package/assets/codemods/transforms/v0.6.0/rename-resizable-pixel-bounds.mjs +57 -10
  70. package/assets/templates/pages/table-tree/page.tsx +1704 -0
  71. package/assets/templates/pages/table-tree/template.doc.mjs +12 -0
  72. package/authoring/config/config.doc.mjs +1 -1
  73. package/authoring/config/debug-composition.test.mjs +92 -0
  74. package/authoring/config/type.ts +15 -3
  75. package/clients/cli/command-load-failure.test.mjs +83 -0
  76. package/clients/cli/commands/blog.mjs +23 -8
  77. package/clients/cli/commands/blog.test.mjs +42 -1
  78. package/clients/cli/commands/build-theme.ascii-output.test.mjs +161 -0
  79. package/clients/cli/commands/build-theme.flag-docs.test.mjs +110 -0
  80. package/clients/cli/commands/build-theme.mjs +5 -5
  81. package/clients/cli/commands/build-theme.path-safety.test.mjs +86 -1
  82. package/clients/cli/commands/build-theme.variants.test.mjs +76 -0
  83. package/clients/cli/commands/build.doc.mjs +4 -1
  84. package/clients/cli/commands/build.exit-codes-doc.test.mjs +50 -0
  85. package/clients/cli/commands/build.mjs +32 -47
  86. package/clients/cli/commands/build.playbook.test.mjs +75 -0
  87. package/clients/cli/commands/build.text-fields.test.mjs +40 -0
  88. package/clients/cli/commands/component/index.mjs +2 -7
  89. package/clients/cli/commands/component-package.test.mjs +18 -0
  90. package/clients/cli/commands/component-resolution.test.mjs +21 -0
  91. package/clients/cli/commands/component.test.mjs +19 -0
  92. package/clients/cli/commands/detail-levels.test.mjs +2 -2
  93. package/clients/cli/commands/discover.broken-integration.test.mjs +48 -0
  94. package/clients/cli/commands/discover.components-flag.test.mjs +97 -0
  95. package/clients/cli/commands/discover.doc.mjs +4 -2
  96. package/clients/cli/commands/discover.mjs +3 -3
  97. package/clients/cli/commands/discover.text-projection.test.mjs +103 -0
  98. package/clients/cli/commands/doctor-integration.package-json.test.mjs +53 -0
  99. package/clients/cli/commands/doctor.mjs +6 -16
  100. package/clients/cli/commands/doctor.test.mjs +42 -0
  101. package/clients/cli/commands/gap-report.doc.mjs +16 -5
  102. package/clients/cli/commands/gap-report.test.mjs +72 -0
  103. package/clients/cli/commands/hook/index.mjs +7 -17
  104. package/clients/cli/commands/hook.text-projection.test.mjs +45 -0
  105. package/clients/cli/commands/init.doc.mjs +19 -8
  106. package/clients/cli/commands/init.flag-help.test.mjs +153 -0
  107. package/clients/cli/commands/integration-add.controls.test.mjs +132 -0
  108. package/clients/cli/commands/integration-add.doc.mjs +21 -5
  109. package/clients/cli/commands/interactive-guard.test.mjs +101 -24
  110. package/clients/cli/commands/json-contract.test.mjs +33 -0
  111. package/clients/cli/commands/layout-check.doc.mjs +14 -3
  112. package/clients/cli/commands/layout-expand.doc.mjs +21 -4
  113. package/clients/cli/commands/layout.doc.mjs +2 -2
  114. package/clients/cli/commands/layout.mjs +21 -9
  115. package/clients/cli/commands/layout.path-help.test.mjs +33 -0
  116. package/clients/cli/commands/layout.stdin-cap.test.mjs +47 -0
  117. package/clients/cli/commands/layout.text-fields.test.mjs +39 -0
  118. package/clients/cli/commands/no-prompt-wording.test.mjs +94 -0
  119. package/clients/cli/commands/search.doc.mjs +6 -3
  120. package/clients/cli/commands/search.mjs +17 -7
  121. package/clients/cli/commands/search.test.mjs +75 -0
  122. package/clients/cli/commands/swizzle.doc.mjs +2 -1
  123. package/clients/cli/commands/swizzle.path-safety.test.mjs +42 -0
  124. package/clients/cli/commands/template.doc.mjs +28 -6
  125. package/clients/cli/commands/template.flag-help.test.mjs +117 -0
  126. package/clients/cli/commands/template.path-help.test.mjs +40 -0
  127. package/clients/cli/commands/theme-add.doc.mjs +2 -1
  128. package/clients/cli/commands/theme-build.doc.mjs +7 -6
  129. package/clients/cli/commands/theme-palette-generate.test.mjs +19 -0
  130. package/clients/cli/commands/theme-template.behavior.test.mjs +12 -0
  131. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  132. package/clients/cli/commands/upgrade.ascii-output.test.mjs +87 -0
  133. package/clients/cli/commands/upgrade.doc.mjs +17 -6
  134. package/clients/cli/commands/upgrade.flag-help.test.mjs +188 -0
  135. package/clients/cli/commands/upgrade.hook-output.test.mjs +88 -0
  136. package/clients/cli/index.mjs +13 -30
  137. package/clients/cli/latest-version-env.test.mjs +50 -0
  138. package/clients/cli/lib/cli-error.test.mjs +7 -0
  139. package/clients/cli/lib/component-format.mjs +9 -9
  140. package/clients/cli/lib/component-format.test.mjs +1 -1
  141. package/clients/cli/lib/define-command.mjs +32 -6
  142. package/clients/cli/lib/doc-text-ascii.test.mjs +82 -0
  143. package/clients/cli/lib/exit-codes.test.mjs +97 -0
  144. package/clients/cli/lib/hook-format.mjs +5 -5
  145. package/clients/cli/lib/json-shim.mjs +38 -2
  146. package/clients/cli/lib/json-shim.test.mjs +83 -0
  147. package/clients/cli/lib/manifest.d.ts +2 -0
  148. package/clients/cli/lib/manifest.mjs +22 -0
  149. package/clients/cli/lib/manifest.test.mjs +17 -0
  150. package/foundation/agent-docs/agent-docs.d.mts +4 -0
  151. package/foundation/agent-docs/agent-docs.mjs +69 -3
  152. package/foundation/agent-docs/agent-docs.path-safety.test.mjs +266 -4
  153. package/foundation/config/integration-debug.test.mjs +28 -3
  154. package/foundation/config/project.mjs +123 -9
  155. package/foundation/config/project.test.mjs +126 -0
  156. package/foundation/discovery/template-adapter.d.mts +14 -5
  157. package/foundation/discovery/template-adapter.fixture-refs.test.mjs +248 -0
  158. package/foundation/discovery/template-adapter.integration-isolation.test.mjs +94 -0
  159. package/foundation/discovery/template-adapter.mjs +292 -25
  160. package/foundation/discovery/theming-targets.test.mjs +4 -0
  161. package/foundation/fs/module-loader.d.mts +1 -0
  162. package/foundation/fs/module-loader.mjs +50 -1
  163. package/foundation/fs/module-loader.stdout.test.mjs +332 -0
  164. package/foundation/fs/path-safety.d.mts +3 -2
  165. package/foundation/fs/path-safety.mjs +49 -19
  166. package/foundation/fs/path-safety.test.mjs +50 -0
  167. package/foundation/fs/publish-file-hardlink-unavailable.test.mjs +129 -94
  168. package/foundation/integrations/autolink.mjs +6 -1
  169. package/foundation/response/base.d.ts +8 -4
  170. package/foundation/response/error-codes.doc.mjs +1 -2
  171. package/foundation/response/error-codes.mjs +1 -1
  172. package/foundation/response/error-codes.test.mjs +83 -0
  173. package/foundation/response/json-contract.test.mjs +11 -0
  174. package/foundation/response/json.d.mts +4 -2
  175. package/foundation/response/json.mjs +8 -10
  176. package/foundation/response/response-types.doc.mjs +3 -3
  177. package/foundation/xle/expand.d.mts +2 -0
  178. package/foundation/xle/expand.mjs +3 -2
  179. package/foundation/xle/expand.test.mjs +54 -0
  180. package/package.json +9 -9
  181. package/clients/cli/lib/update-check.mjs +0 -83
  182. package/clients/cli/lib/update-check.test.mjs +0 -137
  183. package/clients/cli/update-hint-commands.test.mjs +0 -54
package/README.md CHANGED
@@ -51,8 +51,8 @@ Options:
51
51
 
52
52
  - `--type <component|hook|doc|template>`: restrict to a single domain
53
53
  - `--limit <n>`: cap the number of results (default 20)
54
- - `--detail`: include the import path and the match reason/score
55
- - `--json`: typed `{ type: 'search', data: { query, matchCount, results } }` envelope — `matchCount` is how many candidates matched in total, `results` the slice `--limit` allowed
54
+ - `--verbose`: also print each result's match score and reason
55
+ - `--json`: typed `{ apiVersion, type: 'search', data: { query, matchCount, results } }` envelope — `matchCount` is how many candidates matched in total, `results` the slice `--limit` allowed
56
56
 
57
57
  ## Commands
58
58
 
@@ -84,7 +84,7 @@ Options:
84
84
 
85
85
  These flags work with any command:
86
86
 
87
- - `--json`: Output as typed JSON envelope: `{ type, data }` (errors: `{ error, code, suggestions? }`)
87
+ - `--json`: Output as typed JSON envelope: `{ apiVersion, type, data, meta? }` (errors: `{ apiVersion, error, code, suggestions? }`)
88
88
  - `--detail <level>`: Detail level for list views, increasing in size: `brief` (names only, default for `--list`) < `compact` (names + 1-line descriptions) < `full` (full docs per entry). Single-item views default to `full`.
89
89
  - `--zh`: Output docs in Chinese Simplified
90
90
  - `--dense`: Compressed format (token-efficient, useful for AI agents)
@@ -95,13 +95,14 @@ These flags work with any command:
95
95
  Every command supports `--json` for machine-readable output. Responses are typed envelopes:
96
96
 
97
97
  ```json
98
- {"type": "component.detail", "data": {"name": "Button", ...}}
98
+ {"apiVersion": 1, "type": "component.detail", "data": {"name": "Button", ...}}
99
99
  ```
100
100
 
101
101
  Errors:
102
102
 
103
103
  ```json
104
104
  {
105
+ "apiVersion": 1,
105
106
  "error": "No component named \"Buttn\"",
106
107
  "code": "ERR_UNKNOWN_COMPONENT",
107
108
  "suggestions": [{"name": "Button", "reason": "similar name"}]
@@ -175,7 +176,7 @@ if (isError(result)) {
175
176
  | `ERR_NO_SOURCE` | No source file could be located for the requested component/template. |
176
177
  | `ERR_INVALID_DOC` | A component's docs failed validation (malformed `.doc.mjs`). |
177
178
  | `ERR_FILE_NOT_FOUND` | A required input file did not exist. |
178
- | `ERR_FILE_EXISTS` | Refused to overwrite an existing file in non-interactive mode. |
179
+ | `ERR_FILE_EXISTS` | Refused to overwrite an existing file. |
179
180
  | `ERR_PATH_TRAVERSAL` | A path escaped its allowed root, or a name contained traversal markers. |
180
181
  | `ERR_WRITE_FAILED` | Writing output files failed (and was rolled back). |
181
182
  | `ERR_THEME_INVALID` | A theme definition or contributed theme catalog is invalid. |
@@ -199,8 +200,9 @@ if (isError(result)) {
199
200
 
200
201
  Agents don't have to scrape `--help` to learn the CLI. A single call returns a
201
202
  **self-describing manifest**: every command, its arguments, flags (with types,
202
- choices, and defaults), whether it supports `--json`, and the response `type`
203
- discriminators each command can emit. Think of it as an OpenAPI spec for the CLI.
203
+ choices, and defaults), whether it supports `--json`, the response `type`
204
+ discriminators each command can emit, and its documented exit codes. Think of it
205
+ as an OpenAPI spec for the CLI.
204
206
 
205
207
  ```bash
206
208
  astryx manifest --json # dedicated surface — type: "manifest"
@@ -262,6 +264,10 @@ Shape:
262
264
  "…",
263
265
  ],
264
266
  "examples": ["astryx component Button --props --json"],
267
+ "exitCodes": [
268
+ {"code": 0, "when": "success"},
269
+ {"code": 1, "when": "…"},
270
+ ],
265
271
  },
266
272
  // …one entry per command; subcommands (e.g. `theme build`) nest under `subcommands`
267
273
  ],
@@ -343,9 +349,9 @@ import type {
343
349
  // ...import the response types for the commands you consume
344
350
  } from '@astryxdesign/cli/json';
345
351
 
346
- // parseResponse returns the structural { type, data, meta? } envelope; `data`
347
- // is `unknown` until you narrow it. Reconstruct the union you care about from
348
- // the per-command response types, then narrow on `type`:
352
+ // parseResponse returns the structural { apiVersion, type, data, meta? }
353
+ // envelope; `data` is `unknown` until you narrow it. Reconstruct the union you
354
+ // care about from the per-command response types, then narrow on `type`:
349
355
  type MyResponse =
350
356
  ComponentDetailResponse | ComponentListResponse | DocsListResponse;
351
357
 
@@ -412,7 +418,7 @@ Every response has a `type` discriminant. The full set is below (generated from
412
418
  | `discover.detail.doc` | The validated ComponentDoc for one external component: an @scope/name/Component query, or a free-text term resolving to exactly one component. |
413
419
  | `discover.search` | The echoed query plus the matching {package, component} pairs, when a free-text term matches several components. |
414
420
  | `search` | The echoed query, `matchCount` (how many candidates matched in total, before `limit`), plus a ranked SearchResultEntry[] bounded by `limit` (domain, name, score, reason, description, follow-up command, and import path where relevant). |
415
- | `build.help` | A marker (`playbook: true`) that the renderer expands into the how-to-build-a-page workflow; emitted when no query is given. |
421
+ | `build.help` | The how-to-build-a-page playbook, emitted when no query is given: `playbook: true`, a title, the ordered steps (title, commands, optional returns), the on-system rules, and related lookups. Commands are bare subcommands for the caller to render with its own invocation. |
416
422
  | `build.kit` | The grouped composition kit: echoed query, hasResults/matchCount/directMatch fields (matchCount is the total matched, never a cap read back), the closest page templates, drop-in block patterns, idea-specific components/hooks, and the always-on frame + foundation component-name arrays. |
417
423
  | `swizzle.list` | The names of swizzlable components discoverable from cwd's @astryxdesign/core. |
418
424
  | `swizzle.copy` | An eject receipt: component name, owning package, output directory, files-copied count, the written file names, whether any file uses StyleX, and an optional maintainer note. |
@@ -426,7 +432,7 @@ Every response has a `type` discriminant. The full set is below (generated from
426
432
  | `hook.list` | The hook catalog grouped by category: `detail` (the level: names \| compact \| full) and `components`, the grouped map of hook names, brief entries, or a full HookDoc per entry. |
427
433
  | `hook.detail` | One hook's full authored HookDoc. |
428
434
  | `hook.detail.params` | Just one hook's parameters table (HookParamDoc[]). |
429
- | `theme.build` | A theme build receipt: name, token- and component-override counts, output size, the written outputs {css, js, dts, and variantsDts when applicable}, and any validation warnings. |
435
+ | `theme.build` | A theme build receipt: name, tokenCount and componentCount (override counts), sizeKB, the written outputs {css, js, dts, and variantsDts when applicable}, warnings (defects to fix), and notices (advisories about a correct theme, such as a named font it does not load). |
430
436
  | `theme.build.check` | The --check receipt: theme name, an upToDate flag, the stale outputs (each {path, reason: missing \| outdated}), and the full list of checked paths. Writes nothing. |
431
437
  | `theme.build.batch` | Several themes built in one invocation: `count` plus one {file, receipt} per theme in argument order, where receipt is that theme's theme.build (or theme.build.check) envelope, or null when it produced no CSS. |
432
438
  | `theme.list` | Every bundled or installed integration theme as a ThemeListEntry[]: each with slug, displayName, description, maintained flag, and owner package. |
@@ -437,7 +443,7 @@ Every response has a `type` discriminant. The full set is below (generated from
437
443
  | `upgrade.list` | Every available codemod, oldest→newest, as {name, title, version, optional}; returned for --list without running anything. |
438
444
  | `upgrade.status` | A short-circuit outcome with no codemods run (up_to_date, no_codemods, or config_fixable), each carrying the agent-docs summary. |
439
445
  | `upgrade.run` | The run receipt: from/to versions, codemod count, integrations processed, the agent-docs summary, and (apply mode) filesChanged, transformsApplied, and per-codemod errors. |
440
- | `manifest` | The self-describing CLI capability manifest: name, version, apiVersion, global options, the command tree (args, options, json flag, response types, examples), the jsonSupported allowlist, and the flat responseTypes index. |
446
+ | `manifest` | The CLI capability manifest: name, version, apiVersion, description, globalOptions, commands (each name, description, arguments, options, json, aliases?, responseTypes?, examples?, exitCodes? as [{code, when}], subcommands?), jsonSupported, and the flat responseTypes index. |
441
447
  | `doctor` | The health-check report: `checks` (each with id, label, status: pass \| warn \| fail \| info, a message, and a fix when not passing) plus a `summary` of counts per status. |
442
448
  | `integration.add` | A contribution-writer receipt: kind, name, optional root {path, created}, integration-manifest path, every affected project-relative path, written, and dryRun. |
443
449
  | `integration.pack-check` | The packed-package check: package identity, tarball facts, local and packed contribution inventories, and issues. |
@@ -456,25 +462,33 @@ Every response has a `type` discriminant. The full set is below (generated from
456
462
 
457
463
  `astryx doctor` runs read-only health checks against your project and
458
464
  environment. Each record uses `[ok]`, `[warn]`, `[fail]`, or `[info]`, and
459
- includes an actionable `fix` when one is available. The exact checks and values
460
- depend on the project; the output shape is stable:
465
+ includes an actionable `fix` when one is available. Field names match the
466
+ `--json` keys. The exact checks and values depend on the project; the output
467
+ shape is stable:
461
468
 
462
469
  ```
463
470
  $ astryx doctor
464
471
  astryx doctor - diagnosing your setup
465
472
 
473
+ id: node-version
466
474
  status: [ok]
467
- check: Node.js version
475
+ label: Node.js version
468
476
  message: Node v24.18.1 meets the minimum (>=22.13.0).
469
477
 
478
+ id: themes
470
479
  status: [warn]
471
- check: Theme packages
480
+ label: Theme packages
472
481
  message: No @astryxdesign/theme-* packages are installed.
473
482
  fix: Install a theme, e.g. `npm install @astryxdesign/theme-neutral`, then import its CSS or set astryx.theme.
474
483
 
475
484
  ...
476
485
 
477
- Summary: 4 passed, 2 warnings, 0 failures, 2 info
486
+ summary
487
+
488
+ pass: 4
489
+ warn: 2
490
+ fail: 0
491
+ info: 2
478
492
 
479
493
  No failures - but review the [warn] warnings above when you can.
480
494
  ```
@@ -16,8 +16,8 @@ export const doc = {
16
16
  'Page-building assistant: the how-to-build playbook, or a composition kit for an idea.',
17
17
  description:
18
18
  'The "assemble a page" entry point. Called with no query it returns the ' +
19
- 'playbook signal that the renderer expands into the how-to-build-a-page ' +
20
- 'workflow. Called with a query it runs the unified search and groups the ' +
19
+ 'how-to-build-a-page playbook as data: the workflow steps with their ' +
20
+ 'commands, the on-system rules, and related lookups. Called with a query it runs the unified search and groups the ' +
21
21
  'hits into a composition KIT: the closest page templates, drop-in blocks, ' +
22
22
  'and idea-specific components/hooks, plus the always-on frame + foundation.',
23
23
  importPath: '@astryxdesign/cli/api',
@@ -54,7 +54,7 @@ export const doc = {
54
54
  {
55
55
  type: 'build.help',
56
56
  description:
57
- 'Emitted when the query is omitted: a pure marker (`data.playbook: true`) that the command renderer expands into the page-building workflow prose.',
57
+ 'Emitted when the query is omitted: the page-building playbook — `playbook: true`, a `title`, the ordered `steps` (each a `title`, its `commands`, and optionally what the step `returns`), the on-system `rules`, and `related` lookups. Each command is a bare subcommand ({command, purpose?}) for the caller to render with its own CLI invocation.',
58
58
  },
59
59
  {
60
60
  type: 'build.kit',
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file Tests for the build API (playbook signal + composition kit).
4
+ * @file Tests for the build API (playbook + composition kit).
5
5
  */
6
6
 
7
7
  import {describe, it, expect, vi} from 'vitest';
@@ -20,10 +20,21 @@ const REPO = path.resolve(
20
20
  vi.setConfig({testTimeout: 30000});
21
21
 
22
22
  describe('build API', () => {
23
- it('no query → build.help playbook signal', async () => {
23
+ it('no query → build.help carries the playbook as data', async () => {
24
24
  const r = await build();
25
25
  expect(r.type).toBe('build.help');
26
- expect(r.data).toEqual({playbook: true});
26
+ if (r.type !== 'build.help') return;
27
+ expect(r.data.playbook).toBe(true);
28
+ expect(r.data.title).toMatch(/build a page/i);
29
+ expect(r.data.steps.length).toBeGreaterThan(0);
30
+ for (const step of r.data.steps) {
31
+ expect(step.title).toBeTruthy();
32
+ expect(step.commands.length).toBeGreaterThan(0);
33
+ }
34
+ expect(r.data.rules.length).toBeGreaterThan(0);
35
+ // Bare subcommands: the caller adds its own invocation.
36
+ const commands = [...r.data.steps.flatMap(s => s.commands), ...r.data.related];
37
+ for (const {command} of commands) expect(command).not.toMatch(/^(astryx|npx|pnpm|yarn|bunx?)\b/);
27
38
  });
28
39
 
29
40
  it('query → build.kit with raw entries + static frame/foundation', async () => {
@@ -2,12 +2,46 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * astryx --json build (no query) — the "how to build a page" playbook signal.
5
+ * A command the playbook tells the caller to run.
6
+ */
7
+ export type BuildPlaybookCommand = {
8
+ /**
9
+ * Bare subcommand with `<placeholder>` arguments (e.g. `template <name> --skeleton`) and no package-manager prefix — render it with your own CLI invocation.
10
+ */
11
+ command: string;
12
+ /**
13
+ * What running it is for.
14
+ */
15
+ purpose?: string | undefined;
16
+ };
17
+ /**
18
+ * One step of the page-building workflow.
19
+ */
20
+ export type BuildPlaybookStep = {
21
+ /**
22
+ * What to do.
23
+ */
24
+ title: string;
25
+ /**
26
+ * The commands for this step, in the order to run them.
27
+ */
28
+ commands: BuildPlaybookCommand[];
29
+ /**
30
+ * What the step's command gives back, when that decides the next step.
31
+ */
32
+ returns?: string | undefined;
33
+ };
34
+ /**
35
+ * astryx --json build (no query) — the "how to build a page" playbook.
6
36
  */
7
37
  export type BuildHelpResponse = {
8
38
  type: "build.help";
9
39
  data: {
10
40
  playbook: true;
41
+ title: string;
42
+ steps: BuildPlaybookStep[];
43
+ rules: string[];
44
+ related: BuildPlaybookCommand[];
11
45
  };
12
46
  };
13
47
  /**
@@ -2,17 +2,38 @@
2
2
 
3
3
  /**
4
4
  * @file Colocated types for the `build` command — source of truth for the
5
- * `build.help` (playbook signal) and `build.kit` (composition kit) JSON
6
- * responses. Re-exported by types/build.d.ts.
5
+ * `build.help` (playbook) and `build.kit` (composition kit) JSON responses.
6
+ * Re-exported by types/build.d.ts.
7
7
  */
8
8
 
9
9
  /**
10
- * astryx --json build (no query) — the "how to build a page" playbook signal.
10
+ * A command the playbook tells the caller to run.
11
+ *
12
+ * @typedef {object} BuildPlaybookCommand
13
+ * @property {string} command Bare subcommand with `<placeholder>` arguments (e.g. `template <name> --skeleton`) and no package-manager prefix — render it with your own CLI invocation.
14
+ * @property {string} [purpose] What running it is for.
15
+ */
16
+
17
+ /**
18
+ * One step of the page-building workflow.
19
+ *
20
+ * @typedef {object} BuildPlaybookStep
21
+ * @property {string} title What to do.
22
+ * @property {BuildPlaybookCommand[]} commands The commands for this step, in the order to run them.
23
+ * @property {string} [returns] What the step's command gives back, when that decides the next step.
24
+ */
25
+
26
+ /**
27
+ * astryx --json build (no query) — the "how to build a page" playbook.
11
28
  *
12
29
  * @typedef {object} BuildHelpResponse
13
30
  * @property {'build.help'} type
14
31
  * @property {object} data
15
32
  * @property {true} data.playbook Always true; marks this envelope as the playbook rather than a result set.
33
+ * @property {string} data.title The playbook's heading.
34
+ * @property {BuildPlaybookStep[]} data.steps The workflow, in order.
35
+ * @property {string[]} data.rules The rules that keep a page on-system.
36
+ * @property {BuildPlaybookCommand[]} data.related Lookups to reach for alongside the workflow.
16
37
  */
17
38
 
18
39
  /**
@@ -2,14 +2,17 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * @file build.help leaf — the "how to build a page" playbook signal.
5
+ * @file build.help leaf — the "how to build a page" playbook.
6
6
  *
7
- * `build` with no query returns this envelope: a pure marker that the command
8
- * renderer expands into the workflow playbook prose. It carries no data beyond
9
- * `playbook: true`, so the JSON shape stays environment-agnostic and stable.
7
+ * `build` with no query returns this envelope. The playbook is data — steps,
8
+ * rules, and related lookups — so a `--json` or programmatic caller gets the
9
+ * same guidance the terminal shows. Commands are bare subcommands with no
10
+ * package-manager prefix, which keeps the JSON environment-agnostic; the CLI
11
+ * renders each one with the caller's invocation, as it does build.kit's
12
+ * `hint.commands`.
10
13
  */
11
14
  /**
12
- * The page-building playbook signal (emitted when `build` runs with no query).
15
+ * The page-building playbook (emitted when `build` runs with no query).
13
16
  *
14
17
  * @returns {import('../build.type.mjs').BuildHelpResponse}
15
18
  */
@@ -1,18 +1,68 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file build.help leaf — the "how to build a page" playbook signal.
4
+ * @file build.help leaf — the "how to build a page" playbook.
5
5
  *
6
- * `build` with no query returns this envelope: a pure marker that the command
7
- * renderer expands into the workflow playbook prose. It carries no data beyond
8
- * `playbook: true`, so the JSON shape stays environment-agnostic and stable.
6
+ * `build` with no query returns this envelope. The playbook is data — steps,
7
+ * rules, and related lookups — so a `--json` or programmatic caller gets the
8
+ * same guidance the terminal shows. Commands are bare subcommands with no
9
+ * package-manager prefix, which keeps the JSON environment-agnostic; the CLI
10
+ * renders each one with the caller's invocation, as it does build.kit's
11
+ * `hint.commands`.
9
12
  */
10
13
 
11
14
  /**
12
- * The page-building playbook signal (emitted when `build` runs with no query).
15
+ * The page-building playbook (emitted when `build` runs with no query).
13
16
  *
14
17
  * @returns {import('../build.type.mjs').BuildHelpResponse}
15
18
  */
16
19
  export function buildHelp() {
17
- return {type: 'build.help', data: {playbook: true}};
20
+ return {
21
+ type: 'build.help',
22
+ data: {
23
+ playbook: true,
24
+ title: 'How to build a page with Astryx',
25
+ steps: [
26
+ {
27
+ title: "Find a starting point for what you're building",
28
+ commands: [{command: 'build "<what you\'re building>"'}],
29
+ returns:
30
+ 'the closest [page] template, the [block]s that cover parts, and the [component]s to fill the gaps, with a recommended start',
31
+ },
32
+ {
33
+ title: 'If a [page] template matches, scaffold it and adapt',
34
+ commands: [{command: 'template <name> [path]'}],
35
+ },
36
+ {
37
+ title: 'If nothing matches exactly, compose',
38
+ commands: [
39
+ {
40
+ command: 'template <name> --skeleton',
41
+ purpose: "study a close page's layout",
42
+ },
43
+ {
44
+ command: 'template <BlockName>',
45
+ purpose: 'drop in each block from the kit',
46
+ },
47
+ {
48
+ command: 'component <Name>',
49
+ purpose: 'fill remaining gaps (read props)',
50
+ },
51
+ ],
52
+ },
53
+ ],
54
+ rules: [
55
+ 'No <div>/raw HTML for layout — use VStack/HStack/Grid/Stack/Card etc.',
56
+ 'No style={{}} — use component props, and design tokens for values.',
57
+ 'Wrap the app in <Theme theme={...}> and import core reset.css + astryx.css.',
58
+ ],
59
+ related: [
60
+ {command: 'docs tokens', purpose: 'the design tokens'},
61
+ {
62
+ command: 'search <query>',
63
+ purpose: 'a neutral lookup of any component, doc, or template',
64
+ },
65
+ ],
66
+ },
67
+ };
18
68
  }
@@ -91,7 +91,8 @@ export const doc = {
91
91
  {
92
92
  name: 'options.lang',
93
93
  type: 'string',
94
- description: 'Language code for localized doc content.',
94
+ description:
95
+ "Language code for localized doc content: 'en', 'zh', or 'dense'.",
95
96
  },
96
97
  {
97
98
  name: 'options.zh',
@@ -113,7 +114,7 @@ export const doc = {
113
114
  {
114
115
  type: 'component.detail',
115
116
  description:
116
- "One component's authored ComponentDoc plus ownership metadata (owner package, import specifier, whether source is available).",
117
+ "One component's authored ComponentDoc plus ownership metadata (owner package, import specifier, whether source is available). When the name is a sub-component documented in a parent's doc, the payload is scoped to it and parentDoc names that parent.",
117
118
  },
118
119
  {
119
120
  type: 'component.detail.props',
@@ -135,6 +136,14 @@ export const doc = {
135
136
  },
136
137
  ],
137
138
  throws: [
139
+ {
140
+ code: 'ERR_INVALID_DETAIL',
141
+ when: "options.detail is not 'full', 'compact', or 'brief'",
142
+ },
143
+ {
144
+ code: 'ERR_INVALID_LANG',
145
+ when: "options.lang is set to anything other than 'en', 'zh', or 'dense'",
146
+ },
138
147
  {
139
148
  code: 'ERR_CORE_NOT_FOUND',
140
149
  when: '@astryxdesign/core cannot be resolved from cwd',
@@ -34,6 +34,11 @@ import {componentDetailSource} from './detail/source/source.mjs';
34
34
  import {componentDetailShowcase} from './detail/showcase/showcase.mjs';
35
35
  import {componentDetailBlocks} from './detail/blocks/blocks.mjs';
36
36
 
37
+ /** @type {ReadonlyArray<string>} */
38
+ const DETAIL_LEVELS = ['full', 'compact', 'brief'];
39
+ /** @type {ReadonlyArray<string>} */
40
+ const LANGS = ['en', 'zh', 'dense'];
41
+
37
42
  /**
38
43
  * @param {string} [name]
39
44
  * @param {object} [options]
@@ -81,6 +86,23 @@ export async function component(name, options = {}) {
81
86
  const isListView = list || category != null || !name;
82
87
  const detail = detailOption ?? (isListView ? 'brief' : 'full');
83
88
 
89
+ // Same accepted values and codes as the CLI's --detail and --lang, checked
90
+ // first as the CLI parser does.
91
+ if (!DETAIL_LEVELS.includes(detail)) {
92
+ throw new AstryxError(
93
+ `Invalid detail "${String(detail)}". Valid levels: ${DETAIL_LEVELS.join(', ')}`,
94
+ undefined,
95
+ ERROR_CODES.ERR_INVALID_DETAIL,
96
+ );
97
+ }
98
+ if (lang != null && !LANGS.includes(lang)) {
99
+ throw new AstryxError(
100
+ `Invalid lang "${String(lang)}". Valid values: ${LANGS.join(', ')}`,
101
+ undefined,
102
+ ERROR_CODES.ERR_INVALID_LANG,
103
+ );
104
+ }
105
+
84
106
  const coreDir = requireCoreDir(cwd);
85
107
 
86
108
  // A public API caller could pass a non-string category; the list leaf does
@@ -156,6 +178,13 @@ export async function component(name, options = {}) {
156
178
  }
157
179
  const extDocPath = resolveLegacyExternalDoc(scoped.ext, dirName);
158
180
  if (extDocPath) {
181
+ // Legacy packages ship docs, never source.
182
+ if (source) {
183
+ return componentDetailSource(dirName, null, {name, notFoundInPackage: packageScope});
184
+ }
185
+ if (blocks) {
186
+ return componentDetailBlocks(dirName);
187
+ }
159
188
  const docs = await loadComponentDoc(extDocPath, docOpts);
160
189
  if (props) return componentDetailProps(docs);
161
190
  return componentDetail(docs, {package: scoped.ext.name, sourcePath: null}, dirName, coreDir);
@@ -14,6 +14,7 @@ import * as path from 'node:path';
14
14
  import {fileURLToPath} from 'node:url';
15
15
  import {component} from './component.mjs';
16
16
  import {AstryxError} from '../error.mjs';
17
+ import {runCli} from '../../test-utils/run-cli.mjs';
17
18
 
18
19
  // api/component/ -> up 4 = repo root (has packages/core, which findCoreDir walks to).
19
20
  const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../..');
@@ -161,3 +162,40 @@ describe('component dispatcher — category guard', () => {
161
162
  }
162
163
  }, SLOW);
163
164
  });
165
+
166
+ describe('component dispatcher — detail and lang guards', () => {
167
+ // `detail` and `lang` are the same controls as the CLI's --detail and --lang:
168
+ // same accepted values, same error codes.
169
+ it('rejects a detail level the CLI rejects, with the same code', async () => {
170
+ const cliRun = await runCli(['--json', 'component', '--list', '--detail', 'bogus'], cwd);
171
+ expect(cliRun.code).toBe(1);
172
+ expect(JSON.parse(cliRun.stdout).code).toBe('ERR_INVALID_DETAIL');
173
+
174
+ const bogus = /** @type {any} */ ('bogus');
175
+ for (const call of [
176
+ () => component(undefined, {cwd, list: true, detail: bogus}),
177
+ () => component('Button', {cwd, detail: bogus}),
178
+ ]) {
179
+ const err = await call().catch(e => e);
180
+ expect(err).toBeInstanceOf(AstryxError);
181
+ expect(err.code).toBe('ERR_INVALID_DETAIL');
182
+ }
183
+ }, SLOW);
184
+
185
+ it('rejects a lang the CLI rejects, with the same code', async () => {
186
+ const cliRun = await runCli(['--json', 'component', 'Button', '--lang', 'fr'], cwd);
187
+ expect(cliRun.code).toBe(1);
188
+ expect(JSON.parse(cliRun.stdout).code).toBe('ERR_INVALID_LANG');
189
+
190
+ for (const call of [
191
+ () => component('Button', {cwd, lang: 'fr'}),
192
+ () => component(undefined, {cwd, list: true, detail: 'compact', lang: 'fr'}),
193
+ ]) {
194
+ const err = await call().catch(e => e);
195
+ expect(err).toBeInstanceOf(AstryxError);
196
+ expect(err.code).toBe('ERR_INVALID_LANG');
197
+ }
198
+ const zh = await component('Button', {cwd, lang: 'zh'});
199
+ expect(zh.type).toBe('component.detail');
200
+ }, SLOW);
201
+ });
@@ -59,7 +59,17 @@ export type ComponentBriefEntry = {
59
59
  */
60
60
  export type ComponentDetailResponse = {
61
61
  type: "component.detail";
62
- data: import("@astryxdesign/cli/authoring").ComponentDoc & ComponentOwnership;
62
+ data: import("@astryxdesign/cli/authoring").ComponentDoc & ComponentOwnership & ComponentDetailScope;
63
+ };
64
+ /**
65
+ * Present only when the requested name is a sub-component documented inside a
66
+ * parent's doc (e.g. `HStack` in the `Stack` doc); the payload is scoped to it.
67
+ */
68
+ export type ComponentDetailScope = {
69
+ /**
70
+ * - Name of the parent doc the payload was scoped from, e.g. 'Stack'.
71
+ */
72
+ parentDoc?: string | undefined;
63
73
  };
64
74
  /**
65
75
  * Ownership metadata attached to every `component.detail` payload. Exposes the
@@ -73,7 +73,14 @@
73
73
  * astryx --json component <name>
74
74
  * @typedef {object} ComponentDetailResponse
75
75
  * @property {'component.detail'} type
76
- * @property {import('@astryxdesign/cli/authoring').ComponentDoc & ComponentOwnership} data
76
+ * @property {import('@astryxdesign/cli/authoring').ComponentDoc & ComponentOwnership & ComponentDetailScope} data
77
+ */
78
+
79
+ /**
80
+ * Present only when the requested name is a sub-component documented inside a
81
+ * parent's doc (e.g. `HStack` in the `Stack` doc); the payload is scoped to it.
82
+ * @typedef {object} ComponentDetailScope
83
+ * @property {string} [parentDoc] - Name of the parent doc the payload was scoped from, e.g. 'Stack'.
77
84
  */
78
85
 
79
86
  /**
@@ -41,7 +41,7 @@ export const doc = {
41
41
  name: 'options.components',
42
42
  type: 'boolean',
43
43
  description:
44
- 'List components only. A CLI display flag consumed by the renderer; the programmatic response shape is unchanged.',
44
+ 'In the CLI package list, print every component of each package instead of the first 10. A display flag for the CLI renderer; the programmatic response is unchanged.',
45
45
  },
46
46
  {
47
47
  name: 'options.lang',
@@ -32,17 +32,19 @@ export const doc = {
32
32
  name: 'component',
33
33
  type: 'string',
34
34
  description:
35
- 'Component or general design-system area. Required unless listCategories is true.',
35
+ 'Component or general design-system area, up to 120 characters. Required unless listCategories is true.',
36
36
  },
37
37
  {
38
38
  name: 'options.category',
39
39
  type: 'GapReportCategory',
40
- description: 'Fixed category from the reported category vocabulary.',
40
+ description:
41
+ 'Fixed category from the reported category vocabulary. Required unless listCategories is true.',
41
42
  },
42
43
  {
43
44
  name: 'options.reason',
44
45
  type: 'string',
45
- description: 'What capability was missing or difficult.',
46
+ description:
47
+ 'What capability was missing or difficult, up to 2000 characters. Required unless listCategories is true.',
46
48
  },
47
49
  {
48
50
  name: 'options.detail',
@@ -65,7 +67,8 @@ export const doc = {
65
67
  {
66
68
  name: 'options.listCategories',
67
69
  type: 'boolean',
68
- description: 'Return categories without resolving a route or writing.',
70
+ description:
71
+ 'Return categories without resolving a route or writing; the component and every other option are ignored.',
69
72
  default: 'false',
70
73
  },
71
74
  {
@@ -90,6 +90,10 @@ export const doc = {
90
90
  code: 'ERR_FILE_EXISTS',
91
91
  when: 'scaffolding a template would overwrite an existing page.tsx',
92
92
  },
93
+ {
94
+ code: 'ERR_PATH_TRAVERSAL',
95
+ when: 'the template output path resolves outside cwd, for example through a symlinked src directory',
96
+ },
93
97
  ],
94
98
  examples: [
95
99
  {label: 'Default setup', code: 'const r = await init();'},