@astryxdesign/cli 0.7.3-canary.f94e962 → 0.7.3

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 (205) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/README.md +68 -68
  3. package/api/build/_adapter.mjs +37 -25
  4. package/api/build/blocks/blocks.d.mts +68 -18
  5. package/api/build/blocks/blocks.mjs +475 -116
  6. package/api/build/blocks/blocks.test.mjs +191 -61
  7. package/api/build/blocks/blocks.weights.json +1 -1
  8. package/api/build/build.type.mjs +1 -1
  9. package/api/build/kit/answer.d.mts +9 -5
  10. package/api/build/kit/answer.mjs +123 -13
  11. package/api/build/kit/answer.test.mjs +73 -3
  12. package/api/build/kit/signals.d.mts +19 -0
  13. package/api/build/kit/signals.mjs +18 -7
  14. package/api/build/kit/weights.d.mts +8 -22
  15. package/api/build/kit/weights.mjs +87 -8
  16. package/api/build/kit/weights.test.mjs +96 -0
  17. package/api/build/tree.mjs +2 -1
  18. package/api/build/tree.test.mjs +37 -29
  19. package/api/component/_adapter.mjs +39 -5
  20. package/api/component/component-replacement.test.mjs +1 -0
  21. package/api/component/component.mjs +1 -1
  22. package/api/component/doc-links.test.mjs +2 -2
  23. package/api/discover/_adapter.d.mts +1 -2
  24. package/api/discover/_adapter.mjs +6 -8
  25. package/api/discover/discover.mjs +0 -1
  26. package/api/docs/_adapter.d.mts +2 -2
  27. package/api/docs/_adapter.mjs +65 -18
  28. package/api/docs/docs-homes.test.mjs +127 -0
  29. package/api/docs/docs.doc.mjs +3 -3
  30. package/api/docs/docs.test.mjs +28 -18
  31. package/api/docs/integration-tree.test.mjs +20 -20
  32. package/api/docs/integrationDocs.test.mjs +1 -1
  33. package/api/docs/namespace-section.test.mjs +6 -6
  34. package/api/docs/reference-blocks.test.mjs +2 -2
  35. package/api/doctor/_adapter.d.mts +33 -13
  36. package/api/doctor/_adapter.mjs +55 -25
  37. package/api/doctor/doctor.d.mts +23 -5
  38. package/api/doctor/doctor.mjs +97 -28
  39. package/api/doctor/doctor.test.mjs +67 -9
  40. package/api/hook/hook.mjs +1 -1
  41. package/api/integration/validate-integration-fixes.test.mjs +6 -5
  42. package/api/integration/validate-integration-gaps.test.mjs +12 -1
  43. package/api/integration/validate-integration.d.mts +4 -0
  44. package/api/integration/validate-integration.mjs +48 -7
  45. package/api/integration/validate-integration.type.d.mts +36 -5
  46. package/api/integration/validate-integration.type.mjs +27 -6
  47. package/api/integration/validateIntegration.doc.mjs +1 -1
  48. package/api/search/_adapter.d.mts +16 -0
  49. package/api/search/_adapter.mjs +39 -0
  50. package/api/search/_adapter.test.mjs +173 -0
  51. package/api/search/_candidate-score.mjs +1 -1
  52. package/api/search/_entries.d.mts +11 -0
  53. package/api/search/_entries.mjs +35 -17
  54. package/api/search/_entries.test.mjs +48 -0
  55. package/api/search/_gather-docs.mjs +3 -3
  56. package/api/search/_gather-templates.d.mts +0 -1
  57. package/api/search/_gather-templates.mjs +25 -0
  58. package/api/search/search.doc.mjs +1 -1
  59. package/api/search/search.integration-block.test.mjs +100 -0
  60. package/api/search/search.mjs +6 -2
  61. package/api/search/search.test.mjs +14 -14
  62. package/api/template/template.mjs +5 -1
  63. package/assets/docs/author-a-theme.doc.mjs +2 -2
  64. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  65. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  66. package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
  67. package/assets/docs/tree/agent-guidance.doc.mjs +1 -1
  68. package/assets/docs/tree/{integrations.doc.mjs → authoring.doc.mjs} +15 -6
  69. package/assets/docs/tree/block-template.doc.mjs +1 -1
  70. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  71. package/assets/docs/tree/building-blocks.doc.mjs +2 -2
  72. package/assets/docs/tree/check-the-props.doc.mjs +1 -1
  73. package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
  74. package/assets/docs/tree/checks.doc.mjs +2 -2
  75. package/assets/docs/tree/ci-and-containers.doc.mjs +13 -0
  76. package/assets/docs/tree/cli-command.doc.mjs +1 -1
  77. package/assets/docs/tree/cli.doc.mjs +1 -1
  78. package/assets/docs/tree/codemods.doc.mjs +1 -1
  79. package/assets/docs/tree/component-family.doc.mjs +1 -1
  80. package/assets/docs/tree/component-imports.doc.mjs +1 -1
  81. package/assets/docs/tree/components.doc.mjs +1 -1
  82. package/assets/docs/tree/configuration.doc.mjs +1 -1
  83. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
  84. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  85. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  86. package/assets/docs/tree/docs.doc.mjs +1 -1
  87. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  88. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  89. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  90. package/assets/docs/tree/extend-or-replace.doc.mjs +1 -1
  91. package/assets/docs/{authoring.doc.mjs → tree/field-reference.doc.mjs} +4 -3
  92. package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
  93. package/assets/docs/tree/generate-a-palette.doc.mjs +1 -1
  94. package/assets/docs/tree/global-integrations.doc.mjs +2 -2
  95. package/assets/docs/tree/grade-template-with-agent.doc.mjs +4 -4
  96. package/assets/docs/tree/help.doc.mjs +2 -2
  97. package/assets/docs/tree/links.doc.mjs +1 -1
  98. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  99. package/assets/docs/tree/page-template.doc.mjs +1 -1
  100. package/assets/docs/tree/publishing.doc.mjs +1 -1
  101. package/assets/docs/tree/quick-start.doc.mjs +1 -1
  102. package/assets/docs/tree/replace-a-core-component.doc.mjs +1 -1
  103. package/assets/docs/tree/replace-a-core-template.doc.mjs +1 -1
  104. package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
  105. package/assets/docs/tree/see-it-in-an-app.doc.mjs +1 -1
  106. package/assets/docs/tree/ship.doc.mjs +2 -2
  107. package/assets/docs/tree/short-and-findable.doc.mjs +1 -1
  108. package/assets/docs/tree/single-component.doc.mjs +1 -1
  109. package/assets/docs/tree/start-a-template.doc.mjs +1 -1
  110. package/assets/docs/tree/subcomponent.doc.mjs +1 -1
  111. package/assets/docs/tree/template-assets.doc.mjs +1 -1
  112. package/assets/docs/tree/template-doc-overview.doc.mjs +2 -2
  113. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  114. package/assets/docs/tree/template-grading-rubric.doc.mjs +1 -1
  115. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  116. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  117. package/assets/docs/tree/template-styles.doc.mjs +1 -1
  118. package/assets/docs/tree/templates.doc.mjs +1 -1
  119. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  120. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  121. package/assets/docs/tree/themes.doc.mjs +1 -1
  122. package/assets/docs/tree/troubleshooting.doc.mjs +1 -1
  123. package/assets/docs/tree/upgrading.doc.mjs +1 -1
  124. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +1 -1
  125. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  126. package/assets/docs/tree/versioning.doc.mjs +5 -1
  127. package/assets/docs/tree/write-good-templates.doc.mjs +1 -1
  128. package/assets/docs/tree/write-the-template-file.doc.mjs +1 -1
  129. package/assets/docs/use-integrations.doc.mjs +120 -0
  130. package/authoring/doctypes/schema/schema.doc.mjs +1 -1
  131. package/authoring/integration/integration.doc.mjs +1 -1
  132. package/authoring/integration/type.ts +1 -1
  133. package/clients/cli/command-result-coverage.test.mjs +6 -5
  134. package/clients/cli/commands/build-theme.color-scheme.test.mjs +1 -1
  135. package/clients/cli/commands/{component/index.mjs → component.mjs} +37 -37
  136. package/clients/cli/commands/component.test.mjs +6 -6
  137. package/clients/cli/commands/docs.doc.mjs +2 -2
  138. package/clients/cli/commands/docs.mjs +1 -1
  139. package/clients/cli/commands/docs.test.mjs +14 -14
  140. package/clients/cli/commands/doctor-integration.test.mjs +49 -1
  141. package/clients/cli/commands/doctor.doc.mjs +1 -1
  142. package/clients/cli/commands/doctor.mjs +10 -0
  143. package/clients/cli/commands/{hook/index.mjs → hook.mjs} +22 -22
  144. package/clients/cli/commands/import-hint-correctness.test.mjs +1 -1
  145. package/clients/cli/commands/integration.doc.mjs +1 -1
  146. package/clients/cli/commands/manifest.doc.mjs +1 -1
  147. package/clients/cli/commands/manifest.mjs +67 -0
  148. package/clients/cli/commands/outside-project.test.mjs +99 -0
  149. package/clients/cli/commands/postinstall.doc.mjs +23 -0
  150. package/clients/cli/commands/postinstall.mjs +31 -0
  151. package/clients/cli/commands/setup-nudge.test.mjs +17 -0
  152. package/clients/cli/commands/{build-theme.mjs → theme.mjs} +1 -1
  153. package/clients/cli/index.mjs +35 -93
  154. package/clients/cli/lib/component-format.mjs +1 -1
  155. package/clients/cli/lib/define-command.mjs +12 -7
  156. package/clients/cli/lib/exit-codes.test.mjs +5 -0
  157. package/clients/cli/lib/manifest.test.mjs +12 -0
  158. package/clients/cli/lib/welcome-box.mjs +50 -0
  159. package/foundation/agent-docs/agent-doc-state.d.mts +12 -0
  160. package/foundation/agent-docs/agent-doc-state.mjs +24 -2
  161. package/foundation/agent-docs/agent-docs.mjs +7 -6
  162. package/foundation/agent-docs/agent-docs.test.mjs +5 -4
  163. package/foundation/agent-docs/computer-agent-text.d.mts +39 -2
  164. package/foundation/agent-docs/computer-agent-text.mjs +135 -8
  165. package/foundation/agent-docs/computer-agent-text.test.mjs +99 -2
  166. package/foundation/discovery/authoring-self-docs.d.mts +7 -0
  167. package/foundation/discovery/authoring-self-docs.mjs +16 -4
  168. package/foundation/discovery/authoring-self-docs.test.mjs +15 -3
  169. package/foundation/discovery/authoring-surface.d.mts +1 -1
  170. package/foundation/discovery/authoring-surface.mjs +2 -2
  171. package/foundation/discovery/authoring-surface.test.mjs +1 -1
  172. package/foundation/discovery/cli-self-docs.d.mts +2 -1
  173. package/foundation/discovery/cli-self-docs.mjs +4 -3
  174. package/foundation/discovery/cli-self-docs.test.mjs +2 -2
  175. package/foundation/discovery/runner-commands.mjs +1 -0
  176. package/foundation/discovery/stray-pointers.test.mjs +1 -1
  177. package/foundation/doc-compiler/doc-loads.test.mjs +21 -9
  178. package/foundation/doc-compiler/split-topic-keywords.test.mjs +3 -2
  179. package/foundation/doc-compiler/tree.d.mts +32 -6
  180. package/foundation/doc-compiler/tree.mjs +77 -43
  181. package/foundation/doc-compiler/tree.test.mjs +7 -7
  182. package/foundation/fs/read-record.d.mts +18 -0
  183. package/foundation/fs/read-record.mjs +131 -0
  184. package/foundation/fs/read-record.test.mjs +77 -0
  185. package/foundation/integrations/cli-peer-version.d.mts +36 -0
  186. package/foundation/integrations/cli-peer-version.mjs +132 -0
  187. package/foundation/integrations/cli-peer-version.test.mjs +354 -0
  188. package/foundation/integrations/exports-subpaths.d.mts +57 -0
  189. package/foundation/integrations/exports-subpaths.mjs +113 -0
  190. package/foundation/integrations/public-imports.d.mts +118 -0
  191. package/foundation/integrations/public-imports.mjs +1769 -0
  192. package/foundation/integrations/public-imports.test.mjs +1793 -0
  193. package/foundation/release/cache.test.mjs +24 -21
  194. package/foundation/release/global-state.d.mts +8 -4
  195. package/foundation/release/global-state.mjs +4 -2
  196. package/foundation/release/notices.d.mts +62 -8
  197. package/foundation/release/notices.mjs +136 -25
  198. package/foundation/release/notices.test.mjs +21 -0
  199. package/foundation/response/response-types.doc.mjs +1 -1
  200. package/foundation/text/string-utils.d.mts +2 -1
  201. package/foundation/text/string-utils.mjs +16 -5
  202. package/foundation/text/suggest-order.d.mts +72 -0
  203. package/foundation/text/suggest-order.mjs +363 -0
  204. package/foundation/text/suggest-order.test.mjs +259 -0
  205. package/package.json +9 -9
