@astryxdesign/cli 0.7.16-canary.g8514aae → 0.7.16-canary.gbb5e9d4

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 (60) hide show
  1. package/api/doctor/doctor.mjs +1 -1
  2. package/api/integration/pack-check.mjs +13 -7
  3. package/api/search/_adapter.mjs +3 -16
  4. package/api/theme/build/build.d.mts +63 -6
  5. package/api/theme/build/build.mjs +196 -36
  6. package/api/theme/template/template.mjs +12 -7
  7. package/api/theme-edit/_adapter.d.mts +13 -8
  8. package/api/theme-edit/_adapter.mjs +34 -36
  9. package/api/theme-edit/_check.d.mts +62 -3
  10. package/api/theme-edit/_check.mjs +488 -66
  11. package/api/theme-edit/_context.d.mts +8 -0
  12. package/api/theme-edit/_context.mjs +271 -108
  13. package/api/theme-edit/_css.d.mts +10 -0
  14. package/api/theme-edit/_css.mjs +94 -0
  15. package/api/theme-edit/_edit.mjs +437 -56
  16. package/api/theme-edit/_overview.mjs +2 -0
  17. package/api/theme-edit/_palette.d.mts +5 -0
  18. package/api/theme-edit/_palette.mjs +30 -3
  19. package/api/theme-edit/_parts.d.mts +17 -0
  20. package/api/theme-edit/_parts.mjs +89 -8
  21. package/api/theme-edit/_png.d.mts +18 -0
  22. package/api/theme-edit/_png.mjs +76 -0
  23. package/api/theme-edit/_preview-app.d.mts +9 -0
  24. package/api/theme-edit/_preview-app.mjs +678 -45
  25. package/api/theme-edit/_preview.d.mts +5 -3
  26. package/api/theme-edit/_preview.mjs +90 -6
  27. package/api/theme-edit/_project.mjs +11 -3
  28. package/api/theme-edit/_settings.d.mts +122 -4
  29. package/api/theme-edit/_settings.mjs +1236 -82
  30. package/api/theme-edit/_tables.d.mts +5 -0
  31. package/api/theme-edit/_tables.mjs +6 -0
  32. package/api/upgrade/registry/registry.mjs +6 -1
  33. package/assets/docs.generated.json +2 -2
  34. package/assets/preview-app/package.json +1 -0
  35. package/assets/self-audit.generated.json +1 -1
  36. package/assets/templates/components.generated.json +1 -1
  37. package/assets/templates/pages/dashboard/page.tsx +1 -1
  38. package/clients/cli/build-id.generated.json +1 -1
  39. package/clients/cli/commands/experimental/theme.mjs +49 -8
  40. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
  41. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  42. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  43. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  44. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  45. package/clients/cli/commands/theme.mjs +93 -53
  46. package/clients/cli/lib/json-shim.mjs +44 -12
  47. package/clients/cli/manifest.generated.json +1 -1
  48. package/clients/cli/run.mjs +49 -0
  49. package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
  50. package/foundation/agent-docs/agent-docs-target.mjs +9 -17
  51. package/foundation/agent-docs/agent-docs.mjs +3 -2
  52. package/foundation/discovery/template-adapter.mjs +29 -1
  53. package/foundation/fs/exact-codec.d.mts +35 -0
  54. package/foundation/fs/exact-codec.mjs +148 -0
  55. package/foundation/fs/gather-cache.mjs +56 -14
  56. package/foundation/fs/paths.d.mts +23 -0
  57. package/foundation/fs/paths.mjs +19 -11
  58. package/foundation/fs/read-record.mjs +11 -1
  59. package/foundation/integrations/may-have-integrations.mjs +3 -2
  60. package/package.json +6 -6
@@ -2193,7 +2193,7 @@ export function checkGatherCache() {
2193
2193
  id: 'gather-cache',
2194
2194
  label: 'Kept catalog cache',
2195
2195
  status: 'info',
2196
- message: `search, build, component, template, theme, discover and doctor keep what they gather (search's catalogs, each integration's check results, and doctor's docs checks) in ${summary.dir} (${summary.entries} ${summary.entries === 1 ? 'entry' : 'entries'}, ${size})${summary.pnp ? ", but not in a run under Yarn Plug'n'Play's loader, such as `yarn astryx`, which gathers every time" : ''}; each is used only while nothing it read has changed, and deleting the folder clears it.`,
2196
+ message: `search, build, component, template, theme, discover and doctor keep what they gather (search's catalogs, each integration's check results, template discovery's records, and doctor's docs checks) in ${summary.dir} (${summary.entries} ${summary.entries === 1 ? 'entry' : 'entries'}, ${size})${summary.pnp ? ", but not in a run under Yarn Plug'n'Play's loader, such as `yarn astryx`, which gathers every time" : ''}; each is used only while nothing it read has changed, and deleting the folder clears it.`,
2197
2197
  };
2198
2198
  }
2199
2199
 
