@astryxdesign/cli 0.6.3-canary.7ada42e → 0.6.3-canary.7ec7be0

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 (221) 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 +24 -13
  23. package/api/docs/detail/section/section.test.mjs +15 -6
  24. package/api/docs/docs.d.mts +5 -3
  25. package/api/docs/docs.doc.mjs +38 -17
  26. package/api/docs/docs.mjs +44 -8
  27. package/api/docs/docs.test.mjs +158 -4
  28. package/api/docs/docs.type.d.mts +181 -2
  29. package/api/docs/docs.type.mjs +117 -3
  30. package/api/docs/index/index.mjs +11 -3
  31. package/api/docs/index/index.test.mjs +1 -1
  32. package/api/docs/integration-tree.test.mjs +555 -0
  33. package/api/docs/integrationDocs.test.mjs +14 -14
  34. package/api/docs/list/list.mjs +25 -5
  35. package/api/docs/node/node.d.mts +43 -0
  36. package/api/docs/node/node.mjs +192 -0
  37. package/api/docs/reference-blocks.test.mjs +406 -0
  38. package/api/doctor/doctor.d.mts +30 -2
  39. package/api/doctor/doctor.mjs +151 -8
  40. package/api/doctor/doctor.test.mjs +95 -7
  41. package/api/index.d.mts +1 -1
  42. package/api/index.mjs +1 -0
  43. package/api/init/init.doc.mjs +1 -1
  44. package/api/integration/add-contribution.d.mts +2 -1
  45. package/api/integration/add-contribution.mjs +107 -5
  46. package/api/integration/add-contribution.test.mjs +137 -0
  47. package/api/integration/authoring-checks.mjs +138 -28
  48. package/api/integration/authoring-checks.test.mjs +171 -3
  49. package/api/integration/authoring-checks.type.mjs +6 -1
  50. package/api/integration/integration-authoring.type.d.mts +2 -0
  51. package/api/integration/integration-authoring.type.mjs +2 -0
  52. package/api/integration/integrationAdd.doc.mjs +6 -0
  53. package/api/integration/integrationAddDoc.doc.mjs +7 -1
  54. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  55. package/api/integration/integrationPackCheck.doc.mjs +1 -1
  56. package/api/integration/integrationTemplateConflicts.doc.d.mts +3 -0
  57. package/api/integration/integrationTemplateConflicts.doc.mjs +3 -0
  58. package/api/integration/pack-check.mjs +34 -0
  59. package/api/integration/pack-check.test.mjs +121 -0
  60. package/api/integration/pack-check.type.d.mts +26 -2
  61. package/api/integration/pack-check.type.mjs +14 -1
  62. package/api/integration/template-conflict-compatibility.test.mjs +73 -0
  63. package/api/integration/validate-integration.test.mjs +3 -3
  64. package/api/integration/validateIntegration.doc.mjs +1 -1
  65. package/api/json/index.ts +2 -0
  66. package/api/layout/_adapter.mjs +20 -5
  67. package/api/search/search.d.mts +59 -1
  68. package/api/search/search.doc.mjs +4 -3
  69. package/api/search/search.mjs +442 -71
  70. package/api/search/search.test.mjs +91 -2
  71. package/api/search/search.type.d.mts +13 -1
  72. package/api/search/search.type.mjs +4 -1
  73. package/api/template/list/list.mjs +1 -0
  74. package/api/template/table-floating-bulk-actions.test.mjs +66 -0
  75. package/api/template/template-integration.test.mjs +1072 -3
  76. package/api/template/template.doc.mjs +27 -7
  77. package/api/template/template.mjs +45 -8
  78. package/api/template/template.type.d.mts +6 -8
  79. package/api/template/template.type.mjs +3 -2
  80. package/api/theme/template/template.test.mjs +5 -0
  81. package/api/theme/themeTemplate.doc.mjs +1 -1
  82. package/assets/docs/getting-started.doc.mjs +2 -2
  83. package/assets/docs/layout.doc.dense.mjs +2 -2
  84. package/assets/docs/layout.doc.mjs +1 -1
  85. package/assets/docs/principles.doc.mjs +6 -6
  86. package/assets/docs/styling-libraries.doc.mjs +3 -3
  87. package/assets/docs/styling.doc.mjs +4 -4
  88. package/assets/docs/theme.doc.mjs +4 -4
  89. package/assets/docs/tokens.doc.mjs +1 -1
  90. package/assets/docs/tree/api.doc.mjs +30 -0
  91. package/assets/docs/tree/cli.doc.mjs +23 -0
  92. package/assets/docs/tree/commands.doc.mjs +25 -0
  93. package/assets/docs/{cli-integrations.doc.mjs → tree/integrations.doc.mjs} +37 -9
  94. package/assets/docs/tree/integrations.test.mjs +62 -0
  95. package/assets/docs/tree/writing-docs.doc.mjs +286 -0
  96. package/assets/docs/working-with-ai.doc.mjs +3 -3
  97. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.doc.mjs +1 -1
  98. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.tsx +1 -3
  99. package/assets/templates/blocks/components/Table/TableBulkActionsTable.doc.mjs +14 -0
  100. package/assets/templates/blocks/components/Table/TableBulkActionsTable.tsx +71 -0
  101. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.doc.mjs +19 -0
  102. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.tsx +139 -0
  103. package/authoring/debug/parse.d.mts +3 -3
  104. package/authoring/doctypes/_schema.d.mts +119 -117
  105. package/authoring/doctypes/_schema.mjs +54 -3
  106. package/authoring/doctypes/base/graph-fields.doc.mjs +7 -5
  107. package/authoring/doctypes/base/type.ts +6 -5
  108. package/authoring/doctypes/command/command.doc.mjs +1 -1
  109. package/authoring/doctypes/command/type.ts +2 -2
  110. package/authoring/doctypes/enum/enum.doc.mjs +1 -1
  111. package/authoring/doctypes/enum/type.ts +1 -1
  112. package/authoring/doctypes/function/function.doc.mjs +3 -2
  113. package/authoring/doctypes/function/type.ts +3 -2
  114. package/authoring/doctypes/load-contract.test.mjs +26 -1
  115. package/authoring/doctypes/namespace/namespace.doc.mjs +6 -10
  116. package/authoring/doctypes/namespace/parse.test.mjs +23 -25
  117. package/authoring/doctypes/namespace/type.ts +5 -2
  118. package/authoring/doctypes/parse.mjs +3 -2
  119. package/authoring/doctypes/reference/reference.doc.mjs +34 -5
  120. package/authoring/doctypes/reference/type.ts +28 -11
  121. package/authoring/doctypes/schema/schema.doc.mjs +1 -1
  122. package/authoring/doctypes/schema/type.ts +1 -1
  123. package/authoring/doctypes/template/parse.d.mts +2 -0
  124. package/authoring/doctypes/template/parse.mjs +4 -0
  125. package/authoring/doctypes/template/parse.test.mjs +18 -0
  126. package/authoring/doctypes/template/template.doc.mjs +6 -0
  127. package/authoring/doctypes/template/type.ts +8 -0
  128. package/authoring/identity/identity.doc.mjs +2 -2
  129. package/authoring/index.d.ts +1 -0
  130. package/authoring/integration/type.ts +1 -1
  131. package/clients/cli/commands/build-theme.adaptations.test.mjs +100 -1
  132. package/clients/cli/commands/build-theme.mjs +1 -1
  133. package/clients/cli/commands/build.doc.mjs +11 -6
  134. package/clients/cli/commands/build.mjs +105 -67
  135. package/clients/cli/commands/build.text-fields.test.mjs +41 -0
  136. package/clients/cli/commands/component/index.mjs +1 -1
  137. package/clients/cli/commands/component-ownership.test.mjs +3 -3
  138. package/clients/cli/commands/discover.broken-integration.test.mjs +7 -8
  139. package/clients/cli/commands/discover.mjs +1 -1
  140. package/clients/cli/commands/docs.doc.mjs +20 -8
  141. package/clients/cli/commands/docs.mjs +183 -69
  142. package/clients/cli/commands/docs.test.mjs +120 -16
  143. package/clients/cli/commands/doctor-integration-docs.doc.mjs +2 -2
  144. package/clients/cli/commands/doctor-integration-templates.doc.mjs +14 -7
  145. package/clients/cli/commands/doctor-integration.test.mjs +75 -1
  146. package/clients/cli/commands/doctor.mjs +53 -16
  147. package/clients/cli/commands/integration-add.doc.mjs +10 -0
  148. package/clients/cli/commands/integration.mjs +1 -0
  149. package/clients/cli/commands/search.mjs +11 -2
  150. package/clients/cli/commands/setup-nudge.test.mjs +6 -0
  151. package/clients/cli/commands/template.doc.mjs +23 -6
  152. package/clients/cli/commands/template.mjs +4 -91
  153. package/clients/cli/index.mjs +8 -0
  154. package/clients/cli/lib/manifest.mjs +9 -2
  155. package/foundation/agent-docs/agent-docs.d.mts +3 -2
  156. package/foundation/agent-docs/agent-docs.mjs +13 -9
  157. package/foundation/agent-docs/agent-docs.test.mjs +19 -1
  158. package/foundation/config/project.d.mts +12 -11
  159. package/foundation/config/project.mjs +73 -59
  160. package/foundation/config/project.test.mjs +141 -5
  161. package/foundation/discovery/authoring-self-docs.d.mts +12 -0
  162. package/foundation/discovery/authoring-self-docs.mjs +20 -8
  163. package/foundation/discovery/authoring-self-docs.test.mjs +25 -9
  164. package/foundation/discovery/cli-self-docs.d.mts +40 -34
  165. package/foundation/discovery/cli-self-docs.mjs +91 -115
  166. package/foundation/discovery/cli-self-docs.test.mjs +104 -166
  167. package/foundation/discovery/component-discovery.d.mts +38 -0
  168. package/foundation/discovery/component-discovery.mjs +48 -0
  169. package/foundation/discovery/docs-discovery.d.mts +109 -9
  170. package/foundation/discovery/docs-discovery.mjs +223 -24
  171. package/foundation/discovery/docs-discovery.test.mjs +103 -27
  172. package/foundation/discovery/docs-output-budget.d.mts +2 -2
  173. package/foundation/discovery/docs-output-budget.mjs +1 -1
  174. package/foundation/discovery/docs-section-key.d.mts +28 -10
  175. package/foundation/discovery/docs-section-key.mjs +134 -33
  176. package/foundation/discovery/docs-section-key.test.mjs +41 -19
  177. package/foundation/discovery/template-adapter.d.mts +92 -6
  178. package/foundation/discovery/template-adapter.mjs +453 -17
  179. package/foundation/discovery/template-adapter.test.mjs +42 -0
  180. package/foundation/discovery/template-conflict-release.d.mts +13 -0
  181. package/foundation/discovery/template-conflict-release.mjs +40 -0
  182. package/foundation/discovery/template-conflict-release.test.mjs +40 -0
  183. package/foundation/doc-compiler/bundle.mjs +61 -1
  184. package/foundation/doc-compiler/bundle.test.mjs +21 -10
  185. package/foundation/doc-compiler/compile.d.mts +113 -132
  186. package/foundation/doc-compiler/compile.mjs +57 -10
  187. package/foundation/doc-compiler/diagnostics.mjs +28 -0
  188. package/foundation/doc-compiler/doc-loads.test.mjs +2 -2
  189. package/foundation/doc-compiler/inputs.d.mts +2 -2
  190. package/foundation/doc-compiler/inputs.mjs +6 -1
  191. package/foundation/doc-compiler/ir.mjs +7 -0
  192. package/foundation/doc-compiler/lenses.d.mts +8 -5
  193. package/foundation/doc-compiler/lenses.mjs +50 -4
  194. package/foundation/doc-compiler/links.d.mts +162 -0
  195. package/foundation/doc-compiler/links.mjs +294 -0
  196. package/foundation/doc-compiler/links.test.mjs +192 -0
  197. package/foundation/doc-compiler/lower-doc.test.mjs +5 -2
  198. package/foundation/doc-compiler/read.d.mts +3 -2
  199. package/foundation/doc-compiler/read.mjs +6 -1
  200. package/foundation/doc-compiler/tree.d.mts +288 -0
  201. package/foundation/doc-compiler/tree.mjs +876 -0
  202. package/foundation/doc-compiler/tree.test.mjs +598 -0
  203. package/foundation/integrations/autolink.test.mjs +1 -1
  204. package/foundation/integrations/cli-requirement.d.mts +45 -0
  205. package/foundation/integrations/cli-requirement.mjs +154 -0
  206. package/foundation/integrations/cli-requirement.test.mjs +84 -0
  207. package/foundation/integrations/contribution-inventory.d.mts +2 -1
  208. package/foundation/integrations/contribution-inventory.mjs +10 -4
  209. package/foundation/integrations/contribution-inventory.test.mjs +19 -0
  210. package/foundation/integrations/integration-warnings.d.mts +9 -2
  211. package/foundation/integrations/integration-warnings.mjs +51 -26
  212. package/foundation/integrations/integration-warnings.test.mjs +74 -1
  213. package/foundation/integrations/validate-contributions.mjs +25 -27
  214. package/foundation/response/response-types.doc.d.mts +5 -1
  215. package/foundation/response/response-types.doc.mjs +19 -10
  216. package/foundation/text/string-utils.d.mts +8 -0
  217. package/foundation/text/string-utils.mjs +18 -0
  218. package/foundation/xle/expand.mjs +1 -1
  219. package/foundation/xle/xle.test.mjs +13 -0
  220. package/package.json +9 -9
  221. package/assets/docs/cli.doc.mjs +0 -15
