@astryxdesign/cli 0.7.3 → 0.7.4-canary.1a552f2

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 (244) hide show
  1. package/README.md +63 -63
  2. package/api/component/_adapter.mjs +4 -3
  3. package/api/component/component.mjs +13 -6
  4. package/api/component/doc-links.test.mjs +33 -0
  5. package/api/discover/_adapter.mjs +22 -10
  6. package/api/discover/_catalog-view.d.mts +2 -0
  7. package/api/discover/_catalog-view.mjs +1 -0
  8. package/api/discover/_catalog-view.test.mjs +1 -0
  9. package/api/discover/detail/detail.mjs +1 -0
  10. package/api/discover/detail/detail.test.mjs +3 -0
  11. package/api/discover/detail/doc/doc.mjs +5 -1
  12. package/api/discover/detail/doc/doc.test.mjs +1 -0
  13. package/api/discover/detail/item/item.mjs +2 -0
  14. package/api/discover/detail/item/item.test.mjs +2 -0
  15. package/api/discover/discover.doc.mjs +4 -4
  16. package/api/discover/discover.type.d.mts +20 -0
  17. package/api/discover/discover.type.mjs +5 -0
  18. package/api/discover/list/list.test.mjs +2 -0
  19. package/api/discover/search/search.d.mts +3 -2
  20. package/api/discover/search/search.mjs +26 -7
  21. package/api/discover/search/search.test.mjs +67 -0
  22. package/api/docs/_adapter.d.mts +80 -0
  23. package/api/docs/_adapter.mjs +261 -11
  24. package/api/docs/detail/detail.mjs +8 -0
  25. package/api/docs/docOverlays.test.mjs +2 -1
  26. package/api/docs/docs.d.mts +16 -6
  27. package/api/docs/docs.doc.mjs +1 -1
  28. package/api/docs/docs.mjs +55 -6
  29. package/api/docs/docs.type.d.mts +28 -2
  30. package/api/docs/docs.type.mjs +13 -3
  31. package/api/docs/guide-route-targets.test.mjs +1002 -0
  32. package/api/docs/index/index.mjs +9 -0
  33. package/api/docs/integration-tree.test.mjs +22 -0
  34. package/api/docs/integrationDocs.test.mjs +85 -0
  35. package/api/docs/list/list.mjs +7 -1
  36. package/api/docs/node/node.mjs +9 -1
  37. package/api/docs/reference-blocks.test.mjs +1 -1
  38. package/api/doctor/_adapter.d.mts +40 -0
  39. package/api/doctor/_adapter.mjs +171 -1
  40. package/api/doctor/built-checks.d.mts +85 -0
  41. package/api/doctor/built-checks.mjs +837 -0
  42. package/api/doctor/built-checks.test.mjs +531 -0
  43. package/api/doctor/doctor.d.mts +6 -5
  44. package/api/doctor/doctor.doc.mjs +11 -1
  45. package/api/doctor/doctor.mjs +18 -3
  46. package/api/doctor/doctor.type.d.mts +6 -0
  47. package/api/doctor/doctor.type.mjs +3 -0
  48. package/api/hook/list/list.d.mts +1 -1
  49. package/api/integration/_adapter.d.mts +11 -2
  50. package/api/integration/_adapter.mjs +30 -4
  51. package/api/integration/authoring-checks.mjs +29 -2
  52. package/api/integration/authoring-checks.test.mjs +131 -1
  53. package/api/integration/check/check.d.mts +4 -1
  54. package/api/integration/check/check.mjs +34 -4
  55. package/api/integration/check/check.test.mjs +49 -0
  56. package/api/integration/integration-check.type.d.mts +8 -0
  57. package/api/integration/integration-check.type.mjs +4 -1
  58. package/api/integration/integrationCheck.doc.mjs +8 -1
  59. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  60. package/api/integration/pack-check.mjs +71 -2
  61. package/api/integration/pack-check.test.mjs +77 -0
  62. package/api/integration/validate-integration-case-disk.test.mjs +2 -0
  63. package/api/integration/validate-integration-gaps.test.mjs +7 -4
  64. package/api/integration/validate-integration.mjs +96 -14
  65. package/api/integration/validate-integration.type.d.mts +10 -4
  66. package/api/integration/validate-integration.type.mjs +10 -5
  67. package/api/integration/validateIntegration.doc.mjs +1 -1
  68. package/api/search/_candidate-score.d.mts +3 -2
  69. package/api/search/_candidate-score.mjs +66 -3
  70. package/api/search/_gather-docs.mjs +12 -2
  71. package/api/search/_priority.mjs +2 -1
  72. package/api/search/_score.d.mts +2 -1
  73. package/api/search/_score.mjs +2 -2
  74. package/api/search/search.doc.mjs +1 -1
  75. package/api/search/search.family-members.test.mjs +124 -0
  76. package/api/search/search.mjs +28 -0
  77. package/api/theme/palette/generate/generate.d.mts +8 -0
  78. package/api/theme/palette/generate/generate.mjs +38 -11
  79. package/api/theme/palette/generate/generate.test.mjs +83 -4
  80. package/api/theme/palette/generate/generator.d.mts +6 -0
  81. package/api/theme/palette/generate/generator.mjs +6 -0
  82. package/api/theme/theme.type.d.mts +12 -1
  83. package/api/theme/theme.type.mjs +7 -1
  84. package/api/theme/themeBuild.doc.mjs +1 -1
  85. package/api/theme/themeList.doc.mjs +1 -1
  86. package/api/theme/themePaletteGenerate.doc.mjs +1 -1
  87. package/api/theme/themeTargets.doc.mjs +1 -1
  88. package/assets/discover/official-packages.json +16 -0
  89. package/assets/docs/author-a-theme.doc.mjs +15 -15
  90. package/assets/docs/browser-support.doc.mjs +1 -1
  91. package/assets/docs/getting-started.doc.mjs +16 -16
  92. package/assets/docs/is-my-code-good.doc.mjs +6 -6
  93. package/assets/docs/styling-overview.doc.mjs +5 -5
  94. package/assets/docs/theme.doc.mjs +5 -5
  95. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  96. package/assets/docs/tree/add-a-theme.doc.mjs +2 -2
  97. package/assets/docs/tree/add-a-topic.doc.mjs +6 -6
  98. package/assets/docs/tree/agent-guidance.doc.mjs +5 -5
  99. package/assets/docs/tree/authoring.doc.mjs +2 -2
  100. package/assets/docs/tree/block-template.doc.mjs +1 -1
  101. package/assets/docs/tree/check-the-props.doc.mjs +3 -3
  102. package/assets/docs/tree/check-your-docs.doc.mjs +6 -6
  103. package/assets/docs/tree/checks.doc.mjs +11 -11
  104. package/assets/docs/tree/ci-and-containers.doc.mjs +1 -1
  105. package/assets/docs/tree/cli-command.doc.mjs +6 -6
  106. package/assets/docs/tree/codemods.doc.mjs +7 -7
  107. package/assets/docs/tree/component-family.doc.mjs +1 -1
  108. package/assets/docs/tree/component-imports.doc.mjs +2 -2
  109. package/assets/docs/tree/component-lookups.doc.mjs +6 -5
  110. package/assets/docs/tree/computer-agent-guide.doc.mjs +7 -7
  111. package/assets/docs/tree/computer-integrations.doc.mjs +5 -5
  112. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +3 -3
  113. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  114. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  115. package/assets/docs/tree/doc-syntax.doc.mjs +219 -0
  116. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  117. package/assets/docs/tree/extend-or-replace.doc.mjs +39 -7
  118. package/assets/docs/tree/font-setup.doc.mjs +1 -1
  119. package/assets/docs/tree/generate-a-palette.doc.mjs +1 -1
  120. package/assets/docs/tree/global-integrations.doc.mjs +11 -11
  121. package/assets/docs/tree/global.doc.mjs +2 -2
  122. package/assets/docs/tree/host-entry.doc.mjs +1 -1
  123. package/assets/docs/tree/install-once.doc.mjs +4 -4
  124. package/assets/docs/tree/layout.doc.mjs +1 -1
  125. package/assets/docs/tree/links.doc.mjs +2 -2
  126. package/assets/docs/tree/migration-setup.doc.mjs +15 -15
  127. package/assets/docs/tree/migration.doc.mjs +2 -1
  128. package/assets/docs/tree/other-libraries.doc.mjs +1 -1
  129. package/assets/docs/tree/page-template.doc.mjs +2 -2
  130. package/assets/docs/tree/problems.doc.mjs +8 -8
  131. package/assets/docs/tree/project-global-or-both.doc.mjs +2 -2
  132. package/assets/docs/tree/publishing.doc.mjs +7 -7
  133. package/assets/docs/tree/quick-start.doc.mjs +9 -9
  134. package/assets/docs/tree/reference.doc.mjs +2 -2
  135. package/assets/docs/tree/replace-a-core-component.doc.mjs +1 -1
  136. package/assets/docs/tree/replace-a-core-template.doc.mjs +4 -4
  137. package/assets/docs/tree/scaffold.doc.mjs +1 -1
  138. package/assets/docs/tree/sections-and-placement.doc.mjs +3 -3
  139. package/assets/docs/tree/see-it-in-an-app.doc.mjs +3 -3
  140. package/assets/docs/tree/short-and-findable.doc.mjs +3 -3
  141. package/assets/docs/tree/single-component.doc.mjs +4 -4
  142. package/assets/docs/tree/start-a-template.doc.mjs +5 -5
  143. package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
  144. package/assets/docs/tree/styling-libraries.doc.mjs +2 -1
  145. package/assets/docs/tree/styling.doc.mjs +1 -1
  146. package/assets/docs/tree/tailwind.doc.mjs +1 -1
  147. package/assets/docs/tree/test-in-an-app.doc.mjs +5 -5
  148. package/assets/docs/tree/test-template-in-app.doc.mjs +6 -6
  149. package/assets/docs/tree/tokens-and-setup.doc.mjs +1 -1
  150. package/assets/docs/tree/troubleshooting.doc.mjs +24 -20
  151. package/assets/docs/tree/uninstall.doc.mjs +2 -2
  152. package/assets/docs/tree/updates.doc.mjs +1 -1
  153. package/assets/docs/tree/upgrading.doc.mjs +3 -3
  154. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +1 -1
  155. package/assets/docs/tree/verify-packed-template.doc.mjs +3 -3
  156. package/assets/docs/tree/versioning.doc.mjs +4 -4
  157. package/assets/docs/tree/who-answers.doc.mjs +4 -4
  158. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -4
  159. package/assets/docs/use-a-theme.doc.mjs +10 -10
  160. package/assets/docs/use-integrations.doc.mjs +1 -1
  161. package/assets/docs/working-with-ai.doc.mjs +15 -15
  162. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +1 -1
  163. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +1 -1
  164. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +54 -0
  165. package/assets/templates/themes/butter/butterPalettes.generated.receipt.json +1499 -0
  166. package/assets/templates/themes/butter/butterPalettes.generated.ts +550 -0
  167. package/assets/templates/themes/butter/butterTheme.ts +274 -234
  168. package/assets/templates/themes/butter/palette.config.json +484 -0
  169. package/assets/templates/themes/gothic/gothicPaletteRefs.generated.ts +41 -0
  170. package/assets/templates/themes/gothic/gothicPalettes.generated.receipt.json +979 -0
  171. package/assets/templates/themes/gothic/gothicPalettes.generated.ts +271 -0
  172. package/assets/templates/themes/gothic/gothicTheme.ts +130 -160
  173. package/assets/templates/themes/gothic/palette.config.json +371 -0
  174. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +51 -0
  175. package/assets/templates/themes/matcha/matchaPalettes.generated.receipt.json +1502 -0
  176. package/assets/templates/themes/matcha/matchaPalettes.generated.ts +501 -0
  177. package/assets/templates/themes/matcha/matchaPalettes.ts +21 -0
  178. package/assets/templates/themes/matcha/matchaTheme.ts +164 -103
  179. package/assets/templates/themes/matcha/palette.config.json +448 -0
  180. package/assets/templates/themes/stone/palette.config.json +262 -0
  181. package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +51 -0
  182. package/assets/templates/themes/stone/stonePalettes.generated.receipt.json +840 -0
  183. package/assets/templates/themes/stone/stonePalettes.generated.ts +501 -0
  184. package/assets/templates/themes/stone/stoneTheme.ts +190 -207
  185. package/assets/templates/themes/y2k/palette.config.json +166 -0
  186. package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +54 -0
  187. package/assets/templates/themes/y2k/y2kPalettes.generated.receipt.json +872 -0
  188. package/assets/templates/themes/y2k/y2kPalettes.generated.ts +550 -0
  189. package/assets/templates/themes/y2k/y2kPalettes.ts +257 -0
  190. package/assets/templates/themes/y2k/y2kTheme.ts +164 -391
  191. package/authoring/codemod/codemod.doc.mjs +1 -1
  192. package/authoring/config/config.doc.mjs +4 -4
  193. package/authoring/debug/parse.d.mts +1 -1
  194. package/authoring/discover/discover.doc.mjs +1 -1
  195. package/authoring/doctypes/_schema.d.mts +4 -0
  196. package/authoring/doctypes/_schema.mjs +4 -0
  197. package/authoring/doctypes/reference/type.ts +14 -2
  198. package/authoring/gap-report/gap-report.doc.mjs +1 -1
  199. package/authoring/integration/integration.doc.mjs +6 -6
  200. package/clients/cli/commands/discover.mjs +1 -1
  201. package/clients/cli/commands/discover.sources.test.mjs +6 -0
  202. package/clients/cli/commands/docs.doc.mjs +1 -1
  203. package/clients/cli/commands/docs.mjs +27 -2
  204. package/clients/cli/commands/docs.test.mjs +1 -1
  205. package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -1
  206. package/clients/cli/commands/doctor.doc.mjs +13 -1
  207. package/clients/cli/commands/doctor.mjs +25 -9
  208. package/clients/cli/commands/integration-check.doc.mjs +11 -0
  209. package/clients/cli/commands/integration-check.test.mjs +36 -3
  210. package/clients/cli/commands/integration-pack.doc.mjs +1 -1
  211. package/clients/cli/commands/integration-verify.doc.mjs +1 -1
  212. package/clients/cli/commands/integration.mjs +15 -3
  213. package/clients/cli/commands/theme-targets.doc.mjs +1 -1
  214. package/clients/cli/commands/upgrade.doc.mjs +2 -2
  215. package/clients/cli/lib/define-command.mjs +5 -3
  216. package/foundation/agent-docs/agent-docs.d.mts +14 -2
  217. package/foundation/agent-docs/agent-docs.mjs +65 -4
  218. package/foundation/agent-docs/agent-docs.test.mjs +107 -0
  219. package/foundation/discovery/docs-discovery.d.mts +93 -2
  220. package/foundation/discovery/docs-discovery.mjs +237 -8
  221. package/foundation/discovery/runner-allowlist.d.mts +2 -0
  222. package/foundation/discovery/runner-allowlist.mjs +4 -0
  223. package/foundation/discovery/runner-commands.d.mts +29 -13
  224. package/foundation/discovery/runner-commands.mjs +253 -17
  225. package/foundation/discovery/stray-pointers.mjs +11 -5
  226. package/foundation/discovery/stray-pointers.test.mjs +6 -0
  227. package/foundation/doc-compiler/compile.mjs +8 -1
  228. package/foundation/doc-compiler/doc-loads.test.mjs +3 -0
  229. package/foundation/doc-compiler/doc-syntax.d.mts +194 -0
  230. package/foundation/doc-compiler/doc-syntax.mjs +739 -0
  231. package/foundation/doc-compiler/doc-syntax.test.mjs +383 -0
  232. package/foundation/doc-compiler/links.d.mts +13 -16
  233. package/foundation/doc-compiler/links.mjs +40 -7
  234. package/foundation/doc-compiler/tree.d.mts +5 -0
  235. package/foundation/doc-compiler/tree.mjs +9 -0
  236. package/foundation/env/package-manager.d.mts +18 -0
  237. package/foundation/env/package-manager.mjs +40 -0
  238. package/foundation/integrations/cli-requirement.d.mts +29 -0
  239. package/foundation/integrations/cli-requirement.mjs +47 -0
  240. package/foundation/integrations/cli-requirement.test.mjs +23 -2
  241. package/foundation/response/error-codes.test.mjs +9 -0
  242. package/foundation/response/response-types.doc.mjs +11 -11
  243. package/foundation/response/response-types.doc.test.mjs +29 -0
  244. package/package.json +9 -9
