@astryxdesign/cli 0.7.4-canary.e5c5a87 → 0.7.4-canary.eccc6ee

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 (78) hide show
  1. package/README.md +63 -63
  2. package/api/docs/_adapter.d.mts +80 -0
  3. package/api/docs/_adapter.mjs +248 -5
  4. package/api/docs/detail/detail.mjs +8 -0
  5. package/api/docs/docs.doc.mjs +1 -1
  6. package/api/docs/docs.type.d.mts +28 -2
  7. package/api/docs/docs.type.mjs +13 -3
  8. package/api/docs/guide-route-targets.test.mjs +998 -0
  9. package/api/docs/index/index.mjs +9 -0
  10. package/api/docs/list/list.mjs +7 -1
  11. package/api/docs/node/node.mjs +9 -1
  12. package/api/docs/reference-blocks.test.mjs +1 -1
  13. package/api/doctor/built-checks.mjs +43 -13
  14. package/api/doctor/built-checks.test.mjs +29 -0
  15. package/api/doctor/doctor.doc.mjs +1 -1
  16. package/api/integration/_adapter.d.mts +8 -0
  17. package/api/integration/_adapter.mjs +25 -0
  18. package/api/integration/authoring-checks.mjs +29 -2
  19. package/api/integration/pack-check.mjs +32 -1
  20. package/api/integration/pack-check.test.mjs +33 -0
  21. package/api/integration/validate-integration.mjs +66 -1
  22. package/api/integration/validateIntegration.doc.mjs +1 -1
  23. package/api/search/_candidate-score.d.mts +3 -2
  24. package/api/search/_candidate-score.mjs +66 -3
  25. package/api/search/_gather-docs.mjs +12 -2
  26. package/api/search/_priority.mjs +2 -1
  27. package/api/search/_score.d.mts +2 -1
  28. package/api/search/_score.mjs +2 -2
  29. package/api/search/search.family-members.test.mjs +124 -0
  30. package/assets/discover/official-packages.json +16 -0
  31. package/assets/docs/browser-support.doc.mjs +1 -1
  32. package/assets/docs/theme.doc.mjs +2 -2
  33. package/assets/docs/tree/component-lookups.doc.mjs +2 -1
  34. package/assets/docs/tree/extend-or-replace.doc.mjs +36 -4
  35. package/assets/docs/tree/migration.doc.mjs +2 -1
  36. package/assets/docs/tree/styling-libraries.doc.mjs +2 -1
  37. package/assets/docs/tree/styling.doc.mjs +1 -1
  38. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +54 -0
  39. package/assets/templates/themes/butter/butterPalettes.generated.receipt.json +1499 -0
  40. package/assets/templates/themes/butter/butterPalettes.generated.ts +550 -0
  41. package/assets/templates/themes/butter/butterTheme.ts +274 -234
  42. package/assets/templates/themes/butter/palette.config.json +484 -0
  43. package/assets/templates/themes/gothic/gothicPaletteRefs.generated.ts +41 -0
  44. package/assets/templates/themes/gothic/gothicPalettes.generated.receipt.json +979 -0
  45. package/assets/templates/themes/gothic/gothicPalettes.generated.ts +271 -0
  46. package/assets/templates/themes/gothic/gothicTheme.ts +130 -160
  47. package/assets/templates/themes/gothic/palette.config.json +371 -0
  48. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +51 -0
  49. package/assets/templates/themes/matcha/matchaPalettes.generated.receipt.json +1502 -0
  50. package/assets/templates/themes/matcha/matchaPalettes.generated.ts +501 -0
  51. package/assets/templates/themes/matcha/matchaPalettes.ts +21 -0
  52. package/assets/templates/themes/matcha/matchaTheme.ts +164 -103
  53. package/assets/templates/themes/matcha/palette.config.json +448 -0
  54. package/assets/templates/themes/y2k/palette.config.json +166 -0
  55. package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +54 -0
  56. package/assets/templates/themes/y2k/y2kPalettes.generated.receipt.json +872 -0
  57. package/assets/templates/themes/y2k/y2kPalettes.generated.ts +550 -0
  58. package/assets/templates/themes/y2k/y2kPalettes.ts +257 -0
  59. package/assets/templates/themes/y2k/y2kTheme.ts +164 -391
  60. package/authoring/doctypes/_schema.d.mts +4 -0
  61. package/authoring/doctypes/_schema.mjs +4 -0
  62. package/authoring/doctypes/reference/type.ts +14 -2
  63. package/clients/cli/commands/docs.mjs +27 -2
  64. package/clients/cli/commands/docs.test.mjs +1 -1
  65. package/foundation/agent-docs/agent-docs.d.mts +14 -2
  66. package/foundation/agent-docs/agent-docs.mjs +54 -2
  67. package/foundation/agent-docs/agent-docs.test.mjs +61 -0
  68. package/foundation/discovery/docs-discovery.d.mts +93 -2
  69. package/foundation/discovery/docs-discovery.mjs +236 -8
  70. package/foundation/doc-compiler/compile.mjs +8 -1
  71. package/foundation/doc-compiler/doc-loads.test.mjs +3 -0
  72. package/foundation/doc-compiler/tree.d.mts +5 -0
  73. package/foundation/doc-compiler/tree.mjs +3 -0
  74. package/foundation/integrations/cli-requirement.d.mts +14 -0
  75. package/foundation/integrations/cli-requirement.mjs +23 -0
  76. package/foundation/integrations/cli-requirement.test.mjs +1 -0
  77. package/foundation/response/response-types.doc.mjs +5 -5
  78. package/package.json +9 -9
