@astryxdesign/cli 0.6.3-canary.2bb99ed → 0.6.3-canary.2bdba84

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 (216) hide show
  1. package/README.md +21 -19
  2. package/api/build/_adapter.d.mts +50 -0
  3. package/api/build/_adapter.mjs +60 -0
  4. package/api/build/build.doc.mjs +13 -7
  5. package/api/build/build.test.mjs +184 -6
  6. package/api/build/build.type.d.mts +57 -2
  7. package/api/build/build.type.mjs +30 -7
  8. package/api/build/help/help.d.mts +4 -0
  9. package/api/build/help/help.mjs +24 -11
  10. package/api/build/kit/kit.d.mts +4 -1
  11. package/api/build/kit/kit.mjs +165 -49
  12. package/api/build/kit/rank.d.mts +44 -0
  13. package/api/build/kit/rank.mjs +432 -0
  14. package/api/build/kit/rank.test.mjs +196 -0
  15. package/api/component/_adapter.d.mts +6 -12
  16. package/api/component/_adapter.mjs +20 -10
  17. package/api/component/component.mjs +60 -12
  18. package/api/component/list/list.mjs +3 -2
  19. package/api/docs/_adapter.d.mts +251 -28
  20. package/api/docs/_adapter.mjs +918 -35
  21. package/api/docs/detail/detail.mjs +11 -3
  22. package/api/docs/detail/section/section.mjs +20 -3
  23. package/api/docs/docs.d.mts +5 -3
  24. package/api/docs/docs.doc.mjs +38 -17
  25. package/api/docs/docs.mjs +44 -8
  26. package/api/docs/docs.test.mjs +158 -4
  27. package/api/docs/docs.type.d.mts +181 -2
  28. package/api/docs/docs.type.mjs +117 -3
  29. package/api/docs/index/index.mjs +11 -3
  30. package/api/docs/index/index.test.mjs +1 -1
  31. package/api/docs/integration-tree.test.mjs +555 -0
  32. package/api/docs/integrationDocs.test.mjs +14 -14
  33. package/api/docs/list/list.mjs +25 -5
  34. package/api/docs/node/node.d.mts +43 -0
  35. package/api/docs/node/node.mjs +192 -0
  36. package/api/docs/reference-blocks.test.mjs +406 -0
  37. package/api/doctor/doctor.d.mts +30 -2
  38. package/api/doctor/doctor.mjs +150 -7
  39. package/api/doctor/doctor.test.mjs +89 -1
  40. package/api/index.d.mts +1 -1
  41. package/api/index.mjs +1 -0
  42. package/api/init/init.doc.mjs +1 -1
  43. package/api/integration/add-contribution.d.mts +2 -1
  44. package/api/integration/add-contribution.mjs +107 -5
  45. package/api/integration/add-contribution.test.mjs +137 -0
  46. package/api/integration/authoring-checks.mjs +138 -28
  47. package/api/integration/authoring-checks.test.mjs +171 -3
  48. package/api/integration/authoring-checks.type.mjs +6 -1
  49. package/api/integration/integration-authoring.type.d.mts +2 -0
  50. package/api/integration/integration-authoring.type.mjs +2 -0
  51. package/api/integration/integrationAdd.doc.mjs +6 -0
  52. package/api/integration/integrationAddDoc.doc.mjs +7 -1
  53. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  54. package/api/integration/integrationPackCheck.doc.mjs +1 -1
  55. package/api/integration/integrationTemplateConflicts.doc.d.mts +3 -0
  56. package/api/integration/integrationTemplateConflicts.doc.mjs +3 -0
  57. package/api/integration/pack-check.mjs +34 -0
  58. package/api/integration/pack-check.test.mjs +121 -0
  59. package/api/integration/pack-check.type.d.mts +26 -2
  60. package/api/integration/pack-check.type.mjs +14 -1
  61. package/api/integration/template-conflict-compatibility.test.mjs +73 -0
  62. package/api/integration/validate-integration.test.mjs +3 -3
  63. package/api/integration/validateIntegration.doc.mjs +1 -1
  64. package/api/json/index.ts +2 -0
  65. package/api/layout/_adapter.mjs +20 -5
  66. package/api/search/search.d.mts +59 -1
  67. package/api/search/search.doc.mjs +4 -3
  68. package/api/search/search.mjs +442 -71
  69. package/api/search/search.test.mjs +91 -2
  70. package/api/search/search.type.d.mts +13 -1
  71. package/api/search/search.type.mjs +4 -1
  72. package/api/template/list/list.mjs +1 -0
  73. package/api/template/table-floating-bulk-actions.test.mjs +66 -0
  74. package/api/template/template-integration.test.mjs +1072 -3
  75. package/api/template/template.doc.mjs +27 -7
  76. package/api/template/template.mjs +45 -8
  77. package/api/template/template.type.d.mts +6 -8
  78. package/api/template/template.type.mjs +3 -2
  79. package/api/theme/template/template.test.mjs +5 -0
  80. package/api/theme/themeTemplate.doc.mjs +1 -1
  81. package/assets/docs/getting-started.doc.mjs +2 -2
  82. package/assets/docs/layout.doc.dense.mjs +2 -2
  83. package/assets/docs/layout.doc.mjs +1 -1
  84. package/assets/docs/principles.doc.mjs +6 -6
  85. package/assets/docs/styling-libraries.doc.mjs +3 -3
  86. package/assets/docs/styling.doc.mjs +4 -4
  87. package/assets/docs/theme.doc.mjs +4 -4
  88. package/assets/docs/tokens.doc.mjs +1 -1
  89. package/assets/docs/tree/api.doc.mjs +30 -0
  90. package/assets/docs/tree/cli.doc.mjs +23 -0
  91. package/assets/docs/tree/commands.doc.mjs +25 -0
  92. package/assets/docs/{cli-integrations.doc.mjs → tree/integrations.doc.mjs} +37 -9
  93. package/assets/docs/tree/integrations.test.mjs +62 -0
  94. package/assets/docs/tree/writing-docs.doc.mjs +286 -0
  95. package/assets/docs/working-with-ai.doc.mjs +3 -3
  96. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.doc.mjs +1 -1
  97. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.tsx +1 -3
  98. package/assets/templates/blocks/components/Table/TableBulkActionsTable.doc.mjs +14 -0
  99. package/assets/templates/blocks/components/Table/TableBulkActionsTable.tsx +71 -0
  100. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.doc.mjs +19 -0
  101. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.tsx +139 -0
  102. package/authoring/debug/parse.d.mts +3 -3
  103. package/authoring/doctypes/_schema.d.mts +72 -0
  104. package/authoring/doctypes/_schema.mjs +25 -1
  105. package/authoring/doctypes/base/graph-fields.doc.mjs +7 -5
  106. package/authoring/doctypes/base/type.ts +6 -5
  107. package/authoring/doctypes/command/command.doc.mjs +1 -1
  108. package/authoring/doctypes/command/type.ts +2 -2
  109. package/authoring/doctypes/enum/enum.doc.mjs +1 -1
  110. package/authoring/doctypes/enum/type.ts +1 -1
  111. package/authoring/doctypes/function/function.doc.mjs +3 -2
  112. package/authoring/doctypes/function/type.ts +3 -2
  113. package/authoring/doctypes/load-contract.test.mjs +25 -0
  114. package/authoring/doctypes/namespace/namespace.doc.mjs +5 -9
  115. package/authoring/doctypes/reference/reference.doc.mjs +31 -4
  116. package/authoring/doctypes/reference/type.ts +23 -5
  117. package/authoring/doctypes/schema/schema.doc.mjs +1 -1
  118. package/authoring/doctypes/schema/type.ts +1 -1
  119. package/authoring/doctypes/template/parse.d.mts +2 -0
  120. package/authoring/doctypes/template/parse.mjs +4 -0
  121. package/authoring/doctypes/template/parse.test.mjs +18 -0
  122. package/authoring/doctypes/template/template.doc.mjs +6 -0
  123. package/authoring/doctypes/template/type.ts +8 -0
  124. package/authoring/identity/identity.doc.mjs +2 -2
  125. package/authoring/integration/type.ts +1 -1
  126. package/clients/cli/commands/build-theme.adaptations.test.mjs +100 -1
  127. package/clients/cli/commands/build-theme.mjs +1 -1
  128. package/clients/cli/commands/build.doc.mjs +11 -6
  129. package/clients/cli/commands/build.mjs +105 -67
  130. package/clients/cli/commands/build.text-fields.test.mjs +41 -0
  131. package/clients/cli/commands/component/index.mjs +1 -1
  132. package/clients/cli/commands/component-ownership.test.mjs +3 -3
  133. package/clients/cli/commands/discover.broken-integration.test.mjs +7 -8
  134. package/clients/cli/commands/discover.mjs +1 -1
  135. package/clients/cli/commands/docs.doc.mjs +20 -8
  136. package/clients/cli/commands/docs.mjs +177 -20
  137. package/clients/cli/commands/docs.test.mjs +114 -7
  138. package/clients/cli/commands/doctor-integration-docs.doc.mjs +2 -2
  139. package/clients/cli/commands/doctor-integration-templates.doc.mjs +14 -7
  140. package/clients/cli/commands/doctor-integration.test.mjs +75 -1
  141. package/clients/cli/commands/doctor.mjs +53 -16
  142. package/clients/cli/commands/integration-add.doc.mjs +10 -0
  143. package/clients/cli/commands/integration.mjs +1 -0
  144. package/clients/cli/commands/search.mjs +11 -2
  145. package/clients/cli/commands/setup-nudge.test.mjs +6 -0
  146. package/clients/cli/commands/template.doc.mjs +23 -6
  147. package/clients/cli/commands/template.mjs +4 -91
  148. package/clients/cli/commands/text-json-parity.test.mjs +2 -1
  149. package/clients/cli/index.mjs +8 -0
  150. package/clients/cli/lib/manifest.mjs +9 -2
  151. package/foundation/agent-docs/agent-docs.d.mts +3 -2
  152. package/foundation/agent-docs/agent-docs.mjs +13 -9
  153. package/foundation/agent-docs/agent-docs.test.mjs +19 -1
  154. package/foundation/config/project.d.mts +12 -11
  155. package/foundation/config/project.mjs +73 -59
  156. package/foundation/config/project.test.mjs +141 -5
  157. package/foundation/discovery/authoring-self-docs.d.mts +12 -0
  158. package/foundation/discovery/authoring-self-docs.mjs +20 -8
  159. package/foundation/discovery/authoring-self-docs.test.mjs +24 -9
  160. package/foundation/discovery/cli-self-docs.d.mts +40 -34
  161. package/foundation/discovery/cli-self-docs.mjs +91 -115
  162. package/foundation/discovery/cli-self-docs.test.mjs +104 -166
  163. package/foundation/discovery/component-discovery.d.mts +38 -0
  164. package/foundation/discovery/component-discovery.mjs +48 -0
  165. package/foundation/discovery/docs-discovery.d.mts +109 -9
  166. package/foundation/discovery/docs-discovery.mjs +217 -19
  167. package/foundation/discovery/docs-discovery.test.mjs +96 -17
  168. package/foundation/discovery/docs-output-budget.d.mts +2 -2
  169. package/foundation/discovery/docs-output-budget.mjs +1 -1
  170. package/foundation/discovery/docs-section-key.d.mts +9 -2
  171. package/foundation/discovery/docs-section-key.mjs +15 -1
  172. package/foundation/discovery/template-adapter.d.mts +92 -6
  173. package/foundation/discovery/template-adapter.mjs +453 -17
  174. package/foundation/discovery/template-adapter.test.mjs +42 -0
  175. package/foundation/discovery/template-conflict-release.d.mts +13 -0
  176. package/foundation/discovery/template-conflict-release.mjs +40 -0
  177. package/foundation/discovery/template-conflict-release.test.mjs +40 -0
  178. package/foundation/doc-compiler/bundle.mjs +61 -1
  179. package/foundation/doc-compiler/bundle.test.mjs +21 -10
  180. package/foundation/doc-compiler/compile.d.mts +113 -132
  181. package/foundation/doc-compiler/compile.mjs +52 -6
  182. package/foundation/doc-compiler/diagnostics.mjs +28 -0
  183. package/foundation/doc-compiler/doc-loads.test.mjs +2 -2
  184. package/foundation/doc-compiler/inputs.d.mts +2 -2
  185. package/foundation/doc-compiler/inputs.mjs +6 -1
  186. package/foundation/doc-compiler/ir.mjs +7 -0
  187. package/foundation/doc-compiler/lenses.d.mts +8 -5
  188. package/foundation/doc-compiler/lenses.mjs +50 -4
  189. package/foundation/doc-compiler/links.d.mts +162 -0
  190. package/foundation/doc-compiler/links.mjs +294 -0
  191. package/foundation/doc-compiler/links.test.mjs +192 -0
  192. package/foundation/doc-compiler/lower-doc.test.mjs +5 -2
  193. package/foundation/doc-compiler/read.d.mts +3 -2
  194. package/foundation/doc-compiler/read.mjs +6 -1
  195. package/foundation/doc-compiler/tree.d.mts +288 -0
  196. package/foundation/doc-compiler/tree.mjs +876 -0
  197. package/foundation/doc-compiler/tree.test.mjs +598 -0
  198. package/foundation/integrations/autolink.test.mjs +1 -1
  199. package/foundation/integrations/cli-requirement.d.mts +45 -0
  200. package/foundation/integrations/cli-requirement.mjs +154 -0
  201. package/foundation/integrations/cli-requirement.test.mjs +84 -0
  202. package/foundation/integrations/contribution-inventory.d.mts +2 -1
  203. package/foundation/integrations/contribution-inventory.mjs +10 -4
  204. package/foundation/integrations/contribution-inventory.test.mjs +19 -0
  205. package/foundation/integrations/integration-warnings.d.mts +9 -2
  206. package/foundation/integrations/integration-warnings.mjs +51 -26
  207. package/foundation/integrations/integration-warnings.test.mjs +74 -1
  208. package/foundation/integrations/validate-contributions.mjs +25 -27
  209. package/foundation/response/response-types.doc.d.mts +5 -1
  210. package/foundation/response/response-types.doc.mjs +19 -10
  211. package/foundation/text/string-utils.d.mts +8 -0
  212. package/foundation/text/string-utils.mjs +18 -0
  213. package/foundation/xle/expand.mjs +1 -1
  214. package/foundation/xle/xle.test.mjs +13 -0
  215. package/package.json +9 -9
  216. package/assets/docs/cli.doc.mjs +0 -15
