@astryxdesign/cli 0.6.3-canary.039a67e → 0.6.3-canary.0550afd

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 (209) 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 +209 -28
  20. package/api/docs/_adapter.mjs +667 -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 +35 -15
  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 +165 -2
  28. package/api/docs/docs.type.mjs +101 -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 +547 -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/doctor/doctor.d.mts +30 -2
  37. package/api/doctor/doctor.mjs +146 -7
  38. package/api/doctor/doctor.test.mjs +89 -1
  39. package/api/index.d.mts +1 -1
  40. package/api/index.mjs +1 -0
  41. package/api/init/init.doc.mjs +1 -1
  42. package/api/integration/add-contribution.d.mts +2 -1
  43. package/api/integration/add-contribution.mjs +107 -5
  44. package/api/integration/add-contribution.test.mjs +137 -0
  45. package/api/integration/authoring-checks.mjs +125 -28
  46. package/api/integration/authoring-checks.test.mjs +171 -3
  47. package/api/integration/authoring-checks.type.mjs +6 -1
  48. package/api/integration/integration-authoring.type.d.mts +2 -0
  49. package/api/integration/integration-authoring.type.mjs +2 -0
  50. package/api/integration/integrationAdd.doc.mjs +6 -0
  51. package/api/integration/integrationAddDoc.doc.mjs +7 -1
  52. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  53. package/api/integration/integrationPackCheck.doc.mjs +1 -1
  54. package/api/integration/integrationTemplateConflicts.doc.d.mts +3 -0
  55. package/api/integration/integrationTemplateConflicts.doc.mjs +3 -0
  56. package/api/integration/pack-check.mjs +34 -0
  57. package/api/integration/pack-check.test.mjs +121 -0
  58. package/api/integration/pack-check.type.d.mts +26 -2
  59. package/api/integration/pack-check.type.mjs +14 -1
  60. package/api/integration/template-conflict-compatibility.test.mjs +73 -0
  61. package/api/integration/validate-integration.test.mjs +3 -3
  62. package/api/integration/validateIntegration.doc.mjs +1 -1
  63. package/api/json/index.ts +2 -0
  64. package/api/layout/_adapter.mjs +20 -5
  65. package/api/search/search.d.mts +59 -1
  66. package/api/search/search.doc.mjs +4 -3
  67. package/api/search/search.mjs +442 -71
  68. package/api/search/search.test.mjs +91 -2
  69. package/api/search/search.type.d.mts +13 -1
  70. package/api/search/search.type.mjs +4 -1
  71. package/api/template/list/list.mjs +1 -0
  72. package/api/template/table-floating-bulk-actions.test.mjs +66 -0
  73. package/api/template/template-integration.test.mjs +1072 -3
  74. package/api/template/template.doc.mjs +27 -7
  75. package/api/template/template.mjs +45 -8
  76. package/api/template/template.type.d.mts +6 -8
  77. package/api/template/template.type.mjs +3 -2
  78. package/api/theme/template/template.test.mjs +5 -0
  79. package/api/theme/themeTemplate.doc.mjs +1 -1
  80. package/assets/docs/getting-started.doc.mjs +2 -2
  81. package/assets/docs/layout.doc.dense.mjs +2 -2
  82. package/assets/docs/layout.doc.mjs +1 -1
  83. package/assets/docs/principles.doc.mjs +6 -6
  84. package/assets/docs/styling-libraries.doc.mjs +2 -2
  85. package/assets/docs/styling.doc.mjs +4 -4
  86. package/assets/docs/theme.doc.mjs +3 -3
  87. package/assets/docs/tokens.doc.mjs +1 -1
  88. package/assets/docs/tree/api.doc.mjs +30 -0
  89. package/assets/docs/tree/cli.doc.mjs +23 -0
  90. package/assets/docs/tree/commands.doc.mjs +25 -0
  91. package/assets/docs/{cli-integrations.doc.mjs → tree/integrations.doc.mjs} +37 -9
  92. package/assets/docs/tree/integrations.test.mjs +62 -0
  93. package/assets/docs/tree/writing-docs.doc.mjs +286 -0
  94. package/assets/docs/working-with-ai.doc.mjs +3 -3
  95. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.doc.mjs +1 -1
  96. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.tsx +1 -3
  97. package/assets/templates/blocks/components/Table/TableBulkActionsTable.doc.mjs +14 -0
  98. package/assets/templates/blocks/components/Table/TableBulkActionsTable.tsx +71 -0
  99. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.doc.mjs +19 -0
  100. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.tsx +139 -0
  101. package/authoring/debug/parse.d.mts +3 -3
  102. package/authoring/doctypes/base/graph-fields.doc.mjs +7 -5
  103. package/authoring/doctypes/base/type.ts +6 -5
  104. package/authoring/doctypes/command/command.doc.mjs +1 -1
  105. package/authoring/doctypes/command/type.ts +2 -2
  106. package/authoring/doctypes/enum/enum.doc.mjs +1 -1
  107. package/authoring/doctypes/enum/type.ts +1 -1
  108. package/authoring/doctypes/function/function.doc.mjs +3 -2
  109. package/authoring/doctypes/function/type.ts +3 -2
  110. package/authoring/doctypes/namespace/namespace.doc.mjs +5 -9
  111. package/authoring/doctypes/reference/reference.doc.mjs +3 -3
  112. package/authoring/doctypes/reference/type.ts +3 -0
  113. package/authoring/doctypes/schema/schema.doc.mjs +1 -1
  114. package/authoring/doctypes/schema/type.ts +1 -1
  115. package/authoring/doctypes/template/parse.d.mts +2 -0
  116. package/authoring/doctypes/template/parse.mjs +4 -0
  117. package/authoring/doctypes/template/parse.test.mjs +18 -0
  118. package/authoring/doctypes/template/template.doc.mjs +6 -0
  119. package/authoring/doctypes/template/type.ts +8 -0
  120. package/authoring/identity/identity.doc.mjs +2 -2
  121. package/authoring/integration/type.ts +1 -1
  122. package/clients/cli/commands/build-theme.mjs +1 -1
  123. package/clients/cli/commands/build.doc.mjs +11 -6
  124. package/clients/cli/commands/build.mjs +105 -67
  125. package/clients/cli/commands/build.text-fields.test.mjs +41 -0
  126. package/clients/cli/commands/component/index.mjs +1 -1
  127. package/clients/cli/commands/component-ownership.test.mjs +3 -3
  128. package/clients/cli/commands/discover.broken-integration.test.mjs +7 -8
  129. package/clients/cli/commands/discover.mjs +1 -1
  130. package/clients/cli/commands/docs.doc.mjs +20 -8
  131. package/clients/cli/commands/docs.mjs +175 -18
  132. package/clients/cli/commands/docs.test.mjs +114 -7
  133. package/clients/cli/commands/doctor-integration-docs.doc.mjs +2 -2
  134. package/clients/cli/commands/doctor-integration-templates.doc.mjs +14 -7
  135. package/clients/cli/commands/doctor-integration.test.mjs +75 -1
  136. package/clients/cli/commands/doctor.mjs +53 -16
  137. package/clients/cli/commands/integration-add.doc.mjs +10 -0
  138. package/clients/cli/commands/integration.mjs +1 -0
  139. package/clients/cli/commands/search.mjs +11 -2
  140. package/clients/cli/commands/setup-nudge.test.mjs +6 -0
  141. package/clients/cli/commands/template.doc.mjs +23 -6
  142. package/clients/cli/commands/template.mjs +4 -91
  143. package/clients/cli/commands/text-json-parity.test.mjs +2 -1
  144. package/clients/cli/index.mjs +8 -0
  145. package/clients/cli/lib/manifest.mjs +9 -2
  146. package/foundation/agent-docs/agent-docs.d.mts +3 -2
  147. package/foundation/agent-docs/agent-docs.mjs +13 -9
  148. package/foundation/agent-docs/agent-docs.test.mjs +19 -1
  149. package/foundation/config/project.d.mts +12 -11
  150. package/foundation/config/project.mjs +73 -59
  151. package/foundation/config/project.test.mjs +141 -5
  152. package/foundation/discovery/authoring-self-docs.test.mjs +17 -7
  153. package/foundation/discovery/cli-self-docs.d.mts +40 -34
  154. package/foundation/discovery/cli-self-docs.mjs +91 -115
  155. package/foundation/discovery/cli-self-docs.test.mjs +104 -166
  156. package/foundation/discovery/component-discovery.d.mts +38 -0
  157. package/foundation/discovery/component-discovery.mjs +48 -0
  158. package/foundation/discovery/docs-discovery.d.mts +105 -8
  159. package/foundation/discovery/docs-discovery.mjs +177 -13
  160. package/foundation/discovery/docs-discovery.test.mjs +56 -17
  161. package/foundation/discovery/docs-output-budget.d.mts +2 -2
  162. package/foundation/discovery/docs-output-budget.mjs +1 -1
  163. package/foundation/discovery/docs-section-key.d.mts +9 -2
  164. package/foundation/discovery/docs-section-key.mjs +15 -1
  165. package/foundation/discovery/template-adapter.d.mts +92 -6
  166. package/foundation/discovery/template-adapter.mjs +453 -17
  167. package/foundation/discovery/template-adapter.test.mjs +42 -0
  168. package/foundation/discovery/template-conflict-release.d.mts +13 -0
  169. package/foundation/discovery/template-conflict-release.mjs +40 -0
  170. package/foundation/discovery/template-conflict-release.test.mjs +40 -0
  171. package/foundation/doc-compiler/bundle.mjs +61 -1
  172. package/foundation/doc-compiler/bundle.test.mjs +21 -10
  173. package/foundation/doc-compiler/compile.d.mts +113 -132
  174. package/foundation/doc-compiler/compile.mjs +52 -6
  175. package/foundation/doc-compiler/diagnostics.mjs +28 -0
  176. package/foundation/doc-compiler/doc-loads.test.mjs +2 -2
  177. package/foundation/doc-compiler/inputs.d.mts +2 -2
  178. package/foundation/doc-compiler/inputs.mjs +6 -1
  179. package/foundation/doc-compiler/ir.mjs +7 -0
  180. package/foundation/doc-compiler/lenses.d.mts +3 -2
  181. package/foundation/doc-compiler/lenses.mjs +2 -1
  182. package/foundation/doc-compiler/links.d.mts +135 -0
  183. package/foundation/doc-compiler/links.mjs +253 -0
  184. package/foundation/doc-compiler/links.test.mjs +139 -0
  185. package/foundation/doc-compiler/lower-doc.test.mjs +5 -2
  186. package/foundation/doc-compiler/read.d.mts +3 -2
  187. package/foundation/doc-compiler/read.mjs +6 -1
  188. package/foundation/doc-compiler/tree.d.mts +288 -0
  189. package/foundation/doc-compiler/tree.mjs +876 -0
  190. package/foundation/doc-compiler/tree.test.mjs +598 -0
  191. package/foundation/integrations/autolink.test.mjs +1 -1
  192. package/foundation/integrations/cli-requirement.d.mts +45 -0
  193. package/foundation/integrations/cli-requirement.mjs +154 -0
  194. package/foundation/integrations/cli-requirement.test.mjs +109 -0
  195. package/foundation/integrations/contribution-inventory.d.mts +2 -1
  196. package/foundation/integrations/contribution-inventory.mjs +10 -4
  197. package/foundation/integrations/contribution-inventory.test.mjs +19 -0
  198. package/foundation/integrations/integration-warnings.d.mts +9 -2
  199. package/foundation/integrations/integration-warnings.mjs +51 -26
  200. package/foundation/integrations/integration-warnings.test.mjs +74 -1
  201. package/foundation/integrations/validate-contributions.mjs +25 -27
  202. package/foundation/response/response-types.doc.d.mts +5 -1
  203. package/foundation/response/response-types.doc.mjs +19 -10
  204. package/foundation/text/string-utils.d.mts +8 -0
  205. package/foundation/text/string-utils.mjs +18 -0
  206. package/foundation/xle/expand.mjs +1 -1
  207. package/foundation/xle/xle.test.mjs +13 -0
  208. package/package.json +9 -9
  209. package/assets/docs/cli.doc.mjs +0 -15
