@astryxdesign/cli 0.6.5-canary.69aa1cb → 0.6.5-canary.74a62ce

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.
@@ -10,6 +10,10 @@
10
10
  * @param {boolean} [options.dense]
11
11
  * @param {boolean} [options.index] return the topic's section index instead of
12
12
  * the whole doc
13
+ * @param {number | 'all'} [options.depth] how many levels below a docs-tree
14
+ * namespace to read; a doc with nothing below it reads the same at any depth
15
+ * @param {'brief' | 'compact' | 'full'} [options.detail] how much of each doc
16
+ * below the named one a depth read returns (brief by default)
13
17
  * @param {string} [options.cwd]
14
18
  * @returns {Promise<
15
19
  * import('./docs.type.mjs').DocsListResponse |
@@ -24,6 +28,8 @@ export function docs(topic?: string, section?: string, options?: {
24
28
  zh?: boolean | undefined;
25
29
  dense?: boolean | undefined;
26
30
  index?: boolean | undefined;
31
+ depth?: number | "all" | undefined;
32
+ detail?: "compact" | "full" | "brief" | undefined;
27
33
  cwd?: string | undefined;
28
34
  }): 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>;
29
35
  import { list } from './list/list.mjs';
@@ -0,0 +1,132 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, expect, it} from 'vitest';
4
+ import {docs} from './docs.mjs';
5
+
6
+ const SLOW = 60_000;
7
+
8
+ /**
9
+ * @param {any} node
10
+ * @param {string} route
11
+ * @returns {any}
12
+ */
13
+ function findRoute(node, route) {
14
+ if (node.route === route) return node;
15
+ for (const slot of node.slots ?? []) {
16
+ for (const child of slot.children) {
17
+ const found = findRoute(child, route);
18
+ if (found) return found;
19
+ }
20
+ }
21
+ return undefined;
22
+ }
23
+
24
+ /**
25
+ * @param {any} node
26
+ * @returns {any[]}
27
+ */
28
+ function children(node) {
29
+ return (node.slots ?? []).flatMap((/** @type {any} */ slot) => slot.children);
30
+ }
31
+
32
+ describe('docs() depth', () => {
33
+ it(
34
+ 'reads one level down, as it always has, without a depth',
35
+ async () => {
36
+ const plain = await docs('cli/api');
37
+ expect(plain.type).toBe('docs.node');
38
+ if (plain.type !== 'docs.node') return;
39
+ expect(plain.data).not.toHaveProperty('childCount');
40
+ for (const child of children(plain.data)) {
41
+ expect(Object.keys(child).sort()).toEqual([
42
+ 'kind',
43
+ 'name',
44
+ 'route',
45
+ 'summary',
46
+ 'title',
47
+ ]);
48
+ }
49
+ },
50
+ SLOW,
51
+ );
52
+
53
+ it(
54
+ 'goes as many levels down as asked, each doc below as its identity',
55
+ async () => {
56
+ const result = await docs('cli/api', undefined, {depth: 2});
57
+ if (result.type !== 'docs.node') throw new Error(result.type);
58
+ const functions = findRoute(result.data, 'cli/api/functions');
59
+ expect(functions).not.toHaveProperty('childCount');
60
+ expect(findRoute(result.data, 'cli/api/functions/search')).toEqual({
61
+ route: 'cli/api/functions/search',
62
+ name: 'search',
63
+ kind: 'function',
64
+ title: 'search()',
65
+ summary: expect.any(String),
66
+ });
67
+ },
68
+ SLOW,
69
+ );
70
+
71
+ it(
72
+ 'says how many docs sit below where the read stops',
73
+ async () => {
74
+ const one = await docs('cli/api', undefined, {depth: 1});
75
+ if (one.type !== 'docs.node') throw new Error(one.type);
76
+ const functions = findRoute(one.data, 'cli/api/functions');
77
+ expect(functions).not.toHaveProperty('slots');
78
+ expect(functions.childCount).toBeGreaterThan(1);
79
+
80
+ const zero = await docs('cli/api', undefined, {depth: 0});
81
+ if (zero.type !== 'docs.node') throw new Error(zero.type);
82
+ expect(zero.data.slots).toEqual([]);
83
+ expect(zero.data.childCount).toBe(children(one.data).length);
84
+ },
85
+ SLOW,
86
+ );
87
+
88
+ it(
89
+ "reads every level with 'all', and each doc's text at full detail",
90
+ async () => {
91
+ const result = await docs('cli/api', undefined, {
92
+ depth: 'all',
93
+ detail: 'full',
94
+ });
95
+ if (result.type !== 'docs.node') throw new Error(result.type);
96
+ expect(JSON.stringify(result.data)).not.toContain('"childCount"');
97
+ const search = findRoute(result.data, 'cli/api/functions/search');
98
+ expect(JSON.stringify(search.content)).toContain(
99
+ '`astryx search` runs it. Read it with `astryx docs cli/commands/search`.',
100
+ );
101
+ },
102
+ SLOW,
103
+ );
104
+
105
+ it(
106
+ 'reads a doc with nothing below it the same at any depth',
107
+ async () => {
108
+ expect(
109
+ await docs('cli/api/functions/search', undefined, {depth: 3}),
110
+ ).toEqual(await docs('cli/api/functions/search'));
111
+ },
112
+ SLOW,
113
+ );
114
+
115
+ it(
116
+ 'refuses a depth that is not a number of levels, and an unknown detail',
117
+ async () => {
118
+ for (const depth of [-1, 1.5, 'deep', '2']) {
119
+ await expect(
120
+ docs('cli/api', undefined, {depth: /** @type {any} */ (depth)}),
121
+ ).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
122
+ }
123
+ await expect(
124
+ docs('cli/api', undefined, {
125
+ depth: 1,
126
+ detail: /** @type {any} */ ('huge'),
127
+ }),
128
+ ).rejects.toMatchObject({code: 'ERR_INVALID_DETAIL'});
129
+ },
130
+ SLOW,
131
+ );
132
+ });
@@ -25,7 +25,8 @@ export const doc = {
25
25
  'ones the project\'s configured integrations contribute, including any ' +
26
26
  'topic an integration replaces or extends, so it depends on the cwd. ' +
27
27
  'A route opens a node of the docs tree instead: a namespace such as ' +
28
- "`cli/api` returns its children one level down, a typed doc such as " +
28
+ '`cli/api` returns its children one level down (`depth` reads as many ' +
29
+ 'levels as asked, and `detail` how much of each doc below), a typed doc such as ' +
29
30
  "`cli/api/functions/search` returns its content, and a guide the tree " +
30
31
  'places (`cli/integrations/quick-start`) reads like any topic. ' +
31
32
  'Every read but the list carries `links`, the commands that move from it: ' +
@@ -82,6 +83,18 @@ export const doc = {
82
83
  description:
83
84
  "Return the topic's section index (each section's key, title, and summary), even for a topic with one section.",
84
85
  },
86
+ {
87
+ name: 'options.depth',
88
+ type: "number | 'all'",
89
+ description:
90
+ "How many levels below a docs-tree namespace to read: 0 for the namespace alone, 1 for its children (the default), 'all' for every level. Where a read stops, a child with docs below it carries childCount. A doc with nothing below it reads the same at any depth.",
91
+ },
92
+ {
93
+ name: 'options.detail',
94
+ type: "'brief' | 'compact' | 'full'",
95
+ description:
96
+ "How much of each doc below the named one a depth read returns: brief (the default) is its identity; compact and full add its text (a guide's sections, a namespace's or typed doc's content). Given alone, it reads one level down.",
97
+ },
85
98
  {
86
99
  name: 'options.cwd',
87
100
  type: 'string',
@@ -113,10 +126,18 @@ export const doc = {
113
126
  {
114
127
  type: 'docs.node',
115
128
  description:
116
- "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.",
129
+ "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, or as deep as depth asks, each child carrying its own slots, childCount where the read stops, and its text at compact or full detail; a typed doc carries its content.",
117
130
  },
118
131
  ],
119
132
  throws: [
133
+ {
134
+ code: 'ERR_INVALID_ARGUMENT',
135
+ when: "depth is not a whole number of levels or 'all'",
136
+ },
137
+ {
138
+ code: 'ERR_INVALID_DETAIL',
139
+ when: 'detail is not brief, compact, or full',
140
+ },
120
141
  {
121
142
  code: 'ERR_UNKNOWN_TOPIC',
122
143
  when: 'the topic is not a string, or matches no topic and no docs-tree route',
@@ -134,6 +155,14 @@ export const doc = {
134
155
  code: "await docs('principles', undefined, {index: true});",
135
156
  },
136
157
  {label: 'A docs-tree namespace', code: "await docs('cli/api');"},
158
+ {
159
+ label: 'Every doc below a namespace, one entry each',
160
+ code: "await docs('cli', undefined, {depth: 'all'});",
161
+ },
162
+ {
163
+ label: 'A namespace and everything below it, in full',
164
+ code: "await docs('cli/integrations', undefined, {depth: 'all', detail: 'full'});",
165
+ },
137
166
  {label: 'One API function', code: "await docs('cli/api/functions/search');"},
138
167
  {
139
168
  label: 'A whole guide from the docs tree',
package/api/docs/docs.mjs CHANGED
@@ -11,6 +11,7 @@
11
11
  * docs(topic, undefined, {index: true}) -> index -> docs.index
12
12
  * docs(topic, section) -> section -> docs.detail.section
13
13
  * docs(route) -> node -> docs.node
14
+ * docs(route, undefined, {depth: 2}) -> node -> docs.node, two levels
14
15
  *
15
16
  * A topic read returns the whole doc, as it always has; `index` returns its
16
17
  * sections, so a reader can open one by its key (spec:AST-047). The CLI's text
@@ -33,6 +34,43 @@ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
33
34
 
34
35
  export {list, index, detail, sectionLeaf as section, nodeLeaf as node};
35
36
 
37
+ const DETAILS = ['brief', 'compact', 'full'];
38
+
39
+ /**
40
+ * How far a docs-tree read goes, from the options: `depth` levels below the
41
+ * node, or every level for `'all'`, and `detail` for each doc below it (brief
42
+ * by default). `detail` alone reads one level down. Neither: the plain read.
43
+ * @param {import('./docs.type.mjs').DocsOptions} options
44
+ * @returns {import('./node/node.mjs').DepthRead | undefined}
45
+ */
46
+ function depthRead(options) {
47
+ const {depth, detail} = options;
48
+ if (detail != null && !DETAILS.includes(detail)) {
49
+ throw new AstryxError(
50
+ `detail is brief, compact, or full, not ${JSON.stringify(detail)}.`,
51
+ undefined,
52
+ ERROR_CODES.ERR_INVALID_DETAIL,
53
+ );
54
+ }
55
+ if (
56
+ depth != null &&
57
+ depth !== 'all' &&
58
+ !(Number.isInteger(depth) && /** @type {number} */ (depth) >= 0)
59
+ ) {
60
+ throw new AstryxError(
61
+ `depth is a number of levels (0, 1, 2, ...) or "all", not ${JSON.stringify(depth)}.`,
62
+ undefined,
63
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
64
+ );
65
+ }
66
+ if (depth == null && detail == null) return undefined;
67
+ return {
68
+ depth: depth === 'all' ? Infinity : (depth ?? 1),
69
+ detail: /** @type {'brief' | 'compact' | 'full'} */ (detail ?? 'brief'),
70
+ lang: options.lang || (options.dense ? 'dense' : options.zh ? 'zh' : null),
71
+ };
72
+ }
73
+
36
74
  /**
37
75
  * @param {string} [topic]
38
76
  * @param {string} [section]
@@ -42,6 +80,10 @@ export {list, index, detail, sectionLeaf as section, nodeLeaf as node};
42
80
  * @param {boolean} [options.dense]
43
81
  * @param {boolean} [options.index] return the topic's section index instead of
44
82
  * the whole doc
83
+ * @param {number | 'all'} [options.depth] how many levels below a docs-tree
84
+ * namespace to read; a doc with nothing below it reads the same at any depth
85
+ * @param {'brief' | 'compact' | 'full'} [options.detail] how much of each doc
86
+ * below the named one a depth read returns (brief by default)
45
87
  * @param {string} [options.cwd]
46
88
  * @returns {Promise<
47
89
  * import('./docs.type.mjs').DocsListResponse |
@@ -52,6 +94,7 @@ export {list, index, detail, sectionLeaf as section, nodeLeaf as node};
52
94
  * >}
53
95
  */
54
96
  export async function docs(topic, section, options = {}) {
97
+ const read = depthRead(options);
55
98
  if (!topic) return list(options);
56
99
  const found = await resolveDocsArgument(topic, options);
57
100
  if (found.kind === 'node') {
@@ -77,7 +120,7 @@ export async function docs(topic, section, options = {}) {
77
120
  }
78
121
  return {
79
122
  type: 'docs.node',
80
- data: await nodeView(found.catalog, found.tree, found.node),
123
+ data: await nodeView(found.catalog, found.tree, found.node, read),
81
124
  };
82
125
  }
83
126
  if (section) return sectionLeaf(topic, section, options);
@@ -205,9 +205,14 @@ export type DocsNode = {
205
205
  breadcrumb: DocsNodeLink[];
206
206
  /**
207
207
  * a namespace's slots that hold children, in
208
- * order; empty for a typed doc
208
+ * order; empty for a typed doc, and for a depth read of 0
209
209
  */
210
210
  slots: DocsNodeSlot[];
211
+ /**
212
+ * with a depth read of 0, how many docs sit
213
+ * right below the namespace
214
+ */
215
+ childCount?: number | undefined;
211
216
  /**
212
217
  * a typed doc's content; empty for a namespace
213
218
  */
@@ -246,6 +251,26 @@ export type DocsNodeChild = {
246
251
  kind: string;
247
252
  title: string;
248
253
  summary: string;
254
+ /**
255
+ * with a depth read, its own slots, while
256
+ * the read goes deeper
257
+ */
258
+ slots?: DocsNodeSlot[] | undefined;
259
+ /**
260
+ * with a depth read, how many docs sit right
261
+ * below it where the read stops
262
+ */
263
+ childCount?: number | undefined;
264
+ /**
265
+ * with a depth read at compact or full detail: a namespace's intro or a typed
266
+ * doc's content
267
+ */
268
+ content?: import("@astryxdesign/cli/authoring").ReferenceContentBlock[] | undefined;
269
+ /**
270
+ * with a depth read at compact or full
271
+ * detail: a guide's sections
272
+ */
273
+ sections?: DocsReadSection[] | undefined;
249
274
  };
250
275
  /**
251
276
  * Options for `docs()`.
@@ -259,6 +284,18 @@ export type DocsOptions = {
259
284
  * whole doc
260
285
  */
261
286
  index?: boolean | undefined;
287
+ /**
288
+ * how many levels below a docs-tree
289
+ * namespace to read: 0 for the namespace alone, 1 for its children (the
290
+ * default), 'all' for every level
291
+ */
292
+ depth?: number | "all" | undefined;
293
+ /**
294
+ * how much of each doc below
295
+ * the named one a depth read returns: brief (the default) is its identity,
296
+ * compact and full add its text
297
+ */
298
+ detail?: "compact" | "full" | "brief" | undefined;
262
299
  /**
263
300
  * project directory whose configured integrations
264
301
  * contribute topics; defaults to process.cwd()
@@ -153,7 +153,9 @@
153
153
  * @property {string} summary
154
154
  * @property {DocsNodeLink[]} breadcrumb the namespaces above it, top first
155
155
  * @property {DocsNodeSlot[]} slots a namespace's slots that hold children, in
156
- * order; empty for a typed doc
156
+ * order; empty for a typed doc, and for a depth read of 0
157
+ * @property {number} [childCount] with a depth read of 0, how many docs sit
158
+ * right below the namespace
157
159
  * @property {import('@astryxdesign/cli/authoring').ReferenceContentBlock[]} content
158
160
  * a typed doc's content; empty for a namespace
159
161
  * @property {DocsLinks} links the moves from the node: up to its parent (the
@@ -181,6 +183,15 @@
181
183
  * @property {string} kind
182
184
  * @property {string} title
183
185
  * @property {string} summary
186
+ * @property {DocsNodeSlot[]} [slots] with a depth read, its own slots, while
187
+ * the read goes deeper
188
+ * @property {number} [childCount] with a depth read, how many docs sit right
189
+ * below it where the read stops
190
+ * @property {import('@astryxdesign/cli/authoring').ReferenceContentBlock[]} [content]
191
+ * with a depth read at compact or full detail: a namespace's intro or a typed
192
+ * doc's content
193
+ * @property {DocsReadSection[]} [sections] with a depth read at compact or full
194
+ * detail: a guide's sections
184
195
  */
185
196
 
186
197
  /**
@@ -191,6 +202,12 @@
191
202
  * @property {boolean} [dense]
192
203
  * @property {boolean} [index] return a topic's section index instead of its
193
204
  * whole doc
205
+ * @property {number | 'all'} [depth] how many levels below a docs-tree
206
+ * namespace to read: 0 for the namespace alone, 1 for its children (the
207
+ * default), 'all' for every level
208
+ * @property {'brief' | 'compact' | 'full'} [detail] how much of each doc below
209
+ * the named one a depth read returns: brief (the default) is its identity,
210
+ * compact and full add its text
194
211
  * @property {string} [cwd] project directory whose configured integrations
195
212
  * contribute topics; defaults to process.cwd()
196
213
  */
@@ -4,15 +4,28 @@
4
4
  /**
5
5
  * @typedef {import('../../../foundation/doc-compiler/tree.mjs').DocsTree} DocsTree
6
6
  * @typedef {import('../../../foundation/doc-compiler/tree.mjs').TreeNode} TreeNode
7
+ * @typedef {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} DocsCatalog
7
8
  */
8
9
  /**
9
- * The docs.node view of one tree node.
10
- * @param {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} catalog
10
+ * How far a read goes below the node it names, and how much of each doc below
11
+ * it shows: `depth` levels (Infinity for every level), and `detail` brief (its
12
+ * identity), or compact or full (with its text: a namespace's intro, a guide's
13
+ * sections, a typed doc's content). `lang` selects the guides' language.
14
+ * @typedef {object} DepthRead
15
+ * @property {number} depth
16
+ * @property {'brief' | 'compact' | 'full'} detail
17
+ * @property {string | null} lang
18
+ */
19
+ /**
20
+ * The docs.node view of one tree node. Without a depth read, a namespace lists
21
+ * its children one level down.
22
+ * @param {DocsCatalog} catalog
11
23
  * @param {DocsTree} tree
12
24
  * @param {TreeNode} node
25
+ * @param {DepthRead} [read] how far down to go, and how much of each doc below
13
26
  * @returns {Promise<import('../docs.type.mjs').DocsNode>}
14
27
  */
15
- export function nodeView(catalog: import("../../../foundation/discovery/docs-discovery.mjs").DocsCatalog, tree: DocsTree, node: TreeNode): Promise<import("../docs.type.mjs").DocsNode>;
28
+ export function nodeView(catalog: DocsCatalog, tree: DocsTree, node: TreeNode, read?: DepthRead): Promise<import("../docs.type.mjs").DocsNode>;
16
29
  /**
17
30
  * The typed edges a doc declares (spec:AST-047 FR5), resolved to routes: a
18
31
  * function doc's `command` and `related`, and a command doc's `fn` and
@@ -41,3 +54,15 @@ export function node(route: string, options?: {
41
54
  }): Promise<import("../docs.type.mjs").DocsNodeResponse>;
42
55
  export type DocsTree = import("../../../foundation/doc-compiler/tree.mjs").DocsTree;
43
56
  export type TreeNode = import("../../../foundation/doc-compiler/tree.mjs").TreeNode;
57
+ export type DocsCatalog = import("../../../foundation/discovery/docs-discovery.mjs").DocsCatalog;
58
+ /**
59
+ * How far a read goes below the node it names, and how much of each doc below
60
+ * it shows: `depth` levels (Infinity for every level), and `detail` brief (its
61
+ * identity), or compact or full (with its text: a namespace's intro, a guide's
62
+ * sections, a typed doc's content). `lang` selects the guides' language.
63
+ */
64
+ export type DepthRead = {
65
+ depth: number;
66
+ detail: "brief" | "compact" | "full";
67
+ lang: string | null;
68
+ };
@@ -7,14 +7,18 @@
7
7
  * typed doc such as `cli/api/functions/search`, plus {cwd}.
8
8
  * @output { type: 'docs.node', data: DocsNode } — the node's identity, title
9
9
  * and summary, the namespaces above it, and either its slots with their
10
- * children (a namespace) or its content (a typed doc). A namespace never
11
- * lists its grandchildren, so a reader goes down one level at a time.
12
- * Matches `astryx --json docs <route>`.
10
+ * children (a namespace) or its content (a typed doc). By default a
11
+ * namespace lists its children one level down; a depth read goes as far
12
+ * down as asked, with each doc below as its identity (brief) or with its
13
+ * text (compact, full). Matches `astryx --json docs <route> [--depth <n>]`.
13
14
  * @position Leaf under api/docs, beside the topic leaves. A guide the tree
14
15
  * places is a topic: the detail leaf reads it by its route.
15
16
  */
16
17
 
18
+ import {detailView} from '../../../foundation/doc-compiler/lenses.mjs';
17
19
  import {
20
+ compileTopic,
21
+ guideEntry,
18
22
  nodeContent,
19
23
  placeLinks,
20
24
  resolveDocsArgument,
@@ -24,18 +28,34 @@ import {
24
28
  /**
25
29
  * @typedef {import('../../../foundation/doc-compiler/tree.mjs').DocsTree} DocsTree
26
30
  * @typedef {import('../../../foundation/doc-compiler/tree.mjs').TreeNode} TreeNode
31
+ * @typedef {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} DocsCatalog
27
32
  */
28
33
 
29
34
  /**
30
- * The docs.node view of one tree node.
31
- * @param {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} catalog
35
+ * How far a read goes below the node it names, and how much of each doc below
36
+ * it shows: `depth` levels (Infinity for every level), and `detail` brief (its
37
+ * identity), or compact or full (with its text: a namespace's intro, a guide's
38
+ * sections, a typed doc's content). `lang` selects the guides' language.
39
+ * @typedef {object} DepthRead
40
+ * @property {number} depth
41
+ * @property {'brief' | 'compact' | 'full'} detail
42
+ * @property {string | null} lang
43
+ */
44
+
45
+ /**
46
+ * The docs.node view of one tree node. Without a depth read, a namespace lists
47
+ * its children one level down.
48
+ * @param {DocsCatalog} catalog
32
49
  * @param {DocsTree} tree
33
50
  * @param {TreeNode} node
51
+ * @param {DepthRead} [read] how far down to go, and how much of each doc below
34
52
  * @returns {Promise<import('../docs.type.mjs').DocsNode>}
35
53
  */
36
- export async function nodeView(catalog, tree, node) {
54
+ export async function nodeView(catalog, tree, node, read) {
37
55
  const {content} = await nodeContent(catalog, tree, node);
38
- return {
56
+ const slots = node.slots.filter(slot => slot.children.length > 0);
57
+ /** @type {import('../docs.type.mjs').DocsNode} */
58
+ const view = {
39
59
  id: node.id,
40
60
  route: node.route,
41
61
  kind: node.kind,
@@ -45,25 +65,128 @@ export async function nodeView(catalog, tree, node) {
45
65
  breadcrumb: tree
46
66
  .ancestors(node)
47
67
  .map(ancestor => ({route: ancestor.route, title: ancestor.title})),
48
- slots: node.slots
49
- .filter(slot => slot.children.length > 0)
50
- .map(slot => ({
51
- name: slot.name,
52
- title: slot.title,
53
- children: slot.children.map(route => {
54
- const child = /** @type {TreeNode} */ (tree.get(route));
55
- return {
56
- route: child.route,
57
- name: child.route.slice(child.route.lastIndexOf('/') + 1),
58
- kind: child.kind,
59
- title: child.title,
60
- summary: child.summary,
61
- };
62
- }),
63
- })),
68
+ slots: !read
69
+ ? slots.map(slot => ({
70
+ name: slot.name,
71
+ title: slot.title,
72
+ children: slot.children.map(route =>
73
+ childIdentity(/** @type {TreeNode} */ (tree.get(route))),
74
+ ),
75
+ }))
76
+ : read.depth >= 1
77
+ ? await slotsBelow(catalog, tree, slots, 1, read)
78
+ : [],
64
79
  content,
65
80
  links: nodeLinks(tree, node),
66
81
  };
82
+ if (read && read.depth < 1 && slots.length > 0) {
83
+ view.childCount = countChildren(slots);
84
+ }
85
+ return view;
86
+ }
87
+
88
+ /**
89
+ * The fields every child carries: what it is, and the route that opens it.
90
+ * @param {TreeNode} child
91
+ * @returns {import('../docs.type.mjs').DocsNodeChild}
92
+ */
93
+ function childIdentity(child) {
94
+ return {
95
+ route: child.route,
96
+ name: child.route.slice(child.route.lastIndexOf('/') + 1),
97
+ kind: child.kind,
98
+ title: child.title,
99
+ summary: child.summary,
100
+ };
101
+ }
102
+
103
+ /**
104
+ * @param {TreeNode['slots']} slots
105
+ * @returns {number}
106
+ */
107
+ function countChildren(slots) {
108
+ return slots.reduce((count, slot) => count + slot.children.length, 0);
109
+ }
110
+
111
+ /**
112
+ * Slots read `level` levels below the named node: each child at the read's
113
+ * detail, and its own slots while the read goes deeper.
114
+ * @param {DocsCatalog} catalog
115
+ * @param {DocsTree} tree
116
+ * @param {TreeNode['slots']} slots
117
+ * @param {number} level
118
+ * @param {DepthRead} read
119
+ * @returns {Promise<import('../docs.type.mjs').DocsNodeSlot[]>}
120
+ */
121
+ async function slotsBelow(catalog, tree, slots, level, read) {
122
+ return Promise.all(
123
+ slots.map(async slot => ({
124
+ name: slot.name,
125
+ title: slot.title,
126
+ children: await Promise.all(
127
+ slot.children.map(route =>
128
+ childBelow(
129
+ catalog,
130
+ tree,
131
+ /** @type {TreeNode} */ (tree.get(route)),
132
+ level,
133
+ read,
134
+ ),
135
+ ),
136
+ ),
137
+ })),
138
+ );
139
+ }
140
+
141
+ /**
142
+ * One child of a depth read. Where the read stops, a child with docs below it
143
+ * says how many, so a reader knows to go deeper.
144
+ * @param {DocsCatalog} catalog
145
+ * @param {DocsTree} tree
146
+ * @param {TreeNode} child
147
+ * @param {number} level
148
+ * @param {DepthRead} read
149
+ * @returns {Promise<import('../docs.type.mjs').DocsNodeChild>}
150
+ */
151
+ async function childBelow(catalog, tree, child, level, read) {
152
+ const view = childIdentity(child);
153
+ if (read.detail !== 'brief') {
154
+ Object.assign(view, await childText(catalog, tree, child, read.lang));
155
+ }
156
+ const slots = child.slots.filter(slot => slot.children.length > 0);
157
+ if (slots.length > 0) {
158
+ if (level < read.depth) {
159
+ view.slots = await slotsBelow(catalog, tree, slots, level + 1, read);
160
+ } else {
161
+ view.childCount = countChildren(slots);
162
+ }
163
+ }
164
+ return view;
165
+ }
166
+
167
+ /**
168
+ * A child's text: a guide's compiled sections, or the content of a namespace
169
+ * or typed doc.
170
+ * @param {DocsCatalog} catalog
171
+ * @param {DocsTree} tree
172
+ * @param {TreeNode} child
173
+ * @param {string | null} lang
174
+ * @returns {Promise<{content?: any[], sections?: any[]}>}
175
+ */
176
+ async function childText(catalog, tree, child, lang) {
177
+ if (child.kind === 'generic') {
178
+ const entry = child.ref?.topicFile
179
+ ? guideEntry(child)
180
+ : child.ref?.flatTopic
181
+ ? catalog.resolve(child.ref.flatTopic)
182
+ : null;
183
+ if (!entry) return {};
184
+ return {
185
+ sections: detailView(await compileTopic(catalog, entry, lang)).sections,
186
+ };
187
+ }
188
+ const {content} = await nodeContent(catalog, tree, child);
189
+ return {content};
67
190
  }
68
191
 
69
192
  /**
@@ -13,7 +13,7 @@
13
13
  export function list({ cwd, category, detail, zh, lang, }?: {
14
14
  cwd?: string | undefined;
15
15
  category?: string | undefined;
16
- detail?: "compact" | "full" | "names" | "brief" | undefined;
16
+ detail?: "compact" | "full" | "brief" | "names" | undefined;
17
17
  zh?: boolean | undefined;
18
18
  lang?: string | null | undefined;
19
19
  }): Promise<import("../hook.type.mjs").HookListResponse>;
@@ -2,7 +2,7 @@
2
2
 
3
3
  // AUTO-GENERATED — do not edit manually.
4
4
  // Source: packages/core/src/theme/tokens.stylex.ts,
5
- // domainTokens/dataTokens.ts, and syntax/tokens.ts
5
+ // dataTokens.stylex.ts, and syntax/tokens.ts
6
6
  // Run: node scripts/generate-token-docs.mjs
7
7
  // Total: 258 tokens across 15 categories.
8
8
 
@@ -439,7 +439,7 @@ export const docs = {
439
439
  "content": [
440
440
  {
441
441
  "type": "prose",
442
- "text": "Colors for charts and graphs: one categorical accent per series, a neutral for labels and reference lines, and sequential ramps from 5 (darkest) to 1 (lightest) for ordered scales and heatmaps."
442
+ "text": "Colors for charts and graphs: one categorical accent per series, a neutral for labels and reference lines, and sequential ramps from 5 (darkest) to 1 (lightest) for ordered scales and heatmaps. Import their public StyleX variables from @astryxdesign/core/theme/dataTokens.stylex."
443
443
  },
444
444
  {
445
445
  "type": "table",
@@ -1479,7 +1479,7 @@ export const docs = {
1479
1479
  "type": "code",
1480
1480
  "lang": "tsx",
1481
1481
  "label": "Using token imports",
1482
- "code": "import * as stylex from '@stylexjs/stylex';\nimport {colorVars, spacingVars, sizeVars, radiusVars} from '@astryxdesign/core/theme/tokens.stylex';\n\nconst styles = stylex.create({\n card: {\n padding: spacingVars['--spacing-4'],\n backgroundColor: colorVars['--color-background-surface'],\n borderRadius: radiusVars['--radius-container'],\n },\n button: {\n height: sizeVars['--size-element-md'],\n },\n});"
1482
+ "code": "import * as stylex from '@stylexjs/stylex';\nimport {colorVars, spacingVars, sizeVars, radiusVars} from '@astryxdesign/core/theme/tokens.stylex';\nimport {dataVars} from '@astryxdesign/core/theme/dataTokens.stylex';\n\nconst styles = stylex.create({\n card: {\n padding: spacingVars['--spacing-4'],\n backgroundColor: colorVars['--color-background-surface'],\n borderRadius: radiusVars['--radius-container'],\n },\n series: {\n color: dataVars['--color-data-categorical-blue'],\n },\n button: {\n height: sizeVars['--size-element-md'],\n },\n});"
1483
1483
  },
1484
1484
  {
1485
1485
  "type": "prose",
@@ -0,0 +1,219 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import * as fs from 'node:fs';
4
+ import * as path from 'node:path';
5
+ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
6
+ import {runCli} from '../../../test-utils/run-cli.mjs';
7
+
8
+ const SLOW = 60_000;
9
+
10
+ /** @type {string} */
11
+ let tmpDir;
12
+
13
+ beforeEach(() => {
14
+ tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-docs-depth-test-'));
15
+ });
16
+
17
+ afterEach(() => {
18
+ fs.rmSync(tmpDir, {recursive: true, force: true});
19
+ });
20
+
21
+ /** An app with an integration that places one guide under its namespace. */
22
+ function scaffoldGuide() {
23
+ fs.writeFileSync(
24
+ path.join(tmpDir, 'package.json'),
25
+ JSON.stringify({name: 'consumer'}),
26
+ );
27
+ fs.writeFileSync(
28
+ path.join(tmpDir, 'astryx.config.mjs'),
29
+ "export default {integrations: ['@acme/kit']};\n",
30
+ );
31
+ const packageDir = path.join(tmpDir, 'node_modules', '@acme', 'kit');
32
+ fs.mkdirSync(path.join(packageDir, 'docs'), {recursive: true});
33
+ fs.writeFileSync(
34
+ path.join(packageDir, 'package.json'),
35
+ JSON.stringify({name: '@acme/kit', version: '1.0.0'}),
36
+ );
37
+ fs.writeFileSync(
38
+ path.join(packageDir, 'astryx.integration.mjs'),
39
+ "export default {docs: './docs'};\n",
40
+ );
41
+ const namespace = {
42
+ type: 'namespace',
43
+ name: 'acme',
44
+ title: 'Acme docs',
45
+ summary: 'Build with the Acme kit.',
46
+ slots: {guides: {title: 'Guides', accepts: {kinds: ['generic']}}},
47
+ };
48
+ const guide = {
49
+ type: 'generic',
50
+ name: 'themes',
51
+ title: 'Theme building',
52
+ description: 'Build an Acme theme.',
53
+ placement: {parent: 'namespace:acme', slot: 'guides'},
54
+ sections: [
55
+ {
56
+ title: 'Create the theme',
57
+ content: [
58
+ {
59
+ type: 'prose',
60
+ text: 'Child guide body marker: compile the ocean palette.',
61
+ },
62
+ {type: 'code', lang: 'bash', code: 'npx acme theme build ocean'},
63
+ ],
64
+ },
65
+ ],
66
+ };
67
+ for (const [file, doc] of [
68
+ ['acme.doc.mjs', namespace],
69
+ ['themes.doc.mjs', guide],
70
+ ]) {
71
+ fs.writeFileSync(
72
+ path.join(packageDir, 'docs', file),
73
+ `export const docs = ${JSON.stringify(doc, null, 2)};\n`,
74
+ );
75
+ }
76
+ }
77
+
78
+ describe('astryx docs --depth', () => {
79
+ it(
80
+ 'lists every doc below a namespace, one line each, by where it sits',
81
+ async () => {
82
+ const result = await runCli(['docs', 'cli/api', '--depth', 'all']);
83
+ expect(result.status).toBe(0);
84
+ expect(result.stdout).toMatch(/^functions\s+\S/m);
85
+ expect(result.stdout).toMatch(/^functions\/search\s+search\(\): /m);
86
+ expect(result.stdout).toContain('Open one: ');
87
+ expect(result.stdout).toContain('docs cli/api/<name>');
88
+ // One line each: no doc's body.
89
+ expect(result.stdout).not.toContain('`astryx search` runs it.');
90
+ },
91
+ SLOW,
92
+ );
93
+
94
+ it(
95
+ 'says how many docs sit below where the read stops',
96
+ async () => {
97
+ const zero = await runCli(['docs', 'cli/api', '--depth', '0']);
98
+ expect(zero.status).toBe(0);
99
+ expect(zero.stdout).toMatch(
100
+ /^\d+ docs below\. Read them: .*docs cli\/api --depth 1$/m,
101
+ );
102
+ expect(zero.stdout).not.toMatch(/^functions\s/m);
103
+
104
+ const one = await runCli(['docs', 'cli/api', '--depth', '1']);
105
+ expect(one.status).toBe(0);
106
+ expect(one.stdout).toMatch(/^functions\s+.*\(\d+ docs below\)$/m);
107
+ expect(one.stdout).not.toMatch(/^functions\/search\s/m);
108
+ },
109
+ SLOW,
110
+ );
111
+
112
+ it(
113
+ 'prints each doc below whole with --detail full, and drops code at compact',
114
+ async () => {
115
+ scaffoldGuide();
116
+ const full = await runCli(
117
+ ['docs', 'acme', '--depth', 'all', '--detail', 'full'],
118
+ tmpDir,
119
+ );
120
+ expect(full.status).toBe(0);
121
+ expect(full.stdout).toMatch(/^## Theme building \(themes\)$/m);
122
+ expect(full.stdout).toMatch(/^### Create the theme$/m);
123
+ expect(full.stdout).toContain(
124
+ 'Child guide body marker: compile the ocean palette.',
125
+ );
126
+ expect(full.stdout).toContain('npx acme theme build ocean');
127
+
128
+ const compact = await runCli(
129
+ ['docs', 'acme', '--depth', '1', '--detail', 'compact'],
130
+ tmpDir,
131
+ );
132
+ expect(compact.status).toBe(0);
133
+ expect(compact.stdout).toContain('Child guide body marker');
134
+ expect(compact.stdout).not.toContain('npx acme theme build ocean');
135
+
136
+ // Without --depth, the namespace still lists the guide by one line.
137
+ const plain = await runCli(['docs', 'acme'], tmpDir);
138
+ expect(plain.status).toBe(0);
139
+ expect(plain.stdout).toMatch(/^themes\s+Build an Acme theme\./m);
140
+ expect(plain.stdout).not.toContain('Child guide body marker');
141
+ },
142
+ SLOW,
143
+ );
144
+
145
+ it(
146
+ 'returns the same tree as JSON, with text only when --detail asks',
147
+ async () => {
148
+ const brief = await runCli(['--json', 'docs', 'cli/api', '--depth', '2']);
149
+ expect(brief.status).toBe(0);
150
+ const briefData = JSON.parse(brief.stdout);
151
+ expect(briefData.type).toBe('docs.node');
152
+ const functions = briefData.data.slots
153
+ .flatMap((/** @type {any} */ slot) => slot.children)
154
+ .find(
155
+ (/** @type {any} */ child) => child.route === 'cli/api/functions',
156
+ );
157
+ const search = functions.slots
158
+ .flatMap((/** @type {any} */ slot) => slot.children)
159
+ .find(
160
+ (/** @type {any} */ child) =>
161
+ child.route === 'cli/api/functions/search',
162
+ );
163
+ expect(search).not.toHaveProperty('content');
164
+
165
+ const full = await runCli([
166
+ '--json',
167
+ 'docs',
168
+ 'cli/api',
169
+ '--depth',
170
+ '2',
171
+ '--detail',
172
+ 'full',
173
+ ]);
174
+ expect(full.status).toBe(0);
175
+ expect(full.stdout).toContain('`astryx search` runs it.');
176
+ },
177
+ SLOW,
178
+ );
179
+
180
+ it(
181
+ 'composes with --index and --full, and leaves a topic read as it was',
182
+ async () => {
183
+ const depth = await runCli(['docs', 'cli/api', '--depth', '1']);
184
+ expect(depth.status).toBe(0);
185
+ for (const flag of ['--index', '--full']) {
186
+ const both = await runCli(['docs', 'cli/api', '--depth', '1', flag]);
187
+ expect(both.status).toBe(0);
188
+ expect(both.stdout).toBe(depth.stdout);
189
+ }
190
+ for (const args of [
191
+ ['docs', 'theme'],
192
+ ['docs', 'theme', '--index'],
193
+ ['docs', 'theme', '--full'],
194
+ ]) {
195
+ const plain = await runCli(args);
196
+ const withDepth = await runCli([...args, '--depth', '2']);
197
+ expect(withDepth.status).toBe(plain.status);
198
+ expect(withDepth.stdout).toBe(plain.stdout);
199
+ }
200
+ },
201
+ SLOW,
202
+ );
203
+
204
+ it(
205
+ 'refuses a depth that is not a number of levels',
206
+ async () => {
207
+ const result = await runCli([
208
+ '--json',
209
+ 'docs',
210
+ 'cli/api',
211
+ '--depth',
212
+ 'deep',
213
+ ]);
214
+ expect(result.status).toBe(1);
215
+ expect(JSON.parse(result.stdout).code).toBe('ERR_INVALID_ARGUMENT');
216
+ },
217
+ SLOW,
218
+ );
219
+ });
@@ -22,7 +22,9 @@ export const doc = {
22
22
  'does, and `--index` its section index. A route ' +
23
23
  'opens a node of the docs tree: `cli` lists its guides and reference, ' +
24
24
  '`cli/api/functions` lists every API function, and `cli/api/functions/search` prints ' +
25
- 'one.',
25
+ 'one. `--depth` reads as far down the tree as you ask, from the doc alone (0) to ' +
26
+ 'everything below it (all), and with it `--detail` sets how much of each doc below ' +
27
+ 'shows: one line (brief, the default), its sections (compact), or all of it (full).',
26
28
  fn: 'docs',
27
29
  args: [
28
30
  {name: 'topic', param: 'topic', required: false},
@@ -39,6 +41,12 @@ export const doc = {
39
41
  description:
40
42
  'Print the whole topic instead of its sections (text; `--json` returns the whole topic unless --index). Cannot be set with --index',
41
43
  },
44
+ {
45
+ flag: '--depth <levels>',
46
+ param: 'options.depth',
47
+ description:
48
+ 'How many levels of the docs tree to read below a namespace: 0 for the namespace alone, 1 for its children (what a read without --depth shows), all for everything below it. With it, --detail sets how much of each doc below shows: brief (one line each, the default), compact (with its sections), or full',
49
+ },
42
50
  ],
43
51
  examples: [
44
52
  {label: 'List topics', cli: 'astryx docs'},
@@ -46,6 +54,11 @@ export const doc = {
46
54
  {label: 'A whole topic as JSON', cli: 'astryx docs spacing --json'},
47
55
  {label: 'One section', cli: 'astryx docs theme quick-start'},
48
56
  {label: 'The CLI docs tree', cli: 'astryx docs cli'},
57
+ {label: 'Every CLI doc, one line each', cli: 'astryx docs cli --depth all'},
58
+ {
59
+ label: 'The integration guides as one read',
60
+ cli: 'astryx docs cli/integrations --depth all --detail full',
61
+ },
49
62
  {label: 'One API function', cli: 'astryx docs cli/api/functions/search'},
50
63
  {label: 'A whole guide', cli: 'astryx docs cli/integrations/quick-start --full'},
51
64
  ],
@@ -53,7 +66,7 @@ export const doc = {
53
66
  {code: 0, when: 'success'},
54
67
  {
55
68
  code: 1,
56
- when: 'unknown topic or route, or a section that matches no section or more than one',
69
+ when: 'unknown topic or route, a section that matches no section or more than one, or a --depth that is not a number of levels or all',
57
70
  },
58
71
  ],
59
72
  related: ['search', 'component', 'hook', 'template'],
@@ -4,9 +4,10 @@
4
4
  * @file docs command — Print Astryx reference docs
5
5
  *
6
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.
7
+ * open one section by its key, and `--full` prints the whole topic. `--depth`
8
+ * reads a docs-tree namespace as many levels down as asked, each doc below it
9
+ * at --detail (brief by default: one line each). `--json` keeps the docs()
10
+ * contract: a topic returns its whole doc, and `--index` its sections.
10
11
  * Supports --detail (full|compact|brief) and --lang (en|zh|dense). A code
11
12
  * block's label prints above its fence, and table cells escape their pipes.
12
13
  *
@@ -18,6 +19,7 @@
18
19
  * astryx docs <topic> --full Print the whole topic
19
20
  * astryx docs <route> Open a node of the docs tree, such as
20
21
  * cli, cli/api, or cli/api/functions/search
22
+ * astryx docs <route> --depth <n|all> Read that many levels below it
21
23
  */
22
24
 
23
25
  import {
@@ -181,6 +183,202 @@ function formatReferenceFull(docs, detail) {
181
183
  return `${header}\n\n${sections.join(sep)}`;
182
184
  }
183
185
 
186
+ /**
187
+ * @param {string} title
188
+ * @param {number} level
189
+ * @returns {string}
190
+ */
191
+ function treeHeading(title, level) {
192
+ return `${'#'.repeat(Math.max(1, Math.min(6, level)))} ${title}`;
193
+ }
194
+
195
+ /**
196
+ * A doc's blocks at one depth: its headings move down with it.
197
+ * @param {import('@astryxdesign/cli/authoring').ReferenceContentBlock[]} blocks
198
+ * @param {'full' | 'compact' | 'brief'} detail
199
+ * @param {number} headingOffset
200
+ * @returns {string[]}
201
+ */
202
+ function formatTreeBlocks(blocks, detail, headingOffset) {
203
+ /** @type {string[]} */
204
+ const formatted = [];
205
+ for (const block of blocks) {
206
+ const value =
207
+ block.type === 'heading'
208
+ ? treeHeading(block.text, (block.level || 3) + headingOffset)
209
+ : formatBlock(block, detail);
210
+ if (value) formatted.push(value);
211
+ }
212
+ return formatted;
213
+ }
214
+
215
+ /**
216
+ * @param {import('../../../api/docs/docs.type.mjs').DocsReadSection} docSection
217
+ * @param {'full' | 'compact' | 'brief'} detail
218
+ * @param {number} headingLevel
219
+ * @returns {string}
220
+ */
221
+ function formatTreeSection(docSection, detail, headingLevel) {
222
+ const heading = treeHeading(docSection.title, headingLevel);
223
+ const blocks = formatTreeBlocks(docSection.content, detail, headingLevel - 2);
224
+ return blocks.length > 0 ? `${heading}\n\n${blocks.join('\n\n')}` : heading;
225
+ }
226
+
227
+ /**
228
+ * Where a route sits below the namespace a read names.
229
+ * @param {string} route
230
+ * @param {string} root
231
+ * @returns {string}
232
+ */
233
+ function belowRoot(route, root) {
234
+ return route.startsWith(`${root}/`) ? route.slice(root.length + 1) : route;
235
+ }
236
+
237
+ /**
238
+ * @param {number} count
239
+ * @returns {string}
240
+ */
241
+ function docsBelow(count) {
242
+ return `${count} ${count === 1 ? 'doc' : 'docs'} below`;
243
+ }
244
+
245
+ /**
246
+ * Every child of a depth read, one row each in reading order, named by where
247
+ * it sits below the read's namespace.
248
+ * @param {import('../../../api/docs/docs.type.mjs').DocsNodeChild[]} children
249
+ * @param {string} root
250
+ * @returns {{name: string, summary: string}[]}
251
+ */
252
+ function treeRows(children, root) {
253
+ return children.flatMap(child => [
254
+ {
255
+ name: belowRoot(child.route, root),
256
+ summary: child.childCount
257
+ ? `${childRow(child).summary} (${docsBelow(child.childCount)})`
258
+ : childRow(child).summary,
259
+ },
260
+ ...(child.slots ?? []).flatMap(slot => treeRows(slot.children, root)),
261
+ ]);
262
+ }
263
+
264
+ /**
265
+ * One child of a depth read with its text, under a heading for its level, and
266
+ * its own children below it.
267
+ * @param {import('../../../api/docs/docs.type.mjs').DocsNodeChild} child
268
+ * @param {'full' | 'compact'} detail
269
+ * @param {number} level
270
+ * @param {string} root
271
+ * @param {string} run
272
+ * @returns {string}
273
+ */
274
+ function formatTreeChild(child, detail, level, root, run) {
275
+ const parts = [
276
+ `${treeHeading(child.title, level)} (${belowRoot(child.route, root)})`,
277
+ ];
278
+ if (
279
+ child.summary &&
280
+ (child.kind === 'namespace' || child.kind === 'generic')
281
+ ) {
282
+ parts.push(child.summary);
283
+ }
284
+ const content = formatTreeBlocks(child.content ?? [], detail, level - 2);
285
+ if (content.length > 0) parts.push(content.join('\n\n'));
286
+ parts.push(
287
+ ...(child.sections ?? []).map(docSection =>
288
+ formatTreeSection(docSection, detail, level + 1),
289
+ ),
290
+ );
291
+ if (child.childCount) {
292
+ parts.push(
293
+ `${docsBelow(child.childCount)}: ${run} docs ${child.route} --depth 1`,
294
+ );
295
+ }
296
+ for (const slot of child.slots ?? []) {
297
+ parts.push(
298
+ ...slot.children.map(each =>
299
+ formatTreeChild(each, detail, level + 1, root, run),
300
+ ),
301
+ );
302
+ }
303
+ return parts.join('\n\n');
304
+ }
305
+
306
+ /**
307
+ * A depth read of a namespace: its intro, then each slot's docs as deep as
308
+ * asked, one line each (brief) or with their text (compact, full). A typed doc
309
+ * has nothing below it, so it reads as it always does.
310
+ * @param {import('../../../api/docs/docs.type.mjs').DocsNode} node
311
+ * @param {'full' | 'compact' | 'brief'} detail how the named node reads
312
+ * @param {'full' | 'compact' | 'brief'} childDetail how each doc below reads
313
+ * @param {string} run
314
+ */
315
+ function emitTree(node, detail, childDetail, run) {
316
+ if (node.kind !== 'namespace') {
317
+ emitNode(node, detail, run);
318
+ return;
319
+ }
320
+ /**
321
+ * @param {import('../../../api/docs/docs.type.mjs').DocsNodeChild[]} children
322
+ * @returns {string[]}
323
+ */
324
+ const routes = children =>
325
+ children.flatMap(child => [
326
+ child.route,
327
+ ...(child.slots ?? []).flatMap(slot => routes(slot.children)),
328
+ ]);
329
+ const allBelow = node.slots
330
+ .flatMap(slot => routes(slot.children))
331
+ .every(route => route.startsWith(`${node.route}/`));
332
+ const root = allBelow ? node.route : '';
333
+ emit(
334
+ section(node.title, wrapText(node.summary)),
335
+ ...(node.content?.length
336
+ ? [
337
+ text(
338
+ node.content
339
+ .map(b => formatBlock(b, detail))
340
+ .filter(Boolean)
341
+ .join('\n\n'),
342
+ ),
343
+ ]
344
+ : []),
345
+ ...(node.childCount
346
+ ? [
347
+ text(
348
+ `${docsBelow(node.childCount)}. Read them: ${run} docs ${node.route} --depth 1`,
349
+ ),
350
+ ]
351
+ : []),
352
+ ...node.slots.flatMap(slot => [
353
+ ...(node.slots.length === 1 && slot.title === node.title
354
+ ? []
355
+ : [section(slot.title)]),
356
+ childDetail === 'brief'
357
+ ? records(treeRows(slot.children, root), {
358
+ fields: ['name', 'summary'],
359
+ layout: 'inline',
360
+ })
361
+ : code(
362
+ slot.children
363
+ .map(child => formatTreeChild(child, childDetail, 2, root, run))
364
+ .join('\n\n'),
365
+ ),
366
+ ]),
367
+ text(
368
+ [
369
+ ...(node.slots.length > 0
370
+ ? [
371
+ allBelow
372
+ ? `Open one: ${run} docs ${node.route}/<name>`
373
+ : `Open one: ${run} docs <name>`,
374
+ ]
375
+ : []),
376
+ ...linkLines(node.links),
377
+ ].join('\n'),
378
+ ),
379
+ );
380
+ }
381
+
184
382
  /**
185
383
  * The moves a read offers (spec:AST-047), one runnable command per line: up to
186
384
  * the level it sits in, the item before and after it, and the docs it names.
@@ -331,7 +529,7 @@ export function registerDocs(program) {
331
529
  action: async (
332
530
  /** @type {string | undefined} */ topic,
333
531
  /** @type {string | undefined} */ sectionName,
334
- /** @type {{index?: boolean, full?: boolean}} */ options = {},
532
+ /** @type {{index?: boolean, full?: boolean, depth?: string}} */ options = {},
335
533
  ) => {
336
534
  const run = getCliInvocation();
337
535
  const lang = program.opts().lang || null;
@@ -346,6 +544,22 @@ export function registerDocs(program) {
346
544
  {code: ERROR_CODES.ERR_INVALID_ARGUMENT},
347
545
  );
348
546
  }
547
+ /** @type {number | 'all' | undefined} */
548
+ let depth;
549
+ if (options.depth != null) {
550
+ if (options.depth === 'all') depth = 'all';
551
+ else if (/^\d+$/.test(options.depth)) depth = Number(options.depth);
552
+ else {
553
+ return cliError(
554
+ `--depth takes a number of levels (0, 1, 2, ...) or all, not "${options.depth}".`,
555
+ {code: ERROR_CODES.ERR_INVALID_ARGUMENT},
556
+ );
557
+ }
558
+ }
559
+ // With --depth, --detail is how much of each doc below shows; left at
560
+ // its default, each is one line.
561
+ const childDetail =
562
+ program.getOptionValueSource('detail') === 'default' ? 'brief' : detail;
349
563
  // Text reads one level: a topic lists its sections (one with a single
350
564
  // section prints whole). JSON keeps docs(): the whole topic unless
351
565
  // --index. The dense variant is written to be read whole.
@@ -363,6 +577,7 @@ export function registerDocs(program) {
363
577
  zh,
364
578
  dense,
365
579
  index: listSections,
580
+ ...(depth != null ? {depth, detail: childDetail} : {}),
366
581
  });
367
582
  if (
368
583
  !options.index &&
@@ -417,6 +632,7 @@ export function registerDocs(program) {
417
632
  ` ${run} docs <topic> <section> read one section`,
418
633
  ` ${run} docs <topic> --full read the whole topic`,
419
634
  ` ${run} docs cli/api go down the docs tree one level at a time`,
635
+ ` ${run} docs cli --depth all every doc below cli, one line each`,
420
636
  `With --json, a topic returns its whole doc; add --index for its section list.`,
421
637
  ].join('\n'),
422
638
  ),
@@ -462,7 +678,8 @@ export function registerDocs(program) {
462
678
  }
463
679
 
464
680
  case 'docs.node': {
465
- emitNode(result.data, detail, run);
681
+ if (depth != null) emitTree(result.data, detail, childDetail, run);
682
+ else emitNode(result.data, detail, run);
466
683
  break;
467
684
  }
468
685
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.6.5-canary.69aa1cb",
3
+ "version": "0.6.5-canary.74a62ce",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -101,10 +101,10 @@
101
101
  "zod": "^4.4.3"
102
102
  },
103
103
  "peerDependencies": {
104
- "@astryxdesign/charts": "0.6.5-canary.69aa1cb",
105
- "@astryxdesign/core": "0.6.5-canary.69aa1cb",
106
- "@astryxdesign/lab": "0.6.5-canary.69aa1cb",
107
- "@astryxdesign/theme-neutral": "0.6.5-canary.69aa1cb"
104
+ "@astryxdesign/charts": "0.6.5-canary.74a62ce",
105
+ "@astryxdesign/core": "0.6.5-canary.74a62ce",
106
+ "@astryxdesign/lab": "0.6.5-canary.74a62ce",
107
+ "@astryxdesign/theme-neutral": "0.6.5-canary.74a62ce"
108
108
  },
109
109
  "peerDependenciesMeta": {
110
110
  "@astryxdesign/charts": {
@@ -121,10 +121,10 @@
121
121
  }
122
122
  },
123
123
  "devDependencies": {
124
- "@astryxdesign/charts": "0.6.5-canary.69aa1cb",
125
- "@astryxdesign/core": "0.6.5-canary.69aa1cb",
126
- "@astryxdesign/lab": "0.6.5-canary.69aa1cb",
127
- "@astryxdesign/theme-neutral": "0.6.5-canary.69aa1cb",
124
+ "@astryxdesign/charts": "0.6.5-canary.74a62ce",
125
+ "@astryxdesign/core": "0.6.5-canary.74a62ce",
126
+ "@astryxdesign/lab": "0.6.5-canary.74a62ce",
127
+ "@astryxdesign/theme-neutral": "0.6.5-canary.74a62ce",
128
128
  "@heroicons/react": "^2.2.0",
129
129
  "@stylexjs/stylex": "^0.19.0",
130
130
  "@types/babel__core": "^7.20.5",