@astryxdesign/cli 0.7.15 → 0.7.16-canary.g56680f6

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 (117) hide show
  1. package/README.md +5 -3
  2. package/api/component/_adapter.d.mts +1 -1
  3. package/api/component/_adapter.mjs +28 -1
  4. package/api/doctor/_adapter.d.mts +17 -0
  5. package/api/doctor/_adapter.mjs +35 -0
  6. package/api/doctor/doctor.mjs +18 -4
  7. package/api/integration/validate-integration.mjs +1 -1
  8. package/api/theme/_adapter.d.mts +5 -2
  9. package/api/theme/_adapter.mjs +43 -12
  10. package/api/theme/build/build.d.mts +15 -23
  11. package/api/theme/build/build.mjs +185 -39
  12. package/api/theme/eject/eject.mjs +22 -1
  13. package/api/theme/template/template.d.mts +19 -0
  14. package/api/theme/template/template.mjs +91 -19
  15. package/api/theme/theme.type.d.mts +5 -1
  16. package/api/theme/theme.type.mjs +2 -1
  17. package/api/theme/themeBuild.doc.mjs +3 -3
  18. package/api/theme/themeEject.doc.mjs +1 -1
  19. package/api/theme/themeTemplate.doc.mjs +9 -3
  20. package/api/theme-edit/_adapter.d.mts +21 -0
  21. package/api/theme-edit/_adapter.mjs +176 -22
  22. package/api/theme-edit/_check.d.mts +7 -0
  23. package/api/theme-edit/_check.mjs +1050 -173
  24. package/api/theme-edit/_color.d.mts +2 -8
  25. package/api/theme-edit/_color.mjs +292 -219
  26. package/api/theme-edit/_compiler.d.mts +1 -0
  27. package/api/theme-edit/_compiler.mjs +20 -1
  28. package/api/theme-edit/_context.d.mts +21 -0
  29. package/api/theme-edit/_context.mjs +235 -12
  30. package/api/theme-edit/_css.d.mts +50 -1
  31. package/api/theme-edit/_css.mjs +310 -28
  32. package/api/theme-edit/_edit.d.mts +9 -0
  33. package/api/theme-edit/_edit.mjs +907 -123
  34. package/api/theme-edit/_how-commands.d.mts +11 -26
  35. package/api/theme-edit/_how-commands.mjs +30 -2
  36. package/api/theme-edit/_how-question.d.mts +7 -0
  37. package/api/theme-edit/_how-question.mjs +1304 -176
  38. package/api/theme-edit/_how.mjs +144 -30
  39. package/api/theme-edit/_palette.d.mts +6 -0
  40. package/api/theme-edit/_palette.mjs +164 -62
  41. package/api/theme-edit/_parts.d.mts +16 -0
  42. package/api/theme-edit/_parts.mjs +49 -1
  43. package/api/theme-edit/_png.mjs +19 -14
  44. package/api/theme-edit/_preview-app.mjs +514 -27
  45. package/api/theme-edit/_preview.d.mts +11 -0
  46. package/api/theme-edit/_preview.mjs +245 -24
  47. package/api/theme-edit/_project.d.mts +11 -0
  48. package/api/theme-edit/_project.mjs +35 -9
  49. package/api/theme-edit/_settings.d.mts +122 -5
  50. package/api/theme-edit/_settings.mjs +1363 -71
  51. package/api/theme-edit/_tables.d.mts +19 -0
  52. package/api/theme-edit/_tables.mjs +205 -149
  53. package/api/theme-edit/_vet.d.mts +42 -0
  54. package/api/theme-edit/_vet.mjs +144 -0
  55. package/api/theme-edit/theme-edit.type.d.mts +2 -1
  56. package/api/theme-edit/theme-edit.type.mjs +1 -1
  57. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  58. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  59. package/assets/docs/tree/single-component.doc.mjs +11 -2
  60. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  61. package/assets/docs.generated.json +2 -2
  62. package/assets/preview-app/next.config.mjs +7 -1
  63. package/assets/preview-app/src/app/globals.css +1 -0
  64. package/assets/self-audit.generated.json +1 -1
  65. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  66. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  67. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  68. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  69. package/assets/templates/components.generated.json +1 -1
  70. package/assets/templates/pages/dashboard/page.tsx +1 -1
  71. package/authoring/doctypes/_schema.d.mts +52 -5
  72. package/authoring/doctypes/_schema.mjs +62 -7
  73. package/authoring/doctypes/base/type.ts +10 -0
  74. package/authoring/doctypes/component/component.doc.mjs +1 -1
  75. package/authoring/doctypes/function/function.doc.mjs +6 -0
  76. package/authoring/doctypes/function/type.ts +3 -0
  77. package/authoring/doctypes/legacy.mjs +5 -1
  78. package/authoring/index.d.ts +1 -0
  79. package/clients/cli/build-id.generated.json +1 -1
  80. package/clients/cli/commands/doctor.doc.mjs +2 -2
  81. package/clients/cli/commands/experimental/theme.mjs +188 -37
  82. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  83. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
  84. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
  85. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  86. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  87. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  88. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  89. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  90. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  91. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  92. package/clients/cli/commands/theme.mjs +93 -10
  93. package/clients/cli/formatters/index.mjs +7 -4
  94. package/clients/cli/lib/cli-error.mjs +9 -3
  95. package/clients/cli/lib/component-format.mjs +27 -9
  96. package/clients/cli/lib/json-shim.mjs +40 -2
  97. package/clients/cli/manifest.generated.json +1 -1
  98. package/foundation/config/project.mjs +50 -14
  99. package/foundation/discovery/theme-discovery.d.mts +5 -1
  100. package/foundation/discovery/theme-discovery.mjs +24 -3
  101. package/foundation/fs/gather-cache.d.mts +9 -2
  102. package/foundation/fs/gather-cache.mjs +36 -10
  103. package/foundation/fs/paths.d.mts +16 -0
  104. package/foundation/fs/paths.mjs +25 -0
  105. package/foundation/render/host-exit.d.mts +8 -0
  106. package/foundation/render/host-exit.mjs +11 -0
  107. package/foundation/render/page-host.mjs +56 -10
  108. package/foundation/render/page-worker.mjs +14 -0
  109. package/foundation/render/render-page.mjs +37 -2
  110. package/foundation/response/error-codes.d.mts +2 -1
  111. package/foundation/response/error-codes.d.ts +1 -0
  112. package/foundation/response/error-codes.doc.mjs +5 -0
  113. package/foundation/response/error-codes.mjs +3 -0
  114. package/foundation/response/json.d.mts +15 -0
  115. package/foundation/response/json.mjs +52 -1
  116. package/foundation/response/response-types.doc.mjs +1 -1
  117. package/package.json +7 -6
