@astryxdesign/cli 0.7.14-canary.gfb823d9 → 0.7.14

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 (135) hide show
  1. package/CHANGELOG.md +197 -0
  2. package/api/component/_adapter.d.mts +15 -0
  3. package/api/component/_adapter.mjs +76 -0
  4. package/api/component/component.mjs +8 -1
  5. package/api/search/_named-keywords.d.mts +31 -0
  6. package/api/search/_named-keywords.mjs +177 -0
  7. package/api/search/search-index.mjs +8 -1
  8. package/api/search/search.d.mts +6 -1
  9. package/api/search/search.mjs +49 -8
  10. package/api/theme/_adapter.d.mts +33 -0
  11. package/api/theme/_adapter.mjs +352 -16
  12. package/api/theme/build/build.mjs +261 -10
  13. package/api/theme/eject/eject.mjs +13 -1
  14. package/api/theme/list/list.mjs +11 -2
  15. package/api/theme/palette/generate/color.d.mts +2 -0
  16. package/api/theme/palette/generate/color.mjs +1 -1
  17. package/api/theme/template/template.mjs +139 -6
  18. package/api/theme/theme.type.d.mts +15 -1
  19. package/api/theme/theme.type.mjs +9 -3
  20. package/api/theme/themeAdd.doc.mjs +1 -1
  21. package/api/theme/themeBuild.doc.mjs +10 -2
  22. package/api/theme/themeEject.doc.mjs +2 -2
  23. package/api/theme/themeListAvailable.doc.mjs +1 -1
  24. package/api/theme/themeRemove.doc.mjs +1 -1
  25. package/api/theme/themeTemplate.doc.mjs +8 -0
  26. package/api/theme/themeUse.doc.mjs +1 -1
  27. package/api/theme-edit/_adapter.d.mts +36 -2
  28. package/api/theme-edit/_adapter.mjs +340 -12
  29. package/api/theme-edit/_check.d.mts +28 -25
  30. package/api/theme-edit/_check.mjs +876 -308
  31. package/api/theme-edit/_color.d.mts +53 -4
  32. package/api/theme-edit/_color.mjs +406 -79
  33. package/api/theme-edit/_compiler.d.mts +14 -6
  34. package/api/theme-edit/_compiler.mjs +89 -59
  35. package/api/theme-edit/_context.d.mts +28 -8
  36. package/api/theme-edit/_context.mjs +142 -19
  37. package/api/theme-edit/_edit.d.mts +3 -1
  38. package/api/theme-edit/_edit.mjs +746 -76
  39. package/api/theme-edit/_how-commands.d.mts +91 -0
  40. package/api/theme-edit/_how-commands.mjs +269 -0
  41. package/api/theme-edit/_how-question.d.mts +57 -0
  42. package/api/theme-edit/_how-question.mjs +2574 -0
  43. package/api/theme-edit/_how.d.mts +27 -8
  44. package/api/theme-edit/_how.mjs +776 -175
  45. package/api/theme-edit/_overview.d.mts +9 -0
  46. package/api/theme-edit/_overview.mjs +296 -0
  47. package/api/theme-edit/_palette.d.mts +155 -15
  48. package/api/theme-edit/_palette.mjs +1446 -262
  49. package/api/theme-edit/_parts.mjs +61 -5
  50. package/api/theme-edit/_png.d.mts +18 -6
  51. package/api/theme-edit/_png.mjs +135 -25
  52. package/api/theme-edit/_preview-app.d.mts +32 -11
  53. package/api/theme-edit/_preview-app.mjs +1976 -285
  54. package/api/theme-edit/_preview.d.mts +39 -8
  55. package/api/theme-edit/_preview.mjs +367 -41
  56. package/api/theme-edit/_settings.d.mts +147 -11
  57. package/api/theme-edit/_settings.mjs +908 -99
  58. package/api/theme-edit/_tables.d.mts +4 -16
  59. package/api/theme-edit/_tables.mjs +51 -117
  60. package/api/theme-edit/theme-edit.type.d.mts +102 -66
  61. package/api/theme-edit/theme-edit.type.mjs +58 -40
  62. package/api/theme-edit/themeEditHow.doc.mjs +17 -6
  63. package/api/theme-edit/themeEditNew.doc.mjs +21 -5
  64. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +18 -5
  65. package/api/theme-edit/themeEditPreviewApp.doc.mjs +12 -9
  66. package/api/theme-edit/themeEditPreviewList.doc.mjs +11 -2
  67. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +29 -3
  68. package/api/theme-edit/themeEditSet.doc.mjs +14 -8
  69. package/api/theme-edit/themeEditShow.doc.mjs +10 -5
  70. package/api/theme-edit/themeEditUndo.doc.mjs +9 -4
  71. package/assets/discover/official-packages.json +4 -0
  72. package/assets/docs/tree/icon-sets.doc.mjs +3 -3
  73. package/assets/docs.generated.json +1 -0
  74. package/assets/icons/definitions/bookmarkAdd.doc.mjs +9 -0
  75. package/assets/icons/definitions/documentSearch.doc.mjs +9 -0
  76. package/assets/icons/definitions/keyboard.doc.mjs +9 -0
  77. package/assets/icons/definitions/paintBrush.doc.mjs +9 -0
  78. package/assets/icons/definitions/wallet.doc.mjs +9 -0
  79. package/assets/preview-app/gitignore +3 -0
  80. package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.doc.mjs +1 -1
  81. package/assets/templates/blocks/components/Lightbox/LightboxGallery.tsx +1 -1
  82. package/assets/templates/components.generated.json +1 -0
  83. package/assets/templates/pages/gallery-hero/page.tsx +8 -2
  84. package/assets/templates/pages/settings-dialog/template.doc.mjs +3 -3
  85. package/assets/templates/pages/side-gallery/page.tsx +1 -1
  86. package/assets/templates/pages/table-filter/template.doc.mjs +2 -2
  87. package/assets/templates/pages/theme-showcase/template.doc.mjs +1 -1
  88. package/clients/cli/bin/astryx.mjs +37 -5
  89. package/clients/cli/commands/experimental/theme.mjs +422 -57
  90. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +22 -9
  91. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +103 -4
  92. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +13 -8
  93. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +5 -5
  94. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +5 -5
  95. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  96. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +3 -2
  97. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -8
  98. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +2 -2
  99. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  100. package/clients/cli/commands/experimental-theme-targets.doc.mjs +1 -1
  101. package/clients/cli/commands/experimental-theme.doc.mjs +3 -4
  102. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  103. package/clients/cli/commands/theme-eject.doc.mjs +3 -3
  104. package/clients/cli/commands/theme-remove.doc.mjs +2 -2
  105. package/clients/cli/commands/theme-template.doc.mjs +11 -4
  106. package/clients/cli/commands/theme.mjs +145 -46
  107. package/clients/cli/commands.generated.json +1 -0
  108. package/clients/cli/index.mjs +96 -5
  109. package/clients/cli/lib/json-shim.mjs +29 -1
  110. package/foundation/config/project.d.mts +16 -2
  111. package/foundation/config/project.mjs +40 -6
  112. package/foundation/config/theme-state.d.mts +9 -0
  113. package/foundation/config/theme-state.mjs +20 -1
  114. package/foundation/discovery/template-adapter.d.mts +12 -1
  115. package/foundation/discovery/template-adapter.mjs +29 -4
  116. package/foundation/discovery/template-icons.d.mts +13 -0
  117. package/foundation/discovery/template-icons.mjs +76 -0
  118. package/foundation/discovery/template-needs.d.mts +7 -0
  119. package/foundation/discovery/template-needs.mjs +117 -8
  120. package/foundation/discovery/template-source-tree.d.mts +5 -1
  121. package/foundation/discovery/template-source-tree.mjs +6 -4
  122. package/foundation/discovery/theme-discovery.d.mts +14 -3
  123. package/foundation/discovery/theme-discovery.mjs +45 -12
  124. package/foundation/doc-compiler/import.mjs +68 -3
  125. package/foundation/doc-compiler/stored-docs.d.mts +27 -0
  126. package/foundation/doc-compiler/stored-docs.mjs +65 -0
  127. package/foundation/fs/fs-error.d.mts +17 -0
  128. package/foundation/fs/fs-error.mjs +34 -0
  129. package/foundation/response/error-codes.d.mts +3 -1
  130. package/foundation/response/error-codes.doc.mjs +13 -1
  131. package/foundation/response/error-codes.mjs +11 -1
  132. package/foundation/response/response-types.doc.mjs +6 -6
  133. package/package.json +6 -7
  134. package/clients/cli/commands/experimental-theme-palette-generate.doc.mjs +0 -73
  135. package/clients/cli/commands/experimental-theme-palette.doc.mjs +0 -37