@@ -35,6 +35,15 @@ export async function index(topic, options = {}) {
35
35
  ...view,
36
36
  // A guide the docs tree places is read by its route, not its doc name.
37
37
  name: entry.tree ? entry.name : view.name,
38
+ // What it took the place of, and whose that was (INV28).
39
+ ...(entry.replaces != null
40
+ ? {
41
+ replaces: entry.replaces,
42
+ ...(entry.replacedPackage != null
43
+ ? {replacedPackage: entry.replacedPackage}
44
+ : {}),
45
+ }
46
+ : {}),
38
47
  // Each section names the package that wrote it: the topic's own, or an
39
48
  // extension's.
40
49
  sections: view.sections.map(s => ({
@@ -52,7 +52,13 @@ export async function list({cwd} = {}) {
52
52
  ),
53
53
  package: entry.package,
54
54
  };
55
- if (entry.replaces != null) listed.replaces = entry.replaces;
55
+ if (entry.replaces != null) {
56
+ listed.replaces = entry.replaces;
57
+ // INV28: the package whose topic it replaced, beside its own.
58
+ if (entry.replacedPackage != null) {
59
+ listed.replacedPackage = entry.replacedPackage;
60
+ }
61
+ }
56
62
  entries.push(listed);
57
63
  }
58
64
  // The docs tree's top-level namespaces, the CLI's and each integration's,
@@ -94,7 +94,15 @@ function childIdentity(child) {
94
94
  return {
95
95
  route: child.route,
96
96
  name: child.route.slice(child.route.lastIndexOf('/') + 1),
97
- package: child.provider,
97
+ package: child.guideOverlay?.replacement?.package ?? child.provider,
98
+ // A guide an integration's doc took the place of names whose it was.
99
+ ...(child.guideOverlay?.replacement
100
+ ? {
101
+ replaces: child.route,
102
+ replacedPackage:
103
+ child.guideOverlay.replacedPackage ?? child.provider,
104
+ }
105
+ : {}),
98
106
  kind: child.kind,
99
107
  title: child.title,
100
108
  summary: child.summary,
@@ -259,7 +259,7 @@ describe('a reference block in a topic section', () => {
259
259
  /^docs\(\): Read the reference docs: .* Read it with `astryx docs cli\/api\/functions\/docs`\.$/,
260
260
  );
261
261
  expect(more[1].text).toMatch(
262
- /^Theme System: .* Read it with `astryx docs theme`\.$/,
262
+ /^Theming: .* Read it with `astryx docs theme`\.$/,
263
263
  );
264
264
  },
265
265
  SLOW,
@@ -9,7 +9,7 @@
9
9
  * built `.html` page or a source file), and the package names whose
10
10
  * components count as Astryx: every `@astryxdesign/*` package and each
11
11
  * integration the project loads (its component catalog's providers).
12
- * @output `built-astryx-usage`: fails when the path holds no import from those
12
+ * @output `built-astryx-usage`: fails when the path holds no value import from those
13
13
  * packages, no use of a component imported from them, and no Astryx
14
14
  * stylesheet in built CSS or HTML. `built-astryx-purity`: warns with the
15
15
  * findings of the source check in `astryx docs is-my-code-good` (raw
@@ -323,12 +323,17 @@ function astImports(ast) {
323
323
  /** @type {{spec: string, names: string[], at: number}[]} */
324
324
  const found = [];
325
325
  for (const node of ast.program.body) {
326
+ // A type-only import or re-export is erased from the built page, so it
327
+ // is not Astryx use.
328
+ if (node.importKind === 'type' || node.exportKind === 'type') continue;
326
329
  if (node.type === 'ImportDeclaration') {
330
+ const values = node.specifiers.filter(
331
+ (/** @type {any} */ each) => each.importKind !== 'type',
332
+ );
333
+ if (node.specifiers.length > 0 && values.length === 0) continue;
327
334
  found.push({
328
335
  spec: node.source.value,
329
- names: node.specifiers.map(
330
- (/** @type {any} */ each) => each.local.name,
331
- ),
336
+ names: values.map((/** @type {any} */ each) => each.local.name),
332
337
  at: node.start,
333
338
  });
334
339
  } else if (
@@ -336,6 +341,15 @@ function astImports(ast) {
336
341
  node.type === 'ExportAllDeclaration') &&
337
342
  node.source
338
343
  ) {
344
+ const specifiers = node.specifiers ?? [];
345
+ if (
346
+ specifiers.length > 0 &&
347
+ specifiers.every(
348
+ (/** @type {any} */ each) => each.exportKind === 'type',
349
+ )
350
+ ) {
351
+ continue;
352
+ }
339
353
  found.push({spec: node.source.value, names: [], at: node.start});
340
354
  }
341
355
  }
@@ -406,14 +420,26 @@ function importsOf(text) {
406
420
  /** @type {{spec: string, names: string[], at: number}[]} */
407
421
  const found = [];
408
422
  const fromImport =
409
- /\bimport\s+(?:type\s+)?([^'";]*?)\s+from\s+['"]([^'"]+)['"]|\bimport\s+['"]([^'"]+)['"]/g;
423
+ /\bimport\s+(type\s+)?([^'";]*?)\s+from\s+['"]([^'"]+)['"]|\bimport\s+['"]([^'"]+)['"]/g;
424
+ /** Whether every name in a `{…}` list is marked `type`. */
425
+ const allTypes = (/** @type {string} */ list) => {
426
+ const parts = list
427
+ .split(',')
428
+ .map(part => part.trim())
429
+ .filter(Boolean);
430
+ return parts.length > 0 && parts.every(part => /^type\s/.test(part));
431
+ };
410
432
  for (const match of text.matchAll(fromImport)) {
411
433
  const at = /** @type {number} */ (match.index);
412
- if (match[3]) {
413
- found.push({spec: match[3], names: [], at});
434
+ if (match[4]) {
435
+ found.push({spec: match[4], names: [], at});
414
436
  continue;
415
437
  }
416
- const clause = match[1];
438
+ // A type-only import is erased from the build, so it is not use.
439
+ if (match[1]) continue;
440
+ const clause = match[2];
441
+ const onlyBraces = /^\{([\s\S]*)\}$/.exec(clause.trim());
442
+ if (onlyBraces && allTypes(onlyBraces[1])) continue;
417
443
  /** @type {string[]} */
418
444
  const names = [];
419
445
  const braces = /\{([\s\S]*)\}/.exec(clause);
@@ -433,14 +459,18 @@ function importsOf(text) {
433
459
  const name = part.trim().replace(/^\*\s+as\s+/, '');
434
460
  if (/^[A-Za-z_$][\w$]*$/.test(name)) names.push(name);
435
461
  }
436
- found.push({spec: match[2], names, at});
462
+ found.push({spec: match[3], names, at});
437
463
  }
438
- // A barrel that re-exports a package reaches it as an import does.
464
+ // A barrel that re-exports a package reaches it as an import does; a
465
+ // type-only re-export is erased like a type-only import.
439
466
  for (const match of text.matchAll(
440
- /\bexport\s+(?:type\s+)?(?:\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})\s*from\s+['"]([^'"]+)['"]/g,
467
+ /\bexport\s+(type\s+)?(\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})\s*from\s+['"]([^'"]+)['"]/g,
441
468
  )) {
469
+ if (match[1]) continue;
470
+ const list = /^\{([\s\S]*)\}$/.exec(match[2]);
471
+ if (list && allTypes(list[1])) continue;
442
472
  found.push({
443
- spec: match[1],
473
+ spec: match[3],
444
474
  names: [],
445
475
  at: /** @type {number} */ (match.index),
446
476
  });
@@ -738,7 +768,7 @@ export function checkBuilt(target, {cwd, packages}) {
738
768
  id: 'built-astryx-usage',
739
769
  label: 'Built output uses Astryx',
740
770
  status: 'fail',
741
- message: `Read ${read}: no import from an Astryx package, no Astryx component, and no Astryx styles, so this output does not use Astryx.`,
771
+ message: `Read ${read}: no value import from an Astryx package (a type-only import is erased from the build), no Astryx component, and no Astryx styles, so this output does not use Astryx.`,
742
772
  fix: `Rebuild the page from an Astryx template: run \`${formatCliCommand('build "<what the page is>"', cwd)}\`, scaffold the template it names, and fill it with Astryx components. Do not deliver this output.`,
743
773
  };
744
774
  const unreadNames =
@@ -425,6 +425,35 @@ describe('--built edge cases', () => {
425
425
  expect(check('dist').usage.status).toBe('fail');
426
426
  });
427
427
 
428
+ it('does not count a type-only Astryx import as use', () => {
429
+ write({
430
+ 'src/Page.tsx': [
431
+ "import type {ButtonProps} from '@astryxdesign/core/Button';",
432
+ "import {type TextProps} from '@astryxdesign/core/Text';",
433
+ "export type {CardProps} from '@astryxdesign/core/Card';",
434
+ "export {type BadgeProps} from '@astryxdesign/core/Badge';",
435
+ 'export const Page = (props: ButtonProps & TextProps) => null;',
436
+ '',
437
+ ].join('\n'),
438
+ });
439
+ expect(check('src').usage.status).toBe('fail');
440
+ });
441
+
442
+ it('does not count a type-only import in a file the parser cannot read', () => {
443
+ write({
444
+ 'src/Broken.tsx': [
445
+ "import type {ButtonProps} from '@astryxdesign/core/Button';",
446
+ "import {type TextProps} from '@astryxdesign/core/Text';",
447
+ "export type {CardProps} from '@astryxdesign/core/Card';",
448
+ "export {type BadgeProps} from '@astryxdesign/core/Badge';",
449
+ 'export const B = () => <div>{</div>;',
450
+ '@@ enum ;',
451
+ '',
452
+ ].join('\n'),
453
+ });
454
+ expect(check('src').usage.status).not.toBe('pass');
455
+ });
456
+
428
457
  it('does not count an import written only in a string or JSX text', () => {
429
458
  write({
430
459
  'src/Page.tsx': [
@@ -41,7 +41,7 @@ export const doc = {
41
41
  name: 'options.built',
42
42
  type: 'string',
43
43
  description:
44
- 'A finished build to check before you deliver it: a project folder, a build output folder, or one built `.html` file, relative to `cwd`. Adds two checks after the others. `built-astryx-usage` fails when the path holds no import from an Astryx package (any `@astryxdesign/*` package or an integration the project installs), no component imported from one, and no Astryx styles in built CSS or HTML. `built-astryx-purity` warns with the source check of `astryx docs is-my-code-good`: raw elements Astryx has a component for, raw SVG and icon-library icons, inline styles, classes, `stylex.create` and imported stylesheets, each with its file and line, in `.tsx` and `.jsx` files and JSX in `.js` source, found by parsing it; it is info, not inspected, when the path holds no source with JSX, such as a bundle. It reads at most 20,000 files, each up to 5 MB, skipping installs and version control; when either limit leaves source unread and nothing was found, the purity check is info, not fully inspected, and when the file limit ends the read before any Astryx turns up, `built-astryx-usage` warns that the rest went unread instead of failing. Given one built `.html` file, it also reads the local stylesheets and scripts that page links, finding a root-relative link from the nearest folder above the page that holds it; a linked file that is not there makes `built-astryx-usage` warn instead of fail. An empty folder fails with nothing checked, like a missing path. A source tree counts as using Astryx through an import, a re-export (`export … from`) or a stylesheet `@import` of an Astryx package. `--built` goes with `doctor` alone; a `doctor integration` check refuses it. A path that does not exist fails `built-astryx-usage` with nothing checked, and the purity check is left out. The integrations that count are the dependencies the nearest package.json above the path declares whose installed copy, found the way the CLI autolinks (a hoisted workspace copy included), has an integration manifest. The files under the path, and that configuration, are only read, never run. Without it, doctor runs exactly as before.',
44
+ 'A finished build to check before you deliver it: a project folder, a build output folder, or one built `.html` file, relative to `cwd`. Adds two checks after the others. `built-astryx-usage` fails when the path holds no value import from an Astryx package (any `@astryxdesign/*` package or an integration the project installs), no component imported from one, and no Astryx styles in built CSS or HTML. `built-astryx-purity` warns with the source check of `astryx docs is-my-code-good`: raw elements Astryx has a component for, raw SVG and icon-library icons, inline styles, classes, `stylex.create` and imported stylesheets, each with its file and line, in `.tsx` and `.jsx` files and JSX in `.js` source, found by parsing it; it is info, not inspected, when the path holds no source with JSX, such as a bundle. It reads at most 20,000 files, each up to 5 MB, skipping installs and version control; when either limit leaves source unread and nothing was found, the purity check is info, not fully inspected, and when the file limit ends the read before any Astryx turns up, `built-astryx-usage` warns that the rest went unread instead of failing. Given one built `.html` file, it also reads the local stylesheets and scripts that page links, finding a root-relative link from the nearest folder above the page that holds it; a linked file that is not there makes `built-astryx-usage` warn instead of fail. An empty folder fails with nothing checked, like a missing path. A source tree counts as using Astryx through an import, a re-export (`export … from`) or a stylesheet `@import` of an Astryx package; a type-only import or re-export (`import type`, `export type`, or a list whose names are all `type`) does not count, since the build erases it. `--built` goes with `doctor` alone; a `doctor integration` check refuses it. A path that does not exist fails `built-astryx-usage` with nothing checked, and the purity check is left out. The integrations that count are the dependencies the nearest package.json above the path declares whose installed copy, found the way the CLI autolinks (a hoisted workspace copy included), has an integration manifest. The files under the path, and that configuration, are only read, never run. Without it, doctor runs exactly as before.',
45
45
  },
46
46
  ],
47
47
  returns: [
@@ -40,6 +40,14 @@ export function integrationFluff(discovered: Parameters<typeof findFluff>[0]): P
40
40
  * read too
41
41
  */
42
42
  export function integrationStrayPointers(discovered: Parameters<typeof findStrayPointers>[0], integration?: any): Promise<import("./authoring-checks.type.mjs").StrayPointer[]>;
43
+ /**
44
+ * What each doc in one integration's docs replaces or extends, read against
45
+ * the CLI's docs and the package's own (see `packageDocTargets`); empty when
46
+ * the docs do not load, which other checks report.
47
+ * @param {any} integration a loaded integration
48
+ * @returns {Promise<import('../docs/_adapter.mjs').DocTarget[]>}
49
+ */
50
+ export function integrationDocTargets(integration: any): Promise<import("../docs/_adapter.mjs").DocTarget[]>;
43
51
  /**
44
52
  * Each Astryx command a package's topics write with a package runner. A
45
53
  * package whose topics cannot be discovered has none here: the other checks
@@ -16,6 +16,7 @@ import {
16
16
  integrationSourceForDoc,
17
17
  } from '../../foundation/discovery/component-discovery.mjs';
18
18
  import {discoverIntegrationDocs} from '../../foundation/discovery/docs-discovery.mjs';
19
+ import {packageDocTargets} from '../docs/_adapter.mjs';
19
20
  import {comparePropDocs} from '../../foundation/discovery/prop-drift.mjs';
20
21
  import {findCopiedPassages} from '../../foundation/discovery/copied-passages.mjs';
21
22
  import {findFluff} from '../../foundation/discovery/doc-fluff.mjs';
@@ -114,6 +115,30 @@ export async function integrationStrayPointers(discovered, integration) {
114
115
  return findStrayPointers({...discovered, components});
115
116
  }
116
117
 
118
+ /**
119
+ * What each doc in one integration's docs replaces or extends, read against
120
+ * the CLI's docs and the package's own (see `packageDocTargets`); empty when
121
+ * the docs do not load, which other checks report.
122
+ * @param {any} integration a loaded integration
123
+ * @returns {Promise<import('../docs/_adapter.mjs').DocTarget[]>}
124
+ */
125
+ export async function integrationDocTargets(integration) {
126
+ let discovered;
127
+ try {
128
+ discovered = await discoverIntegrationDocs(integration);
129
+ } catch {
130
+ return [];
131
+ }
132
+ // A doc that does not load is an issue already; its targets are not read.
133
+ if (discovered.errors.length > 0) return [];
134
+ try {
135
+ return await packageDocTargets(integration, discovered);
136
+ } catch {
137
+ // A package whose docs cannot form a tree is reported by the docs check.
138
+ return [];
139
+ }
140
+ }
141
+
117
142
  /**
118
143
  * Each Astryx command a package's topics write with a package runner. A
119
144
  * package whose topics cannot be discovered has none here: the other checks
@@ -22,6 +22,7 @@ import path from 'node:path';
22
22
  import {getCliInvocation} from '../../foundation/env/package-manager.mjs';
23
23
  import {
24
24
  packageComponentLinkProblems,
25
+ packageDocTargets,
25
26
  packageDocsProblems,
26
27
  packageReferenceProblems,
27
28
  } from '../docs/_adapter.mjs';
@@ -38,8 +39,10 @@ import {
38
39
  integrationStrayPointers,
39
40
  } from './_adapter.mjs';
40
41
  import {
42
+ BUILTIN_DOCS_PACKAGE,
41
43
  discoverBuiltinTopics,
42
44
  discoverIntegrationDocs,
45
+ isGuideRoute,
43
46
  } from '../../foundation/discovery/docs-discovery.mjs';
44
47
  import {
45
48
  applyTemplateReplacements,
@@ -489,11 +492,14 @@ export async function integrationDocConflicts(pkg, options = {}) {
489
492
  });
490
493
  }
491
494
 
492
- // An extension never owns its own name. A replacement does, so it may only
493
- // reuse a Core name when that is the Core topic it explicitly replaces.
495
+ // An extension never owns its own name, and neither does a doc that
496
+ // replaces a guide by its route: readers open the route. A topic
497
+ // replacement does, so it may only reuse a Core name when that is the
498
+ // Core topic it explicitly replaces.
494
499
  if (
495
500
  sameNameCore != null &&
496
501
  record.extendsTopic == null &&
502
+ !isGuideRoute(record.replaces) &&
497
503
  replacedCore !== sameNameCore
498
504
  ) {
499
505
  findings.push({
@@ -507,6 +513,27 @@ export async function integrationDocConflicts(pkg, options = {}) {
507
513
  });
508
514
  }
509
515
  }
516
+ // A doc that replaces or extends one of the CLI's guides by its route is
517
+ // as intentional as one that names a Core topic.
518
+ if (errors.length === 0) {
519
+ for (const target of await packageDocTargets(
520
+ /** @type {{name: string}} */ (docsIntegration),
521
+ discovered,
522
+ )) {
523
+ if (target.kind !== 'guide' || target.owner !== BUILTIN_DOCS_PACKAGE) {
524
+ continue;
525
+ }
526
+ // A route the guide moved from names the guide at its route now.
527
+ const route = target.guide ?? target.target;
528
+ findings.push({
529
+ topic: target.topic,
530
+ severity: 'info',
531
+ relationship: target.relationship,
532
+ coreTopic: route,
533
+ message: `Intentional ${target.relationship === 'replaces' ? 'override' : 'extension'}: "${target.topic}" ${target.relationship} the CLI guide "${route}".`,
534
+ });
535
+ }
536
+ }
510
537
  findings.sort((a, b) =>
511
538
  `${a.topic}:${a.relationship}`.localeCompare(
512
539
  `${b.topic}:${b.relationship}`,
@@ -37,6 +37,7 @@ import {
37
37
  keywordsCliProblem,
38
38
  replacesCliProblem,
39
39
  sectionIdsCliProblem,
40
+ sectionPositionCliProblem,
40
41
  themesCliProblem,
41
42
  } from '../../foundation/integrations/cli-requirement.mjs';
42
43
  import {
@@ -328,13 +329,27 @@ function extractTarball(tgzPath, extractDir) {
328
329
  * @returns {Promise<boolean>}
329
330
  */
330
331
  async function setsSectionIds(files) {
332
+ return setsSectionField(files, ['id']);
333
+ }
334
+
335
+ /**
336
+ * Whether any of these doc files has a section that sets one of `fields`.
337
+ * @param {string[]} files
338
+ * @param {string[]} fields
339
+ * @returns {Promise<boolean>}
340
+ */
341
+ async function setsSectionField(files, fields) {
331
342
  for (const file of files) {
332
343
  if (typeof file !== 'string') continue;
333
344
  const doc = /** @type {any} */ (
334
345
  await loadTopicModule(file).catch(() => null)
335
346
  );
336
347
  const sections = Array.isArray(doc?.sections) ? doc.sections : [];
337
- if (sections.some((/** @type {any} */ section) => section?.id != null)) {
348
+ if (
349
+ sections.some((/** @type {any} */ section) =>
350
+ fields.some(field => section?.[field] != null),
351
+ )
352
+ ) {
338
353
  return true;
339
354
  }
340
355
  }
@@ -1383,6 +1398,22 @@ export async function integrationPackCheck(options = {}) {
1383
1398
  issues.push(error('section_ids_need_cli', idProblem));
1384
1399
  }
1385
1400
  }
1401
+ // `before` and `after` need a newer CLI than any field above. Added in a
1402
+ // patch release, it warns and never fails the check (INV35).
1403
+ if (
1404
+ await setsSectionField(
1405
+ [
1406
+ ...records.map(record => record.path),
1407
+ ...guides.map(guide => /** @type {any} */ (guide.ref).topicFile),
1408
+ ],
1409
+ ['before', 'after'],
1410
+ )
1411
+ ) {
1412
+ const positionProblem = sectionPositionCliProblem(pkg);
1413
+ if (positionProblem != null) {
1414
+ issues.push(warning('section_position_needs_cli', positionProblem));
1415
+ }
1416
+ }
1386
1417
  }
1387
1418
  // A template that sets `replaces` (spec:AST-035) or `keywords` needs a CLI
1388
1419
  // that reads the field: an older CLI drops that template and can hide the
@@ -1724,6 +1724,39 @@ describe('integrationPackCheck', () => {
1724
1724
  expect(await codes()).not.toContain('section_ids_need_cli');
1725
1725
  }, 120_000);
1726
1726
 
1727
+ it('warns, without failing, when a doc section sets before or after on a CLI range that rejects them', async () => {
1728
+ writePackage({
1729
+ manifest: "export default {docs: './docs'};\n",
1730
+ themes: false,
1731
+ });
1732
+ fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
1733
+ const pkgFile = path.join(tmpDir, 'package.json');
1734
+ const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf-8'));
1735
+ pkg.peerDependencies = {'@astryxdesign/cli': '>=0.7.0'};
1736
+ fs.writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\n`);
1737
+ const issues = async () =>
1738
+ (await integrationPackCheck({cwd: tmpDir})).data.issues.filter(
1739
+ (/** @type {{code: string}} */ issue) =>
1740
+ issue.code === 'section_position_needs_cli',
1741
+ );
1742
+ // A placed guide's section counts too: an older CLI rejects the field in
1743
+ // any doc and hides the package's topics.
1744
+ fs.writeFileSync(
1745
+ path.join(tmpDir, 'docs', 'acme.doc.mjs'),
1746
+ "export default {type: 'namespace', name: 'acme', title: 'Acme', summary: 'Acme.', slots: {guides: {title: 'Guides', accepts: {kinds: ['generic']}}}};\n",
1747
+ );
1748
+ fs.writeFileSync(
1749
+ path.join(tmpDir, 'docs', 'setup.doc.mjs'),
1750
+ "export default {type: 'generic', name: 'setup', title: 'Setup', description: 'Set up.', placement: {parent: 'namespace:acme', slot: 'guides'}, sections: [{id: 'overview', title: 'Overview', after: 'nothing', content: [{type: 'prose', text: 'Set up.'}]}]};\n",
1751
+ );
1752
+ expect(await issues()).toEqual([
1753
+ expect.objectContaining({severity: 'warning'}),
1754
+ ]);
1755
+ pkg.peerDependencies = {'@astryxdesign/cli': '>=0.7.4'};
1756
+ fs.writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\n`);
1757
+ expect(await issues()).toEqual([]);
1758
+ }, 120_000);
1759
+
1727
1760
  it('fails a package with a template that sets replaces on a CLI range that rejects the field', async () => {
1728
1761
  writePackage({
1729
1762
  manifest: "export default {templates: './templates'};\n",
@@ -37,7 +37,10 @@ import {assertWithin} from '../../foundation/fs/path-safety.mjs';
37
37
  import {normalizeProviderId} from '../../foundation/identity/provider-identity.mjs';
38
38
  import {integrationDocTypes} from '../docs/_adapter.mjs';
39
39
  import {integrationDocConsistency} from '../../foundation/discovery/doc-consistency.mjs';
40
- import {integrationRunnerCommands} from './_adapter.mjs';
40
+ import {
41
+ integrationDocTargets,
42
+ integrationRunnerCommands,
43
+ } from './_adapter.mjs';
41
44
  import {
42
45
  THEME_SLUG_RE,
43
46
  unreadThemeFolders,
@@ -77,6 +80,15 @@ import {runChoice} from '../../foundation/release/run-context.mjs';
77
80
  /** The running CLI is outside the package's `@astryxdesign/cli` peer range. */
78
81
  const CLI_PEER_VERSION = 'cli_peer_version';
79
82
 
83
+ /** A doc replaces or extends a name that holds no topic and no guide. */
84
+ const DOC_TARGET_NOT_FOUND = 'doc_target_not_found';
85
+
86
+ /** An extension section's `before` or `after` names no section of the base. */
87
+ const DOC_SECTION_UNPLACED = 'doc_section_unplaced';
88
+
89
+ /** Two docs of one package replace one guide; only the last one is read. */
90
+ const DUPLICATE_GUIDE_REPLACEMENT = 'duplicate_guide_replacement';
91
+
80
92
  export {validateLoadedIntegration, isListedIssue};
81
93
 
82
94
  /**
@@ -703,6 +715,58 @@ async function runnerCommandNotes(integration) {
703
715
  }));
704
716
  }
705
717
 
718
+ /**
719
+ * The notes for docs that replace or extend a topic or a guide the docs tree
720
+ * places, or place an extension's section with `before` or `after`: a name
721
+ * that holds neither (such as a namespace) applies nothing, and a key that
722
+ * names no section adds the section at the end. Each is listed, failing nothing, until
723
+ * the next minor release (architecture:cli-surface INV35).
724
+ * @param {any} integration a loaded integration
725
+ * @returns {Promise<Array<{code: string, message: string}>>}
726
+ */
727
+ async function docTargetNotes(integration) {
728
+ /** @type {Array<{code: string, message: string}>} */
729
+ const notes = [];
730
+ const targets = await integrationDocTargets(integration);
731
+ /** @type {Map<string, string[]>} lowercased route → the docs replacing it */
732
+ const replacers = new Map();
733
+ for (const each of targets) {
734
+ if (each.kind !== 'guide' || each.relationship !== 'replaces') continue;
735
+ // An old route and the new one name one guide.
736
+ const key = each.guide ?? each.target.toLowerCase();
737
+ replacers.set(key, [...(replacers.get(key) ?? []), each.topic]);
738
+ }
739
+ for (const [route, topics] of replacers) {
740
+ if (topics.length < 2) continue;
741
+ notes.push({
742
+ code: DUPLICATE_GUIDE_REPLACEMENT,
743
+ message: `"${topics.join('", "')}" all replace the guide "${route}", and only the last, "${topics.at(-1)}", is read. Fix: keep one replacement, or make the others extend it.`,
744
+ });
745
+ }
746
+ for (const each of targets) {
747
+ if (each.kind === 'namespace') {
748
+ const shown = each.guidesBelow.slice(0, 8);
749
+ const more = each.guidesBelow.length - shown.length;
750
+ notes.push({
751
+ code: DOC_TARGET_NOT_FOUND,
752
+ message: `"${each.topic}" ${each.relationship} "${each.target}", which is a namespace of the docs tree: it holds no sections to ${each.relationship === 'replaces' ? 'replace' : 'extend'}, so this changes nothing. Fix: name the route of a guide below it${shown.length > 0 ? `: ${shown.join(', ')}${more > 0 ? `, and ${more} more` : ''}` : ''}.`,
753
+ });
754
+ } else if (each.kind == null) {
755
+ notes.push({
756
+ code: DOC_TARGET_NOT_FOUND,
757
+ message: `"${each.topic}" ${each.relationship} "${each.target}", which is neither a topic nor a guide of the CLI's docs or this package's own: it changes nothing unless an app also installs a package that provides it. Fix: if it should name one of those, name a topic as \`${formatCliCommand('docs')}\` lists it, or a guide's route as \`${formatCliCommand('docs authoring --depth all')}\` or \`${formatCliCommand('docs cli --depth all')}\` lists it.`,
758
+ });
759
+ }
760
+ for (const {section, field, key} of each.unplaced) {
761
+ notes.push({
762
+ code: DOC_SECTION_UNPLACED,
763
+ message: `Section "${section}" of "${each.topic}" goes ${field} "${key}", which is no section of "${each.guide ?? each.target}", so it is added at the end. Fix: use a key \`${formatCliCommand(`docs ${each.guide ?? each.target} --index`)}\` lists.`,
764
+ });
765
+ }
766
+ }
767
+ return notes;
768
+ }
769
+
706
770
  /**
707
771
  * Unified entry: validate the LOCAL integration (no `pkg`) or an INSTALLED one
708
772
  * (`pkg` given) and return the `integration.validate` envelope. The no-manifest
@@ -757,6 +821,7 @@ export async function validateIntegration(pkg, options = {}) {
757
821
  // `runner_command` note with its fix, the same way.
758
822
  if (integration?.docs) {
759
823
  notes.push(...(await runnerCommandNotes(integration)));
824
+ notes.push(...(await docTargetNotes(integration)));
760
825
  }
761
826
  return {
762
827
  type: 'integration.validate',
@@ -62,7 +62,7 @@ export const doc = {
62
62
  {
63
63
  type: 'integration.validate',
64
64
  description:
65
- "The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means \"not looked at\", not \"healthy\"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message, fix?, file?, line?}: `fix` is the change that resolves the issue, and `file` and `line` where it is, relative to the package, when the check knows them; and `data.notes` when there are any: {code, message} information that fails nothing, such as `invalid_cli_command` for a `cliCommand` that was ignored as malformed and `cli_peer_version` when the running CLI is outside the `@astryxdesign/cli` peer range of the package, and the package layout findings added after the last minor release, each with its fix in the message: `duplicate_component_doc`, `symlinked_root`, `unreadable_file`, `invalid_package_json` (no `name` or `version`), `no_provider_id`, and `source_without_component_doc` for a doc whose file name differs from its source only in letter case where the two still pair; and `doc_name_mismatch` and `unknown_block_component` (see `docNames` and `blockComponents`); they become warnings in the next minor release. A `runner_command` note lists each Astryx command a topic writes with a package runner, with its file, line and the bare command to write. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked. When the manifest loads, `data.docNames` lists the component doc names it could not judge: `status` (`checked`), `findings` (always empty; a doc name the module its import names provably does not export is a `doc_name_mismatch` note, with its fix in the message) and `unchecked` ({file, name, reason}: a doc whose `name` differs from the name it is listed under and whose source exports cannot all be read, such as a re-export from another package). When the manifest loads, `data.blockComponents` lists the component names templates give in `exampleFor` or `componentsUsed` that could not be judged: `status` (`checked`), `findings` (always empty; a name neither the package nor Core has, and the template does not import, is an `unknown_block_component` note, with its fix in the message) and `unchecked` ({file, name, reason}: a name the template may reach through anything other than named imports and re-exports from Core, React, StyleX, local helpers or the entry of the package itself, such as an import from another package, a default or namespace import, an alias of or member read off an imported binding, require() or a dynamic import(), or a local module that cannot be read, or any name Core would have to resolve when Core is not installed). Since 0.7.3 each import apps cannot use is a note in `data.notes`, its fix inside the message, listed only: it does not fail this command or `integration check --strict`, and fails `--strict` from the next minor release. The codes are `component_import_not_exported`, `component_import_other_package`, `component_import_missing_name`, `example_import_not_exported`, `example_import_missing_name`, `template_import_not_exported`, `template_import_outside_root`, `template_private_import`, `template_import_missing_name` and `template_no_default_export`. When the manifest loads, `data.publicImports` is `{status: 'checked', findings: [], unchecked}`: `unchecked` lists each import the check could not judge, as {file, specifier, reason}, the reason starting `example <label>:` for an import in a component example: an `exports` target not built yet; a module whose export list cannot be read in full (CommonJS, or a declaration file it cannot read); a root import in a package with no `exports` (the root module `main` names is not read); every name an import (other than a component doc's own component) names that its module does not export, while a TypeScript file in the package has a `declare module` block for a relative path or the package's own name or a subpath of it, which can add names to that module (a `declare module` in a comment, `declare global`, a wildcard such as `'*.css'`, and another package's name do not count; a file whose text has `declare module` but that cannot be parsed counts); the same for every such name when the package has more than 5,000 files to search for that block; a deep path into build output not built yet in a package with no `exports`; a template import of Core when `@astryxdesign/core` is not installed beside the package (a `packages/core` of the workspace under another name does not count); every import of the package's own name when package.json has no `name` or a `name` that is not a bare package name; one entry for the whole check when package.json cannot be read; and an import of a subpath whose `exports` entry has only a `types` target, unless it is `import type`, every binding is an inline `type`, or every name it imports is a type its types file declares: a value import of a name that file does not declare as a type, a namespace or side-effect import, or any import when the types file cannot be read (it may be build output). `integration check` counts the unchecked as not compared; they never fail it.",
65
+ "The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means \"not looked at\", not \"healthy\"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message, fix?, file?, line?}: `fix` is the change that resolves the issue, and `file` and `line` where it is, relative to the package, when the check knows them; and `data.notes` when there are any: {code, message} information that fails nothing, such as `invalid_cli_command` for a `cliCommand` that was ignored as malformed and `cli_peer_version` when the running CLI is outside the `@astryxdesign/cli` peer range of the package, and the package layout findings added after the last minor release, each with its fix in the message: `duplicate_component_doc`, `symlinked_root`, `unreadable_file`, `invalid_package_json` (no `name` or `version`), `no_provider_id`, and `source_without_component_doc` for a doc whose file name differs from its source only in letter case where the two still pair; and `doc_name_mismatch` and `unknown_block_component` (see `docNames` and `blockComponents`); they become warnings in the next minor release. A `runner_command` note lists each Astryx command a topic writes with a package runner, with its file, line and the bare command to write. A `doc_target_not_found` note names a doc whose `replaces` or `extends` names no topic and no guide of the CLI's docs or the package's own (such as a namespace, with the guides below it), so it changes nothing unless an app also installs a package that provides it, and a `doc_section_unplaced` note a section whose `before` or `after` names no section of the topic or guide it extends, so it is added at the end, and a `duplicate_guide_replacement` note two docs of the package that replace one guide, of which only the last is read; they become warnings in the next minor release. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked. When the manifest loads, `data.docNames` lists the component doc names it could not judge: `status` (`checked`), `findings` (always empty; a doc name the module its import names provably does not export is a `doc_name_mismatch` note, with its fix in the message) and `unchecked` ({file, name, reason}: a doc whose `name` differs from the name it is listed under and whose source exports cannot all be read, such as a re-export from another package). When the manifest loads, `data.blockComponents` lists the component names templates give in `exampleFor` or `componentsUsed` that could not be judged: `status` (`checked`), `findings` (always empty; a name neither the package nor Core has, and the template does not import, is an `unknown_block_component` note, with its fix in the message) and `unchecked` ({file, name, reason}: a name the template may reach through anything other than named imports and re-exports from Core, React, StyleX, local helpers or the entry of the package itself, such as an import from another package, a default or namespace import, an alias of or member read off an imported binding, require() or a dynamic import(), or a local module that cannot be read, or any name Core would have to resolve when Core is not installed). Since 0.7.3 each import apps cannot use is a note in `data.notes`, its fix inside the message, listed only: it does not fail this command or `integration check --strict`, and fails `--strict` from the next minor release. The codes are `component_import_not_exported`, `component_import_other_package`, `component_import_missing_name`, `example_import_not_exported`, `example_import_missing_name`, `template_import_not_exported`, `template_import_outside_root`, `template_private_import`, `template_import_missing_name` and `template_no_default_export`. When the manifest loads, `data.publicImports` is `{status: 'checked', findings: [], unchecked}`: `unchecked` lists each import the check could not judge, as {file, specifier, reason}, the reason starting `example <label>:` for an import in a component example: an `exports` target not built yet; a module whose export list cannot be read in full (CommonJS, or a declaration file it cannot read); a root import in a package with no `exports` (the root module `main` names is not read); every name an import (other than a component doc's own component) names that its module does not export, while a TypeScript file in the package has a `declare module` block for a relative path or the package's own name or a subpath of it, which can add names to that module (a `declare module` in a comment, `declare global`, a wildcard such as `'*.css'`, and another package's name do not count; a file whose text has `declare module` but that cannot be parsed counts); the same for every such name when the package has more than 5,000 files to search for that block; a deep path into build output not built yet in a package with no `exports`; a template import of Core when `@astryxdesign/core` is not installed beside the package (a `packages/core` of the workspace under another name does not count); every import of the package's own name when package.json has no `name` or a `name` that is not a bare package name; one entry for the whole check when package.json cannot be read; and an import of a subpath whose `exports` entry has only a `types` target, unless it is `import type`, every binding is an inline `type`, or every name it imports is a type its types file declares: a value import of a name that file does not declare as a type, a namespace or side-effect import, or any import when the types file cannot be read (it may be build output). `integration check` counts the unchecked as not compared; they never fail it.",
66
66
  },
67
67
  ],
68
68
  examples: [
@@ -17,7 +17,7 @@
17
17
  * @param {string} [candidate.description]
18
18
  * @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
19
19
  * @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
20
- * @param {{fuzzy?: boolean, joins?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false. `joins`: read a spaced query joined into a name or keyword (default true); off when the query names an entry outright.
20
+ * @param {{fuzzy?: boolean, joins?: boolean, part?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false. `joins`: read a spaced query joined into a name or keyword (default true); off when the query names an entry outright. `part`: the term is one word of a longer query, so a name's head word after single letters (Stack in VStack) does not count as a keyword hit for it.
21
21
  * @returns {{score: number, reason: string, alias?: 'partial' | 'keyword'} | null}
22
22
  * `alias` marks a hit that read the query's words joined.
23
23
  */
@@ -30,9 +30,10 @@ export function scoreCandidate(term: string, { name, aliases, domain, keywords,
30
30
  description?: string | undefined;
31
31
  prose?: string[] | undefined;
32
32
  guidance?: string[] | undefined;
33
- }, { fuzzy, joins }?: {
33
+ }, { fuzzy, joins, part }?: {
34
34
  fuzzy?: boolean;
35
35
  joins?: boolean;
36
+ part?: boolean;
36
37
  }): {
37
38
  score: number;
38
39
  reason: string;