@astryxdesign/cli 0.7.3-canary.31e06f4 → 0.7.3-canary.641d08e

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 (122) hide show
  1. package/README.md +68 -68
  2. package/api/component/doc-links.test.mjs +2 -2
  3. package/api/docs/_adapter.d.mts +2 -2
  4. package/api/docs/_adapter.mjs +61 -18
  5. package/api/docs/docs-homes.test.mjs +127 -0
  6. package/api/docs/docs.doc.mjs +3 -3
  7. package/api/docs/docs.test.mjs +28 -18
  8. package/api/docs/integration-tree.test.mjs +20 -20
  9. package/api/docs/integrationDocs.test.mjs +1 -1
  10. package/api/docs/namespace-section.test.mjs +6 -6
  11. package/api/docs/reference-blocks.test.mjs +2 -2
  12. package/api/doctor/doctor.mjs +16 -12
  13. package/api/doctor/doctor.test.mjs +9 -9
  14. package/api/integration/_adapter.d.mts +8 -0
  15. package/api/integration/_adapter.mjs +21 -1
  16. package/api/integration/authoring-checks.test.mjs +220 -0
  17. package/api/integration/validate-integration.mjs +24 -0
  18. package/api/integration/validate-integration.type.d.mts +2 -1
  19. package/api/integration/validate-integration.type.mjs +2 -1
  20. package/api/integration/validateIntegration.doc.mjs +1 -1
  21. package/api/search/_candidate-score.mjs +1 -1
  22. package/api/search/_entries.mjs +57 -1
  23. package/api/search/_gather-docs.mjs +3 -3
  24. package/api/search/search.doc.mjs +1 -1
  25. package/api/search/search.test.mjs +14 -14
  26. package/assets/docs/author-a-theme.doc.mjs +2 -2
  27. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  28. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  29. package/assets/docs/tree/add-a-topic.doc.mjs +2 -2
  30. package/assets/docs/tree/agent-guidance.doc.mjs +1 -1
  31. package/assets/docs/tree/{integrations.doc.mjs → authoring.doc.mjs} +15 -6
  32. package/assets/docs/tree/block-template.doc.mjs +1 -1
  33. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  34. package/assets/docs/tree/building-blocks.doc.mjs +2 -2
  35. package/assets/docs/tree/check-the-props.doc.mjs +1 -1
  36. package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
  37. package/assets/docs/tree/checks.doc.mjs +2 -2
  38. package/assets/docs/tree/cli-command.doc.mjs +1 -1
  39. package/assets/docs/tree/cli.doc.mjs +1 -1
  40. package/assets/docs/tree/codemods.doc.mjs +1 -1
  41. package/assets/docs/tree/component-family.doc.mjs +1 -1
  42. package/assets/docs/tree/component-imports.doc.mjs +1 -1
  43. package/assets/docs/tree/components.doc.mjs +1 -1
  44. package/assets/docs/tree/configuration.doc.mjs +1 -1
  45. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
  46. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  47. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  48. package/assets/docs/tree/docs.doc.mjs +1 -1
  49. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  50. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  51. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  52. package/assets/docs/tree/extend-or-replace.doc.mjs +1 -1
  53. package/assets/docs/{authoring.doc.mjs → tree/field-reference.doc.mjs} +4 -3
  54. package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
  55. package/assets/docs/tree/generate-a-palette.doc.mjs +1 -1
  56. package/assets/docs/tree/global-integrations.doc.mjs +2 -2
  57. package/assets/docs/tree/grade-template-with-agent.doc.mjs +4 -4
  58. package/assets/docs/tree/help.doc.mjs +2 -2
  59. package/assets/docs/tree/links.doc.mjs +1 -1
  60. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  61. package/assets/docs/tree/page-template.doc.mjs +1 -1
  62. package/assets/docs/tree/publishing.doc.mjs +1 -1
  63. package/assets/docs/tree/quick-start.doc.mjs +1 -1
  64. package/assets/docs/tree/replace-a-core-component.doc.mjs +1 -1
  65. package/assets/docs/tree/replace-a-core-template.doc.mjs +1 -1
  66. package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
  67. package/assets/docs/tree/see-it-in-an-app.doc.mjs +1 -1
  68. package/assets/docs/tree/ship.doc.mjs +2 -2
  69. package/assets/docs/tree/short-and-findable.doc.mjs +1 -1
  70. package/assets/docs/tree/single-component.doc.mjs +1 -1
  71. package/assets/docs/tree/start-a-template.doc.mjs +1 -1
  72. package/assets/docs/tree/subcomponent.doc.mjs +1 -1
  73. package/assets/docs/tree/template-assets.doc.mjs +1 -1
  74. package/assets/docs/tree/template-doc-overview.doc.mjs +2 -2
  75. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  76. package/assets/docs/tree/template-grading-rubric.doc.mjs +1 -1
  77. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  78. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  79. package/assets/docs/tree/template-styles.doc.mjs +1 -1
  80. package/assets/docs/tree/templates.doc.mjs +1 -1
  81. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  82. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  83. package/assets/docs/tree/themes.doc.mjs +1 -1
  84. package/assets/docs/tree/troubleshooting.doc.mjs +1 -1
  85. package/assets/docs/tree/upgrading.doc.mjs +1 -1
  86. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +1 -1
  87. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  88. package/assets/docs/tree/versioning.doc.mjs +1 -1
  89. package/assets/docs/tree/write-good-templates.doc.mjs +1 -1
  90. package/assets/docs/tree/write-the-template-file.doc.mjs +1 -1
  91. package/authoring/doctypes/schema/schema.doc.mjs +1 -1
  92. package/authoring/integration/integration.doc.mjs +1 -1
  93. package/authoring/integration/type.ts +1 -1
  94. package/clients/cli/commands/docs.doc.mjs +2 -2
  95. package/clients/cli/commands/docs.mjs +1 -1
  96. package/clients/cli/commands/docs.test.mjs +14 -14
  97. package/clients/cli/commands/integration-check.test.mjs +48 -0
  98. package/clients/cli/commands/integration.doc.mjs +1 -1
  99. package/foundation/agent-docs/agent-docs.mjs +2 -1
  100. package/foundation/agent-docs/agent-docs.test.mjs +5 -4
  101. package/foundation/discovery/authoring-self-docs.d.mts +7 -0
  102. package/foundation/discovery/authoring-self-docs.mjs +16 -4
  103. package/foundation/discovery/authoring-self-docs.test.mjs +15 -3
  104. package/foundation/discovery/authoring-surface.d.mts +1 -1
  105. package/foundation/discovery/authoring-surface.mjs +2 -2
  106. package/foundation/discovery/authoring-surface.test.mjs +1 -1
  107. package/foundation/discovery/cli-self-docs.d.mts +2 -1
  108. package/foundation/discovery/cli-self-docs.mjs +4 -3
  109. package/foundation/discovery/cli-self-docs.test.mjs +2 -2
  110. package/foundation/discovery/runner-allowlist.d.mts +2 -4
  111. package/foundation/discovery/runner-allowlist.mjs +2 -4
  112. package/foundation/discovery/runner-commands.d.mts +77 -0
  113. package/foundation/discovery/runner-commands.mjs +293 -0
  114. package/foundation/discovery/runner-commands.test.mjs +128 -0
  115. package/foundation/discovery/stray-pointers.test.mjs +1 -1
  116. package/foundation/doc-compiler/doc-loads.test.mjs +4 -0
  117. package/foundation/doc-compiler/split-topic-keywords.test.mjs +3 -2
  118. package/foundation/doc-compiler/tree.d.mts +32 -6
  119. package/foundation/doc-compiler/tree.mjs +77 -43
  120. package/foundation/doc-compiler/tree.test.mjs +7 -7
  121. package/foundation/response/response-types.doc.mjs +1 -1
  122. package/package.json +9 -9