@@ -5,6 +5,8 @@
5
5
  * @typedef {object} DocsTopicRecord A doc file discovered under a docs root.
6
6
  * @property {string} name
7
7
  * @property {string} package owner package
8
+ * @property {string} [providerId] the owner's ProviderId, when it differs from
9
+ * the package name
8
10
  * @property {string} path absolute path to the doc file
9
11
  * @property {string} [title]
10
12
  * @property {string} [description]
@@ -16,13 +18,21 @@
16
18
  * @typedef {object} DocsTopicEntry A resolved topic in the catalog.
17
19
  * @property {string} name
18
20
  * @property {string} package owner package
21
+ * @property {string} [providerId] the owner's ProviderId; the package name when
22
+ * absent. Links in the topic resolve against it.
19
23
  * @property {string} path absolute path to the doc file
20
24
  * @property {string} [title]
21
25
  * @property {string} [description]
22
26
  * @property {string|null} [category]
23
27
  * @property {string} [replaces] the topic this one took the place of
24
- * @property {Array<{package: string, path: string}>} extensions overlays to
25
- * merge onto the base doc, in the order their integrations were configured
28
+ * @property {Array<{package: string, path: string, providerId?: string}>} extensions
29
+ * overlays to merge onto the base doc, in the order their integrations were
30
+ * configured; each section an extension adds resolves its links against the
31
+ * extension's provider id (its package name when absent)
32
+ * @property {string} [parent] the route of the namespace a tree guide sits in
33
+ * @property {string} [route] a tree guide's route
34
+ * @property {boolean} [tree] a guide that only the docs tree reads, by its
35
+ * route; never a flat topic
26
36
  */