@@ -60,32 +60,48 @@ describe('authoring self-docs', () => {
60
60
  );
61
61
  });
62
62
 
63
- describe('what the authoring docs say about the unbuilt docs graph', () => {
64
- it('marks exactly the fields topic loading rejects as not read yet', () => {
63
+ describe('what the authoring docs say about the docs tree', () => {
64
+ it('marks exactly the fields the docs tree does not read yet', () => {
65
65
  const notReadYet = graphFieldsDoc.fields
66
66
  .filter(field => /Not read yet/.test(field.description))
67
67
  .map(field => field.name);
68
- expect(notReadYet.sort()).toEqual([...GRAPH_ONLY_FIELDS].sort());
68
+ // The tree reads `placement` for every guide (spec:AST-046); the other
69
+ // graph fields are still refused by every topic reader.
70
+ expect(notReadYet.sort()).toEqual(
71
+ GRAPH_ONLY_FIELDS.filter(field => field !== 'placement').sort(),
72
+ );
69
73
  for (const field of graphFieldsDoc.fields) {
70
- if (notReadYet.includes(field.name)) {
74
+ if (GRAPH_ONLY_FIELDS.includes(field.name)) {
71
75
  expect(field.description).toMatch(/fails to load/);
72
76
  }
73
77
  }
78
+ const placement = graphFieldsDoc.fields.find(f => f.name === 'placement');
79
+ expect(placement.description).toMatch(
80
+ /Read for every guide, the CLI's and each integration's/,
81
+ );
74
82
  expect(graphFieldsDoc.description).toMatch(/not built yet/);
75
83
  });
76
84
 
77
- it('says a topic using a graph block fails to load', () => {
85
+ it('keeps graph blocks behind the separate GraphContentBlock type, and a section takes a reference block', () => {
78
86
  const content = referenceDoc.fields
79
87
  .flatMap(field => [field, ...(field.fields ?? [])])
80
88
  .find(field => field.name === 'sections[].content');
89
+ expect(content.type).toBe('(ReferenceContentBlock | ReferenceDocBlock)[]');
90
+ expect(content.description).toContain('GraphContentBlock');
81
91
  for (const type of GRAPH_BLOCK_TYPES) {
82
92
  expect(content.description).toContain(type);
83
93
  }
84
- expect(content.description).toMatch(/fails to load/);
94
+ // A section's reference block reads as the doc it includes.
95
+ expect(GRAPH_BLOCK_TYPES.has('reference')).toBe(false);
96
+ expect(content.description).toMatch(
97
+ /A `reference` block .* includes another doc/,
98
+ );
85
99
  });
86
100
 
87
- it('says namespace docs are not loaded yet', () => {
88
- expect(namespaceDoc.description).toMatch(/Not loaded yet/);
101
+ it('says where namespace docs live: the CLI tree, and each integration', () => {
102
+ expect(namespaceDoc.description).toMatch(
103
+ /an integration ships its own in its docs directory/,
104
+ );
89
105
  expect(
90
106
  problemsInTopic({
91
107
  ...namespaceDoc.examples?.[0],
@@ -93,7 +109,7 @@ describe('what the authoring docs say about the unbuilt docs graph', () => {
93
109
  name: 'x',
94
110
  }),
95
111
  ).toEqual([
96
- '"x" is a namespace doc. Only the docs graph reads namespace docs, and it is not built yet; remove this file from the docs directory.',
112
+ '"x" 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.',
97
113
  ]);
98
114
  });
99
115
  });
@@ -27,46 +27,45 @@ export function loadCliSelfDocs(sources?: string[], root?: string): Promise<{
27
27
  }[];
28
28
  }>;
29
29
  /**
30
- * A name as a section-key segment: lowercase words joined by hyphens.
31
- * `integrationPackCheck` and `integration pack` both read naturally.
32
- * @param {string} name
33
- * @returns {string}
30
+ * What cross-links need: the loaded function docs by name, the command names,
31
+ * and the route the docs tree gave a doc, if it gave one.
32
+ * @typedef {object} CliDocIndex
33
+ * @property {Map<string, any>} functions
34
+ * @property {Set<string>} commands
35
+ * @property {(kind: string, name: string) => string | null} route
34
36
  */
35
- export function keySegment(name: string): string;
36
37
  /**
37
- * The section key a doc is read by in `astryx docs cli`, or null when its
38
- * namespace is not one of the topic's.
39
- * @param {any} doc
40
- * @returns {string | null}
41
- */
42
- export function cliSectionKey(doc: any): string | null;
43
- /**
44
- * The `cli` topic: one section per doc whose namespace is `cli/…`.
45
- * @param {any[]} docs every loaded CLI doc; the ones in other namespaces are
46
- * left out
47
- * @returns {import('../../authoring/doctypes/reference/type').ReferenceDoc}
38
+ * @param {any[]} docs every loaded CLI typed doc
39
+ * @param {(kind: string, name: string) => string | null} [route]
40
+ * @returns {CliDocIndex}
48
41
  */
49
- export function buildCliReferenceDoc(docs: any[]): import("../../authoring/doctypes/reference/type").ReferenceDoc;
42
+ export function cliDocIndex(docs: any[], route?: (kind: string, name: string) => string | null): CliDocIndex;
50
43
  /**
51
- * The `cli` topic from every CLI doc that loads. One that fails is left out
52
- * here and reported by {@link auditCliSelfDocs}.
53
- * @returns {Promise<import('../../authoring/doctypes/reference/type').ReferenceDoc>}
44
+ * What `astryx docs <route>` prints for one CLI typed doc: its title and the
45
+ * blocks of its content, with cross-links to the routes the tree gave.
46
+ * @param {any} doc
47
+ * @param {CliDocIndex} index
48
+ * @returns {{id: string, title: string, content: any[]}}
54
49
  */
55
- export function buildCliTopic(): Promise<import("../../authoring/doctypes/reference/type").ReferenceDoc>;
50
+ export function cliDocSection(doc: any, index: CliDocIndex): {
51
+ id: string;
52
+ title: string;
53
+ content: any[];
54
+ };
56
55
  /**
57
- * What stands between a CLI doc and a reader: a missing namespace, one no
58
- * topic reads, one that disagrees with the authoring topic's list, a doc that
59
- * fails to load, and a `cli` section that clashes or is too large.
56
+ * What stands between a CLI doc and a reader: a missing namespace, one nothing
57
+ * reads, one that disagrees with the authoring topic's list, a doc that fails
58
+ * to load, and a tree leaf too large for one read. Whether the tree gives
59
+ * every `cli/...` doc a route is the docs-tree check's job.
60
60
  * @param {{root?: string, sources?: string[], budget?: number, authoringSources?: string[]}} [options]
61
61
  * @returns {Promise<{
62
62
  * docs: number,
63
- * sections: number,
63
+ * tree: number,
64
64
  * authoring: number,
65
65
  * missing: string[],
66
66
  * unknown: {source: string, namespace: string}[],
67
67
  * misfiled: {source: string, message: string}[],
68
68
  * failed: {source: string, error: string}[],
69
- * keyProblems: string[],
70
69
  * oversized: {key: string, title: string, bytes: number}[],
71
70
  * }>}
72
71
  */
@@ -77,7 +76,7 @@ export function auditCliSelfDocs({ root, sources, budget, authoringSources, }?:
77
76
  authoringSources?: string[];
78
77
  }): Promise<{
79
78
  docs: number;
80
- sections: number;
79
+ tree: number;
81
80
  authoring: number;
82
81
  missing: string[];
83
82
  unknown: {
@@ -92,7 +91,6 @@ export function auditCliSelfDocs({ root, sources, budget, authoringSources, }?:
92
91
  source: string;
93
92
  error: string;
94
93
  }[];
95
- keyProblems: string[];
96
94
  oversized: {
97
95
  key: string;
98
96
  title: string;
@@ -102,12 +100,20 @@ export function auditCliSelfDocs({ root, sources, budget, authoringSources, }?:
102
100
  /** The directories, relative to the CLI root, that hold the CLI's own docs. */
103
101
  export const CLI_SELF_DOC_DIRS: string[];
104
102
  /**
105
- * Every namespace a CLI doc may declare, and the topic that reads it. A doc in
106
- * a `cli/` namespace is the section `<key prefix>-<name>` of `astryx docs cli`;
107
- * a doc in `authoring` is a section of `astryx docs authoring`.
108
- * @type {Record<string, {topic: string, keyPrefix?: string}>}
103
+ * Every namespace a CLI doc may declare, and what reads it. The docs tree
104
+ * adopts `cli/commands` (under `cli/commands`) and `cli/api` (under
105
+ * `cli/api/<kind>s`); `astryx docs authoring` reads `authoring` from its list.
106
+ * @type {Record<string, {reader: 'tree' | 'authoring'}>}
109
107
  */
110
108
  export const CLI_DOC_NAMESPACES: Record<string, {
111
- topic: string;
112
- keyPrefix?: string;
109
+ reader: "tree" | "authoring";
113
110
  }>;
111
+ /**
112
+ * What cross-links need: the loaded function docs by name, the command names,
113
+ * and the route the docs tree gave a doc, if it gave one.
114
+ */
115
+ export type CliDocIndex = {
116
+ functions: Map<string, any>;
117
+ commands: Set<string>;
118
+ route: (kind: string, name: string) => string | null;
119
+ };
@@ -1,17 +1,18 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file The CLI's own docs, read by their `namespace`: every command, API
5
- * function, schema, and enum doc the CLI ships says which `astryx docs` topic
6
- * reads it, and the `cli` topic is built from the ones that name it.
4
+ * @file The CLI's own typed docs, read by their `namespace`: every command,
5
+ * API function, schema, and enum doc the CLI ships names the group that reads
6
+ * it. The docs tree adopts `cli/commands` and `cli/api` (spec:AST-046); the
7
+ * authoring topic reads `authoring` from its own list.
7
8
  *
8
9
  * @input The command, function, schema, and enum docs under
9
10
  * clients/cli/commands, api, authoring, and foundation.
10
- * @output {@link buildCliTopic} for `astryx docs cli`, and
11
+ * @output {@link loadCliSelfDocs} for the docs tree, {@link cliDocSection} for
12
+ * what `astryx docs <route>` prints for one of them, and
11
13
  * {@link auditCliSelfDocs}, which `astryx doctor` runs.
12
- * @position foundation/discovery — the reader for docs whose namespace starts
13
- * with `cli/`. The authoring topic reads the `authoring` namespace from its
14
- * own list (authoring-self-docs.mjs).
14
+ * @position foundation/discovery. The tree (doc-compiler/tree.mjs) gives each
15
+ * doc its route; this module only loads the docs and renders one.
15
16
  */
16
17
 
17
18
  import * as fs from 'node:fs';
@@ -23,7 +24,7 @@ import {
23
24
  DOC_OUTPUT_BUDGET_BYTES,
24
25
  oversizedDocSections,
25
26
  } from './docs-output-budget.mjs';
26
- import {sectionKeyProblems} from './docs-section-key.mjs';
27
+ import {routeSegment} from './docs-section-key.mjs';
27
28
 
28
29
  /** The directories, relative to the CLI root, that hold the CLI's own docs. */
29
30
  export const CLI_SELF_DOC_DIRS = [
@@ -37,23 +38,20 @@ export const CLI_SELF_DOC_DIRS = [
37
38
  const NAMESPACED_KINDS = new Set(['command', 'function', 'schema', 'enum']);
38
39
 
39
40
  /**
40
- * Every namespace a CLI doc may declare, and the topic that reads it. A doc in
41
- * a `cli/` namespace is the section `<key prefix>-<name>` of `astryx docs cli`;
42
- * a doc in `authoring` is a section of `astryx docs authoring`.
43
- * @type {Record<string, {topic: string, keyPrefix?: string}>}
41
+ * Every namespace a CLI doc may declare, and what reads it. The docs tree
42
+ * adopts `cli/commands` (under `cli/commands`) and `cli/api` (under
43
+ * `cli/api/<kind>s`); `astryx docs authoring` reads `authoring` from its list.
44
+ * @type {Record<string, {reader: 'tree' | 'authoring'}>}
44
45
  */
45
46
  export const CLI_DOC_NAMESPACES = {
46
- 'cli/commands': {topic: 'cli', keyPrefix: 'commands'},
47
- 'cli/api': {topic: 'cli', keyPrefix: 'api'},
48
- authoring: {topic: 'authoring'},
47
+ 'cli/commands': {reader: 'tree'},
48
+ 'cli/api': {reader: 'tree'},
49
+ authoring: {reader: 'authoring'},
49
50
  };
50
51
 
51
52
  /** Blocks a doc's notes may carry that a topic section can render. */
52
53
  const TOPIC_BLOCKS = new Set(['prose', 'list', 'code', 'heading', 'table']);
53
54
 
54
- /** Section order within the `cli` topic: commands, then the API by kind. */
55
- const KIND_ORDER = ['command', 'function', 'schema', 'enum'];
56
-
57
55
  /**
58
56
  * Every `*.doc.mjs` under the CLI's doc directories, relative to `root` and
59
57
  * sorted. Fixture, test, and dependency directories are skipped.
@@ -121,29 +119,27 @@ export async function loadCliSelfDocs(
121
119
  }
122
120
 
123
121
  /**
124
- * A name as a section-key segment: lowercase words joined by hyphens.
125
- * `integrationPackCheck` and `integration pack` both read naturally.
126
- * @param {string} name
127
- * @returns {string}
122
+ * What cross-links need: the loaded function docs by name, the command names,
123
+ * and the route the docs tree gave a doc, if it gave one.
124
+ * @typedef {object} CliDocIndex
125
+ * @property {Map<string, any>} functions
126
+ * @property {Set<string>} commands
127
+ * @property {(kind: string, name: string) => string | null} route
128
128
  */
129
- export function keySegment(name) {
130
- return name
131
- .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
132
- .toLowerCase()
133
- .replace(/[^a-z0-9]+/g, '-')
134
- .replace(/^-+|-+$/g, '');
135
- }
136
129
 
137
130
  /**
138
- * The section key a doc is read by in `astryx docs cli`, or null when its
139
- * namespace is not one of the topic's.
140
- * @param {any} doc
141
- * @returns {string | null}
131
+ * @param {any[]} docs every loaded CLI typed doc
132
+ * @param {(kind: string, name: string) => string | null} [route]
133
+ * @returns {CliDocIndex}
142
134
  */
143
- export function cliSectionKey(doc) {
144
- const prefix = CLI_DOC_NAMESPACES[doc?.namespace]?.keyPrefix;
145
- if (prefix == null) return null;
146
- return `${prefix}-${keySegment(String(doc.name))}`;
135
+ export function cliDocIndex(docs, route = () => null) {
136
+ return {
137
+ functions: new Map(
138
+ docs.filter(d => d.type === 'function').map(d => [d.name, d]),
139
+ ),
140
+ commands: new Set(docs.filter(d => d.type === 'command').map(d => d.name)),
141
+ route,
142
+ };
147
143
  }
148
144
 
149
145
  /** @param {unknown} value */
@@ -197,9 +193,9 @@ function noteBlocks(notes) {
197
193
  }
198
194
 
199
195
  /**
200
- * One command doc as a section of `astryx docs cli`.
196
+ * What `astryx docs <route>` prints for one command doc.
201
197
  * @param {any} cmd
202
- * @param {{functions: Map<string, any>, commands: Set<string>}} index
198
+ * @param {CliDocIndex} index
203
199
  */
204
200
  function commandSection(cmd, index) {
205
201
  const fn = cmd.fn == null ? undefined : index.functions.get(cmd.fn);
@@ -255,6 +251,8 @@ function commandSection(cmd, index) {
255
251
  rows: exitCodes.map((/** @type {any} */ e) => [String(e.code), e.when]),
256
252
  });
257
253
  }
254
+ // Links name docs by identity; the route in each command is derived when
255
+ // the doc is read (spec:AST-047 FR9).
258
256
  const subcommands = (cmd.subcommands ?? []).filter(
259
257
  (/** @type {string} */ sub) => index.commands.has(`${cmd.name} ${sub}`),
260
258
  );
@@ -264,28 +262,44 @@ function commandSection(cmd, index) {
264
262
  style: 'unordered',
265
263
  items: subcommands.map(
266
264
  (/** @type {string} */ sub) =>
267
- `\`astryx ${cmd.name} ${sub}\`: \`astryx docs cli commands-${keySegment(`${cmd.name} ${sub}`)}\``,
265
+ `\`astryx ${cmd.name} ${sub}\`: {@link command:${cmd.name} ${sub}}`,
268
266
  ),
269
267
  });
270
268
  }
271
269
  if (fn != null) {
272
270
  content.push({
273
271
  type: 'prose',
274
- text: `It runs \`${fn.name}()\` from \`${fn.importPath}\`. Read it with \`astryx docs cli ${cliSectionKey(fn)}\`.`,
272
+ text: `It runs \`${fn.name}()\` from \`${fn.importPath}\`. Read it with {@link function:${fn.name}}.`,
275
273
  });
276
274
  }
277
275
  content.push(...noteBlocks(cmd.notes));
278
276
  return {
279
- id: cliSectionKey(cmd),
277
+ id: routeSegment(cmd.name),
280
278
  title: cmd.displayName ?? `astryx ${cmd.name}`,
281
279
  content,
282
280
  };
283
281
  }
284
282
 
285
283
  /**
286
- * One API function doc as a section of `astryx docs cli`.
284
+ * The command doc a command line belongs to: its longest leading words that
285
+ * name one (`integration add theme` is the `integration add` command).
286
+ * @param {string} line
287
+ * @param {Set<string>} commands
288
+ * @returns {string | null}
289
+ */
290
+ function commandDocName(line, commands) {
291
+ const words = line.trim().split(/\s+/);
292
+ for (let n = words.length; n > 0; n--) {
293
+ const name = words.slice(0, n).join(' ');
294
+ if (commands.has(name)) return name;
295
+ }
296
+ return null;
297
+ }
298
+
299
+ /**
300
+ * What `astryx docs <route>` prints for one API function doc.
287
301
  * @param {any} fn
288
- * @param {{functions: Map<string, any>, commands: Set<string>}} index
302
+ * @param {CliDocIndex} index
289
303
  */
290
304
  function functionSection(fn, index) {
291
305
  /** @type {any[]} */
@@ -341,26 +355,28 @@ function functionSection(fn, index) {
341
355
  code: example.code,
342
356
  });
343
357
  }
344
- if (fn.command != null && index.commands.has(fn.command)) {
358
+ const commandDoc =
359
+ fn.command == null ? null : commandDocName(fn.command, index.commands);
360
+ if (commandDoc != null) {
345
361
  content.push({
346
362
  type: 'prose',
347
- text: `\`astryx ${fn.command}\` runs it. Read it with \`astryx docs cli commands-${keySegment(fn.command)}\`.`,
363
+ text: `\`astryx ${fn.command}\` runs it. Read it with {@link command:${commandDoc}}.`,
348
364
  });
349
365
  }
350
366
  return {
351
- id: cliSectionKey(fn),
367
+ id: routeSegment(fn.name),
352
368
  title: fn.displayName ?? `${fn.name}()`,
353
369
  content,
354
370
  };
355
371
  }
356
372
 
357
373
  /**
358
- * One enum doc as a section of `astryx docs cli`.
374
+ * What `astryx docs <route>` prints for one enum doc.
359
375
  * @param {any} doc
360
376
  */
361
377
  function enumSection(doc) {
362
378
  return {
363
- id: cliSectionKey(doc),
379
+ id: routeSegment(doc.name),
364
380
  title: doc.displayName ?? doc.name,
365
381
  content: [
366
382
  {type: 'prose', text: doc.description},
@@ -379,79 +395,33 @@ function enumSection(doc) {
379
395
  }
380
396
 
381
397
  /**
382
- * The docs a `cli/` namespace names, in reading order: commands by name (a
383
- * group before its subcommands), then API functions, schemas, and enums.
384
- * @param {any[]} docs
385
- * @returns {any[]}
386
- */
387
- function cliDocsInOrder(docs) {
388
- return docs
389
- .filter(doc => CLI_DOC_NAMESPACES[doc.namespace]?.topic === 'cli')
390
- .sort(
391
- (a, b) =>
392
- KIND_ORDER.indexOf(a.type) - KIND_ORDER.indexOf(b.type) ||
393
- (a.name < b.name ? -1 : a.name > b.name ? 1 : 0),
394
- );
395
- }
396
-
397
- /**
398
- * The `cli` topic: one section per doc whose namespace is `cli/…`.
399
- * @param {any[]} docs every loaded CLI doc; the ones in other namespaces are
400
- * left out
401
- * @returns {import('../../authoring/doctypes/reference/type').ReferenceDoc}
402
- */
403
- export function buildCliReferenceDoc(docs) {
404
- const ordered = cliDocsInOrder(docs);
405
- const index = {
406
- functions: new Map(
407
- ordered.filter(d => d.type === 'function').map(d => [d.name, d]),
408
- ),
409
- commands: new Set(
410
- ordered.filter(d => d.type === 'command').map(d => d.name),
411
- ),
412
- };
413
- return /** @type {any} */ ({
414
- name: 'cli',
415
- title: 'CLI Reference',
416
- category: 'guide',
417
- description:
418
- 'Every command and API function of the CLI, with the JSON output envelope, error codes, and response types, read from the docs the CLI ships.',
419
- sections: ordered.map(doc =>
420
- doc.type === 'command'
421
- ? commandSection(doc, index)
422
- : doc.type === 'function'
423
- ? functionSection(doc, index)
424
- : doc.type === 'enum'
425
- ? enumSection(doc)
426
- : {...selfDocSection(doc), id: cliSectionKey(doc)},
427
- ),
428
- });
429
- }
430
-
431
- /**
432
- * The `cli` topic from every CLI doc that loads. One that fails is left out
433
- * here and reported by {@link auditCliSelfDocs}.
434
- * @returns {Promise<import('../../authoring/doctypes/reference/type').ReferenceDoc>}
398
+ * What `astryx docs <route>` prints for one CLI typed doc: its title and the
399
+ * blocks of its content, with cross-links to the routes the tree gave.
400
+ * @param {any} doc
401
+ * @param {CliDocIndex} index
402
+ * @returns {{id: string, title: string, content: any[]}}
435
403
  */
436
- export async function buildCliTopic() {
437
- const {loaded} = await loadCliSelfDocs();
438
- return buildCliReferenceDoc(loaded.map(entry => entry.doc));
404
+ export function cliDocSection(doc, index) {
405
+ if (doc.type === 'command') return commandSection(doc, index);
406
+ if (doc.type === 'function') return functionSection(doc, index);
407
+ if (doc.type === 'enum') return enumSection(doc);
408
+ return {...selfDocSection(doc), id: routeSegment(doc.name)};
439
409
  }
440
410
 
441
411
  /**
442
- * What stands between a CLI doc and a reader: a missing namespace, one no
443
- * topic reads, one that disagrees with the authoring topic's list, a doc that
444
- * fails to load, and a `cli` section that clashes or is too large.
412
+ * What stands between a CLI doc and a reader: a missing namespace, one nothing
413
+ * reads, one that disagrees with the authoring topic's list, a doc that fails
414
+ * to load, and a tree leaf too large for one read. Whether the tree gives
415
+ * every `cli/...` doc a route is the docs-tree check's job.
445
416
  * @param {{root?: string, sources?: string[], budget?: number, authoringSources?: string[]}} [options]
446
417
  * @returns {Promise<{
447
418
  * docs: number,
448
- * sections: number,
419
+ * tree: number,
449
420
  * authoring: number,
450
421
  * missing: string[],
451
422
  * unknown: {source: string, namespace: string}[],
452
423
  * misfiled: {source: string, message: string}[],
453
424
  * failed: {source: string, error: string}[],
454
- * keyProblems: string[],
455
425
  * oversized: {key: string, title: string, bytes: number}[],
456
426
  * }>}
457
427
  */
@@ -472,6 +442,8 @@ export async function auditCliSelfDocs({
472
442
  const unknown = [];
473
443
  /** @type {{source: string, message: string}[]} */
474
444
  const misfiled = [];
445
+ /** @type {any[]} */
446
+ const treeDocs = [];
475
447
  let authoring = 0;
476
448
  for (const {source, doc} of loaded) {
477
449
  const namespace = doc.namespace;
@@ -484,7 +456,7 @@ export async function auditCliSelfDocs({
484
456
  continue;
485
457
  }
486
458
  const inAuthoring = listed.has(source);
487
- if (namespace === 'authoring') {
459
+ if (CLI_DOC_NAMESPACES[namespace].reader === 'authoring') {
488
460
  if (inAuthoring) authoring++;
489
461
  else {
490
462
  misfiled.push({
@@ -497,18 +469,22 @@ export async function auditCliSelfDocs({
497
469
  source,
498
470
  message: `${source} is read in \`astryx docs authoring\`, but its namespace is "${namespace}"`,
499
471
  });
472
+ } else {
473
+ treeDocs.push(doc);
500
474
  }
501
475
  }
502
- const topic = buildCliReferenceDoc(loaded.map(entry => entry.doc));
476
+ const index = cliDocIndex(loaded.map(entry => entry.doc));
503
477
  return {
504
478
  docs: loaded.length,
505
- sections: topic.sections.length,
479
+ tree: treeDocs.length,
506
480
  authoring,
507
481
  missing,
508
482
  unknown,
509
483
  misfiled,
510
484
  failed,
511
- keyProblems: sectionKeyProblems(topic.sections),
512
- oversized: oversizedDocSections(topic.sections, budget),
485
+ oversized: oversizedDocSections(
486
+ treeDocs.map(doc => cliDocSection(doc, index)),
487
+ budget,
488
+ ),
513
489
  };
514
490
  }