@@ -1048,16 +1048,20 @@ function nameTypes(names) {
1048
1048
  }
1049
1049
 
1050
1050
  /**
1051
- * The section keys `astryx docs authoring --index` lists, read the way that
1052
- * command reads them.
1051
+ * The section keys the field reference lists (`astryx docs
1052
+ * authoring/field-reference --index`), read the way that command reads them.
1053
1053
  * @returns {Promise<{keys: Set<string>} | {keys: null, error: string}>}
1054
1054
  */
1055
1055
  async function authoringTopicKeys() {
1056
1056
  try {
1057
+ const {AUTHORING_REFERENCE_ROUTE} =
1058
+ await import('../../foundation/discovery/authoring-self-docs.mjs');
1057
1059
  const catalog = DocsCatalog.fromBuiltins();
1058
- const entry = catalog.resolve('authoring');
1059
- if (!entry) return {keys: null, error: 'it is not a built-in topic'};
1060
- const index = indexView(await lowerTopic(catalog, entry));
1060
+ const node = (await projectTree(catalog)).get(AUTHORING_REFERENCE_ROUTE);
1061
+ if (!node?.ref?.topicFile) {
1062
+ return {keys: null, error: 'the docs tree has no field reference'};
1063
+ }
1064
+ const index = indexView(await lowerTopic(catalog, guideEntry(node)));
1061
1065
  return {keys: new Set(index.sections.map(section => section.id))};
1062
1066
  } catch (err) {
1063
1067
  return {
@@ -1076,7 +1080,7 @@ function surfaceProblems(surface) {
1076
1080
  const problems = [];
1077
1081
  if (surface.types === 0 && surface.untraced.length === 0) {
1078
1082
  problems.push(
1079
- `@astryxdesign/cli/authoring exports no types, so nothing was compared with \`${formatCliCommand('docs authoring')}\``,
1083
+ `@astryxdesign/cli/authoring exports no types, so nothing was compared with \`${formatCliCommand('docs authoring/field-reference')}\``,
1080
1084
  );
1081
1085
  }
1082
1086
  for (const {module, names, reason, source, key} of surface.unreadable) {
@@ -1089,7 +1093,7 @@ function surfaceProblems(surface) {
1089
1093
  ? `${source} does not load`
1090
1094
  : `${source} renders section "${key}", which the topic's index does not list`;
1091
1095
  problems.push(
1092
- `${nameTypes(names)} from ${module} ${names.length === 1 ? 'has' : 'have'} no doc in \`${formatCliCommand('docs authoring')}\`: ${why}`,
1096
+ `${nameTypes(names)} from ${module} ${names.length === 1 ? 'has' : 'have'} no doc in \`${formatCliCommand('docs authoring/field-reference')}\`: ${why}`,
1093
1097
  );
1094
1098
  }
1095
1099
  for (const {name, reason} of surface.untraced) {
@@ -1130,7 +1134,7 @@ export async function checkAuthoringDocs(_ctx, options = {}) {
1130
1134
  const audit = await auditAuthoringSelfDocs({root, sources});
1131
1135
  const problems = [
1132
1136
  ...audit.unreachable.map(
1133
- source => `${source} is not in \`${formatCliCommand('docs authoring')}\``,
1137
+ source => `${source} is not in \`${formatCliCommand('docs authoring/field-reference')}\``,
1134
1138
  ),
1135
1139
  ...audit.failed.map(
1136
1140
  ({source, error}) => `${source} failed to load: ${error}`,
@@ -1146,7 +1150,7 @@ export async function checkAuthoringDocs(_ctx, options = {}) {
1146
1150
  : {keys: options.topicKeys};
1147
1151
  const surface = [
1148
1152
  ...('error' in topic
1149
- ? [`\`${formatCliCommand('docs authoring')}\` could not be read: ${topic.error}`]
1153
+ ? [`\`${formatCliCommand('docs authoring/field-reference')}\` could not be read: ${topic.error}`]
1150
1154
  : []),
1151
1155
  ...surfaceProblems(
1152
1156
  await auditAuthoringSurface({root, sources, topicKeys: topic.keys}),
@@ -1170,7 +1174,7 @@ export async function checkAuthoringDocs(_ctx, options = {}) {
1170
1174
  id,
1171
1175
  label,
1172
1176
  status: 'pass',
1173
- message: `All ${audit.sections} authoring schemas are readable in \`${formatCliCommand('docs authoring')}\`.`,
1177
+ message: `All ${audit.sections} authoring schemas are readable in \`${formatCliCommand('docs authoring/field-reference')}\`.`,
1174
1178
  };
1175
1179
  } catch (err) {
1176
1180
  return {
@@ -1238,7 +1242,7 @@ export async function checkCliDocs(_ctx, options = {}) {
1238
1242
  id,
1239
1243
  label,
1240
1244
  status: 'pass',
1241
- message: `All ${audit.docs} CLI docs are readable: ${audit.tree} in the \`${formatCliCommand('docs cli')}\` tree and ${audit.authoring} in \`${formatCliCommand('docs authoring')}\`.`,
1245
+ message: `All ${audit.docs} CLI docs are readable: ${audit.tree} in the \`${formatCliCommand('docs cli')}\` tree and ${audit.authoring} in \`${formatCliCommand('docs authoring/field-reference')}\`.`,
1242
1246
  };
1243
1247
  } catch (err) {
1244
1248
  return {
@@ -1355,7 +1359,7 @@ export async function checkDocsProgressiveDisclosure(ctx) {
1355
1359
  // A guide the docs tree places is a topic read by its route; it is held
1356
1360
  // to the same budget as every flat topic.
1357
1361
  const guides = [...(await projectTree(catalog)).nodes.values()]
1358
- // A flat topic in the Unorganized level is checked above, as a topic.
1362
+ // A flat topic in a topic level is checked above, as a topic.
1359
1363
  .filter(node => node.kind === 'generic' && !node.ref?.flatTopic)
1360
1364
  .map(guideEntry);
1361
1365
  for (const entry of [...catalog.entries(), ...guides]) {
@@ -652,7 +652,7 @@ describe('checkAuthoringDocs', () => {
652
652
  it('passes when every authoring self-doc is reachable and fits one read', async () => {
653
653
  const c = await checkAuthoringDocs();
654
654
  expect(c).toMatchObject({id: 'authoring-docs', status: 'pass'});
655
- expect(c.message).toContain(formatCliCommand('docs authoring'));
655
+ expect(c.message).toContain(formatCliCommand('docs authoring/field-reference'));
656
656
  }, SLOW);
657
657
  });
658
658
 
@@ -680,7 +680,7 @@ describe('checkCliDocs', () => {
680
680
  id: 'cli-docs',
681
681
  label: 'CLI docs',
682
682
  status: 'pass',
683
- message: `All ${audit.docs} CLI docs are readable: ${audit.tree} in the \`${formatCliCommand('docs cli')}\` tree and ${audit.authoring} in \`${formatCliCommand('docs authoring')}\`.`,
683
+ message: `All ${audit.docs} CLI docs are readable: ${audit.tree} in the \`${formatCliCommand('docs cli')}\` tree and ${audit.authoring} in \`${formatCliCommand('docs authoring/field-reference')}\`.`,
684
684
  });
685
685
  },
686
686
  SLOW,
@@ -790,7 +790,7 @@ describe('checkDocsTree', () => {
790
790
  describe('checkAuthoringDocs against the public authoring surface', () => {
791
791
  const NAMESPACE = 'doctypes/namespace/namespace.doc.mjs';
792
792
  const NAMESPACE_TYPES =
793
- `NamespaceDoc, NamespaceProviderScope, NamespaceSlotAcceptance, NamespaceSlot, NamespaceAdoptionSource, NamespaceAdoptionRule from doctypes/namespace/type.ts have no doc in \`${formatCliCommand('docs authoring')}\``;
793
+ `NamespaceDoc, NamespaceProviderScope, NamespaceSlotAcceptance, NamespaceSlot, NamespaceAdoptionSource, NamespaceAdoptionRule from doctypes/namespace/type.ts have no doc in \`${formatCliCommand('docs authoring/field-reference')}\``;
794
794
  const SURFACE_FIX =
795
795
  'Put a self-doc beside each module whose types @astryxdesign/cli/authoring exports and list it in AUTHORING_SELF_DOCS; export what each listed self-doc documents, or remove that self-doc.';
796
796
 
@@ -820,7 +820,7 @@ describe('checkAuthoringDocs against the public authoring surface', () => {
820
820
  id: 'authoring-docs',
821
821
  label: 'Authoring docs',
822
822
  status: 'pass',
823
- message: `All ${AUTHORING_SELF_DOCS.length} authoring schemas are readable in \`${formatCliCommand('docs authoring')}\`.`,
823
+ message: `All ${AUTHORING_SELF_DOCS.length} authoring schemas are readable in \`${formatCliCommand('docs authoring/field-reference')}\`.`,
824
824
  });
825
825
  },
826
826
  SLOW,
@@ -849,7 +849,7 @@ describe('checkAuthoringDocs against the public authoring surface', () => {
849
849
  });
850
850
  expect(c.status).toBe('fail');
851
851
  expect(c.message).toBe(
852
- `2 problems: ${NAMESPACE} is not in \`${formatCliCommand('docs authoring')}\`; ${NAMESPACE_TYPES}: ${NAMESPACE} is not listed in AUTHORING_SELF_DOCS`,
852
+ `2 problems: ${NAMESPACE} is not in \`${formatCliCommand('docs authoring/field-reference')}\`; ${NAMESPACE_TYPES}: ${NAMESPACE} is not listed in AUTHORING_SELF_DOCS`,
853
853
  );
854
854
  },
855
855
  SLOW,
@@ -858,7 +858,7 @@ describe('checkAuthoringDocs against the public authoring surface', () => {
858
858
  it(
859
859
  "fails when the topic's index no longer exposes the NamespaceDoc section",
860
860
  async () => {
861
- const index = await docs('authoring', undefined, {index: true});
861
+ const index = await docs('authoring/field-reference', undefined, {index: true});
862
862
  const topicKeys = new Set(
863
863
  index.data.sections
864
864
  .map((/** @type {any} */ s) => s.id)
@@ -947,7 +947,7 @@ describe('checkAuthoringDocs against the public authoring surface', () => {
947
947
  expect(c.fix).toBe(SURFACE_FIX);
948
948
  expect(c.message).toMatch(
949
949
  new RegExp(
950
- `^[A-Za-z, ]+ from ${escape(module)} have no doc in \`${escape(formatCliCommand('docs authoring'))}\`: no self-doc sits beside ${escape(module)}$`,
950
+ `^[A-Za-z, ]+ from ${escape(module)} have no doc in \`${escape(formatCliCommand('docs authoring/field-reference'))}\`: no self-doc sits beside ${escape(module)}$`,
951
951
  ),
952
952
  );
953
953
  for (const name of names) {
@@ -990,7 +990,7 @@ describe('checkAuthoringDocs against the public authoring surface', () => {
990
990
  expect(await checkAuthoringDocs()).toMatchObject({
991
991
  status: 'fail',
992
992
  message:
993
- `\`${formatCliCommand('docs authoring')}\` could not be read: no built-in docs`,
993
+ `\`${formatCliCommand('docs authoring/field-reference')}\` could not be read: no built-in docs`,
994
994
  fix: SURFACE_FIX,
995
995
  });
996
996
  } finally {
@@ -1011,7 +1011,7 @@ describe('checkAuthoringDocs against the public authoring surface', () => {
1011
1011
  const c = await checkAuthoringDocs(undefined, {root});
1012
1012
  expect(c.status).toBe('fail');
1013
1013
  expect(c.message).toContain(
1014
- `@astryxdesign/cli/authoring exports no types, so nothing was compared with \`${formatCliCommand('docs authoring')}\``,
1014
+ `@astryxdesign/cli/authoring exports no types, so nothing was compared with \`${formatCliCommand('docs authoring/field-reference')}\``,
1015
1015
  );
1016
1016
  },
1017
1017
  SLOW,
@@ -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
+ * Each Astryx command a package's topics write with a package runner. A
45
+ * package whose topics cannot be discovered has none here: the other checks
46
+ * report topics that do not load.
47
+ * @param {any} integration a loaded integration
48
+ * @returns {Promise<import('../../foundation/discovery/runner-commands.mjs').RunnerCommand[]>}
49
+ */
50
+ export function integrationRunnerCommands(integration: any): Promise<import("../../foundation/discovery/runner-commands.mjs").RunnerCommand[]>;
43
51
  import { findCopiedPassages } from '../../foundation/discovery/copied-passages.mjs';
44
52
  import { findFluff } from '../../foundation/discovery/doc-fluff.mjs';
45
53
  import { findStrayPointers } from '../../foundation/discovery/stray-pointers.mjs';
@@ -2,7 +2,8 @@
2
2
 
3
3
  /**
4
4
  * @file The integration subject's access to the environment (INV21): reading
5
- * one package's component docs and sources with the project's own TypeScript.
5
+ * one package's component docs and sources with the project's own TypeScript,
6
+ * and its topics.
6
7
  *
7
8
  * @input a loaded integration and the directory the command runs in
8
9
  * @output the reports the integration checks attach to their results
@@ -14,9 +15,11 @@ import {
14
15
  forEachIntegrationDoc,
15
16
  integrationSourceForDoc,
16
17
  } from '../../foundation/discovery/component-discovery.mjs';
18
+ import {discoverIntegrationDocs} from '../../foundation/discovery/docs-discovery.mjs';
17
19
  import {comparePropDocs} from '../../foundation/discovery/prop-drift.mjs';
18
20
  import {findCopiedPassages} from '../../foundation/discovery/copied-passages.mjs';
19
21
  import {findFluff} from '../../foundation/discovery/doc-fluff.mjs';
22
+ import {findRunnerCommands} from '../../foundation/discovery/runner-commands.mjs';
20
23
  import {findStrayPointers} from '../../foundation/discovery/stray-pointers.mjs';
21
24
 
22
25
  /**
@@ -110,3 +113,20 @@ export async function integrationStrayPointers(discovered, integration) {
110
113
  }
111
114
  return findStrayPointers({...discovered, components});
112
115
  }
116
+
117
+ /**
118
+ * Each Astryx command a package's topics write with a package runner. A
119
+ * package whose topics cannot be discovered has none here: the other checks
120
+ * report topics that do not load.
121
+ * @param {any} integration a loaded integration
122
+ * @returns {Promise<import('../../foundation/discovery/runner-commands.mjs').RunnerCommand[]>}
123
+ */
124
+ export async function integrationRunnerCommands(integration) {
125
+ let discovered;
126
+ try {
127
+ discovered = await discoverIntegrationDocs(integration);
128
+ } catch {
129
+ return [];
130
+ }
131
+ return findRunnerCommands(discovered);
132
+ }
@@ -14,6 +14,7 @@ vi.mock('../../foundation/discovery/template-conflict-release.mjs', () => ({
14
14
  }));
15
15
  import * as fs from 'node:fs';
16
16
  import * as path from 'node:path';
17
+ import {validateIntegration} from './validate-integration.mjs';
17
18
  import {discoverCoreTemplates} from '../../foundation/discovery/template-adapter.mjs';
18
19
  import {discoverOwnedComponents} from '../../foundation/discovery/component-discovery.mjs';
19
20
  import {discoverBuiltinTopics} from '../../foundation/discovery/docs-discovery.mjs';
@@ -1331,3 +1332,222 @@ describe('links in component docs and topic descriptions', () => {
1331
1332
  ]);
1332
1333
  });
1333
1334
  });
1335
+
1336
+ describe('validateIntegration runner-command notes', () => {
1337
+ /** The runner-command notes, read back into their parts. */
1338
+ async function runnerNotes() {
1339
+ const {data} = await validateIntegration(undefined, {cwd: tmpDir});
1340
+ const notes = (data.notes ?? [])
1341
+ .filter((/** @type {any} */ note) => note.code === 'runner_command')
1342
+ .map((/** @type {any} */ note) => {
1343
+ const m =
1344
+ /^(\S+): "([^"]+)"(?: \(section "([^"]+)"\))? writes `([^`]+)`(?: \(line (\d+)\))?\./.exec(
1345
+ note.message,
1346
+ );
1347
+ return {
1348
+ file: m?.[1],
1349
+ topic: m?.[2],
1350
+ section: m?.[3] ?? null,
1351
+ command: m?.[4],
1352
+ line: m?.[5] ? Number(m[5]) : null,
1353
+ message: note.message,
1354
+ };
1355
+ });
1356
+ return {data, notes};
1357
+ }
1358
+
1359
+ function writeTopic(/** @type {string} */ text) {
1360
+ fs.writeFileSync(
1361
+ path.join(tmpDir, 'package.json'),
1362
+ JSON.stringify({name: '@acme/widgets', version: '1.2.3'}),
1363
+ );
1364
+ fs.writeFileSync(
1365
+ path.join(tmpDir, 'astryx.integration.mjs'),
1366
+ `export default {docs: './docs'};\n`,
1367
+ );
1368
+ fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
1369
+ const doc = {
1370
+ type: 'generic',
1371
+ name: 'acme-setup',
1372
+ title: 'Fixture',
1373
+ description: 'Fixture topic.',
1374
+ sections: [
1375
+ {
1376
+ title: 'Overview',
1377
+ content: [
1378
+ {type: 'prose', text},
1379
+ {type: 'code', lang: 'bash', code: 'npx @astryxdesign/cli init'},
1380
+ ],
1381
+ },
1382
+ ],
1383
+ };
1384
+ fs.writeFileSync(
1385
+ path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'),
1386
+ `export default ${JSON.stringify(doc)};\n`,
1387
+ );
1388
+ }
1389
+
1390
+ it('lists a runner command with its line and fix, and raises no issue', async () => {
1391
+ writeTopic('Check it with `pnpm exec astryx doctor` first.');
1392
+
1393
+ const {data, notes} = await runnerNotes();
1394
+ const [hit, ...rest] = notes;
1395
+
1396
+ expect(rest).toEqual([]);
1397
+ expect(hit).toMatchObject({
1398
+ topic: 'acme-setup',
1399
+ section: 'Overview',
1400
+ file: 'docs/acme-setup.doc.mjs',
1401
+ line: 1,
1402
+ command: 'pnpm exec astryx doctor',
1403
+ });
1404
+ expect(hit.message).toContain('Write `astryx doctor`');
1405
+ // A note only: no issue, so no exit changes on it.
1406
+ expect(
1407
+ data.issues.map((/** @type {any} */ issue) => issue.code),
1408
+ ).not.toContain('runner_command');
1409
+ });
1410
+
1411
+ it('puts each copy of a repeated command on its own line', async () => {
1412
+ fs.writeFileSync(
1413
+ path.join(tmpDir, 'package.json'),
1414
+ JSON.stringify({name: '@acme/widgets', version: '1.2.3'}),
1415
+ );
1416
+ fs.writeFileSync(
1417
+ path.join(tmpDir, 'astryx.integration.mjs'),
1418
+ `export default {docs: './docs'};\n`,
1419
+ );
1420
+ fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
1421
+ const doc = {
1422
+ type: 'generic',
1423
+ name: 'acme-setup',
1424
+ title: 'Fixture',
1425
+ description: 'Fixture topic.',
1426
+ sections: [
1427
+ {
1428
+ title: 'First',
1429
+ content: [{type: 'prose', text: 'Run `npx astryx doctor`.'}],
1430
+ },
1431
+ {
1432
+ title: 'Second',
1433
+ content: [{type: 'prose', text: 'Run `npx astryx doctor` again.'}],
1434
+ },
1435
+ {
1436
+ title: 'Third',
1437
+ content: [{type: 'prose', text: 'Or plain `npx astryx`.'}],
1438
+ },
1439
+ ],
1440
+ };
1441
+ fs.writeFileSync(
1442
+ path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'),
1443
+ `export default ${JSON.stringify(doc, null, 2)};\n`,
1444
+ );
1445
+ const lines = fs
1446
+ .readFileSync(path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'), 'utf8')
1447
+ .split('\n');
1448
+ const lineHolding = (/** @type {string} */ text) =>
1449
+ lines.findIndex(line => line.includes(text)) + 1;
1450
+
1451
+ const {notes} = await runnerNotes();
1452
+
1453
+ expect(
1454
+ notes.map((/** @type {any} */ each) => [
1455
+ each.section,
1456
+ each.line,
1457
+ each.command,
1458
+ ]),
1459
+ ).toEqual([
1460
+ ['First', lineHolding('Run `npx astryx doctor`.'), 'npx astryx doctor'],
1461
+ ['Second', lineHolding('again.'), 'npx astryx doctor'],
1462
+ ['Third', lineHolding('Or plain'), 'npx astryx'],
1463
+ ]);
1464
+ });
1465
+
1466
+ it('puts each copy of an identical one-line string on its own line', async () => {
1467
+ fs.writeFileSync(
1468
+ path.join(tmpDir, 'package.json'),
1469
+ JSON.stringify({name: '@acme/widgets', version: '1.2.3'}),
1470
+ );
1471
+ fs.writeFileSync(
1472
+ path.join(tmpDir, 'astryx.integration.mjs'),
1473
+ `export default {docs: './docs'};\n`,
1474
+ );
1475
+ fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
1476
+ const block = {type: 'code', lang: 'bash', code: 'npx astryx doctor'};
1477
+ const doc = {
1478
+ type: 'generic',
1479
+ name: 'acme-setup',
1480
+ title: 'Fixture',
1481
+ description: 'Fixture topic.',
1482
+ sections: [
1483
+ {title: 'First', content: [block]},
1484
+ {title: 'Second', content: [block]},
1485
+ ],
1486
+ };
1487
+ fs.writeFileSync(
1488
+ path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'),
1489
+ `export default ${JSON.stringify(doc, null, 2)};\n`,
1490
+ );
1491
+ const lines = fs
1492
+ .readFileSync(path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'), 'utf8')
1493
+ .split('\n');
1494
+ const copies = lines.flatMap((line, at) =>
1495
+ line.includes('"npx astryx doctor"') ? [at + 1] : [],
1496
+ );
1497
+
1498
+ const {notes} = await runnerNotes();
1499
+
1500
+ expect(copies).toHaveLength(2);
1501
+ expect(
1502
+ notes.map((/** @type {any} */ each) => [each.section, each.line]),
1503
+ ).toEqual([
1504
+ ['First', copies[0]],
1505
+ ['Second', copies[1]],
1506
+ ]);
1507
+ });
1508
+
1509
+ it("places a section's command on its own line when the section sits in a constant above the doc", async () => {
1510
+ fs.writeFileSync(
1511
+ path.join(tmpDir, 'package.json'),
1512
+ JSON.stringify({name: '@acme/widgets', version: '1.2.3'}),
1513
+ );
1514
+ fs.writeFileSync(
1515
+ path.join(tmpDir, 'astryx.integration.mjs'),
1516
+ `export default {docs: './docs'};\n`,
1517
+ );
1518
+ fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
1519
+ fs.writeFileSync(
1520
+ path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'),
1521
+ [
1522
+ "const install = {title: 'Install', content: [{type: 'prose', text: 'Run `npx astryx doctor`.'}]};",
1523
+ '',
1524
+ 'export default {',
1525
+ " type: 'generic',",
1526
+ " name: 'acme-setup',",
1527
+ " title: 'Fixture',",
1528
+ " description: 'Install first: `npx astryx doctor`.',",
1529
+ ' sections: [install],',
1530
+ '};',
1531
+ '',
1532
+ ].join('\n'),
1533
+ );
1534
+
1535
+ const {notes} = await runnerNotes();
1536
+
1537
+ expect(
1538
+ notes.map((/** @type {any} */ each) => [each.section, each.line]),
1539
+ ).toEqual(
1540
+ expect.arrayContaining([
1541
+ [null, 7],
1542
+ ['Install', 1],
1543
+ ]),
1544
+ );
1545
+ });
1546
+
1547
+ it('lists nothing for bare commands and the scoped install step', async () => {
1548
+ writeTopic('Check it with `astryx doctor` first.');
1549
+
1550
+ const {notes} = await runnerNotes();
1551
+ expect((await runnerNotes()).notes).toEqual([]);
1552
+ });
1553
+ });
@@ -37,6 +37,7 @@ 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
41
  import {
41
42
  THEME_SLUG_RE,
42
43
  unreadThemeFolders,
@@ -647,6 +648,24 @@ export async function validateInstalledIntegration(spec, cwd = process.cwd()) {
647
648
  });
648
649
  }
649
650
 
651
+ /**
652
+ * The runner-command notes for a package's topics: each Astryx command a topic
653
+ * writes with a package runner, where the doc file is, and the bare command to
654
+ * write.
655
+ * @param {any} integration a loaded integration
656
+ * @returns {Promise<Array<{code: string, message: string}>>}
657
+ */
658
+ async function runnerCommandNotes(integration) {
659
+ const packageDir = integration.__packageDir;
660
+ return (await integrationRunnerCommands(integration)).map(each => ({
661
+ code: 'runner_command',
662
+ message:
663
+ typeof packageDir === 'string'
664
+ ? `${path.relative(packageDir, each.file).split(path.sep).join('/')}: ${each.message}`
665
+ : each.message,
666
+ }));
667
+ }
668
+
650
669
  /**
651
670
  * Unified entry: validate the LOCAL integration (no `pkg`) or an INSTALLED one
652
671
  * (`pkg` given) and return the `integration.validate` envelope. The no-manifest
@@ -697,6 +716,11 @@ export async function validateIntegration(pkg, options = {}) {
697
716
  ...(names ?? []).flatMap(each => each.notes),
698
717
  ]
699
718
  : [];
719
+ // Each Astryx command a topic writes with a package runner, as a
720
+ // `runner_command` note with its fix, the same way.
721
+ if (integration?.docs) {
722
+ notes.push(...(await runnerCommandNotes(integration)));
723
+ }
700
724
  return {
701
725
  type: 'integration.validate',
702
726
  data: {
@@ -47,7 +47,8 @@ export type ValidateIntegrationResponse = {
47
47
  * whose file name differs from its source only in letter case where the two
48
48
  * still pair (`source_without_component_doc`); and `doc_name_mismatch` and
49
49
  * `unknown_block_component` (see `docNames` and `blockComponents`); they
50
- * become warnings in the next minor release
50
+ * become warnings in the next minor release; and `runner_command`, an
51
+ * Astryx command a topic writes with a package runner
51
52
  */
52
53
  data: {
53
54
  validated: boolean;
@@ -51,7 +51,8 @@
51
51
  * whose file name differs from its source only in letter case where the two
52
52
  * still pair (`source_without_component_doc`); and `doc_name_mismatch` and
53
53
  * `unknown_block_component` (see `docNames` and `blockComponents`); they
54
- * become warnings in the next minor release
54
+ * become warnings in the next minor release; and `runner_command`, an
55
+ * Astryx command a topic writes with a package runner
55
56
  */
56
57
 
57
58
  /**
@@ -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 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. 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).',
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 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).',
66
66
  },
67
67
  ],
68
68
  examples: [
@@ -104,7 +104,7 @@ export function scoreCandidate(
104
104
  for (const candidateName of [name, ...aliases.filter(Boolean)]) {
105
105
  const nameLower = candidateName.toLowerCase();
106
106
  // A placed guide's name is its route, and the route's last segment is its
107
- // name too, as a flat topic's is: `codemods` is cli/integrations/codemods.
107
+ // name too, as a flat topic's is: `codemods` is authoring/building-blocks/codemods.
108
108
  const leafLower = nameLower.slice(nameLower.lastIndexOf('/') + 1);
109
109
 
110
110
  // A plural of the name is the name: `integration` is the `integrations`
@@ -6,6 +6,7 @@
6
6
  * Built once per gathered catalog.
7
7
  */
8
8
 
9
+ import {createHash} from 'node:crypto';
9
10
  import {DOMAINS, words, fold, nameWords} from './_query-words.mjs';
10
11
 
11
12
  /** @param {string[]} list @returns {Map<string, number>} */
@@ -57,6 +58,62 @@ export const entryId = c =>
57
58
  export function entryTable(all, cards) {
58
59
  const hit = tables.get(all);
59
60
  if (hit) return hit;
61
+ // Each search gathers a fresh candidate list, so the table is also kept by
62
+ // the text it is built from: an unchanged catalog reuses it.
63
+ const key = fingerprint(all, cards);
64
+ if (last && last.key === key) {
65
+ tables.set(all, last.table);
66
+ return last.table;
67
+ }
68
+ const built = buildTable(all, cards);
69
+ last = {key, table: built};
70
+ tables.set(all, built);
71
+ return built;
72
+ }
73
+
74
+ /** @type {{key: string, table: EntryTable} | null} */
75
+ let last = null;
76
+ /** @type {WeakMap<object, number>} */
77
+ const cardIds = new WeakMap();
78
+ let nextCardId = 0;
79
+
80
+ /**
81
+ * Everything the table reads from the catalog, hashed.
82
+ * @param {any[]} all
83
+ * @param {object} cards
84
+ * @returns {string}
85
+ */
86
+ function fingerprint(all, cards) {
87
+ if (!cardIds.has(cards)) cardIds.set(cards, nextCardId++);
88
+ const h = createHash('sha1');
89
+ h.update(String(cardIds.get(cards)));
90
+ for (const c of all) {
91
+ h.update(
92
+ JSON.stringify([
93
+ c.domain,
94
+ c.name,
95
+ c._topic,
96
+ c._section,
97
+ c._resultName,
98
+ c._package,
99
+ c.description,
100
+ c.keywords,
101
+ c.aliases,
102
+ c.titles,
103
+ (c.guidance ?? []).slice(0, 10),
104
+ (c.prose ?? []).slice(0, 4),
105
+ ]),
106
+ );
107
+ }
108
+ return h.digest('hex');
109
+ }
110
+
111
+ /**
112
+ * @param {any[]} all
113
+ * @param {Record<string, {what?: string, synonyms?: string[], props?: string[]}>} cards
114
+ * @returns {EntryTable}
115
+ */
116
+ function buildTable(all, cards) {
60
117
  /** @type {Map<string, any[]>} */
61
118
  const by = new Map();
62
119
  /** @type {Map<string, string>} each id's first package */
@@ -153,6 +210,5 @@ export function entryTable(all, cards) {
153
210
  idf.set(w, Math.log(1 + (n - d + 0.5) / (d + 0.5)));
154
211
  table.fields[f] = {post, idf, len, avg: len.reduce((a, b) => a + b, 0) / n};
155
212
  }
156
- tables.set(all, table);
157
213
  return table;
158
214
  }
@@ -63,7 +63,7 @@ export async function gatherDocs(cwd) {
63
63
  // integration issues; search just cannot index it.
64
64
  }
65
65
  const doc = lowered?.doc ?? null;
66
- // A flat topic lives in the Unorganized level; its hits say so, and name
66
+ // A flat topic lives in its topic level; its hits say so, and name
67
67
  // the package each section came from.
68
68
  const home = tree?.get(entry.name);
69
69
  const placed = home?.ref?.flatTopic === entry.name ? home : null;
@@ -176,7 +176,7 @@ export async function gatherDocs(cwd) {
176
176
  * @param {string} [path] - where the topic lives in the docs tree, as titles
177
177
  * joined by ` › `; a flat topic is its own title
178
178
  * @param {string} [parent] - the command that opens the level above the
179
- * topic: its namespace, or the Unorganized level for a flat topic
179
+ * topic: its namespace, or the topic level for a flat topic
180
180
  * @param {string} [pkg] - the npm package that authored the topic
181
181
  * @param {(key: string) => string} [sectionPackage] - the npm package a
182
182
  * section came from: an extension's section names the extension's package
@@ -197,7 +197,7 @@ function topicCandidates(
197
197
  const docTitle = path || doc?.title || title || name;
198
198
  const split = sections.length > 1;
199
199
  // A placed guide also answers to its last route segment's words:
200
- // `quick start` is cli/integrations/quick-start.
200
+ // `quick start` is authoring/quick-start.
201
201
  const leaf = name.slice(name.lastIndexOf('/') + 1);
202
202
  /** @type {Candidate[]} */
203
203
  const out = [