@astryxdesign/cli 0.6.3-canary.1f30d4e → 0.6.3-canary.1ffe66d

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 (181) hide show
  1. package/README.md +19 -17
  2. package/api/component/_adapter.d.mts +6 -12
  3. package/api/component/_adapter.mjs +20 -10
  4. package/api/component/component.mjs +60 -12
  5. package/api/component/list/list.mjs +3 -2
  6. package/api/docs/_adapter.d.mts +209 -28
  7. package/api/docs/_adapter.mjs +667 -35
  8. package/api/docs/detail/detail.mjs +11 -3
  9. package/api/docs/detail/section/section.mjs +20 -3
  10. package/api/docs/docs.d.mts +5 -3
  11. package/api/docs/docs.doc.mjs +35 -15
  12. package/api/docs/docs.mjs +44 -8
  13. package/api/docs/docs.test.mjs +158 -4
  14. package/api/docs/docs.type.d.mts +165 -2
  15. package/api/docs/docs.type.mjs +101 -3
  16. package/api/docs/index/index.mjs +11 -3
  17. package/api/docs/index/index.test.mjs +1 -1
  18. package/api/docs/integration-tree.test.mjs +547 -0
  19. package/api/docs/integrationDocs.test.mjs +14 -14
  20. package/api/docs/list/list.mjs +25 -5
  21. package/api/docs/node/node.d.mts +43 -0
  22. package/api/docs/node/node.mjs +192 -0
  23. package/api/doctor/doctor.d.mts +30 -2
  24. package/api/doctor/doctor.mjs +146 -7
  25. package/api/doctor/doctor.test.mjs +89 -1
  26. package/api/index.d.mts +1 -1
  27. package/api/index.mjs +1 -0
  28. package/api/init/init.doc.mjs +1 -1
  29. package/api/integration/add-contribution.d.mts +2 -1
  30. package/api/integration/add-contribution.mjs +107 -5
  31. package/api/integration/add-contribution.test.mjs +137 -0
  32. package/api/integration/authoring-checks.mjs +125 -28
  33. package/api/integration/authoring-checks.test.mjs +171 -3
  34. package/api/integration/authoring-checks.type.mjs +6 -1
  35. package/api/integration/integration-authoring.type.d.mts +2 -0
  36. package/api/integration/integration-authoring.type.mjs +2 -0
  37. package/api/integration/integrationAdd.doc.mjs +6 -0
  38. package/api/integration/integrationAddDoc.doc.mjs +7 -1
  39. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  40. package/api/integration/integrationPackCheck.doc.mjs +1 -1
  41. package/api/integration/integrationTemplateConflicts.doc.d.mts +3 -0
  42. package/api/integration/integrationTemplateConflicts.doc.mjs +3 -0
  43. package/api/integration/pack-check.mjs +34 -0
  44. package/api/integration/pack-check.test.mjs +121 -0
  45. package/api/integration/pack-check.type.d.mts +26 -2
  46. package/api/integration/pack-check.type.mjs +14 -1
  47. package/api/integration/template-conflict-compatibility.test.mjs +73 -0
  48. package/api/integration/validate-integration.test.mjs +3 -3
  49. package/api/integration/validateIntegration.doc.mjs +1 -1
  50. package/api/json/index.ts +2 -0
  51. package/api/layout/_adapter.mjs +20 -5
  52. package/api/search/search.d.mts +26 -1
  53. package/api/search/search.doc.mjs +4 -3
  54. package/api/search/search.mjs +308 -29
  55. package/api/search/search.test.mjs +91 -2
  56. package/api/search/search.type.d.mts +13 -1
  57. package/api/search/search.type.mjs +4 -1
  58. package/api/template/list/list.mjs +1 -0
  59. package/api/template/template-integration.test.mjs +1022 -3
  60. package/api/template/template.doc.mjs +27 -7
  61. package/api/template/template.mjs +45 -8
  62. package/api/template/template.type.d.mts +6 -8
  63. package/api/template/template.type.mjs +3 -2
  64. package/api/theme/template/template.test.mjs +5 -0
  65. package/api/theme/themeTemplate.doc.mjs +1 -1
  66. package/assets/docs/getting-started.doc.mjs +2 -2
  67. package/assets/docs/principles.doc.mjs +6 -6
  68. package/assets/docs/styling-libraries.doc.mjs +2 -2
  69. package/assets/docs/styling.doc.mjs +4 -4
  70. package/assets/docs/theme.doc.mjs +3 -3
  71. package/assets/docs/tokens.doc.mjs +1 -1
  72. package/assets/docs/tree/api.doc.mjs +30 -0
  73. package/assets/docs/tree/cli.doc.mjs +23 -0
  74. package/assets/docs/tree/commands.doc.mjs +25 -0
  75. package/assets/docs/{cli-integrations.doc.mjs → tree/integrations.doc.mjs} +37 -9
  76. package/assets/docs/tree/integrations.test.mjs +62 -0
  77. package/assets/docs/tree/writing-docs.doc.mjs +286 -0
  78. package/authoring/debug/parse.d.mts +3 -3
  79. package/authoring/doctypes/base/graph-fields.doc.mjs +7 -5
  80. package/authoring/doctypes/base/type.ts +6 -5
  81. package/authoring/doctypes/command/command.doc.mjs +1 -1
  82. package/authoring/doctypes/command/type.ts +2 -2
  83. package/authoring/doctypes/enum/enum.doc.mjs +1 -1
  84. package/authoring/doctypes/enum/type.ts +1 -1
  85. package/authoring/doctypes/function/function.doc.mjs +3 -2
  86. package/authoring/doctypes/function/type.ts +3 -2
  87. package/authoring/doctypes/namespace/namespace.doc.mjs +5 -9
  88. package/authoring/doctypes/reference/reference.doc.mjs +3 -3
  89. package/authoring/doctypes/reference/type.ts +3 -0
  90. package/authoring/doctypes/schema/schema.doc.mjs +1 -1
  91. package/authoring/doctypes/schema/type.ts +1 -1
  92. package/authoring/doctypes/template/parse.d.mts +2 -0
  93. package/authoring/doctypes/template/parse.mjs +4 -0
  94. package/authoring/doctypes/template/parse.test.mjs +18 -0
  95. package/authoring/doctypes/template/template.doc.mjs +6 -0
  96. package/authoring/doctypes/template/type.ts +8 -0
  97. package/authoring/identity/identity.doc.mjs +2 -2
  98. package/authoring/integration/type.ts +1 -1
  99. package/clients/cli/commands/build-theme.mjs +1 -1
  100. package/clients/cli/commands/build.mjs +5 -2
  101. package/clients/cli/commands/component/index.mjs +1 -1
  102. package/clients/cli/commands/component-ownership.test.mjs +3 -3
  103. package/clients/cli/commands/discover.broken-integration.test.mjs +7 -8
  104. package/clients/cli/commands/discover.mjs +1 -1
  105. package/clients/cli/commands/docs.doc.mjs +20 -8
  106. package/clients/cli/commands/docs.mjs +175 -18
  107. package/clients/cli/commands/docs.test.mjs +114 -7
  108. package/clients/cli/commands/doctor-integration-docs.doc.mjs +2 -2
  109. package/clients/cli/commands/doctor-integration-templates.doc.mjs +14 -7
  110. package/clients/cli/commands/doctor-integration.test.mjs +75 -1
  111. package/clients/cli/commands/doctor.mjs +53 -16
  112. package/clients/cli/commands/integration-add.doc.mjs +10 -0
  113. package/clients/cli/commands/integration.mjs +1 -0
  114. package/clients/cli/commands/search.mjs +11 -2
  115. package/clients/cli/commands/setup-nudge.test.mjs +6 -0
  116. package/clients/cli/commands/template.doc.mjs +23 -6
  117. package/clients/cli/commands/template.mjs +4 -91
  118. package/clients/cli/commands/text-json-parity.test.mjs +2 -1
  119. package/clients/cli/index.mjs +8 -0
  120. package/clients/cli/lib/manifest.mjs +9 -2
  121. package/foundation/agent-docs/agent-docs.mjs +1 -0
  122. package/foundation/agent-docs/agent-docs.test.mjs +10 -1
  123. package/foundation/config/project.d.mts +12 -11
  124. package/foundation/config/project.mjs +73 -59
  125. package/foundation/config/project.test.mjs +141 -5
  126. package/foundation/discovery/authoring-self-docs.test.mjs +17 -7
  127. package/foundation/discovery/cli-self-docs.d.mts +40 -34
  128. package/foundation/discovery/cli-self-docs.mjs +91 -115
  129. package/foundation/discovery/cli-self-docs.test.mjs +104 -166
  130. package/foundation/discovery/component-discovery.d.mts +38 -0
  131. package/foundation/discovery/component-discovery.mjs +48 -0
  132. package/foundation/discovery/docs-discovery.d.mts +105 -8
  133. package/foundation/discovery/docs-discovery.mjs +177 -13
  134. package/foundation/discovery/docs-discovery.test.mjs +56 -17
  135. package/foundation/discovery/docs-output-budget.d.mts +2 -2
  136. package/foundation/discovery/docs-output-budget.mjs +1 -1
  137. package/foundation/discovery/docs-section-key.d.mts +9 -2
  138. package/foundation/discovery/docs-section-key.mjs +15 -1
  139. package/foundation/discovery/template-adapter.d.mts +92 -6
  140. package/foundation/discovery/template-adapter.mjs +453 -17
  141. package/foundation/discovery/template-adapter.test.mjs +42 -0
  142. package/foundation/discovery/template-conflict-release.d.mts +13 -0
  143. package/foundation/discovery/template-conflict-release.mjs +40 -0
  144. package/foundation/discovery/template-conflict-release.test.mjs +40 -0
  145. package/foundation/doc-compiler/bundle.mjs +61 -1
  146. package/foundation/doc-compiler/bundle.test.mjs +21 -10
  147. package/foundation/doc-compiler/compile.d.mts +113 -132
  148. package/foundation/doc-compiler/compile.mjs +52 -6
  149. package/foundation/doc-compiler/diagnostics.mjs +28 -0
  150. package/foundation/doc-compiler/doc-loads.test.mjs +2 -2
  151. package/foundation/doc-compiler/inputs.d.mts +2 -2
  152. package/foundation/doc-compiler/inputs.mjs +6 -1
  153. package/foundation/doc-compiler/ir.mjs +7 -0
  154. package/foundation/doc-compiler/lenses.d.mts +3 -2
  155. package/foundation/doc-compiler/lenses.mjs +2 -1
  156. package/foundation/doc-compiler/links.d.mts +135 -0
  157. package/foundation/doc-compiler/links.mjs +253 -0
  158. package/foundation/doc-compiler/links.test.mjs +139 -0
  159. package/foundation/doc-compiler/lower-doc.test.mjs +5 -2
  160. package/foundation/doc-compiler/read.d.mts +3 -2
  161. package/foundation/doc-compiler/read.mjs +6 -1
  162. package/foundation/doc-compiler/tree.d.mts +288 -0
  163. package/foundation/doc-compiler/tree.mjs +876 -0
  164. package/foundation/doc-compiler/tree.test.mjs +598 -0
  165. package/foundation/integrations/autolink.test.mjs +1 -1
  166. package/foundation/integrations/cli-requirement.d.mts +45 -0
  167. package/foundation/integrations/cli-requirement.mjs +154 -0
  168. package/foundation/integrations/cli-requirement.test.mjs +109 -0
  169. package/foundation/integrations/contribution-inventory.d.mts +2 -1
  170. package/foundation/integrations/contribution-inventory.mjs +10 -4
  171. package/foundation/integrations/contribution-inventory.test.mjs +19 -0
  172. package/foundation/integrations/integration-warnings.d.mts +9 -2
  173. package/foundation/integrations/integration-warnings.mjs +51 -26
  174. package/foundation/integrations/integration-warnings.test.mjs +74 -1
  175. package/foundation/integrations/validate-contributions.mjs +25 -27
  176. package/foundation/response/response-types.doc.d.mts +5 -1
  177. package/foundation/response/response-types.doc.mjs +18 -9
  178. package/foundation/xle/expand.mjs +1 -1
  179. package/foundation/xle/xle.test.mjs +13 -0
  180. package/package.json +9 -9
  181. package/assets/docs/cli.doc.mjs +0 -15