@@ -67,6 +67,29 @@ const INTEGRATION_DOC_SUFFIXES = ['.doc.ts', '.doc.mjs', '.doc.js'];
67
67
  /** A topic name is a CLI argument and a URL segment; keep it to both. */
68
68
  const TOPIC_NAME_RE = /^[\w-]+$/;
69
69
 
70
+ /**
71
+ * Whether a `replaces` or `extends` names a route of the docs tree rather than
72
+ * a flat topic: a topic name never holds a `/`, and a guide the tree places is
73
+ * always read by a route that does.
74
+ * @param {unknown} target
75
+ * @returns {target is string}
76
+ */
77
+ export function isGuideRoute(target) {
78
+ return typeof target === 'string' && target.includes('/');
79
+ }
80
+
81
+ /**
82
+ * What the integrations do to one guide the docs tree places, in configured
83
+ * order: a replacement, and the extensions merged onto whatever is there.
84
+ * @typedef {object} GuideOverlay
85
+ * @property {DocsTopicRecord | null} replacement the doc readers get at the
86
+ * route instead of the guide; the last package configured wins
87
+ * @property {Array<{package: string, path: string, providerId?: string}>} extensions
88
+ * extensions authored after the replacement, if any, in configured order
89
+ * @property {string} [replacedPackage] the package of the replacement this one
90
+ * took over from, when the guide was replaced twice
91
+ */
92
+
70
93
  /**
71
94
  * @typedef {object} DocsTopicRecord A doc file discovered under a docs root.
72
95
  * @property {string} name
@@ -92,6 +115,8 @@ const TOPIC_NAME_RE = /^[\w-]+$/;
92
115
  * @property {string} [description]
93
116
  * @property {string|null} [category]
94
117
  * @property {string} [replaces] the topic this one took the place of
118
+ * @property {string} [replacedPackage] the package whose topic or guide this
119
+ * one took the place of
95
120
  * @property {Array<{package: string, path: string, providerId?: string}>} extensions
96
121
  * overlays to merge onto the base doc, in the order their integrations were
97
122
  * configured; each section an extension adds resolves its links against the
@@ -205,7 +230,21 @@ const BLOCK_FIELD_VALUES = {
205
230
  const PROJECTION_FIELDS = ['fields', 'sections'];
206
231
 
207
232
  /** Keys a section may carry. */