@@ -13,7 +13,7 @@
13
13
 
14
14
  import {linkReferenceTopic} from '../../../foundation/doc-compiler/compile.mjs';
15
15
  import {detailView} from '../../../foundation/doc-compiler/lenses.mjs';
16
- import {referenceTargets, resolveTopicDocs} from '../_adapter.mjs';
16
+ import {referenceTargets, resolveTopicDocs, topicLinks} from '../_adapter.mjs';
17
17
 
18
18
  /**
19
19
  * @param {string} topic
@@ -25,10 +25,18 @@ import {referenceTargets, resolveTopicDocs} from '../_adapter.mjs';
25
25
  * @returns {Promise<import('../docs.type.mjs').DocsDetailResponse>}
26
26
  */
27
27
  export async function detail(topic, options = {}) {
28
- const {catalog, node, lang} = await resolveTopicDocs(topic, options);
28
+ const {catalog, node, lang, entry} = await resolveTopicDocs(topic, options);
29
29
  const linked = await linkReferenceTopic(
30
30
  node,
31
31
  referenceTargets(catalog, lang),
32
32
  );
33
- return {type: 'docs.detail', data: detailView(linked)};
33
+ return {
34
+ type: 'docs.detail',
35
+ data: {
36
+ ...detailView(linked),
37
+ // A guide the docs tree places is read by its route, not its doc name.
38
+ ...(entry.tree ? {name: entry.name} : {}),
39
+ links: await topicLinks(catalog, entry),
40
+ },
41
+ };
34
42
  }