@@ -22,6 +22,24 @@ function reason(value, label = 'template') {
22
22
  }
23
23
 
24
24
  describe('parseTemplate (load boundary)', () => {
25
+ it('accepts replaces on page and block templates', () => {
26
+ for (const type of ['page', 'block']) {
27
+ const parsed = parseTemplate({
28
+ type,
29
+ name: 'Acme shell',
30
+ description: 'Replaces a Core template.',
31
+ replaces: 'shell-side-nav',
32
+ });
33
+ expect(parsed.replaces).toBe('shell-side-nav');
34
+ }
35
+ });
36
+
37
+ it('rejects an empty replaces', () => {
38
+ expect(reason({type: 'page', name: 'Acme shell', replaces: ''})).toMatch(
39
+ /replaces must name a Core template id/,
40
+ );
41
+ });
42
+
25
43
  it('accepts a stamped page template', () => {
26
44
  const parsed = parseTemplate({
27
45
  type: 'page',
@@ -52,6 +52,12 @@ export const doc = {
52
52
  type: 'string',
53
53
  description: 'One-sentence description of what the template provides.',
54
54
  },
55
+ {
56
+ name: 'replaces',
57
+ type: 'string',
58
+ description:
59
+ "Integration templates only: the exact id of the Core template this one replaces for unqualified lookup. Find it with `astryx --json template --list --package @astryxdesign/core`; the Core original stays selectable with `--package @astryxdesign/core`. A page replaces only a Core page and a block only a Core block. Needs @astryxdesign/cli 0.7.0 or later: earlier CLIs reject the field and withhold the package's templates and doc topics.",
60
+ },
55
61
  {
56
62
  name: 'isReady',
57
63
  type: 'boolean',
@@ -28,6 +28,14 @@ export interface BaseTemplateDoc extends AuthoredDocGraphFields {
28
28
 
29
29
  /** Optional stable slug override and prior aliases for registry output. */
30
30
  registry?: RegistryDocIdentity;
31
+
32
+ /** Integration templates only: the exact id of the Core template this one
33
+ * replaces for unqualified lookup (find it with
34
+ * `astryx --json template --list --package @astryxdesign/core`). The Core
35
+ * original stays selectable with `--package @astryxdesign/core`. Needs
36
+ * `@astryxdesign/cli` 0.7.0 or later: earlier CLIs reject the field and
37
+ * withhold the package's templates and doc topics. */
38
+ replaces?: string;
31
39
  /** Whether this template is ready for use. Templates with
32
40
  * isReady: false show as "(WIP)" in the gallery and CLI. */
33
41
  isReady?: boolean;
@@ -12,9 +12,9 @@ export const doc = {
12
12
  displayName: 'Provider and artifact identity',
13
13
  namespace: 'authoring',
14
14
  description:
15
- 'Separates stable provider/artifact identity from package instances and runtime lifecycle state. providerId is in use today: an integration manifest may declare it, and Doctor and every command report two packages that claim one. The artifact, doc, instance, and compiler-input identities are defined for the docs graph, which is not built yet, and no command reads them.',
15
+ 'Separates stable provider/artifact identity from package instances and runtime lifecycle state. Provider identity names integration manifests and settles provider conflicts. Docs-tree nodes are identified by doc identity; the tree covers the CLI\'s own docs. Artifact, instance, and compiler-input identities are defined for every provider-owned artifact; no command reads them.',
16
16
  appliesTo:
17
- 'Integration manifests and provider conflicts today; the docs graph once it ships',
17
+ 'Integration manifests, provider conflicts, and docs-tree node ids.',
18
18
  fields: [
19
19
  {
20
20
  name: 'ProviderId',
@@ -11,7 +11,7 @@
11
11
  * The manifest module may also carry `debug` and `gapReport` NAMED exports.
12
12
  * They are not fields here on purpose: a CLI released before a given manifest
13
13
  * field existed could reject it and lose every contribution, while an unknown
14
- * named export is simply not read. See the `cli-integrations` doc topic.
14
+ * named export is simply not read. See `astryx docs cli/integrations`.
15
15
  */
16
16
  export interface AstryxIntegration {
17
17
  /** Stable logical provider ID. Omit to use package.json#name. Set this only
@@ -196,7 +196,7 @@ async function warnOnThemeIntegrationIssues(json) {
196
196
  try {
197
197
  const project = await Project.load(process.cwd());
198
198
  await project.themes();
199
- await warnOnIntegrationIssues(project.loadedIntegrations, {json});
199
+ await warnOnIntegrationIssues(project, {json});
200
200
  } catch {
201
201
  // Never let the nudge break the command.
202
202
  }
@@ -177,10 +177,13 @@ export function registerBuild(program) {
177
177
  // `template <name> <path>` scaffolds into your project; <path> is the file
178
178
  // (or folder) to write it to — a placeholder, since we can't know your
179
179
  // layout. `--skeleton` and `component <Name>` just print, so no path.
180
+ const pageCommand = pages.length
181
+ ? formatCliCommand(pages[0].command)
182
+ : null;
180
183
  const startCmd = directMatch
181
- ? `${run} template ${pages[0].name} <path>`
184
+ ? `${pageCommand} <path>`
182
185
  : pages.length
183
- ? `${run} template ${pages[0].name} --skeleton`
186
+ ? pageCommand
184
187
  : `${run} component AppShell`;
185
188
  const startNote = directMatch
186
189
  ? `This \`${pages[0].name}\` page template appears to be the closest to what you want, so we recommend scaffolding it into your project — replace \`<path>\` with the file (or folder) to write it to — then adapting. Otherwise, browse PAGE TEMPLATES first, then BLOCKS and DOMAIN COMPONENTS below.`
@@ -111,7 +111,7 @@ export function registerComponent(program) {
111
111
  // doctor integration validate. Best-effort; suppressed in --json mode.
112
112
  try {
113
113
  const project = await Project.load(process.cwd());
114
- await warnOnIntegrationIssues(project.loadedIntegrations, {json});
114
+ await warnOnIntegrationIssues(project, {json});
115
115
  } catch {
116
116
  // Never let the nudge break the command.
117
117
  }
@@ -71,7 +71,7 @@ function createFixture({
71
71
  );
72
72
  fs.writeFileSync(
73
73
  path.join(compDir, 'MetaAppShell.doc.mjs'),
74
- `export const docs = {\n name: 'MetaAppShell',\n usage: { description: 'Meta-flavored app shell.' },\n props: [{ name: 'title', type: 'string', description: 'Header title' }],\n};\n`,
74
+ `export default {\n type: 'component',\n name: 'MetaAppShell',\n usage: { description: 'Meta-flavored app shell.' },\n props: [{ name: 'title', type: 'string', description: 'Header title' }],\n};\n`,
75
75
  );
76
76
  if (withSource) {
77
77
  fs.writeFileSync(
@@ -82,7 +82,7 @@ function createFixture({
82
82
  if (extraComponent) {
83
83
  fs.writeFileSync(
84
84
  path.join(compDir, `${extraComponent}.doc.mjs`),
85
- `export const docs = {\n name: '${extraComponent}',\n usage: { description: '${extraComponent} from meta.' },\n};\n`,
85
+ `export default {\n type: 'component',\n name: '${extraComponent}',\n usage: { description: '${extraComponent} from meta.' },\n props: [],\n};\n`,
86
86
  );
87
87
  fs.writeFileSync(
88
88
  path.join(compDir, `${extraComponent}.tsx`),
@@ -100,7 +100,7 @@ function createFixture({
100
100
  : '';
101
101
  fs.writeFileSync(
102
102
  path.join(entryDir, `${entryPoint.component}.doc.mjs`),
103
- `export const docs = {\n name: '${entryPoint.component}',${ownSpecifier}\n usage: { description: '${entryPoint.component} from an entry point.' },\n};\n`,
103
+ `export default {\n type: 'component',\n name: '${entryPoint.component}',${ownSpecifier}\n usage: { description: '${entryPoint.component} from an entry point.' },\n props: [],\n};\n`,
104
104
  );
105
105
  }
106
106
 
@@ -69,11 +69,12 @@ describe('astryx discover with a manifest that fails to load', () => {
69
69
 
70
70
  expect(status).toBe(0);
71
71
  expect(stderr).toContain(
72
- 'Warning: @test/broken has 1 integration issue(s). ' +
73
- 'Run: astryx doctor integration validate @test/broken',
72
+ 'Warning: @test/broken has 1 integration issue(s). Run: astryx doctor',
74
73
  );
75
74
  expect(stdout).not.toContain('No integrations configured.');
76
- expect(stdout).toContain('No external components found in configured integrations.');
75
+ expect(stdout).toContain(
76
+ 'No external components found in configured integrations.',
77
+ );
77
78
  });
78
79
 
79
80
  it('reports meta.configured=true in --json, with the nudge suppressed', async () => {
@@ -101,7 +102,7 @@ describe('astryx discover with a configured package that is not installed', () =
101
102
  );
102
103
  fs.writeFileSync(
103
104
  path.join(healthy, 'components', 'Widget.doc.mjs'),
104
- `export const docs = {name: 'Widget', usage: {description: 'A widget.'}};\n`,
105
+ `export const docs = {name: 'Widget', usage: {description: 'A widget.'}, props: []};\n`,
105
106
  );
106
107
  fs.writeFileSync(
107
108
  path.join(healthy, 'components', 'Widget.tsx'),
@@ -129,8 +130,7 @@ describe('astryx discover with a configured package that is not installed', () =
129
130
 
130
131
  expect(status).toBe(0);
131
132
  expect(stderr).toContain(
132
- 'Warning: @test/missing has 1 integration issue(s). ' +
133
- 'Run: astryx doctor integration validate @test/missing',
133
+ 'Warning: @test/missing has 1 integration issue(s). Run: astryx doctor\n',
134
134
  );
135
135
  });
136
136
  });
@@ -149,8 +149,7 @@ describe('astryx search with a manifest that fails to load', () => {
149
149
 
150
150
  expect(status).toBe(0);
151
151
  expect(stderr).toContain(
152
- 'Warning: @test/broken has 1 integration issue(s). ' +
153
- 'Run: astryx doctor integration validate @test/broken',
152
+ 'Warning: @test/broken has 1 integration issue(s). Run: astryx doctor',
154
153
  );
155
154
 
156
155
  const asJson = await runCli(['search', 'button', '--json'], {cwd: project});
@@ -83,7 +83,7 @@ export function registerDiscover(program) {
83
83
  // doctor integration validate. Best-effort; suppressed in --json mode.
84
84
  try {
85
85
  const project = await Project.load(process.cwd());
86
- await warnOnIntegrationIssues(project.loadedIntegrations, {json});
86
+ await warnOnIntegrationIssues(project, {json});
87
87
  } catch {
88
88
  // Never let the nudge break the command.
89
89
  }
@@ -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';
@@ -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
  }