208
- const SECTION_FIELDS = ['id', 'title', 'category', 'content', 'previewType'];
233
+ const SECTION_FIELDS = [
234
+ 'id',
235
+ 'title',
236
+ 'category',
237
+ 'content',
238
+ 'previewType',
239
+ 'before',
240
+ 'after',
241
+ ];
242
+
243
+ /**
244
+ * The fields an extension section places itself with: the key of the base
245
+ * section it goes before or after. Read only by a merge, never by a reader.
246
+ */
247
+ export const SECTION_POSITION_FIELDS = ['before', 'after'];
209
248
 
210
249
  /**
211
250
  * Check the fields the docs surfaces actually read. `parseDoc` is the outer
@@ -265,6 +304,19 @@ export function problemsInTopic(doc, {placement = false} = {}) {
265
304
  problems.push(`${at}.${key}: not a field of a section`);
266
305
  }
267
306
  }
307
+ for (const field of SECTION_POSITION_FIELDS) {
308
+ const value = section?.[field];
309
+ if (value != null && (typeof value !== 'string' || value === '')) {
310
+ problems.push(
311
+ `${at}.${field}: expected the key of a section, as \`--index\` shows it`,
312
+ );
313
+ }
314
+ }
315
+ if (section?.before != null && section?.after != null) {
316
+ problems.push(
317
+ `${at}: sets both \`before\` and \`after\`; a section goes in one place`,
318
+ );
319
+ }
268
320
  if (!Array.isArray(section?.content)) {
269
321
  problems.push(`${at}.content: expected an array of blocks`);
270
322
  return;
@@ -565,6 +617,7 @@ export async function discoverIntegrationDocs(integration) {
565
617
  kind: 'generic',
566
618
  name: parsed.name,
567
619
  title: parsed.title,
620
+ // Rendered once, where the tree is built (api/docs/_adapter.mjs).
568
621
  summary: parsed.description,
569
622
  group: null,
570
623
  placement: parsed.placement,
@@ -599,8 +652,9 @@ export async function discoverIntegrationDocs(integration) {
599
652
  /**
600
653
  * Merge an extension onto a base topic: a section with a stable `id` replaces
601
654
  * the base section with the same `id`; legacy sections without IDs fall back to
602
- * title matching. A section with no match is appended. The title and
603
- * description stay the base topic's: an extension adds to a topic, it never
655
+ * title matching. A section with no match is added: before or after the
656
+ * section whose key its `before` or `after` names, else at the end. The title
657
+ * and description stay the base topic's: an extension adds to a topic, it never
604
658
  * renames it. A topic that `replaces` another is the one that renames.
605
659
  *
606
660
  * Keyed by section TITLE rather than by position, the way the localization
@@ -613,22 +667,123 @@ export async function discoverIntegrationDocs(integration) {
613
667
  * @returns {any} a new doc; neither input is mutated
614
668
  */