@@ -21,14 +21,15 @@ export const doc = {
21
21
  'consumed, naming the CLI command that prints the authoritative reference for each. Read ' +
22
22
  'it, copy what you need into your own theme file, delete it. Use `theme add <slug>` to ' +
23
23
  'use an installed built theme, extend that theme for ordinary customization, or use ' +
24
- '`theme eject <slug>` for a complete source fork. Leaves an existing file untouched unless --overwrite.',
24
+ '`theme eject <slug>` for a complete source fork. The path is a .ts file, never a folder. Leaves an existing file untouched unless --overwrite, which replaces only an earlier copy of the template or a file named like a theme source (`*.theme.ts`, `*Theme.ts`, `*.template.ts`).',
25
25
  fn: 'themeTemplate',
26
26
  args: [{name: 'path', param: 'options.targetPath', required: false}],
27
27
  options: [
28
28
  {
29
29
  flag: '-f, --overwrite',
30
30
  param: 'options.overwrite',
31
- description: 'Replace an existing file',
31
+ description:
32
+ 'Replace an existing copy of the template or theme source file. Any other file, such as package.json, or a file in a folder the theme editor made, fails with ERR_FILE_EXISTS and is left as it was',
32
33
  },
33
34
  ],
34
35
  examples: [
@@ -37,8 +38,14 @@ export const doc = {
37
38
  ],
38
39
  outsideProject: 'same',
39
40
  exitCodes: [
40
- {code: 0, when: 'success, including when an existing file was left untouched'},
41
- {code: 1, when: 'the target path escapes the project, or the file cannot be written'},
41
+ {
42
+ code: 0,
43
+ when: 'success, including when an existing file was left untouched',
44
+ },
45
+ {
46
+ code: 1,
47
+ when: 'the target path escapes the project, is blank, a folder or not a .ts file, --overwrite names a file that is not a theme template or source, or the file cannot be written',
48
+ },
42
49
  ],
43
50
  related: ['theme add', 'theme eject', 'theme list', 'theme build'],
44
51
  };
@@ -106,6 +106,32 @@ import {doc as themePaletteGenerateFn} from '../../../api/theme/themePaletteGene
106
106
  /** @type {ThemeCommandWords} */
107
107
  const THEME_WORDS = {group: 'theme', build: 'build'};
108
108
 
109
+ /**
110
+ * A theme API refusal as the group that ran it words it: under
111
+ * `experimental theme`, the commands it names are that group's own (`build`
112
+ * is `compile` there). Under `theme`, the text is unchanged.
113
+ * @param {import('../../../api/error.mjs').AstryxError} err
114
+ * @param {ThemeCommandWords} [words]
115
+ */
116
+ function themeError(err, words = THEME_WORDS) {
117
+ /** @param {string} text */
118
+ const local = text =>
119
+ words.group === THEME_WORDS.group
120
+ ? text
121
+ : text.replace(
122
+ /(?<!experimental )\btheme (add|use|remove|list|build|eject|template|targets)\b/g,
123
+ (_, sub) => `${words.group} ${sub === 'build' ? words.build : sub}`,
124
+ );
125
+ return cliError(local(err.message), {
126
+ suggestions: (err.suggestions || []).map(x => ({
127
+ ...x,
128
+ name: local(x.name),
129
+ ...(x.reason ? {reason: local(x.reason)} : {}),
130
+ })),
131
+ code: err.code,
132
+ });
133
+ }
134
+
109
135
  /**
110
136
  * Path to this CLI's real entry (clients/cli/bin/astryx.mjs), resolved from
111
137
  * this module's location (clients/cli/commands/theme.mjs → ../bin/
@@ -335,8 +361,14 @@ function themeNextSteps(run, words = THEME_WORDS) {
335
361
  * @param {import('../../../api/theme/theme.type.mjs').ThemeListEntry[]} themes
336
362
  * @param {import('../../../api/theme/theme.type.mjs').ThemeUnmigratedCopy[]} [unmigratedCopies]
337
363
  * @param {ThemeCommandWords} [words]
364
+ * @param {Array<{slug: string, path: string, reason: string}>} [skippedThemes]
338
365
  */
339
- function printThemeList(themes, unmigratedCopies = [], words = THEME_WORDS) {
366
+ function printThemeList(
367
+ themes,
368
+ unmigratedCopies = [],
369
+ words = THEME_WORDS,
370
+ skippedThemes = [],
371
+ ) {
340
372
  const run = getCliInvocation();
341
373
  const more = text(
342
374
  `More themes in packages you could add: ${run} discover theme`,
@@ -381,6 +413,18 @@ function printThemeList(themes, unmigratedCopies = [], words = THEME_WORDS) {
381
413
  text(`Migrate them: ${unmigratedCopies[0].upgradeCommand}`),
382
414
  );
383
415
  }
416
+ if (skippedThemes.length > 0) {
417
+ emit(
418
+ section(
419
+ 'Skipped local themes',
420
+ `${skippedThemes.length} broken, not listed`,
421
+ ),
422
+ records(skippedThemes, {
423
+ fields: ['slug', 'path', 'reason'],
424
+ layout: 'stacked',
425
+ }),
426
+ );
427
+ }
384
428
  }
385
429
 
386
430
  /**
@@ -428,6 +472,7 @@ function printThemeApp(result) {
428
472
  },
429
473
  ),
430
474
  );
475
+ for (const note of result.data.notes ?? []) emit(text(`[note] ${note}`));
431
476
  if (!change.firstAdd) return;
432
477
  const stem = path.basename(modulePath, path.extname(modulePath));
433
478
  emit(
@@ -459,9 +504,19 @@ function printThemeEject(result, words = THEME_WORDS) {
459
504
  'entry',
460
505
  'exportName',
461
506
  'files',
507
+ 'missingPackages',
462
508
  ],
463
509
  layout: 'stacked',
464
510
  }),
511
+ ...(data.missingPackages.length > 0
512
+ ? [
513
+ text(
514
+ data.installCommand
515
+ ? `The fork imports packages this app lacks. Install them first: ${data.installCommand}`
516
+ : `The fork imports packages this app lacks: ${data.missingPackages.join(', ')}. Install them first.`,
517
+ ),
518
+ ]
519
+ : []),
465
520
  text(
466
521
  `This is a local fork. Build it with ${getCliInvocation()} ${words.group} ${words.build} ${path.join(data.outputDir, data.entry)}.`,
467
522
  ),
@@ -471,8 +526,8 @@ function printThemeEject(result, words = THEME_WORDS) {
471
526
  /**
472
527
  * The CommandDocs one copy of the theme subcommands is built from.
473
528
  * @typedef {object} ThemeCommandDocs
474
- * @property {import('@astryxdesign/cli/authoring').CommandDoc} palette
475
- * @property {import('@astryxdesign/cli/authoring').CommandDoc} paletteGenerate
529
+ * @property {import('@astryxdesign/cli/authoring').CommandDoc} [palette] - With `paletteGenerate`; a copy without them has no palette commands.
530
+ * @property {import('@astryxdesign/cli/authoring').CommandDoc} [paletteGenerate]
476
531
  * @property {import('@astryxdesign/cli/authoring').CommandDoc} build
477
532
  * @property {import('@astryxdesign/cli/authoring').CommandDoc} list
478
533
  * @property {import('@astryxdesign/cli/authoring').CommandDoc} add
@@ -544,8 +599,8 @@ export function registerTheme(program) {
544
599
  }
545
600
 
546
601
  /**
547
- * Register the theme subcommands under a group: palette (generate), build,
548
- * list, add, remove, use, eject, template and targets. `astryx theme` and the
602
+ * Register the theme subcommands under a group: palette (generate) when its
603
+ * docs are given, build, list, add, remove, use, eject, template and targets. `astryx theme` and the
549
604
  * copies under `astryx experimental theme` share these actions and their API
550
605
  * calls; `docs` and `words` give each copy its own names.
551
606
  * @param {import('commander').Command} theme the group to register under
@@ -554,7 +609,33 @@ export function registerTheme(program) {
554
609
  * @param {ThemeCommandWords} words
555
610
  */
556
611
  export function registerThemeSubcommands(theme, program, docs, words) {
557
- const palette = defineCommand(theme, docs.palette, {
612
+ if (docs.palette && docs.paletteGenerate)
613
+ registerPaletteCommands(
614
+ theme,
615
+ program,
616
+ docs.palette,
617
+ docs.paletteGenerate,
618
+ words,
619
+ );
620
+ registerThemeCommands(theme, program, docs, words);
621
+ }
622
+
623
+ /**
624
+ * Register `palette` and `palette generate` under a theme group.
625
+ * @param {import('commander').Command} theme
626
+ * @param {import('commander').Command} program
627
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} paletteDoc
628
+ * @param {import('@astryxdesign/cli/authoring').CommandDoc} generateDoc
629
+ * @param {ThemeCommandWords} words
630
+ */
631
+ function registerPaletteCommands(
632
+ theme,
633
+ program,
634
+ paletteDoc,
635
+ generateDoc,
636
+ words,
637
+ ) {
638
+ const palette = defineCommand(theme, paletteDoc, {
558
639
  action: (
559
640
  /** @type {unknown} */ options,
560
641
  /** @type {import('commander').Command} */ cmd,
@@ -578,7 +659,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
578
659
  },
579
660
  });
580
661
 
581
- defineCommand(palette, docs.paletteGenerate, {
662
+ defineCommand(palette, generateDoc, {
582
663
  fn: themePaletteGenerateFn,
583
664
  action: (
584
665
  /** @type {string} */ configPath,
@@ -594,10 +675,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
594
675
  } catch (error) {
595
676
  const err =
596
677
  /** @type {import('../../../api/error.mjs').AstryxError} */ (error);
597
- return cliError(err.message, {
598
- suggestions: err.suggestions || [],
599
- code: err.code,
600
- });
678
+ return themeError(err, words);
601
679
  }
602
680
 
603
681
  // Generating a palette computes and writes candidate files; the numbers
@@ -642,7 +720,16 @@ export function registerThemeSubcommands(theme, program, docs, words) {
642
720
  return NO_RESULT_SET;
643
721
  },
644
722
  });
723
+ }
645
724
 
725
+ /**
726
+ * Register build, list, add, remove, use, eject, template and targets.
727
+ * @param {import('commander').Command} theme
728
+ * @param {import('commander').Command} program
729
+ * @param {ThemeCommandDocs} docs
730
+ * @param {ThemeCommandWords} words
731
+ */
732
+ function registerThemeCommands(theme, program, docs, words) {
646
733
  defineCommand(theme, docs.build, {
647
734
  fn: themeBuildFn,
648
735
  action: async (
@@ -681,6 +768,19 @@ export function registerThemeSubcommands(theme, program, docs, words) {
681
768
  });
682
769
  }
683
770
 
771
+ // One file passed twice would build twice and report two themes.
772
+ const seenFiles = new Set();
773
+ for (const entry of entries) {
774
+ const key = fs.realpathSync(entry.filePath);
775
+ if (seenFiles.has(key)) {
776
+ return cliError(
777
+ `${entry.file} is given more than once. Select each theme file once.`,
778
+ {code: ERROR_CODES.ERR_THEME_INVALID},
779
+ );
780
+ }
781
+ seenFiles.add(key);
782
+ }
783
+
684
784
  // Family mode is a thin orchestration branch over the existing build API.
685
785
  // Its key is required exactly with --family, and options that describe one
686
786
  // standalone output or a long-running loop remain intentionally separate.
@@ -785,6 +885,8 @@ export function registerThemeSubcommands(theme, program, docs, words) {
785
885
  /** @type {Array<{file: string, receipt: import('../../../api/theme/theme.type.mjs').ThemeBuildResponse | import('../../../api/theme/theme.type.mjs').ThemeBuildCheckResponse | null}>} */
786
886
  const results = [];
787
887
  let stale = false;
888
+ /** @type {Map<string, string>} */
889
+ const claimedOutputs = new Map();
788
890
  for (const entry of entries) {
789
891
  try {
790
892
  const buildOptions = {
@@ -792,6 +894,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
792
894
  check: options.check,
793
895
  iconsSpecifier: options.iconsSpecifier,
794
896
  __onPrivateVarError: onPrivateVarError,
897
+ __claimedOutputs: claimedOutputs,
795
898
  };
796
899
  let result;
797
900
  if (report) {
@@ -884,7 +987,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
884
987
  },
885
988
  });
886
989
 
887
- defineCommand(theme, docs.list, {
990
+ const listCli = defineCommand(theme, docs.list, {
888
991
  fn: themeListFn,
889
992
  action: async (/** @type {{package?: string}} */ options) => {
890
993
  const json = program.opts().json || false;
@@ -898,10 +1001,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
898
1001
  } catch (e) {
899
1002
  const err =
900
1003
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
901
- return cliError(err.message, {
902
- suggestions: err.suggestions || [],
903
- code: err.code,
904
- });
1004
+ return themeError(err, words);
905
1005
  }
906
1006
 
907
1007
  await warnOnThemeIntegrationIssues(json);
@@ -914,7 +1014,12 @@ export function registerThemeSubcommands(theme, program, docs, words) {
914
1014
  return answered;
915
1015
  }
916
1016
 
917
- printThemeList(result.data, result.meta?.unmigratedCopies, words);
1017
+ printThemeList(
1018
+ result.data,
1019
+ result.meta?.unmigratedCopies,
1020
+ words,
1021
+ result.meta?.skippedThemes,
1022
+ );
918
1023
  return answered;
919
1024
  },
920
1025
  });
@@ -943,10 +1048,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
943
1048
  } catch (e) {
944
1049
  const err =
945
1050
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
946
- return cliError(err.message, {
947
- suggestions: err.suggestions || [],
948
- code: err.code,
949
- });
1051
+ return themeError(err, words);
950
1052
  }
951
1053
 
952
1054
  await warnOnThemeIntegrationIssues(json);
@@ -970,7 +1072,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
970
1072
  // Reject the removed target-path argument in Commander's standard parse path.
971
1073
  themeAddCli.allowExcessArguments(false);
972
1074
 
973
- defineCommand(theme, docs.remove, {
1075
+ const removeCli = defineCommand(theme, docs.remove, {
974
1076
  fn: themeRemoveFn,
975
1077
  action: async (/** @type {string} */ slug) => {
976
1078
  const json = program.opts().json || false;
@@ -981,10 +1083,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
981
1083
  } catch (e) {
982
1084
  const err =
983
1085
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
984
- return cliError(err.message, {
985
- suggestions: err.suggestions || [],
986
- code: err.code,
987
- });
1086
+ return themeError(err, words);
988
1087
  }
989
1088
  await warnOnThemeIntegrationIssues(json);
990
1089
  if (json) jsonOut(result);
@@ -993,7 +1092,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
993
1092
  },
994
1093
  });
995
1094
 
996
- defineCommand(theme, docs.use, {
1095
+ const useCli = defineCommand(theme, docs.use, {
997
1096
  fn: themeUseFn,
998
1097
  action: async (/** @type {string} */ slug) => {
999
1098
  const json = program.opts().json || false;
@@ -1004,10 +1103,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
1004
1103
  } catch (e) {
1005
1104
  const err =
1006
1105
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1007
- return cliError(err.message, {
1008
- suggestions: err.suggestions || [],
1009
- code: err.code,
1010
- });
1106
+ return themeError(err, words);
1011
1107
  }
1012
1108
  await warnOnThemeIntegrationIssues(json);
1013
1109
  if (json) jsonOut(result);
@@ -1016,7 +1112,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
1016
1112
  },
1017
1113
  });
1018
1114
 
1019
- defineCommand(theme, docs.eject, {
1115
+ const ejectCli = defineCommand(theme, docs.eject, {
1020
1116
  fn: themeEjectFn,
1021
1117
  action: async (
1022
1118
  /** @type {string} */ slug,
@@ -1036,10 +1132,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
1036
1132
  } catch (e) {
1037
1133
  const err =
1038
1134
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1039
- return cliError(err.message, {
1040
- suggestions: err.suggestions || [],
1041
- code: err.code,
1042
- });
1135
+ return themeError(err, words);
1043
1136
  }
1044
1137
  await warnOnThemeIntegrationIssues(json);
1045
1138
  if (json) jsonOut(result);
@@ -1048,7 +1141,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
1048
1141
  },
1049
1142
  });
1050
1143
 
1051
- defineCommand(theme, docs.template, {
1144
+ const templateCli = defineCommand(theme, docs.template, {
1052
1145
  fn: themeTemplateFn,
1053
1146
  action: (
1054
1147
  /** @type {string | undefined} */ targetPath,
@@ -1067,10 +1160,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
1067
1160
  } catch (e) {
1068
1161
  const err =
1069
1162
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1070
- return cliError(err.message, {
1071
- suggestions: err.suggestions || [],
1072
- code: err.code,
1073
- });
1163
+ return themeError(err, words);
1074
1164
  }
1075
1165
 
1076
1166
  // Writes a starter theme file, or declines to overwrite one.
@@ -1099,7 +1189,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
1099
1189
  },
1100
1190
  });
1101
1191
 
1102
- defineCommand(theme, docs.targets, {
1192
+ const targetsCli = defineCommand(theme, docs.targets, {
1103
1193
  fn: themeTargetsFn,
1104
1194
  action: async (/** @type {string | undefined} */ filter) => {
1105
1195
  const json = program.opts().json || false;
@@ -1111,10 +1201,7 @@ export function registerThemeSubcommands(theme, program, docs, words) {
1111
1201
  } catch (e) {
1112
1202
  const err =
1113
1203
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1114
- return cliError(err.message, {
1115
- suggestions: err.suggestions || [],
1116
- code: err.code,
1117
- });
1204
+ return themeError(err, words);
1118
1205
  }
1119
1206
 
1120
1207
  // A filter is a substring search with an exact-name fast path (see
@@ -1162,4 +1249,16 @@ export function registerThemeSubcommands(theme, program, docs, words) {
1162
1249
  return answered;
1163
1250
  },
1164
1251
  });
1252
+ // A stray word is refused rather than dropped: `theme use neutral dark`
1253
+ // must not report a success that ignored "dark".
1254
+ for (const cli of [
1255
+ listCli,
1256
+ removeCli,
1257
+ useCli,
1258
+ ejectCli,
1259
+ templateCli,
1260
+ targetsCli,
1261
+ ]) {
1262
+ cli.allowExcessArguments(false);
1263
+ }
1165
1264
  }
@@ -0,0 +1 @@
1
+ [{"name":"init","term":"init [options]","description":"Initialize the design system in your project"},{"name":"component","term":"component [options] [names...]","description":"List components or print component docs"},{"name":"docs","term":"docs [options] [topic] [section]","description":"Print reference docs"},{"name":"blog","term":"blog [slug]","description":"Read the Astryx blog from the published feed"},{"name":"swizzle","term":"swizzle [options] [component]","description":"Copy component source for customization"},{"name":"gap-report","term":"gap-report [options] [component]","description":"Report a missing component or feature to the package that owns it"},{"name":"template","term":"template [options] [name] [path]","description":"List, show, or scaffold page and block templates"},{"name":"upgrade","term":"upgrade [options]","description":"Update your code after upgrading Astryx, and refresh ShadCN-copied components"},{"name":"theme","term":"theme","description":"Add, switch, build, and author themes"},{"name":"integration","term":"integration","description":"Author and verify an Astryx integration package"},{"name":"hook","term":"hook [options] [name]","description":"List hooks or print hook docs"},{"name":"discover","term":"discover [options] [query]","description":"Browse and search integrations: the ones you have and the ones you could add"},{"name":"search","term":"search [options] <query...>","description":"Search components, hooks, docs, templates, and themes in one ranked list"},{"name":"build","term":"build [options] [query]","description":"Build a page: the template to start from, or the workflow playbook (no query)"},{"name":"doctor","term":"doctor [options]","description":"Diagnose Astryx projects and integration packages"},{"name":"experimental","term":"experimental","description":"[experimental] Try features that may change in a patch release: icon sets, page rendering, checked theme editing"},{"name":"manifest","term":"manifest","description":"Print the full CLI capability manifest (use with --json)"},{"name":"help","term":"help","description":"Show all commands"}]
@@ -12,7 +12,7 @@
12
12
  * the full program in program.mjs.
13
13
  */
14
14
 
15
- import {Command, Option} from 'commander';
15
+ import {Command, Help, Option} from 'commander';
16
16
  import {fileURLToPath} from 'node:url';
17
17
  import * as fs from 'node:fs';
18
18
  import * as path from 'node:path';
@@ -123,7 +123,6 @@ export const JSON_SUPPORTED = new Set([
123
123
  'experimental theme eject',
124
124
  'experimental theme template',
125
125
  'experimental theme targets',
126
- 'experimental theme palette generate',
127
126
  'build',
128
127
  'swizzle',
129
128
  'gap-report',
@@ -364,8 +363,10 @@ const READS_EVERY_COMMAND = new Set(['manifest']);
364
363
  * first operand after the root's own options, so this reads the arguments the
365
364
  * same way. It returns that one command, no command for a run that only
366
365
  * prints the version, or null for every command. These runs load every
367
- * command: help, the manifest, `help <command>`, an unknown word, and a flag
368
- * the root does not declare. They print or read the whole list.
366
+ * command: the root help when no stored list ships (a checkout; the published
367
+ * package prints it from the list, see `printsRootHelp`), the manifest,
368
+ * `help <command>`, an unknown word, and a flag the root does not declare.
369
+ * They print or read the whole list.
369
370
  *
370
371
  * @param {import('commander').Command} program the root, with its options
371
372
  * @param {string[]} argv the arguments after `astryx`
@@ -399,6 +400,93 @@ export function commandsForArgs(program, argv) {
399
400
  return printsVersion ? new Set() : null;
400
401
  }
401
402
 
403
+ /**
404
+ * Make `help <group> <command> ...` print the help of the deepest command the
405
+ * words name. Commander's help command reads only the first word, so
406
+ * `help theme build` printed the help of `theme`. Commander has no public hook
407
+ * for this; the override wraps its help dispatch and falls back to it.
408
+ * @param {import('commander').Command} program
409
+ */
410
+ export function resolveDeepHelp(program) {
411
+ const root = /** @type {any} */ (program);
412
+ // A Commander release without this method keeps its own help dispatch.
413
+ if (typeof root._dispatchHelpCommand !== 'function') return;
414
+ const dispatch = root._dispatchHelpCommand.bind(root);
415
+ root._dispatchHelpCommand = (/** @type {string | undefined} */ name) => {
416
+ const words = (root.args ?? [])
417
+ .slice(1)
418
+ .filter((/** @type {string} */ word) => !word.startsWith('-'));
419
+ /** @type {any} */
420
+ let target = root;
421
+ for (const word of words) {
422
+ const next = target._findCommand(word);
423
+ if (!next) break;
424
+ target = next;
425
+ }
426
+ if (words.length > 1 && target !== root && !target._executableHandler) {
427
+ target.help();
428
+ }
429
+ return dispatch(name);
430
+ };
431
+ }
432
+
433
+ /**
434
+ * Where the root help's command list is stored: each command's name, and the
435
+ * term and description the root help prints for it, as the fully loaded
436
+ * program gives them. `prepack` writes it (scripts/generate-command-list.mjs),
437
+ * so the published package prints its root help without loading every
438
+ * command. A checkout has none and loads them.
439
+ */
440
+ export const COMMAND_LIST_FILE = path.join(__dirname, 'commands.generated.json');
441
+
442
+ /**
443
+ * Whether a run only prints the root help: `--help`, `-h` or `help`, alone.
444
+ * @param {string[]} argv
445
+ * @returns {boolean}
446
+ */
447
+ function printsRootHelp(argv) {
448
+ return argv.length === 1 && ['--help', '-h', 'help'].includes(argv[0]);
449
+ }
450
+
451
+ /**
452
+ * The stored command list, or null when there is none or it cannot be read.
453
+ * @returns {Array<{name: string, term: string, description: string}> | null}
454
+ */
455
+ function storedCommandList() {
456
+ try {
457
+ return JSON.parse(fs.readFileSync(COMMAND_LIST_FILE, 'utf-8'));
458
+ } catch {
459
+ return null;
460
+ }
461
+ }
462
+
463
+ /**
464
+ * Give `program` a command for each stored row, which the root help prints
465
+ * with the row's term and description. Commander adds its own `help`
466
+ * command, so a stored `help` row adds none.
467
+ * @param {import('commander').Command} program
468
+ * @param {Array<{name: string, term: string, description: string}>} rows
469
+ */
470
+ function listStoredCommands(program, rows) {
471
+ /** @type {Map<string, {term: string, description: string}>} */
472
+ const byName = new Map();
473
+ for (const row of rows) {
474
+ if (row.name === 'help') continue;
475
+ byName.set(row.name, row);
476
+ program.command(row.name);
477
+ }
478
+ const help = program.configureHelp();
479
+ program.configureHelp({
480
+ ...help,
481
+ subcommandTerm: cmd =>
482
+ byName.get(cmd.name())?.term ??
483
+ Help.prototype.subcommandTerm.call(program.createHelp(), cmd),
484
+ subcommandDescription: cmd =>
485
+ byName.get(cmd.name())?.description ??
486
+ Help.prototype.subcommandDescription.call(program.createHelp(), cmd),
487
+ });
488
+ }
489
+
402
490
  const SETUP_NUDGE_EXEMPT = new Set(['init', 'agent-docs']);
403
491
 
404
492
  /**
@@ -595,6 +683,7 @@ export async function createProgram({argv} = {}) {
595
683
  program.help();
596
684
  });
597
685
  markReportsResult(program);
686
+ resolveDeepHelp(program);
598
687
 
599
688
  /**
600
689
  * Pre-action hook: gate --json BEFORE any command body runs.
@@ -810,7 +899,9 @@ export async function createProgram({argv} = {}) {
810
899
  });
811
900
 
812
901
  const loads = argv == null ? null : commandsForArgs(program, argv);
813
- for (const cmd of commands) {
902
+ const listed = argv != null && printsRootHelp(argv) ? storedCommandList() : null;
903
+ if (listed) listStoredCommands(program, listed);
904
+ for (const cmd of listed ? [] : commands) {
814
905
  if (loads != null && !loads.has(cmd.name)) continue;
815
906
  try {
816
907
  const mod = await import(cmd.path);
@@ -188,6 +188,7 @@ function commanderCodeToErrorCode(commanderCode, message) {
188
188
  case 'commander.unknownOption':
189
189
  return ERROR_CODES.ERR_INVALID_OPTION;
190
190
  case 'commander.missingArgument':
191
+ case 'commander.optionMissingArgument':
191
192
  case 'commander.missingMandatoryOptionValue':
192
193
  return ERROR_CODES.ERR_MISSING_ARGUMENT;
193
194
  case 'commander.excessArguments':
@@ -249,6 +250,8 @@ function applyShimRecursively(cmd) {
249
250
  } catch {
250
251
  // Never let recording interfere with the error path.
251
252
  }
253
+ // The error handler names the rejected command's usage from it.
254
+ /** @type {any} */ (err)[REJECTED_COMMAND] = cmd;
252
255
  throw err;
253
256
  });
254
257
  cmd.configureOutput({
@@ -276,6 +279,25 @@ function applyShimRecursively(cmd) {
276
279
  }
277
280
  }
278
281
 
282
+ /** Carries the command Commander rejected from exitOverride to the error handler. */
283
+ const REJECTED_COMMAND = Symbol.for('astryx.jsonShim.rejectedCommand');
284
+
285
+ /**
286
+ * The usage line of the command a parse error came from, as a suggestion, for
287
+ * an option given without its value.
288
+ * @param {unknown} err
289
+ * @param {string} code
290
+ * @returns {import('../../../foundation/response/base').Suggestion[] | undefined}
291
+ */
292
+ function usageSuggestion(err, code) {
293
+ if (code !== 'commander.optionMissingArgument') return undefined;
294
+ const cmd = /** @type {any} */ (err)?.[REJECTED_COMMAND];
295
+ if (!cmd) return undefined;
296
+ const parts = [];
297
+ for (let node = cmd; node; node = node.parent) parts.unshift(node.name());
298
+ return [{name: `${parts.join(' ')} ${cmd.usage()}`.trim(), reason: 'usage'}];
299
+ }
300
+
279
301
  /** Marks a command whose `command`/`addCommand` already self-install the shim. */
280
302
  const SELF_INSTALLING = Symbol.for('astryx.jsonShim.selfInstalling');
281
303
 
@@ -448,12 +470,18 @@ export function handleCommanderError(err) {
448
470
  // Real error paths. Strip Commander's "error: " prefix once: in the envelope
449
471
  // the key is already `error`, and in text mode the Astryx prefix replaces it.
450
472
  const cleaned = message.replace(/^error:\s*/i, '');
473
+ const suggestions = usageSuggestion(err, code);
451
474
  if (jsonActive()) {
452
- emitJsonError(cleaned, undefined, commanderCodeToErrorCode(code, cleaned));
475
+ emitJsonError(
476
+ cleaned,
477
+ suggestions,
478
+ commanderCodeToErrorCode(code, cleaned),
479
+ );
453
480
  } else {
454
481
  // Commander's own line was suppressed above, so a parse failure reads the
455
482
  // same as every other CLI error — the `Error: …` line cliError prints.
456
483
  process.stderr.write(`Error: ${cleaned}\n`);
484
+ if (suggestions) process.stderr.write(`Usage: ${suggestions[0].name}\n`);
457
485
  }
458
486
  process.exit(exitCode || 1);
459
487
  }
@@ -159,12 +159,26 @@ export class Project {
159
159
  * ejects share one discovery seam. A broken integration theme contribution is
160
160
  * reported without hiding the package's other valid kinds.
161
161
  *
162
- * @param {{includeLocal?: boolean}} [options]
162
+ * With `skipBrokenLocal`, a local theme folder that fails validation is
163
+ * left out and recorded for `skippedLocalThemes()`, so one broken folder
164
+ * does not hide every other theme.
165
+ *
166
+ * @param {{includeLocal?: boolean, skipBrokenLocal?: boolean}} [options]
163
167
  * @returns {Promise<import('../discovery/theme-discovery.mjs').DiscoveredTheme[]>}
164
168
  */
165
- themes({ includeLocal }?: {
169
+ themes({ includeLocal, skipBrokenLocal }?: {
166
170
  includeLocal?: boolean;
171
+ skipBrokenLocal?: boolean;
167
172
  }): Promise<import("../discovery/theme-discovery.mjs").DiscoveredTheme[]>;
173
+ /**
174
+ * Local theme folders `themes({skipBrokenLocal: true})` left out, with why.
175
+ * @returns {Array<{slug: string, path: string, reason: string}>}
176
+ */
177
+ skippedLocalThemes(): Array<{
178
+ slug: string;
179
+ path: string;
180
+ reason: string;
181
+ }>;
168
182
  /**
169
183
  * Installed icon sets, the sets withdrawn and why, and the project's icon
170
184
  * set (AST-084 FR7, FR8). Sets come from each loaded integration's