@@ -17,7 +17,10 @@
17
17
 
18
18
  import {AstryxError} from '../../../error.mjs';
19
19
  import {ERROR_CODES} from '../../../../foundation/response/error-codes.mjs';
20
- import {findDocSection} from '../../../../foundation/discovery/docs-section-key.mjs';
20
+ import {
21
+ findDocSection,
22
+ sectionKey,
23
+ } from '../../../../foundation/discovery/docs-section-key.mjs';
21
24
  import {linkReferenceSection} from '../../../../foundation/doc-compiler/compile.mjs';
22
25
  import {
23
26
  readerSections,
@@ -47,7 +50,7 @@ export async function section(topic, sectionName, options = {}) {
47
50
  );
48
51
  }
49
52
 
50
- const {catalog, node, lang} = await resolveTopicDocs(topic, options);
53
+ const {catalog, node, lang, entry} = await resolveTopicDocs(topic, options);
51
54
  const sections = readerSections(node);
52
55
  const {section: match} = findDocSection(sections, sectionName);
53
56
  if (!match) {
@@ -68,5 +71,19 @@ export async function section(topic, sectionName, options = {}) {
68
71
  match,
69
72
  referenceTargets(catalog, lang),
70
73
  );
71
- return {type: 'docs.detail.section', data: sectionView(node, linked)};
74
+ // The moves from one section (spec:AST-047): up to its topic's index, and
75
+ // across to the sections before and after it.
76
+ const at = sections.indexOf(match);
77
+ /** @type {import('../../docs.type.mjs').DocsLinks} */
78
+ const links = {up: `astryx docs ${entry.name} --index`};
79
+ if (at > 0) {
80
+ links.previous = `astryx docs ${entry.name} ${sectionKey(sections[at - 1])}`;
81
+ }
82
+ if (at !== -1 && at < sections.length - 1) {
83
+ links.next = `astryx docs ${entry.name} ${sectionKey(sections[at + 1])}`;
84
+ }
85
+ return {
86
+ type: 'docs.detail.section',
87
+ data: {...sectionView(node, linked), links},
88
+ };
72
89
  }
@@ -15,7 +15,8 @@
15
15
  * import('./docs.type.mjs').DocsListResponse |
16
16
  * import('./docs.type.mjs').DocsIndexResponse |
17
17
  * import('./docs.type.mjs').DocsDetailResponse |
18
- * import('./docs.type.mjs').DocsDetailSectionResponse
18
+ * import('./docs.type.mjs').DocsDetailSectionResponse |
19
+ * import('./docs.type.mjs').DocsNodeResponse
19
20
  * >}
20
21
  */