615
669
  export function mergeTopic(base, overlay) {
670
+ return mergeTopicReport(base, overlay).doc;
671
+ }
672
+
673
+ /**
674
+ * {@link mergeTopic}, also naming each `before` or `after` that found no
675
+ * section: that section was added at the end instead.
676
+ *
677
+ * @param {any} base
678
+ * @param {any} overlay
679
+ * @returns {{doc: any, unplaced: Array<{section: string, field: 'before' | 'after', key: string}>}}
680
+ */
681
+ export function mergeTopicReport(base, overlay) {
616
682
  const sections = [...(base.sections ?? [])];
617
- for (const section of overlay.sections ?? []) {
683
+ /** @type {Array<{section: string, field: 'before' | 'after', key: string}>} */
684
+ const unplaced = [];
685
+
686
+ for (const authored of overlay.sections ?? []) {
687
+ const section = withoutPosition(authored);
618
688
  const at = findMergeTarget(sections, section);
619
689
  if (at === -1) {
620
- sections.push(section);
690
+ const field = authored.before != null ? 'before' : 'after';
691
+ const key = authored[field];
692
+ if (typeof key !== 'string') {
693
+ sections.push(section);
694
+ continue;
695
+ }
696
+ const anchor = sections.findIndex(
697
+ candidate => sectionKey(candidate) === key || candidate.id === key,
698
+ );
699
+ if (anchor === -1) {
700
+ unplaced.push({section: sectionKey(section), field, key});
701
+ sections.push(section);
702
+ } else if (field === 'before') {
703
+ // Placed just before a section another was placed `after`, it joins
704
+ // that section's group, so later sections placed there follow both.
705
+ if (sections[anchor][PLACED_AFTER] != null) {
706
+ Object.defineProperty(section, PLACED_AFTER, {
707
+ value: sections[anchor][PLACED_AFTER],
708
+ configurable: true,
709
+ });
710
+ }
711
+ sections.splice(anchor, 0, section);
712
+ } else {
713
+ // Sections placed after one key keep their order, across every
714
+ // extension merged onto the topic: each goes after every section
715
+ // placed there before it, and after the sections placed after those.
716
+ const group = new Set([key]);
717
+ let at = anchor + 1;
718
+ while (at < sections.length && group.has(sections[at][PLACED_AFTER])) {
719
+ group.add(sectionKey(sections[at]));
720
+ at += 1;
721
+ }
722
+ Object.defineProperty(section, PLACED_AFTER, {
723
+ value: key,
724
+ configurable: true,
725
+ });
726
+ sections.splice(at, 0, section);
727
+ }
621
728
  } else {
622
729
  // A legacy extension that replaces a section which has since gained a
623
- // stable ID keeps that ID, so readers addressing it keep working.
730
+ // stable ID keeps that ID, so readers addressing it keep working. A
731
+ // replacing section keeps the place of the one it replaces.
624
732
  const replaced = sections[at];
625
- sections[at] =
733
+ const replacing =
626
734
  section.id == null && replaced.id != null
627
735
  ? withSourceTitle({...section, id: replaced.id}, sourceTitle(section))
628
736
  : section;
737
+ // It also keeps the place an earlier `after` gave the one it replaces,
738
+ // so sections placed after that key later still follow it.
739
+ if (replaced[PLACED_AFTER] != null) {
740
+ const placed = replacing === section ? withoutPosition({...section}) : replacing;
741
+ for (const symbol of Object.getOwnPropertySymbols(section)) {
742
+ if (!(symbol in placed)) {
743
+ Object.defineProperty(
744
+ placed,
745
+ symbol,
746
+ /** @type {PropertyDescriptor} */ (
747
+ Object.getOwnPropertyDescriptor(section, symbol)
748
+ ),
749
+ );
750
+ }
751
+ }
752
+ Object.defineProperty(placed, PLACED_AFTER, {
753
+ value: replaced[PLACED_AFTER],
754
+ configurable: true,
755
+ });
756
+ sections[at] = placed;
757
+ } else {
758
+ sections[at] = replacing;
759
+ }
629
760
  }
630
761
  }
631
- return {...base, sections};
762
+ return {doc: {...base, sections}, unplaced};
763
+ }
764
+
765
+ /** The key a merged section was placed `after`, so later ones follow it. */
766
+ const PLACED_AFTER = Symbol('astryx.docs.placedAfter');
767
+
768
+ /**
769
+ * A section without the fields that place it; readers never see them.
770
+ * @param {any} section
771
+ * @returns {any}
772
+ */
773
+ export function withoutPosition(section) {
774
+ if (section?.before == null && section?.after == null) return section;
775
+ const {before: _before, after: _after, ...rest} = section;
776
+ // Copy every own symbol (the provider and authored-title marks) too.
777
+ for (const symbol of Object.getOwnPropertySymbols(section)) {
778
+ Object.defineProperty(
779
+ rest,
780
+ symbol,
781
+ /** @type {PropertyDescriptor} */ (
782
+ Object.getOwnPropertyDescriptor(section, symbol)
783
+ ),
784
+ );
785
+ }
786
+ return rest;
632
787
  }
633
788
 
634
789
  /**
@@ -723,6 +878,71 @@ export class DocsCatalog {
723
878
  #treeInputs = [];
724
879
  /** @type {Array<{package: string, message: string}>} */
725
880
  #issues = [];
881
+ /** @type {Map<string, GuideOverlay>} lowercased route → what applies there */
882
+ #guideOverlays = new Map();
883
+ /** @type {DocsTopicRecord[]} every doc that targets a route, in order */
884
+ #guideTargeters = [];
885
+
886
+ /**
887
+ * Record a doc that replaces or extends a guide the docs tree places, by
888
+ * its route. Whether the route holds such a guide is known only once the
889
+ * tree is built: {@link guideOverlay} applies the record there, and a route
890
+ * that holds none applies nothing.
891
+ * @param {DocsTopicRecord} record
892
+ * @returns {import('../integrations/issue').AstryxIntegrationIssue | null}
893
+ */
894
+ #targetGuide(record) {
895
+ const route = /** @type {string} */ (
896
+ record.replaces ?? record.extendsTopic
897
+ );
898
+ const key = route.toLowerCase();
899
+ const overlay = this.#guideOverlays.get(key) ?? {
900
+ replacement: null,
901
+ extensions: [],
902
+ };
903
+ if (record.replaces != null) {
904
+ const earlier = overlay.replacement;
905
+ if (earlier) {
906
+ // As with a flat topic, the later-configured doc wins, and reads name
907
+ // the replacement it took over from. Unlike a flat topic's, this is
908
+ // no warning: a new failing finding joins only in a minor release
909
+ // (architecture:cli-surface INV35); `integration validate` lists one
910
+ // package's two replacements of a guide as a note.
911
+ overlay.replacedPackage = earlier.package;
912
+ }
913
+ // Extensions were authored against the content that just went away.
914
+ overlay.replacement = record;
915
+ overlay.extensions = [];
916
+ } else {
917
+ overlay.extensions.push({
918
+ package: record.package,
919
+ path: record.path,
920
+ ...(record.providerId ? {providerId: record.providerId} : {}),
921
+ });
922
+ }
923
+ this.#guideOverlays.set(key, overlay);
924
+ this.#guideTargeters.push(record);
925
+ return null;
926
+ }
927
+
928
+ /**
929
+ * What the integrations do to the guide the docs tree places at `route`, or
930
+ * null when they leave it as it is.
931
+ * @param {string} route
932
+ * @returns {GuideOverlay | null}
933
+ */
934
+ guideOverlay(route) {
935
+ return this.#guideOverlays.get(route.toLowerCase()) ?? null;
936
+ }
937
+
938
+ /**
939
+ * Every doc that replaces or extends a guide by its route, in configured
940
+ * order, so a check can name a route that holds no guide.
941
+ * @returns {ReadonlyArray<DocsTopicRecord>}
942
+ */
943
+ get guideTargeters() {
944
+ return this.#guideTargeters;
945
+ }
726
946
 