27
37
  /**
28
38
  * Discover the CLI's own topics.
@@ -48,9 +58,19 @@ export function loadTopicModule(file: string): Promise<unknown>;
48
58
  * where the file that needs fixing can be named.
49
59
  *
50
60
  * @param {any} doc a parsed doc
61
+ * @param {{placement?: boolean}} [options] `placement`: the doc is a guide the
62
+ * docs tree places, so its `placement` field is read, not rejected
51
63
  * @returns {string[]} problems, each already pointed at a place in the doc
52
64
  */
53
- export function problemsInTopic(doc: any): string[];
65
+ export function problemsInTopic(doc: any, { placement }?: {
66
+ placement?: boolean;
67
+ }): string[];
68
+ /**
69
+ * The fields the docs tree reads from a namespace doc an integration ships.
70
+ * @param {any} doc
71
+ * @returns {string[]}
72
+ */
73
+ export function problemsInNamespace(doc: any): string[];
54
74
  /**
55
75
  * Discover the topics contributed by a single loaded integration. Mirrors
56
76
  * `discoverIntegrationComponents`: walk the resolved root, take every
@@ -58,18 +78,25 @@ export function problemsInTopic(doc: any): string[];
58
78
  * discovery this loads each doc, because a topic's name and its relationship
59
79
  * to an existing topic are fields inside the file.
60
80
  *
81
+ * A namespace doc and a guide with `placement` go to the docs tree instead of
82
+ * the topic list (spec:AST-046): they come back in `namespaces` and `guides`,
83
+ * named by the integration's provider id.
84
+ *
61
85
  * Errors are returned, not thrown: one unusable doc is reported as an issue
62
86
  * against its package while the rest of the CLI keeps working.
63
87
  *
64
- * @param {{name: string, docs?: string}} integration a loaded integration
65
- * @returns {Promise<{records: DocsTopicRecord[], errors: Error[]}>}
88
+ * @param {{name: string, docs?: string, providerId?: string}} integration a loaded integration
89
+ * @returns {Promise<{records: DocsTopicRecord[], errors: Error[], namespaces: import('../doc-compiler/tree.mjs').TreeNamespaceInput[], guides: import('../doc-compiler/tree.mjs').TreeDocInput[]}>}
66
90
  */