@@ -57,7 +57,11 @@ import {themeAdd} from '../../../api/theme/add/add.mjs';
57
57
  import {themeRemove} from '../../../api/theme/remove/remove.mjs';
58
58
  import {themeUse} from '../../../api/theme/use/use.mjs';
59
59
  import {themeEject} from '../../../api/theme/eject/eject.mjs';
60
- import {themeTemplate} from '../../../api/theme/template/template.mjs';
60
+ import {
61
+ OUTSIDE_PROJECT_WARNING,
62
+ themeTemplate,
63
+ } from '../../../api/theme/template/template.mjs';
64
+ import {findPackageRoot} from '../../../foundation/fs/paths.mjs';
61
65
  import {
62
66
  themeListAvailable,
63
67
  themeListCopySources,
@@ -73,6 +77,8 @@ import {
73
77
  import {
74
78
  printBatchTrailer,
75
79
  printCompactTrailer,
80
+ setEditorFolderListener,
81
+ setPrivateVarErrorListener,
76
82
  themeBuild,
77
83
  themeBuildFamily,
78
84
  themeBuildForReport,
@@ -113,6 +119,7 @@ import {doc as themePaletteGenerateFn} from '../../../api/theme/themePaletteGene
113
119
  * @property {(err: import('../../../api/error.mjs').AstryxError, cwd: string) => import('../../../api/error.mjs').AstryxError | null} [explain] - A clearer refusal for this group, or null.
114
120
  * @property {(files: string[], options: {cwd: string, check?: boolean, family?: boolean}) => Promise<import('../../../api/error.mjs').AstryxError | null>} [preflight] - A refusal before a build starts, or null.
115
121
  * @property {(files: string[], options: {cwd: string}) => Promise<() => Promise<void>>} [hold] - Locks held while a build or check runs; resolves to their release.
122
+ * @property {(options: {targetPath?: string, overwrite?: boolean, cwd?: string}) => import('../../../api/theme/theme.type.mjs').ThemeTemplateResponse} [template] - This group's template write, in place of `themeTemplate`.
116
123
  */
117
124
 
118
125
  /** @type {ThemeCommandWords} */
@@ -222,6 +229,20 @@ function themeCommand(words, sub, args = [], reason = '') {
222
229
  };
223
230
  }
224
231
 
232
+ /**
233
+ * The message type a `theme build` child sends its watcher in place of a
234
+ * warning a build prints once per invocation (the --out editor-folder
235
+ * warning), so a watch session prints it once, not on every rebuild.
236
+ */
237
+ const WATCH_WARNING = 'astryx.theme.build.warning';
238
+
239
+ /**
240
+ * The `argv0` a watcher starts each `theme build` child with. With the IPC
241
+ * channel it marks the child as the watcher's own, so a CLI run another way
242
+ * with an IPC channel (forked by a tool or test runner) still prints.
243
+ */
244
+ const WATCH_CHILD_ARGV0 = 'astryx-theme-watch';
245
+
225
246
  /**
226
247
  * Path to this CLI's real entry (clients/cli/bin/astryx.mjs), resolved from
227
248
  * this module's location (clients/cli/commands/theme.mjs → ../bin/
@@ -244,9 +265,17 @@ function resolveCliBin() {
244
265
  * @param {(child: import('node:child_process').ChildProcess) => void} [onSpawn] -
245
266
  * Receives the child, so a watcher that stops can stop it too.
246
267
  * @param {ThemeCommandWords} [words]
268
+ * @param {(message: unknown) => void} [onMessage] - Receives what the child
269
+ * hands over the channel (WATCH_WARNING messages).
247
270
  * @returns {Promise<number>}
248
271
  */
249
- function runThemeBuildOnceChild(file, options, onSpawn, words = THEME_WORDS) {
272
+ function runThemeBuildOnceChild(
273
+ file,
274
+ options,
275
+ onSpawn,
276
+ words = THEME_WORDS,
277
+ onMessage,
278
+ ) {
250
279
  const cliBin = resolveCliBin();
251
280
  const command = [...words.group.split(' '), words.build];
252
281
  // A detail level the user chose applies to every rebuild.
@@ -257,10 +286,15 @@ function runThemeBuildOnceChild(file, options, onSpawn, words = THEME_WORDS) {
257
286
  if (options.iconsSpecifier)
258
287
  args.push('--icons-specifier', options.iconsSpecifier);
259
288
  return new Promise((/** @type {(code: number) => void} */ resolve) => {
289
+ // The IPC channel and argv0 tell the child it builds for this watcher: it
290
+ // hands its once-per-invocation warnings over the channel instead of
291
+ // printing them.
260
292
  const child = spawn(process.execPath, args, {
261
- stdio: 'inherit',
293
+ argv0: WATCH_CHILD_ARGV0,
294
+ stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
262
295
  env: process.env,
263
296
  });
297
+ child.on('message', message => onMessage?.(message));
264
298
  onSpawn?.(child);
265
299
  child.on('close', code => resolve(code ?? 0));
266
300
  child.on('error', () => resolve(1));
@@ -290,9 +324,28 @@ async function runThemeBuildWatch(entries, options, words = THEME_WORDS) {
290
324
  .map(e => rel(e.filePath))
291
325
  .join(', ')} for changes — press Ctrl-C to stop.`;
292
326
 
327
+ // A warning a build prints once per invocation is printed at most once
328
+ // per watch session (spec:AST-017 FR29a), not on every rebuild.
329
+ let warned = false;
330
+ // Watch never runs under --json, so the logger prints (cli-surface INV12).
331
+ logger.setSilent(false);
332
+ const onMessage = (/** @type {unknown} */ message) => {
333
+ const m = /** @type {{type?: unknown, text?: unknown}} */ (message);
334
+ if (warned || m?.type !== WATCH_WARNING || typeof m.text !== 'string')
335
+ return;
336
+ warned = true;
337
+ logger.warn(m.text);
338
+ };
339
+
293
340
  // Initial build.
294
341
  for (const entry of entries) {
295
- await runThemeBuildOnceChild(entry.file, options, undefined, words);
342
+ await runThemeBuildOnceChild(
343
+ entry.file,
344
+ options,
345
+ undefined,
346
+ words,
347
+ onMessage,
348
+ );
296
349
  }
297
350
 
298
351
  let building = false;
@@ -323,6 +376,7 @@ async function runThemeBuildWatch(entries, options, words = THEME_WORDS) {
323
376
  rebuildChild = child;
324
377
  },
325
378
  words,
379
+ onMessage,
326
380
  );
327
381
  rebuildDone = done.then(() => {});
328
382
  await done;
@@ -1074,10 +1128,25 @@ function registerThemeCommands(theme, program, docs, words) {
1074
1128
  // [ok]/[warn] lines, and the install instructions are all emitted from
1075
1129
  // inside themeBuild via the shared logger.
1076
1130
  logger.setSilent(json);
1131
+ // Started by a watcher (runThemeBuildWatch): hand the editor-folder
1132
+ // warning to it, and let the channel not keep this build alive.
1133
+ const watchChild =
1134
+ typeof process.send === 'function' &&
1135
+ process.argv0 === WATCH_CHILD_ARGV0;
1136
+ if (watchChild) {
1137
+ process.channel?.unref();
1138
+ setEditorFolderListener(warning => {
1139
+ // Held open until the message is out, then let go again.
1140
+ process.channel?.ref();
1141
+ process.send?.({type: WATCH_WARNING, text: warning}, () =>
1142
+ process.channel?.unref(),
1143
+ );
1144
+ });
1145
+ }
1077
1146
  let privateVarError = false;
1078
- const onPrivateVarError = () => {
1147
+ setPrivateVarErrorListener(() => {
1079
1148
  privateVarError = true;
1080
- };
1149
+ });
1081
1150
 
1082
1151
  const refused = await words.preflight?.(files, {
1083
1152
  cwd: process.cwd(),
@@ -1094,7 +1163,6 @@ function registerThemeCommands(theme, program, docs, words) {
1094
1163
  familyKey: /** @type {string} */ (options.familyKey),
1095
1164
  check: options.check,
1096
1165
  iconsSpecifier: options.iconsSpecifier,
1097
- __onPrivateVarError: onPrivateVarError,
1098
1166
  __commandWords: words,
1099
1167
  },
1100
1168
  {cwd: process.cwd()},
@@ -1102,7 +1170,12 @@ function registerThemeCommands(theme, program, docs, words) {
1102
1170
  if (json) jsonOut(result);
1103
1171
  if (
1104
1172
  privateVarError ||
1105
- (result.type === 'theme.build.check' && !result.data.upToDate)
1173
+ (result.type === 'theme.build.check' &&
1174
+ !(
1175
+ /** @type {import('../../../api/theme/theme.type.mjs').ThemeBuildCheckResponse} */ (
1176
+ result
1177
+ ).data.upToDate
1178
+ ))
1106
1179
  ) {
1107
1180
  process.exitCode = 1;
1108
1181
  }
@@ -1173,7 +1246,6 @@ function registerThemeCommands(theme, program, docs, words) {
1173
1246
  out: options.out,
1174
1247
  check: options.check,
1175
1248
  iconsSpecifier: options.iconsSpecifier,
1176
- __onPrivateVarError: onPrivateVarError,
1177
1249
  __claimedOutputs: claimedOutputs,
1178
1250
  __deferredWrites: deferred ? writes : undefined,
1179
1251
  __commandWords: words,
@@ -1471,6 +1543,9 @@ function registerThemeCommands(theme, program, docs, words) {
1471
1543
  const json = program.opts().json || false;
1472
1544
  /** @type {import('../../../api/theme/theme.type.mjs').ThemeEjectResponse} */
1473
1545
  let result;
1546
+ // Eject's warnings go to stderr in text mode; the logger is silent
1547
+ // under --json (cli-surface INV12).
1548
+ logger.setSilent(json);
1474
1549
  try {
1475
1550
  result = await themeEject(slug, {
1476
1551
  targetPath,
@@ -1503,7 +1578,9 @@ function registerThemeCommands(theme, program, docs, words) {
1503
1578
  /** @type {import('../../../api/theme/theme.type.mjs').ThemeTemplateResponse} */
1504
1579
  let result;
1505
1580
  try {
1506
- result = themeTemplate({
1581
+ // The experimental command passes its own write, which protects
1582
+ // only the editor's own files.
1583
+ result = (words.template ?? themeTemplate)({
1507
1584
  targetPath,
1508
1585
  overwrite: options.overwrite,
1509
1586
  cwd: process.cwd(),
@@ -1521,6 +1598,12 @@ function registerThemeCommands(theme, program, docs, words) {
1521
1598
  ]);
1522
1599
  }
1523
1600
 
1601
+ // Outside a project the template is written here, with one warning
1602
+ // on stderr when a file was written; the logger is silent under --json
1603
+ // (cli-surface INV12).
1604
+ logger.setSilent(json);
1605
+ if (result.data.written && !findPackageRoot(process.cwd()))
1606
+ logger.warn(OUTSIDE_PROJECT_WARNING);
1524
1607
  // Writes a starter theme file, or declines to overwrite one.
1525
1608
  if (json) {
1526
1609
  jsonOut(result);
@@ -236,7 +236,9 @@ function wrapLine(line, width, indent) {
236
236
  * @returns {Block}
237
237
  */
238
238
  export function section(heading, subtitle) {
239
- return new Block(toAscii(subtitle ? `${heading}\n${subtitle}` : String(heading)));
239
+ return new Block(
240
+ toAscii(subtitle ? `${heading}\n${subtitle}` : String(heading)),
241
+ );
240
242
  }
241
243
 
242
244
  /**
@@ -311,9 +313,10 @@ export function records(items, options = {}) {
311
313
  * @returns {Block}
312
314
  */
313
315
  function inlineRecords(items, options) {
314
- const [lead, ...rest] = (options.fields ?? Object.keys(items[0] ?? {})).filter(
315
- k => !options.omit?.includes(k),
316
- );
316
+ // Columns from every row: an optional field is on some rows only.
317
+ const [lead, ...rest] = (
318
+ options.fields ?? [...new Set(items.flatMap(o => Object.keys(o ?? {})))]
319
+ ).filter(k => !options.omit?.includes(k));
317
320
  if (lead == null) return new Block('');
318
321
  /** @param {any} o @param {string} k */
319
322
  const value = (o, k) => {
@@ -54,6 +54,8 @@ import {
54
54
  isJsonMode,
55
55
  jsonError as _jsonError,
56
56
  humanWarn,
57
+ outputCaptured,
58
+ writeAllSync,
57
59
  } from '../../../foundation/response/json.mjs';
58
60
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
59
61
  import {setOutcome} from '../../../foundation/debug/index.mjs';
@@ -129,18 +131,22 @@ export function cliError(message, options = {}) {
129
131
  // Human mode: prefix "Error:" and print suggestions on subsequent lines.
130
132
  // Use console.error directly — we always want stderr for errors regardless
131
133
  // of the JSON-mode flag (we already handled JSON above).
132
- console.error(`Error: ${message}`);
134
+ const lines = [`Error: ${message}`];
133
135
  if (suggestions?.length) {
134
- console.error('');
136
+ lines.push('');
135
137
  for (const s of suggestions) {
136
138
  // A suggested command stays bare in JSON and is prefixed here.
137
139
  const name = /^astryx(\s|$)/.test(s.name)
138
140
  ? formatCliCommand(s.name)
139
141
  : s.name;
140
142
  const tag = s.reason ? ` ${name} (${s.reason})` : ` ${name}`;
141
- console.error(tag);
143
+ lines.push(tag);
142
144
  }
143
145
  }
146
+ // Written whole before a hard exit: output still queued for a slow pipe
147
+ // would be cut at 64 KiB. A soft exit lets the stream drain on its own.
148
+ if (hard && !outputCaptured(2)) writeAllSync(2, `${lines.join('\n')}\n`);
149
+ else for (const line of lines) console.error(line);
144
150
 
145
151
  if (hard) {
146
152
  process.exit(exitCode);
@@ -30,6 +30,24 @@ function targetKey(target) {
30
30
  return target.className.replace(/^astryx-/, '');
31
31
  }
32
32
 
33
+ /**
34
+ * Render one doc example as an optional heading and a code block. A setup
35
+ * example says so in its heading, because it does not run on its own.
36
+ * @param {import('@astryxdesign/cli/authoring').ComponentExampleDoc} ex
37
+ * @param {string} hashes - heading level, e.g. '###'
38
+ * @returns {string[]}
39
+ */
40
+ function formatExample(ex, hashes) {
41
+ const lines = [];
42
+ if (ex.kind === 'setup') {
43
+ lines.push(`${hashes} ${ex.label ?? 'Setup'} (setup, code only)\n`);
44
+ } else if (ex.label) {
45
+ lines.push(`${hashes} ${ex.label}\n`);
46
+ }
47
+ lines.push('```tsx\n' + ex.code + '\n```\n');
48
+ return lines;
49
+ }
50
+
33
51
  /** @param {string} name @returns {string} */
34
52
  function dataAttrForName(name) {
35
53
  return `data-${name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()}`;
@@ -306,8 +324,7 @@ export function formatFull(docs, options = {}) {
306
324
  sections.push(...formatSubComponent(comp));
307
325
  if (comp.examples?.length) {
308
326
  for (const ex of comp.examples) {
309
- if (ex.label) sections.push(`#### ${ex.label}\n`);
310
- sections.push('```tsx\n' + ex.code + '\n```\n');
327
+ sections.push(...formatExample(ex, '####'));
311
328
  }
312
329
  }
313
330
  }
@@ -316,8 +333,7 @@ export function formatFull(docs, options = {}) {
316
333
  if (docs.examples?.length) {
317
334
  sections.push('## Examples\n');
318
335
  for (const ex of docs.examples) {
319
- if (ex.label) sections.push(`### ${ex.label}\n`);
320
- sections.push('```tsx\n' + ex.code + '\n```\n');
336
+ sections.push(...formatExample(ex, '###'));
321
337
  }
322
338
  }
323
339
 
@@ -515,8 +531,7 @@ export function formatCompact(docs, componentName, importHint) {
515
531
  if (examples.length) {
516
532
  sections.push('## Usage\n');
517
533
  for (const ex of examples) {
518
- if (ex.label) sections.push(`### ${ex.label}\n`);
519
- sections.push('```tsx\n' + ex.code + '\n```\n');
534
+ sections.push(...formatExample(ex, '###'));
520
535
  }
521
536
  }
522
537
 
@@ -703,9 +718,12 @@ export function formatBrief(docs, componentName, importHint, options = {}) {
703
718
  output.push(` ${otherProps.join(', ')}`);
704
719
  }
705
720
 
706
- // First code example
707
- if (examples.length > 0) {
708
- const code = examples[0].code;
721
+ // First code example; a setup example does not show the component in use.
722
+ const usageExample =
723
+ examples.find((/** @type {any} */ ex) => ex.kind !== 'setup') ??
724
+ examples[0];
725
+ if (usageExample) {
726
+ const code = usageExample.code;
709
727
  const codeLine =
710
728
  code
711
729
  .split('\n')
@@ -45,6 +45,7 @@ import {API_VERSION, isJsonMode, toErrorEnvelope} from '../../../foundation/resp
45
45
  import {answeredBy} from '../../../foundation/release/run-context.mjs';
46
46
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
47
47
  import {setCommand, setOutcome, recordHelp} from '../../../foundation/debug/index.mjs';
48
+ import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
48
49
 
49
50
  /**
50
51
  * Fully-qualified name of a command relative to the root program, e.g.
@@ -290,14 +291,43 @@ const REJECTED_COMMAND = Symbol.for('astryx.jsonShim.rejectedCommand');
290
291
  * @returns {import('../../../foundation/response/base').Suggestion[] | undefined}
291
292
  */
292
293
  function usageSuggestion(err, code) {
293
- if (code !== 'commander.optionMissingArgument') return undefined;
294
294
  const cmd = /** @type {any} */ (err)?.[REJECTED_COMMAND];
295
295
  if (!cmd) return undefined;
296
296
  const parts = [];
297
297
  for (let node = cmd; node; node = node.parent) parts.unshift(node.name());
298
+ // The theme editor names what is missing with its usage and its help, as
299
+ // the project runs the CLI.
300
+ if (
301
+ code === 'commander.missingArgument' &&
302
+ parts.slice(1, 4).join(' ') === 'experimental theme editor'
303
+ ) {
304
+ const words = parts.slice(1).join(' ');
305
+ const invocation = getCliInvocation(process.cwd());
306
+ return [
307
+ {name: `${invocation} ${words} ${cmd.usage()}`.trim(), reason: 'usage'},
308
+ {name: `${invocation} ${words} --help`, reason: 'what each argument is'},
309
+ ];
310
+ }
311
+ if (code !== 'commander.optionMissingArgument') return undefined;
298
312
  return [{name: `${parts.join(' ')} ${cmd.usage()}`.trim(), reason: 'usage'}];
299
313
  }
300
314
 
315
+ /**
316
+ * The theme editor's message for a missing argument: what the command takes
317
+ * and the words it was given, in order.
318
+ * @param {unknown} err
319
+ * @param {string} message Commander's message
320
+ */
321
+ function editorMissingMessage(err, message) {
322
+ const cmd = /** @type {any} */ (err)?.[REJECTED_COMMAND];
323
+ const given = /** @type {string[]} */ (cmd?.args ?? []);
324
+ const wants = (cmd?.registeredArguments ?? [])
325
+ .filter((/** @type {any} */ a) => a.required)
326
+ .map((/** @type {any} */ a) => `<${a.name()}>`);
327
+ const missing = /'([^']+)'/.exec(message)?.[1];
328
+ return `${cmd.name()} takes ${wants.join(' ')}, and ${given.length ? `was given ${given.length} (${given.join(' ')}), read as ${wants.slice(0, given.length).join(' ')}` : 'was given none'}: ${missing ? `<${missing}>` : 'an argument'} is missing.`;
329
+ }
330
+
301
331
  /** Marks a command whose `command`/`addCommand` already self-install the shim. */
302
332
  const SELF_INSTALLING = Symbol.for('astryx.jsonShim.selfInstalling');
303
333
 
@@ -469,8 +499,14 @@ export function handleCommanderError(err) {
469
499
 
470
500
  // Real error paths. Strip Commander's "error: " prefix once: in the envelope
471
501
  // the key is already `error`, and in text mode the Astryx prefix replaces it.
472
- const cleaned = message.replace(/^error:\s*/i, '');
473
502
  const suggestions = usageSuggestion(err, code);
503
+ // In the theme editor a missing argument names what was given: in
504
+ // `set corners small` the first word is read as the theme, so "value" alone
505
+ // would name the wrong thing.
506
+ const cleaned =
507
+ suggestions?.length === 2
508
+ ? editorMissingMessage(err, message)
509
+ : message.replace(/^error:\s*/i, '');
474
510
  if (jsonActive()) {
475
511
  emitJsonError(
476
512
  cleaned,
@@ -482,6 +518,8 @@ export function handleCommanderError(err) {
482
518
  // same as every other CLI error — the `Error: …` line cliError prints.
483
519
  process.stderr.write(`Error: ${cleaned}\n`);
484
520
  if (suggestions) process.stderr.write(`Usage: ${suggestions[0].name}\n`);
521
+ if (suggestions?.[1])
522
+ process.stderr.write(`Run: ${suggestions[1].name}\n`);
485
523
  }
486
524
  process.exit(exitCode || 1);
487
525
  }