727
947
  /**
728
948
  * Record a doc file a package ships that did not load. Its package's docs
@@ -810,6 +1030,9 @@ export class DocsCatalog {
810
1030
  add(record) {
811
1031
  if (record.extendsTopic != null) {
812
1032
  const target = this.resolve(record.extendsTopic);
1033
+ if (!target && isGuideRoute(record.extendsTopic)) {
1034
+ return this.#targetGuide(record);
1035
+ }
813
1036
  if (!target) {
814
1037
  return {
815
1038
  code: 'invalid_doc',
@@ -827,6 +1050,9 @@ export class DocsCatalog {
827
1050
 
828
1051
  if (record.replaces != null) {
829
1052
  const target = this.resolve(record.replaces);
1053
+ if (!target && isGuideRoute(record.replaces)) {
1054
+ return this.#targetGuide(record);
1055
+ }
830
1056
  if (!target) {
831
1057
  return {
832
1058
  code: 'invalid_doc',
@@ -859,6 +1085,9 @@ export class DocsCatalog {
859
1085
  description: record.description,
860
1086
  category: record.category,
861
1087
  replaces: replaced,
1088
+ // The package whose topic it took over: an earlier replacement's, when
1089
+ // the topic was already replaced.
1090
+ replacedPackage: target.package,
862
1091
  ...(record.providerId ? {providerId: record.providerId} : {}),
863
1092
  // Extensions were authored against the content that just went away.
864
1093
  extensions: [],
@@ -33,6 +33,8 @@ export const RUNNER_COMMAND_ALLOWLIST: Readonly<{
33
33
  'packages/cli/assets/docs/tree/who-answers.doc.mjs': "explains how printed commands start, the pinned `npx @astryxdesign/cli@<version>` among them";
34
34
  'packages/cli/assets/docs/tree/project-global-or-both.doc.mjs': "compares running the CLI with npx to installing it, and is found by searching for that command";
35
35
  'packages/cli/assets/docs/tree/install-once.doc.mjs': "names a pinned release, `npx @astryxdesign/cli@<version>`, which answers as that version";
36
+ 'packages/cli/assets/docs/tree/doc-syntax.doc.mjs': "shows what each doc token renders as, in every package manager";
37
+ 'packages/cli/assets/docs/tree/add-a-topic.doc.mjs': "shows what a reader sees for a command token, with their runner";
36
38
  'packages/cli/clients/cli/commands/upgrade.doc.mjs': "quotes the command upgrade prints when the CLI is older than Core, pinned to the matching release";
37
39
  }>;
38
40
  }>;
@@ -45,6 +45,10 @@ export const RUNNER_COMMAND_ALLOWLIST = Object.freeze({
45
45
  'compares running the CLI with npx to installing it, and is found by searching for that command',
46
46
  'packages/cli/assets/docs/tree/install-once.doc.mjs':
47
47
  'names a pinned release, `npx @astryxdesign/cli@<version>`, which answers as that version',
48
+ 'packages/cli/assets/docs/tree/doc-syntax.doc.mjs':
49
+ 'shows what each doc token renders as, in every package manager',
50
+ 'packages/cli/assets/docs/tree/add-a-topic.doc.mjs':
51
+ 'shows what a reader sees for a command token, with their runner',
48
52
  'packages/cli/clients/cli/commands/upgrade.doc.mjs':
49
53
  'quotes the command upgrade prints when the CLI is older than Core, pinned to the matching release',
50
54
  }),
@@ -14,24 +14,28 @@ export function runnerCommandsIn(text: string): {
14
14
  download: boolean;
15
15
  }[];
16
16
  /**
17
- * An Astryx command a topic writes with a package runner in front.
18
- *
19
- * @typedef {object} RunnerCommand
20
- * @property {string} topic
21
- * @property {string | null} section the title of the section it is in
22
- * @property {string} file the doc file
23
- * @property {number | null} line the file line that holds it, when found
24
- * @property {string} command the command as written
25
- * @property {string} message the bare command to write instead
17
+ * The doc-syntax findings in one string of a doc, in order: runner commands,
18
+ * package-manager commands, bare Astryx commands and tokens that do not
19
+ * parse, each with what to write instead.
20
+ * @param {string} text
21
+ * @param {string | null} lang the code block's language; null for text
22
+ * @returns {{at: number, written: string, code: string, fix: string}[]}
26
23
  */