67
91
  export function discoverIntegrationDocs(integration: {
68
92
  name: string;
69
93
  docs?: string;
94
+ providerId?: string;
70
95
  }): Promise<{
71
96
  records: DocsTopicRecord[];
72
97
  errors: Error[];
98
+ namespaces: import("../doc-compiler/tree.mjs").TreeNamespaceInput[];
99
+ guides: import("../doc-compiler/tree.mjs").TreeDocInput[];
73
100
  }>;
74
101
  /**
75
102
  * Merge an extension onto a base topic: a section with a stable `id` replaces
@@ -95,9 +122,15 @@ export { withSourceTitle };
95
122
  * unlike component discovery, whose built-ins belong to core.
96
123
  */
97
124
  export const BUILTIN_DOCS_PACKAGE: import("../../authoring/index.js").ProviderId;
98
- /** Blocks that are valid authoring but require the compiled graph renderer. */
125
+ /**
126
+ * Blocks that are valid authoring but require the compiled graph renderer: a
127
+ * namespace doc's `blocks` hold them, a topic section does not.
128
+ */
99
129
  export const GRAPH_BLOCK_TYPES: Set<string>;
100
- /** Doc fields only the docs graph reads; a topic that sets one fails to load. */
130
+ /**
131
+ * Doc fields only the docs tree reads. A flat topic that sets one fails to
132
+ * load; a guide the tree places may set `placement` (spec:AST-046).
133
+ */
101
134
  export const GRAPH_ONLY_FIELDS: string[];
102
135
  /**
103
136
  * Every topic a project can read, and the relationships between them.
@@ -114,6 +147,40 @@ export class DocsCatalog {
114
147
  * @returns {DocsCatalog}
115
148
  */
116
149
  static fromBuiltins(builtins?: Record<string, string>): DocsCatalog;