@@ -57,7 +57,7 @@ import {
57
57
  } from '../../foundation/discovery/theme-imports.mjs';
58
58
  import {
59
59
  normalizeThemeBuildForCompare,
60
- themeBuild,
60
+ themeBuildWithHandOff,
61
61
  } from '../theme/build/build.mjs';
62
62
  import {
63
63
  discoverIntegrationComponents,
@@ -641,8 +641,12 @@ async function validateIncompleteThemeExports(
641
641
  if (outputs.some(output => output.kind !== 'font stylesheet')) {
642
642
  // The scratch directory is the write root; the package stays the cwd,
643
643
  // so the build selects the package's Core and its paths as before.
644
- const scratchBuild = {out: expectedCss, __writeRoot: expectedDir};
645
- const receipt = await themeBuild(source, scratchBuild, {cwd: packageDir});
644
+ const receipt = await themeBuildWithHandOff(
645
+ source,
646
+ {out: expectedCss},
647
+ {cwd: packageDir},
648
+ {writeRoot: expectedDir},
649
+ );
646
650
  if (receipt == null || receipt.type !== 'theme.build') {
647
651
  throw new Error('the theme build produced no complete receipt');
648
652
  }
@@ -1079,10 +1083,12 @@ async function validatePackedThemeExports(
1079
1083
  try {
1080
1084
  // The scratch directory is the write root; the package stays the cwd,
1081
1085
  // so the build selects the package's Core and its paths as before.
1082
- const scratchBuild = {out: expectedCss, __writeRoot: expectedDir};
1083
- const receipt = await themeBuild(source, scratchBuild, {
1084
- cwd: localIntegration.__packageDir,
1085
- });
1086
+ const receipt = await themeBuildWithHandOff(
1087
+ source,
1088
+ {out: expectedCss},
1089
+ {cwd: localIntegration.__packageDir},
1090
+ {writeRoot: expectedDir},
1091
+ );
1086
1092
  if (receipt == null || receipt.type !== 'theme.build') {
1087
1093
  issues.push(
1088
1094
  error(
@@ -6,9 +6,9 @@
6
6
  * domain, _gather-*.mjs) and loads the tree's static data before it runs.
7
7
  */
8
8
 
9
- import {readFileSync, realpathSync} from 'node:fs';
9
+ import {readFileSync} from 'node:fs';
10
10
  import * as path from 'node:path';
11
- import {requireCoreDir} from '../../foundation/fs/paths.mjs';
11
+ import {realDir, requireCoreDir} from '../../foundation/fs/paths.mjs';
12
12
  import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
13
13
  import {persistedGather} from '../../foundation/fs/gather-cache.mjs';
14
14
  import {
@@ -130,19 +130,6 @@ async function gatherDomains(options) {
130
130
  };
131
131
  }
132
132
 
133
- /**
134
- * The folder's real path, so a link and its target share a kept gather.
135
- * @param {string} dir
136
- * @returns {string}
137
- */
138
- function realFolder(dir) {
139
- try {
140
- return realpathSync(dir);
141
- } catch {
142
- return dir;
143
- }
144
- }
145
-
146
133
  /**
147
134
  * A gathered catalog as plain JSON and back, for a gather kept between runs
148
135
  * (persistedGather). A template's derived component names are read once and
@@ -264,7 +251,7 @@ export function gatherCandidatesReused(options) {
264
251
  gather = reusedWhileUnchanged(
265
252
  () =>
266
253
  persistedGather(
267
- [realFolder(cwd), type ?? null],
254
+ [realDir(cwd), type ?? null],
268
255
  () => gatherCandidates({cwd, type}),
269
256
  GATHER_CODEC,
270
257
  // A gather that skipped Core (a failed install still in its
@@ -68,6 +68,19 @@ export function themeSourceFiles(filePath: string): string[];
68
68
  * @returns {string[]} at most three paths
69
69
  */
70
70
  export function themeSourceGuesses(file: string, cwd: string): string[];
71
+ /**
72
+ * Hand the theme editor warnings of the builds in this process to
73
+ * `listener` instead of the logger. CLI-internal: the watch child's
74
+ * hand-off to its parent.
75
+ * @param {((warning: string) => void) | null} listener
76
+ */
77
+ export function setEditorFolderListener(listener: ((warning: string) => void) | null): void;
78
+ /**
79
+ * Tell `listener` when a build in this process finds private var errors.
80
+ * CLI-internal.
81
+ * @param {(() => void) | null} listener
82
+ */
83
+ export function setPrivateVarErrorListener(listener: (() => void) | null): void;
71
84
  /**
72
85
  * Publish the outputs a batch deferred, one theme at a time, in build order.
73
86
  * @param {Array<Array<{dest: string, content: string}>>} deferred
@@ -155,6 +168,7 @@ export function printCompactTrailer(trailers: ThemeBuildTrailer[], { hint }?: {
155
168
  * @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options]
156
169
  * @param {{cwd?: string}} [ctx]
157
170
  * @param {{compact?: boolean}} [report]
171
+ * @param {ThemeBuildHandOff} [handOff]
158
172
  * @returns {Promise<{receipt: import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null, trailer: ThemeBuildTrailer | null}>}
159
173
  */
160
174
  export function themeBuildForReport(file: string, options?: {
@@ -165,7 +179,7 @@ export function themeBuildForReport(file: string, options?: {
165
179
  cwd?: string;
166
180
  }, { compact }?: {
167
181
  compact?: boolean;
168
- }): Promise<{
182
+ }, handOff?: ThemeBuildHandOff): Promise<{
169
183
  receipt: import("../theme.type.mjs").ThemeBuildResponse | import("../theme.type.mjs").ThemeBuildCheckResponse | null;
170
184
  trailer: ThemeBuildTrailer | null;
171
185
  }>;
@@ -178,18 +192,36 @@ export function themeBuild(file: string, options?: {
178
192
  cwd?: string;
179
193
  projectCore?: boolean;
180
194
  }): Promise<import("../theme.type.mjs").ThemeBuildResponse | import("../theme.type.mjs").ThemeBuildCheckResponse | null>;
181
- /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void, __commandWords?: {group: string, build: string}}} options @param {{cwd?: string}} [ctx] */
195
+ /**
196
+ * {@link themeBuild} with the CLI's hand-off: the same build, outputs, and
197
+ * receipt, plus what only the CLI's batch and scratch builds pass.
198
+ * CLI-internal: not exported from the API entry.
199
+ * @param {string} file
200
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string}} options
201
+ * @param {{cwd?: string, projectCore?: boolean}} ctx
202
+ * @param {ThemeBuildHandOff} handOff
203
+ * @returns {Promise<import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null>}
204
+ */
205
+ export function themeBuildWithHandOff(file: string, options: {
206
+ out?: string;
207
+ check?: boolean;
208
+ iconsSpecifier?: string;
209
+ }, ctx: {
210
+ cwd?: string;
211
+ projectCore?: boolean;
212
+ }, handOff: ThemeBuildHandOff): Promise<import("../theme.type.mjs").ThemeBuildResponse | import("../theme.type.mjs").ThemeBuildCheckResponse | null>;
213
+ /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string}} options @param {{cwd?: string}} [ctx] @param {{commandWords?: {group: string, build: string}}} [handOff] - the CLI's words for the rebuild hint */
182
214
  export function themeBuildFamily(files: string[], options: {
183
215
  familyKey: string;
184
216
  check?: boolean;
185
217
  iconsSpecifier?: string;
186
- __onPrivateVarError?: () => void;
187
- __commandWords?: {
218
+ }, { cwd }?: {
219
+ cwd?: string;
220
+ }, handOff?: {
221
+ commandWords?: {
188
222
  group: string;
189
223
  build: string;
190
224
  };
191
- }, { cwd }?: {
192
- cwd?: string;
193
225
  }): Promise<import("../theme.type.mjs").ThemeBuildCheckResponse | {
194
226
  type: string;
195
227
  data: {
@@ -267,3 +299,28 @@ export type ThemeBuildTrailer = {
267
299
  */
268
300
  fontNotices: string[];
269
301
  };
302
+ /**
303
+ * What the CLI hands a build beyond themeBuild's options. CLI-internal, never
304
+ * a themeBuild option: `claimedOutputs` records the outputs earlier builds in
305
+ * one run wrote, so a later theme cannot replace them; with `deferredWrites`
306
+ * the build adds its outputs to that list instead of writing them, for
307
+ * writeDeferredBuildOutputs; `writeRoot` replaces `cwd` as the directory every
308
+ * output must stay inside, for a scratch build; `commandWords` names the
309
+ * command in the rebuild hint; `prepareFamily`, `familyLoader`, and
310
+ * `familyInterception` make the build a family member's plan.
311
+ */
312
+ export type ThemeBuildHandOff = {
313
+ prepareFamily?: boolean;
314
+ familyLoader?: any;
315
+ familyInterception?: any;
316
+ writeRoot?: string;
317
+ claimedOutputs?: Map<string, string>;
318
+ deferredWrites?: Array<Array<{
319
+ dest: string;
320
+ content: string;
321
+ }>>;
322
+ commandWords?: {
323
+ group: string;
324
+ build: string;
325
+ };
326
+ };
@@ -1094,6 +1094,54 @@ function assertThemeSourceFile(filePath, cwd) {
1094
1094
  }
1095
1095
  }
1096
1096
 
1097
+ /**
1098
+ * What the CLI hands a build beyond themeBuild's options. CLI-internal, never
1099
+ * a themeBuild option: `claimedOutputs` records the outputs earlier builds in
1100
+ * one run wrote, so a later theme cannot replace them; with `deferredWrites`
1101
+ * the build adds its outputs to that list instead of writing them, for
1102
+ * writeDeferredBuildOutputs; `writeRoot` replaces `cwd` as the directory every
1103
+ * output must stay inside, for a scratch build; `commandWords` names the
1104
+ * command in the rebuild hint; `prepareFamily`, `familyLoader`, and
1105
+ * `familyInterception` make the build a family member's plan.
1106
+ * @typedef {{prepareFamily?: boolean, familyLoader?: any, familyInterception?: any, writeRoot?: string, claimedOutputs?: Map<string, string>, deferredWrites?: Array<Array<{dest: string, content: string}>>, commandWords?: {group: string, build: string}}} ThemeBuildHandOff
1107
+ */
1108
+
1109
+ /**
1110
+ * Who takes the theme editor warnings (an editor folder, an editor-made
1111
+ * theme) instead of the logger: the watcher's child build hands each to its
1112
+ * parent, which prints it once per session. Set
1113
+ * only by the CLI (not part of the public API), and never by an option of
1114
+ * themeBuild.
1115
+ * @type {((warning: string) => void) | null}
1116
+ */
1117
+ let editorFolderListener = null;
1118
+
1119
+ /**
1120
+ * Hand the theme editor warnings of the builds in this process to
1121
+ * `listener` instead of the logger. CLI-internal: the watch child's
1122
+ * hand-off to its parent.
1123
+ * @param {((warning: string) => void) | null} listener
1124
+ */
1125
+ export function setEditorFolderListener(listener) {
1126
+ editorFolderListener = listener;
1127
+ }
1128
+
1129
+ /**
1130
+ * Who is told a build found private var errors (the CLI, to exit 1). Set
1131
+ * only by the CLI, never by an option of themeBuild.
1132
+ * @type {(() => void) | null}
1133
+ */
1134
+ let privateVarErrorListener = null;
1135
+
1136
+ /**
1137
+ * Tell `listener` when a build in this process finds private var errors.
1138
+ * CLI-internal.
1139
+ * @param {(() => void) | null} listener
1140
+ */
1141
+ export function setPrivateVarErrorListener(listener) {
1142
+ privateVarErrorListener = listener;
1143
+ }
1144
+
1097
1145
  /**
1098
1146
  * Refuse a build that would replace a file it does not own. A build never
1099
1147
  * writes over its input, two of its own outputs at one path, or an output
@@ -1125,6 +1173,7 @@ function assertOutputsReplaceable(
1125
1173
  const rel = (/** @type {string} */ file) => path.relative(cwd, file);
1126
1174
  const sourceKey = outputKey(filePath);
1127
1175
  const seen = new Set();
1176
+ /** @type {string | false} */
1128
1177
  let warnedOtherSource = false;
1129
1178
  // The same build without --out, with its other options.
1130
1179
  const beside = {
@@ -1201,11 +1250,10 @@ function assertOutputsReplaceable(
1201
1250
  : null;
1202
1251
  if (otherSource && !OUT_REFUSES_OTHER_SOURCE) {
1203
1252
  // One warning per build: every output of that source goes together.
1253
+ // It is printed after every output passes, so it names a replacement
1254
+ // that happens.
1204
1255
  if (warnedOtherSource) continue;
1205
- warnedOtherSource = true;
1206
- logger.warn(
1207
- `Warning: ${rel(write.dest)} was built from ${otherSource}; this build of ${rel(filePath)} replaces it.`,
1208
- );
1256
+ warnedOtherSource = `Warning: ${rel(write.dest)} was built from ${otherSource}; this build of ${rel(filePath)} replaces it.`;
1209
1257
  } else if (otherSource) {
1210
1258
  throw new AstryxError(
1211
1259
  `${rel(write.dest)} is the build output of another theme source, ${otherSource}, so this build does not replace it. Pick another ${elsewhere}.`,
@@ -1242,6 +1290,7 @@ function assertOutputsReplaceable(
1242
1290
  }
1243
1291
  // Warned only once nothing refuses the build, so it names a write that
1244
1292
  // happens.
1293
+ if (warnedOtherSource) logger.warn(warnedOtherSource);
1245
1294
  if (editorFolder) {
1246
1295
  const dir = path.dirname(writes[0].dest);
1247
1296
  const warning = `Warning: ${rel(dir) || '.'} is a folder the theme editor made, and ${rel(filePath)} is outside it; the build writes there anyway. Build beside the source, or pick another ${elsewhere}, to keep the editor's folder to its own theme.`;
@@ -1387,7 +1436,9 @@ function toIdentifier(name) {
1387
1436
  * @returns {string}
1388
1437
  */
1389
1438
  export function importSpecifier(relDir, base) {
1390
- const normalized = relDir === '.' ? '' : relDir;
1439
+ // An import specifier always uses `/`. On Windows the cwd-relative dir comes
1440
+ // from path.relative with `\`, which would print `./\themes\ocean/ocean`.
1441
+ const normalized = relDir === '.' ? '' : relDir.split(path.sep).join('/');
1391
1442
  const withinSrc = normalized.replace(/^src\/?/, '').replace(/\/+$/, '');
1392
1443
  return withinSrc ? `./${withinSrc}/${base}` : `./${base}`;
1393
1444
  }
@@ -3608,26 +3659,29 @@ function validateHeadingTypeAugmentationSupport(themeDef) {
3608
3659
  * `logger` (silent by default).
3609
3660
  *
3610
3661
  * @param {string} file - Theme file path, resolved against `cwd`.
3611
- * @param {{out?: string, check?: boolean, iconsSpecifier?: string, __prepareFamily?: boolean, __familyLoader?: any, __familyInterception?: any, __onPrivateVarError?: () => void, __writeRoot?: string, __claimedOutputs?: Map<string, string>, __deferredWrites?: Array<Array<{dest: string, content: string}>>, __commandWords?: {group: string, build: string}, __onEditorFolder?: (warning: string) => void}} [options] -
3662
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options] -
3612
3663
  * `out` overrides the output CSS path, or names the folder for it; `check` compares against on-disk outputs
3613
- * instead of writing. `__claimedOutputs` records the outputs earlier builds
3614
- * in one run wrote, so a later theme cannot replace them; with
3615
- * `__deferredWrites` the build adds its outputs to that list instead of
3616
- * writing them, for writeDeferredBuildOutputs. `__writeRoot` replaces `cwd` as the directory every
3617
- * output must stay inside, for a CLI-internal scratch build. `__onEditorFolder`
3618
- * takes the editor-folder warning instead of the logger. `iconsSpecifier` overrides the icon registry import
3664
+ * instead of writing. `iconsSpecifier` overrides the icon registry import
3619
3665
  * specifier in the generated module (e.g. `./icons.mjs`); when omitted, the
3620
3666
  * direct registry specifiers from the theme source are emitted unchanged.
3621
3667
  * @param {{cwd?: string, projectCore?: boolean}} [ctx] `projectCore`: only the
3622
3668
  * project's installed Core (spec AST-081 FR3)
3669
+ * @param {{compact?: boolean, trailers?: ThemeBuildTrailer[]}} [report]
3670
+ * @param {ThemeBuildHandOff} [handOff] - what the CLI's batch, family, and
3671
+ * scratch builds hand a build; never an option of the public themeBuild.
3623
3672
  * @returns {Promise<any>}
3624
3673
  */
3625
3674
  async function themeBuildInternal(
3626
3675
  file,
3627
3676
  options = {},
3628
3677
  {cwd = process.cwd(), projectCore = false} = {},
3629
- /** @type {{compact?: boolean, trailers?: ThemeBuildTrailer[]}} */ report = {},
3678
+ report = {},
3679
+ handOff = {},
3630
3680
  ) {
3681
+ // A backslash in --out separates folders on every platform, as it does in
3682
+ // the other theme paths (a Windows path copied into a POSIX shell).
3683
+ if (typeof options.out === 'string' && options.out.includes('\\'))
3684
+ options = {...options, out: options.out.replace(/\\/g, '/')};
3631
3685
  const filePath = path.resolve(cwd, file);
3632
3686
 
3633
3687
  if (!fs.existsSync(filePath)) {
@@ -3641,6 +3695,22 @@ async function themeBuildInternal(
3641
3695
  );
3642
3696
  }
3643
3697
 
3698
+ // A theme the theme editor made is built from its settings by the editor;
3699
+ // a plain build reads its settings module as last written (released CLIs
3700
+ // built it, so it still does, and says so).
3701
+ {
3702
+ const dir = path.dirname(filePath);
3703
+ const slug = path.basename(dir);
3704
+ if (
3705
+ (!handOff.commandWords || handOff.commandWords.group === 'theme') &&
3706
+ path.basename(filePath) === `${slug}.theme.ts` &&
3707
+ editorThemeRecord(dir)
3708
+ )
3709
+ (editorFolderListener ?? (w => logger.warn(w)))(
3710
+ `Warning: ${path.relative(cwd, filePath)} is a theme the theme editor made (${slug}.settings.json is beside it). This build reads ${slug}.settings.ts as last written; to build it from its settings, run ${formatCliCommand(`experimental theme editor show ${shellWord(slug)}`, cwd)}.`,
3711
+ );
3712
+ }
3713
+
3644
3714
  if (fs.statSync(filePath).isDirectory()) {
3645
3715
  throw new AstryxError(
3646
3716
  `${path.relative(cwd, filePath) || '.'} is a folder. Pass the theme file inside it.`,
@@ -3679,7 +3749,7 @@ async function themeBuildInternal(
3679
3749
  // shared loader so exact authored parent identity stays CLI-private instead
3680
3750
  // of becoming a public DefinedTheme field.
3681
3751
  const interception =
3682
- options.__familyInterception ??
3752
+ handOff.familyInterception ??
3683
3753
  (_generateAdaptationCSS && themeFolderResolvesCore(filePath)
3684
3754
  ? undefined
3685
3755
  : interceptCore(_coreThemeModule, _coreRootModule));
@@ -3704,7 +3774,7 @@ async function themeBuildInternal(
3704
3774
  const loaded = await extractThemeDefinition(
3705
3775
  filePath,
3706
3776
  interception,
3707
- options.__familyLoader,
3777
+ handOff.familyLoader,
3708
3778
  );
3709
3779
  const after = fs.readFileSync(filePath, 'utf8');
3710
3780
  if (before !== after || before === '') {
@@ -3719,9 +3789,64 @@ async function themeBuildInternal(
3719
3789
  } catch (e) {
3720
3790
  const err = /** @type {Error} */ (e);
3721
3791
  const shown = path.relative(cwd, filePath) || filePath;
3792
+ // A theme file that is a link and does not load: named with the file it
3793
+ // points to (some loaders read its relative imports from the link's
3794
+ // folder, others from the file's own), never with Node's require stack.
3795
+ // Only an unresolved relative import is about the link; any other
3796
+ // failure (a package not installed) keeps its own remedy.
3797
+ let link = null;
3798
+ try {
3799
+ if (
3800
+ fs.lstatSync(filePath).isSymbolicLink() &&
3801
+ /Cannot find (?:module|package) '\.\.?\//.test(err.message)
3802
+ )
3803
+ link = fs.realpathSync(filePath);
3804
+ } catch {
3805
+ link = null;
3806
+ }
3807
+ const message = err.message
3808
+ .replace(/\n+Require stack:(?:\n- [^\n]*)*/, '')
3809
+ .split(filePath)
3810
+ .join(shown);
3722
3811
  throw new AstryxError(
3723
- err.message.split(filePath).join(shown),
3724
- themeLoadSuggestions(err, shown, cwd),
3812
+ link
3813
+ ? `${shown} is a link to ${path.relative(cwd, link) || link}, and it could not be loaded (a relative import may be read from the link's folder or from the file's own, depending on the loader); build the file itself: ${message}`
3814
+ : message,
3815
+ link
3816
+ ? [
3817
+ {
3818
+ // The file itself, with its outputs kept inside the working
3819
+ // folder (beside the link) when the file is outside it.
3820
+ name: formatCliCommand(
3821
+ [
3822
+ 'theme',
3823
+ 'build',
3824
+ path.relative(cwd, link) || link,
3825
+ ...(path.relative(cwd, link).startsWith('..') ||
3826
+ path.isAbsolute(path.relative(cwd, link))
3827
+ ? [
3828
+ '--out',
3829
+ path
3830
+ .relative(
3831
+ cwd,
3832
+ path.join(
3833
+ path.dirname(filePath),
3834
+ `${path.basename(filePath).replace(/\.[^.]+$/, '')}.css`,
3835
+ ),
3836
+ )
3837
+ .split(path.sep)
3838
+ .join('/'),
3839
+ ]
3840
+ : []),
3841
+ ]
3842
+ .map(shellWord)
3843
+ .join(' '),
3844
+ cwd,
3845
+ ),
3846
+ reason: 'build the file itself',
3847
+ },
3848
+ ]
3849
+ : themeLoadSuggestions(err, shown, cwd),
3725
3850
  ERROR_CODES.ERR_THEME_LOAD,
3726
3851
  );
3727
3852
  }
@@ -3731,13 +3856,13 @@ async function themeBuildInternal(
3731
3856
  // JSON.stringify and Object.keys, so it could not reach output regardless.)
3732
3857
  // Both reads happen BEFORE the strip, which is what removes the evidence.
3733
3858
  const ancestryObserved =
3734
- !options.__prepareFamily ||
3859
+ !handOff.prepareFamily ||
3735
3860
  !interception ||
3736
3861
  interception.observed(themeDef) ||
3737
3862
  Object.hasOwn(themeDef, 'extends');
3738
- if (options.__prepareFamily && interception) interception.retain(themeDef);
3863
+ if (handOff.prepareFamily && interception) interception.retain(themeDef);
3739
3864
  const sourceParent =
3740
- options.__prepareFamily && interception
3865
+ handOff.prepareFamily && interception
3741
3866
  ? interception.parentOf(themeDef)
3742
3867
  : undefined;
3743
3868
  const adaptationLineage = interception
@@ -3796,7 +3921,7 @@ async function themeBuildInternal(
3796
3921
  // generation so neither the no-CSS return nor --check can bypass the error.
3797
3922
  // Family preparation keeps its own named-import registry contract, which
3798
3923
  // themeBuildFamily checks against the selected members' graph.
3799
- const standaloneIcons = !options.__prepareFamily;
3924
+ const standaloneIcons = !handOff.prepareFamily;
3800
3925
  // Function icon entries stay functions in the built module, beside a node
3801
3926
  // view bound to `<theme>IconNodes` and computed from `<theme>IconEntries`.
3802
3927
  const functionEntries =
@@ -3855,7 +3980,7 @@ async function themeBuildInternal(
3855
3980
  logger.error(` [error] ${source}${e}`);
3856
3981
  }
3857
3982
  if (privateVarErrors.length > 0) {
3858
- options.__onPrivateVarError?.();
3983
+ privateVarErrorListener?.();
3859
3984
  logger.error(
3860
3985
  `\n ${source}${privateVarErrors.length} private var error(s). Use standard CSS properties instead.`,
3861
3986
  );
@@ -4172,7 +4297,20 @@ async function themeBuildInternal(
4172
4297
  // Source path relative to cwd — used in @generated headers
4173
4298
  const sourceRelative = path.relative(cwd, filePath);
4174
4299
  // What `--check` prints to rebuild, from the working folder.
4175
- const rebuildCommand = `astryx theme build ${sourceRelative}${options.out ? ' --out ' + path.relative(cwd, path.resolve(cwd, options.out)) : ''}`;
4300
+ // The project's own invocation, each path quoted for the shell.
4301
+ const rebuildCommand = formatCliCommand(
4302
+ [
4303
+ 'theme',
4304
+ 'build',
4305
+ sourceRelative,
4306
+ ...(options.out
4307
+ ? ['--out', path.relative(cwd, path.resolve(cwd, options.out))]
4308
+ : []),
4309
+ ]
4310
+ .map(shellWord)
4311
+ .join(' '),
4312
+ cwd,
4313
+ );
4176
4314
  // Stable provenance recorded in @generated headers — versions, not a
4177
4315
  // timestamp, so identical inputs produce byte-identical output.
4178
4316
  const versions = resolveToolVersions(cwd);
@@ -4182,7 +4320,7 @@ async function themeBuildInternal(
4182
4320
  const baseName = themeDef.name;
4183
4321
  // Every write stays inside cwd. A CLI-internal caller that renders into a
4184
4322
  // scratch directory it creates and removes names that directory instead.
4185
- const writeRoot = options.__writeRoot ?? cwd;
4323
+ const writeRoot = handOff.writeRoot ?? cwd;
4186
4324
  let outPath;
4187
4325
  if (options.out) {
4188
4326
  outPath = path.resolve(cwd, options.out);
@@ -4262,7 +4400,7 @@ async function themeBuildInternal(
4262
4400
  'export {};\n';
4263
4401
  // A family member's module is generated by themeBuildFamily, which carries
4264
4402
  // its registries and slot functions through the family's own imports.
4265
- const jsContent = options.__prepareFamily
4403
+ const jsContent = handOff.prepareFamily
4266
4404
  ? ''
4267
4405
  : generatedHeader(headerSource, 'js', buildCommand, versions) +
4268
4406
  generateBuiltModule(
@@ -4292,7 +4430,7 @@ async function themeBuildInternal(
4292
4430
  ]),
4293
4431
  ];
4294
4432
 
4295
- if (options.__prepareFamily) {
4433
+ if (handOff.prepareFamily) {
4296
4434
  return {
4297
4435
  filePath,
4298
4436
  sourceRelative: sourceRelative.split(path.sep).join('/'),
@@ -4333,10 +4471,10 @@ async function themeBuildInternal(
4333
4471
  // of a CLI before 0.6.7, which the build has always replaced. A path that
4334
4472
  // --out names may hold anything, so there only build outputs are replaced.
4335
4473
  assertOutputsReplaceable(writes, filePath, cwd, {
4336
- claimed: options.__claimedOutputs,
4474
+ claimed: handOff.claimedOutputs,
4337
4475
  rerun,
4338
4476
  refuseUnmarked: Boolean(options.out),
4339
- onEditorFolder: options.__onEditorFolder,
4477
+ onEditorFolder: editorFolderListener ?? undefined,
4340
4478
  });
4341
4479
  }
4342
4480
 
@@ -4366,7 +4504,7 @@ async function themeBuildInternal(
4366
4504
  if (remedy) logger.error(`\n ${remedy.join('\n ')}`);
4367
4505
  else
4368
4506
  logger.error(
4369
- `\n Rebuild with: ${rebuildLine(rebuildCommand, options.__commandWords)}`,
4507
+ `\n Rebuild with: ${rebuildLine(rebuildCommand, handOff.commandWords)}`,
4370
4508
  );
4371
4509
  }
4372
4510
  warnMissingDeclarations(writes, cwd);
@@ -4385,10 +4523,10 @@ async function themeBuildInternal(
4385
4523
 
4386
4524
  // A batch publishes every theme's outputs after all of them are built, so
4387
4525
  // two themes that build the same files are refused before either writes.
4388
- if (options.__deferredWrites) options.__deferredWrites.push(writes);
4526
+ if (handOff.deferredWrites) handOff.deferredWrites.push(writes);
4389
4527
  else writeBuildOutputs(writes);
4390
4528
  for (const write of writes) {
4391
- options.__claimedOutputs?.set(outputKey(write.dest), sourceRelative);
4529
+ handOff.claimedOutputs?.set(outputKey(write.dest), sourceRelative);
4392
4530
  }
4393
4531
 
4394
4532
  if (!report.compact) {
@@ -4612,6 +4750,7 @@ function groupUnloadedFonts(trailers) {
4612
4750
  * @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options]
4613
4751
  * @param {{cwd?: string}} [ctx]
4614
4752
  * @param {{compact?: boolean}} [report]
4753
+ * @param {ThemeBuildHandOff} [handOff]
4615
4754
  * @returns {Promise<{receipt: import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null, trailer: ThemeBuildTrailer | null}>}
4616
4755
  */
4617
4756
  export async function themeBuildForReport(
@@ -4619,18 +4758,38 @@ export async function themeBuildForReport(
4619
4758
  options = {},
4620
4759
  ctx = {},
4621
4760
  {compact = false} = {},
4761
+ handOff = {},
4622
4762
  ) {
4623
4763
  /** @type {ThemeBuildTrailer[]} */
4624
4764
  const trailers = [];
4625
4765
  const receipt = /** @type {any} */ (
4626
- await themeBuildInternal(file, options, ctx, {compact, trailers})
4766
+ await themeBuildInternal(file, options, ctx, {compact, trailers}, handOff)
4627
4767
  );
4628
4768
  return {receipt, trailer: trailers[0] ?? null};
4629
4769
  }
4630
4770
 
4631
4771
  /** @param {string} file @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options] @param {{cwd?: string, projectCore?: boolean}} [ctx] `projectCore`: read only the project's installed Core, never the carried one (doctor; spec AST-081 FR3) @returns {Promise<import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null>} */
4632
4772
  export async function themeBuild(file, options = {}, ctx = {}) {
4633
- return /** @type {any} */ (themeBuildInternal(file, options, ctx));
4773
+ const {out, check, iconsSpecifier} = options;
4774
+ return /** @type {any} */ (
4775
+ themeBuildInternal(file, {out, check, iconsSpecifier}, ctx)
4776
+ );
4777
+ }
4778
+
4779
+ /**
4780
+ * {@link themeBuild} with the CLI's hand-off: the same build, outputs, and
4781
+ * receipt, plus what only the CLI's batch and scratch builds pass.
4782
+ * CLI-internal: not exported from the API entry.
4783
+ * @param {string} file
4784
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string}} options
4785
+ * @param {{cwd?: string, projectCore?: boolean}} ctx
4786
+ * @param {ThemeBuildHandOff} handOff
4787
+ * @returns {Promise<import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null>}
4788
+ */
4789
+ export async function themeBuildWithHandOff(file, options, ctx, handOff) {
4790
+ return /** @type {any} */ (
4791
+ themeBuildInternal(file, options, ctx, {}, handOff)
4792
+ );
4634
4793
  }
4635
4794
  /** @param {string} name */
4636
4795
  // prettier-ignore
@@ -4769,11 +4928,12 @@ async function preloadFamilySource(filePath, loader, interception) {
4769
4928
  finally { patch.undo(); }
4770
4929
  }
4771
4930
 
4772
- /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void, __commandWords?: {group: string, build: string}}} options @param {{cwd?: string}} [ctx] */
4931
+ /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string}} options @param {{cwd?: string}} [ctx] @param {{commandWords?: {group: string, build: string}}} [handOff] - the CLI's words for the rebuild hint */
4773
4932
  export async function themeBuildFamily(
4774
4933
  files,
4775
4934
  options,
4776
4935
  {cwd = process.cwd()} = {},
4936
+ handOff = {},
4777
4937
  ) {
4778
4938
  if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(options?.familyKey ?? '')) {
4779
4939
  throw new AstryxError(
@@ -4806,7 +4966,7 @@ export async function themeBuildFamily(
4806
4966
  }
4807
4967
  const file = source.file;
4808
4968
  // prettier-ignore
4809
- const member = await themeBuildInternal(file, {iconsSpecifier: options.iconsSpecifier, __prepareFamily: true, __familyLoader: familyLoader, __familyInterception: familyInterception, __onPrivateVarError: options.__onPrivateVarError}, {cwd});
4969
+ const member = await themeBuildInternal(file, {iconsSpecifier: options.iconsSpecifier}, {cwd}, {}, {prepareFamily: true, familyLoader, familyInterception});
4810
4970
  if (!member || member.type) {
4811
4971
  throw new AstryxError(
4812
4972
  `Theme family member "${file}" did not produce a complete build plan.`,
@@ -5037,7 +5197,7 @@ export async function themeBuildFamily(
5037
5197
  if (remedy) logger.error(`\n ${remedy.join('\n ')}`);
5038
5198
  else
5039
5199
  logger.error(
5040
- `\n Rebuild with: ${rebuildLine(rebuildCommand, options.__commandWords)}`,
5200
+ `\n Rebuild with: ${rebuildLine(rebuildCommand, handOff.commandWords)}`,
5041
5201
  );
5042
5202
  }
5043
5203
  warnMissingDeclarations(writes, cwd);