24
+ export function docCommandsIn(text: string, lang: string | null): {
25
+ at: number;
26
+ written: string;
27
+ code: string;
28
+ fix: string;
29
+ }[];
27
30
  /**
28
- * Runner commands in a package's topics.
31
+ * The doc-syntax findings in a package's topics, each placed on the file line
32
+ * that holds it.
29
33
  *
30
34
  * @param {{records: {name: string, path: string}[], guides?: {name: string, ref?: {topicFile?: string}}[]}} discovered
31
35
  * the package's docs, as discoverIntegrationDocs returns them
32
36
  * @returns {Promise<RunnerCommand[]>}
33
37
  */
34
- export function findRunnerCommands(discovered: {
38
+ export function findDocCommands(discovered: {
35
39
  records: {
36
40
  name: string;
37
41
  path: string;
@@ -43,6 +47,14 @@ export function findRunnerCommands(discovered: {
43
47
  };
44
48
  }[];
45
49
  }): Promise<RunnerCommand[]>;
50
+ /**
51
+ * Runner commands in a package's topics: the `runner_command` findings of
52
+ * {@link findDocCommands}.
53
+ *
54
+ * @param {Parameters<typeof findDocCommands>[0]} discovered
55
+ * @returns {Promise<RunnerCommand[]>}
56
+ */
57
+ export function findRunnerCommands(discovered: Parameters<typeof findDocCommands>[0]): Promise<RunnerCommand[]>;
46
58
  /**
47
59
  * The CLI's top-level commands, the words that make a project runner's
48
60
  * `astryx <word>` a command; runner-commands.test.mjs keeps the list equal to
@@ -50,9 +62,13 @@ export function findRunnerCommands(discovered: {
50
62
  */
51
63
  export const CLI_COMMANDS: readonly string[];
52
64
  /**
53
- * An Astryx command a topic writes with a package runner in front.
65
+ * A command a topic writes that the doc syntax writes another way: with a
66
+ * runner in front (`runner_command`), a package-manager command written for
67
+ * one package manager (`package_manager_command`), a bare Astryx command
68
+ * (`plain_command`), or a doc token that does not parse (`doc_token`).
54
69
  */
55
70
  export type RunnerCommand = {
71
+ code: string;
56
72
  topic: string;
57
73
  /**
58
74
  * the title of the section it is in
@@ -71,7 +87,7 @@ export type RunnerCommand = {
71
87
  */
72
88
  command: string;
73
89
  /**
74
- * the bare command to write instead
90
+ * what to write instead
75
91
  */
76
92
  message: string;
77
93
  };