150
+ /**
151
+ * Record a doc file a package ships that did not load. Its package's docs
152
+ * are withdrawn; readers name the package so an author knows where to look.
153
+ * @param {{package: string, message: string}} issue
154
+ */
155
+ addIssue(issue: {
156
+ package: string;
157
+ message: string;
158
+ }): void;
159
+ /**
160
+ * The doc files that did not load, by package.
161
+ * @returns {ReadonlyArray<{package: string, message: string}>}
162
+ */
163
+ get issues(): ReadonlyArray<{
164
+ package: string;
165
+ message: string;
166
+ }>;
167
+ /**
168
+ * Add the namespace docs and placed guides one integration ships to the
169
+ * docs tree (spec:AST-046).
170
+ * @param {{namespaces: import('../doc-compiler/tree.mjs').TreeNamespaceInput[], guides: import('../doc-compiler/tree.mjs').TreeDocInput[]}} inputs
171
+ */
172
+ addTreeInputs(inputs: {
173
+ namespaces: import("../doc-compiler/tree.mjs").TreeNamespaceInput[];
174
+ guides: import("../doc-compiler/tree.mjs").TreeDocInput[];
175
+ }): void;
176
+ /**
177
+ * What the integrations add to the docs tree, in configured order.
178
+ * @returns {ReadonlyArray<{namespaces: import('../doc-compiler/tree.mjs').TreeNamespaceInput[], guides: import('../doc-compiler/tree.mjs').TreeDocInput[]}>}
179
+ */
180
+ get treeInputs(): ReadonlyArray<{
181
+ namespaces: import("../doc-compiler/tree.mjs").TreeNamespaceInput[];
182
+ guides: import("../doc-compiler/tree.mjs").TreeDocInput[];
183
+ }>;
117
184
  /**
118
185
  * Add one integration-contributed doc, honoring what it declares. Returns
119
186
  * the issue it caused, or null when it applied cleanly — the caller owns
@@ -123,6 +190,14 @@ export class DocsCatalog {
123
190
  * @returns {import('../integrations/issue').AstryxIntegrationIssue | null}
124
191
  */
125
192
  add(record: DocsTopicRecord): import("../integrations/issue").AstryxIntegrationIssue | null;
193
+ /**
194
+ * Every other name a topic answers to, lowercased: the names of the topics
195
+ * it replaced, directly or through a chain of replacements. `resolve` finds
196
+ * the topic by each of them.
197
+ * @param {DocsTopicEntry} entry
198
+ * @returns {string[]}
199
+ */
200
+ aliasesOf(entry: DocsTopicEntry): string[];
126
201
  /**
127
202
  * Look a topic up by name, case-insensitively, following the alias a renamed
128
203
  * replacement left behind.
@@ -145,6 +220,11 @@ export type DocsTopicRecord = {
145
220
  * owner package
146
221
  */
147
222
  package: string;
223
+ /**
224
+ * the owner's ProviderId, when it differs from
225
+ * the package name
226
+ */
227
+ providerId?: string | undefined;
148
228
  /**
149
229
  * absolute path to the doc file
150
230
  */
