@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
@@ -15,10 +15,14 @@ export const doc = {
15
15
  namespace: 'cli/commands',
16
16
  summary: 'Print reference docs',
17
17
  description:
18
- 'Reads the reference docs: with no topic it lists every topic; a topic prints that ' +
19
- 'full doc; `--index` lists its sections instead, each with the key to read it by; a ' +
20
- 'topic plus a section prints that section (by key, exact title, or a unique part of ' +
21
- 'a title).',
18
+ 'Reads the reference docs one level at a time: with no topic it lists every topic; a ' +
19
+ 'topic lists its sections, each with the key to read it by (a topic with one section ' +
20
+ 'prints whole); a topic plus a section prints that section; `--full` prints the whole ' +
21
+ 'topic, as does `--dense`. With `--json`, a topic returns its whole doc, as docs() ' +
22
+ 'does, and `--index` its section index. A route ' +
23
+ 'opens a node of the docs tree: `cli` lists its guides and reference, ' +
24
+ '`cli/api/functions` lists every API function, and `cli/api/functions/search` prints ' +
25
+ 'one.',
22
26
  fn: 'docs',
23
27
  args: [
24
28
  {name: 'topic', param: 'topic', required: false},
@@ -28,20 +32,28 @@ export const doc = {
28
32
  {
29
33
  flag: '--index',
30
34
  param: 'options.index',
31
- description: "List the topic's sections and their keys instead of printing the whole topic",
35
+ description: "List the topic's sections and their keys, even for a topic with one section",
36
+ },
37
+ {
38
+ flag: '--full',
39
+ description:
40
+ 'Print the whole topic instead of its sections (text; `--json` returns the whole topic unless --index). Cannot be set with --index',
32
41
  },
33
42
  ],
34
43
  examples: [
35
44
  {label: 'List topics', cli: 'astryx docs'},
36
- {label: 'One topic as JSON', cli: 'astryx docs spacing --json'},
37
- {label: "A topic's sections", cli: 'astryx docs theme --index'},
45
+ {label: "A topic's sections", cli: 'astryx docs theme'},
46
+ {label: 'A whole topic as JSON', cli: 'astryx docs spacing --json'},
38
47
  {label: 'One section', cli: 'astryx docs theme quick-start'},
48
+ {label: 'The CLI docs tree', cli: 'astryx docs cli'},
49
+ {label: 'One API function', cli: 'astryx docs cli/api/functions/search'},
50
+ {label: 'A whole guide', cli: 'astryx docs cli/integrations --full'},
39
51
  ],
40
52
  exitCodes: [
41
53
  {code: 0, when: 'success'},
42
54
  {
43
55
  code: 1,
44
- when: 'unknown topic, or a section that matches no section or more than one',
56
+ when: 'unknown topic or route, or a section that matches no section or more than one',
45
57
  },
46
58
  ],
47
59
  related: ['search', 'component', 'hook', 'template'],
@@ -3,18 +3,26 @@
3
3
  /**
4
4
  * @file docs command — Print Astryx reference docs
5
5
  *
6
- * A topic prints its whole doc; `--index` lists its sections instead, so a
7
- * reader can open one section by its key.
6
+ * In text, every read is one level: a topic lists its sections, so a reader can
7
+ * open one section by its key, and `--full` prints the whole topic. `--json`
8
+ * keeps the docs() contract: a topic returns its whole doc, and `--index` its
9
+ * sections.
8
10
  * Supports --detail (full|compact|brief) and --lang (en|zh|dense).
9
11
  *
10
12
  * Usage:
11
13
  * astryx docs List available topics
12
- * astryx docs <topic> Print the whole topic
13
- * astryx docs <topic> --index List the topic's sections
14
+ * astryx docs <topic> List the topic's sections (a topic
15
+ * with one section prints whole)
14
16
  * astryx docs <topic> <section> Print one section
17
+ * astryx docs <topic> --full Print the whole topic
18
+ * astryx docs <route> Open a node of the docs tree, such as
19
+ * cli, cli/api, or cli/api/functions/search
15
20
  */
16
21
 
17
- import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
22
+ import {
23
+ formatCliCommand,
24
+ getCliInvocation,
25
+ } from '../../../foundation/env/package-manager.mjs';
18
26
  import {jsonOut} from '../../../foundation/response/json.mjs';
19
27
  import {
20
28
  emit,
@@ -25,6 +33,7 @@ import {
25
33
  wrapText,
26
34
  } from '../formatters/index.mjs';
27
35
  import {cliError} from '../lib/cli-error.mjs';
36
+ import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
28
37
  import {defineCommand} from '../lib/define-command.mjs';
29
38
  import {resultSet} from '../../../foundation/debug/index.mjs';
30
39
  import {docs as docsApi} from '../../../api/docs/docs.mjs';
@@ -106,7 +115,7 @@ function formatBlock(block, detail) {
106
115
  }
107
116
 
108
117
  /**
109
- * @param {import('@astryxdesign/cli/authoring').ReferenceSection} section
118
+ * @param {import('../../../api/docs/docs.type.mjs').DocsReadSection} section
110
119
  * @param {'full' | 'compact' | 'brief'} detail
111
120
  * @returns {string}
112
121
  */
@@ -126,7 +135,7 @@ function formatSection(section, detail) {
126
135
  }
127
136
 
128
137
  /**
129
- * @param {import('@astryxdesign/cli/authoring').ReferenceDoc} docs
138
+ * @param {import('../../../api/docs/docs.type.mjs').DocsReadDoc} docs
130
139
  * @param {'full' | 'compact' | 'brief'} detail
131
140
  * @returns {string}
132
141
  */
@@ -146,6 +155,24 @@ function formatReferenceFull(docs, detail) {
146
155
  return `${header}\n\n${sections.join(sep)}`;
147
156
  }
148
157
 
158
+ /**
159
+ * The moves a read offers (spec:AST-047), one runnable command per line: up to
160
+ * the level it sits in, the item before and after it, and the docs it names.
161
+ * @param {import('../../../api/docs/docs.type.mjs').DocsLinks | undefined} links
162
+ * @returns {string[]}
163
+ */
164
+ function linkLines(links) {
165
+ if (!links) return [];
166
+ return [
167
+ `Up: ${formatCliCommand(links.up)}`,
168
+ ...(links.previous ? [`Previous: ${formatCliCommand(links.previous)}`] : []),
169
+ ...(links.next ? [`Next: ${formatCliCommand(links.next)}`] : []),
170
+ ...(links.related ?? []).map(
171
+ (command, i) => `${i === 0 ? 'Related: ' : ' '}${formatCliCommand(command)}`,
172
+ ),
173
+ ];
174
+ }
175
+
149
176
  /**
150
177
  * A topic's section index: what the topic is, one line per section with the
151
178
  * key to read it by, and how to read further.
@@ -158,20 +185,80 @@ function emitIndex(index, run) {
158
185
  index.title,
159
186
  index.description ? wrapText(index.description) : undefined,
160
187
  ),
188
+ // Summaries wrap rather than being cut: the summary is how a reader picks
189
+ // the one section to open.
161
190
  records(index.sections, {
162
191
  fields: ['id', 'title', 'summary'],
163
192
  layout: 'inline',
164
- overflow: 'truncate',
165
193
  }),
166
194
  text(
167
195
  [
168
196
  `Read one section: ${run} docs ${index.name} <section>`,
169
- `Read everything: ${run} docs ${index.name}`,
197
+ `Read everything: ${run} docs ${index.name} --full`,
198
+ ...linkLines(index.links),
170
199
  ].join('\n'),
171
200
  ),
172
201
  );
173
202
  }
174
203
 
204
+ /**
205
+ * One child row of a namespace: its route name, then the doc's own title when
206
+ * it is not the route name (`assertResponse()`, `search()`), then its summary.
207
+ * @param {import('../../../api/docs/docs.type.mjs').DocsNodeChild} child
208
+ * @returns {{name: string, summary: string}}
209
+ */
210
+ function childRow(child) {
211
+ return {
212
+ name: child.name,
213
+ summary:
214
+ child.title === child.name ? child.summary : `${child.title}: ${child.summary}`,
215
+ };
216
+ }
217
+
218
+ /**
219
+ * One node of the docs tree. A namespace lists each slot's children, one level
220
+ * down, with the command to open one; a typed doc prints its content. Both end
221
+ * with the way back up.
222
+ * @param {import('../../../api/docs/docs.type.mjs').DocsNode} node
223
+ * @param {'full' | 'compact' | 'brief'} detail
224
+ * @param {string} run
225
+ */
226
+ function emitNode(node, detail, run) {
227
+ if (node.kind === 'namespace') {
228
+ emit(
229
+ section(node.title, wrapText(node.summary)),
230
+ ...node.slots.flatMap(slot => [
231
+ // A namespace with one slot titled like itself needs no second heading.
232
+ ...(node.slots.length === 1 && slot.title === node.title
233
+ ? []
234
+ : [section(slot.title)]),
235
+ records(slot.children.map(childRow), {
236
+ fields: ['name', 'summary'],
237
+ layout: 'inline',
238
+ overflow: 'truncate',
239
+ }),
240
+ ]),
241
+ text(
242
+ [
243
+ // A child's route is its parent's route and its name, except a flat
244
+ // topic in the Unorganized level, which keeps its own name.
245
+ node.slots.every(slot =>
246
+ slot.children.every(child => child.route.startsWith(`${node.route}/`)),
247
+ )
248
+ ? `Open one: ${run} docs ${node.route}/<name>`
249
+ : `Open one: ${run} docs <name>`,
250
+ ...linkLines(node.links),
251
+ ].join('\n'),
252
+ ),
253
+ );
254
+ return;
255
+ }
256
+ emit(
257
+ code(formatSection({title: node.title, content: node.content}, detail)),
258
+ text(linkLines(node.links).join('\n')),
259
+ );
260
+ }
261
+
175
262
  /**
176
263
  * What the run answered with. A named topic (or one of its sections) resolves
177
264
  * or throws, so it is always a direct match of one doc; the bare form lists
@@ -180,7 +267,8 @@ function emitIndex(index, run) {
180
267
  * @param {import('../../../api/docs/docs.type.mjs').DocsListResponse
181
268
  * | import('../../../api/docs/docs.type.mjs').DocsIndexResponse
182
269
  * | import('../../../api/docs/docs.type.mjs').DocsDetailResponse
183
- * | import('../../../api/docs/docs.type.mjs').DocsDetailSectionResponse} result
270
+ * | import('../../../api/docs/docs.type.mjs').DocsDetailSectionResponse
271
+ * | import('../../../api/docs/docs.type.mjs').DocsNodeResponse} result
184
272
  * @returns {import('../../../foundation/debug/command-result.mjs').CommandResult}
185
273
  */
186
274
  function summarize(result) {
@@ -200,7 +288,7 @@ export function registerDocs(program) {
200
288
  action: async (
201
289
  /** @type {string | undefined} */ topic,
202
290
  /** @type {string | undefined} */ sectionName,
203
- /** @type {{index?: boolean}} */ options = {},
291
+ /** @type {{index?: boolean, full?: boolean}} */ options = {},
204
292
  ) => {
205
293
  const run = getCliInvocation();
206
294
  const lang = program.opts().lang || null;
@@ -209,14 +297,37 @@ export function registerDocs(program) {
209
297
  const detail = program.opts().detail || 'full';
210
298
  const json = program.opts().json || false;
211
299
 
300
+ if (options.index && options.full) {
301
+ return cliError(
302
+ 'Ask for the section list or the whole topic, not both: --index and --full cannot both be set.',
303
+ {code: ERROR_CODES.ERR_INVALID_ARGUMENT},
304
+ );
305
+ }
306
+ // Text reads one level: a topic lists its sections (one with a single
307
+ // section prints whole). JSON keeps docs(): the whole topic unless
308
+ // --index. The dense variant is written to be read whole.
309
+ const listSections =
310
+ Boolean(options.index) ||
311
+ (!json &&
312
+ !options.full &&
313
+ !dense &&
314
+ lang !== 'dense' &&
315
+ sectionName == null);
212
316
  let result;
213
317
  try {
214
318
  result = await docsApi(topic, sectionName, {
215
319
  lang,
216
320
  zh,
217
321
  dense,
218
- index: Boolean(options.index),
322
+ index: listSections,
219
323
  });
324
+ if (
325
+ !options.index &&
326
+ result.type === 'docs.index' &&
327
+ result.data.sections.length <= 1
328
+ ) {
329
+ result = await docsApi(topic, sectionName, {lang, zh, dense});
330
+ }
220
331
  } catch (e) {
221
332
  // docs API throws structured errors with {name, reason} suggestions —
222
333
  // pass them through untouched so the CLI envelope matches the API.
@@ -236,17 +347,50 @@ export function registerDocs(program) {
236
347
 
237
348
  switch (result.type) {
238
349
  case 'docs.list': {
239
- // Keep the published 0.6 text projection: stacked topic and
240
- // description fields, followed by the two original usage lines.
350
+ // The text view mirrors the JSON list, with the docs tree's
351
+ // namespaces (`meta.namespaces`) first under their own heading: that
352
+ // is where the CLI's own docs start, and a namespace reads
353
+ // differently from a topic.
354
+ const namespaces = result.meta?.namespaces ?? [];
355
+ const topics = result.data;
241
356
  emit(
242
- section('Available docs'),
243
- records(result.data, {fields: ['topic', 'description']}),
357
+ ...(namespaces.length > 0
358
+ ? [
359
+ section('Docs tree'),
360
+ records(namespaces, {
361
+ fields: ['topic', 'description', 'package'],
362
+ layout: 'inline',
363
+ }),
364
+ ]
365
+ : []),
366
+ section('Topics'),
367
+ records(topics, {
368
+ fields: ['topic', 'description', 'package'],
369
+ layout: 'inline',
370
+ }),
244
371
  text(
245
372
  [
246
- `Usage: ${run} docs <topic>`,
247
- ` ${run} docs <topic> <section>`,
373
+ `Usage: ${run} docs <topic> list a topic's sections`,
374
+ ` ${run} docs <topic> <section> read one section`,
375
+ ` ${run} docs <topic> --full read the whole topic`,
376
+ ` ${run} docs cli/api go down the docs tree one level at a time`,
377
+ `With --json, a topic returns its whole doc; add --index for its section list.`,
248
378
  ].join('\n'),
249
379
  ),
380
+ // A package whose doc files did not load has no topics here; say
381
+ // so, and where to look, instead of leaving them silently missing.
382
+ ...(result.meta?.notLoaded?.length
383
+ ? [
384
+ section('Not loaded'),
385
+ records(result.meta.notLoaded, {
386
+ fields: ['package', 'message'],
387
+ layout: 'inline',
388
+ }),
389
+ text(
390
+ `Run \`${run} doctor integration docs\` in that package to see every problem.`,
391
+ ),
392
+ ]
393
+ : []),
250
394
  );
251
395
  break;
252
396
  }
@@ -257,12 +401,25 @@ export function registerDocs(program) {
257
401
  }
258
402
 
259
403
  case 'docs.detail': {
260
- emit(code(formatReferenceFull(result.data, detail)));
404
+ emit(
405
+ code(formatReferenceFull(result.data, detail)),
406
+ text(linkLines(result.data.links).join('\n')),
407
+ );
261
408
  break;
262
409
  }
263
410
 
264
411
  case 'docs.detail.section': {
265
- emit(code(formatSection(result.data, detail)));
412
+ // One section ends with its moves: up to its topic's index, and to
413
+ // the sections before and after it.
414
+ emit(
415
+ code(formatSection(result.data, detail)),
416
+ text(linkLines(result.data.links).join('\n')),
417
+ );
418
+ break;
419
+ }
420
+
421
+ case 'docs.node': {
422
+ emitNode(result.data, detail, run);
266
423
  break;
267
424
  }
268
425
  }
@@ -75,7 +75,7 @@ describe('hyphenated doc filenames', () => {
75
75
 
76
76
  it('returns docs.detail via API for hyphenated topic', async () => {
77
77
  const {docs: docsApi} = await import('../../../api/docs/docs.mjs');
78
- const result = await docsApi('getting-started');
78
+ const result = await docsApi('getting-started', undefined, {full: true});
79
79
  expect(result.type).toBe('docs.detail');
80
80
  expect(result.data).toBeDefined();
81
81
  expect(result.data.description).toBeDefined();
@@ -108,10 +108,11 @@ describe('progressive reads', () => {
108
108
  /** @param {string} out */
109
109
  const widest = out => Math.max(...out.split('\n').map(line => line.length));
110
110
 
111
- it('keeps the 0.6.x stacked topic list', async () => {
111
+ it('lists every topic on one line each', async () => {
112
112
  const {status, stdout} = await runCli(['docs']);
113
113
  expect(status).toBe(0);
114
- expect(stdout).toMatch(/^topic: +principles$/m);
114
+ expect(stdout).toMatch(/^principles +\S/m);
115
+ expect(widest(stdout)).toBeLessThanOrEqual(120);
115
116
  expect(stdout).toContain('Usage: pnpm exec astryx docs <topic>');
116
117
  }, SLOW);
117
118
 
@@ -120,7 +121,7 @@ describe('progressive reads', () => {
120
121
  expect(status).toBe(0);
121
122
  expect(stdout).toMatch(/^quick-start +Quick Start/m);
122
123
  expect(stdout).toContain('docs theme <section>');
123
- expect(stdout).toMatch(/Read everything: +\S.* docs theme$/m);
124
+ expect(stdout).toMatch(/Read everything: +\S.* docs theme --full$/m);
124
125
  expect(widest(stdout)).toBeLessThanOrEqual(120);
125
126
  }, SLOW);
126
127
 
@@ -130,20 +131,23 @@ describe('progressive reads', () => {
130
131
  expect(stdout).toMatch(/^## Quick Start/m);
131
132
  }, SLOW);
132
133
 
133
- it('prints the whole topic by default, as before', async () => {
134
+ it("lists a topic's sections by default; --full prints the whole topic", async () => {
134
135
  const index = await runCli(['docs', 'theme', '--index']);
135
- const full = await runCli(['docs', 'theme']);
136
+ expect((await runCli(['docs', 'theme'])).stdout).toBe(index.stdout);
137
+ const full = await runCli(['docs', 'theme', '--full']);
136
138
  expect(full.status).toBe(0);
137
139
  expect(full.stdout).toMatch(/^## Quick Start/m);
138
140
  expect(full.stdout.length).toBeGreaterThan(index.stdout.length * 3);
139
- expect((await runCli(['--detail', 'full', 'docs', 'theme'])).stdout).toBe(
141
+ expect((await runCli(['--detail', 'full', 'docs', 'theme', '--full'])).stdout).toBe(
140
142
  full.stdout,
141
143
  );
142
144
  }, SLOW);
143
145
 
144
146
  it('returns the matching envelopes as JSON', async () => {
145
147
  const envelope = async args => JSON.parse((await runCli([...args, '--json'])).stdout);
148
+ // JSON keeps docs(): a bare read is the whole topic.
146
149
  expect((await envelope(['docs', 'theme'])).type).toBe('docs.detail');
150
+ expect((await envelope(['docs', 'theme', '--full'])).type).toBe('docs.detail');
147
151
  expect((await envelope(['docs', 'theme', '--index'])).type).toBe(
148
152
  'docs.index',
149
153
  );
@@ -153,6 +157,109 @@ describe('progressive reads', () => {
153
157
  }, SLOW);
154
158
  });
155
159
 
160
+ describe('the docs tree, one level at a time', () => {
161
+ const SLOW = 60_000;
162
+ /** @param {string} out */
163
+ const widest = out => Math.max(...out.split('\n').map(line => line.length));
164
+
165
+ it('lists the docs tree first, under its own heading, then the topics', async () => {
166
+ const {status, stdout} = await runCli(['docs']);
167
+ expect(status).toBe(0);
168
+ expect(stdout).toMatch(/^Docs tree$/m);
169
+ expect(stdout).toMatch(/^Topics$/m);
170
+ expect(stdout).toMatch(/^cli +Commands, programmatic APIs/m);
171
+ expect(stdout.indexOf('\ncli ')).toBeLessThan(stdout.indexOf('\nprinciples '));
172
+ expect(stdout).not.toMatch(/^cli-integrations /m);
173
+ }, SLOW);
174
+
175
+ it("shows a child's own name when its route name does not spell it", async () => {
176
+ const {status, stdout} = await runCli(['docs', 'cli/api/functions']);
177
+ expect(status).toBe(0);
178
+ expect(stdout).toMatch(/^assert-response +assertResponse\(\): \S/m);
179
+ expect(stdout).toMatch(/^search +search\(\): Unified ranked search/m);
180
+ }, SLOW);
181
+
182
+ it('prints a namespace: each slot, its children, and how to go down and up', async () => {
183
+ const {status, stdout} = await runCli(['docs', 'cli/api']);
184
+ expect(status).toBe(0);
185
+ expect(stdout).toMatch(/^API$/m);
186
+ expect(stdout).toMatch(/^Reference$/m);
187
+ expect(stdout).toMatch(/^functions +Functions: Every function/m);
188
+ expect(stdout).toMatch(/^schemas +/m);
189
+ expect(stdout).toMatch(/^enums +/m);
190
+ // One level only: no function is listed on the api page.
191
+ expect(stdout).not.toMatch(/^search +/m);
192
+ expect(stdout).toMatch(/Open one: .*docs cli\/api\/<name>$/m);
193
+ expect(stdout).toMatch(/Up: .*docs cli$/m);
194
+ expect(widest(stdout)).toBeLessThanOrEqual(120);
195
+ }, SLOW);
196
+
197
+ it('prints a typed doc and the way back up', async () => {
198
+ const {status, stdout} = await runCli(['docs', 'cli/api/functions/search']);
199
+ expect(status).toBe(0);
200
+ expect(stdout).toMatch(/^## search\(\)/m);
201
+ expect(stdout).toContain('Read it with `astryx docs cli/commands/search`.');
202
+ expect(stdout).toMatch(/Up: .*docs cli\/api\/functions$/m);
203
+ }, SLOW);
204
+
205
+ it('reads the dense variant whole, asked with --dense or with --lang dense', async () => {
206
+ for (const args of [['--dense', 'docs', 'theme'], ['--lang', 'dense', 'docs', 'theme']]) {
207
+ const {status, stdout} = await runCli(args);
208
+ expect(status).toBe(0);
209
+ expect(stdout).not.toContain('Read one section:');
210
+ }
211
+ }, SLOW);
212
+
213
+ it('refuses --index with --full', async () => {
214
+ const both = await runCli(['docs', 'theme', '--index', '--full', '--json']);
215
+ expect(both.status).toBe(1);
216
+ expect(JSON.parse(both.stdout).code).toBe('ERR_INVALID_ARGUMENT');
217
+ }, SLOW);
218
+
219
+ it('reads the integration guide by its route, and not by its old name', async () => {
220
+ const guide = await runCli(['docs', 'cli/integrations', '--index']);
221
+ expect(guide.status).toBe(0);
222
+ expect(guide.stdout).toMatch(/Read one section: .*docs cli\/integrations <section>/);
223
+ // A bare read is one level too: the sections, and how to read it all.
224
+ const bare = await runCli(['docs', 'cli/integrations']);
225
+ expect(bare.status).toBe(0);
226
+ expect(bare.stdout).toBe(guide.stdout);
227
+ expect(bare.stdout).toMatch(/Read everything: +.*docs cli\/integrations --full$/m);
228
+ const one = await runCli(['docs', 'cli/integrations', 'codemods']);
229
+ expect(one.status).toBe(0);
230
+ expect(one.stdout).toMatch(/^## Codemods$/m);
231
+ expect(one.stdout).toMatch(/^Up: .*docs cli\/integrations --index$/m);
232
+ expect(one.stdout).toMatch(/^Previous: .*docs cli\/integrations agent-docs$/m);
233
+ expect(one.stdout).toMatch(/^Next: .*docs cli\/integrations recording-runs$/m);
234
+ const full = await runCli(['docs', 'cli/integrations', '--full']);
235
+ expect(full.status).toBe(0);
236
+ expect(full.stdout).toMatch(/^## Overview$/m);
237
+ expect(full.stdout.length).toBeGreaterThan(bare.stdout.length * 4);
238
+ const old = await runCli(['docs', 'cli-integrations']);
239
+ expect(old.status).toBe(1);
240
+ expect(old.stderr).toContain('Unknown topic "cli-integrations"');
241
+ }, SLOW);
242
+
243
+ it('returns docs.node as JSON, and fails a section of a namespace', async () => {
244
+ const node = JSON.parse((await runCli(['docs', 'cli', '--json'])).stdout);
245
+ expect(node).toMatchObject({
246
+ type: 'docs.node',
247
+ data: {route: 'cli', kind: 'namespace', breadcrumb: []},
248
+ });
249
+ expect(node.data.slots.map(slot => slot.name)).toEqual(['guides', 'reference']);
250
+ const section = await runCli(['docs', 'cli', 'commands', '--json']);
251
+ expect(section.status).toBe(1);
252
+ const error = JSON.parse(section.stdout);
253
+ expect(error).toMatchObject({code: 'ERR_UNKNOWN_SECTION'});
254
+ expect(error.suggestions.map(s => s.name)).toEqual([
255
+ 'cli/integrations',
256
+ 'cli/writing-docs',
257
+ 'cli/commands',
258
+ 'cli/api',
259
+ ]);
260
+ }, SLOW);
261
+ });
262
+
156
263
  describe('text width in every language', () => {
157
264
  const SLOW = 60_000;
158
265
  /** Widest line outside code blocks, in terminal columns. */
@@ -8,7 +8,7 @@ export const doc = {
8
8
  name: 'doctor integration docs',
9
9
  displayName: 'astryx doctor integration docs',
10
10
  namespace: 'cli/commands',
11
- summary: 'Classify integration doc overlaps with Core topics',
11
+ summary: 'Check an integration\'s docs: the docs tree they add, every link, and overlaps with Core topics',
12
12
  description:
13
13
  'Reports intentional Core topic replacements and extensions as information. ' +
14
14
  'A same-name topic without `replaces` or `extends` is an accidental conflict ' +
@@ -32,7 +32,7 @@ export const doc = {
32
32
  ],
33
33
  exitCodes: [
34
34
  {code: 0, when: 'all Core overlaps are explicitly declared or no overlap exists'},
35
- {code: 1, when: 'an overlap is accidental or the integration docs are invalid'},
35
+ {code: 1, when: 'an overlap is accidental, a doc is invalid, a namespace or placement fails, or a reference block cannot include what it names. A link that names no doc is a warning, and does not change the exit code'},
36
36
  ],
37
37
  related: ['doctor integration validate', 'docs'],
38
38
  };
@@ -10,12 +10,13 @@ export const doc = {
10
10
  name: 'doctor integration templates',
11
11
  displayName: 'astryx doctor integration templates',
12
12
  namespace: 'cli/commands',
13
- summary: 'Warn when integration template ids conflict with Core',
13
+ summary: 'Validate integration template replacements and Core id overlaps',
14
14
  description:
15
- 'Compares one local or installed integration with the built-in Core page and ' +
16
- 'block template ids. A conflict is allowed and exits successfully, but the ' +
17
- 'report recommends renaming and gives the exact --package command required ' +
18
- 'to select the integration template when the overlap is intentional.',
15
+ 'Validates one local or installed integration against the built-in Core page ' +
16
+ 'and block template ids. Intentional replacements are informational and name ' +
17
+ 'the command for selecting the Core original. Missing targets, ambiguous ' +
18
+ 'replacements, and invalid declarations are errors; undeclared same-id overlaps ' +
19
+ 'remain warnings that require package selection.',
19
20
  fn: 'integrationTemplateConflicts',
20
21
  args: [
21
22
  {
@@ -37,8 +38,14 @@ export const doc = {
37
38
  },
38
39
  ],
39
40
  exitCodes: [
40
- {code: 0, when: 'the check completed; template conflicts are warnings'},
41
- {code: 1, when: 'the integration or one of its templates is invalid'},
41
+ {
42
+ code: 0,
43
+ when: 'replacement declarations are valid; undeclared id conflicts are warnings',
44
+ },
45
+ {
46
+ code: 1,
47
+ when: 'the integration, a template, or a replacement declaration is invalid',
48
+ },
42
49
  ],
43
50
  related: ['doctor integration validate', 'template'],
44
51
  };