@@ -59,51 +59,51 @@ const PINNED = [
59
59
  [
60
60
  'analytics dashboard with a KPI row and a sortable table',
61
61
  [
62
- 'PaginationPageSize',
63
- 'GridDashboardLayout',
64
- 'TableBulkActionsTable',
62
+ 'TableSortableTable',
65
63
  'TableGridDividersTable',
66
- 'TableRowExpansionTable',
64
+ 'TableShowcase',
65
+ 'TableGroupedRowsTable',
66
+ 'TableStripedTable',
67
67
  ],
68
68
  ],
69
69
  [
70
70
  'settings page with notification toggles and a save bar',
71
71
  [
72
- 'ToggleButtonColor',
73
- 'ToggleButtonGroup',
74
- 'ToggleButtonGroupShowcase',
75
- 'ToggleButtonGroupVertical',
76
- 'ToggleButtonIconSwap',
72
+ 'SwitchShowcase',
73
+ 'SwitchSettingsPanel',
74
+ 'ToggleButtonShowcase',
75
+ 'ToggleButtonStates',
76
+ 'SwitchWithDescription',
77
77
  ],
78
78
  ],
79
79
  [
80
80
  'empty state for a question bank with an import button',
81
81
  [
82
- 'EmptyStateActions',
83
- 'EmptyStateCompact',
84
82
  'EmptyStateContainer',
85
83
  'EmptyStateShowcase',
86
- 'ToolbarTableFilter',
84
+ 'EmptyStateCompact',
85
+ 'EmptyStateActions',
86
+ 'CommandPaletteEmptyShowcase',
87
87
  ],
88
88
  ],
89
89
  [
90
90
  'login form with single sign-on buttons',
91
91
  [
92
+ 'ButtonWithIcon',
92
93
  'CardWithInnerLayout',
93
- 'BottomSheetMobileKeyboard',
94
- 'ButtonGroupBasic',
95
- 'CollapsibleControlledAccordion',
96
- 'BottomSheetSwitcherReviewFlow',
94
+ 'ButtonVariants',
95
+ 'FormLayoutShowcase',
96
+ 'FormLayoutMixedControls',
97
97
  ],
98
98
  ],
99
99
  [
100
100
  'calendar for booking appointments',
101
101
  [
102
- 'CalendarRangeWithValue',
103
102
  'CalendarSingle',
104
- 'CalendarTwoMonths',
105
- 'CalendarConstraints',
106
103
  'CalendarShowcase',
104
+ 'CalendarConstraints',
105
+ 'CalendarRangeWithValue',
106
+ 'CalendarTwoMonths',
107
107
  ],
108
108
  ],
109
109
  [
@@ -125,16 +125,15 @@ afterAll(() => {
125
125
  });
126
126
 
127
127
  describe('build tree', () => {
128
- it('keeps the blocks a request names in build’s slots', async () => {
129
- const phrase = 'calendar for booking appointments';
128
+ it('keeps a block the request names by its exact name in build’s slot', async () => {
129
+ const phrase = 'calendar for booking appointments with CalendarTwoMonths';
130
130
  const answer = await build(phrase, {cwd: REPO});
131
131
  const own = await withListingCache(() => buildKit(phrase, {cwd: REPO}));
132
132
  if (answer?.type !== 'build.kit' || own.type !== 'build.kit')
133
133
  throw new Error('expected a kit');
134
- own.data.blocks.forEach((b, k) => {
135
- if (b.name.startsWith('Calendar'))
136
- expect(answer.data.blocks[k].name).toBe(b.name);
137
- });
134
+ const k = own.data.blocks.findIndex(b => b.name === 'CalendarTwoMonths');
135
+ expect(k).toBeGreaterThanOrEqual(0);
136
+ expect(answer.data.blocks[k].name).toBe('CalendarTwoMonths');
138
137
  });
139
138
 
140
139
  it('runs with the network and subprocesses blocked', async () => {
@@ -166,12 +165,21 @@ describe('build tree', () => {
166
165
  expect(answer.data.start?.alternatives).toEqual(
167
166
  own.data.start?.alternatives,
168
167
  );
169
- // The picker only re-orders build's own blocks: each keeps build's
170
- // entry (its real score and reason), none is added, none is dropped.
168
+ // Every block is build's own entry, one search returned, or the picker's
169
+ // own, each with its real score and reason; never more blocks than
170
+ // build's own.
171
171
  expect(answer.data.blocks.length).toBe(own.data.blocks.length);
172
- for (const b of answer.data.blocks)
173
- expect(own.data.blocks.find(o => o.name === b.name)).toEqual(b);
172
+ for (const b of answer.data.blocks) {
173
+ expect(b.score).toBeGreaterThan(0);
174
+ expect(typeof b.reason).toBe('string');
175
+ const mine = own.data.blocks.find(o => o.name === b.name);
176
+ if (mine) expect(mine).toEqual(b);
177
+ }
174
178
  expect(answer.data.blocks.map(b => b.name)).toEqual(blocks);
179
+ // Never longer than build's own answer for the same request.
180
+ expect(Buffer.byteLength(JSON.stringify(answer))).toBeLessThanOrEqual(
181
+ Buffer.byteLength(JSON.stringify(own)),
182
+ );
175
183
  });
176
184
  }
177
185
  });
@@ -44,6 +44,10 @@ import {Project} from '../../foundation/config/project.mjs';
44
44
  import {loadComponentDoc as loadValidatedComponentDoc} from '../../foundation/discovery/component-loader.mjs';
45
45
  import {resolveComponentReplacements} from '../../foundation/discovery/component-replacement.mjs';
46
46
  import {searchComponents} from '../../foundation/text/string-utils.mjs';
47
+ import {
48
+ rankComponentSuggestions,
49
+ synonymMatches,
50
+ } from '../../foundation/text/suggest-order.mjs';
47
51
  import {AstryxError, coreDirOrThrow} from '../error.mjs';
48
52
  import {
49
53
  componentLinkProvider,
@@ -51,6 +55,28 @@ import {
51
55
  loadDocsCatalog,
52
56
  } from '../docs/_adapter.mjs';
53
57
 
58
+ /** @type {Record<string, {synonyms?: string[]}> | undefined} */
59
+ let cards;
60
+ /**
61
+ * Search's component cards (each component's other names), read once.
62
+ * @returns {Record<string, {synonyms?: string[]}>}
63
+ */
64
+ function searchCards() {
65
+ if (!cards) {
66
+ try {
67
+ cards = JSON.parse(
68
+ fs.readFileSync(
69
+ new URL('../search/_cards.json', import.meta.url),
70
+ 'utf8',
71
+ ),
72
+ );
73
+ } catch {
74
+ cards = {};
75
+ }
76
+ }
77
+ return /** @type {Record<string, {synonyms?: string[]}>} */ (cards);
78
+ }
79
+
54
80
  export {CORE_PACKAGE, unscopedComponentOwners};
55
81
 
56
82
  /**
@@ -463,12 +489,20 @@ export async function resolveUnscopedDoc(dirName, {coreDir, cwd, name}) {
463
489
  resolvedOwnerPackage = CORE_PACKAGE;
464
490
  resolvedSourcePath = findComponentSource(coreDir, resolvedName);
465
491
  } else {
492
+ // How many to suggest: the near-top results, at most five and at
493
+ // least two. Which ones, and in what order, is the suggestion
494
+ // ranking's call.
466
495
  const threshold = Math.max(topScore - 20, 1);
467
- const candidates = results
468
- .filter(r => r.score >= threshold)
469
- .slice(0, 5);
470
- if (candidates.length < 2)
471
- candidates.push(...results.slice(candidates.length, 2));
496
+ const count = Math.max(
497
+ results.filter(r => r.score >= threshold).slice(0, 5).length,
498
+ Math.min(2, results.length),
499
+ );
500
+ const candidates = rankComponentSuggestions(
501
+ dirName,
502
+ results,
503
+ Object.values(components).flat(),
504
+ synonymMatches(dirName, searchCards()),
505
+ ).slice(0, count);
472
506
  throw new AstryxError(
473
507
  `No component named "${name}"`,
474
508
  candidates.map(c => ({name: c.name, reason: c.reason})),
@@ -64,6 +64,7 @@ function writeIntegration(name, components, peers) {
64
64
  type: 'component',
65
65
  name: componentName,
66
66
  displayName: componentName,
67
+ import: `${name}/components/${componentName}`,
67
68
  ...(replaces ? {replaces} : {}),
68
69
  keywords: ['acme'],
69
70
  usage: {description: `${componentName} for Acme apps.`},
@@ -293,7 +293,7 @@ async function componentRead(name, options = {}) {
293
293
  const selectorList = Array.isArray(name) ? name : null;
294
294
  const noName = selectorList == null && !name;
295
295
 
296
- // Default detail level mirrors the CLI (see commands/component/index.mjs):
296
+ // Default detail level mirrors the CLI (see commands/component.mjs):
297
297
  // single-component views default to 'full', list-style views (--list,
298
298
  // --category, or no name) default to 'brief' (scannable name lists).
299
299
  // An explicit array remains a batch even when it is empty or a caller also
@@ -250,14 +250,14 @@ describe("a link in a guide's description, as the docs tree shows it", () => {
250
250
  'Document a theme by extending the core theme topic, so an app reads it in `astryx docs theme`.';
251
251
  const guide = /** @type {any} */ (
252
252
  await docs(
253
- 'cli/integrations/building-blocks/themes/document-the-theme',
253
+ 'authoring/building-blocks/themes/document-the-theme',
254
254
  undefined,
255
255
  {cwd: tmpDir, full: true},
256
256
  )
257
257
  );
258
258
  expect(guide.data.description).toBe(expected);
259
259
  const namespace = /** @type {any} */ (
260
- await docs('cli/integrations/building-blocks/themes', undefined, {
260
+ await docs('authoring/building-blocks/themes', undefined, {
261
261
  cwd: tmpDir,
262
262
  })
263
263
  );
@@ -43,12 +43,11 @@ export function hasSources(project: Project | undefined): boolean;
43
43
  * @param {Project | undefined} project
44
44
  * @param {Array<{name: string}>} installed
45
45
  * @param {Set<string>} declared
46
- * @param {(name: string, version?: string) => string} add
47
46
  * @returns {Promise<import('./discover.type.mjs').DiscoverAvailableEntry[]>}
48
47
  */
49
48
  export function computerAvailableEntries(project: Project | undefined, installed: Array<{
50
49
  name: string;
51
- }>, declared: Set<string>, add: (name: string, version?: string) => string): Promise<import("./discover.type.mjs").DiscoverAvailableEntry[]>;
50
+ }>, declared: Set<string>): Promise<import("./discover.type.mjs").DiscoverAvailableEntry[]>;
52
51
  /**
53
52
  * Package names the project's package.json declares in any dependency field.
54
53
  * @param {Project | undefined} project
@@ -25,6 +25,7 @@ import {
25
25
  availableComputerIntegrations,
26
26
  } from '../../foundation/config/project.mjs';
27
27
  import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
28
+ import {projectAddCommand} from '../../foundation/release/notices.mjs';
28
29
  import {hostedRun} from '../../foundation/runtime/package-root.mjs';
29
30
  import {
30
31
  scanAllPackages,
@@ -274,17 +275,14 @@ const COMPUTER_SOURCE = 'installed for this computer';
274
275
  * @param {Project | undefined} project
275
276
  * @param {Array<{name: string}>} installed
276
277
  * @param {Set<string>} declared
277
- * @param {(name: string, version?: string) => string} add
278
278
  * @returns {Promise<import('./discover.type.mjs').DiscoverAvailableEntry[]>}
279
279
  */
280
- export async function computerAvailableEntries(
281
- project,
282
- installed,
283
- declared,
284
- add,
285
- ) {
280
+ export async function computerAvailableEntries(project, installed, declared) {
286
281
  const cwd = project?.cwd ?? process.cwd();
287
282
  if (isOutsideProject(cwd)) return [];
283
+ // The same command doctor names: in the project spec:AST-040 FR9 defines,
284
+ // and none where FR9 finds no project.
285
+ const add = projectAddCommand(cwd);
288
286
  const have = new Set([...installed.map(pkg => pkg.name), ...declared]);
289
287
  return (await availableComputerIntegrations(cwd, have)).map(c => ({
290
288
  name: c.name,
@@ -292,7 +290,7 @@ export async function computerAvailableEntries(
292
290
  ...(c.version ? {version: c.version} : {}),
293
291
  ...(c.description ? {description: c.description} : {}),
294
292
  source: COMPUTER_SOURCE,
295
- install: add(c.name),
293
+ ...(add ? {install: add(c.name)} : {}),
296
294
  }));
297
295
  }
298
296
 
@@ -223,7 +223,6 @@ export async function discover(query, options = {}) {
223
223
  project,
224
224
  packages,
225
225
  declared,
226
- add,
227
226
  );
228
227
  const fromSources = officialFirst(
229
228
  availableEntries(catalog, packages, declared, {
@@ -226,7 +226,7 @@ export function topicUp(entry: import("../../foundation/discovery/docs-discovery
226
226
  export function placeLinks(tree: DocsTree, node: TreeNode): import("./docs.type.mjs").DocsLinks;
227
227
  /**
228
228
  * The moves a topic read offers: from its place in the tree, where a guide
229
- * sits in its namespace and a flat topic in the Unorganized level.
229
+ * sits in its namespace and a flat topic in its topic level.
230
230
  * @param {DocsCatalog} catalog
231
231
  * @param {import('../../foundation/discovery/docs-discovery.mjs').DocsTopicEntry} entry
232
232
  * @returns {Promise<import('./docs.type.mjs').DocsLinks>}
@@ -290,7 +290,7 @@ export function holdsOwnName(tree: DocsTree, catalog: DocsCatalog, entry: import
290
290
  /**
291
291
  * The doc that took a flat topic's route in the docs tree, when it is not
292
292
  * that topic (spec:AST-046 FR11): the CLI keeps its routes, such as `cli`
293
- * and `unorganized`, and a namespace keeps its route over a topic of the same
293
+ * and `guides`, and a namespace keeps its route over a topic of the same
294
294
  * name. Null when the topic owns its route, or the tree has no node there.
295
295
  * @param {DocsTree} tree
296
296
  * @param {import('../../foundation/discovery/docs-discovery.mjs').DocsTopicEntry} entry
@@ -52,6 +52,7 @@ import {
52
52
  cliDocSection,
53
53
  } from '../../foundation/discovery/cli-self-docs.mjs';
54
54
  import {
55
+ AUTHORING_REFERENCE_ROUTE,
55
56
  loadAuthoringSelfDocs,
56
57
  schemaFieldTable,
57
58
  selfDocSection,
@@ -70,6 +71,7 @@ import {
70
71
  import {findCoreDir} from '../../foundation/fs/paths.mjs';
71
72
  import {AstryxError} from '../error.mjs';
72
73
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
74
+ import {orderRouteSuggestions} from '../../foundation/text/suggest-order.mjs';
73
75
  import {formatCliCommand} from '../../foundation/env/package-manager.mjs';
74
76
 
75
77
  export {OVERLAY_LANGUAGES, overlayLanguages};
@@ -385,7 +387,7 @@ export function projectTree(catalog, {fresh = false} = {}) {
385
387
  let cliTreeInputs;
386
388
 
387
389
  /**
388
- * Every flat topic in the catalog, as the tree's Unorganized level reads it.
390
+ * Every flat topic in the catalog, as the tree's topic levels read it.
389
391
  * @param {DocsCatalog} catalog
390
392
  * @returns {Promise<import('../../foundation/doc-compiler/tree.mjs').TreeTopicInput[]>}
391
393
  */
@@ -394,12 +396,13 @@ async function flatTopicInputs(catalog) {
394
396
  const topics = [];
395
397
  for (const entry of catalog.entries()) {
396
398
  const aliases = catalog.aliasesOf(entry);
397
- let {title, description} = entry;
398
- if (title == null || description == null) {
399
+ let {title, description, category} = entry;
400
+ if (title == null || description == null || category === undefined) {
399
401
  try {
400
402
  const file = await loadTopicFile(entry.path, null);
401
403
  title ??= file.doc?.title;
402
404
  description ??= file.doc?.description;
405
+ category ??= file.doc?.category;
403
406
  } catch {
404
407
  // A topic that does not load is reported where it is read.
405
408
  }
@@ -410,6 +413,7 @@ async function flatTopicInputs(catalog) {
410
413
  name: entry.name,
411
414
  title: title ?? entry.name,
412
415
  summary: description ?? '',
416
+ category: category ?? null,
413
417
  source: `${entry.package}:${entry.name}`,
414
418
  ...(aliases.length > 0 ? {aliases} : {}),
415
419
  });
@@ -419,7 +423,7 @@ async function flatTopicInputs(catalog) {
419
423
 
420
424
  /**
421
425
  * The CLI's tree, each configured integration's namespaces and guides, and
422
- * every flat topic in the generated Unorganized level.
426
+ * every flat topic in the generated level for its category.
423
427
  * @param {DocsCatalog} catalog
424
428
  * @param {boolean} fresh
425
429
  * @returns {Promise<DocsTree>}
@@ -509,23 +513,22 @@ function identitiesOf(tree) {
509
513
  }
510
514
 
511
515
  /**
512
- * The CLI's authoring docs, by kind and name. `astryx docs authoring` reads
513
- * each as one section keyed by its name, so a link to one opens that section.
514
- * Loaded once per process, like the CLI's tree files.
516
+ * The CLI's authoring docs, by kind and name. The field reference under
517
+ * `astryx docs authoring` reads each as one section keyed by its name, so a
518
+ * link to one opens that section. Loaded once per process, like the CLI's
519
+ * tree files.
515
520
  * @type {Promise<Map<string, any>> | undefined}
516
521
  */
517
522
  let authoringDocs;
518
523
 
519
524
  /**
520
- * The CLI authoring doc a link names, while `astryx docs authoring` is the
521
- * CLI's own topic.
522
- * @param {DocsCatalog} catalog
525
+ * The CLI authoring doc a link names. The `authoring` namespace is the CLI's
526
+ * own, so no integration can take its route.
523
527
  * @param {string} kind
524
528
  * @param {string} name
525
529
  * @returns {Promise<any | null>}
526
530
  */
527
- async function authoringDoc(catalog, kind, name) {
528
- if (catalog.resolve('authoring')?.package !== CLI_PROVIDER_ID) return null;
531
+ async function authoringDoc(kind, name) {
529
532
  authoringDocs ??= loadAuthoringSelfDocs().then(
530
533
  ({loaded}) =>
531
534
  new Map(loaded.map(({doc}) => [`${doc.type}\u0000${doc.name}`, doc])),
@@ -611,14 +614,14 @@ function docFinderOver(catalog, tree, fromProvider, summaries = true) {
611
614
  }
612
615
  const authored =
613
616
  provider === CLI_PROVIDER_ID
614
- ? await authoringDoc(catalog, parsed.kind, parsed.name)
617
+ ? await authoringDoc(parsed.kind, parsed.name)
615
618
  : null;
616
619
  if (authored) {
617
620
  return {
618
621
  link: {
619
622
  target,
620
623
  id: createDocId(provider, authored.type, authored.name),
621
- route: 'authoring',
624
+ route: AUTHORING_REFERENCE_ROUTE,
622
625
  title: authored.displayName ?? authored.name,
623
626
  summary: authored.description ?? '',
624
627
  command: `astryx docs authoring ${authored.name}`,
@@ -1428,7 +1431,7 @@ export function placeLinks(tree, node) {
1428
1431
 
1429
1432
  /**
1430
1433
  * The moves a topic read offers: from its place in the tree, where a guide
1431
- * sits in its namespace and a flat topic in the Unorganized level.
1434
+ * sits in its namespace and a flat topic in its topic level.
1432
1435
  * @param {DocsCatalog} catalog
1433
1436
  * @param {import('../../foundation/discovery/docs-discovery.mjs').DocsTopicEntry} entry
1434
1437
  * @returns {Promise<import('./docs.type.mjs').DocsLinks>}
@@ -1526,7 +1529,7 @@ function treeArgument(catalog, tree, node) {
1526
1529
  /**
1527
1530
  * The doc that took a flat topic's route in the docs tree, when it is not
1528
1531
  * that topic (spec:AST-046 FR11): the CLI keeps its routes, such as `cli`
1529
- * and `unorganized`, and a namespace keeps its route over a topic of the same
1532
+ * and `guides`, and a namespace keeps its route over a topic of the same
1530
1533
  * name. Null when the topic owns its route, or the tree has no node there.
1531
1534
  * @param {DocsTree} tree
1532
1535
  * @param {import('../../foundation/discovery/docs-discovery.mjs').DocsTopicEntry} entry
@@ -1540,6 +1543,35 @@ export function routeOwner(tree, entry) {
1540
1543
  : node;
1541
1544
  }
1542
1545
 
1546
+ /**
1547
+ * Routes that moved, old prefix first: the integration guides moved from
1548
+ * `cli/integrations` (and, before that, the `cli-integrations` topic) into
1549
+ * `authoring`, the one home for integration authors.
1550
+ * Only the not-found error reads this, to name where a doc went; an old route
1551
+ * opens nothing.
1552
+ */
1553
+ const MOVED_ROUTES = [
1554
+ ['cli/integrations', 'authoring'],
1555
+ ['cli-integrations', 'authoring'],
1556
+ ];
1557
+
1558
+ /**
1559
+ * The node an old route moved to, or null.
1560
+ * @param {unknown} topic
1561
+ * @param {DocsTree} tree
1562
+ * @returns {TreeNode | null}
1563
+ */
1564
+ function movedRoute(topic, tree) {
1565
+ if (typeof topic !== 'string') return null;
1566
+ const wanted = topic.toLowerCase();
1567
+ for (const [from, to] of MOVED_ROUTES) {
1568
+ if (wanted !== from && !wanted.startsWith(`${from}/`)) continue;
1569
+ const node = tree.getFolded(`${to}${wanted.slice(from.length)}`);
1570
+ if (node) return node;
1571
+ }
1572
+ return null;
1573
+ }
1574
+
1543
1575
  /**
1544
1576
  * The error for a docs argument that names nothing. For a route, it suggests
1545
1577
  * the children of the deepest namespace the route reaches; otherwise, every
@@ -1572,8 +1604,7 @@ export async function unknownTopicError(topic, catalog) {
1572
1604
  }
1573
1605
  if (suggestions.length === 0 && typeof topic === 'string') {
1574
1606
  // The docs whose own name it is (`doctor` is cli/commands/doctor), or whose
1575
- // route it spells with hyphens (`cli-integrations`, the guide's name before
1576
- // it moved to cli/integrations).
1607
+ // route it spells with hyphens (`cli-host-entry` is cli/host-entry).
1577
1608
  const wanted = topic.toLowerCase();
1578
1609
  suggestions = [...tree.nodes.values()]
1579
1610
  .filter(
@@ -1592,6 +1623,22 @@ export async function unknownTopicError(topic, catalog) {
1592
1623
  ...catalog.names().map(name => ({name, reason: 'available topic'})),
1593
1624
  ];
1594
1625
  }
1626
+ if (typeof topic === 'string') {
1627
+ suggestions = orderRouteSuggestions(topic, suggestions);
1628
+ }
1629
+ // A route that moved names where it went, ahead of the usual suggestions
1630
+ // (spec:AST-046 FR9, FR6).
1631
+ const moved = movedRoute(topic, tree);
1632
+ if (moved) {
1633
+ return new AstryxError(
1634
+ `Unknown topic "${String(topic)}". It moved to "${moved.route}"${notLoaded(catalog)}`,
1635
+ [
1636
+ {name: moved.route, reason: moved.summary},
1637
+ ...suggestions.filter(entry => entry.name !== moved.route),
1638
+ ],
1639
+ ERROR_CODES.ERR_UNKNOWN_TOPIC,
1640
+ );
1641
+ }
1595
1642
  return new AstryxError(
1596
1643
  `Unknown topic "${String(topic)}"${notLoaded(catalog)}`,
1597
1644
  suggestions,
@@ -0,0 +1,127 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Every Core doc has a named home in the docs tree (spec:AST-046 FR12).
5
+ *
6
+ * A reader sees a doc's home in its path (`Guides › Getting started`) and in
7
+ * its Up move. A flat Core topic sits in Guides or Foundations by the
8
+ * category it declares, so a new topic with no category, or one the levels
9
+ * do not know, fails here instead of landing in a catch-all. The integration
10
+ * guides and their field reference live under `authoring`, and the routes
11
+ * they left name where they went.
12
+ */
13
+
14
+ import {describe, expect, it} from 'vitest';
15
+ import {docs} from './docs.mjs';
16
+ import {TOPIC_LEVELS} from '../../foundation/doc-compiler/tree.mjs';
17
+
18
+ const CLI = '@astryxdesign/cli';
19
+ const SLOW = 60_000;
20
+
21
+ describe('every Core doc has a named home', () => {
22
+ it(
23
+ 'puts each flat Core topic in Guides or Foundations by its category',
24
+ async () => {
25
+ const list = await docs();
26
+ const core = list.data.filter(topic => topic.package === CLI);
27
+ expect(core.length).toBeGreaterThan(10);
28
+ /** @type {string[]} */
29
+ const unfiled = [];
30
+ for (const topic of core) {
31
+ const read = await docs(topic.topic);
32
+ const {category} = read.data;
33
+ if (category !== 'guide' && category !== 'foundations') {
34
+ unfiled.push(`${topic.topic} (category ${String(category)})`);
35
+ continue;
36
+ }
37
+ const level =
38
+ category === 'foundations'
39
+ ? TOPIC_LEVELS.foundations
40
+ : TOPIC_LEVELS.guides;
41
+ expect(read.data.links.up, topic.topic).toBe(
42
+ `astryx docs ${level.route}`,
43
+ );
44
+ }
45
+ expect(unfiled, 'Core topics with no home: give each a category').toEqual(
46
+ [],
47
+ );
48
+ },
49
+ SLOW,
50
+ );
51
+
52
+ it(
53
+ 'lists each level under a plain name, and no catch-all',
54
+ async () => {
55
+ const list = await docs();
56
+ const roots = (list.meta.namespaces ?? []).map(entry => entry.topic);
57
+ expect(roots).toEqual(expect.arrayContaining(['guides', 'foundations']));
58
+ expect(roots).not.toContain('unorganized');
59
+ const guides = await docs('guides');
60
+ expect(guides.data).toMatchObject({route: 'guides', title: 'Guides'});
61
+ expect(guides.data.slots[0].children.map(child => child.route)).toEqual(
62
+ expect.arrayContaining(['getting-started', 'principles', 'theme']),
63
+ );
64
+ const foundations = await docs('foundations');
65
+ expect(foundations.data.title).toBe('Foundations');
66
+ expect(
67
+ foundations.data.slots[0].children.map(child => child.route),
68
+ ).toEqual(expect.arrayContaining(['color', 'icons', 'spacing']));
69
+ await expect(docs('unorganized')).rejects.toMatchObject({
70
+ code: 'ERR_UNKNOWN_TOPIC',
71
+ });
72
+ },
73
+ SLOW,
74
+ );
75
+
76
+ it(
77
+ 'keeps everything for integration authors under authoring, and names where an old route went',
78
+ async () => {
79
+ const authoring = await docs('authoring');
80
+ expect(authoring.data).toMatchObject({
81
+ route: 'authoring',
82
+ kind: 'namespace',
83
+ breadcrumb: [],
84
+ links: {up: 'astryx docs'},
85
+ });
86
+ const children = authoring.data.slots.flatMap(slot =>
87
+ slot.children.map(child => child.route),
88
+ );
89
+ expect(children).toEqual(
90
+ expect.arrayContaining([
91
+ 'authoring/quick-start',
92
+ 'authoring/building-blocks',
93
+ 'authoring/ship',
94
+ 'authoring/help',
95
+ 'authoring/field-reference',
96
+ ]),
97
+ );
98
+ // Every field reference section still opens from the namespace by its
99
+ // key, as `astryx docs authoring <name>` did on the topic (FR13).
100
+ const reference = await docs('authoring/field-reference', undefined, {
101
+ index: true,
102
+ });
103
+ const keys = reference.data.sections.map(section => section.id);
104
+ expect(keys.length).toBeGreaterThan(15);
105
+ for (const key of keys) {
106
+ const section = await docs('authoring', key);
107
+ expect(section.type, key).toBe('docs.detail.section');
108
+ expect(section.data.id, key).toBe(key);
109
+ }
110
+ for (const [old, now] of [
111
+ ['cli/integrations', 'authoring'],
112
+ ['cli/integrations/quick-start', 'authoring/quick-start'],
113
+ ['cli/integrations/ship/publishing', 'authoring/ship/publishing'],
114
+ ]) {
115
+ const error = await docs(old).catch(e => e);
116
+ expect(error).toMatchObject({
117
+ code: 'ERR_UNKNOWN_TOPIC',
118
+ message: expect.stringContaining(`It moved to "${now}"`),
119
+ });
120
+ // The new route comes first, ahead of the suggestions any unknown
121
+ // route gets (FR6).
122
+ expect(error.suggestions[0]).toMatchObject({name: now});
123
+ }
124
+ },
125
+ SLOW,
126
+ );
127
+ });
@@ -28,7 +28,7 @@ export const doc = {
28
28
  '`cli/api` returns its children one level down (`depth` reads as many ' +
29
29
  'levels as asked, and `detail` how much of each doc below), a typed doc such as ' +
30
30
  "`cli/api/functions/search` returns its content, and a guide the tree " +
31
- 'places (`cli/integrations/quick-start`) reads like any topic. ' +
31
+ 'places (`authoring/quick-start`) reads like any topic. ' +
32
32
  'Every read but the list carries `links`, the commands that move from it: ' +
33
33
  '`up` to the level it sits in, `previous` and `next` to its neighbors, and, ' +
34
34
  'for a typed doc, `related` to the docs it names (its command or function, ' +
@@ -162,12 +162,12 @@ export const doc = {
162
162
  },
163
163
  {
164
164
  label: 'A namespace and everything below it, in full',
165
- code: "await docs('cli/integrations', undefined, {depth: 'all', detail: 'full'});",
165
+ code: "await docs('authoring', undefined, {depth: 'all', detail: 'full'});",
166
166
  },
167
167
  {label: 'One API function', code: "await docs('cli/api/functions/search');"},
168
168
  {
169
169
  label: 'A whole guide from the docs tree',
170
- code: "await docs('cli/integrations/quick-start');",
170
+ code: "await docs('authoring/quick-start');",
171
171
  },
172
172
  {label: 'One section by key', code: "await docs('spacing', 'scale');"},
173
173
  ],