@@ -170,6 +250,11 @@ export type DocsTopicEntry = {
170
250
  * owner package
171
251
  */
172
252
  package: string;
253
+ /**
254
+ * the owner's ProviderId; the package name when
255
+ * absent. Links in the topic resolve against it.
256
+ */
257
+ providerId?: string | undefined;
173
258
  /**
174
259
  * absolute path to the doc file
175
260
  */
@@ -182,12 +267,27 @@ export type DocsTopicEntry = {
182
267
  */
183
268
  replaces?: string | undefined;
184
269
  /**
185
- * overlays to
186
- * merge onto the base doc, in the order their integrations were configured
270
+ * overlays to merge onto the base doc, in the order their integrations were
271
+ * configured; each section an extension adds resolves its links against the
272
+ * extension's provider id (its package name when absent)
187
273
  */
188
274
  extensions: Array<{
189
275
  package: string;
190
276
  path: string;
277
+ providerId?: string;
191
278
  }>;
279
+ /**
280
+ * the route of the namespace a tree guide sits in
281
+ */
282
+ parent?: string | undefined;
283
+ /**
284
+ * a tree guide's route
285
+ */
286
+ route?: string | undefined;
287
+ /**
288
+ * a guide that only the docs tree reads, by its
289
+ * route; never a flat topic
290
+ */
291
+ tree?: boolean | undefined;
192
292
  };
193
293
  import { withSourceTitle } from './docs-section-key.mjs';
@@ -71,6 +71,8 @@ const TOPIC_NAME_RE = /^[\w-]+$/;
71
71
  * @typedef {object} DocsTopicRecord A doc file discovered under a docs root.
72
72
  * @property {string} name
73
73
  * @property {string} package owner package
74
+ * @property {string} [providerId] the owner's ProviderId, when it differs from
75
+ * the package name
74
76
  * @property {string} path absolute path to the doc file
75
77
  * @property {string} [title]
76
78
  * @property {string} [description]
@@ -83,13 +85,21 @@ const TOPIC_NAME_RE = /^[\w-]+$/;
83
85
  * @typedef {object} DocsTopicEntry A resolved topic in the catalog.
84
86
  * @property {string} name
85
87
  * @property {string} package owner package
88
+ * @property {string} [providerId] the owner's ProviderId; the package name when
89
+ * absent. Links in the topic resolve against it.
86
90
  * @property {string} path absolute path to the doc file
87
91
  * @property {string} [title]
88
92
  * @property {string} [description]
89
93
  * @property {string|null} [category]
90
94
  * @property {string} [replaces] the topic this one took the place of
91
- * @property {Array<{package: string, path: string}>} extensions overlays to
92
- * merge onto the base doc, in the order their integrations were configured
95
+ * @property {Array<{package: string, path: string, providerId?: string}>} extensions
96
+ * overlays to merge onto the base doc, in the order their integrations were
97
+ * configured; each section an extension adds resolves its links against the
98
+ * extension's provider id (its package name when absent)
99
+ * @property {string} [parent] the route of the namespace a tree guide sits in
100
+ * @property {string} [route] a tree guide's route
101
+ * @property {boolean} [tree] a guide that only the docs tree reads, by its
102
+ * route; never a flat topic
93
103
  */
94
104
 
95
105
  /**
@@ -135,16 +145,20 @@ const BLOCK_FIELDS = {
135
145
  table: ['headers', 'rows'],
136
146
  list: ['style', 'items'],
137
147
  'token-ref': ['topic', 'section'],
148
+ // A read inlines it as the doc it names includes (spec:AST-047 FR9).
149
+ reference: ['target'],
138
150
  };
139
151
 
140
- /** Blocks that are valid authoring but require the compiled graph renderer. */
141
- export const GRAPH_BLOCK_TYPES = new Set([
142
- 'workflow',
143
- 'collection',
144
- 'reference',
145
- ]);
152
+ /**
153
+ * Blocks that are valid authoring but require the compiled graph renderer: a
154
+ * namespace doc's `blocks` hold them, a topic section does not.
155
+ */
156
+ export const GRAPH_BLOCK_TYPES = new Set(['workflow', 'collection']);
146
157
 
147
- /** Doc fields only the docs graph reads; a topic that sets one fails to load. */
158
+ /**
159
+ * Doc fields only the docs tree reads. A flat topic that sets one fails to
160
+ * load; a guide the tree places may set `placement` (spec:AST-046).
161
+ */
148
162
  export const GRAPH_ONLY_FIELDS = ['placement', 'aliases', 'audience'];
149
163
 
150
164
  /**
@@ -155,6 +169,7 @@ export const GRAPH_ONLY_FIELDS = ['placement', 'aliases', 'audience'];
155
169
  /** @type {Record<string, string[]>} */
156
170
  const OPTIONAL_BLOCK_FIELDS = {
157
171
  code: ['label'],
172
+ reference: ['projection', 'presentation'],
158
173
  };
159
174
 
160
175
  /**
@@ -166,8 +181,12 @@ const OPTIONAL_BLOCK_FIELDS = {
166
181
  const BLOCK_FIELD_VALUES = {
167
182
  heading: {level: [3, 4, 5, 6]},
168
183
  list: {style: ['ordered', 'unordered', 'do', 'dont']},
184
+ reference: {presentation: ['summary', 'compact', 'full']},
169
185
  };
170
186
 
187
+ /** The parts of a doc a reference block's `projection` may select. */
188
+ const PROJECTION_FIELDS = ['fields', 'sections'];
189
+
171
190
  /** Keys a section may carry. */
172
191
  const SECTION_FIELDS = ['id', 'title', 'category', 'content', 'previewType'];
173
192
 
@@ -180,14 +199,16 @@ const SECTION_FIELDS = ['id', 'title', 'category', 'content', 'previewType'];
180
199
  * where the file that needs fixing can be named.
181
200
  *
182
201
  * @param {any} doc a parsed doc
202
+ * @param {{placement?: boolean}} [options] `placement`: the doc is a guide the
203
+ * docs tree places, so its `placement` field is read, not rejected
183
204
  * @returns {string[]} problems, each already pointed at a place in the doc
184
205
  */
185
- export function problemsInTopic(doc) {
186
- // A namespace doc is valid authoring that only the docs graph reads. Said
206
+ export function problemsInTopic(doc, {placement = false} = {}) {
207
+ // A namespace doc is valid authoring that only the docs tree reads. Said
187
208
  // plainly, instead of as the topic fields it does not have.
188
209
  if (doc?.type === 'namespace') {
189
210
  return [
190
- `"${doc.name}" is a namespace doc. Only the docs graph reads namespace docs, and it is not built yet; remove this file from the docs directory.`,
211
+ `"${doc.name}" is a namespace doc, which the docs tree reads, not the topic list. The CLI keeps its own in assets/docs/tree; an integration ships its namespace docs in its docs directory.`,
191
212
  ];
192
213
  }
193
214
  /** @type {string[]} */
@@ -203,6 +224,8 @@ export function problemsInTopic(doc) {
203
224
  );
204
225
  }
205
226
  for (const field of GRAPH_ONLY_FIELDS) {
227
+ // A guide the docs tree places carries `placement`; the tree reads it.
228
+ if (field === 'placement' && placement) continue;
206
229
  if (doc?.[field] != null) {
207
230
  problems.push(
208
231
  `${field}: requires the compiled graph reader and is not supported by legacy topic readers`,
@@ -308,6 +331,34 @@ export function problemsInTopic(doc) {
308
331
  );
309
332
  }
310
333
  }
334
+ // A projection names the parts of the doc to include, so each part
335
+ // it names is a non-empty list of names.
336
+ if (block.type === 'reference' && block.projection != null) {
337
+ const projection = block.projection;
338
+ if (typeof projection !== 'object' || Array.isArray(projection)) {
339
+ problems.push(
340
+ `${blockAt}.projection: expected {fields?, sections?}, naming the parts of the doc to include`,
341
+ );
342
+ } else {
343
+ for (const [key, names] of Object.entries(projection)) {
344
+ if (!PROJECTION_FIELDS.includes(key)) {
345
+ problems.push(
346
+ `${blockAt}.projection.${key}: not a field of a projection`,
347
+ );
348
+ } else if (
349
+ !Array.isArray(names) ||
350
+ names.length === 0 ||
351
+ names.some(
352
+ name => typeof name !== 'string' || name.trim() === '',
353
+ )
354
+ ) {
355
+ problems.push(
356
+ `${blockAt}.projection.${key}: expected a non-empty array of names`,
357
+ );
358
+ }
359
+ }
360
+ }
361
+ }
311
362
  },
312
363
  );
313
364
  },