21
22
  export function docs(topic?: string, section?: string, options?: {
@@ -24,9 +25,10 @@ export function docs(topic?: string, section?: string, options?: {
24
25
  dense?: boolean | undefined;
25
26
  index?: boolean | undefined;
26
27
  cwd?: string | undefined;
27
- }): Promise<import("./docs.type.mjs").DocsListResponse | import("./docs.type.mjs").DocsIndexResponse | import("./docs.type.mjs").DocsDetailResponse | import("./docs.type.mjs").DocsDetailSectionResponse>;
28
+ }): Promise<import("./docs.type.mjs").DocsListResponse | import("./docs.type.mjs").DocsIndexResponse | import("./docs.type.mjs").DocsDetailResponse | import("./docs.type.mjs").DocsDetailSectionResponse | import("./docs.type.mjs").DocsNodeResponse>;
28
29
  import { list } from './list/list.mjs';
29
30
  import { index } from './index/index.mjs';
30
31
  import { detail } from './detail/detail.mjs';
31
32
  import { section as sectionLeaf } from './detail/section/section.mjs';
32
- export { list, index, detail, sectionLeaf as section };
33
+ import { node as nodeLeaf } from './node/node.mjs';
34
+ export { list, index, detail, sectionLeaf as section, nodeLeaf as node };
@@ -16,18 +16,26 @@ export const doc = {
16
16
  summary:
17
17
  'Read the reference docs: list every topic, one topic\'s sections, one section, or a whole topic.',
18
18
  description:
19
- 'No topic lists every reference-doc topic; a topic returns that full ' +
20
- 'ReferenceDoc; `index: true` returns the topic\'s section index instead ' +
21
- '(each section\'s key, title, and summary); a topic plus a section returns ' +
22
- 'that one section, found by its key, then its exact title, then a unique ' +
23
- 'part of its title (an ambiguous query is refused). Token-ref blocks are ' +
19
+ 'No topic lists every reference-doc topic; a topic returns its whole ' +
20
+ 'ReferenceDoc, and `index: true` returns its section index (each ' +
21
+ 'section\'s key, title, and summary); a topic plus a section returns ' +
22
+ 'that one section. Token-ref blocks are ' +
24
23
  'inlined in every read. The topic set is the CLI\'s own docs plus the ' +
25
24
  'ones the project\'s configured integrations contribute, including any ' +
26
25
  'topic an integration replaces or extends, so it depends on the cwd. ' +
26
+ 'A route opens a node of the docs tree instead: a namespace such as ' +
27
+ "`cli/api` returns its children one level down, a typed doc such as " +
28
+ "`cli/api/functions/search` returns its content, and a guide the tree " +
29
+ 'places (`cli/integrations`) reads like any topic. ' +
30
+ 'Every read but the list carries `links`, the commands that move from it: ' +
31
+ '`up` to the level it sits in, `previous` and `next` to its neighbors, and, ' +
32
+ 'for a typed doc, `related` to the docs it names (its command or function, ' +
33
+ 'and its related docs); `previous` and `next` ' +
34
+ 'to the section or node before and after it. ' +
27
35
  'Overlay options select localized or dense variants.',
28
36
  importPath: '@astryxdesign/cli/api',
29
37
  signature:
30
- 'docs(topic?: string, section?: string, options?: DocsOptions): Promise<DocsListResponse | DocsIndexResponse | DocsDetailResponse | DocsDetailSectionResponse>',
38
+ 'docs(topic?: string, section?: string, options?: DocsOptions): Promise<DocsListResponse | DocsIndexResponse | DocsDetailResponse | DocsDetailSectionResponse | DocsNodeResponse>',
31
39
  keywords: [
32
40
  'docs',
33
41
  'documentation',
@@ -43,7 +51,7 @@ export const doc = {
43
51
  name: 'topic',
44
52
  type: 'string',
45
53
  description:
46
- "Doc topic to load (e.g. 'principles'). Omit to list all topics.",
54
+ "Doc topic to load (e.g. 'principles'), or a docs-tree route (e.g. 'cli/api/functions/search'). Omit to list all topics.",
47
55
  },
48
56
  {
49
57
  name: 'section',
@@ -64,13 +72,14 @@ export const doc = {
64
72
  {
65
73
  name: 'options.dense',
66
74
  type: 'boolean',
67
- description: 'Return the token-efficient dense doc variant.',
75
+ description:
76
+ 'Return the token-efficient dense doc variant. It is written to be read whole, so it returns the whole doc.',
68
77
  },
69
78
  {
70
79
  name: 'options.index',
71
80
  type: 'boolean',
72
81
  description:
73
- "Return the topic's section index (each section's key, title, and summary) instead of the whole doc.",
82
+ "Return the topic's section index (each section's key, title, and summary), even for a topic with one section.",
74
83
  },
75
84
  {
76
85
  name: 'options.cwd',
@@ -83,41 +92,52 @@ export const doc = {
83
92
  {
84
93
  type: 'docs.list',
85
94
  description:
86
- 'All available reference-doc topics as DocsListEntry[] ({topic, description, package, replaces?}), in read order.',
95
+ "Every reference-doc topic in read order, as DocsListEntry[] ({topic, description, package, replaces?}), each readable with docs(topic). meta.namespaces lists the docs tree's top-level namespaces ({topic, description, package}), and meta.notLoaded each package whose docs did not load ({package, message}).",
87
96
  },
88
97
  {
89
98
  type: 'docs.detail',
90
99
  description:
91
- "One topic's full ReferenceDoc, with token-ref blocks inlined.",
100
+ "One topic's full ReferenceDoc, with token-ref blocks inlined, plus links.",
92
101
  },
93
102
  {
94
103
  type: 'docs.index',
95
104
  description:
96
- "One topic's section index (index: true): {name, title, description, sections: [{id, title, summary}]}.",
105
+ "One topic's section index (index: true): {name, title, description, sections: [{id, title, summary}], links}.",
97
106
  },
98
107
  {
99
108
  type: 'docs.detail.section',
100
109
  description:
101
110
  'One ReferenceSection of the topic, found by key or title, with token-ref blocks inlined.',
102
111
  },
112
+ {
113
+ type: 'docs.node',
114
+ description:
115
+ "A namespace or typed doc in the docs tree, read by its route: {id, route, kind, package, title, summary, breadcrumb, slots, content}. A namespace lists each slot's children one level down; a typed doc carries its content.",
116
+ },
103
117
  ],
104
118
  throws: [
105
119
  {
106
120
  code: 'ERR_UNKNOWN_TOPIC',
107
- when: 'the topic is not a string or matches no known doc topic',
121
+ when: 'the topic is not a string, or matches no topic and no docs-tree route',
108
122
  },
109
123
  {
110
124
  code: 'ERR_UNKNOWN_SECTION',
111
- when: 'a section is requested but is empty, matches no section, or matches more than one',
125
+ when: 'a section is requested but is empty, matches no section, matches more than one, or is asked of a docs-tree namespace or typed doc, which have no sections',
112
126
  },
113
127
  ],
114
128
  examples: [
115
129
  {label: 'List topics', code: 'const r = await docs();'},
116
- {label: 'Load a topic', code: "await docs('principles');"},
130
+ {label: 'A whole topic', code: "await docs('principles');"},
117
131
  {
118
132
  label: "A topic's sections",
119
133
  code: "await docs('principles', undefined, {index: true});",
120
134
  },
135
+ {label: 'A docs-tree namespace', code: "await docs('cli/api');"},
136
+ {label: 'One API function', code: "await docs('cli/api/functions/search');"},
137
+ {
138
+ label: 'A whole guide from the docs tree',
139
+ code: "await docs('cli/integrations');",
140
+ },
121
141
  {label: 'One section by key', code: "await docs('tokens', 'spacing');"},
122
142
  ],
123
143
  command: 'docs',
package/api/docs/docs.mjs CHANGED
@@ -3,27 +3,35 @@
3
3
  /**
4
4
  * @file Programmatic API for the docs command.
5
5
  *
6
- * Dispatcher + barrel. `docs()` routes by argument shape into one of four
6
+ * Dispatcher + barrel. `docs()` routes by argument shape into one of five
7
7
  * leaves, each projecting into a single { type, data } envelope:
8
8
  *
9
9
  * docs() -> list -> docs.list
10
10
  * docs(topic) -> detail -> docs.detail
11
11
  * docs(topic, undefined, {index: true}) -> index -> docs.index
12
12
  * docs(topic, section) -> section -> docs.detail.section
13
+ * docs(route) -> node -> docs.node
13
14
  *
14
- * A topic read returns the whole doc, as it always has. The index is how a
15
- * reader works progressively instead: list the topic's sections, then read one
16
- * by its key. The leaves live in list/, index/, detail/, and detail/section/;
17
- * the discovery, overlay loading, and topic resolution they share sit in
18
- * _adapter.mjs.
15
+ * A topic read returns the whole doc, as it always has; `index` returns its
16
+ * sections, so a reader can open one by its key (spec:AST-047). The CLI's text
17
+ * view lists the sections by default. A route names a node
18
+ * of the docs tree (spec:AST-046): a namespace lists its children, a guide the
19
+ * tree places reads like any topic, and a typed doc prints its content. The
20
+ * leaves
21
+ * live in list/, index/, detail/, detail/section/, and node/; the discovery,
22
+ * overlay loading, and resolution they share sit in _adapter.mjs.
19
23
  */
20
24
 
21
25
  import {list} from './list/list.mjs';
22
26
  import {index} from './index/index.mjs';
23
27
  import {detail} from './detail/detail.mjs';
24
28
  import {section as sectionLeaf} from './detail/section/section.mjs';
29
+ import {node as nodeLeaf, nodeView} from './node/node.mjs';
30
+ import {resolveDocsArgument} from './_adapter.mjs';
31
+ import {AstryxError} from '../error.mjs';
32
+ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
25
33
 
26
- export {list, index, detail, sectionLeaf as section};
34
+ export {list, index, detail, sectionLeaf as section, nodeLeaf as node};
27
35
 
28
36
  /**
29
37
  * @param {string} [topic]
@@ -39,11 +47,39 @@ export {list, index, detail, sectionLeaf as section};
39
47
  * import('./docs.type.mjs').DocsListResponse |
40
48
  * import('./docs.type.mjs').DocsIndexResponse |
41
49
  * import('./docs.type.mjs').DocsDetailResponse |
42
- * import('./docs.type.mjs').DocsDetailSectionResponse
50
+ * import('./docs.type.mjs').DocsDetailSectionResponse |
51
+ * import('./docs.type.mjs').DocsNodeResponse
43
52
  * >}
44
53
  */
45
54
  export async function docs(topic, section, options = {}) {
46
55
  if (!topic) return list(options);
56
+ const found = await resolveDocsArgument(topic, options);
57
+ if (found.kind === 'node') {
58
+ // A namespace or a typed doc has no sections: it is one read. `--index`
59
+ // asks for what the node read already is.
60
+ if (section) {
61
+ throw new AstryxError(
62
+ `"${found.node.route}" has no sections. ${
63
+ found.node.kind === 'namespace'
64
+ ? 'Open one of its children instead.'
65
+ : `Read it whole: astryx docs ${found.node.route}.`
66
+ }`,
67
+ found.node.kind === 'namespace'
68
+ ? found.node.slots.flatMap(slot =>
69
+ slot.children.map(route => ({
70
+ name: route,
71
+ reason: found.tree.get(route)?.summary ?? '',
72
+ })),
73
+ )
74
+ : [{name: found.node.route, reason: found.node.summary}],
75
+ ERROR_CODES.ERR_UNKNOWN_SECTION,
76
+ );
77
+ }
78
+ return {
79
+ type: 'docs.node',
80
+ data: await nodeView(found.catalog, found.tree, found.node),
81
+ };
82
+ }
47
83
  if (section) return sectionLeaf(topic, section, options);
48
84
  if (options.index) return index(topic, options);
49
85
  return detail(topic, options);
@@ -26,11 +26,9 @@ describe('docs() dispatcher routing', () => {
26
26
  expect((await docs('')).type).toBe('docs.list');
27
27
  }, SLOW);
28
28
 
29
- it('topic only -> docs.detail', async () => {
29
+ it('topic only -> docs.detail, the whole doc', async () => {
30
30
  const {data} = await docs();
31
- const topic = data[0].topic;
32
- const r = await docs(topic);
33
- expect(r.type).toBe('docs.detail');
31
+ expect((await docs(data[0].topic)).type).toBe('docs.detail');
34
32
  }, SLOW);
35
33
 
36
34
  it('topic + index -> docs.index', async () => {
@@ -69,6 +67,162 @@ describe('docs() dispatcher routing', () => {
69
67
  });
70
68
  }, SLOW);
71
69
 
70
+ it("lists the docs tree's namespaces in meta, so every data entry reads as a topic", async () => {
71
+ const res = await docs();
72
+ expect(res.meta.namespaces.map(entry => entry.topic)).toEqual(['cli', 'unorganized']);
73
+ for (const entry of res.data) {
74
+ expect((await docs(entry.topic)).type).toBe('docs.detail');
75
+ }
76
+ }, SLOW);
77
+
78
+ it('opens a route typed in another case', async () => {
79
+ const r = await docs('CLI/API');
80
+ expect(r.type).toBe('docs.node');
81
+ expect(r.data).toMatchObject({route: 'cli/api', links: {up: 'astryx docs cli'}});
82
+ }, SLOW);
83
+
84
+ it('a section of a typed doc -> ERR_UNKNOWN_SECTION, suggesting the doc itself', async () => {
85
+ const err = await docs('cli/api/functions/search', 'x').catch(e => e);
86
+ expect(err.code).toBe('ERR_UNKNOWN_SECTION');
87
+ expect(err.message).toContain('astryx docs cli/api/functions/search');
88
+ expect(err.suggestions.map(s => s.name)).toEqual(['cli/api/functions/search']);
89
+ }, SLOW);
90
+
91
+ it('a namespace route -> docs.node, one level of children', async () => {
92
+ const r = await docs('cli/api');
93
+ expect(r.type).toBe('docs.node');
94
+ expect(r.data).toMatchObject({
95
+ id: 'astryx:artifact:v1/%40astryxdesign%2Fcli/namespace/api',
96
+ route: 'cli/api',
97
+ kind: 'namespace',
98
+ package: '@astryxdesign/cli',
99
+ breadcrumb: [{route: 'cli', title: 'Astryx CLI'}],
100
+ content: [],
101
+ });
102
+ expect(r.data.slots.flatMap(slot => slot.children.map(c => c.route))).toEqual([
103
+ 'cli/api/functions',
104
+ 'cli/api/schemas',
105
+ 'cli/api/enums',
106
+ ]);
107
+ }, SLOW);
108
+
109
+ it('a typed doc route -> docs.node with its content', async () => {
110
+ const r = await docs('cli/api/functions/search');
111
+ expect(r.type).toBe('docs.node');
112
+ expect(r.data).toMatchObject({
113
+ id: 'astryx:artifact:v1/%40astryxdesign%2Fcli/function/search',
114
+ kind: 'function',
115
+ title: 'search()',
116
+ slots: [],
117
+ });
118
+ expect(r.data.breadcrumb.map(link => link.route)).toEqual([
119
+ 'cli',
120
+ 'cli/api',
121
+ 'cli/api/functions',
122
+ ]);
123
+ expect(JSON.stringify(r.data.content)).toContain(
124
+ '`astryx search` runs it. Read it with `astryx docs cli/commands/search`.',
125
+ );
126
+ }, SLOW);
127
+
128
+ it('a guide the tree places reads like a topic: the whole doc, its index, a section', async () => {
129
+ expect((await docs('cli/integrations')).type).toBe('docs.detail');
130
+ const index = await docs('cli/integrations', undefined, {index: true});
131
+ expect(index).toMatchObject({type: 'docs.index', data: {name: 'cli/integrations'}});
132
+ expect(index.data.sections.length).toBeGreaterThan(1);
133
+ expect((await docs('cli/integrations', 'components')).type).toBe(
134
+ 'docs.detail.section',
135
+ );
136
+ }, SLOW);
137
+
138
+ it('every read carries its moves (spec:AST-047)', async () => {
139
+ const root = (await docs('cli')).data;
140
+ expect(root.links).toEqual({up: 'astryx docs'});
141
+ const leaf = (await docs('cli/api/functions/search')).data;
142
+ expect(leaf.links.up).toBe('astryx docs cli/api/functions');
143
+ expect(leaf.links.previous).toMatch(/^astryx docs cli\/api\/functions\/[a-z-]+$/);
144
+ expect(leaf.links.next).toMatch(/^astryx docs cli\/api\/functions\/[a-z-]+$/);
145
+ const index = await docs('cli/integrations', undefined, {index: true});
146
+ // A guide moves across its namespace's slot, as any tree node does.
147
+ expect(index.data.links).toEqual({
148
+ up: 'astryx docs cli',
149
+ next: 'astryx docs cli/writing-docs',
150
+ });
151
+ const first = (await docs('cli/integrations', index.data.sections[0].id)).data;
152
+ expect(first.links).toEqual({
153
+ up: 'astryx docs cli/integrations --index',
154
+ next: `astryx docs cli/integrations ${index.data.sections[1].id}`,
155
+ });
156
+ const last = index.data.sections.at(-1).id;
157
+ const end = (await docs('cli/integrations', last)).data;
158
+ expect(end.links.next).toBeUndefined();
159
+ expect(end.links.previous).toBe(
160
+ `astryx docs cli/integrations ${index.data.sections.at(-2).id}`,
161
+ );
162
+ // A flat topic's home is the Unorganized level, and it moves across it.
163
+ const flat = (await docs('principles')).data.links;
164
+ expect(flat.up).toBe('astryx docs unorganized');
165
+ expect(flat.previous).toMatch(/^astryx docs [a-z-]+$/);
166
+ expect(flat.next).toMatch(/^astryx docs [a-z-]+$/);
167
+ const home = (await docs('unorganized')).data;
168
+ expect(home).toMatchObject({id: null, kind: 'namespace', links: {up: 'astryx docs'}});
169
+ expect(home.slots[0].children.map(child => child.route)).toEqual(
170
+ (await docs()).data.map(entry => entry.topic),
171
+ );
172
+ }, SLOW);
173
+
174
+ it('names a node by its doc identity; a generated level has id null', async () => {
175
+ const level = (await docs('cli/api/functions')).data;
176
+ expect(level).toHaveProperty('id', null);
177
+ expect(level.route).toBe('cli/api/functions');
178
+ }, SLOW);
179
+
180
+ it("offers a typed doc's related docs as moves", async () => {
181
+ const fn = (await docs('cli/api/functions/search')).data;
182
+ expect(fn.links.related).toContain('astryx docs cli/commands/search');
183
+ const cmd = (await docs('cli/commands/search')).data;
184
+ expect(cmd.links.related).toContain('astryx docs cli/api/functions/search');
185
+ }, SLOW);
186
+
187
+ it('a topic read returns the whole doc; index returns its sections', async () => {
188
+ expect((await docs('principles')).type).toBe('docs.detail');
189
+ const index = await docs('principles', undefined, {index: true});
190
+ expect(index.type).toBe('docs.index');
191
+ expect(index.data.sections.length).toBeGreaterThan(1);
192
+ expect((await docs('principles', undefined, {dense: true})).type).toBe(
193
+ 'docs.detail',
194
+ );
195
+ }, SLOW);
196
+
197
+ it("the guide's old flat name is gone, and its error names the new route", async () => {
198
+ await expect(docs('cli-integrations')).rejects.toMatchObject({
199
+ code: 'ERR_UNKNOWN_TOPIC',
200
+ suggestions: [expect.objectContaining({name: 'cli/integrations'})],
201
+ });
202
+ expect((await docs()).data.map(entry => entry.topic)).not.toContain(
203
+ 'cli-integrations',
204
+ );
205
+ }, SLOW);
206
+
207
+ it('a section of a namespace -> ERR_UNKNOWN_SECTION, naming its children', async () => {
208
+ const err = await docs('cli', 'commands').catch(e => e);
209
+ expect(err).toBeInstanceOf(AstryxError);
210
+ expect(err.code).toBe('ERR_UNKNOWN_SECTION');
211
+ expect(err.suggestions.map(s => s.name)).toEqual([
212
+ 'cli/integrations',
213
+ 'cli/writing-docs',
214
+ 'cli/commands',
215
+ 'cli/api',
216
+ ]);
217
+ }, SLOW);
218
+
219
+ it('an unknown route suggests the children of the deepest namespace it reaches', async () => {
220
+ const err = await docs('cli/api/functions/serch').catch(e => e);
221
+ expect(err.code).toBe('ERR_UNKNOWN_TOPIC');
222
+ expect(err.suggestions.map(s => s.name)).toContain('cli/api/functions/search');
223
+ expect(err.suggestions.every(s => s.name.startsWith('cli/api/functions/'))).toBe(true);
224
+ }, SLOW);
225
+
72
226
  it('non-string topic -> ERR_UNKNOWN_TOPIC (not a raw TypeError)', async () => {
73
227
  for (const bad of [123, {}, ['tokens'], true]) {
74
228
  const err = await docs(/** @type {any} */ (bad)).catch(e => e);
@@ -6,7 +6,22 @@
6
6
  */
7
7
  export type DocsListResponse = {
8
8
  type: "docs.list";
9
+ /**
10
+ * every topic, each readable as a topic
11
+ */
9
12
  data: DocsListEntry[];
13
+ /**
14
+ * `namespaces`: the docs tree's top-level namespaces, each opened by its
15
+ * `topic` as a docs.node; `notLoaded`: each package whose doc files did not
16
+ * load, and why (its docs are withdrawn)
17
+ */
18
+ meta?: {
19
+ namespaces?: DocsListNamespace[];
20
+ notLoaded?: Array<{
21
+ package: string;
22
+ message: string;
23
+ }>;
24
+ } | undefined;
10
25
  };
11
26
  export type DocsListEntry = {
12
27
  topic: string;
@@ -22,6 +37,21 @@ export type DocsListEntry = {
22
37
  */
23
38
  replaces?: string | undefined;
24
39
  };
40
+ /**
41
+ * A top-level namespace of the docs tree, as `astryx docs --json` lists it in
42
+ * `meta.namespaces`.
43
+ */
44
+ export type DocsListNamespace = {
45
+ /**
46
+ * its route, the argument that opens it
47
+ */
48
+ topic: string;
49
+ description: string;
50
+ /**
51
+ * the package that owns it
52
+ */
53
+ package: string;
54
+ };
25
55
  /**
26
56
  * astryx --json docs <topic> --index
27
57
  */
@@ -34,7 +64,49 @@ export type DocsIndexResponse = {
34
64
  */
35
65
  export type DocsDetailResponse = {
36
66
  type: "docs.detail";
37
- data: import("@astryxdesign/cli/authoring").ReferenceDoc;
67
+ /**
68
+ * the whole doc, and the moves from it
69
+ */
70
+ data: import("@astryxdesign/cli/authoring").ReferenceDoc & {
71
+ links: DocsLinks;
72
+ };
73
+ };
74
+ /**
75
+ * The doc a link opens (spec:AST-047 FR9). A docs read resolves every link:
76
+ * an inline `{@link <target>}` reads as `link.command`, a `reference` block
77
+ * carries `link` (null when the target names no doc), and each `workflow` step
78
+ * carries `links`, one per reference.
79
+ */
80
+ export type DocLink = import("../../foundation/doc-compiler/links.mjs").DocLink;
81
+ /**
82
+ * One move: a whole `astryx docs` command a reader can run as is.
83
+ */
84
+ export type DocsCommand = "astryx docs" | `astryx docs ${string}`;
85
+ /**
86
+ * The moves a docs read offers (spec:AST-047). Every read but the topic list
87
+ * carries them.
88
+ */
89
+ export type DocsLinks = {
90
+ /**
91
+ * opens the level the read sits in: a section's
92
+ * topic index, a node's parent namespace, or the topic list
93
+ */
94
+ up: DocsCommand;
95
+ /**
96
+ * opens the item before it at its level: the
97
+ * previous section of its topic, or the previous node in its parent's slot
98
+ */
99
+ previous?: DocsCommand | undefined;
100
+ /**
101
+ * opens the item after it at its level
102
+ */
103
+ next?: DocsCommand | undefined;
104
+ /**
105
+ * opens each doc a typed doc names: a
106
+ * function's command, a command's function, and the docs it lists as
107
+ * related
108
+ */
109
+ related?: DocsCommand[] | undefined;
38
110
  };
39
111
  /**
40
112
  * The section index of one topic: what the topic is, and the key each section
@@ -48,6 +120,10 @@ export type DocsIndex = {
48
120
  title: string;
49
121
  description: string;
50
122
  sections: DocsIndexSection[];
123
+ /**
124
+ * the moves from the index
125
+ */
126
+ links: DocsLinks;
51
127
  };
52
128
  export type DocsIndexSection = {
53
129
  /**
@@ -66,7 +142,94 @@ export type DocsIndexSection = {
66
142
  */
67
143
  export type DocsDetailSectionResponse = {
68
144
  type: "docs.detail.section";
69
- data: import("@astryxdesign/cli/authoring").ReferenceSection;
145
+ /**
146
+ * the section, and the moves from it: up to its topic's index, and across to
147
+ * the sections before and after it
148
+ */
149
+ data: import("@astryxdesign/cli/authoring").ReferenceSection & {
150
+ links: DocsLinks;
151
+ };
152
+ };
153
+ /**
154
+ * astryx --json docs <route>, for a namespace or a typed doc in the docs tree
155
+ */
156
+ export type DocsNodeResponse = {
157
+ type: "docs.node";
158
+ data: DocsNode;
159
+ };
160
+ /**
161
+ * One node of the docs tree.
162
+ */
163
+ export type DocsNode = {
164
+ /**
165
+ * the doc's DocId, built from its provider's
166
+ * ProviderId, kind, and name (see the provider-identity authoring doc);
167
+ * unchanged when the node moves. Always present; null on a generated level,
168
+ * such as `cli/api/functions`, which has no authored doc
169
+ */
170
+ id: string | null;
171
+ /**
172
+ * pass it to `astryx docs`
173
+ */
174
+ route: string;
175
+ /**
176
+ * `namespace`, or the typed doc's kind: `command`,
177
+ * `function`, `schema`, or `enum`
178
+ */
179
+ kind: string;
180
+ /**
181
+ * the package that owns the node
182
+ */
183
+ package: string;
184
+ title: string;
185
+ summary: string;
186
+ /**
187
+ * the namespaces above it, top first
188
+ */
189
+ breadcrumb: DocsNodeLink[];
190
+ /**
191
+ * a namespace's slots that hold children, in
192
+ * order; empty for a typed doc
193
+ */
194
+ slots: DocsNodeSlot[];
195
+ /**
196
+ * a typed doc's content; empty for a namespace
197
+ */
198
+ content: import("@astryxdesign/cli/authoring").ReferenceContentBlock[];
199
+ /**
200
+ * the moves from the node: up to its parent (the
201
+ * topic list, for a top-level namespace), and across to its neighbors in its
202
+ * parent's slot
203
+ */
204
+ links: DocsLinks;
205
+ };
206
+ export type DocsNodeLink = {
207
+ route: string;
208
+ title: string;
209
+ };
210
+ export type DocsNodeSlot = {
211
+ /**
212
+ * the slot's key in its namespace
213
+ */
214
+ name: string;
215
+ title: string;
216
+ /**
217
+ * in reading order
218
+ */
219
+ children: DocsNodeChild[];
220
+ };
221
+ export type DocsNodeChild = {
222
+ /**
223
+ * pass it to `astryx docs` to go one level down
224
+ */
225
+ route: string;
226
+ /**
227
+ * the last segment of its route
228
+ */
229
+ name: string;
230
+ kind: string;
231
+ title: string;
232
+ summary: string;
70
233
  };
71
234
  /**
72
235
  * Options for `docs()`.