@@ -319,6 +370,35 @@ export function problemsInTopic(doc) {
319
370
  return problems;
320
371
  }
321
372
 
373
+ /**
374
+ * The fields the docs tree reads from a namespace doc an integration ships.
375
+ * @param {any} doc
376
+ * @returns {string[]}
377
+ */
378
+ export function problemsInNamespace(doc) {
379
+ /** @type {string[]} */
380
+ const problems = [];
381
+ for (const field of ['name', 'title', 'summary']) {
382
+ if (typeof doc?.[field] !== 'string' || doc[field] === '') {
383
+ problems.push(`${field}: expected a non-empty string`);
384
+ }
385
+ }
386
+ const slots = doc?.slots;
387
+ if (slots == null || typeof slots !== 'object' || Object.keys(slots).length === 0) {
388
+ problems.push('slots: expected at least one slot');
389
+ return problems;
390
+ }
391
+ for (const [name, slot] of Object.entries(slots)) {
392
+ if (typeof slot?.title !== 'string' || slot.title === '') {
393
+ problems.push(`slots.${name}.title: expected a non-empty string`);
394
+ }
395
+ if (!Array.isArray(slot?.accepts?.kinds) || slot.accepts.kinds.length === 0) {
396
+ problems.push(`slots.${name}.accepts.kinds: expected at least one kind`);
397
+ }
398
+ }
399
+ return problems;
400
+ }
401
+
322
402
  /**
323
403
  * Discover the topics contributed by a single loaded integration. Mirrors
324
404
  * `discoverIntegrationComponents`: walk the resolved root, take every
@@ -326,11 +406,15 @@ export function problemsInTopic(doc) {
326
406
  * discovery this loads each doc, because a topic's name and its relationship
327
407
  * to an existing topic are fields inside the file.
328
408
  *
409
+ * A namespace doc and a guide with `placement` go to the docs tree instead of
410
+ * the topic list (spec:AST-046): they come back in `namespaces` and `guides`,
411
+ * named by the integration's provider id.
412
+ *
329
413
  * Errors are returned, not thrown: one unusable doc is reported as an issue
330
414
  * against its package while the rest of the CLI keeps working.
331
415
  *
332
- * @param {{name: string, docs?: string}} integration a loaded integration
333
- * @returns {Promise<{records: DocsTopicRecord[], errors: Error[]}>}
416
+ * @param {{name: string, docs?: string, providerId?: string}} integration a loaded integration
417
+ * @returns {Promise<{records: DocsTopicRecord[], errors: Error[], namespaces: import('../doc-compiler/tree.mjs').TreeNamespaceInput[], guides: import('../doc-compiler/tree.mjs').TreeDocInput[]}>}
334
418
  */
335
419
  export async function discoverIntegrationDocs(integration) {
336
420
  const docsDir = integration?.docs;
@@ -338,7 +422,14 @@ export async function discoverIntegrationDocs(integration) {
338
422
  const records = [];
339
423
  /** @type {Error[]} */
340
424
  const errors = [];
341
- if (!docsDir || !fs.existsSync(docsDir)) return {records, errors};
425
+ /** @type {import('../doc-compiler/tree.mjs').TreeNamespaceInput[]} */
426
+ const namespaces = [];
427
+ /** @type {import('../doc-compiler/tree.mjs').TreeDocInput[]} */
428
+ const guides = [];
429
+ if (!docsDir || !fs.existsSync(docsDir)) {
430
+ return {records, errors, namespaces, guides};
431
+ }
432
+ const providerId = integration.providerId ?? integration.name;
342
433
 
343
434
  /** @type {string[]} */
344
435
  const files = [];
@@ -373,11 +464,34 @@ export async function discoverIntegrationDocs(integration) {
373
464
  );
374
465
  continue;
375
466
  }
376
- const problems = problemsInTopic(doc);
467
+ const relative = path.relative(docsDir, file);
468
+ const source = `${integration.name}/${relative.split(path.sep).join('/')}`;
469
+ if (/** @type {any} */ (doc)?.type === 'namespace') {
470
+ const problems = problemsInNamespace(doc);
471
+ if (problems.length > 0) {
472
+ errors.push(
473
+ new Error(
474
+ `${relative} is not a usable namespace doc:\n${problems
475
+ .map(problem => ` ${problem}`)
476
+ .join('\n')}`,
477
+ ),
478
+ );
479
+ continue;
480
+ }
481
+ namespaces.push({
482
+ provider: integration.name,
483
+ providerId,
484
+ source,
485
+ doc: /** @type {any} */ (doc),
486
+ });
487
+ continue;
488
+ }
489
+ const placed = /** @type {any} */ (doc)?.placement != null;
490
+ const problems = problemsInTopic(doc, {placement: placed});
377
491
  if (problems.length > 0) {
378
492
  errors.push(
379
493
  new Error(
380
- `${path.relative(docsDir, file)} is not a usable topic:\n${problems
494
+ `${relative} is not a usable topic:\n${problems
381
495
  .map(problem => ` ${problem}`)
382
496
  .join('\n')}`,
383
497
  ),
@@ -398,6 +512,29 @@ export async function discoverIntegrationDocs(integration) {
398
512
  continue;
399
513
  }
400
514
  seen.set(topicKey, path.relative(docsDir, file));
515
+ if (placed) {
516
+ if (parsed.replaces != null || parsed.extends != null) {
517
+ errors.push(
518
+ new Error(
519
+ `${relative} is placed in the docs tree and also declares \`${parsed.replaces != null ? 'replaces' : 'extends'}\`. A placed guide has its own route; only a flat topic takes over or extends another.`,
520
+ ),
521
+ );
522
+ continue;
523
+ }
524
+ guides.push({
525
+ provider: integration.name,
526
+ providerId,
527
+ source,
528
+ kind: 'generic',
529
+ name: parsed.name,
530
+ title: parsed.title,
531
+ summary: parsed.description,
532
+ group: null,
533
+ placement: parsed.placement,
534
+ ref: {topicFile: file},
535
+ });
536
+ continue;
537
+ }
401
538
  if (parsed.replaces != null && parsed.extends != null) {
402
539
  errors.push(
403
540
  new Error(
@@ -415,10 +552,11 @@ export async function discoverIntegrationDocs(integration) {
415
552
  category: parsed.category ?? null,
416
553
  replaces: parsed.replaces,
417
554
  extendsTopic: parsed.extends,
555
+ ...(providerId === integration.name ? {} : {providerId}),
418
556
  });
419
557
  }
420
558
 
421
- return {records, errors};
559
+ return {records, errors, namespaces, guides};
422
560
  }
423
561
 
424
562
  /**
@@ -504,6 +642,46 @@ export class DocsCatalog {
504
642
  #topics = new Map();
505
643
  /** @type {Map<string, string>} old topic name → the name that replaced it */
506
644
  #aliases = new Map();
645
+ /** @type {Array<{namespaces: import('../doc-compiler/tree.mjs').TreeNamespaceInput[], guides: import('../doc-compiler/tree.mjs').TreeDocInput[]}>} */
646
+ #treeInputs = [];
647
+ /** @type {Array<{package: string, message: string}>} */
648
+ #issues = [];
649
+
650
+ /**
651
+ * Record a doc file a package ships that did not load. Its package's docs
652
+ * are withdrawn; readers name the package so an author knows where to look.
653
+ * @param {{package: string, message: string}} issue
654
+ */
655
+ addIssue(issue) {
656
+ this.#issues.push(issue);
657
+ }
658
+
659
+ /**
660
+ * The doc files that did not load, by package.
661
+ * @returns {ReadonlyArray<{package: string, message: string}>}
662
+ */
663
+ get issues() {
664
+ return this.#issues;
665
+ }
666
+
667
+ /**
668
+ * Add the namespace docs and placed guides one integration ships to the
669
+ * docs tree (spec:AST-046).
670
+ * @param {{namespaces: import('../doc-compiler/tree.mjs').TreeNamespaceInput[], guides: import('../doc-compiler/tree.mjs').TreeDocInput[]}} inputs
671
+ */
672
+ addTreeInputs(inputs) {
673
+ if (inputs.namespaces.length > 0 || inputs.guides.length > 0) {
674
+ this.#treeInputs.push(inputs);
675
+ }
676
+ }
677
+
678
+ /**
679
+ * What the integrations add to the docs tree, in configured order.
680
+ * @returns {ReadonlyArray<{namespaces: import('../doc-compiler/tree.mjs').TreeNamespaceInput[], guides: import('../doc-compiler/tree.mjs').TreeDocInput[]}>}
681
+ */
682
+ get treeInputs() {
683
+ return this.#treeInputs;
684
+ }
507
685
 
508
686
  /**
509
687
  * Seed a catalog with the CLI's own topics.
@@ -541,7 +719,11 @@ export class DocsCatalog {
541
719
  message: `"${record.name}" extends "${record.extendsTopic}", which is not a topic in this project.`,
542
720
  };
543
721
  }
544
- target.extensions.push({package: record.package, path: record.path});
722
+ target.extensions.push({
723
+ package: record.package,
724
+ path: record.path,
725
+ ...(record.providerId ? {providerId: record.providerId} : {}),
726
+ });
545
727
  return null;
546
728
  }
547
729
 
@@ -579,6 +761,7 @@ export class DocsCatalog {
579
761
  description: record.description,
580
762
  category: record.category,
581
763
  replaces: replaced,
764
+ ...(record.providerId ? {providerId: record.providerId} : {}),
582
765
  // Extensions were authored against the content that just went away.
583
766
  extensions: [],
584
767
  });
@@ -608,11 +791,26 @@ export class DocsCatalog {
608
791
  title: record.title,
609
792
  description: record.description,
610
793
  category: record.category,
794
+ ...(record.providerId ? {providerId: record.providerId} : {}),
611
795
  extensions: [],
612
796
  });
613
797
  return null;
614
798
  }
615
799
 
800
+ /**
801
+ * Every other name a topic answers to, lowercased: the names of the topics
802
+ * it replaced, directly or through a chain of replacements. `resolve` finds
803
+ * the topic by each of them.
804
+ * @param {DocsTopicEntry} entry
805
+ * @returns {string[]}
806
+ */
807
+ aliasesOf(entry) {
808
+ const key = entry.name.toLowerCase();
809
+ return [...this.#aliases]
810
+ .filter(([, to]) => to === key)
811
+ .map(([from]) => from);
812
+ }
813
+
616
814
  /**
617
815
  * Look a topic up by name, case-insensitively, following the alias a renamed
618
816
  * replacement left behind.